00001 // ///////////////////////////////////////////////////////////////////////////// 00002 // 00003 // Name: GameState.cpp 00004 // Author: Michael Bartsch (ZCCdark203) 00005 // 00006 // Desc : The GameState object is a base class which is implemented 00007 // through derived sub-classes. 00008 // 00009 // License: Copyright (C) 2009 Michael Bartsch and Contributors 00010 // 00011 // This program is free software: you can redistribute it 00012 // and/or modify it under the terms of the zlib/libpng License. 00013 // See main.cpp for conditions of distribution and use. 00014 // 00015 // ///////////////////////////////////////////////////////////////////////////// 00016 00017 // Include files 00018 #include "GameState.h" 00019 #include "../scripting/ScriptHelper.h" 00020 00021 00022 // GameState class 00023 // Static variables. 00024 u32 GameState::mIDCount = 0; 00025 00026 // Constructer of the GameState class. 00027 GameState::GameState() 00028 { 00029 mID = mIDCount++; 00030 00031 // Create the base entity. 00032 std::stringstream ss; 00033 ss << "GameState#" << mID; 00034 mBaseEntity = GameManager::Instance()->getEntityManager()->createEntity(ss.str()); 00035 } 00036 00037 // Deconstructor of the GameState class. 00038 GameState::~GameState() 00039 { 00040 GameManager::Instance()->getEntityManager()->removeEntity(mBaseEntity); 00041 } 00042 00043 // Initialises the GameState. 00044 // -> Implemented by subclass. 00045 void GameState::init() 00046 { 00047 } 00048 00049 // Clears the GameState. 00050 // -> Implemented by subclass. 00051 void GameState::clear() 00052 { 00053 } 00054 00055 // Updates the GameState. 00056 // -> Implemented by subclass. 00057 void GameState::update(f32 deltaTime) 00058 { 00059 } 00060 00061 // Renders the GameState. 00062 // -> Implemented by subclass. 00063 void GameState::render() 00064 { 00065 } 00066 00067 // Returns the base entity. 00068 const Entity* GameState::getBaseEntity() const 00069 { 00070 return mBaseEntity; 00071 } 00072 00073 // Event functions 00074 // Sends the "onUpdate" event to all entities subscribed to this state. 00075 void GameState::onUpdate(f32 deltaTime) 00076 { 00077 mBaseEntity->emitEvent("onUpdate", &deltaTime); 00078 } 00079 00080 // Sends the "onUpdate" event to all entities subscribed to this state. 00081 void GameState::onRender() 00082 { 00083 mBaseEntity->emitEvent("onRender"); 00084 } 00085 00086 // Sends the "onPause" event to all entities subscribed to this state. 00087 void GameState::onPause() 00088 { 00089 mBaseEntity->emitEvent("onPause"); 00090 } 00091 00092 // Sends the "onUnPause" event to all entities subscribed to this state. 00093 void GameState::onUnPause() 00094 { 00095 mBaseEntity->emitEvent("onUnPause"); 00096 } 00097 00098 // End of File