17#ifndef _FGE_C_OBJECT_HPP_INCLUDED
18#define _FGE_C_OBJECT_HPP_INCLUDED
20#include "FastEngine/fge_extern.hpp"
21#include "C_childObjectsAccessor.hpp"
22#include "FastEngine/C_event.hpp"
23#include "FastEngine/C_propertyList.hpp"
24#include "FastEngine/C_quad.hpp"
25#include "FastEngine/C_rect.hpp"
26#include "FastEngine/C_tagList.hpp"
27#include "FastEngine/graphic/C_drawable.hpp"
28#include "FastEngine/graphic/C_transformable.hpp"
29#include "FastEngine/network/C_networkType.hpp"
30#include "FastEngine/object/C_objectAnchor.hpp"
31#include "FastEngine/vulkan/C_context.hpp"
37#define FGE_OBJ_BADCLASSNAME "NULL"
38#define FGE_OBJ_NOSCENE nullptr
39#define FGE_OBJ_DEFAULT_COPYMETHOD(objClass) \
40 fge::Object* copy() override \
42 return new objClass(*this); \
46 #define FGE_OBJ_UPDATE_DECLARE \
47 void update(fge::Event& event, fge::DeltaTime const& deltaTime, fge::Scene& scene) override;
49 #define FGE_OBJ_UPDATE_DECLARE \
50 void update(fge::RenderTarget& target, fge::Event& event, fge::DeltaTime const& deltaTime, fge::Scene& scene) \
55 #define FGE_OBJ_UPDATE_BODY(class_) \
56 void class_::update([[maybe_unused]] fge::Event& event, [[maybe_unused]] fge::DeltaTime const& deltaTime, \
57 [[maybe_unused]] fge::Scene& scene)
59 #define FGE_OBJ_UPDATE_CALL(object_) object_.update(event, deltaTime, scene)
60 #define FGE_OBJ_UPDATE_PTRCALL(object_) object_->update(event, deltaTime, scene)
62 #define FGE_OBJ_UPDATE_BODY(class_) \
63 void class_::update([[maybe_unused]] fge::RenderTarget& target, [[maybe_unused]] fge::Event& event, \
64 [[maybe_unused]] fge::DeltaTime const& deltaTime, [[maybe_unused]] fge::Scene& scene)
66 #define FGE_OBJ_UPDATE_CALL(object_) object_.update(target, event, deltaTime, scene)
67 #define FGE_OBJ_UPDATE_PTRCALL(object_) object_->update(target, event, deltaTime, scene)
71 #define FGE_OBJ_DRAW_DECLARE
73 #define FGE_OBJ_DRAW_DECLARE void draw(fge::RenderTarget& target, const fge::RenderStates& states) const override;
76#define FGE_OBJ_DRAW_BODY(class_) void class_::draw(fge::RenderTarget& target, const fge::RenderStates& states) const
81using DeltaTime = std::chrono::microseconds;
89using ObjectDataWeak = std::weak_ptr<fge::ObjectData>;
90using ObjectDataShared = std::shared_ptr<fge::ObjectData>;
98class FGE_API
Object :
public fge::Transformable,
public fge::Anchor,
public fge::OwnView
105 Object(Object
const& r);
106 Object(Object&& r)
noexcept;
107 ~Object()
override =
default;
164#ifndef FGE_DEF_SERVER
189 virtual void save(nlohmann::json& jsonObject);
196 virtual void load(nlohmann::json& jsonObject, std::filesystem::path
const& filePath);
230 [[nodiscard]]
virtual fge::Quad getGlobalQuad()
const;
237 [[nodiscard]]
virtual fge::Quad getLocalQuad()
const;
247 bool saveInFile(std::filesystem::path
const& path,
int fieldWidth = 2,
bool saveClassName =
true);
255 bool loadFromFile(std::filesystem::path
const& path,
bool loadClassName =
true);
262 [[nodiscard]]
static std::unique_ptr<fge::Object>
LoadFromFile(std::filesystem::path
const& path);
301 enum class DrawModes : uint8_t
307 DRAW_DEFAULT = DRAW_IF_ON_TARGET
311 enum class CallbackContextModes : uint8_t
316 CONTEXT_DEFAULT = CONTEXT_AUTO
319 CallbackContextModes::CONTEXT_DEFAULT};
321 enum class NetSyncModes : uint8_t
328 NETSYNC_DEFAULT = FULL_SYNC
330 NETSYNC_DEFAULT = NO_SYNC
338 enum ChildrenControlFlags : uint8_t
340 CHILDREN_AUTO_CLEAR_ON_REMOVE = 1 << 0,
341 CHILDREN_AUTO_UPDATE = 1 << 1,
342 CHILDREN_AUTO_DRAW = 1 << 2,
344 CHILDREN_DEFAULT = CHILDREN_AUTO_CLEAR_ON_REMOVE
346 using ChildrenControlFlags_t = std::underlying_type_t<ChildrenControlFlags>;
Definition C_objectAnchor.hpp:40
Definition C_childObjectsAccessor.hpp:43
Definition C_drawable.hpp:36
This class is a wrapper for SDL events.
Definition C_event.hpp:59
A class to handle highest priority selection of GUI elements.
Definition C_guiElement.hpp:235
A base class for all GUI elements.
Definition C_guiElement.hpp:120
Data wrapper representing an Object in a Scene.
Definition C_scene.hpp:170
The Object class is the base class for all objects in the engine.
Definition C_object.hpp:102
fge::net::NetworkTypeHandler _netList
The network types container of the object.
Definition C_object.hpp:295
fge::Vector2f getParentsScale() const
Retrieve recursively all parents scale by combining them.
CallbackContextModes _callbackContextMode
Tell a scene how the callbackRegister must be called.
Definition C_object.hpp:318
virtual void draw(fge::RenderTarget &target, fge::RenderStates const &states) const override
Method called every frame to draw the object.
virtual fge::Object * copy()
Duplicate the object.
fge::TagList _tags
The tags of the object.
Definition C_object.hpp:290
DrawModes _drawMode
Tell a scene when this object should be drawn.
Definition C_object.hpp:309
virtual void first(fge::Scene &scene)
Method called when the object is added to a scene for initialization purposes.
virtual char const * getClassName() const
Get the unique class name of the object.
virtual void load(nlohmann::json &jsonObject, std::filesystem::path const &filePath)
Load the object from a json object.
virtual char const * getReadableClassName() const
Get a readable version of the class name.
virtual void save(nlohmann::json &jsonObject)
Save the object to a json object.
virtual fge::RectFloat getGlobalBounds() const
Get the global bounds of the object.
fge::ObjectDataWeak _myObjectData
The object data of the object (valid only if the object is in a scene)
Definition C_object.hpp:299
fge::ChildObjectsAccessor _children
An access to child objects of this object.
Definition C_object.hpp:349
virtual void networkRegister()
Register all network types needed by the object.
NetSyncModes _netSyncMode
Tell a scene how the object must be synchronised.
Definition C_object.hpp:333
bool saveInFile(std::filesystem::path const &path, int fieldWidth=2, bool saveClassName=true)
Save the object in a file.
virtual void netSignaled(int8_t signal)
Method called when the object is signaled by the network.
virtual void pack(fge::net::Packet &pck)
Pack the object into a packet.
virtual fge::RectFloat getLocalBounds() const
Get the local bounds of the object (without any transformations)
static std::unique_ptr< fge::Object > LoadFromFile(std::filesystem::path const &path)
Static form of the loadFromFile method.
virtual fge::GuiElement * getGuiElement()
Get the GuiElement attached to this object if there is one.
void centerOriginFromLocalBounds()
Center the origin of the object from its local bounds.
fge::PropertyList _properties
The properties of the object.
Definition C_object.hpp:291
virtual void update(fge::RenderTarget &target, fge::Event &event, fge::DeltaTime const &deltaTime, fge::Scene &scene)
Main method called every frame.
bool loadFromFile(std::filesystem::path const &path, bool loadClassName=true)
Load the object from a file.
virtual void unpack(fge::net::Packet const &pck)
Unpack the object from a packet.
net::Identity _netOwner
The owner of the object.
Definition C_object.hpp:334
virtual void removed(fge::Scene &scene)
Method called when the object is removed from a scene.
ChildrenControlFlags_t _childrenControlFlags
The control flags of the child objects.
Definition C_object.hpp:348
virtual void callbackRegister(fge::Event &event, fge::GuiElementHandler *guiElementHandlerPtr)
Ask the object to register all callbacks it needs to receive events.
glm::mat4 getParentsTransform() const
Retrieve recursively all parents transform by combining them.
virtual void transfered(fge::Scene &oldScene, fge::Scene &newScene)
Method called when the object is transferred from a scene to another.
Definition C_view.hpp:156
A class that map a string to a Property.
Definition C_propertyList.hpp:35
The RenderStates class contains all the information needed to render something.
Definition C_renderStates.hpp:412
Definition C_renderTarget.hpp:56
A scene contain a collection of object and handle them.
Definition C_scene.hpp:465
Definition C_tagList.hpp:28
A regroupment of network types.
Definition C_networkType.hpp:690
Definition C_packet.hpp:52
A class to represent a client or server identity with an IP address and a port.
Definition C_identity.hpp:31