Added respawning rabbits
This commit is contained in:
@@ -32,11 +32,11 @@ BarrierManager::~BarrierManager() {
|
||||
}
|
||||
|
||||
//arg: a list of barriers to be updated in the clients
|
||||
void BarrierManager::Update(std::list<std::pair<const int, BarrierData*>>* barrierList) {
|
||||
void BarrierManager::Update(std::list<std::pair<const int, BarrierData*>>* barrierList, bool updateAll) {
|
||||
int ret;
|
||||
for (auto& it : elementMap) {
|
||||
ret = it.second.Update(lua);
|
||||
if (ret) {
|
||||
if (ret || updateAll) {
|
||||
barrierList->push_back(std::pair<const int, BarrierData*>(it.first, &it.second));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
~BarrierManager();
|
||||
|
||||
//common public methods
|
||||
void Update(std::list<std::pair<const int, BarrierData*>>* barrierList);
|
||||
void Update(std::list<std::pair<const int, BarrierData*>>* barrierList, bool updateAll);
|
||||
|
||||
int Create(int instanceIndex);
|
||||
void Unload(int uid);
|
||||
|
||||
@@ -32,11 +32,11 @@ CreatureManager::~CreatureManager() {
|
||||
}
|
||||
|
||||
//arg: a list of creatures to be updated in the clients
|
||||
void CreatureManager::Update(std::list<std::pair<const int, CreatureData*>>* creatureList) {
|
||||
void CreatureManager::Update(std::list<std::pair<const int, CreatureData*>>* creatureList, bool updateAll) {
|
||||
int ret;
|
||||
for (auto& it : elementMap) {
|
||||
ret = it.second.Update(lua);
|
||||
if (ret) {
|
||||
if (ret || updateAll) {
|
||||
creatureList->push_back(std::pair<const int, CreatureData*>(it.first, &it.second));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
~CreatureManager();
|
||||
|
||||
//common public methods
|
||||
void Update(std::list<std::pair<const int, CreatureData*>>* creatureList);
|
||||
void Update(std::list<std::pair<const int, CreatureData*>>* creatureList, bool updateAll);
|
||||
|
||||
int Create(std::string avatar, int scriptRef);
|
||||
void Unload(int uid);
|
||||
|
||||
@@ -109,6 +109,24 @@ static int forEachCreature(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int forEachBarrier(lua_State* L) {
|
||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||
BarrierManager* barrierMgr = room->GetBarrierMgr();
|
||||
//pass each barrier to the given function
|
||||
for (auto& it : *barrierMgr->GetContainer()) {
|
||||
lua_pushvalue(L, -1);
|
||||
lua_pushlightuserdata(L, static_cast<void*>(&it.second));
|
||||
//call each iteration, throwing an exception if something happened
|
||||
if (lua_pcall(L, 1, 0, 0) != LUA_OK) {
|
||||
std::ostringstream os;
|
||||
os << "Lua error: ";
|
||||
os << lua_tostring(L, -1);
|
||||
throw(std::runtime_error(os.str()));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int setOnTick(lua_State* L) {
|
||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, room->GetTickReference());
|
||||
@@ -122,6 +140,19 @@ static int getOnTick(lua_State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
//TODO: autogen docs
|
||||
static int setTag(lua_State* L) {
|
||||
RoomData* room = static_cast<RoomData*>(lua_touserdata(L, 1));
|
||||
room->SetTag(lua_tostring(L, 2), lua_tostring(L, 3));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int getTag(lua_State* L) {
|
||||
RoomData* room = static_cast<RoomData*>(lua_touserdata(L, 1));
|
||||
lua_pushstring(L, room->GetTag(lua_tostring(L, 2)).c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int initialize(lua_State* L) {
|
||||
RoomData* room = static_cast<RoomData*>(lua_touserdata(L, 1));
|
||||
|
||||
@@ -148,10 +179,14 @@ static const luaL_Reg roomLib[] = {
|
||||
|
||||
{"ForEachCharacter", forEachCharacter},
|
||||
{"ForEachCreature", forEachCreature},
|
||||
{"ForEachBarrier", forEachBarrier},
|
||||
|
||||
{"SetOnTick", setOnTick},
|
||||
{"GetOnTick", getOnTick},
|
||||
|
||||
{"SetTag", setTag},
|
||||
{"GetTag", getTag},
|
||||
|
||||
{"Initialize", initialize},
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
@@ -36,12 +36,21 @@ void RoomData::RunFrame() {
|
||||
//get the hook
|
||||
lua_rawgeti(lua, LUA_REGISTRYINDEX, tickRef);
|
||||
|
||||
//returning 1 means pump all
|
||||
bool updateAll = false;
|
||||
if (!lua_isnil(lua, -1)) {
|
||||
//call the tick function, with this as a parameter
|
||||
lua_pushlightuserdata(lua, this);
|
||||
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) {
|
||||
if (lua_pcall(lua, 1, 1, 0) != LUA_OK) {
|
||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
|
||||
}
|
||||
|
||||
//pump creatures & barriers
|
||||
if (lua_tonumber(lua, -1)) {
|
||||
updateAll = true;
|
||||
}
|
||||
|
||||
lua_pop(lua, 1);
|
||||
}
|
||||
else {
|
||||
lua_pop(lua, 1);
|
||||
@@ -55,8 +64,8 @@ void RoomData::RunFrame() {
|
||||
for (auto& it : characterList) {
|
||||
it->Update();
|
||||
}
|
||||
creatureMgr.Update(&creatureList);
|
||||
barrierMgr.Update(&barrierList);
|
||||
creatureMgr.Update(&creatureList, updateAll);
|
||||
barrierMgr.Update(&barrierList, updateAll);
|
||||
|
||||
//build a list of entities for use with the triggers
|
||||
std::stack<Entity*> entityStack;
|
||||
@@ -202,4 +211,12 @@ int RoomData::SetTickReference(int i) {
|
||||
|
||||
int RoomData::GetTickReference() {
|
||||
return tickRef;
|
||||
}
|
||||
|
||||
std::string RoomData::SetTag(std::string key, std::string value) {
|
||||
return tags[key] = value;
|
||||
}
|
||||
|
||||
std::string RoomData::GetTag(std::string key) {
|
||||
return tags[key];
|
||||
}
|
||||
@@ -70,6 +70,9 @@ public:
|
||||
int GetTickReference();
|
||||
//TODO: other triggers like player entry & exit, etc.
|
||||
|
||||
std::string SetTag(std::string key, std::string value);
|
||||
std::string GetTag(std::string key);
|
||||
|
||||
private:
|
||||
//metadata
|
||||
std::string roomName;
|
||||
@@ -90,4 +93,5 @@ private:
|
||||
|
||||
//hooks
|
||||
int tickRef = LUA_NOREF;
|
||||
std::map<std::string, std::string> tags;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user