bones_was_here [Mon, 5 Feb 2024 22:59:24 +0000 (08:59 +1000)]
fs: save files in the correct place when gamedir(s) are in use
As per the description of the `gamedir` command, it's expected that a
gamedir can be added without needing to re-add the primary
(gamedirname1) or secondary/mod (gamedirname2) as the last gamedir just
to ensure that files still get saved there as usual.
bones_was_here [Mon, 5 Feb 2024 20:38:45 +0000 (06:38 +1000)]
sv_cheats: fix two segfaults when setting it to 0
Assuming the SVQC program is always running crashes when it's not.
Testing if the edict pointer is NULL isn't a valid way to stop at the
end of the client slots, which caused this to crash when Xonotic SVQC
was running.
bones_was_here [Sun, 4 Feb 2024 16:18:03 +0000 (02:18 +1000)]
cvar: fix many bugs in gamedir, loadconfig, unset, cvar_resettodefaults* commands
Fixes a segfault when Cvar_RestoreInitState() deleted cvars (null ptr deref).
Fixes an infinite loop in Host_LoadConfig_f() due to calling Cbuf_Execute()
from inside Cbuf_Execute() via Host_AddConfigText().
Fixes `unset` being able to delete autocvars while they're in use by QC.
Fixes Cvar_RestoreInitState() not updating autocvars when necessary.
Fixes Cvar_RestoreInitState() not calling cvar callbacks.
Fixes Cvar_RestoreInitState() sometimes restoring such that .string
doesn't match .value, or such that .defstring is wrong. This was caused
by Cvar_SaveInitState() saving only string pointers and not strings.
Fixes CF_READONLY cvars like gl_info_* getting restored/reset. It
doesn't make sense for any of these to be changed by code outside their
own subsystems.
Fixes Xonotic menu QC errors caused by Host_LoadConfig_f deleting cvars
before calling QC's m_shutdown().
Saves a little memory by storing only minimal init state data for
Cvar_RestoreInitState(), and by relaxing alignment requirements in
_Mem_strdup().
Improves some warns and docs and tidies up a little.
Removes `vid_restart` from `gamedir`, it usually isn't needed because
current DP applies many vid_ cvar changes without it, and because of
the ubiquity of flat panel displays.
bones_was_here [Tue, 30 Jan 2024 11:38:52 +0000 (21:38 +1000)]
Work around Microsoft's broken vsnprintf implementation
Microsoft's documentation says it has supported %zu (C99 standard format
for size_t) for some years but trying to use it causes crashes at least
on older versions of Windows.
Makes dpsnprintf and dpvsnprintf documentation more accessible (these
funcs have different return behaviour than the C standard ones).
bones_was_here [Fri, 26 Jan 2024 06:58:50 +0000 (16:58 +1000)]
MD3: fix misaligned memory access
The memory subdivision was ordered such that this format likely had no
issues on a 32-bit machine but on 64-bit the alignment requirement of
texture_t increases to 8 bytes, invoking undefined behaviour.
bones_was_here [Thu, 25 Jan 2024 06:25:48 +0000 (16:25 +1000)]
Update and micro-optimise memory allocation
The max alignment requirement no longer needs to be hard-coded.
We were allocating slightly more than necessary for alignment padding.
Makes a (currently unused) macro more useful and robust.
Fixes bitfield data type.
bones_was_here [Mon, 18 Dec 2023 09:24:15 +0000 (19:24 +1000)]
Fix uses of strlcpy on unterminated source strings
BSD strlcpy() keeps reading until a \0 or a segfault, even after it
stops writing. In these cases the source was part of a longer string so
it wouldn't have crashed.
These were caught by the new warning.
The +1 on the source sizes copied an extra char that would be changed to
\0 and is now redundant because the real dest and src sizes are always
passed to a purpose-written func.
bones_was_here [Wed, 13 Dec 2023 07:16:24 +0000 (17:16 +1000)]
com: replace BSD strlcpy and strlcat
Compared to BSD strlcpy and strlcat, dp_strlcpy and dp_strlcat are
faster, never crash, and have a more useful return (DP didn't use the
strlcpy return at all), see included docs.
Adds dp_stpecpy() for efficient chain copying and dp_ustr2stp() for
copying measured byte sequences (unterminated strings) to strings.
Replaces the only use of the strlcat() return with dp_stpecpy().
bones_was_here [Fri, 15 Dec 2023 10:16:15 +0000 (20:16 +1000)]
com: rename BSD strlcpy and strlcat
The C standard reserves str* and mem* for the implementation.
Checking for BSD or OS X is not a robust way to determine if libc
provides these (eg glibc may implement them).
bones_was_here [Wed, 3 Jan 2024 16:58:15 +0000 (02:58 +1000)]
sys: make stdout/stderr configurable during runtime
Adds cvar sys_stdout which offers the same behaviours as the -nostdout
and -stderr cmdline options and is initialised by them if they're passed.
Makes -noterminal cmdline option a synonym for -nostdout, previously it
was effectively the same but less efficient.
Platforms with the fcntl() syscall (ie non-Windows):
Changes to non-blocking stdout/stderr by default to prevent stutters and
halts in certain scenarios.
Adds cvar sys_stdout_blocks for enabling blocking stdout/stderr if
required.
Retrieves stdio stream FDs instead of assuming they're always 0,1,2.
NaitLee [Sun, 29 Jan 2023 08:51:37 +0000 (16:51 +0800)]
Fix several long-lasting font rendering problems:
Fix resources waste of fontmap usage worst-cases;
Fix memory waste of improperly designed `struct ft2_font_map_s`;
Deprecate `r_font_diskcache`
Rudolf Polzer [Tue, 2 Jan 2024 20:48:07 +0000 (12:48 -0800)]
r_viewfbo 0: skip the postprocessing/blending pass if there is nothing to blend.
May save some fps on low-end systems.
NOTE: Had to make sure that 2D rendering does not enable depth test,
as in r_skipblend mode, the main framebuffer Z values are written to as
part of regular 3D rendering. There appear to be no behavioral changes
from this, but we need to be careful here.
r_viewfbo 1 disables this logic (it differs in no other way from r_viewfbo 0)
Rudolf Polzer [Tue, 2 Jan 2024 19:19:28 +0000 (11:19 -0800)]
R_BlendView: fix motion blur by using the correct FBO for it.
Motion blur has to be applied to the view FBO, not the (optional) screen FBO.
Especially as the code generating runs before even writing to the screen FBO.
bones_was_here [Tue, 26 Dec 2023 07:45:26 +0000 (17:45 +1000)]
Makefile: support explicit static linking of all configurable libraries
Fixes a bug in df973c344562c8cadc2413d36dcaa03f8e9040c2 where
libd0_rijndael static linking only worked if
DP_LINK_CRYPTO_RIJNDAEL=static was read from the environment rather than
being passed as an override.
bones_was_here [Thu, 21 Dec 2023 11:06:36 +0000 (21:06 +1000)]
cvar: use unsigned for flags and hashindex
Signed is too error-prone with bitwise operations. The common pattern
of passing ~0 (all bits set) resulted in neededflags=-1 in a backtrace
on x86_64.
bones_was_here [Tue, 12 Dec 2023 10:13:26 +0000 (20:13 +1000)]
net_slist: reduce worst-case time until any given server first appears
Fixes sending multiple queries to servers that happen to be early in the
list before sending any to servers late in the list, when
net_slist_maxtries > 1, which was a side-effect of making
net_slist_maxtries work as described in fe2b222e32752c408fbe5ccf4ac3fb546f8ff41a.
Slightly reduces the total real time and CPU time to query all servers.
bones_was_here [Sat, 9 Dec 2023 07:49:56 +0000 (17:49 +1000)]
cbuf: recycle node after it executes, clear commands on Host_Error()
This reverts 626658074c8dd5c2288becd836103e2efdb9b741 which looks like a
potentially racy or non-threadsafe approach, and instead prevents
problems by clearing the command buffers if Host_Error() is called and
doesn't shut down DP.
bones_was_here [Fri, 1 Dec 2023 06:18:45 +0000 (16:18 +1000)]
client: improve server connection status messages
Always logs various errors and rejections that previously were only
visible with developer cvar(s) set. Among other things this fixes
silent failure when trying to join a full server.
Includes IP address in more messages.
Uses CON_ERROR and CON_WARN colours for various errors and warns.
Moves status message generation to the code that sets the relevant
states. This allows more information to be included, makes the code
easier to follow and reduces polling.
Fixes some cases where a message was always clobbered before it could be
displayed.
Merges the built-in menu and loading screen connection status generation
and buffering.
bones_was_here [Sun, 26 Nov 2023 01:17:53 +0000 (11:17 +1000)]
Sys_Sleep overhaul
One function to rule them all, and in the darkplaces sleep threads.
Makes sub-millisecond accuracy available on Windows.
Increases the number of sockets we can monitor on Windows.
Improves Curl_Select() a little.
Updates flags of some timing-related cvars.