WIP trying to get Eventsystem to work in client.
This commit is contained in:
@@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
#include "Network/MessageType.h"
|
#include "Network/MessageType.h"
|
||||||
#include "Network/NetworkDefines.h"
|
#include "Network/NetworkDefines.h"
|
||||||
|
#include "Core/EventBroker.h"
|
||||||
|
#include "Core/EKeyDown.h"
|
||||||
|
|
||||||
|
|
||||||
class Client
|
class Client
|
||||||
@@ -17,7 +19,7 @@ class Client
|
|||||||
public:
|
public:
|
||||||
Client();
|
Client();
|
||||||
~Client();
|
~Client();
|
||||||
void Start();
|
void Start(EventBroker* eventBroker);
|
||||||
void Close();
|
void Close();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -54,6 +56,11 @@ private:
|
|||||||
bool m_ShouldDrawGameBoard = true;
|
bool m_ShouldDrawGameBoard = true;
|
||||||
std::string m_PlayerName;
|
std::string m_PlayerName;
|
||||||
bool m_ThreadIsRunning = true;
|
bool m_ThreadIsRunning = true;
|
||||||
|
|
||||||
|
// Events
|
||||||
|
EventBroker* m_EventBroker;
|
||||||
|
EventRelay<Client, Events::KeyDown> m_EKeyDown;
|
||||||
|
bool OnKeyDown(const Events::KeyDown &e);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ private:
|
|||||||
|
|
||||||
// Network methods
|
// Network methods
|
||||||
void NetworkFunction();
|
void NetworkFunction();
|
||||||
|
// Network events
|
||||||
|
EventRelay<Client, Events::KeyDown> m_EKeyDown;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,12 @@ using namespace boost::asio::ip;
|
|||||||
|
|
||||||
Client::Client() : m_Socket(m_IOService)
|
Client::Client() : m_Socket(m_IOService)
|
||||||
{
|
{
|
||||||
|
//m_EventBroker = eventBroker;
|
||||||
// Set up network stream
|
// Set up network stream
|
||||||
m_ReceiverEndpoint = udp::endpoint(boost::asio::ip::address::from_string("192.168.1.6"), 13);
|
m_ReceiverEndpoint = udp::endpoint(boost::asio::ip::address::from_string("192.168.1.6"), 13);
|
||||||
//Start(); // All logic happens here
|
|
||||||
|
|
||||||
|
//EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Client::OnKeyDown);
|
||||||
}
|
}
|
||||||
|
|
||||||
Client::~Client()
|
Client::~Client()
|
||||||
@@ -15,8 +18,12 @@ Client::~Client()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::Start()
|
void Client::Start(EventBroker* eventBroker)
|
||||||
{
|
{
|
||||||
|
// Subscribe to events
|
||||||
|
m_EventBroker = eventBroker;
|
||||||
|
m_EKeyDown = decltype(m_EKeyDown)(std::bind(&Client::OnKeyDown, this, std::placeholders::_1));
|
||||||
|
m_EventBroker->Subscribe(m_EKeyDown);
|
||||||
std::cout << "Please enter you name: ";
|
std::cout << "Please enter you name: ";
|
||||||
std::cin >> m_PlayerName;
|
std::cin >> m_PlayerName;
|
||||||
while (m_PlayerName.size() > 7) {
|
while (m_PlayerName.size() > 7) {
|
||||||
@@ -91,7 +98,7 @@ void Client::DisplayLoop()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (m_ShouldDrawGameBoard)
|
if (m_ShouldDrawGameBoard)
|
||||||
DrawBoard();
|
//DrawBoard();
|
||||||
boost::this_thread::sleep(boost::posix_time::millisec(100));
|
boost::this_thread::sleep(boost::posix_time::millisec(100));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -332,3 +339,9 @@ void Client::SendInput()
|
|||||||
memset(dataPackage, 0, INPUTSIZE);
|
memset(dataPackage, 0, INPUTSIZE);
|
||||||
delete[] dataPackage;
|
delete[] dataPackage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Client::OnKeyDown(const Events::KeyDown& event)
|
||||||
|
{
|
||||||
|
std::cout << event.KeyCode;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
+9
-7
@@ -39,7 +39,8 @@ Game::Game(int argc, char* argv[])
|
|||||||
m_World = new HardcodedTestWorld();
|
m_World = new HardcodedTestWorld();
|
||||||
|
|
||||||
// TEMP: Invoke network
|
// TEMP: Invoke network
|
||||||
boost::thread workerThread(&Game::NetworkFunction, this);
|
|
||||||
|
boost::thread workerThread(&Game::NetworkFunction, this);
|
||||||
|
|
||||||
m_LastTime = glfwGetTime();
|
m_LastTime = glfwGetTime();
|
||||||
}
|
}
|
||||||
@@ -56,6 +57,7 @@ void Game::Tick()
|
|||||||
double currentTime = glfwGetTime();
|
double currentTime = glfwGetTime();
|
||||||
double dt = currentTime - m_LastTime;
|
double dt = currentTime - m_LastTime;
|
||||||
m_LastTime = currentTime;
|
m_LastTime = currentTime;
|
||||||
|
m_EventBroker->Process<Client>();
|
||||||
|
|
||||||
m_EventBroker->Swap();
|
m_EventBroker->Swap();
|
||||||
m_InputManager->Update(dt);
|
m_InputManager->Update(dt);
|
||||||
@@ -74,10 +76,10 @@ void Game::Tick()
|
|||||||
|
|
||||||
void Game::NetworkFunction()
|
void Game::NetworkFunction()
|
||||||
{
|
{
|
||||||
std::string inputMessage;
|
std::string inputMessage;
|
||||||
std::cout << "Start client or server? (c/s)" << std::endl;
|
std::cout << "Start client or server? (c/s)" << std::endl;
|
||||||
std::cin >> inputMessage;
|
std::cin >> inputMessage;
|
||||||
if (inputMessage == "c" || inputMessage == "C") {
|
if (inputMessage == "c" || inputMessage == "C") {
|
||||||
m_Client.Start();
|
m_Client.Start(m_EventBroker);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user