Platform.cpp
Go to the documentation of this file.00001 //*** Platform.cpp *** 00002 00003 #include "Platform.h" 00004 #include "Platform_OS.h" 00005 #include "Platform_Time.h" 00006 #include "Platform_Sound.h" 00007 #include "Platform_Input.h" 00008 #include "Platform_FileSystem.h" 00009 #include "Platform_Screen.h" 00010 #include "Platform_Network.h" 00011 #include "Platform_3D.h" 00012 00013 // Singleton instance of the platform system 00014 Platform Platform::platform_; 00015 00016 // Instances of the platform subsystems 00017 Platform_OS* Platform::platform_OS_=0; 00018 Platform_Time* Platform::platform_Time_=0; 00019 Platform_Sound* Platform::platform_Sound_=0; 00020 Platform_Input* Platform::platform_Input_=0; 00021 Platform_FileSystem* Platform::platform_FileSystem_=0; 00022 Platform_Screen* Platform::platform_Screen_=0; 00023 Platform_Network* Platform::platform_Network_=0; 00024 Platform_3D* Platform::platform_3D_=0; 00025 PlatformEventListener* Platform::eventListeners_[64]; 00026 int Platform::eventListenerCount_=0; 00027 00028 00030 00031 Platform::Platform() 00032 { 00033 } 00034 00035 00037 00038 Platform::~Platform() 00039 { 00040 if (platform_Time_) 00041 { 00042 delete platform_Time_; 00043 platform_Time_=0; 00044 } 00045 00046 if (platform_Input_) 00047 { 00048 delete platform_Input_; 00049 platform_Input_=0; 00050 } 00051 00052 if (platform_FileSystem_) 00053 { 00054 delete platform_FileSystem_; 00055 platform_FileSystem_=0; 00056 } 00057 00058 if (platform_Network_) 00059 { 00060 delete platform_Network_; 00061 platform_Network_=0; 00062 } 00063 00064 if (platform_Sound_) 00065 { 00066 delete platform_Sound_; 00067 platform_Sound_=0; 00068 } 00069 00070 if (platform_Screen_) 00071 { 00072 delete platform_Screen_; 00073 platform_Screen_=0; 00074 } 00075 00076 if (platform_3D_) 00077 { 00078 delete platform_3D_; 00079 platform_3D_=0; 00080 } 00081 00082 if (platform_OS_) 00083 { 00084 delete platform_OS_; 00085 platform_OS_=0; 00086 } 00087 } 00088 00089 00090 //*** RegisterEventListener *** 00091 00092 void Platform::RegisterEventListener(PlatformEventListener* listener) 00093 { 00094 // Add the listener to the end of the listener array, if there's room 00095 if (eventListenerCount_<MaxEventListeners-1) 00096 { 00097 eventListeners_[eventListenerCount_]=listener; 00098 eventListenerCount_++; 00099 } 00100 } 00101 00102 00103 //*** UnregisterEventListener *** 00104 00105 void Platform::UnregisterEventListener(PlatformEventListener* listener) 00106 { 00107 // Go through all registered event listeners, to find the one we need to remove 00108 for (int i=0; i<eventListenerCount_; i++) 00109 { 00110 if (eventListeners_[i]==listener) 00111 { 00112 // Remove it from the list, and fill its slot with the last one 00113 eventListeners_[i]=eventListeners_[eventListenerCount_-1]; 00114 eventListenerCount_--; 00115 return; 00116 } 00117 } 00118 } 00119 00120 00121 //*** SendEvent_OsYield *** 00122 00123 void Platform::SendEvent_OsYield() 00124 { 00125 // Send the event to each registered listener 00126 for (int i=0; i<eventListenerCount_; i++) 00127 { 00128 eventListeners_[i]->OnOsYield(); 00129 } 00130 } 00131 00132 00133 //*** Event_CustomEvent *** 00134 00135 void Platform::SendEvent_CustomEvent(const char* eventId,void* userData) 00136 { 00137 // Send the event to each registered listener 00138 for (int i=0; i<eventListenerCount_; i++) 00139 { 00140 eventListeners_[i]->OnCustomEvent(eventId,userData); 00141 } 00142 } 00143 00144 00145 00146 //*** GetPlatform_OS *** 00147 00148 Platform_OS* Platform::GetPlatform_OS() 00149 { 00150 return platform_OS_; 00151 } 00152 00153 00154 //*** SetPlatform_OS *** 00155 00156 void Platform::SetPlatform_OS(Platform_OS* instance) 00157 { 00158 if (platform_OS_==0) 00159 { 00160 platform_OS_=instance; 00161 } 00162 else 00163 { 00164 delete instance; 00165 } 00166 } 00167 00168 00169 //*** GetPlatform_Time *** 00170 00171 Platform_Time* Platform::GetPlatform_Time() 00172 { 00173 return platform_Time_; 00174 } 00175 00176 00177 //*** SetPlatform_Time *** 00178 00179 void Platform::SetPlatform_Time(Platform_Time* instance) 00180 { 00181 if (platform_Time_==0) 00182 { 00183 platform_Time_=instance; 00184 } 00185 else 00186 { 00187 delete instance; 00188 } 00189 } 00190 00191 00192 //*** GetPlatform_Sound *** 00193 00194 Platform_Sound* Platform::GetPlatform_Sound() 00195 { 00196 return platform_Sound_; 00197 } 00198 00199 00200 //*** SetPlatform_Sound *** 00201 00202 void Platform::SetPlatform_Sound(Platform_Sound* instance) 00203 { 00204 if (platform_Sound_==0) 00205 { 00206 platform_Sound_=instance; 00207 } 00208 else 00209 { 00210 delete instance; 00211 } 00212 } 00213 00214 00215 //*** GetPlatform_Input *** 00216 00217 Platform_Input* Platform::GetPlatform_Input() 00218 { 00219 return platform_Input_; 00220 } 00221 00222 00223 //*** SetPlatform_Input *** 00224 00225 void Platform::SetPlatform_Input(Platform_Input* instance) 00226 { 00227 if (platform_Input_==0) 00228 { 00229 platform_Input_=instance; 00230 } 00231 else 00232 { 00233 delete instance; 00234 } 00235 } 00236 00237 00238 //*** GetPlatform_FileSystem *** 00239 00240 Platform_FileSystem* Platform::GetPlatform_FileSystem() 00241 { 00242 return platform_FileSystem_; 00243 } 00244 00245 00246 //*** SetPlatform_FileSystem *** 00247 00248 void Platform::SetPlatform_FileSystem(Platform_FileSystem* instance) 00249 { 00250 if (platform_FileSystem_==0) 00251 { 00252 platform_FileSystem_=instance; 00253 } 00254 else 00255 { 00256 delete instance; 00257 } 00258 } 00259 00260 00261 //*** GetPlatform_Screen *** 00262 00263 Platform_Screen* Platform::GetPlatform_Screen() 00264 { 00265 return platform_Screen_; 00266 } 00267 00268 00269 //*** SetPlatform_Screen *** 00270 00271 void Platform::SetPlatform_Screen(Platform_Screen* instance) 00272 { 00273 if (platform_Screen_==0) 00274 { 00275 platform_Screen_=instance; 00276 } 00277 else 00278 { 00279 delete instance; 00280 } 00281 } 00282 00283 00284 //*** GetPlatform_Network *** 00285 00286 Platform_Network* Platform::GetPlatform_Network() 00287 { 00288 return platform_Network_; 00289 } 00290 00291 00292 //*** SetPlatform_Network *** 00293 00294 void Platform::SetPlatform_Network(Platform_Network* instance) 00295 { 00296 if (platform_Network_==0) 00297 { 00298 platform_Network_=instance; 00299 } 00300 else 00301 { 00302 delete instance; 00303 } 00304 } 00305 00306 00307 //*** GetPlatform_3D *** 00308 00309 Platform_3D* Platform::GetPlatform_3D() 00310 { 00311 return platform_3D_; 00312 } 00313 00314 00315 //*** SetPlatform_3D *** 00316 00317 void Platform::SetPlatform_3D(Platform_3D* instance) 00318 { 00319 if (platform_3D_==0) 00320 { 00321 platform_3D_=instance; 00322 } 00323 else 00324 { 00325 delete instance; 00326 } 00327 }
Reproduction/republishing of any material on this site without permission is strictly prohibited.
