Merge branch 'develop' into master (read more)
Following a rather educational "game jam" using components of Tortuga, I've made a significant number of revisions. A brief summary: * The entirety of the map system now have lua APIs * The ConfigUtility handles recusive config files * Collisions are functional * I've added a singleton template base class, which is used by the apps * I've decided that focusing on the engine's stability is important * I need to push through the generated TODO list
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
//components
|
//components
|
||||||
#include "character_defines.hpp"
|
#include "character_defines.hpp"
|
||||||
#include "vector2.hpp"
|
#include "vector2.hpp"
|
||||||
|
#include "bounding_box.hpp"
|
||||||
#include "statistics.hpp"
|
#include "statistics.hpp"
|
||||||
|
|
||||||
//graphics
|
//graphics
|
||||||
@@ -64,8 +65,8 @@ public:
|
|||||||
Vector2 GetOrigin() const { return origin; }
|
Vector2 GetOrigin() const { return origin; }
|
||||||
Vector2 SetMotion(Vector2 v) { return motion = v; }
|
Vector2 SetMotion(Vector2 v) { return motion = v; }
|
||||||
Vector2 GetMotion() const { return motion; }
|
Vector2 GetMotion() const { return motion; }
|
||||||
Vector2 SetBounds(Vector2 v) { return bounds = v; }
|
BoundingBox SetBounds(BoundingBox b) { return bounds = b; }
|
||||||
Vector2 GetBounds() const { return bounds; }
|
BoundingBox GetBounds() { return bounds; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//graphics
|
//graphics
|
||||||
@@ -84,7 +85,7 @@ private:
|
|||||||
//position
|
//position
|
||||||
Vector2 origin = {0.0,0.0};
|
Vector2 origin = {0.0,0.0};
|
||||||
Vector2 motion = {0.0,0.0};
|
Vector2 motion = {0.0,0.0};
|
||||||
Vector2 bounds = {CHARACTER_BOUNDS_WIDTH,CHARACTER_BOUNDS_HEIGHT};
|
BoundingBox bounds;
|
||||||
};
|
};
|
||||||
|
|
||||||
//tmp
|
//tmp
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "client_application.hpp"
|
#include "client_application.hpp"
|
||||||
|
|
||||||
#include "serial.hpp"
|
#include "serial.hpp"
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
@@ -48,6 +49,7 @@ void ClientApplication::Init(int argc, char** argv) {
|
|||||||
std::cout << "Beginning " << argv[0] << std::endl;
|
std::cout << "Beginning " << argv[0] << std::endl;
|
||||||
|
|
||||||
//load the prerequisites
|
//load the prerequisites
|
||||||
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
config.Load("rsc\\config.cfg");
|
config.Load("rsc\\config.cfg");
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -165,25 +167,25 @@ void ClientApplication::LoadScene(SceneList sceneIndex) {
|
|||||||
//add scene creation calls here
|
//add scene creation calls here
|
||||||
case SceneList::FIRST:
|
case SceneList::FIRST:
|
||||||
case SceneList::SPLASHSCREEN:
|
case SceneList::SPLASHSCREEN:
|
||||||
activeScene = new SplashScreen(&config);
|
activeScene = new SplashScreen();
|
||||||
break;
|
break;
|
||||||
case SceneList::MAINMENU:
|
case SceneList::MAINMENU:
|
||||||
activeScene = new MainMenu(&config);
|
activeScene = new MainMenu();
|
||||||
break;
|
break;
|
||||||
case SceneList::OPTIONSMENU:
|
case SceneList::OPTIONSMENU:
|
||||||
activeScene = new OptionsMenu(&config);
|
activeScene = new OptionsMenu();
|
||||||
break;
|
break;
|
||||||
case SceneList::LOBBYMENU:
|
case SceneList::LOBBYMENU:
|
||||||
activeScene = new LobbyMenu(&config, &network, &clientIndex, &accountIndex);
|
activeScene = new LobbyMenu(&network, &clientIndex, &accountIndex);
|
||||||
break;
|
break;
|
||||||
case SceneList::INWORLD:
|
case SceneList::INWORLD:
|
||||||
activeScene = new InWorld(&config, &network, &clientIndex, &accountIndex, &characterIndex, &characterMap);
|
activeScene = new InWorld(&network, &clientIndex, &accountIndex, &characterIndex, &characterMap);
|
||||||
break;
|
break;
|
||||||
case SceneList::INCOMBAT:
|
case SceneList::INCOMBAT:
|
||||||
activeScene = new InCombat(&config, &network, &clientIndex, &accountIndex, &characterIndex, &characterMap);
|
activeScene = new InCombat(&network, &clientIndex, &accountIndex, &characterIndex, &characterMap);
|
||||||
break;
|
break;
|
||||||
case SceneList::CLEANUP:
|
case SceneList::CLEANUP:
|
||||||
activeScene = new CleanUp(&config, &network, &clientIndex, &accountIndex, &characterIndex, &characterMap);
|
activeScene = new CleanUp(&network, &clientIndex, &accountIndex, &characterIndex, &characterMap);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw(std::logic_error("Failed to recognize the scene index"));
|
throw(std::logic_error("Failed to recognize the scene index"));
|
||||||
|
|||||||
@@ -25,22 +25,26 @@
|
|||||||
#include "scene_list.hpp"
|
#include "scene_list.hpp"
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
#include "config_utility.hpp"
|
|
||||||
#include "udp_network_utility.hpp"
|
#include "udp_network_utility.hpp"
|
||||||
#include "character.hpp"
|
#include "character.hpp"
|
||||||
|
|
||||||
|
#include "singleton.hpp"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
class ClientApplication {
|
class ClientApplication: public Singleton<ClientApplication> {
|
||||||
public:
|
public:
|
||||||
ClientApplication() = default;
|
//public methods
|
||||||
~ClientApplication() = default;
|
|
||||||
|
|
||||||
void Init(int argc, char** argv);
|
void Init(int argc, char** argv);
|
||||||
void Proc();
|
void Proc();
|
||||||
void Quit();
|
void Quit();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend Singleton<ClientApplication>;
|
||||||
|
|
||||||
|
ClientApplication() = default;
|
||||||
|
~ClientApplication() = default;
|
||||||
|
|
||||||
//Private access members
|
//Private access members
|
||||||
void LoadScene(SceneList sceneIndex);
|
void LoadScene(SceneList sceneIndex);
|
||||||
void UnloadScene();
|
void UnloadScene();
|
||||||
@@ -48,7 +52,6 @@ private:
|
|||||||
BaseScene* activeScene = nullptr;
|
BaseScene* activeScene = nullptr;
|
||||||
|
|
||||||
//shared parameters
|
//shared parameters
|
||||||
ConfigUtility config;
|
|
||||||
UDPNetworkUtility network;
|
UDPNetworkUtility network;
|
||||||
int clientIndex = -1;
|
int clientIndex = -1;
|
||||||
int accountIndex = -1;
|
int accountIndex = -1;
|
||||||
|
|||||||
+14
-2
@@ -21,6 +21,9 @@
|
|||||||
*/
|
*/
|
||||||
#include "client_application.hpp"
|
#include "client_application.hpp"
|
||||||
|
|
||||||
|
//singletons
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@@ -28,14 +31,23 @@ using namespace std;
|
|||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
try {
|
try {
|
||||||
ClientApplication app;
|
//create the singletons
|
||||||
|
ClientApplication::Create();
|
||||||
|
ConfigUtility::Create();
|
||||||
|
|
||||||
|
//call the server's routines
|
||||||
|
ClientApplication& app = ClientApplication::GetSingleton();
|
||||||
app.Init(argc, argv);
|
app.Init(argc, argv);
|
||||||
app.Proc();
|
app.Proc();
|
||||||
app.Quit();
|
app.Quit();
|
||||||
|
|
||||||
|
//delete the singletons
|
||||||
|
ConfigUtility::Delete();
|
||||||
|
ClientApplication::Delete();
|
||||||
}
|
}
|
||||||
catch(exception& e) {
|
catch(exception& e) {
|
||||||
cerr << "Fatal exception thrown: " << e.what() << endl;
|
cerr << "Fatal exception thrown: " << e.what() << endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. scenes ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet ../common/network/serial ../common/ui ../common/utilities
|
INCLUDES+=. scenes ../common/debugging ../common/gameplay ../common/graphics ../common/map ../common/network ../common/network/packet ../common/network/serial ../common/ui ../common/utilities
|
||||||
LIBS+=client.a ../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua
|
LIBS+=client.a ../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "clean_up.hpp"
|
#include "clean_up.hpp"
|
||||||
|
|
||||||
#include "channels.hpp"
|
#include "channels.hpp"
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
@@ -30,20 +31,20 @@
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
CleanUp::CleanUp(
|
CleanUp::CleanUp(
|
||||||
ConfigUtility* const argConfig,
|
|
||||||
UDPNetworkUtility* const argNetwork,
|
UDPNetworkUtility* const argNetwork,
|
||||||
int* const argClientIndex,
|
int* const argClientIndex,
|
||||||
int* const argAccountIndex,
|
int* const argAccountIndex,
|
||||||
int* const argCharacterIndex,
|
int* const argCharacterIndex,
|
||||||
CharacterMap* argCharacterMap
|
CharacterMap* argCharacterMap
|
||||||
):
|
):
|
||||||
config(*argConfig),
|
|
||||||
network(*argNetwork),
|
network(*argNetwork),
|
||||||
clientIndex(*argClientIndex),
|
clientIndex(*argClientIndex),
|
||||||
accountIndex(*argAccountIndex),
|
accountIndex(*argAccountIndex),
|
||||||
characterIndex(*argCharacterIndex),
|
characterIndex(*argCharacterIndex),
|
||||||
characterMap(*argCharacterMap)
|
characterMap(*argCharacterMap)
|
||||||
{
|
{
|
||||||
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
|
|
||||||
//setup the utility objects
|
//setup the utility objects
|
||||||
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
||||||
image.SetClipH(image.GetClipH()/3);
|
image.SetClipH(image.GetClipH()/3);
|
||||||
|
|||||||
@@ -31,7 +31,6 @@
|
|||||||
#include "button.hpp"
|
#include "button.hpp"
|
||||||
|
|
||||||
//common
|
//common
|
||||||
#include "config_utility.hpp"
|
|
||||||
#include "frame_rate.hpp"
|
#include "frame_rate.hpp"
|
||||||
|
|
||||||
#include "character.hpp"
|
#include "character.hpp"
|
||||||
@@ -46,7 +45,6 @@ class CleanUp : public BaseScene {
|
|||||||
public:
|
public:
|
||||||
//Public access members
|
//Public access members
|
||||||
CleanUp(
|
CleanUp(
|
||||||
ConfigUtility* const argConfig,
|
|
||||||
UDPNetworkUtility* const argNetwork,
|
UDPNetworkUtility* const argNetwork,
|
||||||
int* const argClientIndex,
|
int* const argClientIndex,
|
||||||
int* const argAccountIndex,
|
int* const argAccountIndex,
|
||||||
@@ -70,7 +68,6 @@ protected:
|
|||||||
void KeyUp(SDL_KeyboardEvent const&);
|
void KeyUp(SDL_KeyboardEvent const&);
|
||||||
|
|
||||||
//shared parameters
|
//shared parameters
|
||||||
ConfigUtility& config;
|
|
||||||
UDPNetworkUtility& network;
|
UDPNetworkUtility& network;
|
||||||
int& clientIndex;
|
int& clientIndex;
|
||||||
int& accountIndex;
|
int& accountIndex;
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include "channels.hpp"
|
#include "channels.hpp"
|
||||||
#include "utility.hpp"
|
#include "utility.hpp"
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
@@ -31,14 +32,12 @@
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
InCombat::InCombat(
|
InCombat::InCombat(
|
||||||
ConfigUtility* const argConfig,
|
|
||||||
UDPNetworkUtility* const argNetwork,
|
UDPNetworkUtility* const argNetwork,
|
||||||
int* const argClientIndex,
|
int* const argClientIndex,
|
||||||
int* const argAccountIndex,
|
int* const argAccountIndex,
|
||||||
int* const argCharacterIndex,
|
int* const argCharacterIndex,
|
||||||
CharacterMap* argCharacterMap
|
CharacterMap* argCharacterMap
|
||||||
):
|
):
|
||||||
config(*argConfig),
|
|
||||||
network(*argNetwork),
|
network(*argNetwork),
|
||||||
clientIndex(*argClientIndex),
|
clientIndex(*argClientIndex),
|
||||||
accountIndex(*argAccountIndex),
|
accountIndex(*argAccountIndex),
|
||||||
|
|||||||
@@ -31,7 +31,6 @@
|
|||||||
#include "button.hpp"
|
#include "button.hpp"
|
||||||
|
|
||||||
//common
|
//common
|
||||||
#include "config_utility.hpp"
|
|
||||||
#include "frame_rate.hpp"
|
#include "frame_rate.hpp"
|
||||||
|
|
||||||
#include "character.hpp"
|
#include "character.hpp"
|
||||||
@@ -43,7 +42,6 @@ class InCombat : public BaseScene {
|
|||||||
public:
|
public:
|
||||||
//Public access members
|
//Public access members
|
||||||
InCombat(
|
InCombat(
|
||||||
ConfigUtility* const argConfig,
|
|
||||||
UDPNetworkUtility* const argNetwork,
|
UDPNetworkUtility* const argNetwork,
|
||||||
int* const argClientIndex,
|
int* const argClientIndex,
|
||||||
int* const argAccountIndex,
|
int* const argAccountIndex,
|
||||||
@@ -79,7 +77,6 @@ protected:
|
|||||||
void RequestShutdown();
|
void RequestShutdown();
|
||||||
|
|
||||||
//shared parameters
|
//shared parameters
|
||||||
ConfigUtility& config;
|
|
||||||
UDPNetworkUtility& network;
|
UDPNetworkUtility& network;
|
||||||
int& clientIndex;
|
int& clientIndex;
|
||||||
int& accountIndex;
|
int& accountIndex;
|
||||||
|
|||||||
+40
-12
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include "channels.hpp"
|
#include "channels.hpp"
|
||||||
#include "utility.hpp"
|
#include "utility.hpp"
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@@ -34,20 +35,20 @@
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
InWorld::InWorld(
|
InWorld::InWorld(
|
||||||
ConfigUtility* const argConfig,
|
|
||||||
UDPNetworkUtility* const argNetwork,
|
UDPNetworkUtility* const argNetwork,
|
||||||
int* const argClientIndex,
|
int* const argClientIndex,
|
||||||
int* const argAccountIndex,
|
int* const argAccountIndex,
|
||||||
int* const argCharacterIndex,
|
int* const argCharacterIndex,
|
||||||
CharacterMap* argCharacterMap
|
CharacterMap* argCharacterMap
|
||||||
):
|
):
|
||||||
config(*argConfig),
|
|
||||||
network(*argNetwork),
|
network(*argNetwork),
|
||||||
clientIndex(*argClientIndex),
|
clientIndex(*argClientIndex),
|
||||||
accountIndex(*argAccountIndex),
|
accountIndex(*argAccountIndex),
|
||||||
characterIndex(*argCharacterIndex),
|
characterIndex(*argCharacterIndex),
|
||||||
characterMap(*argCharacterMap)
|
characterMap(*argCharacterMap)
|
||||||
{
|
{
|
||||||
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
|
|
||||||
//setup the utility objects
|
//setup the utility objects
|
||||||
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
buttonImage.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
||||||
buttonImage.SetClipH(buttonImage.GetClipH()/3);
|
buttonImage.SetClipH(buttonImage.GetClipH()/3);
|
||||||
@@ -71,7 +72,8 @@ InWorld::InWorld(
|
|||||||
|
|
||||||
//load the tilesheet
|
//load the tilesheet
|
||||||
//TODO: add the tilesheet to the map system?
|
//TODO: add the tilesheet to the map system?
|
||||||
tileSheet.Load(config["dir.tilesets"] + "terrain.bmp", 12, 15);
|
//TODO: Tile size and tile sheet should be loaded elsewhere
|
||||||
|
tileSheet.Load(config["dir.tilesets"] + "terrain.bmp", 32, 32);
|
||||||
|
|
||||||
//request a sync
|
//request a sync
|
||||||
RequestSynchronize();
|
RequestSynchronize();
|
||||||
@@ -105,16 +107,41 @@ void InWorld::Update(double delta) {
|
|||||||
it.second.Update(delta);
|
it.second.Update(delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Check collisions here
|
|
||||||
|
|
||||||
//update the camera
|
|
||||||
if(localCharacter) {
|
|
||||||
camera.x = localCharacter->GetOrigin().x - camera.marginX;
|
|
||||||
camera.y = localCharacter->GetOrigin().y - camera.marginY;
|
|
||||||
}
|
|
||||||
|
|
||||||
//check the map
|
//check the map
|
||||||
UpdateMap();
|
UpdateMap();
|
||||||
|
|
||||||
|
//skip the rest
|
||||||
|
if (!localCharacter) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//check for collisions with the map
|
||||||
|
BoundingBox wallBounds = {0, 0, tileSheet.GetTileW(), tileSheet.GetTileH()};
|
||||||
|
const int xCount = localCharacter->GetBounds().w / wallBounds.w + 1;
|
||||||
|
const int yCount = localCharacter->GetBounds().h / wallBounds.h + 1;
|
||||||
|
|
||||||
|
for (int i = -1; i <= xCount; ++i) {
|
||||||
|
for (int j = -1; j <= yCount; ++j) {
|
||||||
|
//set the wall's position
|
||||||
|
wallBounds.x = wallBounds.w * i + snapToBase((double)wallBounds.w, localCharacter->GetOrigin().x);
|
||||||
|
wallBounds.y = wallBounds.h * j + snapToBase((double)wallBounds.h, localCharacter->GetOrigin().y);
|
||||||
|
|
||||||
|
if (!regionPager.GetSolid(wallBounds.x / wallBounds.w, wallBounds.y / wallBounds.h)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((localCharacter->GetOrigin() + localCharacter->GetBounds()).CheckOverlap(wallBounds)) {
|
||||||
|
localCharacter->SetOrigin(localCharacter->GetOrigin() - (localCharacter->GetMotion() * delta));
|
||||||
|
localCharacter->SetMotion({0,0});
|
||||||
|
localCharacter->CorrectSprite();
|
||||||
|
SendPlayerUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//update the camera
|
||||||
|
camera.x = localCharacter->GetOrigin().x - camera.marginX;
|
||||||
|
camera.y = localCharacter->GetOrigin().y - camera.marginY;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InWorld::FrameEnd() {
|
void InWorld::FrameEnd() {
|
||||||
@@ -276,10 +303,11 @@ void InWorld::HandleCharacterNew(CharacterPacket* const argPacket) {
|
|||||||
newCharacter.SetHandle(argPacket->handle);
|
newCharacter.SetHandle(argPacket->handle);
|
||||||
newCharacter.SetAvatar(argPacket->avatar);
|
newCharacter.SetAvatar(argPacket->avatar);
|
||||||
|
|
||||||
newCharacter.GetSprite()->LoadSurface(config["dir.sprites"] + newCharacter.GetAvatar(), 4, 4);
|
newCharacter.GetSprite()->LoadSurface(ConfigUtility::GetSingleton()["dir.sprites"] + newCharacter.GetAvatar(), 4, 4);
|
||||||
|
|
||||||
newCharacter.SetOrigin(argPacket->origin);
|
newCharacter.SetOrigin(argPacket->origin);
|
||||||
newCharacter.SetMotion(argPacket->motion);
|
newCharacter.SetMotion(argPacket->motion);
|
||||||
|
newCharacter.SetBounds({0, 16, 32, 32}); //TODO: magic numbers, fix this
|
||||||
|
|
||||||
(*newCharacter.GetStats()) = argPacket->stats;
|
(*newCharacter.GetStats()) = argPacket->stats;
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,6 @@
|
|||||||
#include "tile_sheet.hpp"
|
#include "tile_sheet.hpp"
|
||||||
|
|
||||||
//common
|
//common
|
||||||
#include "config_utility.hpp"
|
|
||||||
#include "frame_rate.hpp"
|
#include "frame_rate.hpp"
|
||||||
|
|
||||||
#include "character.hpp"
|
#include "character.hpp"
|
||||||
@@ -50,7 +49,6 @@ class InWorld : public BaseScene {
|
|||||||
public:
|
public:
|
||||||
//Public access members
|
//Public access members
|
||||||
InWorld(
|
InWorld(
|
||||||
ConfigUtility* const argConfig,
|
|
||||||
UDPNetworkUtility* const argNetwork,
|
UDPNetworkUtility* const argNetwork,
|
||||||
int* const argClientIndex,
|
int* const argClientIndex,
|
||||||
int* const argAccountIndex,
|
int* const argAccountIndex,
|
||||||
@@ -94,7 +92,6 @@ protected:
|
|||||||
void UpdateMap();
|
void UpdateMap();
|
||||||
|
|
||||||
//shared parameters
|
//shared parameters
|
||||||
ConfigUtility& config;
|
|
||||||
UDPNetworkUtility& network;
|
UDPNetworkUtility& network;
|
||||||
int& clientIndex;
|
int& clientIndex;
|
||||||
int& accountIndex;
|
int& accountIndex;
|
||||||
|
|||||||
@@ -31,12 +31,10 @@
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
LobbyMenu::LobbyMenu(
|
LobbyMenu::LobbyMenu(
|
||||||
ConfigUtility* const argConfig,
|
|
||||||
UDPNetworkUtility* const argNetwork,
|
UDPNetworkUtility* const argNetwork,
|
||||||
int* const argClientIndex,
|
int* const argClientIndex,
|
||||||
int* const argAccountIndex
|
int* const argAccountIndex
|
||||||
):
|
):
|
||||||
config(*argConfig),
|
|
||||||
network(*argNetwork),
|
network(*argNetwork),
|
||||||
clientIndex(*argClientIndex),
|
clientIndex(*argClientIndex),
|
||||||
accountIndex(*argAccountIndex)
|
accountIndex(*argAccountIndex)
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ class LobbyMenu : public BaseScene {
|
|||||||
public:
|
public:
|
||||||
//Public access members
|
//Public access members
|
||||||
LobbyMenu(
|
LobbyMenu(
|
||||||
ConfigUtility* const argConfig,
|
|
||||||
UDPNetworkUtility* const argNetwork,
|
UDPNetworkUtility* const argNetwork,
|
||||||
int* const argClientIndex,
|
int* const argClientIndex,
|
||||||
int* const argAccountIndex
|
int* const argAccountIndex
|
||||||
@@ -68,7 +67,7 @@ protected:
|
|||||||
void HandleJoinResponse(ClientPacket* const);
|
void HandleJoinResponse(ClientPacket* const);
|
||||||
|
|
||||||
//shared parameters
|
//shared parameters
|
||||||
ConfigUtility& config;
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
UDPNetworkUtility& network;
|
UDPNetworkUtility& network;
|
||||||
int& clientIndex;
|
int& clientIndex;
|
||||||
int& accountIndex;
|
int& accountIndex;
|
||||||
|
|||||||
@@ -21,13 +21,15 @@
|
|||||||
*/
|
*/
|
||||||
#include "main_menu.hpp"
|
#include "main_menu.hpp"
|
||||||
|
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Public access members
|
//Public access members
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
MainMenu::MainMenu(ConfigUtility* const argConfig):
|
MainMenu::MainMenu() {
|
||||||
config(*argConfig)
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
{
|
|
||||||
//setup the utility objects
|
//setup the utility objects
|
||||||
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
||||||
image.SetClipH(image.GetClipH()/3);
|
image.SetClipH(image.GetClipH()/3);
|
||||||
@@ -101,6 +103,7 @@ void MainMenu::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
void MainMenu::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||||
|
//TODO: Buttons should only register as "selected" when the left button is used
|
||||||
if (startButton.MouseButtonUp(button) == Button::State::HOVER) {
|
if (startButton.MouseButtonUp(button) == Button::State::HOVER) {
|
||||||
SetNextScene(SceneList::LOBBYMENU);
|
SetNextScene(SceneList::LOBBYMENU);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
#include "config_utility.hpp"
|
|
||||||
#include "image.hpp"
|
#include "image.hpp"
|
||||||
#include "raster_font.hpp"
|
#include "raster_font.hpp"
|
||||||
#include "button.hpp"
|
#include "button.hpp"
|
||||||
@@ -32,7 +31,7 @@
|
|||||||
class MainMenu : public BaseScene {
|
class MainMenu : public BaseScene {
|
||||||
public:
|
public:
|
||||||
//Public access members
|
//Public access members
|
||||||
MainMenu(ConfigUtility* const);
|
MainMenu();
|
||||||
~MainMenu();
|
~MainMenu();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -49,9 +48,6 @@ protected:
|
|||||||
void KeyDown(SDL_KeyboardEvent const&);
|
void KeyDown(SDL_KeyboardEvent const&);
|
||||||
void KeyUp(SDL_KeyboardEvent const&);
|
void KeyUp(SDL_KeyboardEvent const&);
|
||||||
|
|
||||||
//shared parameters
|
|
||||||
ConfigUtility& config;
|
|
||||||
|
|
||||||
//members
|
//members
|
||||||
Image image;
|
Image image;
|
||||||
RasterFont font;
|
RasterFont font;
|
||||||
|
|||||||
@@ -21,13 +21,15 @@
|
|||||||
*/
|
*/
|
||||||
#include "options_menu.hpp"
|
#include "options_menu.hpp"
|
||||||
|
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Public access members
|
//Public access members
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
OptionsMenu::OptionsMenu(ConfigUtility* const argConfig):
|
OptionsMenu::OptionsMenu() {
|
||||||
config(*argConfig)
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
{
|
|
||||||
//setup the utility objects
|
//setup the utility objects
|
||||||
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
image.LoadSurface(config["dir.interface"] + "button_menu.bmp");
|
||||||
image.SetClipH(image.GetClipH()/3);
|
image.SetClipH(image.GetClipH()/3);
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
#include "config_utility.hpp"
|
|
||||||
#include "image.hpp"
|
#include "image.hpp"
|
||||||
#include "raster_font.hpp"
|
#include "raster_font.hpp"
|
||||||
#include "button.hpp"
|
#include "button.hpp"
|
||||||
@@ -33,7 +32,7 @@
|
|||||||
class OptionsMenu : public BaseScene {
|
class OptionsMenu : public BaseScene {
|
||||||
public:
|
public:
|
||||||
//Public access members
|
//Public access members
|
||||||
OptionsMenu(ConfigUtility* const);
|
OptionsMenu();
|
||||||
~OptionsMenu();
|
~OptionsMenu();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -50,9 +49,6 @@ protected:
|
|||||||
void KeyDown(SDL_KeyboardEvent const&);
|
void KeyDown(SDL_KeyboardEvent const&);
|
||||||
void KeyUp(SDL_KeyboardEvent const&);
|
void KeyUp(SDL_KeyboardEvent const&);
|
||||||
|
|
||||||
//shared parameters
|
|
||||||
ConfigUtility& config;
|
|
||||||
|
|
||||||
//members
|
//members
|
||||||
Image image;
|
Image image;
|
||||||
RasterFont font;
|
RasterFont font;
|
||||||
|
|||||||
@@ -21,14 +21,14 @@
|
|||||||
*/
|
*/
|
||||||
#include "splash_screen.hpp"
|
#include "splash_screen.hpp"
|
||||||
|
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Public access members
|
//Public access members
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
SplashScreen::SplashScreen(ConfigUtility* const argConfig):
|
SplashScreen::SplashScreen() {
|
||||||
config(*argConfig)
|
logo.LoadSurface(ConfigUtility::GetSingleton()["dir.logos"] + "krstudios.bmp");
|
||||||
{
|
|
||||||
logo.LoadSurface(config["dir.logos"] + "krstudios.bmp");
|
|
||||||
startTick = std::chrono::steady_clock::now();
|
startTick = std::chrono::steady_clock::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
#include "config_utility.hpp"
|
|
||||||
#include "image.hpp"
|
#include "image.hpp"
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
@@ -32,7 +31,7 @@
|
|||||||
class SplashScreen : public BaseScene {
|
class SplashScreen : public BaseScene {
|
||||||
public:
|
public:
|
||||||
//Public access members
|
//Public access members
|
||||||
SplashScreen(ConfigUtility* const);
|
SplashScreen();
|
||||||
~SplashScreen();
|
~SplashScreen();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -40,9 +39,6 @@ protected:
|
|||||||
void Update(double delta);
|
void Update(double delta);
|
||||||
void Render(SDL_Surface* const);
|
void Render(SDL_Surface* const);
|
||||||
|
|
||||||
//shared parameters
|
|
||||||
ConfigUtility& config;
|
|
||||||
|
|
||||||
//members
|
//members
|
||||||
std::chrono::steady_clock::time_point startTick;
|
std::chrono::steady_clock::time_point startTick;
|
||||||
Image logo;
|
Image logo;
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#config
|
||||||
|
INCLUDES+=.
|
||||||
|
LIBS+=
|
||||||
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
#source
|
||||||
|
CXXSRC=$(wildcard *.cpp)
|
||||||
|
|
||||||
|
#objects
|
||||||
|
OBJDIR=obj
|
||||||
|
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
|
||||||
|
|
||||||
|
#output
|
||||||
|
OUTDIR=../..
|
||||||
|
OUT=$(addprefix $(OUTDIR)/,libcommon.a)
|
||||||
|
|
||||||
|
#targets
|
||||||
|
all: $(OBJ) $(OUT)
|
||||||
|
ar -crs $(OUT) $(OBJ)
|
||||||
|
|
||||||
|
$(OBJ): | $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUT): | $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR):
|
||||||
|
mkdir $(OBJDIR)
|
||||||
|
|
||||||
|
$(OUTDIR):
|
||||||
|
mkdir $(OUTDIR)
|
||||||
|
|
||||||
|
$(OBJDIR)/%.o: %.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) *.o *.a *.exe
|
||||||
|
|
||||||
|
rebuild: clean all
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "timer.hpp"
|
||||||
|
|
||||||
|
Timer::Timer(): start(Timer::Clock::now()) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer::Timer(std::string s): name(s), start(Timer::Clock::now()) {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void Timer::Start() {
|
||||||
|
start = Clock::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Timer::Stop() {
|
||||||
|
timeSpan = Clock::now() - start;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, Timer& t) {
|
||||||
|
os << t.GetName() << ": ";
|
||||||
|
os << std::chrono::duration_cast<std::chrono::milliseconds>(t.GetTime()).count();
|
||||||
|
os << "ms";
|
||||||
|
return os;
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#ifndef TIMER_HPP_
|
||||||
|
#define TIMER_HPP_
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <string>
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
|
class Timer {
|
||||||
|
public:
|
||||||
|
typedef std::chrono::high_resolution_clock Clock;
|
||||||
|
|
||||||
|
Timer();
|
||||||
|
Timer(std::string s);
|
||||||
|
~Timer() = default;
|
||||||
|
|
||||||
|
inline void Start();
|
||||||
|
inline void Stop();
|
||||||
|
|
||||||
|
//accessors and mutators
|
||||||
|
Clock::duration GetTime() { return timeSpan; }
|
||||||
|
|
||||||
|
std::string SetName(std::string s) { return name = s; }
|
||||||
|
std::string GetName() { return name; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string name;
|
||||||
|
Clock::time_point start;
|
||||||
|
Clock::duration timeSpan;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, Timer& t);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. ../map
|
INCLUDES+=.
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
all:
|
all:
|
||||||
|
$(MAKE) -C debugging
|
||||||
$(MAKE) -C gameplay
|
$(MAKE) -C gameplay
|
||||||
$(MAKE) -C graphics
|
$(MAKE) -C graphics
|
||||||
$(MAKE) -C map
|
$(MAKE) -C map
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. ../utilities
|
INCLUDES+=. ../graphics ../utilities
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
|||||||
+12
-13
@@ -78,28 +78,27 @@ static int getDepth(lua_State* L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int onLoad(lua_State* L) {
|
static int load(lua_State* L) {
|
||||||
//TODO: onLoad()
|
//EMPTY
|
||||||
lua_pushboolean(L, false);
|
lua_pushboolean(L, false);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int onSave(lua_State* L) {
|
static int save(lua_State* L) {
|
||||||
//TODO: onSave()
|
//EMPTY
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int onCreate(lua_State* L) {
|
static int create(lua_State* L) {
|
||||||
//TODO: onCreate()
|
//EMPTY
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int onUnload(lua_State* L) {
|
static int unload(lua_State* L) {
|
||||||
//TODO: onUnload()
|
//EMPTY
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: wrappers for the collision map
|
|
||||||
static const luaL_Reg regionLib[] = {
|
static const luaL_Reg regionLib[] = {
|
||||||
{"SetTile",setTile},
|
{"SetTile",setTile},
|
||||||
{"GetTile",getTile},
|
{"GetTile",getTile},
|
||||||
@@ -110,10 +109,10 @@ static const luaL_Reg regionLib[] = {
|
|||||||
{"GetWidth",getWidth},
|
{"GetWidth",getWidth},
|
||||||
{"GetHeight",getHeight},
|
{"GetHeight",getHeight},
|
||||||
{"GetDepth",getDepth},
|
{"GetDepth",getDepth},
|
||||||
{"OnLoad",onLoad},
|
{"Load",load},
|
||||||
{"OnSave",onSave},
|
{"Save",save},
|
||||||
{"OnCreate",onCreate},
|
{"Create",create},
|
||||||
{"OnUnload",onUnload},
|
{"Unload",unload},
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -24,10 +24,9 @@
|
|||||||
#include "region_pager_lua.hpp"
|
#include "region_pager_lua.hpp"
|
||||||
#include "region.hpp"
|
#include "region.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
//DOCS: These functions are just wrappers for the RegionPagerLua class
|
//DOCS: These glue functions simply wrap RegionPagerLua's methods
|
||||||
|
|
||||||
static int setTile(lua_State* L) {
|
static int setTile(lua_State* L) {
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
||||||
@@ -64,20 +63,6 @@ static int getRegion(lua_State* L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int setDirectory(lua_State* L) {
|
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
|
||||||
std::string s = pager->SetDirectory(lua_tostring(L, 2));
|
|
||||||
lua_pushstring(L, s.c_str());
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int getDirectory(lua_State* L) {
|
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
|
||||||
std::string s = pager->GetDirectory();
|
|
||||||
lua_pushstring(L, s.c_str());
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int loadRegion(lua_State* L) {
|
static int loadRegion(lua_State* L) {
|
||||||
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
RegionPagerLua* pager = reinterpret_cast<RegionPagerLua*>(lua_touserdata(L, 1));
|
||||||
Region* region = pager->LoadRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
Region* region = pager->LoadRegion(lua_tointeger(L, 2), lua_tointeger(L, 3));
|
||||||
@@ -105,14 +90,12 @@ static int unloadRegion(lua_State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const luaL_Reg pagerlib[] = {
|
static const luaL_Reg regionPagerLib[] = {
|
||||||
{"SetTile", setTile},
|
{"SetTile", setTile},
|
||||||
{"GetTile", getTile},
|
{"GetTile", getTile},
|
||||||
{"SetSolid", setSolid},
|
{"SetSolid", setSolid},
|
||||||
{"GetSolid", getSolid},
|
{"GetSolid", getSolid},
|
||||||
{"GetRegion", getRegion},
|
{"GetRegion", getRegion},
|
||||||
{"SetDirectory", setDirectory},
|
|
||||||
{"GetDirectory", getDirectory},
|
|
||||||
{"LoadRegion", loadRegion},
|
{"LoadRegion", loadRegion},
|
||||||
{"SaveRegion", saveRegion},
|
{"SaveRegion", saveRegion},
|
||||||
{"CreateRegion", createRegion},
|
{"CreateRegion", createRegion},
|
||||||
@@ -121,6 +104,6 @@ static const luaL_Reg pagerlib[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
LUAMOD_API int openRegionPagerAPI(lua_State* L) {
|
LUAMOD_API int openRegionPagerAPI(lua_State* L) {
|
||||||
luaL_newlib(L, pagerlib);
|
luaL_newlib(L, regionPagerLib);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -19,8 +19,8 @@
|
|||||||
* 3. This notice may not be removed or altered from any source
|
* 3. This notice may not be removed or altered from any source
|
||||||
* distribution.
|
* distribution.
|
||||||
*/
|
*/
|
||||||
#ifndef PAGERAPI_HPP_
|
#ifndef REGIONPAGERAPI_HPP_
|
||||||
#define PAGERAPI_HPP_
|
#define REGIONPAGERAPI_HPP_
|
||||||
|
|
||||||
#include "lua/lua.hpp"
|
#include "lua/lua.hpp"
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,9 @@ bool RegionPagerBase::GetSolid(int x, int y) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Region* RegionPagerBase::GetRegion(int x, int y) {
|
Region* RegionPagerBase::GetRegion(int x, int y) {
|
||||||
|
x = snapToBase(REGION_WIDTH, x);
|
||||||
|
y = snapToBase(REGION_HEIGHT, y);
|
||||||
|
|
||||||
//get the region by various means
|
//get the region by various means
|
||||||
Region* ptr = nullptr;
|
Region* ptr = nullptr;
|
||||||
ptr = FindRegion(x, y);
|
ptr = FindRegion(x, y);
|
||||||
|
|||||||
@@ -32,19 +32,18 @@ Region* RegionPagerLua::LoadRegion(int x, int y) {
|
|||||||
Region tmpRegion(x, y);
|
Region tmpRegion(x, y);
|
||||||
|
|
||||||
//API hook
|
//API hook
|
||||||
lua_getglobal(luaState, "Region");
|
lua_getglobal(lua, "Region");
|
||||||
lua_getfield(luaState, -1, "OnLoad");
|
lua_getfield(lua, -1, "Load");
|
||||||
lua_pushlightuserdata(luaState, &tmpRegion);
|
lua_pushlightuserdata(lua, &tmpRegion);
|
||||||
lua_pushstring(luaState, directory.c_str());
|
if (lua_pcall(lua, 1, 1, 0) != LUA_OK) {
|
||||||
if (lua_pcall(luaState, 2, 1, 0) != LUA_OK) {
|
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
|
||||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
|
|
||||||
}
|
}
|
||||||
//success or failure
|
//success or failure
|
||||||
if (!lua_toboolean(luaState, -1)) {
|
if (!lua_toboolean(lua, -1)) {
|
||||||
lua_pop(luaState, 2);
|
lua_pop(lua, 2);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
lua_pop(luaState, 2);
|
lua_pop(lua, 2);
|
||||||
regionList.push_front(tmpRegion);
|
regionList.push_front(tmpRegion);
|
||||||
return ®ionList.front();
|
return ®ionList.front();
|
||||||
}
|
}
|
||||||
@@ -54,14 +53,13 @@ Region* RegionPagerLua::SaveRegion(int x, int y) {
|
|||||||
Region* ptr = FindRegion(x, y);
|
Region* ptr = FindRegion(x, y);
|
||||||
if (ptr) {
|
if (ptr) {
|
||||||
//API hook
|
//API hook
|
||||||
lua_getglobal(luaState, "Region");
|
lua_getglobal(lua, "Region");
|
||||||
lua_getfield(luaState, -1, "OnSave");
|
lua_getfield(lua, -1, "Save");
|
||||||
lua_pushlightuserdata(luaState, ptr);
|
lua_pushlightuserdata(lua, ptr);
|
||||||
lua_pushstring(luaState, directory.c_str());
|
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) {
|
||||||
if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
|
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
|
||||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
|
|
||||||
}
|
}
|
||||||
lua_pop(luaState, 1);
|
lua_pop(lua, 1);
|
||||||
}
|
}
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
@@ -75,30 +73,29 @@ Region* RegionPagerLua::CreateRegion(int x, int y) {
|
|||||||
Region tmpRegion(x, y);
|
Region tmpRegion(x, y);
|
||||||
|
|
||||||
//API hook
|
//API hook
|
||||||
lua_getglobal(luaState, "Region");
|
lua_getglobal(lua, "Region");
|
||||||
lua_getfield(luaState, -1, "OnCreate");
|
lua_getfield(lua, -1, "Create");
|
||||||
lua_pushlightuserdata(luaState, &tmpRegion);
|
lua_pushlightuserdata(lua, &tmpRegion);
|
||||||
//TODO: parameters
|
//TODO: parameters
|
||||||
if (lua_pcall(luaState, 1, 0, 0) != LUA_OK) {
|
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) {
|
||||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
|
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
|
||||||
}
|
}
|
||||||
lua_pop(luaState, 1);
|
lua_pop(lua, 1);
|
||||||
regionList.push_front(tmpRegion);
|
regionList.push_front(tmpRegion);
|
||||||
return ®ionList.front();
|
return ®ionList.front();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegionPagerLua::UnloadRegion(int x, int y) {
|
void RegionPagerLua::UnloadRegion(int x, int y) {
|
||||||
lua_getglobal(luaState, "Region");
|
lua_getglobal(lua, "Region");
|
||||||
|
|
||||||
regionList.remove_if([&](Region& region) -> bool {
|
regionList.remove_if([&](Region& region) -> bool {
|
||||||
if (region.GetX() == x && region.GetY() == y) {
|
if (region.GetX() == x && region.GetY() == y) {
|
||||||
|
|
||||||
//API hook
|
//API hook
|
||||||
lua_getfield(luaState, -1, "OnUnload");
|
lua_getfield(lua, -1, "Unload");
|
||||||
lua_pushlightuserdata(luaState, ®ion);
|
lua_pushlightuserdata(lua, ®ion);
|
||||||
lua_pushstring(luaState, directory.c_str());
|
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) {
|
||||||
if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
|
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
|
||||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -106,22 +103,21 @@ void RegionPagerLua::UnloadRegion(int x, int y) {
|
|||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
lua_pop(luaState, 1);
|
lua_pop(lua, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegionPagerLua::UnloadAll() {
|
void RegionPagerLua::UnloadAll() {
|
||||||
lua_getglobal(luaState, "Region");
|
lua_getglobal(lua, "Region");
|
||||||
|
|
||||||
for (auto& it : regionList) {
|
for (auto& it : regionList) {
|
||||||
//API hook
|
//API hook
|
||||||
lua_getfield(luaState, -1, "OnUnload");
|
lua_getfield(lua, -1, "Unload");
|
||||||
lua_pushlightuserdata(luaState, &it);
|
lua_pushlightuserdata(lua, &it);
|
||||||
lua_pushstring(luaState, directory.c_str());
|
if (lua_pcall(lua, 1, 0, 0) != LUA_OK) {
|
||||||
if (lua_pcall(luaState, 2, 0, 0) != LUA_OK) {
|
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(lua, -1) ));
|
||||||
throw(std::runtime_error(std::string() + "Lua error: " + lua_tostring(luaState, -1) ));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lua_pop(luaState, 1);
|
lua_pop(lua, 1);
|
||||||
regionList.clear();
|
regionList.clear();
|
||||||
}
|
}
|
||||||
@@ -42,14 +42,10 @@ public:
|
|||||||
void UnloadAll() override;
|
void UnloadAll() override;
|
||||||
|
|
||||||
//accessors & mutators
|
//accessors & mutators
|
||||||
std::string SetDirectory(std::string s) { return directory = s; }
|
lua_State* SetLuaState(lua_State* L) { return lua = L; }
|
||||||
std::string GetDirectory() { return directory; }
|
lua_State* GetLuaState() { return lua; }
|
||||||
|
|
||||||
lua_State* SetLuaState(lua_State* L) { return luaState = L; }
|
|
||||||
lua_State* GetLuaState() { return luaState; }
|
|
||||||
protected:
|
protected:
|
||||||
std::string directory;
|
lua_State* lua = nullptr;
|
||||||
lua_State* luaState = nullptr;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -21,24 +21,24 @@
|
|||||||
*/
|
*/
|
||||||
#include "tile_sheet.hpp"
|
#include "tile_sheet.hpp"
|
||||||
|
|
||||||
void TileSheet::Load(std::string fname, int xc, int yc) {
|
void TileSheet::Load(std::string fname, int tileWidth, int tileHeight) {
|
||||||
XCount = xc;
|
|
||||||
YCount = yc;
|
|
||||||
image.LoadSurface(fname);
|
image.LoadSurface(fname);
|
||||||
image.SetClipW(image.GetClipW()/XCount);
|
image.SetClipW(tileWidth);
|
||||||
image.SetClipH(image.GetClipH()/YCount);
|
image.SetClipH(tileHeight);
|
||||||
|
xCount = image.GetSurface()->w / image.GetClipW();
|
||||||
|
yCount = image.GetSurface()->h / image.GetClipH();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileSheet::Unload() {
|
void TileSheet::Unload() {
|
||||||
image.FreeSurface();
|
image.FreeSurface();
|
||||||
XCount = YCount = 0;
|
xCount = yCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileSheet::DrawTo(SDL_Surface* const dest, int x, int y, Region::type_t tile) {
|
void TileSheet::DrawTileTo(SDL_Surface* const dest, int x, int y, Region::type_t tile) {
|
||||||
//0 is invisible
|
//0 is invisible
|
||||||
if (tile == 0) return;
|
if (tile == 0) return;
|
||||||
image.SetClipX((tile-1) % XCount * image.GetClipW());
|
image.SetClipX((tile-1) % xCount * image.GetClipW());
|
||||||
image.SetClipY((tile-1) / XCount * image.GetClipH());
|
image.SetClipY((tile-1) / xCount * image.GetClipH());
|
||||||
image.DrawTo(dest, x, y);
|
image.DrawTo(dest, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,8 +50,8 @@ void TileSheet::DrawRegionTo(SDL_Surface* const dest, Region* const region, int
|
|||||||
tile = region->GetTile(i, j, k);
|
tile = region->GetTile(i, j, k);
|
||||||
//0 is invisible
|
//0 is invisible
|
||||||
if (tile == 0) continue;
|
if (tile == 0) continue;
|
||||||
image.SetClipX((tile-1) % XCount * image.GetClipW());
|
image.SetClipX((tile-1) % xCount * image.GetClipW());
|
||||||
image.SetClipY((tile-1) / XCount * image.GetClipH());
|
image.SetClipY((tile-1) / xCount * image.GetClipH());
|
||||||
image.DrawTo(dest,
|
image.DrawTo(dest,
|
||||||
(region->GetX() + i) * image.GetClipW() - camX,
|
(region->GetX() + i) * image.GetClipW() - camX,
|
||||||
(region->GetY() + j) * image.GetClipH() - camY);
|
(region->GetY() + j) * image.GetClipH() - camY);
|
||||||
@@ -31,24 +31,24 @@
|
|||||||
class TileSheet {
|
class TileSheet {
|
||||||
public:
|
public:
|
||||||
TileSheet() = default;
|
TileSheet() = default;
|
||||||
TileSheet(std::string f, int x, int y) { Load(f, x, y); }
|
TileSheet(std::string f, int w, int h) { Load(f, w, h); }
|
||||||
~TileSheet() = default;
|
~TileSheet() = default;
|
||||||
|
|
||||||
void Load(std::string fname, int XCount, int YCount);
|
void Load(std::string fname, int tileWidth, int tileHeight);
|
||||||
void Unload();
|
void Unload();
|
||||||
|
|
||||||
void DrawTo(SDL_Surface* const dest, int x, int y, Region::type_t tile);
|
void DrawTileTo(SDL_Surface* const dest, int x, int y, Region::type_t tile);
|
||||||
void DrawRegionTo(SDL_Surface* const dest, Region* const region, int camX, int camY);
|
void DrawRegionTo(SDL_Surface* const dest, Region* const region, int camX, int camY);
|
||||||
|
|
||||||
//accessors
|
//accessors
|
||||||
Image* GetImage() { return ℑ }
|
Image* GetImage() { return ℑ }
|
||||||
int GetXCount() { return XCount; }
|
int GetXCount() { return xCount; }
|
||||||
int GetYCount() { return YCount; }
|
int GetYCount() { return yCount; }
|
||||||
int GetTileW() { return image.GetClipW(); }
|
int GetTileW() { return image.GetClipW(); }
|
||||||
int GetTileH() { return image.GetClipH(); }
|
int GetTileH() { return image.GetClipH(); }
|
||||||
private:
|
private:
|
||||||
Image image;
|
Image image;
|
||||||
int XCount = 0, YCount = 0;
|
int xCount = 0, yCount = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#include "tile_sheet_api.hpp"
|
||||||
|
|
||||||
|
#include "tile_sheet.hpp"
|
||||||
|
|
||||||
|
static int load(lua_State* L) {
|
||||||
|
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
|
||||||
|
sheet->Load(lua_tostring(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int unload(lua_State* L) {
|
||||||
|
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
|
||||||
|
sheet->Unload();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getXCount(lua_State* L) {
|
||||||
|
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
|
||||||
|
lua_pushinteger(L, sheet->GetXCount());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getYCount(lua_State* L) {
|
||||||
|
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
|
||||||
|
lua_pushinteger(L, sheet->GetYCount());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getTileW(lua_State* L) {
|
||||||
|
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
|
||||||
|
lua_pushinteger(L, sheet->GetTileW());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getTileH(lua_State* L) {
|
||||||
|
TileSheet* sheet = reinterpret_cast<TileSheet*>(lua_touserdata(L, 1));
|
||||||
|
lua_pushinteger(L, sheet->GetTileH());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const luaL_Reg tileSheetLib[] = {
|
||||||
|
{"Load",load},
|
||||||
|
{"Unload",unload},
|
||||||
|
{"GetXCount",getXCount},
|
||||||
|
{"GetYCount",getYCount},
|
||||||
|
{"GetTileW",getTileW},
|
||||||
|
{"GetTileH",getTileH},
|
||||||
|
{nullptr, nullptr}
|
||||||
|
};
|
||||||
|
|
||||||
|
LUAMOD_API int openTileSheetAPI(lua_State* L) {
|
||||||
|
luaL_newlib(L, tileSheetLib);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
@@ -19,24 +19,12 @@
|
|||||||
* 3. This notice may not be removed or altered from any source
|
* 3. This notice may not be removed or altered from any source
|
||||||
* distribution.
|
* distribution.
|
||||||
*/
|
*/
|
||||||
#ifndef SIMPLERNG_HPP_
|
#ifndef TILESHEETAPI_HPP_
|
||||||
#define SIMPLERNG_HPP_
|
#define TILESHEETAPI_HPP_
|
||||||
|
|
||||||
//a simple, stateless, random number generator
|
#include "lua/lua.hpp"
|
||||||
class SimpleRNG {
|
|
||||||
public:
|
|
||||||
SimpleRNG() { SetSeed(8891.0); }
|
|
||||||
SimpleRNG(double x) { SetSeed(x); }
|
|
||||||
|
|
||||||
double SetSeed(double s) { return seed = s; }
|
#define TORTUGA_TILE_SHEET_NAME "TileSheet"
|
||||||
double GetSeed() { return seed; }
|
LUAMOD_API int openTileSheetAPI(lua_State* L);
|
||||||
|
|
||||||
double operator()(double x) {
|
#endif
|
||||||
return (x + seed) * 11235.0 + 81321.0;
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
|
||||||
double seed;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013, 2014
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#ifndef BOUNDINGBOX_HPP_
|
||||||
|
#define BOUNDINGBOX_HPP_
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
class BoundingBox {
|
||||||
|
public:
|
||||||
|
//This is explicitly a POD
|
||||||
|
int x, y;
|
||||||
|
int w, h;
|
||||||
|
|
||||||
|
BoundingBox() = default;
|
||||||
|
BoundingBox(int i, int j, int k, int l): x(i), y(j), w(k), h(l) {};
|
||||||
|
~BoundingBox() = default;
|
||||||
|
BoundingBox& operator=(BoundingBox const&) = default;
|
||||||
|
|
||||||
|
int Size() {
|
||||||
|
return std::max(w*h,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CheckOverlap(BoundingBox rhs) {
|
||||||
|
return !(
|
||||||
|
x >= rhs.x + rhs.w ||
|
||||||
|
y >= rhs.y + rhs.h ||
|
||||||
|
rhs.x >= x + w ||
|
||||||
|
rhs.y >= y + h);
|
||||||
|
}
|
||||||
|
|
||||||
|
BoundingBox CalcOverlap(BoundingBox rhs) {
|
||||||
|
if (!CheckOverlap(rhs)) {
|
||||||
|
return {0, 0, 0, 0};
|
||||||
|
}
|
||||||
|
BoundingBox ret;
|
||||||
|
ret.x = std::max(x, rhs.x);
|
||||||
|
ret.y = std::max(y, rhs.y);
|
||||||
|
ret.w = std::min(x+w, rhs.x+rhs.w) - ret.x;
|
||||||
|
ret.h = std::min(y+h, rhs.y+rhs.h) - ret.y;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//This is explicitly a POD
|
||||||
|
static_assert(std::is_pod<Vector2>::value, "BoundingBox is not a POD");
|
||||||
|
|
||||||
|
#include "vector2.hpp"
|
||||||
|
|
||||||
|
//operators
|
||||||
|
inline BoundingBox operator+(BoundingBox b, Vector2 v) {
|
||||||
|
return {b.x + (int)v.x, b.y + (int)v.y, b.w, b.h};
|
||||||
|
}
|
||||||
|
inline BoundingBox operator+(Vector2 v, BoundingBox b) {
|
||||||
|
return b + v;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -25,25 +25,37 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
using namespace std;
|
void ConfigUtility::Load(std::string fname) {
|
||||||
|
//clear the stored configuration
|
||||||
|
configMap.clear();
|
||||||
|
//pass to the recursive method
|
||||||
|
configMap = Read(fname);
|
||||||
|
}
|
||||||
|
|
||||||
void ConfigUtility::Load(string fname) {
|
ConfigUtility::table_t ConfigUtility::Read(std::string fname) {
|
||||||
ifstream is(fname);
|
//read in and return this file's data
|
||||||
|
table_t retTable;
|
||||||
|
std::ifstream is(fname);
|
||||||
|
|
||||||
if (!is.is_open()) {
|
if (!is.is_open()) {
|
||||||
throw(runtime_error("Failed to open config file"));
|
std::string msg;
|
||||||
|
msg += "Failed to open a config file: ";
|
||||||
|
msg += fname;
|
||||||
|
throw(std::runtime_error(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
string key, val;
|
std::string key, val;
|
||||||
|
|
||||||
for (;;) { //forever
|
while(true) { //forever
|
||||||
//eat whitespace
|
//eat whitespace
|
||||||
while(isspace(is.peek()))
|
while(isspace(is.peek())) {
|
||||||
is.ignore();
|
is.ignore();
|
||||||
|
}
|
||||||
|
|
||||||
//end of file
|
//end of file
|
||||||
if (is.eof())
|
if (is.eof()) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
//skip comment lines
|
//skip comment lines
|
||||||
if (is.peek() == '#') {
|
if (is.peek() == '#') {
|
||||||
@@ -64,41 +76,54 @@ void ConfigUtility::Load(string fname) {
|
|||||||
while(key.size() && isspace(*(key.end()-1))) key.erase(key.end() - 1);
|
while(key.size() && isspace(*(key.end()-1))) key.erase(key.end() - 1);
|
||||||
while(val.size() && isspace(*(val.end()-1))) val.erase(val.end() - 1);
|
while(val.size() && isspace(*(val.end()-1))) val.erase(val.end() - 1);
|
||||||
|
|
||||||
//allow empty/wiped values
|
//disallow empty/wiped values
|
||||||
if (key.size() == 0) {
|
if (key.size() == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//save the pair
|
//save the pair
|
||||||
table[key] = val;
|
retTable[key] = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
is.close();
|
is.close();
|
||||||
|
|
||||||
|
//load in any subordinate config files
|
||||||
|
//TODO: Possibility of nesting config levels?
|
||||||
|
if (retTable.find("config.next") != retTable.end()) {
|
||||||
|
table_t subTable = Read(retTable["config.next"]);
|
||||||
|
retTable.insert(subTable.begin(), subTable.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
return retTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//Convert to a type
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
std::string& ConfigUtility::String(std::string s) {
|
std::string& ConfigUtility::String(std::string s) {
|
||||||
return table[s];
|
return configMap[s];
|
||||||
}
|
}
|
||||||
|
|
||||||
int ConfigUtility::Integer(std::string s) {
|
int ConfigUtility::Integer(std::string s) {
|
||||||
std::map<std::string, std::string>::iterator it = table.find(s);
|
table_t::iterator it = configMap.find(s);
|
||||||
if (it == table.end()) {
|
if (it == configMap.end()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return atoi(it->second.c_str());
|
return atoi(it->second.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
double ConfigUtility::Double(std::string s) {
|
double ConfigUtility::Double(std::string s) {
|
||||||
std::map<std::string, std::string>::iterator it = table.find(s);
|
table_t::iterator it = configMap.find(s);
|
||||||
if (it == table.end()) {
|
if (it == configMap.end()) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
return atof(it->second.c_str());
|
return atof(it->second.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfigUtility::Boolean(std::string s) {
|
bool ConfigUtility::Boolean(std::string s) {
|
||||||
std::map<std::string, std::string>::iterator it = table.find(s);
|
table_t::iterator it = configMap.find(s);
|
||||||
if (it == table.end()) {
|
if (it == configMap.end()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return it->second == "true";
|
return it->second == "true";
|
||||||
|
|||||||
@@ -22,14 +22,13 @@
|
|||||||
#ifndef CONFIGUTILITY_HPP_
|
#ifndef CONFIGUTILITY_HPP_
|
||||||
#define CONFIGUTILITY_HPP_
|
#define CONFIGUTILITY_HPP_
|
||||||
|
|
||||||
|
#include "singleton.hpp"
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class ConfigUtility {
|
class ConfigUtility : public Singleton<ConfigUtility> {
|
||||||
public:
|
public:
|
||||||
ConfigUtility() = default;
|
|
||||||
ConfigUtility(std::string s) { Load(s); }
|
|
||||||
|
|
||||||
void Load(std::string fname);
|
void Load(std::string fname);
|
||||||
|
|
||||||
//convert to a type
|
//convert to a type
|
||||||
@@ -39,22 +38,21 @@ public:
|
|||||||
bool Boolean(std::string);
|
bool Boolean(std::string);
|
||||||
|
|
||||||
//shorthand
|
//shorthand
|
||||||
std::string& operator[](std::string s) {
|
inline std::string& operator[](std::string s) { return configMap[s]; }
|
||||||
return String(s);
|
inline int Int(std::string s) { return Integer(s); }
|
||||||
}
|
inline bool Bool(std::string s) { return Boolean(s); }
|
||||||
int Int(std::string s) {
|
|
||||||
return Integer(s);
|
|
||||||
}
|
|
||||||
bool Bool(std::string s) {
|
|
||||||
return Boolean(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
//OO breaker
|
|
||||||
std::map<std::string, std::string>* GetMap() {
|
|
||||||
return &table;
|
|
||||||
}
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, std::string> table;
|
typedef std::map<std::string, std::string> table_t;
|
||||||
|
|
||||||
|
friend Singleton<ConfigUtility>;
|
||||||
|
|
||||||
|
ConfigUtility() = default;
|
||||||
|
~ConfigUtility() = default;
|
||||||
|
|
||||||
|
table_t Read(std::string fname);
|
||||||
|
|
||||||
|
table_t configMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#ifndef SINGLETON_HPP_
|
||||||
|
#define SINGLETON_HPP_
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class Singleton {
|
||||||
|
public:
|
||||||
|
static T& GetSingleton() {
|
||||||
|
if (!ptr) {
|
||||||
|
throw(std::logic_error("This singleton has not been created"));
|
||||||
|
}
|
||||||
|
return *ptr;
|
||||||
|
}
|
||||||
|
static void Create() {
|
||||||
|
if (ptr) {
|
||||||
|
throw(std::logic_error("This singleton has already been created"));
|
||||||
|
}
|
||||||
|
ptr = new T();
|
||||||
|
}
|
||||||
|
static void Delete() {
|
||||||
|
if (!ptr) {
|
||||||
|
throw(std::logic_error("A non-existant singleton cannot be deleted"));
|
||||||
|
}
|
||||||
|
delete ptr;
|
||||||
|
ptr = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Singleton() = default;
|
||||||
|
Singleton(Singleton const&) = default;
|
||||||
|
Singleton(Singleton&&) = default;
|
||||||
|
~Singleton() = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static T* ptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T* Singleton<T>::ptr = nullptr;
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -32,6 +32,10 @@ int snapToBase(int base, int x) {
|
|||||||
return x / base * base;
|
return x / base * base;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double snapToBase(double base, double x) {
|
||||||
|
return floor(x / base) * base;
|
||||||
|
}
|
||||||
|
|
||||||
std::string truncatePath(std::string pathname) {
|
std::string truncatePath(std::string pathname) {
|
||||||
return std::string(
|
return std::string(
|
||||||
std::find_if(
|
std::find_if(
|
||||||
|
|||||||
@@ -25,6 +25,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
int snapToBase(int base, int x);
|
int snapToBase(int base, int x);
|
||||||
|
double snapToBase(double base, double x);
|
||||||
|
|
||||||
std::string truncatePath(std::string pathname);
|
std::string truncatePath(std::string pathname);
|
||||||
|
|
||||||
//fixing known bugs in g++
|
//fixing known bugs in g++
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ public:
|
|||||||
}
|
}
|
||||||
void Normalize() {
|
void Normalize() {
|
||||||
double l = Length();
|
double l = Length();
|
||||||
|
if (l == 0)
|
||||||
|
throw(std::domain_error("Divide by zero"));
|
||||||
x /= l;
|
x /= l;
|
||||||
y /= l;
|
y /= l;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,9 @@
|
|||||||
#RM=del /y
|
#RM=del /y
|
||||||
|
|
||||||
#CXXFLAGS+=-static-libgcc -static-libstdc++ -g -fno-inline-functions -Wall
|
#CXXFLAGS+=-static-libgcc -static-libstdc++ -g -fno-inline-functions -Wall
|
||||||
CXXFLAGS+=-static-libgcc -static-libstdc++
|
#CXXFLAGS+=-static-libgcc -static-libstdc++
|
||||||
|
|
||||||
export
|
#export
|
||||||
|
|
||||||
OUTDIR=out
|
OUTDIR=out
|
||||||
|
|
||||||
@@ -15,6 +15,12 @@ all: $(OUTDIR)
|
|||||||
$(MAKE) -C server
|
$(MAKE) -C server
|
||||||
$(MAKE) -C client
|
$(MAKE) -C client
|
||||||
|
|
||||||
|
debug: export CXXFLAGS+=-g
|
||||||
|
debug: clean all
|
||||||
|
|
||||||
|
release: export CXXFLAGS+=-static-libgcc -static-libstdc++
|
||||||
|
release: clean all
|
||||||
|
|
||||||
$(OUTDIR):
|
$(OUTDIR):
|
||||||
mkdir $(OUTDIR)
|
mkdir $(OUTDIR)
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ server.name = local
|
|||||||
server.dbname = database.db
|
server.dbname = database.db
|
||||||
|
|
||||||
#client specific settings
|
#client specific settings
|
||||||
|
#client.screen.w = 800
|
||||||
|
#client.screen.h = 600
|
||||||
client.screen.f = false
|
client.screen.f = false
|
||||||
|
|
||||||
client.username = Kayne Ruse
|
client.username = Kayne Ruse
|
||||||
|
|||||||
@@ -1,38 +1,39 @@
|
|||||||
print("Lua script check")
|
print("Lua script check")
|
||||||
|
|
||||||
--uber lazy declarations
|
--uber lazy declarations
|
||||||
function square(x) return x*x end
|
function math.sqr(x) return x*x end
|
||||||
function distance(x, y, i, j) return math.sqrt(square(x - i) + square(y - j)) end
|
function math.dist(x, y, i, j) return math.sqrt(math.sqr(x - i) + math.sqr(y - j)) end
|
||||||
|
|
||||||
--tile macros, mapped to the tilesheet
|
--tile macros, mapped to the tilesheet
|
||||||
local base = 14
|
local base = 14
|
||||||
local shift = 36
|
local shift = 36
|
||||||
plains = base + shift * 0
|
tiles = {
|
||||||
grass = base + shift * 1
|
plains = base + shift * 0,
|
||||||
dirt = base + shift * 2
|
grass = base + shift * 1,
|
||||||
sand = base + shift * 3
|
dirt = base + shift * 2,
|
||||||
water = base + shift * 4
|
sand = base + shift * 3,
|
||||||
|
water = base + shift * 4
|
||||||
|
}
|
||||||
|
|
||||||
--Overwrite the original OnCreate with my own version
|
--could set custom generation systems here, that differ from the global generators, etc.
|
||||||
Region.hcOnCreate = Region.OnCreate
|
function Region.Create(region)
|
||||||
Region.OnCreate = function(region)
|
|
||||||
local ret = Region.hcOnCreate(region) --best practices
|
|
||||||
for i = 1, Region.GetWidth() do
|
for i = 1, Region.GetWidth() do
|
||||||
for j = 1, Region.GetHeight() do
|
for j = 1, Region.GetHeight() do
|
||||||
local dist = distance(0, 0, i + Region.GetX(region) -1, j + Region.GetY(region) -1)
|
local dist = math.dist(0, 0, i + Region.GetX(region) -1, j + Region.GetY(region) -1)
|
||||||
if dist < 10 then
|
if dist < 10 then
|
||||||
Region.SetTile(region, i, j, 1, plains)
|
Region.SetTile(region, i, j, 1, tiles.plains)
|
||||||
elseif dist < 12 then
|
elseif dist < 12 then
|
||||||
Region.SetTile(region, i, j, 1, sand)
|
Region.SetTile(region, i, j, 1, tiles.sand)
|
||||||
else
|
else
|
||||||
Region.SetTile(region, i, j, 1, water)
|
Region.SetTile(region, i, j, 1, tiles.water)
|
||||||
|
Region.SetSolid(region, i, j, true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return ret
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--Get some regions
|
--Get some regions
|
||||||
|
--BUG: The server fails without this
|
||||||
newRoom = RoomMgr.CreateRoom("overworld")
|
newRoom = RoomMgr.CreateRoom("overworld")
|
||||||
pager = Room.GetPager(newRoom)
|
pager = Room.GetPager(newRoom)
|
||||||
regionTable = {
|
regionTable = {
|
||||||
@@ -42,4 +43,4 @@ regionTable = {
|
|||||||
RegionPager.GetRegion(pager, Region.GetWidth() *-1, Region.GetHeight() *-1)
|
RegionPager.GetRegion(pager, Region.GetWidth() *-1, Region.GetHeight() *-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
print("Finished the lua script")
|
print("Finished the lua script")
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
|
|
||||||
#include "region_api.hpp"
|
#include "region_api.hpp"
|
||||||
#include "region_pager_api.hpp"
|
#include "region_pager_api.hpp"
|
||||||
|
#include "tile_sheet_api.hpp"
|
||||||
#include "room_api.hpp"
|
#include "room_api.hpp"
|
||||||
#include "room_mgr_api.hpp"
|
#include "room_mgr_api.hpp"
|
||||||
|
|
||||||
@@ -58,6 +59,7 @@ static const luaL_Reg loadedlibs[] = {
|
|||||||
//Tortuga's API
|
//Tortuga's API
|
||||||
{TORTUGA_REGION_NAME, openRegionAPI},
|
{TORTUGA_REGION_NAME, openRegionAPI},
|
||||||
{TORTUGA_REGION_PAGER_NAME, openRegionPagerAPI},
|
{TORTUGA_REGION_PAGER_NAME, openRegionPagerAPI},
|
||||||
|
{TORTUGA_TILE_SHEET_NAME, openTileSheetAPI},
|
||||||
{TORTUGA_ROOM_NAME, openRoomAPI},
|
{TORTUGA_ROOM_NAME, openRoomAPI},
|
||||||
{TORTUGA_ROOM_MGR_NAME, openRoomMgrAPI},
|
{TORTUGA_ROOM_MGR_NAME, openRoomMgrAPI},
|
||||||
|
|
||||||
|
|||||||
+13
-1
@@ -21,6 +21,9 @@
|
|||||||
*/
|
*/
|
||||||
#include "server_application.hpp"
|
#include "server_application.hpp"
|
||||||
|
|
||||||
|
//singletons
|
||||||
|
#include "config_utility.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@@ -28,10 +31,19 @@ using namespace std;
|
|||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
try {
|
try {
|
||||||
ServerApplication app;
|
//create the singletons
|
||||||
|
ConfigUtility::Create();
|
||||||
|
ServerApplication::Create();
|
||||||
|
|
||||||
|
//call the server's routines
|
||||||
|
ServerApplication& app = ServerApplication::GetSingleton();
|
||||||
app.Init(argc, argv);
|
app.Init(argc, argv);
|
||||||
app.Proc();
|
app.Proc();
|
||||||
app.Quit();
|
app.Quit();
|
||||||
|
|
||||||
|
//delete the singletons
|
||||||
|
ConfigUtility::Delete();
|
||||||
|
ServerApplication::Delete();
|
||||||
}
|
}
|
||||||
catch(exception& e) {
|
catch(exception& e) {
|
||||||
cerr << "Fatal exception thrown: " << e.what() << endl;
|
cerr << "Fatal exception thrown: " << e.what() << endl;
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. accounts characters combat enemies mapgen mapgen/generators rooms ../common/gameplay ../common/map ../common/network ../common/network/packet ../common/network/serial ../common/utilities
|
INCLUDES+=. accounts characters combat enemies mapgen mapgen/generators rooms ../common/debugging ../common/gameplay ../common/map ../common/network ../common/network/packet ../common/network/serial ../common/utilities
|
||||||
LIBS+=server.a ../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua -lsqlite3
|
LIBS+=server.a ../libcommon.a -lSDL_net -lwsock32 -liphlpapi -lmingw32 -lSDLmain -lSDL -llua -lsqlite3
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
//common utilities
|
//common utilities
|
||||||
#include "udp_network_utility.hpp"
|
#include "udp_network_utility.hpp"
|
||||||
#include "config_utility.hpp"
|
#include "config_utility.hpp"
|
||||||
|
#include "singleton.hpp"
|
||||||
|
|
||||||
//APIs
|
//APIs
|
||||||
#include "lua/lua.hpp"
|
#include "lua/lua.hpp"
|
||||||
@@ -42,17 +43,19 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
//The main application class
|
//The main application class
|
||||||
class ServerApplication {
|
class ServerApplication: public Singleton<ServerApplication> {
|
||||||
public:
|
public:
|
||||||
//public methods
|
//public methods
|
||||||
ServerApplication() = default;
|
|
||||||
~ServerApplication() = default;
|
|
||||||
|
|
||||||
void Init(int argc, char** argv);
|
void Init(int argc, char** argv);
|
||||||
void Proc();
|
void Proc();
|
||||||
void Quit();
|
void Quit();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend Singleton<ServerApplication>;
|
||||||
|
|
||||||
|
ServerApplication() = default;
|
||||||
|
~ServerApplication() = default;
|
||||||
|
|
||||||
//handle incoming traffic
|
//handle incoming traffic
|
||||||
void HandlePacket(SerialPacket* const);
|
void HandlePacket(SerialPacket* const);
|
||||||
|
|
||||||
@@ -83,7 +86,7 @@ private:
|
|||||||
sqlite3* database = nullptr;
|
sqlite3* database = nullptr;
|
||||||
lua_State* luaState = nullptr;
|
lua_State* luaState = nullptr;
|
||||||
UDPNetworkUtility network;
|
UDPNetworkUtility network;
|
||||||
ConfigUtility config;
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
|
|
||||||
//simple tables
|
//simple tables
|
||||||
std::map<int, ClientData> clientMap;
|
std::map<int, ClientData> clientMap;
|
||||||
|
|||||||
Reference in New Issue
Block a user