- started building the framework to replace the global level variable

A few of the old level members will also be moved to the new class, now that workaround getters can be implemented.
These currently spit out some deprecation warnings which will be addressed next.
This commit is contained in:
Christoph Oelckers 2019-01-10 19:46:51 +01:00
parent 5cd3f86775
commit f25397b391
9 changed files with 86 additions and 13 deletions

View file

@ -168,6 +168,21 @@ void *statcopy; // for statistics driver
FLevelLocals level; // info about current level FLevelLocals level; // info about current level
FGameSession *currentSession;
// Temporary placeholder to initialize the data until it can be done properly.
class HackyInitializer
{
FGameSession session;
public:
HackyInitializer()
{
session.Levelinfo.Push(&level);
currentSession = &session;
}
};
HackyInitializer hackyinit;
//========================================================================== //==========================================================================
// //
@ -1486,6 +1501,11 @@ int G_FinishTravel ()
void FLevelLocals::InitLevelLocals () void FLevelLocals::InitLevelLocals ()
{ {
info = FindLevelInfo(MapName);
// Session data should be moved out of here later!
currentSession->F1Pic = info->F1Pic;
P_InitParticles(this); P_InitParticles(this);
P_ClearParticles(this); P_ClearParticles(this);
BaseBlendA = 0.0f; // Remove underwater blend effect, if any BaseBlendA = 0.0f; // Remove underwater blend effect, if any
@ -1499,7 +1519,6 @@ void FLevelLocals::InitLevelLocals ()
freeze = false; freeze = false;
changefreeze = false; changefreeze = false;
info = FindLevelInfo (MapName);
skyspeed1 = info->skyspeed1; skyspeed1 = info->skyspeed1;
skyspeed2 = info->skyspeed2; skyspeed2 = info->skyspeed2;
@ -1549,7 +1568,6 @@ void FLevelLocals::InitLevelLocals ()
LevelName = info->LookupLevelName(); LevelName = info->LookupLevelName();
NextMap = info->NextMap; NextMap = info->NextMap;
NextSecretMap = info->NextSecretMap; NextSecretMap = info->NextSecretMap;
F1Pic = info->F1Pic;
hazardcolor = info->hazardcolor; hazardcolor = info->hazardcolor;
hazardflash = info->hazardflash; hazardflash = info->hazardflash;

View file

@ -178,7 +178,6 @@ struct FLevelLocals : public FLevelData
FString MapName; // the lump name (E1M1, MAP01, etc) FString MapName; // the lump name (E1M1, MAP01, etc)
FString NextMap; // go here when using the regular exit FString NextMap; // go here when using the regular exit
FString NextSecretMap; // map to go to when used secret exit FString NextSecretMap; // map to go to when used secret exit
FString F1Pic;
EMapType maptype; EMapType maptype;
@ -297,6 +296,16 @@ struct FLevelLocals : public FLevelData
} }
}; };
class FGameSession
{
public:
TArray<FLevelLocals *> Levelinfo;
FString F1Pic;
};
extern FGameSession *currentSession;
#ifndef NO_DEFINE_LEVEL #ifndef NO_DEFINE_LEVEL
extern FLevelLocals level; extern FLevelLocals level;

View file

@ -2285,7 +2285,7 @@ static void ClearMapinfo()
DefaultSkill = -1; DefaultSkill = -1;
DeinitIntermissions(); DeinitIntermissions();
level.info = NULL; level.info = NULL;
level.F1Pic = ""; currentSession->F1Pic = "";
} }
//========================================================================== //==========================================================================

View file

@ -6275,6 +6275,23 @@ FxExpression *FxIdentifier::ResolveMember(FCompileContext &ctx, PContainerType *
} }
else else
{ {
if (objtype != nullptr)
{
// Try to remap deprecated fields to getter functions.
FStringf getter("__getter__%s__", Identifier.GetChars());
FName gettername(getter, true);
if (gettername != NAME_None)
{
if ((sym = objtype->Symbols.FindSymbolInTable(gettername, symtbl)) != nullptr)
{
FxExpression *x = new FxMemberFunctionCall(object, gettername, FArgumentList(), ScriptPosition);
x = x->Resolve(ctx);
delete this;
return x;
}
}
}
ScriptPosition.Message(MSG_ERROR, "Unknown identifier '%s'", Identifier.GetChars()); ScriptPosition.Message(MSG_ERROR, "Unknown identifier '%s'", Identifier.GetChars());
delete object; delete object;
object = nullptr; object = nullptr;

View file

@ -2724,7 +2724,6 @@ DEFINE_FIELD(FLevelLocals, LevelName)
DEFINE_FIELD(FLevelLocals, MapName) DEFINE_FIELD(FLevelLocals, MapName)
DEFINE_FIELD(FLevelLocals, NextMap) DEFINE_FIELD(FLevelLocals, NextMap)
DEFINE_FIELD(FLevelLocals, NextSecretMap) DEFINE_FIELD(FLevelLocals, NextSecretMap)
DEFINE_FIELD(FLevelLocals, F1Pic)
DEFINE_FIELD(FLevelLocals, maptype) DEFINE_FIELD(FLevelLocals, maptype)
DEFINE_FIELD(FLevelLocals, Music) DEFINE_FIELD(FLevelLocals, Music)
DEFINE_FIELD(FLevelLocals, musicorder) DEFINE_FIELD(FLevelLocals, musicorder)
@ -2767,6 +2766,10 @@ DEFINE_FIELD_BIT(FLevelLocals, flags2, no_dlg_freeze, LEVEL2_CONV_SINGLE_UNFREEZ
DEFINE_FIELD_BIT(FLevelLocals, flags2, keepfullinventory, LEVEL2_KEEPFULLINVENTORY) DEFINE_FIELD_BIT(FLevelLocals, flags2, keepfullinventory, LEVEL2_KEEPFULLINVENTORY)
DEFINE_FIELD_BIT(FLevelLocals, flags3, removeitems, LEVEL3_REMOVEITEMS) DEFINE_FIELD_BIT(FLevelLocals, flags3, removeitems, LEVEL3_REMOVEITEMS)
DEFINE_FIELD(FGameSession, Levelinfo)
DEFINE_FIELD(FGameSession, F1Pic)
DEFINE_GLOBAL(currentSession)
DEFINE_FIELD_X(Sector, sector_t, floorplane) DEFINE_FIELD_X(Sector, sector_t, floorplane)
DEFINE_FIELD_X(Sector, sector_t, ceilingplane) DEFINE_FIELD_X(Sector, sector_t, ceilingplane)
DEFINE_FIELD_X(Sector, sector_t, Colormap) DEFINE_FIELD_X(Sector, sector_t, Colormap)
@ -2868,3 +2871,5 @@ DEFINE_FIELD(DBaseStatusBar, Level);
DEFINE_FIELD(DHUDFont, mFont); DEFINE_FIELD(DHUDFont, mFont);
DEFINE_GLOBAL(StatusBar); DEFINE_GLOBAL(StatusBar);
DEFINE_FIELD(DThinker, Level);

View file

@ -44,6 +44,7 @@ struct _ native // These are the global variables, the struct is only here to av
native ui BaseStatusBar StatusBar; native ui BaseStatusBar StatusBar;
native readonly Weapon WP_NOCHANGE; native readonly Weapon WP_NOCHANGE;
native int LocalViewPitch; native int LocalViewPitch;
native GameSession currentSession;
} }
@ -92,7 +93,7 @@ struct TexMan
native static TextureID CheckForTexture(String name, int usetype, int flags = TryAny); native static TextureID CheckForTexture(String name, int usetype, int flags = TryAny);
deprecated("3.8") static void ReplaceTextures(String from, String to, int flags) deprecated("3.8") static void ReplaceTextures(String from, String to, int flags)
{ {
level.ReplaceTextures(from, to, flags); currentSession.LevelInfo[0].ReplaceTextures(from, to, flags);
} }
native static String GetName(TextureID tex); native static String GetName(TextureID tex);
native static int, int GetSize(TextureID tex); native static int, int GetSize(TextureID tex);
@ -463,6 +464,8 @@ class Thinker : Object native play
const TICRATE = 35; const TICRATE = 35;
native readonly LevelLocals Level;
virtual native void Tick(); virtual native void Tick();
virtual native void PostBeginPlay(); virtual native void PostBeginPlay();
native void ChangeStatNum(int stat); native void ChangeStatNum(int stat);
@ -485,7 +488,7 @@ class ActorIterator : Object native
{ {
deprecated("3.8") static ActorIterator Create(int tid, class<Actor> type = "Actor") deprecated("3.8") static ActorIterator Create(int tid, class<Actor> type = "Actor")
{ {
return level.CreateActorIterator(tid, type); return currentSession.LevelInfo[0].CreateActorIterator(tid, type);
} }
native Actor Next(); native Actor Next();
native void Reinit(); native void Reinit();
@ -618,6 +621,13 @@ struct DropItem native
native readonly int Amount; native readonly int Amount;
} }
struct GameSession native
{
// all open levels. The first entry in this list is the primary one where gameplay takes place.
native Array<LevelLocals> LevelInfo;
native readonly String F1Pic;
}
struct LevelLocals native struct LevelLocals native
{ {
enum EUDMF enum EUDMF
@ -630,6 +640,13 @@ struct LevelLocals native
const CLUSTER_HUB = 0x00000001; // Cluster uses hub behavior const CLUSTER_HUB = 0x00000001; // Cluster uses hub behavior
// Do not even THINK about using these functions directly, or else... >)
deprecated("3.8") static String __getter__F1Pic__()
{
return currentSession? currentSession.F1Pic : "";
}
native Array<@Sector> Sectors; native Array<@Sector> Sectors;
native Array<@Line> Lines; native Array<@Line> Lines;
@ -650,7 +667,6 @@ struct LevelLocals native
native readonly String MapName; native readonly String MapName;
native String NextMap; native String NextMap;
native String NextSecretMap; native String NextSecretMap;
deprecated("3.8") native readonly String F1Pic;
native readonly int maptype; native readonly int maptype;
deprecated("3.8") native readonly String Music; deprecated("3.8") native readonly String Music;
deprecated("3.8") native readonly int musicorder; deprecated("3.8") native readonly int musicorder;

View file

@ -509,7 +509,7 @@ class ConversationMenu : Menu
override void Ticker() override void Ticker()
{ {
// [CW] Freeze the game depending on MAPINFO options. // [CW] Freeze the game depending on MAPINFO options.
if (ConversationPauseTic < gametic && !multiplayer && !level.no_dlg_freeze) if (ConversationPauseTic < gametic && !multiplayer && !mPlayer.mo.Level.no_dlg_freeze)
{ {
menuactive = Menu.On; menuactive = Menu.On;
} }

View file

@ -37,6 +37,7 @@ class ReadThisMenu : GenericMenu
{ {
int mScreen; int mScreen;
int mInfoTic; int mInfoTic;
TextureID F1Pic;
//============================================================================= //=============================================================================
// //
@ -49,6 +50,13 @@ class ReadThisMenu : GenericMenu
Super.Init(parent); Super.Init(parent);
mScreen = 1; mScreen = 1;
mInfoTic = gametic; mInfoTic = gametic;
if (currentSession)
{
String F1 = currentSession.F1Pic;
if (F1.Length() > 0) F1Pic = TexMan.CheckForTexture(F1, TexMan.Type_MiscPatch);
}
} }
override void Drawer() override void Drawer()
@ -57,9 +65,9 @@ class ReadThisMenu : GenericMenu
TextureID tex, prevpic; TextureID tex, prevpic;
// Did the mapper choose a custom help page via MAPINFO? // Did the mapper choose a custom help page via MAPINFO?
if (level.F1Pic.Length() != 0) if (F1Pic.IsValid())
{ {
tex = TexMan.CheckForTexture(level.F1Pic, TexMan.Type_MiscPatch); tex = F1Pic;
mScreen = 1; mScreen = 1;
} }
@ -98,7 +106,7 @@ class ReadThisMenu : GenericMenu
MenuSound("menu/choose"); MenuSound("menu/choose");
mScreen++; mScreen++;
mInfoTic = gametic; mInfoTic = gametic;
if (level.F1Pic.Length() != 0 || mScreen > gameinfo.infoPages.Size()) if (F1Pic.IsValid() || mScreen > gameinfo.infoPages.Size())
{ {
Close(); Close();
} }

View file

@ -2764,7 +2764,7 @@ struct PlayerInfo native play // self is what internally is known as player_t
return return
gamestate == GS_TITLELEVEL || gamestate == GS_TITLELEVEL ||
(cheats & CF_TOTALLYFROZEN) || (cheats & CF_TOTALLYFROZEN) ||
(level.frozen && timefreezer == 0); (mo.Level.frozen && timefreezer == 0);
} }
void Uncrouch() void Uncrouch()