Commit Graph

98 Commits

Author SHA1 Message Date
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 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 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 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 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 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 728c42e921 [gamecode] Use pr_type_names for debug views
I abandoned the reason for doing it (adding a pile of vector types), but
I liked the cleanup. All the implementations are hand-written still, but
at least the boilerplate stuff is automated.
2022-01-30 10:49:33 +09:00
Bill Currie 5c22253095 [gamecode] Use the stack frame to find local defs
Of course, only in Ruamoko progs, but it works quite nicely.
global_string is now passed the absolute address of the referenced
operand. With a little groveling through the progs stack, it should be
possible to resolve pointers to locals in functions further up the
stack.
2022-01-27 14:20:09 +09:00
Bill Currie de974fdd3f [gamecode] Add format for addressing modes and use in return
This fixes Ruamoko's return format string. It looks like it's producing
the correct address (but doesn't show all the information it should),
but the rest of the debug code needs work locals.
2022-01-27 13:29:38 +09:00
Bill Currie a0d9cf8d8e [gamecode] Improve verbose statement prints for Ruamoko
They now include base register index and effective address of the
operands (though it may be wrong for instructions that don't use a base
register for that operand).
2022-01-27 10:57:31 +09:00
Bill Currie 59ee723201 [gamecode] Rename parm to param
That misspelling bothered me from the very beginning, I'd always have
trouble getting the name right when trying to access one of those fields.
2022-01-27 10:55:06 +09:00
Bill Currie faa98d8198 [gamecode] Use a struct for offset/count pairs
This cleans up dprograms_t, making it easier to read and see what chunks
are in it (I was surprised to see only 6, the explicit pairs made it
seem to have more).
2022-01-26 19:30:25 +09:00
Bill Currie 3c86660d4a [gamecode] Rename MAX_PARMS to PR_MAXPARAMS 2022-01-23 14:17:25 +09:00
Bill Currie 16a203c643 [gamecode] Partially implement conversion code debug
The code is simply printed in octal for now, but it's better than
breaking the rest of the format string.
2022-01-21 10:12:50 +09:00
Bill Currie 5f66bfe887 [gamecode] Update printed opcode width
Opcodes now need 3 hex digits (hexits?) to print.
2022-01-20 18:37:28 +09:00
Bill Currie 068c04ece6 [gamecode] Add ev_ushort and partial support
Really, only just enough to get everything compiling (which does include
vkgen running correctly).
2022-01-18 22:08:37 +09:00
Bill Currie cd30408675 [gamecode] Rename ev_quat to ev_quaternion
I much prefer the full name, though the short version is easier to type.
2022-01-18 17:05:12 +09:00
Bill Currie e9e54d08c0 [gamecode] Rename func_t to pr_func_t
Even more consistency.
2022-01-18 15:36:58 +09:00
Bill Currie afd1eb775b [gamecode] Rename ev_pointer to ev_ptr
Rather short (no worse than ev_int, though) but more consistency is
usually a good thing.
2022-01-18 14:36:06 +09:00
Bill Currie cfe7c44df0 [gamecode] Rename ev_integer to ev_int
And other related fields so integer is now int (and uinteger is uint). I
really don't know why I went with integer in the first place, but this
will make using macros easier for dealing with types.
2022-01-18 13:27:19 +09:00
Bill Currie 2df64384c1 [gamecode] Clean up string_t and pointer_t
They are both gone, and pr_pointer_t is now pr_ptr_t (pointer may be a
little clearer than ptr, but ptr is consistent with things like intptr,
and keeps the type name short).
2022-01-18 12:11:14 +09:00
Bill Currie 8e5c2c6534 [gamecode] Correct type of return address in stack
This is another one of those "why signed?" things: can't have negative
return addresses.
2022-01-17 14:43:43 +09:00
Bill Currie 0bd05c71ac [gamecode] Use unsigned for entity values
I don't know why they were ever signed (oversight at id and just
propagated?). Anyway, this resulted in "unsigned" spreading a bit, but
all to reasonable places.
2022-01-16 22:15:18 +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 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 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 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 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 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 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 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 81f73e4524 [gamecode] Support printing a single edict field 2021-07-25 09:54:08 +09:00
Bill Currie 86cf7fbecd [gamecode] Check for null edict before printing number
Avoids segfault during double-verbose disassembly of progs code that
uses entities.
2021-07-24 18:04:57 +09:00
Bill Currie d865095d0b [gamecode] Check for nil entity
Fixes a segfault when disassembling progs.dat files that access entity
fields as the accessed entity will generally be nil.
2021-06-28 18:12:15 +09:00
Bill Currie d23c9582f1 [qwaq] Implement execute-to-cursor
Support for finding the first address associated with a source line was
added to the engine, returning 0 if not found.

A temporary breakpoint is set and the progs allowed to run free.
However, better handling of temporary breakpoitns is needed as currently
a "permanent" breakpoint will be cleared without clearing the temporary
breakpoing if the permanent breakpoing is hit while execut-to-cursor is
running.
2021-06-08 16:54:04 +09:00
Bill Currie 6fea5f5e1a [build] Add -Wformat-non-literal option
While this caused some trouble for pr_strings and configurable strftime
(evil hacks abound), it's the result of discovering an ancient (from
maybe as early as 2004, definitely before 2012) bug in qwaq's printing
that somehow got past months of trial-by-fire testing (origin understood
thanks to the warning finding it).
2021-03-29 17:27:06 +09:00
Bill Currie c9f1d770e0 Merge master into csqc-improvements
That was a mess
2021-03-25 22:01:31 +09:00
Bill Currie 66fda1fddb Rewrite edict access.
The server edict arrays are now stored outside of progs memory, only the
entity data itself (ie data accessible to progs via ent.fld) is stored in
progs memory. Many of the changes were due to code accessing edicts and
entity fields directly rather than through the provided macros.
2021-03-25 18:13:48 +09:00
Bill Currie 56cf181a11 [gamecode] Make PR_RESMAP macros more function-like
I never liked that some of the macros needed the type as a parameter
(yay typeof and __auto_type) or those that returned a value hid the
return statement so they couldn't be used in assignments.
2021-03-21 21:26:36 +09:00
Bill Currie db14025935 [gamecode] Put strings and debug back in load funcs
It turns out they're required to be initialized before most of the rest
of the system.
2021-01-12 17:34:57 +09:00
Bill Currie ab04a1915e [build] Fix a pile of gcc 10 issues
gcc got stricter about array accesses, complicating progs macros, and
much better at detecting buffer overflows.
2020-12-21 14:14:29 +09:00
Bill Currie cf7c4780eb [gamecode] Load extended debug data
And add function to get a source file's base directory if available.
2020-04-04 12:50:25 +09:00