Skip to content

Commit 2a60ffa

Browse files
committed
Merge branch 'master' into for-0.56.0/sync
2 parents 3dda072 + 36196cc commit 2a60ffa

File tree

14 files changed

+473
-621
lines changed

14 files changed

+473
-621
lines changed

src/common/Defs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3737
/** No case, No spaces */
3838
#define PRODUCT_NAME_LOWER "unvanquished"
3939

40-
#define PRODUCT_VERSION "0.55.2"
40+
#define PRODUCT_VERSION "0.55.3"
4141

4242
/** Default base package */
4343
#define DEFAULT_BASE_PAK PRODUCT_NAME_LOWER

src/engine/renderer/GeometryOptimiser.cpp

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -308,20 +308,25 @@ void MergeDuplicateVertices( bspSurface_t** rendererSurfaces, int numSurfaces, s
308308
for ( int i = 0; i < numSurfaces; i++ ) {
309309
bspSurface_t* surface = rendererSurfaces[i];
310310

311-
srfGeneric_t* face = ( srfGeneric_t* ) surface->data;
312-
face->firstIndex = idx;
313-
for ( srfTriangle_t* triangle = face->triangles; triangle < face->triangles + face->numTriangles; triangle++ ) {
311+
srfGeneric_t* srf = ( srfGeneric_t* ) surface->data;
312+
srf->firstIndex = idx;
313+
for ( srfTriangle_t* triangle = srf->triangles; triangle < srf->triangles + srf->numTriangles; triangle++ ) {
314314
for ( int j = 0; j < 3; j++ ) {
315-
srfVert_t& vert = face->verts[triangle->indexes[j]];
315+
srfVert_t& vert = srf->verts[triangle->indexes[j]];
316316
uint32_t index = verts[vert];
317317

318-
ASSERT_LT( idx, numIndicesIn );
318+
/* There were some crashes due to bad lightmap values in .bsp vertices,
319+
do the check again here just in case some calculation earlier, like patch mesh triangulation,
320+
fucks things up again */
321+
ValidateVertex( &vert, -1, surface->shader );
322+
323+
ASSERT_LT( idx, ( uint32_t ) numIndicesIn );
319324
if ( !index ) {
320325
verts[vert] = vertIdx + 1;
321326
vertices[vertIdx] = vert;
322327
indices[idx] = vertIdx;
323328

324-
ASSERT_LT( vertIdx, numVerticesIn );
329+
ASSERT_LT( vertIdx, ( uint32_t ) numVerticesIn );
325330

326331
vertIdx++;
327332
} else {
@@ -356,7 +361,7 @@ void MergeDuplicateVertices( bspSurface_t** rendererSurfaces, int numSurfaces, s
356361
}
357362
} */
358363

359-
std::vector<MaterialSurface> OptimiseMapGeometryMaterial( world_t* world, int numSurfaces ) {
364+
std::vector<MaterialSurface> OptimiseMapGeometryMaterial(bspSurface_t** rendererSurfaces, int numSurfaces ) {
360365
std::vector<MaterialSurface> materialSurfaces;
361366
materialSurfaces.reserve( numSurfaces );
362367

@@ -365,24 +370,46 @@ std::vector<MaterialSurface> OptimiseMapGeometryMaterial( world_t* world, int nu
365370

366371
// std::unordered_map<TriEdge, TriIndex> triEdges;
367372

368-
int surfaceIndex = 0;
369-
for ( int k = 0; k < world->numSurfaces; k++ ) {
370-
bspSurface_t* surface = &world->surfaces[k];
373+
vec3_t worldBounds[2] = {};
374+
for ( int i = 0; i < numSurfaces; i++ ) {
375+
bspSurface_t* surface = rendererSurfaces[i];
376+
377+
if ( surface->BSPModel ) {
378+
// Not implemented yet
379+
continue;
380+
}
371381

372382
MaterialSurface srf {};
373383

374384
srf.shader = surface->shader;
385+
375386
srf.bspSurface = true;
387+
srf.skyBrush = surface->skyBrush;
388+
389+
srf.lightMapNum = surface->lightmapNum;
376390
srf.fog = surface->fogIndex;
391+
srf.portalNum = surface->portalNum;
377392

378393
srf.firstIndex = ( ( srfGeneric_t* ) surface->data )->firstIndex;
379-
srf.count = ( ( srfGeneric_t* ) surface->data )->numTriangles;
394+
srf.count = ( ( srfGeneric_t* ) surface->data )->numTriangles * 3;
380395
srf.verts = ( ( srfGeneric_t* ) surface->data )->verts;
381396
srf.tris = ( ( srfGeneric_t* ) surface->data )->triangles;
382397

398+
VectorCopy( ( ( srfGeneric_t* ) surface->data )->origin, srf.origin );
399+
srf.radius = ( ( srfGeneric_t* ) surface->data )->radius;
400+
401+
BoundsAdd( worldBounds[0], worldBounds[1],
402+
( ( srfGeneric_t* ) surface->data )->bounds[0], ( ( srfGeneric_t* ) surface->data )->bounds[1] );
403+
404+
materialSystem.GenerateMaterial( &srf );
405+
383406
materialSurfaces.emplace_back( srf );
384-
surfaceIndex++;
385407
}
386408

409+
materialSystem.GenerateWorldMaterialsBuffer();
410+
materialSystem.GeneratePortalBoundingSpheres();
411+
materialSystem.SetWorldBounds( worldBounds );
412+
materialSystem.GenerateWorldCommandBuffer( materialSurfaces );
413+
387414
return materialSurfaces;
388415
}

src/engine/renderer/GeometryOptimiser.h

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,12 @@ struct TriIndex {
6868

6969
struct MapVertHasher {
7070
size_t operator()( const srfVert_t& vert ) const {
71-
size_t hash = ~( *( ( size_t* ) &vert.xyz[0] ) << 15 );
72-
hash ^= ( *( ( size_t* ) &vert.xyz[0] ) >> 10 );
73-
hash += ( *( ( size_t* ) &vert.xyz[1] ) << 3 );
74-
hash ^= ( *( ( size_t* ) &vert.xyz[1] ) >> 6 );
75-
hash += ~( *( ( size_t* ) &vert.xyz[2] ) << 11 );
76-
hash ^= ( *( ( size_t* ) &vert.xyz[2] ) >> 16 );
77-
78-
hash ^= ( *( ( size_t* ) &vert.st[0] ) << 7 );
79-
hash += ( *( ( size_t* ) &vert.st[0] ) >> 12 );
80-
81-
hash ^= ( *( ( size_t* ) &vert.st[1] ) << 13 );
82-
hash += ( *( ( size_t* ) &vert.st[1] ) >> 8 );
71+
uint32_t hash = ~( Util::bit_cast<uint32_t, float>( vert.xyz[0] ) << 15 );
72+
hash ^= ( Util::bit_cast<uint32_t, float>( vert.xyz[0] ) >> 10 );
73+
hash += ( Util::bit_cast<uint32_t, float>( vert.xyz[1] ) << 3 );
74+
hash ^= ( Util::bit_cast<uint32_t, float>( vert.xyz[1] ) >> 6 );
75+
hash += ( Util::bit_cast<uint32_t, float>( vert.xyz[2] ) << 11 );
76+
hash ^= ( Util::bit_cast<uint32_t, float>( vert.xyz[2] ) >> 16 );
8377

8478
return hash;
8579
}
@@ -98,14 +92,15 @@ struct MapVertEqual {
9892
&& VectorCompareEpsilon( lhs.normal, rhs.normal, 0.0001f )
9993
&& CompareEpsilon( lhs.qtangent[0], rhs.qtangent[0] ) && CompareEpsilon( lhs.qtangent[1], rhs.qtangent[1] )
10094
&& CompareEpsilon( lhs.qtangent[2], rhs.qtangent[2] ) && CompareEpsilon( lhs.qtangent[3], rhs.qtangent[3] )
101-
&& lhs.lightColor.ArrayBytes() == rhs.lightColor.ArrayBytes();
95+
&& lhs.lightColor.Red() == rhs.lightColor.Red() && lhs.lightColor.Green() == rhs.lightColor.Green()
96+
&& lhs.lightColor.Blue() == rhs.lightColor.Blue() && lhs.lightColor.Alpha() == rhs.lightColor.Alpha();
10297
}
10398
};
10499

105100
void OptimiseMapGeometryCore( world_t* world, bspSurface_t** rendererSurfaces, int numSurfaces );
106101
void MergeLeafSurfacesCore( world_t* world, bspSurface_t** rendererSurfaces, int numSurfaces );
107102
void MergeDuplicateVertices( bspSurface_t** rendererSurfaces, int numSurfaces, srfVert_t* vertices, int numVerticesIn,
108103
glIndex_t* indices, int numIndicesIn, int& numVerticesOut, int& numIndicesOut );
109-
std::vector<MaterialSurface> OptimiseMapGeometryMaterial( world_t* world, int numSurfaces );
104+
std::vector<MaterialSurface> OptimiseMapGeometryMaterial( bspSurface_t** rendererSurfaces, int numSurfaces );
110105

111106
#endif // GEOMETRY_OPTIMISER_H

0 commit comments

Comments
 (0)