diff --git a/common/network/serial_packet.hpp b/common/network/serial_packet.hpp index ecf08cb..2f66e4b 100644 --- a/common/network/serial_packet.hpp +++ b/common/network/serial_packet.hpp @@ -34,15 +34,16 @@ typedef SerialPacketBase SerialPacket; //DOCS: NETWORK_VERSION is used to discern compatible servers and clients -constexpr int NETWORK_VERSION = 20160404; +constexpr int NETWORK_VERSION = 20160825; union MaxPacket { - CharacterPacket a; - ClientPacket b; - CreaturePacket c; - RegionPacket d; - ServerPacket e; - TextPacket f; + BarrierPacket a; + CharacterPacket b; + ClientPacket c; + CreaturePacket d; + RegionPacket e; + ServerPacket f; + TextPacket g; }; constexpr int MAX_PACKET_SIZE = sizeof(MaxPacket); diff --git a/common/network/serial_packet_type.hpp b/common/network/serial_packet_type.hpp index 69307a9..84929da 100644 --- a/common/network/serial_packet_type.hpp +++ b/common/network/serial_packet_type.hpp @@ -142,25 +142,6 @@ enum class SerialPacketType { FORMAT_END_CREATURE = 599, - //------------------------- - //BarrierPacket - // barrier index, - // bounds, - // roomIndex, origin, motion - // status - //------------------------- - - FORMAT_COMBAT = 700, - - BARRIER_UPDATE = 701, - - BARRIER_CREATE = 702, - BARRIER_UNLOAD = 703, - - QUERY_BARRIER_EXISTS = 704, - - FORMAT_END_COMBAT = 799, - //------------------------- //TextPacket // name, text @@ -184,6 +165,28 @@ enum class SerialPacketType { FORMAT_END_TEXT = 699, + //------------------------- + //BarrierPacket + // barrier index, + // bounds, + // roomIndex, origin, motion + // status + //------------------------- + + FORMAT_BARRIER = 700, + + BARRIER_UPDATE = 701, + + BARRIER_CREATE = 702, + BARRIER_UNLOAD = 703, + + QUERY_BARRIER_EXISTS = 704, + + BARRIER_ENTRY = 705, + BARRIER_EXIT = 706, + + FORMAT_END_BARRIER = 799, + //------------------------- //not used //------------------------- diff --git a/common/network/serial_utility.cpp b/common/network/serial_utility.cpp index 79a86c3..d473ddd 100644 --- a/common/network/serial_utility.cpp +++ b/common/network/serial_utility.cpp @@ -70,13 +70,13 @@ void serializePacket(void* buffer, SerialPacketBase* packet) { serializeCreature(buffer, static_cast(packet)); } - if (BOUNDS(packet->type, SerialPacketType::FORMAT_COMBAT, SerialPacketType::FORMAT_END_COMBAT)) { - serializeBarrier(buffer, static_cast(packet)); - } - if (BOUNDS(packet->type, SerialPacketType::FORMAT_TEXT, SerialPacketType::FORMAT_END_TEXT)) { serializeText(buffer, static_cast(packet)); } + + if (BOUNDS(packet->type, SerialPacketType::FORMAT_BARRIER, SerialPacketType::FORMAT_END_BARRIER)) { + serializeBarrier(buffer, static_cast(packet)); + } } void deserializePacket(void* buffer, SerialPacketBase* packet) { @@ -104,11 +104,11 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) { deserializeCreature(buffer, static_cast(packet)); } - if (BOUNDS(type, SerialPacketType::FORMAT_COMBAT, SerialPacketType::FORMAT_END_COMBAT)) { - deserializeBarrier(buffer, static_cast(packet)); - } - if (BOUNDS(type, SerialPacketType::FORMAT_TEXT, SerialPacketType::FORMAT_END_TEXT)) { deserializeText(buffer, static_cast(packet)); } + + if (BOUNDS(type, SerialPacketType::FORMAT_BARRIER, SerialPacketType::FORMAT_END_BARRIER)) { + deserializeBarrier(buffer, static_cast(packet)); + } } \ No newline at end of file diff --git a/server/battles/battle.cpp b/server/battles/battle_data.cpp similarity index 72% rename from server/battles/battle.cpp rename to server/battles/battle_data.cpp index 63cd2a7..ff9a2bb 100644 --- a/server/battles/battle.cpp +++ b/server/battles/battle_data.cpp @@ -19,33 +19,33 @@ * 3. This notice may not be removed or altered from any source * distribution. */ -#include "battle.hpp" +#include "battle_data.hpp" -Battle::Battle() { +BattleData::BattleData() { // } -Battle::~Battle() { +BattleData::~BattleData() { // } -void Battle::Update() { +void BattleData::Update() { // } //accessors and mutators -void Battle::PushCharacter(CharacterData* const characterData) { +void BattleData::PushCharacter(CharacterData* const characterData) { // } -void Battle::PopCharacter(CharacterData* const characterData) { +void BattleData::PopCharacter(CharacterData* const characterData) { // } -void Battle::PushCreature(CreatureData* const creatureData) { +void BattleData::PushCreature(CreatureData* const creatureData) { // } -void Battle::PopCreature(CreatureData* const creatureData) { +void BattleData::PopCreature(CreatureData* const creatureData) { // } diff --git a/server/battles/battle.hpp b/server/battles/battle_data.hpp similarity index 96% rename from server/battles/battle.hpp rename to server/battles/battle_data.hpp index 9061951..5493249 100644 --- a/server/battles/battle.hpp +++ b/server/battles/battle_data.hpp @@ -26,10 +26,10 @@ #include -class Battle { +class BattleData { public: - Battle(); - ~Battle(); + BattleData(); + ~BattleData(); void Update(); diff --git a/server/battles/battle_manager.cpp b/server/battles/battle_manager.cpp index eaf282e..69cc2a0 100644 --- a/server/battles/battle_manager.cpp +++ b/server/battles/battle_manager.cpp @@ -38,7 +38,7 @@ void BattleManager::Update() { int BattleManager::Create() { //implicitly create the new object - elementMap.emplace( std::pair(counter, Battle()) ); + elementMap.emplace( std::pair(counter, BattleData()) ); //TODO: do various things like saving to the database return counter++; @@ -54,8 +54,8 @@ void BattleManager::UnloadAll() { elementMap.clear(); } -void BattleManager::UnloadIf(std::function)> fn) { - std::map::iterator it = elementMap.begin(); +void BattleManager::UnloadIf(std::function)> fn) { + std::map::iterator it = elementMap.begin(); while (it != elementMap.end()) { if (fn(*it)) { it = elementMap.erase(it); @@ -66,8 +66,8 @@ void BattleManager::UnloadIf(std::function::iterator it = elementMap.find(uid); +BattleData* BattleManager::Find(int uid) { + std::map::iterator it = elementMap.find(uid); if (it == elementMap.end()) { return nullptr; @@ -80,7 +80,7 @@ int BattleManager::GetLoadedCount() { return elementMap.size(); } -std::map* BattleManager::GetContainer() { +std::map* BattleManager::GetContainer() { return &elementMap; } diff --git a/server/battles/battle_manager.hpp b/server/battles/battle_manager.hpp index 09faa59..dcf7010 100644 --- a/server/battles/battle_manager.hpp +++ b/server/battles/battle_manager.hpp @@ -21,7 +21,7 @@ */ #pragma once -#include "battle.hpp" +#include "battle_data.hpp" #include "lua.hpp" #include "sqlite3.h" @@ -41,12 +41,12 @@ public: void Unload(int uid); void UnloadAll(); - void UnloadIf(std::function)> fn); + void UnloadIf(std::function)> fn); //accessors & mutators - Battle* Find(int uid); + BattleData* Find(int uid); int GetLoadedCount(); - std::map* GetContainer(); + std::map* GetContainer(); //hooks lua_State* SetLuaState(lua_State* L); @@ -56,7 +56,7 @@ public: private: //members - std::map elementMap; + std::map elementMap; int counter = 0; lua_State* lua = nullptr; sqlite3* database = nullptr; diff --git a/server/rooms/room_data.cpp b/server/rooms/room_data.cpp index d552229..0c04514 100644 --- a/server/rooms/room_data.cpp +++ b/server/rooms/room_data.cpp @@ -160,6 +160,7 @@ void RoomData::RunFrameCharacterCreatureCollisions() { if (characterBox.CheckOverlap(creatureBox)) { //create the barrier and battle + //TODO: Barrier needs data about the creatures inside it. int barrierIndex = barrierMgr.Create(battleMgr.Create()); //link the barrier to a battle BarrierData* barrierData = barrierMgr.Find(barrierIndex); barrierData->SetRoomIndex(roomIndex); @@ -197,20 +198,32 @@ void RoomData::RunFrameCharacterCreatureCollisions() { void RoomData::RunFrameCharacterBarrierCollisions() { //TODO: check for character collisions with barriers, O(m*n) for (auto characterIt : characterList) { + //character bounds BoundingBox characterBox = characterIt->GetBounds() + characterIt->GetOrigin(); for (auto barrierIt : *barrierMgr.GetContainer()) { + //barrier bounds BoundingBox barrierBox = barrierIt.second.GetBounds() + barrierIt.second.GetOrigin(); if (characterBox.CheckOverlap(barrierBox)) { - //TODO: (0) actually move the character to a battle - Battle* battle = battleMgr.Find(barrierIt.second.GetBattleIndex()); + //Actually move the character to a battle + BattleData* battle = battleMgr.Find(barrierIt.second.GetBattleIndex()); +// battle->PushCharacter(characterIt.second); +// characterList. + //DEBUG: output barrierIndex, battleIndex std::cout << barrierIt.first << "\t" << barrierIt.second.GetBattleIndex() << std::endl; - //only confirm one barrier per character - break; + //Send the entry message to the client + BarrierPacket newPacket; + newPacket.type = SerialPacketType::BARRIER_ENTRY; + newPacket.barrierIndex = barrierIt.first; + +// udpNetworkUtility.Send(); + + //only confirm one barrier/character collison per frame + return; } } }