00001
00002
00003
00004
00005
00006
00007 const uint32_t RBITS = 6;
00008 const uint32_t SBITS = 5;
00009 const uint32_t SRBITS = RBITS+SBITS;
00010
00011 typedef struct
00012 {
00013 GSList* list;
00014 } stg_cell_t;
00015
00016 class Stg::Region
00017 {
00018 friend class SuperRegion;
00019
00020 private:
00021 static const uint32_t REGIONWIDTH = 1<<RBITS;
00022 static const uint32_t REGIONSIZE = REGIONWIDTH*REGIONWIDTH;
00023
00024 stg_cell_t cells[REGIONSIZE];
00025
00026 public:
00027 uint32_t count;
00028
00029 Region()
00030 {
00031 bzero( cells, REGIONSIZE * sizeof(stg_cell_t));
00032 count = 0;
00033 }
00034
00035 stg_cell_t* GetCell( int32_t x, int32_t y )
00036 {
00037 uint32_t index = x + (y*REGIONWIDTH);
00038 assert( index >=0 );
00039 assert( index < REGIONSIZE );
00040 return &cells[index];
00041 }
00042
00043
00044 void AddBlock( StgBlock* block, int32_t x, int32_t y, unsigned int* count2 )
00045 {
00046 stg_cell_t* cell = GetCell( x, y );
00047 cell->list = g_slist_prepend( cell->list, block );
00048 block->RecordRenderPoint( &cell->list, cell->list, &this->count, count2 );
00049 count++;
00050 }
00051 };
00052
00053
00054 class Stg::SuperRegion
00055 {
00056 friend class StgWorld;
00057
00058 private:
00059 static const uint32_t SUPERREGIONWIDTH = 1<<SBITS;
00060 static const uint32_t SUPERREGIONSIZE = SUPERREGIONWIDTH*SUPERREGIONWIDTH;
00061
00062 Region regions[SUPERREGIONSIZE];
00063 uint32_t count;
00064
00065 stg_point_int_t origin;
00066
00067 public:
00068
00069 SuperRegion( int32_t x, int32_t y )
00070 {
00071 count = 0;
00072 origin.x = x;
00073 origin.y = y;
00074 }
00075
00076 ~SuperRegion()
00077 {
00078 }
00079
00080
00081 Region* GetRegion( int32_t x, int32_t y )
00082 {
00083 int32_t index = x + (y*SUPERREGIONWIDTH);
00084 assert( index >=0 );
00085 assert( index < (int)SUPERREGIONSIZE );
00086 return ®ions[ index ];
00087 }
00088
00089
00090 void AddBlock( StgBlock* block, int32_t x, int32_t y )
00091 {
00092 GetRegion( x>>RBITS, y>>RBITS )
00093 ->AddBlock( block,
00094 x - ((x>>RBITS)<<RBITS),
00095 y - ((y>>RBITS)<<RBITS),
00096 &count);
00097 count++;
00098 }
00099
00100
00101 static void Draw_cb( gpointer dummykey,
00102 SuperRegion* sr,
00103 gpointer dummyval )
00104 {
00105 sr->Draw();
00106 }
00107
00108 void Draw()
00109 {
00110 glPushMatrix();
00111 glTranslatef( origin.x<<SRBITS, origin.y<<SRBITS,0);
00112
00113 glColor3f( 1,0,0 );
00114
00115 for( unsigned int x=0; x<SUPERREGIONWIDTH; x++ )
00116 for( unsigned int y=0; y<SUPERREGIONWIDTH; y++ )
00117 {
00118 Region* r = GetRegion(x,y);
00119
00120 for( unsigned int p=0; p<Region::REGIONWIDTH; p++ )
00121 for( unsigned int q=0; q<Region::REGIONWIDTH; q++ )
00122 if( r->cells[p+(q*Region::REGIONWIDTH)].list )
00123 glRecti( p+(x<<RBITS), q+(y<<RBITS),
00124 1+p+(x<<RBITS), 1+q+(y<<RBITS) );
00125 }
00126
00127
00128 glColor3f( 0,1,0 );
00129 for( unsigned int x=0; x<SUPERREGIONWIDTH; x++ )
00130 for( unsigned int y=0; y<SUPERREGIONWIDTH; y++ )
00131 glRecti( x<<RBITS, y<<RBITS,
00132 (x+1)<<RBITS, (y+1)<<RBITS );
00133
00134
00135 glColor3f( 0,0,1 );
00136 glRecti( 0,0, 1<<SRBITS, 1<<SRBITS );
00137
00138 glPopMatrix();
00139 }
00140
00141 static void Floor_cb( gpointer dummykey,
00142 SuperRegion* sr,
00143 gpointer dummyval )
00144 {
00145 sr->Floor();
00146 }
00147
00148 void Floor()
00149 {
00150 glPushMatrix();
00151 glTranslatef( origin.x<<SRBITS, origin.y<<SRBITS, 0 );
00152 glRecti( 0,0, 1<<SRBITS, 1<<SRBITS );
00153 glPopMatrix();
00154 }
00155 };