From 0b2c0a2e3344530a9d131101c777408c9b44db9d Mon Sep 17 00:00:00 2001 From: ergo720 <45463469+ergo720@users.noreply.github.com> Date: Mon, 29 Nov 2021 14:45:24 +0100 Subject: [PATCH] review remarks --- src/common/win32/EmuShared.cpp | 2 +- src/common/win32/EmuShared.h | 4 ++-- src/core/common/imgui/ui.cpp | 16 ---------------- src/core/common/imgui/ui.hpp | 2 -- src/core/common/imgui/video.cpp | 16 ++++++++++++++++ src/core/common/imgui/video.hpp | 1 + src/core/hle/D3D8/Direct3D9/Direct3D9.cpp | 5 ----- src/core/hle/XAPI/Xapi.cpp | 2 +- src/core/kernel/exports/EmuKrnlHal.cpp | 6 +++++- src/devices/video/EmuNV2A_PGRAPH.cpp | 7 ------- 10 files changed, 26 insertions(+), 35 deletions(-) diff --git a/src/common/win32/EmuShared.cpp b/src/common/win32/EmuShared.cpp index 43c243640..4df2be0bd 100644 --- a/src/common/win32/EmuShared.cpp +++ b/src/common/win32/EmuShared.cpp @@ -152,7 +152,7 @@ EmuShared::EmuShared() m_bEmulating_status = false; m_bFirstLaunch = false; m_bClipCursor = false; - m_LightgunLaser = 1; // laser on by default + m_LightgunLaser = 0xF; // laser on by default on all ports std::memset(m_DeviceControlNames, '\0', sizeof(m_DeviceControlNames)); std::memset(m_DeviceName, '\0', sizeof(m_DeviceName)); diff --git a/src/common/win32/EmuShared.h b/src/common/win32/EmuShared.h index c7b6c1d9d..964f29049 100644 --- a/src/common/win32/EmuShared.h +++ b/src/common/win32/EmuShared.h @@ -260,8 +260,8 @@ class EmuShared : public Mutex // ****************************************************************** // * LightgunLaser flag Accessors // ****************************************************************** - void GetLightgunLaser(uint8_t *value) { Lock(); *value = m_LightgunLaser; Unlock(); } - void SetLightgunLaser(const uint8_t *value) { Lock(); m_LightgunLaser = *value; Unlock(); } + void GetLightgunLaser(uint8_t *value, int port) { Lock(); *value = (m_LightgunLaser >> port) & 1; Unlock(); } + void SetLightgunLaser(const uint8_t *value, int port) { Lock(); (m_LightgunLaser &= ~(1 << port)) |= ((*value) << port); Unlock(); } // ****************************************************************** // * ImGui Accessors diff --git a/src/core/common/imgui/ui.cpp b/src/core/common/imgui/ui.cpp index 47c0e6d89..680a2bf93 100644 --- a/src/core/common/imgui/ui.cpp +++ b/src/core/common/imgui/ui.cpp @@ -15,13 +15,6 @@ #include "core/kernel/init/CxbxKrnl.h" -const ImColor ImGuiUI::m_laser_col[4] = { - ImColor(ImVec4(1.0f, 0.0f, 0.0f, 1.0f)), // ply1: red - ImColor(ImVec4(0.0f, 1.0f, 0.0f, 1.0f)), // ply2: green - ImColor(ImVec4(0.0f, 0.0f, 1.0f, 1.0f)), // ply3: blue - ImColor(ImVec4(1.0f, 1.0f, 0.0f, 1.0f)) // ply4: yellow -}; - bool ImGuiUI::Initialize() { IMGUI_CHECKVERSION(); @@ -197,12 +190,3 @@ void ImGuiUI::DrawWidgets() m_audio.DrawWidgets(m_is_focus, input_handler); } - -void ImGuiUI::DrawLightgunLaser(int port) -{ - ImGui::Begin("Laser", nullptr, ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoDecoration); - - ImGui::GetForegroundDrawList()->AddCircleFilled(g_InputDeviceManager.CalcLaserPos(port), 5, m_laser_col[port], 0); - - ImGui::End(); -} diff --git a/src/core/common/imgui/ui.hpp b/src/core/common/imgui/ui.hpp index 9fbda490a..19abf1498 100644 --- a/src/core/common/imgui/ui.hpp +++ b/src/core/common/imgui/ui.hpp @@ -32,7 +32,6 @@ public: void DrawMenu(); void DrawWidgets(); - void DrawLightgunLaser(int port); protected: @@ -62,7 +61,6 @@ protected: overlay_settings m_settings; unsigned int m_lle_flags; float fps_counter; - static const ImColor m_laser_col[4]; // Make them as settings storage. /*bool m_show_fps; bool m_show_LLE_stats; diff --git a/src/core/common/imgui/video.cpp b/src/core/common/imgui/video.cpp index 027cf9a3a..8cad468d5 100644 --- a/src/core/common/imgui/video.cpp +++ b/src/core/common/imgui/video.cpp @@ -14,6 +14,13 @@ #include "core/kernel/init/CxbxKrnl.h" #include "core/hle/D3D8/XbVertexBuffer.h" +const ImColor ImGuiVideo::m_laser_col[4] = { + ImColor(ImVec4(1.0f, 0.0f, 0.0f, 1.0f)), // player1: red + ImColor(ImVec4(0.0f, 1.0f, 0.0f, 1.0f)), // player2: green + ImColor(ImVec4(0.0f, 0.0f, 1.0f, 1.0f)), // player3: blue + ImColor(ImVec4(1.0f, 1.0f, 0.0f, 1.0f)) // player4: yellow +}; + bool ImGuiVideo::Initialize() { g_EmuShared->GetImGuiVideoWindows(&m_windows); @@ -46,4 +53,13 @@ void ImGuiVideo::DrawWidgets(bool is_focus, ImGuiWindowFlags input_handler) ImGui::End(); } } + + // Render the lightgun laser + for (int port = PORT_1; port < XBOX_NUM_PORTS; ++port) { + if (g_devs[port].type == XBOX_INPUT_DEVICE::LIGHTGUN && g_devs[port].info.ligthgun.laser) { + ImGui::Begin("Laser", nullptr, ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoDecoration); + ImGui::GetForegroundDrawList()->AddCircleFilled(g_InputDeviceManager.CalcLaserPos(port), 5, m_laser_col[port], 0); + ImGui::End(); + } + } } diff --git a/src/core/common/imgui/video.hpp b/src/core/common/imgui/video.hpp index 687e18055..716b97a13 100644 --- a/src/core/common/imgui/video.hpp +++ b/src/core/common/imgui/video.hpp @@ -20,4 +20,5 @@ public: protected: imgui_video_windows m_windows; + static const ImColor m_laser_col[4]; }; diff --git a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp index 845eaecd3..8cfeec77d 100644 --- a/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp +++ b/src/core/hle/D3D8/Direct3D9/Direct3D9.cpp @@ -194,11 +194,6 @@ static void CxbxImGui_RenderD3D9(ImGuiUI* m_imgui, IDirect3DSurface9* renderTarg m_imgui->DrawMenu(); m_imgui->DrawWidgets(); - for (int port = PORT_1; port < XBOX_NUM_PORTS; ++port) { - if (g_devs[port].type == XBOX_INPUT_DEVICE::LIGHTGUN && g_devs[port].info.ligthgun.laser) { - m_imgui->DrawLightgunLaser(port); - } - } ImGui::EndFrame(); diff --git a/src/core/hle/XAPI/Xapi.cpp b/src/core/hle/XAPI/Xapi.cpp index d39b2b27e..56e874e14 100644 --- a/src/core/hle/XAPI/Xapi.cpp +++ b/src/core/hle/XAPI/Xapi.cpp @@ -268,7 +268,7 @@ void ConstructHleInputDevice(DeviceState *dev, DeviceState *upstream, int type, dev->info.ligthgun.offset_upp_x = dev->info.ligthgun.offset_upp_x = 0; dev->info.ligthgun.last_in_state = dev->info.ligthgun.turbo_delay = 0; dev->info.ligthgun.turbo = dev->info.ligthgun.last_turbo = 0; - g_EmuShared->GetLightgunLaser(&dev->info.ligthgun.laser); + g_EmuShared->GetLightgunLaser(&dev->info.ligthgun.laser, port_num); break; case to_underlying(XBOX_INPUT_DEVICE::STEEL_BATTALION_CONTROLLER): diff --git a/src/core/kernel/exports/EmuKrnlHal.cpp b/src/core/kernel/exports/EmuKrnlHal.cpp index 137680265..987405ba4 100644 --- a/src/core/kernel/exports/EmuKrnlHal.cpp +++ b/src/core/kernel/exports/EmuKrnlHal.cpp @@ -536,7 +536,11 @@ XBSYSAPI EXPORTNUM(49) xbox::void_xt DECLSPEC_NORETURN NTAPI xbox::HalReturnToFi } // Save lightgun laser status - g_EmuShared->SetLightgunLaser(&g_devs->info.ligthgun.laser); + for (int port = PORT_1; port < XBOX_NUM_PORTS; ++port) { + if (g_devs[port].type == XBOX_INPUT_DEVICE::LIGHTGUN) { + g_EmuShared->SetLightgunLaser(&g_devs[port].info.ligthgun.laser, port); + } + } std::string TitlePath = xbox::LaunchDataPage->Header.szLaunchPath; diff --git a/src/devices/video/EmuNV2A_PGRAPH.cpp b/src/devices/video/EmuNV2A_PGRAPH.cpp index c349ffdf0..9e7f8acf1 100644 --- a/src/devices/video/EmuNV2A_PGRAPH.cpp +++ b/src/devices/video/EmuNV2A_PGRAPH.cpp @@ -33,8 +33,6 @@ // * // ****************************************************************** -#include "common\input\InputManager.h" - // FIXME #define qemu_mutex_lock_iothread() #define qemu_mutex_unlock_iothread() @@ -715,11 +713,6 @@ static void CxbxImGui_RenderOpenGL(ImGuiUI* m_imgui, std::nullptr_t unused) m_imgui->DrawMenu(); m_imgui->DrawWidgets(); - for (int port = PORT_1; port < XBOX_NUM_PORTS; ++port) { - if (g_devs[port].type == XBOX_INPUT_DEVICE::LIGHTGUN && g_devs[port].info.ligthgun.laser) { - m_imgui->DrawLightgunLaser(port); - } - } ImGui::Render();