From 0dba35b207bf7f5f0d3d819ddc3eebd8232021d0 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Fri, 12 Apr 2013 11:59:32 +0000 Subject: [PATCH] build.lua: add .sectsperbunch to map table, useful for TROR stats w/ findmaps.sh Also, sync MAXBUNCHES to new limit in lunatic/defs_common.lua. git-svn-id: https://svn.eduke32.com/eduke32@3665 1a8010ca-5511-0410-912e-c29ae57300e0 --- .../eduke32/source/lunatic/defs_common.lua | 2 +- polymer/eduke32/source/lunatic/util/build.lua | 22 ++++++---- .../source/lunatic/util/foreachmap.lua | 40 ++++++++++++------- 3 files changed, 42 insertions(+), 22 deletions(-) diff --git a/polymer/eduke32/source/lunatic/defs_common.lua b/polymer/eduke32/source/lunatic/defs_common.lua index 81b7bdeff..9cea73f5a 100644 --- a/polymer/eduke32/source/lunatic/defs_common.lua +++ b/polymer/eduke32/source/lunatic/defs_common.lua @@ -287,7 +287,7 @@ enum { MAXTILES = 30720, MAXSPRITESONSCREEN = 4096, - MAXBUNCHES = 256, + MAXBUNCHES = 512, CEILING = 0, FLOOR = 1, diff --git a/polymer/eduke32/source/lunatic/util/build.lua b/polymer/eduke32/source/lunatic/util/build.lua index 46aabaf18..acb6f3eaa 100644 --- a/polymer/eduke32/source/lunatic/util/build.lua +++ b/polymer/eduke32/source/lunatic/util/build.lua @@ -118,6 +118,7 @@ local function get_numyaxbunches(map) end local numbunches = 0 + local sectsperbunch = { [0]={}, [1]={} } for i=0,map.numsectors-1 do for cf=0,1 do @@ -129,11 +130,18 @@ local function get_numyaxbunches(map) if (xpan+1 > numbunches) then numbunches = xpan+1 end + + if (sectsperbunch[cf][xpan]==nil) then + sectsperbunch[cf][xpan] = 1 + else + sectsperbunch[cf][xpan] = sectsperbunch[cf][xpan]+1 + end end end end - return numbunches + map.numbunches = numbunches + map.sectsperbunch = sectsperbunch end --== sprite canonicalizer ==-- @@ -195,6 +203,10 @@ end -- start = -- { x=, y=, z=, ang=, sectnum= }, -- numbunches = , +-- sectsperbunch = { +-- [0] = { []= }, +-- [1] = { []= } +-- } -- } function loadboard(filename, do_canonicalize_sprite) local fh, errmsg = io.open(filename) @@ -284,7 +296,7 @@ function loadboard(filename, do_canonicalize_sprite) map.wall = set_secwalspr_mt(map.wall, map.numwalls) map.sprite = set_secwalspr_mt(map.sprite, map.numsprites) - map.numbunches = get_numyaxbunches(map) + get_numyaxbunches(map) -- done return map @@ -389,11 +401,7 @@ function readdefs(fn) local defs = {} - while (true) do - local line = fh:read() - if (line == nil) then - break - end + for line in fh:lines() do local defname, numstr = string.match(line, "#?%s*define%s+([%a_][%w_]+)%s+([0-9]+)") if (defname) then defs[defname] = tonumber(numstr) diff --git a/polymer/eduke32/source/lunatic/util/foreachmap.lua b/polymer/eduke32/source/lunatic/util/foreachmap.lua index 035c37040..f6009868e 100755 --- a/polymer/eduke32/source/lunatic/util/foreachmap.lua +++ b/polymer/eduke32/source/lunatic/util/foreachmap.lua @@ -16,10 +16,14 @@ -- forxcode example: print sprite numbers with lotag < -1 (interpreting lotag it as signed), -- and for each matching sprite also print its lotag and picnum: --- ./findmaps.sh ~/.eduke32/ "sprite: .lotag < -1 :: io. write(', '.. .lotag .. ' ' .. .picnum)" +-- $ ./findmaps.sh ~/.eduke32/ "sprite: .lotag < -1 :: io. write(', '.. .lotag .. ' ' .. .picnum)" -- The local 'd' provides defs loaded from ../../names.h, example: --- ./findmaps.sh ~/.eduke32/ "sprite: .picnum>=d. CRACK1 and .picnum<=d. CRACK4" +-- $ ./findmaps.sh ~/.eduke32/ "sprite: .picnum>=d. CRACK1 and .picnum<=d. CRACK4" + +-- Print all V9 maps along with their number of bunches and max(ceilings of a bunch) +-- $ prog='if (map.version==9) then print(map.numbunches.." ".. math.max(unpack(map.sectsperbunch[0],0)) .." "..fn) end' +-- $ ./findmaps.sh ~/.eduke32 "$prog" |sort -n -k 2 local B = require "build" local string = require "string" @@ -45,6 +49,14 @@ end local modname = string.gsub(arg[1], "%.lua$", "") +function sum(tab, initidx) + local s = 0 + for i=(initidx or 1),#tab do + s = s + tab[i] + end + return s +end + local mod if (modname:sub(1,2) == "-e") then local body = modname:sub(3) @@ -68,25 +80,25 @@ if (modname:sub(1,2) == "-e") then perxcode = "" end + assert(what=="sector" or what=="wall" or what=="sprite") + body = "for i=0,num"..what.."s-1 do\n".. " if ("..body..") then\n".. (onlyfiles and "io.write(fn); return\n" or "io.write(fn..': '..i)\n") .. - perxcode .. "io.write('\\n')".. - "\n end\n".. + perxcode .. "io.write('\\n')\n".. + " end\n".. "end\n" end - local successfunc, errmsg = loadstring( - "local d=require('build').readdefs('../../names.h') or error('Need ../../names.h')\n".. -- XXX - "local numsectors, numwalls, numsprites\n" - .."local sector, wall, sprite\n" - .."return function (map, fn) \n" - .." numsectors, numwalls, numsprites = map.numsectors, map.numwalls, map.numsprites\n" - .." sector, wall, sprite = map.sector, map.wall, map.sprite\n" - ..body.."\n" - .."end" - ) + local successfunc, errmsg = loadstring([[ + local d=require('build').readdefs('../../names.h') or error('Need ../../names.h') -- XXX + local numsectors, numwalls, numsprites, sector, wall, sprite + return function (map, fn) + numsectors, numwalls, numsprites = map.numsectors, map.numwalls, map.numsprites + sector, wall, sprite = map.sector, map.wall, map.sprite + ]]..body + .." end") if (successfunc==nil) then io.stderr:write("Error loading string: "..errmsg.."\n")