![]() |
FastEngine 0.9.3
A multiplayer oriented 2D engine made with Vulkan.
|
A scene contain a collection of object and handle them. More...
#include <C_scene.hpp>
Classes | |
struct | NewObjectParameters |
Parameters for the newObject method. More... | |
struct | UpdateCountRange |
Public Types | |
enum | UpdateFlags : uint32_t { NONE = 0 , INCREMENT_UPDATE_COUNT = 1 << 0 } |
using | NetworkEventQueue = std::queue<fge::SceneNetEvent> |
using | UpdateCount = uint16_t |
using | CommandDataType = std::vector<fge::CommandHandler::CommandData> |
Public Member Functions | |
Scene (std::string sceneName) | |
Scene (Scene const &r) | |
Scene (Scene &&r) noexcept=delete | |
Scene & | operator= (Scene const &r) |
Scene & | operator= (Scene &&r) noexcept=delete |
std::string const & | getName () const |
Get the name of the Scene. | |
void | setName (std::string name) |
Set the name of the Scene. | |
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. | |
uint16_t | getUpdateCount () const |
Return the number of update. | |
void | draw (fge::RenderTarget &target, fge::RenderStates const &states=fge::RenderStates{}) const |
Draw the Scene. | |
fge::ObjectPlanDepth | updatePlanDepth (fge::ObjectSid sid) |
update the ObjectPlanDepth for one object | |
void | updateAllPlanDepth (fge::ObjectPlan plan) |
update the ObjectPlanDepth for every objects inside the same plan | |
void | updateAllPlanDepth () |
update the ObjectPlanDepth for every objects | |
void | clear () |
Clear the Scene. | |
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. | |
template<class TObject , class... TArgs> | |
TObject * | newObject (NewObjectParameters const ¶meters, TArgs &&... args) |
template<class TObject , class... TArgs> | |
TObject * | newObject (TArgs &&... args) |
template<class TObject > | |
TObject * | newObject () |
fge::ObjectDataShared | newObject (fge::ObjectDataShared const &objectData, bool silent=false) |
Add a new Object in the Scene. | |
fge::ObjectDataShared | duplicateObject (fge::ObjectSid sid, fge::ObjectSid newSid=std::numeric_limits< fge::ObjectSid >::max()) |
Duplicate the provided Object SID. | |
fge::ObjectDataShared | transferObject (fge::ObjectSid sid, fge::Scene &newScene) |
Transfer the specified Object to another Scene. | |
void | delUpdatedObject () |
Delete the actual updated Object. | |
bool | delObject (fge::ObjectSid sid) |
Delete the Object provided with his SID. | |
std::size_t | delAllObject (bool ignoreGuiObject) |
Delete every Object in the Scene. | |
bool | setObjectSid (fge::ObjectSid sid, fge::ObjectSid newSid) |
Set the Object with a new SID. | |
bool | setObject (fge::ObjectSid sid, fge::ObjectPtr &&newObject) |
Set a new Object pointer in place of the provided one. | |
bool | setObjectPlan (fge::ObjectSid sid, fge::ObjectPlan newPlan) |
Set a new Object plan. | |
bool | setObjectPlanTop (fge::ObjectSid sid) |
Set an Object on top of his plan. | |
bool | setObjectPlanBot (fge::ObjectSid sid) |
Set an Object in the bottom of his plan. | |
fge::ObjectDataShared | getObject (fge::ObjectSid sid) const |
Get an Object with his SID. | |
fge::ObjectDataShared | getObject (fge::Object const *ptr) const |
Get an Object with his pointer. | |
fge::Object * | getObjectPtr (fge::ObjectSid sid) const |
Get an Object pointer with his SID. | |
fge::ObjectDataShared | getUpdatedObject () const |
Get the actual updated Object. | |
std::size_t | getObjectSize () const |
Get total Object stored in this Scene. | |
std::size_t | getAllObj_ByPosition (fge::Vector2f const &pos, fge::ObjectContainer &buff) const |
Get all Object with a position. | |
std::size_t | getAllObj_ByZone (fge::RectFloat const &zone, fge::ObjectContainer &buff) const |
Get all Object within a zone (or rectangle). | |
std::size_t | getAllObj_ByLocalPosition (fge::Vector2i const &pos, fge::RenderTarget const &target, fge::ObjectContainer &buff) const |
Get all Object with a local position. | |
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). | |
std::size_t | getAllObj_FromLocalPosition (fge::Vector2i const &pos, fge::RenderTarget const &target, fge::ObjectContainer &buff) const |
Get all Object with a local position. | |
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::size_t | getAllObj_ByClass (std::string_view class_name, fge::ObjectContainer &buff) const |
Get all Object with the same class name. | |
std::size_t | getAllObj_ByTag (std::string_view tag_name, fge::ObjectContainer &buff) const |
Get all Object that contain the provided tag. | |
fge::ObjectDataShared | getFirstObj_ByPosition (fge::Vector2f const &pos) const |
Get the first Object with a position. | |
fge::ObjectDataShared | getFirstObj_ByZone (fge::RectFloat const &zone) const |
Get the first Object within a zone. | |
fge::ObjectDataShared | getFirstObj_ByLocalPosition (fge::Vector2i const &pos, fge::RenderTarget const &target) const |
Get the first Object with a local position. | |
fge::ObjectDataShared | getFirstObj_ByLocalZone (fge::RectInt const &zone, fge::RenderTarget const &target) const |
Get the first Object within a local zone. | |
fge::ObjectDataShared | getFirstObj_FromLocalPosition (fge::Vector2i const &pos, fge::RenderTarget const &target) const |
Get the first Object with a local position position. | |
fge::ObjectDataShared | getFirstObj_FromLocalZone (fge::RectInt const &zone, fge::RenderTarget const &target) const |
Get the first Object within a local zone. | |
fge::ObjectDataShared | getFirstObj_ByClass (std::string_view class_name) const |
Get the first Object that match a provided class name. | |
fge::ObjectDataShared | getFirstObj_ByTag (std::string_view tag_name) const |
Get the first Object that match a provided tag. | |
fge::ObjectSid | getSid (fge::Object const *ptr) const |
Get the SID of the provided Object pointer. | |
bool | isValid (fge::ObjectSid sid) const |
Check if the SID correspond to an Object in this Scene. | |
virtual fge::ObjectSid | generateSid (fge::ObjectSid wanted_sid, fge::ObjectType type) const |
Generate an SID based on the provided wanted SID. | |
void | signalObject (fge::ObjectSid sid, int8_t signal) |
Signal an Object over the network. | |
void | pack (fge::net::Packet &pck) |
Pack all the Scene data in a Packet. | |
void | pack (fge::net::Packet &pck, fge::net::Identity const &id) |
Pack all the Scene data in a Packet for a net::Client. | |
std::optional< fge::net::Error > | unpack (fge::net::Packet const &pck) |
Unpack all the received data of a serverside Scene. | |
void | packModification (fge::net::Packet &pck, fge::net::Identity const &id) |
Pack all modification in a net::Packet for a net::Client. | |
std::optional< fge::net::Error > | unpackModification (fge::net::Packet const &pck, UpdateCountRange &range) |
Unpack all modification of received data packet from a server. | |
void | packNeededUpdate (fge::net::Packet &pck) |
Pack object that need an explicit update from the server. | |
std::optional< fge::net::Error > | unpackNeededUpdate (fge::net::Packet const &pck, fge::net::Identity const &id) |
Unpack client object that require an explicit update. | |
void | forceCheckClient (fge::net::Identity const &id) |
Force every network type modification flag to be true for a specified client net::Identity. | |
void | forceUncheckClient (fge::net::Identity const &id) |
Force every network type modification flag to be false for a specified client net::Identity. | |
void | clientsCheckup (fge::net::ClientList const &clients, bool force=false) |
Do a clients checkup. | |
void | pushEvent (fge::SceneNetEvent const &netEvent) |
Manually push a Scene related event for every clients. | |
bool | pushEvent (fge::SceneNetEvent const &netEvent, fge::net::Identity const &id) |
Manually push a Scene related event for a specified client. | |
void | watchEvent (bool on) |
Start to watch Scene related event or not. | |
bool | isWatchingEvent () const |
Check if the Scene is currently watching events. ". | |
void | clearNetEventsQueue (fge::net::Identity const &id) |
Clear Scene network events queue for the specified client. | |
void | clearNetEventsQueue () |
Clear Scene network events queue for all clients. | |
void | clearPerClientSyncData () |
Remove all network clients related data. | |
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 > | unpackWatchedEvent (fge::net::Packet const &pck) |
Unpack all Scene related events from a server. | |
fge::ObjectDataShared | operator[] (fge::ObjectSid sid) const |
void | setCustomView (std::shared_ptr< fge::View > customView) |
Set a custom shared view. | |
std::shared_ptr< fge::View > const & | getCustomView () const |
Get the custom shared view if there is one. | |
void | delCustomView () |
Remove the actual custom view. | |
void | setLinkedRenderTarget (fge::RenderTarget *target) |
Link a RenderTarget to the Scene. | |
fge::RenderTarget const * | getLinkedRenderTarget () const |
Get the RenderTarget linked to this Scene. | |
fge::RenderTarget * | getLinkedRenderTarget () |
Get the RenderTarget linked to this Scene (non-const). | |
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::CallbackContext | getCallbackContext () const |
Get the callback context of this Scene. | |
virtual void | saveCustomData (nlohmann::json &jsonObject) |
Save some user defined custom data. | |
virtual void | loadCustomData (nlohmann::json &jsonObject) |
Load some user defined custom data. | |
bool | saveInFile (std::string const &path) |
Save all the Scene with its Object in a file. | |
bool | loadFromFile (std::string const &path) |
Load all the Scene data from a json file. | |
fge::ObjectContainer::const_iterator | begin () const |
fge::ObjectContainer::const_iterator | end () const |
fge::ObjectContainer::const_reverse_iterator | rbegin () const |
fge::ObjectContainer::const_reverse_iterator | rend () const |
fge::ObjectContainer::const_iterator | find (fge::ObjectSid sid) const |
Find an Object with the specified SID. | |
fge::ObjectContainer::const_iterator | find (fge::Object const *ptr) const |
Find an Object with the specified Object pointer. | |
fge::ObjectContainer::const_iterator | findPlan (fge::ObjectPlan plan) const |
Find an Object with the specified plan. | |
bool | addCmd (std::string_view name, fge::CommandHandler *handle, fge::CommandFunction cmdfunc) |
Add a new command to the handler. | |
void | delCmd (std::string_view name) |
Delete a command from the handler. | |
bool | replaceCmd (std::string_view name, fge::CommandHandler *handle, fge::CommandFunction cmdfunc) |
Replace a command from the handler. | |
void | clearCmd () |
Clear all commands from the handler. | |
fge::Property | callCmd (std::string_view name, fge::Object *caller, fge::Property const &arg, fge::Scene *caller_scene) |
Call a command by its name. | |
fge::Property | callCmd (std::size_t index, fge::Object *caller, fge::Property const &arg, fge::Scene *caller_scene) |
Call a command by its index. | |
std::size_t | getCmdIndex (std::string_view name) const |
Get the index of a command by its name. | |
std::string_view | getCmdName (std::size_t index) const |
Get the name of a command by its index. | |
fge::CommandHandler::CommandData const * | getCmd (std::string_view name) const |
Get a command by its name. | |
std::size_t | getCmdSize () const |
Get the number of commands. | |
fge::CommandHandler::CommandDataType const & | getCmdList () const |
Get the commands list. | |
Public Attributes | |
fge::net::NetworkTypeHandler | _netList |
fge::PropertyList | _properties |
fge::CallbackHandler< fge::Scene const &, fge::RenderTarget & > | _onDraw |
Event called when the Scene is about to be drawn. | |
fge::CallbackHandler< fge::Scene &, fge::ObjectDataShared const & > | _onObjectAdded |
Event called when a new Object has been added. | |
fge::CallbackHandler< fge::Scene &, fge::ObjectDataShared const & > | _onObjectRemoved |
Event called when an Object has been removed. | |
fge::CallbackHandler< fge::Scene &, fge::ObjectPlan > | _onPlanUpdate |
Event called when a change in the plan is detected. | |
fge::CallbackHandler< fge::Scene & > | _onDelayedUpdate |
Event called only once after a Scene update. | |
A scene contain a collection of object and handle them.
The job of a Scene is to hande a collection of Object and implement some utility method for the user to control them.
|
inherited |
Add a new command to the handler.
An object should inherit from CommandHandler and add commands to it.
name | The name of the command |
handle | The object that will handle the command |
cmdfunc | The function pointer of the command |
|
inherited |
Call a command by its index.
index | The index of the command |
caller | The object that call the command |
arg | The arguments of the command |
caller_scene | The scene that contains the caller |
|
inherited |
Call a command by its name.
name | The name of the command |
caller | The object that call the command |
arg | The arguments of the command |
caller_scene | The scene that contains the caller |
void fge::Scene::clear | ( | ) |
|
inherited |
Clear all commands from the handler.
void fge::Scene::clearNetEventsQueue | ( | ) |
Clear Scene network events queue for all clients.
void fge::Scene::clearNetEventsQueue | ( | fge::net::Identity const & | id | ) |
Clear Scene network events queue for the specified client.
id | A client net::Identity |
void fge::Scene::clearPerClientSyncData | ( | ) |
Remove all network clients related data.
After a call to this function, you have to recall clientsCheckupEvent to re-register clients.
void fge::Scene::clientsCheckup | ( | fge::net::ClientList const & | clients, |
bool | force = false ) |
Do a clients checkup.
A clients checkup is necessary to keep an eye of new/removal client and keep a modification flag for every one of them.
Clients latency will vary a lot, so to keep an eye of what partial Scene modification have to be sent, a clients checkup is required.
clients | The net::ClientList attributed to this Scene |
force | If true, all per clients data will clear and redo a full checkup |
std::size_t fge::Scene::delAllObject | ( | bool | ignoreGuiObject | ) |
|
inherited |
Delete a command from the handler.
name | The name of the command |
void fge::Scene::delCustomView | ( | ) |
Remove the actual custom view.
bool fge::Scene::delObject | ( | fge::ObjectSid | sid | ) |
void fge::Scene::delUpdatedObject | ( | ) |
Delete the actual updated Object.
This method mark the actual Object to be deleted internally. When the actual Object has finished is update, the update() method correctly delete it.
void fge::Scene::draw | ( | fge::RenderTarget & | target, |
fge::RenderStates const & | states = fge::RenderStates{} ) const |
Draw the Scene.
This method call the Object::draw method of every Object in the scene.
The scene will draw an object according to it's Object::_drawMode : By default, the Scene check if the global bounds of the Object is in the bounds of the screen and draw it if it's there.
This behaviour can be surpassed by setting Object::_drawMode.
During the draw, the depth plan is re-assigned depending on the Object plan and position in the list.
target | A RenderTarget |
states | The default RenderStates to be used for every drawn Object |
fge::ObjectDataShared fge::Scene::duplicateObject | ( | fge::ObjectSid | sid, |
fge::ObjectSid | newSid = std::numeric_limits< fge::ObjectSid >::max() ) |
Duplicate the provided Object SID.
This method duplicate the Object corresponding to the provided SID by giving a new SID to the freshly duplicated Object.
This method call the Object::copy method.
fge::ObjectContainer::const_iterator fge::Scene::find | ( | fge::Object const * | ptr | ) | const |
Find an Object with the specified Object pointer.
ptr | The Object pointer |
fge::ObjectContainer::const_iterator fge::Scene::find | ( | fge::ObjectSid | sid | ) | const |
Find an Object with the specified SID.
sid | The Object SID |
fge::ObjectContainer::const_iterator fge::Scene::findPlan | ( | fge::ObjectPlan | plan | ) | const |
Find an Object with the specified plan.
plan | The Object plan |
void fge::Scene::forceCheckClient | ( | fge::net::Identity const & | id | ) |
Force every network type modification flag to be true for a specified client net::Identity.
When a modification flag is true for a net::NetworkType, every data affected will be packed in the next call of packModification
id | The client net::Identity |
void fge::Scene::forceUncheckClient | ( | fge::net::Identity const & | id | ) |
Force every network type modification flag to be false for a specified client net::Identity.
id | The client net::Identity |
|
virtual |
Generate an SID based on the provided wanted SID.
By default, if the wanted SID is FGE_SCENE_BAD_SID, this function try to generate one with random value using fge::_random. The last 2bits in the SID is also here to separate from each of ObjectType.
If the wanted SID is already taken, this will cause a random SID generation.
wanted_sid | The wanted SID |
type | The type of the Object |
std::size_t fge::Scene::getAllObj_ByClass | ( | std::string_view | class_name, |
fge::ObjectContainer & | buff ) const |
Get all Object with the same class name.
class_name | The wanted class name |
buff | An ObjectContainer that will receive results |
std::size_t fge::Scene::getAllObj_ByLocalPosition | ( | fge::Vector2i const & | pos, |
fge::RenderTarget const & | target, | ||
fge::ObjectContainer & | buff ) const |
Get all Object with a local position.
This function first convert the local position to global coordinate with the custom view of the Scene if there is one. Then it check if the global bounds of every Object contain the provided position.
pos | The local position |
target | An RenderTarget |
buff | An ObjectContainer that will receive results |
std::size_t fge::Scene::getAllObj_ByLocalZone | ( | fge::RectInt const & | zone, |
fge::RenderTarget const & | target, | ||
fge::ObjectContainer & | buff ) const |
Get all Object within a local zone (or rectangle).
This function first convert the local zone to global coordinate with the custom view of the Scene if there is one. Then it check if the global bounds of every Object intersect with the provided zone (or rectangle).
zone | The local zone |
target | An RenderTarget |
buff | An ObjectContainer that will receive results |
std::size_t fge::Scene::getAllObj_ByPosition | ( | fge::Vector2f const & | pos, |
fge::ObjectContainer & | buff ) const |
Get all Object with a position.
This function check if the global bounds of every Object contain the provided position.
pos | The position |
buff | An ObjectContainer that will receive results |
std::size_t fge::Scene::getAllObj_ByTag | ( | std::string_view | tag_name, |
fge::ObjectContainer & | buff ) const |
std::size_t fge::Scene::getAllObj_ByZone | ( | fge::RectFloat const & | zone, |
fge::ObjectContainer & | buff ) const |
Get all Object within a zone (or rectangle).
This function check if the global bounds of every Object intersect with the provided zone (or rectangle).
zone | The zone |
buff | An ObjectContainer that will receive results |
std::size_t fge::Scene::getAllObj_FromLocalPosition | ( | fge::Vector2i const & | pos, |
fge::RenderTarget const & | target, | ||
fge::ObjectContainer & | buff ) const |
Get all Object with a local position.
Instead of converting the provided local position to global coordinate, this function convert the global bounds of the Object to local coordinate and check if converted local bounds contain the provided position.
This function will use the custom view of the Scene if there is one.
pos | The local position |
target | An RenderTarget |
buff | An ObjectContainer that will receive results |
std::size_t fge::Scene::getAllObj_FromLocalZone | ( | fge::RectInt const & | zone, |
fge::RenderTarget const & | target, | ||
fge::ObjectContainer & | buff ) const |
Get all Object within a local zone (or rectangle).
Instead of converting the provided local zone to global coordinate, this function convert the global bounds of the Object to local coordinate and check if the converted local bounds intersect with the provided zone.
This function will use the custom view of the Scene if there is one.
zone | The local zone |
target | An RenderTarget |
buff | An ObjectContainer that will receive results |
fge::CallbackContext fge::Scene::getCallbackContext | ( | ) | const |
|
nodiscardinherited |
Get a command by its name.
name | The name of the command |
|
nodiscardinherited |
Get the index of a command by its name.
name | The name of the command |
|
nodiscardinherited |
Get the commands list.
|
nodiscardinherited |
Get the name of a command by its index.
index | The index of the command |
|
nodiscardinherited |
Get the number of commands.
std::shared_ptr< fge::View > const & fge::Scene::getCustomView | ( | ) | const |
Get the custom shared view if there is one.
fge::ObjectDataShared fge::Scene::getFirstObj_ByClass | ( | std::string_view | class_name | ) | const |
Get the first Object that match a provided class name.
class_name | The class name |
fge::ObjectDataShared fge::Scene::getFirstObj_ByLocalPosition | ( | fge::Vector2i const & | pos, |
fge::RenderTarget const & | target ) const |
Get the first Object with a local position.
pos | The local position |
target | The RenderTarget |
fge::ObjectDataShared fge::Scene::getFirstObj_ByLocalZone | ( | fge::RectInt const & | zone, |
fge::RenderTarget const & | target ) const |
Get the first Object within a local zone.
zone | The local zone |
target | The RenderTarget |
fge::ObjectDataShared fge::Scene::getFirstObj_ByPosition | ( | fge::Vector2f const & | pos | ) | const |
Get the first Object with a position.
pos | The position |
fge::ObjectDataShared fge::Scene::getFirstObj_ByTag | ( | std::string_view | tag_name | ) | const |
Get the first Object that match a provided tag.
tag_name | The tag |
fge::ObjectDataShared fge::Scene::getFirstObj_ByZone | ( | fge::RectFloat const & | zone | ) | const |
Get the first Object within a zone.
zone | The zone |
fge::ObjectDataShared fge::Scene::getFirstObj_FromLocalPosition | ( | fge::Vector2i const & | pos, |
fge::RenderTarget const & | target ) const |
Get the first Object with a local position position.
pos | The position |
target | The RenderTarget |
fge::ObjectDataShared fge::Scene::getFirstObj_FromLocalZone | ( | fge::RectInt const & | zone, |
fge::RenderTarget const & | target ) const |
Get the first Object within a local zone.
zone | The local zone |
target | The RenderTarget |
fge::RenderTarget * fge::Scene::getLinkedRenderTarget | ( | ) |
Get the RenderTarget linked to this Scene (non-const).
fge::RenderTarget const * fge::Scene::getLinkedRenderTarget | ( | ) | const |
Get the RenderTarget linked to this Scene.
|
inline |
fge::ObjectDataShared fge::Scene::getObject | ( | fge::Object const * | ptr | ) | const |
Get an Object with his pointer.
ptr | Actual pointer of the wanted Object |
fge::ObjectDataShared fge::Scene::getObject | ( | fge::ObjectSid | sid | ) | const |
Get an Object with his SID.
sid | Actual SID of the wanted Object |
fge::Object * fge::Scene::getObjectPtr | ( | fge::ObjectSid | sid | ) | const |
|
inline |
|
nodiscard |
Get the related view of the scene.
If the scene have a custom view set, the custom view is returned. Else if the scene have a linked render target, the view of this render target is returned.
Else return nullptr.
fge::ObjectSid fge::Scene::getSid | ( | fge::Object const * | ptr | ) | const |
|
nodiscard |
Return the number of update.
In order to increment the update count, the UpdateFlags::INCREMENT_UPDATE_COUNT flag must be used while calling the update method.
This flag is generally set by the server.
fge::ObjectDataShared fge::Scene::getUpdatedObject | ( | ) | const |
Get the actual updated Object.
|
inline |
bool fge::Scene::isWatchingEvent | ( | ) | const |
Check if the Scene is currently watching events. ".
|
inlinevirtual |
Load some user defined custom data.
This function doesn't do anything by default but can be override to load some data during a loadFromFile call.
jsonObject | The json object |
bool fge::Scene::loadFromFile | ( | std::string const & | path | ) |
Load all the Scene data from a json file.
This function load all the data from a json format.
path | The path of the file |
fge::ObjectDataShared fge::Scene::newObject | ( | fge::ObjectDataShared const & | objectData, |
bool | silent = false ) |
Add a new Object in the Scene.
This method add already handled shared ObjectData in the Scene. The bound Scene is automatically set to the target Scene.
If the object is created inside the update() method from a second object, the second object become parent.
objectData | The shared ObjectData |
silent | If true, the Scene will not call the Object::first or Object::callbackRegister methods |
fge::ObjectDataShared fge::Scene::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.
This method add a created Object in the Scene. The provided SID is passed to the virtual generateSid() method.
If the object is created inside the update() method from a second object, the second object become parent.
newObject | The object pointer allocated by the user |
plan | The plan of the new object |
sid | The wanted SID |
type | The type of the new Object |
silent | If true, the Scene will not call the Object::first or Object::callbackRegister methods |
void fge::Scene::pack | ( | fge::net::Packet & | pck | ) |
void fge::Scene::pack | ( | fge::net::Packet & | pck, |
fge::net::Identity const & | id ) |
Pack all the Scene data in a Packet for a net::Client.
This function is useful to do a full Scene synchronisation in a network from a server. By providing a net::Identity, the function will initialise/reset some internal sync stats like update count.
pck | The network packet |
id | The Identity of the client |
void fge::Scene::packModification | ( | fge::net::Packet & | pck, |
fge::net::Identity const & | id ) |
Pack all modification in a net::Packet for a net::Client.
The scene check for variable modification, the new value is then packed in the network net::Packet, with some basic Object information like the SID.
This allow a partial synchronisation between multiple clients and a server. A partial sync is here to avoid re-sending over and over the same or a bit modified full Scene data. If you have a lots of Object, this can be helpful for Packet size and bandwidth.
pck | The network packet |
id | The Identity of the client |
void fge::Scene::packNeededUpdate | ( | fge::net::Packet & | pck | ) |
Pack object that need an explicit update from the server.
This should be called by a client to ask the server for specific network value update.
pck | The network packet |
void fge::Scene::packWatchedEvent | ( | fge::net::Packet & | pck, |
fge::net::Identity const & | id ) |
Pack all Scene related events for a specified client.
After a call to this function, the event queue is empty.
pck | The network packet |
id | The client net::Identity |
void fge::Scene::pushEvent | ( | fge::SceneNetEvent const & | netEvent | ) |
Manually push a Scene related event for every clients.
netEvent | The SceneNetEvent |
bool fge::Scene::pushEvent | ( | fge::SceneNetEvent const & | netEvent, |
fge::net::Identity const & | id ) |
Manually push a Scene related event for a specified client.
netEvent | The SceneNetEvent |
id | A client net::Identity |
|
inherited |
Replace a command from the handler.
name | The name of the command |
handle | The new object that will handle the command |
cmdfunc | The new function pointer of the command |
|
inlinevirtual |
Save some user defined custom data.
This function doesn't do anything by default but can be override to save some data during a saveInFile call.
jsonObject | The json object |
bool fge::Scene::saveInFile | ( | std::string const & | path | ) |
Save all the Scene with its Object in a file.
This function save all the data in a json format.
path | The path of the file |
void fge::Scene::setCallbackContext | ( | fge::CallbackContext | context | ) |
Set the callback context of this Scene.
By setting a callback context, the scene will be able to automatically call Object::callbackRegister during object creation.
context | The callback context |
void fge::Scene::setCustomView | ( | std::shared_ptr< fge::View > | customView | ) |
Set a custom shared view.
This is useful if you need to draw a Scene in another place in the screen.
customView | The shared pointer of a view |
void fge::Scene::setLinkedRenderTarget | ( | fge::RenderTarget * | target | ) |
Link a RenderTarget to the Scene.
This is useful for any Object that required an RenderTarget in its method.
target | The RenderTarget (can be nullptr) |
|
inline |
Set the name of the Scene.
name | The new name of the scene |
bool fge::Scene::setObject | ( | fge::ObjectSid | sid, |
fge::ObjectPtr && | newObject ) |
bool fge::Scene::setObjectPlan | ( | fge::ObjectSid | sid, |
fge::ObjectPlan | newPlan ) |
bool fge::Scene::setObjectPlanBot | ( | fge::ObjectSid | sid | ) |
bool fge::Scene::setObjectPlanTop | ( | fge::ObjectSid | sid | ) |
bool fge::Scene::setObjectSid | ( | fge::ObjectSid | sid, |
fge::ObjectSid | newSid ) |
void fge::Scene::signalObject | ( | fge::ObjectSid | sid, |
int8_t | signal ) |
fge::ObjectDataShared fge::Scene::transferObject | ( | fge::ObjectSid | sid, |
fge::Scene & | newScene ) |
Transfer the specified Object to another Scene.
The provided Scene must not have another Object with the same SID, causing the method to failed and return an invalid shared pointer.
Events/methods are called in this order : [Object destroyed from old Scene] _onObjectRemoved called on old Scene _onPlanUpdate called on old Scene [Object is added in new Scene] _onObjectAdded called on new Scene _onPlanUpdate called on new Scene Object::transfered() called
std::optional< fge::net::Error > fge::Scene::unpack | ( | fge::net::Packet const & | pck | ) |
std::optional< fge::net::Error > fge::Scene::unpackModification | ( | fge::net::Packet const & | pck, |
UpdateCountRange & | range ) |
Unpack all modification of received data packet from a server.
This function only extract Scene partial data, for full Scene sync please see pack and unpack.
pck | The network packet |
range | The UpdateCountRange from the server |
std::optional< fge::net::Error > fge::Scene::unpackNeededUpdate | ( | fge::net::Packet const & | pck, |
fge::net::Identity const & | id ) |
Unpack client object that require an explicit update.
This should be called by a server.
pck | The network packet |
id | The Identity of the client |
std::optional< fge::net::Error > fge::Scene::unpackWatchedEvent | ( | fge::net::Packet const & | pck | ) |
Unpack all Scene related events from a server.
pck | The network packet |
void fge::Scene::update | ( | fge::RenderWindow & | screen, |
fge::Event & | event, | ||
std::chrono::microseconds const & | deltaTime, | ||
std::underlying_type_t< UpdateFlags > | flags = UpdateFlags::NONE ) |
Update of the Scene.
This method call the Object::update method of every Object in the scene.
screen | A RenderWindow |
event | The FastEngine Event class |
deltaTime | The time in microseconds between two updates |
flags | Some flags to control the update like the update count |
void fge::Scene::updateAllPlanDepth | ( | ) |
update the ObjectPlanDepth for every objects
This method should not really be used as the depth is automatically calculated inside the draw method.
void fge::Scene::updateAllPlanDepth | ( | fge::ObjectPlan | plan | ) |
update the ObjectPlanDepth for every objects inside the same plan
plan | The plan |
fge::ObjectPlanDepth fge::Scene::updatePlanDepth | ( | fge::ObjectSid | sid | ) |
update the ObjectPlanDepth for one object
sid | The object sid that will be updated |
void fge::Scene::watchEvent | ( | bool | on | ) |
Start to watch Scene related event or not.
When true, the Scene will start to push SceneNetEvent for clients. This is false by default to avoid events overflow.
on | Start or stop watching Scene related events |
fge::net::NetworkTypeHandler fge::Scene::_netList |
The network list must be used to synchronised data between client and server.
|
mutable |
|
mutable |
|
mutable |
|
mutable |
|
mutable |
fge::PropertyList fge::Scene::_properties |
The properties list is a multi-type container for multi-purpose use.