C# Класс Terrarium.Game.GameEngine

This class encapsulates the majority of the Terrarium gaming engine that controls the creatures, updates of the world data, manipulation of events, and other common engine features. To see the basic game logic, look at the ProcessTurn() function. This is what controls the flow of the game.
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
AddNewOrganism ( String assemblyPath, Point preferredLocation, System.Boolean reintroduction ) : Species

Add a new organism to the terrarium using the given assembly to generate a species from, a preferred insertion point, and whether this is a reintroduction or not.

AddNewOrganism ( Species species, Point preferredLocation ) : void

Add a new organism given the species of the creature, and the preferred location of insertion.

LoadEcosystemGame ( string dataPath, string fileName, TerrariumLed leds ) : void

Creates a new game engine that can be used to load a pre-existing EcoSystem game.

LoadTerrariumGame ( string dataPath, string fileName, TerrariumLed leds ) : void

Creates a game engine that loads an existing Terrarium game save state.

NewEcosystemGame ( string dataPath, string fileName, TerrariumLed leds ) : void

Creates a new game engine that can be used to play an EcoSystem game.

NewTerrariumGame ( string dataPath, string fileName, TerrariumLed leds ) : void

Creates a new game engine that can be used for a Terrarium game. Terrarium games aren't networked and can load any creatures.

OnEngineStateChanged ( EngineStateChangedEventArgs e ) : void

Helper function for the EngineStateChanged event to fire the event given a new EngineStateChangedEventArgs

OnWorldVectorChanged ( WorldVectorChangedEventArgs e ) : void

Helper function for the WorldVectorChanged event to fire the event given a new WorldVectorChangedEventArgs.

ProcessTurn ( ) : Boolean

Processes turns in a phase manner. After 10 calls to ProcessTurn all 10 phases will be complete and the method will have completed one game tick.

ReceiveTeleportation ( Object teleportedObject, bool teleportedToSelf ) : void

Receieves a teleported state either from a remote peer or the local peer.

RemoveOrganismQueued ( KilledOrganism killedOrganism ) : void

Method used to add an organism to the organism removal queue.

StopGame ( Boolean serializeState ) : void

Stops the game and determines if the final tick of data should be serialized.

Teleport ( OrganismState state ) : void

Can be called with an OrganismState that needs to be teleported. Cannot be called during MoveAnimals since it passes true to the clearOld argument in RemoveOrganism.

Приватные методы

Метод Описание
CalculateWorldSize ( ) : void

This routine attempts to figure out how fast the machine is by running some standardized tests to test code execution speed. It then uses this information to determine how big the Terrarium world should be on this machine to maintain a decent frame rate. It also determines how big of a time slice we should give each animal.

GameEngine ( string dataPath, bool useNetwork, bool deserializeState, string fileName, bool reportData, TerrariumLed leds, bool trackLastRun ) : System

Constructs a new game engine.

burnBaseEnergy ( ) : void
changeMovementVectors ( ) : void

Helper function to change movement vectors for all creatures after they have processed their turn and determined new points of destination.

computeWorldHeight ( ) : void

Now lets compute worldheight Each animal needs a certain amount of territory so we can compute a density. 10,000 pixels per plant/animal is the key at this point.

countOrganism ( OrganismState state, PopulationChangeReason reason ) : void

Adds another organism to the count of organisms. Depending on the organism type either plants or animals will be incremented.

deserializeState ( string path ) : void

Deserializes the game state from the given path.

doAntennas ( ) : void

Helper function to update all state objects with the latest antenna information after the creature's have processed their ticks.

doAttacks ( ) : void
doBites ( ) : void

Assumes the animal was dead (if an animal) at the time of the bite and that it is the proper food source for this animal (herbivore or carnivore) Also assumes that it is within biting range.

doDefends ( ) : void

We only send these events so that animals can easily continue defending if they want to. There is no information in them

estimateNumberOfAnimalsToSupport ( ) : void

This is where we attempt to estimate how many animals we can support on this machine. We assume we want 20 frames a second and we do two engine ticks per second which means we have 500 msec per engine tick. We budget our paint time 200 mSec, and that leaves 300 mSec for all engine processing. We assume we'll allocate 4/5 of our available engine processing time to running animals, and 1/5 to plants. organismQuanta is how many microseconds each animal will get, so we have to divide by 1000 to get milliseconds. We assume that we can use all engine processing time for running animals although this isn't strictly true since we need to run the engine code too. It's OK, because animals can't use all their allocated time every tick -- they'll eventually get killed. Thus, we use the time they don't use for the engine processing. It's all basically an estimate, that we've tuned and works pretty well.

findEmptyPosition ( int cellRadius, Point preferredGridPoint ) : Point

Finds a location within the current game world where no organisms exist.

giveEnergyToPlants ( ) : void
growAllOrganisms ( ) : void
heal ( ) : void
incubate ( ) : void
insertOrganismsFromQueue ( ) : void

Inserts all new organisms from the queue when it is safe to insert them. This happens so that all new organism are inserted at the same time in a serial manner rather than in multiple phases.

killDiseasedOrganisms2 ( ) : void
killOrganisms ( IDictionary organismsToKill, int organismKillCount, int totalPopulation, bool killingAnimals ) : void
moveAnimals ( ) : void
removeOrganism ( KilledOrganism killedOrganism ) : void

Method used to remove an organism given a KilledOrganism object. This method instantly removes the organism and so should not be called by normal code, rather call RemoveOrganismQueued.

removeOrganismsFromQueue ( ) : void

Method used to remove organisms that have been queued for removal.

serializeState ( string path ) : void

Serializes the game state to the given path.

sortOrganismsForDisease ( IDictionary plantsToKill, IDictionary animalsToKill, IList deadAnimals ) : void

Fills in the hashtables with sorted lists keyed on SpeciesName

startReproduction ( ) : void
teleportOrganisms ( ) : void
uncountOrganism ( OrganismState state, PopulationChangeReason reason ) : void

Subtracts an organism from the count of organisms. Depending on the organism type either plants or animals will be decremented.

Описание методов

AddNewOrganism() публичный Метод

Add a new organism to the terrarium using the given assembly to generate a species from, a preferred insertion point, and whether this is a reintroduction or not.
public AddNewOrganism ( String assemblyPath, Point preferredLocation, System.Boolean reintroduction ) : Species
assemblyPath String The path to the assembly used for this creature.
preferredLocation Point The preferred point of insertion.
reintroduction System.Boolean Controls if this is a reintroduction.
Результат Species

AddNewOrganism() публичный Метод

Add a new organism given the species of the creature, and the preferred location of insertion.
public AddNewOrganism ( Species species, Point preferredLocation ) : void
species Species The species for the new organism.
preferredLocation Point The preferred insertion point.
Результат void

LoadEcosystemGame() публичный статический Метод

Creates a new game engine that can be used to load a pre-existing EcoSystem game.
public static LoadEcosystemGame ( string dataPath, string fileName, TerrariumLed leds ) : void
dataPath string The path where the Terrarium game will be stored.
fileName string The path to the serialized Terrarium.
leds TerrariumLed A series of leds to be used for state reporting.
Результат void

LoadTerrariumGame() публичный статический Метод

Creates a game engine that loads an existing Terrarium game save state.
public static LoadTerrariumGame ( string dataPath, string fileName, TerrariumLed leds ) : void
dataPath string The path where the Terrarium game will be stored.
fileName string The path to the serialized Terrarium.
leds TerrariumLed A series of leds to be used for state reporting.
Результат void

NewEcosystemGame() публичный статический Метод

Creates a new game engine that can be used to play an EcoSystem game.
public static NewEcosystemGame ( string dataPath, string fileName, TerrariumLed leds ) : void
dataPath string The path where the Terrarium game will be stored.
fileName string The path to the serialized Terrarium.
leds TerrariumLed A series of leds to be used for state reporting.
Результат void

NewTerrariumGame() публичный статический Метод

Creates a new game engine that can be used for a Terrarium game. Terrarium games aren't networked and can load any creatures.
public static NewTerrariumGame ( string dataPath, string fileName, TerrariumLed leds ) : void
dataPath string The path where the Terrarium game will be stored.
fileName string The path to the serialized Terrarium.
leds TerrariumLed A series of leds to be used for state reporting.
Результат void

OnEngineStateChanged() публичный Метод

Helper function for the EngineStateChanged event to fire the event given a new EngineStateChangedEventArgs
public OnEngineStateChanged ( EngineStateChangedEventArgs e ) : void
e EngineStateChangedEventArgs Properties identifying the change to the engine.
Результат void

OnWorldVectorChanged() публичный Метод

Helper function for the WorldVectorChanged event to fire the event given a new WorldVectorChangedEventArgs.
public OnWorldVectorChanged ( WorldVectorChangedEventArgs e ) : void
e WorldVectorChangedEventArgs References to the new and old vectors.
Результат void

ProcessTurn() публичный Метод

Processes turns in a phase manner. After 10 calls to ProcessTurn all 10 phases will be complete and the method will have completed one game tick.
public ProcessTurn ( ) : Boolean
Результат Boolean

ReceiveTeleportation() публичный Метод

Receieves a teleported state either from a remote peer or the local peer.
public ReceiveTeleportation ( Object teleportedObject, bool teleportedToSelf ) : void
teleportedObject Object The teleported object.
teleportedToSelf bool Whether the teleportation is local or from a remote peer.
Результат void

RemoveOrganismQueued() публичный Метод

Method used to add an organism to the organism removal queue.
public RemoveOrganismQueued ( KilledOrganism killedOrganism ) : void
killedOrganism KilledOrganism The organism to remove.
Результат void

StopGame() публичный Метод

Stops the game and determines if the final tick of data should be serialized.
public StopGame ( Boolean serializeState ) : void
serializeState Boolean Controls if the state is serialized.
Результат void

Teleport() публичный Метод

Can be called with an OrganismState that needs to be teleported. Cannot be called during MoveAnimals since it passes true to the clearOld argument in RemoveOrganism.
public Teleport ( OrganismState state ) : void
state OrganismState The state of the creature to be teleported.
Результат void