Karma Engine
Loading...
Searching...
No Matches
World.h
1#pragma once
2
3#include "krpch.h"
4
5#include "Object.h"
6#include "SubClassOf.h"
7
8namespace Karma
9{
10 class AActor;
11 class FTransform;
12 struct FActorSpawnParameters;
13 class APawn;
14 class ULevel;
15 class UClass;
16 class UGameInstance;
17
18 /* Struct of optional parameters passed to SpawnActor function(s). */
19 struct KARMA_API FActorSpawnParameters
20 {
22
23 /* A name to assign as the Name of the Actor being spawned. If no value is specified, the name of the spawned Actor will be automatically generated using the form [Class]_[Number]. */
24 std::string m_Name;
25
26 /* An Actor to use as a template when spawning the new Actor. The spawned Actor will be initialized using the property values of the template Actor. If left NULL the class default object (CDO) will be used to initialize the spawned Actor. */
27 AActor* m_Template;
28
29 /* The Actor that spawned this Actor. (Can be left as NULL). */
30 AActor* m_Owner;
31
32 /* The APawn that is responsible for damage done by the spawned Actor. (Can be left as NULL). */
33 APawn* m_Instigator;
34
35 /* The ULevel to spawn the Actor in, i.e. the Outer of the Actor. If left as NULL the Outer of the Owner is used. If the Owner is NULL the persistent level is used. */
36 ULevel* m_OverrideLevel;
37
38#if WITH_EDITOR
39 /* The UPackage to set the Actor in. If left as NULL the Package will not be set and the actor will be saved in the same package as the persistent level. */
40 class UPackage* OverridePackage;
41
43 FGuid OverrideActorGuid;
44#endif
45
46 /* The parent component to set the Actor in. */
47 class UChildActorComponent* m_OverrideParentComponent;
48
50 // Need physics
51 //ESpawnActorCollisionHandlingMethod SpawnCollisionHandlingOverride;
52
53 private:
54
55 //friend class UPackageMapClient;
56
57 /* 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. */
58 uint8_t m_bRemoteOwned : 1;
59
60 public:
61
62 /* Modes that SpawnActor can use the supplied name when it is not None. */
63 enum class ESpawnActorNameMode : uint8_t
64 {
65 /* Fatal if unavailable, application will assert */
66 Required_Fatal,
67
68 /* Report an error return null if unavailable */
69 Required_ErrorAndReturnNull,
70
71 /* Return null if unavailable */
72 Required_ReturnNull,
73
74 /* If the supplied Name is already in use the generate an unused one using the supplied version as a base */
75 Requested
76 };
77
78 /* In which way should SpawnActor should treat the supplied Name if not none. */
79 ESpawnActorNameMode m_NameMode;
80
81 /* Flags used to describe the spawned actor/object instance. */
82 EObjectFlags m_ObjectFlags;
83
84 /* Custom function allowing the caller to specific a function to execute post actor construction but before other systems see this actor spawn. */
85 // maybe later
86 //TFunction<void(AActor*)> CustomPreSpawnInitalization;
87
88 bool IsRemoteOwned() const { return m_bRemoteOwned; }
89
90 /* Determines whether spawning will not fail if certain conditions are not met. If true, spawning will not fail because the class being spawned is `bStatic=true` or because the class of the template Actor is not the same as the class of the Actor being spawned. */
91 uint8_t m_bNoFail : 1;
92
93 /* Determines whether the construction script will be run. If true, the construction script will not be run on the spawned Actor. Only applicable if the Actor is being spawned from a Blueprint. */
94 uint8_t m_bDeferConstruction : 1;
95 };
96
107 class KARMA_API UWorld : public UObject
108 {
109 DECLARE_KARMA_CLASS(UWorld, UObject)
110
111 public:
112 UWorld();
113
123 AActor* SpawnActor(UClass* Class, FTransform const* Transform, const FActorSpawnParameters& SpawnParameters = FActorSpawnParameters());
124
129 template< class T >
130 T* SpawnActor(UClass* Class, const FActorSpawnParameters& SpawnParameters = FActorSpawnParameters())
131 {
132 return CastChecked<T>(SpawnActor(Class, nullptr, SpawnParameters), ECastCheckedType::NullAllowed);
133 }
134
135 ULevel* GetPersistentLevel() const { return m_PersistentLevel; }
136
138 inline void SetGameInstance(UGameInstance* NewGI)
139 {
140 m_OwningGameInstance = NewGI;
141 }
142
143 private:
144//#if WITH_EDITORONLY_DATA
146 ULevel* m_CurrentLevel;
147//#endif
148
150 ULevel* m_PersistentLevel;
151
152
153 UGameInstance* m_OwningGameInstance;
154
156 // Time variables
158 double m_TimeSeconds;
159
161 double m_UnpausedTimeSeconds;
162
164 double m_RealTimeSeconds;
165
167 double m_AudioTimeSeconds;
168
170 float m_DeltaRealTimeSeconds;
171
173 float m_DeltaTimeSeconds;
174
176 double m_PauseDelay;
177
178 bool m_bIsPaused;
179
180 public:
182 uint8_t m_bIsTearingDown : 1;
183
185 //double m_TimeSeconds;
186
189
191 uint8_t m_bBegunPlay : 1;
192
195
197 //TEnumAsByte<ERHIFeatureLevel::Type> FeatureLevel;
198
201 {
203 : bInitializeScenes(true)
204 , bAllowAudioPlayback(true)
205 , bRequiresHitProxies(true)
206 , bCreatePhysicsScene(true)
207 , bCreateNavigation(true)
208 , bCreateAISystem(true)
209 , bShouldSimulatePhysics(true)
210 , bEnableTraceCollision(false)
211 , bForceUseMovementComponentInNonGameWorld(false)
212 , bTransactional(true)
213 , bCreateFXSystem(true)
214 , bCreateWorldPartition(false)
215 {
216 }
217
219 uint32_t bInitializeScenes : 1;
220
223
226
229
231 uint32_t bCreateNavigation : 1;
232
234 uint32_t bCreateAISystem : 1;
235
238
241
244
246 uint32_t bTransactional : 1;
247
249 uint32_t bCreateFXSystem : 1;
250
253
256
257 InitializationValues& InitializeScenes(const bool bInitialize) { bInitializeScenes = bInitialize; return *this; }
258 InitializationValues& AllowAudioPlayback(const bool bAllow) { bAllowAudioPlayback = bAllow; return *this; }
259 InitializationValues& RequiresHitProxies(const bool bRequires) { bRequiresHitProxies = bRequires; return *this; }
260 InitializationValues& CreatePhysicsScene(const bool bCreate) { bCreatePhysicsScene = bCreate; return *this; }
261 InitializationValues& CreateNavigation(const bool bCreate) { bCreateNavigation = bCreate; return *this; }
262 InitializationValues& CreateAISystem(const bool bCreate) { bCreateAISystem = bCreate; return *this; }
263 InitializationValues& ShouldSimulatePhysics(const bool bInShouldSimulatePhysics) { bShouldSimulatePhysics = bInShouldSimulatePhysics; return *this; }
264 InitializationValues& EnableTraceCollision(const bool bInEnableTraceCollision) { bEnableTraceCollision = bInEnableTraceCollision; return *this; }
265 InitializationValues& ForceUseMovementComponentInNonGameWorld(const bool bInForceUseMovementComponentInNonGameWorld) { bForceUseMovementComponentInNonGameWorld = bInForceUseMovementComponentInNonGameWorld; return *this; }
266 InitializationValues& SetTransactional(const bool bInTransactional) { bTransactional = bInTransactional; return *this; }
267 InitializationValues& CreateFXSystem(const bool bCreate) { bCreateFXSystem = bCreate; return *this; }
268 InitializationValues& CreateWorldPartition(const bool bCreate) { bCreateWorldPartition = bCreate; return *this; }
269 InitializationValues& SetDefaultGameMode(TSubclassOf<class AGameModeBase> GameMode) { DefaultGameMode = GameMode; return *this; }
270 };
271
276 void Tick(/*ELevelTick TickType,*/ float DeltaSeconds);
277
278 public:
280 // UWorld inlines:
281
282 FORCEINLINE double GetTimeSeconds() const
283 {
284 return m_TimeSeconds;
285 }
286
287 FORCEINLINE ULevel* GetCurrentLevel() const
288 {
289 return m_CurrentLevel;
290 }
291
292 public:
294 bool AreActorsInitialized() const;
295
300 //void InitializeNewWorld(const InitializationValues IVS = InitializationValues(), bool bInSkipInitWorld = false);
301
303 bool HasBegunPlay() const;
304
308 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);
309
313 void InitializeNewWorld(const InitializationValues IVS = InitializationValues(), bool bInSkipInitWorld = false);
314
321 void InitializeActorsForPlay(const FURL& InURL, bool bResetTime = true/*, FRegisterComponentContext* Context = nullptr*/);
322
327 void ModifyLevel(ULevel* Level) const;
328
330 bool IsGameWorld() const;
331
339 void RemoveActor( AActor* Actor, bool bShouldModifyLevel ) const;
340
357 bool ShivaActor(AActor* Actor, bool bNetForce = false, bool bShouldModifyLevel = true);
358
364 void AddOnActorSpawnedHandler() const;
365 void RemoveOnActorSpawnedHander() const {}
366
374 /*mutable FOnActorSpawned*/ void OnActorSpawned();
375 };
376}
This file contains the class UObject along with helper functions.
Definition Actor.h:22
Definition Transform.h:107
Definition SubClassOf.h:64
Definition ChildActorComponent.h:14
Definition Class.h:99
Definition GameInstance.h:16
Definition Level.h:21
The base class of all the game code relevant objects.
Definition Object.h:106
Definition Package.h:9
Definition World.h:108
void SetGameInstance(UGameInstance *NewGI)
Definition World.h:138
uint8_t m_bBegunPlay
Definition World.h:191
EWorldType::Type m_WorldType
Definition World.h:194
uint8_t m_bIsTearingDown
Definition World.h:182
uint8_t m_bActorsInitialized
Definition World.h:188
T * SpawnActor(UClass *Class, const FActorSpawnParameters &SpawnParameters=FActorSpawnParameters())
Definition World.h:130
Type
Definition KarmaTypes.h:31
Definition KarmaTypes.h:378
Definition World.h:20
uint32_t bShouldSimulatePhysics
Definition World.h:237
TSubclassOf< class AGameModeBase > DefaultGameMode
Definition World.h:255
uint32_t bCreateAISystem
Definition World.h:234
uint32_t bRequiresHitProxies
Definition World.h:225
uint32_t bInitializeScenes
Definition World.h:219
uint32_t bCreateWorldPartition
Definition World.h:252
uint32_t bCreateNavigation
Definition World.h:231
uint32_t bCreateFXSystem
Definition World.h:249
uint32_t bForceUseMovementComponentInNonGameWorld
Definition World.h:243
uint32_t bCreatePhysicsScene
Definition World.h:228
uint32_t bEnableTraceCollision
Definition World.h:240
uint32_t bAllowAudioPlayback
Definition World.h:222
uint32_t bTransactional
Definition World.h:246