Files Classes Functions Hierarchy
00001 #ifndef GOBJBASE_H 00002 #define GOBJBASE_H 00003 00004 #include <cassert> 00005 #include <deque> 00006 #include <vector> 00007 #include <iostream> 00008 using namespace std; 00009 00010 #include <GL/glut.h> 00011 #include <GL/gl.h> 00012 00013 #include <fnobjTfn.h> 00014 #include <point.h> 00015 #include <print.h> 00016 #include <typedefs.h> 00017 00018 #define gobjpush(x) assert(gobjContainer::global != 0); gobj::global->push(x) 00019 #define DOUBLECOLOR(uR,uG,uB) 1.0*uR/256.0, 1.0*uG/256.0, 1.0*uB/256.0 00020 00021 #include <gobjdebug.h> 00022 00023 00024 00025 class gobjContainer; 00026 00027 /* 00028 \brief Scene base class. 00029 00030 It is assumed that the scene is a vector of gobj pointers. 00031 ie a stack. See gobjContainer. I believe a stack is more 00032 general and powerful than a scene graph which is assumed 00033 to be a tree. A vector contains trees as a subset. 00034 00035 An important application is that vectors can be easily 00036 indexed with integers. Contrast this with a scene graph 00037 which is often implemented with pointers. 00038 00039 All graphics objects can draw (unless they exist in a gobj 00040 stack for other purposes). 00041 00042 All graphics sees the universal graphics stream 00043 gobj::global. (This is currently a single threaded design, 00044 but this may be changed). 00045 */ 00046 class gobj 00047 { 00048 public: 00049 00051 static gobjContainer * global; 00052 00054 static void globaldisplaylist(uintc id); 00055 00057 virtual void draw() = 0; 00058 00060 virtual ~gobj(); 00061 00062 }; 00063 00075 class gobjGlobal 00076 { 00077 gobjContainer * const globalnew; 00078 gobjGlobal() : globalnew(0) {} 00079 public: 00080 00082 gobjGlobal(gobjContainer * const globalnew_); 00083 // TODO 00084 //gobjGlobal(gobjContainer& globalnew_); 00085 00087 ~gobjGlobal(); 00088 }; 00089 00090 00100 template< typename T > 00101 class gobjglCallList : public gobj 00102 { 00103 public: 00104 00106 T listid; 00107 00109 gobjglCallList(T listid_) 00110 : listid(listid_) {} 00111 00113 void draw() 00114 { GOBJDEBUGCODE glCallList(listid); } 00115 00116 }; 00117 00118 00125 template< class T > 00126 class gobjcallback : public gobj 00127 { 00128 fnobj0Tfn<T,void> fobj; 00129 public: 00130 00131 typedef void (T::*Fptr)(); 00132 00134 gobjcallback( T & data_, Fptr fn_) 00135 : fobj(data_,fn_) {} 00136 00138 void draw() 00139 { GOBJDEBUGCODE fobj(); } 00140 00141 }; 00142 00145 template< class T > 00146 gobjcallback<T>* gobjcallbackcreatenew(T & data_, void (T::*fn_)() ) 00147 { return new gobjcallback<T>(data_,fn_); } 00148 00149 00171 class gobjContainer : public gobj 00172 { 00173 public: 00174 00177 void set() 00178 { gobj::global = this; } 00179 00181 static vector< gobjContainer * > globalvec; 00182 00185 void globalpush() 00186 { globalvec.push_back( gobj::global); set(); } 00187 00189 static void globalpop(); 00190 00192 vector<gobj*> vg; 00193 00195 bool cleanup; 00196 00198 gobjContainer(); 00200 gobjContainer(boolc cleanup_); 00202 ~gobjContainer(); 00203 00205 void nuke(); 00206 00208 boolc kill(uintc k); 00210 boolc kill(gobj* const targ); 00211 00213 void draw(); 00214 00216 void push(gobj * g) 00217 { assert(g!=0); vg.push_back(g); } 00219 template< class T > 00220 void pushcallback(T & data_, void (T::*fn_)() ) 00221 { push(new gobjcallback<T>(data_,fn_)); } 00222 00225 gobjglCallList<GLuint> * displaylistcreatenew(uint id); 00226 00231 void displaylist(uintc id); 00232 }; 00233 00234 class gobjContainerdeque : public gobj 00235 { 00236 public: 00237 00238 void push_front(gobj* g) 00239 { assert(g!=0); vg.push_front(g); } 00240 void push_back(gobj* g) 00241 { assert(g!=0); vg.push_back(g); } 00242 00244 void draw(); 00245 00247 deque<gobj*> vg; 00248 00251 bool cleanup; 00252 00254 gobjContainerdeque() 00255 : cleanup(true) {}; 00256 00260 gobjContainerdeque(boolc cleanup_) 00261 : cleanup(cleanup_) {}; 00263 ~gobjContainerdeque(); 00264 00267 void nuke(); 00268 00269 }; 00270 00271 template< typename BOOL=bool > 00272 class gobjSwitch; 00273 00283 class gobjContainerSwitch : public gobj 00284 { 00285 public: 00286 00288 gobjContainer gcontainer; 00290 vector< gobjSwitch<>* > gswitch; 00291 00294 gobjContainerSwitch(boolc cleanup_); 00295 00297 void draw() 00298 { GOBJDEBUGCODE gcontainer.draw(); } 00299 00302 void nuke(); 00304 ~gobjContainerSwitch(); 00305 00307 gobjSwitch<> * push(gobj* g); 00308 }; 00309 00310 00330 class gobjContainerPrePost : public gobjContainer 00331 { 00332 public: 00333 00335 gobjContainer pre; 00337 gobjContainer post; 00338 00340 void draw(); 00341 00343 gobjContainerPrePost(boolc cleanup_=false) 00344 : gobjContainer(cleanup_), pre(cleanup_), post(cleanup_) {} 00345 00346 }; 00347 00348 00357 template< typename BOOL > 00358 class gobjSwitch : public gobj 00359 { 00360 public: 00361 00363 gobj * x; 00364 00366 BOOL isdrawn; 00368 bool cleanup; 00369 00373 gobjSwitch 00374 ( 00375 gobj * x_, 00376 BOOL isdrawn_, 00377 boolc cleanup_=true 00378 ) 00379 : x(x_), isdrawn(isdrawn_), cleanup(cleanup_) 00380 { } 00381 00383 ~gobjSwitch() 00384 { if (cleanup==false) return; delete x; x=0; } 00385 00387 void draw() 00388 { GOBJDEBUGCODE assert(x!=0); if (isdrawn) x->draw(); } 00389 00391 void toggle() 00392 { assert(x!=0); isdrawn = ! isdrawn; } 00393 00394 }; 00395 00396 00403 template< class T > 00404 class gobjcallbackcontainer : public gobj 00405 { 00406 fnobj1Tfn<T,void,gobjContainer&> fobj; 00407 public: 00408 00409 typedef void (T::*Fptr)(gobjContainer&); 00410 00412 gobjcallbackcontainer( T & data_, Fptr fn_) 00413 : fobj(data_,fn_) {} 00414 00416 void draw() 00417 { 00418 GOBJDEBUGCODE 00419 gobjContainer* shp = new gobjContainer(true); 00420 00421 fobj(*shp); 00422 gobjpush(shp); 00423 } 00424 00425 }; 00426 00429 template< class T > 00430 gobjcallbackcontainer<T>* gobjcallbackcontainercreatenew 00431 ( 00432 T & data_, 00433 void (T::*fn_)(gobjContainer&) 00434 ) 00435 { return new gobjcallbackcontainer<T>(data_,fn_); } 00436 00437 00438 00439 #endif 00440
1.5.8