Engine loads fine with basic config physfslayer
authorunc0rr
Wed, 14 Nov 2012 23:27:33 +0400
branchphysfslayer
changeset 8028 dc30104660d3
parent 8025 07862ab415c8
child 8031 fc40b343c45c
Engine loads fine with basic config
hedgewars/SDLh.pas
hedgewars/uLandObjects.pas
hedgewars/uLocale.pas
hedgewars/uPhysFSLayer.pas
hedgewars/uStore.pas
--- a/hedgewars/SDLh.pas	Wed Nov 14 22:45:36 2012 +0400
+++ b/hedgewars/SDLh.pas	Wed Nov 14 23:27:33 2012 +0400
@@ -1004,7 +1004,7 @@
 function  TTF_RenderUTF8_Blended(font: PTTF_Font; const text: PChar; fg: TSDL_Color): PSDL_Surface; cdecl; external SDL_TTFLibName;
 function  TTF_RenderUTF8_Shaded(font: PTTF_Font; const text: PChar; fg, bg: TSDL_Color): PSDL_Surface; cdecl; external SDL_TTFLibName;
 
-function  TTF_OpenFontRW(const filename: PChar; freesrc: LongBool; size: LongInt): PTTF_Font; cdecl; external SDL_TTFLibName;
+function  TTF_OpenFontRW(src: PSDL_RWops; freesrc: LongBool; size: LongInt): PTTF_Font; cdecl; external SDL_TTFLibName;
 procedure TTF_SetFontStyle(font: PTTF_Font; style: LongInt); cdecl; external SDL_TTFLibName;
 
 (*  SDL_mixer  *)
--- a/hedgewars/uLandObjects.pas	Wed Nov 14 22:45:36 2012 +0400
+++ b/hedgewars/uLandObjects.pas	Wed Nov 14 23:27:33 2012 +0400
@@ -30,8 +30,9 @@
 procedure AddOnLandObjects(Surface: PSDL_Surface);
 
 implementation
-uses uStore, uConsts, uConsole, uRandom, uSound, GLunit,
-     uTypes, uVariables, uUtils, uDebug, SysUtils;
+uses uStore, uConsts, uConsole, uRandom, uSound, GLunit
+     , uTypes, uVariables, uUtils, uDebug, SysUtils
+     , uPhysFSLayer;
 
 const MaxRects = 512;
       MAXOBJECTRECTS = 16;
@@ -399,7 +400,7 @@
 
 procedure ReadThemeInfo(var ThemeObjects: TThemeObjects; var SprayObjects: TSprayObjects);
 var s, key: shortstring;
-    f: textfile;
+    f: PFSFile;
     i: LongInt;
     ii, t: Longword;
     c2: TSDL_Color;
@@ -431,17 +432,15 @@
 
 s:= cPathz[ptCurrTheme] + '/' + cThemeCFGFilename;
 WriteLnToConsole('Reading objects info...');
-Assign(f, s);
-{$I-}
-filemode:= 0; // readonly
-Reset(f);
+f:= pfsOpenRead(s);
+TryDo(f <> nil, 'Bad data or cannot access file ' + cThemeCFGFilename, true);
 
 ThemeObjects.Count:= 0;
 SprayObjects.Count:= 0;
 
-while not eof(f) do
+while not pfsEOF(f) do
     begin
-    Readln(f, s);
+    pfsReadLn(f, s);
     if Length(s) = 0 then
         continue;
     if s[1] = ';' then
@@ -736,9 +735,7 @@
         end
     end;
 
-Close(f);
-{$I+}
-TryDo(IOResult = 0, 'Bad data or cannot access file ' + cThemeCFGFilename, true);
+pfsClose(f);
 AddProgress;
 end;
 
--- a/hedgewars/uLocale.pas	Wed Nov 14 22:45:36 2012 +0400
+++ b/hedgewars/uLocale.pas	Wed Nov 14 23:27:33 2012 +0400
@@ -34,14 +34,14 @@
 {$ENDIF}
 
 implementation
-uses uRandom, uUtils, uVariables, uDebug;
+uses uRandom, uUtils, uVariables, uDebug, uPhysFSLayer;
 
 var trevt: array[TEventId] of array [0..Pred(MAX_EVENT_STRINGS)] of ansistring;
     trevt_n: array[TEventId] of integer;
 
 procedure LoadLocale(FileName: shortstring);
-var s: ansistring;
-    f: textfile;
+var s: shortstring;
+    f: pfsFile;
     a, b, c: LongInt;
     first: array[TEventId] of boolean;
     e: TEventId;
@@ -51,18 +51,14 @@
 for e:= Low(TEventId) to High(TEventId) do
     first[e]:= true;
 
-{$I-} // iochecks off
-Assign(f, FileName);
-filemode:= 0; // readonly
-Reset(f);
-if IOResult = 0 then
-    loaded:= true;
-TryDo(loaded, 'Cannot load locale "' + FileName + '"', false);
-if loaded then
+f:= pfsOpenRead(FileName);
+TryDo(f <> nil, 'Cannot load locale "' + FileName + '"', false);
+
+if f <> nil then
     begin
-    while not eof(f) do
+    while not pfsEof(f) do
         begin
-        readln(f, s);
+        pfsReadLn(f, s);
         if Length(s) = 0 then
             continue;
         if (s[1] < '0') or (s[1] > '9') then
@@ -99,9 +95,8 @@
                 trgoal[TGoalStrId(b)]:= s;
            end;
        end;
-   Close(f);
+   pfsClose(f);
    end;
-{$I+}
 end;
 
 function GetEventString(e: TEventId): ansistring;
--- a/hedgewars/uPhysFSLayer.pas	Wed Nov 14 22:45:36 2012 +0400
+++ b/hedgewars/uPhysFSLayer.pas	Wed Nov 14 23:27:33 2012 +0400
@@ -9,9 +9,17 @@
 procedure initModule;
 procedure freeModule;
 
+type PFSFile = pointer;
+
 function rwopsOpenRead(fname: shortstring): PSDL_RWops;
 function rwopsOpenWrite(fname: shortstring): PSDL_RWops;
 
+function pfsOpenRead(fname: shortstring): PFSFile;
+function pfsEOF(f: PFSFile): boolean;
+function pfsClose(f: PFSFile): boolean;
+
+procedure pfsReadLn(f: PFSFile; var s: shortstring);
+
 implementation
 uses uUtils, uVariables;
 
@@ -21,6 +29,10 @@
 function PHYSFSRWOPS_openWrite(fname: PChar): PSDL_RWops; cdecl; external;
 
 function PHYSFS_mount(newDir, mountPoint: PChar; appendToPath: LongBool) : LongInt; cdecl; external;
+function PHYSFS_openRead(fname: PChar): PFSFile; cdecl; external;
+function PHYSFS_eof(f: PFSFile): LongBool; cdecl; external;
+function PHYSFS_read(f: PFSFile; buf: pointer; objSize, objCount: Longword): Int64; cdecl; external;
+function PHYSFS_close(f: PFSFile): LongBool; cdecl; external;
 
 function rwopsOpenRead(fname: shortstring): PSDL_RWops;
 begin
@@ -32,6 +44,35 @@
     exit(PHYSFSRWOPS_openWrite(Str2PChar(fname)));
 end;
 
+function pfsOpenRead(fname: shortstring): PFSFile;
+begin
+    exit(PHYSFS_openRead(Str2PChar(fname)));
+end;
+
+function pfsEOF(f: PFSFile): boolean;
+begin
+    exit(PHYSFS_eof(f))
+end;
+
+function pfsClose(f: PFSFile): boolean;
+begin
+    exit(PHYSFS_close(f))
+end;
+
+
+procedure pfsReadLn(f: PFSFile; var s: shortstring);
+var c: char;
+begin
+s[0]:= #0;
+
+while (PHYSFS_read(f, @c, 1, 1) = 1) and (c <> #10) do
+    if (c <> #13) and (s[0] < #255) then
+        begin
+        inc(s[0]);
+        s[byte(s[0])]:= c
+        end
+end;
+
 procedure initModule;
 var i: LongInt;
 begin
--- a/hedgewars/uStore.pas	Wed Nov 14 22:45:36 2012 +0400
+++ b/hedgewars/uStore.pas	Wed Nov 14 23:27:33 2012 +0400
@@ -312,7 +312,7 @@
             begin
             s:= cPathz[ptFonts] + '/' + Name;
             WriteToConsole(msgLoading + s + ' (' + inttostr(Height) + 'pt)... ');
-            Handle:= TTF_OpenFontRW(Str2PChar(s), true, Height);
+            Handle:= TTF_OpenFontRW(rwopsOpenRead(s), true, Height);
             SDLTry(Handle <> nil, true);
             TTF_SetFontStyle(Handle, style);
             WriteLnToConsole(msgOK)