Commit Graph

1108 Commits

Author SHA1 Message Date
Bill Currie 062f616548 [cexpr] Add support for casting plitems
This allows using references in expressions, eg:

    $frames.size * size_t($properties.limits.maxSamplers)

As references remain property list items until actually evaluated.
2021-12-24 06:45:13 +09:00
Bill Currie e7b067d6a9 [cexpr] Add some functions for size_t and uint
Casting for size_t and uint, and min/max/bound for size_t.
2021-12-24 06:45:13 +09:00
Bill Currie ee1c3e7db5 [cexpr] Clean up the macros a little 2021-12-24 06:45:13 +09:00
Bill Currie d2eb928210 [cexpr] Add a small library with some useful functions
For now, just dot product, trig, and min/max/bound, but it works well as
a proof of concept. The main goal was actually min. Only the list of
symbols is provided, it is the user's responsibility to set up the
symbol table and context.
2021-12-24 06:45:12 +09:00
Bill Currie 44102f2639 [cexpr] Support chained contexts for scoping
cexpr's symbol tables currently aren't readily extended, and dynamic
scoping is usually a good thing anyway. The chain of contexts is walked
when a symbol is not found in the current context's symtab, but minor
efforts are made to avoid checking the same symtab twice (usually cased
by cloning a context but not updating the symtab).
2021-12-24 06:45:12 +09:00
Bill Currie 049968b38e white space 2021-12-24 06:45:12 +09:00
Bill Currie 4e8718980f [cexpr] Remove some disabled code
It looks like a munged commit, but I think I had decided that it was
best to make cvar access explicit.
2021-12-24 06:45:12 +09:00
Bill Currie c8846f8007 [cexpr] Support array indexing
The index is currently limited to ints, and is bounds checked (the array
type has a size field indicating the number of elements).
2021-12-24 06:45:12 +09:00
Bill Currie 614c744693 [cexpr] Use ` to allow identifiers to start with a number
The generated short names for a lot of Vulkan enums start with a number
(eg VK_IMAGE_TYPE_2D -> 2d). Having to prefix the short name with ` is a
tiny cost for the convenience.
2021-12-24 06:45:12 +09:00
Bill Currie a6703c95cf [plist] Allow ` to be used without quotes
It has no special meaning when parsing property lists, so there's no
reason to require quotes around it.
2021-12-24 06:45:12 +09:00
Bill Currie bd31f40c9b [cexpr] Support varargs functions
While there may be better solutions, I needed a varargs function for
building Vulkan specialization data. Like progs functions, negative
parameter counts indicate ellipsis with the number of fixed parameters
being equal to -param_count - 1.
2021-12-24 06:45:12 +09:00
Bill Currie 9d4017885f [cvar] Preserve cvars loaded from config files
This restores the equivalent functionality that seta in config.cfg
provided (no more losing my volume setting after using -nosound).
2021-12-17 08:32:36 +09:00
Bill Currie 032f9971ed [plist] Remove incorrect const from PL_RemoveObjectForKey
I'm not sure what I was thinking when I made PL_RemoveObjectForKey take
a const plitem. One of those times where C could do with being a little
more strict.
2021-12-17 08:30:00 +09:00
Bill Currie c4118a4bf1 [util] Add listeners to cvars
Listeners are separate to the main callback as listeners have only
read-only access to the objects, but the main callback is free to modify
the cvar and thus can act as a parser and validator. The listeners are
invoked after the main callback if the cvar is modified. There does not
need to be a main callback for the listeners to be invoked.
2021-11-25 17:46:16 +09:00
Bill Currie c069e7754f [util] Add a listener object
I decided cvars and input buttons/axes need listeners so any changes to
them can be propagated. This will make using cvars in bindings feasible
and I have an idea for automatic imt switching that would benefit from
listeners attached to buttons and cvars.
2021-11-25 13:36:02 +09:00
Bill Currie 48ecfcf411 [cexpr] Fix a naming issue with uint
I didn't notice that uint is defined somewhere on Linux... until I tried
compiling for windows (not defined). Use a define to keep the cast
function naming nice.
2021-11-19 08:58:02 +09:00
Bill Currie 111e5d923e [cexpr] Support casting to double
For int, uint and float, also add uint to float (not that it will do any
good for values over 16M).
2021-11-16 19:59:47 +09:00
Bill Currie b80c19bd77 [util] Save and load cvars to/from plist configs
Other than some backwards compatibility, this completes the
configuration updates for now.
2021-11-15 22:04:29 +09:00
Bill Currie 7c9f3a3b09 [util] Expose the quakerc check function
qargs probably needs to go away. It certainly needs to be rethought. For
now, this is good enough to get qw working with plist-based
quakeforge.cfg
2021-11-14 10:12:14 +09:00
Bill Currie 6e85377d7a [cexpr] Support variable assignment
I might have to add code to block it when necessary, but it's needed for
axis recipe parsing.
2021-11-12 00:19:58 +09:00
Bill Currie 7d022db702 [util] Avoid Sys_Shutdown for IO signals
It turns out that calling Sys_Shutdown in the signal handler can cause
lockups due to the signal occurring at unsafe times. Fortunately, this is
just the IO related signals (INT, HUP, TERM, QUIT) as the others are
usually caused by actual errors and should not occur in system code thus
timing should not be an issue. However, care will need to be taken when it
comes to handling SIGINT or similar for breaking runaway progs code when
that time comes.
2021-11-05 09:56:08 +09:00
Bill Currie cacf0be7f6 [util] Wrap fd_set
While select itself is reasonably portable, it turns out that including
the declaration for fd_set makes a bit of a mess for QF's clean headers.
2021-09-28 10:53:51 +09:00
Bill Currie 940d824be0 [util] Split out the select code to Sys_Select
While select itself is fairly portable, it's not super convenient.
2021-09-26 14:54:24 +09:00
Bill Currie 05215e0295 [util] Add functions to help convert external times 2021-08-27 12:10:05 +09:00
Bill Currie 5d4013b485 [util] Use clock_gettime for Sys_LongTime
While QF doesn't currently use nanoseconds, having access to a clock
that is not affected by setting system time is nice, and as a bonus, can
handle suspends should the need arise.
2021-08-27 11:22:57 +09:00
Bill Currie 8a5c3c1ac1 [util] Add sys function to get cpu count
And use it in qfvis.
2021-08-13 21:26:48 +09:00
Bill Currie a01cafe972 [util] Minimize set growth
At the low level, only unions can cause a set to grow. Of course, things
get interesting at the higher level when infinite (inverted) sets are
mixed in.
2021-08-11 12:31:03 +09:00
Bill Currie 37a5b475c0 [util] Minimize the string for infinite sets
Instead of printing every representable member of an infinite set (ie,
up to element 63 in a set that can hold 64 elements), only those
elements up to one after the last non-member are listed. For example,

    {...} - {2 3} -> {0 1 4 ...}

This makes reading (and testing!) infinite sets much easier.
2021-08-11 12:31:03 +09:00
Bill Currie aa72f1dc31 [util] Fix reversed finite-infinite set union ops
It looks like I tried to test it, but my tests weren't so good This
seems to cover everything for the three main set ops.
2021-08-11 12:31:03 +09:00
Bill Currie b320c3352f [util] Make set_t endian-agnostic
Most of the set ops were always endian-agnostic since they were simply
operating on multiple bits in parallel, but individual element
add/remove/test was very endian-dependent. For the most part, this
didn't matter, but it does matter very much when loading external data
into a set or writing the data out (eg, for PVS).
2021-08-08 12:34:18 +09:00
Bill Currie d56d8ac707 [util] Loosen up the epsilon on simd seb tests
It seems my eeepc's SSE units don't get quite the same answers as does
my i7's (maybe due to lack of hadd?).
2021-08-02 23:15:20 +09:00
Bill Currie 80b17623b1 [util] Fix an out-by-one in pqueue tests
Showed up only when the data arrays were packed.
2021-08-02 23:08:14 +09:00
Bill Currie f76964b86b [util] Add an priority queue implementation
Done via macros (like darray and ringbuffer). Might prove useful for
qfvis and maybe dynamic lights.
2021-08-02 13:29:55 +09:00
Bill Currie 4f2113bc05 [util] Enable accidentally disabled seb tests 2021-08-02 12:44:08 +09:00
Bill Currie e4984aad17 [util] Add functions for binary heaps
Sink, swim, build and sort, both "simple" and with a data parameter for
the compare function.
2021-08-02 12:44:08 +09:00
Bill Currie 674ffa0941 [util] Make bsp_t counts size_t
and other bsp data counts unsigned, and clean up the resulting mess.
2021-08-01 21:54:05 +09:00
Bill Currie 80a89c5e1e [util] Write the correct bsp format id for bsp2
Oops :P
2021-08-01 14:07:24 +09:00
Bill Currie 9d819254d4 [util] Make a number of improvements to SEB
Attempting to vis ad_tears drags a few lurking bugs out of
SmallestEnclosingBall_vf: poor calculation of 2-point affine space, poor
handling of duplicate points and dropped support points, poor
calculation of the new center (related to duplicate points), and
insufficient iterations for large point sets. qfvis (modified for
cluster spheres) now loads ad_tears.
2021-07-30 14:57:47 +09:00
Bill Currie fe98a513bc [util] Add a function to check hunk pointers
Its only real utility is to check that a pointer is not pointing into
freed space.
2021-07-29 15:27:48 +09:00
Bill Currie 6d312aaa63 [simd] Check the distance to the affine point
As per usual, fp math finds a way to confound any epsilon test. So
rather than relying entirely on test_support_points, check the distance
from the sphere center to the affine point and break out of the loop if
the distance is small enough (< 1% of the current radius). This allows
qfvis to load ad_tears without hacks.
2021-07-29 15:15:14 +09:00
Bill Currie 45aa8e6504 [util] Loosen affine test epsilon for SEB
Scaling the checks by 1e-6 was a little too tight for very small
triangles, but 1e-5 seems to work well. This fixes SEB getting stuck for
a ridiculously small (for quake) triangle in ad_tears (probably resulted
from some bad math in qfbsp when generating the portal file from the
bsp).
2021-07-29 15:03:54 +09:00
Bill Currie 4f51a3b406 [utils] Fix set tests for 32-bit machines 2021-07-29 14:10:18 +09:00
Bill Currie 8f376a48f8 [util] Add raw versions of hunk alloc and free
They do not clear memory and thus are good for situations where speed is
more critical.
2021-07-29 11:44:10 +09:00
Bill Currie ca63c0360a Do an audit of hunk mark usage
I realized that after making the hunk 64-bit clean, I had forgotten to
go through and convert all the saved marks to size_t.
2021-07-29 11:43:27 +09:00
Bill Currie 54604d9aa2 [util] Make hunk (optionally) thread-safe
For now, the functions check for a null hunk pointer and use the global
hunk (initialized via Memory_Init) if necessary. However, Hunk_Init is
available (and used by Memory_Init) to create a hunk from any arbitrary
memory block. So long as that block is 64-byte aligned, allocations
within the hunk will remain 64-byte aligned.
2021-07-29 11:43:27 +09:00
Bill Currie 8fdd9c1f5a [util] Write some tests for utf8 r/w
And fix some errors with 5-byte encodings.
2021-07-27 23:29:14 +09:00
Bill Currie 5b4428420e [utils] Get utf-8 writing working for up to 11 bits
I need to write some automated tests for this, and reading of course,
but 1 and two byte outputs look correct. Kind of sad it took sixteen
years to get around to attempting to use the code :(
2021-07-27 23:29:02 +09:00
Bill Currie 163d147044 [util] Give set_count a >8x speed boost
I knew counting bits individually was slow, but it never really mattered
until now. However, I didn't expect such a dramatic boost just by going
to mapping bytes to bit counts. 16-bit words would be faster still, but
the 64kB lookup table would probably start hurting cache performance,
and 32-bit words (4GB table) definitely would ruin the cache. The
universe isn't big enough for 64-bits :)
2021-07-27 13:54:22 +09:00
Bill Currie 49c3dacbbc [util] Rename set_size to set_count
After seeing set_size and thinking it redundant (thought it returned the
capacity of the set until I checked), I realized set_count would be a
much better name (set_count (node->successors) in qfcc does make much
more sense).
2021-07-27 11:52:21 +09:00
Bill Currie cf96f340df [util] Use same distance calc in simd CC test
The test started failing when optimizing (not sure why). Using the same
code to calculate the squared distance "fixes" the test.
2021-07-26 15:46:12 +09:00