/*********************************************************\
         __      __           __  __
        / /     / / _____    / / / / ______   __     __
       / /     / / /___  \  / / / / / ___  | / /    / /
      / /_____/ / _____| / / / / / / /__/ / / /    / /
     / ______  / / ___  / / / / / / _____/ / /    / /
    / /     / / / /__/ / / / / / / |____  / |____/ /
   /_/     /_/ |______/ /_/ /_/  \_____/  \_____  /
                                         ______/ /
            High Level Game Framework   /_______/

  ------------------------------------------------------

  Copyright (c) 2007 - Rodrigo Braz Monteiro.
  This file is subject to the terms of license.txt.

\*********************************************************/

#pragma once

#include "frame.h"

namespace Halley {
	class Game;
	class RedirectStream;

	typedef shared_ptr<Game> spGame;
	typedef weak_ptr<Game> wpGame;

	class Game : public IFrameParent {
		friend class Frame;

	public:
		Game(String gameName);
		virtual ~Game();

		void Start(StringArray args);

		static spGame GetInstance();
		static void SetInstance(spGame game);
		static String GetProgramPath();

	protected:
		virtual void onPreUpdate() {}

		virtual void Init(StringArray args)=0;
		virtual void DeInit()=0;
		virtual spFrame CreateFrame(String frameName)=0;
		void SetTopFrame(spFrame frame);
		spFrame getTopFrame() { return topFrame; }

		void Quit();

	private:
		static spGame instance;

		int fps;
		bool run;
		String name;
		spFrame topFrame;
		String programPath;

		void Exit();
		void ChildFrameChange(spFrame from,spFrame to);
		void ParseProgramPath(String path);

		void Run();
		void PollEvents();
		bool UpdateLogic();
		void RenderScreen();

		shared_ptr<RedirectStream> out;
	};
}
