- scriptified the SBARINFO wrapper.

This serves no purpose in itself but it removes a native side class from the status bar class hierarchy which allows for better editing options later.
This commit is contained in:
Christoph Oelckers 2017-03-22 17:29:13 +01:00
parent 04c2565d7f
commit 1423d5f42a
14 changed files with 232 additions and 152 deletions

View File

@ -409,7 +409,7 @@ void FCajunMaster::RemoveAllBots (bool fromlist)
players[j].camera = players[j].mo;
if (j == consoleplayer)
{
StatusBar->CallAttachToPlayer (players + j);
StatusBar->AttachToPlayer (players + j);
}
}
}

View File

@ -473,7 +473,7 @@ CUSTOM_CVAR (Int, dmflags2, 0, CVAR_SERVERINFO)
p->camera = p->mo;
S_UpdateSounds (p->camera);
StatusBar->CallAttachToPlayer (p);
StatusBar->AttachToPlayer (p);
if (demoplayback || multiplayer)
StatusBar->ShowPlayerName ();

View File

@ -342,7 +342,7 @@ static void UpdateTeam (int pnum, int team, bool update)
R_BuildPlayerTranslation (pnum);
if (StatusBar != NULL && StatusBar->GetPlayer() == pnum)
{
StatusBar->CallAttachToPlayer (&players[pnum]);
StatusBar->AttachToPlayer (&players[pnum]);
}
// Double-check
if (!TeamLibrary.IsValidTeam (team))
@ -884,7 +884,7 @@ void D_ReadUserInfoStrings (int pnum, uint8_t **stream, bool update)
R_BuildPlayerTranslation(pnum);
if (StatusBar != NULL && pnum == StatusBar->GetPlayer())
{
StatusBar->CallAttachToPlayer(&players[pnum]);
StatusBar->AttachToPlayer(&players[pnum]);
}
}
}

View File

@ -923,7 +923,7 @@ static void ChangeSpy (int changespy)
players[consoleplayer].camera = players[pnum].mo;
S_UpdateSounds(players[consoleplayer].camera);
StatusBar->CallAttachToPlayer (&players[pnum]);
StatusBar->AttachToPlayer (&players[pnum]);
if (demoplayback || multiplayer)
{
StatusBar->ShowPlayerName ();
@ -1823,7 +1823,7 @@ void G_DoPlayerPop(int playernum)
players[ii].camera = players[ii].mo;
if (ii == consoleplayer && StatusBar != NULL)
{
StatusBar->CallAttachToPlayer(&players[ii]);
StatusBar->AttachToPlayer(&players[ii]);
}
}
}
@ -2909,7 +2909,7 @@ bool G_CheckDemoStatus (void)
players[0].camera = NULL;
if (StatusBar != NULL)
{
StatusBar->CallAttachToPlayer (&players[0]);
StatusBar->AttachToPlayer (&players[0]);
}
if (singledemo || timingdemo)
{

View File

@ -444,7 +444,8 @@ void G_InitNew (const char *mapname, bool bTitleLevel)
if (bTitleLevel)
{
StatusBar = new DBaseStatusBar (0);
StatusBar = new DBaseStatusBar ();
StatusBar->SetSize(0);
}
else if (cls && gameinfo.gametype == GAME_Doom)
{
@ -480,11 +481,12 @@ void G_InitNew (const char *mapname, bool bTitleLevel)
}
else
{
StatusBar = new DBaseStatusBar (0);
StatusBar = new DBaseStatusBar();
StatusBar->SetSize(0);
}
}
GC::WriteBarrier(StatusBar);
StatusBar->CallAttachToPlayer (&players[consoleplayer]);
StatusBar->AttachToPlayer (&players[consoleplayer]);
StatusBar->NewGame ();
setsizeneeded = true;
@ -1090,7 +1092,7 @@ void G_DoLoadLevel (int position, bool autosave)
FBehavior::StaticStartTypedScripts(SCRIPT_Reopen, NULL, false);
}
StatusBar->CallAttachToPlayer (&players[consoleplayer]);
StatusBar->AttachToPlayer (&players[consoleplayer]);
// unsafe world load
E_WorldLoadedUnsafe();
// regular world load (savegames are handled internally)

View File

@ -337,7 +337,8 @@ public:
ST_DEADFACE = ST_GODFACE + 1
};
DBaseStatusBar (int reltop = 32, int hres=320, int vres=200);
DBaseStatusBar ();
void SetSize(int reltop = 32, int hres = 320, int vres = 200);
void OnDestroy() override;
void AttachMessage (DHUDMessage *msg, uint32_t id=0, int layer=HUDMSGLayer_Default);
@ -361,17 +362,14 @@ public:
void CallDraw(EHudState state);
void DrawBottomStuff (EHudState state);
void DrawTopStuff (EHudState state);
virtual void FlashItem (const PClass *itemtype);
virtual void AttachToPlayer (player_t *player);
void CallAttachToPlayer(player_t *player);
void FlashItem (const PClass *itemtype);
void AttachToPlayer(player_t *player);
virtual void FlashCrosshair ();
virtual void BlendView (float blend[4]);
virtual void NewGame ();
void NewGame ();
virtual void ScreenSizeChanged ();
void CallScreenSizeChanged();
virtual void ShowPop (int popnum);
void CallShowPop(int popnum);
virtual void ReceivedWeapon (AWeapon *weapon);
void ShowPop (int popnum);
virtual bool MustDrawLog(EHudState state);
virtual void SetMugShotState (const char *state_name, bool wait_till_done=false, bool reset=false);
void DrawLog();
@ -404,6 +402,7 @@ public:
bool CompleteBorder;
double CrosshairSize;
double Displacement;
bool ShowLog;
FImageCollection Images;
@ -416,7 +415,6 @@ private:
void DrawWaiting () const;
TObjPtr<DHUDMessage*> Messages[NUM_HUDMSGLAYERS];
bool ShowLog;
};
extern DBaseStatusBar *StatusBar;

View File

@ -1033,7 +1033,7 @@ public:
{
if (script->cleanX <= 0)
{ // Calculate cleanX and cleanY
wrapper->ScreenSizeChanged();
wrapper->CallScreenSizeChanged();
}
int hud = STBAR_NORMAL;
if(state == HUD_StatusBar)
@ -1572,102 +1572,117 @@ void SBarInfoMainBlock::DrawAux(const SBarInfoMainBlock *block, DSBarInfo *statu
//==========================================================================
//
// SBarinfoWrapper
//
// This class abstracts SBARINFO from the rest of the engine.
// The idea is, when status bars are moved to ZScript that only
// this small wrapper class needs to be dealt with and the implementation
// can be left alone.
// This routes all access through a scripted class because a native
// side class of an entire scripted hierarchy would be a major obstacle.
//
//==========================================================================
DSBarInfoWrapper::DSBarInfoWrapper(SBarInfo *script)
: DBaseStatusBar(script->height, script->resW, script->resH)
DEFINE_ACTION_FUNCTION(DSBarInfo, Destroy)
{
core = new DSBarInfo(this, script);
core->_SetScaled(Scaled);
CompleteBorder = script->completeBorder;
PARAM_SELF_STRUCT_PROLOGUE(DSBarInfo);
delete self;
return 0;
}
void DSBarInfoWrapper::OnDestroy()
DEFINE_ACTION_FUNCTION(DSBarInfo, SetScaled)
{
if (core != nullptr) delete core;
Super::OnDestroy();
PARAM_SELF_STRUCT_PROLOGUE(DSBarInfo);
PARAM_BOOL(scale);
self->_SetScaled(scale);
return 0;
}
void DSBarInfoWrapper::SetScaled(bool scale, bool force)
DEFINE_ACTION_FUNCTION(DSBarInfo, AttachToPlayer)
{
Super::SetScaled(scale, force);
core->_SetScaled(Scaled);
PARAM_SELF_STRUCT_PROLOGUE(DSBarInfo);
PARAM_POINTER(player, player_t);
self->_AttachToPlayer(player);
return 0;
}
void DSBarInfoWrapper::AttachToPlayer(player_t *player)
DEFINE_ACTION_FUNCTION(DSBarInfo, ScreenSizeChanged)
{
Super::AttachToPlayer(player);
core->_AttachToPlayer(player);
PARAM_SELF_STRUCT_PROLOGUE(DSBarInfo);
self->_ScreenSizeChanged();
return 0;
}
void DSBarInfoWrapper::ScreenSizeChanged()
DEFINE_ACTION_FUNCTION(DSBarInfo, Draw)
{
Super::ScreenSizeChanged();
core->_ScreenSizeChanged();
PARAM_SELF_STRUCT_PROLOGUE(DSBarInfo);
PARAM_INT(State);
self->_Draw((EHudState)State);
return 0;
}
void DSBarInfoWrapper::Draw(EHudState state)
DEFINE_ACTION_FUNCTION(DSBarInfo, NewGame)
{
Super::Draw(state);
core->_Draw(state);
PARAM_SELF_STRUCT_PROLOGUE(DSBarInfo);
self->_NewGame();
return 0;
}
void DSBarInfoWrapper::NewGame()
DEFINE_ACTION_FUNCTION(DSBarInfo, MustDrawLog)
{
Super::NewGame();
if (CPlayer != NULL)
{
AttachToPlayer(CPlayer);
core->_NewGame();
}
PARAM_SELF_STRUCT_PROLOGUE(DSBarInfo);
PARAM_INT(State);
ACTION_RETURN_BOOL(self->_MustDrawLog((EHudState)State));
}
bool DSBarInfoWrapper::MustDrawLog(EHudState state)
DEFINE_ACTION_FUNCTION(DSBarInfo, SetMugshotState)
{
return core->_MustDrawLog(state);
PARAM_SELF_STRUCT_PROLOGUE(DSBarInfo);
PARAM_STRING(name);
PARAM_BOOL(wait);
PARAM_BOOL(reset);
self->_SetMugShotState(name, wait, reset);
return 0;
}
void DSBarInfoWrapper::SetMugShotState(const char *state_name, bool wait_till_done, bool reset)
DEFINE_ACTION_FUNCTION(DSBarInfo, Tick)
{
core->_SetMugShotState(state_name, wait_till_done, reset);
PARAM_SELF_STRUCT_PROLOGUE(DSBarInfo);
self->_Tick();
return 0;
}
void DSBarInfoWrapper::Tick()
DEFINE_ACTION_FUNCTION(DSBarInfo, ReceivedWeapon)
{
DBaseStatusBar::Tick();
core->_Tick();
PARAM_SELF_STRUCT_PROLOGUE(DSBarInfo);
PARAM_OBJECT(w, AWeapon);
self->_ReceivedWeapon(w);
return 0;
}
void DSBarInfoWrapper::ReceivedWeapon(AWeapon *weapon)
DEFINE_ACTION_FUNCTION(DSBarInfo, FlashItem)
{
core->_ReceivedWeapon(weapon);
PARAM_SELF_STRUCT_PROLOGUE(DSBarInfo);
PARAM_CLASS(w, AInventory);
self->_FlashItem(w);
return 0;
}
void DSBarInfoWrapper::FlashItem(const PClass *itemtype)
DEFINE_ACTION_FUNCTION(DSBarInfo, ShowPop)
{
core->_FlashItem(itemtype);
PARAM_SELF_STRUCT_PROLOGUE(DSBarInfo);
PARAM_INT(State);
self->_ShowPop(State);
return 0;
}
void DSBarInfoWrapper::ShowPop(int popnum)
{
DBaseStatusBar::ShowPop(popnum); //DBaseStatusBar supercall
core->_ShowPop(popnum);
}
IMPLEMENT_CLASS(DSBarInfoWrapper, false, false)
DBaseStatusBar *CreateCustomStatusBar(int script)
DBaseStatusBar *CreateCustomStatusBar(int scriptno)
{
if (SBarInfoScript[script] == NULL)
auto script = SBarInfoScript[scriptno];
if (script == NULL)
I_FatalError("Tried to create a status bar with no script!");
return new DSBarInfoWrapper(SBarInfoScript[script]);
auto sbar = (DBaseStatusBar*)PClass::FindClass("SBarInfoWrapper")->CreateNew();
auto core = new DSBarInfo(sbar, script);
sbar->PointerVar<DSBarInfo>("core") = core;
sbar->SetSize(script->height, script->resW, script->resH);
core->_SetScaled(sbar->Scaled);
sbar->CompleteBorder = script->completeBorder;
return sbar;
}

View File

@ -129,27 +129,4 @@ struct SBarInfo
#define SCRIPT_DEFAULT 1
extern SBarInfo *SBarInfoScript[2];
class DSBarInfoWrapper : public DBaseStatusBar
{
DSBarInfo *core;
DECLARE_CLASS(DSBarInfoWrapper, DBaseStatusBar)
public:
DSBarInfoWrapper() : DBaseStatusBar(10, 10, 10) { core = nullptr; }
DSBarInfoWrapper(SBarInfo *script);
void OnDestroy() override;
void SetScaled(bool scale, bool force);
void AttachToPlayer(player_t *player) override;
void ScreenSizeChanged() override;
void Draw(EHudState state) override;
void NewGame() override;
bool MustDrawLog(EHudState state) override;
void SetMugShotState(const char *state_name, bool wait_till_done, bool reset) override;
void Tick() override;
void ReceivedWeapon(AWeapon *weapon) override;
void FlashItem(const PClass *itemtype) override;
void ShowPop(int popnum) override;
};
#endif //__SBarInfo_SBAR_H__

View File

@ -224,23 +224,38 @@ void ST_Clear()
//
//---------------------------------------------------------------------------
DBaseStatusBar::DBaseStatusBar (int reltop, int hres, int vres)
DBaseStatusBar::DBaseStatusBar ()
{
CompleteBorder = false;
Centering = false;
FixedOrigin = false;
CrosshairSize = 1.;
RelTop = reltop;
memset(Messages, 0, sizeof(Messages));
Displacement = 0;
CPlayer = NULL;
ShowLog = false;
}
void DBaseStatusBar::SetSize(int reltop, int hres, int vres)
{
RelTop = reltop;
HorizontalResolution = hres;
VerticalResolution = vres;
CallSetScaled (st_scale);
CallSetScaled(st_scale);
}
DEFINE_ACTION_FUNCTION(DBaseStatusBar, SetSize)
{
PARAM_SELF_PROLOGUE(DBaseStatusBar);
PARAM_INT_DEF(rt);
PARAM_INT_DEF(vw);
PARAM_INT_DEF(vh);
self->SetSize(rt, vw, vh);
return 0;
}
//---------------------------------------------------------------------------
//
// PROP Destroy
@ -334,27 +349,13 @@ void DBaseStatusBar::CallSetScaled(bool scale, bool force)
//
//---------------------------------------------------------------------------
void DBaseStatusBar::AttachToPlayer (player_t *player)
{
CPlayer = player;
}
DEFINE_ACTION_FUNCTION(DBaseStatusBar, AttachToPlayer)
{
PARAM_SELF_PROLOGUE(DBaseStatusBar);
PARAM_POINTER(player, player_t);
self->AttachToPlayer(player);
return 0;
}
void DBaseStatusBar::CallAttachToPlayer(player_t *player)
void DBaseStatusBar::AttachToPlayer(player_t *player)
{
IFVIRTUAL(DBaseStatusBar, AttachToPlayer)
{
VMValue params[] = { (DObject*)this, player };
GlobalVMStack.Call(func, params, countof(params), nullptr, 0);
}
else AttachToPlayer(player);
}
//---------------------------------------------------------------------------
@ -1019,6 +1020,12 @@ bool DBaseStatusBar::MustDrawLog(EHudState state)
void DBaseStatusBar::SetMugShotState(const char *stateName, bool waitTillDone, bool reset)
{
IFVIRTUAL(DBaseStatusBar, SetMugShotState)
{
FString statestring = stateName;
VMValue params[] = { (DObject*)this, &statestring, waitTillDone, reset };
GlobalVMStack.Call(func, params, countof(params), nullptr, 0);
}
}
//---------------------------------------------------------------------------
@ -1223,44 +1230,17 @@ void DBaseStatusBar::NewGame ()
}
}
void DBaseStatusBar::ShowPop (int popnum)
{
ShowLog = (popnum == POP_Log && !ShowLog);
}
DEFINE_ACTION_FUNCTION(DBaseStatusBar, ShowPop)
{
PARAM_SELF_PROLOGUE(DBaseStatusBar);
PARAM_INT(state);
self->ShowPop(state);
return 0;
}
void DBaseStatusBar::CallShowPop(int pop)
void DBaseStatusBar::ShowPop(int pop)
{
IFVIRTUAL(DBaseStatusBar, ShowPop)
{
VMValue params[] = { (DObject*)this, pop };
GlobalVMStack.Call(func, params, countof(params), nullptr, 0);
}
else ShowPop(pop);
}
void DBaseStatusBar::ReceivedWeapon (AWeapon *weapon)
{
}
DEFINE_ACTION_FUNCTION(DBaseStatusBar, ReceivedWeapon)
{
PARAM_SELF_PROLOGUE(DBaseStatusBar);
PARAM_POINTER(w, AWeapon);
self->ReceivedWeapon(w);
return 0;
}
void DBaseStatusBar::SerializeMessages(FSerializer &arc)
{
arc.Array("hudmessages", Messages, 3, true);
@ -1461,7 +1441,7 @@ CCMD (showpop)
{
popnum = 0;
}
StatusBar->CallShowPop (popnum);
StatusBar->ShowPop (popnum);
}
}
@ -1477,6 +1457,8 @@ DEFINE_FIELD(DBaseStatusBar, CompleteBorder);
DEFINE_FIELD(DBaseStatusBar, CrosshairSize);
DEFINE_FIELD(DBaseStatusBar, Displacement);
DEFINE_FIELD(DBaseStatusBar, CPlayer);
DEFINE_FIELD(DBaseStatusBar, ShowLog);
DEFINE_GLOBAL(StatusBar);

View File

@ -5584,7 +5584,7 @@ APlayerPawn *P_SpawnPlayer (FPlayerStart *mthing, int playernum, int flags)
if (StatusBar != NULL && (playernum == consoleplayer || StatusBar->GetPlayer() == playernum))
{
StatusBar->CallAttachToPlayer (p);
StatusBar->AttachToPlayer (p);
}
if (multiplayer)

View File

@ -34,6 +34,7 @@ version "2.5"
#include "zscript/statusbar/statusbar.txt"
#include "zscript/statusbar/strife_sbar.txt"
#include "zscript/statusbar/sbarinfowrapper.txt"
#include "zscript/inventory/inventory.txt"
#include "zscript/inventory/inv_misc.txt"

View File

@ -0,0 +1,99 @@
struct SBarInfo native ui
{
native void SetScaled(bool scaled);
native void Destroy();
native void AttachToPlayer(PlayerInfo player);
native void ScreenSizeChanged();
native void Draw(int state);
native void NewGame();
native bool MustDrawLog(int state);
native void SetMugShotState(String state_name, bool wait_till_done, bool reset);
native void Tick();
native clearscope void ReceivedWeapon(Weapon weapon);
native void FlashItem(class<Inventory> itemtype);
native void ShowPop(int popnum);
}
// The sole purpose of this wrapper is to elimintate the native dependencies of the status bar object
// because those would seriously impede the script conversion of the base class.
class SBarInfoWrapper : BaseStatusBar
{
private clearscope SBarInfo core;
override void OnDestroy()
{
if (core != null) core.Destroy(); // note that the core is not a GC'd object!
Super.OnDestroy();
}
override void SetScaled(bool scale, bool force)
{
Super.SetScaled(scale, force);
core.SetScaled(Scaled);
}
override void AttachToPlayer(PlayerInfo player)
{
Super.AttachToPlayer(player);
core.AttachToPlayer(player);
}
override void ScreenSizeChanged()
{
Super.ScreenSizeChanged();
core.ScreenSizeChanged();
}
override void Draw(int state, double TicFrac)
{
Super.Draw(state, TicFrac);
core.Draw(state);
}
override void NewGame()
{
Super.NewGame();
if (CPlayer != NULL)
{
AttachToPlayer(CPlayer);
core.NewGame();
}
}
override bool MustDrawLog(int state)
{
return core.MustDrawLog(state);
}
override void SetMugShotState(String state_name, bool wait_till_done, bool reset)
{
core.SetMugShotState(state_name, wait_till_done, reset);
}
override void Tick()
{
Super.Tick();
core.Tick();
}
override void ReceivedWeapon(Weapon weapon)
{
core.ReceivedWeapon(weapon);
}
override void FlashItem(class<Inventory> itemtype)
{
core.FlashItem(itemtype);
}
override void ShowPop(int popnum)
{
Super.ShowPop(popnum);
core.ShowPop(popnum);
}
}

View File

@ -59,20 +59,25 @@ class BaseStatusBar native ui
native double CrosshairSize;
native double Displacement;
native PlayerInfo CPlayer;
native bool ShowLog;
native void SetSize(int height, int vwidth, int vheight);
virtual void Init() {}
native virtual void SetScaled(bool scale, bool force = false);
native virtual void Tick ();
native virtual void Draw (int state, double TicFrac);
native virtual void ScreenSizeChanged ();
virtual void FlashItem (class<Inventory> itemtype) {}
native virtual void AttachToPlayer (PlayerInfo player);
virtual void AttachToPlayer (PlayerInfo player) { CPlayer = player; }
virtual void FlashCrosshair () { CrosshairSize = XHAIRPICKUPSIZE; }
virtual void NewGame () {}
native virtual void ScreenSizeChanged ();
native virtual void ShowPop (int popnum);
native virtual clearscope void ReceivedWeapon (Weapon weapn);
virtual void ShowPop (int popnum) { ShowLog = (popnum == POP_Log && !ShowLog); }
virtual clearscope void ReceivedWeapon (Weapon weapn) {}
virtual bool MustDrawLog(int state) { return true; }
// native virtual void SetMugShotState (String state_name, bool wait_till_done=false, bool reset=false); later - at the moment the backing code is not accessible from the script side.
virtual void SetMugShotState (String state_name, bool wait_till_done=false, bool reset=false) {}
native void RefreshBackground () const;
native Inventory, Inventory, int, int GetCurrentAmmo () const;
native Inventory ValidateInvFirst (int numVisible) const;

View File

@ -59,6 +59,7 @@ class StrifeStatusBar : BaseStatusBar
override void Init()
{
SetSize(32, 320, 200);
DoCommonInit();
}