diff --git a/source/blood/src/tile.cpp b/source/blood/src/tile.cpp index dbba5c6b7..58cdd2594 100644 --- a/source/blood/src/tile.cpp +++ b/source/blood/src/tile.cpp @@ -84,7 +84,7 @@ int tileInit(char a1, const char *a2) UNREFERENCED_PARAMETER(a1); if (artLoaded) return 1; - artLoadFiles(a2 ? a2 : pzBaseFileName, MAXCACHE1DSIZE); + TileFiles.artLoadFiles(a2 ? a2 : pzBaseFileName); for (int i = 0; i < kMaxTiles; i++) voxelIndex[i] = 0; diff --git a/source/build/include/build.h b/source/build/include/build.h index e9657f971..ce03d9888 100644 --- a/source/build/include/build.h +++ b/source/build/include/build.h @@ -833,15 +833,8 @@ EXTERN char show2dsector[(MAXSECTORS+7)>>3]; EXTERN char show2dwall[(MAXWALLS+7)>>3]; EXTERN char show2dsprite[(MAXSPRITES+7)>>3]; -// In the editor, gotpic is only referenced from inline assembly; -// the compiler needs that hint or building with LTO will discard it. -#if !defined __clang__ && !defined NOASM -# define GOTPIC_USED ATTRIBUTE((used)) -#else -# define GOTPIC_USED -#endif -EXTERN char GOTPIC_USED gotpic[(MAXTILES+7)>>3]; +EXTERN uint8_t gotpic[(MAXTILES+7)>>3]; EXTERN char gotsector[(MAXSECTORS+7)>>3]; EXTERN char editorcolors[256]; @@ -1048,7 +1041,6 @@ int32_t artReadHeaderFromBuffer(uint8_t const *buf, artheader_t *local); int32_t artCheckUnitFileHeader(uint8_t const *buf, int32_t length); 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); bool tileCache(int tilenume); @@ -1100,7 +1092,6 @@ int32_t printext16(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, const char *name, char fontsize) ATTRIBUTE((nonnull(5))); void printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, const char *name, char fontsize) ATTRIBUTE((nonnull(5))); -void Buninitart(void); ////////// specialized rotatesprite wrappers for (very) often used cases ////////// static FORCE_INLINE void rotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum, diff --git a/source/build/include/cache1d.h b/source/build/include/cache1d.h index 45f6f7fb3..01f88a726 100644 --- a/source/build/include/cache1d.h +++ b/source/build/include/cache1d.h @@ -18,68 +18,10 @@ extern char *kpzbuf; extern int32_t kpzbufsiz; extern int32_t kpzbufload(const char *); -void cacheInitBuffer(intptr_t dacachestart, int32_t dacachesize); +void cacheInitBuffer(int32_t dacachesize); void cacheAllocateBlock(intptr_t *newhandle, int32_t newbytes, uint8_t *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) @@ -109,7 +51,6 @@ 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); diff --git a/source/build/src/cache1d.cpp b/source/build/src/cache1d.cpp index 9eefdea92..fd79781dc 100644 --- a/source/build/src/cache1d.cpp +++ b/source/build/src/cache1d.cpp @@ -103,8 +103,8 @@ int32_t kpzbufload(char const * const filnam) #define MAXCACHEOBJECTS 16384 #if !defined DEBUG_ALLOCACHE_AS_MALLOC -static int32_t cachesize = 0; static uint8_t zerochar = 0; +static TArray cache; static intptr_t cachestart = 0; static int32_t lockrecip[200]; @@ -135,7 +135,7 @@ uint8_t toupperlookup[256] = static void reportandexit(const char *errormessage); -void cacheInitBuffer(intptr_t dacachestart, int32_t dacachesize) +void cacheInitBuffer(int32_t dacachesize) { #ifndef DEBUG_ALLOCACHE_AS_MALLOC int32_t i; @@ -143,14 +143,11 @@ void cacheInitBuffer(intptr_t dacachestart, int32_t dacachesize) for (i=1; i<200; i++) lockrecip[i] = tabledivide32_noinline(1<<28, 200-i); - // we allocate this block with aligned_alloc, but I'm leaving this here in - // case we run on any platforms that just implement it as regular malloc + cache.Resize(dacachesize); - cachestart = ((uintptr_t)dacachestart+15)&~(uintptr_t)0xf; - cachesize = (dacachesize-(((uintptr_t)(dacachestart))&0xf))&~(uintptr_t)0xf; - - cac[0].leng = cachesize; + cac[0].leng = cache.Size(); cac[0].lock = &zerochar; + cachestart = (intptr_t)cache.Data(); cacnum = 1; initprintf("Initialized %.1fM cache\n", (float)(dacachesize/1024.f/1024.f)); @@ -178,13 +175,13 @@ int32_t cacheFindBlock(int32_t newbytes, int32_t *besto, int32_t *bestz) { int32_t bestval = 0x7fffffff; - for (native_t z=cacnum-1, o1=cachesize; z>=0; z--) + for (native_t z=cacnum-1, o1=cache.Size(); z>=0; z--) { o1 -= cac[z].leng; int32_t const o2 = o1 + newbytes; - if (o2 > cachesize) + if (o2 > cache.Size()) continue; int32_t daval = 0; @@ -234,9 +231,9 @@ void cacheAllocateBlock(intptr_t* newhandle, int32_t newbytes, uint8_t* newlockp reportandexit("ALLOCACHE CALLED WITH LOCK OF 0!"); #endif - if (EDUKE32_PREDICT_FALSE((unsigned)newbytes > (unsigned)cachesize)) + if ((unsigned)newbytes > (unsigned)cache.Size()) { - initprintf("Cachesize: %d\n",cachesize); + initprintf("Cachesize: %u\n", cache.Size()); initprintf("*Newhandle: 0x%" PRIxPTR ", Newbytes: %d, *Newlock: %d\n",(intptr_t)newhandle,newbytes,*newlockptr); reportandexit("BUFFER TOO BIG TO FIT IN CACHE!"); } @@ -353,7 +350,7 @@ static void reportandexit(const char *errormessage) j += cac[i].leng; } - initprintf("Cachesize = %d\n", cachesize); + initprintf("Cachesize = %u\n", cache.Size()); initprintf("Cacnum = %d\n", cacnum); initprintf("Cache length sum = %d\n", j); #endif diff --git a/source/build/src/defs.cpp b/source/build/src/defs.cpp index dca55c18f..c70028ac6 100644 --- a/source/build/src/defs.cpp +++ b/source/build/src/defs.cpp @@ -518,11 +518,6 @@ static int32_t defsparser(scriptfile *script) if (scriptfile_getsymbol(script,&tile)) break; if (scriptfile_getnumber(script,&col)) break; if (scriptfile_getnumber(script,&col2)) break; - if ((uint32_t)tile < MAXTILES) - { - spritecol2d[tile][0] = col; - spritecol2d[tile][1] = col2; - } } break; case T_2DCOL: diff --git a/source/build/src/engine.cpp b/source/build/src/engine.cpp index 27ce99c5e..f376cca75 100644 --- a/source/build/src/engine.cpp +++ b/source/build/src/engine.cpp @@ -8258,8 +8258,6 @@ void engineUnInit(void) # endif #endif - Buninitart(); - DO_FREE_AND_NULL(lookups); for (bssize_t i=0; i>3] |= pow2char[tilenume&7]; } diff --git a/source/build/src/sdlayer.cpp b/source/build/src/sdlayer.cpp index a98d68a17..dc750e7fb 100644 --- a/source/build/src/sdlayer.cpp +++ b/source/build/src/sdlayer.cpp @@ -723,6 +723,11 @@ void initprintf(const char *f, ...) Bvsnprintf(buf, sizeof(buf), f, va); va_end(va); +#ifdef _WIN32 + if (IsDebuggerPresent()) + OutputDebugStringA(buf); +#endif + initputs(buf); } diff --git a/source/build/src/tiles.cpp b/source/build/src/tiles.cpp index fd569bde4..1eb816eaf 100644 --- a/source/build/src/tiles.cpp +++ b/source/build/src/tiles.cpp @@ -26,8 +26,8 @@ EDUKE32_STATIC_ASSERT(MAXARTFILES_TOTAL <= 256); static int32_t tilefileoffs[MAXTILES]; -static vec2_16_t tilesizearray[MAXTILES]; -static uint8_t picsizearray[MAXTILES]; +vec2_16_t tilesizearray[MAXTILES]; +uint8_t picsizearray[MAXTILES]; // These may only be manipulated through a function interface so that the backing texture objects can be adjusted or replaced. const vec2_16_t* const tilesiz = tilesizearray; const uint8_t* const picsiz = picsizearray; @@ -567,49 +567,6 @@ static int32_t artReadIndexedFile(int32_t tilefilei) // // loadpics // -int32_t artLoadFiles(const char *filename, int32_t askedsize) -{ - TileFiles.LoadArtSet(filename); - -#if 1 - Bstrncpyz(artfilenameformat, filename, sizeof(artfilenameformat)); - - Bmemset(&tilesizearray[0], 0, sizeof(vec2_16_t) * MAXTILES); - Bmemset(picanm, 0, sizeof(picanm)); - - for (auto &rot : rottile) - rot = { -1, -1 }; - - // artsize = 0; - - for (int tilefilei=0; tilefileiPicAnim; - tilesizearray[i] = tex->GetSize(); - } - - return 0; -} - const uint8_t* tilePtr(int num) { auto tex = TileFiles.tiles[num]; @@ -796,8 +753,8 @@ void tileCopySection(int32_t tilenume1, int32_t sx1, int32_t sy1, int32_t xsiz, xsiz2 = tilesiz[tilenume2].x; ysiz2 = tilesiz[tilenume2].y; if ((xsiz1 > 0) && (ysiz1 > 0) && (xsiz2 > 0) && (ysiz2 > 0)) { - if (tileptr[tilenume1] == 0) tileLoad(tilenume1); - if (tiledata[tilenume2] == 0) tileLoad(tilenume2); + tileLoad(tilenume1); + if (tileData(tilenume2) == 0) return; // Error: Destination is not writable. x1 = sx1; for (i=0; i= ArtFiles.Size()) // Do not process if already loaded. @@ -264,6 +264,7 @@ void BuildFiles::LoadArtFile(const char *fn, bool mapart, int firsttile) else { //initprintf("%s: file not found\n", fn); + return -1; } } else @@ -273,6 +274,7 @@ void BuildFiles::LoadArtFile(const char *fn, bool mapart, int firsttile) //ArtFiles.Delete(old); //ArtFiles.Push(std::move(fd)); } + return 0; } //========================================================================== @@ -326,6 +328,34 @@ FTexture* BuildFiles::ValidateCustomTile(int tilenum, int type) return replacement; } +//========================================================================== +// +// global interface +// +//========================================================================== +extern vec2_16_t tilesizearray[MAXTILES]; +extern uint8_t picsizearray[MAXTILES]; + +int32_t BuildFiles::artLoadFiles(const char* filename) +{ + TileFiles.LoadArtSet(filename); + memset(gotpic, 0, MAXTILES); + cacheInitBuffer(MAXCACHE1DSIZE); + + for (unsigned i = 0; i < MAXTILES; i++) + { + auto tex = TileFiles.tiles[i]; + assert(tex); + picanm[i] = tex->PicAnim; + tilesizearray[i] = tex->GetSize(); + picsizearray[i] = tex->PicSize; + rottile[i] = { -1, -1 }; + } + + + return 0; +} + //========================================================================== // // Creates a tile for displaying custom content diff --git a/source/common/textures/imagetexture.cpp b/source/common/textures/imagetexture.cpp index 7d5b01047..518edcfa1 100644 --- a/source/common/textures/imagetexture.cpp +++ b/source/common/textures/imagetexture.cpp @@ -52,8 +52,7 @@ FImageTexture::FImageTexture(FImageSource *img, const char *name) mImage = img; if (img != nullptr) { - Size.x = img->GetWidth(); - Size.y = img->GetHeight(); + SetSize(img->GetWidth(), img->GetHeight()); auto offsets = img->GetOffsets(); PicAnim.xofs = offsets.first; diff --git a/source/common/textures/textures.h b/source/common/textures/textures.h index e35fc141f..1207fe3e5 100644 --- a/source/common/textures/textures.h +++ b/source/common/textures/textures.h @@ -259,11 +259,10 @@ protected: void UpdatePicSize() { int j = 15; - int size; while ((j > 1) && ((1 << j) > Size.x)) j--; - size = j; + PicSize = j; j = 15; while ((j > 1) && ((1 << j) > Size.y)) @@ -278,7 +277,7 @@ protected: uint8_t bMasked = true; // Texture (might) have holes int8_t bTranslucent = -1; // Does this texture have an active alpha channel? bool skyColorDone = false; - uint8_t PicSize; // A special piece of Build weirdness. + uint8_t PicSize = 0; // A special piece of Build weirdness. UseType useType = Image; PalEntry FloorSkyColor; PalEntry CeilingSkyColor; @@ -507,10 +506,11 @@ struct BuildFiles { return ArtFiles.FindEx([filename](const BuildArtFile* element) { return filename.CompareNoCase(element->filename) == 0; }); } - void LoadArtFile(const char* file, bool mapart = false, int firsttile = -1); + int LoadArtFile(const char* file, bool mapart = false, int firsttile = -1); void CloseAllMapArt(); void LoadArtSet(const char* filename); FTexture* ValidateCustomTile(int tilenum, int type); + int32_t artLoadFiles(const char* filename); uint8_t *tileMakeWritable(int num); uint8_t *tileCreate(int tilenum, int width, int height); void tileSetExternal(int tilenum, int width, int height, uint8_t* data); diff --git a/source/duke3d/src/actors.cpp b/source/duke3d/src/actors.cpp index 6ec1fc257..b6d803a3a 100644 --- a/source/duke3d/src/actors.cpp +++ b/source/duke3d/src/actors.cpp @@ -2458,8 +2458,6 @@ DETONATE: g_curViewscreen = -1; sprite[spriteNum].yvel = 0; // VIEWSCREEN_YVEL T1(spriteNum) = 0; - - for (bssize_t ii = 0; ii < VIEWSCREENFACTOR; ii++) walock[TILE_VIEWSCR - ii] = 199; } } diff --git a/source/duke3d/src/game.cpp b/source/duke3d/src/game.cpp index 366529315..cac26c23e 100644 --- a/source/duke3d/src/game.cpp +++ b/source/duke3d/src/game.cpp @@ -6115,7 +6115,7 @@ static void G_Startup(void) if (numplayers > 1) initprintf("Multiplayer initialized.\n"); - if (artLoadFiles("tiles%03i.art",MAXCACHE1DSIZE) < 0) + if (TileFiles.artLoadFiles("tiles%03i.art") < 0) G_GameExit("Failed loading art."); cacheAllSounds(); diff --git a/source/duke3d/src/menus.cpp b/source/duke3d/src/menus.cpp index 5c8170b60..0f0fa826a 100644 --- a/source/duke3d/src/menus.cpp +++ b/source/duke3d/src/menus.cpp @@ -7014,7 +7014,6 @@ void M_DisplayMenus(void) if ((g_player[myconnectindex].ps->gm&MODE_MENU) == 0) { - walock[TILE_LOADSHOT] = 1; return; } diff --git a/source/rr/src/actors.cpp b/source/rr/src/actors.cpp index 12e7bbc5b..f485e70f7 100644 --- a/source/rr/src/actors.cpp +++ b/source/rr/src/actors.cpp @@ -2217,8 +2217,6 @@ DETONATE: g_curViewscreen = -1; sprite[spriteNum].yvel = 0; // VIEWSCREEN_YVEL T1(spriteNum) = 0; - - for (bssize_t ii = 0; ii < VIEWSCREENFACTOR; ii++) walock[TILE_VIEWSCR - ii] = 199; } } diff --git a/source/rr/src/game.cpp b/source/rr/src/game.cpp index 5ca8dad40..6aac5a57d 100644 --- a/source/rr/src/game.cpp +++ b/source/rr/src/game.cpp @@ -7518,7 +7518,7 @@ static void G_Startup(void) if (numplayers > 1) initprintf("Multiplayer initialized.\n"); - if (artLoadFiles("tiles%03i.art",MAXCACHE1DSIZE) < 0) + if (TileFiles.artLoadFiles("tiles%03i.art") < 0) G_GameExit("Failed loading art."); // Make the fullscreen nuke logo background non-fullbright. Has to be diff --git a/source/sw/src/game.cpp b/source/sw/src/game.cpp index 4a9815161..8df7b94db 100644 --- a/source/sw/src/game.cpp +++ b/source/sw/src/game.cpp @@ -734,7 +734,7 @@ LoadImages(const char *filename) short ndx; FILE *fin; - if (artLoadFiles(filename, 32*1048576) == -1) + if (TileFiles.LoadArtFile(filename) == -1) { TerminateGame(); #ifdef RENDERTYPEWIN