mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-15 08:52:00 +00:00
- moved backend independent HUD code out of glbackend.cpp.
This commit is contained in:
parent
0bdbf0f1cb
commit
b3bcedda6c
27 changed files with 155 additions and 112 deletions
|
@ -1046,6 +1046,7 @@ set (PCH_SOURCES
|
|||
core/gameconfigfile.cpp
|
||||
core/gamecvars.cpp
|
||||
core/gamecontrol.cpp
|
||||
core/gamehud.cpp
|
||||
core/gamefuncs.cpp
|
||||
core/gameinput.cpp
|
||||
core/interpolate.cpp
|
||||
|
|
139
source/core/gamehud.cpp
Normal file
139
source/core/gamehud.cpp
Normal file
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
** 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"
|
||||
|
||||
F2DDrawer twodpsp;
|
||||
|
||||
|
||||
void hud_drawsprite(double sx, double sy, int z, double a, int picnum, int dashade, int dapalnum, int dastat, double alpha)
|
||||
{
|
||||
double dz = z / 65536.;
|
||||
alpha *= (dastat & RS_TRANS1)? glblend[0].def[!!(dastat & RS_TRANS2)].alpha : 1.;
|
||||
int palid = TRANSLATION(Translation_Remap + curbasepal, dapalnum);
|
||||
|
||||
if (picanm[picnum].sf & PICANM_ANIMTYPE_MASK)
|
||||
picnum += animateoffs(picnum, 0);
|
||||
|
||||
auto tex = tileGetTexture(picnum);
|
||||
|
||||
DrawTexture(&twodpsp, tex, sx, sy,
|
||||
DTA_ScaleX, dz, DTA_ScaleY, dz,
|
||||
DTA_Color, shadeToLight(dashade),
|
||||
DTA_TranslationIndex, palid,
|
||||
DTA_ViewportX, windowxy1.x, DTA_ViewportY, windowxy1.y,
|
||||
DTA_ViewportWidth, windowxy2.x - windowxy1.x + 1, DTA_ViewportHeight, windowxy2.y - windowxy1.y + 1,
|
||||
DTA_FullscreenScale, (dastat & RS_STRETCH)? FSMode_ScaleToScreen: FSMode_ScaleToHeight, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200,
|
||||
DTA_CenterOffsetRel, !(dastat & (RS_TOPLEFT | RS_CENTER)),
|
||||
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,
|
||||
DTA_Rotate, a * -BAngToDegree,
|
||||
DTA_FlipOffsets, !(dastat & (/*RS_TOPLEFT |*/ RS_CENTER)),
|
||||
DTA_Alpha, alpha,
|
||||
TAG_DONE);
|
||||
}
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// DFrameBuffer :: DrawRateStuff
|
||||
//
|
||||
// Draws the fps counter, dot ticker, and palette debug.
|
||||
//
|
||||
//==========================================================================
|
||||
CVAR(Bool, vid_fps, false, 0)
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
output.AppendFormat("%5.1f fps (%.1f ms)\n", lastFPS, frameDelay);
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
|
8
source/core/gamehud.h
Normal file
8
source/core/gamehud.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "v_2ddrawer.h"
|
||||
|
||||
extern F2DDrawer twodpsp;
|
||||
|
||||
void DrawRateStuff();
|
||||
void hud_drawsprite(double sx, double sy, int z, double a, int picnum, int dashade, int dapalnum, int dastat, double alpha = 1);
|
|
@ -88,6 +88,7 @@
|
|||
#include "gamestruct.h"
|
||||
#include "savegamehelp.h"
|
||||
#include "v_draw.h"
|
||||
#include "gamehud.h"
|
||||
|
||||
CVAR(Bool, vid_activeinbackground, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
CVAR(Bool, r_ticstability, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
|
|
|
@ -38,7 +38,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#include "v_2ddrawer.h"
|
||||
#include "v_video.h"
|
||||
#include "v_font.h"
|
||||
#include "glbackend/glbackend.h"
|
||||
|
||||
BEGIN_BLD_NS
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#include "SmackerDecoder.h"
|
||||
#include "blood.h"
|
||||
#include "animtexture.h"
|
||||
#include "../glbackend/glbackend.h"
|
||||
#include "raze_sound.h"
|
||||
#include "v_2ddrawer.h"
|
||||
#include "screenjob.h"
|
||||
|
|
|
@ -37,7 +37,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#include "gstrings.h"
|
||||
#include "v_2ddrawer.h"
|
||||
#include "v_video.h"
|
||||
#include "glbackend/glbackend.h"
|
||||
#include "gamehud.h"
|
||||
|
||||
BEGIN_BLD_NS
|
||||
|
||||
|
|
|
@ -38,7 +38,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#include "v_2ddrawer.h"
|
||||
#include "v_video.h"
|
||||
#include "v_font.h"
|
||||
#include "glbackend/glbackend.h"
|
||||
|
||||
BEGIN_BLD_NS
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#include "compat.h"
|
||||
#include "common_game.h"
|
||||
#include "v_draw.h"
|
||||
#include "glbackend/glbackend.h"
|
||||
#include "blood.h"
|
||||
|
||||
BEGIN_BLD_NS
|
||||
|
|
|
@ -37,7 +37,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#include "v_2ddrawer.h"
|
||||
#include "v_video.h"
|
||||
#include "v_font.h"
|
||||
#include "glbackend/glbackend.h"
|
||||
#include "statusbar.h"
|
||||
#include "automap.h"
|
||||
#include "v_draw.h"
|
||||
|
|
|
@ -42,7 +42,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#include "automap.h"
|
||||
#include "gamefuncs.h"
|
||||
#include "v_draw.h"
|
||||
#include "glbackend/glbackend.h"
|
||||
|
||||
BEGIN_BLD_NS
|
||||
|
||||
|
|
|
@ -42,7 +42,6 @@ Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms
|
|||
#include "mapinfo.h"
|
||||
#include "gamestate.h"
|
||||
#include "dukeactor.h"
|
||||
#include "../../glbackend/glbackend.h"
|
||||
|
||||
|
||||
BEGIN_DUKE_NS
|
||||
|
|
|
@ -38,7 +38,6 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au)
|
|||
#include "st_start.h"
|
||||
#include "i_interface.h"
|
||||
#include "prediction.h"
|
||||
#include "glbackend/glbackend.h"
|
||||
#include "gamestate.h"
|
||||
|
||||
BEGIN_DUKE_NS
|
||||
|
|
|
@ -41,7 +41,6 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au)
|
|||
#include "i_interface.h"
|
||||
#include "prediction.h"
|
||||
#include "sbar.h"
|
||||
#include "glbackend/glbackend.h"
|
||||
#include "gamestate.h"
|
||||
#include "dukeactor.h"
|
||||
#include "interpolate.h"
|
||||
|
|
|
@ -35,7 +35,6 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au)
|
|||
#include "mapinfo.h"
|
||||
#include "texturemanager.h"
|
||||
#include "interpolate.h"
|
||||
#include "glbackend/glbackend.h"
|
||||
|
||||
BEGIN_DUKE_NS
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "mathutil.h"
|
||||
#include "glbackend/glbackend.h"
|
||||
#include "gamehud.h"
|
||||
#include "global.h"
|
||||
|
||||
// all inline functions.
|
||||
|
|
|
@ -33,6 +33,7 @@ Modifications for JonoF's port by Jonathon Fowler (jf@jonof.id.au)
|
|||
#include "automap.h"
|
||||
#include "dukeactor.h"
|
||||
#include "interpolate.h"
|
||||
#include "glbackend/glbackend.h"
|
||||
|
||||
|
||||
BEGIN_DUKE_NS
|
||||
|
|
|
@ -34,7 +34,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#include "vm.h"
|
||||
#include "razemenu.h"
|
||||
|
||||
#include "../../glbackend/glbackend.h"
|
||||
|
||||
|
||||
BEGIN_PS_NS
|
||||
|
|
|
@ -20,7 +20,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#include "exhumed.h"
|
||||
#include "view.h"
|
||||
#include "aistuff.h"
|
||||
#include "../glbackend/glbackend.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
|
|
@ -16,7 +16,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
*/
|
||||
//-------------------------------------------------------------------------
|
||||
#include "ns.h"
|
||||
#include "glbackend/glbackend.h"
|
||||
#include "gamehud.h"
|
||||
#include "sequence.h"
|
||||
#include "engine.h"
|
||||
#include "exhumed.h"
|
||||
|
|
|
@ -29,7 +29,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#include "mapinfo.h"
|
||||
#include "v_video.h"
|
||||
#include "interpolate.h"
|
||||
#include "glbackend/glbackend.h"
|
||||
#include "v_draw.h"
|
||||
#include <string.h>
|
||||
|
||||
|
|
|
@ -51,9 +51,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
#include "v_draw.h"
|
||||
#include "vm.h"
|
||||
|
||||
#include "../../glbackend/glbackend.h"
|
||||
|
||||
|
||||
BEGIN_SW_NS
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
|
|
@ -55,7 +55,6 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
|
|||
#include "v_2ddrawer.h"
|
||||
#include "v_video.h"
|
||||
#include "v_draw.h"
|
||||
#include "glbackend/glbackend.h"
|
||||
|
||||
BEGIN_SW_NS
|
||||
|
||||
|
|
|
@ -44,7 +44,6 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
|
|||
#include "pal.h"
|
||||
#include "parent.h"
|
||||
#include "v_video.h"
|
||||
#include "glbackend/glbackend.h"
|
||||
|
||||
BEGIN_SW_NS
|
||||
|
||||
|
|
|
@ -37,11 +37,11 @@ Prepared for public release: 03/28/2005 - Charlie Wiederhold, 3D Realms
|
|||
#include "pal.h"
|
||||
#include "player.h"
|
||||
#include "v_2ddrawer.h"
|
||||
#include "gamehud.h"
|
||||
|
||||
#include "weapon.h"
|
||||
#include "razemenu.h"
|
||||
#include "raze_sound.h"
|
||||
#include "glbackend/glbackend.h"
|
||||
|
||||
BEGIN_SW_NS
|
||||
|
||||
|
|
|
@ -50,10 +50,10 @@
|
|||
#include "hw_cvars.h"
|
||||
#include "gamestruct.h"
|
||||
#include "gl_models.h"
|
||||
#include "gamehud.h"
|
||||
|
||||
CVAR(Bool, gl_texture, true, 0)
|
||||
|
||||
F2DDrawer twodpsp;
|
||||
static int BufferLock = 0;
|
||||
|
||||
TArray<VSMatrix> matrixArray;
|
||||
|
@ -405,62 +405,6 @@ void renderFinishScene()
|
|||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// DFrameBuffer :: DrawRateStuff
|
||||
//
|
||||
// Draws the fps counter, dot ticker, and palette debug.
|
||||
//
|
||||
//==========================================================================
|
||||
CVAR(Bool, vid_fps, false, 0)
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
output.AppendFormat("%5.1f fps (%.1f ms)\n", lastFPS, frameDelay);
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
int32_t r_scenebrightness = 0;
|
||||
|
||||
|
@ -533,33 +477,3 @@ void precacheMarkedTiles()
|
|||
}
|
||||
}
|
||||
|
||||
void hud_drawsprite(double sx, double sy, int z, double a, int picnum, int dashade, int dapalnum, int dastat, double alpha)
|
||||
{
|
||||
double dz = z / 65536.;
|
||||
alpha *= (dastat & RS_TRANS1)? glblend[0].def[!!(dastat & RS_TRANS2)].alpha : 1.;
|
||||
int palid = TRANSLATION(Translation_Remap + curbasepal, dapalnum);
|
||||
|
||||
if (picanm[picnum].sf & PICANM_ANIMTYPE_MASK)
|
||||
picnum += animateoffs(picnum, 0);
|
||||
|
||||
auto tex = tileGetTexture(picnum);
|
||||
|
||||
DrawTexture(&twodpsp, tex, sx, sy,
|
||||
DTA_ScaleX, dz, DTA_ScaleY, dz,
|
||||
DTA_Color, shadeToLight(dashade),
|
||||
DTA_TranslationIndex, palid,
|
||||
DTA_ViewportX, windowxy1.x, DTA_ViewportY, windowxy1.y,
|
||||
DTA_ViewportWidth, windowxy2.x - windowxy1.x + 1, DTA_ViewportHeight, windowxy2.y - windowxy1.y + 1,
|
||||
DTA_FullscreenScale, (dastat & RS_STRETCH)? FSMode_ScaleToScreen: FSMode_ScaleToHeight, DTA_VirtualWidth, 320, DTA_VirtualHeight, 200,
|
||||
DTA_CenterOffsetRel, !(dastat & (RS_TOPLEFT | RS_CENTER)),
|
||||
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,
|
||||
DTA_Rotate, a * -BAngToDegree,
|
||||
DTA_FlipOffsets, !(dastat & (/*RS_TOPLEFT |*/ RS_CENTER)),
|
||||
DTA_Alpha, alpha,
|
||||
TAG_DONE);
|
||||
}
|
||||
|
||||
|
|
|
@ -340,13 +340,10 @@ public:
|
|||
};
|
||||
|
||||
extern GLInstance GLInterface;
|
||||
extern F2DDrawer twodpsp;
|
||||
|
||||
void renderSetProjectionMatrix(const float* p);
|
||||
void renderSetViewMatrix(const float* p);
|
||||
void renderSetVisibility(float v);
|
||||
void renderBeginScene();
|
||||
void renderFinishScene();
|
||||
void DrawRateStuff();
|
||||
void videoShowFrame(int32_t);
|
||||
void hud_drawsprite(double sx, double sy, int z, double a, int picnum, int dashade, int dapalnum, int dastat, double alpha = 1);
|
||||
|
|
Loading…
Reference in a new issue