diff --git a/hw/source/master.c b/hw/source/master.c index 2142eaa81..f05a34d69 100644 --- a/hw/source/master.c +++ b/hw/source/master.c @@ -55,7 +55,15 @@ typedef struct server_s { double timeout; } server_t; -static cvar_t *sv_console_plugin; +static char *sv_console_plugin; +static cvar_t sv_console_plugin_cvar = { + .name = "sv_console_plugin", + .description = + "Plugin used for the console", + .default_value = "server", + .flags = CVAR_ROM, + .value = { .type = 0, .value = &sv_console_plugin }, +}; SERVER_PLUGIN_PROTOS static plugin_list_t server_plugin_list[] = { SERVER_PLUGIN_LIST @@ -535,10 +543,9 @@ main (int argc, const char **argv) PI_Init (); - sv_console_plugin = Cvar_Get ("sv_console_plugin", "server", - CVAR_ROM, 0, "Plugin used for the console"); + Cvar_Register (&sv_console_plugin_cvar, 0, 0); PI_RegisterPlugins (server_plugin_list); - Con_Init (sv_console_plugin->string); + Con_Init (sv_console_plugin); if (con_module) con_module->data->console->cbuf = mst_cbuf; con_list_print = Sys_Printf; diff --git a/include/QF/GL/qf_rmain.h b/include/QF/GL/qf_rmain.h index 8aeb4c898..a9aea8770 100644 --- a/include/QF/GL/qf_rmain.h +++ b/include/QF/GL/qf_rmain.h @@ -38,7 +38,7 @@ extern int c_brush_polys, c_alias_polys; extern float gl_modelalpha; //extern vec3_t shadecolor; -extern void gl_multitexture_f (struct cvar_s *var); +extern void gl_multitexture_f (void *data, const struct cvar_s *var); void glrmain_init (void); void gl_R_RotateForEntity (struct entity_s *e); diff --git a/include/QF/Vulkan/cvars.h b/include/QF/Vulkan/cvars.h index 54a34048b..c9869d1c2 100644 --- a/include/QF/Vulkan/cvars.h +++ b/include/QF/Vulkan/cvars.h @@ -1,8 +1,8 @@ #ifndef __QF_Vulkan_cvars_h #define __QF_Vulkan_cvars_h -extern struct cvar_s *vulkan_use_validation; -extern struct cvar_s *vulkan_presentation_mode; -extern struct cvar_s *vulkan_frame_count; +extern int vulkan_use_validation; +extern int vulkan_presentation_mode; +extern int vulkan_frame_count; #endif//__QF_Vulkan_cvars_h diff --git a/include/QF/cmd.h b/include/QF/cmd.h index b57e8ca15..f9ae0c7b6 100644 --- a/include/QF/cmd.h +++ b/include/QF/cmd.h @@ -85,7 +85,7 @@ struct cbuf_interpreter_s *Cmd_GetProvider(const char *name); extern struct cbuf_args_s *cmd_args; -extern struct cvar_s *cmd_warncmd; +extern int cmd_warncmd; ///@} diff --git a/include/QF/cvar.h b/include/QF/cvar.h index 2fe20aafa..de87ee6ff 100644 --- a/include/QF/cvar.h +++ b/include/QF/cvar.h @@ -33,31 +33,20 @@ */ ///@{ +#include "QF/cexpr.h" #include "QF/listener.h" #include "QF/qtypes.h" #include "QF/quakeio.h" typedef struct cvar_s { - const char *name; ///< The name of the cvar. - const char *string; ///< The current cvar value as a string. - const char *default_string; ///< The default value of the cvar. - int flags; ///< Cvar flags - /** Callback for when the cvar value changes. - - This allows for more flexibility in what happens when a cvar is - nodifed than can be achieved with flags alone. While a similar could - be done using commands, a cvar with a callback and CVAR_ARCHIVE set - allows the setting to be saved automatically. - - \param var This cvar. - */ - void (*callback)(struct cvar_s *var); + const char *name; + const char *description; + const char *default_value; + unsigned flags; + exprval_t value; + int (*validator) (const struct cvar_s *var); struct cvar_listener_set_s *listeners; - const char *description; ///< for "help" command - float value; ///< The current cvar value as a float - int int_val; ///< The current cvar value as an integer - vec3_t vec; ///< The current cvar value as a vector - struct cvar_s *next; ///< \internal Linked list of cvars. + struct cvar_s *next; } cvar_t; typedef struct cvar_listener_set_s LISTENER_SET_TYPE (cvar_t) @@ -88,16 +77,14 @@ typedef struct cvar_alias_s { ///< (not implemented) #define CVAR_ROM 64 ///< display only, cannot be set #define CVAR_USER_CREATED 128 ///< created by a set command +#define CVAR_REGISTERED 256 ///< var has been registered #define CVAR_LATCH 2048 ///< will change only when C code next does ///< a Cvar_Get(), so it can't be changed ///< (not implemented) ///@} -// Returns the Cvar if found, creates it with value if not. Description and -// flags are always updated. -cvar_t *Cvar_Get (const char *name, const char *value, int cvarflags, - void (*callback)(cvar_t*), const char *description); +void Cvar_Register (cvar_t *var, cvar_listener_t listener, void *data); cvar_t *Cvar_FindAlias (const char *alias_name); @@ -107,17 +94,18 @@ void Cvar_AddListener (cvar_t *cvar, cvar_listener_t listener, void *data); void Cvar_RemoveListener (cvar_t *cvar, cvar_listener_t listener, void *data); // equivelants to " " typed at the console -void Cvar_Set (cvar_t *var, const char *value); -void Cvar_SetValue (cvar_t *var, float value); +void Cvar_Set (const char *var, const char *value); +void Cvar_SetVar (cvar_t *var, const char *value); // allows you to change a Cvar's flags without a full Cvar_Get void Cvar_SetFlags (cvar_t *var, int cvarflags); // returns 0 if not defined or non numeric -float Cvar_VariableValue (const char *var_name); +float Cvar_Value (const char *var_name); // returns an empty string if not defined -const char *Cvar_VariableString (const char *var_name); +const char *Cvar_String (const char *var_name); +const char *Cvar_VarString (const cvar_t *var); // called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known // command. Returns true if the command was a variable reference that diff --git a/include/QF/input.h b/include/QF/input.h index 119ad170b..2b85ee3c4 100644 --- a/include/QF/input.h +++ b/include/QF/input.h @@ -122,16 +122,16 @@ int IN_GetButtonInfo (int devid, int button_num, in_buttoninfo_t *info); void IN_ProcessEvents (void); -void IN_UpdateGrab (struct cvar_s *); +void IN_UpdateGrab (int grab); void IN_ClearStates (void); -extern struct cvar_s *in_grab; -extern struct cvar_s *in_amp; -extern struct cvar_s *in_pre_amp; -extern struct cvar_s *in_mouse_accel; -extern struct cvar_s *in_freelook; -extern struct cvar_s *lookstrafe; +extern int in_grab; +extern float in_amp; +extern float in_pre_amp; +extern int in_mouse_accel; +extern int in_freelook; +extern char *lookstrafe; #endif diff --git a/include/QF/joystick.h b/include/QF/joystick.h index 4b8163f7e..2e23d39f7 100644 --- a/include/QF/joystick.h +++ b/include/QF/joystick.h @@ -34,8 +34,8 @@ #define JOY_MAX_AXES 32 #define JOY_MAX_BUTTONS 64 -extern struct cvar_s *joy_device; // Joystick device name -extern struct cvar_s *joy_enable; // Joystick enabling flag +extern char *joy_device; +extern int joy_enable; struct joy_axis_button { float threshold; @@ -92,7 +92,7 @@ extern struct joy_button joy_buttons[JOY_MAX_BUTTONS]; frame. You should exit this function immediately if either joy_active or - joy_enable->int_val are zero. + joy_enable are zero. */ void JOY_Command (void); void joy_clear_axis (int i); @@ -103,7 +103,7 @@ void joy_clear_axis (int i); Use this function to process joystick movements to move the player around. You should exit this function immediately if either joy_active or - joy_enable->int_val are zero. + joy_enable are zero. */ void JOY_Move (void); diff --git a/include/QF/model.h b/include/QF/model.h index 875aeec3b..66628d37c 100644 --- a/include/QF/model.h +++ b/include/QF/model.h @@ -449,10 +449,11 @@ void Mod_LeafPVS_mix (const mleaf_t *leaf, const model_t *model, byte defvis, void Mod_Print (void); -extern struct cvar_s *gl_mesh_cache; -extern struct cvar_s *gl_subdivide_size; -extern struct cvar_s *gl_alias_render_tri; -extern struct cvar_s *gl_textures_external; +extern int gl_mesh_cache; +extern float gl_subdivide_size; +extern int gl_alias_render_tri; +extern int gl_textures_external; +extern int mod_sky_divide; extern int mod_lightmap_bytes; #endif//__QF_model_h diff --git a/include/QF/plugin.h b/include/QF/plugin.h index 96de3124e..cb73f6b7f 100644 --- a/include/QF/plugin.h +++ b/include/QF/plugin.h @@ -98,7 +98,7 @@ typedef struct plugin_list_s { /* Plugin system variables */ -extern struct cvar_s *fs_pluginpath; +extern char *fs_pluginpath; /* Function prototypes diff --git a/include/QF/plugin/vid_render.h b/include/QF/plugin/vid_render.h index 19ed1e394..6f775de78 100644 --- a/include/QF/plugin/vid_render.h +++ b/include/QF/plugin/vid_render.h @@ -138,9 +138,9 @@ typedef struct vid_render_data_s { int scr_copytop; int scr_copyeverything; int scr_fullupdate; // set to 0 to force full redraw - void (*viewsize_callback) (struct cvar_s *); - struct cvar_s *scr_viewsize; - struct cvar_s *graphheight; + void (*viewsize_callback) (int view_size); + int *scr_viewsize; + int *graphheight; float min_wateralpha; qboolean force_fullscreen; qboolean inhibit_viewmodel; diff --git a/include/QF/progs.h b/include/QF/progs.h index cd1008f91..b90c96e99 100644 --- a/include/QF/progs.h +++ b/include/QF/progs.h @@ -1829,11 +1829,12 @@ void PR_DumpState (progs_t *pr); void PR_StackTrace (progs_t *pr); void PR_Profile (progs_t *pr); -extern struct cvar_s *pr_debug; -extern struct cvar_s *pr_deadbeef_ents; -extern struct cvar_s *pr_deadbeef_locals; -extern struct cvar_s *pr_boundscheck; -extern struct cvar_s *pr_faultchecks; +extern int pr_debug; +extern char *pr_source_path; +extern int pr_deadbeef_ents; +extern int pr_deadbeef_locals; +extern int pr_boundscheck; +extern int pr_faultchecks; ///@} diff --git a/include/QF/qargs.h b/include/QF/qargs.h index 947bea592..689b5b5a1 100644 --- a/include/QF/qargs.h +++ b/include/QF/qargs.h @@ -39,8 +39,8 @@ extern int com_argc; extern const char **com_argv; extern const char *com_cmdline; -extern struct cvar_s *fs_globalcfg; -extern struct cvar_s *fs_usercfg; +extern char *fs_globalcfg; +extern char *fs_usercfg; int COM_CheckParm (const char *parm) __attribute__((pure)); void COM_AddParm (const char *parm); diff --git a/include/QF/render.h b/include/QF/render.h index d989bd38b..01994d095 100644 --- a/include/QF/render.h +++ b/include/QF/render.h @@ -181,7 +181,6 @@ struct progs_s; void R_Progs_Init (struct progs_s *pr); dlight_t *R_AllocDlight (int key); -void R_MaxDlightsCheck (struct cvar_s *var); void R_DecayLights (double frametime); void Fog_Update (float density, float red, float green, float blue, float time); diff --git a/include/QF/screen.h b/include/QF/screen.h index 10e0176e1..362cae41b 100644 --- a/include/QF/screen.h +++ b/include/QF/screen.h @@ -47,7 +47,10 @@ void SCR_SetFOV (float fov); void SCR_SetFullscreen (qboolean fullscreen); void SCR_SetBottomMargin (int lines); -extern struct cvar_s *hud_fps, *hud_time, *r_timegraph, *r_zgraph; +extern int hud_fps; +extern int hud_time; +extern int r_timegraph; +extern int r_zgraph; extern int scr_copytop; extern qboolean scr_skipupdate; diff --git a/include/QF/sys.h b/include/QF/sys.h index 3b6d5aed3..dde61872b 100644 --- a/include/QF/sys.h +++ b/include/QF/sys.h @@ -40,12 +40,12 @@ struct dstring_s; -extern struct cvar_s *sys_nostdout; -extern struct cvar_s *sys_extrasleep; -extern struct cvar_s *sys_dead_sleep; -extern struct cvar_s *sys_sleep; +extern int sys_nostdout; +extern int sys_extrasleep; +extern int sys_dead_sleep; +extern int sys_sleep; -extern struct cvar_s *developer; +extern int developer; extern const char sys_char_map[256]; diff --git a/include/QF/teamplay.h b/include/QF/teamplay.h index 91b2a6f65..0f03ff5e9 100644 --- a/include/QF/teamplay.h +++ b/include/QF/teamplay.h @@ -28,9 +28,9 @@ #ifndef __QF_teamplay_h #define __QF_teamplay_h -extern struct cvar_s *cl_parsesay; -extern struct cvar_s *cl_nofake; -extern struct cvar_s *cl_freply; +extern int cl_parsesay; +extern int cl_nofake; +extern float cl_freply; typedef const char *(*ffunc_t) (char *args); typedef struct freply_s { diff --git a/include/client/chase.h b/include/client/chase.h index a1415408b..91e12cd5a 100644 --- a/include/client/chase.h +++ b/include/client/chase.h @@ -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); diff --git a/include/client/hud.h b/include/client/hud.h index 31b4d5542..82fa94365 100644 --- a/include/client/hud.h +++ b/include/client/hud.h @@ -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 diff --git a/include/client/input.h b/include/client/input.h index e66d02140..3cf9cee24 100644 --- a/include/client/input.h +++ b/include/client/input.h @@ -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; diff --git a/include/context_win.h b/include/context_win.h index 536a01564..4921ce24f 100644 --- a/include/context_win.h +++ b/include/context_win.h @@ -40,7 +40,7 @@ extern int win_canalttab; extern DEVMODE win_gdevmode; extern struct sw_ctx_s *win_sw_context; extern int win_minimized; -extern struct cvar_s *vid_ddraw; +extern int vid_ddraw; extern int win_center_x, win_center_y; extern RECT win_rect; diff --git a/include/context_x11.h b/include/context_x11.h index ebb4b6d3b..48e350826 100644 --- a/include/context_x11.h +++ b/include/context_x11.h @@ -67,6 +67,7 @@ void X11_CloseDisplay (void); void X11_CreateNullCursor (void); void X11_CreateWindow (int, int); void X11_ForceViewPort (void); +void X11_UpdateFullscreen (int fullscreen); void X11_Init_Cvars (void); void X11_OpenDisplay (void); void X11_ProcessEvent (void); diff --git a/include/d_iface.h b/include/d_iface.h index 32e7e307a..1a0479d44 100644 --- a/include/d_iface.h +++ b/include/d_iface.h @@ -112,8 +112,8 @@ typedef struct int color; } zpointdesc_t; -extern struct cvar_s *r_drawflat; -extern int r_framecount; // sequence # of current frame since Quake +extern int r_drawflat; +extern int r_framecount; // sequence # of current frame since Quake // started extern qboolean r_drawpolys; // 1 if driver wants clipped polygons // rather than a span list diff --git a/include/netchan.h b/include/netchan.h index 5fe10eb81..94b56f954 100644 --- a/include/netchan.h +++ b/include/netchan.h @@ -62,7 +62,7 @@ extern netadr_t net_loopback_adr; extern netadr_t net_from; // address of who sent the packet extern struct msg_s *net_message; -extern struct cvar_s *qport; +extern int qport; int Net_Log_Init (const char **sound_precache, int server); void Net_LogPrintf (const char *fmt, ...) __attribute__ ((format (PRINTF, 1, 2))); @@ -72,7 +72,7 @@ void Net_LogStop (void *data); void Analyze_Client_Packet (const byte * data, int len, int has_sequence); void Analyze_Server_Packet (const byte * data, int len, int has_sequence); -extern struct cvar_s *net_packetlog; +extern int net_packetlog; ///@} /** \defgroup qw-udp QuakeWorld udp support. diff --git a/include/netmain.h b/include/netmain.h index 882b7acc9..dbf319914 100644 --- a/include/netmain.h +++ b/include/netmain.h @@ -385,7 +385,7 @@ extern qboolean slistInProgress; extern qboolean slistSilent; extern qboolean slistLocal; -extern struct cvar_s *hostname; +extern char *hostname; extern QFile *vcrFile; diff --git a/include/qw/pmove.h b/include/qw/pmove.h index b8c436e56..20e68bb05 100644 --- a/include/qw/pmove.h +++ b/include/qw/pmove.h @@ -88,7 +88,7 @@ typedef struct { float entgravity; } movevars_t; -extern struct cvar_s *no_pogo_stick; +extern int no_pogo_stick; extern movevars_t movevars; extern playermove_t pmove; extern int onground; diff --git a/include/r_cvar.h b/include/r_cvar.h index 756c2ef03..3aac1e6db 100644 --- a/include/r_cvar.h +++ b/include/r_cvar.h @@ -1,93 +1,92 @@ #include "QF/mathlib.h" -extern void gl_overbright_f (struct cvar_s *cvar); +extern void gl_overbright_f (void *data, const struct cvar_s *cvar); -extern struct cvar_s *cl_crossx; -extern struct cvar_s *cl_crossy; -extern struct cvar_s *cl_verstring; -extern struct cvar_s *crosshair; -extern struct cvar_s *crosshaircolor; +extern int cl_crossx; +extern int cl_crossy; +extern char *cl_verstring; +extern int crosshair; +extern int crosshaircolor; extern quat_t crosshair_color; -extern struct cvar_s *d_mipcap; -extern struct cvar_s *d_mipscale; +extern float d_mipcap; +extern float d_mipscale; -extern struct cvar_s *gl_affinemodels; -extern struct cvar_s *gl_anisotropy; -extern struct cvar_s *gl_clear; -extern struct cvar_s *gl_conspin; -extern struct cvar_s *gl_constretch; -extern struct cvar_s *gl_dlight_polyblend; -extern struct cvar_s *gl_dlight_smooth; -extern struct cvar_s *gl_fb_bmodels; -extern struct cvar_s *gl_fb_models; -extern struct cvar_s *gl_finish; -extern struct cvar_s *gl_keeptjunctions; -extern struct cvar_s *gl_lerp_anim; -extern struct cvar_s *gl_lightmap_align; -extern struct cvar_s *gl_lightmap_subimage; -extern struct cvar_s *gl_max_size; -extern struct cvar_s *gl_multitexture; -extern struct cvar_s *gl_nocolors; -extern struct cvar_s *gl_overbright; -extern struct cvar_s *gl_particle_mip; -extern struct cvar_s *gl_particle_size; -extern struct cvar_s *gl_picmip; -extern struct cvar_s *gl_playermip; -extern struct cvar_s *gl_reporttjunctions; -extern struct cvar_s *gl_sky_clip; -extern struct cvar_s *gl_sky_debug; -extern struct cvar_s *gl_sky_divide; -extern struct cvar_s *gl_sky_multipass; -extern struct cvar_s *gl_tessellate; -extern struct cvar_s *gl_texsort; -extern struct cvar_s *gl_textures_bgra; -extern struct cvar_s *gl_triplebuffer; -extern struct cvar_s *gl_vector_light; +extern int gl_affinemodels; +extern float gl_anisotropy; +extern int gl_clear; +extern float gl_conspin; +extern int gl_constretch; +extern int gl_dlight_polyblend; +extern int gl_dlight_smooth; +extern int gl_fb_bmodels; +extern int gl_fb_models; +extern int gl_finish; +extern int gl_keeptjunctions; +extern int gl_lerp_anim; +extern int gl_lightmap_align; +extern int gl_lightmap_subimage; +extern int gl_max_size; +extern int gl_multitexture; +extern int gl_nocolors; +extern int gl_overbright; +extern int gl_particle_mip; +extern int gl_particle_size; +extern int gl_picmip; +extern int gl_playermip; +extern int gl_reporttjunctions; +extern int gl_sky_clip; +extern int gl_sky_debug; +extern int gl_sky_multipass; +extern int gl_tessellate; +extern int gl_texsort; +extern int gl_textures_bgra; +extern int gl_triplebuffer; +extern int gl_vector_light; -extern struct cvar_s *r_aliasstats; -extern struct cvar_s *r_aliastransadj; -extern struct cvar_s *r_aliastransbase; -extern struct cvar_s *r_clearcolor; -extern struct cvar_s *r_dlight_lightmap; -extern struct cvar_s *r_drawentities; -extern struct cvar_s *r_drawexplosions; -extern struct cvar_s *r_drawviewmodel; -extern struct cvar_s *r_dspeeds; -extern struct cvar_s *r_dynamic; -extern struct cvar_s *r_explosionclip; -extern struct cvar_s *r_farclip; -extern struct cvar_s *r_firecolor; -extern struct cvar_s *r_flatlightstyles; -extern struct cvar_s *r_graphheight; -extern struct cvar_s *r_lightmap_components; -extern struct cvar_s *r_maxedges; -extern struct cvar_s *r_maxsurfs; -extern struct cvar_s *r_mirroralpha; -extern struct cvar_s *r_nearclip; -extern struct cvar_s *r_norefresh; -extern struct cvar_s *r_novis; -extern struct cvar_s *r_numedges; -extern struct cvar_s *r_numsurfs; -extern struct cvar_s *r_particles; -extern struct cvar_s *r_particles_max; -extern struct cvar_s *r_particles_nearclip; -extern struct cvar_s *r_reportedgeout; -extern struct cvar_s *r_reportsurfout; -extern struct cvar_s *r_shadows; -extern struct cvar_s *r_skyname; -extern struct cvar_s *r_speeds; -extern struct cvar_s *r_timegraph; -extern struct cvar_s *r_wateralpha; -extern struct cvar_s *r_waterripple; -extern struct cvar_s *r_waterwarp; -extern struct cvar_s *r_zgraph; +extern int r_aliasstats; +extern float r_aliastransadj; +extern float r_aliastransbase; +extern int r_clearcolor; +extern int r_dlight_lightmap; +extern int r_drawentities; +extern int r_drawexplosions; +extern int r_drawviewmodel; +extern int r_dspeeds; +extern int r_dynamic; +extern int r_explosionclip; +extern float r_farclip; +extern vec4f_t r_firecolor; +extern int r_flatlightstyles; +extern int r_graphheight; +extern int r_lightmap_components; +extern int r_maxedges; +extern int r_maxsurfs; +extern float r_mirroralpha; +extern float r_nearclip; +extern int r_norefresh; +extern int r_novis; +extern int r_numedges; +extern int r_numsurfs; +extern int r_particles; +extern int r_particles_max; +extern float r_particles_nearclip; +extern int r_reportedgeout; +extern int r_reportsurfout; +extern int r_shadows; +extern char *r_skyname; +extern int r_speeds; +extern int r_timegraph; +extern float r_wateralpha; +extern float r_waterripple; +extern int r_waterwarp; +extern int r_zgraph; -extern struct cvar_s *scr_fov; -extern struct cvar_s *scr_fisheye; -extern struct cvar_s *scr_fviews; -extern struct cvar_s *scr_ffov; -extern struct cvar_s *scr_showpause; -extern struct cvar_s *scr_showram; -extern struct cvar_s *scr_showturtle; -extern struct cvar_s *scr_viewsize; +extern float scr_fov; +extern int scr_fisheye; +extern int scr_fviews; +extern float scr_ffov; +extern int scr_showpause; +extern int scr_showram; +extern int scr_showturtle; +extern int scr_viewsize; diff --git a/include/r_dynamic.h b/include/r_dynamic.h index 3239a9297..9c2a23525 100644 --- a/include/r_dynamic.h +++ b/include/r_dynamic.h @@ -46,16 +46,12 @@ typedef enum { struct entity_s; void R_PushDlights (const vec3_t entorigin); -struct cvar_s; -void R_MaxDlightsCheck (struct cvar_s *var); +void R_MaxDlightsCheck (int max_dlights); void R_Particles_Init_Cvars (void); void R_InitBubble (void); void R_InitParticles (void); void R_ClearParticles (void); -struct cvar_s; -void R_MaxParticlesCheck (struct cvar_s *r_particles, - struct cvar_s *r_particles_max); void R_InitSprites (void); #endif // _R_DYNAMIC_H diff --git a/include/r_local.h b/include/r_local.h index ef0db6963..486347f0d 100644 --- a/include/r_local.h +++ b/include/r_local.h @@ -66,22 +66,22 @@ typedef struct { //=========================================================================== -extern struct cvar_s *r_speeds; -extern struct cvar_s *r_timegraph; -extern struct cvar_s *r_graphheight; -extern struct cvar_s *r_clearcolor; -extern struct cvar_s *r_waterwarp; -extern struct cvar_s *r_drawentities; -extern struct cvar_s *r_aliasstats; -extern struct cvar_s *r_dspeeds; -extern struct cvar_s *r_drawflat; -extern struct cvar_s *r_ambient; -extern struct cvar_s *r_reportsurfout; -extern struct cvar_s *r_maxsurfs; -extern struct cvar_s *r_numsurfs; -extern struct cvar_s *r_reportedgeout; -extern struct cvar_s *r_maxedges; -extern struct cvar_s *r_numedges; +extern int r_speeds; +extern int r_timegraph; +extern int r_graphheight; +extern int r_clearcolor; +extern int r_waterwarp; +extern int r_drawentities; +extern int r_aliasstats; +extern int r_dspeeds; +extern int r_drawflat; +extern int r_ambient; +extern int r_reportsurfout; +extern int r_maxsurfs; +extern int r_numsurfs; +extern int r_reportedgeout; +extern int r_maxedges; +extern int r_numedges; extern float cl_wateralpha; diff --git a/include/r_shared.h b/include/r_shared.h index 2251a7b1d..16bb3bbb2 100644 --- a/include/r_shared.h +++ b/include/r_shared.h @@ -60,7 +60,7 @@ extern float pixelAspect; extern int r_drawnpolycount; -extern struct cvar_s *r_clearcolor; +extern int r_clearcolor; extern int sintable[SIN_BUFFER_SIZE]; extern int intsintable[SIN_BUFFER_SIZE]; diff --git a/include/sbar.h b/include/sbar.h index 7fa9fbdd3..a8d964010 100644 --- a/include/sbar.h +++ b/include/sbar.h @@ -38,7 +38,7 @@ extern int sb_lines; // scan lines to draw void Sbar_Init (void); struct cvar_s; -void Sbar_DMO_Init_f (struct cvar_s *var); +void Sbar_DMO_Init_f (void *data, const struct cvar_s *var); void Sbar_Changed (void); // call whenever any of the client stats represented on the sbar changes diff --git a/include/snd_internal.h b/include/snd_internal.h index 078d32cbb..63dd6a62d 100644 --- a/include/snd_internal.h +++ b/include/snd_internal.h @@ -229,7 +229,7 @@ struct channel_s { //@} }; -extern struct cvar_s *snd_volume; +extern float snd_volume; extern snd_render_data_t snd_render_data; #define PAINTBUFFER_SIZE 512 diff --git a/include/vid_internal.h b/include/vid_internal.h index 9df75a395..f413d4d66 100644 --- a/include/vid_internal.h +++ b/include/vid_internal.h @@ -4,6 +4,14 @@ #include "QF/vid.h" #include "QF/plugin/vid_render.h" +typedef struct vid_system_s { + void (*init) (byte *palette, byte *colormap); + void (*init_cvars) (void); + void (*update_fullscreen) (int fullscreen); +} vid_system_t; + +extern vid_system_t vid_system; + typedef struct vid_internal_s { void (*flush_caches) (void *data); void (*init_buffers) (void *data); @@ -20,15 +28,15 @@ typedef struct vid_internal_s { struct vulkan_ctx_s *(*vulkan_context) (void); } vid_internal_t; -extern struct cvar_s *vid_fullscreen; -extern struct cvar_s *vid_system_gamma; -extern struct cvar_s *vid_gamma; +extern int vid_fullscreen; +extern int vid_system_gamma; +extern float vid_gamma; void VID_GetWindowSize (int def_w, int def_h); void VID_InitGamma (const byte *); qboolean VID_SetGamma (double); -void VID_UpdateGamma (struct cvar_s *); +void VID_UpdateGamma (void); void VID_MakeColormaps (void); diff --git a/include/vid_vulkan.h b/include/vid_vulkan.h index def07b666..9cfe51ca7 100644 --- a/include/vid_vulkan.h +++ b/include/vid_vulkan.h @@ -108,13 +108,13 @@ typedef struct vulkan_ctx_s { #define qfvPushDebug(ctx, x) \ do { \ - if (developer->int_val & SYS_vulkan) { \ + if (developer & SYS_vulkan) { \ DARRAY_APPEND(&(ctx)->instance->debug_stack, (x)); \ } \ } while (0) #define qfvPopDebug(ctx) \ do { \ - if (developer->int_val & SYS_vulkan) { \ + if (developer & SYS_vulkan) { \ __auto_type ds = &(ctx)->instance->debug_stack; \ DARRAY_REMOVE_AT(ds, ds->size - 1); \ } \ diff --git a/libs/audio/cd.c b/libs/audio/cd.c index 0faee5a13..4ac01e361 100644 --- a/libs/audio/cd.c +++ b/libs/audio/cd.c @@ -40,7 +40,15 @@ #include "QF/plugin/general.h" #include "QF/plugin/cd.h" -cvar_t *cd_plugin; +char *cd_plugin; +static cvar_t cd_plugin_cvar = { + .name = "cd_plugin", + .description = + "CD Plugin to use", + .default_value = CD_DEFAULT, + .flags = CVAR_ROM, + .value = { .type = 0, .value = &cd_plugin }, +}; plugin_t *cdmodule = NULL; CD_PLUGIN_PROTOS @@ -96,19 +104,18 @@ CDAudio_Init (void) Sys_RegisterShutdown (CDAudio_shutdown, 0); PI_RegisterPlugins (cd_plugin_list); - cd_plugin = Cvar_Get ("cd_plugin", CD_DEFAULT, CVAR_ROM, NULL, - "CD Plugin to use"); + Cvar_Register (&cd_plugin_cvar, 0, 0); if (COM_CheckParm ("-nocdaudio")) return 0; - if (!*cd_plugin->string) { + if (!*cd_plugin) { Sys_Printf ("Not loading CD due to no driver\n"); return 0; } - cdmodule = PI_LoadPlugin ("cd", cd_plugin->string); + cdmodule = PI_LoadPlugin ("cd", cd_plugin); if (!cdmodule) { - Sys_Printf ("Loading of cd module: %s failed!\n", cd_plugin->string); + Sys_Printf ("Loading of cd module: %s failed!\n", cd_plugin); return -1; } Cmd_AddCommand ( diff --git a/libs/audio/cd_file.c b/libs/audio/cd_file.c index 126dabd1e..401c6b59a 100644 --- a/libs/audio/cd_file.c +++ b/libs/audio/cd_file.c @@ -84,15 +84,31 @@ static plitem_t *play_list; // string or array of strings static int play_pos = -1; // position in play_list (0 for string) // -1 = invalid (both) -static cvar_t *bgmvolume; // volume cvar -static cvar_t *mus_ogglist; // tracklist cvar +static float bgmvolume; +static cvar_t bgmvolume_cvar = { + .name = "bgmvolume", + .description = + "Volume of CD music", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &bgmvolume }, +}; +static char *mus_ogglist; +static cvar_t mus_ogglist_cvar = { + .name = "mus_ogglist", + .description = + "filename of track to music file map", + .default_value = "tracklist.cfg", + .flags = CVAR_NONE, + .value = { .type = 0, .value = &mus_ogglist }, +}; static void set_volume (void) { if (cd_channel && cd_channel->sfx) { - int vol = bgmvolume->value * 255; + int vol = bgmvolume * 255; cd_channel->master_vol = vol; cd_channel->leftvol = cd_channel->rightvol = cd_channel->master_vol; @@ -151,14 +167,14 @@ Load_Tracklist (void) ogglistvalid = false; mus_enabled = false; - if (!mus_ogglist || strequal (mus_ogglist->string, "none")) { + if (!mus_ogglist || strequal (mus_ogglist, "none")) { return -1; // bail if we don't have a valid filename } - oggfile = QFS_FOpenFile (mus_ogglist->string); + oggfile = QFS_FOpenFile (mus_ogglist); if (!oggfile) { Sys_Printf ("Mus_OggInit: open of file \"%s\" failed\n", - mus_ogglist->string); + mus_ogglist); return -1; } @@ -324,7 +340,7 @@ I_OGGMus_Info (void) return; Sys_Printf ("\n" "Tracklist loaded from file:\n%s\n" - "---------------------------\n", mus_ogglist->string); + "---------------------------\n", mus_ogglist); /* loop, and count up the Highest key number. */ for (iter = 1, count = 0; count < keycount && iter <= 99 ; iter++) { @@ -439,15 +455,14 @@ I_OGGMus_Update (void) /* called when the mus_ogglist cvar is changed */ static void -Mus_OggChange (cvar_t *ogglist) +Mus_OggChange (void *data, const cvar_t *cvar) { - mus_ogglist = ogglist; Load_Tracklist (); } /* change volume on sound object */ static void -Mus_VolChange (cvar_t *bgmvolume) +Mus_VolChange (void *data, const cvar_t *bgmvolume) { set_volume (); } @@ -456,18 +471,15 @@ static void Mus_gamedir (int phase) { if (phase) - Mus_OggChange (mus_ogglist); + Load_Tracklist (); } static void I_OGGMus_Init (void) { /* check list file cvar, open list file, create map, close file. */ - mus_ogglist = Cvar_Get ("mus_ogglist", "tracklist.cfg", CVAR_NONE, - Mus_OggChange, - "filename of track to music file map"); - bgmvolume = Cvar_Get ("bgmvolume", "1.0", CVAR_ARCHIVE, Mus_VolChange, - "Volume of CD music"); + Cvar_Register (&mus_ogglist_cvar, Mus_OggChange, 0); + Cvar_Register (&bgmvolume_cvar, Mus_VolChange, 0); QFS_GamedirCallback (Mus_gamedir); } diff --git a/libs/audio/cd_linux.c b/libs/audio/cd_linux.c index 53bc7f450..15452ce8c 100644 --- a/libs/audio/cd_linux.c +++ b/libs/audio/cd_linux.c @@ -77,8 +77,24 @@ static byte playTrack; static byte maxTrack; static int cdfile = -1; -static cvar_t *mus_cddevice; -static cvar_t *bgmvolume; +static char *mus_cddevice; +static cvar_t mus_cddevice_cvar = { + .name = "mus_cddevice", + .description = + "device to use for CD music", + .default_value = "/dev/cdrom", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &mus_cddevice }, +}; +static float bgmvolume; +static cvar_t bgmvolume_cvar = { + .name = "bgmvolume", + .description = + "Volume of CD music", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &bgmvolume }, +}; static void @@ -382,14 +398,14 @@ I_CDAudio_Update (void) if (!mus_enabled) return; - if (bgmvolume->value != cdvolume) { + if (bgmvolume != cdvolume) { if (cdvolume) { - Cvar_SetValue (bgmvolume, 0.0); - cdvolume = bgmvolume->value; + bgmvolume = 0.0; + cdvolume = bgmvolume; I_CDAudio_Pause (); } else { - Cvar_SetValue (bgmvolume, 1.0); - cdvolume = bgmvolume->value; + bgmvolume = 1.0; + cdvolume = bgmvolume; I_CDAudio_Resume (); } } @@ -412,20 +428,20 @@ I_CDAudio_Update (void) } static void -Mus_CDChange (cvar_t *mus_cdaudio) +Mus_CDChange (void *data, const cvar_t *cvar) { int i; I_CDAudio_Shutdown (); - if (strequal (mus_cdaudio->string, "none")) { + if (strequal (mus_cddevice, "none")) { return; } - cdfile = open (mus_cdaudio->string, O_RDONLY | O_NONBLOCK); + cdfile = open (mus_cddevice, O_RDONLY | O_NONBLOCK); if (cdfile == -1) { Sys_MaskPrintf (SYS_snd, "Mus_CDInit: open device \"%s\" failed (error %i)\n", - mus_cdaudio->string, errno); + mus_cddevice, errno); return; } @@ -443,10 +459,8 @@ Mus_CDChange (cvar_t *mus_cdaudio) static void I_CDAudio_Init (void) { - mus_cddevice = Cvar_Get ("mus_cddevice", "/dev/cdrom", CVAR_NONE, - Mus_CDChange, "device to use for CD music"); - bgmvolume = Cvar_Get ("bgmvolume", "1", CVAR_ARCHIVE, NULL, - "Volume of CD music"); + Cvar_Register (&mus_cddevice_cvar, Mus_CDChange, 0); + Cvar_Register (&bgmvolume_cvar, 0, 0); } static general_funcs_t plugin_info_general_funcs = { diff --git a/libs/audio/cd_sdl.c b/libs/audio/cd_sdl.c index fb3b9b502..2e90c342a 100644 --- a/libs/audio/cd_sdl.c +++ b/libs/audio/cd_sdl.c @@ -64,7 +64,15 @@ static qboolean playLooping = false; static SDL_CD *cd_id; static float cdvolume = 1.0; -static cvar_t *bgmvolume; +static float bgmvolume; +static cvar_t bgmvolume_cvar = { + .name = "bgmvolume", + .description = + "Volume of CD music", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &bgmvolume }, +}; static void @@ -168,15 +176,15 @@ I_CDAudio_Update (void) { if (!cd_id || !enabled) return; - if (bgmvolume->value != cdvolume) { + if (bgmvolume != cdvolume) { if (cdvolume) { - Cvar_SetValue (bgmvolume, 0.0); + bgmvolume = 0.0; I_CDAudio_Pause (); } else { - Cvar_SetValue (bgmvolume, 1.0); + bgmvolume = 1.0; I_CDAudio_Resume (); } - cdvolume = bgmvolume->value; + cdvolume = bgmvolume; return; } if (playLooping && (SDL_CDStatus (cd_id) != CD_PLAYING) @@ -276,8 +284,7 @@ I_CDAudio_Init (void) cdValid = false; } - bgmvolume = Cvar_Get ("bgmvolume", "1", CVAR_ARCHIVE, NULL, - "Volume of CD music"); + Cvar_Register (&bgmvolume_cvar, 0, 0); Sys_Printf ("CD Audio Initialized.\n"); } diff --git a/libs/audio/cd_sgi.c b/libs/audio/cd_sgi.c index 2f235d86b..8e57bb9ed 100644 --- a/libs/audio/cd_sgi.c +++ b/libs/audio/cd_sgi.c @@ -63,7 +63,15 @@ static byte playTrack; static char cd_dev[] = "/dev/cdrom"; static CDPLAYER *cdp = NULL; -static cvar_t *bgmvolume; +static float bgmvolume; +static cvar_t bgmvolume_cvar = { + .name = "bgmvolume", + .description = + "Volume of CD music", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &bgmvolume }, +}; static void I_SGI_Eject (void) @@ -219,14 +227,14 @@ I_SGI_Update (void) if (!initialized || !enabled) return; - if (bgmvolume->value != cdvolume) { + if (bgmvolume != cdvolume) { if (cdvolume) { - Cvar_SetValue (bgmvolume, 0.0); - cdvolume = bgmvolume->value; + bgmvolume = 0.0; + cdvolume = bgmvolume; CDAudio_Pause (); } else { - Cvar_SetValue (bgmvolume, 1.0); - cdvolume = bgmvolume->value; + bgmvolume = 1.0; + cdvolume = bgmvolume; CDAudio_Resume (); } } @@ -334,8 +342,7 @@ I_SGI_Init (void) { int i; - bgmvolume = Cvar_Get ("bgmvolume", "1", CVAR_ARCHIVE, NULL, - "Volume of CD music"); + Cvar_Register (&bgmvolume_cvar, 0, 0); if ((i = COM_CheckParm ("-cddev")) != 0 && i < com_argc - 1) { strncpy (cd_dev, com_argv[i + 1], sizeof (cd_dev)); cd_dev[sizeof (cd_dev) - 1] = 0; diff --git a/libs/audio/cd_win.c b/libs/audio/cd_win.c index 919908a79..2d2aa59fe 100644 --- a/libs/audio/cd_win.c +++ b/libs/audio/cd_win.c @@ -64,7 +64,15 @@ static UINT wDeviceID; static void I_CDAudio_Play (int track, qboolean looping); static void I_CDAudio_Stop (void); -static cvar_t *bgmvolume; +static float bgmvolume; +static cvar_t bgmvolume_cvar = { + .name = "bgmvolume", + .description = + "Volume of CD music", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &bgmvolume }, +}; static void @@ -331,14 +339,14 @@ I_CDAudio_Update (void) if (!enabled) return; - if (bgmvolume->value != cdvolume) { + if (bgmvolume != cdvolume) { if (cdvolume) { - Cvar_SetValue (bgmvolume, 0.0); - cdvolume = bgmvolume->value; + bgmvolume = 0.0; + cdvolume = bgmvolume; I_CDAudio_Pause (); } else { - Cvar_SetValue (bgmvolume, 1.0); - cdvolume = bgmvolume->value; + bgmvolume = 1.0; + cdvolume = bgmvolume; I_CDAudio_Resume (); } } @@ -483,8 +491,7 @@ I_CDAudio_Init (void) initialized = true; enabled = true; - bgmvolume = Cvar_Get ("bgmvolume", "1", CVAR_ARCHIVE, NULL, - "Volume of CD music"); + Cvar_Register (&bgmvolume_cvar, 0, 0); if (I_CDAudio_GetAudioDiskInfo ()) { Sys_Printf ("CDAudio_Init: No CD in player.\n"); diff --git a/libs/audio/renderer/Makemodule.am b/libs/audio/renderer/Makemodule.am index a98c2214f..0e726fe36 100644 --- a/libs/audio/renderer/Makemodule.am +++ b/libs/audio/renderer/Makemodule.am @@ -2,39 +2,57 @@ plugin_LTLIBRARIES += @snd_render_plugins@ noinst_LTLIBRARIES += @snd_render_static_plugins@ EXTRA_LTLIBRARIES += libs/audio/renderer/snd_render_default.la -flac_src=libs/audio/renderer/flac.c -midi_src=libs/audio/renderer/midi.c -vorbis_src=libs/audio/renderer/vorbis.c -wav_src=libs/audio/renderer/wav.c +flac_src = libs/audio/renderer/flac.c +midi_src = libs/audio/renderer/midi.c +vorbis_src = libs/audio/renderer/vorbis.c +wav_src = libs/audio/renderer/wav.c if HAVE_FLAC -have_flac_src=$(flac_src) +have_flac_src = $(flac_src) else -have_flac_src= +have_flac_src = endif if HAVE_MIDI -have_midi_src=$(midi_src) +have_midi_src = $(midi_src) else -have_midi_src= +have_midi_src = endif if HAVE_VORBIS -have_vorbis_src=$(vorbis_src) +have_vorbis_src = $(vorbis_src) else -have_vorbis_src= +have_vorbis_src = endif -have_wav_src=$(wav_src) +have_wav_src = $(wav_src) format_src=$(have_flac_src) $(have_midi_src) $(have_vorbis_src) $(have_wav_src) format_libs= \ - $(SAMPLERATE_LIBS) $(VORBISFILE_LIBS) $(VORBIS_LIBS) $(FLAC_LIBS) \ - $(OGG_LIBS) $(WM_LIBS) -extra_format_src=libs/audio/renderer/flac.c libs/audio/renderer/midi.c libs/audio/renderer/vorbis.c libs/audio/renderer/wav.c -snd_common=libs/audio/renderer/snd_channels.c libs/audio/renderer/snd_mem.c libs/audio/renderer/snd_mix.c libs/audio/renderer/snd_resample.c libs/audio/renderer/snd_sfx.c -snd_libs= \ + $(SAMPLERATE_LIBS) \ + $(VORBISFILE_LIBS) \ + $(VORBIS_LIBS) \ + $(FLAC_LIBS) \ + $(OGG_LIBS) \ + $(WM_LIBS) +extra_format_src = \ + libs/audio/renderer/flac.c \ + libs/audio/renderer/midi.c \ + libs/audio/renderer/vorbis.c \ + libs/audio/renderer/wav.c +snd_common = \ + libs/audio/renderer/snd_channels.c \ + libs/audio/renderer/snd_mem.c \ + libs/audio/renderer/snd_mix.c \ + libs/audio/renderer/snd_resample.c \ + libs/audio/renderer/snd_sfx.c +snd_libs = \ libs/util/libQFutil.la -libs_audio_renderer_snd_render_default_la_LDFLAGS= $(plugin_ldflags) -libs_audio_renderer_snd_render_default_la_SOURCES= libs/audio/renderer/snd_dma.c $(snd_common) $(format_src) -libs_audio_renderer_snd_render_default_la_LIBADD= $(snd_libs) $(format_libs) -libs_audio_renderer_snd_render_default_la_DEPENDENCIES= $(snd_libs) -EXTRA_libs_audio_renderer_snd_render_default_la_SOURCES=$(extra_format_src) +libs_audio_renderer_snd_render_default_la_LDFLAGS = $(plugin_ldflags) +libs_audio_renderer_snd_render_default_la_SOURCES = \ + libs/audio/renderer/snd_dma.c \ + $(snd_common) \ + $(format_src) +libs_audio_renderer_snd_render_default_la_LIBADD = \ + $(snd_libs) \ + $(format_libs) +libs_audio_renderer_snd_render_default_la_DEPENDENCIES = $(snd_libs) +EXTRA_libs_audio_renderer_snd_render_default_la_SOURCES = $(extra_format_src) diff --git a/libs/audio/renderer/midi.c b/libs/audio/renderer/midi.c index 4a2b51ab2..f0dc91b58 100644 --- a/libs/audio/renderer/midi.c +++ b/libs/audio/renderer/midi.c @@ -57,19 +57,32 @@ typedef struct { static int midi_intiialized = 0; -static cvar_t *wildmidi_volume; -static cvar_t *wildmidi_config; +static char *wildmidi_volume; +static cvar_t wildmidi_volume_cvar = { + .name = "wildmidi_volume", + .description = + "Set the Master Volume", + .default_value = "100", + .flags = CVAR_ARCHIVE, + .value = { .type = 0/* not used */, .value = &wildmidi_volume }, +}; +static char *wildmidi_config; +static cvar_t wildmidi_config_cvar = { + .name = "wildmidi_config", + .description = + "path/filename of timidity.cfg", + .default_value = "/etc/timidity.cfg", + .flags = CVAR_ROM, + .value = { .type = 0, .value = &wildmidi_config }, +}; static int midi_init (snd_t *snd) { - wildmidi_volume = Cvar_Get ("wildmidi_volume", "100", CVAR_ARCHIVE, NULL, - "Set the Master Volume"); - wildmidi_config = Cvar_Get ("wildmidi_config", "/etc/timidity.cfg", - CVAR_ROM, NULL, - "path/filename of timidity.cfg"); + Cvar_Register (&wildmidi_volume_cvar, 0, 0); + Cvar_Register (&wildmidi_config_cvar, 0, 0); - if (WildMidi_Init (wildmidi_config->string, snd->speed, 0) == -1) + if (WildMidi_Init (wildmidi_config, snd->speed, 0) == -1) return 1; midi_intiialized = 1; return 0; diff --git a/libs/audio/renderer/snd_channels.c b/libs/audio/renderer/snd_channels.c index 492fb430b..66e9f19ab 100644 --- a/libs/audio/renderer/snd_channels.c +++ b/libs/audio/renderer/snd_channels.c @@ -71,11 +71,51 @@ static vec4f_t listener_forward; static vec4f_t listener_right; static vec4f_t listener_up; -static cvar_t *snd_phasesep; -static cvar_t *snd_volumesep; -static cvar_t *snd_swapchannelside; -static cvar_t *ambient_fade; -static cvar_t *ambient_level; +static float snd_phasesep; +static cvar_t snd_phasesep_cvar = { + .name = "snd_phasesep", + .description = + "max stereo phase separation in ms. 0.6 is for 20cm head", + .default_value = "0.0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &snd_phasesep }, +}; +static float snd_volumesep; +static cvar_t snd_volumesep_cvar = { + .name = "snd_volumesep", + .description = + "max stereo volume separation. 1.0 is max", + .default_value = "1.0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &snd_volumesep }, +}; +static int snd_swapchannelside; +static cvar_t snd_swapchannelside_cvar = { + .name = "snd_swapchannelside", + .description = + "Toggle swapping of left and right channels", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &snd_swapchannelside }, +}; +static float ambient_fade; +static cvar_t ambient_fade_cvar = { + .name = "ambient_fade", + .description = + "How quickly ambient sounds fade in or out", + .default_value = "100", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &ambient_fade }, +}; +static float ambient_level; +static cvar_t ambient_level_cvar = { + .name = "ambient_level", + .description = + "Ambient sounds' volume", + .default_value = "0.3", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &ambient_level }, +}; static inline channel_t * unlink_channel (channel_t **_ch) @@ -320,18 +360,11 @@ SND_Channels_Init (snd_t *snd) { int i; - snd_phasesep = Cvar_Get ("snd_phasesep", "0.0", CVAR_ARCHIVE, NULL, - "max stereo phase separation in ms. 0.6 is for " - "20cm head"); - snd_volumesep = Cvar_Get ("snd_volumesep", "1.0", CVAR_ARCHIVE, NULL, - "max stereo volume separation. 1.0 is max"); - snd_swapchannelside = Cvar_Get ("snd_swapchannelside", "0", CVAR_ARCHIVE, - NULL, "Toggle swapping of left and right " - "channels"); - ambient_fade = Cvar_Get ("ambient_fade", "100", CVAR_NONE, NULL, - "How quickly ambient sounds fade in or out"); - ambient_level = Cvar_Get ("ambient_level", "0.3", CVAR_NONE, NULL, - "Ambient sounds' volume"); + Cvar_Register (&snd_phasesep_cvar, 0, 0); + Cvar_Register (&snd_volumesep_cvar, 0, 0); + Cvar_Register (&snd_swapchannelside_cvar, 0, 0); + Cvar_Register (&ambient_fade_cvar, 0, 0); + Cvar_Register (&ambient_level_cvar, 0, 0); Cmd_AddDataCommand ("play", s_play_f, snd, "Play selected sound effect (play pathto/sound.wav)"); @@ -408,7 +441,7 @@ s_updateAmbientSounds (snd_t *snd, const byte *ambient_sound_level) if (!snd_ambient) return; // calc ambient sound levels - if (!ambient_sound_level || !ambient_level->value) { + if (!ambient_sound_level || !ambient_level) { // if we're not in a leaf (huh?) or ambients have been turned off, // stop all ambient channels. for (ambient_channel = 0; ambient_channel < NUM_AMBIENTS; @@ -447,19 +480,19 @@ s_updateAmbientSounds (snd_t *snd, const byte *ambient_sound_level) // sfx will be written to chan->sfx later to ensure mixer doesn't use // channel prematurely. - vol = ambient_level->value * ambient_sound_level[ambient_channel]; + vol = ambient_level * ambient_sound_level[ambient_channel]; if (vol < 8) vol = 0; // don't adjust volume too fast if (chan->master_vol < vol) { chan->master_vol += *snd_render_data.host_frametime - * ambient_fade->value; + * ambient_fade; if (chan->master_vol > vol) chan->master_vol = vol; } else if (chan->master_vol > vol) { chan->master_vol -= *snd_render_data.host_frametime - * ambient_fade->value; + * ambient_fade; if (chan->master_vol < vol) chan->master_vol = vol; } @@ -494,7 +527,7 @@ s_spatialize (snd_t *snd, channel_t *ch) dist = VectorNormalize (source_vec) * ch->dist_mult; dot = DotProduct (listener_right, source_vec); - if (snd_swapchannelside->int_val) + if (snd_swapchannelside) dot = -dot; if (snd->channels == 1) { @@ -502,9 +535,9 @@ s_spatialize (snd_t *snd, channel_t *ch) lscale = 1.0; phase = 0; } else { - rscale = 1.0 + dot * snd_volumesep->value; - lscale = 1.0 - dot * snd_volumesep->value; - phase = snd_phasesep->value * 0.001 * snd->speed * dot; + rscale = 1.0 + dot * snd_volumesep; + lscale = 1.0 - dot * snd_volumesep; + phase = snd_phasesep * 0.001 * snd->speed * dot; } // add in distance effect diff --git a/libs/audio/renderer/snd_dma.c b/libs/audio/renderer/snd_dma.c index 010793cae..c8ab69577 100644 --- a/libs/audio/renderer/snd_dma.c +++ b/libs/audio/renderer/snd_dma.c @@ -60,10 +60,52 @@ static unsigned soundtime; // sample PAIRS static int sound_started = 0; -static cvar_t *nosound; -static cvar_t *snd_mixahead; -static cvar_t *snd_noextraupdate; -static cvar_t *snd_show; +float snd_volume; +static cvar_t snd_volume_cvar = { + .name = "volume", + .description = + "Set the volume for sound playback", + .default_value = "0.7", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &snd_volume }, +}; +static char *nosound; +static cvar_t nosound_cvar = { + .name = "nosound", + .description = + "Set to turn sound off", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &nosound }, +}; +static float snd_mixahead; +static cvar_t snd_mixahead_cvar = { + .name = "snd_mixahead", + .description = + "Delay time for sounds", + .default_value = "0.1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &snd_mixahead }, +}; +static int snd_noextraupdate; +static cvar_t snd_noextraupdate_cvar = { + .name = "snd_noextraupdate", + .description = + "Toggles the correct value display in host_speeds. Usually messes up " + "sound playback when in effect", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &snd_noextraupdate }, +}; +static char *snd_show; +static cvar_t snd_show_cvar = { + .name = "snd_show", + .description = + "Toggles display of sounds currently being played", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &snd_show }, +}; static general_data_t plugin_info_general_data; @@ -196,7 +238,7 @@ s_update_ (void) snd.paintedtime = soundtime; } // mix ahead of current position - endtime = soundtime + snd_mixahead->value * snd.speed; + endtime = soundtime + snd_mixahead * snd.speed; samps = snd.frames; if (endtime - soundtime > samps) endtime = soundtime + samps; @@ -233,7 +275,7 @@ static void s_extra_update (void) { if (snd_output_data->model == som_push) { - if (!sound_started || snd_noextraupdate->int_val) + if (!sound_started || snd_noextraupdate) return; // don't pollute timings s_update_ (); } @@ -315,18 +357,11 @@ s_snd_force_unblock (void) static void s_init_cvars (void) { - nosound = Cvar_Get ("nosound", "0", CVAR_NONE, NULL, - "Set to turn sound off"); - snd_volume = Cvar_Get ("volume", "0.7", CVAR_ARCHIVE, NULL, - "Set the volume for sound playback"); - snd_mixahead = Cvar_Get ("snd_mixahead", "0.1", CVAR_ARCHIVE, NULL, - "Delay time for sounds"); - snd_noextraupdate = Cvar_Get ("snd_noextraupdate", "0", CVAR_NONE, NULL, - "Toggles the correct value display in " - "host_speeds. Usually messes up sound " - "playback when in effect"); - snd_show = Cvar_Get ("snd_show", "0", CVAR_NONE, NULL, - "Toggles display of sounds currently being played"); + Cvar_Register (&nosound_cvar, 0, 0); + Cvar_Register (&snd_volume_cvar, 0, 0); + Cvar_Register (&snd_mixahead_cvar, 0, 0); + Cvar_Register (&snd_noextraupdate_cvar, 0, 0); + Cvar_Register (&snd_show_cvar, 0, 0); } static void @@ -344,13 +379,6 @@ s_init (void) Cmd_AddCommand ("snd_force_unblock", s_snd_force_unblock, "fix permanently blocked sound"); -// FIXME -//extern struct cvar_s *snd_loadas8bit; -// if (host_parms.memsize < 0x800000) { -// Cvar_Set (snd_loadas8bit, "1"); -// Sys_Printf ("loading all sounds as 8bit\n"); -// } - snd_initialized = true; s_startup (); diff --git a/libs/audio/renderer/snd_mix.c b/libs/audio/renderer/snd_mix.c index d26b4e430..36ee40527 100644 --- a/libs/audio/renderer/snd_mix.c +++ b/libs/audio/renderer/snd_mix.c @@ -48,8 +48,6 @@ // note: must be >= 255 due to the channel // volumes being 0-255. -cvar_t *snd_volume; - portable_samplepair_t snd_paintbuffer[PAINTBUFFER_SIZE * 2]; static int max_overpaint; // number of extra samples painted // due to phase shift @@ -170,7 +168,7 @@ SND_PaintChannels (snd_t *snd, unsigned endtime) // transfer out according to DMA format snd->xfer (snd, snd_paintbuffer, end - snd->paintedtime, - snd_volume->value); + snd_volume); memmove (snd_paintbuffer, snd_paintbuffer + end - snd->paintedtime, max_overpaint * sizeof (snd_paintbuffer[0])); diff --git a/libs/audio/renderer/snd_sfx.c b/libs/audio/renderer/snd_sfx.c index b3abc6f66..b3ad1b602 100644 --- a/libs/audio/renderer/snd_sfx.c +++ b/libs/audio/renderer/snd_sfx.c @@ -53,7 +53,15 @@ static sfx_t snd_sfx[MAX_SFX]; static int snd_num_sfx; static hashtab_t *snd_sfx_hash; -static cvar_t *precache; +static int precache; +static cvar_t precache_cvar = { + .name = "precache", + .description = + "Toggle the use of a precache", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &precache }, +}; static const char * snd_sfx_getkey (const void *sfx, void *unused) @@ -203,7 +211,7 @@ SND_PrecacheSound (snd_t *snd, const char *name) Sys_Error ("SND_PrecacheSound: NULL"); sfx = SND_LoadSound (snd, va (0, "sound/%s", name)); - if (sfx && precache->int_val) { + if (sfx && precache) { if (sfx->retain (sfx)) sfx->release (sfx); } @@ -249,8 +257,7 @@ void SND_SFX_Init (snd_t *snd) { snd_sfx_hash = Hash_NewTable (511, snd_sfx_getkey, snd_sfx_free, 0, 0); - precache = Cvar_Get ("precache", "1", CVAR_NONE, NULL, - "Toggle the use of a precache"); + Cvar_Register (&precache_cvar, 0, 0); QFS_GamedirCallback (s_gamedir); diff --git a/libs/audio/snd.c b/libs/audio/snd.c index 072fef20f..86ddda631 100644 --- a/libs/audio/snd.c +++ b/libs/audio/snd.c @@ -37,8 +37,24 @@ #include "snd_internal.h" -static cvar_t *snd_output; -static cvar_t *snd_render; +static char *snd_output; +static cvar_t snd_output_cvar = { + .name = "snd_output", + .description = + "Sound Output Plugin to use", + .default_value = SND_OUTPUT_DEFAULT, + .flags = CVAR_ROM, + .value = { .type = 0, .value = &snd_output }, +}; +static char *snd_render; +static cvar_t snd_render_cvar = { + .name = "snd_render", + .description = + "Sound Renderer Plugin to use", + .default_value = "default", + .flags = CVAR_ROM, + .value = { .type = 0, .value = &snd_render }, +}; static plugin_t *snd_render_module = NULL; static plugin_t *snd_output_module = NULL; static snd_render_funcs_t *snd_render_funcs = NULL; @@ -73,7 +89,7 @@ S_Init (int *viewentity, double *host_frametime) if (COM_CheckParm ("-nosound")) return; - if (!*snd_output->string || !*snd_render->string) { + if (!*snd_output || !*snd_render) { Sys_Printf ("Not loading sound due to no renderer/output\n"); return; } @@ -82,15 +98,15 @@ S_Init (int *viewentity, double *host_frametime) PI_RegisterPlugins (snd_output_list); PI_RegisterPlugins (snd_render_list); - snd_output_module = PI_LoadPlugin ("snd_output", snd_output->string); + snd_output_module = PI_LoadPlugin ("snd_output", snd_output); if (!snd_output_module) { Sys_Printf ("Loading of sound output module: %s failed!\n", - snd_output->string); + snd_output); } else { - snd_render_module = PI_LoadPlugin ("snd_render", snd_render->string); + snd_render_module = PI_LoadPlugin ("snd_render", snd_render); if (!snd_render_module) { Sys_Printf ("Loading of sound render module: %s failed!\n", - snd_render->string); + snd_render); PI_UnloadPlugin (snd_output_module); snd_output_module = NULL; } else { @@ -114,10 +130,8 @@ S_Init (int *viewentity, double *host_frametime) VISIBLE void S_Init_Cvars (void) { - snd_output = Cvar_Get ("snd_output", SND_OUTPUT_DEFAULT, CVAR_ROM, NULL, - "Sound Output Plugin to use"); - snd_render = Cvar_Get ("snd_render", "default", CVAR_ROM, NULL, - "Sound Renderer Plugin to use"); + Cvar_Register (&snd_output_cvar, 0, 0); + Cvar_Register (&snd_render_cvar, 0, 0); } VISIBLE void diff --git a/libs/audio/targets/snd_alsa.c b/libs/audio/targets/snd_alsa.c index fdee222b1..8fba39a2c 100644 --- a/libs/audio/targets/snd_alsa.c +++ b/libs/audio/targets/snd_alsa.c @@ -53,10 +53,42 @@ static void *alsa_handle; static snd_pcm_t *pcm; static snd_async_handler_t *async_handler; -static cvar_t *snd_bits; -static cvar_t *snd_device; -static cvar_t *snd_rate; -static cvar_t *snd_stereo; +static int snd_bits; +static cvar_t snd_bits_cvar = { + .name = "snd_bits", + .description = + "sound sample depth. 0 is system default", + .default_value = "0", + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &snd_bits }, +}; +static char *snd_device; +static cvar_t snd_device_cvar = { + .name = "snd_device", + .description = + "sound device. \"\" is system default", + .default_value = "", + .flags = CVAR_ROM, + .value = { .type = 0, .value = &snd_device }, +}; +static int snd_rate; +static cvar_t snd_rate_cvar = { + .name = "snd_rate", + .description = + "sound playback rate. 0 is system default", + .default_value = "0", + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &snd_rate }, +}; +static int snd_stereo; +static cvar_t snd_stereo_cvar = { + .name = "snd_stereo", + .description = + "sound stereo output", + .default_value = "1", + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &snd_stereo }, +}; //FIXME xfer probably should not be touching this (such data should probably //come through snd_t) @@ -92,14 +124,10 @@ load_libasound (void) static void SNDDMA_Init_Cvars (void) { - snd_stereo = Cvar_Get ("snd_stereo", "1", CVAR_ROM, NULL, - "sound stereo output"); - snd_rate = Cvar_Get ("snd_rate", "0", CVAR_ROM, NULL, - "sound playback rate. 0 is system default"); - snd_device = Cvar_Get ("snd_device", "", CVAR_ROM, NULL, - "sound device. \"\" is system default"); - snd_bits = Cvar_Get ("snd_bits", "0", CVAR_ROM, NULL, - "sound sample depth. 0 is system default"); + Cvar_Register (&snd_stereo_cvar, 0, 0); + Cvar_Register (&snd_rate_cvar, 0, 0); + Cvar_Register (&snd_device_cvar, 0, 0); + Cvar_Register (&snd_bits_cvar, 0, 0); } static __attribute__((const)) snd_pcm_uframes_t @@ -415,13 +443,13 @@ alsa_playback_set_bps (snd_t *snd, snd_pcm_hw_params_t *hw) int res; int bps = 0; - if (snd_bits->int_val == 16) { + if (snd_bits == 16) { bps = SND_PCM_FORMAT_S16_LE; snd->samplebits = 16; - } else if (snd_bits->int_val == 8) { + } else if (snd_bits == 8) { bps = SND_PCM_FORMAT_U8; snd->samplebits = 8; - } else if (snd_bits->int_val) { + } else if (snd_bits) { Sys_Printf ("snd_alsa: invalid sample bits: %d\n", bps); return 0; } @@ -454,7 +482,7 @@ alsa_playback_set_channels (snd_t *snd, snd_pcm_hw_params_t *hw) int res; int channels = 1; - if (snd_stereo->int_val) { + if (snd_stereo) { channels = 2; } if ((res = qfsnd_pcm_hw_params_set_channels (pcm, hw, channels)) == 0) { @@ -473,8 +501,8 @@ alsa_playback_set_rate (snd_t *snd, snd_pcm_hw_params_t *hw) unsigned rate = 0; static int default_rates[] = { 48000, 44100, 22050, 11025, 0 }; - if (snd_rate->int_val) { - rate = snd_rate->int_val; + if (snd_rate) { + rate = snd_rate; } if (rate) { @@ -531,7 +559,7 @@ static int SNDDMA_Init (snd_t *snd) { int res; - const char *device = snd_device->string; + const char *device = snd_device; snd_pcm_hw_params_t *hw; snd_pcm_sw_params_t *sw; diff --git a/libs/audio/targets/snd_dx.c b/libs/audio/targets/snd_dx.c index e53839c4e..610fc4616 100644 --- a/libs/audio/targets/snd_dx.c +++ b/libs/audio/targets/snd_dx.c @@ -83,21 +83,42 @@ static HINSTANCE hInstDS; static sndinitstat SNDDMA_InitDirect (snd_t *snd); -static cvar_t *snd_stereo; -static cvar_t *snd_rate; -static cvar_t *snd_bits; +static int snd_stereo; +static cvar_t snd_stereo_cvar = { + .name = "snd_stereo", + .description = + "sound stereo output", + .default_value = "1", + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &snd_stereo }, +}; +static int snd_rate; +static cvar_t snd_rate_cvar = { + .name = "snd_rate", + .description = + "sound playback rate. 0 is system default", + .default_value = "0", + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &snd_rate }, +}; +static int snd_bits; +static cvar_t snd_bits_cvar = { + .name = "snd_bits", + .description = + "sound sample depth. 0 is system default", + .default_value = "0", + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &snd_bits }, +}; static DWORD *DSOUND_LockBuffer (snd_t *snd, qboolean lockit); static void SNDDMA_Init_Cvars (void) { - snd_stereo = Cvar_Get ("snd_stereo", "1", CVAR_ROM, NULL, - "sound stereo output"); - snd_rate = Cvar_Get ("snd_rate", "11025", CVAR_ROM, NULL, - "sound playback rate. 0 is system default"); - snd_bits = Cvar_Get ("snd_bits", "16", CVAR_ROM, NULL, - "sound sample depth. 0 is system default"); + Cvar_Register (&snd_stereo_cvar, 0, 0); + Cvar_Register (&snd_rate_cvar, 0, 0); + Cvar_Register (&snd_bits_cvar, 0, 0); } static void @@ -152,14 +173,14 @@ SNDDMA_InitDirect (snd_t *snd) HRESULT hresult; WAVEFORMATEX format, pformat; - if (!snd_stereo->int_val) { + if (!snd_stereo) { snd->channels = 1; } else { snd->channels = 2; } - snd->samplebits = snd_bits->int_val; - snd->speed = snd_rate->int_val; + snd->samplebits = snd_bits; + snd->speed = snd_rate; memset (&format, 0, sizeof (format)); format.wFormatTag = WAVE_FORMAT_PCM; diff --git a/libs/audio/targets/snd_jack.c b/libs/audio/targets/snd_jack.c index 095349e1b..d484c3e46 100644 --- a/libs/audio/targets/snd_jack.c +++ b/libs/audio/targets/snd_jack.c @@ -55,8 +55,25 @@ static double snd_alive_time = 0; static jack_client_t *jack_handle; static jack_port_t *jack_out[2]; static float *output[2]; -static cvar_t *snd_jack_server; -static cvar_t *snd_jack_ports; +static char *snd_jack_server; +static cvar_t snd_jack_server_cvar = { + .name = "snd_jack_server", + .description = + "The name of the JACK server to connect to", + .default_value = "default", + .flags = CVAR_ROM, + .value = { .type = 0, .value = &snd_jack_server }, +}; +static char *snd_jack_ports; +static cvar_t snd_jack_ports_cvar = { + .name = "snd_jack_ports", + .description = + "; separated list of port names to which QF will connect. Defaults to " + "the first two physical ports. Currently only two ports are supported.", + .default_value = "", + .flags = CVAR_ROM, + .value = { .type = 0, .value = &snd_jack_ports }, +}; static int s_jack_connect (snd_t *snd); @@ -126,13 +143,13 @@ s_jack_activate (void) int i; snd_shutdown = 0; - if (!*snd_jack_ports->string) { + if (!*snd_jack_ports) { ports = jack_get_ports (jack_handle, 0, 0, JackPortIsPhysical | JackPortIsInput); } else { - ports = s_jack_parse_ports (snd_jack_ports->string); + ports = s_jack_parse_ports (snd_jack_ports); } - if (developer->int_val & SYS_snd) { + if (developer & SYS_snd) { for (i = 0; ports[i]; i++) { Sys_Printf ("%s\n", ports[i]); } @@ -222,7 +239,7 @@ snd_jack_error (const char *desc) static int snd_jack_xrun (void *arg) { - if (developer->int_val & SYS_snd) { + if (developer & SYS_snd) { fprintf (stderr, "snd_jack: xrun\n"); } return 0; @@ -236,7 +253,7 @@ s_jack_connect (snd_t *snd) jack_set_error_function (snd_jack_error); if ((jack_handle = jack_client_open ("QuakeForge", JackServerName | JackNoStartServer, 0, - snd_jack_server->string)) == 0) { + snd_jack_server)) == 0) { Sys_Printf ("Could not connect to JACK\n"); return 0; } @@ -280,13 +297,8 @@ s_shutdown (snd_t *snd) static void s_init_cvars (void) { - snd_jack_server = Cvar_Get ("snd_jack_server", "default", CVAR_ROM, NULL, - "The name of the JACK server to connect to"); - snd_jack_ports = Cvar_Get ("snd_jack_ports", "", CVAR_ROM, NULL, - "; separated list of port names to which QF " - "will connect. Defaults to the first two " - "physical ports. Currently only two ports " - "are supported."); + Cvar_Register (&snd_jack_server_cvar, 0, 0); + Cvar_Register (&snd_jack_ports_cvar, 0, 0); } static general_funcs_t plugin_info_general_funcs = { diff --git a/libs/audio/targets/snd_oss.c b/libs/audio/targets/snd_oss.c index 59e34cf93..e938e3965 100644 --- a/libs/audio/targets/snd_oss.c +++ b/libs/audio/targets/snd_oss.c @@ -81,11 +81,51 @@ static const char *snd_dev = "/dev/dsp"; static int tryrates[] = { 44100, 48000, 11025, 22050, 22051, 44100, 8000 }; -static cvar_t *snd_stereo; -static cvar_t *snd_rate; -static cvar_t *snd_device; -static cvar_t *snd_bits; -static cvar_t *snd_oss_mmaped; +static int snd_stereo; +static cvar_t snd_stereo_cvar = { + .name = "snd_stereo", + .description = + "sound stereo output", + .default_value = "1", + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &snd_stereo }, +}; +static int snd_rate; +static cvar_t snd_rate_cvar = { + .name = "snd_rate", + .description = + "sound playback rate. 0 is system default", + .default_value = "0", + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &snd_rate }, +}; +static char *snd_device; +static cvar_t snd_device_cvar = { + .name = "snd_device", + .description = + "sound device. \"\" is system default", + .default_value = "", + .flags = CVAR_ROM, + .value = { .type = 0, .value = &snd_device }, +}; +static int snd_bits; +static cvar_t snd_bits_cvar = { + .name = "snd_bits", + .description = + "sound sample depth. 0 is system default", + .default_value = "0", + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &snd_bits }, +}; +static int snd_oss_mmaped; +static cvar_t snd_oss_mmaped_cvar = { + .name = "snd_oss_mmaped", + .description = + "mmaped io", + .default_value = "1", + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &snd_oss_mmaped }, +}; static plugin_t plugin_info; static plugin_data_t plugin_info_data; @@ -99,16 +139,11 @@ static snd_output_funcs_t plugin_info_snd_output_funcs; static void SNDDMA_Init_Cvars (void) { - snd_stereo = Cvar_Get ("snd_stereo", "1", CVAR_ROM, NULL, - "sound stereo output"); - snd_rate = Cvar_Get ("snd_rate", "0", CVAR_ROM, NULL, - "sound playback rate. 0 is system default"); - snd_device = Cvar_Get ("snd_device", "", CVAR_ROM, NULL, - "sound device. \"\" is system default"); - snd_bits = Cvar_Get ("snd_bits", "0", CVAR_ROM, NULL, - "sound sample depth. 0 is system default"); - snd_oss_mmaped = Cvar_Get ("snd_oss_mmaped", "1", CVAR_ROM, NULL, - "mmaped io"); + Cvar_Register (&snd_stereo_cvar, 0, 0); + Cvar_Register (&snd_rate_cvar, 0, 0); + Cvar_Register (&snd_device_cvar, 0, 0); + Cvar_Register (&snd_bits_cvar, 0, 0); + Cvar_Register (&snd_oss_mmaped_cvar, 0, 0); } static int @@ -122,11 +157,11 @@ try_open (snd_t *snd, int rw) struct audio_buf_info info; snd_inited = 0; - mmaped_io = snd_oss_mmaped->int_val; + mmaped_io = snd_oss_mmaped; // open snd_dev, confirm capability to mmap, and get size of dma buffer - if (snd_device->string[0]) - snd_dev = snd_device->string; + if (snd_device[0]) + snd_dev = snd_device; if (rw) { omode = O_RDWR; @@ -168,7 +203,7 @@ try_open (snd_t *snd, int rw) } // set sample bits & speed - snd->samplebits = snd_bits->int_val; + snd->samplebits = snd_bits; if (snd->samplebits != 16 && snd->samplebits != 8) { ioctl (audio_fd, SNDCTL_DSP_GETFMTS, &fmt); @@ -216,8 +251,8 @@ try_open (snd_t *snd, int rw) return 0; } - if (snd_rate->int_val) { - snd->speed = snd_rate->int_val; + if (snd_rate) { + snd->speed = snd_rate; } else { for (i = 0; i < ((int) sizeof (tryrates) / 4); i++) if (!ioctl (audio_fd, SNDCTL_DSP_SPEED, &tryrates[i])) @@ -225,7 +260,7 @@ try_open (snd_t *snd, int rw) snd->speed = tryrates[i]; } - if (!snd_stereo->int_val) { + if (!snd_stereo) { snd->channels = 1; } else { snd->channels = 2; diff --git a/libs/audio/targets/snd_sdl.c b/libs/audio/targets/snd_sdl.c index c9ab69060..f77f17a61 100644 --- a/libs/audio/targets/snd_sdl.c +++ b/libs/audio/targets/snd_sdl.c @@ -55,9 +55,33 @@ static unsigned shm_rpos; static unsigned wpos; -static cvar_t *snd_bits; -static cvar_t *snd_rate; -static cvar_t *snd_stereo; +static int snd_bits; +static cvar_t snd_bits_cvar = { + .name = "snd_bits", + .description = + "sound sample depth. 0 is system default", + .default_value = "0", + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &snd_bits }, +}; +static int snd_rate; +static cvar_t snd_rate_cvar = { + .name = "snd_rate", + .description = + "sound playback rate. 0 is system default", + .default_value = "0", + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &snd_rate }, +}; +static int snd_stereo; +static cvar_t snd_stereo_cvar = { + .name = "snd_stereo", + .description = + "sound stereo output", + .default_value = "1", + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &snd_stereo }, +}; static plugin_t plugin_info; static plugin_data_t plugin_info_data; @@ -86,12 +110,9 @@ paint_audio (void *unused, Uint8 * stream, int len) static void SNDDMA_Init_Cvars (void) { - snd_stereo = Cvar_Get ("snd_stereo", "1", CVAR_ROM, NULL, - "sound stereo output"); - snd_rate = Cvar_Get ("snd_rate", "0", CVAR_ROM, NULL, - "sound playback rate. 0 is system default"); - snd_bits = Cvar_Get ("snd_bits", "0", CVAR_ROM, NULL, - "sound sample depth. 0 is system default"); + Cvar_Register (&snd_stereo_cvar, 0, 0); + Cvar_Register (&snd_rate_cvar, 0, 0); + Cvar_Register (&snd_bits_cvar, 0, 0); } static int @@ -109,9 +130,9 @@ SNDDMA_Init (snd_t *snd) /* Set up the desired format */ desired.freq = 22050; - if (snd_rate->int_val) - desired.freq = snd_rate->int_val; - switch (snd_bits->int_val) { + if (snd_rate) + desired.freq = snd_rate; + switch (snd_bits) { case 8: desired.format = AUDIO_U8; break; @@ -124,10 +145,10 @@ SNDDMA_Init (snd_t *snd) break; default: Sys_Printf ("Unknown number of audio bits: %d\n", - snd_bits->int_val); + snd_bits); return 0; } - desired.channels = snd_stereo->int_val ? 2 : 1; + desired.channels = snd_stereo ? 2 : 1; desired.samples = 1024; desired.callback = paint_audio; diff --git a/libs/audio/targets/snd_win.c b/libs/audio/targets/snd_win.c index 361bb5afc..42b23a820 100644 --- a/libs/audio/targets/snd_win.c +++ b/libs/audio/targets/snd_win.c @@ -70,20 +70,41 @@ static DWORD gSndBufSize; static qboolean SNDDMA_InitWav (snd_t *snd); -static cvar_t *snd_stereo; -static cvar_t *snd_rate; -static cvar_t *snd_bits; +static int snd_stereo; +static cvar_t snd_stereo_cvar = { + .name = "snd_stereo", + .description = + "sound stereo output", + .default_value = "1", + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &snd_stereo }, +}; +static int snd_rate; +static cvar_t snd_rate_cvar = { + .name = "snd_rate", + .description = + "sound playback rate. 0 is system default", + .default_value = "0", + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &snd_rate }, +}; +static int snd_bits; +static cvar_t snd_bits_cvar = { + .name = "snd_bits", + .description = + "sound sample depth. 0 is system default", + .default_value = "0", + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &snd_bits }, +}; static void SNDDMA_Init_Cvars (void) { - snd_stereo = Cvar_Get ("snd_stereo", "1", CVAR_ROM, NULL, - "sound stereo output"); - snd_rate = Cvar_Get ("snd_rate", "11025", CVAR_ROM, NULL, - "sound playback rate. 0 is system default"); - snd_bits = Cvar_Get ("snd_bits", "16", CVAR_ROM, NULL, - "sound sample depth. 0 is system default"); + Cvar_Register (&snd_stereo_cvar, 0, 0); + Cvar_Register (&snd_rate_cvar, 0, 0); + Cvar_Register (&snd_bits_cvar, 0, 0); } static void @@ -150,14 +171,14 @@ SNDDMA_InitWav (snd_t *snd) snd_sent = 0; snd_completed = 0; - if (!snd_stereo->int_val) { + if (!snd_stereo) { snd->channels = 1; } else { snd->channels = 2; } - snd->samplebits = snd_bits->int_val; - snd->speed = snd_rate->int_val; + snd->samplebits = snd_bits; + snd->speed = snd_rate; memset (&format, 0, sizeof (format)); format.wFormatTag = WAVE_FORMAT_PCM; diff --git a/libs/audio/test/testsound.c b/libs/audio/test/testsound.c index d5fe91347..f917a4440 100644 --- a/libs/audio/test/testsound.c +++ b/libs/audio/test/testsound.c @@ -66,7 +66,7 @@ init (void) Sys_Init (); COM_ParseConfig (testsound_cbuf); - Cvar_Get ("cmd_warncmd", "1", CVAR_NONE, NULL, NULL); + cmd_warncmd = 1; memhunk_t *hunk = Memory_Init (Sys_Alloc (MEMSIZE), MEMSIZE); diff --git a/libs/client/cl_chase.c b/libs/client/cl_chase.c index 483e1605f..7712875ba 100644 --- a/libs/client/cl_chase.c +++ b/libs/client/cl_chase.c @@ -50,19 +50,51 @@ #include "client/view.h" -cvar_t *chase_back; -cvar_t *chase_up; -cvar_t *chase_right; -cvar_t *chase_active; +float chase_back; +static cvar_t chase_back_cvar = { + .name = "chase_back", + .description = + "None", + .default_value = "100", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &chase_back }, +}; +float chase_up; +static cvar_t chase_up_cvar = { + .name = "chase_up", + .description = + "None", + .default_value = "16", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &chase_up }, +}; +float chase_right; +static cvar_t chase_right_cvar = { + .name = "chase_right", + .description = + "None", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &chase_right }, +}; +int chase_active; +static cvar_t chase_active_cvar = { + .name = "chase_active", + .description = + "None", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &chase_active }, +}; void Chase_Init_Cvars (void) { - chase_back = Cvar_Get ("chase_back", "100", CVAR_NONE, NULL, "None"); - chase_up = Cvar_Get ("chase_up", "16", CVAR_NONE, NULL, "None"); - chase_right = Cvar_Get ("chase_right", "0", CVAR_NONE, NULL, "None"); - chase_active = Cvar_Get ("chase_active", "0", CVAR_NONE, NULL, "None"); + Cvar_Register (&chase_back_cvar, 0, 0); + Cvar_Register (&chase_up_cvar, 0, 0); + Cvar_Register (&chase_right_cvar, 0, 0); + Cvar_Register (&chase_active_cvar, 0, 0); } void @@ -104,8 +136,8 @@ limit_distance (chasestate_t *cs) vec4f_t dir = cs->camera_origin - cs->player_origin; vec4f_t forward = normalf (dir); - if (magnitudef (dir)[0] > chase_back->value) { - cs->camera_origin = cs->player_origin + forward * chase_back->value; + if (magnitudef (dir)[0] > chase_back) { + cs->camera_origin = cs->player_origin + forward * chase_back; } } @@ -132,26 +164,26 @@ cam_controls (chasestate_t *cs, viewstate_t *vs) vec4f_t dir = { }; if (in_strafe.state & 1) { - move[SIDE] += cl_sidespeed->value * IN_ButtonState (&in_right); - move[SIDE] -= cl_sidespeed->value * IN_ButtonState (&in_left); + move[SIDE] += cl_sidespeed * IN_ButtonState (&in_right); + move[SIDE] -= cl_sidespeed * IN_ButtonState (&in_left); } - move[SIDE] += cl_sidespeed->value * IN_ButtonState (&in_moveright); - move[SIDE] -= cl_sidespeed->value * IN_ButtonState (&in_moveleft); + move[SIDE] += cl_sidespeed * IN_ButtonState (&in_moveright); + move[SIDE] -= cl_sidespeed * IN_ButtonState (&in_moveleft); if (!(in_klook.state & 1)) { - move[FORWARD] += cl_forwardspeed->value + move[FORWARD] += cl_forwardspeed * IN_ButtonState (&in_forward); - move[FORWARD] -= cl_backspeed->value * IN_ButtonState (&in_back); + move[FORWARD] -= cl_backspeed * IN_ButtonState (&in_back); } if (in_speed.state & 1) { - move *= cl_movespeedkey->value; + move *= cl_movespeedkey; } // mouse and joystick controllers add to movement VectorSet (0, vs->player_angles[1] - cs->camera_angles[1], 0, dir); AngleVectors ((vec_t*)&dir, (vec_t*)&forward, (vec_t*)&right, (vec_t*)&up); //FIXME - forward *= IN_UpdateAxis (&in_cam_forward) * m_forward->value; - right *= IN_UpdateAxis (&in_cam_side) * m_side->value; + forward *= IN_UpdateAxis (&in_cam_forward) * m_forward; + right *= IN_UpdateAxis (&in_cam_side) * m_side; dir = forward + right; move[FORWARD] += dir[0]; move[SIDE] -= dir[1]; @@ -191,9 +223,9 @@ chase_mode_1 (chasestate_t *cs) // calc exact destination cs->camera_origin = vs->player_origin - - forward * chase_back->value - right * chase_right->value; + - forward * chase_back - right * chase_right; // chase_up is world up - cs->camera_origin[2] += chase_up->value; + cs->camera_origin[2] += chase_up; // check for walls between player and camera stop = TraceLine (cs, vs->player_origin, cs->camera_origin); @@ -219,13 +251,13 @@ chase_mode_2 (chasestate_t *cs) // move camera, it's not enough to just change the angles because // the angles are automatically changed to look toward the player AngleVectors (cs->camera_angles, (vec_t*)&forward, (vec_t*)&right, (vec_t*)&up);//FIXME - cs->camera_origin = cs->player_origin - chase_back->value * forward; + cs->camera_origin = cs->player_origin - chase_back * forward; cs->player_origin = vs->player_origin; // don't let camera get too low - if (cs->camera_origin[2] < cs->player_origin[2] + chase_up->value) { - cs->camera_origin[2] = cs->player_origin[2] + chase_up->value; + if (cs->camera_origin[2] < cs->player_origin[2] + chase_up) { + cs->camera_origin[2] = cs->player_origin[2] + chase_up; } limit_distance (cs); @@ -267,7 +299,7 @@ chase_mode_3 (chasestate_t *cs) cs->player_origin = vs->player_origin; AngleVectors (cs->camera_angles, (vec_t*)&forward, (vec_t*)&right, (vec_t*)&up);//FIXME - cs->camera_origin = cs->player_origin - chase_back->value * forward; + cs->camera_origin = cs->player_origin - chase_back * forward; limit_distance (cs); check_for_walls (cs, forward); set_camera (cs, vs); @@ -277,7 +309,7 @@ chase_mode_3 (chasestate_t *cs) void Chase_Update (chasestate_t *cs) { - switch (chase_active->int_val) { + switch (chase_active) { case 1: chase_mode_1 (cs); return; diff --git a/libs/client/cl_effects.c b/libs/client/cl_effects.c index e5fc1d858..083d955ed 100644 --- a/libs/client/cl_effects.c +++ b/libs/client/cl_effects.c @@ -129,7 +129,7 @@ CL_ModelEffects (entity_t *ent, int num, int glow_color, double time) VectorCopy (ent_origin, dl->origin); dl->radius = 200.0; dl->die = time + 0.1; - //FIXME VectorCopy (r_firecolor->vec, dl->color); + //FIXME VectorCopy (r_firecolor, dl->color); VectorSet (0.9, 0.7, 0.0, dl->color); dl->color[3] = 0.7; } diff --git a/libs/client/cl_input.c b/libs/client/cl_input.c index ec2201cd2..6feefdf50 100644 --- a/libs/client/cl_input.c +++ b/libs/client/cl_input.c @@ -214,20 +214,124 @@ static in_button_t *cl_in_buttons[] = { 0 }; -cvar_t *cl_anglespeedkey; -cvar_t *cl_backspeed; -cvar_t *cl_forwardspeed; -cvar_t *cl_movespeedkey; -cvar_t *cl_pitchspeed; -cvar_t *cl_sidespeed; -cvar_t *cl_upspeed; -cvar_t *cl_yawspeed; +float cl_anglespeedkey; +static cvar_t cl_anglespeedkey_cvar = { + .name = "cl_anglespeedkey", + .description = + "turn `run' speed multiplier", + .default_value = "1.5", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &cl_anglespeedkey }, +}; +float cl_backspeed; +static cvar_t cl_backspeed_cvar = { + .name = "cl_backspeed", + .description = + "backward speed", + .default_value = "200", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &cl_backspeed }, +}; +float cl_forwardspeed; +static cvar_t cl_forwardspeed_cvar = { + .name = "cl_forwardspeed", + .description = + "forward speed", + .default_value = "200", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &cl_forwardspeed }, +}; +float cl_movespeedkey; +static cvar_t cl_movespeedkey_cvar = { + .name = "cl_movespeedkey", + .description = + "move `run' speed multiplier", + .default_value = "2.0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &cl_movespeedkey }, +}; +float cl_pitchspeed; +static cvar_t cl_pitchspeed_cvar = { + .name = "cl_pitchspeed", + .description = + "look up/down speed", + .default_value = "150", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &cl_pitchspeed }, +}; +float cl_sidespeed; +static cvar_t cl_sidespeed_cvar = { + .name = "cl_sidespeed", + .description = + "strafe speed", + .default_value = "350", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &cl_sidespeed }, +}; +float cl_upspeed; +static cvar_t cl_upspeed_cvar = { + .name = "cl_upspeed", + .description = + "swim/fly up/down speed", + .default_value = "200", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &cl_upspeed }, +}; +float cl_yawspeed; +static cvar_t cl_yawspeed_cvar = { + .name = "cl_yawspeed", + .description = + "turning speed", + .default_value = "140", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &cl_yawspeed }, +}; -cvar_t *lookspring; -cvar_t *m_pitch; -cvar_t *m_yaw; -cvar_t *m_forward; -cvar_t *m_side; +int lookspring; +static cvar_t lookspring_cvar = { + .name = "lookspring", + .description = + "Snap view to center when moving and no mlook/klook", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &lookspring }, +}; +float m_pitch; +static cvar_t m_pitch_cvar = { + .name = "m_pitch", + .description = + "mouse pitch (up/down) multipier", + .default_value = "0.022", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &m_pitch }, +}; +float m_yaw; +static cvar_t m_yaw_cvar = { + .name = "m_yaw", + .description = + "mouse yaw (left/right) multipiler", + .default_value = "0.022", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &m_yaw }, +}; +float m_forward; +static cvar_t m_forward_cvar = { + .name = "m_forward", + .description = + "mouse forward/back speed", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &m_forward }, +}; +float m_side; +static cvar_t m_side_cvar = { + .name = "m_side", + .description = + "mouse strafe speed", + .default_value = "0.8", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &m_side }, +}; static void CL_AdjustAngles (float frametime, movestate_t *ms, viewstate_t *vs) @@ -236,12 +340,12 @@ CL_AdjustAngles (float frametime, movestate_t *ms, viewstate_t *vs) float pitchspeed, yawspeed; vec4f_t delta = {}; - pitchspeed = cl_pitchspeed->value; - yawspeed = cl_yawspeed->value; + pitchspeed = cl_pitchspeed; + yawspeed = cl_yawspeed; if (in_speed.state & inb_down) { - pitchspeed *= cl_anglespeedkey->value; - yawspeed *= cl_anglespeedkey->value; + pitchspeed *= cl_anglespeedkey; + yawspeed *= cl_anglespeedkey; } pitchspeed *= frametime; @@ -263,9 +367,9 @@ CL_AdjustAngles (float frametime, movestate_t *ms, viewstate_t *vs) delta[PITCH] -= pitchspeed * up; delta[PITCH] += pitchspeed * down; - delta[PITCH] -= IN_UpdateAxis (&in_move_pitch) * m_pitch->value; - delta[YAW] -= IN_UpdateAxis (&in_move_yaw) * m_yaw->value; - delta[ROLL] -= IN_UpdateAxis (&in_move_roll) * m_pitch->value; + delta[PITCH] -= IN_UpdateAxis (&in_move_pitch) * m_pitch; + delta[YAW] -= IN_UpdateAxis (&in_move_yaw) * m_yaw; + delta[ROLL] -= IN_UpdateAxis (&in_move_roll) * m_pitch; ms->angles += delta; @@ -359,7 +463,7 @@ CL_Legacy_Init (void) void CL_Input_BuildMove (float frametime, movestate_t *state, viewstate_t *vs) { - if (IN_ButtonReleased (&in_mlook) && !freelook && lookspring->int_val) { + if (IN_ButtonReleased (&in_mlook) && !freelook && lookspring) { V_StartPitchDrift (vs); } @@ -368,35 +472,35 @@ CL_Input_BuildMove (float frametime, movestate_t *state, viewstate_t *vs) vec4f_t move = {}; if (in_strafe.state & inb_down) { - move[SIDE] += cl_sidespeed->value * IN_ButtonState (&in_right); - move[SIDE] -= cl_sidespeed->value * IN_ButtonState (&in_left); + move[SIDE] += cl_sidespeed * IN_ButtonState (&in_right); + move[SIDE] -= cl_sidespeed * IN_ButtonState (&in_left); } - move[SIDE] += cl_sidespeed->value * IN_ButtonState (&in_moveright); - move[SIDE] -= cl_sidespeed->value * IN_ButtonState (&in_moveleft); + move[SIDE] += cl_sidespeed * IN_ButtonState (&in_moveright); + move[SIDE] -= cl_sidespeed * IN_ButtonState (&in_moveleft); - move[UP] += cl_upspeed->value * IN_ButtonState (&in_up); - move[UP] -= cl_upspeed->value * IN_ButtonState (&in_down); + move[UP] += cl_upspeed * IN_ButtonState (&in_up); + move[UP] -= cl_upspeed * IN_ButtonState (&in_down); if (!(in_klook.state & inb_down)) { - move[FORWARD] += cl_forwardspeed->value * IN_ButtonState (&in_forward); - move[FORWARD] -= cl_backspeed->value * IN_ButtonState (&in_back); + move[FORWARD] += cl_forwardspeed * IN_ButtonState (&in_forward); + move[FORWARD] -= cl_backspeed * IN_ButtonState (&in_back); } // adjust for speed key if (in_speed.state & inb_down) { - move *= cl_movespeedkey->value; + move *= cl_movespeedkey; } - move[FORWARD] -= IN_UpdateAxis (&in_move_forward) * m_forward->value; - move[SIDE] += IN_UpdateAxis (&in_move_side) * m_side->value; + move[FORWARD] -= IN_UpdateAxis (&in_move_forward) * m_forward; + move[SIDE] += IN_UpdateAxis (&in_move_side) * m_side; move[UP] -= IN_UpdateAxis (&in_move_up); if (freelook) V_StopPitchDrift (vs); if (vs->chase - && (chase_active->int_val == 2 || chase_active->int_val == 3)) { + && (chase_active == 2 || chase_active == 3)) { /* adjust for chase camera angles * makes the player move relative to the chase camera frame rather * than the player's frame @@ -481,32 +585,19 @@ CL_Input_Init (cbuf_t *cbuf) void CL_Input_Init_Cvars (void) { - lookspring = Cvar_Get ("lookspring", "0", CVAR_ARCHIVE, NULL, "Snap view " - "to center when moving and no mlook/klook"); - m_pitch = Cvar_Get ("m_pitch", "0.022", CVAR_ARCHIVE, NULL, - "mouse pitch (up/down) multipier"); - m_yaw = Cvar_Get ("m_yaw", "0.022", CVAR_ARCHIVE, NULL, - "mouse yaw (left/right) multipiler"); - m_forward = Cvar_Get ("m_forward", "1", CVAR_ARCHIVE, NULL, - "mouse forward/back speed"); - m_side = Cvar_Get ("m_side", "0.8", CVAR_ARCHIVE, NULL, - "mouse strafe speed"); - cl_anglespeedkey = Cvar_Get ("cl_anglespeedkey", "1.5", CVAR_NONE, NULL, - "turn `run' speed multiplier"); - cl_backspeed = Cvar_Get ("cl_backspeed", "200", CVAR_ARCHIVE, NULL, - "backward speed"); - cl_forwardspeed = Cvar_Get ("cl_forwardspeed", "200", CVAR_ARCHIVE, NULL, - "forward speed"); - cl_movespeedkey = Cvar_Get ("cl_movespeedkey", "2.0", CVAR_NONE, NULL, - "move `run' speed multiplier"); - cl_pitchspeed = Cvar_Get ("cl_pitchspeed", "150", CVAR_NONE, NULL, - "look up/down speed"); - cl_sidespeed = Cvar_Get ("cl_sidespeed", "350", CVAR_NONE, NULL, - "strafe speed"); - cl_upspeed = Cvar_Get ("cl_upspeed", "200", CVAR_NONE, NULL, - "swim/fly up/down speed"); - cl_yawspeed = Cvar_Get ("cl_yawspeed", "140", CVAR_NONE, NULL, - "turning speed"); + Cvar_Register (&lookspring_cvar, 0, 0); + Cvar_Register (&m_pitch_cvar, 0, 0); + Cvar_Register (&m_yaw_cvar, 0, 0); + Cvar_Register (&m_forward_cvar, 0, 0); + Cvar_Register (&m_side_cvar, 0, 0); + Cvar_Register (&cl_anglespeedkey_cvar, 0, 0); + Cvar_Register (&cl_backspeed_cvar, 0, 0); + Cvar_Register (&cl_forwardspeed_cvar, 0, 0); + Cvar_Register (&cl_movespeedkey_cvar, 0, 0); + Cvar_Register (&cl_pitchspeed_cvar, 0, 0); + Cvar_Register (&cl_sidespeed_cvar, 0, 0); + Cvar_Register (&cl_upspeed_cvar, 0, 0); + Cvar_Register (&cl_yawspeed_cvar, 0, 0); } void diff --git a/libs/client/cl_particles.c b/libs/client/cl_particles.c index 618067612..249a14aaf 100644 --- a/libs/client/cl_particles.c +++ b/libs/client/cl_particles.c @@ -60,8 +60,24 @@ cl_particle_funcs_t *clp_funcs; static mtstate_t mt; // private PRNG state static psystem_t *cl_psystem; -static cvar_t *easter_eggs; -static cvar_t *particles_style; +static int easter_eggs; +static cvar_t easter_eggs_cvar = { + .name = "easter_eggs", + .description = + "Enables easter eggs.", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &easter_eggs }, +}; +static int particles_style; +static cvar_t particles_style_cvar = { + .name = "particles_style", + .description = + "Sets particle style. 0 for Id, 1 for QF.", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &particles_style }, +}; static int ramp[] = { /*ramp1*/ 0x6f, 0x6d, 0x6b, 0x69, 0x67, 0x65, 0x63, 0x61, @@ -1238,37 +1254,34 @@ static cl_particle_funcs_t particles_ID_egg = { }; static void -easter_eggs_f (cvar_t *var) +set_particle_funcs (void) { if (easter_eggs) { - if (easter_eggs->int_val) { - if (particles_style->int_val) { - clp_funcs = &particles_QF_egg; - } else { - clp_funcs = &particles_ID_egg; - } - } else if (particles_style) { - if (particles_style->int_val) { - clp_funcs = &particles_QF; - } else { - clp_funcs = &particles_ID; - } + if (particles_style) { + clp_funcs = &particles_QF_egg; + } else { + clp_funcs = &particles_ID_egg; + } + } else { + if (particles_style) { + clp_funcs = &particles_QF; + } else { + clp_funcs = &particles_ID; } } } static void -particles_style_f (cvar_t *var) +easter_eggs_f (void *data, const cvar_t *cvar) { - easter_eggs_f (easter_eggs); - cl_psystem->points_only = !var->int_val; + set_particle_funcs (); } static void -CL_ParticleFunctionInit (void) +particles_style_f (void *data, const cvar_t *cvar) { - particles_style_f (particles_style); - easter_eggs_f (easter_eggs); + set_particle_funcs (); + cl_psystem->points_only = !particles_style; } void @@ -1276,12 +1289,9 @@ CL_Particles_Init (void) { mtwist_seed (&mt, 0xdeadbeef); cl_psystem = r_funcs->ParticleSystem (); - easter_eggs = Cvar_Get ("easter_eggs", "0", CVAR_NONE, easter_eggs_f, - "Enables easter eggs."); - particles_style = Cvar_Get ("particles_style", "1", CVAR_ARCHIVE, - particles_style_f, - "Sets particle style. 0 for Id, 1 for QF."); - CL_ParticleFunctionInit (); + Cvar_Register (&easter_eggs_cvar, easter_eggs_f, 0); + Cvar_Register (&particles_style_cvar, particles_style_f, 0); + set_particle_funcs (); } void diff --git a/libs/client/cl_view.c b/libs/client/cl_view.c index fa693107b..b163efa65 100644 --- a/libs/client/cl_view.c +++ b/libs/client/cl_view.c @@ -54,37 +54,230 @@ especially when crossing a water boudnary. */ -cvar_t *scr_ofsx; -cvar_t *scr_ofsy; -cvar_t *scr_ofsz; +float scr_ofsx; +static cvar_t scr_ofsx_cvar = { + .name = "scr_ofsx", + .description = + "None", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &scr_ofsx }, +}; +float scr_ofsy; +static cvar_t scr_ofsy_cvar = { + .name = "scr_ofsy", + .description = + "None", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &scr_ofsy }, +}; +float scr_ofsz; +static cvar_t scr_ofsz_cvar = { + .name = "scr_ofsz", + .description = + "None", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &scr_ofsz }, +}; -cvar_t *cl_rollspeed; -cvar_t *cl_rollangle; +float cl_rollspeed; +static cvar_t cl_rollspeed_cvar = { + .name = "cl_rollspeed", + .description = + "How quickly you straighten out after strafing", + .default_value = "200", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &cl_rollspeed }, +}; +float cl_rollangle; +static cvar_t cl_rollangle_cvar = { + .name = "cl_rollangle", + .description = + "How much your screen tilts when strafing", + .default_value = "2.0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &cl_rollangle }, +}; -cvar_t *cl_bob; -cvar_t *cl_bobcycle; -cvar_t *cl_bobup; +float cl_bob; +static cvar_t cl_bob_cvar = { + .name = "cl_bob", + .description = + "How much your weapon moves up and down when walking", + .default_value = "0.02", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &cl_bob }, +}; +float cl_bobcycle; +static cvar_t cl_bobcycle_cvar = { + .name = "cl_bobcycle", + .description = + "How quickly your weapon moves up and down when walking", + .default_value = "0.6", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &cl_bobcycle }, +}; +float cl_bobup; +static cvar_t cl_bobup_cvar = { + .name = "cl_bobup", + .description = + "How long your weapon stays up before cycling when walking", + .default_value = "0.5", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &cl_bobup }, +}; -cvar_t *v_centermove; -cvar_t *v_centerspeed; +float v_centermove; +static cvar_t v_centermove_cvar = { + .name = "v_centermove", + .description = + "How far the player must move forward before the view re-centers", + .default_value = "0.15", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &v_centermove }, +}; +float v_centerspeed; +static cvar_t v_centerspeed_cvar = { + .name = "v_centerspeed", + .description = + "How quickly you return to a center view after a lookup or lookdown", + .default_value = "500", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &v_centerspeed }, +}; -cvar_t *v_kicktime; -cvar_t *v_kickroll; -cvar_t *v_kickpitch; +float v_kicktime; +static cvar_t v_kicktime_cvar = { + .name = "v_kicktime", + .description = + "How long the kick from an attack lasts", + .default_value = "0.5", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &v_kicktime }, +}; +float v_kickroll; +static cvar_t v_kickroll_cvar = { + .name = "v_kickroll", + .description = + "How much you lean when hit", + .default_value = "0.6", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &v_kickroll }, +}; +float v_kickpitch; +static cvar_t v_kickpitch_cvar = { + .name = "v_kickpitch", + .description = + "How much you look up when hit", + .default_value = "0.6", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &v_kickpitch }, +}; -cvar_t *cl_cshift_bonus; -cvar_t *cl_cshift_contents; -cvar_t *cl_cshift_damage; -cvar_t *cl_cshift_powerup; +int cl_cshift_bonus; +static cvar_t cl_cshift_bonus_cvar = { + .name = "cl_cshift_bonus", + .description = + "Show bonus flash on item pickup", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &cl_cshift_bonus }, +}; +int cl_cshift_contents; +static cvar_t cl_cshift_contents_cvar = { + .name = "cl_cshift_content", + .description = + "Shift view colors for contents (water, slime, etc)", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &cl_cshift_contents }, +}; +int cl_cshift_damage; +static cvar_t cl_cshift_damage_cvar = { + .name = "cl_cshift_damage", + .description = + "Shift view colors on damage", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &cl_cshift_damage }, +}; +int cl_cshift_powerup; +static cvar_t cl_cshift_powerup_cvar = { + .name = "cl_cshift_powerup", + .description = + "Shift view colors for powerups", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &cl_cshift_powerup }, +}; -cvar_t *v_iyaw_cycle; -cvar_t *v_iroll_cycle; -cvar_t *v_ipitch_cycle; -cvar_t *v_iyaw_level; -cvar_t *v_iroll_level; -cvar_t *v_ipitch_level; +float v_iyaw_cycle; +static cvar_t v_iyaw_cycle_cvar = { + .name = "v_iyaw_cycle", + .description = + "How far you tilt right and left when v_idlescale is enabled", + .default_value = "2", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &v_iyaw_cycle }, +}; +float v_iroll_cycle; +static cvar_t v_iroll_cycle_cvar = { + .name = "v_iroll_cycle", + .description = + "How quickly you tilt right and left when v_idlescale is enabled", + .default_value = "0.5", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &v_iroll_cycle }, +}; +float v_ipitch_cycle; +static cvar_t v_ipitch_cycle_cvar = { + .name = "v_ipitch_cycle", + .description = + "How quickly you lean forwards and backwards when v_idlescale is " + "enabled", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &v_ipitch_cycle }, +}; +float v_iyaw_level; +static cvar_t v_iyaw_level_cvar = { + .name = "v_iyaw_level", + .description = + "How far you tilt right and left when v_idlescale is enabled", + .default_value = "0.3", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &v_iyaw_level }, +}; +float v_iroll_level; +static cvar_t v_iroll_level_cvar = { + .name = "v_iroll_level", + .description = + "How far you tilt right and left when v_idlescale is enabled", + .default_value = "0.1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &v_iroll_level }, +}; +float v_ipitch_level; +static cvar_t v_ipitch_level_cvar = { + .name = "v_ipitch_level", + .description = + "How far you lean forwards and backwards when v_idlescale is enabled", + .default_value = "0.3", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &v_ipitch_level }, +}; -cvar_t *v_idlescale; +float v_idlescale; +static cvar_t v_idlescale_cvar = { + .name = "v_idlescale", + .description = + "Toggles whether the view remains idle", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &v_idlescale }, +}; float v_dmg_time, v_dmg_roll, v_dmg_pitch; @@ -137,10 +330,10 @@ V_CalcRoll (const vec3_t angles, vec4f_t velocity) sign = side < 0 ? -1 : 1; side = fabs (side); - value = cl_rollangle->value; + value = cl_rollangle; - if (side < cl_rollspeed->value) - side = side * value / cl_rollspeed->value; + if (side < cl_rollspeed) + side = side * value / cl_rollspeed; else side = value; @@ -162,18 +355,18 @@ V_CalcBob (viewstate_t *vs) return bob; // just use old value bobtime += vs->frametime; - cycle = bobtime - (int) (bobtime / cl_bobcycle->value) * - cl_bobcycle->value; - cycle /= cl_bobcycle->value; - if (cycle < cl_bobup->value) - cycle = cycle / cl_bobup->value; + cycle = bobtime - (int) (bobtime / cl_bobcycle) * + cl_bobcycle; + cycle /= cl_bobcycle; + if (cycle < cl_bobup) + cycle = cycle / cl_bobup; else - cycle = 1 + (cycle - cl_bobup->value) / (1.0 - cl_bobup->value); + cycle = 1 + (cycle - cl_bobup) / (1.0 - cl_bobup); // bob is proportional to velocity in the xy plane // (don't count Z, or jumping messes it up) velocity[2] = 0; - bob = sqrt (dotf (velocity, velocity)[0]) * cl_bob->value; + bob = sqrt (dotf (velocity, velocity)[0]) * cl_bob; bob = bob * 0.3 + bob * 0.7 * sin (cycle * M_PI); if (bob > 4) bob = 4; @@ -190,7 +383,7 @@ V_StartPitchDrift (viewstate_t *vs) } if (vs->nodrift || !vs->pitchvel) { - vs->pitchvel = v_centerspeed->value; + vs->pitchvel = v_centerspeed; vs->nodrift = false; vs->driftmove = 0; } @@ -236,12 +429,12 @@ V_DriftPitch (viewstate_t *vs) // don't count small mouse motion if (vs->nodrift) { - if (fabs (forwardmove) < cl_forwardspeed->value) + if (fabs (forwardmove) < cl_forwardspeed) vs->driftmove = 0; else vs->driftmove += vs->frametime; - if (vs->driftmove > v_centermove->value) { + if (vs->driftmove > v_centermove) { V_StartPitchDrift (vs); } return; @@ -255,7 +448,7 @@ V_DriftPitch (viewstate_t *vs) } move = vs->frametime * vs->pitchvel; - vs->pitchvel += vs->frametime * v_centerspeed->value; + vs->pitchvel += vs->frametime * v_centerspeed; if (delta > 0) { if (move > delta) { @@ -291,7 +484,7 @@ V_ParseDamage (qmsg_t *net_message, viewstate_t *vs) if (count < 10) count = 10; - if (cl_cshift_damage->int_val + if (cl_cshift_damage || (vs->force_cshifts & INFO_CSHIFT_DAMAGE)) { cshift_t *cshift = &vs->cshifts[CSHIFT_DAMAGE]; int percent = cshift->percent; @@ -309,12 +502,12 @@ V_ParseDamage (qmsg_t *net_message, viewstate_t *vs) AngleVectors (angles, forward, right, up); side = DotProduct (from, right); - v_dmg_roll = count * side * v_kickroll->value; + v_dmg_roll = count * side * v_kickroll; side = DotProduct (from, forward); - v_dmg_pitch = count * side * v_kickpitch->value; + v_dmg_pitch = count * side * v_kickpitch; - v_dmg_time = v_kicktime->value; + v_dmg_time = v_kicktime; } static void @@ -335,7 +528,7 @@ static void V_BonusFlash_f (void *data) { viewstate_t *vs = data; - if (!cl_cshift_bonus->int_val + if (!cl_cshift_bonus && !(vs->force_cshifts & INFO_CSHIFT_BONUS)) return; @@ -352,7 +545,7 @@ V_BonusFlash_f (void *data) void V_SetContentsColor (viewstate_t *vs, int contents) { - if (!cl_cshift_contents->int_val + if (!cl_cshift_contents && !(vs->force_cshifts & INFO_CSHIFT_CONTENTS)) { vs->cshifts[CSHIFT_CONTENTS] = cshift_empty; return; @@ -441,7 +634,7 @@ V_PrepBlend (viewstate_t *vs) { int i, j; - if (cl_cshift_powerup->int_val + if (cl_cshift_powerup || (vs->force_cshifts & INFO_CSHIFT_POWERUP)) V_CalcPowerupCshift (vs); @@ -499,14 +692,14 @@ V_BoundOffsets (viewstate_t *vs) } static vec4f_t -idle_quat (vec4f_t axis, cvar_t *cycle, cvar_t *level, double time) +idle_quat (vec4f_t axis, float cycle, float level, double time) { vec4f_t identity = { 0, 0, 0, 1 }; if (!level || !cycle) { return identity; } - float scale = sin (time * cycle->value); - float ang = scale * level->value * v_idlescale->value; + float scale = sin (time * cycle); + float ang = scale * level * v_idlescale; float c = cos (ang * M_PI / 360); float s = sin (ang * M_PI / 360); return axis * s + identity * c; @@ -553,8 +746,8 @@ V_CalcViewRoll (viewstate_t *vs) ang[ROLL] = V_CalcRoll (angles, velocity); if (v_dmg_time > 0) { - ang[ROLL] += v_dmg_time / v_kicktime->value * v_dmg_roll; - ang[PITCH] += v_dmg_time / v_kicktime->value * v_dmg_pitch; + ang[ROLL] += v_dmg_time / v_kicktime * v_dmg_roll; + ang[PITCH] += v_dmg_time / v_kicktime * v_dmg_pitch; v_dmg_time -= vs->frametime; } @@ -586,10 +779,10 @@ V_CalcIntermissionRefdef (viewstate_t *vs) view->renderer.model = NULL; // always idle in intermission - old = v_idlescale->value; - Cvar_SetValue (v_idlescale, 1); + old = v_idlescale; + v_idlescale = 1; V_AddIdle (vs); - Cvar_SetValue (v_idlescale, old); + v_idlescale = old; } static void @@ -628,9 +821,7 @@ V_CalcRefdef (viewstate_t *vs) // don't allow cheats in multiplayer // FIXME check for dead if (vs->voffs_enabled) { - origin += scr_ofsx->value * forward - + scr_ofsy->value * right - + scr_ofsz->value * up; + origin += scr_ofsx * forward + scr_ofsy * right + scr_ofsz * up; } V_BoundOffsets (vs); @@ -644,15 +835,15 @@ V_CalcRefdef (viewstate_t *vs) // fudge position around to keep amount of weapon visible // roughly equal with different FOV - if (hud_sbar->int_val == 0 && r_data->scr_viewsize->int_val >= 100) { + if (hud_sbar == 0 && *r_data->scr_viewsize >= 100) { ; - } else if (r_data->scr_viewsize->int_val == 110) { + } else if (*r_data->scr_viewsize == 110) { gun_origin += (vec4f_t) { 0, 0, 1, 0}; - } else if (r_data->scr_viewsize->int_val == 100) { + } else if (*r_data->scr_viewsize == 100) { gun_origin += (vec4f_t) { 0, 0, 2, 0}; - } else if (r_data->scr_viewsize->int_val == 90) { + } else if (*r_data->scr_viewsize == 90) { gun_origin += (vec4f_t) { 0, 0, 1, 0}; - } else if (r_data->scr_viewsize->int_val == 80) { + } else if (*r_data->scr_viewsize == 80) { gun_origin += (vec4f_t) { 0, 0, 0.5, 0}; } @@ -741,7 +932,7 @@ V_RenderView (viewstate_t *vs) if (vs->intermission) { // intermission / finale rendering V_CalcIntermissionRefdef (vs); } else { - if (vs->chase && chase_active->int_val) { + if (vs->chase && chase_active) { Chase_Update (vs->chasestate); } else { V_CalcRefdef (vs); @@ -769,61 +960,29 @@ V_Init (viewstate_t *viewstate) void V_Init_Cvars (void) { - v_centermove = Cvar_Get ("v_centermove", "0.15", CVAR_NONE, NULL, - "How far the player must move forward before the " - "view re-centers"); - v_centerspeed = Cvar_Get ("v_centerspeed", "500", CVAR_NONE, NULL, - "How quickly you return to a center view after " - "a lookup or lookdown"); - v_iyaw_cycle = Cvar_Get ("v_iyaw_cycle", "2", CVAR_NONE, NULL, - "How far you tilt right and left when " - "v_idlescale is enabled"); - v_iroll_cycle = Cvar_Get ("v_iroll_cycle", "0.5", CVAR_NONE, NULL, - "How quickly you tilt right and left when " - "v_idlescale is enabled"); - v_ipitch_cycle = Cvar_Get ("v_ipitch_cycle", "1", CVAR_NONE, NULL, - "How quickly you lean forwards and backwards " - "when v_idlescale is enabled"); - v_iyaw_level = Cvar_Get ("v_iyaw_level", "0.3", CVAR_NONE, NULL, - "How far you tilt right and left when " - "v_idlescale is enabled"); - v_iroll_level = Cvar_Get ("v_iroll_level", "0.1", CVAR_NONE, NULL, - "How far you tilt right and left when " - "v_idlescale is enabled"); - v_ipitch_level = Cvar_Get ("v_ipitch_level", "0.3", CVAR_NONE, NULL, - "How far you lean forwards and backwards when " - "v_idlescale is enabled"); - v_idlescale = Cvar_Get ("v_idlescale", "0", CVAR_NONE, NULL, - "Toggles whether the view remains idle"); + Cvar_Register (&v_centermove_cvar, 0, 0); + Cvar_Register (&v_centerspeed_cvar, 0, 0); + Cvar_Register (&v_iyaw_cycle_cvar, 0, 0); + Cvar_Register (&v_iroll_cycle_cvar, 0, 0); + Cvar_Register (&v_ipitch_cycle_cvar, 0, 0); + Cvar_Register (&v_iyaw_level_cvar, 0, 0); + Cvar_Register (&v_iroll_level_cvar, 0, 0); + Cvar_Register (&v_ipitch_level_cvar, 0, 0); + Cvar_Register (&v_idlescale_cvar, 0, 0); - scr_ofsx = Cvar_Get ("scr_ofsx", "0", CVAR_NONE, NULL, "None"); - scr_ofsy = Cvar_Get ("scr_ofsy", "0", CVAR_NONE, NULL, "None"); - scr_ofsz = Cvar_Get ("scr_ofsz", "0", CVAR_NONE, NULL, "None"); - cl_rollspeed = Cvar_Get ("cl_rollspeed", "200", CVAR_NONE, NULL, - "How quickly you straighten out after strafing"); - cl_rollangle = Cvar_Get ("cl_rollangle", "2.0", CVAR_NONE, NULL, - "How much your screen tilts when strafing"); - cl_bob = Cvar_Get ("cl_bob", "0.02", CVAR_NONE, NULL, - "How much your weapon moves up and down when walking"); - cl_bobcycle = Cvar_Get ("cl_bobcycle", "0.6", CVAR_NONE, NULL, - "How quickly your weapon moves up and down when " - "walking"); - cl_bobup = Cvar_Get ("cl_bobup", "0.5", CVAR_NONE, NULL, - "How long your weapon stays up before cycling when " - "walking"); - v_kicktime = Cvar_Get ("v_kicktime", "0.5", CVAR_NONE, NULL, - "How long the kick from an attack lasts"); - v_kickroll = Cvar_Get ("v_kickroll", "0.6", CVAR_NONE, NULL, - "How much you lean when hit"); - v_kickpitch = Cvar_Get ("v_kickpitch", "0.6", CVAR_NONE, NULL, - "How much you look up when hit"); - cl_cshift_bonus = Cvar_Get ("cl_cshift_bonus", "1", CVAR_ARCHIVE, NULL, - "Show bonus flash on item pickup"); - cl_cshift_contents = Cvar_Get ("cl_cshift_content", "1", CVAR_ARCHIVE, - NULL, "Shift view colors for contents " - "(water, slime, etc)"); - cl_cshift_damage = Cvar_Get ("cl_cshift_damage", "1", CVAR_ARCHIVE, NULL, - "Shift view colors on damage"); - cl_cshift_powerup = Cvar_Get ("cl_cshift_powerup", "1", CVAR_ARCHIVE, NULL, - "Shift view colors for powerups"); + Cvar_Register (&scr_ofsx_cvar, 0, 0); + Cvar_Register (&scr_ofsy_cvar, 0, 0); + Cvar_Register (&scr_ofsz_cvar, 0, 0); + Cvar_Register (&cl_rollspeed_cvar, 0, 0); + Cvar_Register (&cl_rollangle_cvar, 0, 0); + Cvar_Register (&cl_bob_cvar, 0, 0); + Cvar_Register (&cl_bobcycle_cvar, 0, 0); + Cvar_Register (&cl_bobup_cvar, 0, 0); + Cvar_Register (&v_kicktime_cvar, 0, 0); + Cvar_Register (&v_kickroll_cvar, 0, 0); + Cvar_Register (&v_kickpitch_cvar, 0, 0); + Cvar_Register (&cl_cshift_bonus_cvar, 0, 0); + Cvar_Register (&cl_cshift_contents_cvar, 0, 0); + Cvar_Register (&cl_cshift_damage_cvar, 0, 0); + Cvar_Register (&cl_cshift_powerup_cvar, 0, 0); } diff --git a/libs/client/hud.c b/libs/client/hud.c index 2d8f880ed..5011b3a6e 100644 --- a/libs/client/hud.c +++ b/libs/client/hud.c @@ -29,8 +29,162 @@ # include "config.h" #endif -#include "QF/cvar.h" +#include -cvar_t *hud_sbar; -cvar_t *hud_scoreboard_gravity; -cvar_t *hud_swap; +#include "QF/cvar.h" +#include "QF/screen.h" +#include "QF/render.h" +#include "QF/plugin/vid_render.h" +#include "QF/ui/view.h" + +#include "compat.h" + +#include "client/hud.h" + +int hud_sb_lines; + +int hud_sbar; +static cvar_t hud_sbar_cvar = { + .name = "hud_sbar", + .description = + "status bar mode: 0 = hud, 1 = oldstyle", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &hud_sbar }, +}; +char *hud_scoreboard_gravity; +static cvar_t hud_scoreboard_gravity_cvar = { + .name = "hud_scoreboard_gravity", + .description = + "control placement of scoreboard overlay: center, northwest, north, " + "northeast, west, east, southwest, south, southeast", + .default_value = "center", + .flags = CVAR_ARCHIVE, + .value = { .type = 0/* not used */, .value = &hud_scoreboard_gravity }, +}; +int hud_swap; +static cvar_t hud_swap_cvar = { + .name = "hud_swap", + .description = + "new HUD on left side?", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &hud_swap }, +}; + +view_t *sbar_view; +view_t *sbar_inventory_view; +view_t *sbar_frags_view; + +view_t *hud_view; +view_t *hud_inventory_view; +view_t *hud_armament_view; +view_t *hud_frags_view; + +view_t *hud_overlay_view; +view_t *hud_stuff_view; +view_t *hud_main_view; + +static void +hud_sbar_f (void *data, const cvar_t *cvar) +{ + HUD_Calc_sb_lines (*r_data->scr_viewsize); + SCR_SetBottomMargin (hud_sbar ? hud_sb_lines : 0); + if (hud_sbar) { + view_remove (hud_main_view, hud_main_view->children[0]); + view_insert (hud_main_view, sbar_view, 0); + } else { + view_remove (hud_main_view, hud_main_view->children[0]); + view_insert (hud_main_view, hud_view, 0); + } +} + +static void +hud_swap_f (void *data, const cvar_t *cvar) +{ + if (hud_swap) { + //FIXME why is this needed for nq but not for qw? + hud_armament_view->children[0]->gravity = grav_northwest; + hud_armament_view->children[1]->gravity = grav_southeast; + view_setgravity (hud_armament_view, grav_southwest); + view_setgravity (hud_stuff_view, grav_southeast); + } else { + //FIXME why is this needed for nq but not for qw? + hud_armament_view->children[0]->gravity = grav_northeast; + hud_armament_view->children[1]->gravity = grav_southwest; + view_setgravity (hud_armament_view, grav_southeast); + view_setgravity (hud_stuff_view, grav_southwest); + } + view_move (hud_armament_view, hud_armament_view->xpos, + hud_armament_view->ypos); + view_move (hud_stuff_view, hud_stuff_view->xpos, hud_stuff_view->ypos); +} + +static void +hud_scoreboard_gravity_f (void *data, const cvar_t *cvar) +{ + grav_t grav; + + if (strequal (hud_scoreboard_gravity, "center")) + grav = grav_center; + else if (strequal (hud_scoreboard_gravity, "northwest")) + grav = grav_northwest; + else if (strequal (hud_scoreboard_gravity, "north")) + grav = grav_north; + else if (strequal (hud_scoreboard_gravity, "northeast")) + grav = grav_northeast; + else if (strequal (hud_scoreboard_gravity, "west")) + grav = grav_west; + else if (strequal (hud_scoreboard_gravity, "east")) + grav = grav_east; + else if (strequal (hud_scoreboard_gravity, "southwest")) + grav = grav_southwest; + else if (strequal (hud_scoreboard_gravity, "south")) + grav = grav_south; + else if (strequal (hud_scoreboard_gravity, "southeast")) + grav = grav_southeast; + else + grav = grav_center; + view_setgravity (hud_overlay_view, grav); +} + +void +HUD_Init_Cvars (void) +{ + Cvar_Register (&hud_sbar_cvar, hud_sbar_f, 0); + Cvar_Register (&hud_swap_cvar, hud_swap_f, 0); + Cvar_Register (&hud_scoreboard_gravity_cvar, hud_scoreboard_gravity_f, 0); +} + +void +HUD_Calc_sb_lines (int view_size) +{ + int stuff_y; + + if (view_size >= 120) { + hud_sb_lines = 0; + stuff_y = 0; + } else if (view_size >= 110) { + hud_sb_lines = 24; + sbar_inventory_view->visible = 0; + hud_inventory_view->visible = 0; + hud_armament_view->visible = 0; + stuff_y = 32; + } else { + hud_sb_lines = 48; + sbar_inventory_view->visible = 1; + hud_inventory_view->visible = 1; + hud_armament_view->visible = 1; + stuff_y = 48; + } + if (hud_sb_lines) { + sbar_view->visible = 1; + hud_view->visible = 1; + view_resize (sbar_view, sbar_view->xlen, hud_sb_lines); + view_resize (hud_view, hud_view->xlen, hud_sb_lines); + } else { + sbar_view->visible = 0; + hud_view->visible = 0; + } + view_move (hud_stuff_view, hud_stuff_view->xpos, stuff_y); +} diff --git a/libs/console/client.c b/libs/console/client.c index 02f7d2f62..0c4970535 100644 --- a/libs/console/client.c +++ b/libs/console/client.c @@ -80,11 +80,79 @@ static old_console_t *con; static float con_cursorspeed = 4; -static cvar_t *con_notifytime; // seconds -static cvar_t *con_alpha; -static cvar_t *con_size; -static cvar_t *con_speed; -static cvar_t *cl_conmode; +static float con_notifytime; +static cvar_t con_notifytime_cvar = { + .name = "con_notifytime", + .description = + "How long in seconds messages are displayed on screen", + .default_value = "3", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &con_notifytime }, +}; +static float con_alpha; +static cvar_t con_alpha_cvar = { + .name = "con_alpha", + .description = + "alpha value for the console background", + .default_value = "0.6", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &con_alpha }, +}; +static float con_size; +static cvar_t con_size_cvar = { + .name = "con_size", + .description = + "Fraction of the screen the console covers when down", + .default_value = "0.5", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &con_size }, +}; +static float con_speed; +static cvar_t con_speed_cvar = { + .name = "con_speed", + .description = + "How quickly the console scrolls up or down", + .default_value = "300", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &con_speed }, +}; +static exprenum_t cl_conmode_enum; +static exprtype_t cl_conmode_type = { + .name = "cl_conmode", + .size = sizeof (int), + .data = &cl_conmode_enum, + .get_string = cexpr_enum_get_string, +}; +static int cl_exec_line_command (void *data, const char *line); +static int cl_exec_line_chat (void *data, const char *line); +static int cl_exec_line_rcon (void *data, const char *line); +static int (*cl_conmode_values[])(void *, const char *) = { + cl_exec_line_command, + cl_exec_line_chat, + cl_exec_line_rcon, +}; +static exprsym_t cl_conmode_symbols[] = { + {"command", &cl_conmode_type, cl_conmode_values + 0}, + {"chat", &cl_conmode_type, cl_conmode_values + 1}, + {"rcon", &cl_conmode_type, cl_conmode_values + 1}, + {} +}; +static exprtab_t cl_conmode_symtab = { + cl_conmode_symbols, +}; +static exprenum_t cl_conmode_enum = { + &cl_conmode_type, + &cl_conmode_symtab, +}; +static char *cl_conmode; +static cvar_t cl_conmode_cvar = { + .name = "cl_conmode", + .description = + "Set the console input mode (command, chat, rcon)", + .default_value = "command", + .flags = CVAR_ARCHIVE, + .value = { .type = &cl_conmode_type, .value = &cl_conmode }, +}; #define NUM_CON_TIMES 4 static float con_times[NUM_CON_TIMES]; // realtime time the line was generated @@ -313,22 +381,6 @@ cl_exec_line_rcon (void *data, const char *line) return 0; } -static void -cl_conmode_f (cvar_t *var) -{ - if (!strcmp (var->string, "command")) { - con_data.exec_line = cl_exec_line_command; - } else if (!strcmp (var->string, "chat")) { - con_data.exec_line = cl_exec_line_chat; - } else if (!strcmp (var->string, "rcon")) { - con_data.exec_line = cl_exec_line_rcon; - } else { - Sys_Printf ("mode must be one of \"command\", \"chat\" or \"rcon\"\n"); - Sys_Printf (" forcing \"command\"\n"); - Cvar_Set (var, "command"); - } -} - static void con_end_message (inputline_t *line) { @@ -588,8 +640,8 @@ draw_console (view_t *view) if (con_state == con_fullscreen) { alpha = 255; } else { - float y = r_data->vid->conview->ylen * con_size->value; - alpha = 255 * con_alpha->value * view->ylen / y; + float y = r_data->vid->conview->ylen * con_size; + alpha = 255 * con_alpha * view->ylen / y; alpha = min (alpha, 255); } // draw the background @@ -632,7 +684,7 @@ draw_notify (view_t *view) if (time == 0) continue; time = *con_data.realtime - time; - if (time > con_notifytime->value) + if (time > con_notifytime) continue; text = con->text + (i % con_totallines) * con_linewidth; @@ -655,7 +707,7 @@ setup_console (void) lines = 0; break; case con_active: - lines = r_data->vid->conview->ylen * bound (0.2, con_size->value, + lines = r_data->vid->conview->ylen * bound (0.2, con_size, 1); break; case con_fullscreen: @@ -663,12 +715,12 @@ setup_console (void) break; } - if (con_speed->value) { + if (con_speed) { if (lines < con_data.lines) { - con_data.lines -= max (0.2, con_speed->value) * *con_data.frametime; + con_data.lines -= max (0.2, con_speed) * *con_data.frametime; con_data.lines = max (con_data.lines, lines); } else if (lines > con_data.lines) { - con_data.lines += max (0.2, con_speed->value) * *con_data.frametime; + con_data.lines += max (0.2, con_speed) * *con_data.frametime; con_data.lines = min (con_data.lines, lines); } } else { @@ -843,19 +895,12 @@ C_Init (void) Menu_Init (); - con_notifytime = Cvar_Get ("con_notifytime", "3", CVAR_NONE, NULL, - "How long in seconds messages are displayed " - "on screen"); + Cvar_Register (&con_notifytime_cvar, 0, 0); - con_alpha = Cvar_Get ("con_alpha", "0.6", CVAR_ARCHIVE, NULL, - "alpha value for the console background"); - con_size = Cvar_Get ("con_size", "0.5", CVAR_ARCHIVE, NULL, - "Fraction of the screen the console covers when " - "down"); - con_speed = Cvar_Get ("con_speed", "300", CVAR_ARCHIVE, NULL, - "How quickly the console scrolls up or down"); - cl_conmode = Cvar_Get ("cl_conmode", "command", CVAR_ARCHIVE, cl_conmode_f, - "Set the console input mode (command, chat, rcon)"); + Cvar_Register (&con_alpha_cvar, 0, 0); + Cvar_Register (&con_size_cvar, 0, 0); + Cvar_Register (&con_speed_cvar, 0, 0); + Cvar_Register (&cl_conmode_cvar, 0, 0); con_debuglog = COM_CheckParm ("-condebug"); diff --git a/libs/console/console.c b/libs/console/console.c index b75884e71..36f137423 100644 --- a/libs/console/console.c +++ b/libs/console/console.c @@ -56,23 +56,31 @@ static U inputline_t *(*const create)(int, int, char) = Con_CreateInputLine; static U void (*const display)(const char **, int) = Con_DisplayList; #undef U -static cvar_t *con_interpreter; +static char *con_interpreter; +static cvar_t con_interpreter_cvar = { + .name = "con_interpreter", + .description = + "Interpreter for the interactive console", + .default_value = "id", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &con_interpreter }, +}; static sys_printf_t saved_sys_printf; static void -Con_Interp_f (cvar_t *var) +Con_Interp_f (void *data, const cvar_t *cvar) { cbuf_interpreter_t *interp; if (!con_module) return; - interp = Cmd_GetProvider(var->string); + interp = Cmd_GetProvider(con_interpreter); if (interp) { cbuf_t *new; - Sys_Printf ("Switching to interpreter '%s'\n", var->string); + Sys_Printf ("Switching to interpreter '%s'\n", con_interpreter); new = Cbuf_New (interp); @@ -83,7 +91,7 @@ Con_Interp_f (cvar_t *var) } con_module->data->console->cbuf = new; } else { - Sys_Printf ("Unknown interpreter '%s'\n", var->string); + Sys_Printf ("Unknown interpreter '%s'\n", con_interpreter); } } @@ -111,9 +119,7 @@ Con_Init (const char *plugin_name) } else { setvbuf (stdout, 0, _IOLBF, BUFSIZ); } - con_interpreter = - Cvar_Get("con_interpreter", "id", CVAR_NONE, Con_Interp_f, - "Interpreter for the interactive console"); + Cvar_Register (&con_interpreter_cvar, Con_Interp_f, 0); } VISIBLE void diff --git a/libs/console/menu.c b/libs/console/menu.c index 0e02d63e3..ef57dc8de 100644 --- a/libs/console/menu.c +++ b/libs/console/menu.c @@ -79,7 +79,15 @@ typedef struct menu_item_s { menu_pic_t *pics; } menu_item_t; -static cvar_t *confirm_quit; +static int confirm_quit; +static cvar_t confirm_quit_cvar = { + .name = "confirm_quit", + .description = + "confirm quit command", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &confirm_quit }, +}; static progs_t menu_pr_state; static menu_item_t *menu; @@ -482,7 +490,7 @@ quit_f (void) { int ret; - if (confirm_quit->int_val && menu_quit) { + if (confirm_quit && menu_quit) { run_menu_pre (); PR_ExecuteProgram (&menu_pr_state, menu_quit); ret = R_INT (&menu_pr_state); @@ -611,8 +619,7 @@ Menu_Init (void) R_Progs_Init (&menu_pr_state); S_Progs_Init (&menu_pr_state); - confirm_quit = Cvar_Get ("confirm_quit", "1", CVAR_ARCHIVE, NULL, - "confirm quit command"); + Cvar_Register (&confirm_quit_cvar, 0, 0); Cmd_AddCommand ("togglemenu", togglemenu_f, "Toggle the display of the menu"); diff --git a/libs/console/server.c b/libs/console/server.c index f553fa67a..3b10f64e6 100644 --- a/libs/console/server.c +++ b/libs/console/server.c @@ -82,8 +82,59 @@ static console_data_t sv_con_data; static QFile *log_file; -static cvar_t *sv_logfile; -static cvar_t *sv_conmode; +static char *sv_logfile; +static cvar_t sv_logfile_cvar = { + .name = "sv_logfile", + .description = + "Control server console logging. \"none\" for off, or " + "\"filename:gzflags\"", + .default_value = "none", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &sv_logfile }, +}; +static exprenum_t sv_conmode_enum; +static exprtype_t sv_conmode_type = { + .name = "sv_conmode", + .size = sizeof (int), + .data = &sv_conmode_enum, + .get_string = cexpr_enum_get_string, +}; +static int sv_exec_line_command (void *data, const char *line); +static int sv_exec_line_chat (void *data, const char *line); +static int (*sv_conmode_values[])(void *, const char *) = { + sv_exec_line_command, + sv_exec_line_chat, +}; +static exprsym_t sv_conmode_symbols[] = { + {"command", &sv_conmode_type, sv_conmode_values + 0}, + {"chat", &sv_conmode_type, sv_conmode_values + 1}, + {} +}; +static exprtab_t sv_conmode_symtab = { + sv_conmode_symbols, +}; +static exprenum_t sv_conmode_enum = { + &sv_conmode_type, + &sv_conmode_symtab, +}; +static char *sv_conmode; +static cvar_t sv_conmode_cvar = { + .name = "sv_conmode", + .description = + "Set the console input mode (command, chat)", + .default_value = "command", + .flags = CVAR_NONE, + .value = { .type = &sv_conmode_type, .value = &sv_conmode }, +}; +static int sv_use_curses; +static cvar_t sv_use_curses_cvar = { + .name = "sv_use_curses", + .description = + "Set to 1 to enable curses server console.", + .default_value = "0", + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &sv_use_curses }, +}; #ifdef HAVE_NCURSES @@ -631,14 +682,14 @@ init (void) #endif static void -sv_logfile_f (cvar_t *var) +sv_logfile_f (void *data, const cvar_t *cvar) { - if (!var->string[0] || strequal (var->string, "none")) { + if (!sv_logfile[0] || strequal (sv_logfile, "none")) { if (log_file) Qclose (log_file); log_file = 0; } else { - char *fname = strdup (var->string); + char *fname = strdup (sv_logfile); char *flags = strrchr (fname, ':'); if (flags) { @@ -670,37 +721,19 @@ sv_exec_line_chat (void *data, const char *line) return 0; } -static void -sv_conmode_f (cvar_t *var) -{ - if (!strcmp (var->string, "command")) { - sv_con_data.exec_line = sv_exec_line_command; - } else if (!strcmp (var->string, "chat")) { - sv_con_data.exec_line = sv_exec_line_chat; - } else { - Sys_Printf ("mode must be one of \"command\" or \"chat\"\n"); - Sys_Printf (" forcing \"command\"\n"); - Cvar_Set (var, "command"); - } -} - static void C_Init (void) { + Cvar_Register (&sv_use_curses_cvar, 0, 0); #ifdef HAVE_NCURSES - cvar_t *curses = Cvar_Get ("sv_use_curses", "0", CVAR_ROM, NULL, - "Set to 1 to enable curses server console."); - use_curses = curses->int_val; + use_curses = sv_use_curses; if (use_curses) { init (); } else #endif setvbuf (stdout, 0, _IOLBF, BUFSIZ); - sv_logfile = Cvar_Get ("sv_logfile", "none", CVAR_NONE, sv_logfile_f, - "Control server console logging. \"none\" for off, " - "or \"filename:gzflags\""); - sv_conmode = Cvar_Get ("sv_conmode", "command", CVAR_NONE, sv_conmode_f, - "Set the console input mode (command, chat)"); + Cvar_Register (&sv_logfile_cvar, sv_logfile_f, 0); + Cvar_Register (&sv_conmode_cvar, 0, 0); } static void diff --git a/libs/gamecode/pr_debug.c b/libs/gamecode/pr_debug.c index 61016e371..101bb92dc 100644 --- a/libs/gamecode/pr_debug.c +++ b/libs/gamecode/pr_debug.c @@ -117,8 +117,24 @@ typedef struct { dstring_t *dstr; } pr_debug_data_t; -cvar_t *pr_debug; -cvar_t *pr_source_path; +int pr_debug; +static cvar_t pr_debug_cvar = { + .name = "pr_debug", + .description = + "enable progs debugging", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &pr_debug }, +}; +char *pr_source_path; +static cvar_t pr_source_path_cvar = { + .name = "pr_source_path", + .description = + "where to look (within gamedir) for source files", + .default_value = ".", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &pr_source_path }, +}; static char *source_path_string; static char **source_paths; @@ -182,7 +198,7 @@ compunit_get_key (const void *cu, void *p) } static void -source_path_f (cvar_t *var) +source_path_f (void *data, const cvar_t *cvar) { int i; char *s; @@ -190,7 +206,7 @@ source_path_f (cvar_t *var) if (source_path_string) { free (source_path_string); } - source_path_string = strdup (var->string); + source_path_string = strdup (pr_source_path); if (source_paths) { free (source_paths); } @@ -587,7 +603,7 @@ PR_LoadDebug (progs_t *pr) res->debug = 0; - if (!pr_debug->int_val) + if (!pr_debug) return 1; def = PR_FindGlobal (pr, ".debug_file"); @@ -976,7 +992,7 @@ PR_DumpState (progs_t *pr) { prdeb_resources_t *res = pr->pr_debug_resources; if (pr->pr_xfunction) { - if (pr_debug->int_val && res->debug) { + if (pr_debug && res->debug) { pr_lineno_t *lineno; pr_auxfunction_t *func = 0; dfunction_t *descriptor = pr->pr_xfunction->descriptor; @@ -1045,7 +1061,7 @@ pr_debug_find_def (progs_t *pr, pr_ptr_t *ofs) prdeb_resources_t *res = pr->pr_debug_resources; pr_def_t *def = 0; - if (pr_debug->int_val && res->debug) { + if (pr_debug && res->debug) { def = PR_Get_Local_Def (pr, ofs); } if (*ofs >= pr->progs->globals.count) { @@ -1486,10 +1502,10 @@ PR_PrintStatement (progs_t *pr, dstatement_t *s, int contents) data.pr = pr; data.dstr = res->dstr; - if (pr_debug->int_val > 1) + if (pr_debug > 1) dump_code = 1; - if (pr_debug->int_val && res->debug) { + if (pr_debug && res->debug) { const char *source_line = PR_Get_Source_Line (pr, addr); if (source_line) { @@ -1528,7 +1544,7 @@ PR_PrintStatement (progs_t *pr, dstatement_t *s, int contents) } dasprintf (res->line, "%04x ", addr); - if (pr_debug->int_val > 2) { + if (pr_debug > 2) { if (pr->progs->version < PROG_VERSION) { dasprintf (res->line, "%03x %04x(%8s) %04x(%8s) %04x(%8s)\t", @@ -1741,7 +1757,7 @@ dump_frame (progs_t *pr, prstack_t *frame) Sys_Printf ("\n"); return; } - if (pr_debug->int_val && res->debug) { + if (pr_debug && res->debug) { pr_lineno_t *lineno = PR_Find_Lineno (pr, frame->staddr); pr_auxfunction_t *func = PR_Get_Lineno_Func (pr, lineno); pr_uint_t line = PR_Get_Lineno_Line (pr, lineno); @@ -1932,9 +1948,6 @@ PR_Debug_Init (progs_t *pr) void PR_Debug_Init_Cvars (void) { - pr_debug = Cvar_Get ("pr_debug", "0", CVAR_NONE, NULL, - "enable progs debugging"); - pr_source_path = Cvar_Get ("pr_source_path", ".", CVAR_NONE, source_path_f, - "where to look (within gamedir) for source " - "files"); + Cvar_Register (&pr_debug_cvar, 0, 0); + Cvar_Register (&pr_source_path_cvar, source_path_f, 0); } diff --git a/libs/gamecode/pr_edict.c b/libs/gamecode/pr_edict.c index 34c132b20..174c61ab0 100644 --- a/libs/gamecode/pr_edict.c +++ b/libs/gamecode/pr_edict.c @@ -114,7 +114,7 @@ ED_Free (progs_t *pr, edict_t *ed) if (pr->unlink) pr->unlink (ed); // unlink from world bsp - if (pr_deadbeef_ents->int_val) { + if (pr_deadbeef_ents) { ED_ClearEdict (pr, ed, 0xdeadbeef); } else { if (pr->free_edict) diff --git a/libs/gamecode/pr_exec.c b/libs/gamecode/pr_exec.c index 0138ef7c3..a7d4fbac7 100644 --- a/libs/gamecode/pr_exec.c +++ b/libs/gamecode/pr_exec.c @@ -284,7 +284,7 @@ PR_EnterFunction (progs_t *pr, bfunction_t *f) sizeof (pr_type_t) * f->locals); pr->localstack_used += f->locals; - if (pr_deadbeef_locals->int_val) { + if (pr_deadbeef_locals) { for (pr_uint_t i = f->params_start; i < f->params_start + f->locals; i++) { pr->pr_globals[i].int_var = 0xdeadbeef; @@ -357,7 +357,7 @@ PR_BoundsCheckSize (progs_t *pr, pr_ptr_t addr, unsigned size) || size > (unsigned) (pr->globals_size - addr)) PR_RunError (pr, "invalid memory access: %d (0 to %d-%d)", addr, pr->globals_size, size); - if (pr_boundscheck->int_val >= 2 + if (pr_boundscheck >= 2 && PR_GetPointer (pr, addr + size) > (pr_type_t *) pr->zone) { void *mem = (void *) PR_GetPointer (pr, addr); Z_CheckPointer (pr->zone, mem, size * sizeof (pr_type_t)); @@ -385,7 +385,7 @@ signal_hook (int sig, void *data) { progs_t *pr = (progs_t *) data; - if (sig == SIGFPE && pr_faultchecks->int_val) { + if (sig == SIGFPE && pr_faultchecks) { dstatement_t *st; pr_type_t *op_a, *op_b, *op_c; @@ -501,7 +501,7 @@ PR_SetupParams (progs_t *pr, int num_params, int min_alignment) } pr_ptr_t mask = ~(min_alignment - 1); pr_ptr_t stack = (*pr->globals.stack - offset) & mask; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { check_stack_pointer (pr, stack, 0); } *pr->globals.stack = stack; @@ -835,7 +835,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) case OP_STOREP_I_v6p: case OP_STOREP_P_v6p: pointer = OPB(ptr); - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { PR_BoundsCheck (pr, pointer, ev_int); } ptr = pr->pr_globals + pointer; @@ -843,7 +843,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) break; case OP_STOREP_V_v6p: pointer = OPB(ptr); - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { PR_BoundsCheck (pr, pointer, ev_vector); } ptr = pr->pr_globals + pointer; @@ -851,7 +851,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) break; case OP_STOREP_Q_v6p: pointer = OPB(ptr); - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { PR_BoundsCheck (pr, pointer, ev_quaternion); } ptr = pr->pr_globals + pointer; @@ -859,7 +859,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) break; case OP_STOREP_D_v6p: pointer = OPB(ptr); - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { PR_BoundsCheck (pr, pointer, ev_double); } ptr = pr->pr_globals + pointer; @@ -867,7 +867,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) break; case OP_ADDRESS_v6p: - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { if (OPA(entity) >= pr->pr_edict_area_size) PR_RunError (pr, "Progs attempted to address an out " "of bounds edict"); @@ -901,7 +901,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) case OP_LOAD_FN_v6p: case OP_LOAD_I_v6p: case OP_LOAD_P_v6p: - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { if (OPA(entity) >= pr->pr_edict_area_size) PR_RunError (pr, "Progs attempted to read an out of " "bounds edict number"); @@ -913,7 +913,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) OPC(int) = pr->pr_edict_area[fldofs].int_var; break; case OP_LOAD_V_v6p: - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { if (OPA(entity) >= pr->pr_edict_area_size) PR_RunError (pr, "Progs attempted to read an out of " "bounds edict number"); @@ -925,7 +925,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) memcpy (op_c, &pr->pr_edict_area[fldofs], 3 * sizeof (*op_c)); break; case OP_LOAD_Q_v6p: - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { if (OPA(entity) >= pr->pr_edict_area_size) PR_RunError (pr, "Progs attempted to read an out of " "bounds edict number"); @@ -937,7 +937,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) memcpy (op_c, &pr->pr_edict_area[fldofs], 4 * sizeof (*op_c)); break; case OP_LOAD_D_v6p: - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { if (OPA(entity) >= pr->pr_edict_area_size) PR_RunError (pr, "Progs attempted to read an out of " "bounds edict number"); @@ -957,7 +957,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) case OP_LOADB_I_v6p: case OP_LOADB_P_v6p: pointer = OPA(entity) + OPB(field); - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { PR_BoundsCheck (pr, pointer, ev_int); } ptr = pr->pr_globals + pointer; @@ -965,7 +965,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) break; case OP_LOADB_V_v6p: pointer = OPA(entity) + OPB(field); - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { PR_BoundsCheck (pr, pointer, ev_vector); } ptr = pr->pr_globals + pointer; @@ -973,7 +973,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) break; case OP_LOADB_Q_v6p: pointer = OPA(entity) + OPB(field); - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { PR_BoundsCheck (pr, pointer, ev_quaternion); } ptr = pr->pr_globals + pointer; @@ -981,7 +981,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) break; case OP_LOADB_D_v6p: pointer = OPA(entity) + OPB(field); - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { PR_BoundsCheck (pr, pointer, ev_double); } ptr = pr->pr_globals + pointer; @@ -996,7 +996,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) case OP_LOADBI_I_v6p: case OP_LOADBI_P_v6p: pointer = OPA(ptr) + (short) st->b; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { PR_BoundsCheck (pr, pointer, ev_int); } ptr = pr->pr_globals + pointer; @@ -1004,7 +1004,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) break; case OP_LOADBI_V_v6p: pointer = OPA(ptr) + (short) st->b; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { PR_BoundsCheck (pr, pointer, ev_vector); } ptr = pr->pr_globals + pointer; @@ -1012,7 +1012,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) break; case OP_LOADBI_Q_v6p: pointer = OPA(ptr) + (short) st->b; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { PR_BoundsCheck (pr, pointer, ev_quaternion); } ptr = pr->pr_globals + pointer; @@ -1020,7 +1020,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) break; case OP_LOADBI_D_v6p: pointer = OPA(ptr) + (short) st->b; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { PR_BoundsCheck (pr, pointer, ev_quaternion); } ptr = pr->pr_globals + pointer; @@ -1045,7 +1045,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) case OP_STOREB_I_v6p: case OP_STOREB_P_v6p: pointer = OPB(ptr) + OPC(int); - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { PR_BoundsCheck (pr, pointer, ev_int); } ptr = pr->pr_globals + pointer; @@ -1053,7 +1053,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) break; case OP_STOREB_V_v6p: pointer = OPB(ptr) + OPC(int); - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { PR_BoundsCheck (pr, pointer, ev_vector); } ptr = pr->pr_globals + pointer; @@ -1061,7 +1061,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) break; case OP_STOREB_Q_v6p: pointer = OPB(ptr) + OPC(int); - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { PR_BoundsCheck (pr, pointer, ev_quaternion); } ptr = pr->pr_globals + pointer; @@ -1069,7 +1069,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) break; case OP_STOREB_D_v6p: pointer = OPB(ptr) + OPC(int); - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { PR_BoundsCheck (pr, pointer, ev_quaternion); } ptr = pr->pr_globals + pointer; @@ -1084,7 +1084,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) case OP_STOREBI_I_v6p: case OP_STOREBI_P_v6p: pointer = OPB(ptr) + (short) st->c; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { PR_BoundsCheck (pr, pointer, ev_int); } ptr = pr->pr_globals + pointer; @@ -1092,7 +1092,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) break; case OP_STOREBI_V_v6p: pointer = OPB(ptr) + (short) st->c; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { PR_BoundsCheck (pr, pointer, ev_vector); } ptr = pr->pr_globals + pointer; @@ -1100,7 +1100,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) break; case OP_STOREBI_Q_v6p: pointer = OPB(ptr) + (short) st->c; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { PR_BoundsCheck (pr, pointer, ev_quaternion); } ptr = pr->pr_globals + pointer; @@ -1108,7 +1108,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) break; case OP_STOREBI_D_v6p: pointer = OPB(ptr) + (short) st->c; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { PR_BoundsCheck (pr, pointer, ev_quaternion); } ptr = pr->pr_globals + pointer; @@ -1125,7 +1125,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) { pr_ptr_t stack = *pr->globals.stack - 1; pr_type_t *stk = pr->pr_globals + stack; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { check_stack_pointer (pr, stack, 1); } stk->int_var = OPA(int); @@ -1136,7 +1136,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) { pr_ptr_t stack = *pr->globals.stack - 3; pr_type_t *stk = pr->pr_globals + stack; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { check_stack_pointer (pr, stack, 3); } memcpy (stk, op_a, 3 * sizeof (*op_c)); @@ -1147,7 +1147,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) { pr_ptr_t stack = *pr->globals.stack - 4; pr_type_t *stk = pr->pr_globals + stack; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { check_stack_pointer (pr, stack, 4); } memcpy (stk, op_a, 4 * sizeof (*op_c)); @@ -1169,7 +1169,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) pointer = OPA(ptr) + OPB(int); ptr = pr->pr_globals + pointer; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { check_stack_pointer (pr, stack, 1); PR_BoundsCheck (pr, pointer, ev_int); } @@ -1186,7 +1186,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) pointer = OPA(ptr) + OPB(int); ptr = pr->pr_globals + pointer; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { check_stack_pointer (pr, stack, 3); PR_BoundsCheck (pr, pointer, ev_int); } @@ -1203,7 +1203,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) pointer = OPA(ptr) + OPB(int); ptr = pr->pr_globals + pointer; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { check_stack_pointer (pr, stack, 4); PR_BoundsCheck (pr, pointer, ev_quaternion); } @@ -1227,7 +1227,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) pointer = OPA(ptr) + st->b; ptr = pr->pr_globals + pointer; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { check_stack_pointer (pr, stack, 1); PR_BoundsCheck (pr, pointer, ev_int); } @@ -1244,7 +1244,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) pointer = OPA(ptr) + st->b; ptr = pr->pr_globals + pointer; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { check_stack_pointer (pr, stack, 3); PR_BoundsCheck (pr, pointer, ev_int); } @@ -1261,7 +1261,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) pointer = OPA(ptr) + st->b; ptr = pr->pr_globals + pointer; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { check_stack_pointer (pr, stack, 4); PR_BoundsCheck (pr, pointer, ev_quaternion); } @@ -1281,7 +1281,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) { pr_ptr_t stack = *pr->globals.stack; pr_type_t *stk = pr->pr_globals + stack; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { check_stack_pointer (pr, stack, 1); } OPA(int) = stk->int_var; @@ -1292,7 +1292,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) { pr_ptr_t stack = *pr->globals.stack; pr_type_t *stk = pr->pr_globals + stack; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { check_stack_pointer (pr, stack, 3); } memcpy (op_a, stk, 3 * sizeof (*op_c)); @@ -1303,7 +1303,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) { pr_ptr_t stack = *pr->globals.stack; pr_type_t *stk = pr->pr_globals + stack; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { check_stack_pointer (pr, stack, 4); } memcpy (op_a, stk, 4 * sizeof (*op_c)); @@ -1325,7 +1325,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) pointer = OPA(ptr) + OPB(int); ptr = pr->pr_globals + pointer; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { check_stack_pointer (pr, stack, 1); PR_BoundsCheck (pr, pointer, ev_int); } @@ -1342,7 +1342,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) pointer = OPA(ptr) + OPB(int); ptr = pr->pr_globals + pointer; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { check_stack_pointer (pr, stack, 3); PR_BoundsCheck (pr, pointer, ev_int); } @@ -1359,7 +1359,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) pointer = OPA(ptr) + OPB(int); ptr = pr->pr_globals + pointer; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { check_stack_pointer (pr, stack, 4); PR_BoundsCheck (pr, pointer, ev_quaternion); } @@ -1383,7 +1383,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) pointer = OPA(ptr) + st->b; ptr = pr->pr_globals + pointer; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { check_stack_pointer (pr, stack, 1); PR_BoundsCheck (pr, pointer, ev_int); } @@ -1400,7 +1400,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) pointer = OPA(ptr) + st->b; ptr = pr->pr_globals + pointer; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { check_stack_pointer (pr, stack, 3); PR_BoundsCheck (pr, pointer, ev_int); } @@ -1417,7 +1417,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) pointer = OPA(ptr) + st->b; ptr = pr->pr_globals + pointer; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { check_stack_pointer (pr, stack, 4); PR_BoundsCheck (pr, pointer, ev_quaternion); } @@ -1469,7 +1469,7 @@ pr_exec_quakec (progs_t *pr, int exitdepth) st = pr->pr_statements + pr->pr_xstatement; break; case OP_JUMP_v6p: - if (pr_boundscheck->int_val + if (pr_boundscheck && (OPA(uint) >= pr->progs->statements.count)) { PR_RunError (pr, "Invalid jump destination"); } @@ -1478,12 +1478,12 @@ pr_exec_quakec (progs_t *pr, int exitdepth) break; case OP_JUMPB_v6p: pointer = st->a + OPB(int); - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { PR_BoundsCheck (pr, pointer, ev_int); } ptr = pr->pr_globals + pointer; pointer = ptr->int_var; - if (pr_boundscheck->int_val + if (pr_boundscheck && (pointer >= pr->progs->statements.count)) { PR_RunError (pr, "Invalid jump destination"); } @@ -1701,7 +1701,7 @@ op_call: memmove (op_c, op_a, st->b * 4); break; case OP_MOVEP_v6p: - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { PR_BoundsCheckSize (pr, OPC(ptr), OPB(uint)); PR_BoundsCheckSize (pr, OPA(ptr), OPB(uint)); } @@ -1710,7 +1710,7 @@ op_call: OPB(uint) * 4); break; case OP_MOVEPI_v6p: - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { PR_BoundsCheckSize (pr, OPC(ptr), st->b); PR_BoundsCheckSize (pr, OPA(ptr), st->b); } @@ -1722,14 +1722,14 @@ op_call: pr_memset (op_c, OPA(ptr), st->b); break; case OP_MEMSETP_v6p: - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { PR_BoundsCheckSize (pr, OPC(ptr), OPB(uint)); } pr_memset (pr->pr_globals + OPC(ptr), OPA(int), OPB(uint)); break; case OP_MEMSETPI_v6p: - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { PR_BoundsCheckSize (pr, OPC(ptr), st->b); } pr_memset (pr->pr_globals + OPC(ptr), OPA(int), @@ -1888,7 +1888,7 @@ pr_jump_mode (progs_t *pr, const dstatement_t *st, int jump_ind) jump_offs = OPA(ptr) + OPB(int); break; } - if (pr_boundscheck->int_val && jump_offs >= pr->progs->statements.count) { + if (pr_boundscheck && jump_offs >= pr->progs->statements.count) { PR_RunError (pr, "out of bounds: %x", jump_offs); } return jump_offs - 1; // for st++ @@ -1900,7 +1900,7 @@ pr_stack_push (progs_t *pr) // keep the stack 16-byte aligned pr_ptr_t stack = *pr->globals.stack - 4; pr_type_t *stk = pr->pr_globals + stack; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { check_stack_pointer (pr, stack, 4); } *pr->globals.stack = stack; @@ -1912,7 +1912,7 @@ pr_stack_pop (progs_t *pr) { pr_ptr_t stack = *pr->globals.stack; pr_type_t *stk = pr->pr_globals + stack; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { check_stack_pointer (pr, stack, 4); } // keep the stack 16-byte aligned @@ -1929,7 +1929,7 @@ pr_stack_adjust (progs_t *pr, int mode, int offset) } pr_ptr_t stack = *pr->globals.stack; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { check_stack_pointer (pr, stack + offset, 0); } *pr->globals.stack = stack + offset; diff --git a/libs/gamecode/pr_load.c b/libs/gamecode/pr_load.c index 492d65bd7..eabbaa8b9 100644 --- a/libs/gamecode/pr_load.c +++ b/libs/gamecode/pr_load.c @@ -50,10 +50,42 @@ #include "compat.h" -VISIBLE cvar_t *pr_boundscheck; -cvar_t *pr_deadbeef_ents; -cvar_t *pr_deadbeef_locals; -cvar_t *pr_faultchecks; +VISIBLE int pr_boundscheck; +static cvar_t pr_boundscheck_cvar = { + .name = "pr_boundscheck", + .description = + "Server progs bounds checking", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &pr_boundscheck }, +}; +int pr_deadbeef_ents; +static cvar_t pr_deadbeef_ents_cvar = { + .name = "pr_deadbeef_ents", + .description = + "set to clear unallocated memory to 0xdeadbeef", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &pr_deadbeef_ents }, +}; +int pr_deadbeef_locals; +static cvar_t pr_deadbeef_locals_cvar = { + .name = "pr_deadbeef_locals", + .description = + "set to clear uninitialized local vars to 0xdeadbeef", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &pr_deadbeef_locals }, +}; +int pr_faultchecks; +static cvar_t pr_faultchecks_cvar = { + .name = "pr_faultchecks", + .description = + "capture and handle division by 0 in progs", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &pr_faultchecks }, +}; static const char * function_get_key (const void *f, void *_pr) @@ -498,16 +530,10 @@ PR_LoadProgs (progs_t *pr, const char *progsname) VISIBLE void PR_Init_Cvars (void) { - pr_boundscheck = - Cvar_Get ("pr_boundscheck", "0", CVAR_NONE, NULL, - "Server progs bounds checking"); - pr_deadbeef_ents = Cvar_Get ("pr_deadbeef_ents", "0", CVAR_NONE, NULL, - "set to clear unallocated memory to 0xdeadbeef"); - pr_deadbeef_locals = Cvar_Get ("pr_deadbeef_locals", "0", CVAR_NONE, NULL, - "set to clear uninitialized local vars to " - "0xdeadbeef"); - pr_faultchecks = Cvar_Get ("pr_faultchecks", "0", CVAR_NONE, NULL, - "capture and handle division by 0 in progs"); + Cvar_Register (&pr_boundscheck_cvar, 0, 0); + Cvar_Register (&pr_deadbeef_ents_cvar, 0, 0); + Cvar_Register (&pr_deadbeef_locals_cvar, 0, 0); + Cvar_Register (&pr_faultchecks_cvar, 0, 0); PR_Debug_Init_Cvars (); } diff --git a/libs/gamecode/pr_v6p_opcode.c b/libs/gamecode/pr_v6p_opcode.c index dd609ad12..2f57d1ad4 100644 --- a/libs/gamecode/pr_v6p_opcode.c +++ b/libs/gamecode/pr_v6p_opcode.c @@ -1562,7 +1562,7 @@ check_global (progs_t *pr, dstatement_t *st, const v6p_opcode_t *op, etype_t typ } if (!pr->denorm_found) { pr->denorm_found = 1; - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { Sys_Printf ("DENORMAL floats detected, these progs might " "not work. Good luck.\n"); return; @@ -1619,7 +1619,7 @@ PR_Check_v6p_Opcodes (progs_t *pr) //FIXME need to decide if I really want to always do static bounds checking // the only problem is that it slows progs load a little, but it's the only // way to check for qccx' evil - if (0 && !pr_boundscheck->int_val) { + if (0 && !pr_boundscheck) { for (i = 0, st = pr->pr_statements; i < pr->progs->statements.count; st++, i++) { pr_opcode_v6p_e st_op = (pr_opcode_v6p_e) st->op; diff --git a/libs/gamecode/test/main.c b/libs/gamecode/test/main.c index b2fdd45c8..4c8299e17 100644 --- a/libs/gamecode/test/main.c +++ b/libs/gamecode/test/main.c @@ -201,7 +201,7 @@ main (int argc, char **argv) Cmd_Init (); Cvar_Init (); PR_Init_Cvars (); - pr_boundscheck->int_val = 1; + pr_boundscheck = 1; while ((c = getopt (argc, argv, "qvt:")) != EOF) { switch (c) { diff --git a/libs/gib/gib_init.c b/libs/gib/gib_init.c index 9b20c61f8..a50df21c3 100644 --- a/libs/gib/gib_init.c +++ b/libs/gib/gib_init.c @@ -76,8 +76,8 @@ GIB_Exec_Override_f (void) return; } if (!Cvar_Command () - && (cmd_warncmd->int_val - || (developer && developer->int_val & SYS_dev))) + && (cmd_warncmd + || (developer && developer & SYS_dev))) Sys_Printf ("execing %s\n", Cmd_Argv (1)); if ((strlen (Cmd_Argv (1)) >= 4 && !strcmp (Cmd_Argv (1) + strlen (Cmd_Argv (1)) - 4, ".gib")) diff --git a/libs/gib/gib_process.c b/libs/gib/gib_process.c index 7492c8a91..182b92294 100644 --- a/libs/gib/gib_process.c +++ b/libs/gib/gib_process.c @@ -114,7 +114,8 @@ GIB_Process_Embedded (gib_tree_t * node, cbuf_args_t * args) } else if (cur->delim == '#') dstring_appendstr (args->argv[args->argc - 1], "0"); else if (cvar) - dstring_appendstr (args->argv[args->argc - 1], cvar->string); + dstring_appendstr (args->argv[args->argc - 1], + Cvar_VarString (cvar)); } else if ((var = GIB_Var_Get_Complex (&GIB_DATA (cbuf_active)->locals, &GIB_DATA (cbuf_active)->globals, (char *) cur->str, &index, false))) { @@ -126,7 +127,8 @@ GIB_Process_Embedded (gib_tree_t * node, cbuf_args_t * args) } else if (cur->delim == '#') dstring_appendstr (args->argv[args->argc - 1], "0"); else if ((cvar = Cvar_FindVar (cur->str))) - dstring_appendstr (args->argv[args->argc - 1], cvar->string); + dstring_appendstr (args->argv[args->argc - 1], + Cvar_VarString (cvar)); } if (str[prev]) dstring_appendstr (args->argv[args->argc - 1], str + prev); diff --git a/libs/gib/gib_vars.c b/libs/gib/gib_vars.c index 27adc7f4a..b03d53402 100644 --- a/libs/gib/gib_vars.c +++ b/libs/gib/gib_vars.c @@ -222,9 +222,11 @@ GIB_Var_Get_Very_Complex (hashtab_t ** first, hashtab_t ** second, dstring_t *ke dstring_replace (key, n, i-n+varstartskip, "0", 1); protect = n+1; } else if ((cvar = Cvar_FindVar (key->str+n+1+varstartskip))) { + const char *cvar_str = Cvar_VarString (cvar); key->str[i] = c; - dstring_replace (key, n, i-n+varstartskip, cvar->string, strlen (cvar->string)); - protect = n+strlen(cvar->string); + dstring_replace (key, n, i-n+varstartskip, cvar_str, + strlen (cvar_str)); + protect = n+strlen(cvar_str); } else { key->str[i] = c; dstring_snip (key, n, n-i+varstartskip); diff --git a/libs/input/in_common.c b/libs/input/in_common.c index ad69ee3a4..de8e22a68 100644 --- a/libs/input/in_common.c +++ b/libs/input/in_common.c @@ -70,14 +70,79 @@ typedef struct { static struct DARRAY_TYPE (in_regdriver_t) in_drivers = { .grow = 8 }; static struct DARRAY_TYPE (in_device_t) in_devices = { .grow = 8 }; -cvar_t *in_grab; -VISIBLE cvar_t *in_amp; -VISIBLE cvar_t *in_pre_amp; -cvar_t *in_freelook; -cvar_t *in_mouse_filter; -cvar_t *in_mouse_amp; -cvar_t *in_mouse_pre_amp; -cvar_t *lookstrafe; +int in_grab; +static cvar_t in_grab_cvar = { + .name = "in_grab", + .description = + "With this set to 1, quake will grab the mouse, preventing loss of " + "input focus.", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &in_grab }, +}; +VISIBLE float in_amp; +static cvar_t in_amp_cvar = { + .name = "in_amp", + .description = + "global in_amp multiplier", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &in_amp }, +}; +VISIBLE float in_pre_amp; +static cvar_t in_pre_amp_cvar = { + .name = "in_pre_amp", + .description = + "global in_pre_amp multiplier", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &in_pre_amp }, +}; +int in_freelook; +static cvar_t in_freelook_cvar = { + .name = "freelook", + .description = + "force +mlook", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &in_freelook }, +}; +char *in_mouse_filter; +static cvar_t in_mouse_filter_cvar = { + .name = "in_mouse_filter", + .description = + "Toggle mouse input filtering.", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = 0/* not used */, .value = &in_mouse_filter }, +}; +char *in_mouse_amp; +static cvar_t in_mouse_amp_cvar = { + .name = "in_mouse_amp", + .description = + "mouse in_mouse_amp multiplier", + .default_value = "15", + .flags = CVAR_ARCHIVE, + .value = { .type = 0/* not used */, .value = &in_mouse_amp }, +}; +char *in_mouse_pre_amp; +static cvar_t in_mouse_pre_amp_cvar = { + .name = "in_mouse_pre_amp", + .description = + "mouse in_mouse_pre_amp multiplier", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = 0/* not used */, .value = &in_mouse_pre_amp }, +}; +char *lookstrafe; +static cvar_t lookstrafe_cvar = { + .name = "lookstrafe", + .description = + "when mlook/klook on player will strafe", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = 0/* not used */, .value = &lookstrafe }, +}; int64_t in_timeout = 10000;//10ms default timeout @@ -395,18 +460,22 @@ IN_GetButtonInfo (int devid, int button_num, in_buttoninfo_t *info) } void -IN_UpdateGrab (cvar_t *var) // called from context_*.c +IN_UpdateGrab (int grab) { - if (var) { - for (size_t i = 0; i < in_drivers.size; i++) { - in_regdriver_t *rd = &in_drivers.a[i]; - if (rd->driver.grab_input) { - rd->driver.grab_input (rd->data, var->int_val); - } + for (size_t i = 0; i < in_drivers.size; i++) { + in_regdriver_t *rd = &in_drivers.a[i]; + if (rd->driver.grab_input) { + rd->driver.grab_input (rd->data, grab); } } } +static void +in_grab_f (void *data, const cvar_t *cvar) +{ + IN_UpdateGrab (in_grab); +} + void IN_ProcessEvents (void) { @@ -488,23 +557,14 @@ IN_Init (void) void IN_Init_Cvars (void) { - in_grab = Cvar_Get ("in_grab", "0", CVAR_ARCHIVE, IN_UpdateGrab, - "With this set to 1, quake will grab the mouse, " - "preventing loss of input focus."); - in_amp = Cvar_Get ("in_amp", "1", CVAR_ARCHIVE, NULL, - "global in_amp multiplier"); - in_pre_amp = Cvar_Get ("in_pre_amp", "1", CVAR_ARCHIVE, NULL, - "global in_pre_amp multiplier"); - in_freelook = Cvar_Get ("freelook", "0", CVAR_ARCHIVE, NULL, - "force +mlook"); - in_mouse_filter = Cvar_Get ("in_mouse_filter", "0", CVAR_ARCHIVE, NULL, - "Toggle mouse input filtering."); - in_mouse_amp = Cvar_Get ("in_mouse_amp", "15", CVAR_ARCHIVE, NULL, - "mouse in_mouse_amp multiplier"); - in_mouse_pre_amp = Cvar_Get ("in_mouse_pre_amp", "1", CVAR_ARCHIVE, NULL, - "mouse in_mouse_pre_amp multiplier"); - lookstrafe = Cvar_Get ("lookstrafe", "0", CVAR_ARCHIVE, NULL, - "when mlook/klook on player will strafe"); + Cvar_Register (&in_grab_cvar, in_grab_f, 0); + Cvar_Register (&in_amp_cvar, 0, 0); + Cvar_Register (&in_pre_amp_cvar, 0, 0); + Cvar_Register (&in_freelook_cvar, 0, 0); + Cvar_Register (&in_mouse_filter_cvar, 0, 0); + Cvar_Register (&in_mouse_amp_cvar, 0, 0); + Cvar_Register (&in_mouse_pre_amp_cvar, 0, 0); + Cvar_Register (&lookstrafe_cvar, 0, 0); for (size_t i = 0; i < in_drivers.size; i++) { in_regdriver_t *rd = &in_drivers.a[i]; if (rd->driver.init_cvars) { diff --git a/libs/input/in_imt.c b/libs/input/in_imt.c index 2d1d1f5b3..554053df4 100644 --- a/libs/input/in_imt.c +++ b/libs/input/in_imt.c @@ -267,7 +267,8 @@ imt_switcher_update (imt_switcher_t *switcher) val = !!(input->button->state & inb_down); break; case imti_cvar: - val = !!input->cvar->int_val; + //FIXME check cvar type + val = !!*(int *) input->cvar->value.value; break; } state |= val << i; @@ -497,6 +498,7 @@ IMT_CreateSwitcher (const char *switcher_name, int context, imt_t *default_imt, switcher); } else { input->type = imti_cvar; + //FIXME check cvar type input->cvar = Cvar_FindVar (input_name); Cvar_AddListener (input->cvar, imt_switcher_cvar_update, switcher); } diff --git a/libs/models/alias/gl_mesh.c b/libs/models/alias/gl_mesh.c index 9dba75be7..5c7b6a9ce 100644 --- a/libs/models/alias/gl_mesh.c +++ b/libs/models/alias/gl_mesh.c @@ -350,10 +350,9 @@ gl_Mod_MakeAliasModelDisplayLists (mod_alias_ctx_t *alias_ctx, void *_m, cache = dstring_new (); fullpath = dstring_new (); - if (!gl_alias_render_tri->int_val) { + if (!gl_alias_render_tri) { - if (gl_mesh_cache->int_val - && gl_mesh_cache->int_val <= header->mdl.numtris) { + if (gl_mesh_cache && gl_mesh_cache <= header->mdl.numtris) { do_cache = true; mdfour (model_digest, (unsigned char *) _m, _s); diff --git a/libs/models/brush/gl_model_brush.c b/libs/models/brush/gl_model_brush.c index e4de487e2..4e81f35f1 100644 --- a/libs/models/brush/gl_model_brush.c +++ b/libs/models/brush/gl_model_brush.c @@ -125,7 +125,7 @@ gl_Mod_ProcessTexture (model_t *mod, texture_t *tx) r_notexture_mip->render = &gl_notexture; return; } - if (gl_textures_external && gl_textures_external->int_val) { + if (gl_textures_external) { if (Mod_LoadExternalTextures (mod, tx)) { return; } @@ -239,8 +239,7 @@ SubdividePolygon (int numverts, float *verts) for (i = 0; i < 3; i++) { m = (mins[i] + maxs[i]) * 0.5; - m = gl_subdivide_size->value * floor (m / gl_subdivide_size->value + - 0.5); + m = gl_subdivide_size * floor (m / gl_subdivide_size + 0.5); if (maxs[i] - m < 8) continue; if (m - mins[i] < 8) diff --git a/libs/models/brush/model_brush.c b/libs/models/brush/model_brush.c index cf5552aed..ee307da3d 100644 --- a/libs/models/brush/model_brush.c +++ b/libs/models/brush/model_brush.c @@ -56,8 +56,8 @@ #include "compat.h" #include "mod_internal.h" -VISIBLE cvar_t *gl_sky_divide; //FIXME visibility? -VISIBLE int mod_lightmap_bytes = 1; //FIXME should this be visible? +VISIBLE int mod_sky_divide; //FIXME visibility? +VISIBLE int mod_lightmap_bytes = 1; //FIXME should this be visible? VISIBLE mleaf_t * Mod_PointInLeaf (const vec3_t p, model_t *model) @@ -640,9 +640,11 @@ Mod_LoadFaces (model_t *mod, bsp_t *bsp) if (!strncmp (out->texinfo->texture->name, "sky", 3)) { // sky out->flags |= (SURF_DRAWSKY | SURF_DRAWTILED); - if (gl_sky_divide && gl_sky_divide->int_val) - if (mod_funcs && mod_funcs->Mod_SubdivideSurface) + if (mod_sky_divide) { + if (mod_funcs && mod_funcs->Mod_SubdivideSurface) { mod_funcs->Mod_SubdivideSurface (mod, out); + } + } continue; } diff --git a/libs/models/gl_skin.c b/libs/models/gl_skin.c index 5ecef36ba..96506fb65 100644 --- a/libs/models/gl_skin.c +++ b/libs/models/gl_skin.c @@ -174,12 +174,12 @@ build_skin (skin_t *skin, int cmap) int texnum, fb_texnum; // FIXME deek: This 512x256 limit sucks! - scaled_width = min (gl_max_size->int_val, 512); - scaled_height = min (gl_max_size->int_val, 256); + scaled_width = min (gl_max_size, 512); + scaled_height = min (gl_max_size, 256); // allow users to crunch sizes down even more if they want - scaled_width >>= gl_playermip->int_val; - scaled_height >>= gl_playermip->int_val; + scaled_width >>= gl_playermip; + scaled_height >>= gl_playermip; scaled_width = max (scaled_width, 1); scaled_height = max (scaled_height, 1); diff --git a/libs/models/model.c b/libs/models/model.c index 2e7dc48b2..ee8969543 100644 --- a/libs/models/model.c +++ b/libs/models/model.c @@ -59,10 +59,43 @@ static size_t mod_numknown; VISIBLE texture_t *r_notexture_mip; -cvar_t *gl_mesh_cache; -cvar_t *gl_subdivide_size; -cvar_t *gl_alias_render_tri; -cvar_t *gl_textures_external; +int gl_mesh_cache; +static cvar_t gl_mesh_cache_cvar = { + .name = "gl_mesh_cache", + .description = + "minimum triangle count in a model for its mesh to be cached. 0 to " + "disable caching", + .default_value = "256", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &gl_mesh_cache }, +}; +float gl_subdivide_size; +static cvar_t gl_subdivide_size_cvar = { + .name = "gl_subdivide_size", + .description = + "Sets the division value for the sky brushes.", + .default_value = "128", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &gl_subdivide_size }, +}; +int gl_alias_render_tri; +static cvar_t gl_alias_render_tri_cvar = { + .name = "gl_alias_render_tri", + .description = + "When loading alias models mesh for pure triangle rendering", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &gl_alias_render_tri }, +}; +int gl_textures_external; +static cvar_t gl_textures_external_cvar = { + .name = "gl_textures_external", + .description = + "Use external textures to replace BSP textures", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &gl_textures_external }, +}; static void Mod_CallbackLoad (void *object, cache_allocator_t allocator); @@ -99,18 +132,10 @@ Mod_Init (void) VISIBLE void Mod_Init_Cvars (void) { - gl_subdivide_size = - Cvar_Get ("gl_subdivide_size", "128", CVAR_ARCHIVE, NULL, - "Sets the division value for the sky brushes."); - gl_mesh_cache = Cvar_Get ("gl_mesh_cache", "256", CVAR_ARCHIVE, NULL, - "minimum triangle count in a model for its mesh" - " to be cached. 0 to disable caching"); - gl_alias_render_tri = - Cvar_Get ("gl_alias_render_tri", "0", CVAR_ARCHIVE, NULL, "When " - "loading alias models mesh for pure triangle rendering"); - gl_textures_external = - Cvar_Get ("gl_textures_external", "1", CVAR_ARCHIVE, NULL, - "Use external textures to replace BSP textures"); + Cvar_Register (&gl_subdivide_size_cvar, 0, 0); + Cvar_Register (&gl_mesh_cache_cvar, 0, 0); + Cvar_Register (&gl_alias_render_tri_cvar, 0, 0); + Cvar_Register (&gl_textures_external_cvar, 0, 0); } VISIBLE void diff --git a/libs/net/nc/net_udp6.c b/libs/net/nc/net_udp6.c index fcbcda1f2..f0e8109e5 100644 --- a/libs/net/nc/net_udp6.c +++ b/libs/net/nc/net_udp6.c @@ -114,7 +114,15 @@ # endif #endif -static cvar_t *net_family; +static char *net_family; +static cvar_t net_family_cvar = { + .name = "net_family", + .description = + "Set the address family to ipv4, ipv6 or unspecified", + .default_value = "unspecified", + .flags = CVAR_ROM, + .value = { .type = 0, .value = &net_family }, +}; netadr_t net_from; netadr_t net_local_adr; @@ -330,9 +338,9 @@ NET_StringToAdr (const char *s, netadr_t *a) memset (&hints, 0, sizeof (hints)); hints.ai_socktype = SOCK_DGRAM; - if (strchr (net_family->string, '6')) { + if (strchr (net_family, '6')) { hints.ai_family = AF_INET6; - } else if (strchr (net_family->string, '4')) { + } else if (strchr (net_family, '4')) { hints.ai_family = AF_INET; } else { hints.ai_family = AF_UNSPEC; @@ -492,9 +500,9 @@ UDP_OpenSocket (int port) address.sin6_family = AF_INET6; memset (&hints, 0, sizeof (hints)); - if (strchr (net_family->string, '6')) { + if (strchr (net_family, '6')) { hints.ai_family = AF_INET6; - } else if (strchr (net_family->string, '4')) { + } else if (strchr (net_family, '4')) { hints.ai_family = AF_INET; } else { hints.ai_family = AF_UNSPEC; @@ -581,9 +589,7 @@ NET_Init (int port) if (r) Sys_Error ("Winsock initialization failed."); #endif /* _WIN32 */ - net_family = Cvar_Get ("net_family", "unspecified", CVAR_ROM, 0, - "Set the address family to ipv4, ipv6 or" - " unspecified"); + Cvar_Register (&net_family_cvar, 0, 0); // open the single socket to be used for all communications net_socket = UDP_OpenSocket (port); diff --git a/libs/net/net_chan.c b/libs/net/net_chan.c index 58da40169..13d4e5e9a 100644 --- a/libs/net/net_chan.c +++ b/libs/net/net_chan.c @@ -54,9 +54,35 @@ int net_nochoke; int net_blocksend; double *net_realtime; -cvar_t *showpackets; -cvar_t *showdrop; -cvar_t *qport; +int showpackets; +static cvar_t showpackets_cvar = { + .name = "showpackets", + .description = + "Show all network packets", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &showpackets }, +}; +int showdrop; +static cvar_t showdrop_cvar = { + .name = "showdrop", + .description = + "Toggle the display of how many packets you are dropping", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &showdrop }, +}; +int qport; +static cvar_t qport_cvar = { + .name = "qport", + .description = + "The internal port number for the game networking code. Useful for " + "clients who use multiple connections through one IP address (NAT/IP-" + "MASQ) because default port is random.", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &qport }, +}; void (*net_log_packet) (int length, const void *data, netadr_t to); @@ -68,21 +94,15 @@ Netchan_Init (void) // pick a port value that should be nice and random port = Sys_TimeID (); - Cvar_SetValue (qport, port); + qport = port; } void Netchan_Init_Cvars (void) { - showpackets = Cvar_Get ("showpackets", "0", CVAR_NONE, NULL, - "Show all network packets"); - showdrop = Cvar_Get ("showdrop", "0", CVAR_NONE, NULL, "Toggle the " - "display of how many packets you are dropping"); - qport = Cvar_Get ("qport", "0", CVAR_NONE, NULL, "The internal port " - "number for the game networking code. Useful for " - "clients who use multiple connections through one " - "IP address (NAT/IP-MASQ) because default port is " - "random."); + Cvar_Register (&showpackets_cvar, 0, 0); + Cvar_Register (&showdrop_cvar, 0, 0); + Cvar_Register (&qport_cvar, 0, 0); } /* @@ -256,13 +276,13 @@ Netchan_Transmit (netchan_t *chan, unsigned length, byte *data) if (net_nochoke) chan->cleartime = *net_realtime; - if (showpackets->int_val & 1) { + if (showpackets & 1) { Sys_Printf ("--> s=%i(%i) a=%i(%i) %-4i %i\n", chan->outgoing_sequence, send_reliable, chan->incoming_sequence, chan->incoming_reliable_sequence, send.cursize, chan->outgoing_sequence - chan->incoming_sequence); - if (showpackets->int_val & 4) { + if (showpackets & 4) { SZ_Dump (&send); } } @@ -292,10 +312,10 @@ Netchan_Process (netchan_t *chan) sequence &= ~(1 << 31); sequence_ack &= ~(1 << 31); - if (showpackets->int_val & 2) { + if (showpackets & 2) { Sys_Printf ("<-- s=%i(%i) a=%i(%i) %i\n", sequence, reliable_message, sequence_ack, reliable_ack, net_message->message->cursize); - if (showpackets->int_val & 8) { + if (showpackets & 8) { SZ_Dump (net_message->message); } } @@ -329,7 +349,7 @@ Netchan_Process (netchan_t *chan) /// Discard stale or duplicated packets. if (sequence < (unsigned int) chan->incoming_sequence + 1) { - if (showdrop->int_val) + if (showdrop) Sys_Printf ("%s:Out of order packet %i at %i\n", NET_AdrToString (chan->remote_address), sequence, chan->incoming_sequence); @@ -341,7 +361,7 @@ Netchan_Process (netchan_t *chan) if (chan->net_drop > 0) { chan->drop_count += 1; - if (showdrop->int_val) + if (showdrop) Sys_Printf ("%s:Dropped %i packets at %i\n", NET_AdrToString (chan->remote_address), sequence - (chan->incoming_sequence + 1), sequence); diff --git a/libs/net/net_main.c b/libs/net/net_main.c index 6ef7e9a0f..523366bc0 100644 --- a/libs/net/net_main.c +++ b/libs/net/net_main.c @@ -86,8 +86,24 @@ int messagesReceived = 0; int unreliableMessagesSent = 0; int unreliableMessagesReceived = 0; -cvar_t *net_messagetimeout; -cvar_t *hostname; +float net_messagetimeout; +static cvar_t net_messagetimeout_cvar = { + .name = "net_messagetimeout", + .description = + "None", + .default_value = "300", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &net_messagetimeout }, +}; +char *hostname; +static cvar_t hostname_cvar = { + .name = "hostname", + .description = + "None", + .default_value = "UNNAMED", + .flags = CVAR_NONE, + .value = { .type = 0, .value = &hostname }, +}; QFile *vcrFile; qboolean recording = false; @@ -229,9 +245,9 @@ MaxPlayers_f (void) svs.maxclients = n; if (n == 1) - Cvar_Set (deathmatch, "0"); + Cvar_Set ("deathmatch", "0"); else - Cvar_Set (deathmatch, "1"); + Cvar_Set ("deathmatch", "1"); } @@ -574,7 +590,7 @@ NET_GetMessage (qsocket_t *sock) // see if this connection has timed out if (ret == 0 && sock->driver) { - if (net_time - sock->lastMessageTime > net_messagetimeout->value) { + if (net_time - sock->lastMessageTime > net_messagetimeout) { Sys_MaskPrintf (SYS_net, "socket timed out\n"); NET_Close (sock); return -1; @@ -849,9 +865,8 @@ NET_Init (cbuf_t *cbuf) // allocate space for network message buffer SZ_Alloc (&_net_message_message, NET_MAXMESSAGE); - net_messagetimeout = - Cvar_Get ("net_messagetimeout", "300", CVAR_NONE, NULL, "None"); - hostname = Cvar_Get ("hostname", "UNNAMED", CVAR_NONE, NULL, "None"); + Cvar_Register (&net_messagetimeout_cvar, 0, 0); + Cvar_Register (&hostname_cvar, 0, 0); Cmd_AddCommand ("slist", NET_Slist_f, "No Description"); Cmd_AddCommand ("listen", NET_Listen_f, "No Description"); diff --git a/libs/net/nm/net_dgrm.c b/libs/net/nm/net_dgrm.c index 71f74ff4a..faa762f92 100644 --- a/libs/net/nm/net_dgrm.c +++ b/libs/net/nm/net_dgrm.c @@ -634,7 +634,7 @@ _Datagram_CheckNewConnections (void) MSG_WriteByte (net_message->message, CCREP_SERVER_INFO); dfunc.GetSocketAddr (acceptsock, &newaddr); MSG_WriteString (net_message->message, dfunc.AddrToString (&newaddr)); - MSG_WriteString (net_message->message, hostname->string); + MSG_WriteString (net_message->message, hostname); MSG_WriteString (net_message->message, sv.name); MSG_WriteByte (net_message->message, net_activeconnections); MSG_WriteByte (net_message->message, svs.maxclients); @@ -719,7 +719,7 @@ _Datagram_CheckNewConnections (void) MSG_WriteByte (net_message->message, CCREP_RULE_INFO); if (var) { MSG_WriteString (net_message->message, var->name); - MSG_WriteString (net_message->message, var->string); + MSG_WriteString (net_message->message, Cvar_VarString (var)); } MSG_PokeLongBE (net_message->message, 0, NETFLAG_CTL | net_message->message->cursize); diff --git a/libs/net/nm/net_loop.c b/libs/net/nm/net_loop.c index ddf61f6f3..168cbe23e 100644 --- a/libs/net/nm/net_loop.c +++ b/libs/net/nm/net_loop.c @@ -69,8 +69,8 @@ Loop_SearchForHosts (qboolean xmit) return; const char *name = "local"; - if (strcmp (hostname->string, "UNNAMED") != 0) { - name = hostname->string; + if (strcmp (hostname, "UNNAMED") != 0) { + name = hostname; } const char *map = sv.name; int users = net_activeconnections; diff --git a/libs/net/nm/net_udp.c b/libs/net/nm/net_udp.c index 13044d0c3..8701214cd 100644 --- a/libs/net/nm/net_udp.c +++ b/libs/net/nm/net_udp.c @@ -259,9 +259,9 @@ UDP_Init (void) myAddr = 0; // if the quake hostname isn't set, set it to the machine name - if (strcmp (hostname->string, "UNNAMED") == 0) { + if (strcmp (hostname, "UNNAMED") == 0) { buff[15] = 0; - Cvar_Set (hostname, buff); + Cvar_Set ("hostname", buff); } if ((net_controlsocket = UDP_OpenSocket (0)) == -1) @@ -552,7 +552,7 @@ UDP_Read (int socket, byte *buf, int len, netadr_t *from) UDP_AddrToString (from)); last_iface = default_iface; #endif - if (developer->int_val & SYS_net) { + if (developer & SYS_net) { hex_dump_buf (buf, ret); } return ret; @@ -603,7 +603,7 @@ UDP_Write (int socket, byte *buf, int len, netadr_t *to) return 0; Sys_MaskPrintf (SYS_net, "sent %d bytes to %s\n", ret, UDP_AddrToString (to)); - if (developer->int_val & SYS_net) { + if (developer & SYS_net) { hex_dump_buf (buf, len); } return ret; diff --git a/libs/net/nm/net_wins.c b/libs/net/nm/net_wins.c index 411c0b838..c93229ca2 100644 --- a/libs/net/nm/net_wins.c +++ b/libs/net/nm/net_wins.c @@ -252,7 +252,7 @@ WINS_Init (void) return -1; } // if the quake hostname isn't set, set it to the machine name - if (strcmp (hostname->string, "UNNAMED") == 0) { + if (strcmp (hostname, "UNNAMED") == 0) { // see if it's a text IP address (well, close enough) for (p = buff; *p; p++) if ((*p < '0' || *p > '9') && *p != '.') @@ -265,7 +265,7 @@ WINS_Init (void) break; buff[i] = 0; } - Cvar_Set (hostname, buff); + Cvar_Set ("hostname", buff); } i = COM_CheckParm ("-ip"); diff --git a/libs/ruamoko/pr_cmds.c b/libs/ruamoko/pr_cmds.c index 8e38ac948..bf8d9c19c 100644 --- a/libs/ruamoko/pr_cmds.c +++ b/libs/ruamoko/pr_cmds.c @@ -209,7 +209,7 @@ PF_cvar (progs_t *pr, void *data) str = P_GSTRING (pr, 0); - R_FLOAT (pr) = Cvar_VariableValue (str); + R_FLOAT (pr) = Cvar_Value (str); } /* @@ -231,7 +231,7 @@ PF_cvar_set (progs_t *pr, void *data) return; } - Cvar_Set (var, val); + Cvar_SetVar (var, val); } /* diff --git a/libs/ruamoko/rua_cvar.c b/libs/ruamoko/rua_cvar.c index 4d953db9c..e81b9241a 100644 --- a/libs/ruamoko/rua_cvar.c +++ b/libs/ruamoko/rua_cvar.c @@ -41,6 +41,8 @@ #include "QF/progs.h" #include "QF/va.h" +#include "QF/simd/types.h" + #include "rua_internal.h" typedef struct bi_alias_s { @@ -127,7 +129,7 @@ bi_Cvar_SetString (progs_t *pr, void *_res) if (!var) var = Cvar_FindAlias (varname); if (var) - Cvar_Set (var, val); + Cvar_SetVar (var, val); } static void @@ -140,7 +142,7 @@ bi_Cvar_SetInteger (progs_t *pr, void *_res) if (!var) var = Cvar_FindAlias (varname); if (var) - Cvar_Set (var, va (0, "%d", val)); + Cvar_SetVar (var, va (0, "%d", val)); } static void @@ -153,7 +155,7 @@ bi_Cvar_SetFloat (progs_t *pr, void *_res) if (!var) var = Cvar_FindAlias (varname); if (var) - Cvar_Set (var, va (0, "%g", val)); + Cvar_SetVar (var, va (0, "%g", val)); } static void @@ -166,7 +168,7 @@ bi_Cvar_SetVector (progs_t *pr, void *_res) if (!var) var = Cvar_FindAlias (varname); if (var) - Cvar_Set (var, va (0, "%g %g %g", val[0], val[1], val[2])); + Cvar_SetVar (var, va (0, "%g %g %g", val[0], val[1], val[2])); } static void @@ -178,7 +180,7 @@ bi_Cvar_GetString (progs_t *pr, void *_res) if (!var) var = Cvar_FindAlias (varname); if (var) - RETURN_STRING (pr, var->string); + RETURN_STRING (pr, Cvar_VarString (var)); else RETURN_STRING (pr, ""); } @@ -189,9 +191,13 @@ bi_Cvar_GetInteger (progs_t *pr, void *_res) const char *varname = P_GSTRING (pr, 0); cvar_t *var = Cvar_FindVar (varname); + R_INT (pr) = 0; if (!var) var = Cvar_FindAlias (varname); - R_INT (pr) = var ? var->int_val : 0; + if (!var || var->value.type != &cexpr_int) + return; + + R_INT (pr) = *(int *) var->value.value; } static void @@ -200,9 +206,12 @@ bi_Cvar_GetFloat (progs_t *pr, void *_res) const char *varname = P_GSTRING (pr, 0); cvar_t *var = Cvar_FindVar (varname); + R_FLOAT (pr) = 0; if (!var) var = Cvar_FindAlias (varname); - R_FLOAT (pr) = var ? var->value : 0; + if (!var || var->value.type != &cexpr_float) + return; + R_INT (pr) = *(float *) var->value.value; } static void @@ -213,8 +222,8 @@ bi_Cvar_GetVector (progs_t *pr, void *_res) if (!var) var = Cvar_FindAlias (varname); - if (var) - RETURN_VECTOR (pr, var->vec); + if (var && var->value.type == &cexpr_vector) + RETURN_VECTOR (pr, *(vec4f_t *) var->value.value); else VectorZero (R_VECTOR (pr)); } @@ -228,8 +237,9 @@ bi_Cvar_Toggle (progs_t *pr, void *_res) var = Cvar_FindVar (varname); if (!var) var = Cvar_FindAlias (varname); - if (var) - Cvar_Set (var, var->int_val ? "0" : "1"); + if (var && var->value.type == &cexpr_int) { + *(int *) var->value.value = !*(int *) var->value.value; + } } #define bi(x,np,params...) {#x, bi_##x, -1, np, {params}} diff --git a/libs/ruamoko/rua_obj.c b/libs/ruamoko/rua_obj.c index 65df011d6..510dff248 100644 --- a/libs/ruamoko/rua_obj.c +++ b/libs/ruamoko/rua_obj.c @@ -860,7 +860,7 @@ obj_find_message (probj_t *probj, pr_class_t *class, pr_sel_t *selector) pr_method_t *method; pr_sel_t *sel; int i; - int dev = developer->int_val; + int dev = developer; pr_string_t *names; if (dev & SYS_rua_msg) { @@ -882,7 +882,7 @@ obj_find_message (probj_t *probj, pr_class_t *class, pr_sel_t *selector) for (i = 0, method = method_list->method_list; i < method_list->method_count; i++, method++) { sel = &G_STRUCT (pr, pr_sel_t, method->method_name); - if (developer->int_val & SYS_rua_msg) { + if (developer & SYS_rua_msg) { names = probj->selector_names; Sys_Printf (" %s\n", PR_GetString (pr, names[sel->sel_id])); @@ -1214,7 +1214,7 @@ rua___obj_exec_class (progs_t *pr, void *data) Sys_MaskPrintf (SYS_rua_obj, " instance variables: %d @ %x\n", class->instance_size, class->ivars); - if (developer->int_val & SYS_rua_obj) + if (developer & SYS_rua_obj) dump_ivars (probj, class->ivars); Sys_MaskPrintf (SYS_rua_obj, " instance methods: %x\n", class->methods); @@ -1224,7 +1224,7 @@ rua___obj_exec_class (progs_t *pr, void *data) Sys_MaskPrintf (SYS_rua_obj, " instance variables: %d @ %x\n", meta->instance_size, meta->ivars); - if (developer->int_val & SYS_rua_obj) + if (developer & SYS_rua_obj) dump_ivars (probj, meta->ivars); class->subclass_list = 0; @@ -1482,7 +1482,7 @@ rua_obj_msg_sendv (progs_t *pr, void *data) if (count < 2 || count > PR_MAX_PARAMS) { PR_RunError (pr, "bad args count in obj_msg_sendv: %d", count); } - if (pr_boundscheck->int_val) { + if (pr_boundscheck) { PR_BoundsCheckSize (pr, args->list, count * pr->pr_param_size); } diff --git a/libs/util/cexpr-vars.c b/libs/util/cexpr-vars.c index c9af82710..4344c6035 100644 --- a/libs/util/cexpr-vars.c +++ b/libs/util/cexpr-vars.c @@ -132,21 +132,13 @@ cexpr_cvar (const char *name, exprctx_t *ctx) } exprtype_t *type = ctx->result->type; - binop_t *cast = cexpr_find_cast (type, &cexpr_int); - - exprval_t *val = 0; - if (cast || val->type == &cexpr_int || val->type == &cexpr_uint) { - val = cexpr_value (type, ctx); - *(int *) val->value = var->int_val; - } else if (val->type == &cexpr_float) { - val = cexpr_value (type, ctx); - *(float *) val->value = var->value; - } else if (val->type == &cexpr_double) { - val = cexpr_value (type, ctx); - //FIXME cvars need to support double values - *(double *) val->value = var->value; + if (var->value.type) { + exprval_t *val = cexpr_value (type, ctx); + cexpr_assign_value (val, &var->value, ctx); + return val; } - return val; + cexpr_error (ctx, "cvar %s has unknown type", var->name); + return 0; } VISIBLE exprval_t * diff --git a/libs/util/cmd.c b/libs/util/cmd.c index 13038f53d..4b33673e4 100644 --- a/libs/util/cmd.c +++ b/libs/util/cmd.c @@ -65,7 +65,15 @@ typedef struct cmd_provider_s static cmdalias_t *cmd_alias; -VISIBLE cvar_t *cmd_warncmd; +VISIBLE int cmd_warncmd; +static cvar_t cmd_warncmd_cvar = { + .name = "cmd_warncmd", + .description = + "Toggles the display of error messages for unknown commands", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &cmd_warncmd }, +}; static hashtab_t *cmd_alias_hash; static hashtab_t *cmd_hash; @@ -130,7 +138,7 @@ Cmd_Command (cbuf_args_t *args) return 0; if (cbuf_active->strict) return -1; - else if (cmd_warncmd->int_val || developer->int_val & SYS_dev) + else if (cmd_warncmd || developer & SYS_dev) Sys_Printf ("Unknown command \"%s\"\n", Cmd_Argv (0)); return 0; } @@ -515,9 +523,7 @@ Cmd_Exec_f (void) Sys_Printf ("couldn't exec %s\n", Cmd_Argv (1)); return; } - if (!Cvar_Command () - && (cmd_warncmd->int_val - || (developer && developer->int_val & SYS_dev))) + if (!Cvar_Command () && (cmd_warncmd || (developer & SYS_dev))) Sys_Printf ("execing %s\n", Cmd_Argv (1)); Cbuf_InsertText (cbuf_active, f); Hunk_FreeToLowMark (0, mark); @@ -629,8 +635,7 @@ Cmd_Init (void) Cmd_AddCommand ("echo", Cmd_Echo_f, "Print text to console"); Cmd_AddCommand ("wait", Cmd_Wait_f, "Wait a game tic"); Cmd_AddCommand ("sleep", Cmd_Sleep_f, "Wait for a certain number of seconds."); - cmd_warncmd = Cvar_Get ("cmd_warncmd", "0", CVAR_NONE, NULL, "Toggles the " - "display of error messages for unknown commands"); + Cvar_Register (&cmd_warncmd_cvar, 0, 0); cmd_cbuf = Cbuf_New (&id_interp); Cmd_AddProvider("id", &id_interp); diff --git a/libs/util/cvar.c b/libs/util/cvar.c index d1f9b693d..8eb2ed3aa 100644 --- a/libs/util/cvar.c +++ b/libs/util/cvar.c @@ -43,6 +43,7 @@ #include "QF/cmd.h" #include "QF/cvar.h" +#include "QF/cmem.h" #include "QF/hash.h" #include "QF/mathlib.h" #include "QF/plist.h" @@ -56,13 +57,82 @@ #define USER_RO_CVAR "User-created READ-ONLY Cvar" #define USER_CVAR "User-created cvar" -VISIBLE cvar_t *developer; +static exprenum_t developer_enum; +static exprtype_t developer_type = { + .name = "developer", + .size = sizeof (int), + .binops = cexpr_flag_binops, + .unops = cexpr_flag_unops, + .data = &developer_enum, + .get_string = cexpr_enum_get_string, +}; + +#define SYS_DEVELOPER(dev) (SYS_##dev & ~SYS_dev), +static int developer_values[] = { + SYS_dev, +#include "QF/sys_developer.h" +}; +#undef SYS_DEVELOPER +#define SYS_DEVELOPER(dev) {#dev, &developer_type, developer_values + __LINE__ - 31}, +static exprsym_t developer_symbols[] = { + {"dev", &developer_type, developer_values + 0}, +#include "QF/sys_developer.h" + {} +}; +#undef SYS_DEVELOPER +static exprtab_t developer_symtab = { + developer_symbols, +}; +static exprenum_t developer_enum = { + &developer_type, + &developer_symtab, +}; + +VISIBLE int developer; +static cvar_t developer_cvar = { + .name = "developer", + .description = + "set to enable extra debugging information", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &developer_type, .value = &developer }, +}; VISIBLE cvar_t *cvar_vars; +static cvar_t *user_cvars; static const char *cvar_null_string = ""; static cvar_alias_t *calias_vars; static hashtab_t *cvar_hash; static hashtab_t *calias_hash; +static cvar_t * +cvar_create (const char *name, const char *value) +{ + cvar_t *var = calloc (1, sizeof (cvar_t) + sizeof (char *)); + var->name = strdup (name); + var->description = cvar_null_string; + var->default_value = cvar_null_string; + var->flags = CVAR_USER_CREATED; + var->value.value = var + 1; + *(char **)var->value.value = strdup (value); + + var->next = user_cvars; + user_cvars = var; + + Hash_Add (cvar_hash, var); + return var; +} + +static void +cvar_destroy (cvar_t *var) +{ + if (!(var->flags & CVAR_USER_CREATED)) { + Sys_Error ("Attempt to destroy non-user cvar"); + } + Hash_Del (cvar_hash, var->name); + free (*(char **) var->value.value); + free ((char *) var->name); + free (var); +} VISIBLE cvar_t * Cvar_FindVar (const char *var_name) @@ -130,8 +200,21 @@ Cvar_RemoveAlias (const char *name) return var; } +static float +cvar_value (cvar_t *var) +{ + if (!var->value.type) { + return atof (*(char **)var->value.value); + } else if (var->value.type == &cexpr_int) { + return *(int *)var->value.value; + } else if (var->value.type == &cexpr_float) { + return *(float *)var->value.value; + } + return 0; +} + VISIBLE float -Cvar_VariableValue (const char *var_name) +Cvar_Value (const char *var_name) { cvar_t *var; @@ -140,11 +223,22 @@ Cvar_VariableValue (const char *var_name) var = Cvar_FindAlias (var_name); if (!var) return 0; - return atof (var->string); + return cvar_value (var); +} + +static const char * +cvar_string (const cvar_t *var) +{ + if (!var->value.type) { + return *(char **)var->value.value; + } else if (var->value.type->get_string) { + return var->value.type->get_string (&var->value, 0); + } + return cvar_null_string; } VISIBLE const char * -Cvar_VariableString (const char *var_name) +Cvar_String (const char *var_name) { cvar_t *var; @@ -153,7 +247,13 @@ Cvar_VariableString (const char *var_name) var = Cvar_FindAlias (var_name); if (!var) return cvar_null_string; - return var->string; + return cvar_string (var); +} + +VISIBLE const char * +Cvar_VarString (const cvar_t *var) +{ + return cvar_string (var); } VISIBLE const char * @@ -267,47 +367,74 @@ Cvar_RemoveListener (cvar_t *cvar, cvar_listener_t listener, void *data) } } -VISIBLE void -Cvar_Set (cvar_t *var, const char *value) +static int +cvar_setvar (cvar_t *var, const char *value) { - int changed; - int vals; + int changed = 0; - if (!var) - return; + if (!var->value.type) { + char **str_value = var->value.value; + changed = !*str_value || !strequal (*str_value, value); + if (var->validator) { + changed = changed && var->validator (var); + } + if (changed) { + free (*str_value); + *str_value = strdup (value); + } + } else { + exprenum_t *enm = var->value.type->data; + exprctx_t context = { + .memsuper = new_memsuper (), + .symtab = enm ? enm->symtab : 0, + .msg_prefix = var->name, + }; + if (context.symtab && !context.symtab->tab) { + cexpr_init_symtab (context.symtab, &context); + } + context.result = cexpr_value (var->value.type, &context); + if (!cexpr_eval_string (value, &context)) { + changed = memcmp (context.result->value, var->value.value, + var->value.type->size) != 0; + if (var->validator) { + changed = changed && var->validator (var); + } + if (changed) { + memcpy (var->value.value, context.result->value, + var->value.type->size); + } + } + delete_memsuper (context.memsuper); + } + if (changed && var->listeners) { + LISTENER_INVOKE (var->listeners, var); + } + return changed; +} + +VISIBLE void +Cvar_SetVar (cvar_t *var, const char *value) +{ if (var->flags & CVAR_ROM) { Sys_MaskPrintf (SYS_dev, "Cvar \"%s\" is read-only, cannot modify\n", var->name); return; } - - changed = !strequal (var->string, value); - if (changed) { - free ((char*)var->string); // free the old value string - - var->string = strdup (value); - var->value = atof (var->string); - var->int_val = atoi (var->string); - VectorZero (var->vec); - vals = sscanf (var->string, "%f %f %f", - &var->vec[0], &var->vec[1], &var->vec[2]); - if (vals == 1) - var->vec[2] = var->vec[1] = var->vec[0]; - - if (var->callback) - var->callback (var); - - if (var->listeners) { - LISTENER_INVOKE (var->listeners, var); - } - } + cvar_setvar (var, value); } VISIBLE void -Cvar_SetValue (cvar_t *var, float value) +Cvar_Set (const char *var_name, const char *value) { - Cvar_Set (var, va (0, "%.9g", value)); + cvar_t *var; + + var = Cvar_FindVar (var_name); + + if (!var) + return; + + Cvar_SetVar (var, value); } /* @@ -329,11 +456,11 @@ Cvar_Command (void) // perform a variable print or set if (Cmd_Argc () == 1) { - Sys_Printf ("\"%s\" is \"%s\"\n", v->name, v->string); + Sys_Printf ("\"%s\" is \"%s\"\n", v->name, cvar_string (v)); return true; } - Cvar_Set (v, Cmd_Argv (1)); + Cvar_SetVar (v, Cmd_Argv (1)); return true; } @@ -350,7 +477,7 @@ Cvar_WriteVariables (QFile *f) for (var = cvar_vars; var; var = var->next) if (var->flags & CVAR_ARCHIVE) - Qprintf (f, "seta %s \"%s\"\n", var->name, var->string); + Qprintf (f, "seta %s \"%s\"\n", var->name, cvar_string (var)); } VISIBLE void @@ -360,7 +487,7 @@ Cvar_SaveConfig (plitem_t *config) PL_D_AddObject (config, "cvars", cvars); for (cvar_t *var = cvar_vars; var; var = var->next) { if (var->flags & CVAR_ARCHIVE) { - PL_D_AddObject (cvars, var->name, PL_NewString (var->string)); + PL_D_AddObject (cvars, var->name, PL_NewString (cvar_string (var))); } } } @@ -379,79 +506,16 @@ Cvar_LoadConfig (plitem_t *config) if (value) { cvar_t *var = Cvar_FindVar (cvar_name); if (var) { - Cvar_Set (var, value); - Cvar_SetFlags (var, var->flags | CVAR_ARCHIVE); + Cvar_SetVar (var, value); + var->flags |= CVAR_ARCHIVE; } else { - Cvar_Get (cvar_name, value, CVAR_USER_CREATED | CVAR_ARCHIVE, - 0, USER_CVAR); + var = cvar_create (cvar_name, value); + var->flags |= CVAR_ARCHIVE; } } } } -#define SYS_DEVELOPER(developer) #developer, -static const char *developer_flags[] = { - "dev", -#include "QF/sys_developer.h" - 0 -}; - -static int -parse_developer_flag (const char *flag) -{ - const char **devflag; - char *end; - int val; - - val = strtol (flag, &end, 0); - if (!*end) { - return val; - } - for (devflag = developer_flags; *devflag; devflag++) { - if (!strcmp (*devflag, flag)) { - return 1 << (devflag - developer_flags); - } - } - return 0; -} - -static void -developer_f (cvar_t *var) -{ - char *buf = alloca (strlen (var->string) + 1); - const char *s; - char *b; - char c; - int parse = 0; - - for (s = var->string; *s; s++) { - if (isalpha (*s) || *s == '|') { - parse = 1; - break; - } - } - if (!parse) { - return; - } - var->int_val = 0; - for (s = var->string, b = buf; (c = *s++); ) { - if (isspace (c)) { - continue; - } - if (c == '|') { - *b = 0; - var->int_val |= parse_developer_flag (buf); - b = buf; - continue; - } - *b++ = c; - } - if (b != buf) { - *b = 0; - var->int_val |= parse_developer_flag (buf); - } -} - static void set_cvar (const char *cmd, int orflags) { @@ -477,12 +541,12 @@ set_cvar (const char *cmd, int orflags) "Cvar \"%s\" is read-only, cannot modify\n", var_name); } else { - Cvar_Set (var, value); - Cvar_SetFlags (var, var->flags | orflags); + Cvar_SetVar (var, value); + var->flags |= orflags; } } else { - Cvar_Get (var_name, value, CVAR_USER_CREATED | orflags, NULL, - USER_CVAR); + var = cvar_create (var_name, value); + var->flags |= orflags; } } @@ -523,11 +587,23 @@ Cvar_Inc_f (void) var = Cvar_FindVar (name); if (!var) var = Cvar_FindAlias (name); - if (!var) + if (!var) { Sys_Printf ("Unknown variable \"%s\"\n", name); + return; + } + if (var->flags & CVAR_ROM) { + Sys_Printf ("Variable \"%s\" is read-only\n", name); + return; + } break; } - Cvar_SetValue (var, var->value + inc); + if (var->value.type == &cexpr_float) { + *(float *) var->value.value += inc; + } else if (var->value.type == &cexpr_int) { + *(int *) var->value.value += inc; + } else { + Sys_Printf ("Variable \"%s\" cannot be incremented\n", name); + } } static void @@ -547,8 +623,12 @@ Cvar_Toggle_f (void) Sys_Printf ("Unknown variable \"%s\"\n", Cmd_Argv (1)); return; } + if ((var->flags & CVAR_ROM) || var->value.type != &cexpr_int) { + Sys_Printf ("Variable \"%s\" cannot be toggled\n", Cmd_Argv (1)); + return; + } - Cvar_Set (var, var->int_val ? "0" : "1"); + *(int *) var->value.value = !*(int *) var->value.value; } static void @@ -569,8 +649,7 @@ Cvar_Cycle_f (void) if (!var) var = Cvar_FindAlias (name); if (!var) { - var = Cvar_Get (name, Cmd_Argv (Cmd_Argc () - 1), CVAR_USER_CREATED, - 0, USER_CVAR); + var = cvar_create (name, Cmd_Argv (Cmd_Argc () - 1)); } // loop through the args until you find one that matches the current cvar @@ -583,27 +662,22 @@ Cvar_Cycle_f (void) // it won't match on zero when it should, but after that, it will be // comparing string that all had the same source (the user) so it will // work. - if (atof (Cmd_Argv (i)) == 0) { - if (!strcmp (Cmd_Argv (i), var->string)) - break; - } else { - if (atof (Cmd_Argv (i)) == var->value) - break; - } + if (!strcmp (Cmd_Argv (i), cvar_string (var))) + break; } if (i == Cmd_Argc ()) - Cvar_Set (var, Cmd_Argv (2)); // no match + Cvar_SetVar (var, Cmd_Argv (2)); // no match else if (i + 1 == Cmd_Argc ()) - Cvar_Set (var, Cmd_Argv (2)); // matched last value in list + Cvar_SetVar (var, Cmd_Argv (2)); // matched last value in list else - Cvar_Set (var, Cmd_Argv (i + 1)); // matched earlier in list + Cvar_SetVar (var, Cmd_Argv (i + 1)); // matched earlier in list } static void Cvar_Reset (cvar_t *var) { - Cvar_Set (var, var->default_string); + Cvar_SetVar (var, var->default_value); } static void @@ -661,7 +735,7 @@ Cvar_CvarList_f (void) var->flags & CVAR_SERVERINFO ? 's' : ' '); if (showhelp == 2) Sys_Printf ("//%s %s\n%s \"%s\"\n\n", flags, var->description, - var->name, var->string); + var->name, cvar_string (var)); else if (showhelp) Sys_Printf ("%s %-20s : %s\n", flags, var->name, var->description); else @@ -671,15 +745,6 @@ Cvar_CvarList_f (void) Sys_Printf ("------------\n%d variables\n", i); } -static void -cvar_free (void *c, void *unused) -{ - cvar_t *cvar = (cvar_t*)c; - free ((char*)cvar->name); - free ((char*)cvar->string); - free (cvar); -} - static const char * cvar_get_key (const void *c, void *unused) { @@ -705,15 +770,14 @@ calias_get_key (const void *c, void *unused) VISIBLE void Cvar_Init_Hash (void) { - cvar_hash = Hash_NewTable (1021, cvar_get_key, cvar_free, 0, 0); + cvar_hash = Hash_NewTable (1021, cvar_get_key, 0, 0, 0); calias_hash = Hash_NewTable (1021, calias_get_key, calias_free, 0, 0); } VISIBLE void Cvar_Init (void) { - developer = Cvar_Get ("developer", "0", CVAR_NONE, developer_f, - "set to enable extra debugging information"); + Cvar_Register (&developer_cvar, 0, 0); Cmd_AddCommand ("set", Cvar_Set_f, "Set the selected variable, useful on " "the command line (+set variablename setting)"); @@ -732,66 +796,38 @@ Cvar_Init (void) Cmd_AddCommand ("resetall", Cvar_ResetAll_f, "Reset all cvars"); } -VISIBLE cvar_t * -Cvar_Get (const char *name, const char *string, int cvarflags, - void (*callback)(cvar_t*), const char *description) +VISIBLE void +Cvar_Register (cvar_t *var, cvar_listener_t listener, void *data) { - int changed = 0; - cvar_t *var; + cvar_t *user_var; - if (Cmd_Exists (name)) { - Sys_Printf ("Cvar_Get: %s is a command\n", name); - return NULL; + if (Cmd_Exists (var->name)) { + Sys_Printf ("Cvar_Get: %s is a command\n", var->name); + return; + } + if (var->flags & CVAR_REGISTERED) { + Sys_Error ("Cvar %s already registered", var->name); } - var = Cvar_FindVar (name); - if (!var) { - cvar_t **v; - var = (cvar_t *) calloc (1, sizeof (cvar_t)); - // Cvar doesn't exist, so we create it - var->name = strdup (name); - var->string = strdup (string); - var->default_string = strdup (string); - var->flags = cvarflags; - var->callback = callback; - var->description = description; - var->value = atof (var->string); - var->int_val = atoi (var->string); - sscanf (var->string, "%f %f %f", - &var->vec[0], &var->vec[1], &var->vec[2]); - Hash_Add (cvar_hash, var); - - for (v = &cvar_vars; *v; v = &(*v)->next) - if (strcmp ((*v)->name, var->name) >= 0) - break; - var->next = *v; - *v = var; - - changed = 1; + if ((user_var = Hash_Find (cvar_hash, var->name))) { + cvar_setvar (var, cvar_string (user_var)); + cvar_destroy (user_var); } else { - // Cvar does exist, so we update the flags and return. - var->flags &= ~CVAR_USER_CREATED; - var->flags |= cvarflags; - changed = !strequal (var->string, string) || var->callback != callback; - if (!var->callback) - var->callback = callback; - if (!var->description - || strequal (var->description, USER_RO_CVAR) - || strequal (var->description, USER_CVAR)) - var->description = description; - if (!var->default_string) - var->default_string = strdup (string); + cvar_setvar (var, var->default_value); } - if (changed) { - if (var->callback) - var->callback (var); + var->flags |= CVAR_REGISTERED; + var->next = cvar_vars; + cvar_vars = var; - if (var->listeners) { - LISTENER_INVOKE (var->listeners, var); - } + if (listener) { + Cvar_AddListener (var, listener, data); } - return var; + Hash_Add (cvar_hash, var); + + if (var->listeners) { + LISTENER_INVOKE (var->listeners, var); + } } /* diff --git a/libs/util/plugin.c b/libs/util/plugin.c index 53ca4012e..e5bf0ace2 100644 --- a/libs/util/plugin.c +++ b/libs/util/plugin.c @@ -71,7 +71,15 @@ typedef struct loaded_plugin_s { plugin_t *plugin; } loaded_plugin_t; -cvar_t *fs_pluginpath; +char *fs_pluginpath; +static cvar_t fs_pluginpath_cvar = { + .name = "fs_pluginpath", + .description = + "Location of your plugin directory", + .default_value = FS_PLUGINPATH, + .flags = CVAR_ROM, + .value = { .type = 0, .value = &fs_pluginpath }, +}; hashtab_t *registered_plugins, *loaded_plugins; @@ -155,9 +163,9 @@ static const char * pi_realname (const char *type, const char *name) { #if defined(HAVE_DLOPEN) - return va (0, "%s/%s_%s.so", fs_pluginpath->string, type, name); + return va (0, "%s/%s_%s.so", fs_pluginpath, type, name); #elif defined(_WIN32) - return va (0, "%s/%s_%s.dll", fs_pluginpath->string, type, name); + return va (0, "%s/%s_%s.dll", fs_pluginpath, type, name); #else return "No shared library support. FIXME"; #endif @@ -178,8 +186,7 @@ pi_info_name (const char *type, const char *name) static void PI_InitCvars (void) { - fs_pluginpath = Cvar_Get ("fs_pluginpath", FS_PLUGINPATH, CVAR_ROM, NULL, - "Location of your plugin directory"); + Cvar_Register (&fs_pluginpath_cvar, 0, 0); } static void diff --git a/libs/util/qargs.c b/libs/util/qargs.c index 45bd04636..ad7eda0e7 100644 --- a/libs/util/qargs.c +++ b/libs/util/qargs.c @@ -51,8 +51,24 @@ #include "QF/sys.h" #include "QF/va.h" -cvar_t *fs_globalcfg; -cvar_t *fs_usercfg; +char *fs_globalcfg; +static cvar_t fs_globalcfg_cvar = { + .name = "fs_globalcfg", + .description = + "global configuration file", + .default_value = FS_GLOBALCFG, + .flags = CVAR_ROM, + .value = { .type = 0, .value = &fs_globalcfg }, +}; +char *fs_usercfg; +static cvar_t fs_usercfg_cvar = { + .name = "fs_usercfg", + .description = + "user configuration file", + .default_value = FS_USERCFG, + .flags = CVAR_ROM, + .value = { .type = 0, .value = &fs_usercfg }, +}; static const char **largv; static const char *argvdummy = " "; @@ -160,9 +176,8 @@ COM_ParseConfig (cbuf_t *cbuf) Cbuf_Execute_Sets (cbuf); // execute set commands in the global configuration file if it exists - fs_globalcfg = Cvar_Get ("fs_globalcfg", FS_GLOBALCFG, CVAR_ROM, NULL, - "global configuration file"); - Cmd_Exec_File (cbuf, fs_globalcfg->string, 0); + Cvar_Register (&fs_globalcfg_cvar, 0, 0); + Cmd_Exec_File (cbuf, fs_globalcfg, 0); Cbuf_Execute_Sets (cbuf); // execute +set again to override the config file @@ -170,9 +185,8 @@ COM_ParseConfig (cbuf_t *cbuf) Cbuf_Execute_Sets (cbuf); // execute set commands in the user configuration file if it exists - fs_usercfg = Cvar_Get ("fs_usercfg", FS_USERCFG, CVAR_ROM, NULL, - "user configuration file"); - Cmd_Exec_File (cbuf, fs_usercfg->string, 0); + Cvar_Register (&fs_usercfg_cvar, 0, 0); + Cmd_Exec_File (cbuf, fs_usercfg, 0); Cbuf_Execute_Sets (cbuf); // execute +set again to override the config file @@ -212,14 +226,14 @@ COM_ExecConfig (cbuf_t *cbuf, int skip_quakerc) // should be used to set up defaults on the assumption that the user has // things set up to work with another (hopefully compatible) client if (Cmd_Exec_File (cbuf, "quakeforge.cfg", 1)) { - Cmd_Exec_File (cbuf, fs_usercfg->string, 0); + Cmd_Exec_File (cbuf, fs_usercfg, 0); Cmd_StuffCmds (cbuf); COM_Check_quakerc ("startdemos", cbuf); } else { if (!skip_quakerc) { Cbuf_InsertText (cbuf, "exec quake.rc\n"); } - Cmd_Exec_File (cbuf, fs_usercfg->string, 0); + Cmd_Exec_File (cbuf, fs_usercfg, 0); // Reparse the command line for + commands. // (sets still done, but it doesn't matter) // (Note, no non-base commands exist yet) diff --git a/libs/util/quakefs.c b/libs/util/quakefs.c index b9ea4c38a..162722a81 100644 --- a/libs/util/quakefs.c +++ b/libs/util/quakefs.c @@ -123,9 +123,33 @@ int fnmatch (const char *__pattern, const char *__string, int __flags); // QUAKE FILESYSTEM static memhunk_t *qfs_hunk; -static cvar_t *fs_userpath; -static cvar_t *fs_sharepath; -static cvar_t *fs_dirconf; +static char *fs_userpath; +static cvar_t fs_userpath_cvar = { + .name = "fs_userpath", + .description = + "location of your game directories", + .default_value = FS_USERPATH, + .flags = CVAR_ROM, + .value = { .type = 0, .value = &fs_userpath }, +}; +static char *fs_sharepath; +static cvar_t fs_sharepath_cvar = { + .name = "fs_sharepath", + .description = + "location of shared (read-only) game directories", + .default_value = FS_SHAREPATH, + .flags = CVAR_ROM, + .value = { .type = 0, .value = &fs_sharepath }, +}; +static char *fs_dirconf; +static cvar_t fs_dirconf_cvar = { + .name = "fs_dirconf", + .description = + "full path to gamedir.conf FIXME", + .default_value = "", + .flags = CVAR_ROM, + .value = { .type = 0, .value = &fs_dirconf }, +}; VISIBLE const char *qfs_userpath; @@ -650,8 +674,8 @@ qfs_load_config (void) char *buf; char *dirconf; - if (*fs_dirconf->string) { - dirconf = Sys_ExpandSquiggle (fs_dirconf->string); + if (*fs_dirconf) { + dirconf = Sys_ExpandSquiggle (fs_dirconf); if (!(f = Qopen (dirconf, "rt"))) Sys_MaskPrintf (SYS_fs, "Could not load `%s', using builtin defaults\n", @@ -1333,17 +1357,17 @@ qfs_add_gamedir (vpath_t *vpath, const char *dir) if (!*dir) return; - e = fs_sharepath->string + strlen (fs_sharepath->string); + e = fs_sharepath + strlen (fs_sharepath); s = e; s_dir = dstring_new (); f_dir = dstring_new (); - while (s >= fs_sharepath->string) { - while (s != fs_sharepath->string && s[-1] !=':') + while (s >= fs_sharepath) { + while (s != fs_sharepath && s[-1] !=':') s--; if (s != e) { dsprintf (s_dir, "%.*s", (int) (e - s), s); - if (strcmp (s_dir->str, fs_userpath->string) != 0) { + if (strcmp (s_dir->str, fs_userpath) != 0) { if (qfs_expand_path (f_dir, s_dir->str, dir, 0) != 0) { Sys_Printf ("dropping bad directory %s\n", dir); break; @@ -1409,12 +1433,15 @@ QFS_GamedirCallback (gamedir_callback_t *func) } static void -qfs_path_cvar (cvar_t *var) +qfs_path_cvar (void *data, const cvar_t *cvar) { - char *cpath = QFS_CompressPath (var->string); - if (strcmp (cpath, var->string)) - Cvar_Set (var, cpath); - free (cpath); + char *cpath = QFS_CompressPath (*(char **)data); + if (strcmp (cpath, *(char **)data)) { + free (*(char **)cvar->value.value); + *(char **)cvar->value.value = cpath; + } else { + free (cpath); + } } static void @@ -1434,19 +1461,13 @@ QFS_Init (memhunk_t *hunk, const char *game) qfs_hunk = hunk; - fs_sharepath = Cvar_Get ("fs_sharepath", FS_SHAREPATH, CVAR_ROM, - qfs_path_cvar, - "location of shared (read-only) game " - "directories"); - fs_userpath = Cvar_Get ("fs_userpath", FS_USERPATH, CVAR_ROM, - qfs_path_cvar, - "location of your game directories"); - fs_dirconf = Cvar_Get ("fs_dirconf", "", CVAR_ROM, NULL, - "full path to gamedir.conf FIXME"); + Cvar_Register (&fs_sharepath_cvar, qfs_path_cvar, &fs_sharepath); + Cvar_Register (&fs_userpath_cvar, qfs_path_cvar, &fs_userpath); + Cvar_Register (&fs_dirconf_cvar, 0, 0); Cmd_AddCommand ("path", qfs_path_f, "Show what paths Quake is using"); - qfs_userpath = Sys_ExpandSquiggle (fs_userpath->string); + qfs_userpath = Sys_ExpandSquiggle (fs_userpath); qfs_load_config (); diff --git a/libs/util/sys.c b/libs/util/sys.c index daa9adb55..f5ebfded5 100644 --- a/libs/util/sys.c +++ b/libs/util/sys.c @@ -96,10 +96,45 @@ static void Sys_StdPrintf (const char *fmt, va_list args) __attribute__((format(PRINTF, 1, 0))); static void Sys_ErrPrintf (const char *fmt, va_list args) __attribute__((format(PRINTF, 1, 0))); -VISIBLE cvar_t *sys_nostdout; -VISIBLE cvar_t *sys_extrasleep; -cvar_t *sys_dead_sleep; -cvar_t *sys_sleep; +VISIBLE int sys_nostdout; +static cvar_t sys_nostdout_cvar = { + .name = "sys_nostdout", + .description = + "Set to disable std out", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sys_nostdout }, +}; +VISIBLE int sys_extrasleep; +static cvar_t sys_extrasleep_cvar = { + .name = "sys_extrasleep", + .description = + "Set to cause whatever amount delay in microseconds you want. Mostly " + "useful to generate simulated bad connections.", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sys_extrasleep }, +}; +int sys_dead_sleep; +static cvar_t sys_dead_sleep_cvar = { + .name = "sys_dead_sleep", + .description = + "When set, the server gets NO cpu if no clients are connected and " + "there's no other activity. *MIGHT* cause problems with some mods.", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sys_dead_sleep }, +}; +int sys_sleep; +static cvar_t sys_sleep_cvar = { + .name = "sys_sleep", + .description = + "Sleep how long in seconds between checking for connections. Minimum " + "is 0, maximum is 13", + .default_value = "8", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sys_sleep }, +}; int sys_checksum; @@ -297,7 +332,7 @@ Sys_Print (FILE *stream, const char *fmt, va_list args) static void Sys_StdPrintf (const char *fmt, va_list args) { - if (sys_nostdout && sys_nostdout->int_val) + if (sys_nostdout) return; Sys_Print (stdout, fmt, args); } @@ -322,7 +357,7 @@ Sys_MaskPrintf (int mask, const char *fmt, ...) { va_list args; - if (!developer || !(developer->int_val & mask)) + if (!(developer & mask)) return; va_start (args, fmt); sys_std_printf_function (fmt, args); @@ -495,21 +530,10 @@ Sys_MakeCodeWriteable (uintptr_t startaddr, size_t length) VISIBLE void Sys_Init_Cvars (void) { - sys_nostdout = Cvar_Get ("sys_nostdout", "0", CVAR_NONE, NULL, - "Set to disable std out"); - sys_extrasleep = Cvar_Get ("sys_extrasleep", "0", CVAR_NONE, NULL, - "Set to cause whatever amount delay in " - "microseconds you want. Mostly " - "useful to generate simulated bad " - "connections."); - sys_dead_sleep = Cvar_Get ("sys_dead_sleep", "0", CVAR_NONE, NULL, - "When set, the server gets NO cpu if no " - "clients are connected and there's no other " - "activity. *MIGHT* cause problems with some " - "mods."); - sys_sleep = Cvar_Get ("sys_sleep", "8", CVAR_NONE, NULL, "Sleep how long " - "in seconds between checking for connections. " - "Minimum is 0, maximum is 13"); + Cvar_Register (&sys_nostdout_cvar, 0, 0); + Cvar_Register (&sys_extrasleep_cvar, 0, 0); + Cvar_Register (&sys_dead_sleep_cvar, 0, 0); + Cvar_Register (&sys_sleep_cvar, 0, 0); } void @@ -802,7 +826,7 @@ Sys_CheckInput (int idle, int net_socket) int sleep_msec; // Now we want to give some processing time to other applications, // such as qw_client, running on this machine. - sleep_msec = sys_sleep->int_val; + sleep_msec = sys_sleep; if (sleep_msec > 0) { if (sleep_msec > 13) sleep_msec = 13; @@ -825,7 +849,7 @@ Sys_CheckInput (int idle, int net_socket) if (net_socket >= 0) QF_FD_SET (((unsigned) net_socket), &fdset);// cast needed for windows - if (idle && sys_dead_sleep->int_val) + if (idle && sys_dead_sleep) usec = -1; res = Sys_Select (max (net_socket, 0), &fdset, usec); diff --git a/libs/util/zone.c b/libs/util/zone.c index cfde5a3dd..0341af421 100644 --- a/libs/util/zone.c +++ b/libs/util/zone.c @@ -222,7 +222,7 @@ Z_TagMalloc (memzone_t *zone, size_t size, int tag) int requested_size = size; memblock_t *start, *rover, *new, *base; - if (!developer || developer->int_val & SYS_dev) + if (developer & SYS_dev) Z_CheckHeap (zone); // DEBUG if (!tag) { @@ -291,7 +291,7 @@ Z_Realloc (memzone_t *zone, void *ptr, size_t size) if (!ptr) return Z_Malloc (zone, size); - if (!developer || developer->int_val & SYS_dev) + if (developer & SYS_dev) Z_CheckHeap (zone); // DEBUG block = (memblock_t *) ((byte *) ptr - sizeof (memblock_t)); diff --git a/libs/video/renderer/gl/gl_draw.c b/libs/video/renderer/gl/gl_draw.c index e20718da5..f131fa0d7 100644 --- a/libs/video/renderer/gl/gl_draw.c +++ b/libs/video/renderer/gl/gl_draw.c @@ -569,7 +569,7 @@ crosshair_2 (int x, int y) { unsigned char *pColor; - pColor = (unsigned char *) &d_8to24table[crosshaircolor->int_val]; + pColor = (unsigned char *) &d_8to24table[crosshaircolor]; qfglColor4ubv (pColor); qfglBindTexture (GL_TEXTURE_2D, cs_texture); @@ -593,7 +593,7 @@ crosshair_3 (int x, int y) { unsigned char *pColor; - pColor = (unsigned char *) &d_8to24table[crosshaircolor->int_val]; + pColor = (unsigned char *) &d_8to24table[crosshaircolor]; qfglColor4ubv (pColor); qfglBindTexture (GL_TEXTURE_2D, cs_texture); @@ -617,7 +617,7 @@ crosshair_4 (int x, int y) { unsigned char *pColor; - pColor = (unsigned char *) &d_8to24table[crosshaircolor->int_val]; + pColor = (unsigned char *) &d_8to24table[crosshaircolor]; qfglColor4ubv (pColor); qfglBindTexture (GL_TEXTURE_2D, cs_texture); @@ -641,7 +641,7 @@ crosshair_5 (int x, int y) //FIXME don't use until the data is filled in { unsigned char *pColor; - pColor = (unsigned char *) &d_8to24table[crosshaircolor->int_val]; + pColor = (unsigned char *) &d_8to24table[crosshaircolor]; qfglColor4ubv (pColor); qfglBindTexture (GL_TEXTURE_2D, cs_texture); @@ -674,12 +674,12 @@ gl_Draw_Crosshair (void) int x, y; int ch; - ch = crosshair->int_val - 1; + ch = crosshair - 1; if ((unsigned) ch >= sizeof (crosshair_func) / sizeof (crosshair_func[0])) return; - x = vid.conview->xlen / 2 + cl_crossx->int_val; - y = vid.conview->ylen / 2 + cl_crossy->int_val; + x = vid.conview->xlen / 2 + cl_crossx; + y = vid.conview->ylen / 2 + cl_crossy; crosshair_func[ch] (x, y); } @@ -784,7 +784,7 @@ gl_Draw_ConsoleBackground (int lines, byte alpha) gl = (glpic_t *) conback->data; // spin the console? - effect described in a QER tutorial - if (gl_conspin->value) { + if (gl_conspin) { static float xangle = 0; static float xfactor = .3f; static float xstep = .005f; @@ -793,7 +793,7 @@ gl_Draw_ConsoleBackground (int lines, byte alpha) qfglMatrixMode (GL_TEXTURE); qfglPushMatrix (); qfglLoadIdentity (); - xangle += gl_conspin->value; + xangle += gl_conspin; xfactor += xstep; if (xfactor > 8 || xfactor < .3f) xstep = -xstep; @@ -801,7 +801,7 @@ gl_Draw_ConsoleBackground (int lines, byte alpha) qfglScalef (xfactor, xfactor, xfactor); } // slide console up/down or stretch it? - if (gl_constretch->int_val) { + if (gl_constretch) { ofs = 0; } else ofs = (vid.conview->ylen - lines) / (float) vid.conview->ylen; @@ -827,15 +827,15 @@ gl_Draw_ConsoleBackground (int lines, byte alpha) qfglColor3ubv (color_0_8); } - if (gl_conspin->value) { + if (gl_conspin) { qfglPopMatrix (); qfglMatrixMode (GL_MODELVIEW); qfglPopMatrix (); } - int len = strlen (cl_verstring->string); + int len = strlen (cl_verstring); gl_Draw_AltString (vid.conview->xlen - len * 8 - 11, lines - 14, - cl_verstring->string); + cl_verstring); qfglColor3ubv (color_white); } diff --git a/libs/video/renderer/gl/gl_dyn_lights.c b/libs/video/renderer/gl/gl_dyn_lights.c index 6af2287b2..02bbcb552 100644 --- a/libs/video/renderer/gl/gl_dyn_lights.c +++ b/libs/video/renderer/gl/gl_dyn_lights.c @@ -112,7 +112,7 @@ gl_R_RenderDlights (void) unsigned int i; dlight_t *l; - if (!gl_dlight_polyblend->int_val) + if (!gl_dlight_polyblend) return; qfglDepthMask (GL_FALSE); @@ -127,7 +127,7 @@ gl_R_RenderDlights (void) R_RenderDlight (l); } - if (!gl_dlight_smooth->int_val) + if (!gl_dlight_smooth) qfglShadeModel (GL_FLAT); qfglColor3ubv (color_white); qfglEnable (GL_TEXTURE_2D); diff --git a/libs/video/renderer/gl/gl_dyn_part.c b/libs/video/renderer/gl/gl_dyn_part.c index 151a2ed72..e6ede88fc 100644 --- a/libs/video/renderer/gl/gl_dyn_part.c +++ b/libs/video/renderer/gl/gl_dyn_part.c @@ -109,9 +109,17 @@ alloc_arrays (psystem_t *ps) } } +static void +gl_particles_f (void *data, const cvar_t *cvar) +{ + alloc_arrays (&r_psystem);//FIXME +} + void gl_R_InitParticles (void) { + Cvar_AddListener (Cvar_FindVar ("r_particles"), gl_particles_f, 0); + Cvar_AddListener (Cvar_FindVar ("r_particles_max"), gl_particles_f, 0); alloc_arrays (&r_psystem); } @@ -134,8 +142,8 @@ gl_R_DrawParticles (psystem_t *psystem) qfglInterleavedArrays (GL_T2F_C4UB_V3F, 0, particleVertexArray); minparticledist = DotProduct (r_refdef.frame.position, - r_refdef.frame.forward) + - r_particles_nearclip->value; + r_refdef.frame.forward) + + r_particles_nearclip; vacount = 0; VA = particleVertexArray; @@ -233,42 +241,6 @@ gl_R_DrawParticles (psystem_t *psystem) qfglDepthMask (GL_TRUE); } -static void -r_particles_nearclip_f (cvar_t *var) -{ - Cvar_SetValue (r_particles_nearclip, bound (r_nearclip->value, var->value, - r_farclip->value)); -} - -static void -r_particles_f (cvar_t *var) -{ - R_MaxParticlesCheck (var, r_particles_max); - alloc_arrays (&r_psystem); -} - -static void -r_particles_max_f (cvar_t *var) -{ - R_MaxParticlesCheck (r_particles, var); - alloc_arrays (&r_psystem); -} - -void -gl_R_Particles_Init_Cvars (void) -{ - r_particles = Cvar_Get ("r_particles", "1", CVAR_ARCHIVE, r_particles_f, - "Toggles drawing of particles."); - r_particles_max = Cvar_Get ("r_particles_max", "2048", CVAR_ARCHIVE, - r_particles_max_f, "Maximum amount of " - "particles to display. No maximum, minimum " - "is 0."); - r_particles_nearclip = Cvar_Get ("r_particles_nearclip", "32", - CVAR_ARCHIVE, r_particles_nearclip_f, - "Distance of the particle near clipping " - "plane from the player."); -} - psystem_t * __attribute__((const))//FIXME gl_ParticleSystem (void) { diff --git a/libs/video/renderer/gl/gl_fisheye.c b/libs/video/renderer/gl/gl_fisheye.c index bb0a34e21..2e1483214 100644 --- a/libs/video/renderer/gl/gl_fisheye.c +++ b/libs/video/renderer/gl/gl_fisheye.c @@ -156,10 +156,10 @@ gl_FisheyeScreen (framebuffer_t *fb) static float pfov = -1; if (pwidth != r_refdef.vrect.width || pheight != r_refdef.vrect.height - || pfov != scr_ffov->value) { + || pfov != scr_ffov) { pwidth = r_refdef.vrect.width; pheight = r_refdef.vrect.height; - pfov = scr_ffov->value; + pfov = scr_ffov; build_display_list (pwidth, pheight, pfov); } diff --git a/libs/video/renderer/gl/gl_lightmap.c b/libs/video/renderer/gl/gl_lightmap.c index a2ce210da..068f0ce00 100644 --- a/libs/video/renderer/gl/gl_lightmap.c +++ b/libs/video/renderer/gl/gl_lightmap.c @@ -452,7 +452,7 @@ do_subimage_2 (int i) static void GL_UploadLightmap (int i) { - switch (gl_lightmap_subimage->int_val) { + switch (gl_lightmap_subimage) { case 2: do_subimage_2 (i); break; @@ -526,15 +526,15 @@ gl_R_BlendLightmaps (void) } void -gl_overbright_f (cvar_t *var) +gl_overbright_f (void *data, const cvar_t *cvar) { int num; mod_brush_t *brush; - if (!var) + if (!cvar) return; - if (var->int_val) { + if (gl_overbright) { if (!gl_combine_capable && gl_mtex_capable) { Sys_Printf ("Warning: gl_overbright has no effect with " "gl_multitexture enabled if you don't have " @@ -547,7 +547,7 @@ gl_overbright_f (cvar_t *var) lm_src_blend = GL_DST_COLOR; lm_dest_blend = GL_SRC_COLOR; - switch (var->int_val) { + switch (gl_overbright) { case 2: lmshift = 9; gl_rgb_scale = 4.0; @@ -569,9 +569,6 @@ gl_overbright_f (cvar_t *var) gl_rgb_scale = 1.0; } - if (gl_multitexture) - gl_multitexture_f (gl_multitexture); - if (!gl_R_BuildLightMap) return; @@ -672,7 +669,7 @@ GL_BuildLightmaps (model_t **models, int num_models) qfglGenTextures (MAX_LIGHTMAPS, gl_lightmap_textures); } - switch (r_lightmap_components->int_val) { + switch (r_lightmap_components) { case 1: gl_internalformat = 1; gl_lightmap_format = GL_LUMINANCE; @@ -712,10 +709,7 @@ GL_BuildLightmaps (model_t **models, int num_models) gl_currentmodel = m; // non-bsp models don't have surfaces. for (unsigned i = 0; i < brush->numsurfaces; i++) { - if (brush->surfaces[i].flags & SURF_DRAWTURB) - continue; - if (gl_sky_divide->int_val && (brush->surfaces[i].flags & - SURF_DRAWSKY)) + if (brush->surfaces[i].flags & (SURF_DRAWTURB | SURF_DRAWSKY)) continue; GL_CreateSurfaceLightmap (brush, brush->surfaces + i); GL_BuildSurfaceDisplayList (brush, brush->surfaces + i); diff --git a/libs/video/renderer/gl/gl_mod_alias.c b/libs/video/renderer/gl/gl_mod_alias.c index a66cccbd1..7e28beea9 100644 --- a/libs/video/renderer/gl/gl_mod_alias.c +++ b/libs/video/renderer/gl/gl_mod_alias.c @@ -302,7 +302,7 @@ GL_GetAliasFrameVerts16 (aliashdr_t *paliashdr, entity_t *e) } vo->count = count; - if (!gl_lerp_anim->int_val) + if (!gl_lerp_anim) blend = 1.0; @@ -367,7 +367,7 @@ GL_GetAliasFrameVerts (aliashdr_t *paliashdr, entity_t *e) } vo->count = count; - if (!gl_lerp_anim->int_val) + if (!gl_lerp_anim) blend = 1.0; if (blend == 0.0) { @@ -467,7 +467,7 @@ gl_R_DrawAliasModel (entity_t *e) ambientcolor[0] = ambientcolor[1] = ambientcolor[2] = minlight; } - if (gl_vector_light->int_val) { + if (gl_vector_light) { for (l = r_dlights, lnum = 0; lnum < r_maxdlights; lnum++, l++) { if (l->die >= vr_data.realtime) { VectorSubtract (l->origin, origin, dist); @@ -560,11 +560,11 @@ gl_R_DrawAliasModel (entity_t *e) // if the model has a colorised/external skin, use it, otherwise use // the skin embedded in the model data - if (e->renderer.skin && e->renderer.skin->texnum && !gl_nocolors->int_val) { + if (e->renderer.skin && e->renderer.skin->texnum && !gl_nocolors) { skin_t *skin = e->renderer.skin; texture = skin->texnum; - if (gl_fb_models->int_val) { + if (gl_fb_models) { fb_texture = skin->auxtex; } } else { @@ -574,7 +574,7 @@ gl_R_DrawAliasModel (entity_t *e) skindesc = R_AliasGetSkindesc (animation, e->renderer.skinnum, paliashdr); texture = skindesc->texnum; - if (gl_fb_models->int_val && !is_fullbright) { + if (gl_fb_models && !is_fullbright) { fb_texture = skindesc->fb_texnum; } } @@ -607,7 +607,7 @@ gl_R_DrawAliasModel (entity_t *e) if (is_fullbright) { qfglBindTexture (GL_TEXTURE_2D, texture); - if (gl_vector_light->int_val) { + if (gl_vector_light) { qfglDisable (GL_LIGHTING); if (!gl_tess) qfglDisable (GL_NORMALIZE); @@ -618,7 +618,7 @@ gl_R_DrawAliasModel (entity_t *e) else GL_DrawAliasFrame (vo); - if (gl_vector_light->int_val) { + if (gl_vector_light) { if (!gl_tess) qfglEnable (GL_NORMALIZE); qfglEnable (GL_LIGHTING); @@ -653,7 +653,7 @@ gl_R_DrawAliasModel (entity_t *e) qfglBindTexture (GL_TEXTURE_2D, texture); GL_DrawAliasFrameTri (vo); - if (gl_vector_light->int_val) { + if (gl_vector_light) { qfglDisable (GL_LIGHTING); if (!gl_tess) qfglDisable (GL_NORMALIZE); @@ -664,7 +664,7 @@ gl_R_DrawAliasModel (entity_t *e) qfglBindTexture (GL_TEXTURE_2D, fb_texture); GL_DrawAliasFrameTri (vo); - if (gl_vector_light->int_val) { + if (gl_vector_light) { qfglEnable (GL_LIGHTING); if (!gl_tess) qfglEnable (GL_NORMALIZE); @@ -673,7 +673,7 @@ gl_R_DrawAliasModel (entity_t *e) qfglBindTexture (GL_TEXTURE_2D, texture); GL_DrawAliasFrame (vo); - if (gl_vector_light->int_val) { + if (gl_vector_light) { qfglDisable (GL_LIGHTING); if (!gl_tess) qfglDisable (GL_NORMALIZE); @@ -684,7 +684,7 @@ gl_R_DrawAliasModel (entity_t *e) qfglBindTexture (GL_TEXTURE_2D, fb_texture); GL_DrawAliasFrame (vo); - if (gl_vector_light->int_val) { + if (gl_vector_light) { qfglEnable (GL_LIGHTING); if (!gl_tess) qfglEnable (GL_NORMALIZE); @@ -696,7 +696,7 @@ gl_R_DrawAliasModel (entity_t *e) qfglPopMatrix (); // torches, grenades, and lightning bolts do not have shadows - if (r_shadows->int_val && model->shadow_alpha) { + if (r_shadows && model->shadow_alpha) { mat4f_t shadow_mat; qfglPushMatrix (); diff --git a/libs/video/renderer/gl/gl_rmain.c b/libs/video/renderer/gl/gl_rmain.c index a3b19615b..720bf9469 100644 --- a/libs/video/renderer/gl/gl_rmain.c +++ b/libs/video/renderer/gl/gl_rmain.c @@ -81,10 +81,9 @@ glrmain_init (void) gldepthmax = 1; qfglDepthFunc (GL_LEQUAL); qfglDepthRange (gldepthmin, gldepthmax); - if (gl_multitexture) - gl_multitexture_f (gl_multitexture); - if (gl_overbright) - gl_overbright_f (gl_overbright); + + gl_overbright_f (0, 0); + gl_multitexture_f (0, 0); } void @@ -98,7 +97,7 @@ gl_R_RotateForEntity (entity_t *e) void gl_R_RenderEntities (entqueue_t *queue) { - if (!r_drawentities->int_val) + if (!r_drawentities) return; // LordHavoc: split into 3 loops to simplify state changes @@ -110,13 +109,13 @@ gl_R_RenderEntities (entqueue_t *queue) qfglDisable (GL_TEXTURE_2D); qglActiveTexture (gl_mtex_enum + 0); } - if (gl_affinemodels->int_val) + if (gl_affinemodels) qfglHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); if (gl_tess) qfglEnable (GL_PN_TRIANGLES_ATI); qfglEnable (GL_CULL_FACE); - if (gl_vector_light->int_val) { + if (gl_vector_light) { qfglEnable (GL_LIGHTING); qfglEnable (GL_NORMALIZE); } else if (gl_tess) { @@ -134,13 +133,13 @@ gl_R_RenderEntities (entqueue_t *queue) if (gl_tess) qfglDisable (GL_PN_TRIANGLES_ATI); - if (gl_affinemodels->int_val) + if (gl_affinemodels) qfglHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_DONT_CARE); if (gl_mtex_active_tmus >= 2) { // FIXME: Ugly, but faster than cleaning // up in every R_DrawAliasModel()! qglActiveTexture (gl_mtex_enum + 1); qfglEnable (GL_TEXTURE_2D); - if (gl_combine_capable && gl_overbright->int_val) { + if (gl_combine_capable && gl_overbright) { qfglTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); qfglTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE); qfglTexEnvf (GL_TEXTURE_ENV, GL_RGB_SCALE, gl_rgb_scale); @@ -174,8 +173,8 @@ R_DrawViewModel (void) { entity_t *ent = vr_data.view_model; if (vr_data.inhibit_viewmodel - || !r_drawviewmodel->int_val - || !r_drawentities->int_val + || !r_drawviewmodel + || !r_drawentities || !ent->renderer.model) return; @@ -183,14 +182,14 @@ R_DrawViewModel (void) qfglDepthRange (gldepthmin, gldepthmin + 0.3 * (gldepthmax - gldepthmin)); qfglEnable (GL_CULL_FACE); - if (gl_vector_light->int_val) { + if (gl_vector_light) { qfglEnable (GL_LIGHTING); qfglEnable (GL_NORMALIZE); } else if (gl_tess) { qfglEnable (GL_NORMALIZE); } - if (gl_affinemodels->int_val) + if (gl_affinemodels) qfglHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); if (gl_mtex_active_tmus >= 2) { qglActiveTexture (gl_mtex_enum + 1); @@ -207,7 +206,7 @@ R_DrawViewModel (void) // up in every R_DrawAliasModel()! qglActiveTexture (gl_mtex_enum + 1); qfglEnable (GL_TEXTURE_2D); - if (gl_combine_capable && gl_overbright->int_val) { + if (gl_combine_capable && gl_overbright) { qfglTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); qfglTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE); qfglTexEnvf (GL_TEXTURE_ENV, GL_RGB_SCALE, gl_rgb_scale); @@ -218,7 +217,7 @@ R_DrawViewModel (void) qglActiveTexture (gl_mtex_enum + 0); } - if (gl_affinemodels->int_val) + if (gl_affinemodels) qfglHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_DONT_CARE); qfglDisable (GL_NORMALIZE); @@ -257,7 +256,7 @@ R_SetupGL (void) qfglDisable (GL_ALPHA_TEST); qfglAlphaFunc (GL_GREATER, 0.5); qfglEnable (GL_DEPTH_TEST); - if (gl_dlight_smooth->int_val) + if (gl_dlight_smooth) qfglShadeModel (GL_SMOOTH); else qfglShadeModel (GL_FLAT); @@ -266,7 +265,7 @@ R_SetupGL (void) void gl_R_RenderView (void) { - if (r_norefresh->int_val) { + if (r_norefresh) { return; } if (!r_refdef.worldmodel) { diff --git a/libs/video/renderer/gl/gl_rmisc.c b/libs/video/renderer/gl/gl_rmisc.c index fc72d7f96..f7056bcfb 100644 --- a/libs/video/renderer/gl/gl_rmisc.c +++ b/libs/video/renderer/gl/gl_rmisc.c @@ -115,7 +115,6 @@ void gl_R_Init (void) { R_Init_Cvars (); - gl_R_Particles_Init_Cvars (); Cmd_AddCommand ("timerefresh", gl_R_TimeRefresh_f, "Tests the current refresh rate for the current location"); diff --git a/libs/video/renderer/gl/gl_rsurf.c b/libs/video/renderer/gl/gl_rsurf.c index bb3f4a958..c9c143c08 100644 --- a/libs/video/renderer/gl/gl_rsurf.c +++ b/libs/video/renderer/gl/gl_rsurf.c @@ -291,7 +291,7 @@ R_AddToLightmapChain (glbspctx_t *bctx, msurface_t *surf, instsurf_t *sc) if ((surf->dlightframe == r_framecount) || surf->cached_dlight) { dynamic: - if (r_dynamic->int_val) { + if (r_dynamic) { gl_lightmap_modified[surf->lightmaptexturenum] = true; theRect = &gl_lightmap_rectchange[surf->lightmaptexturenum]; if (surf->light_t < theRect->t) { @@ -321,7 +321,7 @@ gl_R_DrawWaterSurfaces (void) int i; instsurf_t *s; msurface_t *surf; - float wateralpha = max (vr_data.min_wateralpha, r_wateralpha->value); + float wateralpha = max (vr_data.min_wateralpha, r_wateralpha); if (!waterchain) return; @@ -571,7 +571,7 @@ gl_R_DrawBrushModel (entity_t *e) } // calculate dynamic lighting for bmodel if it's not an instanced model - if (brush->firstmodelsurface != 0 && r_dlight_lightmap->int_val) { + if (brush->firstmodelsurface != 0 && r_dlight_lightmap) { vec3_t lightorigin; for (unsigned k = 0; k < r_maxdlights; k++) { @@ -727,7 +727,7 @@ gl_R_DrawWorld (void) sky_chain = 0; sky_chain_tail = &sky_chain; - if (!gl_sky_clip->int_val) { + if (!gl_sky_clip) { gl_R_DrawSky (); } @@ -740,7 +740,7 @@ gl_R_DrawWorld (void) gl_R_DrawSkyChain (sky_chain); - if (r_drawentities->int_val) { + if (r_drawentities) { for (size_t i = 0; i < r_ent_queue->ent_queues[mod_brush].size; i++) { \ entity_t *ent = r_ent_queue->ent_queues[mod_brush].a[i]; \ gl_R_DrawBrushModel (ent); @@ -748,7 +748,7 @@ gl_R_DrawWorld (void) } if (!Fog_GetDensity () - || (gl_fb_bmodels->int_val && gl_mtex_fullbright) + || (gl_fb_bmodels && gl_mtex_fullbright) || gl_mtex_active_tmus > 1) { // we have enough active TMUs to render everything in one go // or we're not doing fog @@ -757,7 +757,7 @@ gl_R_DrawWorld (void) if (gl_mtex_active_tmus <= 1) gl_R_BlendLightmaps (); - if (gl_fb_bmodels->int_val && !gl_mtex_fullbright) + if (gl_fb_bmodels && !gl_mtex_fullbright) R_RenderFullbrights (); } else { if (gl_mtex_active_tmus > 1) { @@ -877,7 +877,7 @@ GL_BuildSurfaceDisplayList (mod_brush_t *brush, msurface_t *surf) } // remove co-linear points - Ed - if (!gl_keeptjunctions->int_val && !(surf->flags & SURF_UNDERWATER)) { + if (!gl_keeptjunctions && !(surf->flags & SURF_UNDERWATER)) { for (i = 0; i < lnumverts; ++i) { vec3_t v1, v2; float *prev, *this, *next; diff --git a/libs/video/renderer/gl/gl_sky.c b/libs/video/renderer/gl/gl_sky.c index 47c6bc072..a66261294 100644 --- a/libs/video/renderer/gl/gl_sky.c +++ b/libs/video/renderer/gl/gl_sky.c @@ -115,7 +115,7 @@ gl_R_LoadSkys (const char *skyname) int i; // j if (!skyname || !*skyname) - skyname = r_skyname->string; + skyname = r_skyname; if (!*skyname || strcasecmp (skyname, "none") == 0) { gl_skyloaded = false; @@ -370,13 +370,13 @@ R_DrawSkyDome (void) qfglEnable (GL_BLEND); // clouds - if (gl_sky_multipass->int_val) { + if (gl_sky_multipass) { qfglBindTexture (GL_TEXTURE_2D, gl_alphaskytexture); speedscale = vr_data.realtime / 8.0; speedscale -= floor (speedscale); R_DrawSkyLayer (speedscale); } - if (gl_sky_debug->int_val) { + if (gl_sky_debug) { skydome_debug (); } } diff --git a/libs/video/renderer/gl/gl_sky_clip.c b/libs/video/renderer/gl/gl_sky_clip.c index fc1331dc8..e069c8768 100644 --- a/libs/video/renderer/gl/gl_sky_clip.c +++ b/libs/video/renderer/gl/gl_sky_clip.c @@ -750,7 +750,7 @@ draw_id_sky_polys (const instsurf_t *sky_chain) sc = sc->tex_chain; } - if (gl_sky_multipass->int_val) { + if (gl_sky_multipass) { sc = sky_chain; speedscale = vr_data.realtime / 8; @@ -797,19 +797,19 @@ draw_z_sky_polys (const instsurf_t *sky_chain) void gl_R_DrawSkyChain (const instsurf_t *sky_chain) { - if (gl_sky_clip->int_val > 2) { + if (gl_sky_clip > 2) { draw_black_sky_polys (sky_chain); return; } if (gl_skyloaded) { - if (gl_sky_clip->int_val) { + if (gl_sky_clip) { draw_skybox_sky_polys (sky_chain); } draw_z_sky_polys (sky_chain); - } else if (gl_sky_clip->int_val == 2) { + } else if (gl_sky_clip == 2) { draw_id_sky_polys (sky_chain); - } else if (gl_sky_clip->int_val) { + } else if (gl_sky_clip) { // XXX not properly implemented draw_skydome_sky_polys (sky_chain); //draw_z_sky_polys (sky_chain); @@ -817,11 +817,11 @@ gl_R_DrawSkyChain (const instsurf_t *sky_chain) draw_z_sky_polys (sky_chain); } - if (gl_sky_debug->int_val) { + if (gl_sky_debug) { const instsurf_t *sc; qfglDisable (GL_TEXTURE_2D); - if (gl_sky_debug->int_val & 1) { + if (gl_sky_debug & 1) { sc = sky_chain; qfglColor3ub (255, 255, 255); while (sc) { @@ -846,7 +846,7 @@ gl_R_DrawSkyChain (const instsurf_t *sky_chain) sc = sc->tex_chain; } } - if (gl_sky_debug->int_val & 2) { + if (gl_sky_debug & 2) { sc = sky_chain; qfglColor3ub (0, 255, 0); qfglBegin (GL_POINTS); @@ -876,7 +876,7 @@ gl_R_DrawSkyChain (const instsurf_t *sky_chain) } qfglEnd (); } - if (gl_sky_debug->int_val & 4) { + if (gl_sky_debug & 4) { if (gl_skyloaded) { int i, j; diff --git a/libs/video/renderer/gl/gl_textures.c b/libs/video/renderer/gl/gl_textures.c index 9beb146dc..e0c7d893d 100644 --- a/libs/video/renderer/gl/gl_textures.c +++ b/libs/video/renderer/gl/gl_textures.c @@ -374,11 +374,11 @@ GL_Upload32 (unsigned int *data, int width, int height, qboolean mipmap, for (scaled_width = 1; scaled_width < width; scaled_width <<= 1); for (scaled_height = 1; scaled_height < height; scaled_height <<= 1); - scaled_width >>= gl_picmip->int_val; - scaled_height >>= gl_picmip->int_val; + scaled_width >>= gl_picmip; + scaled_height >>= gl_picmip; - scaled_width = min (scaled_width, gl_max_size->int_val); - scaled_height = min (scaled_height, gl_max_size->int_val); + scaled_width = min (scaled_width, gl_max_size); + scaled_height = min (scaled_height, gl_max_size); if (!(scaled = malloc (scaled_width * scaled_height * sizeof (GLuint)))) Sys_Error ("GL_LoadTexture: too big"); @@ -421,7 +421,7 @@ GL_Upload32 (unsigned int *data, int width, int height, qboolean mipmap, } else { qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_max); - if (gl_picmip->int_val) + if (gl_picmip) qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); else @@ -452,11 +452,11 @@ GL_Upload8_EXT (const byte *data, int width, int height, qboolean mipmap, for (scaled_width = 1; scaled_width < width; scaled_width <<= 1); for (scaled_height = 1; scaled_height < height; scaled_height <<= 1); - scaled_width >>= gl_picmip->int_val; - scaled_height >>= gl_picmip->int_val; + scaled_width >>= gl_picmip; + scaled_height >>= gl_picmip; - scaled_width = min (scaled_width, gl_max_size->int_val); - scaled_height = min (scaled_height, gl_max_size->int_val); + scaled_width = min (scaled_width, gl_max_size); + scaled_height = min (scaled_height, gl_max_size); if (!(scaled = malloc (scaled_width * scaled_height))) Sys_Error ("GL_LoadTexture: too big"); @@ -498,7 +498,7 @@ GL_Upload8_EXT (const byte *data, int width, int height, qboolean mipmap, } else { qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_max); - if (gl_picmip->int_val) + if (gl_picmip) qfglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); else diff --git a/libs/video/renderer/gl/gl_warp.c b/libs/video/renderer/gl/gl_warp.c index 4ae963cf7..f7a0b9ee4 100644 --- a/libs/video/renderer/gl/gl_warp.c +++ b/libs/video/renderer/gl/gl_warp.c @@ -70,11 +70,11 @@ GL_EmitWaterPolys (msurface_t *surf) t = (v[4] + os) * (1.0 / 64.0); qfglTexCoord2f (s, t); - if (r_waterripple->value != 0) { + if (r_waterripple != 0) { vec3_t nv; VectorCopy (v, nv); - nv[2] += r_waterripple->value * os * ot * (1.0 / 64.0); + nv[2] += r_waterripple * os * ot * (1.0 / 64.0); qfglVertex3fv (nv); } else qfglVertex3fv (v); diff --git a/libs/video/renderer/gl/vid_common_gl.c b/libs/video/renderer/gl/vid_common_gl.c index e0e5f5231..4ff4b85fe 100644 --- a/libs/video/renderer/gl/vid_common_gl.c +++ b/libs/video/renderer/gl/vid_common_gl.c @@ -112,73 +112,358 @@ int gl_tess; // GL_LIGHT int gl_max_lights; -cvar_t *gl_anisotropy; -cvar_t *gl_fb_bmodels; -cvar_t *gl_finish; -cvar_t *gl_max_size; -cvar_t *gl_multitexture; -cvar_t *gl_tessellate; -cvar_t *gl_textures_bgra; -cvar_t *gl_vaelements_max; -cvar_t *gl_vector_light; -cvar_t *gl_screenshot_byte_swap; +float gl_anisotropy; +static cvar_t gl_anisotropy_cvar = { + .name = "gl_anisotropy", + .description = 0, + .default_value = "1.0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &gl_anisotropy }, +}; +int gl_fb_bmodels; +static cvar_t gl_fb_bmodels_cvar = { + .name = "gl_fb_bmodels", + .description = + "Toggles fullbright color support for bmodels", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &gl_fb_bmodels }, +}; +int gl_finish; +static cvar_t gl_finish_cvar = { + .name = "gl_finish", + .description = + "wait for rendering to finish", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &gl_finish }, +}; +int gl_max_size; +static cvar_t gl_max_size_cvar = { + .name = "gl_max_size", + .description = + "Texture dimension", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &gl_max_size }, +}; +int gl_multitexture; +static cvar_t gl_multitexture_cvar = { + .name = "gl_multitexture", + .description = + "Use multitexture when available.", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &gl_multitexture }, +}; +int gl_tessellate; +static cvar_t gl_tessellate_cvar = { + .name = "gl_tessellate", + .description = 0, + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &gl_tessellate }, +}; +int gl_textures_bgra; +static cvar_t gl_textures_bgra_cvar = { + .name = "gl_textures_bgra", + .description = + "If set to 1, try to use BGR & BGRA textures instead of RGB & RGBA.", + .default_value = "0", + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &gl_textures_bgra }, +}; +int gl_vaelements_max; +static cvar_t gl_vaelements_max_cvar = { + .name = "gl_vaelements_max", + .description = + "Limit the vertex array size for buggy drivers. 0 (default) uses " + "driver provided limit, -1 disables use of vertex arrays.", + .default_value = "0", + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &gl_vaelements_max }, +}; +int gl_vector_light; +static cvar_t gl_vector_light_cvar = { + .name = "gl_vector_light", + .description = + "Enable use of GL vector lighting. 0 = flat lighting.", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &gl_vector_light }, +}; +int gl_screenshot_byte_swap; +static cvar_t gl_screenshot_byte_swap_cvar = { + .name = "gl_screenshot_byte_swap", + .description = + "Swap the bytes for gl screenshots. Needed if you get screenshots with" + " red and blue swapped.", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &gl_screenshot_byte_swap }, +}; -cvar_t *gl_affinemodels; -cvar_t *gl_clear; -cvar_t *gl_conspin; -cvar_t *gl_constretch; -cvar_t *gl_dlight_polyblend; -cvar_t *gl_dlight_smooth; -cvar_t *gl_driver; -cvar_t *gl_fb_models; -cvar_t *gl_keeptjunctions; -cvar_t *gl_lerp_anim; -cvar_t *gl_lightmap_align; -cvar_t *gl_lightmap_subimage; -cvar_t *gl_nocolors; -cvar_t *gl_overbright; -cvar_t *gl_particle_mip; -cvar_t *gl_particle_size; -cvar_t *gl_picmip; -cvar_t *gl_playermip; -cvar_t *gl_reporttjunctions; -cvar_t *gl_sky_clip; -cvar_t *gl_sky_debug; -cvar_t *gl_sky_multipass; -cvar_t *gl_texsort; -cvar_t *gl_triplebuffer; -static cvar_t *vid_use8bit; +int gl_affinemodels; +static cvar_t gl_affinemodels_cvar = { + .name = "gl_affinemodels", + .description = + "Makes texture rendering quality better if set to 1", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &gl_affinemodels }, +}; +int gl_clear; +static cvar_t gl_clear_cvar = { + .name = "gl_clear", + .description = + "Set to 1 to make background black. Useful for removing HOM effect", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &gl_clear }, +}; +float gl_conspin; +static cvar_t gl_conspin_cvar = { + .name = "gl_conspin", + .description = + "speed at which the console spins", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &gl_conspin }, +}; +int gl_constretch; +static cvar_t gl_constretch_cvar = { + .name = "gl_constretch", + .description = + "toggle console between slide and stretch", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &gl_constretch }, +}; +int gl_dlight_polyblend; +static cvar_t gl_dlight_polyblend_cvar = { + .name = "gl_dlight_polyblend", + .description = + "Set to 1 to use a dynamic light effect faster on GL", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &gl_dlight_polyblend }, +}; +int gl_dlight_smooth; +static cvar_t gl_dlight_smooth_cvar = { + .name = "gl_dlight_smooth", + .description = + "Smooth dynamic vertex lighting", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &gl_dlight_smooth }, +}; +int gl_fb_models; +static cvar_t gl_fb_models_cvar = { + .name = "gl_fb_models", + .description = + "Toggles fullbright color support for models", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &gl_fb_models }, +}; +int gl_keeptjunctions; +static cvar_t gl_keeptjunctions_cvar = { + .name = "gl_keeptjunctions", + .description = + "Set to 0 to turn off colinear vertexes upon level load.", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &gl_keeptjunctions }, +}; +int gl_lerp_anim; +static cvar_t gl_lerp_anim_cvar = { + .name = "gl_lerp_anim", + .description = + "Toggles model animation interpolation", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &gl_lerp_anim }, +}; +int gl_lightmap_align; +static cvar_t gl_lightmap_align_cvar = { + .name = "gl_lightmap_align", + .description = + "Workaround for nvidia slow path. Set to 4 or 16 if you have an nvidia" + " 3d accelerator, set to 1 otherwise.", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &gl_lightmap_align }, +}; +int gl_lightmap_subimage; +static cvar_t gl_lightmap_subimage_cvar = { + .name = "gl_lightmap_subimage", + .description = + "Lightmap Update method. Default 2 updates a minimum 'dirty rectangle'" + " around the area changed. 1 updates every line that changed. 0 " + "updates the entire lightmap.", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &gl_lightmap_subimage }, +}; +int gl_nocolors; +static cvar_t gl_nocolors_cvar = { + .name = "gl_nocolors", + .description = + "Set to 1, turns off all player colors", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &gl_nocolors }, +}; +int gl_overbright; +static cvar_t gl_overbright_cvar = { + .name = "gl_overbright", + .description = + "Darken lightmaps so that dynamic lights can be overbright. 1 = 0.75 " + "brightness, 2 = 0.5 brightness.", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &gl_overbright }, +}; +int gl_particle_mip; +static cvar_t gl_particle_mip_cvar = { + .name = "gl_particle_mip", + .description = + "Toggles particle texture mipmapping.", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &gl_particle_mip }, +}; +int gl_particle_size; +static cvar_t gl_particle_size_cvar = { + .name = "gl_particle_size", + .description = + "Vertical and horizontal size of particle textures as a power of 2. " + "Default is 5 (32 texel square).", + .default_value = "5", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &gl_particle_size }, +}; +int gl_picmip; +static cvar_t gl_picmip_cvar = { + .name = "gl_picmip", + .description = + "Dimensions of textures. 0 is normal, 1 is half, 2 is 1/4", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &gl_picmip }, +}; +int gl_playermip; +static cvar_t gl_playermip_cvar = { + .name = "gl_playermip", + .description = + "Detail of player skins. 0 best, 4 worst.", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &gl_playermip }, +}; +int gl_reporttjunctions; +static cvar_t gl_reporttjunctions_cvar = { + .name = "gl_reporttjunctions", + .description = + "None", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &gl_reporttjunctions }, +}; +int gl_sky_clip; +static cvar_t gl_sky_clip_cvar = { + .name = "gl_sky_clip", + .description = + "controls amount of sky overdraw", + .default_value = "2", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &gl_sky_clip }, +}; +int gl_sky_debug; +static cvar_t gl_sky_debug_cvar = { + .name = "gl_sky_debug", + .description = + "debugging `info' for sky clipping", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &gl_sky_debug }, +}; +int gl_sky_divide; +static cvar_t gl_sky_divide_cvar = { + .name = "gl_sky_divide", + .description = + "subdivide sky polys", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &gl_sky_divide }, +}; +int gl_sky_multipass; +static cvar_t gl_sky_multipass_cvar = { + .name = "gl_sky_multipass", + .description = + "controls whether the skydome is single or double pass", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &gl_sky_multipass }, +}; +int gl_texsort; +static cvar_t gl_texsort_cvar = { + .name = "gl_texsort", + .description = + "None", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &gl_texsort }, +}; +int gl_triplebuffer; +static cvar_t gl_triplebuffer_cvar = { + .name = "gl_triplebuffer", + .description = + "Set to 1 by default. Fixes status bar flicker on some hardware", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &gl_triplebuffer }, +}; +static int vid_use8bit; +static cvar_t vid_use8bit_cvar = { + .name = "vid_use8bit", + .description = + "Use 8-bit shared palettes.", + .default_value = "0", + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &vid_use8bit }, +}; static void -gl_triplebuffer_f (cvar_t *var) +gl_triplebuffer_f (void *data, const cvar_t *cvar) { - vid.numpages = var->int_val ? 3 : 2; + vid.numpages = gl_triplebuffer ? 3 : 2; } static void -gl_max_size_f (cvar_t *var) +gl_max_size_f (void *data, const cvar_t *cvar) { GLint texSize; - if (!var) + if (!cvar) return; // Check driver's max texture size qfglGetIntegerv (GL_MAX_TEXTURE_SIZE, &texSize); - if (var->int_val < 1) { - Cvar_SetValue (var, texSize); + if (gl_max_size < 1) { + gl_max_size = texSize; } else { - Cvar_SetValue (var, bound (1, var->int_val, texSize)); + gl_max_size = bound (1, gl_max_size, texSize); } } static void -gl_textures_bgra_f (cvar_t *var) +gl_textures_bgra_f (void *data, const cvar_t *cvar) { - if (!var) + if (!cvar) return; - if (var->int_val && gl_bgra_capable) { + if (gl_textures_bgra && gl_bgra_capable) { gl_use_bgra = 1; } else { gl_use_bgra = 0; @@ -186,12 +471,12 @@ gl_textures_bgra_f (cvar_t *var) } static void -gl_fb_bmodels_f (cvar_t *var) +gl_fb_bmodels_f (void *data, const cvar_t *cvar) { - if (!var) + if (!cvar) return; - if (var->int_val && gl_mtex_tmus >= 3) { + if (gl_fb_bmodels && gl_mtex_tmus >= 3) { gl_mtex_fullbright = true; } else { gl_mtex_fullbright = false; @@ -199,16 +484,13 @@ gl_fb_bmodels_f (cvar_t *var) } void -gl_multitexture_f (cvar_t *var) +gl_multitexture_f (void *data, const cvar_t *cvar) { - if (!var) - return; - - if (var->int_val && gl_mtex_capable) { + if (gl_multitexture && gl_mtex_capable) { gl_mtex_active_tmus = gl_mtex_tmus; if (gl_fb_bmodels) { - if (gl_fb_bmodels->int_val) { + if (gl_fb_bmodels) { if (gl_mtex_tmus >= 3) { gl_mtex_fullbright = true; @@ -231,7 +513,7 @@ gl_multitexture_f (cvar_t *var) qglActiveTexture (gl_mtex_enum + 1); qfglEnable (GL_TEXTURE_2D); if (gl_overbright) { - if (gl_combine_capable && gl_overbright->int_val) { + if (gl_combine_capable && gl_overbright) { qfglTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); qfglTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE); qfglTexEnvf (GL_TEXTURE_ENV, GL_RGB_SCALE, gl_rgb_scale); @@ -252,19 +534,19 @@ gl_multitexture_f (cvar_t *var) } static void -gl_screenshot_byte_swap_f (cvar_t *var) +gl_screenshot_byte_swap_f (void *data, const cvar_t *cvar) { - if (var) + if (cvar) qfglPixelStorei (GL_PACK_SWAP_BYTES, - var->int_val ? GL_TRUE : GL_FALSE); + gl_screenshot_byte_swap ? GL_TRUE : GL_FALSE); } static void -gl_anisotropy_f (cvar_t * var) +gl_anisotropy_f (void *data, const cvar_t *var) { if (gl_Anisotropy) { if (var) - gl_aniso = (bound (1.0, var->value, aniso_max)); + gl_aniso = (bound (1.0, gl_anisotropy, aniso_max)); else gl_aniso = 1.0; } else { @@ -278,11 +560,11 @@ gl_anisotropy_f (cvar_t * var) } static void -gl_tessellate_f (cvar_t * var) +gl_tessellate_f (void *data, const cvar_t *var) { if (TruForm) { if (var) - gl_tess = (bound (0, var->int_val, tess_max)); + gl_tess = (bound (0, gl_tessellate, tess_max)); else gl_tess = 0; qfglPNTrianglesiATI (GL_PN_TRIANGLES_TESSELATION_LEVEL_ATI, gl_tess); @@ -296,117 +578,69 @@ gl_tessellate_f (cvar_t * var) } static void -gl_vaelements_max_f (cvar_t *var) +gl_vaelements_max_f (void *data, const cvar_t *cvar) { - if (var->int_val) - vaelements = min (var->int_val, driver_vaelements); + if (gl_vaelements_max) + vaelements = min (gl_vaelements_max, driver_vaelements); else vaelements = driver_vaelements; } +static void +gl_sky_divide_f (void *data, const cvar_t *cvar) +{ + mod_sky_divide = gl_sky_divide; +} + static void GL_Common_Init_Cvars (void) { - vid_use8bit = Cvar_Get ("vid_use8bit", "0", CVAR_ROM, NULL, "Use 8-bit " - "shared palettes."); - gl_textures_bgra = Cvar_Get ("gl_textures_bgra", "0", CVAR_ROM, - gl_textures_bgra_f, "If set to 1, try to use " - "BGR & BGRA textures instead of RGB & RGBA."); - gl_fb_bmodels = Cvar_Get ("gl_fb_bmodels", "1", CVAR_ARCHIVE, - gl_fb_bmodels_f, "Toggles fullbright color " - "support for bmodels"); - gl_finish = Cvar_Get ("gl_finish", "1", CVAR_ARCHIVE, NULL, - "wait for rendering to finish"); - gl_max_size = Cvar_Get ("gl_max_size", "0", CVAR_NONE, gl_max_size_f, - "Texture dimension"); - gl_multitexture = Cvar_Get ("gl_multitexture", "1", CVAR_ARCHIVE, - gl_multitexture_f, "Use multitexture when " - "available."); - gl_screenshot_byte_swap = - Cvar_Get ("gl_screenshot_byte_swap", "0", CVAR_NONE, - gl_screenshot_byte_swap_f, "Swap the bytes for gl " - "screenshots. Needed if you get screenshots with red and " - "blue swapped."); - gl_anisotropy = - Cvar_Get ("gl_anisotropy", "1.0", CVAR_NONE, gl_anisotropy_f, - nva ("Specifies degree of anisotropy, from 1.0 to %f. " - "Higher anisotropy means less distortion of textures " - "at shallow angles to the viewer.", aniso_max)); - gl_tessellate = - Cvar_Get ("gl_tessellate", "0", CVAR_NONE, gl_tessellate_f, - nva ("Specifies tessellation level from 0 to %i. Higher " - "tessellation level means more triangles.", tess_max)); - gl_vaelements_max = Cvar_Get ("gl_vaelements_max", "0", CVAR_ROM, - gl_vaelements_max_f, - "Limit the vertex array size for buggy " - "drivers. 0 (default) uses driver provided " - "limit, -1 disables use of vertex arrays."); - gl_vector_light = Cvar_Get ("gl_vector_light", "1", CVAR_NONE, NULL, - "Enable use of GL vector lighting. 0 = flat lighting."); - gl_affinemodels = Cvar_Get ("gl_affinemodels", "0", CVAR_ARCHIVE, NULL, - "Makes texture rendering quality better if " - "set to 1"); - gl_clear = Cvar_Get ("gl_clear", "0", CVAR_NONE, NULL, "Set to 1 to make " - "background black. Useful for removing HOM effect"); - gl_conspin = Cvar_Get ("gl_conspin", "0", CVAR_ARCHIVE, NULL, - "speed at which the console spins"); - gl_constretch = Cvar_Get ("gl_constretch", "0", CVAR_ARCHIVE, NULL, - "toggle console between slide and stretch"); - gl_dlight_polyblend = Cvar_Get ("gl_dlight_polyblend", "0", CVAR_ARCHIVE, - NULL, "Set to 1 to use a dynamic light " - "effect faster on GL"); - gl_dlight_smooth = Cvar_Get ("gl_dlight_smooth", "1", CVAR_ARCHIVE, NULL, - "Smooth dynamic vertex lighting"); - gl_fb_models = Cvar_Get ("gl_fb_models", "1", CVAR_ARCHIVE, NULL, - "Toggles fullbright color support for models"); - gl_keeptjunctions = Cvar_Get ("gl_keeptjunctions", "1", CVAR_ARCHIVE, NULL, - "Set to 0 to turn off colinear vertexes " - "upon level load."); - gl_lerp_anim = Cvar_Get ("gl_lerp_anim", "1", CVAR_ARCHIVE, NULL, - "Toggles model animation interpolation"); + Cvar_Register (&vid_use8bit_cvar, 0, 0); + Cvar_Register (&gl_textures_bgra_cvar, gl_textures_bgra_f, 0); + Cvar_Register (&gl_fb_bmodels_cvar, gl_fb_bmodels_f, 0); + Cvar_Register (&gl_finish_cvar, 0, 0); + Cvar_Register (&gl_max_size_cvar, gl_max_size_f, 0); + Cvar_Register (&gl_multitexture_cvar, gl_multitexture_f, 0); + Cvar_Register (&gl_screenshot_byte_swap_cvar, gl_screenshot_byte_swap_f, 0); + Cvar_Register (&gl_anisotropy_cvar, gl_anisotropy_f, 0); + gl_anisotropy_cvar.description = nva ( + "Specifies degree of anisotropy, from 1.0 to %f. Higher anisotropy " + "means less distortion of textures at shallow angles to the viewer.", + aniso_max); + Cvar_Register (&gl_tessellate_cvar, gl_tessellate_f, 0); + gl_tessellate_cvar.description = nva ( + "Specifies tessellation level from 0 to %i. Higher tessellation level " + "means more triangles.", + tess_max); + Cvar_Register (&gl_vaelements_max_cvar, gl_vaelements_max_f, 0); + Cvar_Register (&gl_vector_light_cvar, 0, 0); + Cvar_Register (&gl_affinemodels_cvar, 0, 0); + Cvar_Register (&gl_clear_cvar, 0, 0); + Cvar_Register (&gl_conspin_cvar, 0, 0); + Cvar_Register (&gl_constretch_cvar, 0, 0); + Cvar_Register (&gl_dlight_polyblend_cvar, 0, 0); + Cvar_Register (&gl_dlight_smooth_cvar, 0, 0); + Cvar_Register (&gl_fb_models_cvar, 0, 0); + Cvar_Register (&gl_keeptjunctions_cvar, 0, 0); + Cvar_Register (&gl_lerp_anim_cvar, 0, 0); - gl_lightmap_align = Cvar_Get ("gl_lightmap_align", "1", CVAR_NONE, NULL, - "Workaround for nvidia slow path. Set to 4 " - "or 16 if you have an nvidia 3d " - "accelerator, set to 1 otherwise."); - gl_lightmap_subimage = Cvar_Get ("gl_lightmap_subimage", "1", CVAR_NONE, - NULL, "Lightmap Update method. Default 2 " - "updates a minimum 'dirty rectangle' " - "around the area changed. 1 updates " - "every line that changed. 0 updates the " - "entire lightmap."); - gl_nocolors = Cvar_Get ("gl_nocolors", "0", CVAR_NONE, NULL, - "Set to 1, turns off all player colors"); - gl_overbright = Cvar_Get ("gl_overbright", "0", CVAR_NONE, - gl_overbright_f, "Darken lightmaps so that " - "dynamic lights can be overbright. 1 = 0.75 " - "brightness, 2 = 0.5 brightness."); - gl_particle_mip = Cvar_Get ("gl_particle_mip", "0", CVAR_NONE, NULL, - "Toggles particle texture mipmapping."); - gl_particle_size = Cvar_Get ("gl_particle_size", "5", CVAR_NONE, NULL, - "Vertical and horizontal size of particle " - "textures as a power of 2. Default is 5 " - "(32 texel square)."); - gl_picmip = Cvar_Get ("gl_picmip", "0", CVAR_NONE, NULL, "Dimensions of " - "textures. 0 is normal, 1 is half, 2 is 1/4"); - gl_playermip = Cvar_Get ("gl_playermip", "0", CVAR_NONE, NULL, - "Detail of player skins. 0 best, 4 worst."); - gl_reporttjunctions = Cvar_Get ("gl_reporttjunctions", "0", CVAR_NONE, - NULL, "None"); - gl_sky_clip = Cvar_Get ("gl_sky_clip", "2", CVAR_ARCHIVE, NULL, - "controls amount of sky overdraw"); - gl_sky_debug = Cvar_Get ("gl_sky_debug", "0", CVAR_NONE, NULL, - "debugging `info' for sky clipping"); - gl_sky_divide = Cvar_Get ("gl_sky_divide", "1", CVAR_ARCHIVE, NULL, - "subdivide sky polys"); - gl_sky_multipass = Cvar_Get ("gl_sky_multipass", "1", CVAR_ARCHIVE, NULL, - "controls whether the skydome is single or " - "double pass"); - gl_texsort = Cvar_Get ("gl_texsort", "1", CVAR_NONE, NULL, "None"); - gl_triplebuffer = Cvar_Get ("gl_triplebuffer", "1", CVAR_ARCHIVE, - gl_triplebuffer_f, - "Set to 1 by default. Fixes status bar " - "flicker on some hardware"); + Cvar_Register (&gl_lightmap_align_cvar, 0, 0); + Cvar_Register (&gl_lightmap_subimage_cvar, 0, 0); + Cvar_Register (&gl_nocolors_cvar, 0, 0); + Cvar_Register (&gl_overbright_cvar, gl_overbright_f, 0); + Cvar_Register (&gl_particle_mip_cvar, 0, 0); + Cvar_Register (&gl_particle_size_cvar, 0, 0); + Cvar_Register (&gl_picmip_cvar, 0, 0); + Cvar_Register (&gl_playermip_cvar, 0, 0); + Cvar_Register (&gl_reporttjunctions_cvar, 0, 0); + Cvar_Register (&gl_sky_clip_cvar, 0, 0); + Cvar_Register (&gl_sky_debug_cvar, 0, 0); + Cvar_Register (&gl_sky_divide_cvar, gl_sky_divide_f, 0); + Cvar_Register (&gl_sky_multipass_cvar, 0, 0); + Cvar_Register (&gl_texsort_cvar, 0, 0); + Cvar_Register (&gl_triplebuffer_cvar, gl_triplebuffer_f, 0); + + Cvar_AddListener (&gl_overbright_cvar, gl_multitexture_f, 0); } static void @@ -689,7 +923,7 @@ static void VID_Init8bitPalette (void) { Sys_MaskPrintf (SYS_vid, "Checking for 8-bit extension: "); - if (vid_use8bit->int_val) { + if (vid_use8bit) { Tdfx_Init8bitPalette (); Shared_Init8bitPalette (); if (!vr_data.vid->is8bit) diff --git a/libs/video/renderer/glsl/glsl_alias.c b/libs/video/renderer/glsl/glsl_alias.c index 3ecf33bc6..efb814251 100644 --- a/libs/video/renderer/glsl/glsl_alias.c +++ b/libs/video/renderer/glsl/glsl_alias.c @@ -186,7 +186,7 @@ set_arrays (const shaderparam_t *vert, const shaderparam_t *norm, { byte *pose_offs = (byte *) pose; - if (developer->int_val & SYS_glsl) { + if (developer & SYS_glsl) { GLint size; qfeglGetBufferParameteriv (GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); diff --git a/libs/video/renderer/glsl/glsl_bsp.c b/libs/video/renderer/glsl/glsl_bsp.c index 7ae7dec1e..cfdcec3b9 100644 --- a/libs/video/renderer/glsl/glsl_bsp.c +++ b/libs/video/renderer/glsl/glsl_bsp.c @@ -374,7 +374,7 @@ update_lightmap (glslbspctx_t *bctx, msurface_t *surf) if ((surf->dlightframe == r_framecount) || surf->cached_dlight) { dynamic: - if (r_dynamic->int_val) + if (r_dynamic) glsl_R_BuildLightMap (bctx->entity->transform, bctx->brush, surf); } } @@ -698,7 +698,7 @@ R_DrawBrushModel (entity_t *e) } // calculate dynamic lighting for bmodel if it's not an instanced model - if (brush->firstmodelsurface != 0 && r_dlight_lightmap->int_val) { + if (brush->firstmodelsurface != 0 && r_dlight_lightmap) { vec3_t lightorigin; for (k = 0; k < r_maxdlights; k++) { @@ -936,7 +936,7 @@ turb_begin (void) { quat_t fog; - default_color[3] = bound (0, r_wateralpha->value, 1); + default_color[3] = bound (0, r_wateralpha, 1); QuatCopy (default_color, last_color); qfeglVertexAttrib4fv (quake_bsp.color.location, default_color); @@ -1146,7 +1146,7 @@ glsl_R_DrawWorld (void) bctx.entity = &worldent; R_VisitWorldNodes (&bctx); - if (r_drawentities->int_val) { + if (r_drawentities) { for (size_t i = 0; i < r_ent_queue->ent_queues[mod_brush].size; i++) { entity_t *ent = r_ent_queue->ent_queues[mod_brush].a[i]; R_DrawBrushModel (ent); @@ -1405,7 +1405,7 @@ glsl_R_LoadSkys (const char *sky) }; if (!sky || !*sky) - sky = r_skyname->string; + sky = r_skyname; if (!*sky || !strcasecmp (sky, "none")) { skybox_loaded = false; diff --git a/libs/video/renderer/glsl/glsl_draw.c b/libs/video/renderer/glsl/glsl_draw.c index 47b99575b..1b85edd87 100644 --- a/libs/video/renderer/glsl/glsl_draw.c +++ b/libs/video/renderer/glsl/glsl_draw.c @@ -110,7 +110,15 @@ static qpic_t *crosshair_pic; static qpic_t *white_pic; static qpic_t *backtile_pic; static hashtab_t *pic_cache; -static cvar_t *glsl_conback_texnum; +static int glsl_conback_texnum; +static cvar_t glsl_conback_texnum_cvar = { + .name = "glsl_conback_texnum", + .description = + "bind conback to this texture for debugging", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &glsl_conback_texnum }, +}; static qpic_t * make_glpic (const char *name, qpic_t *p) @@ -377,7 +385,7 @@ glsl_Draw_Init (void) QFS_GamedirCallback (Draw_ClearCache); //FIXME temporary work around for the timing of cvar creation and palette //loading - crosshaircolor->callback (crosshaircolor); + //crosshaircolor->callback (crosshaircolor); draw_queue = dstring_new (); @@ -427,9 +435,7 @@ glsl_Draw_Init (void) //FIXME qfeglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //FIXME qfeglTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - glsl_conback_texnum = Cvar_Get ("glsl_conback_texnum", "0", CVAR_NONE, - NULL, "bind conback to this texture for " - "debugging"); + Cvar_Register (&glsl_conback_texnum_cvar, 0, 0); } static inline void @@ -568,10 +574,10 @@ glsl_Draw_Crosshair (void) { int x, y; - x = vid.conview->xlen / 2 + cl_crossx->int_val; - y = vid.conview->ylen / 2 + cl_crossy->int_val; + x = vid.conview->xlen / 2 + cl_crossx; + y = vid.conview->ylen / 2 + cl_crossy; - glsl_Draw_CrosshairAt (crosshair->int_val, x, y); + glsl_Draw_CrosshairAt (crosshair, x, y); } void @@ -621,8 +627,8 @@ glsl_Draw_ConsoleBackground (int lines, byte alpha) QuatCopy (color, verts[4].color); QuatCopy (color, verts[5].color); - if (glsl_conback_texnum->int_val) - qfeglBindTexture (GL_TEXTURE_2D, glsl_conback_texnum->int_val); + if (glsl_conback_texnum) + qfeglBindTexture (GL_TEXTURE_2D, glsl_conback_texnum); else qfeglBindTexture (GL_TEXTURE_2D, conback_texture); diff --git a/libs/video/renderer/glsl/glsl_fisheye.c b/libs/video/renderer/glsl/glsl_fisheye.c index 2635d8ffe..edd7c9871 100644 --- a/libs/video/renderer/glsl/glsl_fisheye.c +++ b/libs/video/renderer/glsl/glsl_fisheye.c @@ -104,7 +104,7 @@ glsl_FisheyeScreen (framebuffer_t *fb) { qfeglUseProgram (fisheye.program); - qfeglUniform1f (fisheye.fov.location, scr_ffov->value * M_PI / 360); + qfeglUniform1f (fisheye.fov.location, scr_ffov * M_PI / 360); qfeglUniform1f (fisheye.aspect.location, (float) r_refdef.vrect.height / r_refdef.vrect.width); diff --git a/libs/video/renderer/glsl/glsl_main.c b/libs/video/renderer/glsl/glsl_main.c index 892f8d235..a2fa1f8f6 100644 --- a/libs/video/renderer/glsl/glsl_main.c +++ b/libs/video/renderer/glsl/glsl_main.c @@ -89,7 +89,7 @@ glsl_R_RenderEntities (entqueue_t *queue) { int begun; - if (!r_drawentities->int_val) + if (!r_drawentities) return; #define RE_LOOP(type_name, Type) \ do { \ @@ -117,8 +117,8 @@ R_DrawViewModel (void) { entity_t *ent = vr_data.view_model; if (vr_data.inhibit_viewmodel - || !r_drawviewmodel->int_val - || !r_drawentities->int_val + || !r_drawviewmodel + || !r_drawentities || !ent->renderer.model) return; @@ -173,7 +173,6 @@ glsl_R_Init (void) Cmd_AddCommand ("timerefresh", glsl_R_TimeRefresh_f, "Test the current refresh rate for the current location."); R_Init_Cvars (); - glsl_R_Particles_Init_Cvars (); glsl_Draw_Init (); SCR_Init (); glsl_R_InitBsp (); diff --git a/libs/video/renderer/glsl/glsl_particles.c b/libs/video/renderer/glsl/glsl_particles.c index a4caefa6f..fd1993bee 100644 --- a/libs/video/renderer/glsl/glsl_particles.c +++ b/libs/video/renderer/glsl/glsl_particles.c @@ -138,6 +138,7 @@ alloc_arrays (psystem_t *ps) maxparticles = ps->maxparticles; if (particleVertexArray) free (particleVertexArray); + printf ("alloc_arrays: %d\n", ps->maxparticles); particleVertexArray = calloc (ps->maxparticles * 4, sizeof (partvert_t)); @@ -155,6 +156,12 @@ alloc_arrays (psystem_t *ps) } } +static void +glsl_particles_f (void *data, const cvar_t *cvar) +{ + alloc_arrays (&r_psystem);//FIXME +} + void glsl_R_InitParticles (void) { @@ -165,6 +172,9 @@ glsl_R_InitParticles (void) byte data[64][64][2]; tex_t *tex; + Cvar_AddListener (Cvar_FindVar ("r_particles"), glsl_particles_f, 0); + Cvar_AddListener (Cvar_FindVar ("r_particles_max"), glsl_particles_f, 0); + qfeglEnable (GL_VERTEX_PROGRAM_POINT_SIZE); qfeglGetFloatv (GL_ALIASED_POINT_SIZE_RANGE, v); Sys_MaskPrintf (SYS_glsl, "point size: %g - %g\n", v[0], v[1]); @@ -258,8 +268,8 @@ draw_qf_particles (psystem_t *psystem) qfeglDepthMask (GL_FALSE); minparticledist = DotProduct (r_refdef.frame.position, - r_refdef.frame.forward) + - r_particles_nearclip->value; + r_refdef.frame.forward) + + r_particles_nearclip; vacount = 0; VA = particleVertexArray; @@ -378,8 +388,8 @@ draw_id_particles (psystem_t *psystem) qfeglBindTexture (GL_TEXTURE_2D, glsl_palette); minparticledist = DotProduct (r_refdef.frame.position, - r_refdef.frame.forward) + - r_particles_nearclip->value; + r_refdef.frame.forward) + + r_particles_nearclip; vacount = 0; VA = particleVertexArray; @@ -424,42 +434,6 @@ glsl_R_DrawParticles (psystem_t *psystem) } } -static void -r_particles_nearclip_f (cvar_t *var) -{ - Cvar_SetValue (r_particles_nearclip, bound (r_nearclip->value, var->value, - r_farclip->value)); -} - -static void -r_particles_f (cvar_t *var) -{ - R_MaxParticlesCheck (var, r_particles_max); - alloc_arrays (&r_psystem); -} - -static void -r_particles_max_f (cvar_t *var) -{ - R_MaxParticlesCheck (r_particles, var); - alloc_arrays (&r_psystem); -} - -void -glsl_R_Particles_Init_Cvars (void) -{ - r_particles = Cvar_Get ("r_particles", "1", CVAR_ARCHIVE, r_particles_f, - "Toggles drawing of particles."); - r_particles_max = Cvar_Get ("r_particles_max", "2048", CVAR_ARCHIVE, - r_particles_max_f, "Maximum amount of " - "particles to display. No maximum, minimum " - "is 0."); - r_particles_nearclip = Cvar_Get ("r_particles_nearclip", "32", - CVAR_ARCHIVE, r_particles_nearclip_f, - "Distance of the particle near clipping " - "plane from the player."); -} - psystem_t * __attribute__((const))//FIXME glsl_ParticleSystem (void) { diff --git a/libs/video/renderer/glsl/vid_common_glsl.c b/libs/video/renderer/glsl/vid_common_glsl.c index 0dffe7d11..71e516cec 100644 --- a/libs/video/renderer/glsl/vid_common_glsl.c +++ b/libs/video/renderer/glsl/vid_common_glsl.c @@ -151,7 +151,7 @@ GLSL_Init_Common (void) GLSL_TextureInit (); - if (developer->int_val & SYS_glsl) { + if (developer & SYS_glsl) { GLint max; qfeglGetIntegerv (GL_MAX_VERTEX_UNIFORM_VECTORS, &max); @@ -198,7 +198,7 @@ GLSL_CompileShader (const char *name, const shader_t *shader, int type) qfeglShaderSource (sid, shader->num_strings, shader->strings, 0); qfeglCompileShader (sid); qfeglGetShaderiv (sid, GL_COMPILE_STATUS, &compiled); - if (!compiled || (developer->int_val & SYS_glsl)) { + if (!compiled || (developer & SYS_glsl)) { dstring_t *log = dstring_new (); int size; qfeglGetShaderiv (sid, GL_INFO_LOG_LENGTH, &size); @@ -321,7 +321,7 @@ GLSL_LinkProgram (const char *name, int vert, int frag) qfeglLinkProgram (program); qfeglGetProgramiv (program, GL_LINK_STATUS, &linked); - if (!linked || (developer->int_val & SYS_glsl)) { + if (!linked || (developer & SYS_glsl)) { dstring_t *log = dstring_new (); int size; qfeglGetProgramiv (program, GL_INFO_LOG_LENGTH, &size); @@ -336,7 +336,7 @@ GLSL_LinkProgram (const char *name, int vert, int frag) if (!linked) return 0; } - if (developer->int_val & SYS_glsl) + if (developer & SYS_glsl) dump_program (name, program); return program; } diff --git a/libs/video/renderer/r_bsp.c b/libs/video/renderer/r_bsp.c index 53b778647..31951b46f 100644 --- a/libs/video/renderer/r_bsp.c +++ b/libs/video/renderer/r_bsp.c @@ -56,7 +56,7 @@ R_MarkLeaves (void) msurface_t **mark; mod_brush_t *brush = &r_refdef.worldmodel->brush; - if (r_oldviewleaf == r_refdef.viewleaf && !r_novis->int_val) + if (r_oldviewleaf == r_refdef.viewleaf && !r_novis) return; r_visframecount++; @@ -64,7 +64,7 @@ R_MarkLeaves (void) if (!r_refdef.viewleaf) return; - if (r_novis->int_val) { + if (r_novis) { r_oldviewleaf = 0; // so vis will be recalcualted when novis gets // turned off if (!solid) { diff --git a/libs/video/renderer/r_cvar.c b/libs/video/renderer/r_cvar.c index 83c5f1958..76937ebae 100644 --- a/libs/video/renderer/r_cvar.c +++ b/libs/video/renderer/r_cvar.c @@ -41,90 +41,497 @@ #include "compat.h" #include "r_internal.h" -cvar_t *cl_crossx; -cvar_t *cl_crossy; -cvar_t *cl_verstring; -cvar_t *crosshair; -cvar_t *crosshaircolor; +int cl_crossx; +static cvar_t cl_crossx_cvar = { + .name = "cl_crossx", + .description = + "Sets the position of the crosshair on the X-axis.", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &cl_crossx }, +}; +int cl_crossy; +static cvar_t cl_crossy_cvar = { + .name = "cl_crossy", + .description = + "Sets the position of the crosshair on the Y-axis.", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &cl_crossy }, +}; +char *cl_verstring; +static cvar_t cl_verstring_cvar = { + .name = "cl_verstring", + .description = + "Client version string", + .default_value = PACKAGE_VERSION, + .flags = CVAR_NONE, + .value = { .type = 0, .value = &cl_verstring }, +}; +int crosshair; +static cvar_t crosshair_cvar = { + .name = "crosshair", + .description = + "Crosshair type. 0 off, 1 old white, 2 new with colors", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &crosshair }, +}; +int crosshaircolor; +static cvar_t crosshaircolor_cvar = { + .name = "crosshaircolor", + .description = + "Color of the new crosshair", + .default_value = "79", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &crosshaircolor }, +}; -cvar_t *d_mipcap; -cvar_t *d_mipscale; +float d_mipcap; +static cvar_t d_mipcap_cvar = { + .name = "d_mipcap", + .description = + "Detail level. 0 is highest, 3 is lowest.", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &d_mipcap }, +}; +float d_mipscale; +static cvar_t d_mipscale_cvar = { + .name = "d_mipscale", + .description = + "Detail level of objects. 0 is highest, 3 is lowest.", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &d_mipscale }, +}; -cvar_t *r_aliasstats; -cvar_t *r_aliastransadj; -cvar_t *r_aliastransbase; -cvar_t *r_clearcolor; -cvar_t *r_dlight_lightmap; -cvar_t *r_dlight_max; -cvar_t *r_drawentities; -cvar_t *r_drawexplosions; -cvar_t *r_drawviewmodel; -cvar_t *r_dspeeds; -cvar_t *r_dynamic; -cvar_t *r_explosionclip; -cvar_t *r_farclip; -cvar_t *r_firecolor; -cvar_t *r_flatlightstyles; -cvar_t *r_graphheight; -cvar_t *r_lightmap_components; -cvar_t *r_maxedges; -cvar_t *r_maxsurfs; -cvar_t *r_mirroralpha; -cvar_t *r_nearclip; -cvar_t *r_norefresh; -cvar_t *r_novis; -cvar_t *r_numedges; -cvar_t *r_numsurfs; -cvar_t *r_particles; -cvar_t *r_particles_max; -cvar_t *r_particles_nearclip; -cvar_t *r_reportedgeout; -cvar_t *r_reportsurfout; -cvar_t *r_shadows; -cvar_t *r_skyname; -cvar_t *r_speeds; -cvar_t *r_timegraph; -cvar_t *r_wateralpha; -cvar_t *r_waterripple; -cvar_t *r_waterwarp; -cvar_t *r_zgraph; +int r_aliasstats; +static cvar_t r_aliasstats_cvar = { + .name = "r_polymodelstats", + .description = + "Toggles the displays of number of polygon models current being viewed", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &r_aliasstats }, +}; +float r_aliastransadj; +static cvar_t r_aliastransadj_cvar = { + .name = "r_aliastransadj", + .description = + "Determines how much of an alias model is clipped away and how much is" + " viewable.", + .default_value = "100", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &r_aliastransadj }, +}; +float r_aliastransbase; +static cvar_t r_aliastransbase_cvar = { + .name = "r_aliastransbase", + .description = + "Determines how much of an alias model is clipped away and how much is" + " viewable", + .default_value = "200", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &r_aliastransbase }, +}; +int r_clearcolor; +static cvar_t r_clearcolor_cvar = { + .name = "r_clearcolor", + .description = + "This sets the color for areas outside of the current map", + .default_value = "2", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &r_clearcolor }, +}; +int r_dlight_lightmap; +static cvar_t r_dlight_lightmap_cvar = { + .name = "r_dlight_lightmap", + .description = + "Set to 1 for high quality dynamic lighting.", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &r_dlight_lightmap }, +}; +int r_dlight_max; +static cvar_t r_dlight_max_cvar = { + .name = "r_dlight_max", + .description = + "Number of dynamic lights.", + .default_value = "32", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &r_dlight_max }, +}; +int r_drawentities; +static cvar_t r_drawentities_cvar = { + .name = "r_drawentities", + .description = + "Toggles drawing of entities (almost everything but the world)", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &r_drawentities }, +}; +int r_drawexplosions; +static cvar_t r_drawexplosions_cvar = { + .name = "r_drawexplosions", + .description = + "Draw explosions.", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &r_drawexplosions }, +}; +int r_drawviewmodel; +static cvar_t r_drawviewmodel_cvar = { + .name = "r_drawviewmodel", + .description = + "Toggles view model drawing (your weapons)", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &r_drawviewmodel }, +}; +int r_dspeeds; +static cvar_t r_dspeeds_cvar = { + .name = "r_dspeeds", + .description = + "Toggles the display of drawing speed information", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &r_dspeeds }, +}; +int r_dynamic; +static cvar_t r_dynamic_cvar = { + .name = "r_dynamic", + .description = + "Set to 0 to disable lightmap changes", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &r_dynamic }, +}; +int r_explosionclip; +static cvar_t r_explosionclip_cvar = { + .name = "r_explosionclip", + .description = + "Clip explosions.", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &r_explosionclip }, +}; +float r_farclip; +static cvar_t r_farclip_cvar = { + .name = "r_farclip", + .description = + "Distance of the far clipping plane from the player.", + .default_value = "4096", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &r_farclip }, +}; +vec4f_t r_firecolor; +static cvar_t r_firecolor_cvar = { + .name = "r_firecolor", + .description = + "color of rocket and lava ball fires", + .default_value = "[0.9, 0.7, 0.0]", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_vector, .value = &r_firecolor }, +}; +int r_flatlightstyles; +static cvar_t r_flatlightstyles_cvar = { + .name = "r_flatlightstyles", + .description = + "Disable animated lightmaps. 2 = use peak, 1 = use average, anything " + "else = normal", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &r_flatlightstyles }, +}; +int r_graphheight; +static cvar_t r_graphheight_cvar = { + .name = "r_graphheight", + .description = + "Set the number of lines displayed in the various graphs", + .default_value = "32", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &r_graphheight }, +}; +int r_lightmap_components; +static cvar_t r_lightmap_components_cvar = { + .name = "r_lightmap_components", + .description = + "Lightmap texture components. 1 is greyscale, 3 is RGB, 4 is RGBA.", + .default_value = "3", + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &r_lightmap_components }, +}; +int r_maxedges; +static cvar_t r_maxedges_cvar = { + .name = "r_maxedges", + .description = + "Sets the maximum number of edges", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &r_maxedges }, +}; +int r_maxsurfs; +static cvar_t r_maxsurfs_cvar = { + .name = "r_maxsurfs", + .description = + "Sets the maximum number of surfaces", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &r_maxsurfs }, +}; +float r_mirroralpha; +static cvar_t r_mirroralpha_cvar = { + .name = "r_mirroralpha", + .description = + "None", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &r_mirroralpha }, +}; +float r_nearclip; +static cvar_t r_nearclip_cvar = { + .name = "r_nearclip", + .description = + "Distance of the near clipping plane from the player.", + .default_value = "4", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &r_nearclip }, +}; +int r_norefresh; +static cvar_t r_norefresh_cvar = { + .name = "r_norefresh_", + .description = + "Set to 1 to disable display refresh", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &r_norefresh }, +}; +int r_novis; +static cvar_t r_novis_cvar = { + .name = "r_novis", + .description = + "Set to 1 to enable runtime visibility checking (SLOW)", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &r_novis }, +}; +int r_numedges; +static cvar_t r_numedges_cvar = { + .name = "r_numedges", + .description = + "Toggles the displaying of number of edges currently being viewed", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &r_numedges }, +}; +int r_numsurfs; +static cvar_t r_numsurfs_cvar = { + .name = "r_numsurfs", + .description = + "Toggles the displaying of number of surfaces currently being viewed", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &r_numsurfs }, +}; +int r_reportedgeout; +static cvar_t r_reportedgeout_cvar = { + .name = "r_reportedgeout", + .description = + "Toggle the display of how many edges were not displayed", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &r_reportedgeout }, +}; +int r_reportsurfout; +static cvar_t r_reportsurfout_cvar = { + .name = "r_reportsurfout", + .description = + "Toggle the display of how many surfaces were not displayed", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &r_reportsurfout }, +}; +int r_shadows; +static cvar_t r_shadows_cvar = { + .name = "r_shadows", + .description = + "Set to 1 to enable shadows for entities", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &r_shadows }, +}; +char *r_skyname; +static cvar_t r_skyname_cvar = { + .name = "r_skyname", + .description = + "name of the current skybox", + .default_value = "none", + .flags = CVAR_NONE, + .value = { .type = 0, .value = &r_skyname }, +}; +int r_speeds; +static cvar_t r_speeds_cvar = { + .name = "r_speeds", + .description = + "Display drawing time and statistics of what is being viewed", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &r_speeds }, +}; +int r_timegraph; +static cvar_t r_timegraph_cvar = { + .name = "r_timegraph", + .description = + "Toggle the display of a performance graph", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &r_timegraph }, +}; +float r_wateralpha; +static cvar_t r_wateralpha_cvar = { + .name = "r_wateralpha", + .description = + "Determine the opacity of liquids. 1 = opaque, 0 = transparent, " + "otherwise translucent.", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &r_wateralpha }, +}; +float r_waterripple; +static cvar_t r_waterripple_cvar = { + .name = "r_waterripple", + .description = + "Set to make liquids ripple, try setting to 5", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &r_waterripple }, +}; +int r_waterwarp; +static cvar_t r_waterwarp_cvar = { + .name = "r_waterwarp", + .description = + "Toggles whether surfaces are warped in liquid.", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &r_waterwarp }, +}; +int r_zgraph; +static cvar_t r_zgraph_cvar = { + .name = "r_zgraph", + .description = + "Toggle the graph that reports the changes of z-axis position", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &r_zgraph }, +}; -cvar_t *scr_fov; -cvar_t *scr_fisheye; -cvar_t *scr_fviews; -cvar_t *scr_ffov; -cvar_t *scr_showpause; -cvar_t *scr_showram; -cvar_t *scr_showturtle; -cvar_t *scr_viewsize; +float scr_fov; +static cvar_t scr_fov_cvar = { + .name = "fov", + .description = + "Your field of view in degrees. Smaller than 90 zooms in. Don't touch " + "in fisheye mode, use ffov instead.", + .default_value = "90", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &scr_fov }, +}; +int scr_fisheye; +static cvar_t scr_fisheye_cvar = { + .name = "fisheye", + .description = + "Toggles fisheye mode.", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &scr_fisheye }, +}; +int scr_fviews; +static cvar_t scr_fviews_cvar = { + .name = "fviews", + .description = + "The number of fisheye views.", + .default_value = "6", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &scr_fviews }, +}; +float scr_ffov; +static cvar_t scr_ffov_cvar = { + .name = "ffov", + .description = + "Your field of view in degrees in fisheye mode.", + .default_value = "180", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &scr_ffov }, +}; +int scr_showpause; +static cvar_t scr_showpause_cvar = { + .name = "showpause", + .description = + "Toggles display of pause graphic", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &scr_showpause }, +}; +int scr_showram; +static cvar_t scr_showram_cvar = { + .name = "showram", + .description = + "Show RAM icon if game is running low on memory", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &scr_showram }, +}; +int scr_showturtle; +static cvar_t scr_showturtle_cvar = { + .name = "showturtle", + .description = + "Show a turtle icon if your fps is below 10", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &scr_showturtle }, +}; +int scr_viewsize; +static cvar_t scr_viewsize_cvar = { + .name = "viewsize", + .description = + "Set the screen size 30 minimum, 120 maximum", + .default_value = "100", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &scr_viewsize }, +}; int r_viewsize; quat_t crosshair_color; static void -crosshaircolor_update (void *_var, const viddef_t *vid) +set_crosshair_color (int col, const viddef_t *vid) { - cvar_t *var = _var; byte *color; - color = &vid->palette32[bound (0, var->int_val, 255) * 4]; + color = &vid->palette32[bound (0, col, 255) * 4]; QuatScale (color, 1.0 / 255, crosshair_color); } static void -crosshaircolor_f (cvar_t *var) +crosshaircolor_update (void *data, const viddef_t *vid) +{ + set_crosshair_color (crosshaircolor, vid); +} + +static void +crosshaircolor_f (void *data, const cvar_t *cvar) { if (!r_data->vid->palette32) { // palette not initialized yet return; } - crosshaircolor_update (var, r_data->vid); + set_crosshair_color (crosshaircolor, r_data->vid); } static void -r_lightmap_components_f (cvar_t *var) +r_lightmap_components_f (void *data, const cvar_t *cvar) { - switch (var->int_val) { + switch (r_lightmap_components) { case 1: mod_lightmap_bytes = 1; break; @@ -137,200 +544,120 @@ r_lightmap_components_f (cvar_t *var) } static void -r_farclip_f (cvar_t *var) +r_farclip_f (void *data, const cvar_t *cvar) { - Cvar_SetValue (r_farclip, bound (8.0, var->value, Q_MAXFLOAT)); - if (r_particles_nearclip && r_nearclip) - Cvar_SetValue (r_particles_nearclip, - bound (r_nearclip->value, r_particles_nearclip->value, - r_farclip->value)); + r_farclip = bound (8.0, r_farclip, Q_MAXFLOAT); + r_particles_nearclip = bound (r_nearclip, r_particles_nearclip, r_farclip); r_data->vid->recalc_refdef = true; } static void -r_nearclip_f (cvar_t *var) +r_nearclip_f (void *data, const cvar_t *cvar) { - Cvar_SetValue (r_nearclip, bound (0.01, var->value, 4.0)); - if (r_particles_nearclip && r_farclip) - Cvar_SetValue (r_particles_nearclip, - bound (r_nearclip->value, r_particles_nearclip->value, - r_farclip->value)); + r_nearclip = bound (0.01, r_nearclip, 4.0); + r_particles_nearclip = bound (r_nearclip, r_particles_nearclip, r_farclip); r_data->vid->recalc_refdef = true; } static void -scr_fov_f (cvar_t *var) +scr_fov_f (void *data, const cvar_t *cvar) { // bound field of view - float fov = bound (0, var->value, 170); - - if (fov != var->value) { - Cvar_SetValue (var, fov); - } else { - SCR_SetFOV (var->value); - } + scr_fov = bound (0, scr_fov, 170); + SCR_SetFOV (scr_fov); } static void -scr_fisheye_f (cvar_t *var) +scr_fisheye_f (void *data, const cvar_t *cvar) { - if (var->int_val) - Cvar_Set (scr_fov, "90"); + if (scr_fisheye) + Cvar_Set ("fov", "90"); } static void -scr_ffov_f (cvar_t *var) +scr_ffov_f (void *data, const cvar_t *cvar) { - if (var->value < 130) - Cvar_Set (scr_fviews, "3"); - else if (var->value < 220) - Cvar_Set (scr_fviews, "5"); + if (scr_ffov < 130) + Cvar_Set ("fviews", "3"); + else if (scr_ffov < 220) + Cvar_Set ("fviews", "5"); else - Cvar_Set (scr_fviews, "6"); + Cvar_Set ("fviews", "6"); } static void -viewsize_f (cvar_t *var) +viewsize_f (void *data, const cvar_t *cvar) { - if (var->int_val < 30 || var->int_val > 120) { - Cvar_SetValue (var, bound (30, var->int_val, 120)); - } else { - r_data->vid->recalc_refdef = true; - r_viewsize = bound (0, var->int_val, 100); - if (r_data->viewsize_callback) - r_data->viewsize_callback (var); - } + scr_viewsize = bound (30, scr_viewsize, 120); + r_data->vid->recalc_refdef = true; + r_viewsize = bound (0, scr_viewsize, 100); + if (r_data->viewsize_callback) + r_data->viewsize_callback (scr_viewsize); } static void -r_dlight_max_f (cvar_t *var) +r_dlight_max_f (void *data, const cvar_t *cvar) { - R_MaxDlightsCheck (var); + R_MaxDlightsCheck (r_dlight_max); } void R_Init_Cvars (void) { - cl_crossx = Cvar_Get ("cl_crossx", "0", CVAR_ARCHIVE, NULL, - "Sets the position of the crosshair on the X-axis."); - cl_crossy = Cvar_Get ("cl_crossy", "0", CVAR_ARCHIVE, NULL, - "Sets the position of the crosshair on the Y-axis."); - cl_verstring = Cvar_Get ("cl_verstring", PACKAGE_VERSION, CVAR_NONE, - NULL, "Client version string"); - crosshair = Cvar_Get ("crosshair", "0", CVAR_ARCHIVE, NULL, "Crosshair " - "type. 0 off, 1 old white, 2 new with colors"); - crosshaircolor = Cvar_Get ("crosshaircolor", "79", CVAR_ARCHIVE, - crosshaircolor_f, "Color of the new crosshair"); - VID_OnPaletteChange_AddListener (crosshaircolor_update, crosshaircolor); - d_mipcap = Cvar_Get ("d_mipcap", "0", CVAR_NONE, NULL, - "Detail level. 0 is highest, 3 is lowest."); - d_mipscale = Cvar_Get ("d_mipscale", "1", CVAR_NONE, NULL, "Detail level " - "of objects. 0 is highest, 3 is lowest."); - r_aliasstats = Cvar_Get ("r_polymodelstats", "0", CVAR_NONE, NULL, - "Toggles the displays of number of polygon " - "models current being viewed"); - r_aliastransadj = Cvar_Get ("r_aliastransadj", "100", CVAR_NONE, NULL, - "Determines how much of an alias model is " - "clipped away and how much is viewable."); - r_aliastransbase = Cvar_Get ("r_aliastransbase", "200", CVAR_NONE, NULL, - "Determines how much of an alias model is " - "clipped away and how much is viewable"); - r_clearcolor = Cvar_Get ("r_clearcolor", "2", CVAR_NONE, NULL, - "This sets the color for areas outside of the " - "current map"); - r_dlight_lightmap = Cvar_Get ("r_dlight_lightmap", "1", CVAR_ARCHIVE, - NULL, "Set to 1 for high quality dynamic " - "lighting."); - r_dlight_max = Cvar_Get ("r_dlight_max", "32", CVAR_ARCHIVE, - r_dlight_max_f, "Number of dynamic lights."); - r_drawentities = Cvar_Get ("r_drawentities", "1", CVAR_NONE, NULL, - "Toggles drawing of entities (almost " - "everything but the world)"); - r_drawexplosions = Cvar_Get ("r_drawexplosions", "1", CVAR_ARCHIVE, NULL, - "Draw explosions."); - r_drawviewmodel = Cvar_Get ("r_drawviewmodel", "1", CVAR_ARCHIVE, NULL, - "Toggles view model drawing (your weapons)"); - r_dspeeds = Cvar_Get ("r_dspeeds", "0", CVAR_NONE, NULL, - "Toggles the display of drawing speed information"); - r_dynamic = Cvar_Get ("r_dynamic", "1", CVAR_NONE, NULL, - "Set to 0 to disable lightmap changes"); - r_explosionclip = Cvar_Get ("r_explosionclip", "0", CVAR_ARCHIVE, NULL, - "Clip explosions."); - r_farclip = Cvar_Get ("r_farclip", "4096", CVAR_ARCHIVE, r_farclip_f, - "Distance of the far clipping plane from the " - "player."); - r_firecolor = Cvar_Get ("r_firecolor", "0.9 0.7 0.0", CVAR_ARCHIVE, NULL, - "color of rocket and lava ball fires"); - r_flatlightstyles = Cvar_Get ("r_flatlightstyles", "0", CVAR_NONE, NULL, - "Disable animated lightmaps. 2 = use peak, " - "1 = use average, anything else = normal"); - r_graphheight = Cvar_Get ("r_graphheight", "32", CVAR_NONE, NULL, - "Set the number of lines displayed in the " - "various graphs"); - r_lightmap_components = Cvar_Get ("r_lightmap_components", "3", CVAR_ROM, - r_lightmap_components_f, - "Lightmap texture components. 1 " - "is greyscale, 3 is RGB, 4 is RGBA."); - r_maxedges = Cvar_Get ("r_maxedges", "0", CVAR_NONE, NULL, - "Sets the maximum number of edges"); - r_maxsurfs = Cvar_Get ("r_maxsurfs", "0", CVAR_NONE, NULL, - "Sets the maximum number of surfaces"); - r_mirroralpha = Cvar_Get ("r_mirroralpha", "1", CVAR_NONE, NULL, "None"); - r_nearclip = Cvar_Get ("r_nearclip", "4", CVAR_ARCHIVE, r_nearclip_f, - "Distance of the near clipping plane from the " - "player."); - r_norefresh = Cvar_Get ("r_norefresh_", "0", CVAR_NONE, NULL, - "Set to 1 to disable display refresh"); - r_novis = Cvar_Get ("r_novis", "0", CVAR_NONE, NULL, "Set to 1 to enable " - "runtime visibility checking (SLOW)"); - r_numedges = Cvar_Get ("r_numedges", "0", CVAR_NONE, NULL, - "Toggles the displaying of number of edges " - "currently being viewed"); - r_numsurfs = Cvar_Get ("r_numsurfs", "0", CVAR_NONE, NULL, - "Toggles the displaying of number of surfaces " - "currently being viewed"); - r_reportedgeout = Cvar_Get ("r_reportedgeout", "0", CVAR_NONE, NULL, - "Toggle the display of how many edges were " - "not displayed"); - r_reportsurfout = Cvar_Get ("r_reportsurfout", "0", CVAR_NONE, NULL, - "Toggle the display of how many surfaces " - "were not displayed"); - r_shadows = Cvar_Get ("r_shadows", "0", CVAR_ARCHIVE, NULL, - "Set to 1 to enable shadows for entities"); - r_skyname = Cvar_Get ("r_skyname", "none", CVAR_NONE, NULL, - "name of the current skybox"); - r_speeds = Cvar_Get ("r_speeds", "0", CVAR_NONE, NULL, "Display drawing " - "time and statistics of what is being viewed"); - r_timegraph = Cvar_Get ("r_timegraph", "0", CVAR_NONE, NULL, - "Toggle the display of a performance graph"); - r_wateralpha = Cvar_Get ("r_wateralpha", "1", CVAR_ARCHIVE, NULL, - "Determine the opacity of liquids. 1 = opaque, " - "0 = transparent, otherwise translucent."); - r_waterripple = Cvar_Get ("r_waterripple", "0", CVAR_NONE, NULL, - "Set to make liquids ripple, try setting to 5"); - r_waterwarp = Cvar_Get ("r_waterwarp", "1", CVAR_NONE, NULL, - "Toggles whether surfaces are warped in liquid."); - r_zgraph = Cvar_Get ("r_zgraph", "0", CVAR_NONE, NULL, - "Toggle the graph that reports the changes of " - "z-axis position"); - scr_fov = Cvar_Get ("fov", "90", CVAR_NONE, scr_fov_f, - "Your field of view in degrees. Smaller than 90 zooms " - "in. Don't touch in fisheye mode, use ffov instead."); - scr_fisheye = Cvar_Get ("fisheye", "0", CVAR_NONE, scr_fisheye_f, - "Toggles fisheye mode."); - scr_fviews = Cvar_Get ("fviews", "6", CVAR_NONE, NULL, "The number of " - "fisheye views."); - scr_ffov = Cvar_Get ("ffov", "180", CVAR_NONE, scr_ffov_f, "Your field of " - "view in degrees in fisheye mode."); - scr_showpause = Cvar_Get ("showpause", "1", CVAR_NONE, NULL, - "Toggles display of pause graphic"); - scr_showram = Cvar_Get ("showram", "1", CVAR_NONE, NULL, - "Show RAM icon if game is running low on memory"); - scr_showturtle = Cvar_Get ("showturtle", "0", CVAR_NONE, NULL, - "Show a turtle icon if your fps is below 10"); - scr_viewsize = Cvar_Get ("viewsize", "100", CVAR_ARCHIVE, viewsize_f, - "Set the screen size 30 minimum, 120 maximum"); + Cvar_Register (&cl_crossx_cvar, 0, 0); + Cvar_Register (&cl_crossy_cvar, 0, 0); + Cvar_Register (&cl_verstring_cvar, 0, 0); + Cvar_Register (&crosshair_cvar, 0, 0); + Cvar_Register (&crosshaircolor_cvar, crosshaircolor_f, 0); + VID_OnPaletteChange_AddListener (crosshaircolor_update, 0); + Cvar_Register (&d_mipcap_cvar, 0, 0); + Cvar_Register (&d_mipscale_cvar, 0, 0); + Cvar_Register (&r_aliasstats_cvar, 0, 0); + Cvar_Register (&r_aliastransadj_cvar, 0, 0); + Cvar_Register (&r_aliastransbase_cvar, 0, 0); + Cvar_Register (&r_clearcolor_cvar, 0, 0); + Cvar_Register (&r_dlight_lightmap_cvar, 0, 0); + Cvar_Register (&r_dlight_max_cvar, r_dlight_max_f, 0); + Cvar_Register (&r_drawentities_cvar, 0, 0); + Cvar_Register (&r_drawexplosions_cvar, 0, 0); + Cvar_Register (&r_drawviewmodel_cvar, 0, 0); + Cvar_Register (&r_dspeeds_cvar, 0, 0); + Cvar_Register (&r_dynamic_cvar, 0, 0); + Cvar_Register (&r_explosionclip_cvar, 0, 0); + Cvar_Register (&r_farclip_cvar, r_farclip_f, 0); + Cvar_Register (&r_firecolor_cvar, 0, 0); + Cvar_Register (&r_flatlightstyles_cvar, 0, 0); + Cvar_Register (&r_graphheight_cvar, 0, 0); + Cvar_Register (&r_lightmap_components_cvar, r_lightmap_components_f, 0); + Cvar_Register (&r_maxedges_cvar, 0, 0); + Cvar_Register (&r_maxsurfs_cvar, 0, 0); + Cvar_Register (&r_mirroralpha_cvar, 0, 0); + Cvar_Register (&r_nearclip_cvar, r_nearclip_f, 0); + Cvar_Register (&r_norefresh_cvar, 0, 0); + Cvar_Register (&r_novis_cvar, 0, 0); + Cvar_Register (&r_numedges_cvar, 0, 0); + Cvar_Register (&r_numsurfs_cvar, 0, 0); + Cvar_Register (&r_reportedgeout_cvar, 0, 0); + Cvar_Register (&r_reportsurfout_cvar, 0, 0); + Cvar_Register (&r_shadows_cvar, 0, 0); + Cvar_Register (&r_skyname_cvar, 0, 0); + Cvar_Register (&r_speeds_cvar, 0, 0); + Cvar_Register (&r_timegraph_cvar, 0, 0); + Cvar_Register (&r_wateralpha_cvar, 0, 0); + Cvar_Register (&r_waterripple_cvar, 0, 0); + Cvar_Register (&r_waterwarp_cvar, 0, 0); + Cvar_Register (&r_zgraph_cvar, 0, 0); + Cvar_Register (&scr_fov_cvar, scr_fov_f, 0); + Cvar_Register (&scr_fisheye_cvar, scr_fisheye_f, 0); + Cvar_Register (&scr_fviews_cvar, 0, 0); + Cvar_Register (&scr_ffov_cvar, scr_ffov_f, 0); + Cvar_Register (&scr_showpause_cvar, 0, 0); + Cvar_Register (&scr_showram_cvar, 0, 0); + Cvar_Register (&scr_showturtle_cvar, 0, 0); + Cvar_Register (&scr_viewsize_cvar, viewsize_f, 0); - r_data->graphheight = r_graphheight; - r_data->scr_viewsize = scr_viewsize; + r_data->graphheight = &r_graphheight; + r_data->scr_viewsize = &scr_viewsize; + + R_Particles_Init_Cvars (); } diff --git a/libs/video/renderer/r_graph.c b/libs/video/renderer/r_graph.c index 4c309aacf..ff2aee694 100644 --- a/libs/video/renderer/r_graph.c +++ b/libs/video/renderer/r_graph.c @@ -98,5 +98,5 @@ R_ZGraph (view_t *view) height[r_framecount & 255] = ((int) r_refdef.frame.position[2]) & 31; r_funcs->R_LineGraph (view->xabs, view->yabs, height, - w, r_data->graphheight->int_val); + w, *r_data->graphheight); } diff --git a/libs/video/renderer/r_init.c b/libs/video/renderer/r_init.c index 4ddfe33eb..5b3b53033 100644 --- a/libs/video/renderer/r_init.c +++ b/libs/video/renderer/r_init.c @@ -49,7 +49,15 @@ #include "r_scrap.h" #include "vid_internal.h" -cvar_t *vidrend_plugin; +char *vidrend_plugin; +static cvar_t vidrend_plugin_cvar = { + .name = "vid_render", + .description = + "Video Render Plugin to use", + .default_value = VID_RENDER_DEFAULT, + .flags = CVAR_ROM, + .value = { .type = 0, .value = &vidrend_plugin }, +}; plugin_t *vidrendmodule = NULL; VID_RENDER_PLUGIN_PROTOS @@ -77,12 +85,11 @@ VISIBLE void R_LoadModule (vid_internal_t *vid_internal) { PI_RegisterPlugins (vidrend_plugin_list); - vidrend_plugin = Cvar_Get ("vid_render", VID_RENDER_DEFAULT, CVAR_ROM, 0, - "Video Render Plugin to use"); - vidrendmodule = PI_LoadPlugin ("vid_render", vidrend_plugin->string); + Cvar_Register (&vidrend_plugin_cvar, 0, 0); + vidrendmodule = PI_LoadPlugin ("vid_render", vidrend_plugin); if (!vidrendmodule) { Sys_Error ("Loading of video render module: %s failed!\n", - vidrend_plugin->string); + vidrend_plugin); } r_funcs = vidrendmodule->functions->vid_render; mod_funcs = r_funcs->model_funcs; diff --git a/libs/video/renderer/r_light.c b/libs/video/renderer/r_light.c index d9a96915e..0c9a50a28 100644 --- a/libs/video/renderer/r_light.c +++ b/libs/video/renderer/r_light.c @@ -106,9 +106,9 @@ R_FindNearLights (vec4f_t pos, int count, dlight_t **lights) } void -R_MaxDlightsCheck (cvar_t *var) +R_MaxDlightsCheck (int max_dlights) { - r_maxdlights = bound (0, var->int_val, MAX_DLIGHTS); + r_maxdlights = bound (0, max_dlights, MAX_DLIGHTS); if (r_dlights) free (r_dlights); @@ -134,9 +134,9 @@ R_AnimateLight (void) d_lightstylevalue[j] = 256; continue; } - if (r_flatlightstyles->int_val == 2) { + if (r_flatlightstyles == 2) { k = r_data->lightstyle[j].peak - 'a'; - } else if (r_flatlightstyles->int_val == 1) { + } else if (r_flatlightstyles == 1) { k = r_data->lightstyle[j].average - 'a'; } else { k = i % r_data->lightstyle[j].length; @@ -317,7 +317,7 @@ R_PushDlights (const vec3_t entorigin) dlight_t *l; vec3_t lightorigin; - if (!r_dlight_lightmap->int_val) + if (!r_dlight_lightmap) return; l = r_dlights; diff --git a/libs/video/renderer/r_part.c b/libs/video/renderer/r_part.c index e0b6c56be..0a73882e9 100644 --- a/libs/video/renderer/r_part.c +++ b/libs/video/renderer/r_part.c @@ -37,6 +37,33 @@ #include "r_internal.h" psystem_t r_psystem; //FIXME singleton +int r_particles; +static cvar_t r_particles_cvar = { + .name = "r_particles", + .description = + "Toggles drawing of particles.", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &r_particles }, +}; +int r_particles_max; +static cvar_t r_particles_max_cvar = { + .name = "r_particles_max", + .description = + "Maximum amount of particles to display. No maximum, minimum is 0.", + .default_value = "2048", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &r_particles_max }, +}; +float r_particles_nearclip; +static cvar_t r_particles_nearclip_cvar = { + .name = "r_particles_nearclip", + .description = + "Distance of the particle near clipping plane from the player.", + .default_value = "32", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &r_particles_nearclip }, +}; /* R_MaxParticlesCheck @@ -45,14 +72,13 @@ psystem_t r_psystem; //FIXME singleton Thanks to a LOT of help from Taniwha, Deek, Mercury, Lordhavoc, and lots of others. */ -void -R_MaxParticlesCheck (cvar_t *r_particles, cvar_t *r_particles_max) +static void +R_MaxParticlesCheck (void) { psystem_t *ps = &r_psystem;//FIXME unsigned maxparticles = 0; - if (r_particles && r_particles->int_val) { - maxparticles = r_particles_max ? r_particles_max->int_val : 0; - } + + maxparticles = r_particles ? r_particles_max : 0; if (ps->maxparticles == maxparticles) { return; @@ -116,3 +142,29 @@ R_RunParticles (float dT) } ps->numparticles = j; } + +static void +r_particles_nearclip_f (void *data, const cvar_t *cvar) +{ + r_particles_nearclip = bound (r_nearclip, r_particles_nearclip, r_farclip); +} + +static void +r_particles_f (void *data, const cvar_t *cvar) +{ + R_MaxParticlesCheck (); +} + +static void +r_particles_max_f (void *data, const cvar_t *cvar) +{ + R_MaxParticlesCheck (); +} + +void +R_Particles_Init_Cvars (void) +{ + Cvar_Register (&r_particles_cvar, r_particles_f, 0); + Cvar_Register (&r_particles_max_cvar, r_particles_max_f, 0); + Cvar_Register (&r_particles_nearclip_cvar, r_particles_nearclip_f, 0); +} diff --git a/libs/video/renderer/r_screen.c b/libs/video/renderer/r_screen.c index cabd491cc..6152efce9 100644 --- a/libs/video/renderer/r_screen.c +++ b/libs/video/renderer/r_screen.c @@ -229,11 +229,11 @@ SCR_UpdateScreen (transform_t *camera, double realtime, SCR_Func *scr_funcs) return; } - if (r_timegraph->int_val || r_speeds->int_val || r_dspeeds->int_val) { + if (r_timegraph || r_speeds || r_dspeeds) { r_time1 = Sys_DoubleTime (); } - if (scr_fisheye->int_val && !fisheye_cube_map) { + if (scr_fisheye && !fisheye_cube_map) { fisheye_cube_map = r_funcs->create_cube_map (r_data->vid->height); } @@ -273,7 +273,7 @@ SCR_UpdateScreen (transform_t *camera, double realtime, SCR_Func *scr_funcs) vec4f_t position = refdef->frame.position; refdef->viewleaf = Mod_PointInLeaf ((vec_t*)&position, refdef->worldmodel);//FIXME r_dowarpold = r_dowarp; - if (r_waterwarp->int_val) { + if (r_waterwarp) { r_dowarp = refdef->viewleaf->contents <= CONTENTS_WATER; } if (r_dowarp && !warp_buffer) { @@ -288,12 +288,12 @@ SCR_UpdateScreen (transform_t *camera, double realtime, SCR_Func *scr_funcs) if (r_dowarp) { r_funcs->bind_framebuffer (warp_buffer); } - if (scr_fisheye->int_val && fisheye_cube_map) { + if (scr_fisheye && fisheye_cube_map) { int side = fisheye_cube_map->width; vrect_t feye = { 0, 0, side, side }; r_funcs->set_viewport (&feye); r_funcs->set_fov (1, 1); //FIXME shouldn't be every frame (2d stuff) - switch (scr_fviews->int_val) { + switch (scr_fviews) { case 6: render_side (BOX_BEHIND); case 5: render_side (BOX_BOTTOM); case 4: render_side (BOX_TOP); @@ -336,7 +336,7 @@ update_vrect (void) vrect.height = r_data->vid->height; set_vrect (&vrect, &refdef->vrect, r_data->lineadj); - SCR_SetFOV (scr_fov->value); + SCR_SetFOV (scr_fov); } void @@ -407,8 +407,8 @@ ScreenShot_f (void) static void SCR_SizeUp_f (void) { - if (scr_viewsize->int_val < 120) { - Cvar_SetValue (scr_viewsize, scr_viewsize->int_val + 10); + if (scr_viewsize < 120) { + scr_viewsize = scr_viewsize + 10; r_data->vid->recalc_refdef = 1; } } @@ -421,14 +421,14 @@ SCR_SizeUp_f (void) static void SCR_SizeDown_f (void) { - Cvar_SetValue (scr_viewsize, scr_viewsize->int_val - 10); + scr_viewsize = scr_viewsize - 10; r_data->vid->recalc_refdef = 1; } void SCR_DrawRam (void) { - if (!scr_showram->int_val) + if (!scr_showram) return; if (!r_cache_thrash) @@ -444,7 +444,7 @@ SCR_DrawTurtle (void) { static int count; - if (!scr_showturtle->int_val) + if (!scr_showturtle) return; if (r_data->frametime < 0.1) { @@ -466,7 +466,7 @@ SCR_DrawPause (void) { qpic_t *pic; - if (!scr_showpause->int_val) // turn off for screenshots + if (!scr_showpause) // turn off for screenshots return; if (!r_data->paused) @@ -501,6 +501,7 @@ SCR_Init (void) r_ent_queue = EntQueue_New (mod_num_types); - Cvar_AddListener (scr_viewsize, viewsize_listener, 0); + cvar_t *var = Cvar_FindVar ("viewsize"); + Cvar_AddListener (var, viewsize_listener, 0); update_vrect (); } diff --git a/libs/video/renderer/sw/d_edge.c b/libs/video/renderer/sw/d_edge.c index a1fd07616..84787f981 100644 --- a/libs/video/renderer/sw/d_edge.c +++ b/libs/video/renderer/sw/d_edge.c @@ -194,7 +194,7 @@ D_DrawSurfaces (void) d_zistepv = 0; d_ziorigin = -0.9; - D_DrawSolidSurface (s, r_clearcolor->int_val & 0xFF); + D_DrawSolidSurface (s, r_clearcolor & 0xFF); D_DrawZSpans (s->spans); } else if (s->flags & SURF_DRAWTURB) { pface = s->data; diff --git a/libs/video/renderer/sw/d_init.c b/libs/video/renderer/sw/d_init.c index ec0353817..e5daaf439 100644 --- a/libs/video/renderer/sw/d_init.c +++ b/libs/video/renderer/sw/d_init.c @@ -87,10 +87,10 @@ D_SetupFrame (void) d_roverwrapped = false; d_initial_rover = sc_rover; - d_minmip = bound (0, d_mipcap->value, 3); + d_minmip = bound (0, d_mipcap, 3); for (i = 0; i < (NUM_MIPS - 1); i++) - d_scalemip[i] = basemip[i] * d_mipscale->value; + d_scalemip[i] = basemip[i] * d_mipscale; d_drawspans = D_DrawSpans8; diff --git a/libs/video/renderer/sw/draw.c b/libs/video/renderer/sw/draw.c index 750105e39..bea4c305c 100644 --- a/libs/video/renderer/sw/draw.c +++ b/libs/video/renderer/sw/draw.c @@ -353,7 +353,7 @@ crosshair_1 (int x, int y) static void crosshair_2 (int x, int y) { - byte c = crosshaircolor->int_val; + byte c = crosshaircolor; Draw_Pixel (x - 1, y, c); Draw_Pixel (x - 3, y, c); @@ -368,7 +368,7 @@ crosshair_2 (int x, int y) static void crosshair_3 (int x, int y) { - byte c = crosshaircolor->int_val; + byte c = crosshaircolor; Draw_Pixel (x - 3, y - 3, c); Draw_Pixel (x + 3, y - 3, c); @@ -383,7 +383,7 @@ crosshair_3 (int x, int y) static void crosshair_4 (int x, int y) { - //byte c = crosshaircolor->int_val; + //byte c = crosshaircolor; Draw_Pixel (x, y - 2, 8); Draw_Pixel (x + 1, y - 2, 9); @@ -417,7 +417,7 @@ crosshair_4 (int x, int y) static void crosshair_5 (int x, int y) { - byte c = crosshaircolor->int_val; + byte c = crosshaircolor; Draw_Pixel (x - 1, y - 3, c); Draw_Pixel (x + 0, y - 3, c); @@ -458,12 +458,12 @@ Draw_Crosshair (void) int x, y; int ch; - ch = crosshair->int_val - 1; + ch = crosshair - 1; if ((unsigned) ch >= sizeof (crosshair_func) / sizeof (crosshair_func[0])) return; - x = vid.conview->xlen / 2 + cl_crossx->int_val; - y = vid.conview->ylen / 2 + cl_crossy->int_val; + x = vid.conview->xlen / 2 + cl_crossx; + y = vid.conview->ylen / 2 + cl_crossy; crosshair_func[ch] (x, y); } @@ -644,8 +644,8 @@ Draw_ConsoleBackground (int lines, byte alpha) } } - Draw_AltString (vid.conview->xlen - strlen (cl_verstring->string) * 8 - 11, - lines - 14, cl_verstring->string); + Draw_AltString (vid.conview->xlen - strlen (cl_verstring) * 8 - 11, + lines - 14, cl_verstring); } static void diff --git a/libs/video/renderer/sw/sw_fisheye.c b/libs/video/renderer/sw/sw_fisheye.c index 83d6c2a15..28500ee68 100644 --- a/libs/video/renderer/sw/sw_fisheye.c +++ b/libs/video/renderer/sw/sw_fisheye.c @@ -128,7 +128,7 @@ R_RenderFisheye (framebuffer_t *cube) { int width = r_refdef.vrect.width; int height = r_refdef.vrect.height; - float fov = scr_ffov->value; + float fov = scr_ffov; static int pwidth = -1; static int pheight = -1; static int pfov = -1; diff --git a/libs/video/renderer/sw/sw_rmain.c b/libs/video/renderer/sw/sw_rmain.c index 74ad36338..9f9b852a3 100644 --- a/libs/video/renderer/sw/sw_rmain.c +++ b/libs/video/renderer/sw/sw_rmain.c @@ -116,7 +116,6 @@ sw_R_Init (void) r_stack_start = (byte *) & dummy; R_Init_Cvars (); - R_Particles_Init_Cvars (); Draw_Init (); SCR_Init (); @@ -131,8 +130,8 @@ sw_R_Init (void) "refresh rate for the current location"); Cmd_AddCommand ("loadsky", R_LoadSky_f, "Load a skybox"); - Cvar_SetValue (r_maxedges, (float) NUMSTACKEDGES); - Cvar_SetValue (r_maxsurfs, (float) NUMSTACKSURFACES); + r_maxedges = NUMSTACKEDGES; + r_maxsurfs = NUMSTACKSURFACES; view_clipplanes[0].leftedge = true; view_clipplanes[1].rightedge = true; @@ -171,7 +170,7 @@ R_NewMap (model_t *worldmodel, struct model_s **models, int num_models) R_ClearParticles (); - r_cnumsurfs = r_maxsurfs->int_val; + r_cnumsurfs = r_maxsurfs; if (r_cnumsurfs <= MINSURFACES) r_cnumsurfs = MINSURFACES; @@ -194,7 +193,7 @@ R_NewMap (model_t *worldmodel, struct model_s **models, int num_models) r_maxedgesseen = 0; r_maxsurfsseen = 0; - r_numallocatededges = r_maxedges->int_val; + r_numallocatededges = r_maxedges; if (r_numallocatededges < MINEDGES) r_numallocatededges = MINEDGES; @@ -294,7 +293,7 @@ draw_iqm_entity (entity_t *ent) void R_DrawEntitiesOnList (entqueue_t *queue) { - if (!r_drawentities->int_val) + if (!r_drawentities) return; R_LowFPPrecision (); @@ -330,8 +329,8 @@ R_DrawViewModel (void) alight_t lighting; if (vr_data.inhibit_viewmodel - || !r_drawviewmodel->int_val - || !r_drawentities->int_val) + || !r_drawviewmodel + || !r_drawentities) return; viewent = vr_data.view_model; @@ -440,7 +439,7 @@ R_DrawBrushEntitiesOnList (entqueue_t *queue) model_t *clmodel; float minmaxs[6]; - if (!r_drawentities->int_val) + if (!r_drawentities) return; insubmodel = true; @@ -574,7 +573,7 @@ R_EdgeDrawing (entqueue_t *queue) static void R_RenderView_ (void) { - if (r_norefresh->int_val) + if (r_norefresh) return; if (!r_refdef.worldmodel) { return; @@ -592,7 +591,7 @@ R_RenderView_ (void) R_DrawViewModel (); - if (r_aliasstats->int_val) + if (r_aliasstats) R_PrintAliasStats (); // back to high floating-point precision diff --git a/libs/video/renderer/sw/sw_rpart.c b/libs/video/renderer/sw/sw_rpart.c index d24eeda2c..66f623165 100644 --- a/libs/video/renderer/sw/sw_rpart.c +++ b/libs/video/renderer/sw/sw_rpart.c @@ -68,40 +68,6 @@ R_DrawParticles (psystem_t *psystem) } } -static void -r_particles_nearclip_f (cvar_t *var) -{ - Cvar_SetValue (r_particles_nearclip, bound (r_nearclip->value, var->value, - r_farclip->value)); -} - -static void -r_particles_f (cvar_t *var) -{ - R_MaxParticlesCheck (var, r_particles_max); -} - -static void -r_particles_max_f (cvar_t *var) -{ - R_MaxParticlesCheck (r_particles, var); -} - -void -R_Particles_Init_Cvars (void) -{ - r_particles = Cvar_Get ("r_particles", "1", CVAR_ARCHIVE, r_particles_f, - "Toggles drawing of particles."); - r_particles_max = Cvar_Get ("r_particles_max", "2048", CVAR_ARCHIVE, - r_particles_max_f, "Maximum amount of " - "particles to display. No maximum, minimum " - "is 0."); - r_particles_nearclip = Cvar_Get ("r_particles_nearclip", "32", - CVAR_ARCHIVE, r_particles_nearclip_f, - "Distance of the particle near clipping " - "plane from the player."); -} - psystem_t * __attribute__((const))//FIXME sw_ParticleSystem (void) { diff --git a/libs/video/renderer/vid_render_gl.c b/libs/video/renderer/vid_render_gl.c index 0d5f5b640..f6a980710 100644 --- a/libs/video/renderer/vid_render_gl.c +++ b/libs/video/renderer/vid_render_gl.c @@ -214,7 +214,7 @@ gl_begin_frame (void) //update in sw modes but must in gl mode vr_data.scr_copyeverything = 1; - if (gl_clear->int_val) { + if (gl_clear) { qfglClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } else { qfglClear (GL_DEPTH_BUFFER_BIT); @@ -222,7 +222,7 @@ gl_begin_frame (void) gl_ctx->begun = 1; - if (r_speeds->int_val) { + if (r_speeds) { gl_ctx->start_time = Sys_DoubleTime (); gl_ctx->brush_polys = 0; gl_ctx->alias_polys = 0; @@ -274,7 +274,7 @@ gl_draw_transparent (void) static void gl_post_process (framebuffer_t *src) { - if (scr_fisheye->int_val) { + if (scr_fisheye) { gl_FisheyeScreen (src); } else if (r_dowarp) { gl_WarpScreen (src); @@ -294,7 +294,7 @@ gl_set_2d (int scaled) static void gl_end_frame (void) { - if (r_speeds->int_val) { + if (r_speeds) { // qfglFinish (); double start_time = gl_ctx->start_time; double end_time = Sys_DoubleTime (); @@ -307,7 +307,7 @@ gl_end_frame (void) GL_FlushText (); qfglFlush (); - if (gl_finish->int_val) { + if (gl_finish) { gl_ctx->end_rendering (); gl_ctx->begun = 0; } @@ -440,8 +440,8 @@ gl_set_fov (float x, float y) float neard, fard; mat4f_t proj; - neard = r_nearclip->value; - fard = r_farclip->value; + neard = r_nearclip; + fard = r_farclip; // NOTE columns! proj[0] = (vec4f_t) { 1/x, 0, 0, 0 }; diff --git a/libs/video/renderer/vid_render_glsl.c b/libs/video/renderer/vid_render_glsl.c index 5c93e36b1..b60624ae6 100644 --- a/libs/video/renderer/vid_render_glsl.c +++ b/libs/video/renderer/vid_render_glsl.c @@ -237,7 +237,7 @@ static void glsl_bind_framebuffer (framebuffer_t *fb); static void glsl_post_process (framebuffer_t *src) { - if (scr_fisheye->int_val) { + if (scr_fisheye) { glsl_FisheyeScreen (src); } else if (r_dowarp) { glsl_WarpScreen (src); @@ -387,8 +387,8 @@ glsl_set_fov (float x, float y) float neard, fard; mat4f_t proj; - neard = r_nearclip->value; - fard = r_farclip->value; + neard = r_nearclip; + fard = r_farclip; // NOTE columns! proj[0] = (vec4f_t) { 1/x, 0, 0, 0 }; diff --git a/libs/video/renderer/vid_render_sw.c b/libs/video/renderer/vid_render_sw.c index 14e09d3d4..fdde33ec8 100644 --- a/libs/video/renderer/vid_render_sw.c +++ b/libs/video/renderer/vid_render_sw.c @@ -126,7 +126,7 @@ static void sw_bind_framebuffer (framebuffer_t *framebuffer); static void sw_begin_frame (void) { - if (r_numsurfs->int_val) { + if (r_numsurfs) { int surfcount = surface_p - surfaces; int max_surfs = surf_max - surfaces; if (surfcount > r_maxsurfsseen) @@ -136,7 +136,7 @@ sw_begin_frame (void) surfcount, max_surfs, r_maxsurfsseen); } - if (r_numedges->int_val) { + if (r_numedges) { int edgecount = edge_p - r_edges; if (edgecount > r_maxedgesseen) @@ -169,7 +169,7 @@ sw_draw_transparent (void) static void sw_post_process (framebuffer_t *src) { - if (scr_fisheye->int_val) { + if (scr_fisheye) { R_RenderFisheye (src); } else if (r_dowarp) { D_WarpScreen (src); @@ -184,10 +184,10 @@ sw_set_2d (int scaled) static void sw_end_frame (void) { - if (r_reportsurfout->int_val && r_outofsurfaces) + if (r_reportsurfout && r_outofsurfaces) Sys_Printf ("Short %d surfaces\n", r_outofsurfaces); - if (r_reportedgeout->int_val && r_outofedges) + if (r_reportedgeout && r_outofedges) Sys_Printf ("Short roughly %d edges\n", r_outofedges * 2 / 3); // update one of three areas @@ -408,8 +408,8 @@ sw_set_fov (float x, float y) res_scale = sqrt ((double) (r_refdef.vrect.width * r_refdef.vrect.height) / (320.0 * 152.0)) * (2.0 / hFOV); - r_aliastransition = r_aliastransbase->value * res_scale; - r_resfudge = r_aliastransadj->value * res_scale; + r_aliastransition = r_aliastransbase * res_scale; + r_resfudge = r_aliastransadj * res_scale; } static void diff --git a/libs/video/renderer/vid_render_vulkan.c b/libs/video/renderer/vid_render_vulkan.c index f845ce9c2..e23fa7244 100644 --- a/libs/video/renderer/vid_render_vulkan.c +++ b/libs/video/renderer/vid_render_vulkan.c @@ -601,7 +601,7 @@ vulkan_vid_render_choose_visual (void *data) Vulkan_CreateDevice (vulkan_ctx); if (!vulkan_ctx->device) { Sys_Error ("Unable to create Vulkan device.%s", - vulkan_use_validation->int_val ? "" + vulkan_use_validation ? "" : "\nSet vulkan_use_validation for details"); } vulkan_ctx->choose_visual (vulkan_ctx); diff --git a/libs/video/renderer/vulkan/instance.c b/libs/video/renderer/vulkan/instance.c index d8cc53c2d..f2dc5ffac 100644 --- a/libs/video/renderer/vulkan/instance.c +++ b/libs/video/renderer/vulkan/instance.c @@ -37,7 +37,7 @@ #include "util.h" -cvar_t *vulkan_use_validation; +int vulkan_use_validation; static uint32_t numLayers; static VkLayerProperties *instanceLayerProperties; @@ -81,7 +81,7 @@ get_instance_layers_and_extensions (vulkan_ctx_t *ctx) strset_add (instanceExtensions, extensions[i].extensionName); } - if (developer->int_val & SYS_vulkan) { + if (developer & SYS_vulkan) { for (i = 0; i < numLayers; i++) { Sys_Printf ("%s %x %u %s\n", layers[i].layerName, @@ -127,7 +127,7 @@ debug_callback (VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, void *data) { qfv_instance_t *instance = data; - if (!(messageSeverity & vulkan_use_validation->int_val)) { + if (!(messageSeverity & vulkan_use_validation)) { return 0; } const char *msgSev = ""; @@ -223,7 +223,7 @@ QFV_CreateInstance (vulkan_ctx_t *ctx, uint32_t nlay = count_strings (layers) + 1; uint32_t next = count_strings (extensions) + count_strings (ctx->required_extensions) + 1; - if (vulkan_use_validation->int_val) { + if (vulkan_use_validation) { nlay += count_strings (vulkanValidationLayers); next += count_strings (debugExtensions); } @@ -235,7 +235,7 @@ QFV_CreateInstance (vulkan_ctx_t *ctx, memset (ext, 0, next-- * sizeof (const char *)); merge_strings (lay, layers, 0); merge_strings (ext, extensions, ctx->required_extensions); - if (vulkan_use_validation->int_val) { + if (vulkan_use_validation) { merge_strings (lay, lay, vulkanValidationLayers); merge_strings (ext, ext, debugExtensions); } @@ -262,7 +262,7 @@ QFV_CreateInstance (vulkan_ctx_t *ctx, ctx->instance = inst; load_instance_funcs (ctx); - if (vulkan_use_validation->int_val) { + if (vulkan_use_validation) { setup_debug_callback (inst); } diff --git a/libs/video/renderer/vulkan/projection.c b/libs/video/renderer/vulkan/projection.c index 701b52af2..260242f94 100644 --- a/libs/video/renderer/vulkan/projection.c +++ b/libs/video/renderer/vulkan/projection.c @@ -70,8 +70,8 @@ QFV_PerspectiveTan (mat4f_t proj, float fov_x, float fov_y) { float neard, fard; - neard = r_nearclip->value; - fard = r_farclip->value; + neard = r_nearclip; + fard = r_farclip; proj[0] = (vec4f_t) { 1 / fov_x, 0, 0, 0 }; proj[1] = (vec4f_t) { 0, 1 / fov_y, 0, 0 }; diff --git a/libs/video/renderer/vulkan/renderpass.c b/libs/video/renderer/vulkan/renderpass.c index 04936b310..ead9a7363 100644 --- a/libs/video/renderer/vulkan/renderpass.c +++ b/libs/video/renderer/vulkan/renderpass.c @@ -45,7 +45,7 @@ QFV_CreateRenderPass (qfv_device_t *device, VkDevice dev = device->dev; qfv_devfuncs_t *dfunc = device->funcs; - if (developer->int_val & SYS_vulkan) { + if (developer & SYS_vulkan) { Sys_Printf ("attachments: %zd\n", attachments->size); for (size_t i = 0; i < attachments->size; i++) { Sys_Printf (" attachment: %zd\n", i); diff --git a/libs/video/renderer/vulkan/swapchain.c b/libs/video/renderer/vulkan/swapchain.c index 20766233a..390f5dd3c 100644 --- a/libs/video/renderer/vulkan/swapchain.c +++ b/libs/video/renderer/vulkan/swapchain.c @@ -46,12 +46,12 @@ QFV_CreateSwapchain (vulkan_ctx_t *ctx, VkSwapchainKHR old_swapchain) ctx->surface, &numModes, modes); for (uint32_t i = 0; i < numModes; i++) { - if ((int) modes[i] == vulkan_presentation_mode->int_val) { + if ((int) modes[i] == vulkan_presentation_mode) { useMode = modes[i]; } } Sys_MaskPrintf (SYS_vulkan, "presentation mode: %d (%d)\n", useMode, - vulkan_presentation_mode->int_val); + vulkan_presentation_mode); VkSurfaceCapabilitiesKHR surfCaps; ifuncs->vkGetPhysicalDeviceSurfaceCapabilitiesKHR (physDev, diff --git a/libs/video/renderer/vulkan/vulkan_bsp.c b/libs/video/renderer/vulkan/vulkan_bsp.c index a29ba4742..d21f10d63 100644 --- a/libs/video/renderer/vulkan/vulkan_bsp.c +++ b/libs/video/renderer/vulkan/vulkan_bsp.c @@ -920,7 +920,7 @@ turb_begin (qfv_renderframe_t *rFrame) vulkan_ctx_t *ctx = rFrame->vulkan_ctx; bspctx_t *bctx = ctx->bsp_context; - bctx->default_color[3] = bound (0, r_wateralpha->value, 1); + bctx->default_color[3] = bound (0, r_wateralpha, 1); QuatCopy (bctx->default_color, bctx->last_color); @@ -1039,7 +1039,7 @@ Vulkan_DrawWorld (qfv_renderframe_t *rFrame) bctx->color = 0; R_VisitWorldNodes (brush, ctx); - if (r_drawentities->int_val) { + if (r_drawentities) { for (size_t i = 0; i < r_ent_queue->ent_queues[mod_brush].size; i++) { entity_t *ent = r_ent_queue->ent_queues[mod_brush].a[i]; R_DrawBrushModel (ent, ctx); @@ -1453,7 +1453,7 @@ Vulkan_LoadSkys (const char *sky, vulkan_ctx_t *ctx) bctx->skybox_tex = 0; if (!sky || !*sky) { - sky = r_skyname->string; + sky = r_skyname; } if (!*sky || !strcasecmp (sky, "none")) { diff --git a/libs/video/renderer/vulkan/vulkan_draw.c b/libs/video/renderer/vulkan/vulkan_draw.c index a936f0b6f..f2d1678a7 100644 --- a/libs/video/renderer/vulkan/vulkan_draw.c +++ b/libs/video/renderer/vulkan/vulkan_draw.c @@ -627,10 +627,10 @@ Vulkan_Draw_Crosshair (vulkan_ctx_t *ctx) { int x, y; - x = vid.conview->xlen / 2 + cl_crossx->int_val; - y = vid.conview->ylen / 2 + cl_crossy->int_val; + x = vid.conview->xlen / 2 + cl_crossx; + y = vid.conview->ylen / 2 + cl_crossy; - Vulkan_Draw_CrosshairAt (crosshair->int_val, x, y, ctx); + Vulkan_Draw_CrosshairAt (crosshair, x, y, ctx); } void diff --git a/libs/video/renderer/vulkan/vulkan_main.c b/libs/video/renderer/vulkan/vulkan_main.c index 1eedc04ce..4bb82ecbc 100644 --- a/libs/video/renderer/vulkan/vulkan_main.c +++ b/libs/video/renderer/vulkan/vulkan_main.c @@ -66,7 +66,7 @@ void Vulkan_RenderEntities (entqueue_t *queue, qfv_renderframe_t *rFrame) { - if (!r_drawentities->int_val) + if (!r_drawentities) return; #define RE_LOOP(type_name, Type) \ do { \ @@ -103,8 +103,8 @@ Vulkan_DrawViewModel (vulkan_ctx_t *ctx) { entity_t *ent = vr_data.view_model; if (vr_data.inhibit_viewmodel - || !r_drawviewmodel->int_val - || !r_drawentities->int_val + || !r_drawviewmodel + || !r_drawentities || !ent->renderer.model) return; diff --git a/libs/video/renderer/vulkan/vulkan_vid_common.c b/libs/video/renderer/vulkan/vulkan_vid_common.c index e429f688b..4e9c5991a 100644 --- a/libs/video/renderer/vulkan/vulkan_vid_common.c +++ b/libs/video/renderer/vulkan/vulkan_vid_common.c @@ -81,6 +81,8 @@ #include "util.h" #include "vkparse.h" +#include "libs/video/renderer/vulkan/vkparse.hinc" + static const char quakeforge_pipeline[] = #include "libs/video/renderer/vulkan/qfpipeline.plc" ; @@ -89,96 +91,108 @@ static const char quakeforge_renderpass[] = #include "libs/video/renderer/vulkan/deferred.plc" ; -cvar_t *vulkan_frame_count; -cvar_t *vulkan_presentation_mode; -cvar_t *msaaSamples; +int vulkan_frame_count; +static cvar_t vulkan_frame_count_cvar = { + .name = "vulkan_frame_count", + .description = + "Number of frames to render in the background. More frames can " + "increase performance, but at the cost of latency. The default of 3 is" + " recommended.", + .default_value = "3", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &vulkan_frame_count }, +}; +int vulkan_presentation_mode; +static cvar_t vulkan_presentation_mode_cvar = { + .name = "vulkan_presentation_mode", + .description = + "desired presentation mode (may fall back to fifo).", + .default_value = "mailbox", + .flags = CVAR_NONE, + .value = { + .type = &VkPresentModeKHR_type, + .value = &vulkan_presentation_mode, + }, +}; +int msaaSamples; +static cvar_t msaaSamples_cvar = { + .name = "msaaSamples", + .description = + "desired MSAA sample size.", + .default_value = "VK_SAMPLE_COUNT_1_BIT", + .flags = CVAR_NONE, + .value = { .type = &VkSampleCountFlagBits_type, .value = &msaaSamples }, +}; +static exprenum_t validation_enum; +static exprtype_t validation_type = { + .name = "vulkan_use_validation", + .size = sizeof (int), + .binops = cexpr_flag_binops, + .unops = cexpr_flag_unops, + .data = &validation_enum, + .get_string = cexpr_flags_get_string, +}; + +static int validation_values[] = { + 0, + VK_DEBUG_UTILS_MESSAGE_SEVERITY_FLAG_BITS_MAX_ENUM_EXT, +}; +static exprsym_t validation_symbols[] = { + {"none", &validation_type, validation_values + 0}, + {"all", &validation_type, validation_values + 1}, + {} +}; +static exprtab_t validation_symtab = { + validation_symbols, +}; +static exprenum_t validation_enum = { + &validation_type, + &validation_symtab, +}; +static cvar_t vulkan_use_validation_cvar = { + .name = "vulkan_use_validation", + .description = + "enable KRONOS Validation Layer if available (requires instance " + "restart).", + .default_value = "error|warning", + .flags = CVAR_NONE, + .value = { .type = &validation_type, .value = &vulkan_use_validation }, +}; static void -parse_cvar_enum (const char *enum_name, const char *err_str, int err_val, - cvar_t *var) +vulkan_frame_count_f (void *data, const cvar_t *cvar) { - exprctx_t context = {}; - context.memsuper = new_memsuper(); - - if (cexpr_parse_enum (QFV_GetEnum (enum_name), var->string, - &context, &var->int_val)) { - Sys_Printf ("%s\n", err_str); - var->int_val = err_val; + if (vulkan_frame_count < 1) { + Sys_Printf ("Invalid frame count: %d. Setting to 1\n", + vulkan_frame_count); + vulkan_frame_count = 1; } - delete_memsuper (context.memsuper); -} - -static void -vulkan_presentation_mode_f (cvar_t *var) -{ - if (!strcmp (var->string, "immediate")) { - var->int_val = VK_PRESENT_MODE_IMMEDIATE_KHR; - } else if (!strcmp (var->string, "fifo")) { - var->int_val = VK_PRESENT_MODE_FIFO_KHR; - } else if (!strcmp (var->string, "relaxed")) { - var->int_val = VK_PRESENT_MODE_FIFO_RELAXED_KHR; - } else if (!strcmp (var->string, "mailbox")) { - var->int_val = VK_PRESENT_MODE_MAILBOX_KHR; - } else { - Sys_Printf ("Invalid presentation mode, using fifo\n"); - var->int_val = VK_PRESENT_MODE_FIFO_KHR; - } -} - -static void -vulkan_use_validation_f (cvar_t *var) -{ - if (!strcmp (var->string, "none")) { - var->int_val = 0; - } else if (!strcmp (var->string, "all")) { - var->int_val = VK_DEBUG_UTILS_MESSAGE_SEVERITY_FLAG_BITS_MAX_ENUM_EXT; - } else { - parse_cvar_enum ("VkDebugUtilsMessageSeverityFlagBitsEXT", - "Invalid validation flags, using all", - VK_DEBUG_UTILS_MESSAGE_SEVERITY_FLAG_BITS_MAX_ENUM_EXT, - var); - } -} - -static void -vulkan_frame_count_f (cvar_t *var) -{ - if (var->int_val < 1) { - Sys_Printf ("Invalid frame count: %d. Setting to 1\n", var->int_val); - Cvar_Set (var, "1"); - } -} - -static void -msaaSamples_f (cvar_t *var) -{ - parse_cvar_enum ("VkSampleCountFlagBits", "Invalid MSAA samples, using 1", - VK_SAMPLE_COUNT_1_BIT, var); } static void Vulkan_Init_Cvars (void) { - vulkan_use_validation = Cvar_Get ("vulkan_use_validation", - "error|warning", CVAR_NONE, - vulkan_use_validation_f, - "enable KRONOS Validation Layer if " - "available (requires instance " - "restart)."); + int num_syms = 0; + for (exprsym_t *sym = VkDebugUtilsMessageSeverityFlagBitsEXT_symbols; + sym->name; sym++, num_syms++) { + } + for (exprsym_t *sym = validation_symbols; sym->name; sym++, num_syms++) { + } + validation_symtab.symbols = calloc (num_syms + 1, sizeof (exprsym_t)); + num_syms = 0; + for (exprsym_t *sym = VkDebugUtilsMessageSeverityFlagBitsEXT_symbols; + sym->name; sym++, num_syms++) { + validation_symtab.symbols[num_syms] = *sym; + validation_symtab.symbols[num_syms].type = &validation_type; + } + for (exprsym_t *sym = validation_symbols; sym->name; sym++, num_syms++) { + validation_symtab.symbols[num_syms] = *sym; + } + Cvar_Register (&vulkan_use_validation_cvar, 0, 0); // FIXME implement fallback choices (instead of just fifo) - vulkan_presentation_mode = Cvar_Get ("vulkan_presentation_mode", "mailbox", - CVAR_NONE, vulkan_presentation_mode_f, - "desired presentation mode (may fall " - "back to fifo)."); - vulkan_frame_count = Cvar_Get ("vulkan_frame_count", "3", CVAR_NONE, - vulkan_frame_count_f, - "Number of frames to render in the" - " background. More frames can increase" - " performance, but at the cost of latency." - " The default of 3 is recommended."); - msaaSamples = Cvar_Get ("msaaSamples", "VK_SAMPLE_COUNT_1_BIT", - CVAR_NONE, msaaSamples_f, - "desired MSAA sample size."); + Cvar_Register (&vulkan_presentation_mode_cvar, 0, 0); + Cvar_Register (&vulkan_frame_count_cvar, vulkan_frame_count_f, 0); + Cvar_Register (&msaaSamples_cvar, 0, 0); R_Init_Cvars (); } @@ -254,7 +268,7 @@ Vulkan_CreateDevice (vulkan_ctx_t *ctx) //FIXME msaa and deferred rendering... //also, location ctx->msaaSamples = 1; - /*ctx->msaaSamples = min ((VkSampleCountFlagBits) msaaSamples->int_val, + /*ctx->msaaSamples = min ((VkSampleCountFlagBits) msaaSamples, QFV_GetMaxSampleCount (device->physDev)); if (ctx->msaaSamples > 1) { name = "renderpass_msaa"; @@ -703,7 +717,7 @@ Vulkan_CreateFrames (vulkan_ctx_t *ctx) DARRAY_INIT (&ctx->frames, 4); } - DARRAY_RESIZE (&ctx->frames, vulkan_frame_count->int_val); + DARRAY_RESIZE (&ctx->frames, vulkan_frame_count); __auto_type cmdBuffers = QFV_AllocCommandBufferSet (ctx->frames.size, alloca); diff --git a/libs/video/targets/context_sdl.c b/libs/video/targets/context_sdl.c index 91a0927de..a2464144b 100644 --- a/libs/video/targets/context_sdl.c +++ b/libs/video/targets/context_sdl.c @@ -52,12 +52,12 @@ VID_SetGamma (double gamma) } static void -VID_UpdateFullscreen (cvar_t *vid_fullscreen) +VID_UpdateFullscreen (void *data, const cvar_t *cvar) { if (!r_data || !viddef.initialized) return; - if ((vid_fullscreen->int_val && !(sdl_screen->flags & SDL_FULLSCREEN)) - || (!vid_fullscreen->int_val && sdl_screen->flags & SDL_FULLSCREEN)) + if ((cvar && !(sdl_screen->flags & SDL_FULLSCREEN)) + || (!cvar && sdl_screen->flags & SDL_FULLSCREEN)) if (!SDL_WM_ToggleFullScreen (sdl_screen)) Sys_Printf ("VID_UpdateFullscreen: error setting fullscreen\n"); IN_UpdateGrab (in_grab); @@ -66,9 +66,6 @@ VID_UpdateFullscreen (cvar_t *vid_fullscreen) void SDL_Init_Cvars (void) { - vid_fullscreen = Cvar_Get ("vid_fullscreen", "0", CVAR_ARCHIVE, - VID_UpdateFullscreen, - "Toggles fullscreen mode"); - vid_system_gamma = Cvar_Get ("vid_system_gamma", "1", CVAR_ARCHIVE, NULL, - "Use system gamma control if available"); + Cvar_Register (&vid_fullscreen_cvar, VID_UpdateFullscreen, 0); + Cvar_Register (&vid_system_gamma_cvar, 0, 0); } diff --git a/libs/video/targets/context_win.c b/libs/video/targets/context_win.c index 55a6910c9..0d3d8e973 100644 --- a/libs/video/targets/context_win.c +++ b/libs/video/targets/context_win.c @@ -56,28 +56,156 @@ sw_ctx_t *win_sw_context; #define NO_MODE (MODE_WINDOWED - 1) #define MODE_FULLSCREEN_DEFAULT (MODE_WINDOWED + 3) -cvar_t *vid_ddraw; +int vid_ddraw; +static cvar_t vid_ddraw_cvar = { + .name = "vid_ddraw", + .description = + "", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &vid_ddraw }, +}; // Note that 0 is MODE_WINDOWED -static cvar_t *vid_mode; +static int vid_mode; +static cvar_t vid_mode_cvar = { + .name = "vid_mode", + .description = + "", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &vid_mode }, +}; // Note that 0 is MODE_WINDOWED -static cvar_t *_vid_default_mode; +static char *_vid_default_mode; +static cvar_t _vid_default_mode_cvar = { + .name = "_vid_default_mode", + .description = + "", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = 0/* not used */, .value = &_vid_default_mode }, +}; // Note that 3 is MODE_FULLSCREEN_DEFAULT -static cvar_t *_vid_default_mode_win; -static cvar_t *vid_wait; -static cvar_t *vid_nopageflip; -static cvar_t *_vid_wait_override; -static cvar_t *vid_config_x; -static cvar_t *vid_config_y; -static cvar_t *vid_stretch_by_2; -static cvar_t *_windowed_mouse; -static cvar_t *vid_fullscreen_mode; -static cvar_t *vid_windowed_mode; -static cvar_t *block_switch; -static cvar_t *vid_window_x; -static cvar_t *vid_window_y; +static int _vid_default_mode_win; +static cvar_t _vid_default_mode_win_cvar = { + .name = "_vid_default_mode_win", + .description = + "", + .default_value = "3", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &_vid_default_mode_win }, +}; +static char *vid_wait; +static cvar_t vid_wait_cvar = { + .name = "vid_wait", + .description = + "", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &vid_wait }, +}; +static char *vid_nopageflip; +static cvar_t vid_nopageflip_cvar = { + .name = "vid_nopageflip", + .description = + "", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = 0/* not used */, .value = &vid_nopageflip }, +}; +static char *_vid_wait_override; +static cvar_t _vid_wait_override_cvar = { + .name = "_vid_wait_override", + .description = + "", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = 0/* not used */, .value = &_vid_wait_override }, +}; +static char *vid_config_x; +static cvar_t vid_config_x_cvar = { + .name = "vid_config_x", + .description = + "", + .default_value = "800", + .flags = CVAR_ARCHIVE, + .value = { .type = 0/* not used */, .value = &vid_config_x }, +}; +static char *vid_config_y; +static cvar_t vid_config_y_cvar = { + .name = "vid_config_y", + .description = + "", + .default_value = "600", + .flags = CVAR_ARCHIVE, + .value = { .type = 0/* not used */, .value = &vid_config_y }, +}; +static char *vid_stretch_by_2; +static cvar_t vid_stretch_by_2_cvar = { + .name = "vid_stretch_by_2", + .description = + "", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = 0/* not used */, .value = &vid_stretch_by_2 }, +}; +static int _windowed_mouse; +static cvar_t _windowed_mouse_cvar = { + .name = "_windowed_mouse", + .description = + "", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &_windowed_mouse }, +}; +static int vid_fullscreen_mode; +static cvar_t vid_fullscreen_mode_cvar = { + .name = "vid_fullscreen_mode", + .description = + "", + .default_value = "3", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &vid_fullscreen_mode }, +}; +static int vid_windowed_mode; +static cvar_t vid_windowed_mode_cvar = { + .name = "vid_windowed_mode", + .description = + "", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &vid_windowed_mode }, +}; +static char *block_switch; +static cvar_t block_switch_cvar = { + .name = "block_switch", + .description = + "", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = 0/* not used */, .value = &block_switch }, +}; +static int vid_window_x; +static cvar_t vid_window_x_cvar = { + .name = "vid_window_x", + .description = + "", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &vid_window_x }, +}; +static int vid_window_y; +static cvar_t vid_window_y_cvar = { + .name = "vid_window_y", + .description = + "", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &vid_window_y }, +}; //FIXME?int yeahimconsoled; @@ -168,8 +296,8 @@ VID_RememberWindowPos (void) if ((rect.left < GetSystemMetrics (SM_CXSCREEN)) && (rect.top < GetSystemMetrics (SM_CYSCREEN)) && (rect.right > 0) && (rect.bottom > 0)) { - Cvar_SetValue (vid_window_x, (float) rect.left); - Cvar_SetValue (vid_window_y, (float) rect.top); + vid_window_x = rect.left; + vid_window_y = rect.top; } } } @@ -178,11 +306,11 @@ VID_RememberWindowPos (void) static void VID_CheckWindowXY (void) { - if ((vid_window_x->int_val > (GetSystemMetrics (SM_CXSCREEN) - 160)) || - (vid_window_y->int_val > (GetSystemMetrics (SM_CYSCREEN) - 120)) || - (vid_window_x->int_val < 0) || (vid_window_y->int_val < 0)) { - Cvar_SetValue (vid_window_x, 0.0); - Cvar_SetValue (vid_window_y, 0.0); + if ((vid_window_x > (GetSystemMetrics (SM_CXSCREEN) - 160)) || + (vid_window_y > (GetSystemMetrics (SM_CYSCREEN) - 120)) || + (vid_window_x < 0) || (vid_window_y < 0)) { + vid_window_x = 0.0; + vid_window_y = 0.0; } } #endif @@ -391,8 +519,8 @@ VID_SetWindowedMode (int modenum) #if 0 if (!windowed_mode_set) { if (COM_CheckParm ("-resetwinpos")) { - Cvar_SetValue (vid_window_x, 0.0); - Cvar_SetValue (vid_window_y, 0.0); + vid_window_x = 0.0; + vid_window_y = 0.0; } windowed_mode_set = true; @@ -430,8 +558,8 @@ VID_SetWindowedMode (int modenum) // position and show the DIB window VID_CheckWindowXY (); - SetWindowPos (win_mainwindow, NULL, vid_window_x->int_val, - vid_window_y->int_val, 0, 0, + SetWindowPos (win_mainwindow, NULL, vid_window_x, + vid_window_y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW | SWP_DRAWFRAME); if (force_minimized) @@ -600,9 +728,9 @@ VID_SetMode (int modenum, const byte *palette) modenum = vid_default; } - Cvar_SetValue (vid_mode, (float) modenum); + vid_mode = modenum; } else { - Cvar_SetValue (vid_mode, (float) vid_modenum); + vid_mode = vid_modenum; return 0; } } @@ -622,7 +750,7 @@ VID_SetMode (int modenum, const byte *palette) // Set either the fullscreen or windowed mode if (modelist[modenum].type == MS_WINDOWED) { - if (_windowed_mouse->int_val) { + if (_windowed_mouse) { stat = VID_SetWindowedMode (modenum); IN_ActivateMouse (); IN_HideMouse (); @@ -663,7 +791,7 @@ VID_SetMode (int modenum, const byte *palette) ReleaseDC (NULL, hdc); vid_modenum = modenum; - Cvar_SetValue (vid_mode, (float) vid_modenum); + vid_mode = vid_modenum; while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage (&msg); @@ -776,7 +904,7 @@ VID_HandlePause static void __attribute__ ((used)) VID_HandlePause (qboolean pause) { - if ((modestate == MS_WINDOWED) && _windowed_mouse->int_val) { + if ((modestate == MS_WINDOWED) && _windowed_mouse) { if (pause) { IN_DeactivateMouse (); IN_ShowMouse (); @@ -957,13 +1085,13 @@ VID_TestMode_f (void) static void VID_Windowed_f (void) { - VID_SetMode (vid_windowed_mode->int_val, vid_curpal); + VID_SetMode (vid_windowed_mode, vid_curpal); } static void VID_Fullscreen_f (void) { - VID_SetMode (vid_fullscreen_mode->int_val, vid_curpal); + VID_SetMode (vid_fullscreen_mode, vid_curpal); } static void @@ -1018,35 +1146,22 @@ Win_SetGamma (double gamma) void Win_Init_Cvars (void) { - vid_ddraw = Cvar_Get ("vid_ddraw", "1", CVAR_NONE, 0, ""); - vid_mode = Cvar_Get ("vid_mode", "0", CVAR_NONE, 0, ""); - vid_wait = Cvar_Get ("vid_wait", "0", CVAR_NONE, 0, ""); - vid_nopageflip = - Cvar_Get ("vid_nopageflip", "0", CVAR_ARCHIVE, 0, ""); - _vid_wait_override = - Cvar_Get ("_vid_wait_override", "0", CVAR_ARCHIVE, 0, ""); - _vid_default_mode = - Cvar_Get ("_vid_default_mode", "0", CVAR_ARCHIVE, 0, ""); - _vid_default_mode_win = - Cvar_Get ("_vid_default_mode_win", "3", CVAR_ARCHIVE, 0, ""); - vid_config_x = - Cvar_Get ("vid_config_x", "800", CVAR_ARCHIVE, 0, ""); - vid_config_y = - Cvar_Get ("vid_config_y", "600", CVAR_ARCHIVE, 0, ""); - vid_stretch_by_2 = - Cvar_Get ("vid_stretch_by_2", "1", CVAR_ARCHIVE, 0, ""); - _windowed_mouse = - Cvar_Get ("_windowed_mouse", "0", CVAR_ARCHIVE, 0, ""); - vid_fullscreen_mode = - Cvar_Get ("vid_fullscreen_mode", "3", CVAR_ARCHIVE, 0, ""); - vid_windowed_mode = - Cvar_Get ("vid_windowed_mode", "0", CVAR_ARCHIVE, 0, ""); - block_switch = - Cvar_Get ("block_switch", "0", CVAR_ARCHIVE, 0, ""); - vid_window_x = - Cvar_Get ("vid_window_x", "0", CVAR_ARCHIVE, 0, ""); - vid_window_y = - Cvar_Get ("vid_window_y", "0", CVAR_ARCHIVE, 0, ""); + Cvar_Register (&vid_ddraw_cvar, 0, 0); + Cvar_Register (&vid_mode_cvar, 0, 0); + Cvar_Register (&vid_wait_cvar, 0, 0); + Cvar_Register (&vid_nopageflip_cvar, 0, 0); + Cvar_Register (&_vid_wait_override_cvar, 0, 0); + Cvar_Register (&_vid_default_mode_cvar, 0, 0); + Cvar_Register (&_vid_default_mode_win_cvar, 0, 0); + Cvar_Register (&vid_config_x_cvar, 0, 0); + Cvar_Register (&vid_config_y_cvar, 0, 0); + Cvar_Register (&vid_stretch_by_2_cvar, 0, 0); + Cvar_Register (&_windowed_mouse_cvar, 0, 0); + Cvar_Register (&vid_fullscreen_mode_cvar, 0, 0); + Cvar_Register (&vid_windowed_mode_cvar, 0, 0); + Cvar_Register (&block_switch_cvar, 0, 0); + Cvar_Register (&vid_window_x_cvar, 0, 0); + Cvar_Register (&vid_window_y_cvar, 0, 0); Cmd_AddCommand ("vid_testmode", VID_TestMode_f, ""); Cmd_AddCommand ("vid_nummodes", VID_NumModes_f, ""); diff --git a/libs/video/targets/context_x11.c b/libs/video/targets/context_x11.c index 0f960d7a4..468d29da7 100644 --- a/libs/video/targets/context_x11.c +++ b/libs/video/targets/context_x11.c @@ -125,7 +125,16 @@ static int accel_threshold; static Atom x_net_state; static Atom x_net_fullscreen; -static cvar_t *x11_vidmode; +static int x11_vidmode; +static cvar_t x11_vidmode_cvar = { + .name = "x11_vidmode", + .description = + "Use x11 vidmode extension to set video mode (not recommended for " + "modern systems)", + .default_value = "0", + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &x11_vidmode }, +}; static void set_fullscreen (int full) @@ -355,7 +364,7 @@ X11_GetGamma (void) XF86VidModeGamma xgamma; vec3_t *temp; - if (vid_gamma_avail && vid_system_gamma->int_val) { + if (vid_gamma_avail && vid_system_gamma) { if (XF86VidModeGetGamma (x_disp, x_screen, &xgamma)) { if ((temp = malloc (sizeof (vec3_t)))) { (*temp)[0] = xgamma.red; @@ -379,12 +388,12 @@ X11_SetVidMode (int width, int height) if (vidmode_active) return; - if (!x11_vidmode->int_val) { + if (!x11_vidmode) { return; } if (str && (tolower (*str) == 'f')) { - Cvar_Set (vid_fullscreen, "1"); + Cvar_Set ("vid_fullscreen", "1"); } #ifdef HAVE_VIDMODE @@ -412,7 +421,7 @@ X11_SetVidMode (int width, int height) } - if (vid_fullscreen->int_val && vidmode_avail) { + if (vid_fullscreen && vidmode_avail) { int i, dotclock; int best_mode = 0; qboolean found_mode = false; @@ -430,7 +439,7 @@ X11_SetVidMode (int width, int height) (vidmodes[i]->vdisplay == orig_data.vdisplay)) { original_mode = i; } - if (developer->int_val & SYS_vid) { + if (developer & SYS_vid) { Sys_Printf ("VID:%c%dx%d\n", original_mode == i ? '*' : ' ', vidmodes[i]->hdisplay, vidmodes[i]->vdisplay); @@ -471,13 +480,13 @@ X11_SetVidMode (int width, int height) #endif } -static void -X11_UpdateFullscreen (cvar_t *fullscreen) +void +X11_UpdateFullscreen (int fullscreen) { if (!vid_context_created) return; - if (!fullscreen->int_val) { + if (!fullscreen) { X11_RestoreVidMode (); set_fullscreen (0); IN_UpdateGrab (in_grab); @@ -500,14 +509,7 @@ X11_Init_Cvars (void) { Cmd_AddCommand ("vid_center", VID_Center_f, "Center the view port on the " "quake window in a virtual desktop.\n"); - vid_fullscreen = Cvar_Get ("vid_fullscreen", "0", CVAR_ARCHIVE, - &X11_UpdateFullscreen, - "Toggles fullscreen game mode"); - vid_system_gamma = Cvar_Get ("vid_system_gamma", "1", CVAR_ARCHIVE, NULL, - "Use system gamma control if available"); - x11_vidmode = Cvar_Get ("x11_vidmode", "0", CVAR_ROM, 0, - "Use x11 vidmode extension to set video mode " - "(not recommended for modern systems)"); + Cvar_Register (&x11_vidmode_cvar, 0, 0); } void @@ -573,9 +575,7 @@ X11_CreateWindow (int width, int height) vid_context_created = true; XRaiseWindow (x_disp, x_win); X11_WaitForEvent (VisibilityNotify); - if (vid_fullscreen->int_val) { - X11_UpdateFullscreen (vid_fullscreen); - } + X11_UpdateFullscreen (vid_fullscreen); } void @@ -615,7 +615,7 @@ X11_SetGamma (double gamma) #ifdef HAVE_VIDMODE XF86VidModeGamma xgamma; - if (vid_gamma_avail && vid_system_gamma->int_val && x_have_focus) { + if (vid_gamma_avail && vid_system_gamma && x_have_focus) { xgamma.red = xgamma.green = xgamma.blue = (float) gamma; if (XF86VidModeSetGamma (x_disp, x_screen, &xgamma)) return true; diff --git a/libs/video/targets/in_sdl.c b/libs/video/targets/in_sdl.c index 7ad9c727d..d61a3a5e7 100644 --- a/libs/video/targets/in_sdl.c +++ b/libs/video/targets/in_sdl.c @@ -43,7 +43,15 @@ #include "compat.h" -cvar_t *in_snd_block; +int in_snd_block; +static cvar_t in_snd_block_cvar = { + .name = "in_snd_block", + .description = + "block sound output on window focus loss", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &in_snd_block }, +}; static int have_focus = 1; @@ -53,7 +61,7 @@ event_focusout (void) { if (have_focus) { have_focus = 0; - if (in_snd_block->int_val) { + if (in_snd_block) { S_BlockSound (); CDAudio_Pause (); } @@ -64,7 +72,7 @@ static void event_focusin (void) { have_focus = 1; - if (in_snd_block->int_val) { + if (in_snd_block) { S_UnblockSound (); CDAudio_Resume (); } @@ -599,8 +607,7 @@ IN_LL_Init (void) void IN_LL_Init_Cvars (void) { - in_snd_block = Cvar_Get ("in_snd_block", "0", CVAR_ARCHIVE, NULL, - "block sound output on window focus loss"); + Cvar_Register (&in_snd_block_cvar, 0, 0); } void diff --git a/libs/video/targets/in_win.c b/libs/video/targets/in_win.c index e9cc1a331..261173511 100644 --- a/libs/video/targets/in_win.c +++ b/libs/video/targets/in_win.c @@ -1037,7 +1037,7 @@ Win_Activate (BOOL active, BOOL minimize) win_gdevmode.dmPelsHeight, false); } } - else if ((modestate == MS_WINDOWED) && in_grab->int_val + else if ((modestate == MS_WINDOWED) && in_grab && win_in_game) { IN_ActivateMouse (); IN_HideMouse (); @@ -1050,7 +1050,7 @@ Win_Activate (BOOL active, BOOL minimize) ChangeDisplaySettings (NULL, 0); vid_wassuspended = true; } - } else if ((modestate == MS_WINDOWED) && in_grab->int_val) { + } else if ((modestate == MS_WINDOWED) && in_grab) { IN_DeactivateMouse (); IN_ShowMouse (); } diff --git a/libs/video/targets/in_x11.c b/libs/video/targets/in_x11.c index 5395ea639..f7552c424 100644 --- a/libs/video/targets/in_x11.c +++ b/libs/video/targets/in_x11.c @@ -132,10 +132,43 @@ static x11_device_t x11_mouse_device = { x11_mouse_axes, x11_mouse_buttons, }; -cvar_t *in_auto_focus; -cvar_t *in_snd_block; -cvar_t *in_dga; -cvar_t *in_mouse_accel; +int in_auto_focus; +static cvar_t in_auto_focus_cvar = { + .name = "in_auto_focus", + .description = + "grab input focus when the mouse enters the window when using xinput2 " + "with certain window managers using focus-follows-mouse (eg, openbox)", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &in_auto_focus }, +}; +int in_snd_block; +static cvar_t in_snd_block_cvar = { + .name = "in_snd_block", + .description = + "block sound output on window focus loss", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &in_snd_block }, +}; +char *in_dga; +static cvar_t in_dga_cvar = { + .name = "in_dga", + .description = + "DGA Input support", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = 0/* not used */, .value = &in_dga }, +}; +int in_mouse_accel; +static cvar_t in_mouse_accel_cvar = { + .name = "in_mouse_accel", + .description = + "set to 0 to remove mouse acceleration", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &in_mouse_accel }, +}; static qboolean dga_avail; static qboolean dga_active; @@ -190,9 +223,9 @@ dga_off (void) } static void -in_dga_f (cvar_t *var) +in_dga_f (void *data, const cvar_t *cvar) { - if (var->int_val && input_grabbed) { + if (in_dga && input_grabbed) { Sys_MaskPrintf (SYS_vid, "VID: in_dga_f on\n"); dga_on (); } else { @@ -202,9 +235,9 @@ in_dga_f (cvar_t *var) } static void -in_mouse_accel_f (cvar_t *var) +in_mouse_accel_f (void *data, const cvar_t *cvar) { - if (var->int_val) { + if (in_mouse_accel) { X11_RestoreMouseAcceleration (); } else { X11_SaveMouseAcceleration (); @@ -232,7 +265,7 @@ enter_notify (XEvent *event) x11_mouse.x = event->xmotion.x; x11_mouse.y = event->xmotion.y; - if (!x_have_focus && (!in_auto_focus || in_auto_focus->int_val)) { + if (!x_have_focus && in_auto_focus) { XSetInputFocus (x_disp, x_win, RevertToPointerRoot, CurrentTime); } } @@ -661,7 +694,7 @@ event_focusout (XEvent *event) if (x_have_focus) { x_have_focus = false; in_x11_send_focus_event (0); - if (in_snd_block->int_val) { + if (in_snd_block) { S_BlockSound (); CDAudio_Pause (); } @@ -674,11 +707,11 @@ event_focusin (XEvent *event) { in_x11_send_focus_event (1); x_have_focus = true; - if (in_snd_block->int_val) { + if (in_snd_block) { S_UnblockSound (); CDAudio_Resume (); } - VID_UpdateGamma (vid_gamma); + VID_UpdateGamma (); } static void @@ -799,7 +832,7 @@ event_motion (XEvent *event) x11_mouse_axes[0].value = event->xmotion.x_root; x11_mouse_axes[1].value = event->xmotion.y_root; } else { - if (vid_fullscreen->int_val || input_grabbed) { + if (vid_fullscreen || input_grabbed) { if (!event->xmotion.send_event) { int center_x = viddef.width / 2; int center_y = viddef.height / 2; @@ -1140,7 +1173,7 @@ in_x11_grab_input (void *data, int grab) #endif if (vid_fullscreen) - grab = grab || vid_fullscreen->int_val; + grab = grab || vid_fullscreen; if ((input_grabbed && grab) || (!input_grabbed && !grab)) return; @@ -1162,12 +1195,12 @@ in_x11_grab_input (void *data, int grab) return; } input_grabbed = 1; - in_dga_f (in_dga); + in_dga_f (0, &in_dga_cvar); } else { XUngrabPointer (x_disp, CurrentTime); XUngrabKeyboard (x_disp, CurrentTime); input_grabbed = 0; - in_dga_f (in_dga); + in_dga_f (0, &in_dga_cvar); } } #ifdef X11_USE_SELECT @@ -1340,7 +1373,7 @@ in_x11_shutdown (void *data) // XAutoRepeatOn (x_disp); dga_off (); } - if (in_mouse_accel && !in_mouse_accel->int_val) + if (!in_mouse_accel) X11_RestoreMouseAcceleration (); } @@ -1361,18 +1394,10 @@ in_x11_get_device_event_data (void *device, void *data) static void in_x11_init_cvars (void *data) { - in_auto_focus = Cvar_Get ("in_auto_focus", "1", CVAR_ARCHIVE, 0, - "grab input focus when the mouse enters the" - " window when using xinput2 with certain" - " window managers using focus-follows-mouse" - " (eg, openbox)"); - in_snd_block = Cvar_Get ("in_snd_block", "0", CVAR_ARCHIVE, NULL, - "block sound output on window focus loss"); - in_dga = Cvar_Get ("in_dga", "0", CVAR_ARCHIVE, in_dga_f, - "DGA Input support"); - in_mouse_accel = Cvar_Get ("in_mouse_accel", "1", CVAR_ARCHIVE, - in_mouse_accel_f, - "set to 0 to remove mouse acceleration"); + Cvar_Register (&in_auto_focus_cvar, 0, 0); + Cvar_Register (&in_snd_block_cvar, 0, 0); + Cvar_Register (&in_dga_cvar, in_dga_f, 0); + Cvar_Register (&in_mouse_accel_cvar, in_mouse_accel_f, 0); } static void diff --git a/libs/video/targets/joy.c b/libs/video/targets/joy.c index 3ff827726..c08174a80 100644 --- a/libs/video/targets/joy.c +++ b/libs/video/targets/joy.c @@ -42,10 +42,42 @@ #include "compat.h" #include -cvar_t *joy_device; // Joystick device name -cvar_t *joy_enable; // Joystick enabling flag -cvar_t *joy_amp; // Joystick amplification -cvar_t *joy_pre_amp; // Joystick pre-amplification +char *joy_device; +static cvar_t joy_device_cvar = { + .name = "joy_device", + .description = + "Joystick device", + .default_value = "none", + .flags = CVAR_ROM, + .value = { .type = 0, .value = &joy_device }, +}; +int joy_enable; +static cvar_t joy_enable_cvar = { + .name = "joy_enable", + .description = + "Joystick enable flag", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &joy_enable }, +}; +float joy_amp; +static cvar_t joy_amp_cvar = { + .name = "joy_amp", + .description = + "Joystick amplification", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &joy_amp }, +}; +float joy_pre_amp; +static cvar_t joy_pre_amp_cvar = { + .name = "joy_pre_amp", + .description = + "Joystick pre-amplification", + .default_value = "0.01", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &joy_pre_amp }, +}; qboolean joy_found = false; qboolean joy_active = false; @@ -117,11 +149,11 @@ JOY_Move (void) { struct joy_axis *ja; float value; - float amp = joy_amp->value * in_amp->value; - float pre = joy_pre_amp->value * in_pre_amp->value; + float amp = joy_amp * in_amp; + float pre = joy_pre_amp * in_pre_amp; int i; - if (!joy_active || !joy_enable->int_val) + if (!joy_active || !joy_enable) return; for (i = 0; i < JOY_MAX_AXES; i++) { @@ -164,7 +196,7 @@ JOY_Init (void) joy_found = true; - if (!joy_enable->int_val) { + if (!joy_enable) { Sys_MaskPrintf (SYS_vid, "JOY: Joystick found, but not enabled.\n"); joy_active = false; JOY_Close (); @@ -181,9 +213,9 @@ JOY_Init (void) } static void -joyamp_f (cvar_t *var) +joyamp_f (void *data, const cvar_t *cvar) { - Cvar_Set (var, va (0, "%g", max (0.0001, var->value))); + Cvar_SetVar (cvar, va (0, "%g", max (0.0001, *(float *)data))); } typedef struct { @@ -465,14 +497,10 @@ JOY_Init_Cvars (void) { int i; - joy_device = Cvar_Get ("joy_device", "/dev/input/js0", - CVAR_ROM, 0, "Joystick device"); - joy_enable = Cvar_Get ("joy_enable", "1", CVAR_ARCHIVE, 0, - "Joystick enable flag"); - joy_amp = Cvar_Get ("joy_amp", "1", CVAR_ARCHIVE, joyamp_f, - "Joystick amplification"); - joy_pre_amp = Cvar_Get ("joy_pre_amp", "0.01", CVAR_ARCHIVE, - joyamp_f, "Joystick pre-amplification"); + Cvar_Register (&joy_device_cvar, 0, 0); + Cvar_Register (&joy_enable_cvar, 0, 0); + Cvar_Register (&joy_amp_cvar, joyamp_f, &joy_amp); + Cvar_Register (&joy_pre_amp_cvar, joyamp_f, &joy_pre_amp); Cmd_AddCommand ("in_joy", in_joy_f, "Configures the joystick behaviour"); diff --git a/libs/video/targets/joy_linux.c b/libs/video/targets/joy_linux.c index c0869553d..3a7e65a09 100644 --- a/libs/video/targets/joy_linux.c +++ b/libs/video/targets/joy_linux.c @@ -48,7 +48,7 @@ JOY_Read (void) { struct js_event event; - if (!joy_active || !joy_enable->int_val) + if (!joy_active || !joy_enable) return; while (read (joy_handle, &event, sizeof (struct js_event)) > -1) { @@ -82,7 +82,7 @@ int JOY_Open (void) { // Open joystick device - joy_handle = open (joy_device->string, O_RDONLY | O_NONBLOCK); + joy_handle = open (joy_device, O_RDONLY | O_NONBLOCK); if (joy_handle < 0) { return -1; } diff --git a/libs/video/targets/joy_win.c b/libs/video/targets/joy_win.c index f42b5022a..65c4d600c 100644 --- a/libs/video/targets/joy_win.c +++ b/libs/video/targets/joy_win.c @@ -46,7 +46,15 @@ #include "compat.h" // Joystick variables and structures -cvar_t *joy_sensitivity; // Joystick sensitivity +char *joy_sensitivity; +static cvar_t joy_sensitivity_cvar = { + .name = "joy_sensitivity", + .description = + "Joystick sensitivity", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = 0/* not used */, .value = &joy_sensitivity }, +}; // joystick defines and variables // where should defines be moved? @@ -82,27 +90,187 @@ JOYINFOEX ji; // when changing from one controller to another. this way at least something // works. -cvar_t *in_joystick; -cvar_t *joy_name; -cvar_t *joy_advanced; -cvar_t *joy_advaxisx; -cvar_t *joy_advaxisy; -cvar_t *joy_advaxisz; -cvar_t *joy_advaxisr; -cvar_t *joy_advaxisu; -cvar_t *joy_advaxisv; -cvar_t *joy_forwardthreshold; -cvar_t *joy_sidethreshold; -cvar_t *joy_pitchthreshold; -cvar_t *joy_yawthreshold; -cvar_t *joy_forwardsensitivity; -cvar_t *joy_sidesensitivity; -cvar_t *joy_pitchsensitivity; -cvar_t *joy_yawsensitivity; -cvar_t *joy_wwhack1; -cvar_t *joy_wwhack2; +char *in_joystick; +static cvar_t in_joystick_cvar = { + .name = "joystick", + .description = + "FIXME: No Description", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = 0/* not used */, .value = &in_joystick }, +}; +char *joy_name; +static cvar_t joy_name_cvar = { + .name = "joyname", + .description = + "FIXME: No Description", + .default_value = "joystick", + .flags = CVAR_NONE, + .value = { .type = 0, .value = &joy_name }, +}; +int joy_advanced; +static cvar_t joy_advanced_cvar = { + .name = "joyadvanced", + .description = + "FIXME: No Description", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &joy_advanced }, +}; +int joy_advaxisx; +static cvar_t joy_advaxisx_cvar = { + .name = "joyadvaxisx", + .description = + "FIXME: No Description", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &joy_advaxisx }, +}; +int joy_advaxisy; +static cvar_t joy_advaxisy_cvar = { + .name = "joyadvaxisy", + .description = + "FIXME: No Description", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &joy_advaxisy }, +}; +int joy_advaxisz; +static cvar_t joy_advaxisz_cvar = { + .name = "joyadvaxisz", + .description = + "FIXME: No Description", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &joy_advaxisz }, +}; +int joy_advaxisr; +static cvar_t joy_advaxisr_cvar = { + .name = "joyadvaxisr", + .description = + "FIXME: No Description", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &joy_advaxisr }, +}; +int joy_advaxisu; +static cvar_t joy_advaxisu_cvar = { + .name = "joyadvaxisu", + .description = + "FIXME: No Description", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &joy_advaxisu }, +}; +int joy_advaxisv; +static cvar_t joy_advaxisv_cvar = { + .name = "joyadvaxisv", + .description = + "FIXME: No Description", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &joy_advaxisv }, +}; +char *joy_forwardthreshold; +static cvar_t joy_forwardthreshold_cvar = { + .name = "joyforwardthreshold", + .description = + "FIXME: No Description", + .default_value = "0.15", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &joy_forwardthreshold }, +}; +char *joy_sidethreshold; +static cvar_t joy_sidethreshold_cvar = { + .name = "joysidethreshold", + .description = + "FIXME: No Description", + .default_value = "0.15", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &joy_sidethreshold }, +}; +char *joy_pitchthreshold; +static cvar_t joy_pitchthreshold_cvar = { + .name = "joypitchthreshold", + .description = + "FIXME: No Description", + .default_value = "0.15", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &joy_pitchthreshold }, +}; +char *joy_yawthreshold; +static cvar_t joy_yawthreshold_cvar = { + .name = "joyyawthreshold", + .description = + "FIXME: No Description", + .default_value = "0.15", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &joy_yawthreshold }, +}; +char *joy_forwardsensitivity; +static cvar_t joy_forwardsensitivity_cvar = { + .name = "joyforwardsensitivity", + .description = + "FIXME: No Description", + .default_value = "-1.0", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &joy_forwardsensitivity }, +}; +char *joy_sidesensitivity; +static cvar_t joy_sidesensitivity_cvar = { + .name = "joysidesensitivity", + .description = + "FIXME: No Description", + .default_value = "-1.0", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &joy_sidesensitivity }, +}; +char *joy_pitchsensitivity; +static cvar_t joy_pitchsensitivity_cvar = { + .name = "joypitchsensitivity", + .description = + "FIXME: No Description", + .default_value = "1.0", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &joy_pitchsensitivity }, +}; +char *joy_yawsensitivity; +static cvar_t joy_yawsensitivity_cvar = { + .name = "joyyawsensitivity", + .description = + "FIXME: No Description", + .default_value = "-1.0", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &joy_yawsensitivity }, +}; +int joy_wwhack1; +static cvar_t joy_wwhack1_cvar = { + .name = "joywwhack1", + .description = + "FIXME: No Description", + .default_value = "0.0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &joy_wwhack1 }, +}; +char *joy_wwhack2; +static cvar_t joy_wwhack2_cvar = { + .name = "joywwhack2", + .description = + "FIXME: No Description", + .default_value = "0.0", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &joy_wwhack2 }, +}; -cvar_t *joy_debug; +int joy_debug; +static cvar_t joy_debug_cvar = { + .name = "joy_debug", + .description = + "FIXME: No Description", + .default_value = "0.0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &joy_debug }, +}; qboolean joy_advancedinit, joy_haspov; DWORD joy_oldbuttonstate, joy_oldpovstate; @@ -142,10 +310,10 @@ _JOY_Read (void) // DInput driver that causes it to make 32668 the center point // instead // of 32768 - if (joy_wwhack1->int_val) { + if (joy_wwhack1) { ji.dwUpos += 100; } - if (joy_debug->int_val) { + if (joy_debug) { if (ji.dwXpos) Sys_Printf("X: %ld\n",ji.dwXpos); if (ji.dwYpos) Sys_Printf("Y: %ld\n",ji.dwYpos); if (ji.dwZpos) Sys_Printf("Z: %ld\n",ji.dwZpos); @@ -306,7 +474,7 @@ JOY_AdvancedUpdate_f (void) pdwRawValue[i] = RawValuePointer (i); } - if (joy_advanced->int_val) { + if (joy_advanced) { // default joystick initialization // only 2 axes with joystick control dwAxisMap[JOY_AXIS_X] = AxisTurn; @@ -314,28 +482,28 @@ JOY_AdvancedUpdate_f (void) dwAxisMap[JOY_AXIS_Y] = AxisForward; // dwControlMap[JOY_AXIS_Y] = JOY_ABSOLUTE_AXIS; } else { - if (strcmp (joy_name->string, "joystick") != 0) { + if (strcmp (joy_name, "joystick") != 0) { // notify user of advanced controller - Sys_Printf ("\n%s configured\n\n", joy_name->string); + Sys_Printf ("\n%s configured\n\n", joy_name); } // advanced initialization here // data supplied by user via joy_axisn cvars - dwTemp = joy_advaxisx->int_val; + dwTemp = joy_advaxisx; dwAxisMap[JOY_AXIS_X] = dwTemp & 0x0000000f; dwControlMap[JOY_AXIS_X] = dwTemp & JOY_RELATIVE_AXIS; - dwTemp = joy_advaxisy->int_val; + dwTemp = joy_advaxisy; dwAxisMap[JOY_AXIS_Y] = dwTemp & 0x0000000f; dwControlMap[JOY_AXIS_Y] = dwTemp & JOY_RELATIVE_AXIS; - dwTemp = joy_advaxisz->int_val; + dwTemp = joy_advaxisz; dwAxisMap[JOY_AXIS_Z] = dwTemp & 0x0000000f; dwControlMap[JOY_AXIS_Z] = dwTemp & JOY_RELATIVE_AXIS; - dwTemp = joy_advaxisr->int_val; + dwTemp = joy_advaxisr; dwAxisMap[JOY_AXIS_R] = dwTemp & 0x0000000f; dwControlMap[JOY_AXIS_R] = dwTemp & JOY_RELATIVE_AXIS; - dwTemp = joy_advaxisu->int_val; + dwTemp = joy_advaxisu; dwAxisMap[JOY_AXIS_U] = dwTemp & 0x0000000f; dwControlMap[JOY_AXIS_U] = dwTemp & JOY_RELATIVE_AXIS; - dwTemp = joy_advaxisv->int_val; + dwTemp = joy_advaxisv; dwAxisMap[JOY_AXIS_V] = dwTemp & 0x0000000f; dwControlMap[JOY_AXIS_V] = dwTemp & JOY_RELATIVE_AXIS; } @@ -353,52 +521,30 @@ void JOY_Init_Cvars(void) { // joystick variables - joy_device = Cvar_Get ("joy_device", "none", CVAR_ROM, 0, - "Joystick device"); - joy_enable = Cvar_Get ("joy_enable", "1", CVAR_ARCHIVE, 0, - "Joystick enable flag"); - joy_sensitivity = Cvar_Get ("joy_sensitivity", "1", CVAR_ARCHIVE, 0, "Joystick sensitivity"); - in_joystick = Cvar_Get ("joystick", "0", CVAR_ARCHIVE, 0, "FIXME: No " - "Description"); - joy_name = Cvar_Get ("joyname", "joystick", CVAR_NONE, 0, "FIXME: No " - "Description"); - joy_advanced = Cvar_Get ("joyadvanced", "0", CVAR_NONE, 0, "FIXME: No " - "Description"); - joy_advaxisx = Cvar_Get ("joyadvaxisx", "0", CVAR_NONE, 0, "FIXME: No " - "Description"); - joy_advaxisy = Cvar_Get ("joyadvaxisy", "0", CVAR_NONE, 0, "FIXME: No " - "Description"); - joy_advaxisz = Cvar_Get ("joyadvaxisz", "0", CVAR_NONE, 0, "FIXME: No " - "Description"); - joy_advaxisr = Cvar_Get ("joyadvaxisr", "0", CVAR_NONE, 0, "FIXME: No " - "Description"); - joy_advaxisu = Cvar_Get ("joyadvaxisu", "0", CVAR_NONE, 0, "FIXME: No " - "Description"); - joy_advaxisv = Cvar_Get ("joyadvaxisv", "0", CVAR_NONE, 0, "FIXME: No " - "Description"); - joy_forwardthreshold = Cvar_Get ("joyforwardthreshold", "0.15", CVAR_NONE, - 0, "FIXME: No Description"); - joy_sidethreshold = Cvar_Get ("joysidethreshold", "0.15", CVAR_NONE, 0, - "FIXME: No Description"); - joy_pitchthreshold = Cvar_Get ("joypitchthreshold", "0.15", CVAR_NONE, 0, - "FIXME: No Description"); - joy_yawthreshold = Cvar_Get ("joyyawthreshold", "0.15", CVAR_NONE, 0, - "FIXME: No Description"); - joy_forwardsensitivity = Cvar_Get ("joyforwardsensitivity", "-1.0", - CVAR_NONE, 0, "FIXME: No Description"); - joy_sidesensitivity = Cvar_Get ("joysidesensitivity", "-1.0", CVAR_NONE, - 0, "FIXME: No Description"); - joy_pitchsensitivity = Cvar_Get ("joypitchsensitivity", "1.0", CVAR_NONE, - 0, "FIXME: No Description"); - joy_yawsensitivity = Cvar_Get ("joyyawsensitivity", "-1.0", CVAR_NONE, 0, - "FIXME: No Description"); - joy_wwhack1 = Cvar_Get ("joywwhack1", "0.0", CVAR_NONE, 0, "FIXME: No " - "Description"); - joy_wwhack2 = Cvar_Get ("joywwhack2", "0.0", CVAR_NONE, 0, "FIXME: No " - "Description"); + Cvar_Register (&joy_device_cvar, 0, 0); + Cvar_Register (&joy_enable_cvar, 0, 0); + Cvar_Register (&joy_sensitivity_cvar, 0, 0); + Cvar_Register (&in_joystick_cvar, 0, 0); + Cvar_Register (&joy_name_cvar, 0, 0); + Cvar_Register (&joy_advanced_cvar, 0, 0); + Cvar_Register (&joy_advaxisx_cvar, 0, 0); + Cvar_Register (&joy_advaxisy_cvar, 0, 0); + Cvar_Register (&joy_advaxisz_cvar, 0, 0); + Cvar_Register (&joy_advaxisr_cvar, 0, 0); + Cvar_Register (&joy_advaxisu_cvar, 0, 0); + Cvar_Register (&joy_advaxisv_cvar, 0, 0); + Cvar_Register (&joy_forwardthreshold_cvar, 0, 0); + Cvar_Register (&joy_sidethreshold_cvar, 0, 0); + Cvar_Register (&joy_pitchthreshold_cvar, 0, 0); + Cvar_Register (&joy_yawthreshold_cvar, 0, 0); + Cvar_Register (&joy_forwardsensitivity_cvar, 0, 0); + Cvar_Register (&joy_sidesensitivity_cvar, 0, 0); + Cvar_Register (&joy_pitchsensitivity_cvar, 0, 0); + Cvar_Register (&joy_yawsensitivity_cvar, 0, 0); + Cvar_Register (&joy_wwhack1_cvar, 0, 0); + Cvar_Register (&joy_wwhack2_cvar, 0, 0); - joy_debug = Cvar_Get ("joy_debug", "0.0", CVAR_NONE, 0, "FIXME: No " - "Description"); + Cvar_Register (&joy_debug_cvar, 0, 0); return; } #endif diff --git a/libs/video/targets/vid.c b/libs/video/targets/vid.c index 12aeedf99..d13da102e 100644 --- a/libs/video/targets/vid.c +++ b/libs/video/targets/vid.c @@ -51,19 +51,75 @@ /* Software and hardware gamma support */ #define viddef (*r_data->vid) #define vi (viddef.vid_internal) -cvar_t *vid_gamma; -cvar_t *vid_system_gamma; -cvar_t *con_width; // FIXME: Try to move with rest of con code -cvar_t *con_height; // FIXME: Try to move with rest of con code +float vid_gamma; +static cvar_t vid_gamma_cvar = { + .name = "vid_gamma", + .description = + "Gamma correction", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &vid_gamma }, +}; +int vid_system_gamma; +static cvar_t vid_system_gamma_cvar = { + .name = "vid_system_gamma", + .description = + "Use system gamma control if available", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &vid_system_gamma }, +}; +int con_width; +static cvar_t con_width_cvar = { + .name = "con_width", + .description = + "console effective width (GL only)", + .default_value = 0, + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &con_width }, +}; +int con_height; +static cvar_t con_height_cvar = { + .name = "con_height", + .description = + "console effective height (GL only)", + .default_value = 0, + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &con_height }, +}; qboolean vid_gamma_avail; // hardware gamma availability VISIBLE unsigned int d_8to24table[256]; /* Screen size */ -cvar_t *vid_width; -cvar_t *vid_height; +int vid_width; +static cvar_t vid_width_cvar = { + .name = "vid_width", + .description = + "screen width", + .default_value = 0, + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &vid_width }, +}; +int vid_height; +static cvar_t vid_height_cvar = { + .name = "vid_height", + .description = + "screen height", + .default_value = 0, + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &vid_height }, +}; -cvar_t *vid_fullscreen; +int vid_fullscreen; +static cvar_t vid_fullscreen_cvar = { + .name = "vid_fullscreen", + .description = + "Toggles fullscreen mode", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &vid_fullscreen }, +}; static view_t conview; @@ -72,18 +128,17 @@ VID_GetWindowSize (int def_w, int def_h) { int pnum, conheight; - vid_width = Cvar_Get ("vid_width", va (0, "%d", def_w), CVAR_NONE, NULL, - "screen width"); - vid_height = Cvar_Get ("vid_height", va (0, "%d", def_h), CVAR_NONE, NULL, - "screen height"); + vid_width_cvar.default_value = nva ("%d", def_w); + vid_height_cvar.default_value = nva ("%d", def_h); + Cvar_Register (&vid_width_cvar, 0, 0); + Cvar_Register (&vid_height_cvar, 0, 0); if ((pnum = COM_CheckParm ("-width"))) { if (pnum >= com_argc - 1) Sys_Error ("VID: -width "); - Cvar_Set (vid_width, com_argv[pnum + 1]); - - if (!vid_width->int_val) + vid_width = atoi (com_argv[pnum + 1]); + if (!vid_width) Sys_Error ("VID: Bad window width"); } @@ -91,9 +146,8 @@ VID_GetWindowSize (int def_w, int def_h) if (pnum >= com_argc - 1) Sys_Error ("VID: -height "); - Cvar_Set (vid_height, com_argv[pnum + 1]); - - if (!vid_height->int_val) + vid_height = atoi (com_argv[pnum + 1]); + if (!vid_height) Sys_Error ("VID: Bad window height"); } @@ -101,47 +155,43 @@ VID_GetWindowSize (int def_w, int def_h) if (pnum >= com_argc - 2) Sys_Error ("VID: -winsize "); - Cvar_Set (vid_width, com_argv[pnum + 1]); - Cvar_Set (vid_height, com_argv[pnum + 2]); + vid_width = atoi (com_argv[pnum + 1]); + vid_height = atoi (com_argv[pnum + 2]); - if (!vid_width->int_val || !vid_height->int_val) + if (!vid_width || !vid_height) Sys_Error ("VID: Bad window width/height"); } - Cvar_SetFlags (vid_width, vid_width->flags | CVAR_ROM); - Cvar_SetFlags (vid_height, vid_height->flags | CVAR_ROM); // viddef.maxlowwidth = LOW_WIDTH; // viddef.maxlowheight = LOW_HEIGHT; - viddef.width = vid_width->int_val; - viddef.height = vid_height->int_val; + viddef.width = vid_width; + viddef.height = vid_height; viddef.conview = &conview; - con_width = Cvar_Get ("con_width", va (0, "%d", viddef.width), CVAR_NONE, - NULL, "console effective width (GL only)"); + con_width_cvar.default_value = nva ("%d", vid_width); + Cvar_Register (&con_width_cvar, 0, 0); if ((pnum = COM_CheckParm ("-conwidth"))) { if (pnum >= com_argc - 1) Sys_Error ("VID: -conwidth "); - Cvar_Set (con_width, com_argv[pnum + 1]); + con_width = atoi(com_argv[pnum + 1]); } + con_width = max (con_width & ~7, 320); // make con_width a multiple of 8 and >= 320 - Cvar_Set (con_width, va (0, "%d", max (con_width->int_val & ~7, 320))); - Cvar_SetFlags (con_width, con_width->flags | CVAR_ROM); - viddef.conview->xlen = con_width->int_val; + viddef.conview->xlen = con_width; conheight = (viddef.conview->xlen * viddef.height) / viddef.width; - con_height = Cvar_Get ("con_height", va (0, "%d", conheight), CVAR_NONE, - NULL, "console effective height (GL only)"); + con_height_cvar.default_value = nva ("%d", conheight); + Cvar_Register (&con_height_cvar, 0, 0); if ((pnum = COM_CheckParm ("-conheight"))) { if (pnum >= com_argc - 1) Sys_Error ("VID: -conheight "); - Cvar_Set (con_height, com_argv[pnum + 1]); + con_height = atoi (com_argv[pnum + 1]); } // make con_height >= 200 - Cvar_Set (con_height, va (0, "%d", max (con_height->int_val, 200))); - Cvar_SetFlags (con_height, con_height->flags | CVAR_ROM); - viddef.conview->ylen = con_height->int_val; + con_height = max (con_height & ~7, 200); + viddef.conview->ylen = con_height; Con_CheckResize (); // Now that we have a window size, fix console } @@ -168,16 +218,9 @@ VID_BuildGammaTable (double gamma) } } -/* - VID_UpdateGamma - - This is a callback to update the palette or system gamma whenever the - vid_gamma Cvar is changed. -*/ void -VID_UpdateGamma (cvar_t *vid_gamma) +VID_UpdateGamma (void) { - double gamma = bound (0.1, vid_gamma->value, 9.9); byte *p24; byte *p32; const byte *col; @@ -185,10 +228,10 @@ VID_UpdateGamma (cvar_t *vid_gamma) viddef.recalc_refdef = 1; // force a surface cache flush - if (vid_gamma_avail && vid_system_gamma->int_val) { // Have system, use it - Sys_MaskPrintf (SYS_vid, "Setting hardware gamma to %g\n", gamma); + if (vid_gamma_avail && vid_system_gamma) { // Have system, use it + Sys_MaskPrintf (SYS_vid, "Setting hardware gamma to %g\n", vid_gamma); VID_BuildGammaTable (1.0); // hardware gamma wants a linear palette - VID_SetGamma (gamma); + VID_SetGamma (vid_gamma); p24 = viddef.palette; p32 = viddef.palette32; col = viddef.basepal; @@ -200,8 +243,8 @@ VID_UpdateGamma (cvar_t *vid_gamma) } p32[-1] = 0; // color 255 is transparent } else { // We have to hack the palette - Sys_MaskPrintf (SYS_vid, "Setting software gamma to %g\n", gamma); - VID_BuildGammaTable (gamma); + Sys_MaskPrintf (SYS_vid, "Setting software gamma to %g\n", vid_gamma); + VID_BuildGammaTable (vid_gamma); p24 = viddef.palette; p32 = viddef.palette32; col = viddef.basepal; @@ -217,6 +260,13 @@ VID_UpdateGamma (cvar_t *vid_gamma) } } +static void +vid_gamma_f (void *data, const cvar_t *cvar) +{ + vid_gamma = bound (0.1, vid_gamma, 9.9); + VID_UpdateGamma (); +} + /* VID_InitGamma @@ -237,10 +287,9 @@ VID_InitGamma (const byte *pal) } gamma = bound (0.1, gamma, 9.9); - vid_gamma = Cvar_Get ("vid_gamma", va (0, "%f", gamma), CVAR_ARCHIVE, - VID_UpdateGamma, "Gamma correction"); + Cvar_Register (&vid_gamma_cvar, vid_gamma_f, 0); - VID_BuildGammaTable (vid_gamma->value); + VID_BuildGammaTable (vid_gamma); if (viddef.onPaletteChanged) { LISTENER_INVOKE (viddef.onPaletteChanged, &viddef); @@ -272,3 +321,27 @@ VID_OnPaletteChange_RemoveListener (viddef_listener_t listener, void *data) LISTENER_REMOVE (viddef.onPaletteChanged, listener, data); } } + +VISIBLE void +VID_Init (byte *palette, byte *colormap) +{ + vid_system.init (palette, colormap); +} + +static void +vid_fullscreen_f (void *data, const cvar_t *var) +{ + vid_system.update_fullscreen (vid_fullscreen); +} + +VISIBLE void +VID_Init_Cvars (void) +{ + if (vid_system.update_fullscreen) { + // A bit of a hack, but windows registers a vid_fullscreen command + // and does fullscreen handling differently. + Cvar_Register (&vid_fullscreen_cvar, vid_fullscreen_f, 0); + } + Cvar_Register (&vid_system_gamma_cvar, 0, 0); + vid_system.init_cvars (); +} diff --git a/libs/video/targets/vid_3dfxsvga.c b/libs/video/targets/vid_3dfxsvga.c index 48f7dd389..b5e449c60 100644 --- a/libs/video/targets/vid_3dfxsvga.c +++ b/libs/video/targets/vid_3dfxsvga.c @@ -121,8 +121,8 @@ QFGL_LoadLibrary (void) { void *handle; - if (!(handle = dlopen (gl_driver->string, RTLD_NOW))) { - Sys_Error ("Couldn't load OpenGL library %s: %s", gl_driver->string, + if (!(handle = dlopen (gl_driver, RTLD_NOW))) { + Sys_Error ("Couldn't load OpenGL library %s: %s", gl_driver, dlerror ()); } glGetProcAddress = dlsym (handle, "glXGetProcAddress"); @@ -331,8 +331,7 @@ VID_Init (byte *palette, byte *colormap) void VID_Init_Cvars (void) { - vid_system_gamma = Cvar_Get ("vid_system_gamma", "1", CVAR_ARCHIVE, NULL, - "Use system gamma control if available"); + Cvar_Register (&vid_system_gamma_cvar, 0, 0); } void diff --git a/libs/video/targets/vid_fbdev.c b/libs/video/targets/vid_fbdev.c index b56d94dee..f43b29a07 100644 --- a/libs/video/targets/vid_fbdev.c +++ b/libs/video/targets/vid_fbdev.c @@ -90,8 +90,24 @@ static byte vid_current_palette[768]; static int fbdev_inited = 0; static int fbdev_backgrounded = 0; -static cvar_t *vid_redrawfull; -static cvar_t *vid_waitforrefresh; +static int vid_redrawfull; +static cvar_t vid_redrawfull_cvar = { + .name = "vid_redrawfull", + .description = + "Redraw entire screen each frame instead of just dirty areas", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &vid_redrawfull }, +}; +static int vid_waitforrefresh; +static cvar_t vid_waitforrefresh_cvar = { + .name = "vid_waitforrefresh", + .description = + "Wait for vertical retrace before drawing next frame", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &vid_waitforrefresh }, +}; static byte *framebuffer_ptr; @@ -467,10 +483,8 @@ VID_Init (byte *palette, byte *colormap) void VID_Init_Cvars () { - vid_redrawfull = Cvar_Get ("vid_redrawfull", "0", CVAR_NONE, NULL, - "Redraw entire screen each frame instead of just dirty areas"); - vid_waitforrefresh = Cvar_Get ("vid_waitforrefresh", "0", CVAR_ARCHIVE, - NULL, "Wait for vertical retrace before drawing next frame"); + Cvar_Register (&vid_redrawfull_cvar, 0, 0); + Cvar_Register (&vid_waitforrefresh_cvar, 0, 0); } void @@ -492,11 +506,11 @@ VID_Update (vrect_t *rects) } } - if (vid_waitforrefresh->int_val) { + if (vid_waitforrefresh) { // ??? } - if (vid_redrawfull->int_val) { + if (vid_redrawfull) { double *d = (double *)framebuffer_ptr, *s = (double *)viddef.buffer; double *ends = (double *)(viddef.buffer + viddef.height*viddef.rowbytes); diff --git a/libs/video/targets/vid_sdl.c b/libs/video/targets/vid_sdl.c index 21ec6f051..b653aa684 100644 --- a/libs/video/targets/vid_sdl.c +++ b/libs/video/targets/vid_sdl.c @@ -88,7 +88,7 @@ VID_Init (byte *palette, byte *colormap) // Set video width, height and flags sdl_flags = (SDL_SWSURFACE | SDL_HWPALETTE); - if (vid_fullscreen->int_val) { + if (vid_fullscreen) { sdl_flags |= SDL_FULLSCREEN; #ifndef _WIN32 // Don't annoy Mesa/3dfx folks // doesn't hurt if not using a gl renderer diff --git a/libs/video/targets/vid_sdl_gl.c b/libs/video/targets/vid_sdl_gl.c index 9a0aa0a58..79d1fc47f 100644 --- a/libs/video/targets/vid_sdl_gl.c +++ b/libs/video/targets/vid_sdl_gl.c @@ -66,7 +66,15 @@ static void (GLAPIENTRY *qfglFinish) (void); static int use_gl_procaddress = 0; -static cvar_t *gl_driver; +static char *gl_driver; +static cvar_t gl_driver_cvar = { + .name = "gl_driver", + .description = + "The OpenGL library to use. (path optional)", + .default_value = GL_DRIVER, + .flags = CVAR_ROM, + .value = { .type = 0, .value = &gl_driver }, +}; static void * QFGL_ProcAddress (const char *name, qboolean crit) @@ -151,8 +159,8 @@ sdlgl_end_rendering (void) static void sdl_load_gl (void) { - if (SDL_GL_LoadLibrary (gl_driver->string) != 0) - Sys_Error ("Couldn't load OpenGL library %s!", gl_driver->string); + if (SDL_GL_LoadLibrary (gl_driver) != 0) + Sys_Error ("Couldn't load OpenGL library %s!", gl_driver); use_gl_procaddress = 1; @@ -173,6 +181,5 @@ SDL_GL_Context (void) void SDL_GL_Init_Cvars () { - gl_driver = Cvar_Get ("gl_driver", GL_DRIVER, CVAR_ROM, NULL, - "The OpenGL library to use. (path optional)"); + Cvar_Register (&gl_driver_cvar, 0, 0); } diff --git a/libs/video/targets/vid_svgalib.c b/libs/video/targets/vid_svgalib.c index 66eacea49..bfd490868 100644 --- a/libs/video/targets/vid_svgalib.c +++ b/libs/video/targets/vid_svgalib.c @@ -72,8 +72,24 @@ static byte *framebuffer_ptr; static int svgalib_inited = 0; static int svgalib_backgrounded = 0; -static cvar_t *vid_redrawfull; -static cvar_t *vid_waitforrefresh; +static int vid_redrawfull; +static cvar_t vid_redrawfull_cvar = { + .name = "vid_redrawfull", + .description = + "Redraw entire screen each frame instead of just dirty areas", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &vid_redrawfull }, +}; +static int vid_waitforrefresh; +static cvar_t vid_waitforrefresh_cvar = { + .name = "vid_waitforrefresh", + .description = + "Wait for vertical retrace before drawing next frame", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &vid_waitforrefresh }, +}; int VGA_width, VGA_height, VGA_rowbytes, VGA_bufferrowbytes, VGA_planar; byte *VGA_pagebase; @@ -393,14 +409,9 @@ VID_Init (byte *palette, byte *colormap) void VID_Init_Cvars () { - vid_redrawfull = Cvar_Get ("vid_redrawfull", "0", CVAR_NONE, NULL, - "Redraw entire screen each frame instead of " - "just dirty areas"); - vid_waitforrefresh = Cvar_Get ("vid_waitforrefresh", "0", CVAR_ARCHIVE, - NULL, "Wait for vertical retrace before " - "drawing next frame"); - vid_system_gamma = Cvar_Get ("vid_system_gamma", "1", CVAR_ARCHIVE, NULL, - "Use system gamma control if available"); + Cvar_Register (&vid_redrawfull_cvar, 0, 0); + Cvar_Register (&vid_waitforrefresh_cvar, 0, 0); + Cvar_Register (&vid_system_gamma_cvar, 0, 0); } void @@ -414,13 +425,13 @@ VID_Update (vrect_t *rects) return; } - if (vid_waitforrefresh->int_val) { + if (vid_waitforrefresh) { vga_waitretrace (); } if (VGA_planar) { VGA_UpdatePlanarScreen (vid.buffer); - } else if (vid_redrawfull->int_val) { + } else if (vid_redrawfull) { int total = vid.rowbytes * vid.height; int offset; diff --git a/libs/video/targets/vid_win.c b/libs/video/targets/vid_win.c index eb04efef9..124a971c3 100644 --- a/libs/video/targets/vid_win.c +++ b/libs/video/targets/vid_win.c @@ -117,8 +117,8 @@ VID_shutdown (void *data) Win_CloseDisplay (); } -void -VID_Init (byte *palette, byte *colormap) +static void +Win_VID_Init (byte *palette, byte *colormap) { Sys_RegisterShutdown (VID_shutdown, 0); @@ -153,8 +153,8 @@ VID_Init (byte *palette, byte *colormap) viddef.initialized = true; } -void -VID_Init_Cvars (void) +static void +Win_VID_Init_Cvars (void) { Win_Init_Cvars (); #ifdef HAVE_VULKAN @@ -164,6 +164,11 @@ VID_Init_Cvars (void) Win_SW_Init_Cvars (); } +vid_system_t vid_system = { + .init = Win_VID_Init, + .init_cvars = Win_VID_Init_Cvars, +}; + void VID_SetCaption (const char *text) { @@ -195,48 +200,48 @@ VID_Update (vrect_t *rects) if (modestate == MS_WINDOWED) { GetWindowRect (win_mainwindow, &trect); - if ((trect.left != vid_window_x->int_val) || - (trect.top != vid_window_y->int_val)) { + if ((trect.left != vid_window_x) || + (trect.top != vid_window_y)) { if (COM_CheckParm ("-resetwinpos")) { - Cvar_SetValue (vid_window_x, 0.0); - Cvar_SetValue (vid_window_y, 0.0); + vid_window_x = 0.0; + vid_window_y = 0.0; } VID_CheckWindowXY (); - SetWindowPos (win_mainwindow, NULL, vid_window_x->int_val, - vid_window_y->int_val, 0, 0, + SetWindowPos (win_mainwindow, NULL, vid_window_x, + vid_window_y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW | SWP_DRAWFRAME); } } - if ((_vid_default_mode_win->int_val != vid_default) && + if ((_vid_default_mode_win != vid_default) && (!startwindowed - || (_vid_default_mode_win->int_val < MODE_FULLSCREEN_DEFAULT))) { + || (_vid_default_mode_win < MODE_FULLSCREEN_DEFAULT))) { firstupdate = 0; if (COM_CheckParm ("-resetwinpos")) { - Cvar_SetValue (vid_window_x, 0.0); - Cvar_SetValue (vid_window_y, 0.0); + vid_window_x = 0.0; + vid_window_y = 0.0; } - if ((_vid_default_mode_win->int_val < 0) || - (_vid_default_mode_win->int_val >= nummodes)) { - Cvar_SetValue (_vid_default_mode_win, windowed_default); + if ((_vid_default_mode_win < 0) || + (_vid_default_mode_win >= nummodes)) { + _vid_default_mode_win = windowed_default; } - Cvar_SetValue (vid_mode, _vid_default_mode_win->int_val); + vid_mode = _vid_default_mode_win; } } // We've drawn the frame; copy it to the screen FlipScreen (rects); // check for a driver change - if ((vid_ddraw->int_val && !vid_usingddraw) - || (!vid_ddraw->int_val && vid_usingddraw)) { + if ((vid_ddraw && !vid_usingddraw) + || (!vid_ddraw && vid_usingddraw)) { // reset the mode force_mode_set = true; - VID_SetMode (vid_mode->int_val, vid_curpal); + VID_SetMode (vid_mode, vid_curpal); force_mode_set = false; // store back @@ -252,9 +257,9 @@ VID_Update (vrect_t *rects) vid_testingmode = 0; } } else { - if (vid_mode->int_val != vid_realmode) { - VID_SetMode (vid_mode->int_val, vid_curpal); - Cvar_SetValue (vid_mode, (float) vid_modenum); + if (vid_mode != vid_realmode) { + VID_SetMode (vid_mode, vid_curpal); + vid_mode = vid_modenum; // so if mode set fails, we don't keep on // trying to set that mode vid_realmode = vid_modenum; @@ -263,8 +268,8 @@ VID_Update (vrect_t *rects) // handle the mouse state when windowed if that's changed if (modestate == MS_WINDOWED) { - if (_windowed_mouse->int_val != windowed_mouse) { - if (_windowed_mouse->int_val) { + if (_windowed_mouse != windowed_mouse) { + if (_windowed_mouse) { IN_ActivateMouse (); IN_HideMouse (); } else { @@ -272,7 +277,7 @@ VID_Update (vrect_t *rects) IN_ShowMouse (); } - windowed_mouse = _windowed_mouse->int_val; + windowed_mouse = _windowed_mouse; } } } diff --git a/libs/video/targets/vid_win_gl.c b/libs/video/targets/vid_win_gl.c index 8723225c8..8e5b9d07a 100644 --- a/libs/video/targets/vid_win_gl.c +++ b/libs/video/targets/vid_win_gl.c @@ -54,7 +54,15 @@ static void (GLAPIENTRY *qfglFinish) (void); static void *(WINAPI * glGetProcAddress) (const char *symbol) = NULL; static int use_gl_proceaddress = 0; -static cvar_t *gl_driver; +static char *gl_driver; +static cvar_t gl_driver_cvar = { + .name = "gl_driver", + .description = + "The OpenGL library to use. (path optional)", + .default_value = GL_DRIVER, + .flags = CVAR_ROM, + .value = { .type = 0, .value = &gl_driver }, +}; static HGLRC baseRC;//FIXME should be in gl_ctx_t, but that's GLXContext... static void * QFGL_GetProcAddress (void *handle, const char *name) @@ -155,8 +163,8 @@ wgl_end_rendering (void) SwapBuffers (win_maindc); } // handle the mouse state when windowed if that's changed - if (!vid_fullscreen->int_val) { -//FIXME if (!in_grab->int_val) { + if (!vid_fullscreen) { +//FIXME if (!in_grab) { //FIXME if (windowed_mouse) { //FIXME IN_DeactivateMouse (); //FIXME IN_ShowMouse (); @@ -171,9 +179,9 @@ wgl_end_rendering (void) static void wgl_load_gl (void) { - libgl_handle = LoadLibrary (gl_driver->string); + libgl_handle = LoadLibrary (gl_driver); if (!libgl_handle) { - Sys_Error ("Couldn't load OpenGL library %s!", gl_driver->string); + Sys_Error ("Couldn't load OpenGL library %s!", gl_driver); } glGetProcAddress = (void *) GetProcAddress (libgl_handle, "wglGetProcAddress"); @@ -204,6 +212,5 @@ Win_GL_Context (void) void Win_GL_Init_Cvars (void) { - gl_driver = Cvar_Get ("gl_driver", GL_DRIVER, CVAR_ROM, NULL, - "The OpenGL library to use. (path optional)"); + Cvar_Register (&gl_driver_cvar, 0, 0); } diff --git a/libs/video/targets/vid_win_sw.c b/libs/video/targets/vid_win_sw.c index 2e8667c85..052cad570 100644 --- a/libs/video/targets/vid_win_sw.c +++ b/libs/video/targets/vid_win_sw.c @@ -300,7 +300,7 @@ Win_UnloadAllDrivers (void) static void Win_CreateDriver (void) { - if (vid_ddraw->int_val) { + if (vid_ddraw) { VID_CreateDDrawDriver (viddef.width, viddef.height); } if (!using_ddraw) { diff --git a/libs/video/targets/vid_win_vulkan.c b/libs/video/targets/vid_win_vulkan.c index 240fa2355..f9adb967d 100644 --- a/libs/video/targets/vid_win_vulkan.c +++ b/libs/video/targets/vid_win_vulkan.c @@ -44,7 +44,15 @@ #include "vid_internal.h" #include "vid_vulkan.h" -static cvar_t *vulkan_library_name; +static char *vulkan_library_name; +static cvar_t vulkan_library_name_cvar = { + .name = "vulkan_library", + .description = + "the name of the vulkan shared library", + .default_value = "vulkan-1.dll", + .flags = CVAR_ROM, + .value = { .type = 0, .value = &vulkan_library_name }, +}; typedef struct vulkan_presentation_s { #define PRESENTATION_VULKAN_FUNCTION_FROM_EXTENSION(name,ext) PFN_##name name; @@ -65,11 +73,11 @@ static HMODULE vulkan_library; static void load_vulkan_library (vulkan_ctx_t *ctx) { - vulkan_library = LoadLibrary (vulkan_library_name->string); + vulkan_library = LoadLibrary (vulkan_library_name); if (!vulkan_library) { DWORD errcode = GetLastError (); Sys_Error ("Couldn't load vulkan library %s: %ld", - vulkan_library_name->string, errcode); + vulkan_library_name, errcode); } #define EXPORTED_VULKAN_FUNCTION(name) \ @@ -185,7 +193,5 @@ Win_Vulkan_Context (void) void Win_Vulkan_Init_Cvars (void) { - vulkan_library_name = Cvar_Get ("vulkan_library", "vulkan-1.dll", - CVAR_ROM, 0, - "the name of the vulkan shared library"); + Cvar_Register (&vulkan_library_name_cvar, 0, 0); } diff --git a/libs/video/targets/vid_x11.c b/libs/video/targets/vid_x11.c index d60d1b9f1..e1b674e20 100644 --- a/libs/video/targets/vid_x11.c +++ b/libs/video/targets/vid_x11.c @@ -94,8 +94,8 @@ VID_shutdown (void *data) palette. Palette data will go away after the call, so copy it if you'll need it later. */ -void -VID_Init (byte *palette, byte *colormap) +static void +X11_VID_Init (byte *palette, byte *colormap) { Sys_RegisterShutdown (VID_shutdown, 0); @@ -134,8 +134,8 @@ VID_Init (byte *palette, byte *colormap) viddef.recalc_refdef = 1; // force a surface cache flush } -void -VID_Init_Cvars () +static void +X11_VID_Init_Cvars (void) { X11_Init_Cvars (); #ifdef HAVE_VULKAN @@ -145,6 +145,12 @@ VID_Init_Cvars () X11_SW_Init_Cvars (); } +vid_system_t vid_system = { + .init = X11_VID_Init, + .init_cvars = X11_VID_Init_Cvars, + .update_fullscreen = X11_UpdateFullscreen, +}; + #if 0 static int config_notify = 0; static int config_notify_width; diff --git a/libs/video/targets/vid_x11_gl.c b/libs/video/targets/vid_x11_gl.c index 30bf0aa19..8679479a0 100644 --- a/libs/video/targets/vid_x11_gl.c +++ b/libs/video/targets/vid_x11_gl.c @@ -116,7 +116,15 @@ static void *(*glGetProcAddress) (const char *symbol) = NULL; static int use_gl_procaddress = 0; static GLXFBConfig glx_cfg; -static cvar_t *gl_driver; +static char *gl_driver; +static cvar_t gl_driver_cvar = { + .name = "gl_driver", + .description = + "The OpenGL library to use. (path optional)", + .default_value = GL_DRIVER, + .flags = CVAR_ROM, + .value = { .type = 0, .value = &gl_driver }, +}; static void * QFGL_GetProcAddress (void *handle, const char *name) @@ -219,9 +227,9 @@ glx_end_rendering (void) static void glx_load_gl (void) { - libgl_handle = dlopen (gl_driver->string, RTLD_NOW); + libgl_handle = dlopen (gl_driver, RTLD_NOW); if (!libgl_handle) { - Sys_Error ("Couldn't load OpenGL library %s: %s", gl_driver->string, + Sys_Error ("Couldn't load OpenGL library %s: %s", gl_driver, dlerror ()); } glGetProcAddress = dlsym (libgl_handle, "glXGetProcAddress"); @@ -255,6 +263,5 @@ X11_GL_Context (void) void X11_GL_Init_Cvars (void) { - gl_driver = Cvar_Get ("gl_driver", GL_DRIVER, CVAR_ROM, NULL, - "The OpenGL library to use. (path optional)"); + Cvar_Register (&gl_driver_cvar, 0, 0); } diff --git a/libs/video/targets/vid_x11_vulkan.c b/libs/video/targets/vid_x11_vulkan.c index 39bf90310..43af1897e 100644 --- a/libs/video/targets/vid_x11_vulkan.c +++ b/libs/video/targets/vid_x11_vulkan.c @@ -61,7 +61,15 @@ #include "vid_internal.h" #include "vid_vulkan.h" -static cvar_t *vulkan_library_name; +static char *vulkan_library_name; +static cvar_t vulkan_library_name_cvar = { + .name = "vulkan_library", + .description = + "the name of the vulkan shared library", + .default_value = "libvulkan.so.1", + .flags = CVAR_ROM, + .value = { .type = 0, .value = &vulkan_library_name }, +}; typedef struct vulkan_presentation_s { #define PRESENTATION_VULKAN_FUNCTION_FROM_EXTENSION(name,ext) PFN_##name name; @@ -84,11 +92,11 @@ static void *vulkan_library; static void load_vulkan_library (vulkan_ctx_t *ctx) { - vulkan_library = dlopen (vulkan_library_name->string, + vulkan_library = dlopen (vulkan_library_name, RTLD_DEEPBIND | RTLD_NOW); if (!vulkan_library) { Sys_Error ("Couldn't load vulkan library %s: %s", - vulkan_library_name->name, dlerror ()); + vulkan_library_name, dlerror ()); } #define EXPORTED_VULKAN_FUNCTION(name) \ @@ -224,7 +232,5 @@ X11_Vulkan_Context (void) void X11_Vulkan_Init_Cvars (void) { - vulkan_library_name = Cvar_Get ("vulkan_library", "libvulkan.so.1", - CVAR_ROM, 0, - "the name of the vulkan shared library"); + Cvar_Register (&vulkan_library_name_cvar, 0, 0); } diff --git a/nq/include/client.h b/nq/include/client.h index de0e7cb02..d059db54f 100644 --- a/nq/include/client.h +++ b/nq/include/client.h @@ -210,21 +210,21 @@ typedef struct client_state_s { } client_state_t; // cvars -extern struct cvar_s *cl_name; -extern struct cvar_s *cl_color; +extern char *cl_name; +extern int cl_color; -extern struct cvar_s *cl_shownet; -extern struct cvar_s *cl_nolerp; +extern int cl_shownet; +extern int cl_nolerp; -extern struct cvar_s *cl_name; -extern struct cvar_s *cl_writecfg; +extern char *cl_name; +extern int cl_writecfg; -extern struct cvar_s *cl_cshift_bonus; -extern struct cvar_s *cl_cshift_contents; -extern struct cvar_s *cl_cshift_damage; -extern struct cvar_s *cl_cshift_powerup; +extern int cl_cshift_bonus; +extern int cl_cshift_contents; +extern int cl_cshift_damage; +extern int cl_cshift_powerup; -extern struct cvar_s *noskins; +extern int noskins; extern client_state_t cl; @@ -273,8 +273,8 @@ void CL_Record (const char *argv1, int track); int CL_GetMessage (void); void CL_Demo_Init (void); -extern struct cvar_s *demo_gzip; -extern struct cvar_s *demo_speed; +extern int demo_gzip; +extern float demo_speed; // cl_parse.c struct skin_s; @@ -292,7 +292,8 @@ extern double realtime; extern qboolean recording; -void Cvar_Info (struct cvar_s *var); +struct cvar_s; +void Cvar_Info (void *data, const struct cvar_s *cvar); void CL_UpdateScreen (double realtime); diff --git a/nq/include/game.h b/nq/include/game.h index 6cf6a978f..485c82426 100644 --- a/nq/include/game.h +++ b/nq/include/game.h @@ -156,7 +156,7 @@ extern int current_skill; // skill level for currently loaded level (in case extern qboolean isDedicated; extern qboolean standard_quake; -extern struct cvar_s *registered; +extern char *registered; struct memhunk_s; void Game_Init (struct memhunk_s *hunk); diff --git a/nq/include/host.h b/nq/include/host.h index 70c7327f9..460188eb4 100644 --- a/nq/include/host.h +++ b/nq/include/host.h @@ -38,11 +38,11 @@ typedef struct extern quakeparms_t host_parms; -extern struct cvar_s *sys_ticrate; -extern struct cvar_s *sys_nostdout; -extern struct cvar_s *developer; +extern float sys_ticrate; +extern int sys_nostdout; +extern int developer; -extern struct cvar_s *pausable; +extern int pausable; extern int viewentity; diff --git a/nq/include/server.h b/nq/include/server.h index 8c43ed2e4..3518f3257 100644 --- a/nq/include/server.h +++ b/nq/include/server.h @@ -202,31 +202,31 @@ typedef struct client_s //============================================================================ -extern struct cvar_s *teamplay; -extern struct cvar_s *skill; -extern struct cvar_s *deathmatch; -extern struct cvar_s *coop; -extern struct cvar_s *fraglimit; -extern struct cvar_s *timelimit; +extern int teamplay; +extern int skill; +extern int deathmatch; +extern int coop; +extern char *fraglimit; +extern int timelimit; -extern struct cvar_s *sv_rollangle; -extern struct cvar_s *sv_rollspeed; +extern float sv_rollangle; +extern float sv_rollspeed; -extern struct cvar_s *sv_maxvelocity; -extern struct cvar_s *sv_gravity; -extern struct cvar_s *sv_jump_any; -extern struct cvar_s *sv_nostep; -extern struct cvar_s *sv_friction; -extern struct cvar_s *sv_edgefriction; -extern struct cvar_s *sv_stopspeed; -extern struct cvar_s *sv_maxspeed; -extern struct cvar_s *sv_accelerate; -extern struct cvar_s *sv_idealpitchscale; -extern struct cvar_s *sv_aim; -extern struct cvar_s *sv_friction; -extern struct cvar_s *sv_stopspeed; +extern float sv_maxvelocity; +extern float sv_gravity; +extern int sv_jump_any; +extern int sv_nostep; +extern float sv_friction; +extern float sv_edgefriction; +extern float sv_stopspeed; +extern float sv_maxspeed; +extern float sv_accelerate; +extern float sv_idealpitchscale; +extern float sv_aim; +extern float sv_friction; +extern float sv_stopspeed; -extern struct cvar_s *max_edicts; +extern int max_edicts; extern server_static_t svs; // persistant server info extern server_t sv; // local server @@ -277,6 +277,7 @@ void SV_FinishGravity (edict_t *ent, vec3_t move); void SV_Physics_Toss (edict_t *ent); void SV_Physics_Client (edict_t *ent, int num); void SV_Physics (void); +void SV_Physics_Init_Cvars (void); void SV_ProgStartFrame (void); void SV_RunNewmis (void); @@ -289,6 +290,7 @@ void SV_MoveToGoal (progs_t *pr, void *data); void SV_CheckForNewClients (void); void SV_RunClients (void); +void SV_User_Init_Cvars (void); void SV_SaveSpawnparms (void); void SV_SpawnServer (const char *server); @@ -296,7 +298,8 @@ void SV_LoadProgs (void); void SV_Progs_Init (void); void SV_Progs_Init_Cvars (void); -void Cvar_Info (struct cvar_s *var); +struct cvar_s; +void Cvar_Info (void *data, const struct cvar_s *cvar); //FIXME location #define STOP_EPSILON 0.1 diff --git a/nq/source/cl_demo.c b/nq/source/cl_demo.c index b4d47eebe..510ea767c 100644 --- a/nq/source/cl_demo.c +++ b/nq/source/cl_demo.c @@ -74,10 +74,44 @@ static void CL_TimeFrames_DumpLog (void); static void CL_TimeFrames_AddTimestamp (void); static void CL_TimeFrames_Reset (void); -cvar_t *demo_gzip; -cvar_t *demo_speed; -cvar_t *demo_quit; -cvar_t *demo_timeframes; +int demo_gzip; +static cvar_t demo_gzip_cvar = { + .name = "demo_gzip", + .description = + "Compress demos using gzip. 0 = none, 1 = least compression, 9 = most " + "compression. Compressed demos (1-9) will have .gz appended to the " + "name", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &demo_gzip }, +}; +float demo_speed; +static cvar_t demo_speed_cvar = { + .name = "demo_speed", + .description = + "adjust demo playback speed. 1.0 = normal, < 1 slow-mo, > 1 timelapse", + .default_value = "1.0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &demo_speed }, +}; +int demo_quit; +static cvar_t demo_quit_cvar = { + .name = "demo_quit", + .description = + "automaticly quit after a timedemo has finished", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &demo_quit }, +}; +int demo_timeframes; +static cvar_t demo_timeframes_cvar = { + .name = "demo_timeframes", + .description = + "write timestamps for every frame", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &demo_timeframes }, +}; #define MAX_DEMMSG (MAX_MSGLEN) @@ -370,9 +404,9 @@ CL_Record (const char *argv1, int track) // open the demo file #ifdef HAVE_ZLIB - if (demo_gzip->int_val) { + if (demo_gzip) { QFS_DefaultExtension (name, ".dem.gz"); - cls.demofile = QFS_WOpen (name->str, demo_gzip->int_val); + cls.demofile = QFS_WOpen (name->str, demo_gzip); } else #endif { @@ -544,7 +578,7 @@ CL_StartTimeDemo (void) cls.td_lastframe = -1; // get a new message this frame CL_TimeFrames_Reset (); - if (demo_timeframes->int_val) + if (demo_timeframes) demo_timeframes_isactive = 1; } @@ -603,7 +637,7 @@ CL_FinishTimeDemo (void) Sys_Printf (" min/max fps: %.3f/%.3f\n", min, max); Sys_Printf ("std deviation: %.3f fps\n", sqrt (variance)); } - if (demo_quit->int_val) + if (demo_quit) Cbuf_InsertText (host_cbuf, "quit\n"); } } @@ -648,17 +682,10 @@ CL_Demo_Init (void) demo_timeframes_index = 0; demo_timeframes_array = NULL; - demo_gzip = Cvar_Get ("demo_gzip", "0", CVAR_ARCHIVE, NULL, - "Compress demos using gzip. 0 = none, 1 = least " - "compression, 9 = most compression. Compressed " - " demos (1-9) will have .gz appended to the name"); - demo_speed = Cvar_Get ("demo_speed", "1.0", CVAR_NONE, NULL, - "adjust demo playback speed. 1.0 = normal, " - "< 1 slow-mo, > 1 timelapse"); - demo_quit = Cvar_Get ("demo_quit", "0", CVAR_NONE, NULL, - "automaticly quit after a timedemo has finished"); - demo_timeframes = Cvar_Get ("demo_timeframes", "0", CVAR_NONE, NULL, - "write timestamps for every frame"); + Cvar_Register (&demo_gzip_cvar, 0, 0); + Cvar_Register (&demo_speed_cvar, 0, 0); + Cvar_Register (&demo_quit_cvar, 0, 0); + Cvar_Register (&demo_timeframes_cvar, 0, 0); Cmd_AddCommand ("record", CL_Record_f, "Record a demo, if no filename " "argument is given\n" "the demo will be called Year-Month-Day-Hour-Minute-" diff --git a/nq/source/cl_ents.c b/nq/source/cl_ents.c index 92ea20f5b..9d0a4d357 100644 --- a/nq/source/cl_ents.c +++ b/nq/source/cl_ents.c @@ -108,7 +108,7 @@ CL_LerpPoint (void) f = cl.mtime[0] - cl.mtime[1]; - if (!f || cl_nolerp->int_val || cls.timedemo || sv.active) { + if (!f || cl_nolerp || cls.timedemo || sv.active) { cl.time = cl.mtime[0]; return 1; } @@ -259,7 +259,7 @@ CL_RelinkEntities (void) animation->pose1 = animation->pose2 = -1; CL_TransformEntity (ent, new->scale / 16.0, new->angles, new->origin); - if (i != cl.viewentity || chase_active->int_val) { + if (i != cl.viewentity || chase_active) { if (ent->visibility.efrag) { R_RemoveEfrags (ent); } @@ -293,7 +293,7 @@ CL_RelinkEntities (void) } CL_TransformEntity (ent, new->scale / 16.0, angles, origin); } - if (i != cl.viewentity || chase_active->int_val) { + if (i != cl.viewentity || chase_active) { if (ent->visibility.efrag) { vec4f_t org = Transform_GetWorldPosition (ent->transform); diff --git a/nq/source/cl_main.c b/nq/source/cl_main.c index 1a489621a..25163ade7 100644 --- a/nq/source/cl_main.c +++ b/nq/source/cl_main.c @@ -70,19 +70,91 @@ static plugin_list_t client_plugin_list[] = { }; // these two are not intended to be set directly -cvar_t *cl_name; -cvar_t *cl_color; +char *cl_name; +static cvar_t cl_name_cvar = { + .name = "_cl_name", + .description = + "Player name", + .default_value = "player", + .flags = CVAR_ARCHIVE, + .value = { .type = 0, .value = &cl_name }, +}; +int cl_color; +static cvar_t cl_color_cvar = { + .name = "_cl_color", + .description = + "Player color", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &cl_color }, +}; -cvar_t *cl_writecfg; +int cl_writecfg; +static cvar_t cl_writecfg_cvar = { + .name = "cl_writecfg", + .description = + "write config files?", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &cl_writecfg }, +}; -cvar_t *cl_shownet; -cvar_t *cl_nolerp; +int cl_shownet; +static cvar_t cl_shownet_cvar = { + .name = "cl_shownet", + .description = + "show network packets. 0=off, 1=basic, 2=verbose", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &cl_shownet }, +}; +int cl_nolerp; +static cvar_t cl_nolerp_cvar = { + .name = "cl_nolerp", + .description = + "linear motion interpolation", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &cl_nolerp }, +}; -cvar_t *hud_fps; -cvar_t *hud_time; +int hud_fps; +static cvar_t hud_fps_cvar = { + .name = "hud_fps", + .description = + "display realtime frames per second", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &hud_fps }, +}; +int hud_time; +static cvar_t hud_time_cvar = { + .name = "hud_time", + .description = + "display the current time", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &hud_time }, +}; -static cvar_t *r_ambient; -static cvar_t *r_drawflat; +static char *r_ambient; +static cvar_t r_ambient_cvar = { + .name = "r_ambient", + .description = + "Determines the ambient lighting for a level", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &r_ambient }, +}; +static char *r_drawflat; +static cvar_t r_drawflat_cvar = { + .name = "r_drawflat", + .description = + "Toggles the drawing of textures", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &r_drawflat }, +}; int fps_count; @@ -99,7 +171,7 @@ CL_WriteConfiguration (void) { // dedicated servers initialize the host but don't parse and set the // config.cfg cvars - if (host_initialized && !isDedicated && cl_writecfg->int_val) { + if (host_initialized && !isDedicated && cl_writecfg) { plitem_t *config = PL_NewDictionary (0); //FIXME hashlinks Cvar_SaveConfig (config); IN_SaveConfig (config); @@ -170,27 +242,19 @@ CL_InitCvars (void) Chase_Init_Cvars (); V_Init_Cvars (); - cl_name = Cvar_Get ("_cl_name", "player", CVAR_ARCHIVE, NULL, - "Player name"); - cl_color = Cvar_Get ("_cl_color", "0", CVAR_ARCHIVE, NULL, "Player color"); - cl_writecfg = Cvar_Get ("cl_writecfg", "1", CVAR_NONE, NULL, - "write config files?"); - cl_shownet = Cvar_Get ("cl_shownet", "0", CVAR_NONE, NULL, - "show network packets. 0=off, 1=basic, 2=verbose"); - cl_nolerp = Cvar_Get ("cl_nolerp", "0", CVAR_NONE, NULL, - "linear motion interpolation"); - hud_fps = Cvar_Get ("hud_fps", "0", CVAR_ARCHIVE, NULL, - "display realtime frames per second"); - Cvar_MakeAlias ("show_fps", hud_fps); - hud_time = Cvar_Get ("hud_time", "0", CVAR_ARCHIVE, NULL, - "display the current time"); + Cvar_Register (&cl_name_cvar, 0, 0); + Cvar_Register (&cl_color_cvar, 0, 0); + Cvar_Register (&cl_writecfg_cvar, 0, 0); + Cvar_Register (&cl_shownet_cvar, 0, 0); + Cvar_Register (&cl_nolerp_cvar, 0, 0); + Cvar_Register (&hud_fps_cvar, 0, 0); + Cvar_MakeAlias ("show_fps", &hud_fps_cvar); + Cvar_Register (&hud_time_cvar, 0, 0); //FIXME not hooked up (don't do anything), but should not work in //multi-player - r_ambient = Cvar_Get ("r_ambient", "0", CVAR_NONE, NULL, - "Determines the ambient lighting for a level"); - r_drawflat = Cvar_Get ("r_drawflat", "0", CVAR_NONE, NULL, - "Toggles the drawing of textures"); + Cvar_Register (&r_ambient_cvar, 0, 0); + Cvar_Register (&r_drawflat_cvar, 0, 0); } void @@ -345,11 +409,11 @@ CL_SignonReply (void) case so_spawn: MSG_WriteByte (&cls.message, clc_stringcmd); MSG_WriteString (&cls.message, va (0, "name \"%s\"\n", - cl_name->string)); + cl_name)); MSG_WriteByte (&cls.message, clc_stringcmd); MSG_WriteString (&cls.message, - va (0, "color %i %i\n", (cl_color->int_val) >> 4, - (cl_color->int_val) & 15)); + va (0, "color %i %i\n", (cl_color) >> 4, + (cl_color) & 15)); MSG_WriteByte (&cls.message, clc_stringcmd); MSG_WriteString (&cls.message, "spawn"); break; @@ -450,7 +514,7 @@ CL_ReadFromServer (void) CL_ParseServerMessage (); } while (ret && cls.state >= ca_connected); - if (cl_shownet->int_val) + if (cl_shownet) Sys_Printf ("\n"); CL_RelinkEntities (); diff --git a/nq/source/cl_parse.c b/nq/source/cl_parse.c index 2bf14fe2c..b9c1f0ac6 100644 --- a/nq/source/cl_parse.c +++ b/nq/source/cl_parse.c @@ -707,7 +707,7 @@ CL_SetStat (int stat, int value) } #define SHOWNET(x) \ - if (cl_shownet->int_val == 2) \ + if (cl_shownet == 2) \ Sys_Printf ("%3i:%s\n", net_message->readcount - 1, x); void @@ -725,9 +725,9 @@ CL_ParseServerMessage (void) }; // if recording demos, copy the message out - if (cl_shownet->int_val == 1) + if (cl_shownet == 1) Sys_Printf ("%i ", net_message->message->cursize); - else if (cl_shownet->int_val == 2) + else if (cl_shownet == 2) Sys_Printf ("------------------\n"); cl.viewstate.onground = -1; // unless the server says otherwise diff --git a/nq/source/cl_screen.c b/nq/source/cl_screen.c index 3fd0a3bf5..4bbb1f9dd 100644 --- a/nq/source/cl_screen.c +++ b/nq/source/cl_screen.c @@ -95,8 +95,8 @@ scr_draw_views (void) net_view->visible = (!cls.demoplayback && realtime - cl.last_servermessage >= 0.3); loading_view->visible = cl.loading; - timegraph_view->visible = r_timegraph->int_val; - zgraph_view->visible = r_zgraph->int_val; + timegraph_view->visible = r_timegraph; + zgraph_view->visible = r_zgraph; view_draw (r_data->vid->conview); } diff --git a/nq/source/game.c b/nq/source/game.c index 6fc7c225b..bbac0de20 100644 --- a/nq/source/game.c +++ b/nq/source/game.c @@ -40,8 +40,24 @@ qboolean standard_quake = false; -cvar_t *registered; -cvar_t *cmdline; +char *registered; +static cvar_t registered_cvar = { + .name = "registered", + .description = + "Is the game the registered version. 1 yes 0 no", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = ®istered }, +}; +char *cmdline; +static cvar_t cmdline_cvar = { + .name = "cmdline", + .description = + "None", + .default_value = "0", + .flags = CVAR_SERVERINFO, + .value = { .type = 0/* not used */, .value = &cmdline }, +}; int static_registered = 1; /* @@ -66,7 +82,7 @@ Game_CheckRegistered (void) } if (static_registered) { - Cvar_Set (registered, "1"); + Cvar_Set ("registered", "1"); Sys_Printf ("Playing registered version.\n"); } } @@ -91,9 +107,8 @@ Game_Init (memhunk_t *hunk) } QFS_Init (hunk, game); - registered = Cvar_Get ("registered", "0", CVAR_NONE, NULL, - "Is the game the registered version. 1 yes 0 no"); - cmdline = Cvar_Get ("cmdline", "0", CVAR_SERVERINFO, Cvar_Info, "None"); + Cvar_Register (®istered_cvar, 0, 0); + Cvar_Register (&cmdline_cvar, Cvar_Info, &cmdline); Game_CheckRegistered (); } diff --git a/nq/source/host.c b/nq/source/host.c index 86b428c5a..dc45ef372 100644 --- a/nq/source/host.c +++ b/nq/source/host.c @@ -105,40 +105,178 @@ client_t *host_client; // current client jmp_buf host_abortserver; -cvar_t *host_mem_size; +float host_mem_size; +static cvar_t host_mem_size_cvar = { + .name = "host_mem_size", + .description = + "Amount of memory (in MB) to allocate for the " + PACKAGE_NAME + " heap", + .default_value = "40", + .flags = CVAR_ROM, + .value = { .type = &cexpr_float, .value = &host_mem_size }, +}; -cvar_t *host_framerate; -cvar_t *host_speeds; -cvar_t *max_edicts; +float host_framerate; +static cvar_t host_framerate_cvar = { + .name = "host_framerate", + .description = + "set for slow motion", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &host_framerate }, +}; +int host_speeds; +static cvar_t host_speeds_cvar = { + .name = "host_speeds", + .description = + "set for running times", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &host_speeds }, +}; +int max_edicts; +static cvar_t max_edicts_cvar = { + .name = "max_edicts", + .description = + "maximum server edicts", + .default_value = "1024", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &max_edicts }, +}; -cvar_t *sys_ticrate; -cvar_t *serverprofile; +float sys_ticrate; +static cvar_t sys_ticrate_cvar = { + .name = "sys_ticrate", + .description = + "None", + .default_value = "0.05", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &sys_ticrate }, +}; +int serverprofile; +static cvar_t serverprofile_cvar = { + .name = "serverprofile", + .description = + "None", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &serverprofile }, +}; -cvar_t *cl_quakerc; +int cl_quakerc; +static cvar_t cl_quakerc_cvar = { + .name = "cl_quakerc", + .description = + "exec quake.rc on startup", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &cl_quakerc }, +}; -cvar_t *fraglimit; -cvar_t *timelimit; -cvar_t *teamplay; -cvar_t *noexit; -cvar_t *samelevel; +char *fraglimit; +static cvar_t fraglimit_cvar = { + .name = "fraglimit", + .description = + "None", + .default_value = "0", + .flags = CVAR_SERVERINFO, + .value = { .type = 0/* not used */, .value = &fraglimit }, +}; +int timelimit; +static cvar_t timelimit_cvar = { + .name = "timelimit", + .description = + "None", + .default_value = "0", + .flags = CVAR_SERVERINFO, + .value = { .type = &cexpr_int, .value = &timelimit }, +}; +int teamplay; +static cvar_t teamplay_cvar = { + .name = "teamplay", + .description = + "None", + .default_value = "0", + .flags = CVAR_SERVERINFO, + .value = { .type = &cexpr_int, .value = &teamplay }, +}; +char *noexit; +static cvar_t noexit_cvar = { + .name = "noexit", + .description = + "None", + .default_value = "0", + .flags = CVAR_SERVERINFO, + .value = { .type = 0/* not used */, .value = &noexit }, +}; +char *samelevel; +static cvar_t samelevel_cvar = { + .name = "samelevel", + .description = + "None", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &samelevel }, +}; -cvar_t *skill; -cvar_t *coop; -cvar_t *deathmatch; +int skill; +static cvar_t skill_cvar = { + .name = "skill", + .description = + "0 - 3", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &skill }, +}; +int coop; +static cvar_t coop_cvar = { + .name = "coop", + .description = + "0 or 1", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &coop }, +}; +int deathmatch; +static cvar_t deathmatch_cvar = { + .name = "deathmatch", + .description = + "0, 1, or 2", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &deathmatch }, +}; -cvar_t *pausable; - -cvar_t *temp1; -cvar_t *cl_usleep; - -static int cl_usleep_cache; - -static void -cl_usleep_f (cvar_t *var) -{ - cl_usleep_cache = var->int_val; -} +int pausable; +static cvar_t pausable_cvar = { + .name = "pausable", + .description = + "None", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &pausable }, +}; +char *temp1; +static cvar_t temp1_cvar = { + .name = "temp1", + .description = + "None", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &temp1 }, +}; +int cl_usleep; +static cvar_t cl_usleep_cvar = { + .name = "cl_usleep", + .description = + "Turn this on to save cpu when fps limited. May affect frame rate " + "adversely depending on local machine/os conditions", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &cl_usleep }, +}; void Host_EndGame (const char *message, ...) @@ -248,9 +386,9 @@ Host_FindMaxClients (void) Hunk_AllocName (0, svs.maxclientslimit * sizeof (client_t), "clients"); if (svs.maxclients > 1) - Cvar_SetValue (deathmatch, 1.0); + deathmatch = 1.0; else - Cvar_SetValue (deathmatch, 0.0); + deathmatch = 0.0; } static void @@ -258,37 +396,26 @@ Host_InitLocal (void) { Host_InitCommands (); - host_framerate = - Cvar_Get ("host_framerate", "0", CVAR_NONE, NULL, - "set for slow motion"); - host_speeds = - Cvar_Get ("host_speeds", "0", CVAR_NONE, NULL, - "set for running times"); - max_edicts = Cvar_Get ("max_edicts", "1024", CVAR_NONE, NULL, - "maximum server edicts"); + Cvar_Register (&host_framerate_cvar, 0, 0); + Cvar_Register (&host_speeds_cvar, 0, 0); + Cvar_Register (&max_edicts_cvar, 0, 0); - sys_ticrate = Cvar_Get ("sys_ticrate", "0.05", CVAR_NONE, NULL, "None"); - serverprofile = Cvar_Get ("serverprofile", "0", CVAR_NONE, NULL, "None"); + Cvar_Register (&sys_ticrate_cvar, 0, 0); + Cvar_Register (&serverprofile_cvar, 0, 0); - cl_quakerc = Cvar_Get ("cl_quakerc", "1", CVAR_NONE, NULL, - "exec quake.rc on startup"); + Cvar_Register (&cl_quakerc_cvar, 0, 0); - fraglimit = Cvar_Get ("fraglimit", "0", CVAR_SERVERINFO, Cvar_Info, - "None"); - timelimit = Cvar_Get ("timelimit", "0", CVAR_SERVERINFO, Cvar_Info, - "None"); - teamplay = Cvar_Get ("teamplay", "0", CVAR_SERVERINFO, Cvar_Info, "None"); - samelevel = Cvar_Get ("samelevel", "0", CVAR_NONE, NULL, "None"); - noexit = Cvar_Get ("noexit", "0", CVAR_SERVERINFO, Cvar_Info, "None"); - skill = Cvar_Get ("skill", "1", CVAR_NONE, NULL, "0 - 3"); - deathmatch = Cvar_Get ("deathmatch", "0", CVAR_NONE, NULL, "0, 1, or 2"); - coop = Cvar_Get ("coop", "0", CVAR_NONE, NULL, "0 or 1"); - pausable = Cvar_Get ("pausable", "1", CVAR_NONE, NULL, "None"); - temp1 = Cvar_Get ("temp1", "0", CVAR_NONE, NULL, "None"); - cl_usleep = Cvar_Get ("cl_usleep", "1", CVAR_ARCHIVE, cl_usleep_f, - "Turn this on to save cpu when fps limited. " - "May affect frame rate adversely depending on " - "local machine/os conditions"); + Cvar_Register (&fraglimit_cvar, Cvar_Info, &fraglimit); + Cvar_Register (&timelimit_cvar, Cvar_Info, &timelimit); + Cvar_Register (&teamplay_cvar, Cvar_Info, &teamplay); + Cvar_Register (&samelevel_cvar, 0, 0); + Cvar_Register (&noexit_cvar, Cvar_Info, &noexit); + Cvar_Register (&skill_cvar, 0, 0); + Cvar_Register (&deathmatch_cvar, 0, 0); + Cvar_Register (&coop_cvar, 0, 0); + Cvar_Register (&pausable_cvar, 0, 0); + Cvar_Register (&temp1_cvar, 0, 0); + Cvar_Register (&cl_usleep_cvar, 0, 0); Host_FindMaxClients (); @@ -525,7 +652,7 @@ Host_FilterTime (float time) con_realtime += time; if (cls.demoplayback) { - timescale = max (0, demo_speed->value); + timescale = max (0, demo_speed); time *= timescale; } @@ -543,8 +670,8 @@ Host_FilterTime (float time) con_frametime = con_realtime - oldcon_realtime; oldcon_realtime = con_realtime; - if (host_framerate->value > 0) - host_frametime = host_framerate->value; + if (host_framerate > 0) + host_frametime = host_framerate; else // don't allow really long or short frames host_frametime = bound (0.000, host_frametime, 0.1); @@ -593,17 +720,17 @@ Host_ClientFrame (void) CL_ReadFromServer (); // update video - if (host_speeds->int_val) + if (host_speeds) time1 = Sys_DoubleTime (); - r_data->inhibit_viewmodel = (chase_active->int_val + r_data->inhibit_viewmodel = (chase_active || (cl.stats[STAT_ITEMS] & IT_INVISIBILITY) || cl.stats[STAT_HEALTH] <= 0); r_data->frametime = host_frametime; CL_UpdateScreen (cl.time); - if (host_speeds->int_val) + if (host_speeds) time2 = Sys_DoubleTime (); // update audio @@ -623,7 +750,7 @@ Host_ClientFrame (void) CDAudio_Update (); - if (host_speeds->int_val) { + if (host_speeds) { pass1 = (time1 - time3) * 1000; time3 = Sys_DoubleTime (); pass2 = (time2 - time1) * 1000; @@ -670,7 +797,7 @@ _Host_Frame (float time) if ((sleeptime = Host_FilterTime (time)) != 0) { // don't run too fast, or packet will flood outs #ifdef HAVE_USLEEP - if (cl_usleep_cache && sleeptime > 0.002) // minimum sleep time + if (cl_usleep && sleeptime > 0.002) // minimum sleep time usleep ((unsigned long) (sleeptime * 1000000 / 2)); #endif return; @@ -729,7 +856,7 @@ Host_Frame (float time) int c, m; static int timecount; - if (!serverprofile->int_val) { + if (!serverprofile) { _Host_Frame (time); return; } @@ -835,18 +962,15 @@ Host_Init_Memory (void) else minimum_memory = MINIMUM_MEMORY_LEVELPAK; - host_mem_size = Cvar_Get ("host_mem_size", "40", CVAR_NONE, NULL, - "Amount of memory (in MB) to allocate for the " - PACKAGE_NAME " heap"); + Cvar_Register (&host_mem_size_cvar, 0, 0); if (mem_parm) - Cvar_Set (host_mem_size, com_argv[mem_parm + 1]); + Cvar_Set ("host_mem_size", com_argv[mem_parm + 1]); if (COM_CheckParm ("-minmemory")) - Cvar_SetValue (host_mem_size, minimum_memory / (1024 * 1024.0)); + host_mem_size = minimum_memory / (1024 * 1024.0); - Cvar_SetFlags (host_mem_size, host_mem_size->flags | CVAR_ROM); - mem_size = ((size_t) host_mem_size->value * 1024 * 1024); + mem_size = ((size_t) host_mem_size * 1024 * 1024); if (mem_size < minimum_memory) Sys_Error ("Only %4.1f megs of memory reported, can't execute game", @@ -860,7 +984,7 @@ Host_Init_Memory (void) Sys_PageIn (mem_base, mem_size); memhunk_t *hunk = Memory_Init (mem_base, mem_size); - Sys_Printf ("%4.1f megabyte heap\n", host_mem_size->value); + Sys_Printf ("%4.1f megabyte heap\n", host_mem_size); return hunk; } @@ -873,14 +997,14 @@ Host_ExecConfig (cbuf_t *cbuf, int skip_quakerc) // should be used to set up defaults on the assumption that the user has // things set up to work with another (hopefully compatible) client if (CL_ReadConfiguration ("quakeforge.cfg")) { - Cmd_Exec_File (cbuf, fs_usercfg->string, 0); + Cmd_Exec_File (cbuf, fs_usercfg, 0); Cmd_StuffCmds (cbuf); COM_Check_quakerc ("startdemos", cbuf); } else { if (!skip_quakerc) { Cbuf_InsertText (cbuf, "exec quake.rc\n"); } - Cmd_Exec_File (cbuf, fs_usercfg->string, 0); + Cmd_Exec_File (cbuf, fs_usercfg, 0); // Reparse the command line for + commands. // (sets still done, but it doesn't matter) // (Note, no non-base commands exist yet) @@ -939,7 +1063,7 @@ Host_Init (void) CL_UpdateScreen (cl.time); CL_UpdateScreen (cl.time); - Host_ExecConfig (host_cbuf, isDedicated || !cl_quakerc->int_val); + Host_ExecConfig (host_cbuf, isDedicated || !cl_quakerc); Hunk_AllocName (0, 0, "-HOST_HUNKLEVEL-"); host_hunklevel = Hunk_LowMark (0); diff --git a/nq/source/host_cmd.c b/nq/source/host_cmd.c index 2ad67d3b3..3bd37b6d0 100644 --- a/nq/source/host_cmd.c +++ b/nq/source/host_cmd.c @@ -92,7 +92,7 @@ Host_Status_f (void) } else print = SV_ClientPrintf; - print ("host: %s\n", Cvar_VariableString ("hostname")); + print ("host: %s\n", hostname); print ("version: %4.2s\n", PACKAGE_VERSION); if (tcpipAvailable) print ("tcp/ip: %s\n", my_tcpip_address); @@ -667,7 +667,7 @@ Host_Loadgame_f (void) spawn_parms[i] = atof (PL_String (PL_ObjectAtIndex (item, i))); } current_skill = atoi (PL_String (PL_ObjectForKey (game, "current_skill"))); - Cvar_SetValue (skill, current_skill); + skill = current_skill; mapname = strdup (PL_String (PL_ObjectForKey (game, "name"))); CL_Disconnect_f (); @@ -742,7 +742,7 @@ Host_Name_f (void) const char *newName; if (Cmd_Argc () == 1) { - Sys_Printf ("\"name\" is \"%s\"\n", cl_name->string); + Sys_Printf ("\"name\" is \"%s\"\n", cl_name); return; } if (Cmd_Argc () == 2) @@ -751,9 +751,9 @@ Host_Name_f (void) newName = Cmd_Args (1); if (cmd_source == src_command) { - if (strcmp (cl_name->string, newName) == 0) + if (strcmp (cl_name, newName) == 0) return; - Cvar_Set (cl_name, va (0, "%.15s", newName)); + Cvar_Set ("_cl_name", va (0, "%.15s", newName)); if (cls.state >= ca_connected) CL_Cmd_ForwardToServer (); return; @@ -815,7 +815,7 @@ Host_Say (qboolean teamonly) if (!fromServer) snprintf (text, sizeof (text), "%c%s: ", 1, save->name); else - snprintf (text, sizeof (text), "%c<%s> ", 1, hostname->string); + snprintf (text, sizeof (text), "%c<%s> ", 1, hostname); j = sizeof (text) - 2 - strlen (text); // -2 for /n and null terminator if (strlen (p) > j) @@ -827,7 +827,7 @@ Host_Say (qboolean teamonly) for (j = 0, client = svs.clients; j < svs.maxclients; j++, client++) { if (!client || !client->active || !client->spawned) continue; - if (teamplay->int_val && teamonly && SVfloat (client->edict, team) != + if (teamplay && teamonly && SVfloat (client->edict, team) != SVfloat (save->edict, team)) continue; host_client = client; @@ -925,7 +925,7 @@ Host_Pause_f (void) CL_Cmd_ForwardToServer (); return; } - if (!pausable->int_val) + if (!pausable) SV_ClientPrintf ("Pause not allowed.\n"); else { sv.paused ^= 1; @@ -1137,7 +1137,7 @@ Host_Kick_f (void) if (net_is_dedicated) who = "Console"; else - who = cl_name->string; + who = cl_name; else who = save->name; diff --git a/nq/source/sbar.c b/nq/source/sbar.c index 9e98ce717..df3762ed6 100644 --- a/nq/source/sbar.c +++ b/nq/source/sbar.c @@ -64,6 +64,7 @@ #include "nq/include/server.h" int sb_updates; // if >= vid.numpages, no update needed +static int sb_view_size; #define STAT_MINUS 10 // num frame for '-' stats digit @@ -106,124 +107,33 @@ int hipweapons[4] = { HIT_LASER_CANNON_BIT, HIT_MJOLNIR_BIT, 4, HIT_PROXIMITY_GUN_BIT }; qpic_t *hsb_items[2]; // MED 01/04/97 added hipnotic items array -cvar_t *scr_centertime; -cvar_t *scr_printspeed; - -static view_t *sbar_view; -static view_t *sbar_inventory_view; -static view_t *sbar_frags_view; - -static view_t *hud_view; -static view_t *hud_inventory_view; -static view_t *hud_armament_view; -static view_t *hud_frags_view; - -static view_t *overlay_view; -static view_t *stuff_view; -static view_t *main_view; +float scr_centertime; +static cvar_t scr_centertime_cvar = { + .name = "scr_centertime", + .description = + "How long in seconds screen hints are displayed", + .default_value = "2", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &scr_centertime }, +}; +float scr_printspeed; +static cvar_t scr_printspeed_cvar = { + .name = "scr_printspeed", + .description = + "How fast the text is displayed at the end of the single player " + "episodes", + .default_value = "8", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &scr_printspeed }, +}; static void -hud_swap_f (cvar_t *var) +viewsize_f (int view_size) { - if (var->int_val) { - hud_armament_view->gravity = grav_southwest; - hud_armament_view->children[0]->gravity = grav_northwest; - hud_armament_view->children[1]->gravity = grav_southeast; - stuff_view->gravity = grav_southeast; - } else { - hud_armament_view->gravity = grav_southeast; - hud_armament_view->children[0]->gravity = grav_northeast; - hud_armament_view->children[1]->gravity = grav_southwest; - stuff_view->gravity = grav_southwest; - } - view_move (hud_armament_view, hud_armament_view->xpos, - hud_armament_view->ypos); - view_move (stuff_view, stuff_view->xpos, stuff_view->ypos); -} - -static void -hud_scoreboard_gravity_f (cvar_t *var) -{ - grav_t grav; - - if (strequal (var->string, "center")) - grav = grav_center; - else if (strequal (var->string, "northwest")) - grav = grav_northwest; - else if (strequal (var->string, "north")) - grav = grav_north; - else if (strequal (var->string, "northeast")) - grav = grav_northeast; - else if (strequal (var->string, "west")) - grav = grav_west; - else if (strequal (var->string, "east")) - grav = grav_east; - else if (strequal (var->string, "southwest")) - grav = grav_southwest; - else if (strequal (var->string, "south")) - grav = grav_south; - else if (strequal (var->string, "southeast")) - grav = grav_southeast; - else - grav = grav_center; - overlay_view->gravity = grav; - view_move (overlay_view, overlay_view->xpos, overlay_view->ypos); -} - -static void -calc_sb_lines (cvar_t *var) -{ - int stuff_y; - - if (var->int_val >= 120) { - sb_lines = 0; - stuff_y = 0; - } else if (var->int_val >= 110) { - sb_lines = 24; - sbar_inventory_view->visible = 0; - hud_inventory_view->visible = 0; - hud_armament_view->visible = 0; - stuff_y = 32; - } else { - sb_lines = 48; - sbar_inventory_view->visible = 1; - hud_inventory_view->visible = 1; - hud_armament_view->visible = 1; - stuff_y = 48; - } - if (sb_lines) { - sbar_view->visible = 1; - hud_view->visible = 1; - view_resize (sbar_view, sbar_view->xlen, sb_lines); - view_resize (hud_view, hud_view->xlen, sb_lines); - } else { - sbar_view->visible = 0; - hud_view->visible = 0; - } - view_move (stuff_view, stuff_view->xpos, stuff_y); -} - -static void -hud_sbar_f (cvar_t *var) -{ - if (r_data->scr_viewsize) - calc_sb_lines (r_data->scr_viewsize); - SCR_SetBottomMargin (var->int_val ? sb_lines : 0); - if (var->int_val) { - view_remove (main_view, main_view->children[0]); - view_insert (main_view, sbar_view, 0); - } else { - view_remove (main_view, main_view->children[0]); - view_insert (main_view, hud_view, 0); - } -} - -static void -viewsize_f (cvar_t *var) -{ - calc_sb_lines (var); + sb_view_size = view_size; + HUD_Calc_sb_lines (view_size); if (hud_sbar) { - SCR_SetBottomMargin (hud_sbar->int_val ? sb_lines : 0); + SCR_SetBottomMargin (hud_sbar ? sb_lines : 0); } } @@ -835,7 +745,7 @@ draw_rogue_status (view_t *view) draw_pic (view, 0, 0, sb_armor[0]); // PGM 03/02/97 - fixed so color swatch appears in only CTF modes - if (cl.maxclients != 1 && teamplay->int_val > 3 && teamplay->int_val < 7) + if (cl.maxclients != 1 && teamplay > 3 && teamplay < 7) draw_rogue_face (view); else draw_face (view); @@ -996,7 +906,7 @@ sbar_update_vis (void) sbar_view->visible = 0; - headsup = !(hud_sbar->int_val || r_data->scr_viewsize->int_val < 100); + headsup = !(hud_sbar || sb_view_size < 100); if ((sb_updates >= r_data->vid->numpages) && !headsup) return; @@ -1007,9 +917,9 @@ sbar_update_vis (void) if (cls.state == ca_active && ((cl.stats[STAT_HEALTH] <= 0) || sb_showscores)) - overlay_view->visible = 1; + hud_overlay_view->visible = 1; else - overlay_view->visible = 0; + hud_overlay_view->visible = 0; if (!sb_lines) return; @@ -1024,7 +934,7 @@ void Sbar_Draw (void) { sbar_update_vis (); - main_view->draw (main_view); + hud_main_view->draw (hud_main_view); } static void @@ -1078,7 +988,7 @@ Sbar_DrawScoreboard (void) { //Sbar_SoloScoreboard (); if (cl.gametype == GAME_DEATHMATCH) - Sbar_DeathmatchOverlay (overlay_view); + Sbar_DeathmatchOverlay (hud_overlay_view); } static void @@ -1109,10 +1019,10 @@ draw_time (view_t *view) # define HOUR24 "%k" # define PM "%P" #endif - if (hud_time->int_val == 1) { // Use international format + if (hud_time == 1) { // Use international format strftime (st, sizeof (st), HOUR24":%M", local); draw_string (view, 8, 0, st); - } else if (hud_time->int_val >= 2) { // US AM/PM display + } else if (hud_time >= 2) { // US AM/PM display strftime (st, sizeof (st), HOUR12":%M "PM, local); draw_string (view, 8, 0, st); } @@ -1139,9 +1049,9 @@ draw_fps (view_t *view) static void draw_stuff (view_t *view) { - if (hud_time->int_val > 0) + if (hud_time > 0) draw_time (view); - if (hud_fps->int_val > 0) + if (hud_fps > 0) draw_fps (view); } @@ -1182,10 +1092,10 @@ Sbar_IntermissionOverlay (void) r_data->scr_fullupdate = 0; if (cl.gametype == GAME_DEATHMATCH) { - Sbar_DeathmatchOverlay (overlay_view); + Sbar_DeathmatchOverlay (hud_overlay_view); return; } - draw_intermission (overlay_view); + draw_intermission (hud_overlay_view); } /* CENTER PRINTING */ @@ -1209,7 +1119,7 @@ Sbar_CenterPrint (const char *str) dstring_copystr (¢er_string, str); - centertime_off = scr_centertime->value; + centertime_off = scr_centertime; centertime_start = realtime; // count the number of lines for centering @@ -1263,10 +1173,10 @@ Sbar_FinaleOverlay (void) r_data->scr_copyeverything = 1; - draw_cachepic (overlay_view, 0, 16, "gfx/finale.lmp", 1); + draw_cachepic (hud_overlay_view, 0, 16, "gfx/finale.lmp", 1); // the finale prints the characters one at a time - remaining = scr_printspeed->value * (realtime - centertime_start); - Sbar_DrawCenterString (overlay_view, remaining); + remaining = scr_printspeed * (realtime - centertime_start); + Sbar_DrawCenterString (hud_overlay_view, remaining); } void @@ -1278,7 +1188,7 @@ Sbar_DrawCenterPrint (void) if (centertime_off <= 0) return; - Sbar_DrawCenterString (overlay_view, -1); + Sbar_DrawCenterString (hud_overlay_view, -1); } static void @@ -1383,7 +1293,7 @@ init_hud_views (void) view_add (hud_view, hud_armament_view); - view_insert (main_view, hud_view, 0); + view_insert (hud_main_view, hud_view, 0); } static void @@ -1495,7 +1405,7 @@ init_hipnotic_hud_views (void) view_add (hud_view, hud_armament_view); - view_insert (main_view, hud_view, 0); + view_insert (hud_main_view, hud_view, 0); } static void @@ -1592,33 +1502,33 @@ init_rogue_hud_views (void) view_add (hud_view, hud_armament_view); - view_insert (main_view, hud_view, 0); + view_insert (hud_main_view, hud_view, 0); } static void init_views (void) { - main_view = view_new (0, 0, r_data->vid->conview->xlen, + hud_main_view = view_new (0, 0, r_data->vid->conview->xlen, r_data->vid->conview->ylen, grav_northwest); if (con_module) - view_insert (con_module->data->console->view, main_view, 0); - main_view->resize_x = 1; // get resized if the 2d view resizes - main_view->resize_y = 1; - main_view->visible = 0; // but don't let the console draw our stuff + view_insert (con_module->data->console->view, hud_main_view, 0); + hud_main_view->resize_x = 1; // get resized if the 2d view resizes + hud_main_view->resize_y = 1; + hud_main_view->visible = 0; // but don't let the console draw our stuff if (r_data->vid->conview->ylen > 300) - overlay_view = view_new (0, 0, 320, 300, grav_center); + hud_overlay_view = view_new (0, 0, 320, 300, grav_center); else - overlay_view = view_new (0, 0, 320, r_data->vid->conview->ylen, + hud_overlay_view = view_new (0, 0, 320, r_data->vid->conview->ylen, grav_center); - overlay_view->draw = draw_overlay; - overlay_view->visible = 0; + hud_overlay_view->draw = draw_overlay; + hud_overlay_view->visible = 0; - stuff_view = view_new (0, 48, 152, 16, grav_southwest); - stuff_view->draw = draw_stuff; + hud_stuff_view = view_new (0, 48, 152, 16, grav_southwest); + hud_stuff_view->draw = draw_stuff; - view_insert (main_view, overlay_view, 0); - view_insert (main_view, stuff_view, 0); + view_insert (hud_main_view, hud_overlay_view, 0); + view_insert (hud_main_view, hud_stuff_view, 0); if (!strcmp (qfs_gamedir->hudtype, "hipnotic")) { init_hipnotic_sbar_views (); @@ -1793,21 +1703,9 @@ Sbar_Init (void) } r_data->viewsize_callback = viewsize_f; - hud_sbar = Cvar_Get ("hud_sbar", "0", CVAR_ARCHIVE, hud_sbar_f, - "status bar mode: 0 = hud, 1 = oldstyle"); - hud_swap = Cvar_Get ("hud_swap", "0", CVAR_ARCHIVE, hud_swap_f, - "new HUD on left side?"); - hud_scoreboard_gravity = Cvar_Get ("hud_scoreboard_gravity", "center", - CVAR_ARCHIVE, hud_scoreboard_gravity_f, - "control placement of scoreboard " - "overlay: center, northwest, north, " - "northeast, west, east, southwest, " - "south, southeast"); - scr_centertime = Cvar_Get ("scr_centertime", "2", CVAR_NONE, NULL, "How " - "long in seconds screen hints are displayed"); - scr_printspeed = Cvar_Get ("scr_printspeed", "8", CVAR_NONE, NULL, - "How fast the text is displayed at the end of " - "the single player episodes"); + HUD_Init_Cvars (); + Cvar_Register (&scr_centertime_cvar, 0, 0); + Cvar_Register (&scr_printspeed_cvar, 0, 0); // register GIB builtins GIB_Builtin_Add ("print::center", Sbar_GIB_Print_Center_f); diff --git a/nq/source/sv_cl_phys.c b/nq/source/sv_cl_phys.c index 5a7cda831..20e5ee784 100644 --- a/nq/source/sv_cl_phys.c +++ b/nq/source/sv_cl_phys.c @@ -39,8 +39,6 @@ #define sv_frametime host_frametime -cvar_t *sv_nostep; - // CLIENT MOVEMENT ============================================================ /* @@ -248,7 +246,7 @@ SV_WalkMove (edict_t *ent) if (SVfloat (ent, movetype) != MOVETYPE_WALK) return; // gibbed by a trigger - if (sv_nostep->int_val) + if (sv_nostep) return; if ((int) SVfloat (sv_player, flags) & FL_WATERJUMP) diff --git a/nq/source/sv_cvar.c b/nq/source/sv_cvar.c index 0e8e35383..ea2bfbfd5 100644 --- a/nq/source/sv_cvar.c +++ b/nq/source/sv_cvar.c @@ -35,11 +35,11 @@ #include "nq/include/server.h" void -Cvar_Info (cvar_t *var) +Cvar_Info (void *data, const cvar_t *cvar) { - if (var->flags & CVAR_SERVERINFO) { + if (cvar->flags & CVAR_SERVERINFO) { if (sv.active) SV_BroadcastPrintf ("\"%s\" changed to \"%s\"\n", - var->name, var->string); + cvar->name, Cvar_VarString (cvar)); } } diff --git a/nq/source/sv_ded.c b/nq/source/sv_ded.c index d687063ed..fd0741a7c 100644 --- a/nq/source/sv_ded.c +++ b/nq/source/sv_ded.c @@ -46,10 +46,10 @@ client_static_t cls; worldscene_t cl_world; -cvar_t *cl_name; -cvar_t *cl_writecfg; -cvar_t *demo_speed; -cvar_t *chase_active; +char *cl_name; +int cl_writecfg; +float demo_speed; +int chase_active; int fps_count; int viewentity; diff --git a/nq/source/sv_main.c b/nq/source/sv_main.c index 57282ea1d..04a6bf048 100644 --- a/nq/source/sv_main.c +++ b/nq/source/sv_main.c @@ -85,28 +85,8 @@ SV_Init (void) SV_Progs_Init (); - sv_maxvelocity = Cvar_Get ("sv_maxvelocity", "2000", CVAR_NONE, NULL, - "None"); - sv_gravity = Cvar_Get ("sv_gravity", "800", CVAR_SERVERINFO, Cvar_Info, - "None"); - sv_jump_any = Cvar_Get ("sv_jump_any", "1", CVAR_NONE, NULL, "None"); - sv_friction = Cvar_Get ("sv_friction", "4", CVAR_SERVERINFO, Cvar_Info, - "None"); - //NOTE: the cl/sv clash is deliberate: dedicated server will use the right - //vars, but client/server combo will use the one. - sv_rollspeed = Cvar_Get ("cl_rollspeed", "200", CVAR_NONE, NULL, - "How quickly you straighten out after strafing"); - sv_rollangle = Cvar_Get ("cl_rollangle", "2.0", CVAR_NONE, NULL, - "How much your screen tilts when strafing"); - sv_edgefriction = Cvar_Get ("edgefriction", "2", CVAR_NONE, NULL, "None"); - sv_stopspeed = Cvar_Get ("sv_stopspeed", "100", CVAR_NONE, NULL, "None"); - sv_maxspeed = Cvar_Get ("sv_maxspeed", "320", CVAR_SERVERINFO, Cvar_Info, - "None"); - sv_accelerate = Cvar_Get ("sv_accelerate", "10", CVAR_NONE, NULL, "None"); - sv_idealpitchscale = Cvar_Get ("sv_idealpitchscale", "0.8", CVAR_NONE, - NULL, "None"); - sv_aim = Cvar_Get ("sv_aim", "0.93", CVAR_NONE, NULL, "None"); - sv_nostep = Cvar_Get ("sv_nostep", "0", CVAR_NONE, NULL, "None"); + SV_Physics_Init_Cvars (); + SV_User_Init_Cvars (); Cmd_AddCommand ("sv_protocol", SV_Protocol_f, "set the protocol to be " "used after the next map load"); @@ -254,7 +234,7 @@ SV_SendServerinfo (client_t *client) MSG_WriteLong (&client->message, sv.protocol); MSG_WriteByte (&client->message, svs.maxclients); - if (!coop->int_val && deathmatch->int_val) + if (!coop && deathmatch) MSG_WriteByte (&client->message, GAME_DEATHMATCH); else MSG_WriteByte (&client->message, GAME_COOP); @@ -1109,8 +1089,8 @@ SV_SpawnServer (const char *server) S_BlockSound (); // let's not have any servers with no name - if (hostname->string[0] == 0) - Cvar_Set (hostname, "UNNAMED"); + if (hostname[0] == 0) + Cvar_Set ("hostname", "UNNAMED"); Sys_MaskPrintf (SYS_dev, "SpawnServer: %s\n", server); svs.changelevel_issued = false; // now safe to issue another @@ -1122,15 +1102,15 @@ SV_SpawnServer (const char *server) } // make cvars consistant - if (coop->int_val) - Cvar_SetValue (deathmatch, 0); - current_skill = skill->int_val; + if (coop) + deathmatch = 0; + current_skill = skill; if (current_skill < 0) current_skill = 0; if (current_skill > 3) current_skill = 3; - Cvar_SetValue (skill, (float) current_skill); + skill = current_skill; // set up the new server Host_ClearMemory (); @@ -1142,7 +1122,7 @@ SV_SpawnServer (const char *server) sv.protocol = sv_protocol; // load progs to get entity field count - sv.max_edicts = bound (MIN_EDICTS, max_edicts->int_val, MAX_EDICTS); + sv.max_edicts = bound (MIN_EDICTS, max_edicts, MAX_EDICTS); SV_LoadProgs (); SV_FreeAllEdictLeafs (); @@ -1202,10 +1182,10 @@ SV_SpawnServer (const char *server) SVfloat (ent, solid) = SOLID_BSP; SVfloat (ent, movetype) = MOVETYPE_PUSH; - if (coop->int_val) - *sv_globals.coop = coop->int_val; + if (coop) + *sv_globals.coop = coop; else - *sv_globals.deathmatch = deathmatch->int_val; + *sv_globals.deathmatch = deathmatch; *sv_globals.mapname = PR_SetString (&sv_pr_state, sv.name); diff --git a/nq/source/sv_phys.c b/nq/source/sv_phys.c index 552fe227a..6d8d1cecb 100644 --- a/nq/source/sv_phys.c +++ b/nq/source/sv_phys.c @@ -54,11 +54,52 @@ solid_edge items clip against only bsp models. */ -cvar_t *sv_friction; -cvar_t *sv_gravity; -cvar_t *sv_jump_any; -cvar_t *sv_maxvelocity; -cvar_t *sv_stopspeed; +float sv_friction; +static cvar_t sv_friction_cvar = { + .name = "sv_friction", + .description = + "Sets the friction value for the players", + .default_value = "4", + .flags = CVAR_SERVERINFO, + .value = { .type = &cexpr_float, .value = &sv_friction }, +}; +float sv_gravity; +static cvar_t sv_gravity_cvar = { + .name = "sv_gravity", + .description = + "Sets the global value for the amount of gravity", + .default_value = "800", + .flags = CVAR_SERVERINFO, + .value = { .type = &cexpr_float, .value = &sv_gravity }, +}; +int sv_jump_any; +static cvar_t sv_jump_any_cvar = { + .name = "sv_jump_any", + .description = + "None", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sv_jump_any }, +}; +float sv_maxvelocity; +static cvar_t sv_maxvelocity_cvar = { + .name = "sv_maxvelocity", + .description = + "Sets the maximum velocity an object can travel", + .default_value = "2000", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &sv_maxvelocity }, +}; +float sv_stopspeed; +static cvar_t sv_stopspeed_cvar = { + .name = "sv_stopspeed", + .description = + "Sets the value that determines how fast the player should come to a " + "complete stop", + .default_value = "100", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &sv_stopspeed }, +}; #define MOVE_EPSILON 0.01 #if 0 @@ -107,8 +148,8 @@ SV_CheckVelocity (edict_t *ent) } #endif wishspeed = VectorLength (SVvector (ent, velocity)); - if (wishspeed > sv_maxvelocity->value) { - VectorScale (SVvector (ent, velocity), sv_maxvelocity->value / + if (wishspeed > sv_maxvelocity) { + VectorScale (SVvector (ent, velocity), sv_maxvelocity / wishspeed, SVvector (ent, velocity)); } } @@ -208,7 +249,7 @@ SV_EntCanSupportJump (edict_t *ent) int solid = SVfloat (ent, solid); if (solid == SOLID_BSP) return 1; - if (!sv_jump_any->int_val) + if (!sv_jump_any) return 0; if (solid == SOLID_NOT || solid == SOLID_SLIDEBOX) return 0; @@ -352,7 +393,7 @@ SV_AddGravity (edict_t *ent) ent_grav = SVfloat (ent, gravity); else ent_grav = 1.0; - SVvector (ent, velocity)[2] -= ent_grav * sv_gravity->value * sv_frametime; + SVvector (ent, velocity)[2] -= ent_grav * sv_gravity * sv_frametime; SVdata (ent)->add_grav = true; } @@ -365,7 +406,7 @@ SV_FinishGravity (edict_t *ent, vec3_t move) ent_grav = SVfloat (ent, gravity); else ent_grav = 1.0; - ent_grav *= sv_gravity->value; + ent_grav *= sv_gravity; move[2] += ent_grav * sv_frametime * sv_frametime / 2; } @@ -768,7 +809,7 @@ SV_Physics_Step (edict_t *ent) // freefall if not on ground if (!((int) SVfloat (ent, flags) & (FL_ONGROUND | FL_FLY | FL_SWIM))) { - if (SVvector (ent, velocity)[2] < sv_gravity->value * -0.1) + if (SVvector (ent, velocity)[2] < sv_gravity * -0.1) hitsound = true; else hitsound = false; @@ -889,3 +930,13 @@ SV_Physics (void) PR_ExecuteProgram (&sv_pr_state, sv_funcs.EndFrame); } } + +void +SV_Physics_Init_Cvars (void) +{ + Cvar_Register (&sv_friction_cvar, Cvar_Info, &sv_friction); + Cvar_Register (&sv_gravity_cvar, Cvar_Info, &sv_gravity); + Cvar_Register (&sv_jump_any_cvar, 0, 0); + Cvar_Register (&sv_maxvelocity_cvar, 0, 0); + Cvar_Register (&sv_stopspeed_cvar, 0, 0); +} diff --git a/nq/source/sv_pr_cmds.c b/nq/source/sv_pr_cmds.c index b805a40be..9984d97ff 100644 --- a/nq/source/sv_pr_cmds.c +++ b/nq/source/sv_pr_cmds.c @@ -949,7 +949,15 @@ PF_pointcontents (progs_t *pr, void *data) R_FLOAT (pr) = SV_PointContents (v); } -cvar_t *sv_aim; +float sv_aim; +static cvar_t sv_aim_cvar = { + .name = "sv_aim", + .description = + "None", + .default_value = "0.93", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &sv_aim }, +}; /* PF_aim @@ -980,7 +988,7 @@ PF_aim (progs_t *pr, void *data) VectorMultAdd (start, 2048, dir, end); tr = SV_Move (start, vec3_origin, vec3_origin, end, false, ent); if (tr.ent && SVfloat (tr.ent, takedamage) == DAMAGE_AIM - && (!teamplay->int_val || SVfloat (ent, team) <= 0 + && (!teamplay || SVfloat (ent, team) <= 0 || SVfloat (ent, team) != SVfloat (tr.ent, team))) { VectorCopy (*sv_globals.v_forward, R_VECTOR (pr)); return; @@ -988,7 +996,7 @@ PF_aim (progs_t *pr, void *data) // try all possible entities VectorCopy (dir, bestdir); - bestdist = sv_aim->value; + bestdist = sv_aim; bestent = NULL; check = NEXT_EDICT (pr, sv.edicts); @@ -997,7 +1005,7 @@ PF_aim (progs_t *pr, void *data) continue; if (check == ent) continue; - if (teamplay->int_val && SVfloat (ent, team) > 0 + if (teamplay && SVfloat (ent, team) > 0 && SVfloat (ent, team) == SVfloat (check, team)) continue; // don't aim at teammate @@ -1574,6 +1582,8 @@ static builtin_t builtins[] = { void SV_PR_Cmds_Init () { + Cvar_Register (&sv_aim_cvar, 0, 0); + RUA_Init (&sv_pr_state, 1); PR_Cmds_Init (&sv_pr_state); diff --git a/nq/source/sv_progs.c b/nq/source/sv_progs.c index a0235e108..e9e318a28 100644 --- a/nq/source/sv_progs.c +++ b/nq/source/sv_progs.c @@ -55,23 +55,151 @@ sv_fields_t sv_fields; edict_t sv_edicts[MAX_EDICTS]; sv_data_t sv_data[MAX_EDICTS]; -cvar_t *sv_progs; -cvar_t *sv_progs_zone; -cvar_t *sv_progs_stack; -cvar_t *sv_progs_ext; -cvar_t *pr_checkextensions; +char *sv_progs; +static cvar_t sv_progs_cvar = { + .name = "sv_progs", + .description = + "Override the default game progs.", + .default_value = "", + .flags = CVAR_NONE, + .value = { .type = 0, .value = &sv_progs }, +}; +int sv_progs_zone; +static cvar_t sv_progs_zone_cvar = { + .name = "sv_progs_zone", + .description = + "size of the zone for progs in kb", + .default_value = "256", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sv_progs_zone }, +}; +int sv_progs_stack; +static cvar_t sv_progs_stack_cvar = { + .name = "sv_progs_stack", + .description = + "size of the stack for progs in kb", + .default_value = "256", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sv_progs_stack }, +}; +char *sv_progs_ext; +static cvar_t sv_progs_ext_cvar = { + .name = "sv_progs_ext", + .description = + "extention mapping to use: none, id, qf", + .default_value = "qf", + .flags = CVAR_NONE, + .value = { .type = 0, .value = &sv_progs_ext }, +}; +char *pr_checkextensions; +static cvar_t pr_checkextensions_cvar = { + .name = "pr_checkextensions", + .description = + "indicate the presence of the checkextentions qc function", + .default_value = "1", + .flags = CVAR_ROM, + .value = { .type = 0/* not used */, .value = &pr_checkextensions }, +}; -cvar_t *nomonsters; -cvar_t *gamecfg; -cvar_t *scratch1; -cvar_t *scratch2; -cvar_t *scratch3; -cvar_t *scratch4; -cvar_t *savedgamecfg; -cvar_t *saved1; -cvar_t *saved2; -cvar_t *saved3; -cvar_t *saved4; +char *nomonsters; +static cvar_t nomonsters_cvar = { + .name = "nomonsters", + .description = + "No Description", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &nomonsters }, +}; +char *gamecfg; +static cvar_t gamecfg_cvar = { + .name = "gamecfg", + .description = + "No Description", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &gamecfg }, +}; +char *scratch1; +static cvar_t scratch1_cvar = { + .name = "scratch1", + .description = + "No Description", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &scratch1 }, +}; +char *scratch2; +static cvar_t scratch2_cvar = { + .name = "scratch2", + .description = + "No Description", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &scratch2 }, +}; +char *scratch3; +static cvar_t scratch3_cvar = { + .name = "scratch3", + .description = + "No Description", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &scratch3 }, +}; +char *scratch4; +static cvar_t scratch4_cvar = { + .name = "scratch4", + .description = + "No Description", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &scratch4 }, +}; +char *savedgamecfg; +static cvar_t savedgamecfg_cvar = { + .name = "savedgamecfg", + .description = + "No Description", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = 0/* not used */, .value = &savedgamecfg }, +}; +char *saved1; +static cvar_t saved1_cvar = { + .name = "saved1", + .description = + "No Description", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = 0/* not used */, .value = &saved1 }, +}; +char *saved2; +static cvar_t saved2_cvar = { + .name = "saved2", + .description = + "No Description", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = 0/* not used */, .value = &saved2 }, +}; +char *saved3; +static cvar_t saved3_cvar = { + .name = "saved3", + .description = + "No Description", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = 0/* not used */, .value = &saved3 }, +}; +char *saved4; +static cvar_t saved4_cvar = { + .name = "saved4", + .description = + "No Description", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = 0/* not used */, .value = &saved4 }, +}; static int sv_range; @@ -93,7 +221,7 @@ static int prune_edict (progs_t *pr, edict_t *ent) { // remove things from different skill levels or deathmatch - if (deathmatch->int_val) { + if (deathmatch) { if (((int) SVfloat (ent, spawnflags) & SPAWNFLAG_NOT_DEATHMATCH)) { return 1; @@ -493,10 +621,10 @@ SV_LoadProgs (void) const char *progs_name = "progs.dat"; const char *range; - if (strequal (sv_progs_ext->string, "qf")) { + if (strequal (sv_progs_ext, "qf")) { sv_range = PR_RANGE_QF; range = "QF"; - } else if (strequal (sv_progs_ext->string, "id")) { + } else if (strequal (sv_progs_ext, "id")) { sv_range = PR_RANGE_ID; range = "ID"; } else { @@ -510,12 +638,12 @@ SV_LoadProgs (void) if (qfs_gamedir->gamecode && *qfs_gamedir->gamecode) progs_name = qfs_gamedir->gamecode; - if (*sv_progs->string) - progs_name = sv_progs->string; + if (*sv_progs) + progs_name = sv_progs; sv_pr_state.max_edicts = sv.max_edicts; - sv_pr_state.zone_size = sv_progs_zone->int_val * 1024; - sv_pr_state.stack_size = sv_progs_stack->int_val * 1024; + sv_pr_state.zone_size = sv_progs_zone * 1024; + sv_pr_state.stack_size = sv_progs_stack * 1024; sv.edicts = sv_edicts; PR_LoadProgs (&sv_pr_state, progs_name); @@ -559,30 +687,21 @@ void SV_Progs_Init_Cvars (void) { PR_Init_Cvars (); - sv_progs = Cvar_Get ("sv_progs", "", CVAR_NONE, NULL, - "Override the default game progs."); - sv_progs_zone = Cvar_Get ("sv_progs_zone", "256", CVAR_NONE, NULL, - "size of the zone for progs in kb"); - sv_progs_stack = Cvar_Get ("sv_progs_stack", "256", CVAR_NONE, NULL, - "size of the stack for progs in kb"); - sv_progs_ext = Cvar_Get ("sv_progs_ext", "qf", CVAR_NONE, NULL, - "extention mapping to use: " - "none, id, qf"); - pr_checkextensions = Cvar_Get ("pr_checkextensions", "1", CVAR_ROM, NULL, - "indicate the presence of the " - "checkextentions qc function"); + Cvar_Register (&sv_progs_cvar, 0, 0); + Cvar_Register (&sv_progs_zone_cvar, 0, 0); + Cvar_Register (&sv_progs_stack_cvar, 0, 0); + Cvar_Register (&sv_progs_ext_cvar, 0, 0); + Cvar_Register (&pr_checkextensions_cvar, 0, 0); - nomonsters = Cvar_Get ("nomonsters", "0", CVAR_NONE, NULL, - "No Description"); - gamecfg = Cvar_Get ("gamecfg", "0", CVAR_NONE, NULL, "No Description"); - scratch1 = Cvar_Get ("scratch1", "0", CVAR_NONE, NULL, "No Description"); - scratch2 = Cvar_Get ("scratch2", "0", CVAR_NONE, NULL, "No Description"); - scratch3 = Cvar_Get ("scratch3", "0", CVAR_NONE, NULL, "No Description"); - scratch4 = Cvar_Get ("scratch4", "0", CVAR_NONE, NULL, "No Description"); - savedgamecfg = Cvar_Get ("savedgamecfg", "0", CVAR_ARCHIVE, NULL, - "No Description"); - saved1 = Cvar_Get ("saved1", "0", CVAR_ARCHIVE, NULL, "No Description"); - saved2 = Cvar_Get ("saved2", "0", CVAR_ARCHIVE, NULL, "No Description"); - saved3 = Cvar_Get ("saved3", "0", CVAR_ARCHIVE, NULL, "No Description"); - saved4 = Cvar_Get ("saved4", "0", CVAR_ARCHIVE, NULL, "No Description"); + Cvar_Register (&nomonsters_cvar, 0, 0); + Cvar_Register (&gamecfg_cvar, 0, 0); + Cvar_Register (&scratch1_cvar, 0, 0); + Cvar_Register (&scratch2_cvar, 0, 0); + Cvar_Register (&scratch3_cvar, 0, 0); + Cvar_Register (&scratch4_cvar, 0, 0); + Cvar_Register (&savedgamecfg_cvar, 0, 0); + Cvar_Register (&saved1_cvar, 0, 0); + Cvar_Register (&saved2_cvar, 0, 0); + Cvar_Register (&saved3_cvar, 0, 0); + Cvar_Register (&saved4_cvar, 0, 0); } diff --git a/nq/source/sv_user.c b/nq/source/sv_user.c index 87623e7d6..f1470146d 100644 --- a/nq/source/sv_user.c +++ b/nq/source/sv_user.c @@ -48,12 +48,46 @@ #include "nq/include/server.h" #include "nq/include/sv_progs.h" -cvar_t *sv_rollangle; -cvar_t *sv_rollspeed; +int sv_nostep; +static cvar_t sv_nostep_cvar = { + .name = "sv_nostep", + .description = + "None", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sv_nostep }, +}; + +float sv_rollangle; +static cvar_t sv_rollangle_cvar = { + .name = "cl_rollangle", + .description = + "How much your screen tilts when strafing", + .default_value = "2.0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &sv_rollangle }, +}; +float sv_rollspeed; +static cvar_t sv_rollspeed_cvar = { + .name = "cl_rollspeed", + .description = + "How quickly you straighten out after strafing", + .default_value = "200", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &sv_rollspeed }, +}; edict_t *sv_player; -cvar_t *sv_edgefriction; +float sv_edgefriction; +static cvar_t sv_edgefriction_cvar = { + .name = "edgefriction", + .description = + "None", + .default_value = "2", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &sv_edgefriction }, +}; vec3_t forward, right, up; @@ -69,7 +103,15 @@ qboolean onground; usercmd_t cmd; -cvar_t *sv_idealpitchscale; +float sv_idealpitchscale; +static cvar_t sv_idealpitchscale_cvar = { + .name = "sv_idealpitchscale", + .description = + "None", + .default_value = "0.8", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &sv_idealpitchscale }, +}; #define MAX_FORWARD 6 @@ -86,12 +128,12 @@ SV_CalcRoll (const vec3_t angles, const vec3_t velocity) sign = side < 0 ? -1 : 1; side = fabs (side); - value = sv_rollangle->value; + value = sv_rollangle; // if (cl.inwater) // value *= 6; - if (side < sv_rollspeed->value) - side = side * value / sv_rollspeed->value; + if (side < sv_rollspeed) + side = side * value / sv_rollspeed; else side = value; @@ -154,7 +196,7 @@ SV_SetIdealPitch (void) if (steps < 2) return; - SVfloat (sv_player, idealpitch) = -dir * sv_idealpitchscale->value; + SVfloat (sv_player, idealpitch) = -dir * sv_idealpitchscale; } static void @@ -180,12 +222,12 @@ SV_UserFriction (void) trace = SV_Move (start, vec3_origin, vec3_origin, stop, true, sv_player); if (trace.fraction == 1.0) - friction = sv_friction->value * sv_edgefriction->value; + friction = sv_friction * sv_edgefriction; else - friction = sv_friction->value; + friction = sv_friction; // apply friction - control = speed < sv_stopspeed->value ? sv_stopspeed->value : speed; + control = speed < sv_stopspeed ? sv_stopspeed : speed; newspeed = speed - host_frametime * control * friction; if (newspeed < 0) @@ -197,8 +239,24 @@ SV_UserFriction (void) vel[2] = vel[2] * newspeed; } -cvar_t *sv_maxspeed; -cvar_t *sv_accelerate; +float sv_maxspeed; +static cvar_t sv_maxspeed_cvar = { + .name = "sv_maxspeed", + .description = + "None", + .default_value = "320", + .flags = CVAR_SERVERINFO, + .value = { .type = &cexpr_float, .value = &sv_maxspeed }, +}; +float sv_accelerate; +static cvar_t sv_accelerate_cvar = { + .name = "sv_accelerate", + .description = + "None", + .default_value = "10", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &sv_accelerate }, +}; #if 0 void @@ -214,7 +272,7 @@ SV_Accelerate (vec3_t wishvel) VectorSubtract (wishvel, velocity, pushvec); addspeed = VectorNormalize (pushvec); - accelspeed = sv_accelerate->value * host_frametime * addspeed; + accelspeed = sv_accelerate * host_frametime * addspeed; if (accelspeed > addspeed) accelspeed = addspeed; @@ -233,7 +291,7 @@ SV_Accelerate (void) addspeed = wishspeed - currentspeed; if (addspeed <= 0) return; - accelspeed = sv_accelerate->value * host_frametime * wishspeed; + accelspeed = sv_accelerate * host_frametime * wishspeed; if (accelspeed > addspeed) accelspeed = addspeed; @@ -254,8 +312,8 @@ SV_AirAccelerate (vec3_t wishveloc) addspeed = wishspd - currentspeed; if (addspeed <= 0) return; -// accelspeed = sv_accelerate->value * host_frametime; - accelspeed = sv_accelerate->value * wishspeed * host_frametime; +// accelspeed = sv_accelerate * host_frametime; + accelspeed = sv_accelerate * wishspeed * host_frametime; if (accelspeed > addspeed) accelspeed = addspeed; @@ -296,16 +354,16 @@ SV_WaterMove (void) wishvel[2] += cmd.upmove; wishspeed = VectorLength (wishvel); - if (wishspeed > sv_maxspeed->value) { - VectorScale (wishvel, sv_maxspeed->value / wishspeed, wishvel); - wishspeed = sv_maxspeed->value; + if (wishspeed > sv_maxspeed) { + VectorScale (wishvel, sv_maxspeed / wishspeed, wishvel); + wishspeed = sv_maxspeed; } wishspeed *= 0.7; // water friction speed = VectorLength (velocity); if (speed) { - newspeed = speed - host_frametime * speed * sv_friction->value; + newspeed = speed - host_frametime * speed * sv_friction; if (newspeed < 0) newspeed = 0; VectorScale (velocity, newspeed / speed, velocity); @@ -321,7 +379,7 @@ SV_WaterMove (void) return; VectorNormalize (wishvel); - accelspeed = sv_accelerate->value * wishspeed * host_frametime; + accelspeed = sv_accelerate * wishspeed * host_frametime; if (accelspeed > addspeed) accelspeed = addspeed; @@ -368,9 +426,9 @@ SV_AirMove (void) VectorCopy (wishvel, wishdir); wishspeed = VectorNormalize (wishdir); - if (wishspeed > sv_maxspeed->value) { - VectorScale (wishvel, sv_maxspeed->value / wishspeed, wishvel); - wishspeed = sv_maxspeed->value; + if (wishspeed > sv_maxspeed) { + VectorScale (wishvel, sv_maxspeed / wishspeed, wishvel); + wishspeed = sv_maxspeed; } if (SVfloat (sv_player, movetype) == MOVETYPE_NOCLIP) { // noclip @@ -608,3 +666,40 @@ SV_RunClients (void) SV_ClientThink (); } } + +static void +sv_rollspeed_f (void *data, const cvar_t *cvar) +{ + sv_rollspeed = *(float *) cvar->value.value; +} + +static void +sv_rollangle_f (void *data, const cvar_t *cvar) +{ + sv_rollangle = *(float *) cvar->value.value; +} + +void +SV_User_Init_Cvars (void) +{ + //NOTE: the cl/sv clash is deliberate: dedicated server will use the right + //vars, but client/server combo will use the one. + if (isDedicated) { + Cvar_Register (&sv_rollspeed_cvar, 0, 0); + Cvar_Register (&sv_rollangle_cvar, 0, 0); + } else { + cvar_t *var; + var = Cvar_FindVar ("cl_rollspeed"); + Cvar_AddListener (var, sv_rollspeed_f, 0); + sv_rollspeed = *(float *) var->value.value; + var = Cvar_FindVar ("cl_rollangle"); + Cvar_AddListener (var, sv_rollangle_f, 0); + sv_rollangle = *(float *) var->value.value; + } + Cvar_Register (&sv_edgefriction_cvar, 0, 0); + Cvar_Register (&sv_maxspeed_cvar, Cvar_Info, &sv_maxspeed); + Cvar_Register (&sv_accelerate_cvar, 0, 0); + Cvar_Register (&sv_idealpitchscale_cvar, 0, 0); + + Cvar_Register (&sv_nostep_cvar, 0, 0); +} diff --git a/nq/source/sys_sdl.c b/nq/source/sys_sdl.c index 68c2e91eb..70193fd74 100644 --- a/nq/source/sys_sdl.c +++ b/nq/source/sys_sdl.c @@ -119,7 +119,7 @@ SDL_main (int argc, char *argv[]) Host_Init (); #ifndef _WIN32 - if (!sys_nostdout->int_val) { + if (!sys_nostdout) { fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) | O_NONBLOCK); Sys_Printf ("Quake -- Version %s\n", NQ_VERSION); } @@ -137,14 +137,14 @@ SDL_main (int argc, char *argv[]) time = newtime - oldtime; if (net_is_dedicated) { // play vcrfiles at max speed - if (time < sys_ticrate->value && (!vcrFile || recording)) { + if (time < sys_ticrate && (!vcrFile || recording)) { usleep (1); continue; // not time to run a server-only tic yet } - time = sys_ticrate->value; + time = sys_ticrate; } - if (time > sys_ticrate->value * 2) + if (time > sys_ticrate * 2) oldtime = newtime; else oldtime += time; diff --git a/nq/source/sys_unix.c b/nq/source/sys_unix.c index e244b940e..83d61a105 100644 --- a/nq/source/sys_unix.c +++ b/nq/source/sys_unix.c @@ -80,7 +80,7 @@ main (int argc, const char **argv) Host_Init (); - if (!sys_nostdout->int_val) { + if (!sys_nostdout) { fcntl (0, F_SETFL, fcntl (0, F_GETFL, 0) | O_NONBLOCK); Sys_Printf ("Quake -- Version %s\n", NQ_VERSION); } @@ -92,14 +92,14 @@ main (int argc, const char **argv) time = newtime - oldtime; if (net_is_dedicated) { // play vcrfiles at max speed - if (time < sys_ticrate->value && (!vcrFile || recording)) { + if (time < sys_ticrate && (!vcrFile || recording)) { usleep (1); continue; // not time to run a server-only tic yet } - time = sys_ticrate->value; + time = sys_ticrate; } - if (time > sys_ticrate->value * 2) + if (time > sys_ticrate * 2) oldtime = newtime; else oldtime += time; diff --git a/nq/source/sys_unixd.c b/nq/source/sys_unixd.c index 18e45a8ad..2971e2242 100644 --- a/nq/source/sys_unixd.c +++ b/nq/source/sys_unixd.c @@ -100,13 +100,13 @@ main (int argc, const char **argv) // find time spent rendering last frame newtime = Sys_DoubleTime (); time = newtime - oldtime; - if (time < sys_ticrate->value) { + if (time < sys_ticrate) { usleep (1); continue; // not time to run a server-only tic yet } - time = sys_ticrate->value; + time = sys_ticrate; - if (time > sys_ticrate->value * 2) + if (time > sys_ticrate * 2) oldtime = newtime; else oldtime += time; diff --git a/nq/source/sys_win.c b/nq/source/sys_win.c index 59c61b796..eb543d1c9 100644 --- a/nq/source/sys_win.c +++ b/nq/source/sys_win.c @@ -229,14 +229,14 @@ WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, time = newtime - oldtime; if (net_is_dedicated) { // play vcrfiles at max speed - if (time < sys_ticrate->value && (!vcrFile || recording)) { + if (time < sys_ticrate && (!vcrFile || recording)) { Sleep (1); continue; // not time to run a server-only tic yet } - time = sys_ticrate->value; + time = sys_ticrate; } - if (time > sys_ticrate->value * 2) + if (time > sys_ticrate * 2) oldtime = newtime; else oldtime += time; diff --git a/nq/source/sys_wind.c b/nq/source/sys_wind.c index 69393dfd6..0f1681278 100644 --- a/nq/source/sys_wind.c +++ b/nq/source/sys_wind.c @@ -79,13 +79,13 @@ main (int argc, const char **argv) // find time spent rendering last frame newtime = Sys_DoubleTime (); time = newtime - oldtime; - if (time < sys_ticrate->value) { + if (time < sys_ticrate) { Sleep (1); continue; // not time to run a server-only tic yet } - time = sys_ticrate->value; + time = sys_ticrate; - if (time > sys_ticrate->value * 2) + if (time > sys_ticrate * 2) oldtime = newtime; else oldtime += time; diff --git a/qtv/include/qtv.h b/qtv/include/qtv.h index f8d0918f3..c6afcf39c 100644 --- a/qtv/include/qtv.h +++ b/qtv/include/qtv.h @@ -54,7 +54,7 @@ extern double realtime; extern struct cbuf_s *qtv_cbuf; extern struct cbuf_args_s *qtv_args; -extern struct cvar_s *sv_timeout; +extern float sv_timeout; struct client_s; diff --git a/qtv/source/qtv.c b/qtv/source/qtv.c index 7d720ce0a..6c95554a9 100644 --- a/qtv/source/qtv.c +++ b/qtv/source/qtv.c @@ -75,14 +75,49 @@ static plugin_list_t server_plugin_list[] = { double realtime; -cvar_t *sv_timeout; +float sv_timeout; +static cvar_t sv_timeout_cvar = { + .name = "timeout", + .description = + "Sets the amount of time in seconds before a client is considered " + "disconnected if the server does not receive a packet", + .default_value = "60", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &sv_timeout }, +}; cbuf_t *qtv_cbuf; cbuf_args_t *qtv_args; -static cvar_t *qtv_console_plugin; -static cvar_t *qtv_port; -static cvar_t *qtv_mem_size; +static char *qtv_console_plugin; +static cvar_t qtv_console_plugin_cvar = { + .name = "qtv_console_plugin", + .description = + "Plugin used for the console", + .default_value = "server", + .flags = CVAR_ROM, + .value = { .type = 0, .value = &qtv_console_plugin }, +}; +static int qtv_port; +static cvar_t qtv_port_cvar = { + .name = "qtv_port", + .description = + "udp port to use", + .default_value = 0, + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &qtv_port }, +}; +static float qtv_mem_size; +static cvar_t qtv_mem_size_cvar = { + .name = "qtv_mem_size", + .description = + "Amount of memory (in MB) to allocate for the " + PACKAGE_NAME + " heap", + .default_value = "8", + .flags = CVAR_ROM, + .value = { .type = &cexpr_float, .value = &qtv_mem_size }, +}; redirect_t qtv_redirected; client_t *qtv_redirect_client; @@ -208,12 +243,9 @@ qtv_memory_init (void) int mem_size; void *mem_base; - qtv_mem_size = Cvar_Get ("qtv_mem_size", "8", CVAR_NONE, NULL, - "Amount of memory (in MB) to allocate for the " - PACKAGE_NAME " heap"); + Cvar_Register (&qtv_mem_size_cvar, 0, 0); - Cvar_SetFlags (qtv_mem_size, qtv_mem_size->flags | CVAR_ROM); - mem_size = (int) (qtv_mem_size->value * 1024 * 1024); + mem_size = (int) (qtv_mem_size * 1024 * 1024); mem_base = Sys_Alloc (mem_size); if (!mem_base) Sys_Error ("Can't allocate %d", mem_size); @@ -237,10 +269,10 @@ qtv_quit_f (void) static void qtv_net_init (void) { - qtv_port = Cvar_Get ("qtv_port", va (0, "%d", PORT_QTV), 0, 0, - "udp port to use"); - sv_timeout = Cvar_Get ("sv_timeout", "60", 0, 0, "server timeout"); - NET_Init (qtv_port->int_val); + qtv_port_cvar.default_value = nva ("%d", PORT_QTV); + Cvar_Register (&qtv_port_cvar, 0, 0); + Cvar_Register (&sv_timeout_cvar, 0, 0); + NET_Init (qtv_port); Connection_Init (); net_realtime = &realtime; Netchan_Init (); @@ -256,17 +288,16 @@ qtv_init (void) Sys_Init (); COM_ParseConfig (qtv_cbuf); - Cvar_Get ("cmd_warncmd", "1", CVAR_NONE, NULL, NULL); + cmd_warncmd = 1; memhunk_t *hunk = qtv_memory_init (); QFS_Init (hunk, "qw"); PI_Init (); - qtv_console_plugin = Cvar_Get ("qtv_console_plugin", "server", - CVAR_ROM, 0, "Plugin used for the console"); + Cvar_Register (&qtv_console_plugin_cvar, 0, 0); PI_RegisterPlugins (server_plugin_list); - Con_Init (qtv_console_plugin->string); + Con_Init (qtv_console_plugin); if (con_module) con_module->data->console->cbuf = qtv_cbuf; Sys_SetStdPrintf (qtv_print); diff --git a/qtv/source/server.c b/qtv/source/server.c index 28f43ad6f..6e25723a8 100644 --- a/qtv/source/server.c +++ b/qtv/source/server.c @@ -449,7 +449,7 @@ sv_new_f (void) sv->name = strdup (name); sv->address = strdup (address); sv->adr = adr; - sv->qport = qport->int_val; + sv->qport = qport; sv->info = Info_ParseString ("", MAX_INFO_STRING, 0); Info_SetValueForStarKey (sv->info, "*ver", va (0, "%s QTV %s", QW_VERSION, PACKAGE_VERSION), @@ -554,7 +554,7 @@ Server_Frame (void) server_t *sv; for (sv = servers; sv; sv = sv->next) { - if (realtime - sv->netchan.last_received > sv_timeout->value) { + if (realtime - sv->netchan.last_received > sv_timeout) { qtv_printf ("Server %s timed out\n", sv->name); server_drop (sv); return; // chain has changed, avoid segfaulting diff --git a/qw/include/cl_demo.h b/qw/include/cl_demo.h index 190444785..b11f89583 100644 --- a/qw/include/cl_demo.h +++ b/qw/include/cl_demo.h @@ -40,7 +40,7 @@ void CL_Record (const char *argv1, int track); // track ignored void CL_Demo_Init (void); -extern struct cvar_s *demo_speed; -extern struct cvar_s *demo_gzip; +extern float demo_speed; +extern int demo_gzip; #endif diff --git a/qw/include/cl_ents.h b/qw/include/cl_ents.h index 93872edda..b6d5bc283 100644 --- a/qw/include/cl_ents.h +++ b/qw/include/cl_ents.h @@ -43,7 +43,7 @@ void CL_ParsePlayerinfo (void); void CL_Ents_Init (void); struct entity_s *CL_GetEntity (int num); -extern struct cvar_s *cl_deadbodyfilter; -extern struct cvar_s *cl_gibfilter; +extern int cl_deadbodyfilter; +extern int cl_gibfilter; #endif diff --git a/qw/include/cl_main.h b/qw/include/cl_main.h index 61d9d0481..9ed6667d9 100644 --- a/qw/include/cl_main.h +++ b/qw/include/cl_main.h @@ -52,13 +52,13 @@ void CL_BeginServerConnect(void); #define soundlist_name "soundlist %i %i" -extern struct cvar_s *cl_predict_players; -extern struct cvar_s *cl_solid_players; -extern struct cvar_s *cl_autoexec; -extern struct cvar_s *cl_cshift_bonus; -extern struct cvar_s *cl_cshift_contents; -extern struct cvar_s *cl_cshift_damage; -extern struct cvar_s *cl_cshift_powerup; +extern int cl_predict_players; +extern int cl_solid_players; +extern int cl_autoexec; +extern int cl_cshift_bonus; +extern int cl_cshift_contents; +extern int cl_cshift_damage; +extern int cl_cshift_powerup; extern struct gib_event_s *cl_player_health_e, *cl_chat_e; diff --git a/qw/include/client.h b/qw/include/client.h index 876bc6cca..7951338cb 100644 --- a/qw/include/client.h +++ b/qw/include/client.h @@ -257,28 +257,28 @@ typedef struct client_state_s { /* cvars */ -extern struct cvar_s *cl_netgraph; -extern struct cvar_s *cl_netgraph_height; -extern struct cvar_s *cl_netgraph_alpha; -extern struct cvar_s *cl_netgraph_box; +extern int cl_netgraph; +extern int cl_netgraph_height; +extern float cl_netgraph_alpha; +extern int cl_netgraph_box; -extern struct cvar_s *cl_draw_locs; -extern struct cvar_s *cl_shownet; +extern int cl_draw_locs; +extern int cl_shownet; -extern struct cvar_s *cl_name; +extern char *cl_name; -extern struct cvar_s *cl_model_crcs; +extern int cl_model_crcs; -extern struct cvar_s *rate; +extern float rate; -extern struct cvar_s *hud_ping; -extern struct cvar_s *hud_pl; +extern int hud_ping; +extern int hud_pl; -extern struct cvar_s *skin; +extern char *skin; -extern struct cvar_s *cl_fb_players; +extern float cl_fb_players; -extern struct cvar_s *hud_scoreboard_uid; +extern int hud_scoreboard_uid; extern client_state_t cl; @@ -294,7 +294,8 @@ extern int fps_count; extern struct cbuf_s *cl_cbuf; extern struct cbuf_s *cl_stbuf; -void Cvar_Info (struct cvar_s *var); +struct cvar_s; +void Cvar_Info (void *data, const struct cvar_s *cvar); extern struct view_s *cl_netgraph_view; void CL_NetGraph (struct view_s *view); diff --git a/qw/include/game.h b/qw/include/game.h index 003855f4e..474b11c02 100644 --- a/qw/include/game.h +++ b/qw/include/game.h @@ -33,7 +33,7 @@ #include "QF/qtypes.h" #include "QF/qdefs.h" -extern struct cvar_s *registered; +extern char *registered; void Game_Init (void); void Game_Init_Cvars (void); diff --git a/qw/include/host.h b/qw/include/host.h index ccf759a26..ab0a18770 100644 --- a/qw/include/host.h +++ b/qw/include/host.h @@ -38,8 +38,8 @@ #define MAX_NUM_ARGVS 50 -extern struct cvar_s *sys_ticrate; -extern struct cvar_s *password; +extern float sys_ticrate; +extern char *password; extern double host_frametime; // Tonik diff --git a/qw/include/server.h b/qw/include/server.h index dfdc48f72..9d00ee13e 100644 --- a/qw/include/server.h +++ b/qw/include/server.h @@ -426,21 +426,22 @@ typedef enum { //============================================================================ // FIXME: declare exported variables in their own relevant .h -extern struct cvar_s *sv_hide_version_info; -extern struct cvar_s *sv_highchars; +extern int sv_hide_version_info; +extern int sv_highchars; -extern struct cvar_s *sv_mintic, *sv_maxtic; -extern struct cvar_s *sv_maxspeed; +extern float sv_mintic; +extern float sv_maxtic; +extern float sv_maxspeed; -extern struct cvar_s *sv_timeout; +extern float sv_timeout; extern netadr_t master_adr[MAX_MASTERS]; // address of the master server -extern struct cvar_s *spawn; -extern struct cvar_s *teamplay; -extern struct cvar_s *deathmatch; -extern struct cvar_s *fraglimit; -extern struct cvar_s *timelimit; +extern char *spawn; +extern int teamplay; +extern int deathmatch; +extern char *fraglimit; +extern int timelimit; extern server_static_t svs; // persistant server info extern server_t sv; // local server @@ -544,6 +545,7 @@ void SV_FlushSignon (void); // void SV_ProgStartFrame (void); void SV_Physics (void); +void SV_Physics_Init_Cvars (void); void SV_CheckVelocity (struct edict_s *ent); void SV_AddGravity (struct edict_s *ent); void SV_FinishGravity (struct edict_s *ent, vec3_t move); @@ -630,38 +632,39 @@ void SV_WriteEntitiesToClient (delta_t *delta, sizebuf_t *msg); // sv_nchan.c // -void Cvar_Info (struct cvar_s *var); +struct cvar_s; +void Cvar_Info (void *data, const struct cvar_s *cvar); -extern struct cvar_s *sv_antilag; -extern struct cvar_s *sv_antilag_frac; -extern struct cvar_s *sv_timecheck_fuzz; -extern struct cvar_s *sv_timecheck_decay; -extern struct cvar_s *sv_maxrate; -extern struct cvar_s *sv_timestamps; -extern struct cvar_s *sv_timefmt; -extern struct cvar_s *sv_phs; -extern struct cvar_s *sv_maxvelocity; -extern struct cvar_s *sv_gravity; -extern struct cvar_s *sv_jump_any; -extern struct cvar_s *sv_aim; -extern struct cvar_s *sv_stopspeed; -extern struct cvar_s *sv_spectatormaxspeed; -extern struct cvar_s *sv_accelerate; -extern struct cvar_s *sv_airaccelerate; -extern struct cvar_s *sv_wateraccelerate; -extern struct cvar_s *sv_friction; -extern struct cvar_s *sv_waterfriction; -extern struct cvar_s *pr_double_remove; -extern struct cvar_s *allow_download; -extern struct cvar_s *allow_download_skins; -extern struct cvar_s *allow_download_models; -extern struct cvar_s *allow_download_sounds; -extern struct cvar_s *allow_download_maps; +extern int sv_antilag; +extern float sv_antilag_frac; +extern int sv_timecheck_fuzz; +extern int sv_timecheck_decay; +extern int sv_maxrate; +extern int sv_timestamps; +extern char *sv_timefmt; +extern int sv_phs; +extern float sv_maxvelocity; +extern float sv_gravity; +extern int sv_jump_any; +extern float sv_aim; +extern float sv_stopspeed; +extern float sv_spectatormaxspeed; +extern float sv_accelerate; +extern float sv_airaccelerate; +extern float sv_wateraccelerate; +extern float sv_friction; +extern float sv_waterfriction; +extern int pr_double_remove; +extern int allow_download; +extern int allow_download_skins; +extern int allow_download_models; +extern int allow_download_sounds; +extern int allow_download_maps; extern int fp_messages; extern int fp_persecond; extern int fp_secondsdead; -extern struct cvar_s *pausable; +extern int pausable; extern qboolean nouse; extern char fp_msg[255]; diff --git a/qw/include/sv_demo.h b/qw/include/sv_demo.h index 463d63a49..900362915 100644 --- a/qw/include/sv_demo.h +++ b/qw/include/sv_demo.h @@ -22,9 +22,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define __sv_demo_h extern struct recorder_s demo; -extern struct cvar_s *sv_demofps; -extern struct cvar_s *sv_demoPings; -extern struct cvar_s *sv_demoMaxSize; +extern float sv_demofps; +extern float sv_demoPings; +extern char *sv_demoMaxSize; void SV_Stop (int reason); void Demo_Init (void); diff --git a/qw/source/cl_cam.c b/qw/source/cl_cam.c index e41e76a5f..b730011d8 100644 --- a/qw/source/cl_cam.c +++ b/qw/source/cl_cam.c @@ -66,10 +66,44 @@ #include "QF/mathlib.h" #include "world.h" -cvar_t *cl_hightrack; // track high fragger -cvar_t *cl_chasecam; -cvar_t *cl_camera_maxpitch; -cvar_t *cl_camera_maxyaw; +int cl_hightrack; +static cvar_t cl_hightrack_cvar = { + .name = "cl_hightrack", + .description = + "view the player who has the most frags while you are in spectator " + "mode.", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &cl_hightrack }, +}; +int cl_chasecam; +static cvar_t cl_chasecam_cvar = { + .name = "cl_chasecam", + .description = + "get first person view of the person you are tracking in spectator " + "mode", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &cl_chasecam }, +}; +float cl_camera_maxpitch; +static cvar_t cl_camera_maxpitch_cvar = { + .name = "cl_camera_maxpitch", + .description = + "highest camera pitch in spectator mode", + .default_value = "10", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &cl_camera_maxpitch }, +}; +float cl_camera_maxyaw; +static cvar_t cl_camera_maxyaw_cvar = { + .name = "cl_camera_maxyaw", + .description = + "highest camera yaw in spectator mode", + .default_value = "30", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &cl_camera_maxyaw }, +}; static vec3_t desired_position; // where the camera wants to be static qboolean locked = false; @@ -116,13 +150,13 @@ vectoangles (vec3_t vec, vec3_t ang) qboolean Cam_DrawViewModel (void) { - if (cl.viewstate.chase && chase_active->int_val) + if (cl.viewstate.chase && chase_active) return false; if (!cl.spectator) return true; - if (autocam && locked && cl_chasecam->int_val) + if (autocam && locked && cl_chasecam) return true; return false; } @@ -132,16 +166,16 @@ qboolean Cam_DrawPlayer (int playernum) { if (playernum == cl.playernum) { // client player - if (cl.viewstate.chase == 0 || chase_active->int_val == 0) + if (cl.viewstate.chase == 0 || chase_active == 0) return false; if (!cl.spectator) return true; } else { - if (!cl_chasecam->int_val) + if (!cl_chasecam) return true; if (cl.spectator && autocam && locked && spec_track == playernum) return false; - if (cl.viewstate.chase == 0 || chase_active->int_val == 0) + if (cl.viewstate.chase == 0 || chase_active == 0) return true; } return false; @@ -384,7 +418,7 @@ Cam_Track (usercmd_t *cmd) if (!cl.spectator) return; - if (cl_hightrack->int_val && !locked) + if (cl_hightrack && !locked) Cam_CheckHighTarget (); if (!autocam || cls.state != ca_active) @@ -394,7 +428,7 @@ Cam_Track (usercmd_t *cmd) && (!cl.players[spec_track].name->value[0] || cl.players[spec_track].spectator)) { locked = false; - if (cl_hightrack->int_val) + if (cl_hightrack) Cam_CheckHighTarget (); else Cam_Unlock (); @@ -435,7 +469,7 @@ Cam_Track (usercmd_t *cmd) if (!locked || !autocam) return; - if (cl_chasecam->int_val) { + if (cl_chasecam) { cmd->forwardmove = cmd->sidemove = cmd->upmove = 0; VectorCopy (player->viewangles, cl.viewstate.player_angles); @@ -530,10 +564,10 @@ Cam_SetView (void) cam_viewangles[PITCH] = adjustang (cam_viewangles[PITCH], vec2[PITCH], - cl_camera_maxpitch->value); + cl_camera_maxpitch); cam_viewangles[YAW] = adjustang (cam_viewangles[YAW], vec2[YAW], - cl_camera_maxyaw->value); + cl_camera_maxyaw); } VectorCopy (cam_viewangles, cl.viewstate.player_angles); VectorCopy (cl.viewstate.player_angles, cl.simangles); @@ -570,10 +604,10 @@ Cam_FinishMove (usercmd_t *cmd) cam_viewangles[PITCH] = adjustang (cam_viewangles[PITCH], vec2[PITCH], - cl_camera_maxpitch->value); + cl_camera_maxpitch); cam_viewangles[YAW] = adjustang (cam_viewangles[YAW], vec2[YAW], - cl_camera_maxyaw->value); + cl_camera_maxyaw); } VectorCopy (cam_viewangles, cl.viewstate.player_angles); } @@ -597,7 +631,7 @@ Cam_FinishMove (usercmd_t *cmd) return; } - if (autocam && cl_hightrack->int_val) { + if (autocam && cl_hightrack) { Cam_CheckHighTarget (); return; } @@ -651,14 +685,8 @@ Cam_Reset (void) void CL_Cam_Init_Cvars (void) { - cl_camera_maxpitch = Cvar_Get ("cl_camera_maxpitch", "10", CVAR_NONE, NULL, - "highest camera pitch in spectator mode"); - cl_camera_maxyaw = Cvar_Get ("cl_camera_maxyaw", "30", CVAR_NONE, NULL, - "highest camera yaw in spectator mode"); - cl_chasecam = Cvar_Get ("cl_chasecam", "0", CVAR_NONE, NULL, "get first " - "person view of the person you are tracking in " - "spectator mode"); - cl_hightrack = Cvar_Get ("cl_hightrack", "0", CVAR_NONE, NULL, "view the " - "player who has the most frags while you are in " - "spectator mode."); + Cvar_Register (&cl_camera_maxpitch_cvar, 0, 0); + Cvar_Register (&cl_camera_maxyaw_cvar, 0, 0); + Cvar_Register (&cl_chasecam_cvar, 0, 0); + Cvar_Register (&cl_hightrack_cvar, 0, 0); } diff --git a/qw/source/cl_cvar.c b/qw/source/cl_cvar.c index f9e116ae9..78d6290ec 100644 --- a/qw/source/cl_cvar.c +++ b/qw/source/cl_cvar.c @@ -44,17 +44,18 @@ #include "qw/include/client.h" void -Cvar_Info (cvar_t *var) +Cvar_Info (void *data, const cvar_t *cvar) { - if (var->flags & CVAR_USERINFO) { - Info_SetValueForKey (cls.userinfo, var->name, var->string, - ((!strequal(var->name, "name")) - |(strequal(var->name, "team") << 1))); + if (cvar->flags & CVAR_USERINFO) { + const char *cvar_str = Cvar_VarString (cvar); + Info_SetValueForKey (cls.userinfo, cvar->name, cvar_str, + ((!strequal(cvar->name, "name")) + |(strequal(cvar->name, "team") << 1))); if (cls.state >= ca_connected && !cls.demoplayback) { MSG_WriteByte (&cls.netchan.message, clc_stringcmd); MSG_WriteString (&cls.netchan.message, - va (0, "setinfo \"%s\" \"%s\"\n", var->name, - var->string)); + va (0, "setinfo \"%s\" \"%s\"\n", cvar->name, + cvar_str)); } } } diff --git a/qw/source/cl_demo.c b/qw/source/cl_demo.c index 91fd7ced3..c7ede77e3 100644 --- a/qw/source/cl_demo.c +++ b/qw/source/cl_demo.c @@ -91,10 +91,44 @@ static void CL_TimeFrames_DumpLog (void); static void CL_TimeFrames_AddTimestamp (void); static void CL_TimeFrames_Reset (void); -cvar_t *demo_gzip; -cvar_t *demo_speed; -cvar_t *demo_quit; -cvar_t *demo_timeframes; +int demo_gzip; +static cvar_t demo_gzip_cvar = { + .name = "demo_gzip", + .description = + "Compress demos using gzip. 0 = none, 1 = least compression, 9 = most " + "compression. Compressed demos (1-9) will have .gz appended to the " + "name", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &demo_gzip }, +}; +float demo_speed; +static cvar_t demo_speed_cvar = { + .name = "demo_speed", + .description = + "adjust demo playback speed. 1.0 = normal, < 1 slow-mo, > 1 timelapse", + .default_value = "1.0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &demo_speed }, +}; +int demo_quit; +static cvar_t demo_quit_cvar = { + .name = "demo_quit", + .description = + "automaticly quit after a timedemo has finished", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &demo_quit }, +}; +int demo_timeframes; +static cvar_t demo_timeframes_cvar = { + .name = "demo_timeframes", + .description = + "write timestamps for every frame", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &demo_timeframes }, +}; #define MAX_DEMMSG (MAX_MSGLEN + 8) //+8 for header @@ -422,7 +456,7 @@ CL_GetMessage (void) if (!CL_GetPacket ()) return 0; - if (net_packetlog->int_val) + if (net_packetlog) Log_Incoming_Packet (net_message->message->data, net_message->message->cursize, 1); @@ -879,9 +913,9 @@ CL_Record (const char *argv1, int track) // open the demo file #ifdef HAVE_ZLIB - if (demo_gzip->int_val) { + if (demo_gzip) { QFS_DefaultExtension (name, ".qwd.gz"); - cls.demofile = QFS_WOpen (name->str, demo_gzip->int_val); + cls.demofile = QFS_WOpen (name->str, demo_gzip); } else #endif { @@ -1091,7 +1125,7 @@ CL_StartTimeDemo (void) cls.td_lastframe = -1; // get a new message this frame CL_TimeFrames_Reset (); - if (demo_timeframes->int_val) + if (demo_timeframes) demo_timeframes_isactive = 1; } @@ -1150,7 +1184,7 @@ CL_FinishTimeDemo (void) Sys_Printf (" min/max fps: %.3f/%.3f\n", min, max); Sys_Printf ("std deviation: %.3f fps\n", sqrt (variance)); } - if (demo_quit->int_val) + if (demo_quit) Cbuf_InsertText (cl_cbuf, "quit\n"); } } @@ -1195,17 +1229,10 @@ CL_Demo_Init (void) demo_timeframes_index = 0; demo_timeframes_array = NULL; - demo_gzip = Cvar_Get ("demo_gzip", "0", CVAR_ARCHIVE, NULL, - "Compress demos using gzip. 0 = none, 1 = least " - "compression, 9 = most compression. Compressed " - " demos (1-9) will have .gz appended to the name"); - demo_speed = Cvar_Get ("demo_speed", "1.0", CVAR_NONE, NULL, - "adjust demo playback speed. 1.0 = normal, " - "< 1 slow-mo, > 1 timelapse"); - demo_quit = Cvar_Get ("demo_quit", "0", CVAR_NONE, NULL, - "automaticly quit after a timedemo has finished"); - demo_timeframes = Cvar_Get ("demo_timeframes", "0", CVAR_NONE, NULL, - "write timestamps for every frame"); + Cvar_Register (&demo_gzip_cvar, 0, 0); + Cvar_Register (&demo_speed_cvar, 0, 0); + Cvar_Register (&demo_quit_cvar, 0, 0); + Cvar_Register (&demo_timeframes_cvar, 0, 0); Cmd_AddCommand ("record", CL_Record_f, "Record a demo, if no filename " "argument is given\n" "the demo will be called Year-Month-Day-Hour-Minute-" diff --git a/qw/source/cl_entparse.c b/qw/source/cl_entparse.c index 80ec0112e..26486ae41 100644 --- a/qw/source/cl_entparse.c +++ b/qw/source/cl_entparse.c @@ -648,7 +648,7 @@ CL_SetSolidPlayers (int playernum) physent_t *pent; struct predicted_player *pplayer; - if (!cl_solid_players->int_val) + if (!cl_solid_players) return; pent = pmove.physents + pmove.numphysent; diff --git a/qw/source/cl_ents.c b/qw/source/cl_ents.c index 5e9bb0069..a4955c409 100644 --- a/qw/source/cl_ents.c +++ b/qw/source/cl_ents.c @@ -176,8 +176,8 @@ CL_LinkPacketEntities (void) // if set to invisible, skip if (!new->modelindex - || (cl_deadbodyfilter->int_val && is_dead_body (new)) - || (cl_gibfilter->int_val && is_gib (new))) { + || (cl_deadbodyfilter && is_dead_body (new)) + || (cl_gibfilter && is_gib (new))) { if (ent->visibility.efrag) { R_RemoveEfrags (ent); } @@ -219,7 +219,7 @@ CL_LinkPacketEntities (void) renderer->min_light = 0; renderer->fullbright = 0; if (new->modelindex == cl_playerindex) { - renderer->min_light = min (cl.fbskins, cl_fb_players->value); + renderer->min_light = min (cl.fbskins, cl_fb_players); if (renderer->min_light >= 1.0) { renderer->fullbright = 1; } @@ -230,7 +230,7 @@ CL_LinkPacketEntities (void) animation->pose1 = animation->pose2 = -1; CL_TransformEntity (ent, new->scale / 16, new->angles, new->origin); - if (i != cl.viewentity || chase_active->int_val) { + if (i != cl.viewentity || chase_active) { if (ent->visibility.efrag) { R_RemoveEfrags (ent); } @@ -260,7 +260,7 @@ CL_LinkPacketEntities (void) VectorMultAdd (old->angles, f, d, angles); CL_TransformEntity (ent, new->scale / 16.0, angles, origin); } - if (i != cl.viewentity || chase_active->int_val) { + if (i != cl.viewentity || chase_active) { if (ent->visibility.efrag) { vec4f_t org = Transform_GetWorldPosition (ent->transform); @@ -439,14 +439,14 @@ CL_LinkPlayers (void) continue; // Hack hack hack - if (cl_deadbodyfilter->int_val + if (cl_deadbodyfilter && state->pls.es.modelindex == cl_playerindex && is_dead_body (&state->pls.es)) continue; // predict only half the move to minimize overruns msec = 500 * (playertime - state->state_time); - if (msec <= 0 || (!cl_predict_players->int_val) || cls.demoplayback2) { + if (msec <= 0 || (!cl_predict_players) || cls.demoplayback2) { Sys_Printf("a\n"); exact.pls.es.origin = state->pls.es.origin; } else { // predict players movement @@ -488,7 +488,7 @@ CL_LinkPlayers (void) // use custom skin ent->renderer.skin = player->skin; - ent->renderer.min_light = min (cl.fbskins, cl_fb_players->value); + ent->renderer.min_light = min (cl.fbskins, cl_fb_players); if (ent->renderer.min_light >= 1.0) { ent->renderer.fullbright = 1; @@ -540,7 +540,7 @@ CL_EmitEntities (void) CL_LinkPlayers (); CL_LinkPacketEntities (); CL_UpdateTEnts (cl.time, &tentCtx); - if (cl_draw_locs->int_val) { + if (cl_draw_locs) { locs_draw (cl.time, cl.viewstate.player_origin); } } diff --git a/qw/source/cl_input.c b/qw/source/cl_input.c index 1a04d1579..d0c8fef58 100644 --- a/qw/source/cl_input.c +++ b/qw/source/cl_input.c @@ -63,9 +63,36 @@ #include "qw/include/client.h" #include "qw/include/host.h" -cvar_t *cl_nodelta; -cvar_t *cl_maxnetfps; -cvar_t *cl_spamimpulse; +int cl_nodelta; +static cvar_t cl_nodelta_cvar = { + .name = "cl_nodelta", + .description = + "Disable player delta compression. Set to 1 if you have a poor ISP and" + " get many U_REMOVE warnings.", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &cl_nodelta }, +}; +int cl_maxnetfps; +static cvar_t cl_maxnetfps_cvar = { + .name = "cl_maxnetfps", + .description = + "Controls number of command packets sent per second. Default 0 is " + "unlimited.", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &cl_maxnetfps }, +}; +int cl_spamimpulse; +static cvar_t cl_spamimpulse_cvar = { + .name = "cl_spamimpulse", + .description = + "Controls number of duplicate packets sent if an impulse is being " + "sent. Default (id behavior) is 3.", + .default_value = "3", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &cl_spamimpulse }, +}; int in_impulse; @@ -166,8 +193,8 @@ pps_check (int dontdrop) if (pps_balance > 0.0 || dropcount >= 2 || dontdrop) { float pps; - if (!(pps = cl_maxnetfps->int_val)) - pps = rate->value / 80.0; + if (!(pps = cl_maxnetfps)) + pps = rate / 80.0; pps = bound (1, pps, 72); @@ -250,21 +277,21 @@ CL_SendCmd (void) frame = (cls.netchan.outgoing_sequence - 2) & UPDATE_MASK; cmd = &cl.frames[frame].cmd; - if (cl_spamimpulse->int_val >= 2) + if (cl_spamimpulse >= 2) dontdrop = dontdrop || cmd->impulse; MSG_WriteDeltaUsercmd (&buf, &nullcmd, cmd); oldcmd = cmd; frame = (cls.netchan.outgoing_sequence - 1) & UPDATE_MASK; cmd = &cl.frames[frame].cmd; - if (cl_spamimpulse->int_val >= 3) + if (cl_spamimpulse >= 3) dontdrop = dontdrop || cmd->impulse; MSG_WriteDeltaUsercmd (&buf, oldcmd, cmd); oldcmd = cmd; frame = (cls.netchan.outgoing_sequence) & UPDATE_MASK; cmd = &cl.frames[frame].cmd; - if (cl_spamimpulse->int_val >= 1) + if (cl_spamimpulse >= 1) dontdrop = dontdrop || cmd->impulse; MSG_WriteDeltaUsercmd (&buf, oldcmd, cmd); @@ -277,7 +304,7 @@ CL_SendCmd (void) if (cls.netchan.outgoing_sequence - cl.validsequence >= UPDATE_BACKUP - 1) cl.validsequence = 0; - if (cl.validsequence && !cl_nodelta->int_val && cls.state == ca_active + if (cl.validsequence && !cl_nodelta && cls.state == ca_active && !cls.demorecording) { cl.frames[frame].delta_sequence = cl.validsequence; MSG_WriteByte (&buf, clc_delta); @@ -306,14 +333,7 @@ void CL_Init_Input_Cvars (void) { CL_Input_Init_Cvars (); - cl_nodelta = Cvar_Get ("cl_nodelta", "0", CVAR_NONE, NULL, - "Disable player delta compression. Set to 1 if you " - "have a poor ISP and get many U_REMOVE warnings."); - cl_maxnetfps = Cvar_Get ("cl_maxnetfps", "0", CVAR_ARCHIVE, NULL, - "Controls number of command packets sent per " - "second. Default 0 is unlimited."); - cl_spamimpulse = Cvar_Get ("cl_spamimpulse", "3", CVAR_NONE, NULL, - "Controls number of duplicate packets sent if " - "an impulse is being sent. Default (id " - "behavior) is 3."); + Cvar_Register (&cl_nodelta_cvar, 0, 0); + Cvar_Register (&cl_maxnetfps_cvar, 0, 0); + Cvar_Register (&cl_spamimpulse_cvar, 0, 0); } diff --git a/qw/source/cl_main.c b/qw/source/cl_main.c index 7b4179907..73bf69394 100644 --- a/qw/source/cl_main.c +++ b/qw/source/cl_main.c @@ -134,54 +134,285 @@ qboolean noclip_anglehack; // remnant from old quake cbuf_t *cl_cbuf; cbuf_t *cl_stbuf; -cvar_t *cl_mem_size; +float cl_mem_size; +static cvar_t cl_mem_size_cvar = { + .name = "cl_mem_size", + .description = + "Amount of memory (in MB) to allocate for the " + PACKAGE_NAME + " heap", + .default_value = "32", + .flags = CVAR_ROM, + .value = { .type = &cexpr_float, .value = &cl_mem_size }, +}; -cvar_t *rcon_password; +char *rcon_password; +static cvar_t rcon_password_cvar = { + .name = "rcon_password", + .description = + "Set the password for rcon 'root' commands", + .default_value = "", + .flags = CVAR_NONE, + .value = { .type = 0, .value = &rcon_password }, +}; -cvar_t *rcon_address; +char *rcon_address; +static cvar_t rcon_address_cvar = { + .name = "rcon_address", + .description = + "server IP address when client not connected - for sending rcon " + "commands", + .default_value = "", + .flags = CVAR_NONE, + .value = { .type = 0, .value = &rcon_address }, +}; -cvar_t *cl_writecfg; -cvar_t *cl_allow_cmd_pkt; -cvar_t *cl_cmd_pkt_adr; -cvar_t *cl_paranoid; +int cl_writecfg; +static cvar_t cl_writecfg_cvar = { + .name = "cl_writecfg", + .description = + "write config files?", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &cl_writecfg }, +}; +int cl_allow_cmd_pkt; +static cvar_t cl_allow_cmd_pkt_cvar = { + .name = "cl_allow_cmd_pkt", + .description = + "enables packets from the likes of gamespy", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &cl_allow_cmd_pkt }, +}; +char *cl_cmd_pkt_adr; +static cvar_t cl_cmd_pkt_adr_cvar = { + .name = "cl_cmd_pkt_adr", + .description = + "allowed address for non-local command packet", + .default_value = "", + .flags = CVAR_NONE, + .value = { .type = 0, .value = &cl_cmd_pkt_adr }, +}; +int cl_paranoid; +static cvar_t cl_paranoid_cvar = { + .name = "cl_paranoid", + .description = + "print source address of connectionless packets even when coming from " + "the server being connected to.", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &cl_paranoid }, +}; -cvar_t *cl_timeout; +float cl_timeout; +static cvar_t cl_timeout_cvar = { + .name = "cl_timeout", + .description = + "server connection timeout (since last packet received)", + .default_value = "60", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &cl_timeout }, +}; -cvar_t *cl_draw_locs; -cvar_t *cl_shownet; -cvar_t *cl_autoexec; -cvar_t *cl_quakerc; -cvar_t *cl_maxfps; -cvar_t *cl_usleep; +int cl_draw_locs; +static cvar_t cl_draw_locs_cvar = { + .name = "cl_draw_locs", + .description = + "Draw location markers.", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &cl_draw_locs }, +}; +int cl_shownet; +static cvar_t cl_shownet_cvar = { + .name = "cl_shownet", + .description = + "show network packets. 0=off, 1=basic, 2=verbose", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &cl_shownet }, +}; +int cl_autoexec; +static cvar_t cl_autoexec_cvar = { + .name = "cl_autoexec", + .description = + "exec autoexec.cfg on gamedir change", + .default_value = "0", + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &cl_autoexec }, +}; +int cl_quakerc; +static cvar_t cl_quakerc_cvar = { + .name = "cl_quakerc", + .description = + "exec quake.rc on startup", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &cl_quakerc }, +}; +float cl_maxfps; +static cvar_t cl_maxfps_cvar = { + .name = "cl_maxfps", + .description = + "maximum frames rendered in one second. 0 == 72", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &cl_maxfps }, +}; +int cl_usleep; +static cvar_t cl_usleep_cvar = { + .name = "cl_usleep", + .description = + "Turn this on to save cpu when fps limited. May affect frame rate " + "adversely depending on local machine/os conditions", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &cl_usleep }, +}; -cvar_t *cl_model_crcs; +int cl_model_crcs; +static cvar_t cl_model_crcs_cvar = { + .name = "cl_model_crcs", + .description = + "Controls setting of emodel and pmodel info vars. Required by some " + "servers, but clearing this can make the difference between connecting" + " and not connecting on some others.", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &cl_model_crcs }, +}; -cvar_t *cl_predict_players; -cvar_t *cl_solid_players; +int cl_predict_players; +static cvar_t cl_predict_players_cvar = { + .name = "cl_predict_players", + .description = + "If this is 0, no player prediction is done", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &cl_predict_players }, +}; +int cl_solid_players; +static cvar_t cl_solid_players_cvar = { + .name = "cl_solid_players", + .description = + "Are players solid? If off, you can walk through them with difficulty", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &cl_solid_players }, +}; -cvar_t *localid; +char *localid; +static cvar_t localid_cvar = { + .name = "localid", + .description = + "Used by gamespy+others to authenticate when sending commands to the " + "client", + .default_value = "", + .flags = CVAR_NONE, + .value = { .type = 0, .value = &localid }, +}; -cvar_t *cl_port; -cvar_t *cl_autorecord; +int cl_port; +static cvar_t cl_port_cvar = { + .name = "cl_port", + .description = + "UDP Port for client to use.", + .default_value = PORT_CLIENT, + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &cl_port }, +}; +int cl_autorecord; +static cvar_t cl_autorecord_cvar = { + .name = "cl_autorecord", + .description = + "Turn this on, if you want to record every game", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &cl_autorecord }, +}; -cvar_t *cl_fb_players; +float cl_fb_players; +static cvar_t cl_fb_players_cvar = { + .name = "cl_fb_players", + .description = + "fullbrightness of player models. server must allow (via fbskins " + "serverinfo).", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &cl_fb_players }, +}; static qboolean allowremotecmd = true; /* info mirrors */ -cvar_t *password; -cvar_t *spectator; -cvar_t *cl_name; -cvar_t *team; -cvar_t *rate; -cvar_t *noaim; -cvar_t *msg; +char *password; +static cvar_t password_cvar = { + .name = "password", + .description = + "Set the server password for players", + .default_value = "", + .flags = CVAR_NONE, + .value = { .type = 0, .value = &password }, +}; +char *spectator; +static cvar_t spectator_cvar = { + .name = "spectator", + .description = + "Set to 1 before connecting to become a spectator", + .default_value = "", + .flags = CVAR_USERINFO, + .value = { .type = 0/* not used */, .value = &spectator }, +}; +char *cl_name; +static cvar_t cl_name_cvar = { + .name = "_cl_name", + .description = + "Player name", + .default_value = "player", + .flags = CVAR_ARCHIVE, + .value = { .type = 0, .value = &cl_name }, +}; +float team; +static cvar_t team_cvar = { + .name = "team", + .description = + "Team player is on.", + .default_value = "", + .flags = CVAR_ARCHIVE | CVAR_USERINFO, + .value = { .type = &cexpr_float, .value = &team }, +}; +float rate; +static cvar_t rate_cvar = { + .name = "rate", + .description = + "Amount of bytes per second server will send/download to you", + .default_value = "10000", + .flags = CVAR_ARCHIVE | CVAR_USERINFO, + .value = { .type = &cexpr_float, .value = &rate }, +}; +char *noaim; +static cvar_t noaim_cvar = { + .name = "noaim", + .description = + "Auto aim off switch. Set to 1 to turn off.", + .default_value = "0", + .flags = CVAR_ARCHIVE | CVAR_USERINFO, + .value = { .type = 0/* not used */, .value = &noaim }, +}; +char *msg; +static cvar_t msg_cvar = { + .name = "msg", + .description = + "Determines the type of messages reported 0 is maximum, 4 is none", + .default_value = "1", + .flags = CVAR_ARCHIVE | CVAR_USERINFO, + .value = { .type = 0/* not used */, .value = &msg }, +}; /* GIB events */ gib_event_t *cl_player_health_e, *cl_chat_e; -static int cl_usleep_cache; - client_static_t cls; client_state_t cl; @@ -204,11 +435,51 @@ double oldcon_realtime; size_t host_hunklevel; -cvar_t *host_speeds; -cvar_t *hud_fps; -cvar_t *hud_ping; -cvar_t *hud_pl; -cvar_t *hud_time; +int host_speeds; +static cvar_t host_speeds_cvar = { + .name = "host_speeds", + .description = + "set for running times", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &host_speeds }, +}; +int hud_fps; +static cvar_t hud_fps_cvar = { + .name = "hud_fps", + .description = + "display realtime frames per second", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &hud_fps }, +}; +int hud_ping; +static cvar_t hud_ping_cvar = { + .name = "hud_ping", + .description = + "display current ping to server", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &hud_ping }, +}; +int hud_pl; +static cvar_t hud_pl_cvar = { + .name = "hud_pl", + .description = + "display current packet loss to server", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &hud_pl }, +}; +int hud_time; +static cvar_t hud_time_cvar = { + .name = "hud_time", + .description = + "display the current time", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &hud_time }, +}; int fps_count; @@ -272,7 +543,7 @@ CL_SendConnectPacket (void) connect_time = realtime + t2 - t1; // for retransmit requests - cls.qport = qport->int_val; + cls.qport = qport; data = dstring_new (); dsprintf (data, "%c%c%c%cconnect %i %i %i \"%s\"\n", @@ -360,18 +631,18 @@ CL_Rcon_f (void) if (!message) message = dstring_new (); - dsprintf (message, "\377\377\377\377rcon %s %s", rcon_password->string, + dsprintf (message, "\377\377\377\377rcon %s %s", rcon_password, Cmd_Args (1)); if (cls.state >= ca_connected) to = cls.netchan.remote_address; else { - if (!rcon_address->string[0]) { + if (!rcon_address[0]) { Sys_Printf ("You must either be connected, or set the " "'rcon_address' cvar to issue rcon commands\n"); return; } - NET_StringToAdr (rcon_address->string, &to); + NET_StringToAdr (rcon_address, &to); if (to.port == 0) to.port = BigShort (27500); } @@ -639,7 +910,7 @@ CL_FullServerinfo_f (void) } if ((p = Info_ValueForKey (cl.serverinfo, "teamplay")) && *p) { cl.teamplay = atoi (p); - Sbar_DMO_Init_f (hud_scoreboard_uid); // HUD setup, cl.teamplay changed + Sbar_DMO_Init_f (0, 0); // HUD setup, cl.teamplay changed } if ((p = Info_ValueForKey (cl.serverinfo, "watervis")) && *p) { cl.watervis = atoi (p); @@ -867,7 +1138,7 @@ CL_ConnectionlessPacket (void) if (net_message->badread) return; if (!cls.demoplayback - && (cl_paranoid->int_val + && (cl_paranoid || !NET_CompareAdr (net_from, cls.server_addr))) Sys_Printf ("%s: ", NET_AdrToString (net_from)); if (c == S2C_CONNECTION) { @@ -893,16 +1164,16 @@ CL_ConnectionlessPacket (void) Sys_Printf ("client command\n"); - if (!cl_allow_cmd_pkt->int_val + if (!cl_allow_cmd_pkt || (!NET_CompareBaseAdr (net_from, net_local_adr) && !NET_CompareBaseAdr (net_from, net_loopback_adr) - && (!cl_cmd_pkt_adr->string[0] + && (!cl_cmd_pkt_adr[0] || !NET_CompareBaseAdr (net_from, cl_cmd_packet_address)))) { Sys_Printf ("Command packet from remote host. Ignored.\n"); return; } - if (cl_cmd_pkt_adr->string[0] + if (cl_cmd_pkt_adr[0] && NET_CompareBaseAdr (net_from, cl_cmd_packet_address)) allowremotecmd = false; // force password checking s = MSG_ReadString (net_message); @@ -918,10 +1189,10 @@ CL_ConnectionlessPacket (void) while (len && isspace ((byte) s[len - 1])) len--; - if (!allowremotecmd && (!*localid->string || - (int) strlen (localid->string) > len || - strncmp (localid->string, s, len))) { - if (!*localid->string) { + if (!allowremotecmd && (!*localid || + (int) strlen (localid) > len || + strncmp (localid, s, len))) { + if (!*localid) { Sys_Printf ("===========================\n"); Sys_Printf ("Command packet received from local host, but no " "localid has been set. You may need to upgrade " @@ -934,9 +1205,9 @@ CL_ConnectionlessPacket (void) ("Invalid localid on command packet received from local host. " "\n|%s| != |%s|\n" "You may need to reload your server browser and %s.\n", s, - localid->string, PACKAGE_NAME); + localid, PACKAGE_NAME); Sys_Printf ("===========================\n"); - Cvar_Set (localid, ""); + Cvar_Set ("localid", ""); return; } @@ -953,7 +1224,7 @@ CL_ConnectionlessPacket (void) Sys_Printf ("status response\n"); return; } else if (!cls.demoplayback - && (cl_paranoid->int_val + && (cl_paranoid || !NET_CompareAdr (net_from, cls.server_addr))) { Sys_Printf ("print\n"); } @@ -1028,7 +1299,7 @@ CL_ReadPackets (void) continue; } - if (cls.demoplayback && net_packetlog->int_val) + if (cls.demoplayback && net_packetlog) Log_Incoming_Packet (net_message->message->data, net_message->message->cursize, 0); @@ -1068,7 +1339,7 @@ CL_ReadPackets (void) // check timeout if (!cls.demoplayback && cls.state >= ca_connected - && realtime - cls.netchan.last_received > cl_timeout->value) { + && realtime - cls.netchan.last_received > cl_timeout) { Sys_Printf ("\nServer connection timed out.\n"); CL_Disconnect (); return; @@ -1160,7 +1431,7 @@ CL_SetState (cactive_t state) CL_ClearState (); // Auto demo recorder stops here - if (cl_autorecord->int_val && cls.demorecording) + if (cl_autorecord && cls.demorecording) CL_StopRecording (); r_funcs->R_ClearState (); @@ -1170,7 +1441,7 @@ CL_SetState (cactive_t state) IN_ClearStates (); // Auto demo recorder starts here - if (cl_autorecord->int_val && !cls.demoplayback + if (cl_autorecord && !cls.demoplayback && !cls.demorecording) CL_Record (0, -1); } @@ -1304,33 +1575,27 @@ CL_Init (void) } static void -cl_usleep_f (cvar_t *var) +cl_cmd_pkt_adr_f (void *data, const cvar_t *cvar) { - cl_usleep_cache = var->int_val; -} - -static void -cl_cmd_pkt_adr_f (cvar_t *var) -{ - if (var->string[0]) - NET_StringToAdr (var->string, &cl_cmd_packet_address); + if (cl_cmd_pkt_adr[0]) + NET_StringToAdr (cl_cmd_pkt_adr, &cl_cmd_packet_address); else memset (&cl_cmd_packet_address, 0, sizeof (cl_cmd_packet_address)); } static void -cl_pitchspeed_f (cvar_t *var) +cl_pitchspeed_f (void *data, const cvar_t *var) { - if ((cl.fpd & FPD_LIMIT_PITCH) && var->value > FPD_MAXPITCH) { - var->value = FPD_MAXPITCH; + if ((cl.fpd & FPD_LIMIT_PITCH) && cl_pitchspeed > FPD_MAXPITCH) { + cl_pitchspeed = FPD_MAXPITCH; } } static void -cl_yawspeed_f (cvar_t *var) +cl_yawspeed_f (void *data, const cvar_t *var) { - if ((cl.fpd & FPD_LIMIT_YAW) && var->value > FPD_MAXYAW) { - var->value = FPD_MAXYAW; + if ((cl.fpd & FPD_LIMIT_YAW) && cl_yawspeed > FPD_MAXYAW) { + cl_yawspeed = FPD_MAXYAW; } } @@ -1353,91 +1618,48 @@ CL_Init_Cvars (void) Chase_Init_Cvars (); V_Init_Cvars (); - cl_pitchspeed->callback = cl_pitchspeed_f; - cl_yawspeed->callback = cl_yawspeed_f; + cvar_t *var; + var = Cvar_FindVar ("cl_pitchspeed"); + Cvar_AddListener (var, cl_pitchspeed_f, 0); + var = Cvar_FindVar ("cl_yawspeed"); + Cvar_AddListener (var, cl_yawspeed_f, 0); cls.userinfo = Info_ParseString ("", MAX_INFO_STRING, 0); - cl_model_crcs = Cvar_Get ("cl_model_crcs", "1", CVAR_ARCHIVE, NULL, - "Controls setting of emodel and pmodel info " - "vars. Required by some servers, but clearing " - "this can make the difference between " - "connecting and not connecting on some others."); - cl_allow_cmd_pkt = Cvar_Get ("cl_allow_cmd_pkt", "1", CVAR_NONE, NULL, - "enables packets from the likes of gamespy"); - cl_cmd_pkt_adr = Cvar_Get ("cl_cmd_pkt_adr", "", CVAR_NONE, - cl_cmd_pkt_adr_f, - "allowed address for non-local command packet"); - cl_paranoid = Cvar_Get ("cl_paranoid", "1", CVAR_NONE, NULL, - "print source address of connectionless packets" - " even when coming from the server being connected" - " to."); - cl_autoexec = Cvar_Get ("cl_autoexec", "0", CVAR_ROM, NULL, - "exec autoexec.cfg on gamedir change"); - cl_quakerc = Cvar_Get ("cl_quakerc", "1", CVAR_NONE, NULL, - "exec quake.rc on startup"); - cl_fb_players = Cvar_Get ("cl_fb_players", "0", CVAR_ARCHIVE, NULL, "fullbrightness of player models. " - "server must allow (via fbskins serverinfo)."); - cl_writecfg = Cvar_Get ("cl_writecfg", "1", CVAR_NONE, NULL, - "write config files?"); - cl_draw_locs = Cvar_Get ("cl_draw_locs", "0", CVAR_NONE, NULL, - "Draw location markers."); - cl_shownet = Cvar_Get ("cl_shownet", "0", CVAR_NONE, NULL, - "show network packets. 0=off, 1=basic, 2=verbose"); - cl_maxfps = Cvar_Get ("cl_maxfps", "0", CVAR_ARCHIVE, NULL, - "maximum frames rendered in one second. 0 == 72"); - cl_timeout = Cvar_Get ("cl_timeout", "60", CVAR_ARCHIVE, NULL, "server " - "connection timeout (since last packet received)"); - host_speeds = Cvar_Get ("host_speeds", "0", CVAR_NONE, NULL, - "display host processing times"); - rcon_password = Cvar_Get ("rcon_password", "", CVAR_NONE, NULL, - "remote control password"); - rcon_address = Cvar_Get ("rcon_address", "", CVAR_NONE, NULL, "server IP " - "address when client not connected - for " - "sending rcon commands"); - hud_fps = Cvar_Get ("hud_fps", "0", CVAR_ARCHIVE, NULL, - "display realtime frames per second"); - Cvar_MakeAlias ("show_fps", hud_fps); - hud_ping = Cvar_Get ("hud_ping", "0", CVAR_ARCHIVE, NULL, - "display current ping to server"); - hud_pl = Cvar_Get ("hud_pl", "0", CVAR_ARCHIVE, NULL, - "display current packet loss to server"); - hud_time = Cvar_Get ("hud_time", "0", CVAR_ARCHIVE, NULL, - "Display the current time, 1 24hr, 2 AM/PM"); - cl_predict_players = Cvar_Get ("cl_predict_players", "1", CVAR_NONE, NULL, - "If this is 0, no player prediction is " - "done"); - cl_solid_players = Cvar_Get ("cl_solid_players", "1", CVAR_NONE, NULL, - "Are players solid? If off, you can walk " - "through them with difficulty"); - localid = Cvar_Get ("localid", "", CVAR_NONE, NULL, "Used by " - "gamespy+others to authenticate when sending " - "commands to the client"); + Cvar_Register (&cl_model_crcs_cvar, 0, 0); + Cvar_Register (&cl_allow_cmd_pkt_cvar, 0, 0); + Cvar_Register (&cl_cmd_pkt_adr_cvar, cl_cmd_pkt_adr_f, 0); + Cvar_Register (&cl_paranoid_cvar, 0, 0); + Cvar_Register (&cl_autoexec_cvar, 0, 0); + Cvar_Register (&cl_quakerc_cvar, 0, 0); + Cvar_Register (&cl_fb_players_cvar, 0, 0); + Cvar_Register (&cl_writecfg_cvar, 0, 0); + Cvar_Register (&cl_draw_locs_cvar, 0, 0); + Cvar_Register (&cl_shownet_cvar, 0, 0); + Cvar_Register (&cl_maxfps_cvar, 0, 0); + Cvar_Register (&cl_timeout_cvar, 0, 0); + Cvar_Register (&host_speeds_cvar, 0, 0); + Cvar_Register (&rcon_password_cvar, 0, 0); + Cvar_Register (&rcon_address_cvar, 0, 0); + Cvar_Register (&hud_fps_cvar, 0, 0); + Cvar_MakeAlias ("show_fps", &hud_fps_cvar); + Cvar_Register (&hud_ping_cvar, 0, 0); + Cvar_Register (&hud_pl_cvar, 0, 0); + Cvar_Register (&hud_time_cvar, 0, 0); + Cvar_Register (&cl_predict_players_cvar, 0, 0); + Cvar_Register (&cl_solid_players_cvar, 0, 0); + Cvar_Register (&localid_cvar, 0, 0); // info mirrors - cl_name = Cvar_Get ("name", "unnamed", CVAR_ARCHIVE | CVAR_USERINFO, - Cvar_Info, "Player name"); - password = Cvar_Get ("password", "", CVAR_USERINFO, Cvar_Info, - "Server password"); - spectator = Cvar_Get ("spectator", "", CVAR_USERINFO, Cvar_Info, - "Set to 1 before connecting to become a spectator"); - team = Cvar_Get ("team", "", CVAR_ARCHIVE | CVAR_USERINFO, Cvar_Info, - "Team player is on."); - rate = Cvar_Get ("rate", "10000", CVAR_ARCHIVE | CVAR_USERINFO, Cvar_Info, - "Amount of bytes per second server will send/download " - "to you"); - msg = Cvar_Get ("msg", "1", CVAR_ARCHIVE | CVAR_USERINFO, Cvar_Info, - "Determines the type of messages reported 0 is maximum, " - "4 is none"); - noaim = Cvar_Get ("noaim", "0", CVAR_ARCHIVE | CVAR_USERINFO, Cvar_Info, - "Auto aim off switch. Set to 1 to turn off."); - cl_port = Cvar_Get ("cl_port", PORT_CLIENT, CVAR_NONE, Cvar_Info, - "UDP Port for client to use."); - cl_usleep = Cvar_Get ("cl_usleep", "1", CVAR_ARCHIVE, cl_usleep_f, - "Turn this on to save cpu when fps limited. " - "May affect frame rate adversely depending on " - "local machine/os conditions"); - cl_autorecord = Cvar_Get ("cl_autorecord", "0", CVAR_ARCHIVE, NULL, "Turn " - "this on, if you want to record every game"); + Cvar_Register (&cl_name_cvar, 0, 0); + Cvar_Register (&password_cvar, 0, 0); + Cvar_Register (&spectator_cvar, Cvar_Info, &spectator); + Cvar_Register (&team_cvar, Cvar_Info, &team); + Cvar_Register (&rate_cvar, Cvar_Info, &rate); + Cvar_Register (&msg_cvar, Cvar_Info, &msg); + Cvar_Register (&noaim_cvar, Cvar_Info, &noaim); + Cvar_Register (&cl_port_cvar, Cvar_Info, &cl_port); + Cvar_Register (&cl_usleep_cvar, 0, 0); + Cvar_Register (&cl_autorecord_cvar, 0, 0); } /* @@ -1507,7 +1729,7 @@ Host_Error (const char *error, ...) void Host_WriteConfiguration (void) { - if (host_initialized && cl_writecfg->int_val) { + if (host_initialized && cl_writecfg) { plitem_t *config = PL_NewDictionary (0); //FIXME hashlinks Cvar_SaveConfig (config); IN_SaveConfig (config); @@ -1561,14 +1783,14 @@ Host_ExecConfig (cbuf_t *cbuf, int skip_quakerc) // should be used to set up defaults on the assumption that the user has // things set up to work with another (hopefully compatible) client if (Host_ReadConfiguration ("quakeforge.cfg")) { - Cmd_Exec_File (cbuf, fs_usercfg->string, 0); + Cmd_Exec_File (cbuf, fs_usercfg, 0); Cmd_StuffCmds (cbuf); COM_Check_quakerc ("startdemos", cbuf); } else { if (!skip_quakerc) { Cbuf_InsertText (cbuf, "exec quake.rc\n"); } - Cmd_Exec_File (cbuf, fs_usercfg->string, 0); + Cmd_Exec_File (cbuf, fs_usercfg, 0); // Reparse the command line for + commands. // (sets still done, but it doesn't matter) // (Note, no non-base commands exist yet) @@ -1593,7 +1815,7 @@ Host_SimulationTime (float time) con_realtime += time; if (cls.demoplayback) { - timescale = max (0, demo_speed->value); + timescale = max (0, demo_speed); time *= timescale; } @@ -1604,10 +1826,10 @@ Host_SimulationTime (float time) if (cls.demoplayback) return 0; - if (cl_maxfps->value <= 0) + if (cl_maxfps <= 0) fps = 72; else - fps = min (cl_maxfps->value, 72); + fps = min (cl_maxfps, 72); timedifference = (timescale / fps) - (realtime - oldrealtime); @@ -1655,7 +1877,7 @@ Host_Frame (float time) // decide the simulation time if ((sleeptime = Host_SimulationTime (time)) != 0) { #ifdef HAVE_USLEEP - if (cl_usleep_cache && sleeptime > 0.002) // minimum sleep time + if (cl_usleep && sleeptime > 0.002) // minimum sleep time usleep ((unsigned long) (sleeptime * 1000000 / 2)); #endif return; // framerate is too high @@ -1716,14 +1938,14 @@ Host_Frame (float time) CL_PredictMove (); // Set up prediction for other players - CL_SetUpPlayerPrediction (cl_predict_players->int_val); + CL_SetUpPlayerPrediction (cl_predict_players); // build a refresh entity list CL_EmitEntities (); } // update video - if (host_speeds->int_val) + if (host_speeds) time1 = Sys_DoubleTime (); r_data->inhibit_viewmodel = (!Cam_DrawViewModel () @@ -1733,7 +1955,7 @@ Host_Frame (float time) CL_UpdateScreen (realtime); - if (host_speeds->int_val) + if (host_speeds) time2 = Sys_DoubleTime (); // update audio @@ -1753,7 +1975,7 @@ Host_Frame (float time) CDAudio_Update (); - if (host_speeds->int_val) { + if (host_speeds) { pass1 = (time1 - time3) * 1000; time3 = Sys_DoubleTime (); pass2 = (time2 - time1) * 1000; @@ -1777,18 +1999,15 @@ CL_Init_Memory (void) size_t mem_size; void *mem_base; - cl_mem_size = Cvar_Get ("cl_mem_size", "32", CVAR_NONE, NULL, - "Amount of memory (in MB) to allocate for the " - PACKAGE_NAME " heap"); + Cvar_Register (&cl_mem_size_cvar, 0, 0); if (mem_parm) - Cvar_Set (cl_mem_size, com_argv[mem_parm + 1]); + Cvar_Set ("cl_mem_size", com_argv[mem_parm + 1]); if (COM_CheckParm ("-minmemory")) - Cvar_SetValue (cl_mem_size, MINIMUM_MEMORY / (1024 * 1024.0)); + cl_mem_size = MINIMUM_MEMORY / (1024 * 1024.0); - Cvar_SetFlags (cl_mem_size, cl_mem_size->flags | CVAR_ROM); - mem_size = ((size_t) cl_mem_size->value * 1024 * 1024); + mem_size = ((size_t) cl_mem_size * 1024 * 1024); if (mem_size < MINIMUM_MEMORY) Sys_Error ("Only %4.1f megs of memory reported, can't execute game", @@ -1802,7 +2021,7 @@ CL_Init_Memory (void) Sys_PageIn (mem_base, mem_size); memhunk_t *hunk = Memory_Init (mem_base, mem_size); - Sys_Printf ("%4.1f megabyte heap.\n", cl_mem_size->value); + Sys_Printf ("%4.1f megabyte heap.\n", cl_mem_size); return hunk; } @@ -1812,7 +2031,7 @@ CL_Autoexec (int phase) if (!phase) return; if (!Host_ReadConfiguration ("quakeforge.cfg")) { - int cmd_warncmd_val = cmd_warncmd->int_val; + int cmd_warncmd_val = cmd_warncmd; Cbuf_AddText (cl_cbuf, "cmd_warncmd 0\n"); Cbuf_AddText (cl_cbuf, "exec config.cfg\n"); @@ -1821,7 +2040,7 @@ CL_Autoexec (int phase) Cbuf_AddText (cl_cbuf, va (0, "cmd_warncmd %d\n", cmd_warncmd_val)); } - if (cl_autoexec->int_val) { + if (cl_autoexec) { Cbuf_AddText (cl_cbuf, "exec autoexec.cfg\n"); } } @@ -1856,7 +2075,7 @@ Host_Init (void) CL_Cmd_Init (); Game_Init (); - NET_Init (cl_port->int_val); + NET_Init (cl_port); Netchan_Init (); net_realtime = &realtime; { @@ -1876,7 +2095,7 @@ Host_Init (void) CL_UpdateScreen (realtime); CL_UpdateScreen (realtime); - Host_ExecConfig (cl_cbuf, !cl_quakerc->int_val); + Host_ExecConfig (cl_cbuf, !cl_quakerc); // make sure all + commands have been executed Cbuf_Execute_Stack (cl_cbuf); diff --git a/qw/source/cl_ngraph.c b/qw/source/cl_ngraph.c index 1d31f20da..fb60fe0c8 100644 --- a/qw/source/cl_ngraph.c +++ b/qw/source/cl_ngraph.c @@ -48,29 +48,59 @@ #include "qw/include/client.h" #include "sbar.h" -cvar_t *cl_netgraph; -cvar_t *cl_netgraph_alpha; -cvar_t *cl_netgraph_box; -cvar_t *cl_netgraph_height; +int cl_netgraph; +static cvar_t cl_netgraph_cvar = { + .name = "cl_netgraph", + .description = + "Toggle the display of a graph showing network performance", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &cl_netgraph }, +}; +float cl_netgraph_alpha; +static cvar_t cl_netgraph_alpha_cvar = { + .name = "cl_netgraph_alpha", + .description = + "Net graph translucency", + .default_value = "0.5", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_float, .value = &cl_netgraph_alpha }, +}; +int cl_netgraph_box; +static cvar_t cl_netgraph_box_cvar = { + .name = "cl_netgraph_box", + .description = + " Draw box around net graph", + .default_value = "1", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &cl_netgraph_box }, +}; +int cl_netgraph_height; +static cvar_t cl_netgraph_height_cvar = { + .name = "cl_netgraph_height", + .description = + "Set the fullscale (1s) height of the graph", + .default_value = "32", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &cl_netgraph_height }, +}; view_t *cl_netgraph_view; static void -cl_netgraph_f (cvar_t *var) +cl_netgraph_f (void *data, const cvar_t *cvar) { if (cl_netgraph_view) { - cl_netgraph_view->visible = var->int_val != 0; + cl_netgraph_view->visible = cl_netgraph != 0; } } static void -cl_netgraph_height_f (cvar_t *var) +cl_netgraph_height_f (void *data, const cvar_t *cvar) { - if (var->int_val < 32) { - Cvar_Set (var, "32"); - } + cl_netgraph_height = max (32, cl_netgraph_height); if (cl_netgraph_view) { view_resize (cl_netgraph_view, cl_netgraph_view->xlen, - var->int_val + 25); + cl_netgraph_height + 25); } } @@ -83,10 +113,10 @@ CL_NetGraph (view_t *view) x = view->xabs; y = view->yabs; - if (cl_netgraph_box->int_val) { + if (cl_netgraph_box) { r_funcs->Draw_TextBox (x, y, NET_TIMINGS / 8, - cl_netgraph_height->int_val / 8 + 1, - cl_netgraph_alpha->value * 255); + cl_netgraph_height / 8 + 1, + cl_netgraph_alpha * 255); } lost = CL_CalcNet (); @@ -108,7 +138,7 @@ CL_NetGraph (view_t *view) } memcpy (timings + o, packet_latency + a, l * sizeof (timings[0])); r_funcs->R_LineGraph (x, y, timings, - NET_TIMINGS, cl_netgraph_height->int_val); + NET_TIMINGS, cl_netgraph_height); x = view->xabs + 8; y = view->yabs + 8; @@ -118,15 +148,8 @@ CL_NetGraph (view_t *view) void CL_NetGraph_Init_Cvars (void) { - cl_netgraph = Cvar_Get ("cl_netgraph", "0", CVAR_NONE, cl_netgraph_f, - "Toggle the display of a graph showing network " - "performance"); - cl_netgraph_alpha = Cvar_Get ("cl_netgraph_alpha", "0.5", CVAR_ARCHIVE, 0, - "Net graph translucency"); - cl_netgraph_box = Cvar_Get ("cl_netgraph_box", "1", CVAR_ARCHIVE, 0, - " Draw box around net graph"); - cl_netgraph_height = Cvar_Get ("cl_netgraph_height", "32", CVAR_ARCHIVE, - cl_netgraph_height_f, - "Set the fullscale (1s) height of the " - "graph"); + Cvar_Register (&cl_netgraph_cvar, cl_netgraph_f, 0); + Cvar_Register (&cl_netgraph_alpha_cvar, 0, 0); + Cvar_Register (&cl_netgraph_box_cvar, 0, 0); + Cvar_Register (&cl_netgraph_height_cvar, cl_netgraph_height_f, 0); } diff --git a/qw/source/cl_parse.c b/qw/source/cl_parse.c index cd97ec003..5b58202ac 100644 --- a/qw/source/cl_parse.c +++ b/qw/source/cl_parse.c @@ -190,7 +190,7 @@ CL_CalcNet (void) } else { double d = frame->receivedtime - frame->senttime; d = log (d * 1000 + 1) / log (1000); - d *= d * cl_netgraph_height->int_val; + d *= d * cl_netgraph_height; packet_latency[i & NET_TIMINGSMASK] = d; } } @@ -326,7 +326,7 @@ Model_NextDownload (void) && cl_world.models.a[i]->type == mod_alias) info_key = emodel_name; - if (info_key && cl_model_crcs->int_val) { + if (info_key && cl_model_crcs) { aliashdr_t *ahdr = cl_world.models.a[i]->aliashdr; if (!ahdr) ahdr = Cache_Get (&cl_world.models.a[i]->cache); @@ -1115,11 +1115,11 @@ CL_ServerInfo (void) } else if (strequal (key, "cshifts")) { cl.sv_cshifts = atoi (value); } else if (strequal (key, "no_pogo_stick")) { - Cvar_Set (no_pogo_stick, value); - cl.no_pogo_stick = no_pogo_stick->int_val; + Cvar_Set ("no_pogo_stick", value); + cl.no_pogo_stick = no_pogo_stick; } else if (strequal (key, "teamplay")) { cl.teamplay = atoi (value); - Sbar_DMO_Init_f (hud_scoreboard_uid); // HUD setup, cl.teamplay changed + Sbar_DMO_Init_f (0, 0); // HUD setup, cl.teamplay changed } else if (strequal (key, "watervis")) { cl.watervis = atoi (value); } else if (strequal (key, "fpd")) { @@ -1198,7 +1198,7 @@ CL_ParseMuzzleFlash (void) } #define SHOWNET(x) \ - if (cl_shownet->int_val == 2) \ + if (cl_shownet == 2) \ Sys_Printf ("%3i:%s\n", net_message->readcount - 1, x); int received_framecount; @@ -1218,9 +1218,9 @@ CL_ParseServerMessage (void) CL_ClearProjectiles (); // if recording demos, copy the message out - if (cl_shownet->int_val == 1) + if (cl_shownet == 1) Sys_Printf ("%i ", net_message->message->cursize); - else if (cl_shownet->int_val == 2) + else if (cl_shownet == 2) Sys_Printf ("------------------ %d\n", cls.netchan.incoming_acknowledged); @@ -1286,7 +1286,7 @@ CL_ParseServerMessage (void) break; // TODO: cl_nofake 2 -- accept fake messages from teammates - if (cl_nofake->int_val) { + if (cl_nofake) { char *c; p = dstring_strdup (str); diff --git a/qw/source/cl_pred.c b/qw/source/cl_pred.c index 7d25dd354..53435937f 100644 --- a/qw/source/cl_pred.c +++ b/qw/source/cl_pred.c @@ -42,8 +42,24 @@ #include "qw/include/client.h" #include "qw/pmove.h" -cvar_t *cl_predict; -cvar_t *cl_pushlatency; +int cl_predict; +static cvar_t cl_predict_cvar = { + .name = "cl_predict", + .description = + "Set to enable client prediction", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &cl_predict }, +}; +float cl_pushlatency; +static cvar_t cl_pushlatency_cvar = { + .name = "pushlatency", + .description = + "How much prediction should the client make", + .default_value = "-999", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &cl_pushlatency }, +}; void @@ -108,8 +124,8 @@ CL_PredictMove (void) entity_state_t *fromes; entity_state_t *toes; - if (cl_pushlatency->value > 0) - Cvar_Set (cl_pushlatency, "0"); + if (cl_pushlatency > 0) + Cvar_Set ("pushlatency", "0"); if (cl.paused) return; @@ -117,7 +133,7 @@ CL_PredictMove (void) // assume on ground unless prediction says different cl.viewstate.onground = 0; - cl.time = realtime - cls.latency - cl_pushlatency->value * 0.001; + cl.time = realtime - cls.latency - cl_pushlatency * 0.001; if (cl.time > realtime) cl.time = realtime; @@ -139,7 +155,7 @@ CL_PredictMove (void) from = &cl.frames[cls.netchan.incoming_sequence & UPDATE_MASK]; fromes = &from->playerstate[cl.playernum].pls.es; - if (!cl_predict->int_val) { + if (!cl_predict) { cl.viewstate.velocity = fromes->velocity; cl.viewstate.player_origin = fromes->origin; return; @@ -193,8 +209,6 @@ CL_PredictMove (void) void CL_Prediction_Init_Cvars (void) { - cl_predict = Cvar_Get ("cl_predict", "1", CVAR_NONE, NULL, - "Set to enable client prediction"); - cl_pushlatency = Cvar_Get ("pushlatency", "-999", CVAR_NONE, NULL, - "How much prediction should the client make"); + Cvar_Register (&cl_predict_cvar, 0, 0); + Cvar_Register (&cl_pushlatency_cvar, 0, 0); } diff --git a/qw/source/cl_rss.c b/qw/source/cl_rss.c index b5974ba53..8e0025454 100644 --- a/qw/source/cl_rss.c +++ b/qw/source/cl_rss.c @@ -213,7 +213,7 @@ snap_capture (tex_t *snap, void *data) snap_drawstring (st->str, tex, tex->width - strlen (st->str) * 8, tex->height - 11); - dstring_copystr (st, cl_name->string); + dstring_copystr (st, cl_name); snap_drawstring (st->str, tex, tex->width - strlen (st->str) * 8, tex->height - 21); diff --git a/qw/source/cl_screen.c b/qw/source/cl_screen.c index de8d13cf0..82fd9b63d 100644 --- a/qw/source/cl_screen.c +++ b/qw/source/cl_screen.c @@ -96,12 +96,12 @@ scr_draw_views (void) - cls.netchan.incoming_acknowledged) >= UPDATE_BACKUP - 1); loading_view->visible = cl.loading; - cl_netgraph_view->visible = cl_netgraph->int_val != 0; + cl_netgraph_view->visible = cl_netgraph != 0; //FIXME don't do every frame - view_move (cl_netgraph_view, cl_netgraph_view->xpos, sb_lines); + view_move (cl_netgraph_view, cl_netgraph_view->xpos, hud_sb_lines); view_setgravity (cl_netgraph_view, - hud_swap->int_val ? grav_southeast : grav_southwest); + hud_swap ? grav_southeast : grav_southwest); view_draw (r_data->vid->conview); } @@ -167,9 +167,9 @@ CL_UpdateScreen (double realtime) } if (!cl_netgraph_view) { - cl_netgraph_view = view_new (0, sb_lines, + cl_netgraph_view = view_new (0, hud_sb_lines, NET_TIMINGS + 16, - cl_netgraph_height->int_val + 25, + cl_netgraph_height + 25, grav_southwest); cl_netgraph_view->draw = CL_NetGraph; cl_netgraph_view->visible = 0; diff --git a/qw/source/cl_skin.c b/qw/source/cl_skin.c index 6ff72805b..e509764cc 100644 --- a/qw/source/cl_skin.c +++ b/qw/source/cl_skin.c @@ -50,10 +50,42 @@ #include "qw/include/client.h" #include "qw/include/host.h" -cvar_t *noskins; //XXX FIXME -cvar_t *skin; -cvar_t *topcolor; -cvar_t *bottomcolor; +int noskins; +static cvar_t noskins_cvar = { + .name = "noskins", + .description = + "set to 1 to not download new skins", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &noskins }, +}; +char *skin; +static cvar_t skin_cvar = { + .name = "skin", + .description = + "Players skin", + .default_value = "", + .flags = CVAR_ARCHIVE | CVAR_USERINFO, + .value = { .type = 0, .value = &skin }, +}; +char *topcolor; +static cvar_t topcolor_cvar = { + .name = "topcolor", + .description = + "Players color on top", + .default_value = "0", + .flags = CVAR_ARCHIVE | CVAR_USERINFO, + .value = { .type = 0/* not used */, .value = &topcolor }, +}; +char *bottomcolor; +static cvar_t bottomcolor_cvar = { + .name = "bottomcolor", + .description = + "Players color on bottom", + .default_value = "0", + .flags = CVAR_ARCHIVE | CVAR_USERINFO, + .value = { .type = 0/* not used */, .value = &bottomcolor }, +}; void @@ -76,7 +108,7 @@ Skin_NextDownload (void) if (!sc->name || !sc->name->value[0]) continue; //XXX Skin_Find (sc); - if (noskins->int_val) //XXX FIXME + if (noskins) //XXX FIXME continue; //XXX if (!CL_CheckOrDownloadFile (va (0, "skins/%s.pcx", // sc->skin->name))) @@ -175,18 +207,18 @@ CL_Color_f (void) bottom = 13; snprintf (num, sizeof (num), "%i", top); - Cvar_Set (topcolor, num); + Cvar_Set ("topcolor", num); snprintf (num, sizeof (num), "%i", bottom); - Cvar_Set (bottomcolor, num); + Cvar_Set ("bottomcolor", num); } static void -skin_f (cvar_t *var) +skin_f (void *data, const cvar_t *cvar) { - char *s = Hunk_TempAlloc (0, strlen (var->string) + 1); - QFS_StripExtension (var->string, s); - Cvar_Set (var, s); - Cvar_Info (var); + char *s = Hunk_TempAlloc (0, strlen (skin) + 1); + QFS_StripExtension (skin, s); + skin = strdup (s); + Cvar_Info (0, cvar); } void @@ -200,12 +232,8 @@ CL_Skin_Init (void) "shirt pants) Note that if only shirt color is given, " "pants will match"); - noskins = Cvar_Get ("noskins", "0", CVAR_ARCHIVE, NULL, - "set to 1 to not download new skins"); - skin = Cvar_Get ("skin", "", CVAR_ARCHIVE | CVAR_USERINFO, skin_f, - "Players skin"); - topcolor = Cvar_Get ("topcolor", "0", CVAR_ARCHIVE | CVAR_USERINFO, - Cvar_Info, "Players color on top"); - bottomcolor = Cvar_Get ("bottomcolor", "0", CVAR_ARCHIVE | CVAR_USERINFO, - Cvar_Info, "Players color on bottom"); + Cvar_Register (&noskins_cvar, 0, 0); + Cvar_Register (&skin_cvar, skin_f, 0); + Cvar_Register (&topcolor_cvar, Cvar_Info, &topcolor); + Cvar_Register (&bottomcolor_cvar, Cvar_Info, &bottomcolor); } diff --git a/qw/source/cl_slist.c b/qw/source/cl_slist.c index 4d5b43513..9dd89e9a1 100644 --- a/qw/source/cl_slist.c +++ b/qw/source/cl_slist.c @@ -90,10 +90,42 @@ server_entry_t *fav_slist; int which_slist; int slist_last_details; -cvar_t *sl_sortby; -cvar_t *sl_filter; -cvar_t *sl_game; -cvar_t *sl_ping; +int sl_sortby; +static cvar_t sl_sortby_cvar = { + .name = "sl_sortby", + .description = + "0 = sort by name, 1 = sort by ping", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &sl_sortby }, +}; +int sl_filter; +static cvar_t sl_filter_cvar = { + .name = "sl_filter", + .description = + "enable server filter", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sl_filter }, +}; +char *sl_game; +static cvar_t sl_game_cvar = { + .name = "sl_game", + .description = + "sets the serverlist game filter", + .default_value = "", + .flags = CVAR_ARCHIVE, + .value = { .type = 0, .value = &sl_game }, +}; +int sl_ping; +static cvar_t sl_ping_cvar = { + .name = "sl_ping", + .description = + "sets the serverlist ping filter", + .default_value = "", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &sl_ping }, +}; static void @@ -225,19 +257,19 @@ SL_Swap (server_entry_t *swap1, server_entry_t *swap2) static int SL_CheckFilter (server_entry_t *sl_filteritem) { - if (!sl_filter->int_val) + if (!sl_filter) return (1); if (!sl_filteritem->status) return (0); - if (strlen (sl_game->string)) { + if (strlen (sl_game)) { if (strcasecmp (Info_ValueForKey (sl_filteritem->status, "*gamedir"), - sl_game->string) != 0) + sl_game) != 0) return (0); } - if (sl_ping->int_val) { + if (sl_ping) { if (!sl_filteritem->pongback) return (0); - if (((int) (sl_filteritem->pongback * 1000)) >= sl_ping->int_val) + if (((int) (sl_filteritem->pongback * 1000)) >= sl_ping) return (0); } return (1); @@ -373,7 +405,7 @@ SL_SortEntry (server_entry_t *start) return; for (q = start->next; q; q = q->next) { - if (sl_sortby->int_val) { + if (sl_sortby) { if ((q->pongback) && (start->pongback) && (start->pongback > q->pongback)) { SL_Swap (start, q); @@ -396,7 +428,7 @@ SL_SortEntry (server_entry_t *start) } static void -SL_Sort (cvar_t *var) +SL_Sort (void *data, const cvar_t *cvar) { server_entry_t *p; @@ -413,7 +445,7 @@ SL_Con_List (server_entry_t *sldata) int serv; server_entry_t *cp; - SL_Sort (sl_sortby); + SL_Sort (0, 0); for (serv = 0; serv < SL_Len (sldata); serv++) { cp = SL_Get_By_Num (sldata, serv); @@ -520,7 +552,7 @@ SL_Switch (void) slist = fav_slist; which_slist = 0; } - SL_Sort (sl_sortby); + SL_Sort (0, 0); return (which_slist); } @@ -638,14 +670,10 @@ SL_Init (void) which_slist = 0; Cmd_AddCommand ("slist", SL_Command, "console commands to access server " "list\n"); - sl_sortby = Cvar_Get ("sl_sortby", "0", CVAR_ARCHIVE, SL_Sort, "0 = sort " - "by name, 1 = sort by ping"); - sl_filter = Cvar_Get ("sl_filter", "0", CVAR_NONE, NULL, "enable server " - "filter"); - sl_game = Cvar_Get ("sl_game", "", CVAR_ARCHIVE, NULL, "sets the " - "serverlist game filter"); - sl_ping = Cvar_Get ("sl_ping", "", CVAR_ARCHIVE, NULL, "sets the " - "serverlist ping filter"); + Cvar_Register (&sl_sortby_cvar, SL_Sort, 0); + Cvar_Register (&sl_filter_cvar, 0, 0); + Cvar_Register (&sl_game_cvar, 0, 0); + Cvar_Register (&sl_ping_cvar, 0, 0); } int diff --git a/qw/source/crudefile.c b/qw/source/crudefile.c index 4924a03ee..7ef0cad74 100644 --- a/qw/source/crudefile.c +++ b/qw/source/crudefile.c @@ -66,7 +66,16 @@ typedef struct cf_file_s { } cf_file_t; cf_file_t *cf_filep; -cvar_t *crudefile_quota; +int crudefile_quota; +static cvar_t crudefile_quota_cvar = { + .name = "crudefile_quota", + .description = + "Maximum space available to the Crude File system, -1 to totally " + "disable file writing", + .default_value = "-1", + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &crudefile_quota }, +}; int cf_filepcount; // elements in array int cf_openfiles; // used elements @@ -164,10 +173,8 @@ void CF_Init (void) { CF_BuildQuota (); - crudefile_quota = Cvar_Get ("crudefile_quota", "-1", CVAR_ROM, NULL, - "Maximum space available to the Crude File " - "system, -1 to totally disable file writing"); - cf_maxsize = crudefile_quota->int_val; + Cvar_Register (&crudefile_quota_cvar, 0, 0); + cf_maxsize = crudefile_quota; } /* diff --git a/qw/source/game.c b/qw/source/game.c index df180b306..dba073f3e 100644 --- a/qw/source/game.c +++ b/qw/source/game.c @@ -46,7 +46,15 @@ #include "qw/include/game.h" #include "qw/include/server.h" -cvar_t *registered; +char *registered; +static cvar_t registered_cvar = { + .name = "registered", + .description = + "Is the game the registered version. 1 yes 0 no", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = ®istered }, +}; int static_registered = 1; // only for startup check, then set /* @@ -71,7 +79,7 @@ Game_CheckRegistered (void) } if (static_registered) { - Cvar_Set (registered, "1"); + Cvar_Set ("registered", "1"); Sys_Printf ("Playing registered version.\n"); } } @@ -110,8 +118,7 @@ SV_Gamedir_f (void) void Game_Init (void) { - registered = Cvar_Get ("registered", "0", CVAR_NONE, NULL, - "Is the game the registered version. 1 yes 0 no"); + Cvar_Register (®istered_cvar, 0, 0); Game_CheckRegistered (); Cmd_AddCommand ("gamedir", SV_Gamedir_f, "Specifies the directory to be used while playing."); diff --git a/qw/source/net_packetlog.c b/qw/source/net_packetlog.c index 92cddcb38..cd9b6eed6 100644 --- a/qw/source/net_packetlog.c +++ b/qw/source/net_packetlog.c @@ -59,8 +59,24 @@ #include "qw/protocol.h" #include "qw/include/server.h" -cvar_t *net_packetlog; -cvar_t *net_loglevel; +int net_packetlog; +static cvar_t net_packetlog_cvar = { + .name = "net_packetlog", + .description = + "enable/disable packet logging", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &net_packetlog }, +}; +int net_loglevel; +static cvar_t net_loglevel_cvar = { + .name = "net_loglevel", + .description = + "Packet logging/parsing", + .default_value = "2", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &net_loglevel }, +}; // note: this is SUPPOSED to be duplicate, like many others const char *svc_string[] = { @@ -227,22 +243,22 @@ ascii_dump_buf (unsigned char *buf, int len) void Log_Incoming_Packet (const byte *p, int len, int has_sequence) { - if (!net_loglevel->int_val) + if (!net_loglevel) return; if (is_server) { Net_LogPrintf ("\n<<<<<<<<<<<<<<<<<<<<< client to server %d bytes: " "<<<<<<<<<<<<<<<<<<<<<<<<\n", len); - if (net_loglevel->int_val != 3) + if (net_loglevel != 3) hex_dump_buf ((unsigned char *) p, len); - if (net_loglevel->int_val > 1) + if (net_loglevel > 1) Analyze_Client_Packet (p, len, has_sequence); } else { Net_LogPrintf ("\n>>>>>>>>>>>>>>>>>>>>> server to client %d bytes: " ">>>>>>>>>>>>>>>>>>>>>>>>\n", len); - if (net_loglevel->int_val != 3) + if (net_loglevel != 3) hex_dump_buf ((unsigned char *) p, len); - if (net_loglevel->int_val > 1) + if (net_loglevel > 1) Analyze_Server_Packet (p, len, has_sequence); } return; @@ -251,22 +267,22 @@ Log_Incoming_Packet (const byte *p, int len, int has_sequence) void Log_Outgoing_Packet (const byte *p, int len, int has_sequence) { - if (!net_loglevel->int_val) + if (!net_loglevel) return; if (is_server) { Net_LogPrintf ("\n>>>>>>>>>>>>>>>>>>>>> server to client %d bytes: " ">>>>>>>>>>>>>>>>>>>>>>>>\n", len); - if (net_loglevel->int_val != 3) + if (net_loglevel != 3) hex_dump_buf ((unsigned char *) p, len); - if (net_loglevel->int_val > 1) + if (net_loglevel > 1) Analyze_Server_Packet (p, len, has_sequence); } else { Net_LogPrintf ("\n<<<<<<<<<<<<<<<<<<<<< client to server %d bytes: " "<<<<<<<<<<<<<<<<<<<<<<<<\n", len); - if (net_loglevel->int_val != 3) + if (net_loglevel != 3) hex_dump_buf ((unsigned char *) p, len); - if (net_loglevel->int_val > 1) + if (net_loglevel > 1) Analyze_Client_Packet (p, len, has_sequence); } return; @@ -958,9 +974,9 @@ net_packet_log_f (int length, const void *data, netadr_t to) } static void -Net_PacketLog_f (cvar_t *var) +Net_PacketLog_f (void *data, const cvar_t *cvar) { - if (var->int_val) { + if (net_packetlog) { Net_LogStart ("qfpacket.log"); net_log_packet = net_packet_log_f; } else { @@ -990,8 +1006,7 @@ Net_Log_Init (const char **sound_precache, int server) _stdout = Qdopen (1, "wt"); // create a QFile of stdout - net_packetlog = Cvar_Get ("net_packetlog", "0", CVAR_NONE, Net_PacketLog_f, - "enable/disable packet logging"); + Cvar_Register (&net_packetlog_cvar, Net_PacketLog_f, 0); // 0 = no logging // 1 = hex dump only @@ -999,8 +1014,7 @@ Net_Log_Init (const char **sound_precache, int server) // 3 = just parse // 4 = parse/hexdump, skip movement/empty messages - net_loglevel = Cvar_Get ("net_loglevel", "2", CVAR_NONE, NULL, - "Packet logging/parsing"); + Cvar_Register (&net_loglevel_cvar, 0, 0); Cmd_AddCommand ("net_packetlog_zap", Net_PacketLog_Zap_f, "clear the packet log file"); diff --git a/qw/source/pmove.c b/qw/source/pmove.c index 07d30f0bc..0d208f947 100644 --- a/qw/source/pmove.c +++ b/qw/source/pmove.c @@ -39,7 +39,16 @@ #include "qw/include/client.h" #include "qw/pmove.h" -cvar_t *no_pogo_stick; +int no_pogo_stick; +static cvar_t no_pogo_stick_cvar = { + .name = "no_pogo_stick", + .description = + "disable the ability to pogo stick: 0 pogo allowed, 1 no pogo, 2 pogo " + "but high friction, 3 high friction and no pogo", + .default_value = "0", + .flags = CVAR_SERVERINFO, + .value = { .type = &cexpr_int, .value = &no_pogo_stick }, +}; movevars_t movevars; playermove_t pmove; @@ -63,10 +72,7 @@ Pmove_Init (void) void Pmove_Init_Cvars (void) { - no_pogo_stick = Cvar_Get ("no_pogo_stick", "0", CVAR_SERVERINFO, Cvar_Info, - "disable the ability to pogo stick: 0 pogo " - "allowed, 1 no pogo, 2 pogo but high friction, " - "3 high friction and no pogo"); + Cvar_Register (&no_pogo_stick_cvar, Cvar_Info, &no_pogo_stick); } #define STEPSIZE 18 @@ -637,7 +643,7 @@ JumpButton (void) } if (onground == -1) { - if (no_pogo_stick->int_val & 1) + if (no_pogo_stick & 1) pmove.oldbuttons |= BUTTON_JUMP; // don't jump again until // released return; // in air, so no effect @@ -820,9 +826,9 @@ PlayerMove (void) // set onground, watertype, and waterlevel PM_CategorizePosition (); - if (((pmove.cmd.buttons & BUTTON_JUMP) || (no_pogo_stick->int_val & 1)) + if (((pmove.cmd.buttons & BUTTON_JUMP) || (no_pogo_stick & 1)) && onground != -1 && pmove.oldonground == -1 // just landed - && (no_pogo_stick->int_val & 2)) { + && (no_pogo_stick & 2)) { float save = movevars.friction; pmove.waterjumptime = 0; diff --git a/qw/source/sbar.c b/qw/source/sbar.c index 15863b80d..bd717a1c2 100644 --- a/qw/source/sbar.c +++ b/qw/source/sbar.c @@ -67,6 +67,7 @@ #include "sbar.h" int sb_updates; // if >= vid.numpages, no update needed +static int sb_view_size; #define STAT_MINUS 10 // num frame for '-' stats digit @@ -92,126 +93,64 @@ qpic_t *sb_face_invis_invuln; qboolean sb_showscores; qboolean sb_showteamscores; -int sb_lines; // scan lines to draw - static qboolean largegame = false; -cvar_t *fs_fraglog; -cvar_t *cl_fraglog; -cvar_t *hud_scoreboard_uid; -cvar_t *scr_centertime; -cvar_t *scr_printspeed; - -static view_t *sbar_view; -static view_t *sbar_inventory_view; -static view_t *sbar_frags_view; - -static view_t *hud_view; -static view_t *hud_inventory_view; -static view_t *hud_armament_view; -static view_t *hud_frags_view; - -static view_t *overlay_view; -static view_t *stuff_view; -static view_t *main_view; +char *fs_fraglog; +static cvar_t fs_fraglog_cvar = { + .name = "fs_fraglog", + .description = + "Filename of the automatic frag-log.", + .default_value = "qw-scores.log", + .flags = CVAR_ARCHIVE, + .value = { .type = 0, .value = &fs_fraglog }, +}; +int cl_fraglog; +static cvar_t cl_fraglog_cvar = { + .name = "cl_fraglog", + .description = + "Automatic fraglogging, non-zero value will switch it on.", + .default_value = "0", + .flags = CVAR_ARCHIVE, + .value = { .type = &cexpr_int, .value = &cl_fraglog }, +}; +int hud_scoreboard_uid; +static cvar_t hud_scoreboard_uid_cvar = { + .name = "hud_scoreboard_uid", + .description = + "Set to 1 to show uid instead of ping. Set to 2 to show both.", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &hud_scoreboard_uid }, +}; +float scr_centertime; +static cvar_t scr_centertime_cvar = { + .name = "scr_centertime", + .description = + "How long in seconds screen hints are displayed", + .default_value = "2", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &scr_centertime }, +}; +float scr_printspeed; +static cvar_t scr_printspeed_cvar = { + .name = "scr_printspeed", + .description = + "How fast the text is displayed at the end of the single player " + "episodes", + .default_value = "8", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &scr_printspeed }, +}; static void (*Sbar_Draw_DMO_func) (view_t *view, int l, int y, int skip); static void -hud_swap_f (cvar_t *var) +viewsize_f (int view_size) { - if (var->int_val) { - view_setgravity (hud_armament_view, grav_southwest); - view_setgravity (stuff_view, grav_southeast); - } else { - view_setgravity (hud_armament_view, grav_southeast); - view_setgravity (stuff_view, grav_southwest); - } -} - -static void -hud_scoreboard_gravity_f (cvar_t *var) -{ - grav_t grav; - - if (strequal (var->string, "center")) - grav = grav_center; - else if (strequal (var->string, "northwest")) - grav = grav_northwest; - else if (strequal (var->string, "north")) - grav = grav_north; - else if (strequal (var->string, "northeast")) - grav = grav_northeast; - else if (strequal (var->string, "west")) - grav = grav_west; - else if (strequal (var->string, "east")) - grav = grav_east; - else if (strequal (var->string, "southwest")) - grav = grav_southwest; - else if (strequal (var->string, "south")) - grav = grav_south; - else if (strequal (var->string, "southeast")) - grav = grav_southeast; - else - grav = grav_center; - overlay_view->gravity = grav; - view_move (overlay_view, overlay_view->xpos, overlay_view->ypos); -} - -static void -calc_sb_lines (cvar_t *var) -{ - int stuff_y; - - if (var->int_val >= 120) { - sb_lines = 0; - stuff_y = 0; - } else if (var->int_val >= 110) { - sb_lines = 24; - sbar_inventory_view->visible = 0; - hud_inventory_view->visible = 0; - hud_armament_view->visible = 0; - stuff_y = 32; - } else { - sb_lines = 48; - sbar_inventory_view->visible = 1; - hud_inventory_view->visible = 1; - hud_armament_view->visible = 1; - stuff_y = 48; - } - if (sb_lines) { - sbar_view->visible = 1; - hud_view->visible = 1; - view_resize (sbar_view, sbar_view->xlen, sb_lines); - view_resize (hud_view, hud_view->xlen, sb_lines); - } else { - sbar_view->visible = 0; - hud_view->visible = 0; - } - view_move (stuff_view, stuff_view->xpos, stuff_y); -} - -static void -hud_sbar_f (cvar_t *var) -{ - if (r_data->scr_viewsize) - calc_sb_lines (r_data->scr_viewsize); - SCR_SetBottomMargin (var->int_val ? sb_lines : 0); - if (var->int_val) { - view_remove (main_view, main_view->children[0]); - view_insert (main_view, sbar_view, 0); - } else { - view_remove (main_view, main_view->children[0]); - view_insert (main_view, hud_view, 0); - } -} - -static void -viewsize_f (cvar_t *var) -{ - calc_sb_lines (var); + sb_view_size = view_size; + HUD_Calc_sb_lines (view_size); if (hud_sbar) { - SCR_SetBottomMargin (hud_sbar->int_val ? sb_lines : 0); + SCR_SetBottomMargin (hud_sbar ? hud_sb_lines : 0); } } @@ -1049,7 +988,7 @@ sbar_update_vis (void) sbar_view->visible = 0; - headsup = !(hud_sbar->int_val || r_data->scr_viewsize->int_val < 100); + headsup = !(hud_sbar || sb_view_size < 100); if ((sb_updates >= r_data->vid->numpages) && !headsup) return; @@ -1058,7 +997,7 @@ sbar_update_vis (void) && con_module->data->console->lines == r_data->vid->conview->ylen) return; // console is full screen - if (!sb_lines) + if (!hud_sb_lines) return; sbar_view->visible = 1; @@ -1074,7 +1013,7 @@ void Sbar_Draw (void) { sbar_update_vis (); - main_view->draw (main_view); + hud_main_view->draw (hud_main_view); } /* @@ -1098,10 +1037,10 @@ Sbar_LogFrags (void) const char *t = NULL; time_t tt = time (NULL); - if (!cl_fraglog->int_val) + if (!cl_fraglog) return; - if ((file = QFS_Open (fs_fraglog->string, "a")) == NULL) + if ((file = QFS_Open (fs_fraglog, "a")) == NULL) return; t = ctime (&tt); @@ -1158,7 +1097,7 @@ Sbar_LogFrags (void) } else { if (cl.teamplay) { team = malloc (strlen (s->team->value) + 1); - for (cp = (byte *) s->team->value, d = 0; *cp; cp++, d++) + for (cp = (byte *) s->team, d = 0; *cp; cp++, d++) team[d] = sys_char_map[*cp]; team[d] = 0; @@ -1414,25 +1353,19 @@ Sbar_Draw_DMO_Ping_UID (view_t *view, int l, int y, int skip) } void -Sbar_DMO_Init_f (cvar_t *var) +Sbar_DMO_Init_f (void *data, const cvar_t *cvar) { - // "var" is "hud_scoreboard_uid" - if (!var) { - Sbar_Draw_DMO_func = Sbar_Draw_DMO_Ping; - return; - } - if (cl.teamplay) - if (var->int_val > 1) + if (hud_scoreboard_uid > 1) Sbar_Draw_DMO_func = Sbar_Draw_DMO_Team_Ping_UID; - else if (var->int_val > 0) + else if (hud_scoreboard_uid > 0) Sbar_Draw_DMO_func = Sbar_Draw_DMO_Team_UID; else Sbar_Draw_DMO_func = Sbar_Draw_DMO_Team_Ping; else - if (var->int_val > 1) + if (hud_scoreboard_uid > 1) Sbar_Draw_DMO_func = Sbar_Draw_DMO_Ping_UID; - else if (var->int_val > 0) + else if (hud_scoreboard_uid > 0) Sbar_Draw_DMO_func = Sbar_Draw_DMO_UID; else Sbar_Draw_DMO_func = Sbar_Draw_DMO_Ping; @@ -1572,10 +1505,10 @@ draw_time (view_t *view) # define HOUR24 "%k" # define PM "%P" #endif - if (hud_time->int_val == 1) { // Use international format + if (hud_time == 1) { // Use international format strftime (st, sizeof (st), HOUR24":%M", local); draw_string (view, 8, 0, st); - } else if (hud_time->int_val >= 2) { // US AM/PM display + } else if (hud_time >= 2) { // US AM/PM display strftime (st, sizeof (st), HOUR12":%M "PM, local); draw_string (view, 8, 0, st); } @@ -1608,17 +1541,17 @@ draw_net (view_t *view) MSG_WriteByte (&cls.netchan.message, clc_stringcmd); SZ_Print (&cls.netchan.message, "pings"); } - if (hud_ping->int_val) { + if (hud_ping) { int ping = cl.players[cl.playernum].ping; ping = bound (0, ping, 999); draw_string (view, 0, 0, va (0, "%3d ms ", ping)); } - if (hud_ping->int_val && hud_pl->int_val) + if (hud_ping && hud_pl) draw_character (view, 48, 0, '/'); - if (hud_pl->int_val) { + if (hud_pl) { int lost = CL_CalcNet (); lost = bound (0, lost, 999); @@ -1629,11 +1562,11 @@ draw_net (view_t *view) static void draw_stuff (view_t *view) { - if (hud_time->int_val > 0) + if (hud_time > 0) draw_time (view); - if (hud_fps->int_val > 0) + if (hud_fps > 0) draw_fps (view); - if (cls.state == ca_active && (hud_ping->int_val || hud_pl->int_val)) + if (cls.state == ca_active && (hud_ping || hud_pl)) draw_net (view); } @@ -1644,9 +1577,9 @@ Sbar_IntermissionOverlay (void) r_data->scr_fullupdate = 0; if (cl.teamplay > 0 && !sb_showscores) - Sbar_TeamOverlay (overlay_view); + Sbar_TeamOverlay (hud_overlay_view); else - Sbar_DeathmatchOverlay (overlay_view, 0); + Sbar_DeathmatchOverlay (hud_overlay_view, 0); } /* CENTER PRINTING */ @@ -1670,7 +1603,7 @@ Sbar_CenterPrint (const char *str) dstring_copystr (¢er_string, str); - centertime_off = scr_centertime->value; + centertime_off = scr_centertime; centertime_start = realtime; // count the number of lines for centering @@ -1724,10 +1657,10 @@ Sbar_FinaleOverlay (void) r_data->scr_copyeverything = 1; - draw_cachepic (overlay_view, 0, 16, "gfx/finale.lmp", 1); + draw_cachepic (hud_overlay_view, 0, 16, "gfx/finale.lmp", 1); // the finale prints the characters one at a time - remaining = scr_printspeed->value * (realtime - centertime_start); - Sbar_DrawCenterString (overlay_view, remaining); + remaining = scr_printspeed * (realtime - centertime_start); + Sbar_DrawCenterString (hud_overlay_view, remaining); } void @@ -1739,7 +1672,7 @@ Sbar_DrawCenterPrint (void) if (centertime_off <= 0) return; - Sbar_DrawCenterString (overlay_view, -1); + Sbar_DrawCenterString (hud_overlay_view, -1); } static void @@ -1901,33 +1834,33 @@ init_hud_views (void) view_add (hud_view, hud_armament_view); - view_insert (main_view, hud_view, 0); + view_insert (hud_main_view, hud_view, 0); } static void init_views (void) { - main_view = view_new (0, 0, r_data->vid->conview->xlen, + hud_main_view = view_new (0, 0, r_data->vid->conview->xlen, r_data->vid->conview->ylen, grav_northwest); if (con_module) - view_insert (con_module->data->console->view, main_view, 0); - main_view->resize_x = 1; // get resized if the 2d view resizes - main_view->resize_y = 1; - main_view->visible = 0; // but don't let the console draw our stuff + view_insert (con_module->data->console->view, hud_main_view, 0); + hud_main_view->resize_x = 1; // get resized if the 2d view resizes + hud_main_view->resize_y = 1; + hud_main_view->visible = 0; // but don't let the console draw our stuff if (r_data->vid->conview->ylen > 300) - overlay_view = view_new (0, 0, 320, 300, grav_center); + hud_overlay_view = view_new (0, 0, 320, 300, grav_center); else - overlay_view = view_new (0, 0, 320, r_data->vid->conview->ylen, + hud_overlay_view = view_new (0, 0, 320, r_data->vid->conview->ylen, grav_center); - overlay_view->draw = draw_overlay; - overlay_view->visible = 0; + hud_overlay_view->draw = draw_overlay; + hud_overlay_view->visible = 0; - stuff_view = view_new (0, 48, 152, 16, grav_southwest); - stuff_view->draw = draw_stuff; + hud_stuff_view = view_new (0, 48, 152, 16, grav_southwest); + hud_stuff_view->draw = draw_stuff; - view_insert (main_view, overlay_view, 0); - view_insert (main_view, stuff_view, 0); + view_insert (hud_main_view, hud_overlay_view, 0); + view_insert (hud_main_view, hud_stuff_view, 0); init_sbar_views (); init_hud_views (); @@ -2052,29 +1985,13 @@ Sbar_Init (void) r_data->viewsize_callback = viewsize_f; - hud_scoreboard_uid = Cvar_Get ("hud_scoreboard_uid", "0", CVAR_NONE, - Sbar_DMO_Init_f, "Set to 1 to show uid " - "instead of ping. Set to 2 to show both."); - fs_fraglog = Cvar_Get ("fs_fraglog", "qw-scores.log", CVAR_ARCHIVE, NULL, - "Filename of the automatic frag-log."); - cl_fraglog = Cvar_Get ("cl_fraglog", "0", CVAR_ARCHIVE, NULL, - "Automatic fraglogging, non-zero value will switch " - "it on."); - hud_sbar = Cvar_Get ("hud_sbar", "0", CVAR_ARCHIVE, hud_sbar_f, - "status bar mode: 0 = hud, 1 = oldstyle"); - hud_swap = Cvar_Get ("hud_swap", "0", CVAR_ARCHIVE, hud_swap_f, - "new HUD on left side?"); - hud_scoreboard_gravity = Cvar_Get ("hud_scoreboard_gravity", "center", - CVAR_ARCHIVE, hud_scoreboard_gravity_f, - "control placement of scoreboard " - "overlay: center, northwest, north, " - "northeast, west, east, southwest, " - "south, southeast"); - scr_centertime = Cvar_Get ("scr_centertime", "2", CVAR_NONE, NULL, "How " - "long in seconds screen hints are displayed"); - scr_printspeed = Cvar_Get ("scr_printspeed", "8", CVAR_NONE, NULL, - "How fast the text is displayed at the end of " - "the single player episodes"); + HUD_Init_Cvars (); + + Cvar_Register (&hud_scoreboard_uid_cvar, Sbar_DMO_Init_f, 0); + Cvar_Register (&fs_fraglog_cvar, 0, 0); + Cvar_Register (&cl_fraglog_cvar, 0, 0); + Cvar_Register (&scr_centertime_cvar, 0, 0); + Cvar_Register (&scr_printspeed_cvar, 0, 0); // register GIB builtins GIB_Builtin_Add ("print::center", Sbar_GIB_Print_Center_f); diff --git a/qw/source/sv_ccmds.c b/qw/source/sv_ccmds.c index f9e99f0b5..d48ae705f 100644 --- a/qw/source/sv_ccmds.c +++ b/qw/source/sv_ccmds.c @@ -62,7 +62,15 @@ qboolean sv_allow_cheats; int fp_messages = 4, fp_persecond = 4, fp_secondsdead = 10; char fp_msg[255] = { 0 }; -cvar_t *sv_leetnickmatch; +int sv_leetnickmatch; +static cvar_t sv_leetnickmatch_cvar = { + .name = "sv_3133735_7h4n_7h0u", + .description = + "Match '1' as 'i' and such in nicks", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sv_leetnickmatch }, +}; static qboolean match_char (char a, char b) @@ -70,7 +78,7 @@ match_char (char a, char b) a = tolower ((byte) sys_char_map[(byte) a]); b = tolower ((byte) sys_char_map[(byte) b]); - if (a == b || (sv_leetnickmatch->int_val + if (a == b || (sv_leetnickmatch && ( (a == '1' && b == 'i') || (a == 'i' && b == '1') || (a == '1' && b == 'l') || (a == 'l' && b == '1') || (a == '3' && b == 'e') || (a == 'e' && b == '3') @@ -871,13 +879,12 @@ SV_SendServerInfoChange (const char *key, const char *value) } void -Cvar_Info (cvar_t *var) +Cvar_Info (void *data, const cvar_t *cvar) { - if (var->flags & CVAR_SERVERINFO) { - Info_SetValueForKey (svs.info, var->name, var->string, - (!sv_highchars || !sv_highchars->int_val)); - - SV_SendServerInfoChange (var->name, var->string); + if (cvar->flags & CVAR_SERVERINFO) { + const char *cvar_str = Cvar_VarString (cvar); + Info_SetValueForKey (svs.info, cvar->name, cvar_str, !sv_highchars); + SV_SendServerInfoChange (cvar->name, cvar_str); } } @@ -923,9 +930,9 @@ SV_Serverinfo_f (void) // if this is a cvar, change it too var = Cvar_FindVar (key); if (var && (var->flags & CVAR_SERVERINFO)) { - Cvar_Set (var, value); + Cvar_SetVar (var, value); } else { - Info_SetValueForKey (svs.info, key, value, !sv_highchars->int_val); + Info_SetValueForKey (svs.info, key, value, !sv_highchars); SV_SendServerInfoChange (key, value); } } @@ -939,7 +946,7 @@ SV_SetLocalinfo (const char *key, const char *value) oldvalue = strdup (Info_ValueForKey (localinfo, key)); if (*value) - Info_SetValueForKey (localinfo, key, value, !sv_highchars->int_val); + Info_SetValueForKey (localinfo, key, value, !sv_highchars); else Info_RemoveKey (localinfo, key); @@ -1049,7 +1056,7 @@ SV_Gamedir (void) } Info_SetValueForStarKey (svs.info, "*gamedir", dir, - !sv_highchars->int_val); + !sv_highchars); } /* @@ -1304,6 +1311,5 @@ SV_InitOperatorCommands (void) "commands do, so you can check safely"); // poor description - sv_leetnickmatch = Cvar_Get ("sv_3133735_7h4n_7h0u", "1", CVAR_NONE, NULL, - "Match '1' as 'i' and such in nicks"); + Cvar_Register (&sv_leetnickmatch_cvar, 0, 0); } diff --git a/qw/source/sv_demo.c b/qw/source/sv_demo.c index 47580b4e0..b0b8fb30c 100644 --- a/qw/source/sv_demo.c +++ b/qw/source/sv_demo.c @@ -66,26 +66,138 @@ static recorder_t *recorder; static int delta_sequence; #define MIN_DEMO_MEMORY 0x100000 -#define USECACHE (sv_demoUseCache->int_val && svs.demomemsize) +#define USECACHE (sv_demoUseCache && svs.demomemsize) #define DWRITE(a,b,d) dwrite((QFile *) d, a, b) static int demo_max_size; static int demo_size; -cvar_t *sv_demofps; -cvar_t *sv_demoPings; -cvar_t *sv_demoMaxSize; -static cvar_t *sv_demoUseCache; -static cvar_t *sv_demoCacheSize; -static cvar_t *sv_demoMaxDirSize; -static cvar_t *sv_demoDir; -static cvar_t *sv_demoNoVis; -static cvar_t *sv_demoPrefix; -static cvar_t *sv_demoSuffix; -static cvar_t *sv_onrecordfinish; -static cvar_t *sv_ondemoremove; -static cvar_t *sv_demotxt; -static cvar_t *serverdemo; +float sv_demofps; +static cvar_t sv_demofps_cvar = { + .name = "sv_demofps", + .description = + "FIXME", + .default_value = "20", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &sv_demofps }, +}; +float sv_demoPings; +static cvar_t sv_demoPings_cvar = { + .name = "sv_demoPings", + .description = + "FIXME", + .default_value = "3", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &sv_demoPings }, +}; +char *sv_demoMaxSize; +static cvar_t sv_demoMaxSize_cvar = { + .name = "sv_demoMaxSize", + .description = + "FIXME", + .default_value = "20480", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &sv_demoMaxSize }, +}; +static int sv_demoUseCache; +static cvar_t sv_demoUseCache_cvar = { + .name = "sv_demoUseCache", + .description = + "FIXME", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sv_demoUseCache }, +}; +static char *sv_demoCacheSize; +static cvar_t sv_demoCacheSize_cvar = { + .name = "sv_demoCacheSize", + .description = + "FIXME", + .default_value = 0, + .flags = CVAR_ROM, + .value = { .type = 0/* not used */, .value = &sv_demoCacheSize }, +}; +static char *sv_demoMaxDirSize; +static cvar_t sv_demoMaxDirSize_cvar = { + .name = "sv_demoMaxDirSize", + .description = + "FIXME", + .default_value = "102400", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &sv_demoMaxDirSize }, +}; +static char *sv_demoDir; +static cvar_t sv_demoDir_cvar = { + .name = "sv_demoDir", + .description = + "FIXME", + .default_value = "demos", + .flags = CVAR_NONE, + .value = { .type = 0, .value = &sv_demoDir }, +}; +static char *sv_demoNoVis; +static cvar_t sv_demoNoVis_cvar = { + .name = "sv_demoNoVis", + .description = + "FIXME", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &sv_demoNoVis }, +}; +static char *sv_demoPrefix; +static cvar_t sv_demoPrefix_cvar = { + .name = "sv_demoPrefix", + .description = + "FIXME", + .default_value = "", + .flags = CVAR_NONE, + .value = { .type = 0, .value = &sv_demoPrefix }, +}; +static char *sv_demoSuffix; +static cvar_t sv_demoSuffix_cvar = { + .name = "sv_demoSuffix", + .description = + "FIXME", + .default_value = "", + .flags = CVAR_NONE, + .value = { .type = 0, .value = &sv_demoSuffix }, +}; +static char *sv_onrecordfinish; +static cvar_t sv_onrecordfinish_cvar = { + .name = "sv_onrecordfinish", + .description = + "FIXME", + .default_value = "", + .flags = CVAR_NONE, + .value = { .type = 0, .value = &sv_onrecordfinish }, +}; +static char *sv_ondemoremove; +static cvar_t sv_ondemoremove_cvar = { + .name = "sv_ondemoremove", + .description = + "FIXME", + .default_value = "", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &sv_ondemoremove }, +}; +static int sv_demotxt; +static cvar_t sv_demotxt_cvar = { + .name = "sv_demotxt", + .description = + "FIXME", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sv_demotxt }, +}; +static char *serverdemo; +static cvar_t serverdemo_cvar = { + .name = "serverdemo", + .description = + "FIXME", + .default_value = "", + .flags = CVAR_SERVERINFO, + .value = { .type = 0, .value = &serverdemo }, +}; static int (*dwrite) (QFile * file, const void *buf, int count); @@ -113,10 +225,10 @@ demo_frame (void *unused) { double min_fps; - if (!sv_demofps->value) + if (!sv_demofps) min_fps = 20.0; else - min_fps = sv_demofps->value; + min_fps = sv_demofps; min_fps = max (4, min_fps); if (sv.time - demo_time < 1.0 / min_fps) return 0; @@ -177,13 +289,13 @@ SV_Stop (int reason) break; } /* - if (sv_onrecordfinish->string[0]) { + if (sv_onrecordfinish[0]) { extern redirect_t sv_redirected; int old = sv_redirected; char path[MAX_OSPATH]; char *p; - if ((p = strstr (sv_onrecordfinish->string, " ")) != NULL) + if ((p = strstr (sv_onrecordfinish, " ")) != NULL) *p = 0; // strip parameters strcpy (path, demo_name->str); @@ -192,8 +304,8 @@ SV_Stop (int reason) sv_redirected = RD_NONE; // onrecord script is called always // from the console Cmd_TokenizeString (va (0, "script %s \"%s\" \"%s\" \"%s\" %s", - sv_onrecordfinish->string, demo.path->str, - serverdemo->string, + sv_onrecordfinish, demo.path->str, + serverdemo, path, p != NULL ? p + 1 : "")); if (p) *p = ' '; @@ -202,7 +314,7 @@ SV_Stop (int reason) sv_redirected = old; } */ - Cvar_Set (serverdemo, ""); + Cvar_Set ("serverdemo", ""); } static void @@ -327,7 +439,7 @@ SV_PrintTeams (void) if (numcl == 2) { // duel dsprintf (buffer, "team1 %s\nteam2 %s\n", clients[0]->name, clients[1]->name); - } else if (!teamplay->int_val) { // ffa + } else if (!teamplay) { // ffa dsprintf (buffer, "players:\n"); for (i = 0; i < numcl; i++) dasprintf (buffer, " %s\n", clients[i]->name); @@ -373,12 +485,12 @@ SV_Record (char *name) SV_BroadcastPrintf (PRINT_CHAT, "Server started recording (%s):\n%s\n", demo_disk ? "disk" : "memory", QFS_SkipPath (demo_name->str)); - Cvar_Set (serverdemo, demo_name->str); + Cvar_Set ("serverdemo", demo_name->str); dstring_copystr (demo_text, name); strcpy (demo_text->str + strlen (demo_text->str) - 3, "txt"); - if (sv_demotxt->int_val) { + if (sv_demotxt) { QFile *f; f = QFS_Open (demo_text->str, "w+t"); @@ -390,8 +502,8 @@ SV_Record (char *name) strftime (date, sizeof (date), "%Y-%m-%d-%H-%M", localtime (&tim)); Qprintf (f, "date %s\nmap %s\nteamplay %d\ndeathmatch %d\n" "timelimit %d\n%s", - date, sv.name, teamplay->int_val, - deathmatch->int_val, timelimit->int_val, + date, sv.name, teamplay, + deathmatch, timelimit, SV_PrintTeams ()); Qclose (f); } @@ -629,9 +741,9 @@ SV_Record_f (void) if (recorder) SV_Stop (0); - dsprintf (name, "%s/%s/%s%s%s", qfs_gamedir->dir.def, sv_demoDir->string, - sv_demoPrefix->string, SV_CleanName (Cmd_Argv (1)), - sv_demoSuffix->string); + dsprintf (name, "%s/%s/%s%s%s", qfs_gamedir->dir.def, sv_demoDir, + sv_demoPrefix, SV_CleanName (Cmd_Argv (1)), + sv_demoSuffix); // open the demo file QFS_DefaultExtension (name, ".mvd"); @@ -733,7 +845,7 @@ SV_EasyRecord_f (void) else { // guess game type and write demo name i = Dem_CountPlayers (); - if (teamplay->int_val && i > 2) { + if (teamplay && i > 2) { // Teamplay dsprintf (name, "team_%s_vs_%s_%s", Dem_Team (1), Dem_Team (2), sv.name); @@ -751,10 +863,10 @@ SV_EasyRecord_f (void) // Make sure the filename doesn't contain illegal characters dsprintf (name2, "%s/%s%s%s%s%s", - qfs_gamedir->dir.def, sv_demoDir->string, - sv_demoDir->string[0] ? "/" : "", - sv_demoPrefix->string, SV_CleanName (name->str), - sv_demoSuffix->string); + qfs_gamedir->dir.def, sv_demoDir, + sv_demoDir[0] ? "/" : "", + sv_demoPrefix, SV_CleanName (name->str), + sv_demoSuffix); if ((demo_file = QFS_NextFile (name, name2->str, ".mvd"))) { SV_Record (name->str); @@ -790,25 +902,21 @@ Demo_Init (void) svs.demomem = Hunk_AllocName (0, size, "demo"); svs.demomemsize = size; demo_max_size = size - 0x80000; - - serverdemo = Cvar_Get ("serverdemo", "", CVAR_SERVERINFO, Cvar_Info, - "FIXME"); - sv_demofps = Cvar_Get ("sv_demofps", "20", CVAR_NONE, 0, "FIXME"); - sv_demoPings = Cvar_Get ("sv_demoPings", "3", CVAR_NONE, 0, "FIXME"); - sv_demoNoVis = Cvar_Get ("sv_demoNoVis", "1", CVAR_NONE, 0, "FIXME"); - sv_demoUseCache = Cvar_Get ("sv_demoUseCache", "0", CVAR_NONE, 0, "FIXME"); - sv_demoCacheSize = Cvar_Get ("sv_demoCacheSize", va (0, "%d", size / 1024), - CVAR_ROM, 0, "FIXME"); - sv_demoMaxSize = Cvar_Get ("sv_demoMaxSize", "20480", CVAR_NONE, 0, - "FIXME"); - sv_demoMaxDirSize = Cvar_Get ("sv_demoMaxDirSize", "102400", CVAR_NONE, 0, - "FIXME"); - sv_demoDir = Cvar_Get ("sv_demoDir", "demos", CVAR_NONE, 0, "FIXME"); - sv_demoPrefix = Cvar_Get ("sv_demoPrefix", "", CVAR_NONE, 0, "FIXME"); - sv_demoSuffix = Cvar_Get ("sv_demoSuffix", "", CVAR_NONE, 0, "FIXME"); - sv_onrecordfinish = Cvar_Get ("sv_onrecordfinish", "", CVAR_NONE, 0, "FIXME"); - sv_ondemoremove = Cvar_Get ("sv_ondemoremove", "", CVAR_NONE, 0, "FIXME"); - sv_demotxt = Cvar_Get ("sv_demotxt", "1", CVAR_NONE, 0, "FIXME"); + sv_demoCacheSize_cvar.default_value = nva ("%d", size / 1024); + Cvar_Register (&serverdemo_cvar, Cvar_Info, &serverdemo); + Cvar_Register (&sv_demofps_cvar, 0, 0); + Cvar_Register (&sv_demoPings_cvar, 0, 0); + Cvar_Register (&sv_demoNoVis_cvar, 0, 0); + Cvar_Register (&sv_demoUseCache_cvar, 0, 0); + Cvar_Register (&sv_demoCacheSize_cvar, 0, 0); + Cvar_Register (&sv_demoMaxSize_cvar, 0, 0); + Cvar_Register (&sv_demoMaxDirSize_cvar, 0, 0); + Cvar_Register (&sv_demoDir_cvar, 0, 0); + Cvar_Register (&sv_demoPrefix_cvar, 0, 0); + Cvar_Register (&sv_demoSuffix_cvar, 0, 0); + Cvar_Register (&sv_onrecordfinish_cvar, 0, 0); + Cvar_Register (&sv_ondemoremove_cvar, 0, 0); + Cvar_Register (&sv_demotxt_cvar, 0, 0); Cmd_AddCommand ("record", SV_Record_f, "FIXME"); Cmd_AddCommand ("easyrecord", SV_EasyRecord_f, "FIXME"); diff --git a/qw/source/sv_init.c b/qw/source/sv_init.c index 6f0d9753f..29ba96c5a 100644 --- a/qw/source/sv_init.c +++ b/qw/source/sv_init.c @@ -377,7 +377,7 @@ SV_SpawnServer (const char *server) SV_FreeAllEdictLeafs (); SV_SetupUserCommands (); Info_SetValueForStarKey (svs.info, "*progs", va (0, "%i", sv_pr_state.crc), - !sv_highchars->int_val); + !sv_highchars); // leave slots at start for only clients sv.num_edicts = MAX_CLIENTS + 1; @@ -468,7 +468,7 @@ SV_SpawnServer (const char *server) SV_CreateBaseline (); sv.signon_buffer_size[sv.num_signon_buffers - 1] = sv.signon.cursize; - Info_SetValueForKey (svs.info, "map", sv.name, !sv_highchars->int_val); + Info_SetValueForKey (svs.info, "map", sv.name, !sv_highchars); Sys_MaskPrintf (SYS_dev, "Server spawned.\n"); if (sv_map_e->func) GIB_Event_Callback (sv_map_e, 1, server); @@ -477,14 +477,14 @@ SV_SpawnServer (const char *server) void SV_SetMoveVars (void) { - movevars.gravity = sv_gravity->value; - movevars.stopspeed = sv_stopspeed->value; - movevars.maxspeed = sv_maxspeed->value; - movevars.spectatormaxspeed = sv_spectatormaxspeed->value; - movevars.accelerate = sv_accelerate->value; - movevars.airaccelerate = sv_airaccelerate->value; - movevars.wateraccelerate = sv_wateraccelerate->value; - movevars.friction = sv_friction->value; - movevars.waterfriction = sv_waterfriction->value; + movevars.gravity = sv_gravity; + movevars.stopspeed = sv_stopspeed; + movevars.maxspeed = sv_maxspeed; + movevars.spectatormaxspeed = sv_spectatormaxspeed; + movevars.accelerate = sv_accelerate; + movevars.airaccelerate = sv_airaccelerate; + movevars.wateraccelerate = sv_wateraccelerate; + movevars.friction = sv_friction; + movevars.waterfriction = sv_waterfriction; movevars.entgravity = 1.0; } diff --git a/qw/source/sv_main.c b/qw/source/sv_main.c index 1d81ff1af..651bb8ccf 100644 --- a/qw/source/sv_main.c +++ b/qw/source/sv_main.c @@ -122,74 +122,390 @@ qboolean rcon_from_user; double netdosexpire[DOSFLOODCMDS] = { 1, 1, 2, 0.9, 1, 5 }; double netdosvalues[DOSFLOODCMDS] = { 12, 1, 3, 1, 1, 1 }; -cvar_t *sv_mem_size; +float sv_mem_size; +static cvar_t sv_mem_size_cvar = { + .name = "sv_mem_size", + .description = + "Amount of memory (in MB) to allocate for the " + PACKAGE_NAME + " heap", + .default_value = "8", + .flags = CVAR_ROM, + .value = { .type = &cexpr_float, .value = &sv_mem_size }, +}; -cvar_t *sv_console_plugin; +char *sv_console_plugin; +static cvar_t sv_console_plugin_cvar = { + .name = "sv_console_plugin", + .description = + "Plugin used for the console", + .default_value = "server", + .flags = CVAR_ROM, + .value = { .type = 0, .value = &sv_console_plugin }, +}; -cvar_t *sv_allow_status; -cvar_t *sv_allow_log; -cvar_t *sv_allow_ping; +int sv_allow_status; +static cvar_t sv_allow_status_cvar = { + .name = "sv_allow_status", + .description = + "Allow remote status queries (qstat etc)", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sv_allow_status }, +}; +int sv_allow_log; +static cvar_t sv_allow_log_cvar = { + .name = "sv_allow_log", + .description = + "Allow remote logging", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sv_allow_log }, +}; +int sv_allow_ping; +static cvar_t sv_allow_ping_cvar = { + .name = "sv_allow_pings", + .description = + "Allow remote pings (qstat etc)", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sv_allow_ping }, +}; -cvar_t *sv_extensions; // Use the extended protocols +int sv_extensions; +static cvar_t sv_extensions_cvar = { + .name = "sv_extensions", + .description = + "Use protocol extensions for QuakeForge clients", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sv_extensions }, +}; -cvar_t *sv_mintic; // bound the size of the -cvar_t *sv_maxtic; // physics time tic +float sv_mintic; +static cvar_t sv_mintic_cvar = { + .name = "sv_mintic", + .description = + "The minimum amount of time the server will wait before sending " + "packets to a client. Set to .5 to make modem users happy", + .default_value = "0.03", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &sv_mintic }, +}; +float sv_maxtic; +static cvar_t sv_maxtic_cvar = { + .name = "sv_maxtic", + .description = + "The maximum amount of time in seconds before a client a receives an " + "update from the server", + .default_value = "0.1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &sv_maxtic }, +}; -cvar_t *sv_netdosprotect; // tone down DoS from quake servers +int sv_netdosprotect; +static cvar_t sv_netdosprotect_cvar = { + .name = "sv_netdosprotect", + .description = + "DoS flood attack protection", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sv_netdosprotect }, +}; -cvar_t *sv_timeout; // seconds without any message -cvar_t *zombietime; // seconds to sink messages after +float sv_timeout; +static cvar_t sv_timeout_cvar = { + .name = "timeout", + .description = + "Sets the amount of time in seconds before a client is considered " + "disconnected if the server does not receive a packet", + .default_value = "65", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &sv_timeout }, +}; +float zombietime; +static cvar_t zombietime_cvar = { + .name = "zombietime", + .description = + "The number of seconds that the server will keep the character of a " + "player on the map who seems to have disconnected", + .default_value = "2", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &zombietime }, +}; // disconnect -cvar_t *rcon_password; // password for remote server -cvar_t *admin_password; // password for admin commands +char *rcon_password; +static cvar_t rcon_password_cvar = { + .name = "rcon_password", + .description = + "Set the password for rcon 'root' commands", + .default_value = "", + .flags = CVAR_NONE, + .value = { .type = 0, .value = &rcon_password }, +}; +char *admin_password; +static cvar_t admin_password_cvar = { + .name = "admin_password", + .description = + "Set the password for rcon admin commands", + .default_value = "", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &admin_password }, +}; -cvar_t *password; // password for entering the game -cvar_t *spectator_password; // password for entering as a +char *password; +static cvar_t password_cvar = { + .name = "password", + .description = + "Set the server password for players", + .default_value = "", + .flags = CVAR_NONE, + .value = { .type = 0, .value = &password }, +}; +char *spectator_password; +static cvar_t spectator_password_cvar = { + .name = "spectator_password", + .description = + "Set the spectator password", + .default_value = "", + .flags = CVAR_NONE, + .value = { .type = 0, .value = &spectator_password }, +}; // spectator -cvar_t *allow_download; -cvar_t *allow_download_skins; -cvar_t *allow_download_models; -cvar_t *allow_download_sounds; -cvar_t *allow_download_maps; -cvar_t *allow_download_demos; +int allow_download; +static cvar_t allow_download_cvar = { + .name = "allow_download", + .description = + "Toggle if clients can download game data from the server", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &allow_download }, +}; +int allow_download_skins; +static cvar_t allow_download_skins_cvar = { + .name = "allow_download_skins", + .description = + "Toggle if clients can download skins from the server", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &allow_download_skins }, +}; +int allow_download_models; +static cvar_t allow_download_models_cvar = { + .name = "allow_download_models", + .description = + "Toggle if clients can download models from the server", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &allow_download_models }, +}; +int allow_download_sounds; +static cvar_t allow_download_sounds_cvar = { + .name = "allow_download_sounds", + .description = + "Toggle if clients can download sounds from the server", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &allow_download_sounds }, +}; +int allow_download_maps; +static cvar_t allow_download_maps_cvar = { + .name = "allow_download_maps", + .description = + "Toggle if clients can download maps from the server", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &allow_download_maps }, +}; +char *allow_download_demos; +static cvar_t allow_download_demos_cvar = { + .name = "allow_download_demos", + .description = + "Toggle if clients can download maps from the server", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &allow_download_demos }, +}; -cvar_t *sv_highchars; -cvar_t *sv_phs; +int sv_highchars; +static cvar_t sv_highchars_cvar = { + .name = "sv_highchars", + .description = + "Toggle the use of high character color names for players", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sv_highchars }, +}; +int sv_phs; +static cvar_t sv_phs_cvar = { + .name = "sv_phs", + .description = + "Possibly Hearable Set. If set to zero, the server calculates sound " + "hearability in realtime", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sv_phs }, +}; -cvar_t *pausable; +int pausable; +static cvar_t pausable_cvar = { + .name = "pausable", + .description = + "None", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &pausable }, +}; -cvar_t *sv_minqfversion; // Minimum QF version allowed to +char *sv_minqfversion; +static cvar_t sv_minqfversion_cvar = { + .name = "sv_minqfversion", + .description = + "Minimum QF version on client", + .default_value = "0", + .flags = CVAR_SERVERINFO, + .value = { .type = 0, .value = &sv_minqfversion }, +}; // connect -cvar_t *sv_maxrate; // Maximum allowable rate (silently - // capped) -cvar_t *sv_timestamps; -cvar_t *sv_timefmt; +int sv_timestamps; +static cvar_t sv_timestamps_cvar = { + .name = "sv_timestamps", + .description = + "Time/date stamps in log entries", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sv_timestamps }, +}; +char *sv_timefmt; +static cvar_t sv_timefmt_cvar = { + .name = "sv_timefmt", + .description = + "Time/date format to use", + .default_value = "[%b %e %X] ", + .flags = CVAR_NONE, + .value = { .type = 0, .value = &sv_timefmt }, +}; // game rules mirrored in svs.info -cvar_t *fraglimit; -cvar_t *timelimit; -cvar_t *teamplay; -cvar_t *samelevel; -cvar_t *maxclients; -cvar_t *maxspectators; -cvar_t *deathmatch; // 0, 1, or 2 -cvar_t *coop; -cvar_t *skill; -cvar_t *spawn; -cvar_t *watervis; +char *fraglimit; +static cvar_t fraglimit_cvar = { + .name = "fraglimit", + .description = + "None", + .default_value = "0", + .flags = CVAR_SERVERINFO, + .value = { .type = 0/* not used */, .value = &fraglimit }, +}; +int timelimit; +static cvar_t timelimit_cvar = { + .name = "timelimit", + .description = + "None", + .default_value = "0", + .flags = CVAR_SERVERINFO, + .value = { .type = &cexpr_int, .value = &timelimit }, +}; +int teamplay; +static cvar_t teamplay_cvar = { + .name = "teamplay", + .description = + "None", + .default_value = "0", + .flags = CVAR_SERVERINFO, + .value = { .type = &cexpr_int, .value = &teamplay }, +}; +char *samelevel; +static cvar_t samelevel_cvar = { + .name = "samelevel", + .description = + "None", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = 0/* not used */, .value = &samelevel }, +}; +int maxclients; +static cvar_t maxclients_cvar = { + .name = "maxclients", + .description = + "Sets how many clients can connect to your server, this includes " + "spectators and players", + .default_value = "8", + .flags = CVAR_SERVERINFO, + .value = { .type = &cexpr_int, .value = &maxclients }, +}; +int maxspectators; +static cvar_t maxspectators_cvar = { + .name = "maxspectators", + .description = + "Sets how many spectators can connect to your server. The maxclients " + "value takes precedence over this value so this value should always be" + " equal-to or less-then the maxclients value", + .default_value = "8", + .flags = CVAR_SERVERINFO, + .value = { .type = &cexpr_int, .value = &maxspectators }, +}; +int deathmatch; +static cvar_t deathmatch_cvar = { + .name = "deathmatch", + .description = + "0, 1, or 2", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &deathmatch }, +}; +int coop; +static cvar_t coop_cvar = { + .name = "coop", + .description = + "0 or 1", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &coop }, +}; +int skill; +static cvar_t skill_cvar = { + .name = "skill", + .description = + "0 - 3", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &skill }, +}; +char *spawn; +static cvar_t spawn_cvar = { + .name = "spawn", + .description = + "Spawn the player entity", + .default_value = "0", + .flags = CVAR_SERVERINFO, + .value = { .type = 0/* not used */, .value = &spawn }, +}; +char *watervis; +static cvar_t watervis_cvar = { + .name = "watervis", + .description = + "Set nonzero to enable r_wateralpha on clients", + .default_value = "0", + .flags = CVAR_SERVERINFO, + .value = { .type = 0/* not used */, .value = &watervis }, +}; -cvar_t *hostname; +char *hostname; +static cvar_t hostname_cvar = { + .name = "hostname", + .description = + "None", + .default_value = "UNNAMED", + .flags = CVAR_NONE, + .value = { .type = 0, .value = &hostname }, +}; QFile *sv_fraglogfile; -cvar_t *pr_gc; -cvar_t *pr_gc_interval; -int pr_gc_count = 0; - int sv_net_initialized; const char *client_info_filters[] = { // Info keys needed by client @@ -479,7 +795,7 @@ CheckForFlood (flood_enum_t cmdtype) int oldest, i; static qboolean firsttime = true; - if (!sv_netdosprotect->int_val) + if (!sv_netdosprotect) return 0; oldestTime = 0x7fffffff; @@ -545,7 +861,7 @@ SVC_Status (void) client_t *cl; int ping, bottom, top, i; - if (!sv_allow_status->int_val) + if (!sv_allow_status) return; if (CheckForFlood (FLOOD_STATUS)) return; @@ -610,7 +926,7 @@ SVC_Log (void) char data[MAX_DATAGRAM + 64]; int seq; - if (!sv_allow_log->int_val) + if (!sv_allow_log) return; if (CheckForFlood (FLOOD_LOG)) return; @@ -650,7 +966,7 @@ SVC_Ping (void) { char data; - if (!sv_allow_ping->int_val) + if (!sv_allow_ping) return; if (CheckForFlood (FLOOD_PING)) return; @@ -696,7 +1012,7 @@ SVC_GetChallenge (void) i = oldest; } - if (sv_extensions->int_val) { + if (sv_extensions) { extended = " QF qtv EXT"; } @@ -730,8 +1046,8 @@ SV_AllocClient (int spectator, int server) // if at server limits, refuse connection if (!free || - (!server && ((spectator && spectators >= maxspectators->int_val) - || (!spectator && clients >= maxclients->int_val)))) { + (!server && ((spectator && spectators >= maxspectators) + || (!spectator && clients >= maxclients)))) { return 0; } // find a client slot @@ -789,7 +1105,7 @@ SVC_DirectConnect (void) if (strlen (Cmd_Argv (4)) < MAX_INFO_STRING) userinfo = Info_ParseString (Cmd_Argv (4), 1023, - !sv_highchars->int_val); + !sv_highchars); // Validate the userinfo string. if (!userinfo) { @@ -819,25 +1135,25 @@ SVC_DirectConnect (void) } s = Info_ValueForKey (userinfo, "*qf_version"); - if ((!s[0]) || sv_minqfversion->string[0]) { // kick old clients? - if (ver_compare (s, sv_minqfversion->string) < 0) { + if ((!s[0]) || sv_minqfversion[0]) { // kick old clients? + if (ver_compare (s, sv_minqfversion) < 0) { SV_Printf ("%s: Version %s is less than minimum version %s.\n", NET_AdrToString (net_from), s, - sv_minqfversion->string); + sv_minqfversion); SV_OutOfBandPrint (net_from, "%c\nserver requires QuakeForge " "v%s or greater. Get it from " "http://www.quakeforge.net/\n", A2C_PRINT, - sv_minqfversion->string); + sv_minqfversion); return; } } // check for password or spectator_password s = Info_ValueForKey (userinfo, "spectator"); if (s[0] && strcmp (s, "0")) { - if (spectator_password->string[0] && - !strcaseequal (spectator_password->string, "none") && - !strequal (spectator_password->string, s)) { // failed + if (spectator_password[0] && + !strcaseequal (spectator_password, "none") && + !strequal (spectator_password, s)) { // failed SV_Printf ("%s: spectator password failed\n", NET_AdrToString (net_from)); SV_OutOfBandPrint (net_from, @@ -847,13 +1163,13 @@ SVC_DirectConnect (void) } Info_RemoveKey (userinfo, "spectator"); // remove passwd Info_SetValueForStarKey (userinfo, "*spectator", "1", - !sv_highchars->int_val); + !sv_highchars); spectator = true; } else { s = Info_ValueForKey (userinfo, "password"); - if (password->string[0] - && !strcaseequal (password->string, "none") - && !strequal (password->string, s)) { + if (password[0] + && !strcaseequal (password, "none") + && !strequal (password, s)) { SV_Printf ("%s:password failed\n", NET_AdrToString (net_from)); SV_OutOfBandPrint (net_from, "%c\nserver requires a password\n\n", @@ -948,12 +1264,12 @@ SVC_DirectConnect (void) } static int -Rcon_Validate (cvar_t *pass) +Rcon_Validate (const char *pass) { - if (!strlen (pass->string)) + if (!strlen (pass)) return 0; - if (strcmp (Cmd_Argv (1), pass->string)) + if (strcmp (Cmd_Argv (1), pass)) return 0; return 1; @@ -1146,8 +1462,28 @@ typedef struct { #define MAX_IPFILTERS 1024 -cvar_t *filterban; -cvar_t *sv_filter_automask; +int filterban; +static cvar_t filterban_cvar = { + .name = "filterban", + .description = + "Determines the rules for the IP list 0 Only IP addresses on the Ban " + "list will be allowed onto the server, 1 Only IP addresses NOT on the " + "Ban list will be allowed onto the server", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &filterban }, +}; +int sv_filter_automask; +static cvar_t sv_filter_automask_cvar = { + .name = "sv_filter_automask", + .description = + "Automatically determine the mask length when it is not explicitely " + "given. e.g. \"addip 1.2.0.0\" would be the same as \"addip " + "1.2.0.0/16\"", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sv_filter_automask }, +}; int numipfilters; ipfilter_t ipfilters[MAX_IPFILTERS]; unsigned int ipmasks[33]; // network byte order @@ -1314,7 +1650,7 @@ SV_StringToFilter (const char *address, ipfilter_t *f) // change trailing 0 segments to be a mask, eg 1.2.0.0 gives a /16 mask if (mask == -1) { - if (sv_filter_automask->int_val) { + if (sv_filter_automask) { mask = sizeof (b) * 8; i = sizeof (b); while (i > 0 && !b[i - 1]) { @@ -1563,7 +1899,7 @@ SV_netDoSexpire_f (void) for (i = 0; i < DOSFLOODCMDS; i++) SV_Printf ("%f ", netdosexpire[i]); SV_Printf ("\n"); - if (!sv_netdosprotect->int_val) + if (!sv_netdosprotect) SV_Printf ("(disabled)\n"); return; } @@ -1592,7 +1928,7 @@ SV_netDoSvalues_f (void) for (i = 0; i < DOSFLOODCMDS; i++) SV_Printf ("%f ", netdosvalues[i]); SV_Printf ("\n"); - if (!sv_netdosprotect->int_val) + if (!sv_netdosprotect) SV_Printf ("(disabled)\n"); return; } @@ -1611,33 +1947,6 @@ SV_netDoSvalues_f (void) return; } -static void -SV_MaxRate_f (cvar_t *var) -{ - client_t *cl; - int maxrate = var->int_val; - int i, rate = 2500; - const char *val; - - Cvar_Info (var); - for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) { - if (!cl->userinfo) - continue; - val = Info_ValueForKey (cl->userinfo, "rate"); - if (strlen (val)) { - rate = atoi (val); - - if (maxrate) { - rate = bound (500, rate, maxrate); - } else { - rate = max (500, rate); - } - cl->netchan.rate = 1.0 / rate; - } - SV_ClientPrintf (1, cl, PRINT_HIGH, "Net rate set to %i\n", rate); - } -} - static void SV_SendBan (double till) { @@ -1680,7 +1989,7 @@ SV_FilterIP (byte *ip, double *until) if (SV_MaskIPCompare (ip, ipfilters[i].ip, ipfilters[i].mask)) { if (!ipfilters[i].time) { // normal ban - return filterban->int_val; + return filterban; } else if (ipfilters[i].time > realtime) { *until = ipfilters[i].time; return true; // banned no matter what @@ -1691,7 +2000,7 @@ SV_FilterIP (byte *ip, double *until) } } } - return !filterban->int_val; + return !filterban; } void @@ -1746,7 +2055,7 @@ SV_RestorePenaltyFilter (client_t *cl, filtertype_t type) void SV_OutOfBand (netadr_t adr, unsigned length, byte *data) { - if (net_packetlog->int_val) { + if (net_packetlog) { Log_Outgoing_Packet (data, length, 0); } Netchan_OutOfBand (adr, length, data); @@ -1779,7 +2088,7 @@ SV_ReadPackets (void) double until; while (NET_GetPacket ()) { - if (net_packetlog->int_val) + if (net_packetlog) Log_Incoming_Packet (net_message->message->data, net_message->message->cursize, 1); if (SV_FilterIP (net_from.ip, &until)) { @@ -1857,7 +2166,7 @@ SV_CheckTimeouts (void) float droptime; int nclients, i; - droptime = realtime - sv_timeout->value; + droptime = realtime - sv_timeout; nclients = 0; for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) { @@ -1872,7 +2181,7 @@ SV_CheckTimeouts (void) } } if (cl->state == cs_zombie && - realtime - cl->connection_started > zombietime->value) { + realtime - cl->connection_started > zombietime) { cl->state = cs_free; // can now be reused svs.num_clients--; } @@ -1893,10 +2202,10 @@ SV_CheckVars (void) static char const *pw, *spw; int v; - if (password->string == pw && spectator_password->string == spw) + if (password == pw && spectator_password == spw) return; - pw = password->string; - spw = spectator_password->string; + pw = password; + spw = spectator_password; v = 0; if (pw && pw[0] && strcmp (pw, "none")) @@ -1907,23 +2216,10 @@ SV_CheckVars (void) SV_Printf ("Updated needpass.\n"); if (!v) Info_SetValueForKey (svs.info, "needpass", "", - !sv_highchars->int_val); + !sv_highchars); else Info_SetValueForKey (svs.info, "needpass", va (0, "%i", v), - !sv_highchars->int_val); -} - -/* - SV_GarbageCollect - - Run string GC on progs every pr_gc_interval frames - - //snax: run QFobject GC as well -*/ -static void -SV_GarbageCollect (void) -{ - //Object_Garbage_Collect (); + !sv_highchars); } void @@ -1959,12 +2255,12 @@ SV_Frame (float time) // don't bother running a frame if sys_ticrate seconds haven't passed sv_frametime = sv.time - old_time; if (sv_frametime < 0) { - old_time = sv.time - sv_mintic->value; - sv_frametime = sv_mintic->value; + old_time = sv.time - sv_mintic; + sv_frametime = sv_mintic; } - if (sv_frametime >= sv_mintic->value) { - if (sv_frametime > sv_maxtic->value) - sv_frametime = sv_maxtic->value; + if (sv_frametime >= sv_mintic) { + if (sv_frametime > sv_maxtic) + sv_frametime = sv_maxtic; old_time = sv.time; *sv_globals.frametime = sv_frametime; @@ -2001,8 +2297,6 @@ SV_Frame (float time) // send a heartbeat to the master if needed Master_Heartbeat (); - SV_GarbageCollect (); - // collect timing statistics end = Sys_DoubleTime (); svs.stats.active += end - start; @@ -2021,34 +2315,26 @@ SV_Frame (float time) } static void -maxspectators_f (cvar_t *var) +maxspectators_f (void *data, const cvar_t *cvar) { - if (var->int_val > MAX_CLIENTS) - Cvar_SetValue (var, maxclients->int_val); - else if (var->int_val + maxclients->int_val > MAX_CLIENTS) - Cvar_SetValue (var, MAX_CLIENTS - maxclients->int_val); - else if (var->int_val < 0) - Cvar_SetValue (var, 0); - else if (var->int_val != var->value) - Cvar_SetValue (var, var->int_val); - else - Cvar_Info (var); + if (maxspectators > MAX_CLIENTS) + maxspectators = maxclients; + else if (maxspectators + maxclients > MAX_CLIENTS) + maxspectators = MAX_CLIENTS - maxclients; + else if (maxspectators < 0) + maxspectators = 0; + Cvar_Info (data, cvar); } static void -maxclients_f (cvar_t *var) +maxclients_f (void *data, const cvar_t *cvar) { - if (var->int_val > MAX_CLIENTS) - Cvar_SetValue (var, MAX_CLIENTS); - else if (var->int_val < 1) - Cvar_SetValue (var, 1); - else if (var->int_val != var->value) - Cvar_SetValue (var, var->int_val); - else { - Cvar_Info (var); - if (maxspectators) - maxspectators_f (maxspectators); - } + if (maxclients > MAX_CLIENTS) + maxclients = MAX_CLIENTS; + else if (maxclients < 1) + maxclients = 1; + Cvar_Info (data, cvar); + maxspectators_f (0, &maxspectators_cvar); } static void @@ -2070,172 +2356,45 @@ SV_InitLocal (void) SV_UserInit (); - rcon_password = Cvar_Get ("rcon_password", "", CVAR_NONE, NULL, "Set the " - "password for rcon 'root' commands"); - admin_password = Cvar_Get ("admin_password", "", CVAR_NONE, NULL, "Set " - "the password for rcon admin commands"); - password = Cvar_Get ("password", "", CVAR_NONE, NULL, "Set the server " - "password for players"); - spectator_password = Cvar_Get ("spectator_password", "", CVAR_NONE, NULL, - "Set the spectator password"); - sv_mintic = Cvar_Get ("sv_mintic", "0.03", CVAR_NONE, NULL, "The minimum " - "amount of time the server will wait before sending " - "packets to a client. Set to .5 to make modem users " - "happy"); - sv_maxtic = Cvar_Get ("sv_maxtic", "0.1", CVAR_NONE, NULL, "The maximum " - "amount of time in seconds before a client a " - "receives an update from the server"); - fraglimit = Cvar_Get ("fraglimit", "0", CVAR_SERVERINFO, Cvar_Info, - "Amount of frags a player must attain in order to " - "exit the level"); - timelimit = Cvar_Get ("timelimit", "0", CVAR_SERVERINFO, Cvar_Info, - "Sets the amount of time in minutes that is needed " - "before advancing to the next level"); - teamplay = Cvar_Get ("teamplay", "0", CVAR_SERVERINFO, Cvar_Info, - "Determines teamplay rules. 0 off, 1 You cannot hurt " - "yourself nor your teammates, 2 You can hurt " - "yourself, your teammates, and you will lose one " - "frag for killing a teammate, 3 You can hurt " - "yourself but you cannot hurt your teammates"); - samelevel = Cvar_Get ("samelevel", "0", CVAR_SERVERINFO, Cvar_Info, - "Determines the rules for level changing and " - "exiting. 0 Allows advancing to the next level," - "1 The same level will be played until someone " - "exits, 2 The same level will be played and the " - "exit will kill anybody that tries to exit, 3 The " - "same level will be played and the exit will kill " - "anybody that tries to exit, except on the Start " - "map."); - maxclients = Cvar_Get ("maxclients", "8", CVAR_SERVERINFO, maxclients_f, - "Sets how many clients can connect to your " - "server, this includes spectators and players"); - maxspectators = Cvar_Get ("maxspectators", "8", CVAR_SERVERINFO, - maxspectators_f, - "Sets how many spectators can connect to your " - "server. The maxclients value takes precedence " - "over this value so this value should always be " - "equal-to or less-then the maxclients value"); - hostname = Cvar_Get ("hostname", "unnamed", CVAR_SERVERINFO, Cvar_Info, - "Report or sets the server name"); - deathmatch = Cvar_Get ("deathmatch", "1", CVAR_SERVERINFO, Cvar_Info, - "Sets the rules for weapon and item respawning. " - "1 Does not leave weapons on the map. You can " - "pickup weapons and items and they will respawn, " - "2 Leaves weapons on the map. You can pick up a " - "weapon only once. Picked up items will not " - "respawn, 3 Leaves weapons on the map. You can " - "pick up a weapon only once. Picked up items will " - "respawn."); - coop = Cvar_Get ("coop", "0", CVAR_NONE, NULL, "co-op mode for progs that " - "support it"); - skill = Cvar_Get ("skill", "0", CVAR_NONE, NULL, "skill setting for progs " - "that support it"); - spawn = Cvar_Get ("spawn", "0", CVAR_SERVERINFO, Cvar_Info, - "Spawn the player entity"); - watervis = Cvar_Get ("watervis", "0", CVAR_SERVERINFO, Cvar_Info, - "Set nonzero to enable r_wateralpha on clients"); - sv_timeout = Cvar_Get ("timeout", "65", CVAR_NONE, NULL, "Sets the amount " - "of time in seconds before a client is considered " - "disconnected if the server does not receive a " - "packet"); - zombietime = Cvar_Get ("zombietime", "2", CVAR_NONE, NULL, "The number of " - "seconds that the server will keep the character " - "of a player on the map who seems to have " - "disconnected"); - sv_maxvelocity = Cvar_Get ("sv_maxvelocity", "2000", CVAR_NONE, NULL, - "Sets the maximum velocity an object can " - "travel"); - sv_extensions = Cvar_Get ("sv_extensions", "1", CVAR_NONE, NULL, - "Use protocol extensions for QuakeForge " - "clients"); - sv_gravity = Cvar_Get ("sv_gravity", "800", CVAR_NONE, NULL, - "Sets the global value for the amount of gravity"); - sv_jump_any = Cvar_Get ("sv_jump_any", "1", CVAR_NONE, NULL, "None"); - sv_stopspeed = Cvar_Get ("sv_stopspeed", "100", CVAR_NONE, NULL, - "Sets the value that determines how fast the " - "player should come to a complete stop"); - sv_maxspeed = Cvar_Get ("sv_maxspeed", "320", CVAR_NONE, NULL, - "Sets the maximum speed a player can move"); - sv_spectatormaxspeed = Cvar_Get ("sv_spectatormaxspeed", "500", CVAR_NONE, - NULL, "Sets the maximum speed a " - "spectator can move"); - sv_accelerate = Cvar_Get ("sv_accelerate", "10", CVAR_NONE, NULL, - "Sets the acceleration value for the players"); - sv_airaccelerate = Cvar_Get ("sv_airaccelerate", "0.7", CVAR_NONE, NULL, - "Sets how quickly the players accelerate in " - "air"); - sv_wateraccelerate = Cvar_Get ("sv_wateraccelerate", "10", CVAR_NONE, NULL, - "Sets the water acceleration value"); - sv_friction = Cvar_Get ("sv_friction", "4", CVAR_NONE, NULL, - "Sets the friction value for the players"); - sv_waterfriction = Cvar_Get ("sv_waterfriction", "4", CVAR_NONE, NULL, - "Sets the water friction value"); - sv_aim = Cvar_Get ("sv_aim", "2", CVAR_NONE, NULL, - "Sets the value for auto-aiming leniency"); - sv_minqfversion = Cvar_Get ("sv_minqfversion", "0", CVAR_SERVERINFO, - Cvar_Info, "Minimum QF version on client"); - sv_maxrate = Cvar_Get ("sv_maxrate", "10000", CVAR_SERVERINFO, SV_MaxRate_f, - "Maximum allowable rate"); - sv_allow_log = Cvar_Get ("sv_allow_log", "1", CVAR_NONE, NULL, - "Allow remote logging"); - sv_allow_status = Cvar_Get ("sv_allow_status", "1", CVAR_NONE, NULL, - "Allow remote status queries (qstat etc)"); - sv_allow_ping = Cvar_Get ("sv_allow_pings", "1", CVAR_NONE, NULL, - "Allow remote pings (qstat etc)"); - sv_netdosprotect = Cvar_Get ("sv_netdosprotect", "0", CVAR_NONE, NULL, - "DoS flood attack protection"); - sv_timestamps = Cvar_Get ("sv_timestamps", "0", CVAR_NONE, NULL, - "Time/date stamps in log entries"); - sv_timefmt = Cvar_Get ("sv_timefmt", "[%b %e %X] ", CVAR_NONE, NULL, - "Time/date format to use"); - filterban = Cvar_Get ("filterban", "1", CVAR_NONE, NULL, - "Determines the rules for the IP list " - "0 Only IP addresses on the Ban list will be " - "allowed onto the server, 1 Only IP addresses NOT " - "on the Ban list will be allowed onto the server"); - sv_filter_automask = Cvar_Get ("sv_filter_automask", "1", CVAR_NONE, NULL, - "Automatically determine the mask length " - "when it is not explicitely given. e.g. " - "\"addip 1.2.0.0\" would be the same as " - "\"addip 1.2.0.0/16\""); - allow_download = Cvar_Get ("allow_download", "1", CVAR_NONE, NULL, - "Toggle if clients can download game data from " - "the server"); - allow_download_skins = Cvar_Get ("allow_download_skins", "1", CVAR_NONE, - NULL, "Toggle if clients can download " - "skins from the server"); - allow_download_models = Cvar_Get ("allow_download_models", "1", CVAR_NONE, - NULL, "Toggle if clients can download " - "models from the server"); - allow_download_sounds = Cvar_Get ("allow_download_sounds", "1", CVAR_NONE, - NULL, "Toggle if clients can download " - "sounds from the server"); - allow_download_maps = Cvar_Get ("allow_download_maps", "1", CVAR_NONE, - NULL, "Toggle if clients can download " - "maps from the server"); - allow_download_demos = Cvar_Get ("allow_download_demos", "1", CVAR_NONE, - NULL, "Toggle if clients can download " - "maps from the server"); - sv_highchars = Cvar_Get ("sv_highchars", "1", CVAR_NONE, NULL, - "Toggle the use of high character color names " - "for players"); - sv_phs = Cvar_Get ("sv_phs", "1", CVAR_NONE, NULL, "Possibly Hearable " - "Set. If set to zero, the server calculates sound " - "hearability in realtime"); - pausable = Cvar_Get ("pausable", "1", CVAR_NONE, NULL, - "Toggle if server can be paused 1 is on, 0 is off"); - pr_gc = Cvar_Get ("pr_gc", "2", CVAR_NONE, NULL, "Enable/disable the " - "garbage collector. 0 is off, 1 is on, 2 is auto (on " - "for newer qfcc progs, off otherwise)"); - pr_gc_interval = Cvar_Get ("pr_gc_interval", "50", CVAR_NONE, NULL, - "Number of frames to wait before running " - "string garbage collector."); - pr_double_remove = Cvar_Get ("pr_double_remove", "1", CVAR_NONE, NULL, - "Handling of double entity remove. " - "0 is silently ignore, 1 prints a " - "traceback, and 2 gives an error.\n" - "works Only if debugging is available " - "and enabled"); + Cvar_Register (&rcon_password_cvar, 0, 0); + Cvar_Register (&admin_password_cvar, 0, 0); + Cvar_Register (&password_cvar, 0, 0); + Cvar_Register (&spectator_password_cvar, 0, 0); + Cvar_Register (&sv_mintic_cvar, 0, 0); + Cvar_Register (&sv_maxtic_cvar, 0, 0); + Cvar_Register (&fraglimit_cvar, Cvar_Info, &fraglimit); + Cvar_Register (&timelimit_cvar, Cvar_Info, &timelimit); + Cvar_Register (&teamplay_cvar, Cvar_Info, &teamplay); + Cvar_Register (&samelevel_cvar, 0, 0); + Cvar_Register (&maxclients_cvar, maxclients_f, 0); + Cvar_Register (&maxspectators_cvar, maxspectators_f, 0); + Cvar_Register (&hostname_cvar, 0, 0); + Cvar_Register (&deathmatch_cvar, 0, 0); + Cvar_Register (&coop_cvar, 0, 0); + Cvar_Register (&skill_cvar, 0, 0); + Cvar_Register (&spawn_cvar, Cvar_Info, &spawn); + Cvar_Register (&watervis_cvar, Cvar_Info, &watervis); + Cvar_Register (&sv_timeout_cvar, 0, 0); + Cvar_Register (&zombietime_cvar, 0, 0); + Cvar_Register (&sv_extensions_cvar, 0, 0); + Cvar_Register (&sv_minqfversion_cvar, Cvar_Info, &sv_minqfversion); + Cvar_Register (&sv_allow_log_cvar, 0, 0); + Cvar_Register (&sv_allow_status_cvar, 0, 0); + Cvar_Register (&sv_allow_ping_cvar, 0, 0); + Cvar_Register (&sv_netdosprotect_cvar, 0, 0); + Cvar_Register (&sv_timestamps_cvar, 0, 0); + Cvar_Register (&sv_timefmt_cvar, 0, 0); + Cvar_Register (&filterban_cvar, 0, 0); + Cvar_Register (&sv_filter_automask_cvar, 0, 0); + Cvar_Register (&allow_download_cvar, 0, 0); + Cvar_Register (&allow_download_skins_cvar, 0, 0); + Cvar_Register (&allow_download_models_cvar, 0, 0); + Cvar_Register (&allow_download_sounds_cvar, 0, 0); + Cvar_Register (&allow_download_maps_cvar, 0, 0); + Cvar_Register (&allow_download_demos_cvar, 0, 0); + Cvar_Register (&sv_highchars_cvar, 0, 0); + Cvar_Register (&sv_phs_cvar, 0, 0); + Cvar_Register (&pausable_cvar, 0, 0); // DoS protection Cmd_AddCommand ("netdosexpire", SV_netDoSexpire_f, "FIXME: part of DoS " "protection obviously, but I don't know what it does. No " @@ -2257,13 +2416,13 @@ SV_InitLocal (void) snprintf (localmodels[i], sizeof (localmodels[i]), "*%i", i); Info_SetValueForStarKey (svs.info, "*version", QW_VERSION, - !sv_highchars->int_val); + !sv_highchars); // Brand server as QF, with appropriate QSG standards version --KB Info_SetValueForStarKey (svs.info, "*qf_version", PACKAGE_VERSION, - !sv_highchars->int_val); + !sv_highchars); Info_SetValueForStarKey (svs.info, "*qsg_version", QW_QSG_VERSION, - !sv_highchars->int_val); + !sv_highchars); CF_Init (); @@ -2386,7 +2545,7 @@ SV_ExtractFromUserinfo (client_t *cl) // set the name if (strcmp (newname, val) || strcmp (cl->name, newname)) { Info_SetValueForKey (cl->userinfo, "name", newname, - !sv_highchars->int_val); + !sv_highchars); val = Info_ValueForKey (cl->userinfo, "name"); SVstring (cl->edict, netname) = PR_SetString (&sv_pr_state, newname); @@ -2430,8 +2589,8 @@ SV_ExtractFromUserinfo (client_t *cl) if (strlen (val)) { i = atoi (val); - if (sv_maxrate->int_val) { - i = bound (500, i, sv_maxrate->int_val); + if (sv_maxrate) { + i = bound (500, i, sv_maxrate); } else { i = max (500, i); } @@ -2478,18 +2637,15 @@ SV_Init_Memory (void) size_t mem_size; void *mem_base; - sv_mem_size = Cvar_Get ("sv_mem_size", "8", CVAR_NONE, NULL, - "Amount of memory (in MB) to allocate for the " - PACKAGE_NAME " heap"); + Cvar_Register (&sv_mem_size_cvar, 0, 0); if (mem_parm) - Cvar_Set (sv_mem_size, com_argv[mem_parm + 1]); + Cvar_Set ("sv_mem_size", com_argv[mem_parm + 1]); if (COM_CheckParm ("-minmemory")) - Cvar_SetValue (sv_mem_size, MINIMUM_MEMORY / (1024 * 1024.0)); + sv_mem_size = MINIMUM_MEMORY / (1024 * 1024.0); - Cvar_SetFlags (sv_mem_size, sv_mem_size->flags | CVAR_ROM); - mem_size = ((size_t) sv_mem_size->value * 1024 * 1024); + mem_size = (size_t) (sv_mem_size * 1024 * 1024); if (mem_size < MINIMUM_MEMORY) Sys_Error ("Only %4.1f megs of memory reported, can't execute game", @@ -2515,7 +2671,7 @@ SV_Init (void) GIB_Init (true); COM_ParseConfig (sv_cbuf); - Cvar_Get ("cmd_warncmd", "1", CVAR_NONE, NULL, NULL); + cmd_warncmd = 1; // snax: Init experimental object system and run a test //Object_Init(); @@ -2532,10 +2688,9 @@ SV_Init (void) QFS_Init (hunk, "qw"); PI_Init (); - sv_console_plugin = Cvar_Get ("sv_console_plugin", "server", - CVAR_ROM, 0, "Plugin used for the console"); + Cvar_Register (&sv_console_plugin_cvar, 0, 0); PI_RegisterPlugins (server_plugin_list); - Con_Init (sv_console_plugin->string); + Con_Init (sv_console_plugin); if (con_module) con_module->data->console->cbuf = sv_cbuf; con_list_print = Sys_Printf; @@ -2574,7 +2729,7 @@ SV_Init (void) host_initialized = true; // SV_Printf ("Exe: "__TIME__" "__DATE__"\n"); - SV_Printf ("%4.1f megabyte heap\n", sv_mem_size->value); + SV_Printf ("%4.1f megabyte heap\n", sv_mem_size); SV_Printf ("\n"); SV_Printf ("%s server, Version %s (build %04d)\n", @@ -2585,7 +2740,7 @@ SV_Init (void) SV_Printf ("<==> %s initialized <==>\n", PACKAGE_NAME); // process command line arguments - Cmd_Exec_File (sv_cbuf, fs_usercfg->string, 0); + Cmd_Exec_File (sv_cbuf, fs_usercfg, 0); Cmd_StuffCmds (sv_cbuf); Cbuf_Execute_Stack (sv_cbuf); diff --git a/qw/source/sv_phys.c b/qw/source/sv_phys.c index 5e1122053..560e84ed9 100644 --- a/qw/source/sv_phys.c +++ b/qw/source/sv_phys.c @@ -53,11 +53,52 @@ solid_edge items clip against only bsp models. */ -cvar_t *sv_friction; -cvar_t *sv_gravity; -cvar_t *sv_jump_any; -cvar_t *sv_maxvelocity; -cvar_t *sv_stopspeed; +float sv_friction; +static cvar_t sv_friction_cvar = { + .name = "sv_friction", + .description = + "Sets the friction value for the players", + .default_value = "4", + .flags = CVAR_SERVERINFO, + .value = { .type = &cexpr_float, .value = &sv_friction }, +}; +float sv_gravity; +static cvar_t sv_gravity_cvar = { + .name = "sv_gravity", + .description = + "Sets the global value for the amount of gravity", + .default_value = "800", + .flags = CVAR_SERVERINFO, + .value = { .type = &cexpr_float, .value = &sv_gravity }, +}; +int sv_jump_any; +static cvar_t sv_jump_any_cvar = { + .name = "sv_jump_any", + .description = + "None", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sv_jump_any }, +}; +float sv_maxvelocity; +static cvar_t sv_maxvelocity_cvar = { + .name = "sv_maxvelocity", + .description = + "Sets the maximum velocity an object can travel", + .default_value = "2000", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &sv_maxvelocity }, +}; +float sv_stopspeed; +static cvar_t sv_stopspeed_cvar = { + .name = "sv_stopspeed", + .description = + "Sets the value that determines how fast the player should come to a " + "complete stop", + .default_value = "100", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &sv_stopspeed }, +}; #define MOVE_EPSILON 0.01 #if 0 @@ -106,8 +147,8 @@ SV_CheckVelocity (edict_t *ent) } #endif wishspeed = VectorLength (SVvector (ent, velocity)); - if (wishspeed > sv_maxvelocity->value) { - VectorScale (SVvector (ent, velocity), sv_maxvelocity->value / + if (wishspeed > sv_maxvelocity) { + VectorScale (SVvector (ent, velocity), sv_maxvelocity / wishspeed, SVvector (ent, velocity)); } } @@ -207,7 +248,7 @@ SV_EntCanSupportJump (edict_t *ent) int solid = SVfloat (ent, solid); if (solid == SOLID_BSP) return 1; - if (!sv_jump_any->int_val) + if (!sv_jump_any) return 0; if (solid == SOLID_NOT || solid == SOLID_SLIDEBOX) return 0; @@ -351,7 +392,7 @@ SV_AddGravity (edict_t *ent) ent_grav = SVfloat (ent, gravity); else ent_grav = 1.0; - SVvector (ent, velocity)[2] -= ent_grav * sv_gravity->value * sv_frametime; + SVvector (ent, velocity)[2] -= ent_grav * sv_gravity * sv_frametime; SVdata (ent)->add_grav = true; } @@ -364,7 +405,7 @@ SV_FinishGravity (edict_t *ent, vec3_t move) ent_grav = SVfloat (ent, gravity); else ent_grav = 1.0; - ent_grav *= sv_gravity->value; + ent_grav *= sv_gravity; move[2] += ent_grav * sv_frametime * sv_frametime / 2; } @@ -726,7 +767,7 @@ SV_Physics_Toss (edict_t *ent) } fl = 0; - if (sv_antilag->int_val == 2) + if (sv_antilag == 2) fl |= MOVE_LAGGED; trace = SV_PushEntity (ent, move, fl); if (trace.fraction == 1) @@ -776,7 +817,7 @@ SV_Physics_Step (edict_t *ent) // freefall if not on ground if (!((int) SVfloat (ent, flags) & (FL_ONGROUND | FL_FLY | FL_SWIM))) { - if (SVvector (ent, velocity)[2] < sv_gravity->value * -0.1) + if (SVvector (ent, velocity)[2] < sv_gravity * -0.1) hitsound = true; else hitsound = false; @@ -897,3 +938,13 @@ SV_Physics (void) PR_ExecuteProgram (&sv_pr_state, sv_funcs.EndFrame); } } + +void +SV_Physics_Init_Cvars (void) +{ + Cvar_Register (&sv_friction_cvar, Cvar_Info, &sv_friction); + Cvar_Register (&sv_gravity_cvar, Cvar_Info, &sv_gravity); + Cvar_Register (&sv_jump_any_cvar, 0, 0); + Cvar_Register (&sv_maxvelocity_cvar, 0, 0); + Cvar_Register (&sv_stopspeed_cvar, 0, 0); +} diff --git a/qw/source/sv_pr_cmds.c b/qw/source/sv_pr_cmds.c index 9eb50bca6..103b0a3a3 100644 --- a/qw/source/sv_pr_cmds.c +++ b/qw/source/sv_pr_cmds.c @@ -389,7 +389,7 @@ PF_traceline (progs_t *pr, void *data) nomonsters = P_FLOAT (pr, 2); ent = P_EDICT (pr, 3); - if (sv_antilag->int_val == 2) + if (sv_antilag == 2) nomonsters |= MOVE_LAGGED; trace = SV_Move (v1, vec3_origin, vec3_origin, v2, nomonsters, ent); @@ -692,8 +692,6 @@ PF_spawn (progs_t *pr, void *data) RETURN_EDICT (pr, ed); } -cvar_t *pr_double_remove; - // void (entity e) remove static void PF_remove (progs_t *pr, void *data) @@ -702,14 +700,14 @@ PF_remove (progs_t *pr, void *data) ed = P_EDICT (pr, 0); if (NUM_FOR_EDICT (pr, ed) < *pr->reserved_edicts) { - if (pr_double_remove->int_val == 1) { + if (pr_double_remove == 1) { PR_DumpState (pr); Sys_Printf ("Reserved entity remove\n"); } else // == 2 PR_RunError (pr, "Reserved entity remove\n"); } - if (ed->free && pr_double_remove->int_val) { - if (pr_double_remove->int_val == 1) { + if (ed->free && pr_double_remove) { + if (pr_double_remove == 1) { PR_DumpState (pr); Sys_Printf ("Double entity remove\n"); } else // == 2 @@ -922,8 +920,6 @@ PF_pointcontents (progs_t *pr, void *data) R_FLOAT (pr) = SV_PointContents (v); } -cvar_t *sv_aim; - /* PF_aim @@ -942,7 +938,7 @@ PF_aim (progs_t *pr, void *data) trace_t tr; vec3_t start, dir, end, bestdir; - if (sv_aim->value >= 1.0) { + if (sv_aim >= 1.0) { VectorCopy (*sv_globals.v_forward, R_VECTOR (pr)); return; } @@ -969,7 +965,7 @@ PF_aim (progs_t *pr, void *data) VectorMultAdd (start, 2048, dir, end); tr = SV_Move (start, vec3_origin, vec3_origin, end, false, ent); if (tr.ent && SVfloat (tr.ent, takedamage) == DAMAGE_AIM - && (!teamplay->int_val || SVfloat (ent, team) <= 0 + && (!teamplay || SVfloat (ent, team) <= 0 || SVfloat (ent, team) != SVfloat (tr.ent, team))) { VectorCopy (*sv_globals.v_forward, R_VECTOR (pr)); return; @@ -977,7 +973,7 @@ PF_aim (progs_t *pr, void *data) // try all possible entities VectorCopy (dir, bestdir); - bestdist = sv_aim->value; + bestdist = sv_aim; bestent = NULL; check = NEXT_EDICT (pr, sv.edicts); @@ -986,7 +982,7 @@ PF_aim (progs_t *pr, void *data) continue; if (check == ent) continue; - if (teamplay->int_val && SVfloat (ent, team) > 0 + if (teamplay && SVfloat (ent, team) > 0 && SVfloat (ent, team) == SVfloat (check, team)) continue; // don't aim at teammate @@ -1510,7 +1506,7 @@ PF_infokey (progs_t *pr, void *data) e1 = NUM_FOR_EDICT (pr, e); key = P_GSTRING (pr, 1); - if (sv_hide_version_info->int_val + if (sv_hide_version_info && (strequal (key, "*qf_version") || strequal (key, "*qsg_version") || strequal (key, "no_pogo_stick"))) { @@ -1836,11 +1832,11 @@ PF_sv_cvar (progs_t *pr, void *data) str = P_GSTRING (pr, 0); - if (sv_hide_version_info->int_val + if (sv_hide_version_info && strequal (str, "sv_hide_version_info")) { R_FLOAT (pr) = 0; } else { - R_FLOAT (pr) = Cvar_VariableValue (str); + R_FLOAT (pr) = Cvar_Value (str); } } @@ -1910,7 +1906,7 @@ PF_SV_SetUserinfo (progs_t *pr, void *data) if (entnum < 1 || entnum > MAX_CLIENTS || cl->state != cs_server) PR_RunError (pr, "not a server client"); - cl->userinfo = Info_ParseString (str, 1023, !sv_highchars->int_val); + cl->userinfo = Info_ParseString (str, 1023, !sv_highchars); cl->sendinfo = true; SV_ExtractFromUserinfo (cl); } diff --git a/qw/source/sv_pr_cpqw.c b/qw/source/sv_pr_cpqw.c index f75cddf98..6c72d90cc 100644 --- a/qw/source/sv_pr_cpqw.c +++ b/qw/source/sv_pr_cpqw.c @@ -752,7 +752,7 @@ PF_traceline (progs_t *pr, void *data) nomonsters = TL_ANY_SOLID; nomonsters = tl_to_move[nomonsters]; - if (sv_antilag->int_val == 2) + if (sv_antilag == 2) nomonsters |= MOVE_LAGGED; trace = SV_Move (v1, vec3_origin, vec3_origin, v2, nomonsters, ent); diff --git a/qw/source/sv_progs.c b/qw/source/sv_progs.c index 77d7898ff..fe95916b2 100644 --- a/qw/source/sv_progs.c +++ b/qw/source/sv_progs.c @@ -57,14 +57,100 @@ sv_fields_t sv_fields; edict_t sv_edicts[MAX_EDICTS]; sv_data_t sv_data[MAX_EDICTS]; -cvar_t *r_skyname; -cvar_t *sv_progs; -cvar_t *sv_progs_zone; -cvar_t *sv_progs_stack; -cvar_t *sv_progs_ext; -cvar_t *pr_checkextensions; -cvar_t *sv_old_entity_free; -cvar_t *sv_hide_version_info; +char *r_skyname; +static cvar_t r_skyname_cvar = { + .name = "r_skyname", + .description = + "name of the current skybox", + .default_value = "none", + .flags = CVAR_NONE, + .value = { .type = 0, .value = &r_skyname }, +}; +char *sv_progs; +static cvar_t sv_progs_cvar = { + .name = "sv_progs", + .description = + "Override the default game progs.", + .default_value = "", + .flags = CVAR_NONE, + .value = { .type = 0, .value = &sv_progs }, +}; +int sv_progs_zone; +static cvar_t sv_progs_zone_cvar = { + .name = "sv_progs_zone", + .description = + "size of the zone for progs in kb", + .default_value = "256", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sv_progs_zone }, +}; +int sv_progs_stack; +static cvar_t sv_progs_stack_cvar = { + .name = "sv_progs_stack", + .description = + "size of the stack for progs in kb", + .default_value = "256", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sv_progs_stack }, +}; +char *sv_progs_ext; +static cvar_t sv_progs_ext_cvar = { + .name = "sv_progs_ext", + .description = + "extention mapping to use: none, id, qf", + .default_value = "qf", + .flags = CVAR_NONE, + .value = { .type = 0, .value = &sv_progs_ext }, +}; +char *pr_checkextensions; +static cvar_t pr_checkextensions_cvar = { + .name = "pr_checkextensions", + .description = + "indicate the presence of the checkextentions qc function", + .default_value = "1", + .flags = CVAR_ROM, + .value = { .type = 0/* not used */, .value = &pr_checkextensions }, +}; +int sv_old_entity_free; +static cvar_t sv_old_entity_free_cvar = { + .name = "sv_old_entity_free", + .description = + "set this for buggy mods that rely on the old behaviour of entity " + "freeing (eg, *TF)", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sv_old_entity_free }, +}; +int sv_hide_version_info; +static cvar_t sv_hide_version_info_cvar = { + .name = "sv_hide_version_info", + .description = + "hide QuakeForge specific serverinfo strings from terminally stupid " + "progs (eg, braindead TF variants)", + .default_value = "0", + .flags = CVAR_ROM, + .value = { .type = &cexpr_int, .value = &sv_hide_version_info }, +}; +int pr_double_remove; +static cvar_t pr_double_remove_cvar = { + .name = "pr_double_remove", + .description = + "Handling of double entity remove. 0 is silently ignore, 1 prints a " + "traceback, and 2 gives an error.\nworks Only if debugging is " + "available and enabled", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &pr_double_remove }, +}; +float sv_aim; +static cvar_t sv_aim_cvar = { + .name = "sv_aim", + .description = + "None", + .default_value = "0.93", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &sv_aim }, +}; static pr_uint_t reserved_edicts = MAX_CLIENTS; @@ -94,7 +180,7 @@ bi_map (progs_t *pr, unsigned binum) static void free_edict (progs_t *pr, edict_t *ent) { - if (sv_old_entity_free->int_val) { + if (sv_old_entity_free) { E_fld (ent, sv_fields.model).entity_var = 0; E_fld (ent, sv_fields.takedamage).float_var = 0; E_fld (ent, sv_fields.modelindex).float_var = 0; @@ -118,7 +204,7 @@ prune_edict (progs_t *pr, edict_t *ent) return 1; } else { // remove things from different skill levels or deathmatch - if (deathmatch->int_val) { + if (deathmatch) { if (((int) SVfloat (ent, spawnflags) & SPAWNFLAG_NOT_DEATHMATCH)) { return 1; } @@ -526,17 +612,17 @@ SV_LoadProgs (void) const char *progs_name = "qwprogs.dat"; const char *range; - if (strequal (sv_progs_ext->string, "qf")) { + if (strequal (sv_progs_ext, "qf")) { sv_range = PR_RANGE_QF; range = "QF"; - } else if (strequal (sv_progs_ext->string, "id")) { + } else if (strequal (sv_progs_ext, "id")) { sv_range = PR_RANGE_ID; range = "ID"; - } else if (strequal (sv_progs_ext->string, "qwe") - || strequal (sv_progs_ext->string, "ktpro")) { + } else if (strequal (sv_progs_ext, "qwe") + || strequal (sv_progs_ext, "ktpro")) { sv_range = PR_RANGE_QWE; range = "QWE/KTPro"; - } else if (strequal (sv_progs_ext->string, "cpqw")) { + } else if (strequal (sv_progs_ext, "cpqw")) { sv_range = PR_RANGE_CPQW; range = "CPQW"; } else { @@ -548,20 +634,20 @@ SV_LoadProgs (void) memset (&sv_globals, 0, sizeof (sv_funcs)); memset (&sv_funcs, 0, sizeof (sv_funcs)); Info_RemoveKey (svs.info, "sky"); - if (*r_skyname->string) - Info_SetValueForKey (svs.info, "sky", r_skyname->string, 0); + if (*r_skyname) + Info_SetValueForKey (svs.info, "sky", r_skyname, 0); sv_cbuf->unknown_command = 0; ucmd_unknown = 0; if (qfs_gamedir->gamecode && *qfs_gamedir->gamecode) progs_name = qfs_gamedir->gamecode; - if (*sv_progs->string) - progs_name = sv_progs->string; + if (*sv_progs) + progs_name = sv_progs; sv_pr_state.max_edicts = MAX_EDICTS; - sv_pr_state.zone_size = sv_progs_zone->int_val * 1024; - sv_pr_state.stack_size = sv_progs_stack->int_val * 1024; + sv_pr_state.zone_size = sv_progs_zone * 1024; + sv_pr_state.stack_size = sv_progs_stack * 1024; sv.edicts = sv_edicts; PR_LoadProgs (&sv_pr_state, progs_name); @@ -610,27 +696,14 @@ SV_Progs_Init_Cvars (void) { PR_Init_Cvars (); - r_skyname = Cvar_Get ("r_skyname", "", CVAR_NONE, NULL, - "Default name of skybox if none given by map"); - sv_progs = Cvar_Get ("sv_progs", "", CVAR_NONE, NULL, - "Override the default game progs."); - sv_progs_zone = Cvar_Get ("sv_progs_zone", "256", CVAR_NONE, NULL, - "size of the zone for progs in kB"); - sv_progs_stack = Cvar_Get ("sv_progs_stack", "64", CVAR_NONE, NULL, - "size of the stack for progs in kB"); - sv_progs_ext = Cvar_Get ("sv_progs_ext", "qf", CVAR_NONE, NULL, - "extention mapping to use: " - "none, id, qf, qwe, ktpro, cpqw"); - pr_checkextensions = Cvar_Get ("pr_checkextensions", "1", CVAR_ROM, NULL, - "indicate the presence of the " - "checkextentions qc function"); - sv_old_entity_free = Cvar_Get ("sv_old_entity_free", "1", CVAR_NONE, NULL, - "set this for buggy mods that rely on the" - " old behaviour of entity freeing (eg," - " *TF)"); - sv_hide_version_info = Cvar_Get ("sv_hide_version_info", "0", CVAR_ROM, - NULL, "hide QuakeForge specific " - "serverinfo strings from terminally " - "stupid progs (eg, braindead TF " - "variants)"); + Cvar_Register (&r_skyname_cvar, 0, 0); + Cvar_Register (&sv_progs_cvar, 0, 0); + Cvar_Register (&sv_progs_zone_cvar, 0, 0); + Cvar_Register (&sv_progs_stack_cvar, 0, 0); + Cvar_Register (&sv_progs_ext_cvar, 0, 0); + Cvar_Register (&pr_checkextensions_cvar, 0, 0); + Cvar_Register (&sv_old_entity_free_cvar, 0, 0); + Cvar_Register (&sv_hide_version_info_cvar, 0, 0); + Cvar_Register (&sv_aim_cvar, 0, 0); + Cvar_Register (&pr_double_remove_cvar, 0, 0); } diff --git a/qw/source/sv_qtv.c b/qw/source/sv_qtv.c index 1daf1926d..31306072b 100644 --- a/qw/source/sv_qtv.c +++ b/qw/source/sv_qtv.c @@ -456,7 +456,7 @@ SV_qtvCheckTimeouts (void) float droptime; sv_qtv_t *proxy; - droptime = realtime - sv_timeout->value; + droptime = realtime - sv_timeout; for (i = 0; i < MAX_PROXIES; i++) { proxy = proxies + i; diff --git a/qw/source/sv_recorder.c b/qw/source/sv_recorder.c index cd5cdf1c2..517e981e6 100644 --- a/qw/source/sv_recorder.c +++ b/qw/source/sv_recorder.c @@ -121,7 +121,7 @@ static byte datagram_data[MAX_DATAGRAM]; static byte msg_buffer[2][MAX_DATAGRAM]; #define MIN_DEMO_MEMORY 0x100000 -#define USECACHE (sv_demoUseCache->int_val && svs.demomemsize) +#define USECACHE (sv_demoUseCache && svs.demomemsize) #define MAXSIZE (rec.dbuffer.end < rec.dbuffer.last ? \ rec.dbuffer.start - rec.dbuffer.end : \ rec.dbuffer.maxsize - rec.dbuffer.end) @@ -559,7 +559,7 @@ SVR_SendMessages (void) int stats[MAX_CL_STATS]; recorder_t *r; - if (sv_demoPings->value && sv.time - rec.pingtime > sv_demoPings->value) { + if (sv_demoPings && sv.time - rec.pingtime > sv_demoPings) { demo_pings (); rec.pingtime = sv.time; } diff --git a/qw/source/sv_send.c b/qw/source/sv_send.c index 87c65837e..42f53169e 100644 --- a/qw/source/sv_send.c +++ b/qw/source/sv_send.c @@ -226,14 +226,13 @@ SV_Print (const char *fmt, va_list args) } if (*msg->str && !con_printf_no_log) { // We want to output to console and maybe logfile - if (sv_timestamps && sv_timefmt && sv_timefmt->string - && sv_timestamps->int_val && !pending) + if (sv_timefmt && sv_timestamps && !pending) timestamps = true; if (timestamps) { mytime = time (NULL); local = localtime (&mytime); - hstrftime (msg3, sizeof (msg3), sv_timefmt->string, local); + hstrftime (msg3, sizeof (msg3), sv_timefmt, local); dsprintf (msg2, "%s%s", msg3, msg->str); } else { @@ -423,7 +422,7 @@ SV_StartSound (edict_t *entity, int channel, const char *sample, int volume, ent = NUM_FOR_EDICT (&sv_pr_state, entity); - if ((channel & 8) || !sv_phs->int_val) // no PHS flag + if ((channel & 8) || !sv_phs) // no PHS flag { if (channel & 8) reliable = true; // sounds that break the phs are diff --git a/qw/source/sv_sys_unix.c b/qw/source/sv_sys_unix.c index cb7aabbdd..96b0c67b9 100644 --- a/qw/source/sv_sys_unix.c +++ b/qw/source/sv_sys_unix.c @@ -139,7 +139,7 @@ main (int argc, const char **argv) SV_Frame (time); // extrasleep is just a way to generate a bad connection on purpose - if (sys_extrasleep->int_val) - usleep (sys_extrasleep->int_val); + if (sys_extrasleep) + usleep (sys_extrasleep); } } diff --git a/qw/source/sv_sys_win.c b/qw/source/sv_sys_win.c index 20fbdfb4e..f8c9dba1a 100644 --- a/qw/source/sv_sys_win.c +++ b/qw/source/sv_sys_win.c @@ -81,7 +81,7 @@ main (int argc, const char **argv) SV_Init (); if (COM_CheckParm ("-nopriority")) { - Cvar_Set (sys_sleep, "0"); + Cvar_Set ("sys_sleep", "0"); } else { if (!SetPriorityClass (GetCurrentProcess (), HIGH_PRIORITY_CLASS)) SV_Printf ("SetPriorityClass() failed\n"); @@ -91,7 +91,7 @@ main (int argc, const char **argv) // sys_sleep > 0 seems to cause packet loss on WinNT (why?) if (WinNT) - Cvar_Set (sys_sleep, "0"); + Cvar_Set ("sys_sleep", "0"); Sys_RegisterShutdown (Net_LogStop, 0); diff --git a/qw/source/sv_user.c b/qw/source/sv_user.c index 31dc6c142..553ee274c 100644 --- a/qw/source/sv_user.c +++ b/qw/source/sv_user.c @@ -80,34 +80,215 @@ edict_t *sv_player; usercmd_t cmd; -cvar_t *sv_antilag; -cvar_t *sv_antilag_frac; +int sv_maxrate; +static cvar_t sv_maxrate_cvar = { + .name = "sv_maxrate", + .description = + "Maximum allowable rate", + .default_value = "10000", + .flags = CVAR_SERVERINFO, + .value = { .type = &cexpr_int, .value = &sv_maxrate }, +}; + // capped) +int sv_antilag; +static cvar_t sv_antilag_cvar = { + .name = "sv_antilag", + .description = + "Attempt to backdate impacts to compensate for lag. 0=completely off. " + "1=mod-controlled. 2=forced, which might break certain uses of " + "traceline.", + .default_value = "1", + .flags = CVAR_SERVERINFO, + .value = { .type = &cexpr_int, .value = &sv_antilag }, +}; +float sv_antilag_frac; +static cvar_t sv_antilag_frac_cvar = { + .name = "sv_antilag_frac", + .description = + "FIXME something to do with sv_antilag", + .default_value = "1", + .flags = CVAR_SERVERINFO, + .value = { .type = &cexpr_float, .value = &sv_antilag_frac }, +}; -cvar_t *sv_accelerate; -cvar_t *sv_airaccelerate; -cvar_t *sv_maxspeed; -cvar_t *sv_spectatormaxspeed; -cvar_t *sv_wateraccelerate; -cvar_t *sv_waterfriction; +float sv_accelerate; +static cvar_t sv_accelerate_cvar = { + .name = "sv_accelerate", + .description = + "None", + .default_value = "10", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &sv_accelerate }, +}; +float sv_airaccelerate; +static cvar_t sv_airaccelerate_cvar = { + .name = "sv_airaccelerate", + .description = + "Sets how quickly the players accelerate in air", + .default_value = "0.7", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &sv_airaccelerate }, +}; +float sv_maxspeed; +static cvar_t sv_maxspeed_cvar = { + .name = "sv_maxspeed", + .description = + "None", + .default_value = "320", + .flags = CVAR_SERVERINFO, + .value = { .type = &cexpr_float, .value = &sv_maxspeed }, +}; +float sv_spectatormaxspeed; +static cvar_t sv_spectatormaxspeed_cvar = { + .name = "sv_spectatormaxspeed", + .description = + "Sets the maximum speed a spectator can move", + .default_value = "500", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &sv_spectatormaxspeed }, +}; +float sv_wateraccelerate; +static cvar_t sv_wateraccelerate_cvar = { + .name = "sv_wateraccelerate", + .description = + "Sets the water acceleration value", + .default_value = "10", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &sv_wateraccelerate }, +}; +float sv_waterfriction; +static cvar_t sv_waterfriction_cvar = { + .name = "sv_waterfriction", + .description = + "Sets the water friction value", + .default_value = "4", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &sv_waterfriction }, +}; -cvar_t *sv_allowfake; +int sv_allowfake; +static cvar_t sv_allowfake_cvar = { + .name = "sv_allowfake", + .description = + "Allow 'fake' messages (FuhQuake $\\). 1 = always, 2 = only say_team", + .default_value = "2", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sv_allowfake }, +}; -cvar_t *cl_rollspeed; -cvar_t *cl_rollangle; -cvar_t *sv_spectalk; +float cl_rollspeed; +static cvar_t cl_rollspeed_cvar = { + .name = "cl_rollspeed", + .description = + "How quickly you straighten out after strafing", + .default_value = "200", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &cl_rollspeed }, +}; +float cl_rollangle; +static cvar_t cl_rollangle_cvar = { + .name = "cl_rollangle", + .description = + "How much your screen tilts when strafing", + .default_value = "2.0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &cl_rollangle }, +}; +int sv_spectalk; +static cvar_t sv_spectalk_cvar = { + .name = "sv_spectalk", + .description = + "Toggles the ability of spectators to talk to players", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sv_spectalk }, +}; -cvar_t *sv_kickfake; +int sv_kickfake; +static cvar_t sv_kickfake_cvar = { + .name = "sv_kickfake", + .description = + "Kick users sending to send fake talk messages", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sv_kickfake }, +}; -cvar_t *sv_mapcheck; +int sv_mapcheck; +static cvar_t sv_mapcheck_cvar = { + .name = "sv_mapcheck", + .description = + "Toggle the use of map checksumming to check for players who edit maps" + " to cheat", + .default_value = "1", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sv_mapcheck }, +}; -cvar_t *sv_timecheck_mode; -cvar_t *sv_timekick; -cvar_t *sv_timekick_fuzz; -cvar_t *sv_timekick_interval; -cvar_t *sv_timecheck_fuzz; -cvar_t *sv_timecheck_decay; +int sv_timecheck_mode; +static cvar_t sv_timecheck_mode_cvar = { + .name = "sv_timecheck_mode", + .description = + "select between timekick (0, default) and timecheck (1)", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sv_timecheck_mode }, +}; +int sv_timekick; +static cvar_t sv_timekick_cvar = { + .name = "sv_timekick", + .description = + "Time cheat protection", + .default_value = "3", + .flags = CVAR_SERVERINFO, + .value = { .type = &cexpr_int, .value = &sv_timekick }, +}; +float sv_timekick_fuzz; +static cvar_t sv_timekick_fuzz_cvar = { + .name = "sv_timekick_fuzz", + .description = + "Time cheat \"fuzz factor\" in milliseconds", + .default_value = "30", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &sv_timekick_fuzz }, +}; +float sv_timekick_interval; +static cvar_t sv_timekick_interval_cvar = { + .name = "sv_timekick_interval", + .description = + "Time cheat check interval in seconds", + .default_value = "30", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &sv_timekick_interval }, +}; +int sv_timecheck_fuzz; +static cvar_t sv_timecheck_fuzz_cvar = { + .name = "sv_timecheck_fuzz", + .description = + "Milliseconds of tolerance before time cheat throttling kicks in.", + .default_value = "250", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sv_timecheck_fuzz }, +}; +int sv_timecheck_decay; +static cvar_t sv_timecheck_decay_cvar = { + .name = "sv_timecheck_decay", + .description = + "Rate at which time inaccuracies are \"forgiven\".", + .default_value = "2", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &sv_timecheck_decay }, +}; -cvar_t *sv_http_url_base; +char *sv_http_url_base; +static cvar_t sv_http_url_base_cvar = { + .name = "sv_http_url_base", + .description = + "set to base url for http redirects of downloaded files", + .default_value = "", + .flags = CVAR_NONE, + .value = { .type = 0, .value = &sv_http_url_base }, +}; static void OutofBandPrintf (netadr_t where, const char *fmt, ...) __attribute__ ((format (PRINTF, 2, 3))); @@ -335,7 +516,7 @@ SV_PreSpawn_f (void *unused) // Sys_MaskPrintf (SYS_dev, , "Client check = %d\n", check); - if (sv_mapcheck->int_val && check != sv.worldmodel->brush.checksum && + if (sv_mapcheck && check != sv.worldmodel->brush.checksum && check != sv.worldmodel->brush.checksum2) { SV_ClientPrintf (1, host_client, PRINT_HIGH, "Map model file does " "not match (%s), %i != %i/%i.\n" @@ -386,9 +567,9 @@ SV_Spawn (client_t *client) client->entgravity = 1.0; if (sv_fields.gravity != -1) SVfloat (ent, gravity) = 1.0; - client->maxspeed = sv_maxspeed->value; + client->maxspeed = sv_maxspeed; if (sv_fields.maxspeed != -1) - SVfloat (ent, maxspeed) = sv_maxspeed->value; + SVfloat (ent, maxspeed) = sv_maxspeed; } void @@ -715,19 +896,19 @@ SV_BeginDownload_f (void *unused) name = Cmd_Argv (1); // hacked by zoid to allow more conrol over download // first off, no .. or global allow check - if (strstr (name, "..") || !allow_download->int_val + if (strstr (name, "..") || !allow_download // leading dot is no good || *name == '.' // next up, skin check - || (strncmp (name, "skins/", 6) == 0 && !allow_download_skins->int_val) + || (strncmp (name, "skins/", 6) == 0 && !allow_download_skins) // now models || (strncmp (name, "progs/", 6) == 0 && - !allow_download_models->int_val) + !allow_download_models) // now sounds || (strncmp (name, "sound/", 6) == 0 && - !allow_download_sounds->int_val) + !allow_download_sounds) // now maps (note special case for maps, must not be in pak) - || (strncmp (name, "maps/", 5) == 0 && !allow_download_maps->int_val) + || (strncmp (name, "maps/", 5) == 0 && !allow_download_maps) // MUST be in a subdirectory || !strstr (name, "/")) { // don't allow anything with .. path MSG_ReliableWrite_Begin (&host_client->backbuf, svc_download, 4); @@ -742,7 +923,7 @@ SV_BeginDownload_f (void *unused) } zip = strchr (Info_ValueForKey (host_client->userinfo, "*cap"), 'z') != 0; - http = sv_http_url_base->string[0] + http = sv_http_url_base[0] && strchr (Info_ValueForKey (host_client->userinfo, "*cap"), 'h'); file = _QFS_FOpenFile (name, !zip); @@ -770,15 +951,15 @@ SV_BeginDownload_f (void *unused) if (http) { int size; int ren = zip && strcmp (qfs_foundfile.realname, name); - SV_Printf ("http redirect: %s/%s\n", sv_http_url_base->string, + SV_Printf ("http redirect: %s/%s\n", sv_http_url_base, qfs_foundfile.realname); size = ren ? strlen (qfs_foundfile.realname) * 2 : strlen (name); - size += strlen (sv_http_url_base->string) + 7; + size += strlen (sv_http_url_base) + 7; MSG_ReliableWrite_Begin (&host_client->backbuf, svc_download, size); MSG_ReliableWrite_Short (&host_client->backbuf, DL_HTTP); MSG_ReliableWrite_Byte (&host_client->backbuf, 0); MSG_ReliableWrite_String (&host_client->backbuf, - va (0, "%s/%s", sv_http_url_base->string, + va (0, "%s/%s", sv_http_url_base, ren ? qfs_foundfile.realname : name)); MSG_ReliableWrite_String (&host_client->backbuf, ren ? qfs_foundfile.realname : ""); @@ -860,10 +1041,10 @@ SV_Say (qboolean team) p[strlen (p) - 1] = 0; } - if (!sv_allowfake->int_val || (!team && sv_allowfake->int_val == 2)) { + if (!sv_allowfake || (!team && sv_allowfake == 2)) { for (i = p; *i; i++) { if (*i == 13) { // ^M - if (sv_kickfake->int_val) { + if (sv_kickfake) { SV_BroadcastPrintf (PRINT_HIGH, "%s was kicked for " "attempting to fake messages\n", host_client->name); @@ -892,7 +1073,7 @@ SV_Say (qboolean team) } text = dstring_new (); - if (host_client->spectator && (!sv_spectalk->int_val || team)) { + if (host_client->spectator && (!sv_spectalk || team)) { type = "2"; dsprintf (text, "[SPEC] %s: ", host_client->name); } else if (team) { @@ -915,7 +1096,7 @@ SV_Say (qboolean team) for (j = 0, client = svs.clients; j < MAX_CLIENTS; j++, client++) { if (client->state < cs_connected) // Clients connecting can hear. //FIXME record to mvd? continue; - if (host_client->spectator && !sv_spectalk->int_val) + if (host_client->spectator && !sv_spectalk) if (!client->spectator) continue; @@ -940,7 +1121,7 @@ SV_Say (qboolean team) } // non-team messages should be seen allways, even if not tracking any // player - if (!team && ((host_client->spectator && sv_spectalk->int_val) + if (!team && ((host_client->spectator && sv_spectalk) || !host_client->spectator)) { dbuf = SVR_WriteBegin (dem_all, 0, strlen (text->str) + 3); } else { @@ -1045,7 +1226,7 @@ SV_Pause_f (void *unused) lastpausetime = currenttime; - if (!pausable->int_val) { + if (!pausable) { SV_ClientPrintf (1, host_client, PRINT_HIGH, "Pause not allowed.\n"); return; } @@ -1139,8 +1320,8 @@ SV_Rate_f (void *unused) } rate = atoi (Cmd_Argv (1)); - if (sv_maxrate->int_val) { - rate = bound (500, rate, sv_maxrate->int_val); + if (sv_maxrate) { + rate = bound (500, rate, sv_maxrate); } else { rate = max (500, rate); } @@ -1179,7 +1360,7 @@ SV_SetUserinfo (client_t *client, const char *key, const char *value) if (sv_setinfo_e->func || sv_funcs.UserInfoChanged) oldvalue = strdup (Info_ValueForKey (client->userinfo, key)); if (!Info_SetValueForKey (client->userinfo, key, value, - !sv_highchars->int_val)) { + !sv_highchars)) { // key hasn't changed if (oldvalue) free (oldvalue); @@ -1487,10 +1668,10 @@ SV_CalcRoll (vec3_t angles, vec3_t velocity) sign = side < 0 ? -1 : 1; side = fabs (side); - value = cl_rollangle->value; + value = cl_rollangle; - if (side < cl_rollspeed->value) - side = side * value / cl_rollspeed->value; + if (side < cl_rollspeed) + side = side * value / cl_rollspeed; else side = value; @@ -1592,12 +1773,12 @@ adjust_usecs (usercmd_t *ucmd) passed = (int) ((realtime - host_client->last_check) * 1000.0); host_client->msecs += passed - ucmd->msec; if (host_client->msecs >= 0) { - host_client->msecs -= sv_timecheck_decay->int_val; + host_client->msecs -= sv_timecheck_decay; } else { - host_client->msecs += sv_timecheck_decay->int_val; + host_client->msecs += sv_timecheck_decay; } - if (abs (host_client->msecs) > sv_timecheck_fuzz->int_val) { - int fuzz = sv_timecheck_fuzz->int_val; + if (abs (host_client->msecs) > sv_timecheck_fuzz) { + int fuzz = sv_timecheck_fuzz; host_client->msecs = bound (-fuzz, host_client->msecs, fuzz); ucmd->msec = passed; } @@ -1616,18 +1797,18 @@ check_usecs (usercmd_t *ucmd) if (host_client->last_check == -1.0) return; tmp_time = realtime - host_client->last_check; - if (tmp_time < sv_timekick_interval->value) + if (tmp_time < sv_timekick_interval) return; host_client->last_check = realtime; - tmp_time1 = tmp_time * (1000 + sv_timekick_fuzz->value); + tmp_time1 = tmp_time * (1000 + sv_timekick_fuzz); if (host_client->msecs >= tmp_time1) { host_client->msec_cheating++; SV_BroadcastPrintf (PRINT_HIGH, "%s thinks there are %d ms " "in %d seconds (Strike %d/%d)\n", host_client->name, host_client->msecs, (int) tmp_time, host_client->msec_cheating, - sv_timekick->int_val); - if (host_client->msec_cheating >= sv_timekick->int_val) { + sv_timekick); + if (host_client->msec_cheating >= sv_timekick) { SV_BroadcastPrintf (PRINT_HIGH, "Strike %d for %s!!\n", host_client->msec_cheating, host_client->name); SV_BroadcastPrintf (PRINT_HIGH, "Please see " @@ -1648,7 +1829,7 @@ SV_RunCmd (usercmd_t *ucmd, qboolean inside) edict_t *ent; if (!inside) { - if (sv_timecheck_mode->int_val) { + if (sv_timecheck_mode) { adjust_usecs (ucmd); } else { check_usecs (ucmd); @@ -1863,7 +2044,7 @@ SV_ExecuteClientMessage (client_t *cl) frame->ping_time = realtime - frame->senttime; cl->laggedents_count = 0; - if (sv_antilag->int_val) { + if (sv_antilag) { int i; for (i = 0; i < MAX_CLIENTS; i++) { @@ -1874,7 +2055,7 @@ SV_ExecuteClientMessage (client_t *cl) } } cl->laggedents_count = MAX_CLIENTS; - cl->laggedents_frac = sv_antilag_frac->value; + cl->laggedents_frac = sv_antilag_frac; } // save time for ping calculations @@ -2000,56 +2181,63 @@ static builtin_t builtins[] = { {0} }; +static void +SV_MaxRate_f (void *data, const cvar_t *cvar) +{ + client_t *cl; + int maxrate = sv_maxrate; + int i, rate = 2500; + const char *val; + + Cvar_Info (data, cvar); + for (i = 0, cl = svs.clients; i < MAX_CLIENTS; i++, cl++) { + if (!cl->userinfo) + continue; + val = Info_ValueForKey (cl->userinfo, "rate"); + if (strlen (val)) { + rate = atoi (val); + + if (maxrate) { + rate = bound (500, rate, maxrate); + } else { + rate = max (500, rate); + } + cl->netchan.rate = 1.0 / rate; + } + SV_ClientPrintf (1, cl, PRINT_HIGH, "Net rate set to %i\n", rate); + } +} + void SV_UserInit (void) { ucmd_table = Hash_NewTable (251, ucmds_getkey, ucmds_free, 0, 0); Hash_SetHashCompare (ucmd_table, ucmd_get_hash, ucmd_compare); PR_RegisterBuiltins (&sv_pr_state, builtins, 0); - cl_rollspeed = Cvar_Get ("cl_rollspeed", "200", CVAR_NONE, NULL, - "How quickly a player straightens out after " - "strafing"); - cl_rollangle = Cvar_Get ("cl_rollangle", "2", CVAR_NONE, NULL, "How much " - "a player's screen tilts when strafing"); + Cvar_Register (&cl_rollspeed_cvar, 0, 0); + Cvar_Register (&cl_rollangle_cvar, 0, 0); - sv_antilag = Cvar_Get ("sv_antilag", "1", CVAR_SERVERINFO, Cvar_Info, - "Attempt to backdate impacts to compensate for " - "lag. 0=completely off. 1=mod-controlled. " - "2=forced, which might break certain uses of " - "traceline."); - sv_antilag_frac = Cvar_Get ("sv_antilag_frac", "1", CVAR_SERVERINFO, - Cvar_Info, - "FIXME something to do with sv_antilag"); + Cvar_Register (&sv_antilag_cvar, Cvar_Info, &sv_antilag); + Cvar_Register (&sv_antilag_frac_cvar, Cvar_Info, &sv_antilag_frac); - sv_allowfake = Cvar_Get ("sv_allowfake", "2", CVAR_NONE, NULL, - "Allow 'fake' messages (FuhQuake $\\). 1 = " - "always, 2 = only say_team"); - sv_spectalk = Cvar_Get ("sv_spectalk", "1", CVAR_NONE, NULL, "Toggles " - "the ability of spectators to talk to players"); - sv_mapcheck = Cvar_Get ("sv_mapcheck", "1", CVAR_NONE, NULL, "Toggle the " - "use of map checksumming to check for players who " - "edit maps to cheat"); - sv_timecheck_mode = Cvar_Get ("sv_timecheck_mode", "0", CVAR_NONE, NULL, - "select between timekick (0, default) and " - "timecheck (1)"); - sv_timekick = Cvar_Get ("sv_timekick", "3", CVAR_SERVERINFO, Cvar_Info, - "Time cheat protection"); - sv_timekick_fuzz = Cvar_Get ("sv_timekick_fuzz", "30", CVAR_NONE, NULL, - "Time cheat \"fuzz factor\" in milliseconds"); - sv_timekick_interval = Cvar_Get ("sv_timekick_interval", "30", CVAR_NONE, - NULL, "Time cheat check interval in " - "seconds"); - sv_timecheck_fuzz = Cvar_Get ("sv_timecheck_fuzz", "250", CVAR_NONE, NULL, - "Milliseconds of tolerance before time " - "cheat throttling kicks in."); - sv_timecheck_decay = Cvar_Get ("sv_timecheck_decay", "2", CVAR_NONE, - NULL, "Rate at which time inaccuracies are " - "\"forgiven\"."); - sv_kickfake = Cvar_Get ("sv_kickfake", "0", CVAR_NONE, NULL, - "Kick users sending to send fake talk messages"); - sv_http_url_base = Cvar_Get ("sv_http_url_base", "", CVAR_NONE, NULL, - "set to base url for http redirects of " - "downloaded files"); + Cvar_Register (&sv_allowfake_cvar, 0, 0); + Cvar_Register (&sv_spectalk_cvar, 0, 0); + Cvar_Register (&sv_mapcheck_cvar, 0, 0); + Cvar_Register (&sv_timecheck_mode_cvar, 0, 0); + Cvar_Register (&sv_timekick_cvar, Cvar_Info, &sv_timekick); + Cvar_Register (&sv_timekick_fuzz_cvar, 0, 0); + Cvar_Register (&sv_timekick_interval_cvar, 0, 0); + Cvar_Register (&sv_timecheck_fuzz_cvar, 0, 0); + Cvar_Register (&sv_timecheck_decay_cvar, 0, 0); + Cvar_Register (&sv_kickfake_cvar, 0, 0); + Cvar_Register (&sv_http_url_base_cvar, 0, 0); + Cvar_Register (&sv_maxrate_cvar, SV_MaxRate_f, 0); + Cvar_Register (&sv_maxspeed_cvar, Cvar_Info, &sv_maxspeed); + Cvar_Register (&sv_spectatormaxspeed_cvar, 0, 0); + Cvar_Register (&sv_accelerate_cvar, 0, 0); + Cvar_Register (&sv_airaccelerate_cvar, 0, 0); + Cvar_Register (&sv_wateraccelerate_cvar, 0, 0); + Cvar_Register (&sv_waterfriction_cvar, 0, 0); } static void diff --git a/qw/source/teamplay.c b/qw/source/teamplay.c index a2ced2126..926093007 100644 --- a/qw/source/teamplay.c +++ b/qw/source/teamplay.c @@ -61,11 +61,53 @@ static qboolean died = false, recorded_location = false; static vec4f_t death_location, last_recorded_location; -cvar_t *cl_deadbodyfilter; -cvar_t *cl_gibfilter; -cvar_t *cl_parsesay; -cvar_t *cl_nofake; -cvar_t *cl_freply; +int cl_deadbodyfilter; +static cvar_t cl_deadbodyfilter_cvar = { + .name = "cl_deadbodyfilter", + .description = + "Hide dead player models", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &cl_deadbodyfilter }, +}; +int cl_gibfilter; +static cvar_t cl_gibfilter_cvar = { + .name = "cl_gibfilter", + .description = + "Hide gibs", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &cl_gibfilter }, +}; +int cl_parsesay; +static cvar_t cl_parsesay_cvar = { + .name = "cl_parsesay", + .description = + "Use .loc files to find your present location when you put %l in " + "messages", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &cl_parsesay }, +}; +int cl_nofake; +static cvar_t cl_nofake_cvar = { + .name = "cl_nofake", + .description = + "Unhide fake messages", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &cl_nofake }, +}; +float cl_freply; +static cvar_t cl_freply_cvar = { + .name = "cl_freply", + .description = + "Delay between replies to f_*. 0 disables. Minimum suggested setting " + "is 20", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_float, .value = &cl_freply }, +}; void @@ -129,7 +171,7 @@ Team_ParseSay (dstring_t *buf, const char *s) size_t i, bracket; static location_t *location = NULL; - if (!cl_parsesay->int_val || (cl.fpd & FPD_NO_MACROS)) + if (!cl_parsesay || (cl.fpd & FPD_NO_MACROS)) return s; i = 0; @@ -158,7 +200,7 @@ Team_ParseSay (dstring_t *buf, const char *s) break; case 'S': bracket = 0; - t1 = skin->string; + t1 = skin; break; case 'd': bracket = 0; @@ -308,18 +350,11 @@ Team_NewMap (void) void Team_Init_Cvars (void) { - cl_deadbodyfilter = Cvar_Get ("cl_deadbodyfilter", "0", CVAR_NONE, NULL, - "Hide dead player models"); - cl_gibfilter = Cvar_Get ("cl_gibfilter", "0", CVAR_NONE, NULL, - "Hide gibs"); - cl_parsesay = Cvar_Get ("cl_parsesay", "0", CVAR_NONE, NULL, - "Use .loc files to find your present location " - "when you put %l in messages"); - cl_nofake = Cvar_Get ("cl_nofake", "0", CVAR_NONE, NULL, - "Unhide fake messages"); - cl_freply = Cvar_Get ("cl_freply", "0", CVAR_NONE, NULL, - "Delay between replies to f_*. 0 disables. Minimum " - "suggested setting is 20"); + Cvar_Register (&cl_deadbodyfilter_cvar, 0, 0); + Cvar_Register (&cl_gibfilter_cvar, 0, 0); + Cvar_Register (&cl_parsesay_cvar, 0, 0); + Cvar_Register (&cl_nofake_cvar, 0, 0); + Cvar_Register (&cl_freply_cvar, 0, 0); } /* @@ -435,7 +470,7 @@ Team_F_Skins (char *args) int totalfb, l; float allfb = 0.0; - allfb = min (cl.fbskins, cl_fb_players->value); + allfb = min (cl.fbskins, cl_fb_players); if (allfb >= 1.0) { return "say Player models fullbright"; @@ -474,7 +509,7 @@ Team_ParseChat (const char *string) char *s; unsigned int i; - if (!cl_freply->value) + if (!cl_freply) return; if (!(s = strchr (string, ':'))) @@ -485,7 +520,7 @@ Team_ParseChat (const char *string) for (i = 0; i < sizeof (f_replies) / sizeof (f_replies[0]); i++) { if (!strncmp (f_replies[i].name, s, strlen (f_replies[i].name)) - && realtime - f_replies[i].lasttime >= cl_freply->value) { + && realtime - f_replies[i].lasttime >= cl_freply) { while (*s && !isspace ((byte) *s)) s++; Cbuf_AddText (cl_cbuf, f_replies[i].func (s)); @@ -501,6 +536,6 @@ Team_ResetTimers (void) unsigned int i; for (i = 0; i < sizeof (f_replies) / sizeof (f_replies[0]); i++) - f_replies[i].lasttime = realtime - cl_freply->value; + f_replies[i].lasttime = realtime - cl_freply; return; } diff --git a/ruamoko/qwaq/builtins/main.c b/ruamoko/qwaq/builtins/main.c index 48c404338..b4954a0bb 100644 --- a/ruamoko/qwaq/builtins/main.c +++ b/ruamoko/qwaq/builtins/main.c @@ -149,9 +149,6 @@ init_qf (void) //Cvar_Set (developer, "1"); Memory_Init (Sys_Alloc (8 * 1024 * 1024), 8 * 1024 * 1024); - - Cvar_Get ("pr_debug", "2", 0, 0, 0); - Cvar_Get ("pr_boundscheck", "0", 0, 0, 0); } static void @@ -212,6 +209,8 @@ create_progs (qwaq_thread_t *thread) pr->hashlink_freelist = &thread->hashlink_freelist; PR_Init_Cvars (); + pr_debug = 2; + pr_boundscheck = 0; PR_Init (pr); PR_Resources_Register (pr, "qwaq_thread", thread, qwaq_thread_clear); RUA_Init (pr, thread->rua_security); diff --git a/tools/misc/cvar2.py b/tools/misc/cvar2.py new file mode 100644 index 000000000..338a25904 --- /dev/null +++ b/tools/misc/cvar2.py @@ -0,0 +1,335 @@ +import re +import sys +from pprint import pprint +from io import StringIO +from textwrap import TextWrapper +import os + +STRING = r'\s*"((\\.|[^"\\])*)"\s*' +QSTRING = r'\s*("(\\.|[^"\\])*")\s*' +ID = r'([a-zA-Z_][a-zA-Z_0-9]*)' +STORE = r'(VISIBLE\s+|static\s+|extern\s+|)' +FIELD = r'(string|value|int_val|vec)\b' +FLAGS = r'\s*(' + ID + r'\s*(\|\s*' + ID + r')*)\s*' +TYPE = r'(cvar_t|struct cvar_s)\s*\*' +STUFF = r'\s*(.*)\s*' +cvar_decl_re = re.compile(r'^' + STORE + TYPE + ID + r';.*') +cvar_get_re = re.compile(r'.*\bCvar_Get\s*\(\s*"') +cvar_get_join_prev_re = re.compile(r'^\s*Cvar_Get\s*\(\s*".*') +cvar_get_assign_re = re.compile(r'\s*' + ID + r'\s*=\s*$') +cvar_get_incomplete_re = re.compile(r'.*Cvar_Get\s*\(\s*"[^;]*$') +cvar_get_complete_re = re.compile(r'.*Cvar_Get\s*\(\s*".*\);.*$') +cvar_create_re = re.compile(r'\s*(\w+)\s*=\s*Cvar_Get\s*\(' + + STRING + + ',(' + STRING + '|\s*(.*)\s*),' + FLAGS + r',\s*([^,]+),\s*' + STUFF + r'\);.*') +cvar_use_re = re.compile(ID + r'\s*\->\s*' + FIELD) +cvar_listener_re = re.compile(ID + r'\s*\(\s*cvar_t\s*\*' + ID + '\s*\)\s*') +string_or_id_re = re.compile(f'({ID}|{QSTRING})') +cvar_setrom_re = re.compile(r'\s*Cvar_SetFlags\s*\(\s*' + ID + '.*CVAR_ROM\);.*') +id_re = re.compile(f'\\b{ID}\\b') + +#cvar_decl_re = re.compile(r'^cvar_t\s+(\w+)\s*=\s*\{\s*("[^"]*")\s*,\s*("[^"]*")(\s*,\s*(\w+)(\s*,\s*(\w+))?)?\s*\}\s*;(\s*//\s*(.*))?\n') +cvar_set_re = re.compile(r'^(\s+)(Cvar_Set|Cvar_SetValue)\s*\(' + ID + ',\s*(.*)\);(.*)') + +wrapper = TextWrapper(width = 69, drop_whitespace = False, + break_long_words = False) + +class cvar: + def __init__(self, c_name, name, default, flags, callback, description): + self.c_name = c_name + self.name = name + self.default = default + self.flags = flags + if callback in ['NULL', '0']: + callback = 0 + self.callback = callback + if description in ['NULL', '0', '']: + description = 'FIXME no description' + self.desc = description + if self.desc==None: + self.desc = 'None' + self.data = 0 + self.files = [] + self.type = None + self.c_type = None + self.used_field = None + self.uses = [] + def guess_type(self): + if self.used_field == "value": + self.type = "&cexpr_float" + self.c_type = "float " + elif self.used_field == "int_val": + self.type = "&cexpr_int" + self.c_type = "int " + elif self.used_field == "vec": + self.type = "&cexpr_vector" + self.c_type = "vec4f_t " + elif self.used_field == "string": + self.type = 0 + self.c_type = "char *" + else: + self.type = "0/* not used */" + self.c_type = "char *" + def add_file(self, file, line): + self.files.append((file, line)) + def add_use(self, field, file, line): + if self.used_field and self.used_field != field: + print(f"{file}:{line}: cvar {self.name} used inconsistently") + self.used_field = field + self.uses.append((field, file, line)) + def __repr__(self): + return f"cvar(({self.c_name}, {self.name}, {self.default}, {self.flags}, {self.callback}, {self.desc})" + def __str__(self): + return self.__repr__() + def struct(self): + A = [ + f'static cvar_t {self.c_name}_cvar = {{\n', + f'\t.name = "{self.name}",\n', + f'\t.description =\n', + ] + B = [ + f'\t.default_value = "{self.default}",\n', + f'\t.flags = {self.flags},\n', + f'\t.value = {{ .type = {self.type}, .value = &{self.c_name} }},\n', + f'}};\n', + ] + desc = [] + dstrings = [m[0].strip() for m in string_or_id_re.findall(self.desc)] + def wrap(string, comma = ""): + if string[0] == '"' and string != '""': + string = string[1:-1] + dlines = wrapper.wrap(string) + desc.extend([f'\t\t"{l}"\n' for l in dlines[:-1]]) + desc.append(f'\t\t"{dlines[-1]}"{comma}\n') + else: + desc.append(f'\t\t{string}{comma}\n') + for dstring in dstrings[:-1]: + wrap (dstring) + wrap(dstrings[-1], ",") + return A + desc + B + def var(self, storage): + if storage: + storage += " " + return [f'{storage}{self.c_type}{self.c_name};\n'] + def set_rom(self): + if self.flags == 'CVAR_NONE': + self.flags = 'CVAR_ROM' + else: + self.flags = '|'.join([self.flags, 'CVAR_ROM']) + def register(self): + return [f'\tCvar_Register (&{self.c_name}_cvar, {self.callback}, {self.data});\n'] + + +cvar_decls = {} +cvar_dict = {} +cvar_sets = [] +cvar_rom = set() +cvar_listeners = {} +cvar_listeners_done = set() +cvar_listeners_multi = set() +files = {} +modified = set() + +cvar_struct = [ +"\tconst char *name;\n", +"\tconst char *description;\n", +"\tconst char *default_value;\n", +"\tunsigned flags;\n", +"\texprval_t value;\n", +"\tint (*validator) (const struct cvar_s *var);\n" +"\tstruct cvar_listener_set_s *listeners;\n" +"\tstruct cvar_s *next;\n" +] +cvar_reg = "void Cvar_Register (cvar_t *var, cvar_listener_t listener, void *data);\n" +cvar_cexpr = '#include "QF/cexpr.h"\n' +cvar_set = 'void Cvar_Set (const char *var, const char *value);\n' +cvar_setvar = 'void Cvar_SetVar (cvar_t *var, const char *value);\n' +cvar_info = 'struct cvar_s;\nvoid Cvar_Info (void *data, const struct cvar_s *cvar);\n' +nq_cl_cvar_info = 'nq/include/client.h' +nq_sv_cvar_info = 'nq/include/server.h' +qw_cl_cvar_info = 'qw/include/client.h' +qw_sv_cvar_info = 'qw/include/server.h' + +cvar_file = "include/QF/cvar.h" +line_substitutions = [ + (cvar_file, (40, 60), cvar_struct), + (cvar_file, (96, 100), cvar_reg), + (cvar_file, (35, 35), cvar_cexpr), + (cvar_file, (109, 110), cvar_set), + (cvar_file, (110, 111), cvar_setvar), + (nq_cl_cvar_info, (294,295), cvar_info), + (nq_sv_cvar_info, (300,301), cvar_info), + (qw_cl_cvar_info, (296,297), cvar_info), + (qw_sv_cvar_info, (634,635), cvar_info), +] + +def get_cvar_defs(fname): + fi = open(fname,'rt') + f = files[fname] = fi.readlines() + i = 0 + while i < len(f): + cr = cvar_setrom_re.match(f[i]) + if cr: + cvar_rom.add(cr[1]) + del(f[i]) + continue + if cvar_get_join_prev_re.match(f[i]): + if cvar_get_assign_re.match(f[i - 1]): + f[i - 1] = f"{f[i - 1].rstrip()} {f[i].lstrip()}" + del(f[i]) + i -= 1 + if cvar_get_incomplete_re.match(f[i]): + while not cvar_get_complete_re.match(f[i]): + f[i + 1] = f[i + 1].lstrip() + f[i] = f[i].rstrip() + if f[i][-1] == '"' and f[i + 1][0] == '"': + #string concatentation + f[i] = f[i][:-1] + f[i + 1][1:] + else: + f[i] = f"{f[i]} {f[i + 1]}" + del(f[i + 1]) + cd = cvar_decl_re.match(f[i]) + if cd: + if cd[3] not in cvar_decls: + cvar_decls[cd[3]] = [] + cvar_decls[cd[3]].append((fname, i)) + cl = cvar_listener_re.match(f[i]) + if cl: + if cl[1] not in cvar_listeners: + cvar_listeners[cl[1]] = [] + cvar_listeners[cl[1]].append((fname, i, cl[2])) + cc = cvar_create_re.match(f[i]) + if cc: + if cc.group(7): + default = 7 + else: + default = 5 + cc = cc.group(1, 2, default, 8, 12, 13) + if cc[0] not in cvar_dict: + cvar_dict[cc[0]] = cvar(*cc) + cvar_dict[cc[0]].add_file(fname, i) + cs = cvar_set_re.match(f[i]) + if cs: + cvar_sets.append((fname, i)) + i += 1 + fi.close() + +for f in sys.argv[1:]: + get_cvar_defs(f) +#for cv in cvar_decls.keys(): +# if cv not in cvar_dict: +# print(f"cvar {cv} declared but never created") +for file in files.items(): + fname,f = file + for i in range(len(f)): + for use in cvar_use_re.finditer(f[i]): + if use[1] in cvar_dict and cvar_dict[use[1]]: + cvar_dict[use[1]].add_use(use[2], fname, i) +keys = list(cvar_dict.keys()) +for cv in keys: + var = cvar_dict[cv] + if cv not in cvar_decls or var.callback not in cvar_listeners: + continue + if var.callback in cvar_listeners: + if var.callback in cvar_listeners_done: + if not var.callback in cvar_listeners_multi: + print(f"WARNING: {var.callback} has multiple uses") + cvar_listeners_multi.add (var.callback) + else: + cvar_listeners_done.add (var.callback); +cvar_listeners_done.clear() +for cv in keys: + var = cvar_dict[cv] + var.guess_type() + if var.c_name in cvar_rom: + print(var.c_name, 'rom') + var.set_rom() + if cv in cvar_decls: + if var.callback in cvar_listeners_multi: + var.data = f'&{var.c_name}' + for d in cvar_decls[cv]: + decl = cvar_decl_re.match(files[d[0]][d[1]]) + storage = decl[1].strip() + if storage == "extern": + subst = var.var(storage) + else: + subst = var.var(storage)+var.struct() + line_substitutions.append((d[0], (d[1], d[1] + 1), subst)) + for c in var.files: + line_substitutions.append((c[0], (c[1], c[1] + 1), var.register())) + for u in var.uses: + # use substitutions are done immediately because they never + # change the number of lines + field, fname, line = u + file = files[fname] + places = [] + for use in cvar_use_re.finditer(file[line]): + cv, field = use.group(1, 2) + if cv == var.c_name: + places.append((use.start(), use.end())) + places.reverse() + for p in places: + file[line] = file[line][:p[0]] + var.c_name + file[line][p[1]:] + modified.add(fname) + else: + #for f in cvar_dict[cv].files: + # print(f"{f[0]}:{f[1]}: {cv} created but not kept") + pass +for cv in keys: + var = cvar_dict[cv] + if cv not in cvar_decls or var.callback not in cvar_listeners: + continue + if var.callback in cvar_listeners_done: + continue + for listener in cvar_listeners[var.callback]: + fname, line, c_name = listener + file = files[fname] + file[line] = f"{var.callback} (void *data," " const cvar_t *cvar)\n" + modified.add(fname) + cvar_listeners_done.add (var.callback); + multi = var.callback in cvar_listeners_multi + line += 1 + while line < len(file) and file[line] != '}\n': + line += 1 + places = [] + for use in cvar_use_re.finditer(file[line]): + cv, field = use.group(1, 2) + if cv == c_name: + subst = f'*({var.c_type}*)data' if multi else var.c_name + places.append((use.start(), use.end(), subst)) + places.reverse() + for p in places: + file[line] = file[line][:p[0]] + p[2] + file[line][p[1]:] + modified.add(fname) + places = [] + for v in id_re.finditer(file[line]): + if v[1] == c_name: + places.append((v.start(), v.end(), "cvar")) + for p in places: + file[line] = file[line][:p[0]] + p[2] + file[line][p[1]:] + modified.add(fname) +for s in cvar_sets: + cs = cvar_set_re.match(files[s[0]][s[1]]) + subst = None + val = cs[4] + if cs[2] == "Cvar_SetValue" and cs[3] in cvar_dict: + if val[0] == '(': + #strip off a cast + val = val[val.index(')') + 1:].strip() + subst = f'{cs[1]}{cs[3]} = {val};{cs[5]}\n' + elif cs[2] == "Cvar_Set" and cs[3] in cvar_dict: + subst = f'{cs[1]}{cs[2]} ("{cvar_dict[cs[3]].name}", {val});{cs[5]}\n' + elif cs[2] == "Cvar_Set": + subst = f'{cs[1]}Cvar_SetVar ({cs[3]}, {val});{cs[5]}\n' + if subst: + line_substitutions.append((s[0], (s[1], s[1] + 1), subst)) +line_substitutions.sort(reverse=True, key=lambda s: s[1][1]) +for substitution in line_substitutions: + file, lines, subst = substitution + modified.add(file) + files[file][lines[0]:lines[1]] = subst +for f in files.keys(): + if f in modified: + file = open(f, "wt") + file.writelines(files[f]) + file.close () diff --git a/tools/qfcc/source/qfprogs.c b/tools/qfcc/source/qfprogs.c index b468cc5b3..20e59ea5c 100644 --- a/tools/qfcc/source/qfprogs.c +++ b/tools/qfcc/source/qfprogs.c @@ -234,10 +234,12 @@ init_qf (void) { Sys_Init (); - Cvar_Get ("pr_debug", va (0, "%d", 1+verbosity), 0, 0, ""); - Cvar_Get ("pr_source_path", source_path, 0, 0, ""); PR_Init_Cvars (); + pr_debug = 1 + verbosity; + free (pr_source_path); + pr_source_path = (char *) source_path; + pr.pr_edicts = &edicts; pr.num_edicts = &num_edicts; pr.reserved_edicts = &reserved_edicts; diff --git a/tools/qfcc/test/test-harness.c b/tools/qfcc/test/test-harness.c index a0a4bfd0c..b277e99f1 100644 --- a/tools/qfcc/test/test-harness.c +++ b/tools/qfcc/test/test-harness.c @@ -155,18 +155,10 @@ static void init_qf (void) { Sys_Init (); - Cvar_Get ("developer", va (0, "%d", options.developer), 0, 0, 0); + developer = options.developer; Memory_Init (Sys_Alloc (1024 * 1024), 1024 * 1024); - cvar_t *debug = Cvar_Get ("pr_debug", "2", 0, 0, 0); - Cvar_Get ("pr_boundscheck", "2", 0, 0, 0); - Cvar_Get ("pr_deadbeef_locals", "1", 0, 0, 0); - - if (options.trace > 1) { - Cvar_SetValue (debug, 4); - } - test_pr.pr_edicts = &edicts; test_pr.num_edicts = &num_edicts; test_pr.reserved_edicts = &reserved_edicts; @@ -177,6 +169,10 @@ init_qf (void) PR_Init_Cvars (); + pr_debug = options.trace > 1 ? 4 : 2; + pr_boundscheck = 2; + pr_deadbeef_locals = 1; + PR_AddLoadFunc (&test_pr, init_edicts); PR_Init (&test_pr);