Discovered I need to do something
This commit is contained in:
@@ -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