Returns the number of faces that are approximately within the specified radius
| 2051 | |
| 2052 | // Returns the number of faces that are approximately within the specified radius |
| 2053 | int fvi_QuickDistCellList(int init_cell_index, vector *pos, float rad, int *quick_cell_list, int max_elements) { |
| 2054 | int num_cells = 0; |
| 2055 | int next_y_delta; |
| 2056 | int xstart, xend, ystart, yend; |
| 2057 | int check_x, check_y; |
| 2058 | int xcounter, ycounter; |
| 2059 | int cur_node; |
| 2060 | |
| 2061 | ASSERT(quick_cell_list != nullptr); |
| 2062 | ASSERT(pos != nullptr); |
| 2063 | ASSERT(init_cell_index >= 0 && init_cell_index < TERRAIN_WIDTH * TERRAIN_DEPTH); |
| 2064 | ASSERT(rad >= 0.0f); |
| 2065 | |
| 2066 | cur_node = init_cell_index; |
| 2067 | |
| 2068 | // Check worst-case collisions. This includes all nodes within a radius edge of the current node |
| 2069 | check_x = rad / TERRAIN_SIZE + 1; |
| 2070 | check_y = rad / TERRAIN_SIZE + 1; |
| 2071 | |
| 2072 | xstart = cur_node % TERRAIN_WIDTH - check_x; |
| 2073 | xend = cur_node % TERRAIN_WIDTH + check_x; |
| 2074 | ystart = cur_node / TERRAIN_WIDTH - check_y; |
| 2075 | yend = cur_node / TERRAIN_WIDTH + check_y; |
| 2076 | |
| 2077 | if (xstart < 0) |
| 2078 | xstart = 0; |
| 2079 | if (xend >= TERRAIN_WIDTH) |
| 2080 | xend = TERRAIN_WIDTH - 1; |
| 2081 | if (ystart < 0) |
| 2082 | ystart = 0; |
| 2083 | if (yend >= TERRAIN_DEPTH) |
| 2084 | yend = TERRAIN_DEPTH - 1; |
| 2085 | |
| 2086 | // This should be a faster interative why to do a square with center at original position |
| 2087 | cur_node = TERRAIN_WIDTH * ystart + xstart; |
| 2088 | next_y_delta = TERRAIN_WIDTH - (xend - xstart) - 1; |
| 2089 | |
| 2090 | for (ycounter = ystart; ycounter <= yend; ycounter++) { |
| 2091 | for (xcounter = xstart; xcounter <= xend; xcounter++) { |
| 2092 | if ((Terrain_seg[cur_node].y >= pos->y - rad) || (Terrain_seg[cur_node + TERRAIN_WIDTH + 1].y >= pos->y - rad) || |
| 2093 | (Terrain_seg[cur_node + 1].y >= pos->y - rad) || (Terrain_seg[cur_node + TERRAIN_WIDTH].y >= pos->y - rad)) { |
| 2094 | quick_cell_list[num_cells++] = cur_node; |
| 2095 | if (num_cells >= max_elements) |
| 2096 | break; |
| 2097 | } |
| 2098 | cur_node += 1; |
| 2099 | } |
| 2100 | if (num_cells >= max_elements) |
| 2101 | break; |
| 2102 | cur_node += next_y_delta; |
| 2103 | } |
| 2104 | |
| 2105 | return num_cells; |
| 2106 | } |
| 2107 | |
| 2108 | int fvi_QuickDistObjectList(vector *pos, int init_room_index, float rad, int16_t *object_index_list, int max_elements, |
| 2109 | bool f_lightmap_only, bool f_only_players_and_ais, bool f_include_non_collide_objects, |
no outgoing calls
no test coverage detected