diff --git a/src/engine/surface_load.c b/src/engine/surface_load.c index 8f2e31a6..d3753755 100644 --- a/src/engine/surface_load.c +++ b/src/engine/surface_load.c @@ -120,6 +120,7 @@ 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,6 +136,7 @@ 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; @@ -156,18 +158,14 @@ 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. - if (listIndex == SPATIAL_PARTITION_WATER) { - s32 surfacePriority = surface->upperY * sortDir; - s32 priority; - while (list->next != NULL) { - priority = list->next->surface->upperY * sortDir; + while (list->next != NULL) { + priority = list->next->surface->upperY * sortDir; - if (surfacePriority > priority) { - break; - } - - list = list->next; + if (surfacePriority > priority) { + break; } + + list = list->next; } newNode->next = list->next;