Compare commits

..

1 Commits

Author SHA1 Message Date
Kayne Ruse ac1098fa86 Merge branch 'develop', Major API expansion 2014-06-24 02:46:39 +10:00
95 changed files with 1539 additions and 1170 deletions
-1
View File
@@ -15,7 +15,6 @@ Out/
*.o *.o
*.a *.a
*.exe *.exe
*.diff
#Shell files #Shell files
*.bat *.bat
-86
View File
@@ -1,86 +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.
*/
#ifndef CHARACTER_HPP_
#define CHARACTER_HPP_
//components
#include "character_defines.hpp"
#include "vector2.hpp"
#include "bounding_box.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; }
//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 SetBoundingBox(BoundingBox b) { return bounds = b; }
BoundingBox GetBoundingBox() const { return bounds; }
private:
//graphics
SpriteSheet sprite;
//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
@@ -29,43 +29,29 @@
//Public access members //Public access members
//------------------------- //-------------------------
CleanUp::CleanUp(lua_State* L, UDPNetworkUtility& aNetwork, CharacterMap& aCharacterMap): CleanUp::CleanUp(
lua(L), ConfigUtility* const argConfig,
network(aNetwork), UDPNetworkUtility* const argNetwork,
characterMap(aCharacterMap) int* const argClientIndex,
int* const argAccountIndex,
int* const argCharacterIndex,
std::map<int, CombatData>* argCombatMap,
std::map<int, CharacterData>* argCharacterMap,
std::map<int, EnemyData>* argEnemyMap
):
config(*argConfig),
network(*argNetwork),
clientIndex(*argClientIndex),
accountIndex(*argAccountIndex),
characterIndex(*argCharacterIndex),
combatMap(*argCombatMap),
characterMap(*argCharacterMap),
enemyMap(*argEnemyMap)
{ {
//get the config table
lua_getglobal(lua, "config");
//TODO: I need to figure out an alternative to loading these over and over again
//get the directories
lua_getfield(lua, -1, "dir");
lua_getfield(lua, -1, "interface");
lua_getfield(lua, -2, "fonts");
std::string interfaceDir = lua_tostring(lua, -2);
std::string fontsDir = lua_tostring(lua, -1);
lua_pop(lua, 3);
//clear the indicies
lua_getfield(lua, -1, "client");
lua_pushnil(lua);
lua_pushnil(lua);
lua_pushnil(lua);
lua_setfield(lua, -4, "clientIndex");
lua_setfield(lua, -3, "accountIndex");
lua_setfield(lua, -2, "characterIndex");
//pop the remaining objects from the stack
lua_pop(lua, 2);
//setup the utility objects //setup the utility objects
image.LoadSurface(interfaceDir + "button_menu.bmp"); image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
image.SetClipH(image.GetClipH()/3); image.SetClipH(image.GetClipH()/3);
font.LoadSurface(fontsDir + "pk_white_8.bmp"); font.LoadSurface(config["dir.fonts"] + "pk_white_8.bmp");
//pass the utility objects //pass the utility objects
backButton.SetImage(&image); backButton.SetImage(&image);
@@ -80,7 +66,12 @@ CleanUp::CleanUp(lua_State* L, UDPNetworkUtility& aNetwork, CharacterMap& aChara
//full reset //full reset
network.Unbind(Channels::SERVER); network.Unbind(Channels::SERVER);
clientIndex = -1;
accountIndex = -1;
characterIndex = -1;
combatMap.clear();
characterMap.clear(); characterMap.clear();
enemyMap.clear();
//auto return //auto return
startTick = std::chrono::steady_clock::now(); startTick = std::chrono::steady_clock::now();
@@ -96,7 +87,7 @@ CleanUp::~CleanUp() {
void CleanUp::Update(double delta) { void CleanUp::Update(double delta) {
if (std::chrono::steady_clock::now() - startTick > std::chrono::duration<int>(10)) { if (std::chrono::steady_clock::now() - startTick > std::chrono::duration<int>(10)) {
SetNextScene(SceneList::MAINMENU); QuitEvent();
} }
//BUGFIX: Eat incoming packets //BUGFIX: Eat incoming packets
@@ -132,8 +123,7 @@ void CleanUp::MouseButtonDown(SDL_MouseButtonEvent const& button) {
} }
void CleanUp::MouseButtonUp(SDL_MouseButtonEvent const& button) { void CleanUp::MouseButtonUp(SDL_MouseButtonEvent const& button) {
if (backButton.MouseButtonUp(button) == Button::State::HOVER && if (backButton.MouseButtonUp(button) == Button::State::HOVER) {
button.button & SDL_BUTTON_LMASK) {
SetNextScene(SceneList::MAINMENU); SetNextScene(SceneList::MAINMENU);
} }
} }
@@ -25,18 +25,21 @@
//network //network
#include "udp_network_utility.hpp" #include "udp_network_utility.hpp"
//graphics & ui //graphics
#include "image.hpp" #include "image.hpp"
#include "raster_font.hpp" #include "raster_font.hpp"
#include "button.hpp" #include "button.hpp"
//common
#include "config_utility.hpp"
#include "frame_rate.hpp" #include "frame_rate.hpp"
#include "combat_data.hpp"
#include "character_data.hpp"
#include "enemy_data.hpp"
//client //client
#include "base_scene.hpp" #include "base_scene.hpp"
#include "character.hpp"
//APIs
#include "lua/lua.hpp"
//std namespace //std namespace
#include <chrono> #include <chrono>
@@ -44,7 +47,16 @@
class CleanUp : public BaseScene { class CleanUp : public BaseScene {
public: public:
//Public access members //Public access members
CleanUp(lua_State*, UDPNetworkUtility&, CharacterMap&); CleanUp(
ConfigUtility* const argConfig,
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
int* const argAccountIndex,
int* const argCharacterIndex,
std::map<int, CombatData>* argCombatMap,
std::map<int, CharacterData>* argCharacterMap,
std::map<int, EnemyData>* argEnemyMap
);
~CleanUp(); ~CleanUp();
protected: protected:
@@ -62,13 +74,20 @@ protected:
void KeyUp(SDL_KeyboardEvent const&); void KeyUp(SDL_KeyboardEvent const&);
//shared parameters //shared parameters
lua_State* lua = nullptr; ConfigUtility& config;
UDPNetworkUtility& network; UDPNetworkUtility& network;
CharacterMap& characterMap; int& clientIndex;
int& accountIndex;
int& characterIndex;
std::map<int, CombatData>& combatMap;
std::map<int, CharacterData>& characterMap;
std::map<int, EnemyData>& enemyMap;
//graphics & ui //graphics
Image image; Image image;
RasterFont font; RasterFont font;
//UI
Button backButton; Button backButton;
FrameRate fps; FrameRate fps;
+15 -101
View File
@@ -25,7 +25,6 @@
#include <stdexcept> #include <stdexcept>
#include <chrono> #include <chrono>
#include <iostream>
//------------------------- //-------------------------
//Scene headers //Scene headers
@@ -45,106 +44,24 @@
//------------------------- //-------------------------
void ClientApplication::Init(int argc, char** argv) { void ClientApplication::Init(int argc, char** argv) {
std::cout << "Beginning " << argv[0] << std::endl; //load the prerequisites
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"));
} }
std::cout << "Initialized SDL" << std::endl; 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);
//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;
//initialize lua
lua = luaL_newstate();
if (!lua) {
throw(std::runtime_error("Failed to initialize lua"));
}
luaL_openlibs(lua);
std::cout << "Initialized lua" << std::endl;
//run the setup script
if (luaL_dofile(lua, "rsc\\setup.lua")) {
throw(std::runtime_error("Failed to initialize lua's startup script"));
}
std::cout << "Initialized lua's setup script" << std::endl;
//place the config table onto the stack
lua_getglobal(lua, "config");
//-------------------------
//Setup the screen
//-------------------------
//get each field
lua_getfield(lua, -1, "client");
lua_getfield(lua, -1, "screen");
lua_getfield(lua, -1, "width");
lua_getfield(lua, -2, "height");
lua_getfield(lua, -3, "fullscreen");
int w = lua_tointeger(lua, -3);
int h = lua_tointeger(lua, -2);
int f = lua_toboolean(lua, -1);
//pop the screen members
lua_pop(lua, 5);
BaseScene::SetScreen(w ? w : 800, h ? h : 600, 0, f ?
SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN :
SDL_HWSURFACE|SDL_DOUBLEBUF);
std::cout << "Initialized the screen" << std::endl;
//-------------------------
//debug output
//-------------------------
lua_getfield(lua, -1, "debug");
if (lua_toboolean(lua, -1)) {
#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
}
//pop the debug value
lua_pop(lua, 1);
//-------------------------
//finalize the startup
//-------------------------
//pop the config table
lua_pop(lua, 1);
std::cout << "Startup completed successfully" << std::endl;
//-------------------------
//debugging
//-------------------------
//...
} }
void ClientApplication::Proc() { void ClientApplication::Proc() {
@@ -171,7 +88,7 @@ void ClientApplication::Proc() {
//simulate game time //simulate game time
while (simTime < realTime) { while (simTime < realTime) {
//call each user defined function //call each user defined function
activeScene->RunFrame(constexpr(double(delta.count()) / std::chrono::duration<int, std::milli>::period::den)); activeScene->RunFrame(double(delta.count()) / std::chrono::duration<int, std::milli>::period::den);
simTime += delta; simTime += delta;
} }
@@ -183,12 +100,9 @@ void ClientApplication::Proc() {
} }
void ClientApplication::Quit() { void ClientApplication::Quit() {
std::cout << "Shutting down" << std::endl;
lua_close(lua);
network.Close(); network.Close();
SDLNet_Quit(); SDLNet_Quit();
SDL_Quit(); SDL_Quit();
std::cout << "Clean exit" << std::endl;
} }
//------------------------- //-------------------------
@@ -201,25 +115,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(lua); activeScene = new SplashScreen(&config);
break; break;
case SceneList::MAINMENU: case SceneList::MAINMENU:
activeScene = new MainMenu(lua); activeScene = new MainMenu(&config);
break; break;
case SceneList::OPTIONSMENU: case SceneList::OPTIONSMENU:
activeScene = new OptionsMenu(lua); activeScene = new OptionsMenu(&config);
break; break;
case SceneList::LOBBYMENU: case SceneList::LOBBYMENU:
activeScene = new LobbyMenu(lua, network, characterMap); activeScene = new LobbyMenu(&config, &network, &clientIndex, &accountIndex);
break; break;
case SceneList::INWORLD: case SceneList::INWORLD:
activeScene = new InWorld(lua, network, characterMap); activeScene = new InWorld(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap);
break; break;
case SceneList::INCOMBAT: case SceneList::INCOMBAT:
activeScene = new InCombat(lua, network, characterMap); activeScene = new InCombat(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap, &enemyMap);
break; break;
case SceneList::CLEANUP: case SceneList::CLEANUP:
activeScene = new CleanUp(lua, network, characterMap); activeScene = new CleanUp(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap, &enemyMap);
break; break;
default: default:
throw(std::logic_error("Failed to recognize the scene index")); throw(std::logic_error("Failed to recognize the scene index"));
+8 -5
View File
@@ -25,10 +25,11 @@
#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.hpp" #include "character_data.hpp"
#include "combat_data.hpp"
#include "lua/lua.hpp" #include "enemy_data.hpp"
#include <map> #include <map>
@@ -49,13 +50,15 @@ private:
BaseScene* activeScene = nullptr; BaseScene* activeScene = nullptr;
//shared parameters //shared parameters
lua_State* lua = nullptr; ConfigUtility config;
UDPNetworkUtility network; UDPNetworkUtility network;
int clientIndex = -1; int clientIndex = -1;
int accountIndex = -1; int accountIndex = -1;
int characterIndex = -1; int characterIndex = -1;
CharacterMap characterMap; std::map<int, CombatData> combatMap;
std::map<int, CharacterData> characterMap;
std::map<int, EnemyData> enemyMap;
}; };
#endif #endif
@@ -36,14 +36,18 @@ InCombat::InCombat(
int* const argClientIndex, int* const argClientIndex,
int* const argAccountIndex, int* const argAccountIndex,
int* const argCharacterIndex, int* const argCharacterIndex,
CharacterMap* argCharacterMap std::map<int, CombatData>* argCombatMap,
std::map<int, CharacterData>* argCharacterMap,
std::map<int, EnemyData>* argEnemyMap
): ):
config(*argConfig), config(*argConfig),
network(*argNetwork), network(*argNetwork),
clientIndex(*argClientIndex), clientIndex(*argClientIndex),
accountIndex(*argAccountIndex), accountIndex(*argAccountIndex),
characterIndex(*argCharacterIndex), characterIndex(*argCharacterIndex),
characterMap(*argCharacterMap) combatMap(*argCombatMap),
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");
@@ -34,7 +34,9 @@
#include "config_utility.hpp" #include "config_utility.hpp"
#include "frame_rate.hpp" #include "frame_rate.hpp"
#include "character.hpp" #include "combat_data.hpp"
#include "character_data.hpp"
#include "enemy_data.hpp"
//client //client
#include "base_scene.hpp" #include "base_scene.hpp"
@@ -48,7 +50,9 @@ public:
int* const argClientIndex, int* const argClientIndex,
int* const argAccountIndex, int* const argAccountIndex,
int* const argCharacterIndex, int* const argCharacterIndex,
CharacterMap* argCharacterMap std::map<int, CombatData>* argCombatMap,
std::map<int, CharacterData>* argCharacterMap,
std::map<int, EnemyData>* argEnemyMap
); );
~InCombat(); ~InCombat();
@@ -71,12 +75,14 @@ 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; ConfigUtility& config;
@@ -84,7 +90,9 @@ protected:
int& clientIndex; int& clientIndex;
int& accountIndex; int& accountIndex;
int& characterIndex; int& characterIndex;
CharacterMap& characterMap; std::map<int, CombatData>& combatMap;
std::map<int, CharacterData>& characterMap;
std::map<int, EnemyData>& enemyMap;
//graphics //graphics
//TODO: graphics //TODO: graphics
@@ -24,10 +24,9 @@
#include "channels.hpp" #include "channels.hpp"
#include "utility.hpp" #include "utility.hpp"
#include <stdexcept>
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <iostream> #include <stdexcept>
//------------------------- //-------------------------
//Public access members //Public access members
@@ -39,69 +38,17 @@ InWorld::InWorld(
int* const argClientIndex, int* const argClientIndex,
int* const argAccountIndex, int* const argAccountIndex,
int* const argCharacterIndex, int* const argCharacterIndex,
CharacterMap* argCharacterMap std::map<int, CombatData>* argCombatMap,
std::map<int, CharacterData>* argCharacterMap
): ):
config(*argConfig), config(*argConfig),
network(*argNetwork), network(*argNetwork),
clientIndex(*argClientIndex), clientIndex(*argClientIndex),
accountIndex(*argAccountIndex), accountIndex(*argAccountIndex),
characterIndex(*argCharacterIndex), characterIndex(*argCharacterIndex),
combatMap(*argCombatMap),
characterMap(*argCharacterMap) characterMap(*argCharacterMap)
{ {
//register the pager
lua_pushstring(lua, TORTUGA_REGION_PAGER_PSEUDO_INDEX);
lua_pushlightuserdata(lua, &pager);
lua_settable(L, LUA_REGISTRYINDEX);
//register the tilesheet
lua_pushstring(lua, TORTUGA_TILE_SHEET_PSEUDO_INDEX);
lua_pushlightuserdata(lua, &tileSheet);
lua_settable(L, LUA_REGISTRYINDEX);
//setup the component objecrs
pager.SetLuaState(lua);
//get the config info
lua_getglobal(lua, "config");
lua_getfield(lua, -1, "dir");
lua_getfield(lua, -1, "fonts");
std::string fonts = lua_tostring(lua, -1);
lua_getfield(lua, -2, "interface");
std::string interface = lua_tostring(lua, -1);
lua_getfield(lua, -3, "sprites");
std::string sprites = lua_tostring(lua, -1);
lua_getfield(lua, -4, "scripts");
std::string scripts = lua_tostring(lua, -1);
lua_pop(lua, 6);
//run the additional scripts
if (luaL_dofile(lua, (scripts + "in_world.lua").c_str())) {
throw(std::runtime_error(std::string() + "Failed to run in_world.lua: " + lua_tostring(lua, -1) ));
}
//setup the utility objects
buttonImage.LoadSurface(interface + "button_menu.bmp");
buttonImage.SetClipH(buttonImage.GetClipH()/3);
font.LoadSurface(fonts + "pk_white_8.bmp");
//pass the utility objects
backButton.SetImage(&buttonImage);
backButton.SetFont(&font);
//set the button positions
backButton.SetX(50);
backButton.SetY(50 + buttonImage.GetClipH() * 0);
//set the button texts
backButton.SetText("Back");
//entities
character.GetSprite()->LoadSurface(sprites + "elliot2.bmp", 4, 4);
character.SetBoundingBox({0, 0,
character.GetSprite()->GetImage()->GetClipW(),
character.GetSprite()->GetImage()->GetClipH()
});
//-------------------------
//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);
@@ -135,13 +82,7 @@ InWorld::InWorld(
} }
InWorld::~InWorld() { InWorld::~InWorld() {
//unregister the map components //
lua_pushstring(lua, TORTUGA_REGION_PAGER_PSEUDO_INDEX);
lua_pushstring(lua, TORTUGA_TILE_SHEET_PSEUDO_INDEX);
lua_pushnil(lua);
lua_settable(lua, LUA_REGISTRYINDEX);
lua_pushnil(lua);
lua_settable(lua, LUA_REGISTRYINDEX);
} }
//------------------------- //-------------------------
@@ -165,34 +106,10 @@ void InWorld::Update(double delta) {
it.second.Update(delta); it.second.Update(delta);
} }
//TODO: Check collisions here
//check for collisions with the map
BoundingBox wallBounds = {0, 0, tileSheet.GetTileW(), tileSheet.GetTileH()};
const int xCount = character.GetBoundingBox().w / wallBounds.w + 1;
const int yCount = character.GetBoundingBox().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, character.GetOrigin().x);
wallBounds.y = wallBounds.h * j + snapToBase((double)wallBounds.h, character.GetOrigin().y);
if (!pager.GetSolid(wallBounds.x / wallBounds.w, wallBounds.y / wallBounds.h)) {
continue;
}
if ((character.GetOrigin() + character.GetBoundingBox()).CheckOverlap(wallBounds)) {
character.SetOrigin(character.GetOrigin() - (character.GetMotion() * delta));
character.SetMotion({0,0});
character.CorrectSprite();
}
}
}
//update the camera //update the camera
if(localCharacter) { if(localCharacter) {
camera.x = localCharacter->GetOrigin().x - camera.marginX; camera.x = localCharacter->origin.x - camera.marginX;
camera.y = localCharacter->GetOrigin().y - camera.marginY; camera.y = localCharacter->origin.y - camera.marginY;
} }
//check the map //check the map
@@ -258,60 +175,77 @@ void InWorld::MouseButtonUp(SDL_MouseButtonEvent const& button) {
} }
void InWorld::KeyDown(SDL_KeyboardEvent const& key) { void InWorld::KeyDown(SDL_KeyboardEvent const& key) {
if (!localCharacter) {
return;
}
//player movement
Vector2 motion = localCharacter->GetMotion();
switch(key.keysym.sym) { switch(key.keysym.sym) {
//player movement
case SDLK_LEFT: case SDLK_LEFT:
motion.x -= CHARACTER_WALKING_SPEED; if (localCharacter) {
localCharacter->motion.x -= CHARACTER_WALKING_SPEED;
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
break; break;
case SDLK_RIGHT: case SDLK_RIGHT:
motion.x += CHARACTER_WALKING_SPEED; if (localCharacter) {
localCharacter->motion.x += CHARACTER_WALKING_SPEED;
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
break; break;
case SDLK_UP: case SDLK_UP:
motion.y -= CHARACTER_WALKING_SPEED; if (localCharacter) {
localCharacter->motion.y -= CHARACTER_WALKING_SPEED;
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
break; break;
case SDLK_DOWN: case SDLK_DOWN:
motion.y += CHARACTER_WALKING_SPEED; if (localCharacter) {
localCharacter->motion.y += CHARACTER_WALKING_SPEED;
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
break; break;
default:
return;
} }
localCharacter->SetMotion(motion);
localCharacter->CorrectSprite();
SendPlayerUpdate();
} }
void InWorld::KeyUp(SDL_KeyboardEvent const& key) { void InWorld::KeyUp(SDL_KeyboardEvent const& key) {
if (!localCharacter) {
return;
}
//player movement
Vector2 motion = localCharacter->GetMotion();
switch(key.keysym.sym) { switch(key.keysym.sym) {
//NOTE: The use of min/max here are to prevent awkward movements //player movement
case SDLK_LEFT: case SDLK_LEFT:
motion.x = std::min(motion.x + CHARACTER_WALKING_SPEED, 0.0); if (localCharacter) {
localCharacter->motion.x += CHARACTER_WALKING_SPEED;
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
break; break;
case SDLK_RIGHT: case SDLK_RIGHT:
motion.x = std::max(motion.x - CHARACTER_WALKING_SPEED, 0.0); if (localCharacter) {
localCharacter->motion.x -= CHARACTER_WALKING_SPEED;
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
break; break;
case SDLK_UP: case SDLK_UP:
motion.y = std::min(motion.y + CHARACTER_WALKING_SPEED, 0.0); if (localCharacter) {
localCharacter->motion.y += CHARACTER_WALKING_SPEED;
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
break; break;
case SDLK_DOWN: case SDLK_DOWN:
motion.y = std::max(motion.y - CHARACTER_WALKING_SPEED, 0.0); if (localCharacter) {
localCharacter->motion.y -= CHARACTER_WALKING_SPEED;
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
break; break;
default:
return;
} }
localCharacter->SetMotion(motion);
localCharacter->CorrectSprite();
SendPlayerUpdate();
} }
//------------------------- //-------------------------
@@ -352,41 +286,36 @@ void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) {
} }
//create the character object //create the character object
Character& newCharacter = characterMap[argPacket->characterIndex]; CharacterData& character = characterMap[argPacket->characterIndex];
//fill out the character's members //set the members
newCharacter.SetHandle(argPacket->handle); character.handle = argPacket->handle;
newCharacter.SetAvatar(argPacket->avatar); character.avatar = 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;
newCharacter.GetSprite()->LoadSurface(config["dir.sprites"] + newCharacter.GetAvatar(), 4, 4); character.CorrectSprite();
newCharacter.SetOrigin(argPacket->origin);
newCharacter.SetMotion(argPacket->motion);
(*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 = &newCharacter; localCharacter = &character;
//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->GetSprite()->GetImage()->GetClipW() / 2); camera.marginX = (GetScreen()->w / 2 - localCharacter->sprite.GetImage()->GetClipW() / 2);
camera.marginY = (GetScreen()->h / 2 - localCharacter->GetSprite()->GetImage()->GetClipH() / 2); camera.marginY = (GetScreen()->h / 2 - localCharacter->sprite.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;
@@ -398,17 +327,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;
} }
Character& character = characterMap[argPacket->characterIndex]; CharacterData& character = characterMap[argPacket->characterIndex];
//other characters moving //other characters moving
if (argPacket->characterIndex != characterIndex) { if (argPacket->characterIndex != characterIndex) {
character.SetOrigin(argPacket->origin); character.roomIndex = argPacket->roomIndex;
character.SetMotion(argPacket->motion); character.origin = argPacket->origin;
character.motion = argPacket->motion;
character.CorrectSprite(); character.CorrectSprite();
} }
} }
@@ -435,8 +364,6 @@ 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);
} }
@@ -447,12 +374,12 @@ void InWorld::SendPlayerUpdate() {
newPacket.type = SerialPacketType::CHARACTER_UPDATE; newPacket.type = SerialPacketType::CHARACTER_UPDATE;
newPacket.characterIndex = characterIndex; newPacket.characterIndex = characterIndex;
//NOTE: omitting the handle and avatar here //handle, avatar
newPacket.accountIndex = accountIndex; newPacket.accountIndex = accountIndex;
newPacket.roomIndex = 0; //TODO: room index newPacket.roomIndex = localCharacter->roomIndex;
newPacket.origin = localCharacter->GetOrigin(); newPacket.origin = localCharacter->origin;
newPacket.motion = localCharacter->GetMotion(); newPacket.motion = localCharacter->motion;
newPacket.stats = *localCharacter->GetStats(); newPacket.stats = localCharacter->stats;
//TODO: gameplay components: equipment, items, buffs, debuffs //TODO: gameplay components: equipment, items, buffs, debuffs
@@ -508,7 +435,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 of this area //check if the region is outside off 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
@@ -22,28 +22,27 @@
#ifndef INWORLD_HPP_ #ifndef INWORLD_HPP_
#define INWORLD_HPP_ #define INWORLD_HPP_
//map stuff //maps
#include "tile_sheet.hpp" #include "region_pager_base.hpp"
#include "region_pager_lua.hpp"
//networking //networking
#include "udp_network_utility.hpp" #include "udp_network_utility.hpp"
//graphics & ui //graphics
#include "image.hpp" #include "image.hpp"
#include "raster_font.hpp" #include "raster_font.hpp"
#include "button.hpp" #include "button.hpp"
#include "tile_sheet.hpp"
//utilities //common
#include "config_utility.hpp"
#include "frame_rate.hpp" #include "frame_rate.hpp"
#include "timer.hpp"
#include "combat_data.hpp"
#include "character_data.hpp"
//client //client
#include "base_scene.hpp" #include "base_scene.hpp"
#include "character.hpp"
//APIs
#include "lua/lua.hpp"
//STL //STL
#include <map> #include <map>
@@ -57,7 +56,8 @@ public:
int* const argClientIndex, int* const argClientIndex,
int* const argAccountIndex, int* const argAccountIndex,
int* const argCharacterIndex, int* const argCharacterIndex,
CharacterMap* argCharacterMap std::map<int, CombatData>* argCombatMap,
std::map<int, CharacterData>* argCharacterMap
); );
~InWorld(); ~InWorld();
@@ -95,14 +95,14 @@ protected:
//utilities //utilities
void UpdateMap(); void UpdateMap();
//TODO: Streamline this with lua
//shared parameters //shared parameters
ConfigUtility& config; ConfigUtility& config;
UDPNetworkUtility& network; UDPNetworkUtility& network;
int& clientIndex; int& clientIndex;
int& accountIndex; int& accountIndex;
int& characterIndex; int& characterIndex;
CharacterMap& characterMap; std::map<int, CombatData>& combatMap;
std::map<int, CharacterData>& characterMap;
//graphics //graphics
Image buttonImage; Image buttonImage;
@@ -117,15 +117,14 @@ protected:
Button shutDownButton; Button shutDownButton;
//TODO: Review the camera //TODO: Review the camera
struct { struct {
struct { int x = 0, y = 0;
int x, y; int width = 0, height = 0;
}origin, margin; int marginX = 0, marginY = 0;
}camera; } camera;
FrameRate fps; FrameRate fps;
//game //game
Character* localCharacter = nullptr; CharacterData* localCharacter = nullptr;
}; };
#endif #endif
-85
View File
@@ -1,85 +0,0 @@
/* $Id: linit.c,v 1.32, modified
* Initialization of libraries for lua.c and other clients
* See Copyright Notice in lua.h
*
* If you embed Lua in your program and need to open the standard
* libraries, call luaL_openlibs in your program. If you need a
* different set of libraries, copy this file to your project and edit
* it to suit your needs.
*
* Modified for use in Tortuga, renamed to linit.cpp
* Modifications are released under the zlib license:
*
* 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.
*/
#define linit_c
#define LUA_LIB
#include "lua/lua.hpp"
#include "region_api.hpp"
#include "region_pager_api.hpp"
#include "tile_sheet_api.hpp"
//these libs are loaded by lua.c and are readily available to any Lua program
static const luaL_Reg loadedlibs[] = {
//Standard libs
{"_G", luaopen_base},
{LUA_LOADLIBNAME, luaopen_package},
{LUA_COLIBNAME, luaopen_coroutine},
{LUA_TABLIBNAME, luaopen_table},
{LUA_IOLIBNAME, luaopen_io},
{LUA_OSLIBNAME, luaopen_os},
{LUA_STRLIBNAME, luaopen_string},
{LUA_BITLIBNAME, luaopen_bit32},
{LUA_MATHLIBNAME, luaopen_math},
{LUA_DBLIBNAME, luaopen_debug},
//Tortuga's API
{TORTUGA_REGION_NAME, openRegionAPI},
{TORTUGA_REGION_PAGER_NAME, openRegionPagerAPI},
{TORTUGA_TILE_SHEET_NAME, openTileSheetAPI},
{NULL, NULL}
};
//these libs are preloaded and must be required before used
static const luaL_Reg preloadedlibs[] = {
{NULL, NULL}
};
LUALIB_API void luaL_openlibs (lua_State *L) {
const luaL_Reg *lib;
//call open functions from 'loadedlibs' and set results to global table
for (lib = loadedlibs; lib->func; lib++) {
luaL_requiref(L, lib->name, lib->func, 1);
lua_pop(L, 1); //remove lib
}
//add open functions from 'preloadedlibs' into 'package.preload' table
luaL_getsubtable(L, LUA_REGISTRYINDEX, "_PRELOAD");
for (lib = preloadedlibs; lib->func; lib++) {
lua_pushcfunction(L, lib->func);
lua_setfield(L, -2, lib->name);
}
lua_pop(L, 1); //remove _PRELOAD table
}
@@ -30,25 +30,21 @@
//Public access members //Public access members
//------------------------- //-------------------------
LobbyMenu::LobbyMenu(lua_State* L, UDPNetworkUtility& aNetwork): LobbyMenu::LobbyMenu(
lua(L), ConfigUtility* const argConfig,
network(aNetwork) UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
int* const argAccountIndex
):
config(*argConfig),
network(*argNetwork),
clientIndex(*argClientIndex),
accountIndex(*argAccountIndex)
{ {
//get the config info
lua_getglobal(lua, "config");
lua_getfield(lua, -1, "dir");
lua_getfield(lua, -1, "interface");
lua_getfield(lua, -2, "fonts");
std::string interfaceDir = lua_tostring(lua, -2);
std::string fontsDir = lua_tostring(lua, -1);
lua_pop(lua, 4);
//setup the utility objects //setup the utility objects
image.LoadSurface(interfaceDir + "button_menu.bmp"); image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
image.SetClipH(image.GetClipH()/3); image.SetClipH(image.GetClipH()/3);
font.LoadSurface(fontsDir + "pk_white_8.bmp"); font.LoadSurface(config["dir.fonts"] + "pk_white_8.bmp");
//pass the utility objects //pass the utility objects
search.SetImage(&image); search.SetImage(&image);
@@ -92,11 +88,11 @@ void LobbyMenu::FrameStart() {
void LobbyMenu::Update(double delta) { void LobbyMenu::Update(double delta) {
//suck in and process all waiting packets //suck in and process all waiting packets
SerialPacket* packetBuffer = new SerialPacket(); SerialPacket* packetBuffer = static_cast<SerialPacket*>(malloc(MAX_PACKET_SIZE));
while(network.Receive(packetBuffer)) { while(network.Receive(packetBuffer)) {
HandlePacket(packetBuffer); HandlePacket(packetBuffer);
} }
delete packetBuffer; free(static_cast<void*>(packetBuffer));
} }
void LobbyMenu::FrameEnd() { void LobbyMenu::FrameEnd() {
@@ -152,44 +148,26 @@ void LobbyMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) {
} }
void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) { void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
//prep
lua_getglobal(lua, "config");
if (search.MouseButtonUp(button) == Button::State::HOVER) { if (search.MouseButtonUp(button) == Button::State::HOVER) {
//get the set parameters
lua_getfield(lua, -1, "server");
lua_getfield(lua, -1, "host");
lua_getfield(lua, -2, "port");
//broadcast to the network, or a specific server //broadcast to the network, or a specific server
SerialPacket packet; SerialPacket packet;
packet.type = SerialPacketType::BROADCAST_REQUEST; packet.type = SerialPacketType::BROADCAST_REQUEST;
network.SendTo(lua_tostring(lua, -2), lua_tointeger(lua, -1), &packet); network.SendTo(config["server.host"].c_str(), config.Int("server.port"), &packet);
//reset the server list //reset the server list
serverInfo.clear(); serverInfo.clear();
selection = nullptr; selection = nullptr;
//clear the parameters
lua_pop(lua, 3);
} }
else if (join.MouseButtonUp(button) == Button::State::HOVER && selection != nullptr && selection->compatible) { else if (join.MouseButtonUp(button) == Button::State::HOVER && selection != nullptr && selection->compatible) {
//get the parameters
lua_getfield(lua, -1, "client");
lua_getfield(lua, -1, "username");
//pack the packet //pack the packet
ClientPacket packet; ClientPacket packet;
packet.type = SerialPacketType::JOIN_REQUEST; packet.type = SerialPacketType::JOIN_REQUEST;
strncpy(packet.username, lua_tostring(lua, -1), PACKET_STRING_SIZE); strncpy(packet.username, config["client.username"].c_str(), PACKET_STRING_SIZE);
//join the selected server //join the selected server
network.SendTo(&selection->address, &packet); network.SendTo(&selection->address, &packet);
selection = nullptr; selection = nullptr;
//clear the parameters
lua_pop(lua, 2);
} }
else if (back.MouseButtonUp(button) == Button::State::HOVER) { else if (back.MouseButtonUp(button) == Button::State::HOVER) {
@@ -209,9 +187,6 @@ void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
else { else {
selection = nullptr; selection = nullptr;
} }
//clear the parameters
lua_pop(lua, 1);
} }
void LobbyMenu::KeyDown(SDL_KeyboardEvent const& key) { void LobbyMenu::KeyDown(SDL_KeyboardEvent const& key) {
@@ -229,10 +204,10 @@ void LobbyMenu::KeyUp(SDL_KeyboardEvent const& key) {
void LobbyMenu::HandlePacket(SerialPacket* const argPacket) { void LobbyMenu::HandlePacket(SerialPacket* const argPacket) {
switch(argPacket->type) { switch(argPacket->type) {
case SerialPacketType::BROADCAST_RESPONSE: case SerialPacketType::BROADCAST_RESPONSE:
HandleBroadcastResponse(dynamic_cast<ServerPacket*>(argPacket)); HandleBroadcastResponse(static_cast<ServerPacket*>(argPacket));
break; break;
case SerialPacketType::JOIN_RESPONSE: case SerialPacketType::JOIN_RESPONSE:
HandleJoinResponse(dynamic_cast<ClientPacket*>(argPacket)); HandleJoinResponse(static_cast<ClientPacket*>(argPacket));
break; break;
//handle errors //handle errors
default: default:
@@ -257,25 +232,16 @@ void LobbyMenu::HandleBroadcastResponse(ServerPacket* const argPacket) {
} }
void LobbyMenu::HandleJoinResponse(ClientPacket* const argPacket) { void LobbyMenu::HandleJoinResponse(ClientPacket* const argPacket) {
lua_getglobal(lua, "config"); clientIndex = argPacket->clientIndex;
lua_getfield(lua, -1, "client"); accountIndex = argPacket->accountIndex;
lua_getfield(lua, -1, "handle");
lua_getfield(lua, -2, "avatar");
lua_pushinteger(lua, argPacket->clientIndex);
lua_pushinteger(lua, argPacket->accountIndex);
lua_setfield(lua, -5, "accountIndex");
lua_setfield(lua, -4, "clientIndex");
network.Bind(&argPacket->srcAddress, Channels::SERVER); network.Bind(&argPacket->srcAddress, Channels::SERVER);
SetNextScene(SceneList::INWORLD); SetNextScene(SceneList::INWORLD);
//send this player's character info //send this player's character info
CharacterPacket newPacket; CharacterPacket newPacket;
newPacket.type = SerialPacketType::CHARACTER_NEW; newPacket.type = SerialPacketType::CHARACTER_NEW;
strncpy(newPacket.handle, lua_tostring(lua, -2), PACKET_STRING_SIZE); strncpy(newPacket.handle, config["client.handle"].c_str(), PACKET_STRING_SIZE);
strncpy(newPacket.avatar, lua_tostring(lua, -1), PACKET_STRING_SIZE); strncpy(newPacket.avatar, config["client.avatar"].c_str(), PACKET_STRING_SIZE);
newPacket.accountIndex = argPacket->accountIndex; newPacket.accountIndex = accountIndex;
network.SendTo(Channels::SERVER, &newPacket); network.SendTo(Channels::SERVER, &newPacket);
lua_pop(lua, 4);
} }
@@ -28,21 +28,24 @@
#include "button.hpp" #include "button.hpp"
//utilities //utilities
#include "config_utility.hpp"
#include "udp_network_utility.hpp" #include "udp_network_utility.hpp"
//client //client
#include "base_scene.hpp" #include "base_scene.hpp"
//APIs
#include "lua/lua.hpp"
//STL //STL
#include <vector> #include <vector>
class LobbyMenu : public BaseScene { class LobbyMenu : public BaseScene {
public: public:
//Public access members //Public access members
LobbyMenu(lua_State*, UDPNetworkUtility&); LobbyMenu(
ConfigUtility* const argConfig,
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
int* const argAccountIndex
);
~LobbyMenu(); ~LobbyMenu();
protected: protected:
@@ -65,8 +68,10 @@ protected:
void HandleJoinResponse(ClientPacket* const); void HandleJoinResponse(ClientPacket* const);
//shared parameters //shared parameters
lua_State* lua = nullptr; ConfigUtility& config;
UDPNetworkUtility& network; UDPNetworkUtility& network;
int& clientIndex;
int& accountIndex;
//members //members
Image image; Image image;
@@ -87,7 +92,7 @@ protected:
std::vector<ServerInformation> serverInfo; std::vector<ServerInformation> serverInfo;
//a terrible hack, forgive me //a terrible hack, forgive me
//TODO: I'd love a proper gui system for this //I'd love a proper gui system for this
SDL_Rect listBox; SDL_Rect listBox;
ServerInformation* selection = nullptr; ServerInformation* selection = nullptr;
}; };
+2
View File
@@ -27,6 +27,7 @@
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; ClientApplication app;
app.Init(argc, argv); app.Init(argc, argv);
@@ -37,5 +38,6 @@ int main(int argc, char** argv) {
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;
} }
@@ -25,22 +25,13 @@
//Public access members //Public access members
//------------------------- //-------------------------
MainMenu::MainMenu(lua_State* L): lua(L) { MainMenu::MainMenu(ConfigUtility* const argConfig):
//get the config info config(*argConfig)
lua_getglobal(lua, "config"); {
lua_getfield(lua, -1, "dir");
lua_getfield(lua, -1, "interface");
lua_getfield(lua, -2, "fonts");
std::string interfaceDir = lua_tostring(lua, -2);
std::string fontsDir = lua_tostring(lua, -1);
lua_pop(lua, 4);
//setup the utility objects //setup the utility objects
image.LoadSurface(interfaceDir + "button_menu.bmp"); image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
image.SetClipH(image.GetClipH()/3); image.SetClipH(image.GetClipH()/3);
font.LoadSurface(fontsDir + "pk_white_8.bmp"); font.LoadSurface(config["dir.fonts"] + "pk_white_8.bmp");
//pass the utility objects //pass the utility objects
startButton.SetImage(&image); startButton.SetImage(&image);
@@ -111,13 +102,12 @@ void MainMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) {
void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) { void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
if (startButton.MouseButtonUp(button) == Button::State::HOVER) { if (startButton.MouseButtonUp(button) == Button::State::HOVER) {
SetNextScene(SceneList::INWORLD); SetNextScene(SceneList::LOBBYMENU);
} }
if (optionsButton.MouseButtonUp(button) == Button::State::HOVER) { if (optionsButton.MouseButtonUp(button) == Button::State::HOVER) {
SetNextScene(SceneList::OPTIONSMENU); SetNextScene(SceneList::OPTIONSMENU);
} }
if (quitButton.MouseButtonUp(button) == Button::State::HOVER && if (quitButton.MouseButtonUp(button) == Button::State::HOVER) {
button.button & SDL_BUTTON_LMASK) {
QuitEvent(); QuitEvent();
} }
} }
@@ -24,16 +24,15 @@
#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"
#include "lua/lua.hpp"
class MainMenu : public BaseScene { class MainMenu : public BaseScene {
public: public:
//Public access members //Public access members
MainMenu(lua_State* L); MainMenu(ConfigUtility* const);
~MainMenu(); ~MainMenu();
protected: protected:
@@ -51,7 +50,7 @@ protected:
void KeyUp(SDL_KeyboardEvent const&); void KeyUp(SDL_KeyboardEvent const&);
//shared parameters //shared parameters
lua_State* lua = nullptr; ConfigUtility& config;
//members //members
Image image; Image image;
+3 -4
View File
@@ -1,7 +1,7 @@
#config #config
INCLUDES+=. scenes ../common/debugging ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet ../common/network/serial ../common/ui ../common/utilities INCLUDES+=. ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet ../common/network/serial ../common/ui ../common/utilities
LIBS+=client.a ../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua LIBS+=../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) -DGRAPHICS
#source #source
CXXSRC=$(wildcard *.cpp) CXXSRC=$(wildcard *.cpp)
@@ -16,7 +16,6 @@ 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)
@@ -25,22 +25,13 @@
//Public access members //Public access members
//------------------------- //-------------------------
OptionsMenu::OptionsMenu(lua_State* L): lua(L) { OptionsMenu::OptionsMenu(ConfigUtility* const argConfig):
//get the config info config(*argConfig)
lua_getglobal(lua, "config"); {
lua_getfield(lua, -1, "dir");
lua_getfield(lua, -1, "interface");
lua_getfield(lua, -2, "fonts");
std::string interfaceDir = lua_tostring(lua, -2);
std::string fontsDir = lua_tostring(lua, -1);
lua_pop(lua, 4);
//setup the utility objects //setup the utility objects
image.LoadSurface(interfaceDir + "button_menu.bmp"); image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
image.SetClipH(image.GetClipH()/3); image.SetClipH(image.GetClipH()/3);
font.LoadSurface(fontsDir + "pk_white_8.bmp"); font.LoadSurface(config["dir.fonts"] + "pk_white_8.bmp");
//pass the utility objects //pass the utility objects
backButton.SetImage(&image); backButton.SetImage(&image);
@@ -93,8 +84,7 @@ void OptionsMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) {
} }
void OptionsMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) { void OptionsMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
if (backButton.MouseButtonUp(button) == Button::State::HOVER && if (backButton.MouseButtonUp(button) == Button::State::HOVER) {
button.button & SDL_BUTTON_LMASK) {
SetNextScene(SceneList::MAINMENU); SetNextScene(SceneList::MAINMENU);
} }
} }
@@ -24,17 +24,16 @@
#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"
#include "lua/lua.hpp"
//TODO: The options screen needs to be USED //TODO: The options screen needs to be USED
class OptionsMenu : public BaseScene { class OptionsMenu : public BaseScene {
public: public:
//Public access members //Public access members
OptionsMenu(lua_State* L); OptionsMenu(ConfigUtility* const);
~OptionsMenu(); ~OptionsMenu();
protected: protected:
@@ -52,7 +51,7 @@ protected:
void KeyUp(SDL_KeyboardEvent const&); void KeyUp(SDL_KeyboardEvent const&);
//shared parameters //shared parameters
lua_State* lua = nullptr; ConfigUtility& config;
//members //members
Image image; Image image;
@@ -21,21 +21,14 @@
*/ */
#include "splash_screen.hpp" #include "splash_screen.hpp"
#include <string>
//------------------------- //-------------------------
//Public access members //Public access members
//------------------------- //-------------------------
SplashScreen::SplashScreen(lua_State* L): lua(L) { SplashScreen::SplashScreen(ConfigUtility* const argConfig):
//get the config info config(*argConfig)
lua_getglobal(lua, "config"); {
lua_getfield(lua, -1, "dir"); logo.LoadSurface(config["dir.logos"] + "krstudios.bmp");
lua_getfield(lua, -1, "logos");
std::string logos = lua_tostring(lua, -1);
lua_pop(lua, 3);
logo.LoadSurface(logos + "krstudios.bmp");
startTick = std::chrono::steady_clock::now(); startTick = std::chrono::steady_clock::now();
} }
@@ -24,16 +24,15 @@
#include "base_scene.hpp" #include "base_scene.hpp"
#include "config_utility.hpp"
#include "image.hpp" #include "image.hpp"
#include "lua/lua.hpp"
#include <chrono> #include <chrono>
class SplashScreen : public BaseScene { class SplashScreen : public BaseScene {
public: public:
//Public access members //Public access members
SplashScreen(lua_State* L); SplashScreen(ConfigUtility* const);
~SplashScreen(); ~SplashScreen();
protected: protected:
@@ -42,7 +41,7 @@ protected:
void Render(SDL_Surface* const); void Render(SDL_Surface* const);
//shared parameters //shared parameters
lua_State* lua = nullptr; ConfigUtility& config;
//members //members
std::chrono::steady_clock::time_point startTick; std::chrono::steady_clock::time_point startTick;
@@ -19,23 +19,27 @@
* 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.hpp" #include "character_data.hpp"
void Character::Update(double delta) { void CharacterData::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
} }
void Character::DrawTo(SDL_Surface* const dest, int camX, int camY) { #ifdef GRAPHICS
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 Character::CorrectSprite() { void CharacterData::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);
@@ -59,3 +63,5 @@ void Character::CorrectSprite() {
sprite.SetXIndex(0); sprite.SetXIndex(0);
} }
} }
#endif
@@ -22,15 +22,22 @@
#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;
@@ -41,14 +48,25 @@ 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
@@ -23,18 +23,31 @@
#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;
@@ -47,6 +60,11 @@ 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
@@ -25,6 +25,11 @@
#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>
@@ -40,6 +45,11 @@ 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;
}; };
+2 -2
View File
@@ -1,7 +1,7 @@
#config #config
INCLUDES+=. INCLUDES+=. ../utilities ../graphics
LIBS+= LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) -DGRAPHICS
#source #source
CXXSRC=$(wildcard *.cpp) CXXSRC=$(wildcard *.cpp)
+31
View File
@@ -0,0 +1,31 @@
/* 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 "character_data.hpp"
#include "combat_data.hpp"
#include "enemy_data.hpp"
#include "statistics.hpp"
/* DOCS: Sanity check, read more
* 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
* are written correctly via make.
*/
@@ -21,24 +21,24 @@
*/ */
#include "tile_sheet.hpp" #include "tile_sheet.hpp"
void TileSheet::Load(std::string fname, int tileWidth, int tileHeight) { void TileSheet::Load(std::string fname, int xc, int yc) {
XCount = xc;
YCount = yc;
image.LoadSurface(fname); image.LoadSurface(fname);
image.SetClipW(tileWidth); image.SetClipW(image.GetClipW()/XCount);
image.SetClipH(tileHeight); image.SetClipH(image.GetClipH()/YCount);
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::DrawTileTo(SDL_Surface* const dest, int x, int y, Region::type_t tile) { void TileSheet::DrawTo(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 w, int h) { Load(f, w, h); } TileSheet(std::string f, int x, int y) { Load(f, x, y); }
~TileSheet() = default; ~TileSheet() = default;
void Load(std::string fname, int tileWidth, int tileHeight); void Load(std::string fname, int XCount, int YCount);
void Unload(); void Unload();
void DrawTileTo(SDL_Surface* const dest, int x, int y, Region::type_t tile); void DrawTo(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; } Image* GetImage() { return &image; }
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
-1
View File
@@ -1,5 +1,4 @@
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
View File
@@ -1,5 +1,5 @@
#config #config
INCLUDES+=. ../utilities ../graphics INCLUDES+=. ../utilities
LIBS+= LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
-9
View File
@@ -35,7 +35,6 @@ 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) {
@@ -45,11 +44,3 @@ 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];
}
-16
View File
@@ -22,17 +22,10 @@
#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;
@@ -45,23 +38,14 @@ 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
+12 -28
View File
@@ -37,20 +37,6 @@ 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());
@@ -78,41 +64,39 @@ static int getDepth(lua_State* L) {
return 1; return 1;
} }
static int load(lua_State* L) { static int onLoad(lua_State* L) {
//EMPTY //TODO: onLoad()
lua_pushboolean(L, false); lua_pushboolean(L, false);
return 1; return 1;
} }
static int save(lua_State* L) { static int onSave(lua_State* L) {
//EMPTY //TODO: onSave()
return 0; return 0;
} }
static int create(lua_State* L) { static int onCreate(lua_State* L) {
//EMPTY //TODO: onCreate()
return 0; return 0;
} }
static int unload(lua_State* L) { static int onUnload(lua_State* L) {
//EMPTY //TODO: onUnload()
return 0; return 0;
} }
static const luaL_Reg regionLib[] = { static const luaL_Reg regionLib[] = {
{"SetTile",setTile}, {"SetTile",setTile},
{"GetTile",getTile}, {"GetTile",getTile},
{"SetSolid",setSolid},
{"GetSolid",getSolid},
{"GetX",getX}, {"GetX",getX},
{"GetY",getY}, {"GetY",getY},
{"GetWidth",getWidth}, {"GetWidth",getWidth},
{"GetHeight",getHeight}, {"GetHeight",getHeight},
{"GetDepth",getDepth}, {"GetDepth",getDepth},
{"Load",load}, {"OnLoad",onLoad},
{"Save",save}, {"OnSave",onSave},
{"Create",create}, {"OnCreate",onCreate},
{"Unload",unload}, {"OnUnload",onUnload},
{nullptr, nullptr} {nullptr, nullptr}
}; };
+20 -25
View File
@@ -24,14 +24,10 @@
#include "region_pager_lua.hpp" #include "region_pager_lua.hpp"
#include "region.hpp" #include "region.hpp"
#include <stdexcept>
#include <string> #include <string>
static int getRegionPager(lua_State* L) { //DOCS: These functions are just wrappers for the RegionPagerLua class
lua_pushstring(L, TORTUGA_REGION_PAGER_PSEUDO_INDEX);
lua_gettable(L, LUA_REGISTRYINDEX);
}
//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));
@@ -47,20 +43,6 @@ 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));
@@ -68,6 +50,20 @@ 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) {
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1)); RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
Region* region = pager->LoadRegion(lua_tointeger(L, 2), lua_tointeger(L, 3)); Region* region = pager->LoadRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
@@ -95,13 +91,12 @@ static int unloadRegion(lua_State* L) {
return 0; return 0;
} }
static const luaL_Reg regionPagerLib[] = { static const luaL_Reg pagerlib[] = {
{"GetRegionPager", getRegionPager},
{"SetTile", setTile}, {"SetTile", setTile},
{"GetTile", getTile}, {"GetTile", getTile},
{"SetSolid", setSolid},
{"GetSolid", getSolid},
{"GetRegion", getRegion}, {"GetRegion", getRegion},
{"SetDirectory", setDirectory},
{"GetDirectory", getDirectory},
{"LoadRegion", loadRegion}, {"LoadRegion", loadRegion},
{"SaveRegion", saveRegion}, {"SaveRegion", saveRegion},
{"CreateRegion", createRegion}, {"CreateRegion", createRegion},
@@ -110,6 +105,6 @@ static const luaL_Reg regionPagerLib[] = {
}; };
LUAMOD_API int openRegionPagerAPI(lua_State* L) { LUAMOD_API int openRegionPagerAPI(lua_State* L) {
luaL_newlib(L, regionPagerLib); luaL_newlib(L, pagerlib);
return 1; return 1;
} }
+2 -3
View File
@@ -19,12 +19,11 @@
* 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 REGIONPAGERAPI_HPP_ #ifndef PAGERAPI_HPP_
#define REGIONPAGERAPI_HPP_ #define PAGERAPI_HPP_
#include "lua/lua.hpp" #include "lua/lua.hpp"
#define TORTUGA_REGION_PAGER_PSEUDO_INDEX "RegionPagerPseudoIndex"
#define TORTUGA_REGION_PAGER_NAME "RegionPager" #define TORTUGA_REGION_PAGER_NAME "RegionPager"
LUAMOD_API int openRegionPagerAPI(lua_State* L); LUAMOD_API int openRegionPagerAPI(lua_State* L);
-13
View File
@@ -36,20 +36,7 @@ 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);
-4
View File
@@ -35,10 +35,6 @@ 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);
+36 -32
View File
@@ -32,18 +32,19 @@ Region* RegionPagerLua::LoadRegion(int x, int y) {
Region tmpRegion(x, y); Region tmpRegion(x, y);
//API hook //API hook
lua_getglobal(lua, "Region"); lua_getglobal(luaState, "Region");
lua_getfield(lua, -1, "Load"); lua_getfield(luaState, -1, "OnLoad");
lua_pushlightuserdata(lua, &tmpRegion); lua_pushlightuserdata(luaState, &tmpRegion);
if (lua_pcall(lua, 1, 1, 0) != LUA_OK) { lua_pushstring(luaState, directory.c_str());
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) )); if (lua_pcall(luaState, 2, 1, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
} }
//success or failure //success or failure
if (!lua_toboolean(lua, -1)) { if (!lua_toboolean(luaState, -1)) {
lua_pop(lua, 2); lua_pop(luaState, 2);
return nullptr; return nullptr;
} }
lua_pop(lua, 2); lua_pop(luaState, 2);
regionList.push_front(tmpRegion); regionList.push_front(tmpRegion);
return &regionList.front(); return &regionList.front();
} }
@@ -53,13 +54,14 @@ 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(lua, "Region"); lua_getglobal(luaState, "Region");
lua_getfield(lua, -1, "Save"); lua_getfield(luaState, -1, "OnSave");
lua_pushlightuserdata(lua, ptr); lua_pushlightuserdata(luaState, ptr);
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) { lua_pushstring(luaState, directory.c_str());
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) )); if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
} }
lua_pop(lua, 1); lua_pop(luaState, 1);
} }
return ptr; return ptr;
} }
@@ -73,29 +75,30 @@ Region* RegionPagerLua::CreateRegion(int x, int y) {
Region tmpRegion(x, y); Region tmpRegion(x, y);
//API hook //API hook
lua_getglobal(lua, "Region"); lua_getglobal(luaState, "Region");
lua_getfield(lua, -1, "Create"); lua_getfield(luaState, -1, "OnCreate");
lua_pushlightuserdata(lua, &tmpRegion); lua_pushlightuserdata(luaState, &tmpRegion);
//TODO: parameters //TODO: parameters
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) { if (lua_pcall(luaState, 1, 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(lua, 1); lua_pop(luaState, 1);
regionList.push_front(tmpRegion); regionList.push_front(tmpRegion);
return &regionList.front(); return &regionList.front();
} }
void RegionPagerLua::UnloadRegion(int x, int y) { void RegionPagerLua::UnloadRegion(int x, int y) {
lua_getglobal(lua, "Region"); lua_getglobal(luaState, "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(lua, -1, "Unload"); lua_getfield(luaState, -1, "OnUnload");
lua_pushlightuserdata(lua, &region); lua_pushlightuserdata(luaState, &region);
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) { lua_pushstring(luaState, directory.c_str());
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) )); if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
} }
return true; return true;
@@ -103,21 +106,22 @@ void RegionPagerLua::UnloadRegion(int x, int y) {
return false; return false;
}); });
lua_pop(lua, 1); lua_pop(luaState, 1);
} }
void RegionPagerLua::UnloadAll() { void RegionPagerLua::UnloadAll() {
lua_getglobal(lua, "Region"); lua_getglobal(luaState, "Region");
for (auto& it : regionList) { for (auto& it : regionList) {
//API hook //API hook
lua_getfield(lua, -1, "Unload"); lua_getfield(luaState, -1, "OnUnload");
lua_pushlightuserdata(lua, &it); lua_pushlightuserdata(luaState, &it);
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) { lua_pushstring(luaState, directory.c_str());
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) )); if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
} }
} }
lua_pop(lua, 1); lua_pop(luaState, 1);
regionList.clear(); regionList.clear();
} }
+7 -3
View File
@@ -42,10 +42,14 @@ public:
void UnloadAll() override; void UnloadAll() override;
//accessors & mutators //accessors & mutators
lua_State* SetLuaState(lua_State* L) { return lua = L; } std::string SetDirectory(std::string s) { return directory = s; }
lua_State* GetLuaState() { return lua; } std::string GetDirectory() { return directory; }
lua_State* SetLuaState(lua_State* L) { return luaState = L; }
lua_State* GetLuaState() { return luaState; }
protected: protected:
lua_State* lua = nullptr; std::string directory;
lua_State* luaState = nullptr;
}; };
#endif #endif
-82
View File
@@ -1,82 +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 "tile_sheet_api.hpp"
#include "tile_sheet.hpp"
static int getTileSheet(lua_State* L) {
lua_pushstring(L, TORTUGA_TILE_SHEET_PSEUDO_INDEX);
lua_gettable(L, LUA_REGISTRYINDEX);
return 1;
}
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[] = {
{"GetTileSheet",getTileSheet},
{"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;
}
+2 -2
View File
@@ -24,13 +24,13 @@
#include "serial_packet_base.hpp" #include "serial_packet_base.hpp"
#include "combat_defines.hpp" #include "combat_data.hpp"
struct CombatPacket : SerialPacketBase { struct CombatPacket : SerialPacketBase {
//identify the combat instance //identify the combat instance
int combatIndex; int combatIndex;
int difficulty; int difficulty;
TerrainType terrainType; CombatData::Terrain terrainType;
//combatants //combatants
int characterArray[COMBAT_MAX_CHARACTERS]; int characterArray[COMBAT_MAX_CHARACTERS];
+1 -1
View File
@@ -30,7 +30,7 @@
#include "SDL/SDL_net.h" #include "SDL/SDL_net.h"
constexpr int NETWORK_VERSION = 20140701; constexpr int NETWORK_VERSION = 20140607;
constexpr int PACKET_STRING_SIZE = 100; constexpr int PACKET_STRING_SIZE = 100;
struct SerialPacketBase { struct SerialPacketBase {
+6 -8
View File
@@ -53,15 +53,13 @@ void deserializeRegionContent(RegionPacket*, void*);
void deserializeServer(ServerPacket*, void*); void deserializeServer(ServerPacket*, void*);
void deserializeStatistics(Statistics*, void*); void deserializeStatistics(Statistics*, void*);
/* DOCS: Keep PACKET_BUFFER_SIZE up to date /* DOCS: Keep the PACKET_BUFFER_SIZE up to date
* DOCS: SerialPacketType::REGION_CONTENT is currently the largest type of packet, read more * DOCS: REGION_CONTENT is currently the largest type of packet, read more
* The metadata used are: * map content: REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizoeof(region::type_t)
* SerialPacketType * map format: sizeof(int) * 3
* room index * metadata: sizeof(SerialPacket::Type)
* X & Y positon
* The rest is taken up by the Regions's content.
*/ */
constexpr int PACKET_BUFFER_SIZE = sizeof(SerialPacketType) + sizeof(int) * 3 + REGION_FOOTPRINT; constexpr int PACKET_BUFFER_SIZE = REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t) + sizeof(int) * 3 + sizeof(SerialPacketType);
#endif #endif
+2 -2
View File
@@ -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(TerrainType)); SERIALIZE(buffer, &packet->terrainType, sizeof(CombatData::Terrain));
//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(TerrainType)); DESERIALIZE(buffer, &packet->terrainType, sizeof(CombatData::Terrain));
//combatants //combatants
DESERIALIZE(buffer, &packet->characterArray, sizeof(int) * COMBAT_MAX_CHARACTERS); DESERIALIZE(buffer, &packet->characterArray, sizeof(int) * COMBAT_MAX_CHARACTERS);
+2 -8
View File
@@ -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));
//tiles //content
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,9 +49,6 @@ 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) {
@@ -74,7 +71,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);
//tiles //content
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++) {
@@ -83,7 +80,4 @@ void deserializeRegionContent(RegionPacket* packet, void* buffer) {
} }
} }
} }
//solids
DESERIALIZE(buffer, packet->region->GetSolidBitset(), REGION_SOLID_FOOTPRINT);
} }
-1
View File
@@ -36,7 +36,6 @@
* 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;
-77
View File
@@ -1,77 +0,0 @@
/* 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
+40
View File
@@ -0,0 +1,40 @@
/* 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 "check_bounds.hpp"
bool checkPoint(Vector2 const& origin, Vector2 const& bound, Vector2 const& point) {
return !(
point.x < origin.x ||
point.y < origin.y ||
point.x >= origin.x + bound.x ||
point.y >= origin.y + bound.y
);
}
bool checkOverlap(Vector2 const& originOne, Vector2 const& boundOne, Vector2 const& originTwo, Vector2 const& boundTwo) {
return !(
originOne.x >= originTwo.x + boundTwo.x ||
originOne.x + boundOne.x >= originTwo.x ||
originOne.y >= originTwo.y + boundTwo.y ||
originOne.y + boundOne.y >= originTwo.y
);
}
+30
View File
@@ -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 CHECKBOUNDS_HPP_
#define CHECKBOUNDS_HPP_
#include "vector2.hpp"
bool checkPoint(Vector2 const& origin, Vector2 const& bound, Vector2 const& point);
bool checkOverlap(Vector2 const& originOne, Vector2 const& boundOne, Vector2 const& originTwo, Vector2 const& boundTwo);
#endif
+105
View File
@@ -0,0 +1,105 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "config_utility.hpp"
#include <cstdlib>
#include <fstream>
#include <stdexcept>
using namespace std;
void ConfigUtility::Load(string fname) {
ifstream is(fname);
if (!is.is_open()) {
throw(runtime_error("Failed to open config file"));
}
string key, val;
for (;;) { //forever
//eat whitespace
while(isspace(is.peek()))
is.ignore();
//end of file
if (is.eof())
break;
//skip comment lines
if (is.peek() == '#') {
while(is.peek() != '\n' && !is.eof()) {
is.ignore();
}
continue;
}
//read in the pair
getline(is, key,'=');
getline(is, val);
//trim the strings at the start & end
while(key.size() && isspace(*key.begin())) key.erase(0, 1);
while(val.size() && isspace(*val.begin())) val.erase(0, 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);
//allow empty/wiped values
if (key.size() == 0) {
continue;
}
//save the pair
table[key] = val;
}
is.close();
}
std::string& ConfigUtility::String(std::string s) {
return table[s];
}
int ConfigUtility::Integer(std::string s) {
std::map<std::string, std::string>::iterator it = table.find(s);
if (it == table.end()) {
return 0;
}
return atoi(it->second.c_str());
}
double ConfigUtility::Double(std::string s) {
std::map<std::string, std::string>::iterator it = table.find(s);
if (it == table.end()) {
return 0.0;
}
return atof(it->second.c_str());
}
bool ConfigUtility::Boolean(std::string s) {
std::map<std::string, std::string>::iterator it = table.find(s);
if (it == table.end()) {
return false;
}
return it->second == "true";
}
+60
View File
@@ -0,0 +1,60 @@
/* 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 CONFIGUTILITY_HPP_
#define CONFIGUTILITY_HPP_
#include <map>
#include <string>
class ConfigUtility {
public:
ConfigUtility() = default;
ConfigUtility(std::string s) { Load(s); }
void Load(std::string fname);
//convert to a type
std::string& String(std::string);
int Integer(std::string);
double Double(std::string);
bool Boolean(std::string);
//shorthand
std::string& operator[](std::string s) {
return String(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:
std::map<std::string, std::string> table;
};
#endif
+42
View File
@@ -0,0 +1,42 @@
/* 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 SIMPLERNG_HPP_
#define SIMPLERNG_HPP_
//a simple, stateless, random number generator
class SimpleRNG {
public:
SimpleRNG() { SetSeed(8891.0); }
SimpleRNG(double x) { SetSeed(x); }
double SetSeed(double s) { return seed = s; }
double GetSeed() { return seed; }
double operator()(double x) {
return (x + seed) * 11235.0 + 81321.0;
};
private:
double seed;
};
#endif
-4
View File
@@ -32,10 +32,6 @@ 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(
-2
View File
@@ -25,8 +25,6 @@
#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++
-2
View File
@@ -43,8 +43,6 @@ public:
} }
void Normalize() { void Normalize() {
double l = Length(); double l = Length();
if (l == 0)
throw(std::domain_error("Divide by zero"));
x /= l; x /= l;
y /= l; y /= l;
} }
+29
View File
@@ -0,0 +1,29 @@
#configuration of the programs
#server specific settings
server.host = 255.255.255.255
server.port = 21795
server.name = local
server.dbname = database.db
#client specific settings
client.screen.f = false
client.username = Kayne Ruse
client.handle = Ratstail91
client.avatar = elliot2.bmp
#directories
dir.fonts = rsc/graphics/fonts/
dir.logos = rsc/graphics/logos/
dir.sprites = rsc/graphics/sprites/
dir.tilesets = rsc/graphics/tilesets/
dir.interface = rsc/graphics/interface/
dir.scripts = rsc/scripts/
dir.maps = rsc/maps/
#map system
map.savename = servermap
#debugging
+27 -30
View File
@@ -1,45 +1,42 @@
print("Lua script check") print("Lua script check (./rsc)")
--uber lazy declarations --uber lazy declarations
function math.sqr(x) return x*x end function square(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 distance(x, y, i, j) return math.sqrt(square(x - i) + square(y - j)) end
--objects to work on --tile macros, mapped to the tilesheet
--TODO: sheet is not accessable in the server
local sheet = TileSheet.GetTileSheet()
local pager = RegionPager.GetRegionPager()
--the selected tilesheet
TileSheet.Load(sheet, config.dir.tilesets .. "terrain.bmp", 32, 32)
--tile macros, mapped to this tilesheet
local base = 14 local base = 14
local shift = 36 local shift = 36
tiles = { plains = base + shift * 0
plains = base + shift * 0, grass = base + shift * 1
grass = base + shift * 1, dirt = base + shift * 2
dirt = base + shift * 2, sand = base + shift * 3
sand = base + shift * 3, water = base + shift * 4
water = base + shift * 4
}
--TODO: could set custom generation systems here, that differ from the global generators, etc. --Overwrite the original OnCreate with my own version
--TODO: I need a way to allow for different generation algorithms for different pager objects Region.hcOnCreate = Region.OnCreate
--TODO: This design requires only one pager, but this is not good. Region.OnCreate = function(region)
function Region.Create(region) local ret = Region.hcOnCreate(region) --best practices
for i = 1, Region.GetWidth() do for i = 1, Region.GetWidth() do
for j = 1, Region.GetHeight() do for j = 1, Region.GetHeight() do
local dist = math.dist(0, 0, i + Region.GetX(region) -1, j + Region.GetY(region) -1) if distance(0, 0, i + Region.GetX(region) -1, j + Region.GetY(region) -1) > 10 then
if dist < 10 then Region.SetTile(region, i, j, 1, water)
Region.SetTile(region, i, j, 1, tiles.plains)
elseif dist < 12 then
Region.SetTile(region, i, j, 1, tiles.sand)
else else
Region.SetTile(region, i, j, 1, tiles.water) Region.SetTile(region, i, j, 1, plains)
Region.SetSolid(region, i, j, true)
end end
end end
end end
return ret
end end
--Get some regions
newRoom = RoomMgr.CreateRoom("overworld")
pager = Room.GetPager(newRoom)
regionTable = {
RegionPager.GetRegion(pager, 0, 0),
RegionPager.GetRegion(pager, 0, -20),
RegionPager.GetRegion(pager, -20, 0),
RegionPager.GetRegion(pager, -20, -20)
}
print("Finished the lua script") print("Finished the lua script")
-60
View File
@@ -1,60 +0,0 @@
--[[
--reroute the program while in development
config = {debug = true}
dofile("../rsc/setup.lua")
--]]
--catch the debug signal if the program was rerouted
local debug = false
if config ~= nil then
debug = config.debug
end
--the program's configuration
config = {
--common stuff
debug = debug,
dir = {
fonts = "rsc/graphics/fonts/",
logos = "rsc/graphics/logos/",
sprites = "rsc/graphics/sprites/",
tilesets = "rsc/graphics/tilesets/",
interface = "rsc/graphics/interface/",
scripts = "rsc/scripts/",
maps = "rsc/maps/"
},
--client specific stuff
client = {
screen = {
width = 800,
height = 600,
fullscreen = false
},
username = "Kayne",
handle = "Ratstail91",
avatar = "elliot2.bmp",
--NOTE: these generally go here
-- clientIndex
-- accountIndex
-- characterIndex
},
--server specific stuff
server = {
mapname = "mapsave",
host = "255.255.255.255",
port = 21795,
name = "local",
dbname = "database.db"
}
}
--development environment
if config.debug then
for k, v in pairs(config.dir) do
config.dir[k] = string.format("../%s", v)
end
end
-1
View File
@@ -26,7 +26,6 @@
struct ClientData { struct ClientData {
IPaddress address = {0,0}; IPaddress address = {0,0};
//TODO: ping system?
}; };
#endif #endif
+1 -1
View File
@@ -1,5 +1,5 @@
#config #config
INCLUDES+=. ../../common/gameplay ../../common/utilities ../characters ../enemies INCLUDES+=. ../../common/gameplay ../../common/utilities
LIBS+= LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
+34
View File
@@ -0,0 +1,34 @@
/* 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 "enemy_factory_generic.hpp"
EnemyFactoryGeneric::EnemyFactoryGeneric() : EnemyFactoryInterface() {
//EMPTY
}
EnemyFactoryGeneric::~EnemyFactoryGeneric() noexcept {
//EMPTY
}
void EnemyFactoryGeneric::Generate(std::list<EnemyData>* container) {
//TODO: fill this out
}
+42
View File
@@ -0,0 +1,42 @@
/* 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 ENEMYFACTORYGENERIC_HPP_
#define ENEMYFACTORYGENERIC_HPP_
#include "enemy_factory_interface.hpp"
#include "enemy_data.hpp"
#include <list>
//DOCS: Not really intended for use, but rather for copying and tweaking
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
@@ -0,0 +1,49 @@
/* 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 ENEMYFACTORYINTERFACE_HPP_
#define ENEMYFACTORYINTERFACE_HPP_
#include "enemy_data.hpp"
#include "map_type.hpp"
#include <list>
//NOTE: Based on biome, world difficulty, etc.
class EnemyFactoryInterface {
public:
EnemyFactoryInterface() = default;
virtual ~EnemyFactoryInterface() = default;
virtual void Generate(std::list<EnemyData>* container) = 0;
//control the difficulty of the room
MapType SetType(MapType t) { return type = t; }
MapType GetType() { return type; }
int SetDifficulty(int d) { return difficulty = d; }
int GetDifficulty() { return difficulty; }
protected:
MapType type;
int difficulty = 0;
};
#endif
+2
View File
@@ -40,6 +40,7 @@
#include "region_pager_api.hpp" #include "region_pager_api.hpp"
#include "room_api.hpp" #include "room_api.hpp"
#include "room_mgr_api.hpp" #include "room_mgr_api.hpp"
#include "generator_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[] = {
@@ -60,6 +61,7 @@ static const luaL_Reg loadedlibs[] = {
{TORTUGA_REGION_PAGER_NAME, openRegionPagerAPI}, {TORTUGA_REGION_PAGER_NAME, openRegionPagerAPI},
{TORTUGA_ROOM_NAME, openRoomAPI}, {TORTUGA_ROOM_NAME, openRoomAPI},
{TORTUGA_ROOM_MGR_NAME, openRoomMgrAPI}, {TORTUGA_ROOM_MGR_NAME, openRoomMgrAPI},
{TORTUGA_GENRATOR_NAME, openGeneratorAPI},
{NULL, NULL} {NULL, NULL}
}; };
+5 -1
View File
@@ -21,12 +21,15 @@
*/ */
#include "server_application.hpp" #include "server_application.hpp"
#include "SDL/SDL.h"
#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 server" << endl;
try { try {
ServerApplication app; ServerApplication app;
app.Init(argc, argv); app.Init(argc, argv);
@@ -34,8 +37,9 @@ int main(int argc, char** argv) {
app.Quit(); app.Quit();
} }
catch(exception& e) { catch(exception& e) {
cerr << "Fatal exception thrown: " << e.what() << endl; cerr << "Fatal error: " << e.what() << endl;
return 1; return 1;
} }
cout << "Clean exit" << endl;
return 0; return 0;
} }
+2 -1
View File
@@ -1,5 +1,5 @@
#config #config
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 INCLUDES+=. accounts characters combat enemies mapgen mapgen/generators rooms ../common/gameplay ../common/map ../common/network ../common/network/packet ../common/network/serial ../common/utilities
LIBS+=server.a ../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))
@@ -20,6 +20,7 @@ all: $(OBJ) $(OUT)
$(MAKE) -C characters $(MAKE) -C characters
$(MAKE) -C combat $(MAKE) -C combat
$(MAKE) -C enemies $(MAKE) -C enemies
$(MAKE) -C mapgen
$(MAKE) -C rooms $(MAKE) -C rooms
$(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS) $(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
+44
View File
@@ -0,0 +1,44 @@
/* 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 CHUNKDATA_HPP_
#define CHUNKDATA_HPP_
#include "terrain_type.hpp"
#include <type_traits>
struct ChunkData {
enum class Moddable {
LOCKED, //do not change
HARD, //minor changes
SOFT, //major changes
CLEAR, //untouched
};
TerrainType type;
// int fountainCount;
Moddable mod;
};
static_assert(std::is_pod<ChunkData>::value, "ChunkData is not a POD");
#endif
+79
View File
@@ -0,0 +1,79 @@
/* 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 "generator_api.hpp"
#include "base_generator.hpp"
static int getMapType(lua_State* L) {
BaseGenerator* ptr = reinterpret_cast<BaseGenerator*>(lua_touserdata(L, 1));
switch(ptr->GetMapType()) {
case MapType::NONE:
lua_pushstring(L, "none");
break;
case MapType::OVERWORLD:
lua_pushstring(L, "overworld");
break;
case MapType::RUINS:
lua_pushstring(L, "ruins");
break;
case MapType::TOWERS:
lua_pushstring(L, "towers");
break;
case MapType::FORESTS:
lua_pushstring(L, "forests");
break;
case MapType::CAVES:
lua_pushstring(L, "caves");
break;
}
return 1;
}
static int getChunk(lua_State* L) {
BaseGenerator* ptr = reinterpret_cast<BaseGenerator*>(lua_touserdata(L, 1));
ChunkData* chunk = ptr->GetChunk(lua_tointeger(L, 2), lua_tointeger(L, 3));
lua_pushlightuserdata(L, reinterpret_cast<void*>(chunk));
return 1;
}
static int getMapWidth(lua_State* L) {
lua_pushinteger(L, MAP_WIDTH);
return 1;
}
static int getMapHeight(lua_State* L) {
lua_pushinteger(L, MAP_HEIGHT);
return 1;
}
static const luaL_Reg generatorLib[] = {
{"GetMapType", getMapType},
{"GetChunk", getChunk},
{"GetMapWidth", getMapWidth},
{"GetMapHeight", getMapHeight},
{nullptr, nullptr}
};
LUAMOD_API int openGeneratorAPI(lua_State* L) {
luaL_newlib(L, generatorLib);
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.
*/ */
#ifndef TILESHEETAPI_HPP_ #ifndef GENERATORAPI_HPP_
#define TILESHEETAPI_HPP_ #define GENERATORAPI_HPP_
#include "lua/lua.hpp" #include "lua/lua.hpp"
#define TORTUGA_TILE_SHEET_PSEUDO_INDEX "TileSheetPseudoIndex" #define TORTUGA_GENRATOR_NAME "Generator"
#define TORTUGA_TILE_SHEET_NAME "TileSheet" LUAMOD_API int openGeneratorAPI(lua_State* L);
LUAMOD_API int openTileSheetAPI(lua_State* L);
#endif #endif
@@ -0,0 +1,36 @@
/* 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 "base_generator.hpp"
BaseGenerator::BaseGenerator(MapType t) {
mapType = t;
for (int i = 0; i < MAP_WIDTH; i++) {
for (int j = 0; j < MAP_HEIGHT; j++) {
chunks[i][j].type = TerrainType::NONE;
chunks[i][j].mod = ChunkData::Moddable::CLEAR;
}
}
}
BaseGenerator::~BaseGenerator() {
//
}
@@ -19,36 +19,36 @@
* 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 TIMER_HPP_ #ifndef BASEGENERATOR_HPP_
#define TIMER_HPP_ #define BASEGENERATOR_HPP_
#include <chrono> #include "map_type.hpp"
#include <string> #include "chunk_data.hpp"
#include <ostream>
class Timer { #include "lua/lua.hpp"
constexpr int MAP_WIDTH = 256;
constexpr int MAP_HEIGHT = 256;
class BaseGenerator {
public: public:
typedef std::chrono::high_resolution_clock Clock; virtual ~BaseGenerator();
Timer() = default;
Timer(std::string s) : name(s), start(Clock::now()) {};
~Timer() = default;
inline void Start() { start = Clock::now(); }
inline void Stop() { time = Clock::now() - start; }
//accessors and mutators //accessors and mutators
Clock::duration GetTime() { return time; } virtual ChunkData* GetChunk(int x, int y) { return &chunks[x][y]; }
std::string SetName(std::string s) { return name = s; } MapType GetMapType() { return mapType; }
std::string GetName() { return name; }
private: lua_State* SetLuaState(lua_State* L) { return luaState = L; }
std::string name; lua_State* GetLuaState() { return luaState; }
Clock::time_point start;
Clock::duration time; protected:
BaseGenerator() = delete;
BaseGenerator(MapType t);
ChunkData chunks[MAP_WIDTH][MAP_HEIGHT];
MapType mapType = MapType::NONE;
lua_State* luaState = nullptr;
}; };
std::ostream& operator<<(std::ostream& os, Timer& t);
#endif #endif
@@ -19,11 +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 "timer.hpp" #include "caves_generator.hpp"
std::ostream& operator<<(std::ostream& os, Timer& t) { CavesGenerator::CavesGenerator() : BaseGenerator(MapType::CAVES) {
os << t.GetName() << ": "; //
os << std::chrono::duration_cast<std::chrono::nanoseconds>(t.GetTime()).count();
os << "ns";
return os;
} }
CavesGenerator::~CavesGenerator() {
//
}
@@ -19,17 +19,18 @@
* 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 CHARACTERDEFINES_HPP_ #ifndef CAVESGENERATOR_HPP_
#define CHARACTERDEFINES_HPP_ #define CAVESGENERATOR_HPP_
#include <cmath> #include "base_generator.hpp"
//the speeds that the characters move class CavesGenerator : public BaseGenerator {
constexpr double CHARACTER_WALKING_SPEED = 140.0; public:
constexpr double CHARACTER_WALKING_MOD = 1.0/sqrt(2.0); CavesGenerator();
~CavesGenerator();
//the bounding boxes for the characters private:
constexpr double CHARACTER_BOUNDS_WIDTH = 32.0; //
constexpr double CHARACTER_BOUNDS_HEIGHT = 32.0; };
#endif #endif
@@ -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.
*/
#include "forests_generator.hpp"
ForestsGenerator::ForestsGenerator() : BaseGenerator(MapType::FORESTS) {
//
}
ForestsGenerator::~ForestsGenerator() {
//
}
@@ -0,0 +1,36 @@
/* 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 FORESTSGENERATOR_HPP_
#define FORESTSGENERATOR_HPP_
#include "base_generator.hpp"
class ForestsGenerator : public BaseGenerator {
public:
ForestsGenerator();
~ForestsGenerator();
private:
//
};
#endif
@@ -1,5 +1,5 @@
#config #config
INCLUDES+=. INCLUDES+=. ..
LIBS+= LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
@@ -11,8 +11,8 @@ OBJDIR=obj
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o)) OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
#output #output
OUTDIR=.. OUTDIR=../..
OUT=$(addprefix $(OUTDIR)/,libcommon.a) OUT=$(addprefix $(OUTDIR)/,server.a)
#targets #targets
all: $(OBJ) $(OUT) all: $(OBJ) $(OUT)
@@ -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.
*/
#include "overworld_generator.hpp"
OverworldGenerator::OverworldGenerator() : BaseGenerator(MapType::OVERWORLD) {
//
}
OverworldGenerator::~OverworldGenerator() {
//
}
@@ -0,0 +1,36 @@
/* 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 OVERWORLDGENERATOR_HPP_
#define OVERWORLDGENERATOR_HPP_
#include "base_generator.hpp"
class OverworldGenerator : public BaseGenerator {
public:
OverworldGenerator();
~OverworldGenerator();
private:
//
};
#endif
@@ -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.
*/
#include "ruins_generator.hpp"
RuinsGenerator::RuinsGenerator() : BaseGenerator(MapType::RUINS) {
//
}
RuinsGenerator::~RuinsGenerator() {
//
}
@@ -0,0 +1,36 @@
/* 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 RUINSGENERATOR_HPP_
#define RUINSGENERATOR_HPP_
#include "base_generator.hpp"
class RuinsGenerator : public BaseGenerator {
public:
RuinsGenerator();
~RuinsGenerator();
private:
//
};
#endif
@@ -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.
*/
#include "towers_generator.hpp"
TowersGenerator::TowersGenerator() : BaseGenerator(MapType::TOWERS) {
//
}
TowersGenerator::~TowersGenerator() {
//
}
@@ -0,0 +1,36 @@
/* 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 TOWERSGENERATOR_HPP_
#define TOWERSGENERATOR_HPP_
#include "base_generator.hpp"
class TowersGenerator : public BaseGenerator {
public:
TowersGenerator();
~TowersGenerator();
private:
//
};
#endif
@@ -1,5 +1,5 @@
#config #config
INCLUDES+=. .. ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/network/packet ../../common/network/serial ../../common/ui ../../common/utilities INCLUDES+=. generators
LIBS+= LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
@@ -12,11 +12,12 @@ OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
#output #output
OUTDIR=.. OUTDIR=..
OUT=$(addprefix $(OUTDIR)/,client.a) OUT=$(addprefix $(OUTDIR)/,server.a)
#targets #targets
all: $(OBJ) $(OUT) all: $(OBJ) $(OUT)
ar -crs $(OUT) $(OBJ) ar -crs $(OUT) $(OBJ)
$(MAKE) -C generators
$(OBJ): | $(OBJDIR) $(OBJ): | $(OBJDIR)
+34
View File
@@ -0,0 +1,34 @@
/* 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 MAPTYPE_HPP_
#define MAPTYPE_HPP_
enum class MapType {
NONE,
OVERWORLD,
RUINS,
TOWERS,
FORESTS,
CAVES,
};
#endif
@@ -19,16 +19,22 @@
* 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 COMBATDEFINES_HPP_ #ifndef TERRAINTYPE_HPP_
#define COMBATDEFINES_HPP_ #define TERRAINTYPE_HPP_
#define COMBAT_MAX_CHARACTERS 16
#define COMBAT_MAX_ENEMIES 16
enum class TerrainType { enum class TerrainType {
//default: something's wrong
NONE = 0, NONE = 0,
GRASSLANDS,
//etc. //standard overworld
PLAINS,
GRASS,
DIRT,
SAND,
WATER,
//not used
LAST,
}; };
#endif #endif
+7
View File
@@ -29,6 +29,12 @@ static int getPager(lua_State* L) {
return 1; return 1;
} }
static int getGenerator(lua_State* L) {
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
lua_pushlightuserdata(L, reinterpret_cast<void*>(room->generator));
return 1;
}
static int onCreate(lua_State* L) { static int onCreate(lua_State* L) {
//TODO: onCreate() //TODO: onCreate()
return 0; return 0;
@@ -43,6 +49,7 @@ static int onUnload(lua_State* L) {
static const luaL_Reg roomLib[] = { static const luaL_Reg roomLib[] = {
{"GetPager",getPager}, {"GetPager",getPager},
{"GetGenerator",getGenerator},
{"OnCreate", onCreate}, {"OnCreate", onCreate},
{"OnUnload", onUnload}, {"OnUnload", onUnload},
{nullptr, nullptr} {nullptr, nullptr}
+3
View File
@@ -23,11 +23,14 @@
#define ROOMDATA_HPP_ #define ROOMDATA_HPP_
//map system //map system
#include "map_type.hpp"
#include "region_pager_lua.hpp" #include "region_pager_lua.hpp"
#include "base_generator.hpp"
struct RoomData { struct RoomData {
//members //members
RegionPagerLua pager; RegionPagerLua pager;
BaseGenerator* generator = nullptr;
//TODO: collision map //TODO: collision map
//TODO: NPCs? //TODO: NPCs?
+27 -3
View File
@@ -21,19 +21,41 @@
*/ */
#include "room_manager.hpp" #include "room_manager.hpp"
//the generator types
#include "overworld_generator.hpp"
#include "ruins_generator.hpp"
#include "towers_generator.hpp"
#include "forests_generator.hpp"
#include "caves_generator.hpp"
#include <stdexcept> #include <stdexcept>
//------------------------- //-------------------------
//public access methods //public access methods
//------------------------- //-------------------------
RoomData* RoomManager::CreateRoom() { RoomData* RoomManager::CreateRoom(MapType mapType) {
//create the room //create the room
RoomData* newRoom = new RoomData(); RoomData* newRoom = new RoomData();
//create the generator, use a lambda because I'm lazy
newRoom->generator = [mapType]() -> BaseGenerator* {
switch(mapType) {
//BUG: Not having a map type results in an overworld generator by default
case MapType::NONE:
case MapType::OVERWORLD: return new OverworldGenerator();
case MapType::RUINS: return new RuinsGenerator();
case MapType::TOWERS: return new TowersGenerator();
case MapType::FORESTS: return new ForestsGenerator();
case MapType::CAVES: return new CavesGenerator();
}
throw(std::runtime_error("Failed to set the room's generator"));
}();
//set the state //set the state
if (luaState) { if (luaState) {
newRoom->pager.SetLuaState(luaState); newRoom->pager.SetLuaState(luaState);
newRoom->generator->SetLuaState(luaState);
} }
//register the room //register the room
@@ -69,13 +91,15 @@ void RoomManager::UnloadRoom(int uid) {
lua_pop(luaState, 1); lua_pop(luaState, 1);
//free the memory //free the memory
delete room->generator;
delete room; delete room;
roomMap.erase(uid); roomMap.erase(uid);
} }
RoomData* RoomManager::GetRoom(int uid) { RoomData* RoomManager::GetRoom(int uid) {
return FindRoom(uid); RoomData* ptr = FindRoom(uid);
//TODO: expand this to auto-create the room if (ptr) return ptr;
return CreateRoom(MapType::NONE);
} }
RoomData* RoomManager::FindRoom(int uid) { RoomData* RoomManager::FindRoom(int uid) {
+1 -1
View File
@@ -36,7 +36,7 @@ public:
~RoomManager() = default; ~RoomManager() = default;
//public access methods //public access methods
RoomData* CreateRoom(); RoomData* CreateRoom(MapType);
void UnloadRoom(int uid); void UnloadRoom(int uid);
RoomData* GetRoom(int uid); RoomData* GetRoom(int uid);
+11 -1
View File
@@ -46,8 +46,18 @@ static int createRoom(lua_State* L) {
lua_gettable(L, LUA_REGISTRYINDEX); lua_gettable(L, LUA_REGISTRYINDEX);
RoomManager* roomMgr = reinterpret_cast<RoomManager*>(lua_touserdata(L, -1)); RoomManager* roomMgr = reinterpret_cast<RoomManager*>(lua_touserdata(L, -1));
//determine the specified room type
MapType mapType = [L]() -> MapType {
if (std::string("overworld") == lua_tostring(L, -2)) return MapType::OVERWORLD;
if (std::string("ruins") == lua_tostring(L, -2)) return MapType::RUINS;
if (std::string("towers") == lua_tostring(L, -2)) return MapType::TOWERS;
if (std::string("forests") == lua_tostring(L, -2)) return MapType::FORESTS;
if (std::string("caves") == lua_tostring(L, -2)) return MapType::CAVES;
return MapType::NONE;
}();
//create the room //create the room
RoomData* newRoom = roomMgr->CreateRoom(); RoomData* newRoom = roomMgr->CreateRoom(mapType);
//return the new room //return the new room
lua_pushlightuserdata(L, newRoom); lua_pushlightuserdata(L, newRoom);
+33 -41
View File
@@ -21,11 +21,8 @@
*/ */
#include "server_application.hpp" #include "server_application.hpp"
//for PACKET_BUFFER_SIZE
#include "serial.hpp"
//utility functions
#include "sql_utility.hpp" #include "sql_utility.hpp"
#include "serial.hpp"
#include "utility.hpp" #include "utility.hpp"
#include <stdexcept> #include <stdexcept>
@@ -38,9 +35,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 " << argv[0] << std::endl; std::cout << "Beginning startup" << std::endl;
//load the prerequisites //initial setup
config.Load("rsc\\config.cfg"); config.Load("rsc\\config.cfg");
//------------------------- //-------------------------
@@ -83,7 +80,9 @@ 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;
@@ -114,22 +113,12 @@ 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;
DEBUG_OUTPUT_VAR(sizeof(Region::type_t)); std::cout << "\tRegion Format: " << REGION_WIDTH << ", " << REGION_HEIGHT << ", " << REGION_DEPTH << std::endl;
DEBUG_OUTPUT_VAR(sizeof(Region)); std::cout << "\tRegion Content Footprint: " << REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t) << std::endl;
DEBUG_OUTPUT_VAR(REGION_WIDTH); std::cout << "\tPACKET_BUFFER_SIZE: " << PACKET_BUFFER_SIZE << std::endl;
DEBUG_OUTPUT_VAR(REGION_HEIGHT); std::cout << "\tMAX_PACKET_SIZE: " << MAX_PACKET_SIZE << std::endl;
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
@@ -152,8 +141,7 @@ void ServerApplication::Proc() {
HandlePacket(packetBuffer); HandlePacket(packetBuffer);
} }
//update the internals //update the internals
//BUG: #30 Update the internals i.e. player positions //TODO: update the internals i.e. player positions
//give the computer a break //give the computer a break
SDL_Delay(10); SDL_Delay(10);
} }
@@ -178,7 +166,7 @@ void ServerApplication::Quit() {
SDLNet_Quit(); SDLNet_Quit();
SDL_Quit(); SDL_Quit();
std::cout << "Clean exit" << std::endl; std::cout << "Shutdown finished" << std::endl;
} }
//------------------------- //-------------------------
@@ -281,16 +269,6 @@ 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(
@@ -318,12 +296,6 @@ 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;
@@ -355,6 +327,12 @@ 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
//------------------------- //-------------------------
@@ -421,7 +399,15 @@ void ServerApplication::HandleCharacterUpdate(CharacterPacket* const argPacket)
return; return;
} }
//accept client-side logic /* TODO: rewrite this design flaw, read more
* 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;
@@ -433,6 +419,12 @@ void ServerApplication::HandleCharacterUpdate(CharacterPacket* const argPacket)
PumpPacket(argPacket); PumpPacket(argPacket);
} }
//-------------------------
//enemy management
//-------------------------
//TODO: enemy management
//------------------------- //-------------------------
//mismanagement //mismanagement
//------------------------- //-------------------------
+12 -2
View File
@@ -22,10 +22,12 @@
#ifndef SERVERAPPLICATION_HPP_ #ifndef SERVERAPPLICATION_HPP_
#define SERVERAPPLICATION_HPP_ #define SERVERAPPLICATION_HPP_
//server specific stuff, mostly managers //server specific stuff
#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
@@ -65,11 +67,17 @@ 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,6 +99,8 @@ private:
//managers //managers
AccountManager accountMgr; AccountManager accountMgr;
CharacterManager characterMgr; CharacterManager characterMgr;
CombatManager combatMgr;
EnemyManager enemyMgr;
RoomManager roomMgr; RoomManager roomMgr;
//misc //misc