Add a buffer for files opened with physfs for reading, fixes slow engine start
authorunc0rr
Wed, 25 Jan 2017 00:17:32 +0300
changeset 12122 cc2d2f910d5a
parent 12121 1dbdf05b01ee
child 12123 4027903ff3e7
Add a buffer for files opened with physfs for reading, fixes slow engine start
hedgewars/uPhysFSLayer.pas
--- a/hedgewars/uPhysFSLayer.pas	Sun Jan 15 19:35:41 2017 -0500
+++ b/hedgewars/uPhysFSLayer.pas	Wed Jan 25 00:17:32 2017 +0300
@@ -58,6 +58,7 @@
 function PHYSFS_seek(f: PFSFile; pos: QWord): LongBool; cdecl; external PhysfsLibName;
 function PHYSFS_flush(f: PFSFile): LongBool; cdecl; external PhysfsLibName;
 function PHYSFS_close(f: PFSFile): LongBool; cdecl; external PhysfsLibName;
+function PHYSFS_setBuffer(f: PFSFile; pos: QWord): LongBool; cdecl; external PhysfsLibName;
 function PHYSFS_exists(fname: PChar): LongBool; cdecl; external PhysfsLibName;
 function PHYSFS_mkdir(path: PChar): LongBool; cdecl; external PhysfsLibName;
 function PHYSFS_getLastError(): PChar; cdecl; external PhysfsLibName;
@@ -81,8 +82,12 @@
 end;
 
 function pfsOpenRead(fname: shortstring): PFSFile;
+var f: PFSFile;
 begin
-    exit(PHYSFS_openRead(Str2PChar(fname)));
+    f:= PHYSFS_openRead(Str2PChar(fname));
+    if f <> nil then
+        PHYSFS_setBuffer(f, 4096);
+    exit(f);
 end;
 
 function pfsOpenWrite(fname: shortstring): PFSFile;