Server can be closed correctly now.
This commit is contained in:
parent
3884be8868
commit
389ee41f05
2
TODO
2
TODO
@ -43,7 +43,7 @@ TODO
|
||||
|
||||
# Network
|
||||
|
||||
• TODO: Client/server architecture
|
||||
• DONE: Client/server architecture
|
||||
|
||||
# World
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user