Merge branch 'api' into develop
This commit is contained in:
+22
-22
@@ -64,43 +64,43 @@ static int getDepth(lua_State* L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int load(lua_State* L) {
|
static int onLoad(lua_State* L) {
|
||||||
//TODO: fill this
|
//TODO: onLoad()
|
||||||
lua_pushboolean(L, false);
|
lua_pushboolean(L, false);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int save(lua_State* L) {
|
static int onSave(lua_State* L) {
|
||||||
//TODO: fill this
|
//TODO: onSave()
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int create(lua_State* L) {
|
static int onCreate(lua_State* L) {
|
||||||
//TODO: fill this
|
//TODO: onCreate()
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int unload(lua_State* L) {
|
static int onUnload(lua_State* L) {
|
||||||
//TODO: fill this
|
//TODO: onUnload()
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const luaL_Reg regionlib[] = {
|
static const luaL_Reg regionLib[] = {
|
||||||
{"settile",setTile},
|
{"SetTile",setTile},
|
||||||
{"gettile",getTile},
|
{"GetTile",getTile},
|
||||||
{"getx",getX},
|
{"GetX",getX},
|
||||||
{"gety",getY},
|
{"GetY",getY},
|
||||||
{"getwidth",getWidth},
|
{"GetWidth",getWidth},
|
||||||
{"getheight",getHeight},
|
{"GetHeight",getHeight},
|
||||||
{"getdepth",getDepth},
|
{"GetDepth",getDepth},
|
||||||
{"load",load},
|
{"OnLoad",onLoad},
|
||||||
{"save",save},
|
{"OnSave",onSave},
|
||||||
{"create",create},
|
{"OnCreate",onCreate},
|
||||||
{"unload",unload},
|
{"OnUnload",onUnload},
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|
||||||
LUAMOD_API int luaopen_regionapi(lua_State* L) {
|
LUAMOD_API int openRegionAPI(lua_State* L) {
|
||||||
luaL_newlib(L, regionlib);
|
luaL_newlib(L, regionLib);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
#include "lua/lua.hpp"
|
#include "lua/lua.hpp"
|
||||||
|
|
||||||
#define LUA_REGIONLIBNAME "region"
|
#define TORTUGA_REGION_NAME "Region"
|
||||||
LUAMOD_API int luaopen_regionapi(lua_State* L);
|
LUAMOD_API int openRegionAPI(lua_State* L);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
* 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 "pager_api.hpp"
|
#include "region_pager_api.hpp"
|
||||||
|
|
||||||
#include "region_pager_lua.hpp"
|
#include "region_pager_lua.hpp"
|
||||||
#include "region.hpp"
|
#include "region.hpp"
|
||||||
@@ -27,6 +27,8 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
//DOCS: These functions are just wrappers for the RegionPagerLua class
|
||||||
|
|
||||||
static int setTile(lua_State* L) {
|
static int setTile(lua_State* L) {
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
||||||
int ret = pager->SetTile(lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
|
int ret = pager->SetTile(lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
|
||||||
@@ -63,94 +65,46 @@ static int getDirectory(lua_State* L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int loadRegion(lua_State* L) {
|
static int loadRegion(lua_State* L) {
|
||||||
//get the parameters
|
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
||||||
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
Region* region = pager->LoadRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||||
std::string s = pager->GetDirectory();
|
|
||||||
|
|
||||||
//push the parameters
|
|
||||||
lua_getglobal(L, "region");
|
|
||||||
lua_getfield(L, -1, "load");
|
|
||||||
lua_pushlightuserdata(L, region);
|
lua_pushlightuserdata(L, region);
|
||||||
lua_pushstring(L, s.c_str());
|
|
||||||
|
|
||||||
//call the method
|
|
||||||
if (lua_pcall(L, 2, 1, 0) != LUA_OK) {
|
|
||||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(L, -1) ));
|
|
||||||
}
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int saveRegion(lua_State* L) {
|
static int saveRegion(lua_State* L) {
|
||||||
//get the parameters
|
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
||||||
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
Region* region = pager->SaveRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||||
std::string s = pager->GetDirectory();
|
|
||||||
|
|
||||||
//push the parameters
|
|
||||||
lua_getglobal(L, "region");
|
|
||||||
lua_getfield(L, -1, "save");
|
|
||||||
lua_pushlightuserdata(L, region);
|
lua_pushlightuserdata(L, region);
|
||||||
lua_pushstring(L, s.c_str());
|
return 1;
|
||||||
|
|
||||||
//call the method
|
|
||||||
if (lua_pcall(L, 2, 0, 0) != LUA_OK) {
|
|
||||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(L, -1) ));
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int createRegion(lua_State* L) {
|
static int createRegion(lua_State* L) {
|
||||||
//get the parameters
|
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
||||||
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
Region* region = pager->CreateRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||||
|
|
||||||
//push the parameters
|
|
||||||
lua_getglobal(L, "region");
|
|
||||||
lua_getfield(L, -1, "create");
|
|
||||||
lua_pushlightuserdata(L, region);
|
lua_pushlightuserdata(L, region);
|
||||||
//TODO: parameters
|
return 1;
|
||||||
|
|
||||||
//call the method
|
|
||||||
if (lua_pcall(L, 1, 0, 0) != LUA_OK) {
|
|
||||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(L, -1) ));
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int unloadRegion(lua_State* L) {
|
static int unloadRegion(lua_State* L) {
|
||||||
//get the parameters
|
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
||||||
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
pager->UnloadRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||||
std::string s = pager->GetDirectory();
|
|
||||||
|
|
||||||
//push the parameters
|
|
||||||
lua_getglobal(L, "region");
|
|
||||||
lua_getfield(L, -1, "unload");
|
|
||||||
lua_pushlightuserdata(L, region);
|
|
||||||
lua_pushstring(L, s.c_str());
|
|
||||||
|
|
||||||
//call the method
|
|
||||||
if (lua_pcall(L, 2, 0, 0) != LUA_OK) {
|
|
||||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(L, -1) ));
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const luaL_Reg pagerlib[] = {
|
static const luaL_Reg pagerlib[] = {
|
||||||
{"settile", setTile},
|
{"SetTile", setTile},
|
||||||
{"gettile", getTile},
|
{"GetTile", getTile},
|
||||||
{"getregion", getRegion},
|
{"GetRegion", getRegion},
|
||||||
{"setdirectory", setDirectory},
|
{"SetDirectory", setDirectory},
|
||||||
{"getdirectory", getDirectory},
|
{"GetDirectory", getDirectory},
|
||||||
{"loadregion", loadRegion},
|
{"LoadRegion", loadRegion},
|
||||||
{"saveregion", saveRegion},
|
{"SaveRegion", saveRegion},
|
||||||
{"createregion", createRegion},
|
{"CreateRegion", createRegion},
|
||||||
{"unloadregion", unloadRegion},
|
{"UnloadRegion", unloadRegion},
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|
||||||
LUAMOD_API int luaopen_pagerapi(lua_State* L) {
|
LUAMOD_API int openRegionPagerAPI(lua_State* L) {
|
||||||
luaL_newlib(L, pagerlib);
|
luaL_newlib(L, pagerlib);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
#include "lua/lua.hpp"
|
#include "lua/lua.hpp"
|
||||||
|
|
||||||
#define LUA_PAGERLIBNAME "pager"
|
#define TORTUGA_REGION_PAGER_NAME "RegionPager"
|
||||||
LUAMOD_API int luaopen_pagerapi(lua_State* L);
|
LUAMOD_API int openRegionPagerAPI(lua_State* L);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -29,12 +29,12 @@ Region* RegionPagerLua::LoadRegion(int x, int y) {
|
|||||||
//load the region if possible
|
//load the region if possible
|
||||||
|
|
||||||
//something to work on
|
//something to work on
|
||||||
regionList.emplace_front(x, y);
|
Region tmpRegion(x, y);
|
||||||
|
|
||||||
//API hook
|
//API hook
|
||||||
lua_getglobal(luaState, "region");
|
lua_getglobal(luaState, "Region");
|
||||||
lua_getfield(luaState, -1, "load");
|
lua_getfield(luaState, -1, "OnLoad");
|
||||||
lua_pushlightuserdata(luaState, ®ionList.front());
|
lua_pushlightuserdata(luaState, &tmpRegion);
|
||||||
lua_pushstring(luaState, directory.c_str());
|
lua_pushstring(luaState, directory.c_str());
|
||||||
if (lua_pcall(luaState, 2, 1, 0) != LUA_OK) {
|
if (lua_pcall(luaState, 2, 1, 0) != LUA_OK) {
|
||||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
|
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
|
||||||
@@ -42,10 +42,10 @@ Region* RegionPagerLua::LoadRegion(int x, int y) {
|
|||||||
//success or failure
|
//success or failure
|
||||||
if (!lua_toboolean(luaState, -1)) {
|
if (!lua_toboolean(luaState, -1)) {
|
||||||
lua_pop(luaState, 2);
|
lua_pop(luaState, 2);
|
||||||
regionList.pop_front();
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
lua_pop(luaState, 2);
|
lua_pop(luaState, 2);
|
||||||
|
regionList.push_front(tmpRegion);
|
||||||
return ®ionList.front();
|
return ®ionList.front();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,8 +54,8 @@ Region* RegionPagerLua::SaveRegion(int x, int y) {
|
|||||||
Region* ptr = FindRegion(x, y);
|
Region* ptr = FindRegion(x, y);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
//API hook
|
//API hook
|
||||||
lua_getglobal(luaState, "region");
|
lua_getglobal(luaState, "Region");
|
||||||
lua_getfield(luaState, -1, "save");
|
lua_getfield(luaState, -1, "OnSave");
|
||||||
lua_pushlightuserdata(luaState, ptr);
|
lua_pushlightuserdata(luaState, ptr);
|
||||||
lua_pushstring(luaState, directory.c_str());
|
lua_pushstring(luaState, directory.c_str());
|
||||||
if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
|
if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
|
||||||
@@ -72,28 +72,29 @@ Region* RegionPagerLua::CreateRegion(int x, int y) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//something to work on
|
//something to work on
|
||||||
regionList.emplace_front(x, y);
|
Region tmpRegion(x, y);
|
||||||
|
|
||||||
//API hook
|
//API hook
|
||||||
lua_getglobal(luaState, "region");
|
lua_getglobal(luaState, "Region");
|
||||||
lua_getfield(luaState, -1, "create");
|
lua_getfield(luaState, -1, "OnCreate");
|
||||||
lua_pushlightuserdata(luaState, ®ionList.front());
|
lua_pushlightuserdata(luaState, &tmpRegion);
|
||||||
//TODO: parameters
|
//TODO: parameters
|
||||||
if (lua_pcall(luaState, 1, 0, 0) != LUA_OK) {
|
if (lua_pcall(luaState, 1, 0, 0) != LUA_OK) {
|
||||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
|
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
|
||||||
}
|
}
|
||||||
lua_pop(luaState, 1);
|
lua_pop(luaState, 1);
|
||||||
return ®ionList.front();;
|
regionList.push_front(tmpRegion);
|
||||||
|
return ®ionList.front();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegionPagerLua::UnloadRegion(int x, int y) {
|
void RegionPagerLua::UnloadRegion(int x, int y) {
|
||||||
lua_getglobal(luaState, "region");
|
lua_getglobal(luaState, "Region");
|
||||||
|
|
||||||
regionList.remove_if([&](Region& region) -> bool {
|
regionList.remove_if([&](Region& region) -> bool {
|
||||||
if (region.GetX() == x && region.GetY() == y) {
|
if (region.GetX() == x && region.GetY() == y) {
|
||||||
|
|
||||||
//API hook
|
//API hook
|
||||||
lua_getfield(luaState, -1, "unload");
|
lua_getfield(luaState, -1, "OnUnload");
|
||||||
lua_pushlightuserdata(luaState, ®ion);
|
lua_pushlightuserdata(luaState, ®ion);
|
||||||
lua_pushstring(luaState, directory.c_str());
|
lua_pushstring(luaState, directory.c_str());
|
||||||
if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
|
if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
|
||||||
@@ -109,11 +110,11 @@ void RegionPagerLua::UnloadRegion(int x, int y) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void RegionPagerLua::UnloadAll() {
|
void RegionPagerLua::UnloadAll() {
|
||||||
lua_getglobal(luaState, "region");
|
lua_getglobal(luaState, "Region");
|
||||||
|
|
||||||
for (auto& it : regionList) {
|
for (auto& it : regionList) {
|
||||||
//API hook
|
//API hook
|
||||||
lua_getfield(luaState, -1, "unload");
|
lua_getfield(luaState, -1, "OnUnload");
|
||||||
lua_pushlightuserdata(luaState, &it);
|
lua_pushlightuserdata(luaState, &it);
|
||||||
lua_pushstring(luaState, directory.c_str());
|
lua_pushstring(luaState, directory.c_str());
|
||||||
if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
|
if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ public:
|
|||||||
|
|
||||||
void UnloadAll() override;
|
void UnloadAll() override;
|
||||||
|
|
||||||
|
//accessors & mutators
|
||||||
std::string SetDirectory(std::string s) { return directory = s; }
|
std::string SetDirectory(std::string s) { return directory = s; }
|
||||||
std::string GetDirectory() { return directory; }
|
std::string GetDirectory() { return directory; }
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#MKDIR=mkdir
|
#MKDIR=mkdir
|
||||||
#RM=del /y
|
#RM=del /y
|
||||||
|
|
||||||
|
#CXXFLAGS+=-static-libgcc -static-libstdc++ -g -fno-inline-functions -Wall
|
||||||
CXXFLAGS+=-static-libgcc -static-libstdc++
|
CXXFLAGS+=-static-libgcc -static-libstdc++
|
||||||
|
|
||||||
export
|
export
|
||||||
|
|||||||
@@ -1,20 +1,42 @@
|
|||||||
print("Lua script check (./rsc)")
|
print("Lua script check (./rsc)")
|
||||||
|
|
||||||
-------------------------
|
--uber lazy declarations
|
||||||
--Map API overrides
|
function square(x) return x*x end
|
||||||
-------------------------
|
function distance(x, y, i, j) return math.sqrt(square(x - i) + square(y - j)) end
|
||||||
|
|
||||||
function region.create(r)
|
--tile macros, mapped to the tilesheet
|
||||||
for i = 1, region.getwidth() do
|
local base = 14
|
||||||
for j = 1, region.getheight() do
|
local shift = 36
|
||||||
if math.abs(region.getx(r) + i -1) == math.abs(region.gety(r) + j -1) then
|
plains = base + shift * 0
|
||||||
region.settile(r, i, j, 1, 50)
|
grass = base + shift * 1
|
||||||
|
dirt = base + shift * 2
|
||||||
|
sand = base + shift * 3
|
||||||
|
water = base + shift * 4
|
||||||
|
|
||||||
|
--Overwrite the original OnCreate with my own version
|
||||||
|
Region.hcOnCreate = Region.OnCreate
|
||||||
|
Region.OnCreate = function(region)
|
||||||
|
local ret = Region.hcOnCreate(region) --best practices
|
||||||
|
for i = 1, Region.GetWidth() do
|
||||||
|
for j = 1, Region.GetHeight() do
|
||||||
|
if distance(0, 0, i + Region.GetX(region) -1, j + Region.GetY(region) -1) > 10 then
|
||||||
|
Region.SetTile(region, i, j, 1, water)
|
||||||
else
|
else
|
||||||
region.settile(r, i, j, 1, 14)
|
Region.SetTile(region, i, j, 1, plains)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return ret
|
||||||
|
end
|
||||||
|
|
||||||
--signal
|
--Get some regions
|
||||||
region.settile(r, 4, 5, 2, 86)
|
newRoom = RoomMgr.CreateRoom("overworld")
|
||||||
end
|
pager = Room.GetPager(newRoom)
|
||||||
|
regionTable = {
|
||||||
|
RegionPager.GetRegion(pager, 0, 0),
|
||||||
|
RegionPager.GetRegion(pager, 0, -20),
|
||||||
|
RegionPager.GetRegion(pager, -20, 0),
|
||||||
|
RegionPager.GetRegion(pager, -20, -20)
|
||||||
|
}
|
||||||
|
|
||||||
|
print("Finished the lua script")
|
||||||
+7
-7
@@ -37,7 +37,7 @@
|
|||||||
#include "lua/lua.hpp"
|
#include "lua/lua.hpp"
|
||||||
|
|
||||||
#include "region_api.hpp"
|
#include "region_api.hpp"
|
||||||
#include "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"
|
#include "generator_api.hpp"
|
||||||
@@ -56,12 +56,12 @@ static const luaL_Reg loadedlibs[] = {
|
|||||||
{LUA_MATHLIBNAME, luaopen_math},
|
{LUA_MATHLIBNAME, luaopen_math},
|
||||||
{LUA_DBLIBNAME, luaopen_debug},
|
{LUA_DBLIBNAME, luaopen_debug},
|
||||||
|
|
||||||
//custom libs
|
//Tortuga's API
|
||||||
{LUA_REGIONLIBNAME, luaopen_regionapi},
|
{TORTUGA_REGION_NAME, openRegionAPI},
|
||||||
{LUA_PAGERLIBNAME, luaopen_pagerapi},
|
{TORTUGA_REGION_PAGER_NAME, openRegionPagerAPI},
|
||||||
{LUA_ROOMLIBNAME, luaopen_roomapi},
|
{TORTUGA_ROOM_NAME, openRoomAPI},
|
||||||
{LUA_ROOMMGRLIBNAME, luaopen_roommgrapi},
|
{TORTUGA_ROOM_MGR_NAME, openRoomMgrAPI},
|
||||||
{LUA_GENERATORLIBNAME, luaopen_generatorapi},
|
{TORTUGA_GENRATOR_NAME, openGeneratorAPI},
|
||||||
|
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,17 +21,59 @@
|
|||||||
*/
|
*/
|
||||||
#include "generator_api.hpp"
|
#include "generator_api.hpp"
|
||||||
|
|
||||||
static int getGenerator(lua_State* L) {
|
#include "base_generator.hpp"
|
||||||
//TODO: return a generator based on the given parameter
|
|
||||||
return 0;
|
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 const luaL_Reg generatorlib[] = {
|
static int getChunk(lua_State* L) {
|
||||||
{"getgenerator", getGenerator},
|
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}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|
||||||
LUAMOD_API int luaopen_generatorapi(lua_State* L) {
|
LUAMOD_API int openGeneratorAPI(lua_State* L) {
|
||||||
luaL_newlib(L, generatorlib);
|
luaL_newlib(L, generatorLib);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,8 +24,7 @@
|
|||||||
|
|
||||||
#include "lua/lua.hpp"
|
#include "lua/lua.hpp"
|
||||||
|
|
||||||
#define LUA_GENERATORLIBNAME "generator"
|
#define TORTUGA_GENRATOR_NAME "Generator"
|
||||||
LUAMOD_API int luaopen_generatorapi(lua_State* L);
|
LUAMOD_API int openGeneratorAPI(lua_State* L);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -21,7 +21,8 @@
|
|||||||
*/
|
*/
|
||||||
#include "base_generator.hpp"
|
#include "base_generator.hpp"
|
||||||
|
|
||||||
BaseGenerator::BaseGenerator() {
|
BaseGenerator::BaseGenerator(MapType t) {
|
||||||
|
mapType = t;
|
||||||
for (int i = 0; i < MAP_WIDTH; i++) {
|
for (int i = 0; i < MAP_WIDTH; i++) {
|
||||||
for (int j = 0; j < MAP_HEIGHT; j++) {
|
for (int j = 0; j < MAP_HEIGHT; j++) {
|
||||||
chunks[i][j].type = TerrainType::NONE;
|
chunks[i][j].type = TerrainType::NONE;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#ifndef BASEGENERATOR_HPP_
|
#ifndef BASEGENERATOR_HPP_
|
||||||
#define BASEGENERATOR_HPP_
|
#define BASEGENERATOR_HPP_
|
||||||
|
|
||||||
|
#include "map_type.hpp"
|
||||||
#include "chunk_data.hpp"
|
#include "chunk_data.hpp"
|
||||||
|
|
||||||
#include "lua/lua.hpp"
|
#include "lua/lua.hpp"
|
||||||
@@ -31,17 +32,22 @@ constexpr int MAP_HEIGHT = 256;
|
|||||||
|
|
||||||
class BaseGenerator {
|
class BaseGenerator {
|
||||||
public:
|
public:
|
||||||
BaseGenerator();
|
|
||||||
virtual ~BaseGenerator();
|
virtual ~BaseGenerator();
|
||||||
|
|
||||||
//accessors and mutators
|
//accessors and mutators
|
||||||
virtual ChunkData* GetChunk(int x, int y) { return &chunks[x][y]; }
|
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* SetLuaState(lua_State* L) { return luaState = L; }
|
||||||
lua_State* GetLuaState() { return luaState; }
|
lua_State* GetLuaState() { return luaState; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
BaseGenerator() = delete;
|
||||||
|
BaseGenerator(MapType t);
|
||||||
|
|
||||||
ChunkData chunks[MAP_WIDTH][MAP_HEIGHT];
|
ChunkData chunks[MAP_WIDTH][MAP_HEIGHT];
|
||||||
|
MapType mapType = MapType::NONE;
|
||||||
lua_State* luaState = nullptr;
|
lua_State* luaState = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "caves_generator.hpp"
|
#include "caves_generator.hpp"
|
||||||
|
|
||||||
CavesGenerator::CavesGenerator() {
|
CavesGenerator::CavesGenerator() : BaseGenerator(MapType::CAVES) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,6 @@
|
|||||||
|
|
||||||
#include "base_generator.hpp"
|
#include "base_generator.hpp"
|
||||||
|
|
||||||
#define CAVES_GENERATOR_PSEUDOINDEX "CavesGenerator"
|
|
||||||
|
|
||||||
class CavesGenerator : public BaseGenerator {
|
class CavesGenerator : public BaseGenerator {
|
||||||
public:
|
public:
|
||||||
CavesGenerator();
|
CavesGenerator();
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "forests_generator.hpp"
|
#include "forests_generator.hpp"
|
||||||
|
|
||||||
ForestsGenerator::ForestsGenerator() {
|
ForestsGenerator::ForestsGenerator() : BaseGenerator(MapType::FORESTS) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,6 @@
|
|||||||
|
|
||||||
#include "base_generator.hpp"
|
#include "base_generator.hpp"
|
||||||
|
|
||||||
#define FORESTS_GENERATOR_PSEUDOINDEX "ForestsGenerator"
|
|
||||||
|
|
||||||
class ForestsGenerator : public BaseGenerator {
|
class ForestsGenerator : public BaseGenerator {
|
||||||
public:
|
public:
|
||||||
ForestsGenerator();
|
ForestsGenerator();
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "overworld_generator.hpp"
|
#include "overworld_generator.hpp"
|
||||||
|
|
||||||
OverworldGenerator::OverworldGenerator() {
|
OverworldGenerator::OverworldGenerator() : BaseGenerator(MapType::OVERWORLD) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,6 @@
|
|||||||
|
|
||||||
#include "base_generator.hpp"
|
#include "base_generator.hpp"
|
||||||
|
|
||||||
#define OVERWORLD_GENERATOR_PSEUDOINDEX "OverworldGenerator"
|
|
||||||
|
|
||||||
class OverworldGenerator : public BaseGenerator {
|
class OverworldGenerator : public BaseGenerator {
|
||||||
public:
|
public:
|
||||||
OverworldGenerator();
|
OverworldGenerator();
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "ruins_generator.hpp"
|
#include "ruins_generator.hpp"
|
||||||
|
|
||||||
RuinsGenerator::RuinsGenerator() {
|
RuinsGenerator::RuinsGenerator() : BaseGenerator(MapType::RUINS) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,6 @@
|
|||||||
|
|
||||||
#include "base_generator.hpp"
|
#include "base_generator.hpp"
|
||||||
|
|
||||||
#define RUINS_GENERATOR_PSEUDOINDEX "RuinsGenerator"
|
|
||||||
|
|
||||||
class RuinsGenerator : public BaseGenerator {
|
class RuinsGenerator : public BaseGenerator {
|
||||||
public:
|
public:
|
||||||
RuinsGenerator();
|
RuinsGenerator();
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "towers_generator.hpp"
|
#include "towers_generator.hpp"
|
||||||
|
|
||||||
TowersGenerator::TowersGenerator() {
|
TowersGenerator::TowersGenerator() : BaseGenerator(MapType::TOWERS) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,6 @@
|
|||||||
|
|
||||||
#include "base_generator.hpp"
|
#include "base_generator.hpp"
|
||||||
|
|
||||||
#define TOWERS_GENERATOR_PSEUDOINDEX "TowersGenerator"
|
|
||||||
|
|
||||||
class TowersGenerator : public BaseGenerator {
|
class TowersGenerator : public BaseGenerator {
|
||||||
public:
|
public:
|
||||||
TowersGenerator();
|
TowersGenerator();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=.
|
INCLUDES+=. generators
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
|||||||
@@ -23,11 +23,12 @@
|
|||||||
#define MAPTYPE_HPP_
|
#define MAPTYPE_HPP_
|
||||||
|
|
||||||
enum class MapType {
|
enum class MapType {
|
||||||
OVERWORLD = 0,
|
NONE,
|
||||||
RUINS = 1,
|
OVERWORLD,
|
||||||
TOWERS = 2,
|
RUINS,
|
||||||
FORESTS = 3,
|
TOWERS,
|
||||||
CAVES = 4,
|
FORESTS,
|
||||||
|
CAVES,
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+25
-16
@@ -21,32 +21,41 @@
|
|||||||
*/
|
*/
|
||||||
#include "room_api.hpp"
|
#include "room_api.hpp"
|
||||||
|
|
||||||
#include "room_manager.hpp"
|
|
||||||
#include "room_data.hpp"
|
#include "room_data.hpp"
|
||||||
|
|
||||||
static int getType(lua_State* L) {
|
static int getPager(lua_State* L) {
|
||||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
|
||||||
lua_pushinteger(L, static_cast<int>(room->type));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: parameters
|
|
||||||
|
|
||||||
static int getRegionPager(lua_State* L) {
|
|
||||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||||
lua_pushlightuserdata(L, reinterpret_cast<void*>(&room->pager));
|
lua_pushlightuserdata(L, reinterpret_cast<void*>(&room->pager));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: generators
|
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 const luaL_Reg roomlib[] = {
|
static int onCreate(lua_State* L) {
|
||||||
{"gettype",getType},
|
//TODO: onCreate()
|
||||||
{"getregionpager",getRegionPager},
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int onUnload(lua_State* L) {
|
||||||
|
//TODO: onUnload()
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: parameters
|
||||||
|
|
||||||
|
static const luaL_Reg roomLib[] = {
|
||||||
|
{"GetPager",getPager},
|
||||||
|
{"GetGenerator",getGenerator},
|
||||||
|
{"OnCreate", onCreate},
|
||||||
|
{"OnUnload", onUnload},
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|
||||||
LUAMOD_API int luaopen_roomapi(lua_State* L) {
|
LUAMOD_API int openRoomAPI(lua_State* L) {
|
||||||
luaL_newlib(L, roomlib);
|
luaL_newlib(L, roomLib);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
#include "lua/lua.hpp"
|
#include "lua/lua.hpp"
|
||||||
|
|
||||||
#define LUA_ROOMLIBNAME "room"
|
#define TORTUGA_ROOM_NAME "Room"
|
||||||
LUAMOD_API int luaopen_roomapi(lua_State* L);
|
LUAMOD_API int openRoomAPI(lua_State* L);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -29,7 +29,6 @@
|
|||||||
|
|
||||||
struct RoomData {
|
struct RoomData {
|
||||||
//members
|
//members
|
||||||
MapType type;
|
|
||||||
RegionPagerLua pager;
|
RegionPagerLua pager;
|
||||||
BaseGenerator* generator = nullptr;
|
BaseGenerator* generator = nullptr;
|
||||||
|
|
||||||
|
|||||||
@@ -21,37 +21,85 @@
|
|||||||
*/
|
*/
|
||||||
#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(int uid) {
|
RoomData* RoomManager::CreateRoom(MapType mapType) {
|
||||||
//don't overwrite existing rooms
|
//create the room
|
||||||
std::map<int, RoomData*>::iterator it = roomMap.find(uid);
|
RoomData* newRoom = new RoomData();
|
||||||
if (it != roomMap.end()) {
|
|
||||||
throw(std::runtime_error("Cannot overwrite an existing room"));
|
//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();
|
||||||
}
|
}
|
||||||
roomMap[uid] = new RoomData();
|
throw(std::runtime_error("Failed to set the room's generator"));
|
||||||
//TODO: create room in the API
|
}();
|
||||||
|
|
||||||
|
//set the state
|
||||||
if (luaState) {
|
if (luaState) {
|
||||||
roomMap[uid]->pager.SetLuaState(luaState);
|
newRoom->pager.SetLuaState(luaState);
|
||||||
}
|
newRoom->generator->SetLuaState(luaState);
|
||||||
return roomMap[uid];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RoomData* RoomManager::UnloadRoom(int uid) {
|
//register the room
|
||||||
//TODO: unload room in the API
|
roomMap[counter++] = newRoom;
|
||||||
delete roomMap[uid];
|
|
||||||
|
//API hook
|
||||||
|
lua_getglobal(luaState, "Room");
|
||||||
|
lua_getfield(luaState, -1, "OnCreate");
|
||||||
|
lua_pushlightuserdata(luaState, newRoom);
|
||||||
|
if (lua_pcall(luaState, 1, 0, 0) != LUA_OK) {
|
||||||
|
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
|
||||||
|
}
|
||||||
|
lua_pop(luaState, 1);
|
||||||
|
|
||||||
|
//finish the routine
|
||||||
|
return newRoom;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RoomManager::UnloadRoom(int uid) {
|
||||||
|
//find the room
|
||||||
|
RoomData* room = FindRoom(uid);
|
||||||
|
if (!room) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//API hook
|
||||||
|
lua_getglobal(luaState, "Room");
|
||||||
|
lua_getfield(luaState, -1, "OnUnload");
|
||||||
|
lua_pushlightuserdata(luaState, room);
|
||||||
|
if (lua_pcall(luaState, 1, 0, 0) != LUA_OK) {
|
||||||
|
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
|
||||||
|
}
|
||||||
|
lua_pop(luaState, 1);
|
||||||
|
|
||||||
|
//free the memory
|
||||||
|
delete room->generator;
|
||||||
|
delete room;
|
||||||
roomMap.erase(uid);
|
roomMap.erase(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
RoomData* RoomManager::GetRoom(int uid) {
|
RoomData* RoomManager::GetRoom(int uid) {
|
||||||
RoomData* ptr = FindRoom(uid);
|
RoomData* ptr = FindRoom(uid);
|
||||||
if (ptr) return ptr;
|
if (ptr) return ptr;
|
||||||
ptr = CreateRoom(uid);
|
return CreateRoom(MapType::NONE);
|
||||||
return ptr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RoomData* RoomManager::FindRoom(int uid) {
|
RoomData* RoomManager::FindRoom(int uid) {
|
||||||
@@ -62,11 +110,23 @@ RoomData* RoomManager::FindRoom(int uid) {
|
|||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
RoomData* RoomManager::PushRoom(int uid, RoomData* room) {
|
int RoomManager::PushRoom(RoomData* room) {
|
||||||
//unload existing rooms with this index
|
roomMap[counter++] = room;
|
||||||
std::map<int, RoomData*>::iterator it = roomMap.find(uid);
|
return counter;
|
||||||
if (it != roomMap.end()) {
|
|
||||||
UnloadRoom(uid);
|
|
||||||
}
|
}
|
||||||
roomMap[uid] = room;
|
|
||||||
|
void RoomManager::UnloadAll() {
|
||||||
|
lua_getglobal(luaState, "Room");
|
||||||
|
|
||||||
|
for (auto& it : roomMap) {
|
||||||
|
//API hook
|
||||||
|
lua_getfield(luaState, -1, "OnUnload");
|
||||||
|
lua_pushlightuserdata(luaState, it.second);
|
||||||
|
if (lua_pcall(luaState, 1, 0, 0) != LUA_OK) {
|
||||||
|
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_pop(luaState, 1);
|
||||||
|
roomMap.clear();
|
||||||
}
|
}
|
||||||
@@ -36,12 +36,14 @@ public:
|
|||||||
~RoomManager() = default;
|
~RoomManager() = default;
|
||||||
|
|
||||||
//public access methods
|
//public access methods
|
||||||
RoomData* CreateRoom(int uid);
|
RoomData* CreateRoom(MapType);
|
||||||
RoomData* UnloadRoom(int uid);
|
void UnloadRoom(int uid);
|
||||||
|
|
||||||
RoomData* GetRoom(int uid);
|
RoomData* GetRoom(int uid);
|
||||||
RoomData* FindRoom(int uid);
|
RoomData* FindRoom(int uid);
|
||||||
RoomData* PushRoom(int uid, RoomData*);
|
int PushRoom(RoomData*);
|
||||||
|
|
||||||
|
void UnloadAll();
|
||||||
|
|
||||||
//accessors and mutators
|
//accessors and mutators
|
||||||
std::map<int, RoomData*>* GetContainer() { return &roomMap; }
|
std::map<int, RoomData*>* GetContainer() { return &roomMap; }
|
||||||
@@ -52,6 +54,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::map<int, RoomData*> roomMap;
|
std::map<int, RoomData*> roomMap;
|
||||||
lua_State* luaState = nullptr;
|
lua_State* luaState = nullptr;
|
||||||
|
int counter = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -21,9 +21,12 @@
|
|||||||
*/
|
*/
|
||||||
#include "room_mgr_api.hpp"
|
#include "room_mgr_api.hpp"
|
||||||
|
|
||||||
|
#include "room_api.hpp"
|
||||||
#include "room_manager.hpp"
|
#include "room_manager.hpp"
|
||||||
#include "room_data.hpp"
|
#include "room_data.hpp"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
static int getRoom(lua_State* L) {
|
static int getRoom(lua_State* L) {
|
||||||
//get the room manager
|
//get the room manager
|
||||||
lua_pushstring(L, ROOM_MANAGER_PSEUDOINDEX);
|
lua_pushstring(L, ROOM_MANAGER_PSEUDOINDEX);
|
||||||
@@ -35,12 +38,52 @@ static int getRoom(lua_State* L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const luaL_Reg roommgrlib[] = {
|
static int createRoom(lua_State* L) {
|
||||||
{"getroom",getRoom},
|
//TODO: check parameter count for the glue functions
|
||||||
|
|
||||||
|
//get the room manager
|
||||||
|
lua_pushstring(L, ROOM_MANAGER_PSEUDOINDEX);
|
||||||
|
lua_gettable(L, LUA_REGISTRYINDEX);
|
||||||
|
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
|
||||||
|
RoomData* newRoom = roomMgr->CreateRoom(mapType);
|
||||||
|
|
||||||
|
//return the new room
|
||||||
|
lua_pushlightuserdata(L, newRoom);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int unloadRoom(lua_State* L) {
|
||||||
|
//get the room manager
|
||||||
|
lua_pushstring(L, ROOM_MANAGER_PSEUDOINDEX);
|
||||||
|
lua_gettable(L, LUA_REGISTRYINDEX);
|
||||||
|
RoomManager* roomMgr = reinterpret_cast<RoomManager*>(lua_touserdata(L, -1));
|
||||||
|
|
||||||
|
//unload the specified room
|
||||||
|
roomMgr->UnloadRoom(lua_tointeger(L, -2));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const luaL_Reg roomMgrLib[] = {
|
||||||
|
{"GetRoom",getRoom},
|
||||||
|
{"CreateRoom",createRoom},
|
||||||
|
{"UnloadRoom",unloadRoom},
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|
||||||
LUAMOD_API int luaopen_roommgrapi(lua_State* L) {
|
LUAMOD_API int openRoomMgrAPI(lua_State* L) {
|
||||||
luaL_newlib(L, roommgrlib);
|
luaL_newlib(L, roomMgrLib);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
#include "lua/lua.hpp"
|
#include "lua/lua.hpp"
|
||||||
|
|
||||||
#define LUA_ROOMMGRLIBNAME "roommgr"
|
#define TORTUGA_ROOM_MGR_NAME "RoomMgr"
|
||||||
LUAMOD_API int luaopen_roommgrapi(lua_State* L);
|
LUAMOD_API int openRoomMgrAPI(lua_State* L);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ void ServerApplication::Quit() {
|
|||||||
characterMgr.UnloadAll();
|
characterMgr.UnloadAll();
|
||||||
//TODO: unload combats
|
//TODO: unload combats
|
||||||
//TODO: unload enemies
|
//TODO: unload enemies
|
||||||
//TODO: unload rooms
|
roomMgr.UnloadAll();
|
||||||
|
|
||||||
//APIs
|
//APIs
|
||||||
lua_close(luaState);
|
lua_close(luaState);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
TODO: encapsulate the data structures
|
TODO: encapsulate the data structures
|
||||||
TODO: Get the rooms working
|
TODO: Get the rooms working
|
||||||
|
|
||||||
|
TODO: make the whole thing more fault tolerant
|
||||||
TODO: Authentication
|
TODO: Authentication
|
||||||
TODO: server is slaved to the client
|
TODO: server is slaved to the client
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user