View Issue Details

IDProjectCategoryView StatusLast Update
0006480The Dark ModCodingpublic04.03.2024 22:12
Reporterstgatilov Assigned Tostgatilov  
PrioritynormalSeveritynormalReproducibilitysometimes
Status resolvedResolutionfixed 
Product VersionTDM 1.00 
Target VersionTDM 2.13Fixed in VersionTDM 2.13 
Summary0006480: Dmap rounds all floats in .proc file to integers
DescriptionSee WriteFloat in output.cpp:

static void WriteFloat( idFile *f, float v )
{
    if ( idMath::Fabs(v - idMath::Round(v)) < 0.001 ) {
        f->WriteFloatString( "%i ", (int)idMath::Round(v) );
    }
    else {
        f->WriteFloatString( "%f ", v );
    }
}

This adds up to 1e-3 error into almost axis-aligned planes, which can result in all kind of issues.

For instance, on Dragon's claw there is a visportal which does not match the BSP plane "corrected" by this code.
As the result, if player stands almost perfectly on the portal, he does not see left half of the world.
Steps To Reproduce1) Select Dragon's claw mission.
2) Start game
3) Execute: noclip
4) Execute: setviewpos 207 -1212 -408
5) See that half of the world is missing, and it returns if you move slightly left or right.
Additional InformationOriginally reported here:
  https://forums.thedarkmod.com/index.php?/topic/22294-beta-testing-212/&do=findComment&comment=492051
TagsNo tags attached.

Activities

stgatilov

stgatilov

07.02.2024 20:34

administrator   ~0016485

=== Copying from https://forums.thedarkmod.com/index.php?/topic/22294-beta-testing-212/&do=findComment&comment=492057:

I looked closer at the problem in Dragon's Claw, and this is caused by some kind of precision issue in dmap.

The .proc file contains imprecise BSP plane:
    /* node 18377 */ ( 0.0399680398 1 0 1202.8780517578 ) -38 18378

And also there is a visportal stored there:
    /* iap 62 */ 4 37 50 ( -96 -1200 -488 ) ( 304 -1216 -488 ) ( 304 -1216 300 ) ( -96 -1200 300 )
The game loads the visportal polygon and computes portal plane from it, which is:
    plane (a=-0.0399680398, b=-0.999200940, c=0.00000000, d=-1202.87805)

As you see, the plane normals are different by 0.2%.
The visportal plane computed from polygon is almost perfectly unit, but the BSP plane is not unit (length slightly greater than unit).
This makes the game think it is on the left of visportal in one place, but on the right of visportal in another place.

I tried to re-dmap but the data is the same.
stgatilov

stgatilov

07.02.2024 20:35

administrator   ~0016486

Screenshot by @thebigh.
stgatilov

stgatilov

08.02.2024 19:16

administrator   ~0016491

Here is the fix.
To be tested and committed after 2.12 is over.
dmap_6480.patch (2,859 bytes)   
Index: tools/compilers/dmap/dmap.cpp
===================================================================
--- tools/compilers/dmap/dmap.cpp	(revision 10635)
+++ tools/compilers/dmap/dmap.cpp	(working copy)
@@ -320,6 +320,8 @@
 		extern idCVar dmap_tjunctionsAlgorithm;
 		dmap_aasExpandBrushUseEdgesOnce.SetBool(version >= 211);
 		dmap_tjunctionsAlgorithm.SetBool(version >= 211);
+		//new in 2.13
+		dmap_outputNoSnap.SetBool(version >= 213);
 	}
 
 	if ( args.Argc() < 2 ) {
Index: tools/compilers/dmap/dmap.h
===================================================================
--- tools/compilers/dmap/dmap.h	(revision 10635)
+++ tools/compilers/dmap/dmap.h	(working copy)
@@ -34,6 +34,8 @@
 extern idCVar dmap_pruneAasBrushesChopping;
 extern idCVar dmap_fasterAasWaterJumpReachability;
 extern idCVar dmap_disableCellSnappingTjunc;
+//TDM 2.13:
+extern idCVar dmap_outputNoSnap;
 
 
 typedef struct primitive_s {
Index: tools/compilers/dmap/facebsp.cpp
===================================================================
--- tools/compilers/dmap/facebsp.cpp	(revision 10635)
+++ tools/compilers/dmap/facebsp.cpp	(working copy)
@@ -341,6 +341,9 @@
 
 	// split the bounds if we have a nice axial plane
 	for ( i = 0 ; i < 3 ; i++ ) {
+		// stgatilov: these bounds are only used in this function
+		// they are overwritten in CalcNodeBounds later
+		// so it is OK that they are not precise
 		if ( idMath::Fabs( plane[i] - 1.0 ) < 0.001 ) {
 			node->children[0]->bounds[0][i] = plane.Dist();
 			node->children[1]->bounds[1][i] = plane.Dist();
Index: tools/compilers/dmap/output.cpp
===================================================================
--- tools/compilers/dmap/output.cpp	(revision 10635)
+++ tools/compilers/dmap/output.cpp	(working copy)
@@ -26,6 +26,7 @@
 #if 0
 
 should we try and snap values very close to 0.5, 0.25, 0.125, etc?
+stgatilov #6480: please no!
 
   do we write out normals, or just a "smooth shade" flag?
 resolved: normals.  otherwise adjacent facet shaded surfaces get their
@@ -77,9 +78,15 @@
 	return a1;
 }
 
+idCVar dmap_outputNoSnap(
+	"dmap_outputNoSnap", "1", CVAR_BOOL | CVAR_SYSTEM,
+	"Disables weird snapping of all floats to integers in output. "
+	"This is stability fix for TDM 2.13 (#6480)."
+);
+
 static void WriteFloat( idFile *f, float v )
 {
-	if ( idMath::Fabs(v - idMath::Round(v)) < 0.001 ) {
+	if ( dmap_outputNoSnap.GetBool() ? v == idMath::Round(v) : idMath::Fabs(v - idMath::Round(v)) < 0.001 ) {
 		f->WriteFloatString( "%i ", (int)idMath::Round(v) );
 	}
 	else {
@@ -353,7 +360,9 @@
 	// verts
 	col = 0;
 	for ( i = 0 ; i < tri->numVerts ; i++ ) {
-		Write1DMatrix( procFile, 3, &tri->shadowVertexes[i].xyz[0] );
+		idVec4 pos = tri->shadowVertexes[i].xyz;
+		assert( pos.w == 1.0f );
+		Write1DMatrix( procFile, 3, &pos[0] );
 
 		if ( ++col == 5 ) {
 			col = 0;
dmap_6480.patch (2,859 bytes)   
stgatilov

stgatilov

17.02.2024 12:36

administrator   ~0016517

Supposedly it happens in "Return to the City" at 274.26 -1039.08 184.71 too:
  https://forums.thedarkmod.com/index.php?/topic/22294-beta-testing-212/&do=findComment&comment=492350
stgatilov

stgatilov

04.03.2024 22:12

administrator   ~0016560

Fixed in svn rev 10654.
Checked both missions: the issues go away after re-dmapping.

Issue History

Date Modified Username Field Change
07.02.2024 20:33 stgatilov New Issue
07.02.2024 20:33 stgatilov Status new => assigned
07.02.2024 20:33 stgatilov Assigned To => stgatilov
07.02.2024 20:33 stgatilov Additional Information Updated
07.02.2024 20:34 stgatilov Note Added: 0016485
07.02.2024 20:35 stgatilov Note Added: 0016486
07.02.2024 20:35 stgatilov File Added: claw1_31(2024-02-0718-41-29)(183.68-1210.86-418.81).jpg.3cd6e86a86f5e764ca2c4af36ee24316.jpg
08.02.2024 19:16 stgatilov Note Added: 0016491
08.02.2024 19:16 stgatilov File Added: dmap_6480.patch
17.02.2024 12:36 stgatilov Note Added: 0016517
04.03.2024 22:12 stgatilov Note Added: 0016560
04.03.2024 22:12 stgatilov Status assigned => resolved
04.03.2024 22:12 stgatilov Resolution open => fixed
04.03.2024 22:12 stgatilov Fixed in Version => TDM 2.13