Loosened the requirements for constructing a MapPager

This is so that I can configure the size of the pages in the config.cfg
file.
This commit is contained in:
Kayne Ruse
2014-03-15 19:15:58 +11:00
parent dd786ba579
commit 7e500027e3
6 changed files with 46 additions and 20 deletions
-4
View File
@@ -62,7 +62,3 @@ Region* RegionPagerBase::GetRegion(int x, int y) {
if (ptr) return ptr; if (ptr) return ptr;
return CreateRegion(x, y); return CreateRegion(x, y);
} }
void RegionPagerBase::Update() {
//TODO
}
+13 -10
View File
@@ -29,15 +29,13 @@
class RegionPagerBase { class RegionPagerBase {
public: public:
RegionPagerBase() = delete; RegionPagerBase() = default;
RegionPagerBase(int regionWidth, int regionHeight, int regionDepth); RegionPagerBase(int regionWidth, int regionHeight, int regionDepth);
virtual ~RegionPagerBase(); virtual ~RegionPagerBase();
int SetTile(int x, int y, int z, int v); int SetTile(int x, int y, int z, int v);
int GetTile(int x, int y, int z); int GetTile(int x, int y, int z);
void Update();
Region* GetRegion(int x, int y); Region* GetRegion(int x, int y);
//interface //interface
@@ -47,20 +45,25 @@ public:
virtual void UnloadRegion(int x, int y) = 0; virtual void UnloadRegion(int x, int y) = 0;
//accessors //accessors
int GetRegionWidth() { return regionWidth; } //NOTE: don't change the sizes mid-program, it will cause issues
int GetRegionHeight() { return regionHeight; } int SetRegionWidth(int i) { return regionWidth = i; }
int GetRegionDepth() { return regionDepth; } 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: protected:
const int regionWidth; int regionWidth;
const int regionHeight; int regionHeight;
const int regionDepth; int regionDepth;
std::list<Region*> regionList; std::list<Region*> regionList;
}; };
template<typename MapGenerator, typename MapFileFormat> template<typename MapGenerator, typename MapFileFormat>
class RegionPager : public RegionPagerBase { class RegionPager : public RegionPagerBase {
public: public:
RegionPager() = delete; RegionPager() = default;
RegionPager(int w, int h, int d): RegionPager(int w, int h, int d):
RegionPagerBase(w, h, d) RegionPagerBase(w, h, d)
{ {
+7 -2
View File
@@ -34,8 +34,7 @@ using namespace std;
//------------------------- //-------------------------
EditorScene::EditorScene(ConfigUtility* const arg1): EditorScene::EditorScene(ConfigUtility* const arg1):
config(*arg1), config(*arg1)
pager(20, 20, 3)
{ {
//create the debugging "window" //create the debugging "window"
debugInfo.CreateSurface(256, 256); debugInfo.CreateSurface(256, 256);
@@ -56,6 +55,11 @@ EditorScene::EditorScene(ConfigUtility* const arg1):
{"Debug", "Debug On", "Debug Off", "Toggle", "Testificate"} {"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 //debug
tsheet.Load("rsc\\graphics\\tilesets\\sand.bmp", 12, 3); 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 i = 0; i < pager.GetRegionWidth()*2; i++) {
for (int j = 0; j < pager.GetRegionHeight()*2; j++) { for (int j = 0; j < pager.GetRegionHeight()*2; j++) {
for (int k = 0; k < pager.GetRegionDepth(); k++) { for (int k = 0; k < pager.GetRegionDepth(); k++) {
//TODO: skip the out-of-bounds regions
tsheet.DrawTo( tsheet.DrawTo(
screen, screen,
i*tsheet.GetTileW()-camera.x, i*tsheet.GetTileW()-camera.x,
+5
View File
@@ -17,6 +17,11 @@ dir.tilesets = rsc/graphics/tilesets/
dir.interface = rsc/graphics/interface/ dir.interface = rsc/graphics/interface/
dir.scripts = rsc/scripts/ dir.scripts = rsc/scripts/
#map system
map.pager.width = 20
map.pager.height = 20
map.pager.depth = 3
#player options #player options
player.handle = username player.handle = username
player.avatar = elliot2.bmp player.avatar = elliot2.bmp
+9
View File
@@ -96,6 +96,15 @@ void ServerApplication::Init(int argc, char** argv) {
} }
cout << "Initialized lua's setup script" << endl; 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 //finalize the startup
cout << "Startup completed successfully" << endl; cout << "Startup completed successfully" << endl;
} }
+12 -4
View File
@@ -22,20 +22,25 @@
#ifndef SERVERAPPLICATION_HPP_ #ifndef SERVERAPPLICATION_HPP_
#define SERVERAPPLICATION_HPP_ #define SERVERAPPLICATION_HPP_
//maps
#include "map_generator.hpp"
#include "map_file_format.hpp"
#include "region_pager.hpp"
//networking //networking
#include "network_packet.hpp" #include "network_packet.hpp"
#include "udp_network_utility.hpp" #include "udp_network_utility.hpp"
#include "serial.hpp" #include "serial.hpp"
//common
#include "config_utility.hpp"
#include "vector2.hpp"
//APIs //APIs
#include "lua/lua.hpp" #include "lua/lua.hpp"
#include "sqlite3/sqlite3.h" #include "sqlite3/sqlite3.h"
#include "SDL/SDL.h" #include "SDL/SDL.h"
//common
#include "config_utility.hpp"
#include "vector2.hpp"
//STL //STL
#include <map> #include <map>
#include <string> #include <string>
@@ -79,6 +84,9 @@ private:
void PumpPacket(NetworkPacket); void PumpPacket(NetworkPacket);
//maps
RegionPager<MapGenerator, MapFileFormat> mapPager;
//networking //networking
UDPNetworkUtility network; UDPNetworkUtility network;