Compare commits
42 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 07885cca1b | |||
| 956e920b7a | |||
| 908f91d674 | |||
| fd320767c5 | |||
| c830fa0537 | |||
| 10c89970cc | |||
| 0b512305a9 | |||
| 555abf9c95 | |||
| 2b3ea5eb80 | |||
| 66815016ba | |||
| 46f02dcfdd | |||
| 414a0896c9 | |||
| 0077d501ac | |||
| e946a0741d | |||
| 839c2af940 | |||
| f70241cc57 | |||
| 36d30ce39b | |||
| 28d083cba4 | |||
| 4dd4b37fc0 | |||
| 82b1b589dc | |||
| bac493c96b | |||
| d5520e83c6 | |||
| 93480be685 | |||
| 8ed308e89a | |||
| 8df1ecd804 | |||
| 8c9d071c7a | |||
| ac1098fa86 | |||
| deba324449 | |||
| 95362286f8 | |||
| f5c58bf5ad | |||
| 316db43b0a | |||
| 46ed196bf4 | |||
| 64baa63d12 | |||
| e19b6fbc23 | |||
| a64411a567 | |||
| 3662a97475 | |||
| 97aaacbc23 | |||
| 8afd0e7c8a | |||
| 82c776df83 | |||
| 924ebc2ee9 | |||
| d3bf099a98 | |||
| a6de5f9e69 |
@@ -19,27 +19,23 @@
|
|||||||
* 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 "character_data.hpp"
|
#include "character.hpp"
|
||||||
|
|
||||||
void CharacterData::Update(double delta) {
|
void Character::Update(double delta) {
|
||||||
if (motion.x && motion.y) {
|
if (motion.x && motion.y) {
|
||||||
origin += motion * delta * CHARACTER_WALKING_MOD;
|
origin += motion * delta * CHARACTER_WALKING_MOD;
|
||||||
}
|
}
|
||||||
else if (motion != 0) {
|
else if (motion != 0) {
|
||||||
origin += motion * delta;
|
origin += motion * delta;
|
||||||
}
|
}
|
||||||
#ifdef GRAPHICS
|
|
||||||
sprite.Update(delta);
|
sprite.Update(delta);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef GRAPHICS
|
void Character::DrawTo(SDL_Surface* const dest, int camX, int camY) {
|
||||||
|
|
||||||
void CharacterData::DrawTo(SDL_Surface* const dest, int camX, int camY) {
|
|
||||||
sprite.DrawTo(dest, origin.x - camX, origin.y - camY);
|
sprite.DrawTo(dest, origin.x - camX, origin.y - camY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CharacterData::CorrectSprite() {
|
void Character::CorrectSprite() {
|
||||||
//NOTE: These must correspond to the sprite sheet in use
|
//NOTE: These must correspond to the sprite sheet in use
|
||||||
if (motion.y > 0) {
|
if (motion.y > 0) {
|
||||||
sprite.SetYIndex(0);
|
sprite.SetYIndex(0);
|
||||||
@@ -63,5 +59,3 @@ void CharacterData::CorrectSprite() {
|
|||||||
sprite.SetXIndex(0);
|
sprite.SetXIndex(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#ifndef CHARACTER_HPP_
|
||||||
|
#define CHARACTER_HPP_
|
||||||
|
|
||||||
|
//components
|
||||||
|
#include "character_defines.hpp"
|
||||||
|
#include "vector2.hpp"
|
||||||
|
#include "bounding_box.hpp"
|
||||||
|
#include "statistics.hpp"
|
||||||
|
|
||||||
|
//graphics
|
||||||
|
#include "sprite_sheet.hpp"
|
||||||
|
|
||||||
|
//std namespace
|
||||||
|
#include <string>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
class Character {
|
||||||
|
public:
|
||||||
|
Character() = default;
|
||||||
|
~Character() = default;
|
||||||
|
|
||||||
|
void Update(double delta);
|
||||||
|
|
||||||
|
//graphics
|
||||||
|
void DrawTo(SDL_Surface* const, int camX, int camY);
|
||||||
|
void CorrectSprite();
|
||||||
|
SpriteSheet* GetSprite() { return &sprite; }
|
||||||
|
|
||||||
|
//gameplay
|
||||||
|
Statistics* GetStats() { return &stats; }
|
||||||
|
|
||||||
|
//accessors and mutators
|
||||||
|
|
||||||
|
//metadata
|
||||||
|
int SetOwner(int i) { return owner = i; }
|
||||||
|
int GetOwner() { return owner; }
|
||||||
|
std::string SetHandle(std::string s) { return handle = s; }
|
||||||
|
std::string GetHandle() const { return handle; }
|
||||||
|
std::string SetAvatar(std::string s) { return avatar = s; }
|
||||||
|
std::string GetAvatar() const { return avatar; }
|
||||||
|
|
||||||
|
//position
|
||||||
|
Vector2 SetOrigin(Vector2 v) { return origin = v; }
|
||||||
|
Vector2 GetOrigin() const { return origin; }
|
||||||
|
Vector2 SetMotion(Vector2 v) { return motion = v; }
|
||||||
|
Vector2 GetMotion() const { return motion; }
|
||||||
|
BoundingBox SetBounds(BoundingBox b) { return bounds = b; }
|
||||||
|
BoundingBox GetBounds() { return bounds; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
//graphics
|
||||||
|
SpriteSheet sprite;
|
||||||
|
|
||||||
|
//base statistics
|
||||||
|
Statistics stats;
|
||||||
|
|
||||||
|
//TODO: gameplay components: equipment, items, buffs, debuffs
|
||||||
|
|
||||||
|
//metadata
|
||||||
|
int owner;
|
||||||
|
std::string handle;
|
||||||
|
std::string avatar;
|
||||||
|
|
||||||
|
//position
|
||||||
|
Vector2 origin = {0.0,0.0};
|
||||||
|
Vector2 motion = {0.0,0.0};
|
||||||
|
BoundingBox bounds;
|
||||||
|
};
|
||||||
|
|
||||||
|
//tmp
|
||||||
|
#include <map>
|
||||||
|
typedef std::map<int, Character> CharacterMap;
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -22,9 +22,11 @@
|
|||||||
#include "client_application.hpp"
|
#include "client_application.hpp"
|
||||||
|
|
||||||
#include "serial.hpp"
|
#include "serial.hpp"
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Scene headers
|
//Scene headers
|
||||||
@@ -44,24 +46,72 @@
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
void ClientApplication::Init(int argc, char** argv) {
|
void ClientApplication::Init(int argc, char** argv) {
|
||||||
|
std::cout << "Beginning " << argv[0] << std::endl;
|
||||||
|
|
||||||
//load the prerequisites
|
//load the prerequisites
|
||||||
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
config.Load("rsc\\config.cfg");
|
config.Load("rsc\\config.cfg");
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Initialize the APIs
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
//initialize SDL
|
//initialize SDL
|
||||||
if (SDL_Init(SDL_INIT_VIDEO)) {
|
if (SDL_Init(SDL_INIT_VIDEO)) {
|
||||||
throw(std::runtime_error("Failed to initialize SDL"));
|
throw(std::runtime_error("Failed to initialize SDL"));
|
||||||
}
|
}
|
||||||
int w = config.Int("client.screen.w");
|
std::cout << "Initialized SDL" << std::endl;
|
||||||
int h = config.Int("client.screen.h");
|
|
||||||
int f = config.Bool("client.screen.f") ? SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN : SDL_HWSURFACE|SDL_DOUBLEBUF;
|
|
||||||
|
|
||||||
BaseScene::SetScreen(w ? w : 800, h ? h : 600, 0, f);
|
|
||||||
|
|
||||||
//initialize SDL_net
|
//initialize SDL_net
|
||||||
if (SDLNet_Init()) {
|
if (SDLNet_Init()) {
|
||||||
throw(std::runtime_error("Failed to initialize SDL_net"));
|
throw(std::runtime_error("Failed to initialize SDL_net"));
|
||||||
}
|
}
|
||||||
network.Open(0);
|
network.Open(0);
|
||||||
|
std::cout << "Initialized SDL_net" << std::endl;
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Setup the screen
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
int w = config.Int("client.screen.w");
|
||||||
|
int h = config.Int("client.screen.h");
|
||||||
|
int f = config.Bool("client.screen.f") ? SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN : SDL_HWSURFACE|SDL_DOUBLEBUF;
|
||||||
|
|
||||||
|
BaseScene::SetScreen(w ? w : 800, h ? h : 600, 0, f);
|
||||||
|
std::cout << "Initialized the screen" << std::endl;
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//debug output
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
//TODO: enable/disable these with a switch
|
||||||
|
#define DEBUG_OUTPUT_VAR(x) std::cout << "\t" << #x << ": " << x << std::endl;
|
||||||
|
|
||||||
|
std::cout << "Internal sizes:" << std::endl;
|
||||||
|
|
||||||
|
DEBUG_OUTPUT_VAR(sizeof(Region::type_t));
|
||||||
|
DEBUG_OUTPUT_VAR(sizeof(Region));
|
||||||
|
DEBUG_OUTPUT_VAR(REGION_WIDTH);
|
||||||
|
DEBUG_OUTPUT_VAR(REGION_HEIGHT);
|
||||||
|
DEBUG_OUTPUT_VAR(REGION_DEPTH);
|
||||||
|
DEBUG_OUTPUT_VAR(REGION_SOLID_FOOTPRINT);
|
||||||
|
DEBUG_OUTPUT_VAR(REGION_FOOTPRINT);
|
||||||
|
DEBUG_OUTPUT_VAR(PACKET_BUFFER_SIZE);
|
||||||
|
DEBUG_OUTPUT_VAR(MAX_PACKET_SIZE);
|
||||||
|
|
||||||
|
#undef DEBUG_OUTPUT_VAR
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//finalize the startup
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
std::cout << "Startup completed successfully" << std::endl;
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//debugging
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
//...
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientApplication::Proc() {
|
void ClientApplication::Proc() {
|
||||||
@@ -100,9 +150,11 @@ void ClientApplication::Proc() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ClientApplication::Quit() {
|
void ClientApplication::Quit() {
|
||||||
|
std::cout << "Shutting down" << std::endl;
|
||||||
network.Close();
|
network.Close();
|
||||||
SDLNet_Quit();
|
SDLNet_Quit();
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
std::cout << "Clean exit" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -115,25 +167,25 @@ void ClientApplication::LoadScene(SceneList sceneIndex) {
|
|||||||
//add scene creation calls here
|
//add scene creation calls here
|
||||||
case SceneList::FIRST:
|
case SceneList::FIRST:
|
||||||
case SceneList::SPLASHSCREEN:
|
case SceneList::SPLASHSCREEN:
|
||||||
activeScene = new SplashScreen(&config);
|
activeScene = new SplashScreen();
|
||||||
break;
|
break;
|
||||||
case SceneList::MAINMENU:
|
case SceneList::MAINMENU:
|
||||||
activeScene = new MainMenu(&config);
|
activeScene = new MainMenu();
|
||||||
break;
|
break;
|
||||||
case SceneList::OPTIONSMENU:
|
case SceneList::OPTIONSMENU:
|
||||||
activeScene = new OptionsMenu(&config);
|
activeScene = new OptionsMenu();
|
||||||
break;
|
break;
|
||||||
case SceneList::LOBBYMENU:
|
case SceneList::LOBBYMENU:
|
||||||
activeScene = new LobbyMenu(&config, &network, &clientIndex, &accountIndex);
|
activeScene = new LobbyMenu(&network, &clientIndex, &accountIndex);
|
||||||
break;
|
break;
|
||||||
case SceneList::INWORLD:
|
case SceneList::INWORLD:
|
||||||
activeScene = new InWorld(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap);
|
activeScene = new InWorld(&network, &clientIndex, &accountIndex, &characterIndex, &characterMap);
|
||||||
break;
|
break;
|
||||||
case SceneList::INCOMBAT:
|
case SceneList::INCOMBAT:
|
||||||
activeScene = new InCombat(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap, &enemyMap);
|
activeScene = new InCombat(&network, &clientIndex, &accountIndex, &characterIndex, &characterMap);
|
||||||
break;
|
break;
|
||||||
case SceneList::CLEANUP:
|
case SceneList::CLEANUP:
|
||||||
activeScene = new CleanUp(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap, &enemyMap);
|
activeScene = new CleanUp(&network, &clientIndex, &accountIndex, &characterIndex, &characterMap);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw(std::logic_error("Failed to recognize the scene index"));
|
throw(std::logic_error("Failed to recognize the scene index"));
|
||||||
|
|||||||
@@ -25,24 +25,26 @@
|
|||||||
#include "scene_list.hpp"
|
#include "scene_list.hpp"
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
#include "config_utility.hpp"
|
|
||||||
#include "udp_network_utility.hpp"
|
#include "udp_network_utility.hpp"
|
||||||
#include "character_data.hpp"
|
#include "character.hpp"
|
||||||
#include "combat_data.hpp"
|
|
||||||
#include "enemy_data.hpp"
|
#include "singleton.hpp"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
class ClientApplication {
|
class ClientApplication: public Singleton<ClientApplication> {
|
||||||
public:
|
public:
|
||||||
ClientApplication() = default;
|
//public methods
|
||||||
~ClientApplication() = default;
|
|
||||||
|
|
||||||
void Init(int argc, char** argv);
|
void Init(int argc, char** argv);
|
||||||
void Proc();
|
void Proc();
|
||||||
void Quit();
|
void Quit();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend Singleton<ClientApplication>;
|
||||||
|
|
||||||
|
ClientApplication() = default;
|
||||||
|
~ClientApplication() = default;
|
||||||
|
|
||||||
//Private access members
|
//Private access members
|
||||||
void LoadScene(SceneList sceneIndex);
|
void LoadScene(SceneList sceneIndex);
|
||||||
void UnloadScene();
|
void UnloadScene();
|
||||||
@@ -50,15 +52,12 @@ private:
|
|||||||
BaseScene* activeScene = nullptr;
|
BaseScene* activeScene = nullptr;
|
||||||
|
|
||||||
//shared parameters
|
//shared parameters
|
||||||
ConfigUtility config;
|
|
||||||
UDPNetworkUtility network;
|
UDPNetworkUtility network;
|
||||||
int clientIndex = -1;
|
int clientIndex = -1;
|
||||||
int accountIndex = -1;
|
int accountIndex = -1;
|
||||||
int characterIndex = -1;
|
int characterIndex = -1;
|
||||||
|
|
||||||
std::map<int, CombatData> combatMap;
|
CharacterMap characterMap;
|
||||||
std::map<int, CharacterData> characterMap;
|
|
||||||
std::map<int, EnemyData> enemyMap;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+13
-3
@@ -21,23 +21,33 @@
|
|||||||
*/
|
*/
|
||||||
#include "client_application.hpp"
|
#include "client_application.hpp"
|
||||||
|
|
||||||
|
//singletons
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
cout << "Beginning client" << endl;
|
|
||||||
try {
|
try {
|
||||||
ClientApplication app;
|
//create the singletons
|
||||||
|
ClientApplication::Create();
|
||||||
|
ConfigUtility::Create();
|
||||||
|
|
||||||
|
//call the server's routines
|
||||||
|
ClientApplication& app = ClientApplication::GetSingleton();
|
||||||
app.Init(argc, argv);
|
app.Init(argc, argv);
|
||||||
app.Proc();
|
app.Proc();
|
||||||
app.Quit();
|
app.Quit();
|
||||||
|
|
||||||
|
//delete the singletons
|
||||||
|
ConfigUtility::Delete();
|
||||||
|
ClientApplication::Delete();
|
||||||
}
|
}
|
||||||
catch(exception& e) {
|
catch(exception& e) {
|
||||||
cerr << "Fatal exception thrown: " << e.what() << endl;
|
cerr << "Fatal exception thrown: " << e.what() << endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
cout << "Clean exit" << endl;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
+4
-3
@@ -1,7 +1,7 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet ../common/network/serial ../common/ui ../common/utilities
|
INCLUDES+=. scenes ../common/debugging ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet ../common/network/serial ../common/ui ../common/utilities
|
||||||
LIBS+=../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua
|
LIBS+=client.a ../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) -DGRAPHICS
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
#source
|
#source
|
||||||
CXXSRC=$(wildcard *.cpp)
|
CXXSRC=$(wildcard *.cpp)
|
||||||
@@ -16,6 +16,7 @@ OUT=$(addprefix $(OUTDIR)/,client)
|
|||||||
|
|
||||||
#targets
|
#targets
|
||||||
all: $(OBJ) $(OUT)
|
all: $(OBJ) $(OUT)
|
||||||
|
$(MAKE) -C scenes
|
||||||
$(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
|
$(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
|
||||||
|
|
||||||
$(OBJ): | $(OBJDIR)
|
$(OBJ): | $(OBJDIR)
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "clean_up.hpp"
|
#include "clean_up.hpp"
|
||||||
|
|
||||||
#include "channels.hpp"
|
#include "channels.hpp"
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
@@ -30,24 +31,20 @@
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
CleanUp::CleanUp(
|
CleanUp::CleanUp(
|
||||||
ConfigUtility* const argConfig,
|
|
||||||
UDPNetworkUtility* const argNetwork,
|
UDPNetworkUtility* const argNetwork,
|
||||||
int* const argClientIndex,
|
int* const argClientIndex,
|
||||||
int* const argAccountIndex,
|
int* const argAccountIndex,
|
||||||
int* const argCharacterIndex,
|
int* const argCharacterIndex,
|
||||||
std::map<int, CombatData>* argCombatMap,
|
CharacterMap* argCharacterMap
|
||||||
std::map<int, CharacterData>* argCharacterMap,
|
|
||||||
std::map<int, EnemyData>* argEnemyMap
|
|
||||||
):
|
):
|
||||||
config(*argConfig),
|
|
||||||
network(*argNetwork),
|
network(*argNetwork),
|
||||||
clientIndex(*argClientIndex),
|
clientIndex(*argClientIndex),
|
||||||
accountIndex(*argAccountIndex),
|
accountIndex(*argAccountIndex),
|
||||||
characterIndex(*argCharacterIndex),
|
characterIndex(*argCharacterIndex),
|
||||||
combatMap(*argCombatMap),
|
characterMap(*argCharacterMap)
|
||||||
characterMap(*argCharacterMap),
|
|
||||||
enemyMap(*argEnemyMap)
|
|
||||||
{
|
{
|
||||||
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
|
|
||||||
//setup the utility objects
|
//setup the utility objects
|
||||||
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
||||||
image.SetClipH(image.GetClipH()/3);
|
image.SetClipH(image.GetClipH()/3);
|
||||||
@@ -69,9 +66,9 @@ CleanUp::CleanUp(
|
|||||||
clientIndex = -1;
|
clientIndex = -1;
|
||||||
accountIndex = -1;
|
accountIndex = -1;
|
||||||
characterIndex = -1;
|
characterIndex = -1;
|
||||||
combatMap.clear();
|
// combatMap.clear();
|
||||||
characterMap.clear();
|
characterMap.clear();
|
||||||
enemyMap.clear();
|
// enemyMap.clear();
|
||||||
|
|
||||||
//auto return
|
//auto return
|
||||||
startTick = std::chrono::steady_clock::now();
|
startTick = std::chrono::steady_clock::now();
|
||||||
@@ -31,12 +31,9 @@
|
|||||||
#include "button.hpp"
|
#include "button.hpp"
|
||||||
|
|
||||||
//common
|
//common
|
||||||
#include "config_utility.hpp"
|
|
||||||
#include "frame_rate.hpp"
|
#include "frame_rate.hpp"
|
||||||
|
|
||||||
#include "combat_data.hpp"
|
#include "character.hpp"
|
||||||
#include "character_data.hpp"
|
|
||||||
#include "enemy_data.hpp"
|
|
||||||
|
|
||||||
//client
|
//client
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
@@ -48,14 +45,11 @@ class CleanUp : public BaseScene {
|
|||||||
public:
|
public:
|
||||||
//Public access members
|
//Public access members
|
||||||
CleanUp(
|
CleanUp(
|
||||||
ConfigUtility* const argConfig,
|
|
||||||
UDPNetworkUtility* const argNetwork,
|
UDPNetworkUtility* const argNetwork,
|
||||||
int* const argClientIndex,
|
int* const argClientIndex,
|
||||||
int* const argAccountIndex,
|
int* const argAccountIndex,
|
||||||
int* const argCharacterIndex,
|
int* const argCharacterIndex,
|
||||||
std::map<int, CombatData>* argCombatMap,
|
CharacterMap* argCharacterMap
|
||||||
std::map<int, CharacterData>* argCharacterMap,
|
|
||||||
std::map<int, EnemyData>* argEnemyMap
|
|
||||||
);
|
);
|
||||||
~CleanUp();
|
~CleanUp();
|
||||||
|
|
||||||
@@ -74,14 +68,11 @@ protected:
|
|||||||
void KeyUp(SDL_KeyboardEvent const&);
|
void KeyUp(SDL_KeyboardEvent const&);
|
||||||
|
|
||||||
//shared parameters
|
//shared parameters
|
||||||
ConfigUtility& config;
|
|
||||||
UDPNetworkUtility& network;
|
UDPNetworkUtility& network;
|
||||||
int& clientIndex;
|
int& clientIndex;
|
||||||
int& accountIndex;
|
int& accountIndex;
|
||||||
int& characterIndex;
|
int& characterIndex;
|
||||||
std::map<int, CombatData>& combatMap;
|
CharacterMap& characterMap;
|
||||||
std::map<int, CharacterData>& characterMap;
|
|
||||||
std::map<int, EnemyData>& enemyMap;
|
|
||||||
|
|
||||||
//graphics
|
//graphics
|
||||||
Image image;
|
Image image;
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include "channels.hpp"
|
#include "channels.hpp"
|
||||||
#include "utility.hpp"
|
#include "utility.hpp"
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
@@ -31,23 +32,17 @@
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
InCombat::InCombat(
|
InCombat::InCombat(
|
||||||
ConfigUtility* const argConfig,
|
|
||||||
UDPNetworkUtility* const argNetwork,
|
UDPNetworkUtility* const argNetwork,
|
||||||
int* const argClientIndex,
|
int* const argClientIndex,
|
||||||
int* const argAccountIndex,
|
int* const argAccountIndex,
|
||||||
int* const argCharacterIndex,
|
int* const argCharacterIndex,
|
||||||
std::map<int, CombatData>* argCombatMap,
|
CharacterMap* argCharacterMap
|
||||||
std::map<int, CharacterData>* argCharacterMap,
|
|
||||||
std::map<int, EnemyData>* argEnemyMap
|
|
||||||
):
|
):
|
||||||
config(*argConfig),
|
|
||||||
network(*argNetwork),
|
network(*argNetwork),
|
||||||
clientIndex(*argClientIndex),
|
clientIndex(*argClientIndex),
|
||||||
accountIndex(*argAccountIndex),
|
accountIndex(*argAccountIndex),
|
||||||
characterIndex(*argCharacterIndex),
|
characterIndex(*argCharacterIndex),
|
||||||
combatMap(*argCombatMap),
|
characterMap(*argCharacterMap)
|
||||||
characterMap(*argCharacterMap),
|
|
||||||
enemyMap(*argEnemyMap)
|
|
||||||
{
|
{
|
||||||
/* //setup the utility objects
|
/* //setup the utility objects
|
||||||
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
||||||
@@ -31,12 +31,9 @@
|
|||||||
#include "button.hpp"
|
#include "button.hpp"
|
||||||
|
|
||||||
//common
|
//common
|
||||||
#include "config_utility.hpp"
|
|
||||||
#include "frame_rate.hpp"
|
#include "frame_rate.hpp"
|
||||||
|
|
||||||
#include "combat_data.hpp"
|
#include "character.hpp"
|
||||||
#include "character_data.hpp"
|
|
||||||
#include "enemy_data.hpp"
|
|
||||||
|
|
||||||
//client
|
//client
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
@@ -45,14 +42,11 @@ class InCombat : public BaseScene {
|
|||||||
public:
|
public:
|
||||||
//Public access members
|
//Public access members
|
||||||
InCombat(
|
InCombat(
|
||||||
ConfigUtility* const argConfig,
|
|
||||||
UDPNetworkUtility* const argNetwork,
|
UDPNetworkUtility* const argNetwork,
|
||||||
int* const argClientIndex,
|
int* const argClientIndex,
|
||||||
int* const argAccountIndex,
|
int* const argAccountIndex,
|
||||||
int* const argCharacterIndex,
|
int* const argCharacterIndex,
|
||||||
std::map<int, CombatData>* argCombatMap,
|
CharacterMap* argCharacterMap
|
||||||
std::map<int, CharacterData>* argCharacterMap,
|
|
||||||
std::map<int, EnemyData>* argEnemyMap
|
|
||||||
);
|
);
|
||||||
~InCombat();
|
~InCombat();
|
||||||
|
|
||||||
@@ -75,24 +69,19 @@ protected:
|
|||||||
//Network handlers
|
//Network handlers
|
||||||
void HandlePacket(SerialPacket* const);
|
void HandlePacket(SerialPacket* const);
|
||||||
void HandleDisconnect(SerialPacket* const);
|
void HandleDisconnect(SerialPacket* const);
|
||||||
//TODO: more network handlers
|
|
||||||
|
|
||||||
//Server control
|
//Server control
|
||||||
void RequestSynchronize();
|
void RequestSynchronize();
|
||||||
void SendPlayerUpdate();
|
void SendPlayerUpdate();
|
||||||
void RequestDisconnect();
|
void RequestDisconnect();
|
||||||
void RequestShutdown();
|
void RequestShutdown();
|
||||||
//TODO: more
|
|
||||||
|
|
||||||
//shared parameters
|
//shared parameters
|
||||||
ConfigUtility& config;
|
|
||||||
UDPNetworkUtility& network;
|
UDPNetworkUtility& network;
|
||||||
int& clientIndex;
|
int& clientIndex;
|
||||||
int& accountIndex;
|
int& accountIndex;
|
||||||
int& characterIndex;
|
int& characterIndex;
|
||||||
std::map<int, CombatData>& combatMap;
|
CharacterMap& characterMap;
|
||||||
std::map<int, CharacterData>& characterMap;
|
|
||||||
std::map<int, EnemyData>& enemyMap;
|
|
||||||
|
|
||||||
//graphics
|
//graphics
|
||||||
//TODO: graphics
|
//TODO: graphics
|
||||||
@@ -23,32 +23,32 @@
|
|||||||
|
|
||||||
#include "channels.hpp"
|
#include "channels.hpp"
|
||||||
#include "utility.hpp"
|
#include "utility.hpp"
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <stdexcept>
|
#include <iostream>
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Public access members
|
//Public access members
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
InWorld::InWorld(
|
InWorld::InWorld(
|
||||||
ConfigUtility* const argConfig,
|
|
||||||
UDPNetworkUtility* const argNetwork,
|
UDPNetworkUtility* const argNetwork,
|
||||||
int* const argClientIndex,
|
int* const argClientIndex,
|
||||||
int* const argAccountIndex,
|
int* const argAccountIndex,
|
||||||
int* const argCharacterIndex,
|
int* const argCharacterIndex,
|
||||||
std::map<int, CombatData>* argCombatMap,
|
CharacterMap* argCharacterMap
|
||||||
std::map<int, CharacterData>* argCharacterMap
|
|
||||||
):
|
):
|
||||||
config(*argConfig),
|
|
||||||
network(*argNetwork),
|
network(*argNetwork),
|
||||||
clientIndex(*argClientIndex),
|
clientIndex(*argClientIndex),
|
||||||
accountIndex(*argAccountIndex),
|
accountIndex(*argAccountIndex),
|
||||||
characterIndex(*argCharacterIndex),
|
characterIndex(*argCharacterIndex),
|
||||||
combatMap(*argCombatMap),
|
|
||||||
characterMap(*argCharacterMap)
|
characterMap(*argCharacterMap)
|
||||||
{
|
{
|
||||||
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
|
|
||||||
//setup the utility objects
|
//setup the utility objects
|
||||||
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
||||||
buttonImage.SetClipH(buttonImage.GetClipH()/3);
|
buttonImage.SetClipH(buttonImage.GetClipH()/3);
|
||||||
@@ -72,7 +72,8 @@ InWorld::InWorld(
|
|||||||
|
|
||||||
//load the tilesheet
|
//load the tilesheet
|
||||||
//TODO: add the tilesheet to the map system?
|
//TODO: add the tilesheet to the map system?
|
||||||
tileSheet.Load(config["dir.tilesets"] + "terrain.bmp", 12, 15);
|
//TODO: Tile size and tile sheet should be loaded elsewhere
|
||||||
|
tileSheet.Load(config["dir.tilesets"] + "terrain.bmp", 32, 32);
|
||||||
|
|
||||||
//request a sync
|
//request a sync
|
||||||
RequestSynchronize();
|
RequestSynchronize();
|
||||||
@@ -106,14 +107,41 @@ void InWorld::Update(double delta) {
|
|||||||
it.second.Update(delta);
|
it.second.Update(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
//update the camera
|
|
||||||
if(localCharacter) {
|
|
||||||
camera.x = localCharacter->origin.x - camera.marginX;
|
|
||||||
camera.y = localCharacter->origin.y - camera.marginY;
|
|
||||||
}
|
|
||||||
|
|
||||||
//check the map
|
//check the map
|
||||||
UpdateMap();
|
UpdateMap();
|
||||||
|
|
||||||
|
//skip the rest
|
||||||
|
if (!localCharacter) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//check for collisions with the map
|
||||||
|
BoundingBox wallBounds = {0, 0, tileSheet.GetTileW(), tileSheet.GetTileH()};
|
||||||
|
const int xCount = localCharacter->GetBounds().w / wallBounds.w + 1;
|
||||||
|
const int yCount = localCharacter->GetBounds().h / wallBounds.h + 1;
|
||||||
|
|
||||||
|
for (int i = -1; i <= xCount; ++i) {
|
||||||
|
for (int j = -1; j <= yCount; ++j) {
|
||||||
|
//set the wall's position
|
||||||
|
wallBounds.x = wallBounds.w * i + snapToBase((double)wallBounds.w, localCharacter->GetOrigin().x);
|
||||||
|
wallBounds.y = wallBounds.h * j + snapToBase((double)wallBounds.h, localCharacter->GetOrigin().y);
|
||||||
|
|
||||||
|
if (!regionPager.GetSolid(wallBounds.x / wallBounds.w, wallBounds.y / wallBounds.h)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((localCharacter->GetOrigin() + localCharacter->GetBounds()).CheckOverlap(wallBounds)) {
|
||||||
|
localCharacter->SetOrigin(localCharacter->GetOrigin() - (localCharacter->GetMotion() * delta));
|
||||||
|
localCharacter->SetMotion({0,0});
|
||||||
|
localCharacter->CorrectSprite();
|
||||||
|
SendPlayerUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//update the camera
|
||||||
|
camera.x = localCharacter->GetOrigin().x - camera.marginX;
|
||||||
|
camera.y = localCharacter->GetOrigin().y - camera.marginY;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InWorld::FrameEnd() {
|
void InWorld::FrameEnd() {
|
||||||
@@ -175,77 +203,60 @@ void InWorld::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void InWorld::KeyDown(SDL_KeyboardEvent const& key) {
|
void InWorld::KeyDown(SDL_KeyboardEvent const& key) {
|
||||||
switch(key.keysym.sym) {
|
if (!localCharacter) {
|
||||||
//player movement
|
return;
|
||||||
case SDLK_LEFT:
|
|
||||||
if (localCharacter) {
|
|
||||||
localCharacter->motion.x -= CHARACTER_WALKING_SPEED;
|
|
||||||
localCharacter->CorrectSprite();
|
|
||||||
SendPlayerUpdate();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDLK_RIGHT:
|
|
||||||
if (localCharacter) {
|
|
||||||
localCharacter->motion.x += CHARACTER_WALKING_SPEED;
|
|
||||||
localCharacter->CorrectSprite();
|
|
||||||
SendPlayerUpdate();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDLK_UP:
|
|
||||||
if (localCharacter) {
|
|
||||||
localCharacter->motion.y -= CHARACTER_WALKING_SPEED;
|
|
||||||
localCharacter->CorrectSprite();
|
|
||||||
SendPlayerUpdate();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDLK_DOWN:
|
|
||||||
if (localCharacter) {
|
|
||||||
localCharacter->motion.y += CHARACTER_WALKING_SPEED;
|
|
||||||
localCharacter->CorrectSprite();
|
|
||||||
SendPlayerUpdate();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//player movement
|
||||||
|
Vector2 motion = localCharacter->GetMotion();
|
||||||
|
switch(key.keysym.sym) {
|
||||||
|
case SDLK_LEFT:
|
||||||
|
motion.x -= CHARACTER_WALKING_SPEED;
|
||||||
|
break;
|
||||||
|
case SDLK_RIGHT:
|
||||||
|
motion.x += CHARACTER_WALKING_SPEED;
|
||||||
|
break;
|
||||||
|
case SDLK_UP:
|
||||||
|
motion.y -= CHARACTER_WALKING_SPEED;
|
||||||
|
break;
|
||||||
|
case SDLK_DOWN:
|
||||||
|
motion.y += CHARACTER_WALKING_SPEED;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
localCharacter->SetMotion(motion);
|
||||||
|
localCharacter->CorrectSprite();
|
||||||
|
SendPlayerUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InWorld::KeyUp(SDL_KeyboardEvent const& key) {
|
void InWorld::KeyUp(SDL_KeyboardEvent const& key) {
|
||||||
switch(key.keysym.sym) {
|
if (!localCharacter) {
|
||||||
//player movement
|
return;
|
||||||
case SDLK_LEFT:
|
|
||||||
if (localCharacter) {
|
|
||||||
localCharacter->motion.x += CHARACTER_WALKING_SPEED;
|
|
||||||
localCharacter->CorrectSprite();
|
|
||||||
SendPlayerUpdate();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDLK_RIGHT:
|
|
||||||
if (localCharacter) {
|
|
||||||
localCharacter->motion.x -= CHARACTER_WALKING_SPEED;
|
|
||||||
localCharacter->CorrectSprite();
|
|
||||||
SendPlayerUpdate();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDLK_UP:
|
|
||||||
if (localCharacter) {
|
|
||||||
localCharacter->motion.y += CHARACTER_WALKING_SPEED;
|
|
||||||
localCharacter->CorrectSprite();
|
|
||||||
SendPlayerUpdate();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDLK_DOWN:
|
|
||||||
if (localCharacter) {
|
|
||||||
localCharacter->motion.y -= CHARACTER_WALKING_SPEED;
|
|
||||||
localCharacter->CorrectSprite();
|
|
||||||
SendPlayerUpdate();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//player movement
|
||||||
|
Vector2 motion = localCharacter->GetMotion();
|
||||||
|
switch(key.keysym.sym) {
|
||||||
|
//NOTE: The use of min/max here are to prevent awkward movements
|
||||||
|
case SDLK_LEFT:
|
||||||
|
motion.x = std::min(motion.x + CHARACTER_WALKING_SPEED, 0.0);
|
||||||
|
break;
|
||||||
|
case SDLK_RIGHT:
|
||||||
|
motion.x = std::max(motion.x - CHARACTER_WALKING_SPEED, 0.0);
|
||||||
|
break;
|
||||||
|
case SDLK_UP:
|
||||||
|
motion.y = std::min(motion.y + CHARACTER_WALKING_SPEED, 0.0);
|
||||||
|
break;
|
||||||
|
case SDLK_DOWN:
|
||||||
|
motion.y = std::max(motion.y - CHARACTER_WALKING_SPEED, 0.0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
localCharacter->SetMotion(motion);
|
||||||
|
localCharacter->CorrectSprite();
|
||||||
|
SendPlayerUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -286,36 +297,42 @@ void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//create the character object
|
//create the character object
|
||||||
CharacterData& character = characterMap[argPacket->characterIndex];
|
Character& newCharacter = characterMap[argPacket->characterIndex];
|
||||||
|
|
||||||
//set the members
|
//fill out the character's members
|
||||||
character.handle = argPacket->handle;
|
newCharacter.SetHandle(argPacket->handle);
|
||||||
character.avatar = argPacket->avatar;
|
newCharacter.SetAvatar(argPacket->avatar);
|
||||||
character.sprite.LoadSurface(config["dir.sprites"] + character.avatar, 4, 4);
|
|
||||||
character.roomIndex = argPacket->roomIndex;
|
|
||||||
character.origin = argPacket->origin;
|
|
||||||
character.motion = argPacket->motion;
|
|
||||||
character.stats = argPacket->stats;
|
|
||||||
|
|
||||||
character.CorrectSprite();
|
newCharacter.GetSprite()->LoadSurface(ConfigUtility::GetSingleton()["dir.sprites"] + newCharacter.GetAvatar(), 4, 4);
|
||||||
|
|
||||||
|
newCharacter.SetOrigin(argPacket->origin);
|
||||||
|
newCharacter.SetMotion(argPacket->motion);
|
||||||
|
newCharacter.SetBounds({0, 16, 32, 32}); //TODO: magic numbers, fix this
|
||||||
|
|
||||||
|
(*newCharacter.GetStats()) = argPacket->stats;
|
||||||
|
|
||||||
|
//bookkeeping code
|
||||||
|
newCharacter.CorrectSprite();
|
||||||
|
|
||||||
//catch this client's player object
|
//catch this client's player object
|
||||||
if (argPacket->accountIndex == accountIndex && !localCharacter) {
|
if (argPacket->accountIndex == accountIndex && !localCharacter) {
|
||||||
characterIndex = argPacket->characterIndex;
|
characterIndex = argPacket->characterIndex;
|
||||||
localCharacter = &character;
|
localCharacter = &newCharacter;
|
||||||
|
|
||||||
//setup the camera
|
//setup the camera
|
||||||
|
//TODO: move this?
|
||||||
camera.width = GetScreen()->w;
|
camera.width = GetScreen()->w;
|
||||||
camera.height = GetScreen()->h;
|
camera.height = GetScreen()->h;
|
||||||
|
|
||||||
//center on the player's character
|
//center on the player's character
|
||||||
camera.marginX = (GetScreen()->w / 2 - localCharacter->sprite.GetImage()->GetClipW() / 2);
|
camera.marginX = (GetScreen()->w / 2 - localCharacter->GetSprite()->GetImage()->GetClipW() / 2);
|
||||||
camera.marginY = (GetScreen()->h / 2 - localCharacter->sprite.GetImage()->GetClipH() / 2);
|
camera.marginY = (GetScreen()->h / 2 - localCharacter->GetSprite()->GetImage()->GetClipH() / 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
|
void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
|
||||||
//TODO: authenticate when own character is being deleted (linked to a TODO in the server)
|
//TODO: authenticate when own character is being deleted (linked to a TODO in the server)
|
||||||
|
|
||||||
//catch this client's player object
|
//catch this client's player object
|
||||||
if (argPacket->characterIndex == characterIndex) {
|
if (argPacket->characterIndex == characterIndex) {
|
||||||
characterIndex = -1;
|
characterIndex = -1;
|
||||||
@@ -327,17 +344,17 @@ void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
|
|||||||
|
|
||||||
void InWorld::HandleCharacterUpdate(CharacterPacket* const argPacket) {
|
void InWorld::HandleCharacterUpdate(CharacterPacket* const argPacket) {
|
||||||
if (characterMap.find(argPacket->characterIndex) == characterMap.end()) {
|
if (characterMap.find(argPacket->characterIndex) == characterMap.end()) {
|
||||||
|
std::cout << "Warning: HandleCharacterUpdate() is passing to HandleCharacterNew()" << std::endl;
|
||||||
HandleCharacterNew(argPacket);
|
HandleCharacterNew(argPacket);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CharacterData& character = characterMap[argPacket->characterIndex];
|
Character& character = characterMap[argPacket->characterIndex];
|
||||||
|
|
||||||
//other characters moving
|
//other characters moving
|
||||||
if (argPacket->characterIndex != characterIndex) {
|
if (argPacket->characterIndex != characterIndex) {
|
||||||
character.roomIndex = argPacket->roomIndex;
|
character.SetOrigin(argPacket->origin);
|
||||||
character.origin = argPacket->origin;
|
character.SetMotion(argPacket->motion);
|
||||||
character.motion = argPacket->motion;
|
|
||||||
character.CorrectSprite();
|
character.CorrectSprite();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -364,6 +381,8 @@ void InWorld::RequestSynchronize() {
|
|||||||
newPacket.clientIndex = clientIndex;
|
newPacket.clientIndex = clientIndex;
|
||||||
newPacket.accountIndex = accountIndex;
|
newPacket.accountIndex = accountIndex;
|
||||||
|
|
||||||
|
//TODO: location, range for sync request
|
||||||
|
|
||||||
network.SendTo(Channels::SERVER, &newPacket);
|
network.SendTo(Channels::SERVER, &newPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,12 +393,12 @@ void InWorld::SendPlayerUpdate() {
|
|||||||
newPacket.type = SerialPacketType::CHARACTER_UPDATE;
|
newPacket.type = SerialPacketType::CHARACTER_UPDATE;
|
||||||
|
|
||||||
newPacket.characterIndex = characterIndex;
|
newPacket.characterIndex = characterIndex;
|
||||||
//handle, avatar
|
//NOTE: omitting the handle and avatar here
|
||||||
newPacket.accountIndex = accountIndex;
|
newPacket.accountIndex = accountIndex;
|
||||||
newPacket.roomIndex = localCharacter->roomIndex;
|
newPacket.roomIndex = 0; //TODO: room index
|
||||||
newPacket.origin = localCharacter->origin;
|
newPacket.origin = localCharacter->GetOrigin();
|
||||||
newPacket.motion = localCharacter->motion;
|
newPacket.motion = localCharacter->GetMotion();
|
||||||
newPacket.stats = localCharacter->stats;
|
newPacket.stats = *localCharacter->GetStats();
|
||||||
|
|
||||||
//TODO: gameplay components: equipment, items, buffs, debuffs
|
//TODO: gameplay components: equipment, items, buffs, debuffs
|
||||||
|
|
||||||
@@ -435,7 +454,7 @@ void InWorld::UpdateMap() {
|
|||||||
|
|
||||||
//prune distant regions
|
//prune distant regions
|
||||||
for (std::list<Region>::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); /* EMPTY */) {
|
for (std::list<Region>::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); /* EMPTY */) {
|
||||||
//check if the region is outside off this area
|
//check if the region is outside of this area
|
||||||
if (it->GetX() < xStart || it->GetX() > xEnd || it->GetY() < yStart || it->GetY() > yEnd) {
|
if (it->GetX() < xStart || it->GetX() > xEnd || it->GetY() < yStart || it->GetY() > yEnd) {
|
||||||
|
|
||||||
//clunky, but the alternative was time consuming
|
//clunky, but the alternative was time consuming
|
||||||
@@ -35,11 +35,9 @@
|
|||||||
#include "tile_sheet.hpp"
|
#include "tile_sheet.hpp"
|
||||||
|
|
||||||
//common
|
//common
|
||||||
#include "config_utility.hpp"
|
|
||||||
#include "frame_rate.hpp"
|
#include "frame_rate.hpp"
|
||||||
|
|
||||||
#include "combat_data.hpp"
|
#include "character.hpp"
|
||||||
#include "character_data.hpp"
|
|
||||||
|
|
||||||
//client
|
//client
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
@@ -51,13 +49,11 @@ class InWorld : public BaseScene {
|
|||||||
public:
|
public:
|
||||||
//Public access members
|
//Public access members
|
||||||
InWorld(
|
InWorld(
|
||||||
ConfigUtility* const argConfig,
|
|
||||||
UDPNetworkUtility* const argNetwork,
|
UDPNetworkUtility* const argNetwork,
|
||||||
int* const argClientIndex,
|
int* const argClientIndex,
|
||||||
int* const argAccountIndex,
|
int* const argAccountIndex,
|
||||||
int* const argCharacterIndex,
|
int* const argCharacterIndex,
|
||||||
std::map<int, CombatData>* argCombatMap,
|
CharacterMap* argCharacterMap
|
||||||
std::map<int, CharacterData>* argCharacterMap
|
|
||||||
);
|
);
|
||||||
~InWorld();
|
~InWorld();
|
||||||
|
|
||||||
@@ -96,13 +92,11 @@ protected:
|
|||||||
void UpdateMap();
|
void UpdateMap();
|
||||||
|
|
||||||
//shared parameters
|
//shared parameters
|
||||||
ConfigUtility& config;
|
|
||||||
UDPNetworkUtility& network;
|
UDPNetworkUtility& network;
|
||||||
int& clientIndex;
|
int& clientIndex;
|
||||||
int& accountIndex;
|
int& accountIndex;
|
||||||
int& characterIndex;
|
int& characterIndex;
|
||||||
std::map<int, CombatData>& combatMap;
|
CharacterMap& characterMap;
|
||||||
std::map<int, CharacterData>& characterMap;
|
|
||||||
|
|
||||||
//graphics
|
//graphics
|
||||||
Image buttonImage;
|
Image buttonImage;
|
||||||
@@ -124,7 +118,7 @@ protected:
|
|||||||
FrameRate fps;
|
FrameRate fps;
|
||||||
|
|
||||||
//game
|
//game
|
||||||
CharacterData* localCharacter = nullptr;
|
Character* localCharacter = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -31,12 +31,10 @@
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
LobbyMenu::LobbyMenu(
|
LobbyMenu::LobbyMenu(
|
||||||
ConfigUtility* const argConfig,
|
|
||||||
UDPNetworkUtility* const argNetwork,
|
UDPNetworkUtility* const argNetwork,
|
||||||
int* const argClientIndex,
|
int* const argClientIndex,
|
||||||
int* const argAccountIndex
|
int* const argAccountIndex
|
||||||
):
|
):
|
||||||
config(*argConfig),
|
|
||||||
network(*argNetwork),
|
network(*argNetwork),
|
||||||
clientIndex(*argClientIndex),
|
clientIndex(*argClientIndex),
|
||||||
accountIndex(*argAccountIndex)
|
accountIndex(*argAccountIndex)
|
||||||
@@ -41,7 +41,6 @@ class LobbyMenu : public BaseScene {
|
|||||||
public:
|
public:
|
||||||
//Public access members
|
//Public access members
|
||||||
LobbyMenu(
|
LobbyMenu(
|
||||||
ConfigUtility* const argConfig,
|
|
||||||
UDPNetworkUtility* const argNetwork,
|
UDPNetworkUtility* const argNetwork,
|
||||||
int* const argClientIndex,
|
int* const argClientIndex,
|
||||||
int* const argAccountIndex
|
int* const argAccountIndex
|
||||||
@@ -68,7 +67,7 @@ protected:
|
|||||||
void HandleJoinResponse(ClientPacket* const);
|
void HandleJoinResponse(ClientPacket* const);
|
||||||
|
|
||||||
//shared parameters
|
//shared parameters
|
||||||
ConfigUtility& config;
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
UDPNetworkUtility& network;
|
UDPNetworkUtility& network;
|
||||||
int& clientIndex;
|
int& clientIndex;
|
||||||
int& accountIndex;
|
int& accountIndex;
|
||||||
@@ -21,13 +21,15 @@
|
|||||||
*/
|
*/
|
||||||
#include "main_menu.hpp"
|
#include "main_menu.hpp"
|
||||||
|
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Public access members
|
//Public access members
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
MainMenu::MainMenu(ConfigUtility* const argConfig):
|
MainMenu::MainMenu() {
|
||||||
config(*argConfig)
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
{
|
|
||||||
//setup the utility objects
|
//setup the utility objects
|
||||||
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
||||||
image.SetClipH(image.GetClipH()/3);
|
image.SetClipH(image.GetClipH()/3);
|
||||||
@@ -101,6 +103,7 @@ void MainMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||||
|
//TODO: Buttons should only register as "selected" when the left button is used
|
||||||
if (startButton.MouseButtonUp(button) == Button::State::HOVER) {
|
if (startButton.MouseButtonUp(button) == Button::State::HOVER) {
|
||||||
SetNextScene(SceneList::LOBBYMENU);
|
SetNextScene(SceneList::LOBBYMENU);
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
#include "config_utility.hpp"
|
|
||||||
#include "image.hpp"
|
#include "image.hpp"
|
||||||
#include "raster_font.hpp"
|
#include "raster_font.hpp"
|
||||||
#include "button.hpp"
|
#include "button.hpp"
|
||||||
@@ -32,7 +31,7 @@
|
|||||||
class MainMenu : public BaseScene {
|
class MainMenu : public BaseScene {
|
||||||
public:
|
public:
|
||||||
//Public access members
|
//Public access members
|
||||||
MainMenu(ConfigUtility* const);
|
MainMenu();
|
||||||
~MainMenu();
|
~MainMenu();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -49,9 +48,6 @@ protected:
|
|||||||
void KeyDown(SDL_KeyboardEvent const&);
|
void KeyDown(SDL_KeyboardEvent const&);
|
||||||
void KeyUp(SDL_KeyboardEvent const&);
|
void KeyUp(SDL_KeyboardEvent const&);
|
||||||
|
|
||||||
//shared parameters
|
|
||||||
ConfigUtility& config;
|
|
||||||
|
|
||||||
//members
|
//members
|
||||||
Image image;
|
Image image;
|
||||||
RasterFont font;
|
RasterFont font;
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#config
|
||||||
|
INCLUDES+=. .. ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/network/packet ../../common/network/serial ../../common/ui ../../common/utilities
|
||||||
|
LIBS+=
|
||||||
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
#source
|
||||||
|
CXXSRC=$(wildcard *.cpp)
|
||||||
|
|
||||||
|
#objects
|
||||||
|
OBJDIR=obj
|
||||||
|
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||||
|
|
||||||
|
#output
|
||||||
|
OUTDIR=..
|
||||||
|
OUT=$(addprefix $(OUTDIR)/,client.a)
|
||||||
|
|
||||||
|
#targets
|
||||||
|
all: $(OBJ) $(OUT)
|
||||||
|
ar -crs $(OUT) $(OBJ)
|
||||||
|
|
||||||
|
$(OBJ): | $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUT): | $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR):
|
||||||
|
mkdir $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUTDIR):
|
||||||
|
mkdir $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR)/%.o: %.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) *.o *.a *.exe
|
||||||
|
|
||||||
|
rebuild: clean all
|
||||||
@@ -21,13 +21,15 @@
|
|||||||
*/
|
*/
|
||||||
#include "options_menu.hpp"
|
#include "options_menu.hpp"
|
||||||
|
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Public access members
|
//Public access members
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
OptionsMenu::OptionsMenu(ConfigUtility* const argConfig):
|
OptionsMenu::OptionsMenu() {
|
||||||
config(*argConfig)
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
{
|
|
||||||
//setup the utility objects
|
//setup the utility objects
|
||||||
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
||||||
image.SetClipH(image.GetClipH()/3);
|
image.SetClipH(image.GetClipH()/3);
|
||||||
@@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
#include "config_utility.hpp"
|
|
||||||
#include "image.hpp"
|
#include "image.hpp"
|
||||||
#include "raster_font.hpp"
|
#include "raster_font.hpp"
|
||||||
#include "button.hpp"
|
#include "button.hpp"
|
||||||
@@ -33,7 +32,7 @@
|
|||||||
class OptionsMenu : public BaseScene {
|
class OptionsMenu : public BaseScene {
|
||||||
public:
|
public:
|
||||||
//Public access members
|
//Public access members
|
||||||
OptionsMenu(ConfigUtility* const);
|
OptionsMenu();
|
||||||
~OptionsMenu();
|
~OptionsMenu();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -50,9 +49,6 @@ protected:
|
|||||||
void KeyDown(SDL_KeyboardEvent const&);
|
void KeyDown(SDL_KeyboardEvent const&);
|
||||||
void KeyUp(SDL_KeyboardEvent const&);
|
void KeyUp(SDL_KeyboardEvent const&);
|
||||||
|
|
||||||
//shared parameters
|
|
||||||
ConfigUtility& config;
|
|
||||||
|
|
||||||
//members
|
//members
|
||||||
Image image;
|
Image image;
|
||||||
RasterFont font;
|
RasterFont font;
|
||||||
@@ -21,14 +21,14 @@
|
|||||||
*/
|
*/
|
||||||
#include "splash_screen.hpp"
|
#include "splash_screen.hpp"
|
||||||
|
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Public access members
|
//Public access members
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
SplashScreen::SplashScreen(ConfigUtility* const argConfig):
|
SplashScreen::SplashScreen() {
|
||||||
config(*argConfig)
|
logo.LoadSurface(ConfigUtility::GetSingleton()["dir.logos"] + "krstudios.bmp");
|
||||||
{
|
|
||||||
logo.LoadSurface(config["dir.logos"] + "krstudios.bmp");
|
|
||||||
startTick = std::chrono::steady_clock::now();
|
startTick = std::chrono::steady_clock::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
#include "config_utility.hpp"
|
|
||||||
#include "image.hpp"
|
#include "image.hpp"
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
@@ -32,7 +31,7 @@
|
|||||||
class SplashScreen : public BaseScene {
|
class SplashScreen : public BaseScene {
|
||||||
public:
|
public:
|
||||||
//Public access members
|
//Public access members
|
||||||
SplashScreen(ConfigUtility* const);
|
SplashScreen();
|
||||||
~SplashScreen();
|
~SplashScreen();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -40,9 +39,6 @@ protected:
|
|||||||
void Update(double delta);
|
void Update(double delta);
|
||||||
void Render(SDL_Surface* const);
|
void Render(SDL_Surface* const);
|
||||||
|
|
||||||
//shared parameters
|
|
||||||
ConfigUtility& config;
|
|
||||||
|
|
||||||
//members
|
//members
|
||||||
std::chrono::steady_clock::time_point startTick;
|
std::chrono::steady_clock::time_point startTick;
|
||||||
Image logo;
|
Image logo;
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#config
|
||||||
|
INCLUDES+=.
|
||||||
|
LIBS+=
|
||||||
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
#source
|
||||||
|
CXXSRC=$(wildcard *.cpp)
|
||||||
|
|
||||||
|
#objects
|
||||||
|
OBJDIR=obj
|
||||||
|
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||||
|
|
||||||
|
#output
|
||||||
|
OUTDIR=../..
|
||||||
|
OUT=$(addprefix $(OUTDIR)/,libcommon.a)
|
||||||
|
|
||||||
|
#targets
|
||||||
|
all: $(OBJ) $(OUT)
|
||||||
|
ar -crs $(OUT) $(OBJ)
|
||||||
|
|
||||||
|
$(OBJ): | $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUT): | $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR):
|
||||||
|
mkdir $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUTDIR):
|
||||||
|
mkdir $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR)/%.o: %.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) *.o *.a *.exe
|
||||||
|
|
||||||
|
rebuild: clean all
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "timer.hpp"
|
||||||
|
|
||||||
|
Timer::Timer(): start(Timer::Clock::now()) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer::Timer(std::string s): name(s), start(Timer::Clock::now()) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void Timer::Start() {
|
||||||
|
start = Clock::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Timer::Stop() {
|
||||||
|
timeSpan = Clock::now() - start;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, Timer& t) {
|
||||||
|
os << t.GetName() << ": ";
|
||||||
|
os << std::chrono::duration_cast<std::chrono::milliseconds>(t.GetTime()).count();
|
||||||
|
os << "ms";
|
||||||
|
return os;
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#ifndef TIMER_HPP_
|
||||||
|
#define TIMER_HPP_
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <string>
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
|
class Timer {
|
||||||
|
public:
|
||||||
|
typedef std::chrono::high_resolution_clock Clock;
|
||||||
|
|
||||||
|
Timer();
|
||||||
|
Timer(std::string s);
|
||||||
|
~Timer() = default;
|
||||||
|
|
||||||
|
inline void Start();
|
||||||
|
inline void Stop();
|
||||||
|
|
||||||
|
//accessors and mutators
|
||||||
|
Clock::duration GetTime() { return timeSpan; }
|
||||||
|
|
||||||
|
std::string SetName(std::string s) { return name = s; }
|
||||||
|
std::string GetName() { return name; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string name;
|
||||||
|
Clock::time_point start;
|
||||||
|
Clock::duration timeSpan;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, Timer& t);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -19,24 +19,17 @@
|
|||||||
* 3. This notice may not be removed or altered from any source
|
* 3. This notice may not be removed or altered from any source
|
||||||
* distribution.
|
* distribution.
|
||||||
*/
|
*/
|
||||||
#ifndef ENEMYFACTORYGENERIC_HPP_
|
#ifndef CHARACTERDEFINES_HPP_
|
||||||
#define ENEMYFACTORYGENERIC_HPP_
|
#define CHARACTERDEFINES_HPP_
|
||||||
|
|
||||||
#include "enemy_factory_interface.hpp"
|
#include <cmath>
|
||||||
|
|
||||||
#include "enemy_data.hpp"
|
//the speeds that the characters move
|
||||||
|
constexpr double CHARACTER_WALKING_SPEED = 140.0;
|
||||||
|
constexpr double CHARACTER_WALKING_MOD = 1.0/sqrt(2.0);
|
||||||
|
|
||||||
#include <list>
|
//the bounding boxes for the characters
|
||||||
|
constexpr double CHARACTER_BOUNDS_WIDTH = 32.0;
|
||||||
//DOCS: Not really intended for use, but rather for copying and tweaking
|
constexpr double CHARACTER_BOUNDS_HEIGHT = 32.0;
|
||||||
class EnemyFactoryGeneric : public EnemyFactoryInterface {
|
|
||||||
public:
|
|
||||||
EnemyFactoryGeneric();
|
|
||||||
~EnemyFactoryGeneric() noexcept override;
|
|
||||||
|
|
||||||
void Generate(std::list<EnemyData>* container) override;
|
|
||||||
private:
|
|
||||||
//TODO: hold the parameters specified by the room
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -19,16 +19,16 @@
|
|||||||
* 3. This notice may not be removed or altered from any source
|
* 3. This notice may not be removed or altered from any source
|
||||||
* distribution.
|
* distribution.
|
||||||
*/
|
*/
|
||||||
#include "enemy_factory_generic.hpp"
|
#ifndef COMBATDEFINES_HPP_
|
||||||
|
#define COMBATDEFINES_HPP_
|
||||||
|
|
||||||
EnemyFactoryGeneric::EnemyFactoryGeneric() : EnemyFactoryInterface() {
|
#define COMBAT_MAX_CHARACTERS 16
|
||||||
//EMPTY
|
#define COMBAT_MAX_ENEMIES 16
|
||||||
}
|
|
||||||
|
|
||||||
EnemyFactoryGeneric::~EnemyFactoryGeneric() noexcept {
|
enum class TerrainType {
|
||||||
//EMPTY
|
NONE = 0,
|
||||||
}
|
GRASSLANDS,
|
||||||
|
//etc.
|
||||||
|
};
|
||||||
|
|
||||||
void EnemyFactoryGeneric::Generate(std::list<EnemyData>* container) {
|
#endif
|
||||||
//TODO: fill this out
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. ../utilities ../graphics
|
INCLUDES+=.
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) -DGRAPHICS
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
#source
|
#source
|
||||||
CXXSRC=$(wildcard *.cpp)
|
CXXSRC=$(wildcard *.cpp)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. ../map
|
INCLUDES+=.
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
all:
|
all:
|
||||||
|
$(MAKE) -C debugging
|
||||||
$(MAKE) -C gameplay
|
$(MAKE) -C gameplay
|
||||||
$(MAKE) -C graphics
|
$(MAKE) -C graphics
|
||||||
$(MAKE) -C map
|
$(MAKE) -C map
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. ../utilities
|
INCLUDES+=. ../graphics ../utilities
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ Region::Region(int argX, int argY): x(argX), y(argY) {
|
|||||||
|
|
||||||
Region::Region(Region const& rhs): x(rhs.x), y(rhs.y) {
|
Region::Region(Region const& rhs): x(rhs.x), y(rhs.y) {
|
||||||
memcpy(tiles, rhs.tiles, REGION_WIDTH*REGION_HEIGHT*REGION_DEPTH*sizeof(type_t));
|
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) {
|
Region::type_t Region::SetTile(int x, int y, int z, type_t v) {
|
||||||
@@ -44,3 +45,11 @@ Region::type_t Region::SetTile(int x, int y, int z, type_t v) {
|
|||||||
Region::type_t Region::GetTile(int x, int y, int z) {
|
Region::type_t Region::GetTile(int x, int y, int z) {
|
||||||
return tiles[x][y][z];
|
return tiles[x][y][z];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Region::SetSolid(int x, int y, bool b) {
|
||||||
|
return solid[x * REGION_WIDTH + y] = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Region::GetSolid(int x, int y) {
|
||||||
|
return solid[x * REGION_WIDTH + y];
|
||||||
|
}
|
||||||
@@ -22,10 +22,17 @@
|
|||||||
#ifndef REGION_HPP_
|
#ifndef REGION_HPP_
|
||||||
#define REGION_HPP_
|
#define REGION_HPP_
|
||||||
|
|
||||||
|
#include <bitset>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
//the region's storage format
|
||||||
constexpr int REGION_WIDTH = 20;
|
constexpr int REGION_WIDTH = 20;
|
||||||
constexpr int REGION_HEIGHT = 20;
|
constexpr int REGION_HEIGHT = 20;
|
||||||
constexpr int REGION_DEPTH = 3;
|
constexpr int REGION_DEPTH = 3;
|
||||||
|
|
||||||
|
//the size of the solid map
|
||||||
|
constexpr int REGION_SOLID_FOOTPRINT = ceil(REGION_WIDTH * REGION_HEIGHT / 8.0);
|
||||||
|
|
||||||
class Region {
|
class Region {
|
||||||
public:
|
public:
|
||||||
typedef unsigned char type_t;
|
typedef unsigned char type_t;
|
||||||
@@ -38,14 +45,23 @@ public:
|
|||||||
type_t SetTile(int x, int y, int z, type_t v);
|
type_t SetTile(int x, int y, int z, type_t v);
|
||||||
type_t GetTile(int x, int y, int z);
|
type_t GetTile(int x, int y, int z);
|
||||||
|
|
||||||
|
bool SetSolid(int x, int y, bool b);
|
||||||
|
bool GetSolid(int x, int y);
|
||||||
|
|
||||||
//accessors
|
//accessors
|
||||||
int GetX() const { return x; }
|
int GetX() const { return x; }
|
||||||
int GetY() const { return y; }
|
int GetY() const { return y; }
|
||||||
|
|
||||||
|
std::bitset<REGION_WIDTH*REGION_HEIGHT>* GetSolidBitset() { return &solid; }
|
||||||
private:
|
private:
|
||||||
const int x;
|
const int x;
|
||||||
const int y;
|
const int y;
|
||||||
|
|
||||||
type_t tiles[REGION_WIDTH][REGION_HEIGHT][REGION_DEPTH];
|
type_t tiles[REGION_WIDTH][REGION_HEIGHT][REGION_DEPTH];
|
||||||
|
std::bitset<REGION_WIDTH*REGION_HEIGHT> solid;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//the memory footprint of the tile and solid data; not including any metadata
|
||||||
|
constexpr int REGION_FOOTPRINT = REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t) + REGION_SOLID_FOOTPRINT;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+34
-18
@@ -37,6 +37,20 @@ static int getTile(lua_State* L) {
|
|||||||
return 1;
|
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) {
|
static int getX(lua_State* L) {
|
||||||
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
|
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
|
||||||
lua_pushinteger(L, region->GetX());
|
lua_pushinteger(L, region->GetX());
|
||||||
@@ -65,42 +79,44 @@ static int getDepth(lua_State* L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int load(lua_State* L) {
|
static int load(lua_State* L) {
|
||||||
//TODO: fill this
|
//EMPTY
|
||||||
lua_pushboolean(L, false);
|
lua_pushboolean(L, false);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int save(lua_State* L) {
|
static int save(lua_State* L) {
|
||||||
//TODO: fill this
|
//EMPTY
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int create(lua_State* L) {
|
static int create(lua_State* L) {
|
||||||
//TODO: fill this
|
//EMPTY
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int unload(lua_State* L) {
|
static int unload(lua_State* L) {
|
||||||
//TODO: fill this
|
//EMPTY
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const luaL_Reg regionlib[] = {
|
static const luaL_Reg regionLib[] = {
|
||||||
{"settile",setTile},
|
{"SetTile",setTile},
|
||||||
{"gettile",getTile},
|
{"GetTile",getTile},
|
||||||
{"getx",getX},
|
{"SetSolid",setSolid},
|
||||||
{"gety",getY},
|
{"GetSolid",getSolid},
|
||||||
{"getwidth",getWidth},
|
{"GetX",getX},
|
||||||
{"getheight",getHeight},
|
{"GetY",getY},
|
||||||
{"getdepth",getDepth},
|
{"GetWidth",getWidth},
|
||||||
{"load",load},
|
{"GetHeight",getHeight},
|
||||||
{"save",save},
|
{"GetDepth",getDepth},
|
||||||
{"create",create},
|
{"Load",load},
|
||||||
{"unload",unload},
|
{"Save",save},
|
||||||
|
{"Create",create},
|
||||||
|
{"Unload",unload},
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|
||||||
LUAMOD_API int luaopen_regionapi(lua_State* L) {
|
LUAMOD_API int openRegionAPI(lua_State* L) {
|
||||||
luaL_newlib(L, regionlib);
|
luaL_newlib(L, regionLib);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
#include "lua/lua.hpp"
|
#include "lua/lua.hpp"
|
||||||
|
|
||||||
#define LUA_REGIONLIBNAME "region"
|
#define TORTUGA_REGION_NAME "Region"
|
||||||
LUAMOD_API int luaopen_regionapi(lua_State* L);
|
LUAMOD_API int openRegionAPI(lua_State* L);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -19,14 +19,15 @@
|
|||||||
* 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 "pager_api.hpp"
|
#include "region_pager_api.hpp"
|
||||||
|
|
||||||
#include "region_pager_lua.hpp"
|
#include "region_pager_lua.hpp"
|
||||||
#include "region.hpp"
|
#include "region.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
//DOCS: These glue functions simply wrap RegionPagerLua's methods
|
||||||
|
|
||||||
static int setTile(lua_State* L) {
|
static int setTile(lua_State* L) {
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
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));
|
int ret = pager->SetTile(lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
|
||||||
@@ -41,6 +42,20 @@ static int getTile(lua_State* L) {
|
|||||||
return 1;
|
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) {
|
static int getRegion(lua_State* L) {
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
||||||
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||||
@@ -48,109 +63,47 @@ static int getRegion(lua_State* L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int setDirectory(lua_State* L) {
|
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
|
||||||
std::string s = pager->SetDirectory(lua_tostring(L, 2));
|
|
||||||
lua_pushstring(L, s.c_str());
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int getDirectory(lua_State* L) {
|
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
|
||||||
std::string s = pager->GetDirectory();
|
|
||||||
lua_pushstring(L, s.c_str());
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int loadRegion(lua_State* L) {
|
static int loadRegion(lua_State* L) {
|
||||||
//get the parameters
|
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
||||||
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
Region* region = pager->LoadRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||||
std::string s = pager->GetDirectory();
|
|
||||||
|
|
||||||
//push the parameters
|
|
||||||
lua_getglobal(L, "region");
|
|
||||||
lua_getfield(L, -1, "load");
|
|
||||||
lua_pushlightuserdata(L, region);
|
lua_pushlightuserdata(L, region);
|
||||||
lua_pushstring(L, s.c_str());
|
|
||||||
|
|
||||||
//call the method
|
|
||||||
if (lua_pcall(L, 2, 1, 0) != LUA_OK) {
|
|
||||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(L, -1) ));
|
|
||||||
}
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int saveRegion(lua_State* L) {
|
static int saveRegion(lua_State* L) {
|
||||||
//get the parameters
|
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
||||||
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
Region* region = pager->SaveRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||||
std::string s = pager->GetDirectory();
|
|
||||||
|
|
||||||
//push the parameters
|
|
||||||
lua_getglobal(L, "region");
|
|
||||||
lua_getfield(L, -1, "save");
|
|
||||||
lua_pushlightuserdata(L, region);
|
lua_pushlightuserdata(L, region);
|
||||||
lua_pushstring(L, s.c_str());
|
return 1;
|
||||||
|
|
||||||
//call the method
|
|
||||||
if (lua_pcall(L, 2, 0, 0) != LUA_OK) {
|
|
||||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(L, -1) ));
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int createRegion(lua_State* L) {
|
static int createRegion(lua_State* L) {
|
||||||
//get the parameters
|
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
||||||
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
Region* region = pager->CreateRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||||
|
|
||||||
//push the parameters
|
|
||||||
lua_getglobal(L, "region");
|
|
||||||
lua_getfield(L, -1, "create");
|
|
||||||
lua_pushlightuserdata(L, region);
|
lua_pushlightuserdata(L, region);
|
||||||
//TODO: parameters
|
return 1;
|
||||||
|
|
||||||
//call the method
|
|
||||||
if (lua_pcall(L, 1, 0, 0) != LUA_OK) {
|
|
||||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(L, -1) ));
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int unloadRegion(lua_State* L) {
|
static int unloadRegion(lua_State* L) {
|
||||||
//get the parameters
|
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
||||||
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
pager->UnloadRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||||
std::string s = pager->GetDirectory();
|
|
||||||
|
|
||||||
//push the parameters
|
|
||||||
lua_getglobal(L, "region");
|
|
||||||
lua_getfield(L, -1, "unload");
|
|
||||||
lua_pushlightuserdata(L, region);
|
|
||||||
lua_pushstring(L, s.c_str());
|
|
||||||
|
|
||||||
//call the method
|
|
||||||
if (lua_pcall(L, 2, 0, 0) != LUA_OK) {
|
|
||||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(L, -1) ));
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const luaL_Reg pagerlib[] = {
|
static const luaL_Reg regionPagerLib[] = {
|
||||||
{"settile", setTile},
|
{"SetTile", setTile},
|
||||||
{"gettile", getTile},
|
{"GetTile", getTile},
|
||||||
{"getregion", getRegion},
|
{"SetSolid", setSolid},
|
||||||
{"setdirectory", setDirectory},
|
{"GetSolid", getSolid},
|
||||||
{"getdirectory", getDirectory},
|
{"GetRegion", getRegion},
|
||||||
{"loadregion", loadRegion},
|
{"LoadRegion", loadRegion},
|
||||||
{"saveregion", saveRegion},
|
{"SaveRegion", saveRegion},
|
||||||
{"createregion", createRegion},
|
{"CreateRegion", createRegion},
|
||||||
{"unloadregion", unloadRegion},
|
{"UnloadRegion", unloadRegion},
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|
||||||
LUAMOD_API int luaopen_pagerapi(lua_State* L) {
|
LUAMOD_API int openRegionPagerAPI(lua_State* L) {
|
||||||
luaL_newlib(L, pagerlib);
|
luaL_newlib(L, regionPagerLib);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -19,13 +19,12 @@
|
|||||||
* 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 "character_data.hpp"
|
#ifndef REGIONPAGERAPI_HPP_
|
||||||
#include "combat_data.hpp"
|
#define REGIONPAGERAPI_HPP_
|
||||||
#include "enemy_data.hpp"
|
|
||||||
#include "statistics.hpp"
|
|
||||||
|
|
||||||
/* DOCS: Sanity check, read more
|
#include "lua/lua.hpp"
|
||||||
* Since most/all of the files in this directory are header files, I've created
|
|
||||||
* this source file as a "sanity check", to ensure that the above header files
|
#define TORTUGA_REGION_PAGER_NAME "RegionPager"
|
||||||
* are written correctly via make.
|
LUAMOD_API int openRegionPagerAPI(lua_State* L);
|
||||||
*/
|
|
||||||
|
#endif
|
||||||
@@ -36,7 +36,20 @@ Region::type_t RegionPagerBase::GetTile(int x, int y, int z) {
|
|||||||
return ptr->GetTile(x - ptr->GetX(), y - ptr->GetY(), z);
|
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) {
|
Region* RegionPagerBase::GetRegion(int x, int y) {
|
||||||
|
x = snapToBase(REGION_WIDTH, x);
|
||||||
|
y = snapToBase(REGION_HEIGHT, y);
|
||||||
|
|
||||||
//get the region by various means
|
//get the region by various means
|
||||||
Region* ptr = nullptr;
|
Region* ptr = nullptr;
|
||||||
ptr = FindRegion(x, y);
|
ptr = FindRegion(x, y);
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ public:
|
|||||||
virtual Region::type_t SetTile(int x, int y, int z, Region::type_t v);
|
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);
|
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
|
//region manipulation
|
||||||
virtual Region* GetRegion(int x, int y);
|
virtual Region* GetRegion(int x, int y);
|
||||||
virtual Region* FindRegion(int x, int y);
|
virtual Region* FindRegion(int x, int y);
|
||||||
|
|||||||
@@ -29,23 +29,22 @@ Region* RegionPagerLua::LoadRegion(int x, int y) {
|
|||||||
//load the region if possible
|
//load the region if possible
|
||||||
|
|
||||||
//something to work on
|
//something to work on
|
||||||
regionList.emplace_front(x, y);
|
Region tmpRegion(x, y);
|
||||||
|
|
||||||
//API hook
|
//API hook
|
||||||
lua_getglobal(luaState, "region");
|
lua_getglobal(lua, "Region");
|
||||||
lua_getfield(luaState, -1, "load");
|
lua_getfield(lua, -1, "Load");
|
||||||
lua_pushlightuserdata(luaState, ®ionList.front());
|
lua_pushlightuserdata(lua, &tmpRegion);
|
||||||
lua_pushstring(luaState, directory.c_str());
|
if (lua_pcall(lua, 1, 1, 0) != LUA_OK) {
|
||||||
if (lua_pcall(luaState, 2, 1, 0) != LUA_OK) {
|
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
|
||||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
|
|
||||||
}
|
}
|
||||||
//success or failure
|
//success or failure
|
||||||
if (!lua_toboolean(luaState, -1)) {
|
if (!lua_toboolean(lua, -1)) {
|
||||||
lua_pop(luaState, 2);
|
lua_pop(lua, 2);
|
||||||
regionList.pop_front();
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
lua_pop(luaState, 2);
|
lua_pop(lua, 2);
|
||||||
|
regionList.push_front(tmpRegion);
|
||||||
return ®ionList.front();
|
return ®ionList.front();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,14 +53,13 @@ Region* RegionPagerLua::SaveRegion(int x, int y) {
|
|||||||
Region* ptr = FindRegion(x, y);
|
Region* ptr = FindRegion(x, y);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
//API hook
|
//API hook
|
||||||
lua_getglobal(luaState, "region");
|
lua_getglobal(lua, "Region");
|
||||||
lua_getfield(luaState, -1, "save");
|
lua_getfield(lua, -1, "Save");
|
||||||
lua_pushlightuserdata(luaState, ptr);
|
lua_pushlightuserdata(lua, ptr);
|
||||||
lua_pushstring(luaState, directory.c_str());
|
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) {
|
||||||
if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
|
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
|
||||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
|
|
||||||
}
|
}
|
||||||
lua_pop(luaState, 1);
|
lua_pop(lua, 1);
|
||||||
}
|
}
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
@@ -72,32 +70,32 @@ Region* RegionPagerLua::CreateRegion(int x, int y) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//something to work on
|
//something to work on
|
||||||
regionList.emplace_front(x, y);
|
Region tmpRegion(x, y);
|
||||||
|
|
||||||
//API hook
|
//API hook
|
||||||
lua_getglobal(luaState, "region");
|
lua_getglobal(lua, "Region");
|
||||||
lua_getfield(luaState, -1, "create");
|
lua_getfield(lua, -1, "Create");
|
||||||
lua_pushlightuserdata(luaState, ®ionList.front());
|
lua_pushlightuserdata(lua, &tmpRegion);
|
||||||
//TODO: parameters
|
//TODO: parameters
|
||||||
if (lua_pcall(luaState, 1, 0, 0) != LUA_OK) {
|
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) {
|
||||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
|
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
|
||||||
}
|
}
|
||||||
lua_pop(luaState, 1);
|
lua_pop(lua, 1);
|
||||||
return ®ionList.front();;
|
regionList.push_front(tmpRegion);
|
||||||
|
return ®ionList.front();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegionPagerLua::UnloadRegion(int x, int y) {
|
void RegionPagerLua::UnloadRegion(int x, int y) {
|
||||||
lua_getglobal(luaState, "region");
|
lua_getglobal(lua, "Region");
|
||||||
|
|
||||||
regionList.remove_if([&](Region& region) -> bool {
|
regionList.remove_if([&](Region& region) -> bool {
|
||||||
if (region.GetX() == x && region.GetY() == y) {
|
if (region.GetX() == x && region.GetY() == y) {
|
||||||
|
|
||||||
//API hook
|
//API hook
|
||||||
lua_getfield(luaState, -1, "unload");
|
lua_getfield(lua, -1, "Unload");
|
||||||
lua_pushlightuserdata(luaState, ®ion);
|
lua_pushlightuserdata(lua, ®ion);
|
||||||
lua_pushstring(luaState, directory.c_str());
|
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) {
|
||||||
if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
|
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
|
||||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -105,22 +103,21 @@ void RegionPagerLua::UnloadRegion(int x, int y) {
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
lua_pop(luaState, 1);
|
lua_pop(lua, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegionPagerLua::UnloadAll() {
|
void RegionPagerLua::UnloadAll() {
|
||||||
lua_getglobal(luaState, "region");
|
lua_getglobal(lua, "Region");
|
||||||
|
|
||||||
for (auto& it : regionList) {
|
for (auto& it : regionList) {
|
||||||
//API hook
|
//API hook
|
||||||
lua_getfield(luaState, -1, "unload");
|
lua_getfield(lua, -1, "Unload");
|
||||||
lua_pushlightuserdata(luaState, &it);
|
lua_pushlightuserdata(lua, &it);
|
||||||
lua_pushstring(luaState, directory.c_str());
|
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) {
|
||||||
if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
|
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
|
||||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_pop(luaState, 1);
|
lua_pop(lua, 1);
|
||||||
regionList.clear();
|
regionList.clear();
|
||||||
}
|
}
|
||||||
@@ -41,14 +41,11 @@ public:
|
|||||||
|
|
||||||
void UnloadAll() override;
|
void UnloadAll() override;
|
||||||
|
|
||||||
std::string SetDirectory(std::string s) { return directory = s; }
|
//accessors & mutators
|
||||||
std::string GetDirectory() { return directory; }
|
lua_State* SetLuaState(lua_State* L) { return lua = L; }
|
||||||
|
lua_State* GetLuaState() { return lua; }
|
||||||
lua_State* SetLuaState(lua_State* L) { return luaState = L; }
|
|
||||||
lua_State* GetLuaState() { return luaState; }
|
|
||||||
protected:
|
protected:
|
||||||
std::string directory;
|
lua_State* lua = nullptr;
|
||||||
lua_State* luaState = nullptr;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -21,24 +21,24 @@
|
|||||||
*/
|
*/
|
||||||
#include "tile_sheet.hpp"
|
#include "tile_sheet.hpp"
|
||||||
|
|
||||||
void TileSheet::Load(std::string fname, int xc, int yc) {
|
void TileSheet::Load(std::string fname, int tileWidth, int tileHeight) {
|
||||||
XCount = xc;
|
|
||||||
YCount = yc;
|
|
||||||
image.LoadSurface(fname);
|
image.LoadSurface(fname);
|
||||||
image.SetClipW(image.GetClipW()/XCount);
|
image.SetClipW(tileWidth);
|
||||||
image.SetClipH(image.GetClipH()/YCount);
|
image.SetClipH(tileHeight);
|
||||||
|
xCount = image.GetSurface()->w / image.GetClipW();
|
||||||
|
yCount = image.GetSurface()->h / image.GetClipH();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileSheet::Unload() {
|
void TileSheet::Unload() {
|
||||||
image.FreeSurface();
|
image.FreeSurface();
|
||||||
XCount = YCount = 0;
|
xCount = yCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileSheet::DrawTo(SDL_Surface* const dest, int x, int y, Region::type_t tile) {
|
void TileSheet::DrawTileTo(SDL_Surface* const dest, int x, int y, Region::type_t tile) {
|
||||||
//0 is invisible
|
//0 is invisible
|
||||||
if (tile == 0) return;
|
if (tile == 0) return;
|
||||||
image.SetClipX((tile-1) % XCount * image.GetClipW());
|
image.SetClipX((tile-1) % xCount * image.GetClipW());
|
||||||
image.SetClipY((tile-1) / XCount * image.GetClipH());
|
image.SetClipY((tile-1) / xCount * image.GetClipH());
|
||||||
image.DrawTo(dest, x, y);
|
image.DrawTo(dest, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,8 +50,8 @@ void TileSheet::DrawRegionTo(SDL_Surface* const dest, Region* const region, int
|
|||||||
tile = region->GetTile(i, j, k);
|
tile = region->GetTile(i, j, k);
|
||||||
//0 is invisible
|
//0 is invisible
|
||||||
if (tile == 0) continue;
|
if (tile == 0) continue;
|
||||||
image.SetClipX((tile-1) % XCount * image.GetClipW());
|
image.SetClipX((tile-1) % xCount * image.GetClipW());
|
||||||
image.SetClipY((tile-1) / XCount * image.GetClipH());
|
image.SetClipY((tile-1) / xCount * image.GetClipH());
|
||||||
image.DrawTo(dest,
|
image.DrawTo(dest,
|
||||||
(region->GetX() + i) * image.GetClipW() - camX,
|
(region->GetX() + i) * image.GetClipW() - camX,
|
||||||
(region->GetY() + j) * image.GetClipH() - camY);
|
(region->GetY() + j) * image.GetClipH() - camY);
|
||||||
@@ -31,24 +31,24 @@
|
|||||||
class TileSheet {
|
class TileSheet {
|
||||||
public:
|
public:
|
||||||
TileSheet() = default;
|
TileSheet() = default;
|
||||||
TileSheet(std::string f, int x, int y) { Load(f, x, y); }
|
TileSheet(std::string f, int w, int h) { Load(f, w, h); }
|
||||||
~TileSheet() = default;
|
~TileSheet() = default;
|
||||||
|
|
||||||
void Load(std::string fname, int XCount, int YCount);
|
void Load(std::string fname, int tileWidth, int tileHeight);
|
||||||
void Unload();
|
void Unload();
|
||||||
|
|
||||||
void DrawTo(SDL_Surface* const dest, int x, int y, Region::type_t tile);
|
void DrawTileTo(SDL_Surface* const dest, int x, int y, Region::type_t tile);
|
||||||
void DrawRegionTo(SDL_Surface* const dest, Region* const region, int camX, int camY);
|
void DrawRegionTo(SDL_Surface* const dest, Region* const region, int camX, int camY);
|
||||||
|
|
||||||
//accessors
|
//accessors
|
||||||
Image* GetImage() { return ℑ }
|
Image* GetImage() { return ℑ }
|
||||||
int GetXCount() { return XCount; }
|
int GetXCount() { return xCount; }
|
||||||
int GetYCount() { return YCount; }
|
int GetYCount() { return yCount; }
|
||||||
int GetTileW() { return image.GetClipW(); }
|
int GetTileW() { return image.GetClipW(); }
|
||||||
int GetTileH() { return image.GetClipH(); }
|
int GetTileH() { return image.GetClipH(); }
|
||||||
private:
|
private:
|
||||||
Image image;
|
Image image;
|
||||||
int XCount = 0, YCount = 0;
|
int xCount = 0, yCount = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "tile_sheet_api.hpp"
|
||||||
|
|
||||||
|
#include "tile_sheet.hpp"
|
||||||
|
|
||||||
|
static int load(lua_State* L) {
|
||||||
|
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
|
||||||
|
sheet->Load(lua_tostring(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int unload(lua_State* L) {
|
||||||
|
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
|
||||||
|
sheet->Unload();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getXCount(lua_State* L) {
|
||||||
|
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
|
||||||
|
lua_pushinteger(L, sheet->GetXCount());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getYCount(lua_State* L) {
|
||||||
|
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
|
||||||
|
lua_pushinteger(L, sheet->GetYCount());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getTileW(lua_State* L) {
|
||||||
|
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
|
||||||
|
lua_pushinteger(L, sheet->GetTileW());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getTileH(lua_State* L) {
|
||||||
|
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
|
||||||
|
lua_pushinteger(L, sheet->GetTileH());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const luaL_Reg tileSheetLib[] = {
|
||||||
|
{"Load",load},
|
||||||
|
{"Unload",unload},
|
||||||
|
{"GetXCount",getXCount},
|
||||||
|
{"GetYCount",getYCount},
|
||||||
|
{"GetTileW",getTileW},
|
||||||
|
{"GetTileH",getTileH},
|
||||||
|
{nullptr, nullptr}
|
||||||
|
};
|
||||||
|
|
||||||
|
LUAMOD_API int openTileSheetAPI(lua_State* L) {
|
||||||
|
luaL_newlib(L, tileSheetLib);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#ifndef TILESHEETAPI_HPP_
|
||||||
|
#define TILESHEETAPI_HPP_
|
||||||
|
|
||||||
|
#include "lua/lua.hpp"
|
||||||
|
|
||||||
|
#define TORTUGA_TILE_SHEET_NAME "TileSheet"
|
||||||
|
LUAMOD_API int openTileSheetAPI(lua_State* L);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -24,13 +24,13 @@
|
|||||||
|
|
||||||
#include "serial_packet_base.hpp"
|
#include "serial_packet_base.hpp"
|
||||||
|
|
||||||
#include "combat_data.hpp"
|
#include "combat_defines.hpp"
|
||||||
|
|
||||||
struct CombatPacket : SerialPacketBase {
|
struct CombatPacket : SerialPacketBase {
|
||||||
//identify the combat instance
|
//identify the combat instance
|
||||||
int combatIndex;
|
int combatIndex;
|
||||||
int difficulty;
|
int difficulty;
|
||||||
CombatData::Terrain terrainType;
|
TerrainType terrainType;
|
||||||
|
|
||||||
//combatants
|
//combatants
|
||||||
int characterArray[COMBAT_MAX_CHARACTERS];
|
int characterArray[COMBAT_MAX_CHARACTERS];
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
#include "SDL/SDL_net.h"
|
#include "SDL/SDL_net.h"
|
||||||
|
|
||||||
constexpr int NETWORK_VERSION = 20140607;
|
constexpr int NETWORK_VERSION = 20140701;
|
||||||
constexpr int PACKET_STRING_SIZE = 100;
|
constexpr int PACKET_STRING_SIZE = 100;
|
||||||
|
|
||||||
struct SerialPacketBase {
|
struct SerialPacketBase {
|
||||||
|
|||||||
@@ -53,13 +53,15 @@ void deserializeRegionContent(RegionPacket*, void*);
|
|||||||
void deserializeServer(ServerPacket*, void*);
|
void deserializeServer(ServerPacket*, void*);
|
||||||
void deserializeStatistics(Statistics*, void*);
|
void deserializeStatistics(Statistics*, void*);
|
||||||
|
|
||||||
/* DOCS: Keep the PACKET_BUFFER_SIZE up to date
|
/* DOCS: Keep PACKET_BUFFER_SIZE up to date
|
||||||
* DOCS: REGION_CONTENT is currently the largest type of packet, read more
|
* DOCS: SerialPacketType::REGION_CONTENT is currently the largest type of packet, read more
|
||||||
* map content: REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizoeof(region::type_t)
|
* The metadata used are:
|
||||||
* map format: sizeof(int) * 3
|
* SerialPacketType
|
||||||
* metadata: sizeof(SerialPacket::Type)
|
* room index
|
||||||
|
* X & Y positon
|
||||||
|
* The rest is taken up by the Regions's content.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
constexpr int PACKET_BUFFER_SIZE = REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t) + sizeof(int) * 3 + sizeof(SerialPacketType);
|
constexpr int PACKET_BUFFER_SIZE = sizeof(SerialPacketType) + sizeof(int) * 3 + REGION_FOOTPRINT;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -29,7 +29,7 @@ void serializeCombat(CombatPacket* packet, void* buffer) {
|
|||||||
//identify the combat instance
|
//identify the combat instance
|
||||||
SERIALIZE(buffer, &packet->combatIndex, sizeof(int));
|
SERIALIZE(buffer, &packet->combatIndex, sizeof(int));
|
||||||
SERIALIZE(buffer, &packet->difficulty, sizeof(int));
|
SERIALIZE(buffer, &packet->difficulty, sizeof(int));
|
||||||
SERIALIZE(buffer, &packet->terrainType, sizeof(CombatData::Terrain));
|
SERIALIZE(buffer, &packet->terrainType, sizeof(TerrainType));
|
||||||
|
|
||||||
//combatants
|
//combatants
|
||||||
SERIALIZE(buffer, &packet->characterArray, sizeof(int) * COMBAT_MAX_CHARACTERS);
|
SERIALIZE(buffer, &packet->characterArray, sizeof(int) * COMBAT_MAX_CHARACTERS);
|
||||||
@@ -49,7 +49,7 @@ void deserializeCombat(CombatPacket* packet, void* buffer) {
|
|||||||
//identify the combat instance
|
//identify the combat instance
|
||||||
DESERIALIZE(buffer, &packet->combatIndex, sizeof(int));
|
DESERIALIZE(buffer, &packet->combatIndex, sizeof(int));
|
||||||
DESERIALIZE(buffer, &packet->difficulty, sizeof(int));
|
DESERIALIZE(buffer, &packet->difficulty, sizeof(int));
|
||||||
DESERIALIZE(buffer, &packet->terrainType, sizeof(CombatData::Terrain));
|
DESERIALIZE(buffer, &packet->terrainType, sizeof(TerrainType));
|
||||||
|
|
||||||
//combatants
|
//combatants
|
||||||
DESERIALIZE(buffer, &packet->characterArray, sizeof(int) * COMBAT_MAX_CHARACTERS);
|
DESERIALIZE(buffer, &packet->characterArray, sizeof(int) * COMBAT_MAX_CHARACTERS);
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ void serializeRegionContent(RegionPacket* packet, void* buffer) {
|
|||||||
SERIALIZE(buffer, &packet->x, sizeof(int));
|
SERIALIZE(buffer, &packet->x, sizeof(int));
|
||||||
SERIALIZE(buffer, &packet->y, sizeof(int));
|
SERIALIZE(buffer, &packet->y, sizeof(int));
|
||||||
|
|
||||||
//content
|
//tiles
|
||||||
for (register int i = 0; i < REGION_WIDTH; i++) {
|
for (register int i = 0; i < REGION_WIDTH; i++) {
|
||||||
for (register int j = 0; j < REGION_HEIGHT; j++) {
|
for (register int j = 0; j < REGION_HEIGHT; j++) {
|
||||||
for (register int k = 0; k < REGION_DEPTH; k++) {
|
for (register int k = 0; k < REGION_DEPTH; k++) {
|
||||||
@@ -49,6 +49,9 @@ void serializeRegionContent(RegionPacket* packet, void* buffer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//solids
|
||||||
|
SERIALIZE(buffer, packet->region->GetSolidBitset(), REGION_SOLID_FOOTPRINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void deserializeRegionFormat(RegionPacket* packet, void* buffer) {
|
void deserializeRegionFormat(RegionPacket* packet, void* buffer) {
|
||||||
@@ -71,7 +74,7 @@ void deserializeRegionContent(RegionPacket* packet, void* buffer) {
|
|||||||
//an object to work on
|
//an object to work on
|
||||||
packet->region = new Region(packet->x, packet->y);
|
packet->region = new Region(packet->x, packet->y);
|
||||||
|
|
||||||
//content
|
//tiles
|
||||||
for (register int i = 0; i < REGION_WIDTH; i++) {
|
for (register int i = 0; i < REGION_WIDTH; i++) {
|
||||||
for (register int j = 0; j < REGION_HEIGHT; j++) {
|
for (register int j = 0; j < REGION_HEIGHT; j++) {
|
||||||
for (register int k = 0; k < REGION_DEPTH; k++) {
|
for (register int k = 0; k < REGION_DEPTH; k++) {
|
||||||
@@ -80,4 +83,7 @@ void deserializeRegionContent(RegionPacket* packet, void* buffer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//solids
|
||||||
|
DESERIALIZE(buffer, packet->region->GetSolidBitset(), REGION_SOLID_FOOTPRINT);
|
||||||
}
|
}
|
||||||
@@ -36,6 +36,7 @@
|
|||||||
* This class needs a rewrite.
|
* This class needs a rewrite.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
//TODO: This thing is fucking terrible, fix it and the button class
|
||||||
class MenuBar {
|
class MenuBar {
|
||||||
public:
|
public:
|
||||||
MenuBar() = default;
|
MenuBar() = default;
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#ifndef BOUNDINGBOX_HPP_
|
||||||
|
#define BOUNDINGBOX_HPP_
|
||||||
|
|
||||||
|
#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, 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<Vector2>::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;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -25,25 +25,37 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
using namespace std;
|
void ConfigUtility::Load(std::string fname) {
|
||||||
|
//clear the stored configuration
|
||||||
|
configMap.clear();
|
||||||
|
//pass to the recursive method
|
||||||
|
configMap = Read(fname);
|
||||||
|
}
|
||||||
|
|
||||||
void ConfigUtility::Load(string fname) {
|
ConfigUtility::table_t ConfigUtility::Read(std::string fname) {
|
||||||
ifstream is(fname);
|
//read in and return this file's data
|
||||||
|
table_t retTable;
|
||||||
|
std::ifstream is(fname);
|
||||||
|
|
||||||
if (!is.is_open()) {
|
if (!is.is_open()) {
|
||||||
throw(runtime_error("Failed to open config file"));
|
std::string msg;
|
||||||
|
msg += "Failed to open a config file: ";
|
||||||
|
msg += fname;
|
||||||
|
throw(std::runtime_error(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
string key, val;
|
std::string key, val;
|
||||||
|
|
||||||
for (;;) { //forever
|
while(true) { //forever
|
||||||
//eat whitespace
|
//eat whitespace
|
||||||
while(isspace(is.peek()))
|
while(isspace(is.peek())) {
|
||||||
is.ignore();
|
is.ignore();
|
||||||
|
}
|
||||||
|
|
||||||
//end of file
|
//end of file
|
||||||
if (is.eof())
|
if (is.eof()) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
//skip comment lines
|
//skip comment lines
|
||||||
if (is.peek() == '#') {
|
if (is.peek() == '#') {
|
||||||
@@ -64,41 +76,54 @@ void ConfigUtility::Load(string fname) {
|
|||||||
while(key.size() && isspace(*(key.end()-1))) key.erase(key.end() - 1);
|
while(key.size() && isspace(*(key.end()-1))) key.erase(key.end() - 1);
|
||||||
while(val.size() && isspace(*(val.end()-1))) val.erase(val.end() - 1);
|
while(val.size() && isspace(*(val.end()-1))) val.erase(val.end() - 1);
|
||||||
|
|
||||||
//allow empty/wiped values
|
//disallow empty/wiped values
|
||||||
if (key.size() == 0) {
|
if (key.size() == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//save the pair
|
//save the pair
|
||||||
table[key] = val;
|
retTable[key] = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
is.close();
|
is.close();
|
||||||
|
|
||||||
|
//load in any subordinate config files
|
||||||
|
//TODO: Possibility of nesting config levels?
|
||||||
|
if (retTable.find("config.next") != retTable.end()) {
|
||||||
|
table_t subTable = Read(retTable["config.next"]);
|
||||||
|
retTable.insert(subTable.begin(), subTable.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
return retTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Convert to a type
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
std::string& ConfigUtility::String(std::string s) {
|
std::string& ConfigUtility::String(std::string s) {
|
||||||
return table[s];
|
return configMap[s];
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConfigUtility::Integer(std::string s) {
|
int ConfigUtility::Integer(std::string s) {
|
||||||
std::map<std::string, std::string>::iterator it = table.find(s);
|
table_t::iterator it = configMap.find(s);
|
||||||
if (it == table.end()) {
|
if (it == configMap.end()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return atoi(it->second.c_str());
|
return atoi(it->second.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
double ConfigUtility::Double(std::string s) {
|
double ConfigUtility::Double(std::string s) {
|
||||||
std::map<std::string, std::string>::iterator it = table.find(s);
|
table_t::iterator it = configMap.find(s);
|
||||||
if (it == table.end()) {
|
if (it == configMap.end()) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
return atof(it->second.c_str());
|
return atof(it->second.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfigUtility::Boolean(std::string s) {
|
bool ConfigUtility::Boolean(std::string s) {
|
||||||
std::map<std::string, std::string>::iterator it = table.find(s);
|
table_t::iterator it = configMap.find(s);
|
||||||
if (it == table.end()) {
|
if (it == configMap.end()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return it->second == "true";
|
return it->second == "true";
|
||||||
|
|||||||
@@ -22,14 +22,13 @@
|
|||||||
#ifndef CONFIGUTILITY_HPP_
|
#ifndef CONFIGUTILITY_HPP_
|
||||||
#define CONFIGUTILITY_HPP_
|
#define CONFIGUTILITY_HPP_
|
||||||
|
|
||||||
|
#include "singleton.hpp"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class ConfigUtility {
|
class ConfigUtility : public Singleton<ConfigUtility> {
|
||||||
public:
|
public:
|
||||||
ConfigUtility() = default;
|
|
||||||
ConfigUtility(std::string s) { Load(s); }
|
|
||||||
|
|
||||||
void Load(std::string fname);
|
void Load(std::string fname);
|
||||||
|
|
||||||
//convert to a type
|
//convert to a type
|
||||||
@@ -39,22 +38,21 @@ public:
|
|||||||
bool Boolean(std::string);
|
bool Boolean(std::string);
|
||||||
|
|
||||||
//shorthand
|
//shorthand
|
||||||
std::string& operator[](std::string s) {
|
inline std::string& operator[](std::string s) { return configMap[s]; }
|
||||||
return String(s);
|
inline int Int(std::string s) { return Integer(s); }
|
||||||
}
|
inline bool Bool(std::string s) { return Boolean(s); }
|
||||||
int Int(std::string s) {
|
|
||||||
return Integer(s);
|
|
||||||
}
|
|
||||||
bool Bool(std::string s) {
|
|
||||||
return Boolean(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
//OO breaker
|
|
||||||
std::map<std::string, std::string>* GetMap() {
|
|
||||||
return &table;
|
|
||||||
}
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, std::string> table;
|
typedef std::map<std::string, std::string> table_t;
|
||||||
|
|
||||||
|
friend Singleton<ConfigUtility>;
|
||||||
|
|
||||||
|
ConfigUtility() = default;
|
||||||
|
~ConfigUtility() = default;
|
||||||
|
|
||||||
|
table_t Read(std::string fname);
|
||||||
|
|
||||||
|
table_t configMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -19,30 +19,45 @@
|
|||||||
* 3. This notice may not be removed or altered from any source
|
* 3. This notice may not be removed or altered from any source
|
||||||
* distribution.
|
* distribution.
|
||||||
*/
|
*/
|
||||||
#ifndef ENEMYFACTORYINTERFACE_HPP_
|
#ifndef SINGLETON_HPP_
|
||||||
#define ENEMYFACTORYINTERFACE_HPP_
|
#define SINGLETON_HPP_
|
||||||
|
|
||||||
#include "enemy_data.hpp"
|
#include <stdexcept>
|
||||||
#include "room_data.hpp"
|
|
||||||
|
|
||||||
#include <list>
|
template<typename T>
|
||||||
|
class Singleton {
|
||||||
//NOTE: Based on biome, world difficulty, etc.
|
|
||||||
class EnemyFactoryInterface {
|
|
||||||
public:
|
public:
|
||||||
EnemyFactoryInterface() = default;
|
static T& GetSingleton() {
|
||||||
virtual ~EnemyFactoryInterface() = default;
|
if (!ptr) {
|
||||||
|
throw(std::logic_error("This singleton has not been created"));
|
||||||
|
}
|
||||||
|
return *ptr;
|
||||||
|
}
|
||||||
|
static void Create() {
|
||||||
|
if (ptr) {
|
||||||
|
throw(std::logic_error("This singleton has already been created"));
|
||||||
|
}
|
||||||
|
ptr = new T();
|
||||||
|
}
|
||||||
|
static void Delete() {
|
||||||
|
if (!ptr) {
|
||||||
|
throw(std::logic_error("A non-existant singleton cannot be deleted"));
|
||||||
|
}
|
||||||
|
delete ptr;
|
||||||
|
ptr = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void Generate(std::list<EnemyData>* container) = 0;
|
|
||||||
|
|
||||||
//control the difficulty of the room
|
|
||||||
RoomData::RoomType SetType(RoomData::RoomType t) { return type = t; }
|
|
||||||
int SetDifficulty(int d) { return difficulty = d; }
|
|
||||||
RoomData::RoomType GetType() { return type; }
|
|
||||||
int GetDifficulty() { return difficulty; }
|
|
||||||
protected:
|
protected:
|
||||||
RoomData::RoomType type;
|
Singleton() = default;
|
||||||
int difficulty;
|
Singleton(Singleton const&) = default;
|
||||||
|
Singleton(Singleton&&) = default;
|
||||||
|
~Singleton() = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static T* ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T* Singleton<T>::ptr = nullptr;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -32,6 +32,10 @@ int snapToBase(int base, int x) {
|
|||||||
return x / base * base;
|
return x / base * base;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double snapToBase(double base, double x) {
|
||||||
|
return floor(x / base) * base;
|
||||||
|
}
|
||||||
|
|
||||||
std::string truncatePath(std::string pathname) {
|
std::string truncatePath(std::string pathname) {
|
||||||
return std::string(
|
return std::string(
|
||||||
std::find_if(
|
std::find_if(
|
||||||
|
|||||||
@@ -25,6 +25,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
int snapToBase(int base, int x);
|
int snapToBase(int base, int x);
|
||||||
|
double snapToBase(double base, double x);
|
||||||
|
|
||||||
std::string truncatePath(std::string pathname);
|
std::string truncatePath(std::string pathname);
|
||||||
|
|
||||||
//fixing known bugs in g++
|
//fixing known bugs in g++
|
||||||
|
|||||||
@@ -41,6 +41,13 @@ public:
|
|||||||
double SquaredLength() const {
|
double SquaredLength() const {
|
||||||
return x*x+y*y;
|
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
|
//Arithmetic operators
|
||||||
Vector2 operator+(Vector2 v) const {
|
Vector2 operator+(Vector2 v) const {
|
||||||
@@ -97,15 +104,6 @@ public:
|
|||||||
template<typename T> bool operator!=(T t) { return (x != t || y != t); }
|
template<typename T> bool operator!=(T t) { return (x != t || y != t); }
|
||||||
};
|
};
|
||||||
|
|
||||||
//non-member templates (flip the order)
|
|
||||||
template<typename T> Vector2 operator+(T t, Vector2 v) { return v + t; }
|
|
||||||
template<typename T> Vector2 operator-(T t, Vector2 v) { return v - t; }
|
|
||||||
template<typename T> Vector2 operator*(T t, Vector2 v) { return v * t; }
|
|
||||||
template<typename T> Vector2 operator/(T t, Vector2 v) { return v / t; }
|
|
||||||
|
|
||||||
template<typename T> bool operator==(T t, Vector2 v) { return v == t; }
|
|
||||||
template<typename T> bool operator!=(T t, Vector2 v) { return v != t; }
|
|
||||||
|
|
||||||
//This is explicitly a POD
|
//This is explicitly a POD
|
||||||
static_assert(std::is_pod<Vector2>::value, "Vector2 is not a POD");
|
static_assert(std::is_pod<Vector2>::value, "Vector2 is not a POD");
|
||||||
|
|
||||||
|
|||||||
@@ -3,9 +3,10 @@
|
|||||||
#MKDIR=mkdir
|
#MKDIR=mkdir
|
||||||
#RM=del /y
|
#RM=del /y
|
||||||
|
|
||||||
CXXFLAGS+=-static-libgcc -static-libstdc++
|
#CXXFLAGS+=-static-libgcc -static-libstdc++ -g -fno-inline-functions -Wall
|
||||||
|
#CXXFLAGS+=-static-libgcc -static-libstdc++
|
||||||
|
|
||||||
export
|
#export
|
||||||
|
|
||||||
OUTDIR=out
|
OUTDIR=out
|
||||||
|
|
||||||
@@ -14,6 +15,12 @@ all: $(OUTDIR)
|
|||||||
$(MAKE) -C server
|
$(MAKE) -C server
|
||||||
$(MAKE) -C client
|
$(MAKE) -C client
|
||||||
|
|
||||||
|
debug: export CXXFLAGS+=-g
|
||||||
|
debug: clean all
|
||||||
|
|
||||||
|
release: export CXXFLAGS+=-static-libgcc -static-libstdc++
|
||||||
|
release: clean all
|
||||||
|
|
||||||
$(OUTDIR):
|
$(OUTDIR):
|
||||||
mkdir $(OUTDIR)
|
mkdir $(OUTDIR)
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ server.name = local
|
|||||||
server.dbname = database.db
|
server.dbname = database.db
|
||||||
|
|
||||||
#client specific settings
|
#client specific settings
|
||||||
|
#client.screen.w = 800
|
||||||
|
#client.screen.h = 600
|
||||||
client.screen.f = false
|
client.screen.f = false
|
||||||
|
|
||||||
client.username = Kayne Ruse
|
client.username = Kayne Ruse
|
||||||
|
|||||||
@@ -1,20 +1,46 @@
|
|||||||
print("Lua script check (./rsc)")
|
print("Lua script check")
|
||||||
|
|
||||||
-------------------------
|
--uber lazy declarations
|
||||||
--Map API overrides
|
function math.sqr(x) return x*x end
|
||||||
-------------------------
|
function math.dist(x, y, i, j) return math.sqrt(math.sqr(x - i) + math.sqr(y - j)) end
|
||||||
|
|
||||||
function region.create(r)
|
--tile macros, mapped to the tilesheet
|
||||||
for i = 1, region.getwidth() do
|
local base = 14
|
||||||
for j = 1, region.getheight() do
|
local shift = 36
|
||||||
if math.abs(region.getx(r) + i -1) == math.abs(region.gety(r) + j -1) then
|
tiles = {
|
||||||
region.settile(r, i, j, 1, 50)
|
plains = base + shift * 0,
|
||||||
|
grass = base + shift * 1,
|
||||||
|
dirt = base + shift * 2,
|
||||||
|
sand = base + shift * 3,
|
||||||
|
water = base + shift * 4
|
||||||
|
}
|
||||||
|
|
||||||
|
--could set custom generation systems here, that differ from the global generators, etc.
|
||||||
|
function Region.Create(region)
|
||||||
|
for i = 1, Region.GetWidth() do
|
||||||
|
for j = 1, Region.GetHeight() do
|
||||||
|
local dist = math.dist(0, 0, i + Region.GetX(region) -1, j + Region.GetY(region) -1)
|
||||||
|
if dist < 10 then
|
||||||
|
Region.SetTile(region, i, j, 1, tiles.plains)
|
||||||
|
elseif dist < 12 then
|
||||||
|
Region.SetTile(region, i, j, 1, tiles.sand)
|
||||||
else
|
else
|
||||||
region.settile(r, i, j, 1, 14)
|
Region.SetTile(region, i, j, 1, tiles.water)
|
||||||
|
Region.SetSolid(region, i, j, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--signal
|
|
||||||
region.settile(r, 4, 5, 2, 86)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--Get some regions
|
||||||
|
--BUG: The server fails without this
|
||||||
|
newRoom = RoomMgr.CreateRoom("overworld")
|
||||||
|
pager = Room.GetPager(newRoom)
|
||||||
|
regionTable = {
|
||||||
|
RegionPager.GetRegion(pager, Region.GetWidth() * 0, Region.GetHeight() * 0),
|
||||||
|
RegionPager.GetRegion(pager, Region.GetWidth() *-1, Region.GetHeight() * 0),
|
||||||
|
RegionPager.GetRegion(pager, Region.GetWidth() * 0, Region.GetHeight() *-1),
|
||||||
|
RegionPager.GetRegion(pager, Region.GetWidth() *-1, Region.GetHeight() *-1)
|
||||||
|
}
|
||||||
|
|
||||||
|
print("Finished the lua script")
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#config
|
||||||
|
INCLUDES+=.
|
||||||
|
LIBS+=
|
||||||
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
#source
|
||||||
|
CXXSRC=$(wildcard *.cpp)
|
||||||
|
|
||||||
|
#objects
|
||||||
|
OBJDIR=obj
|
||||||
|
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||||
|
|
||||||
|
#output
|
||||||
|
OUTDIR=..
|
||||||
|
OUT=$(addprefix $(OUTDIR)/,server.a)
|
||||||
|
|
||||||
|
#targets
|
||||||
|
all: $(OBJ) $(OUT)
|
||||||
|
ar -crs $(OUT) $(OBJ)
|
||||||
|
|
||||||
|
$(OBJ): | $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUT): | $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR):
|
||||||
|
mkdir $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUTDIR):
|
||||||
|
mkdir $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR)/%.o: %.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) *.o *.a *.exe
|
||||||
|
|
||||||
|
rebuild: clean all
|
||||||
@@ -22,22 +22,15 @@
|
|||||||
#ifndef CHARACTERDATA_HPP_
|
#ifndef CHARACTERDATA_HPP_
|
||||||
#define CHARACTERDATA_HPP_
|
#define CHARACTERDATA_HPP_
|
||||||
|
|
||||||
|
//components
|
||||||
|
#include "character_defines.hpp"
|
||||||
#include "vector2.hpp"
|
#include "vector2.hpp"
|
||||||
#include "statistics.hpp"
|
#include "statistics.hpp"
|
||||||
|
|
||||||
//graphics
|
|
||||||
#ifdef GRAPHICS
|
|
||||||
#include "sprite_sheet.hpp"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//std namespace
|
//std namespace
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
//the speeds that the characters move
|
|
||||||
constexpr double CHARACTER_WALKING_SPEED = 140.0;
|
|
||||||
constexpr double CHARACTER_WALKING_MOD = 1.0/sqrt(2.0);
|
|
||||||
|
|
||||||
struct CharacterData {
|
struct CharacterData {
|
||||||
//metadata
|
//metadata
|
||||||
int owner;
|
int owner;
|
||||||
@@ -48,25 +41,14 @@ struct CharacterData {
|
|||||||
int roomIndex = 0;
|
int roomIndex = 0;
|
||||||
Vector2 origin = {0.0,0.0};
|
Vector2 origin = {0.0,0.0};
|
||||||
Vector2 motion = {0.0,0.0};
|
Vector2 motion = {0.0,0.0};
|
||||||
Vector2 bounds = {0.0,0.0};
|
|
||||||
|
|
||||||
//base statistics
|
//base statistics
|
||||||
Statistics stats;
|
Statistics stats;
|
||||||
|
|
||||||
//TODO: gameplay components: equipment, items, buffs, debuffs
|
//TODO: gameplay components: equipment, items, buffs, debuffs
|
||||||
|
|
||||||
//methods
|
|
||||||
void Update(double delta);
|
|
||||||
#ifdef GRAPHICS
|
|
||||||
void DrawTo(SDL_Surface* const, int camX, int camY);
|
|
||||||
void CorrectSprite();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//active gameplay members
|
//active gameplay members
|
||||||
//NOTE: these are lost when unloaded
|
//NOTE: these are lost when unloaded
|
||||||
#ifdef GRAPHICS
|
|
||||||
SpriteSheet sprite;
|
|
||||||
#endif
|
|
||||||
bool inCombat = false;
|
bool inCombat = false;
|
||||||
int atbGauge = 0;
|
int atbGauge = 0;
|
||||||
//TODO: stored command
|
//TODO: stored command
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#config
|
||||||
|
INCLUDES+=. ../../common/gameplay ../../common/utilities
|
||||||
|
LIBS+=
|
||||||
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
#source
|
||||||
|
CXXSRC=$(wildcard *.cpp)
|
||||||
|
|
||||||
|
#objects
|
||||||
|
OBJDIR=obj
|
||||||
|
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||||
|
|
||||||
|
#output
|
||||||
|
OUTDIR=..
|
||||||
|
OUT=$(addprefix $(OUTDIR)/,server.a)
|
||||||
|
|
||||||
|
#targets
|
||||||
|
all: $(OBJ) $(OUT)
|
||||||
|
ar -crs $(OUT) $(OBJ)
|
||||||
|
|
||||||
|
$(OBJ): | $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUT): | $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR):
|
||||||
|
mkdir $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUTDIR):
|
||||||
|
mkdir $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR)/%.o: %.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) *.o *.a *.exe
|
||||||
|
|
||||||
|
rebuild: clean all
|
||||||
@@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
struct ClientData {
|
struct ClientData {
|
||||||
IPaddress address = {0,0};
|
IPaddress address = {0,0};
|
||||||
|
//TODO: ping system?
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -23,31 +23,18 @@
|
|||||||
#define COMBATDATA_HPP_
|
#define COMBATDATA_HPP_
|
||||||
|
|
||||||
#include "vector2.hpp"
|
#include "vector2.hpp"
|
||||||
|
#include "combat_defines.hpp"
|
||||||
|
|
||||||
//gameplay members
|
//gameplay members
|
||||||
#include "character_data.hpp"
|
#include "character_data.hpp"
|
||||||
#include "enemy_data.hpp"
|
#include "enemy_data.hpp"
|
||||||
|
|
||||||
//graphics
|
|
||||||
#ifdef GRAPHICS
|
|
||||||
#include "sprite_sheet.hpp"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//std namespace
|
//std namespace
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#define COMBAT_MAX_CHARACTERS 12
|
|
||||||
#define COMBAT_MAX_ENEMIES 12
|
|
||||||
|
|
||||||
struct CombatData {
|
struct CombatData {
|
||||||
enum class Terrain {
|
|
||||||
//TODO: types of combat terrains
|
|
||||||
NONE = 0,
|
|
||||||
GRASSLANDS,
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::chrono::steady_clock Clock;
|
typedef std::chrono::steady_clock Clock;
|
||||||
|
|
||||||
std::array<CharacterData, COMBAT_MAX_CHARACTERS> characterArray;
|
std::array<CharacterData, COMBAT_MAX_CHARACTERS> characterArray;
|
||||||
@@ -60,11 +47,6 @@ struct CombatData {
|
|||||||
|
|
||||||
//time interval
|
//time interval
|
||||||
Clock::time_point lastTick = Clock::now();
|
Clock::time_point lastTick = Clock::now();
|
||||||
|
|
||||||
//graphics
|
|
||||||
#ifdef GRAPHICS
|
|
||||||
SpriteSheet sprite;
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#config
|
||||||
|
INCLUDES+=. ../../common/gameplay ../../common/utilities ../characters ../enemies
|
||||||
|
LIBS+=
|
||||||
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
#source
|
||||||
|
CXXSRC=$(wildcard *.cpp)
|
||||||
|
|
||||||
|
#objects
|
||||||
|
OBJDIR=obj
|
||||||
|
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||||
|
|
||||||
|
#output
|
||||||
|
OUTDIR=..
|
||||||
|
OUT=$(addprefix $(OUTDIR)/,server.a)
|
||||||
|
|
||||||
|
#targets
|
||||||
|
all: $(OBJ) $(OUT)
|
||||||
|
ar -crs $(OUT) $(OBJ)
|
||||||
|
|
||||||
|
$(OBJ): | $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUT): | $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR):
|
||||||
|
mkdir $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUTDIR):
|
||||||
|
mkdir $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR)/%.o: %.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) *.o *.a *.exe
|
||||||
|
|
||||||
|
rebuild: clean all
|
||||||
@@ -25,11 +25,6 @@
|
|||||||
#include "vector2.hpp"
|
#include "vector2.hpp"
|
||||||
#include "statistics.hpp"
|
#include "statistics.hpp"
|
||||||
|
|
||||||
//graphics
|
|
||||||
#ifdef GRAPHICS
|
|
||||||
#include "sprite_sheet.hpp"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//std namespace
|
//std namespace
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@@ -45,11 +40,6 @@ struct EnemyData {
|
|||||||
|
|
||||||
//active gameplay members
|
//active gameplay members
|
||||||
//NOTE: these are lost when unloaded
|
//NOTE: these are lost when unloaded
|
||||||
#ifdef GRAPHICS
|
|
||||||
SpriteSheet sprite;
|
|
||||||
Vector2 origin = {0.0,0.0};
|
|
||||||
Vector2 bounds = {0.0,0.0};
|
|
||||||
#endif
|
|
||||||
int tableIndex;
|
int tableIndex;
|
||||||
int atbGauge = 0;
|
int atbGauge = 0;
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#config
|
||||||
|
INCLUDES+=. ../mapgen ../../common/gameplay ../../common/map ../../common/utilities
|
||||||
|
LIBS+=
|
||||||
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
#source
|
||||||
|
CXXSRC=$(wildcard *.cpp)
|
||||||
|
|
||||||
|
#objects
|
||||||
|
OBJDIR=obj
|
||||||
|
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||||
|
|
||||||
|
#output
|
||||||
|
OUTDIR=..
|
||||||
|
OUT=$(addprefix $(OUTDIR)/,server.a)
|
||||||
|
|
||||||
|
#targets
|
||||||
|
all: $(OBJ) $(OUT)
|
||||||
|
ar -crs $(OUT) $(OBJ)
|
||||||
|
|
||||||
|
$(OBJ): | $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUT): | $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR):
|
||||||
|
mkdir $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUTDIR):
|
||||||
|
mkdir $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR)/%.o: %.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) *.o *.a *.exe
|
||||||
|
|
||||||
|
rebuild: clean all
|
||||||
+10
-4
@@ -37,7 +37,10 @@
|
|||||||
#include "lua/lua.hpp"
|
#include "lua/lua.hpp"
|
||||||
|
|
||||||
#include "region_api.hpp"
|
#include "region_api.hpp"
|
||||||
#include "pager_api.hpp"
|
#include "region_pager_api.hpp"
|
||||||
|
#include "tile_sheet_api.hpp"
|
||||||
|
#include "room_api.hpp"
|
||||||
|
#include "room_mgr_api.hpp"
|
||||||
|
|
||||||
//these libs are loaded by lua.c and are readily available to any Lua program
|
//these libs are loaded by lua.c and are readily available to any Lua program
|
||||||
static const luaL_Reg loadedlibs[] = {
|
static const luaL_Reg loadedlibs[] = {
|
||||||
@@ -53,9 +56,12 @@ static const luaL_Reg loadedlibs[] = {
|
|||||||
{LUA_MATHLIBNAME, luaopen_math},
|
{LUA_MATHLIBNAME, luaopen_math},
|
||||||
{LUA_DBLIBNAME, luaopen_debug},
|
{LUA_DBLIBNAME, luaopen_debug},
|
||||||
|
|
||||||
//custom libs
|
//Tortuga's API
|
||||||
{LUA_REGIONLIBNAME, luaopen_regionapi},
|
{TORTUGA_REGION_NAME, openRegionAPI},
|
||||||
{LUA_PAGERLIBNAME, luaopen_pagerapi},
|
{TORTUGA_REGION_PAGER_NAME, openRegionPagerAPI},
|
||||||
|
{TORTUGA_TILE_SHEET_NAME, openTileSheetAPI},
|
||||||
|
{TORTUGA_ROOM_NAME, openRoomAPI},
|
||||||
|
{TORTUGA_ROOM_MGR_NAME, openRoomMgrAPI},
|
||||||
|
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|||||||
+13
-5
@@ -21,7 +21,8 @@
|
|||||||
*/
|
*/
|
||||||
#include "server_application.hpp"
|
#include "server_application.hpp"
|
||||||
|
|
||||||
#include "SDL/SDL.h"
|
//singletons
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -29,17 +30,24 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
cout << "Beginning server" << endl;
|
|
||||||
try {
|
try {
|
||||||
ServerApplication app;
|
//create the singletons
|
||||||
|
ConfigUtility::Create();
|
||||||
|
ServerApplication::Create();
|
||||||
|
|
||||||
|
//call the server's routines
|
||||||
|
ServerApplication& app = ServerApplication::GetSingleton();
|
||||||
app.Init(argc, argv);
|
app.Init(argc, argv);
|
||||||
app.Proc();
|
app.Proc();
|
||||||
app.Quit();
|
app.Quit();
|
||||||
|
|
||||||
|
//delete the singletons
|
||||||
|
ConfigUtility::Delete();
|
||||||
|
ServerApplication::Delete();
|
||||||
}
|
}
|
||||||
catch(exception& e) {
|
catch(exception& e) {
|
||||||
cerr << "Fatal error: " << e.what() << endl;
|
cerr << "Fatal exception thrown: " << e.what() << endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
cout << "Clean exit" << endl;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
+7
-2
@@ -1,6 +1,6 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. ../common/gameplay ../common/map ../common/network ../common/network/packet ../common/network/serial ../common/utilities
|
INCLUDES+=. accounts characters combat enemies mapgen mapgen/generators rooms ../common/debugging ../common/gameplay ../common/map ../common/network ../common/network/packet ../common/network/serial ../common/utilities
|
||||||
LIBS+=../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua -lsqlite3
|
LIBS+=server.a ../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua -lsqlite3
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
#source
|
#source
|
||||||
@@ -16,6 +16,11 @@ OUT=$(addprefix $(OUTDIR)/,server)
|
|||||||
|
|
||||||
#targets
|
#targets
|
||||||
all: $(OBJ) $(OUT)
|
all: $(OBJ) $(OUT)
|
||||||
|
$(MAKE) -C accounts
|
||||||
|
$(MAKE) -C characters
|
||||||
|
$(MAKE) -C combat
|
||||||
|
$(MAKE) -C enemies
|
||||||
|
$(MAKE) -C rooms
|
||||||
$(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
|
$(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
|
||||||
|
|
||||||
$(OBJ): | $(OBJDIR)
|
$(OBJ): | $(OBJDIR)
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2014
|
|
||||||
*
|
|
||||||
* This software is provided 'as-is', without any express or implied
|
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
|
||||||
* arising from the use of this software.
|
|
||||||
*
|
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
|
||||||
* including commercial applications, and to alter it and redistribute it
|
|
||||||
* freely, subject to the following restrictions:
|
|
||||||
*
|
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
|
||||||
* claim that you wrote the original software. If you use this software
|
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
|
||||||
* appreciated but is not required.
|
|
||||||
*
|
|
||||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
* misrepresented as being the original software.
|
|
||||||
*
|
|
||||||
* 3. This notice may not be removed or altered from any source
|
|
||||||
* distribution.
|
|
||||||
*/
|
|
||||||
#include "room_manager.hpp"
|
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
//public access methods
|
|
||||||
//-------------------------
|
|
||||||
|
|
||||||
RoomData* RoomManager::CreateRoom(int uid) {
|
|
||||||
//don't overwrite existing rooms
|
|
||||||
std::map<int, RoomData*>::iterator it = roomMap.find(uid);
|
|
||||||
if (it != roomMap.end()) {
|
|
||||||
throw(std::runtime_error("Cannot overwrite an existing room"));
|
|
||||||
}
|
|
||||||
roomMap[uid] = new RoomData();
|
|
||||||
//TODO: create room in the API
|
|
||||||
if (luaState) {
|
|
||||||
roomMap[uid]->pager.SetLuaState(luaState);
|
|
||||||
}
|
|
||||||
return roomMap[uid];
|
|
||||||
}
|
|
||||||
|
|
||||||
RoomData* RoomManager::UnloadRoom(int uid) {
|
|
||||||
//TODO: unload room in the API
|
|
||||||
delete roomMap[uid];
|
|
||||||
roomMap.erase(uid);
|
|
||||||
}
|
|
||||||
|
|
||||||
RoomData* RoomManager::GetRoom(int uid) {
|
|
||||||
RoomData* ptr = FindRoom(uid);
|
|
||||||
if (ptr) return ptr;
|
|
||||||
ptr = CreateRoom(uid);
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
RoomData* RoomManager::FindRoom(int uid) {
|
|
||||||
std::map<int, RoomData*>::iterator it = roomMap.find(uid);
|
|
||||||
if (it == roomMap.end()) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return it->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
RoomData* RoomManager::PushRoom(int uid, RoomData* room) {
|
|
||||||
//unload existing rooms with this index
|
|
||||||
std::map<int, RoomData*>::iterator it = roomMap.find(uid);
|
|
||||||
if (it != roomMap.end()) {
|
|
||||||
UnloadRoom(uid);
|
|
||||||
}
|
|
||||||
roomMap[uid] = room;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#config
|
||||||
|
INCLUDES+=. ../mapgen ../mapgen/generators ../../common/map
|
||||||
|
LIBS+=
|
||||||
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
#source
|
||||||
|
CXXSRC=$(wildcard *.cpp)
|
||||||
|
|
||||||
|
#objects
|
||||||
|
OBJDIR=obj
|
||||||
|
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||||
|
|
||||||
|
#output
|
||||||
|
OUTDIR=..
|
||||||
|
OUT=$(addprefix $(OUTDIR)/,server.a)
|
||||||
|
|
||||||
|
#targets
|
||||||
|
all: $(OBJ) $(OUT)
|
||||||
|
ar -crs $(OUT) $(OBJ)
|
||||||
|
|
||||||
|
$(OBJ): | $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUT): | $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR):
|
||||||
|
mkdir $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUTDIR):
|
||||||
|
mkdir $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR)/%.o: %.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) *.o *.a *.exe
|
||||||
|
|
||||||
|
rebuild: clean all
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "room_api.hpp"
|
||||||
|
|
||||||
|
#include "room_data.hpp"
|
||||||
|
|
||||||
|
static int getPager(lua_State* L) {
|
||||||
|
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||||
|
lua_pushlightuserdata(L, reinterpret_cast<void*>(&room->pager));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int onCreate(lua_State* L) {
|
||||||
|
//TODO: onCreate()
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int onUnload(lua_State* L) {
|
||||||
|
//TODO: onUnload()
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: parameters
|
||||||
|
|
||||||
|
static const luaL_Reg roomLib[] = {
|
||||||
|
{"GetPager",getPager},
|
||||||
|
{"OnCreate", onCreate},
|
||||||
|
{"OnUnload", onUnload},
|
||||||
|
{nullptr, nullptr}
|
||||||
|
};
|
||||||
|
|
||||||
|
LUAMOD_API int openRoomAPI(lua_State* L) {
|
||||||
|
luaL_newlib(L, roomLib);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
#include "lua/lua.hpp"
|
#include "lua/lua.hpp"
|
||||||
|
|
||||||
#define LUA_ROOMLIBNAME "room"
|
#define TORTUGA_ROOM_NAME "Room"
|
||||||
LUAMOD_API int luaopen_roomapi(lua_State* L);
|
LUAMOD_API int openRoomAPI(lua_State* L);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -26,17 +26,8 @@
|
|||||||
#include "region_pager_lua.hpp"
|
#include "region_pager_lua.hpp"
|
||||||
|
|
||||||
struct RoomData {
|
struct RoomData {
|
||||||
enum class RoomType {
|
|
||||||
OVERWORLD = 0,
|
|
||||||
RUINS = 1,
|
|
||||||
TOWERS = 2,
|
|
||||||
FORESTS = 3,
|
|
||||||
CAVE = 4,
|
|
||||||
};
|
|
||||||
|
|
||||||
//members
|
//members
|
||||||
RegionPagerLua pager;
|
RegionPagerLua pager;
|
||||||
RoomType type;
|
|
||||||
|
|
||||||
//TODO: collision map
|
//TODO: collision map
|
||||||
//TODO: NPCs?
|
//TODO: NPCs?
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "room_manager.hpp"
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//public access methods
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
RoomData* RoomManager::CreateRoom() {
|
||||||
|
//create the room
|
||||||
|
RoomData* newRoom = new RoomData();
|
||||||
|
|
||||||
|
//set the state
|
||||||
|
if (luaState) {
|
||||||
|
newRoom->pager.SetLuaState(luaState);
|
||||||
|
}
|
||||||
|
|
||||||
|
//register the room
|
||||||
|
roomMap[counter++] = newRoom;
|
||||||
|
|
||||||
|
//API hook
|
||||||
|
lua_getglobal(luaState, "Room");
|
||||||
|
lua_getfield(luaState, -1, "OnCreate");
|
||||||
|
lua_pushlightuserdata(luaState, newRoom);
|
||||||
|
if (lua_pcall(luaState, 1, 0, 0) != LUA_OK) {
|
||||||
|
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
|
||||||
|
}
|
||||||
|
lua_pop(luaState, 1);
|
||||||
|
|
||||||
|
//finish the routine
|
||||||
|
return newRoom;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RoomManager::UnloadRoom(int uid) {
|
||||||
|
//find the room
|
||||||
|
RoomData* room = FindRoom(uid);
|
||||||
|
if (!room) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//API hook
|
||||||
|
lua_getglobal(luaState, "Room");
|
||||||
|
lua_getfield(luaState, -1, "OnUnload");
|
||||||
|
lua_pushlightuserdata(luaState, room);
|
||||||
|
if (lua_pcall(luaState, 1, 0, 0) != LUA_OK) {
|
||||||
|
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
|
||||||
|
}
|
||||||
|
lua_pop(luaState, 1);
|
||||||
|
|
||||||
|
//free the memory
|
||||||
|
delete room;
|
||||||
|
roomMap.erase(uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
RoomData* RoomManager::GetRoom(int uid) {
|
||||||
|
return FindRoom(uid);
|
||||||
|
//TODO: expand this to auto-create the room
|
||||||
|
}
|
||||||
|
|
||||||
|
RoomData* RoomManager::FindRoom(int uid) {
|
||||||
|
std::map<int, RoomData*>::iterator it = roomMap.find(uid);
|
||||||
|
if (it == roomMap.end()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
int RoomManager::PushRoom(RoomData* room) {
|
||||||
|
roomMap[counter++] = room;
|
||||||
|
return counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RoomManager::UnloadAll() {
|
||||||
|
lua_getglobal(luaState, "Room");
|
||||||
|
|
||||||
|
for (auto& it : roomMap) {
|
||||||
|
//API hook
|
||||||
|
lua_getfield(luaState, -1, "OnUnload");
|
||||||
|
lua_pushlightuserdata(luaState, it.second);
|
||||||
|
if (lua_pcall(luaState, 1, 0, 0) != LUA_OK) {
|
||||||
|
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_pop(luaState, 1);
|
||||||
|
roomMap.clear();
|
||||||
|
}
|
||||||
@@ -36,12 +36,14 @@ public:
|
|||||||
~RoomManager() = default;
|
~RoomManager() = default;
|
||||||
|
|
||||||
//public access methods
|
//public access methods
|
||||||
RoomData* CreateRoom(int uid);
|
RoomData* CreateRoom();
|
||||||
RoomData* UnloadRoom(int uid);
|
void UnloadRoom(int uid);
|
||||||
|
|
||||||
RoomData* GetRoom(int uid);
|
RoomData* GetRoom(int uid);
|
||||||
RoomData* FindRoom(int uid);
|
RoomData* FindRoom(int uid);
|
||||||
RoomData* PushRoom(int uid, RoomData*);
|
int PushRoom(RoomData*);
|
||||||
|
|
||||||
|
void UnloadAll();
|
||||||
|
|
||||||
//accessors and mutators
|
//accessors and mutators
|
||||||
std::map<int, RoomData*>* GetContainer() { return &roomMap; }
|
std::map<int, RoomData*>* GetContainer() { return &roomMap; }
|
||||||
@@ -52,6 +54,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::map<int, RoomData*> roomMap;
|
std::map<int, RoomData*> roomMap;
|
||||||
lua_State* luaState = nullptr;
|
lua_State* luaState = nullptr;
|
||||||
|
int counter = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -19,26 +19,14 @@
|
|||||||
* 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 "room_api.hpp"
|
#include "room_mgr_api.hpp"
|
||||||
|
|
||||||
|
#include "room_api.hpp"
|
||||||
#include "room_manager.hpp"
|
#include "room_manager.hpp"
|
||||||
#include "room_data.hpp"
|
#include "room_data.hpp"
|
||||||
|
|
||||||
static int getType(lua_State* L) {
|
#include <string>
|
||||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
|
||||||
lua_pushinteger(L, static_cast<int>(room->type));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: parameters
|
|
||||||
|
|
||||||
static int getRegionPager(lua_State* L) {
|
|
||||||
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
|
||||||
lua_pushlightuserdata(L, reinterpret_cast<void*>(&room->pager));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//RoomManager only
|
|
||||||
static int getRoom(lua_State* L) {
|
static int getRoom(lua_State* L) {
|
||||||
//get the room manager
|
//get the room manager
|
||||||
lua_pushstring(L, ROOM_MANAGER_PSEUDOINDEX);
|
lua_pushstring(L, ROOM_MANAGER_PSEUDOINDEX);
|
||||||
@@ -50,14 +38,42 @@ static int getRoom(lua_State* L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const luaL_Reg roomlib[] = {
|
static int createRoom(lua_State* L) {
|
||||||
{"gettype",getType},
|
//TODO: check parameter count for the glue functions
|
||||||
{"getregionpager",getRegionPager},
|
|
||||||
{"getroom",getRoom},
|
//get the room manager
|
||||||
|
lua_pushstring(L, ROOM_MANAGER_PSEUDOINDEX);
|
||||||
|
lua_gettable(L, LUA_REGISTRYINDEX);
|
||||||
|
RoomManager* roomMgr = reinterpret_cast<RoomManager*>(lua_touserdata(L, -1));
|
||||||
|
|
||||||
|
//create the room
|
||||||
|
RoomData* newRoom = roomMgr->CreateRoom();
|
||||||
|
|
||||||
|
//return the new room
|
||||||
|
lua_pushlightuserdata(L, newRoom);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int unloadRoom(lua_State* L) {
|
||||||
|
//get the room manager
|
||||||
|
lua_pushstring(L, ROOM_MANAGER_PSEUDOINDEX);
|
||||||
|
lua_gettable(L, LUA_REGISTRYINDEX);
|
||||||
|
RoomManager* roomMgr = reinterpret_cast<RoomManager*>(lua_touserdata(L, -1));
|
||||||
|
|
||||||
|
//unload the specified room
|
||||||
|
roomMgr->UnloadRoom(lua_tointeger(L, -2));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const luaL_Reg roomMgrLib[] = {
|
||||||
|
{"GetRoom",getRoom},
|
||||||
|
{"CreateRoom",createRoom},
|
||||||
|
{"UnloadRoom",unloadRoom},
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|
||||||
LUAMOD_API int luaopen_roomapi(lua_State* L) {
|
LUAMOD_API int openRoomMgrAPI(lua_State* L) {
|
||||||
luaL_newlib(L, roomlib);
|
luaL_newlib(L, roomMgrLib);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -19,12 +19,12 @@
|
|||||||
* 3. This notice may not be removed or altered from any source
|
* 3. This notice may not be removed or altered from any source
|
||||||
* distribution.
|
* distribution.
|
||||||
*/
|
*/
|
||||||
#ifndef PAGERAPI_HPP_
|
#ifndef ROOMMGRAPI_HPP_
|
||||||
#define PAGERAPI_HPP_
|
#define ROOMMGRAPI_HPP_
|
||||||
|
|
||||||
#include "lua/lua.hpp"
|
#include "lua/lua.hpp"
|
||||||
|
|
||||||
#define LUA_PAGERLIBNAME "pager"
|
#define TORTUGA_ROOM_MGR_NAME "RoomMgr"
|
||||||
LUAMOD_API int luaopen_pagerapi(lua_State* L);
|
LUAMOD_API int openRoomMgrAPI(lua_State* L);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -21,8 +21,11 @@
|
|||||||
*/
|
*/
|
||||||
#include "server_application.hpp"
|
#include "server_application.hpp"
|
||||||
|
|
||||||
#include "sql_utility.hpp"
|
//for PACKET_BUFFER_SIZE
|
||||||
#include "serial.hpp"
|
#include "serial.hpp"
|
||||||
|
|
||||||
|
//utility functions
|
||||||
|
#include "sql_utility.hpp"
|
||||||
#include "utility.hpp"
|
#include "utility.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
@@ -35,9 +38,9 @@
|
|||||||
|
|
||||||
void ServerApplication::Init(int argc, char** argv) {
|
void ServerApplication::Init(int argc, char** argv) {
|
||||||
//NOTE: I might need to rearrange the init process so that lua & SQL can interact with the map system as needed.
|
//NOTE: I might need to rearrange the init process so that lua & SQL can interact with the map system as needed.
|
||||||
std::cout << "Beginning startup" << std::endl;
|
std::cout << "Beginning " << argv[0] << std::endl;
|
||||||
|
|
||||||
//initial setup
|
//load the prerequisites
|
||||||
config.Load("rsc\\config.cfg");
|
config.Load("rsc\\config.cfg");
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -80,9 +83,7 @@ void ServerApplication::Init(int argc, char** argv) {
|
|||||||
accountMgr.SetDatabase(database);
|
accountMgr.SetDatabase(database);
|
||||||
characterMgr.SetDatabase(database);
|
characterMgr.SetDatabase(database);
|
||||||
|
|
||||||
combatMgr.SetLuaState(luaState);
|
|
||||||
roomMgr.SetLuaState(luaState);
|
roomMgr.SetLuaState(luaState);
|
||||||
enemyMgr.SetLuaState(luaState);
|
|
||||||
|
|
||||||
std::cout << "Internal managers set" << std::endl;
|
std::cout << "Internal managers set" << std::endl;
|
||||||
|
|
||||||
@@ -113,12 +114,22 @@ void ServerApplication::Init(int argc, char** argv) {
|
|||||||
//debug output
|
//debug output
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
|
//TODO: enable/disable these with a switch
|
||||||
|
#define DEBUG_OUTPUT_VAR(x) std::cout << "\t" << #x << ": " << x << std::endl;
|
||||||
|
|
||||||
std::cout << "Internal sizes:" << std::endl;
|
std::cout << "Internal sizes:" << std::endl;
|
||||||
std::cout << "\tTile Size: " << sizeof(Region::type_t) << std::endl;
|
|
||||||
std::cout << "\tRegion Format: " << REGION_WIDTH << ", " << REGION_HEIGHT << ", " << REGION_DEPTH << std::endl;
|
DEBUG_OUTPUT_VAR(sizeof(Region::type_t));
|
||||||
std::cout << "\tRegion Content Footprint: " << REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t) << std::endl;
|
DEBUG_OUTPUT_VAR(sizeof(Region));
|
||||||
std::cout << "\tPACKET_BUFFER_SIZE: " << PACKET_BUFFER_SIZE << std::endl;
|
DEBUG_OUTPUT_VAR(REGION_WIDTH);
|
||||||
std::cout << "\tMAX_PACKET_SIZE: " << MAX_PACKET_SIZE << std::endl;
|
DEBUG_OUTPUT_VAR(REGION_HEIGHT);
|
||||||
|
DEBUG_OUTPUT_VAR(REGION_DEPTH);
|
||||||
|
DEBUG_OUTPUT_VAR(REGION_SOLID_FOOTPRINT);
|
||||||
|
DEBUG_OUTPUT_VAR(REGION_FOOTPRINT);
|
||||||
|
DEBUG_OUTPUT_VAR(PACKET_BUFFER_SIZE);
|
||||||
|
DEBUG_OUTPUT_VAR(MAX_PACKET_SIZE);
|
||||||
|
|
||||||
|
#undef DEBUG_OUTPUT_VAR
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//finalize the startup
|
//finalize the startup
|
||||||
@@ -141,7 +152,8 @@ void ServerApplication::Proc() {
|
|||||||
HandlePacket(packetBuffer);
|
HandlePacket(packetBuffer);
|
||||||
}
|
}
|
||||||
//update the internals
|
//update the internals
|
||||||
//TODO: update the internals i.e. player positions
|
//BUG: #30 Update the internals i.e. player positions
|
||||||
|
|
||||||
//give the computer a break
|
//give the computer a break
|
||||||
SDL_Delay(10);
|
SDL_Delay(10);
|
||||||
}
|
}
|
||||||
@@ -157,7 +169,7 @@ void ServerApplication::Quit() {
|
|||||||
characterMgr.UnloadAll();
|
characterMgr.UnloadAll();
|
||||||
//TODO: unload combats
|
//TODO: unload combats
|
||||||
//TODO: unload enemies
|
//TODO: unload enemies
|
||||||
//TODO: unload rooms
|
roomMgr.UnloadAll();
|
||||||
|
|
||||||
//APIs
|
//APIs
|
||||||
lua_close(luaState);
|
lua_close(luaState);
|
||||||
@@ -166,7 +178,7 @@ void ServerApplication::Quit() {
|
|||||||
SDLNet_Quit();
|
SDLNet_Quit();
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
|
||||||
std::cout << "Shutdown finished" << std::endl;
|
std::cout << "Clean exit" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -269,6 +281,16 @@ void ServerApplication::HandleJoinRequest(ClientPacket* const argPacket) {
|
|||||||
|
|
||||||
void ServerApplication::HandleDisconnect(ClientPacket* const argPacket) {
|
void ServerApplication::HandleDisconnect(ClientPacket* const argPacket) {
|
||||||
//TODO: authenticate who is disconnecting/kicking
|
//TODO: authenticate who is disconnecting/kicking
|
||||||
|
/*Pseudocode:
|
||||||
|
if sender's account index -> client index -> address == sender's address then
|
||||||
|
continue
|
||||||
|
end
|
||||||
|
if sender's account index -> admin == true OR sender's account index -> mod == true then
|
||||||
|
continue
|
||||||
|
end
|
||||||
|
if neither of the above is true, then output a warning to the console, and return
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
//forward to the specified client
|
//forward to the specified client
|
||||||
network.SendTo(
|
network.SendTo(
|
||||||
@@ -296,6 +318,12 @@ void ServerApplication::HandleDisconnect(ClientPacket* const argPacket) {
|
|||||||
|
|
||||||
void ServerApplication::HandleShutdown(SerialPacket* const argPacket) {
|
void ServerApplication::HandleShutdown(SerialPacket* const argPacket) {
|
||||||
//TODO: authenticate who is shutting the server down
|
//TODO: authenticate who is shutting the server down
|
||||||
|
/*Pseudocode:
|
||||||
|
if sender's account -> admin is not true then
|
||||||
|
print a warning
|
||||||
|
return
|
||||||
|
end
|
||||||
|
*/
|
||||||
|
|
||||||
//end the server
|
//end the server
|
||||||
running = false;
|
running = false;
|
||||||
@@ -327,12 +355,6 @@ void ServerApplication::HandleRegionRequest(RegionPacket* const argPacket) {
|
|||||||
network.SendTo(&argPacket->srcAddress, static_cast<SerialPacket*>(&newPacket));
|
network.SendTo(&argPacket->srcAddress, static_cast<SerialPacket*>(&newPacket));
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
//combat management
|
|
||||||
//-------------------------
|
|
||||||
|
|
||||||
//TODO: combat management
|
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Character Management
|
//Character Management
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -399,15 +421,7 @@ void ServerApplication::HandleCharacterUpdate(CharacterPacket* const argPacket)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: rewrite this design flaw, read more
|
//accept client-side logic
|
||||||
* Slaving the client to the server here is a terrible idea, instead there
|
|
||||||
* needs to be a utility function to update and send the server-side character
|
|
||||||
* to the clients.
|
|
||||||
*
|
|
||||||
* Other things to consider include functionality to reequip the character,
|
|
||||||
* apply status effects and to change the stats as well. These should all be
|
|
||||||
* handled server-side.
|
|
||||||
*/
|
|
||||||
character->roomIndex = argPacket->roomIndex;
|
character->roomIndex = argPacket->roomIndex;
|
||||||
character->origin = argPacket->origin;
|
character->origin = argPacket->origin;
|
||||||
character->motion = argPacket->motion;
|
character->motion = argPacket->motion;
|
||||||
@@ -419,12 +433,6 @@ void ServerApplication::HandleCharacterUpdate(CharacterPacket* const argPacket)
|
|||||||
PumpPacket(argPacket);
|
PumpPacket(argPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
|
||||||
//enemy management
|
|
||||||
//-------------------------
|
|
||||||
|
|
||||||
//TODO: enemy management
|
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//mismanagement
|
//mismanagement
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|||||||
@@ -22,17 +22,16 @@
|
|||||||
#ifndef SERVERAPPLICATION_HPP_
|
#ifndef SERVERAPPLICATION_HPP_
|
||||||
#define SERVERAPPLICATION_HPP_
|
#define SERVERAPPLICATION_HPP_
|
||||||
|
|
||||||
//server specific stuff
|
//server specific stuff, mostly managers
|
||||||
|
#include "client_data.hpp"
|
||||||
#include "account_manager.hpp"
|
#include "account_manager.hpp"
|
||||||
#include "character_manager.hpp"
|
#include "character_manager.hpp"
|
||||||
#include "client_data.hpp"
|
|
||||||
#include "combat_manager.hpp"
|
|
||||||
#include "enemy_manager.hpp"
|
|
||||||
#include "room_manager.hpp"
|
#include "room_manager.hpp"
|
||||||
|
|
||||||
//common utilities
|
//common utilities
|
||||||
#include "udp_network_utility.hpp"
|
#include "udp_network_utility.hpp"
|
||||||
#include "config_utility.hpp"
|
#include "config_utility.hpp"
|
||||||
|
#include "singleton.hpp"
|
||||||
|
|
||||||
//APIs
|
//APIs
|
||||||
#include "lua/lua.hpp"
|
#include "lua/lua.hpp"
|
||||||
@@ -44,17 +43,19 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
//The main application class
|
//The main application class
|
||||||
class ServerApplication {
|
class ServerApplication: public Singleton<ServerApplication> {
|
||||||
public:
|
public:
|
||||||
//public methods
|
//public methods
|
||||||
ServerApplication() = default;
|
|
||||||
~ServerApplication() = default;
|
|
||||||
|
|
||||||
void Init(int argc, char** argv);
|
void Init(int argc, char** argv);
|
||||||
void Proc();
|
void Proc();
|
||||||
void Quit();
|
void Quit();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend Singleton<ServerApplication>;
|
||||||
|
|
||||||
|
ServerApplication() = default;
|
||||||
|
~ServerApplication() = default;
|
||||||
|
|
||||||
//handle incoming traffic
|
//handle incoming traffic
|
||||||
void HandlePacket(SerialPacket* const);
|
void HandlePacket(SerialPacket* const);
|
||||||
|
|
||||||
@@ -67,17 +68,11 @@ private:
|
|||||||
//map management
|
//map management
|
||||||
void HandleRegionRequest(RegionPacket* const);
|
void HandleRegionRequest(RegionPacket* const);
|
||||||
|
|
||||||
//combat management
|
|
||||||
//TODO: combat management
|
|
||||||
|
|
||||||
//character management
|
//character management
|
||||||
void HandleCharacterNew(CharacterPacket* const);
|
void HandleCharacterNew(CharacterPacket* const);
|
||||||
void HandleCharacterDelete(CharacterPacket* const);
|
void HandleCharacterDelete(CharacterPacket* const);
|
||||||
void HandleCharacterUpdate(CharacterPacket* const);
|
void HandleCharacterUpdate(CharacterPacket* const);
|
||||||
|
|
||||||
//enemy management
|
|
||||||
//TODO: enemy management
|
|
||||||
|
|
||||||
//mismanagement
|
//mismanagement
|
||||||
void HandleSynchronize(ClientPacket* const);
|
void HandleSynchronize(ClientPacket* const);
|
||||||
|
|
||||||
@@ -91,7 +86,7 @@ private:
|
|||||||
sqlite3* database = nullptr;
|
sqlite3* database = nullptr;
|
||||||
lua_State* luaState = nullptr;
|
lua_State* luaState = nullptr;
|
||||||
UDPNetworkUtility network;
|
UDPNetworkUtility network;
|
||||||
ConfigUtility config;
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
|
|
||||||
//simple tables
|
//simple tables
|
||||||
std::map<int, ClientData> clientMap;
|
std::map<int, ClientData> clientMap;
|
||||||
@@ -99,8 +94,6 @@ private:
|
|||||||
//managers
|
//managers
|
||||||
AccountManager accountMgr;
|
AccountManager accountMgr;
|
||||||
CharacterManager characterMgr;
|
CharacterManager characterMgr;
|
||||||
CombatManager combatMgr;
|
|
||||||
EnemyManager enemyMgr;
|
|
||||||
RoomManager roomMgr;
|
RoomManager roomMgr;
|
||||||
|
|
||||||
//misc
|
//misc
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
TODO: encapsulate the data structures
|
TODO: encapsulate the data structures
|
||||||
TODO: Get the rooms working
|
TODO: Get the rooms working
|
||||||
|
|
||||||
|
TODO: make the whole thing more fault tolerant
|
||||||
TODO: Authentication
|
TODO: Authentication
|
||||||
TODO: server is slaved to the client
|
TODO: server is slaved to the client
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user