program WoodenGun;

uses
  Windows,
  Messages,
  _Scene,
  _Forms,
  _Geometry,
  _SysUtils,
  _World,
  _HexMap,
  QuadEngine,
  Direct3d9 in 'DirectX\Direct3d9.pas',
  DXTypes in 'DirectX\DXTypes.pas', 
  _Effects,
  _Resources;

{ $R *.res}

var
  Quad: IQuadRender;
  Timer: IQuadTimer;

{$REGION 'Kill_program'}
procedure KillApplication;
begin
  Manager:= nil;
  Resources:= nil;
  Timer.SetState(false);
  Timer:= nil;
  Quad:= nil;
end;
{$ENDREGION}

{$REGION 'Change_state'}
procedure ChangeState;
begin
  Quad.ChangeResolution(Window.Width, Window.Height);
end;
{$ENDREGION}

{$REGION 'Timer'}
procedure OnTimer(var dt:Double);
begin
  Manager.Control;
  Manager.Update(dt);

  Quad.BeginRender;
  Manager.Render;
  Quad.EndRender;
end;
{$ENDREGION}

{$REGION 'Create_prog'}
procedure CreateApplication;
begin
  Randomize;

  Quad:= CreateQR;
  Quad.Initialize(Window.Handle, Window.Width, Window.Height);
  Quad.SetBlendMode(qbmNone);
  Timer:= CreateTimer(Quad, @OnTimer, 5);

  Resources:= TResources.Load(Quad);
  World:= TWorld.Create(Quad);
  Menu:= TMainMenu.Create(Quad, World); 
  //Logo
  Manager:= TSceneManager.Create(
    TLogo.Create(
      TLogo.Create(Menu, Quad,
      Resources.LogoTexture), Quad,
    Resources.QuadTexture));
end;
{$ENDREGION}

begin
  Window:=TWindow.Create(
      'Wooden gun',
      @CreateApplication, @KillApplication, @ChangeState,
      (GetSystemMetrics(SM_CXSCREEN) - 1024) div 2,
      (GetSystemMetrics(SM_CYSCREEN) - 768) div 2,
      1024, 768);
  Window.Initialize;
end.
