Compare commits

..

44 Commits

Author SHA1 Message Date
Kayne Ruse f9936f6107 Fixed bin directory 2016-04-15 00:22:53 +10:00
Kayne Ruse 905af46731 Adjusted file names for case sensitivity 2016-04-15 00:17:13 +10:00
Kayne Ruse 8b0bc76a9f Fixed a script 2016-04-14 23:42:11 +10:00
Kayne Ruse fb2d49f1e0 Added respawning rabbits 2016-04-14 23:33:39 +10:00
Kayne Ruse cc6981e35f Refined culling logic, added periodic query 2016-04-14 22:56:15 +10:00
Kayne Ruse f9a5f60969 Try a different approach for creature deletion
This works almost instantly, as opposed to the refactored version, which
takes nearly a second, or more.
2016-04-14 21:52:44 +10:00
Kayne Ruse b74a5aabcd Comment tweaks 2016-04-14 04:17:49 +10:00
Kayne Ruse 7c88392cf3 The server is updating the barrier display 2016-04-12 19:11:57 +10:00
Kayne Ruse 20b121766a Expanded creature & barrier API 2016-04-11 02:18:13 +10:00
Kayne Ruse f32b8a9b4f Exposed BarrierManager to the API* 2016-04-11 01:03:02 +10:00
Kayne Ruse ccb7adbd10 Fixed copying pointer to/from packet 2016-04-11 01:01:22 +10:00
Kayne Ruse 8e7af9ce88 Fixed the table inheritance which was backwards 2016-04-11 00:08:42 +10:00
Kayne Ruse 752f8f82f9 Unit tested CompositeImage, BaseBarrier::CorrectSprite working correctly 2016-04-10 00:12:27 +10:00
Kayne Ruse 1f2d0b8e76 Barriers are created at the correct location 2016-04-09 00:02:39 +10:00
Kayne Ruse ec409c8177 Reduced a graphical artifact, but it's still visible 2016-04-08 23:50:52 +10:00
Kayne Ruse 82d5a5c181 Moved BarrierManager 2016-04-08 23:32:41 +10:00
Kayne Ruse 420d39d467 Barriers are being drawn 2016-04-08 23:30:17 +10:00
Kayne Ruse e2e2e243d4 Server responds to barrier queries 2016-04-08 22:30:44 +10:00
Kayne Ruse 5d0f9e1bb8 Barriers are created in client-side BarrierManager
Still need to hookup a barrier query, and get them drawn to the screen.
2016-04-08 10:48:01 +10:00
Kayne Ruse d3f855c69b Wrote CompositeImage, added it to BaseBarrier 2016-04-05 23:40:31 +10:00
Kayne Ruse 8749d1fd93 Barriers are queried, created when colliding with creatures 2016-04-04 02:41:14 +10:00
Kayne Ruse 7205d6692c Threaded barriers into the client, not yet queried
I've also refactored the rooms slightly.
2016-04-04 01:05:32 +10:00
Kayne Ruse 7b9c016082 Threaded the barriers through the networking system 2016-04-03 22:32:39 +10:00
Kayne Ruse 235f3b57e0 Filled out some barrier stuff 2016-04-03 21:27:48 +10:00
Kayne Ruse f23b929f8a Added some boilerplate 2016-04-03 16:04:41 +10:00
Kayne Ruse 48b9a9b264 Added combat scene 2016-04-03 15:24:20 +10:00
Kayne Ruse d7196df760 Added some files for combat system 2016-04-03 02:44:09 +11:00
Kayne Ruse 957458d489 Renamed some of Get() methods to Find(), read more
From now on, ideally any function with "get" in the name should always
return a valid value. A function with "find" in the name, however, does
the same thing, but may also return an invalid result such as an error
code.
2016-04-03 02:17:02 +11:00
Kayne Ruse 3b24aae422 Added barrier graphics 2016-04-01 01:31:14 +11:00
Kayne Ruse a751531e18 Added distance based creature culling 2016-03-30 12:54:59 +11:00
Kayne Ruse 4794965166 The rabbit is moving on it's own 2016-03-29 20:19:13 +11:00
Kayne Ruse a532d33579 Bunnies are visible in all rooms 2016-03-29 16:29:30 +11:00
Kayne Ruse 8778bfdc4b Creatures are visible 2016-03-29 03:19:17 +11:00
Kayne Ruse 42b37be6f5 Creatures are nearly ready 2016-03-27 14:06:47 +11:00
Kayne Ruse cbf8538c24 Server is ready to send 2016-03-27 11:04:53 +11:00
Kayne Ruse 4ced27a905 Creatures update server-side 2016-03-27 09:53:24 +11:00
Kayne Ruse 57f92a8b2e Modified bunny sprite for proper use 2016-03-26 18:20:21 +11:00
Kayne Ruse a8bbbeabb7 Minor name tweak 2016-03-26 17:56:16 +11:00
Kayne Ruse e2f5494380 Testing the creatures via scripts
I need to find some way to ensure type safety of userdata.
2016-03-25 23:23:12 +11:00
Kayne Ruse 9a1714a881 Added creatures to the room containers 2016-03-25 22:29:26 +11:00
Kayne Ruse 18f119224a Updated the copyright in the scripts 2016-03-25 21:53:41 +11:00
Kayne Ruse ba384c182a Updated the copyright in the file headers 2016-03-22 13:40:26 +11:00
Kayne Ruse 3b90465afd Removed a debug trace statement 2016-03-22 08:15:17 +11:00
Kayne Ruse 284009baa7 Config tweaks for linux 2016-03-22 07:58:37 +11:00
202 changed files with 2953 additions and 374 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+5 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -318,6 +318,7 @@ void ClientApplication::ProcessEvents() {
#include "options_menu.hpp" #include "options_menu.hpp"
#include "lobby_menu.hpp" #include "lobby_menu.hpp"
#include "world.hpp" #include "world.hpp"
#include "combat.hpp"
#include "disconnected_screen.hpp" #include "disconnected_screen.hpp"
void ClientApplication::ProcessSceneSignal(SceneSignal signal) { void ClientApplication::ProcessSceneSignal(SceneSignal signal) {
@@ -341,6 +342,9 @@ void ClientApplication::ProcessSceneSignal(SceneSignal signal) {
case SceneSignal::WORLD: case SceneSignal::WORLD:
activeScene = new World(&clientIndex, &accountIndex); activeScene = new World(&clientIndex, &accountIndex);
break; break;
case SceneSignal::COMBAT:
activeScene = new Combat(&clientIndex, &accountIndex);
break;
case SceneSignal::DISCONNECTEDSCREEN: case SceneSignal::DISCONNECTEDSCREEN:
activeScene = new DisconnectedScreen(); activeScene = new DisconnectedScreen();
break; break;
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+145
View File
@@ -0,0 +1,145 @@
/* 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 "image.hpp"
#include <list>
#include <map>
#include <string>
template<typename T = class Image>
class CompositeImage {
public:
CompositeImage() = default;
~CompositeImage() = default;
void Load(SDL_Renderer* const, std::string spriteDir, std::list<std::string> nameList);
void SetTextures(std::map<std::string, Image>& templateImages);
void Free();
void DrawTo(SDL_Renderer* const, Sint16 x, Sint16 y, double scaleX = 1.0, double scaleY = 1.0);
//accessors & mutators
T* Find(std::string name);
bool Enable(std::string name);
bool Disable(std::string name);
void EnableAll();
void DisableAll();
std::map<std::string, std::pair<bool, T>>* GetTemplateImages();
private:
std::map<std::string, std::pair<bool, T>> imageMap;
};
template<typename T>
void CompositeImage<T>::Load(SDL_Renderer* const renderer, std::string spriteDir, std::list<std::string> nameList) {
for (auto& it : nameList) {
imageMap[it].first = true;
imageMap[it].second.Load(renderer, spriteDir + it);
}
}
template<typename T>
void CompositeImage<T>::SetTextures(std::map<std::string, Image>& templateImages) {
for (auto& it : templateImages) {
imageMap[it.first].first = true;
imageMap[it.first].second.SetTexture(it.second.GetTexture());
}
}
template<typename T>
void CompositeImage<T>::Free() {
imageMap.clear();
}
template<typename T>
void CompositeImage<T>::DrawTo(SDL_Renderer* const dest, Sint16 x, Sint16 y, double scaleX, double scaleY) {
//draw all members, regardless of internal ordering
for (auto& it : imageMap) {
if (it.second.first) {
it.second.second.DrawTo(dest, x, y, scaleX, scaleY);
}
}
}
//-------------------------
//accessors & mutators
//-------------------------
template<typename T>
T* CompositeImage<T>::Find(std::string name) {
auto it = imageMap.find(name);
if (it == imageMap.end()) {
return nullptr;
}
else {
return &it->second.second;
}
}
template<typename T>
bool CompositeImage<T>::Enable(std::string name) {
auto it = imageMap.find(name);
if (it == imageMap.end()) {
return false;
}
else {
imageMap[name].first = true;
return true;
}
}
template<typename T>
bool CompositeImage<T>::Disable(std::string name) {
auto it = imageMap.find(name);
if (it == imageMap.end()) {
return false;
}
else {
imageMap[name].first = false;
return true;
}
}
template<typename T>
void CompositeImage<T>::EnableAll() {
for (auto& it : imageMap) {
it.second.first = true;
}
}
template<typename T>
void CompositeImage<T>::DisableAll() {
for (auto& it : imageMap) {
it.second.first = false;
}
}
template<typename T>
std::map<std::string, std::pair<bool, T>>* CompositeImage<T>::GetTemplateImages() {
return &imageMap;
}
+94
View File
@@ -0,0 +1,94 @@
/* 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"
void BarrierManager::DrawTo(SDL_Renderer* const dest, Sint16 x, Sint16 y, double scaleX, double scaleY) {
for (auto& it : elementMap) {
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::string spriteDir, std::list<std::string> names) {
//sprite names are file names only
for (auto& it : names) {
templateImages.emplace(it, Image(renderer, spriteDir + it));
}
}
void BarrierManager::UnloadTemplateImages() {
templateImages.clear();
}
BaseBarrier* BarrierManager::Create(int index) {
elementMap.emplace(index, BaseBarrier(baseImage, templateImages));
return &elementMap[index];
}
void BarrierManager::Unload(int i) {
elementMap.erase(i);
}
void BarrierManager::UnloadAll() {
elementMap.clear();
}
void BarrierManager::UnloadIf(std::function<bool(std::pair<const int, BaseBarrier const&>)> fn) {
std::map<int, BaseBarrier>::iterator it = elementMap.begin();
while (it != elementMap.end()) {
if (fn(*it)) {
it = elementMap.erase(it);
}
else {
++it;
}
}
}
int BarrierManager::Size() {
return elementMap.size();
}
BaseBarrier* BarrierManager::Find(int i) {
std::map<int, BaseBarrier>::iterator it = elementMap.find(i);
if (it == elementMap.end()) {
return nullptr;
}
return &it->second;
}
std::map<int, BaseBarrier>* BarrierManager::GetContainer() {
return &elementMap;
}
std::map<std::string, Image>* BarrierManager::GetTemplateContainer() {
return &templateImages;
}
+57
View File
@@ -0,0 +1,57 @@
/* 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::string spriteDir, std::list<std::string> names);
void UnloadTemplateImages();
BaseBarrier* Create(int index);
void Unload(int i);
void UnloadAll();
void UnloadIf(std::function<bool(std::pair<const int, BaseBarrier const&>)> fn);
int Size();
BaseBarrier* Find(int i);
std::map<int, BaseBarrier>* GetContainer();
std::map<std::string, Image>* GetTemplateContainer();
private:
Image baseImage;
std::map<std::string, Image> templateImages;
std::map<int, BaseBarrier> elementMap;
};
+105
View File
@@ -0,0 +1,105 @@
/* 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>
#include <sstream>
#include <stdexcept>
BaseBarrier::BaseBarrier(Image& argBaseImage, std::map<std::string, Image>& templateImages) {
baseImage.SetTexture(argBaseImage.GetTexture());
composite.SetTextures(templateImages);
memset(status, 0, sizeof(int) * 8);
CorrectSprite();
}
BaseBarrier::~BaseBarrier() {
//
}
void BaseBarrier::CorrectSprite() {
//TODO: link status to sprite
for (int i = 0; i < 8; i++) {
//setup the name
std::ostringstream os;
os << "slot " << i+1;
switch(status[i]) {
case 0:
composite.Disable(os.str() + " green.png");
composite.Disable(os.str() + " red.png");
break;
case 1:
composite.Enable(os.str() + " green.png");
composite.Disable(os.str() + " red.png");
break;
case 2:
composite.Disable(os.str() + " green.png");
composite.Enable(os.str() + " red.png");
break;
default: {
std::ostringstream os;
os << "index " << i << ", value " << status[i] << std::endl;
throw(std::runtime_error("Unknown graphical status in barrier; " + os.str()));
}
}
}
}
void BaseBarrier::Update() {
//
}
void BaseBarrier::DrawTo(SDL_Renderer* const dest, int camX, int camY) {
//ignore the default sprite for now
baseImage.DrawTo(dest, origin.x - camX, origin.y - camY);
composite.DrawTo(dest, origin.x - camX, origin.y - camY);
}
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;
}
CompositeImage<>* BaseBarrier::GetComposite() {
return &composite;
}
+52
View File
@@ -0,0 +1,52 @@
/* 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"
#include "composite_image.hpp"
class BaseBarrier: public Entity {
public:
BaseBarrier() = default;
BaseBarrier(Image& baseImage, std::map<std::string, Image>& templateImages);
virtual ~BaseBarrier();
void CorrectSprite();
void Update();
void DrawTo(SDL_Renderer* const, int camX, int camY);
int SetStatus(int, int);
int FindStatus(int);
int* SetStatusArray(int*);
int* GetStatusArray();
CompositeImage<>* GetComposite();
protected:
//metadata
int status[8];
Image baseImage;
CompositeImage<> composite;
};
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -37,7 +37,7 @@ std::string BaseCreature::GetHandle() const {
std::string BaseCreature::SetAvatar(SDL_Renderer* const renderer, std::string s) { std::string BaseCreature::SetAvatar(SDL_Renderer* const renderer, std::string s) {
avatar = s; avatar = s;
sprite.Load(renderer, ConfigUtility::GetSingleton()["dir.sprites"] + avatar, 4, 1); sprite.Load(renderer, ConfigUtility::GetSingleton()["dir.sprites"] + avatar, 4, 4);
return avatar; return avatar;
} }
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+4 -4
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -50,14 +50,14 @@ BoundingBox Entity::SetBounds(BoundingBox b) {
return bounds = b; return bounds = b;
} }
Vector2 Entity::GetOrigin() { Vector2 Entity::GetOrigin() const {
return origin; return origin;
} }
Vector2 Entity::GetMotion() { Vector2 Entity::GetMotion() const {
return motion; return motion;
} }
BoundingBox Entity::GetBounds() { BoundingBox Entity::GetBounds() const {
return bounds; return bounds;
} }
+4 -4
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -39,9 +39,9 @@ public:
Vector2 SetMotion(Vector2 v); Vector2 SetMotion(Vector2 v);
BoundingBox SetBounds(BoundingBox b); BoundingBox SetBounds(BoundingBox b);
Vector2 GetOrigin(); Vector2 GetOrigin() const;
Vector2 GetMotion(); Vector2 GetMotion() const;
BoundingBox GetBounds(); BoundingBox GetBounds() const;
protected: protected:
Entity() = default; Entity() = default;
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+2 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -33,5 +33,6 @@ enum SceneSignal {
OPTIONSMENU, OPTIONSMENU,
LOBBYMENU, LOBBYMENU,
WORLD, WORLD,
COMBAT,
DISCONNECTEDSCREEN, DISCONNECTEDSCREEN,
}; };
+77
View File
@@ -0,0 +1,77 @@
/* 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 "combat.hpp"
//Public access members
Combat::Combat(int* const argClientIndex, int* const argAccountIndex) {
//
}
Combat::~Combat() {
//
}
void Combat::RenderFrame(SDL_Renderer* renderer) {
//
}
//frame phases
void Combat::FrameStart() {
//
}
void Combat::Update() {
//
}
void Combat::FrameEnd() {
//
}
//input events
void Combat::QuitEvent() {
//
}
void Combat::MouseMotion(SDL_MouseMotionEvent const& event) {
//
}
void Combat::MouseButtonDown(SDL_MouseButtonEvent const& event) {
//
}
void Combat::MouseButtonUp(SDL_MouseButtonEvent const& event) {
//
}
void Combat::MouseWheel(SDL_MouseWheelEvent const& event) {
//
}
void Combat::KeyDown(SDL_KeyboardEvent const& event) {
//
}
void Combat::KeyUp(SDL_KeyboardEvent const& event) {
//
}
+48
View File
@@ -0,0 +1,48 @@
/* 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_scene.hpp"
class Combat: public BaseScene {
public:
//Public access members
Combat(int* const argClientIndex, int* const argAccountIndex);
~Combat();
void RenderFrame(SDL_Renderer* renderer) override;
private:
//frame phases
void FrameStart() override;
void Update() override;
void FrameEnd() override;
//input events
void QuitEvent();
void MouseMotion(SDL_MouseMotionEvent const& event) override;
void MouseButtonDown(SDL_MouseButtonEvent const& event) override;
void MouseButtonUp(SDL_MouseButtonEvent const& event) override;
void MouseWheel(SDL_MouseWheelEvent const& event) override;
void KeyDown(SDL_KeyboardEvent const& event) override;
void KeyUp(SDL_KeyboardEvent const& event) override;
};
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+237 -34
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -22,6 +22,7 @@
#include "world.hpp" #include "world.hpp"
#include "channels.hpp" #include "channels.hpp"
#include "culling_defines.hpp"
#include "ip_operators.hpp" #include "ip_operators.hpp"
#include "fatal_error.hpp" #include "fatal_error.hpp"
@@ -38,12 +39,12 @@
//------------------------- //-------------------------
//TODO: (3) proper checksum //TODO: (3) proper checksum
static int regionChecksum(Region* const region) { static int regionContentCheck(Region const* region) {
int sum = 0; int sum = 0;
for(int i = 0; i < REGION_WIDTH; i++) { for(int i = 0; i < REGION_WIDTH; i++) {
for (int j = 0; j < REGION_HEIGHT; j++) { for (int j = 0; j < REGION_HEIGHT; j++) {
for (int k = 0; k < REGION_DEPTH; k++) { for (int k = 0; k < REGION_DEPTH; k++) {
sum |= region->GetTile(i, j, k); sum += region->GetTile(i, j, k);
} }
} }
} }
@@ -97,7 +98,28 @@ World::World(int* const argClientIndex, int* const argAccountIndex):
SDL_RenderGetLogicalSize(GetRenderer(), &camera.width, &camera.height); SDL_RenderGetLogicalSize(GetRenderer(), &camera.width, &camera.height);
//debug //debug
// std::list<std::string> slotNames = {
"slot 1 green.png",
"slot 2 green.png",
"slot 3 green.png",
"slot 4 green.png",
"slot 5 green.png",
"slot 6 green.png",
"slot 7 green.png",
"slot 8 green.png",
"slot 1 red.png",
"slot 2 red.png",
"slot 3 red.png",
"slot 4 red.png",
"slot 5 red.png",
"slot 6 red.png",
"slot 7 red.png",
"slot 8 red.png"
};
barrierMgr.LoadBaseImage(GetRenderer(), config["dir.sprites"] + "barrier/base.png");
barrierMgr.LoadTemplateImages(GetRenderer(), config["dir.sprites"] + "barrier/", slotNames);
std::cout << "Templates loaded: " << barrierMgr.GetTemplateContainer()->size() << std::endl;
} }
World::~World() { World::~World() {
@@ -163,6 +185,42 @@ void World::Update() {
return; return;
} }
//TODO: (0) regular query interval
if (Clock::now() - queryTime > std::chrono::seconds(3)) {
queryTime = Clock::now();
//query the world state (room)
CharacterPacket characterPacket;
memset(&characterPacket, 0, MAX_PACKET_SIZE);
characterPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS;
characterPacket.roomIndex = roomIndex;
network.SendTo(Channels::SERVER, &characterPacket);
CreaturePacket creaturePacket;
creaturePacket.type = SerialPacketType::QUERY_CREATURE_EXISTS;
creaturePacket.roomIndex = roomIndex;
network.SendTo(Channels::SERVER, &creaturePacket);
BarrierPacket barrierPacket;
barrierPacket.type = SerialPacketType::QUERY_BARRIER_EXISTS;
barrierPacket.roomIndex = roomIndex;
network.SendTo(Channels::SERVER, &barrierPacket);
}
//cull creatures
for (std::map<int, BaseCreature>::iterator it = creatureMap.begin(); it != creatureMap.end(); /* */) {
if ( (localCharacter->GetOrigin() - it->second.GetOrigin()).Length() > INFLUENCE_RADIUS) {
creatureMap.erase(it++);
}
else {
it++;
}
}
//cull barriers
barrierMgr.UnloadIf([&](std::pair<const int, BaseBarrier const&> barrierIt) -> bool {
return (localCharacter->GetOrigin() - barrierIt.second.GetOrigin()).Length() > INFLUENCE_RADIUS;
});
//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());
@@ -186,11 +244,6 @@ void World::RenderFrame(SDL_Renderer* renderer) {
//draw the map //draw the map
for (std::list<Region>::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); it++) { for (std::list<Region>::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); it++) {
tileSheet.DrawRegionTo(renderer, &(*it), camera.x, camera.y); tileSheet.DrawRegionTo(renderer, &(*it), camera.x, camera.y);
//debugging
// std::ostringstream msg;
// msg << it->GetX() << ", " << it->GetY();
// font.DrawStringTo(msg.str(), screen, it->GetX() * tileSheet.GetImage()->GetClipW() - camera.x, it->GetY() * tileSheet.GetImage()->GetClipH() - camera.y);
} }
//draw the entities //draw the entities
@@ -201,6 +254,7 @@ void World::RenderFrame(SDL_Renderer* renderer) {
for (auto& it : creatureMap) { for (auto& it : creatureMap) {
it.second.DrawTo(renderer, camera.x, camera.y); it.second.DrawTo(renderer, camera.x, camera.y);
} }
barrierMgr.DrawTo(renderer, camera.x, camera.y);
//draw UI //draw UI
disconnectButton.DrawTo(renderer); disconnectButton.DrawTo(renderer);
@@ -250,6 +304,7 @@ void World::MouseWheel(SDL_MouseWheelEvent const& event) {
} }
void World::KeyDown(SDL_KeyboardEvent const& event) { void World::KeyDown(SDL_KeyboardEvent const& event) {
//TODO: Sliding against walls controls
//BUGFIX: SDL2 introduced key repeats, so I need to ignore it //BUGFIX: SDL2 introduced key repeats, so I need to ignore it
if (event.repeat) { if (event.repeat) {
return; return;
@@ -397,6 +452,10 @@ void World::HandlePacket(SerialPacket* const argPacket) {
break; break;
//creature management //creature management
case SerialPacketType::CREATURE_UPDATE:
hCreatureUpdate(static_cast<CreaturePacket*>(argPacket));
break;
case SerialPacketType::CREATURE_CREATE: case SerialPacketType::CREATURE_CREATE:
hCreatureCreate(static_cast<CreaturePacket*>(argPacket)); hCreatureCreate(static_cast<CreaturePacket*>(argPacket));
break; break;
@@ -412,6 +471,22 @@ void World::HandlePacket(SerialPacket* const argPacket) {
hCreatureMovement(static_cast<CreaturePacket*>(argPacket)); hCreatureMovement(static_cast<CreaturePacket*>(argPacket));
break; 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 //chat
case SerialPacketType::TEXT_BROADCAST: case SerialPacketType::TEXT_BROADCAST:
hTextBroadcast(static_cast<TextPacket*>(argPacket)); hTextBroadcast(static_cast<TextPacket*>(argPacket));
@@ -564,18 +639,11 @@ void World::SendRegionRequest(int roomIndex, int x, int y) {
} }
void World::hRegionContent(RegionPacket* const argPacket) { void World::hRegionContent(RegionPacket* const argPacket) {
//checksum
if (regionChecksum(argPacket->region) == 0) {
std::ostringstream msg;
msg << "Received region checksum failed: " << argPacket->x << ", " << argPacket->y;
throw(std::runtime_error(msg.str()));
}
//replace existing regions //replace existing regions
regionPager.UnloadIf([&](Region const& region) -> bool { regionPager.UnloadIf([&](Region const& region) -> bool {
if (region.GetX() == argPacket->x && region.GetY() == argPacket->y) { if (region.GetX() == argPacket->x && region.GetY() == argPacket->y) {
std::cout << "Region Overwrite: " << region.GetX() << ", " << region.GetY(); std::cout << "Region Overwrite: " << region.GetX() << ", " << region.GetY();
std::cout << "\t" << region.GetSolid(1,1) << "\t" << argPacket->region->GetSolid(1,1) << std::endl; std::cout << "\t" << regionContentCheck(&region) << "\t" << regionContentCheck(argPacket->region) << std::endl;
return true; return true;
} }
else { else {
@@ -614,7 +682,7 @@ void World::UpdateMap() {
//request absent region //request absent region
SendRegionRequest(roomIndex, i, j); SendRegionRequest(roomIndex, i, j);
} }
else if (regionChecksum(region) == 0) { else if (regionContentCheck(region) == 0) {
//checksum failed //checksum failed
regionPager.UnloadIf([region](Region const& ref) -> bool { regionPager.UnloadIf([region](Region const& ref) -> bool {
//remove the erroneous region //remove the erroneous region
@@ -622,7 +690,7 @@ void World::UpdateMap() {
}); });
SendRegionRequest(roomIndex, i, j); SendRegionRequest(roomIndex, i, j);
std::ostringstream msg; std::ostringstream msg;
msg << "Existing region checksum failed: " << roomIndex << ", " << i << ", " << j; msg << "Existing region blank: " << roomIndex << ", " << i << ", " << j;
throw(std::runtime_error(msg.str())); throw(std::runtime_error(msg.str()));
} }
} }
@@ -682,6 +750,9 @@ void World::hCharacterCreate(CharacterPacket* const argPacket) {
if (character->GetOwner() == accountIndex) { if (character->GetOwner() == accountIndex) {
localCharacter = static_cast<LocalCharacter*>(character); localCharacter = static_cast<LocalCharacter*>(character);
//reset queries
queryTime = Clock::now() - std::chrono::seconds(4); //back 4 seconds to trigger automatically
//focus the camera on this character's sprite //focus the camera on this character's sprite
camera.marginX = (camera.width / 2 - localCharacter->GetSprite()->GetClipW() / 2); camera.marginX = (camera.width / 2 - localCharacter->GetSprite()->GetClipW() / 2);
camera.marginY = (camera.height/ 2 - localCharacter->GetSprite()->GetClipH() / 2); camera.marginY = (camera.height/ 2 - localCharacter->GetSprite()->GetClipH() / 2);
@@ -689,15 +760,6 @@ void World::hCharacterCreate(CharacterPacket* const argPacket) {
//focus on this character's info //focus on this character's info
characterIndex = argPacket->characterIndex; characterIndex = argPacket->characterIndex;
roomIndex = argPacket->roomIndex; roomIndex = argPacket->roomIndex;
//query the world state (room)
CharacterPacket newPacket;
memset(&newPacket, 0, MAX_PACKET_SIZE);
newPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS;
newPacket.roomIndex = roomIndex;
network.SendTo(Channels::SERVER, &newPacket);
newPacket.type = SerialPacketType::QUERY_CREATURE_EXISTS;
network.SendTo(Channels::SERVER, &newPacket);
} }
//debug //debug
@@ -719,9 +781,10 @@ void World::hCharacterUnload(CharacterPacket* const argPacket) {
camera.marginX = 0; camera.marginX = 0;
camera.marginY = 0; camera.marginY = 0;
//clear the room //clear/reset the room
roomIndex = -1; roomIndex = -1;
regionPager.UnloadAll(); regionPager.UnloadAll();
barrierMgr.UnloadAll();
characterMap.clear(); characterMap.clear();
creatureMap.clear(); creatureMap.clear();
} }
@@ -737,12 +800,12 @@ void World::hCharacterUnload(CharacterPacket* const argPacket) {
void World::hQueryCharacterExists(CharacterPacket* const argPacket) { void World::hQueryCharacterExists(CharacterPacket* const argPacket) {
//prevent a double message about this player's character //prevent a double message about this player's character
//TODO: why is this commented out? //TODO: why is this commented out?
// if (argPacket->accountIndex == accountIndex) { if (argPacket->accountIndex == accountIndex) {
// return; return;
// } }
//ignore characters in a different room (sub-optimal) //ignore characters in a different room (sub-optimal)
if (argPacket->roomIndex != roomIndex) { if (argPacket->roomIndex != roomIndex || (localCharacter->GetOrigin() - argPacket->origin).Length() > INFLUENCE_RADIUS) {
return; return;
} }
@@ -782,6 +845,35 @@ void World::hCharacterMovement(CharacterPacket* const argPacket) {
//creature management //creature management
//------------------------- //-------------------------
void World::hCreatureUpdate(CreaturePacket* const argPacket) {
//BUGFIX: Sometimes crash on exit
if (!localCharacter) {
return;
}
//Cull creatures that are too far away
if ( (localCharacter->GetOrigin() - argPacket->origin).Length() > INFLUENCE_RADIUS) {
//ignore beyond 1000 units
return;
}
//check if this creature exists
std::map<int, BaseCreature>::iterator creatureIt = creatureMap.find(argPacket->creatureIndex);
if (creatureIt != creatureMap.end()) {
//update the origin and motion, if there's a difference
if (creatureIt->second.GetOrigin() != argPacket->origin) {
creatureIt->second.SetOrigin(argPacket->origin);
}
if (creatureIt->second.GetMotion() != argPacket->motion) {
creatureIt->second.SetMotion(argPacket->motion);
creatureIt->second.CorrectSprite(); //only correct the sprite if the motion changes
}
}
else {
hCreatureCreate(argPacket);
}
}
void World::hCreatureCreate(CreaturePacket* const argPacket) { void World::hCreatureCreate(CreaturePacket* const argPacket) {
//check for logic errors //check for logic errors
if (creatureMap.find(argPacket->creatureIndex) != creatureMap.end()) { if (creatureMap.find(argPacket->creatureIndex) != creatureMap.end()) {
@@ -830,8 +922,12 @@ void World::hCreatureUnload(CreaturePacket* const argPacket) {
} }
void World::hQueryCreatureExists(CreaturePacket* const argPacket) { void World::hQueryCreatureExists(CreaturePacket* const argPacket) {
if (!localCharacter) {
return;
}
//ignore creatures in a different room (sub-optimal) //ignore creatures in a different room (sub-optimal)
if (argPacket->roomIndex != roomIndex) { if (argPacket->roomIndex != roomIndex || (localCharacter->GetOrigin() - argPacket->origin).Length() > INFLUENCE_RADIUS) {
return; return;
} }
@@ -850,6 +946,8 @@ void World::hQueryCreatureExists(CreaturePacket* const argPacket) {
} }
void World::hCreatureMovement(CreaturePacket* const argPacket) { void World::hCreatureMovement(CreaturePacket* const argPacket) {
std::cout << "hCreatureMovement" << std::endl;
//ignore if this creature doesn't exist //ignore if this creature doesn't exist
std::map<int, BaseCreature>::iterator creatureIt = creatureMap.find(argPacket->creatureIndex); std::map<int, BaseCreature>::iterator creatureIt = creatureMap.find(argPacket->creatureIndex);
if (creatureIt == creatureMap.end()) { if (creatureIt == creatureMap.end()) {
@@ -860,6 +958,106 @@ void World::hCreatureMovement(CreaturePacket* const argPacket) {
creatureIt->second.SetMotion(argPacket->motion); creatureIt->second.SetMotion(argPacket->motion);
} }
//-------------------------
//barrier management
//-------------------------
void World::hBarrierUpdate(BarrierPacket* const argPacket) {
//BUGFIX: Sometimes crash on exit
if (!localCharacter) {
return;
}
//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
BaseBarrier* barrier = barrierMgr.Find(argPacket->barrierIndex);
if (!barrier) {
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) {
//check for logic errors
//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()));
}
BaseBarrier* barrier = barrierMgr.Find(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
barrier->SetBounds(argPacket->bounds);
barrier->SetOrigin(argPacket->origin);
barrier->SetStatusArray(argPacket->status);
barrier->CorrectSprite();
//debug
std::cout << "Barrier Create, total: " << barrierMgr.Size() << std::endl;
}
void World::hBarrierUnload(BarrierPacket* const argPacket) {
//ignore if this barrier doesn't exist
barrierMgr.Unload(argPacket->barrierIndex);
//debug
std::cout << "Barrier Unload, total: " << barrierMgr.Size() << std::endl;
}
void World::hQueryBarrierExists(BarrierPacket* const argPacket) {
if (!localCharacter) {
return;
}
//ignore barriers in a different room (sub-optimal)
if (argPacket->roomIndex != roomIndex || (localCharacter->GetOrigin() - argPacket->origin).Length() > INFLUENCE_RADIUS) {
return;
}
//implicitly create the element
BaseBarrier* barrier = barrierMgr.Find(argPacket->barrierIndex);
if (!barrier) {
barrier = barrierMgr.Create(argPacket->barrierIndex);
}
//fill the barrier's info
barrier->SetBounds(argPacket->bounds);
barrier->SetOrigin(argPacket->origin);
barrier->SetStatusArray(argPacket->status);
barrier->CorrectSprite();
//debug
std::cout << "Barrier Query, total: " << barrierMgr.Size() << std::endl;
}
//------------------------- //-------------------------
//chat //chat
//------------------------- //-------------------------
@@ -881,6 +1079,11 @@ void World::hTextWhisper(TextPacket* const argPacket) {
//------------------------- //-------------------------
void World::SendLocalCharacterMovement() { void World::SendLocalCharacterMovement() {
//BUGFIX: Sometimes crash on exit
if (!localCharacter) {
return;
}
CharacterPacket newPacket; CharacterPacket newPacket;
newPacket.type = SerialPacketType::CHARACTER_MOVEMENT; newPacket.type = SerialPacketType::CHARACTER_MOVEMENT;
+12 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -39,7 +39,9 @@
#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_creature.hpp" #include "base_creature.hpp"
#include "local_character.hpp" #include "local_character.hpp"
@@ -107,11 +109,18 @@ private:
void hCharacterMovement(CharacterPacket* const); void hCharacterMovement(CharacterPacket* const);
//creature management //creature management
void hCreatureUpdate(CreaturePacket* const);
void hCreatureCreate(CreaturePacket* const); void hCreatureCreate(CreaturePacket* const);
void hCreatureUnload(CreaturePacket* const); void hCreatureUnload(CreaturePacket* const);
void hQueryCreatureExists(CreaturePacket* const); void hQueryCreatureExists(CreaturePacket* const);
void hCreatureMovement(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 //chat
//TODO: ui chat engine //TODO: ui chat engine
void hTextBroadcast(TextPacket* const); void hTextBroadcast(TextPacket* const);
@@ -150,6 +159,7 @@ private:
} camera; } camera;
//entities //entities
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;
@@ -158,6 +168,7 @@ private:
//TODO: (2) Heartbeat needs it's own utility //TODO: (2) Heartbeat needs it's own utility
typedef std::chrono::steady_clock Clock; typedef std::chrono::steady_clock Clock;
Clock::time_point lastBeat = Clock::now(); Clock::time_point lastBeat = Clock::now();
Clock::time_point queryTime = Clock::now() - std::chrono::seconds(4); //back 4 seconds to trigger automatically
int attemptedBeats = 0; int attemptedBeats = 0;
//ugly references; I hate this //ugly references; I hate this
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+28
View File
@@ -0,0 +1,28 @@
/* 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
//the bounds for the objects, mapped to the default sprites
constexpr int BARRIER_BOUNDS_X = 0;
constexpr int BARRIER_BOUNDS_Y = 0;
constexpr int BARRIER_BOUNDS_WIDTH = 96;
constexpr int BARRIER_BOUNDS_HEIGHT = 96;
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+39
View File
@@ -0,0 +1,39 @@
/* 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 <cmath>
//the speeds that the characters move
constexpr double CREATURE_WALKING_SPEED = 1.0;
constexpr double CREATURE_WALKING_MOD = 1.0/sqrt(2.0);
constexpr double CREATURE_WALKING_NEGATIVE_MOD = 1.0 - CREATURE_WALKING_MOD;
//the bounds for the character objects, mapped to the default sprites
constexpr int CREATURE_BOUNDS_X = 0;
constexpr int CREATURE_BOUNDS_Y = 0;
constexpr int CREATURE_BOUNDS_WIDTH = 32;
constexpr int CREATURE_BOUNDS_HEIGHT = 32;
//the character's sprite format
constexpr int CREATURE_CELLS_X = 4;
constexpr int CREATURE_CELLS_Y = 4;
+24
View File
@@ -0,0 +1,24 @@
/* 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
constexpr int INFLUENCE_RADIUS = 1000;
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -161,7 +161,7 @@ SDL_Texture* Image::SetTexture(SDL_Texture* ptr) {
clip.y = 0; clip.y = 0;
if (SDL_QueryTexture(texture, nullptr, nullptr, &clip.w, &clip.h)) { if (SDL_QueryTexture(texture, nullptr, nullptr, &clip.w, &clip.h)) {
std::ostringstream msg; std::ostringstream msg;
msg << "Failed to record metadata for a newly image image"; msg << "Failed to record metadata for a newly set image";
msg << "; " << SDL_GetError(); msg << "; " << SDL_GetError();
throw(std::runtime_error(msg.str())); throw(std::runtime_error(msg.str()));
} }
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -48,7 +48,7 @@ Region::type_t Region::SetTile(int x, int y, int z, type_t v) {
return tiles[x][y][z] = v; return tiles[x][y][z] = v;
} }
Region::type_t Region::GetTile(int x, int y, int z) { Region::type_t Region::GetTile(int x, int y, int z) const {
if (x < 0 || y < 0 || z < 0 || x >= REGION_WIDTH || y >= REGION_HEIGHT || z >= REGION_DEPTH) { if (x < 0 || y < 0 || z < 0 || x >= REGION_WIDTH || y >= REGION_HEIGHT || z >= REGION_DEPTH) {
throw(std::out_of_range("Region::GetTile() argument out of range")); throw(std::out_of_range("Region::GetTile() argument out of range"));
} }
+2 -2
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -41,7 +41,7 @@ public:
~Region() = default; ~Region() = default;
type_t SetTile(int x, int y, int z, type_t v); type_t SetTile(int x, int y, int z, type_t v);
type_t GetTile(int x, int y, int z); type_t GetTile(int x, int y, int z) const;
bool SetSolid(int x, int y, bool b); bool SetSolid(int x, int y, bool b);
bool GetSolid(int x, int y) const; bool GetSolid(int x, int y) const;
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+2 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -33,6 +33,7 @@ Region::type_t RegionPagerBase::SetTile(int x, int y, int z, Region::type_t v) {
return ptr->SetTile(x - ptr->GetX(), y - ptr->GetY(), z, v); return ptr->SetTile(x - ptr->GetX(), y - ptr->GetY(), z, v);
} }
//Bug Origin?
Region::type_t RegionPagerBase::GetTile(int x, int y, int z) { Region::type_t RegionPagerBase::GetTile(int x, int y, int z) {
Region* ptr = GetRegion(x, y); Region* ptr = GetRegion(x, y);
return ptr->GetTile(x - ptr->GetX(), y - ptr->GetY(), z); return ptr->GetTile(x - ptr->GetX(), y - ptr->GetY(), z);
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -0,0 +1,72 @@
/* 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_packet.hpp"
#include "serial_utility.hpp"
void serializeBarrier(void* buffer, BarrierPacket* packet) {
serialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
//identify the barrier
serialCopy(&buffer, &packet->barrierIndex, sizeof(int));
//bounds
serialCopy(&buffer, &packet->bounds.x, sizeof(int));
serialCopy(&buffer, &packet->bounds.y, sizeof(int));
serialCopy(&buffer, &packet->bounds.w, sizeof(int));
serialCopy(&buffer, &packet->bounds.h, sizeof(int));
//location
serialCopy(&buffer, &packet->roomIndex, sizeof(int));
serialCopy(&buffer, &packet->origin.x, sizeof(double));
serialCopy(&buffer, &packet->origin.y, sizeof(double));
serialCopy(&buffer, &packet->motion.x, sizeof(double));
serialCopy(&buffer, &packet->motion.y, sizeof(double));
//graphical data
serialCopy(&buffer, packet->status, sizeof(int) * 8);
}
void deserializeBarrier(void* buffer, BarrierPacket* packet) {
deserialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
//identify the barrier
deserialCopy(&buffer, &packet->barrierIndex, sizeof(int));
//bounds
deserialCopy(&buffer, &packet->bounds.x, sizeof(int));
deserialCopy(&buffer, &packet->bounds.y, sizeof(int));
deserialCopy(&buffer, &packet->bounds.w, sizeof(int));
deserialCopy(&buffer, &packet->bounds.h, sizeof(int));
//location
deserialCopy(&buffer, &packet->roomIndex, sizeof(int));
deserialCopy(&buffer, &packet->origin.x, sizeof(double));
deserialCopy(&buffer, &packet->origin.y, sizeof(double));
deserialCopy(&buffer, &packet->motion.x, sizeof(double));
deserialCopy(&buffer, &packet->motion.y, sizeof(double));
//graphical data
deserialCopy(&buffer, packet->status, sizeof(int) * 8);
}
@@ -0,0 +1,44 @@
/* 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 "serial_packet_base.hpp"
#include "bounding_box.hpp"
#include "vector2.hpp"
struct BarrierPacket : SerialPacketBase {
//identify the barrier
int barrierIndex;
BoundingBox bounds;
//location
int roomIndex;
Vector2 origin;
Vector2 motion;
//graphical data: 0 blank, 1 green, 2 red
int status[8];
};
void serializeBarrier(void* buffer, BarrierPacket* packet);
void deserializeBarrier(void* buffer, BarrierPacket* packet);
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+3 -2
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -22,6 +22,7 @@
#pragma once #pragma once
#include "serial_packet_base.hpp" #include "serial_packet_base.hpp"
#include "barrier_packet.hpp"
#include "character_packet.hpp" #include "character_packet.hpp"
#include "client_packet.hpp" #include "client_packet.hpp"
#include "creature_packet.hpp" #include "creature_packet.hpp"
@@ -33,7 +34,7 @@
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 = 20160321; constexpr int NETWORK_VERSION = 20160404;
union MaxPacket { union MaxPacket {
CharacterPacket a; CharacterPacket a;
+21 -2
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -142,6 +142,25 @@ 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
@@ -169,5 +188,5 @@ enum class SerialPacketType {
//not used //not used
//------------------------- //-------------------------
LAST = 700 LAST = 800
}; };
+10 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
@@ -22,6 +22,7 @@
#include "serial_utility.hpp" #include "serial_utility.hpp"
//packet types //packet types
#include "barrier_packet.hpp"
#include "character_packet.hpp" #include "character_packet.hpp"
#include "client_packet.hpp" #include "client_packet.hpp"
#include "creature_packet.hpp" #include "creature_packet.hpp"
@@ -69,6 +70,10 @@ 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));
} }
@@ -99,6 +104,10 @@ 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));
} }
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,4 +1,4 @@
/* Copyright: (c) Kayne Ruse 2013-2015 /* Copyright: (c) Kayne Ruse 2013-2016
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages * warranty. In no event will the authors be held liable for any damages

Some files were not shown because too many files have changed in this diff Show More