update physlayer and sdl bindings to the new rwops interface
authorkoda
Sat, 27 Jul 2013 01:06:47 +0200
changeset 9378 2be457289e60
parent 9377 48ab6dea8d2f
child 9379 1bcfcaf0926e
update physlayer and sdl bindings to the new rwops interface
hedgewars/SDLh.pas
hedgewars/uPhysFSLayer.pas
misc/libphyslayer/physfsrwops.c
--- a/hedgewars/SDLh.pas	Fri Jul 26 23:02:25 2013 +0200
+++ b/hedgewars/SDLh.pas	Sat Jul 27 01:06:47 2013 +0200
@@ -428,7 +428,12 @@
 
     (* SDL_RWops and friends *)
     PSDL_RWops = ^TSDL_RWops;
+{$IFDEF SDL2}
+    TSize  = function( context: PSDL_RWops): Int64; cdecl;
+    TSeek  = function( context: PSDL_RWops; offset: Int64; whence: LongInt ): Int64; cdecl;
+{$ELSE}
     TSeek  = function( context: PSDL_RWops; offset: LongInt; whence: LongInt ): LongInt; cdecl;
+{$ENDIF}
     TRead  = function( context: PSDL_RWops; Ptr: Pointer; size: LongInt; maxnum : LongInt ): LongInt;  cdecl;
     TWrite = function( context: PSDL_RWops; Ptr: Pointer; size: LongInt; num: LongInt ): LongInt; cdecl;
     TClose = function( context: PSDL_RWops ): LongInt; cdecl;
@@ -473,6 +478,9 @@
 {$ENDIF}
 
     TSDL_RWops = record
+{$IFDEF SDL2}
+        size: TSize;
+{$ENDIF}
         seek: TSeek;
         read: TRead;
         write: TWrite;
--- a/hedgewars/uPhysFSLayer.pas	Fri Jul 26 23:02:25 2013 +0200
+++ b/hedgewars/uPhysFSLayer.pas	Sat Jul 27 01:06:47 2013 +0200
@@ -133,7 +133,7 @@
 begin
 {$IFDEF HWLIBRARY}
     //TODO: http://icculus.org/pipermail/physfs/2011-August/001006.html
-    cPhysfsId:= GetCurrentDir() + {$IFDEF DARWIN}'/Hedgewars.app/Contents/MacOS/' + {$ENDIF} ' hedgewars';
+    cPhysfsId:= GetCurrentDir() + {$IFDEF DARWIN}{$IFNDEF IPHONEOS}'/Hedgewars.app/Contents/MacOS/' + {$ENDIF}{$ENDIF} ' hedgewars';
 {$ELSE}
     cPhysfsId:= ParamStr(0);
 {$ENDIF}
--- a/misc/libphyslayer/physfsrwops.c	Fri Jul 26 23:02:25 2013 +0200
+++ b/misc/libphyslayer/physfsrwops.c	Sat Jul 27 01:06:47 2013 +0200
@@ -32,6 +32,14 @@
 #endif
 
 #if TARGET_SDL13
+static SDLCALL Sint64 physfsrwops_size(struct SDL_RWops *rw)
+{
+    PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
+    return PHYSFS_fileLength(handle);
+}
+#endif
+
+#if TARGET_SDL13
 static SDLCALL Sint64 physfsrwops_seek(struct SDL_RWops *rw, Sint64 offset, int whence)
 #else
 static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence)
@@ -42,7 +50,6 @@
 
     if (whence == SEEK_SET)
         pos = (PHYSFS_sint64) offset;
-
     else if (whence == SEEK_CUR)
     {
         const PHYSFS_sint64 current = PHYSFS_tell(handle);
@@ -173,6 +180,9 @@
         retval = SDL_AllocRW();
         if (retval != NULL)
         {
+#if TARGET_SDL13
+            retval->size  = physfsrwops_size;
+#endif
             retval->seek  = physfsrwops_seek;
             retval->read  = physfsrwops_read;
             retval->write = physfsrwops_write;