Compare commits
59 Commits
release-0.8.2
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 5d95ab97a7 | |||
| d7309091a1 | |||
| 3e859eed32 | |||
| 4f5b87d0f7 | |||
| b844f35e95 | |||
| 9c9f30790e | |||
| 55abdfc7d0 | |||
| e8ad19f267 | |||
| 44b9bb2cd1 | |||
| 377bb36ce2 | |||
| b95f08f62e | |||
| 6a4399934c | |||
| 3a2d28022b | |||
| d3be16ab38 | |||
| 19ccd823ef | |||
| 81aa469595 | |||
| 9ea52db3d5 | |||
| 398ccd5b3f | |||
| c48389d97f | |||
| c553d79439 | |||
| 5c144c2099 | |||
| dae5b667a8 | |||
| 4161dbfaf2 | |||
| 55d0b2b361 | |||
| 61a7a991a8 | |||
| ed5bcc9706 | |||
| b51c4b4f30 | |||
| e1bea5e571 | |||
| ec7908b010 | |||
| afa869f4e6 | |||
| 3ddb63700c | |||
| a9ba4bb759 | |||
| a2f5e367b2 | |||
| 1826baa48d | |||
| baf9492026 | |||
| 131b0b433a | |||
| 00b7f27829 | |||
| dd63efb355 | |||
| 0b631e006c | |||
| 64833f86da | |||
| 518ea93adc | |||
| 07218418a2 | |||
| 6d8d7963a1 | |||
| 69a13c5ed6 | |||
| 011f71ea61 | |||
| 4894daa273 | |||
| 9a1dcc2f53 | |||
| 8d2fc45d7d | |||
| 867a86fd79 | |||
| 7ccea0d1c0 | |||
| 7c6468c1dd | |||
| 5285397101 | |||
| ba295099f3 | |||
| 754fb71850 | |||
| dd25f068af | |||
| bf273db9c2 | |||
| 5d3d82bf3f | |||
| 36ba3fa132 | |||
| 3002afa1e9 |
+7
-1
@@ -1,3 +1,9 @@
|
|||||||
[submodule "bin"]
|
[submodule "bin"]
|
||||||
path = bin
|
path = bin
|
||||||
url = https://github.com/Ratstail91/Tortuga.git
|
url = https://github.com/krgamestudios/bin.git
|
||||||
|
[submodule "TurtleGUI"]
|
||||||
|
path = TurtleGUI
|
||||||
|
url = https://github.com/krgamestudios/TurtleGUI.git
|
||||||
|
[submodule "TurtleMap"]
|
||||||
|
path = TurtleMap
|
||||||
|
url = https://github.com/krgamestudios/TurtleMap.git
|
||||||
|
|||||||
@@ -6,8 +6,14 @@ This game is inspired by classic 2D RPGs (Final Fantasy, The Legend of Zelda), a
|
|||||||
|
|
||||||
## Releases
|
## Releases
|
||||||
|
|
||||||
* The most recent stable build for Windows can be found [here](https://dl.dropboxusercontent.com/u/46669050/Tortuga-win.rar).
|
* The most recent stable build for Windows can be found [here](https://www.dropbox.com/s/zm9hg11ywol7yyz/Tortuga-win.rar?dl=1).
|
||||||
* The most recent stable build for Windows can be found [here](https://dl.dropboxusercontent.com/u/46669050/Tortuga-linux.tar).
|
* The most recent stable build for Linux can be found [here](https://www.dropbox.com/s/5z6ag9r88ovr5bb/Tortuga-linux.tar?dl=1).
|
||||||
|
|
||||||
|
## Patreon
|
||||||
|
|
||||||
|
If you would like to support the development of Tortuga, please consider becoming a patron below.
|
||||||
|
|
||||||
|
* [My Patreon Page](https://patreon.com/user?u=2811779)
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
@@ -52,4 +58,4 @@ Permission is granted to anyone to use this software for any purpose, including
|
|||||||
### Items not made by me
|
### Items not made by me
|
||||||
|
|
||||||
* [Coolvetica Font](http://typodermicfonts.com/coolvetica/)
|
* [Coolvetica Font](http://typodermicfonts.com/coolvetica/)
|
||||||
* Creative Commons Artwork from [Artsader](http://www.moosader.com/artsader/)
|
* Creative Commons Artwork from [Artsader](http://www.moosader.com/artsader/)
|
||||||
|
|||||||
Submodule
+1
Submodule TurtleGUI added at 13e810df0a
Submodule
+1
Submodule TurtleMap added at d6672e59d0
+1
-1
Submodule bin updated: c653980193...08e1382e66
@@ -103,3 +103,7 @@ void BaseScene::KeyDown(SDL_KeyboardEvent const& event) {
|
|||||||
void BaseScene::KeyUp(SDL_KeyboardEvent const& event) {
|
void BaseScene::KeyUp(SDL_KeyboardEvent const& event) {
|
||||||
//EMPTY
|
//EMPTY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BaseScene::TextInput(SDL_TextInputEvent const& event) {
|
||||||
|
//EMPTY
|
||||||
|
}
|
||||||
|
|||||||
@@ -47,8 +47,9 @@ public:
|
|||||||
virtual void MouseWheel(SDL_MouseWheelEvent const& event);
|
virtual void MouseWheel(SDL_MouseWheelEvent const& event);
|
||||||
virtual void KeyDown(SDL_KeyboardEvent const& event);
|
virtual void KeyDown(SDL_KeyboardEvent const& event);
|
||||||
virtual void KeyUp(SDL_KeyboardEvent const& event);
|
virtual void KeyUp(SDL_KeyboardEvent const& event);
|
||||||
|
virtual void TextInput(SDL_TextInputEvent const& event);
|
||||||
|
|
||||||
//TODO: (9) joystick and controller events
|
//TODO: joystick and controller events
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//control
|
//control
|
||||||
|
|||||||
@@ -188,6 +188,12 @@ void ClientApplication::Init(int argc, char* argv[]) {
|
|||||||
DEBUG_INTERNAL_VAR(MAX_PACKET_SIZE);
|
DEBUG_INTERNAL_VAR(MAX_PACKET_SIZE);
|
||||||
DEBUG_INTERNAL_VAR(static_cast<int>(SerialPacketType::LAST));
|
DEBUG_INTERNAL_VAR(static_cast<int>(SerialPacketType::LAST));
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//BUGFIX
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
SDL_StopTextInput();
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//finalize the startup
|
//finalize the startup
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -298,6 +304,10 @@ void ClientApplication::ProcessEvents() {
|
|||||||
activeScene->KeyUp(event.key);
|
activeScene->KeyUp(event.key);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SDL_TEXTINPUT:
|
||||||
|
activeScene->TextInput(event.text);
|
||||||
|
break;
|
||||||
|
|
||||||
//TODO: (9) joystick and controller events
|
//TODO: (9) joystick and controller events
|
||||||
|
|
||||||
//window events are handled internally
|
//window events are handled internally
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include "base_barrier.hpp"
|
#include "base_barrier.hpp"
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. .. ../../common/gameplay ../../common/graphics ../../common/utilities
|
INCLUDES+=. .. ../../common/global_defines ../../common/utilities ../../TurtleGUI
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
|||||||
@@ -19,25 +19,40 @@
|
|||||||
* 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 "application.hpp"
|
#include "heartbeat_utility.hpp"
|
||||||
|
|
||||||
#include "SDL2/SDL.h"
|
#include "channels.hpp"
|
||||||
|
#include "ip_operators.hpp"
|
||||||
|
|
||||||
#include <iostream>
|
//heartbeat system
|
||||||
#include <stdexcept>
|
void HeartbeatUtility::hPing(ServerPacket* const argPacket) {
|
||||||
|
ServerPacket newPacket;
|
||||||
|
newPacket.type = SerialPacketType::PONG;
|
||||||
|
network.SendTo(argPacket->srcAddress, &newPacket);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
void HeartbeatUtility::hPong(ServerPacket* const argPacket) {
|
||||||
std::cout << "Beginning " << argv[0] << std::endl;
|
if (*network.GetIPAddress(Channels::SERVER) != argPacket->srcAddress) {
|
||||||
try {
|
throw(std::runtime_error("Heartbeat message received from an unknown source"));
|
||||||
Application app;
|
|
||||||
app.Init(argc, argv);
|
|
||||||
app.Proc();
|
|
||||||
app.Quit();
|
|
||||||
}
|
}
|
||||||
catch(std::exception& e) {
|
attemptedBeats = 0;
|
||||||
std::cerr << "Fatal Error: " << e.what() << std::endl;
|
lastBeat = Clock::now();
|
||||||
return 1;
|
}
|
||||||
|
|
||||||
|
int HeartbeatUtility::CheckHeartBeat() {
|
||||||
|
//check the connection (heartbeat)
|
||||||
|
if (Clock::now() - lastBeat > std::chrono::seconds(3)) {
|
||||||
|
if (attemptedBeats > 2) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ServerPacket newPacket;
|
||||||
|
newPacket.type = SerialPacketType::PING;
|
||||||
|
network.SendTo(Channels::SERVER, &newPacket);
|
||||||
|
|
||||||
|
attemptedBeats++;
|
||||||
|
lastBeat = Clock::now();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
std::cout << "Clean exit from " << argv[0] << std::endl;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "server_packet.hpp"
|
||||||
|
#include "udp_network_utility.hpp"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
class HeartbeatUtility {
|
||||||
|
public:
|
||||||
|
//heartbeat system
|
||||||
|
void hPing(ServerPacket* const);
|
||||||
|
void hPong(ServerPacket* const);
|
||||||
|
|
||||||
|
int CheckHeartBeat();
|
||||||
|
|
||||||
|
private:
|
||||||
|
UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton();
|
||||||
|
typedef std::chrono::steady_clock Clock;
|
||||||
|
Clock::time_point lastBeat = Clock::now();
|
||||||
|
int attemptedBeats = 0;
|
||||||
|
};
|
||||||
+2
-2
@@ -1,9 +1,9 @@
|
|||||||
#include directories
|
#include directories
|
||||||
INCLUDES+=. entities 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/global_defines ../common/network ../common/network/packet_types ../common/utilities ../TurtleGUI ../TurtleMap
|
||||||
|
|
||||||
#libraries
|
#libraries
|
||||||
#the order of the $(LIBS) is important, at least for MinGW
|
#the order of the $(LIBS) is important, at least for MinGW
|
||||||
LIBS+=client.a ../common/libcommon.a -lSDL2_net
|
LIBS+=client.a ../libcommon.a ../libturtlegui.a ../libturtlemap.a -lSDL2_net
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
LIBS+=-lwsock32 -liphlpapi -lmingw32
|
LIBS+=-lwsock32 -liphlpapi -lmingw32
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -28,6 +28,8 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
constexpr SDL_Color WHITE = {255, 255, 255, 255};
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Public access members
|
//Public access members
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -49,14 +51,16 @@ DisconnectedScreen::DisconnectedScreen() {
|
|||||||
|
|
||||||
//setup the button
|
//setup the button
|
||||||
backButton.SetBackgroundTexture(GetRenderer(), image.GetTexture());
|
backButton.SetBackgroundTexture(GetRenderer(), image.GetTexture());
|
||||||
backButton.SetText(GetRenderer(), font, "Back", COLOR_WHITE);
|
backButton.SetText(GetRenderer(), font, WHITE, "Back");
|
||||||
|
|
||||||
//set the button positions
|
//set the button positions
|
||||||
backButton.SetX(50);
|
backButton.SetX(50);
|
||||||
backButton.SetY(50);
|
backButton.SetY(50);
|
||||||
|
|
||||||
//set the disconnection message text
|
//set the disconnection message text
|
||||||
textLine.SetText(GetRenderer(), font, config["client.disconnectMessage"], {255, 255, 255, 255});
|
textLine.SetX(50);
|
||||||
|
textLine.SetY(30);
|
||||||
|
textLine.SetText(GetRenderer(), font, WHITE, config["client.disconnectMessage"]);
|
||||||
|
|
||||||
//full reset
|
//full reset
|
||||||
UDPNetworkUtility::GetSingleton().Unbind(Channels::SERVER);
|
UDPNetworkUtility::GetSingleton().Unbind(Channels::SERVER);
|
||||||
@@ -92,7 +96,7 @@ void DisconnectedScreen::FrameEnd() {
|
|||||||
|
|
||||||
void DisconnectedScreen::RenderFrame(SDL_Renderer* renderer) {
|
void DisconnectedScreen::RenderFrame(SDL_Renderer* renderer) {
|
||||||
backButton.DrawTo(renderer);
|
backButton.DrawTo(renderer);
|
||||||
textLine.DrawTo(renderer, 50, 30);
|
textLine.DrawTo(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|||||||
+132
-22
@@ -27,6 +27,8 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
constexpr SDL_Color WHITE = {255, 255, 255, 255};
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Public access members
|
//Public access members
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -52,11 +54,11 @@ LobbyMenu::LobbyMenu(int* const argClientIndex, int* const argAccountIndex):
|
|||||||
|
|
||||||
//setup the buttons
|
//setup the buttons
|
||||||
searchButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
|
searchButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
|
||||||
searchButton.SetText(GetRenderer(), font, "Search", COLOR_WHITE);
|
searchButton.SetText(GetRenderer(), font, WHITE, "Search");
|
||||||
joinButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
|
joinButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
|
||||||
joinButton.SetText(GetRenderer(), font, "Join", COLOR_WHITE);
|
joinButton.SetText(GetRenderer(), font, WHITE, "Join");
|
||||||
backButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
|
backButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
|
||||||
backButton.SetText(GetRenderer(), font, "Back", COLOR_WHITE);
|
backButton.SetText(GetRenderer(), font, WHITE, "Back");
|
||||||
|
|
||||||
//set the button positions (assumed)
|
//set the button positions (assumed)
|
||||||
searchButton.SetX(50);
|
searchButton.SetX(50);
|
||||||
@@ -66,7 +68,28 @@ LobbyMenu::LobbyMenu(int* const argClientIndex, int* const argAccountIndex):
|
|||||||
backButton.SetX(50);
|
backButton.SetX(50);
|
||||||
backButton.SetY(90);
|
backButton.SetY(90);
|
||||||
|
|
||||||
|
//setup the text fields
|
||||||
|
username.SetText(GetRenderer(), font, WHITE, config["client.username"]);
|
||||||
|
password.SetText(GetRenderer(), font, WHITE, config["client.password"]);
|
||||||
|
handle.SetText(GetRenderer(), font, WHITE, config["client.handle"]);
|
||||||
|
avatar.SetText(GetRenderer(), font, WHITE, config["client.avatar"]);
|
||||||
|
|
||||||
|
username.SetBounds(BoundingBox{0, 0, 300, 20});
|
||||||
|
password.SetBounds(BoundingBox{0, 0, 300, 20});
|
||||||
|
handle.SetBounds(BoundingBox{0, 0, 300, 20});
|
||||||
|
avatar.SetBounds(BoundingBox{0, 0, 300, 20});
|
||||||
|
|
||||||
|
username.SetX(50);
|
||||||
|
username.SetY(110);
|
||||||
|
password.SetX(50);
|
||||||
|
password.SetY(130);
|
||||||
|
handle.SetX(50);
|
||||||
|
handle.SetY(150);
|
||||||
|
avatar.SetX(50);
|
||||||
|
avatar.SetY(170);
|
||||||
|
|
||||||
//pseudo-list selection
|
//pseudo-list selection
|
||||||
|
//TODO: move this into the UI library?
|
||||||
boundingBox = {300, 50, 200, 12};
|
boundingBox = {300, 50, 200, 12};
|
||||||
|
|
||||||
//hacked together a highlight box
|
//hacked together a highlight box
|
||||||
@@ -112,6 +135,11 @@ void LobbyMenu::RenderFrame(SDL_Renderer* renderer) {
|
|||||||
joinButton.DrawTo(renderer);
|
joinButton.DrawTo(renderer);
|
||||||
backButton.DrawTo(renderer);
|
backButton.DrawTo(renderer);
|
||||||
|
|
||||||
|
username.DrawTo(renderer);
|
||||||
|
password.DrawTo(renderer);
|
||||||
|
handle.DrawTo(renderer);
|
||||||
|
avatar.DrawTo(renderer);
|
||||||
|
|
||||||
//TODO: (3) draw headers for the server list
|
//TODO: (3) draw headers for the server list
|
||||||
//TODO: (3) ping/delay displayed in the server list
|
//TODO: (3) ping/delay displayed in the server list
|
||||||
for (int i = 0; i < serverVector.size(); i++) {
|
for (int i = 0; i < serverVector.size(); i++) {
|
||||||
@@ -121,8 +149,13 @@ void LobbyMenu::RenderFrame(SDL_Renderer* renderer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//draw the server's info
|
//draw the server's info
|
||||||
serverVector[i].nameImage.DrawTo(renderer, boundingBox.x, boundingBox.y + boundingBox.h * i);
|
serverVector[i].nameImage.SetX(boundingBox.x);
|
||||||
serverVector[i].playerCountImage.DrawTo(renderer, boundingBox.x+276, boundingBox.y + boundingBox.h * i);
|
serverVector[i].nameImage.SetY(boundingBox.y + boundingBox.h * i);
|
||||||
|
serverVector[i].nameImage.DrawTo(renderer);
|
||||||
|
|
||||||
|
serverVector[i].playerCountImage.SetX(boundingBox.x+276);
|
||||||
|
serverVector[i].playerCountImage.SetY(boundingBox.y + boundingBox.h * i);
|
||||||
|
serverVector[i].playerCountImage.DrawTo(renderer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,6 +173,35 @@ void LobbyMenu::MouseButtonDown(SDL_MouseButtonEvent const& event) {
|
|||||||
searchButton.MouseButtonDown(event);
|
searchButton.MouseButtonDown(event);
|
||||||
joinButton.MouseButtonDown(event);
|
joinButton.MouseButtonDown(event);
|
||||||
backButton.MouseButtonDown(event);
|
backButton.MouseButtonDown(event);
|
||||||
|
|
||||||
|
if (username.MouseButtonDown(event)) {
|
||||||
|
//GUI trick
|
||||||
|
if (!username.GetText().compare(config["client.username"])) {
|
||||||
|
username.SetText(GetRenderer(), font, WHITE, "");
|
||||||
|
}
|
||||||
|
SDL_StartTextInput();
|
||||||
|
}
|
||||||
|
if (password.MouseButtonDown(event)) {
|
||||||
|
//GUI trick
|
||||||
|
if (!password.GetText().compare(config["client.password"])) {
|
||||||
|
password.SetText(GetRenderer(), font, WHITE, "");
|
||||||
|
}
|
||||||
|
SDL_StartTextInput();
|
||||||
|
}
|
||||||
|
if (handle.MouseButtonDown(event)) {
|
||||||
|
//GUI trick
|
||||||
|
if (!handle.GetText().compare(config["client.handle"])) {
|
||||||
|
handle.SetText(GetRenderer(), font, WHITE, "");
|
||||||
|
}
|
||||||
|
SDL_StartTextInput();
|
||||||
|
}
|
||||||
|
if (avatar.MouseButtonDown(event)) {
|
||||||
|
//GUI trick
|
||||||
|
if (!avatar.GetText().compare(config["client.avatar"])) {
|
||||||
|
avatar.SetText(GetRenderer(), font, WHITE, "");
|
||||||
|
}
|
||||||
|
SDL_StartTextInput();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& event) {
|
void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& event) {
|
||||||
@@ -174,6 +236,22 @@ void LobbyMenu::KeyDown(SDL_KeyboardEvent const& event) {
|
|||||||
case SDLK_ESCAPE:
|
case SDLK_ESCAPE:
|
||||||
SetSceneSignal(SceneSignal::MAINMENU);
|
SetSceneSignal(SceneSignal::MAINMENU);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SDLK_BACKSPACE:
|
||||||
|
//easier than mucking about with SDL_TextEditEvent
|
||||||
|
if (username.GetFocus()) {
|
||||||
|
username.PopChars(GetRenderer(), font, WHITE, 1);
|
||||||
|
}
|
||||||
|
if (password.GetFocus()) {
|
||||||
|
password.PopChars(GetRenderer(), font, WHITE, 1);
|
||||||
|
}
|
||||||
|
if (handle.GetFocus()) {
|
||||||
|
handle.PopChars(GetRenderer(), font, WHITE, 1);
|
||||||
|
}
|
||||||
|
if (avatar.GetFocus()) {
|
||||||
|
avatar.PopChars(GetRenderer(), font, WHITE, 1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,6 +259,21 @@ void LobbyMenu::KeyUp(SDL_KeyboardEvent const& event) {
|
|||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LobbyMenu::TextInput(SDL_TextInputEvent const& event) {
|
||||||
|
if (username.GetFocus()) {
|
||||||
|
username.PushText(GetRenderer(), font, WHITE, std::string(event.text));
|
||||||
|
}
|
||||||
|
if (password.GetFocus()) {
|
||||||
|
password.PushText(GetRenderer(), font, WHITE, std::string(event.text));
|
||||||
|
}
|
||||||
|
if (handle.GetFocus()) {
|
||||||
|
handle.PushText(GetRenderer(), font, WHITE, std::string(event.text));
|
||||||
|
}
|
||||||
|
if (avatar.GetFocus()) {
|
||||||
|
avatar.PushText(GetRenderer(), font, WHITE, std::string(event.text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Network handlers
|
//Network handlers
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -248,8 +341,8 @@ void LobbyMenu::HandleBroadcastResponse(ServerPacket* const argPacket) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
//text graphics
|
//text graphics
|
||||||
serverVector.back().nameImage.SetText(GetRenderer(), font, newServer.name, color);
|
serverVector.back().nameImage.SetText(GetRenderer(), font, color, newServer.name);
|
||||||
serverVector.back().playerCountImage.SetText(GetRenderer(), font, itoa_base10(newServer.playerCount), color);
|
serverVector.back().playerCountImage.SetText(GetRenderer(), font, color, itoa_base10(newServer.playerCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
void LobbyMenu::HandleJoinResponse(ClientPacket* const argPacket) {
|
void LobbyMenu::HandleJoinResponse(ClientPacket* const argPacket) {
|
||||||
@@ -270,11 +363,19 @@ void LobbyMenu::HandleLoginResponse(ClientPacket* const argPacket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LobbyMenu::HandleJoinRejection(TextPacket* const argPacket) {
|
void LobbyMenu::HandleJoinRejection(TextPacket* const argPacket) {
|
||||||
//TODO: (9) LobbyMenu::HandleJoinRejection()
|
//NOTE: NEVER HAPPENS
|
||||||
|
throw(std::runtime_error("HandleJoinRejection"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void LobbyMenu::HandleLoginRejection(TextPacket* const argPacket) {
|
void LobbyMenu::HandleLoginRejection(TextPacket* const argPacket) {
|
||||||
//TODO: (9) LobbyMenu::HandleLoginRejection
|
config["client.disconnectMessage"] = std::string() + "Join request rejected: " + argPacket->text;
|
||||||
|
SetSceneSignal(SceneSignal::DISCONNECTEDSCREEN);
|
||||||
|
|
||||||
|
//avoid crashes from the heartbeat system
|
||||||
|
ClientPacket newPacket;
|
||||||
|
newPacket.type = SerialPacketType::DISCONNECT_REQUEST;
|
||||||
|
newPacket.clientIndex = clientIndex;
|
||||||
|
network.SendTo(argPacket->srcAddress, &newPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -282,24 +383,27 @@ void LobbyMenu::HandleLoginRejection(TextPacket* const argPacket) {
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
void LobbyMenu::SendBroadcastRequest() {
|
void LobbyMenu::SendBroadcastRequest() {
|
||||||
//broadcast to the network, or a specific server
|
//broadcast to the home server, and to the LAN
|
||||||
ClientPacket packet;
|
ClientPacket packet;
|
||||||
packet.type = SerialPacketType::BROADCAST_REQUEST;
|
|
||||||
network.SendTo(config["server.host"].c_str(), config.Int("server.port"), &packet);
|
|
||||||
|
|
||||||
//reset the server list
|
packet.type = SerialPacketType::BROADCAST_REQUEST;
|
||||||
serverVector.clear();
|
network.SendTo(config["server.home"].c_str(), config.Int("server.port"), &packet);
|
||||||
selection = nullptr;
|
network.SendTo(config["server.host"].c_str(), config.Int("server.port"), &packet);
|
||||||
|
|
||||||
|
//reset the server list
|
||||||
|
serverVector.clear();
|
||||||
|
selection = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LobbyMenu::SendJoinRequest() {
|
void LobbyMenu::SendJoinRequest() {
|
||||||
|
//BUG: 101 received in LobbyMenu on failed join
|
||||||
//pack the packet
|
//pack the packet
|
||||||
ClientPacket packet;
|
ClientPacket packet;
|
||||||
packet.type = SerialPacketType::JOIN_REQUEST;
|
packet.type = SerialPacketType::JOIN_REQUEST;
|
||||||
|
|
||||||
//join the selected server
|
//join the selected server
|
||||||
network.SendTo(selection->address, &packet);
|
network.SendTo(selection->address, &packet);
|
||||||
selection = nullptr;
|
selection = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LobbyMenu::SendLoginRequest() {
|
void LobbyMenu::SendLoginRequest() {
|
||||||
@@ -308,7 +412,13 @@ void LobbyMenu::SendLoginRequest() {
|
|||||||
ClientPacket packet;
|
ClientPacket packet;
|
||||||
packet.type = SerialPacketType::LOGIN_REQUEST;
|
packet.type = SerialPacketType::LOGIN_REQUEST;
|
||||||
packet.clientIndex = clientIndex;
|
packet.clientIndex = clientIndex;
|
||||||
strncpy(packet.username, config["client.username"].c_str(), PACKET_STRING_SIZE+1);
|
strncpy(packet.username, username.GetText().c_str(), PACKET_STRING_SIZE+1);
|
||||||
|
|
||||||
network.SendTo(Channels::SERVER, &packet);
|
network.SendTo(Channels::SERVER, &packet);
|
||||||
|
|
||||||
|
//TODO: remove
|
||||||
|
config["client.username"] = username.GetText();
|
||||||
|
config["client.password"] = password.GetText();
|
||||||
|
config["client.handle"] = handle.GetText();
|
||||||
|
config["client.avatar"] = avatar.GetText();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "image.hpp"
|
#include "image.hpp"
|
||||||
#include "button.hpp"
|
#include "button.hpp"
|
||||||
#include "bounding_box.hpp"
|
#include "bounding_box.hpp"
|
||||||
|
#include "text_field.hpp"
|
||||||
#include "text_line.hpp"
|
#include "text_line.hpp"
|
||||||
|
|
||||||
#include "SDL2/SDL_ttf.h"
|
#include "SDL2/SDL_ttf.h"
|
||||||
@@ -61,6 +62,7 @@ protected:
|
|||||||
void MouseWheel(SDL_MouseWheelEvent const& event) override;
|
void MouseWheel(SDL_MouseWheelEvent const& event) override;
|
||||||
void KeyDown(SDL_KeyboardEvent const& event) override;
|
void KeyDown(SDL_KeyboardEvent const& event) override;
|
||||||
void KeyUp(SDL_KeyboardEvent const& event) override;
|
void KeyUp(SDL_KeyboardEvent const& event) override;
|
||||||
|
void TextInput(SDL_TextInputEvent const& event) override;
|
||||||
|
|
||||||
//Network handlers
|
//Network handlers
|
||||||
void HandlePacket(SerialPacket* const);
|
void HandlePacket(SerialPacket* const);
|
||||||
@@ -102,6 +104,10 @@ protected:
|
|||||||
Button searchButton;
|
Button searchButton;
|
||||||
Button joinButton;
|
Button joinButton;
|
||||||
Button backButton;
|
Button backButton;
|
||||||
|
TextField username;
|
||||||
|
TextField password;
|
||||||
|
TextField handle;
|
||||||
|
TextField avatar;
|
||||||
|
|
||||||
std::vector<ServerInfo> serverVector;
|
std::vector<ServerInfo> serverVector;
|
||||||
ServerInfo* selection = nullptr;
|
ServerInfo* selection = nullptr;
|
||||||
|
|||||||
+15
-11
@@ -26,6 +26,8 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
constexpr SDL_Color WHITE = {255, 255, 255, 255};
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Public access members
|
//Public access members
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -46,11 +48,11 @@ MainMenu::MainMenu() {
|
|||||||
|
|
||||||
//setup the buttons
|
//setup the buttons
|
||||||
startButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
|
startButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
|
||||||
startButton.SetText(GetRenderer(), font, "Start", COLOR_WHITE);
|
startButton.SetText(GetRenderer(), font, WHITE, "Start");
|
||||||
optionsButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
|
optionsButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
|
||||||
optionsButton.SetText(GetRenderer(), font, "Options", COLOR_WHITE);
|
optionsButton.SetText(GetRenderer(), font, WHITE, "Options");
|
||||||
quitButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
|
quitButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
|
||||||
quitButton.SetText(GetRenderer(), font, "Quit", COLOR_WHITE);
|
quitButton.SetText(GetRenderer(), font, WHITE, "Quit");
|
||||||
|
|
||||||
//set the button positions
|
//set the button positions
|
||||||
startButton.SetX(50);
|
startButton.SetX(50);
|
||||||
@@ -61,9 +63,15 @@ MainMenu::MainMenu() {
|
|||||||
quitButton.SetY(50 + 20 * 2);
|
quitButton.SetY(50 + 20 * 2);
|
||||||
|
|
||||||
//text box
|
//text box
|
||||||
textBox.PushLine(GetRenderer(), font, "Thanks for playing!", {255, 255, 255, 255});
|
int h = -1;
|
||||||
textBox.PushLine(GetRenderer(), font, "You can get the latest version at: ", {255, 255, 255, 255});
|
SDL_RenderGetLogicalSize(GetRenderer(), nullptr, &h);
|
||||||
textBox.PushLine(GetRenderer(), font, "krgamestudios.com", {255, 255, 255, 255}); //TODO: (9) click to open the website/update
|
|
||||||
|
textBox.SetX(50);
|
||||||
|
textBox.SetY(h-100);
|
||||||
|
|
||||||
|
textBox.PushLine(GetRenderer(), font, WHITE, "Thanks for playing!");
|
||||||
|
textBox.PushLine(GetRenderer(), font, WHITE, "You can get the latest version at: ");
|
||||||
|
textBox.PushLine(GetRenderer(), font, WHITE, "krgamestudios.com"); //TODO: (9) click to open the website/update
|
||||||
|
|
||||||
//debug
|
//debug
|
||||||
//
|
//
|
||||||
@@ -93,11 +101,7 @@ void MainMenu::RenderFrame(SDL_Renderer* renderer) {
|
|||||||
startButton.DrawTo(renderer);
|
startButton.DrawTo(renderer);
|
||||||
optionsButton.DrawTo(renderer);
|
optionsButton.DrawTo(renderer);
|
||||||
quitButton.DrawTo(renderer);
|
quitButton.DrawTo(renderer);
|
||||||
|
textBox.DrawTo(renderer);
|
||||||
int h = -1;
|
|
||||||
SDL_RenderGetLogicalSize(GetRenderer(), nullptr, &h);
|
|
||||||
|
|
||||||
textBox.DrawTo(renderer, 50, h-50, -12);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. .. ../client_utilities ../entities ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/network/packet_types ../../common/ui ../../common/utilities
|
INCLUDES+=. .. ../entities ../../common/debugging ../../common/global_defines ../../common/network ../../common/network/packet_types ../../common/utilities ../../TurtleGUI ../../TurtleMap
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,8 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
constexpr SDL_Color WHITE = {255, 255, 255, 255};
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Public access members
|
//Public access members
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -46,14 +48,16 @@ OptionsMenu::OptionsMenu() {
|
|||||||
|
|
||||||
//setup the button
|
//setup the button
|
||||||
backButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
|
backButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
|
||||||
backButton.SetText(GetRenderer(), font, "Back", COLOR_WHITE);
|
backButton.SetText(GetRenderer(), font, WHITE, "Back");
|
||||||
|
|
||||||
//set the button positions
|
//set the button positions
|
||||||
backButton.SetX(50);
|
backButton.SetX(50);
|
||||||
backButton.SetY(50);
|
backButton.SetY(50);
|
||||||
|
|
||||||
//text line
|
//text line
|
||||||
textLine.SetText(GetRenderer(), font, "This code is fucking hard to refactor.", {255, 255, 255, 255});
|
textLine.SetX(50);
|
||||||
|
textLine.SetY(30);
|
||||||
|
textLine.SetText(GetRenderer(), font, WHITE, "Am I making any progress?");
|
||||||
}
|
}
|
||||||
|
|
||||||
OptionsMenu::~OptionsMenu() {
|
OptionsMenu::~OptionsMenu() {
|
||||||
@@ -78,7 +82,7 @@ void OptionsMenu::FrameEnd() {
|
|||||||
|
|
||||||
void OptionsMenu::RenderFrame(SDL_Renderer* renderer) {
|
void OptionsMenu::RenderFrame(SDL_Renderer* renderer) {
|
||||||
backButton.DrawTo(renderer);
|
backButton.DrawTo(renderer);
|
||||||
textLine.DrawTo(renderer, 50, 30);
|
textLine.DrawTo(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|||||||
+31
-47
@@ -34,6 +34,8 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
constexpr SDL_Color WHITE = {255, 255, 255, 255};
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//static functions
|
//static functions
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -72,9 +74,9 @@ World::World(int* const argClientIndex, int* const argAccountIndex):
|
|||||||
|
|
||||||
//setup the buttons
|
//setup the buttons
|
||||||
disconnectButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
|
disconnectButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
|
||||||
disconnectButton.SetText(GetRenderer(), font, "Disconnect", COLOR_WHITE);
|
disconnectButton.SetText(GetRenderer(), font, WHITE, "Disconnect");
|
||||||
shutdownButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
|
shutdownButton.SetBackgroundTexture(GetRenderer(), buttonImage.GetTexture());
|
||||||
shutdownButton.SetText(GetRenderer(), font, "Shutdown", COLOR_WHITE);
|
shutdownButton.SetText(GetRenderer(), font, WHITE, "Shutdown");
|
||||||
|
|
||||||
//set the button positions
|
//set the button positions
|
||||||
disconnectButton.SetX(50);
|
disconnectButton.SetX(50);
|
||||||
@@ -152,14 +154,19 @@ void World::Update() {
|
|||||||
throw(e);
|
throw(e);
|
||||||
}
|
}
|
||||||
catch(std::exception& e) {
|
catch(std::exception& e) {
|
||||||
std::cerr << "HandlePacket Error: " << e.what() << std::endl;
|
std::cerr << "HandlePacket Error (" << (int)(reinterpret_cast<SerialPacket*>(packetBuffer)->type) << "): " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
//free the buffer
|
//free the buffer
|
||||||
delete reinterpret_cast<char*>(packetBuffer);
|
delete reinterpret_cast<char*>(packetBuffer);
|
||||||
|
|
||||||
//heartbeat system
|
//heartbeat system
|
||||||
CheckHeartBeat();
|
if (heartbeatUtility.CheckHeartBeat()) {
|
||||||
|
//escape to the disconnect screen
|
||||||
|
SendDisconnectRequest();
|
||||||
|
SetSceneSignal(SceneSignal::DISCONNECTEDSCREEN);
|
||||||
|
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "Error: Lost connection to the server";
|
||||||
|
}
|
||||||
|
|
||||||
//update all entities
|
//update all entities
|
||||||
for (auto& it : characterMap) {
|
for (auto& it : characterMap) {
|
||||||
@@ -261,12 +268,12 @@ void World::RenderFrame(SDL_Renderer* renderer) {
|
|||||||
shutdownButton.DrawTo(renderer);
|
shutdownButton.DrawTo(renderer);
|
||||||
|
|
||||||
//FPS
|
//FPS
|
||||||
fpsTextLine.DrawTo(renderer, 0, 0);
|
fpsTextLine.DrawTo(renderer);
|
||||||
int fpsRet = fps.Calculate();
|
int fpsRet = fps.Calculate();
|
||||||
if (fpsRet != -1) {
|
if (fpsRet != -1) {
|
||||||
std::ostringstream msg;
|
std::ostringstream msg;
|
||||||
msg << "FPS: " << fpsRet;
|
msg << "FPS: " << fpsRet;
|
||||||
fpsTextLine.SetText(renderer, font, msg.str(), {255, 255, 255, 255});
|
fpsTextLine.SetText(renderer, font, WHITE, msg.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -409,10 +416,10 @@ void World::HandlePacket(SerialPacket* const argPacket) {
|
|||||||
switch(argPacket->type) {
|
switch(argPacket->type) {
|
||||||
//heartbeat system
|
//heartbeat system
|
||||||
case SerialPacketType::PING:
|
case SerialPacketType::PING:
|
||||||
hPing(static_cast<ServerPacket*>(argPacket));
|
heartbeatUtility.hPing(static_cast<ServerPacket*>(argPacket));
|
||||||
break;
|
break;
|
||||||
case SerialPacketType::PONG:
|
case SerialPacketType::PONG:
|
||||||
hPong(static_cast<ServerPacket*>(argPacket));
|
heartbeatUtility.hPong(static_cast<ServerPacket*>(argPacket));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//game server connections
|
//game server connections
|
||||||
@@ -451,6 +458,10 @@ void World::HandlePacket(SerialPacket* const argPacket) {
|
|||||||
hCharacterMovement(static_cast<CharacterPacket*>(argPacket));
|
hCharacterMovement(static_cast<CharacterPacket*>(argPacket));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SerialPacketType::CHARACTER_REJECTION:
|
||||||
|
hCharacterRejection(static_cast<TextPacket*>(argPacket));
|
||||||
|
break;
|
||||||
|
|
||||||
//creature management
|
//creature management
|
||||||
case SerialPacketType::CREATURE_UPDATE:
|
case SerialPacketType::CREATURE_UPDATE:
|
||||||
hCreatureUpdate(static_cast<CreaturePacket*>(argPacket));
|
hCreatureUpdate(static_cast<CreaturePacket*>(argPacket));
|
||||||
@@ -500,7 +511,6 @@ void World::HandlePacket(SerialPacket* const argPacket) {
|
|||||||
|
|
||||||
//general rejection messages
|
//general rejection messages
|
||||||
case SerialPacketType::REGION_REJECTION:
|
case SerialPacketType::REGION_REJECTION:
|
||||||
case SerialPacketType::CHARACTER_REJECTION:
|
|
||||||
case SerialPacketType::QUERY_REJECTION:
|
case SerialPacketType::QUERY_REJECTION:
|
||||||
throw(fatal_error(static_cast<TextPacket*>(argPacket)->text));
|
throw(fatal_error(static_cast<TextPacket*>(argPacket)->text));
|
||||||
break;
|
break;
|
||||||
@@ -518,44 +528,6 @@ void World::HandlePacket(SerialPacket* const argPacket) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
//heartbeat system
|
|
||||||
//-------------------------
|
|
||||||
|
|
||||||
void World::hPing(ServerPacket* const argPacket) {
|
|
||||||
ServerPacket newPacket;
|
|
||||||
newPacket.type = SerialPacketType::PONG;
|
|
||||||
network.SendTo(argPacket->srcAddress, &newPacket);
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::hPong(ServerPacket* const argPacket) {
|
|
||||||
if (*network.GetIPAddress(Channels::SERVER) != argPacket->srcAddress) {
|
|
||||||
throw(std::runtime_error("Heartbeat message received from an unknown source"));
|
|
||||||
}
|
|
||||||
attemptedBeats = 0;
|
|
||||||
lastBeat = Clock::now();
|
|
||||||
}
|
|
||||||
|
|
||||||
void World::CheckHeartBeat() {
|
|
||||||
//check the connection (heartbeat)
|
|
||||||
if (Clock::now() - lastBeat > std::chrono::seconds(3)) {
|
|
||||||
if (attemptedBeats > 2) {
|
|
||||||
//escape to the disconnect screen
|
|
||||||
SendDisconnectRequest();
|
|
||||||
SetSceneSignal(SceneSignal::DISCONNECTEDSCREEN);
|
|
||||||
ConfigUtility::GetSingleton()["client.disconnectMessage"] = "Error: Lost connection to the server";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ServerPacket newPacket;
|
|
||||||
newPacket.type = SerialPacketType::PING;
|
|
||||||
network.SendTo(Channels::SERVER, &newPacket);
|
|
||||||
|
|
||||||
attemptedBeats++;
|
|
||||||
lastBeat = Clock::now();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Connection control
|
//Connection control
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -841,6 +813,18 @@ void World::hCharacterMovement(CharacterPacket* const argPacket) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void World::hCharacterRejection(TextPacket* const argPacket) {
|
||||||
|
//NOTE: simply crap out
|
||||||
|
config["client.disconnectMessage"] = std::string() + "Character rejected: " + argPacket->text;
|
||||||
|
SetSceneSignal(SceneSignal::DISCONNECTEDSCREEN);
|
||||||
|
|
||||||
|
//avoid crashes from the heartbeat system
|
||||||
|
ClientPacket newPacket;
|
||||||
|
newPacket.type = SerialPacketType::DISCONNECT_REQUEST;
|
||||||
|
newPacket.clientIndex = clientIndex;
|
||||||
|
network.SendTo(argPacket->srcAddress, &newPacket);
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//creature management
|
//creature management
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|||||||
@@ -43,6 +43,7 @@
|
|||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
#include "base_barrier.hpp"
|
#include "base_barrier.hpp"
|
||||||
#include "base_creature.hpp"
|
#include "base_creature.hpp"
|
||||||
|
#include "heartbeat_utility.hpp"
|
||||||
#include "local_character.hpp"
|
#include "local_character.hpp"
|
||||||
|
|
||||||
#include "SDL2/SDL.h"
|
#include "SDL2/SDL.h"
|
||||||
@@ -80,12 +81,6 @@ private:
|
|||||||
//handle incoming traffic
|
//handle incoming traffic
|
||||||
void HandlePacket(SerialPacket* const);
|
void HandlePacket(SerialPacket* const);
|
||||||
|
|
||||||
//heartbeat system
|
|
||||||
void hPing(ServerPacket* const);
|
|
||||||
void hPong(ServerPacket* const);
|
|
||||||
|
|
||||||
void CheckHeartBeat();
|
|
||||||
|
|
||||||
//basic connections
|
//basic connections
|
||||||
void SendLogoutRequest();
|
void SendLogoutRequest();
|
||||||
void SendDisconnectRequest();
|
void SendDisconnectRequest();
|
||||||
@@ -107,6 +102,7 @@ private:
|
|||||||
void hCharacterUnload(CharacterPacket* const);
|
void hCharacterUnload(CharacterPacket* const);
|
||||||
void hQueryCharacterExists(CharacterPacket* const);
|
void hQueryCharacterExists(CharacterPacket* const);
|
||||||
void hCharacterMovement(CharacterPacket* const);
|
void hCharacterMovement(CharacterPacket* const);
|
||||||
|
void hCharacterRejection(TextPacket* const);
|
||||||
|
|
||||||
//creature management
|
//creature management
|
||||||
void hCreatureUpdate(CreaturePacket* const);
|
void hCreatureUpdate(CreaturePacket* const);
|
||||||
@@ -165,11 +161,9 @@ private:
|
|||||||
LocalCharacter* localCharacter = nullptr;
|
LocalCharacter* localCharacter = nullptr;
|
||||||
|
|
||||||
//heartbeat
|
//heartbeat
|
||||||
//TODO: (2) Heartbeat needs it's own utility
|
HeartbeatUtility heartbeatUtility;
|
||||||
typedef std::chrono::steady_clock Clock;
|
typedef std::chrono::steady_clock Clock;
|
||||||
Clock::time_point lastBeat = Clock::now();
|
|
||||||
Clock::time_point queryTime = Clock::now() - std::chrono::seconds(4); //back 4 seconds to trigger automatically
|
Clock::time_point queryTime = Clock::now() - std::chrono::seconds(4); //back 4 seconds to trigger automatically
|
||||||
int attemptedBeats = 0;
|
|
||||||
|
|
||||||
//ugly references; I hate this
|
//ugly references; I hate this
|
||||||
ConfigUtility& config = ConfigUtility::GetSingleton();
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
|
|||||||
@@ -1,188 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#include "application.hpp"
|
|
||||||
|
|
||||||
#include <chrono>
|
|
||||||
#include <sstream>
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
void Application::Init(int argc, char* argv[]) {
|
|
||||||
//create and check the window
|
|
||||||
window = SDL_CreateWindow(
|
|
||||||
"Example Caption",
|
|
||||||
SDL_WINDOWPOS_UNDEFINED,
|
|
||||||
SDL_WINDOWPOS_UNDEFINED,
|
|
||||||
screenWidth,
|
|
||||||
screenHeight,
|
|
||||||
SDL_WINDOW_RESIZABLE);
|
|
||||||
|
|
||||||
if (!window) {
|
|
||||||
std::ostringstream msg;
|
|
||||||
msg << "Failed to create the window: " << SDL_GetError();
|
|
||||||
throw(std::runtime_error(msg.str()));
|
|
||||||
}
|
|
||||||
|
|
||||||
//create and check the renderer
|
|
||||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
|
||||||
|
|
||||||
if (!renderer) {
|
|
||||||
std::ostringstream msg;
|
|
||||||
msg << "Failed to create the renderer: " << SDL_GetError();
|
|
||||||
throw(std::runtime_error(msg.str()));
|
|
||||||
}
|
|
||||||
|
|
||||||
//screen scaling
|
|
||||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "best");
|
|
||||||
SDL_RenderSetLogicalSize(renderer, screenWidth, screenHeight);
|
|
||||||
|
|
||||||
//set the hook for the renderer
|
|
||||||
BaseScene::SetRenderer(renderer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::Proc() {
|
|
||||||
//load the first scene
|
|
||||||
ProcessSceneSignal(SceneSignal::FIRST);
|
|
||||||
|
|
||||||
//fixed frame rate
|
|
||||||
typedef std::chrono::steady_clock Clock;
|
|
||||||
|
|
||||||
Clock::time_point simTime = Clock::now();
|
|
||||||
Clock::time_point realTime;
|
|
||||||
constexpr std::chrono::duration<int, std::milli> frameDelay(16); //~60FPS
|
|
||||||
|
|
||||||
//the game loop continues until the scenes signal QUIT
|
|
||||||
while(activeScene->GetSceneSignal() != SceneSignal::QUIT) {
|
|
||||||
//switch scenes if necessary
|
|
||||||
if(activeScene->GetSceneSignal() != SceneSignal::CONTINUE) {
|
|
||||||
ProcessSceneSignal(activeScene->GetSceneSignal());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//update the current time
|
|
||||||
realTime = Clock::now();
|
|
||||||
|
|
||||||
//simulate the game or give the machine a break
|
|
||||||
if (simTime < realTime) {
|
|
||||||
while(simTime < realTime) {
|
|
||||||
//call the user defined functions
|
|
||||||
activeScene->FrameStart();
|
|
||||||
ProcessEvents();
|
|
||||||
activeScene->Update();
|
|
||||||
activeScene->FrameEnd();
|
|
||||||
|
|
||||||
//step to the next frame
|
|
||||||
simTime += frameDelay;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
SDL_Delay(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_RenderClear(renderer);
|
|
||||||
activeScene->RenderFrame(renderer);
|
|
||||||
SDL_RenderPresent(renderer);
|
|
||||||
}
|
|
||||||
|
|
||||||
//cleanup
|
|
||||||
ClearScene();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::Quit() {
|
|
||||||
//clean up after the program
|
|
||||||
BaseScene::SetRenderer(nullptr);
|
|
||||||
SDL_DestroyRenderer(renderer);
|
|
||||||
SDL_DestroyWindow(window);
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
//Scene management
|
|
||||||
//-------------------------
|
|
||||||
|
|
||||||
void Application::ProcessEvents() {
|
|
||||||
SDL_Event event;
|
|
||||||
while(SDL_PollEvent(&event)) {
|
|
||||||
switch(event.type) {
|
|
||||||
case SDL_QUIT:
|
|
||||||
activeScene->QuitEvent();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_MOUSEMOTION:
|
|
||||||
activeScene->MouseMotion(event.motion);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
|
||||||
activeScene->MouseButtonDown(event.button);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_MOUSEBUTTONUP:
|
|
||||||
activeScene->MouseButtonUp(event.button);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_MOUSEWHEEL:
|
|
||||||
activeScene->MouseWheel(event.wheel);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_KEYDOWN:
|
|
||||||
activeScene->KeyDown(event.key);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_KEYUP:
|
|
||||||
activeScene->KeyUp(event.key);
|
|
||||||
break;
|
|
||||||
|
|
||||||
//TODO: joystick and controller events
|
|
||||||
|
|
||||||
//window events are handled internally
|
|
||||||
case SDL_WINDOWEVENT:
|
|
||||||
switch(event.window.event) {
|
|
||||||
case SDL_WINDOWEVENT_RESIZED:
|
|
||||||
SDL_RenderSetLogicalSize(renderer, event.window.data1, event.window.data2);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Add the custom scene headers here
|
|
||||||
#include "example_scene.hpp"
|
|
||||||
|
|
||||||
void Application::ProcessSceneSignal(SceneSignal signal) {
|
|
||||||
ClearScene();
|
|
||||||
|
|
||||||
switch(signal) {
|
|
||||||
case SceneSignal::FIRST:
|
|
||||||
case SceneSignal::EXAMPLE_SCENE:
|
|
||||||
activeScene = new ExampleScene();
|
|
||||||
break;
|
|
||||||
default: {
|
|
||||||
std::ostringstream msg;
|
|
||||||
msg << "Failed to recognize the scene signal: " << signal;
|
|
||||||
throw(std::logic_error(msg.str()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::ClearScene() {
|
|
||||||
delete activeScene;
|
|
||||||
activeScene = nullptr;
|
|
||||||
}
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "base_scene.hpp"
|
|
||||||
#include "scene_signal.hpp"
|
|
||||||
|
|
||||||
#include "SDL2/SDL.h"
|
|
||||||
|
|
||||||
//TODO: do something with these
|
|
||||||
constexpr int screenWidth = 800;
|
|
||||||
constexpr int screenHeight = 600;
|
|
||||||
|
|
||||||
//DOCS: The Application class handles scene switching, utilizing only one window
|
|
||||||
class Application {
|
|
||||||
public:
|
|
||||||
Application() = default;
|
|
||||||
~Application() = default;
|
|
||||||
|
|
||||||
void Init(int argc, char* argv[]);
|
|
||||||
void Proc();
|
|
||||||
void Quit();
|
|
||||||
|
|
||||||
private:
|
|
||||||
//scene management
|
|
||||||
void ProcessEvents();
|
|
||||||
void ProcessSceneSignal(SceneSignal);
|
|
||||||
void ClearScene();
|
|
||||||
|
|
||||||
BaseScene* activeScene = nullptr;
|
|
||||||
|
|
||||||
//TODO: build a "window" class?
|
|
||||||
SDL_Window* window = nullptr;
|
|
||||||
SDL_Renderer* renderer = nullptr;
|
|
||||||
};
|
|
||||||
@@ -1,105 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#include "base_scene.hpp"
|
|
||||||
|
|
||||||
SDL_Renderer* BaseScene::rendererHandle = nullptr;
|
|
||||||
|
|
||||||
BaseScene::BaseScene() {
|
|
||||||
//EMPTY
|
|
||||||
}
|
|
||||||
|
|
||||||
BaseScene::~BaseScene() {
|
|
||||||
//EMPTY
|
|
||||||
}
|
|
||||||
|
|
||||||
void BaseScene::RenderFrame(SDL_Renderer* renderer) {
|
|
||||||
//EMPTY
|
|
||||||
}
|
|
||||||
|
|
||||||
void BaseScene::SetRenderer(SDL_Renderer* r) {
|
|
||||||
rendererHandle = r;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Renderer* BaseScene::GetRenderer() {
|
|
||||||
return rendererHandle;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BaseScene::SetSceneSignal(SceneSignal signal) {
|
|
||||||
sceneSignal = signal;
|
|
||||||
}
|
|
||||||
|
|
||||||
SceneSignal BaseScene::GetSceneSignal() {
|
|
||||||
return sceneSignal;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
//frame phases
|
|
||||||
//-------------------------
|
|
||||||
|
|
||||||
void BaseScene::FrameStart() {
|
|
||||||
//EMPTY
|
|
||||||
}
|
|
||||||
|
|
||||||
void BaseScene::Update() {
|
|
||||||
//EMPTY
|
|
||||||
}
|
|
||||||
|
|
||||||
void BaseScene::FrameEnd() {
|
|
||||||
//EMPTY
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
//input events
|
|
||||||
//-------------------------
|
|
||||||
|
|
||||||
void BaseScene::QuitEvent() {
|
|
||||||
sceneSignal = SceneSignal::QUIT;
|
|
||||||
}
|
|
||||||
|
|
||||||
void BaseScene::MouseMotion(SDL_MouseMotionEvent const& event) {
|
|
||||||
//EMPTY
|
|
||||||
}
|
|
||||||
|
|
||||||
void BaseScene::MouseButtonDown(SDL_MouseButtonEvent const& event) {
|
|
||||||
//EMPTY
|
|
||||||
}
|
|
||||||
|
|
||||||
void BaseScene::MouseButtonUp(SDL_MouseButtonEvent const& event) {
|
|
||||||
//EMPTY
|
|
||||||
}
|
|
||||||
|
|
||||||
void BaseScene::MouseWheel(SDL_MouseWheelEvent const& event) {
|
|
||||||
//EMPTY
|
|
||||||
}
|
|
||||||
|
|
||||||
void BaseScene::KeyDown(SDL_KeyboardEvent const& event) {
|
|
||||||
//preference as a default
|
|
||||||
switch(event.keysym.sym) {
|
|
||||||
case SDLK_ESCAPE:
|
|
||||||
QuitEvent();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BaseScene::KeyUp(SDL_KeyboardEvent const& event) {
|
|
||||||
//EMPTY
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "scene_signal.hpp"
|
|
||||||
|
|
||||||
#include "SDL2/SDL.h"
|
|
||||||
|
|
||||||
class BaseScene {
|
|
||||||
public:
|
|
||||||
BaseScene();
|
|
||||||
virtual ~BaseScene();
|
|
||||||
|
|
||||||
virtual void RenderFrame(SDL_Renderer*);
|
|
||||||
static void SetRenderer(SDL_Renderer*);
|
|
||||||
SceneSignal GetSceneSignal();
|
|
||||||
|
|
||||||
//frame phases
|
|
||||||
virtual void FrameStart();
|
|
||||||
virtual void Update();
|
|
||||||
virtual void FrameEnd();
|
|
||||||
|
|
||||||
//input events
|
|
||||||
virtual void QuitEvent();
|
|
||||||
virtual void MouseMotion(SDL_MouseMotionEvent const& event);
|
|
||||||
virtual void MouseButtonDown(SDL_MouseButtonEvent const& event);
|
|
||||||
virtual void MouseButtonUp(SDL_MouseButtonEvent const& event);
|
|
||||||
virtual void MouseWheel(SDL_MouseWheelEvent const& event);
|
|
||||||
virtual void KeyDown(SDL_KeyboardEvent const& event);
|
|
||||||
virtual void KeyUp(SDL_KeyboardEvent const& event);
|
|
||||||
|
|
||||||
//TODO: joystick and controller events
|
|
||||||
|
|
||||||
protected:
|
|
||||||
//control
|
|
||||||
static SDL_Renderer* GetRenderer();
|
|
||||||
void SetSceneSignal(SceneSignal);
|
|
||||||
|
|
||||||
private:
|
|
||||||
static SDL_Renderer* rendererHandle;
|
|
||||||
SceneSignal sceneSignal = SceneSignal::CONTINUE;
|
|
||||||
};
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#include "example_scene.hpp"
|
|
||||||
|
|
||||||
ExampleScene::ExampleScene() {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
ExampleScene::~ExampleScene() {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
//frame phases
|
|
||||||
//-------------------------
|
|
||||||
|
|
||||||
void ExampleScene::FrameStart() {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
void ExampleScene::Update() {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
void ExampleScene::FrameEnd() {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
void ExampleScene::RenderFrame(SDL_Renderer* renderer) {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
//input events
|
|
||||||
//-------------------------
|
|
||||||
|
|
||||||
void ExampleScene::MouseMotion(SDL_MouseMotionEvent const& event) {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
void ExampleScene::MouseButtonDown(SDL_MouseButtonEvent const& event) {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
void ExampleScene::MouseButtonUp(SDL_MouseButtonEvent const& event) {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
void ExampleScene::MouseWheel(SDL_MouseWheelEvent const& event) {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
void ExampleScene::KeyDown(SDL_KeyboardEvent const& event) {
|
|
||||||
//preference as a default
|
|
||||||
switch(event.keysym.sym) {
|
|
||||||
case SDLK_ESCAPE:
|
|
||||||
QuitEvent();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ExampleScene::KeyUp(SDL_KeyboardEvent const& event) {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "base_scene.hpp"
|
|
||||||
|
|
||||||
class ExampleScene : public BaseScene {
|
|
||||||
public:
|
|
||||||
ExampleScene();
|
|
||||||
~ExampleScene();
|
|
||||||
|
|
||||||
void RenderFrame(SDL_Renderer* renderer) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
//frame phases
|
|
||||||
void FrameStart() override;
|
|
||||||
void Update() override;
|
|
||||||
void FrameEnd() override;
|
|
||||||
|
|
||||||
//input events
|
|
||||||
void MouseMotion(SDL_MouseMotionEvent const& event) override;
|
|
||||||
void MouseButtonDown(SDL_MouseButtonEvent const& event) override;
|
|
||||||
void MouseButtonUp(SDL_MouseButtonEvent const& event) override;
|
|
||||||
void MouseWheel(SDL_MouseWheelEvent const& event) override;
|
|
||||||
void KeyDown(SDL_KeyboardEvent const& event) override;
|
|
||||||
void KeyUp(SDL_KeyboardEvent const& event) override;
|
|
||||||
};
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
#include directories
|
|
||||||
INCLUDES+=.
|
|
||||||
|
|
||||||
#libraries
|
|
||||||
#the order of the $(LIBS) is important, at least for MinGW
|
|
||||||
LIBS+=
|
|
||||||
ifeq ($(OS),Windows_NT)
|
|
||||||
LIBS+=-lmingw32
|
|
||||||
endif
|
|
||||||
LIBS+=-lSDL2main -lSDL2
|
|
||||||
|
|
||||||
#flags
|
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
|
||||||
ifeq ($(shell uname), Linux)
|
|
||||||
#read data about the current install
|
|
||||||
CXXFLAGS+=$(shell sdl-config --cflags --static-libs)
|
|
||||||
endif
|
|
||||||
|
|
||||||
#source
|
|
||||||
CXXSRC=$(wildcard *.cpp)
|
|
||||||
|
|
||||||
#objects
|
|
||||||
OBJDIR=obj
|
|
||||||
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
|
||||||
|
|
||||||
#output
|
|
||||||
OUTDIR=out
|
|
||||||
OUT=$(addprefix $(OUTDIR)/,scenes)
|
|
||||||
|
|
||||||
#targets
|
|
||||||
all: $(OBJ) $(OUT)
|
|
||||||
$(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
|
|
||||||
|
|
||||||
$(OBJ): | $(OBJDIR)
|
|
||||||
|
|
||||||
$(OUT): | $(OUTDIR)
|
|
||||||
|
|
||||||
$(OBJDIR):
|
|
||||||
mkdir $(OBJDIR)
|
|
||||||
|
|
||||||
$(OUTDIR):
|
|
||||||
mkdir $(OUTDIR)
|
|
||||||
|
|
||||||
$(OBJDIR)/%.o: %.cpp
|
|
||||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
|
||||||
|
|
||||||
clean:
|
|
||||||
ifeq ($(OS),Windows_NT)
|
|
||||||
$(RM) *.o *.a *.exe
|
|
||||||
else ifeq ($(shell uname), Linux)
|
|
||||||
find . -type f -name '*.o' -exec rm -f -r -v {} \;
|
|
||||||
find . -type f -name '*.a' -exec rm -f -r -v {} \;
|
|
||||||
rm -f -v $(OUT)
|
|
||||||
endif
|
|
||||||
|
|
||||||
rebuild: clean all
|
|
||||||
@@ -21,7 +21,12 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "lua.hpp"
|
enum ItemType {
|
||||||
|
//basics
|
||||||
|
POTION = 101,
|
||||||
|
|
||||||
#define TORTUGA_REGION_API "region"
|
//weapons
|
||||||
LUAMOD_API int openRegionAPI(lua_State* L);
|
SWORD = 201,
|
||||||
|
DAGGER = 202,
|
||||||
|
STAFF = 203
|
||||||
|
};
|
||||||
@@ -1,167 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#include "button.hpp"
|
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
void Button::DrawTo(SDL_Renderer* renderer) {
|
|
||||||
image.SetClipY(image.GetClipH() * state);
|
|
||||||
image.DrawTo(renderer, posX, posY);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::SetBackgroundTexture(SDL_Renderer* renderer, SDL_Texture* texture) {
|
|
||||||
//copy the given texture
|
|
||||||
image.Free();
|
|
||||||
|
|
||||||
//a null texture can simply free the image
|
|
||||||
if (!texture) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//get the w & h, & create
|
|
||||||
int w = 0, h = 0;
|
|
||||||
SDL_QueryTexture(texture, nullptr, nullptr, &w, &h);
|
|
||||||
image.Create(renderer, w, h);
|
|
||||||
|
|
||||||
//copy
|
|
||||||
SDL_SetRenderTarget(renderer, image.GetTexture());
|
|
||||||
SDL_RenderCopy(renderer, texture, nullptr, nullptr);
|
|
||||||
SDL_SetRenderTarget(renderer, nullptr);
|
|
||||||
|
|
||||||
//prune
|
|
||||||
image.SetClipH(image.GetClipH() / 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::SetText(SDL_Renderer* renderer, TTF_Font* font, std::string s, SDL_Color color) {
|
|
||||||
//make the surface (from SDL_ttf)
|
|
||||||
SDL_Surface* surf = TTF_RenderText_Solid(font, s.c_str(), color);
|
|
||||||
if (!surf) {
|
|
||||||
throw(std::runtime_error("Failed to create a TTF surface"));
|
|
||||||
}
|
|
||||||
|
|
||||||
//convert to texture
|
|
||||||
SDL_Texture* text = SDL_CreateTextureFromSurface(renderer, surf);
|
|
||||||
SDL_FreeSurface(surf);
|
|
||||||
if (!text) {
|
|
||||||
throw(std::runtime_error("Failed to create a TTF texture"));
|
|
||||||
}
|
|
||||||
|
|
||||||
//get the dimensions & rects
|
|
||||||
int x, y, w, h;
|
|
||||||
SDL_QueryTexture(text, nullptr, nullptr, &w, &h);
|
|
||||||
x = (image.GetClipW() - w) / 2;
|
|
||||||
y = (image.GetClipH() - h) / 2;
|
|
||||||
SDL_Rect src = {0, 0, w, h};
|
|
||||||
SDL_Rect dst;
|
|
||||||
|
|
||||||
//draw the text to the background
|
|
||||||
SDL_SetRenderTarget(renderer, image.GetTexture());
|
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
|
||||||
dst = {x, y + image.GetClipH() * i, w, h};
|
|
||||||
SDL_RenderCopy(renderer, text, &src, &dst);
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_SetRenderTarget(renderer, nullptr);
|
|
||||||
|
|
||||||
//free the texture
|
|
||||||
SDL_DestroyTexture(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::SetX(int x) {
|
|
||||||
posX = x;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::SetY(int y) {
|
|
||||||
posY = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
Button::State Button::MouseMotion(SDL_MouseMotionEvent const& event) {
|
|
||||||
//if out of bounds, exit
|
|
||||||
if (!CheckBounds(event.x, event.y)) {
|
|
||||||
return state = State::IDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
//if in bounds, check button
|
|
||||||
if (event.state & SDL_BUTTON_LMASK && state == State::PRESSED) {
|
|
||||||
//stay pressed
|
|
||||||
// state = State::PRESSED;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
state = State::HOVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
Button::State Button::MouseButtonDown(SDL_MouseButtonEvent const& event) {
|
|
||||||
//if out of bounds, exit
|
|
||||||
if (!CheckBounds(event.x, event.y)) {
|
|
||||||
return state = State::IDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
//if in bounds, check button
|
|
||||||
if (event.button == SDL_BUTTON_LEFT) {
|
|
||||||
return state = State::PRESSED;
|
|
||||||
}
|
|
||||||
|
|
||||||
//NOTE: if not left button down, ignore
|
|
||||||
return State::HOVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
Button::State Button::MouseButtonUp(SDL_MouseButtonEvent const& event) {
|
|
||||||
//if out of bounds, exit
|
|
||||||
if (!CheckBounds(event.x, event.y)) {
|
|
||||||
return state = State::IDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
//if not left button up, ignore
|
|
||||||
if (event.button != SDL_BUTTON_LEFT) {
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
//if in bounds and left button up, send release signal
|
|
||||||
if (state == State::PRESSED) {
|
|
||||||
state = State::HOVER;
|
|
||||||
return State::RELEASED;
|
|
||||||
}
|
|
||||||
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Button::SetState(State s) {
|
|
||||||
state = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
Button::State Button::GetState() {
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Button::CheckBounds(int x, int y) {
|
|
||||||
//return if true (x, y) is within bounds, otherwise return false
|
|
||||||
return !(
|
|
||||||
x < posX ||
|
|
||||||
y < posY ||
|
|
||||||
x > posX + image.GetClipW() ||
|
|
||||||
y > posY + image.GetClipH()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "image.hpp"
|
|
||||||
|
|
||||||
#include "SDL2/SDL_ttf.h"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
constexpr SDL_Color COLOR_WHITE = {255, 255, 255, 255};
|
|
||||||
constexpr SDL_Color COLOR_RED = {255, 0, 0, 255};
|
|
||||||
constexpr SDL_Color COLOR_ORANGE = {255, 127, 0, 255};
|
|
||||||
constexpr SDL_Color COLOR_BLUE = {0, 0, 255, 255};
|
|
||||||
|
|
||||||
class Button {
|
|
||||||
public:
|
|
||||||
enum State {
|
|
||||||
IDLE = 0, HOVER = 1, PRESSED = 2, RELEASED = 3
|
|
||||||
};
|
|
||||||
|
|
||||||
//methods
|
|
||||||
Button() = default;
|
|
||||||
~Button() = default;
|
|
||||||
|
|
||||||
void DrawTo(SDL_Renderer*);
|
|
||||||
|
|
||||||
//setup
|
|
||||||
void SetBackgroundTexture(SDL_Renderer*, SDL_Texture*);
|
|
||||||
void SetText(SDL_Renderer*, TTF_Font*, std::string, SDL_Color);
|
|
||||||
void SetX(int x);
|
|
||||||
void SetY(int y);
|
|
||||||
|
|
||||||
//capture input
|
|
||||||
State MouseMotion(SDL_MouseMotionEvent const&);
|
|
||||||
State MouseButtonDown(SDL_MouseButtonEvent const&);
|
|
||||||
State MouseButtonUp(SDL_MouseButtonEvent const&);
|
|
||||||
|
|
||||||
//states
|
|
||||||
void SetState(State); //TODO: idle, busy or disabled
|
|
||||||
State GetState();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool CheckBounds(int x, int y);
|
|
||||||
|
|
||||||
Image image;
|
|
||||||
int posX = 0, posY = 0;
|
|
||||||
State state = State::IDLE;
|
|
||||||
};
|
|
||||||
@@ -1,211 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#include "image.hpp"
|
|
||||||
|
|
||||||
#include "SDL2/SDL_image.h"
|
|
||||||
|
|
||||||
#include <sstream>
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
Image& Image::operator=(Image const& rhs) {
|
|
||||||
//don't screw yourself
|
|
||||||
if (this == &rhs) {
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Free();
|
|
||||||
|
|
||||||
//Copy the other Image's stuff
|
|
||||||
texture = rhs.texture;
|
|
||||||
clip = rhs.clip;
|
|
||||||
local = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Image& Image::operator=(Image&& rhs) {
|
|
||||||
//don't screw yourself
|
|
||||||
if (this == &rhs) {
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Free();
|
|
||||||
|
|
||||||
//Steal the other Image's stuff
|
|
||||||
texture = rhs.texture;
|
|
||||||
clip = rhs.clip;
|
|
||||||
local = rhs.local;
|
|
||||||
|
|
||||||
rhs.texture = nullptr;
|
|
||||||
rhs.clip = {0, 0, 0, 0};
|
|
||||||
rhs.local = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Texture* Image::Load(SDL_Renderer* renderer, std::string fname) {
|
|
||||||
Free();
|
|
||||||
|
|
||||||
//load the file into a surface
|
|
||||||
SDL_Surface* surface = IMG_Load(fname.c_str());
|
|
||||||
if (!surface) {
|
|
||||||
std::ostringstream msg;
|
|
||||||
msg << "Failed to load an image file: " << fname;
|
|
||||||
msg << "; " << IMG_GetError();
|
|
||||||
throw(std::runtime_error(msg.str()));
|
|
||||||
}
|
|
||||||
|
|
||||||
//create a texture from this surface
|
|
||||||
texture = SDL_CreateTextureFromSurface(renderer, surface);
|
|
||||||
if (!texture) {
|
|
||||||
std::ostringstream msg;
|
|
||||||
msg << "Failed to convert a newly loaded image file: " << fname;
|
|
||||||
msg << "; " << SDL_GetError();
|
|
||||||
throw(std::runtime_error(msg.str()));
|
|
||||||
}
|
|
||||||
|
|
||||||
//set the metadata
|
|
||||||
clip.x = 0;
|
|
||||||
clip.y = 0;
|
|
||||||
if (SDL_QueryTexture(texture, nullptr, nullptr, &clip.w, &clip.h)) {
|
|
||||||
std::ostringstream msg;
|
|
||||||
msg << "Failed to record metadata for a newly loaded image file: " << fname;
|
|
||||||
msg << "; " << SDL_GetError();
|
|
||||||
throw(std::runtime_error(msg.str()));
|
|
||||||
}
|
|
||||||
local = true;
|
|
||||||
|
|
||||||
//free the surface & return
|
|
||||||
SDL_FreeSurface(surface);
|
|
||||||
return texture;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Texture* Image::Create(SDL_Renderer* renderer, Uint16 w, Uint16 h, SDL_Color blank) {
|
|
||||||
Free();
|
|
||||||
|
|
||||||
//make the texture
|
|
||||||
texture = SDL_CreateTexture(renderer,
|
|
||||||
SDL_PIXELFORMAT_RGBA8888,
|
|
||||||
SDL_TEXTUREACCESS_TARGET,
|
|
||||||
w, h);
|
|
||||||
|
|
||||||
//check
|
|
||||||
if (!texture) {
|
|
||||||
std::ostringstream msg;
|
|
||||||
msg << "Failed to create a texture; " << SDL_GetError();
|
|
||||||
throw(std::runtime_error(msg.str()));
|
|
||||||
}
|
|
||||||
|
|
||||||
//set the metadata
|
|
||||||
clip.x = 0;
|
|
||||||
clip.y = 0;
|
|
||||||
if (SDL_QueryTexture(texture, nullptr, nullptr, &clip.w, &clip.h)) {
|
|
||||||
std::ostringstream msg;
|
|
||||||
msg << "Failed to record metadata for a newly created image";
|
|
||||||
msg << "; " << SDL_GetError();
|
|
||||||
throw(std::runtime_error(msg.str()));
|
|
||||||
}
|
|
||||||
local = true;
|
|
||||||
|
|
||||||
//blank (black) texture
|
|
||||||
SDL_SetRenderTarget(renderer, texture);
|
|
||||||
SDL_SetRenderDrawColor(renderer, blank.r, blank.g, blank.b, blank.a);
|
|
||||||
SDL_RenderFillRect(renderer, nullptr);
|
|
||||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
|
|
||||||
SDL_SetRenderTarget(renderer, nullptr);
|
|
||||||
|
|
||||||
return texture;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Texture* Image::CopyTexture(SDL_Renderer* renderer, SDL_Texture* ptr) {
|
|
||||||
Free();
|
|
||||||
int w = 0, h = 0;
|
|
||||||
|
|
||||||
//get the info
|
|
||||||
SDL_QueryTexture(ptr, nullptr, nullptr, &w, &h);
|
|
||||||
|
|
||||||
//create a texture of (w, h) size (also sets the metadata)
|
|
||||||
Create(renderer, w, h);
|
|
||||||
|
|
||||||
//copy the argument texture to the local texture
|
|
||||||
SDL_SetRenderTarget(renderer, texture);
|
|
||||||
SDL_RenderCopy(renderer, ptr, nullptr, nullptr);
|
|
||||||
SDL_SetRenderTarget(renderer, nullptr);
|
|
||||||
|
|
||||||
//return the local texture
|
|
||||||
return texture;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Texture* Image::SetTexture(SDL_Texture* ptr) {
|
|
||||||
Free();
|
|
||||||
|
|
||||||
texture = ptr;
|
|
||||||
|
|
||||||
//set the metadata
|
|
||||||
clip.x = 0;
|
|
||||||
clip.y = 0;
|
|
||||||
if (SDL_QueryTexture(texture, nullptr, nullptr, &clip.w, &clip.h)) {
|
|
||||||
std::ostringstream msg;
|
|
||||||
msg << "Failed to record metadata for a newly set image";
|
|
||||||
msg << "; " << SDL_GetError();
|
|
||||||
throw(std::runtime_error(msg.str()));
|
|
||||||
}
|
|
||||||
local = false;
|
|
||||||
|
|
||||||
return texture;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Texture* Image::GetTexture() const {
|
|
||||||
return texture;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Image::Free() {
|
|
||||||
if (local) {
|
|
||||||
SDL_DestroyTexture(texture);
|
|
||||||
local = false;
|
|
||||||
}
|
|
||||||
texture = nullptr;
|
|
||||||
clip = {0, 0, 0, 0};
|
|
||||||
}
|
|
||||||
|
|
||||||
void Image::DrawTo(SDL_Renderer* const renderer, Sint16 x, Sint16 y, double scaleX, double scaleY) {
|
|
||||||
if (!texture) {
|
|
||||||
throw(std::logic_error("No image texture to draw"));
|
|
||||||
}
|
|
||||||
SDL_Rect sclip = clip;
|
|
||||||
SDL_Rect dclip = {x, y, Uint16(clip.w * scaleX), Uint16(clip.h * scaleY)};
|
|
||||||
SDL_RenderCopy(renderer, texture, &sclip, &dclip);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Image::SetAlpha(Uint8 a) {
|
|
||||||
if (SDL_SetTextureAlphaMod(texture, a)) {
|
|
||||||
std::ostringstream msg;
|
|
||||||
msg << "Failed to set alpha; " << SDL_GetError();
|
|
||||||
throw(std::runtime_error(msg.str()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Uint8 Image::GetAlpha() {
|
|
||||||
Uint8 ret = 0;
|
|
||||||
if (SDL_GetTextureAlphaMod(texture, &ret)) {
|
|
||||||
std::ostringstream msg;
|
|
||||||
msg << "Failed to get alpha; " << SDL_GetError();
|
|
||||||
throw(std::runtime_error(msg.str()));
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "SDL2/SDL.h"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
class Image {
|
|
||||||
public:
|
|
||||||
Image() = default;
|
|
||||||
Image(Image const& rhs) { *this = rhs; }
|
|
||||||
Image(Image&& rhs) { *this = std::move(rhs); }
|
|
||||||
Image(SDL_Renderer* r, std::string fname) { Load(r, fname); }
|
|
||||||
Image(SDL_Renderer* r, Uint16 w, Uint16 h) { Create(r, w, h); }
|
|
||||||
Image(SDL_Texture* p) { SetTexture(p); }
|
|
||||||
virtual ~Image() { Free(); }
|
|
||||||
|
|
||||||
Image& operator=(Image const&);
|
|
||||||
Image& operator=(Image&&);
|
|
||||||
|
|
||||||
SDL_Texture* Load(SDL_Renderer* renderer, std::string fname);
|
|
||||||
SDL_Texture* Create(SDL_Renderer* renderer, Uint16 w, Uint16 h, SDL_Color blank = {0, 0, 0, 255});
|
|
||||||
SDL_Texture* CopyTexture(SDL_Renderer* renderer, SDL_Texture* ptr);
|
|
||||||
SDL_Texture* SetTexture(SDL_Texture*);
|
|
||||||
SDL_Texture* GetTexture() const;
|
|
||||||
virtual void Free();
|
|
||||||
|
|
||||||
void DrawTo(SDL_Renderer* const, Sint16 x, Sint16 y, double scaleX = 1.0, double scaleY = 1.0);
|
|
||||||
|
|
||||||
void SetAlpha(Uint8 a);
|
|
||||||
Uint8 GetAlpha();
|
|
||||||
|
|
||||||
//Clip handlers
|
|
||||||
SDL_Rect SetClip(SDL_Rect r) { return clip = r; }
|
|
||||||
SDL_Rect GetClip() const { return clip; }
|
|
||||||
|
|
||||||
Sint16 SetClipX(Sint16 x) { return clip.x = x; }
|
|
||||||
Sint16 SetClipY(Sint16 y) { return clip.y = y; }
|
|
||||||
Uint16 SetClipW(Uint16 w) { return clip.w = w; }
|
|
||||||
Uint16 SetClipH(Uint16 h) { return clip.h = h; }
|
|
||||||
|
|
||||||
Sint16 GetClipX() const { return clip.x; }
|
|
||||||
Sint16 GetClipY() const { return clip.y; }
|
|
||||||
Uint16 GetClipW() const { return clip.w; }
|
|
||||||
Uint16 GetClipH() const { return clip.h; }
|
|
||||||
|
|
||||||
bool GetLocal() const { return local; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
SDL_Texture* texture = nullptr;
|
|
||||||
SDL_Rect clip = {0, 0, 0, 0};
|
|
||||||
bool local = false;
|
|
||||||
};
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
#config
|
|
||||||
INCLUDES+=.
|
|
||||||
LIBS+=
|
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
|
||||||
|
|
||||||
#source
|
|
||||||
CXXSRC=$(wildcard *.cpp)
|
|
||||||
|
|
||||||
#objects
|
|
||||||
OBJDIR=obj
|
|
||||||
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
|
||||||
|
|
||||||
#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 $@ $<
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#include "text_line.hpp"
|
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
SDL_Texture* renderTextTexture(SDL_Renderer* renderer, TTF_Font* font, std::string str, SDL_Color color) {
|
|
||||||
//make the surface (from SDL_ttf)
|
|
||||||
SDL_Surface* surface = TTF_RenderText_Solid(font, str.c_str(), color);
|
|
||||||
if (!surface) {
|
|
||||||
throw(std::runtime_error("Failed to create a TTF surface"));
|
|
||||||
}
|
|
||||||
|
|
||||||
//convert to texture
|
|
||||||
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface);
|
|
||||||
|
|
||||||
//cleanup
|
|
||||||
SDL_FreeSurface(surface);
|
|
||||||
|
|
||||||
//check
|
|
||||||
if (!texture) {
|
|
||||||
throw(std::runtime_error("Failed to create a TTF texture"));
|
|
||||||
}
|
|
||||||
|
|
||||||
//NOTE: free the texture yourself
|
|
||||||
return texture;
|
|
||||||
}
|
|
||||||
|
|
||||||
TextLine::TextLine() {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
TextLine::~TextLine() {
|
|
||||||
ClearText();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextLine::DrawTo(SDL_Renderer* renderer, int posX, int posY) {
|
|
||||||
SDL_Rect dclip = {posX, posY, 0, 0};
|
|
||||||
SDL_QueryTexture(texture, nullptr, nullptr, &dclip.w, &dclip.h);
|
|
||||||
SDL_RenderCopy(renderer, texture, nullptr, &dclip);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextLine::SetText(SDL_Renderer* renderer, TTF_Font* font, std::string str, SDL_Color color) {
|
|
||||||
//just use the above global function
|
|
||||||
SDL_DestroyTexture(texture);
|
|
||||||
texture = renderTextTexture(renderer, font, str, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextLine::ClearText() {
|
|
||||||
SDL_DestroyTexture(texture);
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "SDL2/SDL.h"
|
|
||||||
#include "SDL2/SDL_ttf.h"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
SDL_Texture* renderTextTexture(SDL_Renderer*, TTF_Font*, std::string, SDL_Color color);
|
|
||||||
|
|
||||||
class TextLine {
|
|
||||||
public:
|
|
||||||
TextLine();
|
|
||||||
TextLine(SDL_Renderer* r, TTF_Font* f, std::string s, SDL_Color c)
|
|
||||||
{ SetText(r, f, s, c); }
|
|
||||||
virtual ~TextLine();
|
|
||||||
|
|
||||||
void DrawTo(SDL_Renderer*, int posX, int posY);
|
|
||||||
|
|
||||||
void SetText(SDL_Renderer*, TTF_Font*, std::string, SDL_Color color);
|
|
||||||
void ClearText();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
SDL_Texture* texture = nullptr;
|
|
||||||
};
|
|
||||||
+2
-4
@@ -1,12 +1,10 @@
|
|||||||
#output
|
#output
|
||||||
export OUTDIR=..
|
export OUTDIR=../..
|
||||||
export OUT=$(addprefix $(OUTDIR)/,libcommon.a)
|
export OUT=$(addprefix $(OUTDIR)/,libcommon.a)
|
||||||
|
|
||||||
all: $(OUTDIR)
|
all: $(OUTDIR)
|
||||||
$(MAKE) -C debugging
|
$(MAKE) -C debugging
|
||||||
$(MAKE) -C gameplay
|
$(MAKE) -C global_defines
|
||||||
$(MAKE) -C graphics
|
|
||||||
$(MAKE) -C map
|
|
||||||
$(MAKE) -C network
|
$(MAKE) -C network
|
||||||
$(MAKE) -C utilities
|
$(MAKE) -C utilities
|
||||||
|
|
||||||
|
|||||||
@@ -1,82 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#include "region.hpp"
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <cstring>
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
int snapToBase(int base, int x) {
|
|
||||||
return floor((double)x / base) * base;
|
|
||||||
}
|
|
||||||
|
|
||||||
Region::Region(int argX, int argY): x(argX), y(argY) {
|
|
||||||
if (x != snapToBase(REGION_WIDTH, x) || y != snapToBase(REGION_HEIGHT, y)) {
|
|
||||||
throw(std::invalid_argument("Region location is off grid"));
|
|
||||||
}
|
|
||||||
memset(tiles, 0, REGION_WIDTH*REGION_HEIGHT*REGION_DEPTH*sizeof(type_t));
|
|
||||||
}
|
|
||||||
|
|
||||||
Region::Region(Region const& rhs): x(rhs.x), y(rhs.y) {
|
|
||||||
memcpy(tiles, rhs.tiles, REGION_WIDTH*REGION_HEIGHT*REGION_DEPTH*sizeof(type_t));
|
|
||||||
solid = rhs.solid;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
Region::type_t Region::GetTile(int x, int y, int z) const {
|
|
||||||
if (x < 0 || y < 0 || z < 0 || x >= REGION_WIDTH || y >= REGION_HEIGHT || z >= REGION_DEPTH) {
|
|
||||||
throw(std::out_of_range("Region::GetTile() argument out of range"));
|
|
||||||
}
|
|
||||||
return tiles[x][y][z];
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Region::GetSolid(int x, int y) const {
|
|
||||||
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];
|
|
||||||
}
|
|
||||||
|
|
||||||
int Region::GetX() const {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Region::GetY() const {
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::bitset<REGION_WIDTH*REGION_HEIGHT>* Region::GetSolidBitset() {
|
|
||||||
return &solid;
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <bitset>
|
|
||||||
|
|
||||||
//the region's storage format
|
|
||||||
constexpr int REGION_WIDTH = 20;
|
|
||||||
constexpr int REGION_HEIGHT = 20;
|
|
||||||
constexpr int REGION_DEPTH = 3;
|
|
||||||
|
|
||||||
//utility function
|
|
||||||
int snapToBase(int base, int x);
|
|
||||||
|
|
||||||
class Region {
|
|
||||||
public:
|
|
||||||
typedef unsigned char type_t;
|
|
||||||
|
|
||||||
Region() = delete;
|
|
||||||
Region(int x, int y);
|
|
||||||
Region(Region const&);
|
|
||||||
~Region() = default;
|
|
||||||
|
|
||||||
type_t SetTile(int x, int y, int z, type_t v);
|
|
||||||
type_t GetTile(int x, int y, int z) const;
|
|
||||||
|
|
||||||
bool SetSolid(int x, int y, bool b);
|
|
||||||
bool GetSolid(int x, int y) const;
|
|
||||||
|
|
||||||
//accessors
|
|
||||||
int GetX() const;
|
|
||||||
int GetY() const;
|
|
||||||
|
|
||||||
std::bitset<REGION_WIDTH*REGION_HEIGHT>* GetSolidBitset();
|
|
||||||
private:
|
|
||||||
friend class TileSheet;
|
|
||||||
|
|
||||||
const int x;
|
|
||||||
const int y;
|
|
||||||
|
|
||||||
type_t tiles[REGION_WIDTH][REGION_HEIGHT][REGION_DEPTH];
|
|
||||||
std::bitset<REGION_WIDTH*REGION_HEIGHT> solid;
|
|
||||||
};
|
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#include "region_api.hpp"
|
|
||||||
|
|
||||||
#include "region.hpp"
|
|
||||||
|
|
||||||
static int setTile(lua_State* L) {
|
|
||||||
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
|
|
||||||
int ret = region->SetTile(lua_tointeger(L, 2)-1, lua_tointeger(L, 3)-1, lua_tointeger(L, 4)-1, lua_tointeger(L, 5));
|
|
||||||
lua_pushinteger(L, ret);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int getTile(lua_State* L) {
|
|
||||||
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
|
|
||||||
int ret = region->GetTile(lua_tointeger(L, 2)-1, lua_tointeger(L, 3)-1, lua_tointeger(L, 4)-1);
|
|
||||||
lua_pushinteger(L, ret);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int setSolid(lua_State* L) {
|
|
||||||
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
|
|
||||||
bool ret = region->SetSolid(lua_tointeger(L, 2)-1, lua_tointeger(L, 3)-1, lua_toboolean(L, 4));
|
|
||||||
lua_pushboolean(L, ret);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int getSolid(lua_State* L) {
|
|
||||||
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
|
|
||||||
bool ret = region->GetSolid(lua_tointeger(L, 2)-1, lua_tointeger(L, 3)-1);
|
|
||||||
lua_pushboolean(L, ret);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int getX(lua_State* L) {
|
|
||||||
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
|
|
||||||
lua_pushinteger(L, region->GetX());
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int getY(lua_State* L) {
|
|
||||||
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
|
|
||||||
lua_pushinteger(L, region->GetY());
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int getWidth(lua_State* L) {
|
|
||||||
lua_pushinteger(L, REGION_WIDTH);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int getHeight(lua_State* L) {
|
|
||||||
lua_pushinteger(L, REGION_HEIGHT);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int getDepth(lua_State* L) {
|
|
||||||
lua_pushinteger(L, REGION_DEPTH);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const luaL_Reg regionLib[] = {
|
|
||||||
{"SetTile",setTile},
|
|
||||||
{"GetTile",getTile},
|
|
||||||
{"SetSolid",setSolid},
|
|
||||||
{"GetSolid",getSolid},
|
|
||||||
{"GetX",getX},
|
|
||||||
{"GetY",getY},
|
|
||||||
|
|
||||||
//the global macros
|
|
||||||
{"GetWidth",getWidth},
|
|
||||||
{"GetHeight",getHeight},
|
|
||||||
{"GetDepth",getDepth},
|
|
||||||
{nullptr, nullptr}
|
|
||||||
};
|
|
||||||
|
|
||||||
LUAMOD_API int openRegionAPI(lua_State* L) {
|
|
||||||
luaL_newlib(L, regionLib);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
@@ -1,172 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#include "region_pager_api.hpp"
|
|
||||||
|
|
||||||
#include "region_pager_lua.hpp"
|
|
||||||
#include "region.hpp"
|
|
||||||
|
|
||||||
//DOCS: These glue functions simply wrap RegionPagerLua's methods
|
|
||||||
//NOTE: zero indexing is used here, but not in the region API
|
|
||||||
|
|
||||||
static int setTile(lua_State* L) {
|
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
|
||||||
int ret = pager->SetTile(lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
|
|
||||||
lua_pushinteger(L, ret);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int getTile(lua_State* L) {
|
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
|
||||||
int ret = pager->GetTile(lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4));
|
|
||||||
lua_pushinteger(L, ret);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int setSolid(lua_State* L) {
|
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
|
||||||
bool ret = pager->SetSolid(lua_tointeger(L, 2), lua_tointeger(L, 3), lua_toboolean(L, 4));
|
|
||||||
lua_pushboolean(L, ret);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int getSolid(lua_State* L) {
|
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
|
||||||
bool ret = pager->GetSolid(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
|
||||||
lua_pushboolean(L, ret);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int getRegion(lua_State* L) {
|
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
|
||||||
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
|
||||||
lua_pushlightuserdata(L, region);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int loadRegion(lua_State* L) {
|
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
|
||||||
Region* region = pager->LoadRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
|
||||||
lua_pushlightuserdata(L, region);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int saveRegion(lua_State* L) {
|
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
|
||||||
Region* region = pager->SaveRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
|
||||||
lua_pushlightuserdata(L, region);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int createRegion(lua_State* L) {
|
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
|
||||||
Region* region = pager->CreateRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
|
||||||
lua_pushlightuserdata(L, region);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int unloadRegion(lua_State* L) {
|
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
|
||||||
|
|
||||||
//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;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int setOnLoad(lua_State* L) {
|
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
|
||||||
luaL_unref(L, LUA_REGISTRYINDEX, pager->GetLoadReference());
|
|
||||||
pager->SetLoadReference(luaL_ref(L, LUA_REGISTRYINDEX));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int setOnSave(lua_State* L) {
|
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
|
||||||
luaL_unref(L, LUA_REGISTRYINDEX, pager->GetSaveReference());
|
|
||||||
pager->SetSaveReference(luaL_ref(L, LUA_REGISTRYINDEX));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int setOnCreate(lua_State* L) {
|
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
|
||||||
luaL_unref(L, LUA_REGISTRYINDEX, pager->GetCreateReference());
|
|
||||||
pager->SetCreateReference(luaL_ref(L, LUA_REGISTRYINDEX));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int setOnUnload(lua_State* L) {
|
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
|
||||||
luaL_unref(L, LUA_REGISTRYINDEX, pager->GetUnloadReference());
|
|
||||||
pager->SetUnloadReference(luaL_ref(L, LUA_REGISTRYINDEX));
|
|
||||||
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[] = {
|
|
||||||
//curry
|
|
||||||
{"SetTile", setTile},
|
|
||||||
{"GetTile", getTile},
|
|
||||||
{"SetSolid", setSolid},
|
|
||||||
{"GetSolid", getSolid},
|
|
||||||
|
|
||||||
//access and control
|
|
||||||
{"GetRegion", getRegion},
|
|
||||||
{"LoadRegion", loadRegion},
|
|
||||||
{"SaveRegion", saveRegion},
|
|
||||||
{"CreateRegion", createRegion},
|
|
||||||
{"UnloadRegion", unloadRegion},
|
|
||||||
|
|
||||||
//triggers
|
|
||||||
{"SetOnLoad",setOnLoad},
|
|
||||||
{"SetOnSave",setOnSave},
|
|
||||||
{"SetOnCreate",setOnCreate},
|
|
||||||
{"SetOnUnload",setOnUnload},
|
|
||||||
|
|
||||||
//debugging
|
|
||||||
{"ContainerSize", containerSize},
|
|
||||||
|
|
||||||
//sentinel
|
|
||||||
{nullptr, nullptr}
|
|
||||||
};
|
|
||||||
|
|
||||||
LUAMOD_API int openRegionPagerAPI(lua_State* L) {
|
|
||||||
luaL_newlib(L, regionPagerLib);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
@@ -1,106 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#include "region_pager_base.hpp"
|
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
RegionPagerBase::~RegionPagerBase() {
|
|
||||||
UnloadAll();
|
|
||||||
};
|
|
||||||
|
|
||||||
Region::type_t RegionPagerBase::SetTile(int x, int y, int z, Region::type_t v) {
|
|
||||||
Region* ptr = GetRegion(x, y);
|
|
||||||
return ptr->SetTile(x - ptr->GetX(), y - ptr->GetY(), z, v);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Bug Origin?
|
|
||||||
Region::type_t RegionPagerBase::GetTile(int x, int y, int z) {
|
|
||||||
Region* ptr = GetRegion(x, y);
|
|
||||||
return ptr->GetTile(x - ptr->GetX(), y - ptr->GetY(), z);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RegionPagerBase::SetSolid(int x, int y, int b) {
|
|
||||||
Region* ptr = GetRegion(x, y);
|
|
||||||
return ptr->SetSolid(x - ptr->GetX(), y - ptr->GetY(), b);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RegionPagerBase::GetSolid(int x, int y) {
|
|
||||||
Region* ptr = GetRegion(x, y);
|
|
||||||
return ptr->GetSolid(x - ptr->GetX(), y - ptr->GetY());
|
|
||||||
}
|
|
||||||
|
|
||||||
Region* RegionPagerBase::GetRegion(int x, int y) {
|
|
||||||
x = snapToBase(REGION_WIDTH, x);
|
|
||||||
y = snapToBase(REGION_HEIGHT, y);
|
|
||||||
|
|
||||||
//get the region by various means
|
|
||||||
Region* ptr = nullptr;
|
|
||||||
ptr = FindRegion(x, y);
|
|
||||||
if (ptr) return ptr;
|
|
||||||
ptr = LoadRegion(x, y);
|
|
||||||
if (ptr) return ptr;
|
|
||||||
return CreateRegion(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
Region* RegionPagerBase::FindRegion(int x, int y) {
|
|
||||||
//find the region
|
|
||||||
std::list<Region>::iterator it = find_if(regionList.begin(), regionList.end(), [x, y](Region& region) -> bool {
|
|
||||||
return region.GetX() == x && region.GetY() == y;
|
|
||||||
});
|
|
||||||
return it != regionList.end() ? &(*it) : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
Region* RegionPagerBase::PushRegion(Region* const ptr) {
|
|
||||||
regionList.push_front(*ptr);
|
|
||||||
return ®ionList.front();
|
|
||||||
}
|
|
||||||
|
|
||||||
Region* RegionPagerBase::LoadRegion(int x, int y) {
|
|
||||||
//EMPTY, intended for override
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
Region* RegionPagerBase::SaveRegion(int x, int y) {
|
|
||||||
//EMPTY, intended for override
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
Region* RegionPagerBase::CreateRegion(int x, int y) {
|
|
||||||
if (FindRegion(x, y)) {
|
|
||||||
throw(std::logic_error("Cannot overwrite an existing region"));
|
|
||||||
}
|
|
||||||
regionList.emplace_front(x, y);
|
|
||||||
return ®ionList.front();
|
|
||||||
}
|
|
||||||
|
|
||||||
void RegionPagerBase::UnloadIf(std::function<bool(Region const&)> fn) {
|
|
||||||
regionList.remove_if(fn);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RegionPagerBase::UnloadAll() {
|
|
||||||
regionList.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::list<Region>* RegionPagerBase::GetContainer() {
|
|
||||||
return ®ionList;
|
|
||||||
}
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "region.hpp"
|
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
#include <list>
|
|
||||||
|
|
||||||
class RegionPagerBase {
|
|
||||||
public:
|
|
||||||
RegionPagerBase() = default;
|
|
||||||
virtual ~RegionPagerBase();
|
|
||||||
|
|
||||||
//tile manipulation
|
|
||||||
virtual Region::type_t SetTile(int x, int y, int z, Region::type_t v);
|
|
||||||
virtual Region::type_t GetTile(int x, int y, int z);
|
|
||||||
|
|
||||||
//solid manipulation
|
|
||||||
virtual bool SetSolid(int x, int y, int b);
|
|
||||||
virtual bool GetSolid(int x, int y);
|
|
||||||
|
|
||||||
//region manipulation
|
|
||||||
virtual Region* GetRegion(int x, int y);
|
|
||||||
virtual Region* FindRegion(int x, int y);
|
|
||||||
virtual Region* PushRegion(Region* const);
|
|
||||||
|
|
||||||
virtual Region* LoadRegion(int x, int y);
|
|
||||||
virtual Region* SaveRegion(int x, int y);
|
|
||||||
virtual Region* CreateRegion(int x, int y);
|
|
||||||
|
|
||||||
virtual void UnloadIf(std::function<bool(Region const&)> fn);
|
|
||||||
virtual void UnloadAll();
|
|
||||||
|
|
||||||
//accessors & mutators
|
|
||||||
std::list<Region>* GetContainer();
|
|
||||||
protected:
|
|
||||||
std::list<Region> regionList;
|
|
||||||
};
|
|
||||||
@@ -1,208 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#include "region_pager_lua.hpp"
|
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
RegionPagerLua::~RegionPagerLua() {
|
|
||||||
//unload all regions
|
|
||||||
UnloadAll();
|
|
||||||
//clear any stored functions
|
|
||||||
luaL_unref(lua, LUA_REGISTRYINDEX, loadRef);
|
|
||||||
luaL_unref(lua, LUA_REGISTRYINDEX, saveRef);
|
|
||||||
luaL_unref(lua, LUA_REGISTRYINDEX, createRef);
|
|
||||||
luaL_unref(lua, LUA_REGISTRYINDEX, unloadRef);
|
|
||||||
}
|
|
||||||
|
|
||||||
//return the loaded region, or nullptr on failure
|
|
||||||
Region* RegionPagerLua::LoadRegion(int x, int y) {
|
|
||||||
//get the pager's function from the registry
|
|
||||||
lua_rawgeti(lua, LUA_REGISTRYINDEX, loadRef);
|
|
||||||
|
|
||||||
//check if this function is available
|
|
||||||
if (lua_isnil(lua, -1)) {
|
|
||||||
lua_pop(lua, 1);
|
|
||||||
//signal that there is no load function
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
//something to work on
|
|
||||||
Region tmpRegion(x, y);
|
|
||||||
lua_pushlightuserdata(lua, &tmpRegion);
|
|
||||||
|
|
||||||
//call the funtion, 1 arg, 1 return
|
|
||||||
if (lua_pcall(lua, 1, 1, 0) != LUA_OK) {
|
|
||||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
|
|
||||||
}
|
|
||||||
|
|
||||||
//check the return value, success or failure
|
|
||||||
if (lua_isboolean(lua, -1) && lua_toboolean(lua, -1)) {
|
|
||||||
lua_pop(lua, 1);
|
|
||||||
//push and return the loaded region
|
|
||||||
regionList.push_front(tmpRegion);
|
|
||||||
return ®ionList.front();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
lua_pop(lua, 1);
|
|
||||||
//signal a failure
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//NOTE: this return value seems strange; could replace it with a boolean
|
|
||||||
//return the saved region, or nullptr on failure
|
|
||||||
Region* RegionPagerLua::SaveRegion(int x, int y) {
|
|
||||||
//get the pager's function from the registry
|
|
||||||
lua_rawgeti(lua, LUA_REGISTRYINDEX, saveRef);
|
|
||||||
|
|
||||||
//check if this function is available
|
|
||||||
if (lua_isnil(lua, -1)) {
|
|
||||||
lua_pop(lua, 1);
|
|
||||||
//signal that the region wasn't saved
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
//find the specified region
|
|
||||||
Region* ptr = FindRegion(x, y);
|
|
||||||
if (!ptr) {
|
|
||||||
lua_pop(lua, 1);
|
|
||||||
//signal that there is no save function
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
lua_pushlightuserdata(lua, ptr);
|
|
||||||
|
|
||||||
//call the function, 1 arg, 1 return
|
|
||||||
if (lua_pcall(lua, 1, 1, 0) != LUA_OK) {
|
|
||||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
|
|
||||||
}
|
|
||||||
|
|
||||||
//check the return value, success or failure
|
|
||||||
if (lua_isboolean(lua, -1) && lua_toboolean(lua, -1)) {
|
|
||||||
lua_pop(lua, 1);
|
|
||||||
//return the specified region that was saved
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
lua_pop(lua, 1);
|
|
||||||
//signal a failure
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//DOCS: since this method is the last ditch call from GetRegion, it must return a valid region object, even if the create function hasn't been set.
|
|
||||||
//return a new region, throwing an error on failure
|
|
||||||
Region* RegionPagerLua::CreateRegion(int x, int y) {
|
|
||||||
if (FindRegion(x, y)) {
|
|
||||||
throw(std::logic_error("Cannot overwrite an existing region"));
|
|
||||||
}
|
|
||||||
|
|
||||||
//get the pager's function from the registry
|
|
||||||
lua_rawgeti(lua, LUA_REGISTRYINDEX, createRef);
|
|
||||||
|
|
||||||
//check if this function is available
|
|
||||||
if (lua_isnil(lua, -1)) {
|
|
||||||
lua_pop(lua, 1);
|
|
||||||
//return an empty region object
|
|
||||||
regionList.emplace_front(x, y);
|
|
||||||
return ®ionList.front();
|
|
||||||
}
|
|
||||||
|
|
||||||
//something to work on
|
|
||||||
Region tmpRegion(x, y);
|
|
||||||
lua_pushlightuserdata(lua, &tmpRegion);
|
|
||||||
|
|
||||||
//call the function, 1 arg, 0 return
|
|
||||||
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) {
|
|
||||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
|
|
||||||
}
|
|
||||||
|
|
||||||
//return the new region
|
|
||||||
regionList.push_front(tmpRegion);
|
|
||||||
return ®ionList.front();
|
|
||||||
}
|
|
||||||
|
|
||||||
//no return
|
|
||||||
void RegionPagerLua::UnloadIf(std::function<bool(Region const&)> fn) {
|
|
||||||
//get the pager's function from the registry
|
|
||||||
lua_rawgeti(lua, LUA_REGISTRYINDEX, unloadRef);
|
|
||||||
|
|
||||||
//check if this function is available
|
|
||||||
if (lua_isnil(lua, -1)) {
|
|
||||||
lua_pop(lua, 1);
|
|
||||||
//remove the regions anyway
|
|
||||||
regionList.remove_if(fn);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//run each region through this lambda
|
|
||||||
regionList.remove_if([&](Region& region) -> bool {
|
|
||||||
if (fn(region)) {
|
|
||||||
|
|
||||||
//push a copy of the function onto the stack with the region
|
|
||||||
lua_pushvalue(lua, -1);
|
|
||||||
lua_pushlightuserdata(lua, static_cast<void*>(®ion));
|
|
||||||
|
|
||||||
//call the function, 1 arg, 0 return
|
|
||||||
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) {
|
|
||||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
|
|
||||||
}
|
|
||||||
|
|
||||||
//signal to the container
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
//signal to the container
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
|
|
||||||
//pop the base copy of the function
|
|
||||||
lua_pop(lua, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RegionPagerLua::UnloadAll() {
|
|
||||||
//get the pager's function from the registry
|
|
||||||
lua_rawgeti(lua, LUA_REGISTRYINDEX, unloadRef);
|
|
||||||
|
|
||||||
//check if this function is available
|
|
||||||
if (lua_isnil(lua, -1)) {
|
|
||||||
lua_pop(lua, 1);
|
|
||||||
//remove the regions anyway
|
|
||||||
regionList.clear();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto& it : regionList) {
|
|
||||||
//push a copy of the function onto the stack with the region
|
|
||||||
lua_pushvalue(lua, -1);
|
|
||||||
lua_pushlightuserdata(lua, &it);
|
|
||||||
|
|
||||||
//call the function, 1 arg, 0 return
|
|
||||||
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) {
|
|
||||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//pop the base copy of the function
|
|
||||||
lua_pop(lua, 1);
|
|
||||||
|
|
||||||
//remove from memory
|
|
||||||
regionList.clear();
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "region_pager_base.hpp"
|
|
||||||
|
|
||||||
#include "lua.hpp"
|
|
||||||
|
|
||||||
#include <functional>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
//DOCS: set the lua hook before use
|
|
||||||
|
|
||||||
class RegionPagerLua : public RegionPagerBase {
|
|
||||||
public:
|
|
||||||
RegionPagerLua() = default;
|
|
||||||
~RegionPagerLua();
|
|
||||||
|
|
||||||
//region manipulation
|
|
||||||
Region* LoadRegion(int x, int y) override;
|
|
||||||
Region* SaveRegion(int x, int y) override;
|
|
||||||
Region* CreateRegion(int x, int y) override;
|
|
||||||
|
|
||||||
void UnloadIf(std::function<bool(Region const&)> fn) override;
|
|
||||||
void UnloadAll() override;
|
|
||||||
|
|
||||||
//accessors & mutators
|
|
||||||
lua_State* SetLuaState(lua_State* L) { return lua = L; }
|
|
||||||
lua_State* GetLuaState() { return lua; }
|
|
||||||
|
|
||||||
//utilities for the API
|
|
||||||
int SetLoadReference(int i) { return loadRef = i; }
|
|
||||||
int SetSaveReference(int i) { return saveRef = i; }
|
|
||||||
int SetCreateReference(int i) { return createRef = i; }
|
|
||||||
int SetUnloadReference(int i) { return unloadRef = i; }
|
|
||||||
|
|
||||||
int GetLoadReference() { return loadRef; }
|
|
||||||
int GetSaveReference() { return saveRef; }
|
|
||||||
int GetCreateReference() { return createRef; }
|
|
||||||
int GetUnloadReference() { return unloadRef; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
lua_State* lua = nullptr;
|
|
||||||
|
|
||||||
int loadRef = LUA_NOREF;
|
|
||||||
int saveRef = LUA_NOREF;
|
|
||||||
int createRef = LUA_NOREF;
|
|
||||||
int unloadRef = LUA_NOREF;
|
|
||||||
};
|
|
||||||
@@ -1,124 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#include "tile_sheet.hpp"
|
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
TileSheet& TileSheet::operator=(TileSheet const& rhs) {
|
|
||||||
//don't screw yourself
|
|
||||||
if (this == &rhs) {
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Free();
|
|
||||||
|
|
||||||
//Copy the other TileSheet's stuff
|
|
||||||
texture = rhs.texture;
|
|
||||||
clip = rhs.clip;
|
|
||||||
local = false;
|
|
||||||
countX = rhs.countX;
|
|
||||||
countY = rhs.countY;
|
|
||||||
}
|
|
||||||
|
|
||||||
TileSheet& TileSheet::operator=(TileSheet&& rhs) {
|
|
||||||
//don't screw yourself
|
|
||||||
if (this == &rhs) {
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
Free();
|
|
||||||
|
|
||||||
//Copy the other TileSheet's stuff
|
|
||||||
texture = rhs.texture;
|
|
||||||
clip = rhs.clip;
|
|
||||||
local = false;
|
|
||||||
countX = rhs.countX;
|
|
||||||
countY = rhs.countY;
|
|
||||||
|
|
||||||
rhs.texture = nullptr;
|
|
||||||
rhs.clip = {0, 0, 0, 0};
|
|
||||||
rhs.local = false;
|
|
||||||
rhs.countX = 0;
|
|
||||||
rhs.countY = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TileSheet::Load(SDL_Renderer* renderer, std::string fname, int tileWidth, int tileHeight) {
|
|
||||||
Image::Load(renderer, fname);
|
|
||||||
countX = clip.w / tileWidth;
|
|
||||||
countY = clip.h / tileHeight;
|
|
||||||
clip.w = tileWidth;
|
|
||||||
clip.h = tileHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_Texture* TileSheet::SetTexture(SDL_Texture* ptr, int tileWidth, int tileHeight) {
|
|
||||||
Image::SetTexture(ptr);
|
|
||||||
countX = clip.w / tileWidth;
|
|
||||||
countY = clip.h / tileHeight;
|
|
||||||
clip.w = tileWidth;
|
|
||||||
clip.h = tileHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TileSheet::Free() {
|
|
||||||
Image::Free();
|
|
||||||
countX = countY = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TileSheet::DrawLayerTo(SDL_Renderer* const renderer, Region* const region, int layer, int camX, int camY, double scaleX, double scaleY) {
|
|
||||||
//TODO: (2) empty
|
|
||||||
}
|
|
||||||
|
|
||||||
void TileSheet::DrawRegionTo(SDL_Renderer* const renderer, Region* const region, int camX, int camY, double scaleX, double scaleY) {
|
|
||||||
//NOTE: TileSheet is a friend class of Region
|
|
||||||
//reimplementing DrawTo() to improve performance (less indirection)
|
|
||||||
if (!texture) {
|
|
||||||
throw(std::logic_error("No image texture to draw"));
|
|
||||||
}
|
|
||||||
|
|
||||||
//the local variables
|
|
||||||
SDL_Rect sclip = {0, 0, clip.w, clip.h};
|
|
||||||
SDL_Rect dclip = {0, 0, Uint16(clip.w * scaleX), Uint16(clip.h * scaleY)};
|
|
||||||
Region::type_t tile = 0;
|
|
||||||
|
|
||||||
//for each tile
|
|
||||||
for (register int i = 0; i < REGION_WIDTH; ++i) {
|
|
||||||
for (register int j = 0; j < REGION_HEIGHT; ++j) {
|
|
||||||
for (register int k = 0; k < REGION_DEPTH; ++k) {
|
|
||||||
//get the value to skip expensive lookups
|
|
||||||
tile = region->tiles[i][j][k];
|
|
||||||
|
|
||||||
//0 is invisible
|
|
||||||
if (tile == 0) continue;
|
|
||||||
|
|
||||||
//set the sclip
|
|
||||||
sclip.x = (tile-1) % countX * clip.h;
|
|
||||||
sclip.y = (tile-1) / countX * clip.w;
|
|
||||||
|
|
||||||
//set the dclip
|
|
||||||
dclip.x = ((region->x + i) * clip.w - camX) * scaleX;
|
|
||||||
dclip.y = ((region->y + j) * clip.h - camY) * scaleY;
|
|
||||||
|
|
||||||
//draw
|
|
||||||
SDL_RenderCopy(renderer, texture, &sclip, &dclip);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "region.hpp"
|
|
||||||
|
|
||||||
#include "image.hpp"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
class TileSheet : public Image {
|
|
||||||
public:
|
|
||||||
TileSheet() = default;
|
|
||||||
TileSheet(TileSheet const& rhs) { *this = rhs; }
|
|
||||||
TileSheet(TileSheet&& rhs) { *this = std::move(rhs); }
|
|
||||||
TileSheet(SDL_Renderer* r, std::string fn, int tw, int th) { Load(r, fn, tw, th); }
|
|
||||||
TileSheet(SDL_Texture* p, int tw, int th) { SetTexture(p, tw, th); }
|
|
||||||
~TileSheet() = default;
|
|
||||||
|
|
||||||
TileSheet& operator=(TileSheet const&);
|
|
||||||
TileSheet& operator=(TileSheet&&);
|
|
||||||
|
|
||||||
void Load(SDL_Renderer*, std::string fname, int tileWidth, int tileHeight);
|
|
||||||
SDL_Texture* SetTexture(SDL_Texture*, int tileWidth, int tileHeight);
|
|
||||||
void Free() override;
|
|
||||||
|
|
||||||
void DrawLayerTo(SDL_Renderer* const renderer, Region* const region, int layer, int camX, int camY, double scaleX = 1.0, double scaleY = 1.0);
|
|
||||||
void DrawRegionTo(SDL_Renderer* const renderer, Region* const region, int camX, int camY, double scaleX = 1.0, double scaleY = 1.0);
|
|
||||||
|
|
||||||
//accessors
|
|
||||||
//DOCS: Reuse Image::clip for tile sizes
|
|
||||||
int GetCountX() { return countX; }
|
|
||||||
int GetCountY() { return countY; }
|
|
||||||
int GetTileW() { return clip.w; }
|
|
||||||
int GetTileH() { return clip.h; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
int countX = 0, countY = 0;
|
|
||||||
|
|
||||||
using Image::Load;
|
|
||||||
using Image::Create;
|
|
||||||
using Image::SetTexture;
|
|
||||||
using Image::SetClip;
|
|
||||||
using Image::SetClipX;
|
|
||||||
using Image::SetClipY;
|
|
||||||
using Image::SetClipW;
|
|
||||||
using Image::SetClipH;
|
|
||||||
};
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. packet_types ../gameplay ../map ../utilities
|
INCLUDES+=. packet_types ../global_defines ../utilities ../../TurtleGUI ../../TurtleMap
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. .. ../../gameplay ../../map ../../utilities
|
INCLUDES+=. .. ../../global_defines ../../utilities ../../../TurtleGUI ../../../TurtleMap
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
|||||||
@@ -34,15 +34,16 @@
|
|||||||
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 = 20160404;
|
constexpr int NETWORK_VERSION = 20161209;
|
||||||
|
|
||||||
union MaxPacket {
|
union MaxPacket {
|
||||||
CharacterPacket a;
|
BarrierPacket a;
|
||||||
ClientPacket b;
|
CharacterPacket b;
|
||||||
CreaturePacket c;
|
ClientPacket c;
|
||||||
RegionPacket d;
|
CreaturePacket d;
|
||||||
ServerPacket e;
|
RegionPacket e;
|
||||||
TextPacket f;
|
ServerPacket f;
|
||||||
|
TextPacket g;
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr int MAX_PACKET_SIZE = sizeof(MaxPacket);
|
constexpr int MAX_PACKET_SIZE = sizeof(MaxPacket);
|
||||||
|
|||||||
@@ -142,25 +142,6 @@ enum class SerialPacketType {
|
|||||||
|
|
||||||
FORMAT_END_CREATURE = 599,
|
FORMAT_END_CREATURE = 599,
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
//BarrierPacket
|
|
||||||
// barrier index,
|
|
||||||
// bounds,
|
|
||||||
// roomIndex, origin, motion
|
|
||||||
// status
|
|
||||||
//-------------------------
|
|
||||||
|
|
||||||
FORMAT_COMBAT = 700,
|
|
||||||
|
|
||||||
BARRIER_UPDATE = 701,
|
|
||||||
|
|
||||||
BARRIER_CREATE = 702,
|
|
||||||
BARRIER_UNLOAD = 703,
|
|
||||||
|
|
||||||
QUERY_BARRIER_EXISTS = 704,
|
|
||||||
|
|
||||||
FORMAT_END_COMBAT = 799,
|
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//TextPacket
|
//TextPacket
|
||||||
// name, text
|
// name, text
|
||||||
@@ -184,6 +165,28 @@ enum class SerialPacketType {
|
|||||||
|
|
||||||
FORMAT_END_TEXT = 699,
|
FORMAT_END_TEXT = 699,
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//BarrierPacket
|
||||||
|
// barrier index,
|
||||||
|
// bounds,
|
||||||
|
// roomIndex, origin, motion
|
||||||
|
// status
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
FORMAT_BARRIER = 700,
|
||||||
|
|
||||||
|
BARRIER_UPDATE = 701,
|
||||||
|
|
||||||
|
BARRIER_CREATE = 702,
|
||||||
|
BARRIER_UNLOAD = 703,
|
||||||
|
|
||||||
|
QUERY_BARRIER_EXISTS = 704,
|
||||||
|
|
||||||
|
BARRIER_ENTRY = 705,
|
||||||
|
BARRIER_EXIT = 706,
|
||||||
|
|
||||||
|
FORMAT_END_BARRIER = 799,
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//not used
|
//not used
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|||||||
@@ -70,13 +70,13 @@ void serializePacket(void* buffer, SerialPacketBase* packet) {
|
|||||||
serializeCreature(buffer, static_cast<CreaturePacket*>(packet));
|
serializeCreature(buffer, static_cast<CreaturePacket*>(packet));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BOUNDS(packet->type, SerialPacketType::FORMAT_COMBAT, SerialPacketType::FORMAT_END_COMBAT)) {
|
|
||||||
serializeBarrier(buffer, static_cast<BarrierPacket*>(packet));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (BOUNDS(packet->type, SerialPacketType::FORMAT_TEXT, SerialPacketType::FORMAT_END_TEXT)) {
|
if (BOUNDS(packet->type, SerialPacketType::FORMAT_TEXT, SerialPacketType::FORMAT_END_TEXT)) {
|
||||||
serializeText(buffer, static_cast<TextPacket*>(packet));
|
serializeText(buffer, static_cast<TextPacket*>(packet));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (BOUNDS(packet->type, SerialPacketType::FORMAT_BARRIER, SerialPacketType::FORMAT_END_BARRIER)) {
|
||||||
|
serializeBarrier(buffer, static_cast<BarrierPacket*>(packet));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void deserializePacket(void* buffer, SerialPacketBase* packet) {
|
void deserializePacket(void* buffer, SerialPacketBase* packet) {
|
||||||
@@ -104,11 +104,11 @@ void deserializePacket(void* buffer, SerialPacketBase* packet) {
|
|||||||
deserializeCreature(buffer, static_cast<CreaturePacket*>(packet));
|
deserializeCreature(buffer, static_cast<CreaturePacket*>(packet));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BOUNDS(type, SerialPacketType::FORMAT_COMBAT, SerialPacketType::FORMAT_END_COMBAT)) {
|
|
||||||
deserializeBarrier(buffer, static_cast<BarrierPacket*>(packet));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (BOUNDS(type, SerialPacketType::FORMAT_TEXT, SerialPacketType::FORMAT_END_TEXT)) {
|
if (BOUNDS(type, SerialPacketType::FORMAT_TEXT, SerialPacketType::FORMAT_END_TEXT)) {
|
||||||
deserializeText(buffer, static_cast<TextPacket*>(packet));
|
deserializeText(buffer, static_cast<TextPacket*>(packet));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (BOUNDS(type, SerialPacketType::FORMAT_BARRIER, SerialPacketType::FORMAT_END_BARRIER)) {
|
||||||
|
deserializeBarrier(buffer, static_cast<BarrierPacket*>(packet));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <type_traits>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
class BoundingBox {
|
|
||||||
public:
|
|
||||||
//This is explicitly a POD
|
|
||||||
int x, y;
|
|
||||||
int w, h;
|
|
||||||
|
|
||||||
BoundingBox() = default;
|
|
||||||
BoundingBox(int i, int j): x(i), y(j), w(0), h(0) {};
|
|
||||||
BoundingBox(int i, int j, int k, int l): x(i), y(j), w(k), h(l) {};
|
|
||||||
~BoundingBox() = default;
|
|
||||||
BoundingBox& operator=(BoundingBox const&) = default;
|
|
||||||
|
|
||||||
int Size() {
|
|
||||||
return std::max(w*h,0);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CheckOverlap(BoundingBox rhs) {
|
|
||||||
return !(
|
|
||||||
x >= rhs.x + rhs.w ||
|
|
||||||
y >= rhs.y + rhs.h ||
|
|
||||||
rhs.x >= x + w ||
|
|
||||||
rhs.y >= y + h);
|
|
||||||
}
|
|
||||||
|
|
||||||
BoundingBox CalcOverlap(BoundingBox rhs) {
|
|
||||||
if (!CheckOverlap(rhs)) {
|
|
||||||
return {0, 0, 0, 0};
|
|
||||||
}
|
|
||||||
BoundingBox ret;
|
|
||||||
ret.x = std::max(x, rhs.x);
|
|
||||||
ret.y = std::max(y, rhs.y);
|
|
||||||
ret.w = std::min(x+w, rhs.x+rhs.w) - ret.x;
|
|
||||||
ret.h = std::min(y+h, rhs.y+rhs.h) - ret.y;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
//This is explicitly a POD
|
|
||||||
static_assert(std::is_pod<BoundingBox>::value, "BoundingBox is not a POD");
|
|
||||||
|
|
||||||
#include "vector2.hpp"
|
|
||||||
|
|
||||||
//operators
|
|
||||||
inline BoundingBox operator+(BoundingBox b, Vector2 v) {
|
|
||||||
return {b.x + (int)v.x, b.y + (int)v.y, b.w, b.h};
|
|
||||||
}
|
|
||||||
inline BoundingBox operator+(Vector2 v, BoundingBox b) {
|
|
||||||
return b + v;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,125 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 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.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
//DOCS: this is a generic CSV reading tool
|
||||||
|
//DOCS: empty lines and comment lines begining with '#' are ignored
|
||||||
|
//DOCS: whitespace characters are valid field values
|
||||||
|
//DOCS: if the file is invalid, then the behavior is undefined
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <cstring>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
//define the container types
|
||||||
|
template<int N>
|
||||||
|
using CSVElement = std::array<std::string, N>;
|
||||||
|
|
||||||
|
template<int N>
|
||||||
|
using CSVObject = std::vector<CSVElement<N>>;
|
||||||
|
|
||||||
|
//read a file into an object
|
||||||
|
template<int N>
|
||||||
|
CSVObject<N> readCSV(std::string fname, char delim = ',') {
|
||||||
|
//open the file
|
||||||
|
std::ifstream is(fname);
|
||||||
|
|
||||||
|
if (!is.is_open()) {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Failed to open file: " << fname;
|
||||||
|
throw(std::runtime_error(msg.str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
//build the scanf format
|
||||||
|
std::ostringstream format;
|
||||||
|
format << "%[^\0" << delim << "]";
|
||||||
|
|
||||||
|
//read and store each record (one per line)
|
||||||
|
CSVObject<N> object;
|
||||||
|
while(!is.eof()) {
|
||||||
|
//get a line
|
||||||
|
std::string tmpLine;
|
||||||
|
getline(is, tmpLine);
|
||||||
|
|
||||||
|
//skip blank and comment lines
|
||||||
|
if (tmpLine.size() == 0 || tmpLine[0] == '#') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//read and store each field
|
||||||
|
CSVElement<N> record;
|
||||||
|
for (int i = 0; i < N; ++i) {
|
||||||
|
//get a field
|
||||||
|
char tmpField[256];
|
||||||
|
memset(tmpField, 0, 256);
|
||||||
|
|
||||||
|
sscanf(tmpLine.c_str(), format.str().c_str(), tmpField);
|
||||||
|
|
||||||
|
//prune the input
|
||||||
|
int len = std::min(strlen(tmpField)+1, tmpLine.size());
|
||||||
|
tmpLine = tmpLine.substr(len);
|
||||||
|
|
||||||
|
//store the field
|
||||||
|
record[i] = tmpField;
|
||||||
|
}
|
||||||
|
|
||||||
|
object.push_back(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
//finally, close the file
|
||||||
|
is.close();
|
||||||
|
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<int N>
|
||||||
|
void writeCSV(std::string fname, CSVObject<N> const& object, char delim = ',') {
|
||||||
|
//open the file
|
||||||
|
std::ofstream os(fname);
|
||||||
|
|
||||||
|
if (!os.is_open()) {
|
||||||
|
std::ostringstream msg;
|
||||||
|
msg << "Failed to open file: " << fname;
|
||||||
|
throw(std::runtime_error(msg.str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
//write each record, one at a time
|
||||||
|
for(auto& record : object) {
|
||||||
|
//write each field, one at a time
|
||||||
|
for (int i = 0; i < N; i++) {
|
||||||
|
os << record[i];
|
||||||
|
|
||||||
|
//print delimiter
|
||||||
|
if (i != N -1) {
|
||||||
|
os << delim;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
os << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
//finish
|
||||||
|
os.close();
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
/* Copyright: (c) Kayne Ruse 2016
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -19,38 +19,42 @@
|
|||||||
* 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 "text_box.hpp"
|
#include "file_hash.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <fstream>
|
||||||
|
|
||||||
TextBox::TextBox() {
|
//hash a byte array into a 32-bit integer
|
||||||
//
|
unsigned fnv_hash_1a_32(void *key, int len) {
|
||||||
}
|
unsigned char *p = static_cast<unsigned char*>(key);
|
||||||
|
unsigned h = 0x811c9dc5;
|
||||||
TextBox::~TextBox() {
|
for (int i = 0; i < len; i++) {
|
||||||
//
|
h = ( h ^ p[i] ) * 0x01000193;
|
||||||
}
|
|
||||||
|
|
||||||
void TextBox::DrawTo(SDL_Renderer* renderer, int posX, int posY, int pointSize) {
|
|
||||||
for (std::list<TextLine>::iterator it = lineList.begin(); it != lineList.end(); it++) {
|
|
||||||
it->DrawTo(renderer, posX, posY);
|
|
||||||
posY += pointSize;
|
|
||||||
}
|
}
|
||||||
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextBox::PushLine(SDL_Renderer* renderer, TTF_Font* font, std::string str, SDL_Color color) {
|
int getFileHash(std::string fname) {
|
||||||
lineList.emplace_front(renderer, font, str, color);
|
std::ifstream is(fname, std::ios::in | std::ios::binary);
|
||||||
}
|
|
||||||
|
|
||||||
void TextBox::PopLine(int num) {
|
//if the file doesn't exist, return a hash of -1
|
||||||
//prevent underflow
|
if (!is.is_open()) {
|
||||||
num < lineList.size() ? num : lineList.size();
|
return -1;
|
||||||
|
|
||||||
for (int i = 0; i < num; ++i) {
|
|
||||||
lineList.pop_back();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void TextBox::ClearLines() {
|
//get the file size
|
||||||
lineList.clear();
|
is.seekg(0, std::ios_base::end);
|
||||||
|
int size = is.tellg();
|
||||||
|
is.seekg(0);
|
||||||
|
|
||||||
|
//create a buffer of that size
|
||||||
|
char buffer[size];
|
||||||
|
|
||||||
|
//load the data
|
||||||
|
is.read(buffer, size);
|
||||||
|
|
||||||
|
//cleanup
|
||||||
|
is.close();
|
||||||
|
|
||||||
|
//finally, return the hash value
|
||||||
|
return fnv_hash_1a_32(buffer, size);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
int getFileHash(std::string fname);
|
||||||
@@ -1,111 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2016
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <type_traits>
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
class Vector2 {
|
|
||||||
public:
|
|
||||||
double x, y;
|
|
||||||
|
|
||||||
Vector2() = default;
|
|
||||||
Vector2(double i, double j): x(i), y(j) {};
|
|
||||||
~Vector2() = default;
|
|
||||||
Vector2& operator=(Vector2 const&) = default;
|
|
||||||
|
|
||||||
double Length() const {
|
|
||||||
return sqrt(x*x+y*y);
|
|
||||||
}
|
|
||||||
double SquaredLength() const {
|
|
||||||
return x*x+y*y;
|
|
||||||
}
|
|
||||||
void Normalize() {
|
|
||||||
double l = Length();
|
|
||||||
if (l == 0)
|
|
||||||
throw(std::domain_error("Divide by zero"));
|
|
||||||
x /= l;
|
|
||||||
y /= l;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Arithmetic operators
|
|
||||||
Vector2 operator+(Vector2 v) const {
|
|
||||||
Vector2 ret;
|
|
||||||
ret.x = x + v.x;
|
|
||||||
ret.y = y + v.y;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
Vector2 operator-(Vector2 v) const {
|
|
||||||
Vector2 ret;
|
|
||||||
ret.x = x - v.x;
|
|
||||||
ret.y = y - v.y;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
Vector2 operator*(Vector2 v) const {
|
|
||||||
Vector2 ret;
|
|
||||||
ret.x = x * v.x;
|
|
||||||
ret.y = y * v.y;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
Vector2 operator*(double d) const {
|
|
||||||
Vector2 ret;
|
|
||||||
ret.x = x * d;
|
|
||||||
ret.y = y * d;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector2 operator/(Vector2 v) {
|
|
||||||
if (!v.x || !v.y)
|
|
||||||
throw(std::domain_error("Divide by zero"));
|
|
||||||
Vector2 ret;
|
|
||||||
ret.x = x / v.x;
|
|
||||||
ret.y = y / v.y;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
Vector2 operator/(double d) {
|
|
||||||
if (!d)
|
|
||||||
throw(std::domain_error("Divide by zero"));
|
|
||||||
Vector2 ret;
|
|
||||||
ret.x = x / d;
|
|
||||||
ret.y = y / d;
|
|
||||||
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); }
|
|
||||||
|
|
||||||
//member templates (curry the above operators)
|
|
||||||
template<typename T> Vector2 operator+=(T t) { return *this = *this + t; }
|
|
||||||
template<typename T> Vector2 operator-=(T t) { return *this = *this - t; }
|
|
||||||
template<typename T> Vector2 operator*=(T t) { return *this = *this * t; }
|
|
||||||
template<typename T> Vector2 operator/=(T t) { return *this = *this / t; }
|
|
||||||
template<typename T> bool operator==(T t) { return (x == t && y == t); }
|
|
||||||
template<typename T> bool operator!=(T t) { return (x != t || y != t); }
|
|
||||||
};
|
|
||||||
|
|
||||||
//This is explicitly a POD
|
|
||||||
static_assert(std::is_pod<Vector2>::value, "Vector2 is not a POD");
|
|
||||||
+18
-14
@@ -15,21 +15,25 @@ 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)
|
(a public server "Island Home" is provided by default)
|
||||||
2. To join a server, your player information must be input into rsc/config.cfg
|
2. To play, run client.exe
|
||||||
(NOTE: This process will be streamlined later)
|
3. Your unique information should be inputted into the lobby screen, replacing
|
||||||
3. To change the config settings, open rsc/config.cfg
|
the default values.
|
||||||
4. These settings must be unique for each player:
|
4. There are currently two options for avatars:
|
||||||
|
|
||||||
* client.username
|
* character1.png #male
|
||||||
* client.handle
|
* character2.png #female
|
||||||
|
|
||||||
5. There are currently two options for 'client.avatar':
|
5. Select a server, and click join.
|
||||||
|
|
||||||
|
-------------------------
|
||||||
|
Linux Users
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
Before running this on linux, you may need to run the following commands:
|
||||||
|
|
||||||
|
sudo apt-get install libsdl2-net-2.0-0
|
||||||
|
sudo apt-get install libsdl2-image-2.0-0
|
||||||
|
sudo apt-get install libsdl2-ttf-2.0-0
|
||||||
|
|
||||||
* client.avatar = character1.png #male
|
|
||||||
* client.avatar = character2.png #female
|
|
||||||
|
|
||||||
6. When you've correctly set these values, run client.exe, and select 'Start'
|
|
||||||
from the main menu; this displays the list of available servers.
|
|
||||||
7. Select the name of a server (default is 'Public') and select 'Join'.
|
|
||||||
8. Welcome to Tortuga, enjoy your stay.
|
|
||||||
|
|||||||
@@ -7,7 +7,9 @@
|
|||||||
OUTDIR=out
|
OUTDIR=out
|
||||||
BINDIR=bin
|
BINDIR=bin
|
||||||
|
|
||||||
all: $(OUTDIR) binary
|
all: $(OUTDIR) dll
|
||||||
|
$(MAKE) -C TurtleGUI
|
||||||
|
$(MAKE) -C TurtleMap
|
||||||
$(MAKE) -C common
|
$(MAKE) -C common
|
||||||
$(MAKE) -C server
|
$(MAKE) -C server
|
||||||
$(MAKE) -C client
|
$(MAKE) -C client
|
||||||
@@ -15,7 +17,9 @@ all: $(OUTDIR) binary
|
|||||||
debug: export CXXFLAGS+=-g
|
debug: export CXXFLAGS+=-g
|
||||||
debug: clean all
|
debug: clean all
|
||||||
|
|
||||||
|
ifeq ($(OS),Windows_NT)
|
||||||
release: export CXXFLAGS+=-static-libgcc -static-libstdc++
|
release: export CXXFLAGS+=-static-libgcc -static-libstdc++
|
||||||
|
endif
|
||||||
release: clean all package
|
release: clean all package
|
||||||
|
|
||||||
#For use on my machine ONLY
|
#For use on my machine ONLY
|
||||||
@@ -27,7 +31,7 @@ else ifeq ($(shell uname), Linux)
|
|||||||
tar -C $(OUTDIR) -zcvf Tortuga-linux.tar client server ../rsc ../copyright.txt ../instructions.txt
|
tar -C $(OUTDIR) -zcvf Tortuga-linux.tar client server ../rsc ../copyright.txt ../instructions.txt
|
||||||
endif
|
endif
|
||||||
|
|
||||||
binary: $(OUTDIR)
|
dll: $(OUTDIR)
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
xcopy /Y $(BINDIR)\\*.dll $(OUTDIR)
|
xcopy /Y $(BINDIR)\\*.dll $(OUTDIR)
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#TODO: (9) split this file in two, one for each program
|
#TODO: (9) split this file in two, one for each program
|
||||||
|
|
||||||
#server specific settings
|
#server specific settings
|
||||||
|
server.home = island.krgamestudios.com
|
||||||
server.host = 255.255.255.255
|
server.host = 255.255.255.255
|
||||||
server.port = 21795
|
server.port = 21795
|
||||||
server.name = local
|
server.name = local
|
||||||
@@ -14,6 +15,7 @@ server.dbname = database.db
|
|||||||
#client.screen.f = false #NOTE: fullscreen option is currently disabled
|
#client.screen.f = false #NOTE: fullscreen option is currently disabled
|
||||||
|
|
||||||
client.username = username
|
client.username = username
|
||||||
|
client.password = password
|
||||||
client.handle = handle
|
client.handle = handle
|
||||||
client.avatar = character2.png
|
client.avatar = character2.png
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
#Format (4 columns): "name", type, "sprite.png", stackable
|
||||||
|
"Sword",weapon,"sword.png",false
|
||||||
|
"Staff",weapon,"staff.png",false
|
||||||
|
"Dagger",weapon,"dagger.png",false
|
||||||
|
"Potion",consumable,"potion.png",true
|
||||||
|
Can't render this file because it contains an unexpected character in line 1 and column 22.
|
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 1009 B |
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 316 B |
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 39 KiB |
@@ -60,12 +60,16 @@ function doorUtility.CreateDoorPair(handle, roomOne, Xone, Yone, roomTwo, Xtwo,
|
|||||||
|
|
||||||
--move the character
|
--move the character
|
||||||
characterAPI.SetRoom(entity, roomTwo)
|
characterAPI.SetRoom(entity, roomTwo)
|
||||||
characterAPI.SetOrigin(entity, Xtwo, Ytwo-16)
|
characterAPI.SetOrigin(entity, Xtwo, Ytwo+16)
|
||||||
networkAPI.PumpCharacterUpdate(entity)
|
networkAPI.PumpCharacterUpdate(entity)
|
||||||
|
|
||||||
--disable the other trigger
|
--disable the other trigger
|
||||||
local triggerTwo = triggerManagerAPI.FindTrigger(roomAPI.GetTriggerMgr(roomTwo), handle)
|
local triggerTwo = triggerManagerAPI.FindTrigger(roomAPI.GetTriggerMgr(roomTwo), handle)
|
||||||
triggerAPI.PushExclusionEntity(triggerTwo, entity)
|
triggerAPI.PushExclusionEntity(triggerTwo, entity)
|
||||||
|
|
||||||
|
--bookkeeping: remove from the original trigger's exclusion list
|
||||||
|
local triggerOne = triggerManagerAPI.FindTrigger(roomAPI.GetTriggerMgr(roomOne), handle)
|
||||||
|
triggerAPI.RemoveExclusionEntity(triggerOne, entity)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function scriptTwo(entity)
|
local function scriptTwo(entity)
|
||||||
@@ -73,12 +77,16 @@ function doorUtility.CreateDoorPair(handle, roomOne, Xone, Yone, roomTwo, Xtwo,
|
|||||||
|
|
||||||
--move the character
|
--move the character
|
||||||
characterAPI.SetRoom(entity, roomOne)
|
characterAPI.SetRoom(entity, roomOne)
|
||||||
characterAPI.SetOrigin(entity, Xone, Yone-16) --NOTE: the 16 pixel margin for presentation
|
characterAPI.SetOrigin(entity, Xone, Yone+16) --NOTE: +16 should prevent double collision issues
|
||||||
networkAPI.PumpCharacterUpdate(entity)
|
networkAPI.PumpCharacterUpdate(entity)
|
||||||
|
|
||||||
--disable the other trigger
|
--disable the other trigger
|
||||||
local triggerOne = triggerManagerAPI.FindTrigger(roomAPI.GetTriggerMgr(roomOne), handle)
|
local triggerOne = triggerManagerAPI.FindTrigger(roomAPI.GetTriggerMgr(roomOne), handle)
|
||||||
triggerAPI.PushExclusionEntity(triggerOne, entity)
|
triggerAPI.PushExclusionEntity(triggerOne, entity)
|
||||||
|
|
||||||
|
--bookkeeping: remove from the original trigger's exclusion list
|
||||||
|
local triggerTwo = triggerManagerAPI.FindTrigger(roomAPI.GetTriggerMgr(roomTwo), handle)
|
||||||
|
triggerAPI.RemoveExclusionEntity(triggerTwo, entity)
|
||||||
end
|
end
|
||||||
|
|
||||||
--create the triggers proper
|
--create the triggers proper
|
||||||
@@ -86,4 +94,4 @@ function doorUtility.CreateDoorPair(handle, roomOne, Xone, Yone, roomTwo, Xtwo,
|
|||||||
doorUtility.CreateTrigger(handle, roomTwo, Xtwo, Ytwo, scriptTwo)
|
doorUtility.CreateTrigger(handle, roomTwo, Xtwo, Ytwo, scriptTwo)
|
||||||
end
|
end
|
||||||
|
|
||||||
return doorUtility
|
return doorUtility
|
||||||
|
|||||||
@@ -20,13 +20,23 @@
|
|||||||
* distribution.
|
* distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
-------------------------
|
||||||
|
--defines
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
PRAGMA foreign_keys = ON;
|
||||||
|
|
||||||
|
-------------------------
|
||||||
|
--table definitions
|
||||||
|
-------------------------
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS UserAccounts (
|
CREATE TABLE IF NOT EXISTS UserAccounts (
|
||||||
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
username varchar(100) UNIQUE, --TODO: (3) Swap username for email address
|
username varchar(100) UNIQUE, --TODO: (3) Swap username for email address
|
||||||
|
|
||||||
--server-client security
|
--server-client security
|
||||||
-- passhash varchar(100),
|
passhash varchar(100),
|
||||||
-- passsalt varchar(100),
|
passsalt varchar(100),
|
||||||
|
|
||||||
--server controls
|
--server controls
|
||||||
blacklisted BIT DEFAULT 0,
|
blacklisted BIT DEFAULT 0,
|
||||||
@@ -39,8 +49,8 @@ CREATE TABLE IF NOT EXISTS LiveCharacters (
|
|||||||
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
|
||||||
--metadata
|
--metadata
|
||||||
owner INTEGER REFERENCES Accounts(uid),
|
owner INTEGER REFERENCES UserAccounts(uid),
|
||||||
handle varchar(100) UNIQUE,
|
handle varchar(100),
|
||||||
avatar varchar(100),
|
avatar varchar(100),
|
||||||
birth timestamp NOT NULL DEFAULT (datetime()),
|
birth timestamp NOT NULL DEFAULT (datetime()),
|
||||||
|
|
||||||
@@ -48,59 +58,8 @@ CREATE TABLE IF NOT EXISTS LiveCharacters (
|
|||||||
roomIndex INTEGER DEFAULT 0,
|
roomIndex INTEGER DEFAULT 0,
|
||||||
originX INTEGER DEFAULT 0,
|
originX INTEGER DEFAULT 0,
|
||||||
originY INTEGER DEFAULT 0,
|
originY INTEGER DEFAULT 0,
|
||||||
boundsX INTEGER DEFAULT 0,
|
|
||||||
boundsY INTEGER DEFAULT 0,
|
|
||||||
boundsW INTEGER DEFAULT 0,
|
|
||||||
boundsH INTEGER DEFAULT 0
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DeadCharacters (
|
--combat stats
|
||||||
uid INTEGER PRIMARY KEY,
|
|
||||||
|
|
||||||
--metadata
|
|
||||||
owner INTEGER REFERENCES Accounts(uid),
|
|
||||||
handle varchar(100),
|
|
||||||
avatar varchar(100),
|
|
||||||
birth timestamp NOT NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS LiveMonsters (
|
|
||||||
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
|
|
||||||
--metadata
|
|
||||||
handle varchar(100) UNIQUE,
|
|
||||||
avatar varchar(100),
|
|
||||||
|
|
||||||
--actions
|
|
||||||
-- script
|
|
||||||
|
|
||||||
--physically exists in the world
|
|
||||||
roomIndex INTEGER DEFAULT 0,
|
|
||||||
originX INTEGER DEFAULT 0,
|
|
||||||
originY INTEGER DEFAULT 0,
|
|
||||||
boundsX INTEGER DEFAULT 0,
|
|
||||||
boundsY INTEGER DEFAULT 0,
|
|
||||||
boundsW INTEGER DEFAULT 0,
|
|
||||||
boundsH INTEGER DEFAULT 0
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DeadMonsters (
|
|
||||||
uid INTEGER PRIMARY KEY,
|
|
||||||
|
|
||||||
--metadata
|
|
||||||
handle varchar(100) UNIQUE,
|
|
||||||
avatar varchar(100)
|
|
||||||
);
|
|
||||||
|
|
||||||
-------------------------
|
|
||||||
--Utility tables
|
|
||||||
-------------------------
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS StatisticSets (
|
|
||||||
--metadata
|
|
||||||
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
|
|
||||||
--general use statistics
|
|
||||||
level INTEGER DEFAULT 0,
|
level INTEGER DEFAULT 0,
|
||||||
exp INTEGER DEFAULT 0,
|
exp INTEGER DEFAULT 0,
|
||||||
maxHP INTEGER DEFAULT 0,
|
maxHP INTEGER DEFAULT 0,
|
||||||
@@ -111,48 +70,53 @@ CREATE TABLE IF NOT EXISTS StatisticSets (
|
|||||||
defence INTEGER DEFAULT 0,
|
defence INTEGER DEFAULT 0,
|
||||||
intelligence INTEGER DEFAULT 0,
|
intelligence INTEGER DEFAULT 0,
|
||||||
resistance INTEGER DEFAULT 0,
|
resistance INTEGER DEFAULT 0,
|
||||||
|
accuracy INTEGER DEFAULT 0,
|
||||||
|
evasion INTEGER DEFAULT 0,
|
||||||
speed INTEGER DEFAULT 0,
|
speed INTEGER DEFAULT 0,
|
||||||
accuracy REAL DEFAULT 0.0,
|
luck INTEGER DEFAULT 0
|
||||||
evasion REAL DEFAULT 0.0,
|
|
||||||
luck REAL DEFAULT 0.0
|
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS InWorldItems (
|
CREATE TABLE IF NOT EXISTS DeadCharacters (
|
||||||
|
uid INTEGER PRIMARY KEY,
|
||||||
|
|
||||||
--metadata
|
--metadata
|
||||||
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
owner INTEGER REFERENCES UserAccounts(uid),
|
||||||
itemType INTEGER,
|
handle varchar(100),
|
||||||
|
avatar varchar(100),
|
||||||
|
birth timestamp NOT NULL,
|
||||||
|
death timestamp NOT NULL DEFAULT (datetime()),
|
||||||
|
|
||||||
--position in the world
|
--combat stats
|
||||||
roomIndex INTEGER DEFAULT 0,
|
level INTEGER DEFAULT 0,
|
||||||
originX INTEGER DEFAULT 0,
|
exp INTEGER DEFAULT 0,
|
||||||
originY INTEGER DEFAULT 0,
|
maxHP INTEGER DEFAULT 0,
|
||||||
|
maxMP INTEGER DEFAULT 0,
|
||||||
--unique information
|
attack INTEGER DEFAULT 0,
|
||||||
stackSize INTEGER DEFAULT 0,
|
defence INTEGER DEFAULT 0,
|
||||||
durability INTEGER DEFAULT 0,
|
intelligence INTEGER DEFAULT 0,
|
||||||
stats INTEGER REFERENCES StatisticSets(uid)
|
resistance INTEGER DEFAULT 0,
|
||||||
|
accuracy INTEGER DEFAULT 0,
|
||||||
|
evasion INTEGER DEFAULT 0,
|
||||||
|
speed INTEGER DEFAULT 0,
|
||||||
|
luck INTEGER DEFAULT 0
|
||||||
);
|
);
|
||||||
|
|
||||||
|
-------------------------
|
||||||
|
--global tables
|
||||||
|
-------------------------
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS InventoryItems (
|
CREATE TABLE IF NOT EXISTS InventoryItems (
|
||||||
--metadata
|
--metadata
|
||||||
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
owner INTEGER REFERENCES Characters(uid),
|
name varchar(100) UNIQUE,
|
||||||
itemType INTEGER,
|
type varchar(100), --tmp type
|
||||||
|
|
||||||
--unique information
|
--unique information
|
||||||
stackSize INTEGER DEFAULT 0,
|
durability INTEGER DEFAULT 0
|
||||||
durability INTEGER DEFAULT 0,
|
|
||||||
stats INTEGER REFERENCES StatisticSets(uid)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS WornEquipment (
|
-------------------------
|
||||||
--metadata
|
--member tables
|
||||||
uid INTEGER PRIMARY KEY AUTOINCREMENT,
|
-------------------------
|
||||||
owner INTEGER REFERENCES Characters(uid),
|
|
||||||
itemType INTEGER,
|
|
||||||
|
|
||||||
--unique information
|
--TODO
|
||||||
durability INTEGER DEFAULT 0,
|
|
||||||
stats INTEGER REFERENCES StatisticSets(uid)
|
|
||||||
--attached script?
|
|
||||||
);
|
|
||||||
@@ -52,15 +52,17 @@ static int getTag(lua_State* L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int setInstance(lua_State* L) {
|
/*
|
||||||
|
static int setBattleIndex(lua_State* L) {
|
||||||
BarrierData* barrier = static_cast<BarrierData*>(lua_touserdata(L, 1));
|
BarrierData* barrier = static_cast<BarrierData*>(lua_touserdata(L, 1));
|
||||||
barrier->SetInstanceIndex(lua_tointeger(L, 2));
|
barrier->SetBattleIndex(lua_tointeger(L, 2));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
static int getInstance(lua_State* L) {
|
static int getBattleIndex(lua_State* L) {
|
||||||
BarrierData* barrier = static_cast<BarrierData*>(lua_touserdata(L, 1));
|
BarrierData* barrier = static_cast<BarrierData*>(lua_touserdata(L, 1));
|
||||||
lua_pushinteger(L, barrier->GetInstanceIndex());
|
lua_pushinteger(L, barrier->GetBattleIndex());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,8 +83,8 @@ static const luaL_Reg barrierLib[] = {
|
|||||||
{"GetScript", getScript},
|
{"GetScript", getScript},
|
||||||
{"SetTag", setTag},
|
{"SetTag", setTag},
|
||||||
{"GetTag", getTag},
|
{"GetTag", getTag},
|
||||||
{"SetInstance", setInstance},
|
// {"SetBattleIndex", setBattleIndex},
|
||||||
{"GetInstance", getInstance},
|
{"GetBattleIndex", getBattleIndex},
|
||||||
{"SetStatus", setStatus},
|
{"SetStatus", setStatus},
|
||||||
{"GetStatus", getStatus},
|
{"GetStatus", getStatus},
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
@@ -28,8 +28,15 @@
|
|||||||
BarrierData::BarrierData(int i):
|
BarrierData::BarrierData(int i):
|
||||||
Entity::Entity("barrier")
|
Entity::Entity("barrier")
|
||||||
{
|
{
|
||||||
instanceIndex = i;
|
battleIndex = i;
|
||||||
memset(status, 0, sizeof(int) * 8);
|
memset(status, 0, sizeof(int) * 8);
|
||||||
|
|
||||||
|
SetBounds({
|
||||||
|
BARRIER_BOUNDS_X,
|
||||||
|
BARRIER_BOUNDS_Y,
|
||||||
|
BARRIER_BOUNDS_WIDTH,
|
||||||
|
BARRIER_BOUNDS_HEIGHT
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
BarrierData::~BarrierData() {
|
BarrierData::~BarrierData() {
|
||||||
@@ -39,6 +46,7 @@ BarrierData::~BarrierData() {
|
|||||||
int BarrierData::Update(lua_State* L) {
|
int BarrierData::Update(lua_State* L) {
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
//NOTE: this is here mostly for the "barrier tick" effect
|
||||||
if (scriptRef != LUA_NOREF) {
|
if (scriptRef != LUA_NOREF) {
|
||||||
//Call the script reference
|
//Call the script reference
|
||||||
lua_pushinteger(L, scriptRef);
|
lua_pushinteger(L, scriptRef);
|
||||||
@@ -54,6 +62,7 @@ int BarrierData::Update(lua_State* L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ret += lua_tonumber(L, -1);
|
ret += lua_tonumber(L, -1);
|
||||||
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity::Update();
|
Entity::Update();
|
||||||
@@ -77,12 +86,12 @@ std::string BarrierData::GetTag(std::string key) {
|
|||||||
return tags[key];
|
return tags[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
int BarrierData::SetInstanceIndex(int i) {
|
int BarrierData::SetBattleIndex(int i) {
|
||||||
return instanceIndex = i;
|
return battleIndex = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BarrierData::GetInstanceIndex() const {
|
int BarrierData::GetBattleIndex() const {
|
||||||
return instanceIndex;
|
return battleIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BarrierData::SetStatus(int k, int v) {
|
int BarrierData::SetStatus(int k, int v) {
|
||||||
@@ -21,6 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "barrier_defines.hpp"
|
||||||
#include "entity.hpp"
|
#include "entity.hpp"
|
||||||
|
|
||||||
#include "lua.hpp"
|
#include "lua.hpp"
|
||||||
@@ -30,7 +31,7 @@
|
|||||||
|
|
||||||
class BarrierData: public Entity {
|
class BarrierData: public Entity {
|
||||||
public:
|
public:
|
||||||
BarrierData(int instanceIndex);
|
BarrierData(int battleIndex);
|
||||||
~BarrierData();
|
~BarrierData();
|
||||||
|
|
||||||
int Update(lua_State*);
|
int Update(lua_State*);
|
||||||
@@ -38,11 +39,12 @@ public:
|
|||||||
int SetScriptReference(int);
|
int SetScriptReference(int);
|
||||||
int GetScriptReference();
|
int GetScriptReference();
|
||||||
|
|
||||||
|
//NOTE: Why does this have tags? Are the tags used?
|
||||||
std::string SetTag(std::string key, std::string value);
|
std::string SetTag(std::string key, std::string value);
|
||||||
std::string GetTag(std::string key);
|
std::string GetTag(std::string key);
|
||||||
|
|
||||||
int SetInstanceIndex(int i);
|
int SetBattleIndex(int i);
|
||||||
int GetInstanceIndex() const;
|
int GetBattleIndex() const;
|
||||||
|
|
||||||
int SetStatus(int k, int v);
|
int SetStatus(int k, int v);
|
||||||
int GetStatus(int k);
|
int GetStatus(int k);
|
||||||
@@ -53,7 +55,7 @@ private:
|
|||||||
int scriptRef = LUA_NOREF;
|
int scriptRef = LUA_NOREF;
|
||||||
std::map<std::string, std::string> tags;
|
std::map<std::string, std::string> tags;
|
||||||
|
|
||||||
int instanceIndex;
|
int battleIndex;
|
||||||
|
|
||||||
int status[8];
|
int status[8];
|
||||||
};
|
};
|
||||||
@@ -27,6 +27,7 @@
|
|||||||
#include "sqlite3.h"
|
#include "sqlite3.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <functional>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. packet_types ../gameplay ../map ../utilities
|
INCLUDES+=. .. ../characters ../creatures ../entities ../inventory ../../common/global_defines ../../common/utilities ../../TurtleGUI
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
@@ -10,10 +10,13 @@ CXXSRC=$(wildcard *.cpp)
|
|||||||
OBJDIR=obj
|
OBJDIR=obj
|
||||||
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||||
|
|
||||||
|
#output
|
||||||
|
OUTDIR=..
|
||||||
|
OUT=$(addprefix $(OUTDIR)/,server.a)
|
||||||
|
|
||||||
#targets
|
#targets
|
||||||
all: $(OBJ) $(OUT)
|
all: $(OBJ) $(OUT)
|
||||||
ar -crs $(OUT) $(OBJ)
|
ar -crs $(OUT) $(OBJ)
|
||||||
$(MAKE) -C packet_types
|
|
||||||
|
|
||||||
$(OBJ): | $(OBJDIR)
|
$(OBJ): | $(OBJDIR)
|
||||||
|
|
||||||
@@ -19,33 +19,33 @@
|
|||||||
* 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 "combat_instance.hpp"
|
#include "battle_data.hpp"
|
||||||
|
|
||||||
CombatInstance::CombatInstance() {
|
BattleData::BattleData() {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
CombatInstance::~CombatInstance() {
|
BattleData::~BattleData() {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
void CombatInstance::Update() {
|
void BattleData::Update() {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
//accessors and mutators
|
//accessors and mutators
|
||||||
void CombatInstance::PushCharacter(CharacterData* const characterData) {
|
void BattleData::PushCharacter(CharacterData* const characterData) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
void CombatInstance::PopCharacter(CharacterData* const characterData) {
|
void BattleData::PopCharacter(CharacterData* const characterData) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
void CombatInstance::PushCreature(CreatureData* const creatureData) {
|
void BattleData::PushCreature(CreatureData* const creatureData) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
void CombatInstance::PopCreature(CreatureData* const creatureData) {
|
void BattleData::PopCreature(CreatureData* const creatureData) {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
@@ -24,10 +24,12 @@
|
|||||||
#include "character_data.hpp"
|
#include "character_data.hpp"
|
||||||
#include "creature_data.hpp"
|
#include "creature_data.hpp"
|
||||||
|
|
||||||
class CombatInstance {
|
#include <functional>
|
||||||
|
|
||||||
|
class BattleData {
|
||||||
public:
|
public:
|
||||||
CombatInstance();
|
BattleData();
|
||||||
~CombatInstance();
|
~BattleData();
|
||||||
|
|
||||||
void Update();
|
void Update();
|
||||||
|
|
||||||
@@ -19,26 +19,26 @@
|
|||||||
* 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 "combat_instance_manager.hpp"
|
#include "battle_manager.hpp"
|
||||||
|
|
||||||
CombatInstanceManager::CombatInstanceManager() {
|
BattleManager::BattleManager() {
|
||||||
//EMPTY
|
//EMPTY
|
||||||
}
|
}
|
||||||
|
|
||||||
CombatInstanceManager::~CombatInstanceManager() {
|
BattleManager::~BattleManager() {
|
||||||
UnloadAll();
|
UnloadAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
//arg: a list of combats to be updated in the clients
|
//arg: a list of combats to be updated in the clients
|
||||||
void CombatInstanceManager::Update() {
|
void BattleManager::Update() {
|
||||||
for (auto& it : elementMap) {
|
for (auto& it : elementMap) {
|
||||||
it.second.Update();
|
it.second.Update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int CombatInstanceManager::Create() {
|
int BattleManager::Create() {
|
||||||
//implicitly create the new object
|
//implicitly create the new object
|
||||||
elementMap.emplace( std::pair<int, CombatInstance>(counter, CombatInstance()) );
|
elementMap.emplace( std::pair<int, BattleData>(counter, BattleData()) );
|
||||||
|
|
||||||
//TODO: do various things like saving to the database
|
//TODO: do various things like saving to the database
|
||||||
return counter++;
|
return counter++;
|
||||||
@@ -46,16 +46,16 @@ int CombatInstanceManager::Create() {
|
|||||||
|
|
||||||
//TODO: (1) combat load, save
|
//TODO: (1) combat load, save
|
||||||
|
|
||||||
void CombatInstanceManager::Unload(int uid) {
|
void BattleManager::Unload(int uid) {
|
||||||
elementMap.erase(uid);
|
elementMap.erase(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CombatInstanceManager::UnloadAll() {
|
void BattleManager::UnloadAll() {
|
||||||
elementMap.clear();
|
elementMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CombatInstanceManager::UnloadIf(std::function<bool(std::pair<const int, CombatInstance const&>)> fn) {
|
void BattleManager::UnloadIf(std::function<bool(std::pair<const int, BattleData const&>)> fn) {
|
||||||
std::map<int, CombatInstance>::iterator it = elementMap.begin();
|
std::map<int, BattleData>::iterator it = elementMap.begin();
|
||||||
while (it != elementMap.end()) {
|
while (it != elementMap.end()) {
|
||||||
if (fn(*it)) {
|
if (fn(*it)) {
|
||||||
it = elementMap.erase(it);
|
it = elementMap.erase(it);
|
||||||
@@ -66,8 +66,8 @@ void CombatInstanceManager::UnloadIf(std::function<bool(std::pair<const int, Com
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CombatInstance* CombatInstanceManager::Find(int uid) {
|
BattleData* BattleManager::Find(int uid) {
|
||||||
std::map<int, CombatInstance>::iterator it = elementMap.find(uid);
|
std::map<int, BattleData>::iterator it = elementMap.find(uid);
|
||||||
|
|
||||||
if (it == elementMap.end()) {
|
if (it == elementMap.end()) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -76,26 +76,26 @@ CombatInstance* CombatInstanceManager::Find(int uid) {
|
|||||||
return &it->second;
|
return &it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CombatInstanceManager::GetLoadedCount() {
|
int BattleManager::GetLoadedCount() {
|
||||||
return elementMap.size();
|
return elementMap.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<int, CombatInstance>* CombatInstanceManager::GetContainer() {
|
std::map<int, BattleData>* BattleManager::GetContainer() {
|
||||||
return &elementMap;
|
return &elementMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_State* CombatInstanceManager::SetLuaState(lua_State* L) {
|
lua_State* BattleManager::SetLuaState(lua_State* L) {
|
||||||
return lua = L;
|
return lua = L;
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_State* CombatInstanceManager::GetLuaState() {
|
lua_State* BattleManager::GetLuaState() {
|
||||||
return lua;
|
return lua;
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlite3* CombatInstanceManager::SetDatabase(sqlite3* db) {
|
sqlite3* BattleManager::SetDatabase(sqlite3* db) {
|
||||||
return database = db;
|
return database = db;
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlite3* CombatInstanceManager::GetDatabase() {
|
sqlite3* BattleManager::GetDatabase() {
|
||||||
return database;
|
return database;
|
||||||
}
|
}
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "combat_instance.hpp"
|
#include "battle_data.hpp"
|
||||||
|
|
||||||
#include "lua.hpp"
|
#include "lua.hpp"
|
||||||
#include "sqlite3.h"
|
#include "sqlite3.h"
|
||||||
@@ -29,10 +29,10 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
class CombatInstanceManager {
|
class BattleManager {
|
||||||
public:
|
public:
|
||||||
CombatInstanceManager();
|
BattleManager();
|
||||||
~CombatInstanceManager();
|
~BattleManager();
|
||||||
|
|
||||||
//common public methods
|
//common public methods
|
||||||
void Update();
|
void Update();
|
||||||
@@ -41,12 +41,12 @@ public:
|
|||||||
void Unload(int uid);
|
void Unload(int uid);
|
||||||
|
|
||||||
void UnloadAll();
|
void UnloadAll();
|
||||||
void UnloadIf(std::function<bool(std::pair<const int, CombatInstance const&>)> fn);
|
void UnloadIf(std::function<bool(std::pair<const int, BattleData const&>)> fn);
|
||||||
|
|
||||||
//accessors & mutators
|
//accessors & mutators
|
||||||
CombatInstance* Find(int uid);
|
BattleData* Find(int uid);
|
||||||
int GetLoadedCount();
|
int GetLoadedCount();
|
||||||
std::map<int, CombatInstance>* GetContainer();
|
std::map<int, BattleData>* GetContainer();
|
||||||
|
|
||||||
//hooks
|
//hooks
|
||||||
lua_State* SetLuaState(lua_State* L);
|
lua_State* SetLuaState(lua_State* L);
|
||||||
@@ -56,7 +56,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
//members
|
//members
|
||||||
std::map<int, CombatInstance> elementMap;
|
std::map<int, BattleData> elementMap;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
lua_State* lua = nullptr;
|
lua_State* lua = nullptr;
|
||||||
sqlite3* database = nullptr;
|
sqlite3* database = nullptr;
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. ../graphics
|
INCLUDES+=. .. ../characters ../creatures ../entities ../inventory ../../common/global_defines ../../common/utilities ../../TurtleGUI
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
@@ -10,6 +10,10 @@ CXXSRC=$(wildcard *.cpp)
|
|||||||
OBJDIR=obj
|
OBJDIR=obj
|
||||||
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||||
|
|
||||||
|
#output
|
||||||
|
OUTDIR=..
|
||||||
|
OUT=$(addprefix $(OUTDIR)/,server.a)
|
||||||
|
|
||||||
#targets
|
#targets
|
||||||
all: $(OBJ) $(OUT)
|
all: $(OBJ) $(OUT)
|
||||||
ar -crs $(OUT) $(OBJ)
|
ar -crs $(OUT) $(OBJ)
|
||||||
@@ -28,50 +28,42 @@
|
|||||||
#include "server_utilities.hpp"
|
#include "server_utilities.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <iostream>
|
||||||
static int setRoom(lua_State* L) {
|
static int setRoom(lua_State* L) {
|
||||||
//reverse engineer the character index
|
//variables
|
||||||
int characterIndex = -1;
|
|
||||||
CharacterData* character = static_cast<CharacterData*>(lua_touserdata(L, 1));
|
CharacterData* character = static_cast<CharacterData*>(lua_touserdata(L, 1));
|
||||||
CharacterManager& characterMgr = CharacterManager::GetSingleton();
|
CharacterManager& characterMgr = CharacterManager::GetSingleton();
|
||||||
|
|
||||||
for (auto& it : *characterMgr.GetContainer()) {
|
|
||||||
if (character == &it.second) {
|
|
||||||
characterIndex = it.first;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//error checking
|
//error checking
|
||||||
if (characterIndex == -1) {
|
if (characterMgr.Find(character->GetIndex()) != character) {
|
||||||
throw(std::runtime_error("Lua Error: Failed to find character index by reference"));
|
throw(std::runtime_error("Lua Error: Failed to verify character index by reference"));
|
||||||
}
|
}
|
||||||
|
|
||||||
//get the room index, depending on the parameter type
|
//get the room index, depending on the parameter type
|
||||||
int roomIndex = -1;
|
int roomIndex = -1;
|
||||||
RoomManager& roomMgr = RoomManager::GetSingleton();
|
|
||||||
switch(lua_type(L, 2)) {
|
switch(lua_type(L, 2)) {
|
||||||
case LUA_TNUMBER:
|
case LUA_TNUMBER:
|
||||||
|
//simple integer
|
||||||
roomIndex = lua_tointeger(L, 2);
|
roomIndex = lua_tointeger(L, 2);
|
||||||
break;
|
break;
|
||||||
case LUA_TLIGHTUSERDATA:
|
case LUA_TLIGHTUSERDATA: {
|
||||||
//reverse engineer the room index
|
//check that this is a room first
|
||||||
for (auto& it : *roomMgr.GetContainer()) {
|
RoomData* room = static_cast<RoomData*>(lua_touserdata(L, 2));
|
||||||
if (lua_touserdata(L, 2) == &it.second) {
|
RoomManager& roomMgr = RoomManager::GetSingleton();
|
||||||
roomIndex = it.first;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
//error checking
|
if (roomMgr.Find(room->GetRoomIndex()) != room) {
|
||||||
if (roomIndex == -1) {
|
std::cout << room->GetRoomIndex() << std::endl;
|
||||||
throw(std::runtime_error("Lua Error: Failed to find room index by reference"));
|
throw(std::runtime_error("Lua Error: Failed to verify room index by reference"));
|
||||||
|
}
|
||||||
|
roomIndex = room->GetRoomIndex();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw(std::runtime_error("Lua Error: Failed to find room index by reference"));
|
||||||
}
|
}
|
||||||
|
|
||||||
//send the delete & create messages
|
//send the delete & create messages
|
||||||
pumpAndChangeRooms(character, roomIndex, characterIndex);
|
pumpAndChangeRooms(character, roomIndex, character->GetIndex());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,10 @@ CharacterData::CharacterData(): Entity("character") {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CharacterData::GetIndex() {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
int CharacterData::GetOwner() {
|
int CharacterData::GetOwner() {
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
@@ -40,4 +44,8 @@ std::string CharacterData::GetHandle() {
|
|||||||
|
|
||||||
std::string CharacterData::GetAvatar() {
|
std::string CharacterData::GetAvatar() {
|
||||||
return avatar;
|
return avatar;
|
||||||
|
}
|
||||||
|
|
||||||
|
Inventory* CharacterData::GetInventory() {
|
||||||
|
return &inventory;
|
||||||
}
|
}
|
||||||
@@ -24,6 +24,7 @@
|
|||||||
//components
|
//components
|
||||||
#include "character_defines.hpp"
|
#include "character_defines.hpp"
|
||||||
#include "entity.hpp"
|
#include "entity.hpp"
|
||||||
|
#include "inventory.hpp"
|
||||||
|
|
||||||
//std namespace
|
//std namespace
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -35,14 +36,18 @@ public:
|
|||||||
~CharacterData() = default;
|
~CharacterData() = default;
|
||||||
|
|
||||||
//database stuff
|
//database stuff
|
||||||
|
int GetIndex();
|
||||||
int GetOwner();
|
int GetOwner();
|
||||||
std::string GetHandle();
|
std::string GetHandle();
|
||||||
std::string GetAvatar();
|
std::string GetAvatar();
|
||||||
|
Inventory* GetInventory();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class CharacterManager;
|
friend class CharacterManager;
|
||||||
|
|
||||||
|
int index = -1;
|
||||||
int owner = -1;
|
int owner = -1;
|
||||||
std::string handle;
|
std::string handle;
|
||||||
std::string avatar;
|
std::string avatar;
|
||||||
|
Inventory inventory;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -39,12 +39,8 @@
|
|||||||
static const char* CREATE_CHARACTER = "INSERT INTO LiveCharacters ("
|
static const char* CREATE_CHARACTER = "INSERT INTO LiveCharacters ("
|
||||||
"owner, "
|
"owner, "
|
||||||
"handle, "
|
"handle, "
|
||||||
"avatar, "
|
"avatar "
|
||||||
"boundsX, "
|
") VALUES (?1, ?2, ?3);";
|
||||||
"boundsY, "
|
|
||||||
"boundsW, "
|
|
||||||
"boundsH"
|
|
||||||
") VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7);";
|
|
||||||
|
|
||||||
static const char* LOAD_CHARACTER = "SELECT "
|
static const char* LOAD_CHARACTER = "SELECT "
|
||||||
"uid, "
|
"uid, "
|
||||||
@@ -53,21 +49,13 @@ static const char* LOAD_CHARACTER = "SELECT "
|
|||||||
"avatar, "
|
"avatar, "
|
||||||
"roomIndex, "
|
"roomIndex, "
|
||||||
"originX, "
|
"originX, "
|
||||||
"originY, "
|
"originY "
|
||||||
"boundsX, "
|
|
||||||
"boundsY, "
|
|
||||||
"boundsW, "
|
|
||||||
"boundsH "
|
|
||||||
"FROM LiveCharacters WHERE handle = ?;";
|
"FROM LiveCharacters WHERE handle = ?;";
|
||||||
|
|
||||||
static const char* SAVE_CHARACTER = "UPDATE OR FAIL LiveCharacters SET "
|
static const char* SAVE_CHARACTER = "UPDATE OR FAIL LiveCharacters SET "
|
||||||
"roomIndex = ?2, "
|
"roomIndex = ?2, "
|
||||||
"originX = ?3, "
|
"originX = ?3, "
|
||||||
"originY = ?4, "
|
"originY = ?4 "
|
||||||
"boundsX = ?5, "
|
|
||||||
"boundsY = ?6, "
|
|
||||||
"boundsW = ?7, "
|
|
||||||
"boundsH = ?8 "
|
|
||||||
"WHERE uid = ?1;";
|
"WHERE uid = ?1;";
|
||||||
|
|
||||||
static const char* DELETE_CHARACTER = "DELETE FROM LiveCharacters WHERE uid = ?;";
|
static const char* DELETE_CHARACTER = "DELETE FROM LiveCharacters WHERE uid = ?;";
|
||||||
@@ -93,10 +81,6 @@ int CharacterManager::Create(int owner, std::string handle, std::string avatar)
|
|||||||
ret |= sqlite3_bind_int(statement, 1, owner);
|
ret |= sqlite3_bind_int(statement, 1, owner);
|
||||||
ret |= sqlite3_bind_text(statement, 2, handle.c_str(), handle.size() + 1, SQLITE_STATIC);
|
ret |= sqlite3_bind_text(statement, 2, handle.c_str(), handle.size() + 1, SQLITE_STATIC);
|
||||||
ret |= sqlite3_bind_text(statement, 3, avatar.c_str(), avatar.size() + 1, SQLITE_STATIC);
|
ret |= sqlite3_bind_text(statement, 3, avatar.c_str(), avatar.size() + 1, SQLITE_STATIC);
|
||||||
ret |= sqlite3_bind_int(statement, 4, CHARACTER_BOUNDS_X);
|
|
||||||
ret |= sqlite3_bind_int(statement, 5, CHARACTER_BOUNDS_Y);
|
|
||||||
ret |= sqlite3_bind_int(statement, 6, CHARACTER_BOUNDS_WIDTH);
|
|
||||||
ret |= sqlite3_bind_int(statement, 7, CHARACTER_BOUNDS_HEIGHT);
|
|
||||||
|
|
||||||
//check for binding errors
|
//check for binding errors
|
||||||
if (ret) {
|
if (ret) {
|
||||||
@@ -157,6 +141,7 @@ int CharacterManager::Load(int owner, std::string handle, std::string avatar) {
|
|||||||
CharacterData& newChar = elementMap[uid];
|
CharacterData& newChar = elementMap[uid];
|
||||||
|
|
||||||
//metadata
|
//metadata
|
||||||
|
newChar.index = uid;
|
||||||
newChar.owner = owner;
|
newChar.owner = owner;
|
||||||
newChar.handle = reinterpret_cast<const char*>(sqlite3_column_text(statement, 2));
|
newChar.handle = reinterpret_cast<const char*>(sqlite3_column_text(statement, 2));
|
||||||
newChar.avatar = reinterpret_cast<const char*>(sqlite3_column_text(statement, 3));
|
newChar.avatar = reinterpret_cast<const char*>(sqlite3_column_text(statement, 3));
|
||||||
@@ -167,10 +152,10 @@ int CharacterManager::Load(int owner, std::string handle, std::string avatar) {
|
|||||||
newChar.origin.x = (double)sqlite3_column_int(statement, 5);
|
newChar.origin.x = (double)sqlite3_column_int(statement, 5);
|
||||||
newChar.origin.y = (double)sqlite3_column_int(statement, 6);
|
newChar.origin.y = (double)sqlite3_column_int(statement, 6);
|
||||||
//bounds
|
//bounds
|
||||||
newChar.bounds.x = (int)sqlite3_column_int(statement, 7);
|
newChar.bounds.x = CHARACTER_BOUNDS_X;
|
||||||
newChar.bounds.y = (int)sqlite3_column_int(statement, 8);
|
newChar.bounds.y = CHARACTER_BOUNDS_Y;
|
||||||
newChar.bounds.w = (int)sqlite3_column_int(statement, 9);
|
newChar.bounds.w = CHARACTER_BOUNDS_WIDTH;
|
||||||
newChar.bounds.h = (int)sqlite3_column_int(statement, 10);
|
newChar.bounds.h = CHARACTER_BOUNDS_HEIGHT;
|
||||||
|
|
||||||
//gameplay components: equipment, items, buffs, debuffs...
|
//gameplay components: equipment, items, buffs, debuffs...
|
||||||
|
|
||||||
@@ -212,12 +197,8 @@ int CharacterManager::Save(int uid) {
|
|||||||
ret |= sqlite3_bind_int(statement, 2, character.roomIndex) != SQLITE_OK;
|
ret |= sqlite3_bind_int(statement, 2, character.roomIndex) != SQLITE_OK;
|
||||||
ret |= sqlite3_bind_int(statement, 3, (int)character.origin.x) != SQLITE_OK;
|
ret |= sqlite3_bind_int(statement, 3, (int)character.origin.x) != SQLITE_OK;
|
||||||
ret |= sqlite3_bind_int(statement, 4, (int)character.origin.y) != SQLITE_OK;
|
ret |= sqlite3_bind_int(statement, 4, (int)character.origin.y) != SQLITE_OK;
|
||||||
ret |= sqlite3_bind_int(statement, 5, character.bounds.x) != SQLITE_OK;
|
|
||||||
ret |= sqlite3_bind_int(statement, 6, character.bounds.y) != SQLITE_OK;
|
|
||||||
ret |= sqlite3_bind_int(statement, 7, character.bounds.w) != SQLITE_OK;
|
|
||||||
ret |= sqlite3_bind_int(statement, 8, character.bounds.h) != SQLITE_OK;
|
|
||||||
|
|
||||||
//gameplay components: equipment, items, buffs, debuffs...
|
//TODO: gameplay components: equipment, items, buffs, debuffs...
|
||||||
|
|
||||||
//check for binding errors
|
//check for binding errors
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. .. ../combat ../creatures ../entities ../monsters ../rooms ../triggers ../../common/gameplay ../../common/map ../../common/network ../../common/network/packet_types ../../common/utilities
|
INCLUDES+=. .. ../barriers ../battles ../creatures ../entities ../monsters ../inventory ../rooms ../triggers ../../common/global_defines ../../common/network ../../common/network/packet_types ../../common/utilities ../../TurtleGUI ../../TurtleMap
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,11 @@ std::list<int> ClientManager::CheckConnections() {
|
|||||||
for (auto& it : elementMap) {
|
for (auto& it : elementMap) {
|
||||||
if (it.second.GetAttempts() > 2) {
|
if (it.second.GetAttempts() > 2) {
|
||||||
returnList.push_back(it.first);
|
returnList.push_back(it.first);
|
||||||
|
|
||||||
|
//send the drop message
|
||||||
|
ServerPacket newPacket;
|
||||||
|
newPacket.type = SerialPacketType::ADMIN_DISCONNECT_FORCED;
|
||||||
|
UDPNetworkUtility::GetSingleton().SendTo(it.second.GetAddress(), &newPacket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,4 +111,4 @@ int ClientManager::GetTotalCount() {
|
|||||||
|
|
||||||
std::map<int, ClientData>* ClientManager::GetContainer() {
|
std::map<int, ClientData>* ClientManager::GetContainer() {
|
||||||
return &elementMap;
|
return &elementMap;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ int CreatureData::Update(lua_State* L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ret += lua_tonumber(L, -1);
|
ret += lua_tonumber(L, -1);
|
||||||
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity::Update();
|
Entity::Update();
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. .. ../entities ../../common/gameplay ../../common/utilities
|
INCLUDES+=. .. ../entities ../../common/global_defines ../../common/utilities ../../TurtleGUI
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. ../../common/utilities
|
INCLUDES+=. ../../common/utilities ../../TurtleGUI
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user