pkgsrc-WIP-changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

doomlegacy-devel: Import code for internal blockmap creation



Module Name:	pkgsrc-wip
Committed By:	Michael Baeuerle <micha%NetBSD.org@localhost>
Pushed By:	micha
Date:		Tue May 12 18:19:37 2020 +0200
Changeset:	190700b7e3af74724d25ad956fa7f273dfde2f43

Modified Files:
	doomlegacy-devel/Makefile
	doomlegacy-devel/TODO
	doomlegacy-devel/distinfo
	doomlegacy-devel/patches/patch-src_Makefile
Added Files:
	doomlegacy-devel/files/p_blockmap.c

Log Message:
doomlegacy-devel: Import code for internal blockmap creation

Based on Crispy Doom 5.8.0.

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=190700b7e3af74724d25ad956fa7f273dfde2f43

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 doomlegacy-devel/Makefile                   |   1 +
 doomlegacy-devel/TODO                       |   1 +
 doomlegacy-devel/distinfo                   |   2 +-
 doomlegacy-devel/files/p_blockmap.c         | 230 ++++++++++++++++++++++++++++
 doomlegacy-devel/patches/patch-src_Makefile |   5 +-
 5 files changed, 236 insertions(+), 3 deletions(-)

diffs:
diff --git a/doomlegacy-devel/Makefile b/doomlegacy-devel/Makefile
index c8f495129c..f9def4319b 100644
--- a/doomlegacy-devel/Makefile
+++ b/doomlegacy-devel/Makefile
@@ -80,6 +80,7 @@ pre-configure:
 	${CP} ${FILESDIR}/INSTALL.pkgsrc ${WRKDIR}
 	${CP} ${FILESDIR}/doomlegacy.sh ${WRKDIR}
 	${CP} ${FILESDIR}/doomlegacy.6.in ${WRKDIR}
+	${CP} ${FILESDIR}/p_blockmap.c ${WRKSRC}/src
 	${CP} ${FILESDIR}/p_extnodes.c ${WRKSRC}/src
 	${CP} ${FILESDIR}/p_extnodes.h ${WRKSRC}/src
 	cd ${WRKSRC} && ${CP} make_options_nix make_options
diff --git a/doomlegacy-devel/TODO b/doomlegacy-devel/TODO
index 1819b08d9b..93585bb933 100644
--- a/doomlegacy-devel/TODO
+++ b/doomlegacy-devel/TODO
@@ -136,6 +136,7 @@ Part 9: Support for internal blockmap creation
 ==============================================
 Make it possible to play maps with broken blockmaps (or no blockmaps at all).
 
+[X] Imported code based on Crispy Doom 5.8.0
 [ ] Fix for NOVA II (Bug #658)
 [ ] Fix for NOVA III (blockmaps missing completely)
 [ ] Command line option "-blockmap" like in PrBoom+
diff --git a/doomlegacy-devel/distinfo b/doomlegacy-devel/distinfo
index fc28e9f78f..9dd93052db 100644
--- a/doomlegacy-devel/distinfo
+++ b/doomlegacy-devel/distinfo
@@ -4,7 +4,7 @@ SHA1 (doomlegacy_1.47.2_common.zip) = 9e6faaea797b988565a078a47e80bbe2119d78b9
 RMD160 (doomlegacy_1.47.2_common.zip) = 1ac1f47563ad2c0d7c5c1bea93a2aaeb1c001c10
 SHA512 (doomlegacy_1.47.2_common.zip) = 7c7c2a0cbab5b9b4645a3fe166addd597de533db7ab41f8011c6c526a868bb04c8dd6b0d27b48765406fbab328bf64fc7827770b395e6c0e5d861d99c4d3865a
 Size (doomlegacy_1.47.2_common.zip) = 981654 bytes
-SHA1 (patch-src_Makefile) = 85b798fcfb33c11a6ac7b7b775b7ad16959f3ab6
+SHA1 (patch-src_Makefile) = 40184838a23e00975a5380f18c8c53b3cc2eee47
 SHA1 (patch-src_am__map.c) = 14b3c8b70c63778ad043827ab2f0b6f4fe07bcde
 SHA1 (patch-src_doomdata.h) = 8c3186dafbf11a8a75262a06755dd9807cb58612
 SHA1 (patch-src_p__setup.c) = 526a5dcf97d4b2db3d05a8c655126fcd70deac21
diff --git a/doomlegacy-devel/files/p_blockmap.c b/doomlegacy-devel/files/p_blockmap.c
new file mode 100644
index 0000000000..b56b92fe2b
--- /dev/null
+++ b/doomlegacy-devel/files/p_blockmap.c
@@ -0,0 +1,230 @@
+//
+// Copyright(C) 1993-1996 Id Software, Inc.
+// Copyright(C) 1999 id Software, Chi Hoang, Lee Killough, Jim Flynn,
+//                   Rand Phares, Ty Halderman
+// Copyright(C) 2005-2014 Simon Howard
+// Copyright(C) 2017 Fabian Greffrath
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// DESCRIPTION:
+//    [crispy] Create Blockmap
+//
+
+#include <inttypes.h>
+#include <stdlib.h>
+#include <string.h>
+
+//#include "i_system.h"
+#include "doomincl.h"  // [MB] 2020-05-12: Added for I_Error()
+#include "p_local.h"
+#include "r_state.h"
+#include "z_zone.h"
+
+
+// [MB] 2020-05-12: Imported from Crispy Doom 5.8.0 (src/i_system.c)
+// I_Realloc
+static void *I_Realloc(void *ptr, size_t size)
+{
+    void *new_ptr;
+
+    new_ptr = realloc(ptr, size);
+
+    if (size != 0 && new_ptr == NULL)
+    {
+        I_Error("I_Realloc: failed on reallocation of %" PRIuPTR " bytes",
+                size);
+    }
+
+    return new_ptr;
+}
+
+
+// [crispy] taken from mbfsrc/P_SETUP.C:547-707, slightly adapted
+// [MB] 2020-05-12: Change indentation to 4 SPs (matching Doom Legacy style)
+// [MB] 2020-05-12: Replace blockmap with blockmapindex (unsigned)
+// [MB] 2020-05-12: Replace blockmaplump with blockmaphead (unsigned)
+// [MB] 2020-05-12: Added typecasts for unsigned target types
+
+void P_CreateBlockMap(void)
+{
+    register int i;
+    fixed_t minx = INT_MAX, miny = INT_MAX;
+    fixed_t maxx = INT_MIN, maxy = INT_MIN;
+
+    // First find limits of map
+    for (i=0 ; i<numvertexes ; i++)
+    {
+        if (vertexes[i].x >> FRACBITS < minx)
+            minx = vertexes[i].x >> FRACBITS;
+        else if (vertexes[i].x >> FRACBITS > maxx)
+            maxx = vertexes[i].x >> FRACBITS;
+        if (vertexes[i].y >> FRACBITS < miny)
+            miny = vertexes[i].y >> FRACBITS;
+        else if (vertexes[i].y >> FRACBITS > maxy)
+            maxy = vertexes[i].y >> FRACBITS;
+    }
+
+    // [crispy] doombsp/DRAWING.M:175-178
+    minx -= 8; miny -= 8;
+    maxx += 8; maxy += 8;
+
+    // Save blockmap parameters
+    bmaporgx = minx << FRACBITS;
+    bmaporgy = miny << FRACBITS;
+    bmapwidth  = ((maxx-minx) >> MAPBTOFRAC) + 1;
+    bmapheight = ((maxy-miny) >> MAPBTOFRAC) + 1;
+
+    // Compute blockmap, which is stored as a 2d array of variable-sized lists
+    //
+    // Pseudocode:
+    //
+    // For each linedef:
+    //
+    //   Map the starting and ending vertices to blocks.
+    //
+    //   Starting in the starting vertex's block, do:
+    //
+    //     Add linedef to current block's list, dynamically resizing it.
+    //
+    //     If current block is the same as the ending vertex's block,
+    //     exit loop.
+    //
+    //     Move to an adjacent block by moving towards the ending block in
+    //     either the x or y direction, to the block which contains the
+    //     linedef.
+    {
+        typedef struct { int n, nalloc, *list; } bmap_t;  // blocklist structure
+        unsigned tot = bmapwidth * bmapheight;            // size of blockmap
+        bmap_t *bmap = calloc(sizeof *bmap, tot);         // array of blocklists
+        int x, y, adx, ady, bend;
+
+        for (i=0; i < numlines; i++)
+        {
+            int dx, dy, diff, b;
+
+            // starting coordinates
+            x = (lines[i].v1->x >> FRACBITS) - minx;
+            y = (lines[i].v1->y >> FRACBITS) - miny;
+
+            // x-y deltas
+            adx = lines[i].dx >> FRACBITS, dx = adx < 0 ? -1 : 1;
+            ady = lines[i].dy >> FRACBITS, dy = ady < 0 ? -1 : 1;
+
+            // difference in preferring to move across y (>0) instead of x (<0)
+            diff = !adx ? 1 : !ady ? -1 :
+                (((x >> MAPBTOFRAC) << MAPBTOFRAC) +
+                    (dx > 0 ? MAPBLOCKUNITS-1 : 0) - x) *
+                        (ady = abs(ady)) * dx -
+                (((y >> MAPBTOFRAC) << MAPBTOFRAC) +
+                    (dy > 0 ? MAPBLOCKUNITS-1 : 0) - y) *
+                        (adx = abs(adx)) * dy;
+
+            // starting block, and pointer to its blocklist structure
+            b = (y >> MAPBTOFRAC)*bmapwidth + (x >> MAPBTOFRAC);
+
+            // ending block
+            bend = (((lines[i].v2->y >> FRACBITS) - miny) >> MAPBTOFRAC) *
+                bmapwidth +
+                    (((lines[i].v2->x >> FRACBITS) - minx) >> MAPBTOFRAC);
+
+            // delta for pointer when moving across y
+            dy *= bmapwidth;
+
+            // deltas for diff inside the loop
+            adx <<= MAPBTOFRAC;
+            ady <<= MAPBTOFRAC;
+
+            // Now we simply iterate block-by-block until we reach the end block
+            while ((unsigned) b < tot)    // failsafe -- should ALWAYS be true
+            {
+                // Increase size of allocated list if necessary
+                if (bmap[b].n >= bmap[b].nalloc)
+                    bmap[b].list = I_Realloc(bmap[b].list,
+                    (bmap[b].nalloc = bmap[b].nalloc ?
+                        bmap[b].nalloc*2 : 8)*sizeof*bmap->list);
+
+                // Add linedef to end of list
+                bmap[b].list[bmap[b].n++] = i;
+
+                // If we have reached the last block, exit
+                if (b == bend)
+                    break;
+
+                // Move in either the x or y direction to the next block
+                if (diff < 0)
+                    diff += ady, b += dx;
+                else
+                    diff -= adx, b += dy;
+            }
+        }
+
+        // Compute the total size of the blockmap.
+        //
+        // Compression of empty blocks is performed by reserving two offset
+        // words at tot and tot+1.
+        //
+        // 4 words, unused if this routine is called, are reserved at the start.
+        {
+            int count = tot+6;  // we need at least 1 word per block,
+                                // plus reserved's
+
+            for (i = 0; i < tot; i++)
+                if (bmap[i].n)
+                    count += bmap[i].n + 2; // 1 header word + 1 trailer word +
+                                            // blocklist
+
+            // Allocate blockmap lump with computed count
+            blockmaphead = Z_Malloc(sizeof(*blockmaphead) * count, PU_LEVEL, 0);
+        }
+
+        // Now compress the blockmap.
+        {
+            int ndx = tot += 4;       // Advance index to start of linedef lists
+            bmap_t *bp = bmap;        // Start of uncompressed blockmap
+
+            blockmaphead[ndx++] = 0;  // Store an empty blockmap list at start
+            blockmaphead[ndx++] = (uint32_t)INT32_C(-1); // (For compression)
+
+            for (i = 4; i < tot; i++, bp++)
+                if (bp->n)                               // Non-empty blocklist
+                {
+                                                         // Store index & header
+                    blockmaphead[blockmaphead[i] = ndx++] = 0;
+                    do
+                                                         // Copy linedef list
+                        blockmaphead[ndx++] = (uint32_t)(unsigned int)
+                                              bp->list[--bp->n];
+                    while (bp->n);
+                                                         // Store trailer
+                    blockmaphead[ndx++] = (uint32_t)INT32_C(-1);
+                    free(bp->list);                      // Free linedef list
+                }
+                else       // Empty blocklist: point to reserved empty blocklist
+                    blockmaphead[i] = tot;
+
+            free(bmap);    // Free uncompressed blockmap
+        }
+    }
+
+    // [crispy] copied over from P_LoadBlockMap()
+    {
+        int count = sizeof(*blocklinks) * bmapwidth * bmapheight;
+
+        blocklinks = Z_Malloc(count, PU_LEVEL, 0);
+        memset(blocklinks, 0, count);
+        blockmapindex = blockmaphead+4;
+    }
+
+#if 0
+    fprintf(stderr, "+BLOCKMAP)\n");
+#endif
+}
diff --git a/doomlegacy-devel/patches/patch-src_Makefile b/doomlegacy-devel/patches/patch-src_Makefile
index c32cf5bc0a..0f17b336e9 100644
--- a/doomlegacy-devel/patches/patch-src_Makefile
+++ b/doomlegacy-devel/patches/patch-src_Makefile
@@ -5,13 +5,14 @@ Add object file for import of extended nodes.
 Created upstream feature request:
 https://sourceforge.net/p/doomlegacy/feature-requests/95/
 
---- src/Makefile.orig	2020-04-20 10:32:33.000000000 +0000
+--- src/Makefile.orig	2020-05-11 09:40:36.000000000 +0000
 +++ src/Makefile
-@@ -1070,7 +1070,7 @@ screen.o v_video.o \
+@@ -1070,7 +1070,8 @@ screen.o v_video.o \
  r_draw.o r_plane.o r_segs.o r_sky.o r_things.o r_splats.o \
  r_bsp.o r_data.o r_main.o \
  z_zone.o \
 -p_sight.o p_mobj.o p_enemy.o p_user.o p_inter.o p_pspr.o \
++p_blockmap.o \
 +p_sight.o p_mobj.o p_enemy.o p_extnodes.o p_user.o p_inter.o p_pspr.o \
  p_lights.o p_ceilng.o p_doors.o p_plats.o p_floor.o p_spec.o \
  p_switch.o p_genlin.o p_telept.o p_tick.o p_fab.o p_info.o p_setup.o \


Home | Main Index | Thread Index | Old Index