foxygit / doom Log in
commit dba0583c05de16762c133c3198a9ef4e94c39253
Author:     Fabian Greffrath <fabian@greffrath.com>
AuthorDate: Wed Nov 11 10:58:04 2015 +0100
Commit:     Fabian Greffrath <fabian@greffrath.com>
CommitDate: Wed Nov 11 11:08:17 2015 +0100

    De-obfuscate some numerical constants found in the source code

    Also, fix pointer arithmetic in R_SetupFrame(), where
    sizeof(lighttable_t) == 1 was correct incidentally.
---
 src/doom/am_map.c   |  6 +++---
 src/doom/d_main.c   |  8 ++++----
 src/doom/f_finale.c | 16 ++++++++--------
 src/doom/f_wipe.c   |  4 ++--
 src/doom/m_menu.c   |  4 ++--
 src/doom/p_enemy.c  |  2 +-
 src/doom/p_map.c    |  4 ++--
 src/doom/p_pspr.c   |  2 +-
 src/doom/p_setup.c  |  4 ++--
 src/doom/p_user.c   |  2 +-
 src/doom/r_main.c   |  4 ++--
 src/doom/r_segs.c   |  4 ++--
 src/doom/r_sky.c    |  2 +-
 src/doom/r_things.c |  4 ++--
 src/m_fixed.c       |  2 +-
 15 files changed, 34 insertions(+), 34 deletions(-)

diff --git a/src/doom/am_map.c b/src/doom/am_map.c
index d3d504e3..c9a4eb58 100644
--- a/src/doom/am_map.c
+++ b/src/doom/am_map.c
@@ -99,8 +99,8 @@
 #define M_ZOOMOUT       ((int) (FRACUNIT/1.02))

 // translates between frame-buffer and map distances
-#define FTOM(x) FixedMul(((x)<<16),scale_ftom)
-#define MTOF(x) (FixedMul((x),scale_mtof)>>16)
+#define FTOM(x) FixedMul(((x)<<FRACBITS),scale_ftom)
+#define MTOF(x) (FixedMul((x),scale_mtof)>>FRACBITS)
 // translates between frame-buffer and map coordinates
 #define CXMTOF(x)  (f_x + MTOF((x)-m_x))
 #define CYMTOF(y)  (f_y + (f_h - MTOF((y)-m_y)))
@@ -199,7 +199,7 @@ static int 	leveljuststarted = 1; 	// kluge until AM_LevelInit() is called

 boolean    	automapactive = false;
 static int 	finit_width = SCREENWIDTH;
-static int 	finit_height = SCREENHEIGHT - 32;
+static int 	finit_height = SCREENHEIGHT - ST_HEIGHT;

 // location of window on screen
 static int 	f_x;
diff --git a/src/doom/d_main.c b/src/doom/d_main.c
index 9dabb931..31c7483a 100644
--- a/src/doom/d_main.c
+++ b/src/doom/d_main.c
@@ -217,12 +217,12 @@ void D_Display (void)
 	    break;
 	if (automapactive)
 	    AM_Drawer ();
-	if (wipe || (viewheight != 200 && fullscreen) || disk_indicator == disk_dirty)
+	if (wipe || (viewheight != SCREENHEIGHT && fullscreen) || disk_indicator == disk_dirty)
 	    redrawsbar = true;
 	if (inhelpscreensstate && !inhelpscreens)
 	    redrawsbar = true;              // just put away the help screen
-	ST_Drawer (viewheight == 200, redrawsbar );
-	fullscreen = viewheight == 200;
+	ST_Drawer (viewheight == SCREENHEIGHT, redrawsbar );
+	fullscreen = viewheight == SCREENHEIGHT;
 	break;

       case GS_INTERMISSION:
@@ -260,7 +260,7 @@ void D_Display (void)
     }

     // see if the border needs to be updated to the screen
-    if (gamestate == GS_LEVEL && !automapactive && scaledviewwidth != 320)
+    if (gamestate == GS_LEVEL && !automapactive && scaledviewwidth != SCREENWIDTH)
     {
 	if (menuactive || menuactivestate || !viewactivestate)
 	    borderdrawcount = 3;
diff --git a/src/doom/f_finale.c b/src/doom/f_finale.c
index ca6775ef..02651357 100644
--- a/src/doom/f_finale.c
+++ b/src/doom/f_finale.c
@@ -512,7 +512,7 @@ void F_CastPrint (char* text)
     }

     // draw it
-    cx = 160-width/2;
+    cx = SCREENWIDTH/2-width/2;
     ch = text;
     while (ch)
     {
@@ -559,9 +559,9 @@ void F_CastDrawer (void)

     patch = W_CacheLumpNum (lump+firstspritelump, PU_CACHE);
     if (flip)
-	V_DrawPatchFlipped(160, 170, patch);
+	V_DrawPatchFlipped(SCREENWIDTH/2, 170, patch);
     else
-	V_DrawPatch(160, 170, patch);
+	V_DrawPatch(SCREENWIDTH/2, 170, patch);
 }


@@ -618,18 +618,18 @@ void F_BunnyScroll (void)

     V_MarkRect (0, 0, SCREENWIDTH, SCREENHEIGHT);

-    scrolled = (320 - ((signed int) finalecount-230)/2);
-    if (scrolled > 320)
-	scrolled = 320;
+    scrolled = (SCREENWIDTH - ((signed int) finalecount-230)/2);
+    if (scrolled > SCREENWIDTH)
+	scrolled = SCREENWIDTH;
     if (scrolled < 0)
 	scrolled = 0;

     for ( x=0 ; x<SCREENWIDTH ; x++)
     {
-	if (x+scrolled < 320)
+	if (x+scrolled < SCREENWIDTH)
 	    F_DrawPatchCol (x, p1, x+scrolled);
 	else
-	    F_DrawPatchCol (x, p2, x+scrolled - 320);
+	    F_DrawPatchCol (x, p2, x+scrolled - SCREENWIDTH);
     }

     if (finalecount < 1130)
diff --git a/src/doom/f_wipe.c b/src/doom/f_wipe.c
index 05852fd2..3c204e05 100644
--- a/src/doom/f_wipe.c
+++ b/src/doom/f_wipe.c
@@ -49,13 +49,13 @@ wipe_shittyColMajorXform
     int		y;
     short*	dest;

-    dest = (short*) Z_Malloc(width*height*2, PU_STATIC, 0);
+    dest = (short*) Z_Malloc(width*height*sizeof(*dest), PU_STATIC, 0);

     for(y=0;y<height;y++)
 	for(x=0;x<width;x++)
 	    dest[x*height+y] = array[y*width+x];

-    memcpy(array, dest, width*height*2);
+    memcpy(array, dest, width*height*sizeof(*dest));

     Z_Free(dest);

diff --git a/src/doom/m_menu.c b/src/doom/m_menu.c
index db40937f..3d0539ff 100644
--- a/src/doom/m_menu.c
+++ b/src/doom/m_menu.c
@@ -1962,7 +1962,7 @@ void M_Drawer (void)
     if (messageToPrint)
     {
 	start = 0;
-	y = 100 - M_StringHeight(messageString) / 2;
+	y = SCREENHEIGHT/2 - M_StringHeight(messageString) / 2;
 	while (messageString[start] != '\0')
 	{
 	    int foundnewline = 0;
@@ -1990,7 +1990,7 @@ void M_Drawer (void)
                 start += strlen(string);
             }

-	    x = 160 - M_StringWidth(string) / 2;
+	    x = SCREENWIDTH/2 - M_StringWidth(string) / 2;
 	    M_WriteText(x, y, string);
 	    y += SHORT(hu_font[0]->height);
 	}
diff --git a/src/doom/p_enemy.c b/src/doom/p_enemy.c
index f2b44d13..8980ff24 100644
--- a/src/doom/p_enemy.c
+++ b/src/doom/p_enemy.c
@@ -212,7 +212,7 @@ boolean P_CheckMissileRange (mobj_t* actor)
     if (!actor->info->meleestate)
 	dist -= 128*FRACUNIT;	// no melee attack, so fire more

-    dist >>= 16;
+    dist >>= FRACBITS;

     if (actor->type == MT_VILE)
     {
diff --git a/src/doom/p_map.c b/src/doom/p_map.c
index 9d3086fd..2dbabd01 100644
--- a/src/doom/p_map.c
+++ b/src/doom/p_map.c
@@ -1083,8 +1083,8 @@ P_AimLineAttack
     shootz = t1->z + (t1->height>>1) + 8*FRACUNIT;

     // can't shoot outside view angles
-    topslope = 100*FRACUNIT/160;
-    bottomslope = -100*FRACUNIT/160;
+    topslope = (SCREENHEIGHT/2)*FRACUNIT/(SCREENWIDTH/2);
+    bottomslope = -(SCREENHEIGHT/2)*FRACUNIT/(SCREENWIDTH/2);

     attackrange = distance;
     linetarget = NULL;
diff --git a/src/doom/p_pspr.c b/src/doom/p_pspr.c
index e4774c70..274d35db 100644
--- a/src/doom/p_pspr.c
+++ b/src/doom/p_pspr.c
@@ -726,7 +726,7 @@ A_FireShotgun2
     {
 	damage = 5*(P_Random ()%3+1);
 	angle = player->mo->angle;
-	angle += (P_Random()-P_Random())<<19;
+	angle += (P_Random()-P_Random())<<ANGLETOFINESHIFT;
 	P_LineAttack (player->mo,
 		      angle,
 		      MISSILERANGE,
diff --git a/src/doom/p_setup.c b/src/doom/p_setup.c
index b5181625..1b8c02bb 100644
--- a/src/doom/p_setup.c
+++ b/src/doom/p_setup.c
@@ -192,8 +192,8 @@ void P_LoadSegs (int lump)
 	li->v1 = &vertexes[SHORT(ml->v1)];
 	li->v2 = &vertexes[SHORT(ml->v2)];

-	li->angle = (SHORT(ml->angle))<<16;
-	li->offset = (SHORT(ml->offset))<<16;
+	li->angle = (SHORT(ml->angle))<<FRACBITS;
+	li->offset = (SHORT(ml->offset))<<FRACBITS;
 	linedef = SHORT(ml->linedef);
 	ldef = &lines[linedef];
 	li->linedef = ldef;
diff --git a/src/doom/p_user.c b/src/doom/p_user.c
index 73c0dc94..772871ef 100644
--- a/src/doom/p_user.c
+++ b/src/doom/p_user.c
@@ -144,7 +144,7 @@ void P_MovePlayer (player_t* player)

     cmd = &player->cmd;

-    player->mo->angle += (cmd->angleturn<<16);
+    player->mo->angle += (cmd->angleturn<<FRACBITS);

     // Do not let the player control movement
     //  if not onground.
diff --git a/src/doom/r_main.c b/src/doom/r_main.c
index 22278fe3..567ea4be 100644
--- a/src/doom/r_main.c
+++ b/src/doom/r_main.c
@@ -482,7 +482,7 @@ fixed_t R_ScaleFromGlobalAngle (angle_t visangle)
     num = FixedMul(projection,sineb)<<detailshift;
     den = FixedMul(rw_distance,sinea);

-    if (den > num>>16)
+    if (den > num>>FRACBITS)
     {
 	scale = FixedDiv (num, den);

@@ -841,7 +841,7 @@ void R_SetupFrame (player_t* player)
     {
 	fixedcolormap =
 	    colormaps
-	    + player->fixedcolormap*256*sizeof(lighttable_t);
+	    + player->fixedcolormap*256;

 	walllights = scalelightfixed;

diff --git a/src/doom/r_segs.c b/src/doom/r_segs.c
index 9b4e413c..461aa4a4 100644
--- a/src/doom/r_segs.c
+++ b/src/doom/r_segs.c
@@ -715,7 +715,7 @@ R_StoreWallRange
     if ( ((ds_p->silhouette & SIL_TOP) || maskedtexture)
 	 && !ds_p->sprtopclip)
     {
-	memcpy (lastopening, ceilingclip+start, 2*(rw_stopx-start));
+	memcpy (lastopening, ceilingclip+start, sizeof(*lastopening)*(rw_stopx-start));
 	ds_p->sprtopclip = lastopening - start;
 	lastopening += rw_stopx - start;
     }
@@ -723,7 +723,7 @@ R_StoreWallRange
     if ( ((ds_p->silhouette & SIL_BOTTOM) || maskedtexture)
 	 && !ds_p->sprbottomclip)
     {
-	memcpy (lastopening, floorclip+start, 2*(rw_stopx-start));
+	memcpy (lastopening, floorclip+start, sizeof(*lastopening)*(rw_stopx-start));
 	ds_p->sprbottomclip = lastopening - start;
 	lastopening += rw_stopx - start;
     }
diff --git a/src/doom/r_sky.c b/src/doom/r_sky.c
index 667c88d3..bcd5a75b 100644
--- a/src/doom/r_sky.c
+++ b/src/doom/r_sky.c
@@ -47,6 +47,6 @@ int			skytexturemid;
 void R_InitSkyMap (void)
 {
   // skyflatnum = R_FlatNumForName ( SKYFLATNAME );
-    skytexturemid = 100*FRACUNIT;
+    skytexturemid = SCREENHEIGHT/2*FRACUNIT;
 }

diff --git a/src/doom/r_things.c b/src/doom/r_things.c
index a62cfde1..f8054302 100644
--- a/src/doom/r_things.c
+++ b/src/doom/r_things.c
@@ -38,7 +38,7 @@


 #define MINZ				(FRACUNIT*4)
-#define BASEYCENTER			100
+#define BASEYCENTER			(SCREENHEIGHT/2)

 //void R_DrawColumn (void);
 //void R_DrawFuzzColumn (void);
@@ -665,7 +665,7 @@ void R_DrawPSprite (pspdef_t* psp)
     flip = (boolean)sprframe->flip[0];

     // calculate edges of the shape
-    tx = psp->sx-160*FRACUNIT;
+    tx = psp->sx-(SCREENWIDTH/2)*FRACUNIT;

     tx -= spriteoffset[lump];
     x1 = (centerxfrac + FixedMul (tx,pspritescale) ) >>FRACBITS;
diff --git a/src/m_fixed.c b/src/m_fixed.c
index 23f6ff30..d2c18184 100644
--- a/src/m_fixed.c
+++ b/src/m_fixed.c
@@ -54,7 +54,7 @@ fixed_t FixedDiv(fixed_t a, fixed_t b)
     {
 	int64_t result;

-	result = ((int64_t) a << 16) / b;
+	result = ((int64_t) a << FRACBITS) / b;

 	return (fixed_t) result;
     }