Continue pruning tris
This commit is contained in:
		
							parent
							
								
									2d99091cf1
								
							
						
					
					
						commit
						34cfa9adac
					
				
					 3 changed files with 130 additions and 9 deletions
				
			
		
							
								
								
									
										4
									
								
								assets.h
									
										
									
									
									
								
							
							
						
						
									
										4
									
								
								assets.h
									
										
									
									
									
								
							|  | @ -15,9 +15,7 @@ static const uint8_t map1[] = | ||||||
|     0, |     0, | ||||||
|     LCR_MAP_BLOCK(LCR_BLOCK_FULL,32,32,32,LCR_BLOCK_MATERIAL_CONCRETE,0), |     LCR_MAP_BLOCK(LCR_BLOCK_FULL,32,32,32,LCR_BLOCK_MATERIAL_CONCRETE,0), | ||||||
|     LCR_MAP_BLOCK(LCR_BLOCK_FULL,33,32,32,LCR_BLOCK_MATERIAL_CONCRETE,0), |     LCR_MAP_BLOCK(LCR_BLOCK_FULL,33,32,32,LCR_BLOCK_MATERIAL_CONCRETE,0), | ||||||
| 
 |     LCR_MAP_BLOCK(LCR_BLOCK_RAMP_CURVED_WALL,34,32,32,LCR_BLOCK_MATERIAL_CONCRETE,/*LCR_BLOCK_TRANSFORM_ROT_90*/0), | ||||||
|     LCR_MAP_BLOCK(LCR_BLOCK_RAMP_CURVED_WALL,34,32,32,LCR_BLOCK_MATERIAL_CONCRETE,LCR_BLOCK_TRANSFORM_ROT_90), |  | ||||||
|   |  | ||||||
|     LCR_MAP_BLOCK(LCR_BLOCK_FULL,32,33,32,LCR_BLOCK_MATERIAL_CONCRETE,0), |     LCR_MAP_BLOCK(LCR_BLOCK_FULL,32,33,32,LCR_BLOCK_MATERIAL_CONCRETE,0), | ||||||
|     LCR_MAP_BLOCK(LCR_BLOCK_FULL,33,33,32,LCR_BLOCK_MATERIAL_CONCRETE,0), |     LCR_MAP_BLOCK(LCR_BLOCK_FULL,33,33,32,LCR_BLOCK_MATERIAL_CONCRETE,0), | ||||||
|     LCR_MAP_BLOCK(LCR_BLOCK_FULL,32,33,33,LCR_BLOCK_MATERIAL_CONCRETE,0), |     LCR_MAP_BLOCK(LCR_BLOCK_FULL,32,33,33,LCR_BLOCK_MATERIAL_CONCRETE,0), | ||||||
|  |  | ||||||
							
								
								
									
										2
									
								
								make.sh
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								make.sh
									
										
									
									
									
								
							|  | @ -3,5 +3,5 @@ | ||||||
| clear | clear | ||||||
| clear | clear | ||||||
| 
 | 
 | ||||||
| gcc -std=c99 -Wall -Wextra -pedantic -O3 -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers `sdl2-config --libs --static-libs` -o game main_sdl.c && ./game | gcc -std=c99 -g -Wall -Wextra -pedantic -O1 -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers `sdl2-config --libs --static-libs` -o game frontend_sdl.c && ./game | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										131
									
								
								renderer.h
									
										
									
									
									
								
							
							
						
						
									
										131
									
								
								renderer.h
									
										
									
									
									
								
							|  | @ -102,11 +102,137 @@ uint8_t _LCR_rendererCheckMapTriangleCover(const S3L_Index *t1, | ||||||
|   if ((t1[0] == t2[0] || t1[0] == t2[1] || t1[0] == t2[2]) && |   if ((t1[0] == t2[0] || t1[0] == t2[1] || t1[0] == t2[2]) && | ||||||
|     (t1[1] == t2[0] || t1[1] == t2[1] || t1[1] == t2[2]) && |     (t1[1] == t2[0] || t1[1] == t2[1] || t1[1] == t2[2]) && | ||||||
|     (t1[2] == t2[0] || t1[2] == t2[1] || t1[2] == t2[2])) |     (t1[2] == t2[0] || t1[2] == t2[1] || t1[2] == t2[2])) | ||||||
|     return 0x03; // same indices => both are covered
 |     return 0x03; | ||||||
| 
 | 
 | ||||||
|  |   uint8_t result = 0; | ||||||
|  |   int plane = -1; | ||||||
|  | 
 | ||||||
|  |   for (int i = 0; i < 3; ++i) | ||||||
|  |     if (LCR_mapVertices[3 * t1[0] + i] == LCR_mapVertices[3 * t1[1] + i] && | ||||||
|  |         LCR_mapVertices[3 * t1[1] + i] == LCR_mapVertices[3 * t1[2] + i] && | ||||||
|  |         LCR_mapVertices[3 * t1[2] + i] == LCR_mapVertices[3 * t2[0] + i] && | ||||||
|  |         LCR_mapVertices[3 * t2[0] + i] == LCR_mapVertices[3 * t2[1] + i] && | ||||||
|  |         LCR_mapVertices[3 * t2[1] + i] == LCR_mapVertices[3 * t2[2] + i]) | ||||||
|  |     { | ||||||
|  |       plane = i; | ||||||
|  |       break; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |   if (plane >= 0) // both triangles in the same plane => then do more checks
 | ||||||
|  |   { | ||||||
|  |     for (int j = 0; j < 2; ++j) | ||||||
|  |     { | ||||||
|  |       S3L_Unit points2D[14]; // tri1, quad (tri2 + 1 extra vert)
 | ||||||
|  | 
 | ||||||
|  |       int coordX = plane == 0 ? 1 : 0, | ||||||
|  |           coordY = plane == 2 ? 1 : 2; | ||||||
|  | 
 | ||||||
|  |       for (int i = 0; i < 3; ++i) | ||||||
|  |       { | ||||||
|  |         points2D[i * 2]         = LCR_mapVertices[3 * t1[i] + coordX]; | ||||||
|  |         points2D[i * 2 + 1]     = LCR_mapVertices[3 * t1[i] + coordY]; | ||||||
|  |         points2D[6 + i * 2]     = LCR_mapVertices[3 * t2[i] + coordX]; | ||||||
|  |         points2D[6 + i * 2 + 1] = LCR_mapVertices[3 * t2[i] + coordY]; | ||||||
|  |       } | ||||||
|  | 
 | ||||||
|  |       points2D[12] = (4 * points2D[6] + 3 * points2D[8] + points2D[10]) / 8; | ||||||
|  |       points2D[13] = (4 * points2D[7] + 3 * points2D[9] + points2D[11]) / 8; | ||||||
|  | 
 | ||||||
|  |       // first: does the triangle alone cover the other one?
 | ||||||
|  |       if (_LCR_quadCoversTriangle(points2D + 6,points2D)) | ||||||
|  |         result |= 1 << j; | ||||||
|  |       else | ||||||
|  |       { | ||||||
|  |         // now check if this triangle along with a neighbor cover the other one
 | ||||||
|  | 
 | ||||||
|  |         S3L_Index *t3 = LCR_mapTriangles; | ||||||
|  | 
 | ||||||
|  |         for (int i = 0; i < LCR_mapModel->triangleCount; ++i) | ||||||
|  |         { | ||||||
|  |           uint8_t sharedVerts = | ||||||
|  |             (t3[0] == t2[0] || t3[0] == t2[1] || t3[0] == t2[2]) | | ||||||
|  |             ((t3[1] == t2[0] || t3[1] == t2[1] || t3[1] == t2[2]) << 1) | | ||||||
|  |             ((t3[2] == t2[0] || t3[2] == t2[1] || t3[2] == t2[2]) << 2); | ||||||
|  | 
 | ||||||
|  |           if ( | ||||||
|  |             t3 != t1 && t3 != t2 && | ||||||
|  |             (sharedVerts == 3 || sharedVerts == 5 || sharedVerts == 6) && | ||||||
|  |             LCR_mapVertices[3 * t3[0] + plane] == | ||||||
|  |             LCR_mapVertices[3 * t3[1] + plane] && | ||||||
|  |             LCR_mapVertices[3 * t3[1] + plane] == | ||||||
|  |             LCR_mapVertices[3 * t3[2] + plane] && | ||||||
|  |             LCR_mapVertices[3 * t3[0] + plane] == | ||||||
|  |             LCR_mapVertices[3 * t1[0] + plane] | ||||||
|  |             ) | ||||||
|  |           { | ||||||
|  |             // here shares exactly two vertices and is in the same plane
 | ||||||
|  | 
 | ||||||
|  |             uint8_t freeVert = | ||||||
|  |               sharedVerts == 3 ? 2 : (sharedVerts == 5 ? 1 : 0); | ||||||
|  | 
 | ||||||
|  |             points2D[12] = LCR_mapVertices[3 * t3[freeVert] + coordX]; | ||||||
|  |             points2D[13] = LCR_mapVertices[3 * t3[freeVert] + coordY]; | ||||||
|  |             | ||||||
|  |             if (_LCR_quadCoversTriangle(points2D + 6,points2D)) | ||||||
|  |             { | ||||||
|  |               result |= 1 << j; | ||||||
|  |               break; | ||||||
|  |             } | ||||||
|  |           } | ||||||
|  | 
 | ||||||
|  |           t3 += 3; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |       } | ||||||
|  | 
 | ||||||
|  |       const S3L_Index *tmp = t1; | ||||||
|  |       t1 = t2; | ||||||
|  |       t2 = tmp; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   return result; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | int _LCR_quadCoversTriangle(const S3L_Unit quad[8], const S3L_Unit tri[6]) | ||||||
|  | { | ||||||
|  |   for (int i = 0; i < 3; ++i) // for each triangle point
 | ||||||
|  |   { | ||||||
|  |     int covered = 0; | ||||||
|  | 
 | ||||||
|  |     for (int j = 0; j < 3; ++j) // for each quad subtriangle
 | ||||||
|  |     { | ||||||
|  |       uint8_t winds = 0; | ||||||
|  | 
 | ||||||
|  |       for (int k = 0; k < 3; ++k) // for each subtriangle side
 | ||||||
|  |       { | ||||||
|  |          S3L_Unit w = // triangle winding
 | ||||||
|  |           (quad[(2 * (j + ((k + 1) % 3))) % 8 + 1] - | ||||||
|  |             quad[(2 * (j + k)) % 8 + 1]) * | ||||||
|  |           (tri[2 * i] - quad[(2 * (j + (k + 1) % 3)) % 8]) - | ||||||
|  |           (quad[(2 * (j + ((k + 1) % 3))) % 8] - quad[(2 * (j + k)) % 8]) | ||||||
|  |           * (tri[2 * i + 1] - quad[(2 * (j + (k + 1) % 3)) % 8 + 1]); | ||||||
|  | 
 | ||||||
|  |          if (w > 0) | ||||||
|  |            winds |= 1; | ||||||
|  |          else if (w < 0) | ||||||
|  |            winds |= 2; | ||||||
|  |       } | ||||||
|  | 
 | ||||||
|  |       if (winds != 3) // no opposite winds?
 | ||||||
|  |       { | ||||||
|  |         covered = 1; | ||||||
|  |         break; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if (!covered) | ||||||
|       return 0; |       return 0; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   return 1; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| /**
 | /**
 | ||||||
|   Removes map triangles that are covered by other triangles (and also vertices |   Removes map triangles that are covered by other triangles (and also vertices | ||||||
|   that by this become unused). This makes the map model smaller, faster and |   that by this become unused). This makes the map model smaller, faster and | ||||||
|  | @ -168,8 +294,6 @@ void _LCR_rendererPruneHiddenMapTriangles(void) | ||||||
| 
 | 
 | ||||||
|   i = 0; |   i = 0; | ||||||
| 
 | 
 | ||||||
| printf("ASASA %d\n",LCR_mapModel->vertexCount); |  | ||||||
| 
 |  | ||||||
|   while (i < LCR_mapModel->vertexCount) |   while (i < LCR_mapModel->vertexCount) | ||||||
|   { |   { | ||||||
|     int used = 0; |     int used = 0; | ||||||
|  | @ -196,7 +320,6 @@ printf("ASASA %d\n",LCR_mapModel->vertexCount); | ||||||
|       LCR_mapModel->vertexCount--; |       LCR_mapModel->vertexCount--; | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| printf("ASASA %d\n",LCR_mapModel->vertexCount); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue