Commit Graph

4234 Commits

Author SHA1 Message Date
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 79177e96e8 [vulkan] Start work on scripted pipeline
Nothing is actually done yet other than parsing the built-in property
list to property list items (the actual parser is just a skeleton), but
everything compiles
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 0945f30731 [vulkan] Use a property list to drive code gen
The property list specifies the base structures for which parser code
will be generated (along with any structures and enums upon which those
structures depend). It also defines option specialized parsers for
better control.
2020-07-05 16:53:35 +09:00
Bill Currie e4ee5c70e0 [vulkan] Rework vkgen alias handling
This is much cleaner and now that all the types are there properly,
doing a parser generator should be easier.
2020-07-05 16:53:35 +09:00
Bill Currie 98795bf604 [gamecode] Add a comment about returning temp strings 2020-07-05 16:53:35 +09:00
Bill Currie 2ca9f80d56 [vulkan] Split up vkgen
It worked as a proof of concept, but as the code itself needs to be a
bit smarter, it would be a lot smarter to break up that code to make it
easier to work on the individual parts.
2020-07-05 16:53:35 +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 cf3262991d [vulkan] Add a tool for making vulkan enum tables
The tables are generated from the enums pulled out of the vulkan headers
using a ruamoko program (thanks to its reflection capabilities). They
will be used for parsing property lists used to create render passes and
pipelines.
2020-06-28 19:08:18 +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 19c75f5e49 [vulkan] Clean up QFV_CreateFramebuffer's prototype
It now takes qfv_imageviewset_t instead of separate count and
VkImageView array.
2020-06-28 13:53:11 +09:00
Bill Currie c1ffb05b87 Remove dead Makefile.am
Forgot this in the merge.
2020-06-25 16:14:39 +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 df89e37afc [console] Call PR_RunPostLoadFuncs
This fixes the segfault when loading the menu progs. I had forgotten
that the menu code doesn't use PR_LoadProgs (I don't remember why.
Obsolete reason?).
2020-06-24 22:47:12 +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 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 2bec2527b4 [gamecode] Re-expose PR_LoadStrings
It's required for qfprogs now that PR_LoadDebug reads strings early.
2020-04-04 14:33:49 +09:00
Bill Currie cf7c4780eb [gamecode] Load extended debug data
And add function to get a source file's base directory if available.
2020-04-04 12:50:25 +09:00
Bill Currie 59f48e5e32 [gamecode] Add function to test if string exists
As it returns the string id, it is useful for getting an string id
without risking creating a new one.
2020-04-04 12:32:12 +09:00
Bill Currie 7bcfd2f2be [gamecode] Move file_hash into debug resources
I don't remember why I didn't do this earlier when I thread-safed progs.
2020-04-03 22:39:27 +09:00
Bill Currie fbbe144399 [gamecode] Clean up some stray "struct"
Left over from moving debug data from progs.h to pr_debug.c
2020-04-03 22:35:55 +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 c09f57c39e [gamecode] Delay .ctor calls if debugging
This allows a debugger to do any symbol lookups and other preparations
between loading progs and the first code execution. .ctors are called as
per normal if debug_handler is not set.
2020-04-02 17:39:11 +09:00
Bill Currie f90613bc3a [gamecode] Rename fields in pr_stack_t
s and f are a little too succinct.
2020-04-02 15:00:01 +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 41184bd97d [gamecode] Document the format state machine 2020-04-01 20:50:42 +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 a36f72f7b4 [gamecode] Support variable field width and precision 2020-04-01 19:45:33 +09:00
Bill Currie 7f4d2215e2 [gamecode] Accept EOS at end of conversion specifier 2020-04-01 18:32:30 +09:00
Bill Currie 7f86fb5529 [gamecode] Rework PR_Sprintf to use a state machine
This makes it much easier to extend. There are even stubs for variable
field width and precision (not set yet).
2020-04-01 13:32:07 +09:00
Bill Currie a7956c7311 [gamecode] Move format state into a state struct
This is the first step in reworking PR_Sprintf to use a state machine.
The goal is to make it more robust against errors and easier to extend
(eg, * width and precision).
2020-04-01 11:19:56 +09:00
Bill Currie e9733416f4 [gamecode] Hide trace messages when debugger is attached 2020-04-01 00:09:34 +09:00
Bill Currie 58acc483fd [gamecode] Save new string ref in return slot
This plugs the memory leak that caused qwaq to crash after resizing the
locals window a "few" times (several seconds of playing with the size).
2020-03-31 20:38:41 +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 ddec80edc1 [qfcc] Make type encoding union anonymous
I'd do more, but things get messy with direct access to unions that I
want to be anonymous.
2020-03-30 11:10:05 +09:00
Bill Currie 8b1e4eea58 [qfcc] Bring back the core of type aliasing
No aliasing is done yet, but most of the infrastructure is there again.
2020-03-27 12:27:46 +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 1586df4dfc [gamecode] Make it possible to check string mutability 2020-03-26 16:38:09 +09:00
Bill Currie ec82d6b027 [gamecode] Add support for holding ephemeral strings
PR_HoldString converts ephemeral (temp and return) strings to dynamic
strings. This makes dealing with strings in progs a little easier.
2020-03-26 16:36:29 +09:00
Bill Currie b4874f7d9b [gamecode] Make PR_FreeString a little more forgiving
It treats only strings that are actually invalid as invalid. That is,
now it is safe to "free" a static string: it's just a no-op.
2020-03-26 15:48:04 +09:00
Bill Currie 22e2695f80 [gamecode] Add VISIBLE to some missed functions 2020-03-26 15:36:46 +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 2d5df34234 [gamecode] Add VM enter/exit events
And rename prd_exit to prd_terminate (the idea is the host will
terminate the VM). This makes it possible for the debugger to pause the
VM before any code, even a builtin function, is executed. Breaks the
debugger source window, but only because it's not updating on file
change (I think).
2020-03-26 12:30:32 +09:00
Bill Currie 1bd8e2ee85 [gamecode] Add a param pointer to debug_handler
I decided I want events for VM enter/exit but enter needs to somehow
pass the function which will be executed (even if a builtin). A generic
void * param seemed the best idea, which meant the error string could be
passed via the param instead of a "global" string in the progs struct.
2020-03-26 11:44:02 +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 c945c42989 [gamecode] Fix some silly errors
I forgot to compile-test :(
2020-03-24 23:16:25 +09:00
Bill Currie d867a1a9f1 [gamecode] Allow watch-point to be updated
With the watch-point address cached in a local var, it was not possible
to update the watch-point while the progs were executing.
2020-03-24 19:45:39 +09:00
Bill Currie 713150b41a [gamecode] Add debug hooks to the VM engine
While there was a breakpoint hook, it was for only breakpoints and more
was needed. Now there's a generic hook that is called for tracing,
breakpoints, watch points, runtime errors and VM errors, with the
"event" type passed as the first parameter and a data pointer in the
second.
2020-03-24 19:45:10 +09:00
Bill Currie 1d6843d7f0 [gamecode] Improve watchpoint handling a little
Mostly just update the old value if the condition didn't trigger.
2020-03-24 13:26:35 +09:00
Bill Currie 753d183d82 [gamecode] Be more informative with function calls
PR_EnterFunction and PR_LeaveFunction now print the
entered/left/returned function when tracing. Makes debugging obj code
much easier.
2020-03-24 13:24:55 +09:00
Bill Currie d0c8d75e92 Clean up unnecessary includes of signal.h 2020-03-23 16:18:08 +09:00
Bill Currie 9986b57a77 [console] Use sig_atomic_t for SIGWINCH
If it's not defined on other platforms, something can be done in
config.h
2020-03-23 16:16:50 +09:00
Bill Currie 178c8dec85 [console] Fix server console resize
I goofed when doing the win32 fixes
2020-03-23 16:01:07 +09:00
Bill Currie eb386826d3 [util] Fix some missed signal calls
*sigh*
2020-03-23 15:28:12 +09:00
Bill Currie a9c6974fc7 [audio] Quieten jack about xruns
They messages are annoying at the moment, but I will want them when I
get around to chasing down the root cause, so hidden behind a developer
mask.
2020-03-23 15:19:05 +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 28f50d2719 Add function key defs up to F48
This allows for the four combinations of shift and control. Not
bothering with alt because alt-f4 closes my xterm (bbkeys from the looks
of it: it grabs a bunch of Mod1-* keys).
2020-03-22 13:46:27 +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 b544a052bf [gamecode] Bail if PR_SearchDefs is given 0 defs
Fixes the hang when searching for a field in progs that don't have any.
2020-03-16 14:24:48 +09:00
Bill Currie e3a1413ad3 [gamecode] Tweak output for lea 2020-03-15 10:06:37 +09:00
Bill Currie 99f89840f9 [gamecode] Show containing def and relative offset
No more guessing when accessing structure field members. Next is ivars,
I guess.
2020-03-15 02:51:29 +09:00
Bill Currie 3d62a7f253 [gamecode] Use fuzzy bsearch to find defs by address
The idea is to find th def that contains the address. Had to write my
own bsearch (well... lifted from wikipedia) because libc's is exact. The
defs are assumed to be sorted (which qfcc now ensures when it writes
progs and sym files).
2020-03-15 02:48:13 +09:00
Bill Currie 2f9f6d3aa9 [gamecode] Relocate aux function return types
They are written with offsets relative to the type encodings base.
2020-03-14 23:39:14 +09:00
Bill Currie 9492f08536 [gamecode] Print structs as well as unions
Much better :)
2020-03-14 21:03:01 +09:00
Bill Currie fea6381574 [gamecode] Rework debug type handling a little
Type encodings are used whenever they are available. For now, if they
are not, then everything is treated as void (which prints <void>, not
very useful). Most return statements and references to .return are now
very readable (excluding structs), and only params going through "..."
are a messy union.
2020-03-14 20:44:43 +09:00
Bill Currie a069fad41e [gamecode] Print only entity address when no edicts
If the edicts pointer is null, it's not possible to convert the entity
address to an index.
2020-03-13 20:16:06 +09:00
Bill Currie a0d85e33c2 [gamecode] Rework implementation of memset*
The memset instructions now match the move* instructions other than the
first operand (always int). Probably breaks much, but fixed in next few
commits.
2020-03-13 17:50:57 +09:00
Bill Currie 087cee06be [gamecode] Use full precision for floating point values 2020-03-13 14:57:33 +09:00
Bill Currie 6dfe37635d [gamecode] Dump union contents
The output is messy, but better than <union>
2020-03-13 14:56:56 +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 6ca85d770d [gamecode] Add memset instructions 2020-03-11 22:48:55 +09:00
Bill Currie 023a920a51 [gamecode] Replace lost parameter auto-reset
rcallN messes with the progs parameter pointers and not resetting them
can cause incorrect data to be copied into the called function.
2020-03-11 19:38:50 +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 6c56e93fc8 [gamecode] Be more careful with temp strings
If a temp string is found in the return slot, PR_FreeTempStrings won't
delete the string. However, PR_PopFrame was blindly stomping on the
possibly surviving temp string with the push strings, which would cause
a leak.
2020-03-10 03:24:31 +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 f290b115a5 [gamecode] Add function PR_PushTempString
This "pushes" a temp string onto the callee's stack frame after removing
it from the caller's stack frame. This is so builtins can pass
auto-freed memory to called progs code. No checking is done, but mayhem
is likely to ensue if a string is pushed that was allocated in an
earlier frame.
2020-03-09 23:36:09 +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 7d43bd5c66 [gamecode] Add function PR_AllocTempBlock()
PR_AllocTempBlock() works the same way as PR_SetTempString(), except
that it takes a size parameter and always allocates (never tries to
merge). This is, in a way, abusing the string system, but I needed a way
to allocate a block of progs memory that would be automatically freed
when the current frame ended. The biggest abuse is the need to cast away
the const of PR_GetString()'s return value.
2020-03-09 22:16:19 +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 67ec9bfb47 [vid] Initialize x event before sending
Quietens valgrind nicely (though it gave a weird source of the memory).
2020-03-08 21:30:08 +09:00
Bill Currie 5f299cbac7 [gamecode] Ensure static string refs are initialized
That was a fun one to track down :P
2020-03-08 21:29:31 +09:00
Bill Currie c726d77e7d [gamecode] Respect the @float_promoted@ magic string
Rather than relying on progs code version, use the string to determine
whether PR_Sprintf should behave as if floats have been promoted through
... I imagine I'll get to the rest of the server code at some stage.

With these two changes, nq-x11 works again (teleporters were the
symptom).
2020-03-08 19:19:15 +09:00
Bill Currie 68fc11857a [gamecode] Fix a string splitting error 2020-03-04 21:10:23 +09:00
Bill Currie c214797e97 [gamecode] Fix some curly space
and add some comments. took a bit to figure out what i was doing
2020-03-04 21:09:36 +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
Bill Currie bc4bea79cb [ruamoko] Remove a stale FIXME
This was fixed when pr_def_t was introduced. I missed the comment at the
time.
2020-03-02 13:00:33 +09:00
Bill Currie 4e4b553cc3 [gamecode] Take care of missed type alias stuff 2020-03-01 16:20:23 +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 789f263855 Use get_strref() correctly
I had forgotten that it works only for dynamic strings.
2020-02-27 02:07:53 +09:00
Bill Currie c9186c8296 Clear the statement line buffer
The problem with moving to a cached buffer is it needs to be cleared.
Fixes the weird output of qfprogs and tracing (not missing local defs,
though).
2020-02-27 01:25:41 +09:00
Bill Currie 62b541793d [gamecode] Remove all use of va
With this, the VA is very close to being safe to use in a threaded
environment (so long as each VM is used by only one thread). Just the
debug file hash and source paths to sort out.
2020-02-26 19:30:10 +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 36bc139b27 Avoid use of va in PR_Sprintf
With this, progs strings are thread safe so long as only one thread
tries to use the VM.
2020-02-26 18:35:19 +09:00
Bill Currie 0f4d89a832 Move free_fmt_items into strings resources
This will make it per-thread.
2020-02-26 18:19:21 +09:00
Bill Currie 383a7fe5e1 Remove File_Open
Other than its blocking of access to certain files, it really wasn't
that useful compared to the functions in qfs, and pointless with access
to qfs anyway.
2020-02-26 13:45:14 +09:00
Bill Currie 225a375ab9 Extend the lifetime of return-strings
This is done by putting the most recently used return-string at the end
of the queue for recycling.
2020-02-26 13:43:03 +09:00
Bill Currie aa02069dd1 Add a breakpoint flag to opcodes
The progs execution code will call a breakpoint handler just before
executing an instruction with the flag set. This means there's no need
for the breakpoint handler to mess with execution state or even the
instruction in order to continue past the breakpoint.

The flag being set in a progs file is invalid.
2020-02-26 13:40:26 +09:00
Bill Currie d60291a73e Clean up a lot of va usage
va is not thread-safe (it's not save even without threads), and I want
to be able to run progs in threads.
2020-02-26 09:46:59 +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 4c1b6ce76c Make pr_parse thread safe
Or at least, conversion to property list is thread safe.
2020-02-26 01:55:56 +09:00
Bill Currie 35c9d6ee38 Make pr_obcode.c mostly thread safe
Its public data is all read-only, and once set up, its private data is
too (just don't call init in multiple threads).
2020-02-26 01:20:28 +09:00
Bill Currie 3577d27a45 Move the ObjQC data into a resource block
This makes it nice and private (though with the cached pointer, ObjQC is
still a first-class component).
2020-02-25 23:14:18 +09:00
Bill Currie 66dd3ef070 Make a bunch of count things positive-only
This fixes a pile of FIXMEs, because some things should never be
negative.
2020-02-25 21:23:13 +09:00
Bill Currie 282132958f Relocate local def type encodings in debug load
For technical reasons (programmer laziness), qfcc does not fix up local
def type encodings when writing the debug symbols file (type encoding
location not readily accessible).
2020-02-25 20:46:01 +09:00
Bill Currie 89e83d7d73 Move the debug info out of progs_t
The debug subsystem now uses the resources system to ensure it cleans
up, and its data is now semi-private. Unfortunately, PR_LoadDebug had to
remain public for qfprogs because using PR_RunLoadFuncs would cause
builtin resolution to complain.
2020-02-25 20:07:29 +09:00
Bill Currie a55b9544ac Improve handling of pr_argc
It is now set to 0 when progs are loaded and every time
PR_ExecuteProgram() returns. This takes care of the default case, but
when setting parameters, pr_argc needs to be set correctly in case a
vararg function is called.
2020-02-25 17:36:29 +09:00
Bill Currie e3953be8f8 Ensure execution state is initialized on progs load 2020-02-25 15:25:10 +09:00
Bill Currie 61d7f4f9c4 Dump locals stack when dumping main stack
Any shutdown functions in progs will need locals too.
2020-02-25 15:18:15 +09:00
Bill Currie 6a4ef598ab Allow progs num_edicts and reserved_edicts to be null
Really, while there are edict related instructions, edict support should
probably not be in the VM itself.
2020-02-25 15:00:33 +09:00
Bill Currie 6e56c9a4aa Ensure edict_parse is reset on progs load
A server switching from a game that sets edict_parse to one that does
not could go badly when it comes time to loading a level.
2020-02-25 14:40:03 +09:00
Bill Currie 9bb68f2d8c Allow nested use of PR_SaveParams()
PR_SaveParams() is required for implementing the +initialize diversion
used by Objective-QuakeC because builtins do not have local def spaces
(of course, a normal stack calling convention would help). However, it
is entirely possible for a call to +initialize to trigger another call
to +initialize, thus the need for stacking parameter stashes. As a
bonus, this implementation cleans up some fields in progs_t.
2020-02-25 14:30:26 +09:00
Bill Currie 99c818adcc Ensure progs zone is always set on load 2020-02-25 00:25:24 +09:00
Bill Currie 256dee98a1 Make progs string resources management private
Strangely enough, using the progs resources system. This is a step
towards having progs that can be reset properly, or even dynamically
created VMs.
2020-02-25 00:23:08 +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 7406e0308e Fix some warnings picked up in an optimized build 2020-02-24 11:28:43 +09:00
Bill Currie dda045bf96 Do lazy computation of def sizes from type encodings
The size is calculated when needed and cached.
2020-02-23 23:29:58 +09:00
Bill Currie 23573953a7 Change pr_type_size to pr_ushort_t 2020-02-23 22:25:08 +09:00
Bill Currie c3c55f0bcc Fix some source formatting 2020-02-23 19:05:43 +09:00
Bill Currie d0dc0e15fb Handle alias types in debug prints 2020-02-23 19:02:16 +09:00
Bill Currie b173c35eb4 Rework progs debug to use the type encodings
It's only a start: the output is, if anything, slightly worse than
before, but it does have the basics going.
2020-02-23 19:01:59 +09:00
Bill Currie 4b7ecdf74a Make PR_Init take an instance to initialize
This allows internal sub-systems to do per-instance initializations
without other engine systems having to know about them.
2020-02-23 18:32:16 +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 806af85447 Remove reference to ddef_t from progs.h
This cleans up some horrible names and redundant fields that were a
result of the transition to pr_def_t
2020-02-22 22:44:08 +09:00
Bill Currie 81083698a8 Move to using an in-memory form of ddef_t
This allows the VM to work with extended ddefs transparently. It seems
to have uncovered a typedef alias relocation bug, though.
2020-02-22 22:33:44 +09:00
Bill Currie c296514b95 Make pr.load_file 'return' the file size 2020-02-21 21:17:28 +09:00
Bill Currie 2db5d04e3f Reduce the ephemeral nature of str_mid
When the substring is the tail of the supplied string, return a
"pointer" to within the supplied string rather than a new "return"
string. This means that tail-end substrings of string constants are
themselves constants.
2020-02-19 21:41:46 +09:00
Bill Currie ad175d054b Sanitize pipelines
wow, talk about doing things the wrong way. I guess that's the problem
with following a book targeted for C++: you get all that safety-goat
nonsense.
2020-02-18 22:38:01 +09:00
Bill Currie 264c4ccdac Sanitize descriptors
I'm sure it will end soon, I think pipelines is the end of it.
2020-02-18 21:18:03 +09:00
Bill Currie c740dea212 Use the correct constant for "infinity" 2020-02-18 19:44:40 +09:00
Bill Currie 0a0035e5e5 Use the render pass to clear the window
Very satisfying to get to this point.
2020-02-18 17:48:22 +09:00
Bill Currie ba654b09f7 Create and destroy render pass and frame buffers 2020-02-18 17:18:37 +09:00
Bill Currie 1f4c019abc Create and destroy color/depth resources 2020-02-18 14:28:28 +09:00
Bill Currie 89d48b5650 Output first pixels
Just clearing the screen to 0xbada55, but the validation layer is quiet.
2020-02-18 01:03:36 +09:00
Bill Currie 73fde40cad Sanitize some more structs 2020-02-17 23:30:25 +09:00
Bill Currie 94565c2382 Rework much of the Vulkan array handling
So much for all those little wrappers hiding the device. Some survived,
but mostly just the bigger things like device, swapchain, etc.
2020-02-17 20:29:35 +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 916e57de37 Get the swapchain image switching sort of working
The render pass isn't set up yet, so the validation layer is having a
fit, but cycling through the swapchain images does seem to be working.
2020-02-17 00:50:39 +09:00
Bill Currie ce72135e70 Fix incorrect init of command buffer set 2020-02-17 00:10:59 +09:00
Bill Currie 4b152a4492 Rework semaphore sets 2020-02-17 00:10:32 +09:00
Bill Currie 559bd2e636 Create command pool and frame timing fences
Nothing is actually done yet, so the reported fps is around 172k (yes,
k), but startup and shutdown seems to be clean (yay validation layers).
2020-02-16 22:45:27 +09:00
Bill Currie b947cc1791 Rework command buffer and fence-set management
I found command buffer handling to be totally redundant and fence-set
management to be a bit awkward.
2020-02-16 22:43:57 +09:00
Bill Currie 9ff4eefe65 Merge branch 'master' into vulkan 2020-02-16 18:17:50 +09:00
Bill Currie ed283a9e7f Copy only the necessary number of vararg parameters 2020-02-16 18:00:29 +09:00
Bill Currie 12d2a0ff75 Copy the correct number of words for rcall 2020-02-16 17:58:36 +09:00
Bill Currie f5741a979e Implement parameter alignment in the engine
The engine now requires non-v6 progs to store the log2 alignment for the
param struct in .param_alignment.

PR_EnterFunction is clearer and possibly more efficient.
2020-02-16 17:13:45 +09:00
Bill Currie 32c21ec559 Make gcc accept the bitwise-boolean magic
Forgot to compile check...
2020-02-16 12:08:08 +09:00
Bill Currie b4fd804e4e Implement true modulo in the engine 2020-02-16 11:53:56 +09:00
Bill Currie 4269c8cb07 Rename the mod instruction to rem
Because % really implements remainder rather than true modulo, and I
plan on adding %% to implement true modulo.
2020-02-16 11:04:30 +09:00
Bill Currie bab3752e98 Add missed overridden math functions
And fix misspelled ones too.
2020-02-15 23:49:12 +09:00
Bill Currie 533fb8acc9 Implement double constants 2020-02-15 23:49:12 +09:00
Bill Currie 2cd62fe01b Fix several double-related bug
float is promoted to double through ... for non-v6 code.
PR_Sprintf has custom param access via P_*, messed up doubles.
2020-02-15 23:49:12 +09:00
Bill Currie df7c08a010 Add support for doubles to Ruamoko
Only as scalars, I still need to think about what to do for vectors and
quaternions due to param size issues. Also, doubles are not yet
guaranteed to be correctly aligned.
2020-02-15 23:49:12 +09:00
Bill Currie 13b608f40c Don't truncat float % float
This allows full usage, eg, x % pi, but otherwise maintains
compatibility with integer %
2020-02-15 23:49:12 +09:00
Bill Currie d56f88f779 Implement swapchain image acquisition 2020-02-15 17:56:02 +09:00
Bill Currie 53b46f0541 Implement pipeline stuff 2020-02-13 04:21:35 +09:00
Bill Currie 69c110193a Fix a thinko
Wrong var for computing number of slots used.
2020-02-13 04:20:54 +09:00
Bill Currie 61036378e2 Implement render pass stuff 2020-02-12 18:55:51 +09:00
Bill Currie 44f5b134e6 Free custom descriptor structs
Forgot this earlier
2020-02-12 18:55:22 +09:00
Bill Currie 85a2f9f621 Implement descriptor stuff 2020-02-12 16:36:01 +09:00
Bill Currie de64be1d67 Show more info when dumping x11 video modes
Found in an old stash. Probably the start of xrandr support.
2020-02-12 11:04:28 +09:00
Bill Currie 6e96b91aa1 Fix a couple more optimization warnings 2020-02-11 15:59:12 +09:00
Bill Currie 9248e8cf01 Update for doxygen 1.8.16 2020-02-11 15:22:42 +09:00
Bill Currie fbd79963bb Update for doxygen 1.8.16 2020-02-11 15:20:49 +09:00
Bill Currie 3144443a82 Allow vulkan_draw to compile when optimizing
Even though it's nowhere near done
2020-02-11 12:19:16 +09:00
Bill Currie 29b1d6baf8 Finish up memory stuff
For now, of course.
2020-02-11 09:37:04 +09:00
Bill Currie 1baee0cbba Implement mem mapping and buffer/image copying 2020-02-10 20:42:19 +09:00
Bill Currie 43e37aa31e Separate out the generic memory stuff 2020-02-10 18:33:29 +09:00
Bill Currie 9fdc15c439 Implement image stuff up to view creation 2020-02-10 18:18:37 +09:00
Bill Currie f4c0d0ebcf Implement buffer view creation
And rename memory allocation as it's buffer-specific.
2020-02-10 18:17:58 +09:00
Bill Currie 2f9ad73f78 Implement buffer memory up to barriers
Still lots to go (views, destruction, transfer...) and I'm uncertain
about the location of the pipeline barrier function.
2020-02-10 15:07:35 +09:00
Bill Currie 8148f256f5 Rework object device caching
It turned out I needed access to the physical device from a buffer
object, so rather than storing the vulkan logical device directly in
buffer (and other) objects, store the qfv logical device.
2020-02-07 11:45:05 +09:00
Bill Currie d3b4e4653e Cache physical devices in the instance 2020-02-06 19:04:28 +09:00
Bill Currie 6ce87497f3 Fix a potential buffer overflow
Highly unlikely to have that many sub models, but it does keep gcc
quiet.
2020-02-06 17:42:21 +09:00
Bill Currie 494f673def Fix a potential buffer overflow
Highly unlikely to have that many sub models, but it does keep gcc
quiet.
2020-02-06 17:38:51 +09:00
Bill Currie 8819d26c95 Fix a compile error
not sure how that one got through
2019-10-16 20:57:39 +09:00
Bill Currie 4957c4f31a Implement the rest of the command stuff 2019-07-23 13:05:32 +09:00
Bill Currie a165d67dfa Add a queue type 2019-07-23 12:37:47 +09:00
Bill Currie 411b897f09 Implement most of the stuff for command submission 2019-07-23 12:28:57 +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 1f24a1408a Destroy the surface 2019-07-13 01:20:02 +09:00
Bill Currie dd1c2db249 Clean up the swapchain
And be a little safer about it
2019-07-13 01:14:21 +09:00
Bill Currie b4dc746a66 Clean up the debug callback 2019-07-13 01:11:34 +09:00
Bill Currie 1eafc33052 Ensure vulkan gets shut down 2019-07-13 00:36:21 +09:00
Bill Currie 4e4d1b99b4 Clean up all the system shutdown calls
I added Sys_RegisterShutdown years ago and never really did anything
with it: now any system that needs to be shutdown can ensure it gets
shutdown on program exit, and in the correct order (ie, reverse to init
order).
2019-07-12 23:15:26 +09:00
Bill Currie b2e12d701b Fix up swapchain creation
Things are working again.
2019-07-12 14:09:42 +09:00
Bill Currie 66e7336b62 Initialize device extension checks early
They need to be initialized before attempting to load the function
pointers.
2019-07-12 13:37:30 +09:00
Bill Currie 75f19f7243 Completely rework the vulkan related api
Things don't work yet, but this feels much cleaner.
2019-07-12 13:34:31 +09:00
Bill Currie b5828bc2ce Output validation message severity
It's nice knowing if something is an error or otherwise.
2019-07-11 00:58:37 +09:00
Bill Currie c0bc5cfad6 Implement swapchain creation 2019-07-11 00:58:14 +09:00
Bill Currie 302a462c32 Make SetMouse timeout after 2 seconds
This makes sure that some unchecked event doesn't cause a lockup.
However, blocking input is really not the way to go: need to implement a
state machine and use non-blocking event reads.
2019-07-10 22:28:33 +09:00
Bill Currie 980cf58ac5 Wait for the window to be visible before mouse warping
This fixes the hang during fullscreen startup on my system (the motion
events weren't being generated because there was no window to see the
motion).
2019-07-10 22:28:33 +09:00
Bill Currie a4f963f67b Add a cvar to block use of x11 vidmode
Or really, allow it if the user specifically requests it: the default is
blocked. Modern systems (particularly displays) do not really like
changing resolution, so doing so by default seems rather wrong.
2019-07-10 22:28:33 +09:00
Bill Currie 4eb6cf6f9e Make SetMouse timeout after 2 seconds
This makes sure that some unchecked event doesn't cause a lockup.
However, blocking input is really not the way to go: need to implement a
state machine and use non-blocking event reads.
2019-07-10 22:24:11 +09:00
Bill Currie 203d981675 Wait for the window to be visible before mouse warping
This fixes the hang during fullscreen startup on my system (the motion
events weren't being generated because there was no window to see the
motion).
2019-07-10 22:18:51 +09:00
Bill Currie d5cb432911 Add a cvar to block use of x11 vidmode
Or really, allow it if the user specifically requests it: the default is
blocked. Modern systems (particularly displays) do not really like
changing resolution, so doing so by default seems rather wrong.
2019-07-10 22:15:39 +09:00
Bill Currie 2771e9c573 Correct extension handling
I had missed a critical bit from the cookbook.
2019-07-10 13:16:46 +09:00
Bill Currie ed3c5cb9ec Add a strset "class"
It's just a wrapper around hashtab, but it makes checking if a string is
in a set easy. Way overkill when only a few extensions are enabled, but
more might come later.
2019-07-10 13:09:16 +09:00
Bill Currie 3191604641 Uncomment already implemented functions 2019-07-09 21:07:59 +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 8a3cd224a3 Add vulkan developer flag 2019-07-09 20:14:30 +09:00
Bill Currie 68449d0f6f Create a window and a surface for vulkan
Yay, segfaults in R_Init :)
2019-07-09 16:33:44 +09:00
Bill Currie 0f511e8342 Move the string list funcs to their own file
They're not (at this stage, at least) worthy of being promoted out to
the utils lib.
2019-07-09 14:24:55 +09:00
Bill Currie b3d982bfc3 Remove global vulkan_ctx
While I can't say that I'm happy with the details of vulkan_ctx_t, I am
pretty sure I don't want to be limited to having only one.
2019-07-09 11:54:23 +09:00
Bill Currie 707bdfc5f2 Get vulkan back to where it was 2019-07-09 09:06:35 +09:00
Bill Currie 8ee06d75a9 Separate render and presentation initialization
This paves the way for clean initialization of the Vulkan renderer, and
very much cleans up the older renderer initialization code as gl and sw
are no longer intertwined.
2019-07-09 01:00:47 +09:00
Bill Currie cb10175824 Pass vid_internal to R_LoadModule
This fixes the segfault and pushes things very much in the desired
direction of proper system independence for rendering and presentation
separation (though things were headed in the right direction before).
2019-07-08 14:04:03 +09:00
Bill Currie 6ee2df8445 Move vid callbacks into vid_internal
Currently segfaults because viddef is an alias for *r_data->vid, which
has not yet been initialized (chicken and egg).
2019-07-08 13:40:29 +09:00
Bill Currie 3e1520c246 Move vid callback access into vid
The plan is to move the callbacks into a "private" struct.
2019-07-08 12:46:22 +09:00
Bill Currie 6137795682 Use deep binding for the vulkan loader
This fixes the problem with using vkGetInstanceProcAddr to find global
vulkan functions.
2019-07-07 16:48:53 +09:00
Bill Currie 7137d61c36 Add some extensions needed for presentation 2019-07-07 16:27:55 +09:00
Bill Currie a755e50c84 Clean up vid access a little
Things are still a mess, but a proper cleanup will be a lot of work and
will, really, involve properly splitting quake-specific code* out from
the rest of the renderer.

* data loading and format specific stuff
2019-07-07 15:38:29 +09:00
Bill Currie d95e9f9af3 Correct vulkan plugin strings 2019-07-07 14:59:20 +09:00
Bill Currie 77afc30486 Fix vid renderer plugin types
I guess that plugin type is currently not checked, otherwise I doubt the
mistake would have gone unnoticed.
2019-07-07 14:57:56 +09:00
Bill Currie 940ef833ae Shutdown Vulkan properly
Well, as properly as can be considering how little is started up :P
2019-07-07 14:34:02 +09:00
Bill Currie ab08e4f207 Create a logical device with a single queue
A single graphics-capable queue should be enough for now. However, I'm
not sure I'm happy with a lot of the code: it's a bit difficult to write
flexibly configured code for Vulkan (or seems to be at this stage),
especially in C.
2019-07-07 01:28:05 +09:00
Bill Currie 2bc78e7f0a Start work on a Vulkan-based renderer
Doesn't do much other than create an instance and enumerate some stuff,
but the build system is working.
2019-07-06 14:56:15 +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 f68129dc0f Try to use type encodings for function return type
Now return statements in traces make much more sense.
2019-06-09 18:11:56 +09:00
Bill Currie 0f5f2a125a Use a reliable reference for calculating progs offsets.
Now that pr->zone can be null, it cannot be used as a reference. Fixes
random crashes when using qfprogs (random due to heap randomization).
2018-10-13 23:23:45 +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 b7aa5bb8fe Fix an oops messing up edict size. 2018-10-12 14:33:26 +09:00