BUILD_SERVER cleanup

This commit is contained in:
mrkubax10 2023-04-24 13:20:09 +02:00
parent bc0717b189
commit 0cb42976d8
6 changed files with 47 additions and 47 deletions

View File

@ -26,6 +26,7 @@ endif()
if(BUILD_CLIENT) if(BUILD_CLIENT)
file(GLOB_RECURSE CLIENT_SOURCES "src/game/**.cpp") file(GLOB_RECURSE CLIENT_SOURCES "src/game/**.cpp")
file(GLOB_RECURSE VENDOR_SOURCES "src/vendor/**.cpp")
endif() endif()
if(BUILD_SERVER) if(BUILD_SERVER)
file(GLOB_RECURSE SERVER_SOURCES "src/server/**.cpp") file(GLOB_RECURSE SERVER_SOURCES "src/server/**.cpp")
@ -34,8 +35,10 @@ if(RENDERER_GL)
file(GLOB_RECURSE RENDERER_GL_SOURCES "src/game/renderer/gl/**.cpp") file(GLOB_RECURSE RENDERER_GL_SOURCES "src/game/renderer/gl/**.cpp")
endif() endif()
file(GLOB_RECURSE COMMON_SOURCES "src/common/**.cpp") file(GLOB_RECURSE COMMON_SOURCES "src/common/**.cpp")
file(GLOB_RECURSE VENDOR_SOURCES "src/vendor/**.cpp")
if(BUILD_SERVER AND NOT BUILD_CLIENT)
set(PROJECT_NAME "polygun_server")
endif()
add_executable(${PROJECT_NAME} add_executable(${PROJECT_NAME}
${CLIENT_SOURCES} ${CLIENT_SOURCES}
${SERVER_SOURCES} ${SERVER_SOURCES}
@ -45,6 +48,7 @@ add_executable(${PROJECT_NAME}
src/main.cpp src/main.cpp
) )
if(BUILD_CLIENT)
if(NOT OPENGL_INCLUDE_DIR OR NOT OPENGL_LIBRARIES) if(NOT OPENGL_INCLUDE_DIR OR NOT OPENGL_LIBRARIES)
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
endif() endif()
@ -77,13 +81,15 @@ include_directories("${VORBIS_INCLUDE_DIR}")
target_link_libraries(${PROJECT_NAME} "${VORBIS_LIBRARY}") target_link_libraries(${PROJECT_NAME} "${VORBIS_LIBRARY}")
target_link_libraries(${PROJECT_NAME} "${OGG_LIBRARY}") target_link_libraries(${PROJECT_NAME} "${OGG_LIBRARY}")
if(UNIX)
target_link_libraries(${PROJECT_NAME} "dl")
endif()
endif()
if(WIN32) if(WIN32)
target_link_libraries(${PROJECT_NAME} "ws2_32") target_link_libraries(${PROJECT_NAME} "ws2_32")
endif() endif()
if(UNIX)
target_link_libraries(${PROJECT_NAME} "dl")
endif()
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
target_link_libraries(${PROJECT_NAME} "${CMAKE_THREAD_LIBS_INIT}") target_link_libraries(${PROJECT_NAME} "${CMAKE_THREAD_LIBS_INIT}")

View File

@ -25,7 +25,6 @@ SOFTWARE.
#include "common/network/network_manager.hpp" #include "common/network/network_manager.hpp"
#include <algorithm> #include <algorithm>
#include <GLFW/glfw3.h>
#include "common/logger.hpp" #include "common/logger.hpp"
@ -92,7 +91,7 @@ void NetworkManager::push_packet(const NetworkPacket& packet) {
} }
if(m_incoming_packet_counter<=packet.get_num()) { if(m_incoming_packet_counter<=packet.get_num()) {
m_incoming_packets.push_back(QueuedPacket{packet, glfwGetTime(), 0}); m_incoming_packets.push_back(QueuedPacket{packet, time(0), 0});
sort_packets(m_incoming_packets); sort_packets(m_incoming_packets);
} }
else { // send ACK just in case else { // send ACK just in case
@ -116,11 +115,11 @@ void NetworkManager::update() {
i--; i--;
continue; continue;
} }
if(glfwGetTime()-packet.m_last_retry>=NETWORK_MANAGER_PACKET_RETRY_INTERVAL) { if(time(0)-packet.m_last_retry>=NETWORK_MANAGER_PACKET_RETRY_INTERVAL) {
if(packet.m_last_retry>0) if(packet.m_last_retry>0)
LOG_VERBOSE("Resending reliable packet with num %d",packet.m_packet.get_num()); LOG_VERBOSE("Resending reliable packet with num %d",packet.m_packet.get_num());
m_socket->send(packet.m_packet, m_endpoint); m_socket->send(packet.m_packet, m_endpoint);
packet.m_last_retry = glfwGetTime(); packet.m_last_retry = time(0);
packet.m_retries++; packet.m_retries++;
} }
} }
@ -132,8 +131,8 @@ void NetworkManager::update() {
// TODO: Quit from game // TODO: Quit from game
return; return;
} }
if(glfwGetTime()-packet.m_last_retry>NETWORK_MANAGER_PACKET_RETRY_INTERVAL) { if(time(0)-packet.m_last_retry>NETWORK_MANAGER_PACKET_RETRY_INTERVAL) {
packet.m_last_retry = glfwGetTime(); packet.m_last_retry = time(0);
packet.m_retries++; packet.m_retries++;
} }
} }

View File

@ -35,7 +35,7 @@ namespace polygun::network {
public: public:
struct QueuedPacket { struct QueuedPacket {
NetworkPacket m_packet; NetworkPacket m_packet;
double m_last_retry; time_t m_last_retry;
uint8_t m_retries; uint8_t m_retries;
}; };
public: public:

View File

@ -24,8 +24,6 @@ SOFTWARE.
#include "server/client.hpp" #include "server/client.hpp"
#include <GLFW/glfw3.h>
using namespace polygun::server; using namespace polygun::server;
Client::Client(std::unique_ptr<polygun::network::NetworkManager> network_manager) : Client::Client(std::unique_ptr<polygun::network::NetworkManager> network_manager) :
@ -34,11 +32,11 @@ Client::Client(std::unique_ptr<polygun::network::NetworkManager> network_manager
m_uuid(0), m_uuid(0),
m_pos(), m_pos(),
m_join_completed(false), m_join_completed(false),
m_last_activity(glfwGetTime()) m_last_activity(time(0))
{ {
m_network_manager = std::move(network_manager); m_network_manager = std::move(network_manager);
} }
void Client::update_activity() { void Client::update_activity() {
m_last_activity = glfwGetTime(); m_last_activity = time(0);
} }

View File

@ -46,7 +46,7 @@ namespace polygun::server {
const std::string& get_nick() const { return m_nick; } const std::string& get_nick() const { return m_nick; }
uint32_t get_uuid() const { return m_uuid; } uint32_t get_uuid() const { return m_uuid; }
bool get_join_completed() const { return m_join_completed; } bool get_join_completed() const { return m_join_completed; }
double get_last_activity() const { return m_last_activity; } time_t get_last_activity() const { return m_last_activity; }
private: private:
std::unique_ptr<polygun::network::NetworkManager> m_network_manager; std::unique_ptr<polygun::network::NetworkManager> m_network_manager;
@ -54,7 +54,7 @@ namespace polygun::server {
uint32_t m_uuid; uint32_t m_uuid;
glm::vec3 m_pos; glm::vec3 m_pos;
bool m_join_completed; bool m_join_completed;
double m_last_activity; time_t m_last_activity;
}; };
} }

View File

@ -25,7 +25,6 @@ SOFTWARE.
#include "server/server.hpp" #include "server/server.hpp"
#include <cstring> #include <cstring>
#include <GLFW/glfw3.h>
#include <iostream> #include <iostream>
#include <csignal> #include <csignal>
#if defined(__unix__) #if defined(__unix__)
@ -50,7 +49,6 @@ Server::Server(std::atomic<bool>* running_atomic) :
LOG_INFO("Starting server"); LOG_INFO("Starting server");
m_server_socket->bind(1337); m_server_socket->bind(1337);
if(m_running_atomic_created) { if(m_running_atomic_created) {
glfwInit();
srand(time(nullptr)); srand(time(nullptr));
m_running->store(true); m_running->store(true);
g_current_server = this; g_current_server = this;
@ -68,7 +66,6 @@ Server::~Server() {
LOG_VERBOSE("Waiting for command thread to finish"); LOG_VERBOSE("Waiting for command thread to finish");
if(m_command_thread->joinable()) if(m_command_thread->joinable())
m_command_thread->join(); m_command_thread->join();
glfwTerminate();
delete m_running; delete m_running;
} }
} }
@ -82,7 +79,7 @@ void Server::run() {
sender.sin_family = AF_INET; sender.sin_family = AF_INET;
sender.sin_addr.s_addr = INADDR_ANY; sender.sin_addr.s_addr = INADDR_ANY;
for(size_t i = 0; i<m_clients.size(); i++) { for(size_t i = 0; i<m_clients.size(); i++) {
if(glfwGetTime()-m_clients[i]->get_last_activity()>=10) { if(time(0)-m_clients[i]->get_last_activity()>=10) {
handle_player_timeout(m_clients[i].get()); handle_player_timeout(m_clients[i].get());
m_clients.erase(m_clients.begin()+i); m_clients.erase(m_clients.begin()+i);
i--; i--;