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

MainSim Class Reference

#include <mainsim.h>

Inheritance diagram for MainSim:

Simulator Persistence List of all members.

Public Types

enum  OPENCITY_MICROSIM {
  OC_MICROSIM_RES = 0, OC_MICROSIM_COM, OC_MICROSIM_IND, OC_MICROSIM_ELE,
  OC_MICROSIM_TRA, OC_MICROSIM_MAX, OC_MICROSIM_DEFAULT
}

Public Member Functions

 MainSim (SDL_mutex *mutex, BuildingLayer *pblayer, Map *pmap)
 ~MainSim ()
void SaveTo (std::fstream &rfs)
void LoadFrom (std::fstream &rfs)
int Main ()
void AddStructure (const uint w1, const uint l1, const uint w2, const uint l2, const OPENCITY_MICROSIM sim=OC_MICROSIM_DEFAULT)
void RemoveStructure (const uint w1, const uint l1, const uint w2, const uint l2, const OPENCITY_MICROSIM sim=OC_MICROSIM_DEFAULT)
void Run ()
void Stop ()
void Return ()
void RefreshSimValue ()
const int GetValue (const OPENCITY_MICROSIM sim) const

Private Attributes

Simulator_tpSimulator [OC_MICROSIM_MAX]
 Table of pointers to Simulator object.

Detailed Description

Handles the simulation of the commercial sub-system.

Definition at line 31 of file mainsim.h.


Member Enumeration Documentation

enum MainSim::OPENCITY_MICROSIM
 

Each enumeration corresponds to a specific micro simulator

Enumeration values:
OC_MICROSIM_RES  Residential micro simulator.
OC_MICROSIM_COM  Commercial micro simulator.
OC_MICROSIM_IND  Industrial micro simulator.
OC_MICROSIM_ELE  Electric micro simulator.
OC_MICROSIM_TRA  Traffic micro simulator.
OC_MICROSIM_MAX  Currently, we have 5 micro sims.

Definition at line 36 of file mainsim.h.


Constructor & Destructor Documentation

MainSim::MainSim SDL_mutex *  mutex,
BuildingLayer pblayer,
Map pmap
 

Constructs a new MainSim object.

Parameters:
mutex A pointer to a SDL_mutex which should be used to prevent that the gobal simulator's data is overwritten by multiple micro simulators
pblayer A pointer to the BuildingLayer
pmap A pointer to the gobal Map object
Todo:
Remove pblayer and pmap. Use global pointer for them

Definition at line 34 of file mainsim.cpp.

References _tpSimulator, GlobalVar::gpMoveMgr, GlobalVar::gpPathFinder, OC_MICROSIM_COM, OC_MICROSIM_ELE, OC_MICROSIM_IND, OC_MICROSIM_RES, and OC_MICROSIM_TRA.

MainSim::~MainSim  ) 
 

Destructs a MainSim object.

Definition at line 52 of file mainsim.cpp.

References _tpSimulator, and OC_MICROSIM_MAX.


Member Function Documentation

void MainSim::AddStructure const uint  w1,
const uint  l1,
const uint  w2,
const uint  l2,
const OPENCITY_MICROSIM  sim = OC_MICROSIM_DEFAULT
 

Notifies the micro simulators that a new structure has been added to the system

Parameters:
w1,l1,w2,l2 The area used by the new structure
sim The optional microsim identifier

Definition at line 112 of file mainsim.cpp.

Referenced by City::_Load().

const int MainSim::GetValue const OPENCITY_MICROSIM  sim  )  const
 

Return the global total value of the micro simulator

Parameters:
sim The micro simulator to query the information
Returns:
The value

Definition at line 264 of file mainsim.cpp.

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

Overload the base method in order to call all other microsims' method

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

Reimplemented from Simulator.

Definition at line 74 of file mainsim.cpp.

References _tpSimulator, Simulator::LoadFrom(), and OC_MICROSIM_MAX.

Referenced by City::_Load().

int MainSim::Main  )  [virtual]
 

The main method of the simulator

Implements Simulator.

Definition at line 84 of file mainsim.cpp.

References _tpSimulator, Simulator::Main(), OC_MICROSIM_MAX, Simulator::RCIDelay(), and RefreshSimValue().

void MainSim::RefreshSimValue  ) 
 

Refresh the values of all the micro simulators. This method is called automatically by Run() every 3 turns

See also:
Run()

Definition at line 184 of file mainsim.cpp.

References _tpSimulator, Structure::GetCode(), Structure::GetLevel(), BuildingLayer::GetLinearStructure(), Layer::GetMaxLinear(), Structure::IsSet(), OC_MICROSIM_COM, OC_MICROSIM_ELE, OC_MICROSIM_IND, OC_MICROSIM_RES, and Simulator::SetValue().

Referenced by City::_Load(), and Main().

void MainSim::RemoveStructure const uint  w1,
const uint  l1,
const uint  w2,
const uint  l2,
const OPENCITY_MICROSIM  sim = OC_MICROSIM_DEFAULT
 

Notify the micro simulators that a structure has been removed from the system

Parameters:
w1,l1,w2,l2 The area used by the structure
sim The optional microsim identifier

Definition at line 132 of file mainsim.cpp.

void MainSim::Return  ) 
 

Overload the parent's method

See also:
Simulator::Return()

Reimplemented from Simulator.

Definition at line 173 of file mainsim.cpp.

References _tpSimulator, OC_MICROSIM_MAX, and Simulator::Return().

Referenced by City::_DeleteSimulator().

void MainSim::Run  ) 
 

Overload the parent's method

See also:
Simulator::Run()

Reimplemented from Simulator.

Definition at line 151 of file mainsim.cpp.

References _tpSimulator, OC_MICROSIM_MAX, and Simulator::Run().

Referenced by City::_CreateSimulator().

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

Overload the base method in order to call all other microsims' method

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

Reimplemented from Simulator.

Definition at line 64 of file mainsim.cpp.

References _tpSimulator, OC_MICROSIM_MAX, and Simulator::SaveTo().

Referenced by City::_Save().

void MainSim::Stop  ) 
 

Overload the parent's method

See also:
Simulator::Stop()

Reimplemented from Simulator.

Definition at line 162 of file mainsim.cpp.

References _tpSimulator, OC_MICROSIM_MAX, and Simulator::Stop().


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