DEADSOFTWARE

Now android version can contain game resources in APK
[d2df-sdl.git] / src / game / Doom2DF.lpr
index 5f707e0d06c7d6a5bd47dd79721715d629367ab4..0b62430ad3d7c369f4dcf485b6f4fbb65f8e1f67 100644 (file)
@@ -14,7 +14,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *)
 {$INCLUDE ../shared/a_modes.inc}
-program Doom2DF;
+{$IFDEF ANDROID}library{$ELSE}program{$ENDIF} Doom2DF;
 {$IFNDEF HEADLESS}
   {$IFDEF WINDOWS}
     {$APPTYPE GUI}
@@ -32,12 +32,22 @@ program Doom2DF;
 {$ENDIF}
 
 uses
+{$IFDEF ANDROID}
+  ctypes,
+{$ENDIF}
+{$IFDEF UNIX}
+  cthreads,
+{$ENDIF}
   mempool in '../shared/mempool.pas',
   conbuf in '../shared/conbuf.pas',
   geom in '../shared/geom.pas',
   math,
+{$IFDEF USE_NANOGL}
+  nanoGL in '../lib/nanogl/nanoGL.pas',
+{$ELSE}
   GL,
   GLExt,
+{$ENDIF}
 {$IFDEF USE_MINIUPNPC}
   miniupnpc in '../lib/miniupnpc/miniupnpc.pas',
 {$ENDIF}
@@ -124,12 +134,33 @@ uses
   {$R *.res}
 {$ENDIF}
 
+{$IFDEF ANDROID}
+function SDL_main(argc: CInt; argv: PPChar): CInt; cdecl;
+{$ENDIF ANDROID}
+
 var
   f: Integer;
   noct: Boolean = false;
   //tfo: Text;
 begin
   SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow, exUnderflow, exPrecision]); //k8: fuck off, that's why
+
+{$IFDEF ANDROID}
+{$I-}
+  e_SetSafeSlowLog(true);
+  Chdir(SDL_AndroidGetExternalStoragePath());
+  if IOresult <> 0 then
+  begin
+    Chdir(SDL_AndroidGetInternalStoragePath());
+    if IOresult <> 0 then
+    begin
+      e_WriteLog('Fuck! Cant chdir to any game directory :(', TMsgType.Fatal);
+      result := 1;
+      exit;
+    end;
+  end;
+{$ENDIF ANDROID}
+
   for f := 1 to ParamCount do
   begin
          if ParamStr(f) = '--gdb' then noct := true
@@ -166,4 +197,10 @@ begin
     end;
   end;
   e_DeinitLog();
+
+{$IFDEF ANDROID}
+  result := 0;
+end; // SDL_main
+exports SDL_main;
+{$ENDIF ANDROID}
 end.