Commit Graph

888 Commits

Author SHA1 Message Date
Bill Currie 2e2dedfd78 [gamecode] Print invalid opcodes correctly
Hex is better for opcodes than octal. Probably copied from one of the
sub-instruction opcode error messages.
2023-09-08 11:12:37 +09:00
Bill Currie e61be2f80f [gamecode] Add 2- and 3-component swizzles
VM side of the work needed for #58. Tests are still only 4-component,
but the geometric algebra tests seem to have 2-component covered at
least a little bit.
2023-08-31 20:08:28 +09:00
Bill Currie a416e9c060 [gamecode] Add a 2d wedge product
While it could be emulated using a 3d cross-product, it was a hack and
required the use of a swizzle (or alias) to extract the scalar value.
This will make 2d PGA a little nicer when I get to modifying qfcc for it
2023-08-31 17:33:05 +09:00
Bill Currie a66fb80517 [gamecode] Switch dot products to give a scalar
Making them give a vector was a mistake for Ruamoko. I've probably got a
mess to clean up in game-source, but oh well.
2023-08-31 15:32:52 +09:00
Bill Currie 727b490a0c [gamecode] Improve hops instruction readability 2023-08-27 12:28:16 +09:00
Bill Currie 29a57b7128 [qfcc] Correct handling of 64-bit comparisons
While the progs engine itself implements the instructions correctly, the
opcode specs (and thus qfcc) treated the results as 32-bit (which was,
really, a hidden fixme, it seems).
2023-08-26 23:04:34 +09:00
Bill Currie a88d17459f [gamecode] Decode hops and extend opcodes 2023-08-26 22:43:15 +09:00
Bill Currie 81b57903fc [gamecode] Support the l flag for %v and %q
This makes it much easier to print double vector types (for 3 and 4
components, at least).
2023-08-26 11:47:04 +09:00
Bill Currie 7338f86c77 [gamecode] Extend extend to support reversal
Using swizzle for some of the geometric product operations was a bit
clunky and has problems with alignment. While I will still need it in
the future, it turns out that the extend instruction almost did what I
needed. However, I'm unsure that reversing components within an extended
vector is the way to go.
2023-08-25 10:30:14 +09:00
Bill Currie fb6d3f2f86 [gamecode] Decode the swizzle operand
-yx00 is much easier to interpret than some "random" number.
2023-08-24 20:17:17 +09:00
Bill Currie 30f2abb0ad [gamecode] Correct 64-bit debug views
I had forgotten that value needs to be incremented by 2 for 64-bit
values because it's only 32-bit.
2023-08-23 21:39:06 +09:00
Bill Currie 2e91b29580 [qfcc] Start work on implementing geometric algebra
This gets only some very basics working:
 * Algebra (multi-vector) types: eg @algebra(float(3,0,1)).
 * Algebra scopes (using either the above or @algebra(TYPE_NAME) where
   the above was used in a typedef.
 * Basis blades (eg, e12) done via procedural symbols that evaluate to
   suitable constants based on the basis group for the blade.
 * Addition and subtraction of multi-vectors (only partially tested).
 * Assignment of sub-algebra multi-vectors to full-algebra multi-vectors
   (missing elements zeroed).

There's still much work to be done, but I thought it time to get
something into git.
2023-08-21 17:58:20 +09:00
Bill Currie b4afaab03c [gamecode] Support wide types in type views
Now the new vector types print properly :)

    0003 scale.F{4,1,4} ([1, 0, 0, 0]), (3), p1
2023-08-21 17:47:55 +09:00
Bill Currie 74405ee31b [gamecode] Switch dstatement ops to signed
I realized recently that I had made a huge mistake making Ruamoko's
based addressing use unsigned offsets as it makes stack-relative
addressing more awkward when it comes to runtime-determined stack frames
(eg, using alloca). This does put a bit of an extra limit on directly
addressable globals, but that's what the based addressing is meant to
help with anyway.
2023-08-21 17:47:55 +09:00
Th3T3chn0G1t 3098b5d3f7 Implement clang support
Fixing a load of issues related to autoconf and some small source-level issues to re-add clang support.
autoconf feature detection probably needs some addressing - partially as -Werror is applied late.
2023-08-11 14:25:01 +09:00
Bill Currie dbd3d6502a Nuke qboolean from orbit
I never liked it, but with C2x coming out, it's best to handle bools
properly. I haven't gone through all the uses of int as bool (I'll leave
that for fixing when I encounter them), but this gets QF working with
both c2x (really, gnu2x because of raw strings).
2023-06-13 18:06:11 +09:00
Bill Currie 6d5e8922a5 [qfcc] Add a handle type for engine resources
I never liked the various hacks I had come up with for representing
resource handles in Ruamoko. Structs with an int were awkward to test,
pointers and ints could be modified, etc etc. The new @handle keyword (@
used to keep handle free for use) works just like struct, union and
enum in syntax, but creates an opaque type suitable for a 32-bit handle.
The backing type is a function so v6 progs can use it without (all the
necessary opcodes exist) and no modifications were needed for
type-checking in binary expressions, but only assignment and comparisons
are supported, and (of course) nil. Tested using cbuf_t and QFile: seems
to work as desired.

I had considered 64-bit handles, but really, if more than 4G resource
objects are needed, I'm not sure QF can handle the game. However, that
limit is per resource manager, not total.
2023-05-25 10:41:28 +09:00
Bill Currie 717cbaff87 [gamecode] Support offset for lea on globals
Allows using `array + offset` addressing. Both constant and variable
offsets are supported.
2023-05-14 12:45:08 +09:00
Bill Currie f18837f195 [gamecode] Fix a pile of UB in the test cases
I always suspected the overflow conversions were UB, but with gcc doing
different things on arm, I thought it was about time to abandon those
particular tests. What I was not expecting was for the return value of
strcmp to be "UB" (in that there's no guarantee of the exact value, just
< = > 0). Fortunately, nothing actually relies on the value of the op
other than the tests, so modify the test to make the behavior well
defined.
2023-03-25 21:21:13 +09:00
Bill Currie 7d4c1d79b1 [plist] Use reference counts for items
This makes it much easier to share items between property lists (eg,
targets and the main entity list in cl_light).
2023-03-13 11:26:13 +09:00
Bill Currie f256ab167d [gamecode] Yet more leaks 2023-03-05 18:31:30 +09:00
Bill Currie b8bd83f5cd [gamecode] Clean up a pile of memory leaks
Usually doesn't matter, but it makes it easier to evaluate valgrind's
output.
2023-03-03 22:07:27 +09:00
Bill Currie 70aa970c32 [gamecode] Make modules responsible for freeing resources
It should have been this way all along, and it seems I thought they were
when I did rua_gui.c as it already freed its resource block, which would
have been a double free (oops). Fixes an invalid write when shutting
down progs in qwaq-cmd (relevant change not committed).
2023-03-03 20:26:00 +09:00
Bill Currie 2d3c2da64d [qfcc] Support advanced progs again
The support for the new vector types broke compiling code using
--advanced. Thus it's necessary to ensure vector constants are
float-type and vec3 and vec4 are treated as vector and quaternion, which
meant resurrecting the old vector expression code for v6p progs.
2022-11-12 20:04:19 +09:00
Bill Currie 0c54b0652b Abandon support for clang
The inconsistencies in clang's handling of casts was bad enough, and its
silliness with certain extensions, but discovering that it doesn't
support raw strings was just too much. Yes, it gives a 3s boost to qfvis
on gmsp3v2.bsp, but it's not worth the hassle.
2022-10-16 18:02:25 +09:00
Bill Currie 87dd4ee33d [gamecode] Remove some rather strange code
As indicated, I have no idea why the code was like that, but removing it
seems to have no effect as it seems to copy the data in the wrong
direction.
2022-10-15 14:44:54 +09:00
Bill Currie 41a6ea3534 [gamecode] Use adjusted vector string for sscanf
There's not much point in converting commas to spaces if the result
isn't used. Fixes several malformed vector errors in ad_tears.
2022-09-22 09:38:39 +09:00
Bill Currie 08328f4076 Fix some cygwin portability issues
Cygwin's headers seem to be rather out of date with respect to linux
with regards to signed types, especially ctype.
2022-09-19 16:31:08 +01:00
Bill Currie aa41e6c4c6 [gamecode] Expose value_string as PR_Debug_ValueString
PR_Debug_ValueString prints the value at the given offset using the
provided type to format the string. The formatted string is appended to
the provided dstring.
2022-09-14 19:23:59 +09:00
Bill Currie a76f6c812c [gamecode] Fix a clang compile issue
Silly clang not being actually compatible :P
2022-09-09 14:57:30 +09:00
Bill Currie be447fc9d6 [gamecode] Add optional support for %@ strings
If no handler has been registered, then the corresponding parameter is
printed as a pointer but with surrounding brackets (eg, [0xfc48]). This
will allow the ruamoko runtime to implement object printing.
2022-09-09 14:48:03 +09:00
Bill Currie 1e54799f69 [gamecode] Take care of failing uint conversion tests
By not doing the unrepresentable conversions, since they seem to be
undefined behavior and even gcc 12 is inconsistent with them
2022-08-18 18:18:19 +09:00
Bill Currie d9d0a80752 [gamecode] Add an extend instruction
The extend instruction is for loading narrower data types into wider
data types, eg, single element into 2, 3, or 4 element types, with a
small set of extension schemes: 0, 1, -1, copy (for 1->any and 2 -> 4).
Possibly most importantly, it works with unaligned data.

Progress towards #30
2022-08-18 18:18:19 +09:00
Bill Currie 0897952a57 Fix windows compile issues
ulong seems to be defined somewhere on Linux, thus I missed that, and of
course there's the fun with aligned memory allocation :/
2022-07-31 17:34:09 +09:00
Bill Currie 732ea3a5fd Fix a bunch of issues for clang
One *actual* error (wrong enum type), and some memory alignment issues.
The rest just clang being lame.
2022-07-31 17:15:40 +09:00
Bill Currie 2c8bec27c7 Fix a pile of warnings for gcc 12
Most were pretty easy and fairly logical, but gib's regex was a bit of a
pain until I figured out the real problem was the conditional
assignments.

However, libs/gamecode/test/test-conv4 fails when optimizing due to gcc
using vcvttps2dq (which is nice, actually) for vector forms, but not the
single equivalent other times. I haven't decided what to do with the
test (I might abandon it as it does seem to be UD).
2022-07-31 17:13:26 +09:00
Bill Currie 78a0075be1 [gamecode] Plug a nasty buffer overflow
This one is ancient: the code was essentially unmodified since release
(just some formatting). Malformed vectors could sneak through due to map
bugs (eg, "angles -90" instead of "angle -90" as in ad_tears) and the
vector parsing code would continue past the end of the string and
writing into unowned memory, potentially messing up the libc allocation
records. Replacing with the obvious sscanf works nicely.

Sometimes, Quake code is brilliant. Other times, it's a real face-palm.
2022-05-21 14:28:47 +09:00
Bill Currie 973ae0ad54 [gamecode] Add PR_Shutdown for tearing down a VM
This is meant for a "permanent" tear-down before freeing the memory
holding the VM state or at program shutdown. As a consequence, builtin
sub-systems registering resources are now required to pass a "destroy"
function pointer that will be called just before the memory holding
those resources is freed by the VM resource manager (ie, the manager
owns the resource memory block, but each subsystem is responsible for
cleaning up any resources held within that block).

This even enhances thread-safety in rua_obj (there are some problems
with cmd, cvar, and gib).
2022-05-12 19:58:18 +09:00
Bill Currie 978d0306c0 [hash] Rename the publicly visible hashlink_t to hashctx_t
I think my biggest problem with the hashlink freelist parameter was how
much implementation it exposed in just the name.
2022-05-12 18:02:01 +09:00
Bill Currie a31ff3153c [gamecode] Fail gracefully on invalid entity strings
Returning null (and printing some error messages) is far friendlier than
aborting.
2022-05-05 23:49:30 +09:00
Bill Currie b87a768c43 [gamecode] Sort debug local defs by address
This allows the fuzzy bsearch used to find a def by address to work
properly (ie, find the actual def instead of giving some other def +
offset). Makes for a much more readable instruction stream.
2022-05-01 14:35:24 +09:00
Bill Currie 875c9bde7c [gamecode] Print operand widths when not 1
The widths for all three operands are printed if any is greater than 1.
Makes figuring out which instruction is executing a little easier.
2022-04-29 16:59:15 +09:00
Bill Currie af2dfde37a [gamecode] Support printing 64-bit integer types
The 'l' modifier always means 64-bit, regardless of the underlying
platform. As well, the 32-bit integer types are handled portably too.
2022-04-29 16:59:15 +09:00
Bill Currie 6d62e91ce7 [gamecode] Clean up progs data access
pr_type_t now contains only the one "value" field, and all the access
macros now use their PACKED variant for base access, making access to
larger types more consistent with the smaller types.
2022-04-29 16:59:15 +09:00
Bill Currie bff0847761 [cvar] Clean up most misinterpreted cvar types
The misinterpretations were due to either the cvar not being accessed
directly by the engine, but via only the callback, or the cvars were
accesssed only by progs (in which case, they should be float). The
remainder are a potential enum (hud gravity) and a "too hard basket"
(rcon password: need to figure out how I want to handle secret strings).
2022-04-24 20:04:06 +09:00
Bill Currie 12c84046f3 [cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.

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

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

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

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

nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-24 19:15:22 +09:00
Bill Currie 78119aeb7a [gamecode] Clean up generated swizzle code 2022-04-01 02:14:05 +09:00
Bill Currie 14ad364e17 [gamecode] Document the tests that fail under clang
The tests fail due to differences in how clang and gcc treat floating
point to unsigned integral type conversions when the values overflow. It
wouldn't be so bad if clang was consistent with conversions to 32-bit
unsigned integers, like it seems to be with conversion to 64-bit
unsigned integers.

With this, the "get QF building with clang" mini-project is done and I
won't have to panic when someone comes to me and asks if it will work.
At worst, there'll be a little bit-rot.
2022-03-31 14:50:49 +09:00
Bill Currie d109571994 [gamecode] Use 64 byte alignment for most of progs memory
Only edicts themselves get a smaller alignment (4, 8 or 32 bytes,
depending on hardware and progs version). I didn't want to waste too
much memory on edict alignment for progs that don't need any better than
void *, but the zone really wants 64 bytes, and the stack might as well
have 64 bytes as well. Fixes a segfault when running v6 progs in a clang
build (clang got really agressive with simd in zone.c).
2022-03-31 02:51:05 +09:00
Bill Currie f601606ad7 [gamecode] Fix an enum cast warning
Harmless, but it doesn't hurt to make it explicit.
2022-03-31 02:50:03 +09:00