- scriptified the main drawer for the in-game HUD and removed all intermediate VM calls from the native source.

This commit is contained in:
Christoph Oelckers 2018-12-02 13:06:42 +01:00
parent fe39236ee1
commit ba905321b0
2 changed files with 40 additions and 268 deletions

View file

@ -171,248 +171,6 @@ static void DrawHudNumber(FFont *font, int color, int num, int x, int y, double
} }
} }
//===========================================================================
//
// draw the status (number of kills etc)
//
//===========================================================================
static void DrawStatus(player_t * CPlayer, int x, int y)
{
IFVM(AltHud, DrawStatus)
{
VMValue params[] = { althud, CPlayer, x, y };
VMCall(func, params, countof(params), nullptr, 0);
}
}
//===========================================================================
//
// draw health
//
//===========================================================================
static void DrawHealth(player_t *CPlayer, int x, int y)
{
IFVM(AltHud, DrawHealth)
{
VMValue params[] = { althud, CPlayer, x, y };
VMCall(func, params, countof(params), nullptr, 0);
}
}
//===========================================================================
//
// Draw Armor.
// very similar to drawhealth, but adapted to handle Hexen armor too
//
//===========================================================================
static void DrawArmor(AInventory * barmor, AInventory * harmor, int x, int y)
{
IFVM(AltHud, DrawArmor)
{
VMValue params[] = { althud, barmor, harmor, x, y };
VMCall(func, params, countof(params), nullptr, 0);
}
}
//===========================================================================
//
// KEYS
//
//===========================================================================
//---------------------------------------------------------------------------
//
// Draw all keys
//
//---------------------------------------------------------------------------
static int DrawKeys(player_t * CPlayer, int x, int y)
{
IFVM(AltHud, DrawKeys)
{
VMValue params[] = { althud, CPlayer, x, y };
int retv;
VMReturn ret(&retv);
VMCall(func, params, countof(params), &ret, 1);
return retv;
}
return 0;
}
//---------------------------------------------------------------------------
//
// Drawing Ammo
//
//---------------------------------------------------------------------------
static int DrawAmmo(player_t *CPlayer, int x, int y)
{
IFVM(AltHud, DrawAmmo)
{
VMValue params[] = { althud, CPlayer, x, y };
int retv;
VMReturn ret(&retv);
VMCall(func, params, countof(params), &ret, 1);
return retv;
}
return 0;
}
static void DrawWeapons(player_t *CPlayer, int x, int y)
{
IFVM(AltHud, DrawWeapons)
{
VMValue params[] = { althud, CPlayer, x, y };
VMCall(func, params, countof(params), nullptr, 0);
}
}
//---------------------------------------------------------------------------
//
// Draw the Inventory
//
//---------------------------------------------------------------------------
static void DrawInventory(player_t * CPlayer, int x, int y)
{
IFVM(AltHud, DrawInventory)
{
VMValue params[] = { althud, CPlayer, x, y };
VMCall(func, params, countof(params), nullptr, 0);
}
}
//---------------------------------------------------------------------------
//
// Draw the Frags
//
//---------------------------------------------------------------------------
static void DrawFrags(player_t * CPlayer, int x, int y)
{
IFVM(AltHud, DrawFrags)
{
VMValue params[] = { althud, CPlayer, x, y };
VMCall(func, params, countof(params), nullptr, 0);
}
}
//---------------------------------------------------------------------------
//
// PROC DrawCoordinates
//
//---------------------------------------------------------------------------
static void DrawCoordinates(player_t * CPlayer)
{
IFVM(AltHud, DrawCoordinates)
{
VMValue params[] = { althud, CPlayer };
VMCall(func, params, countof(params), nullptr, 0);
}
}
//---------------------------------------------------------------------------
//
// Draw in-game time
//
// Check AltHUDTime option value in wadsrc/static/menudef.txt
// for meaning of all display modes
//
//---------------------------------------------------------------------------
static void DrawTime(int y)
{
IFVM(AltHud, DrawTime)
{
VMValue params[] = { althud, y };
VMCall(func, params, countof(params), nullptr, 0);
}
}
//---------------------------------------------------------------------------
//
// Draw in-game latency
//
//---------------------------------------------------------------------------
static void DrawLatency(int y)
{
IFVM(AltHud, DrawLatency)
{
VMValue params[] = { althud, y };
VMCall(func, params, countof(params), nullptr, 0);
}
}
//---------------------------------------------------------------------------
//
// draw the overlay
//
//---------------------------------------------------------------------------
static void DrawPowerups(player_t *CPlayer, int y)
{
IFVM(AltHud, DrawPowerups)
{
VMValue params[] = { althud, CPlayer, y };
VMCall(func, params, countof(params), nullptr, 0);
}
/*
// Each icon gets a 32x32 block to draw itself in.
int x, y;
AInventory *item;
const int POWERUPICONSIZE = 32;
x = hudwidth -20;
for (item = CPlayer->mo->Inventory; item != NULL; item = item->Inventory)
{
if (item->IsKindOf(NAME_Powerup))
{
IFVIRTUALPTRNAME(item, NAME_Powerup, GetPowerupIcon)
{
VMValue param[] = { item };
int rv;
VMReturn ret(&rv);
VMCall(func, param, 1, &ret, 1);
auto tex = FSetTextureID(rv);
if (!tex.isValid()) continue;
auto texture = TexMan(tex);
IFVIRTUALPTRNAME(item, NAME_Powerup, IsBlinking)
{
// Reuse the parameters from GetPowerupIcon
VMCall(func, param, 1, &ret, 1);
if (!rv)
{
screen->DrawTexture(texture, x, y, DTA_KeepRatio, true, DTA_VirtualWidth, hudwidth, DTA_VirtualHeight, hudheight, DTA_CenterBottomOffset, true, TAG_DONE);
x -= POWERUPICONSIZE;
if (x < -hudwidth / 2)
{
x = -20;
y += POWERUPICONSIZE * 3 / 2;
}
}
}
}
}
}
*/
}
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// //
// draw the overlay // draw the overlay
@ -447,31 +205,11 @@ void DrawHUD()
if (!automapactive) if (!automapactive)
{ {
int i; IFVIRTUALPTRNAME(althud, "AltHud", DrawInGame)
// No HUD in the title level!
if (gamestate == GS_TITLELEVEL || !CPlayer) return;
if (!deathmatch) DrawStatus(CPlayer, 5, hudheight-50);
else
{ {
DrawStatus(CPlayer, 5, hudheight-75); VMValue params[] = { althud, CPlayer };
DrawFrags(CPlayer, 5, hudheight-70); VMCall(func, params, countof(params), nullptr, 0);
} }
DrawHealth(CPlayer, 5, hudheight-45);
DrawArmor(CPlayer->mo->FindInventory(NAME_BasicArmor), CPlayer->mo->FindInventory(NAME_HexenArmor), 5, hudheight-20);
i=DrawKeys(CPlayer, hudwidth-4, hudheight-10);
i=DrawAmmo(CPlayer, hudwidth-5, i);
if (hud_showweapons) DrawWeapons(CPlayer, hudwidth - 5, i);
DrawInventory(CPlayer, 144, hudheight-28);
if (idmypos) DrawCoordinates(CPlayer);
DrawTime(SmallFont->GetHeight());
DrawLatency(SmallFont->GetHeight()*2); // to be fixed when fully scripted.
const int POWERUPICONSIZE = 32;
DrawPowerups(CPlayer, SmallFont->GetHeight() * 2 + POWERUPICONSIZE * 5 / 4); // to be fixed when fully scripted.
} }
else else
{ {
@ -511,7 +249,7 @@ void DrawHUD()
DTA_KeepRatio, true, DTA_KeepRatio, true,
DTA_VirtualWidth, hudwidth, DTA_VirtualHeight, hudheight, TAG_DONE); DTA_VirtualWidth, hudwidth, DTA_VirtualHeight, hudheight, TAG_DONE);
DrawCoordinates(CPlayer); //DrawCoordinates(CPlayer);
} }
if (althud) althud->Destroy(); if (althud) althud->Destroy();
@ -607,3 +345,4 @@ void HUD_InitHud()
} }
} }
} }

View file

@ -740,7 +740,7 @@ class AltHud ui
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
private native static int GetRealTime(); private native static int GetRealTime();
void DrawTime(int y) bool DrawTime(int y)
{ {
if (hud_showtime > 0 && hud_showtime <= 9) if (hud_showtime > 0 && hud_showtime <= 9)
{ {
@ -787,7 +787,9 @@ class AltHud ui
int characterCount = timeString.length(); int characterCount = timeString.length();
int width = SmallFont.GetCharWidth("0") * characterCount + 2; // small offset from screen's border int width = SmallFont.GetCharWidth("0") * characterCount + 2; // small offset from screen's border
DrawHudText(SmallFont, hud_timecolor, timeString, hudwidth - width, y, 1); DrawHudText(SmallFont, hud_timecolor, timeString, hudwidth - width, y, 1);
return true;
} }
return false;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@ -799,7 +801,7 @@ class AltHud ui
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
native static int, int, int GetLatency(); native static int, int, int GetLatency();
void DrawLatency(int y) bool DrawLatency(int y)
{ {
if ((hud_showlag == 1 && netgame) || hud_showlag == 2) if ((hud_showlag == 1 && netgame) || hud_showlag == 2)
{ {
@ -813,7 +815,9 @@ class AltHud ui
int width = SmallFont.GetCharWidth("0") * characterCount + 2; // small offset from screen's border int width = SmallFont.GetCharWidth("0") * characterCount + 2; // small offset from screen's border
DrawHudText(SmallFont, color, tempstr, hudwidth - width, y, 1); DrawHudText(SmallFont, color, tempstr, hudwidth - width, y, 1);
return true;
} }
return false;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@ -851,6 +855,35 @@ class AltHud ui
} }
} }
virtual void DrawInGame(PlayerInfo CPlayer)
{
// No HUD in the title level!
if (gamestate == GS_TITLELEVEL || !CPlayer) return;
if (!deathmatch)
{
DrawStatus(CPlayer, 5, hudheight-50);
}
else
{
DrawStatus(CPlayer, 5, hudheight-75);
DrawFrags(CPlayer, 5, hudheight-70);
}
DrawHealth(CPlayer, 5, hudheight-45);
DrawArmor(BasicArmor(CPlayer.mo.FindInventory('BasicArmor')), HexenArmor(CPlayer.mo.FindInventory('HexenArmor')), 5, hudheight-20);
int y = DrawKeys(CPlayer, hudwidth-4, hudheight-10);
y = DrawAmmo(CPlayer, hudwidth-5, y);
if (hud_showweapons) DrawWeapons(CPlayer, hudwidth - 5, y);
DrawInventory(CPlayer, 144, hudheight - 28);
if (idmypos) DrawCoordinates(CPlayer);
int h = SmallFont.GetHeight();
y = h;
if (DrawTime(y)) y += h;
if (DrawLatency(y)) y += h;
DrawPowerups(CPlayer, y - h + POWERUPICONSIZE * 5 / 4);
}
} }