Skip to content

Commit

Permalink
Merge remote-tracking branch 'eduke32/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendricks266 committed Sep 4, 2023
2 parents 7e3541f + d7c2c9b commit 6b8326c
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 25 deletions.
18 changes: 14 additions & 4 deletions source/build/src/clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1903,7 +1903,7 @@ int pushmove(vec3_t *const vect, int16_t *const sectnum,
{
int16_t const os = *sectnum;
clipupdatesector(*vect, sectnum, walldist);
if (enginecompatibilitymode == ENGINE_EDUKE32 && *sectnum < 0)
if (*sectnum < 0)
{
vect->xy = ov;
*sectnum = os;
Expand Down Expand Up @@ -2623,7 +2623,7 @@ static void hitscan_sprite(const vec3_t *sv, int16_t spriteClipSector, int32_t v
x1 = spr->x; y1 = spr->y; z1 = spr->z;
switch (cstat&CSTAT_SPRITE_ALIGNMENT)
{
case 0:
case CSTAT_SPRITE_ALIGNMENT_FACING:
{
if (try_facespr_intersect(spr, *sv, vx, vy, vz, &hit->xyz, 0))
{
Expand Down Expand Up @@ -2938,8 +2938,18 @@ int32_t hitscan(const vec3_t *sv, int16_t sectnum, int32_t vx, int32_t vy, int32
else
{
int32_t daz2;
getzsofslope(dasector,intx,inty,&daz,&daz2);
if (intz >= daz && intz <= daz2)
bool comparison;
if (enginecompatibilitymode == ENGINE_EDUKE32)
{
getzsofslope(dasector,intx,inty,&daz,&daz2);
comparison = intz >= daz && intz <= daz2;
}
else
{
comparison = true;
}

if (comparison)
{
if ((nextsector < 0) || (wal->cstat&dawalclipmask))
{
Expand Down
30 changes: 29 additions & 1 deletion source/build/src/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12639,10 +12639,38 @@ int32_t cansee_19950829(int32_t xs, int32_t ys, int32_t zs, int16_t sectnums, in
return 0;
}

int32_t cansee(int32_t x1, int32_t y1, int32_t z1, int16_t sect1, int32_t x2, int32_t y2, int32_t z2, int16_t sect2, int32_t wallmask)
int32_t cansee(int32_t x1, int32_t y1, int32_t z1, int16_t orig_sect1, int32_t x2, int32_t y2, int32_t z2, int16_t orig_sect2, int32_t wallmask)
{
MICROPROFILE_SCOPEI("Engine", EDUKE32_FUNCTION, MP_AUTO);

int16_t sect1 = orig_sect1;
int16_t sect2 = orig_sect2;

if (enginecompatibilitymode == ENGINE_EDUKE32)
{
// Failsafe: Try to correct the input sectors if the corresponding coordinates aren't actually within the given sector.
if (!inside_z_p(x1, y1, z1, sect1))
{
// DLOG_F(WARNING, "cansee: Origin coordinates x=%d, y=%d, z=%d are outside sector %d", x1, y1, z1, sect1);
updatesectorz(x1, y1, z1, &sect1);
if (sect1 < 0)
{
DLOG_F(WARNING, "cansee: Failed to correct origin sector, falling back to original sector %d", orig_sect1);
sect1 = orig_sect1;
}
}
if (!inside_z_p(x2, y2, z2, sect2))
{
// DLOG_F(WARNING, "cansee: Destination coordinates x=%d, y=%d, z=%d are outside sector %d", x2, y2, z2, sect2);
updatesectorz(x2, y2, z2, &sect2);
if (sect2 < 0)
{
DLOG_F(WARNING, "cansee: Failed to correct destination sector, falling back to original sector %d", orig_sect2);
sect2 = orig_sect2;
}
}
}

if (enginecompatibilitymode == ENGINE_19950829)
return cansee_19950829(x1, y1, z1, sect1, x2, y2, z2, sect2);
int32_t dacnt, danum;
Expand Down
64 changes: 44 additions & 20 deletions source/duke3d/src/actors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ void A_RadiusDamageObject_Internal(int const spriteNum, int const otherSprite, i
}
}

#define MAXDAMAGESECTORS 128
#define MAXDAMAGESECTORS 256

void A_RadiusDamage(int const spriteNum, int const blastRadius, int const dmg1, int const dmg2, int const dmg3, int const dmg4)
{
Expand All @@ -306,9 +306,9 @@ void A_RadiusDamage(int const spriteNum, int const blastRadius, int const dmg1,

auto const pSprite = (uspriteptr_t)&sprite[spriteNum];

int16_t numSectors, sectorList[MAXDAMAGESECTORS];
int16_t sectorListTotal, sectorList[MAXDAMAGESECTORS];
uint8_t * const sectorMap = (uint8_t *)Balloca(bitmap_size(numsectors));
bfirst_search_init(sectorList, sectorMap, &numSectors, numsectors, pSprite->sectnum);
bfirst_search_init(sectorList, sectorMap, &sectorListTotal, numsectors, pSprite->sectnum);

#ifndef EDUKE32_STANDALONE
int wallDamage = true;
Expand All @@ -327,10 +327,33 @@ void A_RadiusDamage(int const spriteNum, int const blastRadius, int const dmg1,
auto wallCanSee = (uint8_t *)Balloca(bitmap_size(numwalls));
Bmemset(wallCanSee, 0, bitmap_size(numwalls));

for (int sectorCount=0; sectorCount < numSectors; ++sectorCount)
for (int sectorCount=0; sectorCount < sectorListTotal; ++sectorCount)
{
int const sectorNum = sectorList[sectorCount];
auto const &listSector = sector[sectorNum];
int const origSector = sectorList[sectorCount];
auto const &listSector = sector[origSector];

#ifdef YAX_ENABLE
if (numyaxbunches > 0 && sectorListTotal < MAXDAMAGESECTORS)
{
int32_t yax_sect;
for (SECTORS_OF_BUNCH(yax_getbunch(origSector, YAX_CEILING), YAX_FLOOR, yax_sect))
{
if (sectorListTotal < MAXDAMAGESECTORS)
bfirst_search_try(sectorList, sectorMap, &sectorListTotal, yax_sect);
}

for (SECTORS_OF_BUNCH(yax_getbunch(origSector, YAX_FLOOR), YAX_CEILING, yax_sect))
{
if (sectorListTotal < MAXDAMAGESECTORS)
bfirst_search_try(sectorList, sectorMap, &sectorListTotal, yax_sect);
}

if (sectorListTotal == MAXDAMAGESECTORS) {
LOG_F(WARNING, "A_RadiusDamage (yax): Sprite %d tried to damage more than %d sectors!", spriteNum, MAXDAMAGESECTORS);
}
Bassert(sectorListTotal <= MAXDAMAGESECTORS);
}
#endif

vec2_t closest = {};
int32_t distance = INT32_MAX;
Expand All @@ -356,7 +379,7 @@ void A_RadiusDamage(int const spriteNum, int const blastRadius, int const dmg1,
closest = p;
}

int16_t aSector = sectorNum;
int16_t aSector = origSector;
vec3_t vect = { (((pWall->x + wall[pWall->point2].x) >> 1) + pSprite->x) >> 1,
(((pWall->y + wall[pWall->point2].y) >> 1) + pSprite->y) >> 1, pSprite->z };

Expand All @@ -365,7 +388,7 @@ void A_RadiusDamage(int const spriteNum, int const blastRadius, int const dmg1,
if (aSector == -1)
{
vect.xy = p;
aSector = sectorNum;
aSector = origSector;
}

bitmap_set(wallTouched, w);
Expand All @@ -386,36 +409,37 @@ void A_RadiusDamage(int const spriteNum, int const blastRadius, int const dmg1,
A_DamageWall_Internal(spriteNum, w, { p.x, p.y, pSprite->z }, pSprite->picnum);
}

int const nextSector = pWall->nextsector;
if (sectorListTotal < MAXDAMAGESECTORS)
{
int const nextSector = pWall->nextsector;

if (nextSector >= 0)
bfirst_search_try(sectorList, sectorMap, &numSectors, nextSector);
if (nextSector >= 0)
bfirst_search_try(sectorList, sectorMap, &sectorListTotal, nextSector);

if (numSectors == MAXDAMAGESECTORS)
{
LOG_F(WARNING, "Sprite %d tried to damage more than %d sectors!", spriteNum, MAXDAMAGESECTORS);
goto wallsfinished;
if (sectorListTotal == MAXDAMAGESECTORS)
LOG_F(WARNING, "A_RadiusDamage: Sprite %d tried to damage more than %d sectors!", spriteNum, MAXDAMAGESECTORS);
Bassert(sectorListTotal <= MAXDAMAGESECTORS);
}
}
}

if (distance >= blastRadius)
continue;

// Intentionally does not use TROR-aware function, so that potentially solid TROR surfaces may be damaged.
int32_t floorZ, ceilZ;
getzsofslope(sectorNum, closest.x, closest.y, &ceilZ, &floorZ);
getzsofslope(origSector, closest.x, closest.y, &ceilZ, &floorZ);

if (((ceilZ - pSprite->z) >> 8) < blastRadius)
Sect_DamageCeiling_Internal(spriteNum, sectorNum);
Sect_DamageCeiling_Internal(spriteNum, origSector);

if (((pSprite->z - floorZ) >> 8) < blastRadius)
Sect_DamageFloor_Internal(spriteNum, sectorNum);
Sect_DamageFloor_Internal(spriteNum, origSector);
}

wallsfinished:
int const randomZOffset = -ZOFFSET2 + (krand()&(ZOFFSET5-1));

for (int sectorCount=0; sectorCount < numSectors; ++sectorCount)
for (int sectorCount=0; sectorCount < sectorListTotal; ++sectorCount)
{
int damageSprite = headspritesect[sectorList[sectorCount]];

Expand Down

0 comments on commit 6b8326c

Please sign in to comment.