It now builds cleanly, but I cut a few code stubs
This commit is contained in:
@@ -29,12 +29,6 @@ static int getPager(lua_State* L) {
|
||||
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) {
|
||||
//TODO: onCreate()
|
||||
return 0;
|
||||
@@ -49,7 +43,6 @@ static int onUnload(lua_State* L) {
|
||||
|
||||
static const luaL_Reg roomLib[] = {
|
||||
{"GetPager",getPager},
|
||||
{"GetGenerator",getGenerator},
|
||||
{"OnCreate", onCreate},
|
||||
{"OnUnload", onUnload},
|
||||
{nullptr, nullptr}
|
||||
|
||||
@@ -23,14 +23,11 @@
|
||||
#define ROOMDATA_HPP_
|
||||
|
||||
//map system
|
||||
#include "map_type.hpp"
|
||||
#include "region_pager_lua.hpp"
|
||||
#include "base_generator.hpp"
|
||||
|
||||
struct RoomData {
|
||||
//members
|
||||
RegionPagerLua pager;
|
||||
BaseGenerator* generator = nullptr;
|
||||
|
||||
//TODO: collision map
|
||||
//TODO: NPCs?
|
||||
|
||||
@@ -21,41 +21,19 @@
|
||||
*/
|
||||
#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>
|
||||
|
||||
//-------------------------
|
||||
//public access methods
|
||||
//-------------------------
|
||||
|
||||
RoomData* RoomManager::CreateRoom(MapType mapType) {
|
||||
RoomData* RoomManager::CreateRoom() {
|
||||
//create the room
|
||||
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
|
||||
if (luaState) {
|
||||
newRoom->pager.SetLuaState(luaState);
|
||||
newRoom->generator->SetLuaState(luaState);
|
||||
}
|
||||
|
||||
//register the room
|
||||
@@ -91,15 +69,12 @@ void RoomManager::UnloadRoom(int uid) {
|
||||
lua_pop(luaState, 1);
|
||||
|
||||
//free the memory
|
||||
delete room->generator;
|
||||
delete room;
|
||||
roomMap.erase(uid);
|
||||
}
|
||||
|
||||
RoomData* RoomManager::GetRoom(int uid) {
|
||||
RoomData* ptr = FindRoom(uid);
|
||||
if (ptr) return ptr;
|
||||
return CreateRoom(MapType::NONE);
|
||||
return FindRoom(uid);
|
||||
}
|
||||
|
||||
RoomData* RoomManager::FindRoom(int uid) {
|
||||
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
~RoomManager() = default;
|
||||
|
||||
//public access methods
|
||||
RoomData* CreateRoom(MapType);
|
||||
RoomData* CreateRoom();
|
||||
void UnloadRoom(int uid);
|
||||
|
||||
RoomData* GetRoom(int uid);
|
||||
|
||||
@@ -46,18 +46,8 @@ static int createRoom(lua_State* L) {
|
||||
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);
|
||||
RoomData* newRoom = roomMgr->CreateRoom();
|
||||
|
||||
//return the new room
|
||||
lua_pushlightuserdata(L, newRoom);
|
||||
|
||||
Reference in New Issue
Block a user