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


		#include "scene3d/scene_event_script_interface.h"
		#include "scene3d/scene_script_unit.h"
		#include "scene3d/scene.h"
		#include "scene3d/mitem_event_interface.h"
		#include "scene3d/mitem.h"
		#include "script/scripted_object.h"
		#include "script/script_variant.h"

		using namespace GS::S3D;
		using namespace GS::Script;


//------------------------------------------------------------------------------
void				SceneScriptEvent::OnSetup(Scene *scene)
{
	ListForeachPtr(Unit *, unit, scene->scripted_object->GetUnitList())
		if	(unit->SetupFunctionCall("OnSetup"))
			unit->DoFunctionCall();
}
void				SceneScriptEvent::OnSetupDone(Scene *scene)
{
	ListForeachPtr(Unit *, unit, scene->scripted_object->GetUnitList())
		if	(unit->SetupFunctionCall("OnSetupDone"))
			unit->DoFunctionCall();
}
void				SceneScriptEvent::OnReset(Scene *scene)
{
	ListForeachPtr(Unit *, unit, scene->scripted_object->GetUnitList())
		if	(unit->SetupFunctionCall("OnReset"))
			unit->DoFunctionCall();
}
void				SceneScriptEvent::OnRender(Scene *scene)
{
	ListForeachPtr(Unit *, unit, scene->scripted_object->GetUnitList())
		if	(((SceneScriptUnit *)unit)->render_callback && unit->SetupFunctionCall("OnRender", ((SceneScriptUnit *)unit)->render_callback))
			unit->DoFunctionCall();
}
void				SceneScriptEvent::OnRenderDone(Scene *scene)
{
	ListForeachPtr(Unit *, unit, scene->scripted_object->GetUnitList())
		if	(((SceneScriptUnit *)unit)->render_done_callback && unit->SetupFunctionCall("OnRenderDone", ((SceneScriptUnit *)unit)->render_done_callback))
			unit->DoFunctionCall();
}
void				SceneScriptEvent::OnRenderUser(Scene *scene)
{
	ListForeachPtr(Unit *, unit, scene->scripted_object->GetUnitList())
		if	(((SceneScriptUnit *)unit)->render_user_callback && unit->SetupFunctionCall("OnRenderUser", ((SceneScriptUnit *)unit)->render_user_callback))
			unit->DoFunctionCall();

	ListForeachPtr(MItem *, item, scene->GetItemList())
		item->item_event->OnRenderUser(item);
}
void				SceneScriptEvent::OnRenderUIDone(Scene *scene)
{
	ListForeachPtr(Unit *, unit, scene->scripted_object->GetUnitList())
		if	(((SceneScriptUnit *)unit)->render_ui_done_callback && unit->SetupFunctionCall("OnRenderUIDone", ((SceneScriptUnit *)unit)->render_ui_done_callback))
			unit->DoFunctionCall();
}
void				SceneScriptEvent::OnPhysicStep(Scene *scene, bool step_taken)
{
	ListForeachPtr(Unit *, unit, scene->scripted_object->GetUnitList())
		if	(((SceneScriptUnit *)unit)->physic_step_callback && unit->SetupFunctionCall("OnPhysicStep", ((SceneScriptUnit *)unit)->physic_step_callback))
		{
			unit->PushFunctionCallArgument(step_taken);
			unit->DoFunctionCall();
		}
}
void				SceneScriptEvent::OnUpdate(Scene *scene)
{
	ListForeachPtr(Unit *, unit, scene->scripted_object->GetUnitList())
	{
		SceneScriptUnit *scene_unit = (SceneScriptUnit *)unit;
		if	(scene_unit->update_callback && scene_unit->SetupFunctionCall("OnUpdate", scene_unit->update_callback))
			scene_unit->DoFunctionCall();
	}
}
void				SceneScriptEvent::OnDelete(Scene *scene)
{
	ListForeachPtr(Unit *, unit, scene->scripted_object->GetUnitList())
		if	(unit->SetupFunctionCall("OnDelete"))
			unit->DoFunctionCall();
}
//------------------------------------------------------------------------------
