# HG changeset patch # User unc0rr # Date 1352839289 -14400 # Node ID 10b3b93c1f568c13bdb811880e2fd4d77b61df9f # Parent b216953c261722bcc0f39d78c6f235b999b0ada0 - Add physfsrwops library - Load images via physfs (crashes) diff -r b216953c2617 -r 10b3b93c1f56 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) diff -r b216953c2617 -r 10b3b93c1f56 hedgewars/CMakeLists.txt --- 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 diff -r b216953c2617 -r 10b3b93c1f56 hedgewars/SDLh.pas --- 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; diff -r b216953c2617 -r 10b3b93c1f56 hedgewars/uPhysFSLayer.pas --- 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; diff -r b216953c2617 -r 10b3b93c1f56 hedgewars/uStore.pas --- 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; diff -r b216953c2617 -r 10b3b93c1f56 hedgewars/uVariables.pas --- 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 = ( diff -r b216953c2617 -r 10b3b93c1f56 misc/physfs/extras/CMakeLists.txt --- /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)