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_control.$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
# executable no matter what the debugging level

View file

@ -11036,6 +11036,13 @@ int32_t krecip(int32_t 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.
// Returns the z offset, 'height' may be NULL.
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".
// Note that jmact/mathutil.c contains practically the same code, but where the
// individual x/y(/z) distances are passed instead.

View file

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

View file

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

View file

@ -274,6 +274,7 @@ double gethitickms(void);
int32_t krand(void);
int32_t ksqrt(uint32_t num);
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")
@ -750,12 +751,8 @@ function hitscan(pos, sectnum, vx,vy,vz, cliptype)
end
function cansee(pos1,sect1, pos2,sect2)
if (sect1 >= ffiC.numsectors+0ULL) then
error("passed out-of-bounds first sector number "..sect1, 2)
end
if (sect2 >= ffiC.numsectors+0ULL) then
error("passed out-of-bounds second sector number "..sect2, 2)
end
check_sector_idx(sect1)
check_sector_idx(sect2)
local ret = ffiC.cansee(pos1.x,pos1.y,pos1.z, sect1,
pos2.x,pos2.y,pos2.z, sect2)

View file

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

View file

@ -137,13 +137,15 @@ local function getlinecol(pos) end -- fwd-decl
local function new_initial_codetab()
return {
"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 gameactor, gameevent, _gv = gameactor, gameevent, gv;"
"local gameactor, gameevent, _gv = gameactor, gameevent, gv;",
"local cansee = cansee;"
}
end
-- 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.
-- KEEPINSYNC gamevars.c: Gv_AddSystemVars()
@ -1401,14 +1403,17 @@ local Cinner = {
--- 2. Math operations
sqrt = cmd(R,W)
/ "%2=gv.ksqrt(%1)",
/ "%2=_gv.ksqrt(%1)",
calchypotenuse = cmd(W,R,R)
/ "%1=_con._hypot(%2,%3)",
sin = cmd(W,R),
cos = cmd(W,R),
mulscale = cmd(W,R,R,R),
sin = cmd(W,R)
/ "%1=_xmath.ksin(%2)",
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)
/ "%1=gv.getangle(%2,%3)",
/ "%1=_gv.getangle(%2,%3)",
getincangle = cmd(W,R,R)
/ "%1=_con._angdiff(%2,%3)",
@ -1460,7 +1465,7 @@ local Cinner = {
lockplayer = cmd(R)
/ PLS".transporter_hold=%1",
quake = cmd(R)
/ "gv.doQuake(%1,81)", -- EARTHQUAKE
/ "_gv.doQuake(%1,81)", -- EARTHQUAKE
jump = cmd(R)
/ handle.NYI, -- will never be
cmenu = cmd(R)
@ -1474,7 +1479,6 @@ local Cinner = {
echo = cmd(R)
/ "_con._echo(%1)",
starttrackvar = cmd(R),
clearmapstate = cmd(R),
activatecheat = cmd(R)
/ handle.NYI,
setgamepalette = cmd(R),
@ -1650,18 +1654,25 @@ local Cinner = {
/ handle.addlog,
addweaponvar = cmd(R,R) -- NLCF
/ handle.addweapon,
cansee = cmd(R,R,R,R,R,R,R,R,W),
canseespr = cmd(R,R,W),
cansee = cmd(R,R,R,R,R,R,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)
/ "sprite.changesect(%1,%2)",
changespritestat = cmd(R,R)
/ "sprite.changestat(%1,%2)",
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),
clipmove = 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),
displayrandvar = cmd(W,D),
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),
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
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
rayintersect = cmd(R,R,R,R,R,R,R,R,R,R,W,W,W,W), -- 10R 4W
loadmapstate = cmd(),
savemapstate = cmd(),
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
/ handle.NYI,
movesprite = cmd(R,R,R,R,R,W),
neartag = cmd(R,R,R,R,R,W,W,W,W,R,R),
palfrom = (sp1 * tok.define)^-4
@ -1703,6 +1713,10 @@ local Cinner = {
myospalx = cmd(R,R,R,R,R,R)
/ "_con._myos(%1,%2,32768,%3,%4,%5,%6)",
clearmapstate = cmd(R),
loadmapstate = cmd(),
savemapstate = cmd(),
headspritesect = cmd(W,R),
headspritestat = cmd(W,R),
nextspritesect = cmd(W,R),
@ -1770,7 +1784,7 @@ local Cinner = {
getkeyname = cmd(R,R,R),
getpname = cmd(R,R),
getticks = cmd(W)
/ "%1=gv.getticks()",
/ "%1=_gv.getticks()",
gettimedate = cmd(W,W,W,W,W,W,W,W)
/ "%1,%2,%3,%4,%5,%6,%7,%8=_con._gettimedate()",
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_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 ===---')
--[[