program demo06;

uses
  QuadEngine,
  Vec2f,
  Classes,
  Winapi.Windows,
  Math,
  QuadFX,
  Resources in 'Resources.pas',
  GameMode.Custom in 'gamemodes\GameMode.Custom.pas',
  GameMode.Manager in 'gamemodes\GameMode.Manager.pas',
  GameMode.StarGate in 'gamemodes\GameMode.StarGate.pas',
  GameMode.Planet in 'gamemodes\GameMode.Planet.pas',
  Units.Custom in 'gamemodes\Units\Units.Custom.pas',
  Units.Player in 'gamemodes\Units\Units.Player.pas',
  Level.Map in 'gamemodes\Levels\Level.Map.pas',
  GameOverlay in 'GameOverlay.pas',
  CustomObject in 'gamemodes\GameObjects\CustomObject.pas',
  ObjectButton in 'gamemodes\GameObjects\ObjectButton.pas',
  ObjectDoor in 'gamemodes\GameObjects\ObjectDoor.pas',
  ObjectSwitch in 'gamemodes\GameObjects\ObjectSwitch.pas',
  CustomSubject in 'gamemodes\GameObjects\CustomSubject.pas',
  Subject in 'gamemodes\GameObjects\Subject.pas',
  GameMode.FeesSquad in 'gamemodes\GameMode.FeesSquad.pas',
  Collision in 'Collision.pas',
  CustomGun in 'gamemodes\GameObjects\Guns\CustomGun.pas',
  CustomBullet in 'gamemodes\GameObjects\Guns\CustomBullet.pas',
  GameMode.Computer in 'gamemodes\GameMode.Computer.pas',
  ObjectTimer in 'gamemodes\GameObjects\ObjectTimer.pas',
  GunBeretta92F in 'gamemodes\GameObjects\Guns\GunBeretta92F.pas',
  GunUMP in 'gamemodes\GameObjects\Guns\GunUMP.pas',
  ObjectNot in 'gamemodes\GameObjects\ObjectNot.pas',
  ObjectTrap in 'gamemodes\GameObjects\ObjectTrap.pas',
  ObjectConsole in 'gamemodes\GameObjects\ObjectConsole.pas',
  ObjectLihgt in 'gamemodes\GameObjects\ObjectLihgt.pas',
  ObjectStartPoint in 'gamemodes\GameObjects\ObjectStartPoint.pas',
  ObjectActionRegion in 'gamemodes\GameObjects\ObjectActionRegion.pas',
  ObjectIPADConsole in 'gamemodes\GameObjects\ObjectIPADConsole.pas',
  ObjectMonster in 'gamemodes\GameObjects\ObjectMonster.pas',
  GlobalTypes in 'GlobalTypes.pas',
  BotMutant in 'gamemodes\Units\BotMutant.pas',
  ObjectCapacitor in 'gamemodes\GameObjects\ObjectCapacitor.pas',
  ObjectOr in 'gamemodes\GameObjects\ObjectOr.pas',
  ObjectDamageRegion in 'gamemodes\GameObjects\ObjectDamageRegion.pas';

procedure OnTimer(out delta: Double; Id: Cardinal); stdcall;
begin
  TGlobals.QuadInput.Update;
  TGlobals.GameModeManager.RefreshGameMode;

  TGlobals.GameModeManager.Process(delta);

  TGlobals.QuadRender.BeginRender;
  TGlobals.QuadRender.Clear($FF000000);

  TGlobals.GameModeManager.Draw;

  TGlobals.QuadRender.EndRender;
end;

procedure OnClose; stdcall;
begin
  TSounds.UnLoad;
  TEffects.UnLoad;
  TShaders.UnLoad;
  TGlobals.Finalize;
end;

begin
  ReportMemoryLeaksOnShutdown := True;
  Randomize;

  TGlobals.QuadDevice := CreateQuadDevice;
  TGlobals.QuadDevice.ShowCursor(True);

  TGlobals.QuadDevice.CreateLog(TGlobals.QuadLog);

  TGlobals.QuadDevice.CreateWindow(TGlobals.QuadWindow);
  TGlobals.QuadWindow.CreateInput(TGlobals.QuadInput);
  TGlobals.QuadWindow.SetCaption('IGDC 126 - Exploration');
  TGlobals.QuadWindow.SetSize(TGlobals.GWidth, TGlobals.GHeight);
  TGlobals.QuadWindow.SetPosition(100, 100);
  TGlobals.QuadWindow.SetOnClose(OnClose);

  TGlobals.QuadDevice.CreateRender(TGlobals.QuadRender);
  TGlobals.QuadRender.Initialize(TGlobals.QuadWindow.GetHandle, TGlobals.GWidth, TGlobals.GHeight, False, qsm20);

  TGlobals.QuadRender.SetAutoCalculateTBN(True);

  TGlobals.QuadDevice.CreateCamera(TGlobals.QuadCamera);
  TGlobals.QuadDevice.CreateCamera(TGlobals.QuadCameraGate);
  TGlobals.QuadDevice.CreateCamera(TGlobals.QuadCameraLights);

  TTextures.Load;
  TShaders.Load;
  TGlobals.Initialize;
  TSounds.Load;
  TEffects.Load;

  TGlobals.QuadDevice.SetCursorProperties(0, 0, TTextures.CursorTexture[ctArrow]);

  TGlobals.QuadDevice.CreateTimerEx(TGlobals.QuadTimer, OnTimer, 16, True);

  TGlobals.QuadWindow.Start;
end.
