unit Resources;

interface

uses
  QuadEngine, GameMode.Manager, GameMode.StarGate, GameMode.Planet, Vec2f, Units.Player, BASS,
  Windows, System.Generics.Collections, IniFiles, Classes, Subject, GameMode.FeesSquad,
  GameMode.Computer, QuadFX, GlobalTypes;

type
  TSpeedType = (stFTL, stSubLight);

  TGlobals = class abstract
  const
    GWidth = 1024;
    GHeight = 768;
    LightSize = 512;
  class var
    QuadDevice: IQuadDevice;
    QuadLog: IQuadLog;
    QuadWindow: IQuadWindow;
    QuadInput: IQuadInput;
    QuadRender: IQuadRender;
    QuadTimer: IQuadTimer;
    QuadCamera: IQuadCamera;
    QuadCameraGate: IQuadCamera;
    QuadCameraLights: IQuadCamera;

    AncientsFont: IQuadFont;
    EarthFont: IQuadFont;
    GameModeManager: TGameModeManager;
    GameModes: record
      StarGate: TGameModeStarGate;
      Level: TGameModePlanet;
      DestinyLevels: array[0..17] of TGameModePlanet;
      PlanetLevels: array[0..2] of TGameModePlanet;
      FeesSquad: TGameModeFeesSquad;
      Computer: TGameModeComputer;
    end;
    Heroes: TObjectList<TUnitsPlayer>;
    LevelHeroes: TList<TUnitsPlayer>;
    Subjects: TList<TSubject>;

    Speed: TSpeedType;
    FTLTimer: Double;

    class procedure SwitchSpeed;
    class procedure Initialize;
    class procedure Finalize;
    class procedure LoadHeroes;
  end;

  TWorldTextures = record
    Ground: IQuadTexture;
    Floor: IQuadTexture;
    Rock3: IQuadTexture;
    Bg: IQuadTexture;
  end;

  TCursotType = (
    ctArrow = 0
  );

  TBotResource = record
    Textures: array[TAnimationType] of IQuadTexture;
    Frames: array[TAnimationType] of Integer;
  end;

  TTextures = class abstract
  class var
    FGate: IQuadTexture;
    FEvent: IQuadTexture;
    FLight: IQuadTexture;
    FOcclusion: IQuadTexture;
    FRoom: IQuadTexture;
    Kawoosh: IQuadTexture;
    GateOpen: IQuadTexture;
    QuadGBuffer: IQuadGBuffer;
    Hero: IQuadTexture;
    Portraits: IQuadTexture;
    Subjects: IQuadTexture;
    SubjectsLight: IQuadTexture;

    Panel: record
      Bg1: IQuadTexture;
      Bg2: IQuadTexture;
      Ramka: IQuadTexture;
      Line: IQuadTexture;
      Hero: IQuadTexture;
    end;

    Trees: IQuadTexture;
    wifi: IQuadTexture;

    Bots: array[TBotModel] of TBotResource;

    HP: IQuadTexture;
    Holder: IQuadTexture;
    DestinyDisplay: IQuadTexture;
    DestinyDisplayButton: IQuadTexture;
    FTL: IQuadTexture;
    sgate: IQuadTexture;
    exit: IQuadTexture;

    LightsBarriers: IQuadTexture;
    LightsBarriersRT1: IQuadTexture;
    LightsBarriersDS: array[0..3] of IQuadTexture;
    ShadowMap: IQuadTexture;
    Mask: IQuadTexture;

    Planet: IQuadTexture;
    Shield: IQuadTexture;

    Console: array[0..5] of IQuadTexture;

    CursorTexture: array[TCursotType] of IQuadTexture;
    WorldTexture: array[TWorldType] of TWorldTextures;
  class procedure Load;
  end;

  TEffects = class abstract
  class var
    QuadFXManager: IQuadFXManager;
    QuadFXLayer: IQuadFXLayer;
    QuadFXAtlas: IQuadFXAtlas;

    Explosion: IQuadFXEffectParams;
    BulletShot: IQuadFXEffectParams;
  class procedure Load;
  class procedure UnLoad;
  end;

  TShaders = class abstract
  class var
    Lights: IQuadShader;
    GateOpen: IQuadShader;
    FTL: IQuadShader;
    LightTrace: record
      pass1: IQuadShader;
      pass2: IQuadShader;
      pass3: IQuadShader;
      pass4: IQuadShader;
      pass5: IQuadShader;
      pass6: IQuadShader;
    end;
    Planet: IQuadShader;
  class procedure Load;
  class procedure UnLoad;
  end;

  TSounds = class abstract
  class var
    Gate: record
      Roll: HSAMPLE;
      Chevron: HSAMPLE;
      Open: HSAMPLE;
      Close: HSAMPLE;
      BeginRoll: HSAMPLE;
    end;
  class procedure Load;
  class function Play(ASample: HSAMPLE): Cardinal;
  class procedure Stop(ASample: HSAMPLE);
  class procedure UnLoad;
  end;

implementation

class procedure TGlobals.Initialize;
var
  df: TDistanceFieldParams;
begin
  GameModeManager := TGameModeManager.Create;
  GameModes.StarGate := TGameModeStarGate.Create;

  Subjects := TList<TSubject>.Create;

  Heroes := TObjectList<TUnitsPlayer>.Create;
  LevelHeroes := TList<TUnitsPlayer>.Create;
  LoadHeroes;

  GameModes.FeesSquad := TGameModeFeesSquad.Create;
  GameModes.level := TGameModePlanet.Create('Maps\Planet2', wtSnow);
  GameModes.Computer := TGameModeComputer.Create;

  GameModeManager.SetActiveGameMode(GameModes.StarGate);

  df.Edge1X := 0.45;
  df.Edge1Y := 0.5;
  df.FirstEdge := True;
  df.SecondEdge := False;
  QuadDevice.CreateAndLoadFont('data\AncientsFont.png', 'data\AncientsFont.qef', AncientsFont);
  QuadDevice.CreateAndLoadFont('data\EarthFont.png', 'data\EarthFont.qef', EarthFont);
  AncientsFont.SetIsSmartColoring(True);

  AncientsFont.SetDistanceFieldParams(df);
  EarthFont.SetDistanceFieldParams(df);
  if HiWord(BASS_GetVersion) = BASSVERSION then
  begin
    BASS_Init(-1, 44100, 0, QuadWindow.GetHandle, nil);
    BASS_Start;
  end;

  FTLTimer := 7 * 60; // 7 минут
  Speed := stFTL;
end;

class procedure TGlobals.Finalize;
begin
  QuadTimer.SetState(False);
  QuadTimer := nil;
  QuadWindow := nil;
  QuadInput := nil;
  QuadRender := nil;
  QuadCamera := nil;
  QuadCameraGate := nil;
  QuadCameraLights := nil;
  QuadDevice := nil;

  GameModes.StarGate.Free;
  GameModes.Level.Free;
  GameModes.FeesSquad.Free;
  GameModes.Computer.Free;
  GameModeManager.Free;
  LevelHeroes.Free;
  Subjects.Free;
  Heroes.Free;
end;

class procedure TGlobals.LoadHeroes;
var
  i: Integer;
  StrList: TStringList;
  ini: TIniFile;
  UnitPlayer: TUnitsPlayer;
begin
  Subjects.Clear;
  Subjects.Add(TSubject.Create(stIPAD, 1));
  for i := 1 to 3 do
    Subjects.Add(TSubject.Create(stFlashLight, 1));

  for i := 1 to 5 do
    Subjects.Add(TSubject.Create(stGunUMP, 1));

  for i := 1 to 3 do
    Subjects.Add(TSubject.Create(stGunBeretta92F, 1));

  Heroes.Clear;
  StrList := TStringList.Create;

  ini := TIniFile.Create('data/heroes.ini');
  ini.ReadSections(StrList);

  for i := 0 to StrList.Count - 1 do
  begin
    UnitPlayer := TUnitsPlayer.Create(TVec2f.Zero);
    UnitPlayer.Load(ini, StrList[i]);
    Heroes.Add(UnitPlayer);
  end;

  ini.Free;
  StrList.Free;
end;

class procedure TGlobals.SwitchSpeed;
begin
  if Speed = stFTL then
  begin
    Speed := stSubLight;
    GameModes.Computer.GeneratePlanets;
  end
  else
    Speed := stFTL;
end;

{ TTextures }

class procedure TTextures.Load;
var
  i: Integer;
begin
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\wifi.png', wifi);

  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\cursor.png', CursorTexture[ctArrow]);

  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\panel_bg.png', Panel.Bg1);
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\panel_bg2.jpg', Panel.Bg2);
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\panel_ramka.png', Panel.Ramka);
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\panel_line.png', Panel.Line);
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\panel_hero.png', Panel.Hero);

  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\holder.png', Holder);
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\hp.png', HP);

  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\gate_diff.png', FGate);
  FGate.LoadFromFile(1, 'data\Universe_n.png');
  FGate.LoadFromFile(2, 'data\1.jpg');
  FGate.LoadFromFile(3, 'data\6.png');

  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\event.png', FEvent);
  FEvent.LoadFromFile(1, 'data\water.jpg');
  FEvent.LoadFromFile(2, 'data\event.jpg');
  FEvent.LoadFromFile(3, 'data\event.jpg');

  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\display.png', DestinyDisplay);
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\display_button.png', DestinyDisplayButton);
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\Universe_g.png', FLight);
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\occlusion.png', FOcclusion);
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\stargate_universe_gate_room.jpg', FRoom);
  TGlobals.QuadDevice.CreateAndLoadTexture(0 ,'data\GateOpen.jpg', GateOpen);
  GateOpen.LoadFromFile(1 ,'data\noise.jpg');

  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\Kawoosh.png', Kawoosh, 128, 128);

  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\Trees.png', Trees, 128, 128);

  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\ground.jpg', WorldTexture[wtDirt].Ground);
  WorldTexture[wtDirt].Ground.LoadFromFile(1, 'data\ground_normal.jpg');
  WorldTexture[wtDirt].Ground.LoadFromFile(2, 'data\ground_diffuse.jpg');
  WorldTexture[wtDirt].Ground.LoadFromFile(3, 'data\ground_bump.jpg');
                                                                 {
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\snow.jpg', WorldTexture[wtSnow].Ground);
  WorldTexture[wtSnow].Ground.LoadFromFile(1, 'data\snow_normal.jpg');
  WorldTexture[wtSnow].Ground.LoadFromFile(2, 'data\snow_diffuse.jpg');
  WorldTexture[wtSnow].Ground.LoadFromFile(3, 'data\snow_bump.jpg');
                                                                    }

  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\snow\tex_d.png', WorldTexture[wtSnow].Ground);
  WorldTexture[wtSnow].Ground.LoadFromFile(1, 'data\snow\tex_n.png');
  WorldTexture[wtSnow].Ground.LoadFromFile(2, 'data\snow\snow_diffuse.jpg');
  WorldTexture[wtSnow].Ground.LoadFromFile(3, 'data\snow\tex_b.png');

  WorldTexture[wtSnow].Floor := WorldTexture[wtSnow].Ground;

  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\snow\5216-diffuse.jpg', WorldTexture[wtSnow].Floor);
  WorldTexture[wtSnow].Floor.LoadFromFile(1, 'data\snow\5216-normal.jpg');
  WorldTexture[wtSnow].Floor.LoadFromFile(2, 'data\snow\5216-specular.jpg');
  WorldTexture[wtSnow].Floor.LoadFromFile(3, 'data\snow\5216-bump.jpg');

  WorldTexture[wtDirt].Floor := WorldTexture[wtSnow].Floor;

  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\snow\Rock3.png', WorldTexture[wtSnow].Rock3);
  WorldTexture[wtSnow].Rock3.LoadFromFile(1, 'data\snow\rock3_normal.png');
//  WorldTexture[wtSnow].Rock3.LoadFromFile(2, 'data\snow\Rock3.png');
  WorldTexture[wtSnow].Rock3.LoadFromFile(3, 'data\snow\rock3_bump.png');

  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\destiny\tex.jpg', WorldTexture[wtDestiny].Ground);
  WorldTexture[wtDestiny].Ground.LoadFromFile(1, 'data\destiny\tex_n.jpg');
  WorldTexture[wtDestiny].Ground.LoadFromFile(2, 'data\destiny\tex_s.jpg');
  WorldTexture[wtDestiny].Ground.LoadFromFile(3, 'data\destiny\tex_b.jpg');

  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\sgate_d.png', sgate);
  sgate.LoadFromFile(1, 'data\sgate_n.png');
  sgate.LoadFromFile(2, 'data\sgate_h.png');
  sgate.LoadFromFile(3, 'data\sgate_h.png');

  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\exit.png', exit);
  exit.LoadFromFile(1, 'data\exit_n.png');
  exit.LoadFromFile(2, 'data\exit_h.png');
  exit.LoadFromFile(3, 'data\exit_h.png');

  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\destiny\bg.jpg', WorldTexture[wtDestiny].Bg);


  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\hero.png', Hero, 32, 32);
  Hero.LoadFromFile(1, 'data\hero_n.png', 32, 32);
  Hero.LoadFromFile(2, 'data\hero_s.png', 32, 32);
  Hero.LoadFromFile(3, 'data\hero_h.png', 32, 32);

  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\portraits.png', Portraits, 80, 100);

  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\subjects.png', SubjectsLight, 64, 64);

  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\subjects.png', Subjects, 64, 64);
  Subjects.LoadFromFile(1, 'data\subjects_n.png', 64, 64);
  Subjects.LoadFromFile(2, 'data\subjects_h.png', 64, 64);
  Subjects.LoadFromFile(3, 'data\subjects_h.png', 64, 64);

  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\FTL.jpg', FTL);
  FTL.LoadFromFile(1, 'data\FTLflow.png');

  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\planet.png', Planet);
  Planet.LoadFromFile(1, 'data\dudv.png');

  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\shield.jpg', Shield);
  Shield.LoadFromFile(1, 'data\dudv_shield.png');

  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\console\1.png', Console[0]);
  Console[0].LoadFromFile(1, 'data\console\normal.png');
  Console[0].LoadFromFile(2, 'data\console\specular.png');
  Console[0].LoadFromFile(3, 'data\console\height.png');
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\console\2.png', Console[1]);
  Console[1].AssignTexture(Console[0], 1, 1);
  Console[1].AssignTexture(Console[0], 2, 2);
  Console[1].AssignTexture(Console[0], 3, 3);
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\console\3.png', Console[2]);
  Console[2].AssignTexture(Console[0], 1, 1);
  Console[2].AssignTexture(Console[0], 2, 2);
  Console[2].AssignTexture(Console[0], 3, 3);
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\console\4.png', Console[3]);
  Console[3].AssignTexture(Console[0], 1, 1);
  Console[3].AssignTexture(Console[0], 2, 2);
  Console[3].AssignTexture(Console[0], 3, 3);
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\console\5.png', Console[4]);
  Console[4].AssignTexture(Console[0], 1, 1);
  Console[4].AssignTexture(Console[0], 2, 2);
  Console[4].AssignTexture(Console[0], 3, 3);
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\console\6.png', Console[5]);
  Console[5].AssignTexture(Console[0], 1, 1);
  Console[5].AssignTexture(Console[0], 2, 2);
  Console[5].AssignTexture(Console[0], 3, 3);


  TGlobals.QuadDevice.CreateRenderTarget(TGlobals.LightSize, TGlobals.LightSize, LightsBarriers, 0);
  TGlobals.QuadDevice.CreateRenderTarget(TGlobals.LightSize, TGlobals.LightSize, LightsBarriersRT1, 0);
  for i := 1 to 4 do
    TGlobals.QuadDevice.CreateRenderTarget(TGlobals.LightSize shr (i * 2), TGlobals.LightSize, LightsBarriersDS[i - 1], 0);

  TGlobals.QuadDevice.CreateRenderTarget(TGlobals.GWidth, TGlobals.GHeight, ShadowMap, 0);

  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\Mask.png', Mask, 24, 24);


  Bots[bmMutent].Frames[baStep] := 52;
  Bots[bmMutent].Frames[baRun] := 29;
  Bots[bmMutent].Frames[baAtack] := 36;
  Bots[bmMutent].Frames[baDeath] := 32;
  Bots[bmMutent].Frames[baDead] := 1;
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\Mutant\Step.png', Bots[bmMutent].Textures[baStep], 128, 128);
  Bots[bmMutent].Textures[baStep].LoadFromFile(1, 'data\Mutant\Step_n.png', 128, 128);
  Bots[bmMutent].Textures[baStep].LoadFromFile(2, 'data\Mutant\Step_h.png', 128, 128);
  Bots[bmMutent].Textures[baStep].LoadFromFile(3, 'data\Mutant\Step_h.png', 128, 128);
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\Mutant\Run.png', Bots[bmMutent].Textures[baRun], 128, 128);
  Bots[bmMutent].Textures[baRun].LoadFromFile(1, 'data\Mutant\Run_n.png', 128, 128);
  Bots[bmMutent].Textures[baRun].LoadFromFile(2, 'data\Mutant\Run_h.png', 128, 128);
  Bots[bmMutent].Textures[baRun].LoadFromFile(3, 'data\Mutant\Run_h.png', 128, 128);
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\Mutant\Atack.png', Bots[bmMutent].Textures[baAtack], 128, 128);
  Bots[bmMutent].Textures[baAtack].LoadFromFile(1, 'data\Mutant\Atack_n.png', 128, 128);
  Bots[bmMutent].Textures[baAtack].LoadFromFile(2, 'data\Mutant\Atack_h.png', 128, 128);
  Bots[bmMutent].Textures[baAtack].LoadFromFile(3, 'data\Mutant\Atack_h.png', 128, 128);
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\Mutant\Death.png', Bots[bmMutent].Textures[baDeath], 128, 128);
  Bots[bmMutent].Textures[baDeath].LoadFromFile(1, 'data\Mutant\Death_n.png', 128, 128);
  Bots[bmMutent].Textures[baDeath].LoadFromFile(2, 'data\Mutant\Death_h.png', 128, 128);
  Bots[bmMutent].Textures[baDeath].LoadFromFile(3, 'data\Mutant\Death_h.png', 128, 128);
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\Mutant\Dead.png', Bots[bmMutent].Textures[baDead], 128, 128);
  Bots[bmMutent].Textures[baDead].LoadFromFile(1, 'data\Mutant\Dead_n.png', 128, 128);
  Bots[bmMutent].Textures[baDead].LoadFromFile(2, 'data\Mutant\Dead_h.png', 128, 128);
  Bots[bmMutent].Textures[baDead].LoadFromFile(3, 'data\Mutant\Dead_h.png', 128, 128);

  Bots[bmBigMutent].Frames[baStep] := 89;
  Bots[bmBigMutent].Frames[baRun] := 34;
  Bots[bmBigMutent].Frames[baAtack] := 48;
  Bots[bmBigMutent].Frames[baDeath] := 32;
  Bots[bmBigMutent].Frames[baDead] := 1;
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\Mutant1\Step.png', Bots[bmBigMutent].Textures[baStep], 128, 128);
  Bots[bmBigMutent].Textures[baStep].LoadFromFile(1, 'data\Mutant1\Step_n.png', 128, 128);
  Bots[bmBigMutent].Textures[baStep].LoadFromFile(2, 'data\Mutant1\Step_h.png', 128, 128);
  Bots[bmBigMutent].Textures[baStep].LoadFromFile(3, 'data\Mutant1\Step_h.png', 128, 128);
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\Mutant1\Run.png', Bots[bmBigMutent].Textures[baRun], 128, 128);
  Bots[bmBigMutent].Textures[baRun].LoadFromFile(1, 'data\Mutant1\Run_n.png', 128, 128);
  Bots[bmBigMutent].Textures[baRun].LoadFromFile(2, 'data\Mutant1\Run_h.png', 128, 128);
  Bots[bmBigMutent].Textures[baRun].LoadFromFile(3, 'data\Mutant1\Run_h.png', 128, 128);
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\Mutant1\Atack.png', Bots[bmBigMutent].Textures[baAtack], 128, 128);
  Bots[bmBigMutent].Textures[baAtack].LoadFromFile(1, 'data\Mutant1\Atack_n.png', 128, 128);
  Bots[bmBigMutent].Textures[baAtack].LoadFromFile(2, 'data\Mutant1\Atack_h.png', 128, 128);
  Bots[bmBigMutent].Textures[baAtack].LoadFromFile(3, 'data\Mutant1\Atack_h.png', 128, 128);
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\Mutant1\Death.png', Bots[bmBigMutent].Textures[baDeath], 128, 128);
  Bots[bmBigMutent].Textures[baDeath].LoadFromFile(1, 'data\Mutant1\Death_n.png', 128, 128);
  Bots[bmBigMutent].Textures[baDeath].LoadFromFile(2, 'data\Mutant1\Death_h.png', 128, 128);
  Bots[bmBigMutent].Textures[baDeath].LoadFromFile(3, 'data\Mutant1\Death_h.png', 128, 128);
  TGlobals.QuadDevice.CreateAndLoadTexture(0, 'data\Mutant1\Dead.png', Bots[bmBigMutent].Textures[baDead], 128, 128);
  Bots[bmBigMutent].Textures[baDead].LoadFromFile(1, 'data\Mutant1\Dead_n.png', 128, 128);
  Bots[bmBigMutent].Textures[baDead].LoadFromFile(2, 'data\Mutant1\Dead_h.png', 128, 128);
  Bots[bmBigMutent].Textures[baDead].LoadFromFile(3, 'data\Mutant1\Dead_h.png', 128, 128);

  TGlobals.QuadDevice.CreateGBuffer(TTextures.QuadGBuffer);
end;

{ TEffects }

class procedure TEffects.Load;
begin
  QuadFXManager := CreateQuadFXManager(TGlobals.QuadDevice);

  QuadFXManager.CreateLayer(QuadFXLayer);

  QuadFXManager.CreateAtlas(QuadFXAtlas);
  QuadFXAtlas.LoadFromFile('Atlas', 'data\Effects.json');

  QuadFXManager.CreateEffectParams(Explosion);
  Explosion.LoadFromFile('Explosion', 'data\Effects.json');

  QuadFXManager.CreateEffectParams(BulletShot);
  BulletShot.LoadFromFile('BulletShot', 'data\Effects.json');
end;

class procedure TEffects.UnLoad;
begin
  BulletShot := nil;
  Explosion := nil;
  QuadFXAtlas := nil;
  QuadFXLayer := nil;
  QuadFXManager := nil;
end;

{ TShaders }

class procedure TShaders.Load;
begin
  TGlobals.QuadDevice.CreateShader(Lights);
  Lights.LoadPixelShader('data\lights.bin');

  TGlobals.QuadDevice.CreateShader(GateOpen);
  GateOpen.LoadPixelShader('data\GateOpen.bin');

  TGlobals.QuadDevice.CreateShader(FTL);
  FTL.LoadPixelShader('data\FTL.bin');

  TGlobals.QuadDevice.CreateShader(LightTrace.pass1);
  LightTrace.pass1.LoadPixelShader('data\Light1pass.bin');
  TGlobals.QuadDevice.CreateShader(LightTrace.pass2);
  LightTrace.pass2.LoadPixelShader('data\Light2pass.bin');
  TGlobals.QuadDevice.CreateShader(LightTrace.pass3);
  LightTrace.pass3.LoadPixelShader('data\Light3pass.bin');
  TGlobals.QuadDevice.CreateShader(LightTrace.pass4);
  LightTrace.pass4.LoadPixelShader('data\Light4pass.bin');
  TGlobals.QuadDevice.CreateShader(LightTrace.pass5);
  LightTrace.pass5.LoadPixelShader('data\Light5pass.bin');
  TGlobals.QuadDevice.CreateShader(LightTrace.pass6);
  LightTrace.pass6.LoadPixelShader('data\Light6pass.bin');

  TGlobals.QuadDevice.CreateShader(Planet);
  Planet.LoadPixelShader('data\dudv_spherize.bin');
end;

class procedure TShaders.UnLoad;
begin
  Lights := nil;
  GateOpen := nil;
  FTL := nil;
  LightTrace.pass1 := nil;
  LightTrace.pass2 := nil;
  LightTrace.pass3 := nil;
  LightTrace.pass4 := nil;
  LightTrace.pass5 := nil;
  LightTrace.pass6 := nil;
  Planet := nil;
end;

{ TSounds }

class procedure TSounds.Load;
begin
  Gate.Roll := BASS_SampleLoad(False, PAnsiChar('Sounds\Fast_Gate_Roll.mp3'), 0, 0, 16, 0);
  Gate.Chevron := BASS_SampleLoad(False, PAnsiChar('Sounds\Chevron.mp3'), 0, 0, 16, 0);
  Gate.Open := BASS_SampleLoad(False, PAnsiChar('Sounds\Gate_Open.mp3'), 0, 0, 16, 0);
  Gate.Close := BASS_SampleLoad(False, PAnsiChar('Sounds\Gate_Close.mp3'), 0, 0, 16, 0);
  Gate.BeginRoll := BASS_SampleLoad(False, PAnsiChar('Sounds\Stargate Begin Roll.mp3'), 0, 0, 16, 0);
end;

class procedure TSounds.UnLoad;
begin
  BASS_Stop;
  BASS_Free;
end;

class function TSounds.Play(ASample: HSAMPLE): Cardinal;
begin
  Result := BASS_SampleGetChannel(ASample, False);
  BASS_ChannelPlay(Result, True);
end;

class procedure TSounds.Stop(ASample: HSAMPLE);
begin
  BASS_ChannelStop(ASample);
end;

end.
