{$APPTYPE GUI}
{$MODE OBJFPC}
{$MODESWITCH DEFAULTPARAMETERS}
{$MODESWITCH OUT}
{$MODESWITCH RESULT}

{$I deng_app.inc} ant;
uses
  {$I deng_app_units.inc},
  dstrings,
  dansiview,
  dansibuffer,
  dansibuffer_ansiview,
  dstream,
  darg,
  dtypes,
  dflags,
  dfiles,
  dpool,
  dhashmap,
  dhashfuncs,
  dmath,
  dstreamfile,
  dvector2f,
  dvector3f,
  dvector2i,
  dvector4f,
  dquat4f,
  dmatrix4f,
  drect2i,
  drect2f,
  dintersect,
  dintersect3f,
  djson,
  dnode,
  djson_node,
  dstrnum,
  dcolors,
  dresize,
  DWinApi,
  DDrawUtils,
  DDrawTex,
  DDrawFont,
  DDrawVertexBuffer,
  DAudio,
  DControl,
  dengcache,
  dsprite,
  dpng,
  dogg,
  dscene,
  dgui3,
  dgui_simple,
  dgifrecorder,
  lua,
  dxml_sax,
  dtiled,
  dtiled_utils,
  dtiled_manager,
  ant_args,
  ant_config,
  ant_profile,
  ant_localizer,
  ant_gui,
  ant_world,
  ant_camera,
  ant_renderer,
  ant_main;

procedure LogStaticStats;
begin
  Log('SizeOf(TEntity) = ' + IntToStr(SizeOf(TEntity)));
end;

{$I deng_app_begin.inc}
try
  Randomize;

  if not ParseCommandLine then
    Halt(1);

  if CommandLineArgs.PrintStaticStats then
    LogStaticStats;

  if CommandLineArgs.OnlyHelp then begin
    PrintArgsHelp;
    Halt(0);
  end;

  if not Config.Load(CommandLineArgs.ConfigPath) then
    Halt(1);

  DetectDefaultLang;
  Log('Detected culture: ' + GetCurrentLang.ToString);
  LoadTranslations; // TODO load after config read

  if Config.CacheDirectory <> '' then begin
    if not dengSetCacheDirectory(Config.CacheDirectory) then
      Log('FAILED to set cache directory: ' + Config.CacheDirectory);
  end;

  if not CommandLineArgs.DryRun then
    AntMain;
except
  Eng.FlushLog;
  raise;
end;
{$I deng_app_end.inc}
