cloudwalk [Sun, 24 May 2020 14:18:15 +0000 (14:18 +0000)]
Fix FS_Seek for compressed file from PK3
From Slava: "Currently FS_Seek works incorrectly with compressed files from PK3 but this issue isn't noticed because in most cases engine is using FS_LoadFile which reads file sequentially without seeking."
havoc [Sun, 24 May 2020 07:06:25 +0000 (07:06 +0000)]
Rework r_shadow_shadowmode to be more maintainable and understandable - it now caches the values of r_shadow_shadowmapping and r_shadow_deferred, and is now updated when those change, rather than just at startup, and changing those now also causes a recompile of world lights (which always had different bounds when shadowing was on/off, toggling shadows had weird behavior as a result, so this is a bugfix).
This fixes a massive fps drain with settings that disabled shadows entirely by disabling shadowmapping (where r_shadow_shadowmapping 0 and r_shadow_deferred 0 together caused it to reallocate the shadowmap texture every frame and do other bad stuff)
cloudwalk [Sat, 23 May 2020 22:22:30 +0000 (22:22 +0000)]
Fix Windows-specific use-after-free causing crash after disconnecting
This explicitly deregisters CSQC commands every time CSQC shuts down. This patch
also avoids Z_Malloc'ing the cmd names for each CSQC command and avoids forcing
a Cmd_AddCommand if the command exists.
CSQC was force-adding a command even if it already existed, and when it did,
it would pass a pointer from a mempool that would later get freed when
CSQC shuts down, and Windows' strcasecmp doesn't like dangling pointers.
The Z_Malloc wasn't much better because it could have caused a memory leak.
So the best solution was to only pass the pointer but make sure the commands
are freed when CSQC shuts down.
cloudwalk [Wed, 20 May 2020 15:22:06 +0000 (15:22 +0000)]
Make connections atomic. Disconnect before trying to connect.
Fixes an issue where a demo freezes in place if you try to connect while one is
running. This also has the side effect of eliminating a duplicate call to
CL_StopPlayback, which is called by both CL_EstablishConnection and
CL_Disconnect (which is itself called by NetConn_ConnectionEstablished).
cloudwalk [Tue, 19 May 2020 18:52:55 +0000 (18:52 +0000)]
Reset r_shadow_occlusion_buf on vid_restart. Fixes query buffer dangling pointer
Basically, when coronas appear when r_coronas_occlusionquery is 1, the engine
binds to a query buffer and stores a pointer to it in r_shadow_occlusion_buf.
Upon vid_restart, somewhere along the way, the buffer is cleared but the
original pointer is kept, resulting in a crash next time a corona appears.
cloudwalk [Mon, 18 May 2020 15:48:37 +0000 (15:48 +0000)]
Implement chromatic aberration, configurable with r_colorfringe cvar.
Do note that it is disabled by default and values higher than 0.025 will distort the image.
cloudwalk [Mon, 18 May 2020 14:26:20 +0000 (14:26 +0000)]
Fix invalid offset spam when r_showbboxes_client is > 0
This checks for server progs before touching viewmodelforclient as it's apparently not a client field.
cloudwalk [Mon, 18 May 2020 03:10:15 +0000 (03:10 +0000)]
Fix a few bugs detected by Cppcheck
(warning) Logical conjunction always evaluates to false: matchrule < 0 && matchrule > 5.
(style) Condition 'k<16' is always true
(style) Variable 'settings->bounceminimumintensity2' is reassigned a value before the old one has been used.
cloudwalk [Sun, 17 May 2020 20:53:49 +0000 (20:53 +0000)]
Use SDL_GameController instead of SDL_Joystick where possible
SDL_GameController provides mappings between axis and button indices and a
general layout that is similar to a XBox 360 controller. Since this layout is
common, these changes allow creating proper controller mappings for a large
variety of gamepad/OS combinations out of the box.
Change initially provided by EACFreddy. Fixed multiple crashes due to a stale
pointer. Also made a Con_Printf a DPrintf and removed ifdefs for SDL2 since
master doesn't support SDL1 anymore.
There's a strange stick drift problem. It might be my controller but
it'll have to be investigated further.
cloudwalk [Sat, 16 May 2020 19:37:37 +0000 (19:37 +0000)]
Clear the skybox textures on map load. Use memset to clear skyname.
This fixes an issue where the skybox textures of the first map you load
stick around in subsequent maps. There was a missing call to
R_SkinFrame_PurgeSkinFrame. Also use memset to clear skyname for good
measure. This may not have actually been part of the bug but it's harmless
and it wasn't clearing the entire array previously.
divverent [Mon, 23 Mar 2020 20:37:56 +0000 (20:37 +0000)]
Fix the corona bug. The render bug only though.
This is done by reviving alphamod and colormod arguments of
RSurf_ActiveCustomEntity.
The current implementation is a bit rough and needlessly copies the
worldentity; the struct isn't huge though and it's only done when
actually colormodding (and thus only for coronas, r_editlights, a few
sprites and nomodels).
divverent [Sun, 15 Mar 2020 01:45:25 +0000 (01:45 +0000)]
Add a Quake Live-style mouse acceleration mode.
Its cvars are m_accel_power*, and the cvar meanings are as close as possible
to the ezQuake implementation (as its source is available). Names differ though
due to conflicts with the current linear acceleration mode.
Original code by Frank <franparpe@franparpe.org>, cleanups by Rudolf Polzer <divVerent@xonotic.org>.
divverent [Sat, 22 Feb 2020 03:47:48 +0000 (03:47 +0000)]
Another flag bites the dust. This time: -ffinite-math-only.
Since GCC 5, with this flag set, NaN compares equal to zero in some cases but
not others. Causes e.g. "attempted division by zero" error spam from this QC
code:
float x = nan("");
if (x == 0) {
return 0;
}
return 1.0 / x;
Yes, those NaNs should not be happening in the first place, but suddenly
passing some but not all equality checks to zero seems rather dangerous.
Reference: issue #2412 (not a fix for it; the QC code has a problem too but
this change helps track it down properly).
havoc [Thu, 6 Feb 2020 14:43:18 +0000 (14:43 +0000)]
Implemented garbage collection of lost references to strzone strings in the PRVM, this is controlled by several prvm_garbagecollection_* cvars, and can notify when this occurs.
havoc [Thu, 23 Jan 2020 20:47:27 +0000 (20:47 +0000)]
Move tracking of aliases and csqc function overrides to a separate cmd_userdefined_t structure, this way it can be shared between cmd_client and cmd_clientfromserver.
This restores functionality so that stuffcmd in svqc can create aliases that are usable in the client, and can invoke csqc commands, but still have restrictions on engine commands.
havoc [Thu, 23 Jan 2020 08:19:11 +0000 (08:19 +0000)]
Redesigned TaskQueue to have a queue and distributor model so that threads can keep their own queues of work to do without locking to check for more work. Tasks are not executed until TaskQueue_WaitForTaskDone calls TaskQueue_DistributeTasks.
Added a fast path to TaskQueue_DistributeTasks for tasks that are waiting on other tasks to finish first, they are simply dequeued and re-enqueued immediately, and tend to just live on the distributor queue.
TaskQueue thread count is now dynamically adjusted based on tasks being queued per frame, and has a minimum and maximum thread count.
TaskQueue threads now sleep when idle, this may not be ideal, but did substantially lower the cpu usage so that it doesn't make other applications relatively unresponsive like it did before.
Removed taskqueue_task_t->started field and some other unused fields.
havoc [Wed, 22 Jan 2020 10:33:30 +0000 (10:33 +0000)]
Changed loading screen to continue during a connection attempt if the console or menu is not forced.
Changed scr_conforcewhiledisconnected 1 to not force the console during a connection attempt, kept the old behavior as scr_conforcewhiledisconnected 2.
If console is already open, the loading screen while connecting is not forced.
havoc [Wed, 22 Jan 2020 09:39:43 +0000 (09:39 +0000)]
Change default value of scr_loadingscreen_background to 0. It's not clear to me if anyone wants this to be 1, some of the bigger games using the engine set it to 0 already.
havoc [Wed, 22 Jan 2020 09:25:29 +0000 (09:25 +0000)]
Fix drawflag handling in Mod_Mesh_GetTexture by duplicating texture_t when drawflag overrides differ (it still uses the same skinframe_t so it's not duplicating the actual texture).
This fixes a menu issue in Steel Storm: Burning Retribution where the black text over a hover button was being rendered as MATERIALFLAG_ADD due to DRAWFLAG_ADD being used earlier in the frame on the same font image, which made the text invisible.
havoc [Wed, 22 Jan 2020 07:21:11 +0000 (07:21 +0000)]
Disable combining of surfaces in R_PolygonBegin, it makes assumptions that break things, and the underlying surface draw will still combine these for us (albeit more slowly).
Thanks to Cloudwalk for the tip, and divVerent and others for debugging in depth.
havoc [Wed, 22 Jan 2020 04:15:01 +0000 (04:15 +0000)]
cvars are now instanced in &cvars_all as a tracking mechanism, there is also &cvars_null if one wishes for no expansion to occur (e.g. client commands received on the server are very untrusted).
cvars now have CVAR_CLIENT and CVAR_SERVER flags, dedicated server can only see CVAR_SERVER variables whereas client can see both because it could start a server.
cvars created via VMs will have the corresponding flag set (client vm and menu vm can see both CVAR_CLIENT and CVAR_SERVER, server vm can only see CVAR_SERVER - may cause issues with singleplayer mods, we'll see).
havoc [Tue, 21 Jan 2020 08:36:34 +0000 (08:36 +0000)]
Split the global cmd interpreter into 4 separate ones for specific uses (client console, server console, client commands received from server, server commands received from clients), this is intended to make clients more robust against malicious servers by restricting which commands make sense.
This also hides some network protocol implementation details from the console command interpreter, and makes the command list a lot shorter in dedicated servers.
Changed Cbuf_LockThreadMutex/Cbuf_UnlockThreadMutex to Cbuf_Lock/Cbuf_Unlock and they now use a spinlock internally.
havoc [Fri, 17 Jan 2020 06:24:40 +0000 (06:24 +0000)]
R_CanSeeBox no longer uses collision_cache for the random traces, only the fixed positions (corners, etc), random rays were simply wasting resources in the collision_cache.
havoc [Fri, 17 Jan 2020 06:22:09 +0000 (06:22 +0000)]
Overhauled r_shadow_bouncegrid, it performs much faster, makes use of as many threads as you wish, and has a nicer calculation for light path accumulation.
r_shadow_bouncegrid now does refractive index calculations on water surfaces, it's not very obvious yet because the traceline doesn't return texture information (if it did, there would be cool caustics effects in dynamic mode).
Implemented TaskQueue system for simple threaded tasks (fibers but less featureful), this is used by r_shadow_bouncegrid but will be used by other parts of the engine in future, also added Thread_Atomic* functions.
havoc [Wed, 15 Jan 2020 12:53:04 +0000 (12:53 +0000)]
Overhauled bouncegrid light splatting for performance reasons - instead of a series of radial dots being accumulated in the texture, it is spherical distance from line segment calculations performed at each pixel, optimized to process pixels in order (filtering down the list of splat paths in each loop). This is a big framerate increase (as raytracing was not the bottleneck at all), and could be threaded in theory.
This required rebalancing the way that spacing interacts with quality, and the conespread parameter has been eliminated (as measuring distance to a non-uniform capsule seems especially challenging, but maybe that could be added back someday), so all parameters have changed a bit.
havoc [Wed, 15 Jan 2020 09:01:10 +0000 (09:01 +0000)]
Fix UI rendering to not use the bouncegrid texture; it looked interesting on the console text but was definitely a bug - now tracks a ui parameter on several surface drawing functions, and triggers the notrippy path in the material rendering as one wouldn't want r_trippy affecting UI either.
Fix a bug that caused bouncegrid to render black if any light was culled by traces (return that was supposed to be a continue).
Changed default values for these cvars to make bouncegrid emphasize the bounced light more, but also reduce the intensity:
r_shadow_bouncegrid_dynamic_directionalshading : 0 -> 1
r_shadow_bouncegrid_dynamic_lightradiusscale : 2 -> 5
r_shadow_bouncegrid_dynamic_maxbounce : 2 -> 5
r_shadow_bouncegrid_static_lightradiusscale 2 -> 5
r_shadow_bouncegrid_intensity 4 -> 1
havoc [Tue, 7 Jan 2020 10:25:49 +0000 (10:25 +0000)]
Fix PRVM_ValueString and PRVM_UglyValueString to check for out of bounds
dereference on a value provided by VM code, and also a NULL pointer
check for another field type.
After migrating to SDL2 interfaces there is noise during startup fix
this by initializng buffer as specification requires.
Per SDL_AudioCallback spec:
The callback must completely initialize the buffer; as of SDL 2.0, this buffer is not initialized before the callback is called. If there is nothing to play, the callback should fill the buffer with silence.
havoc [Sun, 26 May 2019 03:04:36 +0000 (03:04 +0000)]
Implement SDL2 AUDIO_F32 format and use it as the default, since it has become the preferred format of more platforms these days, and SDL2 uses it internally.
Improved the fallback mechanism on SDL2 audio setup - by removing it; SDL2 will tell us what changes it makes for the format, and it will convert the rest automatically.
divverent [Mon, 4 Feb 2019 15:09:01 +0000 (15:09 +0000)]
Remove code for r_equalize_entities*.
r_fullbright_directed and slapping EF_FULLBRIGHT on these entities works a lot
better. I believe other than Xonotic nobody uses this, and Xonotic used it only
to make some fullbright stuff prettier and that's been removed for a few months
now.
After this change, older Xonotic versions will complain about nonexisting flag
at startup, but I bet no player will even notice the difference - all it changes
is that EF_FULLBRIGHT entities will appear less directionally, and
r_fullbright_directed 1 will fix this in a better way (already set in current
Xonotic).
divverent [Fri, 19 Oct 2018 07:38:00 +0000 (07:38 +0000)]
Do not build VBOs on a dedicated server.
Fixes crash at startup of dedicated server in Quake and Xonotic
(probably in everything).
The only reason why this ever worked before was that Mod_BuildVBOs's
main callee R_Mesh_CreateMeshBuffer did a GL2 feature test before
calling into anything VBO related (and on a dedicated server, which does
not initialize GL, the test always returns false); however now that we
require GL32, the feature test is gone and thus the crash happened. An
explicit check for being a dedicated server fixes that.
divverent [Fri, 19 Oct 2018 07:02:35 +0000 (07:02 +0000)]
Make CDAudio_Play_byName static.
It isn't called by any other compilation units, but only internally by
other cd_shared.c functions; more importantly, it does not check for
music_playlist being active like CDAudio_Play does, which would at the
very least be confusing if someone were to add a string version of
qw_svc_cdtrack (WHY WOULD ONE).
divverent [Fri, 19 Oct 2018 06:40:49 +0000 (06:40 +0000)]
Remove the CONFIG_CD macro, and enable faketracks unconditionally.
All support for playing back CD-DA has been removed by leaving only the
SDL2 clients, and it is rather unlikely for CD-DA support to come back.
However while doing so, the CONFIG_CD macro was disabled in the makefile
but not the MSVC project, which broke faketracks (i.e. background music
via track003.ogg files) on Linux.
This change removes all #ifdefs for CONFIG_CD as well as its enablement
in the MSVC project, which is basically equivalent to having the feature
always being enabled.
Fixes background music in Quake with ripped music, Nexuiz, Xonotic, and
probably many other DP-based games. Also fixes Xonotic log spam about
gettime(GETTIME_CDTRACK).