Lunatic: various minor tweaks and fixes.

- Pass original module name (dot=dirsep) to module via our require()
- geom.lua: fix some operations using the vector type constructor
- geom.lua: provide constructor for ivec3, useable like vec3

git-svn-id: https://svn.eduke32.com/eduke32@3894 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-06-22 11:31:09 +00:00
parent 5db04f585e
commit 1febaae767
6 changed files with 42 additions and 21 deletions

View file

@ -1599,7 +1599,9 @@ local function our_require(modname, ...)
error("Module name must not contain directory separators", ERRLEV-1)
end
-- Instead, dots are translated to directory separators. For EDuke32's
-- virtual file system, this is always a forward slash.
-- virtual file system, this is always a forward slash. Keep the original
-- module name for passing to the module function.
local omodname = modname
modname = modname:gsub("%.", "/")
local omod = package_loaded[modname]
@ -1633,7 +1635,7 @@ local function our_require(modname, ...)
-- Run the module code in a separate Lua thread!
local modthread = coroutine.create(modfunc)
local ok, retval = coroutine.resume(modthread, modname, ...)
local ok, retval = coroutine.resume(modthread, omodname, ...)
if (not ok) then
errorf(ERRLEV-1, "Failed running \"%s\": %s", modname, retval)

View file

@ -88,7 +88,7 @@ local vec3_mt = {
-- '^' is the "translate upwards" operator, returns same-typed vector.
__pow = function(v, zofs)
return v(v.x, v.y, v.z-zofs)
return v:_ctor(v.x, v.y, v.z-zofs)
end,
-- XXX: Rewrite using _serialize internal API instead.
@ -112,20 +112,21 @@ local vec3_mt = {
toivec3 = function(v) return ivec3_t(v.x, v.y, v.z) end,
-- Get the type constructor for this vector.
_getctor = function(v)
return v:_isi() and ivec3_t or dvec3_t
end,
-- BUILD-coordinate (z scaled by 16) <-> uniform conversions.
touniform = function(v)
return v:_isi()
and v:_getctor(v.x, v.y, arshift(v.z, 4))
or v:_getctor(v.x, v.y, v.z/4)
and v:_ctor(v.x, v.y, arshift(v.z, 4))
or v:_ctor(v.x, v.y, v.z/16)
end,
tobuild = function(v) return v:_getctor(v.x, v.y, 16*v.z) end,
tobuild = function(v) return v:_ctor(v.x, v.y, 16*v.z) end,
-- PRIVATE methods --
-- Get the type constructor for this vector.
_ctor = function(v, ...)
return v:_isi() and ivec3_t(...) or dvec3_t(...)
end,
-- Is <v> integer vec3? INTERNAL.
_isi = function(v)
return ffi.istype(ivec3_t, v)
@ -135,6 +136,7 @@ local vec3_mt = {
ffi.metatype(dvec2_t, vec2_mt)
ffi.metatype(dvec3_t, vec3_mt)
ffi.metatype(ivec3_t, vec3_mt)
-- VEC2 user data constructor.
-- * vec2([x [, y]]), assuming that x and y are numbers. Vacant positions are
@ -160,8 +162,15 @@ function vec3(...)
end
end
-- TODO: make a constructor like VEC3?
ivec3 = ffi.metatype(ivec3_t, vec3_mt)
-- IVEC3 user data constructor.
function ivec3(...)
local x, y, z = ...
if (type(x)=="number" or x==nil) then
return ivec3_t(...)
else
return ivec3_t(x.x, x.y, x.z)
end
end
-- Two-element vector cross product.

View file

@ -2127,7 +2127,7 @@ local Cinner = {
lockplayer = cmd(R)
/ PLS".transporter_hold=%1",
quake = cmd(R)
/ "_gv.doQuake(%1,81)", -- EARTHQUAKE
/ "_gv.doQuake(%1,81)", -- TODO: dynsound (EARTHQUAKE)
jump = cmd(R)
/ handle.NYI, -- will never be
cmenu = cmd(R)

View file

@ -356,7 +356,9 @@ gameevent
mpos = mpos + wall[i]
end
mpos = mpos/gv.numwalls
printf("Map center point: (%d,%d)", mpos.x, mpos.y)
local impos = geom.ivec3(mpos)^20 -- test ivec3 with dvec3 arg, test '^' op
assert(impos.z == -20)
printf("Map center point: (%d,%f)", mpos.x, impos.y)
end
}
@ -597,7 +599,7 @@ printf("EVENT_INIT = %d", gv.EVENT_INIT) -- tests default defines
local bittest = require "test.test_bitar"
bittest.sieve()
require("test.test_geom")
require("test.test_geom", 123123)
require("test.test_rotspr")
do

View file

@ -83,6 +83,6 @@ gameevent
"DISPLAYREST",
function()
con.minitext(160, 10, string.format("jumped %d times", ournumjumps))
con.minitext(240, 10, string.format("jumped %d times", ournumjumps))
end
}

View file

@ -12,12 +12,17 @@ local V,W = {}, {}
local randvec
local args = { ... }
local ourname = args[1]
if (os.exit) then
local math = require("math")
randvec = function()
return geom.vec2(math.random(), math.random())
end
print("Running stand-alone. ourname: "..tostring(ourname))
else
local randgen = require("randgen")
local s = randgen.new(true)
@ -27,6 +32,9 @@ else
randvec = function()
return geom.vec2(s:getdbl(), s:getdbl())
end
-- Test optional arguments from our_require().
printf("Running %s stand-alone with opt arg %s", ourname, tostring(args[2]))
end
local t1 = os.clock()