diff --git a/source/common/2d/v_draw.cpp b/source/common/2d/v_draw.cpp index 55521e78b18..e41a2eec8b4 100644 --- a/source/common/2d/v_draw.cpp +++ b/source/common/2d/v_draw.cpp @@ -682,13 +682,13 @@ static inline FSpecialColormap * ListGetSpecialColormap(VMVa_List &tags) //========================================================================== template -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(F2DDrawer* drawer, FGameTexture *img, double x, double y, uint32_t tag, Va_List& tags, DrawParms *parms, bool fortext); -template bool ParseDrawTextureTags(F2DDrawer* drawer, FGameTexture *img, double x, double y, uint32_t tag, VMVa_List& tags, DrawParms *parms, bool fortext); +template bool ParseDrawTextureTags(F2DDrawer* drawer, FGameTexture *img, double x, double y, uint32_t tag, Va_List& tags, DrawParms *parms, bool fortext, bool checkimage); +template bool ParseDrawTextureTags(F2DDrawer* drawer, FGameTexture *img, double x, double y, uint32_t tag, VMVa_List& tags, DrawParms *parms, bool fortext, bool checkimage); //========================================================================== // diff --git a/source/common/2d/v_draw.h b/source/common/2d/v_draw.h index 7b1dfa9b698..f4746af99d3 100644 --- a/source/common/2d/v_draw.h +++ b/source/common/2d/v_draw.h @@ -259,7 +259,7 @@ inline int active_con_scale(F2DDrawer *drawer) #endif template -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 void DrawTextCommon(F2DDrawer *drawer, FFont* font, int normalcolor, double x, double y, const T* string, DrawParms& parms); diff --git a/source/common/console/c_console.cpp b/source/common/console/c_console.cpp index fb7fe077d2c..ca8540dd49d 100644 --- a/source/common/console/c_console.cpp +++ b/source/common/console/c_console.cpp @@ -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; diff --git a/source/common/console/c_console.h b/source/common/console/c_console.h index 2d79992bf8e..8fff823b464 100644 --- a/source/common/console/c_console.h +++ b/source/common/console/c_console.h @@ -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); diff --git a/source/common/engine/renderstyle.h b/source/common/engine/renderstyle.h index 70ad5d56140..272f23ba51e 100644 --- a/source/common/engine/renderstyle.h +++ b/source/common/engine/renderstyle.h @@ -39,10 +39,7 @@ #undef OPAQUE #endif -enum -{ - OPAQUE = 65536, -}; +constexpr int OPAQUE = 65536; enum ETexMode { diff --git a/source/common/platform/posix/cocoa/i_input.mm b/source/common/platform/posix/cocoa/i_input.mm index f53ae8ebcf5..79f9d037c1e 100644 --- a/source/common/platform/posix/cocoa/i_input.mm +++ b/source/common/platform/posix/cocoa/i_input.mm @@ -56,7 +56,6 @@ CVAR(Bool, k_allowfullscreentoggle, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) extern int paused, chatmodeon; -extern constate_e ConsoleState; extern bool ToggleFullscreen; bool GUICapture; diff --git a/source/common/platform/posix/sdl/i_input.cpp b/source/common/platform/posix/sdl/i_input.cpp index 66c1c252382..933423e6243 100644 --- a/source/common/platform/posix/sdl/i_input.cpp +++ b/source/common/platform/posix/sdl/i_input.cpp @@ -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] = { diff --git a/source/common/platform/win32/i_input.cpp b/source/common/platform/win32/i_input.cpp index a5ea5ad445a..f8b2c429b3a 100644 --- a/source/common/platform/win32/i_input.cpp +++ b/source/common/platform/win32/i_input.cpp @@ -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 () diff --git a/source/common/platform/win32/i_keyboard.cpp b/source/common/platform/win32/i_keyboard.cpp index e1222d9697b..33cf6da5ba0 100644 --- a/source/common/platform/win32/i_keyboard.cpp +++ b/source/common/platform/win32/i_keyboard.cpp @@ -89,7 +89,6 @@ class FRawKeyboard : public FKeyboard // 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) diff --git a/source/common/platform/win32/i_main.cpp b/source/common/platform/win32/i_main.cpp index f414351a893..f153a1dac2c 100644 --- a/source/common/platform/win32/i_main.cpp +++ b/source/common/platform/win32/i_main.cpp @@ -43,6 +43,7 @@ #include #include +#include #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; } } diff --git a/source/common/platform/win32/i_mouse.cpp b/source/common/platform/win32/i_mouse.cpp index 15e52ce75f3..f9fb1b8ab7b 100644 --- a/source/common/platform/win32/i_mouse.cpp +++ b/source/common/platform/win32/i_mouse.cpp @@ -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) diff --git a/source/common/platform/win32/i_system.cpp b/source/common/platform/win32/i_system.cpp index 68a1261ea2c..02cd8ff9ef6 100644 --- a/source/common/platform/win32/i_system.cpp +++ b/source/common/platform/win32/i_system.cpp @@ -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) - { - OutputDebugStringW(wbuf); - } - if (StdOut != nullptr) + if (*srcp == 0x1c && terminal) { - // Convert back to UTF-8. - DWORD bytes_written; - if (!FancyStdOut) - { - FString conout(wbuf); - WriteFile(StdOut, conout.GetChars(), (DWORD)conout.Len(), &bytes_written, NULL); - } - else + 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) { - 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) - { - outputIt(); - } - if (chr != TEXTCOLOR_ESCAPE) + else if (*srcp != 0x1c && *srcp != 0x1d && *srcp != 0x1e && *srcp != 0x1f) { - 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) diff --git a/source/common/scripting/interface/vmnatives.cpp b/source/common/scripting/interface/vmnatives.cpp index 079cd78ae95..7754cca2217 100644 --- a/source/common/scripting/interface/vmnatives.cpp +++ b/source/common/scripting/interface/vmnatives.cpp @@ -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(); diff --git a/source/common/textures/textureid.h b/source/common/textures/textureid.h index c7a6355cc06..e30b4e86ad6 100644 --- a/source/common/textures/textureid.h +++ b/source/common/textures/textureid.h @@ -35,7 +35,7 @@ class FTextureID 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! diff --git a/source/common/textures/texturemanager.cpp b/source/common/textures/texturemanager.cpp index af57204fc4b..cc070bcd6c9 100644 --- a/source/common/textures/texturemanager.cpp +++ b/source/common/textures/texturemanager.cpp @@ -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); diff --git a/source/common/utility/vectors.h b/source/common/utility/vectors.h index 1e5fa9f3a8e..cb927b4c2d2 100644 --- a/source/common/utility/vectors.h +++ b/source/common/utility/vectors.h @@ -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) { diff --git a/wadsrc/static/zscript/engine/base.zs b/wadsrc/static/zscript/engine/base.zs index 106c0a57587..45e178af0e9 100644 --- a/wadsrc/static/zscript/engine/base.zs +++ b/wadsrc/static/zscript/engine/base.zs @@ -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