//===========================================================================//
// File:	NetAutoPacketSpliter.hpp											
//---------------------------------------------------------------------------//
//   Date    Who  Modification                                               //
// --------  ---  ---------------------------------------------------------- //
// 01/06/1999  JSE  Inital coding
//---------------------------------------------------------------------------//
// Copyright (C) 1998, Microsoft Corp.										 //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//


#pragma once
#include "MW4.hpp"
#include "NetConstants.hpp"
#include "NetUpdateManager.hpp"
#include "MWEntityManager.hpp"

namespace MechWarrior4 
{
	class NetUpdateSortEntry:
		public Stuff::Plug
	{
	public:

		Entity *m_entity;
		int m_size;
		int m_type;
		UpdateRate m_rate;

		NetUpdateSortEntry(Entity *entity, int size, int type, UpdateRate rate);
		
	};

	//##########################################################################
	

	class NetUpdatePageHolder:
		public Stuff::Plug
	{
	public:
		
		int entryCount;
		int totalMaxSize;
		ChainOf<NetUpdateSortEntry*> m_UpdateEntries;
		
		
		NetUpdatePageHolder(int page_overhead);
		~NetUpdatePageHolder();

		bool IsThereRoom(NetUpdateSortEntry *entry, int paragraph_overhead);
		void AddToList(NetUpdateSortEntry *entry, int paragraph_overhead);
		void AddSelfToDictionary(Dictionary *dictionary, int page_number);
		
	};

	//##########################################################################
	//##########################################################################
	
	class NetUpdateSorter:
		public Stuff::Plug
	{
	public:
		
		int m_debugLevel;
		int m_bandwidth;
	
		int pageOverhead;
		int paragraphOverhead;

		ChainOf<NetUpdateSortEntry*> m_halfhzList;
		ChainOf<NetUpdateSortEntry*> m_oneHzList;
		ChainOf<NetUpdateSortEntry*> m_twoHzList;
		ChainOf<NetUpdateSortEntry*> m_threeHzList;
		ChainOf<NetUpdateSortEntry*> m_fourHzList;
		ChainOf<NetUpdateSortEntry*> m_sixHzList;
		ChainOf<NetUpdateSortEntry*> m_eightHzList;
		ChainOf<NetUpdateSortEntry*> m_nineHzList;
		ChainOf<NetUpdateSortEntry*> m_twelveHzList;
		ChainOf<NetUpdateSortEntry*> m_sixteenHzList;

		ChainOf<NetUpdateSortEntry*> *updateList[10];


		NetUpdateSorter(int debug_level, int connection_rate);
		~NetUpdateSorter();

		void AddUpdateToList(Entity *entity, int type, UpdateRate rate);
		
		void MakeDictionaryPages(Dictionary *dictionary);

		void FindPageWithRoom(ChainOf<NetUpdatePageHolder*> *pages, NetUpdateSortEntry *entry);


	};

};