Merge branch 'map' (read more)
After refactoring the map system, this new build uses the preprocessor macros to define the sizes of each region object. These macros, which are defined in region.hpp, were being used anyway; these modifications simply speed up the process by cutting out a lot of the fat.
This commit is contained in:
+23
-40
@@ -27,11 +27,6 @@
|
||||
#include <cmath>
|
||||
#include <stdexcept>
|
||||
|
||||
//debugging
|
||||
#include <iostream>
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
//-------------------------
|
||||
//Public access members
|
||||
//-------------------------
|
||||
@@ -63,14 +58,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 +135,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,20 +340,11 @@ 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)) {
|
||||
cout << "Success" << endl;
|
||||
}
|
||||
else {
|
||||
cout << "Failure" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------
|
||||
@@ -421,7 +405,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,45 +438,43 @@ 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));
|
||||
}
|
||||
|
||||
//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();
|
||||
//TODO: make the region units official?
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<BlankGenerator, DummyFormat> mapPager;
|
||||
RegionPager<BlankAllocator, DummyFormat> regionPager;
|
||||
|
||||
//UI
|
||||
Button disconnectButton;
|
||||
Button shutDownButton;
|
||||
//TODO: Fix the camera
|
||||
struct {
|
||||
int x = 0, y = 0;
|
||||
int width = 0, height = 0;
|
||||
|
||||
@@ -44,9 +44,9 @@ void TileSheet::DrawTo(SDL_Surface* const dest, int x, int y, Region::type_t til
|
||||
|
||||
void TileSheet::DrawRegionTo(SDL_Surface* const dest, Region* const region, int camX, int camY) {
|
||||
Region::type_t tile = 0;
|
||||
for (register int i = 0; i < region->GetWidth(); ++i) {
|
||||
for (register int j = 0; j < region->GetHeight(); ++j) {
|
||||
for (register int k = 0; k < region->GetDepth(); ++k) {
|
||||
for (register int i = 0; i < REGION_WIDTH; ++i) {
|
||||
for (register int j = 0; j < REGION_HEIGHT; ++j) {
|
||||
for (register int k = 0; k < REGION_DEPTH; ++k) {
|
||||
tile = region->GetTile(i, j, k);
|
||||
//0 is invisible
|
||||
if (tile == 0) continue;
|
||||
|
||||
@@ -19,29 +19,21 @@
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "map_generator.hpp"
|
||||
#include "map_allocator.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
void BlankGenerator::Create(Region** const ptr, int width, int height, int depth, int x, int y) {
|
||||
(*ptr) = new Region(width, height, depth, x, y);
|
||||
void BlankAllocator::Create(Region** const ptr, int x, int y) {
|
||||
(*ptr) = new Region(x, y);
|
||||
}
|
||||
|
||||
void BlankGenerator::Unload(Region* const ptr) {
|
||||
void BlankAllocator::Unload(Region* const ptr) {
|
||||
delete ptr;
|
||||
}
|
||||
/*
|
||||
void PerlinGenerator::Create(Region** const ptr, int width, int height, int depth, int x, int y) {
|
||||
(*ptr) = new Region(width, height, depth, x, y);
|
||||
}
|
||||
|
||||
void PerlinGenerator::Unload(Region* const ptr) {
|
||||
delete ptr;
|
||||
}
|
||||
*/
|
||||
void LuaGenerator::Create(Region** const ptr, int width, int height, int depth, int x, int y) {
|
||||
void LuaAllocator::Create(Region** const ptr, int x, int y) {
|
||||
//something to work on
|
||||
(*ptr) = new Region(width, height, depth, x, y);
|
||||
(*ptr) = new Region(x, y);
|
||||
|
||||
//API hook
|
||||
lua_getglobal(state, "Region");
|
||||
@@ -53,7 +45,7 @@ void LuaGenerator::Create(Region** const ptr, int width, int height, int depth,
|
||||
lua_pop(state, 1);
|
||||
}
|
||||
|
||||
void LuaGenerator::Unload(Region* const ptr) {
|
||||
void LuaAllocator::Unload(Region* const ptr) {
|
||||
//API hook
|
||||
lua_getglobal(state, "Region");
|
||||
lua_getfield(state, -1, "Unload");
|
||||
@@ -19,32 +19,24 @@
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#ifndef MAPGENERATOR_HPP_
|
||||
#define MAPGENERATOR_HPP_
|
||||
#ifndef MAPALLOCATOR_HPP_
|
||||
#define MAPALLOCATOR_HPP_
|
||||
|
||||
#include "region.hpp"
|
||||
|
||||
#include "lua/lua.hpp"
|
||||
|
||||
class BlankGenerator {
|
||||
class BlankAllocator {
|
||||
public:
|
||||
void Create(Region** const, int width, int height, int depth, int x, int y);
|
||||
void Create(Region** const, int x, int y);
|
||||
void Unload(Region* const);
|
||||
private:
|
||||
//
|
||||
};
|
||||
/*
|
||||
class PerlinGenerator {
|
||||
|
||||
class LuaAllocator {
|
||||
public:
|
||||
void Create(Region** const, int width, int height, int depth, int x, int y);
|
||||
void Unload(Region* const);
|
||||
private:
|
||||
//
|
||||
};
|
||||
*/
|
||||
class LuaGenerator {
|
||||
public:
|
||||
void Create(Region** const, int width, int height, int depth, int x, int y);
|
||||
void Create(Region** const, int x, int y);
|
||||
void Unload(Region* const);
|
||||
|
||||
lua_State* SetLuaState(lua_State* L) { return state = L; }
|
||||
@@ -23,33 +23,20 @@
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
void DummyFormat::Load(Region** const ptr, int width, int height, int depth, int x, int y) {
|
||||
void DummyFormat::Load(Region** const ptr, int x, int y) {
|
||||
//EMPTY
|
||||
}
|
||||
|
||||
void DummyFormat::Save(Region* const ptr) {
|
||||
//EMPTY
|
||||
}
|
||||
/*
|
||||
void VerboseFormat::Load(Region** const ptr, int x, int y) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
void VerboseFormat::Save(Region* const ptr) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
void CompactFormat::Load(Region** const ptr, int x, int y) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
void CompactFormat::Save(Region* const ptr) {
|
||||
//TODO
|
||||
}
|
||||
*/
|
||||
void LuaFormat::Load(Region** const ptr, int width, int height, int depth, int x, int y) {
|
||||
void LuaFormat::Load(Region** const ptr, int x, int y) {
|
||||
//something to load into
|
||||
(*ptr) = new Region(width, height, depth, x, y);
|
||||
|
||||
if (!(*ptr)) {
|
||||
(*ptr) = new Region(x, y);
|
||||
}
|
||||
|
||||
//API hook
|
||||
lua_getglobal(state, "Region");
|
||||
|
||||
@@ -30,18 +30,7 @@
|
||||
|
||||
class DummyFormat {
|
||||
public:
|
||||
void Load(Region** const, int width, int height, int depth, int x, int y);
|
||||
void Save(Region* const);
|
||||
|
||||
std::string SetSaveDir(std::string s) { return saveDir = s; }
|
||||
std::string GetSaveDir() { return saveDir; }
|
||||
private:
|
||||
std::string saveDir;
|
||||
};
|
||||
/*
|
||||
class VerboseFormat {
|
||||
public:
|
||||
void Load(Region** const, int width, int height, int depth, int x, int y);
|
||||
void Load(Region** const, int x, int y);
|
||||
void Save(Region* const);
|
||||
|
||||
std::string SetSaveDir(std::string s) { return saveDir = s; }
|
||||
@@ -50,20 +39,12 @@ private:
|
||||
std::string saveDir;
|
||||
};
|
||||
|
||||
class CompactFormat {
|
||||
public:
|
||||
void Load(Region** const, int width, int height, int depth, int x, int y);
|
||||
void Save(Region* const);
|
||||
//TODO: verbose save file format
|
||||
//TODO: compact save file format
|
||||
|
||||
std::string SetSaveDir(std::string s) { return saveDir = s; }
|
||||
std::string GetSaveDir() { return saveDir; }
|
||||
private:
|
||||
std::string saveDir;
|
||||
};
|
||||
*/
|
||||
class LuaFormat {
|
||||
public:
|
||||
void Load(Region** const, int width, int height, int depth, int x, int y);
|
||||
void Load(Region** const, int x, int y);
|
||||
void Save(Region* const);
|
||||
|
||||
std::string SetSaveDir(std::string s) { return saveDir = s; }
|
||||
|
||||
+3
-23
@@ -21,34 +21,14 @@
|
||||
*/
|
||||
#include "region.hpp"
|
||||
|
||||
Region::Region(int argWidth, int argHeight, int argDepth, int argX, int argY):
|
||||
width(argWidth),
|
||||
height(argHeight),
|
||||
depth(argDepth),
|
||||
Region::Region(int argX, int argY):
|
||||
x(argX),
|
||||
y(argY)
|
||||
{
|
||||
tiles = new type_t**[width];
|
||||
for (register int i = 0; i < width; ++i) {
|
||||
tiles[i] = new type_t*[height];
|
||||
for (register int j = 0; j < height; ++j) {
|
||||
tiles[i][j] = new type_t[depth];
|
||||
for (register int k = 0; k < depth; ++k) {
|
||||
tiles[i][j][k] = 0;
|
||||
for (register int i = 0; i < REGION_WIDTH*REGION_HEIGHT*REGION_DEPTH; ++i) {
|
||||
*(reinterpret_cast<type_t*>(tiles) + i) = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Region::~Region() {
|
||||
for (register int i = 0; i < width; ++i) {
|
||||
for (register int j = 0; j < height; j++) {
|
||||
delete tiles[i][j];
|
||||
}
|
||||
delete tiles[i];
|
||||
}
|
||||
delete tiles;
|
||||
}
|
||||
|
||||
Region::type_t Region::SetTile(int x, int y, int z, type_t v) {
|
||||
return tiles[x][y][z] = v;
|
||||
|
||||
+3
-10
@@ -22,7 +22,6 @@
|
||||
#ifndef REGION_HPP_
|
||||
#define REGION_HPP_
|
||||
|
||||
//temporary?
|
||||
#define REGION_WIDTH 20
|
||||
#define REGION_HEIGHT 20
|
||||
#define REGION_DEPTH 3
|
||||
@@ -32,26 +31,20 @@ public:
|
||||
typedef unsigned short type_t;
|
||||
|
||||
Region() = delete;
|
||||
Region(int width, int height, int depth, int x, int y);
|
||||
~Region();
|
||||
Region(int x, int y);
|
||||
~Region() = default;
|
||||
|
||||
type_t SetTile(int x, int y, int z, type_t v);
|
||||
type_t GetTile(int x, int y, int z);
|
||||
|
||||
//accessors
|
||||
int GetWidth() const { return width; }
|
||||
int GetHeight() const { return height; }
|
||||
int GetDepth() const { return depth; }
|
||||
int GetX() const { return x; }
|
||||
int GetY() const { return y; }
|
||||
private:
|
||||
const int width;
|
||||
const int height;
|
||||
const int depth;
|
||||
const int x;
|
||||
const int y;
|
||||
|
||||
type_t*** tiles = nullptr;
|
||||
type_t tiles[REGION_WIDTH][REGION_HEIGHT][REGION_DEPTH];
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -23,18 +23,6 @@
|
||||
|
||||
#include "utility.hpp"
|
||||
|
||||
RegionPagerBase::RegionPagerBase(int argWidth, int argHeight, int argDepth):
|
||||
regionWidth(argWidth),
|
||||
regionHeight(argHeight),
|
||||
regionDepth(argDepth)
|
||||
{
|
||||
//EMPTY
|
||||
}
|
||||
|
||||
RegionPagerBase::~RegionPagerBase() {
|
||||
//EMPTY
|
||||
}
|
||||
|
||||
Region::type_t RegionPagerBase::SetTile(int x, int y, int z, Region::type_t v) {
|
||||
Region* ptr = GetRegion(x, y);
|
||||
return ptr->SetTile(x - ptr->GetX(), y - ptr->GetY(), z, v);
|
||||
@@ -47,12 +35,10 @@ Region::type_t RegionPagerBase::GetTile(int x, int y, int z) {
|
||||
|
||||
Region* RegionPagerBase::GetRegion(int x, int y) {
|
||||
//snap the coords
|
||||
x = snapToBase(regionWidth, x);
|
||||
y = snapToBase(regionHeight, y);
|
||||
x = snapToBase(REGION_WIDTH, x);
|
||||
y = snapToBase(REGION_HEIGHT, y);
|
||||
|
||||
//get the region by various means
|
||||
|
||||
//TODO: revert this try/catch point
|
||||
Region* ptr = nullptr;
|
||||
ptr = FindRegion(x, y);
|
||||
if (ptr) return ptr;
|
||||
@@ -62,6 +48,10 @@ Region* RegionPagerBase::GetRegion(int x, int y) {
|
||||
}
|
||||
|
||||
Region* RegionPagerBase::FindRegion(int x, int y) {
|
||||
//snap the coords
|
||||
x = snapToBase(REGION_WIDTH, x);
|
||||
y = snapToBase(REGION_HEIGHT, y);
|
||||
|
||||
//find the region
|
||||
for (std::list<Region*>::iterator it = regionList.begin(); it != regionList.end(); it++) {
|
||||
if ((*it)->GetX() == x && (*it)->GetY() == y) {
|
||||
|
||||
+27
-48
@@ -29,9 +29,8 @@
|
||||
|
||||
class RegionPagerBase {
|
||||
public:
|
||||
RegionPagerBase() = default;
|
||||
RegionPagerBase(int regionWidth, int regionHeight, int regionDepth);
|
||||
virtual ~RegionPagerBase();
|
||||
RegionPagerBase() {};
|
||||
virtual ~RegionPagerBase() {};
|
||||
|
||||
//tile manipulation
|
||||
Region::type_t SetTile(int x, int y, int z, Region::type_t v);
|
||||
@@ -50,86 +49,66 @@ public:
|
||||
//TODO: delete?
|
||||
|
||||
//accessors & mutators
|
||||
//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; }
|
||||
|
||||
std::list<Region*>* GetContainer() { return ®ionList; }
|
||||
protected:
|
||||
int regionWidth;
|
||||
int regionHeight;
|
||||
int regionDepth;
|
||||
std::list<Region*> regionList;
|
||||
};
|
||||
|
||||
template<typename MapGenerator, typename MapFileFormat>
|
||||
template<typename Allocator, typename FileFormat>
|
||||
class RegionPager : public RegionPagerBase {
|
||||
public:
|
||||
RegionPager() = default;
|
||||
RegionPager(int w, int h, int d):
|
||||
RegionPagerBase(w, h, d)
|
||||
{
|
||||
//EMPTY
|
||||
}
|
||||
RegionPager() {};
|
||||
~RegionPager() {
|
||||
UnloadAll();
|
||||
}
|
||||
|
||||
Region* LoadRegion(int x, int y) {
|
||||
//snap the coords
|
||||
x = snapToBase(regionWidth, x);
|
||||
y = snapToBase(regionHeight, y);
|
||||
x = snapToBase(REGION_WIDTH, x);
|
||||
y = snapToBase(REGION_HEIGHT, y);
|
||||
|
||||
//load the region if possible
|
||||
Region* ptr = nullptr;
|
||||
format.Load(&ptr, regionWidth, regionHeight, regionDepth, x, y);
|
||||
format.Load(&ptr, x, y);
|
||||
if (ptr) {
|
||||
regionList.push_back(ptr);
|
||||
return ptr;
|
||||
return PushRegion(ptr);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Region* SaveRegion(int x, int y) {
|
||||
//snap the coords
|
||||
x = snapToBase(regionWidth, x);
|
||||
y = snapToBase(regionHeight, y);
|
||||
x = snapToBase(REGION_WIDTH, x);
|
||||
y = snapToBase(REGION_HEIGHT, y);
|
||||
|
||||
//find & save the region
|
||||
for (std::list<Region*>::iterator it = regionList.begin(); it != regionList.end(); it++) {
|
||||
if ((*it)->GetX() == x && (*it)->GetY() == y) {
|
||||
format.Save(*it);
|
||||
return *it;
|
||||
Region* ptr = FindRegion(x, y);
|
||||
if (ptr) {
|
||||
format.Save(ptr);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
Region* CreateRegion(int x, int y) {
|
||||
//snap the coords
|
||||
x = snapToBase(regionWidth, x);
|
||||
y = snapToBase(regionHeight, y);
|
||||
x = snapToBase(REGION_WIDTH, x);
|
||||
y = snapToBase(REGION_HEIGHT, y);
|
||||
|
||||
//create and push the object
|
||||
Region* ptr = nullptr;
|
||||
generator.Create(&ptr, regionWidth, regionHeight, regionDepth, x, y);
|
||||
regionList.push_back(ptr);
|
||||
return ptr;
|
||||
allocator.Create(&ptr, x, y);
|
||||
return PushRegion(ptr);
|
||||
}
|
||||
|
||||
void UnloadRegion(int x, int y) {
|
||||
//snap the coords
|
||||
x = snapToBase(regionWidth, x);
|
||||
y = snapToBase(regionHeight, y);
|
||||
x = snapToBase(REGION_WIDTH, x);
|
||||
y = snapToBase(REGION_HEIGHT, y);
|
||||
|
||||
//custom loop
|
||||
for (std::list<Region*>::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
|
||||
@@ -141,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
|
||||
|
||||
@@ -107,7 +107,7 @@ union NetworkPacket {
|
||||
//map data
|
||||
struct RegionInformation {
|
||||
Metadata meta;
|
||||
int width, height, depth, x, y;
|
||||
int x, y;
|
||||
Region* region;
|
||||
}regionInfo;
|
||||
|
||||
|
||||
+16
-38
@@ -21,7 +21,7 @@
|
||||
*/
|
||||
#include "serial.hpp"
|
||||
|
||||
#include "map_generator.hpp"
|
||||
#include "map_allocator.hpp"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
@@ -75,14 +75,6 @@ void serializeRegionFormat(NetworkPacket* packet, char* buffer) {
|
||||
memcpy(buffer, &packet->meta.type, sizeof(NetworkPacket::Type));
|
||||
buffer += sizeof(NetworkPacket::Type);
|
||||
|
||||
//size
|
||||
memcpy(buffer, &packet->regionInfo.width, sizeof(int));
|
||||
buffer += sizeof(int);
|
||||
memcpy(buffer, &packet->regionInfo.height, sizeof(int));
|
||||
buffer += sizeof(int);
|
||||
memcpy(buffer, &packet->regionInfo.depth, sizeof(int));
|
||||
buffer += sizeof(int);
|
||||
|
||||
//x & y
|
||||
memcpy(buffer, &packet->regionInfo.x, sizeof(int));
|
||||
buffer += sizeof(int);
|
||||
@@ -94,14 +86,6 @@ void serializeRegionContent(NetworkPacket* packet, char* buffer) {
|
||||
memcpy(buffer, &packet->meta.type, sizeof(NetworkPacket::Type));
|
||||
buffer += sizeof(NetworkPacket::Type);
|
||||
|
||||
//size
|
||||
*reinterpret_cast<int*>(buffer) = packet->regionInfo.region->GetWidth();
|
||||
buffer += sizeof(int);
|
||||
*reinterpret_cast<int*>(buffer) = packet->regionInfo.region->GetHeight();
|
||||
buffer += sizeof(int);
|
||||
*reinterpret_cast<int*>(buffer) = packet->regionInfo.region->GetDepth();
|
||||
buffer += sizeof(int);
|
||||
|
||||
//x & y
|
||||
*reinterpret_cast<int*>(buffer) = packet->regionInfo.region->GetX();
|
||||
buffer += sizeof(int);
|
||||
@@ -109,9 +93,9 @@ void serializeRegionContent(NetworkPacket* packet, char* buffer) {
|
||||
buffer += sizeof(int);
|
||||
|
||||
//content
|
||||
for (register int i = 0; i < packet->regionInfo.region->GetWidth(); i++) {
|
||||
for (register int j = 0; j < packet->regionInfo.region->GetHeight(); j++) {
|
||||
for (register int k = 0; k < packet->regionInfo.region->GetDepth(); k++) {
|
||||
for (register int i = 0; i < REGION_WIDTH; i++) {
|
||||
for (register int j = 0; j < REGION_HEIGHT; j++) {
|
||||
for (register int k = 0; k < REGION_DEPTH; k++) {
|
||||
*reinterpret_cast<Region::type_t*>(buffer) = packet->regionInfo.region->GetTile(i, j, k);
|
||||
buffer += sizeof(Region::type_t);
|
||||
}
|
||||
@@ -169,14 +153,6 @@ void deserializeRegionFormat(NetworkPacket* packet, char* buffer) {
|
||||
memcpy(&packet->meta.type, buffer, sizeof(NetworkPacket::Type));
|
||||
buffer += sizeof(NetworkPacket::Type);
|
||||
|
||||
//size
|
||||
memcpy(&packet->regionInfo.width, buffer, sizeof(int));
|
||||
buffer += sizeof(int);
|
||||
memcpy(&packet->regionInfo.height, buffer, sizeof(int));
|
||||
buffer += sizeof(int);
|
||||
memcpy(&packet->regionInfo.depth, buffer, sizeof(int));
|
||||
buffer += sizeof(int);
|
||||
|
||||
//x & y
|
||||
memcpy(&packet->regionInfo.x, buffer, sizeof(int));
|
||||
buffer += sizeof(int);
|
||||
@@ -184,23 +160,25 @@ void deserializeRegionFormat(NetworkPacket* packet, char* buffer) {
|
||||
}
|
||||
|
||||
void deserializeRegionContent(NetworkPacket* packet, char* buffer) {
|
||||
//format
|
||||
deserializeRegionFormat(packet, buffer);
|
||||
buffer += sizeof(int) * 5 + sizeof(NetworkPacket::Type);
|
||||
memcpy(&packet->meta.type, buffer, sizeof(NetworkPacket::Type));
|
||||
buffer += sizeof(NetworkPacket::Type);
|
||||
|
||||
//x & y
|
||||
memcpy(&packet->regionInfo.x, buffer, sizeof(int));
|
||||
buffer += sizeof(int);
|
||||
memcpy(&packet->regionInfo.y, buffer, sizeof(int));
|
||||
buffer += sizeof(int);
|
||||
|
||||
//content
|
||||
BlankGenerator().Create(
|
||||
BlankAllocator().Create(
|
||||
&packet->regionInfo.region,
|
||||
packet->regionInfo.width,
|
||||
packet->regionInfo.height,
|
||||
packet->regionInfo.depth,
|
||||
packet->regionInfo.x,
|
||||
packet->regionInfo.y
|
||||
);
|
||||
|
||||
for (register int i = 0; i < packet->regionInfo.region->GetWidth(); i++) {
|
||||
for (register int j = 0; j < packet->regionInfo.region->GetHeight(); j++) {
|
||||
for (register int k = 0; k < packet->regionInfo.region->GetDepth(); k++) {
|
||||
for (register int i = 0; i < REGION_WIDTH; i++) {
|
||||
for (register int j = 0; j < REGION_HEIGHT; j++) {
|
||||
for (register int k = 0; k < REGION_DEPTH; k++) {
|
||||
packet->regionInfo.region->SetTile(i, j, k, *reinterpret_cast<Region::type_t*>(buffer));
|
||||
buffer += sizeof(Region::type_t);
|
||||
}
|
||||
|
||||
@@ -24,12 +24,13 @@
|
||||
|
||||
#include "network_packet.hpp"
|
||||
|
||||
/* Sending regions are the largest type of packet
|
||||
* content: width * height * depth * sizoeof(type)
|
||||
* map format: sizeof(int) * 5
|
||||
/* TODO: Keep the PACKET_BUFFER_SIZE up to date
|
||||
* NOTE: REGION_CONTENT is currently the largest type of packet
|
||||
* map content: REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizoeof(region::type_t)
|
||||
* map format: sizeof(int) * 2
|
||||
* metadata: sizeof(metadata)
|
||||
*/
|
||||
#define PACKET_BUFFER_SIZE REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t) + sizeof(int) * 5 + sizeof(NetworkPacket::Metadata)
|
||||
#define PACKET_BUFFER_SIZE REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t) + sizeof(int) * 2 + sizeof(NetworkPacket::Metadata)
|
||||
|
||||
void serialize(NetworkPacket* const, void*);
|
||||
void deserialize(NetworkPacket* const, void*);
|
||||
|
||||
@@ -37,20 +37,17 @@ static int getTile(lua_State* L) {
|
||||
}
|
||||
|
||||
static int getWidth(lua_State* L) {
|
||||
Region* ptr = (Region*)lua_touserdata(L, 1);
|
||||
lua_pushinteger(L, ptr->GetWidth());
|
||||
lua_pushinteger(L, REGION_WIDTH);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int getHeight(lua_State* L) {
|
||||
Region* ptr = (Region*)lua_touserdata(L, 1);
|
||||
lua_pushinteger(L, ptr->GetHeight());
|
||||
lua_pushinteger(L, REGION_HEIGHT);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int getDepth(lua_State* L) {
|
||||
Region* ptr = (Region*)lua_touserdata(L, 1);
|
||||
lua_pushinteger(L, ptr->GetDepth());
|
||||
lua_pushinteger(L, REGION_DEPTH);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
@@ -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<BlankGenerator, DummyFormat> pager;
|
||||
RegionPager<BlankAllocator, DummyFormat> pager;
|
||||
TileSheet tsheet;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
print("Lua script check OK (./rsc)")
|
||||
|
||||
function Region.Create(r)
|
||||
print("Region:Create(r", Region.GetX(r), Region.GetY(r), ")")
|
||||
-- print("Region:Create(r", Region.GetX(r), Region.GetY(r), ")")
|
||||
for i = 1, Region.GetWidth(r) do
|
||||
for j = 1, Region.GetHeight(r) do
|
||||
if math.abs(i) == math.abs(j) then
|
||||
@@ -11,19 +11,19 @@ function Region.Create(r)
|
||||
end
|
||||
end
|
||||
end
|
||||
print("done")
|
||||
-- print("done")
|
||||
end
|
||||
|
||||
function Region.Unload(r)
|
||||
print("Region:Unload(r", Region.GetX(r), Region.GetY(r), ")")
|
||||
-- print("Region:Unload(r", Region.GetX(r), Region.GetY(r), ")")
|
||||
end
|
||||
|
||||
--return true if file loaded, otherwise return false
|
||||
function Region.Load(r, saveDir)
|
||||
print("Region:Load(r,", saveDir, Region.GetX(r), Region.GetY(r), ")")
|
||||
-- print("Region:Load(r,", saveDir, Region.GetX(r), Region.GetY(r), ")")
|
||||
return false
|
||||
end
|
||||
|
||||
function Region.Save(r, saveDir)
|
||||
print("Region:Save(r,", saveDir, Region.GetX(r), Region.GetY(r), ")")
|
||||
-- print("Region:Save(r,", saveDir, Region.GetX(r), Region.GetY(r), ")")
|
||||
end
|
||||
|
||||
@@ -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
|
||||
@@ -26,31 +26,14 @@
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int runSQLScript(sqlite3* db, std::string fname) {
|
||||
ifstream is(fname);
|
||||
if (!is.is_open()) {
|
||||
return -1;
|
||||
}
|
||||
string script;
|
||||
getline(is, script, '\0');
|
||||
is.close();
|
||||
//TODO: flesh out this error if needed
|
||||
if (sqlite3_exec(db, script.c_str(), nullptr, nullptr, nullptr) != SQLITE_OK) {
|
||||
return -2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-------------------------
|
||||
//Define the public members
|
||||
//-------------------------
|
||||
|
||||
void ServerApplication::Init(int argc, char** argv) {
|
||||
cout << "Beginning startup" << endl;
|
||||
//NOTE: I might need to rearrange the init process so that lua & SQL can interact with the map system as needed.
|
||||
std::cout << "Beginning startup" << std::endl;
|
||||
|
||||
//initial setup
|
||||
ClientEntry::uidCounter = 0;
|
||||
@@ -59,61 +42,56 @@ void ServerApplication::Init(int argc, char** argv) {
|
||||
|
||||
//Init SDL
|
||||
if (SDL_Init(0)) {
|
||||
throw(runtime_error("Failed to initialize SDL"));
|
||||
throw(std::runtime_error("Failed to initialize SDL"));
|
||||
}
|
||||
cout << "Initialized SDL" << endl;
|
||||
std::cout << "Initialized SDL" << std::endl;
|
||||
|
||||
//Init SDL_net
|
||||
if (SDLNet_Init()) {
|
||||
throw(runtime_error("Failed to initialize SDL_net"));
|
||||
throw(std::runtime_error("Failed to initialize SDL_net"));
|
||||
}
|
||||
network.Open(config.Int("server.port"), PACKET_BUFFER_SIZE);
|
||||
cout << "Initialized SDL_net" << endl;
|
||||
std::cout << "Initialized SDL_net" << std::endl;
|
||||
|
||||
//Init SQL
|
||||
int ret = sqlite3_open_v2(config["server.dbname"].c_str(), &database, SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, nullptr);
|
||||
if (ret != SQLITE_OK || !database) {
|
||||
throw(runtime_error(string() + "Failed to initialize SQL: " + sqlite3_errmsg(database) ));
|
||||
throw(std::runtime_error(std::string() + "Failed to initialize SQL: " + sqlite3_errmsg(database) ));
|
||||
}
|
||||
cout << "Initialized SQL" << endl;
|
||||
std::cout << "Initialized SQL" << std::endl;
|
||||
|
||||
//setup the database
|
||||
if (runSQLScript(database, config["dir.scripts"] + "setup_server.sql")) {
|
||||
throw(runtime_error("Failed to initialize SQL's setup script"));
|
||||
throw(std::runtime_error("Failed to initialize SQL's setup script"));
|
||||
}
|
||||
cout << "Initialized SQL's setup script" << endl;
|
||||
std::cout << "Initialized SQL's setup script" << std::endl;
|
||||
|
||||
//lua
|
||||
luaState = luaL_newstate();
|
||||
if (!luaState) {
|
||||
throw(runtime_error("Failed to initialize lua"));
|
||||
throw(std::runtime_error("Failed to initialize lua"));
|
||||
}
|
||||
luaL_openlibs(luaState);
|
||||
cout << "Initialized lua" << endl;
|
||||
std::cout << "Initialized lua" << std::endl;
|
||||
|
||||
//run the startup script
|
||||
if (luaL_dofile(luaState, (config["dir.scripts"] + "setup_server.lua").c_str())) {
|
||||
throw(runtime_error(string() + "Failed to initialize lua's setup script: " + lua_tostring(luaState, -1) ));
|
||||
throw(std::runtime_error(std::string() + "Failed to initialize lua's setup script: " + lua_tostring(luaState, -1) ));
|
||||
}
|
||||
cout << "Initialized lua's setup script" << endl;
|
||||
std::cout << "Initialized lua's setup script" << std::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/");
|
||||
//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;
|
||||
cout << "\tsizeof(NetworkPacket): " << sizeof(NetworkPacket) << endl;
|
||||
cout << "\tPACKET_BUFFER_SIZE: " << PACKET_BUFFER_SIZE << endl;
|
||||
|
||||
std::cout << "Initialized the map system" << std::endl;
|
||||
std::cout << "\tsizeof(NetworkPacket): " << sizeof(NetworkPacket) << std::endl;
|
||||
std::cout << "\tPACKET_BUFFER_SIZE: " << PACKET_BUFFER_SIZE << std::endl;
|
||||
|
||||
//finalize the startup
|
||||
cout << "Startup completed successfully" << endl;
|
||||
std::cout << "Startup completed successfully" << std::endl;
|
||||
|
||||
//debugging
|
||||
//
|
||||
@@ -138,7 +116,7 @@ void ServerApplication::Loop() {
|
||||
}
|
||||
|
||||
void ServerApplication::Quit() {
|
||||
cout << "Shutting down" << endl;
|
||||
std::cout << "Shutting down" << std::endl;
|
||||
//empty the members
|
||||
regionPager.UnloadAll();
|
||||
|
||||
@@ -148,7 +126,7 @@ void ServerApplication::Quit() {
|
||||
network.Close();
|
||||
SDLNet_Quit();
|
||||
SDL_Quit();
|
||||
cout << "Shutdown finished" << endl;
|
||||
std::cout << "Shutdown finished" << std::endl;
|
||||
}
|
||||
|
||||
//-------------------------
|
||||
@@ -186,7 +164,7 @@ void ServerApplication::HandlePacket(NetworkPacket packet) {
|
||||
break;
|
||||
//handle errors
|
||||
default:
|
||||
throw(runtime_error("Unknown NetworkPacket::Type encountered"));
|
||||
throw(std::runtime_error("Unknown NetworkPacket::Type encountered"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -201,6 +179,7 @@ void ServerApplication::HandleBroadcastRequest(NetworkPacket packet) {
|
||||
//TODO: version info
|
||||
snprintf(packet.serverInfo.name, PACKET_STRING_SIZE, "%s", config["server.name"].c_str());
|
||||
//TODO: player count
|
||||
//TODO: map format
|
||||
char buffer[PACKET_BUFFER_SIZE];
|
||||
serialize(&packet, buffer);
|
||||
network.Send(&packet.meta.srcAddress, buffer, PACKET_BUFFER_SIZE);
|
||||
@@ -223,7 +202,7 @@ void ServerApplication::HandleJoinRequest(NetworkPacket packet) {
|
||||
|
||||
//finished this routine
|
||||
ClientEntry::uidCounter++;
|
||||
cout << "Connect, total: " << clientMap.size() << endl;
|
||||
std::cout << "Connect, total: " << clientMap.size() << std::endl;
|
||||
}
|
||||
|
||||
void ServerApplication::HandleDisconnect(NetworkPacket packet) {
|
||||
@@ -257,7 +236,7 @@ void ServerApplication::HandleDisconnect(NetworkPacket packet) {
|
||||
});
|
||||
|
||||
//finished this routine
|
||||
cout << "Disconnect, total: " << clientMap.size() << endl;
|
||||
std::cout << "Disconnect, total: " << clientMap.size() << std::endl;
|
||||
}
|
||||
|
||||
void ServerApplication::HandleSynchronize(NetworkPacket packet) {
|
||||
@@ -292,7 +271,7 @@ void ServerApplication::HandleShutdown(NetworkPacket packet) {
|
||||
PumpPacket(packet);
|
||||
|
||||
//finished this routine
|
||||
cout << "Shutdown signal accepted" << endl;
|
||||
std::cout << "Shutdown signal accepted" << std::endl;
|
||||
}
|
||||
|
||||
void ServerApplication::HandlePlayerNew(NetworkPacket packet) {
|
||||
@@ -331,6 +310,7 @@ void ServerApplication::HandlePlayerNew(NetworkPacket packet) {
|
||||
|
||||
void ServerApplication::HandlePlayerDelete(NetworkPacket packet) {
|
||||
//TODO: remove this?
|
||||
//TODO: authenticate who is deleting this player
|
||||
if (playerMap.find(packet.playerInfo.playerIndex) == playerMap.end()) {
|
||||
throw(std::runtime_error("Cannot delete a non-existant player"));
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -23,11 +23,12 @@
|
||||
#define SERVERAPPLICATION_HPP_
|
||||
|
||||
//server specific stuff
|
||||
#include "server_utility.hpp"
|
||||
#include "client_entry.hpp"
|
||||
#include "player_entry.hpp"
|
||||
|
||||
//maps
|
||||
#include "map_generator.hpp"
|
||||
#include "map_allocator.hpp"
|
||||
#include "map_file_format.hpp"
|
||||
#include "region_pager.hpp"
|
||||
|
||||
@@ -47,7 +48,6 @@
|
||||
|
||||
//STL
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
//The main application class
|
||||
class ServerApplication {
|
||||
@@ -88,7 +88,7 @@ private:
|
||||
|
||||
//maps
|
||||
//TODO: I need to handle multiple map objects
|
||||
RegionPager<LuaGenerator, LuaFormat> regionPager;
|
||||
RegionPager<LuaAllocator, LuaFormat> regionPager;
|
||||
|
||||
//misc
|
||||
bool running = true;
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/* Copyright: (c) Kayne Ruse 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
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#include "server_utility.hpp"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
|
||||
int runSQLScript(sqlite3* db, std::string fname) {
|
||||
std::ifstream is(fname);
|
||||
if (!is.is_open()) {
|
||||
return -1;
|
||||
}
|
||||
std::string script;
|
||||
getline(is, script, '\0');
|
||||
is.close();
|
||||
//NOTE: flesh out this error if needed
|
||||
if (sqlite3_exec(db, script.c_str(), nullptr, nullptr, nullptr) != SQLITE_OK) {
|
||||
return -2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/* Copyright: (c) Kayne Ruse 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
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
*/
|
||||
#ifndef SERVERUTILITY_HPP_
|
||||
#define SERVERUTILITY_HPP_
|
||||
|
||||
#include "sqlite3/sqlite3.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
int runSQLScript(sqlite3* db, std::string fname);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user