Threaded barriers into the client, not yet queried
I've also refactored the rooms slightly.
This commit is contained in:
@@ -29,6 +29,53 @@ TriggerManager::~TriggerManager() {
|
||||
UnloadAll();
|
||||
}
|
||||
|
||||
//Compare the triggers to the entities, using their real hitboxes
|
||||
void TriggerManager::Compare(std::stack<Entity*> entityStack) {
|
||||
//NOTE: this stack solution should prevent problems when modifying the various lists
|
||||
while(entityStack.size()) {
|
||||
//get the entity & hitbox
|
||||
Entity* entity = entityStack.top();
|
||||
BoundingBox entityBox = entity->GetBounds() + entity->GetOrigin();
|
||||
|
||||
//get the trigger pair & hitbox
|
||||
for (auto& triggerPair : elementMap) {
|
||||
BoundingBox triggerBox = triggerPair.second.GetBoundingBox() + triggerPair.second.GetOrigin();
|
||||
|
||||
//find all collisions
|
||||
if (entityBox.CheckOverlap(triggerBox)) {
|
||||
//skip members of the exclusion list
|
||||
if (std::any_of(triggerPair.second.GetExclusionList()->begin(), triggerPair.second.GetExclusionList()->end(), [entity](Entity* ptr) -> bool {
|
||||
return entity == ptr;
|
||||
})) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//run the trigger script
|
||||
lua_rawgeti(lua, LUA_REGISTRYINDEX, triggerPair.second.GetScriptReference());
|
||||
lua_pushlightuserdata(lua, entity);
|
||||
|
||||
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) {
|
||||
//error
|
||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
|
||||
}
|
||||
|
||||
//push to the exclusion list
|
||||
triggerPair.second.GetExclusionList()->push_back(entity);
|
||||
}
|
||||
else {
|
||||
//remove members of the exclusion list
|
||||
//NOTE: characters in different rooms won't be removed, but that shouldn't be a problem
|
||||
triggerPair.second.GetExclusionList()->remove_if([entity](Entity* ptr) -> bool {
|
||||
return entity == ptr;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//next
|
||||
entityStack.pop();
|
||||
}
|
||||
}
|
||||
|
||||
int TriggerManager::Create(std::string handle) {
|
||||
//implicitly creates the element
|
||||
TriggerData& triggerData = elementMap[counter];
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <stack>
|
||||
#include <string>
|
||||
|
||||
class TriggerManager {
|
||||
@@ -36,6 +37,8 @@ public:
|
||||
TriggerManager();
|
||||
~TriggerManager();
|
||||
|
||||
void Compare(std::stack<Entity*> entityStack);
|
||||
|
||||
//common public methods
|
||||
int Create(std::string handle); //TODO: return the Trigger itself?
|
||||
void Unload(int uid);
|
||||
|
||||
Reference in New Issue
Block a user