ptd::CGameState Class Reference

#include <PtdGameModule.h>

Collaboration diagram for ptd::CGameState:

Collaboration graph
[legend]

List of all members.

Public Member Functions

std::string gameStateToString ()
 Method for converting the entire game state to a string, to be sent.
Creators
 CGameState ()
 Default constructor.
 CGameState (fsf::CNode *pParent, fsf::Time tTime=0)
 2-parameter constructor: parent and time stamp
 CGameState (std::string &strName, fsf::CNode *pParent, fsf::Time tTime=0)
 3-parameter constructor: node name, parent and time stamp
 CGameState (const CGameState &rhs)
 Copy constructor.
virtual fsf::CNode * clone () const
 Cloning: necessary for run-time polymorphism.
Manipulators
CGameState & operator= (const CGameState &)
 Assignment operator.
CPlatformer * getPlatformer (int playerID)
CCollisionObject * getCollisionObject (int objectID)
CMobileObject * getMobileObject (int objectID)
Accessors
virtual void getTypeID (std::string &str) const
double getMapHeight ()
 Map interaction.
double getMapWidth ()
void setMapSize (double width, double height)
std::list< CCollisionObject * >
::iterator 
getIterCollisionObj ()
 Iterators for CollisionObjects.
std::list< CCollisionObject * >
::iterator 
getCollisionObjEnd ()
std::list< CMobileObject * >
::iterator 
getIterMobileObjects ()
 Iterators for items affected by physics.
std::list< CMobileObject * >
::iterator 
getMobileObjectsEnd ()
std::list< CCollisionObject * >
::iterator 
getIterLevelPieces ()
 Iterators for all LevelPieces.
std::list< CCollisionObject * >
::iterator 
getLevelPiecesEnd ()
std::list< CPlatformer * >
::iterator 
getIterPlatformers ()
 Iterators for platformer players.
std::list< CPlatformer * >
::iterator 
getPlatformersEnd ()
int addCollisionObject (CCollisionObject *object)
int addMobileObject (CMobileObject *object)
int addPlatformer (CPlatformer *platformer)
int addBuilder (CBuilder *builder)
int addLevelPiece (CCollisionObject *levelPiece)
void removeCollisionObject (int objectID)
void removeMobileObject (int objectID)
void removePlatformer (int platformerID)
void removeLevelPiece (int levelPieceID)
void lockCollisionObjects ()
void unlockCollisionObjects ()
void lockMobileObjects ()
void unlockMobileObjects ()
void lockPlatformers ()
void unlockPlatformers ()
CBuilderObject * itemSelected ()
void selectItem (CBuilderObject *object)
CBuilder * getBuilder ()
fsf::CCharBuffer * toBuffer ()
void fromBuffer (fsf::CCharBuffer *gameStateBuffer)
void initialize ()
int getNextObjectID ()
std::list< int > getAvailableObjectIDs ()
std::list< int > getAvailablePlayerIDs ()

Private Attributes

std::list< CCollisionObject * > m_collisionObjects
fsf::CMutex m_csCollisionObjects
std::list< CMobileObject * > m_mobileObjects
 All objects that can be affected by physics.
fsf::CMutex m_csMobileObjects
std::list< CCollisionObject * > m_level
fsf::CMutex m_csLevel
double m_mapHeight
double m_mapWidth
fsf::CMutex m_csObjectIDs
int m_nextObjectID
std::list< int > m_availableObjectIDs

Static Private Attributes

static const int NUM_PLAYERS = 5

Players

std::list< CPlatformer * > m_platformers
 List of all Platfomer objects.
fsf::CMutex m_csPlatformers
std::list< int > m_availablePlayerIDs
fsf::CMutex m_csPlayerIDs
CBuilder * m_builder
 A pointer to the builder object.
fsf::CMutex m_csBuilder
CBuilderObject * m_itemPressed
int m_score
 Current game score.
fsf::CMutex m_csScore
void lockBuilder ()
void unlockBuilder ()


Detailed Description

The game state node type encapsulates all the elements necessary to describe the game state

Member Function Documentation

void CGameState::fromBuffer ( fsf::CCharBuffer *  gameStateBuffer  ) 

Reads from an encoding from a buffer and updates the data members of this object

Parameters:
an object of type fsf::CCharBuffer which represents the updated game state

Updating the list of CollisionObjects

Updating the list of MobileObjects

Updating the list of Platformers

std::list< CCollisionObject * >::iterator CGameState::getIterCollisionObj (  ) 

Iterators for CollisionObjects.

Methods to get Iterators over the various lists of objects. For each list, the first method returns an iterator to the beginning of the list and the second mehtod returns an iterator to the end of the list NOTE: Please lock the lists before iterating over them!

fsf::CCharBuffer * CGameState::toBuffer (  ) 

Places a byte-level encoding of this object into a buffer

Returns:
an object of type fsf::CCharBuffer which represents the game state.


Member Data Documentation

std::list<int> ptd::CGameState::m_availableObjectIDs [private]

m_availableObjectIDs : Keeps track of available object IDs. Starts out empty, but as objects are removed from the game state their IDs are pushed onto the back of the list. When an object is added to the game state and needs an ID, it checks this list first and takes the first value if there is one. If there isn't, it takes and then increments m_nextObjectID.

std::list<int> ptd::CGameState::m_availablePlayerIDs [private]

Keeps track of the playerIDs not currently in use.

  • Should be initialized to hold 1-5, in order
  • When a player is added to the game, it gets its player ID by calling pop_front on this list
  • When a player leaves the game, its player ID should be pushed onto the end of this list

std::list<CCollisionObject*> ptd::CGameState::m_collisionObjects [private]

This list contains all objects in play that can be collided with CBuilderObjects, which are created by the builder will go in this list when a new CBuilderObject is placed in the game. CBuilderObject is a subClass of CCollisionObject, so there is no typing issues. A method which wishes to access a CBuilderObject's cost or label field after it's placed in the game will have to perform a cast operation.

fsf::CMutex ptd::CGameState::m_csObjectIDs [private]

The next two data members keep track of the unique identifiers for the objects in the game state. For now, CollisionObjects, MobileObjects, and LevelPieces all share the same ID list! This reduces clutter, but may become a problem if we're ever adding/removing lots of objects to the game state

std::list<CCollisionObject*> ptd::CGameState::m_level [private]

The level is made up of LevelPieces (ground, walls platforms, etc)

m_nextObjectID : keeps track of the next new value that can be assigned as an object ID. The platformers always hold spots 1-NUM_PLAYERS, so it starts 1 above that and is incremented as objects are added to the game state.


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

Generated on Mon Dec 20 15:54:52 2010 for Platitude by doxygen 1.5.9