I recently have been working on a class with the goal of allowing easy and fast access to “Tweekable Values” Inside code. I have been calling this class “Tweeks” and it works great as a subsystem. Sometimes this is handy when you have a short subroutine that only happens once or twice.
Example In Code Usage:
float scalar = GetSubsystem<Tweeks>()->Get<float>(“scalar”);
//use scalar in your routine
You can also reference the the same Tweek elsewhere in code with another call to Get() with the same unique name “scalar”.
At any time you can save the state of tweeks or load the state of tweeks.
Get() should work with any Urho3D::Variant type.
For further control you can specify “sections” for tweeks to allow for better separation:
float scalar = GetSubsystem<Tweeks>()->Get<float>(“scalar”, “myroutine”);
Or default values:
float scalar = GetSubsystem<Tweeks>()->Get<float>(“scalar”, 1.0f);
You can also get more info on the state of a tweek by using GetTweek():
Tweek* tweek = GetSubsystem<Tweeks>()->GetTweek(“scalar”, “myroutine”);
Tweeks have a “Lifetime” whereas they are marked as expired after their lifetime is up. every call to Get or Update resets the tweek’s lifetime counter.
You can check if a tweek is expired using tweek->IsExpired().
default lifetime is 2 seconds.
There are methods for restricting and extending the lifetime of tweeks in the Tweek class, as well as a push/pop stack for sections and lifetimes in the subsystem:
GetSubsystem<Tweeks>()->BeginSection(“mySection”);
GetSubsystem<Tweeks>()->BeginLifetime(1000);//tweeks modified here will be in the section: “mySection” and have a lifetime of 1000 milliseconds.
GetSubsystem<Tweeks>()->EndLifetime();
GetSubsystem<Tweeks>()->EndSection();
Link to code: