//===========================================================================//
// File:	btl4pb.hpp                                                          //
// Project: BattleTech           Brick: BattleTech LBE Application            //
// Contents: BTL4PlaybackApplication -- the LBE "mission review" / playback   //
//           application, plus the BTSpoolerTask background task that pumps    //
//           recorded network packets out of a SpoolFile.                      //
//---------------------------------------------------------------------------//
//   Date    Who  Modification                                               //
// --------  ---  ---------------------------------------------------------- //
//                                                                           //
//---------------------------------------------------------------------------//
// Copyright (C) 1995, Virtual World Entertainment, Inc.                     //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//
//
// This declaration is the SURVIVING header
// (410SRC\Telsa40\Rel410\CODE\BT\BT_L4\BTL4PB.HPP) reproduced verbatim.  Only
// the file banner has been corrected (the shipped copy still carried the Red
// Planet "rp4lbe4.hh / RPSpoolerTask / RPPlaybackApplication" comment block
// from which it was cloned).  The class bodies are unchanged ground truth and
// match the shipped binary BTL4OPT.EXE: BTL4PlaybackApplication vtable
// @0051f1a4 (ctor @004d3be4), BTSpoolerTask vtable @0051f204 (ctor @004d3b74).
//

#if !defined(BTL4PB_HPP)
#	define BTL4PB_HPP

// NOTE (reconstruction): btl4app.hpp uses L4Application as a base but does not
// itself pull in l4app.hpp (it only chains through btl4mppr.hpp), so the base
// must be made visible here first -- exactly as the RP twin rpl4pb.h relies on
// rpl4app.h -> l4app.h.  This also brings in <app.h>/<appmgr.h> (Application,
// the RunMission/StopMission message IDs, Derivation, SharedData, etc.).
#	include <l4app.hpp>

#	if !defined(BTL4APP_HPP)
#		include <btl4app.hpp>
#	endif

#	if !defined(L4SPLR_HPP)
#		include <l4splr.hpp>
#	endif

	//##########################################################################
	//#######################    BTSpoolerTask    ##############################
	//##########################################################################

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

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

	//##########################################################################
	//####################    BTL4PlaybackApplication    #######################
	//##########################################################################

	class BTL4PlaybackApplication:
		public BTL4Application
	{
	public:
		// PORT NOTE: the surviving DOS header declared this as
		// (ResourceFile*, SpoolFile*).  The WinTesla L4Application base ctor
		// requires (HINSTANCE, HWND, ...) for the Windows window/instance, so --
		// exactly as RPL4PlaybackApplication does -- the playback application
		// threads HINSTANCE/HWND through to the base.
		BTL4PlaybackApplication(
			HINSTANCE hInstance,
			HWND hWnd,
			ResourceFile *resource,
			SpoolFile *spool_file = NULL
		);
		~BTL4PlaybackApplication();

		Logical
      	TestInstance() const;

		void
			SetSpoolFile(SpoolFile *spool_file)
				{spoolFile = spool_file;}

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

		long
			GetTimeBias()
				{return timeBias;}

		void
			DispatchPacket(NetworkPacket *packet);

	protected:
		NetworkManager*
			MakeNetworkManager();

		long
			timeBias;

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

		static const HandlerEntry
			MessageHandlerEntries[];
		// Modernized WinTesla idiom (cf. RPL4PlaybackApplication): the shipped
		// 1995 source declared a plain "static MessageHandlerSet MessageHandlers;"
		// but the ported engine exposes the handler set through an accessor that
		// chains to the inherited Application::GetMessageHandlers().
		static MessageHandlerSet&
			GetMessageHandlers();

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Shared Data Support
	//
	public:
		static Derivation *GetClassDerivations();
		static SharedData DefaultData;

		void
			RunMissionMessageHandler(RunMissionMessage *message);
		void
			StopMissionMessageHandler(StopMissionMessage *message);
	};

#endif
