@@ -58,8 +58,8 @@ SuperRegion::SuperRegion( World* world, point_int_t origin )
5858 world(world),
5959 count(0 )
6060{
61- for ( int32_t r =0 ; r <SUPERREGIONSIZE;r++ )
62- regions[r ].superregion = this ;
61+ for ( int32_t c =0 ; c <SUPERREGIONSIZE;++c )
62+ regions[c ].superregion = this ;
6363}
6464
6565SuperRegion::~SuperRegion ()
@@ -82,6 +82,8 @@ void SuperRegion::RemoveBlock()
8282
8383void SuperRegion::DrawOccupancy () const
8484{
85+ // printf( "SR origin (%d,%d) this %p\n", origin.x, origin.y, this );
86+
8587 glPushMatrix ();
8688 GLfloat scale = 1.0 /world->Resolution ();
8789 glScalef ( scale, scale, 1.0 ); // XX TODO - this seems slightly
@@ -95,70 +97,80 @@ void SuperRegion::DrawOccupancy() const
9597 glRecti ( 0 ,0 , 1 <<SRBITS, 1 <<SRBITS );
9698
9799 // outline regions
98- const Region* r = ®ions[0 ];
99- char buf[32 ];
100-
101- glColor3f ( 0 ,1 ,0 );
102- for ( int y=0 ; y<SUPERREGIONWIDTH; ++y )
103- for ( int x=0 ; x<SUPERREGIONWIDTH; ++x )
104- {
105- if ( r->count ) // region contains some occupied cells
106- {
107- // outline the region
108- glRecti ( x<<RBITS, y<<RBITS,
109- (x+1 )<<RBITS, (y+1 )<<RBITS );
110-
111- // show how many cells are occupied
112- snprintf ( buf, 15 , " %lu" , r->count );
113- Gl::draw_string ( x<<RBITS, y<<RBITS, 0 , buf );
114-
115- // draw a rectangle around each occupied cell
116- for ( int p=0 ; p<REGIONWIDTH; ++p )
117- for ( int q=0 ; q<REGIONWIDTH; ++q )
118- if ( r->cells [p+(q*REGIONWIDTH)].blocks .size () )
119- {
120- GLfloat xx = p+(x<<RBITS);
121- GLfloat yy = q+(y<<RBITS);
122- glRecti ( xx, yy, xx+1 , yy+1 );
123- }
124- }
125- else if ( r->cells ) // empty but used previously
126- {
127- double left = x << RBITS;
128- double right = (x+1 ) << RBITS;
129- double bottom = y << RBITS;
130- double top = (y+1 ) << RBITS;
131-
132- double d = 3.0 ;
133-
134- // draw little corner markers for regions with memory
135- // allocated but no contents
136- glBegin ( GL_LINES );
137- glVertex2f ( left, bottom );
138- glVertex2f ( left+d, bottom );
139- glVertex2f ( left, bottom );
140- glVertex2f ( left, bottom+d );
141- glVertex2f ( left, top );
142- glVertex2f ( left+d, top );
143- glVertex2f ( left, top );
144- glVertex2f ( left, top-d );
145- glVertex2f ( right, top );
146- glVertex2f ( right-d, top );
147- glVertex2f ( right, top );
148- glVertex2f ( right, top-d );
149- glVertex2f ( right, bottom );
150- glVertex2f ( right-d, bottom );
151- glVertex2f ( right, bottom );
152- glVertex2f ( right, bottom+d );
153- glEnd ();
154- }
100+ if ( regions )
101+ {
102+ const Region* r = ®ions[0 ];
103+ char buf[32 ];
155104
156- ++r; // next region quickly
105+ glColor3f ( 0 ,1 ,0 );
106+ for ( int y=0 ; y<SUPERREGIONWIDTH; ++y )
107+ for ( int x=0 ; x<SUPERREGIONWIDTH; ++x )
108+ {
109+ if ( r->count ) // region contains some occupied cells
110+ {
111+ // outline the region
112+ glRecti ( x<<RBITS, y<<RBITS,
113+ (x+1 )<<RBITS, (y+1 )<<RBITS );
114+
115+ // show how many cells are occupied
116+ snprintf ( buf, 15 , " %lu" , r->count );
117+ Gl::draw_string ( x<<RBITS, y<<RBITS, 0 , buf );
118+
119+ // draw a rectangle around each occupied cell
120+ for ( int p=0 ; p<REGIONWIDTH; ++p )
121+ for ( int q=0 ; q<REGIONWIDTH; ++q )
122+ if ( r->cells [p+(q*REGIONWIDTH)].blocks .size () )
123+ {
124+ GLfloat xx = p+(x<<RBITS);
125+ GLfloat yy = q+(y<<RBITS);
126+ glRecti ( xx, yy, xx+1 , yy+1 );
127+ }
128+ }
129+ else if ( r->cells ) // empty but used previously
130+ {
131+ double left = x << RBITS;
132+ double right = (x+1 ) << RBITS;
133+ double bottom = y << RBITS;
134+ double top = (y+1 ) << RBITS;
135+
136+ double d = 3.0 ;
137+
138+ // draw little corner markers for regions with memory
139+ // allocated but no contents
140+ glBegin ( GL_LINES );
141+ glVertex2f ( left, bottom );
142+ glVertex2f ( left+d, bottom );
143+ glVertex2f ( left, bottom );
144+ glVertex2f ( left, bottom+d );
145+ glVertex2f ( left, top );
146+ glVertex2f ( left+d, top );
147+ glVertex2f ( left, top );
148+ glVertex2f ( left, top-d );
149+ glVertex2f ( right, top );
150+ glVertex2f ( right-d, top );
151+ glVertex2f ( right, top );
152+ glVertex2f ( right, top-d );
153+ glVertex2f ( right, bottom );
154+ glVertex2f ( right-d, bottom );
155+ glVertex2f ( right, bottom );
156+ glVertex2f ( right, bottom+d );
157+ glEnd ();
158+ }
159+
160+ ++r; // next region quickly
161+ }
157162 }
158-
163+ else
164+ { // outline region-collected superregion
165+ glColor3f ( 1 ,1 ,0 );
166+ glRecti ( 0 ,0 , (1 <<SRBITS)-1 , (1 <<SRBITS)-1 );
167+ glColor3f ( 0 ,0 ,1 );
168+ }
169+
170+ char buf[32 ];
159171 snprintf ( buf, 15 , " %lu" , count );
160172 Gl::draw_string ( 1 <<SBITS, 1 <<SBITS, 0 , buf );
161-
173+
162174 glPopMatrix ();
163175}
164176
0 commit comments