diff --git a/client/scenes/in_world.cpp b/client/scenes/in_world.cpp index 1890699..38b39c1 100644 --- a/client/scenes/in_world.cpp +++ b/client/scenes/in_world.cpp @@ -63,14 +63,11 @@ InWorld::InWorld(ConfigUtility* const argConfig, UDPNetworkUtility* const argNet shutDownButton.SetText("Shut Down"); //load the tilesheet + //TODO: add the tilesheet to the map system? tileSheet.Load(config["dir.tilesets"] + "terrain.bmp", 12, 15); - //setup the map object - mapPager.SetRegionWidth(REGION_WIDTH); - mapPager.SetRegionHeight(REGION_HEIGHT); - mapPager.SetRegionDepth(REGION_DEPTH); - //create the server-side player object + //TODO: the login system needs an overhaul NetworkPacket packet; packet.meta.type = NetworkPacket::Type::PLAYER_NEW; packet.playerInfo.clientIndex = clientIndex; @@ -143,7 +140,8 @@ void InWorld::RenderFrame() { void InWorld::Render(SDL_Surface* const screen) { //draw the map - for (auto it = mapPager.GetContainer()->begin(); it != mapPager.GetContainer()->end(); it++) { + //TODO: figure out something to fix the region container access + for (auto it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); it++) { tileSheet.DrawRegionTo(screen, *it, camera.x, camera.y); } @@ -347,15 +345,15 @@ void InWorld::HandlePlayerUpdate(NetworkPacket packet) { void InWorld::HandleRegionContent(NetworkPacket packet) { //replace existing regions - if (mapPager.FindRegion(packet.regionInfo.x, packet.regionInfo.y)) { - mapPager.UnloadRegion(packet.regionInfo.x, packet.regionInfo.y); + if (regionPager.FindRegion(packet.regionInfo.x, packet.regionInfo.y)) { + regionPager.UnloadRegion(packet.regionInfo.x, packet.regionInfo.y); } - mapPager.PushRegion(packet.regionInfo.region); + regionPager.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)) { + if (regionPager.FindRegion(packet.regionInfo.x, packet.regionInfo.y)) { cout << "Success" << endl; } else { @@ -421,7 +419,8 @@ void InWorld::RequestRegion(int x, int y) { //------------------------- int InWorld::CheckBufferDistance(Region* const region) { - /* DOCUMENTATION + /* TODO: Remove InWorld::CheckBufferDistance(), and replace it with a simpler system + * DOCUMENTATION * This algorithm is extremely complex and involed, but initial tests show * that it gives the right answers. The purpose is to determine how far off screen * a certain region is, so that it can be unloaded when necessary. @@ -453,16 +452,16 @@ int InWorld::CheckBufferDistance(Region* const region) { int y = region->GetY() - camera.y; //if the region is visible, return -1 - if (x >= -mapPager.GetRegionWidth() * tileSheet.GetTileW() && x < camera.width && - y >= -mapPager.GetRegionHeight() * tileSheet.GetTileH() && y < camera.height) { + if (x >= -REGION_WIDTH * tileSheet.GetTileW() && x < camera.width && + y >= -REGION_HEIGHT * tileSheet.GetTileH() && y < camera.height) { return -1; } //prune the screen's area from the algorithm; get the pseudo-indexes - if (x < 0) x /= (mapPager.GetRegionWidth() * tileSheet.GetTileW()); - if (y < 0) y /= (mapPager.GetRegionHeight() * tileSheet.GetTileH()); - if (x > 0) x = (x - camera.width) / (mapPager.GetRegionWidth() * tileSheet.GetTileW()) + 1; - if (y > 0) y = (y - camera.height) / (mapPager.GetRegionHeight() * tileSheet.GetTileH()) + 1; + if (x < 0) x /= (REGION_WIDTH * tileSheet.GetTileW()); + if (y < 0) y /= (REGION_HEIGHT * tileSheet.GetTileH()); + if (x > 0) x = (x - camera.width) / (REGION_WIDTH * tileSheet.GetTileW()) + 1; + if (y > 0) y = (y - camera.height) / (REGION_HEIGHT * tileSheet.GetTileH()) + 1; //return the pseudo-index with the greatest magnitude return std::max(abs(x), abs(y)); @@ -471,28 +470,28 @@ int InWorld::CheckBufferDistance(Region* const region) { //TODO: eew ugly void InWorld::UpdateMap() { //prune distant regions - for (auto it = mapPager.GetContainer()->begin(); it != mapPager.GetContainer()->end(); /* EMPTY */) { + for (auto it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); /* EMPTY */) { if (CheckBufferDistance(*it) > 2) { //debugging cout << "unloading: " << (*it)->GetX() << ", " << (*it)->GetY() << endl; - mapPager.UnloadRegion((*it)->GetX(), (*it)->GetY()); + regionPager.UnloadRegion((*it)->GetX(), (*it)->GetY()); //reset - it = mapPager.GetContainer()->begin(); + it = regionPager.GetContainer()->begin(); continue; } ++it; } //TODO: make the region units official - int regionUnitX = mapPager.GetRegionWidth() * tileSheet.GetTileW(); - int regionUnitY = mapPager.GetRegionHeight() * tileSheet.GetTileH(); + int regionUnitX = REGION_WIDTH * tileSheet.GetTileW(); + int regionUnitY = REGION_HEIGHT * tileSheet.GetTileH(); //request empty regions, including buffers (-1 & +1 region unit) for (int i = snapToBase(regionUnitX, camera.x - regionUnitX); i <= snapToBase(regionUnitX, camera.x + camera.width + regionUnitX); i += regionUnitX) { for (int j = snapToBase(regionUnitY, camera.y - regionUnitY); j <= snapToBase(regionUnitY, camera.y + camera.height + regionUnitY); j += regionUnitY) { - if (!mapPager.FindRegion(i, j)) { + if (!regionPager.FindRegion(i, j)) { RequestRegion(i, j); } } diff --git a/client/scenes/in_world.hpp b/client/scenes/in_world.hpp index 278c007..62261bc 100644 --- a/client/scenes/in_world.hpp +++ b/client/scenes/in_world.hpp @@ -23,7 +23,7 @@ #define INWORLD_HPP_ //maps -#include "map_generator.hpp" +#include "map_allocator.hpp" #include "map_file_format.hpp" #include "region_pager.hpp" @@ -101,11 +101,12 @@ protected: TileSheet tileSheet; //map - RegionPager mapPager; + RegionPager regionPager; //UI Button disconnectButton; Button shutDownButton; + //TODO: Fix the camera struct { int x = 0, y = 0; int width = 0, height = 0; diff --git a/common/map/region_pager.hpp b/common/map/region_pager.hpp index 8414165..0bf035e 100644 --- a/common/map/region_pager.hpp +++ b/common/map/region_pager.hpp @@ -29,8 +29,8 @@ class RegionPagerBase { public: - RegionPagerBase() = default; - virtual ~RegionPagerBase() = default; + RegionPagerBase() {}; + virtual ~RegionPagerBase() {}; //tile manipulation Region::type_t SetTile(int x, int y, int z, Region::type_t v); @@ -54,10 +54,10 @@ protected: std::list regionList; }; -template +template class RegionPager : public RegionPagerBase { public: - RegionPager() = default; + RegionPager() {}; ~RegionPager() { UnloadAll(); } @@ -96,7 +96,7 @@ public: //create and push the object Region* ptr = nullptr; - generator.Create(&ptr, x, y); + allocator.Create(&ptr, x, y); return PushRegion(ptr); } @@ -108,7 +108,7 @@ public: //custom loop for (std::list::iterator it = regionList.begin(); it != regionList.end(); /* EMPTY */) { if ((*it)->GetX() == x && (*it)->GetY() == y) { - generator.Unload(*it); + allocator.Unload(*it); regionList.erase(it); //reset the loop, because of reasons @@ -120,17 +120,17 @@ public: } void UnloadAll() { for (auto& it : regionList) { - generator.Unload(it); + allocator.Unload(it); } regionList.clear(); } //accessors - MapGenerator* GetGenerator() { return &generator; } - MapFileFormat* GetFormat() { return &format; } + Allocator* GetAllocator() { return &allocator; } + FileFormat* GetFormat() { return &format; } protected: - MapGenerator generator; - MapFileFormat format; + Allocator allocator; + FileFormat format; }; #endif diff --git a/common/network/serial.cpp b/common/network/serial.cpp index 5130841..093c42d 100644 --- a/common/network/serial.cpp +++ b/common/network/serial.cpp @@ -167,6 +167,7 @@ void deserializeRegionContent(NetworkPacket* packet, char* buffer) { memcpy(&packet->regionInfo.x, buffer, sizeof(int)); buffer += sizeof(int); memcpy(&packet->regionInfo.y, buffer, sizeof(int)); + buffer += sizeof(int); //content BlankAllocator().Create( diff --git a/editor/editor_scene.cpp b/editor/editor_scene.cpp index af3a42c..c0d0d73 100644 --- a/editor/editor_scene.cpp +++ b/editor/editor_scene.cpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 2014 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -55,11 +55,6 @@ EditorScene::EditorScene(ConfigUtility* const arg1): {"Debug", "Debug On", "Debug Off", "Toggle", "Testificate"} }); - //setup the map - pager.SetRegionWidth(REGION_WIDTH); - pager.SetRegionHeight(REGION_HEIGHT); - pager.SetRegionDepth(REGION_DEPTH); - //debug tsheet.Load(config["dir.tilesets"] + "terrain.bmp", 12, 15); for (int i = 0; i < REGION_WIDTH; i++) { diff --git a/editor/editor_scene.hpp b/editor/editor_scene.hpp index ecfc291..0ba8734 100644 --- a/editor/editor_scene.hpp +++ b/editor/editor_scene.hpp @@ -1,4 +1,4 @@ -/* Copyright: (c) Kayne Ruse 2013 +/* Copyright: (c) Kayne Ruse 2013, 2014 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -30,7 +30,7 @@ #include "menu_bar.hpp" #include "region_pager.hpp" -#include "map_generator.hpp" +#include "map_allocator.hpp" #include "map_file_format.hpp" #include "tile_sheet.hpp" @@ -73,7 +73,7 @@ protected: int x = 0, y = 0; } camera; - RegionPager pager; + RegionPager pager; TileSheet tsheet; }; diff --git a/server/server_application.cpp b/server/server_application.cpp index b170355..56a9b24 100644 --- a/server/server_application.cpp +++ b/server/server_application.cpp @@ -98,10 +98,7 @@ void ServerApplication::Init(int argc, char** argv) { cout << "Initialized lua's setup script" << endl; //setup the map object - regionPager.SetRegionWidth(REGION_WIDTH); - regionPager.SetRegionHeight(REGION_HEIGHT); - regionPager.SetRegionDepth(REGION_DEPTH); - regionPager.GetGenerator()->SetLuaState(luaState); + regionPager.GetAllocator()->SetLuaState(luaState); regionPager.GetFormat()->SetLuaState(luaState); //TODO: config parameter regionPager.GetFormat()->SetSaveDir("save/mapname/"); diff --git a/server/server_application.hpp b/server/server_application.hpp index 6609994..8a10aa5 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -27,7 +27,7 @@ #include "player_entry.hpp" //maps -#include "map_generator.hpp" +#include "map_allocator.hpp" #include "map_file_format.hpp" #include "region_pager.hpp" @@ -88,7 +88,7 @@ private: //maps //TODO: I need to handle multiple map objects - RegionPager regionPager; + RegionPager regionPager; //misc bool running = true;