diff --git a/Core/Debugger/LuaApi.cpp b/Core/Debugger/LuaApi.cpp index bcf03bb4..f4de142d 100644 --- a/Core/Debugger/LuaApi.cpp +++ b/Core/Debugger/LuaApi.cpp @@ -1,6 +1,4 @@ #include "stdafx.h" - -#ifndef LIBRETRO #include "LuaApi.h" #include "Lua/lua.hpp" #include "Debugger/LuaCallHelper.h" @@ -17,6 +15,7 @@ #include "Shared/Emulator.h" #include "Shared/Video/BaseVideoFilter.h" #include "Shared/Video/DrawScreenBufferCommand.h" +#include "Shared/Video/DrawStringCommand.h" #include "Shared/KeyManager.h" #include "Shared/Interfaces/IConsole.h" #include "Shared/Interfaces/IKeyManager.h" @@ -86,7 +85,9 @@ int LuaApi::GetLibrary(lua_State *lua) { "addEventCallback", LuaApi::RegisterEventCallback }, { "removeEventCallback", LuaApi::UnregisterEventCallback }, + { "measureString", LuaApi::MeasureString }, { "drawString", LuaApi::DrawString }, + { "drawPixel", LuaApi::DrawPixel }, { "drawLine", LuaApi::DrawLine }, { "drawRectangle", LuaApi::DrawRectangle }, @@ -278,7 +279,7 @@ int LuaApi::ConvertAddress(lua_State *lua) checkEnum(MemoryType, memType, "invalid memory type"); errorCond(address < 0 || address >= _memoryDumper->GetMemorySize(memType), "address is out of range"); - AddressInfo src { address, memType }; + AddressInfo src { (int32_t)address, memType }; AddressInfo result; if(DebugUtilities::IsRelativeMemory(memType)) { result = _debugger->GetAbsoluteAddress(src); @@ -398,12 +399,28 @@ int LuaApi::UnregisterEventCallback(lua_State *lua) return l.ReturnCount(); } +int LuaApi::MeasureString(lua_State* lua) +{ + LuaCallHelper l(lua); + l.ForceParamCount(2); + int maxWidth = l.ReadInteger(0); + string text = l.ReadString(); + checkminparams(1); + + TextSize size = DrawStringCommand::MeasureString(text, maxWidth); + lua_newtable(lua); + lua_pushintvalue(width, size.X); + lua_pushintvalue(height, size.Y); + return 1; +} + int LuaApi::DrawString(lua_State *lua) { LuaCallHelper l(lua); - l.ForceParamCount(7); + l.ForceParamCount(8); int displayDelay = l.ReadInteger(0); int frameCount = l.ReadInteger(1); + int maxWidth = l.ReadInteger(0); int backColor = l.ReadInteger(0); int color = l.ReadInteger(0xFFFFFF); string text = l.ReadString(); @@ -412,7 +429,7 @@ int LuaApi::DrawString(lua_State *lua) checkminparams(3); int startFrame = _emu->GetFrameCount() + displayDelay; - _emu->GetDebugHud()->DrawString(x, y, text, color, backColor, frameCount, startFrame); + _emu->GetDebugHud()->DrawString(x, y, text, color, backColor, frameCount, startFrame, maxWidth); return l.ReturnCount(); } @@ -934,6 +951,4 @@ int LuaApi::SetState(lua_State* lua) lua_settable(lua, -3); } return 1; -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/Core/Debugger/LuaApi.h b/Core/Debugger/LuaApi.h index e965a498..da331248 100644 --- a/Core/Debugger/LuaApi.h +++ b/Core/Debugger/LuaApi.h @@ -30,8 +30,10 @@ public: static int UnregisterMemoryCallback(lua_State *lua); static int RegisterEventCallback(lua_State *lua); static int UnregisterEventCallback(lua_State *lua); - + + static int MeasureString(lua_State* lua); static int DrawString(lua_State *lua); + static int DrawLine(lua_State *lua); static int DrawPixel(lua_State *lua); static int DrawRectangle(lua_State *lua); diff --git a/Core/Debugger/LuaCallHelper.cpp b/Core/Debugger/LuaCallHelper.cpp index 5c6133b5..c07082d4 100644 --- a/Core/Debugger/LuaCallHelper.cpp +++ b/Core/Debugger/LuaCallHelper.cpp @@ -1,5 +1,4 @@ #include "stdafx.h" -#ifndef LIBRETRO #include "LuaCallHelper.h" LuaCallHelper::LuaCallHelper(lua_State *lua) : _lua(lua) @@ -145,6 +144,4 @@ void LuaCallHelper::Return(string value) int LuaCallHelper::ReturnCount() { return _returnCount; -} - -#endif \ No newline at end of file +} \ No newline at end of file diff --git a/Core/NES/NesCpu.cpp b/Core/NES/NesCpu.cpp index aa592dac..8a3feb72 100644 --- a/Core/NES/NesCpu.cpp +++ b/Core/NES/NesCpu.cpp @@ -280,7 +280,7 @@ uint16_t NesCpu::FetchOperand() default: break; } -#if !defined(LIBRETRO) && !defined(DUMMYCPU) +#if !defined(DUMMYCPU) if(_lastCrashWarning == 0 || _state.CycleCount - _lastCrashWarning > 5000000) { MessageManager::DisplayMessage("Error", "GameCrash", "Invalid OP code - CPU crashed."); _lastCrashWarning = _state.CycleCount; diff --git a/Core/Shared/MessageManager.cpp b/Core/Shared/MessageManager.cpp index 9a06a3e4..59520065 100644 --- a/Core/Shared/MessageManager.cpp +++ b/Core/Shared/MessageManager.cpp @@ -161,7 +161,6 @@ void MessageManager::DisplayMessage(string title, string message, string param1, void MessageManager::Log(string message) { -#ifndef LIBRETRO auto lock = _logLock.AcquireSafe(); if(message.empty()) { message = "------------------------------------------------------"; @@ -170,11 +169,6 @@ void MessageManager::Log(string message) _log.pop_front(); } _log.push_back(message); -#else - if(MessageManager::_messageManager) { - MessageManager::_messageManager->DisplayMessage("", message + "\n"); - } -#endif } void MessageManager::ClearLog() diff --git a/Core/Shared/Video/DrawStringCommand.h b/Core/Shared/Video/DrawStringCommand.h index 4dfd939b..59d4dd0b 100644 --- a/Core/Shared/Video/DrawStringCommand.h +++ b/Core/Shared/Video/DrawStringCommand.h @@ -226,14 +226,15 @@ public: _backColor = (~backColor & 0xFF000000) | (backColor & 0xFFFFFF); } - static TextSize MeasureString(string text, uint32_t maxWidth = 0) + static TextSize MeasureString(string& text, uint32_t maxWidth = 0) { uint32_t maxX = 0; uint32_t x = 0; uint32_t y = 0; uint32_t lineHeight = 9; - auto newLine = [&x, &y, &lineHeight]() { + auto newLine = [&]() { + maxX = std::max(x, maxX); x = 0; y += lineHeight; lineHeight = 9; diff --git a/Utilities/PlatformUtilities.cpp b/Utilities/PlatformUtilities.cpp index d129c077..3d2ccac3 100644 --- a/Utilities/PlatformUtilities.cpp +++ b/Utilities/PlatformUtilities.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" #include "PlatformUtilities.h" -#if !defined(LIBRETRO) && defined(_WIN32) +#ifdef _WIN32 #include #endif @@ -11,21 +11,21 @@ void PlatformUtilities::DisableScreensaver() { //Prevent screensaver/etc from starting while using the emulator //DirectInput devices apparently do not always count as user input - #if !defined(LIBRETRO) && defined(_WIN32) + #ifdef _WIN32 SetThreadExecutionState(ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED | ES_CONTINUOUS); #endif } void PlatformUtilities::EnableScreensaver() { - #if !defined(LIBRETRO) && defined(_WIN32) + #ifdef _WIN32 SetThreadExecutionState(ES_CONTINUOUS); #endif } void PlatformUtilities::EnableHighResolutionTimer() { -#if !defined(LIBRETRO) && defined(_WIN32) + #ifdef _WIN32 //Request a 1ms timer resolution on Windows while a game is running if(!_highResTimerEnabled) { timeBeginPeriod(1); @@ -36,7 +36,7 @@ void PlatformUtilities::EnableHighResolutionTimer() void PlatformUtilities::RestoreTimerResolution() { - #if !defined(LIBRETRO) && defined(_WIN32) + #ifdef _WIN32 if(_highResTimerEnabled) { timeEndPeriod(1); _highResTimerEnabled = false; diff --git a/Utilities/Socket.h b/Utilities/Socket.h index af553bc3..f93763f4 100644 --- a/Utilities/Socket.h +++ b/Utilities/Socket.h @@ -5,7 +5,6 @@ class Socket { private: -#ifndef LIBRETRO #ifdef _WIN32 bool _cleanupWSA = false; #endif @@ -13,7 +12,6 @@ private: uintptr_t _socket = (uintptr_t)~0; bool _connectionError = false; int32_t _UPnPPort = -1; -#endif public: Socket(); diff --git a/Utilities/UTF8Util.h b/Utilities/UTF8Util.h index c60c9662..69c71a4d 100644 --- a/Utilities/UTF8Util.h +++ b/Utilities/UTF8Util.h @@ -11,7 +11,7 @@ namespace utf8 { static std::string encode(const std::u16string &wstr); }; -#if defined(_WIN32) && !defined(LIBRETRO) +#ifdef _WIN32 class ifstream : public std::ifstream { public: