- major progress on the status bar code: SBARINFO's DrawGraphic has been ported into a generic function of the base statusbar class and put to use for a few items on the Strife status bar.

- decided to ditch the widget system I had started to lay out. As it turns out that would make things far more complicated and slower than they need to be.
This commit is contained in:
Christoph Oelckers 2017-03-23 15:18:09 +01:00
commit a3ee3c287e
13 changed files with 653 additions and 809 deletions

View file

@ -803,6 +803,10 @@ void D_Display ()
V_RefreshViewBorder ();
}
// for timing the statusbar code.
//cycle_t stb;
//stb.Reset();
//stb.Clock();
if (hud_althud && viewheight == SCREENHEIGHT && screenblocks > 10)
{
StatusBar->DrawBottomStuff (HUD_AltHud);
@ -828,6 +832,8 @@ void D_Display ()
StatusBar->CallDraw (HUD_StatusBar);
StatusBar->DrawTopStuff (HUD_StatusBar);
}
//stb.Unclock();
//Printf("Stbar = %f\n", stb.TimeMS());
CT_Drawer ();
break;

View file

@ -672,6 +672,13 @@ static int DrawAmmo(player_t *CPlayer, int x, int y)
//---------------------------------------------------------------------------
FTextureID GetInventoryIcon(AInventory *item, uint32_t flags, bool *applyscale=NULL) // This function is also used by SBARINFO
{
if (applyscale != NULL)
{
*applyscale = false;
}
if (item == nullptr) return FNullTextureID();
FTextureID picnum, AltIcon = item->AltHUDIcon;
FState * state=NULL, *ReadyState;
@ -718,6 +725,17 @@ FTextureID GetInventoryIcon(AInventory *item, uint32_t flags, bool *applyscale=N
return picnum;
}
DEFINE_ACTION_FUNCTION(DBaseStatusBar, GetInventoryIcon)
{
PARAM_PROLOGUE;
PARAM_OBJECT(item, AInventory);
PARAM_INT(flags);
bool applyscale;
FTextureID icon = GetInventoryIcon(item, flags, &applyscale);
if (numret >= 1) ret[0].SetInt(icon.GetIndex());
if (numret >= 2) ret[1].SetInt(applyscale);
return MIN(numret, 2);
}
static void DrawOneWeapon(player_t * CPlayer, int x, int & y, AWeapon * weapon)
{

View file

@ -373,6 +373,28 @@ public:
virtual bool MustDrawLog(EHudState state);
virtual void SetMugShotState (const char *state_name, bool wait_till_done=false, bool reset=false);
void DrawLog();
uint32_t GetTranslation() const;
enum EAlign
{
TOP = 0,
VCENTER = 1,
BOTTOM = 2,
VOFFSET = 3,
VMASK = 3,
LEFT = 0,
HCENTER = 4,
RIGHT = 8,
HOFFSET = 12,
HMASK = 12,
CENTER = VCENTER | HCENTER,
CENTER_BOTTOM = BOTTOM | HCENTER
};
void DBaseStatusBar::DrawGraphic(FTextureID texture, bool animate, double x, double y, double Alpha = 1., bool translatable = false, bool dim = false,
int imgAlign = TOP | LEFT, int screenalign = TOP | LEFT, bool alphamap = false, double width = -1, double height = -1, double scaleX = 1, double scaleY = 1, bool fullscreenoffsets = false);
void GetCoords(int &x, int &y)
{

View file

@ -57,6 +57,7 @@
#include "cmdlib.h"
#include "g_levellocals.h"
#include "virtual.h"
#include "r_data/r_translate.h"
#include "../version.h"
@ -624,9 +625,6 @@ DEFINE_ACTION_FUNCTION(DBaseStatusBar, RefreshBackground)
void DBaseStatusBar::DrawCrosshair ()
{
static uint32_t prevcolor = 0xffffffff;
static int palettecolor = 0;
uint32_t color;
double size;
int w, h;
@ -693,19 +691,13 @@ void DBaseStatusBar::DrawCrosshair ()
color = crosshaircolor;
}
if (color != prevcolor)
{
prevcolor = color;
palettecolor = ColorMatcher.Pick (RPART(color), GPART(color), BPART(color));
}
screen->DrawTexture (CrosshairImage,
viewwidth / 2 + viewwindowx,
viewheight / 2 + viewwindowy,
DTA_DestWidth, w,
DTA_DestHeight, h,
DTA_AlphaChannel, true,
DTA_FillColor, (palettecolor << 24) | (color & 0xFFFFFF),
DTA_FillColor, color & 0xFFFFFF,
TAG_DONE);
}
@ -1377,6 +1369,120 @@ DEFINE_ACTION_FUNCTION(DBaseStatusBar, ValidateInvFirst)
}
uint32_t DBaseStatusBar::GetTranslation() const
{
if (gameinfo.gametype & GAME_Raven)
return TRANSLATION(TRANSLATION_PlayersExtra, int(CPlayer - players));
return TRANSLATION(TRANSLATION_Players, int(CPlayer - players));
}
//============================================================================
//
// draw stuff
//
//============================================================================
EXTERN_CVAR(Bool, hud_scale)
EXTERN_CVAR(Bool, vid_fps)
void DBaseStatusBar::DrawGraphic(FTextureID texture, bool animate, double x, double y, double Alpha, bool translatable, bool dim,
int imgAlign, int screenalign, bool alphamap, double width, double height, double scaleX, double scaleY, bool fullscreenoffsets)
{
if (!texture.isValid())
return;
FTexture *tex = animate ? TexMan(texture) : TexMan[texture];
switch (imgAlign & HMASK)
{
case HCENTER: x -= width / 2; break;
case RIGHT: x -= width; break;
case HOFFSET: x -= tex->GetScaledLeftOffsetDouble() * width / tex->GetScaledWidthDouble(); break;
}
switch (imgAlign & VMASK)
{
case VCENTER: y -= height / 2; break;
case BOTTOM: y -= height; break;
case VOFFSET: y -= tex->GetScaledTopOffsetDouble() * height / tex->GetScaledHeightDouble(); break;
}
if (!fullscreenoffsets)
{
x += ST_X;
y += ST_Y;
// Todo: Allow other scaling values, too.
if (Scaled)
{
y += RelTop - VerticalResolution;
screen->VirtualToRealCoords(x, y, width, height, HorizontalResolution, VerticalResolution, true, true);
}
}
else
{
double orgx, orgy;
switch (screenalign & HMASK)
{
default: orgx = 0; break;
case HCENTER: orgx = screen->GetWidth() / 2; break;
case RIGHT: orgx = screen->GetWidth(); break;
}
switch (screenalign & VMASK)
{
default: orgy = 0; break;
case VCENTER: orgy = screen->GetHeight() / 2; break;
case BOTTOM: orgy = screen->GetHeight(); break;
}
if (screenalign == (RIGHT | TOP) && vid_fps) y += 10;
if (hud_scale)
{
x *= scaleX;
y *= scaleY;
width *= scaleX;
height *= scaleY;
}
x += orgx;
y += orgy;
}
screen->DrawTexture(tex, x, y,
DTA_TopOffset, 0,
DTA_LeftOffset, 0,
DTA_DestWidthF, width,
DTA_DestHeightF, height,
DTA_TranslationIndex, translatable ? GetTranslation() : 0,
DTA_ColorOverlay, dim ? PalEntry(170, 0, 0, 0) : 0,
DTA_Alpha, Alpha,
DTA_AlphaChannel, alphamap,
DTA_FillColor, alphamap ? 0 : -1);
}
DEFINE_ACTION_FUNCTION(DBaseStatusBar, DrawGraphic)
{
PARAM_SELF_PROLOGUE(DBaseStatusBar);
PARAM_INT(texid);
PARAM_BOOL(animate);
PARAM_FLOAT(x);
PARAM_FLOAT(y);
PARAM_FLOAT(alpha);
PARAM_BOOL(translatable);
PARAM_BOOL(dim);
PARAM_INT(ialign);
PARAM_INT(salign);
PARAM_BOOL(alphamap);
PARAM_FLOAT(w);
PARAM_FLOAT(h);
PARAM_FLOAT(sx);
PARAM_FLOAT(sy);
PARAM_BOOL(fso);
self->DrawGraphic(FSetTextureID(texid), animate, x, y, alpha, translatable, dim, ialign, salign, alphamap, w, h, sx, sy, fso);
return 0;
}
//============================================================================
//
// CCMD showpop
@ -1438,36 +1544,3 @@ static DObject *InitObject(PClass *type, int paramnum, VM_ARGS)
return obj;
}
DEFINE_ACTION_FUNCTION(DStatusbarWidget, AppendWidget)
{
PARAM_SELF_PROLOGUE(DObject);
PARAM_CLASS(type, DObject);
if (!type->IsDescendantOf(NAME_StatusbarWidget) || type->IsDescendantOf(NAME_StatusbarCondition))
{
ThrowAbortException(X_OTHER, "Invalid class %s for AppendWidget", type->TypeName.GetChars());
}
auto obj = InitObject(type, paramnum, VM_ARGS_NAMES);
auto owner = self->PointerVar<DObject>(NAME_Owner);
self->PointerVar<DObject>(NAME_Next) = obj;
obj->PointerVar<DObject>(NAME_Prev) = self;
obj->PointerVar<DObject>(NAME_Owner) = owner;
ACTION_RETURN_POINTER(obj);
}
DEFINE_ACTION_FUNCTION(DStatusbarWidget, BeginCondition)
{
PARAM_SELF_PROLOGUE(DObject);
PARAM_CLASS(type, DObject);
if (!type->IsDescendantOf(NAME_StatusbarCondition))
{
ThrowAbortException(X_OTHER, "Invalid class %s for BeginCondition", type->TypeName.GetChars());
}
auto obj = InitObject(type, paramnum, VM_ARGS_NAMES);
auto head = PClass::FindClass(NAME_StatusbarWidget)->CreateNew();
head->PointerVar<DObject>(NAME_Owner) = self;
self->PointerVar<DObject>(NAME_Children) = head;
ACTION_RETURN_POINTER(head);
}

View file

@ -8674,6 +8674,11 @@ FxExpression *FxVMFunctionCall::Resolve(FCompileContext& ctx)
return nullptr;
}
if (Function->Variants[0].Implementation->PrintableName.CompareNoCase("CustomStatusBar.DrawTexture") == 0)
{
int a = 0;
}
CallingFunction = ctx.Function;
if (ArgList.Size() > 0)
{
@ -8736,6 +8741,12 @@ FxExpression *FxVMFunctionCall::Resolve(FCompileContext& ctx)
delete old;
// now fill the gap with constants created from the default list so that we got a full list of arguments.
int insert = j - i;
int skipdefs = 0;
// Defaults contain multiple entries for pointers so we need to calculate how much additional defaults we need to skip
for (unsigned k = 0; k < i + implicit; k++)
{
skipdefs += argtypes[k]->GetRegCount() - 1;
}
for (int k = 0; k < insert; k++)
{
auto ntype = argtypes[i + k + implicit];
@ -8745,8 +8756,23 @@ FxExpression *FxVMFunctionCall::Resolve(FCompileContext& ctx)
assert(ntype->IsKindOf(RUNTIME_CLASS(PPointer)));
ntype = TypeNullPtr; // the default of a reference type can only be a null pointer
}
auto x = new FxConstant(ntype, defaults[i + k + implicit], ScriptPosition);
ArgList.Insert(i + k, x);
if (ntype->GetRegCount() == 1)
{
auto x = new FxConstant(ntype, defaults[i + k + skipdefs + implicit], ScriptPosition);
ArgList.Insert(i + k, x);
}
else
{
// Vectors need special treatment because they are not normal constants
FxConstant *cs[3] = { nullptr };
for (int l = 0; l < ntype->GetRegCount(); l++)
{
cs[l] = new FxConstant(TypeFloat64, defaults[l + i + k + skipdefs + implicit], ScriptPosition);
}
FxExpression *x = new FxVectorValue(cs[0], cs[1], cs[2], ScriptPosition);
ArgList.Insert(i + k, x);
skipdefs += ntype->GetRegCount() - 1;
}
}
done = true;
break;

View file

@ -2503,10 +2503,7 @@ void ZCCCompiler::CompileFunction(ZCC_StructWork *c, ZCC_FuncDeclarator *f, bool
{
flags |= VARF_Optional;
hasoptionals = true;
// The simplifier is not suited to convert the constant into something usable.
// All it does is reduce the expression to a constant but we still got to do proper type checking and conversion.
// It will also lose important type info about enums, once these get implemented
// The code generator can do this properly for us.
FxExpression *x = new FxTypeCast(ConvertNode(p->Default), type, false);
FCompileContext ctx(OutNamespace, c->Type(), false);
x = x->Resolve(ctx);

View file

@ -104,6 +104,7 @@ void SWCanvas::DrawTexture(DCanvas *canvas, FTexture *img, DrawParms &parms)
drawerargs.SetTranslationMap(translation);
drawerargs.SetLight(basecolormap, 0.0f, shade);
bool visible = drawerargs.SetStyle(viewport, parms.style, parms.Alpha, -1, parms.fillcolor, basecolormap);
double x0 = parms.x - parms.left * parms.destwidth / parms.texwidth;

View file

@ -521,7 +521,15 @@ bool DCanvas::ParseDrawTextureTags(FTexture *img, double x, double y, uint32_t t
case DTA_FillColor:
parms->fillcolor = ListGetInt(tags);
fillcolorset = true;
if (parms->fillcolor != -1)
{
fillcolorset = true;
}
else if (parms->fillcolor != 0)
{
// The crosshair is the only thing which uses a non-black fill color.
parms->fillcolor = PalEntry(ColorMatcher.Pick(parms->fillcolor), RPART(parms->fillcolor), GPART(parms->fillcolor), BPART(parms->fillcolor));
}
break;
case DTA_TranslationIndex: