diff --git a/polymer/eduke32/source/lunatic/control.lua b/polymer/eduke32/source/lunatic/control.lua index 44f092882..1c560b8c3 100644 --- a/polymer/eduke32/source/lunatic/control.lua +++ b/polymer/eduke32/source/lunatic/control.lua @@ -1573,6 +1573,8 @@ function _sound(aci, sndidx) CF.A_PlaySound(sndidx, aci) end +-- NOTE: This command is really badly named in CON. It issues a sound that +-- emanates from the current player instead of being 'system-global'. function _globalsound(pli, sndidx) -- TODO: conditional on coop, fake multimode if (pli==ffiC.screenpeek) then diff --git a/polymer/eduke32/source/lunatic/defs.ilua b/polymer/eduke32/source/lunatic/defs.ilua index 5a84bfcb4..714789829 100644 --- a/polymer/eduke32/source/lunatic/defs.ilua +++ b/polymer/eduke32/source/lunatic/defs.ilua @@ -5,6 +5,9 @@ local require = require local ffi = require("ffi") local ffiC = ffi.C +-- Lua C API functions. +local CF = CF + local bit = bit local string = string local table = table @@ -576,6 +579,7 @@ const char *s_buildRev; const char *g_sizes_of_what[]; int32_t g_sizes_of[]; int32_t g_elCallDepth; +int32_t block_deletesprite; const char **g_argv; const char **g_elModules; char g_modDir[]; @@ -775,6 +779,26 @@ do actor_static_members.FLAGS = defs_c.conststruct(our_SFLAG) end +-- Delete sprite with index . +-- TODO: make this (also?) sprite.delete() even though it's game-side? +function actor_static_members.delete(i) + check_sprite_idx(i) + + if (ffiC.sprite[i].statnum == ffiC.MAXSTATUS) then + error("Attempt to delete a sprite already not in the game world", 2) + end + + if (ffiC.block_deletesprite ~= 0) then + error("Attempt to delete sprite in EVENT_EGS", 2) + end + + if (ffiC.g_player_ps[0].i == i) then + error("Attempt to delete player 0's APLAYER sprite", 2) + end + + CF.A_DeleteSprite(i) +end + local tile_static_members = {} do tile_static_members.sizx = defs_c.creategtab(ffiC.tilesizx, ffiC.MAXTILES, "tilesizx[]") diff --git a/polymer/eduke32/source/lunatic/dynsymlist b/polymer/eduke32/source/lunatic/dynsymlist index a86de7331..46d246e7b 100644 --- a/polymer/eduke32/source/lunatic/dynsymlist +++ b/polymer/eduke32/source/lunatic/dynsymlist @@ -101,6 +101,7 @@ s_buildRev; g_sizes_of_what; g_sizes_of; g_elCallDepth; +block_deletesprite; g_RETURN; g_argv; g_elModules; diff --git a/polymer/eduke32/source/lunatic/geom.lua b/polymer/eduke32/source/lunatic/geom.lua index 4692763a0..caae5a508 100644 --- a/polymer/eduke32/source/lunatic/geom.lua +++ b/polymer/eduke32/source/lunatic/geom.lua @@ -63,7 +63,7 @@ local arshift = require("bit").arshift -- The vec3 metatable is shared between the integer- and double-based 3-vector -- types. However, some operations are slightly different. local vec3_mt = { - -- Arithmetic operations. Note that they always return the a dvec3. + -- Arithmetic operations. Note that they always return a dvec3. __add = function(a, b) return dvec3_t(a.x+b.x, a.y+b.y, a.z+b.z) end, __sub = function(a, b) return dvec3_t(a.x-b.x, a.y-b.y, a.z-b.z) end, __unm = function(a) return dvec3_t(-a.x, -a.y, -a.z) end, @@ -92,6 +92,7 @@ local vec3_mt = { end, -- The # operator returns the Euclidean length. + -- TODO: REMOVE. __len = function(a) return math.sqrt(a.x*a.x + a.y*a.y + a.z*a.z) end, -- INTERNAL: Calling a vector calls the constructor of its type. @@ -105,9 +106,17 @@ local vec3_mt = { end, __index = { + -- Euclidean 3D length. + len = function(a) return math.sqrt(a.x*a.x + a.y*a.y + a.z*a.z) end, + -- Euclidean 3D squared length. lensq = function(a) return a.x*a.x + a.y*a.y + a.z*a.z end, - -- Manhattan-distance length: + -- Euclidean 2D length. + len2 = function(a) return math.sqrt(a.x*a.x + a.y*a.y) end, + -- Euclidean 2D squared length. + len2sq = function(a) return a.x*a.x + a.y*a.y end, + + -- Manhattan-distance 3D length: mhlen = function(a) return math.abs(a.x)+math.abs(a.y)+math.abs(a.z) end, toivec3 = function(v) return ivec3_t(v.x, v.y, v.z) end, diff --git a/polymer/eduke32/source/lunatic/lunacon.lua b/polymer/eduke32/source/lunatic/lunacon.lua index 4482d650b..9ceb59671 100644 --- a/polymer/eduke32/source/lunatic/lunacon.lua +++ b/polymer/eduke32/source/lunatic/lunacon.lua @@ -176,7 +176,7 @@ local function new_initial_codetab() -- Cache globals into locals. "local sector, sprite, wall, spriteext, atsprite = sector, sprite, wall, spriteext, atsprite", - "local actor, player, projectile = actor, player, projectile", + "local actor, player, projectile, g_tile = actor, player, projectile, g_tile", "local gameactor, gameevent, _gv = gameactor, gameevent, gv", "local updatesector, updatesectorz, cansee = updatesector, updatesectorz, cansee", "local print, printf = print, printf", diff --git a/polymer/eduke32/source/lunatic/lunatic_game.c b/polymer/eduke32/source/lunatic/lunatic_game.c index a38f15bf2..13e0a8c5a 100644 --- a/polymer/eduke32/source/lunatic/lunatic_game.c +++ b/polymer/eduke32/source/lunatic/lunatic_game.c @@ -271,6 +271,7 @@ extern int32_t A_InsertSprite(int32_t whatsect,int32_t s_x,int32_t s_y,int32_t s int32_t s_xr,int32_t s_yr,int32_t s_a,int32_t s_ve,int32_t s_zv,int32_t s_ow,int32_t s_ss); extern void A_AddToDeleteQueue(int32_t i); extern int32_t A_PlaySound(uint32_t num, int32_t i); +extern void A_DeleteSprite(int32_t s); #define LARG(index) lua_tointeger(L, index) @@ -315,6 +316,7 @@ DEFINE_RET_CFUNC(A_InsertSprite, LARG(1), LARG(2), LARG(3), LARG(4), LARG(5), LA LARG(7), LARG(8), LARG(9), LARG(10), LARG(11), LARG(12), LARG(13)) DEFINE_VOID_CFUNC(A_AddToDeleteQueue, ONE_ARG) DEFINE_RET_CFUNC(A_PlaySound, TWO_ARGS) +DEFINE_VOID_CFUNC(A_DeleteSprite, ONE_ARG) #define CFUNC_REG(Name) { #Name, Name##_CF } @@ -333,6 +335,7 @@ struct { const char *name; lua_CFunction func; } cfuncs[] = CFUNC_REG(A_Spawn), CFUNC_REG(A_AddToDeleteQueue), CFUNC_REG(A_PlaySound), + CFUNC_REG(A_DeleteSprite), }; // Creates a global table "CF" containing the functions from cfuncs[].