Commit Graph

5154 Commits

Author SHA1 Message Date
Bill Currie a1c1c9fcf0 [gamecode] Add test for conversions to double
And fix an incorrect base index in the bool64 tests.
2022-01-14 15:51:49 +09:00
Bill Currie 1f73b26d24 [gamecode] Correct incorrect bool32-bool64 conversion
And add tests for long, ulong and bool64 conversions.
2022-01-14 14:54:35 +09:00
Bill Currie 4bf934e6b9 [gamecode] Correct incorrect bool64-bool32 conversion
And add tests for float, uint and bool32 conversions.
2022-01-14 13:54:03 +09:00
Bill Currie e26fb49df7 [gamecode] Get conversion to int working for all types
Bools turned out to be a problem to due to me wanting any non-zero value
to be treated as true thus had to expand them out as well as the
floating point <-> integral conversions.
2022-01-14 12:11:23 +09:00
Bill Currie cd68455e46 [gamecode] Add tests for converting to int
They currently fail because for vector values, gcc casts the view, not
the value, so vec4 cast to ivec4 simply views the bits as int rather
than doing the actual conversion.
2022-01-14 12:11:22 +09:00
Bill Currie e8e0a69628 [gamecode] Add conversions to/from bool
For now, from bool results in 0/1, but conversion to bool guarantees
0/-1 and correct interpretations for floating point types.
2022-01-13 17:37:44 +09:00
Bill Currie ba1d73200f [gamecode] Clean up a pile of duplicate code
All those duplicated formats were getting unwieldy, especially as I want
to add more conversion modes.
2022-01-13 16:10:06 +09:00
Bill Currie 3eb2194343 [gamecode] Invert the meaning of the skip matrix
Rather than specifying that the conversion should be skipped, it now
specifies the mode of the conversions (with 0 being no conversion). This
is in preparation for boolean conversion.
2022-01-13 15:58:12 +09:00
Bill Currie 6f6f47e27e [gamecode] Drop bool ops in favor of long bit ops
I realized that being able to do bit-wise operations with 64-bit values
(and 256-bit vectors) is far more important than some convenient boolean
logic operators. The logic ops can be handled via the bit-wise ops so
long as the values are all properly boolean, and I plan on adding some
boolean conversion ope, so no real loss.
2022-01-13 14:24:11 +09:00
Bill Currie 424bdcbf96 [gamecode] Implement the scale instructions
Both float 2,3,4 vectors and double 2,3,4 vectors (1 would be just a
copy of the mul instructions).

This completes the currently planned instructions. Now for testing.
2022-01-13 13:53:07 +09:00
Bill Currie 3587b13a40 [gamecode] Implement the conversion instructions
Not all possibilities are supported because converting between int and
uint, and long and ulong is essentially a no-op. However, thanks to
Deek's suggestion, not only are all reasonable conversions available,
conversions for all widths are available, so vector conversions are
supported.

The code for the conversions is generated.
2022-01-13 13:51:24 +09:00
Bill Currie f7181a09b4 [gamecode] Add tests for shiftops
They're in test-unsigned because 2/3 of them are unsigned.
2022-01-12 10:24:59 +09:00
Bill Currie 6229ae8ecc [gamecode] Add tests for unsigned comparisons
And fix the implementation: I had used the wrong macro.
2022-01-11 13:00:54 +09:00
Bill Currie e7d7ec1989 [gamecode] Add tests for signed comparison ops
Fortunately, they all pass without issues.
2022-01-11 09:37:38 +09:00
Bill Currie 0fb6619585 [gamecode] Compact the convert instructions into one
Thanks to Deek for the suggestion: the mode (ie, src and dst types) are
encoded in st->b. Actual code not written yet, but this frees up 13
instructions: now have 74 available for really interesting stuff :)
2022-01-10 11:53:57 +09:00
Bill Currie b9e32ee2f5 [gamecode] Rework call and return instructions
The call1-8 instructions have been removed as they are really not needed
(they were put in when I had plans of simple translation of v6p progs to
ruamoko, but they joined the dinosaurs).

The call instruction lost mode A (that is now return) and its mode B is
just the regular function access. The important thing is op_c (with
support for with-bases) specifies the location of the return def.

The return instruction packs both its addressing mode and return value
size into st->c as a 3.5 value: 3 bits for the mode (it supports all
five addressing modes with entity.field being mode 4) and 5 for the
size, limiting return sizes to 32 words, which is enough for one 4x4
double matrix.

This, especially with the following convert patch, frees up a lot of
instructions.
2022-01-10 11:53:14 +09:00
Bill Currie ba29be3f82 [gamecode] Rename ifnot and if to be less confusing
I think :) anyway, now they're ifz and ifnz, making them consistent with
the rest of the if instructions.
2022-01-10 11:27:57 +09:00
Bill Currie db7a67e5b7 [gamecode] Rearrange vector instructions
This allows the dot products to be consistent with their sizes: cdot is
really dot_2, vdot dot_3, and qdot dot_4.
2022-01-10 11:16:55 +09:00
Bill Currie 494a6908bb [gamecode] Improve with's comment 2022-01-10 11:04:43 +09:00
Bill Currie 86e81ba250 [gamecode] Rearrange the branch instructions
Now they're in a much more consistent arrangement, in particular with
the comparison opcodes if the conditional branch instructions are
considered to be fast comparisons with zero (ifnot -> ifeq, if -> ifne,
etc). Unconditional jump and call fill in the gaps. The goal was to get
them all in an arrangement that would work as a small enum for qfcc: it
can use the enum directly for the ruamoko IS, and a small map array for
v6p (except for call).
2022-01-09 01:07:23 +09:00
Bill Currie 7d5c692313 [gamecode] Generate the new opcodes enum too
It turns out I'll be tweaking it more than I expected.
2022-01-09 01:04:51 +09:00
Bill Currie 4111d44dcc [gamecode] Move progs auxiliary headers into a subdirectory
Just another step along the road of tidying up the QF include directory
(and desirable for generated data).
2022-01-09 00:26:52 +09:00
Bill Currie ed6b84fbde [gamecode] Add missed long and ulong info
Both pr_type_size and pr_type_name. I want to macroize the enum, but
need to sort out the clutter of headers first, just need to decide on
naming. This at least sorts out the missed values for now.
2022-01-08 03:07:17 +09:00
Bill Currie e186d5064d [gamecode] Correct return's opname
Not meant to have the size in it.
2022-01-07 21:48:19 +09:00
Bill Currie 8559a4fe2d whitespace 2022-01-07 21:48:02 +09:00
Bill Currie 14d95f81d1 [gamecode] Remove PR_Opcode_Init
It was idempotent, then it became impotent. Now it's just not needed.
2022-01-07 19:25:34 +09:00
Bill Currie aee31a8be5 [sys] Use tailless INT64_C macro
I guess I missed the non-internal version when searching for it before.
2022-01-06 22:27:42 +09:00
Bill Currie 1cb35b1fe3 [gamecode] Fix some more operand formats
With and relative branches.
2022-01-06 22:27:09 +09:00
Bill Currie 0d9294d541 [gamesource] Work around a windows gcc bug
The bug (alignment issues with AVX on windows) seems to have in gcc from
the 4.x days, and is still present in 11.2: it does not ensure stack
parameters that need 32 byte alignment are aligned. Telling gcc to use
the sysv abi (safe on a static function) lets gcc do what it does for
linux (usually pass the parameters in registers, which it seems to have
done).
2022-01-06 22:21:24 +09:00
Bill Currie c3317f8e5e [gamecode] use INT64_C instead of l-suffix
Once again, I had forgotten that long is not always 64-bits.
2022-01-06 22:20:16 +09:00
Bill Currie 80c5e2c3f6 [simd] Remove requirements for AVX2 for vec4d
It seems gcc-11 does a pretty good job of emulating the instructions (it
no longer requires avx2 for 256-bit wide vectors).
2022-01-06 18:06:56 +09:00
Bill Currie c0277c0b03 [gamecode] Fix incorrect entity load format
Had a typo in load and forgot to edit lea, but now they share the
formats (like they should have in the first place).
2022-01-06 11:51:38 +09:00
Bill Currie d9d37fda47 [gamecode] Implement ruamoko opcode lookup
And get the debugger working with the new instruction set.
2022-01-06 11:47:05 +09:00
Bill Currie c74cfb9bf6 [gamecode] Generate instruction widths and types
Not everything is correct, but this is enough to get started on
supporting disassembly in the various tools and code generation in qfcc.
2022-01-05 22:33:59 +09:00
Bill Currie c9b2a740a0 [gamecode] Add etypes for long and ulong
And partial implementations in qfcc (most places will generate an
internal error (not implemented) or segfault, but some low-hanging fruit
has already been implemented).
2022-01-05 22:32:07 +09:00
Bill Currie 0b92cd3a88 [gamecode] Generate the new opcode table
As I expect to be tweaking things for a while, it's part of the build
process. This will make it a lot easier to adjust mnemonics and argument
formats (tweaking the old table was a pain when conventions changed).

It's not quite done as it still needs arg widths and types.
2022-01-05 19:09:07 +09:00
Bill Currie 0b674f5ed4 [gamecode] Clean up some opcode names
While working on the new opcode table, I decided a lot of the names were
not to my liking.  Part of the problem was the earlier clash with the
v6p opcode names, but that has been resolved via the v6p tag.
2022-01-05 19:04:43 +09:00
Bill Currie 6d9c63999c [gamecode] Rename pr_opcode.c
Just to make way for new tables :)
2022-01-04 20:45:45 +09:00
Bill Currie 35387b5450 [gamecode] Fix a pile of incorrect base register refs
The problem with copying code is it's all to easy to forget to make all
necessary edits.
2022-01-04 19:01:05 +09:00
Bill Currie 59292393e6 [gamecode] Fix up MOD (%%) for integral types
Use the new "1" versions of loadvec3 to get a 1 in w to avoid
divide-by-zero errors, and use the correct type for longs (forgot to
change i to l on the vector types).
2022-01-04 18:36:13 +09:00
Bill Currie 2f09ece65b [gamecode] Add more modes to WITH
It turned out I had no way of using a pointer or field as the value to
load, so all 4 modes are duplicated with loads from where operand b
points, but the loaded value interpreted the same way. Also, fixed an
error in the calculation of op-b offsets.
2022-01-04 17:55:20 +09:00
Bill Currie f2b258ba76 [gamecode] Add statement bounds checking
Statements can be bounds checked in the one place (jump calculation),
but memory accesses cannot as they can be used in lea instructions which
should never cause an exception (unless one of lea's operands is OOB).
2022-01-04 17:53:10 +09:00
Bill Currie 9d74fcc181 [gamecode] Add tests for the basic math ops
* / % %% + -

As a bonus, includes partial tests for a few extra operators. Several
things are broken at this stage, but uncommitted code is already
working.
2022-01-04 17:50:49 +09:00
Bill Currie 5de4c21557 [gamecode] Fix relative offset jumps
Yet another missed sign extension.
2022-01-04 14:30:20 +09:00
Bill Currie 4777f44ba1 [gamecode] Rename test-math to test-vector
I decided to stick with the minimal tests per test program rather than
try to cram all the math operator tests into the one program.
2022-01-03 23:50:38 +09:00
Bill Currie a6badaa05d [gamecode] Complete the vector instruction tests
Finish up the float tests and add double tests.
2022-01-03 23:27:01 +09:00
Bill Currie 6de1ba6901 [gamecode] Clean up the conversion instructions
Float bit-ops as well.

Also, add q*v4 and v4*q instructions. There are currently 48 free
opcodes, and I might remove the scale instructions, but they could be
useful as expanding a single float to a vector would take 3 instructions
(copy to temp, swizzle-expand temp, multiply, vs just scale).
2022-01-03 23:27:01 +09:00
Bill Currie b6f9b68434 [gamecode] Implement 64-bit swizzles
See commit for 32-bit swizzles.
2022-01-03 23:27:01 +09:00
Bill Currie bebc811f11 [gamecode] Implement 4-component 32-bit swizzle
The swizzle instruction is very powerful in that in can do any of the
256 permutations of xyzw, optionally negate any combination of the
resulting components, and zero any combination of the result components
(even all). This means the one instruction can take care of any actual
swizzles, conjugation for complex and quaternion values, zeroing vectors
(not that it's the only way), and probably other weird things.

The python file was used to generate the jump table and actual swizzle
code.
2022-01-03 23:27:01 +09:00
Bill Currie b8d04874c3 [gamecode] Add some math tests
Hit a show stopper when it came to swizzle (not implemented yet). I
guess I know what I need to do next :P.
2022-01-03 23:27:01 +09:00
Bill Currie fd298f3601 [gamecode] Create a mask for extracting the opcode
Got tired of copying the full thing around.
2022-01-03 23:27:01 +09:00
Bill Currie ffbb6122b9 [gamecode] Add tests for push and pop 2022-01-03 23:27:01 +09:00
Bill Currie c86f1f671b [gamecode] Add tests for load instructions
This needed the test struct declaration to be moved out to a head file
so it can be shared with other tests.
2022-01-03 23:27:01 +09:00
Bill Currie 28df32eb0d [gamecode] Use pr_memset instead of memset
This keeps things inline and matches the quakec exec loop. Also removes
the need to calculate the size.
2022-01-03 23:27:01 +09:00
Bill Currie bf604b99b3 [gamecode] Add automated tests for store ops
They even found a bug in the addressing mode functions :) (I'd forgotten
that I wanted signed offsets from the pointer and thus forgot to cast
st->b to short in order to get the sign extension)
2022-01-03 23:27:01 +09:00
Bill Currie 920c5fd99b [gamecode] Add debug event name strings
Makes it easier to print nice debug event messages.
2022-01-03 23:26:50 +09:00
Bill Currie 8a2788c267 [gamecode] Add PROG_V6P_VERSION and bump PROG_VERSION
This allows the VM to select the right execution loop and qfcc currently
still produces only the old IS (it doesn't know how to deal with the new
IS yet)
2022-01-03 13:56:43 +09:00
Bill Currie 925797b1d4 [gamecode] Add a new Ruamoko instruction set
When it's finalized (most of the conversion operations will go, probably
the float bit ops, maybe (very undecided) the 3-component vector ops,
and likely the CALLN ops), this will be the actual instruction set for
Ruamoko.

Main features:
 - Significant reduction in redundant instructions: no more multiple
   opcodes to move the one operand size.
 - load, store, push, and pop share unified addressing mode encoding
   (with the exception of mode 0 for load as that is redundant with mode
   0 for store, thus load mode 0 gives quick access to entity.field).
 - Full support for both 32 and 64 bit signed integer, unsigned integer,
   and floating point values.
 - SIMD for 1, 2, (currently) 3, and 4 components. Transfers support up
   to 128-bit wide operations (need two operations to transfer a full
   4-component double/long vector), but all math operations support both
   128-bit (32-bit components) and 256-bit (64-bit components) vectors.
 - "Interpreted" operations for the various vector sizes: complex dot
   and multiplication, 3d vector dot and cross product, quaternion dot
   and multiplication, along with qv and vq shortcuts.
 - 4-component swizzles for both sizes (not yet implemented, but the
   instructions are allocated), with the option to zero or negate (thus
   conjugates for complex and quaternion values) individual components.
 - "Based offsets": all relevant instructions include base register
   indices for all three operands allowing for direct access to any of
   four areas (eg, current entity, current stack frame, Objective-QC
   self, ...) instructions to set a register and push/pop the four
   registers to/from the stack.

Remaining work:
 - Implement swizzle operations and a few other stragglers.
 = Make a decision about conversion operations (if any instructions
   remain, they'll be just single-component (at 14 meaningful pairs,
   that's a lot of instructions to waste on SIMD versions).
 - Decide whether to keep CALL1-CALL8: probably little point in
   supporting two different calling conventions, and it would free up
   another eight instructions.
 - Unit tests for the instructions.
 - Teach qfcc to generate code for the new instruction set (hah, biggest
   job, I'm sure, though hopefully not as crazy as the rewrite eleven
   years ago).
2022-01-03 00:49:49 +09:00
Bill Currie 0c17c6dc24 [gamecode] Rename the old opcodes
To reflect their basis on v6 progs instructions, they sport the v6p tag
where the p is for "plus" due to the QuakeForge extensions.
2022-01-02 21:30:02 +09:00
Bill Currie bc0a09f452 [gamecode] Switch to using type parameter op macros
I wish I'd done it this way years ago (but maybe gcc 2.95 couldn't hack
the casts, I do know there were aliasing problems in the past). Anyway,
this makes operand access much more consistent for variable sized
operands (eg float vs double vs vec4), and is a big part of the new
instruction set implementation.
2022-01-02 20:46:32 +09:00
Bill Currie 7b0eceda32 [gamecode] Split out the old quake c execution loop
There is no reasonable way (due to hardware-enforced alignment issues)
to simply convert old bytecode to new (probably best done with an
off-line tool, preferably just recompiling when I get qfcc up to the
job), so both loops will need to be present. This just moves the
original loop into its own function in order to make it easy to bring in
the new (and iron out integration issues).
2022-01-02 20:16:45 +09:00
Bill Currie ba5f6d97c6 [gamecode] Remove the right_associative field
It has been useless pretty much since I switched to using bison for the
parser.
2022-01-02 19:09:58 +09:00
Bill Currie 0e1964bf74 [simd] Split out the ivec implementations
And add any/all/none functions.
2022-01-02 16:02:57 +09:00
Bill Currie 5fb28d7c38 [math] Clean up vector component operations
And add a unary op macro. Having VectorCompOp makes it easy to write
macros that work for multiple data widths, which is why it and its users
now use (dst, ...) instead of (..., dst) as in the past. I'll sort out
the other macros later now that I know the compiler handily gives
messages about the switched order (uninitialized vars etc).
2022-01-02 01:15:17 +09:00
Bill Currie 937f36384b [cexpr] Use correct functions for double trunc/floor
Found while sorting out the changes for the new 2d vectors.
2022-01-02 01:13:17 +09:00
Bill Currie 97034d9dde [simd] Add 2d vector types
For int, long, float and double. I've been meaning to add them for a
while, and they're part of the new Ruamoko instructions set (which is
progressing nicely).
2022-01-02 00:57:55 +09:00
Bill Currie 365762b8a6 [gamecode] Switch to using indexed initializers
The opcode table is a nightmare to maintain, but this does clean it up
and speed up opcode lookups since they can now be indexed. Of course, it
turns out I had missed adding several instructions, so had to fix that,
and qfcc needed a bit of a re-jigger to get the opcode out of the table.
2021-12-31 19:16:02 +09:00
Bill Currie be474d9937 [gamecode] Remove the wart from def and function names
I never liked the leading s_ (though I guess it means one is supposed to
interpret the int as a string pointer, but meh).
2021-12-31 15:02:31 +09:00
Bill Currie 70aaafda10 [ruamoko] Clear dtable list on reset
The list of all allocated dispatch tables is used to free all the tables
when the progs are reloaded. Not clearing the list meant that the next
instance (second map change) corrupted the list.
2021-12-30 00:21:29 +09:00
Bill Currie 3c17efe91b [console] Unhook hooked functions on shutdown
Forgetting to unhook the functions (Sys_Printf and the client console's
input event handler) was not a problem for static builds because the
functions were always present, but in builds with dynamic plugins, the
client console's code got ripped away and thus Sys_Printf and the event
hander were being sent into invalid memory. Too much work, not enough
play (with a fully installed client).
2021-12-29 21:50:38 +09:00
Bill Currie 5f4a330b02 [console] Tweak the server status bar colors
Now the yellow stands out nicely.
2021-12-28 00:06:12 +09:00
Bill Currie 1be220559a [zone] Add function to retrieve memory usage 2021-12-27 20:12:03 +09:00
Bill Currie 65f78b43ac [gamecode] Try to set field def size
This fixes the edicts command not printing anything useful.
2021-12-27 19:02:39 +09:00
Bill Currie 94871671d2 [qw] Use a callback for netchan logging
This gets outgoing packet logging working again. Yay, fill my hard-drive
faster ;)
2021-12-27 17:54:58 +09:00
Bill Currie cafc6a541f [gamecode] Get PR_Profile working
The switch from using pr_functions (dfunction_t) to function_table
(bfunction_t) for keeping track of the current function (and thus
profiling data) broke PR_Profile as it never saw anything but 0.
2021-12-27 13:50:49 +09:00
Bill Currie 6368791d2b [gamecode] Check entity_var is valid before display
Even NUM_FOR_BAD_EDICT will have a bad day if the edict pointer is
invalid, so make sure that the entity pointer is valid (within the edict
area AND a multiple of edict size).
2021-12-27 13:47:55 +09:00
Bill Currie f373192a02 [gamecode] Set pr_string_resources in PR_Strings_Init
Like for debug, this is the most sensible place as the pointer will
never change.
2021-12-26 22:46:07 +09:00
Bill Currie 5588d0de60 [gamecode] Separate debug byte-swap and pointer init
PR_LoadDebug now does only the initial version and crc checks, and the
byte-swapping of the loaded symbols file. PR_DebugSetSym sets up all the
pointers.
2021-12-26 22:39:37 +09:00
Bill Currie c9f372fa38 [gamecode] Set pr_debug_resources in PR_Debug_Init
And use the cached value in PR_LoadDebug.
2021-12-26 20:35:09 +09:00
Bill Currie c163b311d0 [gamecode] Create hash tables in PR_Init
This makes much more sense than in PR_LoadProgsFile (and simplifies the
latter, too).
2021-12-26 20:33:37 +09:00
Bill Currie c11a930436 [simd] Set the homogeneous coord in the csvf test
The homogeneous coord was not being initialized and thus was picking up
rubbish from the stack. This is why the test would succeed in some
circumstances but fail in others.
2021-12-26 12:25:06 +09:00
Bill Currie 8385046486 [qfcc] Warn when super dealloc invocation is missing
Forgetting to invoke [super dealloc] in a derived class's -dealloc
method has caused me to waste far too much time chasing down the
resulting memory leaks and crashes. This is actually the main focus of
issue #24, but I want to take care of multiple paths before I consider
the issue to be done.

However, as a bonus, four cases were found :)
2021-12-24 22:45:43 +09:00
Bill Currie 5bfe0e5d34 [sw] Update for changed particle field names
Fixes 32-bit x86 target builds.
2021-12-24 19:33:06 +09:00
Bill Currie 2b25748cc4 [ruamoko] Correct SetIterator memory handling
This makes SetIterator more compatible with autorelease.
2021-12-24 06:45:13 +09:00
Bill Currie 7571231100 [input] Get single axis info for unbound devices
This doesn't fix the problem of keyhelp not working for axes belonging
to unbound devices, but may be a step in the right direction.
2021-12-24 06:45:13 +09:00
Bill Currie 2e3e9ea7c0 [ruamoko] Actually save the cooke
This fixes the listener leak.
2021-12-24 06:45:13 +09:00
Bill Currie f77da210ff [ruamoko] Merge listener cookie code
I know that duplication would turn around and bite me :P
2021-12-24 06:45:13 +09:00
Bill Currie b726c24b05 [ruamoko] Reset parameters before setting in listener
It's right there in the docs, even (though only on the macro, which I'd
forgotten about). Fixes some nasty corruption.
2021-12-24 06:45:13 +09:00
Bill Currie dad19aa2ad [input] Correct balanced range calculation
Fixes axis inputs being half what they should be. Can't quite get +1,
though (need to figure something out for the positive axis range being
slightly smaller than the negative range).
2021-12-24 06:45:13 +09:00
Bill Currie f3918471d5 [ruamoko] Add bindings for the main IMT functions
IMT_SetContextCbuf is not bound as that requires cbuf to be bound.
However, imt contexts can be created, fetched and set.
2021-12-24 06:45:13 +09:00
Bill Currie 0c41c11f1d [gamecode] Use a new developer flag for builtin debug
rua_resolve works for now
2021-12-24 06:45:13 +09:00
Bill Currie 6d64b2c47c [vulkan] Build particle buffers 2021-12-24 06:45:13 +09:00
Bill Currie a4c4155a51 [vulkan] Clean up packet submission
In the end, there's no need for the two paths and I want to be able to
submit empty packets with semaphores.
2021-12-24 06:45:13 +09:00
Bill Currie dcd1fa28ba [ruamoko] Get the input bindings working
With some hacks that are not included (plan on handling events and
contexts properly), button inputs, including using listeners, are
working nicely: my little game is working again. While the trampoline
code was a bit repetitive (and I do want to clean that up), connecting
button listeners directly to Ruamoko instance methods proved to be quite
nice.
2021-12-24 06:45:13 +09:00
Bill Currie 23e3b4c2e5 [ruamoko] Retrieve a plitem_t from PropertyList
And also internally for cross-builtin use.
2021-12-24 06:45:13 +09:00
Bill Currie f1d097c0c4 [ruamoko] Add bindings for Mercenne Twister 2021-12-24 06:45:13 +09:00
Bill Currie 91a686d1f5 [util] Add mtwist float random number functions
mtwist_rand_0_1 produces numbers in the range [0, 1) and
mtwist_rand_m1_1 produces numbers in the range (-1, 1). The numbers will
not be denormal, so the distribution should be fairly uniform (as much
as Mersenne Twister itself is), but this needs proper testing.

0 is included for the mtwist_rand_0_1 as it seems useful, but -1 is not
included in mtwist_rand_m1_1 in order to keep the extremes of the
distribution balanced around 0.
2021-12-24 06:45:13 +09:00
Bill Currie 6411518603 [ruamoko] Make some progress on the input bindings 2021-12-24 06:45:13 +09:00
Bill Currie 3cb93d4cbe [input] Add functions to get single axis/button info
Handy for retrieving the current state (raw) of a single axis or button.
2021-12-24 06:45:13 +09:00
Bill Currie 803c9defae [input] Clean out more keys.h refs 2021-12-24 06:45:13 +09:00
Bill Currie 33e48025dd [ruamoko] Replace rua_key with rua_input
And create rua_game to coordinate other game builtins.

Menus are broken for key handling, but have been since the input rewrite
anyway. rua_input adds the ability to create buttons and axes (but not
destroy them). More work needs to be done to flesh things out, though.
2021-12-24 06:45:13 +09:00
Bill Currie 2cb987fdb5 [build] Clean up a pile of distcheck issues 2021-12-24 06:45:13 +09:00
Bill Currie 2d109e615b [client] Clean up a stray reference to the renderer
Reaching into the renderer internals for r_worldmodel doesn't work when
the plugins are not static.
2021-12-24 06:45:13 +09:00
Bill Currie 194f958666 [console] Add a comment about skipping the first char
I had to dig through logs of deleted files to find out what was going
on. Forget six months later, twenty years...
2021-12-24 06:45:13 +09:00
Bill Currie e0863ff067 [net_chan] Clean out unnecessary include
net_chan was still including client.h from qw when it no longer needed
it (I guess I forgot to clean that out when I resolved any last
dependencies).
2021-12-24 06:45:13 +09:00
Bill Currie d70d72e6e4 [particles] Create a psystem object
This takes care of the global variables to a point (there is still the
global struct shared between the non-vulkan renderers), but it also
takes care of glsl's points-only rendering.
2021-12-24 06:45:13 +09:00
Bill Currie 372c89b479 [particles] Merge physics code
The particle physics is called by the renderer.
2021-12-24 06:45:13 +09:00
Bill Currie 8d2791752e [particles] Merge particle spawning into client
After yesterday's crazy marathon editing all the particles files, and
starting to do another big change to them today, I realized that I
really do need to merge them down. All the actual spawning is now in the
client library (though particle insertion will need to be moved). GLSL
particle rendering is semi-broken in that it now does only points (until
I come up with a way to select between points and quads (probably a
context object, which I need anyway for Vulkan)).
2021-12-24 06:45:13 +09:00
Bill Currie 81a5e076ac [vulkan] Move render pass array init
Having it in Vulkan_Init_Common means the array can be used in more
places than just Vulkan_CreateRenderPass (which probably needs a
rename).
2021-12-24 06:45:13 +09:00
Bill Currie 2be19046b6 [vulkan] Allow render passes to not have a render pass
This may seem a little contradictory, but it's due to the difference
between a high level (engine) render pass and a Vulkan render pass
object (and quite likely a poor choice in names for the high level
object). This is necessary for supporting compute shader dispatches as
they cannot be submitted inside a Vulkan render pass.
2021-12-24 06:45:13 +09:00
Bill Currie 43cdca330b [client] Add bindings for load and quickload in demos 2021-12-24 06:45:13 +09:00
Bill Currie aacd2575d2 [sw,sw32] Ensure the particle system is initialized
This fixes the missing particles (because mtwist_rand was returning 0).
2021-12-24 06:45:13 +09:00
Bill Currie ce4bb1d56c [renderer] Move particles over to simd
This has the advantage of getting entity_t out of the particle system,
and much easier to read math. Also, it served as a nice test for my
particle physics shaders (implemented the ideas in C). There's a lot of
code that needs merging down: all but the actual drawing can be merged.

There's some weirdness with color ramps, but I'll look into that later.
2021-12-24 06:45:13 +09:00
Bill Currie 4d1e8b2375 [vulkan] Update the number of drawn quads correctly
They should increment by one for each pic, not 4 (I think some fluff
remaining from copying glsl's draw code).

I noticed the problem when I saw large gaps of 0s in the vertex data in
renderdoc.
2021-12-24 06:45:13 +09:00
Bill Currie be7216e660 [vulkan] Implement crosshair rendering
That makes quite the difference to playability.
2021-12-24 06:45:13 +09:00
Bill Currie 6b84ae5554 [renderer] Update crosshair color on palette changes
This gets the crosshair working in Vulkan (next commit) and fixes issues
with changing the palette (though I've never seen a different palette
for quate, there's still the change from "all black" to an actual
palette).
2021-12-24 06:45:13 +09:00
Bill Currie 83ec2be2a6 [vid] Add a listener set for palette changes
This was needed to get crosshaircolor working correctly, but is likely
another step towards resizable windows (the listener set types are
generic for any viddef event, not just palette changes).
2021-12-24 06:45:13 +09:00
Bill Currie cd641e2b1c [vulkan] Clean up alias push-constants 2021-12-24 06:45:13 +09:00
Bill Currie 8b1eec08cf [scene] Provide direct access to the world matrix
Holding onto the pointer is not a good idea, and it is read-only as
direct manipulation of the world matrix is not supported. However, this
is useful for passing the matrix to the GPU.
2021-12-24 06:45:13 +09:00
Bill Currie 869cc4050c [vulkan] Flush bsp vertex indices after all drawing 2021-12-24 06:45:13 +09:00
Bill Currie 36e98f013e [vulkan] Clean up bsp push-constants. 2021-12-24 06:45:13 +09:00
Bill Currie 081c46da7a Clean up some white space 2021-12-24 06:45:13 +09:00
Bill Currie b9bc3fa132 [vulkan] Split out the push constants helper
It proved to work well in the sprite pipeline, and should be useful for
cleaning up the magic numbers in bsp and alias.
2021-12-24 06:45:13 +09:00
Bill Currie 0b99ff104d [vulkan] Clear the color attachments
This means color, emission, and translucent. Fixes the HOM issues on my
VersaPro (but halves the frame-rate... definitely need to bring back the
forward renderer as an option).
2021-12-24 06:45:13 +09:00
Bill Currie db6c76d583 [vulkan] Abandon bindless rendering
At least for now, it is more trouble than it is worth as it (or my
implementation of it) breaks lavapipe and renderdoc.
2021-12-24 06:45:13 +09:00
Bill Currie 8228146ac0 [vulkan] Use the particle system buffer for indirect draws
I realized I'd need to get the particle counts out to the draw commands
somehow, and this seemed to be the most natural way.
2021-12-24 06:45:13 +09:00
Bill Currie 6aaf5c3722 [vulkan] Start work on particles for Vulkan
This gets the pipelines loaded (and unloaded on shutdown). Probably the
easy part :P. Still need to sort out the command buffers,
synchronization, and particle generation (and probably a bunch else
that's not coming to mind).
2021-12-24 06:45:13 +09:00
Bill Currie 9dcaa98205 [vulkan] Clean up a pile of C&P fluff 2021-12-24 06:45:13 +09:00
Bill Currie e0af6541e6 [vulkan] And a bunch of buffer barrier transitions
These seem to be the most likely ones for compute shaders (some based on
my ideas for particles).
2021-12-24 06:45:13 +09:00
Bill Currie 7901f87960 [vulkan] Add support for compute shaders
This needed changing Vulkan_CreatePipeline to
Vulkan_CreateGraphicsPipeline for consistency (and parsing the
difference from a plist seemed... not worth thinking about).
2021-12-24 06:45:13 +09:00
Bill Currie 0d4ece875d [vulkan] Use indexed initializers for barriers
This will make maintaining the arrays much easier: no worries about
getting things out of sync.
2021-12-24 06:45:13 +09:00
Bill Currie 6a7f78485a [zone] Use memccpy instead of strncpy
Probably the best way to tell gcc I know what I'm doing.
2021-12-24 06:45:13 +09:00
Bill Currie f7c14a9b39 [sw32] Use the shared R_GetSpriteFrame
One less copy of near-identical code.
2021-12-24 06:45:13 +09:00
Bill Currie 5223752f9e [vulkan] Fix lighting size calculation
It turns out the required memory size is not guaranteed to be aligned.
2021-12-24 06:45:13 +09:00
Bill Currie c366b1b7bb [vulkan] Implement the sprite render passes
It turned out the bindless approach wouldn't work too well for my design
of the sprite objects, but I don't think that's a big issue at this
stage (and it seems bindless is causing problems for brush/alias
rendering via renderdoc and on my versa pro). However, I have figured
out how to make effective use of descriptor sets (finally :P).

The actual normal still needs checking, but the sprites are currently
unlit so not an issue at this stage.
2021-12-24 06:45:13 +09:00
Bill Currie dafe591446 [renderer] Start merging sprite frame calculation
This covers gl and sw. sw32 should be trivial (just haven't done it),
but glsl will take a little. Vulkan will use it.
2021-12-24 06:45:13 +09:00
Bill Currie 743a732bd7 [vulkan] Correct the semantics of QFV_NextOffset
I'm not at all sure what I was thinking when I designed it, but I
certainly designed it wrong (to the point of being fairly useless). It
turns out memory requirements are already aligned in size (so just
multiplying is fine), and what I really wanted was to get the next
offset aligned to the given requirements.
2021-12-24 06:45:13 +09:00
Bill Currie 36e0d857a2 [vulkan] Create the non-C side of the sprite pipeline
This adds the shaders and the pipeline specs. I'm not sure that the
deferred rendering side of the render pass is appropriate, but I thought
I'd give it a go, since quake sprites are really cutoff rather than
translucent.
2021-12-24 06:45:13 +09:00
Bill Currie 2db8d11dd0 [vulkan] Clean up some excessive descriptor sets
With the switch to multi-layer textures for brush models, the bsp and
alias texture descriptor sets became identical and thus the definitions
shareable. However, due to complications I don't want to address yet,
they're still separately identified, but I should be able to use the
texture set for most, if not all, pipelines.
2021-12-24 06:45:13 +09:00
Bill Currie 0eb556b8f9 [vulkan] Load sprite model data
The vertices and frame images are loaded into the one memory object,
with the vertices first followed by the images.

The vertices are 2D xy+uv sets meant to be applied to the model
transform frame, and are pre-computed for the sprite size (this part
does support sprites with varying frame image sizes).

The frame images are loaded into one image with each frame on its own
layer. This will cause some problems if any sprites with varying frame
image sizes are found, but the three sprites in quake are all uniform
size.
2021-12-24 06:45:13 +09:00
Bill Currie c5cfcc7bfd [sprite] Separate model and texture loading
As much as it can be since the texture data is interleaved with the
model data in the files (I guess not that bad a design for 25 years ago
with the tight memory constraints), but this paves the way for
supporting sprites in Vulkan.
2021-12-24 06:45:13 +09:00
Bill Currie e7e6dd87e8 [glsl] Fix some const-correct issues for textures 2021-12-24 06:45:13 +09:00
Bill Currie 2b332cfe4a [zone] Clean up some magic numbers 2021-12-24 06:45:13 +09:00
Bill Currie 854c92d10e [simd] Indicate when the circumsphere is degenerate
CircumSphere_vf sets the sphere radius to -1 when the points are
degenerate (co-linear for three points, co-planar for four points).
2021-12-24 06:45:13 +09:00
Bill Currie eee25d21ba [zone] Clean out unnecessary memsets
As the cache blocks are always filled in with a memcpy, there's no need
to zero out the whole allocation, and the header is initialized anyway.
2021-12-24 06:45:13 +09:00
Bill Currie ff40563fc0 [zone] Squeeze cache_system_t to fit into 64 bytes
The cache system pointers are now indices into an array of
cache_system_t blocks, allowing them to be 32 bits instead of 64, thus
allowing cache_system_t to fit into a single CPU cache line. This still
gives and effective 38 bits (256GB) of addressing for cache/hunk. This
does mean that the cache functions cannot work with more than 256GB, but
should that become a problem, cache and working hunking hunk can be
separate, and it should be possible to have multiple cache systems.
2021-12-24 06:45:13 +09:00
Bill Currie d857bdea77 [vulkan] Fix a typo and gcc purity warning 2021-12-24 06:45:13 +09:00
Bill Currie fde47d6983 [quakefs] Clean out some excess memsets
There's no point in zeroing out memory that is only going to be
overwritten by the loaded file (excess bytes beyond the end of a
massaged text file shouldn't be accessed anyway, and the terminating
null is still written).
2021-12-24 06:45:13 +09:00
Bill Currie 2086125e0b [quakefs] Take in the pointer to the global hunk
This is needed for cleaning up excess memsets when loading files because
Hunk_RawAllocName has nonnull on its hunk pointer (as the rest of the
hunk functions really should, but not just yet).
2021-12-24 06:45:13 +09:00
Bill Currie 39c020908c [zone] Return the pointer to the global hunk
In trying to reduce unnecessary memsets when loading files, I found that
Hunk_RawAllocName already had nonnull on it, so quakefs needed to know
the hunk it was to use. It seemed much better to to go this way (first
step in what is likely to be a lengthy process) than backtracking a
little and removing the nonnull attribute.
2021-12-24 06:45:13 +09:00
Bill Currie 0a5981878b [sprite] Clean up field names and casting
No wonder I hated the sprite code: I couldn't see the code for all the
casts (and hungarian warts).
2021-12-24 06:45:13 +09:00
Bill Currie 1df3c2eea0 [renderer] Make R_BillboarFrame's comments true
While they weren't entirely false, they were overly verbose and thus
clouded the point.
2021-12-24 06:45:13 +09:00
Bill Currie 3a17e062da [renderer] Merge sprite billboarding code
As the sw renderer's implementation was the closest to id's, it was used
as the model (thus a fair bit of cleanup is still needed). This fixes
some incorrect implementations in glsl and gl.
2021-12-24 06:45:13 +09:00
Bill Currie 8c5c39cbe4 [vulkan] Mix turb full-brights into main color
I'd forgotten (when doing the original brush texture loader) that
turbulent surfaces were unlit and thus always full-bright, then never
wrote the turb shader to take care of it. The best solution seems to be
to just mix the two colors in the shader as it will allow turb surfaces
to be lit in the future (probably with severely limited light counts due
to being a forward renderer).
2021-12-24 06:45:13 +09:00
Bill Currie d5b824a47c [vulkan] Switch alias pipeline to multi-texture
This gets the alias pipeline in line with the bsp pipeline, and thus
everything is about as functional as it was before the rework (minus
dealing with large texture sets).
2021-12-24 06:45:13 +09:00
Bill Currie 11492d77ce [vulkan] Switch bsp renderer to multi-texture
I guess it's not quite bindless as the texture index is a push constant,
but it seems to work well (and I may have fixed some full-bright issues
by accident, though I suspect that's just my imagination, but they do
look good).
2021-12-24 06:45:13 +09:00
Bill Currie 6fbce335bb [vulkan] Add an array view for default_magenta
The validation layers get very picky about image view types (rightfully
so, I imagine).
2021-12-24 06:45:13 +09:00
Bill Currie 2740f6093b [vulkan] Update shaders and layouts for new scheme
Still need to work on the code, though.
2021-12-24 06:45:13 +09:00
Bill Currie 8422732505 [vulkan] Move matrices into per-frame buffers
This should fix the horrid frame rate dependent behavior of the view
model.

They are also in their own descriptor set so they can be easily shared
between pipelines. This has been verified to work for Draw.
2021-12-24 06:45:13 +09:00
Bill Currie e8961342d5 [vulkan] Fix some mostly harmless typos 2021-12-24 06:45:13 +09:00
Bill Currie d7f588ecfe [vulkan] Rework bsp texture loader
BSP textures are now two-layered with the albedo and emission in the two
layers rather than two separate images. While this does increase memory
usage for the textures themselves (most do not have fullbright pixels),
it cuts down on image and image view handles (and shader resources).
2021-12-24 06:45:13 +09:00
Bill Currie ea4ac894d8 [model] Swap fullbright/top/bottom color func params
This makes them semantically compatible with memcpy.
2021-12-24 06:45:13 +09:00
Bill Currie ff6d6f6dd6 [vulkan] Rework shaders and pipelines for bindless textures
Smashing everything in the process :P (need to work on the C side).
However, while bindless is supposedly good for performance, the biggest
gain this will bring is portability: the texture counts are
automatically limited to what the hardware can handle, and the reliance
on push descriptors is removed (though they were nice and did help get
things up and running).
2021-12-24 06:45:13 +09:00
Bill Currie 3a742f59f7 [vulkan] Copy array() parameters correctly
I had forgotten that the parameters are in reverse order, and even if I
had remembered, I forgot to reset offset before the second loop.
Pre-decrementing offset takes care of both issues at once.
2021-12-24 06:45:13 +09:00
Bill Currie a0c935e8bc [vulkan] Make lighting samplers configurable
My VersaPro doesn't support more than 32 per-stage samplers (lavapipe).
This is a small part of getting Vulkan to run on lavapipe and even in
itself is rather incomplete.
2021-12-24 06:45:13 +09:00
Bill Currie 062f616548 [cexpr] Add support for casting plitems
This allows using references in expressions, eg:

    $frames.size * size_t($properties.limits.maxSamplers)

As references remain property list items until actually evaluated.
2021-12-24 06:45:13 +09:00
Bill Currie e7b067d6a9 [cexpr] Add some functions for size_t and uint
Casting for size_t and uint, and min/max/bound for size_t.
2021-12-24 06:45:13 +09:00
Bill Currie ee1c3e7db5 [cexpr] Clean up the macros a little 2021-12-24 06:45:13 +09:00
Bill Currie f6cc138f48 [vulkan] Provide access to VkPhysicalDeviceLimits
Fixes the warning about parse_fixed_array not being used (oops, the
problem with partial commits), but more importantly, gives access to
things like maxDescriptorSetSamplers.
2021-12-24 06:45:13 +09:00
Bill Currie cff23ac93c [vulkan] Connect up the cexpr library
This will make property list expressions easier to work with. The
library is rather limited right now (trig, dot, min/max/bound) but even
just min adds a lot of functionality.
2021-12-24 06:45:12 +09:00
Bill Currie d2eb928210 [cexpr] Add a small library with some useful functions
For now, just dot product, trig, and min/max/bound, but it works well as
a proof of concept. The main goal was actually min. Only the list of
symbols is provided, it is the user's responsibility to set up the
symbol table and context.
2021-12-24 06:45:12 +09:00
Bill Currie 44102f2639 [cexpr] Support chained contexts for scoping
cexpr's symbol tables currently aren't readily extended, and dynamic
scoping is usually a good thing anyway. The chain of contexts is walked
when a symbol is not found in the current context's symtab, but minor
efforts are made to avoid checking the same symtab twice (usually cased
by cloning a context but not updating the symtab).
2021-12-24 06:45:12 +09:00
Bill Currie 049968b38e white space 2021-12-24 06:45:12 +09:00
Bill Currie 4e8718980f [cexpr] Remove some disabled code
It looks like a munged commit, but I think I had decided that it was
best to make cvar access explicit.
2021-12-24 06:45:12 +09:00
Bill Currie 8271860fb3 [vkgen] Add support for fixed arrays
I want to support reading VkPhysicalDeviceLimits but it has some arrays.
While I don't need to parse them (VkPhysicalDeviceLimits should be
treated as read-only), I do need to be able to access them in property
list expressions, and vkgen generates the cexpr type descriptors too.

However, I will probably want to parse arrays some time in the future.
2021-12-24 06:45:12 +09:00
Bill Currie c8846f8007 [cexpr] Support array indexing
The index is currently limited to ints, and is bounds checked (the array
type has a size field indicating the number of elements).
2021-12-24 06:45:12 +09:00
Bill Currie c73e4efcb7 [vkgen] Don't queue types for fields with custom parsers
This ensures that unused parser blocks do not get emitted. In the
testing of the upcoming support for fixed arrays, the blend color
constants were being double emitted (both as custom and normal parser)
due to being an array. gcc did not like that (what with all those
warning flags).
2021-12-24 06:45:12 +09:00
Bill Currie a522464fc1 [vkgen] Clean up an unnecessary function redirect
I think it was mostly a holdover from early development, but it
certainly makes sense to tuck the functionality away in Struct.
2021-12-24 06:45:12 +09:00
Bill Currie c402275112 [vulkan] Add some more debug stack contexts 2021-12-24 06:45:12 +09:00
Bill Currie 75d06c4f98 [vulkan] Clean out some expired FIXME comments 2021-12-24 06:45:12 +09:00
Bill Currie 928408bad9 [vulkan] Support multiple render passes
Multiple render passes are needed for supporting shadow mapping, and
this is a huge step towards breaking the Vulkan render free of Quake,
and hopefully will lead the way for breaking the GL renderers free as
well.
2021-12-24 06:45:12 +09:00
Bill Currie 84a24dbb34 [renderer] Make R_RenderView private
This is actually a better solution to the renderer directly accessing
client code than provided by 7e078c7f9c.

Essentially, V_RenderView should not have been calling R_RenderView, and
CL_UpdateScreen should have been calling V_RenderView directly. The
issue was that the renderers expected the world entity model to be valid
at all times. Now, R_RenderView checks the world entity model's validity
and immediately bails if it is not, and R_ClearState (which is called
whenever the client disconnects and thus no longer has a world to
render) clears the world entity model. Thus R_RenderView can (and is)
now called unconditionally from within the renderer, simplifying
renderer-specific variants.
2021-12-24 06:45:12 +09:00
Bill Currie eb828007e9 [vulkan] Add a comment about next pass timing 2021-12-24 06:45:12 +09:00
Bill Currie b1ba87e5aa [vulkan] Use the short name for the image types
Yay for coming up with a solution for enums short names that start with
a number, makes things more readable.
2021-12-24 06:45:12 +09:00
Bill Currie 614c744693 [cexpr] Use ` to allow identifiers to start with a number
The generated short names for a lot of Vulkan enums start with a number
(eg VK_IMAGE_TYPE_2D -> 2d). Having to prefix the short name with ` is a
tiny cost for the convenience.
2021-12-24 06:45:12 +09:00
Bill Currie a6703c95cf [plist] Allow ` to be used without quotes
It has no special meaning when parsing property lists, so there's no
reason to require quotes around it.
2021-12-24 06:45:12 +09:00
Bill Currie 9e755f270e [vulkan] Set staging fence timeout to 5 seconds
0.5s seemes to be unreliable on my VersaPro, particularly after a large
build.
2021-12-24 06:45:12 +09:00
Bill Currie 02ba3da0ba [vulkan] Ease writing of specialization data
While using binary data objects for specialization data works for bools
(as they can be 0 or -1), they don't work so well for numeric values due
to having to get the byte order correct and thus are not portable, and
difficult to get right.

Binary data is still supported, but the data can be written as a string
with an array(...) "constructor" expression taking any number of
parameters, with each parameter itself being an expression (though
values are limited at this stage).

Due to the plist format, quotes are required around the expression
("array(...)")
2021-12-24 06:45:12 +09:00
Bill Currie bd31f40c9b [cexpr] Support varargs functions
While there may be better solutions, I needed a varargs function for
building Vulkan specialization data. Like progs functions, negative
parameter counts indicate ellipsis with the number of fixed parameters
being equal to -param_count - 1.
2021-12-24 06:45:12 +09:00
Bill Currie 422ad2a6c9 [vulkan] Recreate lighting pvs sets when loading lights
Sets never shrink, so assigning a dynamically created set to a
statically created set after the working size has reduced (going from
demo2 to demo3) causes the set code to attempt to resize the statically
created set, which leads to libc having a bad time.
2021-12-24 06:45:12 +09:00
Bill Currie 0c0fce2f03 [vulkan] Drop lights with size 0
They can't contribute any light, so no point in keeping them. Fixes the
erroneous size-0 shadow maps in the second nq demo.
2021-12-24 06:45:12 +09:00
Bill Currie 08721f7a21 [vulkan] Destroy the right framebuffers
Why nvidia's drivers accepted double-destroyed framebuffers is beyond
me, but this fixes the Intel drivers complaining about such (and the
subsequent segfault).
2021-12-24 06:45:12 +09:00
Bill Currie 5b1052087a [vulkan] Calculate matrix offset correctly
When I changed the matrices from an array of floats to an array of
vec4f_t, I forgot to update the flush offsets. Yay for having a
Vulkan-capable Intel device with its different alignment requirements.
2021-12-24 06:45:12 +09:00
Bill Currie 25559243ae [vulkan] Add function to compute next offset
When allocating memory for multiple objects that have alignment
requirements, it gets tedious keeping track of the offset and the
alignment. This is a simple function for walking the offset respecting
size and alignment requirements, and doubles as a size calculator.
2021-12-24 06:45:12 +09:00
Bill Currie 8d58dee4b1 [input] Ensure button id is never 0
IN_ButtonAction treats id 0 as not pressed in its internal processing,
and the previous input implementation treated 0 as "no key", so this is
both the simplest and most correct fix.

Fixes mouse left button not working every second time the game is run
(due to keyboard and mouse bindings swapping places in the config file
(separate issue, if it really is one)).
2021-12-18 14:17:40 +09:00
Bill Currie 68de8615d6 [input] Set cbuf of correct imt context
This fixes key_demo bindings not working. Quite the face-palm.
2021-12-17 08:33:13 +09:00
Bill Currie cbf84d815f [client] Add default bindings for key_demo
Just F10 (quite) and ` (toggleconsole) so the two can be used during
demos, but just this is a major improvement.
2021-12-17 08:33:02 +09:00
Bill Currie 9d4017885f [cvar] Preserve cvars loaded from config files
This restores the equivalent functionality that seta in config.cfg
provided (no more losing my volume setting after using -nosound).
2021-12-17 08:32:36 +09:00
Bill Currie 032f9971ed [plist] Remove incorrect const from PL_RemoveObjectForKey
I'm not sure what I was thinking when I made PL_RemoveObjectForKey take
a const plitem. One of those times where C could do with being a little
more strict.
2021-12-17 08:30:00 +09:00
Bill Currie d76cf9202d [x11] Create barriers only when grabbing
While using barriers is a zillion times better than actually grabbing
the mouse and keyboard, they're still a pain when debugging as qf is not
able to respond to the barrier-hit events. All the other logic is still
there so even when "grabbing", the mouse will not be blocked if the
window doesn't have focus.
2021-12-06 07:27:08 +09:00
Bill Currie 8b85e422d7 [vulkan] Add a debug stack to the vulkan instance
The stack is arbitrary strings that the validation layer debug callback
prints in reverse order after each message. This makes it easy to work
out what nodes in a pipeline/render pass plist are causing validation
errors. Still have to narrow down the actual line, but the messages seem
to help with that.
Putting qfvPushDebug/qfvPopDebug around other calls to vulkan should
help out a lot, tool.
As a bonus, the stack is printed before debug_breakpoint is called, so
it's immediately visible in gdb.
2021-11-30 18:10:48 +09:00
Bill Currie 2334798432 [vulkan] Make vulkan_use_validation easier more useful
Rather than just 0/1, it now acts as flags to control what messages are
printed. In addition to the Vulkan enum names (long and short), none and
all are supported (as well as raw numbers, but they're not checked for
validity). This makes vulkan_use_validation a bit easier to use and less
verbose by default.

Now, if only it was easier to remember the name :P
2021-11-30 18:10:48 +09:00
Bill Currie 901619235b [vulkan] Split out cvar enum parsing code
Need to reuse it :)
2021-11-30 18:10:48 +09:00
Bill Currie 52f86adb84 [vulkan] Fail gracefully if vulkan driver init fails
Well, a little more gracefully than a segfault, at least.
2021-11-30 18:10:48 +09:00
Bill Currie c9508f7261 [vkgen] Name-shorten extension enum flag bits
The prefix was being stripped, but not the _BIT_EXT suffix. This makes
extension flags a little easier to use.
2021-11-30 18:10:48 +09:00
Bill Currie 1efeac6d60 [vkgen] Support specifying enum "searches" directly
Being able to parse enums that aren't part of a specified struct is
handy for cvars.
2021-11-30 18:10:18 +09:00
Bill Currie f36fa23666 [client] Block binding of the escape key
Id's binding of escape to togglemenu interfered with the hard-coding
(want escape to togglemenu (or console as a fallback) no matter what).
This idea was part of mercury's original design, too.
2021-11-28 23:22:11 +09:00
Bill Currie b0447c1cf1 [console] Get message modes and menus working again
I'm not at all happy with con_message and con_menu, but fixing them
properly will take a rework of the menus (planned, though). Also, the
Menu_ console command implementations are a bit iffy and could also do
with a rewrite (probably part of the rest of the menu rework) or just
nuking (they were part of Johnny on Flame's work, so I suspect had
something to do with joystick bindings).
2021-11-28 23:21:55 +09:00
Bill Currie 376e838d1c [console] Remove togglechat implementation
It has always been just a clone of toggleconsole, so the command has
been linked to toggleconsole's implementation instead.
2021-11-28 21:17:06 +09:00
Bill Currie 652546a4fb [input] Clean out a lot of obsolete stuff from keys
The new binding system makes much of keys.[ch] obsolete leaving only the
key name translations.
2021-11-27 12:31:24 +09:00
Bill Currie 70c2fdce9e [client] Move default input config to its own file
This makes it much easier to maintain the config.
2021-11-25 20:23:18 +09:00
Bill Currie b01c38903d [x11] Clamp barriers to the screen
It seems X11 does not like creating barriers entirely off the screen,
though the error seems to be a little unreliable (however, off the left
edge was definitely bad).
2021-11-25 20:23:18 +09:00
Bill Currie d1153be594 [build] Move plist rules to root Makefile
They are globally useful rather than specific to the vulkan renderer.
2021-11-25 20:23:18 +09:00
Bill Currie 62f592b92c [input] Create an automatic imt switcher
An imt switcher automatically changes the context's active imt based on
a user specified list of binary inputs. The inputs may be either buttons
(indicated as +button) or cvars (bare name). For buttons, the
pressed/not pressed state is used, and cvars are interpreted as ints
being 0 or not 0. The order of the inputs determines the bit number of
the input, with the first input being bit 0, second bit 1, third bit 2
etc. A default imt is given so large switchers do not need to be fully
configured (the default imt is written to all states).

A context can have any number of switchers attached. The switchers can
wind up fighting over the active imt, but this seems to be something for
the "user" (eg, configuration system) to sort out rather than the
switcher code enforcing anything.

As a result of the inputs being treated as bits, a switcher with N
inputs will have 2**N states, thus there's a maximum of 16 inputs for
now as 65536 states is a lot of configuration.

Using a switcher, setting up a standard strafe/mouse look configuration
is fairly easy.

    imt_create key_game imt_mod
    imt_create key_game imt_mod_strafe imt_mod
    imt_create key_game imt_mod_freelook
    imt_create key_game imt_mod_lookstrafe imt_mod_freelook
    imt_switcher_create mouse key_game imt_mod_strafe +strafe lookstrafe +mlook freelook
    imt_switcher 0 imt_mod 2 imt_mod 4 imt_mod_freelook 8 imt_mod_freelook 12 imt_mod_freelook
    imt_switcher 6 imt_mod_lookstrafe 10 imt_mod_lookstrafe 14 imt_mod_lookstrafe
    in_bind imt_mod mouse axis 0 move.yaw
    in_bind imt_mod mouse axis 1 move.forward
    in_bind imt_mod_strafe mouse axis 0 move.side
    in_bind imt_mod_lookstrafe mouse axis 0 move.side
    in_bind imt_mod_freelook mouse axis 1 move.pitch

This takes advantage of imt chaining and the default imt for the
switcher (there are 8 states that use imt_mod_strafe).

The switcher name must be unique across all contexts, and every imt used
in a switcher must be in the switcher's context.
2021-11-25 20:23:18 +09:00
Bill Currie 1a79915d22 [input] Add axis listeners
The listener is invoked when the axis value changes due to IN_UpdateAxis
or IN_ClampAxis updating the axis. This does mean the listener
invocation make be somewhat delayed. I am a tad uncertain about this
design thus it being a separate commit.
2021-11-25 20:04:08 +09:00
Bill Currie 8e8a573876 [input] Add listeners to buttons
The listener is invoked when the button state changes.
2021-11-25 20:04:08 +09:00
Bill Currie c4118a4bf1 [util] Add listeners to cvars
Listeners are separate to the main callback as listeners have only
read-only access to the objects, but the main callback is free to modify
the cvar and thus can act as a parser and validator. The listeners are
invoked after the main callback if the cvar is modified. There does not
need to be a main callback for the listeners to be invoked.
2021-11-25 17:46:16 +09:00
Bill Currie 3f299155a3 [client] Reimplement legacy bind and unbind commands
This allows id1/qw config files, and to a certain extent scripts, to
work with the new binding system. It does highlight just how limited the
original system was (many keys could not bound).

Mouse axis input does not work yet as that needs a little more work to
support +strafe and +mlook.
2021-11-25 13:36:02 +09:00
Bill Currie 6a395e3416 [input] Remove some cruft
The disabled commands were implemented elsewhere or are no longer
relevant.
2021-11-25 13:36:02 +09:00
Bill Currie fba1a1ac6b [input] Rebuild the button binding string
I had forgotten that Cmd_Args() preserves quotes, which resulted in
button bindings having excess quotes when used to bind complex commands
(eg, the default quicksave and quickload bindings).
2021-11-25 13:36:02 +09:00
Bill Currie 3bd922e473 [input] Correct a typo in in_bind's help text 2021-11-25 13:36:02 +09:00
Bill Currie c069e7754f [util] Add a listener object
I decided cvars and input buttons/axes need listeners so any changes to
them can be propagated. This will make using cvars in bindings feasible
and I have an idea for automatic imt switching that would benefit from
listeners attached to buttons and cvars.
2021-11-25 13:36:02 +09:00
Bill Currie 67735182d7 [x11] Protect XInput2 and XFixes code
This will allow QF to be built in the unlikely event XInput2 or XFixes
are not available. nq-x11 seemed to work nicely with both disabled.
2021-11-24 02:17:08 +09:00
Bill Currie b45acf7974 [x11] Add a comment about grabbing design 2021-11-24 01:51:52 +09:00
Bill Currie 719525a4a1 [x11] Set backed mouse button state for raw presses
Fixes button press events being treated as button releases in the event
handlers.
2021-11-23 23:21:43 +09:00
Bill Currie 28b80d8bf8 [x11] Handle raw motion events (more) correctly
For now, only the first two axis (mouse X and Y) are supported (XInput
treats the scroll wheel events as axes too, so mice have up to 4!), but
most importantly, this prevents the scroll wheel from being seen as the
X axis. Oops.
2021-11-23 23:15:08 +09:00
Bill Currie 1ef99a9130 [input] Separate absolute and relative axis inputs
Combining absolute and relative inputs at the binding does not work well
because absolute inputs generally update only when the physical input
updates, so clearing the axis input each frame results in a brief pulse
from the physical input, but relative inputs must be cleared each frame
(where frame here is each time the axis is read) but must accumulate the
relative updates between frames.

Other than the axis mode being incorrect, this seems to work quite
nicely.
2021-11-23 22:04:17 +09:00
Bill Currie 78b4e8217e [x11] Fix a optimization compiler warning
With the old headers removed, X11_SetGamma became a stub and gcc
complained about it wanting the const attribute. On investigation, it
turned out the X_XF86VidModeSetGamma was a holdover from the initial
implementation of hardware gamma support.
2021-11-23 12:44:21 +09:00
Bill Currie af5d92708d [x11] Implement raw keyboard input via XInput2
UI key presses are still handled by regular X events, but in-game
"button" presses arrive via raw keyboard events. This gives transparent
handling of keyboard repeat (UI keys see repeat, game keys do not),
without messing with the server's settings (yay, that was most annoying
when it came to debugging), and the keyboard is never grabbed, so this
is a fairly user-friendly setup.

At first, I wasn't too keen on capturing them from the root window
(thinking about the user's security), but after a lot of investigation,
I found a post by Peter Hutterer
(http://who-t.blogspot.com/2011/09/whats-new-in-xi-21-raw-events.html)
commenting that root window events were added to XInput2 specifically
for games. Since application focus is tracked and unfocused key events
are dropped very early on, there's no way for code further down the
food-chain to know there even was an event, abusing the access would
require modifying the x11 input code, in which case all bets are off
anyway and any attempt at security anywhere in the code will fail,
meaning that nefarious progs code and the like shouldn't be a problem.
2021-11-23 11:39:48 +09:00
Bill Currie 0c1927d631 [x11] Remove -nomouse handling
After a lot of thought, it really doesn't make sense to have an option
to block mouse input in x11 (not grabbing or similar does make sense, of
course). Not initializing mouse input made perfect sense in DOS and even
console Linux (SVGA) what with the low level access.
2021-11-22 23:54:31 +09:00
Bill Currie c3ce12de4c [x11] Use root window for barriers
It turns out that if the barriers are set on the app window, and the app
grabs the pointer (even passively), barrier events will no longer be
sent to the app. However, creating the barriers on the root window and
the events are selected on the root window, the barrier events are sent
regardless of the grab state.
2021-11-22 15:42:22 +09:00
Bill Currie d930a49de6 [console] Close console when escape key is pressed
I should have fixed this back when I got console working with the new
input system.
2021-11-22 14:59:32 +09:00
Bill Currie bc0451634a [input] Drop unfocused evdev axis/button events
The kernel knows nothing about X11 application focus, so we need to take
care of it ourselves.

Device add/remove events are unaffected: the are always passed on.
2021-11-22 14:59:32 +09:00
Bill Currie ce8eac5ca0 [x11] Send app focus loss/gain events
Other subsystems, especially low-level input drivers, need to know when
the app has input focus. eg, as the evdev driver uses the raw stream
from the kernel, which has no idea about X application focus (in fact,
it seems the events are shared across multiple apps without any issue),
the evdev driver sees all the events thus needs to know when to drop
them.
2021-11-22 14:59:32 +09:00
Bill Currie 67483eea37 [input] Make event names easy to print
Handy for debugging and testing.
2021-11-22 14:59:32 +09:00
Bill Currie e8a7e8218e [x11] Check hit barrier is valid before releasing pointer
It turns out to be possible to get a barrier event at the same time as a
configure notify event (which rebuilds the barriers), and trying to
release the pointer at such a time results in a bad barrier error and
program crash. Thus check the event barrier against the currently
existing barriers before attempting to release the pointer.

This does mean that a better mechanism for sequencing window
repositioning and barrier creation may be required.
2021-11-22 14:59:32 +09:00
Bill Currie 3ac6d2aa22 [x11] Use barriers to trap the pointer in the window
This should be a much friendlier way of "grabbing" input, though I
suspect that using raw keyboard events will result in a keyboard grab,
which is part of the reason for wanting a friendly grab.

There does seem to be a problem with the mouse sneaking out of the
top-right and bottom-left corners. I currently suspect a bug in the X
server, but further investigation is needed.
2021-11-22 14:59:27 +09:00
Bill Currie 3af078b77a [x11] Send app_window event when window moves
This is needed for getting window position info into in_x11 without
exposing more globals, and is likely to be useful for other things,
especially as it doubles as a resize event when that's eventually
supported.
2021-11-22 13:20:13 +09:00
Bill Currie 4391b87d04 [x11] Grab focus when the pointer enters the window
This is necessary in focus-follows-mouse environments (at least for
openbox, but it wouldn't surprise me if most other WMs behave the same
way) because the WMs don't set focus when the pointer is grabbed (which
XInput does before the WM sees the enter event). This is especially
important when the window is fullscreen on a multi-monitor setup as
there is no border to *maybe* catch the mouse before it enters the
window.
2021-11-21 23:42:33 +09:00
Bill Currie a32f83d50f whitespace 2021-11-21 23:42:33 +09:00
Bill Currie e45d19835c [x11] Add initial support for XInput2
Right now, only raw pointer motion and button events are handled, and
the mouse escapes the window, and there are some issues with focus in
focus-follows-mouse environments. However, this should be a much nicer
setup than DGA.
2021-11-21 23:42:33 +09:00
Bill Currie 4944c40f86 [x11] Remove the magic number for mouse buttons
The current limit is still 32. Dealing with it properly will take some
rather advanced messing with XInput, and will be necessary assuming
non-XInput support is continued.
2021-11-21 22:16:08 +09:00
Bill Currie 26a1f66b4e [x11] Split up in_x11_init into three stages
There's now IN_X11_Preinit, IN_X11_Postinit (both for want of better
names), and in_x11_init. The first two are for taking care of
initialization that needs to be done before window creation and between
window creation and mapping (ie, are very specific to X11 stuff) while
in_x11_init takes care of the setup for the input system. This proved
necessary in my XInput experimentation: a passive enter grab takes
effect only when the pointer enters the window, thus setting up the grab
with the pointer already in the window has no effect until the pointer
leaves the window and returns.
2021-11-21 21:22:11 +09:00
Bill Currie 95becc5c05 [x11] Add some braces around an if block 2021-11-21 21:16:55 +09:00
Bill Currie fe2dd013be [x11] Clean out some unnecessary includes 2021-11-21 21:16:55 +09:00
Bill Currie 8988008ad6 [x11] Don't mess with the mouse when going fullscreen
This was always a horrible hack just to get the screen centered on the
window back when we were doing fullscreen badly. With my experiments
with XInput, it has proven to be a liability (I'd forgotten it was even
there until it started imposing a 2s delay to QF's startup).
2021-11-21 20:59:49 +09:00
Bill Currie 925a55f6cc [input] Allow drivers to initialize cvars early
Input driver can now have an optional init_cvars function. This allows
them to create all their cvars before the actual init pass thus avoiding
some initialization order interdependency issues (in this case, fixing a
segfault when starting x11 clients fullscreen due to the in_dga cvar not
existing yet).
2021-11-21 11:33:58 +09:00
Bill Currie 88b3965794 [vulkan] Pick up vulkan.h from correct location
Well... it could be done better, but this works for now assuming it's in
/usr/include (and it's correct for mxe builts). Does need proper
autoconfiscation, though.
2021-11-19 22:36:19 +09:00
Bill Currie e080bb333c [win] Update windows input for new binding system
Seems to work nicely for keyboard (though key bindings are not
cross-platform). Mouse not tested yet, and I expect there are problems
with it for absolute inputs (yay mouse warp :P).
2021-11-19 13:52:40 +09:00
Bill Currie b1d388563e [input] Don't specify ld flags for evdev lib
libtool gets confused if the convenience library has normal library
linker flags and fails to properly relink the main library when
installing.
2021-11-19 12:08:58 +09:00
Bill Currie 48ecfcf411 [cexpr] Fix a naming issue with uint
I didn't notice that uint is defined somewhere on Linux... until I tried
compiling for windows (not defined). Use a define to keep the cast
function naming nice.
2021-11-19 08:58:02 +09:00
Bill Currie b892ce637a [input] Nuke IN_Move from orbit
gotta be sure :)

On a serious note, it was always a problem in that it had
client-specific code and concepts embedded in the libraries.
2021-11-19 08:58:02 +09:00
Bill Currie 793914718f [x11] Implement input names
Mouse axis and button names are handled internally (and thus
case-insensitive).

Key names are handled by X11. Case-sensitivity is currently determined
by Xlib.
2021-11-18 13:01:33 +09:00
Bill Currie 84f746dab2 [input] Allow button and axis inputs to be named
keyhelp provides the input name if it is known, and in_bind tries to use
the provided input name if not a number. Case sensitivity for name
lookups is dependent on the input driver.
2021-11-18 12:59:18 +09:00
Bill Currie f4c521d51d [input] Move in_devbindings_t definition
In the end, it doesn't need to be public, so move it into in_binding.c
2021-11-18 11:17:04 +09:00
Bill Currie c3fa0d6464 [input] Fix incorrect arg count in in_unbind_f
Yay for copying and editing code :P
2021-11-16 20:14:33 +09:00
Bill Currie 1381932552 [input] Fix imt block management
Reset the blocks completely when loading configs and fix a leftover from
when I thought I'd expose the block numbers to bindings but then changed
my mind to simply track the base binding.
2021-11-16 20:12:53 +09:00
Bill Currie 111e5d923e [cexpr] Support casting to double
For int, uint and float, also add uint to float (not that it will do any
good for values over 16M).
2021-11-16 19:59:47 +09:00
Bill Currie 73ab33ba97 [input] Actually return the button in IN_FindButton
Returning the wrapper object makes for some weird behaviour.
2021-11-16 16:33:53 +09:00
Bill Currie 7739972f19 [x11] Block raw inputs if cooked inputs are handled
The cooked inputs (ie_key, ie_mouse) are intended for UI interaction, so
generally should have priority over the raw events, which are intended
for game interaction.
2021-11-16 12:55:55 +09:00
Bill Currie b8baa04b2e [input] Split binding event handler
There's now an internal event handler for taking care of device addition
and removal, and a public event handler for dealing with device input
events in various contexts In particular, so the clients can check for
the escape key.
2021-11-16 12:54:23 +09:00
Bill Currie b80c19bd77 [util] Save and load cvars to/from plist configs
Other than some backwards compatibility, this completes the
configuration updates for now.
2021-11-15 22:04:29 +09:00
Bill Currie fede9125e1 [input] Save/load config to/from plist configs
While the console command line is quite good for setting everything up,
the devices being bound do need to be present when the commands are
executed (due to needing extra data provided by the devices). Thus
property lists that store the extra data (button and axis counts, device
names/ids, connection names, etc) seems to be the best solution.
2021-11-14 10:17:05 +09:00
Bill Currie 7c9f3a3b09 [util] Expose the quakerc check function
qargs probably needs to go away. It certainly needs to be rethought. For
now, this is good enough to get qw working with plist-based
quakeforge.cfg
2021-11-14 10:12:14 +09:00
Bill Currie 6a9e5f4970 [input] Fix incorrect placement of pure attribute
Should be on the prototype, not definition (for public functions).
2021-11-14 10:10:39 +09:00
Bill Currie 08083b8630 [input] Use double for recipe float values
Recipes themselves still use float, but using double in the cexpr values
allows bare floating point numbers (which parse as double) to be used,
making the bind command line a little more user-friendly.
2021-11-12 08:09:41 +09:00
Bill Currie adaa3c5485 [input] Get bindings actually working
The mouse bound to movement axes works (though signs are all over the
place, so movement direction is a little off), and binding F10 (key 68)
to quit works :)
2021-11-12 00:24:04 +09:00
Bill Currie 6e85377d7a [cexpr] Support variable assignment
I might have to add code to block it when necessary, but it's needed for
axis recipe parsing.
2021-11-12 00:19:58 +09:00
Bill Currie 5557bf0b09 [input] Implement axis binding
Each axis binding has its own recipe (meaning the same input axis can be
interpreted differently for each binding)

Recipes are specified with field=value pairs after the axis name.
Valid fields are minzone, maxzone, deadzone, curve and scale, with
deadzone doubling as a balanced/unbalanced flag.

The default recipe has no zones, is balanced, and curve and scale are 1.
2021-11-11 15:51:47 +09:00
Bill Currie f77b4199c4 Fix some optimization warnings 2021-11-11 15:43:07 +09:00
Bill Currie 9172e76107 [input] Move name and description into in_axis_t
Like with in_button_t, it makes creating static axes a little easier.
2021-11-10 15:48:22 +09:00
Bill Currie b231b63413 [input] Implement hot-plug support for bindings
Hot-plug support is done via "connections" (not sure I'm happy with the
name) that provide a user specifiable name to input devices.  The
connections record the device name (eg, "6d spacemouse") and id (usually
usb path for evdev devices, but may be the device unique id if
available) and whether automatic reconnection should match just the
device name or both device name and id (prevents problems with changing
the device connected to the one usb port).
2021-11-10 13:22:44 +09:00
Bill Currie b95c749438 [input] Add a per-device event data pointer
This might pose a problem with multiple event targets (we'll see), but
it will make connecting input devices to bindings much easier.
2021-11-10 13:22:10 +09:00
Bill Currie 5328c06fbf [input] Clean up imt.h a little
Unnecessary enum removed, and the imt block struct moved to imt.c
(doesn't need to be public). Also, remove device name from the imt block
(and thus the parameter to the functions) as it turns out not to be
needed.
2021-11-09 22:23:57 +09:00
Bill Currie 620ea30683 [input] Implement the core binding commands
Again, much testing is needed, but all the core binding commands are
implemented (ie, not the legacy support commands).
2021-11-08 16:56:26 +09:00
Bill Currie 925ca8081c [input] Implement imt creation, binding, etc
Much testing is needed, but the bulk of imt management is implemented.
Axis bindings are not properly implemented yet, though.
2021-11-08 16:54:52 +09:00
Bill Currie 839808e659 [input] Implement several binding commands
in_bind is only partially implemented (waiting on imt), but device
listing, device naming, and input identification are working. The event
handling system made for a fairly clean implementation for input
identification thanks to the focused event handling.
2021-11-08 15:38:26 +09:00
Bill Currie 4898a44263 [console] Hook up new input system
This has smashed the keydest handling for many things, and bindings, but
seems to be a good start with the new input system: the console in
qw-client-x11 is usable (keyboard-only).

The button and axis values have been removed from the knum_t enum as
mouse events are separate from key events, and other button and axis
inputs will be handled separately.

keys.c has been disabled in the build as it is obsolute (thus much of
the breakage).
2021-11-08 11:20:04 +09:00
Bill Currie 6dc90c5497 [x11] Remove key focus and destination handling
I'm undecided on how to handle application focus (probably gain/lose
events), and the destination handler has been a stub for a while. One less
dependency on the "old" key handling code.
2021-11-05 14:56:27 +09:00
Bill Currie 31c1eae1ec [x11] Send key events for pasted text
I'm undecided if the pasted text should be sent as a string rather than
individual key events, but this will do the job for now as it gets me
closer to being able to test everything.
2021-11-05 14:54:33 +09:00
Bill Currie 0c8fbf0ce4 [x11] Don't use select for checking for events
It seems that under certain circumstances (window managers?), select is not
reliable for getting key events, so use of select has been disabled until I
figure out what's going on and how to fix it.
2021-11-05 13:30:01 +09:00
Bill Currie 63f5c738ca [x11] Send cooked keyboard and mouse events
For the mouse in x11, I'm not sure which is more cooked: deltas or
window-relative coordinates, but I don't imagine that really matters too
much. However, keyboard and mouse events suitable for 2D user interfaces
are sent at the same time as the more game oriented button and axis events.
2021-11-05 13:26:44 +09:00
Bill Currie 0a885fe704 [x11] Rename x11 input devices to core
The x11 keyboard and mouse devices are really core input devices rather
than x11 input devices in that keyboard and mouse will be present on most
systems and thus not specific to the main user interface (x11, windows,
etc).
2021-11-05 10:02:21 +09:00
Bill Currie 7d022db702 [util] Avoid Sys_Shutdown for IO signals
It turns out that calling Sys_Shutdown in the signal handler can cause
lockups due to the signal occurring at unsafe times. Fortunately, this is
just the IO related signals (INT, HUP, TERM, QUIT) as the others are
usually caused by actual errors and should not occur in system code thus
timing should not be an issue. However, care will need to be taken when it
comes to handling SIGINT or similar for breaking runaway progs code when
that time comes.
2021-11-05 09:56:08 +09:00
Bill Currie af56e9242b [x11] Clean up duplicate code in software updates
The actual x11 update code was identical between all versions, so it was
moved into the one function.
2021-11-03 22:22:37 +09:00
Bill Currie 16d1232b91 [x11] Connect the X11 input driver to input events
Now nothing works at all ;) However, that's only because the binding
system is incomplete: the X11 input events are getting through to the
binding system, so now it's just a matter of getting that to work.
2021-11-03 22:20:17 +09:00
Bill Currie 825d8b7a49 [input] Make a start on the new binding system
Input Mapping Tables are still at the core as they are a good concept,
however they include both axis and button mappings, and the size is not
hard-coded, but dependent on the known devices. Not much actually works
yet (nq segfaults when a key is pressed).
2021-11-03 19:02:39 +09:00
Bill Currie 14a5ec7b41 [input] Make device add/remove events broadcast
It proved necessary to support broadcasting events to all event
handlers, with device add/remove being the first such events.
2021-11-03 14:08:41 +09:00
Bill Currie fae9e043df [input] Move button name and description
This puts the name and description into the button itself, making it much
easier to look them up.
2021-11-01 13:54:16 +09:00
Bill Currie 09e3e62a0a [input] Move in_event.h and binding defs
They now live in the include QF/input directory. This cleans up include/QF
a little, and input.h as well.
2021-11-01 13:05:05 +09:00
Bill Currie 665790f562 [video] Remove libQFjs
It is now redundant with the libQFinput, though nothing actually works yet.
2021-11-01 12:30:45 +09:00
Bill Currie 36f6dcc65e [input] Add logical axes
Like logical buttons, logical axes are engine-defined destinations to
which input ("physical") axes can be bound.
2021-10-01 15:38:48 +09:00
Bill Currie a4f71cb4d5 [renderer] Clean out unneeded input.h includes
I really don't know how it goot into the gl/glsl vid_common files, but I
imagine it propogated to vulkan because I copied one then cloned from
there.
2021-10-01 13:11:14 +09:00
Bill Currie 63c2f829b3 [input] Fix a cut-and-paste error
Just the name of a static function, but still...
2021-10-01 12:10:26 +09:00
Bill Currie fed8f66824 [input] Rework logical buttons
kbutton_t is now in_button_t and has been moved to input.h. Also, a
button registration function has been added to take care of +button and
-button command creation and, eventually, direct binding of "physical"
buttons to logical buttons. "Physical" buttons are those coming in from
the OS (keyboard, mouse, joystick...), logical buttons are what the code
looks at for button state.

Additionally, the button edge detection code has been cleaned up such
that it no longer uses magic numbers, and the conversion to a float is
cleaner. Interestingly, I found that the handling is extremely
frame-rate dependent (eg, +forward will accelerate the player to full
speed much faster at 72fps than it does at 20fps). This may be a factor
in why gamers are frame rate obsessed: other games doing the same thing
would certainly feel different under varying frame rates.
2021-10-01 09:16:31 +09:00
Bill Currie c6a073c1f3 [win] Hook up windows input
Not sure it actually works yet (can't test right now), but since the x11
switch-over worked, it should.
2021-09-28 12:48:47 +09:00
Bill Currie 7fcf6bfef5 [build] Autoconfiscate evdev 2021-09-28 10:57:12 +09:00
Bill Currie cacf0be7f6 [util] Wrap fd_set
While select itself is reasonably portable, it turns out that including
the declaration for fd_set makes a bit of a mess for QF's clean headers.
2021-09-28 10:53:51 +09:00
Bill Currie 29f8ed388e [x11] Clean up some formatting 2021-09-27 19:54:08 +09:00
Bill Currie 144a83d761 [input] Free phys and uniq device strings
Forgot to do so when I added the strings.
2021-09-27 19:53:16 +09:00
Bill Currie 9732952709 [x11] Use select for checking input
It seems that there's always some incoming event anyway (possibly due to
the constant screen updates) so it doesn't make much difference
currently.
2021-09-27 11:24:35 +09:00
Bill Currie 7f408351b9 [input] Use a single select call for all drivers
For drivers that support it. Polling is still supported and forces the
select timeout to 0 if any driver requires polling. For now, the default
timeout when all drivers use select is 10ms.
2021-09-26 15:11:07 +09:00
Bill Currie 940d824be0 [util] Split out the select code to Sys_Select
While select itself is fairly portable, it's not super convenient.
2021-09-26 14:54:24 +09:00
Bill Currie 349f8067c3 [gamecode] Conform with libc malloc for pr zone
Allocating 0 bytes returns null and freeing a null pointer is safe.
2021-09-26 12:03:44 +09:00
Bill Currie 192b76ddc6 [input] Remove closed device in correct place
Removing the device from the devices list after closing the device
could cause the device to be double-freed if something went wrong in the
device removal callback resulting in system shutdown which would then
close all open devices.

The device is removed from the list before the callback is called.

There's still a small opportunity for such in a multi-threaded
environment, but that would take device removal occurring at the same
time as the input system is shut down. Probably the responsibility of
the threaded environment rather than inputlib.
2021-09-25 16:43:03 +09:00
Bill Currie 13bc38a55b [input,ruamoko,qwaq] Fix incorrect use of PR_RESMAP
I had forgotten that _size was the number of rows in the map, not the
number of objects (1024 objects per row). This fixes the missed device
removal messages. And probably a slew of other bugs I'd yet to encounter
:P
2021-09-25 15:50:16 +09:00
Bill Currie 2119688b48 [gamecode] Use a flag for format width
This ensures caller specified width always gets through to libc's
printf, even if the caller specifies 0. More importantly, * works
correctly.
2021-09-25 13:24:48 +09:00
Bill Currie cc730c90b4 [input] Rework device registration
And provide functions for collecting axis and button information from a
device id.
2021-09-20 15:21:11 +09:00
Bill Currie 70812b3c49 [input] Hook up low level input to events
This includes device add and remove events, and axis and buttons for
evdev. Will need to sort out X11 input later, but next is getting qwaq
responding.
2021-08-30 14:40:19 +09:00
Bill Currie 5d1e515e9e [qwaq] Hook up input to a certain extent
Really, just enough to show that the initialization process and hotplug
are working. The qwaq input driver is not yet properly integrated.
2021-08-30 09:59:30 +09:00
Bill Currie b39b6031e8 [input] Give input drivers a private data pointer
The pointer can be updated at any time using the driver handle (returned
by IN_RegisterData).
2021-08-30 09:54:36 +09:00
Bill Currie 05215e0295 [util] Add functions to help convert external times 2021-08-27 12:10:05 +09:00
Bill Currie 5d4013b485 [util] Use clock_gettime for Sys_LongTime
While QF doesn't currently use nanoseconds, having access to a clock
that is not affected by setting system time is nice, and as a bonus, can
handle suspends should the need arise.
2021-08-27 11:22:57 +09:00
Bill Currie a91dac60d9 [input] Start work on improved input system
The common input code (input outer loop and event handling) has been
moved into libQFinput, and modified to have the concept of input drivers
that are registered by the appropriate system-level code (x11, win,
etc).

As well, my evdev input library code (with hotplug support) has been
added, but is not yet fully functional. However, the idea is that it
will be available on all systems that support evdev (Linux, and from
what I've read, FreeBSD).
2021-08-27 09:10:21 +09:00
Bill Currie 8a5c3c1ac1 [util] Add sys function to get cpu count
And use it in qfvis.
2021-08-13 21:26:48 +09:00
Bill Currie a01cafe972 [util] Minimize set growth
At the low level, only unions can cause a set to grow. Of course, things
get interesting at the higher level when infinite (inverted) sets are
mixed in.
2021-08-11 12:31:03 +09:00
Bill Currie 37a5b475c0 [util] Minimize the string for infinite sets
Instead of printing every representable member of an infinite set (ie,
up to element 63 in a set that can hold 64 elements), only those
elements up to one after the last non-member are listed. For example,

    {...} - {2 3} -> {0 1 4 ...}

This makes reading (and testing!) infinite sets much easier.
2021-08-11 12:31:03 +09:00
Bill Currie a6a273bb07 [vulkan] Fix up test function api
Whil I can't automatically run the tests in windows builds, at least I
can make sure they build (and run individual ones by hand as necessary).
2021-08-11 12:31:03 +09:00
Bill Currie aa72f1dc31 [util] Fix reversed finite-infinite set union ops
It looks like I tried to test it, but my tests weren't so good This
seems to cover everything for the three main set ops.
2021-08-11 12:31:03 +09:00
Bill Currie c81f2d4b52 [video] Mark dga funcs as const when dga not available
Fixes a compile issue (warning about attribute const) when dga is not
available, thanks to spiritiit for finding it :)
2021-08-11 12:09:07 +09:00
Bill Currie b320c3352f [util] Make set_t endian-agnostic
Most of the set ops were always endian-agnostic since they were simply
operating on multiple bits in parallel, but individual element
add/remove/test was very endian-dependent. For the most part, this
didn't matter, but it does matter very much when loading external data
into a set or writing the data out (eg, for PVS).
2021-08-08 12:34:18 +09:00
Bill Currie 42dc30ec29 [vulkan] Increase main staging buffer to 32MB
1k 32bpp sky textures need 24MB to load. Though there's always better
handling of running out of stating buffer (ie, flushing and trying
again).
2021-08-02 23:17:55 +09:00
Bill Currie d56d8ac707 [util] Loosen up the epsilon on simd seb tests
It seems my eeepc's SSE units don't get quite the same answers as does
my i7's (maybe due to lack of hadd?).
2021-08-02 23:15:20 +09:00
Bill Currie 80b17623b1 [util] Fix an out-by-one in pqueue tests
Showed up only when the data arrays were packed.
2021-08-02 23:08:14 +09:00
Bill Currie ec54c54226 [build] Fix some windows bitrot 2021-08-02 14:02:41 +09:00
Bill Currie d99fb01b65 [build] Fix some distcheck bitrot 2021-08-02 13:47:00 +09:00
Bill Currie f76964b86b [util] Add an priority queue implementation
Done via macros (like darray and ringbuffer). Might prove useful for
qfvis and maybe dynamic lights.
2021-08-02 13:29:55 +09:00
Bill Currie 4f2113bc05 [util] Enable accidentally disabled seb tests 2021-08-02 12:44:08 +09:00
Bill Currie e4984aad17 [util] Add functions for binary heaps
Sink, swim, build and sort, both "simple" and with a data parameter for
the compare function.
2021-08-02 12:44:08 +09:00
Bill Currie 674ffa0941 [util] Make bsp_t counts size_t
and other bsp data counts unsigned, and clean up the resulting mess.
2021-08-01 21:54:05 +09:00
Bill Currie 80a89c5e1e [util] Write the correct bsp format id for bsp2
Oops :P
2021-08-01 14:07:24 +09:00
Bill Currie 9d819254d4 [util] Make a number of improvements to SEB
Attempting to vis ad_tears drags a few lurking bugs out of
SmallestEnclosingBall_vf: poor calculation of 2-point affine space, poor
handling of duplicate points and dropped support points, poor
calculation of the new center (related to duplicate points), and
insufficient iterations for large point sets. qfvis (modified for
cluster spheres) now loads ad_tears.
2021-07-30 14:57:47 +09:00
Bill Currie fe98a513bc [util] Add a function to check hunk pointers
Its only real utility is to check that a pointer is not pointing into
freed space.
2021-07-29 15:27:48 +09:00
Bill Currie 6d312aaa63 [simd] Check the distance to the affine point
As per usual, fp math finds a way to confound any epsilon test. So
rather than relying entirely on test_support_points, check the distance
from the sphere center to the affine point and break out of the loop if
the distance is small enough (< 1% of the current radius). This allows
qfvis to load ad_tears without hacks.
2021-07-29 15:15:14 +09:00
Bill Currie 45aa8e6504 [util] Loosen affine test epsilon for SEB
Scaling the checks by 1e-6 was a little too tight for very small
triangles, but 1e-5 seems to work well. This fixes SEB getting stuck for
a ridiculously small (for quake) triangle in ad_tears (probably resulted
from some bad math in qfbsp when generating the portal file from the
bsp).
2021-07-29 15:03:54 +09:00
Bill Currie 4f51a3b406 [utils] Fix set tests for 32-bit machines 2021-07-29 14:10:18 +09:00
Bill Currie 8f376a48f8 [util] Add raw versions of hunk alloc and free
They do not clear memory and thus are good for situations where speed is
more critical.
2021-07-29 11:44:10 +09:00
Bill Currie ca63c0360a Do an audit of hunk mark usage
I realized that after making the hunk 64-bit clean, I had forgotten to
go through and convert all the saved marks to size_t.
2021-07-29 11:43:27 +09:00
Bill Currie 54604d9aa2 [util] Make hunk (optionally) thread-safe
For now, the functions check for a null hunk pointer and use the global
hunk (initialized via Memory_Init) if necessary. However, Hunk_Init is
available (and used by Memory_Init) to create a hunk from any arbitrary
memory block. So long as that block is 64-byte aligned, allocations
within the hunk will remain 64-byte aligned.
2021-07-29 11:43:27 +09:00
Bill Currie 8fdd9c1f5a [util] Write some tests for utf8 r/w
And fix some errors with 5-byte encodings.
2021-07-27 23:29:14 +09:00
Bill Currie 5b4428420e [utils] Get utf-8 writing working for up to 11 bits
I need to write some automated tests for this, and reading of course,
but 1 and two byte outputs look correct. Kind of sad it took sixteen
years to get around to attempting to use the code :(
2021-07-27 23:29:02 +09:00
Bill Currie 9e2c474d38 [model] Ensure the pvs is not inverted
Mod_DecompressVis_set (via Mod_LeafPVS_set) can be used to recycle pvs
sets, but the set may have been set to everything at some stage, which
is implemented by inverting the set (making the set infinite) and having
1-bits remove elements from the set. This is most definitely not wanted
for pvs :)

Currently undecided what to do about Mod_DecompressVis_mix, thus the
fixme.

Fixes the flickering lights in any map where the camera is out of the
map for a single frame (eg, start.bsp, The Catacombs (hipnotic, hip2m3)).
2021-07-27 17:54:50 +09:00
Bill Currie 163d147044 [util] Give set_count a >8x speed boost
I knew counting bits individually was slow, but it never really mattered
until now. However, I didn't expect such a dramatic boost just by going
to mapping bytes to bit counts. 16-bit words would be faster still, but
the 64kB lookup table would probably start hurting cache performance,
and 32-bit words (4GB table) definitely would ruin the cache. The
universe isn't big enough for 64-bits :)
2021-07-27 13:54:22 +09:00
Bill Currie 50740c1014 [model] Remove the confusion about numleafs
The fact that numleafs did not include leaf 0 actually caused in many
places due to never being sure whether to add 1. Hopefully this fixes
some of the confusion. (and that comment in sv_init didn't last long :P)
2021-07-27 12:38:08 +09:00
Bill Currie 49c3dacbbc [util] Rename set_size to set_count
After seeing set_size and thinking it redundant (thought it returned the
capacity of the set until I checked), I realized set_count would be a
much better name (set_count (node->successors) in qfcc does make much
more sense).
2021-07-27 11:52:21 +09:00
Bill Currie cf96f340df [util] Use same distance calc in simd CC test
The test started failing when optimizing (not sure why). Using the same
code to calculate the squared distance "fixes" the test.
2021-07-26 15:46:12 +09:00
Bill Currie c02fcee58a [util] Make zone functions 64-bit clean
This allows nq and qw clients/servers to use over 2GB of memory if
necessary.
2021-07-26 15:43:57 +09:00
Bill Currie 5fc1a36d92 [gamecode] Be more forgiving of unresolved builtins
If the progs code never calls the functions, then there is no problem.
Thus unresolved builtin references get pointed to the bad function
builtin.
2021-07-26 13:35:35 +09:00
Bill Currie 2e33503c4c [vulkan] Fix a missed array index edit
Caused by the view model implementation, and missed because gcc needs
optimization to cache such errors (and my own error, of course).
2021-07-26 11:43:31 +09:00
Bill Currie f47e03e606 [model] Remove 64k limit on visible leafs
Modern maps can have many more leafs (eg, ad_tears has 98983 leafs).
Using set_t makes dynamic leaf counts easy to support and the code much
easier to read (though set_is_member and the iterators are a little
slower). The main thing to watch out for is the novis set and the set
returned by Mod_LeafPVS never shrink, and may have excess elements (ie,
indicate that nonexistent leafs are visible).
2021-07-26 11:32:05 +09:00