FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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...
 
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 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_t
namespace_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

std::list< Map * > m_maps
 
std::list< namespace_tm_namespaces
 
namespace_tm_last_namespace
 Used to remember last 'selected' namespace. More...
 
std::vector< IPather * > m_pathers
 
std::vector< CellGrid * > m_created_grids
 
std::vector< CellGrid * > m_adopted_grids
 
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 53 of file model.h.

Member Typedef Documentation

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

Definition at line 159 of file model.h.

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

Definition at line 158 of file model.h.

Constructor & Destructor Documentation

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

Constructor.

Definition at line 47 of file model.cpp.

FIFE::Model::~Model ( )

Destructor.

Definition at line 55 of file model.cpp.

References m_adopted_grids, m_created_grids, m_maps, m_namespaces, m_pathers, purge(), and purge_map().

Member Function Documentation

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

Adds cellgrid to model.

Moves ownership to model

Definition at line 92 of file model.cpp.

References m_adopted_grids.

Referenced by FIFE::Engine::init().

+ Here is the caller graph for this function:

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

Adds pather to model.

Moves ownership to model

Definition at line 77 of file model.cpp.

References m_pathers.

Referenced by FIFE::Engine::init().

+ Here is the caller graph for this function:

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 64 of file model.cpp.

References m_maps, m_renderbackend, m_renderers, and m_timeprovider.

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

+ Here is the caller graph for this function:

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 149 of file model.cpp.

References m_namespaces, and selectNamespace().

Referenced by FIFE::ObjectLoader::load(), and FIFE::AtlasLoader::parseObject().

+ Here is the caller graph for this function:

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

Remove a map from this model.

Definition at line 120 of file model.cpp.

References m_maps.

void FIFE::Model::deleteMaps ( )

Removes all maps from this model.

Definition at line 135 of file model.cpp.

References m_maps, and purge().

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 169 of file model.cpp.

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

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 201 of file model.cpp.

References m_last_namespace, m_maps, and m_namespaces.

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

Returns new copy of cellgrid corresponding given name.

If none found, returns NULL

Definition at line 96 of file model.cpp.

References FIFE::_log, FIFE::CellGrid::clone(), FL_WARN, m_adopted_grids, and m_created_grids.

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

+ Here is the caller graph for this function:

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

Get a map.

Parameters
identifierthe id of the map to be found.

Definition at line 110 of file model.cpp.

References m_maps.

uint32_t FIFE::Model::getMapCount ( ) const

Return the number of maps in this model.

Definition at line 131 of file model.cpp.

References m_maps.

Referenced by FIFE::Engine::pump().

+ Here is the caller graph for this function:

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

Get all the maps in the model.

Definition at line 77 of file model.h.

References m_maps.

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

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

Definition at line 140 of file model.cpp.

References m_namespaces.

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

+ Here is the caller graph for this function:

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 224 of file model.cpp.

References selectNamespace().

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

+ Here is the caller graph for this function:

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

Get all the objects in the given namespace.

Definition at line 234 of file model.cpp.

References selectNamespace().

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

+ Here is the caller graph for this function:

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

Returns pather corresponding given name.

If none found, returns NULL

Definition at line 81 of file model.cpp.

References FIFE::_log, FL_WARN, and m_pathers.

Referenced by FIFE::ObjectLoader::load(), and FIFE::AtlasLoader::parseObject().

+ Here is the caller graph for this function:

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

Gets model speed.

See Also
setTimeMultiplier.

Definition at line 152 of file model.h.

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

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 257 of file model.cpp.

References m_last_namespace, and m_namespaces.

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

+ Here is the caller graph for this function:

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 246 of file model.cpp.

References m_namespaces.

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 148 of file model.h.

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

void FIFE::Model::update ( )

Called periodically to update events on model.

Definition at line 271 of file model.cpp.

References m_maps, and m_pathers.

Referenced by FIFE::Engine::pump().

+ Here is the caller graph for this function:

Member Data Documentation

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

Definition at line 173 of file model.h.

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

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

Definition at line 172 of file model.h.

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

namespace_t* FIFE::Model::m_last_namespace
private

Used to remember last 'selected' namespace.

Definition at line 163 of file model.h.

Referenced by deleteObjects(), and selectNamespace().

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

Definition at line 160 of file model.h.

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

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

Definition at line 171 of file model.h.

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

RenderBackend* FIFE::Model::m_renderbackend
private

Definition at line 177 of file model.h.

Referenced by createMap().

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

Definition at line 179 of file model.h.

Referenced by createMap().

TimeProvider FIFE::Model::m_timeprovider
private

Definition at line 175 of file model.h.

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


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