KarmaEngine
Game Engine for practical learning and research purposes
Loading...
Searching...
No Matches
World.h
Go to the documentation of this file.
1
10
11#pragma once
12
13#include "krpch.h"
14
15#include "Object.h"
16#include "SubClassOf.h"
17
18namespace Karma
19{
20 class AActor;
21 class FTransform;
23 class APawn;
24 class ULevel;
25 class UClass;
26 class UGameInstance;
27
31 struct KARMA_API FActorSpawnParameters
32 {
33 FActorSpawnParameters();
34
40 std::string m_Name;
41
48
54
60
67
68#if WITH_EDITOR
72 class UPackage* OverridePackage;
73
75 FGuid OverrideActorGuid;
76#endif
77
80
82 // Need physics
83 //ESpawnActorCollisionHandlingMethod SpawnCollisionHandlingOverride;
84
85 private:
86
87 //friend class UPackageMapClient;
88
89 /* Is the actor remotely owned. This should only be set true by the package map when it is creating an actor on a client that was replicated from the server. */
90 uint8_t m_bRemoteOwned : 1;
91
92 public:
93
109
112
115
116 /* Custom function allowing the caller to specific a function to execute post actor construction but before other systems see this actor spawn. */
117 // maybe later
118 //TFunction<void(AActor*)> CustomPreSpawnInitalization;
119
125 bool IsRemoteOwned() const { return m_bRemoteOwned; }
126
130 uint8_t m_bNoFail : 1;
131
138 };
139
149 class KARMA_API UWorld : public UObject
150 {
152
153 public:
159 UWorld();
160
171 AActor* SpawnActor(UClass* Class, FTransform const* Transform, const FActorSpawnParameters& SpawnParameters = FActorSpawnParameters());
172
183 template< class T >
184 T* SpawnActor(UClass* Class, const FActorSpawnParameters& SpawnParameters = FActorSpawnParameters())
185 {
186 return CastChecked<T>(SpawnActor(Class, nullptr, SpawnParameters), ECastCheckedType::NullAllowed);
187 }
188
195 ULevel* GetPersistentLevel() const { return m_PersistentLevel; }
196
202 inline void SetGameInstance(UGameInstance* NewGI)
203 {
204 m_OwningGameInstance = NewGI;
205 }
206
207 private:
208//#if WITH_EDITORONLY_DATA
214 ULevel* m_CurrentLevel;
215//#endif
216
220 ULevel* m_PersistentLevel;
221
222
223 UGameInstance* m_OwningGameInstance;
224
226 // Time variables
228 double m_TimeSeconds;
229
231 double m_UnpausedTimeSeconds;
232
234 double m_RealTimeSeconds;
235
237 double m_AudioTimeSeconds;
238
240 float m_DeltaRealTimeSeconds;
241
243 float m_DeltaTimeSeconds;
244
246 double m_PauseDelay;
247
249 bool m_bIsPaused;
250
251 public:
253 uint8_t m_bIsTearingDown : 1;
254
256 //double m_TimeSeconds;
257
260
262 uint8_t m_bBegunPlay : 1;
263
266
268 //TEnumAsByte<ERHIFeatureLevel::Type> FeatureLevel;
269
271 struct InitializationValues
272 {
273 InitializationValues()
274 : bInitializeScenes(true)
275 , bAllowAudioPlayback(true)
276 , bRequiresHitProxies(true)
277 , bCreatePhysicsScene(true)
278 , bCreateNavigation(true)
279 , bCreateAISystem(true)
281 , bEnableTraceCollision(false)
283 , bTransactional(true)
284 , bCreateFXSystem(true)
285 , bCreateWorldPartition(false)
286 {
287 }
288
290 uint32_t bInitializeScenes : 1;
291
294
297
300
302 uint32_t bCreateNavigation : 1;
303
305 uint32_t bCreateAISystem : 1;
306
309
312
315
317 uint32_t bTransactional : 1;
318
320 uint32_t bCreateFXSystem : 1;
321
324
327
328 // Documentation left for extremely lazy and din kaat moments
329 InitializationValues& InitializeScenes(const bool bInitialize) { bInitializeScenes = bInitialize; return *this; }
330 InitializationValues& AllowAudioPlayback(const bool bAllow) { bAllowAudioPlayback = bAllow; return *this; }
331 InitializationValues& RequiresHitProxies(const bool bRequires) { bRequiresHitProxies = bRequires; return *this; }
332 InitializationValues& CreatePhysicsScene(const bool bCreate) { bCreatePhysicsScene = bCreate; return *this; }
333 InitializationValues& CreateNavigation(const bool bCreate) { bCreateNavigation = bCreate; return *this; }
334 InitializationValues& CreateAISystem(const bool bCreate) { bCreateAISystem = bCreate; return *this; }
335 InitializationValues& ShouldSimulatePhysics(const bool bInShouldSimulatePhysics) { bShouldSimulatePhysics = bInShouldSimulatePhysics; return *this; }
336 InitializationValues& EnableTraceCollision(const bool bInEnableTraceCollision) { bEnableTraceCollision = bInEnableTraceCollision; return *this; }
337 InitializationValues& ForceUseMovementComponentInNonGameWorld(const bool bInForceUseMovementComponentInNonGameWorld) { bForceUseMovementComponentInNonGameWorld = bInForceUseMovementComponentInNonGameWorld; return *this; }
338 InitializationValues& SetTransactional(const bool bInTransactional) { bTransactional = bInTransactional; return *this; }
339 InitializationValues& CreateFXSystem(const bool bCreate) { bCreateFXSystem = bCreate; return *this; }
340 InitializationValues& CreateWorldPartition(const bool bCreate) { bCreateWorldPartition = bCreate; return *this; }
341 InitializationValues& SetDefaultGameMode(TSubclassOf<class AGameModeBase> GameMode) { DefaultGameMode = GameMode; return *this; }
342 };
343
351 void Tick(/*ELevelTick TickType,*/ float DeltaSeconds);
352
353 public:
355 // UWorld inlines:
356
363 {
364 return m_TimeSeconds;
365 }
366
373 {
374 return m_CurrentLevel;
375 }
376
377 public:
383 bool AreActorsInitialized() const;
384
389 //void InitializeNewWorld(const InitializationValues IVS = InitializationValues(), bool bInSkipInitWorld = false);
390
396 bool HasBegunPlay() const;
397
411 static UWorld* CreateWorld(const EWorldType::Type InWorldType, bool bInformEngineOfWorld, const std::string& WorldName = "NoName", UPackage* InWorldPackage = NULL, bool bAddToRoot = true,/* ERHIFeatureLevel::Type InFeatureLevel = ERHIFeatureLevel::Num, const InitializationValues* InIVS = nullptr,*/ bool bInSkipInitWorld = false);
412
421 void InitializeNewWorld(const InitializationValues IVS = InitializationValues(), bool bInSkipInitWorld = false);
422
432 void InitializeActorsForPlay(const FURL& InURL, bool bResetTime = true/*, FRegisterComponentContext* Context = nullptr*/);
433
441 void ModifyLevel(ULevel* Level) const;
442
448 bool IsGameWorld() const;
449
459 void RemoveActor(AActor* Actor, bool bShouldModifyLevel) const;
460
478 bool ShivaActor(AActor* Actor, bool bNetForce = false, bool bShouldModifyLevel = true);
479
485 void AddOnActorSpawnedHandler() const;
486 void RemoveOnActorSpawnedHander() const {}
487
495 /*mutable FOnActorSpawned*/ void OnActorSpawned();
496 };
497}
#define KARMA_API
Defining Karma's API macro for storage class information.
Definition Core.h:41
#define FORCEINLINE
Typical inlining macro for clarity.
Definition Core.h:157
#define DECLARE_KARMA_CLASS(TClass, TSuperClass)
Karma's gamecode object class declaration.
Definition GFrameworkMacros.h:44
This file contains the class UObject along with helper functions.
This file contains the class TSubclassOf and relevant helpers.
FORCEINLINE T * CastChecked(const U &Src, ECastCheckedType::Type CheckType=ECastCheckedType::NullChecked)
Definition UObjectGlobals.h:704
EObjectFlags
Flags describing an object instance.
Definition UObjectGlobals.h:183
Actor is the base class for an object that can be placed or spawned in a level.
Definition Actor.h:34
Definition Transform.h:116
Template to allow TClassType's to be passed around with type safety.
Definition SubClassOf.h:119
A component that spawns an Actor when registered, and destroys it when unregistered.
Definition ChildActorComponent.h:25
An object class.
Definition Class.h:158
A high-level manager object for an instance of the running game.
Definition GameInstance.h:28
A Level is a collection of Actors (lights, volumes, mesh instances etc.). Multiple Levels can be load...
Definition Level.h:30
UObject()
Definition Object.cpp:10
A generic outer for UObjects, for instance UWorld.
Definition Package.h:23
The World is the top level object representing a map or a sandbox in which Actors and Components will...
Definition World.h:150
void SetGameInstance(UGameInstance *NewGI)
Definition World.h:202
uint8_t m_bBegunPlay
Definition World.h:262
AActor * SpawnActor(UClass *Class, FTransform const *Transform, const FActorSpawnParameters &SpawnParameters=FActorSpawnParameters())
Definition World.cpp:34
EWorldType::Type m_WorldType
Definition World.h:265
UWorld()
Definition World.cpp:19
uint8_t m_bIsTearingDown
Definition World.h:253
FORCEINLINE ULevel * GetCurrentLevel() const
Definition World.h:372
ULevel * GetPersistentLevel() const
Definition World.h:195
FORCEINLINE double GetTimeSeconds() const
Definition World.h:362
uint8_t m_bActorsInitialized
Definition World.h:259
T * SpawnActor(UClass *Class, const FActorSpawnParameters &SpawnParameters=FActorSpawnParameters())
Definition World.h:184
Type
Definition KarmaTypes.h:47
@ NullAllowed
Definition UObjectGlobals.h:688
URL structure.
Definition KarmaTypes.h:487
Struct of optional parameters passed to SpawnActor function(s).
Definition World.h:32
class UChildActorComponent * m_OverrideParentComponent
Definition World.h:79
EObjectFlags m_ObjectFlags
Definition World.h:114
APawn * m_Instigator
Definition World.h:59
uint8_t m_bNoFail
Definition World.h:130
ESpawnActorNameMode
Modes that SpawnActor can use the supplied name when it is not None.
Definition World.h:96
ULevel * m_OverrideLevel
Definition World.h:66
bool IsRemoteOwned() const
Getter for m_bRemoteOwned.
Definition World.h:125
std::string m_Name
Definition World.h:40
uint8_t m_bDeferConstruction
Definition World.h:137
AActor * m_Template
Definition World.h:47
AActor * m_Owner
Definition World.h:53
ESpawnActorNameMode m_NameMode
Definition World.h:111
uint32_t bShouldSimulatePhysics
Definition World.h:308
TSubclassOf< class AGameModeBase > DefaultGameMode
Definition World.h:326
uint32_t bCreateAISystem
Definition World.h:305
uint32_t bRequiresHitProxies
Definition World.h:296
uint32_t bInitializeScenes
Definition World.h:290
uint32_t bCreateWorldPartition
Definition World.h:323
uint32_t bCreateNavigation
Definition World.h:302
uint32_t bCreateFXSystem
Definition World.h:320
uint32_t bForceUseMovementComponentInNonGameWorld
Definition World.h:314
uint32_t bCreatePhysicsScene
Definition World.h:299
uint32_t bEnableTraceCollision
Definition World.h:311
uint32_t bAllowAudioPlayback
Definition World.h:293
uint32_t bTransactional
Definition World.h:317