/*
 * Copyright (c) 2008-2009 Bill Whitacre http://rampancy.g0dsoft.com
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
*/

#ifndef RAT_PHYSICS_ARBITER
#define RAT_PHYSICS_ARBITER

#include "common.h"
#include "body.h"
#include "vector.h"
#include "contact.h"

typedef struct rat_arbiter
{
	rat_body *body_a;
	rat_body *body_b;

	int island_marker;

	rat_real netfriction;
	rat_contact_array *contacts;
	unsigned int stamped;

	rat_block_allocator *bal;
} rat_arbiter;

#ifdef __cplusplus
extern "C" {
#endif

rat_arbiter *rat_arbiter_create(rat_block_allocator *bal,rat_body *body_a,rat_body *body_b,rat_contact_array *contacts);
void rat_arbiter_destroy(rat_arbiter *arbiter);

void rat_arbiter_update_contacts(rat_arbiter *arbiter,rat_contact_array *new_contacts);
void rat_arbiter_prime(rat_arbiter *arbiter,rat_real bias_coef);
void rat_arbiter_step_cached(rat_arbiter *arbiter);
void rat_arbiter_step_solver(rat_arbiter *arbiter,rat_real restitution);


// to be used internally by world

// by default 0.1
void rat_arbiter_global_set_slop(rat_real slop);
rat_real rat_arbiter_global_get_slop();

// by default enabled
void rat_arbiter_global_split_impulse(int enable);
int rat_arbiter_global_split_impulse_enabled();

// by default enabled
void rat_arbiter_global_warm_starting(int enable);
int rat_arbiter_global_warm_starting_enabled();


#ifdef __cplusplus
};
#endif

#endif
