Lunatic: fix current incarnation of gamevar saving/restoration.

git-svn-id: https://svn.eduke32.com/eduke32@3857 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-06-07 10:18:17 +00:00
parent a0f00e28c3
commit 34138cdc96
5 changed files with 84 additions and 32 deletions

View file

@ -1413,7 +1413,7 @@ local function our_require(modname, ...)
local gvnames = {}
for name in pairs(getfenv(2)) do
gvnames[#gvnames] = name
gvnames[#gvnames+1] = name
if (ffiC._DEBUG_LUNATIC ~= 0) then
printf("MODULE %s GAMEVAR %s", thismodname, name)
end

View file

@ -4,6 +4,7 @@
local string = require("string")
local table = require("table")
local assert = assert
local getmetatable = getmetatable
local pairs = pairs
local setmetatable = setmetatable
@ -16,6 +17,9 @@ module(...)
---=== Serialization, based on the idea from PiL ===---
assert(tostring(0/0)=="nan")
assert(tostring(1/0)=="inf")
-- Serialize a 'primitive' Lua value.
local function basicSerialize(o)
-- Compare with sb_get_initial_strbuf() below.

View file

@ -39,25 +39,32 @@ ourvar = { ourvar2; 1, 2, 3, "qwe"; [true]=0, [false]=1 }
ourvar[#ourvar+1] = ourvar;
--]]
print('tweaking sector pals')
print('numsectors: ' .. gv.numsectors .. ' of ' .. gv.MAXSECTORS)
---[[
local SF = sector.STAT
for i = 0, gv.numsectors/2 do
local sec = sector[i]
sec.floorpal = 1;
sector[i].floor.shade = sec.floor.shade + 4
sector[i].ceilingpal = 2;
local ceil = sec.ceiling
ceil.shade = sector[i].ceiling.shade + 8
ceil.statx:flip(SF.SMOOSH)
sec.floorstatx:flip(SF.SWAPXY)
end
local vol, lev = gv.currentEpisode()+1, gv.currentLevel()+1
printf('volume=%d, level=%d', vol, lev)
---[[
if (vol ~= 4) then
-- Tweak some sector pals.
-- NOTE: you're not really supposed to modify game state from Lua file
-- scope! This is for testing only! E.g. it will fail if a savegame is
-- loaded from the menu when no other level is loaded.
print('tweaking sector pals')
print('numsectors: ' .. gv.numsectors .. ' of ' .. gv.MAXSECTORS)
local SF = sector.STAT
for i = 0, gv.numsectors/2 do
local sec = sector[i]
sec.floorpal = 1;
sector[i].floor.shade = sec.floor.shade + 4
sector[i].ceilingpal = 2;
local ceil = sec.ceiling
ceil.shade = sector[i].ceiling.shade + 8
ceil.statx:flip(SF.SMOOSH)
sec.floorstatx:flip(SF.SWAPXY)
end
end
if (vol==1 and lev==1) then -- E1L1
print('tweaking some sprites 2')
local i = 562
@ -215,7 +222,7 @@ gameevent("PROCESSINPUT",
gameevent("JUMP", actor.FLAGS.chain_beg,
function(actori, playeri, dist)
local ps = player[playeri]
print("I'm first!")
print("\n--- I'm first!")
-- DBG_.oom()
ps.weapon.PISTOL.shoots = 2605 -- RPG
ps.weapon[gv.PISTOL_WEAPON].firesound = 351 -- thunder

View file

@ -1,24 +1,53 @@
local require = require
local con = require "con"
local gv = gv
local sprite = sprite
local actor = actor
local player = player
local assert = assert
local printf = printf
local gameevent = gameevent
local spritesofstat = spritesofstat
local Inf = 0/1
-- Insert MUSICANDSFX? (Delete it otherwise.)
-- XXX: should be a per-player gamevar, but this is testing code.
local insp = false
local hitag, lotag = 0, 0
gameevent("JUMP",
module(...)
-- Insert MUSICANDSFX? (Delete it otherwise.)
insp = false
-- Hitag and lotag of last deleted MUSICANDSFX sprite.
tag = {}
tag.hi, tag.lo = 0, 0
-- Preliminary dummy of a local gamevar.
local ournumjumps = 0
require "end_gamevars"
-- We may cache globals defined in the gamevar section afterwards, but not
-- refer to locals defined prior to the gamevar section in it.
local tag = tag
gameevent("JUMP", actor.FLAGS.chain_beg,
function(aci, pli)
local ps = player[pli]
ournumjumps = ournumjumps+1
if (insp) then
-- Insert MUSICANDSFX sprite with same lo-/hitag as last deleted one.
printf("delmusicsfx: jump count=%d, inserting", ournumjumps)
local spr = sprite[con.spawn(aci, 5)]
spr.lotag, spr.hitag = lotag, hitag
spr.lotag, spr.hitag = tag.lo, tag.hi
else
-- Delete nearest MUSICANDSFX sprite.
@ -27,7 +56,8 @@ function(aci, pli)
for i in spritesofstat(gv.STAT_FX) do
local dst = (sprite[i]-ps.pos):len2()
if (nearesti == -1 or dst < nearestdst) then
if (nearesti == -1 or (dst < nearestdst and dst < sprite[i].hitag)) then
printf("MSFX %d dist %d", i, dst)
nearesti = i
nearestdst = dst
end
@ -35,9 +65,12 @@ function(aci, pli)
if (nearesti >= 0) then
local spr = sprite[nearesti]
lotag, hitag = spr.lotag, spr.hitag
tag.lo, tag.hi = spr.lotag, spr.hitag
actor.delete(nearesti)
end
assert(nearesti < 0 or sprite[nearesti].picnum==5)
printf("delmusicsfx: jump count=%d, deleting sprite %d", ournumjumps, nearesti)
end
insp = not insp

View file

@ -848,6 +848,15 @@ static void sv_calcbitptrsize();
static void sv_prescriptsave_once();
static void sv_prescriptload_once();
static void sv_postscript_once();
#else
// Recreate Lua state.
// XXX: It may matter a great deal when this is run from if the Lua code refers
// to C-side data at file scope. Such usage is strongly discouraged though.
static void sv_create_lua_state(void)
{
El_CreateGameState();
G_PostCreateGameState();
}
#endif
static void sv_preactordatasave();
static void sv_postactordata();
@ -867,7 +876,9 @@ static void sv_restload();
((sizeof(g_player[0].user_name)+sizeof(g_player[0].pcolor)+sizeof(g_player[0].pteam) \
+sizeof(g_player[0].frags)+sizeof(DukePlayer_t))*MAXPLAYERS)
#if !defined LUNATIC
static uint32_t savegame_bitptrsize;
#endif
static uint8_t savegame_quotedef[MAXQUOTES>>3];
static char(*savegame_quotes)[MAXQUOTELEN];
static char(*savegame_quoteredefs)[MAXQUOTELEN];
@ -983,7 +994,9 @@ static const dataspec_t svgm_script[] =
{ DS_SAVEFN, (void *)&sv_preactordatasave, 0, 1 },
{ 0, &actor[0], sizeof(actor_t), MAXSPRITES },
{ DS_SAVEFN|DS_LOADFN, (void *)&sv_postactordata, 0, 1 },
#if defined LUNATIC
{ DS_LOADFN|DS_NOCHK, (void *)&sv_create_lua_state, 0, 1 },
#endif
{ DS_END, 0, 0, 0 }
};
@ -1334,11 +1347,6 @@ int32_t sv_loadsnapshot(int32_t fil, int32_t spot, savehead_t *h)
savegame_comprthres = h->comprthres;
#ifdef LUNATIC
El_CreateGameState();
G_PostCreateGameState();
#endif
if (spot >= 0)
{
// savegame