Revision: 7146 http://playerstage.svn.sourceforge.net/playerstage/?rev=7146&view=rev Author: rtv Date: 2008-11-15 02:46:31 +0000 (Sat, 15 Nov 2008)
Log Message: ----------- major changes for 3.1 Modified Paths: -------------- code/stage/trunk/libstage/region.hh code/stage/trunk/libstage/stage_internal.hh Property Changed: ---------------- code/stage/trunk/libstage/file_manager.hh code/stage/trunk/libstage/option.hh code/stage/trunk/libstage/options_dlg.hh code/stage/trunk/libstage/region.hh code/stage/trunk/libstage/stage_internal.hh code/stage/trunk/libstage/texture_manager.hh code/stage/trunk/libstage/worldfile.hh Property changes on: code/stage/trunk/libstage/file_manager.hh ___________________________________________________________________ Added: svn:eol + native Property changes on: code/stage/trunk/libstage/option.hh ___________________________________________________________________ Added: svn:eol + native Property changes on: code/stage/trunk/libstage/options_dlg.hh ___________________________________________________________________ Added: svn:eol + native Modified: code/stage/trunk/libstage/region.hh =================================================================== --- code/stage/trunk/libstage/region.hh 2008-11-15 02:46:11 UTC (rev 7145) +++ code/stage/trunk/libstage/region.hh 2008-11-15 02:46:31 UTC (rev 7146) @@ -8,11 +8,6 @@ const uint32_t SBITS = 5; // superregions contain (2^SBITS)^2 regions const uint32_t SRBITS = RBITS+SBITS; -typedef struct -{ - GSList* list; -} stg_cell_t; - class Stg::Region { friend class SuperRegion; @@ -21,17 +16,24 @@ static const uint32_t REGIONWIDTH = 1<<RBITS; static const uint32_t REGIONSIZE = REGIONWIDTH*REGIONWIDTH; - stg_cell_t cells[REGIONSIZE]; - + //stg_cell_t cells[REGIONSIZE]; + stg_cell_t* cells; + public: uint32_t count; // number of blocks rendered into these cells - Region() + Region() + : cells( new stg_cell_t[REGIONSIZE] ), + count(0) + { + /* do nothing */ + } + + ~Region() { - bzero( cells, REGIONSIZE * sizeof(stg_cell_t)); - count = 0; + delete[] cells; } - + stg_cell_t* GetCell( int32_t x, int32_t y ) { uint32_t index = x + (y*REGIONWIDTH); @@ -39,17 +41,50 @@ assert( index >=0 ); assert( index < REGIONSIZE ); #endif + + printf("GET CELL [%d %d] index %d gives %p\n", + x, y, index, &cells[index] ); + return &cells[index]; } // add a block to a region cell specified in REGION coordinates - void AddBlock( StgBlock* block, int32_t x, int32_t y, unsigned int* count2 ) + void AddBlock( StgModel* mod, + stg_color_t col, + stg_bounds_t zbounds, + int32_t x, int32_t y, + unsigned int* count2 ) { + assert( mod ); + stg_cell_t* cell = GetCell( x, y ); - cell->list = g_slist_prepend( cell->list, block ); - block->RecordRenderPoint( &cell->list, cell->list, &this->count, count2 ); - count++; + assert( cell ); + + // put a new empty pointer on the front of the list to use below + cell->list = g_slist_prepend( cell->list, NULL ); + + // this is the data to be stored in this cell + stg_list_entry_t el; + el.cell = cell; + el.link = cell->list; + el.counter1 = &count; + el.counter2 = count2; + el.mod = mod; + el.color = col; + el.zbounds = zbounds; + + // copy this struct onto the end of the model's array + g_array_append_val( mod->rendered_points, el ); + + // stash this record at the head of the list + cell->list->data = + & g_array_index( mod->rendered_points, + stg_list_entry_t, + mod->rendered_points->len-1 ); + + count++; } + }; @@ -89,16 +124,19 @@ } // add a block to a cell specified in superregion coordinates - void AddBlock( StgBlock* block, int32_t x, int32_t y ) + void AddBlock( StgModel* mod, + stg_color_t col, + stg_bounds_t zbounds, + int32_t x, int32_t y ) { GetRegion( x>>RBITS, y>>RBITS ) - ->AddBlock( block, - x - ((x>>RBITS)<<RBITS), - y - ((y>>RBITS)<<RBITS), + ->AddBlock( mod, col, zbounds, + x - ((x>>RBITS)<<RBITS), + y - ((y>>RBITS)<<RBITS), &count); count++; } - + // callback wrapper for Draw() static void Draw_cb( gpointer dummykey, SuperRegion* sr, Property changes on: code/stage/trunk/libstage/region.hh ___________________________________________________________________ Added: svn:eol + native Modified: code/stage/trunk/libstage/stage_internal.hh =================================================================== --- code/stage/trunk/libstage/stage_internal.hh 2008-11-15 02:46:11 UTC (rev 7145) +++ code/stage/trunk/libstage/stage_internal.hh 2008-11-15 02:46:31 UTC (rev 7146) @@ -11,10 +11,223 @@ // external definitions for libstage users #include "stage.hh" -// internal-only definitions and includes go here +// internal-only definitions and includes go below + #include "worldfile.hh" + // implementation files use our namespace by default using namespace Stg; -#endif + +namespace Stg +{ + + +// COLOR STACK CLASS +class GlColorStack +{ + public: + GlColorStack(); + ~GlColorStack(); + + void Push( GLdouble col[4] ); + void Push( double r, double g, double b, double a ); + void Push( double r, double g, double b ); + void Push( stg_color_t col ); + + void Pop(); + + unsigned int Length() + { return g_queue_get_length( colorstack ); } + + private: + GQueue* colorstack; +}; + + +class StgCanvas : public Fl_Gl_Window +{ + friend class StgWorldGui; // allow access to private members + friend class StgModel; + +private: + GlColorStack colorstack; + + Camera* current_camera; + OrthoCamera camera; + PerspectiveCamera perspective_camera; + bool dirty_buffer; + Worldfile* wf; + + int startx, starty; + bool selectedModel; + bool clicked_empty_space; + int empty_space_startx, empty_space_starty; + GList* selected_models; ///< a list of models that are currently + ///selected by the user + StgModel* last_selection; ///< the most recently selected model + ///(even if it is now unselected). + + stg_msec_t interval; // window refresh interval in ms + + GList* ray_list; + void RecordRay( double x1, double y1, double x2, double y2 ); + void DrawRays(); + void ClearRays(); + void DrawGlobalGrid(); + + Option + showBlinken, + showBlocks, + showClock, + showData, + showFlags, + showFollow, + showFootprints, + showGrid, + showOccupancy, + showScreenshots, + showStatus, + showTrailArrows, + showTrailRise, + showTrails, + showTree, + pCamOn, + visualizeAll; + +public: + StgCanvas( StgWorldGui* world, int x, int y, int W,int H); + ~StgCanvas(); + + bool graphics; + StgWorldGui* world; + + void Screenshot(); + + void createMenuItems( Fl_Menu_Bar* menu, std::string path ); + + void FixViewport(int W,int H); + void DrawFloor(); //simpler floor compared to grid + void DrawBlocks(); + void resetCamera(); + virtual void renderFrame(); + virtual void draw(); + virtual int handle( int event ); + void resize(int X,int Y,int W,int H); + + void CanvasToWorld( int px, int py, + double *wx, double *wy, double* wz ); + + StgModel* getModel( int x, int y ); + bool selected( StgModel* mod ); + void select( StgModel* mod ); + void unSelect( StgModel* mod ); + void unSelectAll(); + + inline void setDirtyBuffer( void ) { dirty_buffer = true; } + inline bool dirtyBuffer( void ) const { return dirty_buffer; } + + inline void PushColor( stg_color_t col ) + { colorstack.Push( col ); } + + void PushColor( double r, double g, double b, double a ) + { colorstack.Push( r,g,b,a ); } + + void PopColor(){ colorstack.Pop(); } + + void InvertView( uint32_t invertflags ); + + static void TimerCallback( StgCanvas* canvas ); + static void perspectiveCb( Fl_Widget* w, void* p ); + + void Load( Worldfile* wf, int section ); + void Save( Worldfile* wf, int section ); +}; + + +class Cell +{ + friend class Region; + friend class SuperRegion; + friend class StgWorld; + friend class StgBlock; + +private: + Region* region; + GSList* list; +public: + Cell() + : region( NULL), + list(NULL) + { /* do nothing */ } + + void RemoveBlock( StgBlock* b ); + void AddBlock( StgBlock* b ); + void AddBlockNoRecord( StgBlock* b ); +}; + +// a bit of experimenting suggests that these values are fast. YMMV. +#define RBITS 4 // regions contain (2^RBITS)^2 pixels +#define SBITS 4 // superregions contain (2^SBITS)^2 regions +#define SRBITS (RBITS+SBITS) + +#define REGIONWIDTH (1<<RBITS) +#define REGIONSIZE REGIONWIDTH*REGIONWIDTH + +#define SUPERREGIONWIDTH (1<<SBITS) +#define SUPERREGIONSIZE SUPERREGIONWIDTH*SUPERREGIONWIDTH + +class Region +{ + friend class SuperRegion; + +private: + static const uint32_t WIDTH; + static const uint32_t SIZE; + + Cell cells[REGIONSIZE]; + SuperRegion* superregion; + +public: + unsigned long count; // number of blocks rendered into these cells + + Region(); + ~Region(); + Cell* GetCell( int32_t x, int32_t y ); + + void DecrementOccupancy(); + void IncrementOccupancy(); +}; + + +class SuperRegion +{ + friend class StgWorld; + friend class StgModel; + +private: + static const uint32_t WIDTH; + static const uint32_t SIZE; + + Region regions[SUPERREGIONSIZE]; + unsigned long count; // number of blocks rendered into these regions + + stg_point_int_t origin; + +public: + + SuperRegion( int32_t x, int32_t y ); + ~SuperRegion(); + + Region* GetRegion( int32_t x, int32_t y ); + + void Draw( bool drawall ); + void Floor(); + void DecrementOccupancy(); + void IncrementOccupancy(); +}; + +}; // namespace Stg + +#endif // STG_INTERNAL_H Property changes on: code/stage/trunk/libstage/stage_internal.hh ___________________________________________________________________ Added: svn:eol + native Property changes on: code/stage/trunk/libstage/texture_manager.hh ___________________________________________________________________ Added: svn:eol + native Property changes on: code/stage/trunk/libstage/worldfile.hh ___________________________________________________________________ Added: svn:eol + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Playerstage-commit mailing list Playerstage-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/playerstage-commit