2021-04-11 06:40:18 +00:00
|
|
|
/*
|
|
|
|
** gamehud.cpp
|
|
|
|
**
|
|
|
|
** Management of HUD elements
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
** Copyright 2019-2021 Christoph Oelckers
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <assert.h>
|
|
|
|
#include "gamehud.h"
|
|
|
|
#include "textures.h"
|
|
|
|
#include "palette.h"
|
|
|
|
#include "gamecontrol.h"
|
|
|
|
#include "v_2ddrawer.h"
|
|
|
|
#include "v_video.h"
|
|
|
|
#include "build.h"
|
|
|
|
#include "v_draw.h"
|
|
|
|
#include "v_font.h"
|
|
|
|
#include "gamestruct.h"
|
2021-04-11 11:56:10 +00:00
|
|
|
#include "gamefuncs.h"
|
2022-12-07 16:10:27 +00:00
|
|
|
#include "texinfo.h"
|
|
|
|
|
|
|
|
#include "buildtiles.h"
|
|
|
|
|
2021-04-11 06:40:18 +00:00
|
|
|
|
|
|
|
F2DDrawer twodpsp;
|
|
|
|
|
|
|
|
|
2022-12-31 18:34:46 +00:00
|
|
|
void hud_drawsprite(double sx, double sy, double sz, double a, FTextureID texid, int dashade, int dapalnum, int dastat, double alpha)
|
2021-04-11 06:40:18 +00:00
|
|
|
{
|
|
|
|
alpha *= (dastat & RS_TRANS1)? glblend[0].def[!!(dastat & RS_TRANS2)].alpha : 1.;
|
|
|
|
int palid = TRANSLATION(Translation_Remap + curbasepal, dapalnum);
|
|
|
|
|
2022-12-31 18:34:46 +00:00
|
|
|
auto tex = TexMan.GetGameTexture(texid, true);
|
2021-04-11 06:40:18 +00:00
|
|
|
|
|
|
|
DrawTexture(&twodpsp, tex, sx, sy,
|
2021-07-29 05:14:21 +00:00
|
|
|
DTA_ScaleX, sz, DTA_ScaleY, sz,
|
2021-04-11 06:40:18 +00:00
|
|
|
DTA_Color, shadeToLight(dashade),
|
|
|
|
DTA_TranslationIndex, palid,
|
2022-08-04 21:47:01 +00:00
|
|
|
DTA_ViewportX, viewport3d.Left(), DTA_ViewportY, viewport3d.Top(),
|
|
|
|
DTA_ViewportWidth, viewport3d.Width(), DTA_ViewportHeight, viewport3d.Height(),
|
2021-04-11 06:40:18 +00:00
|
|
|
DTA_FullscreenScale, (dastat & RS_STRETCH)? FSMode_ScaleToScreen: FSMode_ScaleToHeight, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200,
|
2021-11-28 20:01:48 +00:00
|
|
|
DTA_CenterOffsetRel, (dastat & (RS_TOPLEFT | RS_CENTER))? 0:2,
|
2021-04-11 06:40:18 +00:00
|
|
|
DTA_TopLeft, !!(dastat & RS_TOPLEFT),
|
|
|
|
DTA_CenterOffset, !!(dastat & RS_CENTER),
|
|
|
|
DTA_FlipX, !!(dastat & RS_XFLIPHUD),
|
|
|
|
DTA_FlipY, !!(dastat & RS_YFLIPHUD),
|
|
|
|
DTA_Pin, (dastat & RS_ALIGN_R) ? 1 : (dastat & RS_ALIGN_L) ? -1 : 0,
|
2022-12-11 01:42:54 +00:00
|
|
|
DTA_Rotate, a,
|
2021-04-11 06:40:18 +00:00
|
|
|
DTA_FlipOffsets, !(dastat & (/*RS_TOPLEFT |*/ RS_CENTER)),
|
|
|
|
DTA_Alpha, alpha,
|
|
|
|
TAG_DONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// DFrameBuffer :: DrawRateStuff
|
|
|
|
//
|
|
|
|
// Draws the fps counter, dot ticker, and palette debug.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
2022-10-02 18:33:18 +00:00
|
|
|
EXTERN_CVAR(Bool, vid_fps)
|
2021-04-11 06:40:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
static FString statFPS()
|
|
|
|
{
|
|
|
|
static int32_t frameCount;
|
|
|
|
static double lastFrameTime;
|
|
|
|
static double cumulativeFrameDelay;
|
|
|
|
static double lastFPS;
|
|
|
|
|
|
|
|
FString output;
|
|
|
|
|
|
|
|
double frameTime = I_msTimeF();
|
|
|
|
double frameDelay = frameTime - lastFrameTime;
|
|
|
|
cumulativeFrameDelay += frameDelay;
|
|
|
|
|
|
|
|
frameCount++;
|
|
|
|
if (frameDelay >= 0)
|
|
|
|
{
|
2021-07-24 07:51:05 +00:00
|
|
|
output.AppendFormat("%5.1f fps", lastFPS);
|
|
|
|
if (frameDelay < 10) output.AppendFormat(" ");
|
|
|
|
output.AppendFormat(" (%.1f ms)\n", frameDelay);
|
2021-04-11 06:40:18 +00:00
|
|
|
|
|
|
|
if (cumulativeFrameDelay >= 1000.0)
|
|
|
|
{
|
|
|
|
lastFPS = 1000. * frameCount / cumulativeFrameDelay;
|
|
|
|
frameCount = 0;
|
|
|
|
cumulativeFrameDelay = 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lastFrameTime = frameTime;
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawRateStuff()
|
|
|
|
{
|
|
|
|
// Draws frame time and cumulative fps
|
|
|
|
if (vid_fps)
|
|
|
|
{
|
|
|
|
FString fpsbuff = statFPS();
|
|
|
|
|
|
|
|
int textScale = active_con_scale(twod);
|
|
|
|
int rate_x = screen->GetWidth() / textScale - NewConsoleFont->StringWidth(&fpsbuff[0]);
|
|
|
|
twod->AddColorOnlyQuad(rate_x * textScale, 0, screen->GetWidth(), NewConsoleFont->GetHeight() * textScale, MAKEARGB(255, 0, 0, 0));
|
|
|
|
DrawText(twod, NewConsoleFont, CR_WHITE, rate_x, 0, (char*)&fpsbuff[0],
|
|
|
|
DTA_VirtualWidth, screen->GetWidth() / textScale,
|
|
|
|
DTA_VirtualHeight, screen->GetHeight() / textScale,
|
|
|
|
DTA_KeepRatio, true, TAG_DONE);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|