Skip to content

Commit

Permalink
Update timer value using demo data
Browse files Browse the repository at this point in the history
Adds CustomHud::SetTime.

Ensures that bxt_timer_stop and similar commands are called during
demo, and that the timer stops after game end.
  • Loading branch information
eim64 authored and YaLTeR committed Jul 23, 2023
1 parent 15239ae commit e109e80
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
4 changes: 4 additions & 0 deletions BunnymodXT/hud_custom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1868,6 +1868,10 @@ namespace CustomHud
milliseconds };
}

void SetTime(int h, int m, int s, double r) {
hours = h, minutes = m, seconds = s, timeRemainder = r;
}

bool GetCountingTime()
{
return countingTime;
Expand Down
1 change: 1 addition & 0 deletions BunnymodXT/hud_custom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace CustomHud
void UpdatePlayerInfoInaccurate(float vel[3], float org[3]);

void TimePassed(double time);
void SetTime(int hours, int minutes, int seconds, double remainder);
void ResetTime();
void SetCountingTime(bool counting);
void SetInvalidRun(bool invalidated);
Expand Down
33 changes: 27 additions & 6 deletions BunnymodXT/runtime_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,22 +510,43 @@ namespace RuntimeData
}

// Visitor applied to each Data object found in demo.
class demo_data_visitor : public boost::static_visitor<>
{
class demo_data_visitor : public boost::static_visitor<> {
public:
void operator()(const RuntimeData::Time& t) const {}
void operator()(const RuntimeData::Time& t) const {
CustomHud::SetTime((int)t.hours, (int)t.minutes, (int)t.seconds, t.remainder);
}

void operator()(const RuntimeData::CommandExecution& e) const {
for (const auto& cmd : cmd_whitelist) {
if (e.command.rfind(cmd, 0) == 0) {
HwDLL::GetInstance().ORIG_Cbuf_InsertText(e.command.c_str());
HwDLL::GetInstance().ORIG_Cbuf_InsertText("\n");
}
}
}

void operator()(const RuntimeData::GameEndMarker& m) const {
CustomHud::SetCountingTime(false);
}

void operator()(const RuntimeData::PlayerHealth& p) const {}
void operator()(const RuntimeData::VersionInfo& v) const {}
void operator()(const RuntimeData::CVarValues& v) const {}
void operator()(const RuntimeData::BoundCommand& c) const {}
void operator()(const RuntimeData::AliasExpansion& e) const {}
void operator()(const RuntimeData::ScriptExecution& e) const {}
void operator()(const RuntimeData::CommandExecution& e) const {}
void operator()(const RuntimeData::GameEndMarker& m) const {}
void operator()(const RuntimeData::LoadedModules& m) const {}
void operator()(const RuntimeData::CustomTriggerCommand& c) const {}
void operator()(const RuntimeData::Edicts& e) const {}
void operator()(const RuntimeData::SplitMarker& m) const { }
void operator()(const RuntimeData::SplitMarker& m) const {}

private:
// bxt commands that should be executed when found during demo playback
const std::vector<std::string> cmd_whitelist = {
"bxt_timer_stop",
"bxt_timer_start",
"bxt_timer_reset"
};
};

void ProcessRuntimeData(std::vector<char>& data) {
Expand Down

0 comments on commit e109e80

Please sign in to comment.