Merge pull request #218 from diamante0018/clean-up-renderer
Avoid some bad dvar look ups per frame
This commit is contained in:
commit
5e62e43438
@ -11,6 +11,10 @@ namespace Components
|
||||
std::recursive_mutex Friends::Mutex;
|
||||
std::vector<Friends::Friend> Friends::FriendsList;
|
||||
|
||||
Dvar::Var Friends::UIStreamFriendly;
|
||||
Dvar::Var Friends::CLAnonymous;
|
||||
Dvar::Var Friends::CLNotifyFriendState;
|
||||
|
||||
void Friends::SortIndividualList(std::vector<Friends::Friend>* list)
|
||||
{
|
||||
std::stable_sort(list->begin(), list->end(), [](Friends::Friend const& friend1, Friends::Friend const& friend2)
|
||||
@ -111,8 +115,8 @@ namespace Components
|
||||
|
||||
Friends::SortList();
|
||||
|
||||
const auto notify = Dvar::Var("cl_notifyFriendState").get<bool>();
|
||||
if (gotOnline && (!notify || (notify && !Game::CL_IsCgameInitialized())) && !Dvar::Var("ui_streamFriendly").get<bool>())
|
||||
const auto notify = Friends::CLNotifyFriendState.get<bool>();
|
||||
if (gotOnline && (!notify || (notify && !Game::CL_IsCgameInitialized())) && !Friends::UIStreamFriendly.get<bool>())
|
||||
{
|
||||
Game::Material* material = Friends::CreateAvatar(user);
|
||||
Toast::Show(material, entry->name, "is playing IW4x", 3000, [material]()
|
||||
@ -124,7 +128,7 @@ namespace Components
|
||||
|
||||
void Friends::UpdateState(bool force)
|
||||
{
|
||||
if (Dvar::Var("cl_anonymous").get<bool>() || Friends::IsInvisible() || !Steam::Enabled()) return;
|
||||
if (Friends::CLAnonymous.get<bool>() || Friends::IsInvisible() || !Steam::Enabled()) return;
|
||||
|
||||
if (force)
|
||||
{
|
||||
@ -228,7 +232,7 @@ namespace Components
|
||||
|
||||
void Friends::SetPresence(const std::string& key, const std::string& value)
|
||||
{
|
||||
if (Steam::Proxy::ClientFriends && Steam::Proxy::SteamUtils && !Dvar::Var("cl_anonymous").get<bool>() && !Friends::IsInvisible() && Steam::Enabled())
|
||||
if (Steam::Proxy::ClientFriends && Steam::Proxy::SteamUtils && !Friends::CLAnonymous.get<bool>() && !Friends::IsInvisible() && Steam::Enabled())
|
||||
{
|
||||
Friends::SetRawPresence(key.data(), value.data());
|
||||
}
|
||||
@ -576,10 +580,15 @@ namespace Components
|
||||
{
|
||||
Friends::LoggedOn = false;
|
||||
|
||||
if (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled() || Monitor::IsEnabled()) return;
|
||||
if (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled() || Monitor::IsEnabled())
|
||||
return;
|
||||
|
||||
Dvar::Register<bool>("cl_anonymous", false, Game::DVAR_ARCHIVE, "Enable invisible mode for Steam");
|
||||
Dvar::Register<bool>("cl_notifyFriendState", true, Game::DVAR_ARCHIVE, "Update friends about current game status");
|
||||
Dvar::OnInit([]
|
||||
{
|
||||
Friends::UIStreamFriendly = Dvar::Register<bool>("ui_streamFriendly", false, Game::DVAR_ARCHIVE, "Stream friendly UI");
|
||||
Friends::CLAnonymous = Dvar::Register<bool>("cl_anonymous", false, Game::DVAR_ARCHIVE, "Enable invisible mode for Steam");
|
||||
Friends::CLNotifyFriendState = Dvar::Register<bool>("cl_notifyFriendState", true, Game::DVAR_ARCHIVE, "Update friends about current game status");
|
||||
});
|
||||
|
||||
Command::Add("addFriend", [](Command::Params* params)
|
||||
{
|
||||
@ -712,11 +721,11 @@ namespace Components
|
||||
Friends::InitialState = Steam::Proxy::SteamFriends->GetFriendPersonaState(Steam::Proxy::SteamUser_->GetSteamID());
|
||||
}
|
||||
|
||||
if (Dvar::Var("cl_anonymous").get<bool>() || Friends::IsInvisible() || !Steam::Enabled())
|
||||
if (Friends::CLAnonymous.get<bool>() || Friends::IsInvisible() || !Steam::Enabled())
|
||||
{
|
||||
if (Steam::Proxy::ClientFriends)
|
||||
{
|
||||
for (auto id : Friends::GetAppIdList())
|
||||
for (const auto id : Friends::GetAppIdList())
|
||||
{
|
||||
Steam::Proxy::ClientFriends.invoke<void>("ClearRichPresence", id);
|
||||
}
|
||||
|
@ -25,6 +25,10 @@ namespace Components
|
||||
|
||||
static bool IsInvisible();
|
||||
|
||||
static Dvar::Var UIStreamFriendly;
|
||||
static Dvar::Var CLAnonymous;
|
||||
static Dvar::Var CLNotifyFriendState;
|
||||
|
||||
private:
|
||||
#pragma pack(push, 4)
|
||||
struct FriendRichPresenceUpdate
|
||||
|
@ -858,9 +858,6 @@ namespace Components
|
||||
});
|
||||
#endif
|
||||
|
||||
// Dvars
|
||||
Dvar::Register<bool>("ui_streamFriendly", false, Game::DVAR_ARCHIVE, "Stream friendly UI");
|
||||
|
||||
// Debug patches
|
||||
#ifdef DEBUG
|
||||
// ui_debugMode 1
|
||||
|
@ -18,7 +18,6 @@ namespace Components
|
||||
static void OnDeviceRecoveryEnd(Utils::Slot<Scheduler::Callback> callback);
|
||||
static void OnDeviceRecoveryBegin(Utils::Slot<Scheduler::Callback> callback);
|
||||
|
||||
|
||||
private:
|
||||
static void FrameStub();
|
||||
|
||||
|
@ -4,6 +4,9 @@ namespace Components
|
||||
{
|
||||
ServerInfo::Container ServerInfo::PlayerContainer;
|
||||
|
||||
Game::dvar_t** ServerInfo::CGScoreboardHeight;
|
||||
Game::dvar_t** ServerInfo::CGScoreboardWidth;
|
||||
|
||||
unsigned int ServerInfo::GetPlayerCount()
|
||||
{
|
||||
return ServerInfo::PlayerContainer.playerList.size();
|
||||
@ -74,22 +77,24 @@ namespace Components
|
||||
void ServerInfo::DrawScoreboardInfo(int localClientNum)
|
||||
{
|
||||
Game::Font_s* font = Game::R_RegisterFont("fonts/bigfont", 0);
|
||||
void* cxt = Game::ScrPlace_GetActivePlacement(localClientNum);
|
||||
const auto* cxt = Game::ScrPlace_GetActivePlacement(localClientNum);
|
||||
|
||||
std::string addressText = Network::Address(*Game::connectedHost).getString();
|
||||
if (addressText == "0.0.0.0:0" || addressText == "loopback") addressText = "Listen Server";
|
||||
auto addressText = Network::Address(*Game::connectedHost).getString();
|
||||
|
||||
// get x positions
|
||||
float fontSize = 0.35f;
|
||||
float y = (480.0f - Dvar::Var("cg_scoreboardHeight").get<float>()) * 0.5f;
|
||||
y += Dvar::Var("cg_scoreboardHeight").get<float>() + 6.0f;
|
||||
if (addressText == "0.0.0.0:0" || addressText == "loopback")
|
||||
addressText = "Listen Server";
|
||||
|
||||
float x = 320.0f - Dvar::Var("cg_scoreboardWidth").get<float>() * 0.5f;
|
||||
float x2 = 320.0f + Dvar::Var("cg_scoreboardWidth").get<float>() * 0.5f;
|
||||
// Get x positions
|
||||
auto y = (480.0f - (*ServerInfo::CGScoreboardHeight)->current.value) * 0.5f;
|
||||
y += (*ServerInfo::CGScoreboardHeight)->current.value + 6.0f;
|
||||
|
||||
// draw only when stream friendly ui is not enabled
|
||||
if (!Dvar::Var("ui_streamFriendly").get<bool>())
|
||||
const auto x = 320.0f - (*ServerInfo::CGScoreboardWidth)->current.value * 0.5f;
|
||||
const auto x2 = 320.0f + (*ServerInfo::CGScoreboardWidth)->current.value * 0.5f;
|
||||
|
||||
// Draw only when stream friendly ui is not enabled
|
||||
if (!Friends::UIStreamFriendly.get<bool>())
|
||||
{
|
||||
constexpr auto fontSize = 0.35f;
|
||||
Game::UI_DrawText(cxt, reinterpret_cast<const char*>(0x7ED3F8), 0x7FFFFFFF, font, x, y, 0, 0, fontSize, reinterpret_cast<float*>(0x747F34), 3);
|
||||
Game::UI_DrawText(cxt, addressText.data(), 0x7FFFFFFF, font, x2 - Game::UI_TextWidth(addressText.data(), 0, font, fontSize), y, 0, 0, fontSize, reinterpret_cast<float*>(0x747F34), 3);
|
||||
}
|
||||
@ -172,7 +177,9 @@ namespace Components
|
||||
ServerInfo::ServerInfo()
|
||||
{
|
||||
ServerInfo::PlayerContainer.currentPlayer = 0;
|
||||
ServerInfo::PlayerContainer.playerList.clear();
|
||||
|
||||
ServerInfo::CGScoreboardHeight = reinterpret_cast<Game::dvar_t**>(0x9FD070);
|
||||
ServerInfo::CGScoreboardWidth = reinterpret_cast<Game::dvar_t**>(0x9FD0AC);
|
||||
|
||||
// Draw IP and hostname on the scoreboard
|
||||
Utils::Hook(0x4FC6EA, ServerInfo::DrawScoreboardStub, HOOK_CALL).install()->quick();
|
||||
|
@ -28,6 +28,9 @@ namespace Components
|
||||
Network::Address target;
|
||||
};
|
||||
|
||||
static Game::dvar_t** CGScoreboardHeight;
|
||||
static Game::dvar_t** CGScoreboardWidth;
|
||||
|
||||
static Container PlayerContainer;
|
||||
|
||||
static void ServerStatus(UIScript::Token);
|
||||
|
@ -14,6 +14,11 @@ namespace Components
|
||||
|
||||
std::vector<unsigned int> ServerList::VisibleList;
|
||||
|
||||
Dvar::Var ServerList::UIServerSelected;
|
||||
Dvar::Var ServerList::UIServerSelectedMap;
|
||||
Dvar::Var ServerList::NETServerQueryLimit;
|
||||
Dvar::Var ServerList::NETServerFrames;
|
||||
|
||||
std::vector<ServerList::ServerInfo>* ServerList::GetList()
|
||||
{
|
||||
if (ServerList::IsOnlineList())
|
||||
@ -154,13 +159,13 @@ namespace Components
|
||||
|
||||
if (info)
|
||||
{
|
||||
Dvar::Var("ui_serverSelected").set(true);
|
||||
Dvar::Var("ui_serverSelectedMap").set(info->mapname);
|
||||
ServerList::UIServerSelected.set(true);
|
||||
ServerList::UIServerSelectedMap.set(info->mapname);
|
||||
Dvar::Var("ui_serverSelectedGametype").set(info->gametype);
|
||||
}
|
||||
else
|
||||
{
|
||||
Dvar::Var("ui_serverSelected").set(false);
|
||||
ServerList::UIServerSelected.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -621,8 +626,11 @@ namespace Components
|
||||
void ServerList::Frame()
|
||||
{
|
||||
static Utils::Time::Interval frameLimit;
|
||||
int interval = static_cast<int>(1000.0f / Dvar::Var("net_serverFrames").get<int>());
|
||||
if (!frameLimit.elapsed(std::chrono::milliseconds(interval))) return;
|
||||
const auto interval = static_cast<int>(1000.0f / ServerList::NETServerFrames.get<int>());
|
||||
|
||||
if (!frameLimit.elapsed(std::chrono::milliseconds(interval)))
|
||||
return;
|
||||
|
||||
frameLimit.update();
|
||||
|
||||
std::lock_guard<std::recursive_mutex> _(ServerList::RefreshContainer.mutex);
|
||||
@ -638,7 +646,7 @@ namespace Components
|
||||
}
|
||||
}
|
||||
|
||||
int requestLimit = Dvar::Var("net_serverQueryLimit").get<int>();
|
||||
auto requestLimit = ServerList::NETServerQueryLimit.get<int>();
|
||||
for (unsigned int i = 0; i < ServerList::RefreshContainer.servers.size() && requestLimit > 0; ++i)
|
||||
{
|
||||
ServerList::Container::ServerContainer* server = &ServerList::RefreshContainer.servers[i];
|
||||
@ -734,11 +742,15 @@ namespace Components
|
||||
|
||||
Dvar::OnInit([]()
|
||||
{
|
||||
Dvar::Register<bool>("ui_serverSelected", false, Game::dvar_flag::DVAR_NONE, "Whether a server has been selected in the serverlist");
|
||||
Dvar::Register<const char*>("ui_serverSelectedMap", "mp_afghan", Game::dvar_flag::DVAR_NONE, "Map of the selected server");
|
||||
ServerList::UIServerSelected = Dvar::Register<bool>("ui_serverSelected", false,
|
||||
Game::dvar_flag::DVAR_NONE, "Whether a server has been selected in the serverlist");
|
||||
ServerList::UIServerSelectedMap = Dvar::Register<const char*>("ui_serverSelectedMap", "mp_afghan",
|
||||
Game::dvar_flag::DVAR_NONE, "Map of the selected server");
|
||||
|
||||
Dvar::Register<int>("net_serverQueryLimit", 1, 1, 10, Dedicated::IsEnabled() ? Game::dvar_flag::DVAR_NONE : Game::dvar_flag::DVAR_ARCHIVE, "Amount of server queries per frame");
|
||||
Dvar::Register<int>("net_serverFrames", 30, 1, 60, Dedicated::IsEnabled() ? Game::dvar_flag::DVAR_NONE : Game::dvar_flag::DVAR_ARCHIVE, "Amount of server query frames per second");
|
||||
ServerList::NETServerQueryLimit = Dvar::Register<int>("net_serverQueryLimit", 1,
|
||||
1, 10, Dedicated::IsEnabled() ? Game::dvar_flag::DVAR_NONE : Game::dvar_flag::DVAR_ARCHIVE, "Amount of server queries per frame");
|
||||
ServerList::NETServerFrames = Dvar::Register<int>("net_serverFrames", 30,
|
||||
1, 60, Dedicated::IsEnabled() ? Game::dvar_flag::DVAR_NONE : Game::dvar_flag::DVAR_ARCHIVE, "Amount of server query frames per second");
|
||||
});
|
||||
|
||||
// Fix ui_netsource dvar
|
||||
@ -794,6 +806,7 @@ namespace Components
|
||||
UIScript::Add("RefreshFilter", ServerList::UpdateVisibleList);
|
||||
|
||||
UIScript::Add("RefreshServers", ServerList::Refresh);
|
||||
|
||||
UIScript::Add("JoinServer", [](UIScript::Token)
|
||||
{
|
||||
ServerList::ServerInfo* info = ServerList::GetServer(ServerList::CurrentServer);
|
||||
@ -803,6 +816,7 @@ namespace Components
|
||||
Party::Connect(info->addr);
|
||||
}
|
||||
});
|
||||
|
||||
UIScript::Add("ServerSort", [](UIScript::Token token)
|
||||
{
|
||||
int key = token.get<int>();
|
||||
@ -820,6 +834,7 @@ namespace Components
|
||||
Logger::Print("Sorting server list by token: %d\n", ServerList::SortKey);
|
||||
ServerList::SortList();
|
||||
});
|
||||
|
||||
UIScript::Add("CreateListFavorite", [](UIScript::Token)
|
||||
{
|
||||
ServerList::ServerInfo* info = ServerList::GetCurrentServer();
|
||||
@ -829,10 +844,12 @@ namespace Components
|
||||
ServerList::StoreFavourite(info->addr.getString());
|
||||
}
|
||||
});
|
||||
|
||||
UIScript::Add("CreateFavorite", [](UIScript::Token)
|
||||
{
|
||||
ServerList::StoreFavourite(Dvar::Var("ui_favoriteAddress").get<std::string>());
|
||||
});
|
||||
|
||||
UIScript::Add("CreateCurrentServerFavorite", [](UIScript::Token)
|
||||
{
|
||||
if (Game::CL_IsCgameInitialized())
|
||||
@ -844,6 +861,7 @@ namespace Components
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
UIScript::Add("DeleteFavorite", [](UIScript::Token)
|
||||
{
|
||||
ServerList::ServerInfo* info = ServerList::GetCurrentServer();
|
||||
@ -854,17 +872,18 @@ namespace Components
|
||||
};
|
||||
});
|
||||
|
||||
#ifdef _DEBUG
|
||||
Command::Add("playerCount", [](Command::Params*)
|
||||
{
|
||||
int count = 0;
|
||||
for (auto server : ServerList::OnlineList)
|
||||
auto count = 0;
|
||||
for (const auto& server : ServerList::OnlineList)
|
||||
{
|
||||
count += server.clients;
|
||||
}
|
||||
|
||||
Logger::Print("There are %d players playing.\n", count);
|
||||
});
|
||||
|
||||
#endif
|
||||
// Add required ownerDraws
|
||||
UIScript::AddOwnerDraw(220, ServerList::UpdateSource);
|
||||
UIScript::AddOwnerDraw(253, ServerList::UpdateGameType);
|
||||
|
@ -138,5 +138,10 @@ namespace Components
|
||||
static std::vector<ServerInfo> FavouriteList;
|
||||
|
||||
static std::vector<unsigned int> VisibleList;
|
||||
|
||||
static Dvar::Var UIServerSelected;
|
||||
static Dvar::Var UIServerSelectedMap;
|
||||
static Dvar::Var NETServerQueryLimit;
|
||||
static Dvar::Var NETServerFrames;
|
||||
};
|
||||
}
|
||||
|
@ -624,7 +624,7 @@ namespace Game
|
||||
typedef void(__cdecl * Playlist_ParsePlaylists_t)(const char* data);
|
||||
extern Playlist_ParsePlaylists_t Playlist_ParsePlaylists;
|
||||
|
||||
typedef Font_s* (__cdecl * R_RegisterFont_t)(const char* asset, int safe);
|
||||
typedef Font_s*(__cdecl * R_RegisterFont_t)(const char* asset, int safe);
|
||||
extern R_RegisterFont_t R_RegisterFont;
|
||||
|
||||
typedef void(__cdecl * R_AddCmdDrawText_t)(const char *text, int maxChars, Font_s *font, float x, float y, float xScale, float yScale, float rotation, const float *color, int style);
|
||||
@ -915,13 +915,13 @@ namespace Game
|
||||
typedef void(__cdecl * UI_DrawHandlePic_t)(/*ScreenPlacement*/void *scrPlace, float x, float y, float w, float h, int horzAlign, int vertAlign, const float *color, Material *material);
|
||||
extern UI_DrawHandlePic_t UI_DrawHandlePic;
|
||||
|
||||
typedef ScreenPlacement* (__cdecl * ScrPlace_GetActivePlacement_t)(int localClientNum);
|
||||
typedef ScreenPlacement*(__cdecl * ScrPlace_GetActivePlacement_t)(int localClientNum);
|
||||
extern ScrPlace_GetActivePlacement_t ScrPlace_GetActivePlacement;
|
||||
|
||||
typedef int(__cdecl * UI_TextWidth_t)(const char *text, int maxChars, Font_s *font, float scale);
|
||||
extern UI_TextWidth_t UI_TextWidth;
|
||||
|
||||
typedef void(__cdecl * UI_DrawText_t)(void* scrPlace, const char *text, int maxChars, Font_s *font, float x, float y, int horzAlign, int vertAlign, float scale, const float *color, int style);
|
||||
typedef void(__cdecl * UI_DrawText_t)(const ScreenPlacement* scrPlace, const char* text, int maxChars, Font_s* font, float x, float y, int horzAlign, int vertAlign, float scale, const float* color, int style);
|
||||
extern UI_DrawText_t UI_DrawText;
|
||||
|
||||
typedef Font_s* (__cdecl* UI_GetFontHandle_t)(ScreenPlacement* scrPlace, int fontEnum, float scale);
|
||||
|
Loading…
Reference in New Issue
Block a user