DEADSOFTWARE

hashtable cosmetic updates
[d2df-sdl.git] / src / game / g_main.pas
index e0ecce92ad9c27c43c73748c797b6036cb461017..4e10356760d4b2e00a0e23d08083328120139343 100644 (file)
@@ -1,4 +1,19 @@
-{$MODE DELPHI}
+(* Copyright (C)  DooM 2D:Forever Developers
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *)
+{$INCLUDE ../shared/a_modes.inc}
 unit g_main;
 
 interface
@@ -25,7 +40,8 @@ uses
   e_graphics, e_input, g_game, g_console, g_gui,
   e_sound, g_options, g_sound, g_player,
   g_weapons, SysUtils, g_triggers, MAPDEF, g_map,
-  MAPSTRUCT, g_menu, g_language, g_net, utils;
+  g_menu, g_language, g_net,
+  utils, conbuf, envvars;
 
 var
   charbuff: Array [0..15] of Char;
@@ -42,22 +58,31 @@ begin
   ModelsDir := DataDir + 'models/';
   GameWAD := DataDir + 'Game.wad';
 
-  e_InitLog(GameDir + '/' + LOG_FILENAME, WM_NEWFILE);
+  e_InitLog(GameDir + '/' + LOG_FILENAME, TWriteMode.WM_NEWFILE);
 
-  e_WriteLog('Read config file', MSG_NOTIFY);
+  e_WriteLog('Read config file', TMsgType.Notify);
   g_Options_Read(GameDir + '/' + CONFIG_FILENAME);
 
-  e_WriteToStdOut := {$IFDEF HEADLESS}True;{$ELSE}False;{$ENDIF}
+{$IFDEF HEADLESS}
+  conbufDumpToStdOut := true;
+{$ENDIF}
+  e_WriteToStdOut := False; //{$IFDEF HEADLESS}True;{$ELSE}False;{$ENDIF}
 
   //GetSystemDefaultLCID()
 
   //e_WriteLog('Read language file', MSG_NOTIFY);
   //g_Language_Load(DataDir + gLanguage + '.txt');
-  e_WriteLog(gLanguage, MSG_NOTIFY);
+  e_WriteLog(gLanguage, TMsgType.Notify);
   g_Language_Set(gLanguage);
 
 {$IFDEF HEADLESS}
+ {$IFDEF USE_SDLMIXER}
+  sdlflags := SDL_INIT_TIMER or SDL_INIT_AUDIO or $00004000;
+  // HACK: shit this into env and hope for the best
+  SetEnvVar('SDL_AUDIODRIVER', 'dummy');
+ {$ELSE}
   sdlflags := SDL_INIT_TIMER or $00004000;
+ {$ENDIF}
 {$ELSE}
  {$IFDEF USE_SDLMIXER}
   sdlflags := SDL_INIT_EVERYTHING;
@@ -72,7 +97,7 @@ begin
   SDL_StartTextInput();
 {$ENDIF}
 
-  e_WriteLog('Entering SDLMain', MSG_NOTIFY);
+  e_WriteLog('Entering SDLMain', TMsgType.Notify);
 
 {$WARNINGS OFF}
   SDLMain();
@@ -82,31 +107,42 @@ begin
   SDL_StopTextInput();
 {$ENDIF}
 
-  e_WriteLog('Releasing SDL', MSG_NOTIFY);
+  e_WriteLog('Releasing SDL', TMsgType.Notify);
   SDL_Quit();
 end;
 
 procedure Init();
 var
   a: Integer;
+  NoSound: Boolean;
 begin
   Randomize;
 
-  e_WriteLog('Init Input', MSG_NOTIFY);
+{$IFDEF HEADLESS}
+ {$IFDEF USE_SDLMIXER}
+  NoSound := False; // hope env has set SDL_AUDIODRIVER to dummy
+ {$ELSE}
+  NoSound := True; // FMOD backend will sort it out
+ {$ENDIF}
+{$ELSE}
+  NoSound := False;
+{$ENDIF}
+
+  e_WriteLog('Init Input', TMsgType.Notify);
   e_InitInput();
 
   if (e_JoysticksAvailable > 0) then
-    e_WriteLog('Input: Joysticks available.', MSG_NOTIFY)
+    e_WriteLog('Input: Joysticks available.', TMsgType.Notify)
   else
-    e_WriteLog('Input: No Joysticks.', MSG_NOTIFY);
+    e_WriteLog('Input: No Joysticks.', TMsgType.Notify);
 
   if (not gNoSound) then
   begin
-    e_WriteLog('Initializing sound system', MSG_NOTIFY);
-    e_InitSoundSystem({$IFDEF HEADLESS}True{$ELSE}False{$ENDIF});
+    e_WriteLog('Initializing sound system', TMsgType.Notify);
+    e_InitSoundSystem(NoSound);
   end;
 
-  e_WriteLog('Init game', MSG_NOTIFY);
+  e_WriteLog('Init game', TMsgType.Notify);
   g_Game_Init();
 
   for a := 0 to 15 do charbuff[a] := ' ';
@@ -114,15 +150,15 @@ end;
 
 procedure Release();
 begin
-  e_WriteLog('Releasing engine', MSG_NOTIFY);
+  e_WriteLog('Releasing engine', TMsgType.Notify);
   e_ReleaseEngine();
 
-  e_WriteLog('Releasing Input', MSG_NOTIFY);
+  e_WriteLog('Releasing Input', TMsgType.Notify);
   e_ReleaseInput();
 
   if not gNoSound then
   begin
-    e_WriteLog('Releasing FMOD', MSG_NOTIFY);
+    e_WriteLog('Releasing FMOD', TMsgType.Notify);
     e_ReleaseSoundSystem();
   end;
 end;
@@ -214,12 +250,16 @@ label
   Cheated;
 var
   s, s2: string;
-  c: Char16;
+  c: ShortString;
   a: Integer;
 begin
+  {
   if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
     (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
     or g_Game_IsNet then Exit;
+  }
+  if not gGameOn then exit;
+  if not conIsCheatsEnabled then exit;
 
   s := 'SOUND_GAME_RADIO';
 
@@ -266,7 +306,8 @@ begin
         if gTriggers[a].TriggerType = TRIGGER_EXIT then
         begin
           gExitByTrigger := True;
-          g_Game_ExitLevel(gTriggers[a].Data.MapName);
+          //g_Game_ExitLevel(gTriggers[a].Data.MapName);
+          g_Game_ExitLevel(gTriggers[a].tgcMap);
           Break;
         end;
     goto Cheated;