Add buildvfs, abstraction layer for file I/O.

Currently it passes calls through to the system libraries as before.

Also adds an incomplete implementation on PhysFS.

git-svn-id: https://svn.eduke32.com/eduke32@7359 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2019-03-01 08:51:50 +00:00
parent 5c9b921285
commit 7414f29348
78 changed files with 1108 additions and 991 deletions

View file

@ -87,7 +87,6 @@ BUILD_SRC = \
source/build/src/palette.cpp \
MACT_SRC = \
source/mact/src/file_lib.cpp \
source/mact/src/control.cpp \
source/mact/src/keyboard.cpp \
source/mact/src/joystick.cpp \

View file

@ -340,6 +340,12 @@ HAVE_XMP := 1
RENDERTYPE := SDL
MIXERTYPE := SDL
SDL_TARGET := 2
USE_PHYSFS := 0
ifneq (0,$(USE_PHYSFS))
# PhysFS requires this to be off
override CPLUSPLUS := 0
endif
# Debugging/Build options
FORCEDEBUG := 0

View file

@ -89,6 +89,43 @@ lpeg_inc := $(lpeg_root)/include
lpeg_obj := $(obj)/$(lpeg)
#### PhysicsFS
physfs := physfs
physfs_objs := \
physfs.c \
physfs_archiver_7z.c \
physfs_archiver_dir.c \
physfs_archiver_grp.c \
physfs_archiver_hog.c \
physfs_archiver_iso9660.c \
physfs_archiver_mvl.c \
physfs_archiver_qpak.c \
physfs_archiver_slb.c \
physfs_archiver_unpacked.c \
physfs_archiver_vdf.c \
physfs_archiver_wad.c \
physfs_archiver_zip.c \
physfs_byteorder.c \
physfs_unicode.c \
ifeq ($(PLATFORM),APPLE)
physfs_objs += physfs_platform_apple.m
else ifeq ($(PLATFORM),WINDOWS)
physfs_objs += physfs_platform_windows.c
else
physfs_objs += physfs_platform_unix.c
endif
physfs_root := $(source)/$(physfs)
physfs_src := $(physfs_root)/src
physfs_inc := $(physfs_root)/include
physfs_obj := $(obj)/$(physfs)
physfs_cflags :=
#### ENet
enet := enet
@ -161,9 +198,14 @@ engine_cflags := -I$(engine_src)
engine_deps :=
ifneq (0,$(USE_PHYSFS))
engine_deps += physfs
endif
engine_objs := \
rev.cpp \
baselayer.cpp \
vfs.cpp \
cache1d.cpp \
klzw.cpp \
common.cpp \
@ -286,7 +328,6 @@ mact_inc := $(mact_root)/include
mact_obj := $(obj)/$(mact)
mact_objs := \
file_lib.cpp \
control.cpp \
keyboard.cpp \
joystick.cpp \
@ -786,6 +827,9 @@ endif
#### Final setup
COMPILERFLAGS += -I$(engine_inc) -I$(mact_inc) -I$(audiolib_inc) -I$(enet_inc) -I$(glad_inc)
ifneq (0,$(USE_PHYSFS))
COMPILERFLAGS += -I$(physfs_inc) -DUSE_PHYSFS
endif
##### Recipes
@ -804,6 +848,10 @@ libraries := \
lpeg \
glad \
ifneq (0,$(USE_PHYSFS))
libraries += physfs
endif
components := \
$(games) \
$(libraries) \

View file

@ -50,8 +50,6 @@
0008E73819F1ABB80091588D /* animlib.h in Headers */ = {isa = PBXBuildFile; fileRef = 0008E72619F1ABB80091588D /* animlib.h */; settings = {ATTRIBUTES = (Public, ); }; };
0008E73919F1ABB80091588D /* control.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0008E72719F1ABB80091588D /* control.cpp */; };
0008E73A19F1ABB80091588D /* control.h in Headers */ = {isa = PBXBuildFile; fileRef = 0008E72819F1ABB80091588D /* control.h */; settings = {ATTRIBUTES = (Public, ); }; };
0008E73B19F1ABB80091588D /* file_lib.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0008E72919F1ABB80091588D /* file_lib.cpp */; };
0008E73C19F1ABB80091588D /* file_lib.h in Headers */ = {isa = PBXBuildFile; fileRef = 0008E72A19F1ABB80091588D /* file_lib.h */; settings = {ATTRIBUTES = (Public, ); }; };
0008E73D19F1ABB80091588D /* joystick.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0008E72B19F1ABB80091588D /* joystick.cpp */; };
0008E73E19F1ABB80091588D /* joystick.h in Headers */ = {isa = PBXBuildFile; fileRef = 0008E72C19F1ABB80091588D /* joystick.h */; settings = {ATTRIBUTES = (Public, ); }; };
0008E73F19F1ABB80091588D /* keyboard.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0008E72D19F1ABB80091588D /* keyboard.cpp */; };
@ -314,13 +312,11 @@
001382E219F361B80007DA6C /* animlib.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0008E72519F1ABB80091588D /* animlib.cpp */; };
001382E319F361B80007DA6C /* control.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0008E72719F1ABB80091588D /* control.cpp */; };
001382E419F361B80007DA6C /* scriplib.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0008E73319F1ABB80091588D /* scriplib.cpp */; };
001382E719F361B80007DA6C /* file_lib.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0008E72919F1ABB80091588D /* file_lib.cpp */; };
001382E819F361B80007DA6C /* joystick.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0008E72B19F1ABB80091588D /* joystick.cpp */; };
001382EB19F361B80007DA6C /* mouse.h in Headers */ = {isa = PBXBuildFile; fileRef = 0008E73219F1ABB80091588D /* mouse.h */; settings = {ATTRIBUTES = (Public, ); }; };
001382ED19F361B80007DA6C /* joystick.h in Headers */ = {isa = PBXBuildFile; fileRef = 0008E72C19F1ABB80091588D /* joystick.h */; settings = {ATTRIBUTES = (Public, ); }; };
001382EE19F361B80007DA6C /* control.h in Headers */ = {isa = PBXBuildFile; fileRef = 0008E72819F1ABB80091588D /* control.h */; settings = {ATTRIBUTES = (Public, ); }; };
001382EF19F361B80007DA6C /* _scrplib.h in Headers */ = {isa = PBXBuildFile; fileRef = 0008E72419F1ABB80091588D /* _scrplib.h */; };
001382F019F361B80007DA6C /* file_lib.h in Headers */ = {isa = PBXBuildFile; fileRef = 0008E72A19F1ABB80091588D /* file_lib.h */; settings = {ATTRIBUTES = (Public, ); }; };
001382F119F361B80007DA6C /* scriplib.h in Headers */ = {isa = PBXBuildFile; fileRef = 0008E73419F1ABB80091588D /* scriplib.h */; settings = {ATTRIBUTES = (Public, ); }; };
001382F219F361B80007DA6C /* _control.h in Headers */ = {isa = PBXBuildFile; fileRef = 0008E72319F1ABB80091588D /* _control.h */; };
001382F319F361B80007DA6C /* animlib.h in Headers */ = {isa = PBXBuildFile; fileRef = 0008E72619F1ABB80091588D /* animlib.h */; settings = {ATTRIBUTES = (Public, ); }; };
@ -564,8 +560,6 @@
0008E72619F1ABB80091588D /* animlib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = animlib.h; path = ../../source/mact/include/animlib.h; sourceTree = SOURCE_ROOT; };
0008E72719F1ABB80091588D /* control.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.c; name = control.cpp; path = ../../source/mact/src/control.cpp; sourceTree = SOURCE_ROOT; };
0008E72819F1ABB80091588D /* control.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = control.h; path = ../../source/mact/include/control.h; sourceTree = SOURCE_ROOT; };
0008E72919F1ABB80091588D /* file_lib.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.c; name = file_lib.cpp; path = ../../source/mact/src/file_lib.cpp; sourceTree = SOURCE_ROOT; };
0008E72A19F1ABB80091588D /* file_lib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = file_lib.h; path = ../../source/mact/include/file_lib.h; sourceTree = SOURCE_ROOT; };
0008E72B19F1ABB80091588D /* joystick.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.c; name = joystick.cpp; path = ../../source/mact/src/joystick.cpp; sourceTree = SOURCE_ROOT; };
0008E72C19F1ABB80091588D /* joystick.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = joystick.h; path = ../../source/mact/include/joystick.h; sourceTree = SOURCE_ROOT; };
0008E72D19F1ABB80091588D /* keyboard.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.c; name = keyboard.cpp; path = ../../source/mact/src/keyboard.cpp; sourceTree = SOURCE_ROOT; };
@ -1161,8 +1155,6 @@
0008E72619F1ABB80091588D /* animlib.h */,
0008E72719F1ABB80091588D /* control.cpp */,
0008E72819F1ABB80091588D /* control.h */,
0008E72919F1ABB80091588D /* file_lib.cpp */,
0008E72A19F1ABB80091588D /* file_lib.h */,
0008E72B19F1ABB80091588D /* joystick.cpp */,
0008E72C19F1ABB80091588D /* joystick.h */,
0008E72D19F1ABB80091588D /* keyboard.cpp */,
@ -1509,7 +1501,6 @@
0008E73E19F1ABB80091588D /* joystick.h in Headers */,
0008E73A19F1ABB80091588D /* control.h in Headers */,
0008E73619F1ABB80091588D /* _scrplib.h in Headers */,
0008E73C19F1ABB80091588D /* file_lib.h in Headers */,
0008E74619F1ABB80091588D /* scriplib.h in Headers */,
0008E73519F1ABB80091588D /* _control.h in Headers */,
0008E73819F1ABB80091588D /* animlib.h in Headers */,
@ -1621,7 +1612,6 @@
001382ED19F361B80007DA6C /* joystick.h in Headers */,
001382EE19F361B80007DA6C /* control.h in Headers */,
001382EF19F361B80007DA6C /* _scrplib.h in Headers */,
001382F019F361B80007DA6C /* file_lib.h in Headers */,
001382F119F361B80007DA6C /* scriplib.h in Headers */,
001382F219F361B80007DA6C /* _control.h in Headers */,
001382F319F361B80007DA6C /* animlib.h in Headers */,
@ -2040,7 +2030,6 @@
0008E73719F1ABB80091588D /* animlib.cpp in Sources */,
0008E73919F1ABB80091588D /* control.cpp in Sources */,
0008E74519F1ABB80091588D /* scriplib.cpp in Sources */,
0008E73B19F1ABB80091588D /* file_lib.cpp in Sources */,
0008E73D19F1ABB80091588D /* joystick.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@ -2173,7 +2162,6 @@
001382E219F361B80007DA6C /* animlib.cpp in Sources */,
001382E319F361B80007DA6C /* control.cpp in Sources */,
001382E419F361B80007DA6C /* scriplib.cpp in Sources */,
001382E719F361B80007DA6C /* file_lib.cpp in Sources */,
001382E819F361B80007DA6C /* joystick.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

View file

@ -21,7 +21,6 @@
<ItemGroup>
<ClCompile Include="..\..\source\mact\src\animlib.cpp" />
<ClCompile Include="..\..\source\mact\src\control.cpp" />
<ClCompile Include="..\..\source\mact\src\file_lib.cpp" />
<ClCompile Include="..\..\source\mact\src\joystick.cpp" />
<ClCompile Include="..\..\source\mact\src\keyboard.cpp" />
<ClCompile Include="..\..\source\mact\src\scriplib.cpp" />
@ -29,7 +28,6 @@
<ItemGroup>
<ClInclude Include="..\..\source\mact\include\animlib.h" />
<ClInclude Include="..\..\source\mact\include\control.h" />
<ClInclude Include="..\..\source\mact\include\file_lib.h" />
<ClInclude Include="..\..\source\mact\include\joystick.h" />
<ClInclude Include="..\..\source\mact\include\keyboard.h" />
<ClInclude Include="..\..\source\mact\include\mouse.h" />

View file

@ -17,9 +17,6 @@
<ClCompile Include="..\..\source\mact\src\control.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\source\mact\src\file_lib.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\source\mact\src\joystick.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@ -43,9 +40,6 @@
<ClInclude Include="..\..\source\mact\include\control.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\source\mact\include\file_lib.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\source\mact\include\joystick.h">
<Filter>Header Files</Filter>
</ClInclude>

View file

@ -253,7 +253,7 @@ AUDIOLIB_OBJS=$(AUDIOLIB_OBJ)\drivers.$o \
$(AUDIOLIB_OBJ)\xmp.$o \
$(AUDIOLIB_OBJ)\driver_nosound.$o
MACT_OBJS=$(MACT_OBJ)\file_lib.$o \
MACT_OBJS= \
$(MACT_OBJ)\control.$o \
$(MACT_OBJ)\keyboard.$o \
$(MACT_OBJ)\joystick.$o \

View file

@ -33,8 +33,10 @@ typedef struct
#pragma pack(pop)
#ifndef ANIMVPX_STANDALONE
#include "vfs.h"
extern const char *animvpx_read_ivf_header_errmsg[7];
int32_t animvpx_read_ivf_header(int32_t inhandle, animvpx_ivf_header_t *hdr);
int32_t animvpx_read_ivf_header(buildvfs_kfd inhandle, animvpx_ivf_header_t *hdr);
typedef struct
{
@ -46,7 +48,7 @@ typedef struct
// VVV everything that follows should be considered private! VVV
int32_t inhandle; // the kread() file handle
buildvfs_kfd inhandle; // the kread() file handle
// state of this struct:
// 0: uninited (either not yet or already)
@ -77,7 +79,7 @@ typedef struct
} animvpx_codec_ctx;
int32_t animvpx_init_codec(const animvpx_ivf_header_t *info, int32_t inhandle, animvpx_codec_ctx *codec);
int32_t animvpx_init_codec(const animvpx_ivf_header_t *info, buildvfs_kfd inhandle, animvpx_codec_ctx *codec);
int32_t animvpx_uninit_codec(animvpx_codec_ctx *codec);
extern const char *animvpx_nextpic_errmsg[8];

View file

@ -26,6 +26,9 @@
#include "palette.h"
#include "pragmas.h"
#include "vfs.h"
#include "cache1d.h"
#ifdef __cplusplus
extern "C" {
#endif
@ -1054,12 +1057,12 @@ void tileSetupDummy(int32_t tile);
void tileSetData(int32_t tile, int32_t tsiz, char const *buffer);
void tileDelete(int32_t tile);
void tileSetSize(int32_t picnum, int16_t dasizx, int16_t dasizy);
int32_t artReadHeader(int32_t fil, char const *fn, artheader_t *local);
int32_t artReadHeader(buildvfs_kfd fil, char const *fn, artheader_t *local);
int32_t artReadHeaderFromBuffer(uint8_t const *buf, artheader_t *local);
int32_t artCheckUnitFileHeader(uint8_t const *buf, int32_t length);
void tileConvertAnimFormat(int32_t picnum);
void artReadManifest(int32_t fil, artheader_t const *local);
void artPreloadFile(int32_t fil, artheader_t const *local);
void artReadManifest(buildvfs_kfd fil, artheader_t const *local);
void artPreloadFile(buildvfs_kfd fil, artheader_t const *local);
int32_t artLoadFiles(const char *filename, int32_t askedsize);
void artClearMapArt(void);
void artSetupMapArt(const char *filename);
@ -1264,8 +1267,8 @@ int videoCaptureScreenTGA(const char *filename, char inverseit) ATTRIBUTE((nonnu
struct OutputFileCounter {
uint16_t count = 0;
FILE * opennextfile(char *, char *);
FILE * opennextfile_withext(char *, const char *);
buildvfs_FILE opennextfile(char *, char *);
buildvfs_FILE opennextfile_withext(char *, const char *);
};
// PLAG: line utility functions

View file

@ -11,47 +11,112 @@
#include "compat.h"
#include "vfs.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef WITHKPLIB
int32_t cache1d_file_fromzip(int32_t fil);
#endif
extern char *kpzbuf;
extern int32_t kpzbufsiz;
extern int32_t kpzbufloadfil(int32_t);
extern int32_t kpzbufload(const char *);
void cacheInitBuffer(intptr_t dacachestart, int32_t dacachesize);
void cacheAllocateBlock(intptr_t *newhandle, int32_t newbytes, char *newlockptr);
void cacheAgeEntries(void);
#ifdef USE_PHYSFS
using buildvfs_kfd = PHYSFS_File *;
#define buildvfs_kfd_invalid (nullptr)
extern int32_t pathsearchmode; // 0 = gamefs mode (default), 1 = localfs mode (editor's mode)
#define addsearchpath(a) addsearchpath_user(a, 0)
static inline int32_t addsearchpath_user(const char *p, int32_t)
{
return PHYSFS_mount(p, NULL, 1) == 0 ? -1 : 0;
}
static inline int32_t removesearchpath(const char *p)
{
return PHYSFS_unmount(p);
}
static inline void removesearchpaths_withuser(int32_t)
{
// TODO
}
int32_t findfrompath(const char *fn, char **where);
buildvfs_kfd openfrompath(const char *fn, int32_t flags, int32_t mode);
buildvfs_FILE fopenfrompath(const char *fn, const char *mode);
extern int32_t numgroupfiles;
void uninitgroupfile(void);
static inline int initgroupfile(const char *filename)
{
return PHYSFS_mount(filename, NULL, 1) == 0 ? -1 : 0;
}
#define kread(fd, p, s) PHYSFS_readBytes((fd), (p), (s))
#define kwrite(fd, p, s) PHYSFS_writeBytes((fd), (p), (s))
#define kopen4load(fn, searchfirst) PHYSFS_openRead(fn)
#define ktell(fd) PHYSFS_tell(fd)
#define kfilelength(fd) PHYSFS_fileLength(fd)
static inline void kclose(buildvfs_kfd handle)
{
PHYSFS_close(handle);
}
#define kread_and_test(handle, buffer, leng) EDUKE32_PREDICT_FALSE(kread((handle), (buffer), (leng)) != (leng))
extern int32_t klseek(buildvfs_kfd handle, int32_t offset, int32_t whence);
#define klseek_and_test(handle, offset, whence) EDUKE32_PREDICT_FALSE(klseek((handle), (offset), (whence)) < 0)
static inline void krename(int32_t, int32_t, const char *)
{
}
#else
using buildvfs_kfd = int32_t;
#define buildvfs_kfd_invalid (-1)
extern int32_t pathsearchmode; // 0 = gamefs mode (default), 1 = localfs mode (editor's mode)
char *listsearchpath(int32_t initp);
#define addsearchpath(a) addsearchpath_user(a, 0)
int32_t addsearchpath_user(const char *p, int32_t user);
#define addsearchpath(a) addsearchpath_user(a, 0)
int32_t removesearchpath(const char *p);
void removesearchpaths_withuser(int32_t usermask);
int32_t findfrompath(const char *fn, char **where);
int32_t openfrompath(const char *fn, int32_t flags, int32_t mode);
BFILE *fopenfrompath(const char *fn, const char *mode);
buildvfs_kfd openfrompath(const char *fn, int32_t flags, int32_t mode);
buildvfs_FILE fopenfrompath(const char *fn, const char *mode);
extern int32_t numgroupfiles;
int initgroupfile(const char *filename);
void uninitgroupfile(void);
int32_t kopen4load(const char *filename, char searchfirst); // searchfirst: 0 = anywhere, 1 = first group, 2 = any group
int32_t kread(int32_t handle, void *buffer, int32_t leng);
buildvfs_kfd kopen4load(const char *filename, char searchfirst); // searchfirst: 0 = anywhere, 1 = first group, 2 = any group
int32_t kread(buildvfs_kfd handle, void *buffer, int32_t leng);
#define kread_and_test(handle, buffer, leng) EDUKE32_PREDICT_FALSE(kread((handle), (buffer), (leng)) != (leng))
int32_t klseek(int32_t handle, int32_t offset, int32_t whence);
int32_t klseek(buildvfs_kfd handle, int32_t offset, int32_t whence);
#define klseek_and_test(handle, offset, whence) EDUKE32_PREDICT_FALSE(klseek((handle), (offset), (whence)) < 0)
int32_t kfilelength(int32_t handle);
int32_t ktell(int32_t handle);
void kclose(int32_t handle);
int32_t kfilelength(buildvfs_kfd handle);
int32_t ktell(buildvfs_kfd handle);
void kclose(buildvfs_kfd handle);
void krename(int32_t crcval, int32_t filenum, const char *newname);
char const * kfileparent(int32_t handle);
#endif
extern int32_t kpzbufloadfil(buildvfs_kfd);
#ifdef WITHKPLIB
int32_t cache1d_file_fromzip(buildvfs_kfd fil);
#endif
typedef struct
{
@ -84,14 +149,14 @@ void klistfree(CACHE1D_FIND_REC *rec);
CACHE1D_FIND_REC *klistpath(const char *path, const char *mask, int32_t type);
extern int32_t lz4CompressionLevel;
int32_t kdfread(void *buffer, bsize_t dasizeof, bsize_t count, int32_t fil);
int32_t kdfread_LZ4(void *buffer, bsize_t dasizeof, bsize_t count, int32_t fil);
int32_t kdfread(void *buffer, bsize_t dasizeof, bsize_t count, buildvfs_kfd fil);
int32_t kdfread_LZ4(void *buffer, bsize_t dasizeof, bsize_t count, buildvfs_kfd fil);
#if 0
int32_t dfread(void *buffer, bsize_t dasizeof, bsize_t count, BFILE *fil);
void kdfwrite(const void *buffer, bsize_t dasizeof, bsize_t count, int32_t fil);
int32_t dfread(void *buffer, bsize_t dasizeof, bsize_t count, buildvfs_FILE fil);
void kdfwrite(const void *buffer, bsize_t dasizeof, bsize_t count, buildvfs_kfd fil);
#endif
void dfwrite(const void *buffer, bsize_t dasizeof, bsize_t count, BFILE *fil);
void dfwrite_LZ4(const void *buffer, bsize_t dasizeof, bsize_t count, BFILE *fil);
void dfwrite(const void *buffer, bsize_t dasizeof, bsize_t count, buildvfs_FILE fil);
void dfwrite_LZ4(const void *buffer, bsize_t dasizeof, bsize_t count, buildvfs_FILE fil);
#ifdef __cplusplus
}

View file

@ -405,7 +405,9 @@ defined __x86_64__ || defined __amd64__ || defined _M_X64 || defined _M_IA64 ||
#include <limits.h>
#include <stdarg.h>
#include <stddef.h>
#ifndef USE_PHYSFS
#include <stdio.h>
#endif
#include <stdlib.h>
#include <string.h>
@ -432,6 +434,7 @@ defined __x86_64__ || defined __amd64__ || defined _M_X64 || defined _M_IA64 ||
# include <malloc.h>
#endif
#ifndef USE_PHYSFS
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
@ -442,6 +445,7 @@ defined __x86_64__ || defined __amd64__ || defined _M_X64 || defined _M_IA64 ||
#else
# include <unistd.h>
#endif
#endif
////////// DEPRECATED: Standard library prefixing //////////
@ -902,10 +906,6 @@ static FORCE_INLINE void *Baligned_alloc(const size_t alignment, const size_t si
Baligned_free(var); (var) = NULL; \
} while (0)
#define MAYBE_FCLOSE_AND_NULL(fileptr) do { \
if (fileptr) { Bfclose(fileptr); fileptr=NULL; } \
} while (0)
////////// Data serialization //////////
@ -1124,6 +1124,7 @@ extern "C" {
#endif
#ifndef USE_PHYSFS
////////// Directory enumeration //////////
struct Bdirent
@ -1140,6 +1141,7 @@ typedef void BDIR;
BDIR *Bopendir(const char *name);
struct Bdirent *Breaddir(BDIR *dir);
int32_t Bclosedir(BDIR *dir);
#endif
////////// Paths //////////
@ -1176,8 +1178,6 @@ char *Bstrupr(char *);
////////// Miscellaneous //////////
int32_t Bfilelength(int32_t fd);
uint32_t Bgetsysmemsize(void);

View file

@ -6,9 +6,11 @@ extern "C" {
#include "compat.h"
#endif
#include "vfs.h"
typedef struct
{
FILE *fil; //0:no file open, !=0:open file (either stand-alone or zip)
buildvfs_FILE fil; //0:no file open, !=0:open file (either stand-alone or zip)
int32_t comptyp; //0:raw data (can be ZIP or stand-alone), 8:PKZIP LZ77 *flate
int32_t seek0; //0:stand-alone file, !=0: start of zip compressed stream data
int32_t compleng;//Global variable for compression FIFO

View file

@ -5,6 +5,8 @@
#ifndef osd_h_
#define osd_h_
#include "vfs.h"
#ifdef __cplusplus
extern "C" {
#endif
@ -158,7 +160,7 @@ typedef struct
typedef struct
{
BFILE *fp;
buildvfs_FILE fp;
int32_t cutoff;
int32_t errors;
int32_t lines;
@ -189,7 +191,7 @@ typedef struct
extern osdmain_t *osd;
extern BFILE *osdlog;
extern buildvfs_FILE osdlog;
extern const char* osdlogfn;
enum osdflags_t
@ -291,8 +293,8 @@ int OSD_RegisterFunction(const char *pszName, const char *pszDesc, int (*func)(o
int osdcmd_cvar_set(osdcmdptr_t parm);
void OSD_RegisterCvar(osdcvardata_t * cvar, int (*func)(osdcmdptr_t));
void OSD_WriteAliases(FILE *fp);
void OSD_WriteCvars(FILE *fp);
void OSD_WriteAliases(buildvfs_FILE fp);
void OSD_WriteCvars(buildvfs_FILE fp);
static inline void OSD_SetHistory(int idx, const char *src)
{

View file

@ -11,6 +11,9 @@
#ifndef palette_h_
#define palette_h_
#include "cache1d.h"
#include "vfs.h"
#ifdef __cplusplus
extern "C" {
#endif
@ -71,7 +74,7 @@ extern void setup_blend(int32_t blend, int32_t doreverse);
extern uint8_t basepalreset;
extern int32_t curbrightness, gammabrightness;
extern int32_t paletteLoadLookupTable(int32_t fp);
extern int32_t paletteLoadLookupTable(buildvfs_kfd fp);
extern void paletteSetupDefaultFog(void);
extern void palettePostLoadLookups(void);
extern void paletteFixTranslucencyMask(void);

View file

@ -3,6 +3,8 @@
#include "miniz.h"
#include "vfs.h"
#define CHUNK_COMPRESSED 1
#define CHUNK_ROW 2
@ -16,7 +18,7 @@ enum
typedef struct
{
z_stream *zs;
FILE *file;
buildvfs_FILE file;
uint8_t *pal_data;
uint16_t pal_entries;
uint8_t *text;
@ -32,6 +34,6 @@ typedef struct
void png_set_pal(uint8_t const * data, int numentries);
void png_set_text(char const * keyword, char const * text);
void png_write(FILE * file, uint32_t width, uint32_t height, uint8_t type, uint8_t const * data);
void png_write(buildvfs_FILE file, uint32_t width, uint32_t height, uint8_t type, uint8_t const * data);
#endif

View file

@ -5,6 +5,8 @@
extern "C" {
#endif
#include "vfs.h"
#ifdef USE_OPENGL
#define TEXCACHEMAGIC "LZ41"
@ -33,7 +35,7 @@ typedef struct texcacheitem_
typedef struct {
uint8_t *buf;
FILE * index;
buildvfs_FILE index;
texcacheindex * first;
texcacheindex * current;

178
source/build/include/vfs.h Normal file
View file

@ -0,0 +1,178 @@
#pragma once
#ifndef vfs_h_
#define vfs_h_
#include "compat.h"
#ifdef USE_PHYSFS
#include "physfs.h"
using buildvfs_FILE = PHYSFS_File *;
#define buildvfs_EOF (-1)
#define buildvfs_fread(p, s, n, fp) PHYSFS_readBytes((fp), (p), (s)*(n))
#define buildvfs_fwrite(p, s, n, fp) PHYSFS_writeBytes((fp), (p), (s)*(n))
#define buildvfs_fopen_read(fn) PHYSFS_openRead(fn)
#define buildvfs_fopen_write(fn) PHYSFS_openWrite(fn)
#define buildvfs_fopen_append(fn) PHYSFS_openAppend(fn)
static inline int buildvfs_fgetc(buildvfs_FILE fp)
{
unsigned char c;
if (buildvfs_fread(&c, 1, 1, fp) != 1)
return buildvfs_EOF;
return c;
}
static inline int buildvfs_fputc(char c, buildvfs_FILE fp)
{
if (PHYSFS_writeBytes(fp, &c, 1) != 1)
return buildvfs_EOF;
return c;
}
#define buildvfs_fclose(fp) PHYSFS_close(fp)
#define buildvfs_feof(fp) PHYSFS_eof(fp)
#define buildvfs_ftell(fp) PHYSFS_tell(fp)
#define buildvfs_fseek_abs(fp, o) PHYSFS_seek((fp), (o))
#define buildvfs_fseek_rel(fp, o) PHYSFS_seek((fp), PHYSFS_tell(fp) + (o))
#define buildvfs_rewind(fp) PHYSFS_seek((fp), 0)
#define buildvfs_flength(fp) PHYSFS_fileLength(fp)
#define buildvfs_chdir(dir) (-1)
#define buildvfs_mkdir(dir, x) (!PHYSFS_mkdir(dir))
static inline char *buildvfs_getcwd(char *buf, size_t size)
{
if (buf == nullptr || size == 0)
return nullptr;
buf[0] = '\0';
return buf;
}
using buildvfs_fd = PHYSFS_File *;
#define buildvfs_fd_invalid (nullptr)
#define buildvfs_read(fd, p, s) PHYSFS_readBytes((fd), (p), (s))
#define buildvfs_write(fd, p, s) PHYSFS_writeBytes((fd), (p), (s))
#define buildvfs_open_read(fn) PHYSFS_openRead(fn)
#define buildvfs_open_write(fn) PHYSFS_openWrite(fn)
#define buildvfs_open_append(fn) PHYSFS_openAppend(fn)
#define buildvfs_close(fd) PHYSFS_close(fd)
#define buildvfs_tell(fd) PHYSFS_tell(fd)
static inline int64_t buildvfs_lseek_abs(buildvfs_fd fd, int64_t o)
{
PHYSFS_seek(fd, o);
return PHYSFS_tell(fd);
}
static inline int64_t buildvfs_lseek_rel(buildvfs_fd fd, int64_t o)
{
PHYSFS_seek(fd, PHYSFS_tell(fd) + o);
return PHYSFS_tell(fd);
}
#define buildvfs_length(fd) PHYSFS_fileLength(fd)
#define buildvfs_exists(fn) PHYSFS_exists(fn)
#define buildvfs_isdir(path) PHYSFS_isDirectory(path)
#define buildvfs_unlink(path) PHYSFS_delete(path)
#else
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#ifdef _WIN32
# include <io.h>
#endif
using buildvfs_FILE = FILE *;
#define buildvfs_EOF EOF
#define buildvfs_fread(p, s, n, fp) fread((p), (s), (n), (fp))
#define buildvfs_fwrite(p, s, n, fp) fwrite((p), (s), (n), (fp))
#define buildvfs_fopen_read(fn) fopen((fn), "rb")
#define buildvfs_fopen_write(fn) fopen((fn), "wb")
#define buildvfs_fopen_append(fn) fopen((fn), "ab")
#define buildvfs_fgetc(fp) fgetc(fp)
#define buildvfs_fputc(c, fp) fputc((c), (fp))
#define buildvfs_fgets(str, size, fp) fgets((str), (size), (fp))
#define buildvfs_fclose(fp) fclose(fp)
#define buildvfs_feof(fp) feof(fp)
#define buildvfs_ftell(fp) ftell(fp)
#define buildvfs_fseek_abs(fp, o) fseek((fp), (o), SEEK_SET)
#define buildvfs_fseek_rel(fp, o) fseek((fp), (o), SEEK_CUR)
#define buildvfs_rewind(fp) rewind(fp)
static inline int64_t buildvfs_length(int fd)
{
#ifdef _WIN32
return filelength(fd);
#else
struct stat st;
if (fstat(fd, &st) < 0)
return -1;
return st.st_size;
#endif
}
#define buildvfs_chdir(dir) chdir(dir)
#define buildvfs_mkdir(dir, x) Bmkdir(dir, x)
#define buildvfs_getcwd(buf, size) getcwd((buf), (size))
using buildvfs_fd = int;
#define buildvfs_fd_invalid (-1)
#define buildvfs_read(fd, p, s) read((fd), (p), (s))
#define buildvfs_write(fd, p, s) write((fd), (p), (s))
#define buildvfs_open_read(fn) open((fn), O_RDONLY)
#define buildvfs_open_write(fn) open((fn), O_BINARY|O_TRUNC|O_CREAT|O_WRONLY, S_IREAD|S_IWRITE)
// #define buildvfs_open_append(fn) todo(fn)
#define buildvfs_close(fd) close(fd)
#define buildvfs_tell(fd) lseek((fd), 0, SEEK_CUR)
#define buildvfs_lseek_abs(fd, o) lseek((fd), (o), SEEK_SET)
#define buildvfs_lseek_rel(fd, o) lseek((fd), (o), SEEK_CUR)
static inline int64_t buildvfs_flength(FILE * f)
{
#ifdef _WIN32
return filelength(_fileno(f));
#else
return buildvfs_length(fileno(f));
#endif
}
#define buildvfs_exists(fn) (access((fn), F_OK) == 0)
static inline int buildvfs_isdir(char const *path)
{
struct stat st;
if (stat(path, &st) != 0)
return 0;
else if ((st.st_mode & S_IFDIR) != S_IFDIR)
return 0;
else
return 1;
}
#define buildvfs_unlink(path) unlink(path)
#endif
#define MAYBE_FCLOSE_AND_NULL(fileptr) do { \
if (fileptr) { buildvfs_fclose(fileptr); fileptr = buildvfs_FILE{}; } \
} while (0)
static inline void buildvfs_fputstrptr(buildvfs_FILE fp, char const * str)
{
buildvfs_fwrite(str, 1, strlen(str), fp);
}
static inline void buildvfs_fputs(char const * str, buildvfs_FILE fp)
{
buildvfs_fwrite(str, 1, strlen(str), fp);
}
template <size_t N>
static inline void buildvfs_fputstr(buildvfs_FILE fp, char const (&str)[N])
{
buildvfs_fwrite(&str, 1, N-1, fp);
}
#endif // vfs_h_

View file

@ -27,7 +27,7 @@ const char *animvpx_read_ivf_header_errmsg[] = {
EDUKE32_STATIC_ASSERT(sizeof(animvpx_ivf_header_t) == 32);
int32_t animvpx_read_ivf_header(int32_t inhandle, animvpx_ivf_header_t *hdr)
int32_t animvpx_read_ivf_header(buildvfs_kfd inhandle, animvpx_ivf_header_t *hdr)
{
int32_t err;
@ -85,7 +85,7 @@ static void get_codec_error(animvpx_codec_ctx *codec)
}
// no checks for double-init!
int32_t animvpx_init_codec(const animvpx_ivf_header_t *info, int32_t inhandle, animvpx_codec_ctx *codec)
int32_t animvpx_init_codec(const animvpx_ivf_header_t *info, buildvfs_kfd inhandle, animvpx_codec_ctx *codec)
{
vpx_codec_dec_cfg_t cfg;
@ -152,7 +152,7 @@ int32_t animvpx_uninit_codec(animvpx_codec_ctx *codec)
////////// FRAME RETRIEVAL //////////
// read one IVF/VP8 frame, which may code multiple "picture-frames"
static int32_t animvpx_read_frame(int32_t inhandle, uint8_t **bufptr, uint32_t *bufsizptr, uint32_t *bufallocsizptr)
static int32_t animvpx_read_frame(buildvfs_kfd inhandle, uint8_t **bufptr, uint32_t *bufsizptr, uint32_t *bufallocsizptr)
{
#pragma pack(push,1)
struct { uint32_t framesiz; uint64_t timestamp; } hdr;

View file

@ -19,6 +19,8 @@
#include "baselayer.h"
#include "renderlayer.h"
#include "vfs.h"
#ifdef _WIN32
# include "winbits.h"
#endif
@ -646,7 +648,7 @@ int app_main(int argc, char const * const * argv)
M32_OnShowOSD
);
if (!getcwd(program_origcwd,BMAX_PATH))
if (!buildvfs_getcwd(program_origcwd,BMAX_PATH))
program_origcwd[0] = '\0';
Bstrncpy(game_executable, DefaultGameLocalExec, sizeof(game_executable));
@ -10989,16 +10991,16 @@ void test_map(int32_t mode)
char const *param = " -map " PLAYTEST_MAPNAME " -noinstancechecking";
char current_cwd[BMAX_PATH];
int32_t slen = 0;
BFILE *fp;
buildvfs_FILE fp;
if ((program_origcwd[0] == '\0') || !getcwd(current_cwd, BMAX_PATH))
if ((program_origcwd[0] == '\0') || !buildvfs_getcwd(current_cwd, BMAX_PATH))
current_cwd[0] = '\0';
else // Before we check if file exists, for the case there's no absolute path.
Bchdir(program_origcwd);
buildvfs_chdir(program_origcwd);
fp = fopen(game_executable, "rb"); // File exists?
fp = buildvfs_fopen_read(game_executable); // File exists?
if (fp != NULL)
fclose(fp);
buildvfs_fclose(fp);
else
{
char const * lastslash = (char const *)Bstrrchr(mapster32_fullpath, '/');
@ -11017,7 +11019,7 @@ void test_map(int32_t mode)
}
if (current_cwd[0] != '\0') // Temporarily changing back,
Bchdir(current_cwd); // after checking if file exists.
buildvfs_chdir(current_cwd); // after checking if file exists.
if (testplay_addparam)
slen = Bstrlen(testplay_addparam);
@ -11063,10 +11065,10 @@ void test_map(int32_t mode)
#else
if (current_cwd[0] != '\0')
{
Bchdir(program_origcwd);
buildvfs_chdir(program_origcwd);
if (system(fullparam))
message("Error launching the game!");
Bchdir(current_cwd);
buildvfs_chdir(current_cwd);
}
else system(fullparam);
#endif

View file

@ -19,6 +19,8 @@
#include "lz4.h"
#include "klzw.h"
#include "vfs.h"
#ifdef WITHKPLIB
#include "kplib.h"
@ -40,7 +42,7 @@ static intptr_t kzipopen(const char *filnam)
char *kpzbuf = NULL;
int32_t kpzbufsiz;
int32_t kpzbufloadfil(int32_t const handle)
int32_t kpzbufloadfil(buildvfs_kfd const handle)
{
int32_t const leng = kfilelength(handle);
if (leng > kpzbufsiz)
@ -59,8 +61,8 @@ int32_t kpzbufloadfil(int32_t const handle)
int32_t kpzbufload(char const * const filnam)
{
int32_t const handle = kopen4load(filnam, 0);
if (handle < 0)
buildvfs_kfd const handle = kopen4load(filnam, 0);
if (handle == buildvfs_kfd_invalid)
return 0;
int32_t const leng = kpzbufloadfil(handle);
@ -354,6 +356,8 @@ static searchpath_t *searchpathhead = NULL;
static size_t maxsearchpathlen = 0;
int32_t pathsearchmode = 0;
#ifndef USE_PHYSFS
char *listsearchpath(int32_t initp)
{
static searchpath_t *sp;
@ -508,7 +512,7 @@ int32_t findfrompath(const char *fn, char **where)
if (pathsearchmode)
{
// test unmolested filename first
if (access(fn, F_OK) >= 0)
if (buildvfs_exists(fn))
{
*where = Xstrdup(fn);
return 0;
@ -518,7 +522,7 @@ int32_t findfrompath(const char *fn, char **where)
{
char *tfn = Bstrtolower(Xstrdup(fn));
if (access(tfn, F_OK) >= 0)
if (buildvfs_exists(tfn))
{
*where = tfn;
return 0;
@ -526,7 +530,7 @@ int32_t findfrompath(const char *fn, char **where)
Bstrupr(tfn);
if (access(tfn, F_OK) >= 0)
if (buildvfs_exists(tfn))
{
*where = tfn;
return 0;
@ -552,7 +556,7 @@ int32_t findfrompath(const char *fn, char **where)
strcpy(pfn, "./");
strcat(pfn, ffn);
if (access(pfn, F_OK) >= 0)
if (buildvfs_exists(pfn))
{
*where = pfn;
Bfree(ffn);
@ -566,7 +570,7 @@ int32_t findfrompath(const char *fn, char **where)
strcpy(pfn, sp->path);
strcat(pfn, ffn);
//initprintf("Trying %s\n", pfn);
if (access(pfn, F_OK) >= 0)
if (buildvfs_exists(pfn))
{
*where = pfn;
Bfree(ffn);
@ -579,7 +583,7 @@ int32_t findfrompath(const char *fn, char **where)
strcpy(pfn, sp->path);
Bstrtolower(tfn);
strcat(pfn, tfn);
if (access(pfn, F_OK) >= 0)
if (buildvfs_exists(pfn))
{
*where = pfn;
Bfree(ffn);
@ -591,7 +595,7 @@ int32_t findfrompath(const char *fn, char **where)
strcpy(pfn, sp->path);
Bstrupr(tfn);
strcat(pfn, tfn);
if (access(pfn, F_OK) >= 0)
if (buildvfs_exists(pfn))
{
*where = pfn;
Bfree(ffn);
@ -610,7 +614,7 @@ int32_t findfrompath(const char *fn, char **where)
# define FILENAME_CASE_CHECK
#endif
static int32_t openfrompath_internal(const char *fn, char **where, int32_t flags, int32_t mode)
static buildvfs_kfd openfrompath_internal(const char *fn, char **where, int32_t flags, int32_t mode)
{
if (findfrompath(fn, where) < 0)
return -1;
@ -618,21 +622,21 @@ static int32_t openfrompath_internal(const char *fn, char **where, int32_t flags
return Bopen(*where, flags, mode);
}
int32_t openfrompath(const char *fn, int32_t flags, int32_t mode)
buildvfs_kfd openfrompath(const char *fn, int32_t flags, int32_t mode)
{
char *pfn = NULL;
int32_t h = openfrompath_internal(fn, &pfn, flags, mode);
buildvfs_kfd h = openfrompath_internal(fn, &pfn, flags, mode);
Bfree(pfn);
return h;
}
BFILE *fopenfrompath(const char *fn, const char *mode)
buildvfs_FILE fopenfrompath(const char *fn, const char *mode)
{
int32_t fh;
BFILE *h;
buildvfs_FILE h;
int32_t bmode = 0, smode = 0;
const char *c;
@ -692,7 +696,7 @@ static intptr_t filehan[MAXOPENFILES] =
static char filenamsav[MAXOPENFILES][260];
static int32_t kzcurhand = -1;
int32_t cache1d_file_fromzip(int32_t fil)
int32_t cache1d_file_fromzip(buildvfs_kfd fil)
{
return (filegrp[fil] == GRP_ZIP);
}
@ -948,7 +952,7 @@ static int32_t check_filename_mismatch(const char * const filename, int ofs)
static int32_t kopen_internal(const char *filename, char **lastpfn, char searchfirst, char checkcase, char tryzip, int32_t newhandle, uint8_t *arraygrp, intptr_t *arrayhan, int32_t *arraypos)
{
int32_t fil;
buildvfs_kfd fil;
if (searchfirst == 0 && (fil = openfrompath_internal(filename, lastpfn, BO_BINARY|BO_RDONLY, BS_IREAD)) >= 0)
{
#ifdef FILENAME_CASE_CHECK
@ -1180,8 +1184,7 @@ int32_t kfilelength_internal(int32_t handle, const uint8_t *arraygrp, intptr_t *
int32_t const groupnum = arraygrp[handle];
if (groupnum == GRP_FILESYSTEM)
{
// return (filelength(arrayhan[handle]))
return Bfilelength(arrayhan[handle]);
return buildvfs_length(arrayhan[handle]);
}
#ifdef WITHKPLIB
else if (groupnum == GRP_ZIP)
@ -1270,6 +1273,7 @@ static void kclose_grp(int32_t handle)
{
return kclose_internal(handle, groupfilgrp, groupfil);
}
#endif
static int32_t klistaddentry(CACHE1D_FIND_REC **rec, const char *name, int32_t type, int32_t source)
{
@ -1385,21 +1389,57 @@ CACHE1D_FIND_REC *klistpath(const char *_path, const char *mask, int32_t type)
if (*path && (type & CACHE1D_FIND_DIR))
{
if (klistaddentry(&rec, "..", CACHE1D_FIND_DIR, CACHE1D_SOURCE_CURDIR) < 0) goto failure;
if (klistaddentry(&rec, "..", CACHE1D_FIND_DIR, CACHE1D_SOURCE_CURDIR) < 0)
{
Bfree(path);
klistfree(rec);
return NULL;
}
}
if (!(type & CACHE1D_OPT_NOSTACK)) // current directory and paths in the search stack
{
searchpath_t *search = NULL;
BDIR *dir;
struct Bdirent *dirent;
int32_t stackdepth = CACHE1D_SOURCE_CURDIR;
#ifdef USE_PHYSFS
char **rc = PHYSFS_enumerateFiles("");
char **i;
for (i = rc; *i != NULL; i++)
{
char * name = *i;
if ((name[0] == '.' && name[1] == 0) ||
(name[0] == '.' && name[1] == '.' && name[2] == 0))
continue;
bool const isdir = buildvfs_isdir(name);
if ((type & CACHE1D_FIND_DIR) && !isdir) continue;
if ((type & CACHE1D_FIND_FILE) && isdir) continue;
if (!Bwildmatch(name, mask)) continue;
switch (klistaddentry(&rec, name,
isdir ? CACHE1D_FIND_DIR : CACHE1D_FIND_FILE,
stackdepth))
{
case -1: goto failure;
//case 1: initprintf("%s:%s dropped for lower priority\n", d,dirent->name); break;
//case 0: initprintf("%s:%s accepted\n", d,dirent->name); break;
default:
break;
}
}
PHYSFS_freeList(rc);
#else
static const char *const CUR_DIR = "./";
// Adjusted for the following "autoload" dir fix - NY00123
searchpath_t *search = NULL;
const char *d = pathsearchmode ? _path : CUR_DIR;
int32_t stackdepth = CACHE1D_SOURCE_CURDIR;
char buf[BMAX_PATH];
BDIR *dir;
struct Bdirent *dirent;
do
{
if (d==CUR_DIR && (type & CACHE1D_FIND_NOCURDIR))
@ -1412,7 +1452,6 @@ CACHE1D_FIND_REC *klistpath(const char *_path, const char *mask, int32_t type)
strcat(buf, path);
if (*path) strcat(buf, "/");
}
dir = Bopendir(buf);
if (dir)
{
@ -1456,8 +1495,10 @@ next:
d = search->path;
}
while (search);
#endif
}
#ifndef USE_PHYSFS
#ifdef WITHKPLIB
if (!(type & CACHE1D_FIND_NOCURDIR)) // TEMP, until we have sorted out fs.listpath() API
if (!pathsearchmode) // next, zip files
@ -1558,6 +1599,7 @@ next:
}
}
}
#endif
if (pathsearchmode && (type & CACHE1D_FIND_DRIVE))
{
@ -1590,16 +1632,16 @@ failure:
static int32_t kdfread_func(intptr_t fil, void *outbuf, int32_t length)
{
return kread((int32_t)fil, outbuf, length);
return kread((buildvfs_kfd)fil, outbuf, length);
}
static void dfwrite_func(intptr_t fp, const void *inbuf, int32_t length)
{
Bfwrite(inbuf, length, 1, (BFILE *)fp);
buildvfs_fwrite(inbuf, length, 1, (buildvfs_FILE)fp);
}
int32_t kdfread(void *buffer, bsize_t dasizeof, bsize_t count, int32_t fil)
int32_t kdfread(void *buffer, bsize_t dasizeof, bsize_t count, buildvfs_kfd fil)
{
return klzw_read_compressed(buffer, dasizeof, count, (intptr_t)fil, kdfread_func);
}
@ -1611,7 +1653,7 @@ int32_t kdfread(void *buffer, bsize_t dasizeof, bsize_t count, int32_t fil)
static char compressedDataStackBuf[131072];
int32_t lz4CompressionLevel = LZ4_COMPRESSION_ACCELERATION_VALUE;
int32_t kdfread_LZ4(void *buffer, bsize_t dasizeof, bsize_t count, int32_t fil)
int32_t kdfread_LZ4(void *buffer, bsize_t dasizeof, bsize_t count, buildvfs_kfd fil)
{
int32_t leng;
@ -1638,12 +1680,12 @@ int32_t kdfread_LZ4(void *buffer, bsize_t dasizeof, bsize_t count, int32_t fil)
}
void dfwrite(const void *buffer, bsize_t dasizeof, bsize_t count, BFILE *fil)
void dfwrite(const void *buffer, bsize_t dasizeof, bsize_t count, buildvfs_FILE fil)
{
klzw_write_compressed(buffer, dasizeof, count, (intptr_t)fil, dfwrite_func);
}
void dfwrite_LZ4(const void *buffer, bsize_t dasizeof, bsize_t count, BFILE *fil)
void dfwrite_LZ4(const void *buffer, bsize_t dasizeof, bsize_t count, buildvfs_FILE fil)
{
char * pCompressedData = compressedDataStackBuf;
int32_t const maxCompressedSize = LZ4_compressBound(dasizeof * count);
@ -1654,8 +1696,8 @@ void dfwrite_LZ4(const void *buffer, bsize_t dasizeof, bsize_t count, BFILE *fil
int32_t const leng = LZ4_compress_fast((const char*) buffer, pCompressedData, dasizeof*count, maxCompressedSize, lz4CompressionLevel);
int32_t const swleng = B_LITTLE32(leng);
Bfwrite(&swleng, sizeof(swleng), 1, fil);
Bfwrite(pCompressedData, leng, 1, fil);
buildvfs_fwrite(&swleng, sizeof(swleng), 1, fil);
buildvfs_fwrite(pCompressedData, leng, 1, fil);
if (pCompressedData != compressedDataStackBuf)
Baligned_free(pCompressedData);

View file

@ -8,6 +8,8 @@
#include "common.h"
#include "vfs.h"
void PrintBuildInfo(void)
{
buildprint(
@ -129,15 +131,18 @@ int32_t G_CheckCmdSwitch(int32_t argc, char const * const * argv, const char *st
// returns: 1 if file could be opened, 0 else
int32_t testkopen(const char *filename, char searchfirst)
{
int32_t fd = kopen4load(filename, searchfirst);
if (fd >= 0)
buildvfs_kfd fd = kopen4load(filename, searchfirst);
if (fd != buildvfs_kfd_invalid)
kclose(fd);
return (fd >= 0);
return (fd != buildvfs_kfd_invalid);
}
// checks from path and in ZIPs, returns 1 if NOT found
int32_t check_file_exist(const char *fn)
{
#ifdef USE_PHYSFS
return !PHYSFS_exists(fn);
#else
int32_t opsm = pathsearchmode;
char *tfn;
@ -159,6 +164,7 @@ int32_t check_file_exist(const char *fn)
pathsearchmode = opsm;
return 0;
#endif
}

View file

@ -13,11 +13,13 @@
# include "osxbits.h"
#endif
#ifndef USE_PHYSFS
#if defined(_MSC_VER)
# include <io.h>
#else
# include <dirent.h>
#endif
#endif
#if defined __linux || defined EDUKE32_BSD
# include <libgen.h> // for dirname()
@ -29,6 +31,8 @@
#include "baselayer.h"
#include "vfs.h"
////////// PANICKING ALLOCATION FUNCTIONS //////////
static void (*g_MemErrHandler)(int32_t line, const char *file, const char *func);
@ -112,7 +116,7 @@ char *Bgethomedir(void)
#elif defined(GEKKO)
// return current drive's name
char *drv, cwd[BMAX_PATH] = {0};
getcwd(cwd, BMAX_PATH);
buildvfs_getcwd(cwd, BMAX_PATH);
drv = strchr(cwd, ':');
if (drv)
drv[1] = '\0';
@ -221,6 +225,7 @@ int32_t Bcorrectfilename(char *filename, int32_t removefn)
return 0;
}
#ifndef USE_PHYSFS
int32_t Bcanonicalisefilename(char *filename, int32_t removefn)
{
char cwd[BMAX_PATH];
@ -243,7 +248,7 @@ int32_t Bcanonicalisefilename(char *filename, int32_t removefn)
if (*p == '\\')
*p = '/';
#else
if (!getcwd(cwd, sizeof(cwd)))
if (!buildvfs_getcwd(cwd, sizeof(cwd)))
return -1;
#endif
@ -284,6 +289,7 @@ int32_t Bcanonicalisefilename(char *filename, int32_t removefn)
UNREFERENCED_PARAMETER(removefn); // change the call below to use removefn instead of 1?
return Bcorrectfilename(fnp, 1);
}
#endif
char *Bgetsystemdrives(void)
{
@ -323,13 +329,7 @@ char *Bgetsystemdrives(void)
}
int32_t Bfilelength(int32_t fd)
{
struct Bstat st;
return (Bfstat(fd, &st) < 0) ? -1 : (int32_t)(st.st_size);
}
#ifndef USE_PHYSFS
typedef struct
{
#ifdef _MSC_VER
@ -422,6 +422,16 @@ struct Bdirent *Breaddir(BDIR *dir)
char *fn = (char *)Xmalloc(Bstrlen(dirr->name) + 1 + dirr->info.namlen + 1);
Bsprintf(fn, "%s/%s", dirr->name, dirr->info.name);
#ifdef USE_PHYSFS
PHYSFS_Stat st;
if (PHYSFS_stat(fn, &st))
{
// dirr->info.mode = TODO;
dirr->info.size = st.filesize;
dirr->info.mtime = st.modtime;
}
#else
struct Bstat st;
if (!Bstat(fn, &st))
{
@ -429,6 +439,8 @@ struct Bdirent *Breaddir(BDIR *dir)
dirr->info.size = st.st_size;
dirr->info.mtime = st.st_mtime;
}
#endif
Bfree(fn);
return &dirr->info;
@ -447,6 +459,7 @@ int32_t Bclosedir(BDIR *dir)
return 0;
}
#endif
char *Bstrtoken(char *s, const char *delim, char **ptrptr, int chop)

View file

@ -9,6 +9,8 @@
#include "baselayer.h"
#include "renderlayer.h"
#include "vfs.h"
static double clampd(double d, double mind, double maxd)
{
if (d != d || d<mind)
@ -18,18 +20,18 @@ static double clampd(double d, double mind, double maxd)
return d;
}
static int32_t readconfig(BFILE *fp, const char *key, char *value, uint32_t len)
static int32_t readconfig(buildvfs_FILE fp, const char *key, char *value, uint32_t len)
{
char buf[1000], *k, *v, *eq;
int32_t x=0;
if (len < 1) return 0;
Brewind(fp);
buildvfs_rewind(fp);
while (1)
{
if (!Bfgets(buf, 1000, fp)) return 0;
if (!buildvfs_fgets(buf, 1000, fp)) return 0;
if (buf[0] == ';') continue;
@ -104,12 +106,12 @@ extern int32_t ParentalLock;
int32_t loadsetup(const char *fn)
{
BFILE *fp;
buildvfs_FILE fp;
#define VL 1024
char val[VL];
int32_t i;
if ((fp = Bfopen(fn, "rt")) == NULL) return -1;
if ((fp = buildvfs_fopen_read(fn)) == NULL) return -1;
if (readconfig(fp, "forcesetup", val, VL) > 0) forcesetup = (atoi_safe(val) != 0);
if (readconfig(fp, "fullscreen", val, VL) > 0) fullscreen = (atoi_safe(val) != 0);
@ -295,14 +297,14 @@ int32_t loadsetup(const char *fn)
scripthistend %= SCRIPTHISTSIZ;
Bfclose(fp);
buildvfs_fclose(fp);
return 0;
}
void writesettings(void) // save binds and aliases to <cfgname>_m32_settings.cfg
{
BFILE *fp;
buildvfs_FILE fp;
char *ptr = Xstrdup(setupfilename);
char tempbuf[128];
@ -310,7 +312,7 @@ void writesettings(void) // save binds and aliases to <cfgname>_m32_settings.cfg
Bsprintf(tempbuf, "m32_settings.cfg");
else Bsprintf(tempbuf, "%s_m32_settings.cfg", strtok(ptr, "."));
fp = Bfopen(tempbuf, "wt");
fp = buildvfs_fopen_write(tempbuf);
if (fp)
{
@ -319,7 +321,7 @@ void writesettings(void) // save binds and aliases to <cfgname>_m32_settings.cfg
OSD_WriteAliases(fp);
OSD_WriteCvars(fp);
Bfclose(fp);
buildvfs_fclose(fp);
if (!Bstrcmp(setupfilename, defaultsetupfilename))
OSD_Printf("Wrote m32_settings.cfg\n");
@ -338,10 +340,10 @@ void writesettings(void) // save binds and aliases to <cfgname>_m32_settings.cfg
int32_t writesetup(const char *fn)
{
BFILE *fp;
buildvfs_FILE fp;
int32_t i,j,first=1;
fp = Bfopen(fn,"wt");
fp = buildvfs_fopen_write(fn);
if (!fp) return -1;
Bfprintf(fp,
@ -682,7 +684,7 @@ int32_t writesetup(const char *fn)
Bfprintf(fp, "hist%d = %s\n", j++, scripthist[i]);
}
Bfclose(fp);
buildvfs_fclose(fp);
writesettings();

View file

@ -21,6 +21,8 @@
# include "hightile.h"
#endif
#include "vfs.h"
enum scripttoken_t
{
T_INCLUDE = 0,
@ -670,8 +672,8 @@ static int32_t defsparser(scriptfile *script)
break;
}
int32_t const fil = kopen4load(fn, 0);
if (fil == -1)
buildvfs_kfd const fil = kopen4load(fn, 0);
if (fil == buildvfs_kfd_invalid)
break;
artheader_t local;
@ -1962,7 +1964,7 @@ static int32_t defsparser(scriptfile *script)
char *fn = NULL;
char *highpalend;
#ifdef POLYMER
int32_t fd;
buildvfs_kfd fd;
char *highpaldata;
#endif
static const tokenlist highpaltokens[] =
@ -2834,8 +2836,8 @@ static int32_t defsparser(scriptfile *script)
break;
}
int32_t const fil = kopen4load(fn, 0);
if (EDUKE32_PREDICT_FALSE(fil == -1))
buildvfs_kfd const fil = kopen4load(fn, 0);
if (EDUKE32_PREDICT_FALSE(fil == buildvfs_kfd_invalid))
{
initprintf("Error: basepalette: Failed opening \"%s\" on line %s:%d\n", fn,
script->filename, scriptfile_getlinum(script,cmdtokptr));
@ -3014,8 +3016,8 @@ static int32_t defsparser(scriptfile *script)
break;
}
int32_t const fil = kopen4load(fn, 0);
if (EDUKE32_PREDICT_FALSE(fil == -1))
buildvfs_kfd const fil = kopen4load(fn, 0);
if (EDUKE32_PREDICT_FALSE(fil == buildvfs_kfd_invalid))
{
initprintf("Error: palookup: Failed opening \"%s\" on line %s:%d\n", fn,
script->filename, scriptfile_getlinum(script,cmdtokptr));
@ -3314,8 +3316,8 @@ static int32_t defsparser(scriptfile *script)
break;
}
int32_t const fil = kopen4load(fn, 0);
if (EDUKE32_PREDICT_FALSE(fil == -1))
buildvfs_kfd const fil = kopen4load(fn, 0);
if (EDUKE32_PREDICT_FALSE(fil == buildvfs_kfd_invalid))
{
initprintf("Error: blendtable: Failed opening \"%s\" on line %s:%d\n", fn,
script->filename, scriptfile_getlinum(script,cmdtokptr));

View file

@ -43,6 +43,13 @@ Description of Ken's filter to improve LZW compression of DXT1 format by ~15%: (
#include "texcache.h"
#include "lz4.h"
#include <fcntl.h>
#ifdef _WIN32
# include <io.h>
#else
# include <unistd.h>
#endif
#ifndef EDUKE32_GLES
static uint16_t dxt_hicosub(uint16_t c)
{

View file

@ -40,6 +40,8 @@
L_State g_engState;
#endif
#include "vfs.h"
//////////
// Compilation switches for optional/extended engine features
@ -8971,7 +8973,7 @@ static FORCE_INLINE int32_t have_maptext(void)
return (mapversion >= 10);
}
static void enginePrepareLoadBoard(int32_t fil, vec3_t *dapos, int16_t *daang, int16_t *dacursectnum)
static void enginePrepareLoadBoard(buildvfs_kfd fil, vec3_t *dapos, int16_t *daang, int16_t *dacursectnum)
{
initspritelists();
@ -9129,7 +9131,7 @@ static void check_sprite(int32_t i)
#ifdef NEW_MAP_FORMAT
// Returns the number of sprites, or <0 on error.
LUNATIC_CB int32_t (*loadboard_maptext)(int32_t fil, vec3_t *dapos, int16_t *daang, int16_t *dacursectnum);
LUNATIC_CB int32_t (*loadboard_maptext)(buildvfs_kfd fil, vec3_t *dapos, int16_t *daang, int16_t *dacursectnum);
#endif
#include "md4.h"
@ -9144,13 +9146,14 @@ LUNATIC_CB int32_t (*loadboard_maptext)(int32_t fil, vec3_t *dapos, int16_t *daa
// <= -4: map-text error
int32_t engineLoadBoard(const char *filename, char flags, vec3_t *dapos, int16_t *daang, int16_t *dacursectnum)
{
int32_t fil, i;
int32_t i;
int16_t numsprites;
const char myflags = flags&(~3);
flags &= 3;
if ((fil = kopen4load(filename,flags)) == -1)
buildvfs_kfd fil;
if ((fil = kopen4load(filename,flags)) == buildvfs_kfd_invalid)
{ mapversion = 7; return -1; }
if (kread(fil, &mapversion, 4) != 4)
@ -9365,7 +9368,7 @@ skip_reading_mapbin:
// Witchaven 1 and TekWar and LameDuke use v5
int32_t engineLoadBoardV5V6(const char *filename, char fromwhere, vec3_t *dapos, int16_t *daang, int16_t *dacursectnum)
{
int32_t fil, i;
int32_t i;
int16_t numsprites;
struct sectortypev5 v5sect;
@ -9375,7 +9378,8 @@ int32_t engineLoadBoardV5V6(const char *filename, char fromwhere, vec3_t *dapos,
struct walltypev6 v6wall;
struct spritetypev6 v6spr;
if ((fil = kopen4load(filename,fromwhere)) == -1)
buildvfs_kfd fil;
if ((fil = kopen4load(filename,fromwhere)) == buildvfs_kfd_invalid)
{ mapversion = 5L; return -1; }
kread(fil,&mapversion,4); mapversion = B_LITTLE32(mapversion);
@ -9579,7 +9583,7 @@ static int32_t get_mapversion(void)
int32_t saveboard(const char *filename, const vec3_t *dapos, int16_t daang, int16_t dacursectnum)
{
int16_t numsprites, ts;
int32_t i, j, fil, tl;
int32_t i, j, tl;
// First, some checking.
for (j=0; j<MAXSPRITES; j++)
@ -9623,23 +9627,23 @@ int32_t saveboard(const char *filename, const vec3_t *dapos, int16_t daang, int1
}
#endif
fil = Bopen(filename, BO_BINARY|BO_TRUNC|BO_CREAT|BO_WRONLY, BS_IREAD|BS_IWRITE);
buildvfs_fd fil = buildvfs_open_write(filename);
if (fil == -1)
if (fil == buildvfs_fd_invalid)
{
initprintf("Couldn't open \"%s\" for writing: %s\n", filename, strerror(errno));
return -1;
}
tl = B_LITTLE32(mapversion); Bwrite(fil,&tl,4);
tl = B_LITTLE32(mapversion); buildvfs_write(fil,&tl,4);
tl = B_LITTLE32(dapos->x); Bwrite(fil,&tl,4);
tl = B_LITTLE32(dapos->y); Bwrite(fil,&tl,4);
tl = B_LITTLE32(dapos->z); Bwrite(fil,&tl,4);
ts = B_LITTLE16(daang); Bwrite(fil,&ts,2);
ts = B_LITTLE16(dacursectnum); Bwrite(fil,&ts,2);
tl = B_LITTLE32(dapos->x); buildvfs_write(fil,&tl,4);
tl = B_LITTLE32(dapos->y); buildvfs_write(fil,&tl,4);
tl = B_LITTLE32(dapos->z); buildvfs_write(fil,&tl,4);
ts = B_LITTLE16(daang); buildvfs_write(fil,&ts,2);
ts = B_LITTLE16(dacursectnum); buildvfs_write(fil,&ts,2);
ts = B_LITTLE16(numsectors); Bwrite(fil,&ts,2);
ts = B_LITTLE16(numsectors); buildvfs_write(fil,&ts,2);
while (1) // if, really
{
@ -9683,11 +9687,11 @@ int32_t saveboard(const char *filename, const vec3_t *dapos, int16_t daang, int1
#endif
}
Bwrite(fil, tsect, sizeof(sectortypev7)*numsectors);
buildvfs_write(fil, tsect, sizeof(sectortypev7)*numsectors);
Bfree(tsect);
ts = B_LITTLE16(numwalls);
Bwrite(fil,&ts,2);
buildvfs_write(fil,&ts,2);
twall = (uwalltypev7 *)Xmalloc(sizeof(uwalltypev7) * numwalls);
@ -9726,10 +9730,10 @@ int32_t saveboard(const char *filename, const vec3_t *dapos, int16_t daang, int1
wal->extra = B_LITTLE16(wal->extra);
}
Bwrite(fil, twall, sizeof(walltypev7)*numwalls);
buildvfs_write(fil, twall, sizeof(walltypev7)*numwalls);
Bfree(twall);
ts = B_LITTLE16(numsprites); Bwrite(fil,&ts,2);
ts = B_LITTLE16(numsprites); buildvfs_write(fil,&ts,2);
if (numsprites > 0)
{
@ -9760,15 +9764,15 @@ int32_t saveboard(const char *filename, const vec3_t *dapos, int16_t daang, int1
}
}
Bwrite(fil, tspri, sizeof(spritetype)*numsprites);
buildvfs_write(fil, tspri, sizeof(spritetype)*numsprites);
Bfree(tspri);
}
Bclose(fil);
buildvfs_close(fil);
return 0;
}
Bclose(fil);
buildvfs_close(fil);
return -1;
}
@ -10041,8 +10045,8 @@ void videoNextPage(void)
//
int32_t qloadkvx(int32_t voxindex, const char *filename)
{
const int32_t fil = kopen4load(filename, 0);
if (fil == -1)
const buildvfs_kfd fil = kopen4load(filename, 0);
if (fil == buildvfs_kfd_invalid)
return -1;
int32_t lengcnt = 0;
@ -11575,13 +11579,13 @@ void krd_enable(int which) // 0: disable, 1: rec, 2: play
int32_t krd_print(const char *filename)
{
FILE *fp;
buildvfs_FILE fp;
int32_t i, j;
if (!krd_enabled) return 1;
krd_enabled = 0;
fp = fopen(filename, "wb");
fp = buildvfs_fopen_write(filename);
if (!fp) { OSD_Printf("krd_print (2): fopen"); return 1; }
for (i=0; i<krd_numcalls; i++)
@ -11599,7 +11603,7 @@ int32_t krd_print(const char *filename)
krd_numcalls = 0;
fclose(fp);
buildvfs_fclose(fp);
return 0;
}
#endif // KRANDDEBUG

View file

@ -34,19 +34,12 @@ credits.
#include "kplib.h"
#include "pragmas.h"
#include "vfs.h"
#if !defined(_WIN32)
# include <dirent.h>
static FORCE_INLINE CONSTEXPR int32_t klrotl(int32_t i, int sh) { return (i >> (-sh)) | (i << sh); }
/*inline*/ int32_t filelength(int h)
{
struct stat st;
if (fstat(h,&st) < 0) return -1;
return st.st_size;
}
# define _fileno fileno
#else
# define klrotl(i, sh) _lrotl(i, sh)
# include <io.h>
# ifdef __clang__
# include <emmintrin.h>
# else
@ -195,7 +188,7 @@ static void suckbitsnextblock()
//NOTE: should only read bytes inside compsize, not 64K!!! :/
B_BUF32(&olinbuf[0], B_UNBUF32(&olinbuf[sizeof(olinbuf)-4]));
uint32_t n = min<uint32_t>(kzfs.compleng-kzfs.comptell, sizeof(olinbuf)-4);
fread(&olinbuf[4], n, 1, kzfs.fil);
buildvfs_fread(&olinbuf[4], n, 1, kzfs.fil);
kzfs.comptell += n;
bitpos -= ((sizeof(olinbuf)-4)<<3);
return;
@ -2451,11 +2444,11 @@ void kzuninit()
//If file not found, assumes it's a directory and adds it to an internal list
int32_t kzaddstack(const char *filnam)
{
FILE *fil;
buildvfs_FILE fil;
int32_t i, j, k, leng, hashind, zipnamoffs, numfiles;
char tempbuf[260+46];
fil = fopen(filnam,"rb");
fil = buildvfs_fopen_read(filnam);
if (!fil) //if file not found, assume it's a directory
{
//Add directory name to internal list (using kzhashbuf for convenience of dynamic allocation)
@ -2468,46 +2461,46 @@ int32_t kzaddstack(const char *filnam)
}
//Write ZIP/GRP filename to hash
i = strlen(filnam)+1; if (!kzcheckhashsiz(i)) { fclose(fil); return -1; }
i = strlen(filnam)+1; if (!kzcheckhashsiz(i)) { buildvfs_fclose(fil); return -1; }
strcpy(&kzhashbuf[kzhashpos],filnam);
zipnamoffs = kzhashpos; kzhashpos += i;
fread(&i,4,1,fil);
buildvfs_fread(&i,4,1,fil);
if (i == (int32_t)B_LITTLE32(0x04034b50)) //'PK\3\4' is ZIP file id
{
fseek(fil,-22,SEEK_END);
fread(tempbuf,22,1,fil);
buildvfs_fseek_abs(fil,buildvfs_flength(fil)-22);
buildvfs_fread(tempbuf,22,1,fil);
if (B_UNBUF32(&tempbuf[0]) == B_LITTLE32(0x06054b50)) //Fast way of finding dir info
{
numfiles = B_LITTLE16(B_UNBUF16(&tempbuf[10]));
fseek(fil,B_LITTLE32(B_UNBUF32(&tempbuf[16])),SEEK_SET);
buildvfs_fseek_abs(fil,B_LITTLE32(B_UNBUF32(&tempbuf[16])));
}
else //Slow way of finding dir info (used when ZIP has junk at end)
{
fseek(fil,0,SEEK_SET); numfiles = 0;
buildvfs_fseek_abs(fil,0); numfiles = 0;
while (1)
{
if (!fread(&j,4,1,fil)) { numfiles = -1; break; }
if (!buildvfs_fread(&j,4,1,fil)) { numfiles = -1; break; }
if (j == (int32_t)B_LITTLE32(0x02014b50)) break; //Found central file header :)
if (j != (int32_t)B_LITTLE32(0x04034b50)) { numfiles = -1; break; }
fread(tempbuf,26,1,fil);
fseek(fil,B_LITTLE32(B_UNBUF32(&tempbuf[14])) + B_LITTLE16(B_UNBUF16(&tempbuf[24])) + B_LITTLE16(B_UNBUF16(&tempbuf[22])),SEEK_CUR);
buildvfs_fread(tempbuf,26,1,fil);
buildvfs_fseek_rel(fil,B_LITTLE32(B_UNBUF32(&tempbuf[14])) + B_LITTLE16(B_UNBUF16(&tempbuf[24])) + B_LITTLE16(B_UNBUF16(&tempbuf[22])));
numfiles++;
}
if (numfiles < 0) { fclose(fil); return -1; }
fseek(fil,-4,SEEK_CUR);
if (numfiles < 0) { buildvfs_fclose(fil); return -1; }
buildvfs_fseek_rel(fil,-4);
}
for (i=0; i<numfiles; i++)
{
fread(tempbuf,46,1,fil);
if (B_UNBUF32(&tempbuf[0]) != B_LITTLE32(0x02014b50)) { fclose(fil); return 0; }
buildvfs_fread(tempbuf,46,1,fil);
if (B_UNBUF32(&tempbuf[0]) != B_LITTLE32(0x02014b50)) { buildvfs_fclose(fil); return 0; }
j = B_LITTLE16(B_UNBUF16(&tempbuf[28])); //filename length
fread(&tempbuf[46],j,1,fil);
buildvfs_fread(&tempbuf[46],j,1,fil);
tempbuf[j+46] = 0;
//Write information into hash
j = strlen(&tempbuf[46])+22; if (!kzcheckhashsiz(j)) { fclose(fil); return -1; }
j = strlen(&tempbuf[46])+22; if (!kzcheckhashsiz(j)) { buildvfs_fclose(fil); return -1; }
hashind = kzcalchash(&tempbuf[46]);
B_BUF32(&kzhashbuf[kzhashpos], kzhashead[hashind]);
B_BUF32(&kzhashbuf[kzhashpos+4], kzlastfnam);
@ -2520,24 +2513,24 @@ int32_t kzaddstack(const char *filnam)
j = B_LITTLE16(B_UNBUF16(&tempbuf[30])); //extra field length
j += B_LITTLE16(B_UNBUF16(&tempbuf[32])); //file comment length
fseek(fil,j,SEEK_CUR);
buildvfs_fseek_rel(fil,j);
}
}
else if (i == (int32_t)B_LITTLE32(0x536e654b)) //'KenS' is GRP file id
{
fread(tempbuf,12,1,fil);
buildvfs_fread(tempbuf,12,1,fil);
if ((B_UNBUF32(&tempbuf[0]) != B_LITTLE32(0x65766c69)) || //'ilve'
(B_UNBUF32(&tempbuf[4]) != B_LITTLE32(0x6e616d72))) //'rman'
{ fclose(fil); return 0; }
{ buildvfs_fclose(fil); return 0; }
numfiles = B_LITTLE32(B_UNBUF32(&tempbuf[8])); k = ((numfiles+1)<<4);
for (i=0; i<numfiles; i++,k+=leng)
{
fread(tempbuf,16,1,fil);
buildvfs_fread(tempbuf,16,1,fil);
leng = B_LITTLE32(B_UNBUF32(&tempbuf[12])); //File length
tempbuf[12] = 0;
//Write information into hash
j = strlen(tempbuf)+22; if (!kzcheckhashsiz(j)) { fclose(fil); return -1; }
j = strlen(tempbuf)+22; if (!kzcheckhashsiz(j)) { buildvfs_fclose(fil); return -1; }
hashind = kzcalchash(tempbuf);
B_BUF32(&kzhashbuf[kzhashpos], kzhashead[hashind]);
B_BUF32(&kzhashbuf[kzhashpos+4], kzlastfnam);
@ -2549,36 +2542,36 @@ int32_t kzaddstack(const char *filnam)
kzhashead[hashind] = kzhashpos; kzlastfnam = kzhashpos; kzhashpos += j;
}
}
fclose(fil);
buildvfs_fclose(fil);
return 0;
}
//this allows the use of kplib.c with a file that is already open
void kzsetfil(FILE *fil)
void kzsetfil(buildvfs_FILE fil)
{
kzfs.fil = fil;
kzfs.comptyp = 0;
kzfs.seek0 = 0;
kzfs.leng = filelength(_fileno(kzfs.fil));
kzfs.leng = buildvfs_flength(fil);
kzfs.pos = 0;
kzfs.i = 0;
}
intptr_t kzopen(const char *filnam)
{
FILE *fil;
buildvfs_FILE fil{};
int32_t i, fileoffs, fileleng;
char tempbuf[46+260], *zipnam, iscomp;
//kzfs.fil = 0;
if (filnam[0] != '|') //Search standalone file first
{
kzfs.fil = fopen(filnam,"rb");
kzfs.fil = buildvfs_fopen_read(filnam);
if (kzfs.fil)
{
kzfs.comptyp = 0;
kzfs.seek0 = 0;
kzfs.leng = filelength(_fileno(kzfs.fil));
kzfs.leng = buildvfs_flength(fil);
kzfs.pos = 0;
kzfs.i = 0;
return (intptr_t)kzfs.fil;
@ -2586,8 +2579,8 @@ intptr_t kzopen(const char *filnam)
}
if (kzcheckhash(filnam,&zipnam,&fileoffs,&fileleng,&iscomp)) //Then check mounted ZIP/GRP files
{
fil = fopen(zipnam,"rb"); if (!fil) return 0;
fseek(fil,fileoffs,SEEK_SET);
fil = buildvfs_fopen_read(zipnam); if (!fil) return 0;
buildvfs_fseek_abs(fil,fileoffs);
if (!iscomp) //Must be from GRP file
{
kzfs.fil = fil;
@ -2600,13 +2593,13 @@ intptr_t kzopen(const char *filnam)
}
else
{
fread(tempbuf,30,1,fil);
if (B_UNBUF32(&tempbuf[0]) != B_LITTLE32(0x04034b50)) { fclose(fil); return 0; }
fseek(fil,B_LITTLE16(B_UNBUF16(&tempbuf[26]))+B_LITTLE16(B_UNBUF16(&tempbuf[28])),SEEK_CUR);
buildvfs_fread(tempbuf,30,1,fil);
if (B_UNBUF32(&tempbuf[0]) != B_LITTLE32(0x04034b50)) { buildvfs_fclose(fil); return 0; }
buildvfs_fseek_rel(fil,B_LITTLE16(B_UNBUF16(&tempbuf[26]))+B_LITTLE16(B_UNBUF16(&tempbuf[28])));
kzfs.fil = fil;
kzfs.comptyp = B_LITTLE16(B_UNBUF16(&tempbuf[8]));
kzfs.seek0 = ftell(fil);
kzfs.seek0 = buildvfs_ftell(fil);
kzfs.leng = B_LITTLE32(B_UNBUF32(&tempbuf[22]));
kzfs.pos = 0;
switch (kzfs.comptyp) //Compression method
@ -2621,7 +2614,7 @@ intptr_t kzopen(const char *filnam)
gslidew = 0x7fffffff; //Force reload at beginning
return (intptr_t)kzfs.fil;
default: fclose(kzfs.fil); kzfs.fil = 0; return 0;
default: buildvfs_fclose(kzfs.fil); kzfs.fil = 0; return 0;
}
}
}
@ -2642,12 +2635,12 @@ intptr_t kzopen(const char *filnam)
strcat(tempbuf,"/");
#endif
strcat(tempbuf,filnam);
kzfs.fil = fopen(tempbuf,"rb");
kzfs.fil = buildvfs_fopen_read(tempbuf);
if (kzfs.fil)
{
kzfs.comptyp = 0;
kzfs.seek0 = 0;
kzfs.leng = filelength(_fileno(kzfs.fil));
kzfs.leng = buildvfs_flength(fil);
kzfs.pos = 0;
kzfs.i = 0;
return (intptr_t)kzfs.fil;
@ -2657,12 +2650,14 @@ intptr_t kzopen(const char *filnam)
return 0;
}
#ifndef USE_PHYSFS
// --------------------------------------------------------------------------
#if defined(_WIN32)
static HANDLE hfind = INVALID_HANDLE_VALUE;
static WIN32_FIND_DATA findata;
#else
#include <dirent.h>
#define MAX_PATH 260
static DIR *hfind = NULL;
static struct dirent *findata = NULL;
@ -2807,6 +2802,7 @@ int32_t kzfindfile(char *filnam)
//NOTES:
// * Directory names end with '\' or '/' (depending on system)
// * Files inside zip begin with '|'
#endif
// --------------------------------------------------------------------------
@ -2831,10 +2827,10 @@ int32_t kzread(void *buffer, int32_t leng)
if (kzfs.comptyp == 0)
{
if (kzfs.pos != kzfs.i) //Seek only when position changes
{ fseek(kzfs.fil,kzfs.seek0+kzfs.pos,SEEK_SET); kzfs.i = kzfs.pos; }
{ buildvfs_fseek_abs(kzfs.fil,kzfs.seek0+kzfs.pos); kzfs.i = kzfs.pos; }
i = min(kzfs.leng-kzfs.pos,leng);
fread(buffer,i,1,kzfs.fil);
kzfs.i += i; //kzfs.i is a local copy of ftell(kzfs.fil);
buildvfs_fread(buffer,i,1,kzfs.fil);
kzfs.i += i; //kzfs.i is a local copy of buildvfs_ftell(kzfs.fil);
}
else if (kzfs.comptyp == 8)
{
@ -2847,14 +2843,14 @@ int32_t kzread(void *buffer, int32_t leng)
if (kzfs.pos < gslidew-32768) // Must go back to start :(
{
if (kzfs.comptell) fseek(kzfs.fil,kzfs.seek0,SEEK_SET);
if (kzfs.comptell) buildvfs_fseek_abs(kzfs.fil,kzfs.seek0);
gslidew = 0; gslider = 16384;
kzfs.jmpplc = 0;
//Initialize for suckbits/peekbits/getbits
kzfs.comptell = min<int32_t>(kzfs.compleng,sizeof(olinbuf));
fread(&olinbuf[0],kzfs.comptell,1,kzfs.fil);
buildvfs_fread(&olinbuf[0],kzfs.comptell,1,kzfs.fil);
//Make it re-load when there are < 32 bits left in FIFO
bitpos = -(((int32_t)sizeof(olinbuf)-4)<<3);
//Identity: filptr + (bitpos>>3) = &olinbuf[0]

View file

@ -24,6 +24,8 @@ extern "C" {
#include "lunatic.h"
#include "vfs.h"
////////// HELPER FUNCTIONS //////////
@ -61,14 +63,14 @@ void L_PushDebugTraceback(lua_State *L)
static int32_t read_whole_file(const char *fn, char **retbufptr)
{
int32_t fid, flen, i;
int32_t flen, i;
char *buf;
*retbufptr = NULL;
fid = kopen4load(fn, 0); // TODO: g_loadFromGroupOnly, kopen4loadfrommod ?
buildvfs_kfd fid = kopen4load(fn, 0); // TODO: g_loadFromGroupOnly, kopen4loadfrommod ?
if (fid < 0)
if (fid == buildvfs_kfd_invalid)
return 1;
flen = kfilelength(fid);

View file

@ -17,6 +17,8 @@
#include "common.h"
#include "palette.h"
#include "vfs.h"
static int32_t curextra=MAXTILES;
#define MIN_CACHETIME_PRINT 10
@ -691,8 +693,8 @@ int32_t mdloadskin(md2model_t *m, int32_t number, int32_t pal, int32_t surf)
*texidx = 0;
int32_t filh;
if ((filh = kopen4load(fn, 0)) < 0)
buildvfs_kfd filh;
if ((filh = kopen4load(fn, 0)) == buildvfs_kfd_invalid)
return mdloadskin_notfound(skinfile, fn);
@ -1192,7 +1194,7 @@ static void mdloadvbos(md3model_t *m)
#endif
//--------------------------------------- MD2 LIBRARY BEGINS ---------------------------------------
static md2model_t *md2load(int32_t fil, const char *filnam)
static md2model_t *md2load(buildvfs_kfd fil, const char *filnam)
{
md2model_t *m;
md3model_t *m3;
@ -1477,7 +1479,7 @@ static inline void quicksort(uint16_t *indexes, float *depths, int32_t first, in
//--------------------------------------- MD3 LIBRARY BEGINS ---------------------------------------
static md3model_t *md3load(int32_t fil)
static md3model_t *md3load(buildvfs_kfd fil)
{
int32_t i, surfi, ofsurf, offs[4], leng[4];
int32_t maxtrispersurf;
@ -2653,15 +2655,14 @@ static void md3free(md3model_t *m)
mdmodel_t *mdload(const char *filnam)
{
mdmodel_t *vm;
int32_t fil;
int32_t i;
vm = (mdmodel_t *)voxload(filnam);
if (vm) return vm;
fil = kopen4load(filnam,0);
buildvfs_kfd fil = kopen4load(filnam,0);
if (fil < 0)
if (fil == buildvfs_kfd_invalid)
return NULL;
kread(fil,&i,4);

View file

@ -12,6 +12,8 @@
#define XXH_STATIC_LINKING_ONLY
#include "xxhash.h"
#include "vfs.h"
static osdsymbol_t *osd_addsymbol(const char *name);
static osdsymbol_t *osd_findsymbol(const char *pszName, osdsymbol_t *pSymbol);
static osdsymbol_t *osd_findexactsymbol(const char *pszName);
@ -31,7 +33,7 @@ osdmain_t *osd;
static int osdrowscur = -1;
static int osdmaxrows = 20;
BFILE *osdlog;
buildvfs_FILE osdlog;
const char *osdlogfn;
@ -161,9 +163,10 @@ const char * OSD_StripColors(char *outBuf, const char *inBuf)
int OSD_Exec(const char *szScript)
{
int err = 0;
int32_t handle, len = 0;
int32_t len = 0;
buildvfs_kfd handle;
if ((handle = kopen4load(szScript, 0)) == -1)
if ((handle = kopen4load(szScript, 0)) == buildvfs_kfd_invalid)
err = 1;
else if ((len = kfilelength(handle)) <= 0)
err = 2; // blank file
@ -178,7 +181,7 @@ int OSD_Exec(const char *szScript)
if (!err) // no error message for blank file
OSD_Printf("Error executing \"%s\"!\n", szScript);
if (handle != -1)
if (handle != buildvfs_kfd_invalid)
kclose(handle);
Bfree(buf);
@ -269,9 +272,9 @@ static int osdfunc_fileinfo(osdcmdptr_t parm)
{
if (parm->numparms != 1) return OSDCMD_SHOWHELP;
int32_t h;
buildvfs_kfd h;
if ((h = kopen4load(parm->parms[0],0)) < 0)
if ((h = kopen4load(parm->parms[0],0)) == buildvfs_kfd_invalid)
{
OSD_Printf("fileinfo: File \"%s\" not found.\n", parm->parms[0]);
return OSDCMD_OK;
@ -761,16 +764,18 @@ void OSD_SetLogFile(const char *fn)
if (!fn)
return;
osdlog = Bfopen(fn, "w");
osdlog = buildvfs_fopen_write(fn);
if (osdlog)
{
#ifndef USE_PHYSFS
#ifdef DEBUGGINGAIDS
const int bufmode = _IONBF;
#else
const int bufmode = _IOLBF;
#endif
setvbuf(osdlog, (char *)NULL, bufmode, BUFSIZ);
#endif
osdlogfn = fn;
}
}
@ -1642,13 +1647,13 @@ void OSD_Puts(const char *tmpstr)
if (log.lines < log.cutoff)
{
char *chp2 = Xstrdup(tmpstr);
Bfputs(OSD_StripColors(chp2, tmpstr), osdlog);
buildvfs_fputs(OSD_StripColors(chp2, tmpstr), osdlog);
Bprintf("%s", chp2);
Bfree(chp2);
}
else if (log.lines == log.cutoff)
{
Bfputs("\nLog file full! Consider increasing \"osdlogcutoff\".\n", osdlog);
buildvfs_fputs("\nLog file full! Consider increasing \"osdlogcutoff\".\n", osdlog);
log.lines = log.cutoff + 1;
}
@ -2175,23 +2180,29 @@ int osdcmd_cvar_set(osdcmdptr_t parm)
return OSDCMD_OK;
}
void OSD_WriteAliases(FILE *fp)
void OSD_WriteAliases(buildvfs_FILE fp)
{
Bassert(fp);
for (auto &symb : osd->symbptrs)
{
if (symb == NULL)
break;
else if (symb->func == (void *)OSD_ALIAS)
Bfprintf(fp, "alias \"%s\" \"%s\"\n", symb->name, symb->help);
{
buildvfs_fputstr(fp, "alias \"");
buildvfs_fputstrptr(fp, symb->name);
buildvfs_fputstr(fp, "\" \"");
buildvfs_fputstrptr(fp, symb->help);
buildvfs_fputstr(fp, "\"\n");
}
}
}
void OSD_WriteCvars(FILE *fp)
void OSD_WriteCvars(buildvfs_FILE fp)
{
Bassert(fp);
char buf[64];
for (unsigned i = 0; i < osd->numcvars; i++)
{
osdcvardata_t const &pData = *osd->cvars[i].pData;
@ -2200,12 +2211,33 @@ void OSD_WriteCvars(FILE *fp)
{
switch (pData.flags & CVAR_TYPEMASK)
{
case CVAR_FLOAT: fprintf(fp, "%s \"%f\"\n", pData.name, *pData.f); break;
case CVAR_DOUBLE: fprintf(fp, "%s \"%f\"\n", pData.name, *pData.d); break;
case CVAR_FLOAT:
buildvfs_fputstrptr(fp, pData.name);
snprintf(buf, sizeof(buf), " \"%f\"\n", *pData.f);
buildvfs_fputstrptr(fp, buf);
break;
case CVAR_DOUBLE:
buildvfs_fputstrptr(fp, pData.name);
snprintf(buf, sizeof(buf), " \"%f\"\n", *pData.d);
buildvfs_fputstrptr(fp, buf);
break;
case CVAR_INT:
case CVAR_BOOL: fprintf(fp, "%s \"%d\"\n", pData.name, *pData.i32); break;
case CVAR_UINT: fprintf(fp, "%s \"%u\"\n", pData.name, *pData.u32); break;
case CVAR_STRING: fprintf(fp, "%s \"%s\"\n", pData.name, pData.string); break;
case CVAR_BOOL:
buildvfs_fputstrptr(fp, pData.name);
snprintf(buf, sizeof(buf), " \"%d\"\n", *pData.i32);
buildvfs_fputstrptr(fp, buf);
break;
case CVAR_UINT:
buildvfs_fputstrptr(fp, pData.name);
snprintf(buf, sizeof(buf), " \"%u\"\n", *pData.u32);
buildvfs_fputstrptr(fp, buf);
break;
case CVAR_STRING:
buildvfs_fputstrptr(fp, pData.name);
buildvfs_fputstr(fp, " \"");
buildvfs_fputstrptr(fp, pData.string);
buildvfs_fputstr(fp, "\"\n");
break;
default: EDUKE32_UNREACHABLE_SECTION(break);
}
}

View file

@ -16,6 +16,8 @@
#include "a.h"
#include "xxhash.h"
#include "vfs.h"
uint8_t *basepaltable[MAXBASEPALS] = { palette };
uint8_t basepalreset=1;
uint8_t curbasepal;
@ -151,8 +153,8 @@ void paletteLoadFromDisk(void)
x = defaultglblend;
#endif
int32_t fil;
if ((fil = kopen4load("palette.dat", 0)) == -1)
buildvfs_kfd fil;
if ((fil = kopen4load("palette.dat", 0)) == buildvfs_kfd_invalid)
return;
@ -407,7 +409,7 @@ void paletteFixTranslucencyMask(void)
// - on success, 0
// - on error, -1 (didn't read enough data)
// - -2: error, we already wrote an error message ourselves
int32_t paletteLoadLookupTable(int32_t fp)
int32_t paletteLoadLookupTable(buildvfs_kfd fp)
{
uint8_t numlookups;
char remapbuf[256];

View file

@ -2,9 +2,11 @@
#include "pngwrite.h"
#include "crc32.h"
#include "vfs.h"
pngwrite_t png;
#define png_write_buf(p, size) Bfwrite(p, size, 1, png.file)
#define png_write_buf(p, size) buildvfs_fwrite(p, size, 1, png.file)
static FORCE_INLINE void png_write_uint32(uint32_t const in)
{
@ -57,7 +59,7 @@ void png_set_text(char const * const keyword, char const * const text)
Bmemcpy(png.text + keylen + 1, text, textlen);
}
void png_write(FILE * const file, uint32_t const width, uint32_t const height,
void png_write(buildvfs_FILE const file, uint32_t const width, uint32_t const height,
uint8_t const type, uint8_t const * const data)
{
png.file = file;

View file

@ -26,9 +26,7 @@ Ken Silverman's official web site: http://www.advsys.net/ken
#include "palette.h"
#include "tilepacker.h"
#ifndef _WIN32
extern int32_t filelength(int h); // kplib.c
#endif
#include "vfs.h"
extern char textfont[2048], smalltextfont[2048];
@ -2363,8 +2361,8 @@ int32_t gloadtile_hi(int32_t dapic,int32_t dapalnum, int32_t facen, hicreplctyp
fn = hicr->filename;
}
int32_t filh;
if (EDUKE32_PREDICT_FALSE((filh = kopen4load(fn, 0)) < 0))
buildvfs_kfd filh;
if (EDUKE32_PREDICT_FALSE((filh = kopen4load(fn, 0)) == buildvfs_kfd_invalid))
{
OSD_Printf("hightile: %s (pic %d) not found\n", fn, dapic);
return -2;

View file

@ -4,13 +4,15 @@
#include "pngwrite.h"
#include "vfs.h"
//
// screencapture
//
FILE *OutputFileCounter::opennextfile(char *fn, char *zeros)
buildvfs_FILE OutputFileCounter::opennextfile(char *fn, char *zeros)
{
FILE *file;
buildvfs_FILE file;
do // JBF 2004022: So we don't overwrite existing screenshots
{
@ -21,15 +23,15 @@ FILE *OutputFileCounter::opennextfile(char *fn, char *zeros)
zeros[2] = ((count/10)%10)+'0';
zeros[3] = (count%10)+'0';
if ((file = fopen(fn, "rb")) == nullptr) break;
fclose(file);
if ((file = buildvfs_fopen_read(fn)) == nullptr) break;
buildvfs_fclose(file);
count++;
} while (1);
return fopen(fn, "wb");
return buildvfs_fopen_write(fn);
}
FILE *OutputFileCounter::opennextfile_withext(char *fn, const char *ext)
buildvfs_FILE OutputFileCounter::opennextfile_withext(char *fn, const char *ext)
{
char *dot = strrchr(fn, '.');
strcpy(dot+1, ext);
@ -38,9 +40,9 @@ FILE *OutputFileCounter::opennextfile_withext(char *fn, const char *ext)
static OutputFileCounter capturecounter;
static void screencapture_end(char *fn, BFILE** filptr)
static void screencapture_end(char *fn, buildvfs_FILE * filptr)
{
Bfclose(*filptr);
buildvfs_fclose(*filptr);
OSD_Printf("Saved screenshot to %s\n", fn);
Bfree(fn);
capturecounter.count++;
@ -55,7 +57,7 @@ static void screencapture_end(char *fn, BFILE** filptr)
int videoCaptureScreen(const char *filename, char inverseit)
{
char *fn = Xstrdup(filename);
FILE *fp = capturecounter.opennextfile_withext(fn, "png");
buildvfs_FILE fp = capturecounter.opennextfile_withext(fn, "png");
if (fp == nullptr)
{
@ -136,7 +138,7 @@ int videoCaptureScreenTGA(const char *filename, char inverseit)
//char palette[4*256];
char *fn = Xstrdup(filename);
FILE *fil = capturecounter.opennextfile_withext(fn, "tga");
buildvfs_FILE fil = capturecounter.opennextfile_withext(fn, "tga");
if (fil == nullptr)
{
Bfree(fn);
@ -162,7 +164,7 @@ int videoCaptureScreenTGA(const char *filename, char inverseit)
head[14] = ydim & 0xff;
head[15] = (ydim >> 8) & 0xff;
Bfwrite(head, 18, 1, fil);
buildvfs_fwrite(head, 18, 1, fil);
// palette first
#ifdef USE_OPENGL
@ -173,18 +175,18 @@ int videoCaptureScreenTGA(const char *filename, char inverseit)
{
for (i=0; i<256; i++)
{
Bfputc(255 - curpalettefaded[i].b, fil);
Bfputc(255 - curpalettefaded[i].g, fil);
Bfputc(255 - curpalettefaded[i].r, fil);
buildvfs_fputc(255 - curpalettefaded[i].b, fil);
buildvfs_fputc(255 - curpalettefaded[i].g, fil);
buildvfs_fputc(255 - curpalettefaded[i].r, fil);
}
}
else
{
for (i=0; i<256; i++)
{
Bfputc(curpalettefaded[i].b, fil);
Bfputc(curpalettefaded[i].g, fil);
Bfputc(curpalettefaded[i].r, fil);
buildvfs_fputc(curpalettefaded[i].b, fil);
buildvfs_fputc(curpalettefaded[i].g, fil);
buildvfs_fputc(curpalettefaded[i].r, fil);
}
}
}
@ -203,7 +205,7 @@ int videoCaptureScreenTGA(const char *filename, char inverseit)
for (i = 0; i < size; i += 3)
swapchar(&inversebuf[i], &inversebuf[i + 2]);
Bfwrite(inversebuf, xdim*ydim, 3, fil);
buildvfs_fwrite(inversebuf, xdim*ydim, 3, fil);
Bfree(inversebuf);
}
else
@ -212,7 +214,7 @@ int videoCaptureScreenTGA(const char *filename, char inverseit)
char * const ptr = (char *) frameplace;
for (i = ydim-1; i >= 0; i--)
Bfwrite(ptr + i * bytesperline, xdim, 1, fil);
buildvfs_fwrite(ptr + i * bytesperline, xdim, 1, fil);
}
videoEndDrawing(); //}}}

View file

@ -11,6 +11,8 @@
#include "compat.h"
#include "cache1d.h"
#include "vfs.h"
#define ISWS(x) ((x == ' ') || (x == '\t') || (x == '\r') || (x == '\n'))
static inline void skipoverws(scriptfile *sf) { if ((sf->textptr < sf->eof) && (!sf->textptr[0])) sf->textptr++; }
@ -299,8 +301,8 @@ void scriptfile_preparse(scriptfile *sf, char *tx, int32_t flen)
scriptfile *scriptfile_fromfile(const char *fn)
{
int32_t fp = kopen4load(fn, 0);
if (fp < 0) return nullptr;
buildvfs_kfd fp = kopen4load(fn, 0);
if (fp == buildvfs_kfd_invalid) return nullptr;
uint32_t flen = kfilelength(fp);
char * tx = (char *)Xmalloc(flen + 2);

View file

@ -38,6 +38,8 @@
# include "winbits.h"
#endif
#include "vfs.h"
#if SDL_MAJOR_VERSION != 1
static SDL_version linked;
#endif
@ -488,8 +490,17 @@ int main(int argc, char *argv[])
}
buildargv[buildargc] = NULL;
#ifdef USE_PHYSFS
PHYSFS_init(buildargv[0]);
PHYSFS_setWriteDir(PHYSFS_getBaseDir());
#endif
r = app_main(buildargc, (const char **)buildargv);
#else
#ifdef USE_PHYSFS
int pfsi = PHYSFS_init(argv[0]);
assert(pfsi != 0);
PHYSFS_setWriteDir(PHYSFS_getUserDir());
#endif
r = app_main(argc, (char const * const *)argv);
#endif

View file

@ -11,6 +11,16 @@
#include "xxhash.h"
#include "kplib.h"
#include "vfs.h"
#include <fcntl.h>
#ifdef _WIN32
# include <io.h>
#else
# include <unistd.h>
#endif
#include <sys/stat.h>
#define CLEAR_GL_ERRORS() while(glGetError() != GL_NO_ERROR) { }
#define TEXCACHE_FREEBUFS() { Bfree(pic), Bfree(packbuf), Bfree(midbuf); }
@ -232,7 +242,7 @@ static inline void texcache_clearmemcache(void)
void texcache_syncmemcache(void)
{
int32_t len = Bfilelength(texcache.handle);
int32_t len = filelength(texcache.handle);
if (!texcache.buf || texcache.handle == -1 || len <= (int32_t)texcache.memsize)
return;
@ -310,10 +320,11 @@ void texcache_openfiles(void)
Bstrcpy(ptempbuf, TEXCACHEFILE);
Bstrcat(ptempbuf, ".index");
texcache.index = Bfopen(ptempbuf, "at+");
bool const texcache_exists = buildvfs_exists(ptempbuf);
texcache.index = buildvfs_fopen_append(ptempbuf);
texcache.handle = Bopen(TEXCACHEFILE, BO_BINARY | BO_CREAT | BO_APPEND | BO_RDWR, BS_IREAD | BS_IWRITE);
if (!texcache.index || texcache.handle < 0)
if (!texcache.index || texcache.handle == -1)
{
initprintf("Unable to open cache file \"%s\" or \"%s\": %s\n", TEXCACHEFILE, ptempbuf, strerror(errno));
texcache_closefiles();
@ -321,13 +332,10 @@ void texcache_openfiles(void)
return;
}
Bfseek(texcache.index, 0, BSEEK_END);
if (!Bftell(texcache.index))
if (!texcache_exists)
{
Brewind(texcache.index);
Bfprintf(texcache.index,"// automatically generated by the engine, DO NOT MODIFY!\n");
buildvfs_fputstr(texcache.index, "// automatically generated by the engine, DO NOT MODIFY!\n");
}
else Brewind(texcache.index);
initprintf("Opened \"%s\" as cache file\n", TEXCACHEFILE);
}
@ -693,8 +701,10 @@ void texcache_postwritetex(char const * const cacheid, int32_t const offset)
if (texcache.index)
{
fseek(texcache.index, 0, BSEEK_END);
Bfprintf(texcache.index, "%s %d %d\n", t->name, t->offset, t->len);
char buf[64];
buildvfs_fputstrptr(texcache.index, t->name);
snprintf(buf, sizeof(buf), " %d %d\n", t->offset, t->len);
buildvfs_fputstrptr(texcache.index, buf);
}
else
OSD_Printf("wtf?\n");
@ -838,7 +848,7 @@ void texcache_setupmemcache(void)
if (!glusememcache || !texcache_enabled())
return;
texcache.memsize = Bfilelength(texcache.handle);
texcache.memsize = filelength(texcache.handle);
if (texcache.memsize <= 0)
return;

View file

@ -13,6 +13,8 @@
#include "cache1d.h"
#include "lz4.h"
#include "vfs.h"
void *pic = NULL;
// The tile file number (tilesXXX <- this) of each tile:
@ -39,7 +41,8 @@ static int32_t cachesize = 0;
static char artfilename[20];
static char mapartfilename[BMAX_PATH]; // map-specific ART file name
static int32_t mapartfnXXofs; // byte offset to 'XX' (the number part) in the above
static int32_t artfil = -1, artfilnum, artfilplc;
static int32_t artfilnum, artfilplc;
static buildvfs_kfd artfil;
////////// Per-map ART file loading //////////
@ -86,7 +89,7 @@ void artClearMapArt(void)
{
kclose(artfil);
artfil = -1;
artfil = buildvfs_kfd_invalid;
artfilnum = -1;
artfilplc = 0L;
}
@ -141,9 +144,9 @@ void artSetupMapArt(const char *filename)
mapartfnXXofs = Bstrlen(mapartfilename) - 6;
// Check for first per-map ART file: if that one doesn't exist, don't load any.
int32_t fil = kopen4load(artGetIndexedFileName(MAXARTFILES_BASE), 0);
buildvfs_kfd fil = kopen4load(artGetIndexedFileName(MAXARTFILES_BASE), 0);
if (fil == -1)
if (fil == buildvfs_kfd_invalid)
{
artClearMapArtFilename();
return;
@ -284,7 +287,7 @@ void tileSetSize(int32_t picnum, int16_t dasizx, int16_t dasizy)
tileUpdatePicSiz(picnum);
}
int32_t artReadHeader(int32_t const fil, char const * const fn, artheader_t * const local)
int32_t artReadHeader(buildvfs_kfd const fil, char const * const fn, artheader_t * const local)
{
int32_t artversion;
kread(fil, &artversion, 4); artversion = B_LITTLE32(artversion);
@ -378,7 +381,7 @@ void tileConvertAnimFormat(int32_t const picnum)
thispicanm->sf &= ~PICANM_MISC_MASK;
}
void artReadManifest(int32_t const fil, artheader_t const * const local)
void artReadManifest(buildvfs_kfd const fil, artheader_t const * const local)
{
int16_t *tilesizx = (int16_t *) Xmalloc(local->numtiles * sizeof(int16_t));
int16_t *tilesizy = (int16_t *) Xmalloc(local->numtiles * sizeof(int16_t));
@ -398,7 +401,7 @@ void artReadManifest(int32_t const fil, artheader_t const * const local)
DO_FREE_AND_NULL(tilesizy);
}
void artPreloadFile(int32_t const fil, artheader_t const * const local)
void artPreloadFile(buildvfs_kfd const fil, artheader_t const * const local)
{
char *buffer = NULL;
int32_t buffersize = 0;
@ -421,7 +424,7 @@ void artPreloadFile(int32_t const fil, artheader_t const * const local)
DO_FREE_AND_NULL(buffer);
}
static void artPreloadFileSafe(int32_t const fil, artheader_t const * const local)
static void artPreloadFileSafe(buildvfs_kfd const fil, artheader_t const * const local)
{
char *buffer = NULL;
int32_t buffersize = 0;
@ -475,9 +478,9 @@ static int32_t artReadIndexedFile(int32_t tilefilei)
{
const char *fn = artGetIndexedFileName(tilefilei);
const int32_t permap = (tilefilei >= MAXARTFILES_BASE); // is it a per-map ART file?
int32_t fil;
buildvfs_kfd fil;
if ((fil = kopen4load(fn, 0)) != -1)
if ((fil = kopen4load(fn, 0)) != buildvfs_kfd_invalid)
{
artheader_t local;
int const headerval = artReadHeader(fil, fn, &local);
@ -511,7 +514,11 @@ static int32_t artReadIndexedFile(int32_t tilefilei)
artReadManifest(fil, &local);
#ifndef USE_PHYSFS
if (cache1d_file_fromzip(fil))
#else
if (1)
#endif
{
if (permap)
artPreloadFileSafe(fil, &local);
@ -572,7 +579,7 @@ int32_t artLoadFiles(const char *filename, int32_t askedsize)
artUpdateManifest();
artfil = -1;
artfil = buildvfs_kfd_invalid;
artfilnum = -1;
artfilplc = 0L;
@ -667,14 +674,14 @@ void tileLoadData(int16_t tilenume, int32_t dasiz, char *buffer)
// Potentially switch open ART file.
if (tfn != artfilnum)
{
if (artfil != -1)
if (artfil != buildvfs_kfd_invalid)
kclose(artfil);
char const *fn = artGetIndexedFileName(tfn);
artfil = kopen4load(fn, 0);
if (artfil == -1)
if (artfil == buildvfs_kfd_invalid)
{
initprintf("Failed opening ART file \"%s\"!\n", fn);
engineUnInit();
@ -819,7 +826,7 @@ void tileCopySection(int32_t tilenume1, int32_t sx1, int32_t sy1, int32_t xsiz,
void Buninitart(void)
{
if (artfil != -1)
if (artfil != buildvfs_kfd_invalid)
kclose(artfil);
ALIGNED_FREE_AND_NULL(pic);

29
source/build/src/vfs.cpp Normal file
View file

@ -0,0 +1,29 @@
#include "vfs.h"
#include "cache1d.h"
#ifdef USE_PHYSFS
int32_t numgroupfiles;
void uninitgroupfile(void)
{
PHYSFS_deinit();
}
#include <sys/stat.h>
int32_t klseek(buildvfs_kfd handle, int32_t offset, int32_t whence)
{
// TODO: replace klseek calls with _{abs,cur,end} versions
if (whence == SEEK_CUR)
offset += PHYSFS_tell(handle);
else if (whence == SEEK_END)
offset += PHYSFS_fileLength(handle);
PHYSFS_seek(handle, offset);
return PHYSFS_tell(handle);
}
#endif

View file

@ -16,6 +16,8 @@
#include "kplib.h"
#include "palette.h"
#include "vfs.h"
//For loading/conversion only
static vec3_t voxsiz;
@ -599,7 +601,7 @@ static void alloc_vbit(void)
memset(vbit, 0, i);
}
static void read_pal(int32_t fil, int32_t pal[256])
static void read_pal(buildvfs_kfd fil, int32_t pal[256])
{
klseek(fil, -768, SEEK_END);
@ -615,8 +617,8 @@ static void read_pal(int32_t fil, int32_t pal[256])
static int32_t loadvox(const char *filnam)
{
const int32_t fil = kopen4load(filnam, 0);
if (fil < 0)
const buildvfs_kfd fil = kopen4load(filnam, 0);
if (fil == buildvfs_kfd_invalid)
return -1;
kread(fil, &voxsiz, sizeof(vec3_t));
@ -692,8 +694,8 @@ static int32_t loadkvx(const char *filnam)
{
int32_t i, mip1leng;
const int32_t fil = kopen4load(filnam, 0);
if (fil < 0)
const buildvfs_kfd fil = kopen4load(filnam, 0);
if (fil == buildvfs_kfd_invalid)
return -1;
kread(fil, &mip1leng, 4); mip1leng = B_LITTLE32(mip1leng);
@ -777,8 +779,8 @@ static int32_t loadkv6(const char *filnam)
{
int32_t i;
const int32_t fil = kopen4load(filnam, 0);
if (fil < 0)
const buildvfs_kfd fil = kopen4load(filnam, 0);
if (fil == buildvfs_kfd_invalid)
return -1;
kread(fil, &i, 4);

View file

@ -16,11 +16,13 @@
#include <ogc/color.h>
#include <gctypes.h> // for bool
#include "vfs.h"
#ifdef __cplusplus
extern "C" {
#endif
extern BFILE *osdlog;
extern buildvfs_FILE osdlog;
extern void L2Enhance();
extern void CON_EnableGecko(int channel,int safe);

View file

@ -7,7 +7,6 @@ duke3d_h=\
$(engine_inc)/polymost.h \
$(engine_inc)/texcache.h \
$(engine_inc)/cache1d.h \
$(mact_inc)/file_lib.h \
$(mact_inc)/keyboard.h \
$(mact_inc)/mouse.h \
$(mact_inc)/joystick.h \
@ -120,7 +119,6 @@ $(duke3d_obj)/startgtk.game.$o: $(duke3d_src)/startgtk.game.cpp $(duke3d_h) $(en
# mact objects
$(mact_obj)/animlib.$o: $(mact_src)/animlib.cpp $(mact_inc)/animlib.h $(engine_inc)/compat.h
$(mact_obj)/file_lib.$o: $(mact_src)/file_lib.cpp $(mact_inc)/file_lib.h
$(mact_obj)/control.$o: $(mact_src)/control.cpp $(mact_inc)/control.h $(mact_inc)/keyboard.h $(mact_inc)/mouse.h $(mact_inc)/joystick.h $(engine_inc)/baselayer.h
$(mact_obj)/keyboard.$o: $(mact_src)/keyboard.cpp $(mact_inc)/keyboard.h $(engine_inc)/compat.h $(engine_inc)/baselayer.h
$(mact_obj)/joystick.$o: $(mact_src)/joystick.cpp $(mact_inc)/joystick.h $(engine_inc)/baselayer.h

View file

@ -23,6 +23,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#ifndef rts_private__
#define rts_private__
#include "cache1d.h"
#include "vfs.h"
//===============
// TYPES
//===============
@ -30,7 +33,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
typedef struct
{
char name[8];
int32_t handle, position, size;
buildvfs_kfd handle;
int32_t position, size;
} lumpinfo_t;
typedef struct

View file

@ -34,6 +34,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# include "animvpx.h"
#endif
#include "vfs.h"
// animsound_t.sound
EDUKE32_STATIC_ASSERT(INT16_MAX >= MAXSOUNDS);
@ -245,11 +247,11 @@ int32_t Anim_Play(const char *fn)
break;
dukeanim_t const * origanim = anim;
int32_t handle = -1;
buildvfs_kfd handle = buildvfs_kfd_invalid;
if (!Bstrcmp(dot, ".ivf"))
{
handle = kopen4loadfrommod(fn, 0);
if (handle == -1)
if (handle == buildvfs_kfd_invalid)
break;
}
else
@ -268,7 +270,7 @@ int32_t Anim_Play(const char *fn)
vpxfndot[4] = '\0';
handle = kopen4loadfrommod(vpxfn, 0);
if (handle == -1)
if (handle == buildvfs_kfd_invalid)
break;
anim = Anim_Find(vpxfn);
@ -417,9 +419,9 @@ int32_t Anim_Play(const char *fn)
#ifdef USE_OPENGL
int32_t ogltexfiltermode = gltexfiltermode;
#endif
int32_t handle = kopen4load(fn, 0);
buildvfs_kfd handle = kopen4load(fn, 0);
if (handle == -1)
if (handle == buildvfs_kfd_invalid)
return 0;
int32_t length = kfilelength(handle);

View file

@ -9,6 +9,8 @@
#include "grpscan.h"
#include "vfs.h"
#ifdef _WIN32
# define NEED_SHLWAPI_H
# include "windows_inc.h"
@ -239,9 +241,9 @@ void G_SetupGlobalPsky(void)
static char g_rootDir[BMAX_PATH];
char g_modDir[BMAX_PATH] = "/";
int kopen4loadfrommod(const char *fileName, char searchfirst)
buildvfs_kfd kopen4loadfrommod(const char *fileName, char searchfirst)
{
int kFile = -1;
buildvfs_kfd kFile = buildvfs_kfd_invalid;
if (g_modDir[0] != '/' || g_modDir[1] != 0)
{
@ -250,7 +252,7 @@ int kopen4loadfrommod(const char *fileName, char searchfirst)
kFile = kopen4load(staticFileName, searchfirst);
}
return (kFile < 0) ? kopen4load(fileName, searchfirst) : kFile;
return (kFile == buildvfs_kfd_invalid) ? kopen4load(fileName, searchfirst) : kFile;
}
int g_useCwd;
@ -264,9 +266,9 @@ void G_ExtPreInit(int32_t argc,char const * const * argv)
#ifdef _WIN32
GetModuleFileName(NULL,g_rootDir,BMAX_PATH);
Bcorrectfilename(g_rootDir,1);
//chdir(g_rootDir);
//buildvfs_chdir(g_rootDir);
#else
getcwd(g_rootDir,BMAX_PATH);
buildvfs_getcwd(g_rootDir,BMAX_PATH);
strcat(g_rootDir,"/");
#endif
}
@ -281,7 +283,12 @@ void G_ExtInit(void)
Bfree(appdir);
#endif
if (getcwd(cwd,BMAX_PATH) && Bstrcmp(cwd,"/") != 0)
#ifdef USE_PHYSFS
strncpy(cwd, PHYSFS_getBaseDir(), ARRAY_SIZE(cwd));
cwd[ARRAY_SIZE(cwd)-1] = '\0';
#else
if (buildvfs_getcwd(cwd, ARRAY_SIZE(cwd)) && Bstrcmp(cwd, "/") != 0)
#endif
addsearchpath(cwd);
if (CommandPaths)
@ -305,9 +312,9 @@ void G_ExtInit(void)
}
#if defined(_WIN32) && !defined(EDUKE32_STANDALONE)
if (!access("user_profiles_enabled", F_OK))
if (!buildvfs_exists("user_profiles_enabled"))
#else
if (g_useCwd == 0 && access("user_profiles_disabled", F_OK))
if (g_useCwd == 0 && !buildvfs_exists("user_profiles_disabled"))
#endif
{
char *homedir;
@ -315,7 +322,7 @@ void G_ExtInit(void)
if ((homedir = Bgethomedir()))
{
Bsnprintf(cwd,sizeof(cwd),"%s/"
Bsnprintf(cwd, ARRAY_SIZE(cwd), "%s/"
#if defined(_WIN32)
APPNAME
#elif defined(GEKKO)
@ -327,11 +334,11 @@ void G_ExtInit(void)
asperr = addsearchpath(cwd);
if (asperr == -2)
{
if (Bmkdir(cwd,S_IRWXU) == 0) asperr = addsearchpath(cwd);
if (buildvfs_mkdir(cwd,S_IRWXU) == 0) asperr = addsearchpath(cwd);
else asperr = -1;
}
if (asperr == 0)
Bchdir(cwd);
buildvfs_chdir(cwd);
Bfree(homedir);
}
}
@ -412,13 +419,13 @@ void G_LoadGroups(int32_t autoload)
char path[BMAX_PATH];
if (getcwd(cwd, BMAX_PATH))
if (buildvfs_getcwd(cwd, BMAX_PATH))
{
Bsnprintf(path, sizeof(path), "%s/%s", cwd, g_modDir);
if (!Bstrcmp(g_rootDir, path))
{
if (addsearchpath(path) == -2)
if (Bmkdir(path, S_IRWXU) == 0)
if (buildvfs_mkdir(path, S_IRWXU) == 0)
addsearchpath(path);
}
}
@ -749,16 +756,16 @@ static char* KeyValues_FindKeyValue(char **vdfbuf, char * const vdfbufend, const
static void G_ParseSteamKeyValuesForPaths(const char *vdf)
{
int32_t fd = Bopen(vdf, BO_RDONLY);
int32_t size = Bfilelength(fd);
buildvfs_fd fd = buildvfs_open_read(vdf);
int32_t size = buildvfs_length(fd);
char *vdfbufstart, *vdfbuf, *vdfbufend;
if (size <= 0)
return;
vdfbufstart = vdfbuf = (char*)Xmalloc(size);
size = (int32_t)Bread(fd, vdfbuf, size);
Bclose(fd);
size = (int32_t)buildvfs_read(fd, vdfbuf, size);
buildvfs_close(fd);
vdfbufend = vdfbuf + size;
if (KeyValues_FindParentKey(&vdfbuf, vdfbufend, "LibraryFolders"))
@ -1026,10 +1033,11 @@ void G_DoAutoload(const char *dirname)
void G_LoadLookups(void)
{
int32_t fp, j;
int32_t j;
buildvfs_kfd fp;
if ((fp=kopen4loadfrommod("lookup.dat",0)) == -1)
if ((fp=kopen4loadfrommod("lookup.dat",1)) == -1)
if ((fp=kopen4loadfrommod("lookup.dat",0)) == buildvfs_kfd_invalid)
if ((fp=kopen4loadfrommod("lookup.dat",1)) == buildvfs_kfd_invalid)
return;
j = paletteLoadLookupTable(fp);
@ -1065,13 +1073,13 @@ void G_LoadLookups(void)
#ifdef FORMAT_UPGRADE_ELIGIBLE
static int32_t S_TryFormats(char * const testfn, char * const fn_suffix, char const searchfirst)
static buildvfs_kfd S_TryFormats(char * const testfn, char * const fn_suffix, char const searchfirst)
{
#ifdef HAVE_FLAC
{
Bstrcpy(fn_suffix, ".flac");
int32_t const fp = kopen4loadfrommod(testfn, searchfirst);
if (fp >= 0)
buildvfs_kfd const fp = kopen4loadfrommod(testfn, searchfirst);
if (fp != buildvfs_kfd_invalid)
return fp;
}
#endif
@ -1079,16 +1087,16 @@ static int32_t S_TryFormats(char * const testfn, char * const fn_suffix, char co
#ifdef HAVE_VORBIS
{
Bstrcpy(fn_suffix, ".ogg");
int32_t const fp = kopen4loadfrommod(testfn, searchfirst);
if (fp >= 0)
buildvfs_kfd const fp = kopen4loadfrommod(testfn, searchfirst);
if (fp != buildvfs_kfd_invalid)
return fp;
}
#endif
return -1;
return buildvfs_kfd_invalid;
}
static int32_t S_TryExtensionReplacements(char * const testfn, char const searchfirst, uint8_t const ismusic)
static buildvfs_kfd S_TryExtensionReplacements(char * const testfn, char const searchfirst, uint8_t const ismusic)
{
char * extension = Bstrrchr(testfn, '.');
char * const fn_end = Bstrchr(testfn, '\0');
@ -1098,8 +1106,8 @@ static int32_t S_TryExtensionReplacements(char * const testfn, char const search
{
*extension = '_';
int32_t const fp = S_TryFormats(testfn, fn_end, searchfirst);
if (fp >= 0)
buildvfs_kfd const fp = S_TryFormats(testfn, fn_end, searchfirst);
if (fp != buildvfs_kfd_invalid)
return fp;
}
else
@ -1110,29 +1118,34 @@ static int32_t S_TryExtensionReplacements(char * const testfn, char const search
// ex: grabbag.mid --> grabbag.*
if (ismusic)
{
int32_t const fp = S_TryFormats(testfn, extension, searchfirst);
if (fp >= 0)
buildvfs_kfd const fp = S_TryFormats(testfn, extension, searchfirst);
if (fp != buildvfs_kfd_invalid)
return fp;
}
return -1;
return buildvfs_kfd_invalid;
}
int32_t S_OpenAudio(const char *fn, char searchfirst, uint8_t const ismusic)
buildvfs_kfd S_OpenAudio(const char *fn, char searchfirst, uint8_t const ismusic)
{
int32_t const origfp = kopen4loadfrommod(fn, searchfirst);
char const *const origparent = origfp != -1 ? kfileparent(origfp) : NULL;
buildvfs_kfd const origfp = kopen4loadfrommod(fn, searchfirst);
#ifndef USE_PHYSFS
char const * const origparent = origfp != buildvfs_kfd_invalid ? kfileparent(origfp) : NULL;
uint32_t const parentlength = origparent != NULL ? Bstrlen(origparent) : 0;
auto testfn = (char *)Xmalloc(Bstrlen(fn) + 12 + parentlength); // "music/" + overestimation of parent minus extension + ".flac" + '\0'
#else
auto testfn = (char *)Xmalloc(Bstrlen(fn) + 12);
#endif
// look in ./
// ex: ./grabbag.mid
Bstrcpy(testfn, fn);
int32_t fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic);
if (fp >= 0)
buildvfs_kfd fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic);
if (fp != buildvfs_kfd_invalid)
goto success;
#ifndef USE_PHYSFS
// look in ./music/<file's parent GRP name>/
// ex: ./music/duke3d/grabbag.mid
// ex: ./music/nwinter/grabbag.mid
@ -1143,7 +1156,7 @@ int32_t S_OpenAudio(const char *fn, char searchfirst, uint8_t const ismusic)
Bsprintf(testfn, "music/%.*s/%s", namelength, origparent, fn);
fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic);
if (fp >= 0)
if (fp != buildvfs_kfd_invalid)
goto success;
}
@ -1151,15 +1164,16 @@ int32_t S_OpenAudio(const char *fn, char searchfirst, uint8_t const ismusic)
// ex: ./music/grabbag.mid
Bsprintf(testfn, "music/%s", fn);
fp = S_TryExtensionReplacements(testfn, searchfirst, ismusic);
if (fp >= 0)
if (fp != buildvfs_kfd_invalid)
goto success;
#endif
Bfree(testfn);
return origfp;
fp = origfp;
success:
Bfree(testfn);
if (fp != origfp)
kclose(origfp);
kclose(origfp);
return fp;
}

View file

@ -10,6 +10,8 @@
#include "collections.h"
#include "grpscan.h"
#include "vfs.h"
#ifdef __cplusplus
extern "C" {
#endif
@ -126,7 +128,7 @@ extern void G_SetupGlobalPsky(void);
//////////
extern char g_modDir[BMAX_PATH];
extern int kopen4loadfrommod(const char *filename, char searchfirst);
extern buildvfs_kfd kopen4loadfrommod(const char *filename, char searchfirst);
extern void G_AddSearchPaths(void);
extern void G_CleanupSearchPaths(void);
@ -150,7 +152,7 @@ extern void G_LoadLookups(void);
#if defined HAVE_FLAC || defined HAVE_VORBIS
# define FORMAT_UPGRADE_ELIGIBLE
extern int32_t S_OpenAudio(const char *fn, char searchfirst, uint8_t ismusic);
extern buildvfs_kfd S_OpenAudio(const char *fn, char searchfirst, uint8_t ismusic);
#else
# define S_OpenAudio(fn, searchfirst, ismusic) kopen4loadfrommod(fn, searchfirst)
#endif

View file

@ -26,6 +26,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "renderlayer.h"
#include "cmdline.h"
#include "vfs.h"
#ifdef __ANDROID__
# include "android.h"
#endif
@ -585,10 +587,10 @@ int CONFIG_ReadSetup(void)
if (ud.config.scripthandle < 0)
{
if (SafeFileExists(g_setupFileName)) // JBF 20031211
if (buildvfs_exists(g_setupFileName)) // JBF 20031211
ud.config.scripthandle = SCRIPT_Load(g_setupFileName);
#if !defined(EDUKE32_TOUCH_DEVICES) && !defined(EDUKE32_STANDALONE)
else if (SafeFileExists(SETUPFILENAME))
else if (buildvfs_exists(SETUPFILENAME))
{
int const i = wm_ynbox("Import Configuration Settings",
"The configuration file \"%s\" was not found. "
@ -637,16 +639,12 @@ int CONFIG_ReadSetup(void)
if (g_noSetup == 0 && g_modDir[0] == '/')
{
struct Bstat st;
SCRIPT_GetString(ud.config.scripthandle, "Setup","ModDir",&g_modDir[0]);
if (Bstat(g_modDir, &st))
if (!buildvfs_isdir(g_modDir))
{
if ((st.st_mode & S_IFDIR) != S_IFDIR)
{
initprintf("Invalid mod dir in cfg!\n");
Bsprintf(g_modDir,"/");
}
initprintf("Invalid mod dir in cfg!\n");
Bsprintf(g_modDir,"/");
}
}
@ -697,40 +695,49 @@ int CONFIG_ReadSetup(void)
void CONFIG_WriteSettings(void) // save binds and aliases to <cfgname>_settings.cfg
{
char *ptr = Xstrdup(g_setupFileName);
char filename[BMAX_PATH];
if (!Bstrcmp(g_setupFileName, SETUPFILENAME))
Bsprintf(filename, "settings.cfg");
else
Bsprintf(filename, "%s_settings.cfg", strtok(ptr, "."));
Bsprintf(filename, "%s_settings.cfg", strtok(g_setupFileName, "."));
BFILE *fp = Bfopen(filename, "wt");
buildvfs_FILE fp = buildvfs_fopen_write(filename);
if (fp)
{
Bfprintf(fp,"// this file is automatically generated by %s\n", AppProperName);
Bfprintf(fp,"unbindall\n");
buildvfs_fputstr(fp, "// this file is automatically generated by ");
buildvfs_fputstrptr(fp, AppProperName);
buildvfs_fputstr(fp,"\nunbindall\n");
for (int i=0; i<MAXBOUNDKEYS+MAXMOUSEBUTTONS; i++)
{
if (CONTROL_KeyIsBound(i))
{
Bfprintf(fp, "bind \"%s\"%s \"%s\"\n", CONTROL_KeyBinds[i].key,
CONTROL_KeyBinds[i].repeat ? "" : " norepeat",
CONTROL_KeyBinds[i].cmdstr);
buildvfs_fputstr(fp, "bind \"");
buildvfs_fputstrptr(fp, CONTROL_KeyBinds[i].key);
if (CONTROL_KeyBinds[i].repeat)
buildvfs_fputstr(fp, "\" \"");
else
buildvfs_fputstr(fp, "\" norepeat \"");
buildvfs_fputstrptr(fp, CONTROL_KeyBinds[i].cmdstr);
buildvfs_fputstr(fp, "\"\n");
}
}
OSD_WriteAliases(fp);
if (g_crosshairSum != -1 && g_crosshairSum != DefaultCrosshairColors.r+(DefaultCrosshairColors.g<<8)+(DefaultCrosshairColors.b<<16))
Bfprintf(fp, "crosshaircolor %d %d %d\n", CrosshairColors.r, CrosshairColors.g, CrosshairColors.b);
{
buildvfs_fputstr(fp, "crosshaircolor ");
char buf[64];
snprintf(buf, sizeof(buf), "%d %d %d\n", CrosshairColors.r, CrosshairColors.g, CrosshairColors.b);
buildvfs_fputstrptr(fp, buf);
}
OSD_WriteCvars(fp);
Bfclose(fp);
Bfree(ptr);
buildvfs_fclose(fp);
OSD_Printf("Wrote %s\n", filename);
@ -738,8 +745,6 @@ void CONFIG_WriteSettings(void) // save binds and aliases to <cfgname>_settings.
}
OSD_Printf("Error writing %s: %s\n", filename, strerror(errno));
Bfree(ptr);
}
void CONFIG_WriteSetup(uint32_t flags)

View file

@ -27,10 +27,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "savegame.h"
#include "screens.h"
#include "vfs.h"
char g_firstDemoFile[BMAX_PATH];
FILE *g_demo_filePtr = (FILE *)NULL; // write
int32_t g_demo_recFilePtr = -1; // read
buildvfs_FILE g_demo_filePtr{}; // write
buildvfs_kfd g_demo_recFilePtr = buildvfs_kfd_invalid; // read
int32_t g_demo_cnt;
int32_t g_demo_goalCnt=0;
@ -95,7 +97,7 @@ static int32_t G_OpenDemoRead(int32_t g_whichDemo) // 0 = mine
}
g_demo_recFilePtr = kopen4loadfrommod(demofnptr, g_loadFromGroupOnly);
if (g_demo_recFilePtr == -1)
if (g_demo_recFilePtr == buildvfs_kfd_invalid)
return 0;
Bassert(g_whichDemo >= 1);
@ -103,7 +105,7 @@ static int32_t G_OpenDemoRead(int32_t g_whichDemo) // 0 = mine
if (i)
{
OSD_Printf(OSD_ERROR "There were errors opening demo %d (code: %d).\n", g_whichDemo, i);
kclose(g_demo_recFilePtr); g_demo_recFilePtr = -1;
kclose(g_demo_recFilePtr); g_demo_recFilePtr = buildvfs_kfd_invalid;
return 0;
}
@ -148,7 +150,7 @@ void G_OpenDemoWrite(void)
if (ud.recstat == 2)
{
kclose(g_demo_recFilePtr);
g_demo_recFilePtr = -1;
g_demo_recFilePtr = buildvfs_kfd_invalid;
}
if ((g_player[myconnectindex].ps->gm&MODE_GAME) && g_player[myconnectindex].ps->dead_flag)
@ -191,7 +193,7 @@ void G_OpenDemoWrite(void)
demonum++;
g_demo_filePtr = Bfopen(demofn, "rb");
g_demo_filePtr = buildvfs_fopen_read(demofn);
if (g_demo_filePtr == NULL)
break;
@ -199,7 +201,7 @@ void G_OpenDemoWrite(void)
}
while (1);
g_demo_filePtr = Bfopen(demofn,"wb");
g_demo_filePtr = buildvfs_fopen_write(demofn);
if (g_demo_filePtr == NULL)
return;
@ -262,16 +264,16 @@ static void Demo_WriteSync()
{
int16_t tmpreccnt;
fwrite("sYnC", 4, 1, g_demo_filePtr);
buildvfs_fwrite("sYnC", 4, 1, g_demo_filePtr);
tmpreccnt = (int16_t)ud.reccnt;
fwrite(&tmpreccnt, sizeof(int16_t), 1, g_demo_filePtr);
buildvfs_fwrite(&tmpreccnt, sizeof(int16_t), 1, g_demo_filePtr);
if (demorec_seeds)
fwrite(g_demo_seedbuf, 1, ud.reccnt, g_demo_filePtr);
buildvfs_fwrite(g_demo_seedbuf, 1, ud.reccnt, g_demo_filePtr);
if (demo_synccompress)
dfwrite_LZ4(recsync, sizeof(input_t), ud.reccnt, g_demo_filePtr);
else //if (demo_synccompress==0)
fwrite(recsync, sizeof(input_t), ud.reccnt, g_demo_filePtr);
buildvfs_fwrite(recsync, sizeof(input_t), ud.reccnt, g_demo_filePtr);
ud.reccnt = 0;
}
@ -308,13 +310,13 @@ void G_CloseDemoWrite(void)
if (ud.reccnt > 0)
Demo_WriteSync();
fwrite("EnD!", 4, 1, g_demo_filePtr);
buildvfs_fwrite("EnD!", 4, 1, g_demo_filePtr);
// lastly, we need to write the number of written recsyncs to the demo file
if (fseek(g_demo_filePtr, offsetof(savehead_t, reccnt), SEEK_SET))
if (buildvfs_fseek_abs(g_demo_filePtr, offsetof(savehead_t, reccnt)))
perror("G_CloseDemoWrite: final fseek");
else
fwrite(&g_demo_cnt, sizeof(g_demo_cnt), 1, g_demo_filePtr);
buildvfs_fwrite(&g_demo_cnt, sizeof(g_demo_cnt), 1, g_demo_filePtr);
ud.recstat = ud.m_recstat = 0;
MAYBE_FCLOSE_AND_NULL(g_demo_filePtr);
@ -709,7 +711,7 @@ nextdemo:
nextdemo_nomenu:
foundemo = 0;
ud.reccnt = 0;
kclose(g_demo_recFilePtr); g_demo_recFilePtr = -1;
kclose(g_demo_recFilePtr); g_demo_recFilePtr = buildvfs_kfd_invalid;
if (g_demo_goalCnt>0)
{
@ -971,7 +973,7 @@ nextdemo_nomenu:
#if KRANDDEBUG
krd_print("krandplay.log");
#endif
kclose(g_demo_recFilePtr); g_demo_recFilePtr = -1;
kclose(g_demo_recFilePtr); g_demo_recFilePtr = buildvfs_kfd_invalid;
}
return 0;
@ -979,7 +981,7 @@ nextdemo_nomenu:
}
ud.multimode = numplayers; // fixes 2 infinite loops after watching demo
kclose(g_demo_recFilePtr); g_demo_recFilePtr = -1;
kclose(g_demo_recFilePtr); g_demo_recFilePtr = buildvfs_kfd_invalid;
Demo_FinishProfile();

View file

@ -24,11 +24,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#define demo_h_
#include "compat.h"
#include "vfs.h"
#include "cache1d.h"
#define DEMOFN_FMT "edemo%03d.edm"
#define MAXDEMOS 1000
extern FILE *g_demo_filePtr;
extern buildvfs_FILE g_demo_filePtr;
extern char g_firstDemoFile[BMAX_PATH];
extern int32_t demoplay_diffs;
@ -42,7 +44,7 @@ extern int32_t demorec_synccompress_cvar;
extern int32_t g_demo_cnt;
extern int32_t g_demo_goalCnt;
extern int32_t g_demo_paused;
extern int32_t g_demo_recFilePtr;
extern buildvfs_kfd g_demo_recFilePtr;
extern int32_t g_demo_rewind;
extern int32_t g_demo_showStats;
extern int32_t g_demo_totalCnt;

View file

@ -29,7 +29,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "build.h"
#include "cache1d.h"
#include "compat.h"
#include "file_lib.h"
#include "fx_man.h"
#include "keyboard.h"
#include "pragmas.h"

View file

@ -49,6 +49,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# include "lunatic_game.h"
#endif
#include "vfs.h"
// Uncomment to prevent anything except mirrors from drawing. It is sensible to
// also uncomment ENGINE_CLEAR_SCREEN in build/src/engine_priv.h.
//#define DEBUG_MIRRORS_ONLY
@ -1152,7 +1154,7 @@ void G_DumpDebugInfo(void)
#if !defined LUNATIC
static char const s_WEAPON[] = "WEAPON";
int32_t i,j,x;
// FILE * fp=fopen("condebug.log","w");
// buildvfs_FILE fp = buildvfs_fopen_write("condebug.log");
VM_ScriptInfo(insptr, 64);
buildprint("\nCurrent gamevar values:\n");
@ -1216,7 +1218,7 @@ void G_DumpDebugInfo(void)
}
}
Gv_DumpValues();
// fclose(fp);
// buildvfs_fclose(fp);
#endif
saveboard("debug.map", &g_player[myconnectindex].ps->pos, fix16_to_int(g_player[myconnectindex].ps->q16ang),
g_player[myconnectindex].ps->cursectnum);
@ -4675,7 +4677,7 @@ void G_HandleLocalKeys(void)
KB_ClearKeyDown(sc_Return);
g_demo_cnt = g_demo_goalCnt = ud.reccnt = ud.pause_on = ud.recstat = ud.m_recstat = 0;
// XXX: probably redundant; this stuff needs an API anyway:
kclose(g_demo_recFilePtr); g_demo_recFilePtr = -1;
kclose(g_demo_recFilePtr); g_demo_recFilePtr = buildvfs_kfd_invalid;
myplayer.gm = MODE_GAME;
ready2send=1; // TODO: research this weird variable
screenpeek=myconnectindex;
@ -5902,11 +5904,11 @@ static void G_Startup(void)
Bcorrectfilename(boardfilename,0);
i = kopen4loadfrommod(boardfilename,0);
if (i!=-1)
buildvfs_kfd ii = kopen4loadfrommod(boardfilename, 0);
if (ii != buildvfs_kfd_invalid)
{
initprintf("Using level: \"%s\".\n",boardfilename);
kclose(i);
kclose(ii);
}
else
{
@ -5932,16 +5934,16 @@ static void G_Startup(void)
char *cwd;
if (g_modDir[0] != '/' && (cwd = getcwd(NULL, 0)))
if (g_modDir[0] != '/' && (cwd = buildvfs_getcwd(NULL, 0)))
{
Bchdir(g_modDir);
buildvfs_chdir(g_modDir);
if (artLoadFiles("tiles000.art", MAXCACHE1DSIZE) < 0)
{
Bchdir(cwd);
buildvfs_chdir(cwd);
if (artLoadFiles("tiles000.art", MAXCACHE1DSIZE) < 0)
G_GameExit("Failed loading art.");
}
Bchdir(cwd);
buildvfs_chdir(cwd);
#ifndef __ANDROID__ //This crashes on *some* Android devices. Small onetime memory leak. TODO fix above function
Bfree(cwd);
#endif
@ -6170,11 +6172,13 @@ int app_main(int argc, char const * const * argv)
backgroundidle = 0;
#ifndef USE_PHYSFS
#ifdef DEBUGGINGAIDS
extern int32_t (*check_filename_casing_fn)(void);
check_filename_casing_fn = check_filename_casing;
#endif
#endif
#endif
#ifdef EDUKE32_STANDALONE
G_DeleteOldSaves();
@ -6331,9 +6335,9 @@ int app_main(int argc, char const * const * argv)
g_Shareware = 1;
else
{
int const kFile = kopen4load("DUKESW.BIN",1); // JBF 20030810
buildvfs_kfd const kFile = kopen4load("DUKESW.BIN",1); // JBF 20030810
if (kFile != -1)
if (kFile != buildvfs_kfd_invalid)
{
g_Shareware = 1;
kclose(kFile);

View file

@ -33,6 +33,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "osd.h"
#include "savegame.h"
#include "vfs.h"
#define LINE_NUMBER (g_lineNumber << 12)
int32_t g_scriptVersion = 13; // 13 = 1.3D-style CON files, 14 = 1.4/1.5 style CON files
@ -1886,9 +1888,9 @@ static int C_CountCaseStatements()
static void C_Include(const char *confile)
{
int32_t const fp = kopen4loadfrommod(confile,g_loadFromGroupOnly);
buildvfs_kfd fp = kopen4loadfrommod(confile, g_loadFromGroupOnly);
if (EDUKE32_PREDICT_FALSE(fp < 0))
if (EDUKE32_PREDICT_FALSE(fp == buildvfs_kfd_invalid))
{
g_errorCnt++;
initprintf("%s:%d: error: could not find file `%s'.\n",g_scriptFileName,g_lineNumber,confile);
@ -1941,8 +1943,8 @@ static void C_Include(const char *confile)
#ifdef _WIN32
static void check_filename_case(const char *fn)
{
int32_t fp;
if ((fp = kopen4loadfrommod(fn, g_loadFromGroupOnly)) >= 0)
buildvfs_kfd fp;
if ((fp = kopen4loadfrommod(fn, g_loadFromGroupOnly)) != buildvfs_kfd_invalid)
kclose(fp);
}
#else
@ -2378,28 +2380,16 @@ LUNATIC_EXTERN void C_SetCfgName(const char *cfgname)
#ifdef POLYMER
int const renderMode = glrendmode;
#endif
struct Bstat st;
if (Bstat(g_modDir, &st) < 0)
if (!buildvfs_isdir(g_modDir))
{
if (errno == ENOENT) // path doesn't exist
if (buildvfs_mkdir(g_modDir, S_IRWXU) != 0)
{
if (Bmkdir(g_modDir, S_IRWXU) < 0)
{
OSD_Printf("Failed to create directory \"%s\"!\n", g_modDir);
return;
}
}
else
{
// another type of failure
OSD_Printf("Failed to create directory \"%s\"!\n", g_modDir);
return;
}
}
else if ((st.st_mode & S_IFDIR) != S_IFDIR)
{
// directory isn't a directory
return;
else
OSD_Printf("Created configuration file directory %s\n", g_modDir);
}
// XXX: Back up 'cfgname' as it may be the global 'tempbuf'.
@ -6212,9 +6202,9 @@ void C_Compile(const char *fileName)
Gv_Init();
C_InitProjectiles();
int const kFile = kopen4loadfrommod(fileName, g_loadFromGroupOnly);
buildvfs_kfd kFile = kopen4loadfrommod(fileName, g_loadFromGroupOnly);
if (kFile == -1) // JBF: was 0
if (kFile == buildvfs_kfd_invalid) // JBF: was 0
{
if (g_loadFromGroupOnly == 1 || numgroupfiles == 0)
{

View file

@ -36,6 +36,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# include "lunatic_game.h"
#endif
#include "vfs.h"
#if KRANDDEBUG
# define GAMEEXEC_INLINE
# define GAMEEXEC_STATIC
@ -5755,9 +5757,9 @@ badindex:
dispatch(tw);
}
int kFile = kopen4loadfrommod(apStrings[quoteFilename], 0);
buildvfs_kfd kFile = kopen4loadfrommod(apStrings[quoteFilename], 0);
if (kFile < 0)
if (kFile == buildvfs_kfd_invalid)
dispatch(tw);
size_t const filelength = kfilelength(kFile);
@ -5836,7 +5838,7 @@ badindex:
dispatch(tw);
}
FILE *const fil = Bfopen(temp, "wb");
buildvfs_FILE const fil = buildvfs_fopen_write(temp);
if (EDUKE32_PREDICT_FALSE(fil == NULL))
{
@ -5856,15 +5858,15 @@ badindex:
for (unative_t k = 0; k < numElements; ++k)
pArray[k] = Gv_GetArrayValue(arrayNum, k);
Bfwrite(pArray, 1, numDiskBytes, fil);
buildvfs_fwrite(pArray, 1, numDiskBytes, fil);
Bfree(pArray);
break;
}
#endif
default: Bfwrite(aGameArrays[arrayNum].pValues, 1, Gv_GetArrayAllocSize(arrayNum), fil); break;
default: buildvfs_fwrite(aGameArrays[arrayNum].pValues, 1, Gv_GetArrayAllocSize(arrayNum), fil); break;
}
Bfclose(fil);
buildvfs_fclose(fil);
dispatch(tw);
}

View file

@ -24,6 +24,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "menus.h"
#include "savegame.h"
#include "vfs.h"
#define gamevars_c_
#ifdef LUNATIC
@ -107,7 +109,7 @@ void Gv_Clear(void)
hash_free(i);
}
int Gv_ReadSave(int32_t kFile)
int Gv_ReadSave(buildvfs_kfd kFile)
{
char tbuf[12];
@ -226,10 +228,10 @@ corrupt:
return -7;
}
void Gv_WriteSave(FILE *fil)
void Gv_WriteSave(buildvfs_FILE fil)
{
// AddLog("Saving Game Vars to File");
fwrite("BEG: EDuke32", 12, 1, fil);
buildvfs_fwrite("BEG: EDuke32", 12, 1, fil);
dfwrite_LZ4(&g_gameVarCount,sizeof(g_gameVarCount),1,fil);
@ -291,7 +293,7 @@ void Gv_WriteSave(FILE *fil)
}
}
fwrite("EOF: EDuke32", 12, 1, fil);
buildvfs_fwrite("EOF: EDuke32", 12, 1, fil);
}
void Gv_DumpValues(void)

View file

@ -26,6 +26,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "fix16.hpp"
#include "gamedef.h"
#include "vfs.h"
#define MAXGAMEVARS 2048 // must be a power of two
#define MAXVARLABEL 26
@ -150,8 +152,8 @@ void Gv_DumpValues(void);
void Gv_InitWeaponPointers(void);
void Gv_RefreshPointers(void);
void Gv_ResetVars(void);
int Gv_ReadSave(int32_t kFile);
void Gv_WriteSave(FILE *fil);
int Gv_ReadSave(buildvfs_kfd kFile);
void Gv_WriteSave(buildvfs_FILE fil);
void Gv_Clear(void);
#else
extern int32_t g_noResetVars;

View file

@ -29,6 +29,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "grpscan.h"
#include "scriptfile.h"
#include "vfs.h"
#ifndef EDUKE32_STANDALONE
static void process_vaca13(int32_t crcval);
static void process_vacapp15(int32_t crcval);
@ -232,7 +234,12 @@ static void LoadGameList(void)
}
#endif
CACHE1D_FIND_REC * const srch = klistpath("/", "*.grpinfo", CACHE1D_FIND_FILE);
#ifdef USE_PHYSFS
auto const base = PHYSFS_getBaseDir();
#else
static char const base[] = "/";
#endif
CACHE1D_FIND_REC * const srch = klistpath(base, "*.grpinfo", CACHE1D_FIND_FILE);
for (CACHE1D_FIND_REC *sidx = srch; sidx; sidx = sidx->next)
LoadList(sidx->name);
@ -344,6 +351,7 @@ grpfile_t * FindGroup(int32_t crcval)
return NULL;
}
#ifndef USE_PHYSFS
static grpinfo_t const * FindGrpInfo(int32_t crcval, int32_t size)
{
grpinfo_t *grpinfo;
@ -447,9 +455,11 @@ static void ProcessGroups(CACHE1D_FIND_REC *srch)
Bfree(buf);
}
#endif
int32_t ScanGroups(void)
{
#ifndef USE_PHYSFS
struct grpcache *fg, *fgg;
initprintf("Searching for game data...\n");
@ -491,8 +501,7 @@ int32_t ScanGroups(void)
if (usedgrpcache)
{
int32_t i = 0;
FILE *fp;
fp = fopen(GRPCACHEFILE, "wt");
buildvfs_FILE fp = buildvfs_fopen_write(GRPCACHEFILE);
if (fp)
{
for (fg = usedgrpcache; fg; fg=fgg)
@ -502,7 +511,7 @@ int32_t ScanGroups(void)
Bfree(fg);
i++;
}
fclose(fp);
buildvfs_fclose(fp);
}
// initprintf("Found %d recognized GRP %s.\n",i,i>1?"files":"file");
@ -510,6 +519,7 @@ int32_t ScanGroups(void)
}
initprintf("Found no recognized game data!\n");
#endif
return 0;
}

View file

@ -19,6 +19,8 @@
// XXX: This breaks editors for games other than Duke. The OSD needs a way to specify colors in abstract instead of concatenating palswap escape sequences.
#include "common_game.h"
#include "vfs.h"
//////////////////// Key stuff ////////////////////
#define eitherALT (keystatus[KEYSC_LALT] || keystatus[KEYSC_RALT])
@ -140,7 +142,7 @@ void taglab_init()
int32_t taglab_load(const char *filename, int32_t flags)
{
int32_t fil, len, i;
int32_t len, i;
char buf[BMAX_PATH], *dot, *filebuf;
taglab_init();
@ -160,7 +162,8 @@ int32_t taglab_load(const char *filename, int32_t flags)
Bmemcpy(dot, ".maptags", 9);
//
if ((fil = kopen4load(buf,flags)) == -1)
buildvfs_kfd fil;
if ((fil = kopen4load(buf,flags)) == buildvfs_kfd_invalid)
return -1;
len = kfilelength(fil);
@ -223,7 +226,7 @@ nextline:
int32_t taglab_save(const char *mapname)
{
int32_t fil, len, i;
int32_t len, i;
char buf[BMAX_PATH], *dot;
const char *label;
@ -243,7 +246,8 @@ int32_t taglab_save(const char *mapname)
Bmemcpy(dot, ".maptags", 9);
//
if ((fil = Bopen(buf,BO_BINARY|BO_TRUNC|BO_CREAT|BO_WRONLY,BS_IREAD|BS_IWRITE)) == -1)
buildvfs_fd fil;
if ((fil = buildvfs_open_write(buf)) == buildvfs_fd_invalid)
{
initprintf("Couldn't open \"%s\" for writing: %s\n", buf, strerror(errno));
return -1;
@ -256,11 +260,11 @@ int32_t taglab_save(const char *mapname)
continue;
len = Bsprintf(buf, "%d %s" OURNEWL, i, label);
if (Bwrite(fil, buf, len)!=len)
if (buildvfs_write(fil, buf, len)!=len)
break;
}
Bclose(fil);
buildvfs_close(fil);
return (i!=32768);
}

View file

@ -30,6 +30,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//#include "osd.h"
#include "keys.h"
#include "vfs.h"
char g_szScriptFileName[BMAX_PATH] = "(none)"; // file we're currently compiling
static char g_szCurrentBlockName[BMAX_PATH] = "(none)";
static char g_szLastBlockName[BMAX_PATH] = "NULL";
@ -1736,10 +1738,10 @@ static int32_t C_ParseCommand(void)
const char *origtptr;
char *mptr;
char parentScriptFileName[255];
int32_t fp;
buildvfs_kfd fp;
fp = kopen4load(tempbuf, 0 /*g_loadFromGroupOnly*/);
if (fp < 0)
if (fp == buildvfs_kfd_invalid)
{
g_numCompilerErrors++;
initprintf("%s:%d: error: could not find file `%s'.\n",g_szScriptFileName,g_lineNumber,tempbuf);
@ -3664,7 +3666,8 @@ void C_Compile(const char *filenameortext, int32_t isfilename)
char *mptr = NULL;
static char firstime=1;
int32_t i,j;
int32_t fs=0,fp=0;
int32_t fs=0;
buildvfs_kfd fp = buildvfs_kfd_invalid;
int32_t startcompiletime;
instype *oscriptPtr;
int32_t ostateCount = g_stateCount;
@ -3707,7 +3710,7 @@ void C_Compile(const char *filenameortext, int32_t isfilename)
Bmemcpy(mptr, filenameortext, fs+1);
fp = kopen4load(mptr, 0 /*g_loadFromGroupOnly*/);
if (fp == -1) // JBF: was 0
if (fp == buildvfs_kfd_invalid) // JBF: was 0
{
if (fs < 4 || Bmemcmp(&mptr[fs-4], ".m32", 4) != 0)
{
@ -3715,7 +3718,7 @@ void C_Compile(const char *filenameortext, int32_t isfilename)
fp = kopen4load(mptr, 0 /*g_loadFromGroupOnly*/);
}
if (fp == -1)
if (fp == buildvfs_kfd_invalid)
{
initprintf("M32 file `%s' not found.\n", mptr);
Bfree(mptr);

View file

@ -39,6 +39,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "lz4.h"
#include "crc32.h"
#include "vfs.h"
// Data needed even if netcode is disabled
ENetHost *g_netServer = NULL;
ENetHost *g_netClient = NULL;
@ -2000,8 +2002,8 @@ static void Net_ReceiveUserMapName(uint8_t *pbuf, int32_t packbufleng)
Bcorrectfilename(boardfilename, 0);
if (boardfilename[0] != 0)
{
int32_t i;
if ((i = kopen4loadfrommod(boardfilename, 0)) < 0)
buildvfs_kfd i;
if ((i = kopen4loadfrommod(boardfilename, 0)) == buildvfs_kfd_invalid)
{
Bmemset(boardfilename, 0, sizeof(boardfilename));
Net_SendUserMapName();

View file

@ -38,6 +38,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "in_android.h"
#endif
#include "vfs.h"
struct osdcmd_cheatsinfo osdcmd_cheatsinfo_stat;
float r_ambientlight = 1.0, r_ambientlightrecip = 1.0;
@ -162,7 +164,6 @@ static int osdcmd_changelevel(osdcmdptr_t parm)
static int osdcmd_map(osdcmdptr_t parm)
{
int32_t i;
char filename[BMAX_PATH];
const int32_t wildcardp = parm->numparms==1 &&
@ -210,12 +211,13 @@ static int osdcmd_map(osdcmdptr_t parm)
maybe_append_ext(filename, sizeof(filename), parm->parms[0], ".map");
if ((i = kopen4loadfrommod(filename,0)) < 0)
buildvfs_kfd ii;
if ((ii = kopen4loadfrommod(filename,0)) == buildvfs_kfd_invalid)
{
OSD_Printf(OSD_ERROR "map: file \"%s\" not found.\n", filename);
return OSDCMD_OK;
}
kclose(i);
kclose(ii);
boardfilename[0] = '/';
boardfilename[1] = 0;

View file

@ -27,6 +27,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "menus.h"
#include "savegame.h"
#include "vfs.h"
#ifdef LUNATIC
# include "lunatic_game.h"
#endif
@ -1789,11 +1791,11 @@ void G_SetupFilenameBasedMusic(char *nameBuf, const char *fileName, int levelNum
for (auto & ext : exts)
{
int32_t kFile;
buildvfs_kfd kFile;
Bmemcpy(p+1, ext, Bstrlen(ext) + 1);
if ((kFile = kopen4loadfrommod(nameBuf, 0)) != -1)
if ((kFile = kopen4loadfrommod(nameBuf, 0)) != buildvfs_kfd_invalid)
{
kclose(kFile);
realloc_copy(&g_mapInfo[levelNum].musicfn, nameBuf);

View file

@ -22,6 +22,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "duke3d.h"
#include "vfs.h"
static int32_t rts_numlumps;
static void **rts_lumpcache;
@ -41,15 +43,15 @@ char rts_lumplockbyte[11];
static int32_t RTS_AddFile(const char *filename)
{
wadinfo_t header;
int32_t i, handle, length, startlump;
int32_t i, length, startlump;
filelump_t *fileinfo, *fileinfoo;
// read the entire file in
// FIXME: shared opens
handle = kopen4loadfrommod(filename, 0);
buildvfs_kfd handle = kopen4loadfrommod(filename, 0);
if (handle < 0)
if (handle == buildvfs_kfd_invalid)
return -1;
else
initprintf("RTS file \"%s\" loaded\n", filename);

View file

@ -30,6 +30,8 @@ static int32_t g_savedOK;
const char *g_failedVarname;
#endif
#include "vfs.h"
static OutputFileCounter savecounter;
// For storing pointers in files.
@ -152,8 +154,8 @@ static void ReadSaveGameHeaders_CACHE1D(CACHE1D_FIND_REC *f)
for (; f != nullptr; f = f->next)
{
char const * fn = f->name;
int32_t fil = kopen4loadfrommod(fn, 0);
if (fil == -1)
buildvfs_kfd fil = kopen4loadfrommod(fn, 0);
if (fil == buildvfs_kfd_invalid)
continue;
menusave_t & msv = g_internalsaves[g_numinternalsaves];
@ -283,8 +285,8 @@ void ReadSaveGameHeaders(void)
int32_t G_LoadSaveHeaderNew(char const *fn, savehead_t *saveh)
{
int32_t fil = kopen4loadfrommod(fn, 0);
if (fil == -1)
buildvfs_kfd fil = kopen4loadfrommod(fn, 0);
if (fil == buildvfs_kfd_invalid)
return -1;
int32_t i = sv_loadheader(fil, 0, saveh);
@ -331,9 +333,9 @@ static int different_user_map;
// XXX: keyboard input 'blocked' after load fail? (at least ESC?)
int32_t G_LoadPlayer(savebrief_t & sv)
{
int const fil = kopen4loadfrommod(sv.path, 0);
buildvfs_kfd const fil = kopen4loadfrommod(sv.path, 0);
if (fil == -1)
if (fil == buildvfs_kfd_invalid)
return -1;
ready2send = 0;
@ -445,37 +447,6 @@ static void G_RestoreTimers(void)
//////////
#ifdef __ANDROID__
static void G_SavePalette(void)
{
int32_t pfil;
if ((pfil = kopen4load("palette.dat", 0)) != -1)
{
int len = kfilelength(pfil);
FILE *fil = fopen("palette.dat", "rb");
if (!fil)
{
fil = fopen("palette.dat", "wb");
if (fil)
{
char *buf = (char *) Xaligned_alloc(16, len);
kread(pfil, buf, len);
fwrite(buf, len, 1, fil);
fclose(fil);
Bfree(buf);
}
}
else fclose(fil);
}
}
#endif
void G_DeleteSave(savebrief_t const & sv)
{
if (!sv.isValid())
@ -489,7 +460,7 @@ void G_DeleteSave(savebrief_t const & sv)
return;
}
unlink(temp);
buildvfs_unlink(temp);
}
void G_DeleteOldSaves(void)
@ -533,7 +504,7 @@ int32_t G_SavePlayer(savebrief_t & sv, bool isAutoSave)
char temp[BMAX_PATH];
errno = 0;
FILE *fil;
buildvfs_FILE fil;
if (sv.isValid())
{
@ -542,7 +513,7 @@ int32_t G_SavePlayer(savebrief_t & sv, bool isAutoSave)
OSD_Printf("G_SavePlayer: file name \"%s\" too long\n", sv.path);
goto saveproblem;
}
fil = fopen(temp, "wb");
fil = buildvfs_fopen_write(temp);
}
else
{
@ -580,7 +551,7 @@ int32_t G_SavePlayer(savebrief_t & sv, bool isAutoSave)
// SAVE!
sv_saveandmakesnapshot(fil, sv.name, 0, 0, 0, 0, isAutoSave);
fclose(fil);
buildvfs_fclose(fil);
if (!g_netServer && ud.multimode < 2)
{
@ -706,7 +677,7 @@ static inline void ds_get(const dataspec_t *spec, void **ptr, int32_t *cnt)
}
// write state to file and/or to dump
static uint8_t *writespecdata(const dataspec_t *spec, FILE *fil, uint8_t *dump)
static uint8_t *writespecdata(const dataspec_t *spec, buildvfs_FILE fil, uint8_t *dump)
{
for (; spec->flags != DS_END; spec++)
{
@ -721,7 +692,7 @@ static uint8_t *writespecdata(const dataspec_t *spec, FILE *fil, uint8_t *dump)
continue;
else if (spec->flags & DS_STRING)
{
fwrite(spec->ptr, Bstrlen((const char *)spec->ptr), 1, fil); // not null-terminated!
buildvfs_fwrite(spec->ptr, Bstrlen((const char *)spec->ptr), 1, fil); // not null-terminated!
continue;
}
@ -742,7 +713,7 @@ static uint8_t *writespecdata(const dataspec_t *spec, FILE *fil, uint8_t *dump)
if (fil)
{
if ((spec->flags & DS_CMP) || ((spec->flags & DS_CNTMASK) == 0 && spec->size * cnt <= savegame_comprthres))
fwrite(ptr, spec->size, cnt, fil);
buildvfs_fwrite(ptr, spec->size, cnt, fil);
else
dfwrite_LZ4((void *)ptr, spec->size, cnt, fil);
}
@ -760,14 +731,14 @@ static uint8_t *writespecdata(const dataspec_t *spec, FILE *fil, uint8_t *dump)
// (fil>=0 && havedump): first restore dump from file, then restore state from dump
// (fil<0 && havedump): only restore state from dump
// (fil>=0 && !havedump): only restore state from file
static int32_t readspecdata(const dataspec_t *spec, int32_t fil, uint8_t **dumpvar)
static int32_t readspecdata(const dataspec_t *spec, buildvfs_kfd fil, uint8_t **dumpvar)
{
uint8_t * dump = dumpvar ? *dumpvar : NULL;
auto const sptr = spec;
for (; spec->flags != DS_END; spec++)
{
if (fil < 0 && spec->flags & (DS_NOCHK|DS_STRING|DS_CMP)) // we're updating
if (fil == buildvfs_kfd_invalid && spec->flags & (DS_NOCHK|DS_STRING|DS_CMP)) // we're updating
continue;
if (spec->flags & (DS_LOADFN|DS_SAVEFN))
@ -811,7 +782,7 @@ static int32_t readspecdata(const dataspec_t *spec, int32_t fil, uint8_t **dumpv
if (!ptr || !cnt)
continue;
if (fil >= 0)
if (fil != buildvfs_kfd_invalid)
{
auto const mem = (dump && (spec->flags & DS_NOCHK) == 0) ? dump : (uint8_t *)ptr;
bool const comp = !((spec->flags & DS_CNTMASK) == 0 && spec->size * cnt <= savegame_comprthres);
@ -1320,8 +1291,8 @@ static const dataspec_t svgm_anmisc[] =
#if !defined LUNATIC
static dataspec_gv_t *svgm_vars=NULL;
#endif
static uint8_t *dosaveplayer2(FILE *fil, uint8_t *mem);
static int32_t doloadplayer2(int32_t fil, uint8_t **memptr);
static uint8_t *dosaveplayer2(buildvfs_FILE fil, uint8_t *mem);
static int32_t doloadplayer2(buildvfs_kfd fil, uint8_t **memptr);
static void postloadplayer(int32_t savegamep);
// SVGM snapshot system
@ -1424,7 +1395,7 @@ static void SV_AllocSnap(int32_t allocinit)
}
// make snapshot only if spot < 0 (demo)
int32_t sv_saveandmakesnapshot(FILE *fil, char const *name, int8_t spot, int8_t recdiffsp, int8_t diffcompress, int8_t synccompress, bool isAutoSave)
int32_t sv_saveandmakesnapshot(buildvfs_FILE fil, char const *name, int8_t spot, int8_t recdiffsp, int8_t diffcompress, int8_t synccompress, bool isAutoSave)
{
savehead_t h;
@ -1498,11 +1469,11 @@ int32_t sv_saveandmakesnapshot(FILE *fil, char const *name, int8_t spot, int8_t
// write header
fwrite(&h, sizeof(savehead_t), 1, fil);
buildvfs_fwrite(&h, sizeof(savehead_t), 1, fil);
// for savegames, the file offset after the screenshot goes here;
// for demos, we keep it 0 to signify that we didn't save one
fwrite("\0\0\0\0", 4, 1, fil);
buildvfs_fwrite("\0\0\0\0", 4, 1, fil);
if (spot >= 0 && waloff[TILE_SAVESHOT])
{
int32_t ofs;
@ -1511,10 +1482,10 @@ int32_t sv_saveandmakesnapshot(FILE *fil, char const *name, int8_t spot, int8_t
dfwrite_LZ4((char *)waloff[TILE_SAVESHOT], 320, 200, fil);
// write the current file offset right after the header
ofs = ftell(fil);
fseek(fil, sizeof(savehead_t), SEEK_SET);
fwrite(&ofs, 4, 1, fil);
fseek(fil, ofs, SEEK_SET);
ofs = buildvfs_ftell(fil);
buildvfs_fseek_abs(fil, sizeof(savehead_t));
buildvfs_fwrite(&ofs, 4, 1, fil);
buildvfs_fseek_abs(fil, ofs);
}
#ifdef DEBUGGINGAIDS
@ -1553,7 +1524,7 @@ int32_t sv_saveandmakesnapshot(FILE *fil, char const *name, int8_t spot, int8_t
}
// if file is not an EDuke32 savegame/demo, h->headerstr will be all zeros
int32_t sv_loadheader(int32_t fil, int32_t spot, savehead_t *h)
int32_t sv_loadheader(buildvfs_kfd fil, int32_t spot, savehead_t *h)
{
int32_t havedemo = (spot < 0);
@ -1613,7 +1584,7 @@ int32_t sv_loadheader(int32_t fil, int32_t spot, savehead_t *h)
return 0;
}
int32_t sv_loadsnapshot(int32_t fil, int32_t spot, savehead_t *h)
int32_t sv_loadsnapshot(buildvfs_kfd fil, int32_t spot, savehead_t *h)
{
uint8_t *p;
int32_t i;
@ -1697,7 +1668,7 @@ int32_t sv_loadsnapshot(int32_t fil, int32_t spot, savehead_t *h)
}
uint32_t sv_writediff(FILE *fil)
uint32_t sv_writediff(buildvfs_FILE fil)
{
uint8_t *p = svsnapshot;
uint8_t *d = svdiff;
@ -1715,18 +1686,18 @@ uint32_t sv_writediff(FILE *fil)
uint32_t const diffsiz = d - svdiff;
fwrite("dIfF",4,1,fil);
fwrite(&diffsiz, sizeof(diffsiz), 1, fil);
buildvfs_fwrite("dIfF",4,1,fil);
buildvfs_fwrite(&diffsiz, sizeof(diffsiz), 1, fil);
if (savegame_diffcompress)
dfwrite_LZ4(svdiff, 1, diffsiz, fil); // cnt and sz swapped
else
fwrite(svdiff, 1, diffsiz, fil);
buildvfs_fwrite(svdiff, 1, diffsiz, fil);
return diffsiz;
}
int32_t sv_readdiff(int32_t fil)
int32_t sv_readdiff(buildvfs_kfd fil)
{
int32_t diffsiz;
@ -1993,7 +1964,7 @@ static void sv_restload()
LUNATIC_CB const char *(*El_SerializeGamevars)(int32_t *slenptr, int32_t levelnum);
#endif
static uint8_t *dosaveplayer2(FILE *fil, uint8_t *mem)
static uint8_t *dosaveplayer2(buildvfs_FILE fil, uint8_t *mem)
{
#ifdef DEBUGGINGAIDS
uint8_t *tmem = mem;
@ -2019,9 +1990,9 @@ static uint8_t *dosaveplayer2(FILE *fil, uint8_t *mem)
return mem;
}
fwrite("\0\1LunaGVAR\3\4", 12, 1, fil);
buildvfs_fwrite("\0\1LunaGVAR\3\4", 12, 1, fil);
slen_ext = B_LITTLE32(slen);
fwrite(&slen_ext, sizeof(slen_ext), 1, fil);
buildvfs_fwrite(&slen_ext, sizeof(slen_ext), 1, fil);
dfwrite_LZ4(svcode, 1, slen, fil); // cnt and sz swapped
g_savedOK = 1;
@ -2044,7 +2015,7 @@ static uint8_t *dosaveplayer2(FILE *fil, uint8_t *mem)
#ifdef LUNATIC
char *g_elSavecode = NULL;
static int32_t El_ReadSaveCode(int32_t fil)
static int32_t El_ReadSaveCode(buildvfs_kfd fil)
{
// Read Lua code to restore gamevar values from the savegame.
// It will be run from Lua with its state creation later on.
@ -2103,7 +2074,7 @@ void El_FreeSaveCode(void)
}
#endif
static int32_t doloadplayer2(int32_t fil, uint8_t **memptr)
static int32_t doloadplayer2(buildvfs_kfd fil, uint8_t **memptr)
{
uint8_t *mem = memptr ? *memptr : NULL;
#ifdef DEBUGGINGAIDS
@ -2157,13 +2128,13 @@ int32_t sv_updatestate(int32_t frominit)
if (frominit)
Bmemcpy(svsnapshot, svinitsnap, svsnapsiz);
if (readspecdata(svgm_udnetw, -1, &p)) return -2;
if (readspecdata(svgm_secwsp, -1, &p)) return -4;
if (readspecdata(svgm_script, -1, &p)) return -5;
if (readspecdata(svgm_anmisc, -1, &p)) return -6;
if (readspecdata(svgm_udnetw, buildvfs_kfd_invalid, &p)) return -2;
if (readspecdata(svgm_secwsp, buildvfs_kfd_invalid, &p)) return -4;
if (readspecdata(svgm_script, buildvfs_kfd_invalid, &p)) return -5;
if (readspecdata(svgm_anmisc, buildvfs_kfd_invalid, &p)) return -6;
#if !defined LUNATIC
if (readspecdata((const dataspec_t *)svgm_vars, -1, &p)) return -8;
if (readspecdata((const dataspec_t *)svgm_vars, buildvfs_kfd_invalid, &p)) return -8;
#endif
if (p != pbeg+svsnapsiz)

View file

@ -25,6 +25,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "game.h"
#include "vfs.h"
#ifdef __cplusplus
extern "C" {
#endif
@ -117,11 +119,11 @@ extern menusave_t * g_menusaves;
extern uint16_t g_nummenusaves;
int32_t sv_updatestate(int32_t frominit);
int32_t sv_readdiff(int32_t fil);
uint32_t sv_writediff(FILE *fil);
int32_t sv_loadheader(int32_t fil, int32_t spot, savehead_t *h);
int32_t sv_loadsnapshot(int32_t fil, int32_t spot, savehead_t *h);
int32_t sv_saveandmakesnapshot(FILE *fil, char const *name, int8_t spot, int8_t recdiffsp, int8_t diffcompress, int8_t synccompress, bool isAutoSave = false);
int32_t sv_readdiff(buildvfs_kfd fil);
uint32_t sv_writediff(buildvfs_FILE fil);
int32_t sv_loadheader(buildvfs_kfd fil, int32_t spot, savehead_t *h);
int32_t sv_loadsnapshot(buildvfs_kfd fil, int32_t spot, savehead_t *h);
int32_t sv_saveandmakesnapshot(buildvfs_FILE fil, char const *name, int8_t spot, int8_t recdiffsp, int8_t diffcompress, int8_t synccompress, bool isAutoSave = false);
void sv_freemem();
void G_DeleteSave(savebrief_t const & sv);
void G_DeleteOldSaves(void);

View file

@ -1533,15 +1533,15 @@ void gameDisplay3DRScreen()
{
if (!I_CheckAllInput() && g_noLogoAnim == 0)
{
int32_t i;
buildvfs_kfd i;
Net_GetPackets();
i = kopen4loadfrommod("3dr.ivf", 0);
if (i == -1)
if (i == buildvfs_kfd_invalid)
i = kopen4loadfrommod("3dr.anm", 0);
if (i != -1)
if (i != buildvfs_kfd_invalid)
{
kclose(i);
Anim_Play("3dr.anm");

View file

@ -38,6 +38,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "sdlayer.h"
#include "music.h"
#include "vfs.h"
#if !defined _WIN32 && !defined(GEKKO)
//# define FORK_EXEC_MIDI 1
#endif
@ -216,12 +218,12 @@ fallback:
{
static const char *s[] = { "/etc/timidity.cfg", "/etc/timidity/timidity.cfg", "/etc/timidity/freepats.cfg" };
FILE *fp;
buildvfs_FILE fp;
int32_t i;
for (i = ARRAY_SIZE(s)-1; i>=0; i--)
{
fp = Bfopen(s[i], "r");
fp = buildvfs_fopen_read(s[i]);
if (fp == NULL)
{
if (i == 0)
@ -235,7 +237,7 @@ fallback:
}
else break;
}
Bfclose(fp);
buildvfs_fclose(fp);
}
music_initialized = 1;
@ -412,7 +414,7 @@ int32_t MUSIC_PlaySong(char *song, int32_t songsize, int32_t loopflag)
{
if (external_midi)
{
FILE *fp;
buildvfs_FILE fp;
#if defined FORK_EXEC_MIDI
static int32_t sigchld_handler_set = 0;
@ -431,11 +433,11 @@ int32_t MUSIC_PlaySong(char *song, int32_t songsize, int32_t loopflag)
}
#endif
fp = Bfopen(external_midi_tempfn, "wb");
fp = buildvfs_fopen_write(external_midi_tempfn);
if (fp)
{
fwrite(song, 1, songsize, fp);
Bfclose(fp);
buildvfs_fwrite(song, 1, songsize, fp);
buildvfs_fclose(fp);
#if defined FORK_EXEC_MIDI
external_midi_restart = loopflag;

View file

@ -26,6 +26,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "renderlayer.h" // for win_gethwnd()
#include <atomic>
#include "vfs.h"
#define DQSIZE 256
int32_t g_numEnvSoundsPlaying, g_highestSoundIdx = 0;
@ -197,8 +199,8 @@ static int S_PlayMusic(const char *fn)
if (fn == NULL)
return 1;
int32_t fp = S_OpenAudio(fn, 0, 1);
if (EDUKE32_PREDICT_FALSE(fp < 0))
buildvfs_kfd fp = S_OpenAudio(fn, 0, 1);
if (EDUKE32_PREDICT_FALSE(fp == buildvfs_kfd_invalid))
{
OSD_Printf(OSD_ERROR "S_PlayMusic(): error: can't open \"%s\" for playback!\n",fn);
return 2;
@ -437,9 +439,9 @@ int32_t S_LoadSound(int num)
auto &snd = g_sounds[num];
int32_t fp = S_OpenAudio(snd.filename, g_loadFromGroupOnly, 0);
buildvfs_kfd fp = S_OpenAudio(snd.filename, g_loadFromGroupOnly, 0);
if (EDUKE32_PREDICT_FALSE(fp == -1))
if (EDUKE32_PREDICT_FALSE(fp == buildvfs_kfd_invalid))
{
OSD_Printf(OSDTEXT_RED "Sound %s(#%d) not found!\n", snd.filename, num);
return 0;

View file

@ -43,6 +43,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "common.h"
#include "common_game.h"
#include "vfs.h"
#define LOUDESTVOLUME 150
#define MUSICANDSFX 5
@ -128,8 +130,8 @@ int32_t S_LoadSound(uint32_t num)
return 0;
}
int32_t fp = S_OpenAudio(g_sounds[num].filename, 0, 0);
if (fp == -1)
buildvfs_kfd fp = S_OpenAudio(g_sounds[num].filename, 0, 0);
if (fp == buildvfs_kfd_invalid)
{
OSD_Printf(OSDTEXT_RED "Sound %s(#%d) not found!\n",g_sounds[num].filename,num);
return 0;

View file

@ -1189,7 +1189,7 @@ static int it_load(struct module_data *m, HIO_HANDLE *f, const int start)
/* Alloc extra samples for sustain loop */
if (mod->smp > 0) {
m->xsmp = (xmp_sample *)calloc(sizeof (struct xmp_sample), mod->smp);
m->xsmp = (struct xmp_sample *)calloc(sizeof (struct xmp_sample), mod->smp);
if (m->xsmp == NULL) {
goto err4;
}

View file

@ -1,262 +0,0 @@
//-------------------------------------------------------------------------
/*
Copyright (C) 1996, 2003 - 3D Realms Entertainment
This file is part of Duke Nukem 3D version 1.5 - Atomic Edition
Duke Nukem 3D is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Original Source: 1996 - Todd Replogle
Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms
*/
//-------------------------------------------------------------------------
#pragma once
#ifndef file_lib_public_
#define file_lib_public_
#ifdef __cplusplus
extern "C" {
#endif
enum
{
filetype_binary,
filetype_text
};
enum
{
access_read,
access_write,
access_append
};
//==========================================================================
//
// SafeOpenWrite - Opens a file for writing, returns handle
//
//==========================================================================
int32_t SafeOpenWrite ( const char * filename, int32_t filetype );
//==========================================================================
//
// SafeOpenRead - Opens a file for reading, returns handle
//
//==========================================================================
int32_t SafeOpenRead ( const char * filename, int32_t filetype );
//==========================================================================
//
// SafeOpenAppend - Opens a file for appending, returns handle
//
//==========================================================================
int32_t SafeOpenAppend ( const char * filename, int32_t filetype );
//==========================================================================
//
// SafeClose - Close a file denoted by the file handle
//
//==========================================================================
void SafeClose ( int32_t handle );
//==========================================================================
//
// SafeFileExists - Checks for existence of file
//
//==========================================================================
int32_t SafeFileExists ( const char * filename );
//==========================================================================
//
// SafeFileLength - Get length of a file pointed to by handle
//
//==========================================================================
int32_t SafeFileLength ( int32_t handle );
//==========================================================================
//
// SafeRead - reads from a handle
//
// handle - handle of file to read from
//
// buffer - pointer of buffer to read into
//
// count - number of bytes to read
//
//==========================================================================
void SafeRead (int32_t handle, void *buffer, int32_t count);
//==========================================================================
//
// SafeWrite - writes to a handle
//
// handle - handle of file to write to
//
// buffer - pointer of buffer to write from
//
// count - number of bytes to write
//
//==========================================================================
void SafeWrite (int32_t handle, void *buffer, int32_t count);
//==========================================================================
//
// LoadFile - Load a file
//
// filename - name of file
//
// bufferptr - pointer to pointer of buffer to read into
//
// returns number of bytes read
//
//==========================================================================
int32_t LoadFile ( const char * filename, void ** bufferptr );
//==========================================================================
//
// SaveFile - Save a file
//
// filename - name of file
//
// bufferptr - pointer to buffer to write from
//
// count - number of bytes to write
//
//==========================================================================
void SaveFile ( const char * filename, void * bufferptr, int32_t count );
//==========================================================================
//
// GetPathFromEnvironment - Add a pathname described in an environment
// variable to a standard filename.
//
// fullname - final string containing entire path
//
// envname - string naming enivronment variable
//
// filename - standard filename
//
//==========================================================================
void GetPathFromEnvironment( char *fullname, const char *envname, const char *filename );
//==========================================================================
//
// DefaultExtension - Add a default extension to a path
//
// path - a path
//
// extension - default extension should include '.'
//
//==========================================================================
void DefaultExtension (char *path, const char *extension);
//==========================================================================
//
// DefaultPath - Add the default path to a filename if it doesn't have one
//
// path - filename
//
// extension - default path
//
//==========================================================================
void DefaultPath (char *path, const char *basepath);
//==========================================================================
//
// ExtractFileBase - Extract the base filename from a path
//
// path - the path
//
// dest - where the file base name will be placed
//
//==========================================================================
void ExtractFileBase (char *path, char *dest);
//==========================================================================
//
// GetExtension - Extract the extension from a name
// returns true if an extension is found
// returns false otherwise
//
//==========================================================================
int32_t GetExtension( char *filename, char *extension );
//==========================================================================
//
// SetExtension - Sets the extension from a name. Assumes that enough
// space is left at the end of the string to hold an extension.
//
//==========================================================================
void SetExtension( char *filename, const char *extension );
#ifdef __MSDOS__
//******************************************************************************
//
// GetPath
//
// Purpose
// To parse the directory entered by the user to make the directory.
//
// Parms
// Path - the path to be parsed.
//
// Returns
// Pointer to next path
//
//******************************************************************************
char * GetPath (char * path, char *dir);
//******************************************************************************
//
// ChangeDirectory ()
//
// Purpose
// To change to a directory. Checks for drive changes.
//
// Parms
// path - The path to change to.
//
// Returns
// TRUE - If successful.
// FALSE - If unsuccessful.
//
//******************************************************************************
int32_t ChangeDirectory (char * path);
//******************************************************************************
//
// ChangeDrive ()
//
// Purpose
// To change drives.
//
// Parms
// drive - The drive to change to.
//
// Returns
// TRUE - If drive change successful.
// FALSE - If drive change unsuccessful.
//
//******************************************************************************
int32_t ChangeDrive (char *drive);
#endif
#ifdef __cplusplus
}
#endif
#endif

View file

@ -121,7 +121,7 @@ static inline uint16_t findpage(uint16_t framenumber)
{
lp_descriptor & lp = anim->LpArray[i];
if (lp.baseRecord <= framenumber && framenumber < lp.baseRecord + lp.nRecords)
return i;
return (uint16_t)i;
}
if (j && i == nLps)
@ -134,7 +134,7 @@ static inline uint16_t findpage(uint16_t framenumber)
}
while (0);
return i;
return (uint16_t)i;
}

View file

@ -1,126 +0,0 @@
/*
* file_lib.c
* File functions to emulate MACT
*
* by Jonathon Fowler
*
* Since we weren't given the source for MACT386.LIB so I've had to do some
* creative interpolation here.
*
*/
//-------------------------------------------------------------------------
/*
Duke Nukem Copyright (C) 1996, 2003 3D Realms Entertainment
This file is part of Duke Nukem 3D version 1.5 - Atomic Edition
Duke Nukem 3D is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
//-------------------------------------------------------------------------
#include "compat.h"
#include "file_lib.h"
#include "cache1d.h"
#include "baselayer.h"
#define MaxFiles 20
static char *FileNames[MaxFiles];
int32_t SafeOpen(const char *filename, int32_t mode, int32_t sharemode)
{
int32_t h;
h = openfrompath(filename, mode, sharemode);
if (h < 0)
{
initprintf("Error opening %s: %s", filename, strerror(errno));
return h;
}
if (h < MaxFiles)
{
Bfree(FileNames[h]);
FileNames[h] = (char*)Xmalloc(strlen(filename)+1);
strcpy(FileNames[h], filename);
}
return h;
}
int32_t SafeOpenRead(const char *filename, int32_t filetype)
{
switch (filetype)
{
case filetype_binary:
return SafeOpen(filename, O_RDONLY|O_BINARY, BS_IREAD);
case filetype_text:
return SafeOpen(filename, O_RDONLY|O_TEXT, BS_IREAD);
default:
initprintf("SafeOpenRead: Illegal filetype specified");
return -1;
}
}
void SafeClose(int32_t handle)
{
if (handle < 0) return;
if (close(handle) < 0)
{
if (handle < MaxFiles)
initprintf("Unable to close file %s", FileNames[handle]);
else
initprintf("Unable to close file");
return;
}
if (handle < MaxFiles && FileNames[handle])
{
DO_FREE_AND_NULL(FileNames[handle]);
}
}
int32_t SafeFileExists(const char *filename)
{
if (!access(filename, F_OK)) return TRUE;
return FALSE;
}
int32_t SafeFileLength(int32_t handle)
{
if (handle < 0) return -1;
return Bfilelength(handle);
}
void SafeRead(int32_t handle, void *buffer, int32_t count)
{
int32_t b;
b = read(handle, buffer, count);
if (b != count)
{
close(handle);
if (handle < MaxFiles)
initprintf("File read failure %s reading %d bytes from file %s.",
strerror(errno), count, FileNames[handle]);
else
initprintf("File read failure %s reading %d bytes.",
strerror(errno), count);
return;
}
}

View file

@ -36,9 +36,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "compat.h"
#include "scriplib.h"
#include "file_lib.h"
#include "_scrplib.h"
#include "vfs.h"
static script_t *scriptfiles[MAXSCRIPTFILES];
@ -445,15 +446,16 @@ void SCRIPT_Free(int32_t scripthandle)
int32_t SCRIPT_Load(char const * filename)
{
int32_t s,h,l;
int32_t s,l;
char *b;
buildvfs_fd h;
h = SafeOpenRead(filename, filetype_binary);
l = SafeFileLength(h)+1;
h = buildvfs_open_read(filename);
l = (int32_t)buildvfs_length(h)+1;
b = (char *)Xmalloc(l);
SafeRead(h,b,l-1);
buildvfs_read(h,b,l-1);
b[l-1] = '\n'; // JBF 20040111: evil nasty hack to trick my evil nasty parser
SafeClose(h);
buildvfs_close(h);
s = SCRIPT_Init(filename);
if (s<0)
@ -473,22 +475,27 @@ void SCRIPT_Save(int32_t scripthandle, char const * filename)
{
char const *section, *entry, *value;
int32_t sec, ent, numsect, nument;
FILE *fp;
buildvfs_FILE fp;
if (!filename) return;
if (!SC(scripthandle)) return;
fp = fopen(filename, "w");
fp = buildvfs_fopen_write(filename);
if (!fp) return;
numsect = SCRIPT_NumberSections(scripthandle);
for (sec=0; sec<numsect; sec++)
{
section = SCRIPT_Section(scripthandle, sec);
if (sec>0) fprintf(fp, "\n");
if (sec>0)
buildvfs_fputc('\n', fp);
if (section[0] != 0)
fprintf(fp, "[%s]\n", section);
{
buildvfs_fputc('[', fp);
buildvfs_fputstrptr(fp, section);
buildvfs_fputstr(fp, "]\n");
}
nument = SCRIPT_NumberEntries(scripthandle,section);
for (ent=0; ent<nument; ent++)
@ -496,11 +503,14 @@ void SCRIPT_Save(int32_t scripthandle, char const * filename)
entry = SCRIPT_Entry(scripthandle,section,ent);
value = SCRIPT_GetRaw(scripthandle,section,entry);
fprintf(fp, "%s = %s\n", entry, value);
buildvfs_fputstrptr(fp, entry);
buildvfs_fputstr(fp, " = ");
buildvfs_fputstrptr(fp, value);
buildvfs_fputc('\n', fp);
}
}
fclose(fp);
buildvfs_fclose(fp);
}
int32_t SCRIPT_NumberSections(int32_t scripthandle)

View file

@ -6,7 +6,7 @@ tags_h=$(sw_src)/tags.h $(sw_src)/jtags.h
$(sw_obj)/actor.$o: $(sw_src)/actor.cpp $(build_h) $(sw_src)/keys.h $(names2_h) $(panel_h) $(game_h) $(tags_h) $(sw_src)/weapon.h $(sw_src)/sprite.h $(sw_src)/actor.h $(sw_src)/saveable.h
$(sw_obj)/ai.$o: $(sw_src)/ai.cpp $(build_h) $(sw_src)/keys.h $(names2_h) $(game_h) $(tags_h) $(sw_src)/ninja.h $(sw_src)/ai.h $(sw_src)/sector.h $(sw_src)/sprite.h $(sw_src)/net.h $(sw_src)/saveable.h
$(sw_obj)/anim.$o: $(sw_src)/anim.cpp $(build_h) $(sw_src)/keys.h $(sw_src)/mytypes.h $(audiolib_inc)/fx_man.h $(audiolib_inc)/music.h $(mact_inc)/scriplib.h $(mact_inc)/file_lib.h $(sw_src)/gamedefs.h $(mact_inc)/keyboard.h $(mact_inc)/control.h $(sw_src)/config.h $(sw_src)/sounds.h $(sw_src)/function.h $(mact_inc)/animlib.h $(sw_src)/anim.h $(game_h) $(sw_src)/colormap.h $(sw_src)/net.h
$(sw_obj)/anim.$o: $(sw_src)/anim.cpp $(build_h) $(sw_src)/keys.h $(sw_src)/mytypes.h $(audiolib_inc)/fx_man.h $(audiolib_inc)/music.h $(mact_inc)/scriplib.h $(sw_src)/gamedefs.h $(mact_inc)/keyboard.h $(mact_inc)/control.h $(sw_src)/config.h $(sw_src)/sounds.h $(sw_src)/function.h $(mact_inc)/animlib.h $(sw_src)/anim.h $(game_h) $(sw_src)/colormap.h $(sw_src)/net.h
$(sw_obj)/border.$o: $(sw_src)/border.cpp $(build_h) $(sw_src)/keys.h $(names2_h) $(panel_h) $(sw_src)/lists.h $(game_h) $(sw_src)/net.h $(sw_src)/text.h
$(sw_obj)/break.$o: $(sw_src)/break.cpp $(build_h) $(sw_src)/keys.h $(names2_h) $(panel_h) $(game_h) $(tags_h) $(sw_src)/break.h $(sw_src)/sprite.h $(sw_src)/sector.h $(sw_src)/light.h $(sw_src)/weapon.h
$(sw_obj)/bunny.$o: $(sw_src)/bunny.cpp $(build_h) $(sw_src)/keys.h $(names2_h) $(panel_h) $(game_h) $(tags_h) $(sw_src)/ai.h $(sw_src)/pal.h $(sw_src)/sprite.h $(sw_src)/actor.h $(sw_src)/weapon.h $(sw_src)/track.h $(sw_src)/saveable.h
@ -14,7 +14,7 @@ $(sw_obj)/cache.$o: $(sw_src)/cache.cpp $(build_h) $(names2_h) $(game_h) $(tags_
$(sw_obj)/cd.$o: $(sw_src)/cd.cpp $(sw_src)/mytypes.h $(sw_src)/keys.h $(names2_h) $(panel_h) $(game_h) $(tags_h) $(sw_src)/player.h $(sw_src)/lists.h $(sw_src)/warp.h $(sw_src)/quake.h $(sw_src)/function.h $(mact_inc)/control.h $(sw_src)/trigger.h $(sw_src)/savedef.h $(sw_src)/menus.h $(sw_src)/net.h $(sw_src)/pal.h
$(sw_obj)/cheats.$o: $(sw_src)/cheats.cpp $(build_h) $(sw_src)/keys.h $(names2_h) $(panel_h) $(game_h) $(sw_src)/mytypes.h $(mact_inc)/control.h $(sw_src)/function.h $(sw_src)/text.h
$(sw_obj)/colormap.$o: $(sw_src)/colormap.cpp $(build_h) $(sw_src)/keys.h $(sw_src)/pal.h $(game_h)
$(sw_obj)/config.$o: $(sw_src)/config.cpp $(build_h) $(sw_src)/settings.h $(sw_src)/mytypes.h $(mact_inc)/scriplib.h $(mact_inc)/file_lib.h $(sw_src)/gamedefs.h $(mact_inc)/keyboard.h $(sw_src)/function.h $(mact_inc)/control.h $(audiolib_inc)/fx_man.h $(sw_src)/sounds.h $(sw_src)/config.h $(sw_src)/common_game.h $(sw_src)/_functio.h $(sw_src)/_config.h
$(sw_obj)/config.$o: $(sw_src)/config.cpp $(build_h) $(sw_src)/settings.h $(sw_src)/mytypes.h $(mact_inc)/scriplib.h $(sw_src)/gamedefs.h $(mact_inc)/keyboard.h $(sw_src)/function.h $(mact_inc)/control.h $(audiolib_inc)/fx_man.h $(sw_src)/sounds.h $(sw_src)/config.h $(sw_src)/common_game.h $(sw_src)/_functio.h $(sw_src)/_config.h
$(sw_obj)/console.$o: $(sw_src)/console.cpp $(build_h) $(sw_src)/mytypes.h $(sw_src)/keys.h $(names2_h) $(panel_h) $(game_h) $(tags_h) $(sw_src)/player.h $(sw_src)/lists.h $(sw_src)/warp.h $(sw_src)/quake.h $(sw_src)/function.h $(mact_inc)/control.h $(sw_src)/trigger.h $(sw_src)/savedef.h $(sw_src)/menus.h $(sw_src)/net.h $(sw_src)/pal.h $(sw_src)/weapon.h $(sw_src)/text.h $(sw_src)/jsector.h
$(sw_obj)/coolg.$o: $(sw_src)/coolg.cpp $(build_h) $(sw_src)/keys.h $(names2_h) $(game_h) $(tags_h) $(sw_src)/ai.h $(sw_src)/sprite.h $(sw_src)/actor.h $(sw_src)/weapon.h $(sw_src)/track.h $(sw_src)/saveable.h
$(sw_obj)/coolie.$o: $(sw_src)/coolie.cpp $(build_h) $(sw_src)/keys.h $(names2_h) $(panel_h) $(game_h) $(tags_h) $(sw_src)/ai.h $(sw_src)/sprite.h $(sw_src)/actor.h $(sw_src)/track.h $(sw_src)/weapon.h $(sw_src)/saveable.h
@ -49,12 +49,12 @@ $(sw_obj)/ripper.$o: $(sw_src)/ripper.cpp $(build_h) $(sw_src)/keys.h $(names2_h
$(sw_obj)/ripper2.$o: $(sw_src)/ripper2.cpp $(build_h) $(sw_src)/keys.h $(names2_h) $(panel_h) $(game_h) $(tags_h) $(sw_src)/ai.h $(sw_src)/pal.h $(sw_src)/actor.h $(sw_src)/sprite.h $(sw_src)/track.h $(audiolib_inc)/fx_man.h $(sw_src)/saveable.h
$(sw_obj)/rooms.$o: $(sw_src)/rooms.cpp $(build_h) $(names2_h) $(panel_h) $(game_h) $(sw_src)/warp.h
$(sw_obj)/rotator.$o: $(sw_src)/rotator.cpp $(build_h) $(names2_h) $(panel_h) $(game_h) $(sw_src)/net.h $(tags_h) $(sw_src)/sector.h $(sw_src)/text.h $(sw_src)/interp.h $(sw_src)/sprite.h $(sw_src)/saveable.h
$(sw_obj)/rts.$o: $(sw_src)/rts.cpp $(sw_src)/mytypes.h $(mact_inc)/file_lib.h $(sw_src)/_rts.h $(sw_src)/rts.h $(sw_src)/cache.h
$(sw_obj)/rts.$o: $(sw_src)/rts.cpp $(sw_src)/mytypes.h $(sw_src)/_rts.h $(sw_src)/rts.h $(sw_src)/cache.h
$(sw_obj)/save.$o: $(sw_src)/save.cpp $(build_h) $(sw_src)/keys.h $(names2_h) $(panel_h) $(game_h) $(tags_h) $(sw_src)/lists.h $(sw_src)/interp.h $(sw_src)/net.h $(sw_src)/savedef.h $(sw_src)/jsector.h $(sw_src)/parent.h $(sw_src)/reserve.h $(sw_src)/mfile.h $(sw_src)/weapon.h $(sw_src)/cache.h $(sw_src)/colormap.h $(sw_src)/player.h $(audiolib_inc)/fx_man.h $(audiolib_inc)/music.h $(sw_src)/saveable.h
$(sw_obj)/scrip2.$o: $(sw_src)/scrip2.cpp $(build_h) $(sw_src)/keys.h $(names2_h) $(panel_h) $(game_h) $(sw_src)/parse.h $(sw_src)/jsector.h $(sw_src)/parent.h
$(sw_obj)/sector.$o: $(sw_src)/sector.cpp $(build_h) $(sw_src)/keys.h $(names2_h) $(panel_h) $(game_h) $(tags_h) $(sw_src)/sector.h $(sw_src)/player.h $(sw_src)/quake.h $(sw_src)/weapon.h $(sw_src)/jtags.h $(sw_src)/net.h $(sw_src)/break.h $(sw_src)/track.h $(sw_src)/sprite.h $(sw_src)/light.h $(sw_src)/text.h
$(sw_obj)/serp.$o: $(sw_src)/serp.cpp $(build_h) $(sw_src)/keys.h $(names2_h) $(game_h) $(tags_h) $(sw_src)/ai.h $(sw_src)/actor.h $(sw_src)/track.h $(sw_src)/sector.h
$(sw_obj)/setup.$o: $(sw_src)/setup.cpp $(build_h) $(sw_src)/keys.h $(game_h) $(sw_src)/mytypes.h $(audiolib_inc)/fx_man.h $(audiolib_inc)/music.h $(mact_inc)/scriplib.h $(mact_inc)/file_lib.h $(sw_src)/gamedefs.h $(mact_inc)/keyboard.h $(mact_inc)/control.h $(sw_src)/config.h $(sw_src)/sounds.h $(sw_src)/function.h $(sw_src)/rts.h
$(sw_obj)/setup.$o: $(sw_src)/setup.cpp $(build_h) $(sw_src)/keys.h $(game_h) $(sw_src)/mytypes.h $(audiolib_inc)/fx_man.h $(audiolib_inc)/music.h $(mact_inc)/scriplib.h $(sw_src)/gamedefs.h $(mact_inc)/keyboard.h $(mact_inc)/control.h $(sw_src)/config.h $(sw_src)/sounds.h $(sw_src)/function.h $(sw_src)/rts.h
$(sw_obj)/skel.$o: $(sw_src)/skel.cpp $(build_h) $(sw_src)/keys.h $(names2_h) $(game_h) $(tags_h) $(sw_src)/ai.h $(sw_src)/actor.h $(sw_src)/track.h
$(sw_obj)/skull.$o: $(sw_src)/skull.cpp $(build_h) $(sw_src)/keys.h $(names2_h) $(game_h) $(tags_h) $(sw_src)/ai.h $(sw_src)/weapon.h $(sw_src)/actor.h
$(sw_obj)/slidor.$o: $(sw_src)/slidor.cpp $(build_h) $(names2_h) $(panel_h) $(game_h) $(sw_src)/net.h $(tags_h) $(sw_src)/slidor.h $(sw_src)/slidor.h $(sw_src)/sector.h $(sw_src)/interp.h $(sw_src)/text.h $(sw_src)/sprite.h $(sw_src)/saveable.h

View file

@ -31,7 +31,6 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
#include "fx_man.h"
#include "music.h"
#include "scriplib.h"
#include "file_lib.h"
#include "gamedefs.h"
#include "keyboard.h"

View file

@ -30,7 +30,6 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
#include "settings.h"
#include "mytypes.h"
#include "scriplib.h"
#include "file_lib.h"
#include "gamedefs.h"
#include "keyboard.h"
#include "function.h"

View file

@ -31,7 +31,6 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
#include "baselayer.h"
#include "mytypes.h"
#include "file_lib.h"
#include "_rts.h"
#include "rts.h"
#include "cache.h"

View file

@ -32,7 +32,6 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
#include "fx_man.h"
#include "music.h"
#include "scriplib.h"
#include "file_lib.h"
#include "gamedefs.h"
#include "keyboard.h"
@ -155,7 +154,6 @@ void TermSetup(void)
#include "fx_man.h"
#include "music.h"
#include "scriplib.h"
#include "file_lib.h"
#include "gamedefs.h"
#include "keyboard.h"