From a082ec76dd0115c601696cfde0b380bbf9becf94 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Fri, 17 May 2013 10:41:57 +0000 Subject: [PATCH] Lunatic: fix randgen module after md4 removal, run DEFS_BC_SIZE cmd only once. git-svn-id: https://svn.eduke32.com/eduke32@3785 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/Makefile.common | 12 ++++++--- polymer/eduke32/source/lunatic/dynsymlist | 1 + polymer/eduke32/source/lunatic/dynsymlist_m32 | 1 + polymer/eduke32/source/lunatic/randgen.lua | 26 +++++++++---------- .../eduke32/source/lunatic/test/test_geom.lua | 8 +++--- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/polymer/eduke32/Makefile.common b/polymer/eduke32/Makefile.common index f4b9f1eb4..25165473a 100644 --- a/polymer/eduke32/Makefile.common +++ b/polymer/eduke32/Makefile.common @@ -441,10 +441,14 @@ ifneq ($(LUNATIC),0) endif BASECOMMONFLAGS+= -I$(SRC)/lunatic -DLUNATIC - # Determine size of defs.ilua bytecode - # XXX: Runs way too many times because it's a "recursively expanded" variable. - DEFS_BC_SIZE = $(shell $(LUAJIT) -bg -t h $(SRC)/lunatic/defs.ilua -) - BASECOMMONFLAGS+= -DLUNATIC_DEFS_BC_SIZE=$(word 3, $(DEFS_BC_SIZE)) + # Determine size of defs.ilua bytecode once. + ifndef DEFS_BC_SIZE + DEFS_BC_SIZE := $(shell $(LUAJIT) -bg -t h source/lunatic/defs.ilua -) + DEFS_BC_SIZE := $(word 3, $(DEFS_BC_SIZE)) + # Pass the bytecode size to the sub-makes, too. + export DEFS_BC_SIZE + endif + BASECOMMONFLAGS+= -DLUNATIC_DEFS_BC_SIZE=$(DEFS_BC_SIZE) ifeq ($(PLATFORM),WINDOWS) BASELIBS+= -lluajit diff --git a/polymer/eduke32/source/lunatic/dynsymlist b/polymer/eduke32/source/lunatic/dynsymlist index 61b7252d7..5f6decef7 100644 --- a/polymer/eduke32/source/lunatic/dynsymlist +++ b/polymer/eduke32/source/lunatic/dynsymlist @@ -3,6 +3,7 @@ engine_main_arrays_are_static; engine_v8; saveboard_maptext; +loadboard_maptext; sector; wall; diff --git a/polymer/eduke32/source/lunatic/dynsymlist_m32 b/polymer/eduke32/source/lunatic/dynsymlist_m32 index c1f183d0d..8974fbcbe 100644 --- a/polymer/eduke32/source/lunatic/dynsymlist_m32 +++ b/polymer/eduke32/source/lunatic/dynsymlist_m32 @@ -3,6 +3,7 @@ engine_main_arrays_are_static; engine_v8; saveboard_maptext; +loadboard_maptext; sector; wall; diff --git a/polymer/eduke32/source/lunatic/randgen.lua b/polymer/eduke32/source/lunatic/randgen.lua index e9dcacf3e..9ecc5ee73 100644 --- a/polymer/eduke32/source/lunatic/randgen.lua +++ b/polymer/eduke32/source/lunatic/randgen.lua @@ -20,7 +20,6 @@ typedef struct { } rng_jkiss_t; typedef union { unsigned char u[16]; double d[2]; } uchar_double_u_t; -typedef union { unsigned char u[16]; uint32_t i[4]; } uchar_uint_u_t; ]] -- PRNG functions @@ -28,9 +27,15 @@ decl[[ uint32_t rand_jkiss_u32(rng_jkiss_t *s); double rand_jkiss_dbl(rng_jkiss_t *s); -void md4once(const unsigned char *block, unsigned int len, unsigned char digest [16]); +uint32_t crc32once(uint8_t *blk, uint32_t len); ]] +local function get_rand_u32(tin) + tin.d[0] = ffiC.gethitickms() % 1 + tin.d[1] = ffiC.gethitickms() % 1 + return ffiC.crc32once(tin.u, 16) +end + local mt = { __tostring = function(s) return "rand.new("..s.x..","..s.y..","..s.z..","..s.c..")" @@ -41,23 +46,18 @@ local mt = { getdbl = ffiC.rand_jkiss_dbl, -- Initialize the JKISS PRNG using the MD4 of the lower bits of the - -- profiling timer + -- profiling timer. init_time_md4 = function(s) local tin = ffi.new("uchar_double_u_t") - local tout = ffi.new("uchar_uint_u_t") + local tout = ffi.new("uint32_t [4]") repeat - tin.d[0] = ffiC.gethitickms() % 1 - tin.d[1] = ffiC.gethitickms() % 1 - - ffiC.md4once(tin.u, 16, tout.u) - - s.y = tout.u[1] + s.y = get_rand_u32() until (s.y ~= 0) -- y must not be zero! - s.x = tout.u[0] - s.z = tout.u[2] - s.c = tout.u[3] % 698769068 + 1 -- Should be less than 698769069 + s.x = get_rand_u32() + s.z = get_rand_u32() + s.c = get_rand_u32() % 698769068 + 1 -- Should be less than 698769069 end, }, } diff --git a/polymer/eduke32/source/lunatic/test/test_geom.lua b/polymer/eduke32/source/lunatic/test/test_geom.lua index f829ae915..867509350 100755 --- a/polymer/eduke32/source/lunatic/test/test_geom.lua +++ b/polymer/eduke32/source/lunatic/test/test_geom.lua @@ -67,7 +67,7 @@ local t4 = os.clock() -- x86_64 (embedded): approx. 200 ms (vs. the 100 ms of direct -- ffiC.rand_jkiss_dbl()): -- x86: 170 ms -print(1000*(t2-t1)) -print(1000*(t3-t2)) -- x86_64: 500 ms, x86: 700 ms -print(1000*(t4-t3)) -- x86_64, x86: about 35 ms <- thanks to allocation sinking (else, about 500 ms?) -print(v) +print("getdbl: ".. 1000*(t2-t1)) +print("genpoints: ".. 1000*(t3-t2)) -- x86_64: 500 ms, x86: 700 ms +print("intersect: ".. 1000*(t4-t3)) -- x86_64, x86: about 35 ms <- thanks to allocation sinking (else, about 500 ms?) +print("result: ".. tostring(v))