KarmaEngine
Game Engine for practical learning and research purposes
Loading...
Searching...
No Matches
Actor.h
Go to the documentation of this file.
1
10
11#pragma once
12
13#include "krpch.h"
14#include "Object.h"
15
17
18namespace Karma
19{
20 class UActorComponent;
21 class ULevel;
22 class APawn;
23 class FTransform;
24 class UWorld;
26
33 class KARMA_API AActor : public UObject
34 {
36
37 public:
43 AActor();
44
45 private:
56
63 APawn* m_Instigator;
64
70 uint8_t m_bHasFinishedSpawning : 1;
71
78 uint8_t m_bActorInitialized : 1;
79
84 static uint32_t m_BeginPlayCallDepth;
85
86
93 std::shared_ptr<UChildActorComponent> m_ParentComponent;
94
102
108 enum class EActorBeginPlayState : uint8_t
109 {
110 HasNotBegunPlay,
111 BeginningPlay,
112 HasBegunPlay,
113 };
114
121 EActorBeginPlayState m_ActorHasBegunPlay : 2;
122
129 uint8_t m_bActorBeginningPlayFromLevelStreaming : 1;
130
136 uint8_t m_bActorWantsDestroyDuringBeginPlay : 1;
137
143 uint8_t m_bAutoDestroyWhenFinished : 1;
144
145 public:
152 ULevel* GetLevel() const;
153
169 void PostSpawnInitialize(FTransform const& SpawnTransform, AActor* InOwner, APawn* InInstigator, bool bRemoteOwned, bool bNoFail, bool bDeferConstruction);
170
176 virtual UWorld* GetWorld() const override final;
177
183 bool HasActorBegunPlay() const { return m_ActorHasBegunPlay == EActorBeginPlayState::HasBegunPlay; }
184
190 bool IsActorBeginningPlay() const { return m_ActorHasBegunPlay == EActorBeginPlayState::BeginningPlay; }
191
198 void DispatchBeginPlay(bool bFromLevelStreaming = false);
199
206 virtual void SetOwner(AActor* NewOwner);
207
215 void FinishSpawning(const FTransform& Transform, bool bIsDefaultTransform = false/*, const FComponentInstanceDataCache* InstanceDataCache = nullptr*/);
216
225 inline bool IsOwnedBy(const AActor* TestOwner) const
226 {
227 for (const AActor* Arg = this; Arg; Arg = Arg->m_Owner)
228 {
229 if (Arg == TestOwner)
230 {
231 return true;
232 }
233 }
234 return false;
235 }
236
242 void PostActorConstruction();
243
252 void GetComponents(KarmaVector<USceneComponent*>& OutComponents) const // make use of smartpointer ?
253 {
254 // We should consider removing this function. It's not really hurting anything by existing but the one above it was added so that
255 // we weren't assuming T*, preventing TObjectPtrs from working for this function. The only downside is all the people who force the
256 // template argument with GetComponents's code suddenly not compiling with no clear error message.
257
258 OutComponents.SmartReset();
259
260 // Our own implementation, different from UE, maybe sync in future
261 typename std::vector<std::shared_ptr<UActorComponent>>::const_iterator iterator = m_OwnedComponents.GetElements().begin();
262
263 USceneComponent* tempSceneComponent;
264
265 while (iterator != m_OwnedComponents.GetElements().end())
266 {
267 tempSceneComponent = static_cast<USceneComponent*>((*iterator).get());
268 if (tempSceneComponent != nullptr)
269 {
270 OutComponents.Add(tempSceneComponent);
271 }
272 }
273
274 /*
275 ForEachComponent_Internal<T>(T::StaticClass(), bIncludeFromChildActors, [&](T* InComp)
276 {
277 OutComponents.Add(InComp);
278 });
279 */
280 }
281
288 void GetComponents(KarmaVector<UActorComponent*>& OutComponents) const // make use of smartpointer ?
289 {
290 // We should consider removing this function. It's not really hurting anything by existing but the one above it was added so that
291 // we weren't assuming T*, preventing TObjectPtrs from working for this function. The only downside is all the people who force the
292 // template argument with GetComponents's code suddenly not compiling with no clear error message.
293
294 OutComponents.SmartReset();
295
296 // Our own implementation, different from UE, maybe sync in future
297 typename std::vector<std::shared_ptr<UActorComponent>>::const_iterator iterator = m_OwnedComponents.GetElements().begin();
298
299 USceneComponent* tempSceneComponent;
300
301 while (iterator != m_OwnedComponents.GetElements().end())
302 {
303 tempSceneComponent = static_cast<USceneComponent*>((*iterator).get());
304 if (tempSceneComponent != nullptr)
305 {
306 OutComponents.Add(tempSceneComponent);
307 }
308 }
309 }
310
317 void SetInstigator(APawn* InInstigator);
318
326
333 bool SetRootComponent(USceneComponent* NewRootComponent);
334
341 static void DispatchOnComponentsCreated(AActor* NewActor);
342
350 {
351 return ActorToWorld();
352 }
353
360 inline const FTransform& ActorToWorld() const
361 {
362 return (m_RootComponent ? m_RootComponent->GetComponentTransform() : FTransform::m_Identity);
363 }
364
371 void InitializeComponents();
372
379 virtual void PostInitializeComponents();
380
389 AActor* GetParentActor() const;
390
397 UChildActorComponent* GetParentComponent() const;
398
406 void RemoveOwnedComponent(std::shared_ptr<UActorComponent> Component);
407
413 bool GetAutoDestroyWhenFinished() const { return m_bAutoDestroyWhenFinished; }
414
421 static USceneComponent* FixupNativeActorComponents(AActor* Actor);
422
429 bool CanTick() const { return m_bCanEverTick; }
430
437 void DisableTick(bool bDisable) { m_bCanEverTick = !bDisable; }
438
447 virtual void Tick(float DeltaSeconds);
448
449 public:
455
460 AActor* m_Owner;// UE uses smart pointer
461
467
468 protected:
474 virtual void BeginPlay();
475
480 //void ReceiveBeginPlay();
481
482 protected:
490
491 bool m_bCanEverTick;
492 };
493}
#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 USceneComponent.
Actor is the base class for an object that can be placed or spawned in a level.
Definition Actor.h:34
USceneComponent * m_RootComponent
Definition Actor.h:489
ULevel * GetLevel() const
Definition Actor.cpp:18
AActor()
Definition Actor.cpp:12
bool GetAutoDestroyWhenFinished() const
Definition Actor.h:413
void DisableTick(bool bDisable)
Definition Actor.h:437
const FTransform & GetTransform() const
Definition Actor.h:349
virtual void BeginPlay()
Definition Actor.cpp:370
KarmaVector< AActor * > m_Children
Definition Actor.h:466
bool IsOwnedBy(const AActor *TestOwner) const
Definition Actor.h:225
AActor * m_Owner
Definition Actor.h:460
bool HasActorBegunPlay() const
Definition Actor.h:183
void GetComponents(KarmaVector< UActorComponent * > &OutComponents) const
Definition Actor.h:288
void PostSpawnInitialize(FTransform const &SpawnTransform, AActor *InOwner, APawn *InInstigator, bool bRemoteOwned, bool bNoFail, bool bDeferConstruction)
Definition Actor.cpp:426
const FTransform & ActorToWorld() const
Definition Actor.h:360
void GetComponents(KarmaVector< USceneComponent * > &OutComponents) const
Definition Actor.h:252
bool CanTick() const
Definition Actor.h:429
float m_CreationTime
Definition Actor.h:454
virtual UWorld * GetWorld() const override final
Definition Actor.cpp:23
FORCEINLINE USceneComponent * GetRootComponent() const
Definition Actor.h:325
bool IsActorBeginningPlay() const
Definition Actor.h:190
Definition Transform.h:116
ActorComponent is the base class for components that define reusable behavior that can be added to di...
Definition ActorComponent.h:47
A component that spawns an Actor when registered, and destroys it when unregistered.
Definition ChildActorComponent.h:25
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 SceneComponent has a transform and supports attachment, but has no rendering or collision capabilit...
Definition SceneComponent.h:44
The World is the top level object representing a map or a sandbox in which Actors and Components will...
Definition World.h:150
Karma's std::vector wrapper.
Definition KarmaTypes.h:152