Compare commits

..

5 Commits

Author SHA1 Message Date
Kayne Ruse f978cff98f lobby_server.cpp compiles 2014-07-31 15:58:56 +10:00
Kayne Ruse 35363c05c3 Updated a number of simpler client scenes (read more)
Updated the ClientApplication class to help support the new design, but
it's not finished because of that module's dependence on the various
scenes.

Updated the following scenes:

* CleanUp
* MainMenu
* OptionsMenu

The following source files (in client/scenes/) compile correctly:

* base_scene.cpp
* splash_screen.cpp
* clean_up.cpp
* main_menu.cpp
* options_menu.cpp

The folling source files (in client/scenes/) do not compile:

* in_world.cpp
* in_combat.cpp
* lobby_menu.cpp
2014-07-31 14:53:08 +10:00
Kayne Ruse a8eb67d619 Updated ClientApplication 2014-07-31 13:57:46 +10:00
Kayne Ruse 67c8bb6f11 rsc/ and common/ seem OK from the splice (read more)
common compiles correctly, although there are issues:

* There needs to be support for multiple pagers at once
* There needs to be a way to support multiple generation algorithms
2014-07-30 22:55:22 +10:00
Kayne Ruse 03f1723d88 Lazily committing the entire splice at once (read more)
(this message is copied from my blog)

So I took the lazy route and just committed the entire splice between the jam branch and the development branch all at once. It is exactly as terrible as you think it is, but I've been out of coding for 2 weeks, and I want to get some shit done. I'll pick through each piece one by one, by comparing the diffs from the develop branch to the current jam-merge branch.

Those developers I met on Monday said they were impressed by my ability to manage a large codebase, but if they saw this I'd expect they'd probably take that back.

And oh god it's been 3 weeks since I touched the main branch WTF?
2014-07-30 22:42:24 +10:00
41 changed files with 535 additions and 618 deletions
+1
View File
@@ -15,6 +15,7 @@ Out/
*.o *.o
*.a *.a
*.exe *.exe
*.diff
#Shell files #Shell files
*.bat *.bat
+2 -11
View File
@@ -26,7 +26,6 @@
#include "character_defines.hpp" #include "character_defines.hpp"
#include "vector2.hpp" #include "vector2.hpp"
#include "bounding_box.hpp" #include "bounding_box.hpp"
#include "statistics.hpp"
//graphics //graphics
#include "sprite_sheet.hpp" #include "sprite_sheet.hpp"
@@ -47,9 +46,6 @@ public:
void CorrectSprite(); void CorrectSprite();
SpriteSheet* GetSprite() { return &sprite; } SpriteSheet* GetSprite() { return &sprite; }
//gameplay
Statistics* GetStats() { return &stats; }
//accessors and mutators //accessors and mutators
//metadata //metadata
@@ -65,18 +61,13 @@ public:
Vector2 GetOrigin() const { return origin; } Vector2 GetOrigin() const { return origin; }
Vector2 SetMotion(Vector2 v) { return motion = v; } Vector2 SetMotion(Vector2 v) { return motion = v; }
Vector2 GetMotion() const { return motion; } Vector2 GetMotion() const { return motion; }
BoundingBox SetBounds(BoundingBox b) { return bounds = b; } BoundingBox SetBoundingBox(BoundingBox b) { return bounds = b; }
BoundingBox GetBounds() { return bounds; } BoundingBox GetBoundingBox() const { return bounds; }
private: private:
//graphics //graphics
SpriteSheet sprite; SpriteSheet sprite;
//base statistics
Statistics stats;
//TODO: gameplay components: equipment, items, buffs, debuffs
//metadata //metadata
int owner; int owner;
std::string handle; std::string handle;
+62 -28
View File
@@ -22,7 +22,6 @@
#include "client_application.hpp" #include "client_application.hpp"
#include "serial.hpp" #include "serial.hpp"
#include "config_utility.hpp"
#include <stdexcept> #include <stdexcept>
#include <chrono> #include <chrono>
@@ -48,10 +47,6 @@
void ClientApplication::Init(int argc, char** argv) { void ClientApplication::Init(int argc, char** argv) {
std::cout << "Beginning " << argv[0] << std::endl; std::cout << "Beginning " << argv[0] << std::endl;
//load the prerequisites
ConfigUtility& config = ConfigUtility::GetSingleton();
config.Load("rsc\\config.cfg");
//------------------------- //-------------------------
//Initialize the APIs //Initialize the APIs
//------------------------- //-------------------------
@@ -69,42 +64,80 @@ void ClientApplication::Init(int argc, char** argv) {
network.Open(0); network.Open(0);
std::cout << "Initialized SDL_net" << std::endl; 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 //Setup the screen
//------------------------- //-------------------------
int w = config.Int("client.screen.w"); //get each field
int h = config.Int("client.screen.h"); lua_getfield(lua, -1, "client");
int f = config.Bool("client.screen.f") ? SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN : SDL_HWSURFACE|SDL_DOUBLEBUF; lua_getfield(lua, -1, "screen");
lua_getfield(lua, -1, "width");
lua_getfield(lua, -2, "height");
lua_getfield(lua, -3, "fullscreen");
BaseScene::SetScreen(w ? w : 800, h ? h : 600, 0, f); 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; std::cout << "Initialized the screen" << std::endl;
//------------------------- //-------------------------
//debug output //debug output
//------------------------- //-------------------------
//TODO: enable/disable these with a switch lua_getfield(lua, -1, "debug");
if (lua_toboolean(lua, -1)) {
#define DEBUG_OUTPUT_VAR(x) std::cout << "\t" << #x << ": " << x << std::endl; #define DEBUG_OUTPUT_VAR(x) std::cout << "\t" << #x << ": " << x << std::endl;
std::cout << "Internal sizes:" << std::endl; std::cout << "Internal sizes:" << std::endl;
DEBUG_OUTPUT_VAR(sizeof(Region::type_t)); DEBUG_OUTPUT_VAR(sizeof(Region::type_t));
DEBUG_OUTPUT_VAR(sizeof(Region)); DEBUG_OUTPUT_VAR(sizeof(Region));
DEBUG_OUTPUT_VAR(REGION_WIDTH); DEBUG_OUTPUT_VAR(REGION_WIDTH);
DEBUG_OUTPUT_VAR(REGION_HEIGHT); DEBUG_OUTPUT_VAR(REGION_HEIGHT);
DEBUG_OUTPUT_VAR(REGION_DEPTH); DEBUG_OUTPUT_VAR(REGION_DEPTH);
DEBUG_OUTPUT_VAR(REGION_SOLID_FOOTPRINT); DEBUG_OUTPUT_VAR(REGION_SOLID_FOOTPRINT);
DEBUG_OUTPUT_VAR(REGION_FOOTPRINT); DEBUG_OUTPUT_VAR(REGION_FOOTPRINT);
DEBUG_OUTPUT_VAR(PACKET_BUFFER_SIZE); DEBUG_OUTPUT_VAR(PACKET_BUFFER_SIZE);
DEBUG_OUTPUT_VAR(MAX_PACKET_SIZE); DEBUG_OUTPUT_VAR(MAX_PACKET_SIZE);
#undef DEBUG_OUTPUT_VAR #undef DEBUG_OUTPUT_VAR
}
//pop the debug value
lua_pop(lua, 1);
//------------------------- //-------------------------
//finalize the startup //finalize the startup
//------------------------- //-------------------------
//pop the config table
lua_pop(lua, 1);
std::cout << "Startup completed successfully" << std::endl; std::cout << "Startup completed successfully" << std::endl;
//------------------------- //-------------------------
@@ -138,7 +171,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(double(delta.count()) / std::chrono::duration<int, std::milli>::period::den); activeScene->RunFrame(constexpr(double(delta.count()) / std::chrono::duration<int, std::milli>::period::den));
simTime += delta; simTime += delta;
} }
@@ -151,6 +184,7 @@ void ClientApplication::Proc() {
void ClientApplication::Quit() { void ClientApplication::Quit() {
std::cout << "Shutting down" << std::endl; std::cout << "Shutting down" << std::endl;
lua_close(lua);
network.Close(); network.Close();
SDLNet_Quit(); SDLNet_Quit();
SDL_Quit(); SDL_Quit();
@@ -167,25 +201,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(); activeScene = new SplashScreen(lua);
break; break;
case SceneList::MAINMENU: case SceneList::MAINMENU:
activeScene = new MainMenu(); activeScene = new MainMenu(lua);
break; break;
case SceneList::OPTIONSMENU: case SceneList::OPTIONSMENU:
activeScene = new OptionsMenu(); activeScene = new OptionsMenu(lua);
break; break;
case SceneList::LOBBYMENU: case SceneList::LOBBYMENU:
activeScene = new LobbyMenu(&network, &clientIndex, &accountIndex); activeScene = new LobbyMenu(lua, network, characterMap);
break; break;
case SceneList::INWORLD: case SceneList::INWORLD:
activeScene = new InWorld(&network, &clientIndex, &accountIndex, &characterIndex, &characterMap); activeScene = new InWorld(lua, network, characterMap);
break; break;
case SceneList::INCOMBAT: case SceneList::INCOMBAT:
activeScene = new InCombat(&network, &clientIndex, &accountIndex, &characterIndex, &characterMap); activeScene = new InCombat(lua, network, characterMap);
break; break;
case SceneList::CLEANUP: case SceneList::CLEANUP:
activeScene = new CleanUp(&network, &clientIndex, &accountIndex, &characterIndex, &characterMap); activeScene = new CleanUp(lua, network, characterMap);
break; break;
default: default:
throw(std::logic_error("Failed to recognize the scene index")); throw(std::logic_error("Failed to recognize the scene index"));
+6 -8
View File
@@ -28,23 +28,20 @@
#include "udp_network_utility.hpp" #include "udp_network_utility.hpp"
#include "character.hpp" #include "character.hpp"
#include "singleton.hpp" #include "lua/lua.hpp"
#include <map> #include <map>
class ClientApplication: public Singleton<ClientApplication> { class ClientApplication {
public: public:
//public methods ClientApplication() = default;
~ClientApplication() = default;
void Init(int argc, char** argv); void Init(int argc, char** argv);
void Proc(); void Proc();
void Quit(); void Quit();
private: private:
friend Singleton<ClientApplication>;
ClientApplication() = default;
~ClientApplication() = default;
//Private access members //Private access members
void LoadScene(SceneList sceneIndex); void LoadScene(SceneList sceneIndex);
void UnloadScene(); void UnloadScene();
@@ -52,6 +49,7 @@ private:
BaseScene* activeScene = nullptr; BaseScene* activeScene = nullptr;
//shared parameters //shared parameters
lua_State* lua = nullptr;
UDPNetworkUtility network; UDPNetworkUtility network;
int clientIndex = -1; int clientIndex = -1;
int accountIndex = -1; int accountIndex = -1;
+85
View File
@@ -0,0 +1,85 @@
/* $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
}
+2 -14
View File
@@ -21,9 +21,6 @@
*/ */
#include "client_application.hpp" #include "client_application.hpp"
//singletons
#include "config_utility.hpp"
#include <stdexcept> #include <stdexcept>
#include <iostream> #include <iostream>
@@ -31,23 +28,14 @@ using namespace std;
int main(int argc, char** argv) { int main(int argc, char** argv) {
try { try {
//create the singletons ClientApplication app;
ClientApplication::Create();
ConfigUtility::Create();
//call the server's routines
ClientApplication& app = ClientApplication::GetSingleton();
app.Init(argc, argv); app.Init(argc, argv);
app.Proc(); app.Proc();
app.Quit(); app.Quit();
//delete the singletons
ConfigUtility::Delete();
ClientApplication::Delete();
} }
catch(exception& e) { catch(exception& e) {
cerr << "Fatal exception thrown: " << e.what() << endl; cerr << "Fatal exception thrown: " << e.what() << endl;
return 1; return 1;
} }
return 0; return 0;
} }
+36 -23
View File
@@ -22,7 +22,6 @@
#include "clean_up.hpp" #include "clean_up.hpp"
#include "channels.hpp" #include "channels.hpp"
#include "config_utility.hpp"
#include <stdexcept> #include <stdexcept>
@@ -30,25 +29,43 @@
//Public access members //Public access members
//------------------------- //-------------------------
CleanUp::CleanUp( CleanUp::CleanUp(lua_State* L, UDPNetworkUtility& aNetwork, CharacterMap& aCharacterMap):
UDPNetworkUtility* const argNetwork, lua(L),
int* const argClientIndex, network(aNetwork),
int* const argAccountIndex, characterMap(aCharacterMap)
int* const argCharacterIndex,
CharacterMap* argCharacterMap
):
network(*argNetwork),
clientIndex(*argClientIndex),
accountIndex(*argAccountIndex),
characterIndex(*argCharacterIndex),
characterMap(*argCharacterMap)
{ {
ConfigUtility& config = ConfigUtility::GetSingleton(); //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(config["dir.interface"] + "button_menu.bmp"); image.LoadSurface(interfaceDir + "button_menu.bmp");
image.SetClipH(image.GetClipH()/3); image.SetClipH(image.GetClipH()/3);
font.LoadSurface(config["dir.fonts"] + "pk_white_8.bmp"); font.LoadSurface(fontsDir + "pk_white_8.bmp");
//pass the utility objects //pass the utility objects
backButton.SetImage(&image); backButton.SetImage(&image);
@@ -63,12 +80,7 @@ CleanUp::CleanUp(
//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();
@@ -84,7 +96,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)) {
QuitEvent(); SetNextScene(SceneList::MAINMENU);
} }
//BUGFIX: Eat incoming packets //BUGFIX: Eat incoming packets
@@ -120,7 +132,8 @@ 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);
} }
} }
+8 -18
View File
@@ -25,18 +25,18 @@
//network //network
#include "udp_network_utility.hpp" #include "udp_network_utility.hpp"
//graphics //graphics & ui
#include "image.hpp" #include "image.hpp"
#include "raster_font.hpp" #include "raster_font.hpp"
#include "button.hpp" #include "button.hpp"
//common
#include "frame_rate.hpp" #include "frame_rate.hpp"
#include "character.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,13 +44,7 @@
class CleanUp : public BaseScene { class CleanUp : public BaseScene {
public: public:
//Public access members //Public access members
CleanUp( CleanUp(lua_State*, UDPNetworkUtility&, CharacterMap&);
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
int* const argAccountIndex,
int* const argCharacterIndex,
CharacterMap* argCharacterMap
);
~CleanUp(); ~CleanUp();
protected: protected:
@@ -68,17 +62,13 @@ protected:
void KeyUp(SDL_KeyboardEvent const&); void KeyUp(SDL_KeyboardEvent const&);
//shared parameters //shared parameters
lua_State* lua = nullptr;
UDPNetworkUtility& network; UDPNetworkUtility& network;
int& clientIndex;
int& accountIndex;
int& characterIndex;
CharacterMap& characterMap; CharacterMap& characterMap;
//graphics //graphics & ui
Image image; Image image;
RasterFont font; RasterFont font;
//UI
Button backButton; Button backButton;
FrameRate fps; FrameRate fps;
+2 -1
View File
@@ -23,7 +23,6 @@
#include "channels.hpp" #include "channels.hpp"
#include "utility.hpp" #include "utility.hpp"
#include "config_utility.hpp"
#include <stdexcept> #include <stdexcept>
@@ -32,12 +31,14 @@
//------------------------- //-------------------------
InCombat::InCombat( InCombat::InCombat(
ConfigUtility* const argConfig,
UDPNetworkUtility* const argNetwork, UDPNetworkUtility* const argNetwork,
int* const argClientIndex, int* const argClientIndex,
int* const argAccountIndex, int* const argAccountIndex,
int* const argCharacterIndex, int* const argCharacterIndex,
CharacterMap* argCharacterMap CharacterMap* argCharacterMap
): ):
config(*argConfig),
network(*argNetwork), network(*argNetwork),
clientIndex(*argClientIndex), clientIndex(*argClientIndex),
accountIndex(*argAccountIndex), accountIndex(*argAccountIndex),
+3
View File
@@ -31,6 +31,7 @@
#include "button.hpp" #include "button.hpp"
//common //common
#include "config_utility.hpp"
#include "frame_rate.hpp" #include "frame_rate.hpp"
#include "character.hpp" #include "character.hpp"
@@ -42,6 +43,7 @@ class InCombat : public BaseScene {
public: public:
//Public access members //Public access members
InCombat( InCombat(
ConfigUtility* const argConfig,
UDPNetworkUtility* const argNetwork, UDPNetworkUtility* const argNetwork,
int* const argClientIndex, int* const argClientIndex,
int* const argAccountIndex, int* const argAccountIndex,
@@ -77,6 +79,7 @@ protected:
void RequestShutdown(); void RequestShutdown();
//shared parameters //shared parameters
ConfigUtility& config;
UDPNetworkUtility& network; UDPNetworkUtility& network;
int& clientIndex; int& clientIndex;
int& accountIndex; int& accountIndex;
+81 -27
View File
@@ -23,7 +23,6 @@
#include "channels.hpp" #include "channels.hpp"
#include "utility.hpp" #include "utility.hpp"
#include "config_utility.hpp"
#include <stdexcept> #include <stdexcept>
#include <algorithm> #include <algorithm>
@@ -35,20 +34,74 @@
//------------------------- //-------------------------
InWorld::InWorld( InWorld::InWorld(
ConfigUtility* const argConfig,
UDPNetworkUtility* const argNetwork, UDPNetworkUtility* const argNetwork,
int* const argClientIndex, int* const argClientIndex,
int* const argAccountIndex, int* const argAccountIndex,
int* const argCharacterIndex, int* const argCharacterIndex,
CharacterMap* argCharacterMap CharacterMap* argCharacterMap
): ):
config(*argConfig),
network(*argNetwork), network(*argNetwork),
clientIndex(*argClientIndex), clientIndex(*argClientIndex),
accountIndex(*argAccountIndex), accountIndex(*argAccountIndex),
characterIndex(*argCharacterIndex), characterIndex(*argCharacterIndex),
characterMap(*argCharacterMap) characterMap(*argCharacterMap)
{ {
ConfigUtility& config = ConfigUtility::GetSingleton(); //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);
@@ -72,8 +125,7 @@ InWorld::InWorld(
//load the tilesheet //load the tilesheet
//TODO: add the tilesheet to the map system? //TODO: add the tilesheet to the map system?
//TODO: Tile size and tile sheet should be loaded elsewhere tileSheet.Load(config["dir.tilesets"] + "terrain.bmp", 12, 15);
tileSheet.Load(config["dir.tilesets"] + "terrain.bmp", 32, 32);
//request a sync //request a sync
RequestSynchronize(); RequestSynchronize();
@@ -83,7 +135,13 @@ 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);
} }
//------------------------- //-------------------------
@@ -107,41 +165,38 @@ void InWorld::Update(double delta) {
it.second.Update(delta); it.second.Update(delta);
} }
//check the map //TODO: Check collisions here
UpdateMap();
//skip the rest
if (!localCharacter) {
return;
}
//check for collisions with the map //check for collisions with the map
BoundingBox wallBounds = {0, 0, tileSheet.GetTileW(), tileSheet.GetTileH()}; BoundingBox wallBounds = {0, 0, tileSheet.GetTileW(), tileSheet.GetTileH()};
const int xCount = localCharacter->GetBounds().w / wallBounds.w + 1; const int xCount = character.GetBoundingBox().w / wallBounds.w + 1;
const int yCount = localCharacter->GetBounds().h / wallBounds.h + 1; const int yCount = character.GetBoundingBox().h / wallBounds.h + 1;
for (int i = -1; i <= xCount; ++i) { for (int i = -1; i <= xCount; ++i) {
for (int j = -1; j <= yCount; ++j) { for (int j = -1; j <= yCount; ++j) {
//set the wall's position //set the wall's position
wallBounds.x = wallBounds.w * i + snapToBase((double)wallBounds.w, localCharacter->GetOrigin().x); wallBounds.x = wallBounds.w * i + snapToBase((double)wallBounds.w, character.GetOrigin().x);
wallBounds.y = wallBounds.h * j + snapToBase((double)wallBounds.h, localCharacter->GetOrigin().y); wallBounds.y = wallBounds.h * j + snapToBase((double)wallBounds.h, character.GetOrigin().y);
if (!regionPager.GetSolid(wallBounds.x / wallBounds.w, wallBounds.y / wallBounds.h)) { if (!pager.GetSolid(wallBounds.x / wallBounds.w, wallBounds.y / wallBounds.h)) {
continue; continue;
} }
if ((localCharacter->GetOrigin() + localCharacter->GetBounds()).CheckOverlap(wallBounds)) { if ((character.GetOrigin() + character.GetBoundingBox()).CheckOverlap(wallBounds)) {
localCharacter->SetOrigin(localCharacter->GetOrigin() - (localCharacter->GetMotion() * delta)); character.SetOrigin(character.GetOrigin() - (character.GetMotion() * delta));
localCharacter->SetMotion({0,0}); character.SetMotion({0,0});
localCharacter->CorrectSprite(); character.CorrectSprite();
SendPlayerUpdate();
} }
} }
} }
//update the camera //update the camera
camera.x = localCharacter->GetOrigin().x - camera.marginX; if(localCharacter) {
camera.y = localCharacter->GetOrigin().y - camera.marginY; camera.x = localCharacter->GetOrigin().x - camera.marginX;
camera.y = localCharacter->GetOrigin().y - camera.marginY;
}
//check the map
UpdateMap();
} }
void InWorld::FrameEnd() { void InWorld::FrameEnd() {
@@ -303,11 +358,10 @@ void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) {
newCharacter.SetHandle(argPacket->handle); newCharacter.SetHandle(argPacket->handle);
newCharacter.SetAvatar(argPacket->avatar); newCharacter.SetAvatar(argPacket->avatar);
newCharacter.GetSprite()->LoadSurface(ConfigUtility::GetSingleton()["dir.sprites"] + newCharacter.GetAvatar(), 4, 4); newCharacter.GetSprite()->LoadSurface(config["dir.sprites"] + newCharacter.GetAvatar(), 4, 4);
newCharacter.SetOrigin(argPacket->origin); newCharacter.SetOrigin(argPacket->origin);
newCharacter.SetMotion(argPacket->motion); newCharacter.SetMotion(argPacket->motion);
newCharacter.SetBounds({0, 16, 32, 32}); //TODO: magic numbers, fix this
(*newCharacter.GetStats()) = argPacket->stats; (*newCharacter.GetStats()) = argPacket->stats;
+18 -11
View File
@@ -22,25 +22,28 @@
#ifndef INWORLD_HPP_ #ifndef INWORLD_HPP_
#define INWORLD_HPP_ #define INWORLD_HPP_
//maps //map stuff
#include "region_pager_base.hpp" #include "tile_sheet.hpp"
#include "region_pager_lua.hpp"
//networking //networking
#include "udp_network_utility.hpp" #include "udp_network_utility.hpp"
//graphics //graphics & ui
#include "image.hpp" #include "image.hpp"
#include "raster_font.hpp" #include "raster_font.hpp"
#include "button.hpp" #include "button.hpp"
#include "tile_sheet.hpp"
//common //utilities
#include "frame_rate.hpp" #include "frame_rate.hpp"
#include "timer.hpp"
#include "character.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>
@@ -49,6 +52,7 @@ class InWorld : public BaseScene {
public: public:
//Public access members //Public access members
InWorld( InWorld(
ConfigUtility* const argConfig,
UDPNetworkUtility* const argNetwork, UDPNetworkUtility* const argNetwork,
int* const argClientIndex, int* const argClientIndex,
int* const argAccountIndex, int* const argAccountIndex,
@@ -91,7 +95,9 @@ protected:
//utilities //utilities
void UpdateMap(); void UpdateMap();
//TODO: Streamline this with lua
//shared parameters //shared parameters
ConfigUtility& config;
UDPNetworkUtility& network; UDPNetworkUtility& network;
int& clientIndex; int& clientIndex;
int& accountIndex; int& accountIndex;
@@ -111,10 +117,11 @@ protected:
Button shutDownButton; Button shutDownButton;
//TODO: Review the camera //TODO: Review the camera
struct { struct {
int x = 0, y = 0; struct {
int width = 0, height = 0; int x, y;
int marginX = 0, marginY = 0; }origin, margin;
} camera; }camera;
FrameRate fps; FrameRate fps;
//game //game
+57 -21
View File
@@ -30,19 +30,25 @@
//Public access members //Public access members
//------------------------- //-------------------------
LobbyMenu::LobbyMenu( LobbyMenu::LobbyMenu(lua_State* L, UDPNetworkUtility& aNetwork):
UDPNetworkUtility* const argNetwork, lua(L),
int* const argClientIndex, network(aNetwork)
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 //setup the utility objects
image.LoadSurface(config["dir.interface"] + "button_menu.bmp"); image.LoadSurface(interfaceDir + "button_menu.bmp");
image.SetClipH(image.GetClipH()/3); image.SetClipH(image.GetClipH()/3);
font.LoadSurface(config["dir.fonts"] + "pk_white_8.bmp"); font.LoadSurface(fontsDir + "pk_white_8.bmp");
//pass the utility objects //pass the utility objects
search.SetImage(&image); search.SetImage(&image);
@@ -86,11 +92,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 = static_cast<SerialPacket*>(malloc(MAX_PACKET_SIZE)); SerialPacket* packetBuffer = new SerialPacket();
while(network.Receive(packetBuffer)) { while(network.Receive(packetBuffer)) {
HandlePacket(packetBuffer); HandlePacket(packetBuffer);
} }
free(static_cast<void*>(packetBuffer)); delete packetBuffer;
} }
void LobbyMenu::FrameEnd() { void LobbyMenu::FrameEnd() {
@@ -146,26 +152,44 @@ 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(config["server.host"].c_str(), config.Int("server.port"), &packet); network.SendTo(lua_tostring(lua, -2), lua_tointeger(lua, -1), &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, config["client.username"].c_str(), PACKET_STRING_SIZE); strncpy(packet.username, lua_tostring(lua, -1), 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) {
@@ -185,6 +209,9 @@ 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) {
@@ -202,10 +229,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(static_cast<ServerPacket*>(argPacket)); HandleBroadcastResponse(dynamic_cast<ServerPacket*>(argPacket));
break; break;
case SerialPacketType::JOIN_RESPONSE: case SerialPacketType::JOIN_RESPONSE:
HandleJoinResponse(static_cast<ClientPacket*>(argPacket)); HandleJoinResponse(dynamic_cast<ClientPacket*>(argPacket));
break; break;
//handle errors //handle errors
default: default:
@@ -230,16 +257,25 @@ void LobbyMenu::HandleBroadcastResponse(ServerPacket* const argPacket) {
} }
void LobbyMenu::HandleJoinResponse(ClientPacket* const argPacket) { void LobbyMenu::HandleJoinResponse(ClientPacket* const argPacket) {
clientIndex = argPacket->clientIndex; lua_getglobal(lua, "config");
accountIndex = argPacket->accountIndex; 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");
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, config["client.handle"].c_str(), PACKET_STRING_SIZE); strncpy(newPacket.handle, lua_tostring(lua, -2), PACKET_STRING_SIZE);
strncpy(newPacket.avatar, config["client.avatar"].c_str(), PACKET_STRING_SIZE); strncpy(newPacket.avatar, lua_tostring(lua, -1), PACKET_STRING_SIZE);
newPacket.accountIndex = accountIndex; newPacket.accountIndex = argPacket->accountIndex;
network.SendTo(Channels::SERVER, &newPacket); network.SendTo(Channels::SERVER, &newPacket);
lua_pop(lua, 4);
} }
+6 -10
View File
@@ -28,23 +28,21 @@
#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( LobbyMenu(lua_State*, UDPNetworkUtility&);
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
int* const argAccountIndex
);
~LobbyMenu(); ~LobbyMenu();
protected: protected:
@@ -67,10 +65,8 @@ protected:
void HandleJoinResponse(ClientPacket* const); void HandleJoinResponse(ClientPacket* const);
//shared parameters //shared parameters
ConfigUtility& config = ConfigUtility::GetSingleton(); lua_State* lua = nullptr;
UDPNetworkUtility& network; UDPNetworkUtility& network;
int& clientIndex;
int& accountIndex;
//members //members
Image image; Image image;
@@ -91,7 +87,7 @@ protected:
std::vector<ServerInformation> serverInfo; std::vector<ServerInformation> serverInfo;
//a terrible hack, forgive me //a terrible hack, forgive me
//I'd love a proper gui system for this //TODO: I'd love a proper gui system for this
SDL_Rect listBox; SDL_Rect listBox;
ServerInformation* selection = nullptr; ServerInformation* selection = nullptr;
}; };
+16 -9
View File
@@ -21,19 +21,26 @@
*/ */
#include "main_menu.hpp" #include "main_menu.hpp"
#include "config_utility.hpp"
//------------------------- //-------------------------
//Public access members //Public access members
//------------------------- //-------------------------
MainMenu::MainMenu() { MainMenu::MainMenu(lua_State* L): lua(L) {
ConfigUtility& config = ConfigUtility::GetSingleton(); //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(config["dir.interface"] + "button_menu.bmp"); image.LoadSurface(interfaceDir + "button_menu.bmp");
image.SetClipH(image.GetClipH()/3); image.SetClipH(image.GetClipH()/3);
font.LoadSurface(config["dir.fonts"] + "pk_white_8.bmp"); font.LoadSurface(fontsDir + "pk_white_8.bmp");
//pass the utility objects //pass the utility objects
startButton.SetImage(&image); startButton.SetImage(&image);
@@ -103,14 +110,14 @@ void MainMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) {
} }
void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) { void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
//TODO: Buttons should only register as "selected" when the left button is used
if (startButton.MouseButtonUp(button) == Button::State::HOVER) { if (startButton.MouseButtonUp(button) == Button::State::HOVER) {
SetNextScene(SceneList::LOBBYMENU); SetNextScene(SceneList::INWORLD);
} }
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();
} }
} }
+6 -1
View File
@@ -28,10 +28,12 @@
#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(); MainMenu(lua_State* L);
~MainMenu(); ~MainMenu();
protected: protected:
@@ -48,6 +50,9 @@ protected:
void KeyDown(SDL_KeyboardEvent const&); void KeyDown(SDL_KeyboardEvent const&);
void KeyUp(SDL_KeyboardEvent const&); void KeyUp(SDL_KeyboardEvent const&);
//shared parameters
lua_State* lua = nullptr;
//members //members
Image image; Image image;
RasterFont font; RasterFont font;
+15 -7
View File
@@ -21,19 +21,26 @@
*/ */
#include "options_menu.hpp" #include "options_menu.hpp"
#include "config_utility.hpp"
//------------------------- //-------------------------
//Public access members //Public access members
//------------------------- //-------------------------
OptionsMenu::OptionsMenu() { OptionsMenu::OptionsMenu(lua_State* L): lua(L) {
ConfigUtility& config = ConfigUtility::GetSingleton(); //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(config["dir.interface"] + "button_menu.bmp"); image.LoadSurface(interfaceDir + "button_menu.bmp");
image.SetClipH(image.GetClipH()/3); image.SetClipH(image.GetClipH()/3);
font.LoadSurface(config["dir.fonts"] + "pk_white_8.bmp"); font.LoadSurface(fontsDir + "pk_white_8.bmp");
//pass the utility objects //pass the utility objects
backButton.SetImage(&image); backButton.SetImage(&image);
@@ -86,7 +93,8 @@ 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);
} }
} }
+6 -1
View File
@@ -28,11 +28,13 @@
#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(); OptionsMenu(lua_State* L);
~OptionsMenu(); ~OptionsMenu();
protected: protected:
@@ -49,6 +51,9 @@ protected:
void KeyDown(SDL_KeyboardEvent const&); void KeyDown(SDL_KeyboardEvent const&);
void KeyUp(SDL_KeyboardEvent const&); void KeyUp(SDL_KeyboardEvent const&);
//shared parameters
lua_State* lua = nullptr;
//members //members
Image image; Image image;
RasterFont font; RasterFont font;
+10 -3
View File
@@ -21,14 +21,21 @@
*/ */
#include "splash_screen.hpp" #include "splash_screen.hpp"
#include "config_utility.hpp" #include <string>
//------------------------- //-------------------------
//Public access members //Public access members
//------------------------- //-------------------------
SplashScreen::SplashScreen() { SplashScreen::SplashScreen(lua_State* L): lua(L) {
logo.LoadSurface(ConfigUtility::GetSingleton()["dir.logos"] + "krstudios.bmp"); //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");
startTick = std::chrono::steady_clock::now(); startTick = std::chrono::steady_clock::now();
} }
+6 -1
View File
@@ -26,12 +26,14 @@
#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(); SplashScreen(lua_State* L);
~SplashScreen(); ~SplashScreen();
protected: protected:
@@ -39,6 +41,9 @@ protected:
void Update(double delta); void Update(double delta);
void Render(SDL_Surface* const); void Render(SDL_Surface* const);
//shared parameters
lua_State* lua = nullptr;
//members //members
std::chrono::steady_clock::time_point startTick; std::chrono::steady_clock::time_point startTick;
Image logo; Image logo;
+1 -1
View File
@@ -11,7 +11,7 @@ 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)/,libcommon.a)
#targets #targets
+2 -18
View File
@@ -21,25 +21,9 @@
*/ */
#include "timer.hpp" #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) { std::ostream& operator<<(std::ostream& os, Timer& t) {
os << t.GetName() << ": "; os << t.GetName() << ": ";
os << std::chrono::duration_cast<std::chrono::milliseconds>(t.GetTime()).count(); os << std::chrono::duration_cast<std::chrono::nanoseconds>(t.GetTime()).count();
os << "ms"; os << "ns";
return os; return os;
} }
+6 -6
View File
@@ -30,15 +30,15 @@ class Timer {
public: public:
typedef std::chrono::high_resolution_clock Clock; typedef std::chrono::high_resolution_clock Clock;
Timer(); Timer() = default;
Timer(std::string s); Timer(std::string s) : name(s), start(Clock::now()) {};
~Timer() = default; ~Timer() = default;
inline void Start(); inline void Start() { start = Clock::now(); }
inline void Stop(); inline void Stop() { time = Clock::now() - start; }
//accessors and mutators //accessors and mutators
Clock::duration GetTime() { return timeSpan; } Clock::duration GetTime() { return time; }
std::string SetName(std::string s) { return name = s; } std::string SetName(std::string s) { return name = s; }
std::string GetName() { return name; } std::string GetName() { return name; }
@@ -46,7 +46,7 @@ public:
private: private:
std::string name; std::string name;
Clock::time_point start; Clock::time_point start;
Clock::duration timeSpan; Clock::duration time;
}; };
std::ostream& operator<<(std::ostream& os, Timer& t); std::ostream& operator<<(std::ostream& os, Timer& t);
+1 -1
View File
@@ -1,5 +1,5 @@
#config #config
INCLUDES+=. INCLUDES+=. ../map
LIBS+= LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
+1 -1
View File
@@ -1,5 +1,5 @@
#config #config
INCLUDES+=. ../graphics ../utilities INCLUDES+=. ../utilities ../graphics
LIBS+= LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
+6
View File
@@ -26,6 +26,11 @@
#include <string> #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 //DOCS: These glue functions simply wrap RegionPagerLua's methods
static int setTile(lua_State* L) { static int setTile(lua_State* L) {
@@ -91,6 +96,7 @@ static int unloadRegion(lua_State* L) {
} }
static const luaL_Reg regionPagerLib[] = { static const luaL_Reg regionPagerLib[] = {
{"GetRegionPager", getRegionPager},
{"SetTile", setTile}, {"SetTile", setTile},
{"GetTile", getTile}, {"GetTile", getTile},
{"SetSolid", setSolid}, {"SetSolid", setSolid},
+1
View File
@@ -24,6 +24,7 @@
#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);
+7
View File
@@ -23,6 +23,12 @@
#include "tile_sheet.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) { static int load(lua_State* L) {
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1)); TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
sheet->Load(lua_tostring(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4)); sheet->Load(lua_tostring(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4));
@@ -60,6 +66,7 @@ static int getTileH(lua_State* L) {
} }
static const luaL_Reg tileSheetLib[] = { static const luaL_Reg tileSheetLib[] = {
{"GetTileSheet",getTileSheet},
{"Load",load}, {"Load",load},
{"Unload",unload}, {"Unload",unload},
{"GetXCount",getXCount}, {"GetXCount",getXCount},
+1
View File
@@ -24,6 +24,7 @@
#include "lua/lua.hpp" #include "lua/lua.hpp"
#define TORTUGA_TILE_SHEET_PSEUDO_INDEX "TileSheetPseudoIndex"
#define TORTUGA_TILE_SHEET_NAME "TileSheet" #define TORTUGA_TILE_SHEET_NAME "TileSheet"
LUAMOD_API int openTileSheetAPI(lua_State* L); LUAMOD_API int openTileSheetAPI(lua_State* L);
-40
View File
@@ -1,40 +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 "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
@@ -1,30 +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 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
-130
View File
@@ -1,130 +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.
*/
#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";
}
-58
View File
@@ -1,58 +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 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
-63
View File
@@ -1,63 +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 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
+2 -8
View File
@@ -4,9 +4,9 @@
#RM=del /y #RM=del /y
#CXXFLAGS+=-static-libgcc -static-libstdc++ -g -fno-inline-functions -Wall #CXXFLAGS+=-static-libgcc -static-libstdc++ -g -fno-inline-functions -Wall
#CXXFLAGS+=-static-libgcc -static-libstdc++ CXXFLAGS+=-static-libgcc -static-libstdc++
#export export
OUTDIR=out OUTDIR=out
@@ -15,12 +15,6 @@ all: $(OUTDIR)
$(MAKE) -C server $(MAKE) -C server
$(MAKE) -C client $(MAKE) -C client
debug: export CXXFLAGS+=-g
debug: clean all
release: export CXXFLAGS+=-static-libgcc -static-libstdc++
release: clean all
$(OUTDIR): $(OUTDIR):
mkdir $(OUTDIR) mkdir $(OUTDIR)
-31
View File
@@ -1,31 +0,0 @@
#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
+13 -14
View File
@@ -4,7 +4,15 @@ print("Lua script check")
function math.sqr(x) return x*x end function math.sqr(x) return x*x end
function math.dist(x, y, i, j) return math.sqrt(math.sqr(x - i) + math.sqr(y - j)) end function math.dist(x, y, i, j) return math.sqrt(math.sqr(x - i) + math.sqr(y - j)) end
--tile macros, mapped to the tilesheet --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
local base = 14 local base = 14
local shift = 36 local shift = 36
tiles = { tiles = {
@@ -15,7 +23,9 @@ tiles = {
water = base + shift * 4 water = base + shift * 4
} }
--could set custom generation systems here, that differ from the global generators, etc. --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.
function Region.Create(region) function Region.Create(region)
for i = 1, Region.GetWidth() do for i = 1, Region.GetWidth() do
for j = 1, Region.GetHeight() do for j = 1, Region.GetHeight() do
@@ -32,15 +42,4 @@ function Region.Create(region)
end end
end end
--Get some regions print("Finished the lua script")
--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")
+60
View File
@@ -0,0 +1,60 @@
--[[
--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
-2
View File
@@ -38,7 +38,6 @@
#include "region_api.hpp" #include "region_api.hpp"
#include "region_pager_api.hpp" #include "region_pager_api.hpp"
#include "tile_sheet_api.hpp"
#include "room_api.hpp" #include "room_api.hpp"
#include "room_mgr_api.hpp" #include "room_mgr_api.hpp"
@@ -59,7 +58,6 @@ static const luaL_Reg loadedlibs[] = {
//Tortuga's API //Tortuga's API
{TORTUGA_REGION_NAME, openRegionAPI}, {TORTUGA_REGION_NAME, openRegionAPI},
{TORTUGA_REGION_PAGER_NAME, openRegionPagerAPI}, {TORTUGA_REGION_PAGER_NAME, openRegionPagerAPI},
{TORTUGA_TILE_SHEET_NAME, openTileSheetAPI},
{TORTUGA_ROOM_NAME, openRoomAPI}, {TORTUGA_ROOM_NAME, openRoomAPI},
{TORTUGA_ROOM_MGR_NAME, openRoomMgrAPI}, {TORTUGA_ROOM_MGR_NAME, openRoomMgrAPI},
+1 -13
View File
@@ -21,9 +21,6 @@
*/ */
#include "server_application.hpp" #include "server_application.hpp"
//singletons
#include "config_utility.hpp"
#include <stdexcept> #include <stdexcept>
#include <iostream> #include <iostream>
@@ -31,19 +28,10 @@ using namespace std;
int main(int argc, char** argv) { int main(int argc, char** argv) {
try { try {
//create the singletons ServerApplication app;
ConfigUtility::Create();
ServerApplication::Create();
//call the server's routines
ServerApplication& app = ServerApplication::GetSingleton();
app.Init(argc, argv); app.Init(argc, argv);
app.Proc(); app.Proc();
app.Quit(); app.Quit();
//delete the singletons
ConfigUtility::Delete();
ServerApplication::Delete();
} }
catch(exception& e) { catch(exception& e) {
cerr << "Fatal exception thrown: " << e.what() << endl; cerr << "Fatal exception thrown: " << e.what() << endl;
+5 -8
View File
@@ -31,7 +31,6 @@
//common utilities //common utilities
#include "udp_network_utility.hpp" #include "udp_network_utility.hpp"
#include "config_utility.hpp" #include "config_utility.hpp"
#include "singleton.hpp"
//APIs //APIs
#include "lua/lua.hpp" #include "lua/lua.hpp"
@@ -43,19 +42,17 @@
#include <string> #include <string>
//The main application class //The main application class
class ServerApplication: public Singleton<ServerApplication> { class ServerApplication {
public: public:
//public methods //public methods
ServerApplication() = default;
~ServerApplication() = default;
void Init(int argc, char** argv); void Init(int argc, char** argv);
void Proc(); void Proc();
void Quit(); void Quit();
private: private:
friend Singleton<ServerApplication>;
ServerApplication() = default;
~ServerApplication() = default;
//handle incoming traffic //handle incoming traffic
void HandlePacket(SerialPacket* const); void HandlePacket(SerialPacket* const);
@@ -86,7 +83,7 @@ private:
sqlite3* database = nullptr; sqlite3* database = nullptr;
lua_State* luaState = nullptr; lua_State* luaState = nullptr;
UDPNetworkUtility network; UDPNetworkUtility network;
ConfigUtility& config = ConfigUtility::GetSingleton(); ConfigUtility config;
//simple tables //simple tables
std::map<int, ClientData> clientMap; std::map<int, ClientData> clientMap;