Server can be closed correctly now.

This commit is contained in:
Quentin Bazin 2019-01-09 21:15:46 +01:00
parent 3884be8868
commit 389ee41f05
5 changed files with 16 additions and 17 deletions

4
Notes
View File

@ -1,9 +1,5 @@
Notes
# Network
## Protocol
# Lua API integration
## HUD

2
TODO
View File

@ -43,7 +43,7 @@ TODO
# Network
TODO: Client/server architecture
• DONE: Client/server architecture
# World

View File

@ -22,7 +22,7 @@
class ServerApplication : public gk::CoreApplication {
public:
ServerApplication(int argc, char **argv) : gk::CoreApplication(argc, argv) {}
ServerApplication(int argc, char **argv);
void init() override;

View File

@ -13,13 +13,17 @@
*/
#include "ServerApplication.hpp"
ServerApplication::ServerApplication(int argc, char **argv) : gk::CoreApplication(argc, argv) {
m_loadSDL = false;
}
void ServerApplication::init() {
gk::CoreApplication::init();
m_server.init();
m_server.setRunning(true);
m_server.setGameStarted(false);
gk::CoreApplication::init();
Registry::setInstance(m_registry);
// m_scriptEngine.init();
@ -27,18 +31,14 @@ void ServerApplication::init() {
void ServerApplication::mainLoop() {
while (m_server.isRunning()) {
handleEvents();
m_server.handleGameEvents();
if (m_server.hasGameStarted()) {
m_server.handleKeyState();
m_server.handleKeyState();
m_clock.updateGame([&] {
});
m_clock.updateGame([&] {
});
m_clock.waitForNextFrame();
}
m_clock.waitForNextFrame();
}
}

View File

@ -38,7 +38,7 @@ void Server::handleKeyState() {
u16 clientId;
packet >> command >> timestamp >> clientId;
std::cout << "UDP Message of type '" << Network::commandToString(command) << "' received from: " << senderAddress << ":" << senderPort << std::endl;
// std::cout << "UDP Message of type '" << Network::commandToString(command) << "' received from: " << senderAddress << ":" << senderPort << std::endl;
if (command == Network::Command::KeyState) {
Client *client = m_info.getClient(clientId);
@ -50,6 +50,9 @@ void Server::handleKeyState() {
bool isPressed;
packet >> key >> isPressed;
if (client->inputHandler.keysPressed().at(key) != isPressed)
DEBUG((int)key, "changed state to", isPressed ? "true" : "false");
client->inputHandler.setKeyPressed(key, isPressed);
}
}