shithub: heretic

Download patch

ref: 4f6d19af20a486bdba53ac15a00b1e1f87567276
parent: 078dd1d6d088aab71c37c0e21fea5cebfe1271a8
author: Jacob Moody <moody@posixcafe.org>
date: Sat Feb 4 21:31:04 EST 2023

fix demo playback

This restores how the demos playback on DOS, not
this does not exactly mean correct. From what I can gather
version 1.2-1.3 of heretic and the mega wad used for the expansion
both ship with demos that range from kinda out of sync to very.

Tested with 1.2 shareware, which had functioning demos, and
we now fail in the exact same way that the DOS versions did
for those that are broken.

--- a/doomdef.h
+++ b/doomdef.h
@@ -1280,6 +1280,7 @@
 /* returns a number from 0 to 255 */
 
 int P_Random (void);
+int P_Random2 (void);
 /* as M_Random, but used only by the play simulation */
 
 void M_ClearRandom (void);
--- a/m_misc.c
+++ b/m_misc.c
@@ -174,6 +174,14 @@
 	return rndtable[prndindex];
 }
 
+int P_Random2 (void)
+{
+	int tmp, tmp2;
+	tmp = P_Random();
+	tmp2 = P_Random();
+	return tmp - tmp2;
+}
+
 int M_Random (void)
 {
 	rndindex = (rndindex + 1) & 0xff;
--- a/p_enemy.c
+++ b/p_enemy.c
@@ -782,7 +782,7 @@
 	actor->angle = R_PointToAngle2(actor->x, actor->y, actor->target->x, actor->target->y);
 	if (actor->target->flags & MF_SHADOW)
 	{ // Target is a ghost
-		actor->angle += (P_Random() - P_Random()) << 21;
+		actor->angle += (P_Random2()) << 21;
 	}
 }
 
@@ -809,12 +809,16 @@
 void A_DripBlood(mobj_t *actor)
 {
 	mobj_t *mo;
+	int a, b;
 
-	mo = P_SpawnMobj(actor->x + ((P_Random() - P_Random())<<11),
-			 actor->y + ((P_Random() - P_Random())<<11),
+	b = ((P_Random2())<<11);
+	a = ((P_Random2())<<11);
+
+	mo = P_SpawnMobj(actor->x + a,
+			 actor->y + b,
 			 actor->z, MT_BLOOD);
-	mo->momx = (P_Random() - P_Random())<<10;
-	mo->momy = (P_Random() - P_Random())<<10;
+	mo->momx = (P_Random2())<<10;
+	mo->momy = (P_Random2())<<10;
 	mo->flags2 |= MF2_LOGRAV;
 }
 
@@ -858,12 +862,12 @@
 	mobj_t *mo;
 
 	mo = P_SpawnMobj(actor->x, actor->y, actor->z, MT_IMPCHUNK1);
-	mo->momx = (P_Random() - P_Random ())<<10;
-	mo->momy = (P_Random() - P_Random ())<<10;
+	mo->momx = (P_Random2 ())<<10;
+	mo->momy = (P_Random2 ())<<10;
 	mo->momz = 9*FRACUNIT;
 	mo = P_SpawnMobj(actor->x, actor->y, actor->z, MT_IMPCHUNK2);
-	mo->momx = (P_Random() - P_Random ())<<10;
-	mo->momy = (P_Random() - P_Random ())<<10;
+	mo->momx = (P_Random2 ())<<10;
+	mo->momy = (P_Random2 ())<<10;
 	mo->momz = 9*FRACUNIT;
 	if (actor->special1 == 666)
 	{ // Extreme death crash
@@ -879,11 +883,16 @@
 
 void A_BeastPuff(mobj_t *actor)
 {
+	int a, b, c;
+
 	if (P_Random() > 64)
 	{
-		P_SpawnMobj(actor->x + ((P_Random() - P_Random())<<10),
-			    actor->y+((P_Random() - P_Random())<<10),
-			    actor->z+((P_Random() - P_Random())<<10), MT_PUFFY);
+		c = ((P_Random2())<<10);
+		b = ((P_Random2())<<10);
+		a = ((P_Random2())<<10);
+		P_SpawnMobj(actor->x + a,
+			    actor->y + b,
+			    actor->z + c, MT_PUFFY);
 	}
 }
 
@@ -1147,8 +1156,8 @@
 	{
 		mo = P_SpawnMobj(actor->x, actor->y, actor->z + 20*FRACUNIT, MT_FEATHER);
 		mo->target = actor;
-		mo->momx = (P_Random() - P_Random())<<8;
-		mo->momy = (P_Random() - P_Random())<<8;
+		mo->momx = (P_Random2())<<8;
+		mo->momy = (P_Random2())<<8;
 		mo->momz = FRACUNIT + (P_Random()<<9);
 		P_SetMobjState(mo, S_FEATHER1 + (P_Random() & 7));
 	}
@@ -1440,8 +1449,8 @@
 	for (i = 0; i < 2; i++)
 	{
 		mo = P_SpawnMobj(actor->x, actor->y, actor->z, MT_SOR2FXSPARK);
-		mo->momx = (P_Random() - P_Random())<<9;
-		mo->momy = (P_Random() - P_Random())<<9;
+		mo->momx = (P_Random2())<<9;
+		mo->momy = (P_Random2())<<9;
 		mo->momz = FRACUNIT + (P_Random()<<8);
 	}
 }
@@ -1721,10 +1730,13 @@
 void A_MntrFloorFire(mobj_t *actor)
 {
 	mobj_t *mo;
+	int a, b;
 
 	actor->z = actor->floorz;
-	mo = P_SpawnMobj(actor->x + ((P_Random() - P_Random()) << 10),
-			 actor->y + ((P_Random() - P_Random()) << 10), ONFLOORZ, MT_MNTRFX3);
+	b = ((P_Random2()) << 10);
+	a = ((P_Random2()) << 10);
+	mo = P_SpawnMobj(actor->x + a,
+			 actor->y + b, ONFLOORZ, MT_MNTRFX3);
 	mo->target = actor->target;
 	mo->momx = 1; // Force block checking
 	P_CheckMissileSpawn(mo);
@@ -2086,8 +2098,8 @@
 	}
 	mo = P_SpawnMobj(source->x, source->y,
 			 source->z + (source->height>>1), type);
-	mo->momx = (P_Random() - P_Random())<<8;
-	mo->momy = (P_Random() - P_Random())<<8;
+	mo->momx = (P_Random2())<<8;
+	mo->momy = (P_Random2())<<8;
 	mo->momz = FRACUNIT*5 + (P_Random()<<10);
 	mo->flags |= MF_DROPPED;
 	mo->health = special;
@@ -2197,8 +2209,8 @@
 		goo = P_SpawnMobj(actor->x, actor->y,
 				  actor->z + 48*FRACUNIT, MT_PODGOO);
 		goo->target = actor;
-		goo->momx = (P_Random() - P_Random())<<9;
-		goo->momy = (P_Random() - P_Random())<<9;
+		goo->momx = (P_Random2())<<9;
+		goo->momy = (P_Random2())<<9;
 		goo->momz = FRACUNIT/2 + (P_Random()<<9);
 	}
 }
@@ -2370,9 +2382,12 @@
 void A_SpawnTeleGlitter(mobj_t *actor)
 {
 	mobj_t *mo;
+	int a, b;
 
-	mo = P_SpawnMobj(actor->x + ((P_Random() & 31) - 16) * FRACUNIT,
-			 actor->y + ((P_Random() & 31) - 16) * FRACUNIT,
+	b = ((P_Random() & 31) - 16) * FRACUNIT;
+	a = ((P_Random() & 31) - 16) * FRACUNIT;
+	mo = P_SpawnMobj(actor->x + a,
+			 actor->y + b,
 			 actor->subsector->sector->floorheight, MT_TELEGLITTER);
 	mo->momz = FRACUNIT/4;
 }
@@ -2528,8 +2543,8 @@
 	mo = P_SpawnMobj(actor->x, actor->y, actor->z + 48*FRACUNIT,
 						MT_BLOODYSKULL);
 	//mo->target = actor;
-	mo->momx = (P_Random() - P_Random())<<9;
-	mo->momy = (P_Random() - P_Random())<<9;
+	mo->momx = (P_Random2())<<9;
+	mo->momy = (P_Random2())<<9;
 	mo->momz = FRACUNIT*2 + (P_Random()<<6);
 	// Attach player mobj to bloody skull
 	player = actor->player;
--- a/p_inter.c
+++ b/p_inter.c
@@ -972,9 +972,9 @@
 {
 	int randVal;
 
-	target->angle += (P_Random() - P_Random()) <<20;
-	target->momx  += (P_Random() - P_Random()) <<10;
-	target->momy  += (P_Random() - P_Random()) <<10;
+	target->angle += (P_Random2()) <<20;
+	target->momx  += (P_Random2()) <<10;
+	target->momy  += (P_Random2()) <<10;
 	if (leveltime & 16 && !(target->flags2 & MF2_BOSS))
 	{
 		randVal = P_Random();
--- a/p_map.c
+++ b/p_map.c
@@ -1651,8 +1651,8 @@
 		P_DamageMobj(thing, NULL, NULL, 10);
 		// spray blood in a random direction
 		mo = P_SpawnMobj (thing->x, thing->y, thing->z + thing->height/2, MT_BLOOD);
-		mo->momx = (P_Random() - P_Random ())<<12;
-		mo->momy = (P_Random() - P_Random ())<<12;
+		mo->momx = (P_Random2 ())<<12;
+		mo->momy = (P_Random2 ())<<12;
 	}
 
 	return true;		// keep checking (crush other things)
--- a/p_mobj.c
+++ b/p_mobj.c
@@ -1192,7 +1192,7 @@
 {
 	mobj_t *puff;
 
-	z += ((P_Random() - P_Random()) << 10);
+	z += ((P_Random2()) << 10);
 	puff = P_SpawnMobj(x, y, z, PuffType);
 	if (puff->info->attacksound)
 	{
@@ -1225,7 +1225,7 @@
 {
 	mobj_t	*th;
 
-	z += ((P_Random() - P_Random()) << 10);
+	z += ((P_Random2()) << 10);
 	th = P_SpawnMobj (x, y, z, MT_BLOOD);
 	th->momz = FRACUNIT*2;
 	th->tics -= P_Random() & 3;
@@ -1249,8 +1249,8 @@
 
 	mo = P_SpawnMobj(x, y, z, MT_BLOODSPLATTER);
 	mo->target = originator;
-	mo->momx = (P_Random() - P_Random()) << 9;
-	mo->momy = (P_Random() - P_Random()) << 9;
+	mo->momx = (P_Random2()) << 9;
+	mo->momy = (P_Random2()) << 9;
 	mo->momz = FRACUNIT*2;
 }
 
@@ -1265,9 +1265,9 @@
 	mobj_t *th;
 	fixed_t x, y, z;
 
-	x = mo->x + ((P_Random() - P_Random()) <<12);
-	y = mo->y + ((P_Random() - P_Random()) <<12);
-	z = mo->z + ((P_Random() - P_Random()) <<12);
+	x = mo->x + ((P_Random2()) <<12);
+	y = mo->y + ((P_Random2()) <<12);
+	z = mo->z + ((P_Random2()) <<12);
 	th = P_SpawnMobj(x, y, z, MT_BLOOD);
 	th->flags |= MF_NOGRAVITY;
 	th->momx = mo->momx>>1;
@@ -1317,8 +1317,8 @@
 		P_SpawnMobj(thing->x, thing->y, ONFLOORZ, MT_SPLASHBASE);
 		mo = P_SpawnMobj(thing->x, thing->y, ONFLOORZ, MT_SPLASH);
 		mo->target = thing;
-		mo->momx = (P_Random() -P_Random()) <<8;
-		mo->momy = (P_Random() -P_Random()) <<8;
+		mo->momx = (P_Random2()) <<8;
+		mo->momy = (P_Random2()) <<8;
 		mo->momz = 2*FRACUNIT + (P_Random() <<8);
 		S_StartSound(mo, sfx_gloop);
 		return FLOOR_WATER;
@@ -1332,8 +1332,8 @@
 		P_SpawnMobj(thing->x, thing->y, ONFLOORZ, MT_SLUDGESPLASH);
 		mo = P_SpawnMobj(thing->x, thing->y, ONFLOORZ, MT_SLUDGECHUNK);
 		mo->target = thing;
-		mo->momx = (P_Random() - P_Random()) <<8;
-		mo->momy = (P_Random() - P_Random()) <<8;
+		mo->momx = (P_Random2()) <<8;
+		mo->momy = (P_Random2()) <<8;
 		mo->momz = FRACUNIT + (P_Random() <<8);
 		return FLOOR_SLUDGE;
 	}
@@ -1417,7 +1417,7 @@
 	an = R_PointToAngle2(source->x, source->y, dest->x, dest->y);
 	if (dest->flags & MF_SHADOW)
 	{ // Invisible target
-		an += (P_Random() - P_Random()) <<21;
+		an += (P_Random2()) <<21;
 	}
 	th->angle = an;
 	an >>= ANGLETOFINESHIFT;
--- a/p_pspr.c
+++ b/p_pspr.c
@@ -902,7 +902,7 @@
 
 	damage = 5 + (P_Random() & 15);
 	angle = player->mo->angle;
-	angle += (P_Random() - P_Random())<<18;
+	angle += (P_Random2())<<18;
 	slope = P_AimLineAttack(player->mo, angle, MELEERANGE);
 	PuffType = MT_STAFFPUFF;
 	P_LineAttack(player->mo, angle, MELEERANGE, slope, damage);
@@ -930,7 +930,7 @@
 	// P_inter.c:P_DamageMobj() handles target momentums
 	damage = 18 + (P_Random() & 63);
 	angle = player->mo->angle;
-	angle += (P_Random() - P_Random())<<18;
+	angle += (P_Random2())<<18;
 	slope = P_AimLineAttack(player->mo, angle, MELEERANGE);
 	PuffType = MT_STAFFPUFF2;
 	P_LineAttack(player->mo, angle, MELEERANGE, slope, damage);
@@ -963,7 +963,7 @@
 	angle = mo->angle;
 	if (player->refire)
 	{
-		angle += (P_Random() - P_Random())<<18;
+		angle += (P_Random2())<<18;
 	}
 	PuffType = MT_BLASTERPUFF1;
 	P_LineAttack(mo, angle, MISSILERANGE, bulletslope, damage);
@@ -1009,7 +1009,7 @@
 	angle = mo->angle;
 	if (player->refire)
 	{
-		angle += (P_Random() - P_Random())<<18;
+		angle += (P_Random2())<<18;
 	}
 	PuffType = MT_GOLDWANDPUFF1;
 	P_LineAttack(mo, angle, MISSILERANGE, bulletslope, damage);
@@ -1393,8 +1393,8 @@
 	if (P_Random() > 50)
 	{
 		spark = P_SpawnMobj(bolt->x, bolt->y, bolt->z, MT_CRBOWFX4);
-		spark->x += (P_Random()-P_Random())<<10;
-		spark->y += (P_Random()-P_Random())<<10;
+		spark->x += (P_Random2())<<10;
+		spark->y += (P_Random2())<<10;
 	}
 }
 
@@ -1681,8 +1681,8 @@
 	}
 	pmo = player->mo;
 	angle = pmo->angle;
-	x = pmo->x+((P_Random()-P_Random())<<9);
-	y = pmo->y+((P_Random()-P_Random())<<9);
+	x = pmo->x+((P_Random2())<<9);
+	y = pmo->y+((P_Random2())<<9);
 	z = pmo->z+26*FRACUNIT+((player->lookdir)<<FRACBITS)/173;
 	if (pmo->flags2 & MF2_FEETARECLIPPED)
 	{
@@ -1758,7 +1758,7 @@
 	{
 		damage = HITDICE(2);
 		dist = 4*MELEERANGE;
-		angle += (P_Random() - P_Random())<<17;
+		angle += (P_Random2())<<17;
 		PuffType = MT_GAUNTLETPUFF2;
 	}
 	else
@@ -1765,7 +1765,7 @@
 	{
 		damage = HITDICE(2);
 		dist = MELEERANGE+1;
-		angle += (P_Random() - P_Random())<<18;
+		angle += (P_Random2())<<18;
 		PuffType = MT_GAUNTLETPUFF1;
 	}
 	slope = P_AimLineAttack(player->mo, angle, dist);
--- a/p_user.c
+++ b/p_user.c
@@ -414,7 +414,7 @@
 	pmo = player->mo;
 	if (!(pmo->momx + pmo->momy) && P_Random() < 160)
 	{ // Twitch view angle
-		pmo->angle += (P_Random() - P_Random())<<19;
+		pmo->angle += (P_Random2())<<19;
 	}
 	if ((pmo->z <= pmo->floorz) && (P_Random() < 32))
 	{ // Jump and noise