RLLib  0.1
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
rl::Scene Class Reference

The scene represents a world filled with entities that the game engine can run and display. More...

#include <Scene.hpp>

Public Member Functions

 Scene ()=default
 Creates an empty scene.
 
 Scene (const FilePath &path)
 Creates and loads the scene from a file. More...
 
void load (const FilePath &path)
 Loads the scene from a file. More...
 
void save (const FilePath &path) const
 Saves the scene into a file. More...
 
bool hasEntity (const std::string &name) const
 Tells if the scene has an entity with the specified name. More...
 
std::size_t entityCount () const noexcept
 Returns the number of entities in the scene. More...
 
const Entityoperator[] (const std::string &name) const
 Returns the entity (const) associated to the given name. More...
 
Entityoperator[] (const std::string &name)
 Returns the entity associated to the given name. More...
 
const Entityoperator[] (std::size_t index) const
 Returns the entity (const) at the given index. More...
 
Entityoperator[] (std::size_t index)
 Returns the entity at the given index. More...
 
std::vector< Entity >::iterator begin () noexcept
 
std::vector< Entity >::const_iterator cbegin () const noexcept
 
std::vector< Entity >::iterator end () noexcept
 
std::vector< Entity >::const_iterator cend () const noexcept
 

Public Attributes

ByteStream header
 Some unknown properties that might be specific to this scene.
 

Static Public Attributes

static std::function< std::vector< EntityLocation >ByteStream &)> locator
 Function that locates entities using a specific strategy.
 

Detailed Description

The scene represents a world filled with entities that the game engine can run and display.

When the scene is loaded, it uses an algorithm function to locate all the entities. The default algorithm can be replaced by another one by modifying the static variable rl::Scene::locator, which is a callable object. A few algorithms are available in the namespace rl::locator.

Constructor & Destructor Documentation

◆ Scene()

rl::Scene::Scene ( const FilePath path)
explicit

Creates and loads the scene from a file.

Parameters
pathThe path to the scene file

Member Function Documentation

◆ begin()

std::vector<Entity>::iterator rl::Scene::begin ( )
noexcept
Returns
An iterator pointing to the first entity

◆ cbegin()

std::vector<Entity>::const_iterator rl::Scene::cbegin ( ) const
noexcept
Returns
An iterator pointing to the first entity (const)

◆ cend()

std::vector<Entity>::const_iterator rl::Scene::cend ( ) const
noexcept
Returns
An iterator pointing to the last entity (const)

◆ end()

std::vector<Entity>::iterator rl::Scene::end ( )
noexcept
Returns
An iterator pointing to the last entity

◆ entityCount()

std::size_t rl::Scene::entityCount ( ) const
noexcept

Returns the number of entities in the scene.

Returns
The number of entities

◆ hasEntity()

bool rl::Scene::hasEntity ( const std::string &  name) const

Tells if the scene has an entity with the specified name.

Parameters
nameThe name of the entity
Returns
true if such an entity exists, false if not

◆ load()

void rl::Scene::load ( const FilePath path)

Loads the scene from a file.

Parameters
pathThe path to the scene file

◆ operator[]() [1/4]

const Entity& rl::Scene::operator[] ( const std::string &  name) const

Returns the entity (const) associated to the given name.

If there is no such entity, the behavior is undefined.

Note
Entities names don't have to be unique, even though they usually are in practice. If a scene contains multiple entities with the same name, only the first occurrence is returned.
Warning
This function should be used primarily for testing, since entities names are not identifiers and may change during runtime. Consider using iterators (rl::Scene::begin and rl::Scene::end) or the access-by-index operator (rl::Scene::operator[](std::size_t)).
Parameters
nameThe name of the entity
Returns
A reference to the entity (const).

◆ operator[]() [2/4]

Entity& rl::Scene::operator[] ( const std::string &  name)

Returns the entity associated to the given name.

If there is no such entity, the behavior is undefined.

Note
Entities names don't have to be unique, even though they usually are in practice. If a scene contains multiple entities with the same name, only the first occurrence is returned.
Warning
This function should be used primarily for testing, since entities names are not identifiers and may change during runtime. Consider using iterators (rl::Scene::begin and rl::Scene::end) or the access-by-index operator (rl::Scene::operator[](std::size_t)).
Parameters
nameThe name of the entity
Returns
A reference to the entity

◆ operator[]() [3/4]

const Entity& rl::Scene::operator[] ( std::size_t  index) const

Returns the entity (const) at the given index.

If the index is out of bound, the behavior is undefined.

Parameters
indexThe entity index
Returns
A reference to the entity (const)

◆ operator[]() [4/4]

Entity& rl::Scene::operator[] ( std::size_t  index)

Returns the entity at the given index.

If the index is out of bound, the behavior is undefined.

Parameters
indexThe entity index
Returns
A reference to the entity

◆ save()

void rl::Scene::save ( const FilePath path) const

Saves the scene into a file.

Warning
If the file already exists, the original content of the file will be lost.
Parameters
pathThe path to the scene file

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