- animateoffs cleanup and consolidation

This was rewritten based on specs alone - it still doesn’t look that different due to its simplicity.
This commit is contained in:
Christoph Oelckers 2022-08-05 18:47:35 +02:00
parent 83c0ad55f2
commit 4f2170655c
15 changed files with 68 additions and 140 deletions

View file

@ -268,15 +268,4 @@ extern int32_t rintersect(int32_t x1, int32_t y1, int32_t z1,
void updateModelInterpolation(); void updateModelInterpolation();
inline void tileUpdatePicnum(int* const tileptr, int const obj, int stat)
{
auto& tile = *tileptr;
if (picanm[tile].sf & PICANM_ANIMTYPE_MASK)
tile += animateoffs(tile, obj);
if (((obj & 16384) == 16384) && (stat & CSTAT_WALL_ROTATE_90) && RotTile(tile).newtile != -1)
tile = RotTile(tile).newtile;
}
#endif // build_h_ #endif // build_h_

View file

@ -1467,7 +1467,7 @@ int hitscan(const vec3_t& start, const sectortype* startsect, const vec3_t& dire
{ {
if (picanm[tilenum].sf&PICANM_TEXHITSCAN_BIT) if (picanm[tilenum].sf&PICANM_TEXHITSCAN_BIT)
{ {
tileUpdatePicnum(&tilenum, 0, 0); tileUpdatePicnum(&tilenum);
if (tileLoad(tilenum)) if (tileLoad(tilenum))
{ {

View file

@ -49,43 +49,6 @@ static int16_t radarang[1280];
// Internal Engine Functions // Internal Engine Functions
// //
BEGIN_BLD_NS
int qanimateoffs(int a1, int a2);
END_BLD_NS
//
// animateoffs (internal)
//
int32_t animateoffs(int const tilenum, int fakevar)
{
if (isBlood())
{
return Blood::qanimateoffs(tilenum, fakevar);
}
int const animnum = picanm[tilenum].num;
if (animnum <= 0)
return 0;
int const i = (int) I_GetBuildTime() >> (picanm[tilenum].sf & PICANM_ANIMSPEED_MASK);
int offs = 0;
switch (picanm[tilenum].sf & PICANM_ANIMTYPE_MASK)
{
case PICANM_ANIMTYPE_OSC:
{
int k = (i % (animnum << 1));
offs = (k < animnum) ? k : (animnum << 1) - k;
}
break;
case PICANM_ANIMTYPE_FWD: offs = i % (animnum + 1); break;
case PICANM_ANIMTYPE_BACK: offs = -(i % (animnum + 1)); break;
}
return offs;
}
void engineInit(void) void engineInit(void)
{ {
int32_t i; int32_t i;

View file

@ -408,16 +408,16 @@ void checkRotatedWalls()
{ {
if (w.cstat & CSTAT_WALL_ROTATE_90) if (w.cstat & CSTAT_WALL_ROTATE_90)
{ {
auto& tile = RotTile(w.picnum + animateoffs(w.picnum, 16384)); int picnum = w.picnum;
tileUpdatePicnum(&picnum);
auto& tile = RotTile(picnum);
if (tile.newtile == -1 && tile.owner == -1) if (tile.newtile == -1 && tile.owner == -1)
{ {
auto owner = w.picnum + animateoffs(w.picnum, 16384); tile.newtile = TileFiles.tileCreateRotated(picnum);
tile.newtile = TileFiles.tileCreateRotated(owner);
assert(tile.newtile != -1); assert(tile.newtile != -1);
RotTile(tile.newtile).owner = w.picnum + animateoffs(w.picnum, 16384); RotTile(tile.newtile).owner = picnum;
} }
} }

View file

@ -56,8 +56,7 @@ void hud_drawsprite(double sx, double sy, double sz, double a, int picnum, int d
alpha *= (dastat & RS_TRANS1)? glblend[0].def[!!(dastat & RS_TRANS2)].alpha : 1.; alpha *= (dastat & RS_TRANS1)? glblend[0].def[!!(dastat & RS_TRANS2)].alpha : 1.;
int palid = TRANSLATION(Translation_Remap + curbasepal, dapalnum); int palid = TRANSLATION(Translation_Remap + curbasepal, dapalnum);
if (picanm[picnum].sf & PICANM_ANIMTYPE_MASK) tileUpdatePicnum(&picnum);
picnum += animateoffs(picnum, 0);
auto tex = tileGetTexture(picnum); auto tex = tileGetTexture(picnum);

View file

@ -285,7 +285,7 @@ void HWDrawInfo::DispatchSprites()
actor->spr.cstat2 |= CSTAT2_SPRITE_MAPPED; actor->spr.cstat2 |= CSTAT2_SPRITE_MAPPED;
if ((tspr->cstat & CSTAT_SPRITE_ALIGNMENT_MASK) != CSTAT_SPRITE_ALIGNMENT_SLAB) if ((tspr->cstat & CSTAT_SPRITE_ALIGNMENT_MASK) != CSTAT_SPRITE_ALIGNMENT_SLAB)
tileUpdatePicnum(&tilenum, (actor->GetIndex() & 16383) + 32768, 0); tileUpdatePicnum(&tilenum, false, (actor->GetIndex() & 16383));
tspr->picnum = tilenum; tspr->picnum = tilenum;
gotpic.Set(tilenum); gotpic.Set(tilenum);

View file

@ -355,7 +355,7 @@ void HWFlat::ProcessSector(HWDrawInfo *di, sectortype * frontsector, int section
{ {
int tilenum = frontsector->floorpicnum; int tilenum = frontsector->floorpicnum;
gotpic.Set(tilenum); gotpic.Set(tilenum);
tileUpdatePicnum(&tilenum, tilenum, 0); tileUpdatePicnum(&tilenum);
texture = tileGetTexture(tilenum); texture = tileGetTexture(tilenum);
if (texture && texture->isValid()) if (texture && texture->isValid())
{ {
@ -399,7 +399,7 @@ void HWFlat::ProcessSector(HWDrawInfo *di, sectortype * frontsector, int section
int tilenum = frontsector->ceilingpicnum; int tilenum = frontsector->ceilingpicnum;
gotpic.Set(tilenum); gotpic.Set(tilenum);
tileUpdatePicnum(&tilenum, tilenum, 0); tileUpdatePicnum(&tilenum);
texture = tileGetTexture(tilenum); texture = tileGetTexture(tilenum);
if (texture && texture->isValid()) if (texture && texture->isValid())
{ {

View file

@ -44,7 +44,7 @@ FGameTexture* SkyboxReplacement(FTextureID picnum, int palnum);
void initSkyInfo(HWDrawInfo *di, HWSkyInfo* sky, sectortype* sector, int plane) void initSkyInfo(HWDrawInfo *di, HWSkyInfo* sky, sectortype* sector, int plane)
{ {
int picnum = plane == plane_ceiling ? sector->ceilingpicnum : sector->floorpicnum; int picnum = plane == plane_ceiling ? sector->ceilingpicnum : sector->floorpicnum;
tileUpdatePicnum(&picnum, 0, 0); tileUpdatePicnum(&picnum);
int palette = plane == plane_ceiling ? sector->ceilingpal : sector->floorpal; int palette = plane == plane_ceiling ? sector->ceilingpal : sector->floorpal;
FGameTexture* skytex = SkyboxReplacement(tileGetTexture(picnum)->GetID(), palette); FGameTexture* skytex = SkyboxReplacement(tileGetTexture(picnum)->GetID(), palette);

View file

@ -1000,7 +1000,7 @@ void HWWall::Process(HWDrawInfo* di, walltype* wal, sectortype* frontsector, sec
int tilenum = ((wal->cstat & CSTAT_WALL_1WAY) && wal->nextwall != -1) ? wal->overpicnum : wal->picnum; int tilenum = ((wal->cstat & CSTAT_WALL_1WAY) && wal->nextwall != -1) ? wal->overpicnum : wal->picnum;
gotpic.Set(tilenum); gotpic.Set(tilenum);
tileUpdatePicnum(&tilenum, wallnum(wal) + 16384, wal->cstat); tileUpdatePicnum(&tilenum, (wal->cstat & CSTAT_WALL_ROTATE_90));
texture = tileGetTexture(tilenum); texture = tileGetTexture(tilenum);
if (texture && texture->isValid()) if (texture && texture->isValid())
{ {
@ -1038,7 +1038,7 @@ void HWWall::Process(HWDrawInfo* di, walltype* wal, sectortype* frontsector, sec
{ {
int tilenum = wal->picnum; int tilenum = wal->picnum;
gotpic.Set(tilenum); gotpic.Set(tilenum);
tileUpdatePicnum(&tilenum, wallnum(wal) + 16384, wal->cstat); tileUpdatePicnum(&tilenum, (wal->cstat & CSTAT_WALL_ROTATE_90));
texture = tileGetTexture(tilenum); texture = tileGetTexture(tilenum);
if (texture && texture->isValid()) if (texture && texture->isValid())
{ {
@ -1051,7 +1051,7 @@ void HWWall::Process(HWDrawInfo* di, walltype* wal, sectortype* frontsector, sec
{ {
int tilenum = wal->overpicnum; int tilenum = wal->overpicnum;
gotpic.Set(tilenum); gotpic.Set(tilenum);
tileUpdatePicnum(&tilenum, wallnum(wal) + 16384, wal->cstat); tileUpdatePicnum(&tilenum, (wal->cstat & CSTAT_WALL_ROTATE_90));
texture = tileGetTexture(tilenum); texture = tileGetTexture(tilenum);
if (texture && texture->isValid()) if (texture && texture->isValid())
{ {
@ -1077,7 +1077,7 @@ void HWWall::Process(HWDrawInfo* di, walltype* wal, sectortype* frontsector, sec
auto w = (wal->cstat & CSTAT_WALL_BOTTOM_SWAP) ? backwall : wal; auto w = (wal->cstat & CSTAT_WALL_BOTTOM_SWAP) ? backwall : wal;
int tilenum = w->picnum; int tilenum = w->picnum;
gotpic.Set(tilenum); gotpic.Set(tilenum);
tileUpdatePicnum(&tilenum, wallnum(wal) + 16384, w->cstat); tileUpdatePicnum(&tilenum, (w->cstat & CSTAT_WALL_ROTATE_90));
texture = tileGetTexture(tilenum); texture = tileGetTexture(tilenum);
if (texture && texture->isValid()) if (texture && texture->isValid())
{ {

View file

@ -800,6 +800,41 @@ void tileCopySection(int tilenum1, int sx1, int sy1, int xsiz, int ysiz, int til
TileFiles.InvalidateTile(tilenum2); TileFiles.InvalidateTile(tilenum2);
} }
//==========================================================================
//
// Retrieve animation offset
//
//==========================================================================
int tileAnimateOfs(int tilenum, int randomize)
{
int framecount = picanm[tilenum].num;
if (framecount > 0)
{
int frametime = PlayClock;
if (isBlood() && randomize)
{
frametime += Bcrc32(&randomize, 2, 0);
}
int curframe = (frametime & 0x7fffffff) >> (picanm[tilenum].sf & PICANM_ANIMSPEED_MASK);
switch (picanm[tilenum].sf & PICANM_ANIMTYPE_MASK)
{
case PICANM_ANIMTYPE_FWD:
return curframe % (framecount + 1);
case PICANM_ANIMTYPE_BACK:
return -(curframe % (framecount + 1));
case PICANM_ANIMTYPE_OSC:
curframe = curframe % (framecount << 1);
if (curframe >= framecount) return (framecount << 1) - curframe;
else return curframe;
}
}
return 0;
}
//========================================================================== //==========================================================================
// //
// Check if two tiles are the same // Check if two tiles are the same
@ -836,7 +871,7 @@ void tileUpdateAnimations()
{ {
if (TileFiles.tiledata[i].picanm.sf & PICANM_ANIMTYPE_MASK) if (TileFiles.tiledata[i].picanm.sf & PICANM_ANIMTYPE_MASK)
{ {
int j = i + animateoffs(i, 0); int j = i + tileAnimateOfs(i);
auto id1 = TileFiles.tiledata[i].texture->GetID(); auto id1 = TileFiles.tiledata[i].texture->GetID();
auto id2 = TileFiles.tiledata[j].texture->GetID(); auto id2 = TileFiles.tiledata[j].texture->GetID();

View file

@ -461,18 +461,25 @@ inline rottile_t& RotTile(int tile)
} }
int32_t animateoffs(int const tilenum, int fakevar); int tileAnimateOfs(int tilenum, int randomize = -1);
inline void tileUpdatePicnum(int* const tileptr, bool mayrotate = false, int randomize = -1)
{
auto& tile = *tileptr;
if (picanm[tile].sf & PICANM_ANIMTYPE_MASK)
tile += tileAnimateOfs(tile, randomize);
if (mayrotate && RotTile(tile).newtile != -1)
tile = RotTile(tile).newtile;
}
inline FGameTexture* tileGetTexture(int tile, bool animate = false) inline FGameTexture* tileGetTexture(int tile, bool animate = false)
{ {
assert((unsigned)tile < MAXTILES); assert((unsigned)tile < MAXTILES);
if (tile < 0 || tile >= MAXTILES) return nullptr; if (tile < 0 || tile >= MAXTILES) return nullptr;
if (animate) if (animate) tileUpdatePicnum(&tile);
{
if (TileFiles.tiledata[tile].picanm.sf & PICANM_ANIMTYPE_MASK)
tile += animateoffs(tile, 0);
}
return TileFiles.tiledata[tile].texture; return TileFiles.tiledata[tile].texture;
} }

View file

@ -53,7 +53,6 @@
#include "src/prediction.cpp" #include "src/prediction.cpp"
#include "src/preload.cpp" #include "src/preload.cpp"
#include "src/qav.cpp" #include "src/qav.cpp"
#include "src/replace.cpp"
#include "src/sbar.cpp" #include "src/sbar.cpp"
#include "src/sectorfx.cpp" #include "src/sectorfx.cpp"
#include "src/seq.cpp" #include "src/seq.cpp"

View file

@ -699,7 +699,7 @@ void viewProcessSprites(tspritetype* tsprite, int& spritesortcnt, int32_t cX, in
if ((pTSprite->cstat & CSTAT_SPRITE_ALIGNMENT_MASK) != CSTAT_SPRITE_ALIGNMENT_SLAB && r_voxels && !(owneractor->sprext.renderflags & SPREXT_NOTMD)) if ((pTSprite->cstat & CSTAT_SPRITE_ALIGNMENT_MASK) != CSTAT_SPRITE_ALIGNMENT_SLAB && r_voxels && !(owneractor->sprext.renderflags & SPREXT_NOTMD))
{ {
int const nRootTile = pTSprite->picnum; int const nRootTile = pTSprite->picnum;
int nAnimTile = pTSprite->picnum + qanimateoffs(pTSprite->picnum, 32768 + (pTSprite->ownerActor->GetIndex() & 16383)); int nAnimTile = pTSprite->picnum + tileAnimateOfs(pTSprite->picnum, (pTSprite->ownerActor->GetIndex() & 16383));
#if 0 #if 0
if (tiletovox[nAnimTile] != -1) if (tiletovox[nAnimTile] != -1)
@ -718,7 +718,7 @@ void viewProcessSprites(tspritetype* tsprite, int& spritesortcnt, int32_t cX, in
if ((pTSprite->cstat & CSTAT_SPRITE_ALIGNMENT_MASK) != CSTAT_SPRITE_ALIGNMENT_SLAB && hw_models && !(owneractor->sprext.renderflags & SPREXT_NOTMD)) if ((pTSprite->cstat & CSTAT_SPRITE_ALIGNMENT_MASK) != CSTAT_SPRITE_ALIGNMENT_SLAB && hw_models && !(owneractor->sprext.renderflags & SPREXT_NOTMD))
{ {
int const nRootTile = pTSprite->picnum; int const nRootTile = pTSprite->picnum;
int nAnimTile = pTSprite->picnum + qanimateoffs(pTSprite->picnum, 32768 + (pTSprite->ownerActor->GetIndex() & 16383)); int nAnimTile = pTSprite->picnum + tileAnimateOfs(pTSprite->picnum, (pTSprite->ownerActor->GetIndex() & 16383));
if (tile2model[Ptile2tile(nAnimTile, pTSprite->pal)].modelid >= 0 && if (tile2model[Ptile2tile(nAnimTile, pTSprite->pal)].modelid >= 0 &&
tile2model[Ptile2tile(nAnimTile, pTSprite->pal)].framenum >= 0) tile2model[Ptile2tile(nAnimTile, pTSprite->pal)].framenum >= 0)

View file

@ -88,7 +88,7 @@ static void viewBurnTime(int gScale)
for (int i = 0; i < 9; i++) for (int i = 0; i < 9; i++)
{ {
int nTile = burnTable[i].nTile + qanimateoffs(burnTable[i].nTile, 32768 + i); int nTile = burnTable[i].nTile + tileAnimateOfs(burnTable[i].nTile, i);
int nScale = burnTable[i].nScale; int nScale = burnTable[i].nScale;
if (gScale < 600) if (gScale < 600)
{ {

View file

@ -1,64 +0,0 @@
//-------------------------------------------------------------------------
/*
Copyright (C) 2010-2019 EDuke32 developers and contributors
Copyright (C) 2019 Nuke.YKT
This file is part of NBlood.
NBlood is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
//-------------------------------------------------------------------------
#include "ns.h" // Must come before everything else!
#include "blood.h"
#include "m_crc32.h"
BEGIN_BLD_NS
int qanimateoffs(int a1, int a2)
{
int offset = 0;
if (a1 >= 0 && a1 < kMaxTiles)
{
int frames = picanm[a1].num;
if (frames > 0)
{
int const frameClock = PlayClock;
int vd;
if ((a2&0xc000) == 0x8000)
vd = (Bcrc32(&a2, 2, 0)+frameClock)>>(picanm[a1].sf&PICANM_ANIMSPEED_MASK);
else
vd = frameClock>>(picanm[a1].sf&PICANM_ANIMSPEED_MASK);
switch (picanm[a1].sf&PICANM_ANIMTYPE_MASK)
{
case PICANM_ANIMTYPE_OSC:
offset = vd % (2*frames);
if (offset >= frames)
offset = 2*frames-offset;
break;
case PICANM_ANIMTYPE_FWD:
offset = vd % (frames+1);
break;
case PICANM_ANIMTYPE_BACK:
offset = -(vd % (frames+1));
break;
}
}
}
return offset;
}
END_BLD_NS