Renamed some of Get() methods to Find(), read more

From now on, ideally any function with "get" in the name should always
return a valid value. A function with "find" in the name, however, does
the same thing, but may also return an invalid result such as an error
code.
This commit is contained in:
2016-04-03 02:17:02 +11:00
parent 3b24aae422
commit 957458d489
19 changed files with 63 additions and 63 deletions
+2 -2
View File
@@ -64,7 +64,7 @@ function doorUtility.CreateDoorPair(handle, roomOne, Xone, Yone, roomTwo, Xtwo,
networkAPI.PumpCharacterUpdate(entity) networkAPI.PumpCharacterUpdate(entity)
--disable the other trigger --disable the other trigger
local triggerTwo = triggerManagerAPI.GetTrigger(roomAPI.GetTriggerMgr(roomTwo), handle) local triggerTwo = triggerManagerAPI.FindTrigger(roomAPI.GetTriggerMgr(roomTwo), handle)
triggerAPI.PushExclusionEntity(triggerTwo, entity) triggerAPI.PushExclusionEntity(triggerTwo, entity)
end end
@@ -77,7 +77,7 @@ function doorUtility.CreateDoorPair(handle, roomOne, Xone, Yone, roomTwo, Xtwo,
networkAPI.PumpCharacterUpdate(entity) networkAPI.PumpCharacterUpdate(entity)
--disable the other trigger --disable the other trigger
local triggerOne = triggerManagerAPI.GetTrigger(roomAPI.GetTriggerMgr(roomOne), handle) local triggerOne = triggerManagerAPI.FindTrigger(roomAPI.GetTriggerMgr(roomOne), handle)
triggerAPI.PushExclusionEntity(triggerOne, entity) triggerAPI.PushExclusionEntity(triggerOne, entity)
end end
+1 -1
View File
@@ -234,7 +234,7 @@ void AccountManager::UnloadIf(std::function<bool(std::pair<const int, AccountDat
//Define the accessors and mutators //Define the accessors and mutators
//------------------------- //-------------------------
AccountData* AccountManager::Get(int uid) { AccountData* AccountManager::Find(int uid) {
std::map<int, AccountData>::iterator it = elementMap.find(uid); std::map<int, AccountData>::iterator it = elementMap.find(uid);
if (it == elementMap.end()) { if (it == elementMap.end()) {
+1 -1
View File
@@ -42,7 +42,7 @@ public:
void UnloadIf(std::function<bool(std::pair<const int, AccountData const&>)> fn); void UnloadIf(std::function<bool(std::pair<const int, AccountData const&>)> fn);
//accessors and mutators //accessors and mutators
AccountData* Get(int uid); AccountData* Find(int uid);
int GetLoadedCount(); int GetLoadedCount();
int GetTotalCount(); int GetTotalCount();
std::map<int, AccountData>* GetContainer(); std::map<int, AccountData>* GetContainer();
+2 -2
View File
@@ -294,7 +294,7 @@ void CharacterManager::UnloadIf(std::function<bool(std::pair<const int, Characte
//Define the accessors and mutators //Define the accessors and mutators
//------------------------- //-------------------------
CharacterData* CharacterManager::Get(int uid) { CharacterData* CharacterManager::Find(int uid) {
std::map<int, CharacterData>::iterator it = elementMap.find(uid); std::map<int, CharacterData>::iterator it = elementMap.find(uid);
if (it == elementMap.end()) { if (it == elementMap.end()) {
@@ -304,7 +304,7 @@ CharacterData* CharacterManager::Get(int uid) {
return &it->second; return &it->second;
} }
CharacterData* CharacterManager::Get(std::string handle) { CharacterData* CharacterManager::Find(std::string handle) {
for (std::map<int, CharacterData>::iterator it = elementMap.begin(); it != elementMap.end(); ++it) { for (std::map<int, CharacterData>::iterator it = elementMap.begin(); it != elementMap.end(); ++it) {
if (it->second.GetHandle() == handle) { if (it->second.GetHandle() == handle) {
return &it->second; return &it->second;
+2 -2
View File
@@ -42,8 +42,8 @@ public:
void UnloadIf(std::function<bool(std::pair<const int, CharacterData const&>)> fn); void UnloadIf(std::function<bool(std::pair<const int, CharacterData const&>)> fn);
//accessors and mutators //accessors and mutators
CharacterData* Get(int uid); CharacterData* Find(int uid);
CharacterData* Get(std::string handle); CharacterData* Find(std::string handle);
int GetLoadedCount(); int GetLoadedCount();
int GetTotalCount(); int GetTotalCount();
std::map<int, CharacterData>* GetContainer(); std::map<int, CharacterData>* GetContainer();
+2 -2
View File
@@ -55,11 +55,11 @@ static int getCharacter(lua_State* L) {
switch(lua_type(L, 1)) { switch(lua_type(L, 1)) {
case LUA_TNUMBER: case LUA_TNUMBER:
characterData = characterMgr.Get(lua_tointeger(L, 1)); characterData = characterMgr.Find(lua_tointeger(L, 1));
break; break;
case LUA_TSTRING: case LUA_TSTRING:
//access characters via their handles //access characters via their handles
characterData = characterMgr.Get(lua_tostring(L, 1)); characterData = characterMgr.Find(lua_tostring(L, 1));
break; break;
} }
+1 -1
View File
@@ -86,7 +86,7 @@ void ClientManager::UnloadIf(std::function<bool(std::pair<const int, ClientData
} }
} }
ClientData* ClientManager::Get(int uid) { ClientData* ClientManager::Find(int uid) {
std::map<int, ClientData>::iterator it = elementMap.find(uid); std::map<int, ClientData>::iterator it = elementMap.find(uid);
if (it == elementMap.end()) { if (it == elementMap.end()) {
+1 -1
View File
@@ -47,7 +47,7 @@ public:
void UnloadIf(std::function<bool(std::pair<const int, ClientData const&>)> fn); void UnloadIf(std::function<bool(std::pair<const int, ClientData const&>)> fn);
//accessors & mutators //accessors & mutators
ClientData* Get(int uid); ClientData* Find(int uid);
int GetLoadedCount(); int GetLoadedCount();
int GetTotalCount(); int GetTotalCount();
std::map<int, ClientData>* GetContainer(); std::map<int, ClientData>* GetContainer();
+1 -1
View File
@@ -70,7 +70,7 @@ void CreatureManager::UnloadIf(std::function<bool(std::pair<const int, CreatureD
} }
} }
CreatureData* CreatureManager::Get(int uid) { CreatureData* CreatureManager::Find(int uid) {
std::map<int, CreatureData>::iterator it = elementMap.find(uid); std::map<int, CreatureData>::iterator it = elementMap.find(uid);
if (it == elementMap.end()) { if (it == elementMap.end()) {
+1 -1
View File
@@ -46,7 +46,7 @@ public:
void UnloadIf(std::function<bool(std::pair<const int, CreatureData const&>)> fn); void UnloadIf(std::function<bool(std::pair<const int, CreatureData const&>)> fn);
//accessors & mutators //accessors & mutators
CreatureData* Get(int uid); CreatureData* Find(int uid);
int GetLoadedCount(); int GetLoadedCount();
std::map<int, CreatureData>* GetContainer(); std::map<int, CreatureData>* GetContainer();
+4 -4
View File
@@ -31,7 +31,7 @@ static int create(lua_State* L) {
//create the actual creature //create the actual creature
CreatureManager* mgr = static_cast<CreatureManager* const>(lua_touserdata(L, 1)); CreatureManager* mgr = static_cast<CreatureManager* const>(lua_touserdata(L, 1));
int index = mgr->Create(lua_tostring(L, 2), lua_tointeger(L, 3)); //3 should be the unique reference within LUA_REGISTRYINDEX int index = mgr->Create(lua_tostring(L, 2), lua_tointeger(L, 3)); //3 should be the unique reference within LUA_REGISTRYINDEX
CreatureData* creature = mgr->Get(index); CreatureData* creature = mgr->Find(index);
lua_pushlightuserdata(L, static_cast<void*>(creature)); lua_pushlightuserdata(L, static_cast<void*>(creature));
lua_pushinteger(L, index); lua_pushinteger(L, index);
return 2; return 2;
@@ -56,9 +56,9 @@ static int unloadIf(lua_State* L) {
return 0; return 0;
} }
static int get(lua_State* L) { static int find(lua_State* L) {
CreatureManager* mgr = static_cast<CreatureManager* const>(lua_touserdata(L, 1)); CreatureManager* mgr = static_cast<CreatureManager* const>(lua_touserdata(L, 1));
CreatureData* creature = mgr->Get(lua_tointeger(L, 2)); CreatureData* creature = mgr->Find(lua_tointeger(L, 2));
lua_pushlightuserdata(L, static_cast<void*>(creature)); lua_pushlightuserdata(L, static_cast<void*>(creature));
return 1; return 1;
} }
@@ -74,7 +74,7 @@ static const luaL_Reg creatureManagerLib[] = {
{"Unload", unload}, {"Unload", unload},
{"UnloadAll", unloadAll}, {"UnloadAll", unloadAll},
// {"UnloadIf", unloadIf}, // {"UnloadIf", unloadIf},
{"Get", get}, {"Find", find},
{"GetLoadedCount", getLoadedCount}, {"GetLoadedCount", getLoadedCount},
{nullptr, nullptr} {nullptr, nullptr}
}; };
+4 -4
View File
@@ -116,7 +116,7 @@ void RoomManager::PushCharacter(CharacterData* character) {
throw(std::runtime_error("Failed to push a null character to a room")); throw(std::runtime_error("Failed to push a null character to a room"));
} }
RoomData* room = Get(character->GetRoomIndex()); RoomData* room = Find(character->GetRoomIndex());
if (!room) { if (!room) {
throw(std::runtime_error("Failed to push an character to a non-existant room")); throw(std::runtime_error("Failed to push an character to a non-existant room"));
@@ -131,7 +131,7 @@ void RoomManager::PopCharacter(CharacterData const* character) {
throw(std::runtime_error("Failed to pop a null character to a room")); throw(std::runtime_error("Failed to pop a null character to a room"));
} }
RoomData* room = Get(character->GetRoomIndex()); RoomData* room = Find(character->GetRoomIndex());
if (!room) { if (!room) {
throw(std::runtime_error("Failed to pop an character to a non-existant room")); throw(std::runtime_error("Failed to pop an character to a non-existant room"));
@@ -143,7 +143,7 @@ void RoomManager::PopCharacter(CharacterData const* character) {
} }
//TODO: rename these functions from Get to Find //TODO: rename these functions from Get to Find
RoomData* RoomManager::Get(int uid) { RoomData* RoomManager::Find(int uid) {
std::map<int, RoomData>::iterator it = elementMap.find(uid); std::map<int, RoomData>::iterator it = elementMap.find(uid);
if (it == elementMap.end()) { if (it == elementMap.end()) {
@@ -153,7 +153,7 @@ RoomData* RoomManager::Get(int uid) {
return &it->second; return &it->second;
} }
RoomData* RoomManager::Get(std::string name) { RoomData* RoomManager::Find(std::string name) {
for (std::map<int, RoomData>::iterator it = elementMap.begin(); it != elementMap.end(); ++it) { for (std::map<int, RoomData>::iterator it = elementMap.begin(); it != elementMap.end(); ++it) {
if (it->second.GetName() == name) { if (it->second.GetName() == name) {
return &it->second; return &it->second;
+2 -2
View File
@@ -43,8 +43,8 @@ public:
void PopCharacter(CharacterData const* character); void PopCharacter(CharacterData const* character);
//accessors and mutators //accessors and mutators
RoomData* Get(int uid); RoomData* Find(int uid);
RoomData* Get(std::string name); RoomData* Find(std::string name);
int GetLoadedCount(); int GetLoadedCount();
std::map<int, RoomData>* GetContainer(); std::map<int, RoomData>* GetContainer();
+5 -5
View File
@@ -27,7 +27,7 @@ int createRoom(lua_State* L) {
//create & get the room //create & get the room
RoomManager& roomMgr = RoomManager::GetSingleton(); RoomManager& roomMgr = RoomManager::GetSingleton();
int uid = roomMgr.Create(lua_tostring(L, 1), lua_tostring(L, 2)); int uid = roomMgr.Create(lua_tostring(L, 1), lua_tostring(L, 2));
RoomData* room = roomMgr.Get(uid); RoomData* room = roomMgr.Find(uid);
//TODO: initialization parameters here? //TODO: initialization parameters here?
@@ -70,7 +70,7 @@ int unloadRoom(lua_State* L) {
return 0; return 0;
} }
int getRoom(lua_State* L) { int findRoom(lua_State* L) {
//integer vs name for getRoom() //integer vs name for getRoom()
RoomManager& roomMgr = RoomManager::GetSingleton(); RoomManager& roomMgr = RoomManager::GetSingleton();
RoomData* room = nullptr; RoomData* room = nullptr;
@@ -78,11 +78,11 @@ int getRoom(lua_State* L) {
switch(lua_type(L, 1)) { switch(lua_type(L, 1)) {
case LUA_TNUMBER: case LUA_TNUMBER:
//number //number
room = roomMgr.Get(lua_tointeger(L, 1)); room = roomMgr.Find(lua_tointeger(L, 1));
break; break;
case LUA_TSTRING: case LUA_TSTRING:
//name //name
room = roomMgr.Get(lua_tostring(L, 1)); room = roomMgr.Find(lua_tostring(L, 1));
break; break;
} }
@@ -113,7 +113,7 @@ static int setOnUnload(lua_State* L) {
static const luaL_Reg roomManagerLib[] = { static const luaL_Reg roomManagerLib[] = {
{"CreateRoom", createRoom}, {"CreateRoom", createRoom},
{"UnloadRoom", unloadRoom}, {"UnloadRoom", unloadRoom},
{"GetRoom", getRoom}, {"FindRoom", findRoom},
{"SetOnCreate", setOnCreate}, {"SetOnCreate", setOnCreate},
{"SetOnUnload", setOnUnload}, {"SetOnUnload", setOnUnload},
{nullptr, nullptr} {nullptr, nullptr}
+20 -20
View File
@@ -376,7 +376,7 @@ void ServerApplication::hJoinRequest(ClientPacket* const argPacket) {
void ServerApplication::hLoginRequest(ClientPacket* const argPacket) { void ServerApplication::hLoginRequest(ClientPacket* const argPacket) {
//get the client data //get the client data
ClientData* clientData = clientMgr.Get(argPacket->clientIndex); ClientData* clientData = clientMgr.Find(argPacket->clientIndex);
if (clientData == nullptr || clientData->GetAddress() != argPacket->srcAddress) { if (clientData == nullptr || clientData->GetAddress() != argPacket->srcAddress) {
std::cerr << "Falsified client index detected: " << argPacket->clientIndex << std::endl; std::cerr << "Falsified client index detected: " << argPacket->clientIndex << std::endl;
@@ -421,12 +421,12 @@ void ServerApplication::hLoginRequest(ClientPacket* const argPacket) {
void ServerApplication::hLogoutRequest(ClientPacket* const argPacket) { void ServerApplication::hLogoutRequest(ClientPacket* const argPacket) {
//get the account and client data //get the account and client data
AccountData* accountData = accountMgr.Get(argPacket->accountIndex); AccountData* accountData = accountMgr.Find(argPacket->accountIndex);
if (!accountData) { if (!accountData) {
return; return;
} }
ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); ClientData* clientData = clientMgr.Find(accountData->GetClientIndex());
if (!clientData) { if (!clientData) {
std::ostringstream msg; std::ostringstream msg;
msg << "No client found for an account: " << accountData->GetUsername(); msg << "No client found for an account: " << accountData->GetUsername();
@@ -455,7 +455,7 @@ void ServerApplication::hLogoutRequest(ClientPacket* const argPacket) {
void ServerApplication::hDisconnectRequest(ClientPacket* const argPacket) { void ServerApplication::hDisconnectRequest(ClientPacket* const argPacket) {
//get the client data //get the client data
ClientData* clientData = clientMgr.Get(argPacket->clientIndex); ClientData* clientData = clientMgr.Find(argPacket->clientIndex);
if (!clientData) { if (!clientData) {
return; return;
} }
@@ -490,11 +490,11 @@ void ServerApplication::hAdminDisconnectForced(ClientPacket* const argPacket) {
void ServerApplication::hAdminShutdownRequest(ClientPacket* const argPacket) { void ServerApplication::hAdminShutdownRequest(ClientPacket* const argPacket) {
//get the account and client data //get the account and client data
AccountData* accountData = accountMgr.Get(argPacket->accountIndex); AccountData* accountData = accountMgr.Find(argPacket->accountIndex);
if (!accountData) { if (!accountData) {
return; return;
} }
ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); ClientData* clientData = clientMgr.Find(accountData->GetClientIndex());
if (!clientData) { if (!clientData) {
std::ostringstream msg; std::ostringstream msg;
msg << "No client found for an account: " << accountData->GetUsername(); msg << "No client found for an account: " << accountData->GetUsername();
@@ -545,7 +545,7 @@ void ServerApplication::hAdminShutdownRequest(ClientPacket* const argPacket) {
void ServerApplication::hRegionRequest(RegionPacket* const argPacket) { void ServerApplication::hRegionRequest(RegionPacket* const argPacket) {
//get the region object, send a rejection on error //get the region object, send a rejection on error
RoomData* room = roomMgr.Get(argPacket->roomIndex); RoomData* room = roomMgr.Find(argPacket->roomIndex);
if (!room) { if (!room) {
//build the error message //build the error message
std::ostringstream msg; std::ostringstream msg;
@@ -618,7 +618,7 @@ void ServerApplication::hCharacterCreate(CharacterPacket* const argPacket) {
} }
//push to the rooms //push to the rooms
CharacterData* characterData = characterMgr.Get(characterIndex); CharacterData* characterData = characterMgr.Find(characterIndex);
roomMgr.PushCharacter(characterData); roomMgr.PushCharacter(characterData);
//pump this character to all clients //pump this character to all clients
@@ -630,11 +630,11 @@ void ServerApplication::hCharacterCreate(CharacterPacket* const argPacket) {
void ServerApplication::hCharacterDelete(CharacterPacket* const argPacket) { void ServerApplication::hCharacterDelete(CharacterPacket* const argPacket) {
//get the user's data //get the user's data
AccountData* accountData = accountMgr.Get(argPacket->accountIndex); AccountData* accountData = accountMgr.Find(argPacket->accountIndex);
if (!accountData) { if (!accountData) {
return; return;
} }
ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); ClientData* clientData = clientMgr.Find(accountData->GetClientIndex());
if (!clientData) { if (!clientData) {
return; return;
} }
@@ -663,7 +663,7 @@ void ServerApplication::hCharacterDelete(CharacterPacket* const argPacket) {
} }
//pop from the rooms //pop from the rooms
CharacterData* characterData = characterMgr.Get(characterIndex); CharacterData* characterData = characterMgr.Find(characterIndex);
roomMgr.PopCharacter(characterData); roomMgr.PopCharacter(characterData);
//pump character unload //pump character unload
@@ -700,7 +700,7 @@ void ServerApplication::hCharacterLoad(CharacterPacket* const argPacket) {
} }
//push to the rooms //push to the rooms
CharacterData* characterData = characterMgr.Get(characterIndex); CharacterData* characterData = characterMgr.Find(characterIndex);
roomMgr.PushCharacter(characterData); roomMgr.PushCharacter(characterData);
//pump this character to all clients //pump this character to all clients
@@ -712,17 +712,17 @@ void ServerApplication::hCharacterLoad(CharacterPacket* const argPacket) {
void ServerApplication::hCharacterUnload(CharacterPacket* const argPacket) { void ServerApplication::hCharacterUnload(CharacterPacket* const argPacket) {
//get the entries //get the entries
CharacterData* characterData = characterMgr.Get(argPacket->characterIndex); CharacterData* characterData = characterMgr.Find(argPacket->characterIndex);
if (!characterData) { if (!characterData) {
return; return;
} }
AccountData* accountData = accountMgr.Get(characterData->GetOwner()); AccountData* accountData = accountMgr.Find(characterData->GetOwner());
if (!accountData) { if (!accountData) {
return; return;
} }
ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); ClientData* clientData = clientMgr.Find(accountData->GetClientIndex());
if (!clientData) { if (!clientData) {
return; return;
} }
@@ -748,20 +748,20 @@ void ServerApplication::hCharacterUnload(CharacterPacket* const argPacket) {
void ServerApplication::hCharacterMovement(CharacterPacket* const argPacket) { void ServerApplication::hCharacterMovement(CharacterPacket* const argPacket) {
//get the specified objects //get the specified objects
AccountData* accountData = accountMgr.Get(argPacket->accountIndex); AccountData* accountData = accountMgr.Find(argPacket->accountIndex);
if (!accountData) { if (!accountData) {
throw(std::runtime_error("Failed to move a character, missing account")); throw(std::runtime_error("Failed to move a character, missing account"));
} }
CharacterData* characterData = characterMgr.Get(argPacket->characterIndex); CharacterData* characterData = characterMgr.Find(argPacket->characterIndex);
if (!characterData) { if (!characterData) {
throw(std::runtime_error("Failed to move a character, missing character")); throw(std::runtime_error("Failed to move a character, missing character"));
} }
//get this account's client //get this account's client
ClientData* clientData = clientMgr.Get(accountData->GetClientIndex()); ClientData* clientData = clientMgr.Find(accountData->GetClientIndex());
//check for fraud //check for fraud
if (clientData->GetAddress() != argPacket->srcAddress) { if (clientData->GetAddress() != argPacket->srcAddress) {
@@ -809,9 +809,9 @@ void ServerApplication::hQueryCreatureExists(CreaturePacket* const argPacket) {
//respond with all creature data //respond with all creature data
CreaturePacket newPacket; CreaturePacket newPacket;
CreatureManager* creatureMgr = roomMgr.Get(argPacket->roomIndex)->GetCreatureMgr(); CreatureManager* creatureMgr = roomMgr.Find(argPacket->roomIndex)->GetCreatureMgr();
//TODO: move this into the room class //TODO: (0) move this into the room class
for (auto& it : *(creatureMgr->GetContainer()) ) { for (auto& it : *(creatureMgr->GetContainer()) ) {
copyCreatureToPacket(&newPacket, &(it.second), it.first); copyCreatureToPacket(&newPacket, &(it.second), it.first);
newPacket.type = SerialPacketType::QUERY_CREATURE_EXISTS; newPacket.type = SerialPacketType::QUERY_CREATURE_EXISTS;
+5 -5
View File
@@ -130,7 +130,7 @@ void pumpPacket(SerialPacket* const argPacket) {
void pumpPacketProximity(SerialPacket* const argPacket, int roomIndex, Vector2 position, int distance) { void pumpPacketProximity(SerialPacket* const argPacket, int roomIndex, Vector2 position, int distance) {
//send this packet to all characters within a certain distance of a point in a room //send this packet to all characters within a certain distance of a point in a room
RoomData* roomData = RoomManager::GetSingleton().Get(roomIndex); RoomData* roomData = RoomManager::GetSingleton().Find(roomIndex);
if (!roomData) { if (!roomData) {
throw(std::runtime_error("Failed to pump to a non-existant room")); throw(std::runtime_error("Failed to pump to a non-existant room"));
@@ -141,15 +141,15 @@ void pumpPacketProximity(SerialPacket* const argPacket, int roomIndex, Vector2 p
for (auto& characterIt : *roomData->GetCharacterList()) { for (auto& characterIt : *roomData->GetCharacterList()) {
if (distance == -1 || (characterIt->GetOrigin() - position).Length() <= distance) { if (distance == -1 || (characterIt->GetOrigin() - position).Length() <= distance) {
accountData = AccountManager::GetSingleton().Get(characterIt->GetOwner()); accountData = AccountManager::GetSingleton().Find(characterIt->GetOwner());
clientData = ClientManager::GetSingleton().Get(accountData->GetClientIndex()); clientData = ClientManager::GetSingleton().Find(accountData->GetClientIndex());
UDPNetworkUtility::GetSingleton().SendTo(clientData->GetAddress(), argPacket); UDPNetworkUtility::GetSingleton().SendTo(clientData->GetAddress(), argPacket);
} }
} }
} }
void copyCharacterToPacket(CharacterPacket* const packet, int characterIndex) { void copyCharacterToPacket(CharacterPacket* const packet, int characterIndex) {
CharacterData* characterData = CharacterManager::GetSingleton().Get(characterIndex); CharacterData* characterData = CharacterManager::GetSingleton().Find(characterIndex);
if (!characterData) { if (!characterData) {
throw(std::runtime_error("Failed to copy a character to a packet")); throw(std::runtime_error("Failed to copy a character to a packet"));
} }
@@ -179,7 +179,7 @@ void copyCreatureToPacket(CreaturePacket* const packet, CreatureData* const crea
void pumpAndChangeRooms(int characterIndex, int newRoomIndex) { void pumpAndChangeRooms(int characterIndex, int newRoomIndex) {
//get the character object //get the character object
CharacterData* character = CharacterManager::GetSingleton().Get(characterIndex); CharacterData* character = CharacterManager::GetSingleton().Find(characterIndex);
//pass ownwards //pass ownwards
pumpAndChangeRooms(character, newRoomIndex, characterIndex); pumpAndChangeRooms(character, newRoomIndex, characterIndex);
+2 -2
View File
@@ -59,7 +59,7 @@ void TriggerManager::UnloadIf(std::function<bool(std::pair<const int, TriggerDat
} }
} }
TriggerData* TriggerManager::Get(int uid) { TriggerData* TriggerManager::Find(int uid) {
std::map<int, TriggerData>::iterator it = elementMap.find(uid); std::map<int, TriggerData>::iterator it = elementMap.find(uid);
if (it == elementMap.end()) { if (it == elementMap.end()) {
@@ -69,7 +69,7 @@ TriggerData* TriggerManager::Get(int uid) {
return &it->second; return &it->second;
} }
TriggerData* TriggerManager::Get(std::string handle) { TriggerData* TriggerManager::Find(std::string handle) {
for (std::map<int, TriggerData>::iterator it = elementMap.begin(); it != elementMap.end(); ++it) { for (std::map<int, TriggerData>::iterator it = elementMap.begin(); it != elementMap.end(); ++it) {
if (it->second.GetHandle() == handle) { if (it->second.GetHandle() == handle) {
return &it->second; return &it->second;
+2 -2
View File
@@ -44,8 +44,8 @@ public:
void UnloadIf(std::function<bool(std::pair<const int, TriggerData const&>)> fn); void UnloadIf(std::function<bool(std::pair<const int, TriggerData const&>)> fn);
//accessors & mutators //accessors & mutators
TriggerData* Get(int uid); TriggerData* Find(int uid);
TriggerData* Get(std::string handle); TriggerData* Find(std::string handle);
int GetLoadedCount(); int GetLoadedCount();
std::map<int, TriggerData>* GetContainer(); std::map<int, TriggerData>* GetContainer();
+5 -5
View File
@@ -31,7 +31,7 @@ static int create(lua_State* L) {
//create the trigger //create the trigger
int index = mgr->Create(lua_tostring(L, 2)); int index = mgr->Create(lua_tostring(L, 2));
TriggerData* triggerData = mgr->Get(index); TriggerData* triggerData = mgr->Find(index);
//origin //origin
if (lua_gettop(L) >= 4) { if (lua_gettop(L) >= 4) {
@@ -101,16 +101,16 @@ static int unload(lua_State* L) {
return 1; return 1;
} }
static int getTrigger(lua_State* L) { static int findTrigger(lua_State* L) {
TriggerManager* mgr = static_cast<TriggerManager*>(lua_touserdata(L, 1)); TriggerManager* mgr = static_cast<TriggerManager*>(lua_touserdata(L, 1));
TriggerData* triggerData = nullptr; TriggerData* triggerData = nullptr;
switch(lua_type(L, 2)) { switch(lua_type(L, 2)) {
case LUA_TNUMBER: case LUA_TNUMBER:
triggerData = mgr->Get(lua_tointeger(L, 2)); triggerData = mgr->Find(lua_tointeger(L, 2));
break; break;
case LUA_TSTRING: case LUA_TSTRING:
triggerData = mgr->Get(lua_tostring(L, 2)); triggerData = mgr->Find(lua_tostring(L, 2));
break; break;
} }
@@ -137,7 +137,7 @@ static int getLoadedCount(lua_State* L) {
static const luaL_Reg triggerManagerLib[] = { static const luaL_Reg triggerManagerLib[] = {
{"Create",create}, {"Create",create},
{"Unload",unload}, {"Unload",unload},
{"GetTrigger",getTrigger}, {"FindTrigger",findTrigger},
{"GetCount",getLoadedCount}, {"GetCount",getLoadedCount},
{nullptr, nullptr} {nullptr, nullptr}
}; };