Permalink
Browse files

removing unused code. applied polygon winding patch from Jeff Donner

  • Loading branch information...
1 parent 31e71c9 commit e5a483ca7cebcba8298b350332903ad098ee6d32 rtv committed Dec 1, 2009
Showing with 188 additions and 114 deletions.
  1. +95 −0 libstage/block.cc
  2. +25 −37 libstage/model_load.cc
  3. +2 −0 libstage/region.hh
  4. +9 −3 libstage/stage.hh
  5. +37 −56 libstage/world.cc
  6. +1 −0 todo.txt
  7. +1 −1 worlds/SFU.world
  8. +16 −15 worlds/benchmark/hospital.world
  9. +2 −2 worlds/fasr.world
View
@@ -2,6 +2,10 @@
#include "worldfile.hh"
using namespace Stg;
+using std::vector;
+
+static void canonicalize_winding(vector<stg_point_t>& pts);
+
/** Create a new block. A model's body is a list of these
blocks. The point data is copied, so pts can safely be freed
@@ -32,6 +36,7 @@ Block::Block( Model* mod,
this->pts.reserve( pt_count );
for( size_t p=0; p<pt_count; p++ )
this->pts.push_back( pts[p] );
+ canonicalize_winding(this->pts);
}
/** A from-file constructor */
@@ -52,6 +57,7 @@ Block::Block( Model* mod,
assert(entity);
Load( wf, entity );
+ canonicalize_winding(this->pts);
}
Block::~Block()
@@ -458,3 +464,92 @@ void Block::Load( Worldfile* wf, int entity )
glow = wf->ReadFloat( entity, "glow", glow );
}
+
+static
+/// util; puts angle into [0, 2pi)
+void positivize(stg_radians_t& angle)
+{
+ while (angle < 0) angle += 2 * M_PI;
+}
+
+static
+/// util; puts angle into -pi/2, pi/2
+void pi_ize(stg_radians_t& angle)
+{
+ while (angle < -M_PI) angle += 2 * M_PI;
+ while (M_PI < angle) angle -= 2 * M_PI;
+}
+
+typedef stg_point_t V2;
+
+static
+/// util; How much was v1 rotated to get to v2?
+stg_radians_t angle_change(V2 v1, V2 v2)
+{
+ stg_radians_t a1 = atan2(v1.y, v1.x);
+ positivize(a1);
+
+ stg_radians_t a2 = atan2(v2.y, v2.x);
+ positivize(a2);
+
+ stg_radians_t angle_change = a2 - a1;
+ pi_ize(angle_change);
+
+ return angle_change;
+}
+
+static
+/// util; find vectors between adjacent points, pts[next] - pts[cur]
+vector<stg_point_t> find_vectors(vector<stg_point_t> const& pts)
+{
+ vector<stg_point_t> vs;
+ assert(2 <= pts.size());
+ for (unsigned i = 0, n = pts.size(); i < n; ++i)
+ {
+ unsigned j = (i + 1) % n;
+ vs.push_back(V2(pts[j].x - pts[i].x, pts[j].y - pts[i].y));
+ }
+ assert(vs.size() == pts.size());
+ return vs;
+}
+
+static
+/// util; finds sum of angle changes, from each vertex to the
+/// next one (in current ordering), wrapping around.
+stg_radians_t angles_sum(vector<stg_point_t> const& vs)
+{
+ stg_radians_t angle_sum = 0;
+ for (unsigned i = 0, n = vs.size(); i < n; ++i)
+ {
+ unsigned j = (i + 1) % n;
+ angle_sum += angle_change(vs[i], vs[j]);
+ }
+ return angle_sum;
+}
+
+static
+/// Util
+bool is_canonical_winding(vector<stg_point_t> const& ps)
+{
+ // reuse stg_point_t as vector
+ vector<stg_point_t> vs = find_vectors(ps);
+ stg_radians_t sum = angles_sum(vs);
+ bool bCanon = 0 < sum;
+
+ return bCanon;
+}
+
+static
+/// util; sums angle changes to see whether it's 2pi or -2pi.
+/// 2pi is counter-clockwise winding (which OpenGL requires),
+/// -2pi is clockwise. Reverses <pts> when winding is clockwise.
+// Note that a simple line that doubles back on itself has an
+// angle sum of 0, but that's intrinsic to a line - its winding could
+// be either way.
+void canonicalize_winding(vector<stg_point_t>& ps)
+{
+ if (not is_canonical_winding(ps))
+ {
+ std::reverse(ps.begin(), ps.end());
+ }
+}
@@ -51,26 +51,16 @@ void Model::Load()
watts_give = wf->ReadFloat( wf_entity, "give_watts", watts_give );
watts_take = wf->ReadFloat( wf_entity, "take_watts", watts_take );
- if( wf->PropertyExists( wf_entity, "debug" ) )
- {
- PRINT_WARN2( "debug property specified for model %d %s\n",
- wf_entity, this->token.c_str() );
- this->debug = wf->ReadInt( wf_entity, "debug", this->debug );
- }
-
- if( wf->PropertyExists( wf_entity, "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 = 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.c_str() );
- }
+ this->debug = wf->ReadInt( wf_entity, "debug", this->debug );
+ 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 = name ;
+ world->AddModelName( this, name ); // add this name to the world's table
+ }
+
//PRINT_WARN1( "%s::Load", token );
if( wf->PropertyExists( wf_entity, "origin" ) )
@@ -176,23 +166,21 @@ void Model::Load()
AddBlockRect(blockgroup.maxx-epsilon,blockgroup.miny, epsilon, bgsize.y, bgsize.z );
}
}
-
- if( wf->PropertyExists( wf_entity, "mass" ))
- this->SetMass( wf->ReadFloat(wf_entity, "mass", this->mass ));
-
+
+ stg_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
-
+ SetFiducialReturn( vis.fiducial_return ); // may have some work to do
+
gui.Load( wf, wf_entity );
- if( wf->PropertyExists( wf_entity, "map_resolution" ))
- this->SetMapResolution( wf->ReadFloat(wf_entity, "map_resolution", this->map_resolution ));
-
- // todo - look into this
- //if (vis.gravity_return)
- //this->SetVelocity( GetVelocity() );
-
- velocity_enable = wf->ReadInt( wf_entity, "enable_velocity", velocity_enable );
+ double res = wf->ReadFloat(wf_entity, "map_resolution", this->map_resolution );
+ if( res != this->map_resolution )
+ SetMapResolution( res );
+
+ velocity_enable = wf->ReadInt( wf_entity, "enable_velocity", velocity_enable );
if( wf->PropertyExists( wf_entity, "friction" ))
{
@@ -214,11 +202,11 @@ void Model::Load()
}
- if( wf->PropertyExists( wf_entity, "say" ))
- this->Say( wf->ReadString(wf_entity, "say", "" ));
+
+ Say( wf->ReadString(wf_entity, "say", "" ));
- trail_length = wf->ReadInt( wf_entity, "trail_length", trail_length );
- trail.resize( trail_length );
+ trail_length = wf->ReadInt( wf_entity, "trail_length", trail_length );
+ trail.resize( trail_length );
trail_interval = wf->ReadInt( wf_entity, "trail_interval", trail_interval );
View
@@ -11,6 +11,8 @@ namespace Stg
{
// a bit of experimenting suggests that these values are fast. YMMV.
+ //const int32_t RBITS( 5 ); // regions contain (2^RBITS)^2 pixels
+ //const int32_t SBITS( 5 );// superregions contain (2^SBITS)^2 regions
const int32_t RBITS( 5 ); // regions contain (2^RBITS)^2 pixels
const int32_t SBITS( 5 );// superregions contain (2^SBITS)^2 regions
const int32_t SRBITS( RBITS+SBITS );
View
@@ -783,6 +783,9 @@ namespace Stg
bool destroy;
bool dirty; ///< iff true, a gui redraw would be required
+ /** Models that should be rendered into the background just-in-time, before sensing occurs */
+ //std::vector<Model*> jit_render;
+
/** Pointers to all the models in this world. */
std::set<Model*> models;
@@ -887,9 +890,9 @@ namespace Stg
virtual Model* RecentlySelectedModel(){ return NULL; }
SuperRegion* AddSuperRegion( const stg_point_int_t& coord );
- SuperRegion* GetSuperRegion( const stg_point_int_t& coord );
- SuperRegion* GetSuperRegionCached( const stg_point_int_t& coord);
- SuperRegion* GetSuperRegionCached( int32_t x, int32_t y );
+ //SuperRegion* GetSuperRegion( const stg_point_int_t& coord );
+ //SuperRegion* GetSuperRegionCached( const stg_point_int_t& coord);
+ SuperRegion* GetSuperRegion( int32_t x, int32_t y );
void ExpireSuperRegion( SuperRegion* sr );
/** add a Cell pointer to the vector for each cell on the line from
@@ -1610,6 +1613,9 @@ namespace Stg
always runs. Defaults to false. */
bool alwayson;
+ /** If true, the model is rendered lazily into the regions, to reduce memory use. */
+ // bool background;
+
BlockGroup blockgroup;
/** OpenGL display list identifier for the blockgroup */
int blocks_dl;
Oops, something went wrong. Retry.

0 comments on commit e5a483c

Please sign in to comment.