Skip to content

Commit

Permalink
- started building the framework to replace the global level variable
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
coelckers committed Jan 10, 2019
1 parent 5cd3f86 commit f25397b
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 13 deletions.
22 changes: 20 additions & 2 deletions src/g_level.cpp
Expand Up @@ -168,6 +168,21 @@ void *statcopy; // for statistics driver

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;

//==========================================================================
//
Expand Down Expand Up @@ -1486,6 +1501,11 @@ int G_FinishTravel ()

void FLevelLocals::InitLevelLocals ()
{
info = FindLevelInfo(MapName);

// Session data should be moved out of here later!
currentSession->F1Pic = info->F1Pic;

P_InitParticles(this);
P_ClearParticles(this);
BaseBlendA = 0.0f; // Remove underwater blend effect, if any
Expand All @@ -1499,7 +1519,6 @@ void FLevelLocals::InitLevelLocals ()
freeze = false;
changefreeze = false;

info = FindLevelInfo (MapName);

skyspeed1 = info->skyspeed1;
skyspeed2 = info->skyspeed2;
Expand Down Expand Up @@ -1549,7 +1568,6 @@ void FLevelLocals::InitLevelLocals ()
LevelName = info->LookupLevelName();
NextMap = info->NextMap;
NextSecretMap = info->NextSecretMap;
F1Pic = info->F1Pic;
hazardcolor = info->hazardcolor;
hazardflash = info->hazardflash;

Expand Down
11 changes: 10 additions & 1 deletion src/g_levellocals.h
Expand Up @@ -178,7 +178,6 @@ struct FLevelLocals : public FLevelData
FString MapName; // the lump name (E1M1, MAP01, etc)
FString NextMap; // go here when using the regular exit
FString NextSecretMap; // map to go to when used secret exit
FString F1Pic;
EMapType maptype;


Expand Down Expand Up @@ -297,6 +296,16 @@ struct FLevelLocals : public FLevelData
}
};


class FGameSession
{
public:
TArray<FLevelLocals *> Levelinfo;
FString F1Pic;
};

extern FGameSession *currentSession;

#ifndef NO_DEFINE_LEVEL

extern FLevelLocals level;
Expand Down
2 changes: 1 addition & 1 deletion src/g_mapinfo.cpp
Expand Up @@ -2285,7 +2285,7 @@ static void ClearMapinfo()
DefaultSkill = -1;
DeinitIntermissions();
level.info = NULL;
level.F1Pic = "";
currentSession->F1Pic = "";
}

//==========================================================================
Expand Down
17 changes: 17 additions & 0 deletions src/scripting/backend/codegen.cpp
Expand Up @@ -6275,6 +6275,23 @@ FxExpression *FxIdentifier::ResolveMember(FCompileContext &ctx, PContainerType *
}
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());
delete object;
object = nullptr;
Expand Down
7 changes: 6 additions & 1 deletion src/scripting/vmthunks.cpp
Expand Up @@ -2724,7 +2724,6 @@ DEFINE_FIELD(FLevelLocals, LevelName)
DEFINE_FIELD(FLevelLocals, MapName)
DEFINE_FIELD(FLevelLocals, NextMap)
DEFINE_FIELD(FLevelLocals, NextSecretMap)
DEFINE_FIELD(FLevelLocals, F1Pic)
DEFINE_FIELD(FLevelLocals, maptype)
DEFINE_FIELD(FLevelLocals, Music)
DEFINE_FIELD(FLevelLocals, musicorder)
Expand Down Expand Up @@ -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, 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, ceilingplane)
DEFINE_FIELD_X(Sector, sector_t, Colormap)
Expand Down Expand Up @@ -2868,3 +2871,5 @@ DEFINE_FIELD(DBaseStatusBar, Level);
DEFINE_FIELD(DHUDFont, mFont);

DEFINE_GLOBAL(StatusBar);

DEFINE_FIELD(DThinker, Level);
22 changes: 19 additions & 3 deletions wadsrc/static/zscript/base.txt
Expand Up @@ -44,6 +44,7 @@ struct _ native // These are the global variables, the struct is only here to av
native ui BaseStatusBar StatusBar;
native readonly Weapon WP_NOCHANGE;
native int LocalViewPitch;
native GameSession currentSession;

}

Expand Down Expand Up @@ -92,7 +93,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)
{
level.ReplaceTextures(from, to, flags);
currentSession.LevelInfo[0].ReplaceTextures(from, to, flags);
}
native static String GetName(TextureID tex);
native static int, int GetSize(TextureID tex);
Expand Down Expand Up @@ -463,6 +464,8 @@ class Thinker : Object native play

const TICRATE = 35;

native readonly LevelLocals Level;

virtual native void Tick();
virtual native void PostBeginPlay();
native void ChangeStatNum(int stat);
Expand All @@ -485,7 +488,7 @@ class ActorIterator : Object native
{
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 void Reinit();
Expand Down Expand Up @@ -618,6 +621,13 @@ struct DropItem native
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
{
enum EUDMF
Expand All @@ -630,6 +640,13 @@ struct LevelLocals native

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<@Line> Lines;
Expand All @@ -650,7 +667,6 @@ struct LevelLocals native
native readonly String MapName;
native String NextMap;
native String NextSecretMap;
deprecated("3.8") native readonly String F1Pic;
native readonly int maptype;
deprecated("3.8") native readonly String Music;
deprecated("3.8") native readonly int musicorder;
Expand Down
2 changes: 1 addition & 1 deletion wadsrc/static/zscript/menu/conversationmenu.txt
Expand Up @@ -509,7 +509,7 @@ class ConversationMenu : Menu
override void Ticker()
{
// [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;
}
Expand Down
14 changes: 11 additions & 3 deletions wadsrc/static/zscript/menu/readthis.txt
Expand Up @@ -37,6 +37,7 @@ class ReadThisMenu : GenericMenu
{
int mScreen;
int mInfoTic;
TextureID F1Pic;

//=============================================================================
//
Expand All @@ -49,6 +50,13 @@ class ReadThisMenu : GenericMenu
Super.Init(parent);
mScreen = 1;
mInfoTic = gametic;

if (currentSession)
{
String F1 = currentSession.F1Pic;
if (F1.Length() > 0) F1Pic = TexMan.CheckForTexture(F1, TexMan.Type_MiscPatch);
}

}

override void Drawer()
Expand All @@ -57,9 +65,9 @@ class ReadThisMenu : GenericMenu
TextureID tex, prevpic;

// 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;
}

Expand Down Expand Up @@ -98,7 +106,7 @@ class ReadThisMenu : GenericMenu
MenuSound("menu/choose");
mScreen++;
mInfoTic = gametic;
if (level.F1Pic.Length() != 0 || mScreen > gameinfo.infoPages.Size())
if (F1Pic.IsValid() || mScreen > gameinfo.infoPages.Size())
{
Close();
}
Expand Down
2 changes: 1 addition & 1 deletion wadsrc/static/zscript/shared/player.txt
Expand Up @@ -2764,7 +2764,7 @@ struct PlayerInfo native play // self is what internally is known as player_t
return
gamestate == GS_TITLELEVEL ||
(cheats & CF_TOTALLYFROZEN) ||
(level.frozen && timefreezer == 0);
(mo.Level.frozen && timefreezer == 0);
}

void Uncrouch()
Expand Down

0 comments on commit f25397b

Please sign in to comment.