Compare commits

..

66 Commits

Author SHA1 Message Date
Kayne Ruse 4cce98dba4 BattleData can hold a limited number of characters 2016-08-29 19:05:41 +10:00
Kayne Ruse b2aecc933a I need to do some refactoring 2016-08-26 00:11:54 +10:00
Kayne Ruse 64833f86da Added index to CharacterData, removed some expensive lookups 2016-08-25 23:23:57 +10:00
Kayne Ruse 518ea93adc Added RoomData::[Pop/Push]Character() 2016-08-25 20:47:08 +10:00
Kayne Ruse 07218418a2 Discovered I need to do something 2016-08-25 20:01:17 +10:00
Kayne Ruse 6d8d7963a1 Renamed CombatInstance to Battle, for clarity 2016-07-11 10:14:07 +10:00
Kayne Ruse 69a13c5ed6 Broke RoomData::RunFrame() into several parts for readability 2016-07-09 20:14:07 +10:00
Kayne Ruse 011f71ea61 Wrote out the pseudocode for RoomData::RunFrame
This method is too overloaded. The pseudocode itself takes up a whole
page.
2016-07-09 17:25:13 +10:00
Kayne Ruse 4894daa273 Moved barrier system into it's own subdirectory 2016-07-09 16:56:35 +10:00
Kayne Ruse 9a1dcc2f53 Set barrier bounds 2016-05-29 02:24:10 +10:00
Kayne Ruse 8d2fc45d7d Combat instances are created alongside the barriers 2016-05-29 02:15:41 +10:00
Kayne Ruse 867a86fd79 Fixed Missing #include<functional> 2016-05-28 13:01:19 +10:00
Kayne Ruse 7ccea0d1c0 I quit 2016-04-25 22:22:04 +10:00
Kayne Ruse 7c6468c1dd Multiple changes, read more
* Implemented HeartbeatUtility
* simplified the SQL files
* Added a dummy inventory button
2016-04-25 22:10:11 +10:00
Kayne Ruse 5285397101 I really hate SQL 2016-04-22 20:00:31 +10:00
Kayne Ruse ba295099f3 Experimenting with SQL 2016-04-22 18:14:07 +10:00
Kayne Ruse 754fb71850 Updated SQL script 2016-04-22 08:26:19 +10:00
Kayne Ruse dd25f068af Merge remote-tracking branch 'refs/remotes/origin/master' 2016-04-19 10:14:08 +10:00
Kayne Ruse bf273db9c2 Fixed Typo in README.md 2016-04-18 09:20:03 +10:00
Kayne Ruse 5d3d82bf3f Added a new button graphic 2016-04-17 02:15:23 +10:00
Kayne Ruse 36ba3fa132 Updated GUI library 2016-04-17 02:10:08 +10:00
Kayne Ruse 3002afa1e9 Moved a file 2016-04-17 01:35:34 +10:00
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
227 changed files with 4263 additions and 709 deletions
+2 -2
View File
@@ -7,7 +7,7 @@ This game is inspired by classic 2D RPGs (Final Fantasy, The Legend of Zelda), a
## Releases
* The most recent stable build for Windows can be found [here](https://dl.dropboxusercontent.com/u/46669050/Tortuga-win.rar).
* The most recent stable build for Windows can be found [here](https://dl.dropboxusercontent.com/u/46669050/Tortuga-linux.tar).
* The most recent stable build for Linux can be found [here](https://dl.dropboxusercontent.com/u/46669050/Tortuga-linux.tar).
## Documentation
@@ -52,4 +52,4 @@ Permission is granted to anyone to use this software for any purpose, including
### Items not made by me
* [Coolvetica Font](http://typodermicfonts.com/coolvetica/)
* Creative Commons Artwork from [Artsader](http://www.moosader.com/artsader/)
* Creative Commons Artwork from [Artsader](http://www.moosader.com/artsader/)
+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
* 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
* 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
* 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
* 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 "lobby_menu.hpp"
#include "world.hpp"
#include "combat.hpp"
#include "disconnected_screen.hpp"
void ClientApplication::ProcessSceneSignal(SceneSignal signal) {
@@ -341,6 +342,9 @@ void ClientApplication::ProcessSceneSignal(SceneSignal signal) {
case SceneSignal::WORLD:
activeScene = new World(&clientIndex, &accountIndex);
break;
case SceneSignal::COMBAT:
activeScene = new Combat(&clientIndex, &accountIndex);
break;
case SceneSignal::DISCONNECTEDSCREEN:
activeScene = new DisconnectedScreen();
break;
+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
* warranty. In no event will the authors be held liable for any damages
+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;
}
+58
View File
@@ -0,0 +1,58 @@
/* 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 <functional>
#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
* 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
* 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
* 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) {
avatar = s;
sprite.Load(renderer, ConfigUtility::GetSingleton()["dir.sprites"] + avatar, 4, 1);
sprite.Load(renderer, ConfigUtility::GetSingleton()["dir.sprites"] + avatar, 4, 4);
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
* 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
* 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;
}
Vector2 Entity::GetOrigin() {
Vector2 Entity::GetOrigin() const {
return origin;
}
Vector2 Entity::GetMotion() {
Vector2 Entity::GetMotion() const {
return motion;
}
BoundingBox Entity::GetBounds() {
BoundingBox Entity::GetBounds() const {
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
* warranty. In no event will the authors be held liable for any damages
@@ -39,9 +39,9 @@ public:
Vector2 SetMotion(Vector2 v);
BoundingBox SetBounds(BoundingBox b);
Vector2 GetOrigin();
Vector2 GetMotion();
BoundingBox GetBounds();
Vector2 GetOrigin() const;
Vector2 GetMotion() const;
BoundingBox GetBounds() const;
protected:
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
* 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
* 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
* 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
* warranty. In no event will the authors be held liable for any damages
+58
View File
@@ -0,0 +1,58 @@
/* 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 "heartbeat_utility.hpp"
#include "channels.hpp"
#include "ip_operators.hpp"
//heartbeat system
void HeartbeatUtility::hPing(ServerPacket* const argPacket) {
ServerPacket newPacket;
newPacket.type = SerialPacketType::PONG;
network.SendTo(argPacket->srcAddress, &newPacket);
}
void HeartbeatUtility::hPong(ServerPacket* const argPacket) {
if (*network.GetIPAddress(Channels::SERVER) != argPacket->srcAddress) {
throw(std::runtime_error("Heartbeat message received from an unknown source"));
}
attemptedBeats = 0;
lastBeat = Clock::now();
}
int HeartbeatUtility::CheckHeartBeat() {
//check the connection (heartbeat)
if (Clock::now() - lastBeat > std::chrono::seconds(3)) {
if (attemptedBeats > 2) {
return 1;
}
else {
ServerPacket newPacket;
newPacket.type = SerialPacketType::PING;
network.SendTo(Channels::SERVER, &newPacket);
attemptedBeats++;
lastBeat = Clock::now();
}
}
return 0;
}
+42
View File
@@ -0,0 +1,42 @@
/* 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 "server_packet.hpp"
#include "udp_network_utility.hpp"
#include <chrono>
class HeartbeatUtility {
public:
//heartbeat system
void hPing(ServerPacket* const);
void hPong(ServerPacket* const);
int CheckHeartBeat();
private:
UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton();
typedef std::chrono::steady_clock Clock;
Clock::time_point lastBeat = Clock::now();
int attemptedBeats = 0;
};
+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
* 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
* warranty. In no event will the authors be held liable for any damages
@@ -33,5 +33,6 @@ enum SceneSignal {
OPTIONSMENU,
LOBBYMENU,
WORLD,
COMBAT,
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;
};
+8 -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
* warranty. In no event will the authors be held liable for any damages
@@ -28,6 +28,8 @@
#include <sstream>
#include <stdexcept>
constexpr SDL_Color WHITE = {255, 255, 255, 255};
//-------------------------
//Public access members
//-------------------------
@@ -49,14 +51,16 @@ DisconnectedScreen::DisconnectedScreen() {
//setup the button
backButton.SetBackgroundTexture(GetRenderer(), image.GetTexture());
backButton.SetText(GetRenderer(), font, "Back", COLOR_WHITE);
backButton.SetText(GetRenderer(), font, WHITE, "Back");
//set the button positions
backButton.SetX(50);
backButton.SetY(50);
//set the disconnection message text
textLine.SetText(GetRenderer(), font, config["client.disconnectMessage"], {255, 255, 255, 255});
textLine.SetX(50);
textLine.SetY(30);
textLine.SetText(GetRenderer(), font, WHITE, config["client.disconnectMessage"]);
//full reset
UDPNetworkUtility::GetSingleton().Unbind(Channels::SERVER);
@@ -92,7 +96,7 @@ void DisconnectedScreen::FrameEnd() {
void DisconnectedScreen::RenderFrame(SDL_Renderer* renderer) {
backButton.DrawTo(renderer);
textLine.DrawTo(renderer, 50, 30);
textLine.DrawTo(renderer);
}
//-------------------------
+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
* warranty. In no event will the authors be held liable for any damages
+16 -8
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
* warranty. In no event will the authors be held liable for any damages
@@ -27,6 +27,8 @@
#include <stdexcept>
#include <sstream>
constexpr SDL_Color WHITE = {255, 255, 255, 255};
//-------------------------
//Public access members
//-------------------------
@@ -52,11 +54,11 @@ LobbyMenu::LobbyMenu(int* const argClientIndex, int* const argAccountIndex):
//setup the buttons
searchButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
searchButton.SetText(GetRenderer(), font, "Search", COLOR_WHITE);
searchButton.SetText(GetRenderer(), font, WHITE, "Search");
joinButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
joinButton.SetText(GetRenderer(), font, "Join", COLOR_WHITE);
joinButton.SetText(GetRenderer(), font, WHITE, "Join");
backButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
backButton.SetText(GetRenderer(), font, "Back", COLOR_WHITE);
backButton.SetText(GetRenderer(), font, WHITE, "Back");
//set the button positions (assumed)
searchButton.SetX(50);
@@ -67,6 +69,7 @@ LobbyMenu::LobbyMenu(int* const argClientIndex, int* const argAccountIndex):
backButton.SetY(90);
//pseudo-list selection
//TODO: move this into the UI library?
boundingBox = {300, 50, 200, 12};
//hacked together a highlight box
@@ -121,8 +124,13 @@ void LobbyMenu::RenderFrame(SDL_Renderer* renderer) {
}
//draw the server's info
serverVector[i].nameImage.DrawTo(renderer, boundingBox.x, boundingBox.y + boundingBox.h * i);
serverVector[i].playerCountImage.DrawTo(renderer, boundingBox.x+276, boundingBox.y + boundingBox.h * i);
serverVector[i].nameImage.SetX(boundingBox.x);
serverVector[i].nameImage.SetY(boundingBox.y + boundingBox.h * i);
serverVector[i].nameImage.DrawTo(renderer);
serverVector[i].playerCountImage.SetX(boundingBox.x+276);
serverVector[i].playerCountImage.SetY(boundingBox.y + boundingBox.h * i);
serverVector[i].playerCountImage.DrawTo(renderer);
}
}
@@ -248,8 +256,8 @@ void LobbyMenu::HandleBroadcastResponse(ServerPacket* const argPacket) {
};
//text graphics
serverVector.back().nameImage.SetText(GetRenderer(), font, newServer.name, color);
serverVector.back().playerCountImage.SetText(GetRenderer(), font, itoa_base10(newServer.playerCount), color);
serverVector.back().nameImage.SetText(GetRenderer(), font, color, newServer.name);
serverVector.back().playerCountImage.SetText(GetRenderer(), font, color, itoa_base10(newServer.playerCount));
}
void LobbyMenu::HandleJoinResponse(ClientPacket* const argPacket) {
+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
* warranty. In no event will the authors be held liable for any damages
+16 -12
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
* warranty. In no event will the authors be held liable for any damages
@@ -26,6 +26,8 @@
#include <sstream>
#include <stdexcept>
constexpr SDL_Color WHITE = {255, 255, 255, 255};
//-------------------------
//Public access members
//-------------------------
@@ -46,11 +48,11 @@ MainMenu::MainMenu() {
//setup the buttons
startButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
startButton.SetText(GetRenderer(), font, "Start", COLOR_WHITE);
startButton.SetText(GetRenderer(), font, WHITE, "Start");
optionsButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
optionsButton.SetText(GetRenderer(), font, "Options", COLOR_WHITE);
optionsButton.SetText(GetRenderer(), font, WHITE, "Options");
quitButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
quitButton.SetText(GetRenderer(), font, "Quit", COLOR_WHITE);
quitButton.SetText(GetRenderer(), font, WHITE, "Quit");
//set the button positions
startButton.SetX(50);
@@ -61,9 +63,15 @@ MainMenu::MainMenu() {
quitButton.SetY(50 + 20 * 2);
//text box
textBox.PushLine(GetRenderer(), font, "Thanks for playing!", {255, 255, 255, 255});
textBox.PushLine(GetRenderer(), font, "You can get the latest version at: ", {255, 255, 255, 255});
textBox.PushLine(GetRenderer(), font, "krgamestudios.com", {255, 255, 255, 255}); //TODO: (9) click to open the website/update
int h = -1;
SDL_RenderGetLogicalSize(GetRenderer(), nullptr, &h);
textBox.SetX(50);
textBox.SetY(h-100);
textBox.PushLine(GetRenderer(), font, WHITE, "Thanks for playing!");
textBox.PushLine(GetRenderer(), font, WHITE, "You can get the latest version at: ");
textBox.PushLine(GetRenderer(), font, WHITE, "krgamestudios.com"); //TODO: (9) click to open the website/update
//debug
//
@@ -93,11 +101,7 @@ void MainMenu::RenderFrame(SDL_Renderer* renderer) {
startButton.DrawTo(renderer);
optionsButton.DrawTo(renderer);
quitButton.DrawTo(renderer);
int h = -1;
SDL_RenderGetLogicalSize(GetRenderer(), nullptr, &h);
textBox.DrawTo(renderer, 50, h-50, -12);
textBox.DrawTo(renderer);
}
//-------------------------
+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
* warranty. In no event will the authors be held liable for any damages
+8 -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
* warranty. In no event will the authors be held liable for any damages
@@ -26,6 +26,8 @@
#include <sstream>
#include <stdexcept>
constexpr SDL_Color WHITE = {255, 255, 255, 255};
//-------------------------
//Public access members
//-------------------------
@@ -46,14 +48,16 @@ OptionsMenu::OptionsMenu() {
//setup the button
backButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
backButton.SetText(GetRenderer(), font, "Back", COLOR_WHITE);
backButton.SetText(GetRenderer(), font, WHITE, "Back");
//set the button positions
backButton.SetX(50);
backButton.SetY(50);
//text line
textLine.SetText(GetRenderer(), font, "This code is fucking hard to refactor.", {255, 255, 255, 255});
textLine.SetX(50);
textLine.SetY(30);
textLine.SetText(GetRenderer(), font, WHITE, "Am I making any progress?");
}
OptionsMenu::~OptionsMenu() {
@@ -78,7 +82,7 @@ void OptionsMenu::FrameEnd() {
void OptionsMenu::RenderFrame(SDL_Renderer* renderer) {
backButton.DrawTo(renderer);
textLine.DrawTo(renderer, 50, 30);
textLine.DrawTo(renderer);
}
//-------------------------
+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
* 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
* 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
* warranty. In no event will the authors be held liable for any damages
+251 -79
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
* warranty. In no event will the authors be held liable for any damages
@@ -22,6 +22,7 @@
#include "world.hpp"
#include "channels.hpp"
#include "culling_defines.hpp"
#include "ip_operators.hpp"
#include "fatal_error.hpp"
@@ -33,17 +34,19 @@
#include <sstream>
#include <stdexcept>
constexpr SDL_Color WHITE = {255, 255, 255, 255};
//-------------------------
//static functions
//-------------------------
//TODO: (3) proper checksum
static int regionChecksum(Region* const region) {
static int regionContentCheck(Region const* region) {
int sum = 0;
for(int i = 0; i < REGION_WIDTH; i++) {
for (int j = 0; j < REGION_HEIGHT; j++) {
for (int k = 0; k < REGION_DEPTH; k++) {
sum |= region->GetTile(i, j, k);
sum += region->GetTile(i, j, k);
}
}
}
@@ -71,9 +74,9 @@ World::World(int* const argClientIndex, int* const argAccountIndex):
//setup the buttons
disconnectButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
disconnectButton.SetText(GetRenderer(), font, "Disconnect", COLOR_WHITE);
disconnectButton.SetText(GetRenderer(), font, WHITE, "Disconnect");
shutdownButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
shutdownButton.SetText(GetRenderer(), font, "Shutdown", COLOR_WHITE);
shutdownButton.SetText(GetRenderer(), font, WHITE, "Shutdown");
//set the button positions
disconnectButton.SetX(50);
@@ -97,7 +100,28 @@ World::World(int* const argClientIndex, int* const argAccountIndex):
SDL_RenderGetLogicalSize(GetRenderer(), &camera.width, &camera.height);
//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() {
@@ -137,7 +161,12 @@ void World::Update() {
delete reinterpret_cast<char*>(packetBuffer);
//heartbeat system
CheckHeartBeat();
if (heartbeatUtility.CheckHeartBeat()) {
//escape to the disconnect screen
SendDisconnectRequest();
SetSceneSignal(SceneSignal::DISCONNECTEDSCREEN);
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "Error: Lost connection to the server";
}
//update all entities
for (auto& it : characterMap) {
@@ -163,6 +192,42 @@ void World::Update() {
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
std::list<BoundingBox> boxList = GenerateCollisionGrid(localCharacter, tileSheet.GetTileW(), tileSheet.GetTileH());
@@ -186,11 +251,6 @@ void World::RenderFrame(SDL_Renderer* renderer) {
//draw the map
for (std::list<Region>::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); it++) {
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
@@ -201,18 +261,19 @@ void World::RenderFrame(SDL_Renderer* renderer) {
for (auto& it : creatureMap) {
it.second.DrawTo(renderer, camera.x, camera.y);
}
barrierMgr.DrawTo(renderer, camera.x, camera.y);
//draw UI
disconnectButton.DrawTo(renderer);
shutdownButton.DrawTo(renderer);
//FPS
fpsTextLine.DrawTo(renderer, 0, 0);
fpsTextLine.DrawTo(renderer);
int fpsRet = fps.Calculate();
if (fpsRet != -1) {
std::ostringstream msg;
msg << "FPS: " << fpsRet;
fpsTextLine.SetText(renderer, font, msg.str(), {255, 255, 255, 255});
fpsTextLine.SetText(renderer, font, WHITE, msg.str());
}
}
@@ -250,6 +311,7 @@ void World::MouseWheel(SDL_MouseWheelEvent 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
if (event.repeat) {
return;
@@ -354,10 +416,10 @@ void World::HandlePacket(SerialPacket* const argPacket) {
switch(argPacket->type) {
//heartbeat system
case SerialPacketType::PING:
hPing(static_cast<ServerPacket*>(argPacket));
heartbeatUtility.hPing(static_cast<ServerPacket*>(argPacket));
break;
case SerialPacketType::PONG:
hPong(static_cast<ServerPacket*>(argPacket));
heartbeatUtility.hPong(static_cast<ServerPacket*>(argPacket));
break;
//game server connections
@@ -397,6 +459,10 @@ void World::HandlePacket(SerialPacket* const argPacket) {
break;
//creature management
case SerialPacketType::CREATURE_UPDATE:
hCreatureUpdate(static_cast<CreaturePacket*>(argPacket));
break;
case SerialPacketType::CREATURE_CREATE:
hCreatureCreate(static_cast<CreaturePacket*>(argPacket));
break;
@@ -412,6 +478,22 @@ void World::HandlePacket(SerialPacket* const argPacket) {
hCreatureMovement(static_cast<CreaturePacket*>(argPacket));
break;
//barrier management
case SerialPacketType::BARRIER_UPDATE:
hBarrierUpdate(static_cast<BarrierPacket*>(argPacket));
break;
case SerialPacketType::BARRIER_CREATE:
hBarrierCreate(static_cast<BarrierPacket*>(argPacket));
break;
case SerialPacketType::BARRIER_UNLOAD:
hBarrierUnload(static_cast<BarrierPacket*>(argPacket));
break;
case SerialPacketType::QUERY_BARRIER_EXISTS:
hQueryBarrierExists(static_cast<BarrierPacket*>(argPacket));
break;
//chat
case SerialPacketType::TEXT_BROADCAST:
hTextBroadcast(static_cast<TextPacket*>(argPacket));
@@ -443,44 +525,6 @@ void World::HandlePacket(SerialPacket* const argPacket) {
}
}
//-------------------------
//heartbeat system
//-------------------------
void World::hPing(ServerPacket* const argPacket) {
ServerPacket newPacket;
newPacket.type = SerialPacketType::PONG;
network.SendTo(argPacket->srcAddress, &newPacket);
}
void World::hPong(ServerPacket* const argPacket) {
if (*network.GetIPAddress(Channels::SERVER) != argPacket->srcAddress) {
throw(std::runtime_error("Heartbeat message received from an unknown source"));
}
attemptedBeats = 0;
lastBeat = Clock::now();
}
void World::CheckHeartBeat() {
//check the connection (heartbeat)
if (Clock::now() - lastBeat > std::chrono::seconds(3)) {
if (attemptedBeats > 2) {
//escape to the disconnect screen
SendDisconnectRequest();
SetSceneSignal(SceneSignal::DISCONNECTEDSCREEN);
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "Error: Lost connection to the server";
}
else {
ServerPacket newPacket;
newPacket.type = SerialPacketType::PING;
network.SendTo(Channels::SERVER, &newPacket);
attemptedBeats++;
lastBeat = Clock::now();
}
}
}
//-------------------------
//Connection control
//-------------------------
@@ -564,18 +608,11 @@ void World::SendRegionRequest(int roomIndex, int x, int y) {
}
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
regionPager.UnloadIf([&](Region const& region) -> bool {
if (region.GetX() == argPacket->x && region.GetY() == argPacket->y) {
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;
}
else {
@@ -614,7 +651,7 @@ void World::UpdateMap() {
//request absent region
SendRegionRequest(roomIndex, i, j);
}
else if (regionChecksum(region) == 0) {
else if (regionContentCheck(region) == 0) {
//checksum failed
regionPager.UnloadIf([region](Region const& ref) -> bool {
//remove the erroneous region
@@ -622,7 +659,7 @@ void World::UpdateMap() {
});
SendRegionRequest(roomIndex, i, j);
std::ostringstream msg;
msg << "Existing region checksum failed: " << roomIndex << ", " << i << ", " << j;
msg << "Existing region blank: " << roomIndex << ", " << i << ", " << j;
throw(std::runtime_error(msg.str()));
}
}
@@ -682,6 +719,9 @@ void World::hCharacterCreate(CharacterPacket* const argPacket) {
if (character->GetOwner() == accountIndex) {
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
camera.marginX = (camera.width / 2 - localCharacter->GetSprite()->GetClipW() / 2);
camera.marginY = (camera.height/ 2 - localCharacter->GetSprite()->GetClipH() / 2);
@@ -689,15 +729,6 @@ void World::hCharacterCreate(CharacterPacket* const argPacket) {
//focus on this character's info
characterIndex = argPacket->characterIndex;
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
@@ -719,9 +750,10 @@ void World::hCharacterUnload(CharacterPacket* const argPacket) {
camera.marginX = 0;
camera.marginY = 0;
//clear the room
//clear/reset the room
roomIndex = -1;
regionPager.UnloadAll();
barrierMgr.UnloadAll();
characterMap.clear();
creatureMap.clear();
}
@@ -737,12 +769,12 @@ void World::hCharacterUnload(CharacterPacket* const argPacket) {
void World::hQueryCharacterExists(CharacterPacket* const argPacket) {
//prevent a double message about this player's character
//TODO: why is this commented out?
// if (argPacket->accountIndex == accountIndex) {
// return;
// }
if (argPacket->accountIndex == accountIndex) {
return;
}
//ignore characters in a different room (sub-optimal)
if (argPacket->roomIndex != roomIndex) {
if (argPacket->roomIndex != roomIndex || (localCharacter->GetOrigin() - argPacket->origin).Length() > INFLUENCE_RADIUS) {
return;
}
@@ -782,6 +814,35 @@ void World::hCharacterMovement(CharacterPacket* const argPacket) {
//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) {
//check for logic errors
if (creatureMap.find(argPacket->creatureIndex) != creatureMap.end()) {
@@ -830,8 +891,12 @@ void World::hCreatureUnload(CreaturePacket* const argPacket) {
}
void World::hQueryCreatureExists(CreaturePacket* const argPacket) {
if (!localCharacter) {
return;
}
//ignore creatures in a different room (sub-optimal)
if (argPacket->roomIndex != roomIndex) {
if (argPacket->roomIndex != roomIndex || (localCharacter->GetOrigin() - argPacket->origin).Length() > INFLUENCE_RADIUS) {
return;
}
@@ -850,6 +915,8 @@ void World::hQueryCreatureExists(CreaturePacket* const argPacket) {
}
void World::hCreatureMovement(CreaturePacket* const argPacket) {
std::cout << "hCreatureMovement" << std::endl;
//ignore if this creature doesn't exist
std::map<int, BaseCreature>::iterator creatureIt = creatureMap.find(argPacket->creatureIndex);
if (creatureIt == creatureMap.end()) {
@@ -860,6 +927,106 @@ void World::hCreatureMovement(CreaturePacket* const argPacket) {
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
//-------------------------
@@ -881,6 +1048,11 @@ void World::hTextWhisper(TextPacket* const argPacket) {
//-------------------------
void World::SendLocalCharacterMovement() {
//BUGFIX: Sometimes crash on exit
if (!localCharacter) {
return;
}
CharacterPacket newPacket;
newPacket.type = SerialPacketType::CHARACTER_MOVEMENT;
+14 -10
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
* warranty. In no event will the authors be held liable for any damages
@@ -39,8 +39,11 @@
#include "frame_rate.hpp"
//client
#include "barrier_manager.hpp"
#include "base_scene.hpp"
#include "base_barrier.hpp"
#include "base_creature.hpp"
#include "heartbeat_utility.hpp"
#include "local_character.hpp"
#include "SDL2/SDL.h"
@@ -78,12 +81,6 @@ private:
//handle incoming traffic
void HandlePacket(SerialPacket* const);
//heartbeat system
void hPing(ServerPacket* const);
void hPong(ServerPacket* const);
void CheckHeartBeat();
//basic connections
void SendLogoutRequest();
void SendDisconnectRequest();
@@ -107,11 +104,18 @@ private:
void hCharacterMovement(CharacterPacket* const);
//creature management
void hCreatureUpdate(CreaturePacket* const);
void hCreatureCreate(CreaturePacket* const);
void hCreatureUnload(CreaturePacket* const);
void hQueryCreatureExists(CreaturePacket* const);
void hCreatureMovement(CreaturePacket* const);
//barrier management
void hBarrierUpdate(BarrierPacket* const);
void hBarrierCreate(BarrierPacket* const);
void hBarrierUnload(BarrierPacket* const);
void hQueryBarrierExists(BarrierPacket* const);
//chat
//TODO: ui chat engine
void hTextBroadcast(TextPacket* const);
@@ -150,15 +154,15 @@ private:
} camera;
//entities
BarrierManager barrierMgr;
std::map<int, BaseCharacter> characterMap;
std::map<int, BaseCreature> creatureMap;
LocalCharacter* localCharacter = nullptr;
//heartbeat
//TODO: (2) Heartbeat needs it's own utility
HeartbeatUtility heartbeatUtility;
typedef std::chrono::steady_clock Clock;
Clock::time_point lastBeat = Clock::now();
int attemptedBeats = 0;
Clock::time_point queryTime = Clock::now() - std::chrono::seconds(4); //back 4 seconds to trigger automatically
//ugly references; I hate this
ConfigUtility& config = ConfigUtility::GetSingleton();
+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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
* 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;
+32
View File
@@ -0,0 +1,32 @@
/* 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
enum ItemType {
//basics
POTION = 101,
//weapons
SWORD = 201,
DAGGER = 202,
STAFF = 203
};
+21 -21
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
* warranty. In no event will the authors be held liable for any damages
@@ -21,6 +21,8 @@
*/
#include "button.hpp"
#include "render_text_texture.hpp"
#include <stdexcept>
void Button::DrawTo(SDL_Renderer* renderer) {
@@ -51,19 +53,9 @@ void Button::SetBackgroundTexture(SDL_Renderer* renderer, SDL_Texture* texture)
image.SetClipH(image.GetClipH() / 3);
}
void Button::SetText(SDL_Renderer* renderer, TTF_Font* font, std::string s, SDL_Color color) {
//make the surface (from SDL_ttf)
SDL_Surface* surf = TTF_RenderText_Solid(font, s.c_str(), color);
if (!surf) {
throw(std::runtime_error("Failed to create a TTF surface"));
}
void Button::SetText(SDL_Renderer* renderer, TTF_Font* font, SDL_Color color, std::string s) {
//convert to texture
SDL_Texture* text = SDL_CreateTextureFromSurface(renderer, surf);
SDL_FreeSurface(surf);
if (!text) {
throw(std::runtime_error("Failed to create a TTF texture"));
}
SDL_Texture* text = renderTextTexture(renderer, font, color, s);
//get the dimensions & rects
int x, y, w, h;
@@ -87,14 +79,6 @@ void Button::SetText(SDL_Renderer* renderer, TTF_Font* font, std::string s, SDL_
SDL_DestroyTexture(text);
}
void Button::SetX(int x) {
posX = x;
}
void Button::SetY(int y) {
posY = y;
}
Button::State Button::MouseMotion(SDL_MouseMotionEvent const& event) {
//if out of bounds, exit
if (!CheckBounds(event.x, event.y)) {
@@ -156,6 +140,22 @@ Button::State Button::GetState() {
return state;
}
int Button::SetX(int i) {
return posX = i;
}
int Button::SetY(int i) {
return posY = i;
}
int Button::GetX() const {
return posX;
}
int Button::GetY() const {
return posY;
}
bool Button::CheckBounds(int x, int y) {
//return if true (x, y) is within bounds, otherwise return false
return !(
+9 -10
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
* warranty. In no event will the authors be held liable for any damages
@@ -27,11 +27,6 @@
#include <string>
constexpr SDL_Color COLOR_WHITE = {255, 255, 255, 255};
constexpr SDL_Color COLOR_RED = {255, 0, 0, 255};
constexpr SDL_Color COLOR_ORANGE = {255, 127, 0, 255};
constexpr SDL_Color COLOR_BLUE = {0, 0, 255, 255};
class Button {
public:
enum State {
@@ -46,9 +41,7 @@ public:
//setup
void SetBackgroundTexture(SDL_Renderer*, SDL_Texture*);
void SetText(SDL_Renderer*, TTF_Font*, std::string, SDL_Color);
void SetX(int x);
void SetY(int y);
void SetText(SDL_Renderer*, TTF_Font*, SDL_Color, std::string);
//capture input
State MouseMotion(SDL_MouseMotionEvent const&);
@@ -59,10 +52,16 @@ public:
void SetState(State); //TODO: idle, busy or disabled
State GetState();
//accessors & mutators
int SetX(int x);
int SetY(int y);
int GetX() const;
int GetY() const;
protected:
bool CheckBounds(int x, int y);
Image image;
int posX = 0, posY = 0;
State state = State::IDLE;
int posX = 0, posY = 0;
};
+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;
}
+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
* 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;
if (SDL_QueryTexture(texture, nullptr, nullptr, &clip.w, &clip.h)) {
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();
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
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
#config
INCLUDES+=.
INCLUDES+=. ../utilities
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
+46
View File
@@ -0,0 +1,46 @@
/* 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 "render_text_texture.hpp"
#include <stdexcept>
SDL_Texture* renderTextTexture(SDL_Renderer* renderer, TTF_Font* font, SDL_Color color, std::string str) {
//make the surface (from SDL_ttf)
SDL_Surface* surface = TTF_RenderText_Solid(font, str.c_str(), color);
if (!surface) {
throw(std::runtime_error("Failed to create a TTF surface"));
}
//convert to texture
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface);
//cleanup
SDL_FreeSurface(surface);
//check
if (!texture) {
throw(std::runtime_error("Failed to create a TTF texture"));
}
//NOTE: free the texture yourself
return texture;
}
+29
View File
@@ -0,0 +1,29 @@
/* 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 "SDL2/SDL.h"
#include "SDL2/SDL_ttf.h"
#include <string>
SDL_Texture* renderTextTexture(SDL_Renderer*, TTF_Font*, SDL_Color color, std::string);
+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
* 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
* warranty. In no event will the authors be held liable for any damages
+26 -7
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
* warranty. In no event will the authors be held liable for any damages
@@ -31,15 +31,18 @@ TextBox::~TextBox() {
//
}
void TextBox::DrawTo(SDL_Renderer* renderer, int posX, int posY, int pointSize) {
void TextBox::DrawTo(SDL_Renderer* renderer) {
int renderY = posY;
for (std::list<TextLine>::iterator it = lineList.begin(); it != lineList.end(); it++) {
it->DrawTo(renderer, posX, posY);
posY += pointSize;
it->SetX(posX);
it->SetY(renderY);
it->DrawTo(renderer);
renderY += it->GetPointHeight();
}
}
void TextBox::PushLine(SDL_Renderer* renderer, TTF_Font* font, std::string str, SDL_Color color) {
lineList.emplace_front(renderer, font, str, color);
void TextBox::PushLine(SDL_Renderer* renderer, TTF_Font* font, SDL_Color color, std::string str) {
lineList.emplace_back(renderer, font, color, str, 0, 0);
}
void TextBox::PopLine(int num) {
@@ -47,10 +50,26 @@ void TextBox::PopLine(int num) {
num < lineList.size() ? num : lineList.size();
for (int i = 0; i < num; ++i) {
lineList.pop_back();
lineList.pop_front();
}
}
void TextBox::ClearLines() {
lineList.clear();
}
int TextBox::SetX(int i) {
return posX = i;
}
int TextBox::SetY(int i) {
return posY = i;
}
int TextBox::GetX() const {
return posX;
}
int TextBox::GetY() const {
return posY;
}
+9 -3
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
* warranty. In no event will the authors be held liable for any damages
@@ -34,12 +34,18 @@ public:
TextBox();
~TextBox();
void DrawTo(SDL_Renderer*, int posX, int posY, int pointSize);
void DrawTo(SDL_Renderer*);
void PushLine(SDL_Renderer*, TTF_Font*, std::string, SDL_Color color);
void PushLine(SDL_Renderer*, TTF_Font*, SDL_Color color, std::string);
void PopLine(int num = 1);
void ClearLines();
int SetX(int i);
int SetY(int i);
int GetX() const;
int GetY() const;
private:
std::list<TextLine> lineList;
int posX = 0, posY = 0;
};
+109
View File
@@ -0,0 +1,109 @@
/* 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 "text_field.hpp"
#include "render_text_texture.hpp"
TextField::TextField() {
//
}
TextField::~TextField() {
SDL_DestroyTexture(texture);
}
void TextField::DrawTo(SDL_Renderer* renderer) {
if (!texture) {
return;
}
SDL_Rect dclip = {posX, posY, 0, 0};
SDL_QueryTexture(texture, nullptr, nullptr, &dclip.w, &dclip.h);
SDL_RenderCopy(renderer, texture, nullptr, &dclip);
}
std::string TextField::PushText(SDL_Renderer* renderer, TTF_Font* font, SDL_Color color, std::string s) {
text += s;
return SetText(renderer, font, color, text);
}
std::string TextField::SetText(SDL_Renderer* renderer, TTF_Font* font, SDL_Color color, std::string s) {
text = s;
SDL_DestroyTexture(texture);
if (text.size()) {
texture = renderTextTexture(renderer, font, color, text);
}
else {
texture = nullptr;
}
return text;
}
std::string TextField::PopChars(SDL_Renderer* renderer, TTF_Font* font, SDL_Color color, int i) {
if (text.size() > 0) {
text.erase(text.size() - i);
}
return SetText(renderer, font, color, text);
}
std::string TextField::GetText() {
return text;
}
bool TextField::MouseButtonDown(SDL_MouseButtonEvent const& event) {
BoundingBox cursorBox = {event.x, event.y, 0, 0};
BoundingBox fieldBox = bounds;
fieldBox.x += posX;
fieldBox.y += posY;
return focus = fieldBox.CheckOverlap(cursorBox);
}
BoundingBox TextField::SetBounds(BoundingBox b) {
return bounds = b;
}
BoundingBox TextField::GetBounds() {
return bounds;
}
bool TextField::SetFocus(bool b) {
return focus = b;
}
bool TextField::GetFocus() {
return focus;
}
int TextField::SetX(int i) {
return posX = i;
}
int TextField::SetY(int i) {
return posY = i;
}
int TextField::GetX() const {
return posX;
}
int TextField::GetY() const {
return posY;
}
+65
View File
@@ -0,0 +1,65 @@
/* 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 "bounding_box.hpp"
#include "SDL2/SDL.h"
#include "SDL2/SDL_ttf.h"
#include <string>
class TextField {
public:
TextField();
~TextField();
void DrawTo(SDL_Renderer*);
//input
std::string PushText(SDL_Renderer*, TTF_Font*, SDL_Color color, std::string);
std::string SetText(SDL_Renderer*, TTF_Font*, SDL_Color color, std::string);
std::string PopChars(SDL_Renderer*, TTF_Font*, SDL_Color color, int i);
std::string GetText();
bool MouseButtonDown(SDL_MouseButtonEvent const& event);
BoundingBox SetBounds(BoundingBox b);
BoundingBox GetBounds();
bool SetFocus(bool b);
bool GetFocus();
//accessors & mutators
int SetX(int i);
int SetY(int i);
int GetX() const;
int GetY() const;
private:
SDL_Texture* texture = nullptr;
std::string text;
BoundingBox bounds;
bool focus = false;
int posX = 0, posY = 0;
};
+34 -26
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
* warranty. In no event will the authors be held liable for any damages
@@ -21,50 +21,58 @@
*/
#include "text_line.hpp"
#include "render_text_texture.hpp"
#include <stdexcept>
SDL_Texture* renderTextTexture(SDL_Renderer* renderer, TTF_Font* font, std::string str, SDL_Color color) {
//make the surface (from SDL_ttf)
SDL_Surface* surface = TTF_RenderText_Solid(font, str.c_str(), color);
if (!surface) {
throw(std::runtime_error("Failed to create a TTF surface"));
}
//convert to texture
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface);
//cleanup
SDL_FreeSurface(surface);
//check
if (!texture) {
throw(std::runtime_error("Failed to create a TTF texture"));
}
//NOTE: free the texture yourself
return texture;
}
TextLine::TextLine() {
//
}
TextLine::TextLine(SDL_Renderer* renderer, TTF_Font* font, SDL_Color color, std::string str, int x, int y) {
SetText(renderer, font, color, str);
posX = x;
posY = y;
}
TextLine::~TextLine() {
ClearText();
}
void TextLine::DrawTo(SDL_Renderer* renderer, int posX, int posY) {
void TextLine::DrawTo(SDL_Renderer* renderer) {
SDL_Rect dclip = {posX, posY, 0, 0};
SDL_QueryTexture(texture, nullptr, nullptr, &dclip.w, &dclip.h);
SDL_RenderCopy(renderer, texture, nullptr, &dclip);
}
void TextLine::SetText(SDL_Renderer* renderer, TTF_Font* font, std::string str, SDL_Color color) {
void TextLine::SetText(SDL_Renderer* renderer, TTF_Font* font, SDL_Color color, std::string str) {
//just use the above global function
SDL_DestroyTexture(texture);
texture = renderTextTexture(renderer, font, str, color);
texture = renderTextTexture(renderer, font, color, str);
pointHeight = TTF_FontHeight(font);
}
void TextLine::ClearText() {
SDL_DestroyTexture(texture);
pointHeight = 0;
}
int TextLine::SetX(int i) {
return posX = i;
}
int TextLine::SetY(int i) {
return posY = i;
}
int TextLine::GetX() const {
return posX;
}
int TextLine::GetY() const {
return posY;
}
int TextLine::GetPointHeight() {
return pointHeight;
}
+15 -7
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
* warranty. In no event will the authors be held liable for any damages
@@ -26,20 +26,28 @@
#include <string>
SDL_Texture* renderTextTexture(SDL_Renderer*, TTF_Font*, std::string, SDL_Color color);
class TextLine {
public:
TextLine();
TextLine(SDL_Renderer* r, TTF_Font* f, std::string s, SDL_Color c)
{ SetText(r, f, s, c); }
TextLine(SDL_Renderer*, TTF_Font*, SDL_Color, std::string, int x, int y);
virtual ~TextLine();
void DrawTo(SDL_Renderer*, int posX, int posY);
void DrawTo(SDL_Renderer*);
void SetText(SDL_Renderer*, TTF_Font*, std::string, SDL_Color color);
void SetText(SDL_Renderer*, TTF_Font*, SDL_Color, std::string);
void ClearText();
//accessors & mutators
int SetX(int i);
int SetY(int i);
int GetX() const;
int GetY() const;
//utility
int GetPointHeight();
protected:
SDL_Texture* texture = nullptr;
int posX = 0, posY = 0;
int pointHeight = 0; //internal use for TextBox
};
+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
* 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;
}
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) {
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
* warranty. In no event will the authors be held liable for any damages
@@ -41,7 +41,7 @@ public:
~Region() = default;
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 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
* 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
* 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
* 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
* 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
* 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);
}
//Bug Origin?
Region::type_t RegionPagerBase::GetTile(int x, int y, int z) {
Region* ptr = GetRegion(x, y);
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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
* warranty. In no event will the authors be held liable for any damages
+10 -8
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
* warranty. In no event will the authors be held liable for any damages
@@ -22,6 +22,7 @@
#pragma once
#include "serial_packet_base.hpp"
#include "barrier_packet.hpp"
#include "character_packet.hpp"
#include "client_packet.hpp"
#include "creature_packet.hpp"
@@ -33,15 +34,16 @@
typedef SerialPacketBase SerialPacket;
//DOCS: NETWORK_VERSION is used to discern compatible servers and clients
constexpr int NETWORK_VERSION = 20160321;
constexpr int NETWORK_VERSION = 20160825;
union MaxPacket {
CharacterPacket a;
ClientPacket b;
CreaturePacket c;
RegionPacket d;
ServerPacket e;
TextPacket f;
BarrierPacket a;
CharacterPacket b;
ClientPacket c;
CreaturePacket d;
RegionPacket e;
ServerPacket f;
TextPacket g;
};
constexpr int MAX_PACKET_SIZE = sizeof(MaxPacket);
+24 -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
* warranty. In no event will the authors be held liable for any damages
@@ -165,9 +165,31 @@ enum class SerialPacketType {
FORMAT_END_TEXT = 699,
//-------------------------
//BarrierPacket
// barrier index,
// bounds,
// roomIndex, origin, motion
// status
//-------------------------
FORMAT_BARRIER = 700,
BARRIER_UPDATE = 701,
BARRIER_CREATE = 702,
BARRIER_UNLOAD = 703,
QUERY_BARRIER_EXISTS = 704,
BARRIER_ENTRY = 705,
BARRIER_EXIT = 706,
FORMAT_END_BARRIER = 799,
//-------------------------
//not used
//-------------------------
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
* warranty. In no event will the authors be held liable for any damages
@@ -22,6 +22,7 @@
#include "serial_utility.hpp"
//packet types
#include "barrier_packet.hpp"
#include "character_packet.hpp"
#include "client_packet.hpp"
#include "creature_packet.hpp"
@@ -72,6 +73,10 @@ void serializePacket(void* buffer, SerialPacketBase* packet) {
if (BOUNDS(packet->type, SerialPacketType::FORMAT_TEXT, SerialPacketType::FORMAT_END_TEXT)) {
serializeText(buffer, static_cast<TextPacket*>(packet));
}
if (BOUNDS(packet->type, SerialPacketType::FORMAT_BARRIER, SerialPacketType::FORMAT_END_BARRIER)) {
serializeBarrier(buffer, static_cast<BarrierPacket*>(packet));
}
}
void deserializePacket(void* buffer, SerialPacketBase* packet) {
@@ -102,4 +107,8 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) {
if (BOUNDS(type, SerialPacketType::FORMAT_TEXT, SerialPacketType::FORMAT_END_TEXT)) {
deserializeText(buffer, static_cast<TextPacket*>(packet));
}
if (BOUNDS(type, SerialPacketType::FORMAT_BARRIER, SerialPacketType::FORMAT_END_BARRIER)) {
deserializeBarrier(buffer, static_cast<BarrierPacket*>(packet));
}
}

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