Skip to content

refactor: single-line CVAR declarations - #887

Open
WofWca wants to merge 1 commit into
ioquake:mainfrom
WofWca:single-line-cvars
Open

refactor: single-line CVAR declarations#887
WofWca wants to merge 1 commit into
ioquake:mainfrom
WofWca:single-line-cvars

Conversation

@WofWca

@WofWca WofWca commented Aug 9, 2026

Copy link
Copy Markdown

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.

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>
@WofWca

WofWca commented Aug 9, 2026

Copy link
Copy Markdown
Author

I understand that in this project we generally don't change the non-engine stuff.
However, the project still poses itself as a good basis to make mods. I believe that this this change will aid in that significantly.
It's especially important for the purposes of unification: the baseq3a already adopted this, and I plan to open the same MR for some other mods.

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