Merge branch 'rooms' into develop

This commit is contained in:
Kayne Ruse
2015-01-11 20:13:34 +11:00
36 changed files with 405 additions and 241 deletions
-2
View File
@@ -589,8 +589,6 @@ void InWorld::HandleCharacterDelete(CharacterPacket* const argPacket) {
//ignore if this character doesn't exist
std::map<int, BaseCharacter>::iterator characterIt = characterMap.find(argPacket->characterIndex);
if (characterIt == characterMap.end()) {
//debug
std::cout << "Ignoring character deletion" << std::endl;
return;
}
+1 -1
View File
@@ -1,5 +1,5 @@
#config
INCLUDES+=.
INCLUDES+=. ../map
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
+1 -1
View File
@@ -1,5 +1,5 @@
#config
INCLUDES+=. ../graphics ../utilities
INCLUDES+=. ../utilities
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
-2
View File
@@ -24,7 +24,6 @@
//all map API headers
#include "region_api.hpp"
#include "region_pager_api.hpp"
#include "tile_sheet_api.hpp"
//useful "globals"
//...
@@ -37,7 +36,6 @@ static const luaL_Reg funcs[] = {
static const luaL_Reg libs[] = {
{"Region", openRegionAPI},
{"RegionPager", openRegionPagerAPI},
// {"TileSheet", openTileSheetAPI},
{nullptr, nullptr}
};
-75
View File
@@ -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;
}
+1 -49
View File
@@ -4,7 +4,6 @@ mapSystem = require "map_system"
mapMaker = require "map_maker"
mapSaver = require "map_saver"
roomSystem = require "room_system"
waypointSystem = require "waypoint_system"
local function dumpTable(t)
print(t)
@@ -15,53 +14,6 @@ end
--NOTE: room 0 is the first that the client asks for, therefore it must exist
local overworld, uid = roomSystem.RoomManager.CreateRoom("overworld", "overworld.bmp")
--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)
roomSystem.Room.Initialize(overworld, mapSaver.Load, mapSaver.Save, mapMaker.debugIsland, mapSaver.Save)
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("-------------------------")
--]]
+3 -3
View File
@@ -33,14 +33,14 @@ Vector2 Entity::SetMotion(Vector2 v) {
return motion = v;
}
int Entity::GetRoomIndex() {
int Entity::GetRoomIndex() const {
return roomIndex;
}
Vector2 Entity::GetOrigin() {
Vector2 Entity::GetOrigin() const {
return origin;
}
Vector2 Entity::GetMotion() {
Vector2 Entity::GetMotion() const {
return motion;
}
+3 -3
View File
@@ -32,9 +32,9 @@ public:
Vector2 SetOrigin(Vector2 v);
Vector2 SetMotion(Vector2 v);
int GetRoomIndex();
Vector2 GetOrigin();
Vector2 GetMotion();
int GetRoomIndex() const;
Vector2 GetOrigin() const;
Vector2 GetMotion() const;
protected:
Entity() = default;
+4
View File
@@ -36,7 +36,9 @@
#include "lua.hpp"
#include "entity_api.hpp"
#include "map_system_api.hpp"
#include "monster_system_api.hpp"
#include "room_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
static const luaL_Reg preloadedlibs[] = {
{TORTUGA_ENTITY_API, openEntityAPI},
{TORTUGA_MAP_SYSTEM_API, openMapSystemAPI},
{TORTUGA_MONSTER_SYSTEM_API, openMonsterSystemAPI},
{TORTUGA_ROOM_SYSTEM_API, openRoomSystemAPI},
{TORTUGA_WAYPOINT_SYSTEM_API, openWaypointSystemAPI},
{NULL, NULL}
-5
View File
@@ -26,7 +26,6 @@
#include "character_manager.hpp"
#include "client_manager.hpp"
#include "config_utility.hpp"
#include "monster_manager.hpp"
#include "room_manager.hpp"
#include "udp_network_utility.hpp"
#include "waypoint_manager.hpp"
@@ -43,10 +42,8 @@ int main(int argc, char* argv[]) {
CharacterManager::CreateSingleton();
ClientManager::CreateSingleton();
ConfigUtility::CreateSingleton();
MonsterManager::CreateSingleton();
RoomManager::CreateSingleton();
UDPNetworkUtility::CreateSingleton();
WaypointManager::CreateSingleton();
//call the server's routines
ServerApplication::CreateSingleton();
@@ -63,10 +60,8 @@ int main(int argc, char* argv[]) {
CharacterManager::DeleteSingleton();
ClientManager::DeleteSingleton();
ConfigUtility::DeleteSingleton();
MonsterManager::DeleteSingleton();
RoomManager::DeleteSingleton();
UDPNetworkUtility::DeleteSingleton();
WaypointManager::DeleteSingleton();
}
catch(exception& e) {
cerr << "Fatal exception thrown: " << e.what() << endl;
+44
View File
@@ -23,11 +23,55 @@
#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[] = {
{"SetAvatar", setAvatar},
{"GetAvatar", getAvatar},
{"SetScript", setScript},
{"GetScript", getScript},
{nullptr, nullptr}
};
LUAMOD_API int openMonsterAPI(lua_State* L) {
//the local table
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;
}
+4 -4
View File
@@ -25,14 +25,14 @@ std::string MonsterData::SetAvatar(std::string s) {
return avatar = s;
}
int MonsterData::SetScriptReference(int i) {
return scriptRef = i;
}
std::string MonsterData::GetAvatar() {
return avatar;
}
int MonsterData::SetScriptReference(int i) {
return scriptRef = i;
}
int MonsterData::GetScriptReference() {
return scriptRef;
}
+2 -2
View File
@@ -32,9 +32,9 @@ public:
~MonsterData() = default;
std::string SetAvatar(std::string);
int SetScriptReference(int);
std::string GetAvatar();
int SetScriptReference(int);
int GetScriptReference();
private:
+16 -24
View File
@@ -21,26 +21,22 @@
*/
#include "monster_manager.hpp"
MonsterManager::MonsterManager() {
//EMPTY
}
MonsterManager::~MonsterManager() {
UnloadAll();
}
int MonsterManager::Create(std::string) {
//TODO
}
int MonsterManager::Load(std::string) {
//TODO
}
int MonsterManager::Save(int uid) {
//TODO
}
void MonsterManager::Unload(int uid) {
//TODO
}
void MonsterManager::Delete(int uid) {
//TODO
}
void MonsterManager::UnloadAll() {
//TODO
}
@@ -57,22 +53,10 @@ int MonsterManager::GetLoadedCount() {
//TODO
}
int MonsterManager::GetTotalCount() {
//TODO
}
std::map<int, MonsterData>* MonsterManager::GetContainer() {
//TODO
}
sqlite3* MonsterManager::SetDatabase(sqlite3* db) {
//TODO
}
sqlite3* MonsterManager::GetDatabase() {
//TODO
}
lua_State* MonsterManager::SetLuaState(lua_State* L) {
//TODO
}
@@ -80,3 +64,11 @@ lua_State* MonsterManager::SetLuaState(lua_State* L) {
lua_State* MonsterManager::GetLuaState() {
//TODO
}
sqlite3* MonsterManager::SetDatabase(sqlite3* db) {
//TODO
}
sqlite3* MonsterManager::GetDatabase() {
//TODO
}
+7 -14
View File
@@ -23,7 +23,6 @@
#define MONSTERMANAGER_HPP_
#include "monster_data.hpp"
#include "singleton.hpp"
#include "lua.hpp"
#include "sqlite3.h"
@@ -32,14 +31,14 @@
#include <map>
#include <string>
class MonsterManager: public Singleton<MonsterManager> {
class MonsterManager {
public:
MonsterManager();
~MonsterManager();
//common public methods
int Create(std::string);
int Load(std::string);
int Save(int uid);
void Unload(int uid);
void Delete(int uid);
void UnloadAll();
void UnloadIf(std::function<bool(std::pair<const int, MonsterData const&>)> fn);
@@ -47,25 +46,19 @@ public:
//accessors & mutators
MonsterData* Get(int uid);
int GetLoadedCount();
int GetTotalCount();
std::map<int, MonsterData>* GetContainer();
//hooks
sqlite3* SetDatabase(sqlite3* db);
sqlite3* GetDatabase();
lua_State* SetLuaState(lua_State* L);
lua_State* GetLuaState();
sqlite3* SetDatabase(sqlite3* db);
sqlite3* GetDatabase();
private:
friend Singleton<MonsterManager>;
MonsterManager() = default;
~MonsterManager() = default;
//members
std::map<int, MonsterData> elementMap;
sqlite3* database = nullptr;
lua_State* lua = nullptr;
sqlite3* database = nullptr;
};
#endif
+55
View File
@@ -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
* distribution.
*/
#ifndef TILESHEETAPI_HPP_
#define TILESHEETAPI_HPP_
#ifndef MONSTERSYSTEMAPI_HPP_
#define MONSTERSYSTEMAPI_HPP_
#include "lua.hpp"
#define TORTUGA_TILE_SHEET_NAME "tile_sheet"
LUAMOD_API int openTileSheetAPI(lua_State* L);
#define TORTUGA_MONSTER_SYSTEM_API "monster_system"
LUAMOD_API int openMonsterSystemAPI(lua_State* L);
#endif
#endif
+1 -1
View File
@@ -1,5 +1,5 @@
#config
INCLUDES+=. ../entities ../server_utilities ../../common/map ../../common/utilities
INCLUDES+=. ../entities ../monsters ../server_utilities ../waypoints ../../common/map ../../common/utilities
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
+18 -4
View File
@@ -53,11 +53,21 @@ static int getPager(lua_State* L) {
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) {
//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));
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)
room->GetPager()->SetUnloadReference(luaL_ref(L, LUA_REGISTRYINDEX));
@@ -70,11 +80,15 @@ static int initialize(lua_State* L) {
}
static const luaL_Reg roomLib[] = {
{"GetPager",getPager},
{"SetName", setRoomName},
{"GetName", getRoomName},
{"SetTileset", setTilesetName},
{"GetTileset", getTilesetName},
{"GetPager",getPager},
{"GetMonsterMgr",getMonsterMgr},
{"GetWaypointMgr",getWaypointMgr},
{"Initialize", initialize},
{nullptr, nullptr}
};
+8
View File
@@ -41,6 +41,14 @@ RegionPagerLua* RoomData::GetPager() {
return &pager;
}
MonsterManager* RoomData::GetMonsterMgr() {
return &monsterMgr;
}
WaypointManager* RoomData::GetWaypointMgr() {
return &waypointMgr;
}
std::list<Entity*>* RoomData::GetEntityList() {
return &entityList;
}
+6
View File
@@ -23,7 +23,9 @@
#define ROOMDATA_HPP_
#include "entity.hpp"
#include "monster_manager.hpp"
#include "region_pager_lua.hpp"
#include "waypoint_manager.hpp"
#include "lua.hpp"
@@ -43,6 +45,8 @@ public:
std::string GetTileset();
RegionPagerLua* GetPager();
MonsterManager* GetMonsterMgr();
WaypointManager* GetWaypointMgr();
std::list<Entity*>* GetEntityList();
//TODO: triggers for unload, save, per-second, player enter, player exit, etc.
@@ -55,6 +59,8 @@ private:
std::string tilesetName;
RegionPagerLua pager;
MonsterManager monsterMgr;
WaypointManager waypointMgr;
std::list<Entity*> entityList;
};
+42
View File
@@ -36,6 +36,9 @@ int RoomManager::Create(std::string roomName, std::string tileset) {
newRoom->SetTileset(tileset);
newRoom->pager.SetLuaState(lua);
newRoom->monsterMgr.SetLuaState(lua);
newRoom->monsterMgr.SetDatabase(database);
newRoom->waypointMgr.SetLuaState(lua);
//finish the routine
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) {
std::map<int, RoomData>::iterator it = elementMap.find(uid);
@@ -91,3 +125,11 @@ lua_State* RoomManager::SetLuaState(lua_State* L) {
lua_State* RoomManager::GetLuaState() {
return lua;
}
sqlite3* RoomManager::SetDatabase(sqlite3* db) {
return database = db;
}
sqlite3* RoomManager::GetDatabase() {
return database;
}
+8
View File
@@ -22,10 +22,12 @@
#ifndef ROOMMANAGER_HPP_
#define ROOMMANAGER_HPP_
#include "entity.hpp"
#include "room_data.hpp"
#include "singleton.hpp"
#include "lua.hpp"
#include "sqlite3.h"
#include <functional>
#include <map>
@@ -38,6 +40,9 @@ public:
void UnloadAll();
void UnloadIf(std::function<bool(std::pair<const int, RoomData const&>)> fn);
void PushEntity(Entity* entity);
void PopEntity(Entity const* entity);
//accessors and mutators
RoomData* Get(int uid);
RoomData* Get(std::string name);
@@ -47,6 +52,8 @@ public:
//hooks
lua_State* SetLuaState(lua_State* L);
lua_State* GetLuaState();
sqlite3* SetDatabase(sqlite3* db);
sqlite3* GetDatabase();
private:
friend Singleton<RoomManager>;
@@ -57,6 +64,7 @@ private:
//members
std::map<int, RoomData> elementMap;
lua_State* lua = nullptr;
sqlite3* database = nullptr;
int counter = 0;
};
+1 -4
View File
@@ -28,7 +28,6 @@
#include "client_manager.hpp"
#include "monster_manager.hpp"
#include "room_manager.hpp"
#include "waypoint_manager.hpp"
//utilities
#include "config_utility.hpp"
@@ -115,12 +114,10 @@ private:
lua_State* luaState = nullptr;
//ugly references; I hate this
ClientManager& clientMgr = ClientManager::GetSingleton();
AccountManager& accountMgr = AccountManager::GetSingleton();
CharacterManager& characterMgr = CharacterManager::GetSingleton();
ClientManager& clientMgr = ClientManager::GetSingleton();
MonsterManager& monsterMgr = MonsterManager::GetSingleton();
RoomManager& roomMgr = RoomManager::GetSingleton();
WaypointManager& waypointMgr = WaypointManager::GetSingleton();
ConfigUtility& config = ConfigUtility::GetSingleton();
UDPNetworkUtility& network = UDPNetworkUtility::GetSingleton();
+18
View File
@@ -45,6 +45,9 @@ void ServerApplication::HandleCharacterCreate(CharacterPacket* const argPacket)
return;
}
//push to the rooms
roomMgr.PushEntity(characterMgr.Get(characterIndex));
//pump this character to all clients
CharacterPacket newPacket;
CopyCharacterToPacket(&newPacket, characterIndex);
@@ -86,6 +89,9 @@ void ServerApplication::HandleCharacterDelete(CharacterPacket* const argPacket)
return;
}
//pop from the rooms
roomMgr.PopEntity(characterMgr.Get(characterIndex));
//delete the character
characterMgr.Delete(characterIndex);
@@ -119,6 +125,9 @@ void ServerApplication::HandleCharacterLoad(CharacterPacket* const argPacket) {
return;
}
//push to the rooms
roomMgr.PushEntity(characterMgr.Get(characterIndex));
//pump this character to all clients
CharacterPacket newPacket;
CopyCharacterToPacket(&newPacket, characterIndex);
@@ -149,6 +158,9 @@ void ServerApplication::HandleCharacterUnload(CharacterPacket* const argPacket)
return;
}
//pop from the rooms
roomMgr.PopEntity(characterData);
//unload the character
characterMgr.Unload(argPacket->characterIndex);
@@ -190,11 +202,17 @@ void ServerApplication::HandleCharacterSetRoom(CharacterPacket* const argPacket)
return;
}
//pop from the old room
roomMgr.PopEntity(characterData);
//set the character's room, zero it's origin, zero it's motion
characterData->SetRoomIndex(argPacket->roomIndex);
characterData->SetOrigin({0, 0});
characterData->SetMotion({0, 0});
//push to the new room
roomMgr.PushEntity(characterData);
//update the clients
CharacterPacket newPacket;
CopyCharacterToPacket(&newPacket, argPacket->characterIndex);
+1 -3
View File
@@ -105,7 +105,7 @@ void ServerApplication::Init(int argc, char* argv[]) {
characterMgr.SetDatabase(database);
roomMgr.SetLuaState(luaState);
waypointMgr.SetLuaState(luaState);
roomMgr.SetDatabase(database);
std::cout << "Internal managers initialized" << std::endl;
@@ -202,9 +202,7 @@ void ServerApplication::Quit() {
accountMgr.UnloadAll();
characterMgr.UnloadAll();
clientMgr.UnloadAll();
monsterMgr.UnloadAll();
roomMgr.UnloadAll();
waypointMgr.UnloadAll();
//APIs
lua_close(luaState);
+3
View File
@@ -149,6 +149,9 @@ void ServerApplication::FullCharacterUnload(int index) {
return false;
}
//pop from the rooms
roomMgr.PopEntity(&character.second);
//pump character unload
CharacterPacket newPacket;
newPacket.type = SerialPacketType::CHARACTER_DELETE;
+43 -1
View File
@@ -23,8 +23,50 @@
#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[] = {
{"SetOrigin",setOrigin},
{"GetOrigin",getOrigin},
{"SetBounds",setBoundingBox},
{"GetBounds",getBoundingBox},
{"SetTrigger",setTriggerReference},
{"GetTrigger",getTriggerReference},
{nullptr, nullptr}
};
+17 -1
View File
@@ -27,4 +27,20 @@ int WaypointData::SetTriggerReference(int i) {
int WaypointData::GetTriggerReference() {
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;
}
+11 -2
View File
@@ -22,23 +22,32 @@
#ifndef WAYPOINTDATA_HPP_
#define WAYPOINTDATA_HPP_
#include "entity.hpp"
#include "bounding_box.hpp"
#include "vector2.hpp"
#include "lua.hpp"
#include <string>
class WaypointData: public Entity {
class WaypointData {
public:
WaypointData() = default;
~WaypointData() = default;
Vector2 SetOrigin(Vector2 v);
Vector2 GetOrigin();
BoundingBox SetBoundingBox(BoundingBox b);
BoundingBox GetBoundingBox();
int SetTriggerReference(int i);
int GetTriggerReference();
private:
friend class WaypointManager;
Vector2 origin;
BoundingBox bounds;
int triggerRef = LUA_NOREF;
};
+52 -20
View File
@@ -21,46 +21,78 @@
*/
#include "waypoint_manager.hpp"
WaypointManager::WaypointManager() {
//EMPTY
}
WaypointManager::~WaypointManager() {
UnloadAll();
}
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() {
//TODO
}
int WaypointManager::Create(Vector2 origin, BoundingBox bounds) {
//implicitly creates the element
WaypointData& waypointData = elementMap[counter];
int WaypointManager::Save(int uid) {
//TODO
waypointData.origin = origin;
waypointData.bounds = bounds;
return counter++;
}
void WaypointManager::Unload(int uid) {
//TODO
}
void WaypointManager::Delete(int uid) {
//TODO
elementMap.erase(uid);
}
void WaypointManager::UnloadAll() {
//TODO
elementMap.clear();
}
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) {
//TODO
std::map<int, WaypointData>::iterator it = elementMap.find(uid);
if (it == elementMap.end()) {
return nullptr;
}
return &it->second;
}
int WaypointManager::GetLoadedCount() {
//TODO
}
int WaypointManager::GetTotalCount() {
//TODO
return elementMap.size();
}
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;
}
+9 -15
View File
@@ -22,9 +22,9 @@
#ifndef WAYPOINTMANAGER_HPP_
#define WAYPOINTMANAGER_HPP_
#include "waypoint_data.hpp"
#include "singleton.hpp"
#include "bounding_box.hpp"
#include "vector2.hpp"
#include "waypoint_data.hpp"
#include "lua.hpp"
@@ -32,15 +32,15 @@
#include <map>
#include <string>
//TODO: should waypoints be managed on a per-room basis?
class WaypointManager: public Singleton<WaypointManager> {
class WaypointManager {
public:
WaypointManager();
~WaypointManager();
//common public methods
int Create();
int Load();
int Save(int uid);
int Create(Vector2 origin, BoundingBox bounds);
void Unload(int uid);
void Delete(int uid);
void UnloadAll();
void UnloadIf(std::function<bool(std::pair<const int, WaypointData const&>)> fn);
@@ -48,19 +48,13 @@ public:
//accessors & mutators
WaypointData* Get(int uid);
int GetLoadedCount();
int GetTotalCount();
std::map<int, WaypointData>* GetContainer();
//hooks
lua_State* SetLuaState(lua_State* L) { return lua = L; }
lua_State* GetLuaState() { return lua; }
lua_State* SetLuaState(lua_State* L);
lua_State* GetLuaState();
private:
friend Singleton<WaypointManager>;
WaypointManager() = default;
~WaypointManager() = default;
//members
std::map<int, WaypointData> elementMap;
lua_State* lua = nullptr;
+20
View File
@@ -23,7 +23,27 @@
#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[] = {
{"Create",create},
{"Unload",unload},
{"GetWaypoint",getWaypoint},
{"GetCount",getLoadedCount},
{nullptr, nullptr}
};
+1
View File
@@ -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: Time delay for requesting region packets
TODO: A proper logging system
TODO: Fix the const-ness of accessors