- exported the native fields of FState and FLevelLocals as well.

This commit is contained in:
Christoph Oelckers 2016-11-23 00:35:06 +01:00
parent 099b9970ef
commit 46757ff8bf
4 changed files with 114 additions and 72 deletions

View File

@ -1850,55 +1850,45 @@ void FLevelLocals::AddScroller (int secnum)
//========================================================================== //==========================================================================
// //
// sets up the script-side version of FLevelLocals //
// Since this is a global variable and the script compiler does
// not allow defining them, it will be fully set up here.
// //
//========================================================================== //==========================================================================
void G_InitLevelLocalsForScript() DEFINE_FIELD(FLevelLocals, time)
{ DEFINE_FIELD(FLevelLocals, maptime)
PStruct *lstruct = NewNativeStruct("LevelLocals", nullptr); DEFINE_FIELD(FLevelLocals, totaltime)
PField *levelf = new PField("level", lstruct, VARF_Native | VARF_Static, (intptr_t)&level); DEFINE_FIELD(FLevelLocals, starttime)
GlobalSymbols.AddSymbol(levelf); DEFINE_FIELD(FLevelLocals, partime)
DEFINE_FIELD(FLevelLocals, sucktime)
// This only exports a selection of fields. Not everything here is useful to the playsim. DEFINE_FIELD(FLevelLocals, cluster)
lstruct->AddNativeField("time", TypeSInt32, myoffsetof(FLevelLocals, time), VARF_ReadOnly); DEFINE_FIELD(FLevelLocals, clusterflags)
lstruct->AddNativeField("maptime", TypeSInt32, myoffsetof(FLevelLocals, maptime), VARF_ReadOnly); DEFINE_FIELD(FLevelLocals, levelnum)
lstruct->AddNativeField("totaltime", TypeSInt32, myoffsetof(FLevelLocals, totaltime), VARF_ReadOnly); DEFINE_FIELD(FLevelLocals, LevelName)
lstruct->AddNativeField("starttime", TypeSInt32, myoffsetof(FLevelLocals, starttime), VARF_ReadOnly); DEFINE_FIELD(FLevelLocals, MapName)
lstruct->AddNativeField("partime", TypeSInt32, myoffsetof(FLevelLocals, partime), VARF_ReadOnly); DEFINE_FIELD(FLevelLocals, NextMap)
lstruct->AddNativeField("sucktime", TypeSInt32, myoffsetof(FLevelLocals, sucktime), VARF_ReadOnly); DEFINE_FIELD(FLevelLocals, NextSecretMap)
lstruct->AddNativeField("cluster", TypeSInt32, myoffsetof(FLevelLocals, cluster), VARF_ReadOnly); DEFINE_FIELD(FLevelLocals, maptype)
lstruct->AddNativeField("clusterflags", TypeSInt32, myoffsetof(FLevelLocals, clusterflags), VARF_ReadOnly); DEFINE_FIELD(FLevelLocals, Music)
lstruct->AddNativeField("levelnum", TypeSInt32, myoffsetof(FLevelLocals, levelnum), VARF_ReadOnly); DEFINE_FIELD(FLevelLocals, musicorder)
//lstruct->AddNativeField("levelname", TypeString, myoffsetof(FLevelLocals, LevelName), VARF_ReadOnly); // must use an access function to resolve string table references. DEFINE_FIELD(FLevelLocals, total_secrets)
lstruct->AddNativeField("mapname", TypeString, myoffsetof(FLevelLocals, MapName), VARF_ReadOnly); DEFINE_FIELD(FLevelLocals, found_secrets)
lstruct->AddNativeField("nextmap", TypeString, myoffsetof(FLevelLocals, NextMap)); DEFINE_FIELD(FLevelLocals, total_items)
lstruct->AddNativeField("nextsecretmap", TypeString, myoffsetof(FLevelLocals, NextSecretMap)); DEFINE_FIELD(FLevelLocals, found_items)
lstruct->AddNativeField("maptype", TypeSInt32, myoffsetof(FLevelLocals, maptype), VARF_ReadOnly); DEFINE_FIELD(FLevelLocals, total_monsters)
lstruct->AddNativeField("monsterstelefrag", TypeSInt32, myoffsetof(FLevelLocals, flags), VARF_ReadOnly, LEVEL_MONSTERSTELEFRAG); DEFINE_FIELD(FLevelLocals, killed_monsters)
lstruct->AddNativeField("actownspecial", TypeSInt32, myoffsetof(FLevelLocals, flags), VARF_ReadOnly, LEVEL_ACTOWNSPECIAL); DEFINE_FIELD(FLevelLocals, gravity)
lstruct->AddNativeField("sndseqtotalctrl", TypeSInt32, myoffsetof(FLevelLocals, flags), VARF_ReadOnly, LEVEL_SNDSEQTOTALCTRL); DEFINE_FIELD(FLevelLocals, aircontrol)
lstruct->AddNativeField("allmap", TypeSInt32, myoffsetof(FLevelLocals, flags2), 0, (LEVEL2_ALLMAP)); DEFINE_FIELD(FLevelLocals, airfriction)
lstruct->AddNativeField("missilesactivateimpact", TypeSInt32, myoffsetof(FLevelLocals, flags2), 0, LEVEL2_MISSILESACTIVATEIMPACT); DEFINE_FIELD(FLevelLocals, airsupply)
lstruct->AddNativeField("monsterfallingdamage", TypeSInt32, myoffsetof(FLevelLocals, flags2), 0, LEVEL2_MONSTERFALLINGDAMAGE); DEFINE_FIELD(FLevelLocals, teamdamage)
lstruct->AddNativeField("checkswitchrange", TypeSInt32, myoffsetof(FLevelLocals, flags2), 0, LEVEL2_CHECKSWITCHRANGE); DEFINE_FIELD_BIT(FLevelLocals, flags, monsterstelefrag, LEVEL_MONSTERSTELEFRAG)
lstruct->AddNativeField("polygrind", TypeSInt32, myoffsetof(FLevelLocals, flags2), 0, LEVEL2_POLYGRIND); DEFINE_FIELD_BIT(FLevelLocals, flags, actownspecial, LEVEL_ACTOWNSPECIAL)
lstruct->AddNativeField("music", TypeString, myoffsetof(FLevelLocals, Music), VARF_ReadOnly); DEFINE_FIELD_BIT(FLevelLocals, flags, sndseqtotalctrl, LEVEL_SNDSEQTOTALCTRL)
lstruct->AddNativeField("musicorder", TypeSInt32, myoffsetof(FLevelLocals, musicorder), VARF_ReadOnly); DEFINE_FIELD_BIT(FLevelLocals, flags2, allmap, LEVEL2_ALLMAP)
lstruct->AddNativeField("total_secrets", TypeSInt32, myoffsetof(FLevelLocals, total_secrets), VARF_ReadOnly); DEFINE_FIELD_BIT(FLevelLocals, flags2, missilesactivateimpact, LEVEL2_MISSILESACTIVATEIMPACT)
lstruct->AddNativeField("found_secrets", TypeSInt32, myoffsetof(FLevelLocals, found_secrets)); DEFINE_FIELD_BIT(FLevelLocals, flags2, monsterfallingdamage, LEVEL2_MONSTERFALLINGDAMAGE)
lstruct->AddNativeField("total_items", TypeSInt32, myoffsetof(FLevelLocals, total_items), VARF_ReadOnly); DEFINE_FIELD_BIT(FLevelLocals, flags2, checkswitchrange, LEVEL2_CHECKSWITCHRANGE)
lstruct->AddNativeField("found_items", TypeSInt32, myoffsetof(FLevelLocals, found_items)); DEFINE_FIELD_BIT(FLevelLocals, flags2, polygrind, LEVEL2_POLYGRIND)
lstruct->AddNativeField("total_monsters", TypeSInt32, myoffsetof(FLevelLocals, total_monsters), VARF_ReadOnly);
lstruct->AddNativeField("killed_monsters", TypeSInt32, myoffsetof(FLevelLocals, killed_monsters));
lstruct->AddNativeField("gravity", TypeFloat64, myoffsetof(FLevelLocals, gravity));
lstruct->AddNativeField("aircontrol", TypeFloat64, myoffsetof(FLevelLocals, aircontrol));
lstruct->AddNativeField("airfriction", TypeFloat64, myoffsetof(FLevelLocals, airfriction));
lstruct->AddNativeField("airsupply", TypeSInt32, myoffsetof(FLevelLocals, airsupply));
lstruct->AddNativeField("teamdamage", TypeFloat64, myoffsetof(FLevelLocals, teamdamage));
}
//========================================================================== //==========================================================================
// //

View File

@ -1063,24 +1063,18 @@ CCMD(dumpstates)
// //
//========================================================================== //==========================================================================
void P_InitStateForScript() DEFINE_FIELD(FState, NextState)
{ DEFINE_FIELD(FState, sprite)
PNativeStruct *pstruct = dyn_cast<PNativeStruct>(TypeState->PointedType); DEFINE_FIELD(FState, Tics)
assert(pstruct != nullptr); DEFINE_FIELD(FState, TicRange)
DEFINE_FIELD(FState, Frame)
pstruct->AddNativeField("NextState", TypeState, myoffsetof(FState, NextState), VARF_ReadOnly); DEFINE_FIELD(FState, UseFlags)
pstruct->AddNativeField("sprite", TypeSInt32, myoffsetof(FState, sprite), VARF_ReadOnly); DEFINE_FIELD(FState, Misc1)
pstruct->AddNativeField("Tics", TypeSInt16, myoffsetof(FState, Tics), VARF_ReadOnly); DEFINE_FIELD(FState, Misc2)
pstruct->AddNativeField("TicRange", TypeUInt16, myoffsetof(FState, TicRange), VARF_ReadOnly); DEFINE_FIELD_BIT(FState, StateFlags, bSlow)
pstruct->AddNativeField("Frame", TypeUInt8, myoffsetof(FState, Frame), VARF_ReadOnly); DEFINE_FIELD_BIT(FState, StateFlags, bFast)
pstruct->AddNativeField("UseFlags", TypeUInt8, myoffsetof(FState, UseFlags), VARF_ReadOnly); DEFINE_FIELD_BIT(FState, StateFlags, bFullbright)
pstruct->AddNativeField("Misc1", TypeSInt32, myoffsetof(FState, Misc1), VARF_ReadOnly); DEFINE_FIELD_BIT(FState, StateFlags, bNoDelay)
pstruct->AddNativeField("Misc2", TypeSInt32, myoffsetof(FState, Misc2), VARF_ReadOnly); DEFINE_FIELD_BIT(FState, StateFlags, bSameFrame)
pstruct->AddNativeField("bSlow", TypeUInt16, myoffsetof(FState, StateFlags), VARF_ReadOnly, STF_SLOW); DEFINE_FIELD_BIT(FState, StateFlags, bCanRaise)
pstruct->AddNativeField("bFast", TypeUInt16, myoffsetof(FState, StateFlags), VARF_ReadOnly, STF_FAST); DEFINE_FIELD_BIT(FState, StateFlags, bDehacked)
pstruct->AddNativeField("bFullbright", TypeUInt16, myoffsetof(FState, StateFlags), VARF_ReadOnly, STF_FULLBRIGHT);
pstruct->AddNativeField("bNoDelay", TypeUInt16, myoffsetof(FState, StateFlags), VARF_ReadOnly, STF_NODELAY);
pstruct->AddNativeField("bSameFrame", TypeUInt16, myoffsetof(FState, StateFlags), VARF_ReadOnly, STF_SAMEFRAME);
pstruct->AddNativeField("bCanRaise", TypeUInt16, myoffsetof(FState, StateFlags), VARF_ReadOnly, STF_CANRAISE);
pstruct->AddNativeField("bDehacked", TypeUInt16, myoffsetof(FState, StateFlags), VARF_ReadOnly, STF_DEHACKED);
}

View File

@ -691,9 +691,6 @@ static int fieldcmp(const void * a, const void * b)
// Initialization // Initialization
// //
//========================================================================== //==========================================================================
void G_InitLevelLocalsForScript();
void P_InitPlayerForScript();
void P_InitStateForScript();
void InitThingdef() void InitThingdef()
{ {
@ -703,8 +700,10 @@ void InitThingdef()
auto sptr = NewPointer(sstruct); auto sptr = NewPointer(sstruct);
sstruct->AddNativeField("soundtarget", TypeActor, myoffsetof(sector_t, SoundTarget)); sstruct->AddNativeField("soundtarget", TypeActor, myoffsetof(sector_t, SoundTarget));
G_InitLevelLocalsForScript(); // set up a variable for the global level data structure
P_InitStateForScript(); PStruct *lstruct = NewNativeStruct("LevelLocals", nullptr);
PField *levelf = new PField("level", lstruct, VARF_Native | VARF_Static, (intptr_t)&level);
GlobalSymbols.AddSymbol(levelf);
// set up a variable for the global players array. // set up a variable for the global players array.
PStruct *pstruct = NewNativeStruct("PlayerInfo", nullptr); PStruct *pstruct = NewNativeStruct("PlayerInfo", nullptr);

View File

@ -49,6 +49,65 @@ class SpotState : Object native
native SpecialSpot GetNextInList(class<Actor> type, int skipcounter); native SpecialSpot GetNextInList(class<Actor> type, int skipcounter);
} }
struct LevelLocals native
{
native readonly int time;
native readonly int maptime;
native readonly int totaltime;
native readonly int starttime;
native readonly int partime;
native readonly int sucktime;
native readonly int cluster;
native readonly int clusterflags;
native readonly int levelnum;
native readonly String LevelName;
native readonly String MapName;
native String NextMap;
native String NextSecretMap;
native readonly int maptype;
native readonly String Music;
native readonly int musicorder;
native readonly int total_secrets;
native int found_secrets;
native readonly int total_items;
native int found_items;
native readonly int total_monsters;
native int killed_monsters;
native double gravity;
native double aircontrol;
native double airfriction;
native int airsupply;
native double teamdamage;
native bool monsterstelefrag;
native bool actownspecial;
native bool sndseqtotalctrl;
native bool allmap;
native bool missilesactivateimpact;
native bool monsterfallingdamage;
native bool checkswitchrange;
native bool polygrind;
// level_info_t *info cannot be done yet.
}
struct State native
{
State NextState;
int sprite;
int16 Tics;
uint16 TicRange;
uint8 Frame;
uint8 UseFlags;
int Misc1;
int Misc2;
uint16 bSlow;
uint16 bFast;
bool bFullbright;
bool bNoDelay;
bool bSameFrame;
bool bCanRaise;
bool bDehacked;
}
struct Sector native struct Sector native
{ {
} }