- moved the global spot state into FLevelLocals.

This way it doesn't even have to be a thinker.
This commit is contained in:
Christoph Oelckers 2019-01-05 10:04:27 +01:00
parent 7b16433e97
commit dab68184f5
14 changed files with 39 additions and 44 deletions

View File

@ -1968,6 +1968,7 @@ void FLevelLocals::Tick ()
void FLevelLocals::Mark()
{
GC::Mark(SpotState);
GC::Mark(FraggleScriptThinker);
canvasTextureInfo.Mark();
for (auto &s : sectorPortals)

View File

@ -48,6 +48,7 @@
#include "r_data/r_canvastexture.h"
class DFraggleThinker;
class DSpotState;
struct FLevelData
{
@ -202,7 +203,9 @@ struct FLevelLocals : public FLevelData
FDynamicLight *lights;
// links to global game objects
TObjPtr<DFraggleThinker *> FraggleScriptThinker;
TArray<TObjPtr<AActor *>> CorpseQueue;
TObjPtr<DFraggleThinker *> FraggleScriptThinker = nullptr;
TObjPtr<DSpotState *> SpotState = nullptr;
bool IsJumpingAllowed() const;
bool IsCrouchingAllowed() const;

View File

@ -42,7 +42,6 @@
static FRandom pr_spot ("SpecialSpot");
IMPLEMENT_CLASS(DSpotState, false, false)
TObjPtr<DSpotState*> DSpotState::SpotState;
//----------------------------------------------------------------------------
//
@ -198,16 +197,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, FSpotList &list, FSpot
//----------------------------------------------------------------------------
DSpotState::DSpotState ()
: DThinker (STAT_INFO)
{
if (SpotState)
{
I_Error ("Only one SpotState is allowed to exist at a time.\nCheck your code.");
}
else
{
SpotState = this;
}
}
//----------------------------------------------------------------------------
@ -219,8 +209,6 @@ DSpotState::DSpotState ()
void DSpotState::OnDestroy ()
{
SpotLists.Reset();
SpotState = NULL;
Super::OnDestroy();
}
@ -240,18 +228,6 @@ void DSpotState::Tick ()
//
//----------------------------------------------------------------------------
DSpotState *DSpotState::GetSpotState(bool create)
{
if (SpotState == NULL && create) SpotState = Create<DSpotState>();
return SpotState;
}
//----------------------------------------------------------------------------
//
//
//
//----------------------------------------------------------------------------
FSpotList *DSpotState::FindSpotList(PClassActor *type)
{
if (type == nullptr) return nullptr;

View File

@ -7,10 +7,9 @@
struct FSpotList;
class DSpotState : public DThinker
class DSpotState : public DObject
{
DECLARE_CLASS(DSpotState, DThinker)
static TObjPtr<DSpotState*> SpotState;
DECLARE_CLASS(DSpotState, DObject)
TArray<FSpotList> SpotLists;
public:

View File

@ -2981,6 +2981,8 @@ enum T_Flags
TF_SENSITIVEZ = 0x00000800, // Fail if the actor wouldn't fit in the position (for Z).
};
DSpotState *GetSpotState(FLevelLocals *self, int create);
DEFINE_ACTION_FUNCTION(AActor, A_Teleport)
{
PARAM_ACTION_PROLOGUE(AActor);
@ -3037,7 +3039,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_Teleport)
}
}
DSpotState *state = DSpotState::GetSpotState();
DSpotState *state = GetSpotState(&level, false);
if (state == NULL)
{
return numret;

View File

@ -976,6 +976,7 @@ void G_SerializeLevel(FSerializer &arc, bool hubload)
("level.bodyqueslot", level.bodyqueslot)
("level.spawnindex", level.spawnindex)
.Array("level.bodyque", level.bodyque, level.BODYQUESIZE)
("level.spotstate", level.SpotState)
("level.fragglethinker", level.FraggleScriptThinker);
// Hub transitions must keep the current total time

View File

@ -69,6 +69,7 @@
#include "i_time.h"
#include "scripting/vm/vm.h"
#include "fragglescript/t_fs.h"
#include "a_specialspot.h"
#include "maploader/maploader.h"
void P_ClearUDMFKeys();
@ -273,6 +274,7 @@ void FLevelLocals::ClearLevelData()
}
ClearPortals();
SpotState = nullptr;
canvasTextureInfo.EmptyList();
sections.Clear();
segs.Clear();

View File

@ -1957,13 +1957,6 @@ DEFINE_ACTION_FUNCTION_NATIVE(FWeaponSlots, SetupWeaponSlots, FWeaponSlots::Setu
//=====================================================================================
DEFINE_ACTION_FUNCTION_NATIVE(DSpotState, GetSpotState, DSpotState::GetSpotState)
{
PARAM_PROLOGUE;
PARAM_BOOL(create);
ACTION_RETURN_OBJECT(DSpotState::GetSpotState(create));
}
static void AddSpot(DSpotState *state, AActor *spot)
{
state->AddSpot(spot);
@ -2506,6 +2499,20 @@ DEFINE_ACTION_FUNCTION_NATIVE(DHUDFont, Create, CreateHudFont)
//
//=====================================================================================
DSpotState *GetSpotState(FLevelLocals *self, int create)
{
if (create && self->SpotState == nullptr) self->SpotState = Create<DSpotState>();
GC::WriteBarrier(self->SpotState);
return self->SpotState;
}
DEFINE_ACTION_FUNCTION_NATIVE(FLevelLocals, GetSpotState, GetSpotState)
{
PARAM_SELF_STRUCT_PROLOGUE(FLevelLocals);
PARAM_INT(create);
ACTION_RETURN_POINTER(GetSpotState(self, create));
}
static void FormatMapName(FLevelLocals *self, int cr, FString *result)
{
char mapnamecolor[3] = { '\34', char(cr + 'A'), 0 };

View File

@ -1,4 +1,4 @@
version "3.7"
version "3.8"
#include "zscript/base.txt"
#include "zscript/sounddata.txt"
#include "zscript/mapdata.txt"

View File

@ -687,6 +687,7 @@ struct LevelLocals native
native bool IsCrouchingAllowed() const;
native bool IsFreelookAllowed() const;
native void StartIntermission(Name type, int state) const;
native SpotState GetSpotState(bool create = true);
native static clearscope bool IsPointInMap(vector3 p);

View File

@ -219,7 +219,7 @@ extend class Actor
void A_BrainSpit(class<Actor> spawntype = null)
{
SpotState spstate = SpotState.GetSpotState();
SpotState spstate = Level.GetSpotState();
Actor targ;
Actor spit;
bool isdefault = false;

View File

@ -293,7 +293,7 @@ class Sorcerer2 : Actor
void DSparilTeleport ()
{
SpotState state = SpotState.GetSpotState();
SpotState state = Level.GetSpotState();
if (state == null) return;
Actor spot = state.GetSpotWithMinMaxDistance("BossSpot", pos.x, pos.y, 128, 0);

View File

@ -265,7 +265,7 @@ class Inventory : Actor
if (SpawnPointClass != NULL)
{
Actor spot = NULL;
let state = SpotState.GetSpotState();
let state = Level.GetSpotState();
if (state != NULL) spot = state.GetRandomSpot(SpawnPointClass, false);
if (spot != NULL)

View File

@ -1,6 +1,9 @@
class SpotState : Object native
{
native static SpotState GetSpotState(bool create = true);
deprecated ("3.8") static SpotState GetSpotState(bool create = true)
{
return level.GetSpotState(create);
}
native SpecialSpot GetNextInList(class<Actor> type, int skipcounter);
native SpecialSpot GetSpotWithMinMaxDistance(Class<Actor> type, double x, double y, double mindist, double maxdist);
native SpecialSpot GetRandomSpot(class<Actor> type, bool onlyonce);
@ -13,7 +16,7 @@ class SpecialSpot : Actor
{
override void BeginPlay()
{
let sstate = SpotState.GetSpotState();
let sstate = Level.GetSpotState();
if (sstate != NULL) sstate.AddSpot(self);
Super.BeginPlay();
}
@ -26,7 +29,7 @@ class SpecialSpot : Actor
override void OnDestroy()
{
let sstate = SpotState.GetSpotState(false);
let sstate = Level.GetSpotState(false);
if (sstate != NULL) sstate.RemoveSpot(self);
Super.OnDestroy();
}
@ -40,7 +43,7 @@ class SpecialSpot : Actor
void A_SpawnSingleItem(class<Actor> cls, int fail_sp = 0, int fail_co = 0, int fail_dm = 0)
{
Actor spot = NULL;
let state = SpotState.GetSpotState();
let state = Level.GetSpotState();
if (state != NULL) spot = state.GetRandomSpot(GetClass(), true);
if (spot == NULL) return;