Permalink
Browse files

more STL-ization. may reduce performance slightly in worlds with few …

…models
  • Loading branch information...
1 parent af3b692 commit 5dee8f1251bb973d08b6a1998e0c7c6aecbe6068 rtv committed Jun 23, 2009
View
@@ -2,7 +2,7 @@
using namespace Stg;
Ancestor::Ancestor() :
- children( NULL ),
+ children(),
debug( false ),
puck_list( NULL ),
token( NULL )
@@ -13,13 +13,8 @@ Ancestor::Ancestor() :
Ancestor::~Ancestor()
{
- if( children )
- {
- for( GList* it = children; it; it=it->next )
- delete (Model*)it->data;
-
- g_list_free( children );
- }
+ FOR_EACH( it, children )
+ delete (*it);
}
void Ancestor::AddChild( Model* mod )
@@ -42,7 +37,7 @@ void Ancestor::AddChild( Model* mod )
mod->SetToken( buf );
- children = g_list_append( children, mod );
+ children.push_back( mod );
child_type_counts[mod->type]++;
@@ -52,7 +47,9 @@ void Ancestor::AddChild( Model* mod )
void Ancestor::RemoveChild( Model* mod )
{
child_type_counts[mod->type]--;
- children = g_list_remove( children, mod );
+
+ //children = g_list_remove( children, mod );
+ children.erase( remove( children.begin(), children.end(), mod ) );
}
Pose Ancestor::GetGlobalPose()
@@ -64,11 +61,12 @@ Pose Ancestor::GetGlobalPose()
void Ancestor::ForEachDescendant( stg_model_callback_t func, void* arg )
{
- for( GList* it=children; it; it=it->next ) {
- Model* mod = (Model*)it->data;
+ FOR_EACH( it, children )
+ {
+ Model* mod = (*it);
func( mod, arg );
mod->ForEachDescendant( func, arg );
- }
+ }
}
@@ -30,59 +30,34 @@ void BlockGroup::AppendBlock( Block* block )
void BlockGroup::Clear()
{
-// while( blocks )
-// {
-// delete (Block*)blocks->data;
-// blocks = blocks->next;
-// }
-
- //g_list_free( blocks );
- //blocks = NULL;
-
- for( vector<Block*>::iterator it( blocks.begin() );
- it != blocks.end();
- ++it )
+ FOR_EACH( it, blocks )
delete *it;
-
+
blocks.clear();
}
-
void BlockGroup::SwitchToTestedCells()
{
// confirm the tentative pose for all blocks
- //LISTMETHOD( blocks, Block*, SwitchToTestedCells );
-
- for( vector<Block*>::iterator it( blocks.begin() );
- it != blocks.end();
- ++it )
- (*it)->SwitchToTestedCells();
+ FOR_EACH( it, blocks )
+ (*it)->SwitchToTestedCells();
}
GList* BlockGroup::AppendTouchingModels( GList* list )
{
- for( vector<Block*>::iterator it( blocks.begin() );
- it != blocks.end();
- ++it )
- list = (*it)->AppendTouchingModels( list );
-
+ FOR_EACH( it, blocks )
+ list = (*it)->AppendTouchingModels( list );
return list;
}
Model* BlockGroup::TestCollision()
{
Model* hitmod = NULL;
- for( vector<Block*>::iterator it( blocks.begin() );
- it != blocks.end();
- ++it )
+ FOR_EACH( it, blocks )
if( (hitmod = (*it)->TestCollision()))
break; // bail on the earliest collision
-// for( GList* it=blocks; it; it = it->next )
-// if( (hitmod = ((Block*)it->data)->TestCollision()))
-// break; // bail on the earliest collision
-
return hitmod; // NULL if no collision
}
@@ -98,10 +73,7 @@ void BlockGroup::CalcSize()
size.z = 0.0; // grow to largest z we see
- for( vector<Block*>::iterator it( blocks.begin() );
- it != blocks.end();
- ++it )
- // for( GList* it=blocks; it; it=it->next ) // examine all the blocks
+ FOR_EACH( it, blocks )
{
// examine all the points in the polygon
Block* block = *it;
@@ -132,22 +104,14 @@ void BlockGroup::CalcSize()
void BlockGroup::Map()
{
- for( std::vector<Block*>::iterator it( blocks.begin() );
- it != blocks.end();
- ++it )
+ FOR_EACH( it, blocks )
(*it)->Map();
-
- //LISTMETHOD( blocks, Block*, Map );
}
void BlockGroup::UnMap()
{
- for( std::vector<Block*>::iterator it( blocks.begin() );
- it != blocks.end();
- ++it )
+ FOR_EACH( it, blocks )
(*it)->UnMap();
-
- //LISTMETHOD( blocks, Block*, UnMap );
}
void BlockGroup::DrawSolid( const Geom & geom )
@@ -162,11 +126,8 @@ void BlockGroup::DrawSolid( const Geom & geom )
glTranslatef( -offset.x, -offset.y, -offset.z );
- for( std::vector<Block*>::iterator it( blocks.begin() );
- it != blocks.end();
- ++it )
+ FOR_EACH( it, blocks )
(*it)->DrawSolid();
- // LISTMETHOD( blocks, Block*, DrawSolid );
glPopMatrix();
}
@@ -180,12 +141,9 @@ void BlockGroup::DrawFootPrint( const Geom & geom )
geom.size.z / size.z );
glTranslatef( -offset.x, -offset.y, -offset.z );
-
- for( std::vector<Block*>::iterator it( blocks.begin() );
- it != blocks.end();
- ++it )
+
+ FOR_EACH( it, blocks )
(*it)->DrawFootPrint();
-// LISTMETHOD( blocks, Block*, DrawFootPrint);
glPopMatrix();
}
@@ -222,10 +180,7 @@ void BlockGroup::BuildDisplayList( Model* mod )
mod->PushColor( mod->color );
- for( vector<Block*>::iterator it( blocks.begin() );
- it != blocks.end();
- ++it )
- //for( GList* it=blocks; it; it=it->next )
+ FOR_EACH( it, blocks )
{
Block* blk = (*it);
@@ -250,10 +205,7 @@ void BlockGroup::BuildDisplayList( Model* mod )
stg_color_unpack( mod->color, &r, &g, &b, &a );
mod->PushColor( stg_color_pack( r/2.0, g/2.0, b/2.0, a ));
- for( vector<Block*>::iterator it( blocks.begin() );
- it != blocks.end();
- ++it )
- //for( GList* it=blocks; it; it=it->next )
+ FOR_EACH( it, blocks )
{
Block* blk = *it;
@@ -365,9 +317,6 @@ void BlockGroup::Rasterize( uint8_t* data,
stg_meters_t cellwidth,
stg_meters_t cellheight )
{
- for( vector<Block*>::iterator it( blocks.begin() );
- it != blocks.end();
- ++it )
- //for( GList* it = blocks; it; it=it->next )
+ FOR_EACH( it, blocks )
(*it)->Rasterize( data, width, height, cellwidth, cellheight );
}
View
@@ -204,9 +204,9 @@ Model* Canvas::getModel( int x, int y )
// render all top-level, draggable models in a color that is their
// id
- for( GList* it= world->World::children; it; it=it->next )
+ FOR_EACH( it, world->World::children )
{
- Model* mod = (Model*)it->data;
+ Model* mod = (*it);
if( mod->gui.mask & (STG_MOVE_TRANS | STG_MOVE_ROT ))
{
@@ -694,8 +694,9 @@ void Canvas::resetCamera()
float max_x = 0, max_y = 0, min_x = 0, min_y = 0;
//TODO take orrientation ( `a' ) and geom.pose offset into consideration
- for( GList* it=world->World::children; it; it=it->next ) {
- Model* ptr = (Model*) it->data;
+ FOR_EACH( it, world->World::children )
+ {
+ Model* ptr = (*it);
Pose pose = ptr->GetPose();
Geom geom = ptr->GetGeom();
@@ -1012,12 +1013,12 @@ void Canvas::renderFrame()
// draw the model-specific visualizations
if( showData ) {
if ( ! visualizeAll ) {
- for( GList* it = world->World::children; it; it=it->next )
- ((Model*)it->data)->DataVisualizeTree( current_camera );
+ FOR_EACH( it, world->World::children )
+ (*it)->DataVisualizeTree( current_camera );
}
else if ( selected_models ) {
- for( GList* it = selected_models; it; it=it->next )
- ((Model*)it->data)->DataVisualizeTree( current_camera );
+ FOR_EACH( it, world->World::children )
+ (*it)->DataVisualizeTree( current_camera );
}
else if ( last_selection ) {
last_selection->DataVisualizeTree( current_camera );
Oops, something went wrong.

0 comments on commit 5dee8f1

Please sign in to comment.