mirror of
https://github.com/thunderbrewhq/thunderbrew
synced 2025-12-12 03:02:30 +00:00
feat(glue): implement update realm list
This commit is contained in:
parent
780de91468
commit
41554f32b4
4 changed files with 88 additions and 1 deletions
|
|
@ -58,6 +58,14 @@ ClientServices* ClientServices::GetInstance() {
|
||||||
return ClientServices::s_instance;
|
return ClientServices::s_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
REALM_INFO* ClientServices::GetRealmInfoByIndex(int32_t index) {
|
||||||
|
if (index >= ClientServices::GetInstance()->m_realmList.Count()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return &ClientServices::GetInstance()->m_realmList[index];
|
||||||
|
}
|
||||||
|
|
||||||
const char* ClientServices::GetSelectedRealmName() {
|
const char* ClientServices::GetSelectedRealmName() {
|
||||||
if (!ClientServices::s_realmNameVar) {
|
if (!ClientServices::s_realmNameVar) {
|
||||||
ClientServices::s_realmNameVar = CVar::Register(
|
ClientServices::s_realmNameVar = CVar::Register(
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ class ClientServices : public LoginResponse {
|
||||||
static void ConnectToSelectedServer();
|
static void ConnectToSelectedServer();
|
||||||
static ClientConnection* Connection();
|
static ClientConnection* Connection();
|
||||||
static ClientServices* GetInstance();
|
static ClientServices* GetInstance();
|
||||||
|
static REALM_INFO* GetRealmInfoByIndex(int32_t index);
|
||||||
static const char* GetSelectedRealmName();
|
static const char* GetSelectedRealmName();
|
||||||
static void Initialize();
|
static void Initialize();
|
||||||
static Login* LoginConnection();
|
static Login* LoginConnection();
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,15 @@
|
||||||
#include "glue/CRealmList.hpp"
|
#include "glue/CRealmList.hpp"
|
||||||
|
#include "client/ClientServices.hpp"
|
||||||
#include "db/Db.hpp"
|
#include "db/Db.hpp"
|
||||||
|
#include "ui/FrameScript.hpp"
|
||||||
|
#include <new>
|
||||||
#include <storm/Memory.hpp>
|
#include <storm/Memory.hpp>
|
||||||
|
#include <storm/String.hpp>
|
||||||
|
|
||||||
|
float CRealmList::s_avgLoad;
|
||||||
TSFixedArray<RealmCategory*> CRealmList::s_categories;
|
TSFixedArray<RealmCategory*> CRealmList::s_categories;
|
||||||
|
int32_t CRealmList::s_preferredCategory = -1;
|
||||||
|
int32_t CRealmList::s_selectedCategory = -1;
|
||||||
|
|
||||||
void CRealmList::Initialize() {
|
void CRealmList::Initialize() {
|
||||||
CRealmList::s_categories.SetCount(g_cfg_CategoriesDB.m_numRecords);
|
CRealmList::s_categories.SetCount(g_cfg_CategoriesDB.m_numRecords);
|
||||||
|
|
@ -20,5 +27,73 @@ void CRealmList::Initialize() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CRealmList::UpdateList() {
|
void CRealmList::UpdateList() {
|
||||||
|
CRealmList::s_avgLoad = 0.0f;
|
||||||
|
int32_t category = -1;
|
||||||
|
auto realmCount = ClientServices::GetInstance()->m_realmList.Count();
|
||||||
|
|
||||||
|
for (int32_t realmIndex = 0; realmIndex < realmCount; realmIndex++) {
|
||||||
|
auto realmInfo = ClientServices::GetRealmInfoByIndex(realmIndex);
|
||||||
|
if (!realmInfo) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto selectedRealmName = ClientServices::GetSelectedRealmName();
|
||||||
|
|
||||||
|
if (!SStrCmpI(selectedRealmName, realmInfo->name, STORM_MAX_STR) /* TODO SStrCmpUTF8I */) {
|
||||||
|
if (CRealmList::s_preferredCategory < 0) {
|
||||||
|
CRealmList::s_preferredCategory = realmInfo->category;
|
||||||
|
}
|
||||||
|
|
||||||
|
category = realmInfo->category;
|
||||||
|
}
|
||||||
|
|
||||||
|
CRealmList::s_avgLoad += realmInfo->population;
|
||||||
|
|
||||||
|
for (int32_t categoryIndex = 0; categoryIndex < CRealmList::s_categories.Count(); categoryIndex++) {
|
||||||
|
auto realmCategory = CRealmList::s_categories[categoryIndex];
|
||||||
|
|
||||||
|
if (realmInfo->category != realmCategory->m_category->m_ID) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (realmCategory->m_realms.Count() == realmCategory->uint14) {
|
||||||
|
realmCategory->m_realms.SetCount(realmCategory->uint14 + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
realmCategory->m_realms[realmCategory->uint14] = realmIndex;
|
||||||
|
realmCategory->uint14++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (realmCount <= 1) {
|
||||||
|
CRealmList::s_avgLoad = 1.0f;
|
||||||
|
} else {
|
||||||
// TODO
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO CRealmList::m_stdDevLoad
|
||||||
|
|
||||||
|
// TODO sort realm list
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < CRealmList::s_categories.Count(); i++) {
|
||||||
|
if (CRealmList::s_categories[i]->m_category->m_ID == category) {
|
||||||
|
CRealmList::s_selectedCategory = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CRealmList::s_preferredCategory != -1 /* TODO || ClientServices::Connection()->uint2F10 */) {
|
||||||
|
FrameScript_SignalEvent(9, nullptr);
|
||||||
|
} else {
|
||||||
|
uint32_t nonEmptyCategories = 0;
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < CRealmList::s_categories.Count(); i++) {
|
||||||
|
auto realmCategory = CRealmList::s_categories[i];
|
||||||
|
|
||||||
|
if (realmCategory && realmCategory->uint14 != 0) {
|
||||||
|
nonEmptyCategories++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FrameScript_SignalEvent(10, "%d", nonEmptyCategories);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,10 @@ struct RealmCategory {
|
||||||
class CRealmList {
|
class CRealmList {
|
||||||
public:
|
public:
|
||||||
// Static variables
|
// Static variables
|
||||||
|
static float s_avgLoad;
|
||||||
static TSFixedArray<RealmCategory*> s_categories;
|
static TSFixedArray<RealmCategory*> s_categories;
|
||||||
|
static int32_t s_preferredCategory;
|
||||||
|
static int32_t s_selectedCategory;
|
||||||
|
|
||||||
// Static functions
|
// Static functions
|
||||||
static void Initialize();
|
static void Initialize();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue