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)
{
#if !defined LUNATIC
int32_t i,j,x;
// FILE * fp=fopen("condebug.log","w");
@ -3884,7 +3885,7 @@ static void G_DumpDebugInfo(void)
OSD_Printf("\n");
OSD_Printf("Current gamevar values:\n");
#if !defined LUNATIC
for (i=0; i<MAX_WEAPONS; i++)
{
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;
char g_szBuf[1024];
intptr_t *g_caseScriptPtr=NULL; // the pointer to the start of the case table in a switch statement
// first entry is 'default' code.
#if !defined LUNATIC_ONLY
// 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 int32_t g_numCases = 0;
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_SetScriptSize(int32_t size);
#endif
int32_t g_numQuoteRedefinitions = 0;
@ -160,9 +163,7 @@ gamearray_t aGameArrays[MAXGAMEARRAYS];
int32_t g_gameVarCount=0;
int32_t g_gameArrayCount=0;
extern int32_t qsetmode;
char *textptr;
static char *textptr;
int32_t g_numCompilerErrors,g_numCompilerWarnings;
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)
{
C_AllocQuote(qnum);
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
int32_t C_AllocQuote(int32_t qnum)

View file

@ -10,7 +10,9 @@ local con_lang = require("con_lang")
local setmetatable = setmetatable
local assert = assert
local error = error
local print = print
local type = type
local unpack = unpack
@ -287,20 +289,38 @@ end
--- expose the functionality in a better fashion than merely giving access to
--- 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
error("invalid quote number "..qnum)
error("invalid quote number "..qnum, 3)
end
if (ffiC.ScriptQuotes[qnum] == nil) then
error("null quote "..qnum)
error("null quote "..qnum, 3)
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
ffiC.P_DoQuote(qnum+MAXQUOTES, ffiC.g_player[pli].ps)
end
function _echo(qnum)
check_quote_idx(qnum)
-- XXX: ugly round-trip
print(ffi.string(ffiC.ScriptQuotes[qnum]))
end
local D = {
-- TODO: dynamic tile remapping
ACTIVATOR = 2,
@ -965,6 +985,11 @@ function _globalsound(pli, sndidx)
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)
check_sprite_idx(aci)
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_PlaySound(uint32_t num, int32_t i);
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
@ -497,7 +497,12 @@ int32_t kread(int32_t handle, void *buffer, int32_t leng);
const char *G_ConFile(void);
void G_DoGameStartup(const int32_t *params);
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_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_DoGameStartup;
C_DefineSound;
C_DefineMusic;
C_DefineQuote;
C_DefineVolumeName;
C_DefineLevelName;
actor;
ud;
@ -113,5 +116,5 @@ G_ClearCameraView;
A_CheckAnySoundPlaying;
A_PlaySound;
S_CheckSoundPlaying;
S_StopSound;
S_StopEnvSound;
};

View file

@ -131,6 +131,12 @@ local function addcodef(fmt, ...)
addcode(format(fmt, ...))
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 tilenum = tsamm[1]
@ -149,19 +155,22 @@ local function on_actor_end(usertype, tsamm, codetab)
-- TODO: usertype (is non-nil only for 'useractor')
addcodef("gameactor(%d,%sfunction(_aci, _pli, _dist)", tilenum, str)
assert(type(codetab)=="table")
g_actor_code[tilenum] = codetab
add_code_and_end(codetab, "end)")
addcode(codetab)
addcode("end)")
g_actor_code[tilenum] = codetab
end
local function on_state_end(statename, codetab)
-- TODO: mangle names
addcodef("local function %s(_aci, _pli, _dist)", statename)
assert(type(codetab)=="table")
addcode(codetab)
addcode("end")
add_code_and_end(codetab, "end")
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
----------
@ -279,7 +288,7 @@ local function do_define_label(identifier, num)
else
-- conl.labels[...]: don't warn for wrong PROJ_ redefinitions
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)",
identifier, num, oldval)
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
end
g_data.level[EPMUL*vol+lev] = {
ptime=secs(ptstr), dtime=secs(dtstr), fn=fn, name="/"..levname
local map = {
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
local function cmd_defineskillname(skillnum, name)
@ -498,7 +513,20 @@ local function cmd_definevolumename(vol, name)
return
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
local function cmd_definequote(qnum, quotestr)
@ -514,8 +542,7 @@ local function cmd_definequote(qnum, quotestr)
return
end
-- strip whitespace from front and back
quotestr = quotestr:match("^%s*(.*)%s*$")
quotestr = stripws(quotestr)
if (ffi) then
if (#quotestr >= conl.MAXQUOTELEN) then
@ -550,7 +577,7 @@ end
local function cmd_definesound(sndnum, fn, ...)
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
end
@ -565,8 +592,9 @@ local function cmd_definesound(sndnum, fn, ...)
end
local function cmd_music(volnum, ...)
if (volnum < 0 or volnum >= conl.MAXVOLUMES+1) then
errprintf("volume number is negative or exceeds maximum volume count+1")
if (not (volnum >= 0 and volnum < conl.MAXVOLUMES+1)) then
-- NOTE: MAXVOLUMES is OK, since it's MapInfo[(MAXVOLUMES+1)*MAXLEVELS]
errprintf("volume number is negative or exceeds MAXVOLUMES=%d", conl.MAXVOLUMES)
return
end
@ -579,6 +607,13 @@ local function cmd_music(volnum, ...)
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
end
@ -940,7 +975,8 @@ local Ci = {
savegamevar = cmd(R),
readgamevar = cmd(R),
userquote = cmd(R),
echo = cmd(R),
echo = cmd(D) / "_con._echo(%1)", -- XXX: TEMP
-- echo = cmd(R),
starttrackvar = cmd(R),
clearmapstate = cmd(R),
activatecheat = cmd(R),
@ -1122,7 +1158,8 @@ local Ci = {
readarrayfromfile = 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),
getarraysize = cmd(I,W),
rotatepoint = cmd(R,R,R,R,R,W,W),
@ -1219,7 +1256,8 @@ local Cif = {
ifvarl = cmd(R,D),
ifvarg = cmd(R,D),
ifvare = cmd(R,D),
ifvare = cmd(R,D)
/ "%1==%2",
ifvarn = cmd(R,D),
ifvarand = cmd(R,D),
ifvaror = cmd(R,D),
@ -1505,7 +1543,8 @@ local Cb = {
eventloadactor = lpeg.Cc(nil) * sp1 * lpeg.Ct(t_define)
* 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"
/ on_state_end,
@ -1578,6 +1617,7 @@ end
local function check_else_Cmt()
-- match an 'else' only at the outermost level
-- XXX: THIS IS STILL WRONG
local good = (g_iflevel==0)
if (good) then
return true, "else"