Lunatic: more commands, mostly of the define* variety.

git-svn-id: https://svn.eduke32.com/eduke32@3373 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-01-05 13:09:19 +00:00
parent 4d3df90fa4
commit 50f5a2340f
6 changed files with 150 additions and 32 deletions

View file

@ -3877,6 +3877,7 @@ void G_DrawRooms(int32_t snum, int32_t smoothratio)
static void G_DumpDebugInfo(void) static void G_DumpDebugInfo(void)
{ {
#if !defined LUNATIC
int32_t i,j,x; int32_t i,j,x;
// FILE * fp=fopen("condebug.log","w"); // FILE * fp=fopen("condebug.log","w");
@ -3884,7 +3885,7 @@ static void G_DumpDebugInfo(void)
OSD_Printf("\n"); OSD_Printf("\n");
OSD_Printf("Current gamevar values:\n"); OSD_Printf("Current gamevar values:\n");
#if !defined LUNATIC
for (i=0; i<MAX_WEAPONS; i++) for (i=0; i<MAX_WEAPONS; i++)
{ {
for (j=0; j<numplayers; j++) for (j=0; j<numplayers; j++)

View file

@ -98,8 +98,10 @@ int32_t g_totalLines,g_lineNumber;
static int32_t g_checkingIfElse, g_processingState, g_lastKeyword = -1; static int32_t g_checkingIfElse, g_processingState, g_lastKeyword = -1;
char g_szBuf[1024]; char g_szBuf[1024];
intptr_t *g_caseScriptPtr=NULL; // the pointer to the start of the case table in a switch statement #if !defined LUNATIC_ONLY
// first entry is 'default' code. // The pointer to the start of the case table in a switch statement.
// First entry is 'default' code.
static intptr_t *g_caseScriptPtr=NULL;
static intptr_t *previous_event=NULL; static intptr_t *previous_event=NULL;
static int32_t g_numCases = 0; static int32_t g_numCases = 0;
static int32_t g_checkingSwitch = 0, g_currentEvent = -1; static int32_t g_checkingSwitch = 0, g_currentEvent = -1;
@ -108,6 +110,7 @@ static int32_t g_numBraces = 0;
static int32_t C_ParseCommand(int32_t loop); static int32_t C_ParseCommand(int32_t loop);
static int32_t C_SetScriptSize(int32_t size); static int32_t C_SetScriptSize(int32_t size);
#endif
int32_t g_numQuoteRedefinitions = 0; int32_t g_numQuoteRedefinitions = 0;
@ -160,9 +163,7 @@ gamearray_t aGameArrays[MAXGAMEARRAYS];
int32_t g_gameVarCount=0; int32_t g_gameVarCount=0;
int32_t g_gameArrayCount=0; int32_t g_gameArrayCount=0;
extern int32_t qsetmode; static char *textptr;
char *textptr;
int32_t g_numCompilerErrors,g_numCompilerWarnings; int32_t g_numCompilerErrors,g_numCompilerWarnings;
extern int32_t g_maxSoundPos; extern int32_t g_maxSoundPos;
@ -2129,11 +2130,54 @@ void C_DefineSound(int32_t sndidx, const char *fn, int32_t args[5])
} }
} }
void C_DefineMusic(int32_t vol, int32_t lev, const char *fn)
{
Bassert((unsigned)vol < MAXVOLUMES+1);
Bassert((unsigned)lev < MAXLEVELS);
{
map_t *const map = &MapInfo[(MAXLEVELS*vol)+lev];
Bfree(map->musicfn);
map->musicfn = dup_filename(fn);
check_filename_case(map->musicfn);
}
}
void C_DefineQuote(int32_t qnum, const char *qstr) void C_DefineQuote(int32_t qnum, const char *qstr)
{ {
C_AllocQuote(qnum); C_AllocQuote(qnum);
Bstrncpyz(ScriptQuotes[qnum], qstr, MAXQUOTELEN); Bstrncpyz(ScriptQuotes[qnum], qstr, MAXQUOTELEN);
} }
void C_DefineVolumeName(int32_t vol, const char *name)
{
Bassert((unsigned)vol < MAXVOLUMES);
Bstrncpyz(EpisodeNames[vol], name, sizeof(EpisodeNames[vol]));
g_numVolumes = max(g_numVolumes, vol+1);
}
void C_DefineLevelName(int32_t vol, int32_t lev, const char *fn,
int32_t partime, int32_t designertime,
const char *levelname)
{
Bassert((unsigned)vol < MAXVOLUMES);
Bassert((unsigned)lev < MAXLEVELS);
{
map_t *const map = &MapInfo[(MAXLEVELS*vol)+lev];
Bfree(map->filename);
map->filename = dup_filename(fn);
// TODO: truncate to 32 chars?
Bfree(map->name);
map->name = Bstrdup(levelname);
map->partime = REALGAMETICSPERSEC * partime;
map->designertime = REALGAMETICSPERSEC * designertime;
}
}
#endif #endif
int32_t C_AllocQuote(int32_t qnum) int32_t C_AllocQuote(int32_t qnum)

View file

@ -10,7 +10,9 @@ local con_lang = require("con_lang")
local setmetatable = setmetatable local setmetatable = setmetatable
local assert = assert
local error = error local error = error
local print = print
local type = type local type = type
local unpack = unpack local unpack = unpack
@ -287,20 +289,38 @@ end
--- expose the functionality in a better fashion than merely giving access to --- expose the functionality in a better fashion than merely giving access to
--- the C functions.) --- the C functions.)
function _quote(pli, qnum) local MAXQUOTES = con_lang.MAXQUOTES
local MAXQUOTES = con_lang.MAXQUOTES
local function check_quote_idx(qnum)
if (qnum >= MAXQUOTES+0ULL) then if (qnum >= MAXQUOTES+0ULL) then
error("invalid quote number "..qnum) error("invalid quote number "..qnum, 3)
end end
if (ffiC.ScriptQuotes[qnum] == nil) then if (ffiC.ScriptQuotes[qnum] == nil) then
error("null quote "..qnum) error("null quote "..qnum, 3)
end end
end
function _definequote(qnum, quotestr)
check_quote_idx(qnum)
assert(type(quotestr)=="string")
ffiC.C_DefineQuote(qnum, quotestr)
return (#quotestr >= con_lang.MAXQUOTELEN)
end
function _quote(pli, qnum)
check_quote_idx(qnum)
local p = player[pli] -- bound-check local p = player[pli] -- bound-check
ffiC.P_DoQuote(qnum+MAXQUOTES, ffiC.g_player[pli].ps) ffiC.P_DoQuote(qnum+MAXQUOTES, ffiC.g_player[pli].ps)
end end
function _echo(qnum)
check_quote_idx(qnum)
-- XXX: ugly round-trip
print(ffi.string(ffiC.ScriptQuotes[qnum]))
end
local D = { local D = {
-- TODO: dynamic tile remapping -- TODO: dynamic tile remapping
ACTIVATOR = 2, ACTIVATOR = 2,
@ -965,6 +985,11 @@ function _globalsound(pli, sndidx)
end end
end end
-- This is a macro for EDuke32 (game.h)
local function S_StopSound(sndidx)
ffiC.S_StopEnvSound(sndidx, -1)
end
function _stopsound(aci, sndidx) function _stopsound(aci, sndidx)
check_sprite_idx(aci) check_sprite_idx(aci)
check_sound_idx(sndidx) check_sound_idx(sndidx)

View file

@ -484,7 +484,7 @@ void G_ClearCameraView(DukePlayer_t *ps);
int32_t A_CheckAnySoundPlaying(int32_t i); int32_t A_CheckAnySoundPlaying(int32_t i);
int32_t A_PlaySound(uint32_t num, int32_t i); int32_t A_PlaySound(uint32_t num, int32_t i);
int32_t S_CheckSoundPlaying(int32_t i, int32_t num); int32_t S_CheckSoundPlaying(int32_t i, int32_t num);
void S_StopSound(int32_t num); void S_StopEnvSound(int32_t num, int32_t i);
]] ]]
-- functions -- functions
@ -497,7 +497,12 @@ int32_t kread(int32_t handle, void *buffer, int32_t leng);
const char *G_ConFile(void); const char *G_ConFile(void);
void G_DoGameStartup(const int32_t *params); void G_DoGameStartup(const int32_t *params);
int32_t C_DefineSound(int32_t sndidx, const char *fn, int32_t args[5]); int32_t C_DefineSound(int32_t sndidx, const char *fn, int32_t args[5]);
void C_DefineMusic(int32_t vol, int32_t lev, const char *fn);
void C_DefineQuote(int32_t qnum, const char *qstr); void C_DefineQuote(int32_t qnum, const char *qstr);
void C_DefineVolumeName(int32_t vol, const char *name);
void C_DefineLevelName(int32_t vol, int32_t lev, const char *fn,
int32_t partime, int32_t designertime,
const char *levelname);
]] ]]

View file

@ -66,7 +66,10 @@ kread;
G_ConFile; G_ConFile;
G_DoGameStartup; G_DoGameStartup;
C_DefineSound; C_DefineSound;
C_DefineMusic;
C_DefineQuote; C_DefineQuote;
C_DefineVolumeName;
C_DefineLevelName;
actor; actor;
ud; ud;
@ -113,5 +116,5 @@ G_ClearCameraView;
A_CheckAnySoundPlaying; A_CheckAnySoundPlaying;
A_PlaySound; A_PlaySound;
S_CheckSoundPlaying; S_CheckSoundPlaying;
S_StopSound; S_StopEnvSound;
}; };

View file

@ -131,6 +131,12 @@ local function addcodef(fmt, ...)
addcode(format(fmt, ...)) addcode(format(fmt, ...))
end end
local function add_code_and_end(codetab, endstr)
assert(type(codetab)=="table")
addcode(codetab)
addcode(endstr)
end
local function on_actor_end(usertype, tsamm, codetab) local function on_actor_end(usertype, tsamm, codetab)
local tilenum = tsamm[1] local tilenum = tsamm[1]
@ -149,19 +155,22 @@ local function on_actor_end(usertype, tsamm, codetab)
-- TODO: usertype (is non-nil only for 'useractor') -- TODO: usertype (is non-nil only for 'useractor')
addcodef("gameactor(%d,%sfunction(_aci, _pli, _dist)", tilenum, str) addcodef("gameactor(%d,%sfunction(_aci, _pli, _dist)", tilenum, str)
assert(type(codetab)=="table") add_code_and_end(codetab, "end)")
g_actor_code[tilenum] = codetab
addcode(codetab) g_actor_code[tilenum] = codetab
addcode("end)")
end end
local function on_state_end(statename, codetab) local function on_state_end(statename, codetab)
-- TODO: mangle names -- TODO: mangle names
addcodef("local function %s(_aci, _pli, _dist)", statename) addcodef("local function %s(_aci, _pli, _dist)", statename)
assert(type(codetab)=="table") add_code_and_end(codetab, "end")
addcode(codetab) end
addcode("end")
local function on_event_end(eventidx, codetab)
addcodef("gameevent(%d, function (_aci, _pli, _dist)", eventidx)
add_code_and_end(codetab, "end)")
g_event_code[eventidx] = codetab
end end
---------- ----------
@ -279,7 +288,7 @@ local function do_define_label(identifier, num)
else else
-- conl.labels[...]: don't warn for wrong PROJ_ redefinitions -- conl.labels[...]: don't warn for wrong PROJ_ redefinitions
if (g_warn["not-redefined"]) then if (g_warn["not-redefined"]) then
if (oldval ~= num and conl.labels.PROJ[identifier]==nil) then if (oldval ~= num and conl.PROJ[identifier]==nil) then
warnprintf("label \"%s\" not redefined with new value %d (old: %d)", warnprintf("label \"%s\" not redefined with new value %d (old: %d)",
identifier, num, oldval) identifier, num, oldval)
end end
@ -478,9 +487,15 @@ local function cmd_definelevelname(vol, lev, fn, ptstr, dtstr, levname)
return (m and s) and m*60+s or 0 return (m and s) and m*60+s or 0
end end
g_data.level[EPMUL*vol+lev] = { local map = {
ptime=secs(ptstr), dtime=secs(dtstr), fn=fn, name="/"..levname ptime=secs(ptstr), dtime=secs(dtstr), fn="/"..fn, name=levname
} }
if (ffi) then
ffiC.C_DefineLevelName(vol, lev, map.fn, map.ptime, map.dtime, map.name)
end
g_data.level[EPMUL*vol+lev] = map
end end
local function cmd_defineskillname(skillnum, name) local function cmd_defineskillname(skillnum, name)
@ -498,7 +513,20 @@ local function cmd_definevolumename(vol, name)
return return
end end
g_data.volname[vol] = name:upper() name = name:upper()
if (ffi) then
ffiC.C_DefineVolumeName(vol, name)
if (#name > 32) then
warnprintf("volume %d name truncated to 32 characters.", vol)
end
end
g_data.volname[vol] = name
end
-- strip whitespace from front and back
local function stripws(str)
return str:match("^%s*(.*)%s*$")
end end
local function cmd_definequote(qnum, quotestr) local function cmd_definequote(qnum, quotestr)
@ -514,8 +542,7 @@ local function cmd_definequote(qnum, quotestr)
return return
end end
-- strip whitespace from front and back quotestr = stripws(quotestr)
quotestr = quotestr:match("^%s*(.*)%s*$")
if (ffi) then if (ffi) then
if (#quotestr >= conl.MAXQUOTELEN) then if (#quotestr >= conl.MAXQUOTELEN) then
@ -550,7 +577,7 @@ end
local function cmd_definesound(sndnum, fn, ...) local function cmd_definesound(sndnum, fn, ...)
if (not (sndnum >= 0 and sndnum < conl.MAXSOUNDS)) then if (not (sndnum >= 0 and sndnum < conl.MAXSOUNDS)) then
errprintf("sound number is or exceeds sound limit of %d", conl.MAXSOUNDS) errprintf("sound number is negative or exceeds sound limit of %d", conl.MAXSOUNDS-1)
return return
end end
@ -565,8 +592,9 @@ local function cmd_definesound(sndnum, fn, ...)
end end
local function cmd_music(volnum, ...) local function cmd_music(volnum, ...)
if (volnum < 0 or volnum >= conl.MAXVOLUMES+1) then if (not (volnum >= 0 and volnum < conl.MAXVOLUMES+1)) then
errprintf("volume number is negative or exceeds maximum volume count+1") -- NOTE: MAXVOLUMES is OK, since it's MapInfo[(MAXVOLUMES+1)*MAXLEVELS]
errprintf("volume number is negative or exceeds MAXVOLUMES=%d", conl.MAXVOLUMES)
return return
end end
@ -579,6 +607,13 @@ local function cmd_music(volnum, ...)
end end
end end
if (ffi) then
for i=1,#filenames do
assert(type(filenames[i])=="string")
ffiC.C_DefineMusic(volnum, i-1, "/"..filenames[i])
end
end
g_data.music[volnum] = filenames g_data.music[volnum] = filenames
end end
@ -940,7 +975,8 @@ local Ci = {
savegamevar = cmd(R), savegamevar = cmd(R),
readgamevar = cmd(R), readgamevar = cmd(R),
userquote = cmd(R), userquote = cmd(R),
echo = cmd(R), echo = cmd(D) / "_con._echo(%1)", -- XXX: TEMP
-- echo = cmd(R),
starttrackvar = cmd(R), starttrackvar = cmd(R),
clearmapstate = cmd(R), clearmapstate = cmd(R),
activatecheat = cmd(R), activatecheat = cmd(R),
@ -1122,7 +1158,8 @@ local Ci = {
readarrayfromfile = cmd(I,D), readarrayfromfile = cmd(I,D),
writearraytofile = cmd(I,D), writearraytofile = cmd(I,D),
redefinequote = sp1 * t_define * newline_term_string, redefinequote = sp1 * t_define * newline_term_string
/ function(qnum, qstr) return format("_con._definequote(%d,%q)", qnum, stripws(qstr)) end,
resizearray = cmd(I,R), resizearray = cmd(I,R),
getarraysize = cmd(I,W), getarraysize = cmd(I,W),
rotatepoint = cmd(R,R,R,R,R,W,W), rotatepoint = cmd(R,R,R,R,R,W,W),
@ -1219,7 +1256,8 @@ local Cif = {
ifvarl = cmd(R,D), ifvarl = cmd(R,D),
ifvarg = cmd(R,D), ifvarg = cmd(R,D),
ifvare = cmd(R,D), ifvare = cmd(R,D)
/ "%1==%2",
ifvarn = cmd(R,D), ifvarn = cmd(R,D),
ifvarand = cmd(R,D), ifvarand = cmd(R,D),
ifvaror = cmd(R,D), ifvaror = cmd(R,D),
@ -1505,7 +1543,8 @@ local Cb = {
eventloadactor = lpeg.Cc(nil) * sp1 * lpeg.Ct(t_define) eventloadactor = lpeg.Cc(nil) * sp1 * lpeg.Ct(t_define)
* sp1 * stmt_list_or_eps * "enda" / on_actor_end, * sp1 * stmt_list_or_eps * "enda" / on_actor_end,
onevent = sp1 * t_define * sp1 * stmt_list_or_eps * "endevent", onevent = sp1 * t_define * sp1 * stmt_list_or_eps * "endevent"
/ on_event_end,
state = sp1 * t_identifier * sp1 * stmt_list_or_eps * "ends" state = sp1 * t_identifier * sp1 * stmt_list_or_eps * "ends"
/ on_state_end, / on_state_end,
@ -1578,6 +1617,7 @@ end
local function check_else_Cmt() local function check_else_Cmt()
-- match an 'else' only at the outermost level -- match an 'else' only at the outermost level
-- XXX: THIS IS STILL WRONG
local good = (g_iflevel==0) local good = (g_iflevel==0)
if (good) then if (good) then
return true, "else" return true, "else"