Changeset 3231 in orxonox.OLD for orxonox/trunk/src
- Timestamp:
- Dec 20, 2004, 12:49:07 AM (20 years ago)
- Location:
- orxonox/trunk/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/campaign.cc
r3225 r3231 181 181 ListTemplate<StoryEntity>* l; 182 182 StoryEntity* entity = NULL; 183 l = this->entities->get _next();183 l = this->entities->getNext(); 184 184 while( l != NULL) 185 185 { 186 entity = l->get _object();187 l = l->get _next();186 entity = l->getObject(); 187 l = l->getNext(); 188 188 int id = entity->getStoryID(); 189 189 //printf("Campaing::getStoryEntity() - now looping, found entity nr=%i\n", id); -
orxonox/trunk/src/collision.cc
r2190 r3231 28 28 CollisionCluster::CollisionCluster (float rad = 1.0, Vector mid = Vector(0,0,0)) 29 29 { 30 root = (CC _Tree*) malloc( sizeof( CC_Tree));30 root = (CCTree*) malloc( sizeof( CCTree)); 31 31 root->n = 0; 32 32 root->data.ID = 0; … … 62 62 } 63 63 64 root = load _CC_Tree (stream);64 root = loadCCTree (stream); 65 65 fclose (stream); 66 66 } … … 71 71 CollisionCluster::~CollisionCluster () 72 72 { 73 free _CC_Tree(root);73 freeCCTree(root); 74 74 } 75 75 … … 85 85 stream = fopen( filename, "wb"); 86 86 if( stream == NULL) return -1; 87 r = save _CC_Tree(root, stream);87 r = saveCCTree(root, stream); 88 88 fclose (stream); 89 89 return r; … … 99 99 \return true on collision, false otherwise. If true is returned, the flag in ahitflags that symbolises the hit subsphere is set, and impactpoint is set to the Location where the intersection occured 100 100 */ 101 bool check _trace (const Placement* pa, const CollisionCluster* a, unsigned long* ahitflags, const Line* trace, Vector* impactpoint)102 { 103 CC _Tree* t;101 bool checkTrace (const Placement* pa, const CollisionCluster* a, unsigned long* ahitflags, const Line* trace, Vector* impactpoint) 102 { 103 CCTree* t; 104 104 if( (t = a->root) == NULL) return false; 105 105 106 return cctree _trace( pa, t, ahitflags, trace, impactpoint);106 return cctreeTrace( pa, t, ahitflags, trace, impactpoint); 107 107 } 108 108 … … 118 118 If true is returned, all flags in ahitflags and bhitflags that symbolize intersecting subspheres in the respective CollisionCluster are set 119 119 */ 120 bool check _collision (const Placement* pa, const CollisionCluster* a, unsigned long* ahitflags, const Placement* pb, const CollisionCluster* b, unsigned long* bhitflags)121 { 122 CC _Tree* ta, *tb;120 bool checkCollision (const Placement* pa, const CollisionCluster* a, unsigned long* ahitflags, const Placement* pb, const CollisionCluster* b, unsigned long* bhitflags) 121 { 122 CCTree* ta, *tb; 123 123 if( (ta = a->root) == NULL) return false; 124 124 if( (tb = b->root) == NULL) return false; 125 125 126 return cctree _iterate(pa, ta, ahitflags, pb, tb, bhitflags);126 return cctreeIterate(pa, ta, ahitflags, pb, tb, bhitflags); 127 127 } 128 128 … … 135 135 \return true on intersection, false otherwise 136 136 */ 137 bool sphere _sphere_collision( Vector m1, float r1, Vector m2, float r2)137 bool sphereSphereCollision( Vector m1, float r1, Vector m2, float r2) 138 138 { 139 139 if ((m1-m2).len() < r1+r2) return true; … … 149 149 \return true on intersection, false otherwise. If true is returned, impactpoint is set to the loaction where the intersection occured 150 150 */ 151 bool trace _sphere_collision( Vector m, float r, const Line* l, Vector* impactpoint)151 bool traceSphereCollision( Vector m, float r, const Line* l, Vector* impactpoint) 152 152 { 153 153 float A, B, C, D, t[2]; … … 176 176 } 177 177 178 bool cctree _iterate(const Placement* pa, CC_Tree* ta, unsigned long* ahitflags, const Placement* pb, CC_Tree* tb, unsigned long* bhitflags)178 bool cctreeIterate(const Placement* pa, CCTree* ta, unsigned long* ahitflags, const Placement* pb, CCTree* tb, unsigned long* bhitflags) 179 179 { 180 180 bool r = false; … … 182 182 Vector mra = pa->r + pa->w.apply(ta->m); 183 183 Vector mrb = pb->r + pb->w.apply(tb->m); 184 CC _Tree* use_a, *use_b;185 186 if( use _a == NULL || use_b== NULL) return false;187 188 if( sphere _sphere_collision( mra, ta->r, mrb, tb->r))184 CCTree* useA, *useB; 185 186 if( useA == NULL || useB == NULL) return false; 187 188 if( sphereSphereCollision( mra, ta->r, mrb, tb->r)) 189 189 { 190 190 if( ta->n == 0 && tb->n == 0) … … 196 196 for( ia = 0; ia < ta->n || ta->n == 0; ia++) 197 197 { 198 if( ta->n == 0) use _a= ta;199 else use _a= ta->data.b[ia];198 if( ta->n == 0) useA = ta; 199 else useA = ta->data.b[ia]; 200 200 for( ib = 0; ib < tb->n || ta->n == 0; ib++) 201 201 { 202 if( ta->n == 0) use _b= ta;203 else use _b= ta->data.b[ib];202 if( ta->n == 0) useB = ta; 203 else useB = ta->data.b[ib]; 204 204 205 r = r || cctree _iterate( pa, use_a, ahitflags, pb, use_b, bhitflags);205 r = r || cctreeIterate( pa, useA, ahitflags, pb, useB, bhitflags); 206 206 207 207 if( tb->n == 0) break; … … 233 233 234 234 /** 235 \brief frees the memory allocated in a CC _Tree236 */ 237 void free _CC_Tree( CC_Tree* tree)235 \brief frees the memory allocated in a CCTree 236 */ 237 void freeCCTree( CCTree* tree) 238 238 { 239 239 if (tree == NULL) return; 240 240 for (int i = 0; i < tree->n; i++) 241 241 { 242 free _CC_Tree(tree->data.b[i]);242 freeCCTree(tree->data.b[i]); 243 243 } 244 244 free( tree); … … 246 246 247 247 /** 248 \brief loads a CC _Tree from a stream249 */ 250 CC _Tree* load_CC_Tree (FILE* stream)251 { 252 CC _Tree* tree = NULL;253 CC _Tree** branches = NULL;248 \brief loads a CCTree from a stream 249 */ 250 CCTree* loadCCTree (FILE* stream) 251 { 252 CCTree* tree = NULL; 253 CCTree** branches = NULL; 254 254 float buf[4]; 255 255 unsigned long n; … … 267 267 else 268 268 { 269 branches = (CC _Tree**)malloc( sizeof(CC_Tree*) * n);269 branches = (CCTree**)malloc( sizeof(CCTree*) * n); 270 270 for( int i = 0; i < n; i++) 271 271 { 272 if ((branches[i] = load _CC_Tree (stream)) == NULL)272 if ((branches[i] = loadCCTree (stream)) == NULL) 273 273 { 274 274 for( int j = 0; j < i; j++) 275 275 { 276 free _CC_Tree (branches[j]);277 free 276 freeCCTree (branches[j]); 277 free(branches); 278 278 return NULL; 279 279 } … … 283 283 284 284 // assemble 285 tree = (CC _Tree*) malloc (sizeof(CC_Tree));285 tree = (CCTree*) malloc (sizeof(CCTree)); 286 286 tree->m.x = buf[0]; 287 287 tree->m.y = buf[1]; … … 297 297 298 298 /** 299 \brief saves a CC _Tree to a stream300 */ 301 int save _CC_Tree (CC_Tree* tree, FILE* stream)299 \brief saves a CCTree to a stream 300 */ 301 int saveCCTree (CCTree* tree, FILE* stream) 302 302 { 303 303 float buf[4]; … … 321 321 for( int i = 0; i < tree->n; i++) 322 322 { 323 if ( save _CC_Tree (tree->data.b[i], stream) == -1) return -1;323 if ( saveCCTree (tree->data.b[i], stream) == -1) return -1; 324 324 } 325 325 } … … 329 329 } 330 330 331 bool cctree _trace( const Placement* p, CC_Tree* t, unsigned long* hitflags, const Line* trace, Vector* impactpoint)331 bool cctreetrace( const Placement* p, CCTree* t, unsigned long* hitflags, const Line* trace, Vector* impactpoint) 332 332 { 333 333 bool r = false; 334 334 int i; 335 335 Vector mr = p->r + p->w.apply (t->m); 336 CC _Tree* use_t;336 CCTree* useT; 337 337 Vector* ips; 338 338 unsigned long* hfs; 339 339 340 if( trace _sphere_collision (mr, t->r, trace, impactpoint))340 if( traceSphereCollision (mr, t->r, trace, impactpoint)) 341 341 { 342 342 if( t->n == 0) … … 352 352 for (i = 0; i < t->n; i++) 353 353 { 354 r = r || cctree _trace (p, t->data.b[i], &(hfs[i]), trace, &(ips[i]));354 r = r || cctreeTrace (p, t->data.b[i], &(hfs[i]), trace, &(ips[i])); 355 355 } 356 356 if( r) -
orxonox/trunk/src/collision.h
r3224 r3231 14 14 15 15 //! Tree structure used by the CollisionCluster 16 typedef struct CC _Tree16 typedef struct CCTree 17 17 { 18 18 unsigned long n; 19 19 union 20 20 { 21 struct CC _Tree** b;21 struct CCTree** b; 22 22 unsigned long ID; 23 23 } data; 24 24 float r; 25 25 Vector m; 26 } CC _Tree;26 } CCTree; 27 27 28 28 //! Basic collision detection class … … 42 42 class CollisionCluster { 43 43 44 CC _Tree* root;44 CCTree* root; 45 45 46 46 … … 52 52 int store (char* filename); 53 53 54 friend bool cctree _trace( const Placement* p, CC_Tree* t, unsigned long* hitflags, const Line* trace, Vector* impactpoint);55 friend bool cctree _iterate(const Placement* pa, CC_Tree* ta, unsigned long* ahitflags, const Placement* pb, CC_Tree* tb, unsigned long* bhitflags);56 friend bool check _trace (const Placement* pa, const CollisionCluster* a, unsigned long* ahitflags, const Line* trace, Vector* impactpoint);57 friend bool check _collision (const Placement* pa, const CollisionCluster* a, unsigned long* ahitflags, const Placement* pb, const CollisionCluster* b, unsigned long* bhitflags);54 friend bool cctreeTrace( const Placement* p, CCTree* t, unsigned long* hitflags, const Line* trace, Vector* impactpoint); 55 friend bool cctreeIterate(const Placement* pa, CCTree* ta, unsigned long* ahitflags, const Placement* pb, CCTree* tb, unsigned long* bhitflags); 56 friend bool checkTrace (const Placement* pa, const CollisionCluster* a, unsigned long* ahitflags, const Line* trace, Vector* impactpoint); 57 friend bool checkCollision (const Placement* pa, const CollisionCluster* a, unsigned long* ahitflags, const Placement* pb, const CollisionCluster* b, unsigned long* bhitflags); 58 58 }; 59 59 60 bool sphere _sphere_collision( Vector m1, float r1, Vector m2, float r2);61 bool trace _sphere_collision( Vector m, float r, const Line* l, Vector* impactpoint);60 bool sphereSphereCollision( Vector m1, float r1, Vector m2, float r2); 61 bool traceSphereCollision( Vector m, float r, const Line* l, Vector* impactpoint); 62 62 63 63 void setflag( unsigned long* flags, unsigned long ID); 64 64 65 void free _CC_Tree( CC_Tree* tree);66 CC _Tree* load_CC_Tree (FILE* stream);67 int save _CC_Tree (CC_Tree* tree, FILE* stream);65 void freeCCTree( CCTree* tree); 66 CCTree* loadCCTree (FILE* stream); 67 int saveCCTree (CCTree* tree, FILE* stream); 68 68 69 69 #endif /* _COLLISION_H */ -
orxonox/trunk/src/ini_parser.cc
r2551 r3231 25 25 IniParser::IniParser (char* filename) 26 26 { 27 28 29 open_file(filename);27 stream = NULL; 28 bInSection = false; 29 openFile(filename); 30 30 } 31 31 … … 35 35 IniParser::~IniParser () 36 36 { 37 37 if( stream != NULL) fclose (stream); 38 38 } 39 39 40 40 /** 41 42 43 41 \brief opens another file to parse 42 \param filename: path and name of the new file to parse 43 \return zero on success or -1 if an error occured; 44 44 */ 45 int IniParser::open _file( char* filename)45 int IniParser::openFile( char* filename) 46 46 { 47 48 49 50 51 52 53 54 55 47 if( filename == NULL) return -1; 48 if( stream != NULL) fclose (stream); 49 if( (stream = fopen (filename, "r")) == NULL) 50 { 51 printf("IniParser could not open %s\n", filename); 52 return -1; 53 } 54 bInSection = false; 55 return 0; 56 56 } 57 57 58 58 /** 59 60 61 59 \brief set the parsing cursor to the specified section 60 \param section: the name of the section to set the cursor to 61 \return zero on success or -1 if the section could not be found 62 62 */ 63 int IniParser::get _section( char* section)63 int IniParser::getSection( char* section) 64 64 { 65 65 bInSection = false; … … 95 95 96 96 /** 97 98 99 100 97 \brief gets the next VarName=VarValue pair from the parsing stream 98 \param name: a pointer to a buffer to store the name of the entry 99 \param value: a pointer to a buffer to store the value of the entry 100 \return zero if the buffers have been filled with data or -1 if there are no entries left in the current section 101 101 */ 102 int IniParser::next _var( char* name, char* value)102 int IniParser::nextVar( char* name, char* value) 103 103 { 104 if( stream == NULL) 104 if( stream == NULL) 105 { 106 bInSection = false; 107 return -1; 108 } 109 if( !bInSection) return -1; 110 111 char linebuffer[PARSELINELENGHT]; 112 char* ptr; 113 114 while( !feof( stream)) 115 { 116 // get next line 117 fgets (linebuffer, PARSELINELENGHT, stream); 118 // remove newline char 119 if( (ptr = strchr( linebuffer, '\n')) != NULL) *ptr = 0; 120 if( linebuffer[0] == '[') 105 121 { 106 107 122 bInSection = false; 123 return -1; 108 124 } 109 if( !bInSection) return -1; 110 111 char linebuffer[PARSELINELENGHT]; 112 char* ptr; 113 114 while( !feof( stream)) 125 if( (ptr = strchr( linebuffer, '=')) != NULL) 115 126 { 116 // get next line 117 fgets (linebuffer, PARSELINELENGHT, stream); 118 // remove newline char 119 if( (ptr = strchr( linebuffer, '\n')) != NULL) *ptr = 0; 120 if( linebuffer[0] == '[') 121 { 122 bInSection = false; 123 return -1; 124 } 125 if( (ptr = strchr( linebuffer, '=')) != NULL) 126 { 127 if( ptr == linebuffer) continue; 128 strcpy (value, &ptr[1]); 129 strncpy (name, linebuffer, strlen (linebuffer) - strlen (value) - 1); 130 return 0; 131 } 127 if( ptr == linebuffer) continue; 128 strcpy (value, &ptr[1]); 129 strncpy (name, linebuffer, strlen (linebuffer) - strlen (value) - 1); 130 return 0; 132 131 } 133 return -1; 132 } 133 return -1; 134 134 } 135 135 136 136 /** 137 138 139 140 141 142 143 144 137 \brief directly acesses an entry in a section 138 \param name: the name of the entry to find 139 \param section: the section where the entry is to be found 140 \param defvalue: what should be returned in case the entry cannot be found 141 \return a pointer to a buffer conatining the value of the specified entry. This buffer will contain the data specified in defvalue in case the entry wasn't found 142 143 The returned pointer points to an internal buffer, so do not free it on your own. Do not give a NULL pointer to defvalue, this will certainly 144 lead to unwanted behaviour. 145 145 */ 146 char* IniParser::get _var( char* name, char* section, char* defvalue = "")146 char* IniParser::getVar( char* name, char* section, char* defvalue = "") 147 147 { 148 strcpy (internbuf, defvalue); 149 if( get_section (section) == -1) return internbuf; 150 151 char namebuf[PARSELINELENGHT]; 152 char valuebuf[PARSELINELENGHT]; 153 154 while( next_var (namebuf, valuebuf) != -1) 148 strcpy (internbuf, defvalue); 149 if( getSection (section) == -1) return internbuf; 150 151 char namebuf[PARSELINELENGHT]; 152 char valuebuf[PARSELINELENGHT]; 153 154 while( nextVar (namebuf, valuebuf) != -1) 155 { 156 if( !strcmp (name, namebuf)) 155 157 { 156 if( !strcmp (name, namebuf)) 157 { 158 strcpy (internbuf, valuebuf); 159 return internbuf; 160 } 158 strcpy (internbuf, valuebuf); 159 return internbuf; 161 160 } 162 return internbuf; 161 } 162 return internbuf; 163 163 } -
orxonox/trunk/src/ini_parser.h
r3224 r3231 29 29 ~IniParser (); 30 30 31 char* get _var( char* name, char* section, char* defvalue);32 int open _file( char* name);33 int get _section( char* section);34 int next _var( char* name, char* value);31 char* getVar( char* name, char* section, char* defvalue); 32 int openFile( char* name); 33 int getSection( char* section); 34 int nextVar( char* name, char* value); 35 35 }; 36 36
Note: See TracChangeset
for help on using the changeset viewer.