Commit Graph

870 Commits

Author SHA1 Message Date
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
Bill Currie cdcf1a71ea [gamecode] use correct void for global_string
It seems gcc is a little fast and loose with 0 as a null vector.
2022-03-31 02:48:01 +09:00
Bill Currie 2f9df0f05b Work around some clang parsing issues
clang has no problem with labels crossing declarations, but it can't
cope with a declaration (or end of block) just after a label.
2022-03-31 02:44:58 +09:00
Bill Currie 5b3cd93fa3 [gamecode] Implement with more portably
clang doesn't support taking the address of a vector component. I was
just being lazy when I used a pointer when setting the base register.
2022-03-31 02:38:26 +09:00
Bill Currie 7a6ca0ebcb [simd] Use portable swizzles
gcc and clang have rather different swizzle builtins, but both do a nice
job of optimizing the intuitive initializer swizzle (I think gcc 8(?)
didn't do such a good job thus my use of __builtin_shuffle).
2022-03-31 02:25:33 +09:00
Bill Currie 63e5655f68 Clean up some enum sanity checks
It seems clang defaults to unsigned for enums. Interestingly, gcc was ok
with the checks being either way. I guess gcc treats enums that *can* be
unsigned as DWIM.
2022-03-31 00:18:53 +09:00
Bill Currie fb83d87a0e Fix some distcheck issues
Just keeping up with myself.
2022-03-01 10:12:50 +09:00
Bill Currie 59044d3827 Fix a bunch of distcheck issues 2022-02-14 19:28:19 +09:00
Bill Currie 4d491a444d [gamecode] Fix handling of undefined builtins
The setup of the function descriptor for undefined builtins was
incomplete and led to the progs running code at address 0. It didn't end
well.
2022-02-14 14:28:19 +09:00
Bill Currie db8cf68ef3 [gamecode] Pass registered data pointer to builtins
This is the bulk of the work for recording the resource pointer with
with builtin data. I don't know how much of a difference it makes for
most things, but it's probably pretty big for qwaq-curses due to the
very high number of calls to the curses builtins.

Closes #26
2022-02-14 12:28:38 +09:00
Bill Currie 944a9253e9 [gamecode] Support %u format in PR_Sprintf
Not sure why it was missed as it would have been useful even before
unsigned was properly supported by qfcc.
2022-02-12 01:58:38 +09:00
Bill Currie eba614336d [gamecode] Add single-component float bitop instructions
These add legacy support for basic float bitops (& | ^ ~). Avoiding the
instructions would require tot only the source to be converted, but also
the servers (as they do access those fields), and this seemed to be too
much.
2022-02-06 21:20:00 +09:00
Bill Currie e1ecda9221 [gamecode] Add unsigned divide and remainder instructions
I had forgotten that unsigned division was different from signed
division (rather silly of me). However, with some testing and analysis,
unsigned true modulo is not needed as it's not possible to have
negative inputs and thus it's the same as remainder.
2022-02-06 12:20:17 +09:00
Bill Currie 078f36a871 [gamecode] Add "return pointer" mode to with instruction
This loads the current return pointer into the specified register. No
offset is used (should make that an error, but for now any offset is
simply ignored). This is part of the fix for getting obj_msg_sendv to
work with return values.
2022-02-05 18:42:54 +09:00
Bill Currie 208cba85eb [gamecode] Move return buffer to end of progs memory map
With the return buffer in progs_t, it could not be addressed by the
progs on 64-bit machines (this was intentional, actually), but in order
to get obj_msg_sendv working properly, I needed a way to "bounce" the
return address of a calling function to the called function. The
cleanest solution I could think of was to add a mode to the with
instruction allowing the return pointer to be loaded into a register and
then calling the function with a 0 offset for the return value but using
the relevant register (next few commits). Testing promptly segfaulted
due to the 64-bit offset not fitting into a 32-bit value.
2022-02-05 18:37:23 +09:00
Bill Currie 9cf2740cb4 [gamecode] Create a globally accessible hash of type encodings
The plan is to use the types to extract the number of parameters for a
selector when it is necessary to know the count. However, it'll probably
become useful for something else alter (these things seem to always do
so).
2022-02-05 14:07:45 +09:00
Bill Currie 7731c469e2 [gamecode] Count calls to builtins in profile
It's a bit disconcerting seeing a builtin in the top 10 when builtins
are counted by call while progs functions are counted by instruction.

Also, show the total profile after the function top-10 list.
2022-02-04 21:49:59 +09:00
Bill Currie 0211b6ec5b [gamecode] Add 64-bit load/store instructions
Only widths 3 and 4 have been added because widths 1 and 2 can be
implemented by widths 2 and 4 of the 32-bit load/store instructions.
2022-02-02 14:47:36 +09:00
Bill Currie 6514e09e7c [gamecode] Use an explicit size for the null page
It's currently only 4 (or even 3 for v6) words, but this fixes false
positives when checking for null pointers in Ruamoko progs due to
pr_return pointing to the return buffer and thus outside the progs
memory map resulting in an impossible to exceed value.
2022-02-01 16:43:29 +09:00