Commit Graph

1179 Commits

Author SHA1 Message Date
Bill Currie 39103cc8a3 [sw] Fix some 32-bit assembly issues
I'm not sure that the mismatch between refdef_t and the assembly defines
was a problem (many fields unused), but the main problem was due to
execute permission on the pages: one chunk of asm was in the data
section, and the patched code was not marked as being executable (due to
such a thing not existing when quake was written).
2021-04-02 22:17:32 +09:00
Bill Currie 9ded490806 [util] Add Sys_PageSize
Eliminate that particular problem once and for all.
2021-04-01 18:20:56 +09:00
Bill Currie 73a610508c [util] Fix cmem for windows
I had quite messed up the page size (oops), and missed the fact that
_aligned_free is to be used with _aligned_malloc rather than just free.
2021-04-01 18:00:59 +09:00
Bill Currie 5f93c115ff [util] Make developer flag names easier to manage
They're now an enum, and the flag part of the name is all lowercase, but
now the flag definitions and names list will never get out of sync.
2021-03-29 22:38:47 +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 a754dbca37 [util] Make va return const char *
And clean up the resulting mess.

I don't know why it wasn't doing so, but it certainly should have been.
2021-03-29 17:24:30 +09:00
Bill Currie 00aa584506 [util] Add re-entrant set_as_string
Makes it easier to debug set-related code in multi-threaded code.
2021-03-28 20:25:57 +09:00
Bill Currie b6ab832ed4 [simd] Add vabsf and some more tests 2021-03-28 19:49:43 +09:00
Bill Currie 29e029c792 [util] Add float a simd version of the SEB
And its support functions. I can't tell if it's any faster (mtwist_rand
is a significant chunk of the benchmark timings, oops), but it's nice to
have.
2021-03-27 23:38:10 +09:00
Bill Currie 88ff254f42 Get QF cross-compiling using MXE/mingw32
This includes -win clients (no clue if anything actually works yet).
2021-03-27 20:09:37 +09:00
Bill Currie c4a0f3cc73 [util] Fix a string handling bug
Good grief, they still exist :(
2021-03-27 20:06:40 +09:00
Bill Currie 99f0cde080 [util] Add strndup and reentrant quicksort
Needed for portability.
2021-03-27 20:03:39 +09:00
Bill Currie a9bd436837 [build] Autoconfiscate printf format attribute
I don't know if gnu_printf is appropriate for all cases, but it is
needed for mingw32.
2021-03-27 19:52:59 +09:00
Bill Currie 7c788a6e7a [util] Use size_t for dstring length params
While not overly wrong, unsigned is not really appropriate.
2021-03-27 19:08:18 +09:00
Bill Currie 0167456b21 [util] Loosen up SEB relative epsilon a little
1e-8 is a little too tight, the normal was 4.5x the computed epsilon.
Going to 1e-6 still keeps things tight.
2021-03-27 15:04:13 +09:00
Bill Currie 5d9bf32d3c Merge branch 'vulkan' 2021-03-23 12:31:58 +09:00
Bill Currie cc4167668c Fix a pile of leaks and uninit errors
Still "some" more to go: a pile to do with transforms and temporary
entities, and a nasty one with host_cbuf. There's also all the static
block-alloc lists :/
2021-03-21 19:56:17 +09:00
Bill Currie a3c1b2e992 [util] Rename qfplist.[ch]
The name is a hold-over from before the current quakeforge tree and the
QF include directory.
2021-03-21 16:13:03 +09:00
Bill Currie 6e0cc59e8f [util] Make wad lump failure a soft error
Can't recover from an error if the program is swept out from underneath
you.
2021-03-21 11:36:18 +09:00
Bill Currie 0ace799b27 [util] Support commands with a data parameter
Useful for avoiding a pile of wrapper functions that merely pass on
command-specific data to the actual implementation. Used to clean up the
wrappers in nq and qw cl_input.c
2021-03-20 03:56:16 +09:00
Bill Currie 693225a16f [util] Add a fixme for a comment
The code itself is fine, but the comment is rubbish because it's
confusing, though essentially correct.
2021-03-10 18:05:12 +09:00
Bill Currie 4a97bc3ba5 [util] Create simd quaternion to matrix function
This seems to be pretty close to as fast as it gets (might be able to do
better with some shuffles of the negation constants instead of loading
separate constants).
2021-03-04 17:45:10 +09:00
Bill Currie e3762d8f38 [util] Make plist mostly null-safe
The main purpose is to allow fluent-style:
    const char *targetname = PL_String (PL_ObjectForKey (entity, "targetname"));
    if (targetname && !PL_ObjectForKey (targets, targetname)) {
        PL_D_AddObject (targets, targetname, entity);
    }

[note: the above is iffy due to ownership of entity, but the code from
which the above comes works around the issue]
2021-03-03 18:01:35 +09:00
Bill Currie 45c0255643 [util] Add simd 4x4 matrix functions
Currently just add, subtract, multiply (m m and m v).
2021-03-03 16:34:16 +09:00
Bill Currie 407ea15e35 [util] Fix some test bitrot 2021-03-02 15:05:19 +09:00
Bill Currie 4eb07220cd [util] Make plists more const-correct 2021-02-25 11:55:25 +09:00
Bill Currie 0cd2ece38e [util] Correct element order for vector expressions 2021-02-23 14:37:13 +09:00
Bill Currie 4bda49d798 [util] Correct the lex priority for int constants
The actual need to specify unsigned int constant is a bit of a pain, but
not being able to do so due to lex priority errors is even more of a
pain.
2021-02-17 13:29:53 +09:00
Bill Currie 55104ac430 [util] Allow "any type" results for cexpr
Setting the result type cexpr_exprval tells cexpr to simply return whoe
exprval object rather than the referenced value, thus allowing the
caller to check the type when the expression is context sensitive.
2021-02-09 19:30:30 +09:00
Bill Currie 35f12c36ff [util] Catch some more cexpr errors 2021-02-09 19:29:48 +09:00
Bill Currie 5535d1f8e6 [util] Keep track of plist dictionary key order
The order in which keys are added to the dictionary object is
maintained. Adding a key after removing an old key adds the new key to
the end of the list rather than reusing the old key's spot.
2021-02-09 17:03:33 +09:00
Bill Currie 0dcd946063 [util] Add plist parser for dictionary -> array
PL_ParseLabeledArray works the same way as PL_ParseArray, but instead
takes a dictionary object. The keys of the items are ignored, and the
order is not preserved (at this stage), but this is a cleaner solution
to getting an array of objects when the definitions of those objects
need to be accessible by name as well.
2021-02-09 15:24:28 +09:00
Bill Currie 14e4fd9f6a [util] Pass context to the plist array/symtab parser allocator 2021-02-09 15:01:55 +09:00
Bill Currie a408fd40da [util] Make plist more const-correct 2021-02-09 14:56:48 +09:00
Bill Currie 8664a5b969 [util] Enable parser debugging for cexpr
Not actually turned on in the code, but cexpr_yydebug is present.
2021-02-09 10:02:04 +09:00
Bill Currie dfa7af03c6 [util] Plug a thread-safety hole in plists 2021-02-09 09:57:07 +09:00
Bill Currie e929dca300 [util] Auto-cast plist string items
The casting uses a recursive call to the expression parser, so the
expressions are type-checked automatically.
2021-02-04 22:37:20 +09:00
Bill Currie d2536e584f [util] Add plist support to cexpr
This allows plist objects to be accessed directly from cexpr expressions
using struct.field syntax for dictionary objects and array[index] syntax
for array objects.
2021-02-04 16:58:13 +09:00
Bill Currie 5d1d85f72e [util] Resurrect Hunk_Print and fix some errors
It turned out that Hunk_HighAlloc was not creating a hunk header
(ancient bug by me), and I cleaned up a bunch of name-size issues, along
the way.
2021-02-03 13:21:08 +09:00
Bill Currie 0bfb60775e [util] Ensure hunk allocs are cache alligned
This doesn't seem to make much difference in the vulkan renderer, but it
certainly doesn't hurt.
2021-02-03 13:19:19 +09:00
Bill Currie 7970525ef4 [util] Make va thread-safe
It now takes a context pointer (opaque data) that holds the buffers it
uses for the temporary strings. If the context pointer is null, a static
context is used (making those uses of va NOT thread-safe). Most calls to
va use the static context, but all such calls have been formatted
consistently so they are easy to find when it comes time to do a full
audit.
2021-01-31 16:05:48 +09:00
Bill Currie 12ec6c5c29 [util] Add eol to plist parse errors
I suspect it got lost when I made the error message a string item.
2021-01-26 20:45:07 +09:00
Bill Currie 8224169394 [util] Make plist parse errors a little more useful
Particularly the "unexpected character" ones.
2021-01-23 18:56:15 +09:00
Bill Currie 0622a24380 [util] Support size_t constants
Much like 1u and 1l, 1z is for size_t.
2021-01-20 01:24:32 +09:00
Bill Currie fd07169a80 [util] Support casts from int/uint to size_t
I don't want to do implicit down casts (size_t to uint) but I needed to
be able to reference swapchain array size.
2021-01-10 15:27:39 +09:00
Bill Currie a35eec3877 [util] Fail gracefully when no symtab is present 2021-01-10 15:02:24 +09:00
Bill Currie 16334158bd [util] Support struct pointer accesses in cexpr 2021-01-10 01:51:07 +09:00
Bill Currie 0c1699fdbb Fix a pile of double semicolons 2021-01-09 20:42:23 +09:00
Bill Currie 0da99bc59c [util] Add promotion from float to int to cexpr
I won't go the other way nor will I add double to float.
2021-01-05 23:41:13 +09:00
Bill Currie b493e6ac32 [util] Expose plist type check support functions 2021-01-05 23:39:52 +09:00
Bill Currie a45f8f98b6 [util] Make exprctx hashlinks double pointer
The way I wound up using the field meant that exprctx should not "own"
the hashlinks chain, but rather just point to it. This fixes the nasty
access errors I had.
2021-01-05 19:55:17 +09:00
Bill Currie 5b842da394 [util] Fix types for double and float constants 2021-01-04 00:23:48 +09:00
Bill Currie 55445a25f2 [util] Add some tests for the new cexpr work 2021-01-04 00:23:48 +09:00
Bill Currie 619fe15367 [util] Add vector swizzles to cexpr
That turned out to be a lot easier than expected: needed only 4 ifs per
vector "type" (xyzw vs rgba) instead of 340.
2021-01-04 00:23:48 +09:00
Bill Currie 4562e0b876 [util] Implement more of cexpr
This adds unary, vector and function expressions.
2021-01-04 00:23:48 +09:00
Bill Currie 81300f89f8 [util] Allow multiple types for pl fields
I want to be able to use name references, but that requires string
items, so anything that would normally be dictionary or array (or
binary, even) would also need to accept string. This seemed to be the
cleanest solution. Any custom parser would then need to check the type
and act appropriately, but any inappropriate types have already been
pre-filtered by the standard parsers.
2021-01-02 14:02:33 +09:00
Bill Currie eb52d366c8 [util] Add q-v and v-q multiplication to cexpr 2021-01-02 12:10:58 +09:00
Bill Currie 015cee7b6f [util] Add vector-quaternion shortcut functions
Care needs to be taken to ensure the right function is used with the
right arguments, but with these, the need to use qconj(d|f) for a
one-off inverse rotation is removed.
2021-01-02 10:44:45 +09:00
Bill Currie 7bf90e5f4a [util] Sort out implementation issues for simd 2021-01-02 09:55:59 +09:00
Bill Currie 1fd02322f4 [util] Clean up some minor issues in cmem
I forgot to remove the noinline attribute and do a check with
optimization (to catch the "pure" recommendation).
2021-01-01 22:29:31 +09:00
Bill Currie efdbd59909 [util] Fix handling of sline's list 'pointer'
I forgot to right-shift the value so offsets were becoming 0 or 8
instead of 0-15. This fixes the management of small objects. It turns
out that after this fix, qfvis's problems were caused by fragmentation
in the windings. Need to revisit line allocation and use POT-specialized
pools.
2020-12-30 18:20:11 +09:00
Bill Currie 9090c53519 [util] Add failing sub-line allocator tests
I think the sub-line allocator falling over is the final source of
qfvis's leaks. It certainly causes a mess of the sub-lines. But having
some tests to get working sure beats scratching my head over qfvis :)
2020-12-30 18:20:11 +09:00
Bill Currie d12abc5132 [util] Relink grown free line block
This fixes one source of memory leaks, but it seems some are still
lurking as qfvis still leaks like a sieve.
2020-12-30 18:20:11 +09:00
Bill Currie 73544f0790 [util] Split cmem's free cache-line over size bins
They're binned by powers of two (with in between sizes going to the
smaller bin should I make cache-line allocations NPOT (which I think
might be worthwhile). However, there seems to still be a bug somewhere
causing a nasty leak as now my hacked qfvis consumes 40G in less than a
minute.
2020-12-30 18:20:11 +09:00
Bill Currie 4039075f41 [util] Use a linked list of free cache lines
The idea is to not search through blocks for an available allocation.
While the goal was to speed up allocation of cache lines of varying
cluster sizes, it's not enough due to fragmentation.
2020-12-30 18:20:11 +09:00
Bill Currie 3125009a7c [util] Add vector and quaternion types to cexpr
Although there's no distinction between the two at the C level, I think
it's probably best to separate them in a scripting language.
2020-12-30 18:20:11 +09:00
Bill Currie 1ddd57b09e [util] Add qconj, vtrunc, vceil and vfloor functions
I had forgotten these rather critical functions. Both double and float
versions are included.
2020-12-30 18:20:11 +09:00
Bill Currie 03fcb530c7 [util] Make quat test failure prints clearer 2020-12-30 18:20:11 +09:00
Bill Currie 09a10f80e1 [util] Add basic SIMD implemented vector functions
They take advantage of gcc's vector_size attribute and so only cross,
dot, qmul, qvmul and qrot (create rotation quaternion from two vectors)
are needed at this stage as basic (per-component) math is supported
natively by gcc.

The provided functions work on horizontal (array-of-structs) data, ie a
vec4d_t or vec4f_t represents a single vector, or traditional vector
layout. Vertical layout (struct-of-arrays) does not need any special
functions as the regular math can be used to operate on four vectors at
a time.

Functions are provided for loading a vec4 from a vec3 (4th element set
to 0) and storing a vec4 into a vec3 (discarding the 4th element).

With this, QF will require AVX2 support (needed for vec4d_t). Without
support for doubles, SSE is possible, but may not be worthwhile for
horizontal data.

Fused-multiply-add is NOT used because it alters the results between
unoptimized and optimized code, resulting in -mfma really meaning
-mfast-math-anyway. I really do not want to have to debug issues that
occur only in optimized code.
2020-12-30 18:20:11 +09:00
Bill Currie 4f8a06ddd3 [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-28 18:58:51 +09:00
Bill Currie d824db68a5 [util] Zero plist symtabl object memory 2020-12-25 00:28:26 +09:00
Bill Currie fefb32bf13 [util] Add a PL dictionary to hash table parser 2020-12-24 16:06:34 +09:00
Bill Currie cb2bdb0224 [util] Rename PL_ParseDictionary to PL_ParseStruct
Struct is far more appropriate for its function, and I need to parse a
dictionary into a hash table.
2020-12-24 13:33:37 +09:00
Bill Currie 5b0da2b14c [util] Add an int to uint cast for cexpr 2020-12-24 09:57:24 +09:00
Bill Currie 5864b553ef [util] Add accessors for binary plist objects 2020-12-23 14:07:30 +09:00
Bill Currie 91c5baa708 [util] Add size_t support to cexpr 2020-12-23 14:06:20 +09:00
Bill Currie 79f22ffebf [util] Propagate cexpr errors back to the caller
Not much point in error detection when it's ignored.
2020-12-21 20:15:43 +09:00
Bill Currie 4649294a27 [util] Fix inferred binary operator type checking
The problem is that I needed to support dynamic types on operators (for
bit-field enums), had things working, but a bad edit messed things up
and I had to rebuild that bit of code. Missed one bit :P
2020-12-21 14:47:15 +09:00
Bill Currie f3682638d4 [util] Add a mini expression parser
It is capable of parsing single expressions with fairly simple
operations. It current supports ints, enums, cvars and (external) data
structs. It is also thread-safe (in theory, needs proper testing) and
the memory it uses can be mass-freed.
2020-12-21 14:22:42 +09:00
Bill Currie 591667c36d [util] Add a context parameter to the plist parsers
Not used by the dict/array parsers themselves, but is passed on to any
value parser callbacks for their own use.
2020-12-21 14:22:42 +09:00
Bill Currie ebcef5c8a4 [util] Deal with gcc optimizing out isnan checks
This occurs because of -ffast-math, but I need to investigate how much
of an impact disabling it has on QF's performance.
2020-12-21 14:14:38 +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 af814ff9a8 [util] Add a cache-line aligned memory allocator
This was inspired by
Hoard: A Scalable Memory Allocator
  for Multithreaded Applications

 Emery D. Berger, Kathryn S. McKinley, Robert D. Blumofe, Paul R.
 Wilson,

It's not anywhere near the same implementation, but it did take a few
basic concepts. The idea is twofold:
1) A pool of memory from which blocks can be allocated and then freed
en-mass and is fairly efficient for small (4-16 byte) blocks
2) Tread safety for use with the Vulkan renderer (and any other
multi-threaded tasks).

However, based on the Hoard paper, small allocations are cache-line
aligned. On top of that, larger allocations are page aligned.

I suspect it would help qfvis somewhat if I ever get around to tweaking
qfvis to use cmem.
2020-12-21 14:14:29 +09:00
Bill Currie 62f3e1f428 [util] Calculate quaternion to rotate between two vectors
The calculation fails (produces NaN) if the vectors are anti-parallel,
but works for all other combinations. I came up with this implementation
when I discovered Unity's Quaternion.FromToRotation could did not work
with very small angles. This implementation will produce a usable
quaternion below 0.00255 degrees (though it will be slightly larger than
unit). Unity's failed such that I could see KSP's skybox snap while it
rotated around my test vessel.
2020-12-21 14:14:10 +09:00
Bill Currie e991c44232 [util] Make a minor improvement to QuatMultVec
Switch from using addition to multiplication for doubling the value.

Also, fix lib/util/test Makemodule to actually work (too much c&p
coding).
2020-12-21 14:13:57 +09:00
Bill Currie fdcdbefc05 [sizebuf] Add function to dump contents of a buffer
The usual 8-bit hex + chars (with chars wrapped into 7-bits) with
addresses block.
2020-08-17 13:07:44 +09:00
Bill Currie 9f4f63796b [util] Fix some unitialized vars
Not sure how they got past gcc. Maybe a bug in 9.3.0?
2020-07-17 00:23:09 +09:00
Bill Currie 2b23e01d9a [util] Make PL_Type and PL_Line const-correct 2020-07-17 00:22:47 +09:00
Bill Currie 16c6818612 [util] Set parsed array size correctly
The array has to be allocated using byte elements and thus the size of
the array is the number of bytes, but it needs to be the actual number
of elements in the array. Problem caused by not knowing the actual type
(and C not having type variables anyway).
2020-07-16 22:14:19 +09:00
Bill Currie 26cd93f788 [util] Expose PL_Message
It's far to useful elsewhere.
2020-07-16 22:14:19 +09:00
Bill Currie ef33adac56 [util] Make PL_String const correct 2020-07-16 22:14:19 +09:00
Bill Currie 72f583f16f [util] Fix some plist object parsing errors
Forgot to break after finding the field when parsing a dictionary
object, and use the correct parser for array objects.
2020-07-16 22:14:19 +09:00
Bill Currie c6a8829a52 [util] Add code to parse a plist array to an array 2020-07-14 12:05:34 +09:00
Bill Currie 8bd5f4f201 [util] Add code to parse a dictionary to a struct
PL_ParseDictionary itself does only one level, but it takes care of the
key-field mappings and property list item type checking leaving the
actual parsing to a helper specified by the field. That helper is free
to call PL_ParseDictionary recursively.
2020-07-05 16:53:35 +09:00
Bill Currie f6ea9e4d87 [util] Store source line in plist items
The first line of the parsed item is stored and can be retrieved using
PL_Line. Line numbers not stored for dictionary keys yet. Will be 0 for
any items generated by code rather than parsed from a file or string.
2020-07-01 21:47:09 +09:00
Bill Currie 86b5b30b45 Merge branch 'master' into vulkan 2020-06-25 14:03:52 +09:00
Bill Currie 6d5ffa9f8e [build] Move to non-recursive make
There's still some cleanup to do, but everything seems to be working
nicely: `make -j` works, `make distcheck` passes. There is probably
plenty of bitrot in the package directories (RPM, debian), though.

The vc project files have been removed since those versions are way out
of date and quakeforge is pretty much dependent on gcc now anyway.

Most of the old Makefile.am files  are now Makemodule.am.  This should
allow for new Makefile.am files that allow local building (to be added
on an as-needed bases).  The current remaining Makefile.am files are for
standalone sub-projects.a

The installable bins are currently built in the top-level build
directory. This may change if the clutter gets to be too much.

While this does make a noticeable difference in build times, the main
reason for the switch was to take care of the growing dependency issues:
now it's possible to build tools for code generation (eg, using qfcc and
ruamoko programs for code-gen).
2020-06-25 11:35:37 +09:00
Bill Currie 7ae047654b [util] Rework SEB affine/convex testing
When I ported SEB to python, I discovered that I apparently didn't
really understand the paper's description of the end condition and the
usage of the affine and convex sets for center testing. This cleans up
the test and makes SEB more correct for the cases that have less than 4
supporting points (especially when there are less than 4 points total).
2020-06-21 17:07:54 +09:00
Bill Currie e2d1a0f7d2 [ruamoko] Tag object memory with the class name
This makes it a lot easier to see what's leaking.
2020-03-31 16:43:10 +09:00
Bill Currie 4cef9792f4 [util] Make hash-tables semi-thread-safe
They take a pointer to a free-list used for hashlinks so the hashlink
pools can be per-thread. However, hash tables that are not updated are
always thread-safe, so this affects only updates. progs_t has been set
up such that it is easy for multiple progs within one thread can share
hashlinks.
2020-03-25 15:43:16 +09:00
Bill Currie eb386826d3 [util] Fix some missed signal calls
*sigh*
2020-03-23 15:28:12 +09:00
Bill Currie 4a61ff0d35 [util] Switch to using sigaction for signal handling
This allows for much more consistent semantics when dealing with
signals.
2020-03-23 15:15:39 +09:00
Bill Currie 4dbf280012 [util] Add a means to open a gap in a text buffer
for loading files into the buffer.
2020-03-22 20:19:25 +09:00
Bill Currie 88b4046632 [util] Pass a data pointer to shutdown functions
And clean up the mess.
2020-03-22 00:57:54 +09:00
Bill Currie 1a7add3f6d Merge branch 'master' into vulkan 2020-03-20 13:04:41 +09:00
Bill Currie d2f03e8a64 [util] Fix darray test for gcc purity 2020-03-20 12:59:25 +09:00
Bill Currie 966bd267c5 Add a set of macros for dynamic arrays
Includes docs and test cases.
2020-03-20 12:59:25 +09:00
Bill Currie 79719babda [util] Fix darray test for gcc purity 2020-03-20 12:56:09 +09:00
Bill Currie 0cbe438ac1 [util] Make va slight robust against chained use
va now cycles through a set of four dstrings rather than using just the
one. This allows for some simple chaining of va usage.
2020-03-17 15:05:58 +09:00
Bill Currie 75f4cebf0e Clean up after removal of uint32.h
I guess I forgot to check for its usage in header files, and the fact that
it didn't get cleaned out from being installed hid the error.
2020-02-29 16:11:07 +09:00
Bill Currie ddd007e2d5 [dstring] Return the string instead of printed size
Other than consistency with printf(), I'm not sure why we went with the
printed size as the return value; returning the resultant strings makes
much more sense as dsprintf() (etc) can then be used as a safe va()
2020-02-26 19:00:19 +09:00
Bill Currie 42713cad8b Make script much friendlier to use
It now simply sets an error message pointer and returns false if there's
an error.
2020-02-26 09:39:03 +09:00
Bill Currie 3720956d88 Speed up two of the three deletion cases
The initial code was pretty much a port of the code in the editor I
wrote 25 years ago. Either I didn't think of the optimization back then,
or I tried to implement it, failed, and figured it wasn't worth it
(despite using it on a 386dx33). However, I noticed it now and it was
easy enough to get working, and it's always good to not do something
that's not needed.
2020-02-24 18:52:46 +09:00
Bill Currie f7493fe8fb Add a buffer-gap text buffer
This should be good for text editing and working with text files in
general.
2020-02-24 17:30:33 +09:00
Bill Currie c3c55f0bcc Fix some source formatting 2020-02-23 19:05:43 +09:00
Bill Currie f8b1a3a89f Return the previous sys print callbacks
This allows for temporary overrides.
2020-02-23 11:41:19 +09:00
Bill Currie 0cb04dc490 Add a set of macros for dynamic arrays
Includes docs and test cases.
2020-02-17 16:17:21 +09:00
Bill Currie e37aba364a Correct an apparent typo
Black makes much more sense than Slack, especially if the text is from a
quake mod (no idea where, though).
2020-02-17 12:58:23 +09:00
Bill Currie e164002050 Make QuatToMat faster and more accurate
The better accuracy is for specific cases (90 degree rotations around a
main axis: the matrix element for that axis is now 1 instead of
0.99999994). The speedup comes from doing fewer additions (multiply
seems to be faster than add for fp, at least in this situation).
2019-07-23 08:52:15 +09:00
Bill Currie 452eb5a83d Preserve parsed cvar values when string is same
Fixes parsed developer flags on the command line getting reset.
2019-07-09 20:16:08 +09:00
Bill Currie 8c238d3def Parse developer flag names when cvar is set
So much easier to remember "vulkan" instead of which power of two it
is.
2019-07-09 20:14:57 +09:00
Bill Currie c727f6a130 Rewrite QuatMultVec to be faster
Could be faster still using SSE, but that's another project.
2019-07-06 14:45:40 +09:00
Bill Currie f58c2fef5a Switch QF's quaterions from wxyz to xyzw.
After messing with SIMD stuff for a little, I think I now understand why
the industry went with xyzw instead of the mathematical wxyz. Anyway, this
will make for less pain in the future (assuming I got everything).
2018-10-12 14:33:55 +09:00
Bill Currie 6f28ab2a68 Add basic quaternion multiplication tests. 2018-10-09 12:44:46 +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 db3df6f8a7 Fix a bunch of dead increments. 2018-09-09 11:12:04 +09:00
Bill Currie 59e85b7d5e Fix a pile of dead assignments.
Some were actual bugs!
2018-09-08 22:23:57 +09:00
Bill Currie f75ff2d269 Fix some null argument issues. 2018-09-07 22:30:44 +09:00
Bill Currie 8fd5be0ee0 Fix a pile of sizeof goofs.
While scan-build wasn't what I was looking for, it has proven useful
anyway: many of the sizeof errors were just noise, but a few were actual
bugs (allocating too much or too little memory).
2018-09-07 20:00:57 +09:00
Bill Currie 575a67b2a1 mat4 test case fixes.
The tests cases themselves were buggy.
2018-08-26 15:06:08 +09:00
Bill Currie 4f58429137 Fix an unhealthy pile of gcc 8 warnings.
While some of the warnings were merely annoying, some where actual bugs or
unearthed bugs in related code.
2018-08-20 00:05:00 +09:00
Bill Currie 0de0eb2fc7 Fix a bunch of bit-rot. 2018-06-08 13:21:30 +09:00
Bill Currie 546e333a3c Allow Sys_Error to be hooked.
This makes debugging builtins that wrap normal functions a little easier by
giving a progs dump when such an error occurs.
2016-01-03 23:04:00 +09:00
Bill Currie 735fcf68d5 Clean up usage of va_copy.
AC_TYPE_VA_LIST is no longer necessary, and the code is easier to read.
2016-01-03 21:16:23 +09:00
Bill Currie 2cbb7cb0c8 Remove a redundant va_start/va_end pair.
Found while checking how many places use va_copy.
2016-01-03 18:38:41 +09:00
Bill Currie 946561ba44 Don't bail out prematurely when searching for files.
This fixes the problem of not finding files without a .gz extension when
gzip support is enabled (most of my quake data is compressed, so it took a
while for me to notice the problem).
2014-01-29 16:13:24 +09:00
Bill Currie 8bea6a66ca Create _QFS_VOpenFile and QFS_VOpenFile.
_QFS_VOpenFile is actually _QFS_FOpenFile reimplemented to take vpath start
and end parameters so the search can be limited. QFS_VOpenFile,
_QFS_FOpenFile, and QFS_FOpenFile are all wrappers for _QFS_VOpenFile.
2014-01-28 16:22:05 +09:00
Bill Currie 3efb0c538f Separate file search from loading.
QFS_LoadFile (and its wrappers) now  take a file handle rather than a
path. This will make vpath usage a little cleaner to implement.
2014-01-28 16:22:05 +09:00
Bill Currie 83c47aacef Remove the stack loading from QFS_LoadFile. 2014-01-28 16:22:05 +09:00
Bill Currie a561477274 Nuke QFS_LoadStackFile().
It was used in only one place and is really not necessary (these days,
anyway).
2014-01-28 16:22:05 +09:00
Bill Currie 25a060f369 Remove the foundname param from _QFS_FOpenFile.
It's now obsolete with qfs_foundfile.
2014-01-28 16:22:05 +09:00
Bill Currie 576c73cf7c Replace qfs_file_from_pak with qfs_foundfile.
This exposes the found name, vpath and in_pak status.
2014-01-28 16:22:05 +09:00
Bill Currie e5148493db Prepend qfs_ to file_from_pak.
A little better name-spacing.
2014-01-28 16:22:05 +09:00
Bill Currie 82ded3fbe5 Fix some bitrot resulting from a rebase. 2014-01-28 16:22:05 +09:00
Bill Currie 5560696a65 Fix some unused variables. 2014-01-28 16:22:05 +09:00
Bill Currie 4b18501b00 Fix an uninitialized variable. 2014-01-28 16:22:05 +09:00
Bill Currie 40206904ba Reimplement _QFS_FOpenFile using QFS_FindFile's internals.
_QFS_FOpenFile does a full search, however.
2014-01-28 16:22:05 +09:00
Bill Currie 6b87ddbb7c Add QFS_FindFile.
QFS_FindFile's search can be constrained to begin or end at a certain
vpath.
2014-01-28 16:22:04 +09:00
Bill Currie 8bc2f7f6df Print the vpath name when dumping the paths. 2014-01-28 16:22:04 +09:00
Bill Currie 098821e35d Fix QFS_FilelistFill to work with vpaths. 2014-01-28 16:22:04 +09:00
Bill Currie f05c7179c3 Split up the search paths into vpath chunks.
A vpath is the union of all locations searched for a file in a single
gamedir (eg, shadows, id1 etc). This is a necessary step to preventing
problems like id1/maps/start.lit being used for shadows/maps/start.bsp.

However, QFS_FilelistFill still needs to be reworked as it does not compile
yet (testing was done with a gutted QFS_FilelistFill).
2014-01-28 16:22:04 +09:00
Bill Currie 6910c50a43 Clean up the #ifdef mess in _QFS_FOpenFile
With proper initialization, only the one chunk of #ifdefs is needed. Now
the code is much easier to read.
2014-01-28 16:22:04 +09:00
Bill Currie 550f1ae788 Fix some bitrot.
Just updating for the changes to the ALLOC/FREE macros.
2014-01-28 16:22:03 +09:00
Bill Currie 3b56f0e3bf Advance src with next_line.
This fixes the double counting of the \n at the end of the chunk separator
line.
2014-01-28 16:22:03 +09:00
Bill Currie d1848a93c8 Add tests for chunk line numbers.
Which happen to find errors :P
2014-01-28 16:22:03 +09:00
Bill Currie d912970cd3 Add support for segmented text files.
The idea comes from The OpenGL Shader Wrangler
(http://prideout.net/blog/?p=11). Text files are broken up into chunks via
lines beginning with -- (^-- in regex). The chunks are optionally named
with tags of the form: [0-9A-Za-z._]+. Unnamed chunks cannot be found.
Searching for chunks looks for the longest tag that matches the beginning
of the search tag (eg, a chunk named "Vertex" will be found with a search
tag of "Vertex.foo"). Note that '.' forms the units for the searc
("Vertex.foo" will not find "Vertex.f").

Unlike glsw, this implementation does not have the concept of effects keys
as that will be separate. Also, this implementation takes strings rather
than file names (thus is more generally useful).
2014-01-28 16:22:03 +09:00
Bill Currie f5501fbf24 Fix a pile of automake deprecation warnings.
s/INCLUDES/AM_CPPFLAGS/g

I <3 sed :)
2013-11-24 13:11:50 +09:00
Bill Currie 247f3be0c0 Create reentrant versions of the set functions that need it.
Only the functions that allocate or delete sets or iterators.
2013-03-18 13:20:39 +09:00
Bill Currie 27bb337a60 Use set_bits_t for holding set elements.
set_bits_t is now 64 bits for x86_64 machines (in linux, anyway). This gave
qfvis a huge speed boost: from ~815s to ~720s.

Also, expose some of the set internals so custom set operators can be
created.
2013-03-16 21:26:49 +09:00
Bill Currie 7753583bfd Catch accuracy errors.
I'd forgotten to set the result flag. Unfortunately, the errors can get
very bad (1e-3) it seems :(
2013-03-13 17:16:34 +09:00
Bill Currie 6eec76dd49 Implement Fischer's SEB algorithm (for 3d).
Now we can get tight (<1e-6 * radius_squared error) bounding spheres. More
importantly (for qfvis, anyway) very quickly: 1.7Mspheres/second for a 5
point cloud on my 2.33GHz Core 2 :)
2013-03-13 17:10:55 +09:00
Bill Currie 9bbf1a9110 test the right cs function (oops) 2013-03-13 16:38:56 +09:00
Bill Currie 3193ffd9cc Better (-1..1) random numbers.
Now the distribution should be more even as the rng doesn't affect the
exponent.
2013-03-13 14:41:04 +09:00
Bill Currie b6d4766201 Add a function to find the circumsphere of up to 4 points.
It seems to be a little sloppy (an error of a bit less than 1e-4). This
might be why I'm having trouble with my SEB code.
2013-03-13 14:35:30 +09:00
Bill Currie 0cd6d93030 Add a function to get the barycentric coords of a point.
It "works" for lines, triangles and tetrahedrons. For lines and triangles,
it gives the barycentric coordinates of the perpendicular projection of the
point onto to features. Only tetrahedrons are guaranteed to reproduce the
original point.
2013-03-12 14:16:42 +09:00
Bill Currie ca0b03687f Change the naming of ALLOC's free-list.
Rather than prefixing free_ to the supplied name, suffix _freelist to the
supplied name. The biggest advantage of this is it allows the free-list to
be a structure member. It also cleans up the name-space a little.
2013-03-08 22:16:31 +09:00
Bill Currie eb2828e11c Add a function to pre-allocate space for a large set.
When the maximum set size is large but constant, and members will be added
one at a time, growing the set dynamically is not very efficient.
2013-03-07 10:27:30 +09:00
Bill Currie 8e86ce9de9 Implement Sys_LongTime and wrap it with Sys_DoubleTime.
Sys_LongTime returns time in microseconds as a 64-bit int. Sys_DoubleTime
uses Sys_LongTime, converts to double and offsets 0 time by 4G (2**32).
This gives us consistent sub-microsecond precision for a very long time.

See http://randomascii.wordpress.com/2012/02/13/dont-store-that-in-a-float/
2013-02-27 14:29:28 +09:00
Bill Currie 32b76b3576 Do not try to create directories that already exist.
It seem that solaris will return EACCESS instead of EEXIST if the user
doesn't have write permission in the parent directory.
2013-02-20 14:03:03 +09:00
Bill Currie a611ad57de Add Sys_isdir. 2013-02-20 13:59:31 +09:00
Bill Currie 4e7e7c3ab0 Rename Sys_FileTime to Sys_FileExists.
The function never did anything but check the readability of the file.
2013-02-07 15:43:26 +09:00
Bill Currie c6f9d8b64c Reduce CFLAGS abuse a little for mingw targets.
This fixes missing debug info (useful for fixing linker errors, if nothing
else).
2013-01-28 16:21:42 +09:00
Bill Currie d139640755 Make fs_userpath default to ~/quakeforge on windows.
The ~ gets expanded to CSIDL_LOCAL_APPDATA, $HOME, $USERPROFILE or just
".", whichever succeeds first. The usual location will be:
"C:\windows\profiles\<user>\Local Settings\Application Data".

"." is now the fallback for *nix systems too.
2013-01-23 11:10:19 +09:00
Bill Currie e27d7cbd2d Handle alloca "correctly".
Use AC_FUNC_ALLOCA and the #ifdef mess suggested by the autoconf docs
(hidden in qfalloca.h).
2013-01-22 21:02:50 +09:00
Bill Currie 5188644e75 Implement the Mersenne Twister PRNG.
This gives QF a consistent qualilty PRNG on all platforms. The
implementation is slightly different from the standard, but gives the same
results for the same speed (details in mersenne.c).
2013-01-21 20:05:16 +09:00
Ozkan Sezer cdbb2ad030 Fix incorrect parsing of comments.
Parsing /*..*/ style comments would stop at the first *.
2013-01-16 10:31:02 +09:00
Bill Currie d6bb5bec86 Use the already calculated string length.
No point doing it twice.
2013-01-08 18:10:27 +09:00
Bill Currie a4714ac9b5 Correctly parse octal escapes for plist strings.
It seems the code expected octal escapes to always start with 0. This is
not the case. Also, octal escapes are limited to 3 digits (and hex to 2).

This fixes the garbled bold text in ITS.
2013-01-08 16:54:23 +09:00
Bill Currie febb615580 Create a test for octal chars in plist strings.
Both reading and writing.
2013-01-08 16:32:57 +09:00
Bill Currie 49d07ce452 Implement MH's version of Sys_DoubleTime for windows.
From http://forums.inside3d.com/viewtopic.php?p=36239
2013-01-05 17:52:54 +09:00
Bill Currie 9d6954efb7 Fixup extended bsp when loading the file.
It turns out the tools need the node conversions too, so doing it in
bspfile seems to be best as it is used by everything that reads a bsp file.
2012-12-30 13:29:24 +09:00
Bill Currie 7a86ea2d41 Do not use the bsp2 header when byteswapping the header.
The bsp2 header is not necessarily correct (or even present), but the bsp29
header is: it was setup via set_bsp32_write. This fixes the bsp corruption
when vising a map (and, I expect, any problems with qfbsp on a big-endian
machine).
2012-12-29 20:57:55 +09:00
Bill Currie 6eb6b6c0ba Change pointer_t to unsigned and clean up the mess.
It doesn't make sense to have negative pointers. The size of the commit is
from enabling gcc's -Wtype-limits warning and cleaning up that mess too.
2012-12-21 21:53:13 +09:00
Bill Currie 84a68b139e Rename set_iter_t's value to element.
Correct terminology and all :)
2012-12-21 14:09:00 +09:00
Bill Currie 3e38c4aa48 Merge branch 'qfcc-cse'
qfcc now does local common subexpression elimination. It seems to work, but
is optional (default off): use -O to enable. Also, uninitialized variable
detection is finally back :)

The progs engine now has very basic valgrind-like functionality for
checking pointer accesses. Enable with pr_boundscheck 2
2012-12-13 20:17:28 +09:00
Bill Currie 6473951daa Make the set notation more correct.
The empty set is now {}, the set of everything is now {...} and the rest
now have {} around the members.
2012-12-09 22:17:55 +09:00
Bill Currie 061e2be5d4 Re-write the set testing code.
Getting everything right with an enum proved to be too difficult if not
impossible. Also use better tests for equivalence and intersection.

Many more tests have been added. All pass :)
2012-12-09 13:52:48 +09:00
Bill Currie 94e804d786 Make some more set_test fixes.
Two inverted sets can never be disjoint.
2012-12-07 22:25:36 +09:00
Bill Currie 56956fc370 Rewrite the intersection tests.
The early bailout proved to be difficult to get right, so don't bother.
2012-12-07 22:16:51 +09:00
Bill Currie 98c9e4f8c0 White space. 2012-12-07 22:16:22 +09:00
Bill Currie f3328a61c7 More tests and update a comment. 2012-12-07 22:16:07 +09:00
Bill Currie b053edee17 Fix the handling of size in set_expand.
It was correct for set_add, but not for other ops :/ (out by 1)
2012-12-07 20:44:09 +09:00
Bill Currie 770a40cef0 Add a bunch more tests.
Even found some bugs :)
2012-12-07 20:43:11 +09:00
Bill Currie 39920a4ea7 Fix the type when converting set of everything to string. 2012-12-07 19:35:37 +09:00
Bill Currie c76231ca30 Add some very basic tests for sets.
They test creation, empty, everything and inversion. Already found a bug
(typo: "everythign" :P)
2012-12-07 19:34:34 +09:00
Bill Currie e0c92b6089 Rename set_iter_t's member to value.
Makes more sense now that the membership of the value depends on the
inversion of the set.
2012-12-06 21:11:38 +09:00
Bill Currie eb8fd55677 Move set.c into libQFutil.
Also move the ALLOC/FREE macros from qfcc.h to QF/alloc.h (needed to for
set.c).

Both modules are more generally useful than just for qfcc (eg, set
builtins for ruamoko).
2012-12-06 20:52:53 +09:00
Bill Currie 67b796f851 Fix a silly error in bsp extents checking.
Found while hunting for rhinodemons.
2012-11-23 14:38:15 +09:00
Bill Currie fe9fb41f93 Correct some very suspicious looking code.
While accessing short foo[2][4]; as foo[0][0..7] should work in theory, who
knows what gcc does with it when optimizing. I don't know if this will fix
johnnyonflame's bsp loading problem, but no point in having rhinodemonic
code hanging around.
2012-11-23 14:35:34 +09:00
Bill Currie 4b503c7f72 Store the requested size in the block.
This necessitated disabling the id2 padding, but it's only commented out
incase there's more growth. Now the (compiler) error in -addObjectNoRetain
is caught ealier.
2012-11-19 21:50:42 +09:00