[Friends] Optimize sorting
This commit is contained in:
parent
d31ff2e180
commit
5798de30be
@ -2,7 +2,9 @@
|
||||
|
||||
namespace Components
|
||||
{
|
||||
bool Friends::TriggerSort = false;
|
||||
bool Friends::TriggerUpdate = false;
|
||||
|
||||
int Friends::InitialState;
|
||||
unsigned int Friends::CurrentFriend;
|
||||
std::recursive_mutex Friends::Mutex;
|
||||
@ -15,15 +17,18 @@ namespace Components
|
||||
const Friends::Friend* friend1 = static_cast<const Friends::Friend*>(first);
|
||||
const Friends::Friend* friend2 = static_cast<const Friends::Friend*>(second);
|
||||
|
||||
std::string name1 = Utils::String::ToLower(Colors::Strip(friend1->name));
|
||||
std::string name2 = Utils::String::ToLower(Colors::Strip(friend2->name));
|
||||
|
||||
return name1.compare(name2);
|
||||
return friend1->cleanName.compare(friend2->cleanName);
|
||||
});
|
||||
}
|
||||
|
||||
void Friends::SortList()
|
||||
void Friends::SortList(bool force)
|
||||
{
|
||||
if(!force)
|
||||
{
|
||||
Friends::TriggerSort = true;
|
||||
return;
|
||||
}
|
||||
|
||||
std::lock_guard<std::recursive_mutex> _(Friends::Mutex);
|
||||
|
||||
std::vector<Friends::Friend> connectedList;
|
||||
@ -68,6 +73,7 @@ namespace Components
|
||||
|
||||
entry->name = Steam::Proxy::SteamFriends->GetFriendPersonaName(user);
|
||||
entry->online = Steam::Proxy::SteamFriends->GetFriendPersonaState(user) != 0;
|
||||
entry->cleanName = Utils::String::ToLower(Colors::Strip(entry->name));
|
||||
|
||||
std::string guid = Steam::Proxy::SteamFriends->GetFriendRichPresence(user, "iw4x_guid");
|
||||
std::string name = Steam::Proxy::SteamFriends->GetFriendRichPresence(user, "iw4x_name");
|
||||
@ -426,10 +432,19 @@ namespace Components
|
||||
QuickPatch::OnFrame([]()
|
||||
{
|
||||
static Utils::Time::Interval interval;
|
||||
static Utils::Time::Interval sortInterval;
|
||||
static Utils::Time::Interval stateInterval;
|
||||
|
||||
if(interval.elapsed(5s))
|
||||
if (interval.elapsed(2min))
|
||||
{
|
||||
interval.update();
|
||||
Friends::UpdateTimeStamp();
|
||||
Friends::UpdateState();
|
||||
}
|
||||
|
||||
if(stateInterval.elapsed(5s))
|
||||
{
|
||||
stateInterval.update();
|
||||
|
||||
if(Friends::TriggerUpdate)
|
||||
{
|
||||
@ -438,6 +453,17 @@ namespace Components
|
||||
}
|
||||
}
|
||||
|
||||
if(sortInterval.elapsed(3s))
|
||||
{
|
||||
stateInterval.update();
|
||||
|
||||
if (Friends::TriggerSort)
|
||||
{
|
||||
Friends::TriggerSort = false;
|
||||
Friends::SortList(true);
|
||||
}
|
||||
}
|
||||
|
||||
if(*reinterpret_cast<bool*>(0x1AD5690)) // LiveStorage_DoWeHaveStats
|
||||
{
|
||||
Friends::UpdateRank();
|
||||
@ -475,18 +501,6 @@ namespace Components
|
||||
|
||||
Friends::UpdateFriends();
|
||||
});
|
||||
|
||||
QuickPatch::OnFrame([]()
|
||||
{
|
||||
static Utils::Time::Interval interval;
|
||||
|
||||
if(interval.elapsed(2min))
|
||||
{
|
||||
interval.update();
|
||||
Friends::UpdateTimeStamp();
|
||||
Friends::UpdateState();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Friends::~Friends()
|
||||
|
@ -42,6 +42,7 @@ namespace Components
|
||||
SteamID guid;
|
||||
std::string name;
|
||||
std::string playerName;
|
||||
std::string cleanName;
|
||||
Network::Address server;
|
||||
std::string serverName;
|
||||
bool online;
|
||||
@ -50,6 +51,7 @@ namespace Components
|
||||
int prestige;
|
||||
};
|
||||
|
||||
static bool TriggerSort;
|
||||
static bool TriggerUpdate;
|
||||
static int InitialState;
|
||||
static unsigned int CurrentFriend;
|
||||
@ -65,7 +67,7 @@ namespace Components
|
||||
static void UpdateUserInfo(SteamID user);
|
||||
static void UpdateState(bool force = false);
|
||||
|
||||
static void SortList();
|
||||
static void SortList(bool force = false);
|
||||
static void SortIndividualList(std::vector<Friend>* list);
|
||||
|
||||
static unsigned int GetFriendCount();
|
||||
|
Loading…
Reference in New Issue
Block a user