Skip to content

Get rid of a bunch of duplicate code in map loading and srf*_t#1635

Merged
VReaperV merged 13 commits intoDaemonEngine:masterfrom
VReaperV:generic-srf
Apr 11, 2025
Merged

Get rid of a bunch of duplicate code in map loading and srf*_t#1635
VReaperV merged 13 commits intoDaemonEngine:masterfrom
VReaperV:generic-srf

Conversation

@VReaperV
Copy link
Copy Markdown
Contributor

@VReaperV VReaperV commented Apr 1, 2025

I've run into a bunch of duplicate code while making some improvements to map processing, any improvements to which required to add more such duplication, while the code underneath is the exact same.

This pr NUKES srfTriangles_t and srfSurface_t, and moves all the common information between them, srfGridMesh_t, and srfVBOMesh_t , into srfGeneric_t.

The common parts of ParseFace() and ParseTriSurf() are moved into a new ParseTriangleSurface(), which is all of it except the plane calculation. The comment about .lwo models in ParseTriSurf() is irrelevant, because we don't support those.

ParseTriangleSurface() and ParseMesh() now use SphereFromBounds() instead of FinishGenericSurface(), because the only difference between the 2 was just duplicated code.

@VReaperV
Copy link
Copy Markdown
Contributor Author

VReaperV commented Apr 1, 2025

CI fail is unrelated, and is due to Ubuntu 20.04 being phased out on azure pipelines.

Copy link
Copy Markdown
Member

@slipher slipher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some tiny model lighting changes from Move some common stuff from srf* to srfGeneric_t and Move duplicate code from ParseFace() and ParseTriSurf() into ParseTriangleSurface(). I will try to check later if those diffs are anything.

@VReaperV
Copy link
Copy Markdown
Contributor Author

VReaperV commented Apr 3, 2025

There are some tiny model lighting changes from Move some common stuff from srf* to srfGeneric_t and Move duplicate code from ParseFace() and ParseTriSurf() into ParseTriangleSurface(). I will try to check later if those diffs are anything.

For BSP models? I don't think other models can even be affected by this.

@slipher
Copy link
Copy Markdown
Member

slipher commented Apr 4, 2025

No, it was a buildable model.

@VReaperV
Copy link
Copy Markdown
Contributor Author

VReaperV commented Apr 4, 2025

That's weird... Buildings should only ever use srfVBOMD5Mesh_t or srfVBOMDVMesh_t.

@VReaperV VReaperV force-pushed the generic-srf branch 2 times, most recently from df6eecc to 04e9f54 Compare April 4, 2025 21:01
@slipher
Copy link
Copy Markdown
Member

slipher commented Apr 4, 2025

I can reproduce a similar small diff by adding unused fields to srfGeneric_t, e.g.

diff --git a/src/engine/renderer/tr_local.h b/src/engine/renderer/tr_local.h
index fe658c0b2..c3c4a9b3d 100644
--- a/src/engine/renderer/tr_local.h
+++ b/src/engine/renderer/tr_local.h
@@ -1738,9 +1738,15 @@ enum class ssaoMode {
        {
                surfaceType_t surfaceType;
 
+               int argle;
+
                // culling information
                vec3_t   bounds[ 2 ];
+
+               int bargle;
+
                vec3_t   origin;
+
                float    radius;
        };

Maybe the layout is assumed somewhere else.

@slipher
Copy link
Copy Markdown
Member

slipher commented Apr 4, 2025

Without/with the above patch, the lower part of the Overmind looks a bit more brightly lit on the before side.

unvanquished-nano-overmind

unvanquished-nano-overmind

@slipher
Copy link
Copy Markdown
Member

slipher commented Apr 5, 2025

The lighting diffs reproduce with different OS, compiler, and GPU.

I tried getting rid of srfGeneric_t and commenting out or rewriting all places that use it. After that I still get the same diff by adding extra fields in srfVBOMesh_t only.

The diffs go away if I disable r_deluxeMapping.

@slipher
Copy link
Copy Markdown
Member

slipher commented Apr 5, 2025

I found the cause of that stuff in #1639.

@VReaperV
Copy link
Copy Markdown
Contributor Author

VReaperV commented Apr 5, 2025

Thanks, that is very helpful!

Copy link
Copy Markdown
Member

@slipher slipher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the last commit, NUKE srfSurfaceFace_t, should be dropped. It will just cause confusion for one of the surface types to not have its own struct. But a couple changes from that commit of changing some casts to srfGeneric_t * should be kept (these fix comments I made on earlier commits complaining of casting to an inappropriate type).

|| *surface->data == surfaceType_t::SF_TRIANGLES )
{
srfSurfaceFace_t *face = ( srfSurfaceFace_t * ) surface->data;
srfSurfaceFace_t* srf = ( srfSurfaceFace_t * ) surface->data;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cast to wrong type

@VReaperV
Copy link
Copy Markdown
Contributor Author

VReaperV commented Apr 8, 2025

I think the last commit, NUKE srfSurfaceFace_t, should be dropped. It will just cause confusion for one of the surface types to not have its own struct.

But this is also the case with srfTriangles_t.

@slipher
Copy link
Copy Markdown
Member

slipher commented Apr 8, 2025

I think the last commit, NUKE srfSurfaceFace_t, should be dropped. It will just cause confusion for one of the surface types to not have its own struct.

But this is also the case with srfTriangles_t.

OK then I complain about that one too 😛

@VReaperV
Copy link
Copy Markdown
Contributor Author

VReaperV commented Apr 8, 2025

I guess I can revert those, though I don't see much point in keeping around structs that have nothing in them other than stuff they inherit.

@slipher
Copy link
Copy Markdown
Member

slipher commented Apr 8, 2025

I guess it's fine as long as there are comments on the SF_FACE etc. enum.

@VReaperV
Copy link
Copy Markdown
Contributor Author

VReaperV commented Apr 8, 2025

I've added the comments into srfGeneric_t.

VReaperV added 3 commits April 8, 2025 13:41
…angleSurface()

Also moves `plane` from `srfSurfaceFace_t` to `srfSurfaceGeneric_t`, since it's the only difference between them, and plane computations were already being done on `srfSurfaceGeneric_t` anyway, so they can be moved there too.
VReaperV added 5 commits April 8, 2025 13:41
The only other code in `FinishGenericSurface()` was duplicate from `ParseFace()`. Also moved both `ShaderForShaderNum()` and `SphereFromBounds()` closer to where they're actually used.
It is now the same as `srfGeneric_t`, so just use that instead.
// triangle definitions
int numTriangles;
srfTriangle_t *triangles;
cplane_t plane; // Valid in: SF_FACE, SF_TRIANGLES
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does SF_TRIANGLES really have a plane? It doesn't make much sense and the old srfTriangles_t doesn't have it.

Also I don't think it's necessary to have comments on ones that are always valid; you can remove those if you want.

Copy link
Copy Markdown
Contributor Author

@VReaperV VReaperV Apr 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that too, but R_PlaneForSurface() was already using the first triangle's plane as surface plane for SF_TRIANGLES:

case surfaceType_t::SF_TRIANGLES:
tri = ( srfTriangles_t * ) surfType;
v1 = tri->verts + tri->triangles[ 0 ].indexes[ 0 ];
v2 = tri->verts + tri->triangles[ 0 ].indexes[ 1 ];
v3 = tri->verts + tri->triangles[ 0 ].indexes[ 2 ];
PlaneFromPoints( plane4, v1->xyz, v2->xyz, v3->xyz );
VectorCopy( plane4.normal, plane->normal );
plane->dist = plane4.dist;
return;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For code comments, I'll adjust them in a later pr, since I found some more things that can be cleaned up there, but don't want to overload this pr.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. It seems R_PlaneForSurface is only used for portals.

@slipher
Copy link
Copy Markdown
Member

slipher commented Apr 11, 2025

LGTM

@VReaperV VReaperV merged commit e14bb7a into DaemonEngine:master Apr 11, 2025
9 checks passed
@VReaperV VReaperV deleted the generic-srf branch April 11, 2025 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants