/** 
 * \file Game.h
 * \brief Header file containing CGame class and all global game parameters.
 *
 * \author Petar Bajic, MPE (C) All Rights Reserved, Homepage: www.mystic-peanut.com
 * \date January, 16 2007.
 */

#include "Menu.h"
#include "Level.h"
#include "Movie.h"
#include "Bonus.h"
#include "GameUtils.h"

class CLanguage;

/**
 * \brief Game class initialize the game and passes events to submodules.
 *
 * This class is topmost game class that separates game modes and passes info to 
 * appropriate game modules. Global game variables and utility functions are stored in this class, 
 * all game modules (Menu, Movie, Level) are initialized and called from from CGame class.
 * \author Petar Bajic \date January, 16 2007.
 */
class CGame {

public:
	CGame();
	~CGame();
	void RenderLoading(D3DXVECTOR2 loadingTrans2, WCHAR* strText);
	bool Init(HWND hWnd, int screenWidth, int screenHeight);
	bool OnEvent(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
	void OnRender();
	void OnFrameMove();
	void OnResetDevice(HWND hWnd);
	void OnLostDevice();
	bool LoadSettingsFromFile(HWND hWnd);
	void WriteSettingsToFile();

	CTerrain*	m_pTerrain;
	CSheep*		m_pSheep;
	CTurtle*	m_pTurtle;
	CMenu*		m_Menu;
	CLevel*		m_Level;
	CMovie*		m_Movie;
	CBonus*		m_Bonus;
	CLanguage*	m_Language;

	bool m_GamePaused; //Game paused should stop the rendering 
	bool m_PausedByAltTab; //alt tab was trouble maker, and we just wanted to pause the game
	bool m_wasMaximized; //Used to differ window RESTORE event, weather it was restored from minimized or maximized
	unsigned char m_GameMode; //containing current game mode.

	//Time
	LONGLONG m_QPFTicksPerSec, m_BaseTime;
	double m_CurrentTime;
	float m_ElapsedTime;
	bool m_bUsingQPF;

	int m_oldScreenWidth; //in fullscreen mode this is where the old dimension is saved
	int m_oldScreenHeight; //in fullscreen mode this is where the old dimension is saved
	int m_screenWidth;
	int m_screenHeight;
	int m_counter;
	int m_total_counter;
	int m_total_number;
	float m_aspectRatio;

	IDirectSound8* m_pDS; //Direct Sound Interface
	D3DLIGHT9 m_Light1, m_Light2, m_Light3; //Lights please?
	LPDIRECT3D9 m_pD3D; // Used to create the D3DDevice
	LPDIRECT3DDEVICE9 m_pd3dDevice; // Our rendering device
	D3DPRESENT_PARAMETERS* m_pd3dPP;

	//Loading pic
	LPDIRECT3DTEXTURE9 m_loadingTexture1;
	LPDIRECT3DTEXTURE9 m_loadingTexture2;
	LPDIRECT3DTEXTURE9 m_loadingTexture3;
	LPD3DXSPRITE m_sprite;
	LPD3DXFONT m_pFont;

	//Camera
	D3DXVECTOR3 m_EyePt;
	D3DXVECTOR3 m_LookatPt;
	D3DXVECTOR3 m_UpVec;

	//Config
	bool	m_ConfigFullScreen;
	bool	m_ConfigDetails;
	float	m_ConfigDificulty;
	int		m_ConfigLanguage;
	int		m_ConfigStartCount;
};
