Commit graph

226 commits

Author SHA1 Message Date
Bill Currie
ac42bca98b [ruamoko] Support nil object in obj_error
Segfaulting when trying to produce an error message doesn't help get the
message out. Sure, `obj_error (nil...)` is a bit of an abuse, but it
shouldn't segfault the engine.
2023-05-27 12:47:33 +09:00
Bill Currie
db9a6a9a5c [ruamoko] Make cbuf functions take a cbuf param
A nil param refers to the default cbuf if it has been set by the engine,
otherwise it is invalid. This is the first step to fleshing out the cbuf
API.
2023-05-24 21:01:07 +09:00
Bill Currie
3a9148a3e0 [ruamoko] Return nil for %@ printf format
Fixes a segfault when attempting to print a nil object.
2023-05-18 20:53:04 +09:00
Bill Currie
9317ce7358 [ruamoko] Handle missing fonts correctly
Carrying on as if the missing font had been loaded leads to way too many
issues for it to be a good thing (not that that really needs to be
said). Fixes the segfaults in my test scene.
2023-03-28 13:23:14 +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
ea77df2daa [plist] Add parsing for bare dictionaries and arrays
Requiring top-level {} or () for (usually) hand-written files is awkward
and even a little error prone, and certainly ugly at times. With this,
loaders that expect a particular format can specify the format a little
more directly.
2023-03-12 14:31:17 +09:00
Bill Currie
340127fff2 [ruamoko] Plug yet more memory leaks
Some of them, especially in rua_obj, were quite legitimate and even a
problem for thread-safety (rua_cmd is currently not thread-safe, but it
needs a lock, which I don't feel like doing at this stage).
2023-03-05 18:31:30 +09:00
Bill Currie
161ccc282f [ruamoko] Unlink passage nodes when deleting
Fixes a segfault on shutdown after the memory leak changes.
2023-03-04 02:23:37 +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
2748f1c9f7 [ruamoko] Add support for PL_KeyAtIndex
I'd forgotten to wrap the function when I added it, but didn't need it
until now.
2023-02-14 12:45:04 +09:00
Bill Currie
70e93bb7e8 [ruamoko] Advance glyphset when working through the pool
It seems to help if the right font data is used when rendering glyphs.
Fixes use of multiple fonts in different passages.
2023-01-03 20:20:02 +09:00
Bill Currie
24a85dbadc [ui] Add a component set for passage hierarchy refs
While "set" is a tad strong (there's just the one component for now), I
had missed the changes when adding ECS systems. Fixes the segfault at
the end of demo1 (ie, when any center text is printed).
2022-12-16 18:12:38 +09:00
Bill Currie
41d25df0d2 [ui] Attach text views to passage entities
Instead of creating new entities for the text views. This approximately
halves the number of entities required to display flowed text, but also
tests the ability to have an entity in multiple hierarchies (the goal of
the ECS component and system changes).
2022-12-14 22:38:37 +09:00
Bill Currie
bb677a1a7c [ecs] Move href_comp into hierarchy_t
This means that the component id used for hierarchy references must be
passed to Hierarchy_New and Hierarchy_Copy, but does all an entity to
have more than one hierarchy, which is useful for canvases (hierarchies
of views) in the 3d world (the canvas root would have a 3d hierarchy
reference and a 2d (view) hierarchy reference).
2022-12-12 00:20:20 +09:00
Bill Currie
c316b6b5d1 [ruamoko] Wrap more text and view functions
rua_gui.c is still a horrible mess of hacks, but it does the job for
testing the text code.
2022-12-10 19:05:39 +09:00
Bill Currie
b93ab95c47 [ruamoko] Add some builtins for passages and text
Just some basic implementation so I can test shaping of passage text.
2022-12-09 15:18:47 +09:00
Bill Currie
5fd510ade4 [ui] Add font to renderer when loading
This causes some problems with linking if libQFgui is linked with
libQFrenderer (which is necessary in the long run), but it seems
everything gets away with it for now (which, tbh, I don't like).
2022-12-08 16:57:45 +09:00
Bill Currie
136bf882f6 [ui] Move font loading into new gui library
Font and text handling is very much part of user interface and at least
partially independent of rendering, but does fit it better with GUI than
genera UI (ie, both graphics and text mode), thus libQFgui as well as
libQFui are built in the ui directory.

The existing font related builtins have been moved into the ruamoko
client library.
2022-12-07 17:38:38 +09:00
Bill Currie
0e64f959e2 [scene] Move visibility management into scene code
Well, sort of: it's still really in the renderer, but now calling
R_AddEfrags automatically updates the visibility structure as necessary,
and deleting an entity cleans up the efrags automatically. I wanted this
over twenty years ago.
2022-11-13 15:08:18 +09:00
Bill Currie
600a342200 [ruamoko] Fix missing entity registry pointer 2022-10-26 17:45:45 +09:00
Bill Currie
db7f8a461e [ecs] Move ECS core into its own library
While the libraries are probably getting a little out of hand, the
separation into its own directory is probably a good thing as an ECS
should not be tied to scenes. This should make the ECS more generally
useful.
2022-10-26 17:24:03 +09:00
Bill Currie
8acd5c558b [scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).

While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 22:24:36 +09:00
Bill Currie
de786ce197 [scene] Use hierref_t instead of transform_t in hierarchy
Hierarchies are now much closer to being more general in that they are
not tied to 3d transforms. This is a major step to moving the whole
entity/transform system into an ECS.
2022-10-22 13:04:07 +09:00
Bill Currie
54bd8f5a02 [ruamoko] Implement %@ handing in the ruamoko runtime
-describe is sent to the object, and the returned string passed back.
There is a worry about the lifetime of the returned string as there's
currently no way of both ensuring it doesn't get freed prematurely and
ensuring it does eventually get freed.
2022-09-09 13:51:42 +09:00
Bill Currie
2bb0f0c104 [zone] Add support for reference counting to Z_*
And use it for Ruamoko object reference counts.

I need reference counts for dealing with block sound buffers since they
can be shared by many channels. I figured I take care of Ruamoko's
reference count location at the same time.

Fixes #27.
2022-06-06 12:39:54 +09:00
Bill Currie
50226a64c3 [ruamoko] Free buffer used for loading plists
That's definitely a leak.
2022-05-12 22:47:55 +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
ea8f991bf3 [ruamoko] Clear efrags when destroying an entity
This ensures the rendering system won't attempt to draw the entity after
it has been destroyed.
2022-05-07 09:53:26 +09:00
Bill Currie
ed82b5f299 [ruamoko] Clean up lighting data blocks
Don't want to leak memory.
2022-05-06 08:26:55 +09:00
Bill Currie
d14b17567e [ruamoko] Add builtins for adding lights to scenes
Pretty much just raw wrappers around the C versions. I'm not sure about
Light_EnableSun (even in C), but it does build the sky surf pvs.
2022-05-05 23:49:31 +09:00
Bill Currie
d850285e3f [ruamoko] Allow scenes to be fetched by C code
Need to clean up that part of the API, though.
2022-05-05 23:49:31 +09:00
Bill Currie
2493ca71c7 [ruamoko] Allow entity model to be set
And add header and function definitions for scene to libcsqc.
2022-05-04 17:38:38 +09:00
Bill Currie
3de10f32c7 [ruamoko] Add builtins for handling models
Just "loading" and "unloading" (both really just hints due to the
caching system), and an internal function for converting a handle to a
model pointer, but it let me test IQM loading and unloading in Vulkan.
2022-05-04 14:44:54 +09:00
Bill Currie
4ed9fc6820 [ruamoko] Switch to 64-bit handles for scene objects
The scene id is in the lower 32-bits for all objects (upper 32-bits are
0 for actual scene objects) and entity/transform ids are in the upper
32-bits. Saves having to pass around a second parameter in progs code.
2022-04-29 21:02:08 +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
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
3c86764eb2 [scene] Move entity_t etc into scene headers
I meant to do this a while ago but forgot about it. Things are a bit of
a mess in that the renderer knows too much about entities, but
eventually the renderer will know about only things to render (meshes,
particles, etc).
2022-03-29 14:43:38 +09:00
Bill Currie
73444c3b7a [ruamoko] Give the scene resource block a rua prefix
No effect on the code itself, but it makes debugging much easier when
there aren't two very different structs with the same name.
2022-03-05 02:05:59 +09:00
Bill Currie
54f0af854b [ruamoko] Wrap the transform fuctions
Except for get/set name as I'm still pondering strings.
2022-02-15 00:06:39 +09:00
Bill Currie
f0c35e541a [ruamoko] Pass some more purity tests
Separate because I want to cherry-pick the other commit.
2022-02-14 19:56:56 +09:00
Bill Currie
e58d53d4b6 [gamecode] Pass gcc's purity test again
I guess maybe that change might make a bigger difference than I thought,
gcc wasn't happy with it.
2022-02-14 19:30:50 +09:00
Bill Currie
afbca54faf [ruamoko] Add wrappers for the existing scene functions
I've run into a bit of an issue with transform management (really, just
need to make them owned by the scene, but that means creating a scene
for quake and quakeworld).
2022-02-14 16:43:10 +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
1d26c727a3 [ruamoko] Allocate selectors in large blocks
The zone memory block header is 64 bytes, so allocating a single 8 byte
selector is rather wasteful. Instead, allocate selectors in large chunks
(currently 64) and divvy them out as needed. Significantly reduces
memory pressure in large Ruamoko progs.
2022-02-12 01:52:35 +09:00
Bill Currie
7c6ef06dfb [gamecode] Make PF_VarString v6p-only
It's not enforced a this stage, and it would be easy enough to handle,
but it turns out all the standard quake and quakeworld progs never used
... for the print functions: the behavior of PF_VarString was
undocumented and so... tough :P.
2022-02-06 21:20:00 +09:00
Bill Currie
c10b09d41b [ruamoko] Make RUA_Sprintf more generally useful
It now takes the function name to print in error message (passed on to
PR_Sprintf) and the argument number of the format string. The variable
arguments (in ...) are assumed to be immediately after the format
argument.
2022-02-05 20:24:17 +09:00
Bill Currie
b0810958e7 [ruamoko] Use encoded selector param count when forwarding
This gets message forwarding apparently working, though something isn't
quite right as qwaq-app doesn't update properly when I try to step
through the program, but that could be an error elsewhere.
2022-02-05 14:24:12 +09:00
Bill Currie
2c0969f988 [ruamoko] Rework method call hand-off to preserve the stack
This takes care of the problems with PR_RESET_PARAMS (which has recently
become just a wrapper for PR_SetupParams) changing the stack and causing
PR_CallFunction to save the wrong stack pointer. Message forwarding is
currently broken for Ruamoko ISA progs, but that is due to not having a
valid pr_argc. However, I do have a plan involving extracting the
parameter count from the selector, but that's something for a later
commit. Everything else seems to be ok (my little game is working
nicely).
2022-02-05 13:01:44 +09:00