Navigation Menu

Skip to content

Commit

Permalink
Call getScoreboard only once per second and cache data in the JS
Browse files Browse the repository at this point in the history
  • Loading branch information
RabidSquabbit committed Dec 11, 2017
1 parent 887d961 commit 722f26b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 51 deletions.
32 changes: 0 additions & 32 deletions ElDorito/Source/Patches/Scoreboard.cpp
Expand Up @@ -11,9 +11,6 @@ namespace
void GLScoreboardPlayerConstructorHook();
void ScoreboardUpdateHook();
void SetLocalPlayerHook();
void __cdecl UpdateScoreboardEventHookHost(int a1, unsigned int a2, int a3, int a4);
char __cdecl UpdateScoreboardEventHook(int a1, int a2, int a3);
std::vector<Patches::Scoreboard::ScoreUpdateCallback> ScoreCallbacks;
}

namespace Patches::Scoreboard
Expand All @@ -39,41 +36,12 @@ namespace Patches::Scoreboard
Patch::NopFill(Pointer::Base(0x2E3241), 4); // nop out leftover data
Patch(0x2E3248, { 0x31, 0xC0 }).Apply(); // xor eax, eax
Patch::NopFill(Pointer::Base(0x2E324A), 5); // nop out leftover data
Hook(0x2E5A24, UpdateScoreboardEventHookHost, HookFlags::IsCall).Apply();
Hook(0xC654D, UpdateScoreboardEventHook, HookFlags::IsCall).Apply();
}

void OnScoreUpdate(ScoreUpdateCallback callback)
{
ScoreCallbacks.push_back(callback);
}
}

namespace
{
void __cdecl UpdateScoreboardEventHookHost(int a1, unsigned int a2, int a3, int a4)
{

// Dispatch the event to handlers
for (auto &&callback : ScoreCallbacks)
callback();

typedef char(*UpdateScoreboard)(int a1, unsigned int a2, int a3, int a4);
UpdateScoreboard Update = reinterpret_cast<UpdateScoreboard>(0x5704A0);
Update(a1, a2, a3, a4);

}
char __cdecl UpdateScoreboardEventHook(int a1, int a2, int a3)
{
// Dispatch the event to handlers
for (auto &&callback : ScoreCallbacks)
callback();

typedef char(*UpdateScoreboard)(int a1, int a2, int a3);
UpdateScoreboard Update = reinterpret_cast<UpdateScoreboard>(0x566070);
return Update(a1, a2, a3);

}
struct SslWStringHeader
{
int refCount;
Expand Down
3 changes: 0 additions & 3 deletions ElDorito/Source/Patches/Scoreboard.hpp
Expand Up @@ -4,7 +4,4 @@
namespace Patches::Scoreboard
{
void ApplyAll();

typedef std::function<void()> ScoreUpdateCallback;
void OnScoreUpdate(ScoreUpdateCallback callback);
}
26 changes: 16 additions & 10 deletions ElDorito/Source/Web/Ui/WebScoreboard.cpp
Expand Up @@ -34,10 +34,11 @@ namespace
int lastPressedTime = 0;
int postgameDisplayed;
const float postgameDelayTime = 2;
time_t scoreboardSentTime = 0;


void OnEvent(Blam::DatumIndex player, const Event *event, const EventDefinition *definition);
void OnGameInputUpdated();
void OnScoreUpdate();
}

namespace Web::Ui::WebScoreboard
Expand All @@ -46,7 +47,7 @@ namespace Web::Ui::WebScoreboard
{
Patches::Events::OnEvent(OnEvent);
Patches::Input::RegisterDefaultInputHandler(OnGameInputUpdated);
Patches::Scoreboard::OnScoreUpdate(OnScoreUpdate);
time(&scoreboardSentTime);
}

void Show(bool locked, bool postgame)
Expand Down Expand Up @@ -81,6 +82,7 @@ namespace Web::Ui::WebScoreboard
if (!is_multiplayer() && !is_main_menu())
return;


if (postgame)
{
if (Blam::Time::TicksToSeconds((Blam::Time::GetGameTicks() - postgameDisplayed)) > postgameDelayTime)
Expand All @@ -93,6 +95,16 @@ namespace Web::Ui::WebScoreboard
}
auto isMainMenu = is_main_menu();

if (!postgame && !isMainMenu) {
time_t curTime1;
time(&curTime1);
if (scoreboardSentTime != 0 && curTime1 - scoreboardSentTime > 1)
{
Web::Ui::ScreenLayer::Notify("scoreboard", getScoreboard(), true);
time(&scoreboardSentTime);
}
}

auto currentMapLoadingState = *(bool*)0x023917F0;
if (previousMapLoadingState && !currentMapLoadingState)
{
Expand Down Expand Up @@ -346,21 +358,15 @@ namespace
{
void OnEvent(Blam::DatumIndex player, const Event *event, const EventDefinition *definition)
{
//Update the scoreboard whenever an event occurs
Web::Ui::ScreenLayer::Notify("scoreboard", Web::Ui::WebScoreboard::getScoreboard(), true);

if (event->NameStringId == 0x4004D || event->NameStringId == 0x4005A) // "general_event_game_over" / "general_event_round_over"
{
Web::Ui::ScreenLayer::Notify("scoreboard", Web::Ui::WebScoreboard::getScoreboard(), true);

postgameDisplayed = Blam::Time::GetGameTicks();
postgame = true;
}
}

void OnScoreUpdate()
{
//Update the scoreboard whenever an event occurs
Web::Ui::ScreenLayer::Notify("scoreboard", Web::Ui::WebScoreboard::getScoreboard(), true);
}

void OnGameInputUpdated()
{
Expand Down
8 changes: 2 additions & 6 deletions dist/mods/ui/web/screens/scoreboard/scoreboard.js
Expand Up @@ -381,11 +381,7 @@ dew.on("voip-speaking", function(e){
});

dew.on("show", function(e){
dew.getScoreboard().then(function (data){
if(data.players){
scoreboardData = data;
}
});

isVisible = true;
dew.captureInput(e.data.locked);
locked = e.data.locked;
Expand Down Expand Up @@ -449,7 +445,7 @@ dew.on("hide", function(e){
});

function displayScoreboard(){
if(!scoreboardData)
if(jQuery.isEmptyObject(scoreboardData))
return;
var scoreboardheader = '<th></th><th class="name" colspan="2">Players</th>';
if(locked || (expandedScoreboard == 1)){
Expand Down

0 comments on commit 722f26b

Please sign in to comment.