Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

Simulator Class Reference

#include <simulator.h>

Inheritance diagram for Simulator:

Persistence CommercialSim ElectricitySim IndustrialSim MainSim ResidentialSim TrafficSim List of all members.

Public Types

enum  SIMULATOR_STATE { SIMULATOR_RUNNING, SIMULATOR_STOPED, SIMULATOR_RETURN }

Public Member Functions

 Simulator ()
 do NOT use this
 Simulator (SDL_mutex *mutex, BuildingLayer *pblayer, Map *pmap)
void SaveTo (std::fstream &rfs)
void LoadFrom (std::fstream &rfs)
virtual int Main ()=0
virtual void AddStructure (const uint &w1, const uint &h1, const uint &w2, const uint &h2)
virtual void RemoveStructure (const uint &w1, const uint &h1, const uint &w2, const uint &h2)
void Run ()
void Stop ()
void Return ()
const bool CheckRange (const uint &w, const uint &l, const uint &range, const OPENCITY_STRUCTURE_CODE &enumStructCode) const
const bool CheckLevelUp (const uint w, const uint l, const Structure *pStruct) const
const bool CheckLevelDown (const uint w, const uint l, const Structure *pStruct) const
const int & GetVariation () const
const int GetValue () const
void SetVariation (const int rcVariation)
void SetValue (const int rcValue)

Static Public Member Functions

static int ThreadWrapper (void *pSim)
static void RCIDelay (void)

Protected Attributes

int _iVariation
 The average variation of the structures stimulated.
int _iValue
 The current global value of the simulator.
SIMULATOR_STATE enumSimState
 The current state of the simulator.
SDL_mutex * mutexMain
 Points to the global mutex.
BuildingLayerpbuildlayer
MappmapOfCity

Detailed Description

The class from which all the simulators derive. It contains common tests used by the micro simulators

Definition at line 65 of file simulator.h.


Member Function Documentation

const bool Simulator::CheckLevelDown const uint  w,
const uint  l,
const Structure pStruct
const
 

Check if the structure at the specified coodinates can "level down" Mainly, it consists of structure's size checking

Definition at line 205 of file simulator.cpp.

References Structure::GetCode(), Structure::GetGraphicCode(), Layer::GetLayerSize(), Structure::GetPreviousLevelGraphicCode(), PropertyManager::GetWLH(), and GlobalVar::gpPropertyMgr.

const bool Simulator::CheckLevelUp const uint  w,
const uint  l,
const Structure pStruct
const
 

Check if the structure at the specified coodinates can "level up". Mainly, it consists of structure's size checking

Definition at line 135 of file simulator.cpp.

References Structure::GetCode(), Structure::GetGraphicCode(), Layer::GetLayerSize(), Structure::GetNextLevelGraphicCode(), PropertyManager::GetWLH(), and GlobalVar::gpPropertyMgr.

const bool Simulator::CheckRange const uint &  w,
const uint &  l,
const uint &  range,
const OPENCITY_STRUCTURE_CODE &  enumStructCode
const
 

Given the (w, l) coordinates and a range in integer, this method return "true" if there's at least one required structure within the range and "false" otherwise

Definition at line 113 of file simulator.cpp.

References BuildingLayer::ContainStructure(), and Map::GetPossibleWH().

const int Simulator::GetValue  )  const
 

Return the global total value of the micro simulator

Definition at line 282 of file simulator.cpp.

References _iValue.

void Simulator::LoadFrom std::fstream &  rfs  )  [virtual]
 

Load the data from the specified stream

Parameters:
rfs A reference to a file stream which is ready for reading

Implements Persistence.

Reimplemented in ElectricitySim, and MainSim.

Definition at line 78 of file simulator.cpp.

References _iValue, and _iVariation.

Referenced by MainSim::LoadFrom(), and ElectricitySim::LoadFrom().

void Simulator::RCIDelay void   )  [static]
 

Each RCI (residential, commercial, industrial) micro simulator should call this at the end of each treatement so that the main thread can execute.

Definition at line 319 of file simulator.cpp.

References Structure::GetNumber(), and GlobalVar::gfMsSimDelayMax.

Referenced by MainSim::Main().

void Simulator::SaveTo std::fstream &  rfs  )  [virtual]
 

Save the data to the specified fstream

Parameters:
rfs A reference to a file stream which is ready for writing

Implements Persistence.

Reimplemented in ElectricitySim, and MainSim.

Definition at line 67 of file simulator.cpp.

References _iValue, and _iVariation.

Referenced by MainSim::SaveTo(), and ElectricitySim::SaveTo().


The documentation for this class was generated from the following files:
Generated on Sat Nov 11 10:21:11 2006 for OpenCity by  doxygen 1.4.2