00001 /* 00002 SagaEngine library 00003 Copyright (c) 2002-2006 Skalden Studio AS 00004 00005 This software is provided 'as-is', without any express or implied 00006 warranty. In no event will the authors be held liable for any 00007 damages arising from the use of this software. 00008 00009 Permission is granted to distribute the library under the terms of the 00010 Q Public License version 1.0. Be sure to read and understand the license 00011 before using the library. It should be included here, or you may read it 00012 at http://www.trolltech.com/products/qt/licenses/licensing/qpl 00013 00014 The original version of this library can be located at: 00015 http://www.sagaengine.com/ 00016 00017 Rune Myrland 00018 rune@skalden.com 00019 */ 00020 00021 00022 #ifndef InitListeners_hpp 00023 #define InitListeners_hpp 00024 00025 #include "InitListener.hpp" 00026 #include "sim.hpp" 00027 #include "../util/error/Log.hpp" 00028 00029 namespace se_core { 00030 00031 class _SeCoreExport InitListeners { 00032 enum { init_PRIORITY_ENGINE, init_ENGINE, init_LEVEL, init_GAME, init_START, init_COUNT }; 00033 public: 00034 00035 InitListeners() 00036 : listenerCount_(0), didAlreadyInitEngine_(false) { 00037 for(int i = 0; i < init_COUNT; ++i) { 00038 nextEngineInit_[i] = 0; 00039 } 00040 } 00041 00042 00046 void addListener(InitListener &l) { 00047 AssertFatal(listenerCount_ < MAX_LISTENERS, "Too many listeners. Ajust MAX_LISTENERS."); 00048 listeners_[ listenerCount_++ ] = &l; 00049 } 00050 00051 00055 void removeListener(InitListener &l) { 00056 for(int i = 0; i < listenerCount_; ++i) { 00057 if(listeners_[ i ] == &l) { 00058 listeners_[ i ] = listeners_[ --listenerCount_ ]; 00059 } 00060 } 00061 } 00062 00063 bool castPriorityInitEngineEvent() { 00064 int &i = nextEngineInit_[ init_PRIORITY_ENGINE ]; 00065 while(i < listenerCount_) { 00066 if(!listeners_[ i ]->priorityInitEngineEvent()) { 00067 castPriorityCleanupEngineEvent(); 00068 return false; 00069 } 00070 ++i; 00071 } 00072 return true; 00073 } 00074 00075 void castPriorityCleanupEngineEvent() { 00076 int &i = nextEngineInit_[ init_PRIORITY_ENGINE ]; 00077 while(i > 0) { 00078 --i; 00079 listeners_[ i ]->priorityCleanupEngineEvent(); 00080 } 00081 } 00082 00083 bool castInitEngineEvent() { 00084 int &i = nextEngineInit_[ init_ENGINE ]; 00085 while(i < listenerCount_) { 00086 if(!listeners_[ i ]->initEngineEvent()) { 00087 castCleanupEngineEvent(); 00088 return false; 00089 } 00090 ++i; 00091 } 00092 didAlreadyInitEngine_ = true; 00093 return true; 00094 } 00095 00096 void castCleanupEngineEvent() { 00097 int &i = nextEngineInit_[ init_ENGINE ]; 00098 while(i > 0) { 00099 --i; 00100 listeners_[ i ]->cleanupEngineEvent(); 00101 } 00102 } 00103 00104 00105 bool castInitLevelEvent() { 00106 int &i = nextEngineInit_[ init_LEVEL ]; 00107 while(i < listenerCount_) { 00108 if(!listeners_[ i ]->initLevelEvent()) { 00109 castCleanupLevelEvent(); 00110 return false; 00111 } 00112 ++i; 00113 } 00114 return true; 00115 } 00116 00117 void castCleanupLevelEvent() { 00118 int &i = nextEngineInit_[ init_LEVEL ]; 00119 while(i > 0) { 00120 --i; 00121 listeners_[ i ]->cleanupLevelEvent(); 00122 } 00123 } 00124 00125 00126 bool castInitGameEvent() { 00127 int &i = nextEngineInit_[ init_GAME ]; 00128 while(i < listenerCount_) { 00129 if(!listeners_[ i ]->initGameEvent()) { 00130 castCleanupGameEvent(); 00131 return false; 00132 } 00133 ++i; 00134 } 00135 return true; 00136 } 00137 00138 void castCleanupGameEvent() { 00139 int &i = nextEngineInit_[ init_GAME ]; 00140 while(i > 0) { 00141 --i; 00142 listeners_[ i ]->cleanupGameEvent(); 00143 } 00144 } 00145 00146 00147 bool castStartGameEvent() { 00148 int &i = nextEngineInit_[ init_START ]; 00149 while(i > 0) { 00150 --i; 00151 if(!listeners_[ i ]->startGameEvent()) { 00152 castStopGameEvent(); 00153 return false; 00154 } 00155 } 00156 return true; 00157 } 00158 00159 void castStopGameEvent() { 00160 int &i = nextEngineInit_[ init_START ]; 00161 while(i > 0) { 00162 --i; 00163 listeners_[ i ]->stopGameEvent(); 00164 } 00165 } 00166 00167 00171 void clear() { 00172 listenerCount_ = 0; 00173 didAlreadyInitEngine_ = false; 00174 } 00175 00176 00177 private: 00179 static const int MAX_LISTENERS = 10; 00181 InitListener* listeners_[ MAX_LISTENERS ]; 00183 short listenerCount_; 00184 00185 int nextEngineInit_[init_COUNT]; 00187 bool didAlreadyInitEngine_; 00188 }; 00189 00190 } 00191 00192 #endif
Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:11 2007 by Doxygen version 1.3.9.1.