- rerouted tileCreate and tileSetExternal calls.

This commit is contained in:
Christoph Oelckers 2019-10-15 23:18:52 +02:00
parent c3bc690e98
commit 9a52e8039c
20 changed files with 86 additions and 71 deletions

View file

@ -216,7 +216,7 @@ void credPlaySmk(const char *_pzSMK, const char *_pzWAV, int nWav)
Smacker_GetFrameSize(hSMK, nWidth, nHeight);
uint8_t palette[768];
tileDelete(kSMKTile);
auto pFrame = tileCreate(kSMKTile, nWidth, nHeight);
auto pFrame = TileFiles.tileCreate(kSMKTile, nWidth, nHeight);
if (!pFrame)
{
Smacker_Close(hSMK);

View file

@ -145,14 +145,14 @@ void tileProcessGLVoxels(void)
const uint8_t * tileLoadTile(int nTile)
{
tileCache(nTile);
tileLoad(nTile);
return (const uint8_t*)tilePtr(nTile);
}
uint8_t * tileAllocTile(int nTile, int x, int y, int ox, int oy)
{
dassert(nTile >= 0 && nTile < kMaxTiles);
uint8_t *p = tileCreate(nTile, x, y);
uint8_t *p = TileFiles.tileCreate(nTile, x, y);
dassert(p != NULL);
picanm[nTile].xofs = ClipRange(ox, -127, 127);
picanm[nTile].yofs = ClipRange(oy, -127, 127);

View file

@ -1053,8 +1053,6 @@ void tileUpdatePicSiz(int32_t picnum);
int32_t qloadkvx(int32_t voxindex, const char *filename);
void vox_undefine(int32_t const);
uint8_t *tileCreate(int16_t tilenume, int32_t xsiz, int32_t ysiz);
void tileSetExternal(int16_t tilenume, int32_t xsiz, int32_t ysiz, uint8_t* data);
void tileCopySection(int32_t tilenume1, int32_t sx1, int32_t sy1, int32_t xsiz, int32_t ysiz, int32_t tilenume2, int32_t sx2, int32_t sy2);
void squarerotatetile(int16_t tilenume);

View file

@ -2530,7 +2530,7 @@ restart_grand:
{
tileUpdatePicnum(&tilenum, 0);
if (tileCache(tilenum))
if (tileLoad(tilenum))
{
// daz-intz > 0 && daz-intz < k
int32_t xtex = mulscale16(ucoefup16, tilesiz[tilenum].x);

View file

@ -1906,12 +1906,12 @@ static void maskwallscan(int32_t x1, int32_t x2, int32_t saturatevplc)
if ((uwall[x1] > ydimen) && (uwall[x2] > ydimen)) return;
if ((dwall[x1] < 0) && (dwall[x2] < 0)) return;
vec2_16_t tsiz = tilesiz[globalpicnum];
auto tsiz = tilesiz[globalpicnum];
if ((tsiz.x <= 0) || (tsiz.y <= 0)) return;
setgotpic(globalpicnum);
tileCache(globalpicnum);
tileLoad(globalpicnum);
tweak_tsizes(&tsiz);
@ -2633,7 +2633,7 @@ static int32_t setup_globals_cf1(usectorptr_t sec, int32_t pal, int32_t zd,
tileUpdatePicnum(&globalpicnum, 0);
setgotpic(globalpicnum);
if ((tilesiz[globalpicnum].x <= 0) || (tilesiz[globalpicnum].y <= 0)) return 1;
tileCache(globalpicnum);
tileLoad(globalpicnum);
globalbufplc = (intptr_t)tilePtr(globalpicnum);
@ -2929,7 +2929,7 @@ static void wallscan(int32_t x1, int32_t x2,
if ((uwal[x1] > ydimen) && (uwal[x2] > ydimen)) return;
if ((dwal[x1] < 0) && (dwal[x2] < 0)) return;
tileCache(globalpicnum);
tileLoad(globalpicnum);
tweak_tsizes(&tsiz);
@ -3151,7 +3151,7 @@ static void transmaskwallscan(int32_t x1, int32_t x2, int32_t saturatevplc)
if ((tilesiz[globalpicnum].x <= 0) || (tilesiz[globalpicnum].y <= 0))
return;
tileCache(globalpicnum);
tileLoad(globalpicnum);
setuptvlineasm(globalshiftval, saturatevplc);
@ -3451,7 +3451,7 @@ static void fgrouscan(int32_t dax1, int32_t dax2, int32_t sectnum, char dastat)
tileUpdatePicnum(&globalpicnum, sectnum);
setgotpic(globalpicnum);
if ((tilesiz[globalpicnum].x <= 0) || (tilesiz[globalpicnum].y <= 0)) return;
tileCache(globalpicnum);
tileLoad(globalpicnum);
wal = (uwalltype *)&wall[sec->wallptr];
@ -3743,7 +3743,7 @@ static void grouscan(int32_t dax1, int32_t dax2, int32_t sectnum, char dastat)
tileUpdatePicnum(&globalpicnum, sectnum);
setgotpic(globalpicnum);
if ((tilesiz[globalpicnum].x <= 0) || (tilesiz[globalpicnum].y <= 0)) return;
tileCache(globalpicnum);
tileLoad(globalpicnum);
wal = (uwallptr_t)&wall[sec->wallptr];
@ -5962,7 +5962,7 @@ draw_as_face_sprite:
globalpicnum = tilenum;
if ((unsigned)globalpicnum >= (unsigned)MAXTILES) globalpicnum = 0;
tileCache(globalpicnum);
tileLoad(globalpicnum);
setgotpic(globalpicnum);
globalbufplc = (intptr_t)tilePtr(globalpicnum);
@ -6997,7 +6997,7 @@ static void dorotatesprite(int32_t sx, int32_t sy, int32_t z, int16_t a, int16_t
nextv = v;
}
tileCache(picnum);
tileLoad(picnum);
setgotpic(picnum);
bufplc = (intptr_t)tilePtr(picnum);
@ -8258,6 +8258,8 @@ void engineUnInit(void)
# endif
#endif
//TileFiles.CloseAll();
DO_FREE_AND_NULL(lookups);
for (bssize_t i=0; i<DISTRECIPCACHESIZE; i++)
ALIGNED_FREE_AND_NULL(distrecipcache[i].distrecip);
@ -9289,11 +9291,16 @@ void renderDrawMapView(int32_t dax, int32_t day, int32_t zoome, int16_t ang)
tileUpdatePicnum(&globalpicnum, s);
setgotpic(globalpicnum);
if ((tilesiz[globalpicnum].x <= 0) || (tilesiz[globalpicnum].y <= 0)) continue;
tileCache(globalpicnum);
globalbufplc = (intptr_t)tilePtr(globalpicnum);
globalshade = max(min<int>(sec->floorshade,numshades-1),0);
globvis = globalhisibility;
if (videoGetRenderMode() == REND_POLYMOST)
{
tileLoad(globalpicnum);
// Only load tiles when software rendering.
globalbufplc = (intptr_t)tilePtr(globalpicnum);
}
globalshade = max(min<int>(sec->floorshade, numshades - 1), 0);
globvis = globalhisibility;
if (sec->visibility != 0) globvis = mulscale4(globvis, (uint8_t)(sec->visibility+16));
globalpolytype = 0;
if ((globalorientation&64) == 0)
@ -9415,15 +9422,19 @@ void renderDrawMapView(int32_t dax, int32_t day, int32_t zoome, int16_t ang)
tileUpdatePicnum(&globalpicnum, s);
setgotpic(globalpicnum);
if ((tilesiz[globalpicnum].x <= 0) || (tilesiz[globalpicnum].y <= 0)) continue;
tileCache(globalpicnum);
globalbufplc = (intptr_t)tilePtr(globalpicnum);
// 'loading' the tile doesn't actually guarantee that it's there afterwards.
// This can really happen when drawing the second frame of a floor-aligned
// 'storm icon' sprite (4894+1)
if (!globalbufplc)
continue;
if (videoGetRenderMode() == REND_POLYMOST)
{
tileLoad(globalpicnum);
// Only load tiles when software rendering.
globalbufplc = (intptr_t)tilePtr(globalpicnum);
// 'loading' the tile doesn't actually guarantee that it's there afterwards.
// This can really happen when drawing the second frame of a floor-aligned
// 'storm icon' sprite (4894+1)
if (!globalbufplc)
continue;
}
// For Polymost the abovementioned edge case cannot be detected here if the only way is to check the texture's pixel data.
if ((sector[spr->sectnum].ceilingstat&1) > 0)
globalshade = ((int32_t)sector[spr->sectnum].ceilingshade);
@ -9600,7 +9611,6 @@ static int32_t engineFinishLoadBoard(const vec3_t *dapos, int16_t *dacursectnum,
guniqhudid = 0;
Bmemset(tilecols, 0, sizeof(tilecols));
return numremoved;
}
@ -12120,8 +12130,7 @@ void renderSetTarget(int16_t tilenume, int32_t xsiz, int32_t ysiz)
return;
//DRAWROOMS TO TILE BACKUP&SET CODE
tileDelete(tilenume);
tileCreate(tilenume, xsiz, ysiz);
TileFiles.tileCreate(tilenume, xsiz, ysiz);
bakxsiz[setviewcnt] = xdim; bakysiz[setviewcnt] = ydim;
bakframeplace[setviewcnt] = frameplace; frameplace = (intptr_t)tilePtr(tilenume);
bakwindowxy1[setviewcnt] = windowxy1;

View file

@ -115,7 +115,7 @@ void gloadtile_art(int32_t dapic, int32_t dameth, pthtyp* pth, int32_t doalloc)
//POGOTODO: npoty
char npoty = 0;
tileCache(globalpicnum);
tileLoad(globalpicnum);
const uint8_t* p = tilePtr(dapic);
if (!p)

View file

@ -723,22 +723,6 @@ int32_t tileCRC(int16_t tileNum)
//
// allocatepermanenttile
//
uint8_t *tileCreate(int16_t tilenume, int32_t xsiz, int32_t ysiz)
{
if (xsiz <= 0 || ysiz <= 0 || (unsigned)tilenume >= MAXTILES)
return 0;
tiledata[tilenume] = TileFiles.tileCreate(tilenume, xsiz, ysiz);
tilesizearray[tilenume] = TileFiles.tiles[tilenume]->GetSize();
return tiledata[tilenume];
}
void tileSetExternal(int16_t tilenume, int32_t xsiz, int32_t ysiz, uint8_t *data)
{
TileFiles.tileSetExternal(tilenume, xsiz, ysiz, data);
tilesizearray[tilenume] = TileFiles.tiles[tilenume]->GetSize();
tiledata[tilenume] = TileFiles.tiles[tilenume]->GetWritableBuffer();
}
//

View file

@ -518,6 +518,11 @@ struct BuildFiles
};
extern BuildFiles TileFiles;
inline bool tileCheck(int num)
{
auto tex = TileFiles.tiles[num];
return tex->GetWidth() > 0 && tex->GetHeight() > 0;
}
#endif

View file

@ -499,7 +499,7 @@ int32_t Anim_Play(const char *fn)
i = VM_OnEventWithReturn(EVENT_PRECUTSCENE, g_player[screenpeek].ps->i, screenpeek, i);
tileSetExternal(TILE_ANIM, 200, 320, ANIM_DrawFrame(i));
TileFiles.tileSetExternal(TILE_ANIM, 200, 320, ANIM_DrawFrame(i));
tileInvalidate(TILE_ANIM, 0, 1 << 4); // JBF 20031228
if (VM_OnEventWithReturn(EVENT_SKIPCUTSCENE, g_player[screenpeek].ps->i, screenpeek, I_GeneralTrigger()))

View file

@ -710,7 +710,7 @@ static void G_ReadGLFrame(void)
const int32_t xf = divscale16(ydim*4/3, 320);
const int32_t yf = divscale16(ydim, 200); // (ydim<<16)/200
auto pic = tileCreate(TILE_SAVESHOT, 200, 320);
auto pic = TileFiles.tileCreate(TILE_SAVESHOT, 200, 320);
if (!frame)
{
@ -838,7 +838,7 @@ void G_DrawRooms(int32_t playerNum, int32_t smoothRatio)
if (g_screenCapture)
{
tileCreate(TILE_SAVESHOT, 200, 320);
TileFiles.tileCreate(TILE_SAVESHOT, 200, 320);
if (videoGetRenderMode() == REND_CLASSIC)
renderSetTarget(TILE_SAVESHOT, 200, 320);
@ -896,7 +896,7 @@ void G_DrawRooms(int32_t playerNum, int32_t smoothRatio)
const int32_t viewtilexsiz = (tang&1023) ? tiltcx : tiltcy;
const int32_t viewtileysiz = tiltcx;
tileCreate(TILE_TILT, tiltcx, tiltcx);
TileFiles.tileCreate(TILE_TILT, tiltcx, tiltcx);
renderSetTarget(TILE_TILT, viewtilexsiz, viewtileysiz);
@ -6681,7 +6681,7 @@ int app_main(int argc, char const * const * argv)
minitext_lowercase = 1;
for (int i = MINIFONT + ('a'-'!'); minitext_lowercase && i < MINIFONT + ('z'-'!') + 1; ++i)
minitext_lowercase &= (int)tileLoad(i);
minitext_lowercase &= (int)tileCheck(i);
if (g_networkMode != NET_DEDICATED_SERVER)
{

View file

@ -585,6 +585,8 @@ size_t __fastcall Gv_GetArrayCountForAllocSize(int const arrayIdx, size_t const
return tabledivide64(filelength + denominator - 1, denominator);
}
typedef int (*gamearray_func_cb)(int);
int __fastcall Gv_GetArrayValue(int const id, int index)
{
if (aGameArrays[id].flags & GAMEARRAY_STRIDE2)
@ -603,7 +605,14 @@ int __fastcall Gv_GetArrayValue(int const id, int index)
case GAMEARRAY_UINT8: returnValue = ((uint8_t *)aGameArrays[id].pValues)[index]; break;
case GAMEARRAY_BITMAP:returnValue = !!(((uint8_t *)aGameArrays[id].pValues)[index >> 3] & pow2char[index & 7]); break;
}
case GAMEARRAY_FUNC:
{
auto cb = (gamearray_func_cb)aGameArrays[id].pValues;
returnValue = cb(index);
}
}
return returnValue;
}
@ -1122,6 +1131,17 @@ void Gv_FinalizeWeaponDefaults(void)
static int32_t lastvisinc;
#endif
// Helpers to read the refactored tilesiz array.
static int tileWidth(int num)
{
return tilesiz[num].x;
}
static int tileHeight(int num)
{
return tilesiz[num].y;
}
static void Gv_AddSystemVars(void)
{
// only call ONCE
@ -1322,8 +1342,8 @@ static void Gv_AddSystemVars(void)
Gv_NewArray("gotpic", (void *)&gotpic[0], MAXTILES, GAMEARRAY_SYSTEM | GAMEARRAY_BITMAP);
Gv_NewArray("radiusdmgstatnums", (void *)&g_radiusDmgStatnums[0], MAXSTATUS, GAMEARRAY_SYSTEM | GAMEARRAY_BITMAP);
Gv_NewArray("show2dsector", (void *)&show2dsector[0], MAXSECTORS, GAMEARRAY_SYSTEM | GAMEARRAY_BITMAP);
Gv_NewArray("tilesizx", (void *)&tilesiz[0].x, MAXTILES, GAMEARRAY_SYSTEM | GAMEARRAY_STRIDE2 | GAMEARRAY_READONLY | GAMEARRAY_INT16);
Gv_NewArray("tilesizy", (void *)&tilesiz[0].y, MAXTILES, GAMEARRAY_SYSTEM | GAMEARRAY_STRIDE2 | GAMEARRAY_READONLY | GAMEARRAY_INT16);
Gv_NewArray("tilesizx", (void *)tileWidth, MAXTILES, GAMEARRAY_SYSTEM | GAMEARRAY_FUNC | GAMEARRAY_READONLY);
Gv_NewArray("tilesizy", (void *)tileHeight, MAXTILES, GAMEARRAY_SYSTEM | GAMEARRAY_FUNC | GAMEARRAY_READONLY);
#endif
}

View file

@ -314,7 +314,7 @@ int32_t G_LoadSaveHeaderNew(char const *fn, savehead_t *saveh)
if (kread(fil, &screenshotofs, 4) != 4)
goto corrupt;
tileCreate(TILE_LOADSHOT, 200, 320);
TileFiles.tileCreate(TILE_LOADSHOT, 200, 320);
if (screenshotofs)
{
if (kdfread_LZ4(tileData(TILE_LOADSHOT), 320, 200, fil) != 200)

View file

@ -436,7 +436,7 @@ void G_AnimateCamSprite(int smoothRatio)
int const viewscrTile = TILE_VIEWSCR - viewscrShift;
if (tileData(viewscrTile) ==nullptr)
tileCreate(viewscrTile, tilesiz[PN(spriteNum)].x << viewscrShift, tilesiz[PN(spriteNum)].y << viewscrShift);
TileFiles.tileCreate(viewscrTile, tilesiz[PN(spriteNum)].x << viewscrShift, tilesiz[PN(spriteNum)].y << viewscrShift);
G_SetupCamTile(OW(spriteNum), viewscrTile, smoothRatio);
#ifdef POLYMER

View file

@ -470,7 +470,7 @@ int32_t Anim_Play(const char *fn)
anim->animbuf = buffer.Data();
tileCreate(TILE_ANIM, 200, 320);
TileFiles.tileCreate(TILE_ANIM, 200, 320);
kread(handle, anim->animbuf, length);
kclose(handle);
@ -520,7 +520,7 @@ int32_t Anim_Play(const char *fn)
if (totalclock < ototalclock - 1)
continue;
tileSetExternal(TILE_ANIM, 200, 320, ANIM_DrawFrame(i));
TileFiles.tileSetExternal(TILE_ANIM, 200, 320, ANIM_DrawFrame(i));
tileInvalidate(TILE_ANIM, 0, 1 << 4); // JBF 20031228
if (I_CheckAllInput())

View file

@ -910,7 +910,7 @@ static void G_ReadGLFrame(void)
const int32_t xf = divscale16(ydim*4/3, 320);
const int32_t yf = divscale16(ydim, 200); // (ydim<<16)/200
auto pic = tileCreate(TILE_SAVESHOT, 200, 320);
auto pic = TileFiles.tileCreate(TILE_SAVESHOT, 200, 320);
if (!frame)
{
@ -1035,7 +1035,7 @@ void G_DrawRooms(int32_t playerNum, int32_t smoothRatio)
if (g_screenCapture)
{
tileCreate(TILE_SAVESHOT, 200, 320);
TileFiles.tileCreate(TILE_SAVESHOT, 200, 320);
if (videoGetRenderMode() == REND_CLASSIC)
renderSetTarget(TILE_SAVESHOT, 200, 320);
@ -1093,7 +1093,7 @@ void G_DrawRooms(int32_t playerNum, int32_t smoothRatio)
const int32_t viewtilexsiz = (tang&1023) ? tiltcx : tiltcy;
const int32_t viewtileysiz = tiltcx;
tileCreate(TILE_TILT, tiltcx, tiltcx);
TileFiles.tileCreate(TILE_TILT, tiltcx, tiltcx);
renderSetTarget(TILE_TILT, viewtilexsiz, viewtileysiz);
@ -8064,7 +8064,7 @@ int app_main(int argc, char const * const * argv)
minitext_lowercase = 1;
for (bssize_t i = MINIFONT + ('a'-'!'); minitext_lowercase && i < MINIFONT + ('z'-'!') + 1; ++i)
minitext_lowercase &= (int)tileLoad(i);
minitext_lowercase &= (int)tileCheck(i);
//if (g_networkMode != NET_DEDICATED_SERVER)
{

View file

@ -294,7 +294,7 @@ int32_t G_LoadSaveHeaderNew(char const *fn, savehead_t *saveh)
if (kread(fil, &screenshotofs, 4) != 4)
goto corrupt;
tileCreate(TILE_LOADSHOT, 200, 320);
TileFiles.tileCreate(TILE_LOADSHOT, 200, 320);
if (screenshotofs)
{
if (kdfread_LZ4(tileData(TILE_LOADSHOT), 320, 200, fil) != 200)

View file

@ -542,7 +542,7 @@ void G_AnimateCamSprite(int smoothRatio)
int const viewscrTile = TILE_VIEWSCR - viewscrShift;
if (tileData(viewscrTile) == nullptr)
tileCreate(viewscrTile, tilesiz[PN(spriteNum)].x << viewscrShift, tilesiz[PN(spriteNum)].y << viewscrShift);
TileFiles.tileCreate(viewscrTile, tilesiz[PN(spriteNum)].x << viewscrShift, tilesiz[PN(spriteNum)].y << viewscrShift);
G_SetupCamTile(OW(spriteNum), viewscrTile, smoothRatio);
#ifdef POLYMER

View file

@ -315,7 +315,7 @@ playanm(short anim_num)
if (ANIMnum == 1)
{
// draw the first frame
tileSetExternal(ANIM_TILE(ANIMnum), 200, 320, ANIM_DrawFrame(1));
TileFiles.tileSetExternal(ANIM_TILE(ANIMnum), 200, 320, ANIM_DrawFrame(1));
tileInvalidate(ANIM_TILE(ANIMnum), 0, 1<<4);
rotatesprite(0 << 16, 0 << 16, 65536L, 512, ANIM_TILE(ANIMnum), 0, 0, 2 + 4 + 8 + 16 + 64, 0, 0, xdim - 1, ydim - 1);
}
@ -362,7 +362,7 @@ playanm(short anim_num)
break;
}
tileSetExternal(ANIM_TILE(ANIMnum), 200, 320, ANIM_DrawFrame(1));
TileFiles.tileSetExternal(ANIM_TILE(ANIMnum), 200, 320, ANIM_DrawFrame(1));
tileInvalidate(ANIM_TILE(ANIMnum), 0, 1<<4);
rotatesprite(0 << 16, 0 << 16, 65536L, 512, ANIM_TILE(ANIMnum), 0, 0, 2 + 4 + 8 + 16 + 64, 0, 0, xdim - 1, ydim - 1);

View file

@ -2693,8 +2693,7 @@ ScreenLoadSaveSetup(PLAYERp pp)
ScreenTileLock();
tileDelete(SAVE_SCREEN_TILE);
tileCreate(SAVE_SCREEN_TILE, SAVE_SCREEN_XSIZE, SAVE_SCREEN_YSIZE);
TileFiles.tileCreate(SAVE_SCREEN_TILE, SAVE_SCREEN_XSIZE, SAVE_SCREEN_YSIZE);
return SAVE_SCREEN_TILE;
}

View file

@ -487,7 +487,7 @@ JS_InitMirrors(void)
void drawroomstotile(int daposx, int daposy, int daposz,
short daang, int dahoriz, short dacursectnum, short tilenume)
{
tileCreate(tilenume, tilesiz[tilenume].x, tilesiz[tilenume].y);
TileFiles.tileCreate(tilenume, tilesiz[tilenume].x, tilesiz[tilenume].y);
renderSetTarget(tilenume, tilesiz[tilenume].x, tilesiz[tilenume].y);
@ -857,7 +857,7 @@ JS_DrawMirrors(PLAYERp pp, int tx, int ty, int tz, short tpang, int tphoriz)
// Set up the tile for drawing
tileCreate(mirror[cnt].campic, 128, 128);
TileFiles.tileCreate(mirror[cnt].campic, 128, 128);
if (MirrorMoveSkip16 == 0 || (DoCam && (MoveSkip4 == 0)))
{