Filled out the APIs a bit

This commit is contained in:
Kayne Ruse
2014-06-21 18:24:58 +10:00
parent 3662a97475
commit a64411a567
5 changed files with 82 additions and 19 deletions
+46 -4
View File
@@ -21,13 +21,55 @@
*/ */
#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 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[] = { static const luaL_Reg generatorlib[] = {
{"getgenerator", getGenerator}, {"gettype", getMapType},
{"getchunk", getChunk},
{"getmapwidth", getMapWidth},
{"getmapheight", getMapHeight},
{nullptr, nullptr} {nullptr, nullptr}
}; };
+1 -1
View File
@@ -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))
+10 -13
View File
@@ -21,28 +21,25 @@
*/ */
#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;
}
//TODO: parameters
static const luaL_Reg roomlib[] = { static const luaL_Reg roomlib[] = {
{"gettype",getType}, {"getpager",getPager},
{"getregionpager",getRegionPager}, {"getgenerator",getGenerator},
{nullptr, nullptr} {nullptr, nullptr}
}; };
-1
View File
@@ -29,7 +29,6 @@
struct RoomData { struct RoomData {
//members //members
MapType type;
RegionPagerLua pager; RegionPagerLua pager;
BaseGenerator* generator = nullptr; BaseGenerator* generator = nullptr;
+25
View File
@@ -35,8 +35,33 @@ static int getRoom(lua_State* L) {
return 1; return 1;
} }
static int createRoom(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));
//TODO: create room
return 0;
}
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[] = { static const luaL_Reg roommgrlib[] = {
{"getroom",getRoom}, {"getroom",getRoom},
{"createroom",createRoom},
{"unloadroom",unloadRoom},
{nullptr, nullptr} {nullptr, nullptr}
}; };