mirror of
https://github.com/ZDoom/Raze.git
synced 2024-11-16 09:21:36 +00:00
Lunatic: more convenient weapon data access.
git-svn-id: https://svn.eduke32.com/eduke32@3407 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
fbaa00665d
commit
7acd1ad743
5 changed files with 34 additions and 39 deletions
|
@ -10413,7 +10413,7 @@ int32_t app_main(int32_t argc, const char **argv)
|
||||||
{
|
{
|
||||||
if (!g_player[i].ps) g_player[i].ps = (DukePlayer_t *)Bcalloc(1, sizeof(DukePlayer_t));
|
if (!g_player[i].ps) g_player[i].ps = (DukePlayer_t *)Bcalloc(1, sizeof(DukePlayer_t));
|
||||||
#ifdef LUNATIC
|
#ifdef LUNATIC
|
||||||
g_player[i].ps->idx = i;
|
g_player[i].ps->wa.idx = i;
|
||||||
#endif
|
#endif
|
||||||
if (!g_player[i].sync) g_player[i].sync = (input_t *)Bcalloc(1, sizeof(input_t));
|
if (!g_player[i].sync) g_player[i].sync = (input_t *)Bcalloc(1, sizeof(input_t));
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,7 +231,10 @@ local DUKEPLAYER_STRUCT = [[
|
||||||
|
|
||||||
const char name[32];
|
const char name[32];
|
||||||
|
|
||||||
const int8_t idx;
|
// NOTE: In C, the struct type has no name. We only have it here to define
|
||||||
|
// a metatype later.
|
||||||
|
const weaponaccess_t weapon;
|
||||||
|
const int8_t _padding;
|
||||||
}
|
}
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
@ -282,6 +285,8 @@ typedef struct
|
||||||
]].. strip_const(ACTOR_STRUCT).. [[
|
]].. strip_const(ACTOR_STRUCT).. [[
|
||||||
actor_u_t; // The _u_t versions are unrestricted variants for internal use.
|
actor_u_t; // The _u_t versions are unrestricted variants for internal use.
|
||||||
|
|
||||||
|
typedef struct { int32_t _p; } weaponaccess_t;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
]].. mangle_arrays(DUKEPLAYER_STRUCT) ..[[
|
]].. mangle_arrays(DUKEPLAYER_STRUCT) ..[[
|
||||||
DukePlayer_t;
|
DukePlayer_t;
|
||||||
|
@ -536,7 +541,9 @@ for i=0,7 do
|
||||||
local what = ffi.string(ffiC.g_sizes_of_what[i])
|
local what = ffi.string(ffiC.g_sizes_of_what[i])
|
||||||
local fsz = ffi.sizeof(what)
|
local fsz = ffi.sizeof(what)
|
||||||
local csz = ffiC.g_sizes_of[i]
|
local csz = ffiC.g_sizes_of[i]
|
||||||
-- print(i..": "..what..": C sizeof = "..tostring(csz)..", FFI sizeof = "..tostring(fsz))
|
if (ffiC._DEBUG_LUNATIC ~= 0) then
|
||||||
|
print(i..": "..what..": C sizeof = "..tostring(csz)..", FFI sizeof = "..tostring(fsz))
|
||||||
|
end
|
||||||
if (fsz ~= csz) then
|
if (fsz ~= csz) then
|
||||||
good = false;
|
good = false;
|
||||||
end
|
end
|
||||||
|
@ -758,20 +765,9 @@ local function check_tile_idx(tilenum)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local weapondata_accessor = {}
|
--- PER-PLAYER WEAPON SETTINGS
|
||||||
local function get_weapondata_accessor(pli, weap)
|
local weapondata_mt = {
|
||||||
assert(pli < ffiC.MAXPLAYERS+0ULL)
|
__newindex = function(wd, member, val)
|
||||||
|
|
||||||
local wdaidx = pli*1024 + weap
|
|
||||||
|
|
||||||
if (weapondata_accessor[wdaidx] ~= nil) then
|
|
||||||
return weapondata_accessor[wdaidx]
|
|
||||||
end
|
|
||||||
|
|
||||||
local weapondata_mt = {
|
|
||||||
__index = ffiC.g_playerWeapon[pli][weap],
|
|
||||||
|
|
||||||
__newindex = function(_, member, val)
|
|
||||||
if (string.match(member, "sound")) then
|
if (string.match(member, "sound")) then
|
||||||
-- TODO: set to 0 if oob? (e.g. CrackDown)
|
-- TODO: set to 0 if oob? (e.g. CrackDown)
|
||||||
check_sound_idx(val)
|
check_sound_idx(val)
|
||||||
|
@ -782,17 +778,23 @@ local function get_weapondata_accessor(pli, weap)
|
||||||
check_tile_idx(val)
|
check_tile_idx(val)
|
||||||
end
|
end
|
||||||
|
|
||||||
ffiC.g_playerWeapon[pli][weap][member] = val
|
wd[member] = val
|
||||||
end,
|
end,
|
||||||
|
}
|
||||||
|
ffi.metatype("weapondata_t", weapondata_mt)
|
||||||
|
|
||||||
__metatable = true,
|
local weaponaccess_mt = {
|
||||||
}
|
-- Make syntax like "player[0].weapon.KNEE.shoots" possible
|
||||||
|
__index = function(wa, key)
|
||||||
|
if (type(key)=="number") then
|
||||||
|
check_weapon_idx(key)
|
||||||
|
return ffiC.g_playerWeapon[wa._p][key]
|
||||||
|
end
|
||||||
|
|
||||||
local tab = setmetatable({}, weapondata_mt)
|
return ffiC.g_playerWeapon[wa._p][ffiC[key.."_WEAPON"]]
|
||||||
weapondata_accessor[wdaidx] = tab
|
end,
|
||||||
|
}
|
||||||
return tab
|
ffi.metatype("weaponaccess_t", weaponaccess_mt)
|
||||||
end
|
|
||||||
|
|
||||||
local player_mt = {
|
local player_mt = {
|
||||||
__index = {
|
__index = {
|
||||||
|
@ -839,13 +841,6 @@ local player_mt = {
|
||||||
ffi.cast(player_ptr_ct, p).customexitsound = soundnum
|
ffi.cast(player_ptr_ct, p).customexitsound = soundnum
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-- Access to weapon data (g_playerWeapon)
|
|
||||||
-- TODO: Make syntax e.g. "player[0].weapon.KNEE.shoots" possible
|
|
||||||
weapon = function(p, weap)
|
|
||||||
check_weapon_idx(weap)
|
|
||||||
return get_weapondata_accessor(p.idx, weap)
|
|
||||||
end,
|
|
||||||
|
|
||||||
-- CON-like addammo/addweapon, but without the non-local control flow
|
-- CON-like addammo/addweapon, but without the non-local control flow
|
||||||
-- (returns true if weapon's ammo was at the max. instead).
|
-- (returns true if weapon's ammo was at the max. instead).
|
||||||
addammo = con._addammo,
|
addammo = con._addammo,
|
||||||
|
|
|
@ -176,7 +176,7 @@ local function new_initial_gvartab()
|
||||||
local member = wmembers[i]:gsub(".* ","") -- strip e.g. "int32_t "
|
local member = wmembers[i]:gsub(".* ","") -- strip e.g. "int32_t "
|
||||||
local name = format("WEAPON%d_%s", w, member:upper())
|
local name = format("WEAPON%d_%s", w, member:upper())
|
||||||
|
|
||||||
local code = format(PLS":weapon(%d).%s", w, member)
|
local code = format(PLS".weapon[%d].%s", w, member)
|
||||||
|
|
||||||
gamevar[name] = { name=code, flags=GVFLAG.PERPLAYER+GVFLAG.SYSTEM }
|
gamevar[name] = { name=code, flags=GVFLAG.PERPLAYER+GVFLAG.SYSTEM }
|
||||||
end
|
end
|
||||||
|
|
|
@ -205,7 +205,8 @@ gameevent("JUMP",
|
||||||
function(actori, playeri, dist)
|
function(actori, playeri, dist)
|
||||||
print("I'm first!")
|
print("I'm first!")
|
||||||
-- DBG_.oom()
|
-- DBG_.oom()
|
||||||
player[playeri]:weapon(gv.PISTOL_WEAPON).shoots = 2605 -- RPG
|
player[playeri].weapon.PISTOL.shoots = 2605 -- RPG
|
||||||
|
player[playeri].weapon[gv.PISTOL_WEAPON].firesound = 351 -- thunder
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -221,11 +221,10 @@ typedef struct {
|
||||||
|
|
||||||
#ifdef LUNATIC
|
#ifdef LUNATIC
|
||||||
// The player index. Always valid since we have no loose DukePlayer_t's
|
// The player index. Always valid since we have no loose DukePlayer_t's
|
||||||
// anywhere (like with spritetype_t): g_player[i].ps->idx == i.
|
// anywhere (like with spritetype_t): g_player[i].ps->wa.idx == i.
|
||||||
int8_t idx;
|
struct { int32_t idx; } wa;
|
||||||
#else
|
|
||||||
int8_t padding_;
|
|
||||||
#endif
|
#endif
|
||||||
|
int8_t padding_;
|
||||||
} DukePlayer_t;
|
} DukePlayer_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
Loading…
Reference in a new issue