Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // IMPORTANT VARIABLE DECLARATIONS:
- #define SPATIAL_PARTITION_DYNAMIC 3
- typedef struct SurfaceNode SpatialPartitionCell[4];
- extern SpatialPartitionCell gStaticSurfacePartition[16][16];
- extern SpatialPartitionCell gDynamicSurfacePartition[16][16];
- extern struct SurfaceNode *sSurfaceNodePool;
- extern struct Surface *sSurfacePool;
- extern s16 sSurfacePoolSize;
- static void add_surface_to_cell(s16 dynamic, s16 cellX, s16 cellZ, struct Surface *surface) {
- struct SurfaceNode *newNode = alloc_surface_node();
- struct SurfaceNode *newDynNode = alloc_surface_node();
- struct SurfaceNode *list;
- struct SurfaceNode *dynList;
- s16 surfacePriority;
- s16 priority;
- s16 sortDir;
- s16 listIndex;
- s16 floorOrCeiling = 0;
- if (surface->normal.y > 0.01) {
- listIndex = SPATIAL_PARTITION_FLOORS;
- sortDir = 1; // highest to lowest, then insertion order
- floorOrCeiling = 1;
- } else if (surface->normal.y < -0.01) {
- listIndex = SPATIAL_PARTITION_CEILS;
- sortDir = -1; // lowest to highest, then insertion order
- floorOrCeiling = 1;
- } else {
- listIndex = SPATIAL_PARTITION_WALLS;
- sortDir = 0; // insertion order
- if (surface->normal.x < -0.707 || surface->normal.x > 0.707) {
- surface->flags |= SURFACE_FLAG_X_PROJECTION;
- }
- }
- //! (Surface Cucking) Surfaces are sorted by the height of their first
- // vertex. Since vertices aren't ordered by height, this causes many
- // lower triangles to be sorted higher. This worsens surface cucking since
- // many functions only use the first triangle in surface order that fits,
- // missing higher surfaces.
- // upperY would be a better sort method.
- surfacePriority = surface->vertex1[1] * sortDir;
- newNode->surface = surface;
- newDynNode->surface = surface;
- if (dynamic) {
- list = &gDynamicSurfacePartition[cellZ][cellX][listIndex];
- if (floorOrCeiling)
- dynList = &gDynamicSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_DYNAMIC];
- } else {
- list = &gStaticSurfacePartition[cellZ][cellX][listIndex];
- if (floorOrCeiling)
- dynList = &gStaticSurfacePartition[cellZ][cellX][SPATIAL_PARTITION_DYNAMIC];
- }
- // Loop until we find the appropriate place for the surface in the list.
- while (list->next != NULL) {
- priority = list->next->surface->vertex1[1] * sortDir;
- if (surfacePriority > priority) {
- break;
- }
- list = list->next;
- }
- while (dynList->next != NULL) {
- priority = dynList->next->surface->vertex1[1] * sortDir;
- if (surfacePriority > priority) {
- break;
- }
- dynList = dynList->next;
- }
- newNode->next = list->next;
- list->next = newNode;
- newDynNode->next = dynList->next;
- dynList->next = newDynNode;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement