Barriers are created in client-side BarrierManager
Still need to hookup a barrier query, and get them drawn to the screen.
This commit is contained in:
@@ -0,0 +1,81 @@
|
|||||||
|
/* 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 "barrier_manager.hpp"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
void BarrierManager::DrawTo(SDL_Renderer* const dest, Sint16 x, Sint16 y, double scaleX, double scaleY) {
|
||||||
|
for (auto& it : barrierMap) {
|
||||||
|
it.second.DrawTo(dest, x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BarrierManager::LoadBaseImage(SDL_Renderer* renderer, std::string fname) {
|
||||||
|
baseImage.Load(renderer, fname);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BarrierManager::UnloadBaseImage() {
|
||||||
|
baseImage.Free();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BarrierManager::LoadTemplateImages(SDL_Renderer* renderer, std::list<std::string> names) {
|
||||||
|
for (auto& it : names) {
|
||||||
|
//TODO: check the state of the local flag
|
||||||
|
templateImages.emplace(it, Image(renderer, it));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BarrierManager::UnloadTemplateImages() {
|
||||||
|
templateImages.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseBarrier* BarrierManager::Create(int index) {
|
||||||
|
barrierMap.emplace( index, BaseBarrier(baseImage, templateImages) );
|
||||||
|
|
||||||
|
//DEBUG: debugging
|
||||||
|
return &barrierMap[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
void BarrierManager::Unload(int i) {
|
||||||
|
barrierMap.erase(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BarrierManager::UnloadAll() {
|
||||||
|
barrierMap.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
int BarrierManager::Size() {
|
||||||
|
return barrierMap.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseBarrier* BarrierManager::Find(int i) {
|
||||||
|
std::map<int, BaseBarrier>::iterator it = barrierMap.find(i);
|
||||||
|
|
||||||
|
if (it == barrierMap.end()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return &it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<int, BaseBarrier>* BarrierManager::GetContainer() {
|
||||||
|
return &barrierMap;
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
/* 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 "base_barrier.hpp"
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class BarrierManager {
|
||||||
|
public:
|
||||||
|
BarrierManager() = default;
|
||||||
|
~BarrierManager() = default;
|
||||||
|
|
||||||
|
void DrawTo(SDL_Renderer* const, Sint16 x, Sint16 y, double scaleX = 1.0, double scaleY = 1.0);
|
||||||
|
|
||||||
|
//NOTE: don't use these while you have barriers loaded
|
||||||
|
void LoadBaseImage(SDL_Renderer* renderer, std::string fname);
|
||||||
|
void UnloadBaseImage();
|
||||||
|
void LoadTemplateImages(SDL_Renderer* renderer, std::list<std::string> names);
|
||||||
|
void UnloadTemplateImages();
|
||||||
|
|
||||||
|
BaseBarrier* Create(int index);
|
||||||
|
void Unload(int i);
|
||||||
|
void UnloadAll();
|
||||||
|
|
||||||
|
int Size();
|
||||||
|
|
||||||
|
BaseBarrier* Find(int i);
|
||||||
|
std::map<int, BaseBarrier>* GetContainer();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Image baseImage;
|
||||||
|
std::map<std::string, Image> templateImages;
|
||||||
|
std::map<int, BaseBarrier> barrierMap;
|
||||||
|
};
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
BaseBarrier::BaseBarrier(Image argBaseImage, std::map<std::string, Image>& templateImages) {
|
BaseBarrier::BaseBarrier(Image& argBaseImage, std::map<std::string, Image>& templateImages) {
|
||||||
baseImage = argBaseImage;
|
baseImage = argBaseImage;
|
||||||
composite.SetImageTextures(templateImages);
|
composite.SetImageTextures(templateImages);
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ BaseBarrier::~BaseBarrier() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BaseBarrier::CorrectSprite() {
|
void BaseBarrier::CorrectSprite() {
|
||||||
//TODO: link status to sprite
|
//TODO: (0) link status to sprite
|
||||||
}
|
}
|
||||||
|
|
||||||
int BaseBarrier::SetStatus(int k, int v) {
|
int BaseBarrier::SetStatus(int k, int v) {
|
||||||
|
|||||||
@@ -27,8 +27,8 @@
|
|||||||
|
|
||||||
class BaseBarrier: public Entity {
|
class BaseBarrier: public Entity {
|
||||||
public:
|
public:
|
||||||
BaseBarrier() = delete;
|
BaseBarrier() = default;
|
||||||
BaseBarrier(Image baseImage, std::map<std::string, Image>& templateImages);
|
BaseBarrier(Image& baseImage, std::map<std::string, Image>& templateImages);
|
||||||
virtual ~BaseBarrier();
|
virtual ~BaseBarrier();
|
||||||
|
|
||||||
void CorrectSprite();
|
void CorrectSprite();
|
||||||
|
|||||||
+48
-29
@@ -98,7 +98,18 @@ World::World(int* const argClientIndex, int* const argAccountIndex):
|
|||||||
SDL_RenderGetLogicalSize(GetRenderer(), &camera.width, &camera.height);
|
SDL_RenderGetLogicalSize(GetRenderer(), &camera.width, &camera.height);
|
||||||
|
|
||||||
//debug
|
//debug
|
||||||
//
|
barrierMgr.LoadTemplateImages(GetRenderer(),
|
||||||
|
std::list<std::string>{
|
||||||
|
config["dir.sprites"] + "/barrier/slot 1 green.png",
|
||||||
|
config["dir.sprites"] + "/barrier/slot 2 green.png",
|
||||||
|
config["dir.sprites"] + "/barrier/slot 3 green.png",
|
||||||
|
config["dir.sprites"] + "/barrier/slot 4 green.png",
|
||||||
|
config["dir.sprites"] + "/barrier/slot 5 green.png",
|
||||||
|
config["dir.sprites"] + "/barrier/slot 6 green.png",
|
||||||
|
config["dir.sprites"] + "/barrier/slot 7 green.png",
|
||||||
|
config["dir.sprites"] + "/barrier/slot 8 green.png"
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
World::~World() {
|
World::~World() {
|
||||||
@@ -175,6 +186,8 @@ void World::Update() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: cull barriers
|
||||||
|
|
||||||
//get the collidable boxes
|
//get the collidable boxes
|
||||||
std::list<BoundingBox> boxList = GenerateCollisionGrid(localCharacter, tileSheet.GetTileW(), tileSheet.GetTileH());
|
std::list<BoundingBox> boxList = GenerateCollisionGrid(localCharacter, tileSheet.GetTileW(), tileSheet.GetTileH());
|
||||||
|
|
||||||
@@ -751,7 +764,7 @@ void World::hCharacterUnload(CharacterPacket* const argPacket) {
|
|||||||
//clear/reset the room
|
//clear/reset the room
|
||||||
roomIndex = -1;
|
roomIndex = -1;
|
||||||
regionPager.UnloadAll();
|
regionPager.UnloadAll();
|
||||||
barrierMap.clear();
|
barrierMgr.UnloadAll();
|
||||||
characterMap.clear();
|
characterMap.clear();
|
||||||
creatureMap.clear();
|
creatureMap.clear();
|
||||||
}
|
}
|
||||||
@@ -930,26 +943,24 @@ void World::hBarrierUpdate(BarrierPacket* const argPacket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//check if this barrier exists
|
//check if this barrier exists
|
||||||
std::map<int, BaseBarrier>::iterator barrierIt = barrierMap.find(argPacket->barrierIndex);
|
BaseBarrier* barrier = barrierMgr.Find(argPacket->barrierIndex);
|
||||||
if (barrierIt != barrierMap.end()) {
|
|
||||||
//update the origin and motion, if there's a difference
|
if (!barrier) {
|
||||||
if (barrierIt->second.GetOrigin() != argPacket->origin) {
|
|
||||||
barrierIt->second.SetOrigin(argPacket->origin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
hBarrierCreate(argPacket);
|
hBarrierCreate(argPacket);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//update the origin and motion, if there's a difference
|
||||||
|
if (barrier->GetOrigin() != argPacket->origin) {
|
||||||
|
barrier->SetOrigin(argPacket->origin);
|
||||||
|
}
|
||||||
|
barrier->SetStatusArray(argPacket->status);
|
||||||
|
barrier->CorrectSprite();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::hBarrierCreate(BarrierPacket* const argPacket) {
|
void World::hBarrierCreate(BarrierPacket* const argPacket) {
|
||||||
//check for logic errors
|
//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
|
//ignore barriers from other rooms
|
||||||
if (roomIndex != argPacket->roomIndex) {
|
if (roomIndex != argPacket->roomIndex) {
|
||||||
@@ -960,30 +971,33 @@ void World::hBarrierCreate(BarrierPacket* const argPacket) {
|
|||||||
throw(std::runtime_error(msg.str()));
|
throw(std::runtime_error(msg.str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
//implicitly create the element
|
BaseBarrier* barrier = barrierMgr.Find(argPacket->barrierIndex);
|
||||||
BaseBarrier* barrier = &barrierMap[argPacket->barrierIndex];
|
|
||||||
|
if (barrier) {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Double barrier creation event; ";
|
||||||
|
msg << "Index: " << argPacket->barrierIndex;
|
||||||
|
throw(std::runtime_error(msg.str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
barrier = barrierMgr.Create(argPacket->barrierIndex);
|
||||||
|
|
||||||
//fill the barrier's info
|
//fill the barrier's info
|
||||||
barrier->SetBounds(argPacket->bounds);
|
barrier->SetBounds(argPacket->bounds);
|
||||||
barrier->SetOrigin(argPacket->origin);
|
barrier->SetOrigin(argPacket->origin);
|
||||||
barrier->SetStatusArray(argPacket->status);
|
barrier->SetStatusArray(argPacket->status);
|
||||||
|
barrier->CorrectSprite();
|
||||||
|
|
||||||
//debug
|
//debug
|
||||||
std::cout << "Barrier Create, total: " << barrierMap.size() << std::endl;
|
std::cout << "Barrier Create, total: " << barrierMgr.Size() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::hBarrierUnload(BarrierPacket* const argPacket) {
|
void World::hBarrierUnload(BarrierPacket* const argPacket) {
|
||||||
//ignore if this barrier doesn't exist
|
//ignore if this barrier doesn't exist
|
||||||
std::map<int, BaseBarrier>::iterator barrierIt = barrierMap.find(argPacket->barrierIndex);
|
barrierMgr.Unload(argPacket->barrierIndex);
|
||||||
if (barrierIt == barrierMap.end()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//remove this barrier
|
|
||||||
barrierMap.erase(barrierIt);
|
|
||||||
|
|
||||||
//debug
|
//debug
|
||||||
std::cout << "Barrier Unload, total: " << barrierMap.size() << std::endl;
|
std::cout << "Barrier Unload, total: " << barrierMgr.Size() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::hQueryBarrierExists(BarrierPacket* const argPacket) {
|
void World::hQueryBarrierExists(BarrierPacket* const argPacket) {
|
||||||
@@ -995,15 +1009,20 @@ void World::hQueryBarrierExists(BarrierPacket* const argPacket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//implicitly create the element
|
//implicitly create the element
|
||||||
BaseBarrier* barrier = &barrierMap[argPacket->barrierIndex];
|
BaseBarrier* barrier = barrierMgr.Find(argPacket->barrierIndex);
|
||||||
|
|
||||||
|
if (!barrier) {
|
||||||
|
barrier = barrierMgr.Create(argPacket->barrierIndex);
|
||||||
|
}
|
||||||
|
|
||||||
//fill the barrier's info
|
//fill the barrier's info
|
||||||
barrier->SetBounds(argPacket->bounds);
|
barrier->SetBounds(argPacket->bounds);
|
||||||
barrier->SetOrigin(argPacket->origin);
|
barrier->SetOrigin(argPacket->origin);
|
||||||
barrier->SetStatusArray(argPacket->status);
|
barrier->SetStatusArray(argPacket->status);
|
||||||
|
barrier->CorrectSprite();
|
||||||
|
|
||||||
//debug
|
//debug
|
||||||
std::cout << "Barrier Query, total: " << barrierMap.size() << std::endl;
|
std::cout << "Barrier Query, total: " << barrierMgr.Size() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
#include "frame_rate.hpp"
|
#include "frame_rate.hpp"
|
||||||
|
|
||||||
//client
|
//client
|
||||||
|
#include "barrier_manager.hpp"
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
#include "base_barrier.hpp"
|
#include "base_barrier.hpp"
|
||||||
#include "base_creature.hpp"
|
#include "base_creature.hpp"
|
||||||
@@ -158,7 +159,7 @@ private:
|
|||||||
} camera;
|
} camera;
|
||||||
|
|
||||||
//entities
|
//entities
|
||||||
std::map<int, BaseBarrier> barrierMap;
|
BarrierManager barrierMgr;
|
||||||
std::map<int, BaseCharacter> characterMap;
|
std::map<int, BaseCharacter> characterMap;
|
||||||
std::map<int, BaseCreature> creatureMap;
|
std::map<int, BaseCreature> creatureMap;
|
||||||
LocalCharacter* localCharacter = nullptr;
|
LocalCharacter* localCharacter = nullptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user