Compare commits

..

3 Commits

Author SHA1 Message Date
Kayne Ruse ab6207d4f3 Barriers are working corretly, but are way too slow 2016-04-14 12:43:00 +10:00
Kayne Ruse 1267b30806 Creatures are replaced with barriers 2016-04-14 04:45:30 +10:00
Kayne Ruse 5d217d7cf9 CreatureManager now uses Tuples 2016-04-14 04:19:59 +10:00
36 changed files with 194 additions and 217 deletions
+9 -21
View File
@@ -22,7 +22,7 @@
#include "barrier_manager.hpp"
void BarrierManager::DrawTo(SDL_Renderer* const dest, Sint16 x, Sint16 y, double scaleX, double scaleY) {
for (auto& it : elementMap) {
for (auto& it : barrierMap) {
it.second.DrawTo(dest, x, y);
}
}
@@ -47,38 +47,26 @@ void BarrierManager::UnloadTemplateImages() {
}
BaseBarrier* BarrierManager::Create(int index) {
elementMap.emplace(index, BaseBarrier(baseImage, templateImages));
return &elementMap[index];
barrierMap.emplace(index, BaseBarrier(baseImage, templateImages));
return &barrierMap[index];
}
void BarrierManager::Unload(int i) {
elementMap.erase(i);
barrierMap.erase(i);
}
void BarrierManager::UnloadAll() {
elementMap.clear();
}
void BarrierManager::UnloadIf(std::function<bool(std::pair<const int, BaseBarrier const&>)> fn) {
std::map<int, BaseBarrier>::iterator it = elementMap.begin();
while (it != elementMap.end()) {
if (fn(*it)) {
it = elementMap.erase(it);
}
else {
++it;
}
}
barrierMap.clear();
}
int BarrierManager::Size() {
return elementMap.size();
return barrierMap.size();
}
BaseBarrier* BarrierManager::Find(int i) {
std::map<int, BaseBarrier>::iterator it = elementMap.find(i);
std::map<int, BaseBarrier>::iterator it = barrierMap.find(i);
if (it == elementMap.end()) {
if (it == barrierMap.end()) {
return nullptr;
}
@@ -86,7 +74,7 @@ BaseBarrier* BarrierManager::Find(int i) {
}
std::map<int, BaseBarrier>* BarrierManager::GetContainer() {
return &elementMap;
return &barrierMap;
}
std::map<std::string, Image>* BarrierManager::GetTemplateContainer() {
+1 -2
View File
@@ -42,7 +42,6 @@ public:
BaseBarrier* Create(int index);
void Unload(int i);
void UnloadAll();
void UnloadIf(std::function<bool(std::pair<const int, BaseBarrier const&>)> fn);
int Size();
@@ -53,5 +52,5 @@ public:
private:
Image baseImage;
std::map<std::string, Image> templateImages;
std::map<int, BaseBarrier> elementMap;
std::map<int, BaseBarrier> barrierMap;
};
+32 -42
View File
@@ -116,8 +116,8 @@ World::World(int* const argClientIndex, int* const argAccountIndex):
"slot 7 red.png",
"slot 8 red.png"
};
barrierMgr.LoadBaseImage(GetRenderer(), config["dir.sprites"] + "barrier/base.png");
barrierMgr.LoadTemplateImages(GetRenderer(), config["dir.sprites"] + "barrier/", slotNames);
barrierMgr.LoadBaseImage(GetRenderer(), config["dir.sprites"] + "/barrier/base.png");
barrierMgr.LoadTemplateImages(GetRenderer(), config["dir.sprites"] + "/barrier/", slotNames);
std::cout << "Templates loaded: " << barrierMgr.GetTemplateContainer()->size() << std::endl;
}
@@ -185,27 +185,7 @@ void World::Update() {
return;
}
//TODO: (0) regular query interval
if (Clock::now() - queryTime > std::chrono::seconds(3)) {
queryTime = Clock::now();
//query the world state (room)
CharacterPacket characterPacket;
memset(&characterPacket, 0, MAX_PACKET_SIZE);
characterPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS;
characterPacket.roomIndex = roomIndex;
network.SendTo(Channels::SERVER, &characterPacket);
CreaturePacket creaturePacket;
creaturePacket.type = SerialPacketType::QUERY_CREATURE_EXISTS;
creaturePacket.roomIndex = roomIndex;
network.SendTo(Channels::SERVER, &creaturePacket);
BarrierPacket barrierPacket;
barrierPacket.type = SerialPacketType::QUERY_BARRIER_EXISTS;
barrierPacket.roomIndex = roomIndex;
network.SendTo(Channels::SERVER, &barrierPacket);
}
//TODO: (1) regular query interval
//cull creatures
for (std::map<int, BaseCreature>::iterator it = creatureMap.begin(); it != creatureMap.end(); /* */) {
if ( (localCharacter->GetOrigin() - it->second.GetOrigin()).Length() > INFLUENCE_RADIUS) {
@@ -216,10 +196,7 @@ void World::Update() {
}
}
//cull barriers
barrierMgr.UnloadIf([&](std::pair<const int, BaseBarrier const&> barrierIt) -> bool {
return (localCharacter->GetOrigin() - barrierIt.second.GetOrigin()).Length() > INFLUENCE_RADIUS;
});
//TODO: cull barriers
//get the collidable boxes
std::list<BoundingBox> boxList = GenerateCollisionGrid(localCharacter, tileSheet.GetTileW(), tileSheet.GetTileH());
@@ -750,9 +727,6 @@ void World::hCharacterCreate(CharacterPacket* const argPacket) {
if (character->GetOwner() == accountIndex) {
localCharacter = static_cast<LocalCharacter*>(character);
//reset queries
queryTime = Clock::now() - std::chrono::seconds(4); //back 4 seconds to trigger automatically
//focus the camera on this character's sprite
camera.marginX = (camera.width / 2 - localCharacter->GetSprite()->GetClipW() / 2);
camera.marginY = (camera.height/ 2 - localCharacter->GetSprite()->GetClipH() / 2);
@@ -760,6 +734,26 @@ void World::hCharacterCreate(CharacterPacket* const argPacket) {
//focus on this character's info
characterIndex = argPacket->characterIndex;
roomIndex = argPacket->roomIndex;
//query the world state (room)
CharacterPacket characterPacket;
memset(&characterPacket, 0, MAX_PACKET_SIZE);
characterPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS;
characterPacket.roomIndex = roomIndex;
characterPacket.origin = localCharacter->GetOrigin();
network.SendTo(Channels::SERVER, &characterPacket);
CreaturePacket creaturePacket;
creaturePacket.type = SerialPacketType::QUERY_CREATURE_EXISTS;
creaturePacket.roomIndex = roomIndex;
creaturePacket.origin = localCharacter->GetOrigin();
network.SendTo(Channels::SERVER, &creaturePacket);
BarrierPacket barrierPacket;
barrierPacket.type = SerialPacketType::QUERY_BARRIER_EXISTS;
barrierPacket.roomIndex = roomIndex;
barrierPacket.origin = localCharacter->GetOrigin();
network.SendTo(Channels::SERVER, &barrierPacket);
}
//debug
@@ -800,12 +794,12 @@ void World::hCharacterUnload(CharacterPacket* const argPacket) {
void World::hQueryCharacterExists(CharacterPacket* const argPacket) {
//prevent a double message about this player's character
//TODO: why is this commented out?
if (argPacket->accountIndex == accountIndex) {
return;
}
// if (argPacket->accountIndex == accountIndex) {
// return;
// }
//ignore characters in a different room (sub-optimal)
if (argPacket->roomIndex != roomIndex || (localCharacter->GetOrigin() - argPacket->origin).Length() > INFLUENCE_RADIUS) {
if (argPacket->roomIndex != roomIndex) {
return;
}
@@ -922,12 +916,10 @@ void World::hCreatureUnload(CreaturePacket* const argPacket) {
}
void World::hQueryCreatureExists(CreaturePacket* const argPacket) {
if (!localCharacter) {
return;
}
std::cout << "Creature Query" << std::endl;
//ignore creatures in a different room (sub-optimal)
if (argPacket->roomIndex != roomIndex || (localCharacter->GetOrigin() - argPacket->origin).Length() > INFLUENCE_RADIUS) {
if (argPacket->roomIndex != roomIndex) {
return;
}
@@ -1032,12 +1024,10 @@ void World::hBarrierUnload(BarrierPacket* const argPacket) {
}
void World::hQueryBarrierExists(BarrierPacket* const argPacket) {
if (!localCharacter) {
return;
}
std::cout << "Barrier Query" << std::endl;
//ignore barriers in a different room (sub-optimal)
if (argPacket->roomIndex != roomIndex || (localCharacter->GetOrigin() - argPacket->origin).Length() > INFLUENCE_RADIUS) {
if (argPacket->roomIndex != roomIndex) {
return;
}
-1
View File
@@ -168,7 +168,6 @@ private:
//TODO: (2) Heartbeat needs it's own utility
typedef std::chrono::steady_clock Clock;
Clock::time_point lastBeat = Clock::now();
Clock::time_point queryTime = Clock::now() - std::chrono::seconds(4); //back 4 seconds to trigger automatically
int attemptedBeats = 0;
//ugly references; I hate this
Binary file not shown.

Before

Width:  |  Height:  |  Size: 738 B

After

Width:  |  Height:  |  Size: 738 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 763 B

After

Width:  |  Height:  |  Size: 763 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 273 B

After

Width:  |  Height:  |  Size: 273 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 270 B

After

Width:  |  Height:  |  Size: 270 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 305 B

After

Width:  |  Height:  |  Size: 305 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 302 B

After

Width:  |  Height:  |  Size: 302 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 423 B

After

Width:  |  Height:  |  Size: 423 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 422 B

After

Width:  |  Height:  |  Size: 422 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 301 B

After

Width:  |  Height:  |  Size: 301 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 299 B

After

Width:  |  Height:  |  Size: 299 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 385 B

After

Width:  |  Height:  |  Size: 385 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 383 B

After

Width:  |  Height:  |  Size: 383 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 412 B

After

Width:  |  Height:  |  Size: 412 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 402 B

After

Width:  |  Height:  |  Size: 402 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 431 B

After

Width:  |  Height:  |  Size: 431 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 429 B

After

Width:  |  Height:  |  Size: 429 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 407 B

After

Width:  |  Height:  |  Size: 407 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 400 B

After

Width:  |  Height:  |  Size: 400 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 656 B

After

Width:  |  Height:  |  Size: 656 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 680 B

+3 -15
View File
@@ -130,14 +130,14 @@ roomManagerAPI.SetOnCreate(function(room, index)
--
end)
creatureManagerAPI.Create(roomAPI.GetCreatureMgr(room), "anibunny.png", bunnySquare)
--creatureManager with SetOnCreate, SetOnUnload & create & unload
barrierManagerAPI.SetOnCreate(roomAPI.GetBarrierMgr(room), function(barrier)
barrierAPI.SetScript(barrier, barrierTick)
end)
roomAPI.SetOnTick(room, function(room)
ret = 0
--placeholders
roomAPI.ForEachCharacter(room, function(character)
--
end)
@@ -146,19 +146,7 @@ roomManagerAPI.SetOnCreate(function(room, index)
--
end)
roomAPI.ForEachBarrier(room, function(creature)
--
end)
--respawn a new rabbit when needed
if creatureManagerAPI.GetLoadedCount(roomAPI.GetCreatureMgr(room)) < 1 and
barrierManagerAPI.GetLoadedCount(roomAPI.GetBarrierMgr(room)) < 2
then
--make a new creature
creatureManagerAPI.Create(roomAPI.GetCreatureMgr(room), "anibunny.png", bunnySquare)
ret = 1
end
return ret
--TODO: for each barrier
end)
end)
+52 -5
View File
@@ -23,6 +23,8 @@
#include "lua_utilities.hpp"
#include "barrier_defines.hpp"
BarrierManager::BarrierManager() {
//EMPTY
}
@@ -32,12 +34,57 @@ BarrierManager::~BarrierManager() {
}
//arg: a list of barriers to be updated in the clients
void BarrierManager::Update(std::list<std::pair<const int, BarrierData*>>* barrierList, bool updateAll) {
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) {
int index = Create(-1); //instance from creature index?
BarrierData* barrierData = Find(index);
barrierData->SetOrigin({
(CREATURE_BOUNDS_WIDTH - BARRIER_BOUNDS_WIDTH) / 2 + std::get<1>(it)->GetOrigin().x,
(CREATURE_BOUNDS_HEIGHT - BARRIER_BOUNDS_HEIGHT) / 2 + std::get<1>(it)->GetOrigin().y
});
}
}
//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);
if (ret || updateAll) {
barrierList->push_back(std::pair<const int, BarrierData*>(it.first, &it.second));
//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) {
//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) & 4) {
Unload(std::get<0>(it));
}
}
}
+9 -1
View File
@@ -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, bool updateAll);
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);
+32 -5
View File
@@ -32,12 +32,39 @@ CreatureManager::~CreatureManager() {
}
//arg: a list of creatures to be updated in the clients
void CreatureManager::Update(std::list<std::pair<const int, CreatureData*>>* creatureList, bool updateAll) {
int ret;
void CreatureManager::Update(
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 = collision detected
for (auto& it : elementMap) {
ret = it.second.Update(lua);
if (ret || updateAll) {
creatureList->push_back(std::pair<const int, CreatureData*>(it.first, &it.second));
//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) {
//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));
}
}
}
+7 -1
View File
@@ -21,6 +21,7 @@
*/
#pragma once
#include "character_data.hpp"
#include "creature_data.hpp"
#include "lua.hpp"
@@ -30,6 +31,7 @@
#include <list>
#include <map>
#include <string>
#include <tuple>
class CreatureManager {
public:
@@ -37,7 +39,11 @@ public:
~CreatureManager();
//common public methods
void Update(std::list<std::pair<const int, CreatureData*>>* creatureList, bool updateAll);
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);
void Unload(int uid);
+1 -1
View File
@@ -1,5 +1,5 @@
#config
INCLUDES+=. .. ../entities ../../common/gameplay ../../common/utilities
INCLUDES+=. .. ../characters ../entities ../../common/gameplay ../../common/utilities
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
+4
View File
@@ -63,6 +63,10 @@ BoundingBox Entity::GetBounds() const {
return bounds;
}
BoundingBox Entity::GetRealBounds() const {
return bounds + origin;
}
const char* Entity::GetType() const {
return type;
}
+1
View File
@@ -41,6 +41,7 @@ public:
Vector2 GetOrigin() const;
Vector2 GetMotion() const;
BoundingBox GetBounds() const;
BoundingBox GetRealBounds() const;
const char* GetType() const;
-35
View File
@@ -109,24 +109,6 @@ 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());
@@ -140,19 +122,6 @@ 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));
@@ -179,14 +148,10 @@ static const luaL_Reg roomLib[] = {
{"ForEachCharacter", forEachCharacter},
{"ForEachCreature", forEachCreature},
{"ForEachBarrier", forEachBarrier},
{"SetOnTick", setOnTick},
{"GetOnTick", getOnTick},
{"SetTag", setTag},
{"GetTag", getTag},
{"Initialize", initialize},
{nullptr, nullptr}
};
+42 -83
View File
@@ -30,42 +30,70 @@
#include <iostream>
#include <stack>
#include <stdexcept>
#include <tuple>
//TODO: (9) character collisions should be preformed client-side
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, 1, 0) != LUA_OK) {
if (lua_pcall(lua, 1, 0, 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);
}
//lists of non-character entities that need updating client-side
std::list<std::pair<const int, CreatureData*>> creatureList;
std::list<std::pair<const int, BarrierData*>> barrierList;
//types are index, ptr, action (0 = update, 1 = unload)
std::list<std::tuple<const int, CreatureData*, int>> creatureList;
std::list<std::tuple<const int, BarrierData*, int>> barrierList;
//update the entities in the room
for (auto& it : characterList) {
it->Update();
}
creatureMgr.Update(&creatureList, updateAll);
barrierMgr.Update(&barrierList, updateAll);
creatureMgr.Update(&creatureList, &characterList);
barrierMgr.Update(&barrierList, &creatureList, &characterList);
//send the creature updates
for (auto& it : creatureList) {
CreaturePacket packet;
copyCreatureToPacket(&packet, std::get<1>(it), std::get<0>(it));
//interpret the event
if (std::get<2>(it) & 1) {
packet.type = SerialPacketType::CREATURE_UPDATE;
}
if (std::get<2>(it) & 2) {
packet.type = SerialPacketType::CREATURE_UNLOAD;
}
packet.roomIndex = roomIndex;
pumpPacketProximity(reinterpret_cast<SerialPacket*>(&packet), roomIndex, std::get<1>(it)->GetOrigin(), INFLUENCE_RADIUS);
}
//send the barrier updates
for (auto& it : barrierList) {
BarrierPacket packet;
copyBarrierToPacket(&packet, std::get<1>(it), std::get<0>(it));
//interpret the event
if (std::get<2>(it) & 1 || std::get<2>(it) & 2) {
packet.type = SerialPacketType::BARRIER_UPDATE;
}
packet.roomIndex = roomIndex;
pumpPacketProximity(reinterpret_cast<SerialPacket*>(&packet), roomIndex, std::get<1>(it)->GetOrigin(), INFLUENCE_RADIUS);
}
//cleanup the lists
creatureMgr.Cleanup(&creatureList);
barrierMgr.Cleanup(&barrierList);
//build a list of entities for use with the triggers
std::stack<Entity*> entityStack;
@@ -75,67 +103,6 @@ void RoomData::RunFrame() {
//Compare the triggers to the entities, using their real hitboxes
triggerMgr.Compare(entityStack);
//Creature/character collisions, O(m*n)
for (auto characterIt : characterList) {
BoundingBox characterBox = characterIt->GetBounds() + characterIt->GetOrigin();
std::list<int> creatureUnloadList;
for (auto creatureIt : *creatureMgr.GetContainer()) {
BoundingBox creatureBox = creatureIt.second.GetBounds() + creatureIt.second.GetOrigin();
if (characterBox.CheckOverlap(creatureBox)) {
int barrierIndex = barrierMgr.Create(-1);
BarrierData* barrierData = barrierMgr.Find(barrierIndex);
barrierData->SetRoomIndex(roomIndex);
barrierData->SetOrigin({
(CREATURE_BOUNDS_WIDTH - BARRIER_BOUNDS_WIDTH) / 2 + creatureBox.x,
(CREATURE_BOUNDS_HEIGHT - BARRIER_BOUNDS_HEIGHT) / 2 + creatureBox.y,
});
BarrierPacket barrierPacket;
barrierPacket.type = SerialPacketType::BARRIER_CREATE;
copyBarrierToPacket(&barrierPacket, barrierData, barrierIndex);
pumpPacketProximity(reinterpret_cast<SerialPacket*>(&barrierPacket), roomIndex, characterIt->GetOrigin(), INFLUENCE_RADIUS);
//delete this creature
creatureUnloadList.push_back(creatureIt.first);
}
}
//actually unload these creatures
for (auto& it : creatureUnloadList) {
CreatureData* creatureData = creatureMgr.Find(it);
CreaturePacket creaturePacket;
creaturePacket.type = SerialPacketType::CREATURE_UNLOAD;
copyCreatureToPacket(&creaturePacket, creatureData, it);
pumpPacketProximity(reinterpret_cast<SerialPacket*>(&creaturePacket), roomIndex, creatureData->GetOrigin(), INFLUENCE_RADIUS);
creatureMgr.Unload(it);
}
}
//send the creature updates
for (auto& it : creatureList) {
CreaturePacket packet;
copyCreatureToPacket(&packet, it.second, it.first);
packet.type = SerialPacketType::CREATURE_UPDATE;
packet.roomIndex = roomIndex;
pumpPacketProximity(reinterpret_cast<SerialPacket*>(&packet), roomIndex, it.second->GetOrigin(), INFLUENCE_RADIUS);
}
//send the barrier updates
for (auto& it : barrierList) {
BarrierPacket packet;
copyBarrierToPacket(&packet, it.second, it.first);
packet.type = SerialPacketType::BARRIER_UPDATE;
packet.roomIndex = roomIndex;
pumpPacketProximity(reinterpret_cast<SerialPacket*>(&packet), roomIndex, it.second->GetOrigin(), INFLUENCE_RADIUS);
}
}
std::string RoomData::SetName(std::string s) {
@@ -211,12 +178,4 @@ 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];
}
+1 -5
View File
@@ -70,9 +70,6 @@ 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;
@@ -82,7 +79,7 @@ private:
int roomIndex = 0;
BarrierManager barrierMgr;
std::list<CharacterData*> characterList;
CombatInstanceManager CombatInstanceMgr;
CombatInstanceManager combatInstanceMgr;
CreatureManager creatureMgr;
RegionPagerLua pager;
TriggerManager triggerMgr;
@@ -93,5 +90,4 @@ private:
//hooks
int tickRef = LUA_NOREF;
std::map<std::string, std::string> tags;
};