It now builds cleanly, but I cut a few code stubs

This commit is contained in:
Kayne Ruse
2014-07-03 00:55:54 +10:00
parent 82b1b589dc
commit 4dd4b37fc0
32 changed files with 49 additions and 842 deletions
@@ -19,24 +19,34 @@
* 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 ENEMYFACTORYGENERIC_HPP_ #ifndef COMBATDATA_HPP_
#define ENEMYFACTORYGENERIC_HPP_ #define COMBATDATA_HPP_
#include "enemy_factory_interface.hpp" #include "vector2.hpp"
#include "combat_defines.hpp"
//gameplay members
#include "character_data.hpp"
#include "enemy_data.hpp" #include "enemy_data.hpp"
#include <list> //std namespace
#include <chrono>
#include <array>
#include <utility>
//DOCS: Not really intended for use, but rather for copying and tweaking struct CombatData {
class EnemyFactoryGeneric : public EnemyFactoryInterface { typedef std::chrono::steady_clock Clock;
public:
EnemyFactoryGeneric();
~EnemyFactoryGeneric() noexcept override;
void Generate(std::list<EnemyData>* container) override; std::array<CharacterData, COMBAT_MAX_CHARACTERS> characterArray;
private: std::array<EnemyData, COMBAT_MAX_ENEMIES> enemyArray;
//TODO: hold the parameters specified by the room
//world interaction
int mapIndex = 0;
Vector2 origin = {0.0,0.0};
Vector2 bounds = {0.0,0.0};
//time interval
Clock::time_point lastTick = Clock::now();
}; };
#endif #endif
@@ -19,26 +19,29 @@
* 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 CHUNKDATA_HPP_ #ifndef ENEMYDATA_HPP_
#define CHUNKDATA_HPP_ #define ENEMYDATA_HPP_
#include "terrain_type.hpp" #include "vector2.hpp"
#include "statistics.hpp"
#include <type_traits> //std namespace
#include <string>
struct ChunkData { struct EnemyData {
enum class Moddable { //metadata
LOCKED, //do not change std::string handle;
HARD, //minor changes std::string avatar;
SOFT, //major changes
CLEAR, //untouched //gameplay
Statistics stats;
//TODO: gameplay components: equipment, items, buffs, debuffs, rewards
//active gameplay members
//NOTE: these are lost when unloaded
int tableIndex;
int atbGauge = 0;
}; };
TerrainType type;
// int fountainCount;
Moddable mod;
};
static_assert(std::is_pod<ChunkData>::value, "ChunkData is not a POD");
#endif #endif
+2
View File
@@ -22,6 +22,8 @@
#ifndef CHARACTERDEFINES_HPP_ #ifndef CHARACTERDEFINES_HPP_
#define CHARACTERDEFINES_HPP_ #define CHARACTERDEFINES_HPP_
#include <cmath>
//the speeds that the characters move //the speeds that the characters move
constexpr double CHARACTER_WALKING_SPEED = 140.0; constexpr double CHARACTER_WALKING_SPEED = 140.0;
constexpr double CHARACTER_WALKING_MOD = 1.0/sqrt(2.0); constexpr double CHARACTER_WALKING_MOD = 1.0/sqrt(2.0);
+1
View File
@@ -28,6 +28,7 @@
enum class TerrainType { enum class TerrainType {
NONE = 0, NONE = 0,
GRASSLANDS, GRASSLANDS,
//etc.
}; };
#endif #endif
+1 -1
View File
@@ -1,5 +1,5 @@
#config #config
INCLUDES+=. ../../common/gameplay ../../common/utilities INCLUDES+=. ../../common/gameplay ../../common/utilities ../characters ../enemies
LIBS+= LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
-34
View File
@@ -1,34 +0,0 @@
/* 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 "enemy_factory_generic.hpp"
EnemyFactoryGeneric::EnemyFactoryGeneric() : EnemyFactoryInterface() {
//EMPTY
}
EnemyFactoryGeneric::~EnemyFactoryGeneric() noexcept {
//EMPTY
}
void EnemyFactoryGeneric::Generate(std::list<EnemyData>* container) {
//TODO: fill this out
}
@@ -1,49 +0,0 @@
/* 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 ENEMYFACTORYINTERFACE_HPP_
#define ENEMYFACTORYINTERFACE_HPP_
#include "enemy_data.hpp"
#include "map_type.hpp"
#include <list>
//NOTE: Based on biome, world difficulty, etc.
class EnemyFactoryInterface {
public:
EnemyFactoryInterface() = default;
virtual ~EnemyFactoryInterface() = default;
virtual void Generate(std::list<EnemyData>* container) = 0;
//control the difficulty of the room
MapType SetType(MapType t) { return type = t; }
MapType GetType() { return type; }
int SetDifficulty(int d) { return difficulty = d; }
int GetDifficulty() { return difficulty; }
protected:
MapType type;
int difficulty = 0;
};
#endif
-2
View File
@@ -40,7 +40,6 @@
#include "region_pager_api.hpp" #include "region_pager_api.hpp"
#include "room_api.hpp" #include "room_api.hpp"
#include "room_mgr_api.hpp" #include "room_mgr_api.hpp"
#include "generator_api.hpp"
//these libs are loaded by lua.c and are readily available to any Lua program //these libs are loaded by lua.c and are readily available to any Lua program
static const luaL_Reg loadedlibs[] = { static const luaL_Reg loadedlibs[] = {
@@ -61,7 +60,6 @@ static const luaL_Reg loadedlibs[] = {
{TORTUGA_REGION_PAGER_NAME, openRegionPagerAPI}, {TORTUGA_REGION_PAGER_NAME, openRegionPagerAPI},
{TORTUGA_ROOM_NAME, openRoomAPI}, {TORTUGA_ROOM_NAME, openRoomAPI},
{TORTUGA_ROOM_MGR_NAME, openRoomMgrAPI}, {TORTUGA_ROOM_MGR_NAME, openRoomMgrAPI},
{TORTUGA_GENRATOR_NAME, openGeneratorAPI},
{NULL, NULL} {NULL, NULL}
}; };
-1
View File
@@ -20,7 +20,6 @@ all: $(OBJ) $(OUT)
$(MAKE) -C characters $(MAKE) -C characters
$(MAKE) -C combat $(MAKE) -C combat
$(MAKE) -C enemies $(MAKE) -C enemies
$(MAKE) -C mapgen
$(MAKE) -C rooms $(MAKE) -C rooms
$(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS) $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
-79
View File
@@ -1,79 +0,0 @@
/* 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 "generator_api.hpp"
#include "base_generator.hpp"
static int getMapType(lua_State* L) {
BaseGenerator* ptr = reinterpret_cast<BaseGenerator*>(lua_touserdata(L, 1));
switch(ptr->GetMapType()) {
case MapType::NONE:
lua_pushstring(L, "none");
break;
case MapType::OVERWORLD:
lua_pushstring(L, "overworld");
break;
case MapType::RUINS:
lua_pushstring(L, "ruins");
break;
case MapType::TOWERS:
lua_pushstring(L, "towers");
break;
case MapType::FORESTS:
lua_pushstring(L, "forests");
break;
case MapType::CAVES:
lua_pushstring(L, "caves");
break;
}
return 1;
}
static int getChunk(lua_State* L) {
BaseGenerator* ptr = reinterpret_cast<BaseGenerator*>(lua_touserdata(L, 1));
ChunkData* chunk = ptr->GetChunk(lua_tointeger(L, 2), lua_tointeger(L, 3));
lua_pushlightuserdata(L, reinterpret_cast<void*>(chunk));
return 1;
}
static int getMapWidth(lua_State* L) {
lua_pushinteger(L, MAP_WIDTH);
return 1;
}
static int getMapHeight(lua_State* L) {
lua_pushinteger(L, MAP_HEIGHT);
return 1;
}
static const luaL_Reg generatorLib[] = {
{"GetMapType", getMapType},
{"GetChunk", getChunk},
{"GetMapWidth", getMapWidth},
{"GetMapHeight", getMapHeight},
{nullptr, nullptr}
};
LUAMOD_API int openGeneratorAPI(lua_State* L) {
luaL_newlib(L, generatorLib);
return 1;
}
-30
View File
@@ -1,30 +0,0 @@
/* 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 GENERATORAPI_HPP_
#define GENERATORAPI_HPP_
#include "lua/lua.hpp"
#define TORTUGA_GENRATOR_NAME "Generator"
LUAMOD_API int openGeneratorAPI(lua_State* L);
#endif
@@ -1,36 +0,0 @@
/* 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 "base_generator.hpp"
BaseGenerator::BaseGenerator(MapType t) {
mapType = t;
for (int i = 0; i < MAP_WIDTH; i++) {
for (int j = 0; j < MAP_HEIGHT; j++) {
chunks[i][j].type = TerrainType::NONE;
chunks[i][j].mod = ChunkData::Moddable::CLEAR;
}
}
}
BaseGenerator::~BaseGenerator() {
//
}
@@ -1,54 +0,0 @@
/* 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 BASEGENERATOR_HPP_
#define BASEGENERATOR_HPP_
#include "map_type.hpp"
#include "chunk_data.hpp"
#include "lua/lua.hpp"
constexpr int MAP_WIDTH = 256;
constexpr int MAP_HEIGHT = 256;
class BaseGenerator {
public:
virtual ~BaseGenerator();
//accessors and mutators
virtual ChunkData* GetChunk(int x, int y) { return &chunks[x][y]; }
MapType GetMapType() { return mapType; }
lua_State* SetLuaState(lua_State* L) { return luaState = L; }
lua_State* GetLuaState() { return luaState; }
protected:
BaseGenerator() = delete;
BaseGenerator(MapType t);
ChunkData chunks[MAP_WIDTH][MAP_HEIGHT];
MapType mapType = MapType::NONE;
lua_State* luaState = nullptr;
};
#endif
@@ -1,30 +0,0 @@
/* 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 "caves_generator.hpp"
CavesGenerator::CavesGenerator() : BaseGenerator(MapType::CAVES) {
//
}
CavesGenerator::~CavesGenerator() {
//
}
@@ -1,36 +0,0 @@
/* 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 CAVESGENERATOR_HPP_
#define CAVESGENERATOR_HPP_
#include "base_generator.hpp"
class CavesGenerator : public BaseGenerator {
public:
CavesGenerator();
~CavesGenerator();
private:
//
};
#endif
@@ -1,30 +0,0 @@
/* 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 "forests_generator.hpp"
ForestsGenerator::ForestsGenerator() : BaseGenerator(MapType::FORESTS) {
//
}
ForestsGenerator::~ForestsGenerator() {
//
}
@@ -1,36 +0,0 @@
/* 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 FORESTSGENERATOR_HPP_
#define FORESTSGENERATOR_HPP_
#include "base_generator.hpp"
class ForestsGenerator : public BaseGenerator {
public:
ForestsGenerator();
~ForestsGenerator();
private:
//
};
#endif
-37
View File
@@ -1,37 +0,0 @@
#config
INCLUDES+=. ..
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
#source
CXXSRC=$(wildcard *.cpp)
#objects
OBJDIR=obj
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
#output
OUTDIR=../..
OUT=$(addprefix $(OUTDIR)/,server.a)
#targets
all: $(OBJ) $(OUT)
ar -crs $(OUT) $(OBJ)
$(OBJ): | $(OBJDIR)
$(OUT): | $(OUTDIR)
$(OBJDIR):
mkdir $(OBJDIR)
$(OUTDIR):
mkdir $(OUTDIR)
$(OBJDIR)/%.o: %.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
clean:
$(RM) *.o *.a *.exe
rebuild: clean all
@@ -1,30 +0,0 @@
/* 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 "overworld_generator.hpp"
OverworldGenerator::OverworldGenerator() : BaseGenerator(MapType::OVERWORLD) {
//
}
OverworldGenerator::~OverworldGenerator() {
//
}
@@ -1,36 +0,0 @@
/* 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 OVERWORLDGENERATOR_HPP_
#define OVERWORLDGENERATOR_HPP_
#include "base_generator.hpp"
class OverworldGenerator : public BaseGenerator {
public:
OverworldGenerator();
~OverworldGenerator();
private:
//
};
#endif
@@ -1,30 +0,0 @@
/* 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 "ruins_generator.hpp"
RuinsGenerator::RuinsGenerator() : BaseGenerator(MapType::RUINS) {
//
}
RuinsGenerator::~RuinsGenerator() {
//
}
@@ -1,36 +0,0 @@
/* 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 RUINSGENERATOR_HPP_
#define RUINSGENERATOR_HPP_
#include "base_generator.hpp"
class RuinsGenerator : public BaseGenerator {
public:
RuinsGenerator();
~RuinsGenerator();
private:
//
};
#endif
@@ -1,30 +0,0 @@
/* 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 "towers_generator.hpp"
TowersGenerator::TowersGenerator() : BaseGenerator(MapType::TOWERS) {
//
}
TowersGenerator::~TowersGenerator() {
//
}
@@ -1,36 +0,0 @@
/* 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 TOWERSGENERATOR_HPP_
#define TOWERSGENERATOR_HPP_
#include "base_generator.hpp"
class TowersGenerator : public BaseGenerator {
public:
TowersGenerator();
~TowersGenerator();
private:
//
};
#endif
-38
View File
@@ -1,38 +0,0 @@
#config
INCLUDES+=. generators
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
#source
CXXSRC=$(wildcard *.cpp)
#objects
OBJDIR=obj
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
#output
OUTDIR=..
OUT=$(addprefix $(OUTDIR)/,server.a)
#targets
all: $(OBJ) $(OUT)
ar -crs $(OUT) $(OBJ)
$(MAKE) -C generators
$(OBJ): | $(OBJDIR)
$(OUT): | $(OUTDIR)
$(OBJDIR):
mkdir $(OBJDIR)
$(OUTDIR):
mkdir $(OUTDIR)
$(OBJDIR)/%.o: %.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
clean:
$(RM) *.o *.a *.exe
rebuild: clean all
-34
View File
@@ -1,34 +0,0 @@
/* 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 MAPTYPE_HPP_
#define MAPTYPE_HPP_
enum class MapType {
NONE,
OVERWORLD,
RUINS,
TOWERS,
FORESTS,
CAVES,
};
#endif
-40
View File
@@ -1,40 +0,0 @@
/* 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 TERRAINTYPE_HPP_
#define TERRAINTYPE_HPP_
enum class TerrainType {
//default: something's wrong
NONE = 0,
//standard overworld
PLAINS,
GRASS,
DIRT,
SAND,
WATER,
//not used
LAST,
};
#endif
-7
View File
@@ -29,12 +29,6 @@ static int getPager(lua_State* L) {
return 1; return 1;
} }
static int getGenerator(lua_State* L) {
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
lua_pushlightuserdata(L, reinterpret_cast<void*>(room->generator));
return 1;
}
static int onCreate(lua_State* L) { static int onCreate(lua_State* L) {
//TODO: onCreate() //TODO: onCreate()
return 0; return 0;
@@ -49,7 +43,6 @@ static int onUnload(lua_State* L) {
static const luaL_Reg roomLib[] = { static const luaL_Reg roomLib[] = {
{"GetPager",getPager}, {"GetPager",getPager},
{"GetGenerator",getGenerator},
{"OnCreate", onCreate}, {"OnCreate", onCreate},
{"OnUnload", onUnload}, {"OnUnload", onUnload},
{nullptr, nullptr} {nullptr, nullptr}
-3
View File
@@ -23,14 +23,11 @@
#define ROOMDATA_HPP_ #define ROOMDATA_HPP_
//map system //map system
#include "map_type.hpp"
#include "region_pager_lua.hpp" #include "region_pager_lua.hpp"
#include "base_generator.hpp"
struct RoomData { struct RoomData {
//members //members
RegionPagerLua pager; RegionPagerLua pager;
BaseGenerator* generator = nullptr;
//TODO: collision map //TODO: collision map
//TODO: NPCs? //TODO: NPCs?
+2 -27
View File
@@ -21,41 +21,19 @@
*/ */
#include "room_manager.hpp" #include "room_manager.hpp"
//the generator types
#include "overworld_generator.hpp"
#include "ruins_generator.hpp"
#include "towers_generator.hpp"
#include "forests_generator.hpp"
#include "caves_generator.hpp"
#include <stdexcept> #include <stdexcept>
//------------------------- //-------------------------
//public access methods //public access methods
//------------------------- //-------------------------
RoomData* RoomManager::CreateRoom(MapType mapType) { RoomData* RoomManager::CreateRoom() {
//create the room //create the room
RoomData* newRoom = new RoomData(); RoomData* newRoom = new RoomData();
//create the generator, use a lambda because I'm lazy
newRoom->generator = [mapType]() -> BaseGenerator* {
switch(mapType) {
//BUG: Not having a map type results in an overworld generator by default
case MapType::NONE:
case MapType::OVERWORLD: return new OverworldGenerator();
case MapType::RUINS: return new RuinsGenerator();
case MapType::TOWERS: return new TowersGenerator();
case MapType::FORESTS: return new ForestsGenerator();
case MapType::CAVES: return new CavesGenerator();
}
throw(std::runtime_error("Failed to set the room's generator"));
}();
//set the state //set the state
if (luaState) { if (luaState) {
newRoom->pager.SetLuaState(luaState); newRoom->pager.SetLuaState(luaState);
newRoom->generator->SetLuaState(luaState);
} }
//register the room //register the room
@@ -91,15 +69,12 @@ void RoomManager::UnloadRoom(int uid) {
lua_pop(luaState, 1); lua_pop(luaState, 1);
//free the memory //free the memory
delete room->generator;
delete room; delete room;
roomMap.erase(uid); roomMap.erase(uid);
} }
RoomData* RoomManager::GetRoom(int uid) { RoomData* RoomManager::GetRoom(int uid) {
RoomData* ptr = FindRoom(uid); return FindRoom(uid);
if (ptr) return ptr;
return CreateRoom(MapType::NONE);
} }
RoomData* RoomManager::FindRoom(int uid) { RoomData* RoomManager::FindRoom(int uid) {
+1 -1
View File
@@ -36,7 +36,7 @@ public:
~RoomManager() = default; ~RoomManager() = default;
//public access methods //public access methods
RoomData* CreateRoom(MapType); RoomData* CreateRoom();
void UnloadRoom(int uid); void UnloadRoom(int uid);
RoomData* GetRoom(int uid); RoomData* GetRoom(int uid);
+1 -11
View File
@@ -46,18 +46,8 @@ static int createRoom(lua_State* L) {
lua_gettable(L, LUA_REGISTRYINDEX); lua_gettable(L, LUA_REGISTRYINDEX);
RoomManager* roomMgr = reinterpret_cast<RoomManager*>(lua_touserdata(L, -1)); RoomManager* roomMgr = reinterpret_cast<RoomManager*>(lua_touserdata(L, -1));
//determine the specified room type
MapType mapType = [L]() -> MapType {
if (std::string("overworld") == lua_tostring(L, -2)) return MapType::OVERWORLD;
if (std::string("ruins") == lua_tostring(L, -2)) return MapType::RUINS;
if (std::string("towers") == lua_tostring(L, -2)) return MapType::TOWERS;
if (std::string("forests") == lua_tostring(L, -2)) return MapType::FORESTS;
if (std::string("caves") == lua_tostring(L, -2)) return MapType::CAVES;
return MapType::NONE;
}();
//create the room //create the room
RoomData* newRoom = roomMgr->CreateRoom(mapType); RoomData* newRoom = roomMgr->CreateRoom();
//return the new room //return the new room
lua_pushlightuserdata(L, newRoom); lua_pushlightuserdata(L, newRoom);