Lunatic: more commands, timing test for xmath's sine functions.

git-svn-id: https://svn.eduke32.com/eduke32@3489 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-02-16 18:53:15 +00:00
parent 6cd3b9f4fc
commit a3b3804a08
9 changed files with 85 additions and 32 deletions

View file

@ -157,7 +157,8 @@ ifneq (0,$(LUNATIC))
$(OBJ)/luaJIT_BC_bitar.$o \ $(OBJ)/luaJIT_BC_bitar.$o \
$(OBJ)/luaJIT_BC_control.$o \ $(OBJ)/luaJIT_BC_control.$o \
$(OBJ)/luaJIT_BC_bcarray.$o \ $(OBJ)/luaJIT_BC_bcarray.$o \
$(OBJ)/luaJIT_BC_bcheck.$o $(OBJ)/luaJIT_BC_bcheck.$o \
$(OBJ)/luaJIT_BC_xmath.$o
# now, take care of having the necessary symbols (sector, wall, etc.) in the # now, take care of having the necessary symbols (sector, wall, etc.) in the
# executable no matter what the debugging level # executable no matter what the debugging level

View file

@ -11036,6 +11036,13 @@ int32_t krecip(int32_t num)
return(krecipasm(num)); return(krecipasm(num));
} }
#ifdef LUNATIC
int32_t Mulscale(int32_t a, int32_t b, int32_t sh)
{
return mulscale(a, b, sh);
}
#endif
// Gets the BUILD unit height and z offset of a sprite. // Gets the BUILD unit height and z offset of a sprite.
// Returns the z offset, 'height' may be NULL. // Returns the z offset, 'height' may be NULL.
int32_t spriteheightofsptr(const spritetype *spr, int32_t *height, int32_t alsotileyofs) int32_t spriteheightofsptr(const spritetype *spr, int32_t *height, int32_t alsotileyofs)

View file

@ -387,7 +387,7 @@ int32_t maybe_append_ext(char *wbuf, int32_t wbufsiz, const char *fn, const char
} }
// Approximations to the 2D and 3D euclidean distances. Initial EDuke32 SVN import says // Approximations to 2D and 3D Euclidean distances. Initial EDuke32 SVN import says
// in jmact/mathutil.c: "Ken's reverse-engineering job". // in jmact/mathutil.c: "Ken's reverse-engineering job".
// Note that jmact/mathutil.c contains practically the same code, but where the // Note that jmact/mathutil.c contains practically the same code, but where the
// individual x/y(/z) distances are passed instead. // individual x/y(/z) distances are passed instead.

View file

@ -765,12 +765,10 @@ function _awayfromwall(spr, d)
return true return true
end end
local BANG2RAD = math.pi/1024 local xmath = require("xmath")
local function cossinb(bang) local function cossinb(bang)
-- XXX: better use the precalc'd arrays instead? return xmath.cosb(bang), xmath.sinb(bang)
local ang = BANG2RAD*bang
return 16384*math.cos(ang), 16384*math.sin(ang)
end end
local function manhatdist(v1, v2) local function manhatdist(v1, v2)
@ -844,6 +842,10 @@ function _cansee(aci, ps)
return can return can
end end
function _canseespr(s1, s2)
return cansee(sprite[s1], sprite[s1].sectnum, sprite[s2], sprite[s2].sectnum) and 1 or 0
end
function _sleepcheck(aci, dist) function _sleepcheck(aci, dist)
local acs = actor[aci] local acs = actor[aci]
if (dist > MAXSLEEPDIST and acs.timetosleep == 0) then if (dist > MAXSLEEPDIST and acs.timetosleep == 0) then

View file

@ -1091,6 +1091,7 @@ local allowed_modules = {
geom = geom, geom = geom,
stat = require("stat"), stat = require("stat"),
bitar = require("bitar"), bitar = require("bitar"),
xmath = require("xmath"),
con = con, con = con,
} }

View file

@ -274,6 +274,7 @@ double gethitickms(void);
int32_t krand(void); int32_t krand(void);
int32_t ksqrt(uint32_t num); int32_t ksqrt(uint32_t num);
int32_t __fastcall getangle(int32_t xvect, int32_t yvect); int32_t __fastcall getangle(int32_t xvect, int32_t yvect);
int32_t Mulscale(int32_t a, int32_t b, int32_t sh);
]] ]]
local bcheck = require("bcheck") local bcheck = require("bcheck")
@ -750,12 +751,8 @@ function hitscan(pos, sectnum, vx,vy,vz, cliptype)
end end
function cansee(pos1,sect1, pos2,sect2) function cansee(pos1,sect1, pos2,sect2)
if (sect1 >= ffiC.numsectors+0ULL) then check_sector_idx(sect1)
error("passed out-of-bounds first sector number "..sect1, 2) check_sector_idx(sect2)
end
if (sect2 >= ffiC.numsectors+0ULL) then
error("passed out-of-bounds second sector number "..sect2, 2)
end
local ret = ffiC.cansee(pos1.x,pos1.y,pos1.z, sect1, local ret = ffiC.cansee(pos1.x,pos1.y,pos1.z, sect1,
pos2.x,pos2.y,pos2.z, sect2) pos2.x,pos2.y,pos2.z, sect2)

View file

@ -119,6 +119,9 @@ luaJIT_BC_randgen;
luaJIT_BC_stat; luaJIT_BC_stat;
luaJIT_BC_bitar; luaJIT_BC_bitar;
luaJIT_BC_control; luaJIT_BC_control;
luaJIT_BC_bcarray;
luaJIT_BC_bcheck;
luaJIT_BC_xmath;
rand_jkiss_u32; rand_jkiss_u32;
rand_jkiss_dbl; rand_jkiss_dbl;

View file

@ -137,13 +137,15 @@ local function getlinecol(pos) end -- fwd-decl
local function new_initial_codetab() local function new_initial_codetab()
return { return {
"local _con, _bit, _math = require'con', require'bit', require'math';", "local _con, _bit, _math = require'con', require'bit', require'math';",
"local _xmath, _geom = require'xmath', require'geom';",
"local sector, sprite, actor, player = sector, sprite, actor, player;", "local sector, sprite, actor, player = sector, sprite, actor, player;",
"local gameactor, gameevent, _gv = gameactor, gameevent, gv;" "local gameactor, gameevent, _gv = gameactor, gameevent, gv;",
"local cansee = cansee;"
} }
end end
-- CON global system gamevar -- CON global system gamevar
local function CSV(var) return "gv._csv"..var end local function CSV(var) return "_gv._csv"..var end
-- Creates the table of predefined game variables. -- Creates the table of predefined game variables.
-- KEEPINSYNC gamevars.c: Gv_AddSystemVars() -- KEEPINSYNC gamevars.c: Gv_AddSystemVars()
@ -1401,14 +1403,17 @@ local Cinner = {
--- 2. Math operations --- 2. Math operations
sqrt = cmd(R,W) sqrt = cmd(R,W)
/ "%2=gv.ksqrt(%1)", / "%2=_gv.ksqrt(%1)",
calchypotenuse = cmd(W,R,R) calchypotenuse = cmd(W,R,R)
/ "%1=_con._hypot(%2,%3)", / "%1=_con._hypot(%2,%3)",
sin = cmd(W,R), sin = cmd(W,R)
cos = cmd(W,R), / "%1=_xmath.ksin(%2)",
mulscale = cmd(W,R,R,R), cos = cmd(W,R)
/ "%1=_xmath.kcos(%2)",
mulscale = cmd(W,R,R,R)
/ "%1=_gv.Mulscale(%1,%2,%3)",
getangle = cmd(W,R,R) getangle = cmd(W,R,R)
/ "%1=gv.getangle(%2,%3)", / "%1=_gv.getangle(%2,%3)",
getincangle = cmd(W,R,R) getincangle = cmd(W,R,R)
/ "%1=_con._angdiff(%2,%3)", / "%1=_con._angdiff(%2,%3)",
@ -1460,7 +1465,7 @@ local Cinner = {
lockplayer = cmd(R) lockplayer = cmd(R)
/ PLS".transporter_hold=%1", / PLS".transporter_hold=%1",
quake = cmd(R) quake = cmd(R)
/ "gv.doQuake(%1,81)", -- EARTHQUAKE / "_gv.doQuake(%1,81)", -- EARTHQUAKE
jump = cmd(R) jump = cmd(R)
/ handle.NYI, -- will never be / handle.NYI, -- will never be
cmenu = cmd(R) cmenu = cmd(R)
@ -1474,7 +1479,6 @@ local Cinner = {
echo = cmd(R) echo = cmd(R)
/ "_con._echo(%1)", / "_con._echo(%1)",
starttrackvar = cmd(R), starttrackvar = cmd(R),
clearmapstate = cmd(R),
activatecheat = cmd(R) activatecheat = cmd(R)
/ handle.NYI, / handle.NYI,
setgamepalette = cmd(R), setgamepalette = cmd(R),
@ -1650,18 +1654,25 @@ local Cinner = {
/ handle.addlog, / handle.addlog,
addweaponvar = cmd(R,R) -- NLCF addweaponvar = cmd(R,R) -- NLCF
/ handle.addweapon, / handle.addweapon,
cansee = cmd(R,R,R,R,R,R,R,R,W), cansee = cmd(R,R,R,R,R,R,R,R,W)
canseespr = cmd(R,R,W), / "%9=cansee(_geom.ivec3(%1,%2,%3),%4, _geom.ivec3(%5,%6,%7),%8) and 1 or 0",
canseespr = cmd(R,R,W)
/ "%3=_con._canseespr(%1,%2)",
changespritesect = cmd(R,R) changespritesect = cmd(R,R)
/ "sprite.changesect(%1,%2)", / "sprite.changesect(%1,%2)",
changespritestat = cmd(R,R) changespritestat = cmd(R,R)
/ "sprite.changestat(%1,%2)", / "sprite.changestat(%1,%2)",
clipmove = cmd(W,W,W,R,W,R,R,R,R,R,R), clipmove = cmd(W,W,W,R,W,R,R,R,R,R,R)
clipmovenoslide = cmd(W,W,W,R,W,R,R,R,R,R,R), / handle.NYI,
clipmovenoslide = cmd(W,W,W,R,W,R,R,R,R,R,R)
/ handle.NYI,
displayrand = cmd(W), displayrand = cmd(W),
displayrandvar = cmd(W,D), displayrandvar = cmd(W,D),
displayrandvarvar = cmd(W,R), displayrandvarvar = cmd(W,R),
dist = cmd(W,R,R), dist = cmd(W,R,R)
/ "%1=_xmath.dist(sprite[%1],sprite[%2])",
ldist = cmd(W,R,R)
/ "%1=_xmath.ldist(sprite[%1],sprite[%2])",
dragpoint = cmd(R,R,R), dragpoint = cmd(R,R,R),
hitscan = cmd(R,R,R,R,R,R,R,W,W,W,W,W,W,R), -- 7R 6W 1R hitscan = cmd(R,R,R,R,R,R,R,W,W,W,W,W,W,R), -- 7R 6W 1R
@ -1672,11 +1683,10 @@ local Cinner = {
digitalnumberz = cmd(R,R,R,R,R,R,R,R,R,R,R,R), -- 12R digitalnumberz = cmd(R,R,R,R,R,R,R,R,R,R,R,R), -- 12R
minitext = cmd(R,R,R,R,R), minitext = cmd(R,R,R,R,R),
ldist = cmd(W,R,R), lineintersect = cmd(R,R,R,R,R,R,R,R,R,R,W,W,W,W) -- 10R 4W
lineintersect = cmd(R,R,R,R,R,R,R,R,R,R,W,W,W,W), -- 10R 4W / handle.NYI,
rayintersect = cmd(R,R,R,R,R,R,R,R,R,R,W,W,W,W), -- 10R 4W rayintersect = cmd(R,R,R,R,R,R,R,R,R,R,W,W,W,W) -- 10R 4W
loadmapstate = cmd(), / handle.NYI,
savemapstate = cmd(),
movesprite = cmd(R,R,R,R,R,W), movesprite = cmd(R,R,R,R,R,W),
neartag = cmd(R,R,R,R,R,W,W,W,W,R,R), neartag = cmd(R,R,R,R,R,W,W,W,W,R,R),
palfrom = (sp1 * tok.define)^-4 palfrom = (sp1 * tok.define)^-4
@ -1703,6 +1713,10 @@ local Cinner = {
myospalx = cmd(R,R,R,R,R,R) myospalx = cmd(R,R,R,R,R,R)
/ "_con._myos(%1,%2,32768,%3,%4,%5,%6)", / "_con._myos(%1,%2,32768,%3,%4,%5,%6)",
clearmapstate = cmd(R),
loadmapstate = cmd(),
savemapstate = cmd(),
headspritesect = cmd(W,R), headspritesect = cmd(W,R),
headspritestat = cmd(W,R), headspritestat = cmd(W,R),
nextspritesect = cmd(W,R), nextspritesect = cmd(W,R),
@ -1770,7 +1784,7 @@ local Cinner = {
getkeyname = cmd(R,R,R), getkeyname = cmd(R,R,R),
getpname = cmd(R,R), getpname = cmd(R,R),
getticks = cmd(W) getticks = cmd(W)
/ "%1=gv.getticks()", / "%1=_gv.getticks()",
gettimedate = cmd(W,W,W,W,W,W,W,W) gettimedate = cmd(W,W,W,W,W,W,W,W)
/ "%1,%2,%3,%4,%5,%6,%7,%8=_con._gettimedate()", / "%1,%2,%3,%4,%5,%6,%7,%8=_con._gettimedate()",
getzrange = cmd(R,R,R,R,W,W,W,W,R,R), getzrange = cmd(R,R,R,R,W,W,W,W,R,R),

View file

@ -400,6 +400,34 @@ bittest.sieve()
require("test/test_geom") require("test/test_geom")
require("test/test_rotspr") require("test/test_rotspr")
do
-- Test ksin vs. sinb
local xmath = require "xmath"
local sum = 0
local N = 1000
local t = gv.gethitickms()
for i=0,N*2048-1 do
sum = sum+xmath.ksin(i)
end
t = gv.gethitickms()-t
sum = sum*1e12
printf("ksin: sum*1e12=%.03f, %.03fus per 0-2047 cycle", sum, t)
sum = 0
local t = gv.gethitickms()
for i=0,N*2048-1 do
sum = sum+xmath.sinb(i)
end
t = gv.gethitickms()-t
sum = sum*1e12
printf("sinb: sum*1e12=%.03f, %.03fus per 0-2047 cycle", sum, t)
-- Results (helixhorned x86):
-- ksin: sum*1e12=0.000, 3.801us per 0-2047 cycle
-- sinb: sum*1e12=0.052, 2.886us per 0-2047 cycle
end
print('---=== END TEST SCRIPT ===---') print('---=== END TEST SCRIPT ===---')
--[[ --[[