2009-09-12 23:03:15 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
Copyright (C) 1996, 2003 - 3D Realms Entertainment
|
|
|
|
Copyright (C) 2000, 2003 - Matt Saettler (EDuke Enhancements)
|
|
|
|
Copyright (C) 2004, 2007 - EDuke32 developers
|
|
|
|
|
|
|
|
This file is part of EDuke32
|
|
|
|
|
|
|
|
EDuke32 is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License version 2
|
|
|
|
as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#ifndef _m32script_h_
|
|
|
|
#define _m32script_h_
|
|
|
|
|
|
|
|
#include "compat.h"
|
2009-12-13 01:23:44 +00:00
|
|
|
#include "baselayer.h"
|
2009-09-12 23:03:15 +00:00
|
|
|
#include "build.h"
|
|
|
|
#include "editor.h"
|
|
|
|
|
|
|
|
#define MAXQUOTES 2048
|
|
|
|
#define MAXQUOTELEN 128
|
|
|
|
|
|
|
|
typedef int32_t instype;
|
|
|
|
typedef int32_t ofstype;
|
|
|
|
|
|
|
|
extern char *ScriptQuotes[MAXQUOTES+1], *ScriptQuoteRedefinitions[MAXQUOTES+1];
|
|
|
|
extern int32_t g_numQuoteRedefinitions;
|
|
|
|
|
|
|
|
//extern int16_t neartagsector, neartagwall, neartagsprite;
|
|
|
|
//extern int32_t neartaghitdist;
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
extern int32_t VM_Execute(int32_t once);
|
|
|
|
extern void VM_OnEvent(register int32_t iEventID, register int32_t iActor);
|
2009-09-12 23:03:15 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
extern void VM_ScriptInfo(void);
|
|
|
|
extern void VM_Disasm(ofstype beg, int32_t size);
|
2009-09-12 23:03:15 +00:00
|
|
|
|
|
|
|
extern int32_t Gv_NewVar(const char *pszLabel, intptr_t lValue, uint32_t dwFlags);
|
|
|
|
extern int32_t Gv_NewArray(const char *pszLabel, void *arrayptr, intptr_t asize, uint32_t dwFlags);
|
|
|
|
extern void Gv_Init(void);
|
|
|
|
|
|
|
|
extern int32_t __fastcall Gv_GetVarX(register int32_t id);
|
|
|
|
extern void __fastcall Gv_SetVarX(register int32_t id, register int32_t lValue);
|
2010-08-11 22:37:45 +00:00
|
|
|
extern int32_t __fastcall Gv_GetVarN(register int32_t id); // 'N' for "no side-effects"... vars and locals only!
|
2009-09-12 23:03:15 +00:00
|
|
|
|
|
|
|
extern void SetGAMEPalette(void);
|
|
|
|
extern void SetWATERPalette(void);
|
|
|
|
extern void SetSLIMEPalette(void);
|
|
|
|
extern void SetBOSS1Palette(void);
|
|
|
|
|
2009-09-14 22:11:37 +00:00
|
|
|
extern int32_t *constants, constants_allocsize;
|
|
|
|
extern int32_t g_numSavedConstants;
|
|
|
|
|
2009-09-12 23:03:15 +00:00
|
|
|
extern instype *script ,*insptr;
|
|
|
|
extern int32_t *labelval;
|
|
|
|
extern uint8_t *labeltype;
|
|
|
|
extern int32_t g_numLabels, g_numDefaultLabels;
|
|
|
|
extern int32_t g_scriptSize;
|
|
|
|
extern char *label;
|
|
|
|
//extern int32_t label_allocsize;
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
extern hashtable_t h_labels;
|
2009-09-12 23:03:15 +00:00
|
|
|
|
|
|
|
#define MAXLABELLEN 32
|
|
|
|
|
|
|
|
//extern uint8_t waterpal[768],slimepal[768],titlepal[768],drealms[768],endingpal[768],animpal[768];
|
2010-05-02 23:27:30 +00:00
|
|
|
//extern char currentboardfilename[BMAVM_PATH];
|
2009-09-12 23:03:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
enum GameEvent_t {
|
|
|
|
EVENT_ENTER3DMODE,
|
|
|
|
EVENT_ANALYZESPRITES,
|
|
|
|
EVENT_INSERTSPRITE2D,
|
|
|
|
EVENT_INSERTSPRITE3D,
|
2009-09-17 22:08:37 +00:00
|
|
|
EVENT_DRAW2DSCREEN,
|
2012-07-08 21:47:23 +00:00
|
|
|
EVENT_DRAW3DSCREEN,
|
2009-09-17 22:08:37 +00:00
|
|
|
EVENT_KEYS2D,
|
2009-09-16 22:24:24 +00:00
|
|
|
EVENT_KEYS3D,
|
2009-10-11 20:13:16 +00:00
|
|
|
EVENT_PREKEYS2D,
|
2009-10-03 13:20:31 +00:00
|
|
|
EVENT_PREKEYS3D,
|
2011-04-17 17:01:20 +00:00
|
|
|
EVENT_LINKTAGS,
|
2011-11-25 09:51:06 +00:00
|
|
|
EVENT_KEYPRESS,
|
2009-09-12 23:03:15 +00:00
|
|
|
MAXEVENTS
|
|
|
|
};
|
|
|
|
|
|
|
|
extern ofstype aEventOffsets[MAXEVENTS];
|
2009-09-18 21:44:46 +00:00
|
|
|
extern int32_t aEventSizes[MAXEVENTS];
|
2009-09-12 23:03:15 +00:00
|
|
|
extern uint8_t aEventEnabled[MAXEVENTS];
|
2010-08-11 22:37:45 +00:00
|
|
|
extern uint16_t aEventNumLocals[MAXEVENTS];
|
2009-09-12 23:03:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
enum GamevarFlags_t {
|
|
|
|
MAXGAMEVARS = 1024, // must be a power of two between 256 and 4096, inclusive
|
2009-09-18 21:44:46 +00:00
|
|
|
LOG2MAXGV = 10,
|
2009-09-12 23:03:15 +00:00
|
|
|
MAXVARLABEL = MAXLABELLEN, //26,
|
|
|
|
|
|
|
|
GAMEVAR_PERBLOCK = 0x00000001, // per-block (state, event, or top-level) variable
|
2010-08-11 22:37:45 +00:00
|
|
|
GAMEVAR_USER_MASK = GAMEVAR_PERBLOCK,
|
2009-09-12 23:03:15 +00:00
|
|
|
|
|
|
|
GAMEVAR_RESET = 0x00000008, // marks var for to default
|
|
|
|
GAMEVAR_DEFAULT = 0x00000100, // allow override
|
|
|
|
|
|
|
|
GAMEVAR_SYSTEM = 0x00000800, // cannot change mode flags...(only default value)
|
|
|
|
GAMEVAR_READONLY = 0x00001000, // values are read-only (no setvar allowed)
|
2010-08-11 22:37:45 +00:00
|
|
|
|
2009-09-12 23:03:15 +00:00
|
|
|
GAMEVAR_INTPTR = 0x00002000, // plValues is a pointer to an int32_t
|
2010-05-18 05:14:17 +00:00
|
|
|
GAMEVAR_FLOATPTR = 0x00004000, // plValues is a pointer to a float
|
2009-09-12 23:03:15 +00:00
|
|
|
GAMEVAR_SHORTPTR = 0x00008000, // plValues is a pointer to a short
|
|
|
|
GAMEVAR_CHARPTR = 0x00010000, // plValues is a pointer to a char
|
2010-08-11 22:37:45 +00:00
|
|
|
GAMEVAR_PTR_MASK = GAMEVAR_INTPTR|GAMEVAR_FLOATPTR|GAMEVAR_SHORTPTR|GAMEVAR_CHARPTR,
|
|
|
|
|
2009-09-12 23:03:15 +00:00
|
|
|
// GAMEVAR_NORESET = 0x00020000, // var values are not reset when restoring map state
|
|
|
|
GAMEVAR_SPECIAL = 0x00040000, // flag for structure member shortcut vars
|
|
|
|
};
|
|
|
|
|
|
|
|
enum GamearrayFlags_t {
|
|
|
|
MAXGAMEARRAYS = (MAXGAMEVARS>>2), // must be lower than MAXGAMEVARS
|
|
|
|
MAXARRAYLABEL = MAXVARLABEL,
|
2010-08-11 22:37:45 +00:00
|
|
|
|
2009-09-12 23:03:15 +00:00
|
|
|
GAMEARRAY_READONLY = 0x00001000,
|
2012-08-06 20:00:35 +00:00
|
|
|
GAMEARRAY_WARN = 0x00002000,
|
2009-09-12 23:03:15 +00:00
|
|
|
|
2010-08-11 22:37:45 +00:00
|
|
|
GAMEARRAY_NORMAL = 0,
|
2009-09-12 23:03:15 +00:00
|
|
|
GAMEARRAY_OFCHAR = 0x00000001,
|
|
|
|
GAMEARRAY_OFSHORT = 0x00000002,
|
|
|
|
GAMEARRAY_OFINT = 0x00000004,
|
2010-08-11 22:37:45 +00:00
|
|
|
GAMEARRAY_TYPE_MASK = GAMEARRAY_OFCHAR|GAMEARRAY_OFSHORT|GAMEARRAY_OFINT,
|
2009-09-12 23:03:15 +00:00
|
|
|
|
|
|
|
GAMEARRAY_VARSIZE = 0x00000020,
|
|
|
|
|
|
|
|
GAMEARRAY_RESET = 0x00000008,
|
|
|
|
/// GAMEARRAY_NORESET = 0x00000001,
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
union {
|
|
|
|
intptr_t lValue; // pointer when (dwFlags & GAMEVAR_*PTR)
|
|
|
|
int32_t *plValues; // array of values when (dwFlags & GAMEVAR_PERBLOCK)
|
|
|
|
} val;
|
|
|
|
intptr_t lDefault;
|
|
|
|
char *szLabel;
|
|
|
|
uint32_t dwFlags;
|
|
|
|
} gamevar_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
char *szLabel;
|
|
|
|
void *vals; // array of values, type determined by (dwFlags & GAMEARRAY_TYPEMASK)
|
|
|
|
uint32_t dwFlags;
|
|
|
|
int32_t size; // id to size gamevar when (dwFlags & GAMEARRAY_VARSIZE)
|
|
|
|
} gamearray_t;
|
|
|
|
|
|
|
|
extern gamevar_t aGameVars[MAXGAMEVARS];
|
|
|
|
extern gamearray_t aGameArrays[MAXGAMEARRAYS];
|
|
|
|
extern int32_t g_gameVarCount, g_systemVarCount;
|
|
|
|
extern int32_t g_gameArrayCount, g_systemArrayCount;
|
|
|
|
|
2009-09-16 22:24:24 +00:00
|
|
|
extern uint32_t m32_drawlinepat;
|
2009-09-12 23:03:15 +00:00
|
|
|
|
|
|
|
|
2009-09-17 22:08:37 +00:00
|
|
|
extern int32_t g_iReturnVar;
|
2012-07-08 21:47:23 +00:00
|
|
|
extern int32_t g_doScreenShot;
|
2009-09-17 22:08:37 +00:00
|
|
|
extern int32_t m32_sortvar1, m32_sortvar2;
|
2009-09-12 23:03:15 +00:00
|
|
|
|
2009-09-16 22:24:24 +00:00
|
|
|
//extern int32_t g_numRealPalettes;
|
|
|
|
//extern int32_t g_scriptDebug;
|
2009-09-12 23:03:15 +00:00
|
|
|
|
|
|
|
extern int32_t g_numQuoteRedefinitions;
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
extern hashtable_t h_gamevars;
|
|
|
|
extern hashtable_t h_arrays;
|
2010-05-22 23:41:18 +00:00
|
|
|
//extern hashtable_t h_keywords;
|
2010-05-02 23:27:30 +00:00
|
|
|
extern hashtable_t h_gamefuncs;
|
2009-09-12 23:03:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
extern int32_t mousxplc;
|
|
|
|
extern int32_t mousyplc;
|
|
|
|
|
2010-05-22 23:41:18 +00:00
|
|
|
|
2010-08-11 22:37:45 +00:00
|
|
|
// gamevar bytecode format:
|
|
|
|
|
2010-12-19 22:47:10 +00:00
|
|
|
// FEDC|BA98|7654|3210|FEDC|BA98|7654|3120
|
2010-08-11 22:37:45 +00:00
|
|
|
// | .. .... .... gamevar ID
|
|
|
|
// | . constant bit (checked first) / get-payload-var bit for array or struct
|
|
|
|
// | . negate bit
|
|
|
|
// | . array bit \___\ if both set:
|
|
|
|
// | . struct bit / / local var
|
|
|
|
// .... .... .... ....| optional payload
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define M32_FLAG_CONSTANT (MAXGAMEVARS)
|
2010-05-22 23:41:18 +00:00
|
|
|
#define M32_FLAG_NEGATE (MAXGAMEVARS<<1)
|
2010-08-11 22:37:45 +00:00
|
|
|
|
|
|
|
#define M32_FLAG_VAR (0)
|
2010-05-22 23:41:18 +00:00
|
|
|
#define M32_FLAG_ARRAY (MAXGAMEVARS<<2)
|
2010-08-11 22:37:45 +00:00
|
|
|
#define M32_FLAG_STRUCT (MAXGAMEVARS<<3)
|
|
|
|
#define M32_FLAG_LOCAL (M32_FLAG_ARRAY|M32_FLAG_STRUCT)
|
|
|
|
#define M32_VARTYPE_MASK (M32_FLAG_ARRAY|M32_FLAG_STRUCT)
|
|
|
|
|
|
|
|
#define M32_FLAG_CONSTANTINDEX M32_FLAG_CONSTANT
|
|
|
|
// if set, fetch index for array or struct array from 16 high bits as a constant (otherwise: gamevar)
|
|
|
|
|
|
|
|
#define M32_BITS_MASK (0x0000ffff-(MAXGAMEVARS-1))
|
2010-05-22 23:41:18 +00:00
|
|
|
|
|
|
|
// IDs of special vars
|
|
|
|
#define M32_SPRITE_VAR_ID 0
|
|
|
|
#define M32_SECTOR_VAR_ID 1
|
|
|
|
#define M32_WALL_VAR_ID 2
|
|
|
|
#define M32_TSPRITE_VAR_ID 3
|
2011-05-07 18:23:34 +00:00
|
|
|
#define M32_LIGHT_VAR_ID 4
|
2010-05-22 23:41:18 +00:00
|
|
|
|
2011-05-07 18:23:34 +00:00
|
|
|
#define M32_THISACTOR_VAR_ID 5
|
|
|
|
#define M32_RETURN_VAR_ID 6
|
|
|
|
#define M32_LOTAG_VAR_ID 7
|
|
|
|
#define M32_HITAG_VAR_ID 8
|
|
|
|
#define M32_TEXTURE_VAR_ID 9
|
2012-07-08 21:47:23 +00:00
|
|
|
#define M32_DOSCRSHOT_VAR_ID 10
|
2010-05-22 23:41:18 +00:00
|
|
|
|
2010-08-11 22:37:45 +00:00
|
|
|
#define M32_LOCAL_ARRAY_ID 0
|
|
|
|
|
2010-05-22 23:41:18 +00:00
|
|
|
#define M32_PRINTERROR(Text, ...) OSD_Printf(OSD_ERROR "Line %d, %s: " Text "\n", g_errorLineNum, keyw[g_tw], ## __VA_ARGS__)
|
2011-05-07 18:23:34 +00:00
|
|
|
#define M32_ERROR(Text, ...) do { M32_PRINTERROR(Text, ## __VA_ARGS__); vm.flags |= VMFLAG_ERROR; } while (0)
|
2010-05-22 23:41:18 +00:00
|
|
|
|
2010-08-12 13:38:37 +00:00
|
|
|
|
|
|
|
// how local gamevars are allocated:
|
|
|
|
|
|
|
|
// uncomment if variable-length arrays are available
|
|
|
|
//#define M32_LOCALS_VARARRAY
|
|
|
|
|
|
|
|
// uncomment if alloca() is available
|
|
|
|
//#define M32_LOCALS_ALLOCA
|
|
|
|
|
|
|
|
// if neither is there, use a constant number of them
|
|
|
|
#define M32_LOCALS_FIXEDNUM 64
|
|
|
|
|
|
|
|
#if defined M32_LOCALS_VARARRAY || defined M32_LOCALS_ALLOCA
|
|
|
|
# define M32_MAX_LOCALS MAXGAMEVARS
|
|
|
|
#else
|
|
|
|
# define M32_MAX_LOCALS M32_LOCALS_FIXEDNUM
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2009-09-12 23:03:15 +00:00
|
|
|
#endif
|