From 2a8dd6b9555e9387f8e5b6a3c3276efad86ad34a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 11 Oct 2022 22:09:15 +0200 Subject: [PATCH] - improved RANDOM_P2F interface. --- source/games/sw/src/game.h | 2 +- source/games/sw/src/sector.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 4426bb6db..431eb5e62 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -115,7 +115,7 @@ inline int RANDOM(void) return randomseed; } int RANDOM_P2(int pwr_of_2) { return (RANDOM() & (pwr_of_2 - 1)); } -double RANDOM_P2F(int pwr_of_2) { return (RANDOM() & (pwr_of_2 - 1)) * maptoworld; } +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)); } // diff --git a/source/games/sw/src/sector.cpp b/source/games/sw/src/sector.cpp index 8e192e3e8..6b1f96699 100644 --- a/source/games/sw/src/sector.cpp +++ b/source/games/sw/src/sector.cpp @@ -844,7 +844,7 @@ void SectorExp(DSWActor* actor, sectortype* sectp, double zh) auto mid = SectorMidPoint(sectp); // randomize the explosions actor->spr.angle = DAngle::fromBuild(RANDOM_P2(256) - 128); - actor->spr.pos = { mid.X + RANDOM_P2F(256) - 16, mid.Y + RANDOM_P2F(1024) - 64, zh }; + actor->spr.pos = { mid.X + RANDOM_P2F(16, 4) - 16, mid.Y + RANDOM_P2F(64, 4) - 64, zh }; // setup vars needed by SectorExp ChangeActorSect(actor, sectp);