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

A scene contain a collection of object and handle them. More...

#include <C_scene.hpp>

Inheritance diagram for fge::Scene:
fge::CommandHandler

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
 
Sceneoperator= (Scene const &r)
 
Sceneoperator= (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 &parameters, 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::ObjectgetObjectPtr (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::Errorunpack (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::ErrorunpackModification (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::ErrorunpackNeededUpdate (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::ErrorunpackWatchedEvent (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::RenderTargetgetLinkedRenderTarget ()
 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.
 

Detailed Description

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.

See also
ObjectData

Member Function Documentation

◆ addCmd()

bool fge::CommandHandler::addCmd ( std::string_view name,
fge::CommandHandler * handle,
fge::CommandFunction cmdfunc )
inherited

Add a new command to the handler.

An object should inherit from CommandHandler and add commands to it.

Parameters
nameThe name of the command
handleThe object that will handle the command
cmdfuncThe function pointer of the command
Returns
true if the command was added, false otherwise

◆ callCmd() [1/2]

fge::Property fge::CommandHandler::callCmd ( std::size_t index,
fge::Object * caller,
fge::Property const & arg,
fge::Scene * caller_scene )
inherited

Call a command by its index.

Parameters
indexThe index of the command
callerThe object that call the command
argThe arguments of the command
caller_sceneThe scene that contains the caller
Returns
A Property containing the result of the command

◆ callCmd() [2/2]

fge::Property fge::CommandHandler::callCmd ( std::string_view name,
fge::Object * caller,
fge::Property const & arg,
fge::Scene * caller_scene )
inherited

Call a command by its name.

Parameters
nameThe name of the command
callerThe object that call the command
argThe arguments of the command
caller_sceneThe scene that contains the caller
Returns
A Property containing the result of the command

◆ clear()

void fge::Scene::clear ( )

Clear the Scene.

This method call :

  • delAllObject including GUI Object type.
  • PropertyList::delAllProperties.
  • fge::net::NetworkTypeContainer::clear.

◆ clearCmd()

void fge::CommandHandler::clearCmd ( )
inherited

Clear all commands from the handler.

◆ clearNetEventsQueue() [1/2]

void fge::Scene::clearNetEventsQueue ( )

Clear Scene network events queue for all clients.

◆ clearNetEventsQueue() [2/2]

void fge::Scene::clearNetEventsQueue ( fge::net::Identity const & id)

Clear Scene network events queue for the specified client.

Parameters
idA client net::Identity

◆ clearPerClientSyncData()

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.

◆ clientsCheckup()

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.

See also
net::NetworkTypeBase::clientsCheckup
Parameters
clientsThe net::ClientList attributed to this Scene
forceIf true, all per clients data will clear and redo a full checkup

◆ delAllObject()

std::size_t fge::Scene::delAllObject ( bool ignoreGuiObject)

Delete every Object in the Scene.

Parameters
ignoreGuiObjectIf true, every GUI type Object is not deleted by this method
Returns
The number of deleted Object

◆ delCmd()

void fge::CommandHandler::delCmd ( std::string_view name)
inherited

Delete a command from the handler.

Parameters
nameThe name of the command

◆ delCustomView()

void fge::Scene::delCustomView ( )

Remove the actual custom view.

See also
setCustomView

◆ delObject()

bool fge::Scene::delObject ( fge::ObjectSid sid)

Delete the Object provided with his SID.

Warning
This method should not be called in the updated Object for deleting itself
See also
delUpdatedObject
Parameters
sidThe SID of the Object to be deleted
Returns
true if the Object is correctly deleted or false if the Object is not found

◆ delUpdatedObject()

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.

Warning
This method is not meant to be used outside an update and will cause weird behaviour if not respected. (like deleting the first updated Object)
See also
update

◆ draw()

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.

See also
Object::getGlobalBounds

During the draw, the depth plan is re-assigned depending on the Object plan and position in the list.

See also
ObjectData::getPlanDepth
Parameters
targetA RenderTarget
statesThe default RenderStates to be used for every drawn Object

◆ duplicateObject()

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.

Parameters
sidThe SID of the Object to be duplicated
newSidThe new SID of the duplicated Object
Returns
A shared pointer of the new ObjectData

◆ find() [1/2]

fge::ObjectContainer::const_iterator fge::Scene::find ( fge::Object const * ptr) const

Find an Object with the specified Object pointer.

Parameters
ptrThe Object pointer
Returns
An constant iterator representing the ObjectData

◆ find() [2/2]

fge::ObjectContainer::const_iterator fge::Scene::find ( fge::ObjectSid sid) const

Find an Object with the specified SID.

Parameters
sidThe Object SID
Returns
An constant iterator representing the ObjectData

◆ findPlan()

fge::ObjectContainer::const_iterator fge::Scene::findPlan ( fge::ObjectPlan plan) const

Find an Object with the specified plan.

Parameters
planThe Object plan
Returns
An constant iterator representing the ObjectData

◆ forceCheckClient()

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

Parameters
idThe client net::Identity

◆ forceUncheckClient()

void fge::Scene::forceUncheckClient ( fge::net::Identity const & id)

Force every network type modification flag to be false for a specified client net::Identity.

See also
forceCheckClient
Parameters
idThe client net::Identity

◆ generateSid()

virtual fge::ObjectSid fge::Scene::generateSid ( fge::ObjectSid wanted_sid,
fge::ObjectType type ) const
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.

Parameters
wanted_sidThe wanted SID
typeThe type of the Object
Returns
The SID generated

◆ getAllObj_ByClass()

std::size_t fge::Scene::getAllObj_ByClass ( std::string_view class_name,
fge::ObjectContainer & buff ) const

Get all Object with the same class name.

See also
Object::getClassName
Warning
This function do not clear data in the ObjectContainer.
Parameters
class_nameThe wanted class name
buffAn ObjectContainer that will receive results
Returns
The number of Objects added in the container

◆ getAllObj_ByLocalPosition()

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.

See also
setCustomView
Warning
This function do not clear data in the ObjectContainer.
Parameters
posThe local position
targetAn RenderTarget
buffAn ObjectContainer that will receive results
Returns
The number of Objects added in the container

◆ getAllObj_ByLocalZone()

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).

Warning
This function do not clear data in the ObjectContainer.
Parameters
zoneThe local zone
targetAn RenderTarget
buffAn ObjectContainer that will receive results
Returns
The number of Objects added in the container

◆ getAllObj_ByPosition()

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.

Warning
This function do not clear data in the ObjectContainer.
Parameters
posThe position
buffAn ObjectContainer that will receive results
Returns
The number of Objects added in the container

◆ getAllObj_ByTag()

std::size_t fge::Scene::getAllObj_ByTag ( std::string_view tag_name,
fge::ObjectContainer & buff ) const

Get all Object that contain the provided tag.

See also
TagList
Warning
This function do not clear data in the ObjectContainer.
Parameters
tag_nameThe wanted tag
buffAn ObjectContainer that will receive results
Returns
The number of Objects added in the container

◆ getAllObj_ByZone()

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).

Warning
This function do not clear data in the ObjectContainer.
Parameters
zoneThe zone
buffAn ObjectContainer that will receive results
Returns
The number of Objects added in the container

◆ getAllObj_FromLocalPosition()

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.

See also
setCustomView getAllObj_ByLocalPosition
Warning
This function do not clear data in the ObjectContainer.
Parameters
posThe local position
targetAn RenderTarget
buffAn ObjectContainer that will receive results
Returns
The number of Objects added in the container

◆ getAllObj_FromLocalZone()

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.

See also
setCustomView getAllObj_ByLocalZone
Warning
This function do not clear data in the ObjectContainer.
Parameters
zoneThe local zone
targetAn RenderTarget
buffAn ObjectContainer that will receive results
Returns
The number of Objects added in the container

◆ getCallbackContext()

fge::CallbackContext fge::Scene::getCallbackContext ( ) const

Get the callback context of this Scene.

See also
setCallbackContext
Returns
The callback context

◆ getCmd()

fge::CommandHandler::CommandData const * fge::CommandHandler::getCmd ( std::string_view name) const
nodiscardinherited

Get a command by its name.

Parameters
nameThe name of the command
Returns
The command or nullptr if the command doesn't exist

◆ getCmdIndex()

std::size_t fge::CommandHandler::getCmdIndex ( std::string_view name) const
nodiscardinherited

Get the index of a command by its name.

Parameters
nameThe name of the command
Returns
The index of the command or std::numeric_limits<std::size_t>::max() if the command doesn't exist

◆ getCmdList()

fge::CommandHandler::CommandDataType const & fge::CommandHandler::getCmdList ( ) const
nodiscardinherited

Get the commands list.

Returns
The commands list

◆ getCmdName()

std::string_view fge::CommandHandler::getCmdName ( std::size_t index) const
nodiscardinherited

Get the name of a command by its index.

Parameters
indexThe index of the command
Returns
The name of the command or an empty string if the command doesn't exist

◆ getCmdSize()

std::size_t fge::CommandHandler::getCmdSize ( ) const
nodiscardinherited

Get the number of commands.

Returns
The number of commands

◆ getCustomView()

std::shared_ptr< fge::View > const & fge::Scene::getCustomView ( ) const

Get the custom shared view if there is one.

See also
setCustomView
Returns
The shared point of the view

◆ getFirstObj_ByClass()

fge::ObjectDataShared fge::Scene::getFirstObj_ByClass ( std::string_view class_name) const

Get the first Object that match a provided class name.

See also
getAllObj_ByClass
Parameters
class_nameThe class name
Returns
The first Object that match the argument

◆ getFirstObj_ByLocalPosition()

fge::ObjectDataShared fge::Scene::getFirstObj_ByLocalPosition ( fge::Vector2i const & pos,
fge::RenderTarget const & target ) const

Get the first Object with a local position.

See also
getAllObj_ByLocalPosition
Parameters
posThe local position
targetThe RenderTarget
Returns
The first Object that match the argument

◆ getFirstObj_ByLocalZone()

fge::ObjectDataShared fge::Scene::getFirstObj_ByLocalZone ( fge::RectInt const & zone,
fge::RenderTarget const & target ) const

Get the first Object within a local zone.

See also
getAllObj_ByLocalZone
Parameters
zoneThe local zone
targetThe RenderTarget
Returns
The first Object that match the argument

◆ getFirstObj_ByPosition()

fge::ObjectDataShared fge::Scene::getFirstObj_ByPosition ( fge::Vector2f const & pos) const

Get the first Object with a position.

See also
getAllObj_ByPosition
Parameters
posThe position
Returns
The first Object that match the argument

◆ getFirstObj_ByTag()

fge::ObjectDataShared fge::Scene::getFirstObj_ByTag ( std::string_view tag_name) const

Get the first Object that match a provided tag.

See also
getAllObj_ByTag
Parameters
tag_nameThe tag
Returns
The first Object that match the argument

◆ getFirstObj_ByZone()

fge::ObjectDataShared fge::Scene::getFirstObj_ByZone ( fge::RectFloat const & zone) const

Get the first Object within a zone.

See also
getAllObj_ByZone
Parameters
zoneThe zone
Returns
The first Object that match the argument

◆ getFirstObj_FromLocalPosition()

fge::ObjectDataShared fge::Scene::getFirstObj_FromLocalPosition ( fge::Vector2i const & pos,
fge::RenderTarget const & target ) const

Get the first Object with a local position position.

See also
getAllObj_FromLocalPosition
Parameters
posThe position
targetThe RenderTarget
Returns
The first Object that match the argument

◆ getFirstObj_FromLocalZone()

fge::ObjectDataShared fge::Scene::getFirstObj_FromLocalZone ( fge::RectInt const & zone,
fge::RenderTarget const & target ) const

Get the first Object within a local zone.

See also
getAllObj_FromLocalZone
Parameters
zoneThe local zone
targetThe RenderTarget
Returns
The first Object that match the argument

◆ getLinkedRenderTarget() [1/2]

fge::RenderTarget * fge::Scene::getLinkedRenderTarget ( )

Get the RenderTarget linked to this Scene (non-const).

See also
setLinkedRenderTarget
Returns
The linked RenderTarget or nullptr if there is none

◆ getLinkedRenderTarget() [2/2]

fge::RenderTarget const * fge::Scene::getLinkedRenderTarget ( ) const

Get the RenderTarget linked to this Scene.

See also
setLinkedRenderTarget
Returns
The linked RenderTarget or nullptr if there is none

◆ getName()

std::string const & fge::Scene::getName ( ) const
inline

Get the name of the Scene.

Returns
the name of the Scene

◆ getObject() [1/2]

fge::ObjectDataShared fge::Scene::getObject ( fge::Object const * ptr) const

Get an Object with his pointer.

Parameters
ptrActual pointer of the wanted Object
Returns
The shared ObjectData pointer

◆ getObject() [2/2]

fge::ObjectDataShared fge::Scene::getObject ( fge::ObjectSid sid) const

Get an Object with his SID.

Parameters
sidActual SID of the wanted Object
Returns
The shared ObjectData pointer

◆ getObjectPtr()

fge::Object * fge::Scene::getObjectPtr ( fge::ObjectSid sid) const

Get an Object pointer with his SID.

Parameters
sidActual SID of the wanted Object
Returns
The Object pointer

◆ getObjectSize()

std::size_t fge::Scene::getObjectSize ( ) const
inline

Get total Object stored in this Scene.

Returns
The size of the Scene.

◆ getRelatedView()

fge::View const * fge::Scene::getRelatedView ( ) const
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.

Returns
The related view pointer or nullptr if there is none

◆ getSid()

fge::ObjectSid fge::Scene::getSid ( fge::Object const * ptr) const

Get the SID of the provided Object pointer.

Parameters
ptrThe Object pointer
Returns
FGE_SCENE_BAD_SID if there is no match, the Object SID otherwise

◆ getUpdateCount()

uint16_t fge::Scene::getUpdateCount ( ) 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.

Returns
The number of update

◆ getUpdatedObject()

fge::ObjectDataShared fge::Scene::getUpdatedObject ( ) const

Get the actual updated Object.

Returns
The shared ObjectData pointer

◆ isValid()

bool fge::Scene::isValid ( fge::ObjectSid sid) const
inline

Check if the SID correspond to an Object in this Scene.

Parameters
sidThe Object SID
Returns
true if the SID correspond

◆ isWatchingEvent()

bool fge::Scene::isWatchingEvent ( ) const

Check if the Scene is currently watching events. ".

See also
watchEvent
Returns
Watch Scene events stats

◆ loadCustomData()

virtual void fge::Scene::loadCustomData ( nlohmann::json & jsonObject)
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.

See also
loadFromFile
Parameters
jsonObjectThe json object

◆ loadFromFile()

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.

Warning
This function clear everything in the Scene before the file loading.
See also
saveInFile
Parameters
pathThe path of the file
Returns
true if successful, false otherwise

◆ newObject() [1/2]

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.

Warning
The provided ObjectData must have a valid Object pointer.

If the object is created inside the update() method from a second object, the second object become parent.

Parameters
objectDataThe shared ObjectData
silentIf true, the Scene will not call the Object::first or Object::callbackRegister methods
Returns
A shared pointer of the ObjectData

◆ newObject() [2/2]

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.

Warning
The provided pointer of the Object, have to be allocated in the heap and must not be handled by the user.
If there is an error during the addition of the new Object, the returned shared pointer is not valid and the provided Object is dismissed.

If the object is created inside the update() method from a second object, the second object become parent.

Parameters
newObjectThe object pointer allocated by the user
planThe plan of the new object
sidThe wanted SID
typeThe type of the new Object
silentIf true, the Scene will not call the Object::first or Object::callbackRegister methods
Returns
A shared pointer of the ObjectData

◆ pack() [1/2]

void fge::Scene::pack ( fge::net::Packet & pck)

Pack all the Scene data in a Packet.

This function is useful to do a full Scene synchronisation in a network from a server.

Warning
The maximum Object that can be packed is fge::net::SizeType.
Parameters
pckThe network packet

◆ pack() [2/2]

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.

Parameters
pckThe network packet
idThe Identity of the client

◆ packModification()

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.

See also
clientsCheckup
Warning
The maximum Object that can be packed is fge::net::SizeType.
Parameters
pckThe network packet
idThe Identity of the client

◆ packNeededUpdate()

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.

See also
NetworkTypeContainer::packNeededUpdate
Parameters
pckThe network packet

◆ packWatchedEvent()

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.

Parameters
pckThe network packet
idThe client net::Identity

◆ pushEvent() [1/2]

void fge::Scene::pushEvent ( fge::SceneNetEvent const & netEvent)

Manually push a Scene related event for every clients.

Parameters
netEventThe SceneNetEvent

◆ pushEvent() [2/2]

bool fge::Scene::pushEvent ( fge::SceneNetEvent const & netEvent,
fge::net::Identity const & id )

Manually push a Scene related event for a specified client.

Parameters
netEventThe SceneNetEvent
idA client net::Identity

◆ replaceCmd()

bool fge::CommandHandler::replaceCmd ( std::string_view name,
fge::CommandHandler * handle,
fge::CommandFunction cmdfunc )
inherited

Replace a command from the handler.

Parameters
nameThe name of the command
handleThe new object that will handle the command
cmdfuncThe new function pointer of the command
Returns
true if the command was replaced, false otherwise

◆ saveCustomData()

virtual void fge::Scene::saveCustomData ( nlohmann::json & jsonObject)
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.

See also
saveInFile
Parameters
jsonObjectThe json object

◆ saveInFile()

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.

See also
loadFromFile
Parameters
pathThe path of the file
Returns
true if successful, false otherwise

◆ setCallbackContext()

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.

Parameters
contextThe callback context

◆ setCustomView()

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.

Parameters
customViewThe shared pointer of a view

◆ setLinkedRenderTarget()

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.

Parameters
targetThe RenderTarget (can be nullptr)

◆ setName()

void fge::Scene::setName ( std::string name)
inline

Set the name of the Scene.

Parameters
nameThe new name of the scene

◆ setObject()

bool fge::Scene::setObject ( fge::ObjectSid sid,
fge::ObjectPtr && newObject )

Set a new Object pointer in place of the provided one.

Warning
The provided pointer must respect the same rule as a newly created object with the newObject() method
Parameters
sidActual SID of the Object
newObjectThe new Object pointer
Returns
true if the change is successful

◆ setObjectPlan()

bool fge::Scene::setObjectPlan ( fge::ObjectSid sid,
fge::ObjectPlan newPlan )

Set a new Object plan.

Parameters
sidActual SID of the Object
newPlanThe new plan
Returns
true if the change is successful

◆ setObjectPlanBot()

bool fge::Scene::setObjectPlanBot ( fge::ObjectSid sid)

Set an Object in the bottom of his plan.

This make the object be drawn last.

Parameters
sidActual SID of the Object
Returns
true if the change is successful

◆ setObjectPlanTop()

bool fge::Scene::setObjectPlanTop ( fge::ObjectSid sid)

Set an Object on top of his plan.

This make the object be drawn first.

Parameters
sidActual SID of the Object
Returns
true if the change is successful

◆ setObjectSid()

bool fge::Scene::setObjectSid ( fge::ObjectSid sid,
fge::ObjectSid newSid )

Set the Object with a new SID.

If the new SID is FGE_SCENE_BAD_SID, the method return false.

Parameters
sidActual SID of the Object
newSidThe new SID of the Object
Returns
true if the change is successful

◆ signalObject()

void fge::Scene::signalObject ( fge::ObjectSid sid,
int8_t signal )

Signal an Object over the network.

Parameters
sidThe SID of the Object
signalThe signal to send

◆ transferObject()

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

Warning
This method is not meant to be used on the same Scene, however it will work as expected.
Parameters
sidThe SID of the Object to be transferred
newSceneThe Scene that will get the Object
Returns
A shared pointer of the transferred Object from the new scene

◆ unpack()

std::optional< fge::net::Error > fge::Scene::unpack ( fge::net::Packet const & pck)

Unpack all the received data of a serverside Scene.

This function delete every actual Object in the Scene except GUI Object.

See also
pack
Parameters
pckThe network packet

◆ unpackModification()

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.

See also
packModification
Parameters
pckThe network packet
rangeThe UpdateCountRange from the server

◆ unpackNeededUpdate()

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.

See also
NetworkTypeContainer::packNeededUpdate
Parameters
pckThe network packet
idThe Identity of the client

◆ unpackWatchedEvent()

std::optional< fge::net::Error > fge::Scene::unpackWatchedEvent ( fge::net::Packet const & pck)

Unpack all Scene related events from a server.

Parameters
pckThe network packet

◆ update()

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.

Warning
If the updated Object want to delete itself during an update, it have to use the delUpdatedObject and not any others delete methode that will cause undefined behaviour.
Parameters
screenA RenderWindow
eventThe FastEngine Event class
deltaTimeThe time in microseconds between two updates
flagsSome flags to control the update like the update count

◆ updateAllPlanDepth() [1/2]

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.

◆ updateAllPlanDepth() [2/2]

void fge::Scene::updateAllPlanDepth ( fge::ObjectPlan plan)

update the ObjectPlanDepth for every objects inside the same plan

Parameters
planThe plan

◆ updatePlanDepth()

fge::ObjectPlanDepth fge::Scene::updatePlanDepth ( fge::ObjectSid sid)

update the ObjectPlanDepth for one object

Parameters
sidThe object sid that will be updated
Returns
The new ObjectPlanDepth

◆ watchEvent()

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.

Warning
SceneNetEvent have to be cleared manually by the user with deleteEvents.
Parameters
onStart or stop watching Scene related events

Member Data Documentation

◆ _netList

fge::net::NetworkTypeHandler fge::Scene::_netList

The network list must be used to synchronised data between client and server.

◆ _onDelayedUpdate

fge::CallbackHandler<fge::Scene&> fge::Scene::_onDelayedUpdate
mutable

Event called only once after a Scene update.

You or an Object can register a one time callback that will be called after updating the Scene. Once called, callbacks is cleared.

◆ _onDraw

fge::CallbackHandler<fge::Scene const&, fge::RenderTarget&> fge::Scene::_onDraw
mutable

Event called when the Scene is about to be drawn.

◆ _onObjectAdded

fge::CallbackHandler<fge::Scene&, fge::ObjectDataShared const&> fge::Scene::_onObjectAdded
mutable

Event called when a new Object has been added.

◆ _onObjectRemoved

fge::CallbackHandler<fge::Scene&, fge::ObjectDataShared const&> fge::Scene::_onObjectRemoved
mutable

Event called when an Object has been removed.

◆ _onPlanUpdate

fge::CallbackHandler<fge::Scene&, fge::ObjectPlan> fge::Scene::_onPlanUpdate
mutable

Event called when a change in the plan is detected.

When an Object change his plan, is created, is deleted ... this event is called. The ObjectPlan argument can be FGE_SCENE_BAD_PLAN, this mean that all plans have been impacted.

◆ _properties

fge::PropertyList fge::Scene::_properties

The properties list is a multi-type container for multi-purpose use.


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