Discovered I need to do something
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
//-------------------------
|
||||
|
||||
@@ -70,13 +70,13 @@ void serializePacket(void* buffer, SerialPacketBase* packet) {
|
||||
serializeCreature(buffer, static_cast<CreaturePacket*>(packet));
|
||||
}
|
||||
|
||||
if (BOUNDS(packet->type, SerialPacketType::FORMAT_COMBAT, SerialPacketType::FORMAT_END_COMBAT)) {
|
||||
serializeBarrier(buffer, static_cast<BarrierPacket*>(packet));
|
||||
}
|
||||
|
||||
if (BOUNDS(packet->type, SerialPacketType::FORMAT_TEXT, SerialPacketType::FORMAT_END_TEXT)) {
|
||||
serializeText(buffer, static_cast<TextPacket*>(packet));
|
||||
}
|
||||
|
||||
if (BOUNDS(packet->type, SerialPacketType::FORMAT_BARRIER, SerialPacketType::FORMAT_END_BARRIER)) {
|
||||
serializeBarrier(buffer, static_cast<BarrierPacket*>(packet));
|
||||
}
|
||||
}
|
||||
|
||||
void deserializePacket(void* buffer, SerialPacketBase* packet) {
|
||||
@@ -104,11 +104,11 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) {
|
||||
deserializeCreature(buffer, static_cast<CreaturePacket*>(packet));
|
||||
}
|
||||
|
||||
if (BOUNDS(type, SerialPacketType::FORMAT_COMBAT, SerialPacketType::FORMAT_END_COMBAT)) {
|
||||
deserializeBarrier(buffer, static_cast<BarrierPacket*>(packet));
|
||||
}
|
||||
|
||||
if (BOUNDS(type, SerialPacketType::FORMAT_TEXT, SerialPacketType::FORMAT_END_TEXT)) {
|
||||
deserializeText(buffer, static_cast<TextPacket*>(packet));
|
||||
}
|
||||
|
||||
if (BOUNDS(type, SerialPacketType::FORMAT_BARRIER, SerialPacketType::FORMAT_END_BARRIER)) {
|
||||
deserializeBarrier(buffer, static_cast<BarrierPacket*>(packet));
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
//
|
||||
}
|
||||
@@ -26,10 +26,10 @@
|
||||
|
||||
#include <functional>
|
||||
|
||||
class Battle {
|
||||
class BattleData {
|
||||
public:
|
||||
Battle();
|
||||
~Battle();
|
||||
BattleData();
|
||||
~BattleData();
|
||||
|
||||
void Update();
|
||||
|
||||
@@ -38,7 +38,7 @@ void BattleManager::Update() {
|
||||
|
||||
int BattleManager::Create() {
|
||||
//implicitly create the new object
|
||||
elementMap.emplace( std::pair<int, Battle>(counter, Battle()) );
|
||||
elementMap.emplace( std::pair<int, BattleData>(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<bool(std::pair<const int, Battle const&>)> fn) {
|
||||
std::map<int, Battle>::iterator it = elementMap.begin();
|
||||
void BattleManager::UnloadIf(std::function<bool(std::pair<const int, BattleData const&>)> fn) {
|
||||
std::map<int, BattleData>::iterator it = elementMap.begin();
|
||||
while (it != elementMap.end()) {
|
||||
if (fn(*it)) {
|
||||
it = elementMap.erase(it);
|
||||
@@ -66,8 +66,8 @@ void BattleManager::UnloadIf(std::function<bool(std::pair<const int, Battle cons
|
||||
}
|
||||
}
|
||||
|
||||
Battle* BattleManager::Find(int uid) {
|
||||
std::map<int, Battle>::iterator it = elementMap.find(uid);
|
||||
BattleData* BattleManager::Find(int uid) {
|
||||
std::map<int, BattleData>::iterator it = elementMap.find(uid);
|
||||
|
||||
if (it == elementMap.end()) {
|
||||
return nullptr;
|
||||
@@ -80,7 +80,7 @@ int BattleManager::GetLoadedCount() {
|
||||
return elementMap.size();
|
||||
}
|
||||
|
||||
std::map<int, Battle>* BattleManager::GetContainer() {
|
||||
std::map<int, BattleData>* BattleManager::GetContainer() {
|
||||
return &elementMap;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<bool(std::pair<const int, Battle const&>)> fn);
|
||||
void UnloadIf(std::function<bool(std::pair<const int, BattleData const&>)> fn);
|
||||
|
||||
//accessors & mutators
|
||||
Battle* Find(int uid);
|
||||
BattleData* Find(int uid);
|
||||
int GetLoadedCount();
|
||||
std::map<int, Battle>* GetContainer();
|
||||
std::map<int, BattleData>* GetContainer();
|
||||
|
||||
//hooks
|
||||
lua_State* SetLuaState(lua_State* L);
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
|
||||
private:
|
||||
//members
|
||||
std::map<int, Battle> elementMap;
|
||||
std::map<int, BattleData> elementMap;
|
||||
int counter = 0;
|
||||
lua_State* lua = nullptr;
|
||||
sqlite3* database = nullptr;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user