Skip to content

Commit

Permalink
Add slider to change crosshair size and a core option for the Libretr…
Browse files Browse the repository at this point in the history
…o core (#1304)
  • Loading branch information
bslenul authored Nov 18, 2023
1 parent 665ef86 commit 78a874d
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 16 deletions.
1 change: 1 addition & 0 deletions core/cfg/option.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ std::array<Option<int>, 4> CrosshairColor {
Option<int>("rend.CrossHairColor3"),
Option<int>("rend.CrossHairColor4"),
};
Option<int> CrosshairSize("rend.CrosshairSize", 40);
Option<int> SkipFrame("ta.skip");
Option<int> MaxThreads("pvr.MaxThreads", 3);
Option<int> AutoSkipFrame("pvr.AutoSkipFrame", 0);
Expand Down
1 change: 1 addition & 0 deletions core/cfg/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ extern Option<bool> PerStripSorting;
extern Option<bool> DelayFrameSwapping; // Delay swapping frame until FB_R_SOF matches FB_W_SOF
extern Option<bool> WidescreenGameHacks;
extern std::array<Option<int>, 4> CrosshairColor;
extern Option<int> CrosshairSize;
extern Option<int> SkipFrame;
extern Option<int> MaxThreads;
extern Option<int> AutoSkipFrame; // 0: none, 1: some, 2: more
Expand Down
6 changes: 3 additions & 3 deletions core/rend/dx11/dx11_overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ void DX11Overlay::draw(u32 width, u32 height, bool vmu, bool crosshair)

auto [x, y] = getCrosshairPosition(i);
#ifdef LIBRETRO
float halfWidth = LIGHTGUN_CROSSHAIR_SIZE / 2.f / config::ScreenStretching * 100.f * config::RenderResolution / 480.f;
float halfHeight = LIGHTGUN_CROSSHAIR_SIZE / 2.f * config::RenderResolution / 480.f;
float halfWidth = lightgun_crosshair_size / 2.f / config::ScreenStretching * 100.f * config::RenderResolution / 480.f;
float halfHeight = lightgun_crosshair_size / 2.f * config::RenderResolution / 480.f;
x /= config::ScreenStretching / 100.f;
#else
float halfWidth = XHAIR_WIDTH * settings.display.uiScale / 2.f;
float halfWidth = config::CrosshairSize * settings.display.uiScale / 2.f;
float halfHeight = halfWidth;
#endif
D3D11_VIEWPORT vp{};
Expand Down
2 changes: 1 addition & 1 deletion core/rend/dx9/d3d_overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ void D3DOverlay::draw(u32 width, u32 height, bool vmu, bool crosshair)
continue;

auto [x, y] = getCrosshairPosition(i);
float halfWidth = XHAIR_WIDTH * settings.display.uiScale / 2.f;
float halfWidth = config::CrosshairSize * settings.display.uiScale / 2.f;
RECT rect { (long) (x - halfWidth), (long) (y - halfWidth), (long) (x + halfWidth), (long) (y + halfWidth) };
D3DCOLOR color = (config::CrosshairColor[i] & 0xFF00FF00)
| ((config::CrosshairColor[i] >> 16) & 0xFF)
Expand Down
4 changes: 2 additions & 2 deletions core/rend/gles/gldraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -919,8 +919,8 @@ void DrawGunCrosshair(u8 port, int width, int height)
if (lightgun_params[port].offscreen || lightgun_params[port].colour == 0)
return;

float w = (float)LIGHTGUN_CROSSHAIR_SIZE * 4.f / 3.f / gl.ofbo.aspectRatio * config::RenderResolution / 480.f;
float h = (float)LIGHTGUN_CROSSHAIR_SIZE * config::RenderResolution / 480.f;
float w = lightgun_crosshair_size * 4.f / 3.f / gl.ofbo.aspectRatio * config::RenderResolution / 480.f;
float h = lightgun_crosshair_size * config::RenderResolution / 480.f;
auto [x, y] = getCrosshairPosition(port);
x -= w / 2;
y -= h / 2;
Expand Down
6 changes: 3 additions & 3 deletions core/rend/gles/opengl_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ void OpenGLDriver::displayCrosshairs()

ImVec2 pos;
std::tie(pos.x, pos.y) = getCrosshairPosition(i);
pos.x -= (XHAIR_WIDTH * settings.display.uiScale) / 2.f;
pos.y += (XHAIR_WIDTH * settings.display.uiScale) / 2.f;
ImVec2 pos_b(pos.x + XHAIR_WIDTH * settings.display.uiScale, pos.y - XHAIR_HEIGHT * settings.display.uiScale);
pos.x -= (config::CrosshairSize * settings.display.uiScale) / 2.f;
pos.y += (config::CrosshairSize * settings.display.uiScale) / 2.f;
ImVec2 pos_b(pos.x + config::CrosshairSize * settings.display.uiScale, pos.y - config::CrosshairSize * settings.display.uiScale);

ImGui::GetWindowDrawList()->AddImage(crosshairTexId, pos, pos_b, ImVec2(0, 1), ImVec2(1, 0), config::CrosshairColor[i]);
}
Expand Down
6 changes: 6 additions & 0 deletions core/rend/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,7 @@ static void gui_display_settings()
ImGui::Spacing();
header("Dreamcast Devices");
{
bool is_there_any_xhair = false;
for (int bus = 0; bus < MAPLE_PORTS; bus++)
{
ImGui::Text("Device %c", bus + 'A');
Expand Down Expand Up @@ -1790,10 +1791,15 @@ static void gui_display_settings()
config::CrosshairColor[bus] = 0;
}
}
is_there_any_xhair |= enabled;
ImGui::PopID();
}
ImGui::PopItemWidth();
}
{
DisabledScope scope(!is_there_any_xhair);
OptionSlider("Crosshair Size", config::CrosshairSize, 10, 100);
}
OptionCheckbox("Per Game VMU A1", config::PerGameVmu, "When enabled, each game has its own VMU on port 1 of controller A.");
}

Expand Down
3 changes: 0 additions & 3 deletions core/rend/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ void push_vmu_screen(int bus_id, int bus_port, u8* buffer);
const u32 *getCrosshairTextureData();
std::pair<float, float> getCrosshairPosition(int playerNum);

constexpr int XHAIR_WIDTH = 40;
constexpr int XHAIR_HEIGHT = 40;

static inline bool crosshairsNeeded()
{
if (config::CrosshairColor[0] == 0 && config::CrosshairColor[1] == 0
Expand Down
8 changes: 4 additions & 4 deletions core/rend/vulkan/overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ void VulkanOverlay::Draw(vk::CommandBuffer commandBuffer, vk::Extent2D viewport,
auto [x, y] = getCrosshairPosition(i);

#ifdef LIBRETRO
float w = LIGHTGUN_CROSSHAIR_SIZE * scaling / config::ScreenStretching * 100.f;
float h = LIGHTGUN_CROSSHAIR_SIZE * scaling;
float w = lightgun_crosshair_size * scaling / config::ScreenStretching * 100.f;
float h = lightgun_crosshair_size * scaling;
x /= config::ScreenStretching / 100.f;
#else
float w = XHAIR_WIDTH * scaling;
float h = XHAIR_HEIGHT * scaling;
float w = config::CrosshairSize * scaling;
float h = config::CrosshairSize * scaling;
#endif
x -= w / 2;
y -= h / 2;
Expand Down
9 changes: 9 additions & 0 deletions shell/libretro/libretro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,9 @@ static bool set_variable_visibility(void)
{
option_display.visible = lightgunSettingsShown;

option_display.key = CORE_OPTION_NAME "_lightgun_crosshair_size_scaling";
environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY, &option_display);

for (unsigned i = 0; i < 4; i++)
{
char key[256];
Expand Down Expand Up @@ -911,6 +914,12 @@ static void update_variables(bool first_startup)
else
allow_service_buttons = false;

var.key = CORE_OPTION_NAME "_lightgun_crosshair_size_scaling";
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
lightgun_crosshair_size = (float)LIGHTGUN_CROSSHAIR_SIZE * std::stof(var.value) / 100.f;
else
lightgun_crosshair_size = (float)LIGHTGUN_CROSSHAIR_SIZE;

char key[256];
key[0] = '\0';

Expand Down
38 changes: 38 additions & 0 deletions shell/libretro/libretro_core_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,44 @@ struct retro_core_option_v2_definition option_defs_us[] = {
},
"disabled"
},
{
CORE_OPTION_NAME "_lightgun_crosshair_size_scaling",
"Gun Crosshair Size Scaling",
NULL,
"",
NULL,
"input",
{
{ "50%", NULL },
{ "60%", NULL },
{ "70%", NULL },
{ "80%", NULL },
{ "90%", NULL },
{ "100%", NULL },
{ "110%", NULL },
{ "120%", NULL },
{ "130%", NULL },
{ "140%", NULL },
{ "150%", NULL },
{ "160%", NULL },
{ "170%", NULL },
{ "180%", NULL },
{ "190%", NULL },
{ "200%", NULL },
{ "210%", NULL },
{ "220%", NULL },
{ "230%", NULL },
{ "240%", NULL },
{ "250%", NULL },
{ "260%", NULL },
{ "270%", NULL },
{ "280%", NULL },
{ "290%", NULL },
{ "300%", NULL },
{ NULL, NULL },
},
"100%",
},
{
CORE_OPTION_NAME "_lightgun1_crosshair",
"Gun Crosshair 1 Display",
Expand Down
1 change: 1 addition & 0 deletions shell/libretro/vmu_xhair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ u8 lightgun_palette[LIGHTGUN_COLORS_COUNT*3] =
};

lightgun_params_t lightgun_params[4];
float lightgun_crosshair_size = (float)LIGHTGUN_CROSSHAIR_SIZE;

std::pair<float, float> getCrosshairPosition(int playerNum)
{
Expand Down
1 change: 1 addition & 0 deletions shell/libretro/vmu_xhair.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,4 @@ struct lightgun_params_t {
extern u8 lightgun_palette[LIGHTGUN_COLORS_COUNT*3];
extern u8 lightgun_img_crosshair[LIGHTGUN_CROSSHAIR_SIZE*LIGHTGUN_CROSSHAIR_SIZE];
extern lightgun_params_t lightgun_params[4] ;
extern float lightgun_crosshair_size;

0 comments on commit 78a874d

Please sign in to comment.