/* -----------------------------------------------------------------------------
	GSFramework
	Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */


		#include "automation/automation_source.h"

		using namespace GS::Automation;


//------------------------------------------------------------------------------
void				Source::Dispose(float blend)
{
	if	(!dispose)
	{
		SetWeight(0, blend);
		dispose = true;
	}
}
bool				Source::CanDispose() const
{	return asbool(dispose && (weight == 0));	}
void				Source::Update(const GS::Time &dt_time)
{
	const Time scaled_dt(dt_time * time_scale);

	// Update weight.
	if	(weight_step)
	{
		weight += weight_step * dt_time.toSec();

		if	(weight_step > 0)
		{
			if	(weight > weight_target)
			{
				weight = weight_target;
				weight_step = 0;
			}
		}
		else
		{
			if	(weight < weight_target)
			{
				weight = weight_target;
				weight_step = 0;
			}
		}
	}
	time += scaled_dt;
}
void				Source::SetWeight(float _weight, float _blend)
{
	if	(_weight < 0)
		_weight = 0;
	if	(_blend < 0)
		_blend = 0;

	if	(_blend)
	{
		weight_target = _weight;
		weight_step = (_weight - weight) / _blend;
	}
	else
	{
		weight = _weight;
		weight_target = _weight;
		weight_step = 0;
	}
}
Source::Source()
{
	weight = 0;
	weight_target = 1;
	weight_step = 0;

	time_scale = 1;

	dispose = false;
}
Source::~Source() {}
//------------------------------------------------------------------------------
