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
+5 -10
View File
@@ -34,7 +34,7 @@
//public access methods
//-------------------------
int RoomManager::CreateRoom(MapType mapType) {
RoomData* RoomManager::CreateRoom(MapType mapType) {
//create the room
RoomData* newRoom = new RoomData();
@@ -60,8 +60,6 @@ int RoomManager::CreateRoom(MapType mapType) {
//register the room
roomMap[counter++] = newRoom;
//TODO: pass the room's index to the lua hooks?
//API hook
lua_getglobal(luaState, "Room");
lua_getfield(luaState, -1, "OnCreate");
@@ -72,14 +70,14 @@ int RoomManager::CreateRoom(MapType mapType) {
lua_pop(luaState, 1);
//finish the routine
return counter;
return newRoom;
}
int RoomManager::UnloadRoom(int uid) {
void RoomManager::UnloadRoom(int uid) {
//find the room
RoomData* room = FindRoom(uid);
if (!room) {
return -1;
return;
}
//API hook
@@ -95,15 +93,12 @@ int RoomManager::UnloadRoom(int uid) {
delete room->generator;
delete room;
roomMap.erase(uid);
return 0;
}
RoomData* RoomManager::GetRoom(int uid) {
RoomData* ptr = FindRoom(uid);
if (ptr) return ptr;
int newIndex = CreateRoom(MapType::NONE);
return FindRoom(newIndex);
return CreateRoom(MapType::NONE);
}
RoomData* RoomManager::FindRoom(int uid) {
+2 -2
View File
@@ -36,8 +36,8 @@ public:
~RoomManager() = default;
//public access methods
int CreateRoom(MapType);
int UnloadRoom(int uid);
RoomData* CreateRoom(MapType);
void UnloadRoom(int uid);
RoomData* GetRoom(int uid);
RoomData* FindRoom(int uid);
+4 -3
View File
@@ -21,6 +21,7 @@
*/
#include "room_mgr_api.hpp"
#include "room_api.hpp"
#include "room_manager.hpp"
#include "room_data.hpp"
@@ -54,10 +55,10 @@ static int createRoom(lua_State* L) {
}();
//create the room
int newIndex = roomMgr->CreateRoom(mapType);
RoomData* newRoom = roomMgr->CreateRoom(mapType);
//return the index
lua_pushinteger(L, newIndex);
//return the new room
lua_pushlightuserdata(L, newRoom);
return 1;
}