//===========================================================================//
// File:	rp4lbe4.hh                                                          //
// Project: MUNGA           Brick: Red Planet LBE Application					  //
// Contents: 																					  //
//---------------------------------------------------------------------------//
//   Date    Who  Modification                                               //
// --------  ---  ---------------------------------------------------------- //
//                                            										  //
//---------------------------------------------------------------------------//
// Copyright (C) 1994, Virtual World Entertainment, Inc.                     //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//

#if !defined(L4SPLR_HPP)
#	define L4SPLR_HPP

#	if !defined(L4NET_HPP)
#		include <l4net.hpp>
#	endif

#	if !defined(L4APP_HPP)
#		include <l4app.hpp>
#	endif

#	if !defined(SPOOLER_HPP)
#		include <spooler.hpp>
#	endif

#	if !defined(INTEREST_HPP)
#		include <interest.hpp>
#	endif

#	if !defined(APPTASK_HPP)
#		include <apptask.hpp>
#	endif

	//##########################################################################
	//####################   SpoolingInterestManager   #########################
	//##########################################################################

	class SpoolingInterestManager:
		public InterestManager
	{
	public:
		SpoolingInterestManager();
		~SpoolingInterestManager();

		void
			LoadInterestArenas(Mission *mission);
		void
			LoadMission(Mission *mission);
		void
			ReceiveNetworkPacket(
				NetworkPacket *packet,
				Receiver::Message *packet_message
			);
		void
			Shutdown();
	};

	//##########################################################################
	//###################   L4SpoolingNetworkManager   #########################
	//##########################################################################

	class L4SpoolingNetworkManager:
		public L4NetworkManager
	{
	public:
		L4SpoolingNetworkManager();
		~L4SpoolingNetworkManager();

		void
			ReceiveNetworkPacket(
				NetworkPacket *packet,
				Receiver::Message *packet_message
			);
		void
			StartConnecting(Mission *mission);
	};

	//##########################################################################
	//###################   L4PlaybackNetworkManager   #########################
	//##########################################################################

	class L4PlaybackNetworkManager:
		public NetworkManager
	{
	public:
		L4PlaybackNetworkManager();
		~L4PlaybackNetworkManager();

		void
			StartConnecting(Mission *mission);

		Logical
			Shutdown();

		Logical
			CheckBuffers(NetworkPacket*);
	};

	//##########################################################################
	//###################    L4SpoolingApplication    ##########################
	//##########################################################################

	class L4SpoolingApplication:
		public L4Application
	{
	public:
		L4SpoolingApplication(
			ResourceFile *resource,
         ApplicationID application_ID
		);
		~L4SpoolingApplication();

		SpoolingInterestManager*
			GetInterestManager()
				{
					return
						(SpoolingInterestManager*)Application::GetInterestManager();
				}

		L4SpoolingNetworkManager*
			GetNetworkManager()
				{
					return
						(L4SpoolingNetworkManager*)Application::GetNetworkManager();
				}

		MissionReviewApplicationManager*
			GetApplicationManager()
				{
					return
						(MissionReviewApplicationManager*)
							Application::GetApplicationManager();
				}

	protected:
		Registry*
			MakeRegistry();
		InterestManager*
			MakeInterestManager();
		NetworkManager*
			MakeNetworkManager();

		Mission*
			MakeMission(
				NotationFile *notation_file,
				ResourceFile *resources
			);

		VideoRenderer*
			MakeVideoRenderer();
		AudioRenderer*
			MakeAudioRenderer();
		GaugeRenderer*
			MakeGaugeRenderer();

		Entity*
			MakeViewpointEntity(Entity__MakeMessage *);

		void
			Initialize();
		void
			LoadBackgroundTasks();
		Logical
			Shutdown();


		void
			ReceiveNetworkPacket(
				NetworkPacket *packet,
				Receiver::Message *packet_message
			);

		Logical
			ExecuteForeground(
				Time start_of_frame,
				Scalar frame_duration
			);
		void
			ExecuteBackgroundTask();

	protected:
		Logical
			missionSpooled;

	public:
		static Derivation ClassDerivations;
		static SharedData DefaultData;

		static const HandlerEntry
			MessageHandlerEntries[];
		static MessageHandlerSet
			MessageHandlers;

		void
			LoadMissionMessageHandler(Message *message);
		void
			RunMissionMessageHandler(RunMissionMessage *message);
		void
			StopMissionMessageHandler(StopMissionMessage *message);
		void
			AbortMissionMessageHandler(AbortMissionMessage *message);

		Logical
      	TestInstance() const;
	};

	extern L4SpoolingApplication * &l4_spooling_application;

	//##########################################################################
	//########################    SpoolerTask    ###############################
	//##########################################################################

	class SpoolerTask:
		public ApplicationTask
	{
	public:
		SpoolerTask();
		~SpoolerTask();

		void
			Execute();

		virtual void
			DispatchPacket(NetworkPacket *packet);
		virtual long
			GetTimeBias();
	};

#endif

