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.
bones_was_here [Sat, 11 Nov 2023 10:47:50 +0000 (20:47 +1000)]
cl_maxfps*: various adjustments
Ensures minimum FPS of 10 even while idle to prevent weird issues
(networking assumes at least 10).
If you want to save more resources, hide the game window (disables
rendering entirely) such as by using vid_minimize_on_focus_loss 1.
Disables cl_maxfps_alwayssleep by default, on modern systems with
accurate timers and higher FPS this has a significant impact.
Allows cl_maxfps_alwayssleep to be used with cl_maxfps 0, this was
requested some time ago.
Switches from cl_maxidlefps to cl_maxfps when querying servers to give
pings representative of what can be expected when playing on them.
Simplifies state tracking, ping is now either valid or not set (0) and
isn't abused to store state.
Includes a hash-verified timestamp in pings, fixes impossible pings
(happened when querytime was updated before response arrived) and the
ability to add servers to a client's list with unsolicited packets
(abusing the LAN support).
Checks that DP/QW master server list packets originate from a configured
master (cvar net_sourceaddresscheck).
Fixes unreliable LAN support.
Significantly reduces the total time to complete a full query cycle for
DP servers by improving the logic as well as turning up some cvars.
Prints warnings if DP or QW master server queries time out.
Makes net_slist_maxtries actually give better ping reports like its
description says.
Makes net_slist_pause completely pause (QC builtin resorthostcache()
used by Xonotic and Nexuiz bypassed it), clarifies description, uses a
callback instead of polling to handle changes.
Changes sv_masters[] and sv_qwmasters[] iteration to a more idiomatic
pattern pattern (numeric limit instead of a "null cvar" terminator).
Checks that sockets are open before writing to them in
NetConn_QueryQueueFrame() to avoid crashing in case we ever close a
lower numbered socket while a higher numbered one is still open.
Separates QW master list parsing into a func (like DP list parsing).
Fixes sending a DP master query string to the QW masters if the first
socket is an IPv6 one.
bones_was_here [Fri, 3 Nov 2023 09:15:06 +0000 (19:15 +1000)]
net_slist: update types, declarations
Mostly this changes array indices and externally-sourced data that
should never trigger signed overflow to unsigned,
and changes to lhnetaddresstype_t where applicable.
Fixes an old bug in the DP Quake server list where if there are less
servers than the most that could fit onscreen, the list jumps around
and/or duplicates entries when moving the cursor down.
bones_was_here [Fri, 3 Nov 2023 07:55:44 +0000 (17:55 +1000)]
net_slist: code style/formatting fixes
I wouldn't normally nitpick this stuff but the random tabs mixed into
code and comment lines were too annoying and fixing it later commits
would make their diff too noisy.
bones_was_here [Sun, 12 Nov 2023 12:33:10 +0000 (22:33 +1000)]
Fix bug where +binds could get latched at low FPS
This was introduced in 6b21c467a83808e3becf61afe7b67a88f870b502 which
didn't ensure the -bind would be executed after the +bind when the
keydown and keyup events are processed in the same frame.
bones_was_here [Thu, 5 Oct 2023 18:44:37 +0000 (04:44 +1000)]
input: stop capturing mouse movement if window is hidden without first losing focus
Fixes players looking all around after they alt+tabbed.
Moves the logic for selecting the mouse mode out of screen drawing and
into SDL event handling where it's unaffected if we early-out of drawing
the frame.
Prevents mouse "grab" (raw/relative mode + cursor hiding) in a few
"loading" situations.
bones_was_here [Wed, 4 Oct 2023 16:43:12 +0000 (02:43 +1000)]
vid: implement monitor selection with instant cvar changes
Adds cvars: vid_display, vid_info_displaycount
Prints the monitors detected at startup and on hotplug.
Requires SDL headers >= 2.0.18 at build time.
At runtime older versions should still work but may lack some functionality.
May not work properly or at all if vid_desktopfullscreen is 0.
May require vid_restart after hotplug events.
---
Changes existing cvars vid_fullscreen, vid_desktopfullscreen, vid_resizable,
vid_borderless to apply instantly.
Also (for windowed mode) works around window managers that move the
window after SDL creates and centres it (typically when adding a
titlebar), so the crosshair is always at the centre of the monitor.
Adds some missing SDL_WINDOWEVENT enumerations.
Changes the GL viewport size retrieval from screen coordinates to
pixels, which is a prerequisite for "HIGHDPI" aka "Apple Retina"
support.
bones_was_here [Tue, 3 Oct 2023 17:24:44 +0000 (03:24 +1000)]
vid_vsync: fully support adaptive, remove polling, print better errors
Adaptive vsync was partially supported: it worked if set before window
creation but not if toggled on afterwards, and wasn't mentioned in the
cvar description.
The immediate application of `vid_vsync` cvar changes was implented by
polling, which was ok for one cvar but I'll be making more vid_ cvars
apply immediately (no vid_restart needed), and don't want to poll for
things that rarely change every frame.
SDL is now queried for the current state of vsync instead of storing
what we believe to be the current state.
If the setting can't be applied the reason (as reported by SDL) is now
printed.