FastEngine 0.9.4
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
fge::Object Class Reference

The Object class is the base class for all objects in the engine. More...

#include <C_object.hpp>

Inheritance diagram for fge::Object:
fge::Drawable fge::Transformable fge::Anchor fge::OwnView fge::ObjAnimation fge::ObjButton fge::ObjLight fge::ObjRenderMap fge::ObjSelectBox fge::ObjShaderChain fge::ObjShape fge::ObjSlider fge::ObjSprite fge::ObjSpriteBatches fge::ObjSpriteCluster fge::ObjSwitch fge::ObjText fge::ObjTextInputBox fge::ObjTextList fge::ObjTileLayer fge::ObjWindow

Public Types

enum class  DrawModes : uint8_t { DRAW_IF_ON_TARGET , DRAW_ALWAYS_HIDDEN , DRAW_ALWAYS_DRAWN , DRAW_DEFAULT = DRAW_IF_ON_TARGET }
enum class  CallbackContextModes : uint8_t { CONTEXT_MANUAL , CONTEXT_AUTO , CONTEXT_DEFAULT = CONTEXT_AUTO }
enum class  NetSyncModes : uint8_t { NO_SYNC , FULL_SYNC , DELTA_SYNC , NETSYNC_DEFAULT = NO_SYNC }
enum  ChildrenControlFlags : uint8_t { CHILDREN_AUTO_CLEAR_ON_REMOVE = 1 << 0 , CHILDREN_AUTO_UPDATE = 1 << 1 , CHILDREN_AUTO_DRAW = 1 << 2 , CHILDREN_DEFAULT = CHILDREN_AUTO_CLEAR_ON_REMOVE }
using ChildrenControlFlags_t = std::underlying_type_t<ChildrenControlFlags>
enum class  Types : uint8_t {
  ANCHOR_NONE , ANCHOR_UPLEFT_CORNER , ANCHOR_UPRIGHT_CORNER , ANCHOR_DOWNLEFT_CORNER ,
  ANCHOR_DOWNRIGHT_CORNER
}
enum class  Shifts : uint8_t { SHIFT_NONE , SHIFT_POSITIVE_BOUNDS , SHIFT_NEGATIVE_BOUNDS }

Public Member Functions

 Object (Object const &r)
 Object (Object &&r) noexcept
virtual fge::Objectcopy ()
 Duplicate the object.
virtual void first (fge::Scene &scene)
 Method called when the object is added to a scene for initialization purposes.
virtual void transfered (fge::Scene &oldScene, fge::Scene &newScene)
 Method called when the object is transferred from a scene to another.
virtual void callbackRegister (fge::Event &event, fge::GuiElementHandler *guiElementHandlerPtr)
 Ask the object to register all callbacks it needs to receive events.
virtual void update (fge::RenderTarget &target, fge::Event &event, fge::DeltaTime const &deltaTime, fge::Scene &scene)
 Main method called every frame.
void update (fge::RenderTarget &target, fge::Event &event, fge::DeltaTime const &deltaTime)
virtual void draw (fge::RenderTarget &target, fge::RenderStates const &states) const override
 Method called every frame to draw the object.
virtual void networkRegister ()
 Register all network types needed by the object.
virtual void netSignaled (int8_t signal)
 Method called when the object is signaled by the network.
virtual void removed (fge::Scene &scene)
 Method called when the object is removed from a scene.
virtual void save (nlohmann::json &jsonObject)
 Save the object to a json object.
virtual void load (nlohmann::json &jsonObject, std::filesystem::path const &filePath)
 Load the object from a json object.
virtual void pack (fge::net::Packet &pck)
 Pack the object into a packet.
virtual void unpack (fge::net::Packet const &pck)
 Unpack the object from a packet.
virtual char const * getClassName () const
 Get the unique class name of the object.
virtual char const * getReadableClassName () const
 Get a readable version of the class name.
virtual fge::RectFloat getGlobalBounds () const
 Get the global bounds of the object.
virtual fge::Quad getGlobalQuad () const
virtual fge::RectFloat getLocalBounds () const
 Get the local bounds of the object (without any transformations)
virtual fge::Quad getLocalQuad () const
bool saveInFile (std::filesystem::path const &path, int fieldWidth=2, bool saveClassName=true)
 Save the object in a file.
bool loadFromFile (std::filesystem::path const &path, bool loadClassName=true)
 Load the object from a file.
virtual fge::GuiElementgetGuiElement ()
 Get the GuiElement attached to this object if there is one.
glm::mat4 getParentsTransform () const
 Retrieve recursively all parents transform by combining them.
fge::Vector2f getParentsScale () const
 Retrieve recursively all parents scale by combining them.
void centerOriginFromLocalBounds ()
 Center the origin of the object from its local bounds.
void setPosition (Vector2f const &position)
Vector2f const & getPosition () const
void move (Vector2f const &offset)
void setRotation (float angle)
float getRotation () const
void rotate (float angle)
void setScale (Vector2f const &factors)
void setScale (float factor)
Vector2f const & getScale () const
void scale (Vector2f const &factor)
void scale (float factor)
void setOrigin (Vector2f const &origin)
Vector2f const & getOrigin () const
glm::mat4 const & getTransform () const
glm::mat4 const & getInverseTransform () const
void updateAnchor (fge::Vector2f const &customTargetSize={0.0f, 0.0f})
void setAnchor (Types type, fge::Vector2< Shifts > const &shift, fge::ObjectSid target=std::numeric_limits< fge::ObjectSid >::max())
void setAnchorType (Types type)
void setAnchorShift (fge::Vector2< Shifts > const &shift)
void setAnchorTarget (fge::ObjectSid target)
Types getAnchorType () const
fge::Vector2< Shifts > const & getAnchorShift () const
fge::ObjectSid getAnchorTarget () const
fge::ObjectgetAnchorOwner () const
void setAnchorSuccessor (fge::ObjectDataWeak successor)
fge::ObjectDataWeak getAnchorSuccessor () const
void needAnchorUpdate (bool flag)
bool isNeedingAnchorUpdate () const
ViewcreateOwnView ()
void removeOwnView ()
bool hasOwnView () const
std::shared_ptr< View > const & getOwnView () const
void setOwnView (std::shared_ptr< View > view)
void ownViewOverrideParent (bool enable)
bool isOwnViewOverridingParent () const
void ownViewExplicitlySetDefaultView (bool enable)
bool isOwnViewUsingExplicitDefaultView () const
View const & requestView (View const &source, fge::ObjectDataWeak object) const
View const & requestView (View const &source, OwnView const &parent) const
View const & requestView (View const &source) const
View const & requestView (fge::RenderTarget const &source, fge::ObjectDataWeak object) const
View const & requestView (fge::RenderTarget const &source, OwnView const &parent) const
View const & requestView (fge::RenderTarget const &source) const

Static Public Member Functions

static std::unique_ptr< fge::ObjectLoadFromFile (std::filesystem::path const &path)
 Static form of the loadFromFile method.

Public Attributes

fge::TagList _tags
 The tags of the object.
fge::PropertyList _properties
 The properties of the object.
fge::net::NetworkTypeHandler _netList
 The network types container of the object.
fge::ObjectDataWeak _myObjectData
 The object data of the object (valid only if the object is in a scene)
DrawModes _drawMode {DrawModes::DRAW_DEFAULT}
 Tell a scene when this object should be drawn.
CallbackContextModes _callbackContextMode
 Tell a scene how the callbackRegister must be called.
NetSyncModes _netSyncMode {NetSyncModes::NETSYNC_DEFAULT}
 Tell a scene how the object must be synchronised.
net::Identity _netOwner {}
 The owner of the object.
ChildrenControlFlags_t _childrenControlFlags {CHILDREN_DEFAULT}
 The control flags of the child objects.
fge::ChildObjectsAccessor _children
 An access to child objects of this object.

Detailed Description

The Object class is the base class for all objects in the engine.

Member Function Documentation

◆ callbackRegister()

virtual void fge::Object::callbackRegister ( fge::Event & event,
fge::GuiElementHandler * guiElementHandlerPtr )
virtual

Ask the object to register all callbacks it needs to receive events.

Parameters
eventThe event system
guiElementHandlerPtrThe GUI element handler

Reimplemented in fge::ObjButton, fge::ObjSelectBox, fge::ObjSlider, fge::ObjTextInputBox, fge::ObjTextList, and fge::ObjWindow.

◆ centerOriginFromLocalBounds()

void fge::Object::centerOriginFromLocalBounds ( )

Center the origin of the object from its local bounds.

◆ copy()

virtual fge::Object * fge::Object::copy ( )
virtual

Duplicate the object.

By default, if the copy method is not overridden, the object is duplicated with the help of the register manager (and the object class have to be registered).

Returns
An allocated pointer to the duplicated object

Reimplemented in fge::ObjAnimation, fge::ObjButton, fge::ObjLight, fge::ObjRenderMap, fge::ObjShaderChain, fge::ObjSprite, fge::ObjSpriteBatches, fge::ObjSpriteCluster, fge::ObjSwitch, fge::ObjText, fge::ObjTileLayer, and fge::ObjWindow.

◆ draw()

virtual void fge::Object::draw ( fge::RenderTarget & target,
fge::RenderStates const & states ) const
overridevirtual

Method called every frame to draw the object.

Parameters
targetThe target where the object is drawn
statesThe render states

Implements fge::Drawable.

Reimplemented in fge::ObjAnimation, fge::ObjButton, fge::ObjLight, fge::ObjRenderMap, fge::ObjShaderChain, fge::ObjShape, fge::ObjSprite, fge::ObjSpriteBatches, fge::ObjSpriteCluster, fge::ObjSwitch, fge::ObjText, fge::ObjTileLayer, and fge::ObjWindow.

◆ first()

virtual void fge::Object::first ( fge::Scene & scene)
virtual

Method called when the object is added to a scene for initialization purposes.

Parameters
sceneThe scene where the object is added

Reimplemented in fge::ObjLight, fge::ObjRenderMap, fge::ObjShaderChain, fge::ObjShape, fge::ObjSlider, fge::ObjTextList, and fge::ObjWindow.

◆ getClassName()

◆ getGlobalBounds()

virtual fge::RectFloat fge::Object::getGlobalBounds ( ) const
nodiscardvirtual

◆ getGuiElement()

virtual fge::GuiElement * fge::Object::getGuiElement ( )
virtual

Get the GuiElement attached to this object if there is one.

Returns
The GuiElement pointer or nullptr

Reimplemented in fge::ObjButton, fge::ObjSelectBox, fge::ObjSlider, fge::ObjTextInputBox, and fge::ObjWindow.

◆ getLocalBounds()

virtual fge::RectFloat fge::Object::getLocalBounds ( ) const
nodiscardvirtual

◆ getParentsScale()

fge::Vector2f fge::Object::getParentsScale ( ) const

Retrieve recursively all parents scale by combining them.

Returns
Parents scale

◆ getParentsTransform()

glm::mat4 fge::Object::getParentsTransform ( ) const

Retrieve recursively all parents transform by combining them.

Returns
Parents transform

◆ getReadableClassName()

virtual char const * fge::Object::getReadableClassName ( ) const
virtual

◆ load()

virtual void fge::Object::load ( nlohmann::json & jsonObject,
std::filesystem::path const & filePath )
virtual

Load the object from a json object.

Parameters
jsonObjectThe json object where the object is loaded
filePathThe path of the main file where the object is loaded from

Reimplemented in fge::ObjAnimation, fge::ObjButton, fge::ObjLight, fge::ObjRenderMap, fge::ObjSelectBox, fge::ObjSprite, fge::ObjSpriteBatches, fge::ObjSpriteCluster, fge::ObjSwitch, fge::ObjText, and fge::ObjTextInputBox.

◆ LoadFromFile()

std::unique_ptr< fge::Object > fge::Object::LoadFromFile ( std::filesystem::path const & path)
staticnodiscard

Static form of the loadFromFile method.

Parameters
pathThe path of the file
Returns
The allocated pointer of the loaded object or nullptr if the object was not loaded

◆ loadFromFile()

bool fge::Object::loadFromFile ( std::filesystem::path const & path,
bool loadClassName = true )

Load the object from a file.

Parameters
pathThe path of the file
loadClassNameLoad and verify the class name
Returns
true if the object was loaded, false otherwise

◆ netSignaled()

virtual void fge::Object::netSignaled ( int8_t signal)
virtual

Method called when the object is signaled by the network.

Parameters
signalThe signal received

◆ networkRegister()

virtual void fge::Object::networkRegister ( )
virtual

Register all network types needed by the object.

◆ pack()

virtual void fge::Object::pack ( fge::net::Packet & pck)
virtual

Pack the object into a packet.

Parameters
pckThe packet where the object is packed

Reimplemented in fge::ObjAnimation, fge::ObjButton, fge::ObjLight, fge::ObjRenderMap, fge::ObjSelectBox, fge::ObjSprite, fge::ObjSpriteBatches, fge::ObjSpriteCluster, fge::ObjSwitch, fge::ObjText, and fge::ObjTextInputBox.

◆ removed()

virtual void fge::Object::removed ( fge::Scene & scene)
virtual

Method called when the object is removed from a scene.

Parameters
sceneThe scene where the object is removed

Reimplemented in fge::ObjRenderMap, and fge::ObjWindow.

◆ save()

virtual void fge::Object::save ( nlohmann::json & jsonObject)
virtual

Save the object to a json object.

Parameters
jsonObjectThe json object where the object is saved

Reimplemented in fge::ObjAnimation, fge::ObjButton, fge::ObjLight, fge::ObjRenderMap, fge::ObjSelectBox, fge::ObjSprite, fge::ObjSpriteBatches, fge::ObjSpriteCluster, fge::ObjSwitch, fge::ObjText, and fge::ObjTextInputBox.

◆ saveInFile()

bool fge::Object::saveInFile ( std::filesystem::path const & path,
int fieldWidth = 2,
bool saveClassName = true )

Save the object in a file.

Parameters
pathThe path of the file
fieldWidthThe width of the fields in the file
saveClassNameIf the class name must be saved
Returns
true if the object was saved, false otherwise

◆ transfered()

virtual void fge::Object::transfered ( fge::Scene & oldScene,
fge::Scene & newScene )
virtual

Method called when the object is transferred from a scene to another.

This method is called after the object is removed from the old scene and added to the new scene. The _myObjectData is updated to the new scene when this method is called.

Parameters
oldSceneThe old scene where the object was
newSceneThe new scene where the object is

◆ unpack()

virtual void fge::Object::unpack ( fge::net::Packet const & pck)
virtual

Unpack the object from a packet.

Parameters
pckThe packet where the object is unpacked

Reimplemented in fge::ObjAnimation, fge::ObjButton, fge::ObjLight, fge::ObjRenderMap, fge::ObjSelectBox, fge::ObjSprite, fge::ObjSpriteBatches, fge::ObjSpriteCluster, fge::ObjSwitch, fge::ObjText, and fge::ObjTextInputBox.

◆ update()

virtual void fge::Object::update ( fge::RenderTarget & target,
fge::Event & event,
fge::DeltaTime const & deltaTime,
fge::Scene & scene )
virtual

Main method called every frame.

Parameters
targetThe target where the object is drawn
eventThe event system
deltaTimeThe time since the last frame
sceneThe scene where the object is updated

Reimplemented in fge::ObjAnimation, fge::ObjLight, fge::ObjRenderMap, fge::ObjSwitch, and fge::ObjWindow.

Member Data Documentation

◆ _callbackContextMode

CallbackContextModes fge::Object::_callbackContextMode
Initial value:
{
CallbackContextModes::CONTEXT_DEFAULT}

Tell a scene how the callbackRegister must be called.

◆ _children

fge::ChildObjectsAccessor fge::Object::_children

An access to child objects of this object.

◆ _childrenControlFlags

ChildrenControlFlags_t fge::Object::_childrenControlFlags {CHILDREN_DEFAULT}

The control flags of the child objects.

◆ _drawMode

DrawModes fge::Object::_drawMode {DrawModes::DRAW_DEFAULT}

Tell a scene when this object should be drawn.

◆ _myObjectData

fge::ObjectDataWeak fge::Object::_myObjectData

The object data of the object (valid only if the object is in a scene)

◆ _netList

fge::net::NetworkTypeHandler fge::Object::_netList

The network types container of the object.

◆ _netOwner

net::Identity fge::Object::_netOwner {}

The owner of the object.

◆ _netSyncMode

NetSyncModes fge::Object::_netSyncMode {NetSyncModes::NETSYNC_DEFAULT}

Tell a scene how the object must be synchronised.

◆ _properties

fge::PropertyList fge::Object::_properties

The properties of the object.

◆ _tags

fge::TagList fge::Object::_tags

The tags of the object.


The documentation for this class was generated from the following file: