FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
Loading...
Searching...
No Matches
C_scene.hpp
1/*
2 * Copyright 2024 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 ObjectType : uint8_t
119{
120 TYPE_NULL = 0,
121
122 TYPE_OBJECT,
123 TYPE_DECAY,
124 TYPE_GUI,
125
126 TYPE_MAX_
127};
128
129static_assert(sizeof(fge::ObjectSid) == sizeof(uint32_t), "fge::ObjectSid must be the same size as uint32_t");
130static_assert(ObjectType::TYPE_MAX_ <= 4, "Too many ObjectTypes, DefaultSIDRanges must change");
131enum class DefaultSIDRanges : ObjectSid
132{
133 MASK_SIZE = 2,
134 MASK_POS = 30,
135 MASK = ObjectSid{0x3} << MASK_POS,
136
137 POS_NULL = ObjectSid{ObjectType::TYPE_NULL} << MASK_POS,
138 POS_OBJECT = ObjectSid{ObjectType::TYPE_OBJECT} << MASK_POS,
139 POS_DECAY = ObjectSid{ObjectType::TYPE_DECAY} << MASK_POS,
140 POS_GUI = ObjectSid{ObjectType::TYPE_GUI} << MASK_POS
141};
142using DefaultSIDRanges_t = std::underlying_type_t<DefaultSIDRanges>;
143
159{
160public:
161 inline ObjectData() :
162 g_boundScene(nullptr),
163
164 g_object(nullptr),
165 g_sid(FGE_SCENE_BAD_SID),
166 g_plan(FGE_SCENE_PLAN_DEFAULT),
167 g_type(fge::ObjectType::TYPE_NULL),
168
169 g_planDepth(FGE_SCENE_BAD_PLANDEPTH),
170 g_requireForceClientsCheckup(true)
171 {}
172 inline ObjectData(fge::Scene* boundScene,
173 fge::ObjectPtr&& newObj,
174 fge::ObjectSid newSid = FGE_SCENE_BAD_SID,
175 fge::ObjectPlan newPlan = FGE_SCENE_PLAN_DEFAULT,
176 fge::ObjectType newType = fge::ObjectType::TYPE_OBJECT) :
177 g_boundScene(boundScene),
178
179 g_object(std::move(newObj)),
180 g_sid(newSid),
181 g_plan(newPlan),
182 g_type(newType),
183
184 g_planDepth(FGE_SCENE_BAD_PLANDEPTH),
185 g_requireForceClientsCheckup(true)
186 {}
187
198 [[nodiscard]] inline fge::Object* releaseObject() { return this->g_object.release(); }
199
205 [[nodiscard]] inline fge::Scene* getScene() const { return this->g_boundScene; }
211 [[nodiscard]] inline fge::Object* getObject() const { return this->g_object.get(); }
218 template<class TObject>
219 [[nodiscard]] inline TObject* getObject() const
220 {
221 return reinterpret_cast<TObject*>(this->g_object.get());
222 }
230 [[nodiscard]] inline fge::ObjectSid getSid() const { return this->g_sid; }
239 [[nodiscard]] inline fge::ObjectPlan getPlan() const { return this->g_plan; }
251 [[nodiscard]] inline fge::ObjectType getType() const { return this->g_type; }
252
259 inline void setPlanDepth(fge::ObjectPlanDepth depth) const { this->g_planDepth = depth; }
273 [[nodiscard]] inline fge::ObjectPlanDepth getPlanDepth() const { return this->g_planDepth; }
274
280 inline void setParent(fge::ObjectDataShared const& object) const
281 {
282 if (object)
283 {
284 this->g_parent = object;
285 }
286 }
290 inline void clearParent() const { this->g_parent.reset(); }
296 [[nodiscard]] inline fge::ObjectDataWeak getParent() const { return this->g_parent; }
297
303 [[nodiscard]] inline bool isBound() const { return this->g_boundScene != nullptr; }
304
311 [[nodiscard]] inline bool isClass(std::string_view const className) const
312 {
313 return this->g_object->getClassName() == className;
314 }
315
321 [[nodiscard]] inline bool operator==(fge::ObjectSid const& sid) const { return this->g_sid == sid; }
327 [[nodiscard]] inline bool operator==(fge::Object const* ptr) const { return this->g_object.get() == ptr; }
328
338 [[nodiscard]] static inline bool isValid(fge::ObjectDataShared const& data) { return data && data->isBound(); }
339
346 [[nodiscard]] static inline fge::ObjectDataShared isValid(fge::ObjectDataWeak const& data)
347 {
348 if (auto dataShared = data.lock())
349 {
350 return dataShared->isBound() ? dataShared : nullptr;
351 }
352 return nullptr;
353 }
354
355private:
356 fge::Scene* g_boundScene;
357
358 fge::ObjectPtr g_object;
359 fge::ObjectSid g_sid;
360 fge::ObjectPlan g_plan;
361 fge::ObjectType g_type;
362
363 //Dynamic data (not saved, local only)
364 mutable fge::ObjectPlanDepth g_planDepth;
365 mutable fge::ObjectDataWeak g_parent;
366
367 bool g_requireForceClientsCheckup;
368
369 friend class fge::Scene;
370};
371
372using ObjectDataWeak = std::weak_ptr<fge::ObjectData>;
373using ObjectDataShared = std::shared_ptr<fge::ObjectData>;
374using ObjectContainer = std::list<fge::ObjectDataShared>;
375using ObjectPlanDataMap = std::map<fge::ObjectPlan, fge::ObjectContainer::iterator>;
376
383{
384public:
385 using Map = std::unordered_map<ObjectSid, ObjectContainer::iterator>;
386
387 ObjectContainerHashMap() = default;
388 explicit ObjectContainerHashMap(ObjectContainer& objects);
390 ObjectContainerHashMap(ObjectContainerHashMap&& r) noexcept = default;
391 ~ObjectContainerHashMap() = default;
392
393 ObjectContainerHashMap& operator=(ObjectContainerHashMap const& r) = delete;
394 ObjectContainerHashMap& operator=(ObjectContainerHashMap&& r) noexcept = default;
395
396 void clear();
397 void reMap(ObjectContainer& objects);
398
409 [[nodiscard]] bool newSid(ObjectSid oldSid, ObjectSid newSid);
420 [[nodiscard]] bool newObject(ObjectSid sid, ObjectContainer::iterator it);
426 void delObject(ObjectSid sid);
427
428 [[nodiscard]] std::optional<ObjectContainer::iterator> find(ObjectSid sid);
429 [[nodiscard]] std::optional<ObjectContainer::const_iterator> find(ObjectSid sid) const;
430 [[nodiscard]] fge::ObjectContainer::value_type retrieve(ObjectSid sid) const;
431 [[nodiscard]] bool contains(ObjectSid sid) const;
432
433 [[nodiscard]] std::size_t size() const;
434
435private:
436 Map g_objectMap;
437};
438
449class FGE_API Scene : public fge::CommandHandler
450{
451public:
452 using NetworkEventQueue = std::queue<fge::SceneNetEvent>;
453 using UpdateCount = uint16_t;
455 {
456 UpdateCount _last;
457 UpdateCount _now;
458 };
459
460 enum UpdateFlags : uint32_t
461 {
462 NONE = 0,
463 INCREMENT_UPDATE_COUNT = 1 << 0
464 };
465
466 Scene();
467 explicit Scene(std::string sceneName);
468 Scene(Scene const& r);
469 Scene(Scene&& r) noexcept = delete; //TODO: implement move constructor
470 virtual ~Scene() = default;
471
472 Scene& operator=(Scene const& r);
473 Scene& operator=(Scene&& r) noexcept = delete; //TODO: implement move operator
474
475 // Scene
481 inline std::string const& getName() const { return this->g_name; }
487 inline void setName(std::string name)
488 {
489 if (name.size() <= FGE_SCENE_LIMIT_NAMESIZE)
490 {
491 this->g_name = std::move(name);
492 }
493 }
494
509#ifdef FGE_DEF_SERVER
510 void update(fge::Event& event,
511 std::chrono::microseconds const& deltaTime,
512 std::underlying_type_t<UpdateFlags> flags = UpdateFlags::INCREMENT_UPDATE_COUNT);
513#else
515 fge::Event& event,
516 std::chrono::microseconds const& deltaTime,
517 std::underlying_type_t<UpdateFlags> flags = UpdateFlags::NONE);
518#endif
529 [[nodiscard]] uint16_t getUpdateCount() const;
530
549#ifndef FGE_DEF_SERVER
550 void draw(fge::RenderTarget& target, fge::RenderStates const& states = fge::RenderStates{}) const;
551#endif //FGE_DEF_SERVER
552
559 fge::ObjectPlanDepth updatePlanDepth(fge::ObjectSid sid);
565 void updateAllPlanDepth(fge::ObjectPlan plan);
573
582 void clear();
583
584 // Object
585
596 {
597 fge::ObjectPlan _plan{FGE_SCENE_PLAN_DEFAULT};
598 fge::ObjectSid _sid{FGE_SCENE_BAD_SID};
599 fge::ObjectType _type{fge::ObjectType::TYPE_OBJECT};
600 bool _silent{false};
601 };
602
624 fge::ObjectDataShared newObject(fge::ObjectPtr&& newObject,
625 fge::ObjectPlan plan = FGE_SCENE_PLAN_DEFAULT,
626 fge::ObjectSid sid = FGE_SCENE_BAD_SID,
627 fge::ObjectType type = fge::ObjectType::TYPE_OBJECT,
628 bool silent = false);
629
630 template<class TObject, class... TArgs>
631 inline TObject* newObject(NewObjectParameters const& parameters, TArgs&&... args)
632 {
633 static_assert(std::is_base_of_v<fge::Object, TObject>, "TObject must be a child of fge::Object");
634 auto object = this->newObject(std::make_unique<TObject>(std::forward<TArgs>(args)...), parameters._plan,
635 parameters._sid, parameters._type, parameters._silent);
636 return object ? object->template getObject<TObject>() : nullptr;
637 }
638 template<class TObject, class... TArgs>
639 inline TObject* newObject(TArgs&&... args)
640 {
641 static_assert(std::is_base_of_v<fge::Object, TObject>, "TObject must be a child of fge::Object");
642 auto object = this->newObject(std::make_unique<TObject>(std::forward<TArgs>(args)...));
643 return object ? object->template getObject<TObject>() : nullptr;
644 }
645 template<class TObject>
646 inline TObject* newObject()
647 {
648 static_assert(std::is_base_of_v<fge::Object, TObject>, "TObject must be a child of fge::Object");
649 auto object = this->newObject(std::make_unique<TObject>());
650 return object ? object->template getObject<TObject>() : nullptr;
651 }
666 fge::ObjectDataShared newObject(fge::ObjectDataShared const& objectData, bool silent = false);
667
680 fge::ObjectDataShared duplicateObject(fge::ObjectSid sid, fge::ObjectSid newSid = FGE_SCENE_BAD_SID);
681
704 fge::ObjectDataShared transferObject(fge::ObjectSid sid, fge::Scene& newScene);
705
728 bool delObject(fge::ObjectSid sid);
735 std::size_t delAllObject(bool ignoreGuiObject);
736
746 bool setObjectSid(fge::ObjectSid sid, fge::ObjectSid newSid);
757 bool setObject(fge::ObjectSid sid, fge::ObjectPtr&& newObject);
765 bool setObjectPlan(fge::ObjectSid sid, fge::ObjectPlan newPlan);
774 bool setObjectPlanTop(fge::ObjectSid sid);
783 bool setObjectPlanBot(fge::ObjectSid sid);
784
791 fge::ObjectDataShared getObject(fge::ObjectSid sid) const;
798 fge::ObjectDataShared getObject(fge::Object const* ptr) const;
805 fge::Object* getObjectPtr(fge::ObjectSid sid) const;
811 fge::ObjectDataShared getUpdatedObject() const;
812
818 inline std::size_t getObjectSize() const { return this->g_objects.size(); }
819
820 // Search function
833 std::size_t getAllObj_ByPosition(fge::Vector2f const& pos, fge::ObjectContainer& buff) const;
846 std::size_t getAllObj_ByZone(fge::RectFloat const& zone, fge::ObjectContainer& buff) const;
847
848#ifndef FGE_DEF_SERVER
866 std::size_t getAllObj_ByLocalPosition(fge::Vector2i const& pos,
867 fge::RenderTarget const& target,
868 fge::ObjectContainer& buff) const;
884 std::size_t
885 getAllObj_ByLocalZone(fge::RectInt const& zone, fge::RenderTarget const& target, fge::ObjectContainer& buff) const;
904 std::size_t getAllObj_FromLocalPosition(fge::Vector2i const& pos,
905 fge::RenderTarget const& target,
906 fge::ObjectContainer& buff) const;
925 std::size_t getAllObj_FromLocalZone(fge::RectInt const& zone,
926 fge::RenderTarget const& target,
927 fge::ObjectContainer& buff) const;
928#endif //FGE_DEF_SERVER
929
941 std::size_t getAllObj_ByClass(std::string_view class_name, fge::ObjectContainer& buff) const;
953 std::size_t getAllObj_ByTag(std::string_view tag_name, fge::ObjectContainer& buff) const;
954
963 fge::ObjectDataShared getFirstObj_ByPosition(fge::Vector2f const& pos) const;
972 fge::ObjectDataShared getFirstObj_ByZone(fge::RectFloat const& zone) const;
973
974#ifndef FGE_DEF_SERVER
984 fge::ObjectDataShared getFirstObj_ByLocalPosition(fge::Vector2i const& pos, fge::RenderTarget const& target) const;
994 fge::ObjectDataShared getFirstObj_ByLocalZone(fge::RectInt const& zone, fge::RenderTarget const& target) const;
1004 fge::ObjectDataShared getFirstObj_FromLocalPosition(fge::Vector2i const& pos,
1005 fge::RenderTarget const& target) const;
1015 fge::ObjectDataShared getFirstObj_FromLocalZone(fge::RectInt const& zone, fge::RenderTarget const& target) const;
1024#endif //FGE_DEF_SERVER
1025
1026 fge::ObjectDataShared getFirstObj_ByClass(std::string_view class_name) const;
1035 fge::ObjectDataShared getFirstObj_ByTag(std::string_view tag_name) const;
1036
1037 // Static id
1044 fge::ObjectSid getSid(fge::Object const* ptr) const;
1045
1052 inline bool isValid(fge::ObjectSid sid) const { return this->find(sid) != this->g_objects.cend(); }
1053
1067 virtual fge::ObjectSid generateSid(fge::ObjectSid wanted_sid, fge::ObjectType type) const;
1068
1069 // Network
1076 void signalObject(fge::ObjectSid sid, int8_t signal);
1077
1108 std::optional<fge::net::Error> unpack(fge::net::Packet const& pck);
1137 std::optional<fge::net::Error> unpackModification(fge::net::Packet const& pck, UpdateCountRange& range);
1138
1159 std::optional<fge::net::Error> unpackNeededUpdate(fge::net::Packet const& pck, fge::net::Identity const& id);
1160
1178
1193 void clientsCheckup(fge::net::ClientList const& clients, bool force = false);
1194
1195 // SceneNetEvent
1201 void pushEvent(fge::SceneNetEvent const& netEvent);
1208 bool pushEvent(fge::SceneNetEvent const& netEvent, fge::net::Identity const& id);
1219 void watchEvent(bool on);
1227 bool isWatchingEvent() const;
1228
1246
1261 std::optional<fge::net::Error> unpackWatchedEvent(fge::net::Packet const& pck);
1262
1263 // Operator
1264 inline fge::ObjectDataShared operator[](fge::ObjectSid sid) const { return this->getObject(sid); }
1265
1266 // Custom view
1274 void setCustomView(std::shared_ptr<fge::View> customView);
1282 std::shared_ptr<fge::View> const& getCustomView() const;
1289
1290 // Linked renderTarget
1315
1327 [[nodiscard]] fge::View const* getRelatedView() const;
1328
1347
1348 // Save/Load in file
1359 virtual void saveCustomData([[maybe_unused]] nlohmann::json& jsonObject) {};
1370 virtual void loadCustomData([[maybe_unused]] nlohmann::json& jsonObject) {};
1371
1382 bool saveInFile(std::string const& path);
1396 bool loadFromFile(std::string const& path);
1397
1398 // Iterator
1399 inline fge::ObjectContainer::const_iterator begin() const { return this->g_objects.begin(); }
1400 inline fge::ObjectContainer::const_iterator end() const { return this->g_objects.end(); }
1401 inline fge::ObjectContainer::const_reverse_iterator rbegin() const { return this->g_objects.rbegin(); }
1402 inline fge::ObjectContainer::const_reverse_iterator rend() const { return this->g_objects.rend(); }
1403
1410 fge::ObjectContainer::const_iterator find(fge::ObjectSid sid) const;
1417 fge::ObjectContainer::const_iterator find(fge::Object const* ptr) const;
1424 fge::ObjectContainer::const_iterator findPlan(fge::ObjectPlan plan) const;
1425
1426 // Network type
1432
1433 // Properties
1438
1439 // Event
1442
1447
1455
1463
1464private:
1465 struct PerClientSync
1466 {
1467 inline explicit PerClientSync(UpdateCount updateCount) :
1468 _lastUpdateCount(updateCount)
1469 {}
1470
1471 UpdateCount _lastUpdateCount;
1472 NetworkEventQueue _networkEvents;
1473 };
1474 using PerClientSyncMap = std::unordered_map<fge::net::Identity, PerClientSync, fge::net::IdentityHash>;
1475
1476 void hash_updatePlanDataMap(fge::ObjectPlan plan, fge::ObjectContainer::iterator whoIterator, bool isLeaving);
1477 fge::ObjectContainer::iterator hash_getInsertionIteratorFromPlanDataMap(fge::ObjectPlan plan);
1478
1479 std::string g_name;
1480
1481 NetworkEventQueue g_sceneNetworkEvents;
1482 PerClientSyncMap g_perClientSyncs;
1483 bool g_enableNetworkEventsFlag;
1484
1485 std::shared_ptr<fge::View> g_customView;
1486 fge::RenderTarget* g_linkedRenderTarget;
1487
1488 uint16_t g_updateCount;
1489 bool g_deleteMe; //Delete an object while updating flag
1490 fge::ObjectContainer::iterator g_updatedObjectIterator; //The iterator of the updated object
1491
1492 fge::ObjectContainer g_objects;
1493 fge::ObjectContainerHashMap g_objectsHashMap;
1494 fge::ObjectPlanDataMap g_planDataMap;
1495
1496 fge::CallbackContext g_callbackContext;
1497};
1498
1499} // namespace fge
1500
1501#endif // _FGE_C_SCENE_HPP_INCLUDED
This class is used to handle callbacks in a safe way.
Definition C_callback.hpp:189
CommandHandler is a class that can be used to handle commands.
Definition C_commandHandler.hpp:55
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:383
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.
Data wrapper representing an Object in a Scene.
Definition C_scene.hpp:159
fge::Object * getObject() const
Get the Object pointer.
Definition C_scene.hpp:211
void setParent(fge::ObjectDataShared const &object) const
Set an parent object.
Definition C_scene.hpp:280
void clearParent() const
Clear the parent object.
Definition C_scene.hpp:290
fge::ObjectSid getSid() const
Get the SID of the Object.
Definition C_scene.hpp:230
fge::ObjectDataWeak getParent() const
Get the parent object.
Definition C_scene.hpp:296
static bool isValid(fge::ObjectDataShared const &data)
check if the provided shared pointer Object is valid.
Definition C_scene.hpp:338
bool isBound() const
Check if the Object is bound to a Scene.
Definition C_scene.hpp:303
fge::ObjectType getType() const
Get the type of the Object.
Definition C_scene.hpp:251
fge::ObjectPlanDepth getPlanDepth() const
Get the plan depth of the Object.
Definition C_scene.hpp:273
static fge::ObjectDataShared isValid(fge::ObjectDataWeak const &data)
check if the provided weak pointer Object is valid.
Definition C_scene.hpp:346
fge::ObjectPlan getPlan() const
Get the plan of the Object.
Definition C_scene.hpp:239
bool operator==(fge::ObjectSid const &sid) const
Comparison with another SID.
Definition C_scene.hpp:321
fge::Scene * getScene() const
Get the current bound Scene.
Definition C_scene.hpp:205
bool isClass(std::string_view const className) const
Check if the Object is a specific class.
Definition C_scene.hpp:311
fge::Object * releaseObject()
Release the Object handled by the smart pointer.
Definition C_scene.hpp:198
void setPlanDepth(fge::ObjectPlanDepth depth) const
Set the plan depth of the Object.
Definition C_scene.hpp:259
TObject * getObject() const
Get the Object pointer and cast it.
Definition C_scene.hpp:219
bool operator==(fge::Object const *ptr) const
Comparison with another object pointer.
Definition C_scene.hpp:327
The Object class is the base class for all objects in the engine.
Definition C_object.hpp:102
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
Definition C_renderWindow.hpp:51
A scene contain a collection of object and handle them.
Definition C_scene.hpp:450
void setName(std::string name)
Set the name of the Scene.
Definition C_scene.hpp:487
fge::CallbackHandler< fge::Scene & > _onDelayedUpdate
Event called only once after a Scene update.
Definition C_scene.hpp:1462
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 delCustomView()
Remove the actual custom view.
bool loadFromFile(std::string const &path)
Load all the Scene data from a json file.
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.
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:818
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).
fge::ObjectDataShared getFirstObj_FromLocalZone(fge::RectInt const &zone, fge::RenderTarget const &target) const
Get the first Object within a local zone.
void forceUncheckClient(fge::net::Identity const &id)
Force every network type modification flag to be false for a specified client net::Identity.
void update(fge::RenderWindow &screen, fge::Event &event, std::chrono::microseconds const &deltaTime, std::underlying_type_t< UpdateFlags > flags=UpdateFlags::NONE)
Update of the Scene.
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:1454
virtual void saveCustomData(nlohmann::json &jsonObject)
Save some user defined custom data.
Definition C_scene.hpp:1359
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:1370
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.
std::optional< fge::net::Error > unpack(fge::net::Packet const &pck)
Unpack all the received data of a serverside Scene.
fge::ObjectDataShared transferObject(fge::ObjectSid sid, fge::Scene &newScene)
Transfer the specified Object to another Scene.
void pack(fge::net::Packet &pck)
Pack all the Scene data in a Packet.
fge::ObjectContainer::const_iterator findPlan(fge::ObjectPlan plan) const
Find an Object with the specified plan.
std::shared_ptr< fge::View > const & getCustomView() const
Get the custom shared view if there is one.
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).
std::optional< fge::net::Error > unpackModification(fge::net::Packet const &pck, UpdateCountRange &range)
Unpack all modification of received data packet from a server.
bool isValid(fge::ObjectSid sid) const
Check if the SID correspond to an Object in this Scene.
Definition C_scene.hpp:1052
fge::net::NetworkTypeHandler _netList
Definition C_scene.hpp:1431
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.
fge::ObjectDataShared newObject(fge::ObjectPtr &&newObject, fge::ObjectPlan plan=fge::ObjectPlan { 100 }, fge::ObjectSid sid=std::numeric_limits< fge::ObjectSid >::max(), fge::ObjectType type=fge::ObjectType::TYPE_OBJECT, bool silent=false)
Add a new Object in the Scene.
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:1437
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:1446
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:1444
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.
virtual fge::ObjectSid generateSid(fge::ObjectSid wanted_sid, fge::ObjectType type) const
Generate an SID based on the provided wanted SID.
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 position.
fge::CallbackHandler< fge::Scene const &, fge::RenderTarget & > _onDraw
Event called when the Scene is about to be drawn.
Definition C_scene.hpp:1441
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.
void setCustomView(std::shared_ptr< fge::View > customView)
Set a custom shared view.
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:481
std::optional< fge::net::Error > unpackWatchedEvent(fge::net::Packet const &pck)
Unpack all Scene related events from a server.
bool saveInFile(std::string const &path)
Save all the Scene with its Object in a file.
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:43
A list of clients used by a server.
Definition C_clientList.hpp:57
A regroupment of network types.
Definition C_networkType.hpp:590
Definition C_packet.hpp:70
ObjectType
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:596
Definition C_scene.hpp:455
A class to represent a client or server identity with an IP address and a port.
Definition C_identity.hpp:31