/*
	Lan Wars.
	Copyright (c) 2009, Darragh Coy.
	All rights reserved.
	Original work(s), source code & author(s) details available at: http://www.darraghcoy.com

	Redistribution and use in source and binary forms, with or without modification, are permitted 
	provided that the following conditions are met:

		* 	Redistributions of source code must retain the above copyright notice, this list of 
			conditions and the following disclaimer.
		* 	Redistributions in binary form must reproduce the above copyright notice, this list of 
			conditions and the following disclaimer in the documentation.
		* 	Neither the name of the author nor the names of contributors may be used to endorse or 
			promote products derived from this software without specific prior written permission.
		* 	The use of any third party libraries, modules or data files provided with the source 
			form of the program must follow and respect the individual licensing terms of these 
			components. You do not have permission to modify or circumvent the licensing terms for 
			provided third party components unless the third party licenses specifically allow this. 
			If you do not agree to the terms of provided third party components then you do not have 
			permission to use them in your derived work(s).
		* 	The terms of this license do not apply to separate (but related) distributions if supplied 
			by the author(s), only to the contents of this source distribution, derived works, and the 
			binaries produced by either modified or unmodified versions of the source code. The terms 
			of this license do not also apply to any third party libraries or components provided with 
			the source distribution. Such third party elements are licensed under their own separate 
			agreements.

	THIS SOFTWARE IS PROVIDED BY DARRAGH COY ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
	BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
	ARE DISCLAIMED. IN NO EVENT SHALL DARRAGH COY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
	EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
	OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
	OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
	IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef GAME_NET_SERIALIZER_H
#define GAME_NET_SERIALIZER_H

//=====================================================================================================================
//=====================================================================================================================

namespace Game
{	
	//=================================================================================================================
	//=================================================================================================================
	
	class GamePlayer;
	class GameMap;	
	class GameRocket;
	class GameFireball;
	class GameAmmo;
	class GameHealth;
	class GameEnemy;
	class GamePacket;
	class GameObjectBase;

	//=================================================================================================================
	/// @brief		This helper class packages off objects created on the server for creation on the client.
	///				It also performs the reverse on the client.
	//=================================================================================================================

	class GameNetSerializer
	{
		public:		

			//=========================================================================================================
			// Enums
			//=========================================================================================================
			
				/// The identifiers for each type of object that can be created
				
				enum TypeId
				{
					/// This object is the map
					
					TYPE_ID_GAME_MAP = 0 ,
				
					/// This object is a player
				
					TYPE_ID_GAME_PLAYER = 1 , 
					
					/// This object is a rocket
					
					TYPE_ID_GAME_ROCKET = 2 ,
					
					/// This object is a rocket ammo box
					
					TYPE_ID_GAME_ROCKETS = 3 ,
					
					/// This object is a health box
					
					TYPE_ID_GAME_HEALTH = 4	,

					/// This object is an enemy

					TYPE_ID_GAME_ENEMY = 5 , 
					
					/// This object is an enemy fireball
					
					TYPE_ID_GAME_FIREBALL = 6
				};
				
			//=========================================================================================================
			// Constants
			//=========================================================================================================
			
				/// This is the number of bits required to write/read an object TypeId
				
				static const unsigned TYPE_ID_BITS = 3;
			
			//=========================================================================================================
			// Functions
			//=========================================================================================================

				/// Packs the given net object within the packet for creation on a remote machine
				
				static void Pack( GameObjectBase & obj , GamePacket & p );
				
				/// Unpacks the given net object in the given packet for creation on the local machine
				
				static GameObjectBase * Unpack( GamePacket & p );

		private:
		
			//=========================================================================================================
			// Functions
			//=========================================================================================================
			
				/// Packs a GamePlayer object
				
				static void PackGamePlayer( GamePlayer & obj , GamePacket & p );
			
				/// Unpacks a GamePlayer object and creates it
				
				static GamePlayer * UnpackGamePlayer( GamePacket & p , unsigned net_id , unsigned owner_id );
				
				/// Packs a GameMap object
				
				static void PackGameMap( GameMap & obj , GamePacket & p );				
				
				/// Unpacks a GameMap object and creates it
				
				static GameMap * UnpackGameMap( GamePacket & p , unsigned net_id , unsigned owner_id );
				
				/// Packs a GameRocket object
				
				static void PackGameRocket( GameRocket & obj , GamePacket & p );
				
				/// Unpacks a GameRocket object
				
				static GameRocket * UnpackGameRocket( GamePacket & p , unsigned net_id , unsigned owner_id );

				/// Packs a GameFireball object
				
				static void PackGameFireball( GameFireball & obj , GamePacket & p );
				
				/// Unpacks a GameFireball object
				
				static GameFireball * UnpackGameFireball( GamePacket & p , unsigned net_id , unsigned owner_id );
				
				/// Packs a GameAmmo object
				
				static void PackGameAmmo( GameAmmo & obj , GamePacket & p );
				
				/// Unpacks a GameAmmo object
				
				static GameAmmo * UnpackGameAmmo( GamePacket & p , unsigned net_id , unsigned owner_id );
				
				/// Packs a GameHealth object
				
				static void PackGameHealth( GameHealth & obj , GamePacket & p );
				
				/// Unpacks a GameHealth object
				
				static GameHealth * UnpackGameHealth( GamePacket & p , unsigned net_id , unsigned owner_id );

				/// Packs a GameEnemy object
				
				static void PackGameEnemy( GameEnemy & obj , GamePacket & p );
				
				/// Unpacks a GameEnemy object
				
				static GameEnemy * UnpackGameEnemy( GamePacket & p , unsigned net_id , unsigned owner_id );
	};
};

#endif
