Creatures are replaced with barriers
This commit is contained in:
@@ -32,12 +32,52 @@ BarrierManager::~BarrierManager() {
|
||||
}
|
||||
|
||||
//arg: a list of barriers to be updated in the clients
|
||||
void BarrierManager::Update(std::list<std::pair<const int, BarrierData*>>* barrierList) {
|
||||
int ret;
|
||||
void BarrierManager::Update(
|
||||
std::list<std::tuple<const int, BarrierData*, int>>* barrierList,
|
||||
std::list<std::tuple<const int, CreatureData*, int>>* creatureList,
|
||||
std::list<CharacterData*>* characterList
|
||||
)
|
||||
{
|
||||
//for each given creature, if a collision was detected, make a new barrier
|
||||
for (auto& it : *creatureList) {
|
||||
if (std::get<2>(it) & 2) {
|
||||
Create(-1); //instance from creature index?
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: merge barriers
|
||||
//TODO: absorb creatures into existing barriers
|
||||
|
||||
//update the barriers
|
||||
//TODO: how to delete the barriers?
|
||||
int ret; //0 = no action, ret&1 = update clients, ret&2 = collision detected
|
||||
for (auto& it : elementMap) {
|
||||
ret = it.second.Update(lua);
|
||||
//normal update
|
||||
ret = it.second.Update(lua) ? 1 : 0;
|
||||
|
||||
//check for collision with a character
|
||||
BoundingBox barrierBox = it.second.GetRealBounds();
|
||||
for (auto& it : *characterList) {
|
||||
if (barrierBox.CheckOverlap(it->GetRealBounds())) {
|
||||
//this will need updating
|
||||
ret |= 2;
|
||||
}
|
||||
|
||||
//TODO: absorb characters
|
||||
}
|
||||
|
||||
if (ret) {
|
||||
barrierList->push_back(std::pair<const int, BarrierData*>(it.first, &it.second));
|
||||
//push to the return list
|
||||
barrierList->push_back(std::make_tuple(it.first, &it.second, ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BarrierManager::Cleanup(std::list<std::tuple<const int, BarrierData*, int>>* barrierList) {
|
||||
//unload the given barrier objects
|
||||
for (auto& it : *barrierList) {
|
||||
if (std::get<2>(it) & 2) {
|
||||
Unload(std::get<0>(it));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "barrier_data.hpp"
|
||||
#include "character_data.hpp"
|
||||
#include "creature_data.hpp"
|
||||
|
||||
#include "lua.hpp"
|
||||
#include "sqlite3.h"
|
||||
@@ -29,6 +31,7 @@
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <tuple>
|
||||
|
||||
class BarrierManager {
|
||||
public:
|
||||
@@ -36,7 +39,12 @@ public:
|
||||
~BarrierManager();
|
||||
|
||||
//common public methods
|
||||
void Update(std::list<std::pair<const int, BarrierData*>>* barrierList);
|
||||
void Update(
|
||||
std::list<std::tuple<const int, BarrierData*, int>>* barrierList,
|
||||
std::list<std::tuple<const int, CreatureData*, int>>* creatureList,
|
||||
std::list<CharacterData*>* characterList
|
||||
);
|
||||
void Cleanup(std::list<std::tuple<const int, BarrierData*, int>>* barrierList);
|
||||
|
||||
int Create(int instanceIndex);
|
||||
void Unload(int uid);
|
||||
|
||||
Reference in New Issue
Block a user