Room transitions are working smoothly, read more

Although the room transitions are working fairly well, it is still heavy
handed, and a number of optimizations can be done. On the whole, this
needs a review.
This commit is contained in:
Kayne Ruse
2015-03-09 23:26:37 +11:00
parent 81b3769188
commit 4d71d4cc40
7 changed files with 109 additions and 19 deletions
+25 -2
View File
@@ -22,14 +22,37 @@
#include "character_api.hpp"
#include "character_data.hpp"
#include "character_manager.hpp"
#include "entity_api.hpp"
#include "room_manager.hpp"
#include "server_utilities.hpp"
static int setRoomIndex(lua_State* L) {
#include <stdexcept>
static int setRoomIndex(lua_State* L) { //TODO: (1) take the room userdata as a parameter
//NOTE: type-dependant calls to various API functions, see bug #43
//reverse engineer the character index
int characterIndex = -1;
CharacterData* character = static_cast<CharacterData*>(lua_touserdata(L, 1));
pumpAndChangeRooms(character, lua_tointeger(L, 2), -1); //TODO: (0) undefined behavior without character index
int roomIndex = lua_tointeger(L, 2);
RoomData* roomData = RoomManager::GetSingleton().Get(roomIndex);
CharacterManager& characterMgr = CharacterManager::GetSingleton();
for (auto& it : *characterMgr.GetContainer()) {
if (character == &it.second) {
characterIndex = it.first;
break;
}
}
//error checking
if (characterIndex == -1) {
throw(std::runtime_error("Failed to find character index by reference"));
}
pumpAndChangeRooms(character, lua_tointeger(L, 2), characterIndex);
return 0;
}