Commit Graph

143 Commits

Author SHA1 Message Date
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 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 81f73e4524 [gamecode] Support printing a single edict field 2021-07-25 09:54:08 +09:00
Bill Currie e81d690b51 [input] Create QF input library using keys.c
This refactors (as such) keys.c so that it no longer depends on console
or gib, and pulls keys out of video targets. The eventual plan is to
move all high-level general input handling into libQFinput, and probably
low-level (eg, /dev/input handling for joysticks etc on Linux).

Fixes #8
2021-07-05 16:26:07 +09:00
Bill Currie 8db1957452 [ruamoko] Add bindings for exp() 2021-06-19 11:23:51 +09:00
Bill Currie dc5ebd5c3d [ruamoko] Actually hook up the stdlib builtins 2021-06-01 23:44:51 +09:00
Bill Currie 5ca792c40e [ruamoko] Add some stdlib function wrappers
For now, just bsearch (normal and fuzzy), qsort, and prefixsum (not in
C's stdlib that I know of, but I think having native implementations of
float and int prefix sums will be useful.
2021-06-01 18:53:53 +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 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 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 dfa7af03c6 [util] Plug a thread-safety hole in plists 2021-02-09 09:57:07 +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 eebf3158fa [ruamoko] Check for null when allocating objects
It's difficult for progs to check for errors when the engine crashes out
from underneath them :P
2021-01-13 15:24:50 +09:00
Bill Currie 0c1699fdbb Fix a pile of double semicolons 2021-01-09 20:42:23 +09:00
Bill Currie 37b6d11c01 [ruamoko] Add binding for str_upper
I can't believe I didn't do that when I did str_lower.
2021-01-05 18:24:18 +09:00
Bill Currie e1e2a0e712 [ruamoko] Add a wrapper for PL_Line
Makes error reporting in rua code easier.
2020-12-23 21:52:42 +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 62c20aa4ab [ruamoko] Fix incorrect clearing of dtables
The problem was caused by passing the index into the dtables array to
dtable_get which expects a handle. A handle is the ones-compliment
negative of the index which means that handle 0 is invalid (but 0 was
being passed... oops). Fixes the segfault when qw-client-x11 connects to
a server.
2020-08-17 13:58:35 +09:00
Bill Currie 6d4e370a25 [ruamoko] Handle 0-length @va_list for va_copy
Fixes a progs crash when using vsprintf with no format elements +
params.
2020-06-28 18:48:38 +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 54f2e417dc [ruamoko] Fix daft str_str abi
Returning a string was a bad idea as it makes str_str difficult to use
with str_mid. (actually, iirc, it was the only reason I moved all
strings into progs memory... hmm).
2020-04-08 21:54:41 +09:00
Bill Currie b7b8df0801 [ruamoko] Add str_lower builtin
This returns a string with all chars lower-cased.
2020-04-08 21:53:53 +09:00
Bill Currie 17871b979d [ruamoko] Implement obj_calloc correctly
Forgetting to multiply by the second term leads to not good things.
2020-04-02 19:29:54 +09:00
Bill Currie 6b9d4a747d [ruamoko] Add a builtin to quote strings
All unprintable chars are converted to either standard escape sequences
or \xHH.
2020-04-01 21:28:25 +09:00
Bill Currie 535a2363bb [ruamoko] Create a va_copy for progs
In testing variable fw/precision in PR_Sprintf, I got a nasty reminder
of the limitations of the current progs ABI: passing @args to another QC
function does not work because the args list gets trampled but the
called function's locals. Thus, the need for a va_copy. It's not quite
the same as C's as it returns the destination args instead of copying
like memcpy, but it does copy the list from the source args to a
temporary buffer that is freed when the calling function returns.
2020-04-01 19:48:05 +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 59481bdf61 [ruamoko] Report class name in obj_verror 2020-03-31 14:40:22 +09:00
Bill Currie c23c68cf7f [ruamoko] Allow builtins to inc/dec retain count
Needed for classes that are implemented entirely in C.
2020-03-30 16:58:36 +09:00
Bill Currie 58ebbb147d [ruamoko] Add some new string builtins
Wrappers for hold, valid and mutable. I have no idea why I didn't think
of wrapping string validation years ago.
2020-03-26 16:39:21 +09:00
Bill Currie 6e473dc8f2 [ruamoko] Return nil IMP for nil method
Fixes a segfault.
2020-03-26 14:13:05 +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 0ad9f559ea [ruamoko] Move some string functions
sprintf, vsprintf and strlen now in rua_strings, and strlen now returns
int like it should.
2020-03-25 00:04:20 +09:00
Bill Currie 08b7064a3f [ruamoko] Set pr_argc before calling error methods
Builtins calling ruamoko code need to be careful of the arg count in
case the ruamoko function uses varargs.
2020-03-12 19:40:17 +09:00
Bill Currie 694ad2e840 [ruamoko] Add str_char builtin
This returns the character (as an int) at the index. Equivalent to
string[index], but qc code doesn't have char-level access and not having
it means that strings can internally change to wchar without too much
fuss (maybe).
2020-03-10 18:16:55 +09:00
Bill Currie 1b1249bdb0 [ruamoko] Add vsprintf builtin 2020-03-10 18:16:07 +09:00
Bill Currie 21b64421c3 [ruamoko] Copy ALL the params to the args block
*sigh*
2020-03-10 03:09:21 +09:00
Bill Currie 4b7d5447bb [ruamoko] Correct obj_msg_sendv for __obj_forward
Until I implemented forwarding, I didn't know how obj_msg_sendv was
meant to be used, so no surprise I got the implementation wrong.
2020-03-10 02:56:37 +09:00
Bill Currie 2a152e6356 [ruamoko] Add builtin __obj_responds_to
Fast dtable-based messages response test. However, it does not handle
forwarding.
2020-03-10 00:08:30 +09:00
Bill Currie af37b660e8 [ruamoko] Push the forwarded args block
This causes the block to be freed when the forward: handler returns
(assuming it's not yet another builtin). This is necessary so calling a
lot of forwarded messages in a loop doesn't leak memory (though it will
get freed eventually).
2020-03-09 23:38:27 +09:00
Bill Currie 9b0368039e [ruamoko] Include param size in size of args block
I forget it every time. It really doesn't help that params are 4 words
and words are 4 bytes, so seeing a size of 12 for 3 parameters *looks*
right.
2020-03-09 22:54:22 +09:00
Bill Currie fa0a74efdf [ruamoko] Finish implementation of __obj_forward
With this, object's implementing forward:: seem to accept the message
well, including receiving all the original args (not quite sure how to
deal with them in ruamoko code just yet, though).
2020-03-09 22:20:11 +09:00
Bill Currie e3fe93c586 [gamecode] Implement most of message forwarding
All that's left is the parameter setup of forward::.
2020-03-09 20:41:17 +09:00
Bill Currie a487595149 [ruamoko,libr] Begin implementation of __obj_forward
libr supplies an __obj_forward definition that links to a builtin, but
as it is the only def in its object file, it is readily replaceable by
an alternative Ruamoko implementation.

The builtin version currently simply errors out (rather facetiously),
but only as a stub to allow progs to load.
2020-03-09 19:09:08 +09:00
Bill Currie e2f4c189f9 [ruamoko] Install and use dispatch tables
This should speed up ruamoko code somewhat as hash table lookups have
been replaced with direct array indexing. As a bonus, support for
message forwarding has been added (though not tested).
2020-03-09 18:11:36 +09:00
Bill Currie 1ccdd76780 [ruamoko] Clean up runtime init and cleanup
Move the semi-permanent resource initialisation into the module init and
the cleanup of those resources into cleanup. Makes actual runtime init
much easier to read.
2020-03-09 18:09:03 +09:00
Bill Currie 0e40366c7f [ruamoko] Implement class conformsToProtocol
Seems to work nicely, too :)
2020-03-02 15:21:10 +09:00
Bill Currie a906efac47 [ruamoko] Register protocols and their selectors 2020-03-02 15:20:34 +09:00
Bill Currie 78f552aa87 [ruamoko] Initialize static instances
This is one step closer to implementing conformsToProtocol. However,
protocols are not yet initialized correctly: they are not registered,
nor are their selectors.

While the static initializer list pointer was not written previously,
the module struct always came immediately after the symbols struct, and
the module version has so far always been 0. Thus, the list pointer is
correctly 0 for older progs and there's no need for a version bump.
2020-03-02 13:45:47 +09:00