- Backend update from GZDoom.

This commit is contained in:
Christoph Oelckers 2022-07-20 14:47:18 +02:00 committed by Mitchell Richters
parent b9ee6c327d
commit abb7f87de3
17 changed files with 77 additions and 188 deletions

View file

@ -682,13 +682,13 @@ static inline FSpecialColormap * ListGetSpecialColormap(VMVa_List &tags)
//==========================================================================
template<class T>
bool ParseDrawTextureTags(F2DDrawer *drawer, FGameTexture *img, double x, double y, uint32_t tag, T& tags, DrawParms *parms, bool fortext)
bool ParseDrawTextureTags(F2DDrawer *drawer, FGameTexture *img, double x, double y, uint32_t tag, T& tags, DrawParms *parms, bool fortext, bool checkimage)
{
INTBOOL boolval;
int intval;
bool fillcolorset = false;
if (!fortext)
if (!fortext && checkimage)
{
if (img == NULL || !img->isValid())
{
@ -1285,8 +1285,8 @@ bool ParseDrawTextureTags(F2DDrawer *drawer, FGameTexture *img, double x, double
}
// explicitly instantiate both versions for v_text.cpp.
template bool ParseDrawTextureTags<Va_List>(F2DDrawer* drawer, FGameTexture *img, double x, double y, uint32_t tag, Va_List& tags, DrawParms *parms, bool fortext);
template bool ParseDrawTextureTags<VMVa_List>(F2DDrawer* drawer, FGameTexture *img, double x, double y, uint32_t tag, VMVa_List& tags, DrawParms *parms, bool fortext);
template bool ParseDrawTextureTags<Va_List>(F2DDrawer* drawer, FGameTexture *img, double x, double y, uint32_t tag, Va_List& tags, DrawParms *parms, bool fortext, bool checkimage);
template bool ParseDrawTextureTags<VMVa_List>(F2DDrawer* drawer, FGameTexture *img, double x, double y, uint32_t tag, VMVa_List& tags, DrawParms *parms, bool fortext, bool checkimage);
//==========================================================================
//

View file

@ -259,7 +259,7 @@ inline int active_con_scale(F2DDrawer *drawer)
#endif
template<class T>
bool ParseDrawTextureTags(F2DDrawer *drawer, FGameTexture* img, double x, double y, uint32_t tag, T& tags, DrawParms* parms, bool fortext);
bool ParseDrawTextureTags(F2DDrawer *drawer, FGameTexture* img, double x, double y, uint32_t tag, T& tags, DrawParms* parms, bool fortext, bool checkimage = true);
template<class T>
void DrawTextCommon(F2DDrawer *drawer, FFont* font, int normalcolor, double x, double y, const T* string, DrawParms& parms);

View file

@ -104,7 +104,9 @@ bool vidactive = false;
bool cursoron = false;
int ConBottom, ConScroll, RowAdjust;
uint64_t CursorTicker;
constate_e ConsoleState = c_up;
uint8_t ConsoleState = c_up;
DEFINE_GLOBAL(ConsoleState)
static int TopLine, InsertLine;

View file

@ -41,11 +41,10 @@
struct event_t;
typedef enum cstate_t
enum cstate_t : uint8_t
{
c_up=0, c_down=1, c_falling=2, c_rising=3
}
constate_e;
};
enum
{
@ -53,7 +52,7 @@ enum
};
extern int PrintColors[PRINTLEVELS + 2];
extern constate_e ConsoleState;
extern uint8_t ConsoleState;
// Initialize the console
void C_InitConsole (int width, int height, bool ingame);

View file

@ -39,10 +39,7 @@
#undef OPAQUE
#endif
enum
{
OPAQUE = 65536,
};
constexpr int OPAQUE = 65536;
enum ETexMode
{

View file

@ -56,7 +56,6 @@ CVAR(Bool, use_mouse, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Bool, k_allowfullscreentoggle, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
extern int paused, chatmodeon;
extern constate_e ConsoleState;
extern bool ToggleFullscreen;
bool GUICapture;

View file

@ -57,7 +57,6 @@ CVAR (Bool, use_mouse, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
extern int WaitingForKey, chatmodeon;
extern constate_e ConsoleState;
static const SDL_Keycode DIKToKeySym[256] =
{

View file

@ -93,7 +93,6 @@ FJoystickCollection *JoyDevices[NUM_JOYDEVICES];
extern HINSTANCE g_hInst;
static HMODULE DInputDLL;
bool GUICapture;
extern FMouse *Mouse;
@ -116,7 +115,6 @@ extern BOOL paused;
static bool noidle = false;
LPDIRECTINPUT8 g_pdi;
LPDIRECTINPUT g_pdi3;
extern bool AppActive;
@ -523,58 +521,12 @@ bool I_InitInput (void *hwnd)
noidle = !!Args->CheckParm ("-noidle");
g_pdi = NULL;
g_pdi3 = NULL;
// Try for DirectInput 8 first, then DirectInput 3 for NT 4's benefit.
DInputDLL = LoadLibraryA("dinput8.dll");
if (DInputDLL != NULL)
hr = DirectInput8Create(g_hInst, DIRECTINPUT_VERSION, IID_IDirectInput8, (void **)&g_pdi, NULL);
if (FAILED(hr))
{
typedef HRESULT (WINAPI *blah)(HINSTANCE, DWORD, REFIID, LPVOID *, LPUNKNOWN);
blah di8c = (blah)GetProcAddress(DInputDLL, "DirectInput8Create");
if (di8c != NULL)
{
hr = di8c(g_hInst, DIRECTINPUT_VERSION, IID_IDirectInput8, (void **)&g_pdi, NULL);
if (FAILED(hr))
{
Printf(TEXTCOLOR_ORANGE "DirectInput8Create failed: %08lx\n", hr);
g_pdi = NULL; // Just to be sure DirectInput8Create didn't change it
}
}
else
{
Printf(TEXTCOLOR_ORANGE "Could not find DirectInput8Create in dinput8.dll\n");
}
}
if (g_pdi == NULL)
{
if (DInputDLL != NULL)
{
FreeLibrary(DInputDLL);
}
DInputDLL = LoadLibraryA ("dinput.dll");
if (DInputDLL == NULL)
{
I_FatalError ("Could not load dinput.dll: %08lx", GetLastError());
}
typedef HRESULT (WINAPI *blah)(HINSTANCE, DWORD, LPDIRECTINPUT*, LPUNKNOWN);
#ifdef UNICODE
blah dic = (blah)GetProcAddress (DInputDLL, "DirectInputCreateW");
#else
blah dic = (blah)GetProcAddress(DInputDLL, "DirectInputCreateA");
#endif
if (dic == NULL)
{
I_FatalError ("dinput.dll is corrupt");
}
hr = dic (g_hInst, 0x0300, &g_pdi3, NULL);
if (FAILED(hr))
{
I_FatalError ("DirectInputCreate failed: %08lx", hr);
}
Printf(TEXTCOLOR_ORANGE "DirectInput8Create failed: %08lx\n", hr);
g_pdi = NULL; // Just to be sure DirectInput8Create didn't change it
}
Printf ("I_StartupMouse\n");
@ -622,16 +574,6 @@ void I_ShutdownInput ()
g_pdi->Release ();
g_pdi = NULL;
}
if (g_pdi3)
{
g_pdi3->Release ();
g_pdi3 = NULL;
}
if (DInputDLL != NULL)
{
FreeLibrary (DInputDLL);
DInputDLL = NULL;
}
}
void I_GetEvent ()

View file

@ -89,7 +89,6 @@ protected:
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
extern LPDIRECTINPUT8 g_pdi;
extern LPDIRECTINPUT g_pdi3;
extern bool GUICapture;
// PRIVATE DATA DEFINITIONS ------------------------------------------------
@ -320,17 +319,13 @@ bool FDInputKeyboard::GetDevice()
{
HRESULT hr;
if (g_pdi3 != NULL)
{ // DirectInput3 interface
hr = g_pdi3->CreateDevice(GUID_SysKeyboard, (LPDIRECTINPUTDEVICE*)&Device, NULL);
}
else if (g_pdi != NULL)
if (g_pdi != NULL)
{ // DirectInput8 interface
hr = g_pdi->CreateDevice(GUID_SysKeyboard, &Device, NULL);
}
else
{
hr = -1;
hr = E_FAIL;
}
if (FAILED(hr))
{
@ -383,7 +378,7 @@ void FDInputKeyboard::ProcessInput()
for (;;)
{
DWORD cbObjectData = g_pdi3 ? sizeof(DIDEVICEOBJECTDATA_DX3) : sizeof(DIDEVICEOBJECTDATA);
DWORD cbObjectData = sizeof(DIDEVICEOBJECTDATA);
dwElements = 1;
hr = Device->GetDeviceData(cbObjectData, &od, &dwElements, 0);
if (hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED)

View file

@ -43,6 +43,7 @@
#include <processenv.h>
#include <shellapi.h>
#include <VersionHelpers.h>
#ifdef _MSC_VER
#pragma warning(disable:4244)
@ -179,7 +180,7 @@ int DoMain (HINSTANCE hInstance)
StdOut = NULL;
}
}
if (StdOut == NULL)
if (StdOut == nullptr)
{
if (AttachConsole(ATTACH_PARENT_PROCESS))
{
@ -187,25 +188,21 @@ int DoMain (HINSTANCE hInstance)
DWORD foo; WriteFile(StdOut, "\n", 1, &foo, NULL);
AttachedStdOut = true;
}
if (StdOut == NULL && AllocConsole())
if (StdOut == nullptr && AllocConsole())
{
StdOut = GetStdHandle(STD_OUTPUT_HANDLE);
}
// Deprecated stuff for legacy consoles. As of now this is still relevant, but this code can be removed once Windows 7 is no longer relevant.
CONSOLE_FONT_INFOEX cfi;
cfi.cbSize = sizeof(cfi);
if (GetCurrentConsoleFontEx(StdOut, false, &cfi))
if (StdOut != nullptr)
{
if (*cfi.FaceName == 0) // If the face name is empty, the default (useless) raster font is actoive.
SetConsoleCP(CP_UTF8);
SetConsoleOutputCP(CP_UTF8);
DWORD mode;
if (GetConsoleMode(StdOut, &mode))
{
//cfi.dwFontSize = { 8, 14 };
wcscpy(cfi.FaceName, L"Lucida Console");
cfi.FontFamily = FF_DONTCARE;
SetCurrentConsoleFontEx(StdOut, false, &cfi);
if (SetConsoleMode(StdOut, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING))
FancyStdOut = IsWindows10OrGreater(); // Windows 8.1 and lower do not understand ANSI formatting.
}
}
FancyStdOut = true;
}
}

View file

@ -140,7 +140,6 @@ static void CenterMouse(int x, int y, LONG *centx, LONG *centy);
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
extern LPDIRECTINPUT8 g_pdi;
extern LPDIRECTINPUT g_pdi3;
extern bool GUICapture;
extern int BlockMouseMove;
@ -680,17 +679,13 @@ bool FDInputMouse::GetDevice()
{
HRESULT hr;
if (g_pdi3 != NULL)
{ // DirectInput3 interface
hr = g_pdi3->CreateDevice(GUID_SysMouse, (LPDIRECTINPUTDEVICE*)&Device, NULL);
}
else if (g_pdi != NULL)
if (g_pdi != NULL)
{ // DirectInput8 interface
hr = g_pdi->CreateDevice(GUID_SysMouse, &Device, NULL);
}
else
{
hr = -1;
hr = E_FAIL;
}
if (FAILED(hr))
{
@ -783,7 +778,7 @@ void FDInputMouse::ProcessInput()
event_t ev = { 0 };
for (;;)
{
DWORD cbObjectData = g_pdi3 ? sizeof(DIDEVICEOBJECTDATA_DX3) : sizeof(DIDEVICEOBJECTDATA);
DWORD cbObjectData = sizeof(DIDEVICEOBJECTDATA);
dwElements = 1;
hr = Device->GetDeviceData(cbObjectData, &od, &dwElements, 0);
if (hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED)

View file

@ -278,97 +278,38 @@ void CalculateCPUSpeed()
static void PrintToStdOut(const char *cpt, HANDLE StdOut)
{
if (StdOut == nullptr && !con_debugoutput)
return;
const char* srcp = cpt;
FString printData = "";
bool terminal = FancyStdOut;
wchar_t wbuf[256];
int bpos = 0;
const uint8_t *cptr = (const uint8_t*)cpt;
auto outputIt = [&]()
while (*srcp != 0)
{
wbuf[bpos] = 0;
if (con_debugoutput)
if (*srcp == 0x1c && terminal)
{
OutputDebugStringW(wbuf);
}
if (StdOut != nullptr)
{
// Convert back to UTF-8.
DWORD bytes_written;
if (!FancyStdOut)
srcp += 1;
const uint8_t* scratch = (const uint8_t*)srcp; // GCC does not like direct casting of the parameter.
EColorRange range = V_ParseFontColor(scratch, CR_UNTRANSLATED, CR_YELLOW);
srcp = (char*)scratch;
if (range != CR_UNDEFINED)
{
FString conout(wbuf);
WriteFile(StdOut, conout.GetChars(), (DWORD)conout.Len(), &bytes_written, NULL);
}
else
{
WriteConsoleW(StdOut, wbuf, bpos, &bytes_written, nullptr);
PalEntry color = V_LogColorFromColorRange(range);
printData.AppendFormat("\033[38;2;%u;%u;%um", color.r, color.g, color.b);
}
}
bpos = 0;
};
while (int chr = GetCharFromString(cptr))
{
if ((chr == TEXTCOLOR_ESCAPE && bpos != 0) || bpos == 255)
else if (*srcp != 0x1c && *srcp != 0x1d && *srcp != 0x1e && *srcp != 0x1f)
{
outputIt();
}
if (chr != TEXTCOLOR_ESCAPE)
{
if (chr >= 0x1D && chr <= 0x1F)
{ // The bar characters, most commonly used to indicate map changes
chr = 0x2550; // Box Drawings Double Horizontal
}
wbuf[bpos++] = chr;
printData += *srcp++;
}
else
{
EColorRange range = V_ParseFontColor(cptr, CR_UNTRANSLATED, CR_YELLOW);
if (range != CR_UNDEFINED)
{
// Change the color of future text added to the control.
PalEntry color = V_LogColorFromColorRange(range);
if (StdOut != NULL && FancyStdOut)
{
// Unfortunately, we are pretty limited here: There are only
// eight basic colors, and each comes in a dark and a bright
// variety.
float h, s, v, r, g, b;
int attrib = 0;
RGBtoHSV(color.r / 255.f, color.g / 255.f, color.b / 255.f, &h, &s, &v);
if (s != 0)
{ // color
HSVtoRGB(&r, &g, &b, h, 1, 1);
if (r == 1) attrib = FOREGROUND_RED;
if (g == 1) attrib |= FOREGROUND_GREEN;
if (b == 1) attrib |= FOREGROUND_BLUE;
if (v > 0.6) attrib |= FOREGROUND_INTENSITY;
}
else
{ // gray
if (v < 0.33) attrib = FOREGROUND_INTENSITY;
else if (v < 0.90) attrib = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
else attrib = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY;
}
SetConsoleTextAttribute(StdOut, (WORD)attrib);
}
}
if (srcp[1] != 0) srcp += 2;
else break;
}
}
if (bpos != 0)
{
outputIt();
}
if (StdOut != NULL && FancyStdOut)
{ // Set text back to gray, in case it was changed.
SetConsoleTextAttribute(StdOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
}
DWORD bytes_written;
WriteFile(StdOut, printData.GetChars(), (DWORD)printData.Len(), &bytes_written, NULL);
if (terminal)
WriteFile(StdOut, "\033[0m", 4, &bytes_written, NULL);
}
void I_PrintStr(const char *cp)

View file

@ -1009,6 +1009,18 @@ DEFINE_ACTION_FUNCTION(_Console, Printf)
return 0;
}
DEFINE_ACTION_FUNCTION(_Console, PrintfEx)
{
PARAM_PROLOGUE;
PARAM_INT(printlevel);
PARAM_VA_POINTER(va_reginfo) // Get the hidden type information array
FString s = FStringFormat(VM_ARGS_NAMES,1);
Printf(printlevel,"%s\n", s.GetChars());
return 0;
}
static void StopAllSounds()
{
soundEngine->StopAllChannels();

View file

@ -35,7 +35,7 @@ public:
void SetNull() { texnum = 0; }
bool operator ==(const FTextureID &other) const { return texnum == other.texnum; }
bool operator !=(const FTextureID &other) const { return texnum != other.texnum; }
FTextureID operator +(int offset) throw();
FTextureID operator +(int offset) const noexcept(true);
int GetIndex() const { return texnum; } // Use this only if you absolutely need the index!
void SetIndex(int index) { texnum = index; } // Use this only if you absolutely need the index!

View file

@ -1615,7 +1615,7 @@ void FTextureManager::AddAlias(const char* name, FGameTexture* tex)
//
//==========================================================================
FTextureID FTextureID::operator +(int offset) throw()
FTextureID FTextureID::operator +(int offset) const noexcept(true)
{
if (!isValid()) return *this;
if (texnum + offset >= TexMan.NumTextures()) return FTextureID(-1);

View file

@ -915,6 +915,7 @@ struct TMatrix3x3
TMatrix3x3() = default;
TMatrix3x3(const TMatrix3x3 &other) = default;
TMatrix3x3& operator=(const TMatrix3x3& other) = default;
TMatrix3x3(const Vector3 &row1, const Vector3 &row2, const Vector3 &row3)
{

View file

@ -143,6 +143,14 @@ enum EPrintLevel
PRINT_NOLOG = 2048, // Flag - do not print to log file
};
enum EConsoleState
{
c_up = 0,
c_down = 1,
c_falling = 2,
c_rising = 3
};
/*
// These are here to document the intrinsic methods and fields available on
// the built-in ZScript types
@ -211,6 +219,7 @@ struct _ native // These are the global variables, the struct is only here to av
native readonly int consoleplayer;
native readonly double NotifyFontScale;
native readonly int paused;
native readonly ui uint8 ConsoleState;
}
struct System native
@ -601,6 +610,7 @@ struct Console native
{
native static void HideConsole();
native static vararg void Printf(string fmt, ...);
native static vararg void PrintfEx(int printlevel, string fmt, ...);
}
struct CVar native