mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-17 01:32:21 +02:00
Various fixes and refactorings. Restored client project to solution.
This commit is contained in:
61
lib/CBattleCallback.cpp
Normal file
61
lib/CBattleCallback.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
#define VCMI_DLL
|
||||
#include "CBattleCallback.h"
|
||||
#include "NetPacks.h"
|
||||
#include "Connection.h"
|
||||
#include "CGameState.h"
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
#include "BattleState.h"
|
||||
|
||||
CBattleCallback::CBattleCallback(CGameState *GS, int Player, IConnectionHandler *C )
|
||||
{
|
||||
gs = GS;
|
||||
player = Player;
|
||||
connHandler = C;
|
||||
}
|
||||
|
||||
bool CBattleCallback::battleMakeTacticAction( BattleAction * action )
|
||||
{
|
||||
assert(gs->curB->tacticDistance);
|
||||
MakeAction ma;
|
||||
ma.ba = *action;
|
||||
sendRequest(&ma);
|
||||
return true;
|
||||
}
|
||||
int CBattleCallback::battleMakeAction(BattleAction* action)
|
||||
{
|
||||
assert(action->actionType == BattleAction::HERO_SPELL);
|
||||
MakeCustomAction mca(*action);
|
||||
sendRequest(&mca);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CBattleCallback::sendRequest(const CPack* request)
|
||||
{
|
||||
|
||||
//TODO should be part of CClient (client owns connection, not CB)
|
||||
//but it would have to be very tricky cause template/serialization issues
|
||||
if(waitTillRealize)
|
||||
connHandler->waitingRequest.set(typeList.getTypeID(request));
|
||||
|
||||
connHandler->serv->sendPack(*request);
|
||||
|
||||
if(waitTillRealize)
|
||||
{
|
||||
if(unlockGsWhenWaiting)
|
||||
gs->mx->unlock_shared();
|
||||
connHandler->waitingRequest.waitWhileTrue();
|
||||
if(unlockGsWhenWaiting)
|
||||
gs->mx->lock_shared();
|
||||
}
|
||||
}
|
||||
|
||||
IConnectionHandler::IConnectionHandler()
|
||||
: waitingRequest(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
IConnectionHandler::~IConnectionHandler()
|
||||
{
|
||||
|
||||
}
|
Reference in New Issue
Block a user