From e4024676769cb96b017a8451ccc94643981c5963 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Thu, 5 Sep 2013 17:37:36 +0000 Subject: [PATCH] Lunatic: gv.getangle() vs. analogous Lua function test, add some anchors to doc. Also, in listglobals.sh, check for file existence. git-svn-id: https://svn.eduke32.com/eduke32@4044 1a8010ca-5511-0410-912e-c29ae57300e0 --- .../eduke32/source/lunatic/doc/lunatic.txt | 2 + polymer/eduke32/source/lunatic/listglobals.sh | 4 ++ polymer/eduke32/source/lunatic/test.lua | 51 +++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/polymer/eduke32/source/lunatic/doc/lunatic.txt b/polymer/eduke32/source/lunatic/doc/lunatic.txt index 850689cd1..38e5a441e 100644 --- a/polymer/eduke32/source/lunatic/doc/lunatic.txt +++ b/polymer/eduke32/source/lunatic/doc/lunatic.txt @@ -455,6 +455,7 @@ http://lua-users.org/lists/lua-l/2011-09/msg00534.html * `sec.lotag=32768` results the member to contain `-32768` * `sec.lotag=2^32` is undefined +[[bit_fields]] Bit fields ^^^^^^^^^^ @@ -1717,6 +1718,7 @@ specific actor tile. For this reason, per-actor variables are implemented in a value for every sprite index. They are also ``cleaned'' at unspecified intervals. +[[con_actorvar]] ===== The type `con.actorvar(defaultval)` [_serializable_] Creates and returns a new per-actor variable with default value `defaultval` diff --git a/polymer/eduke32/source/lunatic/listglobals.sh b/polymer/eduke32/source/lunatic/listglobals.sh index d68eaea48..18e4d396c 100755 --- a/polymer/eduke32/source/lunatic/listglobals.sh +++ b/polymer/eduke32/source/lunatic/listglobals.sh @@ -20,6 +20,10 @@ fi LUAC=luac for f in "$@"; do + if [ ! -f "$f" ]; then + echo "$f: No such file" + exit 2 + fi echo "[$f]" # Strip LuaJIT specific syntax first. Run luac and extract interesting lines. sed -r -e "s/[0-9]+U?LL/0/g" "$f" | $LUAC -p -l - | grep "${GS}ETTABUP.*; _ENV " | diff --git a/polymer/eduke32/source/lunatic/test.lua b/polymer/eduke32/source/lunatic/test.lua index 4bab982d2..4f85bce32 100644 --- a/polymer/eduke32/source/lunatic/test.lua +++ b/polymer/eduke32/source/lunatic/test.lua @@ -740,3 +740,54 @@ local D = require("CON.DEFS") checkfail('require("CON.DEFS").APLAYER=123', "modifying base module table forbidden") -- Test with lunatic/test/rotfixed_actor.con. print("DUKECAR="..tostring(D.DUKECAR)) + +do + print('---------- getangle test') + + local function CreateGetAngFunc(roundfunc) + return function(x, y) + local ang = (1024/math.pi)*math.atan2(y, x) -- note the swapped args + return bit.band(roundfunc(ang), 2047) + end + end + + local ourgetang = CreateGetAngFunc(math.ceil) + local ourgetangf = CreateGetAngFunc(math.floor) + + local function printang(x, y) + printf('%4d,%4d: %13d, %16d, %16d', x, y, + gv.getangle(x, y), ourgetang(x, y), ourgetangf(x, y)) + end + + print " x, y: getangle(x, y) | math.atan2/ceil | math.atan2/floor" + printang(10, 100) + printang(10, -100) + printang(-10, -100) + printang(-10, 100) + + printang(0, 0) + + printang(1, 0) + printang(0, 1) + printang(-1, 0) + printang(0, -1) + + local N=1e5 + local r = 0 + + local t = gv.gethiticks() + for i=1,N do + r = r + gv.getangle(10, i) + end + local t1 = gv.gethiticks()-t + + r = 0 + t = gv.gethiticks() + for i=1,N do + r = r + ourgetang(10, i) + end + local t2 = gv.gethiticks()-t + + printf('Time for %d runs: getangle: %.03f ms, math.atan2: %.03f ms', N, t1, t2) + print('----------') +end