Fixed CreateRoom()'s return type

This commit is contained in:
Kayne Ruse
2014-06-23 04:54:01 +10:00
parent 46ed196bf4
commit 316db43b0a
5 changed files with 12 additions and 35 deletions
+1 -1
View File
@@ -24,7 +24,7 @@
#include "lua/lua.hpp" #include "lua/lua.hpp"
#define TORTUGA_REGION_PAGER_NAME "pager" #define TORTUGA_REGION_PAGER_NAME "RegionPager"
LUAMOD_API int openRegionPagerAPI(lua_State* L); LUAMOD_API int openRegionPagerAPI(lua_State* L);
#endif #endif
-19
View File
@@ -1,20 +1 @@
print("Lua script check (./rsc)") print("Lua script check (./rsc)")
-------------------------
--Map API overrides
-------------------------
function region.create(r)
for i = 1, region.getwidth() do
for j = 1, region.getheight() do
if math.abs(region.getx(r) + i -1) == math.abs(region.gety(r) + j -1) then
region.settile(r, i, j, 1, 50)
else
region.settile(r, i, j, 1, 14)
end
end
end
--signal
region.settile(r, 4, 5, 2, 86)
end
+5 -10
View File
@@ -34,7 +34,7 @@
//public access methods //public access methods
//------------------------- //-------------------------
int RoomManager::CreateRoom(MapType mapType) { RoomData* RoomManager::CreateRoom(MapType mapType) {
//create the room //create the room
RoomData* newRoom = new RoomData(); RoomData* newRoom = new RoomData();
@@ -60,8 +60,6 @@ int RoomManager::CreateRoom(MapType mapType) {
//register the room //register the room
roomMap[counter++] = newRoom; roomMap[counter++] = newRoom;
//TODO: pass the room's index to the lua hooks?
//API hook //API hook
lua_getglobal(luaState, "Room"); lua_getglobal(luaState, "Room");
lua_getfield(luaState, -1, "OnCreate"); lua_getfield(luaState, -1, "OnCreate");
@@ -72,14 +70,14 @@ int RoomManager::CreateRoom(MapType mapType) {
lua_pop(luaState, 1); lua_pop(luaState, 1);
//finish the routine //finish the routine
return counter; return newRoom;
} }
int RoomManager::UnloadRoom(int uid) { void RoomManager::UnloadRoom(int uid) {
//find the room //find the room
RoomData* room = FindRoom(uid); RoomData* room = FindRoom(uid);
if (!room) { if (!room) {
return -1; return;
} }
//API hook //API hook
@@ -95,15 +93,12 @@ int RoomManager::UnloadRoom(int uid) {
delete room->generator; delete room->generator;
delete room; delete room;
roomMap.erase(uid); roomMap.erase(uid);
return 0;
} }
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;
int newIndex = CreateRoom(MapType::NONE); return CreateRoom(MapType::NONE);
return FindRoom(newIndex);
} }
RoomData* RoomManager::FindRoom(int uid) { RoomData* RoomManager::FindRoom(int uid) {
+2 -2
View File
@@ -36,8 +36,8 @@ public:
~RoomManager() = default; ~RoomManager() = default;
//public access methods //public access methods
int CreateRoom(MapType); RoomData* CreateRoom(MapType);
int UnloadRoom(int uid); void UnloadRoom(int uid);
RoomData* GetRoom(int uid); RoomData* GetRoom(int uid);
RoomData* FindRoom(int uid); RoomData* FindRoom(int uid);
+4 -3
View File
@@ -21,6 +21,7 @@
*/ */
#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"
@@ -54,10 +55,10 @@ static int createRoom(lua_State* L) {
}(); }();
//create the room //create the room
int newIndex = roomMgr->CreateRoom(mapType); RoomData* newRoom = roomMgr->CreateRoom(mapType);
//return the index //return the new room
lua_pushinteger(L, newIndex); lua_pushlightuserdata(L, newRoom);
return 1; return 1;
} }