Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ab6207d4f3 | |||
| 1267b30806 | |||
| 5d217d7cf9 |
@@ -740,16 +740,19 @@ void World::hCharacterCreate(CharacterPacket* const argPacket) {
|
|||||||
memset(&characterPacket, 0, MAX_PACKET_SIZE);
|
memset(&characterPacket, 0, MAX_PACKET_SIZE);
|
||||||
characterPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS;
|
characterPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS;
|
||||||
characterPacket.roomIndex = roomIndex;
|
characterPacket.roomIndex = roomIndex;
|
||||||
|
characterPacket.origin = localCharacter->GetOrigin();
|
||||||
network.SendTo(Channels::SERVER, &characterPacket);
|
network.SendTo(Channels::SERVER, &characterPacket);
|
||||||
|
|
||||||
CreaturePacket creaturePacket;
|
CreaturePacket creaturePacket;
|
||||||
creaturePacket.type = SerialPacketType::QUERY_CREATURE_EXISTS;
|
creaturePacket.type = SerialPacketType::QUERY_CREATURE_EXISTS;
|
||||||
creaturePacket.roomIndex = roomIndex;
|
creaturePacket.roomIndex = roomIndex;
|
||||||
|
creaturePacket.origin = localCharacter->GetOrigin();
|
||||||
network.SendTo(Channels::SERVER, &creaturePacket);
|
network.SendTo(Channels::SERVER, &creaturePacket);
|
||||||
|
|
||||||
BarrierPacket barrierPacket;
|
BarrierPacket barrierPacket;
|
||||||
barrierPacket.type = SerialPacketType::QUERY_BARRIER_EXISTS;
|
barrierPacket.type = SerialPacketType::QUERY_BARRIER_EXISTS;
|
||||||
barrierPacket.roomIndex = roomIndex;
|
barrierPacket.roomIndex = roomIndex;
|
||||||
|
barrierPacket.origin = localCharacter->GetOrigin();
|
||||||
network.SendTo(Channels::SERVER, &barrierPacket);
|
network.SendTo(Channels::SERVER, &barrierPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
#include "lua_utilities.hpp"
|
#include "lua_utilities.hpp"
|
||||||
|
|
||||||
|
#include "barrier_defines.hpp"
|
||||||
|
|
||||||
BarrierManager::BarrierManager() {
|
BarrierManager::BarrierManager() {
|
||||||
//EMPTY
|
//EMPTY
|
||||||
}
|
}
|
||||||
@@ -32,12 +34,57 @@ BarrierManager::~BarrierManager() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//arg: a list of barriers to be updated in the clients
|
//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(
|
||||||
int ret;
|
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) {
|
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) {
|
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) & 4) {
|
||||||
|
Unload(std::get<0>(it));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "barrier_data.hpp"
|
#include "barrier_data.hpp"
|
||||||
|
#include "character_data.hpp"
|
||||||
|
#include "creature_data.hpp"
|
||||||
|
|
||||||
#include "lua.hpp"
|
#include "lua.hpp"
|
||||||
#include "sqlite3.h"
|
#include "sqlite3.h"
|
||||||
@@ -29,6 +31,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
class BarrierManager {
|
class BarrierManager {
|
||||||
public:
|
public:
|
||||||
@@ -36,7 +39,12 @@ public:
|
|||||||
~BarrierManager();
|
~BarrierManager();
|
||||||
|
|
||||||
//common public methods
|
//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);
|
int Create(int instanceIndex);
|
||||||
void Unload(int uid);
|
void Unload(int uid);
|
||||||
|
|||||||
@@ -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 = collision detected
|
||||||
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;
|
||||||
|
|
||||||
|
|||||||
+41
-47
@@ -30,6 +30,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
//TODO: (9) character collisions should be preformed client-side
|
//TODO: (9) character collisions should be preformed client-side
|
||||||
void RoomData::RunFrame() {
|
void RoomData::RunFrame() {
|
||||||
@@ -48,15 +49,51 @@ void RoomData::RunFrame() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//lists of non-character entities that need updating client-side
|
//lists of non-character entities that need updating client-side
|
||||||
std::list<std::pair<const int, CreatureData*>> creatureList;
|
//types are index, ptr, action (0 = update, 1 = unload)
|
||||||
std::list<std::pair<const int, BarrierData*>> barrierList;
|
std::list<std::tuple<const int, CreatureData*, int>> creatureList;
|
||||||
|
std::list<std::tuple<const int, BarrierData*, int>> barrierList;
|
||||||
|
|
||||||
//update the entities in the room
|
//update the entities in the room
|
||||||
for (auto& it : characterList) {
|
for (auto& it : characterList) {
|
||||||
it->Update();
|
it->Update();
|
||||||
}
|
}
|
||||||
creatureMgr.Update(&creatureList);
|
creatureMgr.Update(&creatureList, &characterList);
|
||||||
barrierMgr.Update(&barrierList);
|
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
|
//build a list of entities for use with the triggers
|
||||||
std::stack<Entity*> entityStack;
|
std::stack<Entity*> entityStack;
|
||||||
@@ -66,49 +103,6 @@ void RoomData::RunFrame() {
|
|||||||
|
|
||||||
//Compare the triggers to the entities, using their real hitboxes
|
//Compare the triggers to the entities, using their real hitboxes
|
||||||
triggerMgr.Compare(entityStack);
|
triggerMgr.Compare(entityStack);
|
||||||
|
|
||||||
//Creature/character collisions, O(m*n)
|
|
||||||
for (auto characterIt : characterList) {
|
|
||||||
BoundingBox characterBox = characterIt->GetBounds() + characterIt->GetOrigin();
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//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) {
|
std::string RoomData::SetName(std::string s) {
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ private:
|
|||||||
int roomIndex = 0;
|
int roomIndex = 0;
|
||||||
BarrierManager barrierMgr;
|
BarrierManager barrierMgr;
|
||||||
std::list<CharacterData*> characterList;
|
std::list<CharacterData*> characterList;
|
||||||
CombatInstanceManager CombatInstanceMgr;
|
CombatInstanceManager combatInstanceMgr;
|
||||||
CreatureManager creatureMgr;
|
CreatureManager creatureMgr;
|
||||||
RegionPagerLua pager;
|
RegionPagerLua pager;
|
||||||
TriggerManager triggerMgr;
|
TriggerManager triggerMgr;
|
||||||
|
|||||||
Reference in New Issue
Block a user