diff --git a/src/g_level.cpp b/src/g_level.cpp index 8987aed6c2..a715b5d263 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -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() -{ - PStruct *lstruct = NewNativeStruct("LevelLocals", nullptr); - PField *levelf = new PField("level", lstruct, VARF_Native | VARF_Static, (intptr_t)&level); - GlobalSymbols.AddSymbol(levelf); - - // This only exports a selection of fields. Not everything here is useful to the playsim. - lstruct->AddNativeField("time", TypeSInt32, myoffsetof(FLevelLocals, time), VARF_ReadOnly); - lstruct->AddNativeField("maptime", TypeSInt32, myoffsetof(FLevelLocals, maptime), VARF_ReadOnly); - lstruct->AddNativeField("totaltime", TypeSInt32, myoffsetof(FLevelLocals, totaltime), VARF_ReadOnly); - lstruct->AddNativeField("starttime", TypeSInt32, myoffsetof(FLevelLocals, starttime), VARF_ReadOnly); - lstruct->AddNativeField("partime", TypeSInt32, myoffsetof(FLevelLocals, partime), VARF_ReadOnly); - lstruct->AddNativeField("sucktime", TypeSInt32, myoffsetof(FLevelLocals, sucktime), VARF_ReadOnly); - lstruct->AddNativeField("cluster", TypeSInt32, myoffsetof(FLevelLocals, cluster), VARF_ReadOnly); - lstruct->AddNativeField("clusterflags", TypeSInt32, myoffsetof(FLevelLocals, clusterflags), VARF_ReadOnly); - lstruct->AddNativeField("levelnum", TypeSInt32, myoffsetof(FLevelLocals, levelnum), VARF_ReadOnly); - //lstruct->AddNativeField("levelname", TypeString, myoffsetof(FLevelLocals, LevelName), VARF_ReadOnly); // must use an access function to resolve string table references. - lstruct->AddNativeField("mapname", TypeString, myoffsetof(FLevelLocals, MapName), VARF_ReadOnly); - lstruct->AddNativeField("nextmap", TypeString, myoffsetof(FLevelLocals, NextMap)); - lstruct->AddNativeField("nextsecretmap", TypeString, myoffsetof(FLevelLocals, NextSecretMap)); - lstruct->AddNativeField("maptype", TypeSInt32, myoffsetof(FLevelLocals, maptype), VARF_ReadOnly); - lstruct->AddNativeField("monsterstelefrag", TypeSInt32, myoffsetof(FLevelLocals, flags), VARF_ReadOnly, LEVEL_MONSTERSTELEFRAG); - lstruct->AddNativeField("actownspecial", TypeSInt32, myoffsetof(FLevelLocals, flags), VARF_ReadOnly, LEVEL_ACTOWNSPECIAL); - lstruct->AddNativeField("sndseqtotalctrl", TypeSInt32, myoffsetof(FLevelLocals, flags), VARF_ReadOnly, LEVEL_SNDSEQTOTALCTRL); - lstruct->AddNativeField("allmap", TypeSInt32, myoffsetof(FLevelLocals, flags2), 0, (LEVEL2_ALLMAP)); - lstruct->AddNativeField("missilesactivateimpact", TypeSInt32, myoffsetof(FLevelLocals, flags2), 0, LEVEL2_MISSILESACTIVATEIMPACT); - lstruct->AddNativeField("monsterfallingdamage", TypeSInt32, myoffsetof(FLevelLocals, flags2), 0, LEVEL2_MONSTERFALLINGDAMAGE); - lstruct->AddNativeField("checkswitchrange", TypeSInt32, myoffsetof(FLevelLocals, flags2), 0, LEVEL2_CHECKSWITCHRANGE); - lstruct->AddNativeField("polygrind", TypeSInt32, myoffsetof(FLevelLocals, flags2), 0, LEVEL2_POLYGRIND); - lstruct->AddNativeField("music", TypeString, myoffsetof(FLevelLocals, Music), VARF_ReadOnly); - lstruct->AddNativeField("musicorder", TypeSInt32, myoffsetof(FLevelLocals, musicorder), VARF_ReadOnly); - lstruct->AddNativeField("total_secrets", TypeSInt32, myoffsetof(FLevelLocals, total_secrets), VARF_ReadOnly); - lstruct->AddNativeField("found_secrets", TypeSInt32, myoffsetof(FLevelLocals, found_secrets)); - lstruct->AddNativeField("total_items", TypeSInt32, myoffsetof(FLevelLocals, total_items), VARF_ReadOnly); - lstruct->AddNativeField("found_items", TypeSInt32, myoffsetof(FLevelLocals, found_items)); - 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)); -} +DEFINE_FIELD(FLevelLocals, time) +DEFINE_FIELD(FLevelLocals, maptime) +DEFINE_FIELD(FLevelLocals, totaltime) +DEFINE_FIELD(FLevelLocals, starttime) +DEFINE_FIELD(FLevelLocals, partime) +DEFINE_FIELD(FLevelLocals, sucktime) +DEFINE_FIELD(FLevelLocals, cluster) +DEFINE_FIELD(FLevelLocals, clusterflags) +DEFINE_FIELD(FLevelLocals, levelnum) +DEFINE_FIELD(FLevelLocals, LevelName) +DEFINE_FIELD(FLevelLocals, MapName) +DEFINE_FIELD(FLevelLocals, NextMap) +DEFINE_FIELD(FLevelLocals, NextSecretMap) +DEFINE_FIELD(FLevelLocals, maptype) +DEFINE_FIELD(FLevelLocals, Music) +DEFINE_FIELD(FLevelLocals, musicorder) +DEFINE_FIELD(FLevelLocals, total_secrets) +DEFINE_FIELD(FLevelLocals, found_secrets) +DEFINE_FIELD(FLevelLocals, total_items) +DEFINE_FIELD(FLevelLocals, found_items) +DEFINE_FIELD(FLevelLocals, total_monsters) +DEFINE_FIELD(FLevelLocals, killed_monsters) +DEFINE_FIELD(FLevelLocals, gravity) +DEFINE_FIELD(FLevelLocals, aircontrol) +DEFINE_FIELD(FLevelLocals, airfriction) +DEFINE_FIELD(FLevelLocals, airsupply) +DEFINE_FIELD(FLevelLocals, teamdamage) +DEFINE_FIELD_BIT(FLevelLocals, flags, monsterstelefrag, LEVEL_MONSTERSTELEFRAG) +DEFINE_FIELD_BIT(FLevelLocals, flags, actownspecial, LEVEL_ACTOWNSPECIAL) +DEFINE_FIELD_BIT(FLevelLocals, flags, sndseqtotalctrl, LEVEL_SNDSEQTOTALCTRL) +DEFINE_FIELD_BIT(FLevelLocals, flags2, allmap, LEVEL2_ALLMAP) +DEFINE_FIELD_BIT(FLevelLocals, flags2, missilesactivateimpact, LEVEL2_MISSILESACTIVATEIMPACT) +DEFINE_FIELD_BIT(FLevelLocals, flags2, monsterfallingdamage, LEVEL2_MONSTERFALLINGDAMAGE) +DEFINE_FIELD_BIT(FLevelLocals, flags2, checkswitchrange, LEVEL2_CHECKSWITCHRANGE) +DEFINE_FIELD_BIT(FLevelLocals, flags2, polygrind, LEVEL2_POLYGRIND) //========================================================================== // diff --git a/src/p_states.cpp b/src/p_states.cpp index 6e45db6b0e..b3e9593af6 100644 --- a/src/p_states.cpp +++ b/src/p_states.cpp @@ -1063,24 +1063,18 @@ CCMD(dumpstates) // //========================================================================== -void P_InitStateForScript() -{ - PNativeStruct *pstruct = dyn_cast(TypeState->PointedType); - assert(pstruct != nullptr); - - pstruct->AddNativeField("NextState", TypeState, myoffsetof(FState, NextState), VARF_ReadOnly); - pstruct->AddNativeField("sprite", TypeSInt32, myoffsetof(FState, sprite), VARF_ReadOnly); - pstruct->AddNativeField("Tics", TypeSInt16, myoffsetof(FState, Tics), VARF_ReadOnly); - pstruct->AddNativeField("TicRange", TypeUInt16, myoffsetof(FState, TicRange), VARF_ReadOnly); - pstruct->AddNativeField("Frame", TypeUInt8, myoffsetof(FState, Frame), VARF_ReadOnly); - pstruct->AddNativeField("UseFlags", TypeUInt8, myoffsetof(FState, UseFlags), VARF_ReadOnly); - pstruct->AddNativeField("Misc1", TypeSInt32, myoffsetof(FState, Misc1), VARF_ReadOnly); - pstruct->AddNativeField("Misc2", TypeSInt32, myoffsetof(FState, Misc2), VARF_ReadOnly); - pstruct->AddNativeField("bSlow", TypeUInt16, myoffsetof(FState, StateFlags), VARF_ReadOnly, STF_SLOW); - pstruct->AddNativeField("bFast", TypeUInt16, myoffsetof(FState, StateFlags), VARF_ReadOnly, STF_FAST); - 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); -} \ No newline at end of file +DEFINE_FIELD(FState, NextState) +DEFINE_FIELD(FState, sprite) +DEFINE_FIELD(FState, Tics) +DEFINE_FIELD(FState, TicRange) +DEFINE_FIELD(FState, Frame) +DEFINE_FIELD(FState, UseFlags) +DEFINE_FIELD(FState, Misc1) +DEFINE_FIELD(FState, Misc2) +DEFINE_FIELD_BIT(FState, StateFlags, bSlow) +DEFINE_FIELD_BIT(FState, StateFlags, bFast) +DEFINE_FIELD_BIT(FState, StateFlags, bFullbright) +DEFINE_FIELD_BIT(FState, StateFlags, bNoDelay) +DEFINE_FIELD_BIT(FState, StateFlags, bSameFrame) +DEFINE_FIELD_BIT(FState, StateFlags, bCanRaise) +DEFINE_FIELD_BIT(FState, StateFlags, bDehacked) diff --git a/src/scripting/thingdef_data.cpp b/src/scripting/thingdef_data.cpp index 7488c97167..bc6e0ad43a 100644 --- a/src/scripting/thingdef_data.cpp +++ b/src/scripting/thingdef_data.cpp @@ -691,9 +691,6 @@ static int fieldcmp(const void * a, const void * b) // Initialization // //========================================================================== -void G_InitLevelLocalsForScript(); -void P_InitPlayerForScript(); -void P_InitStateForScript(); void InitThingdef() { @@ -703,8 +700,10 @@ void InitThingdef() auto sptr = NewPointer(sstruct); sstruct->AddNativeField("soundtarget", TypeActor, myoffsetof(sector_t, SoundTarget)); - G_InitLevelLocalsForScript(); - P_InitStateForScript(); + // set up a variable for the global level data structure + 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. PStruct *pstruct = NewNativeStruct("PlayerInfo", nullptr); diff --git a/wadsrc/static/zscript/base.txt b/wadsrc/static/zscript/base.txt index 0f28de3356..15a8c9a3b6 100644 --- a/wadsrc/static/zscript/base.txt +++ b/wadsrc/static/zscript/base.txt @@ -49,6 +49,65 @@ class SpotState : Object native native SpecialSpot GetNextInList(class 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 { }