- refactored a few more - simple stuff but lots of lines.

This commit is contained in:
Christoph Oelckers 2019-10-21 00:13:17 +02:00
parent 5022c58a63
commit 5333f6adc1
7 changed files with 125 additions and 142 deletions

View file

@ -365,18 +365,16 @@ void sndStartWavDisk(const char *pzFile, int nVolume, int nChannel)
pChannel = &Channel[nChannel];
if (pChannel->at0 > 0)
sndKillSound(pChannel);
int hFile = kopen4loadfrommod(pzFile, 0);
if (hFile == -1)
auto hFile = kopenFileReader(pzFile, 0);
if (!hFile.isOpen())
return;
int nLength = kfilelength(hFile);
int nLength = hFile.GetLength();
char *pData = (char*)gSoundRes.Alloc(nLength);
if (!pData)
{
kclose(hFile);
return;
}
kread(hFile, pData, kfilelength(hFile));
kclose(hFile);
hFile.Read(pData, nLength);
pChannel->at5 = (DICTNODE*)pData;
pChannel->at4 |= 2;
pChannel->at0 = FX_Play(pData, nLength, 0, -1, 0, nVolume, nVolume, nVolume, nVolume, 1.f, (intptr_t)&pChannel->at0);

View file

@ -88,27 +88,24 @@ int tileInit(char a1, const char *a2)
for (int i = 0; i < kMaxTiles; i++)
voxelIndex[i] = 0;
int hFile = kopen4loadfrommod("SURFACE.DAT", 0);
if (hFile != -1)
auto hFile = kopenFileReader("SURFACE.DAT", 0);
if (hFile.isOpen())
{
kread(hFile, surfType, sizeof(surfType));
kclose(hFile);
hFile.Read(surfType, sizeof(surfType));
}
hFile = kopen4loadfrommod("VOXEL.DAT", 0);
if (hFile != -1)
hFile = kopenFileReader("VOXEL.DAT", 0);
if (hFile.isOpen())
{
kread(hFile, voxelIndex, sizeof(voxelIndex));
hFile.Read(voxelIndex, sizeof(voxelIndex));
#if B_BIG_ENDIAN == 1
for (int i = 0; i < kMaxTiles; i++)
voxelIndex[i] = B_LITTLE16(voxelIndex[i]);
#endif
kclose(hFile);
}
hFile = kopen4loadfrommod("SHADE.DAT", 0);
if (hFile != -1)
hFile = kopenFileReader("SHADE.DAT", 0);
if (hFile.isOpen())
{
kread(hFile, tileShade, sizeof(tileShade));
kclose(hFile);
hFile.Read(tileShade, sizeof(tileShade));
}
for (int i = 0; i < kMaxTiles; i++)
{

View file

@ -683,7 +683,7 @@ prep_return:
}
//--------------------------------------- MD2 LIBRARY BEGINS ---------------------------------------
static md2model_t *md2load(buildvfs_kfd fil, const char *filnam)
static md2model_t *md2load(FileReader & fil, const char *filnam)
{
md2model_t *m;
md3model_t *m3;
@ -698,7 +698,7 @@ static md2model_t *md2load(buildvfs_kfd fil, const char *filnam)
m = (md2model_t *)Xcalloc(1,sizeof(md2model_t));
m->mdnum = 2; m->scale = .01f;
kread(fil,(char *)&head,sizeof(md2head_t));
fil.Read((char *)&head,sizeof(md2head_t));
#if B_BIG_ENDIAN != 0
head.id = B_LITTLE32(head.id); head.vers = B_LITTLE32(head.vers);
head.skinxsiz = B_LITTLE32(head.skinxsiz); head.skinysiz = B_LITTLE32(head.skinysiz);
@ -727,23 +727,23 @@ static md2model_t *md2load(buildvfs_kfd fil, const char *filnam)
m->tris = (md2tri_t *)Xmalloc(head.numtris*sizeof(md2tri_t));
m->uv = (md2uv_t *)Xmalloc(head.numuv*sizeof(md2uv_t));
klseek(fil,head.ofsframes,SEEK_SET);
if (kread(fil,(char *)m->frames,m->numframes*m->framebytes) != m->numframes*m->framebytes)
fil.Seek(head.ofsframes,FileReader::SeekSet);
if (fil.Read((char *)m->frames,m->numframes*m->framebytes) != m->numframes*m->framebytes)
{ Xfree(m->uv); Xfree(m->tris); Xfree(m->glcmds); Xfree(m->frames); Xfree(m); return 0; }
if (m->numglcmds > 0)
{
klseek(fil,head.ofsglcmds,SEEK_SET);
if (kread(fil,(char *)m->glcmds,m->numglcmds*sizeof(int32_t)) != (int32_t)(m->numglcmds*sizeof(int32_t)))
fil.Seek(head.ofsglcmds,FileReader::SeekSet);
if (fil.Read((char *)m->glcmds,m->numglcmds*sizeof(int32_t)) != (int32_t)(m->numglcmds*sizeof(int32_t)))
{ Xfree(m->uv); Xfree(m->tris); Xfree(m->glcmds); Xfree(m->frames); Xfree(m); return 0; }
}
klseek(fil,head.ofstris,SEEK_SET);
if (kread(fil,(char *)m->tris,head.numtris*sizeof(md2tri_t)) != (int32_t)(head.numtris*sizeof(md2tri_t)))
fil.Seek(head.ofstris,FileReader::SeekSet);
if (fil.Read((char *)m->tris,head.numtris*sizeof(md2tri_t)) != (int32_t)(head.numtris*sizeof(md2tri_t)))
{ Xfree(m->uv); Xfree(m->tris); Xfree(m->glcmds); Xfree(m->frames); Xfree(m); return 0; }
klseek(fil,head.ofsuv,SEEK_SET);
if (kread(fil,(char *)m->uv,head.numuv*sizeof(md2uv_t)) != (int32_t)(head.numuv*sizeof(md2uv_t)))
fil.Seek(head.ofsuv,FileReader::SeekSet);
if (fil.Read((char *)m->uv,head.numuv*sizeof(md2uv_t)) != (int32_t)(head.numuv*sizeof(md2uv_t)))
{ Xfree(m->uv); Xfree(m->tris); Xfree(m->glcmds); Xfree(m->frames); Xfree(m); return 0; }
#if B_BIG_ENDIAN != 0
@ -792,8 +792,8 @@ static md2model_t *md2load(buildvfs_kfd fil, const char *filnam)
m->skinfn = (char *)Xmalloc(ournumskins*64);
if (m->numskins > 0)
{
klseek(fil,head.ofsskins,SEEK_SET);
if (kread(fil,m->skinfn,64*m->numskins) != 64*m->numskins)
fil.Seek(head.ofsskins,FileReader::SeekSet);
if (fil.Read(m->skinfn,64*m->numskins) != 64*m->numskins)
{ Xfree(m->glcmds); Xfree(m->frames); Xfree(m); return 0; }
}
@ -967,7 +967,7 @@ static inline void quicksort(uint16_t *indexes, float *depths, int32_t first, in
//--------------------------------------- MD3 LIBRARY BEGINS ---------------------------------------
static md3model_t *md3load(buildvfs_kfd fil)
static md3model_t *md3load(FileReader & fil)
{
int32_t i, surfi, ofsurf, offs[4], leng[4];
int32_t maxtrispersurf;
@ -979,7 +979,7 @@ static md3model_t *md3load(buildvfs_kfd fil)
m->muladdframes = NULL;
kread(fil,&m->head,SIZEOF_MD3HEAD_T);
fil.Read(&m->head,SIZEOF_MD3HEAD_T);
#if B_BIG_ENDIAN != 0
m->head.id = B_LITTLE32(m->head.id); m->head.vers = B_LITTLE32(m->head.vers);
@ -997,19 +997,19 @@ static md3model_t *md3load(buildvfs_kfd fil)
ofsurf = m->head.ofssurfs;
klseek(fil,m->head.ofsframes,SEEK_SET); i = m->head.numframes*sizeof(md3frame_t);
fil.Seek(m->head.ofsframes,FileReader::SeekSet); i = m->head.numframes*sizeof(md3frame_t);
m->head.frames = (md3frame_t *)Xmalloc(i);
kread(fil,m->head.frames,i);
fil.Read(m->head.frames,i);
if (m->head.numtags == 0) m->head.tags = NULL;
else
{
klseek(fil,m->head.ofstags,SEEK_SET); i = m->head.numtags*sizeof(md3tag_t);
fil.Seek(m->head.ofstags,FileReader::SeekSet); i = m->head.numtags*sizeof(md3tag_t);
m->head.tags = (md3tag_t *)Xmalloc(i);
kread(fil,m->head.tags,i);
fil.Read(m->head.tags,i);
}
klseek(fil,m->head.ofssurfs,SEEK_SET);
fil.Seek(m->head.ofssurfs,FileReader::SeekSet);
m->head.surfs = (md3surf_t *)Xcalloc(m->head.numsurfs, sizeof(md3surf_t));
// NOTE: We assume that NULL is represented by all-zeros.
// surfs[0].geometry is for POLYMER_MD_PROCESS_CHECK (else: crashes).
@ -1039,7 +1039,7 @@ static md3model_t *md3load(buildvfs_kfd fil)
for (surfi=0; surfi<m->head.numsurfs; surfi++)
{
s = &m->head.surfs[surfi];
klseek(fil,ofsurf,SEEK_SET); kread(fil,s,SIZEOF_MD3SURF_T);
fil.Seek(ofsurf,FileReader::SeekSet); fil.Read(s,SIZEOF_MD3SURF_T);
#if B_BIG_ENDIAN != 0
{
@ -1069,10 +1069,10 @@ static md3model_t *md3load(buildvfs_kfd fil)
s->uv = (md3uv_t *)(((intptr_t)s->shaders)+leng[1]);
s->xyzn = (md3xyzn_t *)(((intptr_t)s->uv)+leng[2]);
klseek(fil,offs[0],SEEK_SET); kread(fil,s->tris ,leng[0]);
klseek(fil,offs[1],SEEK_SET); kread(fil,s->shaders,leng[1]);
klseek(fil,offs[2],SEEK_SET); kread(fil,s->uv ,leng[2]);
klseek(fil,offs[3],SEEK_SET); kread(fil,s->xyzn ,leng[3]);
fil.Seek(offs[0],FileReader::SeekSet); fil.Read(s->tris ,leng[0]);
fil.Seek(offs[1],FileReader::SeekSet); fil.Read(s->shaders,leng[1]);
fil.Seek(offs[2],FileReader::SeekSet); fil.Read(s->uv ,leng[2]);
fil.Seek(offs[3],FileReader::SeekSet); fil.Read(s->xyzn ,leng[3]);
#if B_BIG_ENDIAN != 0
{
@ -1880,13 +1880,13 @@ mdmodel_t *mdload(const char *filnam)
vm = (mdmodel_t *)voxload(filnam);
if (vm) return vm;
buildvfs_kfd fil = kopen4load(filnam,0);
auto fil = kopenFileReader(filnam,0);
if (fil == buildvfs_kfd_invalid)
if (!fil.isOpen())
return NULL;
kread(fil,&i,4);
klseek(fil,0,SEEK_SET);
fil.Read(&i,4);
fil.Seek(0,FileReader::SeekSet);
switch (B_LITTLE32(i))
{
@ -1902,8 +1902,6 @@ mdmodel_t *mdload(const char *filnam)
break;
}
kclose(fil);
if (vm)
{
md3model_t *vm3 = (md3model_t *)vm;

View file

@ -166,11 +166,11 @@ int OSD_Exec(const char *szScript)
{
int err = 0;
int32_t len = 0;
buildvfs_kfd handle;
FileReader handle;
if ((handle = kopen4load(szScript, 0)) == buildvfs_kfd_invalid)
if (!(handle = fopenFileReader(szScript, 0)).isOpen())
err = 1;
else if ((len = kfilelength(handle)) <= 0)
else if ((len = handle.GetLength()) <= 0)
err = 2; // blank file
if (!err)
@ -178,19 +178,15 @@ int OSD_Exec(const char *szScript)
auto buf = (char *) Xmalloc(len + 1);
if (err || kread(handle, buf, len) != len)
if (err || handle.Read(buf, len) != len)
{
if (!err) // no error message for blank file
OSD_Printf("Error executing \"%s\"!\n", szScript);
if (handle != buildvfs_kfd_invalid)
kclose(handle);
Xfree(buf);
return 1;
}
kclose(handle);
buf[len] = '\0';
char const *cp = strtok(buf, "\r\n");
@ -274,9 +270,9 @@ static int osdfunc_fileinfo(osdcmdptr_t parm)
{
if (parm->numparms != 1) return OSDCMD_SHOWHELP;
buildvfs_kfd h;
FileReader h;
if ((h = kopen4load(parm->parms[0],0)) == buildvfs_kfd_invalid)
if (!(h = kopenFileReader(parm->parms[0],0)).isOpen())
{
OSD_Printf("fileinfo: File \"%s\" not found.\n", parm->parms[0]);
return OSDCMD_OK;
@ -291,14 +287,14 @@ static int osdfunc_fileinfo(osdcmdptr_t parm)
do
{
siz = kread(h, buf, ReadSize);
siz = h.Read(buf, ReadSize);
crcval = Bcrc32((uint8_t *)buf, siz, crcval);
}
while (siz == ReadSize);
crctime = timerGetHiTicks() - crctime;
klseek(h, 0, BSEEK_SET);
h.Seek(0, FileReader::SeekSet);
double xxhtime = timerGetHiTicks();
@ -307,7 +303,7 @@ static int osdfunc_fileinfo(osdcmdptr_t parm)
do
{
siz = kread(h, buf, ReadSize);
siz = h.Read(buf, ReadSize);
XXH32_update(&xxh, (uint8_t *)buf, siz);
}
while (siz == ReadSize);
@ -321,12 +317,10 @@ static int osdfunc_fileinfo(osdcmdptr_t parm)
" File size: %d bytes\n"
" CRC-32: %08X (%.1fms)\n"
" xxHash: %08X (%.1fms)\n",
parm->parms[0], kfilelength(h),
parm->parms[0], (int)h.GetLength(),
crcval, crctime,
xxhash, xxhtime);
kclose(h);
return OSDCMD_OK;
}

View file

@ -187,6 +187,11 @@ static void maybe_alloc_palookup(int32_t palnum);
void (*paletteLoadFromDisk_replace)(void) = NULL;
inline bool read_and_test(FileReader& handle, void* buffer, int32_t leng)
{
return handle.Read(buffer, leng) != leng;
};
//
// loadpalette (internal)
//
@ -206,15 +211,15 @@ void paletteLoadFromDisk(void)
return;
}
buildvfs_kfd fil;
if ((fil = kopen4load("palette.dat", 0)) == buildvfs_kfd_invalid)
auto fil = kopenFileReader("palette.dat", 0);
if (!fil.isOpen())
return;
// PALETTE_MAIN
if (kread_and_test(fil, palette, 768))
return kclose(fil);
if (768 != fil.Read(palette, 768))
return;
for (unsigned char & k : palette)
k <<= 2;
@ -226,15 +231,16 @@ void paletteLoadFromDisk(void)
// PALETTE_SHADES
if (kread_and_test(fil, &numshades, 2))
return kclose(fil);
if (2 != fil.Read(&numshades, 2))
return;
numshades = B_LITTLE16(numshades);
if (numshades <= 1)
{
initprintf("Warning: Invalid number of shades in \"palette.dat\"!\n");
numshades = 0;
return kclose(fil);
return;
}
// Auto-detect LameDuke. Its PALETTE.DAT doesn't have a 'numshades' 16-bit
@ -247,15 +253,15 @@ void paletteLoadFromDisk(void)
static char const * const seekfail = "Warning: klseek() failed in loadpalette()!\n";
uint16_t temp;
if (kread_and_test(fil, &temp, 2))
return kclose(fil);
if (read_and_test(fil, &temp, 2))
return;
temp = B_LITTLE16(temp);
if (temp == 770 || numshades > 256) // 02 03
{
if (klseek(fil, -4, BSEEK_CUR) < 0)
if (fil.Seek(-4, FileReader::SeekCur) < 0)
{
initputs(seekfail);
return kclose(fil);
return;
}
numshades = 32;
@ -263,18 +269,18 @@ void paletteLoadFromDisk(void)
}
else
{
if (klseek(fil, -2, BSEEK_CUR) < 0)
if (fil.Seek(-2, FileReader::SeekCur) < 0)
{
initputs(seekfail);
return kclose(fil);
return;
}
}
}
// Read base shade table (palookup 0).
maybe_alloc_palookup(0);
if (kread_and_test(fil, palookup[0], numshades<<8))
return kclose(fil);
if (read_and_test(fil, palookup[0], numshades<<8))
return;
paletteloaded |= PALETTE_SHADE;
@ -292,8 +298,8 @@ void paletteLoadFromDisk(void)
// Read the entries above and on the diagonal, if the table is
// thought as being row-major.
if (kread_and_test(fil, &transluc[256*i + i], 256-i-1))
return kclose(fil);
if (read_and_test(fil, &transluc[256*i + i], 256-i-1))
return;
// Duplicate the entries below the diagonal.
for (bssize_t j=0; j<i; j++)
@ -302,8 +308,8 @@ void paletteLoadFromDisk(void)
}
else
{
if (kread_and_test(fil, transluc, 65536))
return kclose(fil);
if (read_and_test(fil, transluc, 65536))
return;
}
paletteloaded |= PALETTE_TRANSLUC;
@ -312,34 +318,34 @@ void paletteLoadFromDisk(void)
// additional blending tables
uint8_t magic[12];
if (!kread_and_test(fil, magic, sizeof(magic)) && !Bmemcmp(magic, "MoreBlendTab", sizeof(magic)))
if (!read_and_test(fil, magic, sizeof(magic)) && !Bmemcmp(magic, "MoreBlendTab", sizeof(magic)))
{
uint8_t addblendtabs;
if (kread_and_test(fil, &addblendtabs, 1))
if (read_and_test(fil, &addblendtabs, 1))
{
initprintf("Warning: failed reading additional blending table count\n");
return kclose(fil);
return;
}
uint8_t blendnum;
char *tab = (char *) Xmalloc(256*256);
for (bssize_t i=0; i<addblendtabs; i++)
{
if (kread_and_test(fil, &blendnum, 1))
if (read_and_test(fil, &blendnum, 1))
{
initprintf("Warning: failed reading additional blending table index\n");
Xfree(tab);
return kclose(fil);
return;
}
if (paletteGetBlendTable(blendnum) != NULL)
initprintf("Warning: duplicate blending table index %3d encountered\n", blendnum);
if (kread_and_test(fil, tab, 256*256))
if (read_and_test(fil, tab, 256*256))
{
initprintf("Warning: failed reading additional blending table\n");
Xfree(tab);
return kclose(fil);
return;
}
paletteSetBlendTable(blendnum, tab);
@ -348,7 +354,7 @@ void paletteLoadFromDisk(void)
// Read log2 of count of alpha blending tables.
uint8_t lognumalphatabs;
if (!kread_and_test(fil, &lognumalphatabs, 1))
if (!read_and_test(fil, &lognumalphatabs, 1))
{
if (!(lognumalphatabs >= 1 && lognumalphatabs <= 7))
initprintf("invalid lognumalphatabs value, must be in [1 .. 7]\n");
@ -356,8 +362,6 @@ void paletteLoadFromDisk(void)
numalphatabs = 1<<lognumalphatabs;
}
}
kclose(fil);
}
uint32_t PaletteIndexFullbrights[8];
@ -456,7 +460,7 @@ void paletteFixTranslucencyMask(void)
// Load LOOKUP.DAT, which contains lookup tables and additional base palettes.
//
// <fp>: kopen4load file handle
// <fp>: open file handle
//
// Returns:
// - on success, 0

View file

@ -820,33 +820,29 @@ static SDL_GameController *controller = NULL;
static void LoadSDLControllerDB()
{
buildvfs_kfd fh = kopen4load("gamecontrollerdb.txt", 0);
if (fh == buildvfs_kfd_invalid)
auto fh = fopenFileReader("gamecontrollerdb.txt", 0);
if (!fh.isOpen())
return;
int flen = kfilelength(fh);
int flen = fh.GetLength();
if (flen <= 0)
{
kclose(fh);
return;
}
char * dbuf = (char *)malloc(flen + 1);
if (!dbuf)
{
kclose(fh);
return;
}
if (kread_and_test(fh, dbuf, flen))
if (fh.Read(dbuf, flen) != flen)
{
free(dbuf);
kclose(fh);
return;
}
dbuf[flen] = '\0';
kclose(fh);
SDL_RWops * rwops = SDL_RWFromConstMem(dbuf, flen);
if (!rwops)

View file

@ -594,14 +594,14 @@ static void alloc_vbit(void)
memset(vbit, 0, i);
}
static void read_pal(buildvfs_kfd fil, int32_t pal[256])
static void read_pal(FileReader &fil, int32_t pal[256])
{
klseek(fil, -768, SEEK_END);
fil.Seek(-768, FileReader::SeekEnd);
for (bssize_t i=0; i<256; i++)
{
char c[3];
kread(fil, c, 3);
fil.Read(c, 3);
//#if B_BIG_ENDIAN != 0
pal[i] = B_LITTLE32((c[0]<<18) + (c[1]<<10) + (c[2]<<2) + (i<<24));
//#endif
@ -610,11 +610,11 @@ static void read_pal(buildvfs_kfd fil, int32_t pal[256])
static int32_t loadvox(const char *filnam)
{
const buildvfs_kfd fil = kopen4load(filnam, 0);
if (fil == buildvfs_kfd_invalid)
return -1;
auto fil = kopenFileReader(filnam, 0);
if (!fil.isOpen())
return -1;
kread(fil, &voxsiz, sizeof(vec3_t));
fil.Read(&voxsiz, sizeof(vec3_t));
#if B_BIG_ENDIAN != 0
voxsiz.x = B_LITTLE32(voxsiz.x);
voxsiz.y = B_LITTLE32(voxsiz.y);
@ -634,11 +634,11 @@ static int32_t loadvox(const char *filnam)
char *const tbuf = (char *)Xmalloc(voxsiz.z*sizeof(uint8_t));
klseek(fil, 12, SEEK_SET);
fil.Seek(12, FileReader::SeekSet);
for (bssize_t x=0; x<voxsiz.x; x++)
for (bssize_t y=0, j=x*yzsiz; y<voxsiz.y; y++, j+=voxsiz.z)
{
kread(fil, tbuf, voxsiz.z);
fil.Read(tbuf, voxsiz.z);
for (bssize_t z=voxsiz.z-1; z>=0; z--)
if (tbuf[z] != 255)
@ -648,11 +648,11 @@ static int32_t loadvox(const char *filnam)
}
}
klseek(fil, 12, SEEK_SET);
fil.Seek(12, FileReader::SeekSet);
for (bssize_t x=0; x<voxsiz.x; x++)
for (bssize_t y=0, j=x*yzsiz; y<voxsiz.y; y++, j+=voxsiz.z)
{
kread(fil, tbuf, voxsiz.z);
fil.Read(tbuf, voxsiz.z);
for (bssize_t z=0; z<voxsiz.z; z++)
{
@ -678,7 +678,6 @@ static int32_t loadvox(const char *filnam)
}
Xfree(tbuf);
kclose(fil);
return 0;
}
@ -687,27 +686,27 @@ static int32_t loadkvx(const char *filnam)
{
int32_t i, mip1leng;
const buildvfs_kfd fil = kopen4load(filnam, 0);
if (fil == buildvfs_kfd_invalid)
return -1;
auto fil = kopenFileReader(filnam, 0);
if (!fil.isOpen())
return -1;
kread(fil, &mip1leng, 4); mip1leng = B_LITTLE32(mip1leng);
kread(fil, &voxsiz, sizeof(vec3_t));
fil.Read(&mip1leng, 4); mip1leng = B_LITTLE32(mip1leng);
fil.Read(&voxsiz, sizeof(vec3_t));
#if B_BIG_ENDIAN != 0
voxsiz.x = B_LITTLE32(voxsiz.x);
voxsiz.y = B_LITTLE32(voxsiz.y);
voxsiz.z = B_LITTLE32(voxsiz.z);
#endif
kread(fil, &i, 4); voxpiv.x = (float)B_LITTLE32(i)*(1.f/256.f);
kread(fil, &i, 4); voxpiv.y = (float)B_LITTLE32(i)*(1.f/256.f);
kread(fil, &i, 4); voxpiv.z = (float)B_LITTLE32(i)*(1.f/256.f);
klseek(fil, (voxsiz.x+1)<<2, SEEK_CUR);
fil.Read(&i, 4); voxpiv.x = (float)B_LITTLE32(i)*(1.f/256.f);
fil.Read(&i, 4); voxpiv.y = (float)B_LITTLE32(i)*(1.f/256.f);
fil.Read(&i, 4); voxpiv.z = (float)B_LITTLE32(i)*(1.f/256.f);
fil.Seek((voxsiz.x+1)<<2, FileReader::SeekCur);
const int32_t ysizp1 = voxsiz.y+1;
i = voxsiz.x*ysizp1*sizeof(int16_t);
uint16_t *xyoffs = (uint16_t *)Xmalloc(i);
kread(fil, xyoffs, i);
fil.Read(xyoffs, i);
for (i=i/sizeof(int16_t)-1; i>=0; i--)
xyoffs[i] = B_LITTLE16(xyoffs[i]);
@ -724,13 +723,12 @@ static int32_t loadkvx(const char *filnam)
vcolhashsizm1--; //approx to numvoxs!
alloc_vcolhashead();
klseek(fil, 28+((voxsiz.x+1)<<2)+((ysizp1*voxsiz.x)<<1), SEEK_SET);
fil.Seek(28+((voxsiz.x+1)<<2)+((ysizp1*voxsiz.x)<<1), FileReader::SeekSet);
i = kfilelength(fil)-ktell(fil);
i = fil.GetLength() - fil.Tell();
char *const tbuf = (char *)Xmalloc(i);
kread(fil, tbuf, i);
kclose(fil);
fil.Read(tbuf, i);
char *cptr = tbuf;
@ -772,38 +770,37 @@ static int32_t loadkv6(const char *filnam)
{
int32_t i;
const buildvfs_kfd fil = kopen4load(filnam, 0);
if (fil == buildvfs_kfd_invalid)
auto fil = kopenFileReader(filnam, 0);
if (!fil.isOpen())
return -1;
kread(fil, &i, 4);
fil.Read(&i, 4);
if (B_LITTLE32(i) != 0x6c78764b)
{
kclose(fil);
return -1;
} //Kvxl
kread(fil, &voxsiz, sizeof(vec3_t));
fil.Read(&voxsiz, sizeof(vec3_t));
#if B_BIG_ENDIAN != 0
voxsiz.x = B_LITTLE32(voxsiz.x);
voxsiz.y = B_LITTLE32(voxsiz.y);
voxsiz.z = B_LITTLE32(voxsiz.z);
#endif
kread(fil, &i, 4); voxpiv.x = (float)B_LITTLE32(i);
kread(fil, &i, 4); voxpiv.y = (float)B_LITTLE32(i);
kread(fil, &i, 4); voxpiv.z = (float)B_LITTLE32(i);
fil.Read(&i, 4); voxpiv.x = (float)B_LITTLE32(i);
fil.Read(&i, 4); voxpiv.y = (float)B_LITTLE32(i);
fil.Read(&i, 4); voxpiv.z = (float)B_LITTLE32(i);
int32_t numvoxs;
kread(fil, &numvoxs, 4); numvoxs = B_LITTLE32(numvoxs);
fil.Read(&numvoxs, 4); numvoxs = B_LITTLE32(numvoxs);
uint16_t *const ylen = (uint16_t *)Xmalloc(voxsiz.x*voxsiz.y*sizeof(int16_t));
klseek(fil, 32+(numvoxs<<3)+(voxsiz.x<<2), SEEK_SET);
kread(fil, ylen, voxsiz.x*voxsiz.y*sizeof(int16_t));
fil.Seek(32+(numvoxs<<3)+(voxsiz.x<<2), FileReader::SeekSet);
fil.Read(ylen, voxsiz.x*voxsiz.y*sizeof(int16_t));
for (i=voxsiz.x*voxsiz.y-1; i>=0; i--)
ylen[i] = B_LITTLE16(ylen[i]);
klseek(fil, 32, SEEK_SET);
fil.Seek(32, FileReader::SeekSet);
alloc_vbit();
@ -822,7 +819,7 @@ static int32_t loadkv6(const char *filnam)
for (i=ylen[x*voxsiz.y+y]; i>0; i--)
{
char c[8];
kread(fil, c, 8); //b,g,r,a,z_lo,z_hi,vis,dir
fil.Read(c, 8); //b,g,r,a,z_lo,z_hi,vis,dir
const int32_t z0 = B_LITTLE16(B_UNBUF16(&c[4]));
@ -837,7 +834,6 @@ static int32_t loadkv6(const char *filnam)
}
Xfree(ylen);
kclose(fil);
return 0;
}