CreatureManager now uses Tuples
This commit is contained in:
@@ -32,12 +32,39 @@ CreatureManager::~CreatureManager() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//arg: a list of creatures to be updated in the clients
|
//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(
|
||||||
int ret;
|
std::list<std::tuple<const int, CreatureData*, int>>* creatureList,
|
||||||
|
std::list<CharacterData*>* characterList
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//for each creature
|
||||||
|
int ret; //0 = no action, ret&1 = update clients, ret&2 = unload during cleanup step
|
||||||
for (auto& it : elementMap) {
|
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 creatureBox = it.second.GetRealBounds();
|
||||||
|
for (auto& it : *characterList) {
|
||||||
|
if (creatureBox.CheckOverlap(it->GetRealBounds())) {
|
||||||
|
//this will need updating
|
||||||
|
ret += 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
creatureList->push_back(std::pair<const int, CreatureData*>(it.first, &it.second));
|
//push to the return list
|
||||||
|
creatureList->push_back(std::make_tuple(it.first, &it.second, ret));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CreatureManager::Cleanup(std::list<std::tuple<const int, CreatureData*, int>>* creatureList) {
|
||||||
|
//unload the given creature objects
|
||||||
|
for (auto& it : *creatureList) {
|
||||||
|
if (std::get<2>(it) & 2) {
|
||||||
|
// Unload(std::get<0>(it));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "character_data.hpp"
|
||||||
#include "creature_data.hpp"
|
#include "creature_data.hpp"
|
||||||
|
|
||||||
#include "lua.hpp"
|
#include "lua.hpp"
|
||||||
@@ -30,6 +31,7 @@
|
|||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
class CreatureManager {
|
class CreatureManager {
|
||||||
public:
|
public:
|
||||||
@@ -37,7 +39,11 @@ public:
|
|||||||
~CreatureManager();
|
~CreatureManager();
|
||||||
|
|
||||||
//common public methods
|
//common public methods
|
||||||
void Update(std::list<std::pair<const int, CreatureData*>>* creatureList);
|
void Update(
|
||||||
|
std::list<std::tuple<const int, CreatureData*, int>>* creatureList,
|
||||||
|
std::list<CharacterData*>* characterList
|
||||||
|
);
|
||||||
|
void Cleanup(std::list<std::tuple<const int, CreatureData*, int>>* creatureList);
|
||||||
|
|
||||||
int Create(std::string avatar, int scriptRef);
|
int Create(std::string avatar, int scriptRef);
|
||||||
void Unload(int uid);
|
void Unload(int uid);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. .. ../entities ../../common/gameplay ../../common/utilities
|
INCLUDES+=. .. ../characters ../entities ../../common/gameplay ../../common/utilities
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,10 @@ BoundingBox Entity::GetBounds() const {
|
|||||||
return bounds;
|
return bounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BoundingBox Entity::GetRealBounds() const {
|
||||||
|
return bounds + origin;
|
||||||
|
}
|
||||||
|
|
||||||
const char* Entity::GetType() const {
|
const char* Entity::GetType() const {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
@@ -41,6 +41,7 @@ public:
|
|||||||
Vector2 GetOrigin() const;
|
Vector2 GetOrigin() const;
|
||||||
Vector2 GetMotion() const;
|
Vector2 GetMotion() const;
|
||||||
BoundingBox GetBounds() const;
|
BoundingBox GetBounds() const;
|
||||||
|
BoundingBox GetRealBounds() const;
|
||||||
|
|
||||||
const char* GetType() const;
|
const char* GetType() const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user