Commit graph

12877 commits

Author SHA1 Message Date
Bill Currie
80c0beff89 [ecs] Support adding null hierarchies to non-root
As an implementation detail, inserting null hierarchies (src hierarchy
is null) is supported for ease of hierarchy construction from data. No
component data is copied, only the child and parent indices and counts
are updated.
2022-10-27 19:46:28 +09:00
Bill Currie
52b09e81cd [ecs,scene] Update tests for move to separate ecs lib
And fix an issue spotted in hierarchy.c: incorrect move of objects and
lack of check for valid entity when updating hierarchy reference
indices.
2022-10-27 15:35:29 +09:00
Bill Currie
d8cdaa7237 [vulkan] Fix some errors in shadow map setup
I had forgotten to test with nq, so I had missed that I'd messed up cube
map requests and the image map. This gets nq working again.
2022-10-27 13:29:14 +09:00
Bill Currie
0a3c7b5b76 [vulkan] Don't use QFV_CreateImage for resource images
The resource functions assume the requested layers is correct (really,
the lighting code assumes that the resource functions assume such), but
QFV_CreateImage multiplies the layer count by 6 for cube maps (really,
the issue is in QFV_CreateImage, but I want to move away from it
anyway).
2022-10-27 13:26:00 +09:00
Bill Currie
c605e50d52 [renderer] Check view_model entity is valid
It usually is in quake, but my test scene does not have a view model.
2022-10-27 12:55:01 +09:00
Bill Currie
fa057cb121 [vulkan] Record resource memory size
It's useful mainly for information reports, but might be useful
elsewhere.
2022-10-27 11:32:00 +09:00
Bill Currie
1f27622309 [vulkan] Free shadow map resource block
I forgot I had to free the memory too. Oops.
2022-10-27 11:23:49 +09:00
Bill Currie
169c282187 [vulkan] "Fix" view model check in rendering loop
The check for the entity being the view model was checking only the
view model id, which is not sufficient when the view model is invalid by
never being set to other than 0s. A better system for dealing with the
view model is needed.
2022-10-27 11:11:38 +09:00
Bill Currie
6952f6860d [vulkan] Use the resource functions for shadow maps
Another step towards moving all resource creation into the one place.
The motivation for doing the change was getting my test scene to work
with only ambient lights or no lights at all.
2022-10-27 11:02:45 +09:00
Bill Currie
5d19936387 [gl,sw] Don't clear world's efrags on new scene
It seems this isn't needed any more (not sure why) as both glsl and
vulkan are happy without it. Also unsure why moving to ECS made gl and
sw change behavior regarding rendering the test models in my scene.
2022-10-27 00:22:15 +09:00
Bill Currie
600a342200 [ruamoko] Fix missing entity registry pointer 2022-10-26 17:45:45 +09:00
Bill Currie
db7f8a461e [ecs] Move ECS core into its own library
While the libraries are probably getting a little out of hand, the
separation into its own directory is probably a good thing as an ECS
should not be tied to scenes. This should make the ECS more generally
useful.
2022-10-26 17:24:03 +09:00
Bill Currie
4df145d76a [scene] Improve entity component check
For a component to be on an entity, the entity id in the component
pool's dense array must match the entity.
2022-10-26 12:34:09 +09:00
Bill Currie
52b7f7f308 [renderer] Fix a comment typo and add a fixme 2022-10-26 12:32:09 +09:00
Bill Currie
20c861027e [sw] Take advantage of the ECS for edge rendering
This fixes the segfault due to the world entity not actually existing,
without adding a world entity. It takes advantage of the ECS in that the
edge renderer needs only the world matrix, brush model pointer, and the
animation frame number (which is just 0/1 for brush models), thus the
inherent SOA of ECS helps out, though benchmarking is needed to see if
it made any real difference.

With this, all 4 renderers are working again.
2022-10-25 19:36:09 +09:00
Bill Currie
2a9fcf4f5f [renderer] Tidy up entity component access
Since entity_t has a pointer to the registry owning the entity, there's
no need to access a global to get at the registry. Also move component
getting closer to where it's used.
2022-10-25 12:53:30 +09:00
Bill Currie
5b0810f4c2 [scene] Make Ent_AddComponent more raw
It no longer initializes the new component. For that, use
Ent_SetComponent which will copy in the provided data or call the
component's create function if the data pointer is null (in which case,
Ent_SetComponent acts as Ent_SetComponent used to).
2022-10-25 11:41:14 +09:00
Bill Currie
4759be449f [scene] Ensure entity owns component before removing
I realized I should check that the entity owns the component before
treating it as existing when adding an existing component, then noticed
that Ent_RemoveComponent didn't check before removing the component. I
imagine that would have been a fun debug session :P
2022-10-25 09:55:08 +09:00
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
9f9e21f1dc [nq] Relink entities when there model changes
This is the fix for the grenade explosion bug. It was rather difficult
to track down because *two* explosions are rendered for the one grenade
(but that's actually another bug due to the nq/qw merge). It's also
correct as changing the model can change the BSP leafs the entity
touches.
2022-10-23 23:02:16 +09:00
Bill Currie
cf4a3399c4 [nq] Reduce entity churn
While chasing down the grenade explosion bug, I noticed that entities
were being created and destroyed (or really, not destroyed) just to
check of the entity was valid. In the old system, this wasn't
*horrible*, but with the ECS, it does mean entities and components are
getting churned up, which wouldn't be good for the entity generation
counter (only 12 bits).
2022-10-23 22:43:45 +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
dd1554aed3 [qw] Set cl.viewstate.time when setting cl.time
Fixes cshifts not fading. I'm sure there is a better fix, but this at
least gets qw mostly usable (for testing, at least: something is wonky
with roll).
2022-10-22 14:15: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
394018b3c5 [qw] Fix carried flag handling
I guess some of the earlier entity/scene handling hadn't been tested for
flags as no entity was ever being created for a flag. This fixes a
segfault when another player carrying a flag is potentially visible.

Also make the -16 Z offset local. It looks better than global, and the
global was quite wrong anyway as it was incorrectly updating W (which
caused me to spend way too long figuring out why positions were
breaking).

There are still issues with flag handling, and things are likely to
change with the ECS updates, but at least this lets me test.
2022-10-22 12:46:51 +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
8ec4a18f5d [scene] Swtich from - to ~ for entity id index
It saves only 1 bit in the set, but it could save on allocations. Also
takes care of a FIXME :P
2022-10-15 14:48:39 +09:00
Bill Currie
76124ab868 [qw] Document most of the mvd cvars
Many are unused, but it's nice to have the info there.
2022-10-15 14:47:53 +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
6552d76a5f Clarify FIXME on qdefs.h include 2022-10-15 14:42:04 +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
f16fc15605 [scene] Correct some typos in hierarchy.h
Lost the y somewhere
2022-10-09 01:08:48 +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