Game Class Reference

Holds all content of game / provide access to it. More...

#include <game.h>

Inherited by GameClient, and GameServer.

Inheritance diagram for Game:

Inheritance graph
[legend]
Collaboration diagram for Game:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 Game (void)
virtual ~Game (void)
virtual bool loadMap (const std::string mapName)
virtual void init ()=0
 Init data structures for game.
virtual void run ()=0
 Start the game.
virtual void clean ()
 Clean data structures for game.
virtual void endFun ()
 Set flag that signalises engine to end.
WorldgetWorld ()
 Provide access to World.
int newPlayer (const Player &player, int ID=-1)
 Register new player to game.
PlayergetPlayer (int ID)
 Return player associated with this ID.
void removePlayer (int ID)
 Invalidate ID of player.
std::vector< int > & getValidPlayersID ()
 Create vector of all valid players ID.
bool isPlayerIDValid (int ID)
 test of ID validity
bool isRunning ()
 Thread safe access to state of game.
TaskManagergetTaskManager ()
 Get task manager for game.
EventQueuegetEventQueue ()
 Returns reference to event queue.

Protected Member Functions

void recreateWorld ()
 Create new world.
void setRunning (bool state)
 change running state.
void updateValidPlayersID ()
 Update mValidPlayersID to match mPlayers.

Protected Attributes

EventQueue mEventQueue
 Queue to handle events from network or other input - for update tasks.
bool mRunning
 True if game is not lodaing or.. simply the game is running.
Mutex mRunningMutex
 For safe access to mRunning.
WorldmWorld
 World structure holded by Game.
TaskManager mTaskManager
 All tasks.
bool mEndFun
 if true, engine will stop
std::vector< Player * > mPlayers
 Vector of all players in game.
std::vector< int > mValidPlayersID
 List of valid players ID.

Detailed Description

Holds all content of game / provide access to it.

Itself implements access to players in game. You can't create instance of this class. This class implements common Game features for server and client.

Definition at line 21 of file game.h.


Constructor & Destructor Documentation

Game::Game void   ) 
 

Definition at line 8 of file game.cpp.

References mRunning, and mWorld.

Game::~Game void   )  [virtual]
 

Definition at line 24 of file game.cpp.


Member Function Documentation

void Game::clean  )  [virtual]
 

Clean data structures for game.

It mean for examlpe unloading textures and models... This function shouls clean players vector. So don't forget to call it in derived classes.

Reimplemented in GameClient, and GameServer.

Definition at line 29 of file game.cpp.

References mPlayers, and updateValidPlayersID().

Referenced by GameServer::clean(), and GameClient::clean().

Here is the call graph for this function:

void Game::endFun  )  [virtual]
 

Set flag that signalises engine to end.

Definition at line 49 of file game.cpp.

References mEndFun, and TIN.

Referenced by InputManager::checkSDLEvents(), CommanderServer::command_quit(), and CommanderClient::command_quit().

EventQueue& Game::getEventQueue  )  [inline]
 

Returns reference to event queue.

Returns:
Reference to event queue

Definition at line 158 of file game.h.

References mEventQueue.

Player & Game::getPlayer int  ID  ) 
 

Return player associated with this ID.

The program will be halted if you call this with invalid ID.

Parameters:
ID id if player you want to receive.
Returns:
Reference to player that has ID ID

Definition at line 105 of file game.cpp.

References DIE(), LOGE, and mPlayers.

Referenced by CommanderClient::command_players(), Tank::initSpecific(), and Projectile::initSpecific().

Here is the call graph for this function:

TaskManager & Game::getTaskManager  ) 
 

Get task manager for game.

The task manager may contain App.TaskManager as a member

Returns:
TaskManager from game

Definition at line 184 of file game.cpp.

References mTaskManager.

Referenced by GameServer::run(), and GameClient::run().

std::vector< int > & Game::getValidPlayersID  ) 
 

Create vector of all valid players ID.

NOTE that this vector may change in next loop run since some players may leave/join the game. So be carefull. Please dn't modify returned vector.

Returns:
vector of ID's.

Definition at line 132 of file game.cpp.

References mValidPlayersID.

Referenced by CommanderClient::command_players().

World & Game::getWorld  ) 
 

Provide access to World.

Returns:
mWorld

Definition at line 42 of file game.cpp.

References assertL, and mWorld.

Referenced by TaskSimulationServer::checkTerrainHeights(), TaskRender::init(), LayerGame::initRefs(), GameServer::run(), GameClient::run(), TaskSimulationServer::setCollModelTransformations(), TaskSimulationServer::tick(), and TaskSimulationServer::updateHistory().

virtual void Game::init  )  [pure virtual]
 

Init data structures for game.

This is for example loading some textures, models, registering to input manager,...

Implemented in GameClient, and GameServer.

bool Game::isPlayerIDValid int  ID  ) 
 

test of ID validity

This function may be needed because client may kick some other player using its ID but the player allready left so we may get in troubles when calling removePlayer directly.

Parameters:
ID ID to test for valitity
Returns:
true if ID valid.

Definition at line 150 of file game.cpp.

References mPlayers.

Referenced by World::createProjectile(), and World::createTank().

bool Game::isRunning  ) 
 

Thread safe access to state of game.

This is good to test if it is a good idea to send/receive/process network messages like Up/down/tank movement/... Provides access to mRunning.

Returns:
true if whole world is loaded and the game is running.

Definition at line 157 of file game.cpp.

References Mutex::lock(), mRunning, mRunningMutex, and Mutex::unlock().

Here is the call graph for this function:

bool Game::loadMap const std::string  mapName  )  [virtual]
 

Load data for some map.

Parameters:
mapName name of file to load
Returns:
true if loaded sucessfully - Maybe will kill the program. will be decided later.

Reimplemented in GameServer.

Definition at line 56 of file game.cpp.

References LOGE, and TIN.

Referenced by GameServer::loadMap(), and ApplicationClient::run().

int Game::newPlayer const Player player,
int  ID = -1
 

Register new player to game.

Note that generated ID doesn't has to be unique. It may be some older ID that has been invalidated.

Parameters:
player structure with new player to add. The copy of this structure is saved. The copy is made using operator =.
ID of new player. If -1 first free ID is taken. The -1 call is for server and specific ID call will be used in client. If you set ID and ID is allready in use, the program will halt.
Returns:
id of player

Definition at line 66 of file game.cpp.

References DIE(), LOGE, mPlayers, and updateValidPlayersID().

Referenced by TaskSimulationServer::tick().

Here is the call graph for this function:

void Game::recreateWorld  )  [protected]
 

Create new world.

delete old if existed and create new. Be carefull when calling this :-)

Definition at line 174 of file game.cpp.

References DIE(), and mWorld.

Referenced by GameServer::run(), and GameClient::run().

Here is the call graph for this function:

void Game::removePlayer int  ID  ) 
 

Invalidate ID of player.

The ID must not be used then. But the ID may be recycled and later returned by newPlayer. TODO: there should be some fetare that check te vector of players and resize it if number of players is <= 1/2 of allocated space for players. (But at least 8 ? Or something like that)

Parameters:
ID that will be invalidated.

Definition at line 117 of file game.cpp.

References DIE(), LOGE, and mPlayers.

Here is the call graph for this function:

virtual void Game::run  )  [pure virtual]
 

Start the game.

Creates tasks and start main loop.

Implemented in GameClient, and GameServer.

void Game::setRunning bool  state  )  [protected]
 

change running state.

Thread safe. Provides access to mRunning.

Parameters:
state new running state

Definition at line 167 of file game.cpp.

References Mutex::lock(), mRunning, mRunningMutex, and Mutex::unlock().

Referenced by GameServer::loadNewMap(), and GameServer::run().

Here is the call graph for this function:

void Game::updateValidPlayersID  )  [protected]
 

Update mValidPlayersID to match mPlayers.

This should be called after every change of mPlayers

Definition at line 137 of file game.cpp.

References mPlayers, and mValidPlayersID.

Referenced by clean(), and newPlayer().


Member Data Documentation

bool Game::mEndFun [protected]
 

if true, engine will stop

Definition at line 195 of file game.h.

Referenced by endFun(), GameServer::run(), and GameClient::run().

EventQueue Game::mEventQueue [protected]
 

Queue to handle events from network or other input - for update tasks.

Definition at line 168 of file game.h.

Referenced by getEventQueue().

std::vector<Player*> Game::mPlayers [protected]
 

Vector of all players in game.

Note that not all positions has to be valid.

Definition at line 202 of file game.h.

Referenced by clean(), getPlayer(), isPlayerIDValid(), newPlayer(), removePlayer(), and updateValidPlayersID().

bool Game::mRunning [protected]
 

True if game is not lodaing or.. simply the game is running.

Definition at line 186 of file game.h.

Referenced by Game(), isRunning(), and setRunning().

Mutex Game::mRunningMutex [protected]
 

For safe access to mRunning.

Definition at line 187 of file game.h.

Referenced by isRunning(), and setRunning().

TaskManager Game::mTaskManager [protected]
 

All tasks.

Definition at line 193 of file game.h.

Referenced by getTaskManager(), GameServer::run(), and GameClient::run().

std::vector<int> Game::mValidPlayersID [protected]
 

List of valid players ID.

Definition at line 203 of file game.h.

Referenced by getValidPlayersID(), and updateValidPlayersID().

World* Game::mWorld [protected]
 

World structure holded by Game.

Definition at line 191 of file game.h.

Referenced by Game(), getWorld(), and recreateWorld().


The documentation for this class was generated from the following files:
Generated on Wed Apr 12 14:15:08 2006 for bjs by  doxygen 1.4.5