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:
Kayne Ruse
2014-04-20 05:39:28 +10:00
22 changed files with 230 additions and 330 deletions
+23 -40
View File
@@ -27,11 +27,6 @@
#include <cmath> #include <cmath>
#include <stdexcept> #include <stdexcept>
//debugging
#include <iostream>
using std::cout;
using std::endl;
//------------------------- //-------------------------
//Public access members //Public access members
//------------------------- //-------------------------
@@ -63,14 +58,11 @@ InWorld::InWorld(ConfigUtility* const argConfig, UDPNetworkUtility* const argNet
shutDownButton.SetText("Shut Down"); shutDownButton.SetText("Shut Down");
//load the tilesheet //load the tilesheet
//TODO: add the tilesheet to the map system?
tileSheet.Load(config["dir.tilesets"] + "terrain.bmp", 12, 15); 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 //create the server-side player object
//TODO: the login system needs an overhaul
NetworkPacket packet; NetworkPacket packet;
packet.meta.type = NetworkPacket::Type::PLAYER_NEW; packet.meta.type = NetworkPacket::Type::PLAYER_NEW;
packet.playerInfo.clientIndex = clientIndex; packet.playerInfo.clientIndex = clientIndex;
@@ -143,7 +135,8 @@ void InWorld::RenderFrame() {
void InWorld::Render(SDL_Surface* const screen) { void InWorld::Render(SDL_Surface* const screen) {
//draw the map //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); tileSheet.DrawRegionTo(screen, *it, camera.x, camera.y);
} }
@@ -347,20 +340,11 @@ void InWorld::HandlePlayerUpdate(NetworkPacket packet) {
void InWorld::HandleRegionContent(NetworkPacket packet) { void InWorld::HandleRegionContent(NetworkPacket packet) {
//replace existing regions //replace existing regions
if (mapPager.FindRegion(packet.regionInfo.x, packet.regionInfo.y)) { if (regionPager.FindRegion(packet.regionInfo.x, packet.regionInfo.y)) {
mapPager.UnloadRegion(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; 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) { 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 * 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 * 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. * 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; int y = region->GetY() - camera.y;
//if the region is visible, return -1 //if the region is visible, return -1
if (x >= -mapPager.GetRegionWidth() * tileSheet.GetTileW() && x < camera.width && if (x >= -REGION_WIDTH * tileSheet.GetTileW() && x < camera.width &&
y >= -mapPager.GetRegionHeight() * tileSheet.GetTileH() && y < camera.height) { y >= -REGION_HEIGHT * tileSheet.GetTileH() && y < camera.height) {
return -1; return -1;
} }
//prune the screen's area from the algorithm; get the pseudo-indexes //prune the screen's area from the algorithm; get the pseudo-indexes
if (x < 0) x /= (mapPager.GetRegionWidth() * tileSheet.GetTileW()); if (x < 0) x /= (REGION_WIDTH * tileSheet.GetTileW());
if (y < 0) y /= (mapPager.GetRegionHeight() * tileSheet.GetTileH()); if (y < 0) y /= (REGION_HEIGHT * tileSheet.GetTileH());
if (x > 0) x = (x - camera.width) / (mapPager.GetRegionWidth() * tileSheet.GetTileW()) + 1; if (x > 0) x = (x - camera.width) / (REGION_WIDTH * tileSheet.GetTileW()) + 1;
if (y > 0) y = (y - camera.height) / (mapPager.GetRegionHeight() * tileSheet.GetTileH()) + 1; if (y > 0) y = (y - camera.height) / (REGION_HEIGHT * tileSheet.GetTileH()) + 1;
//return the pseudo-index with the greatest magnitude //return the pseudo-index with the greatest magnitude
return std::max(abs(x), abs(y)); return std::max(abs(x), abs(y));
} }
//TODO: eew ugly
void InWorld::UpdateMap() { void InWorld::UpdateMap() {
//prune distant regions //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) { if (CheckBufferDistance(*it) > 2) {
//debugging regionPager.UnloadRegion((*it)->GetX(), (*it)->GetY());
cout << "unloading: " << (*it)->GetX() << ", " << (*it)->GetY() << endl;
mapPager.UnloadRegion((*it)->GetX(), (*it)->GetY());
//reset //reset
it = mapPager.GetContainer()->begin(); it = regionPager.GetContainer()->begin();
continue; continue;
} }
++it; ++it;
} }
//TODO: make the region units official //TODO: make the region units official?
int regionUnitX = mapPager.GetRegionWidth() * tileSheet.GetTileW(); int regionUnitX = REGION_WIDTH * tileSheet.GetTileW();
int regionUnitY = mapPager.GetRegionHeight() * tileSheet.GetTileH(); int regionUnitY = REGION_HEIGHT * tileSheet.GetTileH();
//request empty regions, including buffers (-1 & +1 region unit) //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 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) { 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); RequestRegion(i, j);
} }
} }
+3 -2
View File
@@ -23,7 +23,7 @@
#define INWORLD_HPP_ #define INWORLD_HPP_
//maps //maps
#include "map_generator.hpp" #include "map_allocator.hpp"
#include "map_file_format.hpp" #include "map_file_format.hpp"
#include "region_pager.hpp" #include "region_pager.hpp"
@@ -101,11 +101,12 @@ protected:
TileSheet tileSheet; TileSheet tileSheet;
//map //map
RegionPager<BlankGenerator, DummyFormat> mapPager; RegionPager<BlankAllocator, DummyFormat> regionPager;
//UI //UI
Button disconnectButton; Button disconnectButton;
Button shutDownButton; Button shutDownButton;
//TODO: Fix the camera
struct { struct {
int x = 0, y = 0; int x = 0, y = 0;
int width = 0, height = 0; int width = 0, height = 0;
+3 -3
View File
@@ -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) { void TileSheet::DrawRegionTo(SDL_Surface* const dest, Region* const region, int camX, int camY) {
Region::type_t tile = 0; Region::type_t tile = 0;
for (register int i = 0; i < region->GetWidth(); ++i) { for (register int i = 0; i < REGION_WIDTH; ++i) {
for (register int j = 0; j < region->GetHeight(); ++j) { for (register int j = 0; j < REGION_HEIGHT; ++j) {
for (register int k = 0; k < region->GetDepth(); ++k) { for (register int k = 0; k < REGION_DEPTH; ++k) {
tile = region->GetTile(i, j, k); tile = region->GetTile(i, j, k);
//0 is invisible //0 is invisible
if (tile == 0) continue; if (tile == 0) continue;
@@ -19,29 +19,21 @@
* 3. This notice may not be removed or altered from any source * 3. This notice may not be removed or altered from any source
* distribution. * distribution.
*/ */
#include "map_generator.hpp" #include "map_allocator.hpp"
#include <stdexcept> #include <stdexcept>
void BlankGenerator::Create(Region** const ptr, int width, int height, int depth, int x, int y) { void BlankAllocator::Create(Region** const ptr, int x, int y) {
(*ptr) = new Region(width, height, depth, x, y); (*ptr) = new Region(x, y);
} }
void BlankGenerator::Unload(Region* const ptr) { void BlankAllocator::Unload(Region* const ptr) {
delete 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) { void LuaAllocator::Create(Region** const ptr, int x, int y) {
delete ptr;
}
*/
void LuaGenerator::Create(Region** const ptr, int width, int height, int depth, int x, int y) {
//something to work on //something to work on
(*ptr) = new Region(width, height, depth, x, y); (*ptr) = new Region(x, y);
//API hook //API hook
lua_getglobal(state, "Region"); lua_getglobal(state, "Region");
@@ -53,7 +45,7 @@ void LuaGenerator::Create(Region** const ptr, int width, int height, int depth,
lua_pop(state, 1); lua_pop(state, 1);
} }
void LuaGenerator::Unload(Region* const ptr) { void LuaAllocator::Unload(Region* const ptr) {
//API hook //API hook
lua_getglobal(state, "Region"); lua_getglobal(state, "Region");
lua_getfield(state, -1, "Unload"); lua_getfield(state, -1, "Unload");
@@ -19,32 +19,24 @@
* 3. This notice may not be removed or altered from any source * 3. This notice may not be removed or altered from any source
* distribution. * distribution.
*/ */
#ifndef MAPGENERATOR_HPP_ #ifndef MAPALLOCATOR_HPP_
#define MAPGENERATOR_HPP_ #define MAPALLOCATOR_HPP_
#include "region.hpp" #include "region.hpp"
#include "lua/lua.hpp" #include "lua/lua.hpp"
class BlankGenerator { class BlankAllocator {
public: 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); void Unload(Region* const);
private: private:
// //
}; };
/*
class PerlinGenerator { class LuaAllocator {
public: 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 LuaGenerator {
public:
void Create(Region** const, int width, int height, int depth, int x, int y);
void Unload(Region* const); void Unload(Region* const);
lua_State* SetLuaState(lua_State* L) { return state = L; } lua_State* SetLuaState(lua_State* L) { return state = L; }
+6 -19
View File
@@ -23,33 +23,20 @@
#include <stdexcept> #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 //EMPTY
} }
void DummyFormat::Save(Region* const ptr) { void DummyFormat::Save(Region* const ptr) {
//EMPTY //EMPTY
} }
/*
void VerboseFormat::Load(Region** const ptr, int x, int y) {
//TODO
}
void VerboseFormat::Save(Region* const ptr) { void LuaFormat::Load(Region** const ptr, int x, int y) {
//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) {
//something to load into //something to load into
(*ptr) = new Region(width, height, depth, x, y);
if (!(*ptr)) {
(*ptr) = new Region(x, y);
}
//API hook //API hook
lua_getglobal(state, "Region"); lua_getglobal(state, "Region");
+4 -23
View File
@@ -30,18 +30,7 @@
class DummyFormat { class DummyFormat {
public: 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; }
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 Save(Region* const); void Save(Region* const);
std::string SetSaveDir(std::string s) { return saveDir = s; } std::string SetSaveDir(std::string s) { return saveDir = s; }
@@ -50,20 +39,12 @@ private:
std::string saveDir; std::string saveDir;
}; };
class CompactFormat { //TODO: verbose save file format
public: //TODO: compact save file format
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 LuaFormat { class LuaFormat {
public: 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); void Save(Region* const);
std::string SetSaveDir(std::string s) { return saveDir = s; } std::string SetSaveDir(std::string s) { return saveDir = s; }
+3 -23
View File
@@ -21,35 +21,15 @@
*/ */
#include "region.hpp" #include "region.hpp"
Region::Region(int argWidth, int argHeight, int argDepth, int argX, int argY): Region::Region(int argX, int argY):
width(argWidth),
height(argHeight),
depth(argDepth),
x(argX), x(argX),
y(argY) y(argY)
{ {
tiles = new type_t**[width]; for (register int i = 0; i < REGION_WIDTH*REGION_HEIGHT*REGION_DEPTH; ++i) {
for (register int i = 0; i < width; ++i) { *(reinterpret_cast<type_t*>(tiles) + i) = 0;
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;
}
}
} }
} }
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) { Region::type_t Region::SetTile(int x, int y, int z, type_t v) {
return tiles[x][y][z] = v; return tiles[x][y][z] = v;
} }
+3 -10
View File
@@ -22,7 +22,6 @@
#ifndef REGION_HPP_ #ifndef REGION_HPP_
#define REGION_HPP_ #define REGION_HPP_
//temporary?
#define REGION_WIDTH 20 #define REGION_WIDTH 20
#define REGION_HEIGHT 20 #define REGION_HEIGHT 20
#define REGION_DEPTH 3 #define REGION_DEPTH 3
@@ -32,26 +31,20 @@ public:
typedef unsigned short type_t; typedef unsigned short type_t;
Region() = delete; Region() = delete;
Region(int width, int height, int depth, int x, int y); Region(int x, int y);
~Region(); ~Region() = default;
type_t SetTile(int x, int y, int z, type_t v); type_t SetTile(int x, int y, int z, type_t v);
type_t GetTile(int x, int y, int z); type_t GetTile(int x, int y, int z);
//accessors //accessors
int GetWidth() const { return width; }
int GetHeight() const { return height; }
int GetDepth() const { return depth; }
int GetX() const { return x; } int GetX() const { return x; }
int GetY() const { return y; } int GetY() const { return y; }
private: private:
const int width;
const int height;
const int depth;
const int x; const int x;
const int y; const int y;
type_t*** tiles = nullptr; type_t tiles[REGION_WIDTH][REGION_HEIGHT][REGION_DEPTH];
}; };
#endif #endif
+6 -16
View File
@@ -23,18 +23,6 @@
#include "utility.hpp" #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::type_t RegionPagerBase::SetTile(int x, int y, int z, Region::type_t v) {
Region* ptr = GetRegion(x, y); Region* ptr = GetRegion(x, y);
return ptr->SetTile(x - ptr->GetX(), y - ptr->GetY(), z, v); 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) { Region* RegionPagerBase::GetRegion(int x, int y) {
//snap the coords //snap the coords
x = snapToBase(regionWidth, x); x = snapToBase(REGION_WIDTH, x);
y = snapToBase(regionHeight, y); y = snapToBase(REGION_HEIGHT, y);
//get the region by various means //get the region by various means
//TODO: revert this try/catch point
Region* ptr = nullptr; Region* ptr = nullptr;
ptr = FindRegion(x, y); ptr = FindRegion(x, y);
if (ptr) return ptr; if (ptr) return ptr;
@@ -62,6 +48,10 @@ Region* RegionPagerBase::GetRegion(int x, int y) {
} }
Region* RegionPagerBase::FindRegion(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 //find the region
for (std::list<Region*>::iterator it = regionList.begin(); it != regionList.end(); it++) { for (std::list<Region*>::iterator it = regionList.begin(); it != regionList.end(); it++) {
if ((*it)->GetX() == x && (*it)->GetY() == y) { if ((*it)->GetX() == x && (*it)->GetY() == y) {
+27 -48
View File
@@ -29,9 +29,8 @@
class RegionPagerBase { class RegionPagerBase {
public: public:
RegionPagerBase() = default; RegionPagerBase() {};
RegionPagerBase(int regionWidth, int regionHeight, int regionDepth); virtual ~RegionPagerBase() {};
virtual ~RegionPagerBase();
//tile manipulation //tile manipulation
Region::type_t SetTile(int x, int y, int z, Region::type_t v); Region::type_t SetTile(int x, int y, int z, Region::type_t v);
@@ -50,86 +49,66 @@ public:
//TODO: delete? //TODO: delete?
//accessors & mutators //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 &regionList; } std::list<Region*>* GetContainer() { return &regionList; }
protected: protected:
int regionWidth;
int regionHeight;
int regionDepth;
std::list<Region*> regionList; std::list<Region*> regionList;
}; };
template<typename MapGenerator, typename MapFileFormat> template<typename Allocator, typename FileFormat>
class RegionPager : public RegionPagerBase { class RegionPager : public RegionPagerBase {
public: public:
RegionPager() = default; RegionPager() {};
RegionPager(int w, int h, int d):
RegionPagerBase(w, h, d)
{
//EMPTY
}
~RegionPager() { ~RegionPager() {
UnloadAll(); UnloadAll();
} }
Region* LoadRegion(int x, int y) { Region* LoadRegion(int x, int y) {
//snap the coords //snap the coords
x = snapToBase(regionWidth, x); x = snapToBase(REGION_WIDTH, x);
y = snapToBase(regionHeight, y); y = snapToBase(REGION_HEIGHT, y);
//load the region if possible //load the region if possible
Region* ptr = nullptr; Region* ptr = nullptr;
format.Load(&ptr, regionWidth, regionHeight, regionDepth, x, y); format.Load(&ptr, x, y);
if (ptr) { if (ptr) {
regionList.push_back(ptr); return PushRegion(ptr);
return ptr;
} }
return nullptr; return nullptr;
} }
Region* SaveRegion(int x, int y) { Region* SaveRegion(int x, int y) {
//snap the coords //snap the coords
x = snapToBase(regionWidth, x); x = snapToBase(REGION_WIDTH, x);
y = snapToBase(regionHeight, y); y = snapToBase(REGION_HEIGHT, y);
//find & save the region //find & save the region
for (std::list<Region*>::iterator it = regionList.begin(); it != regionList.end(); it++) { Region* ptr = FindRegion(x, y);
if ((*it)->GetX() == x && (*it)->GetY() == y) { if (ptr) {
format.Save(*it); format.Save(ptr);
return *it;
}
} }
return nullptr; return ptr;
} }
Region* CreateRegion(int x, int y) { Region* CreateRegion(int x, int y) {
//snap the coords //snap the coords
x = snapToBase(regionWidth, x); x = snapToBase(REGION_WIDTH, x);
y = snapToBase(regionHeight, y); y = snapToBase(REGION_HEIGHT, y);
//create and push the object //create and push the object
Region* ptr = nullptr; Region* ptr = nullptr;
generator.Create(&ptr, regionWidth, regionHeight, regionDepth, x, y); allocator.Create(&ptr, x, y);
regionList.push_back(ptr); return PushRegion(ptr);
return ptr;
} }
void UnloadRegion(int x, int y) { void UnloadRegion(int x, int y) {
//snap the coords //snap the coords
x = snapToBase(regionWidth, x); x = snapToBase(REGION_WIDTH, x);
y = snapToBase(regionHeight, y); y = snapToBase(REGION_HEIGHT, y);
//custom loop
for (std::list<Region*>::iterator it = regionList.begin(); it != regionList.end(); /* EMPTY */) { for (std::list<Region*>::iterator it = regionList.begin(); it != regionList.end(); /* EMPTY */) {
if ((*it)->GetX() == x && (*it)->GetY() == y) { if ((*it)->GetX() == x && (*it)->GetY() == y) {
generator.Unload(*it); allocator.Unload(*it);
regionList.erase(it); regionList.erase(it);
//reset the loop, because of reasons //reset the loop, because of reasons
@@ -141,17 +120,17 @@ public:
} }
void UnloadAll() { void UnloadAll() {
for (auto& it : regionList) { for (auto& it : regionList) {
generator.Unload(it); allocator.Unload(it);
} }
regionList.clear(); regionList.clear();
} }
//accessors //accessors
MapGenerator* GetGenerator() { return &generator; } Allocator* GetAllocator() { return &allocator; }
MapFileFormat* GetFormat() { return &format; } FileFormat* GetFormat() { return &format; }
protected: protected:
MapGenerator generator; Allocator allocator;
MapFileFormat format; FileFormat format;
}; };
#endif #endif
+1 -1
View File
@@ -107,7 +107,7 @@ union NetworkPacket {
//map data //map data
struct RegionInformation { struct RegionInformation {
Metadata meta; Metadata meta;
int width, height, depth, x, y; int x, y;
Region* region; Region* region;
}regionInfo; }regionInfo;
+16 -38
View File
@@ -21,7 +21,7 @@
*/ */
#include "serial.hpp" #include "serial.hpp"
#include "map_generator.hpp" #include "map_allocator.hpp"
#include <cstring> #include <cstring>
@@ -75,14 +75,6 @@ void serializeRegionFormat(NetworkPacket* packet, char* buffer) {
memcpy(buffer, &packet->meta.type, sizeof(NetworkPacket::Type)); memcpy(buffer, &packet->meta.type, sizeof(NetworkPacket::Type));
buffer += 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 //x & y
memcpy(buffer, &packet->regionInfo.x, sizeof(int)); memcpy(buffer, &packet->regionInfo.x, sizeof(int));
buffer += sizeof(int); buffer += sizeof(int);
@@ -94,14 +86,6 @@ void serializeRegionContent(NetworkPacket* packet, char* buffer) {
memcpy(buffer, &packet->meta.type, sizeof(NetworkPacket::Type)); memcpy(buffer, &packet->meta.type, sizeof(NetworkPacket::Type));
buffer += 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 //x & y
*reinterpret_cast<int*>(buffer) = packet->regionInfo.region->GetX(); *reinterpret_cast<int*>(buffer) = packet->regionInfo.region->GetX();
buffer += sizeof(int); buffer += sizeof(int);
@@ -109,9 +93,9 @@ void serializeRegionContent(NetworkPacket* packet, char* buffer) {
buffer += sizeof(int); buffer += sizeof(int);
//content //content
for (register int i = 0; i < packet->regionInfo.region->GetWidth(); i++) { for (register int i = 0; i < REGION_WIDTH; i++) {
for (register int j = 0; j < packet->regionInfo.region->GetHeight(); j++) { for (register int j = 0; j < REGION_HEIGHT; j++) {
for (register int k = 0; k < packet->regionInfo.region->GetDepth(); k++) { for (register int k = 0; k < REGION_DEPTH; k++) {
*reinterpret_cast<Region::type_t*>(buffer) = packet->regionInfo.region->GetTile(i, j, k); *reinterpret_cast<Region::type_t*>(buffer) = packet->regionInfo.region->GetTile(i, j, k);
buffer += sizeof(Region::type_t); buffer += sizeof(Region::type_t);
} }
@@ -169,14 +153,6 @@ void deserializeRegionFormat(NetworkPacket* packet, char* buffer) {
memcpy(&packet->meta.type, buffer, sizeof(NetworkPacket::Type)); memcpy(&packet->meta.type, buffer, sizeof(NetworkPacket::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 //x & y
memcpy(&packet->regionInfo.x, buffer, sizeof(int)); memcpy(&packet->regionInfo.x, buffer, sizeof(int));
buffer += sizeof(int); buffer += sizeof(int);
@@ -184,23 +160,25 @@ void deserializeRegionFormat(NetworkPacket* packet, char* buffer) {
} }
void deserializeRegionContent(NetworkPacket* packet, char* buffer) { void deserializeRegionContent(NetworkPacket* packet, char* buffer) {
//format memcpy(&packet->meta.type, buffer, sizeof(NetworkPacket::Type));
deserializeRegionFormat(packet, buffer); buffer += sizeof(NetworkPacket::Type);
buffer += sizeof(int) * 5 + 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 //content
BlankGenerator().Create( BlankAllocator().Create(
&packet->regionInfo.region, &packet->regionInfo.region,
packet->regionInfo.width,
packet->regionInfo.height,
packet->regionInfo.depth,
packet->regionInfo.x, packet->regionInfo.x,
packet->regionInfo.y packet->regionInfo.y
); );
for (register int i = 0; i < packet->regionInfo.region->GetWidth(); i++) { for (register int i = 0; i < REGION_WIDTH; i++) {
for (register int j = 0; j < packet->regionInfo.region->GetHeight(); j++) { for (register int j = 0; j < REGION_HEIGHT; j++) {
for (register int k = 0; k < packet->regionInfo.region->GetDepth(); k++) { for (register int k = 0; k < REGION_DEPTH; k++) {
packet->regionInfo.region->SetTile(i, j, k, *reinterpret_cast<Region::type_t*>(buffer)); packet->regionInfo.region->SetTile(i, j, k, *reinterpret_cast<Region::type_t*>(buffer));
buffer += sizeof(Region::type_t); buffer += sizeof(Region::type_t);
} }
+5 -4
View File
@@ -24,12 +24,13 @@
#include "network_packet.hpp" #include "network_packet.hpp"
/* Sending regions are the largest type of packet /* TODO: Keep the PACKET_BUFFER_SIZE up to date
* content: width * height * depth * sizoeof(type) * NOTE: REGION_CONTENT is currently the largest type of packet
* map format: sizeof(int) * 5 * map content: REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizoeof(region::type_t)
* map format: sizeof(int) * 2
* metadata: sizeof(metadata) * 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 serialize(NetworkPacket* const, void*);
void deserialize(NetworkPacket* const, void*); void deserialize(NetworkPacket* const, void*);
+3 -6
View File
@@ -37,20 +37,17 @@ static int getTile(lua_State* L) {
} }
static int getWidth(lua_State* L) { static int getWidth(lua_State* L) {
Region* ptr = (Region*)lua_touserdata(L, 1); lua_pushinteger(L, REGION_WIDTH);
lua_pushinteger(L, ptr->GetWidth());
return 1; return 1;
} }
static int getHeight(lua_State* L) { static int getHeight(lua_State* L) {
Region* ptr = (Region*)lua_touserdata(L, 1); lua_pushinteger(L, REGION_HEIGHT);
lua_pushinteger(L, ptr->GetHeight());
return 1; return 1;
} }
static int getDepth(lua_State* L) { static int getDepth(lua_State* L) {
Region* ptr = (Region*)lua_touserdata(L, 1); lua_pushinteger(L, REGION_DEPTH);
lua_pushinteger(L, ptr->GetDepth());
return 1; return 1;
} }
+1 -6
View File
@@ -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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * 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"} {"Debug", "Debug On", "Debug Off", "Toggle", "Testificate"}
}); });
//setup the map
pager.SetRegionWidth(REGION_WIDTH);
pager.SetRegionHeight(REGION_HEIGHT);
pager.SetRegionDepth(REGION_DEPTH);
//debug //debug
tsheet.Load(config["dir.tilesets"] + "terrain.bmp", 12, 15); tsheet.Load(config["dir.tilesets"] + "terrain.bmp", 12, 15);
for (int i = 0; i < REGION_WIDTH; i++) { for (int i = 0; i < REGION_WIDTH; i++) {
+3 -3
View File
@@ -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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -30,7 +30,7 @@
#include "menu_bar.hpp" #include "menu_bar.hpp"
#include "region_pager.hpp" #include "region_pager.hpp"
#include "map_generator.hpp" #include "map_allocator.hpp"
#include "map_file_format.hpp" #include "map_file_format.hpp"
#include "tile_sheet.hpp" #include "tile_sheet.hpp"
@@ -73,7 +73,7 @@ protected:
int x = 0, y = 0; int x = 0, y = 0;
} camera; } camera;
RegionPager<BlankGenerator, DummyFormat> pager; RegionPager<BlankAllocator, DummyFormat> pager;
TileSheet tsheet; TileSheet tsheet;
}; };
+5 -5
View File
@@ -1,7 +1,7 @@
print("Lua script check OK (./rsc)") print("Lua script check OK (./rsc)")
function Region.Create(r) 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 i = 1, Region.GetWidth(r) do
for j = 1, Region.GetHeight(r) do for j = 1, Region.GetHeight(r) do
if math.abs(i) == math.abs(j) then if math.abs(i) == math.abs(j) then
@@ -11,19 +11,19 @@ function Region.Create(r)
end end
end end
end end
print("done") -- print("done")
end end
function Region.Unload(r) 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 end
--return true if file loaded, otherwise return false --return true if file loaded, otherwise return false
function Region.Load(r, saveDir) 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 return false
end end
function Region.Save(r, saveDir) 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 end
+29 -49
View File
@@ -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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -26,31 +26,14 @@
#include <stdexcept> #include <stdexcept>
#include <iostream> #include <iostream>
#include <string> #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 //Define the public members
//------------------------- //-------------------------
void ServerApplication::Init(int argc, char** argv) { 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 //initial setup
ClientEntry::uidCounter = 0; ClientEntry::uidCounter = 0;
@@ -59,61 +42,56 @@ void ServerApplication::Init(int argc, char** argv) {
//Init SDL //Init SDL
if (SDL_Init(0)) { 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 //Init SDL_net
if (SDLNet_Init()) { 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); network.Open(config.Int("server.port"), PACKET_BUFFER_SIZE);
cout << "Initialized SDL_net" << endl; std::cout << "Initialized SDL_net" << std::endl;
//Init SQL //Init SQL
int ret = sqlite3_open_v2(config["server.dbname"].c_str(), &database, SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, nullptr); int ret = sqlite3_open_v2(config["server.dbname"].c_str(), &database, SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, nullptr);
if (ret != SQLITE_OK || !database) { 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 //setup the database
if (runSQLScript(database, config["dir.scripts"] + "setup_server.sql")) { 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 //lua
luaState = luaL_newstate(); luaState = luaL_newstate();
if (!luaState) { if (!luaState) {
throw(runtime_error("Failed to initialize lua")); throw(std::runtime_error("Failed to initialize lua"));
} }
luaL_openlibs(luaState); luaL_openlibs(luaState);
cout << "Initialized lua" << endl; std::cout << "Initialized lua" << std::endl;
//run the startup script //run the startup script
if (luaL_dofile(luaState, (config["dir.scripts"] + "setup_server.lua").c_str())) { 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 //setup the map object
regionPager.SetRegionWidth(REGION_WIDTH); regionPager.GetAllocator()->SetLuaState(luaState);
regionPager.SetRegionHeight(REGION_HEIGHT);
regionPager.SetRegionDepth(REGION_DEPTH);
regionPager.GetGenerator()->SetLuaState(luaState);
regionPager.GetFormat()->SetLuaState(luaState); regionPager.GetFormat()->SetLuaState(luaState);
//TODO: config parameter //TODO: config parameter
regionPager.GetFormat()->SetSaveDir("save/mapname/"); 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 std::cout << "Initialized the map system" << std::endl;
// with the map system as needed. std::cout << "\tsizeof(NetworkPacket): " << sizeof(NetworkPacket) << std::endl;
cout << "Initialized the map system" << endl; std::cout << "\tPACKET_BUFFER_SIZE: " << PACKET_BUFFER_SIZE << std::endl;
cout << "\tsizeof(NetworkPacket): " << sizeof(NetworkPacket) << endl;
cout << "\tPACKET_BUFFER_SIZE: " << PACKET_BUFFER_SIZE << endl;
//finalize the startup //finalize the startup
cout << "Startup completed successfully" << endl; std::cout << "Startup completed successfully" << std::endl;
//debugging //debugging
// //
@@ -138,7 +116,7 @@ void ServerApplication::Loop() {
} }
void ServerApplication::Quit() { void ServerApplication::Quit() {
cout << "Shutting down" << endl; std::cout << "Shutting down" << std::endl;
//empty the members //empty the members
regionPager.UnloadAll(); regionPager.UnloadAll();
@@ -148,7 +126,7 @@ void ServerApplication::Quit() {
network.Close(); network.Close();
SDLNet_Quit(); SDLNet_Quit();
SDL_Quit(); SDL_Quit();
cout << "Shutdown finished" << endl; std::cout << "Shutdown finished" << std::endl;
} }
//------------------------- //-------------------------
@@ -186,7 +164,7 @@ void ServerApplication::HandlePacket(NetworkPacket packet) {
break; break;
//handle errors //handle errors
default: default:
throw(runtime_error("Unknown NetworkPacket::Type encountered")); throw(std::runtime_error("Unknown NetworkPacket::Type encountered"));
break; break;
} }
} }
@@ -201,6 +179,7 @@ void ServerApplication::HandleBroadcastRequest(NetworkPacket packet) {
//TODO: version info //TODO: version info
snprintf(packet.serverInfo.name, PACKET_STRING_SIZE, "%s", config["server.name"].c_str()); snprintf(packet.serverInfo.name, PACKET_STRING_SIZE, "%s", config["server.name"].c_str());
//TODO: player count //TODO: player count
//TODO: map format
char buffer[PACKET_BUFFER_SIZE]; char buffer[PACKET_BUFFER_SIZE];
serialize(&packet, buffer); serialize(&packet, buffer);
network.Send(&packet.meta.srcAddress, buffer, PACKET_BUFFER_SIZE); network.Send(&packet.meta.srcAddress, buffer, PACKET_BUFFER_SIZE);
@@ -223,7 +202,7 @@ void ServerApplication::HandleJoinRequest(NetworkPacket packet) {
//finished this routine //finished this routine
ClientEntry::uidCounter++; ClientEntry::uidCounter++;
cout << "Connect, total: " << clientMap.size() << endl; std::cout << "Connect, total: " << clientMap.size() << std::endl;
} }
void ServerApplication::HandleDisconnect(NetworkPacket packet) { void ServerApplication::HandleDisconnect(NetworkPacket packet) {
@@ -257,7 +236,7 @@ void ServerApplication::HandleDisconnect(NetworkPacket packet) {
}); });
//finished this routine //finished this routine
cout << "Disconnect, total: " << clientMap.size() << endl; std::cout << "Disconnect, total: " << clientMap.size() << std::endl;
} }
void ServerApplication::HandleSynchronize(NetworkPacket packet) { void ServerApplication::HandleSynchronize(NetworkPacket packet) {
@@ -292,7 +271,7 @@ void ServerApplication::HandleShutdown(NetworkPacket packet) {
PumpPacket(packet); PumpPacket(packet);
//finished this routine //finished this routine
cout << "Shutdown signal accepted" << endl; std::cout << "Shutdown signal accepted" << std::endl;
} }
void ServerApplication::HandlePlayerNew(NetworkPacket packet) { void ServerApplication::HandlePlayerNew(NetworkPacket packet) {
@@ -331,6 +310,7 @@ void ServerApplication::HandlePlayerNew(NetworkPacket packet) {
void ServerApplication::HandlePlayerDelete(NetworkPacket packet) { void ServerApplication::HandlePlayerDelete(NetworkPacket packet) {
//TODO: remove this? //TODO: remove this?
//TODO: authenticate who is deleting this player
if (playerMap.find(packet.playerInfo.playerIndex) == playerMap.end()) { if (playerMap.find(packet.playerInfo.playerIndex) == playerMap.end()) {
throw(std::runtime_error("Cannot delete a non-existant player")); throw(std::runtime_error("Cannot delete a non-existant player"));
} }
+4 -4
View File
@@ -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 * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -23,11 +23,12 @@
#define SERVERAPPLICATION_HPP_ #define SERVERAPPLICATION_HPP_
//server specific stuff //server specific stuff
#include "server_utility.hpp"
#include "client_entry.hpp" #include "client_entry.hpp"
#include "player_entry.hpp" #include "player_entry.hpp"
//maps //maps
#include "map_generator.hpp" #include "map_allocator.hpp"
#include "map_file_format.hpp" #include "map_file_format.hpp"
#include "region_pager.hpp" #include "region_pager.hpp"
@@ -47,7 +48,6 @@
//STL //STL
#include <map> #include <map>
#include <string>
//The main application class //The main application class
class ServerApplication { class ServerApplication {
@@ -88,7 +88,7 @@ private:
//maps //maps
//TODO: I need to handle multiple map objects //TODO: I need to handle multiple map objects
RegionPager<LuaGenerator, LuaFormat> regionPager; RegionPager<LuaAllocator, LuaFormat> regionPager;
//misc //misc
bool running = true; bool running = true;
+40
View File
@@ -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;
}
+31
View File
@@ -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