From 7e500027e338980144144399347c29b5762686ea Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 15 Mar 2014 19:15:58 +1100 Subject: [PATCH] Loosened the requirements for constructing a MapPager This is so that I can configure the size of the pages in the config.cfg file. --- common/map/region_pager.cpp | 4 ---- common/map/region_pager.hpp | 23 +++++++++++++---------- editor/editor_scene.cpp | 9 +++++++-- rsc/config.cfg | 5 +++++ server/server_application.cpp | 9 +++++++++ server/server_application.hpp | 16 ++++++++++++---- 6 files changed, 46 insertions(+), 20 deletions(-) diff --git a/common/map/region_pager.cpp b/common/map/region_pager.cpp index a251ee8..11baea9 100644 --- a/common/map/region_pager.cpp +++ b/common/map/region_pager.cpp @@ -62,7 +62,3 @@ Region* RegionPagerBase::GetRegion(int x, int y) { if (ptr) return ptr; return CreateRegion(x, y); } - -void RegionPagerBase::Update() { - //TODO -} diff --git a/common/map/region_pager.hpp b/common/map/region_pager.hpp index 30c6f64..9759a69 100644 --- a/common/map/region_pager.hpp +++ b/common/map/region_pager.hpp @@ -29,15 +29,13 @@ class RegionPagerBase { public: - RegionPagerBase() = delete; + RegionPagerBase() = default; RegionPagerBase(int regionWidth, int regionHeight, int regionDepth); virtual ~RegionPagerBase(); int SetTile(int x, int y, int z, int v); int GetTile(int x, int y, int z); - void Update(); - Region* GetRegion(int x, int y); //interface @@ -47,20 +45,25 @@ public: virtual void UnloadRegion(int x, int y) = 0; //accessors - int GetRegionWidth() { return regionWidth; } - int GetRegionHeight() { return regionHeight; } - int GetRegionDepth() { return regionDepth; } + //NOTE: don't change the sizes mid-program, it will cause issues + int SetRegionWidth(int i) { return regionWidth = i; } + int SetRegionHeight(int i) { return regionHeight = i; } + int SetRegionDepth(int i) { return regionDepth = i; } + + int GetRegionWidth() const { return regionWidth; } + int GetRegionHeight() const { return regionHeight; } + int GetRegionDepth() const { return regionDepth; } protected: - const int regionWidth; - const int regionHeight; - const int regionDepth; + int regionWidth; + int regionHeight; + int regionDepth; std::list regionList; }; template class RegionPager : public RegionPagerBase { public: - RegionPager() = delete; + RegionPager() = default; RegionPager(int w, int h, int d): RegionPagerBase(w, h, d) { diff --git a/editor/editor_scene.cpp b/editor/editor_scene.cpp index 07403bf..816c304 100644 --- a/editor/editor_scene.cpp +++ b/editor/editor_scene.cpp @@ -34,8 +34,7 @@ using namespace std; //------------------------- EditorScene::EditorScene(ConfigUtility* const arg1): - config(*arg1), - pager(20, 20, 3) + config(*arg1) { //create the debugging "window" debugInfo.CreateSurface(256, 256); @@ -56,6 +55,11 @@ EditorScene::EditorScene(ConfigUtility* const arg1): {"Debug", "Debug On", "Debug Off", "Toggle", "Testificate"} }); + //setup the map + pager.SetRegionWidth(config.Int("map.pager.width")); + pager.SetRegionHeight(config.Int("map.pager.height")); + pager.SetRegionDepth(config.Int("map.pager.depth")); + //debug tsheet.Load("rsc\\graphics\\tilesets\\sand.bmp", 12, 3); } @@ -85,6 +89,7 @@ void EditorScene::Render(SDL_Surface* const screen) { for (int i = 0; i < pager.GetRegionWidth()*2; i++) { for (int j = 0; j < pager.GetRegionHeight()*2; j++) { for (int k = 0; k < pager.GetRegionDepth(); k++) { + //TODO: skip the out-of-bounds regions tsheet.DrawTo( screen, i*tsheet.GetTileW()-camera.x, diff --git a/rsc/config.cfg b/rsc/config.cfg index 7790217..0b5fec0 100644 --- a/rsc/config.cfg +++ b/rsc/config.cfg @@ -17,6 +17,11 @@ dir.tilesets = rsc/graphics/tilesets/ dir.interface = rsc/graphics/interface/ dir.scripts = rsc/scripts/ +#map system +map.pager.width = 20 +map.pager.height = 20 +map.pager.depth = 3 + #player options player.handle = username player.avatar = elliot2.bmp diff --git a/server/server_application.cpp b/server/server_application.cpp index 56d1e4f..6c11873 100644 --- a/server/server_application.cpp +++ b/server/server_application.cpp @@ -96,6 +96,15 @@ void ServerApplication::Init(int argc, char** argv) { } cout << "Initialized lua's setup script" << endl; + //setup the map object + mapPager.SetRegionWidth(config.Int("map.pager.width")); + mapPager.SetRegionHeight(config.Int("map.pager.height")); + mapPager.SetRegionDepth(config.Int("map.pager.depth")); + //TODO: pass args to the generator & format as needed + //NOTE: I might need to rearrange the init process so that lua & SQL can interact + // with the map system as needed. + cout << "Initialized the map system" << endl; + //finalize the startup cout << "Startup completed successfully" << endl; } diff --git a/server/server_application.hpp b/server/server_application.hpp index c131958..3d43ca4 100644 --- a/server/server_application.hpp +++ b/server/server_application.hpp @@ -22,20 +22,25 @@ #ifndef SERVERAPPLICATION_HPP_ #define SERVERAPPLICATION_HPP_ +//maps +#include "map_generator.hpp" +#include "map_file_format.hpp" +#include "region_pager.hpp" + //networking #include "network_packet.hpp" #include "udp_network_utility.hpp" #include "serial.hpp" +//common +#include "config_utility.hpp" +#include "vector2.hpp" + //APIs #include "lua/lua.hpp" #include "sqlite3/sqlite3.h" #include "SDL/SDL.h" -//common -#include "config_utility.hpp" -#include "vector2.hpp" - //STL #include #include @@ -79,6 +84,9 @@ private: void PumpPacket(NetworkPacket); + //maps + RegionPager mapPager; + //networking UDPNetworkUtility network;