Changes in preparation for the integration of the network server. GUI does not directly know Game and Hand any more, only Session. WARNING: This version crashes due to initialization order problems.
This commit is contained in:
@@ -80,10 +80,10 @@ ServerRecvThread::AddConnection(boost::shared_ptr<ConnectData> data)
|
||||
}
|
||||
|
||||
void
|
||||
ServerRecvThread::AddNotification(unsigned notification)
|
||||
ServerRecvThread::AddNotification(unsigned message, unsigned param1, unsigned param2)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_notificationQueueMutex);
|
||||
m_notificationQueue.push_back(notification);
|
||||
m_notificationQueue.push_back(Notification(message, param1, param2));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -135,14 +135,16 @@ ServerRecvThread::NotificationLoop()
|
||||
// Process all notifications.
|
||||
while (!m_notificationQueue.empty())
|
||||
{
|
||||
unsigned notification = m_notificationQueue.front();
|
||||
Notification notification = m_notificationQueue.front();
|
||||
m_notificationQueue.pop_front();
|
||||
|
||||
switch(notification)
|
||||
switch(notification.message)
|
||||
{
|
||||
case NOTIFY_GAME_START:
|
||||
SetState(SERVER_START_GAME_STATE::Instance());
|
||||
break;
|
||||
case NOTIFY_WAIT_FOR_CLIENT_ACTION:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,17 @@ ServerThread::StartGame()
|
||||
return; // TODO: throw exception
|
||||
|
||||
// Thread-safe notification.
|
||||
GetRecvThread().AddNotification(NOTIFY_GAME_START);
|
||||
GetRecvThread().AddNotification(NOTIFY_GAME_START, 0, 0);
|
||||
}
|
||||
|
||||
void
|
||||
ServerThread::WaitForClientAction(GameState state, unsigned uniquePlayerId)
|
||||
{
|
||||
if (!IsRunning())
|
||||
return; // TODO: throw exception
|
||||
|
||||
// Thread-safe notification.
|
||||
GetRecvThread().AddNotification(NOTIFY_WAIT_FOR_CLIENT_ACTION, state, uniquePlayerId);
|
||||
}
|
||||
|
||||
ServerCallback &
|
||||
|
||||
@@ -36,7 +36,8 @@
|
||||
#define RECEIVER_THREAD_TERMINATE_TIMEOUT 200
|
||||
|
||||
// Notifications
|
||||
#define NOTIFY_GAME_START 1
|
||||
#define NOTIFY_GAME_START 1
|
||||
#define NOTIFY_WAIT_FOR_CLIENT_ACTION 2
|
||||
|
||||
class ServerRecvState;
|
||||
class SenderThread;
|
||||
@@ -54,15 +55,24 @@ public:
|
||||
void Init(const std::string &pwd, const GameData &gameData);
|
||||
|
||||
void AddConnection(boost::shared_ptr<ConnectData> data);
|
||||
void AddNotification(unsigned notification);
|
||||
void AddNotification(unsigned message, unsigned param1, unsigned param2);
|
||||
|
||||
ServerCallback &GetCallback();
|
||||
|
||||
protected:
|
||||
|
||||
struct Notification
|
||||
{
|
||||
Notification(unsigned m, unsigned p1, unsigned p2)
|
||||
: message(m), param1(p1), param2(p2) {}
|
||||
unsigned message;
|
||||
unsigned param1;
|
||||
unsigned param2;
|
||||
};
|
||||
|
||||
typedef std::deque<boost::shared_ptr<ConnectData> > ConnectQueue;
|
||||
typedef std::map<SOCKET, boost::shared_ptr<SessionData> > SocketSessionMap;
|
||||
typedef std::deque<unsigned> NotificationQueue;
|
||||
typedef std::deque<Notification> NotificationQueue;
|
||||
typedef std::list<std::pair<boost::microsec_timer, boost::shared_ptr<SessionData> > > CloseSessionList;
|
||||
|
||||
// Main function of the thread.
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#ifndef _SERVERTHREAD_H_
|
||||
#define _SERVERTHREAD_H_
|
||||
|
||||
#include <game_defs.h>
|
||||
#include <core/thread.h>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
@@ -42,6 +43,7 @@ public:
|
||||
void Init(unsigned serverPort, bool ipv6, const std::string &pwd,
|
||||
const GameData &gameData);
|
||||
void StartGame();
|
||||
void WaitForClientAction(GameState state, unsigned uniquePlayerId);
|
||||
|
||||
ServerCallback &GetCallback();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user