Optional physfs compile, removed deprectaions.
This commit is contained in:
parent
2a3f5aaa6a
commit
b209774f7b
|
@ -5,14 +5,13 @@ SET(CMAKE_COLOR_MAKEFILE ON)
|
||||||
project(breakhack C)
|
project(breakhack C)
|
||||||
|
|
||||||
include(FindLua)
|
include(FindLua)
|
||||||
|
include(FindPhysFS)
|
||||||
include(cmake/FindSDL2.cmake)
|
include(cmake/FindSDL2.cmake)
|
||||||
include(cmake/FindSDL2_image.cmake)
|
include(cmake/FindSDL2_image.cmake)
|
||||||
include(cmake/FindSDL2_ttf.cmake)
|
include(cmake/FindSDL2_ttf.cmake)
|
||||||
include(cmake/FindSDL2_mixer.cmake)
|
include(cmake/FindSDL2_mixer.cmake)
|
||||||
include(cmake/FindCCache.cmake)
|
include(cmake/FindCCache.cmake)
|
||||||
|
|
||||||
add_subdirectory(physfs-3.0.1)
|
|
||||||
|
|
||||||
if (NOT WIN32)
|
if (NOT WIN32)
|
||||||
include(FindX11)
|
include(FindX11)
|
||||||
include(cmake/FindCheck.cmake)
|
include(cmake/FindCheck.cmake)
|
||||||
|
@ -23,8 +22,18 @@ configure_file(
|
||||||
"${PROJECT_BINARY_DIR}/config.h"
|
"${PROJECT_BINARY_DIR}/config.h"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (NOT PHYSFS_FOUND)
|
||||||
|
add_subdirectory(physfs-3.0.1)
|
||||||
|
include_directories(
|
||||||
|
physfs-3.0.1
|
||||||
|
)
|
||||||
|
else (NOT PHYSFS_FOUND)
|
||||||
|
include_directories(
|
||||||
|
${PHYSFS_INCLUDE_DIR}
|
||||||
|
)
|
||||||
|
endif (NOT PHYSFS_FOUND)
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
physfs-3.0.1/src
|
|
||||||
${PROJECT_BINARY_DIR}
|
${PROJECT_BINARY_DIR}
|
||||||
${LUA_INCLUDE_DIR}
|
${LUA_INCLUDE_DIR}
|
||||||
${SDL2_INCLUDE_DIR}
|
${SDL2_INCLUDE_DIR}
|
||||||
|
@ -87,7 +96,6 @@ add_executable(breakhack
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(breakhack
|
target_link_libraries(breakhack
|
||||||
physfs
|
|
||||||
${LUA_LIBRARY}
|
${LUA_LIBRARY}
|
||||||
${SDL2_LIBRARY}
|
${SDL2_LIBRARY}
|
||||||
${SDL2_IMAGE_LIBRARY}
|
${SDL2_IMAGE_LIBRARY}
|
||||||
|
@ -95,6 +103,16 @@ target_link_libraries(breakhack
|
||||||
${SDL2_MIXER_LIBRARY}
|
${SDL2_MIXER_LIBRARY}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (NOT PHYSFS_FOUND)
|
||||||
|
target_link_libraries(breakhack
|
||||||
|
physfs
|
||||||
|
)
|
||||||
|
else (NOT PHYSFS_FOUND)
|
||||||
|
target_link_libraries(breakhack
|
||||||
|
${PHYSFS_LIBRARY}
|
||||||
|
)
|
||||||
|
endif (NOT PHYSFS_FOUND)
|
||||||
|
|
||||||
if (NOT WIN32)
|
if (NOT WIN32)
|
||||||
target_link_libraries(breakhack
|
target_link_libraries(breakhack
|
||||||
${X11_LIBRARIES}
|
${X11_LIBRARIES}
|
||||||
|
|
|
@ -6,8 +6,10 @@
|
||||||
SDL_RWops *
|
SDL_RWops *
|
||||||
io_load_rwops(const char *path)
|
io_load_rwops(const char *path)
|
||||||
{
|
{
|
||||||
if (!PHYSFS_exists(path))
|
if (!PHYSFS_exists(path)) {
|
||||||
fatal("Unable to open file %s: %s", path, PHYSFS_getLastError());
|
PHYSFS_ErrorCode code = PHYSFS_getLastErrorCode();
|
||||||
|
fatal("Unable to open file %s: (%d) %s", path, code, PHYSFS_getErrorByCode(code));
|
||||||
|
}
|
||||||
|
|
||||||
return PHYSFSRWOPS_openRead(path);
|
return PHYSFSRWOPS_openRead(path);
|
||||||
}
|
}
|
||||||
|
|
|
@ -613,7 +613,7 @@ int main(int argc, char *argv[])
|
||||||
UNUSED(argc);
|
UNUSED(argc);
|
||||||
|
|
||||||
PHYSFS_init(argv[0]);
|
PHYSFS_init(argv[0]);
|
||||||
PHYSFS_addToSearchPath("assets", 0);
|
PHYSFS_mount("assets", NULL, 0);
|
||||||
|
|
||||||
if (!init())
|
if (!init())
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -37,11 +37,17 @@
|
||||||
#define RW_SEEK_END SEEK_END
|
#define RW_SEEK_END SEEK_END
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static const char *getLastPhysfsError(void)
|
||||||
|
{
|
||||||
|
const PHYSFS_ErrorCode err = PHYSFS_getLastErrorCode();
|
||||||
|
return (err) ? PHYSFS_getErrorByCode(err) : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
#if TARGET_SDL2
|
#if TARGET_SDL2
|
||||||
static Sint64 SDLCALL physfsrwops_size(struct SDL_RWops *rw)
|
static Sint64 SDLCALL physfsrwops_size(struct SDL_RWops *rw)
|
||||||
{
|
{
|
||||||
PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
|
PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
|
||||||
return (Sint64) PHYSFS_fileLength(handle);
|
return (Sint64) PHYSFS_fileLength(handle);
|
||||||
} /* physfsrwops_size */
|
} /* physfsrwops_size */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -52,192 +58,192 @@ static Sint64 SDLCALL physfsrwops_seek(struct SDL_RWops *rw, Sint64 offset, int
|
||||||
static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence)
|
static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
|
PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
|
||||||
PHYSFS_sint64 pos = 0;
|
PHYSFS_sint64 pos = 0;
|
||||||
|
|
||||||
if (whence == RW_SEEK_SET)
|
if (whence == RW_SEEK_SET)
|
||||||
pos = (PHYSFS_sint64) offset;
|
pos = (PHYSFS_sint64) offset;
|
||||||
|
|
||||||
else if (whence == RW_SEEK_CUR)
|
else if (whence == RW_SEEK_CUR)
|
||||||
{
|
{
|
||||||
const PHYSFS_sint64 current = PHYSFS_tell(handle);
|
const PHYSFS_sint64 current = PHYSFS_tell(handle);
|
||||||
if (current == -1)
|
if (current == -1)
|
||||||
{
|
{
|
||||||
SDL_SetError("Can't find position in file: %s",
|
|
||||||
PHYSFS_getLastError());
|
|
||||||
return -1;
|
|
||||||
} /* if */
|
|
||||||
|
|
||||||
if (offset == 0) /* this is a "tell" call. We're done. */
|
SDL_SetError("Can't find position in file: %s",
|
||||||
{
|
getLastPhysfsError());
|
||||||
#if TARGET_SDL2
|
return -1;
|
||||||
return (Sint64) current;
|
} /* if */
|
||||||
#else
|
|
||||||
return (int) current;
|
|
||||||
#endif
|
|
||||||
} /* if */
|
|
||||||
|
|
||||||
pos = current + ((PHYSFS_sint64) offset);
|
if (offset == 0) /* this is a "tell" call. We're done. */
|
||||||
} /* else if */
|
{
|
||||||
|
#if TARGET_SDL2
|
||||||
|
return (Sint64) current;
|
||||||
|
#else
|
||||||
|
return (int) current;
|
||||||
|
#endif
|
||||||
|
} /* if */
|
||||||
|
|
||||||
else if (whence == RW_SEEK_END)
|
pos = current + ((PHYSFS_sint64) offset);
|
||||||
{
|
} /* else if */
|
||||||
const PHYSFS_sint64 len = PHYSFS_fileLength(handle);
|
|
||||||
if (len == -1)
|
|
||||||
{
|
|
||||||
SDL_SetError("Can't find end of file: %s", PHYSFS_getLastError());
|
|
||||||
return -1;
|
|
||||||
} /* if */
|
|
||||||
|
|
||||||
pos = len + ((PHYSFS_sint64) offset);
|
else if (whence == RW_SEEK_END)
|
||||||
} /* else if */
|
{
|
||||||
|
const PHYSFS_sint64 len = PHYSFS_fileLength(handle);
|
||||||
|
if (len == -1)
|
||||||
|
{
|
||||||
|
SDL_SetError("Can't find end of file: %s", getLastPhysfsError());
|
||||||
|
return -1;
|
||||||
|
} /* if */
|
||||||
|
|
||||||
else
|
pos = len + ((PHYSFS_sint64) offset);
|
||||||
{
|
} /* else if */
|
||||||
SDL_SetError("Invalid 'whence' parameter.");
|
|
||||||
return -1;
|
|
||||||
} /* else */
|
|
||||||
|
|
||||||
if ( pos < 0 )
|
else
|
||||||
{
|
{
|
||||||
SDL_SetError("Attempt to seek past start of file.");
|
SDL_SetError("Invalid 'whence' parameter.");
|
||||||
return -1;
|
return -1;
|
||||||
} /* if */
|
} /* else */
|
||||||
|
|
||||||
if (!PHYSFS_seek(handle, (PHYSFS_uint64) pos))
|
|
||||||
{
|
|
||||||
SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
|
|
||||||
return -1;
|
|
||||||
} /* if */
|
|
||||||
|
|
||||||
#if TARGET_SDL2
|
if ( pos < 0 )
|
||||||
return (Sint64) pos;
|
{
|
||||||
#else
|
SDL_SetError("Attempt to seek past start of file.");
|
||||||
return (int) pos;
|
return -1;
|
||||||
#endif
|
} /* if */
|
||||||
|
|
||||||
|
if (!PHYSFS_seek(handle, (PHYSFS_uint64) pos))
|
||||||
|
{
|
||||||
|
SDL_SetError("PhysicsFS error: %s", getLastPhysfsError());
|
||||||
|
return -1;
|
||||||
|
} /* if */
|
||||||
|
|
||||||
|
#if TARGET_SDL2
|
||||||
|
return (Sint64) pos;
|
||||||
|
#else
|
||||||
|
return (int) pos;
|
||||||
|
#endif
|
||||||
} /* physfsrwops_seek */
|
} /* physfsrwops_seek */
|
||||||
|
|
||||||
|
|
||||||
#if TARGET_SDL2
|
#if TARGET_SDL2
|
||||||
static size_t SDLCALL physfsrwops_read(struct SDL_RWops *rw, void *ptr,
|
static size_t SDLCALL physfsrwops_read(struct SDL_RWops *rw, void *ptr,
|
||||||
size_t size, size_t maxnum)
|
size_t size, size_t maxnum)
|
||||||
#else
|
#else
|
||||||
static int physfsrwops_read(SDL_RWops *rw, void *ptr, int size, int maxnum)
|
static int physfsrwops_read(SDL_RWops *rw, void *ptr, int size, int maxnum)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
|
PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
|
||||||
const PHYSFS_uint64 readlen = (PHYSFS_uint64) (maxnum * size);
|
const PHYSFS_uint64 readlen = (PHYSFS_uint64) (maxnum * size);
|
||||||
const PHYSFS_sint64 rc = PHYSFS_readBytes(handle, ptr, readlen);
|
const PHYSFS_sint64 rc = PHYSFS_readBytes(handle, ptr, readlen);
|
||||||
if (rc != ((PHYSFS_sint64) readlen))
|
if (rc != ((PHYSFS_sint64) readlen))
|
||||||
{
|
{
|
||||||
if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */
|
if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */
|
||||||
{
|
{
|
||||||
SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
|
SDL_SetError("PhysicsFS error: %s", getLastPhysfsError());
|
||||||
|
|
||||||
#if TARGET_SDL2
|
#if TARGET_SDL2
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
return -1;
|
return -1;
|
||||||
#endif
|
#endif
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
#if TARGET_SDL2
|
#if TARGET_SDL2
|
||||||
return (size_t) rc / size;
|
return (size_t) rc / size;
|
||||||
#else
|
#else
|
||||||
return (int) rc / size;
|
return (int) rc / size;
|
||||||
#endif
|
#endif
|
||||||
} /* physfsrwops_read */
|
} /* physfsrwops_read */
|
||||||
|
|
||||||
|
|
||||||
#if TARGET_SDL2
|
#if TARGET_SDL2
|
||||||
static size_t SDLCALL physfsrwops_write(struct SDL_RWops *rw, const void *ptr,
|
static size_t SDLCALL physfsrwops_write(struct SDL_RWops *rw, const void *ptr,
|
||||||
size_t size, size_t num)
|
size_t size, size_t num)
|
||||||
#else
|
#else
|
||||||
static int physfsrwops_write(SDL_RWops *rw, const void *ptr, int size, int num)
|
static int physfsrwops_write(SDL_RWops *rw, const void *ptr, int size, int num)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
|
PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
|
||||||
const PHYSFS_uint64 writelen = (PHYSFS_uint64) (num * size);
|
const PHYSFS_uint64 writelen = (PHYSFS_uint64) (num * size);
|
||||||
const PHYSFS_sint64 rc = PHYSFS_writeBytes(handle, ptr, writelen);
|
const PHYSFS_sint64 rc = PHYSFS_writeBytes(handle, ptr, writelen);
|
||||||
if (rc != ((PHYSFS_sint64) writelen))
|
if (rc != ((PHYSFS_sint64) writelen))
|
||||||
SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
|
SDL_SetError("PhysicsFS error: %s", getLastPhysfsError());
|
||||||
|
|
||||||
#if TARGET_SDL2
|
#if TARGET_SDL2
|
||||||
return (size_t) rc;
|
return (size_t) rc;
|
||||||
#else
|
#else
|
||||||
return (int) rc;
|
return (int) rc;
|
||||||
#endif
|
#endif
|
||||||
} /* physfsrwops_write */
|
} /* physfsrwops_write */
|
||||||
|
|
||||||
|
|
||||||
static int physfsrwops_close(SDL_RWops *rw)
|
static int physfsrwops_close(SDL_RWops *rw)
|
||||||
{
|
{
|
||||||
PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
|
PHYSFS_File *handle = (PHYSFS_File *) rw->hidden.unknown.data1;
|
||||||
if (!PHYSFS_close(handle))
|
if (!PHYSFS_close(handle))
|
||||||
{
|
{
|
||||||
SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
|
SDL_SetError("PhysicsFS error: %s", getLastPhysfsError());
|
||||||
return -1;
|
return -1;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
SDL_FreeRW(rw);
|
SDL_FreeRW(rw);
|
||||||
return 0;
|
return 0;
|
||||||
} /* physfsrwops_close */
|
} /* physfsrwops_close */
|
||||||
|
|
||||||
|
|
||||||
static SDL_RWops *create_rwops(PHYSFS_File *handle)
|
static SDL_RWops *create_rwops(PHYSFS_File *handle)
|
||||||
{
|
{
|
||||||
SDL_RWops *retval = NULL;
|
SDL_RWops *retval = NULL;
|
||||||
|
|
||||||
if (handle == NULL)
|
if (handle == NULL)
|
||||||
SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
|
SDL_SetError("PhysicsFS error: %s", getLastPhysfsError());
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
retval = SDL_AllocRW();
|
retval = SDL_AllocRW();
|
||||||
if (retval != NULL)
|
if (retval != NULL)
|
||||||
{
|
{
|
||||||
#if TARGET_SDL2
|
#if TARGET_SDL2
|
||||||
retval->size = physfsrwops_size;
|
retval->size = physfsrwops_size;
|
||||||
#endif
|
#endif
|
||||||
retval->seek = physfsrwops_seek;
|
retval->seek = physfsrwops_seek;
|
||||||
retval->read = physfsrwops_read;
|
retval->read = physfsrwops_read;
|
||||||
retval->write = physfsrwops_write;
|
retval->write = physfsrwops_write;
|
||||||
retval->close = physfsrwops_close;
|
retval->close = physfsrwops_close;
|
||||||
retval->hidden.unknown.data1 = handle;
|
retval->hidden.unknown.data1 = handle;
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* else */
|
} /* else */
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
} /* create_rwops */
|
} /* create_rwops */
|
||||||
|
|
||||||
|
|
||||||
SDL_RWops *PHYSFSRWOPS_makeRWops(PHYSFS_File *handle)
|
SDL_RWops *PHYSFSRWOPS_makeRWops(PHYSFS_File *handle)
|
||||||
{
|
{
|
||||||
SDL_RWops *retval = NULL;
|
SDL_RWops *retval = NULL;
|
||||||
if (handle == NULL)
|
if (handle == NULL)
|
||||||
SDL_SetError("NULL pointer passed to PHYSFSRWOPS_makeRWops().");
|
SDL_SetError("NULL pointer passed to PHYSFSRWOPS_makeRWops().");
|
||||||
else
|
else
|
||||||
retval = create_rwops(handle);
|
retval = create_rwops(handle);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
} /* PHYSFSRWOPS_makeRWops */
|
} /* PHYSFSRWOPS_makeRWops */
|
||||||
|
|
||||||
|
|
||||||
SDL_RWops *PHYSFSRWOPS_openRead(const char *fname)
|
SDL_RWops *PHYSFSRWOPS_openRead(const char *fname)
|
||||||
{
|
{
|
||||||
return create_rwops(PHYSFS_openRead(fname));
|
return create_rwops(PHYSFS_openRead(fname));
|
||||||
} /* PHYSFSRWOPS_openRead */
|
} /* PHYSFSRWOPS_openRead */
|
||||||
|
|
||||||
|
|
||||||
SDL_RWops *PHYSFSRWOPS_openWrite(const char *fname)
|
SDL_RWops *PHYSFSRWOPS_openWrite(const char *fname)
|
||||||
{
|
{
|
||||||
return create_rwops(PHYSFS_openWrite(fname));
|
return create_rwops(PHYSFS_openWrite(fname));
|
||||||
} /* PHYSFSRWOPS_openWrite */
|
} /* PHYSFSRWOPS_openWrite */
|
||||||
|
|
||||||
|
|
||||||
SDL_RWops *PHYSFSRWOPS_openAppend(const char *fname)
|
SDL_RWops *PHYSFSRWOPS_openAppend(const char *fname)
|
||||||
{
|
{
|
||||||
return create_rwops(PHYSFS_openAppend(fname));
|
return create_rwops(PHYSFS_openAppend(fname));
|
||||||
} /* PHYSFSRWOPS_openAppend */
|
} /* PHYSFSRWOPS_openAppend */
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue