|
Brunot
|
the base class for the engine, most things inherit from this. More...
#include <GameObject.h>
Classes | |
| class | Key |
| a Key class to be used as a key when holding GameObjects (or unique pointers to game objects) in <key, value> datasets More... | |
Public Member Functions | |
| GameObject (std::string typeName, gobj::Type parentType, gobj::Type type) | |
| constructor for gameobject. | |
| virtual | ~GameObject () |
| destructor for GameObject. | |
| GameObject (const GameObject &other) | |
| Copy Constructor. | |
| auto | operator= (const GameObject &other) -> GameObject & |
| copy assignment operator | |
| GameObject (GameObject &&other) noexcept | |
| Move constructor. | |
| auto | operator= (GameObject &&other) noexcept -> GameObject & |
| Move assignment operator. | |
| virtual auto | clone () const -> std::unique_ptr< GameObject >=0 |
| makes a copy a GameObject even if it's held polymorphically | |
| virtual auto | update (float dt) -> void |
| called once every frame. | |
| virtual auto | endWindow () -> void=0 |
| currently unused, but intended to but was assumed to be necessary for a proper ImGui editor | |
| virtual auto | render () -> void |
| called every frame after update has been called for every object. | |
| virtual auto | load (Stream &stream) -> void=0 |
| Implementations will load the state of a GameObject from a th::Json Object. | |
| virtual auto | save (Stream &stream) const -> void=0 |
| Implementations will load the state of a GameObject to a th::Json object. | |
| virtual auto | destroy () -> void |
| Marks an GameObject to be destroyed. | |
| virtual auto | showMenu () -> void |
| Called before update each frame, for calling ImGui editor code relevant to the gameObject. | |
| virtual auto | onEnterEngine () -> void |
| hook that is called when a GameObject enters the Engine tree. | |
| virtual auto | for_each (std::function< void(GameObject &)> func) -> void |
| applies a function to every child. | |
| virtual auto | for_each (std::function< void(const GameObject &)> func) const -> void |
| applies a const function to every child. | |
| virtual auto | getParent () const -> GameObject * |
| Gets the parent of a GameObject. | |
| virtual auto | parentTo (GameObject *newParent) -> bool |
| Sets the GameObject as a child of another GameObject. | |
| auto | getInternalParent () const -> GameObject * |
| returns the actual owning parent of the GameObject | |
| virtual auto | addChild (std::unique_ptr< GameObject > newChild) -> bool |
| Adds a child to a GameObject. | |
| virtual auto | getKey () const -> Key |
| Generates a unique Key that corresponds to the GameObject. | |
| auto | destroyed () const -> bool |
| auto | getUUID () const -> gobj::UUID |
| auto | isUUID (gobj::UUID compareUUID) const -> bool |
| auto | getName () const -> const std::string & |
| Gets the type of the object as a string. | |
| auto | getNickname () const -> const std::string & |
| Gets the nickname (custom, writable name) of a GameObject. | |
| void | calculateFormattedName () const |
| auto | getFormattedName () const -> const std::string & |
| combines a GameObjects Type, Nickname, and UUID into one string, for use with logging. | |
| auto | nameEquals (const std::string &compareString) const -> bool |
| check whether a GameObjects typeName is equivilent to a given string. | |
| auto | isType (gobj::Type otherType) const -> bool |
| check whether the GameObject is the same as a given type. | |
| auto | getObjectType () const -> gobj::Type |
| gets the internal type of the GameObject, as an enum | |
| auto | setNickname (const std::string &newNickname) -> void |
| sets the GameObjects nickname. | |
| auto | updates () const -> bool |
| auto | renders () const -> bool |
| auto | receivesMessages () const -> bool |
| auto | isActive () const -> bool |
| virtual auto | setShouldUpdate (const bool _shouldUpdate) -> void |
| set whether the GameObject should update every frame, and whether all of it's children should update every frame | |
| virtual auto | setShouldRender (const bool _shouldRender) -> void |
| set whether the GameObject should render every frame, and whether all of it's children should render every frame | |
| virtual auto | setShouldReceiveMessages (const bool _shouldReceiveMessages) -> void |
| set whether the GameObject should Receive Messags, and whether all of it's children should receive messages | |
| auto | setActive (const bool shouldBeActive) -> void |
| set the GameObject should update, render, and receive messages | |
Public Attributes | |
| friend | Entity |
| friend | Node |
| friend | ChildrenHandeler |
| friend | Engine |
Protected Member Functions | |
| auto | setInternalParent (GameObject *parent) -> bool |
| sets the internal parent of a GameObject directly, avoiding abstractions provided by ParentTo(). | |
| auto | getGameObjectJson () const -> json |
| Used for serializing GameObjects. | |
| auto | setGameObjectJson (const json &stream) -> void |
| used for deserializing GameObjects | |
| virtual auto | getChildren () const -> std::shared_ptr< std::vector< GameObject * > > |
| gets a vector of a GameObjects public (i.e. | |
| auto | checkAddToSceneHook () -> void |
| Determine if the GameObject was recently added to the engine, and if it was, call onEngineEnter. | |
Private Member Functions | |
| virtual auto | onUpdate (float dt) -> void=0 |
| called once every frame. | |
| virtual auto | onRender () -> void=0 |
| called every frame after update has been called for every object. | |
Private Attributes | |
| const gobj::UUID | uuid |
| a unique ID for each GameObject | |
| bool | isDestroyed |
| whether the GameObject has been destroyed, and if it should be deleted at the end of the frame. | |
| gobj::Type | parentType |
| gobj::Type | type |
| What type this GameObject is, for type checking, and safe casts. | |
| GameObject * | internalParent |
| The GameObject that owns and manages this GameObject. | |
| RenderLayer | renderLayer |
| Currently unused, the z layer an GameObject will be drawn on. | |
| bool | shouldUpdate = true |
| whether the GameObject and it's children updates | |
| bool | shouldRender = true |
| whether the GameObject and it's children render | |
| bool | shouldReceiveMessages = true |
| whether the GameObject and it's children receive messages | |
| bool | inEngine = false |
| whether the GameObject is current in the Engine, underneath SceneManager | |
| std::string | typeName |
| the typeName of a GameObject. | |
| std::string | nickname |
| the nickname of a GameObject is used to identify in the editor. | |
| std::string | formattedName |
| the combined name of the GameObject. | |
the base class for the engine, most things inherit from this.
an abstract class
| GameObject::GameObject | ( | std::string | typeName, |
| gobj::Type | parentType, | ||
| gobj::Type | type ) |
constructor for gameobject.
should only ever be called by derived classes
| typeName | the permenant typeName of the object, not unique |
| parentType | the type this GameObject should be a child of |
| type | the type this GameObject is |
|
virtual |
destructor for GameObject.
removes all messages a GameObject is subscribed to
| GameObject::GameObject | ( | const GameObject & | other | ) |
|
noexcept |
Move constructor.
move operator for gameobject.
| other | GameObject to move |
moves all data, other is left in invalid state. parent pointer and typeName are moved, everything else is copies
| other |
|
nodiscardvirtual |
Adds a child to a GameObject.
Default implementation is to fail, as not all GameObjects have children (e.g. System, Component) Technically this is bad OOP but that's okay right??? This makes the most sense with the current system.
In the case of Node, this adds a child GameObject (other than node), not a child node, unless it is a Node
| newChild |
Reimplemented in Entity, Node, Root, and sys::SceneManager.
| auto GameObject::calculateFormattedName | ( | ) | const |
|
protected |
Determine if the GameObject was recently added to the engine, and if it was, call onEngineEnter.
|
pure virtual |
makes a copy a GameObject even if it's held polymorphically
Implemented in ActionProxy, Background, Board, Button, Card, ChildrenHandeler< C >, ChildrenHandeler< Component >, ChildrenHandeler< Node >, Collider, ConfirmDestructiveActionScene, CreditsScene, Deck, Entity, MainMenuScene, MainScene, Menu, MenuPosition, NewComponentStub, Node, OptionsScene, PauseScene, Physics, Player, Root, Scene, Selector, SplashScreenScene, Sprite, sys::ActionList, sys::AudioSystem, sys::ColliderSystem, sys::DebugDraw, sys::Editor, sys::Input, sys::Messaging, sys::newSystemStub, sys::OpenGL, sys::SceneManager, sys::Scoring, sys::TestRunner, Table, Transform, TutorialScene, and WinScreenScene.
|
virtual |
Marks an GameObject to be destroyed.
The GameObject will be actually removed when it is updated next
Reimplemented in Entity.
|
nodiscard |
|
pure virtual |
currently unused, but intended to but was assumed to be necessary for a proper ImGui editor
Implemented in ActionProxy, Background, Board, Button, Card, ChildrenHandeler< C >, ChildrenHandeler< Component >, ChildrenHandeler< Node >, Collider, ConfirmDestructiveActionScene, CreditsScene, Deck, Entity, MainMenuScene, MainScene, Menu, MenuPosition, NewComponentStub, Node, OptionsScene, PauseScene, Physics, Player, Root, Scene, Selector, SplashScreenScene, Sprite, sys::ActionList, sys::AudioSystem, sys::ColliderSystem, sys::DebugDraw, sys::Editor, sys::Input, sys::Messaging, sys::newSystemStub, sys::OpenGL, sys::SceneManager, sys::Scoring, sys::TestRunner, Table, Transform, TutorialScene, and WinScreenScene.
|
virtual |
applies a const function to every child.
applies to internal children, not public children. (this means that entities will only update their components, not their child entities)
| func | a function that takes a C reference, and does some operation using it |
Reimplemented in ChildrenHandeler< C >, Entity, and Node.
|
virtual |
applies a function to every child.
applies to internal children, not public children. (this means that entities will only update their components, not their child entities)
| func | a function that takes a GameObject reference, and does some operation on it |
Reimplemented in ChildrenHandeler< C >, Entity, and Node.
|
protectedvirtual |
gets a vector of a GameObjects public (i.e.
Entity s Entity and Component children)
Reimplemented in ChildrenHandeler< C >, ChildrenHandeler< Component >, ChildrenHandeler< Node >, Component, Entity, and Node.
|
nodiscard |
combines a GameObjects Type, Nickname, and UUID into one string, for use with logging.
The string will be formatted "type::nickname::uuid"
|
protected |
Used for serializing GameObjects.
|
nodiscard |
returns the actual owning parent of the GameObject
|
nodiscardvirtual |
Generates a unique Key that corresponds to the GameObject.
Unique per GameObject, not per call. Virtual so that GameObjects with subtypes (like System s and Component s) can override it to return a Key with a subtype.
Reimplemented in Component, and System.
|
nodiscard |
Gets the type of the object as a string.
|
nodiscard |
Gets the nickname (custom, writable name) of a GameObject.
|
nodiscard |
gets the internal type of the GameObject, as an enum
|
virtual |
Gets the parent of a GameObject.
Implementations differs depending on what the GameObject is, but using getParent will do the same thing for all GameObjects: get whatever is higher up than the GameObject on the Node tree.
The default implementation calls getInternalParent(), but many classes override this for more complex parent requirements, like with Entity, or Node
Reimplemented in System.
|
nodiscard |
|
nodiscard |
|
nodiscard |
check whether the GameObject is the same as a given type.
This check otherType against an internal Enum, so that type can be checked to ensure safe casting.
| otherType | the enum of the type to compare against |
|
nodiscard |
|
pure virtual |
Implementations will load the state of a GameObject from a th::Json Object.
Unimplemented in GameObject
| stream | th::Json Object |
Implemented in ActionProxy, Background, Board, Button, Card, ChildrenHandeler< C >, ChildrenHandeler< Component >, ChildrenHandeler< Node >, Collider, ConfirmDestructiveActionScene, CreditsScene, Deck, Entity, MainMenuScene, MainScene, Menu, MenuPosition, NewComponentStub, Node, OptionsScene, PauseScene, Physics, Player, Root, Scene, Selector, SplashScreenScene, Sprite, sys::ActionList, sys::AudioSystem, sys::ColliderSystem, sys::DebugDraw, sys::Editor, sys::Input, sys::Messaging, sys::newSystemStub, sys::OpenGL, sys::SceneManager, sys::Scoring, sys::TestRunner, Table, Transform, TutorialScene, and WinScreenScene.
|
nodiscard |
check whether a GameObjects typeName is equivilent to a given string.
this function is provided as a utility function, since most cases where the TypeName is accessed is just to compare
| compareString | a string to compare against |
|
inlinevirtual |
hook that is called when a GameObject enters the Engine tree.
The hook is called immedietly after a gameobject's parent is called. Functionality may not be correct if an object was removed from the engine then re-added
Reimplemented in Board, Button, ChildrenHandeler< C >, ChildrenHandeler< Component >, ChildrenHandeler< Node >, Collider, Entity, MainMenuScene, MainScene, Menu, Node, OptionsScene, Scene, SplashScreenScene, sys::ColliderSystem, sys::OpenGL, and Table.
|
privatepure virtual |
called every frame after update has been called for every object.
Generally used for rendering an object to the screen, when applicable. Unimplemented in GameObject
Implemented in ActionProxy, Background, Board, Button, Card, ChildrenHandeler< C >, ChildrenHandeler< Component >, ChildrenHandeler< Node >, Collider, ConfirmDestructiveActionScene, CreditsScene, Deck, Entity, MainMenuScene, MainScene, Menu, MenuPosition, NewComponentStub, Node, OptionsScene, PauseScene, Physics, Player, Root, Scene, Selector, SplashScreenScene, Sprite, sys::ActionList, sys::AudioSystem, sys::ColliderSystem, sys::DebugDraw, sys::Editor, sys::Input, sys::Messaging, sys::newSystemStub, sys::OpenGL, sys::SceneManager, sys::Scoring, sys::TestRunner, Table, Transform, TutorialScene, and WinScreenScene.
|
privatepure virtual |
called once every frame.
Generally used for timers, movement, condition checks, etc. Unimplemented in GameObject
| dt | the time in seconds that has elapsed |
Implemented in ActionProxy, Background, Board, Button, Card, ChildrenHandeler< C >, ChildrenHandeler< Component >, ChildrenHandeler< Node >, Collider, ConfirmDestructiveActionScene, CreditsScene, Deck, Entity, MainMenuScene, MainScene, Menu, MenuPosition, NewComponentStub, Node, OptionsScene, PauseScene, Physics, Player, Root, Scene, Selector, SplashScreenScene, Sprite, sys::ActionList, sys::AudioSystem, sys::ColliderSystem, sys::DebugDraw, sys::Editor, sys::Input, sys::Messaging, sys::newSystemStub, sys::OpenGL, sys::SceneManager, sys::Scoring, sys::TestRunner, Table, Transform, TutorialScene, and WinScreenScene.
Referenced by onUpdate(), and update().
| auto GameObject::operator= | ( | const GameObject & | other | ) | ->GameObject & |
copy assignment operator
copy assignment operator for gameobject, used by derived classes
| other | GameObject to copy |
| other |
|
noexcept |
Move assignment operator.
move operator for gameobject.
| other | GameObject to move |
moves all data, other is left in invalid state. parent pointer and typeName are moved, everything else is copies
| other |
|
nodiscardvirtual |
Sets the GameObject as a child of another GameObject.
calls setInternalParent() by default, but can be overriden by GameObjects complicated parent requirements, like Entity. Validates pointer and requires type to be valid
| newParent | the GameObject that this GameObject will be a child of |
calls setInternalParent() by default, can be overriden by complicated parent requirements, like Entity. Validates pointer and requires type to be valid
| newParent | the GameObject to parent to |
Reimplemented in ActionProxy, and Transform.
|
nodiscard |
|
virtual |
called every frame after update has been called for every object.
Generally used for rendering an object to the screen, when applicable. override to ensure proper rendering of children that may be active calls onRender for implementation by concrete classes make sure you call GameObject::Update() when overriding
Reimplemented in ChildrenHandeler< C >, ChildrenHandeler< Component >, ChildrenHandeler< Node >, Entity, and Node.
|
nodiscard |
|
pure virtual |
Implementations will load the state of a GameObject to a th::Json object.
Unimplemented in GameObject
| stream | th::Json Object |
Implemented in ActionProxy, Background, Board, Button, Card, ChildrenHandeler< C >, ChildrenHandeler< Component >, ChildrenHandeler< Node >, Collider, ConfirmDestructiveActionScene, CreditsScene, Deck, Entity, MainMenuScene, MainScene, Menu, MenuPosition, NewComponentStub, Node, OptionsScene, PauseScene, Physics, Player, Root, Scene, Selector, SplashScreenScene, Sprite, sys::ActionList, sys::AudioSystem, sys::ColliderSystem, sys::DebugDraw, sys::Editor, sys::Input, sys::Messaging, sys::newSystemStub, sys::OpenGL, sys::SceneManager, sys::Scoring, sys::TestRunner, Table, Transform, TutorialScene, and WinScreenScene.
| auto GameObject::setActive | ( | const bool | shouldBeActive | ) | ->void |
set the GameObject should update, render, and receive messages
| shouldBeActive | whether the GameObject should be active |
|
protected |
used for deserializing GameObjects
| stream | a json object with all the data of the GameObject |
|
protected |
sets the internal parent of a GameObject directly, avoiding abstractions provided by ParentTo().
It also type checks to make sure the parent is valid
| parent | the new parent |
sets the actual parent object, don't call this function unless parentTo() is overriden and you need to directly set the parent (like in entity's implementation of parentTo
| parent | the GameObject to parent to |
| auto GameObject::setNickname | ( | const std::string & | newNickname | ) | ->void |
sets the GameObjects nickname.
Nicknames are non-unique, and user defined. helpful for making Entities more readable nickname should start lowercase, so that they don't conflict with Type names (of components especially)
| newNickname | the new nickname |
|
virtual |
set whether the GameObject should Receive Messags, and whether all of it's children should receive messages
| _shouldReceiveMessages | whether the GameObject should receive messages |
Reimplemented in ChildrenHandeler< C >, ChildrenHandeler< Component >, ChildrenHandeler< Node >, Entity, and Node.
|
virtual |
set whether the GameObject should render every frame, and whether all of it's children should render every frame
| _shouldRender | whether the GameObject should Render |
Reimplemented in ChildrenHandeler< C >, ChildrenHandeler< Component >, ChildrenHandeler< Node >, Entity, and Node.
|
virtual |
set whether the GameObject should update every frame, and whether all of it's children should update every frame
| _shouldUpdate | whether the object should update |
Reimplemented in ChildrenHandeler< C >, ChildrenHandeler< Component >, ChildrenHandeler< Node >, Entity, and Node.
|
inlinevirtual |
Called before update each frame, for calling ImGui editor code relevant to the gameObject.
virtual because we might need to destroy other things too, like parent node for entity Has a empty definition in GameObject, so it may be overriden, but doesn't have to be.
Reimplemented in ChildrenHandeler< C >, ChildrenHandeler< Component >, ChildrenHandeler< Node >, Component, Entity, Node, Root, sys::Scoring, and System.
|
virtual |
called once every frame.
Generally used for timers, movement, condition checks, etc. calls onUpdate for implementation by concrete classes. override to properly call children make sure you call GameObject::Update() when overriding
| dt | the time in seconds that has elapsed |
Reimplemented in ChildrenHandeler< C >, ChildrenHandeler< Component >, ChildrenHandeler< Node >, Entity, and Node.
|
nodiscard |
| friend GameObject::ChildrenHandeler |
| friend GameObject::Engine |
| friend GameObject::Entity |
|
mutableprivate |
the combined name of the GameObject.
NAME::NICKNAME::UUID
|
private |
whether the GameObject is current in the Engine, underneath SceneManager
|
private |
The GameObject that owns and manages this GameObject.
This is sometime different from the parent in the Node tree
|
private |
whether the GameObject has been destroyed, and if it should be deleted at the end of the frame.
|
private |
the nickname of a GameObject is used to identify in the editor.
give a specific name to the object. The nickname should start lowercase, to avoid conflicting with typenames.
| friend GameObject::Node |
|
private |
|
private |
Currently unused, the z layer an GameObject will be drawn on.
|
private |
whether the GameObject and it's children receive messages
|
private |
whether the GameObject and it's children render
|
private |
whether the GameObject and it's children updates
|
private |
What type this GameObject is, for type checking, and safe casts.
|
private |
the typeName of a GameObject.
defaults to whatever the concrete class is (set by concrete class in constructor)
|
private |
a unique ID for each GameObject