diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index f3a8ff1af..1ddfa89f7 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -114,6 +114,10 @@ inline int RANDOM(void) randomseed = ((randomseed * 21 + 1) & 65535); return randomseed; } +inline double RandomRangeF(double range) +{ + return RANDOM() * range / 65536; +} int RANDOM_P2(int pwr_of_2) { return (RANDOM() & (pwr_of_2 - 1)); } double RANDOM_P2F(int pwr_of_2, int shift) { return (RANDOM() & ((pwr_of_2 << shift) - 1)) * (1./(1 << shift)); } DAngle RANDOM_ANGLE() { return DAngle::fromBuild(RANDOM_P2(2048)); } @@ -1522,15 +1526,15 @@ struct SECTOR_OBJECT double scale_dist, // distance from center scale_dist_min, // absolute min scale_dist_max, // absolute max - scale_speed; // speed of scaling + scale_speed, // speed of scaling // values for single point scaling - int16_t _scale_point_dist[MAX_SO_POINTS], // distance from center - _scale_point_speed[MAX_SO_POINTS], // speed of scaling - _scale_point_base_speed, // base speed of scaling - _scale_point_dist_min, // absolute min - _scale_point_dist_max, // absolute max - scale_point_rand_freq, // freqency of direction change - based on rand(1024) + scale_point_dist[MAX_SO_POINTS], // distance from center + scale_point_speed[MAX_SO_POINTS], // speed of scaling + scale_point_base_speed, // base speed of scaling + scale_point_dist_min, // absolute min + scale_point_dist_max; // absolute max + int16_t scale_point_rand_freq, // freqency of direction change - based on rand(1024) scale_x_mult, // x multiplyer for scaling scale_y_mult, // y multiplyer for scaling diff --git a/source/games/sw/src/morph.cpp b/source/games/sw/src/morph.cpp index c7f873a62..f26aa168b 100644 --- a/source/games/sw/src/morph.cpp +++ b/source/games/sw/src/morph.cpp @@ -253,42 +253,38 @@ void ScaleSectorObject(SECTOR_OBJECT* sop) DVector2 ScaleRandomPoint(SECTOR_OBJECT* sop, short k, DAngle ang, const DVector2& pos) { - int xmul, ymul; - - sop->_scale_point_dist[k] += sop->_scale_point_speed[k]; - if (sop->_scale_point_dist[k] > sop->_scale_point_dist_max) + sop->scale_point_dist[k] += sop->scale_point_speed[k]; + if (sop->scale_point_dist[k] > sop->scale_point_dist_max) { - sop->_scale_point_speed[k] *= -1; - sop->_scale_point_dist[k] = sop->_scale_point_dist_max; + sop->scale_point_speed[k] *= -1; + sop->scale_point_dist[k] = sop->scale_point_dist_max; } - else if (sop->_scale_point_dist[k] < sop->_scale_point_dist_min) + else if (sop->scale_point_dist[k] < sop->scale_point_dist_min) { - sop->_scale_point_speed[k] *= -1; - sop->_scale_point_dist[k] = sop->_scale_point_dist_min; + sop->scale_point_speed[k] *= -1; + sop->scale_point_dist[k] = sop->scale_point_dist_min; } if (RANDOM_P2(1024) < sop->scale_point_rand_freq) { - sop->_scale_point_speed[k] *= -1; + sop->scale_point_speed[k] *= -1; } // change up speed at random if (RANDOM_P2(1024) < (sop->scale_point_rand_freq / 2)) { - //sop->scale_point_speed[k] = SCALE_POINT_SPEED; - short half = sop->_scale_point_base_speed / 2; - short quart = sop->_scale_point_base_speed / 4; - sop->_scale_point_speed[k] = sop->_scale_point_base_speed + (RandomRange(half) - quart); + double half = sop->scale_point_base_speed / 2; + double quart = sop->scale_point_base_speed / 4; + sop->scale_point_speed[k] = sop->scale_point_base_speed + (RandomRangeF(half) - quart); } - xmul = (sop->_scale_point_dist[k] * sop->scale_x_mult) >> 8; - ymul = (sop->_scale_point_dist[k] * sop->scale_y_mult) >> 8; - DVector2 mul(xmul / 16., ymul / 16.); + double xmul = (sop->scale_point_dist[k] * sop->scale_x_mult) * (1 / 256.); + double ymul = (sop->scale_point_dist[k] * sop->scale_y_mult) * (1 / 256.); DVector2 ret; - ret.X = pos.X + mul.X * ang.Cos(); - ret.Y = pos.Y + mul.Y * ang.Sin(); + ret.X = pos.X + xmul * ang.Cos(); + ret.Y = pos.Y + ymul * ang.Sin(); return ret; } diff --git a/source/games/sw/src/save.cpp b/source/games/sw/src/save.cpp index e0fb7f254..dd1b8758a 100644 --- a/source/games/sw/src/save.cpp +++ b/source/games/sw/src/save.cpp @@ -686,11 +686,11 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, SECTOR_OBJECT& w, .Array("clipbox_dist", w.clipbox_dist, def->clipbox_dist, w.clipbox_num) .Array("clipbox_ang", w.clipbox_ang, def->clipbox_ang, w.clipbox_num) .Array("clipbox_vdist", w.clipbox_vdist, def->clipbox_vdist, w.clipbox_num) - .Array("scale_point_dist", w._scale_point_dist, def->_scale_point_dist, MAX_SO_POINTS) - .Array("scale_point_speed", w._scale_point_speed, def->_scale_point_speed, MAX_SO_POINTS) - ("scale_point_base_speed", w._scale_point_base_speed, def->_scale_point_base_speed) - ("scale_point_dist_min", w._scale_point_dist_min, def->_scale_point_dist_min) - ("scale_point_dist_max", w._scale_point_dist_max, def->_scale_point_dist_max) + .Array("scale_point_dist", w.scale_point_dist, def->scale_point_dist, MAX_SO_POINTS) + .Array("scale_point_speed", w.scale_point_speed, def->scale_point_speed, MAX_SO_POINTS) + ("scale_point_base_speed", w.scale_point_base_speed, def->scale_point_base_speed) + ("scale_point_dist_min", w.scale_point_dist_min, def->scale_point_dist_min) + ("scale_point_dist_max", w.scale_point_dist_max, def->scale_point_dist_max) ("scale_point_rand_freq", w.scale_point_rand_freq, def->scale_point_rand_freq) ("scale_x_mult", w.scale_x_mult, def->scale_x_mult) ("scale_y_mult", w.scale_y_mult, def->scale_y_mult) diff --git a/source/games/sw/src/sector.h b/source/games/sw/src/sector.h index 2045eb361..6d2fb1da2 100644 --- a/source/games/sw/src/sector.h +++ b/source/games/sw/src/sector.h @@ -54,7 +54,6 @@ enum SO_SCALE_TYPE SO_SCALE_RANDOM_POINT }; -#define SCALE_POINT_SPEED (4 + RandomRange(8)) struct NEAR_TAG_INFO { diff --git a/source/games/sw/src/track.cpp b/source/games/sw/src/track.cpp index 852cb0a81..665db9139 100644 --- a/source/games/sw/src/track.cpp +++ b/source/games/sw/src/track.cpp @@ -1012,11 +1012,11 @@ void SetupSectorObject(sectortype* sectp, short tag) case SO_SCALE_POINT_INFO: - memset(sop->_scale_point_dist,0,sizeof(sop->_scale_point_dist)); - sop->_scale_point_base_speed = SP_TAG2(actor); - for (j = 0; j < (int)SIZ(sop->_scale_point_speed); j++) + memset(sop->scale_point_dist,0,sizeof(sop->scale_point_dist)); + sop->scale_point_base_speed = SP_TAG2(actor) * maptoworld; + for (j = 0; j < (int)SIZ(sop->scale_point_speed); j++) { - sop->_scale_point_speed[j] = SP_TAG2(actor); + sop->scale_point_speed[j] = SP_TAG2(actor) * maptoworld; } if (SP_TAG4(actor)) @@ -1024,8 +1024,8 @@ void SetupSectorObject(sectortype* sectp, short tag) else sop->scale_point_rand_freq = 64; - sop->_scale_point_dist_min = -SP_TAG5(actor); - sop->_scale_point_dist_max = SP_TAG6(actor); + sop->scale_point_dist_min = -SP_TAG5(actor) * maptoworld; + sop->scale_point_dist_max = SP_TAG6(actor) * maptoworld; KillActor(actor); break; @@ -1105,13 +1105,13 @@ void SetupSectorObject(sectortype* sectp, short tag) sop->scale_type = SO_SCALE_RANDOM_POINT; sop->PreMoveAnimator = ScaleSectorObject; - memset(sop->_scale_point_dist,0,sizeof(sop->_scale_point_dist));; - sop->_scale_point_base_speed = SCALE_POINT_SPEED; - for (j = 0; j < (int)SIZ(sop->_scale_point_speed); j++) - sop->_scale_point_speed[j] = SCALE_POINT_SPEED; + memset(sop->scale_point_dist,0,sizeof(sop->scale_point_dist));; + sop->scale_point_base_speed = 0.25 + RandomRangeF(0.5); + for (j = 0; j < (int)SIZ(sop->scale_point_speed); j++) + sop->scale_point_speed[j] = 0.25 + RandomRangeF(0.5); - sop->_scale_point_dist_min = -256; - sop->_scale_point_dist_max = 256; + sop->scale_point_dist_min = -16; + sop->scale_point_dist_max = 16; sop->scale_point_rand_freq = 32; KillActor(actor); break; @@ -1792,8 +1792,8 @@ void RefreshPoints(SECTOR_OBJECT* sop, int nx, int ny, bool dynamic) } else { - double xmul = (sop->scale_dist * sop->scale_x_mult) / 256.; - double ymul = (sop->scale_dist * sop->scale_y_mult) / 256.; + double xmul = (sop->scale_dist * sop->scale_x_mult) * (1 / 256.); + double ymul = (sop->scale_dist * sop->scale_y_mult) * (1 / 256.); dpos.X = pos.X + xmul * ang.Cos(); dpos.Y = pos.Y + ymul * ang.Sin();