2018-11-05 07:28:01 +00:00
|
|
|
// "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman
|
|
|
|
// Ken Silverman's official web site: "http://www.advsys.net/ken"
|
|
|
|
// See the included license file "BUILDLIC.TXT" for license info.
|
|
|
|
//
|
|
|
|
// This file has been modified from Ken Silverman's original release
|
|
|
|
// by Jonathon Fowler (jf@jonof.id.au)
|
|
|
|
// by the EDuke32 team (development@voidpoint.com)
|
2016-06-21 00:34:25 +00:00
|
|
|
|
|
|
|
#include "compat.h"
|
|
|
|
#include "build.h"
|
2016-09-16 21:55:21 +00:00
|
|
|
#include "baselayer.h"
|
2016-06-21 00:34:25 +00:00
|
|
|
#include "engine_priv.h"
|
|
|
|
#include "cache1d.h"
|
|
|
|
#include "lz4.h"
|
2019-09-22 21:15:46 +00:00
|
|
|
#include "crc32_.h"
|
2016-06-21 00:34:25 +00:00
|
|
|
|
2019-03-01 08:51:50 +00:00
|
|
|
#include "vfs.h"
|
|
|
|
|
2016-06-21 00:34:25 +00:00
|
|
|
void *pic = NULL;
|
|
|
|
|
|
|
|
// The tile file number (tilesXXX <- this) of each tile:
|
|
|
|
// 0 <= . < MAXARTFILES_BASE: tile is in a "base" ART file
|
|
|
|
// MAXARTFILES_BASE <= . < MAXARTFILES_TOTAL: tile is in a map-specific ART file
|
|
|
|
static uint8_t tilefilenum[MAXTILES];
|
|
|
|
EDUKE32_STATIC_ASSERT(MAXARTFILES_TOTAL <= 256);
|
|
|
|
|
|
|
|
static int32_t tilefileoffs[MAXTILES];
|
|
|
|
|
|
|
|
// Backup tilefilenum[] and tilefileoffs[]. These get allocated only when
|
|
|
|
// necessary (have per-map ART files).
|
|
|
|
static uint8_t *g_bakTileFileNum;
|
|
|
|
static int32_t *g_bakTileFileOffs;
|
2019-06-25 11:28:09 +00:00
|
|
|
static vec2_16_t *g_bakTileSiz;
|
2019-08-07 16:19:03 +00:00
|
|
|
static char *g_bakPicSiz;
|
|
|
|
static char *g_bakWalock;
|
|
|
|
static intptr_t *g_bakWaloff;
|
2016-06-21 00:34:25 +00:00
|
|
|
static picanm_t *g_bakPicAnm;
|
2018-02-11 05:03:46 +00:00
|
|
|
static char * g_bakFakeTile;
|
|
|
|
static char ** g_bakFakeTileData;
|
2016-06-21 00:34:25 +00:00
|
|
|
// NOTE: picsiz[] is not backed up, but recalculated when necessary.
|
|
|
|
|
|
|
|
//static int32_t artsize = 0;
|
|
|
|
static int32_t cachesize = 0;
|
|
|
|
|
2019-09-19 20:02:45 +00:00
|
|
|
static char artfilename[BMAX_PATH];
|
|
|
|
static char artfilenameformat[BMAX_PATH];
|
2016-06-21 00:34:25 +00:00
|
|
|
static char mapartfilename[BMAX_PATH]; // map-specific ART file name
|
|
|
|
static int32_t mapartfnXXofs; // byte offset to 'XX' (the number part) in the above
|
2019-03-01 08:51:50 +00:00
|
|
|
static int32_t artfilnum, artfilplc;
|
|
|
|
static buildvfs_kfd artfil;
|
2016-06-21 00:34:25 +00:00
|
|
|
|
|
|
|
////////// Per-map ART file loading //////////
|
|
|
|
|
|
|
|
// Some forward declarations.
|
2018-04-12 21:03:30 +00:00
|
|
|
static const char *artGetIndexedFileName(int32_t tilefilei);
|
|
|
|
static int32_t artReadIndexedFile(int32_t tilefilei);
|
2016-06-21 00:34:25 +00:00
|
|
|
|
2018-04-12 21:03:30 +00:00
|
|
|
static inline void artClearMapArtFilename(void)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
|
|
|
Bmemset(mapartfilename, 0, sizeof(mapartfilename));
|
|
|
|
mapartfnXXofs = 0;
|
|
|
|
}
|
|
|
|
|
2018-04-12 21:03:30 +00:00
|
|
|
static inline void artUpdateManifest(void)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
2016-08-27 01:41:21 +00:00
|
|
|
for (bssize_t i=0; i<MAXTILES; i++)
|
2018-04-12 21:03:30 +00:00
|
|
|
tileUpdatePicSiz(i);
|
2016-06-21 00:34:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename origar_t, typename bakar_t>
|
2018-02-11 05:03:46 +00:00
|
|
|
static inline void RESTORE_MAPART_ARRAY(origar_t & origar, bakar_t & bakar)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
2018-02-11 05:03:46 +00:00
|
|
|
EDUKE32_STATIC_ASSERT(sizeof(origar[0]) == sizeof(bakar[0]));
|
|
|
|
Bmemcpy(origar, bakar, ARRAY_SIZE(origar) * sizeof(origar[0]));
|
|
|
|
DO_FREE_AND_NULL(bakar);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename origar_t, typename bakar_t>
|
|
|
|
static inline void ALLOC_MAPART_ARRAY(origar_t & origar, bakar_t & bakar)
|
|
|
|
{
|
|
|
|
bakar = (bakar_t) Xmalloc(ARRAY_SIZE(origar) * sizeof(origar[0]));
|
|
|
|
Bmemcpy(bakar, origar, ARRAY_SIZE(origar) * sizeof(origar[0]));
|
2016-06-21 00:34:25 +00:00
|
|
|
}
|
|
|
|
|
2018-04-12 21:03:30 +00:00
|
|
|
void artClearMapArt(void)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
|
|
|
if (g_bakTileFileNum == NULL)
|
|
|
|
return; // per-map ART N/A
|
|
|
|
|
2018-04-12 21:03:30 +00:00
|
|
|
artClearMapArtFilename();
|
2016-06-21 00:34:25 +00:00
|
|
|
|
|
|
|
if (artfilnum >= MAXARTFILES_BASE)
|
|
|
|
{
|
|
|
|
kclose(artfil);
|
|
|
|
|
2019-03-01 08:51:50 +00:00
|
|
|
artfil = buildvfs_kfd_invalid;
|
2016-06-21 00:34:25 +00:00
|
|
|
artfilnum = -1;
|
|
|
|
artfilplc = 0L;
|
|
|
|
}
|
|
|
|
|
2016-08-27 01:41:21 +00:00
|
|
|
for (bssize_t i=0; i<MAXTILES; i++)
|
2016-06-21 00:34:29 +00:00
|
|
|
{
|
2016-06-21 00:34:25 +00:00
|
|
|
if (tilefilenum[i] >= MAXARTFILES_BASE)
|
|
|
|
{
|
|
|
|
// XXX: OK way to free it? Better: cache1d API. CACHE1D_FREE
|
|
|
|
walock[i] = 1;
|
|
|
|
waloff[i] = 0;
|
|
|
|
}
|
2016-06-21 00:34:29 +00:00
|
|
|
}
|
2016-06-21 00:34:25 +00:00
|
|
|
|
|
|
|
// Restore original per-tile arrays
|
|
|
|
RESTORE_MAPART_ARRAY(tilefilenum, g_bakTileFileNum);
|
|
|
|
RESTORE_MAPART_ARRAY(tilefileoffs, g_bakTileFileOffs);
|
|
|
|
RESTORE_MAPART_ARRAY(tilesiz, g_bakTileSiz);
|
2019-08-07 16:19:03 +00:00
|
|
|
RESTORE_MAPART_ARRAY(picsiz, g_bakPicSiz);
|
|
|
|
RESTORE_MAPART_ARRAY(walock, g_bakWalock);
|
|
|
|
RESTORE_MAPART_ARRAY(waloff, g_bakWaloff);
|
2016-06-21 00:34:25 +00:00
|
|
|
RESTORE_MAPART_ARRAY(picanm, g_bakPicAnm);
|
2018-02-11 05:03:46 +00:00
|
|
|
RESTORE_MAPART_ARRAY(faketile, g_bakFakeTile);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < MAXUSERTILES; ++i)
|
|
|
|
{
|
|
|
|
if (faketiledata[i] != g_bakFakeTileData[i])
|
|
|
|
{
|
|
|
|
free(faketiledata[i]);
|
|
|
|
faketiledata[i] = g_bakFakeTileData[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DO_FREE_AND_NULL(g_bakFakeTileData);
|
2016-06-21 00:34:25 +00:00
|
|
|
|
2018-04-12 21:03:30 +00:00
|
|
|
artUpdateManifest();
|
2016-06-21 00:34:25 +00:00
|
|
|
#ifdef USE_OPENGL
|
2018-03-21 20:41:26 +00:00
|
|
|
//POGOTODO: review this to ensure we're not invalidating more than we have to
|
2016-06-21 00:34:25 +00:00
|
|
|
gltexinvalidatetype(INVALIDATE_ART);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-04-12 21:03:30 +00:00
|
|
|
void artSetupMapArt(const char *filename)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
2018-04-12 21:03:30 +00:00
|
|
|
artClearMapArt();
|
2016-06-21 00:34:25 +00:00
|
|
|
|
|
|
|
if (Bstrlen(filename) + 7 >= sizeof(mapartfilename))
|
|
|
|
return;
|
|
|
|
|
|
|
|
Bstrcpy(mapartfilename, filename);
|
|
|
|
append_ext_UNSAFE(mapartfilename, "_XX.art");
|
|
|
|
mapartfnXXofs = Bstrlen(mapartfilename) - 6;
|
|
|
|
|
|
|
|
// Check for first per-map ART file: if that one doesn't exist, don't load any.
|
2019-03-01 08:51:50 +00:00
|
|
|
buildvfs_kfd fil = kopen4load(artGetIndexedFileName(MAXARTFILES_BASE), 0);
|
2016-06-21 00:34:25 +00:00
|
|
|
|
2019-03-01 08:51:50 +00:00
|
|
|
if (fil == buildvfs_kfd_invalid)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
2018-04-12 21:03:30 +00:00
|
|
|
artClearMapArtFilename();
|
2016-06-21 00:34:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
kclose(fil);
|
|
|
|
|
|
|
|
// Allocate backup arrays.
|
|
|
|
ALLOC_MAPART_ARRAY(tilefilenum, g_bakTileFileNum);
|
|
|
|
ALLOC_MAPART_ARRAY(tilefileoffs, g_bakTileFileOffs);
|
|
|
|
ALLOC_MAPART_ARRAY(tilesiz, g_bakTileSiz);
|
2019-08-07 16:19:03 +00:00
|
|
|
ALLOC_MAPART_ARRAY(picsiz, g_bakPicSiz);
|
|
|
|
ALLOC_MAPART_ARRAY(walock, g_bakWalock);
|
|
|
|
ALLOC_MAPART_ARRAY(waloff, g_bakWaloff);
|
2016-06-21 00:34:25 +00:00
|
|
|
ALLOC_MAPART_ARRAY(picanm, g_bakPicAnm);
|
2018-02-11 05:03:46 +00:00
|
|
|
ALLOC_MAPART_ARRAY(faketile, g_bakFakeTile);
|
|
|
|
ALLOC_MAPART_ARRAY(faketiledata, g_bakFakeTileData);
|
2016-06-21 00:34:25 +00:00
|
|
|
|
2016-08-27 01:41:21 +00:00
|
|
|
for (bssize_t i=MAXARTFILES_BASE; i<MAXARTFILES_TOTAL; i++)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
2018-04-12 21:03:30 +00:00
|
|
|
int ret = artReadIndexedFile(i);
|
2016-06-21 00:34:25 +00:00
|
|
|
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
|
|
|
// NOTE: i == MAXARTFILES_BASE && ret == -1 can only have happened
|
|
|
|
// if the file was deleted between the above file existence check
|
|
|
|
// and now. Very cornerly... but I like my code to be prepared to
|
|
|
|
// any eventuality.
|
|
|
|
if (i == MAXARTFILES_BASE || ret != -1)
|
2018-04-12 21:03:30 +00:00
|
|
|
artClearMapArt();
|
2016-06-21 00:34:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-12 21:03:30 +00:00
|
|
|
artUpdateManifest();
|
2016-06-21 00:34:25 +00:00
|
|
|
#ifdef USE_OPENGL
|
2018-03-21 20:41:26 +00:00
|
|
|
//POGOTODO: review this to ensure we're not invalidating more than we have to
|
2016-06-21 00:34:25 +00:00
|
|
|
gltexinvalidatetype(INVALIDATE_ART);
|
|
|
|
# ifdef POLYMER
|
2018-04-12 21:03:12 +00:00
|
|
|
if (videoGetRenderMode() == REND_POLYMER)
|
2016-06-21 00:34:25 +00:00
|
|
|
polymer_texinvalidate();
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// ART loading
|
|
|
|
//
|
|
|
|
|
2018-04-12 21:03:30 +00:00
|
|
|
void tileSetupDummy(int32_t const tile)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
|
|
|
faketile[tile>>3] |= pow2char[tile&7];
|
|
|
|
DO_FREE_AND_NULL(faketiledata[tile]);
|
|
|
|
}
|
|
|
|
|
2018-04-12 21:03:30 +00:00
|
|
|
static void tileSetDataSafe(int32_t const tile, int32_t tsiz, char const * const buffer)
|
2018-02-11 05:03:46 +00:00
|
|
|
{
|
|
|
|
int const compressed_tsiz = LZ4_compressBound(tsiz);
|
|
|
|
char * newtile = (char *) Xmalloc(compressed_tsiz);
|
|
|
|
|
|
|
|
if ((tsiz = LZ4_compress_default(buffer, newtile, tsiz, compressed_tsiz)) != -1)
|
|
|
|
{
|
|
|
|
faketiledata[tile] = (char *) Xrealloc(newtile, tsiz);
|
|
|
|
faketile[tile>>3] |= pow2char[tile&7];
|
|
|
|
tilefilenum[tile] = MAXARTFILES_TOTAL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
free(newtile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-12 21:03:30 +00:00
|
|
|
void tileSetData(int32_t const tile, int32_t tsiz, char const * const buffer)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
2017-06-14 07:00:08 +00:00
|
|
|
int const compressed_tsiz = LZ4_compressBound(tsiz);
|
|
|
|
faketiledata[tile] = (char *) Xrealloc(faketiledata[tile], compressed_tsiz);
|
2016-06-21 00:34:25 +00:00
|
|
|
|
2017-06-14 07:00:08 +00:00
|
|
|
if ((tsiz = LZ4_compress_default(buffer, faketiledata[tile], tsiz, compressed_tsiz)) != -1)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
|
|
|
faketiledata[tile] = (char *) Xrealloc(faketiledata[tile], tsiz);
|
|
|
|
faketile[tile>>3] |= pow2char[tile&7];
|
2018-02-11 05:03:46 +00:00
|
|
|
tilefilenum[tile] = MAXARTFILES_TOTAL;
|
2016-06-21 00:34:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DO_FREE_AND_NULL(faketiledata[tile]);
|
|
|
|
faketile[tile>>3] &= ~pow2char[tile&7];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-12 21:03:30 +00:00
|
|
|
static void tileSoftDelete(int32_t const tile)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
|
|
|
tilesiz[tile].x = 0;
|
|
|
|
tilesiz[tile].y = 0;
|
|
|
|
picsiz[tile] = 0;
|
|
|
|
|
|
|
|
// CACHE1D_FREE
|
|
|
|
walock[tile] = 1;
|
|
|
|
waloff[tile] = 0;
|
|
|
|
|
|
|
|
faketile[tile>>3] &= ~pow2char[tile&7];
|
2019-10-08 17:46:39 +00:00
|
|
|
picanm[tile].Clear();
|
2018-02-11 05:03:46 +00:00
|
|
|
}
|
|
|
|
|
2018-04-12 21:03:30 +00:00
|
|
|
void tileDelete(int32_t const tile)
|
2018-02-11 05:03:46 +00:00
|
|
|
{
|
2018-04-12 21:03:30 +00:00
|
|
|
tileSoftDelete(tile);
|
2018-02-11 05:03:46 +00:00
|
|
|
|
|
|
|
DO_FREE_AND_NULL(faketiledata[tile]);
|
2016-10-25 05:43:53 +00:00
|
|
|
|
|
|
|
vox_undefine(tile);
|
|
|
|
|
|
|
|
#ifdef USE_OPENGL
|
|
|
|
for (ssize_t i=MAXPALOOKUPS-1; i>=0; --i)
|
|
|
|
hicclearsubst(tile, i);
|
|
|
|
|
|
|
|
md_undefinetile(tile);
|
|
|
|
#endif
|
2016-06-21 00:34:25 +00:00
|
|
|
}
|
|
|
|
|
2019-09-19 22:42:45 +00:00
|
|
|
void tileUpdatePicSiz(int32_t picnum)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
|
|
|
int j = 15;
|
|
|
|
|
|
|
|
while ((j > 1) && (pow2long[j] > tilesiz[picnum].x))
|
|
|
|
j--;
|
|
|
|
picsiz[picnum] = j;
|
|
|
|
|
|
|
|
j = 15;
|
|
|
|
while ((j > 1) && (pow2long[j] > tilesiz[picnum].y))
|
|
|
|
j--;
|
|
|
|
picsiz[picnum] |= j<<4;
|
|
|
|
}
|
|
|
|
|
2018-04-12 21:03:30 +00:00
|
|
|
void tileSetSize(int32_t picnum, int16_t dasizx, int16_t dasizy)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
|
|
|
tilesiz[picnum].x = dasizx;
|
|
|
|
tilesiz[picnum].y = dasizy;
|
|
|
|
|
2018-04-12 21:03:30 +00:00
|
|
|
tileUpdatePicSiz(picnum);
|
2016-06-21 00:34:25 +00:00
|
|
|
}
|
|
|
|
|
2019-03-01 08:51:50 +00:00
|
|
|
int32_t artReadHeader(buildvfs_kfd const fil, char const * const fn, artheader_t * const local)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
|
|
|
int32_t artversion;
|
|
|
|
kread(fil, &artversion, 4); artversion = B_LITTLE32(artversion);
|
2019-08-14 09:02:54 +00:00
|
|
|
|
|
|
|
if (artversion == B_LITTLE32(0x4c495542))
|
|
|
|
{
|
|
|
|
kread(fil, &artversion, 4); artversion = B_LITTLE32(artversion);
|
|
|
|
if (artversion == B_LITTLE32(0x54524144))
|
|
|
|
{
|
|
|
|
kread(fil, &artversion, 4); artversion = B_LITTLE32(artversion);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
initprintf("loadpics: Invalid art file, %s\n", fn);
|
|
|
|
kclose(fil);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 00:34:25 +00:00
|
|
|
if (artversion != 1)
|
|
|
|
{
|
|
|
|
initprintf("loadpics: Invalid art file version in %s\n", fn);
|
|
|
|
kclose(fil);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t numtiles_dummy;
|
|
|
|
kread(fil, &numtiles_dummy, 4);
|
|
|
|
|
|
|
|
kread(fil, &local->tilestart, 4); local->tilestart = B_LITTLE32(local->tilestart);
|
|
|
|
kread(fil, &local->tileend, 4); local->tileend = B_LITTLE32(local->tileend);
|
|
|
|
|
|
|
|
if ((uint32_t) local->tilestart >= MAXUSERTILES || (uint32_t) local->tileend >= MAXUSERTILES)
|
|
|
|
{
|
|
|
|
initprintf("loadpics: Invalid localtilestart or localtileend in %s\n", fn);
|
|
|
|
kclose(fil);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (local->tileend < local->tilestart)
|
|
|
|
{
|
|
|
|
initprintf("loadpics: localtileend < localtilestart in %s\n", fn);
|
|
|
|
kclose(fil);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
local->numtiles = (local->tileend-local->tilestart+1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-12 21:03:30 +00:00
|
|
|
int32_t artReadHeaderFromBuffer(uint8_t const * const buf, artheader_t * const local)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
2016-06-21 00:34:29 +00:00
|
|
|
int const artversion = B_LITTLE32(B_UNBUF32(&buf[0]));
|
2016-06-21 00:34:25 +00:00
|
|
|
if (EDUKE32_PREDICT_FALSE(artversion != 1))
|
|
|
|
{
|
|
|
|
initprintf("loadpics: Invalid art file version\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
local->tilestart = B_LITTLE32(B_UNBUF32(&buf[8]));
|
|
|
|
local->tileend = B_LITTLE32(B_UNBUF32(&buf[12]));
|
|
|
|
|
|
|
|
if (EDUKE32_PREDICT_FALSE((unsigned) local->tilestart >= MAXUSERTILES || (unsigned) local->tileend >= MAXUSERTILES))
|
|
|
|
{
|
|
|
|
initprintf("loadpics: Invalid localtilestart or localtileend\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (EDUKE32_PREDICT_FALSE(local->tileend < local->tilestart))
|
|
|
|
{
|
|
|
|
initprintf("loadpics: localtileend < localtilestart\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
local->numtiles = (local->tileend-local->tilestart+1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-12 21:03:30 +00:00
|
|
|
int32_t artCheckUnitFileHeader(uint8_t const * const buf, int32_t length)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
|
|
|
if (EDUKE32_PREDICT_FALSE(length <= ARTv1_UNITOFFSET))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
artheader_t local;
|
2018-04-12 21:03:30 +00:00
|
|
|
if (EDUKE32_PREDICT_FALSE(artReadHeaderFromBuffer(buf, &local) != 0))
|
2016-06-21 00:34:25 +00:00
|
|
|
return -2;
|
|
|
|
|
|
|
|
if (EDUKE32_PREDICT_FALSE(local.numtiles != 1))
|
|
|
|
return -3;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-09-19 21:02:57 +00:00
|
|
|
void tileConvertAnimFormat(int32_t const picnum, int32_t const picanmdisk)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
2019-09-19 21:02:57 +00:00
|
|
|
EDUKE32_STATIC_ASSERT(PICANM_ANIMTYPE_MASK == 192);
|
|
|
|
|
|
|
|
// Unpack a 4 byte packed anim descriptor into the internal 5 byte format.
|
|
|
|
picanm_t* const thispicanm = &picanm[picnum];
|
|
|
|
thispicanm->num = picanmdisk & 63;
|
|
|
|
thispicanm->xofs = (picanmdisk >> 8) & 255;
|
|
|
|
thispicanm->yofs = (picanmdisk >> 16) & 255;
|
|
|
|
thispicanm->sf = ((picanmdisk >> 24) & 15) | (picanmdisk & 192);
|
|
|
|
thispicanm->extra = (picanmdisk >> 28) & 15;
|
2016-06-21 00:34:25 +00:00
|
|
|
}
|
|
|
|
|
2019-09-19 21:02:57 +00:00
|
|
|
void artReadManifest(int32_t const fil, artheader_t const* const local)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
2019-09-19 21:02:57 +00:00
|
|
|
int16_t* tilesizx = (int16_t*)Xmalloc(local->numtiles * sizeof(int16_t));
|
|
|
|
int16_t* tilesizy = (int16_t*)Xmalloc(local->numtiles * sizeof(int16_t));
|
|
|
|
kread(fil, tilesizx, local->numtiles * sizeof(int16_t));
|
|
|
|
kread(fil, tilesizy, local->numtiles * sizeof(int16_t));
|
2016-06-21 00:34:25 +00:00
|
|
|
|
2019-09-19 21:02:57 +00:00
|
|
|
for (bssize_t i = local->tilestart; i <= local->tileend; i++)
|
|
|
|
{
|
|
|
|
int32_t picanmdisk;
|
2016-06-21 00:34:25 +00:00
|
|
|
|
2019-09-19 21:02:57 +00:00
|
|
|
tilesiz[i].x = B_LITTLE16(tilesizx[i - local->tilestart]);
|
|
|
|
tilesiz[i].y = B_LITTLE16(tilesizy[i - local->tilestart]);
|
2016-06-21 00:34:25 +00:00
|
|
|
|
2019-09-19 21:02:57 +00:00
|
|
|
kread(fil, &picanmdisk, sizeof(int32_t));
|
|
|
|
picanmdisk = B_LITTLE32(picanmdisk);
|
|
|
|
|
|
|
|
tileConvertAnimFormat(i, picanmdisk);
|
|
|
|
}
|
|
|
|
|
|
|
|
DO_FREE_AND_NULL(tilesizx);
|
|
|
|
DO_FREE_AND_NULL(tilesizy);
|
2016-06-21 00:34:25 +00:00
|
|
|
}
|
|
|
|
|
2019-03-01 08:51:50 +00:00
|
|
|
void artPreloadFile(buildvfs_kfd const fil, artheader_t const * const local)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
|
|
|
char *buffer = NULL;
|
|
|
|
int32_t buffersize = 0;
|
|
|
|
|
2016-08-27 01:41:21 +00:00
|
|
|
for (bssize_t i=local->tilestart; i<=local->tileend; i++)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
2016-06-21 00:34:29 +00:00
|
|
|
int const dasiz = tilesiz[i].x * tilesiz[i].y;
|
2016-06-21 00:34:25 +00:00
|
|
|
|
|
|
|
if (dasiz == 0)
|
|
|
|
{
|
2018-04-12 21:03:30 +00:00
|
|
|
tileDelete(i);
|
2016-06-21 00:34:25 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
maybe_grow_buffer(&buffer, &buffersize, dasiz);
|
|
|
|
kread(fil, buffer, dasiz);
|
2018-04-12 21:03:30 +00:00
|
|
|
tileSetData(i, dasiz, buffer);
|
2016-06-21 00:34:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DO_FREE_AND_NULL(buffer);
|
|
|
|
}
|
|
|
|
|
2019-03-01 08:51:50 +00:00
|
|
|
static void artPreloadFileSafe(buildvfs_kfd const fil, artheader_t const * const local)
|
2018-02-11 05:03:46 +00:00
|
|
|
{
|
|
|
|
char *buffer = NULL;
|
|
|
|
int32_t buffersize = 0;
|
|
|
|
|
|
|
|
for (bssize_t i=local->tilestart; i<=local->tileend; i++)
|
|
|
|
{
|
|
|
|
int const dasiz = tilesiz[i].x * tilesiz[i].y;
|
|
|
|
|
|
|
|
if (dasiz == 0)
|
|
|
|
{
|
2018-04-12 21:03:30 +00:00
|
|
|
tileSoftDelete(i);
|
2018-02-11 05:03:46 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
maybe_grow_buffer(&buffer, &buffersize, dasiz);
|
|
|
|
kread(fil, buffer, dasiz);
|
2018-04-12 21:03:30 +00:00
|
|
|
tileSetDataSafe(i, dasiz, buffer);
|
2018-02-11 05:03:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DO_FREE_AND_NULL(buffer);
|
|
|
|
}
|
|
|
|
|
2018-04-12 21:03:30 +00:00
|
|
|
static const char *artGetIndexedFileName(int32_t tilefilei)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
|
|
|
if (tilefilei >= MAXARTFILES_BASE)
|
|
|
|
{
|
|
|
|
int32_t o = mapartfnXXofs;
|
|
|
|
tilefilei -= MAXARTFILES_BASE;
|
|
|
|
|
|
|
|
mapartfilename[o+1] = '0' + tilefilei%10;
|
|
|
|
mapartfilename[o+0] = '0' + (tilefilei/10)%10;
|
|
|
|
|
|
|
|
return mapartfilename;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-19 20:02:45 +00:00
|
|
|
Bsnprintf(artfilename, sizeof(artfilename), artfilenameformat, tilefilei);
|
2016-06-21 00:34:25 +00:00
|
|
|
|
|
|
|
return artfilename;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-19 20:02:45 +00:00
|
|
|
|
|
|
|
|
2016-06-21 00:34:25 +00:00
|
|
|
// Returns:
|
|
|
|
// 0: successfully read ART file
|
|
|
|
// >0: error with the ART file
|
|
|
|
// -1: ART file does not exist
|
|
|
|
//<-1: per-map ART issue
|
2018-04-12 21:03:30 +00:00
|
|
|
static int32_t artReadIndexedFile(int32_t tilefilei)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
2018-04-12 21:03:30 +00:00
|
|
|
const char *fn = artGetIndexedFileName(tilefilei);
|
2016-06-21 00:34:25 +00:00
|
|
|
const int32_t permap = (tilefilei >= MAXARTFILES_BASE); // is it a per-map ART file?
|
2019-03-01 08:51:50 +00:00
|
|
|
buildvfs_kfd fil;
|
2016-06-21 00:34:25 +00:00
|
|
|
|
2019-10-08 17:46:39 +00:00
|
|
|
if ((fil = kopen4loadfrommod(fn, 0)) != buildvfs_kfd_invalid)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
|
|
|
artheader_t local;
|
2018-04-12 21:03:30 +00:00
|
|
|
int const headerval = artReadHeader(fil, fn, &local);
|
2016-06-21 00:34:25 +00:00
|
|
|
if (headerval != 0)
|
2017-12-18 23:36:05 +00:00
|
|
|
{
|
2017-12-19 00:03:12 +00:00
|
|
|
kclose(fil);
|
2016-06-21 00:34:25 +00:00
|
|
|
return headerval;
|
2017-12-18 23:36:05 +00:00
|
|
|
}
|
2016-06-21 00:34:25 +00:00
|
|
|
|
|
|
|
if (permap)
|
|
|
|
{
|
|
|
|
// Check whether we can evict existing tiles to make place for
|
|
|
|
// per-map ART ones.
|
2016-08-29 19:11:47 +00:00
|
|
|
for (int i=local.tilestart; i<=local.tileend; i++)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
|
|
|
// Tiles having dummytile replacements or those that are
|
|
|
|
// cache1d-locked can't be replaced.
|
|
|
|
if (faketile[i>>3] & pow2char[i&7] || walock[i] >= 200)
|
|
|
|
{
|
|
|
|
initprintf("loadpics: per-map ART file \"%s\": "
|
2016-08-29 19:11:47 +00:00
|
|
|
"tile %d has dummytile or is locked\n", fn, i);
|
2016-06-21 00:34:25 +00:00
|
|
|
kclose(fil);
|
|
|
|
return -3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Free existing tiles from the cache1d. CACHE1D_FREE
|
|
|
|
Bmemset(&waloff[local.tilestart], 0, local.numtiles*sizeof(intptr_t));
|
|
|
|
Bmemset(&walock[local.tilestart], 1, local.numtiles*sizeof(walock[0]));
|
|
|
|
}
|
|
|
|
|
2018-04-12 21:03:30 +00:00
|
|
|
artReadManifest(fil, &local);
|
2016-06-21 00:34:25 +00:00
|
|
|
|
|
|
|
if (cache1d_file_fromzip(fil))
|
|
|
|
{
|
2018-02-11 05:03:46 +00:00
|
|
|
if (permap)
|
2018-04-12 21:03:30 +00:00
|
|
|
artPreloadFileSafe(fil, &local);
|
2018-02-11 05:03:46 +00:00
|
|
|
else
|
2018-04-12 21:03:30 +00:00
|
|
|
artPreloadFile(fil, &local);
|
2016-06-21 00:34:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-03-09 02:51:24 +00:00
|
|
|
int offscount = ktell(fil);
|
2016-06-21 00:34:25 +00:00
|
|
|
|
2016-08-27 01:41:21 +00:00
|
|
|
for (bssize_t i=local.tilestart; i<=local.tileend; ++i)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
2016-06-21 00:34:29 +00:00
|
|
|
int const dasiz = tilesiz[i].x * tilesiz[i].y;
|
2016-06-21 00:34:25 +00:00
|
|
|
|
|
|
|
tilefilenum[i] = tilefilei;
|
|
|
|
tilefileoffs[i] = offscount;
|
|
|
|
|
|
|
|
offscount += dasiz;
|
|
|
|
// artsize += ((dasiz+15)&0xfffffff0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
kclose(fil);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// loadpics
|
|
|
|
//
|
2018-04-12 21:03:30 +00:00
|
|
|
int32_t artLoadFiles(const char *filename, int32_t askedsize)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
2019-09-19 20:02:45 +00:00
|
|
|
Bstrncpyz(artfilenameformat, filename, sizeof(artfilenameformat));
|
2016-06-21 00:34:25 +00:00
|
|
|
|
2019-06-25 11:28:09 +00:00
|
|
|
Bmemset(&tilesiz[0], 0, sizeof(vec2_16_t) * MAXTILES);
|
2016-06-21 00:34:25 +00:00
|
|
|
Bmemset(picanm, 0, sizeof(picanm));
|
|
|
|
|
2018-12-15 01:37:19 +00:00
|
|
|
for (auto &rot : rottile)
|
|
|
|
rot = { -1, -1 };
|
|
|
|
|
2016-06-21 00:34:25 +00:00
|
|
|
// artsize = 0;
|
|
|
|
|
2018-12-15 01:37:19 +00:00
|
|
|
for (int tilefilei=0; tilefilei<MAXARTFILES_BASE; tilefilei++)
|
2018-04-12 21:03:30 +00:00
|
|
|
artReadIndexedFile(tilefilei);
|
2016-06-21 00:34:25 +00:00
|
|
|
|
|
|
|
Bmemset(gotpic, 0, sizeof(gotpic));
|
|
|
|
|
|
|
|
//cachesize = min((int32_t)((Bgetsysmemsize()/100)*60),max(artsize,askedsize));
|
2016-09-06 02:15:37 +00:00
|
|
|
cachesize = (Bgetsysmemsize() <= (uint32_t)askedsize) ? (int32_t)((Bgetsysmemsize() / 100) * 60) : askedsize;
|
2019-09-02 05:55:32 +00:00
|
|
|
pic = Xaligned_alloc(Bgetpagesize(), cachesize);
|
2018-04-12 21:03:30 +00:00
|
|
|
cacheInitBuffer((intptr_t) pic, cachesize);
|
2016-06-21 00:34:25 +00:00
|
|
|
|
2018-04-12 21:03:30 +00:00
|
|
|
artUpdateManifest();
|
2016-06-21 00:34:25 +00:00
|
|
|
|
2019-03-01 08:51:50 +00:00
|
|
|
artfil = buildvfs_kfd_invalid;
|
2016-06-21 00:34:25 +00:00
|
|
|
artfilnum = -1;
|
|
|
|
artfilplc = 0L;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// loadtile
|
|
|
|
//
|
|
|
|
|
2018-04-12 21:03:30 +00:00
|
|
|
bool tileLoad(int16_t tileNum)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
2018-04-12 21:03:30 +00:00
|
|
|
if ((unsigned) tileNum >= (unsigned) MAXTILES) return 0;
|
|
|
|
int const dasiz = tilesiz[tileNum].x*tilesiz[tileNum].y;
|
|
|
|
if (dasiz <= 0) return 0;
|
2016-06-21 00:34:25 +00:00
|
|
|
|
|
|
|
// Allocate storage if necessary.
|
2018-04-12 21:03:30 +00:00
|
|
|
if (waloff[tileNum] == 0)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
2018-04-12 21:03:30 +00:00
|
|
|
walock[tileNum] = 199;
|
|
|
|
cacheAllocateBlock(&waloff[tileNum], dasiz, &walock[tileNum]);
|
2016-06-21 00:34:25 +00:00
|
|
|
}
|
|
|
|
|
2018-04-12 21:03:30 +00:00
|
|
|
tileLoadData(tileNum, dasiz, (char *) waloff[tileNum]);
|
2016-06-21 00:34:25 +00:00
|
|
|
|
2018-04-12 21:03:30 +00:00
|
|
|
|
|
|
|
return (waloff[tileNum] != 0 && tilesiz[tileNum].x > 0 && tilesiz[tileNum].y > 0);
|
2016-06-21 00:34:25 +00:00
|
|
|
}
|
|
|
|
|
2018-11-18 18:13:48 +00:00
|
|
|
void tileMaybeRotate(int16_t tilenume)
|
|
|
|
{
|
|
|
|
auto &rot = rottile[tilenume];
|
|
|
|
auto &siz = tilesiz[rot.owner];
|
|
|
|
|
|
|
|
auto src = (char *)waloff[rot.owner];
|
|
|
|
auto dst = (char *)waloff[tilenume];
|
|
|
|
|
|
|
|
// the engine has a squarerotatetile() we could call, but it mirrors at the same time
|
|
|
|
for (int x = 0; x < siz.x; ++x)
|
|
|
|
{
|
|
|
|
int const xofs = siz.x - x - 1;
|
|
|
|
int const yofs = siz.y * x;
|
|
|
|
|
|
|
|
for (int y = 0; y < siz.y; ++y)
|
|
|
|
*(dst + y * siz.x + xofs) = *(src + y + yofs);
|
|
|
|
}
|
|
|
|
|
|
|
|
tileSetSize(tilenume, siz.y, siz.x);
|
|
|
|
}
|
|
|
|
|
2018-04-12 21:03:30 +00:00
|
|
|
void tileLoadData(int16_t tilenume, int32_t dasiz, char *buffer)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
2018-11-18 18:13:48 +00:00
|
|
|
int const owner = rottile[tilenume].owner;
|
2016-06-21 00:34:25 +00:00
|
|
|
|
2018-11-18 21:17:59 +00:00
|
|
|
if (owner != -1)
|
2018-11-18 18:13:48 +00:00
|
|
|
{
|
|
|
|
if (!waloff[owner])
|
|
|
|
tileLoad(owner);
|
|
|
|
|
2019-03-30 19:36:25 +00:00
|
|
|
if (waloff[tilenume])
|
|
|
|
tileMaybeRotate(tilenume);
|
|
|
|
|
2018-11-18 18:13:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int const tfn = tilefilenum[tilenume];
|
|
|
|
|
|
|
|
// dummy tiles for highres replacements and tilefromtexture definitions
|
2016-06-21 00:34:25 +00:00
|
|
|
if (faketile[tilenume>>3] & pow2char[tilenume&7])
|
|
|
|
{
|
|
|
|
if (faketiledata[tilenume] != NULL)
|
|
|
|
LZ4_decompress_fast(faketiledata[tilenume], buffer, dasiz);
|
|
|
|
|
|
|
|
faketimerhandler();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Potentially switch open ART file.
|
2016-06-21 00:34:29 +00:00
|
|
|
if (tfn != artfilnum)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
2019-03-01 08:51:50 +00:00
|
|
|
if (artfil != buildvfs_kfd_invalid)
|
2016-06-21 00:34:25 +00:00
|
|
|
kclose(artfil);
|
|
|
|
|
2018-04-12 21:03:30 +00:00
|
|
|
char const *fn = artGetIndexedFileName(tfn);
|
2016-06-21 00:34:25 +00:00
|
|
|
|
2019-09-21 11:02:17 +00:00
|
|
|
auto kopen4loadfunc = bloodhack == 2 ? kopen4loadfrommod : kopen4load;
|
2019-09-19 21:02:57 +00:00
|
|
|
|
|
|
|
artfil = kopen4loadfunc(fn, 0);
|
2016-06-21 00:34:29 +00:00
|
|
|
|
2019-03-01 08:51:50 +00:00
|
|
|
if (artfil == buildvfs_kfd_invalid)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
|
|
|
initprintf("Failed opening ART file \"%s\"!\n", fn);
|
2018-04-12 21:03:47 +00:00
|
|
|
engineUnInit();
|
2016-06-21 00:34:25 +00:00
|
|
|
Bexit(11);
|
|
|
|
}
|
|
|
|
|
2016-06-21 00:34:29 +00:00
|
|
|
artfilnum = tfn;
|
2016-06-21 00:34:25 +00:00
|
|
|
artfilplc = 0L;
|
|
|
|
|
|
|
|
faketimerhandler();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Seek to the right position.
|
|
|
|
if (artfilplc != tilefileoffs[tilenume])
|
|
|
|
{
|
|
|
|
klseek(artfil, tilefileoffs[tilenume], BSEEK_SET);
|
|
|
|
faketimerhandler();
|
|
|
|
}
|
|
|
|
|
|
|
|
kread(artfil, buffer, dasiz);
|
|
|
|
faketimerhandler();
|
|
|
|
artfilplc = tilefileoffs[tilenume]+dasiz;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-02 23:21:37 +00:00
|
|
|
int32_t tileCRC(int16_t tileNum)
|
|
|
|
{
|
|
|
|
char *data;
|
|
|
|
|
|
|
|
if ((unsigned)tileNum >= (unsigned)MAXTILES)
|
|
|
|
return 0;
|
|
|
|
int const dasiz = tilesiz[tileNum].x * tilesiz[tileNum].y;
|
|
|
|
if (dasiz <= 0)
|
|
|
|
return 0;
|
|
|
|
|
2019-06-25 11:29:08 +00:00
|
|
|
data = (char *)Xmalloc(dasiz);
|
2019-03-02 23:21:37 +00:00
|
|
|
tileLoadData(tileNum, dasiz, data);
|
|
|
|
|
|
|
|
int32_t crc = Bcrc32((unsigned char *)data, (unsigned int)dasiz, 0);
|
|
|
|
|
2019-06-25 11:29:08 +00:00
|
|
|
Xfree(data);
|
2019-03-02 23:21:37 +00:00
|
|
|
|
|
|
|
return crc;
|
|
|
|
}
|
|
|
|
|
2016-06-21 00:34:25 +00:00
|
|
|
//
|
|
|
|
// allocatepermanenttile
|
|
|
|
//
|
2018-04-12 21:03:30 +00:00
|
|
|
intptr_t tileCreate(int16_t tilenume, int32_t xsiz, int32_t ysiz)
|
2016-06-21 00:34:25 +00:00
|
|
|
{
|
|
|
|
if (xsiz <= 0 || ysiz <= 0 || (unsigned) tilenume >= MAXTILES)
|
|
|
|
return 0;
|
|
|
|
|
2016-06-21 00:34:29 +00:00
|
|
|
int const dasiz = xsiz*ysiz;
|
2016-06-21 00:34:25 +00:00
|
|
|
|
|
|
|
walock[tilenume] = 255;
|
2018-04-12 21:03:30 +00:00
|
|
|
cacheAllocateBlock(&waloff[tilenume], dasiz, &walock[tilenume]);
|
2016-06-21 00:34:25 +00:00
|
|
|
|
2018-04-12 21:03:30 +00:00
|
|
|
tileSetSize(tilenume, xsiz, ysiz);
|
2019-10-08 17:46:39 +00:00
|
|
|
picanm[tilenume].Clear();
|
2016-06-21 00:34:25 +00:00
|
|
|
|
|
|
|
return waloff[tilenume];
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// copytilepiece
|
|
|
|
//
|
2018-04-12 21:03:30 +00:00
|
|
|
void tileCopySection(int32_t tilenume1, int32_t sx1, int32_t sy1, int32_t xsiz, int32_t ysiz,
|
2016-06-21 00:34:25 +00:00
|
|
|
int32_t tilenume2, int32_t sx2, int32_t sy2)
|
|
|
|
{
|
|
|
|
char *ptr1, *ptr2, dat;
|
|
|
|
int32_t xsiz1, ysiz1, xsiz2, ysiz2, i, j, x1, y1, x2, y2;
|
|
|
|
|
|
|
|
xsiz1 = tilesiz[tilenume1].x; ysiz1 = tilesiz[tilenume1].y;
|
|
|
|
xsiz2 = tilesiz[tilenume2].x; ysiz2 = tilesiz[tilenume2].y;
|
|
|
|
if ((xsiz1 > 0) && (ysiz1 > 0) && (xsiz2 > 0) && (ysiz2 > 0))
|
|
|
|
{
|
2018-04-12 21:03:30 +00:00
|
|
|
if (waloff[tilenume1] == 0) tileLoad(tilenume1);
|
|
|
|
if (waloff[tilenume2] == 0) tileLoad(tilenume2);
|
2016-06-21 00:34:25 +00:00
|
|
|
|
|
|
|
x1 = sx1;
|
|
|
|
for (i=0; i<xsiz; i++)
|
|
|
|
{
|
|
|
|
y1 = sy1;
|
|
|
|
for (j=0; j<ysiz; j++)
|
|
|
|
{
|
|
|
|
x2 = sx2+i;
|
|
|
|
y2 = sy2+j;
|
|
|
|
if ((x2 >= 0) && (y2 >= 0) && (x2 < xsiz2) && (y2 < ysiz2))
|
|
|
|
{
|
|
|
|
ptr1 = (char *) (waloff[tilenume1] + x1*ysiz1 + y1);
|
|
|
|
ptr2 = (char *) (waloff[tilenume2] + x2*ysiz2 + y2);
|
|
|
|
dat = *ptr1;
|
|
|
|
if (dat != 255)
|
|
|
|
*ptr2 = *ptr1;
|
|
|
|
}
|
|
|
|
|
|
|
|
y1++; if (y1 >= ysiz1) y1 = 0;
|
|
|
|
}
|
|
|
|
x1++; if (x1 >= xsiz1) x1 = 0;
|
|
|
|
}
|
|
|
|
}
|
2019-09-18 22:19:02 +00:00
|
|
|
if (playing_rr)
|
|
|
|
tileInvalidate(tilenume2, -1, -1);
|
2016-06-21 00:34:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Buninitart(void)
|
|
|
|
{
|
2019-03-01 08:51:50 +00:00
|
|
|
if (artfil != buildvfs_kfd_invalid)
|
2016-06-21 00:34:25 +00:00
|
|
|
kclose(artfil);
|
|
|
|
|
2018-04-05 04:39:30 +00:00
|
|
|
ALIGNED_FREE_AND_NULL(pic);
|
2016-06-21 00:34:25 +00:00
|
|
|
}
|