Commit Graph

5574 Commits

Author SHA1 Message Date
Bill Currie 9e83ded0ac [scene] Return existing component instead of null
While checking on how Ent_AddComponent behaved (I don't remember what I
was looking for, though), I realized that instead of treating adding the
same component to an entity as an error, Ent_AddComponent should just
return the existing component.
2022-10-25 09:54:49 +09:00
Bill Currie f37c31a2dc [vulkan] Set entity render id correctly
It was being set to -1 unconditionally due to forgetting to use id.
However, I decided I didn't like reusing the id var and did some
renaming while I was at it.
2022-10-23 23:38:21 +09:00
Bill Currie 8acd5c558b [scene] Make entity_t just an entity id for ECS
This puts the hierarchy (transform) reference, animation, visibility,
renderer, active, and old_origin data in separate components. There are
a few bugs (crashes on grenade explosions in gl/glsl/vulkan, immediately
in sw, reasons known, missing brush models in vulkan).

While quake doesn't really need an ECS, the direction I want to take QF
does, and it does seem to have improved memory bandwidth a little
(uncertain). However, there's a lot more work to go (especially fixing
the above bugs), but this seems to be a good start.
2022-10-23 22:24:36 +09:00
Bill Currie de786ce197 [scene] Use hierref_t instead of transform_t in hierarchy
Hierarchies are now much closer to being more general in that they are
not tied to 3d transforms. This is a major step to moving the whole
entity/transform system into an ECS.
2022-10-22 13:04:07 +09:00
Bill Currie ac8c6b631e [vulkan] Skip ambient lights for shadow maps
Not that anything is actually rendered yet, but the validation layers
don't like the null render pass. Came up now because ctf1 seems to make
the first light an ambient light.
2022-10-22 13:00:12 +09:00
Bill Currie b607fe0878 [scene] Add has/get component functions
And define nullent as 0 is a valid entity.
2022-10-21 19:12:20 +09:00
Bill Currie 6189142c60 [renderer] Remove rglyph_t struct
It didn't really add anything of value as the glyph bitmap rects and the
bearings were never used together, and the rest of the fields were
entirely redundant. A small step towards using a component system for
text.
2022-10-20 15:50:53 +09:00
Bill Currie 06ccc3023b [scene] Start work on a full-on ECS system
That does feel a little redundant, but I think the System in ECS is
referring to the systems that run on the components, while the other
system is the support code for the ECS. Anyway...

This is based heavily on the information provided by @skipjack in his
github blog about EnTT. Currently, entity recycling and sparse arrays
for component pools have been implemented, and adding components to an
entity has been tested.
2022-10-16 18:29:25 +09:00
Bill Currie 0c54b0652b Abandon support for clang
The inconsistencies in clang's handling of casts was bad enough, and its
silliness with certain extensions, but discovering that it doesn't
support raw strings was just too much. Yes, it gives a 3s boost to qfvis
on gmsp3v2.bsp, but it's not worth the hassle.
2022-10-16 18:02:25 +09:00
Bill Currie 31dd419fde [util] Reject non-shortest encoded utf-8 sequences
While chatting about utf-8, I noticed that QF doesn't ensure the input
sequences are the shortest possible encodings. It turns out that the
check is easy in that only the second byte needs to be checked if the
first byte's data bits are 0, and the second byte must have a data value
larger than that representable by the next lower leading byte.
2022-10-15 22:54:24 +09:00
Bill Currie 8868a5facf [renderer] Clean up a weird default case
I don't know why I used the void 0 instead of a break when clang
complained (probably rightly) about the default case hitting the end of
the switch.
2022-10-15 14:46:49 +09:00
Bill Currie 87dd4ee33d [gamecode] Remove some rather strange code
As indicated, I have no idea why the code was like that, but removing it
seems to have no effect as it seems to copy the data in the wrong
direction.
2022-10-15 14:44:54 +09:00
Bill Currie 2c9da25e17 Clean up some FIXMEs and XXXs
They seemed to be generally unnecessary. Also fixes some typos in
related comments.
2022-10-15 14:40:29 +09:00
Bill Currie 2c59a400e4 [vulkan] Ensure memory size is aligned
While the base of a memory object was aligned when calculating the
memory block size, the top end was not, which could result in the memory
block not getting enough bytes allocated to satisfy alignment
requirements (eg, for flushing).

While fixing that, I noticed the offsets of objects were not being
aligned when binding, so that is fixed as well.

Fixes Mr Fixit on my VersaPro.
2022-10-14 19:36:21 +09:00
Bill Currie 8464d71264 [scene] Move hierarchies to an ECS-based system
This is the beginning of adding ECS to QF. While the previous iteration
of hierarchies was a start in the direction towards ECS, this pulls most
of the 3d-specific transform stuff out of the hierarchy "objects",
making all the matrices and vectors/quaternions actual components (in
the ECS sense). There's more work to be done with respect to the
transform and entity members of hierarchy_t (entity should probably go
away entirely, and transform should become hierref_t (or whatever its
final name becomes), but I wanted to get things working sooner than
later.

The motivation for the effort was to allow views to use hierarchy_t,
which should be possible once I get entity and transform sorted out.

I am really glad I already had automated tests for hierarchies, as
things proved to be a little tricky to get working due to forgetting why
certain things were there.
2022-10-10 02:00:33 +09:00
Bill Currie 8120adb455 [renderer] Reduce glyph pixel area padding from 2x to 1.2x
With the improved atlas allocation, 2x is no longer needed and 1.2x
seems to be sufficient. Most importantly, it reduced the texture for
amiri-regular.ttf at 72 pix height from 8x to 4x (the staging buffer
isn't big enough for 8k textures).
2022-10-07 16:58:04 +09:00
Bill Currie 4feffd2de5 [vulkan] Support multiple loaded fonts
Currently, only 16 fonts can be loaded (I need to sort out descriptor
set pools), but glyphs are grouped into batches of the same font. While
not quite optimal as it can result in bouncing between descriptor sets a
lot, it's still reasonably efficient.
2022-10-07 16:53:13 +09:00
Bill Currie f477f2b96e [vullkan] Rework Draw implementation
Line rendering now has its own pipeline (removing the texture issue).

Glyph rendering (for fonts) has been reworked to use instanced quad
rendering, with the geometry (position and texture coords) in a static
buffer (uniform texture buffer), and each instance has a glyph index,
color, and 2d base position.

Multiple fonts can be loaded, but aren't used yet: still just the one
(work needs to be done on the queues to support multiple
textures/fonts).

Quads haven't changed much, but buffer creation and destruction has been
cleaned up to use the resource functions.
2022-10-03 10:29:49 +09:00
Bill Currie c9e7810864 [vulkan] Add resource memory offset to qfv_resobj_s
Its value on input is ignored. QFV_CreateResource writes the resource
object's offset relative to the beginning of the shared memory block.
Needed for the Draw overhaul.
2022-10-03 09:14:29 +09:00
Bill Currie c028e15943 [vulkan] Add a couple of staging helper functions
I got tired of writing the same 13 or so lines of code over and over (it
actually put me off experimenting with Vulkan). Thus...

QFV_PacketCopyBuffer does the work of handling barriers and a (full
packet) copy from the staging buffer to a GPU buffer.

QFV_PacketCopyImage does a similar job, but for images. However, it
still needs a lot of work, but it does make getting a basic texture onto
the GPU much less of a hassle.

Both functions should make staging data much less error-prone.
2022-10-03 09:09:34 +09:00
Bill Currie 51b73eee73 [renderer] Add fontid to Draw_AddFont and Draw_FontString
It's not used yet, but the vulkan draw implementation will eventually
support multiple fonts being loaded (and rendered at a time).
2022-10-03 09:01:54 +09:00
Bill Currie 0352af4542 [vulkan] Initialize resource image from tex_t
This moves the qfv_resobj_t image initialization code from the IQM
loader into the resource management code. This will allow me to reuse
the code for setting up glyph data. As a bonus, it cleans up the IQM
code nicely.
2022-10-02 20:45:20 +09:00
Bill Currie ac8d71733e [vulkan] Clean up QFV_duSetObjectName usage a little
Moving the param calculations into QFV_duSetObjectName params prevents
warnings when debug is disabled without having to use (void) hacks.
2022-10-02 15:07:04 +09:00
Bill Currie 9798400cfb [ui] Add a sub-system for parsing text passages
A passage object has a list of all the text objects in the given string,
where the objects represent either white space or "words", as well as a
view_t object representing the entire passage, with paragraphs split
into child views of the passage view, and each paragraph has a child
view for every text/space object in the paragraph.

Paragraphs are split by '\n' (not included in any object).

White space is grouped into clumps such that multiple adjacent spaces
form a single object. The standard ASCII space (0x20) and all of the
Unicode characters marked "WS;<compat> 0020" are counted as white space.
Unless a white space object is the first in the paragraph, its view is
marked for suppression by the view flow code.

Contiguous non-white space characters are grouped into single objects,
and their views are not suppressed.

All text object views (both white space and "word") have their data
pointer set to the psg_text_t object representing the text for that
view. This should be suitable for simple text-mode unattributed display.
More advanced rendering would probably want to create suitable objects
and set the view data pointers to those objects.

No assumption is made about text direction.

Passage and paragraph views need to have their primary axis sizes set
appropriately, as well as their resize flags. Their xlen and ylen are
both set to 10, and xpos,ypos is 0,0. Paragraph views need their
setgeometry pointer set to the appropriate view_flow_* function.
However, they are set up to have their secondary axis set automatically
when flowed.

Text object views are set up for automatic flowing: grav_flow, 0,0 for
xpos,ypos. However, xlen and ylen are also both 0, so need to be set by
the renderer before attempting to flow the text.
2022-09-30 19:51:14 +09:00
Bill Currie a24fb0ff6a [ui] Add option to auto-fit container to flowed views
Adjusting the size of the parent (container) view to the views it
contains will be useful for automatic layout and knowing how large the
view is for scrolling. New tests added so testing both with and without
the option is still possible.
2022-09-30 11:59:21 +09:00
Bill Currie 378584f41d [ui] Add functions for flow-based automatic layout
This should be suitable for laying out text objects with word-wrap,
where each view is a "word" or break between "words". This should be
useful for any other objects that could benefit from similar layout
rules. All eight flows are supported left-right-top-down (English and
most European languages), right-left-top-down (Arabic and similar),
top-down-right-left (Chinese, Japanese, Korean), top-down-left-right,
as well as bottom-up variants of those four.

More work is needed for support of things like views being centered on
the flow line rather than on one edge (depends on flow direction),
offset views, and others. Suppression of "spaces" at the beginning of a
line is supported but not tested.
2022-09-29 23:54:12 +09:00
Bill Currie c0e3821fa6 [gl/glsl] Shift the 2d view by 0.5 pixels in X and Y
Fixes top and left edge lines not being visible (same story as vulkan).
2022-09-28 22:50:44 +09:00
Bill Currie 2d634b7cf7 [vulkan] Shift the 2d view by 0.5 pixels in X and Y
Lines drawn along the top and left edges were not displayed because
they were just off screen.
2022-09-28 22:24:22 +09:00
Bill Currie ba9a071b1c [console] Fix console sliding and resize
Due to the changes related to console views, the console was either
fully visible or not at all visible, so it took several seconds to
disappear whenever closed.

Taking the screen data from the event fixes the console size being out
due to screen_view updating after the app_window event fires. Really,
this makes it independent of the order.
2022-09-28 21:57:10 +09:00
Bill Currie 60e712f224 [vulkan] Use the right uvs for lines
UVs being 0 meant that lines were picking up the upper left pixel of
char 0 of conchars. With quake data, this meant a transparent pixel.
Fixes invisible debug lines :P.
2022-09-28 21:53:22 +09:00
Bill Currie 49acf7035d [vulkaan] Fix incorrect conback drawing
Putting the console background image in the scrap needed different
calculations for the sliding console, but I rather messed things up.
2022-09-28 18:29:53 +09:00
Bill Currie df6f51b891 [glsl] Fix some mangled whitespace 2022-09-28 18:29:13 +09:00
Bill Currie 10f85edb21 [vulkan] Calculate the size of the capture buffer
It turns out that using the swapchain image for the size requirements is
unreliable: when running under renderdoc, vkGetImageMemoryRequirements
sets the memory requirements fields to 0, leading eventually to a null
memory object being passed to vkMapMemory, which does not end well.
2022-09-28 02:46:09 +09:00
Bill Currie 71e07e6454 [vulkan] Use vkCmdCopyImageToBuffer for screenshot capture
I had missed that vkCmdCopyImage requires the source and destination
images to have exactly the same size, and I guess assumed that the
swapchain images would always be the size they said they were, but this
is not the case for tiled-optimal images. However,
vkCmdCopyImageToBuffer does the right thing regardless of the source
image size.

This fixes the skewed screenshots when the window size is not a multiple
of 8 (for me, might differ for others).
2022-09-26 15:54:20 +09:00
Bill Currie 950d6d1472 [vulkan] Name the default magenta array view
It hasn't caused any problems, but the more objects I can name, the
better.
2022-09-26 13:08:02 +09:00
Bill Currie 1d50940c2a [vulkan] Implement window resize support
There's a problem with screenshot capture in that the image is sheared
after window resize, but the screen view looks good, and vulkan is happy
with the state changes.
2022-09-26 13:04:56 +09:00
Bill Currie 22276ad356 [vulkan] Remove double destroy of the old swapchain
I had forgotten that QFV_CreateSwapchain destroys the old swapchain when
I wrote Vulkan_CreateSwapchain.
2022-09-26 11:49:11 +09:00
Bill Currie d5586730a4 [vulkan] Remove redundant pipeline dynamic setting
As gbuf_base derives from the base pipeline, it inherits base's dynamic
setting, and thus doesn't need its own. I had a FIXME there as I wasn't
sure why I had a redundant setting, but I really can't see why I'd want
it different from any of the other main renderpass pipelines.
2022-09-26 10:07:12 +09:00
Bill Currie 0ecdd0e86b [vulkan] Rearrange init code in preparation for resizing
I've found and mostly isolated the parts of the code that will be
affected by window resizing, minus pipelines but they use dynamic
viewport and scissor settings and thus shouldn't be affected so long as
the swapchain format doesn't change (how does that happen?)
2022-09-26 09:52:14 +09:00
Bill Currie 9e440ff330 [renderer] Use designated inits on more structs
Finally, the model_funcs and render_funcs struts use designated
initializers. Not only are they good for ensuring correct
initialization, they're great for the programmer finding the right
initializer.
2022-09-25 10:37:07 +09:00
Bill Currie 5e154bf1b7 [cvar] Remove reliance on line number for developer parsing
I must have forgotten about the SYS_DeveloperID_... enum values, when I
wrote that code, because relying on the line number is not really for
the best.
2022-09-24 18:26:25 +09:00
Bill Currie c580fb9ec7 [console] Add a comment about console resizing
Due to design issues in the console API that I don't feel like
addressing at this stage, the console view is not a child of the
client's screen view (not even sure it should be in the first place), so
it won't get resized automatically when the client's screen view
resizes. However, ie_app_window is sent when the screen size changes,
and the console has to process input events anyway, so it's quite
reasonable to handle the event.
2022-09-22 16:18:53 +09:00
Bill Currie 7e03f23146 [renderer] Link plugins against external libraries
With the addition of dependencies on freetype and harfbuzz, it became
clear that the renderer plugins need to be explicitly linked against
external dependencies (and that I need to do more installed testing,
rather than just my static local builds). This fixes the unresolved
symbols when attempting to load any of the plugins.
2022-09-22 15:10:10 +09:00
Bill Currie 7c09f86d8d [models] Include fullbright in vulkan lib
I'm not sure why the other renderers are ok with Mod_CalcFullbright, but
the vulkan plugin couldn't find it.
2022-09-22 13:04:26 +09:00
Bill Currie d1f6945747 [renderer] Avoid gl/glsl segfault when resizing qwaq
qwaq doesn't supply a backtile pic, so Draw_TileClear in the gl and glsl
renderers would segfault when qwaq's window width changed due to some
back-tile being drawn.
2022-09-22 10:39:03 +09:00
Bill Currie d7be237af9 [vulkan] Fix a merge dropping that missed a conview change 2022-09-22 10:38:26 +09:00
Bill Currie 20ee47404f Merge branch 'master' into wip-twod 2022-09-22 10:06:00 +09:00
Bill Currie 41a6ea3534 [gamecode] Use adjusted vector string for sscanf
There's not much point in converting commas to spaces if the result
isn't used. Fixes several malformed vector errors in ad_tears.
2022-09-22 09:38:39 +09:00
Bill Currie 784af2bab2 [vulkan] Enable the multiview feature
As of a recent nvidia driver update, it became necessary to enable the
feature. I guess older drivers (or vulkan validation layers?) were a bit
slack in their checking (or perhaps I didn't actually get those lighting
changes working at the time despite having committed them).
2022-09-22 09:38:39 +09:00
Bill Currie 4b38d75f2c [input] Initialize the axis/button callback fields
Found these while trying to use the new code in my KSP addon.
2022-09-22 09:35:57 +09:00
Bill Currie aafb3c1d98 [vulkan] Partially document bsp rendering
This did involve changing some field names and a little bit of cleanup,
but I've got a better handle on what's going on (I think I was in one of
those coding trances where I quickly forget how things work).
2022-09-22 09:35:57 +09:00
Bill Currie ed209c3aa4 [util] Add a comment to darray test
Linux libc has its own "remove" (POSIX, even).
2022-09-22 09:35:57 +09:00
Bill Currie 2a47a61bc3 [util] Add atomic ring buffer and automated tests
Just head and tail are atomic, but it seems to work nicely (at least on
intel). I actually had more trouble with gcc (due to accidentally
testing lock-free with the wrong ring buffer... oops, but yup, gcc will
happily optimize your loop to spin really really fast). Also served as a
nice test for C11 threading.
2022-09-22 09:35:57 +09:00
Bill Currie be4978dc16 [vulkan] Update staging test for properties2 2022-09-22 09:35:57 +09:00
Bill Currie 035595dd7e [vulkan] Clean up bsp global access
This makes bsp traversal even more re-entrant (needed for shadows).
Everything needed for a "pass" is taken from bsp_pass_t (or indirectly
through bspctx_t (though that too might need some revising)).
2022-09-22 09:35:57 +09:00
Bill Currie b8070e0141 [vulkan] Check for ambient lights
Ambient lights are represented by a point at infinity and a zero
direction vector (spherical lights have a non-zero direction vector but
the cone angle is 360 degrees). This fixes what appeared to be mangled
light renderers (it was actually just an ambient light being treated as
a directional light (point at infinity, but non-zero direction vector).
2022-09-22 09:35:57 +09:00
Bill Currie 8e7474f614 [vulkan] Hook up the shadow map render pass
There are some issues with the light renderers getting mangled, and only
the first light is even touched (just begin and end of render pass), but
this gets a lot of the framework into place.
2022-09-22 09:35:57 +09:00
Bill Currie c58a2e5f54 [vulkan] Remove unused command buffer and fence 2022-09-22 09:35:57 +09:00
Bill Currie 71813af090 [vulkan] Support creating render passes with no render pass
Sounds odd, but it's part of the problem with calling two different
things with essentially the same name. The "high level" render pass in
question may be a compute pass, or a complex series of (Vulkan) render
passes and so won't create a Vulkan render pass for the "high level"
render pass (I do need to come up with a better name for it).
2022-09-22 09:35:57 +09:00
Bill Currie 3058a5103f [renderer] Move entity drawing in with view rendering
I really don't remember why I made it separate, though it may have been
to do with r_ent_queue. However, putting it together with the rest is
needed for the "render pass" rework.
2022-09-22 09:35:57 +09:00
Bill Currie 5e1ce5b46e [vulkan] Move main render pass setup to Vulkan_Main
And support sorting of render passes by an order index.
2022-09-22 09:35:57 +09:00
Bill Currie e45867d335 [vulkan] Fix some segfaults for render passes with no framebuffer specs 2022-09-22 09:35:57 +09:00
Bill Currie 3b72c9847a [vulkan] Add list of views to qfv_output_t
I'm not sure I like it, but it was an easy solution to dealing with
per-frame views when setting up a renderpass that has a framebuffer
spec.
2022-09-22 09:35:57 +09:00
Bill Currie e1c4428c8e [vulkan] Set source item for cexpr errors
It's always nice getting at least line numbers from an error message
(even if I still have to hunt for the right source "file").
2022-09-22 09:35:56 +09:00
Bill Currie 3603fa75cd [vulkan] Make Vulkan_CreateRenderPass more generally useful
It now lives in vulkan_renderpass.c and takes most of its parameters
from plist configs (just the name (which is used to find the config),
output spec, and draw function from C). Even the debug colors and names
are taken from the config.
2022-09-22 09:35:56 +09:00
Bill Currie e14e8050dc [vulkan] Remove vkparse.hinc from vkparse.h
Kind of silly having the vkparse_internal define when it was just
bypassed anyway.
2022-09-22 09:35:56 +09:00
Bill Currie 08f33d2f3a [vulkan] Rename the renderpass files
I plan on moving the current hard-coded render pass creation from
vulkan_vid_common and this maintains the (possibly silly) naming
convention).
2022-09-22 09:35:56 +09:00
Bill Currie 6a7c2cb2a1 [vulkan] Clean out the old render pass creation code
QFV_CreateRenderPass is no longer used, and QFV_CreateFramebuffer hasn't
been used for a long time. The C file is still there for now but is
basically empty.
2022-09-22 09:35:56 +09:00
Bill Currie 78437c2c90 [vulkan] Parse VkRenderPass directly
QFV_CreateRenderPass doesn't support pNext and I don't particularly feel
like making it do so at this stage (tempted to remove it).
2022-09-22 09:35:56 +09:00
Bill Currie f04108ae3e [vulkan] Switch to using vkGetPhysicalDeviceProperties2
Necessary for getting VkPhysicalDeviceMultiviewProperties (and others,
but not at this time).
2022-09-22 09:35:56 +09:00
Bill Currie e5932d1f92 [vulkan] Support Vulkan's pNext in vkparse/vkgen
The real reason for the delay in implementing support for pNext is I
didn't know how to approach it at the time, but with the experience I've
gained using and modifying vkparse, the solution turned out to be fairly
simple. This allows for the use of various extensions (eg, multiview,
which was used for testing, though none of the hookup is in this
commit). No checking is done on the struct type being valid other than
it must be of a chainable type (ie, have its own pNext).
2022-09-22 09:35:56 +09:00
Bill Currie 125821fcdd [render] Add basic 2d line drawing
The software renderer uses Bresenham's line slice algorithm as presented
by Michael Abrash in his Graphics Programming Black Book Special Edition
with the serial numbers filed off (as such, more just so *I* can read
the code easily), along with the Chen-Sutherland line clipping
algorithm. The other renderers were more or less trivial in comparison.
2022-09-22 09:35:56 +09:00
Bill Currie 2e14300a11 [client] Auto-detect light color range
Some mappers use 0-255 and others use 0-1. Detection method adapted from
ericw light (seems to be a good bet as it seems to be popular).
2022-09-22 09:35:44 +09:00
Bill Currie c6d73eaf64 [vulkan] Add light count display
Enabled by 'developer lighting'. It was good for confirming that the
lights in ad_e1m1 (Doom Hangar 16) were actually being output (over 600
of them sometimes, ouch). Turned out to be the color scale ambiguity.
2022-09-22 09:31:04 +09:00
Bill Currie fb4bb22048 [client] Add cl_(min|max)(pitch|roll) cvars
The pitch cvars are taken from quakespasm because I ran into a button I
couldn't shoot with the 80 degree limit, but I figured I'd add roll
limits while I was at it.
2022-09-22 09:31:04 +09:00
Bill Currie 3603f90718 [vulkan] Implement BSP surface transparency
Surfaces marked with SURF_DRAWALPHA but not SURF_DRAWTURB are put in a
separate queue for the water shader and run with a turb scale of 0.
Also, entities with colormod alpha < 1 are marked to go in the same
queue as SURF_DRAWALPHA surfaces (ie, no SURF_DRAWTURB unless the
model's texture indicated such).
2022-09-22 09:31:04 +09:00
Bill Currie a936336e84 [model] Support the transparent texture marker
Textures whose names start with a { are meant to be rendered with
transparency. Surfaces using those textures are marked with
SURF_DRAWALPHA.

Unfortunately, the mip levels of ad_tears' transparent textures use the
wrong color so only the highest LOD works properly, but those textures
are meant to be loaded from external files anyway, it seems.
2022-09-22 09:31:04 +09:00
Bill Currie 3a03cc9fda [sw] Use vid instead of dev for a debug print 2022-09-22 01:49:18 +09:00
Bill Currie f758f5fb70 [renderer] Respond to window size changes
Currently, only gl, glsl and sw are working, vulkan needs its swapchain
to be rebuilt, and there are minor issues with the hud and console
resizing.
2022-09-22 01:15:06 +09:00
Bill Currie ef8b267826 [x11] Allow the window to be resized
There's no maximum size, but the minimum size is currently 32x20.
2022-09-22 01:09:27 +09:00
Bill Currie d149457241 [vid] Add a listener for window size changes
A listener is used instead of (really, as well as) ie_app_window events
because systems that need to know about windows sizes may not have
anything to do with input and the event system.
2022-09-22 01:07:54 +09:00
Bill Currie fdfdf9056a [renderer] Add function to destroy frame buffers
Needed for window resizing for fisheye and warp buffers (main buffers
will be taken care of by the drivers).
2022-09-21 23:47:14 +09:00
Bill Currie 4578b1af0d [vid] Remove console view from viddef_t
This breaks console scaling for now (con_width and con_height are gone),
but is a major step towards window resize support as console stuff
should never have been in viddef_t in the first place.

The client screen init code now sets up a screen view (actually the
renderer's scr_view) that is passed to the client console so it can know
the size of the screen. The same view is used by the status bar code.

Also, the ram/cache/paused icon drawing is moved into the client screen
update code. A bit of duplication, but I do plan on merging that
eventually.
2022-09-21 17:31:18 +09:00
Bill Currie 2473584759 [vid] Clean out an unused variable from context_win
It's dead, Jim.
2022-09-21 12:37:55 +09:00
Bill Currie 0921235aa6 [console] Fix a lot of the console view placement issues
Things seem to be at least close to the right place now.

Input line handling has been made more object-oriented in that the
collection of objects required for a single input line (command, say,
say_team) are bundled into one object with just one set of handlers for
resize and draw. Much tidier.
2022-09-21 12:37:55 +09:00
Bill Currie 230e23db5d [console] Update a little for event handling
Con_CheckResize is no longer necessary thanks to the ie_app_window
event, and the client doesn't need C_ProcessInput so that is now
optional.
2022-09-21 12:13:06 +09:00
Bill Currie 8be5d35b0d [ui] Add support for setting view data early
view_new sets the geometry, but any setgeometry that need a valid data
pointer would get null. It might be better to always have the data
pointer, but I didn't feel like doing such a change at this stage as
there are quite a lot of calls to view_new. Thus view_new_data which
sets the data pointer before calling setgeometry.
2022-09-21 11:53:49 +09:00
Bill Currie 058e919273 [renderer] Use better heuristics for scrap allocation
More tuning is needed on the actual splits as it falls over when the
lower rect gets too low for the subrects being allocated. However, the
scrap allocator itself will prefer exact width/height fits with larger
cutoff over inexact cuts with smaller cutoff. Many thanks to tdb for the
suggestions.

Fixes the fps dropping from ~3700fps down to ~450fps (cumulative due to
loss of POT rounding and very poor splitting layout), with a bonus boost
to about 4900fps (all speeds at 800x450). The 2d sprites were mostly ok,
but the lightmaps forming a capital gamma shape in a 4k texture really
hurt. Now the lightmaps are a nice dense bar at the top of the texture,
and 2d sprites are pretty good (slight improvement coming next).
2022-09-20 19:32:49 +09:00
Bill Currie 1fdedbaf33 [renderer] Report scrap rectangle counts
Stats are good. More stats even better :) I wanted to see just how many
lightmaps were being created in e1m3.
2022-09-20 19:32:41 +09:00
Bill Currie 398405c8d6 [console] Remove old_console_t struct
This replaces old_console_t with con_buffer_t for managing scrollback,
and draw_charbuffer_t for actual character drawing, reducing the number
of calls into the renderer. There are numerous issues with placement and
sizing, but the basics are working nicely.
2022-09-20 16:14:55 +09:00
Bill Currie d6d45bf07c [console] Add a function to clear the scroll-back buffer
Needed for when the console display is cleared.
2022-09-20 12:14:01 +09:00
Bill Currie 11e978b4db [console] Fix a signed comparison warning
I'm not sure why that didn't trigger in a linux build. Maybe gcc 12
assumed the result would be positive (I think I'm still using 11 for
mxe).
2022-09-20 10:50:15 +09:00
Bill Currie 474f01d321 [renderer] Return count of lines printed to char buffer
This allows users to know the number of terminated lines in the printed
text without having to redundantly count the lines.
2022-09-20 10:27:24 +09:00
Bill Currie 1cd6a174fe [build] Correct cygwin system type
cygwin is not windows, so trying to build a win32 app on cygwin-native
doesn't work too well.
2022-09-19 16:36:29 +01:00
Bill Currie e36adb07ec [net] Don't include windows.h or winsock.h directly
Including them kills the definition for CMSG_DATA.
2022-09-19 16:32:45 +01:00
Bill Currie 08328f4076 Fix some cygwin portability issues
Cygwin's headers seem to be rather out of date with respect to linux
with regards to signed types, especially ctype.
2022-09-19 16:31:08 +01:00
Bill Currie 745778979a [image] Update stub WritePNG's definition
Fixes some bitrot for when libpng is unavailable
2022-09-19 13:38:58 +01:00
Bill Currie 3eceb444d3 [console] Add test for buffer line tracking
Seems to work, so I guess con_buffer is ok now.
2022-09-18 16:07:22 +09:00
Bill Currie 48e5848a41 [console] Rework con_buffer ring buffers to have gaps
I really don't know why I tried to do ring-buffers without gaps, the
code complication is just not worth the tiny savings in memory. In fact,
just the switch from pointers to 32-bit offsets saves more memory than
not having gaps (on 64-bit systems, no change on 32-bit).
2022-09-18 11:35:09 +09:00
Bill Currie 5e8d18a774 [console] Add failing test for adding to full 1-line buffer
I've decided that appending to a full single-line buffer should simply
scroll through the existing text. Unsurprisingly, the existing code
doesn't handle the situation all that well. While I've already got a fix
for it, I think I've got a better idea that will handle full buffers
more gracefully.
2022-09-17 15:31:52 +09:00
Bill Currie c8c1d2e642 [console] Add a pile of of comments to Con_BufferAddText
And make tail_line setup a little clearer.
2022-09-17 14:22:28 +09:00
Bill Currie 9a92496662 [console] Don't overwrite tail line if same as current line
This fixes the current line object getting corrupted by the tail line
update when the buffer is filled with a single line. There are probably
more tests to write and bugs to fix :)
2022-09-17 13:56:23 +09:00
Bill Currie d13df6cd37 [console] Add failing unit test for con_buffer
I was looking through the code for Con_BufferAddText trying to figure
out what it was doing (answer: ring buffer for both text and lines) and
got suspicious about its handling of the line objects. I decided an
automated test was in order. It turns out I was right: filling the
buffer with a single long line causes the tail line to trample the
current line, setting its pointer and length to 0 when the final
character is put in the buffer.
2022-09-17 12:59:36 +09:00
Bill Currie 437e447b6b [renderer] Add a buffer print function
It handles basic cursor motion respecting \r \n \f and \t (might be a
problem for id chars), wraps at the right edge, and automatically
scrolls when the cursor tries to pass the bottom of the screen.

Clearing the buffer resets its cursor to the upper left.
2022-09-16 00:58:25 +09:00
Bill Currie c5099d30b1 [renderer] Fix access to freed memory loading fonts
QFS_LoadFile closes its file argument (this is a design error resulting
from changing QFS_LoadFile to take a file instead of a path and not
completing the update), resulting in the call to Qfilesize accessing
freed memory.
2022-09-15 14:32:16 +09:00
Bill Currie 25a14eb232 [renderer] Add a cell-based character buffer
This is intended for the built-in 8x8 bitmap characters and quake's
"conchars", but could potentially be used for any simple (non-composed
characters) mono-spaced font. Currently, the buffers can be created,
destroyed, cleared, scrolled vertically in either direction, and
rendered to the screen in a single blast.

One of the reasons for creating the buffer is to make it so scaling can
be supported in the sw renderer.
2022-09-15 14:24:33 +09:00
Bill Currie 98f773b0ed [gamecode] Expose value_string as PR_Debug_ValueString
PR_Debug_ValueString prints the value at the given offset using the
provided type to format the string. The formatted string is appended to
the provided dstring.
2022-09-15 00:30:21 +09:00
Bill Currie aa41e6c4c6 [gamecode] Expose value_string as PR_Debug_ValueString
PR_Debug_ValueString prints the value at the given offset using the
provided type to format the string. The formatted string is appended to
the provided dstring.
2022-09-14 19:23:59 +09:00
Bill Currie c771bfa58c [renderer] Correct freetype and harfbuzz lib linking
renderer_libs was in both LIBADD and DEPENDENCIES, so make was trying to
build the freetype and harfbuzz libs when building for windows.
2022-09-13 17:38:58 +09:00
Bill Currie 6ed045cd9c [audio] Ensure FLAC doesn't use dll imports
For whatever reason, building under MXE (for windows) causes FLAC to try
to use dll import references, but setting FLAC__NO_DLL before including
FLAC/export.h fixes the issue.
2022-09-13 17:13:57 +09:00
Bill Currie bf7ef354d5 [audio] Ensure FLAC doesn't use dll imports
For whatever reason, building under MXE (for windows) causes FLAC to try
to use dll import references, but setting FLAC__NO_DLL before including
FLAC/export.h fixes the issue.
2022-09-13 17:09:42 +09:00
Bill Currie 99196550d1 [renderer] Move r_font.c to correct library
Fixes the linker error in the standard build.
2022-09-12 08:43:28 +09:00
Bill Currie 71efbba628 [vulkan] Switch draw_pic to take subpic_t instead of qpic_t
While this does pull the grovelling for the subpic out to the callers,
the real problem is the excessive use of qpic_t in the internal code:
qpic_t is really just the image format in wad files, and shouldn't be
used as a generic image handle.

Cleans up more of the icky code in the font drawing functions.
2022-09-09 20:05:31 +09:00
Bill Currie 936f6d91e4 [vulkan] Use vertex queue objects for Draw
This makes working with quads, implied alpha quads, and lines much
cleaner (and gets rid of the bulk of the "eww" fixme), and will probably
make it easier to support multiple scraps and fonts, and potentially
more flexible ordering between pipelines.
2022-09-09 17:06:33 +09:00
Bill Currie a6611fc827 [gamecode] Fix a clang compile issue
Silly clang not being actually compatible :P
2022-09-09 14:59:08 +09:00
Bill Currie a76f6c812c [gamecode] Fix a clang compile issue
Silly clang not being actually compatible :P
2022-09-09 14:57:30 +09:00
Bill Currie 019b40fb81 [ruamoko] Implement %@ handing in the ruamoko runtime
-describe is sent to the object, and the returned string passed back.
There is a worry about the lifetime of the returned string as there's
currently no way of both ensuring it doesn't get freed prematurely and
ensuring it does eventually get freed.
2022-09-09 14:48:03 +09:00
Bill Currie be447fc9d6 [gamecode] Add optional support for %@ strings
If no handler has been registered, then the corresponding parameter is
printed as a pointer but with surrounding brackets (eg, [0xfc48]). This
will allow the ruamoko runtime to implement object printing.
2022-09-09 14:48:03 +09:00
Bill Currie 54bd8f5a02 [ruamoko] Implement %@ handing in the ruamoko runtime
-describe is sent to the object, and the returned string passed back.
There is a worry about the lifetime of the returned string as there's
currently no way of both ensuring it doesn't get freed prematurely and
ensuring it does eventually get freed.
2022-09-09 13:51:42 +09:00
Bill Currie 6db44afedc [gamecode] Add optional support for %@ strings
If no handler has been registered, then the corresponding parameter is
printed as a pointer but with surrounding brackets (eg, [0xfc48]). This
will allow the ruamoko runtime to implement object printing.
2022-09-09 09:27:36 +09:00
Bill Currie 935e883d8d [renderer] Switch to using HarfBuzz for glyph positioning
This means that QF should support more exotic fonts without any issue
(once the rest of the text handling system is up to snuff) as HarfBuzz
does all the hard work of handling OpenType, Graphite, etc text shaping,
including kerning (when enabled).

Also, font loading now loads all the glyphs into the atlas (preload is
gone).
2022-09-04 20:56:38 +09:00
Bill Currie db69f5fd23 [renderer] Use VRect_SubRect for scrap allocation
While the results are a little surprising (tends to alternate between
left side and top for allocations), there is much less wasted space in
the partially allocated regions, and the main free region seems to
always be quite big.
2022-09-02 19:08:58 +09:00
Bill Currie 28e9a0a9ba [ui] Add a specialized function for subrect allocation
While VRect_Difference worked for subrect allocation, it wasn't ideal as
it tended to produce a lot of long, narrow strips that were difficult to
reuse and thus wasted a lot of the super-rectangle's area. This is
because it always does horizontal splits first. However, rewriting
VRect_Difference didn't seem to be the best option.

VRect_SubRect (the new function) takes only width and height, and splits
the given rectangle such that if there are two off-cuts, they will be
both the minimum and maximum possible area. This does seem to make for
much better utilization of the available area. It's also faster as it
does only the two splits, rather than four.
2022-09-02 17:47:27 +09:00
Bill Currie cd66dbfc97 [vulkan] Implement font rendering
It is currently an ugly hack for dealing with the separate quad queue,
and the pipeline handling code needs a lot of cleanup, but it works
quite well, though I do plan on moving to HarfBuzz for text shaping. One
nice development is I got updating of descriptor sets working (just need
to ensure the set is no longer in use by the command queue, which the
multiple frames in flight makes easy).
2022-09-02 14:23:19 +09:00
Bill Currie 73635d84bf [renderer] Add stubs for Draw_FontString
Draw_FontString is for font-based text rendering. Nothing is implemented
at this stage.
2022-09-02 11:38:09 +09:00
Bill Currie 599c09e77e [renderer] Add Draw_AddFont for registering a font
It's implemented only in the Vulkan renderer, partly because there's a
lot of experimenting going on with it, but the glyphs do get transferred
to the GPU (checked in render doc). No rendering is done yet: still
thinking about whether to do a quick-and-dirty test, or to add HarfBuzz
immediately, and the design surrounding that.
2022-08-31 19:23:30 +09:00
Bill Currie 096ecc7710 [vulkan] Fix incorrect image view format
R8G8B8A8 was hard-coded by accident when creating Vulkan_LoadTexArray
(or probably even the original Vulkan_LoadTex). This wasn't a problem
while everything was loaded in that format, but attempting to load an R8
texture didn't go so well. The same format as the image itself is used
now (correctly so).
2022-08-31 18:14:24 +09:00
Bill Currie 8c270a0a9e [vulkan] Switch to pre-multiplied alpha for 2d
I have recently learned that pre-multiplied alpha is the correct way to
do compositing, which is pretty much what the 2d pass does (actually,
all passes, but...). This required ensuring the color factor passed to
the fragment shader is pre-multiplied (a little silly for cshifts as
they used to be pre-multiplied but were un-pre-multiplied early in QF's
history and I don't feel like fixing that right now as it affects all
renderers), and also pre-multiplying alpha when converting from 8-bit
palette to rgba as the palette entry for transparent has that funky pink
(which is used in full-brights).
2022-08-30 14:29:22 +09:00
Bill Currie 4d5b38f0c9 [renderer] Star work on adding FreeType support
Right now, this just initializes the library and loads a font into
memory, preloading a given set of characters (specified by unicode
values).
2022-08-27 17:53:03 +09:00
Bill Currie d39f02ecfc [renderer] Don't round up scrap allocations
I will need to do more work to improve the 2d allocation, but rounding
up the requested sizes to the next power of two proved to be excessively
wasteful: I was able to allocate spots for only half of the sub-pics I
needed (though I did still need to double the number of pixels in the
end).
2022-08-27 17:46:14 +09:00
Bill Currie 630dde6df7 [render] Add basic 2d line drawing
The software renderer uses Bresenham's line slice algorithm as presented
by Michael Abrash in his Graphics Programming Black Book Special Edition
with the serial numbers filed off (as such, more just so *I* can read
the code easily), along with the Chen-Sutherland line clipping
algorithm. The other renderers were more or less trivial in comparison.
2022-08-27 17:29:15 +09:00
Bill Currie f611b0d5a1 [client] Preserve intensity when parsing light color
Due to the mis-initialization of the union used to parse the color
vector, the intensity was incorrectly set to zero and thus the light
dropped, meaning that all lights in ad_tears were lost.
2022-08-19 20:19:43 +09:00
Bill Currie 1e54799f69 [gamecode] Take care of failing uint conversion tests
By not doing the unrepresentable conversions, since they seem to be
undefined behavior and even gcc 12 is inconsistent with them
2022-08-18 18:18:19 +09:00
Bill Currie d9d0a80752 [gamecode] Add an extend instruction
The extend instruction is for loading narrower data types into wider
data types, eg, single element into 2, 3, or 4 element types, with a
small set of extension schemes: 0, 1, -1, copy (for 1->any and 2 -> 4).
Possibly most importantly, it works with unaligned data.

Progress towards #30
2022-08-18 18:18:19 +09:00
Bill Currie 0897952a57 Fix windows compile issues
ulong seems to be defined somewhere on Linux, thus I missed that, and of
course there's the fun with aligned memory allocation :/
2022-07-31 17:34:09 +09:00
Bill Currie 732ea3a5fd Fix a bunch of issues for clang
One *actual* error (wrong enum type), and some memory alignment issues.
The rest just clang being lame.
2022-07-31 17:15:40 +09:00
Bill Currie 2c8bec27c7 Fix a pile of warnings for gcc 12
Most were pretty easy and fairly logical, but gib's regex was a bit of a
pain until I figured out the real problem was the conditional
assignments.

However, libs/gamecode/test/test-conv4 fails when optimizing due to gcc
using vcvttps2dq (which is nice, actually) for vector forms, but not the
single equivalent other times. I haven't decided what to do with the
test (I might abandon it as it does seem to be UD).
2022-07-31 17:13:26 +09:00
Bill Currie 330569a3fb [sound] Add a function to set ambient sounds
This gets ambient sounds (in particular, water and sky) working again
for quakeworld after the recent sound changes, and again for nq after I
don't know how long.
2022-06-06 14:29:14 +09:00
Bill Currie c72b04a522 [cvar] Remove a debug print 2022-06-06 14:28:28 +09:00
Bill Currie 520371a3aa [zone] Fix bad suggested mem calculation
Because the calculation didn't take the hunk header size (which is not
included in the hunk size) into account, the conversion to MB was one
short and thus the rounding up to the next 8 MB boundary was giving the
current total hunk size (ie, the already given size). Most confusing to
a user ("But I already asked for 128MB!").
2022-06-06 14:05:52 +09:00
Bill Currie ef64161835 [zone] Make Hunk_RawAlloc the core hunk allocator
It turns out that copying just "unknown" is a significant performance
hit when doing over 100M allocations. Making Hunk_RawAlloc the core and
initializing the name field with a single 0 shaved about a second off
`qfvis gmsp3v2.bsp` (from about 39s to about 38s).
2022-06-06 13:33:54 +09:00
Bill Currie 5c94c40985 [zone] Revert cache behavior to its original design
My reason for using Hunk_HighAlloc for allocating cache blocks was to
lock them down so they were safe for the sound mixer to access when
running in a real-time thread. However, I had never tested under tight
memory constraints, which proved that the design (or maybe just
implementation) just wasn't robust. However, now that sounds are loaded
into a completely separate region, it's safe to put the cache back to
its original behaviour (still with 64-byte alignment and such, of
course). This will even allow the high hunk to be used again, though it
effectively was anyway with Hunk_TempAlloc.
2022-06-06 13:33:15 +09:00
Bill Currie 5fa73e7ff2 [sound] Rename "cache" to "block" and clean out old code
I never liked "cache" as a name because it said where the sound was
stored rather than how it was loaded/played, but "stream" is ok, since
that's pretty much spot on. I'm not sure "block" is the best, but it at
least makes sense because the sounds are loaded as a single block (as
opposed to being streamed). An now, neither use the cache system.
2022-06-06 12:39:54 +09:00
Bill Currie 79f3f651a4 [sound] Bring QF into the atomic age
Nuclear powered audio ;)

More seriously, use _Atomic on a few fields that very obviously need it.
That is, channel's buffer pointer (used to signal to the mixer that the
channel is ready for use) and "flow control" flags (stop, done and
pause), and head and tail in the buffer itself. Since QF has been
working without _Atomic (admittedly, thanks to luck and x86's strong
memory model), this should do until proven otherwise. I imagine getting
stream reading out of the RT thread will highlight any issues.
2022-06-06 12:39:54 +09:00
Bill Currie 7bbfde03fc [sound] Plug the channel leak
Turned out the channels simply weren't being freed by SND_ScanChannels
when they should have been (probably a good thing, too, as it wasn't
being told to wait for the mixer).
2022-06-06 12:39:54 +09:00
Bill Currie fdd070f6dc [sound] Add a threaded field to snd_t
Care needs to be taken when freeing channels as doing so while an
asynchronous mixer is using them is unlikely to end well. However,
whether the mixer is asynchronous depends on the output driver. This
lets the driver inform the rest of the system that the output and mixer
are running asynchronously.
2022-06-06 12:39:54 +09:00
Bill Currie 48f704c84e [sound] Use SYS_snd for all masked prints
SYS_dev is a holdover from when we had only the one flag and is not
meant to be used for tests (I seem to remember mentioning an audit was
necessary, but obviously forgotten). One step at a time, I guess :)
2022-06-06 12:39:54 +09:00
Bill Currie 91140acfee [sound] Access the buffer directly from the channel
This improves the locality of reference when mixing and removes the
proxy sfx for streamed sounds.

The buffer for streamed sounds is allocated when the stream is opened
(since streamed sounds can't share buffers), and freed when the stream
is closed.

For block sounds, the buffer is reference counted (with the sfx holding
one reference, so currently block buffers never get freed), with their
reference count getting incremented on open and decremented on close.
That the reference counts get to 1 has been confirmed, so all that
should be needed is proper destruction of the sfx instances.

Still need to sort out just why channels leak across level changes.
2022-06-06 12:39:54 +09:00
Bill Currie 11fee8571c [zone] Add functions to get and set the tag
Getting the tag is possibly useful in general and definitely in
debugging. Setting, I'm not so sure as it should be done when allocated,
but that's not always possible.

Also, correct the return type of z_block_size, though it affected only
Z_Print. While an allocation larger than 4GB is... big for zone, the
blocks do support it, so printing should too.
2022-06-06 12:39:54 +09:00
Bill Currie 2298227546 [sound] Check for allocation failures
They're currently treated as non-fatal, those sounds just won't ever
play. This allows ad_tears to at least load with only 32MB of locked
memory (it needs somewhere between 64 and 96).
2022-06-06 12:39:54 +09:00