Compare commits

...

36 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
Kayne Ruse 414a0896c9 Began merging the jam branch into the development (read more)
The list of changes committed:

* Removed SimpleRNG
* Added Timer (for debugging)
* Added BoundingBox
* Added floating point snapToBase()
* Added error check to Vector2::Normalize()
* Updated makefiles, project compiles
2014-07-30 21:10:43 +10:00
Kayne Ruse e946a0741d Encapsulated the Character class 2014-07-04 00:55:12 +10:00
Kayne Ruse 839c2af940 Merge branch 'rebuild' into develop, read more
This branch was mostly used for streamlining the code after not seeing it
for a week. It's quite surprising what you realize after taking a break
for a while.
2014-07-03 02:26:42 +10:00
Kayne Ruse f70241cc57 Merge branch 'config' into rebuild 2014-07-03 02:17:44 +10:00
Kayne Ruse 36d30ce39b Moved the scenes into a subdirectory 2014-07-03 02:01:53 +10:00
Kayne Ruse 28d083cba4 Hammered out server-side issues, read more
* Removed the client-only code from CharacterData, including the .cpp file
* Removed CombatManager and EnemyManager instanciation
2014-07-03 01:41:58 +10:00
Kayne Ruse 4dd4b37fc0 It now builds cleanly, but I cut a few code stubs 2014-07-03 00:56:30 +10:00
Kayne Ruse 82b1b589dc Moved some files around 2014-07-03 00:23:43 +10:00
Kayne Ruse bac493c96b Rearranged the debug output 2014-07-02 21:59:26 +10:00
Kayne Ruse d5520e83c6 Merge branch 'collision' into develop, read more
Began working on the collision system. Currently, the collision data which
is set server-side is transferred to the client, and stored in the Region
class. It's incomplete, but it's going well.
2014-07-02 01:10:23 +10:00
Kayne Ruse 93480be685 Solid data is moving from the server to the client, read more
The APIs have access to the solid data, and I fixed a bug: Basically, the
template parameter for std::bitset  expects an integer representing the
number of bits to hold, but I initially misread it as the number of bytes.
This has been corrected.

I've also added a sandy beach to the generated island. I'm tempted to
start working on some simple generators soon.
2014-07-02 00:47:37 +10:00
Kayne Ruse 8ed308e89a Switched the hack for the bitset
I've also added acessors and mutators to the Region and RegionPagerBase
classes.
2014-07-01 22:55:43 +10:00
Kayne Ruse 8df1ecd804 This hack for the collision map was a terrible idea
I'm committing these changes before undoing these, and coding it properly.
2014-07-01 22:04:45 +10:00
Kayne Ruse 8c9d071c7a Minor tweaks 2014-07-01 01:03:03 +10:00
Kayne Ruse deba324449 Merge branch 'api' into develop 2014-06-23 10:46:39 +10:00
Kayne Ruse 95362286f8 Committing the island generator script, and a bugfix
region_api.cpp had a bug, where a glue function's name was used twice. It
was an easy catch, but there was an issue in the new script, where I was
counting from 0 instead of 1. As a result, I was chasing a segfault for 5
hours.
2014-06-23 10:29:39 +10:00
Kayne Ruse f5c58bf5ad Minor tweaks after a failed attempt at metatables 2014-06-23 05:58:54 +10:00
Kayne Ruse 316db43b0a Fixed CreateRoom()'s return type 2014-06-23 04:54:01 +10:00
Kayne Ruse 46ed196bf4 All current lua hooks are being called 2014-06-23 04:10:21 +10:00
Kayne Ruse 64baa63d12 Changed the naming conventions (read more)
I've changed some naming concentions in the lua APIs. I've also made a few
other tweaks, like region_pager_api.cpp delegating to the passed
RegionPager object. This won't explicitly run, becuase there's still a few
more changes needed.
2014-06-23 03:45:30 +10:00
Kayne Ruse e19b6fbc23 Updated RoomManager and the API 2014-06-21 19:02:43 +10:00
Kayne Ruse a64411a567 Filled out the APIs a bit 2014-06-21 18:24:58 +10:00
Kayne Ruse 3662a97475 Added mapType to BaseGenerator 2014-06-21 18:24:01 +10:00
Kayne Ruse 97aaacbc23 Merge branch 'mapgen' into develop 2014-06-21 07:25:46 +10:00
Kayne Ruse 8afd0e7c8a Created a separate API for the RoomManager class 2014-06-21 07:19:51 +10:00
Kayne Ruse 82c776df83 Moved the generators into a subdirectory 2014-06-21 07:00:48 +10:00
Kayne Ruse 924ebc2ee9 Created the generator hierarchy 2014-06-21 06:47:30 +10:00
Kayne Ruse d3bf099a98 Arranged server's source into directories 2014-06-21 05:52:27 +10:00
Kayne Ruse a6de5f9e69 Imported the files from branch 'fixed-map' 2014-06-21 05:28:06 +10:00
Kayne Ruse 618666de43 Renamed the Restart scene to CleanUp 2014-06-15 22:39:10 +10:00
Kayne Ruse 5c74ecdd72 Removed ESC key exit, and tweaked some comments 2014-06-15 22:24:50 +10:00
104 changed files with 1798 additions and 1127 deletions
+1
View File
@@ -15,6 +15,7 @@ Out/
*.o
*.a
*.exe
*.diff
#Shell files
*.bat
+1
View File
@@ -8,6 +8,7 @@ This game is inspired by classic 2D RPGs, as well as more modern sandbox MMOs. T
Tortuga's full documentation can be found in a separate branch, see [Tortuga/docs](https://github.com/Ratstail91/Tortuga/tree/docs).
For Tortuga's primary documentation, please read the [Tortuga Game Design Document](https://github.com/Ratstail91/Tortuga/blob/docs/Tortuga%20Game%20Design%20Document.docx?raw=true).
For a list of known bugs, see the [GitHub bug tracker](https://github.com/Ratstail91/Tortuga/issues).
## External Dependencies
@@ -19,27 +19,23 @@
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "character_data.hpp"
#include "character.hpp"
void CharacterData::Update(double delta) {
void Character::Update(double delta) {
if (motion.x && motion.y) {
origin += motion * delta * CHARACTER_WALKING_MOD;
}
else if (motion != 0) {
origin += motion * delta;
}
#ifdef GRAPHICS
sprite.Update(delta);
#endif
}
#ifdef GRAPHICS
void CharacterData::DrawTo(SDL_Surface* const dest, int camX, int camY) {
void Character::DrawTo(SDL_Surface* const dest, int camX, int camY) {
sprite.DrawTo(dest, origin.x - camX, origin.y - camY);
}
void CharacterData::CorrectSprite() {
void Character::CorrectSprite() {
//NOTE: These must correspond to the sprite sheet in use
if (motion.y > 0) {
sprite.SetYIndex(0);
@@ -63,5 +59,3 @@ void CharacterData::CorrectSprite() {
sprite.SetXIndex(0);
}
}
#endif
+86
View File
@@ -0,0 +1,86 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef CHARACTER_HPP_
#define CHARACTER_HPP_
//components
#include "character_defines.hpp"
#include "vector2.hpp"
#include "bounding_box.hpp"
//graphics
#include "sprite_sheet.hpp"
//std namespace
#include <string>
#include <cmath>
class Character {
public:
Character() = default;
~Character() = default;
void Update(double delta);
//graphics
void DrawTo(SDL_Surface* const, int camX, int camY);
void CorrectSprite();
SpriteSheet* GetSprite() { return &sprite; }
//accessors and mutators
//metadata
int SetOwner(int i) { return owner = i; }
int GetOwner() { return owner; }
std::string SetHandle(std::string s) { return handle = s; }
std::string GetHandle() const { return handle; }
std::string SetAvatar(std::string s) { return avatar = s; }
std::string GetAvatar() const { return avatar; }
//position
Vector2 SetOrigin(Vector2 v) { return origin = v; }
Vector2 GetOrigin() const { return origin; }
Vector2 SetMotion(Vector2 v) { return motion = v; }
Vector2 GetMotion() const { return motion; }
BoundingBox SetBoundingBox(BoundingBox b) { return bounds = b; }
BoundingBox GetBoundingBox() const { return bounds; }
private:
//graphics
SpriteSheet sprite;
//metadata
int owner;
std::string handle;
std::string avatar;
//position
Vector2 origin = {0.0,0.0};
Vector2 motion = {0.0,0.0};
BoundingBox bounds;
};
//tmp
#include <map>
typedef std::map<int, Character> CharacterMap;
#endif
+103 -17
View File
@@ -25,6 +25,7 @@
#include <stdexcept>
#include <chrono>
#include <iostream>
//-------------------------
//Scene headers
@@ -37,31 +38,113 @@
#include "lobby_menu.hpp"
#include "in_world.hpp"
#include "in_combat.hpp"
#include "restart.hpp"
#include "clean_up.hpp"
//-------------------------
//Public access members
//-------------------------
void ClientApplication::Init(int argc, char** argv) {
//load the prerequisites
config.Load("rsc\\config.cfg");
std::cout << "Beginning " << argv[0] << std::endl;
//-------------------------
//Initialize the APIs
//-------------------------
//initialize SDL
if (SDL_Init(SDL_INIT_VIDEO)) {
throw(std::runtime_error("Failed to initialize SDL"));
}
int w = config.Int("client.screen.w");
int h = config.Int("client.screen.h");
int f = config.Bool("client.screen.f") ? SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN : SDL_HWSURFACE|SDL_DOUBLEBUF;
BaseScene::SetScreen(w ? w : 800, h ? h : 600, 0, f);
std::cout << "Initialized SDL" << std::endl;
//initialize SDL_net
if (SDLNet_Init()) {
throw(std::runtime_error("Failed to initialize SDL_net"));
}
network.Open(0);
std::cout << "Initialized SDL_net" << std::endl;
//initialize lua
lua = luaL_newstate();
if (!lua) {
throw(std::runtime_error("Failed to initialize lua"));
}
luaL_openlibs(lua);
std::cout << "Initialized lua" << std::endl;
//run the setup script
if (luaL_dofile(lua, "rsc\\setup.lua")) {
throw(std::runtime_error("Failed to initialize lua's startup script"));
}
std::cout << "Initialized lua's setup script" << std::endl;
//place the config table onto the stack
lua_getglobal(lua, "config");
//-------------------------
//Setup the screen
//-------------------------
//get each field
lua_getfield(lua, -1, "client");
lua_getfield(lua, -1, "screen");
lua_getfield(lua, -1, "width");
lua_getfield(lua, -2, "height");
lua_getfield(lua, -3, "fullscreen");
int w = lua_tointeger(lua, -3);
int h = lua_tointeger(lua, -2);
int f = lua_toboolean(lua, -1);
//pop the screen members
lua_pop(lua, 5);
BaseScene::SetScreen(w ? w : 800, h ? h : 600, 0, f ?
SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN :
SDL_HWSURFACE|SDL_DOUBLEBUF);
std::cout << "Initialized the screen" << std::endl;
//-------------------------
//debug output
//-------------------------
lua_getfield(lua, -1, "debug");
if (lua_toboolean(lua, -1)) {
#define DEBUG_OUTPUT_VAR(x) std::cout << "\t" << #x << ": " << x << std::endl;
std::cout << "Internal sizes:" << std::endl;
DEBUG_OUTPUT_VAR(sizeof(Region::type_t));
DEBUG_OUTPUT_VAR(sizeof(Region));
DEBUG_OUTPUT_VAR(REGION_WIDTH);
DEBUG_OUTPUT_VAR(REGION_HEIGHT);
DEBUG_OUTPUT_VAR(REGION_DEPTH);
DEBUG_OUTPUT_VAR(REGION_SOLID_FOOTPRINT);
DEBUG_OUTPUT_VAR(REGION_FOOTPRINT);
DEBUG_OUTPUT_VAR(PACKET_BUFFER_SIZE);
DEBUG_OUTPUT_VAR(MAX_PACKET_SIZE);
#undef DEBUG_OUTPUT_VAR
}
//pop the debug value
lua_pop(lua, 1);
//-------------------------
//finalize the startup
//-------------------------
//pop the config table
lua_pop(lua, 1);
std::cout << "Startup completed successfully" << std::endl;
//-------------------------
//debugging
//-------------------------
//...
}
void ClientApplication::Proc() {
@@ -88,7 +171,7 @@ void ClientApplication::Proc() {
//simulate game time
while (simTime < realTime) {
//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;
}
@@ -100,9 +183,12 @@ void ClientApplication::Proc() {
}
void ClientApplication::Quit() {
std::cout << "Shutting down" << std::endl;
lua_close(lua);
network.Close();
SDLNet_Quit();
SDL_Quit();
std::cout << "Clean exit" << std::endl;
}
//-------------------------
@@ -115,25 +201,25 @@ void ClientApplication::LoadScene(SceneList sceneIndex) {
//add scene creation calls here
case SceneList::FIRST:
case SceneList::SPLASHSCREEN:
activeScene = new SplashScreen(&config);
activeScene = new SplashScreen(lua);
break;
case SceneList::MAINMENU:
activeScene = new MainMenu(&config);
activeScene = new MainMenu(lua);
break;
case SceneList::OPTIONSMENU:
activeScene = new OptionsMenu(&config);
activeScene = new OptionsMenu(lua);
break;
case SceneList::LOBBYMENU:
activeScene = new LobbyMenu(&config, &network, &clientIndex, &accountIndex);
activeScene = new LobbyMenu(lua, network, characterMap);
break;
case SceneList::INWORLD:
activeScene = new InWorld(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap);
activeScene = new InWorld(lua, network, characterMap);
break;
case SceneList::INCOMBAT:
activeScene = new InCombat(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap, &enemyMap);
activeScene = new InCombat(lua, network, characterMap);
break;
case SceneList::RESTART:
activeScene = new Restart(&config, &network, &clientIndex, &accountIndex, &characterIndex, &combatMap, &characterMap, &enemyMap);
case SceneList::CLEANUP:
activeScene = new CleanUp(lua, network, characterMap);
break;
default:
throw(std::logic_error("Failed to recognize the scene index"));
+5 -8
View File
@@ -25,11 +25,10 @@
#include "scene_list.hpp"
#include "base_scene.hpp"
#include "config_utility.hpp"
#include "udp_network_utility.hpp"
#include "character_data.hpp"
#include "combat_data.hpp"
#include "enemy_data.hpp"
#include "character.hpp"
#include "lua/lua.hpp"
#include <map>
@@ -50,15 +49,13 @@ private:
BaseScene* activeScene = nullptr;
//shared parameters
ConfigUtility config;
lua_State* lua = nullptr;
UDPNetworkUtility network;
int clientIndex = -1;
int accountIndex = -1;
int characterIndex = -1;
std::map<int, CombatData> combatMap;
std::map<int, CharacterData> characterMap;
std::map<int, EnemyData> enemyMap;
CharacterMap characterMap;
};
#endif
+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
View File
@@ -27,7 +27,6 @@
using namespace std;
int main(int argc, char** argv) {
cout << "Beginning client" << endl;
try {
ClientApplication app;
app.Init(argc, argv);
@@ -38,6 +37,5 @@ int main(int argc, char** argv) {
cerr << "Fatal exception thrown: " << e.what() << endl;
return 1;
}
cout << "Clean exit" << endl;
return 0;
}
+4 -3
View File
@@ -1,7 +1,7 @@
#config
INCLUDES+=. ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet ../common/network/serial ../common/ui ../common/utilities
LIBS+=../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) -DGRAPHICS
INCLUDES+=. scenes ../common/debugging ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet ../common/network/serial ../common/ui ../common/utilities
LIBS+=client.a ../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
#source
CXXSRC=$(wildcard *.cpp)
@@ -16,6 +16,7 @@ OUT=$(addprefix $(OUTDIR)/,client)
#targets
all: $(OBJ) $(OUT)
$(MAKE) -C scenes
$(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
$(OBJ): | $(OBJDIR)
+1 -1
View File
@@ -35,7 +35,7 @@ enum class SceneList {
LOBBYMENU,
INWORLD,
INCOMBAT,
RESTART,
CLEANUP,
};
#endif
@@ -19,7 +19,7 @@
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "restart.hpp"
#include "clean_up.hpp"
#include "channels.hpp"
@@ -29,29 +29,43 @@
//Public access members
//-------------------------
Restart::Restart(
ConfigUtility* const argConfig,
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
int* const argAccountIndex,
int* const argCharacterIndex,
std::map<int, CombatData>* argCombatMap,
std::map<int, CharacterData>* argCharacterMap,
std::map<int, EnemyData>* argEnemyMap
):
config(*argConfig),
network(*argNetwork),
clientIndex(*argClientIndex),
accountIndex(*argAccountIndex),
characterIndex(*argCharacterIndex),
combatMap(*argCombatMap),
characterMap(*argCharacterMap),
enemyMap(*argEnemyMap)
CleanUp::CleanUp(lua_State* L, UDPNetworkUtility& aNetwork, CharacterMap& aCharacterMap):
lua(L),
network(aNetwork),
characterMap(aCharacterMap)
{
//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
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
image.LoadSurface(interfaceDir + "button_menu.bmp");
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
backButton.SetImage(&image);
@@ -66,18 +80,13 @@ Restart::Restart(
//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();
}
Restart::~Restart() {
CleanUp::~CleanUp() {
//
}
@@ -85,24 +94,23 @@ Restart::~Restart() {
//Frame loop
//-------------------------
void Restart::Update(double delta) {
void CleanUp::Update(double delta) {
if (std::chrono::steady_clock::now() - startTick > std::chrono::duration<int>(10)) {
QuitEvent();
SetNextScene(SceneList::MAINMENU);
}
while(network.Receive()) {
//EAT INCOMING PACKETS
}
//BUGFIX: Eat incoming packets
while(network.Receive());
}
void Restart::RenderFrame() {
void CleanUp::RenderFrame() {
SDL_FillRect(GetScreen(), 0, 0);
Render(GetScreen());
SDL_Flip(GetScreen());
fps.Calculate();
}
void Restart::Render(SDL_Surface* const screen) {
void CleanUp::Render(SDL_Surface* const screen) {
backButton.DrawTo(screen);
font.DrawStringTo("You have been disconnected.", screen, 50, 30);
}
@@ -111,32 +119,29 @@ void Restart::Render(SDL_Surface* const screen) {
//Event handlers
//-------------------------
void Restart::QuitEvent() {
SetNextScene(SceneList::MAINMENU);
void CleanUp::QuitEvent() {
SetNextScene(SceneList::QUIT);
}
void Restart::MouseMotion(SDL_MouseMotionEvent const& motion) {
void CleanUp::MouseMotion(SDL_MouseMotionEvent const& motion) {
backButton.MouseMotion(motion);
}
void Restart::MouseButtonDown(SDL_MouseButtonEvent const& button) {
void CleanUp::MouseButtonDown(SDL_MouseButtonEvent const& button) {
backButton.MouseButtonDown(button);
}
void Restart::MouseButtonUp(SDL_MouseButtonEvent const& button) {
if (backButton.MouseButtonUp(button) == Button::State::HOVER) {
QuitEvent();
void CleanUp::MouseButtonUp(SDL_MouseButtonEvent const& button) {
if (backButton.MouseButtonUp(button) == Button::State::HOVER &&
button.button & SDL_BUTTON_LMASK) {
SetNextScene(SceneList::MAINMENU);
}
}
void Restart::KeyDown(SDL_KeyboardEvent const& key) {
switch(key.keysym.sym) {
case SDLK_ESCAPE:
QuitEvent();
break;
}
}
void Restart::KeyUp(SDL_KeyboardEvent const& key) {
void CleanUp::KeyDown(SDL_KeyboardEvent const& key) {
//
}
void CleanUp::KeyUp(SDL_KeyboardEvent const& key) {
//
}
@@ -19,45 +19,33 @@
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef RESTART_HPP_
#define RESTART_HPP_
#ifndef CLEANUP_HPP_
#define CLEANUP_HPP_
//network
#include "udp_network_utility.hpp"
//graphics
//graphics & ui
#include "image.hpp"
#include "raster_font.hpp"
#include "button.hpp"
//common
#include "config_utility.hpp"
#include "frame_rate.hpp"
#include "combat_data.hpp"
#include "character_data.hpp"
#include "enemy_data.hpp"
//client
#include "base_scene.hpp"
#include "character.hpp"
//APIs
#include "lua/lua.hpp"
//std namespace
#include <chrono>
class Restart : public BaseScene {
class CleanUp : public BaseScene {
public:
//Public access members
Restart(
ConfigUtility* const argConfig,
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
int* const argAccountIndex,
int* const argCharacterIndex,
std::map<int, CombatData>* argCombatMap,
std::map<int, CharacterData>* argCharacterMap,
std::map<int, EnemyData>* argEnemyMap
);
~Restart();
CleanUp(lua_State*, UDPNetworkUtility&, CharacterMap&);
~CleanUp();
protected:
//Frame loop
@@ -74,20 +62,13 @@ protected:
void KeyUp(SDL_KeyboardEvent const&);
//shared parameters
ConfigUtility& config;
lua_State* lua = nullptr;
UDPNetworkUtility& network;
int& clientIndex;
int& accountIndex;
int& characterIndex;
std::map<int, CombatData>& combatMap;
std::map<int, CharacterData>& characterMap;
std::map<int, EnemyData>& enemyMap;
CharacterMap& characterMap;
//graphics
//graphics & ui
Image image;
RasterFont font;
//UI
Button backButton;
FrameRate fps;
@@ -36,18 +36,14 @@ InCombat::InCombat(
int* const argClientIndex,
int* const argAccountIndex,
int* const argCharacterIndex,
std::map<int, CombatData>* argCombatMap,
std::map<int, CharacterData>* argCharacterMap,
std::map<int, EnemyData>* argEnemyMap
CharacterMap* argCharacterMap
):
config(*argConfig),
network(*argNetwork),
clientIndex(*argClientIndex),
accountIndex(*argAccountIndex),
characterIndex(*argCharacterIndex),
combatMap(*argCombatMap),
characterMap(*argCharacterMap),
enemyMap(*argEnemyMap)
characterMap(*argCharacterMap)
{
/* //setup the utility objects
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
@@ -123,7 +119,7 @@ void InCombat::Render(SDL_Surface* const screen) {
void InCombat::QuitEvent() {
//exit the game AND the server
RequestDisconnect();
SetNextScene(SceneList::MAINMENU);
SetNextScene(SceneList::QUIT);
}
void InCombat::MouseMotion(SDL_MouseMotionEvent const& motion) {
@@ -139,11 +135,7 @@ void InCombat::MouseButtonUp(SDL_MouseButtonEvent const& button) {
}
void InCombat::KeyDown(SDL_KeyboardEvent const& key) {
switch(key.keysym.sym) {
case SDLK_ESCAPE:
QuitEvent();
break;
}
//
}
void InCombat::KeyUp(SDL_KeyboardEvent const& key) {
@@ -167,7 +159,7 @@ void InCombat::HandlePacket(SerialPacket* const argPacket) {
}
void InCombat::HandleDisconnect(SerialPacket* const) {
SetNextScene(SceneList::RESTART);
SetNextScene(SceneList::CLEANUP);
}
//TODO: more network handlers
@@ -201,10 +193,7 @@ void InCombat::SendPlayerUpdate() {
// newPacket.motion = localCharacter->motion;
// newPacket.stats = localCharacter->stats;
//TODO: equipment
//TODO: items
//TODO: buffs
//TODO: debuffs
//TODO: gameplay components: equipment, items, buffs, debuffs
network.SendTo(Channels::SERVER, &newPacket);
}
@@ -34,9 +34,7 @@
#include "config_utility.hpp"
#include "frame_rate.hpp"
#include "combat_data.hpp"
#include "character_data.hpp"
#include "enemy_data.hpp"
#include "character.hpp"
//client
#include "base_scene.hpp"
@@ -50,9 +48,7 @@ public:
int* const argClientIndex,
int* const argAccountIndex,
int* const argCharacterIndex,
std::map<int, CombatData>* argCombatMap,
std::map<int, CharacterData>* argCharacterMap,
std::map<int, EnemyData>* argEnemyMap
CharacterMap* argCharacterMap
);
~InCombat();
@@ -75,14 +71,12 @@ protected:
//Network handlers
void HandlePacket(SerialPacket* const);
void HandleDisconnect(SerialPacket* const);
//TODO: more network handlers
//Server control
void RequestSynchronize();
void SendPlayerUpdate();
void RequestDisconnect();
void RequestShutdown();
//TODO: more
//shared parameters
ConfigUtility& config;
@@ -90,9 +84,7 @@ protected:
int& clientIndex;
int& accountIndex;
int& characterIndex;
std::map<int, CombatData>& combatMap;
std::map<int, CharacterData>& characterMap;
std::map<int, EnemyData>& enemyMap;
CharacterMap& characterMap;
//graphics
//TODO: graphics
+173 -108
View File
@@ -24,9 +24,10 @@
#include "channels.hpp"
#include "utility.hpp"
#include <stdexcept>
#include <algorithm>
#include <cmath>
#include <stdexcept>
#include <iostream>
//-------------------------
//Public access members
@@ -38,17 +39,69 @@ InWorld::InWorld(
int* const argClientIndex,
int* const argAccountIndex,
int* const argCharacterIndex,
std::map<int, CombatData>* argCombatMap,
std::map<int, CharacterData>* argCharacterMap
CharacterMap* argCharacterMap
):
config(*argConfig),
network(*argNetwork),
clientIndex(*argClientIndex),
accountIndex(*argAccountIndex),
characterIndex(*argCharacterIndex),
combatMap(*argCombatMap),
characterMap(*argCharacterMap)
{
//register the pager
lua_pushstring(lua, TORTUGA_REGION_PAGER_PSEUDO_INDEX);
lua_pushlightuserdata(lua, &pager);
lua_settable(L, LUA_REGISTRYINDEX);
//register the tilesheet
lua_pushstring(lua, TORTUGA_TILE_SHEET_PSEUDO_INDEX);
lua_pushlightuserdata(lua, &tileSheet);
lua_settable(L, LUA_REGISTRYINDEX);
//setup the component objecrs
pager.SetLuaState(lua);
//get the config info
lua_getglobal(lua, "config");
lua_getfield(lua, -1, "dir");
lua_getfield(lua, -1, "fonts");
std::string fonts = lua_tostring(lua, -1);
lua_getfield(lua, -2, "interface");
std::string interface = lua_tostring(lua, -1);
lua_getfield(lua, -3, "sprites");
std::string sprites = lua_tostring(lua, -1);
lua_getfield(lua, -4, "scripts");
std::string scripts = lua_tostring(lua, -1);
lua_pop(lua, 6);
//run the additional scripts
if (luaL_dofile(lua, (scripts + "in_world.lua").c_str())) {
throw(std::runtime_error(std::string() + "Failed to run in_world.lua: " + lua_tostring(lua, -1) ));
}
//setup the utility objects
buttonImage.LoadSurface(interface + "button_menu.bmp");
buttonImage.SetClipH(buttonImage.GetClipH()/3);
font.LoadSurface(fonts + "pk_white_8.bmp");
//pass the utility objects
backButton.SetImage(&buttonImage);
backButton.SetFont(&font);
//set the button positions
backButton.SetX(50);
backButton.SetY(50 + buttonImage.GetClipH() * 0);
//set the button texts
backButton.SetText("Back");
//entities
character.GetSprite()->LoadSurface(sprites + "elliot2.bmp", 4, 4);
character.SetBoundingBox({0, 0,
character.GetSprite()->GetImage()->GetClipW(),
character.GetSprite()->GetImage()->GetClipH()
});
//-------------------------
//setup the utility objects
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
buttonImage.SetClipH(buttonImage.GetClipH()/3);
@@ -82,7 +135,13 @@ 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);
}
//-------------------------
@@ -106,10 +165,34 @@ void InWorld::Update(double delta) {
it.second.Update(delta);
}
//TODO: Check collisions here
//check for collisions with the map
BoundingBox wallBounds = {0, 0, tileSheet.GetTileW(), tileSheet.GetTileH()};
const int xCount = character.GetBoundingBox().w / wallBounds.w + 1;
const int yCount = character.GetBoundingBox().h / wallBounds.h + 1;
for (int i = -1; i <= xCount; ++i) {
for (int j = -1; j <= yCount; ++j) {
//set the wall's position
wallBounds.x = wallBounds.w * i + snapToBase((double)wallBounds.w, character.GetOrigin().x);
wallBounds.y = wallBounds.h * j + snapToBase((double)wallBounds.h, character.GetOrigin().y);
if (!pager.GetSolid(wallBounds.x / wallBounds.w, wallBounds.y / wallBounds.h)) {
continue;
}
if ((character.GetOrigin() + character.GetBoundingBox()).CheckOverlap(wallBounds)) {
character.SetOrigin(character.GetOrigin() - (character.GetMotion() * delta));
character.SetMotion({0,0});
character.CorrectSprite();
}
}
}
//update the camera
if(localCharacter) {
camera.x = localCharacter->origin.x - camera.marginX;
camera.y = localCharacter->origin.y - camera.marginY;
camera.x = localCharacter->GetOrigin().x - camera.marginX;
camera.y = localCharacter->GetOrigin().y - camera.marginY;
}
//check the map
@@ -135,7 +218,7 @@ void InWorld::Render(SDL_Surface* const screen) {
//draw characters
for (auto& it : characterMap) {
//TODO: drawing order according to Y origin
//BUG: #29 drawing order according to Y origin
it.second.DrawTo(screen, camera.x, camera.y);
}
@@ -152,7 +235,7 @@ void InWorld::Render(SDL_Surface* const screen) {
void InWorld::QuitEvent() {
//exit the game AND the server
RequestDisconnect();
SetNextScene(SceneList::MAINMENU);
SetNextScene(SceneList::QUIT);
}
void InWorld::MouseMotion(SDL_MouseMotionEvent const& motion) {
@@ -175,82 +258,60 @@ void InWorld::MouseButtonUp(SDL_MouseButtonEvent const& button) {
}
void InWorld::KeyDown(SDL_KeyboardEvent const& key) {
switch(key.keysym.sym) {
case SDLK_ESCAPE: {
QuitEvent();
}
break;
//player movement
case SDLK_LEFT:
if (localCharacter) {
localCharacter->motion.x -= CHARACTER_WALKING_SPEED;
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
break;
case SDLK_RIGHT:
if (localCharacter) {
localCharacter->motion.x += CHARACTER_WALKING_SPEED;
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
break;
case SDLK_UP:
if (localCharacter) {
localCharacter->motion.y -= CHARACTER_WALKING_SPEED;
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
break;
case SDLK_DOWN:
if (localCharacter) {
localCharacter->motion.y += CHARACTER_WALKING_SPEED;
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
break;
if (!localCharacter) {
return;
}
//player movement
Vector2 motion = localCharacter->GetMotion();
switch(key.keysym.sym) {
case SDLK_LEFT:
motion.x -= CHARACTER_WALKING_SPEED;
break;
case SDLK_RIGHT:
motion.x += CHARACTER_WALKING_SPEED;
break;
case SDLK_UP:
motion.y -= CHARACTER_WALKING_SPEED;
break;
case SDLK_DOWN:
motion.y += CHARACTER_WALKING_SPEED;
break;
default:
return;
}
localCharacter->SetMotion(motion);
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
void InWorld::KeyUp(SDL_KeyboardEvent const& key) {
switch(key.keysym.sym) {
//player movement
case SDLK_LEFT:
if (localCharacter) {
localCharacter->motion.x += CHARACTER_WALKING_SPEED;
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
break;
case SDLK_RIGHT:
if (localCharacter) {
localCharacter->motion.x -= CHARACTER_WALKING_SPEED;
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
break;
case SDLK_UP:
if (localCharacter) {
localCharacter->motion.y += CHARACTER_WALKING_SPEED;
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
break;
case SDLK_DOWN:
if (localCharacter) {
localCharacter->motion.y -= CHARACTER_WALKING_SPEED;
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
break;
if (!localCharacter) {
return;
}
//player movement
Vector2 motion = localCharacter->GetMotion();
switch(key.keysym.sym) {
//NOTE: The use of min/max here are to prevent awkward movements
case SDLK_LEFT:
motion.x = std::min(motion.x + CHARACTER_WALKING_SPEED, 0.0);
break;
case SDLK_RIGHT:
motion.x = std::max(motion.x - CHARACTER_WALKING_SPEED, 0.0);
break;
case SDLK_UP:
motion.y = std::min(motion.y + CHARACTER_WALKING_SPEED, 0.0);
break;
case SDLK_DOWN:
motion.y = std::max(motion.y - CHARACTER_WALKING_SPEED, 0.0);
break;
default:
return;
}
localCharacter->SetMotion(motion);
localCharacter->CorrectSprite();
SendPlayerUpdate();
}
//-------------------------
@@ -282,7 +343,7 @@ void InWorld::HandlePacket(SerialPacket* const argPacket) {
}
void InWorld::HandleDisconnect(SerialPacket* const argPacket) {
SetNextScene(SceneList::RESTART);
SetNextScene(SceneList::CLEANUP);
}
void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) {
@@ -291,36 +352,41 @@ void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) {
}
//create the character object
CharacterData& character = characterMap[argPacket->characterIndex];
Character& newCharacter = characterMap[argPacket->characterIndex];
//set the members
character.handle = argPacket->handle;
character.avatar = argPacket->avatar;
character.sprite.LoadSurface(config["dir.sprites"] + character.avatar, 4, 4);
character.roomIndex = argPacket->roomIndex;
character.origin = argPacket->origin;
character.motion = argPacket->motion;
character.stats = argPacket->stats;
//fill out the character's members
newCharacter.SetHandle(argPacket->handle);
newCharacter.SetAvatar(argPacket->avatar);
character.CorrectSprite();
newCharacter.GetSprite()->LoadSurface(config["dir.sprites"] + newCharacter.GetAvatar(), 4, 4);
newCharacter.SetOrigin(argPacket->origin);
newCharacter.SetMotion(argPacket->motion);
(*newCharacter.GetStats()) = argPacket->stats;
//bookkeeping code
newCharacter.CorrectSprite();
//catch this client's player object
if (argPacket->accountIndex == accountIndex && !localCharacter) {
characterIndex = argPacket->characterIndex;
localCharacter = &character;
localCharacter = &newCharacter;
//setup the camera
//TODO: move this?
camera.width = GetScreen()->w;
camera.height = GetScreen()->h;
//center on the player's character
camera.marginX = (GetScreen()->w / 2 - localCharacter->sprite.GetImage()->GetClipW() / 2);
camera.marginY = (GetScreen()->h / 2 - localCharacter->sprite.GetImage()->GetClipH() / 2);
camera.marginX = (GetScreen()->w / 2 - localCharacter->GetSprite()->GetImage()->GetClipW() / 2);
camera.marginY = (GetScreen()->h / 2 - localCharacter->GetSprite()->GetImage()->GetClipH() / 2);
}
}
void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
//TODO: authenticate when own character is being deleted (linked to a TODO in the server)
//catch this client's player object
if (argPacket->characterIndex == characterIndex) {
characterIndex = -1;
@@ -332,17 +398,17 @@ void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
void InWorld::HandleCharacterUpdate(CharacterPacket* const argPacket) {
if (characterMap.find(argPacket->characterIndex) == characterMap.end()) {
std::cout << "Warning: HandleCharacterUpdate() is passing to HandleCharacterNew()" << std::endl;
HandleCharacterNew(argPacket);
return;
}
CharacterData& character = characterMap[argPacket->characterIndex];
Character& character = characterMap[argPacket->characterIndex];
//other characters moving
if (argPacket->characterIndex != characterIndex) {
character.roomIndex = argPacket->roomIndex;
character.origin = argPacket->origin;
character.motion = argPacket->motion;
character.SetOrigin(argPacket->origin);
character.SetMotion(argPacket->motion);
character.CorrectSprite();
}
}
@@ -369,6 +435,8 @@ void InWorld::RequestSynchronize() {
newPacket.clientIndex = clientIndex;
newPacket.accountIndex = accountIndex;
//TODO: location, range for sync request
network.SendTo(Channels::SERVER, &newPacket);
}
@@ -379,17 +447,14 @@ void InWorld::SendPlayerUpdate() {
newPacket.type = SerialPacketType::CHARACTER_UPDATE;
newPacket.characterIndex = characterIndex;
//handle, avatar
//NOTE: omitting the handle and avatar here
newPacket.accountIndex = accountIndex;
newPacket.roomIndex = localCharacter->roomIndex;
newPacket.origin = localCharacter->origin;
newPacket.motion = localCharacter->motion;
newPacket.stats = localCharacter->stats;
newPacket.roomIndex = 0; //TODO: room index
newPacket.origin = localCharacter->GetOrigin();
newPacket.motion = localCharacter->GetMotion();
newPacket.stats = *localCharacter->GetStats();
//TODO: equipment
//TODO: items
//TODO: buffs
//TODO: debuffs
//TODO: gameplay components: equipment, items, buffs, debuffs
network.SendTo(Channels::SERVER, &newPacket);
}
@@ -443,7 +508,7 @@ void InWorld::UpdateMap() {
//prune distant regions
for (std::list<Region>::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); /* EMPTY */) {
//check if the region is outside off this area
//check if the region is outside of this area
if (it->GetX() < xStart || it->GetX() > xEnd || it->GetY() < yStart || it->GetY() > yEnd) {
//clunky, but the alternative was time consuming
@@ -22,27 +22,28 @@
#ifndef INWORLD_HPP_
#define INWORLD_HPP_
//maps
#include "region_pager_base.hpp"
//map stuff
#include "tile_sheet.hpp"
#include "region_pager_lua.hpp"
//networking
#include "udp_network_utility.hpp"
//graphics
//graphics & ui
#include "image.hpp"
#include "raster_font.hpp"
#include "button.hpp"
#include "tile_sheet.hpp"
//common
#include "config_utility.hpp"
//utilities
#include "frame_rate.hpp"
#include "combat_data.hpp"
#include "character_data.hpp"
#include "timer.hpp"
//client
#include "base_scene.hpp"
#include "character.hpp"
//APIs
#include "lua/lua.hpp"
//STL
#include <map>
@@ -56,8 +57,7 @@ public:
int* const argClientIndex,
int* const argAccountIndex,
int* const argCharacterIndex,
std::map<int, CombatData>* argCombatMap,
std::map<int, CharacterData>* argCharacterMap
CharacterMap* argCharacterMap
);
~InWorld();
@@ -95,14 +95,14 @@ protected:
//utilities
void UpdateMap();
//TODO: Streamline this with lua
//shared parameters
ConfigUtility& config;
UDPNetworkUtility& network;
int& clientIndex;
int& accountIndex;
int& characterIndex;
std::map<int, CombatData>& combatMap;
std::map<int, CharacterData>& characterMap;
CharacterMap& characterMap;
//graphics
Image buttonImage;
@@ -117,14 +117,15 @@ protected:
Button shutDownButton;
//TODO: Review the camera
struct {
int x = 0, y = 0;
int width = 0, height = 0;
int marginX = 0, marginY = 0;
} camera;
struct {
int x, y;
}origin, margin;
}camera;
FrameRate fps;
//game
CharacterData* localCharacter = nullptr;
Character* localCharacter = nullptr;
};
#endif
@@ -30,21 +30,25 @@
//Public access members
//-------------------------
LobbyMenu::LobbyMenu(
ConfigUtility* const argConfig,
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
int* const argAccountIndex
):
config(*argConfig),
network(*argNetwork),
clientIndex(*argClientIndex),
accountIndex(*argAccountIndex)
LobbyMenu::LobbyMenu(lua_State* L, UDPNetworkUtility& aNetwork):
lua(L),
network(aNetwork)
{
//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(config["dir.interface"] + "button_menu.bmp");
image.LoadSurface(interfaceDir + "button_menu.bmp");
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
search.SetImage(&image);
@@ -69,6 +73,9 @@ LobbyMenu::LobbyMenu(
//set the server list's position
listBox = {300, 50, 200, font.GetCharH()};
//BUGFIX: Eat incoming packets
while(network.Receive());
}
LobbyMenu::~LobbyMenu() {
@@ -85,11 +92,11 @@ void LobbyMenu::FrameStart() {
void LobbyMenu::Update(double delta) {
//suck in and process all waiting packets
SerialPacket* packetBuffer = static_cast<SerialPacket*>(malloc(MAX_PACKET_SIZE));
SerialPacket* packetBuffer = new SerialPacket();
while(network.Receive(packetBuffer)) {
HandlePacket(packetBuffer);
}
free(static_cast<void*>(packetBuffer));
delete packetBuffer;
}
void LobbyMenu::FrameEnd() {
@@ -145,26 +152,44 @@ 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(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
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, config["client.username"].c_str(), PACKET_STRING_SIZE);
strncpy(packet.username, lua_tostring(lua, -1), 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) {
@@ -184,14 +209,13 @@ void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
else {
selection = nullptr;
}
//clear the parameters
lua_pop(lua, 1);
}
void LobbyMenu::KeyDown(SDL_KeyboardEvent const& key) {
switch(key.keysym.sym) {
case SDLK_ESCAPE:
SetNextScene(SceneList::MAINMENU);
break;
}
//
}
void LobbyMenu::KeyUp(SDL_KeyboardEvent const& key) {
@@ -205,10 +229,10 @@ void LobbyMenu::KeyUp(SDL_KeyboardEvent const& key) {
void LobbyMenu::HandlePacket(SerialPacket* const argPacket) {
switch(argPacket->type) {
case SerialPacketType::BROADCAST_RESPONSE:
HandleBroadcastResponse(static_cast<ServerPacket*>(argPacket));
HandleBroadcastResponse(dynamic_cast<ServerPacket*>(argPacket));
break;
case SerialPacketType::JOIN_RESPONSE:
HandleJoinResponse(static_cast<ClientPacket*>(argPacket));
HandleJoinResponse(dynamic_cast<ClientPacket*>(argPacket));
break;
//handle errors
default:
@@ -225,7 +249,7 @@ void LobbyMenu::HandleBroadcastResponse(ServerPacket* const argPacket) {
server.playerCount = argPacket->playerCount;
server.version = argPacket->version;
//NOTE: Check compatibility here
//Checking compatibility
server.compatible = server.version == NETWORK_VERSION;
//push
@@ -233,16 +257,25 @@ void LobbyMenu::HandleBroadcastResponse(ServerPacket* const argPacket) {
}
void LobbyMenu::HandleJoinResponse(ClientPacket* const argPacket) {
clientIndex = argPacket->clientIndex;
accountIndex = argPacket->accountIndex;
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");
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, config["client.handle"].c_str(), PACKET_STRING_SIZE);
strncpy(newPacket.avatar, config["client.avatar"].c_str(), PACKET_STRING_SIZE);
newPacket.accountIndex = accountIndex;
strncpy(newPacket.handle, lua_tostring(lua, -2), PACKET_STRING_SIZE);
strncpy(newPacket.avatar, lua_tostring(lua, -1), PACKET_STRING_SIZE);
newPacket.accountIndex = argPacket->accountIndex;
network.SendTo(Channels::SERVER, &newPacket);
lua_pop(lua, 4);
}
@@ -28,24 +28,21 @@
#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(
ConfigUtility* const argConfig,
UDPNetworkUtility* const argNetwork,
int* const argClientIndex,
int* const argAccountIndex
);
LobbyMenu(lua_State*, UDPNetworkUtility&);
~LobbyMenu();
protected:
@@ -68,10 +65,8 @@ protected:
void HandleJoinResponse(ClientPacket* const);
//shared parameters
ConfigUtility& config;
lua_State* lua = nullptr;
UDPNetworkUtility& network;
int& clientIndex;
int& accountIndex;
//members
Image image;
@@ -92,7 +87,7 @@ protected:
std::vector<ServerInformation> serverInfo;
//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;
ServerInformation* selection = nullptr;
};
@@ -25,13 +25,22 @@
//Public access members
//-------------------------
MainMenu::MainMenu(ConfigUtility* const argConfig):
config(*argConfig)
{
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);
//setup the utility objects
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
image.LoadSurface(interfaceDir + "button_menu.bmp");
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
startButton.SetImage(&image);
@@ -102,22 +111,19 @@ void MainMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) {
void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
if (startButton.MouseButtonUp(button) == Button::State::HOVER) {
SetNextScene(SceneList::LOBBYMENU);
SetNextScene(SceneList::INWORLD);
}
if (optionsButton.MouseButtonUp(button) == Button::State::HOVER) {
SetNextScene(SceneList::OPTIONSMENU);
}
if (quitButton.MouseButtonUp(button) == Button::State::HOVER) {
if (quitButton.MouseButtonUp(button) == Button::State::HOVER &&
button.button & SDL_BUTTON_LMASK) {
QuitEvent();
}
}
void MainMenu::KeyDown(SDL_KeyboardEvent const& key) {
switch(key.keysym.sym) {
case SDLK_ESCAPE:
QuitEvent();
break;
}
//
}
void MainMenu::KeyUp(SDL_KeyboardEvent const& key) {
@@ -24,15 +24,16 @@
#include "base_scene.hpp"
#include "config_utility.hpp"
#include "image.hpp"
#include "raster_font.hpp"
#include "button.hpp"
#include "lua/lua.hpp"
class MainMenu : public BaseScene {
public:
//Public access members
MainMenu(ConfigUtility* const);
MainMenu(lua_State* L);
~MainMenu();
protected:
@@ -50,7 +51,7 @@ protected:
void KeyUp(SDL_KeyboardEvent const&);
//shared parameters
ConfigUtility& config;
lua_State* lua = nullptr;
//members
Image image;
+37
View File
@@ -0,0 +1,37 @@
#config
INCLUDES+=. .. ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/network/packet ../../common/network/serial ../../common/ui ../../common/utilities
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
#source
CXXSRC=$(wildcard *.cpp)
#objects
OBJDIR=obj
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
#output
OUTDIR=..
OUT=$(addprefix $(OUTDIR)/,client.a)
#targets
all: $(OBJ) $(OUT)
ar -crs $(OUT) $(OBJ)
$(OBJ): | $(OBJDIR)
$(OUT): | $(OUTDIR)
$(OBJDIR):
mkdir $(OBJDIR)
$(OUTDIR):
mkdir $(OUTDIR)
$(OBJDIR)/%.o: %.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
clean:
$(RM) *.o *.a *.exe
rebuild: clean all
@@ -25,13 +25,22 @@
//Public access members
//-------------------------
OptionsMenu::OptionsMenu(ConfigUtility* const argConfig):
config(*argConfig)
{
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);
//setup the utility objects
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
image.LoadSurface(interfaceDir + "button_menu.bmp");
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
backButton.SetImage(&image);
@@ -84,17 +93,14 @@ void OptionsMenu::MouseButtonDown(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);
}
}
void OptionsMenu::KeyDown(SDL_KeyboardEvent const& key) {
switch(key.keysym.sym) {
case SDLK_ESCAPE:
SetNextScene(SceneList::MAINMENU);
break;
}
//
}
void OptionsMenu::KeyUp(SDL_KeyboardEvent const& key) {
@@ -24,16 +24,17 @@
#include "base_scene.hpp"
#include "config_utility.hpp"
#include "image.hpp"
#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(ConfigUtility* const);
OptionsMenu(lua_State* L);
~OptionsMenu();
protected:
@@ -51,7 +52,7 @@ protected:
void KeyUp(SDL_KeyboardEvent const&);
//shared parameters
ConfigUtility& config;
lua_State* lua = nullptr;
//members
Image image;
@@ -21,14 +21,21 @@
*/
#include "splash_screen.hpp"
#include <string>
//-------------------------
//Public access members
//-------------------------
SplashScreen::SplashScreen(ConfigUtility* const argConfig):
config(*argConfig)
{
logo.LoadSurface(config["dir.logos"] + "krstudios.bmp");
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");
startTick = std::chrono::steady_clock::now();
}
@@ -24,15 +24,16 @@
#include "base_scene.hpp"
#include "config_utility.hpp"
#include "image.hpp"
#include "lua/lua.hpp"
#include <chrono>
class SplashScreen : public BaseScene {
public:
//Public access members
SplashScreen(ConfigUtility* const);
SplashScreen(lua_State* L);
~SplashScreen();
protected:
@@ -41,7 +42,7 @@ protected:
void Render(SDL_Surface* const);
//shared parameters
ConfigUtility& config;
lua_State* lua = nullptr;
//members
std::chrono::steady_clock::time_point startTick;
+37
View File
@@ -0,0 +1,37 @@
#config
INCLUDES+=.
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
#source
CXXSRC=$(wildcard *.cpp)
#objects
OBJDIR=obj
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
#output
OUTDIR=..
OUT=$(addprefix $(OUTDIR)/,libcommon.a)
#targets
all: $(OBJ) $(OUT)
ar -crs $(OUT) $(OBJ)
$(OBJ): | $(OBJDIR)
$(OUT): | $(OUTDIR)
$(OBJDIR):
mkdir $(OBJDIR)
$(OUTDIR):
mkdir $(OUTDIR)
$(OBJDIR)/%.o: %.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
clean:
$(RM) *.o *.a *.exe
rebuild: clean all
@@ -19,16 +19,11 @@
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "enemy_factory_generic.hpp"
#include "timer.hpp"
EnemyFactoryGeneric::EnemyFactoryGeneric() : EnemyFactoryInterface() {
//EMPTY
}
EnemyFactoryGeneric::~EnemyFactoryGeneric() noexcept {
//EMPTY
}
void EnemyFactoryGeneric::Generate(std::list<EnemyData>* container) {
//TODO: fill this out
std::ostream& operator<<(std::ostream& os, Timer& t) {
os << t.GetName() << ": ";
os << std::chrono::duration_cast<std::chrono::nanoseconds>(t.GetTime()).count();
os << "ns";
return os;
}
@@ -19,30 +19,36 @@
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef ENEMYFACTORYINTERFACE_HPP_
#define ENEMYFACTORYINTERFACE_HPP_
#ifndef TIMER_HPP_
#define TIMER_HPP_
#include "enemy_data.hpp"
#include "room_data.hpp"
#include <chrono>
#include <string>
#include <ostream>
#include <list>
//NOTE: Based on biome, world difficulty, etc.
class EnemyFactoryInterface {
class Timer {
public:
EnemyFactoryInterface() = default;
virtual ~EnemyFactoryInterface() = default;
typedef std::chrono::high_resolution_clock Clock;
virtual void Generate(std::list<EnemyData>* container) = 0;
Timer() = default;
Timer(std::string s) : name(s), start(Clock::now()) {};
~Timer() = default;
//control the difficulty of the room
RoomData::RoomType SetType(RoomData::RoomType t) { return type = t; }
int SetDifficulty(int d) { return difficulty = d; }
RoomData::RoomType GetType() { return type; }
int GetDifficulty() { return difficulty; }
protected:
RoomData::RoomType type;
int difficulty;
inline void Start() { start = Clock::now(); }
inline void Stop() { time = Clock::now() - start; }
//accessors and mutators
Clock::duration GetTime() { return time; }
std::string SetName(std::string s) { return name = s; }
std::string GetName() { return name; }
private:
std::string name;
Clock::time_point start;
Clock::duration time;
};
std::ostream& operator<<(std::ostream& os, Timer& t);
#endif
+35
View File
@@ -0,0 +1,35 @@
/* 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 CHARACTERDEFINES_HPP_
#define CHARACTERDEFINES_HPP_
#include <cmath>
//the speeds that the characters move
constexpr double CHARACTER_WALKING_SPEED = 140.0;
constexpr double CHARACTER_WALKING_MOD = 1.0/sqrt(2.0);
//the bounding boxes for the characters
constexpr double CHARACTER_BOUNDS_WIDTH = 32.0;
constexpr double CHARACTER_BOUNDS_HEIGHT = 32.0;
#endif
@@ -19,12 +19,16 @@
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef CHECKBOUNDS_HPP_
#define CHECKBOUNDS_HPP_
#ifndef COMBATDEFINES_HPP_
#define COMBATDEFINES_HPP_
#include "vector2.hpp"
#define COMBAT_MAX_CHARACTERS 16
#define COMBAT_MAX_ENEMIES 16
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);
enum class TerrainType {
NONE = 0,
GRASSLANDS,
//etc.
};
#endif
+2 -2
View File
@@ -1,7 +1,7 @@
#config
INCLUDES+=. ../utilities ../graphics
INCLUDES+=.
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) -DGRAPHICS
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
#source
CXXSRC=$(wildcard *.cpp)
+1
View File
@@ -1,4 +1,5 @@
all:
$(MAKE) -C debugging
$(MAKE) -C gameplay
$(MAKE) -C graphics
$(MAKE) -C map
+1 -1
View File
@@ -1,5 +1,5 @@
#config
INCLUDES+=. ../utilities
INCLUDES+=. ../utilities ../graphics
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
+9
View File
@@ -35,6 +35,7 @@ Region::Region(int argX, int argY): x(argX), y(argY) {
Region::Region(Region const& rhs): x(rhs.x), y(rhs.y) {
memcpy(tiles, rhs.tiles, REGION_WIDTH*REGION_HEIGHT*REGION_DEPTH*sizeof(type_t));
solid = rhs.solid;
}
Region::type_t Region::SetTile(int x, int y, int z, type_t v) {
@@ -44,3 +45,11 @@ Region::type_t Region::SetTile(int x, int y, int z, type_t v) {
Region::type_t Region::GetTile(int x, int y, int z) {
return tiles[x][y][z];
}
bool Region::SetSolid(int x, int y, bool b) {
return solid[x * REGION_WIDTH + y] = b;
}
bool Region::GetSolid(int x, int y) {
return solid[x * REGION_WIDTH + y];
}
+16
View File
@@ -22,10 +22,17 @@
#ifndef REGION_HPP_
#define REGION_HPP_
#include <bitset>
#include <cmath>
//the region's storage format
constexpr int REGION_WIDTH = 20;
constexpr int REGION_HEIGHT = 20;
constexpr int REGION_DEPTH = 3;
//the size of the solid map
constexpr int REGION_SOLID_FOOTPRINT = ceil(REGION_WIDTH * REGION_HEIGHT / 8.0);
class Region {
public:
typedef unsigned char type_t;
@@ -38,14 +45,23 @@ public:
type_t SetTile(int x, int y, int z, type_t v);
type_t GetTile(int x, int y, int z);
bool SetSolid(int x, int y, bool b);
bool GetSolid(int x, int y);
//accessors
int GetX() const { return x; }
int GetY() const { return y; }
std::bitset<REGION_WIDTH*REGION_HEIGHT>* GetSolidBitset() { return &solid; }
private:
const int x;
const int y;
type_t tiles[REGION_WIDTH][REGION_HEIGHT][REGION_DEPTH];
std::bitset<REGION_WIDTH*REGION_HEIGHT> solid;
};
//the memory footprint of the tile and solid data; not including any metadata
constexpr int REGION_FOOTPRINT = REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t) + REGION_SOLID_FOOTPRINT;
#endif
+34 -18
View File
@@ -37,6 +37,20 @@ static int getTile(lua_State* L) {
return 1;
}
static int setSolid(lua_State* L) {
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
bool ret = region->SetSolid(lua_tointeger(L, 2)-1, lua_tointeger(L, 3)-1, lua_toboolean(L, 4));
lua_pushboolean(L, ret);
return 1;
}
static int getSolid(lua_State* L) {
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
bool ret = region->GetSolid(lua_tointeger(L, 2)-1, lua_tointeger(L, 3)-1);
lua_pushboolean(L, ret);
return 1;
}
static int getX(lua_State* L) {
Region* region = reinterpret_cast<Region*>(lua_touserdata(L, 1));
lua_pushinteger(L, region->GetX());
@@ -65,42 +79,44 @@ static int getDepth(lua_State* L) {
}
static int load(lua_State* L) {
//TODO: fill this
//EMPTY
lua_pushboolean(L, false);
return 1;
}
static int save(lua_State* L) {
//TODO: fill this
//EMPTY
return 0;
}
static int create(lua_State* L) {
//TODO: fill this
//EMPTY
return 0;
}
static int unload(lua_State* L) {
//TODO: fill this
//EMPTY
return 0;
}
static const luaL_Reg regionlib[] = {
{"settile",setTile},
{"gettile",getTile},
{"getx",getX},
{"gety",getY},
{"getwidth",getWidth},
{"getheight",getHeight},
{"getdepth",getDepth},
{"load",load},
{"save",save},
{"create",create},
{"unload",unload},
static const luaL_Reg regionLib[] = {
{"SetTile",setTile},
{"GetTile",getTile},
{"SetSolid",setSolid},
{"GetSolid",getSolid},
{"GetX",getX},
{"GetY",getY},
{"GetWidth",getWidth},
{"GetHeight",getHeight},
{"GetDepth",getDepth},
{"Load",load},
{"Save",save},
{"Create",create},
{"Unload",unload},
{nullptr, nullptr}
};
LUAMOD_API int luaopen_regionapi(lua_State* L) {
luaL_newlib(L, regionlib);
LUAMOD_API int openRegionAPI(lua_State* L) {
luaL_newlib(L, regionLib);
return 1;
}
+2 -2
View File
@@ -24,7 +24,7 @@
#include "lua/lua.hpp"
#define LUA_REGIONLIBNAME "region"
LUAMOD_API int luaopen_regionapi(lua_State* L);
#define TORTUGA_REGION_NAME "Region"
LUAMOD_API int openRegionAPI(lua_State* L);
#endif
@@ -19,14 +19,20 @@
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "pager_api.hpp"
#include "region_pager_api.hpp"
#include "region_pager_lua.hpp"
#include "region.hpp"
#include <stdexcept>
#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) {
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
int ret = pager->SetTile(lua_tointeger(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4), lua_tointeger(L, 5));
@@ -41,6 +47,20 @@ static int getTile(lua_State* L) {
return 1;
}
static int setSolid(lua_State* L) {
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
bool ret = pager->SetSolid(lua_tointeger(L, 2), lua_tointeger(L, 3), lua_toboolean(L, 4));
lua_pushboolean(L, ret);
return 1;
}
static int getSolid(lua_State* L) {
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
bool ret = pager->GetSolid(lua_tointeger(L, 2), lua_tointeger(L, 3));
lua_pushboolean(L, ret);
return 1;
}
static int getRegion(lua_State* L) {
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
@@ -48,109 +68,48 @@ static int getRegion(lua_State* L) {
return 1;
}
static int setDirectory(lua_State* L) {
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
std::string s = pager->SetDirectory(lua_tostring(L, 2));
lua_pushstring(L, s.c_str());
return 1;
}
static int getDirectory(lua_State* L) {
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
std::string s = pager->GetDirectory();
lua_pushstring(L, s.c_str());
return 1;
}
static int loadRegion(lua_State* L) {
//get the parameters
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
std::string s = pager->GetDirectory();
//push the parameters
lua_getglobal(L, "region");
lua_getfield(L, -1, "load");
Region* region = pager->LoadRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
lua_pushlightuserdata(L, region);
lua_pushstring(L, s.c_str());
//call the method
if (lua_pcall(L, 2, 1, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(L, -1) ));
}
return 1;
}
static int saveRegion(lua_State* L) {
//get the parameters
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
std::string s = pager->GetDirectory();
//push the parameters
lua_getglobal(L, "region");
lua_getfield(L, -1, "save");
Region* region = pager->SaveRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
lua_pushlightuserdata(L, region);
lua_pushstring(L, s.c_str());
//call the method
if (lua_pcall(L, 2, 0, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(L, -1) ));
}
return 0;
return 1;
}
static int createRegion(lua_State* L) {
//get the parameters
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
//push the parameters
lua_getglobal(L, "region");
lua_getfield(L, -1, "create");
Region* region = pager->CreateRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
lua_pushlightuserdata(L, region);
//TODO: parameters
//call the method
if (lua_pcall(L, 1, 0, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(L, -1) ));
}
return 0;
return 1;
}
static int unloadRegion(lua_State* L) {
//get the parameters
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
Region* region = pager->GetRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
std::string s = pager->GetDirectory();
//push the parameters
lua_getglobal(L, "region");
lua_getfield(L, -1, "unload");
lua_pushlightuserdata(L, region);
lua_pushstring(L, s.c_str());
//call the method
if (lua_pcall(L, 2, 0, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(L, -1) ));
}
pager->UnloadRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
return 0;
}
static const luaL_Reg pagerlib[] = {
{"settile", setTile},
{"gettile", getTile},
{"getregion", getRegion},
{"setdirectory", setDirectory},
{"getdirectory", getDirectory},
{"loadregion", loadRegion},
{"saveregion", saveRegion},
{"createregion", createRegion},
{"unloadregion", unloadRegion},
static const luaL_Reg regionPagerLib[] = {
{"GetRegionPager", getRegionPager},
{"SetTile", setTile},
{"GetTile", getTile},
{"SetSolid", setSolid},
{"GetSolid", getSolid},
{"GetRegion", getRegion},
{"LoadRegion", loadRegion},
{"SaveRegion", saveRegion},
{"CreateRegion", createRegion},
{"UnloadRegion", unloadRegion},
{nullptr, nullptr}
};
LUAMOD_API int luaopen_pagerapi(lua_State* L) {
luaL_newlib(L, pagerlib);
LUAMOD_API int openRegionPagerAPI(lua_State* L) {
luaL_newlib(L, regionPagerLib);
return 1;
}
@@ -19,13 +19,13 @@
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "character_data.hpp"
#include "combat_data.hpp"
#include "enemy_data.hpp"
#include "statistics.hpp"
#ifndef REGIONPAGERAPI_HPP_
#define REGIONPAGERAPI_HPP_
/* DOCS: Sanity check, read more
* Since most/all of the files in this directory are header files, I've created
* this source file as a "sanity check", to ensure that the above header files
* are written correctly via make.
*/
#include "lua/lua.hpp"
#define TORTUGA_REGION_PAGER_PSEUDO_INDEX "RegionPagerPseudoIndex"
#define TORTUGA_REGION_PAGER_NAME "RegionPager"
LUAMOD_API int openRegionPagerAPI(lua_State* L);
#endif
+13
View File
@@ -36,7 +36,20 @@ Region::type_t RegionPagerBase::GetTile(int x, int y, int z) {
return ptr->GetTile(x - ptr->GetX(), y - ptr->GetY(), z);
}
bool RegionPagerBase::SetSolid(int x, int y, int b) {
Region* ptr = GetRegion(x, y);
return ptr->SetSolid(x - ptr->GetX(), y - ptr->GetY(), b);
}
bool RegionPagerBase::GetSolid(int x, int y) {
Region* ptr = GetRegion(x, y);
return ptr->GetSolid(x - ptr->GetX(), y - ptr->GetY());
}
Region* RegionPagerBase::GetRegion(int x, int y) {
x = snapToBase(REGION_WIDTH, x);
y = snapToBase(REGION_HEIGHT, y);
//get the region by various means
Region* ptr = nullptr;
ptr = FindRegion(x, y);
+4
View File
@@ -35,6 +35,10 @@ public:
virtual Region::type_t SetTile(int x, int y, int z, Region::type_t v);
virtual Region::type_t GetTile(int x, int y, int z);
//solid manipulation
virtual bool SetSolid(int x, int y, int b);
virtual bool GetSolid(int x, int y);
//region manipulation
virtual Region* GetRegion(int x, int y);
virtual Region* FindRegion(int x, int y);
+37 -40
View File
@@ -29,23 +29,22 @@ Region* RegionPagerLua::LoadRegion(int x, int y) {
//load the region if possible
//something to work on
regionList.emplace_front(x, y);
Region tmpRegion(x, y);
//API hook
lua_getglobal(luaState, "region");
lua_getfield(luaState, -1, "load");
lua_pushlightuserdata(luaState, &regionList.front());
lua_pushstring(luaState, directory.c_str());
if (lua_pcall(luaState, 2, 1, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
lua_getglobal(lua, "Region");
lua_getfield(lua, -1, "Load");
lua_pushlightuserdata(lua, &tmpRegion);
if (lua_pcall(lua, 1, 1, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
}
//success or failure
if (!lua_toboolean(luaState, -1)) {
lua_pop(luaState, 2);
regionList.pop_front();
if (!lua_toboolean(lua, -1)) {
lua_pop(lua, 2);
return nullptr;
}
lua_pop(luaState, 2);
lua_pop(lua, 2);
regionList.push_front(tmpRegion);
return &regionList.front();
}
@@ -54,14 +53,13 @@ Region* RegionPagerLua::SaveRegion(int x, int y) {
Region* ptr = FindRegion(x, y);
if (ptr) {
//API hook
lua_getglobal(luaState, "region");
lua_getfield(luaState, -1, "save");
lua_pushlightuserdata(luaState, ptr);
lua_pushstring(luaState, directory.c_str());
if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
lua_getglobal(lua, "Region");
lua_getfield(lua, -1, "Save");
lua_pushlightuserdata(lua, ptr);
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
}
lua_pop(luaState, 1);
lua_pop(lua, 1);
}
return ptr;
}
@@ -72,32 +70,32 @@ Region* RegionPagerLua::CreateRegion(int x, int y) {
}
//something to work on
regionList.emplace_front(x, y);
Region tmpRegion(x, y);
//API hook
lua_getglobal(luaState, "region");
lua_getfield(luaState, -1, "create");
lua_pushlightuserdata(luaState, &regionList.front());
lua_getglobal(lua, "Region");
lua_getfield(lua, -1, "Create");
lua_pushlightuserdata(lua, &tmpRegion);
//TODO: parameters
if (lua_pcall(luaState, 1, 0, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
}
lua_pop(luaState, 1);
return &regionList.front();;
lua_pop(lua, 1);
regionList.push_front(tmpRegion);
return &regionList.front();
}
void RegionPagerLua::UnloadRegion(int x, int y) {
lua_getglobal(luaState, "region");
lua_getglobal(lua, "Region");
regionList.remove_if([&](Region& region) -> bool {
if (region.GetX() == x && region.GetY() == y) {
//API hook
lua_getfield(luaState, -1, "unload");
lua_pushlightuserdata(luaState, &region);
lua_pushstring(luaState, directory.c_str());
if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
lua_getfield(lua, -1, "Unload");
lua_pushlightuserdata(lua, &region);
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
}
return true;
@@ -105,22 +103,21 @@ void RegionPagerLua::UnloadRegion(int x, int y) {
return false;
});
lua_pop(luaState, 1);
lua_pop(lua, 1);
}
void RegionPagerLua::UnloadAll() {
lua_getglobal(luaState, "region");
lua_getglobal(lua, "Region");
for (auto& it : regionList) {
//API hook
lua_getfield(luaState, -1, "unload");
lua_pushlightuserdata(luaState, &it);
lua_pushstring(luaState, directory.c_str());
if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
lua_getfield(lua, -1, "Unload");
lua_pushlightuserdata(lua, &it);
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
}
}
lua_pop(luaState, 1);
lua_pop(lua, 1);
regionList.clear();
}
+4 -7
View File
@@ -41,14 +41,11 @@ public:
void UnloadAll() override;
std::string SetDirectory(std::string s) { return directory = s; }
std::string GetDirectory() { return directory; }
lua_State* SetLuaState(lua_State* L) { return luaState = L; }
lua_State* GetLuaState() { return luaState; }
//accessors & mutators
lua_State* SetLuaState(lua_State* L) { return lua = L; }
lua_State* GetLuaState() { return lua; }
protected:
std::string directory;
lua_State* luaState = nullptr;
lua_State* lua = nullptr;
};
#endif
@@ -21,24 +21,24 @@
*/
#include "tile_sheet.hpp"
void TileSheet::Load(std::string fname, int xc, int yc) {
XCount = xc;
YCount = yc;
void TileSheet::Load(std::string fname, int tileWidth, int tileHeight) {
image.LoadSurface(fname);
image.SetClipW(image.GetClipW()/XCount);
image.SetClipH(image.GetClipH()/YCount);
image.SetClipW(tileWidth);
image.SetClipH(tileHeight);
xCount = image.GetSurface()->w / image.GetClipW();
yCount = image.GetSurface()->h / image.GetClipH();
}
void TileSheet::Unload() {
image.FreeSurface();
XCount = YCount = 0;
xCount = yCount = 0;
}
void TileSheet::DrawTo(SDL_Surface* const dest, int x, int y, Region::type_t tile) {
void TileSheet::DrawTileTo(SDL_Surface* const dest, int x, int y, Region::type_t tile) {
//0 is invisible
if (tile == 0) return;
image.SetClipX((tile-1) % XCount * image.GetClipW());
image.SetClipY((tile-1) / XCount * image.GetClipH());
image.SetClipX((tile-1) % xCount * image.GetClipW());
image.SetClipY((tile-1) / xCount * image.GetClipH());
image.DrawTo(dest, x, y);
}
@@ -50,8 +50,8 @@ void TileSheet::DrawRegionTo(SDL_Surface* const dest, Region* const region, int
tile = region->GetTile(i, j, k);
//0 is invisible
if (tile == 0) continue;
image.SetClipX((tile-1) % XCount * image.GetClipW());
image.SetClipY((tile-1) / XCount * image.GetClipH());
image.SetClipX((tile-1) % xCount * image.GetClipW());
image.SetClipY((tile-1) / xCount * image.GetClipH());
image.DrawTo(dest,
(region->GetX() + i) * image.GetClipW() - camX,
(region->GetY() + j) * image.GetClipH() - camY);
@@ -31,24 +31,24 @@
class TileSheet {
public:
TileSheet() = default;
TileSheet(std::string f, int x, int y) { Load(f, x, y); }
TileSheet(std::string f, int w, int h) { Load(f, w, h); }
~TileSheet() = default;
void Load(std::string fname, int XCount, int YCount);
void Load(std::string fname, int tileWidth, int tileHeight);
void Unload();
void DrawTo(SDL_Surface* const dest, int x, int y, Region::type_t tile);
void DrawTileTo(SDL_Surface* const dest, int x, int y, Region::type_t tile);
void DrawRegionTo(SDL_Surface* const dest, Region* const region, int camX, int camY);
//accessors
Image* GetImage() { return &image; }
int GetXCount() { return XCount; }
int GetYCount() { return YCount; }
int GetXCount() { return xCount; }
int GetYCount() { return yCount; }
int GetTileW() { return image.GetClipW(); }
int GetTileH() { return image.GetClipH(); }
private:
Image image;
int XCount = 0, YCount = 0;
int xCount = 0, yCount = 0;
};
#endif
+82
View File
@@ -0,0 +1,82 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "tile_sheet_api.hpp"
#include "tile_sheet.hpp"
static int getTileSheet(lua_State* L) {
lua_pushstring(L, TORTUGA_TILE_SHEET_PSEUDO_INDEX);
lua_gettable(L, LUA_REGISTRYINDEX);
return 1;
}
static int load(lua_State* L) {
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
sheet->Load(lua_tostring(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4));
return 0;
}
static int unload(lua_State* L) {
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
sheet->Unload();
return 0;
}
static int getXCount(lua_State* L) {
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
lua_pushinteger(L, sheet->GetXCount());
return 1;
}
static int getYCount(lua_State* L) {
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
lua_pushinteger(L, sheet->GetYCount());
return 1;
}
static int getTileW(lua_State* L) {
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
lua_pushinteger(L, sheet->GetTileW());
return 1;
}
static int getTileH(lua_State* L) {
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
lua_pushinteger(L, sheet->GetTileH());
return 1;
}
static const luaL_Reg tileSheetLib[] = {
{"GetTileSheet",getTileSheet},
{"Load",load},
{"Unload",unload},
{"GetXCount",getXCount},
{"GetYCount",getYCount},
{"GetTileW",getTileW},
{"GetTileH",getTileH},
{nullptr, nullptr}
};
LUAMOD_API int openTileSheetAPI(lua_State* L) {
luaL_newlib(L, tileSheetLib);
return 1;
}
+31
View File
@@ -0,0 +1,31 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef TILESHEETAPI_HPP_
#define TILESHEETAPI_HPP_
#include "lua/lua.hpp"
#define TORTUGA_TILE_SHEET_PSEUDO_INDEX "TileSheetPseudoIndex"
#define TORTUGA_TILE_SHEET_NAME "TileSheet"
LUAMOD_API int openTileSheetAPI(lua_State* L);
#endif
+1 -4
View File
@@ -44,10 +44,7 @@ struct CharacterPacket : SerialPacketBase {
//gameplay
Statistics stats;
//TODO: equipment
//TODO: items
//TODO: buffs
//TODO: debuffs
//TODO: gameplay components: equipment, items, buffs, debuffs
};
#endif
+3 -3
View File
@@ -24,13 +24,13 @@
#include "serial_packet_base.hpp"
#include "combat_data.hpp"
#include "combat_defines.hpp"
struct CombatPacket : SerialPacketBase {
//identify the combat instance
int combatIndex;
int difficulty;
CombatData::Terrain terrainType;
TerrainType terrainType;
//combatants
int characterArray[COMBAT_MAX_CHARACTERS];
@@ -40,7 +40,7 @@ struct CombatPacket : SerialPacketBase {
int mapIndex;
Vector2 origin;
//TODO: rewards
//TODO: gameplay components: rewards
};
#endif
+1 -6
View File
@@ -33,12 +33,7 @@ struct EnemyPacket : SerialPacketBase {
//gameplay
Statistics stats;
//TODO: equipment
//TODO: items
//TODO: buffs
//TODO: debuffs
//TODO: rewards
//TODO: gameplay components: equipment, items, buffs, debuffs, rewards
};
#endif
+1 -1
View File
@@ -30,7 +30,7 @@
#include "SDL/SDL_net.h"
constexpr int NETWORK_VERSION = 20140607;
constexpr int NETWORK_VERSION = 20140701;
constexpr int PACKET_STRING_SIZE = 100;
struct SerialPacketBase {
-1
View File
@@ -148,7 +148,6 @@ void deserializePacket(SerialPacketBase* packet, void* buffer) {
case SerialPacketType::COMBAT_DELETE:
case SerialPacketType::COMBAT_UPDATE:
//TODO: is this the best fit?
case SerialPacketType::COMBAT_ENTER_REQUEST:
case SerialPacketType::COMBAT_ENTER_RESPONSE:
case SerialPacketType::COMBAT_EXIT_REQUEST:
+8 -6
View File
@@ -53,13 +53,15 @@ void deserializeRegionContent(RegionPacket*, void*);
void deserializeServer(ServerPacket*, void*);
void deserializeStatistics(Statistics*, void*);
/* DOCS: Keep the PACKET_BUFFER_SIZE up to date
* DOCS: REGION_CONTENT is currently the largest type of packet, read more
* map content: REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizoeof(region::type_t)
* map format: sizeof(int) * 3
* metadata: sizeof(SerialPacket::Type)
/* DOCS: Keep PACKET_BUFFER_SIZE up to date
* DOCS: SerialPacketType::REGION_CONTENT is currently the largest type of packet, read more
* The metadata used are:
* SerialPacketType
* room index
* X & Y positon
* The rest is taken up by the Regions's content.
*/
constexpr int PACKET_BUFFER_SIZE = REGION_WIDTH * REGION_HEIGHT * REGION_DEPTH * sizeof(Region::type_t) + sizeof(int) * 3 + sizeof(SerialPacketType);
constexpr int PACKET_BUFFER_SIZE = sizeof(SerialPacketType) + sizeof(int) * 3 + REGION_FOOTPRINT;
#endif
+2 -8
View File
@@ -45,10 +45,7 @@ void serializeCharacter(CharacterPacket* packet, void* buffer) {
serializeStatistics(&packet->stats, buffer);
buffer = reinterpret_cast<char*>(buffer) + sizeof(Statistics);
//TODO: equipment
//TODO: items
//TODO: buffs
//TODO: debuffs
//TODO: gameplay components: equipment, items, buffs, debuffs
}
void deserializeCharacter(CharacterPacket* packet, void* buffer) {
@@ -73,8 +70,5 @@ void deserializeCharacter(CharacterPacket* packet, void* buffer) {
deserializeStatistics(&packet->stats, buffer);
buffer = reinterpret_cast<char*>(buffer) + sizeof(Statistics);
//TODO: equipment
//TODO: items
//TODO: buffs
//TODO: debuffs
//TODO: gameplay components: equipment, items, buffs, debuffs
}
+4 -4
View File
@@ -29,7 +29,7 @@ void serializeCombat(CombatPacket* packet, void* buffer) {
//identify the combat instance
SERIALIZE(buffer, &packet->combatIndex, sizeof(int));
SERIALIZE(buffer, &packet->difficulty, sizeof(int));
SERIALIZE(buffer, &packet->terrainType, sizeof(CombatData::Terrain));
SERIALIZE(buffer, &packet->terrainType, sizeof(TerrainType));
//combatants
SERIALIZE(buffer, &packet->characterArray, sizeof(int) * COMBAT_MAX_CHARACTERS);
@@ -40,7 +40,7 @@ void serializeCombat(CombatPacket* packet, void* buffer) {
SERIALIZE(buffer, &packet->origin.x, sizeof(double));
SERIALIZE(buffer, &packet->origin.y, sizeof(double));
//TODO: rewards
//TODO: gameplay components: rewards
}
void deserializeCombat(CombatPacket* packet, void* buffer) {
@@ -49,7 +49,7 @@ void deserializeCombat(CombatPacket* packet, void* buffer) {
//identify the combat instance
DESERIALIZE(buffer, &packet->combatIndex, sizeof(int));
DESERIALIZE(buffer, &packet->difficulty, sizeof(int));
DESERIALIZE(buffer, &packet->terrainType, sizeof(CombatData::Terrain));
DESERIALIZE(buffer, &packet->terrainType, sizeof(TerrainType));
//combatants
DESERIALIZE(buffer, &packet->characterArray, sizeof(int) * COMBAT_MAX_CHARACTERS);
@@ -60,5 +60,5 @@ void deserializeCombat(CombatPacket* packet, void* buffer) {
DESERIALIZE(buffer, &packet->origin.x, sizeof(double));
DESERIALIZE(buffer, &packet->origin.y, sizeof(double));
//TODO: rewards
//TODO: gameplay components: rewards
}
+2 -12
View File
@@ -37,12 +37,7 @@ void serializeEnemy(EnemyPacket* packet, void* buffer) {
serializeStatistics(&packet->stats, buffer);
buffer = reinterpret_cast<char*>(buffer) + sizeof(Statistics);
//TODO: equipment
//TODO: items
//TODO: buffs
//TODO: debuffs
//TODO: rewards
//TODO: gameplay components: equipment, items, buffs, debuffs, rewards
}
void deserializeEnemy(EnemyPacket* packet, void* buffer) {
@@ -57,10 +52,5 @@ void deserializeEnemy(EnemyPacket* packet, void* buffer) {
deserializeStatistics(&packet->stats, buffer);
buffer = reinterpret_cast<char*>(buffer) + sizeof(Statistics);
//TODO: equipment
//TODO: items
//TODO: buffs
//TODO: debuffs
//TODO: rewards
//TODO: gameplay components: equipment, items, buffs, debuffs, rewards
}
+8 -2
View File
@@ -40,7 +40,7 @@ void serializeRegionContent(RegionPacket* packet, void* buffer) {
SERIALIZE(buffer, &packet->x, sizeof(int));
SERIALIZE(buffer, &packet->y, sizeof(int));
//content
//tiles
for (register int i = 0; i < REGION_WIDTH; i++) {
for (register int j = 0; j < REGION_HEIGHT; j++) {
for (register int k = 0; k < REGION_DEPTH; k++) {
@@ -49,6 +49,9 @@ void serializeRegionContent(RegionPacket* packet, void* buffer) {
}
}
}
//solids
SERIALIZE(buffer, packet->region->GetSolidBitset(), REGION_SOLID_FOOTPRINT);
}
void deserializeRegionFormat(RegionPacket* packet, void* buffer) {
@@ -71,7 +74,7 @@ void deserializeRegionContent(RegionPacket* packet, void* buffer) {
//an object to work on
packet->region = new Region(packet->x, packet->y);
//content
//tiles
for (register int i = 0; i < REGION_WIDTH; i++) {
for (register int j = 0; j < REGION_HEIGHT; j++) {
for (register int k = 0; k < REGION_DEPTH; k++) {
@@ -80,4 +83,7 @@ void deserializeRegionContent(RegionPacket* packet, void* buffer) {
}
}
}
//solids
DESERIALIZE(buffer, packet->region->GetSolidBitset(), REGION_SOLID_FOOTPRINT);
}
+1 -1
View File
@@ -25,7 +25,7 @@
#include <stdexcept>
//DOCS: memset() is used before sending a packet to remove old data; you don't want to send sensitive data over the network
//BUGFIX: memset() is used before sending a packet to remove old data; you don't want to send sensitive data over the network
//NOTE: don't confuse SerialPacket with UDPpacket
void UDPNetworkUtility::Open(int port) {
+1
View File
@@ -36,6 +36,7 @@
* This class needs a rewrite.
*/
//TODO: This thing is fucking terrible, fix it and the button class
class MenuBar {
public:
MenuBar() = default;
+77
View File
@@ -0,0 +1,77 @@
/* Copyright: (c) Kayne Ruse 2013, 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef BOUNDINGBOX_HPP_
#define BOUNDINGBOX_HPP_
#include <type_traits>
#include <algorithm>
class BoundingBox {
public:
//This is explicitly a POD
int x, y;
int w, h;
BoundingBox() = default;
BoundingBox(int i, int j, int k, int l): x(i), y(j), w(k), h(l) {};
~BoundingBox() = default;
BoundingBox& operator=(BoundingBox const&) = default;
int Size() {
return std::max(w*h,0);
}
bool CheckOverlap(BoundingBox rhs) {
return !(
x >= rhs.x + rhs.w ||
y >= rhs.y + rhs.h ||
rhs.x >= x + w ||
rhs.y >= y + h);
}
BoundingBox CalcOverlap(BoundingBox rhs) {
if (!CheckOverlap(rhs)) {
return {0, 0, 0, 0};
}
BoundingBox ret;
ret.x = std::max(x, rhs.x);
ret.y = std::max(y, rhs.y);
ret.w = std::min(x+w, rhs.x+rhs.w) - ret.x;
ret.h = std::min(y+h, rhs.y+rhs.h) - ret.y;
return ret;
}
};
//This is explicitly a POD
static_assert(std::is_pod<Vector2>::value, "BoundingBox is not a POD");
#include "vector2.hpp"
//operators
inline BoundingBox operator+(BoundingBox b, Vector2 v) {
return {b.x + (int)v.x, b.y + (int)v.y, b.w, b.h};
}
inline BoundingBox operator+(Vector2 v, BoundingBox b) {
return b + v;
}
#endif
-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
);
}
-105
View File
@@ -1,105 +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>
using namespace std;
void ConfigUtility::Load(string fname) {
ifstream is(fname);
if (!is.is_open()) {
throw(runtime_error("Failed to open config file"));
}
string key, val;
for (;;) { //forever
//eat whitespace
while(isspace(is.peek()))
is.ignore();
//end of file
if (is.eof())
break;
//skip comment lines
if (is.peek() == '#') {
while(is.peek() != '\n' && !is.eof()) {
is.ignore();
}
continue;
}
//read in the pair
getline(is, key,'=');
getline(is, val);
//trim the strings at the start & end
while(key.size() && isspace(*key.begin())) key.erase(0, 1);
while(val.size() && isspace(*val.begin())) val.erase(0, 1);
while(key.size() && isspace(*(key.end()-1))) key.erase(key.end() - 1);
while(val.size() && isspace(*(val.end()-1))) val.erase(val.end() - 1);
//allow empty/wiped values
if (key.size() == 0) {
continue;
}
//save the pair
table[key] = val;
}
is.close();
}
std::string& ConfigUtility::String(std::string s) {
return table[s];
}
int ConfigUtility::Integer(std::string s) {
std::map<std::string, std::string>::iterator it = table.find(s);
if (it == table.end()) {
return 0;
}
return atoi(it->second.c_str());
}
double ConfigUtility::Double(std::string s) {
std::map<std::string, std::string>::iterator it = table.find(s);
if (it == table.end()) {
return 0.0;
}
return atof(it->second.c_str());
}
bool ConfigUtility::Boolean(std::string s) {
std::map<std::string, std::string>::iterator it = table.find(s);
if (it == table.end()) {
return false;
}
return it->second == "true";
}
-60
View File
@@ -1,60 +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 <map>
#include <string>
class ConfigUtility {
public:
ConfigUtility() = default;
ConfigUtility(std::string s) { Load(s); }
void Load(std::string fname);
//convert to a type
std::string& String(std::string);
int Integer(std::string);
double Double(std::string);
bool Boolean(std::string);
//shorthand
std::string& operator[](std::string s) {
return String(s);
}
int Int(std::string s) {
return Integer(s);
}
bool Bool(std::string s) {
return Boolean(s);
}
//OO breaker
std::map<std::string, std::string>* GetMap() {
return &table;
}
private:
std::map<std::string, std::string> table;
};
#endif
+4
View File
@@ -32,6 +32,10 @@ int snapToBase(int base, int x) {
return x / base * base;
}
double snapToBase(double base, double x) {
return floor(x / base) * base;
}
std::string truncatePath(std::string pathname) {
return std::string(
std::find_if(
+2
View File
@@ -25,6 +25,8 @@
#include <string>
int snapToBase(int base, int x);
double snapToBase(double base, double x);
std::string truncatePath(std::string pathname);
//fixing known bugs in g++
+7 -9
View File
@@ -41,6 +41,13 @@ public:
double SquaredLength() const {
return x*x+y*y;
}
void Normalize() {
double l = Length();
if (l == 0)
throw(std::domain_error("Divide by zero"));
x /= l;
y /= l;
}
//Arithmetic operators
Vector2 operator+(Vector2 v) const {
@@ -97,15 +104,6 @@ public:
template<typename T> bool operator!=(T t) { return (x != t || y != t); }
};
//non-member templates (flip the order)
template<typename T> Vector2 operator+(T t, Vector2 v) { return v + t; }
template<typename T> Vector2 operator-(T t, Vector2 v) { return v - t; }
template<typename T> Vector2 operator*(T t, Vector2 v) { return v * t; }
template<typename T> Vector2 operator/(T t, Vector2 v) { return v / t; }
template<typename T> bool operator==(T t, Vector2 v) { return v == t; }
template<typename T> bool operator!=(T t, Vector2 v) { return v != t; }
//This is explicitly a POD
static_assert(std::is_pod<Vector2>::value, "Vector2 is not a POD");
+1
View File
@@ -3,6 +3,7 @@
#MKDIR=mkdir
#RM=del /y
#CXXFLAGS+=-static-libgcc -static-libstdc++ -g -fno-inline-functions -Wall
CXXFLAGS+=-static-libgcc -static-libstdc++
export
-29
View File
@@ -1,29 +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.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
+38 -13
View File
@@ -1,20 +1,45 @@
print("Lua script check (./rsc)")
print("Lua script check")
-------------------------
--Map API overrides
-------------------------
--uber lazy declarations
function math.sqr(x) return x*x end
function math.dist(x, y, i, j) return math.sqrt(math.sqr(x - i) + math.sqr(y - j)) end
function region.create(r)
for i = 1, region.getwidth() do
for j = 1, region.getheight() do
if math.abs(region.getx(r) + i -1) == math.abs(region.gety(r) + j -1) then
region.settile(r, i, j, 1, 50)
--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 shift = 36
tiles = {
plains = base + shift * 0,
grass = base + shift * 1,
dirt = base + shift * 2,
sand = base + shift * 3,
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.
function Region.Create(region)
for i = 1, Region.GetWidth() do
for j = 1, Region.GetHeight() do
local dist = math.dist(0, 0, i + Region.GetX(region) -1, j + Region.GetY(region) -1)
if dist < 10 then
Region.SetTile(region, i, j, 1, tiles.plains)
elseif dist < 12 then
Region.SetTile(region, i, j, 1, tiles.sand)
else
region.settile(r, i, j, 1, 14)
Region.SetTile(region, i, j, 1, tiles.water)
Region.SetSolid(region, i, j, true)
end
end
end
--signal
region.settile(r, 4, 5, 2, 86)
end
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
+37
View File
@@ -0,0 +1,37 @@
#config
INCLUDES+=.
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
#source
CXXSRC=$(wildcard *.cpp)
#objects
OBJDIR=obj
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
#output
OUTDIR=..
OUT=$(addprefix $(OUTDIR)/,server.a)
#targets
all: $(OBJ) $(OUT)
ar -crs $(OUT) $(OBJ)
$(OBJ): | $(OBJDIR)
$(OUT): | $(OUTDIR)
$(OBJDIR):
mkdir $(OBJDIR)
$(OUTDIR):
mkdir $(OUTDIR)
$(OBJDIR)/%.o: %.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
clean:
$(RM) *.o *.a *.exe
rebuild: clean all
@@ -22,22 +22,15 @@
#ifndef CHARACTERDATA_HPP_
#define CHARACTERDATA_HPP_
//components
#include "character_defines.hpp"
#include "vector2.hpp"
#include "statistics.hpp"
//graphics
#ifdef GRAPHICS
#include "sprite_sheet.hpp"
#endif
//std namespace
#include <string>
#include <cmath>
//the speeds that the characters move
constexpr double CHARACTER_WALKING_SPEED = 140.0;
constexpr double CHARACTER_WALKING_MOD = 1.0/sqrt(2.0);
struct CharacterData {
//metadata
int owner;
@@ -48,28 +41,14 @@ struct CharacterData {
int roomIndex = 0;
Vector2 origin = {0.0,0.0};
Vector2 motion = {0.0,0.0};
Vector2 bounds = {0.0,0.0};
//base statistics
Statistics stats;
//TODO: equipment
//TODO: items
//TODO: buffs
//TODO: debuffs
//methods
void Update(double delta);
#ifdef GRAPHICS
void DrawTo(SDL_Surface* const, int camX, int camY);
void CorrectSprite();
#endif
//TODO: gameplay components: equipment, items, buffs, debuffs
//active gameplay members
//NOTE: these are lost when unloaded
#ifdef GRAPHICS
SpriteSheet sprite;
#endif
bool inCombat = false;
int atbGauge = 0;
//TODO: stored command
@@ -58,7 +58,7 @@ static const char* DELETE_CHARACTER = "DELETE FROM Characters WHERE uid = ?;";
//Define the methods
//-------------------------
//TODO: default stats as a parameter? This would be good for differing beggining states or multiple classes
//NOTE: default stats as a parameter would be good for different beggining states or multiple classes
int CharacterManager::CreateCharacter(int owner, std::string handle, std::string avatar) {
//Create the character, failing if it exists
sqlite3_stmt* statement = nullptr;
@@ -157,10 +157,7 @@ int CharacterManager::LoadCharacter(int owner, std::string handle, std::string a
newChar.stats.evasion = sqlite3_column_double(statement, 20);
newChar.stats.luck = sqlite3_column_double(statement, 21);
//TODO: equipment
//TODO: items
//TODO: buffs
//TODO: debuffs
//TODO: gameplay components: equipment, items, buffs, debuffs
//finish the routine
sqlite3_finalize(statement);
@@ -217,10 +214,7 @@ int CharacterManager::SaveCharacter(int uid) {
ret |= sqlite3_bind_double(statement, 17, character.stats.evasion) != SQLITE_OK;
ret |= sqlite3_bind_double(statement, 18, character.stats.luck) != SQLITE_OK;
//TODO: equipment
//TODO: items
//TODO: buffs
//TODO: debuffs
//TODO: gameplay components: equipment, items, buffs, debuffs
//check for binding errors
if (ret) {
+37
View File
@@ -0,0 +1,37 @@
#config
INCLUDES+=. ../../common/gameplay ../../common/utilities
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
#source
CXXSRC=$(wildcard *.cpp)
#objects
OBJDIR=obj
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
#output
OUTDIR=..
OUT=$(addprefix $(OUTDIR)/,server.a)
#targets
all: $(OBJ) $(OUT)
ar -crs $(OUT) $(OBJ)
$(OBJ): | $(OBJDIR)
$(OUT): | $(OUTDIR)
$(OBJDIR):
mkdir $(OBJDIR)
$(OUTDIR):
mkdir $(OUTDIR)
$(OBJDIR)/%.o: %.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
clean:
$(RM) *.o *.a *.exe
rebuild: clean all
+1
View File
@@ -26,6 +26,7 @@
struct ClientData {
IPaddress address = {0,0};
//TODO: ping system?
};
#endif
@@ -23,31 +23,18 @@
#define COMBATDATA_HPP_
#include "vector2.hpp"
#include "combat_defines.hpp"
//gameplay members
#include "character_data.hpp"
#include "enemy_data.hpp"
//graphics
#ifdef GRAPHICS
#include "sprite_sheet.hpp"
#endif
//std namespace
#include <chrono>
#include <array>
#include <utility>
#define COMBAT_MAX_CHARACTERS 12
#define COMBAT_MAX_ENEMIES 12
struct CombatData {
enum class Terrain {
//TODO: types of combat terrains
NONE = 0,
GRASSLANDS,
};
typedef std::chrono::steady_clock Clock;
std::array<CharacterData, COMBAT_MAX_CHARACTERS> characterArray;
@@ -60,11 +47,6 @@ struct CombatData {
//time interval
Clock::time_point lastTick = Clock::now();
//graphics
#ifdef GRAPHICS
SpriteSheet sprite;
#endif
};
#endif
+37
View File
@@ -0,0 +1,37 @@
#config
INCLUDES+=. ../../common/gameplay ../../common/utilities ../characters ../enemies
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
#source
CXXSRC=$(wildcard *.cpp)
#objects
OBJDIR=obj
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
#output
OUTDIR=..
OUT=$(addprefix $(OUTDIR)/,server.a)
#targets
all: $(OBJ) $(OUT)
ar -crs $(OUT) $(OBJ)
$(OBJ): | $(OBJDIR)
$(OUT): | $(OUTDIR)
$(OBJDIR):
mkdir $(OBJDIR)
$(OUTDIR):
mkdir $(OUTDIR)
$(OBJDIR)/%.o: %.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
clean:
$(RM) *.o *.a *.exe
rebuild: clean all
@@ -25,11 +25,6 @@
#include "vector2.hpp"
#include "statistics.hpp"
//graphics
#ifdef GRAPHICS
#include "sprite_sheet.hpp"
#endif
//std namespace
#include <string>
@@ -41,20 +36,10 @@ struct EnemyData {
//gameplay
Statistics stats;
//TODO: equipment
//TODO: items
//TODO: buffs
//TODO: debuffs
//TODO: rewards
//TODO: gameplay components: equipment, items, buffs, debuffs, rewards
//active gameplay members
//NOTE: these are lost when unloaded
#ifdef GRAPHICS
SpriteSheet sprite;
Vector2 origin = {0.0,0.0};
Vector2 bounds = {0.0,0.0};
#endif
int tableIndex;
int atbGauge = 0;
};
+37
View File
@@ -0,0 +1,37 @@
#config
INCLUDES+=. ../mapgen ../../common/gameplay ../../common/map ../../common/utilities
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
#source
CXXSRC=$(wildcard *.cpp)
#objects
OBJDIR=obj
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
#output
OUTDIR=..
OUT=$(addprefix $(OUTDIR)/,server.a)
#targets
all: $(OBJ) $(OUT)
ar -crs $(OUT) $(OBJ)
$(OBJ): | $(OBJDIR)
$(OUT): | $(OUTDIR)
$(OBJDIR):
mkdir $(OBJDIR)
$(OUTDIR):
mkdir $(OUTDIR)
$(OBJDIR)/%.o: %.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
clean:
$(RM) *.o *.a *.exe
rebuild: clean all
+8 -4
View File
@@ -37,7 +37,9 @@
#include "lua/lua.hpp"
#include "region_api.hpp"
#include "pager_api.hpp"
#include "region_pager_api.hpp"
#include "room_api.hpp"
#include "room_mgr_api.hpp"
//these libs are loaded by lua.c and are readily available to any Lua program
static const luaL_Reg loadedlibs[] = {
@@ -53,9 +55,11 @@ static const luaL_Reg loadedlibs[] = {
{LUA_MATHLIBNAME, luaopen_math},
{LUA_DBLIBNAME, luaopen_debug},
//custom libs
{LUA_REGIONLIBNAME, luaopen_regionapi},
{LUA_PAGERLIBNAME, luaopen_pagerapi},
//Tortuga's API
{TORTUGA_REGION_NAME, openRegionAPI},
{TORTUGA_REGION_PAGER_NAME, openRegionPagerAPI},
{TORTUGA_ROOM_NAME, openRoomAPI},
{TORTUGA_ROOM_MGR_NAME, openRoomMgrAPI},
{NULL, NULL}
};
+1 -5
View File
@@ -21,15 +21,12 @@
*/
#include "server_application.hpp"
#include "SDL/SDL.h"
#include <stdexcept>
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
cout << "Beginning server" << endl;
try {
ServerApplication app;
app.Init(argc, argv);
@@ -37,9 +34,8 @@ int main(int argc, char** argv) {
app.Quit();
}
catch(exception& e) {
cerr << "Fatal error: " << e.what() << endl;
cerr << "Fatal exception thrown: " << e.what() << endl;
return 1;
}
cout << "Clean exit" << endl;
return 0;
}
+7 -2
View File
@@ -1,6 +1,6 @@
#config
INCLUDES+=. ../common/gameplay ../common/map ../common/network ../common/network/packet ../common/network/serial ../common/utilities
LIBS+=../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua -lsqlite3
INCLUDES+=. accounts characters combat enemies mapgen mapgen/generators rooms ../common/debugging ../common/gameplay ../common/map ../common/network ../common/network/packet ../common/network/serial ../common/utilities
LIBS+=server.a ../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua -lsqlite3
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
#source
@@ -16,6 +16,11 @@ OUT=$(addprefix $(OUTDIR)/,server)
#targets
all: $(OBJ) $(OUT)
$(MAKE) -C accounts
$(MAKE) -C characters
$(MAKE) -C combat
$(MAKE) -C enemies
$(MAKE) -C rooms
$(CXX) $(CXXFLAGS) -o $(OUT) $(OBJ) $(LIBS)
$(OBJ): | $(OBJDIR)
-72
View File
@@ -1,72 +0,0 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "room_manager.hpp"
#include <stdexcept>
//-------------------------
//public access methods
//-------------------------
RoomData* RoomManager::CreateRoom(int uid) {
//don't overwrite existing rooms
std::map<int, RoomData*>::iterator it = roomMap.find(uid);
if (it != roomMap.end()) {
throw(std::runtime_error("Cannot overwrite an existing room"));
}
roomMap[uid] = new RoomData();
//TODO: create room in the API
if (luaState) {
roomMap[uid]->pager.SetLuaState(luaState);
}
return roomMap[uid];
}
RoomData* RoomManager::UnloadRoom(int uid) {
//TODO: unload room in the API
delete roomMap[uid];
roomMap.erase(uid);
}
RoomData* RoomManager::GetRoom(int uid) {
RoomData* ptr = FindRoom(uid);
if (ptr) return ptr;
ptr = CreateRoom(uid);
return ptr;
}
RoomData* RoomManager::FindRoom(int uid) {
std::map<int, RoomData*>::iterator it = roomMap.find(uid);
if (it == roomMap.end()) {
return nullptr;
}
return it->second;
}
RoomData* RoomManager::PushRoom(int uid, RoomData* room) {
//unload existing rooms with this index
std::map<int, RoomData*>::iterator it = roomMap.find(uid);
if (it != roomMap.end()) {
UnloadRoom(uid);
}
roomMap[uid] = room;
}
+37
View File
@@ -0,0 +1,37 @@
#config
INCLUDES+=. ../mapgen ../mapgen/generators ../../common/map
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
#source
CXXSRC=$(wildcard *.cpp)
#objects
OBJDIR=obj
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
#output
OUTDIR=..
OUT=$(addprefix $(OUTDIR)/,server.a)
#targets
all: $(OBJ) $(OUT)
ar -crs $(OUT) $(OBJ)
$(OBJ): | $(OBJDIR)
$(OUT): | $(OUTDIR)
$(OBJDIR):
mkdir $(OBJDIR)
$(OUTDIR):
mkdir $(OUTDIR)
$(OBJDIR)/%.o: %.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
clean:
$(RM) *.o *.a *.exe
rebuild: clean all
@@ -19,24 +19,36 @@
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef ENEMYFACTORYGENERIC_HPP_
#define ENEMYFACTORYGENERIC_HPP_
#include "room_api.hpp"
#include "enemy_factory_interface.hpp"
#include "room_data.hpp"
#include "enemy_data.hpp"
static int getPager(lua_State* L) {
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
lua_pushlightuserdata(L, reinterpret_cast<void*>(&room->pager));
return 1;
}
#include <list>
static int onCreate(lua_State* L) {
//TODO: onCreate()
return 0;
}
//DOCS: Not really intended for use, but rather for copying and tweaking
class EnemyFactoryGeneric : public EnemyFactoryInterface {
public:
EnemyFactoryGeneric();
~EnemyFactoryGeneric() noexcept override;
static int onUnload(lua_State* L) {
//TODO: onUnload()
return 0;
}
void Generate(std::list<EnemyData>* container) override;
private:
//TODO: hold the parameters specified by the room
//TODO: parameters
static const luaL_Reg roomLib[] = {
{"GetPager",getPager},
{"OnCreate", onCreate},
{"OnUnload", onUnload},
{nullptr, nullptr}
};
#endif
LUAMOD_API int openRoomAPI(lua_State* L) {
luaL_newlib(L, roomLib);
return 1;
}
@@ -24,7 +24,7 @@
#include "lua/lua.hpp"
#define LUA_ROOMLIBNAME "room"
LUAMOD_API int luaopen_roomapi(lua_State* L);
#define TORTUGA_ROOM_NAME "Room"
LUAMOD_API int openRoomAPI(lua_State* L);
#endif
@@ -26,17 +26,8 @@
#include "region_pager_lua.hpp"
struct RoomData {
enum class RoomType {
OVERWORLD = 0,
RUINS = 1,
TOWERS = 2,
FORESTS = 3,
CAVE = 4,
};
//members
RegionPagerLua pager;
RoomType type;
//TODO: collision map
//TODO: NPCs?
+108
View File
@@ -0,0 +1,108 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "room_manager.hpp"
#include <stdexcept>
//-------------------------
//public access methods
//-------------------------
RoomData* RoomManager::CreateRoom() {
//create the room
RoomData* newRoom = new RoomData();
//set the state
if (luaState) {
newRoom->pager.SetLuaState(luaState);
}
//register the room
roomMap[counter++] = newRoom;
//API hook
lua_getglobal(luaState, "Room");
lua_getfield(luaState, -1, "OnCreate");
lua_pushlightuserdata(luaState, newRoom);
if (lua_pcall(luaState, 1, 0, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
}
lua_pop(luaState, 1);
//finish the routine
return newRoom;
}
void RoomManager::UnloadRoom(int uid) {
//find the room
RoomData* room = FindRoom(uid);
if (!room) {
return;
}
//API hook
lua_getglobal(luaState, "Room");
lua_getfield(luaState, -1, "OnUnload");
lua_pushlightuserdata(luaState, room);
if (lua_pcall(luaState, 1, 0, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
}
lua_pop(luaState, 1);
//free the memory
delete room;
roomMap.erase(uid);
}
RoomData* RoomManager::GetRoom(int uid) {
return FindRoom(uid);
//TODO: expand this to auto-create the room
}
RoomData* RoomManager::FindRoom(int uid) {
std::map<int, RoomData*>::iterator it = roomMap.find(uid);
if (it == roomMap.end()) {
return nullptr;
}
return it->second;
}
int RoomManager::PushRoom(RoomData* room) {
roomMap[counter++] = room;
return counter;
}
void RoomManager::UnloadAll() {
lua_getglobal(luaState, "Room");
for (auto& it : roomMap) {
//API hook
lua_getfield(luaState, -1, "OnUnload");
lua_pushlightuserdata(luaState, it.second);
if (lua_pcall(luaState, 1, 0, 0) != LUA_OK) {
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
}
}
lua_pop(luaState, 1);
roomMap.clear();
}
@@ -36,12 +36,14 @@ public:
~RoomManager() = default;
//public access methods
RoomData* CreateRoom(int uid);
RoomData* UnloadRoom(int uid);
RoomData* CreateRoom();
void UnloadRoom(int uid);
RoomData* GetRoom(int uid);
RoomData* FindRoom(int uid);
RoomData* PushRoom(int uid, RoomData*);
int PushRoom(RoomData*);
void UnloadAll();
//accessors and mutators
std::map<int, RoomData*>* GetContainer() { return &roomMap; }
@@ -52,6 +54,7 @@ public:
private:
std::map<int, RoomData*> roomMap;
lua_State* luaState = nullptr;
int counter = 0;
};
#endif
@@ -19,26 +19,14 @@
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "room_api.hpp"
#include "room_mgr_api.hpp"
#include "room_api.hpp"
#include "room_manager.hpp"
#include "room_data.hpp"
static int getType(lua_State* L) {
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
lua_pushinteger(L, static_cast<int>(room->type));
return 1;
}
#include <string>
//TODO: parameters
static int getRegionPager(lua_State* L) {
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
lua_pushlightuserdata(L, reinterpret_cast<void*>(&room->pager));
return 1;
}
//RoomManager only
static int getRoom(lua_State* L) {
//get the room manager
lua_pushstring(L, ROOM_MANAGER_PSEUDOINDEX);
@@ -50,14 +38,42 @@ static int getRoom(lua_State* L) {
return 1;
}
static const luaL_Reg roomlib[] = {
{"gettype",getType},
{"getregionpager",getRegionPager},
{"getroom",getRoom},
static int createRoom(lua_State* L) {
//TODO: check parameter count for the glue functions
//get the room manager
lua_pushstring(L, ROOM_MANAGER_PSEUDOINDEX);
lua_gettable(L, LUA_REGISTRYINDEX);
RoomManager* roomMgr = reinterpret_cast<RoomManager*>(lua_touserdata(L, -1));
//create the room
RoomData* newRoom = roomMgr->CreateRoom();
//return the new room
lua_pushlightuserdata(L, newRoom);
return 1;
}
static int unloadRoom(lua_State* L) {
//get the room manager
lua_pushstring(L, ROOM_MANAGER_PSEUDOINDEX);
lua_gettable(L, LUA_REGISTRYINDEX);
RoomManager* roomMgr = reinterpret_cast<RoomManager*>(lua_touserdata(L, -1));
//unload the specified room
roomMgr->UnloadRoom(lua_tointeger(L, -2));
return 0;
}
static const luaL_Reg roomMgrLib[] = {
{"GetRoom",getRoom},
{"CreateRoom",createRoom},
{"UnloadRoom",unloadRoom},
{nullptr, nullptr}
};
LUAMOD_API int luaopen_roomapi(lua_State* L) {
luaL_newlib(L, roomlib);
LUAMOD_API int openRoomMgrAPI(lua_State* L) {
luaL_newlib(L, roomMgrLib);
return 1;
}

Some files were not shown because too many files have changed in this diff Show More