Revision: 6537
          http://playerstage.svn.sourceforge.net/playerstage/?rev=6537&view=rev
Author:   jeremy_asher
Date:     2008-06-11 11:18:50 -0700 (Wed, 11 Jun 2008)

Log Message:
-----------
Implemented basic File/Load capability

Modified Paths:
--------------
    code/stage/trunk/libstage/main.cc
    code/stage/trunk/libstage/stage.hh
    code/stage/trunk/libstage/world.cc
    code/stage/trunk/libstage/worldgui.cc

Modified: code/stage/trunk/libstage/main.cc
===================================================================
--- code/stage/trunk/libstage/main.cc   2008-06-11 03:38:09 UTC (rev 6536)
+++ code/stage/trunk/libstage/main.cc   2008-06-11 18:18:50 UTC (rev 6537)
@@ -63,7 +63,8 @@
        }
 
        if( loaded_world_file == false ) {
-               printf( "No world file specified.\n" );
+               // replace this with a loading dialog/window
+               StgWorldGui* world = new StgWorldGui( 400, 300 );
        }
 
 

Modified: code/stage/trunk/libstage/stage.hh
===================================================================
--- code/stage/trunk/libstage/stage.hh  2008-06-11 03:38:09 UTC (rev 6536)
+++ code/stage/trunk/libstage/stage.hh  2008-06-11 18:18:50 UTC (rev 6537)
@@ -1012,7 +1012,7 @@
        void RemoveBlock( int x, int y, StgBlock* block );
        //{ }//bgrid->RemoveBlock( x, y, block ); };
 
-       protected:
+protected:
        stg_usec_t interval_real;   ///< real-time interval between updates - 
set this to zero for 'as fast as possible
 
        GHashTable* superregions;
@@ -1032,8 +1032,7 @@
        //GHashTable* blocks;
        GArray lines;
 
-       public:
-
+public:
        StgWorld();
 
        StgWorld( const char* token, 
@@ -1041,56 +1040,57 @@
                        stg_msec_t interval_real,
                        double ppm );
 
-virtual ~StgWorld();
+       virtual ~StgWorld();
 
-stg_usec_t SimTimeNow(void){ return sim_time;} ;
-stg_usec_t RealTimeNow(void);
-stg_usec_t RealTimeSinceStart(void);
-void PauseUntilNextUpdateTime(void);
-void IdleUntilNextUpdateTime( int (*idler)(void) );
+       stg_usec_t SimTimeNow(void){ return sim_time;} ;
+       stg_usec_t RealTimeNow(void);
+       stg_usec_t RealTimeSinceStart(void);
+       void PauseUntilNextUpdateTime(void);
+       void IdleUntilNextUpdateTime( int (*idler)(void) );
 
-void AddBlock( StgBlock* block );
-void RemoveBlock( StgBlock* block );
+       void AddBlock( StgBlock* block );
+       void RemoveBlock( StgBlock* block );
 
-stg_usec_t GetSimInterval(){ return interval_sim; };
+       stg_usec_t GetSimInterval(){ return interval_sim; };
 
 
-Worldfile* GetWorldFile(){ return wf; };
+       Worldfile* GetWorldFile(){ return wf; };
 
-virtual void Load( const char* worldfile_path );
-virtual void Reload();
-virtual bool Save( const char* filename );
-virtual bool Update(void);
-virtual void AddModel( StgModel* mod );
-virtual void RemoveModel( StgModel* mod );
+       virtual void Load( const char* worldfile_path );
+       virtual void UnLoad();
+       virtual void Reload();
+       virtual bool Save( const char* filename );
+       virtual bool Update(void);
+       virtual void AddModel( StgModel* mod );
+       virtual void RemoveModel( StgModel* mod );
 
-void Start(){ paused = false; };
-void Stop(){ paused = true; };
-void TogglePause(){ paused = !paused; };
-bool TestQuit(){ return( quit || quit_all );  }
-void Quit(){ quit = true; }
-void QuitAll(){ quit_all = true; }
-void CancelQuit(){ quit = false; }
-void CancelQuitAll(){ quit_all = false; }
+       void Start(){ paused = false; };
+       void Stop(){ paused = true; };
+       void TogglePause(){ paused = !paused; };
+       bool TestQuit(){ return( quit || quit_all );  }
+       void Quit(){ quit = true; }
+       void QuitAll(){ quit_all = true; }
+       void CancelQuit(){ quit = false; }
+       void CancelQuitAll(){ quit_all = false; }
 
-double Resolution(){ return ppm; };
+       double Resolution(){ return ppm; };
 
-StgModel* GetModel( const stg_id_t id );
-StgModel* GetModel( const char* name );
+       StgModel* GetModel( const stg_id_t id );
+       StgModel* GetModel( const char* name );
 
 
-GList* GetRayList(){ return ray_list; };
-void ClearRays();
+       GList* GetRayList(){ return ray_list; };
+       void ClearRays();
 
-void ClockString( char* str, size_t maxlen );
+       void ClockString( char* str, size_t maxlen );
 
-stg_bounds3d_t GetExtent(){ return extent; };
+       stg_bounds3d_t GetExtent(){ return extent; };
 
-void ForEachModel( GHFunc func, void* arg )
-{ g_hash_table_foreach( models_by_id, func, arg ); };
+       void ForEachModel( GHFunc func, void* arg )
+       { g_hash_table_foreach( models_by_id, func, arg ); };
 
-long unsigned int GetUpdateCount()
-{ return updates; }
+       long unsigned int GetUpdateCount()
+       { return updates; }
 };
 
 
@@ -1869,9 +1869,11 @@
        /** Start the simulation and GUI. Does not return */
        static void Run();
        void Start();
+       void Stop();
        void Cycle();
 
        virtual void Load( const char* filename );
+       virtual void UnLoad();
        virtual bool Save( const char* filename );
 
        // static callback functions

Modified: code/stage/trunk/libstage/world.cc
===================================================================
--- code/stage/trunk/libstage/world.cc  2008-06-11 03:38:09 UTC (rev 6536)
+++ code/stage/trunk/libstage/world.cc  2008-06-11 18:18:50 UTC (rev 6537)
@@ -231,6 +231,19 @@
        mod->Init();
 }
 
+// delete a model from the hash table
+void destroy_model( gpointer dummy1, StgModel* mod, gpointer dummy2 )
+{
+       free(mod);
+}
+
+// delete a model from the hash table
+void destroy_sregion( gpointer dummy1, SuperRegion* sr, gpointer dummy2 )
+{
+       free(sr);
+}
+
+
 void StgWorld::Load( const char* worldfile_path )
 {
        printf( " [Loading %s]", worldfile_path );
@@ -320,6 +333,38 @@
 
 }
 
+void StgWorld::UnLoad()
+{
+       if( wf ) delete wf;
+       //if( bgrid ) delete bgrid;
+
+       g_list_foreach( children, (GFunc)destroy_model, NULL );
+       g_list_free( children );
+       children = NULL;
+       
+       g_hash_table_remove_all( child_types ); // small memory leak    
+       
+       g_hash_table_remove_all( models_by_id );
+               
+       g_hash_table_remove_all( models_by_name );
+       
+       g_list_free( velocity_list );
+       velocity_list = NULL;
+       
+       g_list_free( update_list );
+       update_list = NULL;
+       
+       g_list_free( ray_list );
+       ray_list = NULL;
+       
+       g_hash_table_foreach( superregions, (GHFunc)destroy_sregion, NULL );
+       g_hash_table_remove_all( superregions );
+
+       g_free( token );
+       this->token = (char*)g_malloc(Stg::TOKEN_MAX);  // necessary?
+       
+}
+
 stg_usec_t StgWorld::RealTimeNow()
 {
        struct timeval tv;

Modified: code/stage/trunk/libstage/worldgui.cc
===================================================================
--- code/stage/trunk/libstage/worldgui.cc       2008-06-11 03:38:09 UTC (rev 
6536)
+++ code/stage/trunk/libstage/worldgui.cc       2008-06-11 18:18:50 UTC (rev 
6537)
@@ -180,13 +180,15 @@
 
 StgWorldGui::~StgWorldGui()
 {
+       delete mbar;
+       delete canvas;
 }
 
 void StgWorldGui::Load( const char* filename )
 {
        PRINT_DEBUG1( "%s.Load()", token );
 
-       StgWorld::Load( filename);
+       StgWorld::Load( filename );
 
        wf_section = wf->LookupEntity( "window" );
        if( wf_section < 1) // no section defined
@@ -250,9 +252,43 @@
        // TODO - per model visualizations load
 }
 
+void StgWorldGui::UnLoad() 
+{
+       //canvas->UnLoad();
+//     delete canvas;
+//     canvas = new StgCanvas( this,0,30,640,480 );
+       StgWorld::UnLoad();
+//     canvas->camera.setPose( 0, 0 );
+}
+
 void StgWorldGui::LoadCallback( Fl_Widget* wid, StgWorldGui* world )
 {
-       // implement me
+       const char* filename;
+       const char* worldsPath;
+       //bool success;
+       const char* pattern = "World Files (*.world)";
+       
+       // todo: replace this with real path
+       worldsPath = "/Users/jeremya/stage_trunk/worlds";
+       Fl_File_Chooser fc( worldsPath, pattern, Fl_File_Chooser::CREATE, "Load 
World File..." );
+       fc.ok_label( "Load" );
+       
+       fc.show();
+       while (fc.shown())
+               Fl::wait();
+       
+       filename = fc.value();
+       
+       if (filename != NULL) {
+               // if (initialized) {
+               world->Stop();
+               world->UnLoad();
+               // }
+               
+               // todo: make sure loading is successful
+               world->Load( filename );
+               world->Start();
+       }
 }
 
 void StgWorldGui::SaveCallback( Fl_Widget* wid, StgWorldGui* world )
@@ -482,6 +518,13 @@
                Fl::add_idle( (Fl_Timeout_Handler)idle_callback, this );
 }
 
+void StgWorldGui::Stop()
+{
+       Fl::remove_timeout( (Fl_Timeout_Handler)UpdateCb, this );
+       Fl::remove_idle( (Fl_Timeout_Handler)idle_callback, this );
+}
+
+
 void StgWorldGui::Run()
 {
        Fl::run();


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to