mirror of
https://github.com/ZDoom/Raze.git
synced 2024-11-15 17:01:28 +00:00
- Move Duke's getincangle()
function to the backend, create Q16.16 variant (getincangleq16()
) and replace Shadow Warrior's discrete implementations shared versions.
* Need SW's input helpers available for Blood but therefore also need an angle delta function that does not seem to exist in Blood. * Realise that gamecontrol.h/cpp might not be the most appropriate place, but it's a shared location and these will go into binaryangle.h when its utilisation can be more realised. * Because SW's logic was reversed, in that param #1 was the new angle and param #2 was the current, all calls have been reversed. * By happenstance, also fixes an issue with multiple 180° turns in quick succession.
This commit is contained in:
parent
db7793bf54
commit
1900cf1fcc
12 changed files with 74 additions and 98 deletions
|
@ -1446,3 +1446,44 @@ void LoadDefinitions()
|
|||
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// code fron gameexec/conrun
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
int getincangle(int a, int na)
|
||||
{
|
||||
a &= 2047;
|
||||
na &= 2047;
|
||||
|
||||
if(abs(a-na) < 1024)
|
||||
return (na-a);
|
||||
else
|
||||
{
|
||||
if(na > 1024) na -= 2048;
|
||||
if(a > 1024) a -= 2048;
|
||||
|
||||
na -= 2048;
|
||||
a -= 2048;
|
||||
return (na-a);
|
||||
}
|
||||
}
|
||||
|
||||
fixed_t getincangleq16(fixed_t a, fixed_t na)
|
||||
{
|
||||
a &= 0x7FFFFFF;
|
||||
na &= 0x7FFFFFF;
|
||||
|
||||
if(abs(a-na) < IntToFixed(1024))
|
||||
return (na-a);
|
||||
else
|
||||
{
|
||||
if(na > IntToFixed(1024)) na -= IntToFixed(2048);
|
||||
if(a > IntToFixed(1024)) a -= IntToFixed(2048);
|
||||
|
||||
na -= IntToFixed(2048);
|
||||
a -= IntToFixed(2048);
|
||||
return (na-a);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,6 +63,9 @@ void DeferedStartGame(MapRecord* map, int skill);
|
|||
void ChangeLevel(MapRecord* map, int skill);
|
||||
void CompleteLevel(MapRecord* map);
|
||||
|
||||
int getincangle(int c, int n);
|
||||
fixed_t getincangleq16(fixed_t c, fixed_t n);
|
||||
|
||||
struct UserConfig
|
||||
{
|
||||
FString gamegrp;
|
||||
|
|
|
@ -4667,31 +4667,6 @@ void handle_se130(int i, int countmax, int EXPLOSION2)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
// code fron gameexec/conrun
|
||||
//
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
int getincangle(int a,int na)
|
||||
{
|
||||
a &= 2047;
|
||||
na &= 2047;
|
||||
|
||||
if(abs(a-na) < 1024)
|
||||
return (na-a);
|
||||
else
|
||||
{
|
||||
if(na > 1024) na -= 2048;
|
||||
if(a > 1024) a -= 2048;
|
||||
|
||||
na -= 2048;
|
||||
a -= 2048;
|
||||
return (na-a);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
//
|
||||
//
|
||||
|
|
|
@ -165,7 +165,6 @@ void execute(int s, int p, int d);
|
|||
void makeitfall(int s);
|
||||
int furthestangle(int snum, int angDiv);
|
||||
void getglobalz(int s);
|
||||
int getincangle(int c, int n);
|
||||
void OnEvent(int id, int pnum = -1, int snum = -1, int dist = -1);
|
||||
|
||||
short EGS(short whatsect, int s_x, int s_y, int s_z, short s_pn, signed char s_s, signed char s_xr, signed char s_yr, short s_a, short s_ve, int s_zv, short s_ow, signed char s_ss);
|
||||
|
|
|
@ -1283,7 +1283,7 @@ void CameraView(PLAYERp pp, int *tx, int *ty, int *tz, short *tsectnum, fixed_t
|
|||
sp = &sprite[i];
|
||||
|
||||
ang = getangle(*tx - sp->x, *ty - sp->y);
|
||||
ang_test = GetDeltaAngle(sp->ang, ang) < sp->lotag;
|
||||
ang_test = getincangle(ang, sp->ang) < sp->lotag;
|
||||
|
||||
FAFcansee_test =
|
||||
(FAFcansee(sp->x, sp->y, sp->z, sp->sectnum, *tx, *ty, *tz, pp->cursectnum) ||
|
||||
|
|
|
@ -355,13 +355,13 @@ int StdRandomRange(int range);
|
|||
#define SQ(val) ((val) * (val))
|
||||
|
||||
#define KENFACING_PLAYER(pp,sp) (sintable[NORM_ANGLE(sp->ang+512)]*(pp->posy-sp->y) >= sintable[NORM_ANGLE(sp-ang)]*(pp->posx-sp->x))
|
||||
#define FACING_PLAYER(pp,sp) (abs(GetDeltaAngle((sp)->ang, NORM_ANGLE(getangle((pp)->posx - (sp)->x, (pp)->posy - (sp)->y)))) < 512)
|
||||
#define PLAYER_FACING(pp,sp) (abs(GetDeltaAngle(FixedToInt((pp)->q16ang), NORM_ANGLE(getangle((sp)->x - (pp)->posx, (sp)->y - (pp)->posy)))) < 320)
|
||||
#define FACING(sp1,sp2) (abs(GetDeltaAngle((sp2)->ang, NORM_ANGLE(getangle((sp1)->x - (sp2)->x, (sp1)->y - (sp2)->y)))) < 512)
|
||||
#define FACING_PLAYER(pp,sp) (abs(getincangle(getangle((pp)->posx - (sp)->x, (pp)->posy - (sp)->y), (sp)->ang)) < 512)
|
||||
#define PLAYER_FACING(pp,sp) (abs(getincangle(getangle((sp)->x - (pp)->posx, (sp)->y - (pp)->posy), FixedToInt((pp)->q16ang))) < 320)
|
||||
#define FACING(sp1,sp2) (abs(getincangle(getangle((sp1)->x - (sp2)->x, (sp1)->y - (sp2)->y), (sp2)->ang)) < 512)
|
||||
|
||||
#define FACING_PLAYER_RANGE(pp,sp,range) (abs(GetDeltaAngle((sp)->ang, NORM_ANGLE(getangle((pp)->posx - (sp)->x, (pp)->posy - (sp)->y)))) < (range))
|
||||
#define PLAYER_FACING_RANGE(pp,sp,range) (abs(GetDeltaAngle(FixedToInt((pp)->q16ang), NORM_ANGLE(getangle((sp)->x - (pp)->posx, (sp)->y - (pp)->posy)))) < (range))
|
||||
#define FACING_RANGE(sp1,sp2,range) (abs(GetDeltaAngle((sp2)->ang, NORM_ANGLE(getangle((sp1)->x - (sp2)->x, (sp1)->y - (sp2)->y)))) < (range))
|
||||
#define FACING_PLAYER_RANGE(pp,sp,range) (abs(getincangle(getangle((pp)->posx - (sp)->x, (pp)->posy - (sp)->y), (sp)->ang)) < (range))
|
||||
#define PLAYER_FACING_RANGE(pp,sp,range) (abs(getincangle(getangle((sp)->x - (pp)->posx, (sp)->y - (pp)->posy), FixedToInt((pp)->q16ang))) < (range))
|
||||
#define FACING_RANGE(sp1,sp2,range) (abs(getincangle(getangle((sp1)->x - (sp2)->x, (sp1)->y - (sp2)->y), (sp2)->ang)) < (range))
|
||||
|
||||
// two vectors
|
||||
// can determin direction
|
||||
|
@ -1846,8 +1846,6 @@ extern SECTOR_OBJECT SectorObject[MAX_SECTOR_OBJECTS];
|
|||
ANIMATOR NullAnimator;
|
||||
|
||||
int Distance(int x1, int y1, int x2, int y2);
|
||||
short GetDeltaAngle(short, short);
|
||||
fixed_t GetDeltaQ16Angle(fixed_t, fixed_t);
|
||||
|
||||
int SetActorRotation(short SpriteNum,int,int);
|
||||
int NewStateGroup(short SpriteNum, STATEp SpriteGroup[]);
|
||||
|
|
|
@ -314,7 +314,7 @@ static void processMovement(PLAYERp const pp, ControlInfo* const hidInput, bool
|
|||
|
||||
if (pp->angTarget)
|
||||
{
|
||||
fixed_t angDelta = GetDeltaQ16Angle(pp->angTarget, pp->q16ang);
|
||||
fixed_t angDelta = getincangleq16(pp->q16ang, pp->angTarget);
|
||||
pp->q16ang = (pp->q16ang + xs_CRoundToInt(scaleAdjust * angDelta));
|
||||
|
||||
if (abs(pp->q16ang - pp->angTarget) < FRACUNIT)
|
||||
|
|
|
@ -653,7 +653,7 @@ void JS_DrawCameras(PLAYERp pp, int tx, int ty, int tz)
|
|||
SP_TAG5(sp) = NORM_ANGLE((SP_TAG5(sp) + oscilation_delta));
|
||||
|
||||
// TAG6 = Turn radius
|
||||
if (klabs(GetDeltaAngle(SP_TAG5(sp), sp->ang)) >= SP_TAG6(sp))
|
||||
if (klabs(getincangle(sp->ang, SP_TAG5(sp))) >= SP_TAG6(sp))
|
||||
{
|
||||
SP_TAG5(sp) = NORM_ANGLE((SP_TAG5(sp) - oscilation_delta));
|
||||
RESET_BOOL3(sp); // Reverse turn
|
||||
|
@ -666,7 +666,7 @@ void JS_DrawCameras(PLAYERp pp, int tx, int ty, int tz)
|
|||
SP_TAG5(sp) = NORM_ANGLE((SP_TAG5(sp) - oscilation_delta));
|
||||
|
||||
// TAG6 = Turn radius
|
||||
if (klabs(GetDeltaAngle(SP_TAG5(sp), sp->ang)) >= SP_TAG6(sp))
|
||||
if (klabs(getincangle(sp->ang, SP_TAG5(sp))) >= SP_TAG6(sp))
|
||||
{
|
||||
SP_TAG5(sp) = NORM_ANGLE((SP_TAG5(sp) + oscilation_delta));
|
||||
SET_BOOL3(sp); // Reverse turn
|
||||
|
|
|
@ -1124,45 +1124,6 @@ void pSetVisNorm(PANEL_SPRITEp psp)
|
|||
// SetVisNorm();
|
||||
}
|
||||
|
||||
short
|
||||
GetDeltaAngle(short ang1, short ang2)
|
||||
{
|
||||
// Look at the smaller angle if > 1024 (180 degrees)
|
||||
if (labs(ang1 - ang2) > 1024)
|
||||
{
|
||||
if (ang1 <= 1024)
|
||||
ang1 += 2048;
|
||||
|
||||
if (ang2 <= 1024)
|
||||
ang2 += 2048;
|
||||
}
|
||||
|
||||
//if (ang1 - ang2 == -1024)
|
||||
// return(1024);
|
||||
|
||||
return ang1 - ang2;
|
||||
|
||||
}
|
||||
|
||||
fixed_t
|
||||
GetDeltaQ16Angle(fixed_t ang1, fixed_t ang2)
|
||||
{
|
||||
// Look at the smaller angle if > 1024 (180 degrees)
|
||||
if (abs(ang1 - ang2) > IntToFixed(1024))
|
||||
{
|
||||
if (ang1 <= IntToFixed(1024))
|
||||
ang1 += IntToFixed(2048);
|
||||
|
||||
if (ang2 <= IntToFixed(1024))
|
||||
ang2 += IntToFixed(2048);
|
||||
}
|
||||
|
||||
//if (ang1 - ang2 == -IntToFixed(1024))
|
||||
// return(IntToFixed(1024));
|
||||
|
||||
return ang1 - ang2;
|
||||
}
|
||||
|
||||
TARGET_SORT TargetSort[MAX_TARGET_SORT];
|
||||
unsigned TargetSortCount;
|
||||
|
||||
|
@ -1240,7 +1201,7 @@ DoPickTarget(SPRITEp sp, uint32_t max_delta_ang, int skip_targets)
|
|||
// Get the angle difference
|
||||
// delta_ang = labs(FixedToInt(pp->q16ang) - angle2);
|
||||
|
||||
delta_ang = labs(GetDeltaAngle(sp->ang, angle2));
|
||||
delta_ang = labs(getincangle(angle2, sp->ang));
|
||||
|
||||
// If delta_ang not in the range skip this one
|
||||
if (delta_ang > (int)max_delta_ang)
|
||||
|
@ -1561,7 +1522,7 @@ DoPlayerTurn(PLAYERp pp, fixed_t const q16avel, double const scaleAdjust)
|
|||
|
||||
// make the first turn in the clockwise direction
|
||||
// the rest will follow
|
||||
delta_ang = labs(GetDeltaQ16Angle(pp->turn180_target, pp->q16ang)) >> TURN_SHIFT;
|
||||
delta_ang = labs(getincangleq16(pp->q16ang, pp->turn180_target)) >> TURN_SHIFT;
|
||||
pp->q16ang = (pp->q16ang + xs_CRoundToInt(scaleAdjust * delta_ang)) & 0x7FFFFFF;
|
||||
|
||||
SET(pp->Flags, PF_TURN_180);
|
||||
|
@ -1577,7 +1538,7 @@ DoPlayerTurn(PLAYERp pp, fixed_t const q16avel, double const scaleAdjust)
|
|||
{
|
||||
fixed_t delta_ang;
|
||||
|
||||
delta_ang = GetDeltaQ16Angle(pp->turn180_target, pp->q16ang) >> TURN_SHIFT;
|
||||
delta_ang = getincangleq16(pp->q16ang, pp->turn180_target) >> TURN_SHIFT;
|
||||
pp->q16ang = (pp->q16ang + xs_CRoundToInt(scaleAdjust * delta_ang)) & 0x7FFFFFF;
|
||||
|
||||
sprite[pp->PlayerSprite].ang = FixedToInt(pp->q16ang);
|
||||
|
@ -1588,7 +1549,7 @@ DoPlayerTurn(PLAYERp pp, fixed_t const q16avel, double const scaleAdjust)
|
|||
}
|
||||
|
||||
// get new delta to see how close we are
|
||||
delta_ang = GetDeltaQ16Angle(pp->turn180_target, pp->q16ang);
|
||||
delta_ang = getincangleq16(pp->q16ang, pp->turn180_target);
|
||||
|
||||
if (labs(delta_ang) < (IntToFixed(3) << TURN_SHIFT))
|
||||
{
|
||||
|
@ -1723,7 +1684,7 @@ DoPlayerTurnTurret(PLAYERp pp, fixed_t q16avel)
|
|||
|
||||
if (sop->limit_ang_center >= 0)
|
||||
{
|
||||
diff = GetDeltaQ16Angle(new_ang, IntToFixed(sop->limit_ang_center));
|
||||
diff = getincangleq16(IntToFixed(sop->limit_ang_center), new_ang);
|
||||
|
||||
if (labs(diff) >= IntToFixed(sop->limit_ang_delta))
|
||||
{
|
||||
|
@ -6393,7 +6354,7 @@ void DoPlayerDeathFollowKiller(PLAYERp pp)
|
|||
|
||||
if (FAFcansee(kp->x, kp->y, SPRITEp_TOS(kp), kp->sectnum, pp->posx, pp->posy, pp->posz, pp->cursectnum))
|
||||
{
|
||||
playerAddAngle(pp, GetDeltaQ16Angle(gethiq16angle(kp->x - pp->posx, kp->y - pp->posy), pp->q16ang) / (double)(FRACUNIT << 4));
|
||||
playerAddAngle(pp, getincangleq16(pp->q16ang, gethiq16angle(kp->x - pp->posx, kp->y - pp->posy)) / (double)(FRACUNIT << 4));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6585,7 +6546,7 @@ void DoPlayerDeathMoveHead(PLAYERp pp)
|
|||
|
||||
|
||||
wall_ang = NORM_ANGLE(hsp->ang);
|
||||
dang = GetDeltaAngle(u->slide_ang, wall_ang);
|
||||
dang = getincangle(wall_ang, u->slide_ang);
|
||||
u->slide_ang = NORM_ANGLE(wall_ang + 1024 - dang);
|
||||
|
||||
SpawnShrap(pp->PlayerSprite, -1);
|
||||
|
@ -6602,7 +6563,7 @@ void DoPlayerDeathMoveHead(PLAYERp pp)
|
|||
nw = wall[w].point2;
|
||||
wall_ang = NORM_ANGLE(getangle(wall[nw].x - wall[w].x, wall[nw].y - wall[w].y)-512);
|
||||
|
||||
dang = GetDeltaAngle(u->slide_ang, wall_ang);
|
||||
dang = getincangle(wall_ang, u->slide_ang);
|
||||
u->slide_ang = NORM_ANGLE(wall_ang + 1024 - dang);
|
||||
|
||||
SpawnShrap(pp->PlayerSprite, -1);
|
||||
|
@ -7817,7 +7778,7 @@ void playerSetAngle(PLAYERp pp, double ang)
|
|||
ang += 0.1;
|
||||
}
|
||||
|
||||
pp->angTarget = pp->q16ang + GetDeltaQ16Angle(FloatToFixed(ang), pp->q16ang);
|
||||
pp->angTarget = pp->q16ang + getincangleq16(pp->q16ang, FloatToFixed(ang));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -108,7 +108,6 @@ int MissileZrange(short SpriteNum);
|
|||
#define ACTIVE_CHECK_TIME (3*120)
|
||||
|
||||
/*
|
||||
short GetDeltaAngle(short ang1, short ang2);
|
||||
short GetRotation(short sn);
|
||||
int StateControl(int16_t SpriteNum);
|
||||
void PreCacheRange(short, short);
|
||||
|
|
|
@ -931,7 +931,7 @@ SectorObjectSetupBounds(SECTOR_OBJECTp sop)
|
|||
sop->clipbox_vdist[sop->clipbox_num] = ksqrt(SQ(sop->xmid - sp->x) + SQ(sop->ymid - sp->y));
|
||||
|
||||
ang2 = getangle(sp->x - sop->xmid, sp->y - sop->ymid);
|
||||
sop->clipbox_ang[sop->clipbox_num] = GetDeltaAngle(sop->ang, ang2);
|
||||
sop->clipbox_ang[sop->clipbox_num] = getincangle(ang2, sop->ang);
|
||||
|
||||
sop->clipbox_num++;
|
||||
KillSprite(sp_num);
|
||||
|
@ -1678,7 +1678,7 @@ MovePlayer(PLAYERp pp, SECTOR_OBJECTp sop, int nx, int ny)
|
|||
|
||||
// New angle is formed by taking last known angle and
|
||||
// adjusting by the delta angle
|
||||
playerAddAngle(pp, GetDeltaQ16Angle(pp->RevolveQ16Ang + IntToFixed(pp->RevolveDeltaAng), pp->q16ang));
|
||||
playerAddAngle(pp, getincangleq16(pp->q16ang, pp->RevolveQ16Ang + IntToFixed(pp->RevolveDeltaAng)));
|
||||
|
||||
UpdatePlayerSprite(pp);
|
||||
}
|
||||
|
@ -1891,7 +1891,7 @@ PlayerPart:
|
|||
setspritez(sop->sp_num[i], (vec3_t *)sp);
|
||||
}
|
||||
|
||||
u->oangdiff += GetDeltaAngle(sp->ang, oldang);
|
||||
u->oangdiff += getincangle(oldang, sp->ang);
|
||||
|
||||
if (TEST(sp->extra, SPRX_BLADE))
|
||||
{
|
||||
|
@ -2384,7 +2384,7 @@ MoveSectorObjects(SECTOR_OBJECTp sop, short locktics)
|
|||
DoTrack(sop, locktics, &nx, &ny);
|
||||
|
||||
// get delta to target angle
|
||||
delta_ang = GetDeltaAngle(sop->ang_tgt, sop->ang);
|
||||
delta_ang = getincangle(sop->ang, sop->ang_tgt);
|
||||
|
||||
sop->ang = NORM_ANGLE(sop->ang + (delta_ang >> sop->turn_speed));
|
||||
delta_ang = delta_ang >> sop->turn_speed;
|
||||
|
@ -2896,7 +2896,7 @@ void TornadoSpin(SECTOR_OBJECTp sop)
|
|||
short locktics = synctics;
|
||||
|
||||
// get delta to target angle
|
||||
delta_ang = GetDeltaAngle(sop->ang_tgt, sop->ang);
|
||||
delta_ang = getincangle(sop->ang, sop->ang_tgt);
|
||||
|
||||
sop->ang = NORM_ANGLE(sop->ang + (delta_ang >> sop->turn_speed));
|
||||
delta_ang = delta_ang >> sop->turn_speed;
|
||||
|
@ -3026,7 +3026,7 @@ DoAutoTurretObject(SECTOR_OBJECTp sop)
|
|||
sop->ang_tgt = getangle(u->tgt_sp->x - sop->xmid, u->tgt_sp->y - sop->ymid);
|
||||
|
||||
// get delta to target angle
|
||||
delta_ang = GetDeltaAngle(sop->ang_tgt, sop->ang);
|
||||
delta_ang = getincangle(sop->ang, sop->ang_tgt);
|
||||
|
||||
//sop->ang += delta_ang >> 4;
|
||||
sop->ang = NORM_ANGLE(sop->ang + (delta_ang >> 3));
|
||||
|
@ -3034,7 +3034,7 @@ DoAutoTurretObject(SECTOR_OBJECTp sop)
|
|||
|
||||
if (sop->limit_ang_center >= 0)
|
||||
{
|
||||
diff = GetDeltaAngle(sop->ang, sop->limit_ang_center);
|
||||
diff = getincangle(sop->limit_ang_center, sop->ang);
|
||||
|
||||
if (labs(diff) >= sop->limit_ang_delta)
|
||||
{
|
||||
|
|
|
@ -8310,9 +8310,9 @@ MissileSeek(int16_t Weapon, int16_t delay_tics, int16_t aware_range/*, int16_t d
|
|||
hp = &sprite[User[Weapon]->WpnGoal];
|
||||
|
||||
// move to correct angle
|
||||
ang2tgt = getangle(hp->x - sp->x, hp->y - sp->y);
|
||||
ang2tgt = getangle(hp->y - sp->y, hp->x - sp->x);
|
||||
|
||||
delta_ang = GetDeltaAngle(sp->ang, ang2tgt);
|
||||
delta_ang = getincangle(sp->ang, ang2tgt);
|
||||
|
||||
if (labs(delta_ang) > 32)
|
||||
{
|
||||
|
@ -8386,7 +8386,7 @@ ComboMissileSeek(int16_t Weapon, int16_t delay_tics, int16_t aware_range/*, int1
|
|||
// move to correct angle
|
||||
ang2tgt = getangle(hp->x - sp->x, hp->y - sp->y);
|
||||
|
||||
delta_ang = GetDeltaAngle(sp->ang, ang2tgt);
|
||||
delta_ang = getincangle(ang2tgt, sp->ang);
|
||||
|
||||
if (labs(delta_ang) > 32)
|
||||
{
|
||||
|
@ -18951,7 +18951,7 @@ InitTurretMgun(SECTOR_OBJECTp sop)
|
|||
daang = 512;
|
||||
if ((hitinfo.sprite = WeaponAutoAimHitscan(sp, &daz, &daang, false)) != -1)
|
||||
{
|
||||
delta = labs(GetDeltaAngle(daang, sp->ang));
|
||||
delta = labs(getincangle(sp->ang, daang));
|
||||
if (delta > 128)
|
||||
{
|
||||
// don't shoot if greater than 128
|
||||
|
|
Loading…
Reference in a new issue