Compare commits

...

2 Commits

Author SHA1 Message Date
Kayne Ruse fdaae0e8f2 Problems with lambdas and references 2014-11-26 04:21:30 +11:00
Kayne Ruse bd3838a04e IDK what the fuck is going on, too tired to think
OK, so I think I was working on the parameters for CreateRoom() in lua,
but then shit just got ot of control. IDK, I'm probably going about this
all wrong anyway. I just want to finish this stage, and reach the high
water mark again.
2014-11-24 05:43:38 +11:00
24 changed files with 200 additions and 127 deletions
+12
View File
@@ -24,6 +24,18 @@
#include <stdexcept> #include <stdexcept>
#include <algorithm> #include <algorithm>
RegionPagerBase::RegionPagerBase() {
//
}
RegionPagerBase::RegionPagerBase(RegionPagerBase&& rhs) {
regionList = std::move(rhs.regionList);
}
RegionPagerBase::~RegionPagerBase() {
UnloadAll();
}
Region::type_t RegionPagerBase::SetTile(int x, int y, int z, Region::type_t v) { Region::type_t RegionPagerBase::SetTile(int x, int y, int z, Region::type_t v) {
Region* ptr = GetRegion(x, y); Region* ptr = GetRegion(x, y);
return ptr->SetTile(x - ptr->GetX(), y - ptr->GetY(), z, v); return ptr->SetTile(x - ptr->GetX(), y - ptr->GetY(), z, v);
+3 -2
View File
@@ -28,8 +28,9 @@
class RegionPagerBase { class RegionPagerBase {
public: public:
RegionPagerBase() = default; RegionPagerBase();
virtual ~RegionPagerBase() { UnloadAll(); }; RegionPagerBase(RegionPagerBase&&);
virtual ~RegionPagerBase();
//tile manipulation //tile manipulation
virtual Region::type_t SetTile(int x, int y, int z, Region::type_t v); virtual Region::type_t SetTile(int x, int y, int z, Region::type_t v);
+27
View File
@@ -23,6 +23,29 @@
#include <stdexcept> #include <stdexcept>
RegionPagerLua::RegionPagerLua() {
//
}
RegionPagerLua::RegionPagerLua(RegionPagerLua&& rhs) {
lua = rhs.lua;
loadRef = rhs.loadRef;
saveRef = rhs.saveRef;
createRef = rhs.createRef;
unloadRef = rhs.unloadRef;
}
RegionPagerLua::~RegionPagerLua() {
//unload all regions
UnloadAll();
//clear any stored functions
luaL_unref(lua, LUA_REGISTRYINDEX, loadRef);
luaL_unref(lua, LUA_REGISTRYINDEX, saveRef);
luaL_unref(lua, LUA_REGISTRYINDEX, createRef);
luaL_unref(lua, LUA_REGISTRYINDEX, unloadRef);
}
//return the loaded region, or nullptr on failure
Region* RegionPagerLua::LoadRegion(int x, int y) { Region* RegionPagerLua::LoadRegion(int x, int y) {
//get the pager's function from the registry //get the pager's function from the registry
lua_rawgeti(lua, LUA_REGISTRYINDEX, loadRef); lua_rawgeti(lua, LUA_REGISTRYINDEX, loadRef);
@@ -54,6 +77,7 @@ Region* RegionPagerLua::LoadRegion(int x, int y) {
} }
} }
//return the saved region, or nullptr on failure
Region* RegionPagerLua::SaveRegion(int x, int y) { Region* RegionPagerLua::SaveRegion(int x, int y) {
//get the pager's function from the registry //get the pager's function from the registry
lua_rawgeti(lua, LUA_REGISTRYINDEX, saveRef); lua_rawgeti(lua, LUA_REGISTRYINDEX, saveRef);
@@ -88,6 +112,7 @@ Region* RegionPagerLua::SaveRegion(int x, int y) {
} }
} }
//return the created region, or nullptr on failure
Region* RegionPagerLua::CreateRegion(int x, int y) { Region* RegionPagerLua::CreateRegion(int x, int y) {
if (FindRegion(x, y)) { if (FindRegion(x, y)) {
throw(std::logic_error("Cannot overwrite an existing region")); throw(std::logic_error("Cannot overwrite an existing region"));
@@ -116,6 +141,7 @@ Region* RegionPagerLua::CreateRegion(int x, int y) {
return &regionList.front(); return &regionList.front();
} }
//no return
void RegionPagerLua::UnloadRegion(int x, int y) { void RegionPagerLua::UnloadRegion(int x, int y) {
//get the pager's function from the registry //get the pager's function from the registry
lua_rawgeti(lua, LUA_REGISTRYINDEX, unloadRef); lua_rawgeti(lua, LUA_REGISTRYINDEX, unloadRef);
@@ -150,6 +176,7 @@ void RegionPagerLua::UnloadRegion(int x, int y) {
lua_pop(lua, 1); lua_pop(lua, 1);
} }
//no return
void RegionPagerLua::UnloadAll() { void RegionPagerLua::UnloadAll() {
//get the pager's function from the registry //get the pager's function from the registry
lua_rawgeti(lua, LUA_REGISTRYINDEX, unloadRef); lua_rawgeti(lua, LUA_REGISTRYINDEX, unloadRef);
+3 -2
View File
@@ -34,8 +34,9 @@
class RegionPagerLua : public RegionPagerBase { class RegionPagerLua : public RegionPagerBase {
public: public:
RegionPagerLua() = default; RegionPagerLua();
~RegionPagerLua() = default; RegionPagerLua(RegionPagerLua&&);
~RegionPagerLua();
//region manipulation //region manipulation
Region* LoadRegion(int x, int y) override; Region* LoadRegion(int x, int y) override;
+12 -15
View File
@@ -11,23 +11,20 @@ local function dumpTable(t)
end end
end end
dumpTable(mapMaker)
dumpTable(mapSaver)
dumpTable(roomSystem)
dumpTable(roomSystem.Room)
dumpTable(roomSystem.RoomManager)
--create the overworld, set it's generator, loader & saver --create the overworld, set it's generator, loader & saver
local overworld = roomSystem.RoomManager.CreateRoom("overworld", "overworld.bmp") --[[
roomSystem.Room.SetOnLoad(overworld, 1123) local t = {
roomSystem.Room.SetOnUnload(overworld, 458) "overworld.bmp", --tileset name
mapSaver.load, --load function
mapSaver.save, --save function
mapMaker.debugIsland, --create function
mapSaver.save --unload function
}]]
if roomSystem.Room.GetOnLoad(overworld) == 1123 then dumpTable(roomSystem)
print("onload retreival works") dumpTable(roomSystem.RoomManager)
end dumpTable(roomSystem.Room)
if roomSystem.Room.GetOnUnload(overworld) == 458 then local overworld = roomSystem.RoomManager.CreateRoom("overworld")
print("onunload retreival works")
end
print("Finished the lua script") print("Finished the lua script")
+1 -1
View File
@@ -200,7 +200,7 @@ void AccountManager::UnloadAll() {
elementMap.clear(); elementMap.clear();
} }
void AccountManager::UnloadIf(std::function<bool(std::pair<const int, AccountData>)> fn) { void AccountManager::UnloadIf(std::function<bool(std::pair<const int, AccountData>&)> fn) {
//replicate std::remove_if, using custom code //replicate std::remove_if, using custom code
std::map<int, AccountData>::iterator it = elementMap.begin(); std::map<int, AccountData>::iterator it = elementMap.begin();
while (it != elementMap.end()) { while (it != elementMap.end()) {
+1 -1
View File
@@ -48,7 +48,7 @@ public:
void Delete(int uid) override; void Delete(int uid) override;
void UnloadAll() override; void UnloadAll() override;
void UnloadIf(std::function<bool(std::pair<const int, AccountData>)> fn) override; void UnloadIf(std::function<bool(std::pair<const int, AccountData>&)> fn) override;
//accessors and mutators //accessors and mutators
AccountData* Get(int uid) override; AccountData* Get(int uid) override;
+1 -1
View File
@@ -227,7 +227,7 @@ void CharacterManager::UnloadAll() {
elementMap.clear(); elementMap.clear();
} }
void CharacterManager::UnloadIf(std::function<bool(std::pair<const int, CharacterData>)> fn) { void CharacterManager::UnloadIf(std::function<bool(std::pair<const int, CharacterData>&)> fn) {
std::map<int, CharacterData>::iterator it = elementMap.begin(); std::map<int, CharacterData>::iterator it = elementMap.begin();
while (it != elementMap.end()) { while (it != elementMap.end()) {
if (fn(*it)) { if (fn(*it)) {
+1 -1
View File
@@ -48,7 +48,7 @@ public:
void Delete(int uid) override; void Delete(int uid) override;
void UnloadAll() override; void UnloadAll() override;
void UnloadIf(std::function<bool(std::pair<const int, CharacterData>)> fn) override; void UnloadIf(std::function<bool(std::pair<const int, CharacterData>&)> fn) override;
//accessors and mutators //accessors and mutators
CharacterData* Get(int uid) override; CharacterData* Get(int uid) override;
+1 -1
View File
@@ -73,7 +73,7 @@ void ClientManager::UnloadAll() {
elementMap.clear(); elementMap.clear();
} }
void ClientManager::UnloadIf(std::function<bool(std::pair<const int, ClientData>)> fn) { void ClientManager::UnloadIf(std::function<bool(std::pair<const int, ClientData>&)> fn) {
std::map<int, ClientData>::iterator it = elementMap.begin(); std::map<int, ClientData>::iterator it = elementMap.begin();
while (it != elementMap.end()) { while (it != elementMap.end()) {
if (fn(*it)) { if (fn(*it)) {
+1 -1
View File
@@ -45,7 +45,7 @@ public:
void Unload(int uid) override; void Unload(int uid) override;
void UnloadAll() override; void UnloadAll() override;
void UnloadIf(std::function<bool(std::pair<const int, ClientData>)> fn) override; void UnloadIf(std::function<bool(std::pair<const int, ClientData>&)> fn) override;
//accessors & mutators //accessors & mutators
ClientData* Get(int uid) override; ClientData* Get(int uid) override;
+1 -1
View File
@@ -45,7 +45,7 @@ void DoorManager::UnloadAll() {
//TODO //TODO
} }
void DoorManager::UnloadIf(std::function<bool(std::pair<const int, DoorData>)> fn) { void DoorManager::UnloadIf(std::function<bool(std::pair<const int, DoorData>&)> fn) {
//TODO //TODO
} }
+1 -1
View File
@@ -43,7 +43,7 @@ public:
void Delete(int uid) override; void Delete(int uid) override;
void UnloadAll() override; void UnloadAll() override;
void UnloadIf(std::function<bool(std::pair<const int, DoorData>)> fn) override; void UnloadIf(std::function<bool(std::pair<const int, DoorData>&)> fn) override;
//accessors & mutators //accessors & mutators
DoorData* Get(int uid) override; DoorData* Get(int uid) override;
+1 -1
View File
@@ -45,7 +45,7 @@ void MonsterManager::UnloadAll() {
//TODO //TODO
} }
void MonsterManager::UnloadIf(std::function<bool(std::pair<const int, MonsterData>)> fn) { void MonsterManager::UnloadIf(std::function<bool(std::pair<const int, MonsterData>&)> fn) {
//TODO //TODO
} }
+1 -1
View File
@@ -50,7 +50,7 @@ public:
void Delete(int uid) override; void Delete(int uid) override;
void UnloadAll() override; void UnloadAll() override;
void UnloadIf(std::function<bool(std::pair<const int, MonsterData>)> fn) override; void UnloadIf(std::function<bool(std::pair<const int, MonsterData>&)> fn) override;
//accessors & mutators //accessors & mutators
MonsterData* Get(int uid) override; MonsterData* Get(int uid) override;
+12 -30
View File
@@ -53,46 +53,28 @@ static int getPager(lua_State* L) {
return 1; return 1;
} }
//TODO: GetEntityList? static int initialize(lua_State* L) {
//set the members of the given room
RoomData* room = static_cast<RoomData*>(lua_touserdata(L, 1));
room->SetRoomName(lua_tostring(L, 2));
static int setLoadReference(lua_State* L) { //set the refs of these parameters (backwards, since it pops from the top of the stack)
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1)); room->GetPager()->SetUnloadReference(luaL_ref(L, LUA_REGISTRYINDEX));
luaL_unref(L, LUA_REGISTRYINDEX, room->GetLoadReference()); room->GetPager()->SetCreateReference(luaL_ref(L, LUA_REGISTRYINDEX));
room->SetLoadReference(luaL_ref(L, LUA_REGISTRYINDEX)); room->GetPager()->SetSaveReference(luaL_ref(L, LUA_REGISTRYINDEX));
room->GetPager()->SetLoadReference(luaL_ref(L, LUA_REGISTRYINDEX));
//more parameters can be added here later
return 0; return 0;
} }
static int getLoadReference(lua_State* L) {
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
lua_pushinteger(L, room->GetLoadReference());
lua_gettable(L, LUA_REGISTRYINDEX);
return 1;
}
static int setUnloadReference(lua_State* L) {
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
luaL_unref(L, LUA_REGISTRYINDEX, room->GetUnloadReference());
room->SetUnloadReference(luaL_ref(L, LUA_REGISTRYINDEX));
return 0;
}
static int getUnloadReference(lua_State* L) {
RoomData* room = reinterpret_cast<RoomData*>(lua_touserdata(L, 1));
lua_pushinteger(L, room->GetUnloadReference());
lua_gettable(L, LUA_REGISTRYINDEX);
return 1;
}
static const luaL_Reg roomLib[] = { static const luaL_Reg roomLib[] = {
{"GetPager",getPager}, {"GetPager",getPager},
{"SetRoomName", setRoomName}, {"SetRoomName", setRoomName},
{"GetRoomName", getRoomName}, {"GetRoomName", getRoomName},
{"SetTileset", setTilesetName}, {"SetTileset", setTilesetName},
{"GetTileset", getTilesetName}, {"GetTileset", getTilesetName},
{"SetOnLoad", setLoadReference}, {"Initialize", initialize},
{"GetOnLoad", getLoadReference},
{"SetOnUnload", setUnloadReference},
{"GetOnUnload", getUnloadReference},
{nullptr, nullptr} {nullptr, nullptr}
}; };
+16 -17
View File
@@ -21,6 +21,21 @@
*/ */
#include "room_data.hpp" #include "room_data.hpp"
RoomData::RoomData() {
//
}
RoomData::RoomData(RoomData& rhs) {
roomName = std::move(rhs.roomName);
tilesetName = std::move(rhs.tilesetName);
pager = std::move(rhs.pager);
//entityList = std::move(rhs.entityList);
}
RoomData::~RoomData() {
//
}
std::string RoomData::SetRoomName(std::string s) { std::string RoomData::SetRoomName(std::string s) {
return roomName = s; return roomName = s;
} }
@@ -42,21 +57,5 @@ RegionPagerLua* RoomData::GetPager() {
} }
std::list<Entity*>* RoomData::GetEntityList() { std::list<Entity*>* RoomData::GetEntityList() {
return &entityList; // return &entityList;
}
int RoomData::SetLoadReference(int i) {
return loadRef = i;
}
int RoomData::GetLoadReference() {
return loadRef;
}
int RoomData::SetUnloadReference(int i) {
return unloadRef = i;
}
int RoomData::GetUnloadReference() {
return unloadRef;
} }
+4 -14
View File
@@ -36,8 +36,9 @@
class RoomData { class RoomData {
public: public:
RoomData() = default; RoomData();
~RoomData() = default; RoomData(RoomData&);
~RoomData();
//accessors and mutators //accessors and mutators
std::string SetRoomName(std::string s); std::string SetRoomName(std::string s);
@@ -49,12 +50,6 @@ public:
RegionPagerLua* GetPager(); RegionPagerLua* GetPager();
std::list<Entity*>* GetEntityList(); std::list<Entity*>* GetEntityList();
//hooks
int SetLoadReference(int);
int GetLoadReference();
int SetUnloadReference(int);
int GetUnloadReference();
private: private:
friend class RoomManager; friend class RoomManager;
@@ -63,12 +58,7 @@ private:
std::string tilesetName; std::string tilesetName;
RegionPagerLua pager; RegionPagerLua pager;
std::list<Entity*> entityList; // std::list<Entity*> entityList;
//lua references
//TODO: use RoomData's lua references for load and unload functions
int loadRef = LUA_NOREF;
int unloadRef = LUA_NOREF;
}; };
#endif #endif
+10 -19
View File
@@ -23,31 +23,28 @@
#include "room_api.hpp" #include "room_api.hpp"
#include <iostream>
#include <stdexcept> #include <stdexcept>
//------------------------- //-------------------------
//public access methods //public access methods
//------------------------- //-------------------------
int RoomManager::Create(std::string roomName, std::string tilesetName) { int RoomManager::Create(std::string roomName) {
std::cout << "Create-1" << std::endl;
//create the room //create the room
RoomData* newRoom = &elementMap[counter]; //implicitly constructs the element elementMap.emplace(counter); ////explicitly constructs the element
RoomData* newRoom = &(elementMap.find(counter)->second);
std::cout << "Create-2" << std::endl;
newRoom->SetRoomName(roomName);
std::cout << "Create-3" << std::endl;
newRoom->pager.SetLuaState(lua); newRoom->pager.SetLuaState(lua);
std::cout << "Create-4" << std::endl;
//finish the routine //finish the routine
return counter++; return counter++;
} }
int RoomManager::Load(std::string roomName, std::string tilesetName) {
//TODO: RoomManager::Load()
return -1;
}
int RoomManager::Save(int uid) {
//TODO: RoomManager::Save(uid)
return -1;
}
void RoomManager::Unload(int uid) { void RoomManager::Unload(int uid) {
//find the room //find the room
std::map<int, RoomData>::iterator it = elementMap.find(uid); std::map<int, RoomData>::iterator it = elementMap.find(uid);
@@ -59,17 +56,11 @@ void RoomManager::Unload(int uid) {
elementMap.erase(uid); elementMap.erase(uid);
} }
void RoomManager::Delete(int uid) {
//TODO: RoomManager::Delete(int uid)
//NOTE: aliased to RoomManager::Unload(int uid)
Unload(uid);
}
void RoomManager::UnloadAll() { void RoomManager::UnloadAll() {
elementMap.clear(); elementMap.clear();
} }
void RoomManager::UnloadIf(std::function<bool(std::pair<const int,RoomData>)> fn) { void RoomManager::UnloadIf(std::function<bool(std::pair<const int,RoomData>&)> fn) {
std::map<int, RoomData>::iterator it = elementMap.begin(); std::map<int, RoomData>::iterator it = elementMap.begin();
while (it != elementMap.end()) { while (it != elementMap.end()) {
if (fn(*it)) { if (fn(*it)) {
+8 -6
View File
@@ -34,18 +34,15 @@
class RoomManager: class RoomManager:
public Singleton<RoomManager>, public Singleton<RoomManager>,
public ManagerInterface<RoomData, std::string, std::string> public ManagerInterface<RoomData, std::string>
{ {
public: public:
//common public methods //common public methods
int Create(std::string, std::string) override; int Create(std::string) override;
int Load(std::string, std::string) override;
int Save(int uid) override;
void Unload(int uid) override; void Unload(int uid) override;
void Delete(int uid) override;
void UnloadAll() override; void UnloadAll() override;
void UnloadIf(std::function<bool(std::pair<const int,RoomData>)> fn) override; void UnloadIf(std::function<bool(std::pair<const int,RoomData>&)> fn) override;
//accessors and mutators //accessors and mutators
RoomData* Get(int uid) override; RoomData* Get(int uid) override;
@@ -63,6 +60,11 @@ private:
RoomManager() = default; RoomManager() = default;
~RoomManager() = default; ~RoomManager() = default;
//EMPTY
int Load(std::string) override { return -1; }
int Save(int uid) override { return -1; }
void Delete(int uid) override {}
lua_State* lua = nullptr; lua_State* lua = nullptr;
int counter = 0; int counter = 0;
}; };
+77 -6
View File
@@ -21,18 +21,71 @@
*/ */
#include "room_manager_api.hpp" #include "room_manager_api.hpp"
#include "room_system_api.hpp"
#include "room_api.hpp"
#include "room_manager.hpp" #include "room_manager.hpp"
#include <iostream>
#include <sstream>
#include <stdexcept>
int createRoom(lua_State* L) { int createRoom(lua_State* L) {
std::cout << "DEBUG: createRoom-1" << std::endl;
//create & get the room //create & get the room
RoomManager& roomMgr = RoomManager::GetSingleton(); RoomManager& roomMgr = RoomManager::GetSingleton();
int uid = roomMgr.Create("",""); //TODO: All new managers need their internals fleshed out std::cout << "DEBUG: createRoom-2" << std::endl;
int uid = roomMgr.Create(lua_tostring(L, 1));
std::cout << "DEBUG: createRoom-3" << std::endl;
RoomData* room = roomMgr.Get(uid); RoomData* room = roomMgr.Get(uid);
std::cout << "DEBUG: createRoom-4" << std::endl;
//setup the room //setup the room
//TODO: room parameters only set via lua, fix this if (lua_gettop(L) > 1) {
room->SetRoomName(lua_tostring(L, 1)); //ensure there are the correct number of parameters on the stack, including nil values
room->SetTilesetName(lua_tostring(L, 2)); lua_settop(L, 6); //5 parameters, + RoomName
//get Room::Initialize() onto the top of the stack
luaL_requiref(L, TORTUGA_ROOM_SYSTEM_API, openRoomSystemAPI, false);
lua_pushstring(L, TORTUGA_ROOM_API);
lua_gettable(L, -2); //RoomSystem[TORTUGA_ROOM_API]
lua_pushstring(L, "Initialize");
lua_gettable(L, -3); //Room[Initialize]
//push the room onto the stack
lua_pushlightuserdata(L, static_cast<void*>(room));
//push (copies of) the parameters onto the stack
if (lua_type(L, 2) == LUA_TTABLE) {
//Unroll the table of parameters
for (int i = 1; i <= 5; i++) { //should be 5 members, including nil values
lua_rawgeti(L, 2, i);
}
}
else {
//copy the parameters
for (int i = 2; i <= 6; i++) { //there are 5 parameters, including nil values, due to the call to lua_settop above
lua_pushvalue(L, i);
}
}
//by this point, the stack should look be ready to call Room::Initialize() with 6 parameters, including the room
int result = lua_pcall(L, 6, 0, 0);
if (result != LUA_OK) {
//something went wrong
std::ostringstream msg;
msg << "Failed to initialize a room's parameters in RoomManagerAPI::create(): " << lua_tostring(L, -1);
msg << "; Room name: " << lua_tostring(L, 1);
throw(std::runtime_error(msg.str()));
}
//wow, that was hard
}
//return room, uid //return room, uid
lua_pushlightuserdata(L, static_cast<void*>(room)); lua_pushlightuserdata(L, static_cast<void*>(room));
@@ -42,21 +95,39 @@ int createRoom(lua_State* L) {
} }
int unloadRoom(lua_State* L) { int unloadRoom(lua_State* L) {
//TODO: check authorization for room deletion
RoomManager& roomMgr = RoomManager::GetSingleton(); RoomManager& roomMgr = RoomManager::GetSingleton();
//NOTE: the pager calls the unload function itself
roomMgr.Unload(lua_tointeger(L, 1)); roomMgr.Unload(lua_tointeger(L, 1));
return 0; return 0;
} }
//TODO: lua API RoomManager.GetRoom(uid) int getRoom(lua_State* L) {
RoomManager& roomMgr = RoomManager::GetSingleton();
RoomData* room = roomMgr.Get(lua_tointeger(L, 1));
if (room) {
lua_pushlightuserdata(L, static_cast<void*>(room));
}
else {
lua_pushnil(L);
}
return 1;
}
static const luaL_Reg roomManagerLib[] = { static const luaL_Reg roomManagerLib[] = {
{"CreateRoom", createRoom}, {"CreateRoom", createRoom},
{"UnloadRoom", unloadRoom}, {"UnloadRoom", unloadRoom},
{"GetRoom", getRoom},
{nullptr, nullptr} {nullptr, nullptr}
}; };
LUAMOD_API int openRoomManagerAPI(lua_State* L) { LUAMOD_API int openRoomManagerAPI(lua_State* L) {
std::cout << "DEBUG: openRoomManagerAPI" << std::endl;
luaL_newlib(L, roomManagerLib); luaL_newlib(L, roomManagerLib);
return 1; return 1;
} }
+2 -2
View File
@@ -175,10 +175,10 @@ void ServerApplication::Proc() {
int disconnected = clientMgr.CheckConnections(); int disconnected = clientMgr.CheckConnections();
if (disconnected != -1) { if (disconnected != -1) {
//find and unload the accounts associated with this client //find and unload the accounts associated with this client
accountMgr.UnloadIf([&](std::pair<const int, AccountData> account) -> bool { accountMgr.UnloadIf([&](std::pair<const int, AccountData>& account) -> bool {
if (account.second.GetClientIndex() == disconnected) { if (account.second.GetClientIndex() == disconnected) {
//find and unload the characters associated with this account //find and unload the characters associated with this account
characterMgr.UnloadIf([&](std::pair<const int, CharacterData> character) -> bool { characterMgr.UnloadIf([&](std::pair<const int, CharacterData>& character) -> bool {
if (character.second.GetOwner() == account.first) { if (character.second.GetOwner() == account.first) {
// PumpCharacterUnload(character.first); // PumpCharacterUnload(character.first);
return true; return true;
+3 -3
View File
@@ -139,7 +139,7 @@ void ServerApplication::HandleLogoutRequest(ClientPacket* const argPacket) {
network.SendTo(clientData->GetAddress(), static_cast<SerialPacket*>(&newPacket)); network.SendTo(clientData->GetAddress(), static_cast<SerialPacket*>(&newPacket));
//save and unload this accounts characters //save and unload this accounts characters
characterMgr.UnloadIf([&](std::pair<int, CharacterData> it) -> bool { characterMgr.UnloadIf([&](std::pair<const int, CharacterData>& it) -> bool {
if (argPacket->accountIndex == it.second.GetOwner()) { if (argPacket->accountIndex == it.second.GetOwner()) {
//pump the unload message to all remaining clients //pump the unload message to all remaining clients
// PumpCharacterUnload(it.first); // PumpCharacterUnload(it.first);
@@ -173,10 +173,10 @@ void ServerApplication::HandleDisconnectRequest(ClientPacket* const argPacket) {
//TODO: need a method for this redundunt chunk of redundant code //TODO: need a method for this redundunt chunk of redundant code
//find and unload the accounts associated with this client //find and unload the accounts associated with this client
accountMgr.UnloadIf([&](std::pair<const int, AccountData> account) -> bool { accountMgr.UnloadIf([&](std::pair<const int, AccountData>& account) -> bool {
if (account.second.GetClientIndex() == argPacket->clientIndex) { if (account.second.GetClientIndex() == argPacket->clientIndex) {
//find and unload the characters associated with this account //find and unload the characters associated with this account
characterMgr.UnloadIf([&](std::pair<const int, CharacterData> character) -> bool { characterMgr.UnloadIf([&](std::pair<const int, CharacterData>& character) -> bool {
if (character.second.GetOwner() == account.first) { if (character.second.GetOwner() == account.first) {
// PumpCharacterUnload(character.first); // PumpCharacterUnload(character.first);
return true; return true;
@@ -36,7 +36,7 @@ public:
virtual void Delete(int uid) = 0; virtual void Delete(int uid) = 0;
virtual void UnloadAll() = 0; virtual void UnloadAll() = 0;
virtual void UnloadIf(std::function<bool(std::pair<const int, T>)> fn) = 0; virtual void UnloadIf(std::function<bool(std::pair<const int, T>&)> fn) = 0;
//accessors & mutators //accessors & mutators
virtual T* Get(int uid) = 0; virtual T* Get(int uid) = 0;