Skip to content

Commit

Permalink
add minor cvar performance optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaulwurff committed Jul 29, 2022
1 parent 6943cb0 commit 70b8882
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions zscript/aas_cvar.zs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright Alexander 'm8f' Kromm (mmaulwurff@gmail.com) 2018-2020
/* Copyright Alexander 'm8f' Kromm (mmaulwurff@gmail.com) 2018-2020, 2022
*
* This file is a part of Autoautosave.
*
Expand Down Expand Up @@ -42,32 +42,24 @@ class aas_cvar
return result;
}

String get_string() { load(); return _cvar.GetString(); }
bool get_bool() { load(); return _cvar.GetInt(); }
int get_int() { load(); return _cvar.GetInt(); }
double get_double() { load(); return _cvar.GetFloat(); }
String get_string() { if (_cvar == NULL) load(); return _cvar.GetString(); }
bool get_bool() { if (_cvar == NULL) load(); return _cvar.GetInt(); }
int get_int() { if (_cvar == NULL) load(); return _cvar.GetInt(); }
double get_double() { if (_cvar == NULL) load(); return _cvar.GetFloat(); }

// private: ////////////////////////////////////////////////////////////////////////////////////////

private
void load()
{
if (is_loaded()) return;

_cvar = Cvar.GetCvar(_name, _player);

if (!is_loaded())
if (_cvar == NULL)
{
aas_log.error(String.Format("cvar %s not found", _name));
}
}

private
bool is_loaded()
{
return (_cvar != NULL);
}

private PlayerInfo _player;
private String _name;
private transient Cvar _cvar;
Expand Down

0 comments on commit 70b8882

Please sign in to comment.