Permalink
Browse files

threaded double-buffer with raytracing and moving happening in differ…

…ent buffers. Runs without crashing on dual core i7. Background not yet implemented.
  • Loading branch information...
1 parent 6dd2b05 commit 047355a9f2d1619bc73df1109cc8e3b3823874b6 @rtv committed Dec 13, 2010
Showing with 168 additions and 168 deletions.
  1. +9 −11 libstage/block.cc
  2. +4 −4 libstage/blockgroup.cc
  3. +31 −27 libstage/model.cc
  4. +5 −3 libstage/model_getset.cc
  5. +4 −2 libstage/model_gripper.cc
  6. +2 −2 libstage/model_load.cc
  7. +1 −1 libstage/region.cc
  8. +40 −24 libstage/stage.hh
  9. +71 −93 libstage/world.cc
  10. +1 −1 worlds/fasr2.world
View
@@ -55,7 +55,7 @@ Block::Block( Model* mod,
Block::~Block()
{
- if( mapped ) UnMap();
+ if( mapped ) UnMapAllLayers();
}
void Block::Translate( double x, double y )
@@ -192,11 +192,11 @@ Model* Block::TestCollision()
return NULL; // no hit
}
-void Block::Map()
+void Block::Map( unsigned int layer )
{
// calculate the local coords of the block vertices
const size_t pt_count(pts.size());
-
+
if( mpts.size() == 0 )
{
// no valid cache of model coord points, so generate them
@@ -211,7 +211,7 @@ void Block::Map()
mod->LocalToPixels( mpts, gpts );
// and render this block's polygon into the world
- mod->GetWorld()->MapPoly( gpts, this );
+ mod->world->MapPoly( gpts, this, layer );
// update the block's absolute z bounds at this rendering
Pose gpose( mod->GetGlobalPose() );
@@ -227,16 +227,14 @@ void Block::Map()
#include <algorithm>
#include <functional>
-void Block::UnMap()
+void Block::UnMap( unsigned int layer )
{
-// std::for_each( rendered_cells.begin(),
-// rendered_cells.end(),
-// std::bind2nd( std::mem_fun(&Cell::RemoveBlock), this));
+ // std::for_each( rendered_cells.begin(),
+ // rendered_cells.end(),
+ // std::bind2nd( std::mem_fun(&Cell::RemoveBlock), this));
- unsigned int layer = mod->world->updates % 2;
-
FOR_EACH( it, rendered_cells[layer] )
- (*it)->RemoveBlock(this, layer );
+ (*it)->RemoveBlock(this, layer );
rendered_cells[layer].clear();
mapped = false;
View
@@ -94,19 +94,19 @@ void BlockGroup::CalcSize()
}
-void BlockGroup::Map()
+void BlockGroup::Map( unsigned int layer )
{
FOR_EACH( it, blocks )
- (*it)->Map();
+ (*it)->Map(layer);
}
// defined in world.cc
//void SwitchSuperRegionLock( SuperRegion* current, SuperRegion* next );
-void BlockGroup::UnMap()
+void BlockGroup::UnMap( unsigned int layer )
{
FOR_EACH( it, blocks )
- (*it)->UnMap();
+ (*it)->UnMap(layer);
}
void BlockGroup::DrawSolid( const Geom & geom )
View
@@ -430,7 +430,8 @@ Model::~Model( void )
if( world ) // if I'm not a worldless dummy model
{
- UnMap(); // remove from the raytrace bitmap
+ UnMap(0); // remove from the raytrace bitmap
+ UnMap(1); // remove from the raytrace bitmap
EraseAll( this, parent ? parent->children : world->children );
modelsbyid.erase(id);
@@ -485,9 +486,10 @@ Model::Flag* Model::PopFlag()
return flag;
}
-void Model::ClearBlocks( void )
+void Model::ClearBlocks()
{
- UnMap();
+ blockgroup.UnMapAllLayers();
+
blockgroup.Clear();
//no need to Map() - we have no blocks
NeedRedraw();
@@ -511,8 +513,8 @@ Block* Model::AddBlockRect( meters_t x,
meters_t dy,
meters_t dz )
{
- UnMap();
-
+ blockgroup.UnMapAllLayers();
+
std::vector<point_t> pts(4);
pts[0].x = x;
pts[0].y = y;
@@ -532,7 +534,7 @@ Block* Model::AddBlockRect( meters_t x,
blockgroup.AppendBlock( newblock );
- Map();
+ Map( world->updates%2 );
return newblock;
}
@@ -668,33 +670,33 @@ void Model::LocalToPixels( const std::vector<point_t>& local,
}
}
-void Model::MapWithChildren()
+void Model::MapWithChildren( unsigned int layer )
{
- UnMap();
- Map();
+ UnMap(layer);
+ Map(layer);
// recursive call for all the model's children
FOR_EACH( it, children )
- (*it)->MapWithChildren();
+ (*it)->MapWithChildren(layer);
}
-void Model::MapFromRoot()
+void Model::MapFromRoot( unsigned int layer )
{
- Root()->MapWithChildren();
+ Root()->MapWithChildren(layer);
}
-void Model::UnMapWithChildren()
+void Model::UnMapWithChildren(unsigned int layer)
{
- UnMap();
+ UnMap(layer);
// recursive call for all the model's children
FOR_EACH( it, children )
- (*it)->UnMapWithChildren();
+ (*it)->UnMapWithChildren(layer);
}
-void Model::UnMapFromRoot()
+void Model::UnMapFromRoot(unsigned int layer)
{
- Root()->UnMapWithChildren();
+ Root()->UnMapWithChildren(layer);
}
void Model::Subscribe( void )
@@ -958,16 +960,18 @@ void Model::Move( void )
pose = newpose; // do the move provisionally - we might undo it below
+ const unsigned int layer( world->updates%2 );
+
//UnMapWithChildren(); // remove from all blocks
- MapWithChildren(); // render into new blocks
+ MapWithChildren(layer); // render into new blocks
if( TestCollision() ) // crunch!
{
// put things back the way they were
// this is expensive, but it happens _very_ rarely for most people
pose = startpose;
- UnMapWithChildren();
- MapWithChildren();
+ UnMapWithChildren(layer);
+ MapWithChildren(layer);
SetStall(true);
}
else
@@ -1066,23 +1070,23 @@ kg_t Model::GetMassOfChildren() const
return( GetTotalMass() - mass);
}
-void Model::Map()
+void Model::Map( unsigned int layer )
{
if( ! mapped )
{
// render all blocks in the group at my global pose and size
- blockgroup.Map();
+ blockgroup.Map( layer );
mapped = true;
}
}
-void Model::UnMap()
+void Model::UnMap( unsigned int layer )
{
if( mapped )
- {
- blockgroup.UnMap();
- mapped = false;
- }
+ {
+ blockgroup.UnMap(layer);
+ mapped = false;
+ }
}
void Model::BecomeParentOf( Model* child )
View
@@ -4,15 +4,17 @@ using namespace Stg;
void Model::SetGeom( const Geom& val )
{
- UnMapWithChildren();
+ unsigned int layer = world->updates%2;
+
+ UnMapWithChildren(layer);
geom = val;
blockgroup.CalcSize();
NeedRedraw();
- MapWithChildren();
+ MapWithChildren(layer);
CallCallbacks( CB_GEOM );
}
@@ -216,7 +218,7 @@ void Model::SetPose( const Pose& newpose )
// token, pose.x, pose.y, pose.z, pose.a );
NeedRedraw();
- MapWithChildren();
+ MapWithChildren(world->updates%2);
world->dirty = true;
}
@@ -184,7 +184,9 @@ void ModelGripper::FixBlocks()
// Update the blocks that are the gripper's body
void ModelGripper::PositionPaddles()
{
- UnMap();
+ unsigned int layer = world->GetUpdateCount()%2;
+ UnMap(layer);
+
double paddle_center_pos = cfg.paddle_position * (0.5 - cfg.paddle_size.y );
paddle_left->SetCenterY( paddle_center_pos + cfg.paddle_size.y/2.0 );
paddle_right->SetCenterY( 1.0 - paddle_center_pos - cfg.paddle_size.y/2.0);
@@ -195,7 +197,7 @@ void ModelGripper::PositionPaddles()
paddle_left->SetZ( paddle_bottom, paddle_top );
paddle_right->SetZ( paddle_bottom, paddle_top );
- Map();
+ Map(layer);
}
View
@@ -248,8 +248,8 @@ void Model::Load()
// we may well have changed blocks or geometry
blockgroup.CalcSize();
- UnMapWithChildren();
- MapWithChildren();
+ UnMapWithChildren(world->updates%2);
+ MapWithChildren(world->updates%2);
if( this->debug )
printf( "Model \"%s\" is in debug mode\n", token.c_str() );
View
@@ -118,7 +118,7 @@ void SuperRegion::DrawOccupancy( unsigned int layer ) const
for( int y=0; y<SUPERREGIONWIDTH; ++y )
for( int x=0; x<SUPERREGIONWIDTH; ++x )
{
- if( r->count ) // region contains some occupied cells
+ if( r->count ) // region contains some occupied cells
{
// outline the region
glRecti( x<<RBITS, y<<RBITS,
Oops, something went wrong.

0 comments on commit 047355a

Please sign in to comment.