Threaded barriers into the client, not yet queried

I've also refactored the rooms slightly.
This commit is contained in:
2016-04-04 01:05:32 +10:00
parent 7b9c016082
commit 7205d6692c
12 changed files with 280 additions and 58 deletions
+4
View File
@@ -318,6 +318,7 @@ void ClientApplication::ProcessEvents() {
#include "options_menu.hpp"
#include "lobby_menu.hpp"
#include "world.hpp"
#include "combat.hpp"
#include "disconnected_screen.hpp"
void ClientApplication::ProcessSceneSignal(SceneSignal signal) {
@@ -341,6 +342,9 @@ void ClientApplication::ProcessSceneSignal(SceneSignal signal) {
case SceneSignal::WORLD:
activeScene = new World(&clientIndex, &accountIndex);
break;
case SceneSignal::COMBAT:
activeScene = new Combat(&clientIndex, &accountIndex);
break;
case SceneSignal::DISCONNECTEDSCREEN:
activeScene = new DisconnectedScreen();
break;
+53
View File
@@ -0,0 +1,53 @@
/* Copyright: (c) Kayne Ruse 2013-2016
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "base_barrier.hpp"
#include "config_utility.hpp"
#include <cstring>
void BaseBarrier::CorrectSprite() {
//TODO: (9) BaseBarrier::CorrectSprite()
}
int BaseBarrier::SetStatus(int k, int v) {
if (k >= 8 || k < 0) {
return -1;
}
return status[k] = v;
}
int BaseBarrier::FindStatus(int k) {
if (k >= 8 || k < 0) {
return -1;
}
return status[k];
}
int* BaseBarrier::SetStatusArray(int* ptr) {
memcpy(status, ptr, sizeof(int) * 8);
return status;
}
int* BaseBarrier::GetStatusArray() {
return status;
}
+43
View File
@@ -0,0 +1,43 @@
/* Copyright: (c) Kayne Ruse 2013-2016
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#pragma once
#include "entity.hpp"
class BaseBarrier: public Entity {
public:
BaseBarrier() = default;
virtual ~BaseBarrier() = default;
void CorrectSprite();
int SetStatus(int, int);
int FindStatus(int);
int* SetStatusArray(int*);
int* GetStatusArray();
protected:
//metadata
int status[8];
};
+104 -2
View File
@@ -424,6 +424,22 @@ void World::HandlePacket(SerialPacket* const argPacket) {
hCreatureMovement(static_cast<CreaturePacket*>(argPacket));
break;
//barrier management
case SerialPacketType::BARRIER_UPDATE:
hBarrierUpdate(static_cast<BarrierPacket*>(argPacket));
break;
case SerialPacketType::BARRIER_CREATE:
hBarrierCreate(static_cast<BarrierPacket*>(argPacket));
break;
case SerialPacketType::BARRIER_UNLOAD:
hBarrierUnload(static_cast<BarrierPacket*>(argPacket));
break;
case SerialPacketType::QUERY_BARRIER_EXISTS:
hQueryBarrierExists(static_cast<BarrierPacket*>(argPacket));
break;
//chat
case SerialPacketType::TEXT_BROADCAST:
hTextBroadcast(static_cast<TextPacket*>(argPacket));
@@ -797,8 +813,6 @@ void World::hCreatureUpdate(CreaturePacket* const argPacket) {
return;
}
std::cout << "hCreatureUpdate" << std::endl;
//check if this creature exists
std::map<int, BaseCreature>::iterator creatureIt = creatureMap.find(argPacket->creatureIndex);
if (creatureIt != creatureMap.end()) {
@@ -898,6 +912,94 @@ void World::hCreatureMovement(CreaturePacket* const argPacket) {
creatureIt->second.SetMotion(argPacket->motion);
}
//-------------------------
//barrier management
//-------------------------
void World::hBarrierUpdate(BarrierPacket* const argPacket) {
//Cull barriers that are too far away
if ( (localCharacter->GetOrigin() - argPacket->origin).Length() > INFLUENCE_RADIUS) {
//ignore beyond 1000 units
return;
}
//check if this barrier exists
std::map<int, BaseBarrier>::iterator barrierIt = barrierMap.find(argPacket->barrierIndex);
if (barrierIt != barrierMap.end()) {
//update the origin and motion, if there's a difference
if (barrierIt->second.GetOrigin() != argPacket->origin) {
barrierIt->second.SetOrigin(argPacket->origin);
}
}
else {
hBarrierCreate(argPacket);
}
}
void World::hBarrierCreate(BarrierPacket* const argPacket) {
//check for logic errors
if (barrierMap.find(argPacket->barrierIndex) != barrierMap.end()) {
std::ostringstream msg;
msg << "Double barrier creation event; ";
msg << "Index: " << argPacket->barrierIndex;
throw(std::runtime_error(msg.str()));
}
//ignore barriers from other rooms
if (roomIndex != argPacket->roomIndex) {
//temporary error checking
std::ostringstream msg;
msg << "Barrier from the wrong room received: ";
msg << "barrierIndex: " << argPacket->barrierIndex << ", roomIndex: " << argPacket->roomIndex;
throw(std::runtime_error(msg.str()));
}
//implicitly create the element
BaseBarrier* barrier = &barrierMap[argPacket->barrierIndex];
//fill the barrier's info
barrier->SetBounds(argPacket->bounds);
barrier->SetOrigin(argPacket->origin);
barrier->SetStatusArray(argPacket->status);
//debug
std::cout << "Barrier Create, total: " << barrierMap.size() << std::endl;
}
void World::hBarrierUnload(BarrierPacket* const argPacket) {
//ignore if this barrier doesn't exist
std::map<int, BaseBarrier>::iterator barrierIt = barrierMap.find(argPacket->barrierIndex);
if (barrierIt == barrierMap.end()) {
return;
}
//remove this barrier
barrierMap.erase(barrierIt);
//debug
std::cout << "Barrier Unload, total: " << barrierMap.size() << std::endl;
}
void World::hQueryBarrierExists(BarrierPacket* const argPacket) {
std::cout << "Barrier Query" << std::endl;
//ignore barriers in a different room (sub-optimal)
if (argPacket->roomIndex != roomIndex) {
return;
}
//implicitly create the element
BaseBarrier* barrier = &barrierMap[argPacket->barrierIndex];
//fill the barrier's info
barrier->SetBounds(argPacket->bounds);
barrier->SetOrigin(argPacket->origin);
barrier->SetStatusArray(argPacket->status);
//debug
std::cout << "Barrier Query, total: " << barrierMap.size() << std::endl;
}
//-------------------------
//chat
//-------------------------
+8
View File
@@ -40,6 +40,7 @@
//client
#include "base_scene.hpp"
#include "base_barrier.hpp"
#include "base_creature.hpp"
#include "local_character.hpp"
@@ -113,6 +114,12 @@ private:
void hQueryCreatureExists(CreaturePacket* const);
void hCreatureMovement(CreaturePacket* const);
//barrier management
void hBarrierUpdate(BarrierPacket* const);
void hBarrierCreate(BarrierPacket* const);
void hBarrierUnload(BarrierPacket* const);
void hQueryBarrierExists(BarrierPacket* const);
//chat
//TODO: ui chat engine
void hTextBroadcast(TextPacket* const);
@@ -151,6 +158,7 @@ private:
} camera;
//entities
std::map<int, BaseBarrier> barrierMap;
std::map<int, BaseCharacter> characterMap;
std::map<int, BaseCreature> creatureMap;
LocalCharacter* localCharacter = nullptr;