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 "Karma/Core.h"
14#include "Karma/Log.h"
16#include "Object.h"
18
19namespace Karma
20{
21 class UActorComponent;
22 class ULevel;
23 class APawn;
24 class FTransform;
25 class UWorld;
27
34 class KARMA_API AActor : public UObject
35 {
37
38 public:
44 AActor();
45
46 private:
57
64 APawn* m_Instigator;
65
71 uint8_t m_bHasFinishedSpawning : 1;
72
79 uint8_t m_bActorInitialized : 1;
80
85 static uint32_t m_BeginPlayCallDepth;
86
87
94 std::shared_ptr<UChildActorComponent> m_ParentComponent;
95
103
109 enum class EActorBeginPlayState : uint8_t
110 {
111 HasNotBegunPlay,
112 BeginningPlay,
113 HasBegunPlay,
114 };
115
122 EActorBeginPlayState m_ActorHasBegunPlay : 2;
123
130 uint8_t m_bActorBeginningPlayFromLevelStreaming : 1;
131
137 uint8_t m_bActorWantsDestroyDuringBeginPlay : 1;
138
144 uint8_t m_bAutoDestroyWhenFinished : 1;
145
146 public:
147
154 ULevel* GetLevel() const;
155
171 void PostSpawnInitialize(FTransform const& SpawnTransform, AActor* InOwner, APawn* InInstigator, bool bRemoteOwned, bool bNoFail, bool bDeferConstruction);
172
178 virtual UWorld* GetWorld() const override final;
179
185 bool HasActorBegunPlay() const { return m_ActorHasBegunPlay == EActorBeginPlayState::HasBegunPlay; }
186
192 bool IsActorBeginningPlay() const { return m_ActorHasBegunPlay == EActorBeginPlayState::BeginningPlay; }
193
200 void DispatchBeginPlay(bool bFromLevelStreaming = false);
201
208 virtual void SetOwner(AActor* NewOwner);
209
217 void FinishSpawning(const FTransform& Transform, bool bIsDefaultTransform = false/*, const FComponentInstanceDataCache* InstanceDataCache = nullptr*/);
218
227 inline bool IsOwnedBy(const AActor* TestOwner) const
228 {
229 for (const AActor* Arg = this; Arg; Arg = Arg->m_Owner)
230 {
231 if (Arg == TestOwner)
232 {
233 return true;
234 }
235 }
236 return false;
237 }
238
244 void PostActorConstruction();
245
254 void GetComponents(KarmaVector<USceneComponent*>& OutComponents) const // make use of smartpointer ?
255 {
256 // We should consider removing this function. It's not really hurting anything by existing but the one above it was added so that
257 // we weren't assuming T*, preventing TObjectPtrs from working for this function. The only downside is all the people who force the
258 // template argument with GetComponents's code suddenly not compiling with no clear error message.
259
260 OutComponents.SmartReset();
261
262 // Our own implementation, different from UE, maybe sync in future
263 typename std::vector<std::shared_ptr<UActorComponent>>::const_iterator iterator = m_OwnedComponents.GetElements().begin();
264
265 USceneComponent* tempSceneComponent;
266
267 while (iterator != m_OwnedComponents.GetElements().end())
268 {
269 tempSceneComponent = static_cast<USceneComponent*>((*iterator).get());
270 if (tempSceneComponent != nullptr)
271 {
272 OutComponents.Add(tempSceneComponent);
273 }
274 }
275
276 /*
277 ForEachComponent_Internal<T>(T::StaticClass(), bIncludeFromChildActors, [&](T* InComp)
278 {
279 OutComponents.Add(InComp);
280 });
281 */
282 }
283
290 void GetComponents(KarmaVector<UActorComponent*>& OutComponents) const // make use of smartpointer ?
291 {
292 // We should consider removing this function. It's not really hurting anything by existing but the one above it was added so that
293 // we weren't assuming T*, preventing TObjectPtrs from working for this function. The only downside is all the people who force the
294 // template argument with GetComponents's code suddenly not compiling with no clear error message.
295
296 OutComponents.SmartReset();
297
298 // Our own implementation, different from UE, maybe sync in future
299 typename std::vector<std::shared_ptr<UActorComponent>>::const_iterator iterator = m_OwnedComponents.GetElements().begin();
300
301 USceneComponent* tempSceneComponent;
302
303 while (iterator != m_OwnedComponents.GetElements().end())
304 {
305 tempSceneComponent = static_cast<USceneComponent*>((*iterator).get());
306 if (tempSceneComponent != nullptr)
307 {
308 OutComponents.Add(tempSceneComponent);
309 }
310
311 // shouldn't we have iterator++
312 }
313 }
314
321 void SetInstigator(APawn* InInstigator);
322
330
337 bool SetRootComponent(USceneComponent* NewRootComponent);
338
345 static void DispatchOnComponentsCreated(AActor* NewActor);
346
354 {
355 return ActorToWorld();
356 }
357
373 bool SetActorTransform(const FTransform& NewTransform/*, bool bSweep=false, FHitResult* OutSweepHitResult=nullptr, ETeleportType Teleport = ETeleportType::None*/);
374
378 bool SetActorLocation(const glm::vec3& NewLocation);
379
380 bool SetActorRotation(TRotator NewRotation);
381
383 void SetActorScale3D(glm::vec3 NewScale3D);
384
391 inline const FTransform& ActorToWorld() const
392 {
393 return (m_RootComponent ? m_RootComponent->GetComponentTransform() : FTransform::m_Identity);
394 }
395
402 void InitializeComponents();
403
410 virtual void PostInitializeComponents();
411
420 AActor* GetParentActor() const;
421
428 UChildActorComponent* GetParentComponent() const;
429
437 void RemoveOwnedComponent(std::shared_ptr<UActorComponent> Component);
438
444 bool GetAutoDestroyWhenFinished() const { return m_bAutoDestroyWhenFinished; }
445
452 static USceneComponent* FixupNativeActorComponents(AActor* Actor);
453
460 bool CanTick() const { return m_bCanEverTick; }
461
468 void DisableTick(bool bDisable) { m_bCanEverTick = !bDisable; }
469
478 virtual void Tick(float DeltaSeconds);
479
480 public:
486
491 AActor* m_Owner;// UE uses smart pointer
492
498
499 protected:
505 virtual void BeginPlay();
506
511 //void ReceiveBeginPlay();
512
513 protected:
521
522 bool m_bCanEverTick;
523 };
524}
This file contains the macros for Karma's classes' general purpose use, including assertions and stor...
#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:170
#define DECLARE_KARMA_CLASS(TClass, TSuperClass)
Karma's gamecode object class declaration.
Definition GFrameworkMacros.h:45
This file contains the custom types used in Engine's logic.
This file contains the Log class. I want to imagine the Log pronounciation match with that of that ht...
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:35
USceneComponent * m_RootComponent
Definition Actor.h:520
ULevel * GetLevel() const
Definition Actor.cpp:18
AActor()
Definition Actor.cpp:12
bool GetAutoDestroyWhenFinished() const
Definition Actor.h:444
void DisableTick(bool bDisable)
Definition Actor.h:468
const FTransform & GetTransform() const
Definition Actor.h:353
virtual void BeginPlay()
Definition Actor.cpp:381
KarmaVector< AActor * > m_Children
Definition Actor.h:497
bool IsOwnedBy(const AActor *TestOwner) const
Definition Actor.h:227
AActor * m_Owner
Definition Actor.h:491
bool HasActorBegunPlay() const
Definition Actor.h:185
void GetComponents(KarmaVector< UActorComponent * > &OutComponents) const
Definition Actor.h:290
void PostSpawnInitialize(FTransform const &SpawnTransform, AActor *InOwner, APawn *InInstigator, bool bRemoteOwned, bool bNoFail, bool bDeferConstruction)
Definition Actor.cpp:437
const FTransform & ActorToWorld() const
Definition Actor.h:391
void GetComponents(KarmaVector< USceneComponent * > &OutComponents) const
Definition Actor.h:254
bool CanTick() const
Definition Actor.h:460
float m_CreationTime
Definition Actor.h:485
virtual UWorld * GetWorld() const override final
Definition Actor.cpp:23
FORCEINLINE USceneComponent * GetRootComponent() const
Definition Actor.h:329
bool IsActorBeginningPlay() const
Definition Actor.h:192
Transform composed of Scale, Rotation (as a quaternion), and Translation.
Definition Transform.h:125
ActorComponent is the base class for components that define reusable behavior that can be added to di...
Definition ActorComponent.h:61
A component that spawns an Actor when registered, and destroys it when unregistered.
Definition ChildActorComponent.h:23
A Level is a collection of Actors (lights, volumes, mesh instances etc.). Multiple Levels can be load...
Definition Level.h:28
UObject()
Definition Object.cpp:10
A SceneComponent has a transform and supports attachment, but has no rendering or collision capabilit...
Definition SceneComponent.h:42
The World is the top level object representing a map or a sandbox in which Actors and Components will...
Definition World.h:148
Karma's std::vector wrapper with additional functionalities.
Definition KarmaTypes.h:243
Implements a container for rotation information.
Definition Transform.h:66