Skip to content

Commit

Permalink
- Backend update from Raze
Browse files Browse the repository at this point in the history
Mostly cleanup and better separation of game/backend concerns.
  • Loading branch information
coelckers committed Jun 6, 2022
1 parent b7f3cc1 commit c62e14d
Show file tree
Hide file tree
Showing 30 changed files with 200 additions and 196 deletions.
3 changes: 0 additions & 3 deletions src/common/console/c_cvars.cpp
Expand Up @@ -55,9 +55,6 @@ struct FLatchedValue

static TArray<FLatchedValue> LatchedValues;

bool FBaseCVar::m_DoNoSet = false;
bool FBaseCVar::m_UseCallback = false;

FBaseCVar *CVars = NULL;

int cvar_defflags;
Expand Down
4 changes: 2 additions & 2 deletions src/common/console/c_cvars.h
Expand Up @@ -216,8 +216,8 @@ class FBaseCVar
void (*m_Callback)(FBaseCVar &);
FBaseCVar *m_Next;

static bool m_UseCallback;
static bool m_DoNoSet;
static inline bool m_UseCallback = false;
static inline bool m_DoNoSet = false;

void *m_ExtraDataPointer;

Expand Down
1 change: 0 additions & 1 deletion src/common/cutscenes/movieplayer.cpp
Expand Up @@ -255,7 +255,6 @@ class VpxPlayer : public MoviePlayer
failed = true;
}

// The decoder needs a buffer with even height
Pic.Resize(width * height * 4);


Expand Down
2 changes: 2 additions & 0 deletions src/common/engine/i_interface.cpp
@@ -1,6 +1,8 @@
#include "i_interface.h"
#include "st_start.h"

// Some global engine variables taken out of the backend code.
FStartupScreen* StartWindow;
SystemCallbacks sysCallbacks;
FString endoomName;
bool batchrun;
Expand Down
2 changes: 1 addition & 1 deletion src/common/filesystem/filesystem.cpp
Expand Up @@ -1698,4 +1698,4 @@ CCMD(fs_dir)
bool hidden = fileSystem.FindFile(fn1) != i;
Printf(PRINT_NONOTIFY, "%s%-64s %-15s (%5d) %10d %s %s\n", hidden ? TEXTCOLOR_RED : TEXTCOLOR_UNTRANSLATED, fn1, fns, fnid, length, container, hidden ? "(h)" : "");
}
}
}
2 changes: 1 addition & 1 deletion src/common/rendering/gl/gl_stereo3d.cpp
Expand Up @@ -430,4 +430,4 @@ void FGLRenderer::PresentStereo()
}
}

}
}
5 changes: 3 additions & 2 deletions src/common/rendering/hwrenderer/data/hw_skydome.cpp
Expand Up @@ -455,7 +455,7 @@ void FSkyVertexBuffer::RenderRow(FRenderState& state, EDrawType prim, int row, T
//
//-----------------------------------------------------------------------------

void FSkyVertexBuffer::RenderDome(FRenderState& state, FGameTexture* tex, int mode, bool which, PalEntry color)
void FSkyVertexBuffer::DoRenderDome(FRenderState& state, FGameTexture* tex, int mode, bool which, PalEntry color)
{
auto& primStart = which ? mPrimStartBuild : mPrimStartDoom;
if (tex && tex->isValid())
Expand Down Expand Up @@ -510,7 +510,7 @@ void FSkyVertexBuffer::RenderDome(FRenderState& state, FGameTexture* tex, float
{
SetupMatrices(tex, x_offset, y_offset, mirror, mode, state.mModelMatrix, state.mTextureMatrix, tiled, xscale, yscale);
}
RenderDome(state, tex, mode, false, color);
DoRenderDome(state, tex, mode, false, color);
}


Expand Down Expand Up @@ -570,5 +570,6 @@ void FSkyVertexBuffer::RenderBox(FRenderState& state, FSkyBox* tex, float x_offs
state.Draw(DT_TriangleStrip, FaceStart(4), 4);

state.EnableModelMatrix(false);
state.SetObjectColor(0xffffffff);
}

2 changes: 1 addition & 1 deletion src/common/rendering/hwrenderer/data/hw_skydome.h
Expand Up @@ -90,7 +90,7 @@ class FSkyVertexBuffer
}

void RenderRow(FRenderState& state, EDrawType prim, int row, TArray<unsigned int>& mPrimStart, bool apply = true);
void RenderDome(FRenderState& state, FGameTexture* tex, int mode, bool which, PalEntry color = 0xffffffff);
void DoRenderDome(FRenderState& state, FGameTexture* tex, int mode, bool which, PalEntry color = 0xffffffff);
void RenderDome(FRenderState& state, FGameTexture* tex, float x_offset, float y_offset, bool mirror, int mode, bool tiled, float xscale = 0, float yscale = 0, PalEntry color = 0xffffffff);
void RenderBox(FRenderState& state, FSkyBox* tex, float x_offset, bool sky2, float stretch, const FVector3& skyrotatevector, const FVector3& skyrotatevector2, PalEntry color = 0xffffffff);

Expand Down
2 changes: 1 addition & 1 deletion src/common/scripting/backend/codegen.cpp
Expand Up @@ -11158,7 +11158,7 @@ ExpEmit FxLocalArrayDeclaration::Emit(VMFunctionBuilder *build)

auto zero = build->GetConstantInt(0);
auto elementSizeConst = build->GetConstantInt(static_cast<PArray *>(ValueType)->ElementSize);
int arrOffsetReg;
int arrOffsetReg = 0;
if (!isDynamicArray)
{
arrOffsetReg = build->Registers[REGT_POINTER].Get(1);
Expand Down
6 changes: 3 additions & 3 deletions src/common/scripting/frontend/zcc_parser.cpp
Expand Up @@ -425,9 +425,9 @@ PNamespace *ParseOneScript(const int baselump, ZCCParseState &state)
{
FString fullPath = IncludeLocs[i].FileName.GetChars(); // get full path, format 'wad:filepath/filename'

long start = fullPath.IndexOf(":"); // find first ':'
auto start = fullPath.IndexOf(":"); // find first ':'

long end = fullPath.LastIndexOf("/"); // find last '/'
auto end = fullPath.LastIndexOf("/"); // find last '/'

if (start!=-1&&end!=-1)
{
Expand All @@ -443,7 +443,7 @@ PNamespace *ParseOneScript(const int baselump, ZCCParseState &state)
while (relativePath.IndexOf("../") == 0) // go back one folder for each '..'
{
relativePath = relativePath.Mid(3);
long slash_index = resolvedPath.LastIndexOf("/");
auto slash_index = resolvedPath.LastIndexOf("/");
if (slash_index != -1) {
resolvedPath = resolvedPath.Mid(0,slash_index);
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/common/startscreen/startscreen.cpp
Expand Up @@ -350,15 +350,15 @@ FStartScreen* GetGameStartScreen(int max_progress)
{
try
{
if (GameStartupInfo.Type == FStartupInfo::HexenStartup || (gameinfo.gametype == GAME_Hexen && GameStartupInfo.Type == FStartupInfo::DefaultStartup))
if (GameStartupInfo.Type == FStartupInfo::HexenStartup)
{
return CreateHexenStartScreen(max_progress);
}
else if (GameStartupInfo.Type == FStartupInfo::HereticStartup || (gameinfo.gametype == GAME_Heretic && GameStartupInfo.Type == FStartupInfo::DefaultStartup))
else if (GameStartupInfo.Type == FStartupInfo::HereticStartup)
{
return CreateHereticStartScreen(max_progress);
}
else if (GameStartupInfo.Type == FStartupInfo::StrifeStartup || (gameinfo.gametype == GAME_Strife && GameStartupInfo.Type == FStartupInfo::DefaultStartup))
else if (GameStartupInfo.Type == FStartupInfo::StrifeStartup)
{
return CreateStrifeStartScreen(max_progress);
}
Expand Down
1 change: 0 additions & 1 deletion src/common/textures/formats/startscreentexture.cpp
Expand Up @@ -34,7 +34,6 @@
**
*/

#include "doomtype.h"
#include "files.h"
#include "gi.h"
#include "bitmap.h"
Expand Down
20 changes: 6 additions & 14 deletions src/common/utility/i_time.cpp
Expand Up @@ -198,34 +198,26 @@ void I_ResetFrameTime()
FirstFrameStartTime += (CurrentFrameStartTime - ft);
}

double I_GetInputFrac(bool const synchronised, double const ticrate)
double I_GetInputFrac(bool const synchronised)
{
if (!synchronised)
{
const double max = 1000. / ticrate;
const double now = I_msTimeF();
const double elapsedInputTicks = std::min(now - lastinputtime, max);
const double result = (now - lastinputtime) * GameTicRate * (1. / 1000.);
lastinputtime = now;

if (elapsedInputTicks < max)
if (result < 1)
{
// Calculate an amplification to apply to the result before returning,
// factoring in the game's ticrate and the value of the result.
// This rectifies a deviation of 100+ ms or more depending on the length
// of the operation to be within 1-2 ms of synchronised input
// from 60 fps to at least 1000 fps at ticrates of 30 and 40 Hz.
const double result = elapsedInputTicks * ticrate * (1. / 1000.);
return result * (1. + 0.35 * (1. - ticrate * (1. / 50.)) * (1. - result));
return result * (1. + 0.35 * (1. - GameTicRate * (1. / 50.)) * (1. - result));
}
else
{
return 1;
}
}
else
{
return 1;
}

return 1;
}

void I_ResetInputTime()
Expand Down
2 changes: 1 addition & 1 deletion src/common/utility/i_time.h
Expand Up @@ -40,7 +40,7 @@ uint64_t I_nsTime();
void I_ResetFrameTime();

// Return a decimal fraction to scale input operations at framerate
double I_GetInputFrac(bool const synchronised, double const ticrate = GameTicRate);
double I_GetInputFrac(bool const synchronised);

// Reset the last input check to after a lengthy operation
void I_ResetInputTime();
Expand Down
12 changes: 11 additions & 1 deletion src/d_main.cpp
Expand Up @@ -335,7 +335,6 @@ int restart = 0;
bool AppActive = true;
bool playedtitlemusic;

FStartupScreen* StartWindow;
FStartScreen* StartScreen;

cycle_t FrameCycles;
Expand Down Expand Up @@ -3098,6 +3097,17 @@ static int D_InitGame(const FIWADInfo* iwad_info, TArray<FString>& allwads, TArr
int max_progress = TexMan.GuesstimateNumTextures();
int per_shader_progress = 0;//screen->GetShaderCount()? (max_progress / 10 / screen->GetShaderCount()) : 0;
bool nostartscreen = batchrun || restart || Args->CheckParm("-join") || Args->CheckParm("-host") || Args->CheckParm("-norun");

if (GameStartupInfo.Type == FStartupInfo::DefaultStartup)
{
if (gameinfo.gametype == GAME_Hexen)
GameStartupInfo.Type = FStartupInfo::HexenStartup;
else if (gameinfo.gametype == GAME_Heretic)
GameStartupInfo.Type = FStartupInfo::HereticStartup;
else if (gameinfo.gametype == GAME_Strife)
GameStartupInfo.Type = FStartupInfo::StrifeStartup;
}

StartScreen = nostartscreen? nullptr : GetGameStartScreen(per_shader_progress > 0 ? max_progress * 10 / 9 : max_progress + 3);

GameConfig->DoKeySetup(gameinfo.ConfigName);
Expand Down
8 changes: 6 additions & 2 deletions wadsrc/static/zscript/engine/base.zs
Expand Up @@ -220,13 +220,17 @@ struct System native
native static bool SoundEnabled();
native static bool MusicEnabled();
native static double GetTimeFrac();

static bool specialKeyEvent(InputEvent ev)
{
if (ev.type == InputEvent.Type_KeyDown || ev.type == InputEvent.Type_KeyUp)
{
int key = ev.KeyScan;
if (key == InputEvent.KEY_VOLUMEDOWN || key == InputEvent.KEY_VOLUMEUP || (key > InputEvent.KEY_LASTJOYBUTTON && key < InputEvent.KEY_PAD_LTHUMB_RIGHT)) return true;
let binding = Bindings.GetBinding(key);
bool volumekeys = key == InputEvent.KEY_VOLUMEDOWN || key == InputEvent.KEY_VOLUMEUP;
bool gamepadkeys = key > InputEvent.KEY_LASTJOYBUTTON && key < InputEvent.KEY_PAD_LTHUMB_RIGHT;
bool altkeys = key == InputEvent.KEY_LALT || key == InputEvent.KEY_RALT;
if (volumekeys || gamepadkeys || altkeys || binding ~== "screenshot") return true;
}
return false;
}
Expand Down
12 changes: 6 additions & 6 deletions wadsrc/static/zscript/engine/ui/menu/colorpickermenu.zs
Expand Up @@ -73,20 +73,20 @@ class ColorpickerMenu : OptionMenu
int mStartItem;

CVar mCVar;

double GetColor(int index)
{
double v = index == 0? mRed : index == 1? mGreen : mBlue;
return v;
}

void SetColor(int index, double val)
{
if (index == 0) mRed = val;
else if (index == 1) mGreen = val;
else mBlue = val;
}

//=============================================================================
//
//
Expand Down Expand Up @@ -119,7 +119,7 @@ class ColorpickerMenu : OptionMenu
mDesc.mIndent = 0;
mDesc.CalcIndent();
}

//=============================================================================
//
//
Expand Down Expand Up @@ -273,7 +273,7 @@ class ColorpickerMenu : OptionMenu

if (h > fh) h = fh;
else if (h < 4) return; // no space to draw it.

int indent = (screen.GetWidth() / 2);
int p = 0;

Expand Down Expand Up @@ -328,7 +328,7 @@ class ColorpickerMenu : OptionMenu
y += 49*CleanYfac_1;
screen.DrawText (SmallFont, Font.CR_GRAY, x+(48-SmallFont.StringWidth("---->")/2)*CleanXfac_1, y, "---->", DTA_CleanNoMove_1, true);
}

override void OnDestroy()
{
if (mStartItem >= 0)
Expand Down
30 changes: 15 additions & 15 deletions wadsrc/static/zscript/engine/ui/menu/imagescroller.zs
Expand Up @@ -47,20 +47,20 @@ class ImageScrollerDescriptor : MenuDescriptor native
class ImageScrollerPage : MenuItemBase
{
int virtWidth, virtHeight;

protected void DrawText(Font fnt, int color, double x, double y, String text)
{
screen.DrawText(fnt, color, x, y, text, DTA_VirtualWidth, virtWidth, DTA_VirtualHeight, virtHeight, DTA_FullscreenScale, FSMode_ScaleToFit43);
}

protected void DrawTexture(TextureID tex, double x, double y)
{
screen.DrawTexture(tex, true, x, y, DTA_VirtualWidth, virtWidth, DTA_VirtualHeight, virtHeight, DTA_FullscreenScale, FSMode_ScaleToFit43);
}

virtual void OnStartPage()
{}

virtual void OnEndPage()
{}
}
Expand All @@ -74,13 +74,13 @@ class ImageScrollerPage : MenuItemBase
class ImageScrollerPageImageItem : ImageScrollerPage
{
TextureID mTexture;

void Init(ImageScrollerDescriptor desc, String patch)
{
Super.Init();
mTexture = TexMan.CheckForTexture(patch);
}

override void Drawer(bool selected)
{
Screen.DrawTexture(mTexture, true, 0, 0, DTA_FullscreenEx, FSMode_ScaleToFit43, DTA_LegacyRenderStyle, STYLE_Normal);
Expand All @@ -100,7 +100,7 @@ class ImageScrollerPageTextItem : ImageScrollerPage
TextureID mTexture;
Color mBrightness;
double mTextScale;

void Init(ImageScrollerDescriptor desc, String txt, int y = -1)
{
Super.Init();
Expand All @@ -110,16 +110,16 @@ class ImageScrollerPageTextItem : ImageScrollerPage
mTextScale = desc.textScale;
virtWidth = desc.virtWidth;
virtHeight = desc.virtHeight;

mText = mFont.BreakLines(Stringtable.Localize(txt.Filter()), int(virtWidth / mTextScale));
mYpos = y >= 0? y : virtHeight / 2 - mText.Count() * mFont.GetHeight() * mTextScale / 2;

}

override void Drawer(bool selected)
{
Screen.DrawTexture(mTexture, true, 0, 0, DTA_FullscreenEx, FSMode_ScaleToFit43, DTA_LegacyRenderStyle, STYLE_Normal, DTA_Color, mBrightness);

let fontheight = mFont.GetHeight() * mTextScale;
let y = mYpos;
let c = mText.Count();
Expand Down Expand Up @@ -180,7 +180,7 @@ class ImageScrollerMenu : Menu
//
//
//=============================================================================

override bool MenuEvent(int mkey, bool fromcontroller)
{
if (mDesc.mItems.Size() <= 1)
Expand Down Expand Up @@ -228,7 +228,7 @@ class ImageScrollerMenu : Menu
//
//
//=============================================================================

override bool MouseEvent(int type, int x, int y)
{
// Todo: Implement some form of drag event to switch between pages.
Expand All @@ -244,7 +244,7 @@ class ImageScrollerMenu : Menu
//
//
//=============================================================================

private bool DrawTransition()
{
double now = MSTime() * (120. / 1000.);
Expand All @@ -270,7 +270,7 @@ class ImageScrollerMenu : Menu
//
//
//=============================================================================

override void Drawer()
{
if (previous != null)
Expand Down

0 comments on commit c62e14d

Please sign in to comment.