Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): none yet. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00032 #ifndef __SG_IOBJECT 00033 #define __SG_IOBJECT 00034 00035 #include "SG_QList.h" 00036 #include <vector> 00037 00038 // used for debugging: stage of the game engine main loop at which a Scenegraph modification is done 00039 enum SG_Stage 00040 { 00041 SG_STAGE_UNKNOWN = 0, 00042 SG_STAGE_NETWORK, 00043 SG_STAGE_NETWORK_UPDATE, 00044 SG_STAGE_PHYSICS1, 00045 SG_STAGE_PHYSICS1_UPDATE, 00046 SG_STAGE_CONTROLLER, 00047 SG_STAGE_CONTROLLER_UPDATE, 00048 SG_STAGE_ACTUATOR, 00049 SG_STAGE_ACTUATOR_UPDATE, 00050 SG_STAGE_ANIMATION_UPDATE, 00051 SG_STAGE_PHYSICS2, 00052 SG_STAGE_PHYSICS2_UPDATE, 00053 SG_STAGE_SCENE, 00054 SG_STAGE_RENDER, 00055 SG_STAGE_CONVERTER, 00056 SG_STAGE_CULLING, 00057 SG_STAGE_MAX 00058 }; 00059 00060 extern SG_Stage gSG_Stage; 00061 00062 inline void SG_SetActiveStage(SG_Stage stage) 00063 { 00064 gSG_Stage = stage; 00065 } 00066 00067 00068 00069 class SG_Controller; 00070 class SG_IObject; 00071 00072 typedef std::vector<SG_Controller*> SGControllerList; 00073 00074 typedef void* (*SG_ReplicationNewCallback)( 00075 SG_IObject* sgobject, 00076 void* clientobj, 00077 void* clientinfo 00078 ); 00079 00080 typedef void* (*SG_DestructionNewCallback)( 00081 SG_IObject* sgobject, 00082 void* clientobj, 00083 void* clientinfo 00084 ); 00085 00086 typedef void (*SG_UpdateTransformCallback)( 00087 SG_IObject* sgobject, 00088 void* clientobj, 00089 void* clientinfo 00090 ); 00091 00092 typedef bool (*SG_ScheduleUpdateCallback)( 00093 SG_IObject* sgobject, 00094 void* clientobj, 00095 void* clientinfo 00096 ); 00097 00098 typedef bool (*SG_RescheduleUpdateCallback)( 00099 SG_IObject* sgobject, 00100 void* clientobj, 00101 void* clientinfo 00102 ); 00103 00104 00120 struct SG_Callbacks 00121 { 00122 SG_Callbacks( 00123 ): 00124 m_replicafunc(NULL), 00125 m_destructionfunc(NULL), 00126 m_updatefunc(NULL), 00127 m_schedulefunc(NULL), 00128 m_reschedulefunc(NULL) 00129 { 00130 }; 00131 00132 SG_Callbacks( 00133 SG_ReplicationNewCallback repfunc, 00134 SG_DestructionNewCallback destructfunc, 00135 SG_UpdateTransformCallback updatefunc, 00136 SG_ScheduleUpdateCallback schedulefunc, 00137 SG_RescheduleUpdateCallback reschedulefunc 00138 ): 00139 m_replicafunc(repfunc), 00140 m_destructionfunc(destructfunc), 00141 m_updatefunc(updatefunc), 00142 m_schedulefunc(schedulefunc), 00143 m_reschedulefunc(reschedulefunc) 00144 { 00145 }; 00146 00147 SG_ReplicationNewCallback m_replicafunc; 00148 SG_DestructionNewCallback m_destructionfunc; 00149 SG_UpdateTransformCallback m_updatefunc; 00150 SG_ScheduleUpdateCallback m_schedulefunc; 00151 SG_RescheduleUpdateCallback m_reschedulefunc; 00152 }; 00153 00157 class SG_IObject : public SG_QList 00158 { 00159 private : 00160 00161 void* m_SGclientObject; 00162 void* m_SGclientInfo; 00163 SG_Callbacks m_callbacks; 00164 SGControllerList m_SGcontrollers; 00165 00166 public: 00167 virtual ~SG_IObject(); 00168 00169 00177 void 00178 AddSGController( 00179 SG_Controller* cont 00180 ); 00181 00187 void 00188 RemoveSGController( 00189 SG_Controller* cont 00190 ); 00191 00199 void 00200 RemoveAllControllers( 00201 ); 00202 00204 00213 SGControllerList& GetSGControllerList() 00214 { 00215 return m_SGcontrollers; 00216 } 00217 00221 SG_Callbacks& GetCallBackFunctions() 00222 { 00223 return m_callbacks; 00224 } 00225 00236 inline const void* GetSGClientObject() const 00237 { 00238 return m_SGclientObject; 00239 } 00240 00241 inline void* GetSGClientObject() 00242 { 00243 return m_SGclientObject; 00244 } 00245 00253 void SetSGClientObject(void* clientObject) 00254 { 00255 m_SGclientObject = clientObject; 00256 } 00257 00258 00259 /* needed for scene switching */ 00260 inline const void* GetSGClientInfo() const 00261 { 00262 return m_SGclientInfo; 00263 } 00264 inline void* GetSGClientInfo() 00265 { 00266 return m_SGclientInfo; 00267 } 00268 void SetSGClientInfo(void* clientInfo) 00269 { 00270 m_SGclientInfo = clientInfo; 00271 } 00272 00273 00280 void SetControllerTime(double time); 00281 00282 virtual 00283 void 00284 Destruct( 00285 ) = 0; 00286 00287 protected : 00288 00289 bool 00290 ActivateReplicationCallback( 00291 SG_IObject *replica 00292 ) 00293 { 00294 if (m_callbacks.m_replicafunc) 00295 { 00296 // Call client provided replication func 00297 if (m_callbacks.m_replicafunc(replica,m_SGclientObject,m_SGclientInfo) == NULL) 00298 return false; 00299 } 00300 return true; 00301 } 00302 00303 00304 void 00305 ActivateDestructionCallback( 00306 ) 00307 { 00308 if (m_callbacks.m_destructionfunc) 00309 { 00310 // Call client provided destruction function on this! 00311 m_callbacks.m_destructionfunc(this,m_SGclientObject,m_SGclientInfo); 00312 } 00313 else 00314 { 00315 // no callback but must still destroy the node to avoid memory leak 00316 delete this; 00317 } 00318 } 00319 00320 void 00321 ActivateUpdateTransformCallback( 00322 ) 00323 { 00324 if (m_callbacks.m_updatefunc) 00325 { 00326 // Call client provided update func. 00327 m_callbacks.m_updatefunc(this, m_SGclientObject, m_SGclientInfo); 00328 } 00329 } 00330 00331 bool 00332 ActivateScheduleUpdateCallback( 00333 ) 00334 { 00335 // HACK, this check assumes that the scheduled nodes are put on a DList (see SG_Node.h) 00336 // The early check on Empty() allows up to avoid calling the callback function 00337 // when the node is already scheduled for update. 00338 if (Empty() && m_callbacks.m_schedulefunc) 00339 { 00340 // Call client provided update func. 00341 return m_callbacks.m_schedulefunc(this, m_SGclientObject, m_SGclientInfo); 00342 } 00343 return false; 00344 } 00345 00346 void 00347 ActivateRecheduleUpdateCallback( 00348 ) 00349 { 00350 if (m_callbacks.m_reschedulefunc) 00351 { 00352 // Call client provided update func. 00353 m_callbacks.m_reschedulefunc(this, m_SGclientObject, m_SGclientInfo); 00354 } 00355 } 00356 00357 00358 SG_IObject( 00359 void* clientobj, 00360 void* clientinfo, 00361 SG_Callbacks& callbacks 00362 ); 00363 00364 SG_IObject( 00365 const SG_IObject &other 00366 ); 00367 00368 00369 #ifdef WITH_CXX_GUARDEDALLOC 00370 public: 00371 void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:SG_IObject"); } 00372 void operator delete( void *mem ) { MEM_freeN(mem); } 00373 #endif 00374 }; 00375 00376 #endif //__SG_IOBJECT 00377