Commit efc3debf by Anselme

added destructors to all server classes

parent 160ab74c
......@@ -4,7 +4,7 @@ CONFIG += staticlib
CONFIG += c++11
QMAKE_CXXFLAGS += -std=c++11
QMAKE_CXXFLAGS += -Wno-comment
QMAKE_CXXFLAGS += -fno-strict-aliasing
DESTDIR = $$lib_dir
......
......@@ -18,6 +18,14 @@ MapInstance::MapInstance(Server* s):
m_mapdiffs[m_current_turn_id] = diff;
}
MapInstance::~MapInstance()
{
for(auto c : m_characters)
delete c.second;
for(auto md : m_mapdiffs)
delete md.second;
}
void MapInstance::update()
{
std::lock_guard<std::mutex> guard(m_mutex);
......
......@@ -21,6 +21,7 @@ class MapInstance
std::mutex m_mutex;
public:
MapInstance(Server* s);
~MapInstance();
void update();
void setMapData(MapKoban* new_map){m_map = new_map;}
......
......@@ -13,19 +13,26 @@ Server::Server(unsigned short port)
{
m_map = new MapInstance(this);
m_socket_handler = new SocketHandler(this,port);
new std::thread(Server::updateSockets, m_socket_handler);
m_socketUpdaterRunning = true;
new std::thread(Server::updateSockets, m_socket_handler, m_socketUpdaterRunning);
}
Server::~Server()
{
m_socketUpdaterRunning = false;
delete m_map;
delete m_socket_handler;
}
void Server::initMap(){
m_map->setMapData(MapKoban::getTestMap());
}
void Server::updateSockets(SocketHandler* socket_handler){
while(true)
void Server::updateSockets(SocketHandler* socket_handler, const bool& running){
while(running)
socket_handler->update();
}
void Server::update()
{
sf::sleep(sf::seconds(REFRESH_TIME) - m_clock.getElapsedTime());
......
......@@ -23,13 +23,16 @@ class Server
MapDiff m_diff; //m
//std::mutex m_mutex; // m?
bool m_socketUpdaterRunning;
public:
Server(unsigned short port);
~Server();
void update();
MapInstance* getMap(){return m_map;}
SocketHandler* getSocketHandler(){return m_socket_handler;}
static void updateSockets(SocketHandler* socket_handler);
static void updateSockets(SocketHandler* socket_handler, const bool &running);
// PlayerAction resolveMove(sf::Vector2i pos, Direction dir);
// void stackAction(PlayerDiff p);
......
......@@ -4,7 +4,7 @@ CONFIG += staticlib
CONFIG += c++11
QMAKE_CXXFLAGS += -std=c++11
QMAKE_CXXFLAGS += -Wno-comment
QMAKE_CXXFLAGS += -fno-strict-aliasing
DESTDIR = $$lib_dir
......
......@@ -24,6 +24,12 @@ SocketHandler::SocketHandler(Server* s,unsigned short port):
m_selector.add(m_listener);
}
SocketHandler::~SocketHandler()
{
for(auto it : m_clients)
delete it.first;
}
void SocketHandler::update(){
if(m_selector.wait())
{
......
......@@ -19,6 +19,7 @@ class SocketHandler
std::set<sf::IpAddress> m_ip_timeout_table;
public:
SocketHandler(Server* s, unsigned short port);
~SocketHandler();
void update();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment