Discovered I need to do something

This commit is contained in:
2016-08-25 20:01:17 +10:00
parent 6d8d7963a1
commit 07218418a2
8 changed files with 77 additions and 60 deletions
+8 -7
View File
@@ -34,15 +34,16 @@
typedef SerialPacketBase SerialPacket; typedef SerialPacketBase SerialPacket;
//DOCS: NETWORK_VERSION is used to discern compatible servers and clients //DOCS: NETWORK_VERSION is used to discern compatible servers and clients
constexpr int NETWORK_VERSION = 20160404; constexpr int NETWORK_VERSION = 20160825;
union MaxPacket { union MaxPacket {
CharacterPacket a; BarrierPacket a;
ClientPacket b; CharacterPacket b;
CreaturePacket c; ClientPacket c;
RegionPacket d; CreaturePacket d;
ServerPacket e; RegionPacket e;
TextPacket f; ServerPacket f;
TextPacket g;
}; };
constexpr int MAX_PACKET_SIZE = sizeof(MaxPacket); constexpr int MAX_PACKET_SIZE = sizeof(MaxPacket);
+22 -19
View File
@@ -142,25 +142,6 @@ enum class SerialPacketType {
FORMAT_END_CREATURE = 599, 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 //TextPacket
// name, text // name, text
@@ -184,6 +165,28 @@ enum class SerialPacketType {
FORMAT_END_TEXT = 699, 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 //not used
//------------------------- //-------------------------
+8 -8
View File
@@ -70,13 +70,13 @@ void serializePacket(void* buffer, SerialPacketBase* packet) {
serializeCreature(buffer, static_cast<CreaturePacket*>(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)) { if (BOUNDS(packet->type, SerialPacketType::FORMAT_TEXT, SerialPacketType::FORMAT_END_TEXT)) {
serializeText(buffer, static_cast<TextPacket*>(packet)); 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) { void deserializePacket(void* buffer, SerialPacketBase* packet) {
@@ -104,11 +104,11 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) {
deserializeCreature(buffer, static_cast<CreaturePacket*>(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)) { if (BOUNDS(type, SerialPacketType::FORMAT_TEXT, SerialPacketType::FORMAT_END_TEXT)) {
deserializeText(buffer, static_cast<TextPacket*>(packet)); 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 * 3. This notice may not be removed or altered from any source
* distribution. * 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 //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> #include <functional>
class Battle { class BattleData {
public: public:
Battle(); BattleData();
~Battle(); ~BattleData();
void Update(); void Update();
+6 -6
View File
@@ -38,7 +38,7 @@ void BattleManager::Update() {
int BattleManager::Create() { int BattleManager::Create() {
//implicitly create the new object //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 //TODO: do various things like saving to the database
return counter++; return counter++;
@@ -54,8 +54,8 @@ void BattleManager::UnloadAll() {
elementMap.clear(); elementMap.clear();
} }
void BattleManager::UnloadIf(std::function<bool(std::pair<const int, Battle const&>)> fn) { void BattleManager::UnloadIf(std::function<bool(std::pair<const int, BattleData const&>)> fn) {
std::map<int, Battle>::iterator it = elementMap.begin(); std::map<int, BattleData>::iterator it = elementMap.begin();
while (it != elementMap.end()) { while (it != elementMap.end()) {
if (fn(*it)) { if (fn(*it)) {
it = elementMap.erase(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) { BattleData* BattleManager::Find(int uid) {
std::map<int, Battle>::iterator it = elementMap.find(uid); std::map<int, BattleData>::iterator it = elementMap.find(uid);
if (it == elementMap.end()) { if (it == elementMap.end()) {
return nullptr; return nullptr;
@@ -80,7 +80,7 @@ int BattleManager::GetLoadedCount() {
return elementMap.size(); return elementMap.size();
} }
std::map<int, Battle>* BattleManager::GetContainer() { std::map<int, BattleData>* BattleManager::GetContainer() {
return &elementMap; return &elementMap;
} }
+5 -5
View File
@@ -21,7 +21,7 @@
*/ */
#pragma once #pragma once
#include "battle.hpp" #include "battle_data.hpp"
#include "lua.hpp" #include "lua.hpp"
#include "sqlite3.h" #include "sqlite3.h"
@@ -41,12 +41,12 @@ public:
void Unload(int uid); void Unload(int uid);
void UnloadAll(); 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 //accessors & mutators
Battle* Find(int uid); BattleData* Find(int uid);
int GetLoadedCount(); int GetLoadedCount();
std::map<int, Battle>* GetContainer(); std::map<int, BattleData>* GetContainer();
//hooks //hooks
lua_State* SetLuaState(lua_State* L); lua_State* SetLuaState(lua_State* L);
@@ -56,7 +56,7 @@ public:
private: private:
//members //members
std::map<int, Battle> elementMap; std::map<int, BattleData> elementMap;
int counter = 0; int counter = 0;
lua_State* lua = nullptr; lua_State* lua = nullptr;
sqlite3* database = nullptr; sqlite3* database = nullptr;
+17 -4
View File
@@ -160,6 +160,7 @@ void RoomData::RunFrameCharacterCreatureCollisions() {
if (characterBox.CheckOverlap(creatureBox)) { if (characterBox.CheckOverlap(creatureBox)) {
//create the barrier and battle //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 int barrierIndex = barrierMgr.Create(battleMgr.Create()); //link the barrier to a battle
BarrierData* barrierData = barrierMgr.Find(barrierIndex); BarrierData* barrierData = barrierMgr.Find(barrierIndex);
barrierData->SetRoomIndex(roomIndex); barrierData->SetRoomIndex(roomIndex);
@@ -197,20 +198,32 @@ void RoomData::RunFrameCharacterCreatureCollisions() {
void RoomData::RunFrameCharacterBarrierCollisions() { void RoomData::RunFrameCharacterBarrierCollisions() {
//TODO: check for character collisions with barriers, O(m*n) //TODO: check for character collisions with barriers, O(m*n)
for (auto characterIt : characterList) { for (auto characterIt : characterList) {
//character bounds
BoundingBox characterBox = characterIt->GetBounds() + characterIt->GetOrigin(); BoundingBox characterBox = characterIt->GetBounds() + characterIt->GetOrigin();
for (auto barrierIt : *barrierMgr.GetContainer()) { for (auto barrierIt : *barrierMgr.GetContainer()) {
//barrier bounds
BoundingBox barrierBox = barrierIt.second.GetBounds() + barrierIt.second.GetOrigin(); BoundingBox barrierBox = barrierIt.second.GetBounds() + barrierIt.second.GetOrigin();
if (characterBox.CheckOverlap(barrierBox)) { if (characterBox.CheckOverlap(barrierBox)) {
//TODO: (0) actually move the character to a battle //Actually move the character to a battle
Battle* battle = battleMgr.Find(barrierIt.second.GetBattleIndex()); BattleData* battle = battleMgr.Find(barrierIt.second.GetBattleIndex());
// battle->PushCharacter(characterIt.second);
// characterList.
//DEBUG: output barrierIndex, battleIndex //DEBUG: output barrierIndex, battleIndex
std::cout << barrierIt.first << "\t" << barrierIt.second.GetBattleIndex() << std::endl; std::cout << barrierIt.first << "\t" << barrierIt.second.GetBattleIndex() << std::endl;
//only confirm one barrier per character //Send the entry message to the client
break; BarrierPacket newPacket;
newPacket.type = SerialPacketType::BARRIER_ENTRY;
newPacket.barrierIndex = barrierIt.first;
// udpNetworkUtility.Send();
//only confirm one barrier/character collison per frame
return;
} }
} }
} }