Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

block refactoring

  • Loading branch information...
commit aa783ffd95637c016db2fa4004f74cd4918c1b83 1 parent fda19fb
rtv authored
View
21 libstage/block.cc
@@ -69,10 +69,10 @@ Block::~Block()
void Block::Translate( double x, double y )
{
- for( unsigned int p=0; p<pt_count; p++)
+ FOR_EACH( it, pts )
{
- pts[p].x += x;
- pts[p].y += y;
+ it->x += x;
+ it->y += y;
}
mod->blockgroup.BuildDisplayList( mod );
@@ -83,10 +83,10 @@ double Block::CenterY()
double min = billion;
double max = -billion;
- for( unsigned int p=0; p<pt_count; p++)
+ FOR_EACH( it, pts )
{
- if( pts[p].y > max ) max = pts[p].y;
- if( pts[p].y < min ) min = pts[p].y;
+ if( it->y > max ) max = it->y;
+ if( it->y < min ) min = it->y;
}
// return the value half way between max and min
@@ -98,10 +98,10 @@ double Block::CenterX()
double min = billion;
double max = -billion;
- for( unsigned int p=0; p<pt_count; p++)
+ FOR_EACH( it, pts )
{
- if( pts[p].x > max ) max = pts[p].x;
- if( pts[p].x < min ) min = pts[p].x;
+ if( it->x > max ) max = it->x;
+ if( it->x < min ) min = it->x;
}
// return the value half way between maxx and min
@@ -297,8 +297,9 @@ void Block::GenerateCandidateCells()
{
// no valid cache of model coord points, so generate them
mpts.resize( pt_count );
+
for( unsigned int i=0; i<pt_count; i++ )
- mpts[i] = BlockPointToModelMeters( pts[i] );
+ mpts[i] = BlockPointToModelMeters( pts[i] );
}
gpts.clear();
View
11 libstage/blockgroup.cc
@@ -78,13 +78,12 @@ void BlockGroup::CalcSize()
// examine all the points in the polygon
Block* block = *it;
- for( unsigned int p=0; p < block->pt_count; p++ )
+ FOR_EACH( it, block->pts )
{
- stg_point_t* pt = &block->pts[p];
- if( pt->x < minx ) minx = pt->x;
- if( pt->y < miny ) miny = pt->y;
- if( pt->x > maxx ) maxx = pt->x;
- if( pt->y > maxy ) maxy = pt->y;
+ if( it->x < minx ) minx = it->x;
+ if( it->y < miny ) miny = it->y;
+ if( it->x > maxx ) maxx = it->x;
+ if( it->y > maxy ) maxy = it->y;
}
size.z = std::max( block->local_z.max, size.z );
View
27 libstage/model.cc
@@ -157,18 +157,15 @@
using namespace Stg;
// static members
-uint32_t Model::count = 0;
-uint32_t Model::trail_length = 50;
-uint64_t Model::trail_interval = 5;
+uint32_t Model::count(0);
+uint32_t Model::trail_length(50);
+uint64_t Model::trail_interval(5);
std::map<stg_id_t,Model*> Model::modelsbyid;
std::map<std::string, creator_t> Model::name_map;
-//std::map<void*, std::set<Model::stg_cb_t> > Model::callbacks;
void Size::Load( Worldfile* wf, int section, const char* keyword )
{
if( CProperty* prop = wf->GetProperty( section, keyword ) )
-
- //if( prop )
{
if( prop->values.size() != 3 )
{
@@ -268,7 +265,7 @@ Model::Model( World* world,
blockgroup(),
blocks_dl(0),
boundary(false),
- callbacks(__CB_TYPE_COUNT),
+ callbacks(__CB_TYPE_COUNT), // one slot in the vector for each type
color( 1,0,0 ), // red
data_fresh(false),
disabled(false),
@@ -427,10 +424,10 @@ void Model::LoadBlock( Worldfile* wf, int entity )
Block* Model::AddBlockRect( stg_meters_t x,
- stg_meters_t y,
- stg_meters_t dx,
- stg_meters_t dy,
- stg_meters_t dz )
+ stg_meters_t y,
+ stg_meters_t dx,
+ stg_meters_t dy,
+ stg_meters_t dz )
{
UnMap();
@@ -445,10 +442,10 @@ Block* Model::AddBlockRect( stg_meters_t x,
pts[3].y = y + dy;
Block* newblock = new Block( this,
- pts, 4,
- 0, dz,
- color,
- true );
+ pts, 4,
+ 0, dz,
+ color,
+ true );
blockgroup.AppendBlock( newblock );
View
32 libstage/stage.hh
@@ -1198,17 +1198,11 @@ namespace Stg
/** Set the extent in Z of the block */
void SetZ( double min, double max );
-
- stg_point_t* Points( unsigned int *count )
- { if( count ) *count = pt_count; return &pts[0]; };
-
- std::vector<stg_point_t>& Points()
- { return pts; };
-
+
inline void RemoveFromCellArray( CellPtrVec* blocks );
inline void GenerateCandidateCells();
-
- void AppendTouchingModels( ModelPtrSet& touchers );
+
+ void AppendTouchingModels( ModelPtrSet& touchers );
/** Returns the first model that shares a bitmap cell with this model */
Model* TestCollision();
@@ -1262,32 +1256,32 @@ namespace Stg
void InvalidateModelPointCache();
};
-
+
class BlockGroup
{
friend class Model;
- friend class Block;
-
+ friend class Block;
+
private:
int displaylist;
-
+
void BuildDisplayList( Model* mod );
-
- BlockPtrSet blocks;
+
+ BlockPtrSet blocks;
Size size;
stg_point3_t offset;
stg_meters_t minx, maxx, miny, maxy;
-
+
public:
BlockGroup();
~BlockGroup();
-
+
uint32_t GetCount(){ return blocks.size(); };
const Size& GetSize(){ return size; };
const stg_point3_t& GetOffset(){ return offset; };
-
+
/** Establish the min and max of all the blocks, so we can scale this
- group later. */
+ group later. */
void CalcSize();
void AppendBlock( Block* block );
Please sign in to comment.
Something went wrong with that request. Please try again.