Revision: 2432 http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2432&view=rev Author: rorthomas Date: 2012-02-02 13:23:06 +0000 (Thu, 02 Feb 2012) Log Message: ----------- fixed threading a bit by removing most of the locked sections except truck deletion. also fixed RoR singleton bug: unable to exit game
Modified Paths: -------------- trunk/source/main/CMakeLists.txt trunk/source/main/framework/AppStateManager.cpp trunk/source/main/gameplay/RigsOfRods.cpp trunk/source/main/gameplay/RigsOfRods.h trunk/source/main/gameplay/Savegame.cpp trunk/source/main/physics/Beam.cpp trunk/source/main/physics/BeamFactory.cpp trunk/source/main/physics/BeamFactory.h trunk/source/main/physics/BeamWaitAndLock.h Modified: trunk/source/main/CMakeLists.txt =================================================================== --- trunk/source/main/CMakeLists.txt 2012-02-02 13:21:49 UTC (rev 2431) +++ trunk/source/main/CMakeLists.txt 2012-02-02 13:23:06 UTC (rev 2432) @@ -86,8 +86,11 @@ if(ROR_FEAT_TIMING) add_definitions("-DFEAT_TIMING") endif(ROR_FEAT_TIMING) + + #add_definitions("-DFEAT_DEBUG_MUTEX") + add_definitions("-DBOOST_ALL_NO_LIB") add_definitions("-DUSE_RTSHADER_SYSTEM") Modified: trunk/source/main/framework/AppStateManager.cpp =================================================================== --- trunk/source/main/framework/AppStateManager.cpp 2012-02-02 13:21:49 UTC (rev 2431) +++ trunk/source/main/framework/AppStateManager.cpp 2012-02-02 13:23:06 UTC (rev 2432) @@ -238,6 +238,7 @@ // shutdown needs to be synced MUTEX_LOCK(&lock); m_bShutdown = true; +printf(">SH\n"); MUTEX_UNLOCK(&lock); } @@ -274,4 +275,4 @@ m_ActiveStateStack.back()->resized(r); } -//||||||||||||||||||||||||||||||||||||||||||||||| \ No newline at end of file +//||||||||||||||||||||||||||||||||||||||||||||||| Modified: trunk/source/main/gameplay/RigsOfRods.cpp =================================================================== --- trunk/source/main/gameplay/RigsOfRods.cpp 2012-02-02 13:21:49 UTC (rev 2431) +++ trunk/source/main/gameplay/RigsOfRods.cpp 2012-02-02 13:23:06 UTC (rev 2432) @@ -36,6 +36,7 @@ name(name), embedded(embedded) { + setSingleton(this); } RigsOfRods::~RigsOfRods() @@ -100,7 +101,12 @@ void RigsOfRods::shutdown() { if(stateManager) + { stateManager->shutdown(); + } else + { + printf("shutdown failed, no statemanager instance!\n"); + } } void RigsOfRods::tryShutdown() @@ -112,4 +118,4 @@ void RigsOfRods::pauseRendering() { stateManager->pauseRendering(); -} \ No newline at end of file +} Modified: trunk/source/main/gameplay/RigsOfRods.h =================================================================== --- trunk/source/main/gameplay/RigsOfRods.h 2012-02-02 13:21:49 UTC (rev 2431) +++ trunk/source/main/gameplay/RigsOfRods.h 2012-02-02 13:23:06 UTC (rev 2432) @@ -31,7 +31,7 @@ #include "AdvancedOgreFramework.h" #include "AppStateManager.h" -class RigsOfRods : public RoRSingleton<RigsOfRods> +class RigsOfRods : public RoRSingletonNoCreation<RigsOfRods> { public: RigsOfRods(Ogre::String name = Ogre::String("RoR"), Ogre::String hwnd=Ogre::String(), Ogre::String mainhwnd=Ogre::String(), bool embedded = false); Modified: trunk/source/main/gameplay/Savegame.cpp =================================================================== --- trunk/source/main/gameplay/Savegame.cpp 2012-02-02 13:21:49 UTC (rev 2431) +++ trunk/source/main/gameplay/Savegame.cpp 2012-02-02 13:23:06 UTC (rev 2432) @@ -56,7 +56,7 @@ FILE *f = fopen(filename.c_str(), "wb"); // wait for engine sync - BEAMLOCK(); + BeamWaitNoLock sync(); // TODO: show error if(!f) Modified: trunk/source/main/physics/Beam.cpp =================================================================== --- trunk/source/main/physics/Beam.cpp 2012-02-02 13:21:49 UTC (rev 2431) +++ trunk/source/main/physics/Beam.cpp 2012-02-02 13:23:06 UTC (rev 2432) @@ -85,9 +85,6 @@ // hide all meshes, prevents deleting stuff while drawing this->setMeshVisibility(false); - //block until all threads done - BEAMLOCK(); - // delete all classes we might have constructed #ifdef USE_MYGUI if(dash) delete dash; dash=0; @@ -615,7 +612,7 @@ } // wait for the thread(s) to be ready - BEAMLOCK(); + BeamWaitNoLock sync(); // all finished? so start network stuff if (networked) @@ -2103,7 +2100,7 @@ { //block until all threads are done { - BEAMLOCK(); + BeamWaitNoLock sync(); for (int t=0; t<numtrucks; t++) { if (!trucks[t]) continue; @@ -2164,7 +2161,7 @@ void Beam::prepareShutdown() { - BEAMLOCK(); + BeamWaitNoLock sync(); } void Beam::sendStreamSetup() Modified: trunk/source/main/physics/BeamFactory.cpp =================================================================== --- trunk/source/main/physics/BeamFactory.cpp 2012-02-02 13:21:49 UTC (rev 2431) +++ trunk/source/main/physics/BeamFactory.cpp 2012-02-02 13:23:06 UTC (rev 2432) @@ -341,7 +341,7 @@ bool BeamFactory::syncRemoteStreams() { // block until all threads done - BEAMLOCK(); + BeamWaitNoLock sync(); // we override this here, so we know if something changed and could update the player list // we delete and add trucks in there, so be sure that nothing runs as we delete them ... @@ -564,14 +564,17 @@ return; // block until all threads done - BEAMLOCK(); + { + BEAMLOCK(); - // synced delete - trucks[b->trucknum] = 0; - // TODO: properly delete trucks - //delete b; - b = 0; + // synced delete + trucks[b->trucknum] = 0; + // TODO: properly delete trucks + delete b; + b = 0; + } + #ifdef USE_MYGUI GUI_MainMenu::getSingleton().triggerUpdateVehicleList(); #endif // USE_MYGUI Modified: trunk/source/main/physics/BeamFactory.h =================================================================== --- trunk/source/main/physics/BeamFactory.h 2012-02-02 13:21:49 UTC (rev 2431) +++ trunk/source/main/physics/BeamFactory.h 2012-02-02 13:23:06 UTC (rev 2432) @@ -33,6 +33,7 @@ friend class Network; friend class RoRFrameListener; friend class BeamWaitAndLock; + friend class BeamWaitNoLock; public: BeamFactory(SceneManager *manager, SceneNode *parent, RenderWindow* win, Network *net, float *mapsizex, float *mapsizez, Collisions *icollisions, HeightFinder *mfinder, Water *w, Camera *pcam); ~BeamFactory(); Modified: trunk/source/main/physics/BeamWaitAndLock.h =================================================================== --- trunk/source/main/physics/BeamWaitAndLock.h 2012-02-02 13:21:49 UTC (rev 2431) +++ trunk/source/main/physics/BeamWaitAndLock.h 2012-02-02 13:23:06 UTC (rev 2432) @@ -30,9 +30,7 @@ #ifdef FEAT_DEBUG_MUTEX # define BEAMLOCK() BeamWaitAndLock sync(__FILE__, __FUNCTION__, __LINE__) #else //!FEAT_DEBUG_MUTEX -// TODO: remove this later on -# define BEAMLOCK() BeamWaitAndLock sync(__FILE__, __FUNCTION__, __LINE__) -//# define BEAMLOCK() +# define BEAMLOCK() #endif //FEAT_DEBUG_MUTEX @@ -68,4 +66,27 @@ } }; +/** + * @brief helper class that locks the vehicles array during its lifetime + */ +class BeamWaitNoLock +{ +public: + /** + * constructor + */ + BeamWaitNoLock() + { + BeamFactory::getSingleton()._waitForSyncAndLock(); + BeamFactory::getSingleton()._ReleaseLock(); + } + + /** + * destructor + */ + ~BeamWaitNoLock() + { + } +}; + #endif //__BeamLocker_H__ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Keep Your Developer Skills Current with LearnDevNow! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-d2d _______________________________________________ Rigsofrods-devel mailing list Rigsofrods-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel