- added some compatibility glue for old scripts that reference the global 'globalfreeze' and 'level' variables.

This commit is contained in:
Christoph Oelckers 2019-01-12 14:29:13 +01:00
parent 1ab4ebb7ac
commit 36f79ea363
7 changed files with 36 additions and 16 deletions

View file

@ -89,8 +89,18 @@
#include "i_time.h"
#include "p_maputl.h"
// Compatibility glue to emulate removed features.
FLevelLocals emptyLevelPlaceholderForZScript;
FLevelLocals *levelForZScript = &emptyLevelPlaceholderForZScript;
bool globalfreeze;
DEFINE_GLOBAL(globalfreeze);
DEFINE_GLOBAL_NAMED(levelForZScript, level);
DEFINE_ACTION_FUNCTION(FGameSession, __GetCompatibilityLevel)
{
ACTION_RETURN_POINTER(levelForZScript);
}
void STAT_StartNewGame(TArray<OneLevel> &LevelData, const char *lev);
void STAT_ChangeLevel(TArray<OneLevel> &LevelData, const char *newl, FLevelLocals *Level);
@ -1021,6 +1031,7 @@ void G_DoLoadLevel (const FString &nextlevel, int position, bool autosave, bool
StatusBar->DetachAllMessages ();
currentSession->Levelinfo.DeleteAndClear();
levelForZScript = &emptyLevelPlaceholderForZScript;
GC::FullGC(); // really get rid of all the data we just deleted.
// Force 'teamplay' to 'true' if need be.
@ -1072,6 +1083,8 @@ void G_DoLoadLevel (const FString &nextlevel, int position, bool autosave, bool
{
FLevelLocals *Level = new FLevelLocals;
auto pos = currentSession->Levelinfo.Push(Level);
if (pos == 0) levelForZScript = currentSession->Levelinfo[0];
Level->InitLevelLocals (linfo, pos == 0);
if (changeflags & CHANGELEVEL_NOMONSTERS)

View file

@ -382,6 +382,9 @@ struct OneLevel
};
extern FLevelLocals emptyLevelPlaceholderForZScript;
extern FLevelLocals *levelForZScript;
class FGameSession
{
public:
@ -412,6 +415,7 @@ public:
void Reset()
{
levelForZScript = &emptyLevelPlaceholderForZScript;
Levelinfo.DeleteAndClear();
ClearSnapshots();
DeferredScripts.Clear();

View file

@ -587,7 +587,7 @@ class Actor : Thinker native
native void ChangeTid(int newtid);
deprecated("3.8") static int FindUniqueTid(int start = 0, int limit = 0)
{
return currentSession.LevelInfo[0].FindUniqueTid(start, limit);
return currentSession.__GetCompatibilityLevel().FindUniqueTid(start, limit);
}
native void SetShade(color col);
native clearscope int GetRenderStyle() const;
@ -644,7 +644,7 @@ class Actor : Thinker native
// Since this depends on the global level variable it should not be used any longer because this may block compatibility with future features.
deprecated("3.8") static Actor Spawn(class<Actor> type, vector3 pos = (0,0,0), int replace = NO_REPLACE)
{
return currentSession.LevelInfo[0].Spawn(type, pos, replace);
return currentSession.__GetCompatibilityLevel().Spawn(type, pos, replace);
}
// Helper so that not all old code needs to be changed for the above deprecation.

View file

@ -45,7 +45,8 @@ struct _ native // These are the global variables, the struct is only here to av
native int LocalViewPitch;
native GameSession currentSession;
//native play @LevelLocals level;
// These are deprecated because they can no longer reference valid state in all situations.
deprecated("3.8") native play LevelLocals level;
deprecated("3.8") native readonly bool globalfreeze;
}
@ -95,7 +96,7 @@ struct TexMan
native static TextureID CheckForTexture(String name, int usetype, int flags = TryAny);
deprecated("3.8") static void ReplaceTextures(String from, String to, int flags)
{
currentSession.LevelInfo[0].ReplaceTextures(from, to, flags);
currentSession.__GetCompatibilityLevel().ReplaceTextures(from, to, flags);
}
native static String GetName(TextureID tex);
native static int, int GetSize(TextureID tex);
@ -483,7 +484,7 @@ class ThinkerIterator : Object native
{
deprecated("3.8") static ThinkerIterator Create(class<Object> type = "Actor", int statnum=Thinker.MAX_STATNUM+1)
{
return currentSession.LevelInfo[0].CreateThinkerIterator(type, statnum);
return currentSession.__GetCompatibilityLevel().CreateThinkerIterator(type, statnum);
}
native Thinker Next(bool exact = false);
native void Reinit();
@ -493,7 +494,7 @@ class ActorIterator : Object native
{
deprecated("3.8") static ActorIterator Create(int tid, class<Actor> type = "Actor")
{
return currentSession.LevelInfo[0].CreateActorIterator(tid, type);
return currentSession.__GetCompatibilityLevel().CreateActorIterator(tid, type);
}
native Actor Next();
native void Reinit();
@ -511,7 +512,7 @@ class BlockThingsIterator : Object native
// Since this has no good means to deduce the level from its parameters it should not be used any longer because this may block compatibility with future features.
deprecated("3.8") static BlockThingsIterator CreateFromPos(double checkx, double checky, double checkz, double checkh, double checkradius, bool ignorerestricted)
{
return CreateFromPosition(currentSession.LevelInfo[0], checkx, checky, checkz, checkh, checkradius, ignorerestricted);
return CreateFromPosition(currentSession.__GetCompatibilityLevel(), checkx, checky, checkz, checkh, checkradius, ignorerestricted);
}
native bool Next();
}
@ -528,7 +529,7 @@ class BlockLinesIterator : Object native
// Since this has no good means to deduce the level from its parameters it should not be used any longer because this may block compatibility with future features.
deprecated("3.8") static BlockLinesIterator CreateFromPos(Vector3 pos, double checkh, double checkradius, Sector sec = null)
{
return CreateFromPosition(currentSession.LevelInfo[0], pos, checkh, checkradius, sec);
return CreateFromPosition(currentSession.__GetCompatibilityLevel(), pos, checkh, checkradius, sec);
}
native bool Next();
}
@ -638,6 +639,8 @@ struct GameSession native
native bool isFrozen();
native void setFrozen(bool on);
//IMPORTANT: This function MUST NOT(!!!) be used by user code. It cannot be deprecated because internal code needs it to implement deprecated fallbacks.
native LevelLocals __GetCompatibilityLevel();
}
@ -656,15 +659,15 @@ struct LevelLocals native
// Do not even THINK about using these functions directly, or else... >)
deprecated("3.8") static String __getter__F1Pic__()
{
return currentSession? currentSession.F1Pic : "";
return currentSession.F1Pic;
}
deprecated("3.8") static int __getter__time__()
{
return currentSession? currentSession.time : 0;
return currentSession.time;
}
deprecated("3.8") static int __getter__totaltime__()
{
return currentSession? currentSession.totaltime : 0;
return currentSession.totaltime;
}

View file

@ -2,7 +2,7 @@ struct HealthGroup native play
{
deprecated("3.8") static clearscope HealthGroup Find(int id)
{
return currentSession.LevelInfo[0].FindHealthGroup(id);
return currentSession.__GetCompatibilityLevel().FindHealthGroup(id);
}
readonly int id;

View file

@ -373,7 +373,7 @@ struct Sector native play
native void RemoveForceField();
deprecated("3.8") static clearscope Sector PointInSector(Vector2 pt)
{
return currentSession.LevelInfo[0].PointInSector(pt);
return currentSession.__GetCompatibilityLevel().PointInSector(pt);
}
native bool PlaneMoving(int pos);
@ -537,7 +537,7 @@ class SectorTagIterator : Object native
{
deprecated("3.8") static SectorTagIterator Create(int tag, line defline = null)
{
return currentSession.LevelInfo[0].CreateSectorTagIterator(tag, defline);
return currentSession.__GetCompatibilityLevel().CreateSectorTagIterator(tag, defline);
}
native int Next();
native int NextCompat(bool compat, int secnum);
@ -547,7 +547,7 @@ class LineIdIterator : Object native
{
deprecated("3.8") static LineIdIterator Create(int tag)
{
return currentSession.LevelInfo[0].CreateLineIdIterator(tag);
return currentSession.__GetCompatibilityLevel().CreateLineIdIterator(tag);
}
native int Next();
}

View file

@ -2,7 +2,7 @@ class SpotState : Object native
{
deprecated ("3.8") static SpotState GetSpotState(bool create = true)
{
return currentSession.LevelInfo[0].GetSpotState(create);
return currentSession.__GetCompatibilityLevel().GetSpotState(create);
}
native SpecialSpot GetNextInList(class<Actor> type, int skipcounter);
native SpecialSpot GetSpotWithMinMaxDistance(Class<Actor> type, double x, double y, double mindist, double maxdist);