1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00
This commit is contained in:
Michał W. Urbańczyk
2009-03-06 22:11:17 +00:00
parent f835ea9033
commit b1c0d10ece
16 changed files with 493 additions and 1327 deletions

View File

@@ -17,8 +17,8 @@ class CScriptCallback;
struct BattleResult;
struct BattleAttack;
struct BattleStackAttacked;
template <typename T> struct CPack;
template <typename T> struct Query;
struct CPack;
struct Query;
class CGHeroInstance;
extern std::map<ui32, CFunctionList<void(ui32)> > callbacks; //question id => callback functions - for selection dialogs
extern boost::mutex gsm;
@@ -116,27 +116,43 @@ public:
{
h & QID & states;
}
template <typename T> void applyAndAsk(Query<T> * sel, ui8 player, boost::function<void(ui32)> &callback)
{
gsm.lock();
sel->id = QID;
callbacks[QID] = callback;
states.addQuery(player,QID);
QID++;
sendAndApply(sel);
gsm.unlock();
}
template <typename T> void ask(Query<T> * sel, ui8 player, const CFunctionList<void(ui32)> &callback)
{
gsm.lock();
sel->id = QID;
callbacks[QID] = callback;
states.addQuery(player,QID);
sendToAllClients(sel);
QID++;
gsm.unlock();
}
//template <typename T> void applyAndAsk(Query<T> * sel, ui8 player, boost::function<void(ui32)> &callback)
//{
// gsm.lock();
// sel->id = QID;
// callbacks[QID] = callback;
// states.addQuery(player,QID);
// QID++;
// sendAndApply(sel);
// gsm.unlock();
//}
//template <typename T> void ask(Query<T> * sel, ui8 player, const CFunctionList<void(ui32)> &callback)
//{
// gsm.lock();
// sel->id = QID;
// callbacks[QID] = callback;
// states.addQuery(player,QID);
// sendToAllClients(sel);
// QID++;
// gsm.unlock();
//}
//template <typename T>void sendToAllClients(CPack<T> * info)
//{
// for(std::set<CConnection*>::iterator i=conns.begin(); i!=conns.end();i++)
// {
// (*i)->wmx->lock();
// **i << info->getType() << *info->This();
// (*i)->wmx->unlock();
// }
//}
//template <typename T>void sendAndApply(CPack<T> * info)
//{
// gs->apply(info);
// sendToAllClients(info);
//}
void applyAndAsk(Query * sel, ui8 player, boost::function<void(ui32)> &callback);
void ask(Query * sel, ui8 player, const CFunctionList<void(ui32)> &callback);
template <typename T>void sendDataToClients(const T & data)
{
for(std::set<CConnection*>::iterator i=conns.begin(); i!=conns.end();i++)
@@ -146,19 +162,14 @@ public:
(*i)->wmx->unlock();
}
}
template <typename T>void sendToAllClients(CPack<T> * info)
void sendToAllClients(CPack * info)
{
for(std::set<CConnection*>::iterator i=conns.begin(); i!=conns.end();i++)
{
(*i)->wmx->lock();
**i << info->getType() << *info->This();
(*i)->wmx->unlock();
}
}
template <typename T>void sendAndApply(CPack<T> * info)
void sendAndApply(CPack * info)
{
gs->apply(info);
sendToAllClients(info);
//gs->apply(info);
//sendToAllClients(info);
}
void run(bool resume);
void newTurn();