region.hh
Go to the documentation of this file.00001 #pragma once 00002 /* 00003 region.hh 00004 data structures supporting multi-resolution ray tracing in world class. 00005 Copyright Richard Vaughan 2008 00006 */ 00007 00008 #include "stage.hh" 00009 00010 namespace Stg 00011 { 00012 00013 // a bit of experimenting suggests that these values are fast. YMMV. 00014 const int32_t RBITS( 5 ); // regions contain (2^RBITS)^2 pixels 00015 const int32_t SBITS( 5 );// superregions contain (2^SBITS)^2 regions 00016 const int32_t SRBITS( RBITS+SBITS ); 00017 00018 const int32_t REGIONWIDTH( 1<<RBITS ); 00019 const int32_t REGIONSIZE( REGIONWIDTH*REGIONWIDTH ); 00020 00021 const int32_t SUPERREGIONWIDTH( 1<<SBITS ); 00022 const int32_t SUPERREGIONSIZE( SUPERREGIONWIDTH*SUPERREGIONWIDTH ); 00023 00024 const int32_t CELLMASK( ~((~0x00)<< RBITS )); 00025 const int32_t REGIONMASK( ~((~0x00)<< SRBITS )); 00026 00027 inline int32_t GETCELL( const int32_t x ) { return( x & CELLMASK); } 00028 inline int32_t GETREG( const int32_t x ) { return( ( x & REGIONMASK ) >> RBITS); } 00029 inline int32_t GETSREG( const int32_t x ) { return( x >> SRBITS); } 00030 00031 // this is slightly faster than the inline method above, but not as safe 00032 //#define GETREG(X) (( (static_cast<int32_t>(X)) & REGIONMASK ) >> RBITS) 00033 00034 class Cell 00035 { 00036 friend class Region; 00037 friend class SuperRegion; 00038 friend class World; 00039 friend class Block; 00040 00041 private: 00042 Region* region; 00043 std::vector<Block*> blocks; 00044 00045 public: 00046 Cell( Region* reg ) 00047 : region( reg ), 00048 blocks() 00049 { 00050 } 00051 00052 // virtual void RemoveBlock( Block* b ) 00053 // { 00054 // EraseAll( b, blocks ); 00055 // } 00056 00057 //inline void AddBlock( Block* b ); 00058 //inline void AddBlockNoRecord( Block* b ); 00059 }; 00060 00061 class Region 00062 { 00063 public: 00064 std::vector<Cell> cells; 00065 00066 SuperRegion* superregion; 00067 unsigned long count; // number of blocks rendered into this region 00068 00069 Region( SuperRegion* sr ); 00070 ~Region(); 00071 00072 Cell* GetCell( int32_t x, int32_t y ) 00073 { 00074 if( cells.empty() ) // lazy population of cells 00075 cells.insert( cells.begin(), REGIONSIZE, Cell( this ) ); 00076 00077 return( (Cell*)&cells[ x + y * REGIONWIDTH ] ); 00078 } 00079 00080 }; // end class Region 00081 00082 class SuperRegion 00083 { 00084 friend class World; 00085 friend class Model; 00086 00087 private: 00088 00089 std::vector<Region> regions; 00090 stg_point_int_t origin; 00091 World* world; 00092 00093 public: 00094 00095 SuperRegion( World* world, stg_point_int_t origin ); 00096 ~SuperRegion(); 00097 00098 Region* GetRegion( int32_t x, int32_t y ) 00099 { return( ®ions[ x + y * SUPERREGIONWIDTH ] ); } 00100 00101 void DrawOccupancy(); 00102 void DrawVoxels(); 00103 00104 unsigned long count; // number of blocks rendered into this superregion 00105 }; // class SuperRegion; 00106 00107 }; // namespace Stg
Generated on Tue Oct 20 15:42:05 2009 for Stage by 1.6.1