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


		#include "ui/ui.h"
		#include "ui/ui_camera.h"
		#include "ui/ui_sprite.h"
		#include "ui/ui_ace_manager.h"
		#include "ui/ui_scene_script_event.h"
		#include "ui/ui_scene_scripted_object.h"
		#include "ui/ui_item_script_event.h"
		#include "ui/ui_item_scripted_object.h"
		#include "script/script_engine_types.h"
		#include "script/script_variant.h"
		#include "log/log.h"

		using namespace GS::S2D;


//------------------------------------------------------------------------------
void				Scene::SetAsScriptGlobalScene(GS::Script::IVM *_vm)
{
	if	(!_vm)
		_vm = vm;
	if	(!_vm || !_vm->IsOpen())
		return;

	_vm->Set("g_scene", GS::Script::Variant(this, GS::Script::typetag_Scene2d));
	_vm->Set("g_clock_fq", GS::Platform::Get().GetClockFrequency());
}
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
void				Scene::Update()
{
	if (clock->GetRefCount() == 1)
		clock->Update();
	float dt = clock->GetDeltaf();

	// ACE update.
	ACEManager::Get()->UpdateACEUnit(this, dt);

	ListForeachPtr(Item *, i, item_list)
	{
		i->automation_player->Evaluate(Time::fromSec(dt));

		switch (i->GetItemType())
		{
			case Item::Type_Sprite:
			case Item::Type_Window:
			{
				Sprite *s = (Sprite *)i;
				ACEManager::Get()->UpdateACEUnit(s, dt);
			}
			break;
		}
	}

	//
	// Script events.
//	if	(eval_flag & SceneUpdateEvent)
	{
		scene_event->OnUpdate(this);
		ListForeachPtr(Item *, i, item_list)
			i->item_event->OnUpdate(i);
	}
}
//------------------------------------------------------------------------------
