Problems with lambdas and references
This commit is contained in:
@@ -24,6 +24,18 @@
|
||||
#include <stdexcept>
|
||||
#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* ptr = GetRegion(x, y);
|
||||
return ptr->SetTile(x - ptr->GetX(), y - ptr->GetY(), z, v);
|
||||
|
||||
@@ -28,8 +28,9 @@
|
||||
|
||||
class RegionPagerBase {
|
||||
public:
|
||||
RegionPagerBase() = default;
|
||||
virtual ~RegionPagerBase() { UnloadAll(); };
|
||||
RegionPagerBase();
|
||||
RegionPagerBase(RegionPagerBase&&);
|
||||
virtual ~RegionPagerBase();
|
||||
|
||||
//tile manipulation
|
||||
virtual Region::type_t SetTile(int x, int y, int z, Region::type_t v);
|
||||
|
||||
@@ -23,6 +23,18 @@
|
||||
|
||||
#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();
|
||||
@@ -164,6 +176,7 @@ void RegionPagerLua::UnloadRegion(int x, int y) {
|
||||
lua_pop(lua, 1);
|
||||
}
|
||||
|
||||
//no return
|
||||
void RegionPagerLua::UnloadAll() {
|
||||
//get the pager's function from the registry
|
||||
lua_rawgeti(lua, LUA_REGISTRYINDEX, unloadRef);
|
||||
|
||||
@@ -34,7 +34,8 @@
|
||||
|
||||
class RegionPagerLua : public RegionPagerBase {
|
||||
public:
|
||||
RegionPagerLua() = default;
|
||||
RegionPagerLua();
|
||||
RegionPagerLua(RegionPagerLua&&);
|
||||
~RegionPagerLua();
|
||||
|
||||
//region manipulation
|
||||
|
||||
@@ -200,7 +200,7 @@ void AccountManager::UnloadAll() {
|
||||
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
|
||||
std::map<int, AccountData>::iterator it = elementMap.begin();
|
||||
while (it != elementMap.end()) {
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
void Delete(int uid) 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
|
||||
AccountData* Get(int uid) override;
|
||||
|
||||
@@ -227,7 +227,7 @@ void CharacterManager::UnloadAll() {
|
||||
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();
|
||||
while (it != elementMap.end()) {
|
||||
if (fn(*it)) {
|
||||
|
||||
@@ -48,7 +48,7 @@ public:
|
||||
void Delete(int uid) 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
|
||||
CharacterData* Get(int uid) override;
|
||||
|
||||
@@ -73,7 +73,7 @@ void ClientManager::UnloadAll() {
|
||||
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();
|
||||
while (it != elementMap.end()) {
|
||||
if (fn(*it)) {
|
||||
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
void Unload(int uid) 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
|
||||
ClientData* Get(int uid) override;
|
||||
|
||||
@@ -45,7 +45,7 @@ void DoorManager::UnloadAll() {
|
||||
//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
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
void Delete(int uid) 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
|
||||
DoorData* Get(int uid) override;
|
||||
|
||||
@@ -45,7 +45,7 @@ void MonsterManager::UnloadAll() {
|
||||
//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
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
void Delete(int uid) 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
|
||||
MonsterData* Get(int uid) override;
|
||||
|
||||
@@ -21,6 +21,21 @@
|
||||
*/
|
||||
#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) {
|
||||
return roomName = s;
|
||||
}
|
||||
@@ -42,5 +57,5 @@ RegionPagerLua* RoomData::GetPager() {
|
||||
}
|
||||
|
||||
std::list<Entity*>* RoomData::GetEntityList() {
|
||||
return &entityList;
|
||||
// return &entityList;
|
||||
}
|
||||
@@ -36,8 +36,9 @@
|
||||
|
||||
class RoomData {
|
||||
public:
|
||||
RoomData() = default;
|
||||
~RoomData() = default;
|
||||
RoomData();
|
||||
RoomData(RoomData&);
|
||||
~RoomData();
|
||||
|
||||
//accessors and mutators
|
||||
std::string SetRoomName(std::string s);
|
||||
@@ -57,7 +58,7 @@ private:
|
||||
std::string tilesetName;
|
||||
|
||||
RegionPagerLua pager;
|
||||
std::list<Entity*> entityList;
|
||||
// std::list<Entity*> entityList;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -33,7 +33,8 @@
|
||||
int RoomManager::Create(std::string roomName) {
|
||||
std::cout << "Create-1" << std::endl;
|
||||
//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;
|
||||
@@ -59,7 +60,7 @@ void RoomManager::UnloadAll() {
|
||||
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();
|
||||
while (it != elementMap.end()) {
|
||||
if (fn(*it)) {
|
||||
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
void Unload(int uid) 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
|
||||
RoomData* Get(int uid) override;
|
||||
|
||||
@@ -175,10 +175,10 @@ void ServerApplication::Proc() {
|
||||
int disconnected = clientMgr.CheckConnections();
|
||||
if (disconnected != -1) {
|
||||
//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) {
|
||||
//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) {
|
||||
// PumpCharacterUnload(character.first);
|
||||
return true;
|
||||
|
||||
@@ -139,7 +139,7 @@ void ServerApplication::HandleLogoutRequest(ClientPacket* const argPacket) {
|
||||
network.SendTo(clientData->GetAddress(), static_cast<SerialPacket*>(&newPacket));
|
||||
|
||||
//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()) {
|
||||
//pump the unload message to all remaining clients
|
||||
// PumpCharacterUnload(it.first);
|
||||
@@ -173,10 +173,10 @@ void ServerApplication::HandleDisconnectRequest(ClientPacket* const argPacket) {
|
||||
|
||||
//TODO: need a method for this redundunt chunk of redundant code
|
||||
//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) {
|
||||
//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) {
|
||||
// PumpCharacterUnload(character.first);
|
||||
return true;
|
||||
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
virtual void Delete(int uid) = 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
|
||||
virtual T* Get(int uid) = 0;
|
||||
|
||||
Reference in New Issue
Block a user