1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00
CPlayerInterface instances were removed from CClient::playerint with
clear() and finish() was not called on each. Added multiple insurance.
This commit is contained in:
Vadim Markovtsev 2016-10-22 16:22:00 +02:00
parent d51c9a1ff0
commit 4bcc43d3d0
7 changed files with 17 additions and 11 deletions

View File

@ -101,6 +101,7 @@ VCAI::VCAI(void)
VCAI::~VCAI(void)
{
LOG_TRACE(logAi);
finish();
}
void VCAI::availableCreaturesChanged(const CGDwelling *town)
@ -2750,7 +2751,10 @@ void VCAI::recruitHero(const CGTownInstance * t, bool throwing)
void VCAI::finish()
{
if(makingTurn)
{
makingTurn->interrupt();
makingTurn->join();
}
}
void VCAI::requestActionASAP(std::function<void()> whatToDo)

View File

@ -159,7 +159,7 @@ public:
std::unique_ptr<boost::thread> makingTurn;
VCAI(void);
~VCAI(void);
virtual ~VCAI(void);
//TODO: use only smart pointers?
void tryRealize(Goals::Explore & g);

View File

@ -321,6 +321,8 @@ void CCallback::castSpell(const CGHeroInstance *hero, SpellID spellID, const int
void CCallback::unregisterAllInterfaces()
{
for (auto& pi : cl->playerint)
pi.second->finish();
cl->playerint.clear();
cl->battleints.clear();
}

View File

@ -206,7 +206,7 @@ void CClient::save(const std::string & fname)
void CClient::endGame( bool closeConnection /*= true*/ )
{
//suggest interfaces to finish their stuff (AI should interrupt any bg working threads)
for(auto i : playerint)
for(auto& i : playerint)
i.second->finish();
// Game is ending

View File

@ -59,7 +59,7 @@ public:
static CConnection * justConnectToServer(const std::string &host = "", const std::string &port = ""); //connects to given host without taking any other actions (like setting up server)
CServerHandler(bool runServer = false);
~CServerHandler();
virtual ~CServerHandler();
};
template<typename T>
@ -72,7 +72,6 @@ class ThreadSafeVector
boost::condition_variable cond;
public:
void pushBack(const T &item)
{
TLock lock(mx);

View File

@ -19,7 +19,7 @@ extern boost::mutex eventsM;
CondSh<bool> CGuiHandler::terminate_cond;
boost::thread_specific_ptr<bool> inGuiThread;
SObjectConstruction::SObjectConstruction( CIntObject *obj )
SObjectConstruction::SObjectConstruction(CIntObject *obj)
:myObj(obj)
{
GH.createdObj.push_front(obj);
@ -86,7 +86,7 @@ void CGuiHandler::handleElementDeActivate(CIntObject * elem, ui16 activityFlag)
elem->active_m &= ~activityFlag;
}
void CGuiHandler::popInt( IShowActivatable *top )
void CGuiHandler::popInt(IShowActivatable *top)
{
assert(listInt.front() == top);
top->deactivate();
@ -97,7 +97,7 @@ void CGuiHandler::popInt( IShowActivatable *top )
totalRedraw();
}
void CGuiHandler::popIntTotally( IShowActivatable *top )
void CGuiHandler::popIntTotally(IShowActivatable *top)
{
assert(listInt.front() == top);
popInt(top);
@ -105,7 +105,7 @@ void CGuiHandler::popIntTotally( IShowActivatable *top )
fakeMouseMove();
}
void CGuiHandler::pushInt( IShowActivatable *newInt )
void CGuiHandler::pushInt(IShowActivatable *newInt)
{
assert(newInt);
assert(boost::range::find(listInt, newInt) == listInt.end()); // do not add same object twice
@ -121,7 +121,7 @@ void CGuiHandler::pushInt( IShowActivatable *newInt )
totalRedraw();
}
void CGuiHandler::popInts( int howMany )
void CGuiHandler::popInts(int howMany)
{
if(!howMany) return; //senseless but who knows...
@ -364,7 +364,7 @@ void CGuiHandler::simpleRedraw()
objsToBlit.back()->show(screen); //blit active interface/window
}
void CGuiHandler::handleMoveInterested( const SDL_MouseMotionEvent & motion )
void CGuiHandler::handleMoveInterested(const SDL_MouseMotionEvent & motion)
{
//sending active, MotionInterested objects mouseMoved() call
std::list<CIntObject*> miCopy = motioninterested;
@ -463,7 +463,7 @@ void CGuiHandler::drawFPSCounter()
graphics->fonts[FONT_BIG]->renderTextLeft(screen, fps, yellow, Point(10, 10));
}
SDL_Keycode CGuiHandler::arrowToNum(SDL_Keycode key )
SDL_Keycode CGuiHandler::arrowToNum(SDL_Keycode key)
{
switch(key)
{

View File

@ -82,6 +82,7 @@ public:
class DLL_LINKAGE CGameInterface : public CBattleGameInterface, public IGameEventsReceiver
{
public:
virtual ~CGameInterface() = default;
virtual void init(std::shared_ptr<CCallback> CB){};
virtual void yourTurn(){}; //called AFTER playerStartsTurn(player)