Merge branch 'rooms' into develop
This commit is contained in:
@@ -589,8 +589,6 @@ void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
|
|||||||
//ignore if this character doesn't exist
|
//ignore if this character doesn't exist
|
||||||
std::map<int, BaseCharacter>::iterator characterIt = characterMap.find(argPacket->characterIndex);
|
std::map<int, BaseCharacter>::iterator characterIt = characterMap.find(argPacket->characterIndex);
|
||||||
if (characterIt == characterMap.end()) {
|
if (characterIt == characterMap.end()) {
|
||||||
//debug
|
|
||||||
std::cout << "Ignoring character deletion" << std::endl;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=.
|
INCLUDES+=. ../map
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. ../graphics ../utilities
|
INCLUDES+=. ../utilities
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
//all map API headers
|
//all map API headers
|
||||||
#include "region_api.hpp"
|
#include "region_api.hpp"
|
||||||
#include "region_pager_api.hpp"
|
#include "region_pager_api.hpp"
|
||||||
#include "tile_sheet_api.hpp"
|
|
||||||
|
|
||||||
//useful "globals"
|
//useful "globals"
|
||||||
//...
|
//...
|
||||||
@@ -37,7 +36,6 @@ static const luaL_Reg funcs[] = {
|
|||||||
static const luaL_Reg libs[] = {
|
static const luaL_Reg libs[] = {
|
||||||
{"Region", openRegionAPI},
|
{"Region", openRegionAPI},
|
||||||
{"RegionPager", openRegionPagerAPI},
|
{"RegionPager", openRegionPagerAPI},
|
||||||
// {"TileSheet", openTileSheetAPI},
|
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,75 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013-2015
|
|
||||||
*
|
|
||||||
* 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;
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,6 @@ mapSystem = require "map_system"
|
|||||||
mapMaker = require "map_maker"
|
mapMaker = require "map_maker"
|
||||||
mapSaver = require "map_saver"
|
mapSaver = require "map_saver"
|
||||||
roomSystem = require "room_system"
|
roomSystem = require "room_system"
|
||||||
waypointSystem = require "waypoint_system"
|
|
||||||
|
|
||||||
local function dumpTable(t)
|
local function dumpTable(t)
|
||||||
print(t)
|
print(t)
|
||||||
@@ -15,53 +14,6 @@ end
|
|||||||
|
|
||||||
--NOTE: room 0 is the first that the client asks for, therefore it must exist
|
--NOTE: room 0 is the first that the client asks for, therefore it must exist
|
||||||
local overworld, uid = roomSystem.RoomManager.CreateRoom("overworld", "overworld.bmp")
|
local overworld, uid = roomSystem.RoomManager.CreateRoom("overworld", "overworld.bmp")
|
||||||
|
roomSystem.Room.Initialize(overworld, mapSaver.Load, mapSaver.Save, mapMaker.debugIsland, mapSaver.Save)
|
||||||
--NOTE: This is horrible; room initialization is important
|
|
||||||
mapSystem.RegionPager.SetOnLoad(roomSystem.Room.GetPager(overworld), mapSaver.Load)
|
|
||||||
mapSystem.RegionPager.SetOnSave(roomSystem.Room.GetPager(overworld), mapSaver.Save)
|
|
||||||
mapSystem.RegionPager.SetOnCreate(roomSystem.Room.GetPager(overworld), mapMaker.debugIsland)
|
|
||||||
mapSystem.RegionPager.SetOnUnload(roomSystem.Room.GetPager(overworld), mapSaver.Save)
|
|
||||||
|
|
||||||
print("Finished the lua script")
|
print("Finished the lua script")
|
||||||
|
|
||||||
--[[
|
|
||||||
debugging test
|
|
||||||
|
|
||||||
Ideal output:
|
|
||||||
|
|
||||||
-------------------------
|
|
||||||
pager: userdata: [memory location]
|
|
||||||
Size 0: 0
|
|
||||||
[debug output from load]
|
|
||||||
Size 1: 1
|
|
||||||
[debug output from save]
|
|
||||||
Size 2: 0
|
|
||||||
[debug output from load]
|
|
||||||
Size 3: 1
|
|
||||||
[debug output from save]
|
|
||||||
Size 4: 0
|
|
||||||
-------------------------
|
|
||||||
|
|
||||||
--]-]
|
|
||||||
|
|
||||||
print("-------------------------")
|
|
||||||
local pager = roomSystem.Room.GetPager(overworld)
|
|
||||||
|
|
||||||
print("pager:", pager)
|
|
||||||
|
|
||||||
print("Size 0:", mapSystem.RegionPager.ContainerSize(pager))
|
|
||||||
|
|
||||||
local regionFoo = mapSystem.RegionPager.GetRegion(pager, 0, 0)
|
|
||||||
print("Size 1:", mapSystem.RegionPager.ContainerSize(pager))
|
|
||||||
|
|
||||||
mapSystem.RegionPager.UnloadRegion(pager, regionFoo)
|
|
||||||
print("Size 2:", mapSystem.RegionPager.ContainerSize(pager))
|
|
||||||
|
|
||||||
local regionFoo = mapSystem.RegionPager.GetRegion(pager, 0, 0)
|
|
||||||
print("Size 3:", mapSystem.RegionPager.ContainerSize(pager))
|
|
||||||
|
|
||||||
mapSystem.RegionPager.UnloadRegion(pager, 0, 0)
|
|
||||||
print("Size 4:", mapSystem.RegionPager.ContainerSize(pager))
|
|
||||||
|
|
||||||
print("-------------------------")
|
|
||||||
--]]
|
|
||||||
@@ -33,14 +33,14 @@ Vector2 Entity::SetMotion(Vector2 v) {
|
|||||||
return motion = v;
|
return motion = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Entity::GetRoomIndex() {
|
int Entity::GetRoomIndex() const {
|
||||||
return roomIndex;
|
return roomIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Entity::GetOrigin() {
|
Vector2 Entity::GetOrigin() const {
|
||||||
return origin;
|
return origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Entity::GetMotion() {
|
Vector2 Entity::GetMotion() const {
|
||||||
return motion;
|
return motion;
|
||||||
}
|
}
|
||||||
@@ -32,9 +32,9 @@ public:
|
|||||||
Vector2 SetOrigin(Vector2 v);
|
Vector2 SetOrigin(Vector2 v);
|
||||||
Vector2 SetMotion(Vector2 v);
|
Vector2 SetMotion(Vector2 v);
|
||||||
|
|
||||||
int GetRoomIndex();
|
int GetRoomIndex() const;
|
||||||
Vector2 GetOrigin();
|
Vector2 GetOrigin() const;
|
||||||
Vector2 GetMotion();
|
Vector2 GetMotion() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Entity() = default;
|
Entity() = default;
|
||||||
|
|||||||
@@ -36,7 +36,9 @@
|
|||||||
|
|
||||||
#include "lua.hpp"
|
#include "lua.hpp"
|
||||||
|
|
||||||
|
#include "entity_api.hpp"
|
||||||
#include "map_system_api.hpp"
|
#include "map_system_api.hpp"
|
||||||
|
#include "monster_system_api.hpp"
|
||||||
#include "room_system_api.hpp"
|
#include "room_system_api.hpp"
|
||||||
#include "waypoint_system_api.hpp"
|
#include "waypoint_system_api.hpp"
|
||||||
|
|
||||||
@@ -59,7 +61,9 @@ static const luaL_Reg loadedlibs[] = {
|
|||||||
|
|
||||||
//these libs are preloaded and must be required before used
|
//these libs are preloaded and must be required before used
|
||||||
static const luaL_Reg preloadedlibs[] = {
|
static const luaL_Reg preloadedlibs[] = {
|
||||||
|
{TORTUGA_ENTITY_API, openEntityAPI},
|
||||||
{TORTUGA_MAP_SYSTEM_API, openMapSystemAPI},
|
{TORTUGA_MAP_SYSTEM_API, openMapSystemAPI},
|
||||||
|
{TORTUGA_MONSTER_SYSTEM_API, openMonsterSystemAPI},
|
||||||
{TORTUGA_ROOM_SYSTEM_API, openRoomSystemAPI},
|
{TORTUGA_ROOM_SYSTEM_API, openRoomSystemAPI},
|
||||||
{TORTUGA_WAYPOINT_SYSTEM_API, openWaypointSystemAPI},
|
{TORTUGA_WAYPOINT_SYSTEM_API, openWaypointSystemAPI},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@
|
|||||||
#include "character_manager.hpp"
|
#include "character_manager.hpp"
|
||||||
#include "client_manager.hpp"
|
#include "client_manager.hpp"
|
||||||
#include "config_utility.hpp"
|
#include "config_utility.hpp"
|
||||||
#include "monster_manager.hpp"
|
|
||||||
#include "room_manager.hpp"
|
#include "room_manager.hpp"
|
||||||
#include "udp_network_utility.hpp"
|
#include "udp_network_utility.hpp"
|
||||||
#include "waypoint_manager.hpp"
|
#include "waypoint_manager.hpp"
|
||||||
@@ -43,10 +42,8 @@ int main(int argc, char* argv[]) {
|
|||||||
CharacterManager::CreateSingleton();
|
CharacterManager::CreateSingleton();
|
||||||
ClientManager::CreateSingleton();
|
ClientManager::CreateSingleton();
|
||||||
ConfigUtility::CreateSingleton();
|
ConfigUtility::CreateSingleton();
|
||||||
MonsterManager::CreateSingleton();
|
|
||||||
RoomManager::CreateSingleton();
|
RoomManager::CreateSingleton();
|
||||||
UDPNetworkUtility::CreateSingleton();
|
UDPNetworkUtility::CreateSingleton();
|
||||||
WaypointManager::CreateSingleton();
|
|
||||||
|
|
||||||
//call the server's routines
|
//call the server's routines
|
||||||
ServerApplication::CreateSingleton();
|
ServerApplication::CreateSingleton();
|
||||||
@@ -63,10 +60,8 @@ int main(int argc, char* argv[]) {
|
|||||||
CharacterManager::DeleteSingleton();
|
CharacterManager::DeleteSingleton();
|
||||||
ClientManager::DeleteSingleton();
|
ClientManager::DeleteSingleton();
|
||||||
ConfigUtility::DeleteSingleton();
|
ConfigUtility::DeleteSingleton();
|
||||||
MonsterManager::DeleteSingleton();
|
|
||||||
RoomManager::DeleteSingleton();
|
RoomManager::DeleteSingleton();
|
||||||
UDPNetworkUtility::DeleteSingleton();
|
UDPNetworkUtility::DeleteSingleton();
|
||||||
WaypointManager::DeleteSingleton();
|
|
||||||
}
|
}
|
||||||
catch(exception& e) {
|
catch(exception& e) {
|
||||||
cerr << "Fatal exception thrown: " << e.what() << endl;
|
cerr << "Fatal exception thrown: " << e.what() << endl;
|
||||||
|
|||||||
@@ -23,11 +23,55 @@
|
|||||||
|
|
||||||
#include "monster_data.hpp"
|
#include "monster_data.hpp"
|
||||||
|
|
||||||
|
#include "entity_api.hpp"
|
||||||
|
|
||||||
|
static int setAvatar(lua_State* L) {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getAvatar(lua_State* L) {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
static int setScript(lua_State* L) {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getScript(lua_State* L) {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
static const luaL_Reg monsterLib[] = {
|
static const luaL_Reg monsterLib[] = {
|
||||||
|
{"SetAvatar", setAvatar},
|
||||||
|
{"GetAvatar", getAvatar},
|
||||||
|
{"SetScript", setScript},
|
||||||
|
{"GetScript", getScript},
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|
||||||
LUAMOD_API int openMonsterAPI(lua_State* L) {
|
LUAMOD_API int openMonsterAPI(lua_State* L) {
|
||||||
|
//the local table
|
||||||
luaL_newlib(L, monsterLib);
|
luaL_newlib(L, monsterLib);
|
||||||
|
|
||||||
|
//get the parent table
|
||||||
|
luaL_requiref(L, TORTUGA_ENTITY_API, openEntityAPI, false);
|
||||||
|
|
||||||
|
//clone the parent table into the local table
|
||||||
|
lua_pushnil(L); //first key
|
||||||
|
while(lua_next(L, -2)) {
|
||||||
|
//copy the key-value pair
|
||||||
|
lua_pushvalue(L, -2);
|
||||||
|
lua_pushvalue(L, -2);
|
||||||
|
|
||||||
|
//push the copy to the local table
|
||||||
|
lua_settable(L, -6);
|
||||||
|
|
||||||
|
//pop the original value before continuing
|
||||||
|
lua_pop(L, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
//remove the parent table, leaving the expanded child table
|
||||||
|
lua_pop(L, 1);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -25,14 +25,14 @@ std::string MonsterData::SetAvatar(std::string s) {
|
|||||||
return avatar = s;
|
return avatar = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MonsterData::SetScriptReference(int i) {
|
|
||||||
return scriptRef = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string MonsterData::GetAvatar() {
|
std::string MonsterData::GetAvatar() {
|
||||||
return avatar;
|
return avatar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int MonsterData::SetScriptReference(int i) {
|
||||||
|
return scriptRef = i;
|
||||||
|
}
|
||||||
|
|
||||||
int MonsterData::GetScriptReference() {
|
int MonsterData::GetScriptReference() {
|
||||||
return scriptRef;
|
return scriptRef;
|
||||||
}
|
}
|
||||||
@@ -32,9 +32,9 @@ public:
|
|||||||
~MonsterData() = default;
|
~MonsterData() = default;
|
||||||
|
|
||||||
std::string SetAvatar(std::string);
|
std::string SetAvatar(std::string);
|
||||||
int SetScriptReference(int);
|
|
||||||
|
|
||||||
std::string GetAvatar();
|
std::string GetAvatar();
|
||||||
|
|
||||||
|
int SetScriptReference(int);
|
||||||
int GetScriptReference();
|
int GetScriptReference();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -21,26 +21,22 @@
|
|||||||
*/
|
*/
|
||||||
#include "monster_manager.hpp"
|
#include "monster_manager.hpp"
|
||||||
|
|
||||||
|
MonsterManager::MonsterManager() {
|
||||||
|
//EMPTY
|
||||||
|
}
|
||||||
|
|
||||||
|
MonsterManager::~MonsterManager() {
|
||||||
|
UnloadAll();
|
||||||
|
}
|
||||||
|
|
||||||
int MonsterManager::Create(std::string) {
|
int MonsterManager::Create(std::string) {
|
||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
int MonsterManager::Load(std::string) {
|
|
||||||
//TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
int MonsterManager::Save(int uid) {
|
|
||||||
//TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
void MonsterManager::Unload(int uid) {
|
void MonsterManager::Unload(int uid) {
|
||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
void MonsterManager::Delete(int uid) {
|
|
||||||
//TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
void MonsterManager::UnloadAll() {
|
void MonsterManager::UnloadAll() {
|
||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
@@ -57,22 +53,10 @@ int MonsterManager::GetLoadedCount() {
|
|||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
int MonsterManager::GetTotalCount() {
|
|
||||||
//TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
std::map<int, MonsterData>* MonsterManager::GetContainer() {
|
std::map<int, MonsterData>* MonsterManager::GetContainer() {
|
||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlite3* MonsterManager::SetDatabase(sqlite3* db) {
|
|
||||||
//TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
sqlite3* MonsterManager::GetDatabase() {
|
|
||||||
//TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
lua_State* MonsterManager::SetLuaState(lua_State* L) {
|
lua_State* MonsterManager::SetLuaState(lua_State* L) {
|
||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
@@ -80,3 +64,11 @@ lua_State* MonsterManager::SetLuaState(lua_State* L) {
|
|||||||
lua_State* MonsterManager::GetLuaState() {
|
lua_State* MonsterManager::GetLuaState() {
|
||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sqlite3* MonsterManager::SetDatabase(sqlite3* db) {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite3* MonsterManager::GetDatabase() {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
#define MONSTERMANAGER_HPP_
|
#define MONSTERMANAGER_HPP_
|
||||||
|
|
||||||
#include "monster_data.hpp"
|
#include "monster_data.hpp"
|
||||||
#include "singleton.hpp"
|
|
||||||
|
|
||||||
#include "lua.hpp"
|
#include "lua.hpp"
|
||||||
#include "sqlite3.h"
|
#include "sqlite3.h"
|
||||||
@@ -32,14 +31,14 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class MonsterManager: public Singleton<MonsterManager> {
|
class MonsterManager {
|
||||||
public:
|
public:
|
||||||
|
MonsterManager();
|
||||||
|
~MonsterManager();
|
||||||
|
|
||||||
//common public methods
|
//common public methods
|
||||||
int Create(std::string);
|
int Create(std::string);
|
||||||
int Load(std::string);
|
|
||||||
int Save(int uid);
|
|
||||||
void Unload(int uid);
|
void Unload(int uid);
|
||||||
void Delete(int uid);
|
|
||||||
|
|
||||||
void UnloadAll();
|
void UnloadAll();
|
||||||
void UnloadIf(std::function<bool(std::pair<const int, MonsterData const&>)> fn);
|
void UnloadIf(std::function<bool(std::pair<const int, MonsterData const&>)> fn);
|
||||||
@@ -47,25 +46,19 @@ public:
|
|||||||
//accessors & mutators
|
//accessors & mutators
|
||||||
MonsterData* Get(int uid);
|
MonsterData* Get(int uid);
|
||||||
int GetLoadedCount();
|
int GetLoadedCount();
|
||||||
int GetTotalCount();
|
|
||||||
std::map<int, MonsterData>* GetContainer();
|
std::map<int, MonsterData>* GetContainer();
|
||||||
|
|
||||||
//hooks
|
//hooks
|
||||||
sqlite3* SetDatabase(sqlite3* db);
|
|
||||||
sqlite3* GetDatabase();
|
|
||||||
lua_State* SetLuaState(lua_State* L);
|
lua_State* SetLuaState(lua_State* L);
|
||||||
lua_State* GetLuaState();
|
lua_State* GetLuaState();
|
||||||
|
sqlite3* SetDatabase(sqlite3* db);
|
||||||
|
sqlite3* GetDatabase();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend Singleton<MonsterManager>;
|
|
||||||
|
|
||||||
MonsterManager() = default;
|
|
||||||
~MonsterManager() = default;
|
|
||||||
|
|
||||||
//members
|
//members
|
||||||
std::map<int, MonsterData> elementMap;
|
std::map<int, MonsterData> elementMap;
|
||||||
sqlite3* database = nullptr;
|
|
||||||
lua_State* lua = nullptr;
|
lua_State* lua = nullptr;
|
||||||
|
sqlite3* database = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2015
|
||||||
|
*
|
||||||
|
* 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 "monster_system_api.hpp"
|
||||||
|
|
||||||
|
//all monster API headers
|
||||||
|
#include "monster_api.hpp"
|
||||||
|
#include "monster_manager_api.hpp"
|
||||||
|
|
||||||
|
//useful "globals"
|
||||||
|
//...
|
||||||
|
|
||||||
|
//This mimics linit.c to create a nested collection of all monster modules.
|
||||||
|
static const luaL_Reg funcs[] = {
|
||||||
|
{nullptr, nullptr}
|
||||||
|
};
|
||||||
|
|
||||||
|
static const luaL_Reg libs[] = {
|
||||||
|
{"Monster", openMonsterAPI},
|
||||||
|
{"MonsterManager", openMonsterManagerAPI},
|
||||||
|
{nullptr, nullptr}
|
||||||
|
};
|
||||||
|
|
||||||
|
int openMonsterSystemAPI(lua_State* L) {
|
||||||
|
//create the table
|
||||||
|
luaL_newlibtable(L, libs);
|
||||||
|
|
||||||
|
//push the "global" functions
|
||||||
|
luaL_setfuncs(L, funcs, 0);
|
||||||
|
|
||||||
|
//push the substable
|
||||||
|
for (const luaL_Reg* lib = libs; lib->func; lib++) {
|
||||||
|
lib->func(L);
|
||||||
|
lua_setfield(L, -2, lib->name);
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
@@ -19,12 +19,12 @@
|
|||||||
* 3. This notice may not be removed or altered from any source
|
* 3. This notice may not be removed or altered from any source
|
||||||
* distribution.
|
* distribution.
|
||||||
*/
|
*/
|
||||||
#ifndef TILESHEETAPI_HPP_
|
#ifndef MONSTERSYSTEMAPI_HPP_
|
||||||
#define TILESHEETAPI_HPP_
|
#define MONSTERSYSTEMAPI_HPP_
|
||||||
|
|
||||||
#include "lua.hpp"
|
#include "lua.hpp"
|
||||||
|
|
||||||
#define TORTUGA_TILE_SHEET_NAME "tile_sheet"
|
#define TORTUGA_MONSTER_SYSTEM_API "monster_system"
|
||||||
LUAMOD_API int openTileSheetAPI(lua_State* L);
|
LUAMOD_API int openMonsterSystemAPI(lua_State* L);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#config
|
#config
|
||||||
INCLUDES+=. ../entities ../server_utilities ../../common/map ../../common/utilities
|
INCLUDES+=. ../entities ../monsters ../server_utilities ../waypoints ../../common/map ../../common/utilities
|
||||||
LIBS+=
|
LIBS+=
|
||||||
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
|
||||||
|
|
||||||
|
|||||||
@@ -53,11 +53,21 @@ static int getPager(lua_State* L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int getMonsterMgr(lua_State* L) {
|
||||||
|
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||||
|
lua_pushlightuserdata(L, reinterpret_cast<void*>(room->GetMonsterMgr()) );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getWaypointMgr(lua_State* L) {
|
||||||
|
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
|
||||||
|
lua_pushlightuserdata(L, reinterpret_cast<void*>(room->GetWaypointMgr()) );
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int initialize(lua_State* L) {
|
static int initialize(lua_State* L) {
|
||||||
//set the members of the given room
|
//TODO: This could fit into the room system's globals
|
||||||
RoomData* room = static_cast<RoomData*>(lua_touserdata(L, 1));
|
RoomData* room = static_cast<RoomData*>(lua_touserdata(L, 1));
|
||||||
room->SetName(lua_tostring(L, 2));
|
|
||||||
room->SetTileset(lua_tostring(L, 3));
|
|
||||||
|
|
||||||
//set the refs of these parameters (backwards, since it pops from the top of the stack)
|
//set the refs of these parameters (backwards, since it pops from the top of the stack)
|
||||||
room->GetPager()->SetUnloadReference(luaL_ref(L, LUA_REGISTRYINDEX));
|
room->GetPager()->SetUnloadReference(luaL_ref(L, LUA_REGISTRYINDEX));
|
||||||
@@ -70,11 +80,15 @@ static int initialize(lua_State* L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const luaL_Reg roomLib[] = {
|
static const luaL_Reg roomLib[] = {
|
||||||
{"GetPager",getPager},
|
|
||||||
{"SetName", setRoomName},
|
{"SetName", setRoomName},
|
||||||
{"GetName", getRoomName},
|
{"GetName", getRoomName},
|
||||||
{"SetTileset", setTilesetName},
|
{"SetTileset", setTilesetName},
|
||||||
{"GetTileset", getTilesetName},
|
{"GetTileset", getTilesetName},
|
||||||
|
|
||||||
|
{"GetPager",getPager},
|
||||||
|
{"GetMonsterMgr",getMonsterMgr},
|
||||||
|
{"GetWaypointMgr",getWaypointMgr},
|
||||||
|
|
||||||
{"Initialize", initialize},
|
{"Initialize", initialize},
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -41,6 +41,14 @@ RegionPagerLua* RoomData::GetPager() {
|
|||||||
return &pager;
|
return &pager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MonsterManager* RoomData::GetMonsterMgr() {
|
||||||
|
return &monsterMgr;
|
||||||
|
}
|
||||||
|
|
||||||
|
WaypointManager* RoomData::GetWaypointMgr() {
|
||||||
|
return &waypointMgr;
|
||||||
|
}
|
||||||
|
|
||||||
std::list<Entity*>* RoomData::GetEntityList() {
|
std::list<Entity*>* RoomData::GetEntityList() {
|
||||||
return &entityList;
|
return &entityList;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,9 @@
|
|||||||
#define ROOMDATA_HPP_
|
#define ROOMDATA_HPP_
|
||||||
|
|
||||||
#include "entity.hpp"
|
#include "entity.hpp"
|
||||||
|
#include "monster_manager.hpp"
|
||||||
#include "region_pager_lua.hpp"
|
#include "region_pager_lua.hpp"
|
||||||
|
#include "waypoint_manager.hpp"
|
||||||
|
|
||||||
#include "lua.hpp"
|
#include "lua.hpp"
|
||||||
|
|
||||||
@@ -43,6 +45,8 @@ public:
|
|||||||
std::string GetTileset();
|
std::string GetTileset();
|
||||||
|
|
||||||
RegionPagerLua* GetPager();
|
RegionPagerLua* GetPager();
|
||||||
|
MonsterManager* GetMonsterMgr();
|
||||||
|
WaypointManager* GetWaypointMgr();
|
||||||
std::list<Entity*>* GetEntityList();
|
std::list<Entity*>* GetEntityList();
|
||||||
|
|
||||||
//TODO: triggers for unload, save, per-second, player enter, player exit, etc.
|
//TODO: triggers for unload, save, per-second, player enter, player exit, etc.
|
||||||
@@ -55,6 +59,8 @@ private:
|
|||||||
std::string tilesetName;
|
std::string tilesetName;
|
||||||
|
|
||||||
RegionPagerLua pager;
|
RegionPagerLua pager;
|
||||||
|
MonsterManager monsterMgr;
|
||||||
|
WaypointManager waypointMgr;
|
||||||
std::list<Entity*> entityList;
|
std::list<Entity*> entityList;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ int RoomManager::Create(std::string roomName, std::string tileset) {
|
|||||||
newRoom->SetTileset(tileset);
|
newRoom->SetTileset(tileset);
|
||||||
|
|
||||||
newRoom->pager.SetLuaState(lua);
|
newRoom->pager.SetLuaState(lua);
|
||||||
|
newRoom->monsterMgr.SetLuaState(lua);
|
||||||
|
newRoom->monsterMgr.SetDatabase(database);
|
||||||
|
newRoom->waypointMgr.SetLuaState(lua);
|
||||||
|
|
||||||
//finish the routine
|
//finish the routine
|
||||||
return counter++;
|
return counter++;
|
||||||
@@ -57,6 +60,37 @@ void RoomManager::UnloadIf(std::function<bool(std::pair<const int, RoomData cons
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RoomManager::PushEntity(Entity* entity) {
|
||||||
|
if (!entity) {
|
||||||
|
throw(std::runtime_error("Failed to push a null entity to a room"));
|
||||||
|
}
|
||||||
|
|
||||||
|
RoomData* room = Get(entity->GetRoomIndex());
|
||||||
|
|
||||||
|
if (!room) {
|
||||||
|
throw(std::runtime_error("Failed to push an entity to a non-existant room"));
|
||||||
|
}
|
||||||
|
|
||||||
|
room->entityList.push_back(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RoomManager::PopEntity(Entity const* entity) {
|
||||||
|
//NOTE: to pop an entity from a room, the entity must first exist
|
||||||
|
if (!entity) {
|
||||||
|
throw(std::runtime_error("Failed to pop a null entity to a room"));
|
||||||
|
}
|
||||||
|
|
||||||
|
RoomData* room = Get(entity->GetRoomIndex());
|
||||||
|
|
||||||
|
if (!room) {
|
||||||
|
throw(std::runtime_error("Failed to pop an entity to a non-existant room"));
|
||||||
|
}
|
||||||
|
|
||||||
|
room->entityList.remove_if([entity](Entity* ptr) {
|
||||||
|
return entity == ptr;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
RoomData* RoomManager::Get(int uid) {
|
RoomData* RoomManager::Get(int uid) {
|
||||||
std::map<int, RoomData>::iterator it = elementMap.find(uid);
|
std::map<int, RoomData>::iterator it = elementMap.find(uid);
|
||||||
|
|
||||||
@@ -91,3 +125,11 @@ lua_State* RoomManager::SetLuaState(lua_State* L) {
|
|||||||
lua_State* RoomManager::GetLuaState() {
|
lua_State* RoomManager::GetLuaState() {
|
||||||
return lua;
|
return lua;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sqlite3* RoomManager::SetDatabase(sqlite3* db) {
|
||||||
|
return database = db;
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite3* RoomManager::GetDatabase() {
|
||||||
|
return database;
|
||||||
|
}
|
||||||
|
|||||||
@@ -22,10 +22,12 @@
|
|||||||
#ifndef ROOMMANAGER_HPP_
|
#ifndef ROOMMANAGER_HPP_
|
||||||
#define ROOMMANAGER_HPP_
|
#define ROOMMANAGER_HPP_
|
||||||
|
|
||||||
|
#include "entity.hpp"
|
||||||
#include "room_data.hpp"
|
#include "room_data.hpp"
|
||||||
#include "singleton.hpp"
|
#include "singleton.hpp"
|
||||||
|
|
||||||
#include "lua.hpp"
|
#include "lua.hpp"
|
||||||
|
#include "sqlite3.h"
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -38,6 +40,9 @@ public:
|
|||||||
void UnloadAll();
|
void UnloadAll();
|
||||||
void UnloadIf(std::function<bool(std::pair<const int, RoomData const&>)> fn);
|
void UnloadIf(std::function<bool(std::pair<const int, RoomData const&>)> fn);
|
||||||
|
|
||||||
|
void PushEntity(Entity* entity);
|
||||||
|
void PopEntity(Entity const* entity);
|
||||||
|
|
||||||
//accessors and mutators
|
//accessors and mutators
|
||||||
RoomData* Get(int uid);
|
RoomData* Get(int uid);
|
||||||
RoomData* Get(std::string name);
|
RoomData* Get(std::string name);
|
||||||
@@ -47,6 +52,8 @@ public:
|
|||||||
//hooks
|
//hooks
|
||||||
lua_State* SetLuaState(lua_State* L);
|
lua_State* SetLuaState(lua_State* L);
|
||||||
lua_State* GetLuaState();
|
lua_State* GetLuaState();
|
||||||
|
sqlite3* SetDatabase(sqlite3* db);
|
||||||
|
sqlite3* GetDatabase();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend Singleton<RoomManager>;
|
friend Singleton<RoomManager>;
|
||||||
@@ -57,6 +64,7 @@ private:
|
|||||||
//members
|
//members
|
||||||
std::map<int, RoomData> elementMap;
|
std::map<int, RoomData> elementMap;
|
||||||
lua_State* lua = nullptr;
|
lua_State* lua = nullptr;
|
||||||
|
sqlite3* database = nullptr;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,6 @@
|
|||||||
#include "client_manager.hpp"
|
#include "client_manager.hpp"
|
||||||
#include "monster_manager.hpp"
|
#include "monster_manager.hpp"
|
||||||
#include "room_manager.hpp"
|
#include "room_manager.hpp"
|
||||||
#include "waypoint_manager.hpp"
|
|
||||||
|
|
||||||
//utilities
|
//utilities
|
||||||
#include "config_utility.hpp"
|
#include "config_utility.hpp"
|
||||||
@@ -115,12 +114,10 @@ private:
|
|||||||
lua_State* luaState = nullptr;
|
lua_State* luaState = nullptr;
|
||||||
|
|
||||||
//ugly references; I hate this
|
//ugly references; I hate this
|
||||||
|
ClientManager& clientMgr = ClientManager::GetSingleton();
|
||||||
AccountManager& accountMgr = AccountManager::GetSingleton();
|
AccountManager& accountMgr = AccountManager::GetSingleton();
|
||||||
CharacterManager& characterMgr = CharacterManager::GetSingleton();
|
CharacterManager& characterMgr = CharacterManager::GetSingleton();
|
||||||
ClientManager& clientMgr = ClientManager::GetSingleton();
|
|
||||||
MonsterManager& monsterMgr = MonsterManager::GetSingleton();
|
|
||||||
RoomManager& roomMgr = RoomManager::GetSingleton();
|
RoomManager& roomMgr = RoomManager::GetSingleton();
|
||||||
WaypointManager& waypointMgr = WaypointManager::GetSingleton();
|
|
||||||
|
|
||||||
ConfigUtility& config = ConfigUtility::GetSingleton();
|
ConfigUtility& config = ConfigUtility::GetSingleton();
|
||||||
UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton();
|
UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton();
|
||||||
|
|||||||
@@ -45,6 +45,9 @@ void ServerApplication::HandleCharacterCreate(CharacterPacket* const argPacket)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//push to the rooms
|
||||||
|
roomMgr.PushEntity(characterMgr.Get(characterIndex));
|
||||||
|
|
||||||
//pump this character to all clients
|
//pump this character to all clients
|
||||||
CharacterPacket newPacket;
|
CharacterPacket newPacket;
|
||||||
CopyCharacterToPacket(&newPacket, characterIndex);
|
CopyCharacterToPacket(&newPacket, characterIndex);
|
||||||
@@ -86,6 +89,9 @@ void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//pop from the rooms
|
||||||
|
roomMgr.PopEntity(characterMgr.Get(characterIndex));
|
||||||
|
|
||||||
//delete the character
|
//delete the character
|
||||||
characterMgr.Delete(characterIndex);
|
characterMgr.Delete(characterIndex);
|
||||||
|
|
||||||
@@ -119,6 +125,9 @@ void ServerApplication::HandleCharacterLoad(CharacterPacket* const argPacket) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//push to the rooms
|
||||||
|
roomMgr.PushEntity(characterMgr.Get(characterIndex));
|
||||||
|
|
||||||
//pump this character to all clients
|
//pump this character to all clients
|
||||||
CharacterPacket newPacket;
|
CharacterPacket newPacket;
|
||||||
CopyCharacterToPacket(&newPacket, characterIndex);
|
CopyCharacterToPacket(&newPacket, characterIndex);
|
||||||
@@ -149,6 +158,9 @@ void ServerApplication::HandleCharacterUnload(CharacterPacket* const argPacket)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//pop from the rooms
|
||||||
|
roomMgr.PopEntity(characterData);
|
||||||
|
|
||||||
//unload the character
|
//unload the character
|
||||||
characterMgr.Unload(argPacket->characterIndex);
|
characterMgr.Unload(argPacket->characterIndex);
|
||||||
|
|
||||||
@@ -190,11 +202,17 @@ void ServerApplication::HandleCharacterSetRoom(CharacterPacket* const argPacket)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//pop from the old room
|
||||||
|
roomMgr.PopEntity(characterData);
|
||||||
|
|
||||||
//set the character's room, zero it's origin, zero it's motion
|
//set the character's room, zero it's origin, zero it's motion
|
||||||
characterData->SetRoomIndex(argPacket->roomIndex);
|
characterData->SetRoomIndex(argPacket->roomIndex);
|
||||||
characterData->SetOrigin({0, 0});
|
characterData->SetOrigin({0, 0});
|
||||||
characterData->SetMotion({0, 0});
|
characterData->SetMotion({0, 0});
|
||||||
|
|
||||||
|
//push to the new room
|
||||||
|
roomMgr.PushEntity(characterData);
|
||||||
|
|
||||||
//update the clients
|
//update the clients
|
||||||
CharacterPacket newPacket;
|
CharacterPacket newPacket;
|
||||||
CopyCharacterToPacket(&newPacket, argPacket->characterIndex);
|
CopyCharacterToPacket(&newPacket, argPacket->characterIndex);
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ void ServerApplication::Init(int argc, char* argv[]) {
|
|||||||
characterMgr.SetDatabase(database);
|
characterMgr.SetDatabase(database);
|
||||||
|
|
||||||
roomMgr.SetLuaState(luaState);
|
roomMgr.SetLuaState(luaState);
|
||||||
waypointMgr.SetLuaState(luaState);
|
roomMgr.SetDatabase(database);
|
||||||
|
|
||||||
std::cout << "Internal managers initialized" << std::endl;
|
std::cout << "Internal managers initialized" << std::endl;
|
||||||
|
|
||||||
@@ -202,9 +202,7 @@ void ServerApplication::Quit() {
|
|||||||
accountMgr.UnloadAll();
|
accountMgr.UnloadAll();
|
||||||
characterMgr.UnloadAll();
|
characterMgr.UnloadAll();
|
||||||
clientMgr.UnloadAll();
|
clientMgr.UnloadAll();
|
||||||
monsterMgr.UnloadAll();
|
|
||||||
roomMgr.UnloadAll();
|
roomMgr.UnloadAll();
|
||||||
waypointMgr.UnloadAll();
|
|
||||||
|
|
||||||
//APIs
|
//APIs
|
||||||
lua_close(luaState);
|
lua_close(luaState);
|
||||||
|
|||||||
@@ -149,6 +149,9 @@ void ServerApplication::FullCharacterUnload(int index) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//pop from the rooms
|
||||||
|
roomMgr.PopEntity(&character.second);
|
||||||
|
|
||||||
//pump character unload
|
//pump character unload
|
||||||
CharacterPacket newPacket;
|
CharacterPacket newPacket;
|
||||||
newPacket.type = SerialPacketType::CHARACTER_DELETE;
|
newPacket.type = SerialPacketType::CHARACTER_DELETE;
|
||||||
|
|||||||
@@ -23,8 +23,50 @@
|
|||||||
|
|
||||||
#include "waypoint_data.hpp"
|
#include "waypoint_data.hpp"
|
||||||
|
|
||||||
//TODO: Can I alias the entity API for this?
|
//TODO: return multiple values, dummy
|
||||||
|
|
||||||
|
//origin
|
||||||
|
static int setOrigin(lua_State* L) {
|
||||||
|
//TODO
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getOrigin(lua_State* L) {
|
||||||
|
//TODO
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//bounds
|
||||||
|
static int setBoundingBox(lua_State* L) {
|
||||||
|
//TODO
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getBoundingBox(lua_State* L) {
|
||||||
|
//TODO
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//triggers
|
||||||
|
static int setTriggerReference(lua_State* L) {
|
||||||
|
//TODO
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getTriggerReference(lua_State* L) {
|
||||||
|
//TODO
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static const luaL_Reg waypointLib[] = {
|
static const luaL_Reg waypointLib[] = {
|
||||||
|
{"SetOrigin",setOrigin},
|
||||||
|
{"GetOrigin",getOrigin},
|
||||||
|
|
||||||
|
{"SetBounds",setBoundingBox},
|
||||||
|
{"GetBounds",getBoundingBox},
|
||||||
|
|
||||||
|
{"SetTrigger",setTriggerReference},
|
||||||
|
{"GetTrigger",getTriggerReference},
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -27,4 +27,20 @@ int WaypointData::SetTriggerReference(int i) {
|
|||||||
|
|
||||||
int WaypointData::GetTriggerReference() {
|
int WaypointData::GetTriggerReference() {
|
||||||
return triggerRef;
|
return triggerRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BoundingBox WaypointData::SetBoundingBox(BoundingBox b) {
|
||||||
|
return bounds = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
BoundingBox WaypointData::GetBoundingBox() {
|
||||||
|
return bounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2 WaypointData::SetOrigin(Vector2 v) {
|
||||||
|
return origin = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2 WaypointData::GetOrigin() {
|
||||||
|
return origin;
|
||||||
|
}
|
||||||
|
|||||||
@@ -22,23 +22,32 @@
|
|||||||
#ifndef WAYPOINTDATA_HPP_
|
#ifndef WAYPOINTDATA_HPP_
|
||||||
#define WAYPOINTDATA_HPP_
|
#define WAYPOINTDATA_HPP_
|
||||||
|
|
||||||
#include "entity.hpp"
|
#include "bounding_box.hpp"
|
||||||
|
#include "vector2.hpp"
|
||||||
|
|
||||||
#include "lua.hpp"
|
#include "lua.hpp"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class WaypointData: public Entity {
|
class WaypointData {
|
||||||
public:
|
public:
|
||||||
WaypointData() = default;
|
WaypointData() = default;
|
||||||
~WaypointData() = default;
|
~WaypointData() = default;
|
||||||
|
|
||||||
|
Vector2 SetOrigin(Vector2 v);
|
||||||
|
Vector2 GetOrigin();
|
||||||
|
|
||||||
|
BoundingBox SetBoundingBox(BoundingBox b);
|
||||||
|
BoundingBox GetBoundingBox();
|
||||||
|
|
||||||
int SetTriggerReference(int i);
|
int SetTriggerReference(int i);
|
||||||
int GetTriggerReference();
|
int GetTriggerReference();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class WaypointManager;
|
friend class WaypointManager;
|
||||||
|
|
||||||
|
Vector2 origin;
|
||||||
|
BoundingBox bounds;
|
||||||
int triggerRef = LUA_NOREF;
|
int triggerRef = LUA_NOREF;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -21,46 +21,78 @@
|
|||||||
*/
|
*/
|
||||||
#include "waypoint_manager.hpp"
|
#include "waypoint_manager.hpp"
|
||||||
|
|
||||||
|
WaypointManager::WaypointManager() {
|
||||||
|
//EMPTY
|
||||||
|
}
|
||||||
|
|
||||||
|
WaypointManager::~WaypointManager() {
|
||||||
|
UnloadAll();
|
||||||
|
}
|
||||||
|
|
||||||
int WaypointManager::Create() {
|
int WaypointManager::Create() {
|
||||||
//TODO
|
//implicitly creates the element
|
||||||
|
WaypointData& waypointData = elementMap[counter];
|
||||||
|
|
||||||
|
//no real values set
|
||||||
|
waypointData.origin = {0, 0};
|
||||||
|
waypointData.bounds = {0, 0, 0, 0};
|
||||||
|
|
||||||
|
return counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WaypointManager::Load() {
|
int WaypointManager::Create(Vector2 origin, BoundingBox bounds) {
|
||||||
//TODO
|
//implicitly creates the element
|
||||||
}
|
WaypointData& waypointData = elementMap[counter];
|
||||||
|
|
||||||
int WaypointManager::Save(int uid) {
|
waypointData.origin = origin;
|
||||||
//TODO
|
waypointData.bounds = bounds;
|
||||||
|
|
||||||
|
return counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaypointManager::Unload(int uid) {
|
void WaypointManager::Unload(int uid) {
|
||||||
//TODO
|
elementMap.erase(uid);
|
||||||
}
|
|
||||||
|
|
||||||
void WaypointManager::Delete(int uid) {
|
|
||||||
//TODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaypointManager::UnloadAll() {
|
void WaypointManager::UnloadAll() {
|
||||||
//TODO
|
elementMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaypointManager::UnloadIf(std::function<bool(std::pair<const int, WaypointData const&>)> fn) {
|
void WaypointManager::UnloadIf(std::function<bool(std::pair<const int, WaypointData const&>)> fn) {
|
||||||
//TODO
|
std::map<int, WaypointData>::iterator it = elementMap.begin();
|
||||||
|
while (it != elementMap.end()) {
|
||||||
|
if (fn(*it)) {
|
||||||
|
it = elementMap.erase(it);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WaypointData* WaypointManager::Get(int uid) {
|
WaypointData* WaypointManager::Get(int uid) {
|
||||||
//TODO
|
std::map<int, WaypointData>::iterator it = elementMap.find(uid);
|
||||||
|
|
||||||
|
if (it == elementMap.end()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return &it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
int WaypointManager::GetLoadedCount() {
|
int WaypointManager::GetLoadedCount() {
|
||||||
//TODO
|
return elementMap.size();
|
||||||
}
|
|
||||||
|
|
||||||
int WaypointManager::GetTotalCount() {
|
|
||||||
//TODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<int, WaypointData>* WaypointManager::GetContainer() {
|
std::map<int, WaypointData>* WaypointManager::GetContainer() {
|
||||||
//TODO
|
return &elementMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//hooks
|
||||||
|
lua_State* WaypointManager::SetLuaState(lua_State* L) {
|
||||||
|
return lua = L;
|
||||||
|
}
|
||||||
|
|
||||||
|
lua_State* WaypointManager::GetLuaState() {
|
||||||
|
return lua;
|
||||||
|
}
|
||||||
@@ -22,9 +22,9 @@
|
|||||||
#ifndef WAYPOINTMANAGER_HPP_
|
#ifndef WAYPOINTMANAGER_HPP_
|
||||||
#define WAYPOINTMANAGER_HPP_
|
#define WAYPOINTMANAGER_HPP_
|
||||||
|
|
||||||
#include "waypoint_data.hpp"
|
#include "bounding_box.hpp"
|
||||||
#include "singleton.hpp"
|
|
||||||
#include "vector2.hpp"
|
#include "vector2.hpp"
|
||||||
|
#include "waypoint_data.hpp"
|
||||||
|
|
||||||
#include "lua.hpp"
|
#include "lua.hpp"
|
||||||
|
|
||||||
@@ -32,15 +32,15 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
//TODO: should waypoints be managed on a per-room basis?
|
class WaypointManager {
|
||||||
class WaypointManager: public Singleton<WaypointManager> {
|
|
||||||
public:
|
public:
|
||||||
|
WaypointManager();
|
||||||
|
~WaypointManager();
|
||||||
|
|
||||||
//common public methods
|
//common public methods
|
||||||
int Create();
|
int Create();
|
||||||
int Load();
|
int Create(Vector2 origin, BoundingBox bounds);
|
||||||
int Save(int uid);
|
|
||||||
void Unload(int uid);
|
void Unload(int uid);
|
||||||
void Delete(int uid);
|
|
||||||
|
|
||||||
void UnloadAll();
|
void UnloadAll();
|
||||||
void UnloadIf(std::function<bool(std::pair<const int, WaypointData const&>)> fn);
|
void UnloadIf(std::function<bool(std::pair<const int, WaypointData const&>)> fn);
|
||||||
@@ -48,19 +48,13 @@ public:
|
|||||||
//accessors & mutators
|
//accessors & mutators
|
||||||
WaypointData* Get(int uid);
|
WaypointData* Get(int uid);
|
||||||
int GetLoadedCount();
|
int GetLoadedCount();
|
||||||
int GetTotalCount();
|
|
||||||
std::map<int, WaypointData>* GetContainer();
|
std::map<int, WaypointData>* GetContainer();
|
||||||
|
|
||||||
//hooks
|
//hooks
|
||||||
lua_State* SetLuaState(lua_State* L) { return lua = L; }
|
lua_State* SetLuaState(lua_State* L);
|
||||||
lua_State* GetLuaState() { return lua; }
|
lua_State* GetLuaState();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend Singleton<WaypointManager>;
|
|
||||||
|
|
||||||
WaypointManager() = default;
|
|
||||||
~WaypointManager() = default;
|
|
||||||
|
|
||||||
//members
|
//members
|
||||||
std::map<int, WaypointData> elementMap;
|
std::map<int, WaypointData> elementMap;
|
||||||
lua_State* lua = nullptr;
|
lua_State* lua = nullptr;
|
||||||
|
|||||||
@@ -23,7 +23,27 @@
|
|||||||
|
|
||||||
#include "waypoint_manager.hpp"
|
#include "waypoint_manager.hpp"
|
||||||
|
|
||||||
|
static int create(lua_State* L) {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
static int unload(lua_State* L) {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getWaypoint(lua_State* L) {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
static int getLoadedCount(lua_State* L) {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
static const luaL_Reg waypointManagerLib[] = {
|
static const luaL_Reg waypointManagerLib[] = {
|
||||||
|
{"Create",create},
|
||||||
|
{"Unload",unload},
|
||||||
|
{"GetWaypoint",getWaypoint},
|
||||||
|
{"GetCount",getLoadedCount},
|
||||||
{nullptr, nullptr}
|
{nullptr, nullptr}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -17,3 +17,4 @@ TODO: Make a way for the server owner to control the server directly
|
|||||||
TODO: The TileSheet class should implement the surface itself
|
TODO: The TileSheet class should implement the surface itself
|
||||||
TODO: Time delay for requesting region packets
|
TODO: Time delay for requesting region packets
|
||||||
TODO: A proper logging system
|
TODO: A proper logging system
|
||||||
|
TODO: Fix the const-ness of accessors
|
||||||
Reference in New Issue
Block a user