Daemon icon indicating copy to clipboard operation
Daemon copied to clipboard

let gamelogic retrieve a reference to a CvarProxy from it's name

Open bmorel opened this issue 2 years ago • 0 comments

Currently, gamelogic can only get the value associated with a cvar, by sending the cvar's name as a std::string. This is only used (AFAIK) by the GUI subsystem, and is insufficient: to implement proper GUI, gamelogic needs to be able to retrieve:

  • current value (already works)
  • description
  • default value (if any)
  • a type description, which includes things such as: string, number (both int and float), boolean, but also boundaries when there are some (Cvar::Range)

It would then allow the gamelogic GUI subsystem to replace:

				<row>
					<input type="range" min="0" max="2000" step="10" cvar="g_bot_reactiontime"/>
					<h3> Reaction time </h3>
					<p class="inline">
						Current: <inlinecvar cvar="g_bot_reactiontime" type="number" format="%.0f"/> msecs
						<ilink onclick='Events.pushevent("exec reset g_bot_reactiontime", event)'> (reset) </ilink>
					</p>
				</row>

with:

<input type="cvar" cvar="g_bot_reactiontime" step="10" />

Which is clearly much better, as this implies that description is no longer duplicated (or desync) and also much more readable. It would be desirable to allow not generating some things, but this should be discussed in unvanquished, not here. This was really to show an example of what would be possible with a better interface.

From what I have seen, the simpler (and future-proof) solution would be to allow returning a reference or a pointer to a CvarProxy, which would be able to expose all necessary information. This class should also probably receive the "std::string description;" member currently in CVar, or maybe only provide an interface allowing to check this (since otherwise Cvar::Callback or Cvar::Range would have useless descriptions). Sadly, this requires understanding of the IPC system that I do not have, otherwise I would have done a PR instead of a ticket. I think this feature is really important to further improve the GUI and make it easier to work on. Pinging @illwieckz as he said on IRC he would also like this feature a lot.

bmorel avatar Aug 23 '22 00:08 bmorel