From 39b67b4086dc8e9ef2fdb7e8504f175433d6c05c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 1 Dec 2020 18:24:24 +0100 Subject: [PATCH] - SW: removed some very dangerous type casting. --- source/sw/src/game.h | 7 ++++++- source/sw/src/mclip.cpp | 2 +- source/sw/src/player.cpp | 18 +++++++++--------- source/sw/src/sector.cpp | 4 ++-- source/sw/src/skel.cpp | 2 +- source/sw/src/sounds.cpp | 4 ++-- source/sw/src/sprite.cpp | 6 +++--- source/sw/src/track.cpp | 4 ++-- source/sw/src/weapon.cpp | 21 +++++++++------------ 9 files changed, 35 insertions(+), 33 deletions(-) diff --git a/source/sw/src/game.h b/source/sw/src/game.h index 0843f5098..af62bf4f0 100644 --- a/source/sw/src/game.h +++ b/source/sw/src/game.h @@ -813,7 +813,12 @@ typedef struct struct PLAYERstruct { // variable that fit in the sprite or user structure - int32_t posx, posy, posz; + union + { + struct { int32_t posx, posy, posz; }; + vec3_t pos; + }; + // interpolation int oposx, oposy, oposz; diff --git a/source/sw/src/mclip.cpp b/source/sw/src/mclip.cpp index efcd4f2c4..50377e605 100644 --- a/source/sw/src/mclip.cpp +++ b/source/sw/src/mclip.cpp @@ -287,7 +287,7 @@ short RectClipTurn(PLAYERp pp, short new_ang, int *qx, int *qy, int *ox, int *oy for (i = 0; i < 4; i++) { vec2_t const p = { ox[i], oy[i] }; - rotatepoint(*(vec2_t *)&pp->posx, p, rot_ang, &xy[i]); + rotatepoint(pp->pos.vec2, p, rot_ang, &xy[i]); // cannot use sop->xmid and ymid because the SO is off the map at this point //rotatepoint(*(vec2_t *)&sop->xmid, p, rot_ang, &xy[i]); } diff --git a/source/sw/src/player.cpp b/source/sw/src/player.cpp index d7497b8ec..aaa04b0f1 100644 --- a/source/sw/src/player.cpp +++ b/source/sw/src/player.cpp @@ -2049,7 +2049,7 @@ DoPlayerSlide(PLAYERp pp) if (labs(pp->slide_xvect) < 12800 && labs(pp->slide_yvect) < 12800) pp->slide_xvect = pp->slide_yvect = 0; - push_ret = pushmove((vec3_t *)pp, &pp->cursectnum, ((int)pp->SpriteP->clipdist<<2), pp->ceiling_dist, pp->floor_dist, CLIPMASK_PLAYER); + push_ret = pushmove(&pp->pos, &pp->cursectnum, ((int)pp->SpriteP->clipdist<<2), pp->ceiling_dist, pp->floor_dist, CLIPMASK_PLAYER); if (push_ret < 0) { if (!TEST(pp->Flags, PF_DEAD)) @@ -2062,9 +2062,9 @@ DoPlayerSlide(PLAYERp pp) } return; } - clipmove((vec3_t *)pp, &pp->cursectnum, pp->slide_xvect, pp->slide_yvect, ((int)pp->SpriteP->clipdist<<2), pp->ceiling_dist, pp->floor_dist, CLIPMASK_PLAYER); + clipmove(&pp->pos, &pp->cursectnum, pp->slide_xvect, pp->slide_yvect, ((int)pp->SpriteP->clipdist<<2), pp->ceiling_dist, pp->floor_dist, CLIPMASK_PLAYER); PlayerCheckValidMove(pp); - push_ret = pushmove((vec3_t *)pp, &pp->cursectnum, ((int)pp->SpriteP->clipdist<<2), pp->ceiling_dist, pp->floor_dist, CLIPMASK_PLAYER); + push_ret = pushmove(&pp->pos, &pp->cursectnum, ((int)pp->SpriteP->clipdist<<2), pp->ceiling_dist, pp->floor_dist, CLIPMASK_PLAYER); if (push_ret < 0) { if (!TEST(pp->Flags, PF_DEAD)) @@ -2212,7 +2212,7 @@ DoPlayerMove(PLAYERp pp) } else { - push_ret = pushmove((vec3_t *)pp, &pp->cursectnum, ((int)pp->SpriteP->clipdist<<2), pp->ceiling_dist, pp->floor_dist - Z(16), CLIPMASK_PLAYER); + push_ret = pushmove(&pp->pos, &pp->cursectnum, ((int)pp->SpriteP->clipdist<<2), pp->ceiling_dist, pp->floor_dist - Z(16), CLIPMASK_PLAYER); if (push_ret < 0) { @@ -2235,11 +2235,11 @@ DoPlayerMove(PLAYERp pp) save_cstat = pp->SpriteP->cstat; RESET(pp->SpriteP->cstat, CSTAT_SPRITE_BLOCK); COVERupdatesector(pp->posx, pp->posy, &pp->cursectnum); - clipmove((vec3_t *)pp, &pp->cursectnum, pp->xvect, pp->yvect, ((int)pp->SpriteP->clipdist<<2), pp->ceiling_dist, pp->floor_dist, CLIPMASK_PLAYER); + clipmove(&pp->pos, &pp->cursectnum, pp->xvect, pp->yvect, ((int)pp->SpriteP->clipdist<<2), pp->ceiling_dist, pp->floor_dist, CLIPMASK_PLAYER); pp->SpriteP->cstat = save_cstat; PlayerCheckValidMove(pp); - push_ret = pushmove((vec3_t *)pp, &pp->cursectnum, ((int)pp->SpriteP->clipdist<<2), pp->ceiling_dist, pp->floor_dist - Z(16), CLIPMASK_PLAYER); + push_ret = pushmove(&pp->pos, &pp->cursectnum, ((int)pp->SpriteP->clipdist<<2), pp->ceiling_dist, pp->floor_dist - Z(16), CLIPMASK_PLAYER); if (push_ret < 0) { @@ -4913,7 +4913,7 @@ DoPlayerCurrent(PLAYERp pp) xvect = sectu->speed * synctics * bcos(sectu->ang) >> 4; yvect = sectu->speed * synctics * bsin(sectu->ang) >> 4; - push_ret = pushmove((vec3_t *)pp, &pp->cursectnum, ((int)pp->SpriteP->clipdist<<2), pp->ceiling_dist, pp->floor_dist, CLIPMASK_PLAYER); + push_ret = pushmove(&pp->pos, &pp->cursectnum, ((int)pp->SpriteP->clipdist<<2), pp->ceiling_dist, pp->floor_dist, CLIPMASK_PLAYER); if (push_ret < 0) { if (!TEST(pp->Flags, PF_DEAD)) @@ -4928,9 +4928,9 @@ DoPlayerCurrent(PLAYERp pp) } return; } - clipmove((vec3_t *)pp, &pp->cursectnum, xvect, yvect, ((int)pp->SpriteP->clipdist<<2), pp->ceiling_dist, pp->floor_dist, CLIPMASK_PLAYER); + clipmove(&pp->pos, &pp->cursectnum, xvect, yvect, ((int)pp->SpriteP->clipdist<<2), pp->ceiling_dist, pp->floor_dist, CLIPMASK_PLAYER); PlayerCheckValidMove(pp); - pushmove((vec3_t *)pp, &pp->cursectnum, ((int)pp->SpriteP->clipdist<<2), pp->ceiling_dist, pp->floor_dist, CLIPMASK_PLAYER); + pushmove(&pp->pos, &pp->cursectnum, ((int)pp->SpriteP->clipdist<<2), pp->ceiling_dist, pp->floor_dist, CLIPMASK_PLAYER); if (push_ret < 0) { if (!TEST(pp->Flags, PF_DEAD)) diff --git a/source/sw/src/sector.cpp b/source/sw/src/sector.cpp index 3ab172821..127d61fd4 100644 --- a/source/sw/src/sector.cpp +++ b/source/sw/src/sector.cpp @@ -1046,7 +1046,7 @@ SectorExp(short SpriteNum, short sectnum, short orig_ang, int zh) // setup vars needed by SectorExp changespritesect(SpriteNum, sectnum); - //setspritez(SpriteNum, (vec3_t *)sp); + //setspritez(SpriteNum, &sp->pos); getzsofslope(sp->sectnum, sp->x, sp->y, &u->hiz, &u->loz); // spawn explosion @@ -1154,7 +1154,7 @@ DoSpawnSpotsForKill(short match) change_sprite_stat(sn, STAT_NO_STATE); u->ActorActionFunc = DoSpawnSpot; u->WaitTics = SP_TAG5(sp) * 15; - setspritez(sn, (vec3_t *)sp); + setspritez(sn, &sp->pos); // setting for Killed u->LastDamage = 1; } diff --git a/source/sw/src/skel.cpp b/source/sw/src/skel.cpp index b63774966..a47971f8e 100644 --- a/source/sw/src/skel.cpp +++ b/source/sw/src/skel.cpp @@ -567,7 +567,7 @@ int DoSkelTeleport(short SpriteNum) else sp->y -= 512 + RANDOM_P2(1024); - setspritez(SpriteNum, (vec3_t *)sp); + setspritez(SpriteNum, &sp->pos); //COVERupdatesector(sp->x, sp->y, &sp->sectnum); if (sp->sectnum != -1) diff --git a/source/sw/src/sounds.cpp b/source/sw/src/sounds.cpp index 6fdbcc90b..4f513fd35 100644 --- a/source/sw/src/sounds.cpp +++ b/source/sw/src/sounds.cpp @@ -599,7 +599,7 @@ void GameInterface::UpdateSounds(void) listener.angle = -pp->angle.ang.asbuild() * BAngRadian; // Build uses a period of 2048. listener.velocity.Zero(); - listener.position = GetSoundPos((vec3_t*)&pp->posx); + listener.position = GetSoundPos(&pp->pos); listener.underwater = false; // This should probably use a real environment instead of the pitch hacking in S_PlaySound3D. // listenactor->waterlevel == 3; @@ -649,7 +649,7 @@ int _PlaySound(int num, SPRITEp sp, PLAYERp pp, vec3_t* pos, Voc3D_Flags flags, } else if (pp && !pos) { - pos = (vec3_t*)&pp->posx; + pos = &pp->pos; pp = nullptr; } } diff --git a/source/sw/src/sprite.cpp b/source/sw/src/sprite.cpp index 6a431210d..5fdd93364 100644 --- a/source/sw/src/sprite.cpp +++ b/source/sw/src/sprite.cpp @@ -5178,7 +5178,7 @@ DoGrating(short SpriteNum) } } - setspritez(SpriteNum, (vec3_t *)sp); + setspritez(SpriteNum, &sp->pos); return 0; } @@ -7308,7 +7308,7 @@ move_missile(short spritenum, int xchange, int ychange, int zchange, int ceildis } if (FAF_ConnectArea(sp->sectnum)) - setspritez(spritenum, (vec3_t *)sp); + setspritez(spritenum, &sp->pos); if (TEST(sector[sp->sectnum].extra, SECTFX_WARP_SECTOR)) { @@ -7508,7 +7508,7 @@ move_ground_missile(short spritenum, int xchange, int ychange, int ceildist, int //MissileWaterAdjust(spritenum); //if (FAF_ConnectArea(sp->sectnum)) - // setspritez(spritenum, (vec3_t *)sp); + // setspritez(spritenum, &sp->pos); if (TEST(sector[sp->sectnum].extra, SECTFX_WARP_SECTOR)) { diff --git a/source/sw/src/track.cpp b/source/sw/src/track.cpp index f26056362..7da1af38c 100644 --- a/source/sw/src/track.cpp +++ b/source/sw/src/track.cpp @@ -1881,7 +1881,7 @@ PlayerPart: // Does not necessarily move with the sector so must accout for // moving across sectors if (sop->xmid < MAXSO) // special case for operating SO's - setspritez(sop->sp_num[i], (vec3_t *)sp); + setspritez(sop->sp_num[i], &sp->pos); } u->oangdiff += getincangle(oldang, sp->ang); @@ -2058,7 +2058,7 @@ void UpdateSectorObjectSprites(SECTOR_OBJECTp sop) { sp = &sprite[sop->sp_num[i]]; - setspritez(sop->sp_num[i], (vec3_t *)sp); + setspritez(sop->sp_num[i], &sp->pos); } } diff --git a/source/sw/src/weapon.cpp b/source/sw/src/weapon.cpp index 8dfb1c0c0..919608eba 100644 --- a/source/sw/src/weapon.cpp +++ b/source/sw/src/weapon.cpp @@ -4681,7 +4681,7 @@ WeaponMoveHit(short SpriteNum) // clipmove does not correctly return the sprite for WALL sprites // on walls, so look with hitscan - hitscan((vec3_t *)sp, sp->sectnum, // Start position + hitscan(&sp->pos, sp->sectnum, // Start position bcos(sp->ang), // X vector of 3D ang bsin(sp->ang), // Y vector of 3D ang sp->zvel, // Z vector of 3D ang @@ -12831,7 +12831,7 @@ DoRing(int16_t Weapon) //sp->ang = NORM_ANGLE(sp->ang + 512); //updatesector(sp->x, sp->y); - setsprite(Weapon, (vec3_t *)sp); + setsprite(Weapon, &sp->pos); ASSERT(sp->sectnum >= 0); @@ -12976,7 +12976,7 @@ DoSerpRing(int16_t Weapon) sp->x += mulscale14(u->Dist, bcos(u->slide_ang)); sp->y += mulscale14(u->Dist, bsin(u->slide_ang)); - setsprite(Weapon, (vec3_t *)sp); + setsprite(Weapon, &sp->pos); ASSERT(sp->sectnum >= 0); @@ -17773,8 +17773,7 @@ HitscanSpriteAdjust(short SpriteNum, short hit_wall) // must have this sectnum = sp->sectnum; - clipmove((vec3_t *)sp, §num, xvect, yvect, - 4L, 4L<<8, 4L<<8, CLIPMASK_MISSILE); + clipmove(&sp->pos, §num, xvect, yvect, 4L, 4L<<8, 4L<<8, CLIPMASK_MISSILE); clipmoveboxtracenum = 3; if (sp->sectnum != sectnum) @@ -19109,7 +19108,7 @@ InitEnemyUzi(short SpriteNum) // Make sprite shade brighter u->Vis = 128; - setspritez(SpriteNum, (vec3_t *)sp); + setspritez(SpriteNum, &sp->pos); if (u->ID == ZILLA_RUN_R0) { @@ -20635,8 +20634,7 @@ int QueueHole(short hit_sect, short hit_wall, int hit_x, int hit_y, int hit_z) sectnum = sp->sectnum; clipmoveboxtracenum = 1; - clipmove((vec3_t *)sp, §num, nx, ny, - 0L, 0L, 0L, CLIPMASK_MISSILE); + clipmove(&sp->pos, §num, nx, ny, 0L, 0L, 0L, CLIPMASK_MISSILE); clipmoveboxtracenum = 3; if (sp->sectnum != sectnum) @@ -20954,8 +20952,7 @@ int QueueWallBlood(short hit_sprite, short ang) sectnum = sp->sectnum; clipmoveboxtracenum = 1; - clipmove((vec3_t *)sp, §num, nx, ny, - 0L, 0L, 0L, CLIPMASK_MISSILE); + clipmove(&sp->pos, §num, nx, ny, 0L, 0L, 0L, CLIPMASK_MISSILE); clipmoveboxtracenum = 3; if (sp->sectnum != sectnum) @@ -21092,7 +21089,7 @@ int QueueGeneric(short SpriteNum, short pic) { // move old sprite to new sprite's place osp = &sprite[GenericQueue[GenericQueueHead]]; - //setspritez(GenericQueue[GenericQueueHead], (vec3_t *)sp); + //setspritez(GenericQueue[GenericQueueHead], &sp->pos); osp->x = sp->x; osp->y = sp->y; osp->z = sp->z; @@ -21645,7 +21642,7 @@ int QueueLoWangs(short SpriteNum) else { // move old sprite to new sprite's place - setspritez(LoWangsQueue[LoWangsQueueHead], (vec3_t *)sp); + setspritez(LoWangsQueue[LoWangsQueueHead], &sp->pos); NewSprite = LoWangsQueue[LoWangsQueueHead]; ASSERT(sprite[NewSprite].statnum != MAXSTATUS); }