Commit Graph

38 Commits

Author SHA1 Message Date
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 3e7f2f0578 Fix some doxygen issues
Updating parameter names for renamed parameters and adding docs for new
parameters.
2022-09-22 09:35:57 +09:00
Bill Currie 330569a3fb [sound] Add a function to set ambient sounds
This gets ambient sounds (in particular, water and sky) working again
for quakeworld after the recent sound changes, and again for nq after I
don't know how long.
2022-06-06 14:29:14 +09:00
Bill Currie 5fa73e7ff2 [sound] Rename "cache" to "block" and clean out old code
I never liked "cache" as a name because it said where the sound was
stored rather than how it was loaded/played, but "stream" is ok, since
that's pretty much spot on. I'm not sure "block" is the best, but it at
least makes sense because the sounds are loaded as a single block (as
opposed to being streamed). An now, neither use the cache system.
2022-06-06 12:39:54 +09:00
Bill Currie 79f3f651a4 [sound] Bring QF into the atomic age
Nuclear powered audio ;)

More seriously, use _Atomic on a few fields that very obviously need it.
That is, channel's buffer pointer (used to signal to the mixer that the
channel is ready for use) and "flow control" flags (stop, done and
pause), and head and tail in the buffer itself. Since QF has been
working without _Atomic (admittedly, thanks to luck and x86's strong
memory model), this should do until proven otherwise. I imagine getting
stream reading out of the RT thread will highlight any issues.
2022-06-06 12:39:54 +09:00
Bill Currie 5ab88b0137 [sound] Clean up white space in snd_internal.h 2022-06-06 12:39:54 +09:00
Bill Currie fdd070f6dc [sound] Add a threaded field to snd_t
Care needs to be taken when freeing channels as doing so while an
asynchronous mixer is using them is unlikely to end well. However,
whether the mixer is asynchronous depends on the output driver. This
lets the driver inform the rest of the system that the output and mixer
are running asynchronously.
2022-06-06 12:39:54 +09:00
Bill Currie 91140acfee [sound] Access the buffer directly from the channel
This improves the locality of reference when mixing and removes the
proxy sfx for streamed sounds.

The buffer for streamed sounds is allocated when the stream is opened
(since streamed sounds can't share buffers), and freed when the stream
is closed.

For block sounds, the buffer is reference counted (with the sfx holding
one reference, so currently block buffers never get freed), with their
reference count getting incremented on open and decremented on close.
That the reference counts get to 1 has been confirmed, so all that
should be needed is proper destruction of the sfx instances.

Still need to sort out just why channels leak across level changes.
2022-06-06 12:39:54 +09:00
Bill Currie 4e550ac9c7 [sound] Move block buffers into locked memory
Sounds no longer use the cache, which is good for multi-threaded, but a
pain for memory management: the buffers are shared between channels that
play back the sounds, but when the sounds were cached, they were
automagically (thus problematically) freed when the space was needed.
That no longer happens, so they leak. I think the solution is to use
reference counting and retain/release in sfx->open() and sfx->close().
2022-06-04 23:55:31 +09:00
Bill Currie deab21cb4b [sound] Move stream buffers into locked memory
Streams are the easy one as they were never in the cache. As a side
effect, sfxstream_t is much smaller as it no longer has the buffer
embedded in the struct.
2022-06-04 18:45:11 +09:00
Bill Currie 632226dd32 [sound] Rename sfxbuffer_t's length to size
The field is the size of the buffer, while "length" is a bit ambiguous
between buffer length or sfx length.
2022-06-04 17:05:03 +09:00
Bill Currie da90d93135 [sound] Move most spacialization fields out of channel_t
More shrinkage. It turned out the mixer uses the phase fields, so they
couldn't be removed, but even at 192kHz, +/- 127 samples produces
sufficient phase separation for a 21cm head (which is, actually, pretty
big: mine is about 15cm across), but that change can come later.

The ambient sound loading has been removed from snd_channels because 1)
it doesn't work for nq, 2) it should never have been there in the first
place (it belongs in the client, but that needs some more API).
2022-06-04 16:20:19 +09:00
Bill Currie 5fd9098e05 [sound] Remove the next pointer and entity channel from channel_t
This is part of a process to shrink channel_t so it doesn't waste locked
memory when it gets moved there. Eventually, only the fields the mixer
needs will be in channel_t itself: those needed for spacialization will
be moved into a separate array.

In the process, I found that channels leak across level changes, but
this appears to be due to the cached sounds being removed during loading
and the mixer never marking them as done (it sees the null sfx pointer
and assumes the channel was never in use). Having the mixer mark the
channel as done seems to fix the leak, but cause a free channel list
overflow. Rather than fight with that, I'll leave the leak for now and
fix it at its root cause: the management of the sound samples
themselves.
2022-06-04 12:28:16 +09:00
Bill Currie 5b38117689 [sound] Make all volumes 0-1 (float) instead of 0-255 (int)
The scaling up of the volumes when setting a channel's volume bothered
me. The biggest issue being it hasn't been necessary for over a decade
since the conversion to a float-mixer. Now the volume and attenuation
scaling from protocol bytes is entirely in the client's hands.
2022-06-03 16:54:57 +09:00
Bill Currie 1f16f875f6 [sound] Clean up the public API
sfx_t is now private, and cd_file no longer accesses channel_t's
internals. This is necessary for hiding the code needed to make mixing
and channel management *properly* lock-free (I've been getting away with
murder thanks to x86's strong memory model and just plain luck with
gcc).
2022-06-03 15:20:41 +09:00
Bill Currie 9166b08b06 [sound] Move sfx_t definition into snd_internal.h
I always wanted it there, there were dependency issues at the time. I
guess they got cleaned up for the most part since then (other than
cd_file, but it's on my hit-list).
2022-06-03 11:54:53 +09:00
Bill Currie fddff1c24d Merge branch 'master' into wip-rua_scene 2022-04-25 08:13:35 +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 55f7886607 Remove some long dead cvars
The declarations were still around, but the creation and code using them
was removed long ago.
2022-04-24 17:23:46 +09:00
Bill Currie 32a395a8d5 [dox] Fix up some doxygen issues
I found a few doxygen related patches in my git stash and while testing
them, found a few doc issues.
2022-04-13 14:17:58 +09:00
Bill Currie e97b96b536 Remove some long dead cvars
The declarations were still around, but the creation and code using them
was removed long ago.
2022-04-13 14:17:58 +09:00
Bill Currie da42aaf423 [sound] Use vec4f_t for api functions
Fixes a few vec3_t/vec4f_t FIXMEs.
2022-03-30 23:42:38 +09:00
Bill Currie 57dd4494cc [renderer] Pass in a camera transform
More r_data cleanup. Things could be better still, but this is a start.
2022-02-28 16:59:38 +09:00
Bill Currie c87be87741 Fix some doxygen warnings 2021-12-25 11:17:33 +09:00
Bill Currie f8ffb12713 [audio] Clean up jack and alsa dependencies
I had forgotten to test with shared libs and it turns out jack and alsa
were directly accessing symbols in the renderer (and in jack's case,
linking in a duplicate of the renderer).

Fixes #16.
2021-06-27 01:57:59 +09:00
Bill Currie 54bc7a83ba [audio] Fix missed compile issues
Due to not having wildmidi on my eeepc.
2021-06-24 00:14:33 +09:00
Bill Currie fc907e232f [audio] Rework alsa to use a pull model
This brings the alsa driver in line with the jack render (progress
towards #16), but breaks most of the other drivers (for now: one step at
a time). The idea is that once the pull model is working for at least
one other target, the jack renderer can become just another target like
it should have been in the first place (but I needed to get the pull
model working first, then forgot about it).

Correct state checking is not done yet, but testsound does produce what
seems to be fairly good sound when it starts up correctly (part of the
state checking (or lack thereof), I imagine).
2021-06-24 00:08:05 +09:00
Bill Currie 07b869d1bf Fix some doxygen warnings 2021-01-22 15:23:04 +09:00
Bill Currie fbd79963bb Update for doxygen 1.8.16 2020-02-11 15:20:49 +09:00
Bill Currie 34bcf7faab Do a pure/const/noreturn/format attribute pass.
I always wanted these, but as gcc now provides warnings for functions that
could do with such attributes, finding all the functions is much easier.
2018-10-09 12:42:21 +09:00
Bill Currie 23a38738fc Massive whitespace cleanup.
Lots of trailing whitespace and otherwise blank lines.
2012-05-22 08:23:22 +09:00
Bill Currie 87e56e0655 Fix some doxygen issues. 2012-04-22 22:20:45 +09:00
Bill Currie bc1b483525 Nuke the rcsid stuff.
It's pretty useless in git.
2012-04-22 10:56:32 +09:00
Bill Currie ce6ab908a5 Don't include the specific plugin headers in plugin.h.
This lets files that use plugins not depend on plugins they don't use.
2012-02-13 22:02:07 +09:00
Bill Currie 9a91aff93c Move the ambient level check out of the sound renderer.
Instead, the client gets the current leaf and passes ambient_sound_level
from the leaf to S_Update.
2012-02-13 13:44:29 +09:00
Bill Currie 881d4babce Fix some undefined symbols in snd_alsa.c.
Serves me right for testing with only my debug build :P
2011-09-08 18:10:09 +09:00
Bill Currie a8ea3aaad9 Allow dma sound targets to specify an xfer function. 2011-09-07 17:00:18 +09:00
Bill Currie efa0105748 Rename some headers to fix doxygen warnings. 2011-07-23 15:58:45 +09:00
Renamed from include/snd_render.h (Browse further)