Lunatic: Makefile tweaks, protect sprite[].picnum.

git-svn-id: https://svn.eduke32.com/eduke32@3248 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2012-11-30 18:57:50 +00:00
parent 354a1a70ef
commit b850d04f8d
5 changed files with 77 additions and 42 deletions

View file

@ -158,12 +158,13 @@ ifneq (0,$(DISABLEINLINING))
endif
MISCGAMEDEPS=
MISCEDITORDEPS=
## Lunatic devel
ifneq (0,$(LUNATIC))
EDITOROBJS+= $(OBJ)/lunatic_m32.$o
GAMEOBJS+= $(OBJ)/lunatic_game.$o
EDITOROBJS+= $(OBJ)/lunatic_m32.$o $(OBJ)/luaJIT_BC_defs_common.$o
GAMEOBJS+= $(OBJ)/lunatic_game.$o $(OBJ)/luaJIT_BC_defs_common.$o
GAMEOBJS+= $(OBJ)/../lpeg.$o # TEMP
GAMEOBJS+= $(OBJ)/luaJIT_BC_con_lang.$o \
@ -188,7 +189,9 @@ ifneq (0,$(LUNATIC))
endif
ifeq ($(PLATFORM),WINDOWS)
MISCGAMEDEPS+= $(SRC)/lunatic/eduke32.def
PRINTLDFLAGS+= $(SRC)/lunatic/eduke32.def
GAMELDFLAGS+= $(SRC)/lunatic/eduke32.def
MISCEDITORDEPS+= $(SRC)/lunatic/mapster32.def
EDITORLDFLAGS+= $(SRC)/lunatic/mapster32.def
endif
ifeq ($(PLATFORM),LINUX)
GAMELDFLAGS+= -Wl,--dynamic-list=$(SRC)/lunatic/dynsymlist
@ -366,7 +369,7 @@ ifeq ($(PLATFORM),DARWIN)
cp -f "$(EDUKE32)" "EDuke32.app/Contents/MacOS/"
endif
$(MAPSTER32): $(EDITOROBJS) $(EOBJ)/$(ENGINELIB) $(EOBJ)/$(EDITORLIB) $(JAUDIOLIBDIR)/$(JAUDIOLIB)
$(MAPSTER32): $(EDITOROBJS) $(EOBJ)/$(ENGINELIB) $(EOBJ)/$(EDITORLIB) $(JAUDIOLIBDIR)/$(JAUDIOLIB) $(MISCEDITORDEPS)
$(LINK_STATUS)
if $(LINKER) -o $@ $^ $(OURLDFLAGS) $(EDITORLDFLAGS) $(OURLIBS) $(STATICSTDCPP) $(STDCPPLIB); then $(LINK_OK); else $(LINK_FAILED); fi
ifeq (1,$(RELEASE))
@ -465,12 +468,15 @@ $(SRC)/lunatic/dynsymlist_osx: $(SRC)/lunatic/dynsymlist
#$(SRC)/lunatic/aliases_list: $(SRC)/lunatic/dynsymlist_osx
# sed 's/_\([A-Za-z_][A-Za-z_0-9]*\)/_\1 \1/g' $< > $@
# TODO: _m32
# List of exported symbols, Windows
$(SRC)/lunatic/eduke32.def: $(SRC)/lunatic/dynsymlist
echo EXPORTS > $@
sed 's/[{};]//g' $< >> $@
$(SRC)/lunatic/mapster32.def: $(SRC)/lunatic/dynsymlist_m32
echo EXPORTS > $@
sed 's/[{};]//g' $< >> $@
####
$(OBJ)/%.$o: Apple/%.m

View file

@ -42,7 +42,7 @@ end
-- load them!
local defs_c = require("defs_common")
local strip_const = defs_c.strip_const
---=== EDuke32 game definitions ===---
@ -222,11 +222,6 @@ local DUKEPLAYER_STRUCT = [[
local randgen = require("randgen")
local geom = require("geom")
-- Converts a template struct definition to an internal, unrestricted one.
local function strip_const(structstr)
return string.gsub(structstr, "const ", "");
end
local ma_rand = randgen.new(true) -- initialize to "random" (time-based) seed
local ma_count = nil

View file

@ -6,6 +6,8 @@
local ffi = require("ffi")
local ffiC = ffi.C
local string = require("string")
local error = error
local pairs = pairs
local setmetatable = setmetatable
@ -20,19 +22,41 @@ module(...)
--== Core engine structs ==--
local SPRITE_STRUCT = [[
{
int32_t x, y, z;
uint16_t cstat;
const int16_t picnum;
int8_t shade;
uint8_t pal, clipdist, filler;
uint8_t xrepeat, yrepeat;
int8_t xoffset, yoffset;
const int16_t sectnum, statnum;
int16_t ang, owner, xvel, yvel, zvel;
int16_t lotag, hitag, extra;
}
]]
-- Converts a template struct definition to an internal, unrestricted one.
function strip_const(structstr)
return string.gsub(structstr, "const ", "");
end
-- TODO: provide getters for unsigned {hi,lo}tag?
ffi.cdef[[
ffi.cdef([[
#pragma pack(push,1)
typedef struct
{
const int16_t wallptr, wallnum;
int32_t ceilingz, floorz;
uint16_t ceilingstat, floorstat;
int16_t ceilingpicnum, ceilingheinum;
const int16_t ceilingpicnum;
int16_t ceilingheinum;
int8_t ceilingshade;
uint8_t ceilingpal, ceilingxpanning, ceilingypanning;
int16_t floorpicnum, floorheinum;
const int16_t floorpicnum;
int16_t floorheinum;
int8_t floorshade;
uint8_t floorpal, floorxpanning, floorypanning;
uint8_t visibility, filler;
@ -44,25 +68,19 @@ typedef struct
int32_t x, y;
const int16_t point2, nextwall, nextsector;
uint16_t cstat;
int16_t picnum, overpicnum;
const int16_t picnum, overpicnum;
int8_t shade;
uint8_t pal, xrepeat, yrepeat, xpanning, ypanning;
int16_t lotag, hitag, extra;
} walltype;
typedef struct
{
int32_t x, y, z;
uint16_t cstat;
int16_t picnum;
int8_t shade;
uint8_t pal, clipdist, filler;
uint8_t xrepeat, yrepeat;
int8_t xoffset, yoffset;
const int16_t sectnum, statnum;
int16_t ang, owner, xvel, yvel, zvel;
int16_t lotag, hitag, extra;
} spritetype;
]].. SPRITE_STRUCT ..[[
spritetype;
typedef struct
]].. strip_const(SPRITE_STRUCT) ..[[
spritetype_u_t;
typedef struct {
const uint32_t mdanimtims;
@ -90,7 +108,7 @@ typedef struct {
char r,g,b,f;
} palette_t;
#pragma pack(pop)
]]
]])
local vec3_ct = ffi.typeof("vec3_t")
local hitdata_ct = ffi.typeof("hitdata_t")
@ -198,6 +216,21 @@ int32_t ksqrt(uint32_t num);
]]
local spritetype_ptr_ct = ffi.typeof("spritetype_u_t *")
local spritetype_mt = {
__index = {
set_picnum = function(s, tilenum)
if (tilenum >= ffiC.MAXTILES+0ULL) then
error("attempt to set invalid picnum "..tilenum, 2)
end
ffi.cast(spritetype_ptr_ct, s).picnum = tilenum
end
},
}
ffi.metatype("spritetype", spritetype_mt)
---=== Restricted access to C variables from Lunatic ===---
-- set metatable and forbid setting it further
@ -209,18 +242,18 @@ end
---- indirect C array access ----
local sector_mt = {
__index = function(tab, key)
if (key >= 0 and key < ffiC.numsectors) then return ffiC.sector[key] end
error('out-of-bounds sector[] read access', 2)
end,
if (key >= 0 and key < ffiC.numsectors) then return ffiC.sector[key] end
error('out-of-bounds sector[] read access', 2)
end,
__newindex = function(tab, key, val) error('cannot write directly to sector[] struct', 2) end,
}
local wall_mt = {
__index = function(tab, key)
if (key >= 0 and key < ffiC.numwalls) then return ffiC.wall[key] end
error('out-of-bounds wall[] read access', 2)
end,
if (key >= 0 and key < ffiC.numwalls) then return ffiC.wall[key] end
error('out-of-bounds wall[] read access', 2)
end,
__newindex = function(tab, key, val) error('cannot write directly to wall[] struct', 2) end,
}
@ -230,14 +263,14 @@ function creategtab(ctab, maxidx, name)
local tab = {}
local tmpmt = {
__index = function(tab, key)
if (key>=0 and key < maxidx) then
return ctab[key]
end
error('out-of-bounds '..name..' read access', 2)
end,
if (key>=0 and key < maxidx) then
return ctab[key]
end
error('out-of-bounds '..name..' read access', 2)
end,
__newindex = function(tab, key, val)
error('cannot write directly to '..name, 2)
end,
error('cannot write directly to '..name, 2)
end,
}
return setmtonce(tab, tmpmt)

View file

@ -761,7 +761,7 @@ local Ci = {
/ ACS":set_move(%1)",
cactor = cmd(D)
/ SPS".picnum=%1", -- TODO: wrap, e.g. sprite[]:set_picnum(tilenum), bound check there
/ SPS":set_picnum(%1)",
count = cmd(D)
/ ACS":set_count(%1)",
cstator = cmd(D),

View file

@ -182,6 +182,7 @@ checkfail("do local bt=require'bittest'; bt.QWE=1; end", "modifying module table
-- the cdata returned by player[] can't be made into a pointer!
checkfail("do local pl=player[0]; i=pl[1]; end")
checkfail("do local ud=gv.ud.camera; end", "dummy variable: read access forbidden") -- test for proper decl()
checkfail("sprite[0]:set_picnum(-10)", "attempt to set invalid picnum")
printf('ceilingbunch of sector 0: %d', getbunch(0, gv.CEILING))