Skip to content

Commit

Permalink
more STL-ization. may reduce performance slightly in worlds with few …
Browse files Browse the repository at this point in the history
…models
  • Loading branch information
rtv committed Jun 23, 2009
1 parent af3b692 commit 5dee8f1
Show file tree
Hide file tree
Showing 10 changed files with 426 additions and 486 deletions.
24 changes: 11 additions & 13 deletions libstage/ancestor.cc
Expand Up @@ -2,7 +2,7 @@
using namespace Stg; using namespace Stg;


Ancestor::Ancestor() : Ancestor::Ancestor() :
children( NULL ), children(),
debug( false ), debug( false ),
puck_list( NULL ), puck_list( NULL ),
token( NULL ) token( NULL )
Expand All @@ -13,13 +13,8 @@ Ancestor::Ancestor() :


Ancestor::~Ancestor() Ancestor::~Ancestor()
{ {
if( children ) FOR_EACH( it, children )
{ delete (*it);
for( GList* it = children; it; it=it->next )
delete (Model*)it->data;

g_list_free( children );
}
} }


void Ancestor::AddChild( Model* mod ) void Ancestor::AddChild( Model* mod )
Expand All @@ -42,7 +37,7 @@ void Ancestor::AddChild( Model* mod )


mod->SetToken( buf ); mod->SetToken( buf );


children = g_list_append( children, mod ); children.push_back( mod );


child_type_counts[mod->type]++; child_type_counts[mod->type]++;


Expand All @@ -52,7 +47,9 @@ void Ancestor::AddChild( Model* mod )
void Ancestor::RemoveChild( Model* mod ) void Ancestor::RemoveChild( Model* mod )
{ {
child_type_counts[mod->type]--; 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() Pose Ancestor::GetGlobalPose()
Expand All @@ -64,11 +61,12 @@ Pose Ancestor::GetGlobalPose()


void Ancestor::ForEachDescendant( stg_model_callback_t func, void* arg ) void Ancestor::ForEachDescendant( stg_model_callback_t func, void* arg )
{ {
for( GList* it=children; it; it=it->next ) { FOR_EACH( it, children )
Model* mod = (Model*)it->data; {
Model* mod = (*it);
func( mod, arg ); func( mod, arg );
mod->ForEachDescendant( func, arg ); mod->ForEachDescendant( func, arg );
} }
} }




Expand Down
83 changes: 16 additions & 67 deletions libstage/blockgroup.cc
Expand Up @@ -30,59 +30,34 @@ void BlockGroup::AppendBlock( Block* block )


void BlockGroup::Clear() void BlockGroup::Clear()
{ {
// while( blocks ) FOR_EACH( it, 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 )
delete *it; delete *it;

blocks.clear(); blocks.clear();
} }



void BlockGroup::SwitchToTestedCells() void BlockGroup::SwitchToTestedCells()
{ {
// confirm the tentative pose for all blocks // confirm the tentative pose for all blocks
//LISTMETHOD( blocks, Block*, SwitchToTestedCells ); FOR_EACH( it, blocks )

(*it)->SwitchToTestedCells();
for( vector<Block*>::iterator it( blocks.begin() );
it != blocks.end();
++it )
(*it)->SwitchToTestedCells();
} }


GList* BlockGroup::AppendTouchingModels( GList* list ) GList* BlockGroup::AppendTouchingModels( GList* list )
{ {
for( vector<Block*>::iterator it( blocks.begin() ); FOR_EACH( it, blocks )
it != blocks.end(); list = (*it)->AppendTouchingModels( list );
++it )
list = (*it)->AppendTouchingModels( list );

return list; return list;
} }


Model* BlockGroup::TestCollision() Model* BlockGroup::TestCollision()
{ {
Model* hitmod = NULL; Model* hitmod = NULL;


for( vector<Block*>::iterator it( blocks.begin() ); FOR_EACH( it, blocks )
it != blocks.end();
++it )
if( (hitmod = (*it)->TestCollision())) if( (hitmod = (*it)->TestCollision()))
break; // bail on the earliest collision 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 return hitmod; // NULL if no collision
} }


Expand All @@ -98,10 +73,7 @@ void BlockGroup::CalcSize()


size.z = 0.0; // grow to largest z we see size.z = 0.0; // grow to largest z we see


for( vector<Block*>::iterator it( blocks.begin() ); FOR_EACH( it, blocks )
it != blocks.end();
++it )
// for( GList* it=blocks; it; it=it->next ) // examine all the blocks
{ {
// examine all the points in the polygon // examine all the points in the polygon
Block* block = *it; Block* block = *it;
Expand Down Expand Up @@ -132,22 +104,14 @@ void BlockGroup::CalcSize()


void BlockGroup::Map() void BlockGroup::Map()
{ {
for( std::vector<Block*>::iterator it( blocks.begin() ); FOR_EACH( it, blocks )
it != blocks.end();
++it )
(*it)->Map(); (*it)->Map();

//LISTMETHOD( blocks, Block*, Map );
} }


void BlockGroup::UnMap() void BlockGroup::UnMap()
{ {
for( std::vector<Block*>::iterator it( blocks.begin() ); FOR_EACH( it, blocks )
it != blocks.end();
++it )
(*it)->UnMap(); (*it)->UnMap();

//LISTMETHOD( blocks, Block*, UnMap );
} }


void BlockGroup::DrawSolid( const Geom & geom ) void BlockGroup::DrawSolid( const Geom & geom )
Expand All @@ -162,11 +126,8 @@ void BlockGroup::DrawSolid( const Geom & geom )


glTranslatef( -offset.x, -offset.y, -offset.z ); glTranslatef( -offset.x, -offset.y, -offset.z );


for( std::vector<Block*>::iterator it( blocks.begin() ); FOR_EACH( it, blocks )
it != blocks.end();
++it )
(*it)->DrawSolid(); (*it)->DrawSolid();
// LISTMETHOD( blocks, Block*, DrawSolid );


glPopMatrix(); glPopMatrix();
} }
Expand All @@ -180,12 +141,9 @@ void BlockGroup::DrawFootPrint( const Geom & geom )
geom.size.z / size.z ); geom.size.z / size.z );


glTranslatef( -offset.x, -offset.y, -offset.z ); glTranslatef( -offset.x, -offset.y, -offset.z );


for( std::vector<Block*>::iterator it( blocks.begin() ); FOR_EACH( it, blocks )
it != blocks.end();
++it )
(*it)->DrawFootPrint(); (*it)->DrawFootPrint();
// LISTMETHOD( blocks, Block*, DrawFootPrint);


glPopMatrix(); glPopMatrix();
} }
Expand Down Expand Up @@ -222,10 +180,7 @@ void BlockGroup::BuildDisplayList( Model* mod )


mod->PushColor( mod->color ); mod->PushColor( mod->color );


for( vector<Block*>::iterator it( blocks.begin() ); FOR_EACH( it, blocks )
it != blocks.end();
++it )
//for( GList* it=blocks; it; it=it->next )
{ {
Block* blk = (*it); Block* blk = (*it);


Expand All @@ -250,10 +205,7 @@ void BlockGroup::BuildDisplayList( Model* mod )
stg_color_unpack( mod->color, &r, &g, &b, &a ); stg_color_unpack( mod->color, &r, &g, &b, &a );
mod->PushColor( stg_color_pack( r/2.0, g/2.0, b/2.0, a )); mod->PushColor( stg_color_pack( r/2.0, g/2.0, b/2.0, a ));


for( vector<Block*>::iterator it( blocks.begin() ); FOR_EACH( it, blocks )
it != blocks.end();
++it )
//for( GList* it=blocks; it; it=it->next )
{ {
Block* blk = *it; Block* blk = *it;


Expand Down Expand Up @@ -365,9 +317,6 @@ void BlockGroup::Rasterize( uint8_t* data,
stg_meters_t cellwidth, stg_meters_t cellwidth,
stg_meters_t cellheight ) stg_meters_t cellheight )
{ {
for( vector<Block*>::iterator it( blocks.begin() ); FOR_EACH( it, blocks )
it != blocks.end();
++it )
//for( GList* it = blocks; it; it=it->next )
(*it)->Rasterize( data, width, height, cellwidth, cellheight ); (*it)->Rasterize( data, width, height, cellwidth, cellheight );
} }
17 changes: 9 additions & 8 deletions libstage/canvas.cc
Expand Up @@ -204,9 +204,9 @@ Model* Canvas::getModel( int x, int y )


// render all top-level, draggable models in a color that is their // render all top-level, draggable models in a color that is their
// id // 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 )) if( mod->gui.mask & (STG_MOVE_TRANS | STG_MOVE_ROT ))
{ {
Expand Down Expand Up @@ -694,8 +694,9 @@ void Canvas::resetCamera()
float max_x = 0, max_y = 0, min_x = 0, min_y = 0; float max_x = 0, max_y = 0, min_x = 0, min_y = 0;


//TODO take orrientation ( `a' ) and geom.pose offset into consideration //TODO take orrientation ( `a' ) and geom.pose offset into consideration
for( GList* it=world->World::children; it; it=it->next ) { FOR_EACH( it, world->World::children )
Model* ptr = (Model*) it->data; {
Model* ptr = (*it);
Pose pose = ptr->GetPose(); Pose pose = ptr->GetPose();
Geom geom = ptr->GetGeom(); Geom geom = ptr->GetGeom();


Expand Down Expand Up @@ -1012,12 +1013,12 @@ void Canvas::renderFrame()
// draw the model-specific visualizations // draw the model-specific visualizations
if( showData ) { if( showData ) {
if ( ! visualizeAll ) { if ( ! visualizeAll ) {
for( GList* it = world->World::children; it; it=it->next ) FOR_EACH( it, world->World::children )
((Model*)it->data)->DataVisualizeTree( current_camera ); (*it)->DataVisualizeTree( current_camera );
} }
else if ( selected_models ) { else if ( selected_models ) {
for( GList* it = selected_models; it; it=it->next ) FOR_EACH( it, world->World::children )
((Model*)it->data)->DataVisualizeTree( current_camera ); (*it)->DataVisualizeTree( current_camera );
} }
else if ( last_selection ) { else if ( last_selection ) {
last_selection->DataVisualizeTree( current_camera ); last_selection->DataVisualizeTree( current_camera );
Expand Down

0 comments on commit 5dee8f1

Please sign in to comment.