49#define HAS(type) GetComponent<type>(Component::c##type)
58 auto
update(
float dt) ->
void override;
59 auto
onUpdate(
float dt) ->
void override;
64 auto render() ->
void override;
67 auto onSceneStart(
const std::string& sceneName) ->
void override;
68 auto onSceneExit(
const std::string& sceneName) ->
void override;
71 auto load(
const Stream& stream) ->
void override;
72 auto save(
Stream& stream)
const ->
void override;
76 auto
destroy() ->
void override;
102 auto
pop() -> std::unique_ptr<
Node>;
113 template <typename
type>
116 return static_cast<type*
>(this->
Get(typeId));
119 template <
typename comp>
122 auto typeId = comp::getEnum();
123 return static_cast<comp*
>(this->
Get(typeId));
131 [[nodiscard]]
auto addChild(std::unique_ptr<GameObject> newChild) ->
bool override;
133 auto addChild(std::unique_ptr<Entity> newChild) -> bool;
142 auto addComponent(std::unique_ptr<Component>&& component) -> void;
150 auto addComponent(std::unique_ptr<GameObject> component) -> bool;
157 template <std::derived_from<Component> T>
169 template <std::derived_from<Component> T>
172 addComponent(std::unique_ptr<Component>(component.release()));
180 auto popComponent(
const Key& key) -> std::unique_ptr<Component>;
191 messaging->removeAll(&component);
207#pragma region action_functions
209 template<
typename ActionType>
219 assert(actionList &&
"Tried adding an action to an entity without an actionList");
220 actionList->pushBack(action);
230 template<
typename ActionType>
239 assert(actionList &&
"failed adding an Action to an Entity");
247 template<
typename ActionType>
256 assert(actionList &&
"failed adding an Action to an Entity");
265 template<
typename ActionType>
274 assert(actionList &&
"failed adding an Action to an Entity");
302 return actionList->getAction(actionName);
317 actionList->removeAction(actionName);
337 auto contains(
const std::string& scriptName) -> bool;
411template<typename ActionType>
415 assert(actionList &&
"Tried adding an action to an entity without an actionList");
416 actionList->pushBack(action);
429template<
typename ActionType>
432 auto actionList = entity->GetComponent<
ActionList>(Component::cActionList);
433 assert(actionList &&
"Tried adding an action to an entity without an actionList");
434 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:205
auto pushFront(const std::unique_ptr< Action > &newAction) -> void
Definition ActionList.cpp:211
Definition Component.h:32
static auto getSystem() -> system *
A function to get a system.
Definition Engine.h:50
auto clearActions() -> void
Removes all actions that an entity has inside its ActionList.
Definition Entity.h:282
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:591
auto removeAction(const std::string &actionName) -> void
Removes the first action of a specific type.
Definition Entity.h:313
auto update(float dt) -> void override
called once every frame.
Definition Entity.cpp:563
auto contains(const std::string &scriptName) -> bool
checks if a script is on an entity
Definition Entity.cpp:400
auto setShouldUpdate(bool _shouldUpdate) -> void override
set whether the Entity, its components, and its children Entities should update every frame
Definition Entity.cpp:245
auto showComponentsMenu() -> void
call showMenu() on all children
Definition Entity.cpp:379
auto addComponent(std::unique_ptr< Component > &&component) -> void
takes a component pointer, and adds it to the Entity.
Definition Entity.cpp:99
static auto bindLuaTypes(sol::state &lua) -> void
register Entity as a lua usertype
Definition Entity.cpp:418
auto getParent() const -> Entity *override
Definition Entity.cpp:207
auto destroy() -> void override
Marks an GameObject to be destroyed.
Definition Entity.cpp:237
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:231
auto addComponentButton() -> void
A helper function for drawMenu() to make a button that lets you add components or entities.
Definition Entity.cpp:191
auto onRender() -> void override
called every frame after update has been called for every object.
Definition Entity.cpp:582
auto getScript(const std::string &scriptName) -> Script &
get a script that's on an entity
Definition Entity.cpp:409
auto operator[](const std::string &scriptName) -> Script &
get a script that's on an entity gets a script on an entity
Definition Entity.cpp:395
ChildrenHandeler< Component > components
Definition Entity.h:362
auto operator<<(const ActionType &action) -> Entity &
Adds a new action to this entity's ActionList component.
Definition Entity.h:216
auto load(const Stream &stream) -> void override
Implementations will load the state of a GameObject from a th::Json Object.
Definition Entity.cpp:611
auto setShouldReceiveMessages(bool _shouldReceiveMessages) -> void override
set whether the Entity, its components, and its children Entities should receive messages
Definition Entity.cpp:287
friend auto from_json(const json &j, Entity &obj) -> void
Definition Entity.cpp:628
auto render() -> void override
called every frame after update has been called for every object.
Definition Entity.cpp:575
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:596
auto for_each(std::function< void(GameObject &)> func) -> void override
applies a function to every child.
Definition Entity.cpp:601
auto sendAddedComponentMessage(AddedComponentMessage &message) -> void
helper function for addComponent
Definition Entity.cpp:179
auto deregisterComponents() const -> void
deregister every component from messaging system
Definition Entity.h:185
friend auto to_json(json &j, const Entity &obj) -> void
Definition Entity.cpp:620
auto setShouldRender(bool _shouldRender) -> void override
set whether the Entity, its components, and its children Entities should render every frame
Definition Entity.cpp:266
auto addChildLua(std::unique_ptr< GameObject > &newChild) -> bool
wrapper for addChild to allow it to be bound and called in lua
Definition Entity.cpp:473
~Entity() override
Definition Entity.cpp:58
auto showMenu() -> void override
Called before update each frame, for calling ImGui editor code relevant to the gameObject.
Definition Entity.cpp:478
Entity()
Definition Entity.cpp:40
auto addActionToFront(const ActionType &action) -> void
Adds a new action to the front of an entity's ActionList component, while making sure the component h...
Definition Entity.h:248
auto onUpdate(float dt) -> void override
called once every frame.
Definition Entity.cpp:570
auto insertAction(const ActionType &action, int position) -> void
Adds a new action to the front of an entity's ActionList component, while making sure the component h...
Definition Entity.h:266
auto getAction(const std::string &actionName) -> Action *
Returns the first action of a specific type.
Definition Entity.h:298
auto addComponent(const T &component) -> void
takes a component directly and adds it to the Entity.
Definition Entity.h:158
auto clone() const -> std::unique_ptr< GameObject > override
makes a copy a GameObject even if it's held polymorphically
Definition Entity.cpp:308
auto endWindow() -> void override
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Definition Entity.h:61
auto addComponent(std::unique_ptr< T > component) -> void
allows adding components to objects with unique_ptrs to concrete components
Definition Entity.h:170
auto GetComponent(Component::ComponentTypeEnum typeId) -> type *
the implementation of the GetComponent Template
Definition Entity.h:114
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:66
auto save(Stream &stream) const -> void override
Implementations will load the state of a GameObject to a th::Json object.
Definition Entity.cpp:616
auto pop() -> std::unique_ptr< Node >
Removes the Entity from the Engine tree, and gives ownership to the caller.
Definition Entity.cpp:314
auto onEnterEngine() -> void override
hook that is called when a GameObject enters the Engine tree.
Definition Entity.cpp:586
auto GetComponent() -> comp *
Definition Entity.h:120
auto getChildren() const -> std::shared_ptr< std::vector< GameObject * > > override
Definition Entity.cpp:147
auto showUpdateRenderMessagesFlagButtons() -> void
A helper function for showMenu() to make buttons for toggling shouldRender, shouldUpdate,...
Definition Entity.cpp:328
auto popComponent(const Key &key) -> std::unique_ptr< Component >
Removes a component from the Entity, and gives ownership to the caller.
Definition Entity.cpp:321
auto showNameInputMenu() -> void
A helper function for showMenu() to show a input field for the entity name.
Definition Entity.cpp:457
auto Get(Component::ComponentTypeEnum typeId) -> Component *
Definition Entity.cpp:168
the base class for the engine, most things inherit from this.
Definition GameObject.h:83
friend class ChildrenHandeler
Definition GameObject.h:95
GameObject(std::string typeName, gobj::Type parentType, gobj::Type type)
constructor for gameobject.
Definition GameObject.cpp:24
gobj::Type type
What type this GameObject is, for type checking, and safe casts.
Definition GameObject.h:524
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:45
namespace for things relating to GameObject, other than GameObject itself
Definition Entity.h:440
auto moveEntity(Entity &entityToMove, Entity &newParent) -> void
Makes the provided entity a child of another entity.
Definition Entity.cpp:635
Definition AddedComponentMessage.h:14