47#define HAS(type) GetComponent<type>(Component::c##type)
56 auto
update(
float dt) ->
void override;
57 auto
onUpdate(
float dt) ->
void override;
62 auto render() ->
void override;
65 auto onSceneStart(
const std::string& sceneName) ->
void override;
66 auto onSceneExit(
const std::string& sceneName) ->
void override;
69 auto load(
const Stream& stream) ->
void override;
70 auto save(
Stream& stream)
const ->
void override;
74 auto
destroy() ->
void override;
100 auto
pop() -> std::unique_ptr<
Node>;
111 template <typename
type>
114 return static_cast<type*
>(this->
Get(typeId));
122 [[nodiscard]]
auto addChild(std::unique_ptr<GameObject> newChild) ->
bool override;
124 auto addChild(std::unique_ptr<Entity> newChild) -> bool;
133 auto addComponent(std::unique_ptr<Component>&& component) -> void;
141 auto addComponent(std::unique_ptr<GameObject> component) -> bool;
148 template <std::derived_from<Component> T>
160 template <std::derived_from<Component> T>
163 addComponent(std::unique_ptr<Component>(component.release()));
175 messaging->removeAll(&component);
189 template<
typename ActionType>
199 assert(actionList &&
"Tried adding an action to an entity without an actionList");
200 actionList->pushBack(action);
210 template<
typename ActionType>
219 assert(actionList &&
"failed adding an Action to an Entity");
275template<typename ActionType>
279 assert(actionList &&
"Tried adding an action to an entity without an actionList");
280 actionList->pushBack(action);
293template<
typename ActionType>
297 assert(actionList &&
"Tried adding an action to an entity without an actionList");
298 actionList->pushBack(action);
Component that stores all actions currently affecting the parent entity.
sys::Json Stream
Definition AudioObject.h:20
The class containing Json implemenation for building components.
The base class for components, holding all of their shared All components should inherit from this.
The class that holds the top node, and manages the main game loop, as well as startup and shutdown.
nlohmann::json json
Definition Json.cpp:19
An object that represents where a GameObject or a range of GameObjects exists in the Engine.
Component that stores all actions currently affecting the parent entity.
Definition ActionList.h:30
auto pushBack(const std::unique_ptr< Action > &newAction) -> void
Definition ActionList.cpp:159
Definition Component.h:28
@ cActionList
Definition Component.h:64
static auto getSystem() -> system *
A function to get a system.
Definition Engine.h:46
auto onSceneStart(const std::string &sceneName) -> void override
Hook that is called before the first frame a scene is run, but after the entire scene is loaded into ...
Definition Entity.cpp:462
auto update(float dt) -> void override
called once every frame.
Definition Entity.cpp:434
auto setShouldUpdate(bool _shouldUpdate) -> void override
set whether the Entity, its components, and its children Entities should update every frame
Definition Entity.cpp:237
auto showComponentsMenu() -> void
call showMenu() on all children
Definition Entity.cpp:366
auto addComponent(std::unique_ptr< Component > &&component) -> void
takes a component pointer, and adds it to the Entity.
Definition Entity.cpp:93
auto getParent() const -> Entity *override
Definition Entity.cpp:199
auto destroy() -> void override
Marks an GameObject to be destroyed.
Definition Entity.cpp:229
auto addAction(const ActionType &action) -> void
Adds a new action to an entity's ActionList component, while making sure the component has an ActionL...
Definition Entity.h:211
auto addComponentButton() -> void
A helper function for drawMenu() to make a button that lets you add components or entities.
Definition Entity.cpp:164
auto onRender() -> void override
called every frame after update has been called for every object.
Definition Entity.cpp:453
ChildrenHandeler< Component > components
Definition Entity.h:235
auto operator<<(const ActionType &action) -> Entity &
Adds a new action to this entity's ActionList component.
Definition Entity.h:196
auto load(const Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition Entity.cpp:482
auto setShouldReceiveMessages(bool _shouldReceiveMessages) -> void override
set whether the Entity, its components, and its children Entities should receive messages
Definition Entity.cpp:279
friend auto from_json(const json &j, Entity &obj) -> void
Definition Entity.cpp:526
auto render() -> void override
called every frame after update has been called for every object.
Definition Entity.cpp:446
auto onSceneExit(const std::string &sceneName) -> void override
Hook that is called right before a scene is unloaded To receive the hook, simply override the functio...
Definition Entity.cpp:467
auto for_each(std::function< void(GameObject &)> func) -> void override
applies a function to every child.
Definition Entity.cpp:472
auto deregisterComponents() const -> void
deregister every component from messaging system
Definition Entity.h:169
friend auto to_json(json &j, const Entity &obj) -> void
Definition Entity.cpp:518
auto setShouldRender(bool _shouldRender) -> void override
set whether the Entity, its components, and its children Entities should render every frame
Definition Entity.cpp:258
~Entity() override
Definition Entity.cpp:52
auto showMenu() -> void override
Called before update each frame, for calling ImGui editor code relevant to the gameObject.
Definition Entity.cpp:395
Entity()
Definition Entity.cpp:34
auto onUpdate(float dt) -> void override
called once every frame.
Definition Entity.cpp:441
auto addComponent(const T &component) -> void
takes a component directly and adds it to the Entity.
Definition Entity.h:149
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition Entity.cpp:307
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition Entity.h:59
auto addComponent(std::unique_ptr< T > component) -> void
allows adding components to objects with unique_ptrs to concrete components
Definition Entity.h:161
auto GetComponent(Component::ComponentTypeEnum typeId) -> type *
the implementation of the GetComponent Template
Definition Entity.h:112
auto addChild(std::unique_ptr< GameObject > newChild) -> bool override
adds either a component to the entity, or another game object as a child
Definition Entity.cpp:60
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition Entity.cpp:487
auto pop() -> std::unique_ptr< Node >
Removes the Entity from the Engine tree, and gives ownership to the caller.
Definition Entity.cpp:300
auto onEnterEngine() -> void override
hook that is called when a GameObject enters the Engine tree.
Definition Entity.cpp:457
auto getChildren() const -> std::shared_ptr< std::vector< GameObject * > > override
Definition Entity.cpp:130
auto showUpdateRenderMessagesFlagButtons() -> void
A helper function for showMenu() to make buttons for toggling shouldRender, shouldUpdate,...
Definition Entity.cpp:315
auto showNameInputMenu() -> void
A helper function for showMenu() to show a input field for the entity name.
Definition Entity.cpp:380
auto Get(Component::ComponentTypeEnum typeId) -> Component *
Definition Entity.cpp:150
the base class for the engine, most things inherit from this.
Definition GameObject.h:77
friend ChildrenHandeler
Definition GameObject.h:87
GameObject(std::string typeName, gobj::Type parentType, gobj::Type type)
constructor for gameobject.
Definition GameObject.cpp:23
gobj::Type type
What type this GameObject is, for type checking, and safe casts.
Definition GameObject.h:507
Manages the heirarchical structure between Systems and Entities.
Definition Node.h:41
static auto make(const std::string &name) -> std::unique_ptr< T >
create an object and heap allocate it.
Definition Factory.h:44
namespace for things relating to GameObject, other than GameObject itself
Definition Entity.h:309
auto moveEntity(Entity &entityToMove, Entity &newParent) -> void
Makes the provided entity a child of another entity.
Definition Entity.cpp:533
auto entityTest() -> void
Definition Entity.cpp:492