diff --git a/server/server_application.cpp b/server/server_application.cpp index 00b0ddf..fd45f0c 100644 --- a/server/server_application.cpp +++ b/server/server_application.cpp @@ -90,20 +90,14 @@ void ServerApplication::Init(int argc, char** argv) { sqlite3_exec(database, script.c_str(), nullptr, nullptr, nullptr); //open the rooms - cout << "DEBUG: inserting the room..." << endl; - worldRoomMap.insert( pair(worldRoomCounter++, WorldRoom(playerMap))); - - cout << "DEBUG: opening the rooms..." << endl; + worldRoomMap.insert( pair(worldRoomCounter++, new WorldRoom(playerMap))); for (auto& it : worldRoomMap) { - it.second.OpenRoom(); + it.second->OpenRoom(); } - cout << "DEBUG: Finished initialization" << endl; } void ServerApplication::Loop() { - //debugging - NetworkPacket packet; while(running) { @@ -127,7 +121,8 @@ void ServerApplication::Loop() { void ServerApplication::Quit() { //close the rooms for (auto& it : worldRoomMap) { - it.second.CloseRoom(); + it.second->CloseRoom(); + delete it.second; } worldRoomMap.clear(); @@ -143,7 +138,7 @@ void ServerApplication::Quit() { void ServerApplication::HandlePacket(NetworkPacket packet) { //debgging for (auto& it : worldRoomMap) { - it.second.GetInQueue()->PushBack(packet); + it.second->GetInQueue()->PushBack(packet); } switch(packet.meta.type) { diff --git a/server/server_application.hpp b/server/server_application.hpp index a8318fe..7ed59f3 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -82,7 +82,7 @@ private: //global lists ClientMap clientMap; PlayerMap playerMap; - WorldRoomMap worldRoomMap; + std::map worldRoomMap; int clientCounter = 0; int playerCounter = 0; diff --git a/server/world_room.cpp b/server/world_room.cpp index a012e96..7876a48 100644 --- a/server/world_room.cpp +++ b/server/world_room.cpp @@ -27,22 +27,16 @@ using namespace std; int worldRoomThread(void* arg) { - cout << "DEBUG: in room thread" << endl; WorldRoom* room = reinterpret_cast(arg); - cout << "DEBUG: Beginning try block" << endl; try { - cout << "DEBUG: Init" << endl; room->Init(); - cout << "DEBUG: Loop" << endl; room->Loop(); - cout << "DEBUG: Quit" << endl; room->Quit(); } catch(exception& e) { cerr << "Fatal room error: " << e.what() << endl; return 1; } - cout << "DEBUG: Successfully ending room thread" << endl; return 0; } @@ -57,18 +51,15 @@ WorldRoom::~WorldRoom() { } void WorldRoom::OpenRoom() { - cout << "DEBUG: In OpenRoom" << endl; if (running) { throw(std::runtime_error("Cannot open a room that is already running")); } running = true; - cout << "DEBUG: Attempting to create thread" << endl; if (!(thread = SDL_CreateThread(worldRoomThread, this))) { throw(std::runtime_error("Failed to open the room thread")); } - cout << "DEBUG: End of thread call" << endl; } void WorldRoom::CloseRoom() { @@ -86,9 +77,7 @@ void WorldRoom::Init() { } void WorldRoom::Loop() { - cout << "DEBUG: In Loop" << endl; while(running) { - cout << "DEBUG: Top of loop" << endl; while(networkInQueue.Size() > 0) { HandlePacket(networkInQueue.PopFront()); } diff --git a/server/world_room.hpp b/server/world_room.hpp index dfea084..a2cc664 100644 --- a/server/world_room.hpp +++ b/server/world_room.hpp @@ -60,6 +60,4 @@ private: PlayerMap playerMap; }; -typedef std::map WorldRoomMap; - #endif