FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
FIFE::Model Class Reference

A model is a facade for everything in the model. More...

#include <model.h>

+ Inheritance diagram for FIFE::Model:
+ Collaboration diagram for FIFE::Model:

Public Member Functions

 Model (RenderBackend *renderbackend, const std::vector< RendererBase *> &renderers)
 Constructor. More...
 
 ~Model ()
 Destructor. More...
 
MapcreateMap (const std::string &identifier)
 Add a map this model, and get a pointer to it. More...
 
void deleteMap (Map *)
 Remove a map from this model. More...
 
const std::list< Map * > & getMaps () const
 Get all the maps in the model. More...
 
MapgetMap (const std::string &identifier) const
 Get a map. More...
 
uint32_t getMapCount () const
 Return the number of maps in this model. More...
 
void deleteMaps ()
 Removes all maps from this model. More...
 
uint32_t getActiveCameraCount () const
 Return the number of enabled cameras in this model. More...
 
std::list< std::string > getNamespaces () const
 Get a list of namespaces currently referenced by objects in the metamodel. More...
 
ObjectcreateObject (const std::string &identifier, const std::string &name_space, Object *parent=0)
 Add an object to the metamodel. More...
 
bool deleteObject (Object *)
 Attempt to remove an object from the model Fails and returns false if the object is referenced by an instance. More...
 
bool deleteObjects ()
 Attempt to remove all objects from the model Fails and returns false if any maps with instances are present. More...
 
ObjectgetObject (const std::string &id, const std::string &name_space)
 Get an object by its id. More...
 
std::list< Object * > getObjects (const std::string &name_space) const
 Get all the objects in the given namespace. More...
 
void adoptPather (IPather *pather)
 Adds pather to model. More...
 
IPathergetPather (const std::string &pathername)
 Returns pather corresponding given name. More...
 
void adoptCellGrid (CellGrid *grid)
 Adds cellgrid to model. More...
 
CellGridgetCellGrid (const std::string &gridtype)
 Returns new copy of cellgrid corresponding given name. More...
 
void removeCellGrid (CellGrid *grid)
 Removes cellgrid from model. More...
 
void update ()
 Called periodically to update events on model. More...
 
void setTimeMultiplier (float multip)
 Sets speed for the model. More...
 
double getTimeMultiplier () const
 Gets model speed. More...
 
- Public Member Functions inherited from FIFE::FifeClass
 FifeClass ()
 
virtual ~FifeClass ()
 
fifeid_t getFifeId ()
 Gets unique id of this instance inside the engine. More...
 

Private Types

typedef std::map< std::string, Object * > objectmap_t
 
typedef std::pair< std::string, objectmap_tnamespace_t
 

Private Member Functions

namespace_tselectNamespace (const std::string &name_space)
 Convenience function to retrieve a pointer to a namespace or NULL if it doesn't exist. More...
 
const namespace_tselectNamespace (const std::string &name_space) const
 Convenience function to retrieve a pointer to a namespace or NULL if it doesn't exist. More...
 

Private Attributes

ModelMapObserverm_mapObserver
 
std::list< Map * > m_maps
 
std::list< namespace_tm_namespaces
 
namespace_tm_lastNamespace
 Used to remember last 'selected' namespace. More...
 
std::vector< IPather * > m_pathers
 
std::vector< CellGrid * > m_createdGrids
 
std::vector< CellGrid * > m_adoptedGrids
 
TimeProvider m_timeprovider
 
RenderBackendm_renderbackend
 
std::vector< RendererBase * > m_renderers
 

Detailed Description

A model is a facade for everything in the model.

Definition at line 54 of file model.h.

Member Typedef Documentation

◆ namespace_t

typedef std::pair<std::string,objectmap_t> FIFE::Model::namespace_t
private

Definition at line 170 of file model.h.

◆ objectmap_t

typedef std::map<std::string,Object*> FIFE::Model::objectmap_t
private

Definition at line 169 of file model.h.

Constructor & Destructor Documentation

◆ Model()

FIFE::Model::Model ( RenderBackend renderbackend,
const std::vector< RendererBase *> &  renderers 
)

Constructor.

Definition at line 68 of file model.cpp.

References m_mapObserver.

◆ ~Model()

FIFE::Model::~Model ( )

Destructor.

Definition at line 78 of file model.cpp.

References m_adoptedGrids, m_createdGrids, m_mapObserver, m_maps, m_namespaces, m_pathers, purge(), and purge_map().

Member Function Documentation

◆ adoptCellGrid()

void FIFE::Model::adoptCellGrid ( CellGrid grid)

Adds cellgrid to model.

Moves ownership to model

Definition at line 122 of file model.cpp.

References m_adoptedGrids.

Referenced by getMaps(), and FIFE::Engine::init().

+ Here is the caller graph for this function:

◆ adoptPather()

void FIFE::Model::adoptPather ( IPather pather)

Adds pather to model.

Moves ownership to model

Definition at line 107 of file model.cpp.

References m_pathers.

Referenced by getMaps(), and FIFE::Engine::init().

+ Here is the caller graph for this function:

◆ createMap()

Map * FIFE::Model::createMap ( const std::string &  identifier)

Add a map this model, and get a pointer to it.

The returned pointer is owned by the Model, so don't delete it!

Definition at line 93 of file model.cpp.

References FIFE::Map::addChangeListener(), m_mapObserver, m_maps, m_renderbackend, m_renderers, and m_timeprovider.

Referenced by FIFE::MapLoader::load().

+ Here is the caller graph for this function:

◆ createObject()

Object * FIFE::Model::createObject ( const std::string &  identifier,
const std::string &  name_space,
Object parent = 0 
)

Add an object to the metamodel.

Parameters
identifierA string for identifying this object; must be unique for its namespace.
name_spaceA string identifying the namespace this object resides in.
parentObjects may optionally inherit values from a parent object.
Note
This object belongs to the model, so don't delete the returned pointer

Definition at line 205 of file model.cpp.

References m_namespaces, and selectNamespace().

Referenced by getMaps(), and FIFE::ObjectLoader::load().

+ Here is the caller graph for this function:

◆ deleteMap()

void FIFE::Model::deleteMap ( Map map)

Remove a map from this model.

Definition at line 161 of file model.cpp.

References m_maps.

◆ deleteMaps()

void FIFE::Model::deleteMaps ( )

Removes all maps from this model.

Definition at line 176 of file model.cpp.

References m_createdGrids, m_mapObserver, m_maps, and purge().

Referenced by getMaps().

+ Here is the caller graph for this function:

◆ deleteObject()

bool FIFE::Model::deleteObject ( Object object)

Attempt to remove an object from the model Fails and returns false if the object is referenced by an instance.

Definition at line 225 of file model.cpp.

References FIFE::Object::getId(), FIFE::Object::getNamespace(), m_maps, and selectNamespace().

Referenced by getMaps().

+ Here is the caller graph for this function:

◆ deleteObjects()

bool FIFE::Model::deleteObjects ( )

Attempt to remove all objects from the model Fails and returns false if any maps with instances are present.

Definition at line 257 of file model.cpp.

References m_lastNamespace, m_maps, and m_namespaces.

Referenced by getMaps().

+ Here is the caller graph for this function:

◆ getActiveCameraCount()

uint32_t FIFE::Model::getActiveCameraCount ( ) const

Return the number of enabled cameras in this model.

Definition at line 187 of file model.cpp.

References m_maps.

Referenced by getMaps(), and FIFE::Engine::pump().

+ Here is the caller graph for this function:

◆ getCellGrid()

CellGrid * FIFE::Model::getCellGrid ( const std::string &  gridtype)

Returns new copy of cellgrid corresponding given name.

If none found, returns NULL

Definition at line 126 of file model.cpp.

References FIFE::_log, FIFE::CellGrid::clone(), FL_WARN, m_adoptedGrids, and m_createdGrids.

Referenced by getMaps(), and FIFE::MapLoader::load().

+ Here is the caller graph for this function:

◆ getMap()

Map * FIFE::Model::getMap ( const std::string &  identifier) const

Get a map.

Parameters
identifierthe id of the map to be found.

Definition at line 151 of file model.cpp.

References m_maps.

Referenced by getMaps().

+ Here is the caller graph for this function:

◆ getMapCount()

uint32_t FIFE::Model::getMapCount ( ) const

Return the number of maps in this model.

Definition at line 172 of file model.cpp.

References m_maps.

Referenced by getMaps().

+ Here is the caller graph for this function:

◆ getMaps()

const std::list<Map*>& FIFE::Model::getMaps ( ) const
inline

◆ getNamespaces()

std::list< std::string > FIFE::Model::getNamespaces ( ) const

Get a list of namespaces currently referenced by objects in the metamodel.

Definition at line 196 of file model.cpp.

References m_namespaces.

Referenced by getMaps(), and FIFE::MapLoader::load().

+ Here is the caller graph for this function:

◆ getObject()

Object * FIFE::Model::getObject ( const std::string &  id,
const std::string &  name_space 
)

Get an object by its id.

Returns 0 if object is not found.

Definition at line 280 of file model.cpp.

References selectNamespace().

Referenced by getMaps(), FIFE::ObjectLoader::load(), and FIFE::MapLoader::load().

+ Here is the caller graph for this function:

◆ getObjects()

std::list< Object * > FIFE::Model::getObjects ( const std::string &  name_space) const

Get all the objects in the given namespace.

Definition at line 290 of file model.cpp.

References selectNamespace().

Referenced by getMaps(), and FIFE::MapLoader::load().

+ Here is the caller graph for this function:

◆ getPather()

IPather * FIFE::Model::getPather ( const std::string &  pathername)

Returns pather corresponding given name.

If none found, returns NULL

Definition at line 111 of file model.cpp.

References FIFE::_log, FL_WARN, and m_pathers.

Referenced by getMaps(), and FIFE::ObjectLoader::load().

+ Here is the caller graph for this function:

◆ getTimeMultiplier()

double FIFE::Model::getTimeMultiplier ( ) const
inline

Gets model speed.

See also
setTimeMultiplier.

Definition at line 161 of file model.h.

References FIFE::TimeProvider::getMultiplier(), and m_timeprovider.

◆ removeCellGrid()

void FIFE::Model::removeCellGrid ( CellGrid grid)

Removes cellgrid from model.

Definition at line 139 of file model.cpp.

References m_createdGrids.

Referenced by getMaps(), and FIFE::ModelMapObserver::onLayerDelete().

+ Here is the caller graph for this function:

◆ selectNamespace() [1/2]

Model::namespace_t * FIFE::Model::selectNamespace ( const std::string &  name_space)
private

Convenience function to retrieve a pointer to a namespace or NULL if it doesn't exist.

Definition at line 313 of file model.cpp.

References m_lastNamespace, and m_namespaces.

Referenced by createObject(), deleteObject(), getObject(), and getObjects().

+ Here is the caller graph for this function:

◆ selectNamespace() [2/2]

const Model::namespace_t * FIFE::Model::selectNamespace ( const std::string &  name_space) const
private

Convenience function to retrieve a pointer to a namespace or NULL if it doesn't exist.

Definition at line 302 of file model.cpp.

References m_namespaces.

◆ setTimeMultiplier()

void FIFE::Model::setTimeMultiplier ( float  multip)
inline

Sets speed for the model.

With speed 1.0, everything runs with normal speed. With speed 2.0, clock is ticking twice as fast. With 0, everything gets paused. Negavtive values are not supported (throws NotSupported exception).

Definition at line 157 of file model.h.

References m_timeprovider, and FIFE::TimeProvider::setMultiplier().

◆ update()

void FIFE::Model::update ( )

Called periodically to update events on model.

Definition at line 327 of file model.cpp.

References m_maps, and m_pathers.

Referenced by getMaps(), and FIFE::Engine::pump().

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_adoptedGrids

std::vector<CellGrid*> FIFE::Model::m_adoptedGrids
private

Definition at line 184 of file model.h.

Referenced by adoptCellGrid(), getCellGrid(), and ~Model().

◆ m_createdGrids

std::vector<CellGrid*> FIFE::Model::m_createdGrids
private

Definition at line 183 of file model.h.

Referenced by deleteMaps(), getCellGrid(), removeCellGrid(), and ~Model().

◆ m_lastNamespace

namespace_t* FIFE::Model::m_lastNamespace
private

Used to remember last 'selected' namespace.

Definition at line 174 of file model.h.

Referenced by deleteObjects(), and selectNamespace().

◆ m_mapObserver

ModelMapObserver* FIFE::Model::m_mapObserver
private

Definition at line 165 of file model.h.

Referenced by createMap(), deleteMaps(), Model(), and ~Model().

◆ m_maps

std::list<Map*> FIFE::Model::m_maps
private

◆ m_namespaces

std::list<namespace_t> FIFE::Model::m_namespaces
private

Definition at line 171 of file model.h.

Referenced by createObject(), deleteObjects(), getNamespaces(), selectNamespace(), and ~Model().

◆ m_pathers

std::vector<IPather*> FIFE::Model::m_pathers
private

Definition at line 182 of file model.h.

Referenced by adoptPather(), getPather(), update(), and ~Model().

◆ m_renderbackend

RenderBackend* FIFE::Model::m_renderbackend
private

Definition at line 188 of file model.h.

Referenced by createMap().

◆ m_renderers

std::vector<RendererBase*> FIFE::Model::m_renderers
private

Definition at line 190 of file model.h.

Referenced by createMap().

◆ m_timeprovider

TimeProvider FIFE::Model::m_timeprovider
private

Definition at line 186 of file model.h.

Referenced by createMap(), getTimeMultiplier(), and setTimeMultiplier().


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