Permalink
Browse files

cleaning up

  • Loading branch information...
1 parent 4ba9941 commit 76d30e62bb01242d392c26df5e7423e6edb1a7ef @rtv rtv committed Nov 4, 2011
Showing with 105 additions and 188 deletions.
  1. +36 −4 libstage/color.cc
  2. +8 −51 libstage/model.cc
  3. +1 −19 libstage/model_load.cc
  4. +47 −101 libstage/model_position.cc
  5. +2 −1 libstage/region.cc
  6. +1 −1 libstage/region.hh
  7. +2 −6 libstage/stage.cc
  8. +6 −3 libstage/stage.hh
  9. +2 −2 worlds/benchmark/hospital.world
View
@@ -1,10 +1,12 @@
#include "stage.hh"
+#include "worldfile.hh"
using namespace Stg;
#include "file_manager.hh"
+
#include <errno.h>
-Color::Color( float r, float g, float b, float a )
+Color::Color( double r, double g, double b, double a )
: r(r),g(g),b(b),a(a)
{}
@@ -16,9 +18,9 @@ bool Color::operator!=( const Color& other ) const
{
double epsilon = 1e-4; // small
return( fabs(r-other.r) > epsilon ||
- fabs(g-other.g) > epsilon ||
- fabs(b-other.b) > epsilon ||
- fabs(a-other.a) > epsilon );
+ fabs(g-other.g) > epsilon ||
+ fabs(b-other.b) > epsilon ||
+ fabs(a-other.a) > epsilon );
}
Color::Color( const std::string& name) :
@@ -100,3 +102,33 @@ void Color::Print( const char* prefix ) const
printf( "%s [%.2f %.2f %.2f %.2f]\n", prefix, r,g,b,a );
}
+const Color& Color::Load( Worldfile* wf, const int section )
+{
+ if( wf->PropertyExists( section, "color" ))
+ {
+ const std::string& colorstr = wf->ReadString( section, "color", "" );
+ if( colorstr != "" )
+ {
+ if( colorstr == "random" )
+ {
+ r = drand48();
+ g = drand48();
+ b = drand48();
+ a = 1.0;
+ }
+ else
+ {
+ Color c = Color( colorstr );
+ r = c.r;
+ g = c.g;
+ b = c.b;
+ a = c.a;
+ }
+ }
+ }
+ else
+ wf->ReadTuple( section, "color_rgba", 0, 4, "ffff", &r, &g, &b, &a );
+
+ return *this;
+}
+
View
@@ -180,52 +180,9 @@ Bounds& Bounds::Load( Worldfile* wf, const int section, const char* keyword )
return *this;
}
-bool Color::Load( Worldfile* wf, const int section )
+double Bounds::Constrain( double value )
{
- if( wf->PropertyExists( section, "color" ))
- {
- const std::string& colorstr = wf->ReadString( section, "color", "" );
- if( colorstr != "" )
- {
- if( colorstr == "random" )
- {
- r = drand48();
- g = drand48();
- b = drand48();
- a = 1.0;
- }
- else
- {
- Color c = Color( colorstr );
- r = c.r;
- g = c.g;
- b = c.b;
- a = c.a;
- }
- }
- return true;
- }
-
- if( wf->PropertyExists( section, "color_rgba" ))
- {
- if (wf->GetProperty(section,"color_rgba")->values.size() < 4)
- {
- PRINT_ERR1( "color_rgba requires 4 values, found %d\n",
- (int)wf->GetProperty(section,"color_rgba")->values.size() );
- exit(-1);
- }
- else
- {
- r = wf->ReadTupleFloat( section, "color_rgba", 0, r );
- g = wf->ReadTupleFloat( section, "color_rgba", 1, g );
- b = wf->ReadTupleFloat( section, "color_rgba", 2, b );
- a = wf->ReadTupleFloat( section, "color_rgba", 3, a );
- }
-
- return true;
- }
-
- return false;
+ return Stg::constrain( value, min, max );
}
Stg::Size& Stg::Size::Load( Worldfile* wf, const int section, const char* keyword )
@@ -739,12 +696,12 @@ void Model::Unsubscribe( void )
}
-void pose_invert( Pose* pose )
-{
- pose->x = -pose->x;
- pose->y = -pose->y;
- // pose->a = pose->a;
-}
+// void pose_invert( Pose* pose )
+// {
+// pose->x = -pose->x;
+// pose->y = -pose->y;
+// // pose->a = pose->a;
+// }
void Model::Print( char* prefix ) const
{
View
@@ -115,25 +115,7 @@ void Model::Load()
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", Token() );
- }
- else
- {
-
- double red=1.0, blue=0.0, green=0.0, alpha=1.0;
- if( wf->ReadTuple( wf_entity, "color_rgba", 0, 4, "ffff",
- &red, &green, &blue, &alpha ) != 4 )
- PRINT_ERR( "failed to read 4 floats for \"color_rgba\"" );
- else
- printf( "read four floats ok\n" );
-
- this->SetColor( Color( red, green, blue, alpha ));
- }
- }
+ this->SetColor( GetColor().Load( wf, wf_entity ) );
if( wf->ReadInt( wf_entity, "noblocks", 0 ) )
{
Oops, something went wrong.

0 comments on commit 76d30e6

Please sign in to comment.