Random epic tweaks (#568)

* various tweaks to tackle redundancy

* Update collision.inc.c

* inline the function

* fix surface denorms

* oops forgot to remove a comment that I just proved false lol

* stack asserts

* Update main.c

* Update main.c

* fix bug plural s

* Update main.c

* comment
This commit is contained in:
Fazana
2023-01-24 02:13:49 +00:00
committed by GitHub
parent dc71aef024
commit 35dffd9b4e
9 changed files with 93 additions and 31 deletions

View File

@@ -119,7 +119,6 @@ static void clear_static_surfaces(void) {
*/
static void add_surface_to_cell(s32 dynamic, s32 cellX, s32 cellZ, struct Surface *surface) {
struct SurfaceNode *list;
s32 priority;
s32 sortDir = 1; // highest to lowest, then insertion order (water and floors)
s32 listIndex;
@@ -135,7 +134,6 @@ static void add_surface_to_cell(s32 dynamic, s32 cellX, s32 cellZ, struct Surfac
sortDir = 0; // insertion order
}
s32 surfacePriority = surface->upperY * sortDir;
struct SurfaceNode *newNode = alloc_surface_node(dynamic);
newNode->surface = surface;
@@ -157,14 +155,18 @@ static void add_surface_to_cell(s32 dynamic, s32 cellX, s32 cellZ, struct Surfac
}
// Loop until we find the appropriate place for the surface in the list.
while (list->next != NULL) {
priority = list->next->surface->upperY * sortDir;
if (listIndex == SPATIAL_PARTITION_WATER) {
s32 surfacePriority = surface->upperY * sortDir;
s32 priority;
while (list->next != NULL) {
priority = list->next->surface->upperY * sortDir;
if (surfacePriority > priority) {
break;
if (surfacePriority > priority) {
break;
}
list = list->next;
}
list = list->next;
}
newNode->next = list->next;
@@ -269,7 +271,15 @@ static struct Surface *read_surface_data(TerrainData *vertexData, TerrainData **
find_vector_perpendicular_to_plane(n, v[0], v[1], v[2]);
vec3f_normalize(n);
f32 mag = (sqr(n[0]) + sqr(n[1]) + sqr(n[2]));
// This will never need to be run for custom levels because Fast64 does this step before exporting.
#ifdef ENABLE_VANILLA_LEVEL_SPECIFIC_CHECKS
if (mag < NEAR_ZERO) {
return NULL;
}
#endif
mag = 1.0f / sqrtf(mag);
vec3_mul_val(n, mag);
struct Surface *surface = alloc_surface(dynamic);