Skip to content

refactor: single-line CVAR declarations - #22

Open
WofWca wants to merge 1 commit into
clover-moe:masterfrom
WofWca:single-line-cvars
Open

refactor: single-line CVAR declarations#22
WofWca wants to merge 1 commit into
clover-moe:masterfrom
WofWca:single-line-cvars

Conversation

@WofWca

@WofWca WofWca commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Adding new CVARs is a big headache, let's fix it,
using clever macro trickery: include the same file in multiple places,
but make its output different depending on the surrounding #defines.

The approach is taken from OpenJK, apparently it was introduced in
JACoders/OpenJK@b319c52
Similar MR in another project: https://github.com/ec-/baseq3a/pull/25.

How this commit was made:

  1. Create the *_cvar.h files
  2. Move the lines from cvarTable_ts to the *_cvar.h files,
    do simple search and replace to format the lines.
  3. Remove vmCvar_t mycvar; declarations
    (replace with #include).
  4. Remove extern vmCvar_t mycvar; (replace with #include).

Note that this keeps ui_serverFilterType and cg_gun_frame
out of the CVAR table, so as to not change behavior,
although it would probably make sense to add them.
But let's keep that for another commit.

Regarding the copyright status of this:
the mentioned projects' licenses are not compatible
with GPL-2.0-or-later.
But basically all I took from those projects is the idea,
otherwise I've written this commit by hand.
I also tried to preserve the general coding style of those two projects,
so that they're easier to compare.
I'm adding @LegendaryGuard as a copyright owner
because they expressed the desire to license this
under GPL-2.0-or-later, see https://github.com/ec-/baseq3a/pull/25.

Counterpart MR in ioquake3: ioquake/ioq3#887.
Cherry-pick applied with no conflicts.

Adding new CVARs is a big headache, let's fix it,
using clever macro trickery: include the same file in multiple places,
but make its output different depending on the surrounding `#define`s.

The approach is taken from OpenJK, apparently it was introduced in
JACoders/OpenJK@b319c52
Similar MR in another project: https://github.com/ec-/baseq3a/pull/25.

How this commit was made:
1. Create the `*_cvar.h` files
2. Move the lines from `cvarTable_t`s to the `*_cvar.h` files,
  do simple search and replace to format the lines.
3. Remove `vmCvar_t mycvar;` declarations
  (replace with `#include`).
4. Remove `extern vmCvar_t mycvar;` (replace with `#include`).

Note that this keeps `ui_serverFilterType` and `cg_gun_frame`
out of the CVAR table, so as to not change behavior,
although it would probably make sense to add them.
But let's keep that for another commit.

Regarding the copyright status of this:
the mentioned projects' licenses are not compatible
with GPL-2.0-or-later.
But basically all I took from those projects is the idea,
otherwise I've written this commit by hand.
I also tried to preserve the general coding style of those two projects,
so that they're easier to compare.
I'm adding @LegendaryGuard as a copyright owner
because they expressed the desire to license this
under GPL-2.0-or-later, see https://github.com/ec-/baseq3a/pull/25.

Co-authored-by: LegendaryGuard <rootuser999@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant