- moved the per-level ACS state into FLevelLocals.

This commit is contained in:
Christoph Oelckers 2019-01-05 18:19:35 +01:00
parent 131eef9eb9
commit 7b235ea13e
18 changed files with 213 additions and 206 deletions

View File

@ -92,6 +92,7 @@ Everything that is changed is marked (maybe commented) with "Added by MC"
#include "d_player.h" #include "d_player.h"
#include "events.h" #include "events.h"
#include "vm.h" #include "vm.h"
#include "g_levellocals.h"
static FRandom pr_botspawn ("BotSpawn"); static FRandom pr_botspawn ("BotSpawn");
@ -447,7 +448,7 @@ void FCajunMaster::RemoveAllBots (bool fromlist)
// [ZZ] run event hook // [ZZ] run event hook
E_PlayerDisconnected(i); E_PlayerDisconnected(i);
// //
FBehavior::StaticStartTypedScripts (SCRIPT_Disconnect, players[i].mo, true, i, true); level.Behaviors.StartTypedScripts (SCRIPT_Disconnect, players[i].mo, true, i, true);
ClearPlayer (i, !fromlist); ClearPlayer (i, !fromlist);
} }
} }

View File

@ -1682,11 +1682,11 @@ void G_DoPlayerPop(int playernum)
} }
// [RH] Make the player disappear // [RH] Make the player disappear
FBehavior::StaticStopMyScripts(players[playernum].mo); level.Behaviors.StopMyScripts(players[playernum].mo);
// [ZZ] fire player disconnect hook // [ZZ] fire player disconnect hook
E_PlayerDisconnected(playernum); E_PlayerDisconnected(playernum);
// [RH] Let the scripts know the player left // [RH] Let the scripts know the player left
FBehavior::StaticStartTypedScripts(SCRIPT_Disconnect, players[playernum].mo, true, playernum, true); level.Behaviors.StartTypedScripts(SCRIPT_Disconnect, players[playernum].mo, true, playernum, true);
if (players[playernum].mo != NULL) if (players[playernum].mo != NULL)
{ {
P_DisconnectEffect(players[playernum].mo); P_DisconnectEffect(players[playernum].mo);

View File

@ -641,7 +641,7 @@ void G_ChangeLevel(const char *levelname, int position, int flags, int nextSkill
// [RH] Give scripts a chance to do something // [RH] Give scripts a chance to do something
unloading = true; unloading = true;
FBehavior::StaticStartTypedScripts (SCRIPT_Unloading, NULL, false, 0, true); level.Behaviors.StartTypedScripts (SCRIPT_Unloading, NULL, false, 0, true);
// [ZZ] safe world unload // [ZZ] safe world unload
E_WorldUnloaded(); E_WorldUnloaded();
// [ZZ] unsafe world unload (changemap != map) // [ZZ] unsafe world unload (changemap != map)
@ -854,7 +854,7 @@ void G_DoCompleted (void)
G_SnapshotLevel (); G_SnapshotLevel ();
// Do not free any global strings this level might reference // Do not free any global strings this level might reference
// while it's not loaded. // while it's not loaded.
FBehavior::StaticLockLevelVarStrings(); level.Behaviors.LockLevelVarStrings();
} }
else else
{ // Make sure we don't have a snapshot lying around from before. { // Make sure we don't have a snapshot lying around from before.
@ -1089,7 +1089,7 @@ void G_DoLoadLevel (int position, bool autosave, bool newGame)
if (fromSnapshot) if (fromSnapshot)
{ {
// ENTER scripts are being handled when the player gets spawned, this cannot be changed due to its effect on voodoo dolls. // ENTER scripts are being handled when the player gets spawned, this cannot be changed due to its effect on voodoo dolls.
FBehavior::StaticStartTypedScripts(SCRIPT_Return, players[ii].mo, true); level.Behaviors.StartTypedScripts(SCRIPT_Return, players[ii].mo, true);
} }
} }
} }
@ -1097,7 +1097,7 @@ void G_DoLoadLevel (int position, bool autosave, bool newGame)
if (level.FromSnapshot) if (level.FromSnapshot)
{ {
// [Nash] run REOPEN scripts upon map re-entry // [Nash] run REOPEN scripts upon map re-entry
FBehavior::StaticStartTypedScripts(SCRIPT_Reopen, NULL, false); level.Behaviors.StartTypedScripts(SCRIPT_Reopen, NULL, false);
} }
StatusBar->AttachToPlayer (&players[consoleplayer]); StatusBar->AttachToPlayer (&players[consoleplayer]);
@ -1718,7 +1718,7 @@ void G_UnSnapshotLevel (bool hubLoad)
if (hubLoad) if (hubLoad)
{ {
// Unlock ACS global strings that were locked when the snapshot was made. // Unlock ACS global strings that were locked when the snapshot was made.
FBehavior::StaticUnlockLevelVarStrings(); level.Behaviors.UnlockLevelVarStrings();
} }
} }

View File

@ -43,6 +43,7 @@
#include "p_blockmap.h" #include "p_blockmap.h"
#include "p_local.h" #include "p_local.h"
#include "po_man.h" #include "po_man.h"
#include "p_acs.h"
#include "p_destructible.h" #include "p_destructible.h"
#include "r_data/r_sections.h" #include "r_data/r_sections.h"
#include "r_data/r_canvastexture.h" #include "r_data/r_canvastexture.h"
@ -98,6 +99,7 @@ struct FLevelData
FPlayerStart playerstarts[MAXPLAYERS]; FPlayerStart playerstarts[MAXPLAYERS];
TArray<FPlayerStart> AllPlayerStarts; TArray<FPlayerStart> AllPlayerStarts;
FBehaviorContainer Behaviors;
}; };
struct FLevelLocals : public FLevelData struct FLevelLocals : public FLevelData

View File

@ -157,7 +157,7 @@ void DLightningThinker::LightningFlash ()
// [ZZ] just in case // [ZZ] just in case
E_WorldLightning(); E_WorldLightning();
// start LIGHTNING scripts // start LIGHTNING scripts
FBehavior::StaticStartTypedScripts (SCRIPT_Lightning, NULL, false); // [RH] Run lightning scripts level.Behaviors.StartTypedScripts (SCRIPT_Lightning, NULL, false); // [RH] Run lightning scripts
// Calculate the next lighting flash // Calculate the next lighting flash
if (!NextLightningFlash) if (!NextLightningFlash)

View File

@ -904,7 +904,7 @@ class CommandDrawString : public SBarInfoCommand
if(ACS_GlobalVars[valueArgument] != cache) if(ACS_GlobalVars[valueArgument] != cache)
{ {
cache = ACS_GlobalVars[valueArgument]; cache = ACS_GlobalVars[valueArgument];
str = FBehavior::StaticLookupString(ACS_GlobalVars[valueArgument]); str = level.Behaviors.LookupString(ACS_GlobalVars[valueArgument]);
RealignString(); RealignString();
} }
break; break;
@ -912,7 +912,7 @@ class CommandDrawString : public SBarInfoCommand
if(ACS_GlobalArrays[valueArgument][consoleplayer] != cache) if(ACS_GlobalArrays[valueArgument][consoleplayer] != cache)
{ {
cache = ACS_GlobalArrays[valueArgument][consoleplayer]; cache = ACS_GlobalArrays[valueArgument][consoleplayer];
str = FBehavior::StaticLookupString(ACS_GlobalArrays[valueArgument][consoleplayer]); str = level.Behaviors.LookupString(ACS_GlobalArrays[valueArgument][consoleplayer]);
RealignString(); RealignString();
} }
break; break;

View File

@ -660,6 +660,6 @@ void MapLoader::LoadMapinfoACSLump()
if (Level->info->acsName.IsNotEmpty()) if (Level->info->acsName.IsNotEmpty())
{ {
int lump = Wads.CheckNumForName(Level->info->acsName); int lump = Wads.CheckNumForName(Level->info->acsName);
if (lump >= 0) FBehavior::StaticLoadModule(lump); if (lump >= 0) Level->Behaviors.LoadModule(lump);
} }
} }

View File

@ -2825,12 +2825,12 @@ void MapLoader::LoadBehavior(MapData * map)
{ {
if (map->Size(ML_BEHAVIOR) > 0) if (map->Size(ML_BEHAVIOR) > 0)
{ {
FBehavior::StaticLoadModule(-1, &map->Reader(ML_BEHAVIOR), map->Size(ML_BEHAVIOR)); Level->Behaviors.LoadModule(-1, &map->Reader(ML_BEHAVIOR), map->Size(ML_BEHAVIOR));
} }
if (!FBehavior::StaticCheckAllGood()) if (!Level->Behaviors.CheckAllGood())
{ {
Printf("ACS scripts unloaded.\n"); Printf("ACS scripts unloaded.\n");
FBehavior::StaticUnloadModules(); Level->Behaviors.UnloadModules();
} }
} }
@ -2881,7 +2881,7 @@ void MapLoader::LoadLevel(MapData *map, const char *lumpname, int position)
ForceNodeBuild = gennodes; ForceNodeBuild = gennodes;
// [RH] Load in the BEHAVIOR lump // [RH] Load in the BEHAVIOR lump
FBehavior::StaticUnloadModules(); Level->Behaviors.UnloadModules();
if (map->HasBehavior) if (map->HasBehavior)
{ {
LoadBehavior(map); LoadBehavior(map);
@ -2941,7 +2941,7 @@ void MapLoader::LoadLevel(MapData *map, const char *lumpname, int position)
Level->flags2 |= LEVEL2_DUMMYSWITCHES; Level->flags2 |= LEVEL2_DUMMYSWITCHES;
} }
FBehavior::StaticLoadDefaultModules(); Level->Behaviors.LoadDefaultModules();
LoadMapinfoACSLump(); LoadMapinfoACSLump();
@ -3174,7 +3174,7 @@ void MapLoader::LoadLevel(MapData *map, const char *lumpname, int position)
node.len = (float)g_sqrt(fdx * fdx + fdy * fdy); node.len = (float)g_sqrt(fdx * fdx + fdy * fdy);
} }
InitRenderInfo(); // create hardware independent renderer resources for the level. This must be done BEFORE the PolyObj Spawn!!! InitRenderInfo(); // create hardware independent renderer resources for the Level-> This must be done BEFORE the PolyObj Spawn!!!
P_ClearDynamic3DFloorData(); // CreateVBO must be run on the plain 3D floor data. P_ClearDynamic3DFloorData(); // CreateVBO must be run on the plain 3D floor data.
screen->mVertexData->CreateVBO(); screen->mVertexData->CreateVBO();

File diff suppressed because it is too large Load Diff

View File

@ -344,6 +344,7 @@ enum
enum ACSFormat { ACS_Old, ACS_Enhanced, ACS_LittleEnhanced, ACS_Unknown }; enum ACSFormat { ACS_Old, ACS_Enhanced, ACS_LittleEnhanced, ACS_Unknown };
class FBehavior class FBehavior
{ {
public: public:
@ -381,20 +382,6 @@ public:
BoundsCheckingArray<int32_t *, NUM_MAPVARS> MapVars; BoundsCheckingArray<int32_t *, NUM_MAPVARS> MapVars;
static FBehavior *StaticLoadModule (int lumpnum, FileReader *fr = nullptr, int len=0);
static void StaticLoadDefaultModules ();
static void StaticUnloadModules ();
static bool StaticCheckAllGood ();
static FBehavior *StaticGetModule (int lib);
static void StaticSerializeModuleStates (FSerializer &arc);
static void StaticMarkLevelVarStrings();
static void StaticLockLevelVarStrings();
static void StaticUnlockLevelVarStrings();
static const ScriptPtr *StaticFindScript (int script, FBehavior *&module);
static const char *StaticLookupString (uint32_t index);
static void StaticStartTypedScripts (uint16_t type, AActor *activator, bool always, int arg1=0, bool runNow=false);
static void StaticStopMyScripts (AActor *actor);
private: private:
struct ArrayInfo; struct ArrayInfo;
@ -421,8 +408,6 @@ private:
char ModuleName[9]; char ModuleName[9];
TArray<int> JumpPoints; TArray<int> JumpPoints;
static TArray<FBehavior *> StaticModules;
void LoadScriptsDirectory (); void LoadScriptsDirectory ();
static int SortScripts (const void *a, const void *b); static int SortScripts (const void *a, const void *b);
@ -439,6 +424,30 @@ private:
friend void ArrangeScriptProfiles(TArray<ProfileCollector> &profiles); friend void ArrangeScriptProfiles(TArray<ProfileCollector> &profiles);
friend void ArrangeFunctionProfiles(TArray<ProfileCollector> &profiles); friend void ArrangeFunctionProfiles(TArray<ProfileCollector> &profiles);
friend struct FBehaviorContainer;
}; };
struct FBehaviorContainer
{
TArray<FBehavior *> StaticModules;
FBehavior *LoadModule(int lumpnum, FileReader *fr = nullptr, int len = 0);
void LoadDefaultModules();
void UnloadModules();
bool CheckAllGood();
FBehavior *GetModule(int lib);
void SerializeModuleStates(FSerializer &arc);
void MarkLevelVarStrings();
void LockLevelVarStrings();
void UnlockLevelVarStrings();
const ScriptPtr *FindScript(int script, FBehavior *&module);
const char *LookupString(uint32_t index);
void StartTypedScripts(uint16_t type, AActor *activator, bool always, int arg1 = 0, bool runNow = false);
void StopMyScripts(AActor *actor);
};
#endif //__P_ACS_H__ #endif //__P_ACS_H__

View File

@ -352,7 +352,7 @@ void AActor::Die (AActor *source, AActor *inflictor, int dmgflags, FName MeansOf
// [JM] Fire KILL type scripts for actor. Not needed for players, since they have the "DEATH" script type. // [JM] Fire KILL type scripts for actor. Not needed for players, since they have the "DEATH" script type.
if (!player && !(flags7 & MF7_NOKILLSCRIPTS) && ((flags7 & MF7_USEKILLSCRIPTS) || gameinfo.forcekillscripts)) if (!player && !(flags7 & MF7_NOKILLSCRIPTS) && ((flags7 & MF7_USEKILLSCRIPTS) || gameinfo.forcekillscripts))
{ {
FBehavior::StaticStartTypedScripts(SCRIPT_Kill, this, true, 0, true); level.Behaviors.StartTypedScripts(SCRIPT_Kill, this, true, 0, true);
} }
flags &= ~(MF_SHOOTABLE|MF_FLOAT|MF_SKULLFLY); flags &= ~(MF_SHOOTABLE|MF_FLOAT|MF_SKULLFLY);
@ -563,7 +563,7 @@ void AActor::Die (AActor *source, AActor *inflictor, int dmgflags, FName MeansOf
E_PlayerDied(int(player - players)); E_PlayerDied(int(player - players));
// Death script execution, care of Skull Tag // Death script execution, care of Skull Tag
FBehavior::StaticStartTypedScripts (SCRIPT_Death, this, true); level.Behaviors.StartTypedScripts (SCRIPT_Death, this, true);
// [RH] Force a delay between death and respawn // [RH] Force a delay between death and respawn
player->respawn_time = level.time + TICRATE; player->respawn_time = level.time + TICRATE;

View File

@ -5018,7 +5018,7 @@ AActor *P_SpawnPlayer (FPlayerStart *mthing, int playernum, int flags)
VMValue params[] = { mobj, oldactor }; VMValue params[] = { mobj, oldactor };
VMCall(func, params, 2, nullptr, 0); VMCall(func, params, 2, nullptr, 0);
} }
FBehavior::StaticStopMyScripts (oldactor); // cancel all ENTER/RESPAWN scripts for the voodoo doll level.Behaviors.StopMyScripts (oldactor); // cancel all ENTER/RESPAWN scripts for the voodoo doll
} }
// [GRB] Reset skin // [GRB] Reset skin
@ -5147,7 +5147,7 @@ AActor *P_SpawnPlayer (FPlayerStart *mthing, int playernum, int flags)
{ {
if (state == PST_ENTER || (state == PST_LIVE && !savegamerestore)) if (state == PST_ENTER || (state == PST_LIVE && !savegamerestore))
{ {
FBehavior::StaticStartTypedScripts (SCRIPT_Enter, p->mo, true); level.Behaviors.StartTypedScripts (SCRIPT_Enter, p->mo, true);
} }
else if (state == PST_REBORN) else if (state == PST_REBORN)
{ {
@ -5171,7 +5171,7 @@ AActor *P_SpawnPlayer (FPlayerStart *mthing, int playernum, int flags)
DObject::StaticPointerSubstitution (oldactor, p->mo); DObject::StaticPointerSubstitution (oldactor, p->mo);
E_PlayerRespawned(int(p - players)); E_PlayerRespawned(int(p - players));
FBehavior::StaticStartTypedScripts (SCRIPT_Respawn, p->mo, true); level.Behaviors.StartTypedScripts (SCRIPT_Respawn, p->mo, true);
} }
} }
return mobj; return mobj;

View File

@ -992,11 +992,7 @@ void G_SerializeLevel(FSerializer &arc, bool hubload)
G_AirControlChanged(); G_AirControlChanged();
} }
level.Behaviors.SerializeModuleStates(arc);
// fixme: This needs to ensure it reads from the correct place. Should be one once there's enough of this code converted to JSON
FBehavior::StaticSerializeModuleStates(arc);
// The order here is important: First world state, then portal state, then thinkers, and last polyobjects. // The order here is important: First world state, then portal state, then thinkers, and last polyobjects.
arc("linedefs", level.lines, level.loadlines); arc("linedefs", level.lines, level.loadlines);
arc("sidedefs", level.sides, level.loadsides); arc("sidedefs", level.sides, level.loadsides);

View File

@ -340,7 +340,7 @@ void P_FreeLevelData ()
DThinker::DestroyAllThinkers (); DThinker::DestroyAllThinkers ();
tagManager.Clear(); tagManager.Clear();
FBehavior::StaticUnloadModules (); level.Behaviors.UnloadModules ();
P_FreeStrifeConversations (); P_FreeStrifeConversations ();
level.ClearLevelData(); level.ClearLevelData();

View File

@ -1505,7 +1505,7 @@ void P_SpawnSpecials (MapLoader *ml)
} }
} }
// [RH] Start running any open scripts on this map // [RH] Start running any open scripts on this map
FBehavior::StaticStartTypedScripts (SCRIPT_Open, NULL, false); level.Behaviors.StartTypedScripts (SCRIPT_Open, NULL, false);
} }
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////

View File

@ -693,7 +693,7 @@ bool player_t::Resurrect()
// fire E_PlayerRespawned and start the ACS SCRIPT_Respawn. // fire E_PlayerRespawned and start the ACS SCRIPT_Respawn.
E_PlayerRespawned(int(this - players)); E_PlayerRespawned(int(this - players));
// //
FBehavior::StaticStartTypedScripts(SCRIPT_Respawn, mo, true); level.Behaviors.StartTypedScripts(SCRIPT_Respawn, mo, true);
return true; return true;
} }

View File

@ -2368,19 +2368,19 @@ DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, SetClipRect, SBar_SetClipRect)
static void GetGlobalACSString(int index, FString *result) static void GetGlobalACSString(int index, FString *result)
{ {
*result = FBehavior::StaticLookupString(ACS_GlobalVars[index]); *result = level.Behaviors.LookupString(ACS_GlobalVars[index]);
} }
DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, GetGlobalACSString, GetGlobalACSString) DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, GetGlobalACSString, GetGlobalACSString)
{ {
PARAM_PROLOGUE; PARAM_PROLOGUE;
PARAM_INT(index); PARAM_INT(index);
ACTION_RETURN_STRING(FBehavior::StaticLookupString(ACS_GlobalVars[index])); ACTION_RETURN_STRING(level.Behaviors.LookupString(ACS_GlobalVars[index]));
} }
static void GetGlobalACSArrayString(int arrayno, int index, FString *result) static void GetGlobalACSArrayString(int arrayno, int index, FString *result)
{ {
*result = FBehavior::StaticLookupString(ACS_GlobalVars[index]); *result = level.Behaviors.LookupString(ACS_GlobalVars[index]);
} }
DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, GetGlobalACSArrayString, GetGlobalACSArrayString) DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, GetGlobalACSArrayString, GetGlobalACSArrayString)
@ -2388,7 +2388,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, GetGlobalACSArrayString, GetGlobal
PARAM_PROLOGUE; PARAM_PROLOGUE;
PARAM_INT(arrayno); PARAM_INT(arrayno);
PARAM_INT(index); PARAM_INT(index);
ACTION_RETURN_STRING(FBehavior::StaticLookupString(ACS_GlobalArrays[arrayno][index])); ACTION_RETURN_STRING(level.Behaviors.LookupString(ACS_GlobalArrays[arrayno][index]));
} }
static int GetGlobalACSValue(int index) static int GetGlobalACSValue(int index)

View File

@ -62,7 +62,7 @@ void ScriptUtil::BuildParameters(va_list ap)
break; break;
case ACSClass: case ACSClass:
parameters.Push(VMValue(PClass::FindActor(FBehavior::StaticLookupString(va_arg(ap, int))))); parameters.Push(VMValue(PClass::FindActor(level.Behaviors.LookupString(va_arg(ap, int)))));
break; break;
} }
} }