فهرست منبع

Conurrency related tweaks. Crashes in renderFrame should be fixed, but synchronization is still not perfect

AlexVinS 10 سال پیش
والد
کامیت
c46999bcb8
6فایلهای تغییر یافته به همراه13 افزوده شده و 11 حذف شده
  1. 2 2
      client/CPlayerInterface.cpp
  2. 1 1
      client/CPlayerInterface.h
  3. 2 2
      client/CPreGame.cpp
  4. 1 1
      client/CPreGame.h
  5. 6 4
      client/gui/CGuiHandler.cpp
  6. 1 1
      client/gui/CIntObject.h

+ 2 - 2
client/CPlayerInterface.cpp

@@ -1607,7 +1607,7 @@ void CPlayerInterface::update()
 		GH.drawFPSCounter();
 }
 
-void CPlayerInterface::runLocked(std::function<void(IUpdateable * )> functor)
+void CPlayerInterface::runLocked(std::function<void()> functor)
 {
 	// Updating GUI requires locking pim mutex (that protects screen and GUI state).
 	// When ending the game, the pim mutex might be hold by other thread,
@@ -1635,7 +1635,7 @@ void CPlayerInterface::runLocked(std::function<void(IUpdateable * )> functor)
 	boost::shared_lock<boost::shared_mutex> gsLock(cb->getGsMutex());
 
 	locked = true;
-	functor(this);
+	functor();
 	locked = false;
 }
 

+ 1 - 1
client/CPlayerInterface.h

@@ -134,7 +134,7 @@ public:
 	} spellbookSettings;
 
 	void update() override;
-	void runLocked(std::function<void(IUpdateable * )> functor) override;
+	void runLocked(std::function<void()> functor) override;
 	void initializeHeroTownList();
 	int getLastIndex(std::string namePrefix);
 

+ 2 - 2
client/CPreGame.cpp

@@ -543,10 +543,10 @@ void CGPreGame::update()
 		GH.drawFPSCounter();
 }
 
-void CGPreGame::runLocked(std::function<void(IUpdateable * )> cb)
+void CGPreGame::runLocked(std::function<void()> cb)
 {
 	boost::unique_lock<boost::recursive_mutex> lock(*CPlayerInterface::pim);
-	cb(this);	
+	cb();	
 }
 
 void CGPreGame::openCampaignScreen(std::string name)

+ 1 - 1
client/CPreGame.h

@@ -609,7 +609,7 @@ public:
 
 	~CGPreGame();
 	void update() override;
-	void runLocked(std::function<void(IUpdateable * )> cb) override;
+	void runLocked(std::function<void()> cb) override;
 	void openSel(CMenuScreen::EState type, CMenuScreen::EMultiMode multi = CMenuScreen::SINGLE_PLAYER);
 
 	void openCampaignScreen(std::string name);

+ 6 - 4
client/gui/CGuiHandler.cpp

@@ -411,10 +411,12 @@ void CGuiHandler::fakeMouseMove()
 
 void CGuiHandler::renderFrame()
 {
-	auto doUpdate = [](IUpdateable * target)
+	auto doUpdate = [this]()
 	{
-		if(nullptr != target)
-			target -> update();
+		if(nullptr != curInt)
+		{
+			curInt -> update();
+		}			
 		// draw the mouse cursor and update the screen
 		CCS->curh->render();
 
@@ -430,7 +432,7 @@ void CGuiHandler::renderFrame()
 	if(curInt)
 		curInt->runLocked(doUpdate);
 	else
-		doUpdate(nullptr);
+		doUpdate();
 	
 	mainFPSmng->framerateDelay(); // holds a constant FPS	
 }

+ 1 - 1
client/gui/CIntObject.h

@@ -41,7 +41,7 @@ public:
 class ILockedUpdatable: public IUpdateable
 {
 public:
-	virtual void runLocked(std::function<void(IUpdateable * )> cb) = 0;
+	virtual void runLocked(std::function<void()> cb) = 0;
 	virtual ~ILockedUpdatable(){}; //d-tor
 };