- Add physfsrwops library physfslayer
authorunc0rr
Wed, 14 Nov 2012 00:41:29 +0400
branchphysfslayer
changeset 8022 10b3b93c1f56
parent 8019 b216953c2617
child 8025 07862ab415c8
- Add physfsrwops library - Load images via physfs (crashes)
CMakeLists.txt
hedgewars/CMakeLists.txt
hedgewars/SDLh.pas
hedgewars/uPhysFSLayer.pas
hedgewars/uStore.pas
hedgewars/uVariables.pas
misc/physfs/extras/CMakeLists.txt
--- a/CMakeLists.txt	Tue Nov 13 23:21:46 2012 +0400
+++ b/CMakeLists.txt	Wed Nov 14 00:41:29 2012 +0400
@@ -249,6 +249,7 @@
 
 # physfs library
 add_subdirectory(misc/physfs)
+add_subdirectory(misc/physfs/extras)
 
 #Android related build scripts
 if(ANDROID)
--- a/hedgewars/CMakeLists.txt	Tue Nov 13 23:21:46 2012 +0400
+++ b/hedgewars/CMakeLists.txt	Wed Nov 14 00:41:29 2012 +0400
@@ -275,6 +275,7 @@
 
 # compile physfs before engine
 add_dependencies(${engine_output_name} physfs)
+add_dependencies(${engine_output_name} physfsrwops)
 
 #when ffmpeg/libav is found we need to compile it before engine
 #TODO: convert avwrapper to .pas unit so we can skip this step
--- a/hedgewars/SDLh.pas	Tue Nov 13 23:21:46 2012 +0400
+++ b/hedgewars/SDLh.pas	Wed Nov 14 00:41:29 2012 +0400
@@ -1048,9 +1048,9 @@
 procedure IMG_Quit; {$IFDEF SDL_IMAGE_NEWER}cdecl; external SDL_ImageLibName;{$ENDIF}
 
 function  IMG_Load(const _file: PChar): PSDL_Surface; cdecl; external SDL_ImageLibName;
-function  IMG_Load_RW(rwop: PSDL_RWops; freesrc: LongInt): PSDL_Surface; cdecl; external SDL_ImageLibName;
+function  IMG_Load_RW(rwop: PSDL_RWops; freesrc: LongBool): PSDL_Surface; cdecl; external SDL_ImageLibName;
 function  IMG_LoadPNG_RW(rwop: PSDL_RWops): PSDL_Surface; cdecl; external SDL_ImageLibName;
-function  IMG_LoadTyped_RW(rwop: PSDL_RWops; freesrc: LongInt; type_: PChar): PSDL_Surface; cdecl; external SDL_ImageLibName;
+function  IMG_LoadTyped_RW(rwop: PSDL_RWops; freesrc: LongBool; type_: PChar): PSDL_Surface; cdecl; external SDL_ImageLibName;
 
 (*  SDL_net  *)
 function  SDLNet_Init: LongInt; cdecl; external SDL_NetLibName;
--- a/hedgewars/uPhysFSLayer.pas	Tue Nov 13 23:21:46 2012 +0400
+++ b/hedgewars/uPhysFSLayer.pas	Wed Nov 14 00:41:29 2012 +0400
@@ -1,14 +1,19 @@
 unit uPhysFSLayer;
 
 {$LINKLIB ../bin/libphysfs.a}
+{$LINKLIB ../bin/libphysfsrwops.a}
 
 interface
+uses SDLh;
 
 procedure initModule;
 procedure freeModule;
 
+function PHYSFSRWOPS_openRead(fname: PChar): PSDL_RWops; cdecl; external;
+function PHYSFSRWOPS_openWrite(fname: PChar): PSDL_RWops; cdecl; external;
+
 implementation
-uses uUtils;
+uses uUtils, uVariables;
 
 function PHYSFS_init(argv0: PChar) : LongInt; cdecl; external;
 function PHYSFS_deinit() : LongInt; cdecl; external;
@@ -18,6 +23,9 @@
 procedure initModule;
 begin
     PHYSFS_init(Str2PChar(ParamStr(0)));
+
+    PHYSFS_mount(Str2PChar(PathPrefix), nil, true);
+    PHYSFS_mount(Str2PChar(UserPathPrefix), nil, true);
 end;
 
 procedure freeModule;
--- a/hedgewars/uStore.pas	Tue Nov 13 23:21:46 2012 +0400
+++ b/hedgewars/uStore.pas	Wed Nov 14 00:41:29 2012 +0400
@@ -56,9 +56,11 @@
 procedure SwapBuffers; {$IFDEF USE_VIDEO_RECORDING}cdecl{$ELSE}inline{$ENDIF};
 
 implementation
-uses uMisc, uConsole, uMobile, uVariables, uUtils, uTextures, uRender, uRenderUtils, uCommands,
-     uDebug{$IFDEF USE_CONTEXT_RESTORE}, uWorld{$ENDIF}
-     {$IF NOT DEFINED(SDL13) AND DEFINED(USE_VIDEO_RECORDING)}, glut {$ENDIF};
+uses uMisc, uConsole, uMobile, uVariables, uUtils, uTextures, uRender, uRenderUtils, uCommands
+    , uPhysFSLayer
+    , uDebug
+    {$IFDEF USE_CONTEXT_RESTORE}, uWorld{$ENDIF}
+    {$IF NOT DEFINED(SDL13) AND DEFINED(USE_VIDEO_RECORDING)}, glut {$ENDIF};
 
 //type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple);
 
@@ -564,7 +566,7 @@
     WriteToConsole(msgLoading + filename + '.png [flags: ' + inttostr(imageFlags) + '] ');
 
     s:= filename + '.png';
-    tmpsurf:= IMG_Load(Str2PChar(s));
+    tmpsurf:= IMG_Load_RW(PHYSFSRWOPS_openRead(Str2PChar(s)), true);
 
     if tmpsurf = nil then
     begin
@@ -596,13 +598,7 @@
 var tmpsurf: PSDL_Surface;
 begin
     // check for file in user dir (never critical)
-    tmpsurf:= LoadImage(UserPathz[path] + '/' + filename, imageFlags and (not ifCritical));
-
-    // if unsuccessful check data dir
-    if (tmpsurf = nil) then
-        tmpsurf:= LoadImage(Pathz[path] + '/' + filename, imageFlags);
-
-    LoadDataImage:= tmpsurf;
+    tmpsurf:= LoadImage(cPathz[path] + '/' + filename, imageFlags);
 end;
 
 
--- a/hedgewars/uVariables.pas	Tue Nov 13 23:21:46 2012 +0400
+++ b/hedgewars/uVariables.pas	Wed Nov 14 00:41:29 2012 +0400
@@ -225,27 +225,27 @@
     // these consts are here because they would cause circular dependencies in uConsts/uTypes
     cPathz: array[TPathType] of shortstring = (
         '',                              // ptNone
-        '',                              // ptData
-        'Graphics',                      // ptGraphics
-        'Themes',                        // ptThemes
-        'Themes/Bamboo',                 // ptCurrTheme
-        'Teams',                         // ptTeams
-        'Maps',                          // ptMaps
+        '/',                             // ptData
+        '/Graphics',                     // ptGraphics
+        '/Themes',                       // ptThemes
+        '/Themes/Bamboo',                // ptCurrTheme
+        '/Teams',                        // ptTeams
+        '/Maps',                         // ptMaps
         '',                              // ptMapCurrent
-        'Demos',                         // ptDemos
-        'Sounds',                        // ptSounds
-        'Graphics/Graves',               // ptGraves
-        'Fonts',                         // ptFonts
-        'Forts',                         // ptForts
-        'Locale',                        // ptLocale
-        'Graphics/AmmoMenu',             // ptAmmoMenu
-        'Graphics/Hedgehog',             // ptHedgehog
-        'Sounds/voices',                 // ptVoices
-        'Graphics/Hats',                 // ptHats
-        'Graphics/Flags',                // ptFlags
-        'Missions/Maps',                 // ptMissionMaps
-        'Graphics/SuddenDeath',           // ptSuddenDeath
-        'Graphics/Buttons'                // ptButton
+        '/Demos',                        // ptDemos
+        '/Sounds',                       // ptSounds
+        '/Graphics/Graves',              // ptGraves
+        '/Fonts',                        // ptFonts
+        '/Forts',                        // ptForts
+        '/Locale',                       // ptLocale
+        '/Graphics/AmmoMenu',            // ptAmmoMenu
+        '/Graphics/Hedgehog',            // ptHedgehog
+        '/Sounds/voices',                // ptVoices
+        '/Graphics/Hats',                // ptHats
+        '/Graphics/Flags',               // ptFlags
+        '/Missions/Maps',                // ptMissionMaps
+        '/Graphics/SuddenDeath',         // ptSuddenDeath
+        '/Graphics/Buttons'              // ptButton
     );
 
     Fontz: array[THWFont] of THHFont = (
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/misc/physfs/extras/CMakeLists.txt	Wed Nov 14 00:41:29 2012 +0400
@@ -0,0 +1,6 @@
+find_package(SDL REQUIRED)
+
+include_directories(${SDL_INCLUDE_DIR})
+include_directories(${CMAKE_SOURCE_DIR}/misc/physfs/src)
+
+add_library(physfsrwops STATIC physfsrwops.c)