Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

removed unused model_props file and folded model_getset and model_loa…

…d into model.cc.

for faster builds and fewer things
  • Loading branch information...
commit 4de1b778640d93154cd55caf6d95075d4a41cb8e 1 parent 41f999b
@rtv authored
View
17 libstage/CMakeLists.txt
@@ -20,10 +20,8 @@ set( stageSrcs
model_camera.cc
model_draw.cc
model_fiducial.cc
- model_getset.cc
model_gripper.cc
model_lightindicator.cc
- model_load.cc
model_position.cc
model_ranger.cc
option.cc
@@ -35,14 +33,17 @@ set( stageSrcs
typetable.cc
world.cc
worldfile.cc
- canvas.cc
- options_dlg.cc
- options_dlg.hh
- vis_strip.cc
- worldgui.cc
- ancestor.cc
+ canvas.cc
+ options_dlg.cc
+ options_dlg.hh
+ vis_strip.cc
+ worldgui.cc
+ ancestor.cc
)
+# model_getset.cc
+# model_load.cc
+
#set_source_files_properties( ${stageSrcs} PROPERTIES COMPILE_FLAGS" )
add_library(stage SHARED ${stageSrcs})
View
3  libstage/block.cc
@@ -209,8 +209,7 @@ void Block::Map( unsigned int layer )
}
// now calculate the global pixel coords of the block vertices
- std::vector<point_int_t> gpts;
- mod->LocalToPixels( mpts, gpts );
+ const std::vector<point_int_t> gpts = mod->LocalToPixels( mpts );
// and render this block's polygon into the world
mod->world->MapPoly( gpts, this, layer );
View
500 libstage/model.cc
@@ -136,10 +136,12 @@
#include <map>
#include <sstream> // for converting values to strings
+#include <ltdl.h> // for library module loading
-//#define DEBUG 0
+#include "config.h" // for build-time config
#include "stage.hh"
#include "worldfile.hh"
+#include "file_manager.hh"
using namespace Stg;
// static members
@@ -595,9 +597,10 @@ point_t Model::LocalToGlobal( const point_t& pt) const
}
-void Model::LocalToPixels( const std::vector<point_t>& local,
- std::vector<point_int_t>& global) const
+std::vector<point_int_t> Model::LocalToPixels( const std::vector<point_t>& local ) const
{
+ std::vector<point_int_t> global;
+
const Pose gpose( GetGlobalPose() + geom.pose );
Pose ptpose;
@@ -607,6 +610,8 @@ void Model::LocalToPixels( const std::vector<point_t>& local,
global.push_back( point_int_t( (int32_t)floor( ptpose.x * world->ppm) ,
(int32_t)floor( ptpose.y * world->ppm) ));
}
+
+ return global;
}
void Model::MapWithChildren( unsigned int layer )
@@ -1232,3 +1237,492 @@ void Model::Flag::Draw( GLUquadric* quadric )
glCallList( displaylist );
}
+
+
+
+void Model::SetGeom( const Geom& val )
+{
+ UnMapWithChildren(0);
+ UnMapWithChildren(1);
+
+ geom = val;
+
+ blockgroup.CalcSize();
+
+ NeedRedraw();
+
+ MapWithChildren(0);
+ MapWithChildren(1);
+
+ CallCallbacks( CB_GEOM );
+}
+
+void Model::SetColor( Color val )
+{
+ color = val;
+ NeedRedraw();
+}
+
+void Model::SetMass( kg_t val )
+{
+ mass = val;
+}
+
+void Model::SetStall( bool val )
+{
+ stall = val;
+}
+
+void Model::SetGripperReturn( bool val )
+{
+ vis.gripper_return = val;
+}
+
+void Model::SetFiducialReturn( int val )
+{
+ vis.fiducial_return = val;
+
+ // non-zero values mean we need to be in the world's set of
+ // detectable models
+ if( val == 0 )
+ world->FiducialErase( this );
+ else
+ world->FiducialInsert( this );
+}
+
+void Model::SetFiducialKey( int val )
+{
+ vis.fiducial_key = val;
+}
+
+void Model::SetObstacleReturn( bool val )
+{
+ vis.obstacle_return = val;
+}
+
+void Model::SetBlobReturn( bool val )
+{
+ vis.blob_return = val;
+}
+
+void Model::SetRangerReturn( double val )
+{
+ vis.ranger_return = val;
+}
+
+void Model::SetBoundary( bool val )
+{
+ boundary = val;
+}
+
+void Model::SetGuiNose( bool val )
+{
+ gui.nose = val;
+}
+
+void Model::SetGuiMove( bool val )
+{
+ gui.move = val;
+}
+
+void Model::SetGuiGrid( bool val )
+{
+ gui.grid = val;
+}
+
+void Model::SetGuiOutline( bool val )
+{
+ gui.outline = val;
+}
+
+void Model::SetWatts( watts_t val )
+{
+ watts = val;
+}
+
+void Model::SetMapResolution( meters_t val )
+{
+ map_resolution = val;
+}
+
+// set the pose of model in global coordinates
+void Model::SetGlobalPose( const Pose& gpose )
+{
+ SetPose( parent ? parent->GlobalToLocal( gpose ) : gpose );
+}
+
+int Model::SetParent( Model* newparent)
+{
+ Pose oldPose = GetGlobalPose();
+
+ // remove the model from its old parent (if it has one)
+ if( parent )
+ parent->RemoveChild( this );
+ else
+ world->RemoveChild( this );
+ // link from the model to its new parent
+ this->parent = newparent;
+
+ if( newparent )
+ newparent->AddChild( this );
+ else
+ world->AddModel( this );
+
+ CallCallbacks( CB_PARENT );
+
+ SetGlobalPose( oldPose ); // Needs to recalculate position due to change in parent
+
+ return 0; //ok
+}
+
+// get the model's position in the global frame
+Pose Model::GetGlobalPose() const
+{
+ // if I'm a top level model, my global pose is my local pose
+ if( parent == NULL )
+ return pose;
+
+ // otherwise
+ Pose global_pose = parent->GetGlobalPose() + pose;
+
+ if ( parent->stack_children ) // should we be on top of our parent?
+ global_pose.z += parent->geom.size.z;
+
+ return global_pose;
+}
+
+
+// set the model's pose in the local frame
+void Model::SetPose( const Pose& newpose )
+{
+ // if the pose has changed, we need to do some work
+ if( memcmp( &pose, &newpose, sizeof(Pose) ) != 0 )
+ {
+ pose = newpose;
+ pose.a = normalize(pose.a);
+
+ // if( isnan( pose.a ) )
+ // printf( "SetPose bad angle %s [%.2f %.2f %.2f %.2f]\n",
+ // token, pose.x, pose.y, pose.z, pose.a );
+
+ NeedRedraw();
+
+ UnMapWithChildren(0);
+ UnMapWithChildren(1);
+
+ MapWithChildren(0);
+ MapWithChildren(1);
+
+ world->dirty = true;
+ }
+
+ CallCallbacks( CB_POSE );
+}
+
+void Model::Load()
+{
+ assert( wf );
+ assert( wf_entity );
+
+ PRINT_DEBUG1( "Model \"%s\" loading...", token.c_str() );
+
+ // choose the thread to run in, if thread_safe > 0
+ event_queue_num = wf->ReadInt( wf_entity, "event_queue", event_queue_num );
+
+ if( wf->PropertyExists( wf_entity, "joules" ) )
+ {
+ if( !power_pack )
+ power_pack = new PowerPack( this );
+
+ joules_t j = wf->ReadFloat( wf_entity, "joules",
+ power_pack->GetStored() ) ;
+
+ /* assume that the store is full, so the capacity is the same as
+ the charge */
+ power_pack->SetStored( j );
+ power_pack->SetCapacity( j );
+ }
+
+ if( wf->PropertyExists( wf_entity, "joules_capacity" ) )
+ {
+ if( !power_pack )
+ power_pack = new PowerPack( this );
+
+ power_pack->SetCapacity( wf->ReadFloat( wf_entity, "joules_capacity",
+ power_pack->GetCapacity() ) );
+ }
+
+ if( wf->PropertyExists( wf_entity, "kjoules" ) )
+ {
+ if( !power_pack )
+ power_pack = new PowerPack( this );
+
+ joules_t j = 1000.0 * wf->ReadFloat( wf_entity, "kjoules",
+ power_pack->GetStored() ) ;
+
+ /* assume that the store is full, so the capacity is the same as
+ the charge */
+ power_pack->SetStored( j );
+ power_pack->SetCapacity( j );
+ }
+
+ if( wf->PropertyExists( wf_entity, "kjoules_capacity" ) )
+ {
+ if( !power_pack )
+ power_pack = new PowerPack( this );
+
+ power_pack->SetCapacity( 1000.0 * wf->ReadFloat( wf_entity, "kjoules_capacity",
+ power_pack->GetCapacity() ) );
+ }
+
+
+ watts = wf->ReadFloat( wf_entity, "watts", watts );
+ watts_give = wf->ReadFloat( wf_entity, "give_watts", watts_give );
+ watts_take = wf->ReadFloat( wf_entity, "take_watts", watts_take );
+
+ debug = wf->ReadInt( wf_entity, "debug", debug );
+
+ const std::string& name = wf->ReadString(wf_entity, "name", token );
+ if( name != token )
+ SetToken( name );
+
+ //PRINT_WARN1( "%s::Load", token );
+
+ Geom g( GetGeom() );
+
+ if( wf->PropertyExists( wf_entity, "origin" ) )
+ g.pose.Load( wf, wf_entity, "origin" );
+
+ if( wf->PropertyExists( wf_entity, "size" ) )
+ g.size.Load( wf, wf_entity, "size" );
+
+ SetGeom( g );
+
+ if( wf->PropertyExists( wf_entity, "pose" ))
+ SetPose( GetPose().Load( wf, wf_entity, "pose" ) );
+
+
+ if( wf->PropertyExists( wf_entity, "color" ))
+ {
+ Color col( 1,0,0 ); // red;
+ const std::string& colorstr = wf->ReadString( wf_entity, "color", "" );
+ if( colorstr != "" )
+ {
+ if( colorstr == "random" )
+ col = Color( drand48(), drand48(), drand48() );
+ else
+ col = Color( colorstr );
+ }
+ this->SetColor( col );
+ }
+
+ this->SetColor( GetColor().Load( wf, wf_entity ) );
+
+ if( wf->ReadInt( wf_entity, "noblocks", 0 ) )
+ {
+ if( has_default_block )
+ {
+ blockgroup.Clear();
+ has_default_block = false;
+ blockgroup.CalcSize();
+ }
+ }
+
+ if( wf->PropertyExists( wf_entity, "bitmap" ) )
+ {
+ const std::string bitmapfile = wf->ReadString( wf_entity, "bitmap", "" );
+ if( bitmapfile == "" )
+ PRINT_WARN1( "model %s specified empty bitmap filename\n", Token() );
+
+ if( has_default_block )
+ {
+ blockgroup.Clear();
+ has_default_block = false;
+ }
+
+ blockgroup.LoadBitmap( this, bitmapfile, wf );
+ }
+
+ if( wf->PropertyExists( wf_entity, "boundary" ))
+ {
+ this->SetBoundary( wf->ReadInt(wf_entity, "boundary", this->boundary ));
+
+ if( boundary )
+ {
+ //PRINT_WARN1( "setting boundary for %s\n", token );
+
+ blockgroup.CalcSize();
+
+ double epsilon = 0.01;
+ Size bgsize = blockgroup.GetSize();
+
+ AddBlockRect(blockgroup.minx,blockgroup.miny, epsilon, bgsize.y, bgsize.z );
+ AddBlockRect(blockgroup.minx,blockgroup.miny, bgsize.x, epsilon, bgsize.z );
+ AddBlockRect(blockgroup.minx,blockgroup.maxy-epsilon, bgsize.x, epsilon, bgsize.z );
+ AddBlockRect(blockgroup.maxx-epsilon,blockgroup.miny, epsilon, bgsize.y, bgsize.z );
+ }
+ }
+
+ this->stack_children =
+ wf->ReadInt( wf_entity, "stack_children", this->stack_children );
+
+ kg_t m = wf->ReadFloat(wf_entity, "mass", this->mass );
+ if( m != this->mass )
+ SetMass( m );
+
+ vis.Load( wf, wf_entity );
+ SetFiducialReturn( vis.fiducial_return ); // may have some work to do
+
+ gui.Load( wf, wf_entity );
+
+ double res = wf->ReadFloat(wf_entity, "map_resolution", this->map_resolution );
+ if( res != this->map_resolution )
+ SetMapResolution( res );
+
+ if( wf->PropertyExists( wf_entity, "friction" ))
+ {
+ this->SetFriction( wf->ReadFloat(wf_entity, "friction", this->friction ));
+ }
+
+ if( CProperty* ctrlp = wf->GetProperty( wf_entity, "ctrl" ) )
+ {
+ for( unsigned int index=0; index < ctrlp->values.size(); index++ )
+ {
+
+ const char* lib = wf->GetPropertyValue( ctrlp, index );
+
+ if( !lib )
+ printf( "Error - NULL library name specified for model %s\n", Token() );
+ else
+ LoadControllerModule( lib );
+ }
+ }
+
+ // internally interval is in usec, but we use msec in worldfiles
+ interval = 1000 * wf->ReadInt( wf_entity, "update_interval", interval/1000 );
+
+ Say( wf->ReadString(wf_entity, "say", "" ));
+
+ trail_length = wf->ReadInt( wf_entity, "trail_length", trail_length );
+ trail.resize( trail_length );
+
+ trail_interval = wf->ReadInt( wf_entity, "trail_interval", trail_interval );
+
+ this->alwayson = wf->ReadInt( wf_entity, "alwayson", alwayson );
+ if( alwayson )
+ Subscribe();
+
+ // call any type-specific load callbacks
+ this->CallCallbacks( CB_LOAD );
+
+ // we may well have changed blocks or geometry
+ blockgroup.CalcSize();
+
+ UnMapWithChildren(0);
+ UnMapWithChildren(1);
+ MapWithChildren(0);
+ MapWithChildren(1);
+
+ if( this->debug )
+ printf( "Model \"%s\" is in debug mode\n", Token() );
+
+ PRINT_DEBUG1( "Model \"%s\" loading complete", Token() );
+}
+
+
+void Model::Save( void )
+{
+ //printf( "Model \"%s\" saving...\n", Token() );
+
+ // some models were not loaded, so have no worldfile. Just bail here.
+ if( wf == NULL )
+ return;
+
+ assert( wf_entity );
+
+ PRINT_DEBUG5( "saving model %s pose [ %.2f, %.2f, %.2f, %.2f]",
+ token.c_str(),
+ pose.x,
+ pose.y,
+ pose.z,
+ pose.a );
+
+ // just in case
+ pose.a = normalize( pose.a );
+ geom.pose.a = normalize( geom.pose.a );
+
+ if( wf->PropertyExists( wf_entity, "pose" ) )
+ pose.Save( wf, wf_entity, "pose" );
+
+ if( wf->PropertyExists( wf_entity, "size" ) )
+ geom.size.Save( wf, wf_entity, "size" );
+
+ if( wf->PropertyExists( wf_entity, "origin" ) )
+ geom.pose.Save( wf, wf_entity, "origin" );
+
+ vis.Save( wf, wf_entity );
+
+ // call any type-specific save callbacks
+ CallCallbacks( CB_SAVE );
+
+ PRINT_DEBUG1( "Model \"%s\" saving complete.", token.c_str() );
+}
+
+
+void Model::LoadControllerModule( const char* lib )
+{
+ //printf( "[Ctrl \"%s\"", lib );
+ //fflush(stdout);
+
+ /* Initialise libltdl. */
+ int errors = lt_dlinit();
+ if (errors)
+ {
+ printf( "Libtool error: %s. Failed to init libtool. Quitting\n",
+ lt_dlerror() ); // report the error from libtool
+ puts( "libtool error #1" );
+ fflush( stdout );
+ exit(-1);
+ }
+
+ lt_dlsetsearchpath( FileManager::stagePath().c_str() );
+
+ // PLUGIN_PATH now defined in config.h
+ lt_dladdsearchdir( PLUGIN_PATH );
+
+ lt_dlhandle handle = NULL;
+
+ // the library name is the first word in the string
+ char libname[256];
+ sscanf( lib, "%s %*s", libname );
+
+ if(( handle = lt_dlopenext( libname ) ))
+ {
+ //printf( "]" );
+
+ model_callback_t initfunc = (model_callback_t)lt_dlsym( handle, "Init" );
+ if( initfunc == NULL )
+ {
+ printf( "Libtool error: %s. Something is wrong with your plugin. Quitting\n",
+ lt_dlerror() ); // report the error from libtool
+ puts( "libtool error #1" );
+ fflush( stdout );
+ exit(-1);
+ }
+
+ AddCallback( CB_INIT, initfunc, new CtrlArgs(lib,World::ctrlargs) ); // pass complete string into initfunc
+ }
+ else
+ {
+ printf( "Libtool error: %s. Can't open your plugin controller. Quitting\n",
+ lt_dlerror() ); // report the error from libtool
+
+ PRINT_ERR1( "Failed to open \"%s\". Check that it can be found by searching the directories in your STAGEPATH environment variable, or the current directory if STAGEPATH is not set.]\n", lib );
+ puts( "libtool error #2" );
+ fflush( stdout );
+ exit(-1);
+ }
+
+ fflush(stdout);
+}
+
View
2  libstage/model_draw.cc
@@ -128,7 +128,7 @@ void Model::DrawTrailFootprint()
double darkness = 0;
double fade = 0.5 / (double)(trail_length+1);
- PushColor( 0,0,0,1 ); // dummy pushL just saving the color
+ PushColor( 0,0,0,1 ); // dummy push just saving the color
// this loop could be faster, but optimzing vis is not a priority
for( unsigned int i=0; i<trail_length; i++ )
View
208 libstage/model_getset.cc
@@ -1,208 +0,0 @@
-#include "stage.hh"
-using namespace Stg;
-
-
-void Model::SetGeom( const Geom& val )
-{
- UnMapWithChildren(0);
- UnMapWithChildren(1);
-
- geom = val;
-
- blockgroup.CalcSize();
-
- NeedRedraw();
-
- MapWithChildren(0);
- MapWithChildren(1);
-
- CallCallbacks( CB_GEOM );
-}
-
-void Model::SetColor( Color val )
-{
- color = val;
- NeedRedraw();
-}
-
-void Model::SetMass( kg_t val )
-{
- mass = val;
-}
-
-void Model::SetStall( bool val )
-{
- stall = val;
-}
-
-void Model::SetGripperReturn( bool val )
-{
- vis.gripper_return = val;
-}
-
-void Model::SetFiducialReturn( int val )
-{
- vis.fiducial_return = val;
-
- // non-zero values mean we need to be in the world's set of
- // detectable models
- if( val == 0 )
- world->FiducialErase( this );
- else
- world->FiducialInsert( this );
-}
-
-void Model::SetFiducialKey( int val )
-{
- vis.fiducial_key = val;
-}
-
-void Model::SetObstacleReturn( bool val )
-{
- vis.obstacle_return = val;
-}
-
-void Model::SetBlobReturn( bool val )
-{
- vis.blob_return = val;
-}
-
-void Model::SetRangerReturn( double val )
-{
- vis.ranger_return = val;
-}
-
-void Model::SetBoundary( bool val )
-{
- boundary = val;
-}
-
-void Model::SetGuiNose( bool val )
-{
- gui.nose = val;
-}
-
-void Model::SetGuiMove( bool val )
-{
- gui.move = val;
-}
-
-void Model::SetGuiGrid( bool val )
-{
- gui.grid = val;
-}
-
-void Model::SetGuiOutline( bool val )
-{
- gui.outline = val;
-}
-
-void Model::SetWatts( watts_t val )
-{
- watts = val;
-}
-
-void Model::SetMapResolution( meters_t val )
-{
- map_resolution = val;
-}
-
-// set the pose of model in global coordinates
-void Model::SetGlobalPose( const Pose& gpose )
-{
- SetPose( parent ? parent->GlobalToLocal( gpose ) : gpose );
-}
-
-int Model::SetParent( Model* newparent)
-{
- Pose oldPose = GetGlobalPose();
-
- // remove the model from its old parent (if it has one)
- if( parent )
- parent->RemoveChild( this );
- else
- world->RemoveChild( this );
- // link from the model to its new parent
- this->parent = newparent;
-
- if( newparent )
- newparent->AddChild( this );
- else
- world->AddModel( this );
-
- CallCallbacks( CB_PARENT );
-
- SetGlobalPose( oldPose ); // Needs to recalculate position due to change in parent
-
- return 0; //ok
-}
-
-// // get the model's velocity in the global frame
-// Velocity Model::GetGlobalVelocity() const
-// {
-// const Pose gpose(GetGlobalPose());
-// const double cosa(cos(gpose.a));
-// const double sina(sin(gpose.a));
-
-// return Velocity( velocity.x * cosa - velocity.y * sina,
-// velocity.x * sina + velocity.y * cosa,
-// velocity.z,
-// velocity.a );
-// }
-
-// // set the model's velocity in the global frame
-// void Model::SetGlobalVelocity( const Velocity& gv )
-// {
-// const Pose gpose = GetGlobalPose();
-// const double cosa(cos(gpose.a));
-// const double sina(sin(gpose.a));
-
-// this->SetVelocity( Velocity( gv.x * cosa + gv.y * sina,
-// -gv.x * sina + gv.y * cosa,
-// gv.z,
-// gv.a ));
-// }
-
-// get the model's position in the global frame
-Pose Model::GetGlobalPose() const
-{
- // if I'm a top level model, my global pose is my local pose
- if( parent == NULL )
- return pose;
-
- // otherwise
- Pose global_pose = parent->GetGlobalPose() + pose;
-
- if ( parent->stack_children ) // should we be on top of our parent?
- global_pose.z += parent->geom.size.z;
-
- return global_pose;
-}
-
-
-// set the model's pose in the local frame
-void Model::SetPose( const Pose& newpose )
-{
- // if the pose has changed, we need to do some work
- if( memcmp( &pose, &newpose, sizeof(Pose) ) != 0 )
- {
- pose = newpose;
- pose.a = normalize(pose.a);
-
- // if( isnan( pose.a ) )
- // printf( "SetPose bad angle %s [%.2f %.2f %.2f %.2f]\n",
- // token, pose.x, pose.y, pose.z, pose.a );
-
- NeedRedraw();
-
- UnMapWithChildren(0);
- UnMapWithChildren(1);
-
- MapWithChildren(0);
- MapWithChildren(1);
-
- world->dirty = true;
- }
-
- CallCallbacks( CB_POSE );
-}
View
326 libstage/model_load.cc
@@ -1,326 +0,0 @@
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
-
-#include <limits.h>
-#include <libgen.h> // for dirname()
-#include <string.h>
-#include <ltdl.h> // for library module loading
-
-//#define DEBUG 1
-
-#include "stage.hh"
-#include "worldfile.hh"
-#include "file_manager.hh"
-#include "config.h"
-using namespace Stg;
-
-
-
-void Model::Load()
-{
- assert( wf );
- assert( wf_entity );
-
- PRINT_DEBUG1( "Model \"%s\" loading...", token.c_str() );
-
- // choose the thread to run in, if thread_safe > 0
- event_queue_num = wf->ReadInt( wf_entity, "event_queue", event_queue_num );
-
- if( wf->PropertyExists( wf_entity, "joules" ) )
- {
- if( !power_pack )
- power_pack = new PowerPack( this );
-
- joules_t j = wf->ReadFloat( wf_entity, "joules",
- power_pack->GetStored() ) ;
-
- /* assume that the store is full, so the capacity is the same as
- the charge */
- power_pack->SetStored( j );
- power_pack->SetCapacity( j );
- }
-
- if( wf->PropertyExists( wf_entity, "joules_capacity" ) )
- {
- if( !power_pack )
- power_pack = new PowerPack( this );
-
- power_pack->SetCapacity( wf->ReadFloat( wf_entity, "joules_capacity",
- power_pack->GetCapacity() ) );
- }
-
- if( wf->PropertyExists( wf_entity, "kjoules" ) )
- {
- if( !power_pack )
- power_pack = new PowerPack( this );
-
- joules_t j = 1000.0 * wf->ReadFloat( wf_entity, "kjoules",
- power_pack->GetStored() ) ;
-
- /* assume that the store is full, so the capacity is the same as
- the charge */
- power_pack->SetStored( j );
- power_pack->SetCapacity( j );
- }
-
- if( wf->PropertyExists( wf_entity, "kjoules_capacity" ) )
- {
- if( !power_pack )
- power_pack = new PowerPack( this );
-
- power_pack->SetCapacity( 1000.0 * wf->ReadFloat( wf_entity, "kjoules_capacity",
- power_pack->GetCapacity() ) );
- }
-
-
- watts = wf->ReadFloat( wf_entity, "watts", watts );
- watts_give = wf->ReadFloat( wf_entity, "give_watts", watts_give );
- watts_take = wf->ReadFloat( wf_entity, "take_watts", watts_take );
-
- debug = wf->ReadInt( wf_entity, "debug", debug );
-
- const std::string& name = wf->ReadString(wf_entity, "name", token );
- if( name != token )
- SetToken( name );
-
- //PRINT_WARN1( "%s::Load", token );
-
- Geom g( GetGeom() );
-
- if( wf->PropertyExists( wf_entity, "origin" ) )
- g.pose.Load( wf, wf_entity, "origin" );
-
- if( wf->PropertyExists( wf_entity, "size" ) )
- g.size.Load( wf, wf_entity, "size" );
-
- SetGeom( g );
-
- if( wf->PropertyExists( wf_entity, "pose" ))
- SetPose( GetPose().Load( wf, wf_entity, "pose" ) );
-
-
- if( wf->PropertyExists( wf_entity, "color" ))
- {
- Color col( 1,0,0 ); // red;
- const std::string& colorstr = wf->ReadString( wf_entity, "color", "" );
- if( colorstr != "" )
- {
- if( colorstr == "random" )
- col = Color( drand48(), drand48(), drand48() );
- else
- col = Color( colorstr );
- }
- this->SetColor( col );
- }
-
- this->SetColor( GetColor().Load( wf, wf_entity ) );
-
- if( wf->ReadInt( wf_entity, "noblocks", 0 ) )
- {
- if( has_default_block )
- {
- blockgroup.Clear();
- has_default_block = false;
- blockgroup.CalcSize();
- }
- }
-
- if( wf->PropertyExists( wf_entity, "bitmap" ) )
- {
- const std::string bitmapfile = wf->ReadString( wf_entity, "bitmap", "" );
- if( bitmapfile == "" )
- PRINT_WARN1( "model %s specified empty bitmap filename\n", Token() );
-
- if( has_default_block )
- {
- blockgroup.Clear();
- has_default_block = false;
- }
-
- blockgroup.LoadBitmap( this, bitmapfile, wf );
- }
-
- if( wf->PropertyExists( wf_entity, "boundary" ))
- {
- this->SetBoundary( wf->ReadInt(wf_entity, "boundary", this->boundary ));
-
- if( boundary )
- {
- //PRINT_WARN1( "setting boundary for %s\n", token );
-
- blockgroup.CalcSize();
-
- double epsilon = 0.01;
- Size bgsize = blockgroup.GetSize();
-
- AddBlockRect(blockgroup.minx,blockgroup.miny, epsilon, bgsize.y, bgsize.z );
- AddBlockRect(blockgroup.minx,blockgroup.miny, bgsize.x, epsilon, bgsize.z );
- AddBlockRect(blockgroup.minx,blockgroup.maxy-epsilon, bgsize.x, epsilon, bgsize.z );
- AddBlockRect(blockgroup.maxx-epsilon,blockgroup.miny, epsilon, bgsize.y, bgsize.z );
- }
- }
-
- this->stack_children =
- wf->ReadInt( wf_entity, "stack_children", this->stack_children );
-
- kg_t m = wf->ReadFloat(wf_entity, "mass", this->mass );
- if( m != this->mass )
- SetMass( m );
-
- vis.Load( wf, wf_entity );
- SetFiducialReturn( vis.fiducial_return ); // may have some work to do
-
- gui.Load( wf, wf_entity );
-
- double res = wf->ReadFloat(wf_entity, "map_resolution", this->map_resolution );
- if( res != this->map_resolution )
- SetMapResolution( res );
-
- if( wf->PropertyExists( wf_entity, "friction" ))
- {
- this->SetFriction( wf->ReadFloat(wf_entity, "friction", this->friction ));
- }
-
- if( CProperty* ctrlp = wf->GetProperty( wf_entity, "ctrl" ) )
- {
- for( unsigned int index=0; index < ctrlp->values.size(); index++ )
- {
-
- const char* lib = wf->GetPropertyValue( ctrlp, index );
-
- if( !lib )
- printf( "Error - NULL library name specified for model %s\n", Token() );
- else
- LoadControllerModule( lib );
- }
- }
-
- // internally interval is in usec, but we use msec in worldfiles
- interval = 1000 * wf->ReadInt( wf_entity, "update_interval", interval/1000 );
-
- Say( wf->ReadString(wf_entity, "say", "" ));
-
- trail_length = wf->ReadInt( wf_entity, "trail_length", trail_length );
- trail.resize( trail_length );
-
- trail_interval = wf->ReadInt( wf_entity, "trail_interval", trail_interval );
-
- this->alwayson = wf->ReadInt( wf_entity, "alwayson", alwayson );
- if( alwayson )
- Subscribe();
-
- // call any type-specific load callbacks
- this->CallCallbacks( CB_LOAD );
-
- // we may well have changed blocks or geometry
- blockgroup.CalcSize();
-
- UnMapWithChildren(0);
- UnMapWithChildren(1);
- MapWithChildren(0);
- MapWithChildren(1);
-
- if( this->debug )
- printf( "Model \"%s\" is in debug mode\n", Token() );
-
- PRINT_DEBUG1( "Model \"%s\" loading complete", Token() );
-}
-
-
-void Model::Save( void )
-{
- //printf( "Model \"%s\" saving...\n", Token() );
-
- // some models were not loaded, so have no worldfile. Just bail here.
- if( wf == NULL )
- return;
-
- assert( wf_entity );
-
- PRINT_DEBUG5( "saving model %s pose [ %.2f, %.2f, %.2f, %.2f]",
- token.c_str(),
- pose.x,
- pose.y,
- pose.z,
- pose.a );
-
- // just in case
- pose.a = normalize( pose.a );
- geom.pose.a = normalize( geom.pose.a );
-
- if( wf->PropertyExists( wf_entity, "pose" ) )
- pose.Save( wf, wf_entity, "pose" );
-
- if( wf->PropertyExists( wf_entity, "size" ) )
- geom.size.Save( wf, wf_entity, "size" );
-
- if( wf->PropertyExists( wf_entity, "origin" ) )
- geom.pose.Save( wf, wf_entity, "origin" );
-
- vis.Save( wf, wf_entity );
-
- // call any type-specific save callbacks
- CallCallbacks( CB_SAVE );
-
- PRINT_DEBUG1( "Model \"%s\" saving complete.", token.c_str() );
-}
-
-
-void Model::LoadControllerModule( const char* lib )
-{
- //printf( "[Ctrl \"%s\"", lib );
- //fflush(stdout);
-
- /* Initialise libltdl. */
- int errors = lt_dlinit();
- if (errors)
- {
- printf( "Libtool error: %s. Failed to init libtool. Quitting\n",
- lt_dlerror() ); // report the error from libtool
- puts( "libtool error #1" );
- fflush( stdout );
- exit(-1);
- }
-
- lt_dlsetsearchpath( FileManager::stagePath().c_str() );
-
- // PLUGIN_PATH now defined in config.h
- lt_dladdsearchdir( PLUGIN_PATH );
-
- lt_dlhandle handle = NULL;
-
- // the library name is the first word in the string
- char libname[256];
- sscanf( lib, "%s %*s", libname );
-
- if(( handle = lt_dlopenext( libname ) ))
- {
- //printf( "]" );
-
- model_callback_t initfunc = (model_callback_t)lt_dlsym( handle, "Init" );
- if( initfunc == NULL )
- {
- printf( "Libtool error: %s. Something is wrong with your plugin. Quitting\n",
- lt_dlerror() ); // report the error from libtool
- puts( "libtool error #1" );
- fflush( stdout );
- exit(-1);
- }
-
- AddCallback( CB_INIT, initfunc, new CtrlArgs(lib,World::ctrlargs) ); // pass complete string into initfunc
- }
- else
- {
- printf( "Libtool error: %s. Can't open your plugin controller. Quitting\n",
- lt_dlerror() ); // report the error from libtool
-
- PRINT_ERR1( "Failed to open \"%s\". Check that it can be found by searching the directories in your STAGEPATH environment variable, or the current directory if STAGEPATH is not set.]\n", lib );
- puts( "libtool error #2" );
- fflush( stdout );
- exit(-1);
- }
-
- fflush(stdout);
-}
-
View
187 libstage/model_props.cc
@@ -1,187 +0,0 @@
-
-#include "stage.hh"
-using namespace Stg;
-
-#define MATCH(A,B) (strcmp(A,B)== 0)
-
-const void* Model::GetProperty( const char* key ) const
-{
-
- // see if the key has the predefined-property prefix
- if( strncmp( key, MP_PREFIX, strlen(MP_PREFIX)) == 0 )
- {
-#if 0
- TODO
- static std::map<std::string, const void*> props;
-
- // first time in, populate the map
- if( props.size() < 1 )
- {
- props[MP_COLOR] = (void*)&color;
- props[MP_MASS] = (void*)&mass;
- props[MP_WATTS] = (void*)&watts;
- props[MP_FIDUCIAL_RETURN] = (void*)&vis.fiducial_return;
- props[MP_LASER_RETURN] = (void*)&vis.laser_return;
- props[MP_OBSTACLE_RETURN] = (void*)&vis.obstacle_return;
- props[MP_RANGER_RETURN] = (void*)&vis.ranger_return;
- props[MP_GRIPPER_RETURN] = (void*)&vis.gripper_return;
- }
-#endif
-
- if( MATCH( key, MP_COLOR)) return (void*)&color;
- if( MATCH( key, MP_MASS)) return (void*)&mass;
- if( MATCH( key, MP_WATTS)) return (void*)&watts;
- if( MATCH( key, MP_FIDUCIAL_RETURN)) return (void*)&vis.fiducial_return;
- if( MATCH( key, MP_LASER_RETURN)) return (void*)&vis.laser_return;
- if( MATCH( key, MP_OBSTACLE_RETURN)) return (void*)&vis.obstacle_return;
- if( MATCH( key, MP_RANGER_RETURN)) return (void*)&vis.ranger_return;
- if( MATCH( key, MP_GRIPPER_RETURN)) return (void*)&vis.gripper_return;
-
- PRINT_WARN1( "Requested non-existent model core property \"%s\"", key );
- return NULL;
- }
-
- // otherwise it may be an arbitrary named property
- const std::map< std::string,const void* >::const_iterator& it
- = props.find( key );
-
- if( it != props.end() )
- return it->second;
- else
- return NULL;
-}
-
-int Model::SetProperty( const char* key,
- const void* data )
-{
- // see if the key has the predefined-property prefix
- if( strncmp( key, MP_PREFIX, strlen(MP_PREFIX)) == 0 )
- {
- PRINT_DEBUG1( "Looking up model core property \"%s\"\n", key );
-
- if( MATCH(key,MP_FIDUCIAL_RETURN) )
- {
- this->SetFiducialReturn( *(int*)data );
- return 0;
- }
- if( MATCH( key, MP_LASER_RETURN ) )
- {
- this->SetLaserReturn( *(laser_return_t*)data );
- return 0;
- }
- if( MATCH( key, MP_OBSTACLE_RETURN ) )
- {
- this->SetObstacleReturn( *(int*)data );
- return 0;
- }
- if( MATCH( key, MP_RANGER_RETURN ) )
- {
- this->SetRangerReturn( *(int*)data );
- return 0;
- }
- if( MATCH( key, MP_GRIPPER_RETURN ) )
- {
- this->SetGripperReturn( *(int*)data );
- return 0;
- }
- if( MATCH( key, MP_COLOR ) )
- {
- float* f = (float*)data;
- this->SetColor( Color(f[0], f[1], f[2], f[3]));
- return 0;
- }
- if( MATCH( key, MP_MASS ) )
- {
- this->SetMass( *(double*)data );
- return 0;
- }
- if( MATCH( key, MP_WATTS ) )
- {
- this->SetWatts( *(double*)data );
- return 0;
- }
-
- PRINT_ERR1( "Attempt to set non-existent model core property \"%s\"", key );
- return 1; // error code
- }
-
- //printf( "setting property %s %p\n", key, data );
-
- // otherwise it's an arbitary property and we store the pointer
- //g_datalist_set_data( &this->props, key, (void*)data );
- props[key] = data;
-
- return 0; // ok
-}
-
-
-void Model::UnsetProperty( const char* key )
-{
- if( strncmp( key, MP_PREFIX, strlen(MP_PREFIX)) == 0 )
- PRINT_WARN1( "Attempt to unset a model core property \"%s\" has no effect", key );
- else
- //g_datalist_remove_data( &this->props, key );
- props.erase( key );
-}
-
-
-bool Model::GetPropertyFloat( const char* key, float* f, float defaultval ) const
-{
- float* fp = (float*)GetProperty( key );
- if( fp )
- {
- *f = *fp;
- return true;
- }
-
- *f = defaultval;
- return false;
-}
-
-bool Model::GetPropertyInt( const char* key, int* i, int defaultval ) const
-{
- int* ip = (int*)GetProperty( key );
- if( ip )
- {
- *i = *ip;
- return true;
- }
-
- *i = defaultval;
- return false;
-}
-
-bool Model::GetPropertyStr( const char* key, char** c, char* defaultval ) const
-{
- char* cp = (char*)GetProperty( key );
-
- //printf( "got model %s property string %s=%s\n", token, key, cp );
-
- if( cp )
- {
- *c = cp;
- return true;
- }
-
- *c = defaultval;
- return false;
-}
-
-void Model::SetPropertyInt( const char* key, int i )
-{
- int* ip = new int(i);
- SetProperty( key, (void*)ip );
-}
-
-void Model::SetPropertyFloat( const char* key, float f )
-{
- float* fp = new float(f);
- SetProperty( key, (void*)fp );
-}
-
-void Model::SetPropertyStr( const char* key, const char* str )
-{
- //printf( "set model %s string %s=%s\n", token, key, str );
- SetProperty( key, (void*)strdup(str) );
-}
-
View
344 libstage/region.cc~
@@ -1,344 +0,0 @@
-/*
- region.cc
- data structures supporting multi-resolution ray tracing in world class.
- Copyright Richard Vaughan 2008
-*/
-
-#include <pthread.h>
-#include "region.hh"
-using namespace Stg;
-
-std::vector<Cell*> Region::dead_pool;
-
-Region::Region() :
- cells(),
- count(0),
- superregion(NULL)
-{
-}
-
-Region::~Region()
-{
- if( cells )
- delete[] cells;
-}
-
-void Region::AddBlock()
-{
-
- ++count;
- assert(count>0);
- superregion->AddBlock();
-}
-
-void Region::RemoveBlock()
-{
- --count;
- assert(count>=0);
- superregion->RemoveBlock();
-
- // if there's nothing in this region, we can garbage collect the
- // cells to keep memory usage under control
- /* if( count == 0 )
- {
- if( cells )
- {
- // stash this on the pool for reuse
- dead_pool.push_back(cells);
- //printf( "retiring cells @ %p (pool %u)\n", cells, dead_pool.size() );
- cells = NULL;
- }
- else
- PRINT_ERR( "region.count == 0 but cells == NULL" );
- }
- */
-}
-
-SuperRegion::SuperRegion( World* world, point_int_t origin )
- : count(0),
- rwlock(),
- origin(origin),
- regions(),
- world(world)
-{
- pthread_rwlock_init(&rwlock,NULL);
-
- for( int32_t c=0; c<SUPERREGIONSIZE;++c)
- regions[c].superregion = this;
-}
-
-SuperRegion::~SuperRegion()
-{
-}
-
-
-void SuperRegion::AddBlock()
-{
- ++count;
- assert(count>0);
-}
-
-void SuperRegion::RemoveBlock()
-{
- --count;
- assert(count>=0);
-}
-
-
-void SuperRegion::DrawOccupancy( unsigned int layer ) const
-{
- //printf( "SR origin (%d,%d) this %p\n", origin.x, origin.y, this );
-
- glPushMatrix();
- GLfloat scale = 1.0/world->Resolution();
- glScalef( scale, scale, 1.0 ); // XX TODO - this seems slightly
- glTranslatef( origin.x<<SRBITS, origin.y<<SRBITS,0);
-
- glEnable( GL_DEPTH_TEST );
- glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
-
- // outline superregion
- glColor3f( 0,0,1 );
- glRecti( 0,0, 1<<SRBITS, 1<<SRBITS );
-
- // outline regions
- if( regions )
- {
- const Region* r = &regions[0];
- char buf[32];
-
- switch( layer )
- {
- case 0: // moveable 1
- glColor3f( 0,1,0 );
- break;
- case 1: // moveable 2
- glTranslatef( 0.05, 0.05, 0);
- glColor3f( 0,0,1 );
- break;
-// case 2: // fixed
-// glTranslatef( 0.1, 0.1, 0);
-// glColor3f( 1,0,0 );
-// break;
- default:
- PRINT_ERR1( "error: wrong layer %d", layer );
- }
-
- for( int y=0; y<SUPERREGIONWIDTH; ++y )
- for( int x=0; x<SUPERREGIONWIDTH; ++x )
- {
- if( r->count ) // region contains some occupied cells
- {
- // outline the region
- glRecti( x<<RBITS, y<<RBITS,
- (x+1)<<RBITS, (y+1)<<RBITS );
-
- // show how many cells are occupied
- snprintf( buf, 15, "%lu", r->count );
- Gl::draw_string( x<<RBITS, y<<RBITS, 0, buf );
-
- // draw a rectangle around each occupied cell
- for( int p=0; p<REGIONWIDTH; ++p )
- for( int q=0; q<REGIONWIDTH; ++q )
- if( r->cells[p+(q*REGIONWIDTH)].blocks[layer].size() )
- {
- GLfloat xx = p+(x<<RBITS);
- GLfloat yy = q+(y<<RBITS);
- glRecti( xx, yy, xx+1, yy+1);
- }
- }
- /* else if( r->cells ) // empty but used previously
- {
- double left = x << RBITS;
- double right = (x+1) << RBITS;
- double bottom = y << RBITS;
- double top = (y+1) << RBITS;
-
- double d = 3.0;
-
- // draw little corner markers for regions with memory
- // allocated but no contents
- glBegin( GL_LINES );
- glVertex2f( left, bottom );
- glVertex2f( left+d, bottom );
- glVertex2f( left, bottom );
- glVertex2f( left, bottom+d );
- glVertex2f( left, top );
- glVertex2f( left+d, top );
- glVertex2f( left, top );
- glVertex2f( left, top-d );
- glVertex2f( right, top );
- glVertex2f( right-d, top );
- glVertex2f( right, top );
- glVertex2f( right, top-d );
- glVertex2f( right, bottom );
- glVertex2f( right-d, bottom );
- glVertex2f( right, bottom );
- glVertex2f( right, bottom+d );
- glEnd();
- }
- */
- ++r; // next region quickly
- }
- }
- else
- { // outline region-collected superregion
- glColor3f( 1,1,0 );
- glRecti( 0,0, (1<<SRBITS)-1, (1<<SRBITS)-1 );
- glColor3f( 0,0,1 );
- }
-
- char buf[32];
- snprintf( buf, 15, "%lu", count );
- Gl::draw_string( 1<<SBITS, 1<<SBITS, 0, buf );
-
- glPopMatrix();
-}
-
-
-static inline void DrawBlock( GLfloat x, GLfloat y, GLfloat zmin, GLfloat zmax )
-{
- glBegin( GL_QUADS );
-
- // TOP
- glVertex3f( x, y, zmax );
- glVertex3f( 1+x, y, zmax );
- glVertex3f( 1+x, 1+y, zmax );
- glVertex3f( x, 1+y, zmax );
-
- // sides
- glVertex3f( x, y, zmax );
- glVertex3f( x, 1+y, zmax );
- glVertex3f( x, 1+y, zmin );
- glVertex3f( x, y, zmin );
-
- glVertex3f( 1+x, y, zmax );
- glVertex3f( x, y, zmax );
- glVertex3f( x, y, zmin );
- glVertex3f( 1+x, y, zmin );
-
- glVertex3f( 1+x, 1+y, zmax );
- glVertex3f( 1+x, y, zmax );
- glVertex3f( 1+x, y, zmin );
- glVertex3f( 1+x, 1+y, zmin );
-
- glVertex3f( x, 1+y, zmax );
- glVertex3f( 1+x, 1+y, zmax );
- glVertex3f( 1+x, 1+y, zmin );
- glVertex3f( x, 1+y, zmin );
-
- glEnd();
-}
-
-void SuperRegion::DrawVoxels(unsigned int layer) const
-{
- glPushMatrix();
- GLfloat scale = 1.0/world->Resolution();
- glScalef( scale, scale, 1.0 ); // XX TODO - this seems slightly
- glTranslatef( origin.x<<SRBITS, origin.y<<SRBITS,0);
-
-
- glEnable( GL_DEPTH_TEST );
- glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
-
- const Region* r = &regions[0];
-
- for( int y=0; y<SUPERREGIONWIDTH; ++y )
- for( int x=0; x<SUPERREGIONWIDTH; ++x )
- {
- if( r->count )
- for( int p=0; p<REGIONWIDTH; ++p )
- for( int q=0; q<REGIONWIDTH; ++q )
- {
- const std::vector<Block*>& blocks =
- r->cells[p+(q*REGIONWIDTH)].blocks[layer];
-
- if( blocks.size() )
- {
- GLfloat xx = p+(x<<RBITS);
- GLfloat yy = q+(y<<RBITS);
-
- FOR_EACH( it, blocks )
- {
- Block* block = *it;
- // first draw filled polygons
- Color c = block->GetColor();
- glColor4f( c.r, c.g, c.b, 1.0 );
-
- glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
- glEnable(GL_POLYGON_OFFSET_FILL);
- // TODO - these numbers need tweaking for
- // better-looking rendering
- glPolygonOffset(0.01, 0.1);
- DrawBlock( xx, yy, block->global_z.min, block->global_z.max );
-
- // draw again in outline
- glDisable(GL_POLYGON_OFFSET_FILL);
- glColor4f( c.r/2.0, c.g/2.0, c.b/2.0, c.a );
- glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
- DrawBlock( xx, yy, block->global_z.min, block->global_z.max );
- }
- }
- }
-
- ++r;
- }
- glPopMatrix();
-}
-
-
-//std::set<Block*> mapped_blocks;
-
-void Cell::AddBlock( Block* b, unsigned int layer )
-{
- assert( layer < 2 );
- blocks[layer].push_back( b );
- b->rendered_cells[layer].push_back(this);
- region->AddBlock();
-}
-
-void Cell::RemoveBlock( Block* b, unsigned int layer )
-{
- assert( layer<2 );
-
- std::vector<Block*>& blks = blocks[layer];
-
- size_t len = blks.size();
- if( len )
- {
-#if 1
- // Use conventional STL style
-
- // this special-case test is faster for worlds with simple models,
- // which are the ones we want to be really fast. It's a small
- // extra cost for worlds with several models in each cell. It
- // gives a 5% overall speed increase in fasr.world.
-
- if( (blks.size() == 1) &&
- (blks[0] == b) ) // special but common case
- {
- blks.clear(); // cheap
- }
- else // the general but relatively expensive case
- {
- EraseAll( b, blks );
- }
-#else // attempt faster removal loop
- // O(n) * low constant array element removal
- // this C-style pointer work looks to be very slightly faster than the STL way
- Block **start = &blks[0]; // start of array
- Block **r = &blks[0]; // read from here
- Block **w = &blks[0]; // write to here
-
- while( r < start + len ) // scan down array, skipping 'this'
- {
- if( *r != b )
- *w++ = *r;
- ++r;
- }
- blks.resize( w-start );
-#endif
- }
-
- region->RemoveBlock();
-}
View
7 libstage/stage.hh
@@ -2434,10 +2434,9 @@ namespace Stg
{
return( ( GetGlobalPose() + geom.pose ) + pose );
}
-
- /** Fill an array of global pixels from an array of local points. */
- void LocalToPixels( const std::vector<point_t>& local,
- std::vector<point_int_t>& pixels) const;
+
+ /** Return a vector of global pixels corresponding to a vector of local points. */
+ std::vector<point_int_t> LocalToPixels( const std::vector<point_t>& local ) const;
/** Return the 2d point in world coordinates of a 2d point
specified in the model's local coordinate system */
View
26 libstage/world.cc
@@ -738,6 +738,7 @@ void World::ClearRays()
ray_list.clear();
}
+// Perform multiple raytraces evenly spaced over an angular field of view
void World::Raytrace( const Pose &gpose, // global pose
const meters_t range,
const radians_t fov,
@@ -830,6 +831,9 @@ RaytraceResult World::Raytrace( const Ray& r )
// Stage spends up to 95% of its time in this loop! It would be
// neater with more function calls encapsulating things, but even
// inline calls have a noticeable (2-3%) effect on performance.
+
+ // several useful asserts are commented out so that Stage is not too
+ // slow in debug builds. Add them in if chasing a suspected raytrace bug
while( n > 0 ) // while we are still not at the ray end
{
SuperRegion* sr( GetSuperRegion(point_int_t(GETSREG(globx),GETSREG(globy))));
@@ -848,7 +852,9 @@ RaytraceResult World::Raytrace( const Ray& r )
int32_t cy( GETCELL(globy) );
Cell* c( &reg->cells[ cx + cy * REGIONWIDTH ] );
- assert(c); // should be good: we know the region contains objects
+
+ // this assert makes Stage slow when compiled for debug
+ // assert(c); // should be good: we know the region contains objects
// while within the bounds of this region and while some ray remains
// we'll tweak the cell pointer directly to move around quickly
@@ -859,7 +865,7 @@ RaytraceResult World::Raytrace( const Ray& r )
FOR_EACH( it, c->blocks[layer] )
{
Block* block( *it );
- assert( block );
+ // assert( block );
// skip if not in the right z range
if( r.ztest &&
@@ -1011,6 +1017,7 @@ void World::Reload( void )
ForEachDescendant( _reload_cb, NULL );
}
+// add a block to each cell described by a polygon in world coordinates
void World::MapPoly( const std::vector<point_int_t>& pts, Block* block, unsigned int layer )
{
const size_t pt_count( pts.size() );
@@ -1043,9 +1050,7 @@ void World::MapPoly( const std::vector<point_int_t>& pts, Block* block, unsigned
GETSREG(globy)))
->GetRegion( GETREG(globx),
GETREG(globy)));
- assert(reg);
-
- //printf( "REGION %p\n", reg );
+ // assert(reg);
// add all the required cells in this region before looking up
// another region
@@ -1091,22 +1096,15 @@ SuperRegion* World::AddSuperRegion( const point_int_t& sup )
{
SuperRegion* sr( CreateSuperRegion( sup ) );
- //printf( "Created super region [%d, %d] %p\n", sup.x, sup.y, sr );
-
- // the bounds of the world have changed
- //printf( "lower left (%.2f,%.2f,%.2f)\n", pt.x, pt.y, pt.z );
-
// set the lower left corner of the new superregion
Extend( point3_t( (sup.x << SRBITS) / ppm,
(sup.y << SRBITS) / ppm,
0 ));
-
+
// top right corner of the new superregion
Extend( point3_t( ((sup.x+1) << SRBITS) / ppm,
((sup.y+1) << SRBITS) / ppm,
- 0 ));
- //printf( "top right (%.2f,%.2f,%.2f)\n", pt.x, pt.y, pt.z );
-
+ 0 ));
return sr;
}
Please sign in to comment.
Something went wrong with that request. Please try again.