Exemplo n.º 1
0
void obj_quicksort_colliders(SCP_vector<int> *list, int left, int right, int axis)
{
	Assert( axis >= 0 );
	Assert( axis <= 2 );

	if ( right > left ) {
		int pivot_index = left + (right - left) / 2;

		float pivot_value = obj_get_collider_endpoint((*list)[pivot_index], axis, true);

		// swap!
		int temp = (*list)[pivot_index];
		(*list)[pivot_index] = (*list)[right];
		(*list)[right] = temp;

		int store_index = left;

		int i;
		for ( i = left; i < right; ++i ) {
			if ( obj_get_collider_endpoint((*list)[i], axis, true) <= pivot_value ) {
				temp = (*list)[i];
				(*list)[i] = (*list)[store_index];
				(*list)[store_index] = temp;
				store_index++;
			}
		}

		temp = (*list)[right];
		(*list)[right] = (*list)[store_index];
		(*list)[store_index] = temp;

		obj_quicksort_colliders(list, left, store_index - 1, axis);
		obj_quicksort_colliders(list, store_index + 1, right, axis);
	}
}
Exemplo n.º 2
0
void obj_sort_and_collide()
{
	if (Cmdline_dis_collisions)
		return;

	if ( !(Game_detail_flags & DETAIL_FLAG_COLLISION) )
		return;

	SCP_vector<int> sort_list_y;
	SCP_vector<int> sort_list_z;

	sort_list_y.clear();
	{
		TRACE_SCOPE(tracing::SortColliders);
		obj_quicksort_colliders(&Collision_sort_list, 0, (int)(Collision_sort_list.size() - 1), 0);
	}
	obj_find_overlap_colliders(&sort_list_y, &Collision_sort_list, 0, false);

	sort_list_z.clear();
	{
		TRACE_SCOPE(tracing::SortColliders);
		obj_quicksort_colliders(&sort_list_y, 0, (int)(sort_list_y.size() - 1), 1);
	}
	obj_find_overlap_colliders(&sort_list_z, &sort_list_y, 1, false);

	sort_list_y.clear();
	{
		TRACE_SCOPE(tracing::SortColliders);
		obj_quicksort_colliders(&sort_list_z, 0, (int)(sort_list_z.size() - 1), 2);
	}
	obj_find_overlap_colliders(&sort_list_y, &sort_list_z, 2, true);
}