From c5c1aa2331e7bbbdbae88be1323a43fc7a73ef48 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Mon, 25 Feb 2013 15:31:19 +0000 Subject: [PATCH] Lunatic translator: handle RETURN across events. git-svn-id: https://svn.eduke32.com/eduke32@3526 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/gameexec.c | 2 +- polymer/eduke32/source/lunatic/defs.ilua | 10 ++++++++++ polymer/eduke32/source/lunatic/lunacon.lua | 10 +++++++--- polymer/eduke32/source/lunatic/lunatic_game.c | 7 ++++++- polymer/eduke32/source/lunatic/lunatic_game.h | 2 +- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/polymer/eduke32/source/gameexec.c b/polymer/eduke32/source/gameexec.c index 88232e800..eb97cb725 100644 --- a/polymer/eduke32/source/gameexec.c +++ b/polymer/eduke32/source/gameexec.c @@ -124,7 +124,7 @@ int32_t VM_OnEvent(int32_t iEventID, int32_t iActor, int32_t iPlayer, int32_t lD // TODO: handling of RETURN gamevar / iReturn / this function's return value if (L_IsInitialized(&g_ElState) && El_HaveEvent(iEventID)) - if (El_CallEvent(&g_ElState, iEventID, iActor, iPlayer, lDist)==1) + if (El_CallEvent(&g_ElState, iEventID, iActor, iPlayer, lDist, &iReturn)==1) VM_KillIt(iActor, iPlayer); g_eventTotalMs[iEventID] += gethitickms()-t; diff --git a/polymer/eduke32/source/lunatic/defs.ilua b/polymer/eduke32/source/lunatic/defs.ilua index 52097e977..dc6e213e1 100644 --- a/polymer/eduke32/source/lunatic/defs.ilua +++ b/polymer/eduke32/source/lunatic/defs.ilua @@ -157,6 +157,7 @@ local bcarray = require("bcarray") local bcheck = require("bcheck") local check_sector_idx, check_tile_idx = bcheck.sector_idx, bcheck.tile_idx +local check_sprite_idx = bcheck.sprite_idx local check_weapon_idx, check_inventory_idx = bcheck.weapon_idx, bcheck.inventory_idx local check_sound_idx = bcheck.sound_idx @@ -498,6 +499,7 @@ const char *s_buildRev; const char *g_sizes_of_what[]; int32_t g_sizes_of[]; int32_t g_elCallDepth; +int32_t g_elEventRETURN; char g_modDir[]; actor_t actor[MAXSPRITES]; camera_t g_camera; @@ -1077,6 +1079,14 @@ function gv_access._set_guniqhudid(id) ffiC.guniqhudid = id end +function gv_access._RETURN(setval) + if (setval ~= nil) then + ffiC.g_elEventRETURN = setval + else + return ffiC.g_elEventRETURN + end +end + -- TODO: make return 1-based index function gv_access.currentEpisode() return ffiC.ud.volume_number diff --git a/polymer/eduke32/source/lunatic/lunacon.lua b/polymer/eduke32/source/lunatic/lunacon.lua index 0efb97426..4d6a640dd 100644 --- a/polymer/eduke32/source/lunatic/lunacon.lua +++ b/polymer/eduke32/source/lunatic/lunacon.lua @@ -344,8 +344,12 @@ function on.state_end(funcname, codetab) end function on.event_end(eventidx, codetab) + assert(type(codetab)=="table") addcodef("gameevent(%d, function (_aci, _pli, _dist)", eventidx) - add_code_and_end(codetab, "end)") + addcode(CSV".RETURN=gv._RETURN()") + addcode(codetab) + addcodef("gv._RETURN(%s)", CSV".RETURN") + addcode("end)") g_code.event[eventidx] = codetab end @@ -1780,9 +1784,9 @@ local Cinner = { soundoncevar = cmd(R) / handle.soundonce, stopactorsound = cmd(R,R) - / "_stopactorsound(%1,%2)", + / "_con._stopactorsound(%1,%2)", stopallsounds = cmd() - / "_stopallsounds()", + / "_con._stopallsounds()", mikesnd = cmd() / format("_con._soundonce(_aci,%s)", SPS".yvel"), setactorsoundpitch = cmd(R,R,R) diff --git a/polymer/eduke32/source/lunatic/lunatic_game.c b/polymer/eduke32/source/lunatic/lunatic_game.c index e26eab869..5da2858a6 100644 --- a/polymer/eduke32/source/lunatic/lunatic_game.c +++ b/polymer/eduke32/source/lunatic/lunatic_game.c @@ -24,6 +24,7 @@ uint8_t g_elEvents[MAXEVENTS]; el_actor_t g_elActors[MAXTILES]; int32_t g_elCallDepth = 0; +int32_t g_elEventRETURN; // for timing events and actors uint32_t g_eventCalls[MAXEVENTS], g_actorCalls[MAXTILES]; @@ -442,7 +443,7 @@ static void El_EventErrorPrint(const char *errmsg) EventNames[g_eventIdx], errmsg); } -int32_t El_CallEvent(L_State *estate, int32_t eventidx, int32_t iActor, int32_t iPlayer, int32_t lDist) +int32_t El_CallEvent(L_State *estate, int32_t eventidx, int32_t iActor, int32_t iPlayer, int32_t lDist, int32_t *iReturn) { // XXX: estate must be the one where the events were registered... // make a global? @@ -450,10 +451,14 @@ int32_t El_CallEvent(L_State *estate, int32_t eventidx, int32_t iActor, int32_t lua_State *const L = estate->L; int32_t i; + g_elEventRETURN = *iReturn; + g_elCallDepth++; i = call_regd_function3(L, &g_elEvents[eventidx], iActor, iPlayer, lDist); g_elCallDepth--; + *iReturn = g_elEventRETURN; + if (i != 0) { g_eventIdx = eventidx; diff --git a/polymer/eduke32/source/lunatic/lunatic_game.h b/polymer/eduke32/source/lunatic/lunatic_game.h index 7220b3e90..f19e7b98d 100644 --- a/polymer/eduke32/source/lunatic/lunatic_game.h +++ b/polymer/eduke32/source/lunatic/lunatic_game.h @@ -34,7 +34,7 @@ void El_DisplayErrors(void); int32_t El_CreateState(L_State *estate, const char *name); void El_DestroyState(L_State *estate); -int32_t El_CallEvent(L_State *estate, int32_t eventidx, int32_t iActor, int32_t iPlayer, int32_t lDist); +int32_t El_CallEvent(L_State *estate, int32_t eventidx, int32_t iActor, int32_t iPlayer, int32_t lDist, int32_t *iReturn); int32_t El_CallActor(L_State *estate, int32_t actortile, int32_t iActor, int32_t iPlayer, int32_t lDist); static inline int32_t El_HaveEvent(int32_t eventidx) { return g_elEvents[eventidx]!=0; }