diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index 695b54a..aee7d6b 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -25,6 +25,11 @@ #include +//debugging +#include +using std::cout; +using std::endl; + //------------------------- //Public access members //------------------------- @@ -80,7 +85,7 @@ InWorld::InWorld(ConfigUtility* const argConfig, UDPNetworkUtility* const argNet network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE); //debug - mapPager.GetRegion(0, 0); + RequestRegion(0, 0); } InWorld::~InWorld() { @@ -327,6 +332,15 @@ void InWorld::HandleRegionContent(NetworkPacket packet) { } mapPager.PushRegion(packet.regionInfo.region); packet.regionInfo.region = nullptr; + + //debugging + cout << "Received region: " << packet.regionInfo.x << ", " << packet.regionInfo.y << endl; + if (mapPager.FindRegion(packet.regionInfo.x, packet.regionInfo.y)) { + cout << "Success" << endl; + } + else { + cout << "Failure" << endl; + } } //------------------------- @@ -373,7 +387,7 @@ void InWorld::RequestShutDown() { } void InWorld::UpdateMap() { - // + //TODO } void InWorld::RequestRegion(int x, int y) { @@ -382,9 +396,6 @@ void InWorld::RequestRegion(int x, int y) { //pack the region's data packet.meta.type = NetworkPacket::Type::REGION_REQUEST; - packet.regionInfo.width = mapPager.GetRegionWidth(); - packet.regionInfo.height = mapPager.GetRegionHeight(); - packet.regionInfo.depth = mapPager.GetRegionDepth(); packet.regionInfo.x = x; packet.regionInfo.y = y; serialize(&packet, buffer); diff --git a/common/map/region.cpp b/common/map/region.cpp index e47100c..8dd701b 100644 --- a/common/map/region.cpp +++ b/common/map/region.cpp @@ -21,12 +21,6 @@ */ #include "region.hpp" -#include -#include - -//decorator -#define TRY(x) try { x } catch(std::exception& e) { throw std::runtime_error(std::string() + e.what() + ": " + #x); } - Region::Region(int argWidth, int argHeight, int argDepth, int argX, int argY): width(argWidth), height(argHeight), @@ -34,11 +28,11 @@ Region::Region(int argWidth, int argHeight, int argDepth, int argX, int argY): x(argX), y(argY) { - TRY(tiles = new type_t**[width];) + tiles = new type_t**[width]; for (register int i = 0; i < width; ++i) { - TRY(tiles[i] = new type_t*[height];) + tiles[i] = new type_t*[height]; for (register int j = 0; j < height; ++j) { - TRY(tiles[i][j] = new type_t[depth];) + tiles[i][j] = new type_t[depth]; for (register int k = 0; k < depth; ++k) { tiles[i][j][k] = 0; } diff --git a/common/map/region_pager.cpp b/common/map/region_pager.cpp index 9589b3c..8b2517a 100644 --- a/common/map/region_pager.cpp +++ b/common/map/region_pager.cpp @@ -23,11 +23,6 @@ #include "utility.hpp" -#include -#include - -using namespace std; - RegionPagerBase::RegionPagerBase(int argWidth, int argHeight, int argDepth): regionWidth(argWidth), regionHeight(argHeight), @@ -59,29 +54,11 @@ Region* RegionPagerBase::GetRegion(int x, int y) { //TODO: revert this try/catch point Region* ptr = nullptr; - try { - ptr = FindRegion(x, y); - if (ptr) return ptr; - } - catch(exception& e) { - cerr << "FindRegion Error: " << e.what() << endl; - } - - try { - ptr = LoadRegion(x, y); - if (ptr) return ptr; - } - catch(exception& e) { - cerr << "LoadRegion Error: " << e.what() << endl; - } - - try { - return CreateRegion(x, y); - } - catch(exception& e) { - cerr << "CreateRegion Error: " << e.what() << endl; - } - return nullptr; + ptr = FindRegion(x, y); + if (ptr) return ptr; + ptr = LoadRegion(x, y); + if (ptr) return ptr; + return CreateRegion(x, y); } Region* RegionPagerBase::FindRegion(int x, int y) { diff --git a/server/server_application.cpp b/server/server_application.cpp index 3532a63..890809d 100644 --- a/server/server_application.cpp +++ b/server/server_application.cpp @@ -114,7 +114,7 @@ void ServerApplication::Init(int argc, char** argv) { cout << "Startup completed successfully" << endl; //debugging - mapPager.GetRegion(0, 0); + // } void ServerApplication::Loop() { @@ -180,6 +180,9 @@ void ServerApplication::HandlePacket(NetworkPacket packet) { case NetworkPacket::Type::PLAYER_UPDATE: HandlePlayerUpdate(packet); break; + case NetworkPacket::Type::REGION_REQUEST: + HandleRegionRequest(packet); + break; //handle errors default: throw(runtime_error("Unknown NetworkPacket::Type encountered")); @@ -340,6 +343,14 @@ void ServerApplication::HandlePlayerUpdate(NetworkPacket packet) { PumpPacket(packet); } +void ServerApplication::HandleRegionRequest(NetworkPacket packet) { + char buffer[PACKET_BUFFER_SIZE]; + packet.meta.type = NetworkPacket::Type::REGION_CONTENT; + packet.regionInfo.region = mapPager.GetRegion(packet.regionInfo.x, packet.regionInfo.y); + serialize(&packet, buffer); + network.Send(&packet.meta.srcAddress, buffer, PACKET_BUFFER_SIZE); +} + void ServerApplication::PumpPacket(NetworkPacket packet) { //I don't really like this, but it'll do for now char buffer[PACKET_BUFFER_SIZE]; diff --git a/server/server_application.hpp b/server/server_application.hpp index d3d30fa..97610cf 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -81,6 +81,7 @@ private: void HandlePlayerNew(NetworkPacket); void HandlePlayerDelete(NetworkPacket); void HandlePlayerUpdate(NetworkPacket); + void HandleRegionRequest(NetworkPacket); void PumpPacket(NetworkPacket);