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;
}
+1 -1
View File
@@ -1,5 +1,5 @@
#config
INCLUDES+=. ../entities ../monsters ../rooms ../server_utilities ../triggers ../../common/gameplay ../../common/map ../../common/utilities
INCLUDES+=. ../entities ../monsters ../rooms ../server_utilities ../triggers ../../common/gameplay ../../common/map ../../common/network ../../common/network/packet_types ../../common/utilities
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
+14 -2
View File
@@ -54,13 +54,25 @@ void RoomData::RunFrame() {
if ( itBox.CheckOverlap(hitBox) ) {
//trigger script
lua_rawgeti(lua, LUA_REGISTRYINDEX, it.second.GetScriptReference());
lua_pushlightuserdata(lua, character); //TODO: (1) entity type
lua_pushlightuserdata(lua, character);
//BUG: (0)
std::cout << "running scripts" << std::endl;
//run the script
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) {
//BUGFIX: changing the character's room via lua invalidates the list, therefore, the script much signal for an early exit
//TODO: (2) fix this somehow (operate on a stack?)
if (lua_pcall(lua, 1, 1, 0) != LUA_OK) {
//error
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
}
//true = safe to continue, false = exit early
if (!lua_toboolean(lua, -1)) {
std::cout << "Warning!: Early abort" << std::endl;
return;
}
}
}
// for (auto& monster : *monsterMgr.GetContainer()) {