Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 07885cca1b | |||
| 956e920b7a | |||
| 908f91d674 | |||
| fd320767c5 | |||
| c830fa0537 | |||
| 10c89970cc | |||
| 0b512305a9 | |||
| 555abf9c95 | |||
| 2b3ea5eb80 | |||
| 66815016ba | |||
| 46f02dcfdd | |||
| 0077d501ac | |||
| ac1098fa86 |
@@ -15,7 +15,6 @@ Out/
|
||||
*.o
|
||||
*.a
|
||||
*.exe
|
||||
*.diff
|
||||
|
||||
#Shell files
|
||||
*.bat
|
||||
|
||||
+11
-2
@@ -26,6 +26,7 @@
|
||||
#include "character_defines.hpp"
|
||||
#include "vector2.hpp"
|
||||
#include "bounding_box.hpp"
|
||||
#include "statistics.hpp"
|
||||
|
||||
//graphics
|
||||
#include "sprite_sheet.hpp"
|
||||
@@ -46,6 +47,9 @@ public:
|
||||
void CorrectSprite();
|
||||
SpriteSheet* GetSprite() { return &sprite; }
|
||||
|
||||
//gameplay
|
||||
Statistics* GetStats() { return &stats; }
|
||||
|
||||
//accessors and mutators
|
||||
|
||||
//metadata
|
||||
@@ -61,13 +65,18 @@ public:
|
||||
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; }
|
||||
BoundingBox SetBounds(BoundingBox b) { return bounds = b; }
|
||||
BoundingBox GetBounds() { return bounds; }
|
||||
|
||||
private:
|
||||
//graphics
|
||||
SpriteSheet sprite;
|
||||
|
||||
//base statistics
|
||||
Statistics stats;
|
||||
|
||||
//TODO: gameplay components: equipment, items, buffs, debuffs
|
||||
|
||||
//metadata
|
||||
int owner;
|
||||
std::string handle;
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "client_application.hpp"
|
||||
|
||||
#include "serial.hpp"
|
||||
#include "config_utility.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <chrono>
|
||||
@@ -47,6 +48,10 @@
|
||||
void ClientApplication::Init(int argc, char** argv) {
|
||||
std::cout << "Beginning " << argv[0] << std::endl;
|
||||
|
||||
//load the prerequisites
|
||||
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||
config.Load("rsc\\config.cfg");
|
||||
|
||||
//-------------------------
|
||||
//Initialize the APIs
|
||||
//-------------------------
|
||||
@@ -64,80 +69,42 @@ void ClientApplication::Init(int argc, char** argv) {
|
||||
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 = 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;
|
||||
|
||||
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);
|
||||
BaseScene::SetScreen(w ? w : 800, h ? h : 600, 0, f);
|
||||
std::cout << "Initialized the screen" << std::endl;
|
||||
|
||||
//-------------------------
|
||||
//debug output
|
||||
//-------------------------
|
||||
|
||||
lua_getfield(lua, -1, "debug");
|
||||
|
||||
if (lua_toboolean(lua, -1)) {
|
||||
//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;
|
||||
|
||||
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);
|
||||
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;
|
||||
|
||||
//-------------------------
|
||||
@@ -171,7 +138,7 @@ void ClientApplication::Proc() {
|
||||
//simulate game time
|
||||
while (simTime < realTime) {
|
||||
//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;
|
||||
}
|
||||
|
||||
@@ -184,7 +151,6 @@ void ClientApplication::Proc() {
|
||||
|
||||
void ClientApplication::Quit() {
|
||||
std::cout << "Shutting down" << std::endl;
|
||||
lua_close(lua);
|
||||
network.Close();
|
||||
SDLNet_Quit();
|
||||
SDL_Quit();
|
||||
@@ -201,25 +167,25 @@ void ClientApplication::LoadScene(SceneList sceneIndex) {
|
||||
//add scene creation calls here
|
||||
case SceneList::FIRST:
|
||||
case SceneList::SPLASHSCREEN:
|
||||
activeScene = new SplashScreen(lua);
|
||||
activeScene = new SplashScreen();
|
||||
break;
|
||||
case SceneList::MAINMENU:
|
||||
activeScene = new MainMenu(lua);
|
||||
activeScene = new MainMenu();
|
||||
break;
|
||||
case SceneList::OPTIONSMENU:
|
||||
activeScene = new OptionsMenu(lua);
|
||||
activeScene = new OptionsMenu();
|
||||
break;
|
||||
case SceneList::LOBBYMENU:
|
||||
activeScene = new LobbyMenu(lua, network, characterMap);
|
||||
activeScene = new LobbyMenu(&network, &clientIndex, &accountIndex);
|
||||
break;
|
||||
case SceneList::INWORLD:
|
||||
activeScene = new InWorld(lua, network, characterMap);
|
||||
activeScene = new InWorld(&network, &clientIndex, &accountIndex, &characterIndex, &characterMap);
|
||||
break;
|
||||
case SceneList::INCOMBAT:
|
||||
activeScene = new InCombat(lua, network, characterMap);
|
||||
activeScene = new InCombat(&network, &clientIndex, &accountIndex, &characterIndex, &characterMap);
|
||||
break;
|
||||
case SceneList::CLEANUP:
|
||||
activeScene = new CleanUp(lua, network, characterMap);
|
||||
activeScene = new CleanUp(&network, &clientIndex, &accountIndex, &characterIndex, &characterMap);
|
||||
break;
|
||||
default:
|
||||
throw(std::logic_error("Failed to recognize the scene index"));
|
||||
|
||||
@@ -28,20 +28,23 @@
|
||||
#include "udp_network_utility.hpp"
|
||||
#include "character.hpp"
|
||||
|
||||
#include "lua/lua.hpp"
|
||||
#include "singleton.hpp"
|
||||
|
||||
#include <map>
|
||||
|
||||
class ClientApplication {
|
||||
class ClientApplication: public Singleton<ClientApplication> {
|
||||
public:
|
||||
ClientApplication() = default;
|
||||
~ClientApplication() = default;
|
||||
|
||||
//public methods
|
||||
void Init(int argc, char** argv);
|
||||
void Proc();
|
||||
void Quit();
|
||||
|
||||
private:
|
||||
friend Singleton<ClientApplication>;
|
||||
|
||||
ClientApplication() = default;
|
||||
~ClientApplication() = default;
|
||||
|
||||
//Private access members
|
||||
void LoadScene(SceneList sceneIndex);
|
||||
void UnloadScene();
|
||||
@@ -49,7 +52,6 @@ private:
|
||||
BaseScene* activeScene = nullptr;
|
||||
|
||||
//shared parameters
|
||||
lua_State* lua = nullptr;
|
||||
UDPNetworkUtility network;
|
||||
int clientIndex = -1;
|
||||
int accountIndex = -1;
|
||||
|
||||
@@ -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
|
||||
}
|
||||
+13
-1
@@ -21,6 +21,9 @@
|
||||
*/
|
||||
#include "client_application.hpp"
|
||||
|
||||
//singletons
|
||||
#include "config_utility.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
|
||||
@@ -28,10 +31,19 @@ using namespace std;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
try {
|
||||
ClientApplication app;
|
||||
//create the singletons
|
||||
ClientApplication::Create();
|
||||
ConfigUtility::Create();
|
||||
|
||||
//call the server's routines
|
||||
ClientApplication& app = ClientApplication::GetSingleton();
|
||||
app.Init(argc, argv);
|
||||
app.Proc();
|
||||
app.Quit();
|
||||
|
||||
//delete the singletons
|
||||
ConfigUtility::Delete();
|
||||
ClientApplication::Delete();
|
||||
}
|
||||
catch(exception& e) {
|
||||
cerr << "Fatal exception thrown: " << e.what() << endl;
|
||||
|
||||
+23
-36
@@ -22,6 +22,7 @@
|
||||
#include "clean_up.hpp"
|
||||
|
||||
#include "channels.hpp"
|
||||
#include "config_utility.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
@@ -29,43 +30,25 @@
|
||||
//Public access members
|
||||
//-------------------------
|
||||
|
||||
CleanUp::CleanUp(lua_State* L, UDPNetworkUtility& aNetwork, CharacterMap& aCharacterMap):
|
||||
lua(L),
|
||||
network(aNetwork),
|
||||
characterMap(aCharacterMap)
|
||||
CleanUp::CleanUp(
|
||||
UDPNetworkUtility* const argNetwork,
|
||||
int* const argClientIndex,
|
||||
int* const argAccountIndex,
|
||||
int* const argCharacterIndex,
|
||||
CharacterMap* argCharacterMap
|
||||
):
|
||||
network(*argNetwork),
|
||||
clientIndex(*argClientIndex),
|
||||
accountIndex(*argAccountIndex),
|
||||
characterIndex(*argCharacterIndex),
|
||||
characterMap(*argCharacterMap)
|
||||
{
|
||||
//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);
|
||||
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||
|
||||
//setup the utility objects
|
||||
image.LoadSurface(interfaceDir + "button_menu.bmp");
|
||||
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
||||
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
|
||||
backButton.SetImage(&image);
|
||||
@@ -80,7 +63,12 @@ CleanUp::CleanUp(lua_State* L, UDPNetworkUtility& aNetwork, CharacterMap& aChara
|
||||
|
||||
//full reset
|
||||
network.Unbind(Channels::SERVER);
|
||||
clientIndex = -1;
|
||||
accountIndex = -1;
|
||||
characterIndex = -1;
|
||||
// combatMap.clear();
|
||||
characterMap.clear();
|
||||
// enemyMap.clear();
|
||||
|
||||
//auto return
|
||||
startTick = std::chrono::steady_clock::now();
|
||||
@@ -96,7 +84,7 @@ CleanUp::~CleanUp() {
|
||||
|
||||
void CleanUp::Update(double delta) {
|
||||
if (std::chrono::steady_clock::now() - startTick > std::chrono::duration<int>(10)) {
|
||||
SetNextScene(SceneList::MAINMENU);
|
||||
QuitEvent();
|
||||
}
|
||||
|
||||
//BUGFIX: Eat incoming packets
|
||||
@@ -132,8 +120,7 @@ void CleanUp::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
||||
}
|
||||
|
||||
void CleanUp::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||
if (backButton.MouseButtonUp(button) == Button::State::HOVER &&
|
||||
button.button & SDL_BUTTON_LMASK) {
|
||||
if (backButton.MouseButtonUp(button) == Button::State::HOVER) {
|
||||
SetNextScene(SceneList::MAINMENU);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,18 +25,18 @@
|
||||
//network
|
||||
#include "udp_network_utility.hpp"
|
||||
|
||||
//graphics & ui
|
||||
//graphics
|
||||
#include "image.hpp"
|
||||
#include "raster_font.hpp"
|
||||
#include "button.hpp"
|
||||
|
||||
//common
|
||||
#include "frame_rate.hpp"
|
||||
|
||||
#include "character.hpp"
|
||||
|
||||
//client
|
||||
#include "base_scene.hpp"
|
||||
#include "character.hpp"
|
||||
|
||||
//APIs
|
||||
#include "lua/lua.hpp"
|
||||
|
||||
//std namespace
|
||||
#include <chrono>
|
||||
@@ -44,7 +44,13 @@
|
||||
class CleanUp : public BaseScene {
|
||||
public:
|
||||
//Public access members
|
||||
CleanUp(lua_State*, UDPNetworkUtility&, CharacterMap&);
|
||||
CleanUp(
|
||||
UDPNetworkUtility* const argNetwork,
|
||||
int* const argClientIndex,
|
||||
int* const argAccountIndex,
|
||||
int* const argCharacterIndex,
|
||||
CharacterMap* argCharacterMap
|
||||
);
|
||||
~CleanUp();
|
||||
|
||||
protected:
|
||||
@@ -62,13 +68,17 @@ protected:
|
||||
void KeyUp(SDL_KeyboardEvent const&);
|
||||
|
||||
//shared parameters
|
||||
lua_State* lua = nullptr;
|
||||
UDPNetworkUtility& network;
|
||||
int& clientIndex;
|
||||
int& accountIndex;
|
||||
int& characterIndex;
|
||||
CharacterMap& characterMap;
|
||||
|
||||
//graphics & ui
|
||||
//graphics
|
||||
Image image;
|
||||
RasterFont font;
|
||||
|
||||
//UI
|
||||
Button backButton;
|
||||
FrameRate fps;
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include "channels.hpp"
|
||||
#include "utility.hpp"
|
||||
#include "config_utility.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
@@ -31,14 +32,12 @@
|
||||
//-------------------------
|
||||
|
||||
InCombat::InCombat(
|
||||
ConfigUtility* const argConfig,
|
||||
UDPNetworkUtility* const argNetwork,
|
||||
int* const argClientIndex,
|
||||
int* const argAccountIndex,
|
||||
int* const argCharacterIndex,
|
||||
CharacterMap* argCharacterMap
|
||||
):
|
||||
config(*argConfig),
|
||||
network(*argNetwork),
|
||||
clientIndex(*argClientIndex),
|
||||
accountIndex(*argAccountIndex),
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#include "button.hpp"
|
||||
|
||||
//common
|
||||
#include "config_utility.hpp"
|
||||
#include "frame_rate.hpp"
|
||||
|
||||
#include "character.hpp"
|
||||
@@ -43,7 +42,6 @@ class InCombat : public BaseScene {
|
||||
public:
|
||||
//Public access members
|
||||
InCombat(
|
||||
ConfigUtility* const argConfig,
|
||||
UDPNetworkUtility* const argNetwork,
|
||||
int* const argClientIndex,
|
||||
int* const argAccountIndex,
|
||||
@@ -79,7 +77,6 @@ protected:
|
||||
void RequestShutdown();
|
||||
|
||||
//shared parameters
|
||||
ConfigUtility& config;
|
||||
UDPNetworkUtility& network;
|
||||
int& clientIndex;
|
||||
int& accountIndex;
|
||||
|
||||
+27
-81
@@ -23,6 +23,7 @@
|
||||
|
||||
#include "channels.hpp"
|
||||
#include "utility.hpp"
|
||||
#include "config_utility.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <algorithm>
|
||||
@@ -34,74 +35,20 @@
|
||||
//-------------------------
|
||||
|
||||
InWorld::InWorld(
|
||||
ConfigUtility* const argConfig,
|
||||
UDPNetworkUtility* const argNetwork,
|
||||
int* const argClientIndex,
|
||||
int* const argAccountIndex,
|
||||
int* const argCharacterIndex,
|
||||
CharacterMap* argCharacterMap
|
||||
):
|
||||
config(*argConfig),
|
||||
network(*argNetwork),
|
||||
clientIndex(*argClientIndex),
|
||||
accountIndex(*argAccountIndex),
|
||||
characterIndex(*argCharacterIndex),
|
||||
characterMap(*argCharacterMap)
|
||||
{
|
||||
//register the pager
|
||||
lua_pushstring(lua, TORTUGA_REGION_PAGER_PSEUDO_INDEX);
|
||||
lua_pushlightuserdata(lua, &pager);
|
||||
lua_settable(L, LUA_REGISTRYINDEX);
|
||||
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||
|
||||
//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
|
||||
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
||||
buttonImage.SetClipH(buttonImage.GetClipH()/3);
|
||||
@@ -125,7 +72,8 @@ InWorld::InWorld(
|
||||
|
||||
//load the tilesheet
|
||||
//TODO: add the tilesheet to the map system?
|
||||
tileSheet.Load(config["dir.tilesets"] + "terrain.bmp", 12, 15);
|
||||
//TODO: Tile size and tile sheet should be loaded elsewhere
|
||||
tileSheet.Load(config["dir.tilesets"] + "terrain.bmp", 32, 32);
|
||||
|
||||
//request a sync
|
||||
RequestSynchronize();
|
||||
@@ -135,13 +83,7 @@ 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,38 +107,41 @@ void InWorld::Update(double delta) {
|
||||
it.second.Update(delta);
|
||||
}
|
||||
|
||||
//TODO: Check collisions here
|
||||
//check the map
|
||||
UpdateMap();
|
||||
|
||||
//skip the rest
|
||||
if (!localCharacter) {
|
||||
return;
|
||||
}
|
||||
|
||||
//check for collisions with the map
|
||||
BoundingBox wallBounds = {0, 0, tileSheet.GetTileW(), tileSheet.GetTileH()};
|
||||
const int xCount = character.GetBoundingBox().w / wallBounds.w + 1;
|
||||
const int yCount = character.GetBoundingBox().h / wallBounds.h + 1;
|
||||
const int xCount = localCharacter->GetBounds().w / wallBounds.w + 1;
|
||||
const int yCount = localCharacter->GetBounds().h / wallBounds.h + 1;
|
||||
|
||||
for (int i = -1; i <= xCount; ++i) {
|
||||
for (int j = -1; j <= yCount; ++j) {
|
||||
//set the wall's position
|
||||
wallBounds.x = wallBounds.w * i + snapToBase((double)wallBounds.w, character.GetOrigin().x);
|
||||
wallBounds.y = wallBounds.h * j + snapToBase((double)wallBounds.h, character.GetOrigin().y);
|
||||
wallBounds.x = wallBounds.w * i + snapToBase((double)wallBounds.w, localCharacter->GetOrigin().x);
|
||||
wallBounds.y = wallBounds.h * j + snapToBase((double)wallBounds.h, localCharacter->GetOrigin().y);
|
||||
|
||||
if (!pager.GetSolid(wallBounds.x / wallBounds.w, wallBounds.y / wallBounds.h)) {
|
||||
if (!regionPager.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();
|
||||
if ((localCharacter->GetOrigin() + localCharacter->GetBounds()).CheckOverlap(wallBounds)) {
|
||||
localCharacter->SetOrigin(localCharacter->GetOrigin() - (localCharacter->GetMotion() * delta));
|
||||
localCharacter->SetMotion({0,0});
|
||||
localCharacter->CorrectSprite();
|
||||
SendPlayerUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//update the camera
|
||||
if(localCharacter) {
|
||||
camera.x = localCharacter->GetOrigin().x - camera.marginX;
|
||||
camera.y = localCharacter->GetOrigin().y - camera.marginY;
|
||||
}
|
||||
|
||||
//check the map
|
||||
UpdateMap();
|
||||
camera.x = localCharacter->GetOrigin().x - camera.marginX;
|
||||
camera.y = localCharacter->GetOrigin().y - camera.marginY;
|
||||
}
|
||||
|
||||
void InWorld::FrameEnd() {
|
||||
@@ -358,10 +303,11 @@ void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) {
|
||||
newCharacter.SetHandle(argPacket->handle);
|
||||
newCharacter.SetAvatar(argPacket->avatar);
|
||||
|
||||
newCharacter.GetSprite()->LoadSurface(config["dir.sprites"] + newCharacter.GetAvatar(), 4, 4);
|
||||
newCharacter.GetSprite()->LoadSurface(ConfigUtility::GetSingleton()["dir.sprites"] + newCharacter.GetAvatar(), 4, 4);
|
||||
|
||||
newCharacter.SetOrigin(argPacket->origin);
|
||||
newCharacter.SetMotion(argPacket->motion);
|
||||
newCharacter.SetBounds({0, 16, 32, 32}); //TODO: magic numbers, fix this
|
||||
|
||||
(*newCharacter.GetStats()) = argPacket->stats;
|
||||
|
||||
|
||||
+11
-18
@@ -22,28 +22,25 @@
|
||||
#ifndef INWORLD_HPP_
|
||||
#define INWORLD_HPP_
|
||||
|
||||
//map stuff
|
||||
#include "tile_sheet.hpp"
|
||||
#include "region_pager_lua.hpp"
|
||||
//maps
|
||||
#include "region_pager_base.hpp"
|
||||
|
||||
//networking
|
||||
#include "udp_network_utility.hpp"
|
||||
|
||||
//graphics & ui
|
||||
//graphics
|
||||
#include "image.hpp"
|
||||
#include "raster_font.hpp"
|
||||
#include "button.hpp"
|
||||
#include "tile_sheet.hpp"
|
||||
|
||||
//utilities
|
||||
//common
|
||||
#include "frame_rate.hpp"
|
||||
#include "timer.hpp"
|
||||
|
||||
#include "character.hpp"
|
||||
|
||||
//client
|
||||
#include "base_scene.hpp"
|
||||
#include "character.hpp"
|
||||
|
||||
//APIs
|
||||
#include "lua/lua.hpp"
|
||||
|
||||
//STL
|
||||
#include <map>
|
||||
@@ -52,7 +49,6 @@ class InWorld : public BaseScene {
|
||||
public:
|
||||
//Public access members
|
||||
InWorld(
|
||||
ConfigUtility* const argConfig,
|
||||
UDPNetworkUtility* const argNetwork,
|
||||
int* const argClientIndex,
|
||||
int* const argAccountIndex,
|
||||
@@ -95,9 +91,7 @@ protected:
|
||||
//utilities
|
||||
void UpdateMap();
|
||||
|
||||
//TODO: Streamline this with lua
|
||||
//shared parameters
|
||||
ConfigUtility& config;
|
||||
UDPNetworkUtility& network;
|
||||
int& clientIndex;
|
||||
int& accountIndex;
|
||||
@@ -117,11 +111,10 @@ protected:
|
||||
Button shutDownButton;
|
||||
//TODO: Review the camera
|
||||
struct {
|
||||
struct {
|
||||
int x, y;
|
||||
}origin, margin;
|
||||
}camera;
|
||||
|
||||
int x = 0, y = 0;
|
||||
int width = 0, height = 0;
|
||||
int marginX = 0, marginY = 0;
|
||||
} camera;
|
||||
FrameRate fps;
|
||||
|
||||
//game
|
||||
|
||||
@@ -30,25 +30,19 @@
|
||||
//Public access members
|
||||
//-------------------------
|
||||
|
||||
LobbyMenu::LobbyMenu(lua_State* L, UDPNetworkUtility& aNetwork):
|
||||
lua(L),
|
||||
network(aNetwork)
|
||||
LobbyMenu::LobbyMenu(
|
||||
UDPNetworkUtility* const argNetwork,
|
||||
int* const argClientIndex,
|
||||
int* const argAccountIndex
|
||||
):
|
||||
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
|
||||
image.LoadSurface(interfaceDir + "button_menu.bmp");
|
||||
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
||||
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
|
||||
search.SetImage(&image);
|
||||
@@ -92,11 +86,11 @@ void LobbyMenu::FrameStart() {
|
||||
|
||||
void LobbyMenu::Update(double delta) {
|
||||
//suck in and process all waiting packets
|
||||
SerialPacket* packetBuffer = new SerialPacket();
|
||||
SerialPacket* packetBuffer = static_cast<SerialPacket*>(malloc(MAX_PACKET_SIZE));
|
||||
while(network.Receive(packetBuffer)) {
|
||||
HandlePacket(packetBuffer);
|
||||
}
|
||||
delete packetBuffer;
|
||||
free(static_cast<void*>(packetBuffer));
|
||||
}
|
||||
|
||||
void LobbyMenu::FrameEnd() {
|
||||
@@ -152,44 +146,26 @@ void LobbyMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
||||
}
|
||||
|
||||
void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||
//prep
|
||||
lua_getglobal(lua, "config");
|
||||
|
||||
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
|
||||
SerialPacket packet;
|
||||
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
|
||||
serverInfo.clear();
|
||||
selection = nullptr;
|
||||
|
||||
//clear the parameters
|
||||
lua_pop(lua, 3);
|
||||
}
|
||||
|
||||
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
|
||||
ClientPacket packet;
|
||||
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
|
||||
network.SendTo(&selection->address, &packet);
|
||||
selection = nullptr;
|
||||
|
||||
//clear the parameters
|
||||
lua_pop(lua, 2);
|
||||
}
|
||||
|
||||
else if (back.MouseButtonUp(button) == Button::State::HOVER) {
|
||||
@@ -209,9 +185,6 @@ void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||
else {
|
||||
selection = nullptr;
|
||||
}
|
||||
|
||||
//clear the parameters
|
||||
lua_pop(lua, 1);
|
||||
}
|
||||
|
||||
void LobbyMenu::KeyDown(SDL_KeyboardEvent const& key) {
|
||||
@@ -229,10 +202,10 @@ void LobbyMenu::KeyUp(SDL_KeyboardEvent const& key) {
|
||||
void LobbyMenu::HandlePacket(SerialPacket* const argPacket) {
|
||||
switch(argPacket->type) {
|
||||
case SerialPacketType::BROADCAST_RESPONSE:
|
||||
HandleBroadcastResponse(dynamic_cast<ServerPacket*>(argPacket));
|
||||
HandleBroadcastResponse(static_cast<ServerPacket*>(argPacket));
|
||||
break;
|
||||
case SerialPacketType::JOIN_RESPONSE:
|
||||
HandleJoinResponse(dynamic_cast<ClientPacket*>(argPacket));
|
||||
HandleJoinResponse(static_cast<ClientPacket*>(argPacket));
|
||||
break;
|
||||
//handle errors
|
||||
default:
|
||||
@@ -257,25 +230,16 @@ void LobbyMenu::HandleBroadcastResponse(ServerPacket* const argPacket) {
|
||||
}
|
||||
|
||||
void LobbyMenu::HandleJoinResponse(ClientPacket* const argPacket) {
|
||||
lua_getglobal(lua, "config");
|
||||
lua_getfield(lua, -1, "client");
|
||||
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");
|
||||
clientIndex = argPacket->clientIndex;
|
||||
accountIndex = argPacket->accountIndex;
|
||||
network.Bind(&argPacket->srcAddress, Channels::SERVER);
|
||||
SetNextScene(SceneList::INWORLD);
|
||||
|
||||
//send this player's character info
|
||||
CharacterPacket newPacket;
|
||||
newPacket.type = SerialPacketType::CHARACTER_NEW;
|
||||
strncpy(newPacket.handle, lua_tostring(lua, -2), PACKET_STRING_SIZE);
|
||||
strncpy(newPacket.avatar, lua_tostring(lua, -1), PACKET_STRING_SIZE);
|
||||
newPacket.accountIndex = argPacket->accountIndex;
|
||||
strncpy(newPacket.handle, config["client.handle"].c_str(), PACKET_STRING_SIZE);
|
||||
strncpy(newPacket.avatar, config["client.avatar"].c_str(), PACKET_STRING_SIZE);
|
||||
newPacket.accountIndex = accountIndex;
|
||||
network.SendTo(Channels::SERVER, &newPacket);
|
||||
|
||||
lua_pop(lua, 4);
|
||||
}
|
||||
@@ -28,21 +28,23 @@
|
||||
#include "button.hpp"
|
||||
|
||||
//utilities
|
||||
#include "config_utility.hpp"
|
||||
#include "udp_network_utility.hpp"
|
||||
|
||||
//client
|
||||
#include "base_scene.hpp"
|
||||
|
||||
//APIs
|
||||
#include "lua/lua.hpp"
|
||||
|
||||
//STL
|
||||
#include <vector>
|
||||
|
||||
class LobbyMenu : public BaseScene {
|
||||
public:
|
||||
//Public access members
|
||||
LobbyMenu(lua_State*, UDPNetworkUtility&);
|
||||
LobbyMenu(
|
||||
UDPNetworkUtility* const argNetwork,
|
||||
int* const argClientIndex,
|
||||
int* const argAccountIndex
|
||||
);
|
||||
~LobbyMenu();
|
||||
|
||||
protected:
|
||||
@@ -65,8 +67,10 @@ protected:
|
||||
void HandleJoinResponse(ClientPacket* const);
|
||||
|
||||
//shared parameters
|
||||
lua_State* lua = nullptr;
|
||||
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||
UDPNetworkUtility& network;
|
||||
int& clientIndex;
|
||||
int& accountIndex;
|
||||
|
||||
//members
|
||||
Image image;
|
||||
@@ -87,7 +91,7 @@ protected:
|
||||
std::vector<ServerInformation> serverInfo;
|
||||
|
||||
//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;
|
||||
ServerInformation* selection = nullptr;
|
||||
};
|
||||
|
||||
@@ -21,26 +21,19 @@
|
||||
*/
|
||||
#include "main_menu.hpp"
|
||||
|
||||
#include "config_utility.hpp"
|
||||
|
||||
//-------------------------
|
||||
//Public access members
|
||||
//-------------------------
|
||||
|
||||
MainMenu::MainMenu(lua_State* L): lua(L) {
|
||||
//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);
|
||||
MainMenu::MainMenu() {
|
||||
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||
|
||||
//setup the utility objects
|
||||
image.LoadSurface(interfaceDir + "button_menu.bmp");
|
||||
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
||||
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
|
||||
startButton.SetImage(&image);
|
||||
@@ -110,14 +103,14 @@ void MainMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
||||
}
|
||||
|
||||
void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||
//TODO: Buttons should only register as "selected" when the left button is used
|
||||
if (startButton.MouseButtonUp(button) == Button::State::HOVER) {
|
||||
SetNextScene(SceneList::INWORLD);
|
||||
SetNextScene(SceneList::LOBBYMENU);
|
||||
}
|
||||
if (optionsButton.MouseButtonUp(button) == Button::State::HOVER) {
|
||||
SetNextScene(SceneList::OPTIONSMENU);
|
||||
}
|
||||
if (quitButton.MouseButtonUp(button) == Button::State::HOVER &&
|
||||
button.button & SDL_BUTTON_LMASK) {
|
||||
if (quitButton.MouseButtonUp(button) == Button::State::HOVER) {
|
||||
QuitEvent();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,12 +28,10 @@
|
||||
#include "raster_font.hpp"
|
||||
#include "button.hpp"
|
||||
|
||||
#include "lua/lua.hpp"
|
||||
|
||||
class MainMenu : public BaseScene {
|
||||
public:
|
||||
//Public access members
|
||||
MainMenu(lua_State* L);
|
||||
MainMenu();
|
||||
~MainMenu();
|
||||
|
||||
protected:
|
||||
@@ -50,9 +48,6 @@ protected:
|
||||
void KeyDown(SDL_KeyboardEvent const&);
|
||||
void KeyUp(SDL_KeyboardEvent const&);
|
||||
|
||||
//shared parameters
|
||||
lua_State* lua = nullptr;
|
||||
|
||||
//members
|
||||
Image image;
|
||||
RasterFont font;
|
||||
|
||||
@@ -21,26 +21,19 @@
|
||||
*/
|
||||
#include "options_menu.hpp"
|
||||
|
||||
#include "config_utility.hpp"
|
||||
|
||||
//-------------------------
|
||||
//Public access members
|
||||
//-------------------------
|
||||
|
||||
OptionsMenu::OptionsMenu(lua_State* L): lua(L) {
|
||||
//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);
|
||||
OptionsMenu::OptionsMenu() {
|
||||
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||
|
||||
//setup the utility objects
|
||||
image.LoadSurface(interfaceDir + "button_menu.bmp");
|
||||
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
||||
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
|
||||
backButton.SetImage(&image);
|
||||
@@ -93,8 +86,7 @@ void OptionsMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
||||
}
|
||||
|
||||
void OptionsMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||
if (backButton.MouseButtonUp(button) == Button::State::HOVER &&
|
||||
button.button & SDL_BUTTON_LMASK) {
|
||||
if (backButton.MouseButtonUp(button) == Button::State::HOVER) {
|
||||
SetNextScene(SceneList::MAINMENU);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,13 +28,11 @@
|
||||
#include "raster_font.hpp"
|
||||
#include "button.hpp"
|
||||
|
||||
#include "lua/lua.hpp"
|
||||
|
||||
//TODO: The options screen needs to be USED
|
||||
class OptionsMenu : public BaseScene {
|
||||
public:
|
||||
//Public access members
|
||||
OptionsMenu(lua_State* L);
|
||||
OptionsMenu();
|
||||
~OptionsMenu();
|
||||
|
||||
protected:
|
||||
@@ -51,9 +49,6 @@ protected:
|
||||
void KeyDown(SDL_KeyboardEvent const&);
|
||||
void KeyUp(SDL_KeyboardEvent const&);
|
||||
|
||||
//shared parameters
|
||||
lua_State* lua = nullptr;
|
||||
|
||||
//members
|
||||
Image image;
|
||||
RasterFont font;
|
||||
|
||||
@@ -21,21 +21,14 @@
|
||||
*/
|
||||
#include "splash_screen.hpp"
|
||||
|
||||
#include <string>
|
||||
#include "config_utility.hpp"
|
||||
|
||||
//-------------------------
|
||||
//Public access members
|
||||
//-------------------------
|
||||
|
||||
SplashScreen::SplashScreen(lua_State* L): lua(L) {
|
||||
//get the config info
|
||||
lua_getglobal(lua, "config");
|
||||
lua_getfield(lua, -1, "dir");
|
||||
lua_getfield(lua, -1, "logos");
|
||||
std::string logos = lua_tostring(lua, -1);
|
||||
lua_pop(lua, 3);
|
||||
|
||||
logo.LoadSurface(logos + "krstudios.bmp");
|
||||
SplashScreen::SplashScreen() {
|
||||
logo.LoadSurface(ConfigUtility::GetSingleton()["dir.logos"] + "krstudios.bmp");
|
||||
startTick = std::chrono::steady_clock::now();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,14 +26,12 @@
|
||||
|
||||
#include "image.hpp"
|
||||
|
||||
#include "lua/lua.hpp"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
class SplashScreen : public BaseScene {
|
||||
public:
|
||||
//Public access members
|
||||
SplashScreen(lua_State* L);
|
||||
SplashScreen();
|
||||
~SplashScreen();
|
||||
|
||||
protected:
|
||||
@@ -41,9 +39,6 @@ protected:
|
||||
void Update(double delta);
|
||||
void Render(SDL_Surface* const);
|
||||
|
||||
//shared parameters
|
||||
lua_State* lua = nullptr;
|
||||
|
||||
//members
|
||||
std::chrono::steady_clock::time_point startTick;
|
||||
Image logo;
|
||||
|
||||
@@ -11,7 +11,7 @@ OBJDIR=obj
|
||||
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||
|
||||
#output
|
||||
OUTDIR=..
|
||||
OUTDIR=../..
|
||||
OUT=$(addprefix $(OUTDIR)/,libcommon.a)
|
||||
|
||||
#targets
|
||||
|
||||
@@ -21,9 +21,25 @@
|
||||
*/
|
||||
#include "timer.hpp"
|
||||
|
||||
Timer::Timer(): start(Timer::Clock::now()) {
|
||||
//
|
||||
}
|
||||
|
||||
Timer::Timer(std::string s): name(s), start(Timer::Clock::now()) {
|
||||
//
|
||||
}
|
||||
|
||||
void Timer::Start() {
|
||||
start = Clock::now();
|
||||
}
|
||||
|
||||
void Timer::Stop() {
|
||||
timeSpan = Clock::now() - start;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, Timer& t) {
|
||||
os << t.GetName() << ": ";
|
||||
os << std::chrono::duration_cast<std::chrono::nanoseconds>(t.GetTime()).count();
|
||||
os << "ns";
|
||||
os << std::chrono::duration_cast<std::chrono::milliseconds>(t.GetTime()).count();
|
||||
os << "ms";
|
||||
return os;
|
||||
}
|
||||
|
||||
@@ -30,15 +30,15 @@ class Timer {
|
||||
public:
|
||||
typedef std::chrono::high_resolution_clock Clock;
|
||||
|
||||
Timer() = default;
|
||||
Timer(std::string s) : name(s), start(Clock::now()) {};
|
||||
Timer();
|
||||
Timer(std::string s);
|
||||
~Timer() = default;
|
||||
|
||||
inline void Start() { start = Clock::now(); }
|
||||
inline void Stop() { time = Clock::now() - start; }
|
||||
inline void Start();
|
||||
inline void Stop();
|
||||
|
||||
//accessors and mutators
|
||||
Clock::duration GetTime() { return time; }
|
||||
Clock::duration GetTime() { return timeSpan; }
|
||||
|
||||
std::string SetName(std::string s) { return name = s; }
|
||||
std::string GetName() { return name; }
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
private:
|
||||
std::string name;
|
||||
Clock::time_point start;
|
||||
Clock::duration time;
|
||||
Clock::duration timeSpan;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, Timer& t);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#config
|
||||
INCLUDES+=. ../map
|
||||
INCLUDES+=.
|
||||
LIBS+=
|
||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
#config
|
||||
INCLUDES+=. ../utilities ../graphics
|
||||
INCLUDES+=. ../graphics ../utilities
|
||||
LIBS+=
|
||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||
|
||||
|
||||
@@ -26,11 +26,6 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
static int getRegionPager(lua_State* L) {
|
||||
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) {
|
||||
@@ -96,7 +91,6 @@ static int unloadRegion(lua_State* L) {
|
||||
}
|
||||
|
||||
static const luaL_Reg regionPagerLib[] = {
|
||||
{"GetRegionPager", getRegionPager},
|
||||
{"SetTile", setTile},
|
||||
{"GetTile", getTile},
|
||||
{"SetSolid", setSolid},
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
#include "lua/lua.hpp"
|
||||
|
||||
#define TORTUGA_REGION_PAGER_PSEUDO_INDEX "RegionPagerPseudoIndex"
|
||||
#define TORTUGA_REGION_PAGER_NAME "RegionPager"
|
||||
LUAMOD_API int openRegionPagerAPI(lua_State* L);
|
||||
|
||||
|
||||
@@ -23,12 +23,6 @@
|
||||
|
||||
#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));
|
||||
@@ -66,7 +60,6 @@ static int getTileH(lua_State* L) {
|
||||
}
|
||||
|
||||
static const luaL_Reg tileSheetLib[] = {
|
||||
{"GetTileSheet",getTileSheet},
|
||||
{"Load",load},
|
||||
{"Unload",unload},
|
||||
{"GetXCount",getXCount},
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
#include "lua/lua.hpp"
|
||||
|
||||
#define TORTUGA_TILE_SHEET_PSEUDO_INDEX "TileSheetPseudoIndex"
|
||||
#define TORTUGA_TILE_SHEET_NAME "TileSheet"
|
||||
LUAMOD_API int openTileSheetAPI(lua_State* L);
|
||||
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
@@ -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
|
||||
@@ -0,0 +1,130 @@
|
||||
/* 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>
|
||||
|
||||
void ConfigUtility::Load(std::string fname) {
|
||||
//clear the stored configuration
|
||||
configMap.clear();
|
||||
//pass to the recursive method
|
||||
configMap = Read(fname);
|
||||
}
|
||||
|
||||
ConfigUtility::table_t ConfigUtility::Read(std::string fname) {
|
||||
//read in and return this file's data
|
||||
table_t retTable;
|
||||
std::ifstream is(fname);
|
||||
|
||||
if (!is.is_open()) {
|
||||
std::string msg;
|
||||
msg += "Failed to open a config file: ";
|
||||
msg += fname;
|
||||
throw(std::runtime_error(msg));
|
||||
}
|
||||
|
||||
std::string key, val;
|
||||
|
||||
while(true) { //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);
|
||||
|
||||
//disallow empty/wiped values
|
||||
if (key.size() == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//save the pair
|
||||
retTable[key] = val;
|
||||
}
|
||||
|
||||
is.close();
|
||||
|
||||
//load in any subordinate config files
|
||||
//TODO: Possibility of nesting config levels?
|
||||
if (retTable.find("config.next") != retTable.end()) {
|
||||
table_t subTable = Read(retTable["config.next"]);
|
||||
retTable.insert(subTable.begin(), subTable.end());
|
||||
}
|
||||
|
||||
return retTable;
|
||||
}
|
||||
|
||||
//-------------------------
|
||||
//Convert to a type
|
||||
//-------------------------
|
||||
|
||||
std::string& ConfigUtility::String(std::string s) {
|
||||
return configMap[s];
|
||||
}
|
||||
|
||||
int ConfigUtility::Integer(std::string s) {
|
||||
table_t::iterator it = configMap.find(s);
|
||||
if (it == configMap.end()) {
|
||||
return 0;
|
||||
}
|
||||
return atoi(it->second.c_str());
|
||||
}
|
||||
|
||||
double ConfigUtility::Double(std::string s) {
|
||||
table_t::iterator it = configMap.find(s);
|
||||
if (it == configMap.end()) {
|
||||
return 0.0;
|
||||
}
|
||||
return atof(it->second.c_str());
|
||||
}
|
||||
|
||||
bool ConfigUtility::Boolean(std::string s) {
|
||||
table_t::iterator it = configMap.find(s);
|
||||
if (it == configMap.end()) {
|
||||
return false;
|
||||
}
|
||||
return it->second == "true";
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/* 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 "singleton.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
class ConfigUtility : public Singleton<ConfigUtility> {
|
||||
public:
|
||||
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
|
||||
inline std::string& operator[](std::string s) { return configMap[s]; }
|
||||
inline int Int(std::string s) { return Integer(s); }
|
||||
inline bool Bool(std::string s) { return Boolean(s); }
|
||||
|
||||
private:
|
||||
typedef std::map<std::string, std::string> table_t;
|
||||
|
||||
friend Singleton<ConfigUtility>;
|
||||
|
||||
ConfigUtility() = default;
|
||||
~ConfigUtility() = default;
|
||||
|
||||
table_t Read(std::string fname);
|
||||
|
||||
table_t configMap;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,63 @@
|
||||
/* 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 SINGLETON_HPP_
|
||||
#define SINGLETON_HPP_
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
template<typename T>
|
||||
class Singleton {
|
||||
public:
|
||||
static T& GetSingleton() {
|
||||
if (!ptr) {
|
||||
throw(std::logic_error("This singleton has not been created"));
|
||||
}
|
||||
return *ptr;
|
||||
}
|
||||
static void Create() {
|
||||
if (ptr) {
|
||||
throw(std::logic_error("This singleton has already been created"));
|
||||
}
|
||||
ptr = new T();
|
||||
}
|
||||
static void Delete() {
|
||||
if (!ptr) {
|
||||
throw(std::logic_error("A non-existant singleton cannot be deleted"));
|
||||
}
|
||||
delete ptr;
|
||||
ptr = nullptr;
|
||||
}
|
||||
|
||||
protected:
|
||||
Singleton() = default;
|
||||
Singleton(Singleton const&) = default;
|
||||
Singleton(Singleton&&) = default;
|
||||
~Singleton() = default;
|
||||
|
||||
private:
|
||||
static T* ptr;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
T* Singleton<T>::ptr = nullptr;
|
||||
|
||||
#endif
|
||||
@@ -4,9 +4,9 @@
|
||||
#RM=del /y
|
||||
|
||||
#CXXFLAGS+=-static-libgcc -static-libstdc++ -g -fno-inline-functions -Wall
|
||||
CXXFLAGS+=-static-libgcc -static-libstdc++
|
||||
#CXXFLAGS+=-static-libgcc -static-libstdc++
|
||||
|
||||
export
|
||||
#export
|
||||
|
||||
OUTDIR=out
|
||||
|
||||
@@ -15,6 +15,12 @@ all: $(OUTDIR)
|
||||
$(MAKE) -C server
|
||||
$(MAKE) -C client
|
||||
|
||||
debug: export CXXFLAGS+=-g
|
||||
debug: clean all
|
||||
|
||||
release: export CXXFLAGS+=-static-libgcc -static-libstdc++
|
||||
release: clean all
|
||||
|
||||
$(OUTDIR):
|
||||
mkdir $(OUTDIR)
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
#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.w = 800
|
||||
#client.screen.h = 600
|
||||
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
|
||||
@@ -4,15 +4,7 @@ print("Lua script check")
|
||||
function math.sqr(x) return x*x end
|
||||
function math.dist(x, y, i, j) return math.sqrt(math.sqr(x - i) + math.sqr(y - j)) end
|
||||
|
||||
--objects to work on
|
||||
--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
|
||||
--tile macros, mapped to the tilesheet
|
||||
local base = 14
|
||||
local shift = 36
|
||||
tiles = {
|
||||
@@ -23,9 +15,7 @@ tiles = {
|
||||
water = base + shift * 4
|
||||
}
|
||||
|
||||
--TODO: could set custom generation systems here, that differ from the global generators, etc.
|
||||
--TODO: I need a way to allow for different generation algorithms for different pager objects
|
||||
--TODO: This design requires only one pager, but this is not good.
|
||||
--could set custom generation systems here, that differ from the global generators, etc.
|
||||
function Region.Create(region)
|
||||
for i = 1, Region.GetWidth() do
|
||||
for j = 1, Region.GetHeight() do
|
||||
@@ -42,4 +32,15 @@ function Region.Create(region)
|
||||
end
|
||||
end
|
||||
|
||||
--Get some regions
|
||||
--BUG: The server fails without this
|
||||
newRoom = RoomMgr.CreateRoom("overworld")
|
||||
pager = Room.GetPager(newRoom)
|
||||
regionTable = {
|
||||
RegionPager.GetRegion(pager, Region.GetWidth() * 0, Region.GetHeight() * 0),
|
||||
RegionPager.GetRegion(pager, Region.GetWidth() *-1, Region.GetHeight() * 0),
|
||||
RegionPager.GetRegion(pager, Region.GetWidth() * 0, Region.GetHeight() *-1),
|
||||
RegionPager.GetRegion(pager, Region.GetWidth() *-1, Region.GetHeight() *-1)
|
||||
}
|
||||
|
||||
print("Finished the lua script")
|
||||
@@ -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
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
|
||||
#include "region_api.hpp"
|
||||
#include "region_pager_api.hpp"
|
||||
#include "tile_sheet_api.hpp"
|
||||
#include "room_api.hpp"
|
||||
#include "room_mgr_api.hpp"
|
||||
|
||||
@@ -58,6 +59,7 @@ static const luaL_Reg loadedlibs[] = {
|
||||
//Tortuga's API
|
||||
{TORTUGA_REGION_NAME, openRegionAPI},
|
||||
{TORTUGA_REGION_PAGER_NAME, openRegionPagerAPI},
|
||||
{TORTUGA_TILE_SHEET_NAME, openTileSheetAPI},
|
||||
{TORTUGA_ROOM_NAME, openRoomAPI},
|
||||
{TORTUGA_ROOM_MGR_NAME, openRoomMgrAPI},
|
||||
|
||||
|
||||
+13
-1
@@ -21,6 +21,9 @@
|
||||
*/
|
||||
#include "server_application.hpp"
|
||||
|
||||
//singletons
|
||||
#include "config_utility.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
|
||||
@@ -28,10 +31,19 @@ using namespace std;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
try {
|
||||
ServerApplication app;
|
||||
//create the singletons
|
||||
ConfigUtility::Create();
|
||||
ServerApplication::Create();
|
||||
|
||||
//call the server's routines
|
||||
ServerApplication& app = ServerApplication::GetSingleton();
|
||||
app.Init(argc, argv);
|
||||
app.Proc();
|
||||
app.Quit();
|
||||
|
||||
//delete the singletons
|
||||
ConfigUtility::Delete();
|
||||
ServerApplication::Delete();
|
||||
}
|
||||
catch(exception& e) {
|
||||
cerr << "Fatal exception thrown: " << e.what() << endl;
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
//common utilities
|
||||
#include "udp_network_utility.hpp"
|
||||
#include "config_utility.hpp"
|
||||
#include "singleton.hpp"
|
||||
|
||||
//APIs
|
||||
#include "lua/lua.hpp"
|
||||
@@ -42,17 +43,19 @@
|
||||
#include <string>
|
||||
|
||||
//The main application class
|
||||
class ServerApplication {
|
||||
class ServerApplication: public Singleton<ServerApplication> {
|
||||
public:
|
||||
//public methods
|
||||
ServerApplication() = default;
|
||||
~ServerApplication() = default;
|
||||
|
||||
void Init(int argc, char** argv);
|
||||
void Proc();
|
||||
void Quit();
|
||||
|
||||
private:
|
||||
friend Singleton<ServerApplication>;
|
||||
|
||||
ServerApplication() = default;
|
||||
~ServerApplication() = default;
|
||||
|
||||
//handle incoming traffic
|
||||
void HandlePacket(SerialPacket* const);
|
||||
|
||||
@@ -83,7 +86,7 @@ private:
|
||||
sqlite3* database = nullptr;
|
||||
lua_State* luaState = nullptr;
|
||||
UDPNetworkUtility network;
|
||||
ConfigUtility config;
|
||||
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||
|
||||
//simple tables
|
||||
std::map<int, ClientData> clientMap;
|
||||
|
||||
Reference in New Issue
Block a user