mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-10 23:01:50 +00:00
- moved the per-level ACS state into FLevelLocals.
This commit is contained in:
parent
131eef9eb9
commit
7b235ea13e
18 changed files with 213 additions and 206 deletions
|
@ -92,6 +92,7 @@ Everything that is changed is marked (maybe commented) with "Added by MC"
|
|||
#include "d_player.h"
|
||||
#include "events.h"
|
||||
#include "vm.h"
|
||||
#include "g_levellocals.h"
|
||||
|
||||
static FRandom pr_botspawn ("BotSpawn");
|
||||
|
||||
|
@ -447,7 +448,7 @@ void FCajunMaster::RemoveAllBots (bool fromlist)
|
|||
// [ZZ] run event hook
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1682,11 +1682,11 @@ void G_DoPlayerPop(int playernum)
|
|||
}
|
||||
|
||||
// [RH] Make the player disappear
|
||||
FBehavior::StaticStopMyScripts(players[playernum].mo);
|
||||
level.Behaviors.StopMyScripts(players[playernum].mo);
|
||||
// [ZZ] fire player disconnect hook
|
||||
E_PlayerDisconnected(playernum);
|
||||
// [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)
|
||||
{
|
||||
P_DisconnectEffect(players[playernum].mo);
|
||||
|
|
|
@ -641,7 +641,7 @@ void G_ChangeLevel(const char *levelname, int position, int flags, int nextSkill
|
|||
|
||||
// [RH] Give scripts a chance to do something
|
||||
unloading = true;
|
||||
FBehavior::StaticStartTypedScripts (SCRIPT_Unloading, NULL, false, 0, true);
|
||||
level.Behaviors.StartTypedScripts (SCRIPT_Unloading, NULL, false, 0, true);
|
||||
// [ZZ] safe world unload
|
||||
E_WorldUnloaded();
|
||||
// [ZZ] unsafe world unload (changemap != map)
|
||||
|
@ -854,7 +854,7 @@ void G_DoCompleted (void)
|
|||
G_SnapshotLevel ();
|
||||
// Do not free any global strings this level might reference
|
||||
// while it's not loaded.
|
||||
FBehavior::StaticLockLevelVarStrings();
|
||||
level.Behaviors.LockLevelVarStrings();
|
||||
}
|
||||
else
|
||||
{ // 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)
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
// [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]);
|
||||
|
@ -1718,7 +1718,7 @@ void G_UnSnapshotLevel (bool hubLoad)
|
|||
if (hubLoad)
|
||||
{
|
||||
// Unlock ACS global strings that were locked when the snapshot was made.
|
||||
FBehavior::StaticUnlockLevelVarStrings();
|
||||
level.Behaviors.UnlockLevelVarStrings();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include "p_blockmap.h"
|
||||
#include "p_local.h"
|
||||
#include "po_man.h"
|
||||
#include "p_acs.h"
|
||||
#include "p_destructible.h"
|
||||
#include "r_data/r_sections.h"
|
||||
#include "r_data/r_canvastexture.h"
|
||||
|
@ -98,6 +99,7 @@ struct FLevelData
|
|||
FPlayerStart playerstarts[MAXPLAYERS];
|
||||
TArray<FPlayerStart> AllPlayerStarts;
|
||||
|
||||
FBehaviorContainer Behaviors;
|
||||
};
|
||||
|
||||
struct FLevelLocals : public FLevelData
|
||||
|
|
|
@ -157,7 +157,7 @@ void DLightningThinker::LightningFlash ()
|
|||
// [ZZ] just in case
|
||||
E_WorldLightning();
|
||||
// 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
|
||||
if (!NextLightningFlash)
|
||||
|
|
|
@ -904,7 +904,7 @@ class CommandDrawString : public SBarInfoCommand
|
|||
if(ACS_GlobalVars[valueArgument] != cache)
|
||||
{
|
||||
cache = ACS_GlobalVars[valueArgument];
|
||||
str = FBehavior::StaticLookupString(ACS_GlobalVars[valueArgument]);
|
||||
str = level.Behaviors.LookupString(ACS_GlobalVars[valueArgument]);
|
||||
RealignString();
|
||||
}
|
||||
break;
|
||||
|
@ -912,7 +912,7 @@ class CommandDrawString : public SBarInfoCommand
|
|||
if(ACS_GlobalArrays[valueArgument][consoleplayer] != cache)
|
||||
{
|
||||
cache = ACS_GlobalArrays[valueArgument][consoleplayer];
|
||||
str = FBehavior::StaticLookupString(ACS_GlobalArrays[valueArgument][consoleplayer]);
|
||||
str = level.Behaviors.LookupString(ACS_GlobalArrays[valueArgument][consoleplayer]);
|
||||
RealignString();
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -660,6 +660,6 @@ void MapLoader::LoadMapinfoACSLump()
|
|||
if (Level->info->acsName.IsNotEmpty())
|
||||
{
|
||||
int lump = Wads.CheckNumForName(Level->info->acsName);
|
||||
if (lump >= 0) FBehavior::StaticLoadModule(lump);
|
||||
if (lump >= 0) Level->Behaviors.LoadModule(lump);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2825,12 +2825,12 @@ void MapLoader::LoadBehavior(MapData * map)
|
|||
{
|
||||
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");
|
||||
FBehavior::StaticUnloadModules();
|
||||
Level->Behaviors.UnloadModules();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2881,7 +2881,7 @@ void MapLoader::LoadLevel(MapData *map, const char *lumpname, int position)
|
|||
ForceNodeBuild = gennodes;
|
||||
|
||||
// [RH] Load in the BEHAVIOR lump
|
||||
FBehavior::StaticUnloadModules();
|
||||
Level->Behaviors.UnloadModules();
|
||||
if (map->HasBehavior)
|
||||
{
|
||||
LoadBehavior(map);
|
||||
|
@ -2941,7 +2941,7 @@ void MapLoader::LoadLevel(MapData *map, const char *lumpname, int position)
|
|||
Level->flags2 |= LEVEL2_DUMMYSWITCHES;
|
||||
}
|
||||
|
||||
FBehavior::StaticLoadDefaultModules();
|
||||
Level->Behaviors.LoadDefaultModules();
|
||||
LoadMapinfoACSLump();
|
||||
|
||||
|
||||
|
@ -3174,7 +3174,7 @@ void MapLoader::LoadLevel(MapData *map, const char *lumpname, int position)
|
|||
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.
|
||||
screen->mVertexData->CreateVBO();
|
||||
|
||||
|
|
307
src/p_acs.cpp
307
src/p_acs.cpp
File diff suppressed because it is too large
Load diff
41
src/p_acs.h
41
src/p_acs.h
|
@ -344,6 +344,7 @@ enum
|
|||
|
||||
enum ACSFormat { ACS_Old, ACS_Enhanced, ACS_LittleEnhanced, ACS_Unknown };
|
||||
|
||||
|
||||
class FBehavior
|
||||
{
|
||||
public:
|
||||
|
@ -381,20 +382,6 @@ public:
|
|||
|
||||
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:
|
||||
struct ArrayInfo;
|
||||
|
@ -421,8 +408,6 @@ private:
|
|||
char ModuleName[9];
|
||||
TArray<int> JumpPoints;
|
||||
|
||||
static TArray<FBehavior *> StaticModules;
|
||||
|
||||
void LoadScriptsDirectory ();
|
||||
|
||||
static int SortScripts (const void *a, const void *b);
|
||||
|
@ -439,6 +424,30 @@ private:
|
|||
|
||||
friend void ArrangeScriptProfiles(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__
|
||||
|
|
|
@ -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.
|
||||
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);
|
||||
|
@ -563,7 +563,7 @@ void AActor::Die (AActor *source, AActor *inflictor, int dmgflags, FName MeansOf
|
|||
E_PlayerDied(int(player - players));
|
||||
|
||||
// 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
|
||||
player->respawn_time = level.time + TICRATE;
|
||||
|
|
|
@ -5018,7 +5018,7 @@ AActor *P_SpawnPlayer (FPlayerStart *mthing, int playernum, int flags)
|
|||
VMValue params[] = { mobj, oldactor };
|
||||
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
|
||||
|
@ -5147,7 +5147,7 @@ AActor *P_SpawnPlayer (FPlayerStart *mthing, int playernum, int flags)
|
|||
{
|
||||
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)
|
||||
{
|
||||
|
@ -5171,7 +5171,7 @@ AActor *P_SpawnPlayer (FPlayerStart *mthing, int playernum, int flags)
|
|||
DObject::StaticPointerSubstitution (oldactor, p->mo);
|
||||
|
||||
E_PlayerRespawned(int(p - players));
|
||||
FBehavior::StaticStartTypedScripts (SCRIPT_Respawn, p->mo, true);
|
||||
level.Behaviors.StartTypedScripts (SCRIPT_Respawn, p->mo, true);
|
||||
}
|
||||
}
|
||||
return mobj;
|
||||
|
|
|
@ -992,11 +992,7 @@ void G_SerializeLevel(FSerializer &arc, bool hubload)
|
|||
G_AirControlChanged();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 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);
|
||||
level.Behaviors.SerializeModuleStates(arc);
|
||||
// The order here is important: First world state, then portal state, then thinkers, and last polyobjects.
|
||||
arc("linedefs", level.lines, level.loadlines);
|
||||
arc("sidedefs", level.sides, level.loadsides);
|
||||
|
|
|
@ -340,7 +340,7 @@ void P_FreeLevelData ()
|
|||
DThinker::DestroyAllThinkers ();
|
||||
tagManager.Clear();
|
||||
|
||||
FBehavior::StaticUnloadModules ();
|
||||
level.Behaviors.UnloadModules ();
|
||||
|
||||
P_FreeStrifeConversations ();
|
||||
level.ClearLevelData();
|
||||
|
|
|
@ -1505,7 +1505,7 @@ void P_SpawnSpecials (MapLoader *ml)
|
|||
}
|
||||
}
|
||||
// [RH] Start running any open scripts on this map
|
||||
FBehavior::StaticStartTypedScripts (SCRIPT_Open, NULL, false);
|
||||
level.Behaviors.StartTypedScripts (SCRIPT_Open, NULL, false);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -693,7 +693,7 @@ bool player_t::Resurrect()
|
|||
// fire E_PlayerRespawned and start the ACS SCRIPT_Respawn.
|
||||
E_PlayerRespawned(int(this - players));
|
||||
//
|
||||
FBehavior::StaticStartTypedScripts(SCRIPT_Respawn, mo, true);
|
||||
level.Behaviors.StartTypedScripts(SCRIPT_Respawn, mo, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -2368,19 +2368,19 @@ DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, SetClipRect, SBar_SetClipRect)
|
|||
|
||||
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)
|
||||
{
|
||||
PARAM_PROLOGUE;
|
||||
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)
|
||||
{
|
||||
*result = FBehavior::StaticLookupString(ACS_GlobalVars[index]);
|
||||
*result = level.Behaviors.LookupString(ACS_GlobalVars[index]);
|
||||
}
|
||||
|
||||
DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, GetGlobalACSArrayString, GetGlobalACSArrayString)
|
||||
|
@ -2388,7 +2388,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(DBaseStatusBar, GetGlobalACSArrayString, GetGlobal
|
|||
PARAM_PROLOGUE;
|
||||
PARAM_INT(arrayno);
|
||||
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)
|
||||
|
|
|
@ -62,7 +62,7 @@ void ScriptUtil::BuildParameters(va_list ap)
|
|||
break;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue