Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rocket: avoid doing 2 or 3 Cvar::Get() trap calls per OnUpdate() call per cvar element #2993

Merged
merged 1 commit into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/cgame/rocket/rocketConditionalElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,22 @@ class RocketConditionalElement : public Rml::Element

virtual void OnUpdate()
{
if ( dirty_value || ( !cvar.empty() && cvar_value != Cvar::GetValue( cvar.c_str() ).c_str() ) )
Rml::String value;
bool modified = false;

if ( dirty_value )
{
value = Cvar::GetValue( cvar );
modified = true;
}
else if ( !cvar.empty() )
{
value = Cvar::GetValue( cvar );

modified = cvar_value != value;
}

if ( modified )
{
if ( IsConditionValid() )
{
Expand All @@ -107,7 +122,7 @@ class RocketConditionalElement : public Rml::Element
}
}

cvar_value = Cvar::GetValue( cvar.c_str() ).c_str();
cvar_value = value;

if ( dirty_value )
{
Expand Down
25 changes: 20 additions & 5 deletions src/cgame/rocket/rocketCvarInlineElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,34 @@ class RocketCvarInlineElement : public Rml::Element

virtual void OnUpdate()
{
if ( dirty_value || ( !cvar.empty() && cvar_value.c_str() != Cvar::GetValue( cvar.c_str() ) ) )
Rml::String value;
bool modified = false;

if ( dirty_value )
{
value = Cvar::GetValue( cvar );
modified = true;
}
else if ( !cvar.empty() )
{
value = Cvar::GetValue( cvar );

modified = cvar_value != value;
}

if ( modified )
{
Rml::String value = cvar_value = Cvar::GetValue( cvar.c_str() ).c_str();
cvar_value = value;

if (!format.empty())
if ( !format.empty() )
{
if (type == NUMBER)
{
value = va( format.c_str(), atof( Cvar::GetValue( cvar.c_str() ).c_str() ) );
value = va( format.c_str(), atof( cvar_value.c_str() ) );
}
else
{
value = va( format.c_str(), Cvar::GetValue(cvar.c_str()).c_str() );
value = va( format.c_str(), cvar_value.c_str() );
}
}

Expand Down