Clean
This commit is contained in:
		
							parent
							
								
									4cb558b85c
								
							
						
					
					
						commit
						ccbb9dfdc3
					
				
					 3 changed files with 32 additions and 78 deletions
				
			
		|  | @ -11,8 +11,6 @@ | ||||||
| #include <stdint.h> | #include <stdint.h> | ||||||
| #include "settings.h" | #include "settings.h" | ||||||
| 
 | 
 | ||||||
| // TODO: maybe move module specific constants to the modules themselves?
 |  | ||||||
| 
 |  | ||||||
| // constants (not supposed to be changed, doing so may break stuff):
 | // constants (not supposed to be changed, doing so may break stuff):
 | ||||||
| 
 | 
 | ||||||
| #define LCR_EFFECTIVE_RESOLUTION_X \ | #define LCR_EFFECTIVE_RESOLUTION_X \ | ||||||
|  |  | ||||||
							
								
								
									
										31
									
								
								racing.h
									
										
									
									
									
								
							
							
						
						
									
										31
									
								
								racing.h
									
										
									
									
									
								
							|  | @ -815,13 +815,12 @@ uint8_t _LCR_racingCollisionHandler(uint16_t b1, uint16_t j1, uint16_t b2, | ||||||
|   // Detect crashes:
 |   // Detect crashes:
 | ||||||
| 
 | 
 | ||||||
|   TPE_Unit speed = TPE_vec3Len( |   TPE_Unit speed = TPE_vec3Len( | ||||||
|       TPE_vec3Project( |     TPE_vec3Project(TPE_vec3( | ||||||
|         TPE_vec3( |       LCR_racing.carBody.joints[j1].velocity[0], | ||||||
|           LCR_racing.carBody.joints[j1].velocity[0], |         LCR_racing.carBody.joints[j1].velocity[1], | ||||||
|           LCR_racing.carBody.joints[j1].velocity[1], |         LCR_racing.carBody.joints[j1].velocity[2]), | ||||||
|           LCR_racing.carBody.joints[j1].velocity[2]), |       TPE_vec3Minus(p, | ||||||
|         TPE_vec3Minus(p, |         LCR_racing.carBody.joints[j1].position))); | ||||||
|           LCR_racing.carBody.joints[j1].position))); |  | ||||||
| 
 | 
 | ||||||
|   LCR_racing.crashState |= ((speed >= LCR_CAR_CRASH_SPEED_BIG) << 1) | |   LCR_racing.crashState |= ((speed >= LCR_CAR_CRASH_SPEED_BIG) << 1) | | ||||||
|     (speed >= LCR_CAR_CRASH_SPEED_SMALL); |     (speed >= LCR_CAR_CRASH_SPEED_SMALL); | ||||||
|  | @ -1064,18 +1063,9 @@ TPE_Unit _LCR_applyMaterialFactor(TPE_Unit value, uint8_t mat) | ||||||
| { | { | ||||||
|   switch (mat) |   switch (mat) | ||||||
|   { |   { | ||||||
|     case LCR_BLOCK_MATERIAL_GRASS: |     case LCR_BLOCK_MATERIAL_GRASS: value *= LCR_CAR_GRASS_FACTOR; break; | ||||||
|       value *= LCR_CAR_GRASS_FACTOR; |     case LCR_BLOCK_MATERIAL_DIRT:  value *= LCR_CAR_DIRT_FACTOR;  break; | ||||||
|       break; |     case LCR_BLOCK_MATERIAL_ICE:   value *= LCR_CAR_ICE_FACTOR;   break; | ||||||
| 
 |  | ||||||
|     case LCR_BLOCK_MATERIAL_DIRT: |  | ||||||
|       value *= LCR_CAR_DIRT_FACTOR; |  | ||||||
|       break; |  | ||||||
| 
 |  | ||||||
|     case LCR_BLOCK_MATERIAL_ICE: |  | ||||||
|       value *= LCR_CAR_ICE_FACTOR; |  | ||||||
|       break; |  | ||||||
| 
 |  | ||||||
|     default: value *= 8; break; |     default: value *= 8; break; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | @ -1085,8 +1075,7 @@ TPE_Unit _LCR_applyMaterialFactor(TPE_Unit value, uint8_t mat) | ||||||
| void _LCR_racingWheelAccelerate(unsigned int wheel, TPE_Vec3 dir, | void _LCR_racingWheelAccelerate(unsigned int wheel, TPE_Vec3 dir, | ||||||
|   uint8_t material, uint8_t accelerator) |   uint8_t material, uint8_t accelerator) | ||||||
| { | { | ||||||
|   TPE_Unit acc = |   TPE_Unit acc = _LCR_applyMaterialFactor(LCR_CAR_ACCELERATION,material); | ||||||
|     _LCR_applyMaterialFactor(LCR_CAR_ACCELERATION,material); |  | ||||||
| 
 | 
 | ||||||
|   acc = acc / (1 + (LCR_racingGetCarSpeedUnsigned() / LCR_CAR_AIR_FRICTION)); |   acc = acc / (1 + (LCR_racingGetCarSpeedUnsigned() / LCR_CAR_AIR_FRICTION)); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										71
									
								
								renderer.h
									
										
									
									
									
								
							
							
						
						
									
										71
									
								
								renderer.h
									
										
									
									
									
								
							|  | @ -79,11 +79,7 @@ struct | ||||||
|   S3L_Model3D models[LCR_RENDERER_MODEL_COUNT]; |   S3L_Model3D models[LCR_RENDERER_MODEL_COUNT]; | ||||||
| 
 | 
 | ||||||
|   uint32_t frame; |   uint32_t frame; | ||||||
| 
 |   uint8_t loadedChunks[8]; ///< Numbers of loaded map chunks.
 | ||||||
|   uint8_t carVisibilityDist; |  | ||||||
|   uint8_t ghostVisibilityDist; |  | ||||||
| 
 |  | ||||||
|   uint8_t loadedChunks[8]; ///< numbers of loaded map chunks
 |  | ||||||
| 
 | 
 | ||||||
|   S3L_Unit mapVerts[LCR_SETTING_MAX_MAP_VERTICES * 3]; |   S3L_Unit mapVerts[LCR_SETTING_MAX_MAP_VERTICES * 3]; | ||||||
|   S3L_Index mapTris[LCR_SETTING_MAX_MAP_TRIANGLES * 3]; |   S3L_Index mapTris[LCR_SETTING_MAX_MAP_TRIANGLES * 3]; | ||||||
|  | @ -119,7 +115,7 @@ struct | ||||||
|                                         with color stored in this variable. */ |                                         with color stored in this variable. */ | ||||||
| } LCR_renderer; | } LCR_renderer; | ||||||
| 
 | 
 | ||||||
| void _LCR_rendererSetModelTransofmr(S3L_Model3D *model, | void _LCR_rendererSetModelTransform(S3L_Model3D *model, | ||||||
|   LCR_GameUnit position[3], LCR_GameUnit rotation[3]) |   LCR_GameUnit position[3], LCR_GameUnit rotation[3]) | ||||||
| { | { | ||||||
|   model->transform.translation.x = |   model->transform.translation.x = | ||||||
|  | @ -141,31 +137,14 @@ void LCR_rendererSetCarTransform(LCR_GameUnit position[3], | ||||||
|   LCR_GameUnit rotation[3]) |   LCR_GameUnit rotation[3]) | ||||||
| { | { | ||||||
|   LCR_LOG2("setting car transform"); |   LCR_LOG2("setting car transform"); | ||||||
| 
 |   _LCR_rendererSetModelTransform(LCR_renderer.carModel,position,rotation); | ||||||
|   _LCR_rendererSetModelTransofmr(LCR_renderer.carModel,position,rotation); |  | ||||||
| /*
 |  | ||||||
|   LCR_renderer.carModel->transform.translation.x = |  | ||||||
|     (position[0] * LCR_RENDERER_UNIT) / LCR_GAME_UNIT; |  | ||||||
|   LCR_renderer.carModel->transform.translation.y = |  | ||||||
|     (position[1] * LCR_RENDERER_UNIT) / LCR_GAME_UNIT; |  | ||||||
|   LCR_renderer.carModel->transform.translation.z = |  | ||||||
|     (position[2] * LCR_RENDERER_UNIT) / LCR_GAME_UNIT; |  | ||||||
| 
 |  | ||||||
|   LCR_renderer.carModel->transform.rotation.x = S3L_wrap((rotation[0] * |  | ||||||
|     S3L_F) / LCR_GAME_UNIT,S3L_F); |  | ||||||
|   LCR_renderer.carModel->transform.rotation.y = S3L_wrap((rotation[1] * |  | ||||||
|     S3L_F) / LCR_GAME_UNIT,S3L_F); |  | ||||||
|   LCR_renderer.carModel->transform.rotation.z = S3L_wrap((rotation[2] * |  | ||||||
|     S3L_F) / LCR_GAME_UNIT,S3L_F); |  | ||||||
| */ |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void LCR_rendererSetGhostTransform(LCR_GameUnit position[3], | void LCR_rendererSetGhostTransform(LCR_GameUnit position[3], | ||||||
|   LCR_GameUnit rotation[3]) |   LCR_GameUnit rotation[3]) | ||||||
| { | { | ||||||
|   LCR_LOG2("setting ghost transform"); |   LCR_LOG2("setting ghost transform"); | ||||||
|    |   _LCR_rendererSetModelTransform(LCR_renderer.ghostModel,position,rotation); | ||||||
|   _LCR_rendererSetModelTransofmr(LCR_renderer.ghostModel,position,rotation); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void LCR_rendererSetCarVisibility(uint8_t visible) | void LCR_rendererSetCarVisibility(uint8_t visible) | ||||||
|  | @ -203,7 +182,7 @@ int LCR_rendererComputeTextWidth(const char *text, int size) | ||||||
|     r += 2 * size; |     r += 2 * size; | ||||||
| 
 | 
 | ||||||
|     if (text[1]) |     if (text[1]) | ||||||
|      r += 3 * size / 4; |       r += 3 * size / 4; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   return r + LCR_FONT_PIXEL_SIZE - 1; |   return r + LCR_FONT_PIXEL_SIZE - 1; | ||||||
|  | @ -259,7 +238,6 @@ int _LCR_rendererQuadLooksConvex(S3L_Unit quad[8]) | ||||||
| { | { | ||||||
|   S3L_Unit cx = (quad[0] + quad[2] + quad[4] + quad[6]) / 4; |   S3L_Unit cx = (quad[0] + quad[2] + quad[4] + quad[6]) / 4; | ||||||
|   S3L_Unit cy = (quad[1] + quad[3] + quad[5] + quad[7]) / 4; |   S3L_Unit cy = (quad[1] + quad[3] + quad[5] + quad[7]) / 4; | ||||||
| 
 |  | ||||||
|   S3L_Unit r = 0; |   S3L_Unit r = 0; | ||||||
| 
 | 
 | ||||||
|   for (int i = 0; i < 8; i += 2) |   for (int i = 0; i < 8; i += 2) | ||||||
|  | @ -392,8 +370,8 @@ void _LCR_pixelFunc3D(S3L_PixelInfo *pixel) | ||||||
| 
 | 
 | ||||||
|         case LCR_RENDERER_MAT_FIN: |         case LCR_RENDERER_MAT_FIN: | ||||||
|           LCR_renderer.flatAndTransparent = LCR_SETTING_FINISH_COLOR | CL; |           LCR_renderer.flatAndTransparent = LCR_SETTING_FINISH_COLOR | CL; | ||||||
| #undef CL |  | ||||||
|           break; |           break; | ||||||
|  | #undef CL | ||||||
| 
 | 
 | ||||||
|         default: |         default: | ||||||
|           LCR_loadImage(mat); |           LCR_loadImage(mat); | ||||||
|  | @ -445,6 +423,7 @@ void _LCR_pixelFunc3D(S3L_PixelInfo *pixel) | ||||||
|             LCR_renderer.triUVs[2 + i] += shiftBy; |             LCR_renderer.triUVs[2 + i] += shiftBy; | ||||||
|             LCR_renderer.triUVs[4 + i] += shiftBy; |             LCR_renderer.triUVs[4 + i] += shiftBy; | ||||||
|           } |           } | ||||||
|  | 
 | ||||||
|           break; |           break; | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  | @ -456,7 +435,7 @@ void _LCR_pixelFunc3D(S3L_PixelInfo *pixel) | ||||||
|       LCR_drawPixelXYUnsafe(pixel->x,pixel->y,LCR_renderer.flatAndTransparent); |       LCR_drawPixelXYUnsafe(pixel->x,pixel->y,LCR_renderer.flatAndTransparent); | ||||||
|     else |     else | ||||||
|       S3L_zBufferWrite(pixel->x,pixel->y,S3L_MAX_DEPTH); |       S3L_zBufferWrite(pixel->x,pixel->y,S3L_MAX_DEPTH); | ||||||
|       /* ^ Clear z-buffer if we don't draw the pixel. Without this further
 |       /* ^ Clear z-buffer if we didn't draw the pixel. Without this further
 | ||||||
|       geometry drawn later on won't be seen through transparent objects which |       geometry drawn later on won't be seen through transparent objects which | ||||||
|       looks bad. With this "fix" glitches may still appear (wrong draw order) |       looks bad. With this "fix" glitches may still appear (wrong draw order) | ||||||
|       but it generally looks better this way. */ |       but it generally looks better this way. */ | ||||||
|  | @ -571,17 +550,14 @@ int _LCR_rendererQuadCoversTri(const S3L_Unit quad[8], const S3L_Unit tri[6]) | ||||||
| 
 | 
 | ||||||
|       for (int k = 0; k < 3; ++k) // for each subtriangle side
 |       for (int k = 0; k < 3; ++k) // for each subtriangle side
 | ||||||
|       { |       { | ||||||
|          S3L_Unit w = // triangle winding
 |         S3L_Unit w = // triangle winding
 | ||||||
|           (quad[(2 * (j + ((k + 1) % 3))) % 8 + 1] - |           (quad[(2 * (j + ((k + 1) % 3))) % 8 + 1] - | ||||||
|             quad[(2 * (j + k)) % 8 + 1]) * |             quad[(2 * (j + k)) % 8 + 1]) * | ||||||
|           (tri[2 * i] - quad[(2 * (j + (k + 1) % 3)) % 8]) - |           (tri[2 * i] - quad[(2 * (j + (k + 1) % 3)) % 8]) - | ||||||
|           (quad[(2 * (j + ((k + 1) % 3))) % 8] - quad[(2 * (j + k)) % 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]); |           * (tri[2 * i + 1] - quad[(2 * (j + (k + 1) % 3)) % 8 + 1]); | ||||||
| 
 | 
 | ||||||
|          if (w > 0) |         winds |= (w > 0) | ((w < 0) << 1 ); | ||||||
|            winds |= 1; |  | ||||||
|          else if (w < 0) |  | ||||||
|            winds |= 2; |  | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       if (winds != 3) // no opposite winds?
 |       if (winds != 3) // no opposite winds?
 | ||||||
|  | @ -603,8 +579,7 @@ int _LCR_rendererQuadCoversTri(const S3L_Unit quad[8], const S3L_Unit tri[6]) | ||||||
|   other, in return values lowest bit means whether t1 is covered and the second |   other, in return values lowest bit means whether t1 is covered and the second | ||||||
|   lowest bit means whether t2 is covered. |   lowest bit means whether t2 is covered. | ||||||
| */ | */ | ||||||
| uint8_t _LCR_rendererCheckMapTriCover(const S3L_Index *t1, | uint8_t _LCR_rendererCheckMapTriCover(const S3L_Index *t1, const S3L_Index *t2) | ||||||
|   const S3L_Index *t2) |  | ||||||
| { | { | ||||||
|   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]) && | ||||||
|  | @ -748,15 +723,12 @@ void _LCR_cullHiddenMapTris(void) | ||||||
| 
 | 
 | ||||||
|       t1Covered |= cover & 0x01; |       t1Covered |= cover & 0x01; | ||||||
| 
 | 
 | ||||||
|       if (cover & 0x02) |       if ((cover & 0x02) && (j < LCR_renderer.mapModel.triangleCount - n)) | ||||||
|       { |       { | ||||||
|         if (j < LCR_renderer.mapModel.triangleCount - n) |         _LCR_rendererSwapMapTris(j, | ||||||
|         { |           LCR_renderer.mapModel.triangleCount - 1 - n); | ||||||
|           _LCR_rendererSwapMapTris(j, |  | ||||||
|             LCR_renderer.mapModel.triangleCount - 1 - n); |  | ||||||
| 
 | 
 | ||||||
|           n++; |         n++; | ||||||
|         } |  | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       t2 += 3; // check next triangle
 |       t2 += 3; // check next triangle
 | ||||||
|  | @ -764,9 +736,7 @@ void _LCR_cullHiddenMapTris(void) | ||||||
| 
 | 
 | ||||||
|     if (t1Covered) |     if (t1Covered) | ||||||
|     { |     { | ||||||
|       _LCR_rendererSwapMapTris(i, |       _LCR_rendererSwapMapTris(i,LCR_renderer.mapModel.triangleCount - 1 - n); | ||||||
|         LCR_renderer.mapModel.triangleCount - 1 - n); |  | ||||||
| 
 |  | ||||||
|       n++; |       n++; | ||||||
|       // we stay at this position because we've swapped the triangle here
 |       // we stay at this position because we've swapped the triangle here
 | ||||||
|     } |     } | ||||||
|  | @ -1195,8 +1165,7 @@ void LCR_rendererGetCameraTransform(LCR_GameUnit position[3], | ||||||
|   rotation[2] = (LCR_renderer.scene.camera.transform.rotation.z * |   rotation[2] = (LCR_renderer.scene.camera.transform.rotation.z * | ||||||
|     LCR_GAME_UNIT) / S3L_F; |     LCR_GAME_UNIT) / S3L_F; | ||||||
| 
 | 
 | ||||||
|   *fov = (LCR_renderer.scene.camera.focalLength * LCR_GAME_UNIT) |   *fov = (LCR_renderer.scene.camera.focalLength * LCR_GAME_UNIT) / S3L_F; | ||||||
|     / S3L_F; |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  | @ -1873,8 +1842,7 @@ void LCR_rendererDrawMenu(const char *tabName,const char **items, | ||||||
|     ++i; |     ++i; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   i = stripHeight +  |   i = stripHeight + (stripHeight2 - LCR_rendererComputeTextHeight(3)) / 2; | ||||||
|     (stripHeight2 - LCR_rendererComputeTextHeight(3)) / 2; |  | ||||||
| 
 | 
 | ||||||
|   for (int j = 0; j < itemCount + 1; ++j) |   for (int j = 0; j < itemCount + 1; ++j) | ||||||
|   { |   { | ||||||
|  | @ -1984,8 +1952,7 @@ void LCR_rendererDraw3D(void) | ||||||
|     { |     { | ||||||
|       carGhostVisibility |= 1; |       carGhostVisibility |= 1; | ||||||
| 
 | 
 | ||||||
|       m->config.visible = (S3L_distanceManhattan( |       m->config.visible = (S3L_distanceManhattan(m->transform.translation, | ||||||
|         m->transform.translation, |  | ||||||
|         LCR_renderer.scene.camera.transform.translation) / LCR_RENDERER_UNIT) |         LCR_renderer.scene.camera.transform.translation) / LCR_RENDERER_UNIT) | ||||||
|         <= LCR_SETTING_CAR_RENDER_DISTANCE; |         <= LCR_SETTING_CAR_RENDER_DISTANCE; | ||||||
|     } |     } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue