games.strategy.engine.data
Class GameData

java.lang.Object
  extended by games.strategy.engine.data.GameData
All Implemented Interfaces:
java.io.Serializable

public class GameData
extends java.lang.Object
implements java.io.Serializable

Central place to find all the information for a running game. Using this object you can find the territores, connections, production rules, unit types...

Threading. The game data, and all parts of the game data (such as Territories, Players, Units...) are protected by a read/write lock. If you are reading the game data, you should read while you have the read lock as below.

data.acquireReadLock(); try { //read data here } finally { data.releaseReadLock(); } The exception is delegates within a start(), end() or any method called from an IGamePlayer through the delgates remote interface. The delegate will have a read lock for the duration of those methods.

Non engine code must NOT acquire the games writeLock(). All changes to game Data must be made through a DelegateBridge or through a History object.

Version:
1.0
Author:
Sean Bridges
See Also:
Serialized Form

Field Summary
static java.lang.String GAME_UUID
           
 
Constructor Summary
GameData()
          Creates new GameData
 
Method Summary
 void acquireReadLock()
          No changes to the game data should be made unless this lock is held.
 void acquireWriteLock()
          No changes to the game data should be made unless this lock is held.
 void addDataChangeListener(GameDataChangeListener listener)
           
 void addTerritoryListener(TerritoryListener listener)
           
 boolean areChangesOnlyInSwingEventThread()
          Should we throw an error if changes to this game data are made outside of the swing event thread.
 void clearAllListeners()
           
 void forceChangesOnlyInSwingEventThread()
          If set to true, then we will throw an error when the game data is changed outside the swing event thread.
 AllianceTracker getAllianceTracker()
          Get the Alliance Tracker for the game.
 DelegateList getDelegateList()
           
 IGameLoader getGameLoader()
           
 java.lang.String getGameName()
           
 Version getGameVersion()
           
 History getHistory()
           
 GameMap getMap()
          Return the GameMap.
 PlayerList getPlayerList()
          Get the list of Players in the game.
 ProductionFrontierList getProductionFrontierList()
          Get the list of production Frontiers for this game.
 ProductionRuleList getProductionRuleList()
          Get the list of Production Rules for the game.
 GameProperties getProperties()
           
 RepairFrontierList getRepairFrontierList()
          Get the list of production Frontiers for this game.
 RepairRuleList getRepairRuleList()
          Get the list of Production Rules for the game.
 ResourceList getResourceList()
          Get the list of resources available in the game.
 GameSequence getSequence()
           
 UnitHolder getUnitHolder(java.lang.String name, java.lang.String type)
           
 UnitsList getUnits()
           
 UnitTypeList getUnitTypeList()
           
 void postDeSerialize()
          Not to be called by mere mortals.
 void releaseReadLock()
           
 void releaseWriteLock()
           
 void removeDataChangeListener(GameDataChangeListener listener)
           
 void removeTerritoryListener(TerritoryListener listener)
           
 void testLocksOnRead()
          On reads of the game data components, make sure that the read or write lock is held.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GAME_UUID

public static final java.lang.String GAME_UUID
See Also:
Constant Field Values
Constructor Detail

GameData

public GameData()
Creates new GameData

Method Detail

getMap

public GameMap getMap()
Return the GameMap. The game map allows you to list the territories in the game, and to see which territory is connected to which.

Returns:
the map for this game.

getUnits

public UnitsList getUnits()
Returns:
a collection of all units in the game

getPlayerList

public PlayerList getPlayerList()
Get the list of Players in the game.


getResourceList

public ResourceList getResourceList()
Get the list of resources available in the game.


getProductionFrontierList

public ProductionFrontierList getProductionFrontierList()
Get the list of production Frontiers for this game.


getProductionRuleList

public ProductionRuleList getProductionRuleList()
Get the list of Production Rules for the game.


getRepairFrontierList

public RepairFrontierList getRepairFrontierList()
Get the list of production Frontiers for this game.


getRepairRuleList

public RepairRuleList getRepairRuleList()
Get the list of Production Rules for the game.


getAllianceTracker

public AllianceTracker getAllianceTracker()
Get the Alliance Tracker for the game.


areChangesOnlyInSwingEventThread

public boolean areChangesOnlyInSwingEventThread()
Should we throw an error if changes to this game data are made outside of the swing event thread.


forceChangesOnlyInSwingEventThread

public void forceChangesOnlyInSwingEventThread()
If set to true, then we will throw an error when the game data is changed outside the swing event thread.


getSequence

public GameSequence getSequence()

getUnitTypeList

public UnitTypeList getUnitTypeList()

getDelegateList

public DelegateList getDelegateList()

getUnitHolder

public UnitHolder getUnitHolder(java.lang.String name,
                                java.lang.String type)

getProperties

public GameProperties getProperties()

addTerritoryListener

public void addTerritoryListener(TerritoryListener listener)

removeTerritoryListener

public void removeTerritoryListener(TerritoryListener listener)

addDataChangeListener

public void addDataChangeListener(GameDataChangeListener listener)

removeDataChangeListener

public void removeDataChangeListener(GameDataChangeListener listener)

getGameLoader

public IGameLoader getGameLoader()

getGameVersion

public Version getGameVersion()

getGameName

public java.lang.String getGameName()

getHistory

public History getHistory()

postDeSerialize

public void postDeSerialize()
Not to be called by mere mortals.


acquireReadLock

public void acquireReadLock()
No changes to the game data should be made unless this lock is held. calls to acquire lock will block if the lock is held, and will be held until the release method is called


releaseReadLock

public void releaseReadLock()

acquireWriteLock

public void acquireWriteLock()
No changes to the game data should be made unless this lock is held. calls to acquire lock will block if the lock is held, and will be held until the release method is called


releaseWriteLock

public void releaseWriteLock()

clearAllListeners

public void clearAllListeners()

testLocksOnRead

public void testLocksOnRead()
On reads of the game data components, make sure that the read or write lock is held.