Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fdaae0e8f2 | |||
| bd3838a04e |
@@ -20,17 +20,13 @@ The most recent stable build for Windows can be found [here](https://dl.dropboxu
|
|||||||
* [lua 5.2](http://www.lua.org/) - The lua programming language
|
* [lua 5.2](http://www.lua.org/) - The lua programming language
|
||||||
* [SQLite3](http://www.sqlite.org/) - A lightweight SQL database engine
|
* [SQLite3](http://www.sqlite.org/) - A lightweight SQL database engine
|
||||||
|
|
||||||
## Tools
|
|
||||||
|
|
||||||
* [WinRAR](http://www.rarlab.com/) - The best compression tool available IMO; only needed for distribution
|
|
||||||
|
|
||||||
## Copyright
|
## Copyright
|
||||||
|
|
||||||
(Future versions (to be determined) may be released under a modified version of the [Uplink Developer's License](http://www.introversion.co.uk/uplink/developer/license.html).)
|
(Future versions (to be determined) may be released under a modified version of the [Uplink Developer's License](http://www.introversion.co.uk/uplink/developer/license.html).)
|
||||||
|
|
||||||
The current version of Tortuga is released under the [zlib license](http://en.wikipedia.org/wiki/Zlib_License).
|
The current version of Tortuga is released under the [zlib license](http://en.wikipedia.org/wiki/Zlib_License).
|
||||||
|
|
||||||
Copyright (c) 2013-2015 Kayne Ruse
|
Copyright (c) 2013, 2014 Kayne Ruse
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
|
|||||||
+6
-7
@@ -14,10 +14,9 @@ Both a game server and game client are included in this package.
|
|||||||
Instructions For Setup
|
Instructions For Setup
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
1. To create a server, simply run server.exe
|
1. To create a server, simply run server.exe.
|
||||||
(a public server is provided by default)
|
2. To join that server, run client.exe with config settings not already in use.
|
||||||
2. To join a server, your player information must be input into rsc/config.cfg
|
(Note: This process will be streamlined later).
|
||||||
(NOTE: This process will be streamlined later)
|
|
||||||
3. To change the config settings, open rsc/config.cfg
|
3. To change the config settings, open rsc/config.cfg
|
||||||
4. These settings must be unique for each player:
|
4. These settings must be unique for each player:
|
||||||
|
|
||||||
@@ -29,7 +28,7 @@ Instructions For Setup
|
|||||||
* client.avatar = elliot2.bmp #male
|
* client.avatar = elliot2.bmp #male
|
||||||
* client.avatar = coa2.bmp #female
|
* client.avatar = coa2.bmp #female
|
||||||
|
|
||||||
6. When you've correctly set these values, run client.exe, and select 'Start'
|
6. When you've correctly set these values (good luck), select 'Start' from the
|
||||||
from the main menu; this displays the list of available servers.
|
main menu; this displays the list of available servers.
|
||||||
7. Select the name of a server (default is 'Public') and select 'Join'.
|
7. Select the name of your server (default is 'local') and select 'Join'.
|
||||||
8. Welcome to Tortuga, enjoy your stay.
|
8. Welcome to Tortuga, enjoy your stay.
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
* arising from the use of this software.
|
* arising from the use of this software.
|
||||||
*
|
*
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
* including commercial applications, and to alter it and redistribute it
|
* including commercial ClientApplications, and to alter it and redistribute it
|
||||||
* freely, subject to the following restrictions:
|
* freely, subject to the following restrictions:
|
||||||
*
|
*
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
#include "main_menu.hpp"
|
#include "main_menu.hpp"
|
||||||
#include "options_menu.hpp"
|
#include "options_menu.hpp"
|
||||||
#include "lobby_menu.hpp"
|
#include "lobby_menu.hpp"
|
||||||
#include "world.hpp"
|
#include "in_world.hpp"
|
||||||
#include "disconnected_screen.hpp"
|
#include "disconnected_screen.hpp"
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -49,7 +49,7 @@ void ClientApplication::Init(int argc, char* argv[]) {
|
|||||||
|
|
||||||
//load the prerequisites
|
//load the prerequisites
|
||||||
ConfigUtility& config = ConfigUtility::GetSingleton();
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
config.Load("rsc/config.cfg", false, argc, argv);
|
config.Load("rsc/config.cfg", argc, argv);
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Initialize the APIs
|
//Initialize the APIs
|
||||||
@@ -83,6 +83,7 @@ void ClientApplication::Init(int argc, char* argv[]) {
|
|||||||
//debug output
|
//debug output
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
|
//TODO: enable/disable these with a switch
|
||||||
#define DEBUG_OUTPUT_VAR(x) std::cout << "\t" << #x << ": " << x << std::endl;
|
#define DEBUG_OUTPUT_VAR(x) std::cout << "\t" << #x << ": " << x << std::endl;
|
||||||
|
|
||||||
std::cout << "Internal sizes:" << std::endl;
|
std::cout << "Internal sizes:" << std::endl;
|
||||||
@@ -136,17 +137,11 @@ void ClientApplication::Proc() {
|
|||||||
realTime = Clock::now();
|
realTime = Clock::now();
|
||||||
|
|
||||||
//simulate game time
|
//simulate game time
|
||||||
if (simTime < realTime) {
|
while (simTime < realTime) {
|
||||||
while (simTime < realTime) {
|
//call each user defined function
|
||||||
//call each user defined function
|
activeScene->RunFrame();
|
||||||
activeScene->RunFrame();
|
//~60 FPS
|
||||||
//~60 FPS
|
simTime += std::chrono::duration<int, std::milli>(16);
|
||||||
simTime += std::chrono::duration<int, std::milli>(16);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
//give the machine a break
|
|
||||||
SDL_Delay(10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//draw the game to the screen
|
//draw the game to the screen
|
||||||
@@ -183,10 +178,10 @@ void ClientApplication::LoadScene(SceneList sceneIndex) {
|
|||||||
activeScene = new OptionsMenu();
|
activeScene = new OptionsMenu();
|
||||||
break;
|
break;
|
||||||
case SceneList::LOBBYMENU:
|
case SceneList::LOBBYMENU:
|
||||||
activeScene = new LobbyMenu(&clientIndex, &accountIndex);
|
activeScene = new LobbyMenu(&clientIndex, &accountIndex); //TODO: can I use the ConfigUtility for these parameters?
|
||||||
break;
|
break;
|
||||||
case SceneList::WORLD:
|
case SceneList::INWORLD:
|
||||||
activeScene = new World(&clientIndex, &accountIndex);
|
activeScene = new InWorld(&clientIndex, &accountIndex);
|
||||||
break;
|
break;
|
||||||
case SceneList::DISCONNECTEDSCREEN:
|
case SceneList::DISCONNECTEDSCREEN:
|
||||||
activeScene = new DisconnectedScreen();
|
activeScene = new DisconnectedScreen();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
|
||||||
*
|
|
||||||
* 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 "terminal_error.hpp"
|
|
||||||
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
#ifndef TERMINALERROR_HPP_
|
|
||||||
#define TERMINALERROR_HPP_
|
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
class terminal_error: public std::runtime_error {
|
|
||||||
public:
|
|
||||||
explicit terminal_error(const std::string& str): runtime_error(str) {}
|
|
||||||
explicit terminal_error(const char* cstr): runtime_error(cstr) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -21,12 +21,6 @@
|
|||||||
*/
|
*/
|
||||||
#include "base_character.hpp"
|
#include "base_character.hpp"
|
||||||
|
|
||||||
#include "config_utility.hpp"
|
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
//graphics
|
|
||||||
//-------------------------
|
|
||||||
|
|
||||||
void BaseCharacter::CorrectSprite() {
|
void BaseCharacter::CorrectSprite() {
|
||||||
//NOTE: These must correspond to the sprite sheet in use
|
//NOTE: These must correspond to the sprite sheet in use
|
||||||
if (motion.y > 0) {
|
if (motion.y > 0) {
|
||||||
@@ -51,33 +45,3 @@ void BaseCharacter::CorrectSprite() {
|
|||||||
sprite.SetXIndex(0);
|
sprite.SetXIndex(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
//metadata
|
|
||||||
//-------------------------
|
|
||||||
|
|
||||||
int BaseCharacter::SetOwner(int i) {
|
|
||||||
return owner = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
int BaseCharacter::GetOwner() {
|
|
||||||
return owner;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string BaseCharacter::SetHandle(std::string s) {
|
|
||||||
return handle = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string BaseCharacter::GetHandle() const {
|
|
||||||
return handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string BaseCharacter::SetAvatar(std::string s) {
|
|
||||||
avatar = s;
|
|
||||||
sprite.LoadSurface(ConfigUtility::GetSingleton()["dir.sprites"] + avatar, CHARACTER_CELLS_X, CHARACTER_CELLS_Y);
|
|
||||||
return avatar;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string BaseCharacter::GetAvatar() const {
|
|
||||||
return avatar;
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
//std namespace
|
//std namespace
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class BaseCharacter: public Entity {
|
class BaseCharacter : public Entity {
|
||||||
public:
|
public:
|
||||||
BaseCharacter() = default;
|
BaseCharacter() = default;
|
||||||
virtual ~BaseCharacter() = default;
|
virtual ~BaseCharacter() = default;
|
||||||
@@ -38,14 +38,14 @@ public:
|
|||||||
void CorrectSprite();
|
void CorrectSprite();
|
||||||
|
|
||||||
//metadata
|
//metadata
|
||||||
int SetOwner(int i);
|
int SetOwner(int i) { return owner = i; }
|
||||||
int GetOwner();
|
int GetOwner() { return owner; }
|
||||||
std::string SetHandle(std::string s);
|
std::string SetHandle(std::string s) { return handle = s; }
|
||||||
std::string GetHandle() const;
|
std::string GetHandle() const { return handle; }
|
||||||
std::string SetAvatar(std::string s);
|
std::string SetAvatar(std::string s) { return avatar = s; }
|
||||||
std::string GetAvatar() const;
|
std::string GetAvatar() const { return avatar; }
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
//metadata
|
//metadata
|
||||||
int owner;
|
int owner;
|
||||||
std::string handle;
|
std::string handle;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -21,26 +21,3 @@
|
|||||||
*/
|
*/
|
||||||
#include "base_monster.hpp"
|
#include "base_monster.hpp"
|
||||||
|
|
||||||
#include "config_utility.hpp"
|
|
||||||
|
|
||||||
void BaseMonster::CorrectSprite() {
|
|
||||||
//TODO: (9) empty
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string BaseMonster::SetHandle(std::string s) {
|
|
||||||
return handle = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string BaseMonster::GetHandle() const {
|
|
||||||
return handle;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string BaseMonster::SetAvatar(std::string s) {
|
|
||||||
avatar = s;
|
|
||||||
sprite.LoadSurface(ConfigUtility::GetSingleton()["dir.sprites"] + avatar, 4, 1);
|
|
||||||
return avatar;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string BaseMonster::GetAvatar() const {
|
|
||||||
return avatar;
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -24,22 +24,13 @@
|
|||||||
|
|
||||||
#include "entity.hpp"
|
#include "entity.hpp"
|
||||||
|
|
||||||
class BaseMonster: public Entity {
|
class BaseMonster : public Entity {
|
||||||
public:
|
public:
|
||||||
BaseMonster() = default;
|
BaseMonster() = default;
|
||||||
virtual ~BaseMonster() = default;
|
virtual ~BaseMonster() = default;
|
||||||
|
|
||||||
void CorrectSprite();
|
private:
|
||||||
|
//
|
||||||
std::string SetHandle(std::string s);
|
|
||||||
std::string GetHandle() const;
|
|
||||||
std::string SetAvatar(std::string s);
|
|
||||||
std::string GetAvatar() const;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
//metadata
|
|
||||||
std::string handle;
|
|
||||||
std::string avatar;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
+11
-12
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -30,13 +30,13 @@ void Entity::DrawTo(SDL_Surface* const dest, int camX, int camY) {
|
|||||||
sprite.DrawTo(dest, origin.x - camX, origin.y - camY);
|
sprite.DrawTo(dest, origin.x - camX, origin.y - camY);
|
||||||
}
|
}
|
||||||
|
|
||||||
SpriteSheet* Entity::GetSprite() {
|
int Entity::SetEntityIndex(int i) {
|
||||||
return &sprite;
|
return entityIndex = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
int Entity::SetRoomIndex(int i) {
|
||||||
//accessors & mutators
|
return roomIndex = i;
|
||||||
//-------------------------
|
}
|
||||||
|
|
||||||
Vector2 Entity::SetOrigin(Vector2 v) {
|
Vector2 Entity::SetOrigin(Vector2 v) {
|
||||||
return origin = v;
|
return origin = v;
|
||||||
@@ -45,9 +45,12 @@ Vector2 Entity::SetOrigin(Vector2 v) {
|
|||||||
Vector2 Entity::SetMotion(Vector2 v) {
|
Vector2 Entity::SetMotion(Vector2 v) {
|
||||||
return motion = v;
|
return motion = v;
|
||||||
}
|
}
|
||||||
|
int Entity::GetEntityIndex() {
|
||||||
|
return entityIndex;
|
||||||
|
}
|
||||||
|
|
||||||
BoundingBox Entity::SetBounds(BoundingBox b) {
|
int Entity::GetRoomIndex() {
|
||||||
return bounds = b;
|
return roomIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Entity::GetOrigin() {
|
Vector2 Entity::GetOrigin() {
|
||||||
@@ -56,8 +59,4 @@ Vector2 Entity::GetOrigin() {
|
|||||||
|
|
||||||
Vector2 Entity::GetMotion() {
|
Vector2 Entity::GetMotion() {
|
||||||
return motion;
|
return motion;
|
||||||
}
|
|
||||||
|
|
||||||
BoundingBox Entity::GetBounds() {
|
|
||||||
return bounds;
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -32,22 +32,28 @@ public:
|
|||||||
virtual void Update();
|
virtual void Update();
|
||||||
virtual void DrawTo(SDL_Surface* const, int camX, int camY);
|
virtual void DrawTo(SDL_Surface* const, int camX, int camY);
|
||||||
|
|
||||||
SpriteSheet* GetSprite();
|
SpriteSheet* GetSprite() { return &sprite; }
|
||||||
|
|
||||||
//accessors & mutators
|
//accessors & mutators
|
||||||
|
int SetEntityIndex(int i);
|
||||||
|
int SetRoomIndex(int i);
|
||||||
Vector2 SetOrigin(Vector2 v);
|
Vector2 SetOrigin(Vector2 v);
|
||||||
Vector2 SetMotion(Vector2 v);
|
Vector2 SetMotion(Vector2 v);
|
||||||
BoundingBox SetBounds(BoundingBox b);
|
BoundingBox SetBounds(BoundingBox b) { return bounds = b; }
|
||||||
|
|
||||||
|
int GetEntityIndex();
|
||||||
|
int GetRoomIndex();
|
||||||
Vector2 GetOrigin();
|
Vector2 GetOrigin();
|
||||||
Vector2 GetMotion();
|
Vector2 GetMotion();
|
||||||
BoundingBox GetBounds();
|
BoundingBox GetBounds() { return bounds; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Entity() = default;
|
Entity() = default;
|
||||||
virtual ~Entity() = default;
|
~Entity() = default;
|
||||||
|
|
||||||
SpriteSheet sprite;
|
SpriteSheet sprite;
|
||||||
|
int entityIndex = -1;
|
||||||
|
int roomIndex = -1;
|
||||||
Vector2 origin;
|
Vector2 origin;
|
||||||
Vector2 motion;
|
Vector2 motion;
|
||||||
BoundingBox bounds;
|
BoundingBox bounds;
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
|
||||||
*
|
|
||||||
* 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 "local_character.hpp"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
bool LocalCharacter::ProcessCollisionGrid(std::list<BoundingBox> boxList) {
|
|
||||||
for(auto& box : boxList) {
|
|
||||||
if (box.CheckOverlap(origin + bounds)) {
|
|
||||||
origin -= motion;
|
|
||||||
motion = {0, 0};
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
#config
|
|
||||||
INCLUDES+=. .. ../client_utilities ../entities ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/network/packet_types ../../common/ui ../../common/utilities
|
|
||||||
LIBS+=
|
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
|
||||||
|
|
||||||
#source
|
|
||||||
CXXSRC=$(wildcard *.cpp)
|
|
||||||
|
|
||||||
#objects
|
|
||||||
OBJDIR=obj
|
|
||||||
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
|
||||||
|
|
||||||
#output
|
|
||||||
OUTDIR=..
|
|
||||||
OUT=$(addprefix $(OUTDIR)/,client.a)
|
|
||||||
|
|
||||||
#targets
|
|
||||||
all: $(OBJ) $(OUT)
|
|
||||||
ar -crs $(OUT) $(OBJ)
|
|
||||||
|
|
||||||
$(OBJ): | $(OBJDIR)
|
|
||||||
|
|
||||||
$(OUT): | $(OUTDIR)
|
|
||||||
|
|
||||||
$(OBJDIR):
|
|
||||||
mkdir $(OBJDIR)
|
|
||||||
|
|
||||||
$(OUTDIR):
|
|
||||||
mkdir $(OUTDIR)
|
|
||||||
|
|
||||||
$(OBJDIR)/%.o: %.cpp
|
|
||||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(RM) *.o *.a *.exe
|
|
||||||
|
|
||||||
rebuild: clean all
|
|
||||||
@@ -1,207 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
|
||||||
*
|
|
||||||
* 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 "world.hpp"
|
|
||||||
|
|
||||||
#include "channels.hpp"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
//character management
|
|
||||||
//-------------------------
|
|
||||||
|
|
||||||
//DOCS: preexisting characters will result in query responses
|
|
||||||
//DOCS: new characters will result in create messages
|
|
||||||
//DOCS: this client's character will exist in both (skipped)
|
|
||||||
|
|
||||||
void World::hCharacterCreate(CharacterPacket* const argPacket) {
|
|
||||||
//prevent double message
|
|
||||||
if (characterMap.find(argPacket->characterIndex) != characterMap.end()) {
|
|
||||||
std::ostringstream msg;
|
|
||||||
msg << "Double character creation event; ";
|
|
||||||
msg << "Index: " << argPacket->characterIndex << "; ";
|
|
||||||
msg << "Handle: " << argPacket->handle;
|
|
||||||
throw(std::runtime_error(msg.str()));
|
|
||||||
}
|
|
||||||
|
|
||||||
//implicity create and retrieve the entity
|
|
||||||
BaseCharacter* character = &characterMap[argPacket->characterIndex];
|
|
||||||
|
|
||||||
//fill the character's info
|
|
||||||
character->SetOrigin(argPacket->origin);
|
|
||||||
character->SetMotion(argPacket->motion);
|
|
||||||
character->SetBounds({CHARACTER_BOUNDS_X, CHARACTER_BOUNDS_Y, CHARACTER_BOUNDS_WIDTH, CHARACTER_BOUNDS_HEIGHT}); //TODO: (1) send the bounds from the server
|
|
||||||
character->SetHandle(argPacket->handle);
|
|
||||||
character->SetAvatar(argPacket->avatar);
|
|
||||||
character->SetOwner(argPacket->accountIndex);
|
|
||||||
character->CorrectSprite();
|
|
||||||
|
|
||||||
//check for this player's character
|
|
||||||
if (character->GetOwner() == accountIndex) {
|
|
||||||
localCharacter = static_cast<LocalCharacter*>(character);
|
|
||||||
|
|
||||||
//focus the camera on this character
|
|
||||||
camera.marginX = (camera.width / 2 - localCharacter->GetSprite()->GetImage()->GetClipW() / 2);
|
|
||||||
camera.marginY = (camera.height/ 2 - localCharacter->GetSprite()->GetImage()->GetClipH() / 2);
|
|
||||||
|
|
||||||
//focus on this character's info
|
|
||||||
characterIndex = argPacket->characterIndex;
|
|
||||||
roomIndex = argPacket->roomIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
//debug
|
|
||||||
std::cout << "Character Create, total: " << characterMap.size() << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::hCharacterDelete(CharacterPacket* const argPacket) {
|
|
||||||
//ignore if this character doesn't exist
|
|
||||||
std::map<int, BaseCharacter>::iterator characterIt = characterMap.find(argPacket->characterIndex);
|
|
||||||
if (characterIt == characterMap.end()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//check for this player's character
|
|
||||||
if ((*characterIt).second.GetOwner() == accountIndex) {
|
|
||||||
localCharacter = nullptr;
|
|
||||||
|
|
||||||
//clear the camera
|
|
||||||
camera.marginX = 0;
|
|
||||||
camera.marginY = 0;
|
|
||||||
|
|
||||||
//clear the room
|
|
||||||
roomIndex = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//remove this character
|
|
||||||
characterMap.erase(characterIt);
|
|
||||||
|
|
||||||
//debug
|
|
||||||
std::cout << "Character Delete, total: " << characterMap.size() << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::hQueryCharacterExists(CharacterPacket* const argPacket) {
|
|
||||||
//prevent a double message about this player's character
|
|
||||||
if (argPacket->accountIndex == accountIndex) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//ignore characters in a different room (sub-optimal)
|
|
||||||
if (argPacket->roomIndex != roomIndex) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//implicitly construct the character if it doesn't exist
|
|
||||||
BaseCharacter* character = &characterMap[argPacket->characterIndex];
|
|
||||||
|
|
||||||
//set/update the character's info
|
|
||||||
character->SetOrigin(argPacket->origin);
|
|
||||||
character->SetMotion(argPacket->motion);
|
|
||||||
character->SetBounds({CHARACTER_BOUNDS_X, CHARACTER_BOUNDS_Y, CHARACTER_BOUNDS_WIDTH, CHARACTER_BOUNDS_HEIGHT});
|
|
||||||
character->SetHandle(argPacket->handle);
|
|
||||||
character->SetAvatar(argPacket->avatar);
|
|
||||||
character->SetOwner(argPacket->accountIndex);
|
|
||||||
character->CorrectSprite();
|
|
||||||
|
|
||||||
//debug
|
|
||||||
std::cout << "Character Query, total: " << characterMap.size() << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::hQueryCharacterStats(CharacterPacket* const argPacket) {
|
|
||||||
//TODO: (9) empty
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::hQueryCharacterLocation(CharacterPacket* const argPacket) {
|
|
||||||
//TODO: (9) empty
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::hCharacterMovement(CharacterPacket* const argPacket) {
|
|
||||||
//TODO: (1) Authentication
|
|
||||||
if (argPacket->characterIndex == characterIndex) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//check that this character exists
|
|
||||||
std::map<int, BaseCharacter>::iterator characterIt = characterMap.find(argPacket->characterIndex);
|
|
||||||
if (characterIt != characterMap.end()) {
|
|
||||||
//set the origin and motion
|
|
||||||
characterIt->second.SetOrigin(argPacket->origin);
|
|
||||||
characterIt->second.SetMotion(argPacket->motion);
|
|
||||||
characterIt->second.CorrectSprite();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::hCharacterAttack(CharacterPacket* const argPacket) {
|
|
||||||
//TODO: (9) empty
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::hCharacterDamage(CharacterPacket* const argPacket) {
|
|
||||||
//TODO: (9) empty
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
//player movement & collision
|
|
||||||
//-------------------------
|
|
||||||
|
|
||||||
void World::SendLocalCharacterMovement() {
|
|
||||||
CharacterPacket newPacket;
|
|
||||||
newPacket.type = SerialPacketType::CHARACTER_MOVEMENT;
|
|
||||||
|
|
||||||
newPacket.accountIndex = accountIndex;
|
|
||||||
newPacket.characterIndex = characterIndex;
|
|
||||||
newPacket.roomIndex = roomIndex;
|
|
||||||
newPacket.origin = localCharacter->GetOrigin();
|
|
||||||
newPacket.motion = localCharacter->GetMotion();
|
|
||||||
|
|
||||||
network.SendTo(Channels::SERVER, &newPacket);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::list<BoundingBox> World::GenerateCollisionGrid(Entity* ptr, int tileWidth, int tileHeight) {
|
|
||||||
//prepare for collisions
|
|
||||||
BoundingBox wallBounds = {0, 0, tileWidth, tileHeight};
|
|
||||||
std::list<BoundingBox> boxList;
|
|
||||||
|
|
||||||
//NOTE: for loops were too dense to work with, so I've just used while loops
|
|
||||||
|
|
||||||
//outer loop
|
|
||||||
wallBounds.x = snapToBase((double)wallBounds.w, ptr->GetOrigin().x);
|
|
||||||
while(wallBounds.x < (ptr->GetOrigin() + ptr->GetBounds()).x + ptr->GetBounds().w) {
|
|
||||||
//inner loop
|
|
||||||
wallBounds.y = snapToBase((double)wallBounds.h, ptr->GetOrigin().y);
|
|
||||||
while(wallBounds.y < (ptr->GetOrigin() + ptr->GetBounds()).y + ptr->GetBounds().h) {
|
|
||||||
//check to see if this tile is solid
|
|
||||||
if (regionPager.GetSolid(wallBounds.x / wallBounds.w, wallBounds.y / wallBounds.h)) {
|
|
||||||
//push onto the box set
|
|
||||||
boxList.push_front(wallBounds);
|
|
||||||
}
|
|
||||||
|
|
||||||
//increment
|
|
||||||
wallBounds.y += wallBounds.h;
|
|
||||||
}
|
|
||||||
|
|
||||||
//increment
|
|
||||||
wallBounds.x += wallBounds.w;
|
|
||||||
}
|
|
||||||
|
|
||||||
return std::move(boxList);
|
|
||||||
}
|
|
||||||
@@ -1,135 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
|
||||||
*
|
|
||||||
* 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 "world.hpp"
|
|
||||||
|
|
||||||
#include "channels.hpp"
|
|
||||||
#include "ip_operators.hpp"
|
|
||||||
|
|
||||||
#include <chrono>
|
|
||||||
#include <sstream>
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
//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();
|
|
||||||
SetNextScene(SceneList::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
|
|
||||||
//-------------------------
|
|
||||||
|
|
||||||
void World::SendLogoutRequest() {
|
|
||||||
ClientPacket newPacket;
|
|
||||||
|
|
||||||
//send a logout request
|
|
||||||
newPacket.type = SerialPacketType::LOGOUT_REQUEST;
|
|
||||||
newPacket.accountIndex = accountIndex;
|
|
||||||
|
|
||||||
network.SendTo(Channels::SERVER, &newPacket);
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::SendDisconnectRequest() {
|
|
||||||
ClientPacket newPacket;
|
|
||||||
|
|
||||||
//send a disconnect request
|
|
||||||
newPacket.type = SerialPacketType::DISCONNECT_REQUEST;
|
|
||||||
newPacket.clientIndex = clientIndex;
|
|
||||||
|
|
||||||
network.SendTo(Channels::SERVER, &newPacket);
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::SendAdminDisconnectForced() {
|
|
||||||
//TODO: (9) empty
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void World::SendAdminShutdownRequest() {
|
|
||||||
ClientPacket newPacket;
|
|
||||||
|
|
||||||
//send a shutdown request
|
|
||||||
newPacket.type = SerialPacketType::ADMIN_SHUTDOWN_REQUEST;
|
|
||||||
newPacket.accountIndex = accountIndex;
|
|
||||||
|
|
||||||
network.SendTo(Channels::SERVER, &newPacket);
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::hLogoutResponse(ClientPacket* const argPacket) {
|
|
||||||
if (localCharacter) {
|
|
||||||
characterMap.erase(characterIndex);
|
|
||||||
localCharacter = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
accountIndex = -1;
|
|
||||||
characterIndex = -1;
|
|
||||||
|
|
||||||
//reset the camera
|
|
||||||
camera.marginX = camera.marginY = 0;
|
|
||||||
|
|
||||||
//because, why not? I guess...
|
|
||||||
SendDisconnectRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::hDisconnectResponse(ClientPacket* const argPacket) {
|
|
||||||
hLogoutResponse(argPacket);//shortcut
|
|
||||||
SetNextScene(SceneList::DISCONNECTEDSCREEN);
|
|
||||||
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have successfully logged out";
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::hAdminDisconnectForced(ClientPacket* const argPacket) {
|
|
||||||
hDisconnectResponse(argPacket);//shortcut
|
|
||||||
SetNextScene(SceneList::DISCONNECTEDSCREEN);
|
|
||||||
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been forcibly disconnected by the server";
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,418 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
|
||||||
*
|
|
||||||
* 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 "world.hpp"
|
|
||||||
|
|
||||||
#include "channels.hpp"
|
|
||||||
|
|
||||||
#include "terminal_error.hpp"
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cmath>
|
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
//Public access members
|
|
||||||
//-------------------------
|
|
||||||
|
|
||||||
World::World(int* const argClientIndex, int* const argAccountIndex):
|
|
||||||
clientIndex(*argClientIndex),
|
|
||||||
accountIndex(*argAccountIndex)
|
|
||||||
{
|
|
||||||
//setup the utility objects
|
|
||||||
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
|
||||||
buttonImage.SetClipH(buttonImage.GetClipH()/3);
|
|
||||||
font.LoadSurface(config["dir.fonts"] + "pk_white_8.bmp");
|
|
||||||
|
|
||||||
//pass the utility objects
|
|
||||||
disconnectButton.SetImage(&buttonImage);
|
|
||||||
disconnectButton.SetFont(&font);
|
|
||||||
shutDownButton.SetImage(&buttonImage);
|
|
||||||
shutDownButton.SetFont(&font);
|
|
||||||
|
|
||||||
//set the button positions
|
|
||||||
disconnectButton.SetX(50);
|
|
||||||
disconnectButton.SetY(50 + buttonImage.GetClipH() * 0);
|
|
||||||
shutDownButton.SetX(50);
|
|
||||||
shutDownButton.SetY(50 + buttonImage.GetClipH() * 1);
|
|
||||||
|
|
||||||
//set the button texts
|
|
||||||
disconnectButton.SetText("Disconnect");
|
|
||||||
shutDownButton.SetText("Shut Down");
|
|
||||||
|
|
||||||
//load the tilesheet
|
|
||||||
//TODO: (1) Tile size and tile sheet should be loaded elsewhere
|
|
||||||
tileSheet.Load(config["dir.tilesets"] + "overworld.bmp", 32, 32);
|
|
||||||
|
|
||||||
//Send the character data
|
|
||||||
CharacterPacket newPacket;
|
|
||||||
newPacket.type = SerialPacketType::CHARACTER_LOAD;
|
|
||||||
strncpy(newPacket.handle, config["client.handle"].c_str(), PACKET_STRING_SIZE);
|
|
||||||
strncpy(newPacket.avatar, config["client.avatar"].c_str(), PACKET_STRING_SIZE);
|
|
||||||
newPacket.accountIndex = accountIndex;
|
|
||||||
network.SendTo(Channels::SERVER, &newPacket);
|
|
||||||
|
|
||||||
//query the world state
|
|
||||||
memset(&newPacket, 0, MAX_PACKET_SIZE);
|
|
||||||
newPacket.type = SerialPacketType::QUERY_CHARACTER_EXISTS;
|
|
||||||
network.SendTo(Channels::SERVER, &newPacket);
|
|
||||||
newPacket.type = SerialPacketType::QUERY_MONSTER_EXISTS;
|
|
||||||
network.SendTo(Channels::SERVER, &newPacket);
|
|
||||||
|
|
||||||
//set the camera's values
|
|
||||||
camera.width = GetScreen()->w;
|
|
||||||
camera.height = GetScreen()->h;
|
|
||||||
|
|
||||||
//debug
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
World::~World() {
|
|
||||||
//unload the local data
|
|
||||||
characterMap.clear();
|
|
||||||
monsterMap.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
//Frame loop
|
|
||||||
//-------------------------
|
|
||||||
|
|
||||||
void World::FrameStart() {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::Update() {
|
|
||||||
//create and zero the buffer
|
|
||||||
SerialPacket* packetBuffer = reinterpret_cast<SerialPacket*>(new char[MAX_PACKET_SIZE]);
|
|
||||||
memset(packetBuffer, 0, MAX_PACKET_SIZE);
|
|
||||||
|
|
||||||
try {
|
|
||||||
//suck in and process all waiting packets
|
|
||||||
while(network.Receive(packetBuffer)) {
|
|
||||||
HandlePacket(packetBuffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(terminal_error& e) {
|
|
||||||
throw(e);
|
|
||||||
}
|
|
||||||
catch(std::exception& e) {
|
|
||||||
std::cerr << "HandlePacket Error: " << e.what() << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
//free the buffer
|
|
||||||
delete reinterpret_cast<char*>(packetBuffer);
|
|
||||||
|
|
||||||
//heartbeat system
|
|
||||||
CheckHeartBeat();
|
|
||||||
|
|
||||||
//update all entities
|
|
||||||
for (auto& it : characterMap) {
|
|
||||||
it.second.Update();
|
|
||||||
}
|
|
||||||
for (auto& it : monsterMap) {
|
|
||||||
it.second.Update();
|
|
||||||
}
|
|
||||||
|
|
||||||
//update the map
|
|
||||||
UpdateMap();
|
|
||||||
|
|
||||||
//skip the rest without a local character
|
|
||||||
if (!localCharacter) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//get the collidable boxes
|
|
||||||
std::list<BoundingBox> boxList = GenerateCollisionGrid(localCharacter, tileSheet.GetTileW(), tileSheet.GetTileH());
|
|
||||||
|
|
||||||
//process the collisions
|
|
||||||
if (localCharacter->ProcessCollisionGrid(boxList)) {
|
|
||||||
localCharacter->CorrectSprite();
|
|
||||||
SendLocalCharacterMovement();
|
|
||||||
}
|
|
||||||
|
|
||||||
//update the camera
|
|
||||||
camera.x = localCharacter->GetOrigin().x - camera.marginX;
|
|
||||||
camera.y = localCharacter->GetOrigin().y - camera.marginY;
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::FrameEnd() {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::RenderFrame() {
|
|
||||||
// SDL_FillRect(GetScreen(), 0, 0);
|
|
||||||
Render(GetScreen());
|
|
||||||
SDL_Flip(GetScreen());
|
|
||||||
fps.Calculate();
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::Render(SDL_Surface* const screen) {
|
|
||||||
//draw the map
|
|
||||||
for (std::list<Region>::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); it++) {
|
|
||||||
tileSheet.DrawRegionTo(screen, &(*it), camera.x, camera.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
//draw the entities
|
|
||||||
for (auto& it : characterMap) {
|
|
||||||
//TODO: (1) depth ordering
|
|
||||||
it.second.DrawTo(screen, camera.x, camera.y);
|
|
||||||
}
|
|
||||||
for (auto& it : monsterMap) {
|
|
||||||
it.second.DrawTo(screen, camera.x, camera.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
//draw UI
|
|
||||||
disconnectButton.DrawTo(screen);
|
|
||||||
shutDownButton.DrawTo(screen);
|
|
||||||
std::ostringstream msg;
|
|
||||||
msg << fps.GetFrameRate();
|
|
||||||
font.DrawStringTo(msg.str(), screen, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
//Event handlers
|
|
||||||
//-------------------------
|
|
||||||
|
|
||||||
void World::QuitEvent() {
|
|
||||||
//two-step logout
|
|
||||||
SendDisconnectRequest();
|
|
||||||
SetNextScene(SceneList::QUIT);
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
|
||||||
disconnectButton.MouseMotion(motion);
|
|
||||||
shutDownButton.MouseMotion(motion);
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
|
||||||
disconnectButton.MouseButtonDown(button);
|
|
||||||
shutDownButton.MouseButtonDown(button);
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
|
||||||
if (disconnectButton.MouseButtonUp(button) == Button::State::HOVER && button.button == SDL_BUTTON_LEFT) {
|
|
||||||
SendLogoutRequest();
|
|
||||||
}
|
|
||||||
if (shutDownButton.MouseButtonUp(button) == Button::State::HOVER && button.button == SDL_BUTTON_LEFT) {
|
|
||||||
SendAdminShutdownRequest();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::KeyDown(SDL_KeyboardEvent const& key) {
|
|
||||||
//hotkeys
|
|
||||||
switch(key.keysym.sym) {
|
|
||||||
case SDLK_ESCAPE:
|
|
||||||
//TODO: (1) the escape key should actually control menus and stuff
|
|
||||||
SendLogoutRequest();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//character movement
|
|
||||||
if (!localCharacter) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Vector2 motion = localCharacter->GetMotion();
|
|
||||||
switch(key.keysym.sym) {
|
|
||||||
case SDLK_w:
|
|
||||||
motion.y -= CHARACTER_WALKING_SPEED;
|
|
||||||
break;
|
|
||||||
case SDLK_a:
|
|
||||||
motion.x -= CHARACTER_WALKING_SPEED;
|
|
||||||
break;
|
|
||||||
case SDLK_s:
|
|
||||||
motion.y += CHARACTER_WALKING_SPEED;
|
|
||||||
break;
|
|
||||||
case SDLK_d:
|
|
||||||
motion.x += CHARACTER_WALKING_SPEED;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
//DOCS: prevents wrong keys screwing with character movement
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//handle diagonals
|
|
||||||
if (motion.x != 0 && motion.y != 0) {
|
|
||||||
motion *= CHARACTER_WALKING_MOD;
|
|
||||||
}
|
|
||||||
//set the info
|
|
||||||
localCharacter->SetMotion(motion);
|
|
||||||
localCharacter->CorrectSprite();
|
|
||||||
SendLocalCharacterMovement();
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::KeyUp(SDL_KeyboardEvent const& key) {
|
|
||||||
//character movement
|
|
||||||
if (!localCharacter) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Vector2 motion = localCharacter->GetMotion();
|
|
||||||
switch(key.keysym.sym) {
|
|
||||||
case SDLK_w:
|
|
||||||
motion.y = std::min(0.0, motion.y += CHARACTER_WALKING_SPEED);
|
|
||||||
break;
|
|
||||||
case SDLK_a:
|
|
||||||
motion.x = std::min(0.0, motion.x += CHARACTER_WALKING_SPEED);
|
|
||||||
break;
|
|
||||||
case SDLK_s:
|
|
||||||
motion.y = std::max(0.0, motion.y -= CHARACTER_WALKING_SPEED);
|
|
||||||
break;
|
|
||||||
case SDLK_d:
|
|
||||||
motion.x = std::max(0.0, motion.x -= CHARACTER_WALKING_SPEED);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
//DOCS: prevents wrong keys screwing with character movement
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//BUGFIX: reset cardinal direction speed on key release
|
|
||||||
if (motion.x > 0) {
|
|
||||||
motion.x = CHARACTER_WALKING_SPEED;
|
|
||||||
}
|
|
||||||
else if (motion.x < 0) {
|
|
||||||
motion.x = -CHARACTER_WALKING_SPEED;
|
|
||||||
}
|
|
||||||
if (motion.y > 0) {
|
|
||||||
motion.y = CHARACTER_WALKING_SPEED;
|
|
||||||
}
|
|
||||||
else if (motion.y < 0) {
|
|
||||||
motion.y = -CHARACTER_WALKING_SPEED;
|
|
||||||
}
|
|
||||||
//handle diagonals
|
|
||||||
if (motion.x != 0 && motion.y != 0) {
|
|
||||||
motion *= CHARACTER_WALKING_MOD;
|
|
||||||
}
|
|
||||||
//set the info
|
|
||||||
localCharacter->SetMotion(motion);
|
|
||||||
localCharacter->CorrectSprite();
|
|
||||||
SendLocalCharacterMovement();
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
//Direct incoming traffic
|
|
||||||
//-------------------------
|
|
||||||
|
|
||||||
void World::HandlePacket(SerialPacket* const argPacket) {
|
|
||||||
switch(argPacket->type) {
|
|
||||||
//heartbeat system
|
|
||||||
case SerialPacketType::PING:
|
|
||||||
hPing(static_cast<ServerPacket*>(argPacket));
|
|
||||||
break;
|
|
||||||
case SerialPacketType::PONG:
|
|
||||||
hPong(static_cast<ServerPacket*>(argPacket));
|
|
||||||
break;
|
|
||||||
|
|
||||||
//game server connections
|
|
||||||
case SerialPacketType::LOGOUT_RESPONSE:
|
|
||||||
hLogoutResponse(static_cast<ClientPacket*>(argPacket));
|
|
||||||
break;
|
|
||||||
case SerialPacketType::DISCONNECT_RESPONSE:
|
|
||||||
hDisconnectResponse(static_cast<ClientPacket*>(argPacket));
|
|
||||||
break;
|
|
||||||
case SerialPacketType::ADMIN_DISCONNECT_FORCED:
|
|
||||||
hAdminDisconnectForced(static_cast<ClientPacket*>(argPacket));
|
|
||||||
break;
|
|
||||||
|
|
||||||
//map management
|
|
||||||
case SerialPacketType::REGION_CONTENT:
|
|
||||||
hRegionContent(static_cast<RegionPacket*>(argPacket));
|
|
||||||
break;
|
|
||||||
|
|
||||||
//character management
|
|
||||||
case SerialPacketType::CHARACTER_CREATE:
|
|
||||||
hCharacterCreate(static_cast<CharacterPacket*>(argPacket));
|
|
||||||
break;
|
|
||||||
case SerialPacketType::CHARACTER_DELETE:
|
|
||||||
hCharacterDelete(static_cast<CharacterPacket*>(argPacket));
|
|
||||||
break;
|
|
||||||
case SerialPacketType::QUERY_CHARACTER_EXISTS:
|
|
||||||
hQueryCharacterExists(static_cast<CharacterPacket*>(argPacket));
|
|
||||||
break;
|
|
||||||
case SerialPacketType::QUERY_CHARACTER_STATS:
|
|
||||||
hQueryCharacterStats(static_cast<CharacterPacket*>(argPacket));
|
|
||||||
break;
|
|
||||||
case SerialPacketType::QUERY_CHARACTER_LOCATION:
|
|
||||||
hQueryCharacterLocation(static_cast<CharacterPacket*>(argPacket));
|
|
||||||
break;
|
|
||||||
case SerialPacketType::CHARACTER_MOVEMENT:
|
|
||||||
hCharacterMovement(static_cast<CharacterPacket*>(argPacket));
|
|
||||||
break;
|
|
||||||
case SerialPacketType::CHARACTER_ATTACK:
|
|
||||||
hCharacterAttack(static_cast<CharacterPacket*>(argPacket));
|
|
||||||
break;
|
|
||||||
case SerialPacketType::CHARACTER_DAMAGE:
|
|
||||||
hCharacterDamage(static_cast<CharacterPacket*>(argPacket));
|
|
||||||
break;
|
|
||||||
|
|
||||||
//monster management
|
|
||||||
case SerialPacketType::MONSTER_CREATE:
|
|
||||||
hMonsterCreate(static_cast<MonsterPacket*>(argPacket));
|
|
||||||
break;
|
|
||||||
case SerialPacketType::MONSTER_DELETE:
|
|
||||||
hMonsterDelete(static_cast<MonsterPacket*>(argPacket));
|
|
||||||
break;
|
|
||||||
case SerialPacketType::QUERY_MONSTER_EXISTS:
|
|
||||||
hQueryMonsterExists(static_cast<MonsterPacket*>(argPacket));
|
|
||||||
break;
|
|
||||||
case SerialPacketType::QUERY_MONSTER_STATS:
|
|
||||||
hQueryMonsterStats(static_cast<MonsterPacket*>(argPacket));
|
|
||||||
break;
|
|
||||||
case SerialPacketType::QUERY_MONSTER_LOCATION:
|
|
||||||
hQueryMonsterLocation(static_cast<MonsterPacket*>(argPacket));
|
|
||||||
break;
|
|
||||||
case SerialPacketType::MONSTER_MOVEMENT:
|
|
||||||
hMonsterMovement(static_cast<MonsterPacket*>(argPacket));
|
|
||||||
break;
|
|
||||||
case SerialPacketType::MONSTER_ATTACK:
|
|
||||||
hMonsterAttack(static_cast<MonsterPacket*>(argPacket));
|
|
||||||
break;
|
|
||||||
case SerialPacketType::MONSTER_DAMAGE:
|
|
||||||
hMonsterDamage(static_cast<MonsterPacket*>(argPacket));
|
|
||||||
break;
|
|
||||||
|
|
||||||
//chat
|
|
||||||
case SerialPacketType::TEXT_BROADCAST:
|
|
||||||
hTextBroadcast(static_cast<TextPacket*>(argPacket));
|
|
||||||
break;
|
|
||||||
case SerialPacketType::TEXT_SPEECH:
|
|
||||||
hTextSpeech(static_cast<TextPacket*>(argPacket));
|
|
||||||
break;
|
|
||||||
case SerialPacketType::TEXT_WHISPER:
|
|
||||||
hTextWhisper(static_cast<TextPacket*>(argPacket));
|
|
||||||
break;
|
|
||||||
|
|
||||||
//general rejection messages
|
|
||||||
case SerialPacketType::REGION_REJECTION:
|
|
||||||
case SerialPacketType::CHARACTER_REJECTION:
|
|
||||||
case SerialPacketType::QUERY_REJECTION:
|
|
||||||
throw(terminal_error(static_cast<TextPacket*>(argPacket)->text));
|
|
||||||
break;
|
|
||||||
case SerialPacketType::SHUTDOWN_REJECTION:
|
|
||||||
throw(std::runtime_error(static_cast<TextPacket*>(argPacket)->text));
|
|
||||||
break;
|
|
||||||
|
|
||||||
//errors
|
|
||||||
default: {
|
|
||||||
std::ostringstream msg;
|
|
||||||
msg << "Unknown SerialPacketType encountered in World: " << static_cast<int>(argPacket->type);
|
|
||||||
throw(std::runtime_error(msg.str()));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
|
||||||
*
|
|
||||||
* 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 "world.hpp"
|
|
||||||
|
|
||||||
#include "channels.hpp"
|
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
//map management
|
|
||||||
//-------------------------
|
|
||||||
|
|
||||||
void World::SendRegionRequest(int roomIndex, int x, int y) {
|
|
||||||
RegionPacket packet;
|
|
||||||
|
|
||||||
//pack the region's data
|
|
||||||
packet.type = SerialPacketType::REGION_REQUEST;
|
|
||||||
packet.roomIndex = roomIndex;
|
|
||||||
packet.x = x;
|
|
||||||
packet.y = y;
|
|
||||||
|
|
||||||
network.SendTo(Channels::SERVER, &packet);
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::hRegionContent(RegionPacket* const argPacket) {
|
|
||||||
//replace existing regions
|
|
||||||
regionPager.UnloadIf([&](Region const& region) -> bool {
|
|
||||||
return region.GetX() == argPacket->x && region.GetY() == argPacket->y;
|
|
||||||
});
|
|
||||||
regionPager.PushRegion(argPacket->region);
|
|
||||||
|
|
||||||
//clean up after the serial code
|
|
||||||
delete argPacket->region;
|
|
||||||
argPacket->region = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::UpdateMap() {
|
|
||||||
if (roomIndex == -1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//these represent the zone of regions that the client needs loaded, including the mandatory buffers (+1/-1)
|
|
||||||
int xStart = snapToBase(REGION_WIDTH, camera.x/tileSheet.GetTileW()) - REGION_WIDTH;
|
|
||||||
int xEnd = snapToBase(REGION_WIDTH, (camera.x+camera.width)/tileSheet.GetTileW()) + REGION_WIDTH;
|
|
||||||
|
|
||||||
int yStart = snapToBase(REGION_HEIGHT, camera.y/tileSheet.GetTileH()) - REGION_HEIGHT;
|
|
||||||
int yEnd = snapToBase(REGION_HEIGHT, (camera.y+camera.height)/tileSheet.GetTileH()) + REGION_HEIGHT;
|
|
||||||
|
|
||||||
//prune distant regions
|
|
||||||
regionPager.GetContainer()->remove_if([&](Region const& region) -> bool {
|
|
||||||
return region.GetX() < xStart || region.GetX() > xEnd || region.GetY() < yStart || region.GetY() > yEnd;
|
|
||||||
});
|
|
||||||
|
|
||||||
//request empty regions within this zone
|
|
||||||
for (int i = xStart; i <= xEnd; i += REGION_WIDTH) {
|
|
||||||
for (int j = yStart; j <= yEnd; j += REGION_HEIGHT) {
|
|
||||||
if (!regionPager.FindRegion(i, j)) {
|
|
||||||
SendRegionRequest(roomIndex, i, j);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
|
||||||
*
|
|
||||||
* 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 "world.hpp"
|
|
||||||
|
|
||||||
#include "channels.hpp"
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
//monster management
|
|
||||||
//-------------------------
|
|
||||||
|
|
||||||
void World::hMonsterCreate(MonsterPacket* const argPacket) {
|
|
||||||
//check for logic errors
|
|
||||||
if (monsterMap.find(argPacket->monsterIndex) != monsterMap.end()) {
|
|
||||||
std::ostringstream msg;
|
|
||||||
msg << "Double monster creation event; ";
|
|
||||||
msg << "Index: " << argPacket->monsterIndex << "; ";
|
|
||||||
msg << "Handle: " << argPacket->handle;
|
|
||||||
throw(std::runtime_error(msg.str()));
|
|
||||||
}
|
|
||||||
|
|
||||||
//ignore monsters from other rooms
|
|
||||||
if (roomIndex != argPacket->roomIndex) {
|
|
||||||
//temporary error checking
|
|
||||||
std::ostringstream msg;
|
|
||||||
msg << "Monster from the wrong room received: ";
|
|
||||||
msg << "monsterIndex: " << argPacket->monsterIndex << ", roomIndex: " << argPacket->roomIndex;
|
|
||||||
throw(std::runtime_error(msg.str()));
|
|
||||||
}
|
|
||||||
|
|
||||||
//implicitly create the element
|
|
||||||
BaseMonster* monster = &monsterMap[argPacket->monsterIndex];
|
|
||||||
|
|
||||||
//fill the monster's info
|
|
||||||
monster->SetHandle(argPacket->handle);
|
|
||||||
monster->SetAvatar(argPacket->avatar);
|
|
||||||
monster->SetBounds(argPacket->bounds);
|
|
||||||
monster->SetOrigin(argPacket->origin);
|
|
||||||
monster->SetMotion(argPacket->motion);
|
|
||||||
|
|
||||||
//debug
|
|
||||||
std::cout << "Monster Create, total: " << monsterMap.size() << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::hMonsterDelete(MonsterPacket* const argPacket) {
|
|
||||||
//ignore if this monster doesn't exist
|
|
||||||
std::map<int, BaseMonster>::iterator monsterIt = monsterMap.find(argPacket->monsterIndex);
|
|
||||||
if (monsterIt == monsterMap.end()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//remove this monster
|
|
||||||
monsterMap.erase(monsterIt);
|
|
||||||
|
|
||||||
//debug
|
|
||||||
std::cout << "Monster Delete, total: " << monsterMap.size() << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::hQueryMonsterExists(MonsterPacket* const argPacket) {
|
|
||||||
//ignore monsters in a different room (sub-optimal)
|
|
||||||
if (argPacket->roomIndex != roomIndex) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//implicitly create the element
|
|
||||||
BaseMonster* monster = &monsterMap[argPacket->monsterIndex];
|
|
||||||
|
|
||||||
//fill the monster's info
|
|
||||||
monster->SetHandle(argPacket->handle);
|
|
||||||
monster->SetAvatar(argPacket->avatar);
|
|
||||||
monster->SetBounds(argPacket->bounds);
|
|
||||||
monster->SetOrigin(argPacket->origin);
|
|
||||||
monster->SetMotion(argPacket->motion);
|
|
||||||
|
|
||||||
//debug
|
|
||||||
std::cout << "Monster Query, total: " << monsterMap.size() << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::hQueryMonsterStats(MonsterPacket* const argPacket) {
|
|
||||||
//TODO: (9) empty
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::hQueryMonsterLocation(MonsterPacket* const argPacket) {
|
|
||||||
//TODO: (9) empty
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::hMonsterMovement(MonsterPacket* const argPacket) {
|
|
||||||
//ignore if this monster doesn't exist
|
|
||||||
std::map<int, BaseMonster>::iterator monsterIt = monsterMap.find(argPacket->monsterIndex);
|
|
||||||
if (monsterIt == monsterMap.end()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
monsterIt->second.SetOrigin(argPacket->origin);
|
|
||||||
monsterIt->second.SetOrigin(argPacket->motion);
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::hMonsterAttack(MonsterPacket* const argPacket) {
|
|
||||||
//TODO: (9) empty
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::hMonsterDamage(MonsterPacket* const argPacket) {
|
|
||||||
//TODO: (9) empty
|
|
||||||
}
|
|
||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -36,7 +36,7 @@ int main(int argc, char* argv[]) {
|
|||||||
ConfigUtility::CreateSingleton();
|
ConfigUtility::CreateSingleton();
|
||||||
UDPNetworkUtility::CreateSingleton();
|
UDPNetworkUtility::CreateSingleton();
|
||||||
|
|
||||||
//call the client's routines
|
//call the server's routines
|
||||||
ClientApplication::CreateSingleton();
|
ClientApplication::CreateSingleton();
|
||||||
ClientApplication& app = ClientApplication::GetSingleton();
|
ClientApplication& app = ClientApplication::GetSingleton();
|
||||||
|
|
||||||
|
|||||||
+2
-4
@@ -1,5 +1,5 @@
|
|||||||
#include directories
|
#include directories
|
||||||
INCLUDES+=. client_utilities entities gameplay_scenes menu_scenes ../common/debugging ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet_types ../common/ui ../common/utilities
|
INCLUDES+=. entities scenes ../common/debugging ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet_types ../common/ui ../common/utilities
|
||||||
|
|
||||||
#libraries
|
#libraries
|
||||||
#the order of the $(LIBS) is important, at least for MinGW
|
#the order of the $(LIBS) is important, at least for MinGW
|
||||||
@@ -25,10 +25,8 @@ OUT=$(addprefix $(OUTDIR)/,client)
|
|||||||
|
|
||||||
#targets
|
#targets
|
||||||
all: $(OBJ) $(OUT)
|
all: $(OBJ) $(OUT)
|
||||||
$(MAKE) -C client_utilities
|
|
||||||
$(MAKE) -C entities
|
$(MAKE) -C entities
|
||||||
$(MAKE) -C gameplay_scenes
|
$(MAKE) -C scenes
|
||||||
$(MAKE) -C menu_scenes
|
|
||||||
$(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
|
$(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
|
||||||
|
|
||||||
$(OBJ): | $(OBJDIR)
|
$(OBJ): | $(OBJDIR)
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
#config
|
|
||||||
INCLUDES+=. .. ../../common/graphics ../../common/map ../../common/network ../../common/network/packet_types ../../common/ui ../../common/utilities
|
|
||||||
LIBS+=
|
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
|
||||||
|
|
||||||
#source
|
|
||||||
CXXSRC=$(wildcard *.cpp)
|
|
||||||
|
|
||||||
#objects
|
|
||||||
OBJDIR=obj
|
|
||||||
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
|
||||||
|
|
||||||
#output
|
|
||||||
OUTDIR=..
|
|
||||||
OUT=$(addprefix $(OUTDIR)/,client.a)
|
|
||||||
|
|
||||||
#targets
|
|
||||||
all: $(OBJ) $(OUT)
|
|
||||||
ar -crs $(OUT) $(OBJ)
|
|
||||||
|
|
||||||
$(OBJ): | $(OBJDIR)
|
|
||||||
|
|
||||||
$(OUT): | $(OUTDIR)
|
|
||||||
|
|
||||||
$(OBJDIR):
|
|
||||||
mkdir $(OBJDIR)
|
|
||||||
|
|
||||||
$(OUTDIR):
|
|
||||||
mkdir $(OUTDIR)
|
|
||||||
|
|
||||||
$(OBJDIR)/%.o: %.cpp
|
|
||||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(RM) *.o *.a *.exe
|
|
||||||
|
|
||||||
rebuild: clean all
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -33,7 +33,7 @@ enum class SceneList {
|
|||||||
MAINMENU,
|
MAINMENU,
|
||||||
OPTIONSMENU,
|
OPTIONSMENU,
|
||||||
LOBBYMENU,
|
LOBBYMENU,
|
||||||
WORLD,
|
INWORLD,
|
||||||
DISCONNECTEDSCREEN,
|
DISCONNECTEDSCREEN,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -127,7 +127,7 @@ void BaseScene::HandleEvents() {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
#ifdef USE_EVENT_JOYSTICK
|
#ifdef USE_EVENT_JOYSTICK
|
||||||
//EMPTY
|
//TODO: joystick/gamepad support
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_EVENT_UNKNOWN
|
#ifdef USE_EVENT_UNKNOWN
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -59,7 +59,7 @@ protected:
|
|||||||
virtual void KeyUp(SDL_KeyboardEvent const&) {}
|
virtual void KeyUp(SDL_KeyboardEvent const&) {}
|
||||||
|
|
||||||
#ifdef USE_EVENT_JOYSTICK
|
#ifdef USE_EVENT_JOYSTICK
|
||||||
//EMPTY
|
//TODO: joystick/gamepad support
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_EVENT_UNKNOWN
|
#ifdef USE_EVENT_UNKNOWN
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -0,0 +1,558 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
|
*
|
||||||
|
* 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 "in_world.hpp"
|
||||||
|
|
||||||
|
#include "channels.hpp"
|
||||||
|
#include "utility.hpp"
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cmath>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Public access members
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
InWorld::InWorld(int* const argClientIndex, int* const argAccountIndex):
|
||||||
|
clientIndex(*argClientIndex),
|
||||||
|
accountIndex(*argAccountIndex)
|
||||||
|
{
|
||||||
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
|
|
||||||
|
//setup the utility objects
|
||||||
|
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
||||||
|
buttonImage.SetClipH(buttonImage.GetClipH()/3);
|
||||||
|
font.LoadSurface(config["dir.fonts"] + "pk_white_8.bmp");
|
||||||
|
|
||||||
|
//pass the utility objects
|
||||||
|
disconnectButton.SetImage(&buttonImage);
|
||||||
|
disconnectButton.SetFont(&font);
|
||||||
|
shutDownButton.SetImage(&buttonImage);
|
||||||
|
shutDownButton.SetFont(&font);
|
||||||
|
|
||||||
|
//set the button positions
|
||||||
|
disconnectButton.SetX(50);
|
||||||
|
disconnectButton.SetY(50 + buttonImage.GetClipH() * 0);
|
||||||
|
shutDownButton.SetX(50);
|
||||||
|
shutDownButton.SetY(50 + buttonImage.GetClipH() * 1);
|
||||||
|
|
||||||
|
//set the button texts
|
||||||
|
disconnectButton.SetText("Disconnect");
|
||||||
|
shutDownButton.SetText("Shut Down");
|
||||||
|
|
||||||
|
//load the tilesheet
|
||||||
|
//TODO: add the tilesheet to the map system?
|
||||||
|
//TODO: Tile size and tile sheet should be loaded elsewhere
|
||||||
|
tileSheet.Load(config["dir.tilesets"] + "overworld.bmp", 32, 32);
|
||||||
|
|
||||||
|
//send this player's character info
|
||||||
|
// CharacterPacket newPacket;
|
||||||
|
// newPacket.type = SerialPacketType::CHARACTER_NEW;
|
||||||
|
// strncpy(newPacket.handle, config["client.handle"].c_str(), PACKET_STRING_SIZE);
|
||||||
|
// strncpy(newPacket.avatar, config["client.avatar"].c_str(), PACKET_STRING_SIZE);
|
||||||
|
// newPacket.accountIndex = accountIndex;
|
||||||
|
// network.SendTo(Channels::SERVER, &newPacket);
|
||||||
|
|
||||||
|
//request a sync
|
||||||
|
// RequestSynchronize();
|
||||||
|
|
||||||
|
//debug
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
InWorld::~InWorld() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Frame loop
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void InWorld::FrameStart() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::Update() {
|
||||||
|
//suck in and process all waiting packets
|
||||||
|
SerialPacket* packetBuffer = reinterpret_cast<SerialPacket*>(new char[MAX_PACKET_SIZE]);
|
||||||
|
while(network.Receive(packetBuffer)) {
|
||||||
|
HandlePacket(packetBuffer);
|
||||||
|
}
|
||||||
|
delete reinterpret_cast<char*>(packetBuffer);
|
||||||
|
|
||||||
|
//update the characters
|
||||||
|
for (auto& it : characterMap) {
|
||||||
|
it.second.Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
//check the map
|
||||||
|
UpdateMap();
|
||||||
|
|
||||||
|
//skip the rest
|
||||||
|
if (!localCharacter) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//check for collisions with the map
|
||||||
|
BoundingBox wallBounds = {0, 0, tileSheet.GetTileW(), tileSheet.GetTileH()};
|
||||||
|
const int xCount = localCharacter->GetBounds().w / wallBounds.w + 1;
|
||||||
|
const int yCount = localCharacter->GetBounds().h / wallBounds.h + 1;
|
||||||
|
|
||||||
|
for (int i = -1; i <= xCount; ++i) {
|
||||||
|
for (int j = -1; j <= yCount; ++j) {
|
||||||
|
//set the wall's position
|
||||||
|
wallBounds.x = wallBounds.w * i + snapToBase((double)wallBounds.w, localCharacter->GetOrigin().x);
|
||||||
|
wallBounds.y = wallBounds.h * j + snapToBase((double)wallBounds.h, localCharacter->GetOrigin().y);
|
||||||
|
|
||||||
|
if (!regionPager.GetSolid(wallBounds.x / wallBounds.w, wallBounds.y / wallBounds.h)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((localCharacter->GetOrigin() + localCharacter->GetBounds()).CheckOverlap(wallBounds)) {
|
||||||
|
localCharacter->SetOrigin(localCharacter->GetOrigin() - (localCharacter->GetMotion()));
|
||||||
|
localCharacter->SetMotion({0,0});
|
||||||
|
localCharacter->CorrectSprite();
|
||||||
|
SendPlayerUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//update the camera (following the player)
|
||||||
|
camera.x = localCharacter->GetOrigin().x - camera.marginX;
|
||||||
|
camera.y = localCharacter->GetOrigin().y - camera.marginY;
|
||||||
|
|
||||||
|
//check the connection
|
||||||
|
if (Clock::now() - lastBeat > std::chrono::seconds(3)) {
|
||||||
|
if (attemptedBeats > 2) {
|
||||||
|
RequestDisconnect();
|
||||||
|
SetNextScene(SceneList::DISCONNECTEDSCREEN);
|
||||||
|
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "Error: Lost connection to the server";
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerPacket newPacket;
|
||||||
|
newPacket.type = SerialPacketType::PING;
|
||||||
|
network.SendTo(Channels::SERVER, &newPacket);
|
||||||
|
|
||||||
|
attemptedBeats++;
|
||||||
|
lastBeat = Clock::now();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::FrameEnd() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::RenderFrame() {
|
||||||
|
// SDL_FillRect(GetScreen(), 0, 0);
|
||||||
|
Render(GetScreen());
|
||||||
|
SDL_Flip(GetScreen());
|
||||||
|
fps.Calculate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::Render(SDL_Surface* const screen) {
|
||||||
|
//draw the map
|
||||||
|
for (std::list<Region>::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); it++) {
|
||||||
|
tileSheet.DrawRegionTo(screen, &(*it), camera.x, camera.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
//draw characters
|
||||||
|
for (auto& it : characterMap) {
|
||||||
|
//BUG: #29 drawing order according to Y origin
|
||||||
|
//TODO: use a list of renderable objects
|
||||||
|
it.second.DrawTo(screen, camera.x, camera.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
//draw UI
|
||||||
|
disconnectButton.DrawTo(screen);
|
||||||
|
shutDownButton.DrawTo(screen);
|
||||||
|
font.DrawStringTo(to_string_custom(fps.GetFrameRate()), screen, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Event handlers
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void InWorld::QuitEvent() {
|
||||||
|
//exit the game AND the server
|
||||||
|
RequestDisconnect();
|
||||||
|
SetNextScene(SceneList::QUIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
||||||
|
disconnectButton.MouseMotion(motion);
|
||||||
|
shutDownButton.MouseMotion(motion);
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
||||||
|
disconnectButton.MouseButtonDown(button);
|
||||||
|
shutDownButton.MouseButtonDown(button);
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||||
|
if (disconnectButton.MouseButtonUp(button) == Button::State::HOVER && button.button == SDL_BUTTON_LEFT) {
|
||||||
|
RequestDisconnect();
|
||||||
|
}
|
||||||
|
if (shutDownButton.MouseButtonUp(button) == Button::State::HOVER && button.button == SDL_BUTTON_LEFT) {
|
||||||
|
RequestShutDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::KeyDown(SDL_KeyboardEvent const& key) {
|
||||||
|
if (!localCharacter) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//hotkeys
|
||||||
|
switch(key.keysym.sym) {
|
||||||
|
case SDLK_ESCAPE:
|
||||||
|
RequestDisconnect();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//player movement
|
||||||
|
Vector2 motion = localCharacter->GetMotion();
|
||||||
|
switch(key.keysym.sym) {
|
||||||
|
case SDLK_LEFT:
|
||||||
|
motion.x -= CHARACTER_WALKING_SPEED;
|
||||||
|
break;
|
||||||
|
case SDLK_RIGHT:
|
||||||
|
motion.x += CHARACTER_WALKING_SPEED;
|
||||||
|
break;
|
||||||
|
case SDLK_UP:
|
||||||
|
motion.y -= CHARACTER_WALKING_SPEED;
|
||||||
|
break;
|
||||||
|
case SDLK_DOWN:
|
||||||
|
motion.y += CHARACTER_WALKING_SPEED;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
localCharacter->SetMotion(motion);
|
||||||
|
localCharacter->CorrectSprite();
|
||||||
|
SendPlayerUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::KeyUp(SDL_KeyboardEvent const& key) {
|
||||||
|
if (!localCharacter) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//player movement
|
||||||
|
Vector2 motion = localCharacter->GetMotion();
|
||||||
|
switch(key.keysym.sym) {
|
||||||
|
//NOTE: The use of min/max here are to prevent awkward movements
|
||||||
|
case SDLK_LEFT:
|
||||||
|
motion.x = std::min(motion.x + CHARACTER_WALKING_SPEED, 0.0);
|
||||||
|
break;
|
||||||
|
case SDLK_RIGHT:
|
||||||
|
motion.x = std::max(motion.x - CHARACTER_WALKING_SPEED, 0.0);
|
||||||
|
break;
|
||||||
|
case SDLK_UP:
|
||||||
|
motion.y = std::min(motion.y + CHARACTER_WALKING_SPEED, 0.0);
|
||||||
|
break;
|
||||||
|
case SDLK_DOWN:
|
||||||
|
motion.y = std::max(motion.y - CHARACTER_WALKING_SPEED, 0.0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
localCharacter->SetMotion(motion);
|
||||||
|
localCharacter->CorrectSprite();
|
||||||
|
SendPlayerUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Network handlers
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void InWorld::HandlePacket(SerialPacket* const argPacket) {
|
||||||
|
switch(argPacket->type) {
|
||||||
|
//heartbeat system
|
||||||
|
case SerialPacketType::PING: {
|
||||||
|
ServerPacket newPacket;
|
||||||
|
newPacket.type = SerialPacketType::PONG;
|
||||||
|
network.SendTo(argPacket->srcAddress, &newPacket);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SerialPacketType::PONG:
|
||||||
|
// HandlePong(static_cast<ServerPacket*>(argPacket));
|
||||||
|
break;
|
||||||
|
|
||||||
|
//game server connections
|
||||||
|
case SerialPacketType::LOGOUT_RESPONSE:
|
||||||
|
// HandleLogoutResponse(static_cast<ClientPacket*>(argPacket));
|
||||||
|
break;
|
||||||
|
case SerialPacketType::DISCONNECT_REQUEST:
|
||||||
|
// HandleDisconnectRequest(static_cast<ClientPacket*>(argPacket));
|
||||||
|
break;
|
||||||
|
case SerialPacketType::DISCONNECT_FORCED:
|
||||||
|
// HandleDisconnectForced(static_cast<ClientPacket*>(argPacket));
|
||||||
|
break;
|
||||||
|
|
||||||
|
//data management
|
||||||
|
case SerialPacketType::REGION_CONTENT:
|
||||||
|
// HandleRegionContent(static_cast<RegionPacket*>(argPacket));
|
||||||
|
break;
|
||||||
|
// case SerialPacketType::QUERY_CHARACTER_EXISTS:
|
||||||
|
// case SerialPacketType::QUERY_CHARACTER_STATS:
|
||||||
|
// case SerialPacketType::QUERY_CHARACTER_LOCATION:
|
||||||
|
|
||||||
|
//character management
|
||||||
|
// case SerialPacketType::CHARACTER_NEW:
|
||||||
|
// HandleCharacterNew(static_cast<CharacterPacket*>(argPacket));
|
||||||
|
// break;
|
||||||
|
// case SerialPacketType::CHARACTER_DELETE:
|
||||||
|
// HandleCharacterDelete(static_cast<CharacterPacket*>(argPacket));
|
||||||
|
// break;
|
||||||
|
// case SerialPacketType::CHARACTER_UPDATE:
|
||||||
|
// HandleCharacterUpdate(static_cast<CharacterPacket*>(argPacket));
|
||||||
|
// break;
|
||||||
|
// case SerialPacketType::CHARACTER_REJECTION:
|
||||||
|
// HandleCharacterRejection(static_cast<TextPacket*>(argPacket));
|
||||||
|
// break;
|
||||||
|
|
||||||
|
//enemy management
|
||||||
|
//TODO: enemy management
|
||||||
|
|
||||||
|
//TODO: text
|
||||||
|
|
||||||
|
//handle errors
|
||||||
|
default:
|
||||||
|
throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in InWorld: " + to_string_custom(static_cast<int>(argPacket->type)) ));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::HandlePong(ServerPacket* const argPacket) {
|
||||||
|
if (network.GetIPAddress(Channels::SERVER)->host != argPacket->srcAddress.host) {
|
||||||
|
throw(std::runtime_error("Heartbeat message received from an unknown source"));
|
||||||
|
}
|
||||||
|
|
||||||
|
attemptedBeats = 0;
|
||||||
|
lastBeat = Clock::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::HandleDisconnect(ClientPacket* const argPacket) {
|
||||||
|
//TODO: More needed in the disconnection
|
||||||
|
SetNextScene(SceneList::DISCONNECTEDSCREEN);
|
||||||
|
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "You have been disconnected";
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) {
|
||||||
|
if (characterMap.find(argPacket->characterIndex) != characterMap.end()) {
|
||||||
|
throw(std::runtime_error("Cannot create duplicate characters"));
|
||||||
|
}
|
||||||
|
|
||||||
|
//create the character object
|
||||||
|
BaseCharacter& newCharacter = characterMap[argPacket->characterIndex];
|
||||||
|
|
||||||
|
//fill out the character's members
|
||||||
|
newCharacter.SetHandle(argPacket->handle);
|
||||||
|
newCharacter.SetAvatar(argPacket->avatar);
|
||||||
|
|
||||||
|
newCharacter.GetSprite()->LoadSurface(ConfigUtility::GetSingleton()["dir.sprites"] + newCharacter.GetAvatar(), 4, 4);
|
||||||
|
|
||||||
|
newCharacter.SetOrigin(argPacket->origin);
|
||||||
|
newCharacter.SetMotion(argPacket->motion);
|
||||||
|
newCharacter.SetBounds({
|
||||||
|
CHARACTER_BOUNDS_X,
|
||||||
|
CHARACTER_BOUNDS_Y,
|
||||||
|
CHARACTER_BOUNDS_WIDTH,
|
||||||
|
CHARACTER_BOUNDS_HEIGHT
|
||||||
|
});
|
||||||
|
|
||||||
|
// (*newCharacter.GetBaseStats()) = argPacket->stats;
|
||||||
|
|
||||||
|
//bookkeeping code
|
||||||
|
newCharacter.CorrectSprite();
|
||||||
|
|
||||||
|
//catch this client's player object
|
||||||
|
if (argPacket->accountIndex == accountIndex && !localCharacter) {
|
||||||
|
characterIndex = argPacket->characterIndex;
|
||||||
|
localCharacter = &newCharacter;
|
||||||
|
|
||||||
|
//setup the camera
|
||||||
|
camera.width = GetScreen()->w;
|
||||||
|
camera.height = GetScreen()->h;
|
||||||
|
|
||||||
|
//center on the player's character
|
||||||
|
camera.marginX = (GetScreen()->w / 2 - localCharacter->GetSprite()->GetImage()->GetClipW() / 2);
|
||||||
|
camera.marginY = (GetScreen()->h / 2 - localCharacter->GetSprite()->GetImage()->GetClipH() / 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
|
||||||
|
//TODO: authenticate when own character is being deleted (linked to a TODO in the server)
|
||||||
|
|
||||||
|
//catch this client's player object
|
||||||
|
if (argPacket->characterIndex == characterIndex) {
|
||||||
|
characterIndex = -1;
|
||||||
|
localCharacter = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
characterMap.erase(argPacket->characterIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::HandleCharacterUpdate(CharacterPacket* const argPacket) {
|
||||||
|
if (characterMap.find(argPacket->characterIndex) == characterMap.end()) {
|
||||||
|
HandleCharacterNew(argPacket);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseCharacter& character = characterMap[argPacket->characterIndex];
|
||||||
|
|
||||||
|
//other characters moving
|
||||||
|
if (argPacket->characterIndex != characterIndex) {
|
||||||
|
character.SetOrigin(argPacket->origin);
|
||||||
|
character.SetMotion(argPacket->motion);
|
||||||
|
character.CorrectSprite();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::HandleCharacterRejection(TextPacket* const argPacket) {
|
||||||
|
RequestDisconnect();
|
||||||
|
SetNextScene(SceneList::DISCONNECTEDSCREEN);
|
||||||
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
|
config["client.disconnectMessage"] = "Error: ";
|
||||||
|
config["client.disconnectMessage"] += argPacket->text;
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::HandleRegionContent(RegionPacket* const argPacket) {
|
||||||
|
//replace existing regions
|
||||||
|
regionPager.UnloadRegion(argPacket->x, argPacket->y);
|
||||||
|
regionPager.PushRegion(argPacket->region);
|
||||||
|
|
||||||
|
//clean up after the serial code
|
||||||
|
delete argPacket->region;
|
||||||
|
argPacket->region = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Server control
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
void InWorld::RequestSynchronize() {
|
||||||
|
// ClientPacket newPacket;
|
||||||
|
|
||||||
|
//request a sync
|
||||||
|
// newPacket.type = SerialPacketType::SYNCHRONIZE;
|
||||||
|
// newPacket.clientIndex = clientIndex;
|
||||||
|
// newPacket.accountIndex = accountIndex;
|
||||||
|
|
||||||
|
//TODO: location, range for sync request
|
||||||
|
|
||||||
|
// network.SendTo(Channels::SERVER, &newPacket);
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::SendPlayerUpdate() {
|
||||||
|
CharacterPacket newPacket;
|
||||||
|
|
||||||
|
//pack the packet
|
||||||
|
// newPacket.type = SerialPacketType::CHARACTER_UPDATE;
|
||||||
|
|
||||||
|
newPacket.characterIndex = characterIndex;
|
||||||
|
//NOTE: omitting the handle and avatar here
|
||||||
|
newPacket.accountIndex = accountIndex;
|
||||||
|
newPacket.roomIndex = 0; //TODO: room index
|
||||||
|
newPacket.origin = localCharacter->GetOrigin();
|
||||||
|
newPacket.motion = localCharacter->GetMotion();
|
||||||
|
// newPacket.stats = *localCharacter->GetBaseStats();
|
||||||
|
|
||||||
|
//TODO: gameplay components: equipment, items, buffs, debuffs
|
||||||
|
|
||||||
|
network.SendTo(Channels::SERVER, &newPacket);
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::RequestDisconnect() {
|
||||||
|
ClientPacket newPacket;
|
||||||
|
|
||||||
|
//send a disconnect request
|
||||||
|
newPacket.type = SerialPacketType::DISCONNECT_REQUEST;
|
||||||
|
newPacket.clientIndex = clientIndex;
|
||||||
|
newPacket.accountIndex = accountIndex;
|
||||||
|
|
||||||
|
network.SendTo(Channels::SERVER, &newPacket);
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::RequestShutDown() {
|
||||||
|
ClientPacket newPacket;
|
||||||
|
|
||||||
|
//send a shutdown request
|
||||||
|
newPacket.type = SerialPacketType::SHUTDOWN_REQUEST;
|
||||||
|
newPacket.clientIndex = clientIndex;
|
||||||
|
newPacket.accountIndex = accountIndex;
|
||||||
|
|
||||||
|
network.SendTo(Channels::SERVER, &newPacket);
|
||||||
|
}
|
||||||
|
|
||||||
|
void InWorld::RequestRegion(int roomIndex, int x, int y) {
|
||||||
|
RegionPacket packet;
|
||||||
|
|
||||||
|
//pack the region's data
|
||||||
|
packet.type = SerialPacketType::REGION_REQUEST;
|
||||||
|
packet.roomIndex = roomIndex;
|
||||||
|
packet.x = x;
|
||||||
|
packet.y = y;
|
||||||
|
|
||||||
|
network.SendTo(Channels::SERVER, &packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Utilities
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
//TODO: convert this into a more generic function?; using parameters for the bounds
|
||||||
|
void InWorld::UpdateMap() {
|
||||||
|
//these represent the zone of regions that the client needs loaded, including the mandatory buffers (+1/-1)
|
||||||
|
int xStart = snapToBase(REGION_WIDTH, camera.x/tileSheet.GetTileW()) - REGION_WIDTH;
|
||||||
|
int xEnd = snapToBase(REGION_WIDTH, (camera.x+camera.width)/tileSheet.GetTileW()) + REGION_WIDTH;
|
||||||
|
|
||||||
|
int yStart = snapToBase(REGION_HEIGHT, camera.y/tileSheet.GetTileH()) - REGION_HEIGHT;
|
||||||
|
int yEnd = snapToBase(REGION_HEIGHT, (camera.y+camera.height)/tileSheet.GetTileH()) + REGION_HEIGHT;
|
||||||
|
|
||||||
|
//prune distant regions
|
||||||
|
for (std::list<Region>::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); /* EMPTY */) {
|
||||||
|
//check if the region is outside of this area
|
||||||
|
if (it->GetX() < xStart || it->GetX() > xEnd || it->GetY() < yStart || it->GetY() > yEnd) {
|
||||||
|
|
||||||
|
//clunky, but the alternative was time consuming
|
||||||
|
int tmpX = it->GetX();
|
||||||
|
int tmpY = it->GetY();
|
||||||
|
++it;
|
||||||
|
|
||||||
|
regionPager.UnloadRegion(tmpX, tmpY);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
|
||||||
|
//request empty regions within this zone
|
||||||
|
for (int i = xStart; i <= xEnd; i += REGION_WIDTH) {
|
||||||
|
for (int j = yStart; j <= yEnd; j += REGION_HEIGHT) {
|
||||||
|
if (!regionPager.FindRegion(i, j)) {
|
||||||
|
RequestRegion(0, i, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -25,10 +25,9 @@
|
|||||||
//maps
|
//maps
|
||||||
#include "region_pager_base.hpp"
|
#include "region_pager_base.hpp"
|
||||||
|
|
||||||
//utilities
|
//networking
|
||||||
#include "udp_network_utility.hpp"
|
#include "udp_network_utility.hpp"
|
||||||
#include "serial_packet.hpp"
|
#include "serial_packet.hpp"
|
||||||
#include "config_utility.hpp"
|
|
||||||
|
|
||||||
//graphics
|
//graphics
|
||||||
#include "image.hpp"
|
#include "image.hpp"
|
||||||
@@ -39,21 +38,22 @@
|
|||||||
//common
|
//common
|
||||||
#include "frame_rate.hpp"
|
#include "frame_rate.hpp"
|
||||||
|
|
||||||
|
#include "base_character.hpp"
|
||||||
|
#include "base_monster.hpp"
|
||||||
|
|
||||||
//client
|
//client
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
#include "base_monster.hpp"
|
|
||||||
#include "local_character.hpp"
|
|
||||||
|
|
||||||
//STL
|
//STL
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
class World: public BaseScene {
|
class InWorld : public BaseScene {
|
||||||
public:
|
public:
|
||||||
//Public access members
|
//Public access members
|
||||||
World(int* const argClientIndex, int* const argAccountIndex);
|
InWorld(int* const argClientIndex, int* const argAccountIndex);
|
||||||
~World();
|
~InWorld();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//Frame loop
|
//Frame loop
|
||||||
@@ -71,64 +71,33 @@ protected:
|
|||||||
void KeyDown(SDL_KeyboardEvent const&);
|
void KeyDown(SDL_KeyboardEvent const&);
|
||||||
void KeyUp(SDL_KeyboardEvent const&);
|
void KeyUp(SDL_KeyboardEvent const&);
|
||||||
|
|
||||||
//handle incoming traffic
|
//Network handlers
|
||||||
void HandlePacket(SerialPacket* const);
|
void HandlePacket(SerialPacket* const);
|
||||||
|
void HandlePong(ServerPacket* const);
|
||||||
|
void HandleDisconnect(ClientPacket* const);
|
||||||
|
void HandleCharacterNew(CharacterPacket* const);
|
||||||
|
void HandleCharacterDelete(CharacterPacket* const);
|
||||||
|
void HandleCharacterUpdate(CharacterPacket* const);
|
||||||
|
void HandleCharacterRejection(TextPacket* const);
|
||||||
|
void HandleRegionContent(RegionPacket* const);
|
||||||
|
|
||||||
//heartbeat system
|
//Server control
|
||||||
void hPing(ServerPacket* const);
|
void RequestSynchronize();
|
||||||
void hPong(ServerPacket* const);
|
void SendPlayerUpdate();
|
||||||
|
void RequestDisconnect();
|
||||||
|
void RequestShutDown();
|
||||||
|
void RequestRegion(int roomIndex, int x, int y);
|
||||||
|
|
||||||
void CheckHeartBeat();
|
//utilities
|
||||||
|
|
||||||
//basic connections
|
|
||||||
void SendLogoutRequest();
|
|
||||||
void SendDisconnectRequest();
|
|
||||||
void SendAdminDisconnectForced();
|
|
||||||
void SendAdminShutdownRequest();
|
|
||||||
|
|
||||||
void hLogoutResponse(ClientPacket* const);
|
|
||||||
void hDisconnectResponse(ClientPacket* const);
|
|
||||||
void hAdminDisconnectForced(ClientPacket* const);
|
|
||||||
|
|
||||||
//map management
|
|
||||||
void SendRegionRequest(int roomIndex, int x, int y);
|
|
||||||
void hRegionContent(RegionPacket* const);
|
|
||||||
void UpdateMap();
|
void UpdateMap();
|
||||||
|
|
||||||
//character management
|
//singleton shortcut
|
||||||
void hCharacterCreate(CharacterPacket* const);
|
UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton();
|
||||||
void hCharacterDelete(CharacterPacket* const);
|
|
||||||
void hQueryCharacterExists(CharacterPacket* const);
|
|
||||||
void hQueryCharacterStats(CharacterPacket* const);
|
|
||||||
void hQueryCharacterLocation(CharacterPacket* const);
|
|
||||||
void hCharacterMovement(CharacterPacket* const);
|
|
||||||
void hCharacterAttack(CharacterPacket* const);
|
|
||||||
void hCharacterDamage(CharacterPacket* const);
|
|
||||||
|
|
||||||
//monster management
|
|
||||||
void hMonsterCreate(MonsterPacket* const);
|
|
||||||
void hMonsterDelete(MonsterPacket* const);
|
|
||||||
void hQueryMonsterExists(MonsterPacket* const);
|
|
||||||
void hQueryMonsterStats(MonsterPacket* const);
|
|
||||||
void hQueryMonsterLocation(MonsterPacket* const);
|
|
||||||
void hMonsterMovement(MonsterPacket* const);
|
|
||||||
void hMonsterAttack(MonsterPacket* const);
|
|
||||||
void hMonsterDamage(MonsterPacket* const);
|
|
||||||
|
|
||||||
//chat
|
|
||||||
void hTextBroadcast(TextPacket* const);
|
|
||||||
void hTextSpeech(TextPacket* const);
|
|
||||||
void hTextWhisper(TextPacket* const);
|
|
||||||
|
|
||||||
//general gameplay
|
|
||||||
void SendLocalCharacterMovement();
|
|
||||||
std::list<BoundingBox> GenerateCollisionGrid(Entity*, int tileWidth, int tileHeight);
|
|
||||||
|
|
||||||
//indexes
|
//indexes
|
||||||
int& clientIndex;
|
int& clientIndex;
|
||||||
int& accountIndex;
|
int& accountIndex;
|
||||||
int characterIndex = -1;
|
int characterIndex = -1;
|
||||||
int roomIndex = -1;
|
|
||||||
|
|
||||||
//graphics
|
//graphics
|
||||||
Image buttonImage;
|
Image buttonImage;
|
||||||
@@ -150,20 +119,16 @@ protected:
|
|||||||
int marginX = 0, marginY = 0;
|
int marginX = 0, marginY = 0;
|
||||||
} camera;
|
} camera;
|
||||||
|
|
||||||
//entities
|
//game components
|
||||||
|
BaseCharacter* localCharacter = nullptr;
|
||||||
std::map<int, BaseCharacter> characterMap;
|
std::map<int, BaseCharacter> characterMap;
|
||||||
std::map<int, BaseMonster> monsterMap;
|
std::map<int, BaseMonster> monsterMap;
|
||||||
LocalCharacter* localCharacter = nullptr;
|
|
||||||
|
|
||||||
//heartbeat
|
//heartbeat
|
||||||
//TODO: (2) Heartbeat needs it's own utility
|
//TODO: This needs it's own utility, for both InWorld and InCombat
|
||||||
typedef std::chrono::steady_clock Clock;
|
typedef std::chrono::steady_clock Clock;
|
||||||
Clock::time_point lastBeat = Clock::now();
|
Clock::time_point lastBeat = Clock::now();
|
||||||
int attemptedBeats = 0;
|
int attemptedBeats = 0;
|
||||||
|
|
||||||
//ugly references; I hate this
|
|
||||||
ConfigUtility& config = ConfigUtility::GetSingleton();
|
|
||||||
UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -22,9 +22,9 @@
|
|||||||
#include "lobby_menu.hpp"
|
#include "lobby_menu.hpp"
|
||||||
|
|
||||||
#include "channels.hpp"
|
#include "channels.hpp"
|
||||||
|
#include "utility.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Public access members
|
//Public access members
|
||||||
@@ -100,14 +100,14 @@ void LobbyMenu::FrameEnd() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LobbyMenu::Render(SDL_Surface* const screen) {
|
void LobbyMenu::Render(SDL_Surface* const screen) {
|
||||||
//TODO: (2) I need a proper UI system for the entire client and the editor
|
//TODO: I need a proper UI system for the entire client and the editor
|
||||||
|
|
||||||
//UI
|
//UI
|
||||||
search.DrawTo(screen);
|
search.DrawTo(screen);
|
||||||
join.DrawTo(screen);
|
join.DrawTo(screen);
|
||||||
back.DrawTo(screen);
|
back.DrawTo(screen);
|
||||||
|
|
||||||
//TODO: (1) draw headers for the server list
|
//TODO: draw headers for the server list
|
||||||
for (int i = 0; i < serverInfo.size(); i++) {
|
for (int i = 0; i < serverInfo.size(); i++) {
|
||||||
//draw the selected server's highlight
|
//draw the selected server's highlight
|
||||||
if (selection == &serverInfo[i]) {
|
if (selection == &serverInfo[i]) {
|
||||||
@@ -123,14 +123,14 @@ void LobbyMenu::Render(SDL_Surface* const screen) {
|
|||||||
font.DrawStringTo(serverInfo[i].name, screen, listBox.x, listBox.y + i*listBox.h);
|
font.DrawStringTo(serverInfo[i].name, screen, listBox.x, listBox.y + i*listBox.h);
|
||||||
|
|
||||||
//draw the player count
|
//draw the player count
|
||||||
std::ostringstream msg;
|
font.DrawStringTo(to_string_custom(serverInfo[i].playerCount), screen, listBox.x + listBox.w, listBox.y + i*listBox.h);
|
||||||
msg << serverInfo[i].playerCount;
|
|
||||||
font.DrawStringTo(msg.str(), screen, listBox.x + listBox.w, listBox.y + i*listBox.h);
|
|
||||||
|
|
||||||
//compatible?
|
//compatible?
|
||||||
if (!serverInfo[i].compatible) {
|
if (!serverInfo[i].compatible) {
|
||||||
font.DrawStringTo("?", screen, listBox.x - font.GetCharW(), listBox.y + i*listBox.h);
|
font.DrawStringTo("?", screen, listBox.x - font.GetCharW(), listBox.y + i*listBox.h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: ping/delay?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -210,11 +210,8 @@ void LobbyMenu::HandlePacket(SerialPacket* const argPacket) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
//handle errors
|
//handle errors
|
||||||
default: {
|
default:
|
||||||
std::ostringstream msg;
|
throw(std::runtime_error(std::string() + "Unknown SerialPacketType encountered in LobbyMenu: " + to_string_custom(static_cast<int>(argPacket->type)) ));
|
||||||
msg << "Unknown SerialPacketType encountered in LobbyMenu: " << static_cast<int>(argPacket->type);
|
|
||||||
throw(std::runtime_error( msg.str() ));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -248,15 +245,15 @@ void LobbyMenu::HandleLoginResponse(ClientPacket* const argPacket) {
|
|||||||
throw(std::runtime_error("Client index invalid during login"));
|
throw(std::runtime_error("Client index invalid during login"));
|
||||||
}
|
}
|
||||||
accountIndex = argPacket->accountIndex;
|
accountIndex = argPacket->accountIndex;
|
||||||
SetNextScene(SceneList::WORLD);
|
SetNextScene(SceneList::INWORLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LobbyMenu::HandleJoinRejection(TextPacket* const argPacket) {
|
void LobbyMenu::HandleJoinRejection(TextPacket* const argPacket) {
|
||||||
//TODO: (9) empty
|
//TODO: Better output for join rejection
|
||||||
}
|
}
|
||||||
|
|
||||||
void LobbyMenu::HandleLoginRejection(TextPacket* const argPacket) {
|
void LobbyMenu::HandleLoginRejection(TextPacket* const argPacket) {
|
||||||
//TODO: (9) empty
|
//TODO: Better output for login rejection
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -84,11 +84,6 @@ void MainMenu::Render(SDL_Surface* const screen) {
|
|||||||
startButton.DrawTo(screen);
|
startButton.DrawTo(screen);
|
||||||
optionsButton.DrawTo(screen);
|
optionsButton.DrawTo(screen);
|
||||||
quitButton.DrawTo(screen);
|
quitButton.DrawTo(screen);
|
||||||
|
|
||||||
//text
|
|
||||||
font.DrawStringTo("Thanks for playing!", screen, 50, screen->h - 50 - image.GetClipH() * 2);
|
|
||||||
font.DrawStringTo("You can get the latest version at: ", screen, 50, screen->h - 50 - image.GetClipH() * 1);
|
|
||||||
font.DrawStringTo("krgamestudios.com", screen, 50, screen->h - 50 - image.GetClipH() * 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -108,7 +103,7 @@ void MainMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||||
//TODO: (2) Buttons should only register as "selected" when the left button is used
|
//TODO: Buttons should only register as "selected" when the left button is used
|
||||||
if (startButton.MouseButtonUp(button) == Button::State::HOVER) {
|
if (startButton.MouseButtonUp(button) == Button::State::HOVER) {
|
||||||
SetNextScene(SceneList::LOBBYMENU);
|
SetNextScene(SceneList::LOBBYMENU);
|
||||||
}
|
}
|
||||||
@@ -125,9 +120,5 @@ void MainMenu::KeyDown(SDL_KeyboardEvent const& key) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainMenu::KeyUp(SDL_KeyboardEvent const& key) {
|
void MainMenu::KeyUp(SDL_KeyboardEvent const& key) {
|
||||||
switch(key.keysym.sym) {
|
//
|
||||||
case SDLK_ESCAPE:
|
|
||||||
QuitEvent();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=.
|
INCLUDES+=. .. ../entities ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/network/packet_types ../../common/ui ../../common/utilities
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
#include "raster_font.hpp"
|
#include "raster_font.hpp"
|
||||||
#include "button.hpp"
|
#include "button.hpp"
|
||||||
|
|
||||||
//NOTE: The options screen needs to be USED
|
//TODO: The options screen needs to be USED
|
||||||
class OptionsMenu : public BaseScene {
|
class OptionsMenu : public BaseScene {
|
||||||
public:
|
public:
|
||||||
//Public access members
|
//Public access members
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -39,7 +39,7 @@ void Timer::Stop() {
|
|||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, Timer& t) {
|
std::ostream& operator<<(std::ostream& os, Timer& t) {
|
||||||
os << t.GetName() << ": ";
|
os << t.GetName() << ": ";
|
||||||
os << std::chrono::duration_cast<std::chrono::microseconds>(t.GetTime()).count();
|
os << std::chrono::duration_cast<std::chrono::milliseconds>(t.GetTime()).count();
|
||||||
os << "us";
|
os << "ms";
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -34,8 +34,8 @@ public:
|
|||||||
Timer(std::string s);
|
Timer(std::string s);
|
||||||
~Timer() = default;
|
~Timer() = default;
|
||||||
|
|
||||||
void Start();
|
inline void Start();
|
||||||
void Stop();
|
inline void Stop();
|
||||||
|
|
||||||
//accessors and mutators
|
//accessors and mutators
|
||||||
Clock::duration GetTime() { return timeSpan; }
|
Clock::duration GetTime() { return timeSpan; }
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -35,8 +35,4 @@ constexpr int CHARACTER_BOUNDS_Y = 16;
|
|||||||
constexpr int CHARACTER_BOUNDS_WIDTH = 32;
|
constexpr int CHARACTER_BOUNDS_WIDTH = 32;
|
||||||
constexpr int CHARACTER_BOUNDS_HEIGHT = 32;
|
constexpr int CHARACTER_BOUNDS_HEIGHT = 32;
|
||||||
|
|
||||||
//the character's sprite format
|
|
||||||
constexpr int CHARACTER_CELLS_X = 4;
|
|
||||||
constexpr int CHARACTER_CELLS_Y = 4;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. ../map
|
INCLUDES+=.
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. ../utilities
|
INCLUDES+=. ../graphics ../utilities
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -24,18 +24,40 @@
|
|||||||
//all map API headers
|
//all map API headers
|
||||||
#include "region_api.hpp"
|
#include "region_api.hpp"
|
||||||
#include "region_pager_api.hpp"
|
#include "region_pager_api.hpp"
|
||||||
|
#include "tile_sheet_api.hpp"
|
||||||
|
|
||||||
|
//macros
|
||||||
|
#include "region.hpp"
|
||||||
|
|
||||||
//useful "globals"
|
//useful "globals"
|
||||||
//...
|
static int getRegionWidth(lua_State* L) {
|
||||||
|
lua_pushinteger(L, REGION_WIDTH);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getRegionHeight(lua_State* L) {
|
||||||
|
lua_pushinteger(L, REGION_HEIGHT);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getRegionDepth(lua_State* L) {
|
||||||
|
lua_pushinteger(L, REGION_DEPTH);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
//This mimics linit.c to create a nested collection of all map modules.
|
//This mimics linit.c to create a nested collection of all map modules.
|
||||||
static const luaL_Reg funcs[] = {
|
static const luaL_Reg funcs[] = {
|
||||||
|
//synonyms
|
||||||
|
{"GetRegionWidth", getRegionWidth},
|
||||||
|
{"GetRegionHeight", getRegionHeight},
|
||||||
|
{"GetRegionDepth", getRegionDepth},
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|
||||||
static const luaL_Reg libs[] = {
|
static const luaL_Reg libs[] = {
|
||||||
{"Region", openRegionAPI},
|
{"Region", openRegionAPI},
|
||||||
{"RegionPager", openRegionPagerAPI},
|
{"RegionPager", openRegionPagerAPI},
|
||||||
|
// {"TileSheet", openTileSheetAPI},
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -48,7 +70,7 @@ int openMapSystemAPI(lua_State* L) {
|
|||||||
|
|
||||||
//push the substable
|
//push the substable
|
||||||
for (const luaL_Reg* lib = libs; lib->func; lib++) {
|
for (const luaL_Reg* lib = libs; lib->func; lib++) {
|
||||||
lib->func(L);
|
lua_pushcfunction(L, lib->func);
|
||||||
lua_setfield(L, -2, lib->name);
|
lua_setfield(L, -2, lib->name);
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -22,7 +22,11 @@
|
|||||||
#ifndef MAPSYSTEMAPI_HPP_
|
#ifndef MAPSYSTEMAPI_HPP_
|
||||||
#define MAPSYSTEMAPI_APP_
|
#define MAPSYSTEMAPI_APP_
|
||||||
|
|
||||||
#include "lua.hpp"
|
#if defined(__MINGW32__)
|
||||||
|
#include "lua/lua.hpp"
|
||||||
|
#else
|
||||||
|
#include "lua.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define TORTUGA_MAP_SYSTEM_API "map_system"
|
#define TORTUGA_MAP_SYSTEM_API "map_system"
|
||||||
LUAMOD_API int openMapSystemAPI(lua_State* L);
|
LUAMOD_API int openMapSystemAPI(lua_State* L);
|
||||||
|
|||||||
+2
-26
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -21,9 +21,9 @@
|
|||||||
*/
|
*/
|
||||||
#include "region.hpp"
|
#include "region.hpp"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
int snapToBase(int base, int x) {
|
int snapToBase(int base, int x) {
|
||||||
return floor((double)x / base) * base;
|
return floor((double)x / base) * base;
|
||||||
@@ -42,41 +42,17 @@ Region::Region(Region const& rhs): x(rhs.x), y(rhs.y) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Region::type_t Region::SetTile(int x, int y, int z, type_t v) {
|
Region::type_t Region::SetTile(int x, int y, int z, type_t v) {
|
||||||
if (x < 0 || y < 0 || z < 0 || x >= REGION_WIDTH || y >= REGION_HEIGHT || z >= REGION_DEPTH) {
|
|
||||||
throw(std::out_of_range("Region::SetTile() argument out of range"));
|
|
||||||
}
|
|
||||||
return tiles[x][y][z] = v;
|
return tiles[x][y][z] = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
Region::type_t Region::GetTile(int x, int y, int z) {
|
Region::type_t Region::GetTile(int x, int y, int z) {
|
||||||
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"));
|
|
||||||
}
|
|
||||||
return tiles[x][y][z];
|
return tiles[x][y][z];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Region::SetSolid(int x, int y, bool b) {
|
bool Region::SetSolid(int x, int y, bool b) {
|
||||||
if (x < 0 || y < 0 || x >= REGION_WIDTH || y >= REGION_HEIGHT) {
|
|
||||||
throw(std::out_of_range("Region::SetSolid() argument out of range"));
|
|
||||||
}
|
|
||||||
return solid[x * REGION_WIDTH + y] = b;
|
return solid[x * REGION_WIDTH + y] = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Region::GetSolid(int x, int y) {
|
bool Region::GetSolid(int x, int y) {
|
||||||
if (x < 0 || y < 0 || x >= REGION_WIDTH || y >= REGION_HEIGHT) {
|
|
||||||
throw(std::out_of_range("Region::GetSolid() argument out of range"));
|
|
||||||
}
|
|
||||||
return solid[x * REGION_WIDTH + y];
|
return solid[x * REGION_WIDTH + y];
|
||||||
}
|
|
||||||
|
|
||||||
int Region::GetX() const {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Region::GetY() const {
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::bitset<REGION_WIDTH*REGION_HEIGHT>* Region::GetSolidBitset() {
|
|
||||||
return &solid;
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -48,10 +48,10 @@ public:
|
|||||||
bool GetSolid(int x, int y);
|
bool GetSolid(int x, int y);
|
||||||
|
|
||||||
//accessors
|
//accessors
|
||||||
int GetX() const;
|
int GetX() const { return x; }
|
||||||
int GetY() const;
|
int GetY() const { return y; }
|
||||||
|
|
||||||
std::bitset<REGION_WIDTH*REGION_HEIGHT>* GetSolidBitset();
|
std::bitset<REGION_WIDTH*REGION_HEIGHT>* GetSolidBitset() { return &solid; }
|
||||||
private:
|
private:
|
||||||
const int x;
|
const int x;
|
||||||
const int y;
|
const int y;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -85,8 +85,6 @@ static const luaL_Reg regionLib[] = {
|
|||||||
{"GetSolid",getSolid},
|
{"GetSolid",getSolid},
|
||||||
{"GetX",getX},
|
{"GetX",getX},
|
||||||
{"GetY",getY},
|
{"GetY",getY},
|
||||||
|
|
||||||
//the global macros
|
|
||||||
{"GetWidth",getWidth},
|
{"GetWidth",getWidth},
|
||||||
{"GetHeight",getHeight},
|
{"GetHeight",getHeight},
|
||||||
{"GetDepth",getDepth},
|
{"GetDepth",getDepth},
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -22,7 +22,11 @@
|
|||||||
#ifndef REGIONAPI_HPP_
|
#ifndef REGIONAPI_HPP_
|
||||||
#define REGIONAPI_HPP_
|
#define REGIONAPI_HPP_
|
||||||
|
|
||||||
#include "lua.hpp"
|
#if defined(__MINGW32__)
|
||||||
|
#include "lua/lua.hpp"
|
||||||
|
#else
|
||||||
|
#include "lua.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define TORTUGA_REGION_NAME "region"
|
#define TORTUGA_REGION_NAME "region"
|
||||||
LUAMOD_API int openRegionAPI(lua_State* L);
|
LUAMOD_API int openRegionAPI(lua_State* L);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -84,22 +84,7 @@ static int createRegion(lua_State* L) {
|
|||||||
|
|
||||||
static int unloadRegion(lua_State* L) {
|
static int unloadRegion(lua_State* L) {
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
||||||
|
pager->UnloadRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||||
//two argument types: coords & the region itself
|
|
||||||
switch(lua_type(L, 2)) {
|
|
||||||
case LUA_TNUMBER:
|
|
||||||
pager->UnloadIf([&](Region const& region) -> bool {
|
|
||||||
int x = lua_tointeger(L, 2);
|
|
||||||
int y = lua_tointeger(L, 3);
|
|
||||||
return region.GetX() == x && region.GetY() == y;
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case LUA_TLIGHTUSERDATA:
|
|
||||||
pager->UnloadIf([&](Region const& region) -> bool {
|
|
||||||
return (®ion) == lua_touserdata(L, 2);
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,13 +116,6 @@ static int setOnUnload(lua_State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//debugging
|
|
||||||
static int containerSize(lua_State* L) {
|
|
||||||
RegionPagerLua* pager = static_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
|
||||||
lua_pushinteger(L, pager->GetContainer()->size());
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const luaL_Reg regionPagerLib[] = {
|
static const luaL_Reg regionPagerLib[] = {
|
||||||
//curry
|
//curry
|
||||||
{"SetTile", setTile},
|
{"SetTile", setTile},
|
||||||
@@ -158,9 +136,6 @@ static const luaL_Reg regionPagerLib[] = {
|
|||||||
{"SetOnCreate",setOnCreate},
|
{"SetOnCreate",setOnCreate},
|
||||||
{"SetOnUnload",setOnUnload},
|
{"SetOnUnload",setOnUnload},
|
||||||
|
|
||||||
//debugging
|
|
||||||
{"ContainerSize", containerSize},
|
|
||||||
|
|
||||||
//sentinel
|
//sentinel
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -22,7 +22,11 @@
|
|||||||
#ifndef REGIONPAGERAPI_HPP_
|
#ifndef REGIONPAGERAPI_HPP_
|
||||||
#define REGIONPAGERAPI_HPP_
|
#define REGIONPAGERAPI_HPP_
|
||||||
|
|
||||||
#include "lua.hpp"
|
#if defined(__MINGW32__)
|
||||||
|
#include "lua/lua.hpp"
|
||||||
|
#else
|
||||||
|
#include "lua.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define TORTUGA_REGION_PAGER_NAME "region_pager"
|
#define TORTUGA_REGION_PAGER_NAME "region_pager"
|
||||||
LUAMOD_API int openRegionPagerAPI(lua_State* L);
|
LUAMOD_API int openRegionPagerAPI(lua_State* L);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -24,9 +24,17 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
RegionPagerBase::RegionPagerBase() {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
RegionPagerBase::RegionPagerBase(RegionPagerBase&& rhs) {
|
||||||
|
regionList = std::move(rhs.regionList);
|
||||||
|
}
|
||||||
|
|
||||||
RegionPagerBase::~RegionPagerBase() {
|
RegionPagerBase::~RegionPagerBase() {
|
||||||
UnloadAll();
|
UnloadAll();
|
||||||
};
|
}
|
||||||
|
|
||||||
Region::type_t RegionPagerBase::SetTile(int x, int y, int z, Region::type_t v) {
|
Region::type_t RegionPagerBase::SetTile(int x, int y, int z, Region::type_t v) {
|
||||||
Region* ptr = GetRegion(x, y);
|
Region* ptr = GetRegion(x, y);
|
||||||
@@ -92,14 +100,12 @@ Region* RegionPagerBase::CreateRegion(int x, int y) {
|
|||||||
return ®ionList.front();
|
return ®ionList.front();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegionPagerBase::UnloadIf(std::function<bool(Region const&)> fn) {
|
void RegionPagerBase::UnloadRegion(int x, int y) {
|
||||||
regionList.remove_if(fn);
|
regionList.remove_if([x, y](Region& region) -> bool {
|
||||||
|
return region.GetX() == x && region.GetY() == y;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegionPagerBase::UnloadAll() {
|
void RegionPagerBase::UnloadAll() {
|
||||||
regionList.clear();
|
regionList.clear();
|
||||||
}
|
|
||||||
|
|
||||||
std::list<Region>* RegionPagerBase::GetContainer() {
|
|
||||||
return ®ionList;
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -24,12 +24,12 @@
|
|||||||
|
|
||||||
#include "region.hpp"
|
#include "region.hpp"
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
class RegionPagerBase {
|
class RegionPagerBase {
|
||||||
public:
|
public:
|
||||||
RegionPagerBase() = default;
|
RegionPagerBase();
|
||||||
|
RegionPagerBase(RegionPagerBase&&);
|
||||||
virtual ~RegionPagerBase();
|
virtual ~RegionPagerBase();
|
||||||
|
|
||||||
//tile manipulation
|
//tile manipulation
|
||||||
@@ -48,12 +48,12 @@ public:
|
|||||||
virtual Region* LoadRegion(int x, int y);
|
virtual Region* LoadRegion(int x, int y);
|
||||||
virtual Region* SaveRegion(int x, int y);
|
virtual Region* SaveRegion(int x, int y);
|
||||||
virtual Region* CreateRegion(int x, int y);
|
virtual Region* CreateRegion(int x, int y);
|
||||||
|
virtual void UnloadRegion(int x, int y);
|
||||||
|
|
||||||
virtual void UnloadIf(std::function<bool(Region const&)> fn);
|
|
||||||
virtual void UnloadAll();
|
virtual void UnloadAll();
|
||||||
|
|
||||||
//accessors & mutators
|
//accessors & mutators
|
||||||
std::list<Region>* GetContainer();
|
std::list<Region>* GetContainer() { return ®ionList; }
|
||||||
protected:
|
protected:
|
||||||
std::list<Region> regionList;
|
std::list<Region> regionList;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -23,8 +23,17 @@
|
|||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
//DOCS: Load, Save and Create fail unless the lua function has been set
|
RegionPagerLua::RegionPagerLua() {
|
||||||
//DOCS: UnloadIf and UnloadAll will still continue without the function set
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
RegionPagerLua::RegionPagerLua(RegionPagerLua&& rhs) {
|
||||||
|
lua = rhs.lua;
|
||||||
|
loadRef = rhs.loadRef;
|
||||||
|
saveRef = rhs.saveRef;
|
||||||
|
createRef = rhs.createRef;
|
||||||
|
unloadRef = rhs.unloadRef;
|
||||||
|
}
|
||||||
|
|
||||||
RegionPagerLua::~RegionPagerLua() {
|
RegionPagerLua::~RegionPagerLua() {
|
||||||
//unload all regions
|
//unload all regions
|
||||||
@@ -133,25 +142,23 @@ Region* RegionPagerLua::CreateRegion(int x, int y) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//no return
|
//no return
|
||||||
void RegionPagerLua::UnloadIf(std::function<bool(Region const&)> fn) {
|
void RegionPagerLua::UnloadRegion(int x, int y) {
|
||||||
//get the pager's function from the registry
|
//get the pager's function from the registry
|
||||||
lua_rawgeti(lua, LUA_REGISTRYINDEX, unloadRef);
|
lua_rawgeti(lua, LUA_REGISTRYINDEX, unloadRef);
|
||||||
|
|
||||||
//check if this function is available
|
//check if this function is available
|
||||||
if (lua_isnil(lua, -1)) {
|
if (lua_isnil(lua, -1)) {
|
||||||
lua_pop(lua, 1);
|
lua_pop(lua, 1);
|
||||||
//remove the regions anyway
|
|
||||||
regionList.remove_if(fn);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//run each region through this lambda
|
//run each region through this lambda
|
||||||
regionList.remove_if([&](Region& region) -> bool {
|
regionList.remove_if([&](Region& region) -> bool {
|
||||||
if (fn(region)) {
|
if (region.GetX() == x && region.GetY() == y) {
|
||||||
|
|
||||||
//push a copy of the function onto the stack with the region
|
//push a copy of the function onto the stack with the region
|
||||||
lua_pushvalue(lua, -1);
|
lua_pushvalue(lua, -1);
|
||||||
lua_pushlightuserdata(lua, static_cast<void*>(®ion));
|
lua_pushlightuserdata(lua, ®ion);
|
||||||
|
|
||||||
//call the function, 1 arg, 0 return
|
//call the function, 1 arg, 0 return
|
||||||
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) {
|
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) {
|
||||||
@@ -169,6 +176,7 @@ void RegionPagerLua::UnloadIf(std::function<bool(Region const&)> fn) {
|
|||||||
lua_pop(lua, 1);
|
lua_pop(lua, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//no return
|
||||||
void RegionPagerLua::UnloadAll() {
|
void RegionPagerLua::UnloadAll() {
|
||||||
//get the pager's function from the registry
|
//get the pager's function from the registry
|
||||||
lua_rawgeti(lua, LUA_REGISTRYINDEX, unloadRef);
|
lua_rawgeti(lua, LUA_REGISTRYINDEX, unloadRef);
|
||||||
@@ -176,8 +184,6 @@ void RegionPagerLua::UnloadAll() {
|
|||||||
//check if this function is available
|
//check if this function is available
|
||||||
if (lua_isnil(lua, -1)) {
|
if (lua_isnil(lua, -1)) {
|
||||||
lua_pop(lua, 1);
|
lua_pop(lua, 1);
|
||||||
//remove the regions anyway
|
|
||||||
regionList.clear();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -24,22 +24,26 @@
|
|||||||
|
|
||||||
#include "region_pager_base.hpp"
|
#include "region_pager_base.hpp"
|
||||||
|
|
||||||
#include "lua.hpp"
|
#if defined(__MINGW32__)
|
||||||
|
#include "lua/lua.hpp"
|
||||||
|
#else
|
||||||
|
#include "lua.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class RegionPagerLua : public RegionPagerBase {
|
class RegionPagerLua : public RegionPagerBase {
|
||||||
public:
|
public:
|
||||||
RegionPagerLua() = default;
|
RegionPagerLua();
|
||||||
|
RegionPagerLua(RegionPagerLua&&);
|
||||||
~RegionPagerLua();
|
~RegionPagerLua();
|
||||||
|
|
||||||
//region manipulation
|
//region manipulation
|
||||||
Region* LoadRegion(int x, int y) override;
|
Region* LoadRegion(int x, int y) override;
|
||||||
Region* SaveRegion(int x, int y) override;
|
Region* SaveRegion(int x, int y) override;
|
||||||
Region* CreateRegion(int x, int y) override;
|
Region* CreateRegion(int x, int y) override;
|
||||||
|
void UnloadRegion(int x, int y) override;
|
||||||
|
|
||||||
void UnloadIf(std::function<bool(Region const&)> fn) override;
|
|
||||||
void UnloadAll() override;
|
void UnloadAll() override;
|
||||||
|
|
||||||
//accessors & mutators
|
//accessors & mutators
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
|
*
|
||||||
|
* 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 "tile_sheet_api.hpp"
|
||||||
|
|
||||||
|
#include "tile_sheet.hpp"
|
||||||
|
|
||||||
|
static int load(lua_State* L) {
|
||||||
|
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
|
||||||
|
sheet->Load(lua_tostring(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int unload(lua_State* L) {
|
||||||
|
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
|
||||||
|
sheet->Unload();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getXCount(lua_State* L) {
|
||||||
|
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
|
||||||
|
lua_pushinteger(L, sheet->GetXCount());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getYCount(lua_State* L) {
|
||||||
|
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
|
||||||
|
lua_pushinteger(L, sheet->GetYCount());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getTileW(lua_State* L) {
|
||||||
|
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
|
||||||
|
lua_pushinteger(L, sheet->GetTileW());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getTileH(lua_State* L) {
|
||||||
|
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
|
||||||
|
lua_pushinteger(L, sheet->GetTileH());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const luaL_Reg tileSheetLib[] = {
|
||||||
|
{"Load",load},
|
||||||
|
{"Unload",unload},
|
||||||
|
{"GetXCount",getXCount},
|
||||||
|
{"GetYCount",getYCount},
|
||||||
|
{"GetTileW",getTileW},
|
||||||
|
{"GetTileH",getTileH},
|
||||||
|
{nullptr, nullptr}
|
||||||
|
};
|
||||||
|
|
||||||
|
LUAMOD_API int openTileSheetAPI(lua_State* L) {
|
||||||
|
luaL_newlib(L, tileSheetLib);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -19,12 +19,16 @@
|
|||||||
* 3. This notice may not be removed or altered from any source
|
* 3. This notice may not be removed or altered from any source
|
||||||
* distribution.
|
* distribution.
|
||||||
*/
|
*/
|
||||||
#ifndef CHARACTERAPI_HPP_
|
#ifndef TILESHEETAPI_HPP_
|
||||||
#define CHARACTERAPI_HPP_
|
#define TILESHEETAPI_HPP_
|
||||||
|
|
||||||
#include "lua.hpp"
|
#if defined(__MINGW32__)
|
||||||
|
#include "lua/lua.hpp"
|
||||||
|
#else
|
||||||
|
#include "lua.hpp"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define TORTUGA_CHARACTER_API "character"
|
#define TORTUGA_TILE_SHEET_NAME "tile_sheet"
|
||||||
LUAMOD_API int openCharacterAPI(lua_State* L);
|
LUAMOD_API int openTileSheetAPI(lua_State* L);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -34,11 +34,14 @@ struct CharacterPacket : SerialPacketBase {
|
|||||||
|
|
||||||
//the owner
|
//the owner
|
||||||
int accountIndex;
|
int accountIndex;
|
||||||
|
//TODO: Authentication token?
|
||||||
|
|
||||||
//location
|
//location
|
||||||
int roomIndex;
|
int roomIndex;
|
||||||
Vector2 origin;
|
Vector2 origin;
|
||||||
Vector2 motion;
|
Vector2 motion;
|
||||||
|
|
||||||
|
//gameplay components: equipment, items, buffs, debuffs...
|
||||||
};
|
};
|
||||||
|
|
||||||
void serializeCharacter(void* buffer, CharacterPacket* packet);
|
void serializeCharacter(void* buffer, CharacterPacket* packet);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -28,7 +28,6 @@ struct ClientPacket : SerialPacketBase {
|
|||||||
int clientIndex;
|
int clientIndex;
|
||||||
int accountIndex;
|
int accountIndex;
|
||||||
char username[PACKET_STRING_SIZE];
|
char username[PACKET_STRING_SIZE];
|
||||||
//TODO: (9) password, auth token
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void serializeClient(void* buffer, ClientPacket* packet);
|
void serializeClient(void* buffer, ClientPacket* packet);
|
||||||
|
|||||||
@@ -1,70 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
|
||||||
*
|
|
||||||
* 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 "monster_packet.hpp"
|
|
||||||
|
|
||||||
#include "serial_utility.hpp"
|
|
||||||
|
|
||||||
void serializeMonster(void* buffer, MonsterPacket* packet) {
|
|
||||||
serialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
|
|
||||||
|
|
||||||
//identify the monster
|
|
||||||
serialCopy(&buffer, &packet->monsterIndex, sizeof(int));
|
|
||||||
serialCopy(&buffer, packet->handle, PACKET_STRING_SIZE);
|
|
||||||
serialCopy(&buffer, packet->avatar, PACKET_STRING_SIZE);
|
|
||||||
|
|
||||||
//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));
|
|
||||||
}
|
|
||||||
|
|
||||||
void deserializeMonster(void* buffer, MonsterPacket* packet) {
|
|
||||||
deserialCopy(&buffer, &packet->type, sizeof(SerialPacketType));
|
|
||||||
|
|
||||||
//identify the monster
|
|
||||||
deserialCopy(&buffer, &packet->monsterIndex, sizeof(int));
|
|
||||||
deserialCopy(&buffer, packet->handle, PACKET_STRING_SIZE);
|
|
||||||
deserialCopy(&buffer, packet->avatar, PACKET_STRING_SIZE);
|
|
||||||
|
|
||||||
//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));
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
#ifndef MONSTERPACKET_HPP_
|
|
||||||
#define MONSTERPACKET_HPP_
|
|
||||||
|
|
||||||
#include "serial_packet_base.hpp"
|
|
||||||
|
|
||||||
#include "bounding_box.hpp"
|
|
||||||
#include "vector2.hpp"
|
|
||||||
|
|
||||||
struct MonsterPacket : SerialPacketBase {
|
|
||||||
//identify the monster
|
|
||||||
int monsterIndex;
|
|
||||||
char handle[PACKET_STRING_SIZE];
|
|
||||||
char avatar[PACKET_STRING_SIZE];
|
|
||||||
BoundingBox bounds;
|
|
||||||
|
|
||||||
//location
|
|
||||||
int roomIndex;
|
|
||||||
Vector2 origin;
|
|
||||||
Vector2 motion;
|
|
||||||
};
|
|
||||||
|
|
||||||
void serializeMonster(void* buffer, MonsterPacket* packet);
|
|
||||||
void deserializeMonster(void* buffer, MonsterPacket* packet);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -29,12 +29,6 @@ void serializeText(void* buffer, TextPacket* packet) {
|
|||||||
//content
|
//content
|
||||||
serialCopy(&buffer, packet->name, PACKET_STRING_SIZE);
|
serialCopy(&buffer, packet->name, PACKET_STRING_SIZE);
|
||||||
serialCopy(&buffer, packet->text, PACKET_STRING_SIZE);
|
serialCopy(&buffer, packet->text, PACKET_STRING_SIZE);
|
||||||
|
|
||||||
//location
|
|
||||||
serialCopy(&buffer, &packet->roomIndex, sizeof(int));
|
|
||||||
serialCopy(&buffer, &packet->origin.x, sizeof(double));
|
|
||||||
serialCopy(&buffer, &packet->origin.y, sizeof(double));
|
|
||||||
serialCopy(&buffer, &packet->range, sizeof(int));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void deserializeText(void* buffer, TextPacket* packet) {
|
void deserializeText(void* buffer, TextPacket* packet) {
|
||||||
@@ -43,10 +37,4 @@ void deserializeText(void* buffer, TextPacket* packet) {
|
|||||||
//content
|
//content
|
||||||
deserialCopy(&buffer, packet->name, PACKET_STRING_SIZE);
|
deserialCopy(&buffer, packet->name, PACKET_STRING_SIZE);
|
||||||
deserialCopy(&buffer, packet->text, PACKET_STRING_SIZE);
|
deserialCopy(&buffer, packet->text, PACKET_STRING_SIZE);
|
||||||
|
|
||||||
//location
|
|
||||||
deserialCopy(&buffer, &packet->roomIndex, sizeof(int));
|
|
||||||
deserialCopy(&buffer, &packet->origin.x, sizeof(double));
|
|
||||||
deserialCopy(&buffer, &packet->origin.y, sizeof(double));
|
|
||||||
deserialCopy(&buffer, &packet->range, sizeof(int));
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -24,14 +24,9 @@
|
|||||||
|
|
||||||
#include "serial_packet_base.hpp"
|
#include "serial_packet_base.hpp"
|
||||||
|
|
||||||
#include "vector2.hpp"
|
|
||||||
|
|
||||||
struct TextPacket : SerialPacketBase {
|
struct TextPacket : SerialPacketBase {
|
||||||
char name[PACKET_STRING_SIZE];
|
char name[PACKET_STRING_SIZE];
|
||||||
char text[PACKET_STRING_SIZE];
|
char text[PACKET_STRING_SIZE];
|
||||||
int roomIndex;
|
|
||||||
Vector2 origin;
|
|
||||||
int range;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void serializeText(void* buffer, TextPacket* packet);
|
void serializeText(void* buffer, TextPacket* packet);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -25,7 +25,6 @@
|
|||||||
#include "serial_packet_base.hpp"
|
#include "serial_packet_base.hpp"
|
||||||
#include "character_packet.hpp"
|
#include "character_packet.hpp"
|
||||||
#include "client_packet.hpp"
|
#include "client_packet.hpp"
|
||||||
#include "monster_packet.hpp"
|
|
||||||
#include "region_packet.hpp"
|
#include "region_packet.hpp"
|
||||||
#include "server_packet.hpp"
|
#include "server_packet.hpp"
|
||||||
#include "text_packet.hpp"
|
#include "text_packet.hpp"
|
||||||
@@ -34,15 +33,14 @@
|
|||||||
typedef SerialPacketBase SerialPacket;
|
typedef SerialPacketBase SerialPacket;
|
||||||
|
|
||||||
//DOCS: NETWORK_VERSION is used to discern compatible servers and clients
|
//DOCS: NETWORK_VERSION is used to discern compatible servers and clients
|
||||||
constexpr int NETWORK_VERSION = 20150214;
|
constexpr int NETWORK_VERSION = -1;
|
||||||
|
|
||||||
union MaxPacket {
|
union MaxPacket {
|
||||||
CharacterPacket a;
|
CharacterPacket a;
|
||||||
ClientPacket b;
|
ClientPacket b;
|
||||||
MonsterPacket c;
|
RegionPacket c;
|
||||||
RegionPacket d;
|
ServerPacket d;
|
||||||
ServerPacket e;
|
TextPacket e;
|
||||||
TextPacket f;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr int MAX_PACKET_SIZE = sizeof(MaxPacket);
|
constexpr int MAX_PACKET_SIZE = sizeof(MaxPacket);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -27,9 +27,10 @@
|
|||||||
* valid data, but it will still be carried in that packet's format.
|
* valid data, but it will still be carried in that packet's format.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//TODO: This needs to be smoothed out
|
||||||
enum class SerialPacketType {
|
enum class SerialPacketType {
|
||||||
//default: there is something wrong
|
//default: there is something wrong
|
||||||
NONE,
|
NONE = 0,
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//ServerPacket
|
//ServerPacket
|
||||||
@@ -56,7 +57,7 @@ enum class SerialPacketType {
|
|||||||
//disconnect from the server
|
//disconnect from the server
|
||||||
DISCONNECT_REQUEST,
|
DISCONNECT_REQUEST,
|
||||||
DISCONNECT_RESPONSE,
|
DISCONNECT_RESPONSE,
|
||||||
ADMIN_DISCONNECT_FORCED,
|
DISCONNECT_FORCED,
|
||||||
|
|
||||||
//load the account
|
//load the account
|
||||||
LOGIN_REQUEST,
|
LOGIN_REQUEST,
|
||||||
@@ -67,7 +68,7 @@ enum class SerialPacketType {
|
|||||||
LOGOUT_RESPONSE,
|
LOGOUT_RESPONSE,
|
||||||
|
|
||||||
//shut down the server
|
//shut down the server
|
||||||
ADMIN_SHUTDOWN_REQUEST,
|
SHUTDOWN_REQUEST,
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//RegionPacket
|
//RegionPacket
|
||||||
@@ -75,7 +76,7 @@ enum class SerialPacketType {
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
//map data
|
//map data
|
||||||
REGION_REQUEST,
|
REGION_REQUEST, //NOTE: technically a query
|
||||||
REGION_CONTENT,
|
REGION_CONTENT,
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -83,7 +84,8 @@ enum class SerialPacketType {
|
|||||||
// character index,
|
// character index,
|
||||||
// handle, avatar,
|
// handle, avatar,
|
||||||
// account index (owner),
|
// account index (owner),
|
||||||
// room index, origin, motion
|
// room index, origin, motion,
|
||||||
|
// statistics
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
//character management
|
//character management
|
||||||
@@ -98,31 +100,11 @@ enum class SerialPacketType {
|
|||||||
QUERY_CHARACTER_LOCATION,
|
QUERY_CHARACTER_LOCATION,
|
||||||
|
|
||||||
//set the info in the server
|
//set the info in the server
|
||||||
CHARACTER_MOVEMENT,
|
CHARACTER_SET_ROOM,
|
||||||
CHARACTER_ATTACK,
|
CHARACTER_SET_ORIGIN,
|
||||||
CHARACTER_DAMAGE,
|
CHARACTER_SET_MOTION,
|
||||||
|
|
||||||
//admin control
|
//TODO: enemy management
|
||||||
// ADMIN_SET_CHARACTER_ORIGIN,
|
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
//MonsterPacket
|
|
||||||
// monster index,
|
|
||||||
// handle, avatar
|
|
||||||
// bounds
|
|
||||||
// room index, origin, motion
|
|
||||||
//-------------------------
|
|
||||||
|
|
||||||
MONSTER_CREATE,
|
|
||||||
MONSTER_DELETE,
|
|
||||||
|
|
||||||
QUERY_MONSTER_EXISTS,
|
|
||||||
QUERY_MONSTER_STATS,
|
|
||||||
QUERY_MONSTER_LOCATION,
|
|
||||||
|
|
||||||
MONSTER_MOVEMENT,
|
|
||||||
MONSTER_ATTACK,
|
|
||||||
MONSTER_DAMAGE,
|
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//TextPacket
|
//TextPacket
|
||||||
@@ -131,17 +113,12 @@ enum class SerialPacketType {
|
|||||||
|
|
||||||
//general speech
|
//general speech
|
||||||
TEXT_BROADCAST,
|
TEXT_BROADCAST,
|
||||||
TEXT_SPEECH,
|
|
||||||
TEXT_WHISPER,
|
|
||||||
|
|
||||||
//rejection/error messages
|
//rejection/error messages
|
||||||
JOIN_REJECTION,
|
JOIN_REJECTION,
|
||||||
LOGIN_REJECTION,
|
LOGIN_REJECTION,
|
||||||
REGION_REJECTION,
|
|
||||||
CHARACTER_REJECTION,
|
CHARACTER_REJECTION,
|
||||||
MONSTER_REJECTION,
|
|
||||||
SHUTDOWN_REJECTION,
|
SHUTDOWN_REJECTION,
|
||||||
QUERY_REJECTION,
|
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//not used
|
//not used
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -24,7 +24,6 @@
|
|||||||
//packet types
|
//packet types
|
||||||
#include "character_packet.hpp"
|
#include "character_packet.hpp"
|
||||||
#include "client_packet.hpp"
|
#include "client_packet.hpp"
|
||||||
#include "monster_packet.hpp"
|
|
||||||
#include "region_packet.hpp"
|
#include "region_packet.hpp"
|
||||||
#include "server_packet.hpp"
|
#include "server_packet.hpp"
|
||||||
#include "text_packet.hpp"
|
#include "text_packet.hpp"
|
||||||
@@ -57,12 +56,12 @@ void serializePacket(void* buffer, SerialPacketBase* packet) {
|
|||||||
case SerialPacketType::JOIN_RESPONSE:
|
case SerialPacketType::JOIN_RESPONSE:
|
||||||
case SerialPacketType::DISCONNECT_REQUEST:
|
case SerialPacketType::DISCONNECT_REQUEST:
|
||||||
case SerialPacketType::DISCONNECT_RESPONSE:
|
case SerialPacketType::DISCONNECT_RESPONSE:
|
||||||
case SerialPacketType::ADMIN_DISCONNECT_FORCED:
|
case SerialPacketType::DISCONNECT_FORCED:
|
||||||
case SerialPacketType::LOGIN_REQUEST:
|
case SerialPacketType::LOGIN_REQUEST:
|
||||||
case SerialPacketType::LOGIN_RESPONSE:
|
case SerialPacketType::LOGIN_RESPONSE:
|
||||||
case SerialPacketType::LOGOUT_REQUEST:
|
case SerialPacketType::LOGOUT_REQUEST:
|
||||||
case SerialPacketType::LOGOUT_RESPONSE:
|
case SerialPacketType::LOGOUT_RESPONSE:
|
||||||
case SerialPacketType::ADMIN_SHUTDOWN_REQUEST:
|
case SerialPacketType::SHUTDOWN_REQUEST:
|
||||||
serializeClient(buffer, static_cast<ClientPacket*>(packet));
|
serializeClient(buffer, static_cast<ClientPacket*>(packet));
|
||||||
break;
|
break;
|
||||||
case SerialPacketType::REGION_REQUEST:
|
case SerialPacketType::REGION_REQUEST:
|
||||||
@@ -76,31 +75,16 @@ void serializePacket(void* buffer, SerialPacketBase* packet) {
|
|||||||
case SerialPacketType::QUERY_CHARACTER_EXISTS:
|
case SerialPacketType::QUERY_CHARACTER_EXISTS:
|
||||||
case SerialPacketType::QUERY_CHARACTER_STATS:
|
case SerialPacketType::QUERY_CHARACTER_STATS:
|
||||||
case SerialPacketType::QUERY_CHARACTER_LOCATION:
|
case SerialPacketType::QUERY_CHARACTER_LOCATION:
|
||||||
case SerialPacketType::CHARACTER_MOVEMENT:
|
case SerialPacketType::CHARACTER_SET_ROOM:
|
||||||
case SerialPacketType::CHARACTER_ATTACK:
|
case SerialPacketType::CHARACTER_SET_ORIGIN:
|
||||||
case SerialPacketType::CHARACTER_DAMAGE:
|
case SerialPacketType::CHARACTER_SET_MOTION:
|
||||||
serializeCharacter(buffer, static_cast<CharacterPacket*>(packet));
|
serializeCharacter(buffer, static_cast<CharacterPacket*>(packet));
|
||||||
break;
|
break;
|
||||||
case SerialPacketType::MONSTER_CREATE:
|
|
||||||
case SerialPacketType::MONSTER_DELETE:
|
|
||||||
case SerialPacketType::QUERY_MONSTER_EXISTS:
|
|
||||||
case SerialPacketType::QUERY_MONSTER_STATS:
|
|
||||||
case SerialPacketType::QUERY_MONSTER_LOCATION:
|
|
||||||
case SerialPacketType::MONSTER_MOVEMENT:
|
|
||||||
case SerialPacketType::MONSTER_ATTACK:
|
|
||||||
case SerialPacketType::MONSTER_DAMAGE:
|
|
||||||
serializeMonster(buffer, static_cast<MonsterPacket*>(packet));
|
|
||||||
break;
|
|
||||||
case SerialPacketType::TEXT_BROADCAST:
|
case SerialPacketType::TEXT_BROADCAST:
|
||||||
case SerialPacketType::TEXT_SPEECH:
|
|
||||||
case SerialPacketType::TEXT_WHISPER:
|
|
||||||
case SerialPacketType::JOIN_REJECTION:
|
case SerialPacketType::JOIN_REJECTION:
|
||||||
case SerialPacketType::LOGIN_REJECTION:
|
case SerialPacketType::LOGIN_REJECTION:
|
||||||
case SerialPacketType::REGION_REJECTION:
|
|
||||||
case SerialPacketType::CHARACTER_REJECTION:
|
case SerialPacketType::CHARACTER_REJECTION:
|
||||||
case SerialPacketType::MONSTER_REJECTION:
|
|
||||||
case SerialPacketType::SHUTDOWN_REJECTION:
|
case SerialPacketType::SHUTDOWN_REJECTION:
|
||||||
case SerialPacketType::QUERY_REJECTION:
|
|
||||||
serializeText(buffer, static_cast<TextPacket*>(packet));
|
serializeText(buffer, static_cast<TextPacket*>(packet));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -111,7 +95,7 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) {
|
|||||||
SerialPacketType type;
|
SerialPacketType type;
|
||||||
memcpy(&type, buffer, sizeof(SerialPacketType));
|
memcpy(&type, buffer, sizeof(SerialPacketType));
|
||||||
|
|
||||||
switch(type) {
|
switch(packet->type) {
|
||||||
case SerialPacketType::PING:
|
case SerialPacketType::PING:
|
||||||
case SerialPacketType::PONG:
|
case SerialPacketType::PONG:
|
||||||
case SerialPacketType::BROADCAST_REQUEST:
|
case SerialPacketType::BROADCAST_REQUEST:
|
||||||
@@ -122,12 +106,12 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) {
|
|||||||
case SerialPacketType::JOIN_RESPONSE:
|
case SerialPacketType::JOIN_RESPONSE:
|
||||||
case SerialPacketType::DISCONNECT_REQUEST:
|
case SerialPacketType::DISCONNECT_REQUEST:
|
||||||
case SerialPacketType::DISCONNECT_RESPONSE:
|
case SerialPacketType::DISCONNECT_RESPONSE:
|
||||||
case SerialPacketType::ADMIN_DISCONNECT_FORCED:
|
case SerialPacketType::DISCONNECT_FORCED:
|
||||||
case SerialPacketType::LOGIN_REQUEST:
|
case SerialPacketType::LOGIN_REQUEST:
|
||||||
case SerialPacketType::LOGIN_RESPONSE:
|
case SerialPacketType::LOGIN_RESPONSE:
|
||||||
case SerialPacketType::LOGOUT_REQUEST:
|
case SerialPacketType::LOGOUT_REQUEST:
|
||||||
case SerialPacketType::LOGOUT_RESPONSE:
|
case SerialPacketType::LOGOUT_RESPONSE:
|
||||||
case SerialPacketType::ADMIN_SHUTDOWN_REQUEST:
|
case SerialPacketType::SHUTDOWN_REQUEST:
|
||||||
deserializeClient(buffer, static_cast<ClientPacket*>(packet));
|
deserializeClient(buffer, static_cast<ClientPacket*>(packet));
|
||||||
break;
|
break;
|
||||||
case SerialPacketType::REGION_REQUEST:
|
case SerialPacketType::REGION_REQUEST:
|
||||||
@@ -141,31 +125,16 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) {
|
|||||||
case SerialPacketType::QUERY_CHARACTER_EXISTS:
|
case SerialPacketType::QUERY_CHARACTER_EXISTS:
|
||||||
case SerialPacketType::QUERY_CHARACTER_STATS:
|
case SerialPacketType::QUERY_CHARACTER_STATS:
|
||||||
case SerialPacketType::QUERY_CHARACTER_LOCATION:
|
case SerialPacketType::QUERY_CHARACTER_LOCATION:
|
||||||
case SerialPacketType::CHARACTER_MOVEMENT:
|
case SerialPacketType::CHARACTER_SET_ROOM:
|
||||||
case SerialPacketType::CHARACTER_ATTACK:
|
case SerialPacketType::CHARACTER_SET_ORIGIN:
|
||||||
case SerialPacketType::CHARACTER_DAMAGE:
|
case SerialPacketType::CHARACTER_SET_MOTION:
|
||||||
deserializeCharacter(buffer, static_cast<CharacterPacket*>(packet));
|
deserializeCharacter(buffer, static_cast<CharacterPacket*>(packet));
|
||||||
break;
|
break;
|
||||||
case SerialPacketType::MONSTER_CREATE:
|
|
||||||
case SerialPacketType::MONSTER_DELETE:
|
|
||||||
case SerialPacketType::QUERY_MONSTER_EXISTS:
|
|
||||||
case SerialPacketType::QUERY_MONSTER_STATS:
|
|
||||||
case SerialPacketType::QUERY_MONSTER_LOCATION:
|
|
||||||
case SerialPacketType::MONSTER_MOVEMENT:
|
|
||||||
case SerialPacketType::MONSTER_ATTACK:
|
|
||||||
case SerialPacketType::MONSTER_DAMAGE:
|
|
||||||
deserializeMonster(buffer, static_cast<MonsterPacket*>(packet));
|
|
||||||
break;
|
|
||||||
case SerialPacketType::TEXT_BROADCAST:
|
case SerialPacketType::TEXT_BROADCAST:
|
||||||
case SerialPacketType::TEXT_SPEECH:
|
|
||||||
case SerialPacketType::TEXT_WHISPER:
|
|
||||||
case SerialPacketType::JOIN_REJECTION:
|
case SerialPacketType::JOIN_REJECTION:
|
||||||
case SerialPacketType::LOGIN_REJECTION:
|
case SerialPacketType::LOGIN_REJECTION:
|
||||||
case SerialPacketType::REGION_REJECTION:
|
|
||||||
case SerialPacketType::CHARACTER_REJECTION:
|
case SerialPacketType::CHARACTER_REJECTION:
|
||||||
case SerialPacketType::MONSTER_REJECTION:
|
|
||||||
case SerialPacketType::SHUTDOWN_REJECTION:
|
case SerialPacketType::SHUTDOWN_REJECTION:
|
||||||
case SerialPacketType::QUERY_REJECTION:
|
|
||||||
deserializeText(buffer, static_cast<TextPacket*>(packet));
|
deserializeText(buffer, static_cast<TextPacket*>(packet));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
//DOCS: memset() is used before sending a packet to remove old data; you don't want to send sensitive data over the network
|
//NOTE: memset() is used before sending a packet to remove old data; you don't want to send sensitive data over the network
|
||||||
//NOTE: don't confuse SerialPacketBase with UDPpacket
|
//NOTE: don't confuse SerialPacketBase with UDPpacket
|
||||||
|
|
||||||
void UDPNetworkUtility::Open(int port) {
|
void UDPNetworkUtility::Open(int port) {
|
||||||
@@ -140,6 +140,7 @@ int UDPNetworkUtility::SendToAllChannels(void* data, int len) {
|
|||||||
return sent;
|
return sent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: put a void* and int* parameter list here
|
||||||
int UDPNetworkUtility::Receive() {
|
int UDPNetworkUtility::Receive() {
|
||||||
memset(packet->data, 0, packet->maxlen);
|
memset(packet->data, 0, packet->maxlen);
|
||||||
int ret = SDLNet_UDP_Recv(socket, packet);
|
int ret = SDLNet_UDP_Recv(socket, packet);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -27,13 +27,13 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
void ConfigUtility::Load(std::string fname, bool skipMissingFile, int argc, char* argv[]) {
|
void ConfigUtility::Load(std::string fname, int argc, char* argv[]) {
|
||||||
//clear the stored configuration
|
//clear the stored configuration
|
||||||
configMap.clear();
|
configMap.clear();
|
||||||
|
|
||||||
//use the default file
|
//use the default file
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
configMap = Read(fname, skipMissingFile);
|
configMap = Read(fname);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,9 +47,7 @@ void ConfigUtility::Load(std::string fname, bool skipMissingFile, int argc, char
|
|||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
//read from a specified config file
|
//read from a specified config file
|
||||||
if (!strncmp(argv[i], "-config=", 8)) {
|
if (!strncmp(argv[i], "-config=", 8)) {
|
||||||
//older specified files take precedence
|
redirectedFile = Read(argv[i] + 8);
|
||||||
table_t tmp = Read(argv[i] + 8, skipMissingFile);
|
|
||||||
redirectedFile.insert(tmp.begin(), tmp.end());
|
|
||||||
redirectUsed = true;
|
redirectUsed = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -75,21 +73,18 @@ void ConfigUtility::Load(std::string fname, bool skipMissingFile, int argc, char
|
|||||||
|
|
||||||
//finally, construct the final config table
|
//finally, construct the final config table
|
||||||
if (!redirectUsed) {
|
if (!redirectUsed) {
|
||||||
redirectedFile = Read(fname, skipMissingFile);
|
redirectedFile = Read(fname);
|
||||||
}
|
}
|
||||||
configMap.insert(cmdLineParams.begin(), cmdLineParams.end());
|
configMap.insert(cmdLineParams.begin(), cmdLineParams.end());
|
||||||
configMap.insert(redirectedFile.begin(), redirectedFile.end());
|
configMap.insert(redirectedFile.begin(), redirectedFile.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigUtility::table_t ConfigUtility::Read(std::string fname, bool skipMissingFile) {
|
ConfigUtility::table_t ConfigUtility::Read(std::string fname) {
|
||||||
//read in and return this file's data
|
//read in and return this file's data
|
||||||
table_t retTable;
|
table_t retTable;
|
||||||
std::ifstream is(fname);
|
std::ifstream is(fname);
|
||||||
|
|
||||||
if (!is.is_open()) {
|
if (!is.is_open()) {
|
||||||
if (skipMissingFile) {
|
|
||||||
return {}; //empty table
|
|
||||||
}
|
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << "Failed to open a config file: " << fname;
|
os << "Failed to open a config file: " << fname;
|
||||||
throw(std::runtime_error( os.str() ));
|
throw(std::runtime_error( os.str() ));
|
||||||
@@ -148,7 +143,7 @@ ConfigUtility::table_t ConfigUtility::Read(std::string fname, bool skipMissingFi
|
|||||||
|
|
||||||
//load in any subordinate config files
|
//load in any subordinate config files
|
||||||
if (retTable.find("config.next") != retTable.end()) {
|
if (retTable.find("config.next") != retTable.end()) {
|
||||||
table_t subTable = Read(retTable["config.next"], skipMissingFile);
|
table_t subTable = Read(retTable["config.next"]);
|
||||||
retTable.insert(subTable.begin(), subTable.end());
|
retTable.insert(subTable.begin(), subTable.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -27,9 +27,9 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class ConfigUtility: public Singleton<ConfigUtility> {
|
class ConfigUtility : public Singleton<ConfigUtility> {
|
||||||
public:
|
public:
|
||||||
void Load(std::string fname, bool skipMissingFile = false, int argc = 0, char* argv[] = nullptr);
|
void Load(std::string fname, int argc = 0, char* argv[] = nullptr);
|
||||||
|
|
||||||
//convert to a type
|
//convert to a type
|
||||||
std::string& String(std::string);
|
std::string& String(std::string);
|
||||||
@@ -47,7 +47,10 @@ private:
|
|||||||
|
|
||||||
friend Singleton<ConfigUtility>;
|
friend Singleton<ConfigUtility>;
|
||||||
|
|
||||||
table_t Read(std::string fname, bool skipMissingFile);
|
ConfigUtility() = default;
|
||||||
|
~ConfigUtility() = default;
|
||||||
|
|
||||||
|
table_t Read(std::string fname);
|
||||||
|
|
||||||
table_t configMap;
|
table_t configMap;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
#ifndef IPOPERATORS_HPP_
|
|
||||||
#define IPOPERATORS_HPP_
|
|
||||||
|
|
||||||
#include "SDL/SDL_net.h"
|
|
||||||
|
|
||||||
//these should've come standard
|
|
||||||
bool operator==(IPaddress lhs, IPaddress rhs);
|
|
||||||
bool operator!=(IPaddress lhs, IPaddress rhs);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -19,21 +19,30 @@
|
|||||||
* 3. This notice may not be removed or altered from any source
|
* 3. This notice may not be removed or altered from any source
|
||||||
* distribution.
|
* distribution.
|
||||||
*/
|
*/
|
||||||
#include "world.hpp"
|
#include "utility.hpp"
|
||||||
|
|
||||||
//-------------------------
|
#include <algorithm>
|
||||||
//chat
|
|
||||||
//-------------------------
|
|
||||||
|
|
||||||
void World::hTextBroadcast(TextPacket* const argPacket) {
|
std::string truncatePath(std::string pathname) {
|
||||||
//TODO: (9) empty
|
return std::string(
|
||||||
|
std::find_if(
|
||||||
|
pathname.rbegin(),
|
||||||
|
pathname.rend(),
|
||||||
|
[](char ch) -> bool {
|
||||||
|
//windows & unix tested
|
||||||
|
return ch == '/' || ch == '\\';
|
||||||
|
}).base(),
|
||||||
|
pathname.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::hTextSpeech(TextPacket* const argPacket) {
|
std::string to_string_custom(int i) {
|
||||||
//TODO: (9) empty
|
char buffer[20];
|
||||||
}
|
snprintf(buffer, 20, "%d", i);
|
||||||
|
return std::string(buffer);
|
||||||
void World::hTextWhisper(TextPacket* const argPacket) {
|
|
||||||
//TODO: (9) empty
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int to_integer_custom(std::string s) {
|
||||||
|
int ret = 0;
|
||||||
|
sscanf(s.c_str(), "%d", &ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -19,12 +19,16 @@
|
|||||||
* 3. This notice may not be removed or altered from any source
|
* 3. This notice may not be removed or altered from any source
|
||||||
* distribution.
|
* distribution.
|
||||||
*/
|
*/
|
||||||
#ifndef CHARACTERMANAGERAPI_HPP_
|
#ifndef UTILITY_HPP_
|
||||||
#define CHARACTERMANAGERAPI_HPP_
|
#define UTILITY_HPP_
|
||||||
|
|
||||||
#include "lua.hpp"
|
#include <string>
|
||||||
|
|
||||||
#define TORTUGA_CHARACTER_MANAGER_API "character_manager"
|
std::string truncatePath(std::string pathname);
|
||||||
LUAMOD_API int openCharacterManagerAPI(lua_State* L);
|
|
||||||
|
|
||||||
#endif
|
//fixing known bugs in g++
|
||||||
|
std::string to_string_custom(int i);
|
||||||
|
|
||||||
|
int to_integer_custom(std::string);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -92,10 +92,6 @@ public:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
//unary operators
|
|
||||||
Vector2 operator-() { return {-x, -y}; }
|
|
||||||
|
|
||||||
//comparison operators
|
|
||||||
bool operator==(Vector2 v) { return (x == v.x && y == v.y); }
|
bool operator==(Vector2 v) { return (x == v.x && y == v.y); }
|
||||||
bool operator!=(Vector2 v) { return (x != v.x || y != v.y); }
|
bool operator!=(Vector2 v) { return (x != v.x || y != v.y); }
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ Future versions (to be determined) may be released under a modified version of t
|
|||||||
|
|
||||||
The current version of Tortuga is released under the zlib license.
|
The current version of Tortuga is released under the zlib license.
|
||||||
|
|
||||||
Copyright (c) 2013-2015 Kayne Ruse
|
Copyright (c) 2013, 2014 Kayne Ruse
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user