LunaCON: fix tilesizx[] and tilesizy[] system gamearrays.

git-svn-id: https://svn.eduke32.com/eduke32@4731 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2014-11-07 22:07:07 +00:00
parent 1f9c37517a
commit 76d60511bc
4 changed files with 25 additions and 8 deletions

View file

@ -951,8 +951,8 @@ end
local tile_static_members = defs_c.static_members_tab() local tile_static_members = defs_c.static_members_tab()
do do
tile_static_members.sizx = defs_c.creategtab(ffiC.tilesizx, ffiC.MAXTILES, "tilesizx[]") tile_static_members.sizx = defs_c.creategtab_membidx(ffiC.tilesiz, "x", ffiC.MAXTILES, "tilesizx[]")
tile_static_members.sizy = defs_c.creategtab(ffiC.tilesizy, ffiC.MAXTILES, "tilesizy[]") tile_static_members.sizy = defs_c.creategtab_membidx(ffiC.tilesiz, "y", ffiC.MAXTILES, "tilesizy[]")
end end
-- XXX: error message will say "g_player_ps" -- XXX: error message will say "g_player_ps"

View file

@ -444,7 +444,7 @@ int32_t guniqhudid;
const int16_t headspritesect[MAXSECTORS+1], headspritestat[MAXSTATUS+1]; const int16_t headspritesect[MAXSECTORS+1], headspritestat[MAXSTATUS+1];
const int16_t prevspritesect[MAXSPRITES], prevspritestat[MAXSPRITES]; const int16_t prevspritesect[MAXSPRITES], prevspritestat[MAXSPRITES];
const int16_t nextspritesect[MAXSPRITES], nextspritestat[MAXSPRITES]; const int16_t nextspritesect[MAXSPRITES], nextspritestat[MAXSPRITES];
const int16_t tilesizx[MAXTILES], tilesizy[MAXTILES]; const vec2_t tilesiz[MAXTILES];
uint8_t show2dsector[(MAXSECTORS+7)>>3]; uint8_t show2dsector[(MAXSECTORS+7)>>3];
@ -849,7 +849,7 @@ end
---- indirect C array access ---- ---- indirect C array access ----
-- create a safe indirection for an ffi.C array -- Create a safe indirection for an ffi.C array.
function creategtab(ctab, maxidx, name) function creategtab(ctab, maxidx, name)
local tab = {} local tab = {}
local tmpmt = { local tmpmt = {
@ -867,6 +867,25 @@ function creategtab(ctab, maxidx, name)
return setmtonce(tab, tmpmt) return setmtonce(tab, tmpmt)
end end
-- Create a a safe indirection for an ffi.C struct array, accessing a given
-- member.
function creategtab_membidx(ctab, membname, maxidx, name)
local tab = {}
local tmpmt = {
__index = function(tab, key)
if (key>=0 and key < maxidx) then
return ctab[key][membname]
end
error('out-of-bounds '..name..' read access', 2)
end,
__newindex = function()
error('cannot write directly to '..name, 2)
end,
}
return setmtonce(tab, tmpmt)
end
-- Construct const struct from table -- Construct const struct from table
function conststruct(tab) function conststruct(tab)
local strtab = { "struct {" } local strtab = { "struct {" }

View file

@ -46,8 +46,7 @@ prevspritesect;
prevspritestat; prevspritestat;
nextspritesect; nextspritesect;
nextspritestat; nextspritestat;
tilesizx; tilesiz;
tilesizy;
show2dsector; show2dsector;

View file

@ -46,8 +46,7 @@ prevspritesect;
prevspritestat; prevspritestat;
nextspritesect; nextspritesect;
nextspritestat; nextspritestat;
tilesizx; tilesiz;
tilesizy;
show2dsector; show2dsector;