FastEngine 0.9.4
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_scene.hpp
1/*
2 * Copyright 2025 Guillaume Guillet
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _FGE_C_SCENE_HPP_INCLUDED
18#define _FGE_C_SCENE_HPP_INCLUDED
19
20#include "FastEngine/fge_extern.hpp"
21
22#include "FastEngine/C_callback.hpp"
23#include "FastEngine/C_commandHandler.hpp"
24#include "FastEngine/C_propertyList.hpp"
25#include "FastEngine/graphic/C_renderTarget.hpp"
26#include "FastEngine/network/C_identity.hpp"
27#include "FastEngine/object/C_object.hpp"
28#include <memory>
29#include <queue>
30#include <string>
31#include <unordered_map>
32
33#define FGE_SCENE_PLAN_HIDE_BACK (FGE_SCENE_PLAN_MIDDLE - 4)
34#define FGE_SCENE_PLAN_BACK (FGE_SCENE_PLAN_MIDDLE - 2)
35#define FGE_SCENE_PLAN_MIDDLE \
36 fge::ObjectPlan \
37 { \
38 100 \
39 }
40#define FGE_SCENE_PLAN_TOP (FGE_SCENE_PLAN_MIDDLE + 2)
41#define FGE_SCENE_PLAN_GUI (FGE_SCENE_PLAN_MIDDLE + 4)
42#define FGE_SCENE_PLAN_HIGH_TOP (FGE_SCENE_PLAN_MIDDLE + 6)
43#define FGE_SCENE_PLAN_DEFAULT FGE_SCENE_PLAN_MIDDLE
44
45#define FGE_SCENE_BAD_SID std::numeric_limits<fge::ObjectSid>::max()
46#define FGE_SCENE_BAD_PLANDEPTH std::numeric_limits<fge::ObjectPlanDepth>::max()
47#define FGE_SCENE_BAD_PLAN std::numeric_limits<fge::ObjectPlan>::max()
48
49#define FGE_SCENE_LIMIT_NAMESIZE 200
50
51#define FGE_NEWOBJECT(objectType_, ...) \
52 fge::ObjectPtr \
53 { \
54 new objectType_ \
55 { \
56 __VA_ARGS__ \
57 } \
58 }
59#define FGE_NEWOBJECT_PTR(objectPtr_) \
60 fge::ObjectPtr \
61 { \
62 objectPtr_ \
63 }
64
65namespace fge
66{
67
68namespace net
69{
70
71class ClientList;
72
73} // namespace net
74
75class Scene;
76
77using ObjectPlanDepth = uint32_t;
78using ObjectPlan = uint16_t;
79using ObjectSid = uint32_t;
80using ObjectPtr = std::unique_ptr<fge::Object>;
81
83{
84 fge::Event* _event;
85 fge::GuiElementHandler* _guiElementHandler;
86};
87
97{
98 enum class Events : uint8_t
99 {
100 OBJECT_DELETED = 0,
101 OBJECT_CREATED,
102 OBJECT_SIGNALED,
103
104 LAST_ENUM_
105 };
106 using Events_t = std::underlying_type_t<Events>;
107
108 Events _event;
109 ObjectSid _sid;
110 int8_t _signal{0};
111};
112
118enum class ObjectTypes : uint8_t
119{
120 INVALID = 0,
121
122 OBJECT,
123 DECAY,
124 GUI,
125
126 _MAX_
127};
128using ObjectTypes_t = std::underlying_type_t<ObjectTypes>;
129
130static_assert(sizeof(fge::ObjectSid) == sizeof(uint32_t), "fge::ObjectSid must be the same size as uint32_t");
131static_assert(static_cast<ObjectTypes_t>(ObjectTypes::_MAX_) <= 4,
132 "Too many ObjectTypes, DefaultSIDRanges must change");
133enum class DefaultSIDRanges : ObjectSid
134{
135 MASK_SIZE = 2,
136 MASK_POS = 30,
137 MASK = ObjectSid{0x3} << MASK_POS,
138
139 POS_NULL = ObjectSid{static_cast<ObjectTypes_t>(ObjectTypes::INVALID)} << MASK_POS,
140 POS_OBJECT = ObjectSid{static_cast<ObjectTypes_t>(ObjectTypes::OBJECT)} << MASK_POS,
141 POS_DECAY = ObjectSid{static_cast<ObjectTypes_t>(ObjectTypes::DECAY)} << MASK_POS,
142 POS_GUI = ObjectSid{static_cast<ObjectTypes_t>(ObjectTypes::GUI)} << MASK_POS
143};
144using DefaultSIDRanges_t = std::underlying_type_t<DefaultSIDRanges>;
145
146enum ObjectContextFlags : uint32_t
147{
148 OBJ_CONTEXT_NETWORK = 1 << 0,
149 OBJ_CONTEXT_DETACHED = 1 << 1,
150
151 OBJ_CONTEXT_NONE = 0,
152 OBJ_CONTEXT_DEFAULT = OBJ_CONTEXT_NONE
153};
154
169class ObjectData
170{
171public:
172 inline ObjectData() :
173 g_boundScene(nullptr),
174
175 g_object(nullptr),
176 g_sid(FGE_SCENE_BAD_SID),
177 g_plan(FGE_SCENE_PLAN_DEFAULT),
178 g_type(fge::ObjectTypes::INVALID),
179
180 g_planDepth(FGE_SCENE_BAD_PLANDEPTH),
181 g_requireForceClientsCheckup(true)
182 {}
183 inline ObjectData(fge::Scene* boundScene,
184 fge::ObjectPtr&& newObj,
185 fge::ObjectSid newSid = FGE_SCENE_BAD_SID,
186 fge::ObjectPlan newPlan = FGE_SCENE_PLAN_DEFAULT,
187 fge::ObjectTypes newType = fge::ObjectTypes::OBJECT) :
188 g_boundScene(boundScene),
189
190 g_object(std::move(newObj)),
191 g_sid(newSid),
192 g_plan(newPlan),
193 g_type(newType),
194
195 g_planDepth(FGE_SCENE_BAD_PLANDEPTH),
196 g_requireForceClientsCheckup(true)
197 {}
198
209 [[nodiscard]] inline fge::Object* releaseObject() { return this->g_object.release(); }
210
216 [[nodiscard]] inline fge::Scene* getScene() const { return this->g_boundScene; }
222 [[nodiscard]] inline fge::Object* getObject() const { return this->g_object.get(); }
229 template<class TObject>
230 [[nodiscard]] inline TObject* getObject() const
231 {
232 return reinterpret_cast<TObject*>(this->g_object.get());
233 }
234
241 [[nodiscard]] inline fge::ObjectSid getSid() const { return this->g_sid; }
250 [[nodiscard]] inline fge::ObjectPlan getPlan() const { return this->g_plan; }
262 [[nodiscard]] inline fge::ObjectTypes getType() const { return this->g_type; }
263
270 inline void setPlanDepth(fge::ObjectPlanDepth depth) const { this->g_planDepth = depth; }
284 [[nodiscard]] inline fge::ObjectPlanDepth getPlanDepth() const { return this->g_planDepth; }
285
291 inline void setParent(fge::ObjectDataShared const& object) const
292 {
293 if (object)
294 {
295 this->g_parent = object;
296 }
297 }
298
301 inline void clearParent() const { this->g_parent.reset(); }
307 [[nodiscard]] inline fge::ObjectDataWeak getParent() const { return this->g_parent; }
308
314 [[nodiscard]] inline bool isBound() const { return this->g_boundScene != nullptr; }
315
322 [[nodiscard]] inline bool isClass(std::string_view const className) const
323 {
324 return this->g_object->getClassName() == className;
325 }
326
327 [[nodiscard]] inline fge::EnumFlags<ObjectContextFlags>& getContextFlags() const { return this->g_contextFlags; }
328
334 [[nodiscard]] inline bool operator==(fge::ObjectSid const& sid) const { return this->g_sid == sid; }
340 [[nodiscard]] inline bool operator==(fge::Object const* ptr) const { return this->g_object.get() == ptr; }
341
351 [[nodiscard]] static inline bool isValid(fge::ObjectDataShared const& data) { return data && data->isBound(); }
352
359 [[nodiscard]] static inline fge::ObjectDataShared isValid(fge::ObjectDataWeak const& data)
360 {
361 if (auto dataShared = data.lock())
362 {
363 return dataShared->isBound() ? dataShared : nullptr;
364 }
365 return nullptr;
366 }
367
368private:
369 fge::Scene* g_boundScene;
370
371 fge::ObjectPtr g_object;
372 fge::ObjectSid g_sid;
373 fge::ObjectPlan g_plan;
374 fge::ObjectTypes g_type;
375
376 //Dynamic data (not saved, local only)
377 mutable fge::ObjectPlanDepth g_planDepth;
378 mutable fge::ObjectDataWeak g_parent;
379 mutable fge::EnumFlags<ObjectContextFlags> g_contextFlags; //TODO: make it uneditable ?
380
381 bool g_requireForceClientsCheckup;
382
383 friend class fge::Scene;
384 friend class fge::ChildObjectsAccessor;
385};
386
387using ObjectDataWeak = std::weak_ptr<fge::ObjectData>;
388using ObjectDataShared = std::shared_ptr<fge::ObjectData>;
389using ObjectContainer = std::list<fge::ObjectDataShared>;
390using ObjectPlanDataMap = std::map<fge::ObjectPlan, fge::ObjectContainer::iterator>;
391
397class FGE_API ObjectContainerHashMap
398{
399public:
400 using Map = std::unordered_map<ObjectSid, ObjectContainer::iterator>;
401
402 ObjectContainerHashMap() = default;
403 explicit ObjectContainerHashMap(ObjectContainer& objects);
404 ObjectContainerHashMap(ObjectContainerHashMap const& r) = delete;
405 ObjectContainerHashMap(ObjectContainerHashMap&& r) noexcept = default;
406 ~ObjectContainerHashMap() = default;
407
408 ObjectContainerHashMap& operator=(ObjectContainerHashMap const& r) = delete;
409 ObjectContainerHashMap& operator=(ObjectContainerHashMap&& r) noexcept = default;
410
411 void clear();
412 void reMap(ObjectContainer& objects);
413
424 [[nodiscard]] bool newSid(ObjectSid oldSid, ObjectSid newSid);
435 [[nodiscard]] bool newObject(ObjectSid sid, ObjectContainer::iterator it);
441 void delObject(ObjectSid sid);
442
443 [[nodiscard]] std::optional<ObjectContainer::iterator> find(ObjectSid sid);
444 [[nodiscard]] std::optional<ObjectContainer::const_iterator> find(ObjectSid sid) const;
445 [[nodiscard]] fge::ObjectContainer::value_type retrieve(ObjectSid sid) const;
446 [[nodiscard]] bool contains(ObjectSid sid) const;
447
448 [[nodiscard]] std::size_t size() const;
449
450private:
451 Map g_objectMap;
452};
453
464class FGE_API Scene : public fge::CommandHandler, public fge::OwnView
465{
466public:
467 using NetworkEventQueue = std::queue<fge::SceneNetEvent>;
468 using UpdateCount = uint16_t;
470 {
471 UpdateCount _last;
472 UpdateCount _now;
473 };
474
475 enum UpdateFlags : uint32_t
476 {
477 NONE = 0,
478 INCREMENT_UPDATE_COUNT = 1 << 0
479 };
480
481 Scene();
482 explicit Scene(std::string sceneName);
483 Scene(Scene const& r);
484 Scene(Scene&& r) noexcept = delete; //TODO: implement move constructor
485 virtual ~Scene();
486
487 Scene& operator=(Scene const& r);
488 Scene& operator=(Scene&& r) noexcept = delete; //TODO: implement move operator
489
490 // Scene
496 inline std::string const& getName() const { return this->g_name; }
502 inline void setName(std::string name)
503 {
504 if (name.size() <= FGE_SCENE_LIMIT_NAMESIZE)
505 {
506 this->g_name = std::move(name);
507 }
508 }
509
524#ifdef FGE_DEF_SERVER
525 void update(fge::Event& event,
526 fge::DeltaTime const& deltaTime,
527 std::underlying_type_t<UpdateFlags> flags = UpdateFlags::INCREMENT_UPDATE_COUNT);
528#else
530 fge::Event& event,
531 fge::DeltaTime const& deltaTime,
532 std::underlying_type_t<UpdateFlags> flags = UpdateFlags::NONE);
533#endif
544 [[nodiscard]] uint16_t getUpdateCount() const;
545
564#ifndef FGE_DEF_SERVER
565 void draw(fge::RenderTarget& target, fge::RenderStates const& states = fge::RenderStates{}) const;
566#endif //FGE_DEF_SERVER
567
574 fge::ObjectPlanDepth updatePlanDepth(fge::ObjectSid sid);
580 void updateAllPlanDepth(fge::ObjectPlan plan);
588
597 void clear();
598
599 // Object
600
611 {
612 fge::ObjectPlan _plan{FGE_SCENE_PLAN_DEFAULT};
613 fge::ObjectSid _sid{FGE_SCENE_BAD_SID};
614 fge::ObjectTypes _type{fge::ObjectTypes::OBJECT};
615 bool _silent{false};
616 fge::EnumFlags<ObjectContextFlags> _contextFlags{OBJ_CONTEXT_DEFAULT};
617 };
618
641 fge::ObjectDataShared newObject(fge::ObjectPtr&& newObject,
642 fge::ObjectPlan plan = FGE_SCENE_PLAN_DEFAULT,
643 fge::ObjectSid sid = FGE_SCENE_BAD_SID,
644 fge::ObjectTypes type = fge::ObjectTypes::OBJECT,
645 bool silent = false,
646 fge::EnumFlags<ObjectContextFlags> contextFlags = OBJ_CONTEXT_DEFAULT);
647
648 template<class TObject, class... TArgs>
649 inline TObject* newObject(NewObjectParameters const& parameters, TArgs&&... args)
650 {
651 static_assert(std::is_base_of_v<fge::Object, TObject>, "TObject must be a child of fge::Object");
652 auto object = this->newObject(std::make_unique<TObject>(std::forward<TArgs>(args)...), parameters._plan,
653 parameters._sid, parameters._type, parameters._silent, parameters._contextFlags);
654 return object ? object->template getObject<TObject>() : nullptr;
655 }
656 template<class TObject, class... TArgs>
657 inline TObject* newObject(TArgs&&... args)
658 {
659 static_assert(std::is_base_of_v<fge::Object, TObject>, "TObject must be a child of fge::Object");
660 auto object = this->newObject(std::make_unique<TObject>(std::forward<TArgs>(args)...));
661 return object ? object->template getObject<TObject>() : nullptr;
662 }
663 template<class TObject>
664 inline TObject* newObject()
665 {
666 static_assert(std::is_base_of_v<fge::Object, TObject>, "TObject must be a child of fge::Object");
667 auto object = this->newObject(std::make_unique<TObject>());
668 return object ? object->template getObject<TObject>() : nullptr;
669 }
684 fge::ObjectDataShared newObject(fge::ObjectDataShared const& objectData, bool silent = false);
685
698 fge::ObjectDataShared duplicateObject(fge::ObjectSid sid, fge::ObjectSid newSid = FGE_SCENE_BAD_SID);
699
722 fge::ObjectDataShared transferObject(fge::ObjectSid sid, fge::Scene& newScene);
723
746 bool delObject(fge::ObjectSid sid);
753 std::size_t delAllObject(bool ignoreGuiObject);
754
765 bool setObjectSid(fge::ObjectSid sid, fge::ObjectSid newSid);
776 bool setObject(fge::ObjectSid sid, fge::ObjectPtr&& newObject);
784 bool setObjectPlan(fge::ObjectSid sid, fge::ObjectPlan newPlan);
793 bool setObjectPlanTop(fge::ObjectSid sid);
802 bool setObjectPlanBot(fge::ObjectSid sid);
803
810 fge::ObjectDataShared getObject(fge::ObjectSid sid) const;
817 fge::ObjectDataShared getObject(fge::Object const* ptr) const;
824 fge::Object* getObjectPtr(fge::ObjectSid sid) const;
830 fge::ObjectDataShared getUpdatedObject() const;
831
837 inline std::size_t getObjectSize() const { return this->g_objects.size(); }
838
839 // Search function
852 std::size_t getAllObj_ByPosition(fge::Vector2f const& pos, fge::ObjectContainer& buff) const;
865 std::size_t getAllObj_ByZone(fge::RectFloat const& zone, fge::ObjectContainer& buff) const;
866
867#ifndef FGE_DEF_SERVER
885 std::size_t getAllObj_ByLocalPosition(fge::Vector2i const& pos,
886 fge::RenderTarget const& target,
887 fge::ObjectContainer& buff) const;
903 std::size_t
904 getAllObj_ByLocalZone(fge::RectInt const& zone, fge::RenderTarget const& target, fge::ObjectContainer& buff) const;
923 std::size_t getAllObj_FromLocalPosition(fge::Vector2i const& pos,
924 fge::RenderTarget const& target,
925 fge::ObjectContainer& buff) const;
944 std::size_t getAllObj_FromLocalZone(fge::RectInt const& zone,
945 fge::RenderTarget const& target,
946 fge::ObjectContainer& buff) const;
947#endif //FGE_DEF_SERVER
948
960 std::size_t getAllObj_ByClass(std::string_view class_name, fge::ObjectContainer& buff) const;
972 std::size_t getAllObj_ByTag(std::string_view tag_name, fge::ObjectContainer& buff) const;
973
982 fge::ObjectDataShared getFirstObj_ByPosition(fge::Vector2f const& pos) const;
991 fge::ObjectDataShared getFirstObj_ByZone(fge::RectFloat const& zone) const;
992
993#ifndef FGE_DEF_SERVER
1003 fge::ObjectDataShared getFirstObj_ByLocalPosition(fge::Vector2i const& pos, fge::RenderTarget const& target) const;
1013 fge::ObjectDataShared getFirstObj_ByLocalZone(fge::RectInt const& zone, fge::RenderTarget const& target) const;
1023 fge::ObjectDataShared getFirstObj_FromLocalPosition(fge::Vector2i const& pos,
1024 fge::RenderTarget const& target) const;
1034 fge::ObjectDataShared getFirstObj_FromLocalZone(fge::RectInt const& zone, fge::RenderTarget const& target) const;
1043#endif //FGE_DEF_SERVER
1044
1045 fge::ObjectDataShared getFirstObj_ByClass(std::string_view class_name) const;
1054 fge::ObjectDataShared getFirstObj_ByTag(std::string_view tag_name) const;
1055
1056 // Static id
1063 fge::ObjectSid getSid(fge::Object const* ptr) const;
1064
1071 inline bool isValid(fge::ObjectSid sid) const { return this->find(sid) != this->g_objects.cend(); }
1072
1086 virtual fge::ObjectSid generateSid(fge::ObjectSid wanted_sid, fge::ObjectTypes type) const;
1087
1088 // Network
1095 void signalObject(fge::ObjectSid sid, int8_t signal);
1096
1118 std::optional<fge::net::Error> unpack(fge::net::Packet const& pck, bool clearObjects = true);
1153 std::optional<fge::net::Error>
1154 unpackModification(fge::net::Packet const& pck, UpdateCountRange& range, bool ignoreUpdateCount = false);
1155
1176 std::optional<fge::net::Error> unpackNeededUpdate(fge::net::Packet const& pck, fge::net::Identity const& id);
1177
1195
1210 void clientsCheckup(fge::net::ClientList const& clients, bool force = false);
1211
1212 // SceneNetEvent
1218 void pushEvent(fge::SceneNetEvent const& netEvent);
1225 bool pushEvent(fge::SceneNetEvent const& netEvent, fge::net::Identity const& id);
1236 void watchEvent(bool on);
1244 bool isWatchingEvent() const;
1245
1263
1278 std::optional<fge::net::Error> unpackWatchedEvent(fge::net::Packet const& pck);
1279
1280 // Operator
1281 inline fge::ObjectDataShared operator[](fge::ObjectSid sid) const { return this->getObject(sid); }
1282
1283 // Linked renderTarget
1308
1320 [[nodiscard]] fge::View const* getRelatedView() const;
1321
1340
1341 // Save/Load in file
1352 virtual void saveCustomData([[maybe_unused]] nlohmann::json& jsonObject) {};
1363 virtual void loadCustomData([[maybe_unused]] nlohmann::json& jsonObject) {};
1364
1375 bool saveInFile(std::filesystem::path const& path);
1389 bool loadFromFile(std::filesystem::path const& path);
1390
1391 // Iterator
1392 inline fge::ObjectContainer::const_iterator begin() const { return this->g_objects.begin(); }
1393 inline fge::ObjectContainer::const_iterator end() const { return this->g_objects.end(); }
1394 inline fge::ObjectContainer::const_reverse_iterator rbegin() const { return this->g_objects.rbegin(); }
1395 inline fge::ObjectContainer::const_reverse_iterator rend() const { return this->g_objects.rend(); }
1396
1403 fge::ObjectContainer::const_iterator find(fge::ObjectSid sid) const;
1410 fge::ObjectContainer::const_iterator find(fge::Object const* ptr) const;
1417 fge::ObjectContainer::const_iterator findPlan(fge::ObjectPlan plan) const;
1418
1419 // Network type
1425
1426 // Properties
1431
1432 // Event
1435
1440
1448
1456
1457private:
1458 struct PerClientSync
1459 {
1460 inline explicit PerClientSync(UpdateCount updateCount) :
1461 _lastUpdateCount(updateCount)
1462 {}
1463
1464 UpdateCount _lastUpdateCount;
1465 NetworkEventQueue _networkEvents;
1466 };
1467 using PerClientSyncMap = std::unordered_map<fge::net::Identity, PerClientSync, fge::net::IdentityHash>;
1468
1469 void hash_updatePlanDataMap(fge::ObjectPlan plan, fge::ObjectContainer::iterator whoIterator, bool isLeaving);
1470 fge::ObjectContainer::iterator hash_getInsertionIteratorFromPlanDataMap(fge::ObjectPlan plan);
1471
1472 std::string g_name;
1473
1474 NetworkEventQueue g_sceneNetworkEvents;
1475 PerClientSyncMap g_perClientSyncs;
1476 bool g_enableNetworkEventsFlag;
1477
1478 //std::shared_ptr<fge::View> g_customView;
1479 fge::RenderTarget* g_linkedRenderTarget;
1480
1481 uint16_t g_updateCount;
1482 bool g_deleteMe; //Delete an object while updating flag
1483 fge::ObjectContainer::iterator g_updatedObjectIterator; //The iterator of the updated object
1484
1485 fge::ObjectContainer g_objects;
1486 fge::ObjectContainerHashMap g_objectsHashMap;
1487 fge::ObjectPlanDataMap g_planDataMap;
1488
1489 fge::CallbackContext g_callbackContext;
1490};
1491
1492} // namespace fge
1493
1494#endif // _FGE_C_SCENE_HPP_INCLUDED
This class is used to handle callbacks in a safe way.
Definition C_callback.hpp:189
Definition C_childObjectsAccessor.hpp:43
CommandHandler is a class that can be used to handle commands.
Definition C_commandHandler.hpp:55
A class to handle "flags" for an enum type.
Definition C_flag.hpp:104
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 hash map to have direct access to an Object in a Scene.
Definition C_scene.hpp:398
void delObject(ObjectSid sid)
Announce the deletion of an Object.
bool newSid(ObjectSid oldSid, ObjectSid newSid)
Announce a new SID for an Object.
bool newObject(ObjectSid sid, ObjectContainer::iterator it)
Announce a new Object in the hash map.
fge::Object * getObject() const
Get the Object pointer.
Definition C_scene.hpp:222
void setParent(fge::ObjectDataShared const &object) const
Set an parent object.
Definition C_scene.hpp:291
void clearParent() const
Clear the parent object.
Definition C_scene.hpp:301
fge::ObjectSid getSid() const
Get the SID of the Object.
Definition C_scene.hpp:241
fge::ObjectDataWeak getParent() const
Get the parent object.
Definition C_scene.hpp:307
static bool isValid(fge::ObjectDataShared const &data)
check if the provided shared pointer Object is valid.
Definition C_scene.hpp:351
bool isBound() const
Check if the Object is bound to a Scene.
Definition C_scene.hpp:314
fge::ObjectTypes getType() const
Get the type of the Object.
Definition C_scene.hpp:262
fge::ObjectPlanDepth getPlanDepth() const
Get the plan depth of the Object.
Definition C_scene.hpp:284
static fge::ObjectDataShared isValid(fge::ObjectDataWeak const &data)
check if the provided weak pointer Object is valid.
Definition C_scene.hpp:359
fge::ObjectPlan getPlan() const
Get the plan of the Object.
Definition C_scene.hpp:250
bool operator==(fge::ObjectSid const &sid) const
Comparison with another SID.
Definition C_scene.hpp:334
fge::Scene * getScene() const
Get the current bound Scene.
Definition C_scene.hpp:216
bool isClass(std::string_view const className) const
Check if the Object is a specific class.
Definition C_scene.hpp:322
fge::Object * releaseObject()
Release the Object handled by the smart pointer.
Definition C_scene.hpp:209
void setPlanDepth(fge::ObjectPlanDepth depth) const
Set the plan depth of the Object.
Definition C_scene.hpp:270
TObject * getObject() const
Get the Object pointer and cast it.
Definition C_scene.hpp:230
bool operator==(fge::Object const *ptr) const
Comparison with another object pointer.
Definition C_scene.hpp:340
The Object class is the base class for all objects in the engine.
Definition C_object.hpp:102
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
bool loadFromFile(std::filesystem::path const &path)
Load all the Scene data from a json file.
virtual fge::ObjectSid generateSid(fge::ObjectSid wanted_sid, fge::ObjectTypes type) const
Generate an SID based on the provided wanted SID.
fge::ObjectDataShared newObject(fge::ObjectPtr &&newObject, fge::ObjectPlan plan=fge::ObjectPlan { 100 }, fge::ObjectSid sid=std::numeric_limits< fge::ObjectSid >::max(), fge::ObjectTypes type=fge::ObjectTypes::OBJECT, bool silent=false, fge::EnumFlags< ObjectContextFlags > contextFlags=OBJ_CONTEXT_DEFAULT)
Add a new Object in the Scene.
void setName(std::string name)
Set the name of the Scene.
Definition C_scene.hpp:502
fge::CallbackHandler< fge::Scene & > _onDelayedUpdate
Event called only once after a Scene update.
Definition C_scene.hpp:1455
void clear()
Clear the Scene.
void updateAllPlanDepth(fge::ObjectPlan plan)
update the ObjectPlanDepth for every objects inside the same plan
bool isWatchingEvent() const
Check if the Scene is currently watching events. ".
void update(fge::RenderTarget &target, fge::Event &event, fge::DeltaTime const &deltaTime, std::underlying_type_t< UpdateFlags > flags=UpdateFlags::NONE)
Update of the Scene.
uint16_t getUpdateCount() const
Return the number of update.
void clearNetEventsQueue(fge::net::Identity const &id)
Clear Scene network events queue for the specified client.
void updateAllPlanDepth()
update the ObjectPlanDepth for every objects
fge::ObjectDataShared getFirstObj_ByPosition(fge::Vector2f const &pos) const
Get the first Object with a position.
std::optional< fge::net::Error > unpackModification(fge::net::Packet const &pck, UpdateCountRange &range, bool ignoreUpdateCount=false)
Unpack all modification of received data packet from a server.
fge::ObjectDataShared duplicateObject(fge::ObjectSid sid, fge::ObjectSid newSid=std::numeric_limits< fge::ObjectSid >::max())
Duplicate the provided Object SID.
fge::CallbackContext getCallbackContext() const
Get the callback context of this Scene.
fge::ObjectDataShared getFirstObj_ByClass(std::string_view class_name) const
Get the first Object that match a provided class name.
fge::Object * getObjectPtr(fge::ObjectSid sid) const
Get an Object pointer with his SID.
bool pushEvent(fge::SceneNetEvent const &netEvent, fge::net::Identity const &id)
Manually push a Scene related event for a specified client.
void forceCheckClient(fge::net::Identity const &id)
Force every network type modification flag to be true for a specified client net::Identity.
fge::ObjectDataShared getFirstObj_ByLocalZone(fge::RectInt const &zone, fge::RenderTarget const &target) const
Get the first Object within a local zone.
std::size_t getObjectSize() const
Get total Object stored in this Scene.
Definition C_scene.hpp:837
void signalObject(fge::ObjectSid sid, int8_t signal)
Signal an Object over the network.
fge::ObjectSid getSid(fge::Object const *ptr) const
Get the SID of the provided Object pointer.
std::size_t getAllObj_ByZone(fge::RectFloat const &zone, fge::ObjectContainer &buff) const
Get all Object within a zone (or rectangle).
bool saveInFile(std::filesystem::path const &path)
Save all the Scene with its Object in a file.
fge::ObjectDataShared getFirstObj_FromLocalZone(fge::RectInt const &zone, fge::RenderTarget const &target) const
Get the first Object within a local zone.
std::optional< fge::net::Error > unpack(fge::net::Packet const &pck, bool clearObjects=true)
Unpack all the received data of a serverside Scene.
void forceUncheckClient(fge::net::Identity const &id)
Force every network type modification flag to be false for a specified client net::Identity.
fge::RenderTarget * getLinkedRenderTarget()
Get the RenderTarget linked to this Scene (non-const).
bool setObject(fge::ObjectSid sid, fge::ObjectPtr &&newObject)
Set a new Object pointer in place of the provided one.
fge::CallbackHandler< fge::Scene &, fge::ObjectPlan > _onPlanUpdate
Event called when a change in the plan is detected.
Definition C_scene.hpp:1447
virtual void saveCustomData(nlohmann::json &jsonObject)
Save some user defined custom data.
Definition C_scene.hpp:1352
void clientsCheckup(fge::net::ClientList const &clients, bool force=false)
Do a clients checkup.
std::size_t delAllObject(bool ignoreGuiObject)
Delete every Object in the Scene.
virtual void loadCustomData(nlohmann::json &jsonObject)
Load some user defined custom data.
Definition C_scene.hpp:1363
bool delObject(fge::ObjectSid sid)
Delete the Object provided with his SID.
std::size_t getAllObj_ByClass(std::string_view class_name, fge::ObjectContainer &buff) const
Get all Object with the same class name.
fge::ObjectDataShared transferObject(fge::ObjectSid sid, fge::Scene &newScene)
Transfer the specified Object to another Scene.
fge::ObjectContainer::const_iterator findPlan(fge::ObjectPlan plan) const
Find an Object with the specified plan.
void clearPerClientSyncData()
Remove all network clients related data.
void packModification(fge::net::Packet &pck, fge::net::Identity const &id)
Pack all modification in a net::Packet for a net::Client.
void packNeededUpdate(fge::net::Packet &pck)
Pack object that need an explicit update from the server.
fge::ObjectDataShared getObject(fge::ObjectSid sid) const
Get an Object with his SID.
std::size_t getAllObj_FromLocalZone(fge::RectInt const &zone, fge::RenderTarget const &target, fge::ObjectContainer &buff) const
Get all Object within a local zone (or rectangle).
bool isValid(fge::ObjectSid sid) const
Check if the SID correspond to an Object in this Scene.
Definition C_scene.hpp:1071
fge::net::NetworkTypeHandler _netList
Definition C_scene.hpp:1424
std::size_t getAllObj_ByLocalPosition(fge::Vector2i const &pos, fge::RenderTarget const &target, fge::ObjectContainer &buff) const
Get all Object with a local position.
void setLinkedRenderTarget(fge::RenderTarget *target)
Link a RenderTarget to the Scene.
fge::RenderTarget const * getLinkedRenderTarget() const
Get the RenderTarget linked to this Scene.
fge::ObjectContainer::const_iterator find(fge::ObjectSid sid) const
Find an Object with the specified SID.
bool setObjectSid(fge::ObjectSid sid, fge::ObjectSid newSid)
Set the Object with a new SID.
bool setObjectPlanTop(fge::ObjectSid sid)
Set an Object on top of his plan.
fge::View const * getRelatedView() const
Get the related view of the scene.
void setCallbackContext(fge::CallbackContext context)
Set the callback context of this Scene.
fge::PropertyList _properties
Definition C_scene.hpp:1430
fge::ObjectDataShared getFirstObj_ByZone(fge::RectFloat const &zone) const
Get the first Object within a zone.
fge::CallbackHandler< fge::Scene &, fge::ObjectDataShared const & > _onObjectRemoved
Event called when an Object has been removed.
Definition C_scene.hpp:1439
void draw(fge::RenderTarget &target, fge::RenderStates const &states=fge::RenderStates{}) const
Draw the Scene.
fge::CallbackHandler< fge::Scene &, fge::ObjectDataShared const & > _onObjectAdded
Event called when a new Object has been added.
Definition C_scene.hpp:1437
void packWatchedEvent(fge::net::Packet &pck, fge::net::Identity const &id)
Pack all Scene related events for a specified client.
std::optional< fge::net::Error > unpackNeededUpdate(fge::net::Packet const &pck, fge::net::Identity const &id)
Unpack client object that require an explicit update.
std::size_t getAllObj_FromLocalPosition(fge::Vector2i const &pos, fge::RenderTarget const &target, fge::ObjectContainer &buff) const
Get all Object with a local position.
fge::ObjectPlanDepth updatePlanDepth(fge::ObjectSid sid)
update the ObjectPlanDepth for one object
fge::ObjectContainer::const_iterator find(fge::Object const *ptr) const
Find an Object with the specified Object pointer.
std::size_t getAllObj_ByLocalZone(fge::RectInt const &zone, fge::RenderTarget const &target, fge::ObjectContainer &buff) const
Get all Object within a local zone (or rectangle).
fge::ObjectDataShared getFirstObj_ByTag(std::string_view tag_name) const
Get the first Object that match a provided tag.
fge::ObjectDataShared getFirstObj_FromLocalPosition(fge::Vector2i const &pos, fge::RenderTarget const &target) const
Get the first Object with a local position.
fge::CallbackHandler< fge::Scene const &, fge::RenderTarget & > _onDraw
Event called when the Scene is about to be drawn.
Definition C_scene.hpp:1434
void pushEvent(fge::SceneNetEvent const &netEvent)
Manually push a Scene related event for every clients.
void delUpdatedObject()
Delete the actual updated Object.
void pack(fge::net::Packet &pck, fge::net::Identity const &id)
Pack all the Scene data in a Packet for a net::Client.
bool setObjectPlan(fge::ObjectSid sid, fge::ObjectPlan newPlan)
Set a new Object plan.
bool setObjectPlanBot(fge::ObjectSid sid)
Set an Object in the bottom of his plan.
void watchEvent(bool on)
Start to watch Scene related event or not.
std::string const & getName() const
Get the name of the Scene.
Definition C_scene.hpp:496
std::optional< fge::net::Error > unpackWatchedEvent(fge::net::Packet const &pck)
Unpack all Scene related events from a server.
std::size_t getAllObj_ByTag(std::string_view tag_name, fge::ObjectContainer &buff) const
Get all Object that contain the provided tag.
fge::ObjectDataShared getObject(fge::Object const *ptr) const
Get an Object with his pointer.
fge::ObjectDataShared getUpdatedObject() const
Get the actual updated Object.
fge::ObjectDataShared newObject(fge::ObjectDataShared const &objectData, bool silent=false)
Add a new Object in the Scene.
fge::ObjectDataShared getFirstObj_ByLocalPosition(fge::Vector2i const &pos, fge::RenderTarget const &target) const
Get the first Object with a local position.
std::size_t getAllObj_ByPosition(fge::Vector2f const &pos, fge::ObjectContainer &buff) const
Get all Object with a position.
void clearNetEventsQueue()
Clear Scene network events queue for all clients.
Define a camera in a 2D scene.
Definition C_view.hpp:49
A list of clients used by a server.
Definition C_clientList.hpp:60
A regroupment of network types.
Definition C_networkType.hpp:690
Definition C_packet.hpp:52
ObjectTypes
Represent different Object type.
Definition C_scene.hpp:119
Definition C_scene.hpp:83
Structure that represent an network event related to Scene.
Definition C_scene.hpp:97
Parameters for the newObject method.
Definition C_scene.hpp:611
Definition C_scene.hpp:470
A class to represent a client or server identity with an IP address and a port.
Definition C_identity.hpp:31