2011-09-20 19:12:24 +00:00
|
|
|
-- test script for ELua/Lunatic Interpreter
|
|
|
|
|
2012-05-06 20:22:56 +00:00
|
|
|
--do return end
|
2012-04-22 19:10:29 +00:00
|
|
|
|
2012-07-13 18:20:38 +00:00
|
|
|
-- error=nil -- must not affect "require"
|
|
|
|
local string = require("string")
|
|
|
|
local bit = require("bit")
|
|
|
|
local math = require("math")
|
|
|
|
|
2012-12-25 16:13:45 +00:00
|
|
|
local pcall = pcall
|
|
|
|
local DBG_ = DBG_
|
|
|
|
|
2012-05-13 16:04:28 +00:00
|
|
|
print('---=== ELua Test script ===---')
|
2011-09-20 19:12:24 +00:00
|
|
|
|
2012-06-10 18:56:10 +00:00
|
|
|
local function printf(fmt, ...)
|
|
|
|
print(string.format(fmt, ...))
|
|
|
|
end
|
|
|
|
|
2012-07-13 18:20:40 +00:00
|
|
|
local function checkfail(funcstr, expectedmsg)
|
|
|
|
local status, errmsg = pcall(DBG_.loadstring(funcstr))
|
2011-09-25 15:11:47 +00:00
|
|
|
if (status) then
|
2012-12-25 16:13:41 +00:00
|
|
|
print('^21ERROR:^O '..funcstr.." DIDN'T fail")
|
2011-09-25 15:11:47 +00:00
|
|
|
else
|
2012-07-13 18:20:40 +00:00
|
|
|
if (expectedmsg==nil or string.find(errmsg, expectedmsg, 1, true)) then
|
2012-12-25 16:13:41 +00:00
|
|
|
print("^11SUCCESS:^O "..funcstr.." failed: "..errmsg)
|
2012-07-13 18:20:40 +00:00
|
|
|
else
|
2012-12-25 16:13:41 +00:00
|
|
|
-- XXX: beginning with "^10" is counted as error in OSD_Printf()
|
|
|
|
print("^10ERROR*:^O "..funcstr.." failed: "..errmsg..
|
2012-07-13 18:20:40 +00:00
|
|
|
", but expected error message was: "..expectedmsg)
|
|
|
|
end
|
2011-09-25 15:11:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-04-22 19:10:29 +00:00
|
|
|
|
|
|
|
---- check serialization ----
|
|
|
|
gamevar("ourvar")
|
|
|
|
gamevar("ourvar2")
|
|
|
|
|
2012-06-17 19:45:37 +00:00
|
|
|
-- test nans, infs, precision, subnorms, booleans
|
|
|
|
ourvar2 = { "asd"; 0/0, 1/0, -1/0, 0.12345678901234567, 1e-314, true }
|
|
|
|
ourvar = { ourvar2; 1, 2, 3, "qwe"; [true]=0, [false]=1 }
|
2012-04-22 19:10:29 +00:00
|
|
|
ourvar[#ourvar+1] = ourvar;
|
|
|
|
|
|
|
|
local gvstr = DBG_.serializeGamevars()
|
|
|
|
ourvar = -1
|
|
|
|
|
2012-05-13 16:04:28 +00:00
|
|
|
print("========== attempting to load string: ==========")
|
2012-04-22 19:10:29 +00:00
|
|
|
print(gvstr)
|
|
|
|
print("---------- (end string to load) ----------")
|
|
|
|
|
2012-06-17 19:45:33 +00:00
|
|
|
-- XXX: need to think about fully restoring state
|
2012-04-22 19:10:29 +00:00
|
|
|
DBG_.loadGamevarsString(gvstr)
|
|
|
|
print("ourvar[4]="..ourvar[4])
|
|
|
|
|
|
|
|
|
2011-09-20 19:12:24 +00:00
|
|
|
print('tweaking sector pals')
|
2012-02-08 11:00:48 +00:00
|
|
|
print('numsectors: ' .. gv.numsectors .. ' of ' .. gv.MAXSECTORS)
|
2012-01-28 14:37:24 +00:00
|
|
|
|
2011-10-11 16:53:15 +00:00
|
|
|
---[[
|
2011-09-20 19:12:24 +00:00
|
|
|
for i = 0, gv.numsectors/2 do
|
|
|
|
sector[i].floorpal = 1;
|
|
|
|
sector[i].ceilingpal = 2;
|
|
|
|
end
|
|
|
|
|
2013-01-20 21:17:06 +00:00
|
|
|
local vol, lev = gv.currentEpisode()+1, gv.currentLevel()+1
|
|
|
|
printf('volume=%d, level=%d', vol, lev)
|
2012-01-28 14:38:41 +00:00
|
|
|
|
|
|
|
if (vol==1 and lev==1) then -- E1L1
|
|
|
|
print('tweaking some sprites 2')
|
2013-03-21 10:20:14 +00:00
|
|
|
local i = 562
|
2012-01-28 14:38:41 +00:00
|
|
|
spriteext[i].alpha = 0.5;
|
|
|
|
sprite[i].cstat = bit.bor(sprite[i].cstat, 2+512);
|
|
|
|
spriteext[i].pitch = 128;
|
|
|
|
spriteext[i].roll = 256;
|
|
|
|
|
2013-03-21 10:20:14 +00:00
|
|
|
i = 107 -- pistol ammo at rooftop
|
|
|
|
spriteext[i].pitch = 128;
|
|
|
|
spriteext[i].roll = 256;
|
|
|
|
|
2012-01-28 14:38:41 +00:00
|
|
|
for spr in spritesofsect(307) do -- some fence sprites in E1L1
|
2013-01-19 18:28:40 +00:00
|
|
|
printf('spr %d', spr)
|
2012-01-28 14:38:41 +00:00
|
|
|
sprite[spr].pal = 6
|
|
|
|
end
|
2012-01-28 14:37:24 +00:00
|
|
|
|
2012-01-28 14:38:41 +00:00
|
|
|
--this is a problem
|
|
|
|
--actor = {}
|
|
|
|
actor[562].flags = bit.bor(actor[562].flags, 2); -- pal 6 with goggles on front SEENINE
|
|
|
|
end
|
|
|
|
|
2012-12-29 15:21:24 +00:00
|
|
|
--[[
|
|
|
|
-- TODO: better API for all TROR things?
|
2012-01-28 14:38:41 +00:00
|
|
|
if (vol==1 and lev==8) then
|
2012-02-04 14:29:59 +00:00
|
|
|
print('tweaking bunch 1');
|
2012-01-28 14:38:41 +00:00
|
|
|
-- trueror1.map
|
|
|
|
for i in sectorsofbunch(1, gv.CEILING) do
|
|
|
|
sector[i].ceilingz = sector[i].ceilingz - 3*1024;
|
|
|
|
end
|
|
|
|
for i in sectorsofbunch(1, gv.FLOOR) do
|
|
|
|
sector[i].floorz = sector[i].floorz - 3*1024;
|
|
|
|
end
|
|
|
|
end
|
2012-12-29 15:21:24 +00:00
|
|
|
--]]
|
2011-12-21 18:43:08 +00:00
|
|
|
|
2012-07-20 21:57:37 +00:00
|
|
|
local unsafe = pcall(function() string.UNSAFE=true; end)
|
|
|
|
|
2011-10-11 16:53:15 +00:00
|
|
|
--]]
|
2012-07-13 18:20:35 +00:00
|
|
|
--tostring = nil -- REMEMBER
|
2012-05-29 20:01:58 +00:00
|
|
|
--DBG_.printkv('_G in test.elua', _G)
|
2011-09-25 15:11:47 +00:00
|
|
|
|
2012-07-13 18:20:40 +00:00
|
|
|
-- direct gv array access forbidden
|
2013-01-19 18:28:40 +00:00
|
|
|
checkfail('gv.sprite[0].yrepeat = 100', "access forbidden")
|
2012-07-13 18:20:40 +00:00
|
|
|
|
|
|
|
-- indexing struct array with non-numeric type
|
|
|
|
checkfail('local i = sprite["qwe"]') -- this will produce an error inside the sprite metatable
|
|
|
|
|
2013-02-10 16:23:54 +00:00
|
|
|
checkfail('print(sprite[100000].ceilingpal)', "out-of-bounds sprite[] read access")
|
2012-07-13 18:20:40 +00:00
|
|
|
|
2013-01-19 18:28:40 +00:00
|
|
|
checkfail('print(gv.sprite[0])', "access forbidden")
|
2012-07-13 18:20:40 +00:00
|
|
|
|
|
|
|
-- set metatable forbidden
|
|
|
|
checkfail('setmetatable(sprite, {})', "attempt to read undeclared variable 'setmetatable'")
|
|
|
|
|
2013-01-19 18:28:40 +00:00
|
|
|
-- OOB write access.
|
|
|
|
-- Note that indexing ("reading") sector fails, even if the user wants to
|
|
|
|
-- assign to a sector member. Potentially confusing error message.
|
|
|
|
checkfail('sector[-1].ceilingpal = 4', "out-of-bounds sector[] read access")
|
2012-07-13 18:20:40 +00:00
|
|
|
|
|
|
|
-- wallnum member is read-only
|
|
|
|
checkfail('sector[0].wallnum = 0', "attempt to write to constant location") -- this comes from LJ/FFI
|
|
|
|
|
|
|
|
-- gv.numsectors is read-only
|
2013-01-19 18:28:40 +00:00
|
|
|
checkfail('gv.numsectors = 4', "write access forbidden")
|
2012-07-13 18:20:40 +00:00
|
|
|
|
|
|
|
-- cannot create new fields in 'gv'
|
2013-01-19 18:28:40 +00:00
|
|
|
checkfail('gv.QWE = 4', "write access forbidden")
|
2012-07-13 18:20:40 +00:00
|
|
|
|
|
|
|
-- direct sector write access forbidden
|
2013-02-01 13:05:20 +00:00
|
|
|
checkfail('sector[4] = sector[6]', "cannot write directly to sector[]")
|
2012-07-13 18:20:40 +00:00
|
|
|
|
|
|
|
-- that would be horrible...
|
2013-02-18 16:07:32 +00:00
|
|
|
checkfail('sprite._nextspritesect[4] = -666', "cannot write directly to nextspritesect[]")
|
2012-07-13 18:20:40 +00:00
|
|
|
|
|
|
|
-- we're indexing a plain array!
|
2013-02-18 16:07:32 +00:00
|
|
|
checkfail('print(sprite._nextspritesect[4].whatfield)', "attempt to index a number value")
|
2012-07-13 18:20:40 +00:00
|
|
|
|
2013-03-15 16:56:19 +00:00
|
|
|
-- creating new keys forbidden... handled by LuaJIT
|
2012-07-13 18:20:40 +00:00
|
|
|
checkfail('wall[4].QWE = 123', "has no member named 'QWE'")
|
|
|
|
|
2012-11-03 19:32:43 +00:00
|
|
|
-- our 'require' has only safe stuff
|
|
|
|
--checkfail("require('os')")
|
2012-07-13 18:20:40 +00:00
|
|
|
|
|
|
|
-- we must declare globals with 'gamevar'
|
|
|
|
checkfail("new_global = 345", "attempt to write to undeclared variable 'new_global'")
|
|
|
|
|
|
|
|
-- can't redefine constants in 'gv'
|
2013-01-19 18:28:40 +00:00
|
|
|
checkfail('gv.CEILING = 3', "write access forbidden")
|
2012-07-13 18:20:40 +00:00
|
|
|
|
|
|
|
-- string.dump is unavailable
|
|
|
|
checkfail('local s=require[[string]]; local tmp=s.dump(gameevent)',
|
|
|
|
"attempt to call field 'dump' (a nil value)")
|
|
|
|
|
2012-07-20 21:57:37 +00:00
|
|
|
if (not unsafe) then
|
|
|
|
-- changing base module tables is disallowed
|
|
|
|
checkfail('local s=require[[string]]; s.format=nil', "modifying base module table forbidden")
|
|
|
|
else
|
|
|
|
print('WARNING: RUNNING WITH UNPROTECTED BASE MODULES')
|
|
|
|
end
|
2012-07-13 18:20:40 +00:00
|
|
|
|
2012-07-13 18:20:38 +00:00
|
|
|
print('')
|
2012-05-29 20:01:58 +00:00
|
|
|
-- This is problematic, even though pretty much every access will yield a
|
|
|
|
-- "missing declaration" error.
|
|
|
|
-- See http://luajit.org/ext_ffi_api.html#ffi_C about what stuff ffi.C contains.
|
2012-07-13 18:20:40 +00:00
|
|
|
checkfail('gv.luaJIT_setmode(nil, 0, 0)', "missing declaration for symbol 'luaJIT_setmode'")
|
|
|
|
|
|
|
|
checkfail('gv.luaJIT_BC_con_lang', "attempt to call a nil value")
|
2013-01-19 18:28:40 +00:00
|
|
|
checkfail('gv.yax_getbunch(0,0)', "access forbidden")
|
|
|
|
checkfail('gv.gethitickms = nil', "write access forbidden")
|
2012-07-13 18:20:40 +00:00
|
|
|
|
2013-02-03 12:48:06 +00:00
|
|
|
-- actor[].t_data[] is not accessible for now
|
2012-07-13 18:20:40 +00:00
|
|
|
checkfail('local i = actor[0].t_data[15]', "has no member named 't_data'")
|
|
|
|
|
|
|
|
-- no pointer arithmetic!
|
2012-08-19 12:52:18 +00:00
|
|
|
checkfail('local spr = sprite[0]; local x=spr+1', "attempt to perform arithmetic on")
|
2012-07-13 18:20:40 +00:00
|
|
|
|
2012-12-23 19:24:16 +00:00
|
|
|
checkfail('gameactor(1680, 0)', "invalid last argument to gameactor: must be a function")
|
2012-07-13 18:20:40 +00:00
|
|
|
|
2012-07-20 21:57:37 +00:00
|
|
|
checkfail("do local bt=require'bittest'; bt.QWE=1; end", "modifying module table forbidden")
|
2012-11-25 13:18:52 +00:00
|
|
|
-- the cdata returned by player[] can't be made into a pointer!
|
|
|
|
checkfail("do local pl=player[0]; i=pl[1]; end")
|
2013-01-19 18:28:40 +00:00
|
|
|
checkfail("do local ud=gv.ud.camerasprite; end", "access forbidden") -- test for proper decl()
|
2013-02-10 16:23:54 +00:00
|
|
|
checkfail("sprite[0]:set_picnum(-10)", "invalid tile number")
|
2013-01-19 18:28:40 +00:00
|
|
|
checkfail("gv.g_sizes_of=nil; print(gv.g_sizes_of[0])", "write access forbidden")
|
2013-02-10 16:23:54 +00:00
|
|
|
checkfail("gv.cam.sect=-1", "invalid sector number")
|
2012-06-22 21:40:01 +00:00
|
|
|
|
|
|
|
printf('ceilingbunch of sector 0: %d', getbunch(0, gv.CEILING))
|
2012-05-29 20:01:58 +00:00
|
|
|
|
2012-06-10 18:56:15 +00:00
|
|
|
gameevent(gv.EVENT_JUMP,
|
|
|
|
function(actori, playeri, dist)
|
|
|
|
printf("jump i=%d p=%d d=%d", actori, playeri, dist)
|
2012-12-25 16:13:41 +00:00
|
|
|
error("greetings from EVENT_JUMP")
|
2012-06-10 18:56:15 +00:00
|
|
|
end
|
|
|
|
)
|
|
|
|
|
2013-02-10 16:24:44 +00:00
|
|
|
gameevent("PROCESSINPUT",
|
|
|
|
-- Input test.
|
|
|
|
-- NOTE: I don't think that exposing g_player[].sync (aka "input") is a good idea...
|
|
|
|
function(actori, playeri, dist)
|
|
|
|
local IB = player.INPUT_BITS
|
|
|
|
local input = player[playeri]._input
|
|
|
|
if (bit.band(input.bits, IB.JUMP) ~= 0) then
|
|
|
|
print("JUMPED")
|
|
|
|
-- ... because for example this doesn't work
|
|
|
|
-- (P_HandleSharedKeys, where the JETPACK bit is tested, runs
|
|
|
|
-- before P_ProcessInput):
|
|
|
|
input.bits = bit.bor(input.bits, IB.JETPACK)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
2012-12-25 16:13:45 +00:00
|
|
|
-- test event chaining
|
|
|
|
gameevent("JUMP",
|
|
|
|
function(actori, playeri, dist)
|
2013-01-20 21:17:06 +00:00
|
|
|
local ps = player[playeri]
|
2012-12-25 16:13:45 +00:00
|
|
|
print("I'm first!")
|
2013-01-06 18:56:45 +00:00
|
|
|
-- DBG_.oom()
|
2013-01-20 21:17:06 +00:00
|
|
|
ps.weapon.PISTOL.shoots = 2605 -- RPG
|
|
|
|
ps.weapon[gv.PISTOL_WEAPON].firesound = 351 -- thunder
|
|
|
|
|
2013-02-07 21:01:18 +00:00
|
|
|
-- XXX: provide either named constants or methods?
|
2013-01-20 21:17:06 +00:00
|
|
|
ps.pipebombControl = 2
|
|
|
|
ps.tripbombControl = 2
|
2013-02-01 13:04:52 +00:00
|
|
|
|
|
|
|
-- Test of INTERNAL member _pals.
|
|
|
|
-- NOTE: setting colors partially is bad! E.g. after an item is
|
|
|
|
-- picked up, col[0] and col[1] remain and tint everything greenish.
|
|
|
|
ps._pals.col[2] = 20
|
|
|
|
ps._pals.f = 30
|
2012-12-25 16:13:45 +00:00
|
|
|
end
|
|
|
|
)
|
|
|
|
|
2012-06-22 21:40:01 +00:00
|
|
|
gameevent(gv.EVENT_ENTERLEVEL,
|
|
|
|
function()
|
2013-02-10 16:24:32 +00:00
|
|
|
if (gv._DEBUG_LUNATIC) then
|
|
|
|
DBG_.testmembread()
|
|
|
|
end
|
|
|
|
|
2012-07-01 22:11:07 +00:00
|
|
|
-- NOTE: times are for helixhorned (Core2Duo 3GHz)
|
2012-06-22 21:40:01 +00:00
|
|
|
local i
|
|
|
|
local N = 1e6
|
|
|
|
local t = gv.gethitickms()
|
|
|
|
|
|
|
|
for i=3,N do
|
|
|
|
gv.gethitickms()
|
|
|
|
end
|
|
|
|
|
|
|
|
t = gv.gethitickms()-t
|
|
|
|
|
2012-08-06 20:00:23 +00:00
|
|
|
-- x86_64: 35ns/call, x86: 280 ns/call
|
2012-08-02 10:52:25 +00:00
|
|
|
-- Windows 32-bit: about 1 us/call?
|
2012-06-22 21:40:01 +00:00
|
|
|
printf("%d gethitickms() calls took %.03f ms (%.03f us/call)",
|
|
|
|
N, t, (t*1000)/N)
|
2012-07-01 22:11:07 +00:00
|
|
|
|
|
|
|
local sum=0
|
|
|
|
t = gv.gethitickms()
|
|
|
|
for i=1,N do sum = sum+gv.ksqrt(i) end
|
|
|
|
t = gv.gethitickms()-t
|
|
|
|
-- x86_64: 14ns/call
|
|
|
|
printf("%d ksqrt() calls took %.03f ms (%.03f us/call) [sum=%f]",
|
|
|
|
N, t, (t*1000)/N, sum)
|
|
|
|
|
|
|
|
sum=0
|
|
|
|
t = gv.gethitickms()
|
|
|
|
for i=1,N do sum = sum+math.sqrt(i) end
|
|
|
|
t = gv.gethitickms()-t
|
|
|
|
-- x86_64: 7ns/call
|
|
|
|
printf("%d math.sqrt() calls took %.03f ms (%.03f us/call) [sum=%f]",
|
|
|
|
N, t, (t*1000)/N, sum)
|
|
|
|
|
|
|
|
printf("sqrt(0xffffffff) = %f(ksqrt) %f(math.sqrt)",
|
2012-07-01 22:11:14 +00:00
|
|
|
gv.ksqrt(0xffffffff), math.sqrt(0xffffffff))
|
2012-12-25 16:13:45 +00:00
|
|
|
|
2013-02-01 13:04:52 +00:00
|
|
|
local pl = player[0]
|
2013-03-15 16:56:19 +00:00
|
|
|
-- MAX < current is "allowed"
|
2013-02-01 13:04:52 +00:00
|
|
|
pl.max_ammo_amount[gv.RPG_WEAPON] = 17
|
|
|
|
pl:give_weapon(gv.RPG_WEAPON)
|
|
|
|
pl.ammo_amount[gv.RPG_WEAPON] = 54
|
2013-01-26 17:07:44 +00:00
|
|
|
|
2013-03-15 16:56:19 +00:00
|
|
|
pl:give_weapon(gv.SHRINKER_WEAPON)
|
|
|
|
-- This looks much prettier:
|
|
|
|
pl.ammo_amount.SHRINKER = 2
|
|
|
|
|
2013-02-07 21:01:03 +00:00
|
|
|
-- MORTER2 from test/weaponvars.con
|
|
|
|
player[0].weapon.SHOTGUN.shoots = 1653
|
2013-02-10 16:23:59 +00:00
|
|
|
local proj = projectile[1653]
|
|
|
|
proj.drop = 0
|
|
|
|
proj:set_trail(2329) -- SMALLSMOKE
|
2013-02-07 21:01:03 +00:00
|
|
|
|
2013-02-10 16:23:54 +00:00
|
|
|
t = gv.gethitickms()
|
|
|
|
local N=1
|
|
|
|
for n=1,N do
|
|
|
|
for i=0,gv.MAXSPRITES-1 do
|
|
|
|
sprite[i].filler = 1
|
|
|
|
end
|
|
|
|
for i=gv.MAXSPRITES-1,0,-1 do
|
|
|
|
sprite[i].shade = 1
|
|
|
|
end
|
|
|
|
for i=0,gv.MAXSPRITES-1 do
|
|
|
|
sprite[i].xoffset = 0
|
|
|
|
end
|
|
|
|
for i=gv.MAXSPRITES-1,0,-1 do
|
|
|
|
sprite[i].yoffset = 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
t = gv.gethitickms()-t
|
|
|
|
printf("%d x four 0..MAXSPRITES-1 iterations took %.03f us per outer iteration", N, (1000*t)/N)
|
|
|
|
-- Results on x86:
|
|
|
|
-- N=1: 480-1000 us (too large variance)
|
|
|
|
-- N=10: 190-210 us * 10 = 1.9-2.1 ms
|
|
|
|
-- N=100: about 160 us * 100 = about 16 ms
|
|
|
|
|
2013-02-18 16:07:42 +00:00
|
|
|
-- Make the DUKECAR in E1L1 into a zombie actor (temporarily)
|
2013-02-10 16:24:32 +00:00
|
|
|
if (sprite[24].picnum==2491) then
|
2013-02-18 16:07:42 +00:00
|
|
|
sprite.changestat(24, gv.STAT_ZOMBIEACTOR)
|
2013-02-10 16:24:32 +00:00
|
|
|
end
|
|
|
|
|
2012-12-25 16:13:45 +00:00
|
|
|
checkfail("gameevent('GAME', function() print('qwe') end)",
|
|
|
|
"must be called from top level")
|
2012-06-22 21:40:01 +00:00
|
|
|
end
|
|
|
|
)
|
|
|
|
|
2013-02-18 16:07:42 +00:00
|
|
|
local geom = require "geom"
|
|
|
|
|
|
|
|
gameevent("LOADACTOR", function(i)
|
|
|
|
local spr = sprite[i]
|
|
|
|
if (i==614 and spr.picnum==930) then
|
|
|
|
-- "police line" ribbon in E1L1
|
|
|
|
-- clear the hitag so that it doesn't spawn as FALLER from premap
|
|
|
|
spr.hitag = 0
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
gameactor(930, 1, function(i) -- "police line" ribbon
|
|
|
|
local spr = sprite[i]
|
|
|
|
local r = math.random
|
|
|
|
local d = 20
|
2013-03-21 10:20:27 +00:00
|
|
|
-- NOTE: __add metamethod is called because of the RHS:
|
|
|
|
local v = spr + geom.vec3(r(-d,d), r(-d,d))
|
2013-02-18 16:07:42 +00:00
|
|
|
spr:setpos(v)
|
|
|
|
end)
|
|
|
|
|
2012-08-02 10:52:32 +00:00
|
|
|
local stat = require("stat")
|
|
|
|
local hs = stat.new()
|
|
|
|
|
2012-08-06 20:00:29 +00:00
|
|
|
local con = require("con")
|
2012-08-08 19:32:35 +00:00
|
|
|
local AC, MV = con.AC, con.MV
|
2012-12-23 19:24:16 +00:00
|
|
|
con.action("TROOPSTAND",0,1,5,1,1)
|
2012-08-06 20:00:29 +00:00
|
|
|
con.action("TROOPFLINTCH", 50, 1, 1, 1, 6)
|
2012-08-08 19:32:35 +00:00
|
|
|
con.move("SHRUNKVELS", 32)
|
2012-11-25 13:18:46 +00:00
|
|
|
con.ai("AITEMP", AC.TROOPFLINTCH, MV.SHRUNKVELS, 0) -- TODO: test
|
|
|
|
-- This should work as well. In fact, it's exactly the same, but I prefer the
|
|
|
|
-- above version for clarity. NOTE: we'll need to think whether it's OK to
|
|
|
|
-- redefine composites (moves/actions/ais) during gameplay (probably not).
|
|
|
|
-- Or will we allow only one definition per label ever?
|
|
|
|
con.ai("AITEMP", "TROOPFLINTCH", "SHRUNKVELS", 0)
|
2012-08-06 20:00:29 +00:00
|
|
|
|
2012-12-23 19:24:16 +00:00
|
|
|
local TROOPSTRENGTH = 30
|
|
|
|
|
|
|
|
gameactor(1680, TROOPSTRENGTH, "TROOPSTAND", -- LIZTROOP
|
2012-06-10 18:56:15 +00:00
|
|
|
function(i, playeri, dist)
|
2013-02-01 13:05:20 +00:00
|
|
|
spriteext[i]:make_animated()
|
|
|
|
|
2012-06-10 18:56:15 +00:00
|
|
|
sprite[i].pal = math.random(32)
|
|
|
|
-- sprite[i].ang = bit.band(sprite[i].ang-20, 2047)
|
2012-06-22 21:40:01 +00:00
|
|
|
|
|
|
|
local spr = sprite[i]
|
|
|
|
|
|
|
|
local t = gv.gethitickms()
|
2012-10-07 15:26:24 +00:00
|
|
|
local hit = hitscan(spr, spr.sectnum, 10, 10, 0, gv.CLIPMASK0)
|
2012-08-02 10:52:32 +00:00
|
|
|
|
|
|
|
hs:add(1000*(gv.gethitickms()-t))
|
|
|
|
|
|
|
|
if (hs.n == 300) then
|
2013-01-06 18:56:45 +00:00
|
|
|
printf("hitscan: %s", hs:getstatstr())
|
2012-08-19 12:52:18 +00:00
|
|
|
hs:reset()
|
2012-12-25 16:13:41 +00:00
|
|
|
error("greetings from LIZTROOP actor")
|
2012-08-02 10:52:32 +00:00
|
|
|
end
|
2012-08-06 20:00:29 +00:00
|
|
|
|
|
|
|
if (dist < 4096) then
|
|
|
|
-- Duke Vader / Anakin Nukewalker?
|
2012-11-25 13:18:46 +00:00
|
|
|
actor[i]:set_action("TROOPFLINTCH")
|
|
|
|
actor[i]:set_move("SHRUNKVELS")
|
2012-11-30 18:57:59 +00:00
|
|
|
|
|
|
|
if (dist < 1024) then
|
|
|
|
con.killit()
|
|
|
|
end
|
2012-08-06 20:00:29 +00:00
|
|
|
end
|
2012-06-10 18:56:15 +00:00
|
|
|
end
|
|
|
|
)
|
|
|
|
|
2013-01-19 18:28:40 +00:00
|
|
|
gameevent("DISPLAYROOMS",
|
|
|
|
function()
|
|
|
|
local cam = gv.cam
|
|
|
|
cam.pos.z = cam.pos.z + 64*16*math.sin(gv.totalclock/30)
|
2013-02-25 15:31:13 +00:00
|
|
|
|
|
|
|
local ps = player[0]
|
|
|
|
if (ps.cursectnum >= 0) then
|
|
|
|
local hit = sector[ps.cursectnum]:zrangeat(cam.pos)
|
|
|
|
if (gv.totalclock%200==0) then
|
|
|
|
printf("hit %s %d at z=%d, %s %d at z=%d",
|
|
|
|
hit.c.spritep and "sprite" or "sector", hit.c.num, hit.c.z,
|
|
|
|
hit.f.spritep and "sprite" or "sector", hit.f.num, hit.f.z)
|
|
|
|
end
|
|
|
|
end
|
2013-01-19 18:28:40 +00:00
|
|
|
end
|
|
|
|
)
|
|
|
|
|
2013-02-28 17:30:04 +00:00
|
|
|
gameevent("DISPLAYREST", function()
|
|
|
|
for i=0,10 do
|
|
|
|
for j=1,100 do
|
2013-03-21 10:20:14 +00:00
|
|
|
-- XXX: This is slower in the Polymodes than with classic!
|
|
|
|
-- con._gametext(2822, j, i, 12, 0, 0, 16, 0,0,gv.xdim,gv.ydim,8192)
|
2013-02-28 17:30:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2013-02-10 16:23:54 +00:00
|
|
|
local CS = sprite.CSTAT
|
|
|
|
|
2013-02-01 13:05:20 +00:00
|
|
|
gameevent("ANIMATESPRITES",
|
|
|
|
function(aci)
|
|
|
|
local tspr = atsprite[aci]
|
2013-02-10 16:23:54 +00:00
|
|
|
if (tspr:getspr().picnum==1680) then
|
2013-02-01 13:05:20 +00:00
|
|
|
local tspr2 = tspr:dup()
|
2013-02-10 16:23:54 +00:00
|
|
|
if (tspr2) then
|
|
|
|
tspr2.x = tspr2.x + 512*math.cos(gv.totalclock/60)
|
|
|
|
tspr2.y = tspr2.y + 512*math.sin(gv.totalclock/60)
|
|
|
|
tspr2:set_cstat_bits(CS.TRANSLUCENT_BOTH_BITS)
|
|
|
|
end
|
2013-02-01 13:05:20 +00:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2012-06-17 19:45:33 +00:00
|
|
|
printf("EVENT_INIT = %d", gv.EVENT_INIT) -- tests default defines
|
2012-05-29 20:01:58 +00:00
|
|
|
|
2012-07-20 21:57:28 +00:00
|
|
|
local bittest = require "bittest"
|
|
|
|
bittest.sieve()
|
|
|
|
|
2012-08-02 10:52:21 +00:00
|
|
|
require("test/test_geom")
|
2012-08-19 12:52:18 +00:00
|
|
|
require("test/test_rotspr")
|
2012-08-02 10:52:21 +00:00
|
|
|
|
2013-02-16 18:53:15 +00:00
|
|
|
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
|
|
|
|
|
2012-05-13 16:04:28 +00:00
|
|
|
print('---=== END TEST SCRIPT ===---')
|
2012-07-20 21:57:31 +00:00
|
|
|
|
2013-01-19 18:28:40 +00:00
|
|
|
--[[
|
2012-12-28 17:18:02 +00:00
|
|
|
function check_sector_idx()
|
|
|
|
error("bla")
|
|
|
|
end
|
|
|
|
spritesofsect(0)
|
2013-02-03 12:48:06 +00:00
|
|
|
--]]
|
2012-12-28 17:18:02 +00:00
|
|
|
|
2013-01-06 18:56:45 +00:00
|
|
|
--DBG_.oom()
|
|
|
|
|
2012-07-20 21:57:31 +00:00
|
|
|
-- This will complain about wrong usage of 'error'. In particular,
|
|
|
|
-- the nil must not propagate to C!
|
|
|
|
error(nil)
|