//===========================================================================//
// File:	update.hh                                                           //
// Project: MUNGA           Brick: Update Manager	                          //
// Contents: 																					  //
//---------------------------------------------------------------------------//
//   Date    Who  Modification                                               //
// --------  ---  ---------------------------------------------------------- //
// 12/20/94  ECH  Initial coding.                                            //
//---------------------------------------------------------------------------//
// Copyright (C) 1994-1995, Virtual World Entertainment, Inc.                //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//

#if !defined(UPDATE_HPP)
#	define UPDATE_HPP

#if !defined(NODE_HPP)
#	include <node.hpp>
#endif

#if !defined(TIME_HPP)
#	include <time.hpp>
#endif

#	if !defined(MEMBLOCK_HPP)
#		include <memblock.hpp>
#	endif

#	if !defined(SIMULATE_HPP)
#		include <simulate.hpp>
#	endif

	class UpdateManager;

	class SimulationEncore:
		public Plug
	{
		friend class UpdateManager;

	private:
		static MemoryBlock AllocatedMemory;

		void*
			operator new(size_t)
				{return AllocatedMemory.New();}
		void
			operator delete(void *where)
				{AllocatedMemory.Delete(where);}

		Simulation *encoreSimulation;
		Simulation::Encore encoreCallback;
		Logical runWatchers;

		SimulationEncore(
			Simulation *sim,
			Simulation::Encore callback
		);
		~SimulationEncore();
	};

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ UpdateManager ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	class UpdateManager:
		public Node
	{
	public:
		//
		//--------------------------------------------------------------------
		// Construction, Destruction
		//--------------------------------------------------------------------
		//
		UpdateManager();
		~UpdateManager();

		Logical
			TestInstance() const;

		//
		//--------------------------------------------------------------------
		// Execute
		//
		// Perform update management functions
		//--------------------------------------------------------------------
		//
		void
			Execute(Time target_render_time);

		//
		//----------------------------------------------------------------------
		// CreateEncore
		//
		// Registers a callback to be executed after all entity performances are
		// completed
		//----------------------------------------------------------------------
		//
		void
			RequestEncore(
				Simulation *simulation,
				Simulation::Encore encore
			);

	protected:
		ChainOf<SimulationEncore*>
			simulationEncores;
	};

#endif

