Replaced deprecated bound functions with modern lambda-functions.

This commit is contained in:
Exynox 2024-11-16 15:51:09 +00:00
parent d4fa88b7e2
commit e921594eff
8 changed files with 28 additions and 125 deletions

View File

@ -1,5 +1,4 @@
#ifndef __INC_METIN_II_STL_H__ #pragma once
#define __INC_METIN_II_STL_H__
#include <vector> #include <vector>
#include <string> #include <string>
@ -19,15 +18,15 @@
inline void stl_lowers(std::string& rstRet) inline void stl_lowers(std::string& rstRet)
{ {
for (size_t i = 0; i < rstRet.length(); ++i) for (size_t i = 0; i < rstRet.length(); ++i)
rstRet[i] = tolower(rstRet[i]); rstRet[i] = (char) tolower(rstRet[i]);
} }
struct stringhash struct stringhash
{ {
size_t operator () (const std::string & str) const size_t operator () (const std::string & str) const
{ {
const unsigned char * s = (const unsigned char*) str.c_str(); const auto * s = (const unsigned char*) str.c_str();
const unsigned char * end = s + str.size(); const auto * end = s + str.size();
size_t h = 0; size_t h = 0;
while (s < end) while (s < end)
@ -39,98 +38,3 @@ struct stringhash
return h; return h;
} }
}; };
// code from tr1/functional_hash.h
template<typename T>
struct hash;
template<typename _Tp>
struct hash<_Tp*>
: public std::unary_function<_Tp*, std::size_t>
{
std::size_t
operator()(_Tp* __p) const
{ return reinterpret_cast<std::size_t>(__p); }
};
namespace std
{
template <class container, class Pred>
void erase_if (container & a, typename container::iterator first, typename container::iterator past, Pred pred)
{
while (first != past)
if (pred(*first))
a.erase(first++);
else
++first;
}
template <class container>
void wipe(container & a)
{
typename container::iterator first, past;
first = a.begin();
past = a.end();
while (first != past)
delete *(first++);
a.clear();
}
template <class container>
void wipe_second(container & a)
{
typename container::iterator first, past;
first = a.begin();
past = a.end();
while (first != past)
{
delete first->second;
++first;
}
a.clear();
}
template <class _Ty>
class void_mem_fun_t : public unary_function<_Ty *, void>
{
public:
explicit void_mem_fun_t(void (_Ty::*_Pm)()) : _Ptr(_Pm)
{
}
void operator()(_Ty* p) const
{
((p->*_Ptr)());
}
private:
void (_Ty::*_Ptr)();
};
template<class _Ty> inline
void_mem_fun_t<_Ty> void_mem_fun(void (_Ty::*_Pm)())
{ return (void_mem_fun_t<_Ty>(_Pm)); }
template<class _Ty>
class void_mem_fun_ref_t : public unary_function<_Ty, void>
{
public:
explicit void_mem_fun_ref_t(void (_Ty::*_Pm)()) : _Ptr(_Pm) {}
void operator()(_Ty& x) const
{ return ((x.*_Ptr)()); }
private:
void (_Ty::*_Ptr)();
};
template<class _Ty> inline
void_mem_fun_ref_t<_Ty> void_mem_fun_ref(void (_Ty::*_Pm)())
{ return (void_mem_fun_ref_t< _Ty>(_Pm)); }
};
#endif

View File

@ -1009,7 +1009,8 @@ void CHARACTER::ItemDropPenalty(LPCHARACTER pkKiller)
if (!vec_bSlots.empty()) if (!vec_bSlots.empty())
{ {
random_shuffle(vec_bSlots.begin(), vec_bSlots.end()); unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::shuffle(vec_bSlots.begin(), vec_bSlots.end(), std::default_random_engine(seed));
int iQty = std::min<int>(vec_bSlots.size(), r.iInventoryQty); int iQty = std::min<int>(vec_bSlots.size(), r.iInventoryQty);
@ -1041,7 +1042,9 @@ void CHARACTER::ItemDropPenalty(LPCHARACTER pkKiller)
if (!vec_bSlots.empty()) if (!vec_bSlots.empty())
{ {
random_shuffle(vec_bSlots.begin(), vec_bSlots.end()); unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::shuffle(vec_bSlots.begin(), vec_bSlots.end(), std::default_random_engine(seed));
int iQty; int iQty;
if (isDropAllEquipments) if (isDropAllEquipments)

View File

@ -663,7 +663,7 @@ void CHARACTER_MANAGER::Update(int iPulse)
else else
{ {
//for_each(v.begin(), v.end(), mem_fun(&CFSM::Update)); //for_each(v.begin(), v.end(), mem_fun(&CFSM::Update));
for_each(v.begin(), v.end(), bind2nd(mem_fun(&CHARACTER::UpdateCharacter), iPulse)); for (auto& ch : v) ch->UpdateCharacter(iPulse);
} }
} }
@ -678,7 +678,7 @@ void CHARACTER_MANAGER::Update(int iPulse)
v.reserve(m_set_pkChrState.size()); v.reserve(m_set_pkChrState.size());
transform(m_set_pkChrState.begin(), m_set_pkChrState.end(), back_inserter(v), identity<CHARACTER_SET::value_type>()); transform(m_set_pkChrState.begin(), m_set_pkChrState.end(), back_inserter(v), identity<CHARACTER_SET::value_type>());
for_each(v.begin(), v.end(), bind2nd(mem_fun(&CHARACTER::UpdateStateMachine), iPulse)); for (auto& ch : v) ch->UpdateStateMachine(iPulse);
} }
} }
@ -688,8 +688,7 @@ void CHARACTER_MANAGER::Update(int iPulse)
if (CHARACTER_MANAGER::instance().GetCharactersByRaceNum(xmas::MOB_SANTA_VNUM, i)) if (CHARACTER_MANAGER::instance().GetCharactersByRaceNum(xmas::MOB_SANTA_VNUM, i))
{ {
for_each(i.begin(), i.end(), for (auto& ch : i) ch->UpdateStateMachine(iPulse);
bind2nd(mem_fun(&CHARACTER::UpdateStateMachine), iPulse));
} }
} }

View File

@ -618,15 +618,15 @@ void CGuild::Load(DWORD guild_id)
m_data.guild_id = guild_id; m_data.guild_id = guild_id;
DBManager::instance().FuncQuery(std::bind1st(std::mem_fun(&CGuild::LoadGuildData), this), DBManager::instance().FuncQuery([this](auto const& msg) { LoadGuildData(msg); },
"SELECT master, level, exp, name, skill_point, skill, sp, ladder_point, win, draw, loss, gold FROM guild%s WHERE id = %u", get_table_postfix(), m_data.guild_id); "SELECT master, level, exp, name, skill_point, skill, sp, ladder_point, win, draw, loss, gold FROM guild%s WHERE id = %u", get_table_postfix(), m_data.guild_id);
SPDLOG_DEBUG("GUILD: loading guild id {:>12} {}", m_data.name, guild_id); SPDLOG_DEBUG("GUILD: loading guild id {:>12} {}", m_data.name, guild_id);
DBManager::instance().FuncQuery(std::bind1st(std::mem_fun(&CGuild::LoadGuildGradeData), this), DBManager::instance().FuncQuery([this](auto const& msg) { LoadGuildGradeData(msg); },
"SELECT grade, name, auth+0 FROM guild_grade%s WHERE guild_id = %u", get_table_postfix(), m_data.guild_id); "SELECT grade, name, auth+0 FROM guild_grade%s WHERE guild_id = %u", get_table_postfix(), m_data.guild_id);
DBManager::instance().FuncQuery(std::bind1st(std::mem_fun(&CGuild::LoadGuildMemberData), this), DBManager::instance().FuncQuery([this](auto const& msg) { LoadGuildMemberData(msg); },
"SELECT pid, grade, is_general, offer, level, job, name FROM guild_member%s, player%s WHERE guild_id = %u and pid = id", get_table_postfix(), get_table_postfix(), guild_id); "SELECT pid, grade, is_general, offer, level, job, name FROM guild_member%s, player%s WHERE guild_id = %u and pid = id", get_table_postfix(), get_table_postfix(), guild_id);
} }
@ -756,7 +756,7 @@ void CGuild::__P2PUpdateGrade(SQLMsg* pmsg)
void CGuild::P2PChangeGrade(BYTE grade) void CGuild::P2PChangeGrade(BYTE grade)
{ {
DBManager::instance().FuncQuery(std::bind1st(std::mem_fun(&CGuild::__P2PUpdateGrade),this), DBManager::instance().FuncQuery([this](auto const& msg) { __P2PUpdateGrade(msg); },
"SELECT grade, name, auth+0 FROM guild_grade%s WHERE guild_id = %u and grade = %d", get_table_postfix(), m_data.guild_id, grade); "SELECT grade, name, auth+0 FROM guild_grade%s WHERE guild_id = %u and grade = %d", get_table_postfix(), m_data.guild_id, grade);
} }
@ -1011,7 +1011,7 @@ void CGuild::AddComment(LPCHARACTER ch, const std::string& str)
char text[GUILD_COMMENT_MAX_LEN * 2 + 1]; char text[GUILD_COMMENT_MAX_LEN * 2 + 1];
DBManager::instance().EscapeString(text, sizeof(text), str.c_str(), str.length()); DBManager::instance().EscapeString(text, sizeof(text), str.c_str(), str.length());
DBManager::instance().FuncAfterQuery(void_bind(std::bind1st(std::mem_fun(&CGuild::RefreshCommentForce),this),ch->GetPlayerID()), DBManager::instance().FuncAfterQuery([this, ch]() { this->RefreshCommentForce(ch->GetPlayerID()); },
"INSERT INTO guild_comment%s(guild_id, name, notice, content, time) VALUES(%u, '%s', %d, '%s', NOW())", "INSERT INTO guild_comment%s(guild_id, name, notice, content, time) VALUES(%u, '%s', %d, '%s', NOW())",
get_table_postfix(), m_data.guild_id, ch->GetName(), (str[0] == '!') ? 1 : 0, text); get_table_postfix(), m_data.guild_id, ch->GetName(), (str[0] == '!') ? 1 : 0, text);
} }
@ -1223,7 +1223,7 @@ void CGuild::SkillLevelUp(DWORD dwVnum)
break; break;
}*/ }*/
for_each(m_memberOnline.begin(), m_memberOnline.end(), std::bind1st(std::mem_fun_ref(&CGuild::SendSkillInfoPacket),*this)); for (auto& ch : m_memberOnline) SendSkillInfoPacket(ch);
SPDLOG_DEBUG("Guild SkillUp: {} {} level {} type {}", GetName(), pkSk->dwVnum, m_data.abySkill[dwRealVnum], pkSk->dwType); SPDLOG_DEBUG("Guild SkillUp: {} {} level {} type {}", GetName(), pkSk->dwVnum, m_data.abySkill[dwRealVnum], pkSk->dwType);
} }
@ -1482,7 +1482,7 @@ void CGuild::GuildPointChange(BYTE type, int amount, bool save)
SaveSkill(); SaveSkill();
} }
for_each(m_memberOnline.begin(), m_memberOnline.end(), std::bind1st(std::mem_fun_ref(&CGuild::SendSkillInfoPacket),*this)); for (auto& ch : m_memberOnline) SendSkillInfoPacket(ch);
break; break;
case POINT_EXP: case POINT_EXP:
@ -1513,7 +1513,7 @@ void CGuild::GuildPointChange(BYTE type, int amount, bool save)
ChangeLadderPoint(GUILD_LADDER_POINT_PER_LEVEL); ChangeLadderPoint(GUILD_LADDER_POINT_PER_LEVEL);
// NOTIFY_GUILD_EXP_CHANGE // NOTIFY_GUILD_EXP_CHANGE
for_each(m_memberOnline.begin(), m_memberOnline.end(), std::bind1st(std::mem_fun(&CGuild::SendGuildInfoPacket), this)); for (auto& ch : m_memberOnline) SendGuildInfoPacket(ch);
// END_OF_NOTIFY_GUILD_EXP_CHANGE // END_OF_NOTIFY_GUILD_EXP_CHANGE
} }

View File

@ -284,7 +284,7 @@ int CGuildManager::GetRank(CGuild* g)
return rank; return rank;
} }
struct FGuildCompare : public std::binary_function<CGuild*, CGuild*, bool> struct FGuildCompare
{ {
bool operator () (CGuild* g1, CGuild* g2) const bool operator () (CGuild* g1, CGuild* g2) const
{ {
@ -942,16 +942,13 @@ std::vector<CGuildWarReserveForGame *> & CGuildManager::GetReserveWarRef()
void CGuildManager::ChangeMaster(DWORD dwGID) void CGuildManager::ChangeMaster(DWORD dwGID)
{ {
TGuildMap::iterator iter = m_mapGuild.find(dwGID); auto iter = m_mapGuild.find(dwGID);
if (iter != m_mapGuild.end()) if (iter != m_mapGuild.end())
{
iter->second->Load(dwGID); iter->second->Load(dwGID);
}
// 업데이트된 정보 보내주기 // 업데이트된 정보 보내주기
DBManager::instance().FuncQuery(std::bind1st(std::mem_fun(&CGuild::SendGuildDataUpdateToAllMember), iter->second), DBManager::instance().FuncQuery([iter](auto const& msg) { iter->second->SendGuildDataUpdateToAllMember(msg); },
"SELECT 1"); "SELECT 1");
} }

View File

@ -1682,7 +1682,7 @@ void CInputDB::ReloadProto(const char * c_pData)
CMotionManager::instance().Build(); CMotionManager::instance().Build();
CHARACTER_MANAGER::instance().for_each_pc(std::mem_fun(&CHARACTER::ComputePoints)); CHARACTER_MANAGER::instance().for_each_pc([](auto& pc) { pc->ComputePoints(); });
} }
void CInputDB::GuildSkillUsableChange(const char* c_pData) void CInputDB::GuildSkillUsableChange(const char* c_pData)

View File

@ -43,7 +43,7 @@ void MessengerManager::Login(MessengerManager::keyA account)
if (m_set_loginAccount.find(account) != m_set_loginAccount.end()) if (m_set_loginAccount.find(account) != m_set_loginAccount.end())
return; return;
DBManager::instance().FuncQuery(std::bind1st(std::mem_fun(&MessengerManager::LoadList), this), DBManager::instance().FuncQuery([this](auto const& msg) { LoadList(msg); },
"SELECT account, companion FROM messenger_list%s WHERE account='%s'", get_table_postfix(), account.c_str()); "SELECT account, companion FROM messenger_list%s WHERE account='%s'", get_table_postfix(), account.c_str());
m_set_loginAccount.insert(account); m_set_loginAccount.insert(account);

View File

@ -109,7 +109,7 @@ bool CMobManager::Initialize(TMobTable * pTable, int iSize)
// END_OF_LOCALE_SERVICE // END_OF_LOCALE_SERVICE
//exit(EXIT_FAILURE); //exit(EXIT_FAILURE);
CHARACTER_MANAGER::instance().for_each_pc(std::bind1st(std::mem_fun(&CMobManager::RebindMobProto),this)); CHARACTER_MANAGER::instance().for_each_pc([this](auto& pc) { RebindMobProto(pc); });
return true; return true;
} }