[cvar] Make cvars properly typed

This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.

As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.

The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).

While not used yet (partly due to working out the design), cvars can
have a validation function.

Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.

nq-x11 is known to work at least well enough for the demos. More testing
will come.
This commit is contained in:
Bill Currie 2022-04-23 12:22:45 +09:00
parent 87b3c64801
commit 12c84046f3
240 changed files with 8069 additions and 4224 deletions

View file

@ -40,7 +40,7 @@ typedef struct chasestate_s {
vec3_t player_angles;
} chasestate_t;
extern struct cvar_s *chase_active;
extern int chase_active;
void Chase_Init_Cvars (void);
void Chase_Reset (void);

View file

@ -25,11 +25,29 @@
Boston, MA 02111-1307, USA
*/
#ifndef __client_hud_h_
#define __client_hud_h_
#ifndef __client_hud_h
#define __client_hud_h
extern struct cvar_s *hud_sbar;
extern struct cvar_s *hud_scoreboard_gravity;
extern struct cvar_s *hud_swap;
extern int hud_sb_lines;
#endif // __client_hud_h_
extern int hud_sbar;
extern char *hud_scoreboard_gravity;
extern int hud_swap;
extern struct view_s *sbar_view;
extern struct view_s *sbar_inventory_view;
extern struct view_s *sbar_frags_view;
extern struct view_s *hud_view;
extern struct view_s *hud_inventory_view;
extern struct view_s *hud_armament_view;
extern struct view_s *hud_frags_view;
extern struct view_s *hud_overlay_view;
extern struct view_s *hud_stuff_view;
extern struct view_s *hud_main_view;
void HUD_Init_Cvars (void);
void HUD_Calc_sb_lines (int view_size);
#endif//__client_hud_h

View file

@ -33,22 +33,22 @@
struct cbuf_s;
extern struct cvar_s *cl_upspeed;
extern struct cvar_s *cl_forwardspeed;
extern struct cvar_s *cl_backspeed;
extern struct cvar_s *cl_sidespeed;
extern float cl_upspeed;
extern float cl_forwardspeed;
extern float cl_backspeed;
extern float cl_sidespeed;
extern struct cvar_s *cl_movespeedkey;
extern float cl_movespeedkey;
extern struct cvar_s *cl_yawspeed;
extern struct cvar_s *cl_pitchspeed;
extern float cl_yawspeed;
extern float cl_pitchspeed;
extern struct cvar_s *cl_anglespeedkey;
extern float cl_anglespeedkey;
extern struct cvar_s *m_pitch;
extern struct cvar_s *m_yaw;
extern struct cvar_s *m_forward;
extern struct cvar_s *m_side;
extern float m_pitch;
extern float m_yaw;
extern float m_forward;
extern float m_side;
#define FORWARD 0
#define SIDE 1
@ -59,7 +59,7 @@ typedef struct movestate_s {
vec4f_t angles;
} movestate_t;
#define freelook (in_mlook.state & 1 || in_freelook->int_val)
#define freelook (in_mlook.state & 1 || in_freelook)
struct viewstate_s;