- more updating and bug in UpdatePicSize fixed.

This commit is contained in:
Christoph Oelckers 2019-10-15 20:02:37 +02:00
parent 0e165e40a3
commit c3bc690e98
18 changed files with 61 additions and 154 deletions

View file

@ -84,7 +84,7 @@ int tileInit(char a1, const char *a2)
UNREFERENCED_PARAMETER(a1); UNREFERENCED_PARAMETER(a1);
if (artLoaded) if (artLoaded)
return 1; return 1;
artLoadFiles(a2 ? a2 : pzBaseFileName, MAXCACHE1DSIZE); TileFiles.artLoadFiles(a2 ? a2 : pzBaseFileName);
for (int i = 0; i < kMaxTiles; i++) for (int i = 0; i < kMaxTiles; i++)
voxelIndex[i] = 0; voxelIndex[i] = 0;

View file

@ -833,15 +833,8 @@ EXTERN char show2dsector[(MAXSECTORS+7)>>3];
EXTERN char show2dwall[(MAXWALLS+7)>>3]; EXTERN char show2dwall[(MAXWALLS+7)>>3];
EXTERN char show2dsprite[(MAXSPRITES+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 gotsector[(MAXSECTORS+7)>>3];
EXTERN char editorcolors[256]; 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); int32_t artCheckUnitFileHeader(uint8_t const *buf, int32_t length);
void artReadManifest(buildvfs_kfd fil, artheader_t const *local); void artReadManifest(buildvfs_kfd fil, artheader_t const *local);
void artPreloadFile(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 artClearMapArt(void);
void artSetupMapArt(const char *filename); void artSetupMapArt(const char *filename);
bool tileCache(int tilenume); 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))); const char *name, char fontsize) ATTRIBUTE((nonnull(5)));
void printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol, void printext256(int32_t xpos, int32_t ypos, int16_t col, int16_t backcol,
const char *name, char fontsize) ATTRIBUTE((nonnull(5))); const char *name, char fontsize) ATTRIBUTE((nonnull(5)));
void Buninitart(void);
////////// specialized rotatesprite wrappers for (very) often used cases ////////// ////////// 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, static FORCE_INLINE void rotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t picnum,

View file

@ -18,68 +18,10 @@ extern char *kpzbuf;
extern int32_t kpzbufsiz; extern int32_t kpzbufsiz;
extern int32_t kpzbufload(const char *); 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 cacheAllocateBlock(intptr_t *newhandle, int32_t newbytes, uint8_t *newlockptr);
void cacheAgeEntries(void); 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; using buildvfs_kfd = int32_t;
#define buildvfs_kfd_invalid (-1) #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); void krename(int32_t crcval, int32_t filenum, const char *newname);
char const * kfileparent(int32_t handle); char const * kfileparent(int32_t handle);
#endif
extern int32_t kpzbufloadfil(buildvfs_kfd); extern int32_t kpzbufloadfil(buildvfs_kfd);

View file

@ -103,8 +103,8 @@ int32_t kpzbufload(char const * const filnam)
#define MAXCACHEOBJECTS 16384 #define MAXCACHEOBJECTS 16384
#if !defined DEBUG_ALLOCACHE_AS_MALLOC #if !defined DEBUG_ALLOCACHE_AS_MALLOC
static int32_t cachesize = 0;
static uint8_t zerochar = 0; static uint8_t zerochar = 0;
static TArray<uint8_t> cache;
static intptr_t cachestart = 0; static intptr_t cachestart = 0;
static int32_t lockrecip[200]; static int32_t lockrecip[200];
@ -135,7 +135,7 @@ uint8_t toupperlookup[256] =
static void reportandexit(const char *errormessage); static void reportandexit(const char *errormessage);
void cacheInitBuffer(intptr_t dacachestart, int32_t dacachesize) void cacheInitBuffer(int32_t dacachesize)
{ {
#ifndef DEBUG_ALLOCACHE_AS_MALLOC #ifndef DEBUG_ALLOCACHE_AS_MALLOC
int32_t i; int32_t i;
@ -143,14 +143,11 @@ void cacheInitBuffer(intptr_t dacachestart, int32_t dacachesize)
for (i=1; i<200; i++) for (i=1; i<200; i++)
lockrecip[i] = tabledivide32_noinline(1<<28, 200-i); lockrecip[i] = tabledivide32_noinline(1<<28, 200-i);
// we allocate this block with aligned_alloc, but I'm leaving this here in cache.Resize(dacachesize);
// case we run on any platforms that just implement it as regular malloc
cachestart = ((uintptr_t)dacachestart+15)&~(uintptr_t)0xf; cac[0].leng = cache.Size();
cachesize = (dacachesize-(((uintptr_t)(dacachestart))&0xf))&~(uintptr_t)0xf;
cac[0].leng = cachesize;
cac[0].lock = &zerochar; cac[0].lock = &zerochar;
cachestart = (intptr_t)cache.Data();
cacnum = 1; cacnum = 1;
initprintf("Initialized %.1fM cache\n", (float)(dacachesize/1024.f/1024.f)); 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; 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; o1 -= cac[z].leng;
int32_t const o2 = o1 + newbytes; int32_t const o2 = o1 + newbytes;
if (o2 > cachesize) if (o2 > cache.Size())
continue; continue;
int32_t daval = 0; 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!"); reportandexit("ALLOCACHE CALLED WITH LOCK OF 0!");
#endif #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); initprintf("*Newhandle: 0x%" PRIxPTR ", Newbytes: %d, *Newlock: %d\n",(intptr_t)newhandle,newbytes,*newlockptr);
reportandexit("BUFFER TOO BIG TO FIT IN CACHE!"); reportandexit("BUFFER TOO BIG TO FIT IN CACHE!");
} }
@ -353,7 +350,7 @@ static void reportandexit(const char *errormessage)
j += cac[i].leng; j += cac[i].leng;
} }
initprintf("Cachesize = %d\n", cachesize); initprintf("Cachesize = %u\n", cache.Size());
initprintf("Cacnum = %d\n", cacnum); initprintf("Cacnum = %d\n", cacnum);
initprintf("Cache length sum = %d\n", j); initprintf("Cache length sum = %d\n", j);
#endif #endif

View file

@ -518,11 +518,6 @@ static int32_t defsparser(scriptfile *script)
if (scriptfile_getsymbol(script,&tile)) break; if (scriptfile_getsymbol(script,&tile)) break;
if (scriptfile_getnumber(script,&col)) break; if (scriptfile_getnumber(script,&col)) break;
if (scriptfile_getnumber(script,&col2)) break; if (scriptfile_getnumber(script,&col2)) break;
if ((uint32_t)tile < MAXTILES)
{
spritecol2d[tile][0] = col;
spritecol2d[tile][1] = col2;
}
} }
break; break;
case T_2DCOL: case T_2DCOL:

View file

@ -8258,8 +8258,6 @@ void engineUnInit(void)
# endif # endif
#endif #endif
Buninitart();
DO_FREE_AND_NULL(lookups); DO_FREE_AND_NULL(lookups);
for (bssize_t i=0; i<DISTRECIPCACHESIZE; i++) for (bssize_t i=0; i<DISTRECIPCACHESIZE; i++)
ALIGNED_FREE_AND_NULL(distrecipcache[i].distrecip); ALIGNED_FREE_AND_NULL(distrecipcache[i].distrecip);

View file

@ -209,7 +209,6 @@ extern int32_t m32_numdebuglines;
static FORCE_INLINE void setgotpic(int32_t tilenume) static FORCE_INLINE void setgotpic(int32_t tilenume)
{ {
if (walock[tilenume] < 200) walock[tilenume] = 199;
gotpic[tilenume>>3] |= pow2char[tilenume&7]; gotpic[tilenume>>3] |= pow2char[tilenume&7];
} }

View file

@ -723,6 +723,11 @@ void initprintf(const char *f, ...)
Bvsnprintf(buf, sizeof(buf), f, va); Bvsnprintf(buf, sizeof(buf), f, va);
va_end(va); va_end(va);
#ifdef _WIN32
if (IsDebuggerPresent())
OutputDebugStringA(buf);
#endif
initputs(buf); initputs(buf);
} }

View file

@ -26,8 +26,8 @@ EDUKE32_STATIC_ASSERT(MAXARTFILES_TOTAL <= 256);
static int32_t tilefileoffs[MAXTILES]; static int32_t tilefileoffs[MAXTILES];
static vec2_16_t tilesizearray[MAXTILES]; vec2_16_t tilesizearray[MAXTILES];
static uint8_t picsizearray[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. // 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 vec2_16_t* const tilesiz = tilesizearray;
const uint8_t* const picsiz = picsizearray; const uint8_t* const picsiz = picsizearray;
@ -567,49 +567,6 @@ static int32_t artReadIndexedFile(int32_t tilefilei)
// //
// loadpics // 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; tilefilei<MAXARTFILES_BASE; tilefilei++)
artReadIndexedFile(tilefilei);
Bmemset(gotpic, 0, sizeof(gotpic));
//cachesize = min((int32_t)((Bgetsysmemsize()/100)*60),max(artsize,askedsize));
cachesize = (Bgetsysmemsize() <= (uint32_t)askedsize) ? (int32_t)((Bgetsysmemsize() / 100) * 60) : askedsize;
pic = Xaligned_alloc(Bgetpagesize(), cachesize);
cacheInitBuffer((intptr_t) pic, cachesize);
artUpdateManifest();
artfil = buildvfs_kfd_invalid;
artfilnum = -1;
artfilplc = 0L;
#endif
for (unsigned i = 0; i < MAXTILES; i++)
{
auto tex = TileFiles.tiles[i];
assert(tex);
picanm[i] = tex->PicAnim;
tilesizearray[i] = tex->GetSize();
}
return 0;
}
const uint8_t* tilePtr(int num) const uint8_t* tilePtr(int num)
{ {
auto tex = TileFiles.tiles[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; xsiz2 = tilesiz[tilenume2].x; ysiz2 = tilesiz[tilenume2].y;
if ((xsiz1 > 0) && (ysiz1 > 0) && (xsiz2 > 0) && (ysiz2 > 0)) if ((xsiz1 > 0) && (ysiz1 > 0) && (xsiz2 > 0) && (ysiz2 > 0))
{ {
if (tileptr[tilenume1] == 0) tileLoad(tilenume1); tileLoad(tilenume1);
if (tiledata[tilenume2] == 0) tileLoad(tilenume2); if (tileData(tilenume2) == 0) return; // Error: Destination is not writable.
x1 = sx1; x1 = sx1;
for (i=0; i<xsiz; i++) for (i=0; i<xsiz; i++)

View file

@ -236,7 +236,7 @@ void BuildFiles::CloseAllMapArt()
// //
//=========================================================================== //===========================================================================
void BuildFiles::LoadArtFile(const char *fn, bool mapart, int firsttile) int BuildFiles::LoadArtFile(const char *fn, bool mapart, int firsttile)
{ {
auto old = FindFile(fn); auto old = FindFile(fn);
if (old >= ArtFiles.Size()) // Do not process if already loaded. if (old >= ArtFiles.Size()) // Do not process if already loaded.
@ -264,6 +264,7 @@ void BuildFiles::LoadArtFile(const char *fn, bool mapart, int firsttile)
else else
{ {
//initprintf("%s: file not found\n", fn); //initprintf("%s: file not found\n", fn);
return -1;
} }
} }
else else
@ -273,6 +274,7 @@ void BuildFiles::LoadArtFile(const char *fn, bool mapart, int firsttile)
//ArtFiles.Delete(old); //ArtFiles.Delete(old);
//ArtFiles.Push(std::move(fd)); //ArtFiles.Push(std::move(fd));
} }
return 0;
} }
//========================================================================== //==========================================================================
@ -326,6 +328,34 @@ FTexture* BuildFiles::ValidateCustomTile(int tilenum, int type)
return replacement; 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 // Creates a tile for displaying custom content

View file

@ -52,8 +52,7 @@ FImageTexture::FImageTexture(FImageSource *img, const char *name)
mImage = img; mImage = img;
if (img != nullptr) if (img != nullptr)
{ {
Size.x = img->GetWidth(); SetSize(img->GetWidth(), img->GetHeight());
Size.y = img->GetHeight();
auto offsets = img->GetOffsets(); auto offsets = img->GetOffsets();
PicAnim.xofs = offsets.first; PicAnim.xofs = offsets.first;

View file

@ -259,11 +259,10 @@ protected:
void UpdatePicSize() void UpdatePicSize()
{ {
int j = 15; int j = 15;
int size;
while ((j > 1) && ((1 << j) > Size.x)) while ((j > 1) && ((1 << j) > Size.x))
j--; j--;
size = j; PicSize = j;
j = 15; j = 15;
while ((j > 1) && ((1 << j) > Size.y)) while ((j > 1) && ((1 << j) > Size.y))
@ -278,7 +277,7 @@ protected:
uint8_t bMasked = true; // Texture (might) have holes uint8_t bMasked = true; // Texture (might) have holes
int8_t bTranslucent = -1; // Does this texture have an active alpha channel? int8_t bTranslucent = -1; // Does this texture have an active alpha channel?
bool skyColorDone = false; 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; UseType useType = Image;
PalEntry FloorSkyColor; PalEntry FloorSkyColor;
PalEntry CeilingSkyColor; PalEntry CeilingSkyColor;
@ -507,10 +506,11 @@ struct BuildFiles
{ {
return ArtFiles.FindEx([filename](const BuildArtFile* element) { return filename.CompareNoCase(element->filename) == 0; }); 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 CloseAllMapArt();
void LoadArtSet(const char* filename); void LoadArtSet(const char* filename);
FTexture* ValidateCustomTile(int tilenum, int type); FTexture* ValidateCustomTile(int tilenum, int type);
int32_t artLoadFiles(const char* filename);
uint8_t *tileMakeWritable(int num); uint8_t *tileMakeWritable(int num);
uint8_t *tileCreate(int tilenum, int width, int height); uint8_t *tileCreate(int tilenum, int width, int height);
void tileSetExternal(int tilenum, int width, int height, uint8_t* data); void tileSetExternal(int tilenum, int width, int height, uint8_t* data);

View file

@ -2458,8 +2458,6 @@ DETONATE:
g_curViewscreen = -1; g_curViewscreen = -1;
sprite[spriteNum].yvel = 0; // VIEWSCREEN_YVEL sprite[spriteNum].yvel = 0; // VIEWSCREEN_YVEL
T1(spriteNum) = 0; T1(spriteNum) = 0;
for (bssize_t ii = 0; ii < VIEWSCREENFACTOR; ii++) walock[TILE_VIEWSCR - ii] = 199;
} }
} }

View file

@ -6115,7 +6115,7 @@ static void G_Startup(void)
if (numplayers > 1) if (numplayers > 1)
initprintf("Multiplayer initialized.\n"); initprintf("Multiplayer initialized.\n");
if (artLoadFiles("tiles%03i.art",MAXCACHE1DSIZE) < 0) if (TileFiles.artLoadFiles("tiles%03i.art") < 0)
G_GameExit("Failed loading art."); G_GameExit("Failed loading art.");
cacheAllSounds(); cacheAllSounds();

View file

@ -7014,7 +7014,6 @@ void M_DisplayMenus(void)
if ((g_player[myconnectindex].ps->gm&MODE_MENU) == 0) if ((g_player[myconnectindex].ps->gm&MODE_MENU) == 0)
{ {
walock[TILE_LOADSHOT] = 1;
return; return;
} }

View file

@ -2217,8 +2217,6 @@ DETONATE:
g_curViewscreen = -1; g_curViewscreen = -1;
sprite[spriteNum].yvel = 0; // VIEWSCREEN_YVEL sprite[spriteNum].yvel = 0; // VIEWSCREEN_YVEL
T1(spriteNum) = 0; T1(spriteNum) = 0;
for (bssize_t ii = 0; ii < VIEWSCREENFACTOR; ii++) walock[TILE_VIEWSCR - ii] = 199;
} }
} }

View file

@ -7518,7 +7518,7 @@ static void G_Startup(void)
if (numplayers > 1) if (numplayers > 1)
initprintf("Multiplayer initialized.\n"); initprintf("Multiplayer initialized.\n");
if (artLoadFiles("tiles%03i.art",MAXCACHE1DSIZE) < 0) if (TileFiles.artLoadFiles("tiles%03i.art") < 0)
G_GameExit("Failed loading art."); G_GameExit("Failed loading art.");
// Make the fullscreen nuke logo background non-fullbright. Has to be // Make the fullscreen nuke logo background non-fullbright. Has to be

View file

@ -734,7 +734,7 @@ LoadImages(const char *filename)
short ndx; short ndx;
FILE *fin; FILE *fin;
if (artLoadFiles(filename, 32*1048576) == -1) if (TileFiles.LoadArtFile(filename) == -1)
{ {
TerminateGame(); TerminateGame();
#ifdef RENDERTYPEWIN #ifdef RENDERTYPEWIN