Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

replaced some c-strings with std::strings

  • Loading branch information...
commit 996c281279c4396bc3c3de0d81fc0cc41e5b807b 1 parent f41586a
rtv authored
View
1  CMakeLists.txt
@@ -31,7 +31,6 @@ SET (PROJECT_CMAKE_DIR ${PROJECT_SOURCE_DIR}/cmake CACHE PATH "Location of CMake
# Determine the operating system in detail
INCLUDE (${PROJECT_CMAKE_DIR}/internal/FindOS.cmake)
-
# Enable -Wall by default unless on Win or Solaris
IF (NOT PROJECT_OS_WIN AND NOT PROJECT_OS_SOLARIS)
# Using -Wall on Windows causes MSVC to produce thousands of warnings in its
View
3  INSTALL.txt
@@ -9,8 +9,9 @@ become more portable.
Dependencies
------------
-Building Stage requires the following libraries:
+Building Stage requires the following tools and libraries:
+- pkg-config
- FLTK 1.1.x
- OpenGL
- libpng
View
22 RELEASE.txt
@@ -1,3 +1,25 @@
+Version 3.2.0
+-------------
+
+This minor release fixes many bugs, has some performance improvements
+and some significant internal and API changes, including:
+
+* introduced an internal event queue, so that there is no longer any
+ atomic world update interval. Each model can have its update
+ interval specified individually
+* worldfile syntax checking improved: poses and sizes are checked for
+ correct vector length
+* pkg-config file for libstage now contains correct dependencies,
+ making it much easier to build things using libstage
+* controllers can now take an argument string from the worldfile and
+ command line
+* better powerpack model
+* cleaned up namespace quite a bit - controllers and simulators using
+ libstage may need some simple tweaks, but the design is cleaner and
+ more consistent.
+
+Richard Vaughan (rtv) vaughan@sfu.ca - 2009.9.12
+
Version 3.1.0
-------------
View
5 examples/ctrl/CMakeLists.txt
@@ -1,14 +1,13 @@
SET( PLUGINS
- # convoy
fasr
- # fasr2
lasernoise
sink
source
wander
+ wander_pioneer
pioneer_flocking
-# rasterize
+ rasterize
)
# need plaer's wavefront planning library for this one
View
2  examples/ctrl/fasr.cc
@@ -493,7 +493,7 @@ class Robot
};
// Stage calls this when the model starts up
-extern "C" int Init( Model* mod, char* str )
+extern "C" int Init( Model* mod, CtrlArgs* args )
{
#if 1
// example using the model rasterizer
View
4 examples/ctrl/pioneer_flocking.cc
@@ -46,13 +46,13 @@ extern "C" int Init( Model* mod )
robot->position = (ModelPosition*)mod;
// subscribe to the ranger, which we use for navigating
- robot->ranger = (ModelRanger*)mod->GetModel( "ranger:0" );
+ robot->ranger = (ModelRanger*)mod->GetUnusedModelOfType( "ranger" );
assert( robot->ranger );
// ask Stage to call into our ranger update function
robot->ranger->AddUpdateCallback( (stg_model_callback_t)RangerUpdate, robot );
- robot->fiducial = (ModelFiducial*)mod->GetModel( "fiducial:0" ) ;
+ robot->fiducial = (ModelFiducial*)mod->GetUnusedModelOfType( "fiducial" ) ;
assert( robot->fiducial );
robot->fiducial->AddUpdateCallback( (stg_model_callback_t)FiducialUpdate, robot );
View
5 examples/ctrl/wander.cc
@@ -35,13 +35,12 @@ extern "C" int Init( Model* mod, CtrlArgs* args )
robot->randcount = 0;
robot->pos = (ModelPosition*)mod;
- robot->laser = (ModelLaser*)mod->GetModel( "laser:0" );
+ robot->laser = (ModelLaser*)mod->GetChild( "laser:0" );
robot->laser->AddUpdateCallback( (stg_model_callback_t)LaserUpdate, robot );
robot->laser->Subscribe(); // starts the laser updates
robot->pos->Subscribe(); // starts the position updates
-
-
+
return 0; //ok
}
View
4 examples/ctrl/wander_pioneer.cc
@@ -47,12 +47,12 @@ extern "C" int Init( Model* mod )
robot->position = (ModelPosition*)mod;
assert( robot->ranger );
- robot->ranger = (ModelRanger*)mod->GetModel( "ranger:0" );
+ robot->ranger = (ModelRanger*)mod->GetUnusedModelOfType( "ranger" );
assert( robot->ranger );
// ask Stage to call into our ranger update function whenever the ranger is updated
robot->ranger->AddUpdateCallback( (stg_model_callback_t)RangerUpdate, robot );
- robot->fiducial = (ModelFiducial*)mod->GetModel( "fiducial:0" ) ;
+ robot->fiducial = (ModelFiducial*)mod->GetUnusedModelOfType( "fiducial" ) ;
assert( robot->fiducial );
// ask Stage to call into our fiducial update function whenever the fiducial is updated
robot->fiducial->AddUpdateCallback( (stg_model_callback_t)FiducialUpdate, robot );
View
10 libstage/CMakeLists.txt
@@ -4,7 +4,6 @@ MESSAGE( STATUS "Configuring libstage" )
include_directories(${PROJECT_BINARY_DIR})
set( stageSrcs
- ancestor.cc
block.cc
blockgroup.cc
camera.cc
@@ -18,17 +17,17 @@ set( stageSrcs
model_blinkenlight.cc
model_blobfinder.cc
model_callbacks.cc
- model_draw.cc
model_camera.cc
+ model_draw.cc
model_fiducial.cc
model_getset.cc
model_gripper.cc
model_laser.cc
+ model_lightindicator.cc
model_load.cc
model_position.cc
model_props.cc
model_ranger.cc
- model_lightindicator.cc
option.cc
powerpack.cc
region.cc
@@ -36,13 +35,14 @@ set( stageSrcs
stage.hh
texture_manager.cc
typetable.cc
- vis_strip.cc
world.cc
worldfile.cc
- worldgui.cc
canvas.cc
options_dlg.cc
options_dlg.hh
+ vis_strip.cc
+ worldgui.cc
+ ancestor.cc
)
set_source_files_properties( ${stageSrcs} PROPERTIES COMPILE_FLAGS "${FLTK_CFLAGS}" )
View
40 libstage/ancestor.cc
@@ -1,11 +1,13 @@
+#include <sstream> // for converting values to strings
+
#include "stage.hh"
using namespace Stg;
-//using names
+
Ancestor::Ancestor() :
children(),
debug( false ),
- token( NULL ),
+ token(),
access_mutex(),
child_type_counts()
{
@@ -29,31 +31,23 @@ void Ancestor::AddChild( Model* mod )
}
// poke a name into the child
- static char* buf = new char[TOKEN_MAX]; // allocated once
+ std::ostringstream name;
// printf( "adding child of type %d token %s\n", mod->type, mod->Token() );
- std::string typestr = mod->type;
-
- if( token ) // if this object has a name, use it
- snprintf( buf, TOKEN_MAX, "%s.%s:%d",
- token,
- typestr.c_str(),
- child_type_counts[mod->type] );
- else
- snprintf( buf, TOKEN_MAX, "%s:%d",
- typestr.c_str(),
- child_type_counts[mod->type] );
-
- //printf( "%s generated a name for my child %s\n", token, buf );
-
- mod->SetToken( buf );
-
+ // if this object has a name, use it
+ if( token.size() )
+ name << this->token << '.';
+
+ name << mod->type << ':' << child_type_counts[mod->type];
+
+ // printf( "%s generated a name for my child %s\n", Token(), name.str().c_str() );
+
+ mod->SetToken( name.str() );
+
children.push_back( mod );
-
- child_type_counts[mod->type]++;
-
- //delete[] buf; // no need to free the statically allocated buffer
+
+ child_type_counts[mod->type]++;
}
void Ancestor::RemoveChild( Model* mod )
View
39 libstage/block.cc
@@ -43,7 +43,7 @@ Block::Block( Model* mod,
mpts(),
pt_count(0),
pts(),
- color(0),
+ color(),
inherit_color(true),
rendered_cells( new CellPtrVec ),
candidate_cells( new CellPtrVec )
@@ -408,39 +408,6 @@ void Block::DrawFootPrint()
glEnd();
}
-void Block::Draw( Model* mod )
-{
- // draw filled color polygons
- Color col = inherit_color ? mod->color : color;
-
- col.Print( "block color" );
-
- mod->PushColor( col );
- glEnable(GL_POLYGON_OFFSET_FILL);
- glPolygonOffset(1.0, 1.0);
- DrawSides();
- DrawTop();
- glDisable(GL_POLYGON_OFFSET_FILL);
-
- // draw the block outline in a darker version of the same color
- mod->PushColor( Color( col.r/2.0, col.g/2.0, col.b/2.0, col.a ));
-
- glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
- glDepthMask(GL_FALSE);
- DrawTop();
- DrawSides();
- glDepthMask(GL_TRUE);
- glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
-
- if( glow > 0.0 )
- {
-
- }
-
- mod->PopColor();
- mod->PopColor();
-}
-
void Block::DrawSolid()
{
DrawSides();
@@ -468,8 +435,8 @@ void Block::Load( Worldfile* wf, int entity )
local_z.min = wf->ReadTupleLength( entity, "z", 0, 0.0 );
local_z.max = wf->ReadTupleLength( entity, "z", 1, 1.0 );
- const char* colorstr = wf->ReadString( entity, "color", NULL );
- if( colorstr )
+ const std::string& colorstr = wf->ReadString( entity, "color", "" );
+ if( colorstr != "" )
{
color = Color( colorstr );
inherit_color = false;
View
6 libstage/blockgroup.cc
@@ -248,19 +248,19 @@ void BlockGroup::LoadBlock( Model* mod, Worldfile* wf, int entity )
AppendBlock( new Block( mod, wf, entity ));
}
-void BlockGroup::LoadBitmap( Model* mod, const char* bitmapfile, Worldfile* wf )
+void BlockGroup::LoadBitmap( Model* mod, const std::string& bitmapfile, Worldfile* wf )
{
PRINT_DEBUG1( "attempting to load bitmap \"%s\n", bitmapfile );
char full[_POSIX_PATH_MAX];
if( bitmapfile[0] == '/' )
- strcpy( full, bitmapfile );
+ strncpy( full, bitmapfile.c_str(), _POSIX_PATH_MAX );
else
{
char *tmp = strdup(wf->filename.c_str());
snprintf( full, _POSIX_PATH_MAX,
- "%s/%s", dirname(tmp), bitmapfile );
+ "%s/%s", dirname(tmp), bitmapfile.c_str() );
free(tmp);
}
View
2  libstage/canvas.cc
@@ -66,7 +66,7 @@ Canvas::Canvas( WorldGui* world,
starty( -1 ),
selected_models(),
last_selection( NULL ),
- interval( 20 ), // msec between redraws
+ interval( 40 ), // msec between redraws
// initialize Option objects
// showBlinken( "Blinkenlights", "show_blinkenlights", "", true, world ),
showBBoxes( "Debug/Bounding boxes", "show_boundingboxes", "^b", false, world ),
View
7 libstage/color.cc
@@ -21,13 +21,10 @@ bool Color::operator!=( const Color& other )
fabs(a-other.a) > epsilon );
}
-Color::Color( const char *name) :
+Color::Color( const std::string& name) :
r(1), g(0), b(0), a(1)
{
- if( name == NULL ) // no string?
- return; // red
-
- if( strcmp( name, "" ) == 0 ) // empty string?
+ if( name == "" ) // empty string?
return; // red
static FILE *file = NULL;
View
74 libstage/model.cc
@@ -274,7 +274,7 @@ Model::Model( World* world,
props(),
rastervis(),
rebuild_displaylist(true),
- say_string(NULL),
+ say_string(),
stall(false),
subs(0),
thread_safe( false ),
@@ -282,7 +282,7 @@ Model::Model( World* world,
trail_length(50),
trail_interval(5),
type(type),
- event_queue_num( -1 ),
+ event_queue_num( 0 ),
used(false),
velocity(),
watts(0.0),
@@ -296,10 +296,10 @@ Model::Model( World* world,
//assert( modelsbyid );
assert( world );
- PRINT_DEBUG3( "Constructing model world: %s parent: %s type: %d ",
- world->Token(),
- parent ? parent->Token() : "(null)",
- type );
+ PRINT_DEBUG3( "Constructing model world: %s parent: %s type: %s \n",
+ world->Token(),
+ parent ? parent->Token() : "(null)",
+ type.c_str() );
modelsbyid[id] = this;
@@ -310,7 +310,7 @@ Model::Model( World* world,
else
{
world->AddChild( this );
- // top level models are draggable in the GUI
+ // top level models are draggable in the GUI by default
gui.move = true;
}
@@ -323,7 +323,7 @@ Model::Model( World* world,
AddVisualizer( &rastervis, false );
- PRINT_DEBUG2( "finished model %s @ %p", this->token, this );
+ PRINT_DEBUG2( "finished model %s @ %p", this->Token(), this );
}
Model::~Model( void )
@@ -355,8 +355,7 @@ void Model::Init()
// find the queue for update events: zero if thread safe, else we
// ask the world to assign us to a queue
- if( event_queue_num < 1 )
- event_queue_num = thread_safe ? world->GetEventQueue( this ) : 0;
+ event_queue_num = thread_safe ? world->GetEventQueue( this ) : 0;
CallCallbacks( &hooks.init );
@@ -366,7 +365,7 @@ void Model::Init()
void Model::InitRecursive()
{
- // init children first
+ // must init children first
FOR_EACH( it, children )
(*it)->InitRecursive();
@@ -541,11 +540,9 @@ Pose Model::GlobalToLocal( const Pose& pose ) const
}
-void Model::Say( const char* str )
+void Model::Say( const std::string& str )
{
- if( say_string )
- free( say_string );
- say_string = strdup( str );
+ say_string = str;
}
// returns true iff model [testmod] is an antecedent of this model
@@ -673,12 +670,12 @@ void Model::Print( char* prefix ) const
printf( "%s model ", prefix );
else
printf( "Model ");
-
+
printf( "%s:%s\n",
- // id,
- world->Token(),
- token );
-
+ // id,
+ world->Token(),
+ token.c_str() );
+
FOR_EACH( it, children )
(*it)->Print( prefix );
}
@@ -689,8 +686,8 @@ const char* Model::PrintWithPose() const
static char txt[256];
snprintf(txt, sizeof(txt), "%s @ [%.2f,%.2f,%.2f,%.2f]",
- token,
- gpose.x, gpose.y, gpose.z, gpose.a );
+ token.c_str(),
+ gpose.x, gpose.y, gpose.z, gpose.a );
return txt;
}
@@ -975,22 +972,6 @@ stg_kg_t Model::GetMassOfChildren()
return( GetTotalMass() - mass);
}
-Model* Model::GetModel( const char* modelname ) const
-{
- // construct the full model name and look it up
- char* buf = new char[TOKEN_MAX];
- snprintf( buf, TOKEN_MAX, "%s.%s", this->token, modelname );
-
- Model* mod = world->GetModel( buf );
-
- if( mod == NULL )
- PRINT_WARN1( "Model %s not found", buf );
-
- delete[] buf;
-
- return mod;
-}
-
void Model::UnMap()
{
blockgroup.UnMap();
@@ -1047,6 +1028,23 @@ void Model::SetFriction( double friction )
CallCallbacks( &this->friction );
}
+Model* Model::GetChild( const std::string& modelname ) const
+{
+ // construct the full model name and look it up
+ //char* buf = new char[TOKEN_MAX];
+ //snprintf( buf, TOKEN_MAX, "%s.%s", this->token, modelname );
+
+ std::string fullname = token + "." + modelname;
+
+ Model* mod = world->GetModel( fullname );
+
+ if( mod == NULL )
+ PRINT_WARN1( "Model %s not found", fullname.c_str() );
+
+ return mod;
+}
+
+
//***************************************************************
// Raster data visualizer
//
View
37 libstage/model_actuator.cc
@@ -87,28 +87,25 @@ ModelActuator::~ModelActuator( void )
void ModelActuator::Load( void )
{
- Model::Load();
- InitialPose = GetPose();
-
- // load steering mode
- if( wf->PropertyExists( wf_entity, "type" ) )
- {
- const char* type_str =
- wf->ReadString( wf_entity, "type", NULL );
-
- if( type_str )
- {
- if( strcmp( type_str, "linear" ) == 0 )
- actuator_type = TYPE_LINEAR;
- else if( strcmp( type_str, "rotational" ) == 0 )
- actuator_type = TYPE_ROTATIONAL;
- else
+ Model::Load();
+ InitialPose = GetPose();
+
+ // load steering mode
+ if( wf->PropertyExists( wf_entity, "type" ) )
+ {
+ const std::string& type_str =
+ wf->ReadString( wf_entity, "type", "linear" );
+
+ if( type_str == "linear" )
+ actuator_type = TYPE_LINEAR;
+ else if ( type_str == "rotational" )
+ actuator_type = TYPE_ROTATIONAL;
+ else
{
- PRINT_ERR1( "invalid actuator type specified: \"%s\" - should be one of: \"linear\" or \"rotational\". Using \"linear\" as default.", type_str );
+ PRINT_ERR1( "invalid actuator type specified: \"%s\" - should be one of: \"linear\" or \"rotational\". Using \"linear\" as default.", type_str.c_str() );
}
- }
- }
-
+ }
+
if (actuator_type == TYPE_LINEAR)
{
// if we are a linear actuator find the axis we operate in
View
202 libstage/model_draw.cc
@@ -19,7 +19,7 @@ void Model::DrawSelected()
char buf[64];
snprintf( buf, 63, "%s [%.2f %.2f %.2f %.2f]",
- token, gpose.x, gpose.y, gpose.z, rtod(gpose.a) );
+ token.c_str(), gpose.x, gpose.y, gpose.z, rtod(gpose.a) );
PushColor( 0,0,0,1 ); // text color black
Gl::draw_string( 0.5,0.5,0.5, buf );
@@ -50,52 +50,52 @@ void Model::DrawSelected()
void Model::DrawTrailFootprint()
{
- double darkness = 0;
- double fade = 0.5 / (double)(trail_length+1);
+ 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 pushL just saving the color
- FOR_EACH( it, trail )
- {
- TrailItem& checkpoint = *it;
+ FOR_EACH( it, trail )
+ {
+ TrailItem& checkpoint = *it;
- glPushMatrix();
- Pose pz = checkpoint.pose;
+ glPushMatrix();
+ Pose pz = checkpoint.pose;
- Gl::pose_shift( pz );
- Gl::pose_shift( geom.pose );
+ Gl::pose_shift( pz );
+ Gl::pose_shift( geom.pose );
- darkness += fade;
- Color c = checkpoint.color;
- c.a = darkness;
- glColor4f( c.r, c.g, c.b, c.a );
+ darkness += fade;
+ Color c = checkpoint.color;
+ c.a = darkness;
+ glColor4f( c.r, c.g, c.b, c.a );
- blockgroup.DrawFootPrint( geom );
+ blockgroup.DrawFootPrint( geom );
- glPopMatrix();
+ glPopMatrix();
}
- PopColor();
+ PopColor();
}
void Model::DrawTrailBlocks()
{
double timescale = 0.0000001;
- FOR_EACH( it, trail )
- {
- TrailItem& checkpoint = *it;
+ FOR_EACH( it, trail )
+ {
+ TrailItem& checkpoint = *it;
- glPushMatrix();
- Pose pz = checkpoint.pose;
- pz.z = (world->sim_time - checkpoint.time) * timescale;
+ glPushMatrix();
+ Pose pz = checkpoint.pose;
+ pz.z = (world->sim_time - checkpoint.time) * timescale;
- Gl::pose_shift( pz );
- Gl::pose_shift( geom.pose );
+ Gl::pose_shift( pz );
+ Gl::pose_shift( geom.pose );
- DrawBlocks();
+ DrawBlocks();
- glPopMatrix();
+ glPopMatrix();
}
}
@@ -283,7 +283,7 @@ void Model::DrawStatusTree( Camera* cam )
void Model::DrawStatus( Camera* cam )
{
- if( say_string || power_pack )
+ if( power_pack || !say_string.empty() )
{
float yaw, pitch;
pitch = - cam->pitch();
@@ -302,70 +302,70 @@ void Model::DrawStatus( Camera* cam )
glRotatef( -pitch, 1,0,0 );
if( power_pack )
- power_pack->Visualize( cam );
+ power_pack->Visualize( cam );
- if( say_string )
- {
- glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
-
- //get raster positition, add gl_width, then project back to world coords
- glRasterPos3f( 0, 0, 0 );
- GLfloat pos[ 4 ];
- glGetFloatv(GL_CURRENT_RASTER_POSITION, pos);
-
- GLboolean valid;
- glGetBooleanv( GL_CURRENT_RASTER_POSITION_VALID, &valid );
+ if( !say_string.empty() )
+ {
+ glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
+
+ //get raster positition, add gl_width, then project back to world coords
+ glRasterPos3f( 0, 0, 0 );
+ GLfloat pos[ 4 ];
+ glGetFloatv(GL_CURRENT_RASTER_POSITION, pos);
+
+ GLboolean valid;
+ glGetBooleanv( GL_CURRENT_RASTER_POSITION_VALID, &valid );
- if( valid )
- {
- //fl_font( FL_HELVETICA, 12 );
- float w = gl_width( this->say_string ); // scaled text width
- float h = gl_height(); // scaled text height
-
- GLdouble wx, wy, wz;
- GLint viewport[4];
- glGetIntegerv(GL_VIEWPORT, viewport);
+ if( valid )
+ {
+ //fl_font( FL_HELVETICA, 12 );
+ float w = gl_width( this->say_string.c_str() ); // scaled text width
+ float h = gl_height(); // scaled text height
+
+ GLdouble wx, wy, wz;
+ GLint viewport[4];
+ glGetIntegerv(GL_VIEWPORT, viewport);
+
+ GLdouble modelview[16];
+ glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
+
+ GLdouble projection[16];
+ glGetDoublev(GL_PROJECTION_MATRIX, projection);
- GLdouble modelview[16];
- glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
+ //get width and height in world coords
+ gluUnProject( pos[0] + w, pos[1], pos[2], modelview, projection, viewport, &wx, &wy, &wz );
+ w = wx;
+ gluUnProject( pos[0], pos[1] + h, pos[2], modelview, projection, viewport, &wx, &wy, &wz );
+ h = wy;
- GLdouble projection[16];
- glGetDoublev(GL_PROJECTION_MATRIX, projection);
+ // calculate speech bubble margin
+ const float m = h/10;
- //get width and height in world coords
- gluUnProject( pos[0] + w, pos[1], pos[2], modelview, projection, viewport, &wx, &wy, &wz );
- w = wx;
- gluUnProject( pos[0], pos[1] + h, pos[2], modelview, projection, viewport, &wx, &wy, &wz );
- h = wy;
+ // draw inside of bubble
+ PushColor( BUBBLE_FILL );
+ glPushAttrib( GL_POLYGON_BIT | GL_LINE_BIT );
+ glPolygonMode( GL_FRONT, GL_FILL );
+ glEnable( GL_POLYGON_OFFSET_FILL );
+ glPolygonOffset( 1.0, 1.0 );
+ Gl::draw_octagon( w, h, m );
+ glDisable( GL_POLYGON_OFFSET_FILL );
+ PopColor();
- // calculate speech bubble margin
- const float m = h/10;
+ // draw outline of bubble
+ PushColor( BUBBLE_BORDER );
+ glLineWidth( 1 );
+ glEnable( GL_LINE_SMOOTH );
+ glPolygonMode( GL_FRONT, GL_LINE );
+ Gl::draw_octagon( w, h, m );
+ glPopAttrib();
+ PopColor();
- // draw inside of bubble
- PushColor( BUBBLE_FILL );
- glPushAttrib( GL_POLYGON_BIT | GL_LINE_BIT );
- glPolygonMode( GL_FRONT, GL_FILL );
- glEnable( GL_POLYGON_OFFSET_FILL );
- glPolygonOffset( 1.0, 1.0 );
- Gl::draw_octagon( w, h, m );
- glDisable( GL_POLYGON_OFFSET_FILL );
- PopColor();
-
- // draw outline of bubble
- PushColor( BUBBLE_BORDER );
- glLineWidth( 1 );
- glEnable( GL_LINE_SMOOTH );
- glPolygonMode( GL_FRONT, GL_LINE );
- Gl::draw_octagon( w, h, m );
- glPopAttrib();
- PopColor();
-
- PushColor( BUBBLE_TEXT );
- // draw text inside the bubble
- Gl::draw_string( m, 2.5*m, 0, this->say_string );
- PopColor();
- }
- }
+ PushColor( BUBBLE_TEXT );
+ // draw text inside the bubble
+ Gl::draw_string( m, 2.5*m, 0, this->say_string.c_str() );
+ PopColor();
+ }
+ }
glPopMatrix();
}
@@ -375,14 +375,14 @@ void Model::DrawStatus( Camera* cam )
}
// extern GLuint glowTex;
-// extern GLuint checkTex;
+ // extern GLuint checkTex;
-// if( parent == NULL )
-// {
-// glBlendFunc(GL_SRC_COLOR, GL_ONE );
-// DrawImage( glowTex, cam, 1.0 );
-// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
-// }
+ // if( parent == NULL )
+ // {
+ // glBlendFunc(GL_SRC_COLOR, GL_ONE );
+ // DrawImage( glowTex, cam, 1.0 );
+ // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
+ // }
}
void Model::DrawImage( uint32_t texture_id, Camera* cam, float alpha,
@@ -421,14 +421,14 @@ void Model::DrawImage( uint32_t texture_id, Camera* cam, float alpha,
glBindTexture( GL_TEXTURE_2D, 0 );
glDisable(GL_TEXTURE_2D);
-// glPolygonMode( GL_FRONT, GL_LINE );
-// glColor3f( 0,0,1 );
-// glBegin(GL_QUADS);
-// glVertex3f(-0.25f, 0, -0.25f );
-// glVertex3f( 0.25f, 0, -0.25f );
-// glVertex3f( 0.25f, 0, 0.25f );
-// glVertex3f(-0.25f, 0, 0.25f );
-// glEnd();
+ // glPolygonMode( GL_FRONT, GL_LINE );
+ // glColor3f( 0,0,1 );
+ // glBegin(GL_QUADS);
+ // glVertex3f(-0.25f, 0, -0.25f );
+ // glVertex3f( 0.25f, 0, -0.25f );
+ // glVertex3f( 0.25f, 0, 0.25f );
+ // glVertex3f(-0.25f, 0, 0.25f );
+ // glEnd();
glPopMatrix();
}
View
55 libstage/model_load.cc
@@ -54,21 +54,21 @@ void Model::Load()
if( wf->PropertyExists( wf_entity, "debug" ) )
{
PRINT_WARN2( "debug property specified for model %d %s\n",
- wf_entity, this->token );
+ wf_entity, this->token.c_str() );
this->debug = wf->ReadInt( wf_entity, "debug", this->debug );
}
if( wf->PropertyExists( wf_entity, "name" ) )
{
- char *name = (char*)wf->ReadString(wf_entity, "name", NULL );
- if( name )
+ const std::string& name = wf->ReadString(wf_entity, "name", token );
+ if( name != token )
{
//printf( "adding name %s to %s\n", name, this->token );
- this->token = strdup( name );
- world->AddModel( this ); // add this name to the world's table
+ this->token = name ;
+ world->AddModelName( this, name ); // add this name to the world's table
}
else
- PRINT_ERR1( "Name blank for model %s. Check your worldfile\n", this->token );
+ PRINT_ERR1( "Name blank for model %s. Check your worldfile\n", this->token.c_str() );
}
//PRINT_WARN1( "%s::Load", token );
@@ -104,23 +104,22 @@ void Model::Load()
if( wf->PropertyExists( wf_entity, "color" ))
{
Color col( 1,0,0 ); // red;
- const char* colorstr = wf->ReadString( wf_entity, "color", NULL );
- if( colorstr )
- {
- if( strcmp( colorstr, "random" ) == 0 )
- col = Color( drand48(), drand48(), drand48() );
- else
- col = Color( colorstr );
- }
- this->SetColor( col );
- }
-
-
+ 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 );
+ }
+
if( wf->PropertyExists( wf_entity, "color_rgba" ))
{
if (wf->GetProperty(wf_entity,"color_rgba")->values.size() < 4)
{
- PRINT_ERR1( "model %s color_rgba requires 4 values\n", this->token );
+ PRINT_ERR1( "model %s color_rgba requires 4 values\n", this->token.c_str() );
}
else
{
@@ -145,8 +144,9 @@ void Model::Load()
if( wf->PropertyExists( wf_entity, "bitmap" ) )
{
- const char* bitmapfile = wf->ReadString( wf_entity, "bitmap", NULL );
- assert( bitmapfile );
+ const std::string bitmapfile = wf->ReadString( wf_entity, "bitmap", "" );
+ if( bitmapfile == "" )
+ PRINT_WARN1( "model %s specified empty bitmap filename\n", token.c_str() );
if( has_default_block )
{
@@ -206,13 +206,13 @@ void Model::Load()
if( CProperty* ctrlp = wf->GetProperty( wf_entity, "ctrl" ) )
{
- for( int index=0; index < ctrlp->values.size(); index++ )
+ 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 );
+ printf( "Error - NULL library name specified for model %s\n", token.c_str() );
else
LoadControllerModule( lib );
}
@@ -220,7 +220,7 @@ void Model::Load()
if( wf->PropertyExists( wf_entity, "say" ))
- this->Say( wf->ReadString(wf_entity, "say", NULL ));
+ this->Say( wf->ReadString(wf_entity, "say", "" ));
trail_length = wf->ReadInt( wf_entity, "trail_length", trail_length );
trail_interval = wf->ReadInt( wf_entity, "trail_interval", trail_interval );
@@ -234,9 +234,9 @@ void Model::Load()
MapWithChildren();
if( this->debug )
- printf( "Model \"%s\" is in debug mode\n", token );
+ printf( "Model \"%s\" is in debug mode\n", token.c_str() );
- PRINT_DEBUG1( "Model \"%s\" loading complete", token );
+ PRINT_DEBUG1( "Model \"%s\" loading complete", token.c_str() );
}
@@ -340,9 +340,6 @@ void Model::LoadControllerModule( const char* lib )
}
fflush(stdout);
-
- // as we now have a controller, the world needs to call our update function
- //StartUpdating();
}
View
67 libstage/model_position.cc
@@ -119,24 +119,20 @@ void ModelPosition::Load( void )
// load steering mode
if( wf->PropertyExists( wf_entity, "drive" ) )
{
- const char* mode_str =
- wf->ReadString( wf_entity, "drive", NULL );
+ const std::string& mode_str =
+ wf->ReadString( wf_entity, "drive", "diff" );
- if( mode_str )
- {
- if( strcmp( mode_str, "diff" ) == 0 )
- drive_mode = DRIVE_DIFFERENTIAL;
- else if( strcmp( mode_str, "omni" ) == 0 )
- drive_mode = DRIVE_OMNI;
- else if( strcmp( mode_str, "car" ) == 0 )
- drive_mode = DRIVE_CAR;
- else
- {
- PRINT_ERR1( "invalid position drive mode specified: \"%s\" - should be one of: \"diff\", \"omni\" or \"car\". Using \"diff\" as default.", mode_str );
- }
- }
- }
-
+ if( mode_str == "diff" )
+ drive_mode = DRIVE_DIFFERENTIAL;
+ else if( mode_str == "omni" )
+ drive_mode = DRIVE_OMNI;
+ else if( mode_str == "car" )
+ drive_mode = DRIVE_CAR;
+ else
+ PRINT_ERR1( "invalid position drive mode specified: \"%s\" - should be one of: \"diff\", \"omni\" or \"car\". Using \"diff\" as default.", mode_str.c_str() );
+
+ }
+
// load odometry if specified
if( wf->PropertyExists( wf_entity, "odom" ) )
{
@@ -144,7 +140,7 @@ void ModelPosition::Load( void )
" but this property is no longer available."
" Use localization_origin instead. See the position"
" entry in the manual or src/model_position.c for details.",
- this->token );
+ this->token.c_str() );
}
// set the starting pose as my initial odom position. This could be
@@ -190,24 +186,18 @@ void ModelPosition::Load( void )
// choose a localization model
if( wf->PropertyExists( wf_entity, "localization" ) )
{
- const char* loc_str =
- wf->ReadString( wf_entity, "localization", NULL );
-
- if( loc_str )
- {
- if( strcmp( loc_str, "gps" ) == 0 )
- localization_mode = LOCALIZATION_GPS;
- else if( strcmp( loc_str, "odom" ) == 0 )
- localization_mode = LOCALIZATION_ODOM;
- else
- PRINT_ERR2( "unrecognized localization mode \"%s\" for model \"%s\"."
- " Valid choices are \"gps\" and \"odom\".",
- loc_str, this->token );
- }
- else
- PRINT_ERR1( "no localization mode string specified for model \"%s\"",
- this->token );
- }
+ const std::string& loc_str =
+ wf->ReadString( wf_entity, "localization", "gps" );
+
+ if( loc_str == "gps" )
+ localization_mode = LOCALIZATION_GPS;
+ else if( loc_str == "odom" )
+ localization_mode = LOCALIZATION_ODOM;
+ else
+ PRINT_ERR2( "unrecognized localization mode \"%s\" for model \"%s\"."
+ " Valid choices are \"gps\" and \"odom\".",
+ loc_str.c_str(), this->token.c_str() );
+ }
}
void ModelPosition::Update( void )
@@ -400,7 +390,7 @@ void ModelPosition::Update( void )
default:
PRINT_ERR2( "unknown localization mode %d for model %s\n",
- localization_mode, this->token );
+ localization_mode, this->token.c_str() );
break;
}
@@ -654,9 +644,8 @@ ModelPosition::Waypoint::Waypoint( stg_meters_t x, stg_meters_t y, stg_meters_t
ModelPosition::Waypoint::Waypoint()
+ : pose(), color()
{
- pose = Pose( 0,0,0,0 );
- color = 0;
};
View
41 libstage/stage.hh
@@ -218,7 +218,7 @@ namespace Stg
/** Look up the color in the X11-style database. If the color is
not found in the database, a cheerful red color will be used
instead. */
- Color( const char* name );
+ Color( const std::string& name );
Color();
@@ -649,15 +649,15 @@ namespace Stg
protected:
ModelPtrVec children;
bool debug;
- char* token;
+ std::string token;
pthread_mutex_t access_mutex; ///< Used by Lock() and Unlock() to prevent parallel access to this model
void Load( Worldfile* wf, int section );
void Save( Worldfile* wf, int section );
public:
- /** The maximum length of a Stage model identifier string */
- static const uint32_t TOKEN_MAX = 64;
+ /* The maximum length of a Stage model identifier string */
+ //static const uint32_t TOKEN_MAX = 64;
/** get the children of the this element */
ModelPtrVec& GetChildren(){ return children;}
@@ -676,10 +676,13 @@ namespace Stg
virtual Pose GetGlobalPose();
const char* Token()
- { return token; }
+ { return token.c_str(); }
- void SetToken( const char* str )
- { token = strdup( str ); } // minor memory leak
+ //const std::string& Token()
+ //{ return token; }
+
+ void SetToken( const std::string& str )
+ { token = str; }
void Lock(){ pthread_mutex_lock( &access_mutex ); }
void Unlock(){ pthread_mutex_unlock( &access_mutex ); }
@@ -941,6 +944,8 @@ namespace Stg
virtual void AddModel( Model* mod );
virtual void RemoveModel( Model* mod );
+
+ void AddModelName( Model* mod, const std::string& name );
void AddPowerPack( PowerPack* pp );
void RemovePowerPack( PowerPack* pp );
@@ -994,8 +999,8 @@ namespace Stg
public:
/** returns true when time to quit, false otherwise */
static bool UpdateAll();
-
- World( const char* token = "MyWorld",
+
+ World( const std::string& name = "MyWorld",
double ppm = DEFAULT_PPM );
virtual ~World();
@@ -1026,7 +1031,7 @@ namespace Stg
/** Returns a pointer to the model identified by name, or NULL if
nonexistent */
- Model* GetModel( const char* name ) const;
+ Model* GetModel( const std::string& name ) const;
/** Return the 3D bounding box of the world, in meters */
const stg_bounds3d_t& GetExtent(){ return extent; };
@@ -1078,7 +1083,6 @@ namespace Stg
/** draw the block in OpenGL as a solid single color */
void DrawSolid();
- void Draw( Model* mod );
/** draw the projection of the block onto the z=0 plane */
void DrawFootPrint();
@@ -1217,7 +1221,7 @@ namespace Stg
/** Draw the projection of the block onto the z=0 plane. */
void DrawFootPrint( const Geom &geom);
- void LoadBitmap( Model* mod, const char* bitmapfile, Worldfile *wf );
+ void LoadBitmap( Model* mod, const std::string& bitmapfile, Worldfile *wf );
void LoadBlock( Model* mod, Worldfile* wf, int entity );
void Rasterize( uint8_t* data,
@@ -1781,7 +1785,7 @@ namespace Stg
} rastervis;
bool rebuild_displaylist; ///< iff true, regenerate block display list before redraw
- char* say_string; ///< if non-null, this string is displayed in the GUI
+ std::string say_string; ///< if non-null, this string is displayed in the GUI
stg_bool_t stall;
int subs; ///< the number of subscriptions to this model
@@ -1815,7 +1819,7 @@ namespace Stg
const std::string type;
/** The index into the world's vector of event queues. Initially
-1, to indicate that it is not on a list yet. */
- int event_queue_num;
+ unsigned int event_queue_num;
bool used; ///< TRUE iff this model has been returned by GetUnusedModelOfType()
Velocity velocity;
stg_watts_t watts;///< power consumed by this model
@@ -1838,6 +1842,10 @@ namespace Stg
const std::string& GetModelType() const {return type;}
std::string GetSayString(){return std::string(say_string);}
+ /** Returns a pointer to the model identified by name, or NULL if
+ it doesn't exist in this world. */
+ Model* GetChild( const std::string& name ) const;
+
class Visibility
{
public:
@@ -2011,7 +2019,7 @@ namespace Stg
/** Destructor */
virtual ~Model();
- void Say( const char* str );
+ void Say( const std::string& str );
/** Attach a user supplied visualization to a model. */
void AddVisualizer( Visualizer* custom_visual, bool on_by_default );
@@ -2095,9 +2103,6 @@ namespace Stg
model has no parent */
Model* Parent() const { return this->parent; }
- Model* GetModel( const char* name ) const;
- //int GuiMask(){ return this->gui_mask; };
-
/** Returns a pointer to the world that contains this model */
World* GetWorld() const { return this->world; }
View
22 libstage/world.cc
@@ -97,7 +97,7 @@ bool World::quit_all = false;
std::set<World*> World::world_set;
std::string World::ctrlargs;
-World::World( const char* token,
+World::World( const std::string& name,
double ppm )
:
// private
@@ -148,7 +148,7 @@ World::World( const char* token,
World::~World( void )
{
- PRINT_DEBUG2( "destroying world %d %s", id, token );
+ PRINT_DEBUG2( "destroying world %d %s", id, token.c_str() );
if( wf ) delete wf;
World::world_set.erase( this );
}
@@ -310,7 +310,7 @@ void World::Load( const char* worldfile_path )
int entity = 0;
- this->token = (char*)
+ this->token =
wf->ReadString( entity, "name", this->token );
this->quit_time =
@@ -391,7 +391,7 @@ void World::UnLoad()
// todo - clean up regions & superregions?
- token = NULL;
+ token = "[unloaded]";
}
bool World::PastQuitTime()
@@ -549,11 +549,17 @@ bool World::Update()
return false;
}
-void World::AddModel( Model* mod )
+void World::AddModel( Model* mod )
{
models_by_name[mod->token] = mod;
}
+void World::AddModelName( Model* mod, const std::string& name )
+{
+ models_by_name[name] = mod;
+}
+
+
unsigned int World::GetEventQueue( Model* mod )
{
if( worker_threads < 1 )
@@ -561,16 +567,16 @@ unsigned int World::GetEventQueue( Model* mod )
return( (random() % worker_threads) + 1);
}
-Model* World::GetModel( const char* name ) const
+Model* World::GetModel( const std::string& name ) const
{
- PRINT_DEBUG1( "looking up model name %s in models_by_name", name );
+ PRINT_DEBUG1( "looking up model name %s in models_by_name", name.c_str() );
std::map<std::string,Model*>::const_iterator it =
models_by_name.find( name );
if( it == models_by_name.end() )
{
- PRINT_WARN1( "lookup of model name %s: no matching name", name );
+ PRINT_WARN1( "lookup of model name %s: no matching name", name.c_str() );
return NULL;
}
else
View
26 libstage/worldfile.cc
@@ -163,23 +163,23 @@ bool Worldfile::Load(const char *filename)
DumpProperties();
return false;
}
-
+
// Work out what the length units are
- const char *unit = ReadString(0, "unit_length", "m");
- if (strcmp(unit, "m") == 0)
+ const std::string& unitl = ReadString(0, "unit_length", "m");
+ if( unitl == "m")
this->unit_length = 1.0;
- else if (strcmp(unit, "cm") == 0)
+ else if( unitl == "cm")
this->unit_length = 0.01;
- else if (strcmp(unit, "mm") == 0)
+ else if( unitl == "mm")
this->unit_length = 0.001;
-
+
// Work out what the angle units are
- unit = ReadString(0, "unit_angle", "degrees");
- if (strcmp(unit, "degrees") == 0)
+ const std::string& unita = ReadString(0, "unit_angle", "degrees");
+ if( unita == "degrees")
this->unit_angle = M_PI / 180;
- else if (strcmp(unit, "radians") == 0)
+ else if( unita == "radians")
this->unit_angle = 1;
-
+
return true;
}
@@ -1376,7 +1376,7 @@ void Worldfile::DumpProperties()
///////////////////////////////////////////////////////////////////////////
// Read a string
-const char *Worldfile::ReadString(int entity, const char *name, const char *value)
+const std::string Worldfile::ReadString(int entity, const char *name, const std::string& value)
{
CProperty* property = GetProperty(entity, name);
if (property == NULL )
@@ -1387,12 +1387,12 @@ const char *Worldfile::ReadString(int entity, const char *name, const char *valu
///////////////////////////////////////////////////////////////////////////
// Write a string
-void Worldfile::WriteString(int entity, const char *name, const char *value)
+void Worldfile::WriteString(int entity, const char *name, const std::string &value)
{
CProperty* property = GetProperty(entity, name);
if( property == NULL )
return;
- SetPropertyValue(property, 0, value);
+ SetPropertyValue(property, 0, value.c_str());
}
View
6 libstage/worldfile.hh
@@ -85,12 +85,12 @@ namespace Stg {
// Check for unused properties and print warnings
public: bool WarnUnused();
-
+
// Read a string
- public: const char *ReadString(int entity, const char *name, const char *value);
+ public: const std::string ReadString(int entity, const char* name, const std::string& value);
// Write a string
- public: void WriteString(int entity, const char *name, const char *value);
+ public: void WriteString(int entity, const char *name, const std::string& value );
// Read an integer
public: int ReadInt(int entity, const char *name, int value);
View
1  libstageplugin/p_driver.cc
@@ -577,7 +577,6 @@ void StgDriver::Update(void)
switch( interface->addr.interf )
{
case PLAYER_SIMULATION_CODE:
- //world->Update();
// one round of FLTK's update loop.
Fl::wait();
break;
View
4 worlds/benchmark/expand_pioneer.cc
@@ -39,14 +39,14 @@ extern "C" int Init( Model* mod )
assert( robot->position );
// subscribe to the ranger, which we use for navigating
- robot->ranger = (ModelRanger*)mod->GetModel( "ranger:0" );
+ robot->ranger = (ModelRanger*)mod->GetUnusedModelOfType( "ranger" );
assert( robot->ranger );
// ask Stage to call into our ranger update function
robot->ranger->AddUpdateCallback( (stg_model_callback_t)RangerUpdate, robot );
// subscribe to the laser, though we don't use it for navigating
- //robot->laser = (ModelLaser*)mod->GetModel( "laser:0" );
+ //robot->laser = (ModelLaser*)mod->GetUnusedModelOfType( "laser" );
//assert( robot->laser );
// start the models updating
View
4 worlds/benchmark/expand_swarm.cc
@@ -37,7 +37,7 @@ extern "C" int Init( Model* mod )
robot->position = (ModelPosition*)mod;
// subscribe to the ranger, which we use for navigating
- robot->ranger = (ModelRanger*)mod->GetModel( "ranger:0" );
+ robot->ranger = (ModelRanger*)mod->GetUnusedModelOfType( "ranger" );
assert( robot->ranger );
@@ -45,7 +45,7 @@ extern "C" int Init( Model* mod )
robot->ranger->AddUpdateCallback( (stg_model_callback_t)RangerUpdate, robot );
// subscribe to the laser, though we don't use it for navigating
- //robot->laser = (ModelLaser*)mod->GetModel( "laser:0" );
+ //robot->laser = (ModelLaser*)mod->GetUnusedModelofType( "laser" );
//assert( robot->laser );
// start the models updating
View
2  worlds/fasr.world
@@ -28,7 +28,7 @@ window
show_data 1
show_flags 1
- interval 50
+ # interval 50
)
# load an environment bitmap
View
2  worlds/pioneer_flocking.world
@@ -13,7 +13,7 @@ paused 1
resolution 0.1
# this is very helpful if you have multiple CPUs - a good value is $(number of CPU cores) -
-threads 2
+threads 8
# configure the GUI window
window
Please sign in to comment.
Something went wrong with that request. Please try again.