Commit aaf6c9ed authored by James's avatar James
Browse files

Fix clang formatting for LibRetro files

parent bc5432b5
......@@ -16,14 +16,11 @@ namespace AudioCore {
// TODO: Should this be global? I think: yes.
std::list<std::vector<s16>> queue;
struct LibRetroSink::Impl {
};
struct LibRetroSink::Impl {};
LibRetroSink::LibRetroSink() : impl(std::make_unique<Impl>()) {
}
LibRetroSink::LibRetroSink() : impl(std::make_unique<Impl>()) {}
LibRetroSink::~LibRetroSink() {
}
LibRetroSink::~LibRetroSink() {}
unsigned int LibRetroSink::GetNativeSampleRate() const {
return 41000; // We specify this.
......@@ -38,27 +35,26 @@ void LibRetroSink::EnqueueSamples(const s16* samples, size_t sample_count) {
}
size_t LibRetroSink::SamplesInQueue() const {
return std::accumulate(queue.begin(), queue.end(),
static_cast<size_t>(0), [](size_t sum, const auto& buffer) {
// Division by two because each stereo sample is made of
// two s16.
return sum + buffer.size() / 2;
});
return std::accumulate(queue.begin(), queue.end(), static_cast<size_t>(0),
[](size_t sum, const auto& buffer) {
// Division by two because each stereo sample is made of
// two s16.
return sum + buffer.size() / 2;
});
}
void LibRetroSink::SetDevice(int device_id) {
}
void LibRetroSink::SetDevice(int device_id) {}
void LibRetroSink::SubmitAudioFrames(const int16_t *samples,
size_t sample_count) {
//audio_batch_cb(data, frames);
// audio_batch_cb(data, frames);
queue.emplace_back(samples, samples + sample_count * 2);
}
void audio_callback() {
u8 buffer_backing[512];
size_t remaining_size = static_cast<size_t>(512) /
sizeof(s16); // Keep track of size in 16-bit increments.
size_t remaining_size =
static_cast<size_t>(512) / sizeof(s16); // Keep track of size in 16-bit increments.
size_t max_size = remaining_size;
u8* buffer = buffer_backing;
......@@ -71,8 +67,7 @@ void audio_callback() {
} else {
memcpy(buffer, queue.front().data(), remaining_size * sizeof(s16));
buffer += remaining_size * sizeof(s16);
queue.front().erase(queue.front().begin(),
queue.front().begin() + remaining_size);
queue.front().erase(queue.front().begin(), queue.front().begin() + remaining_size);
remaining_size = 0;
}
}
......@@ -81,15 +76,14 @@ void audio_callback() {
memset(buffer, 0, remaining_size * sizeof(s16));
}
LibRetro::SubmitAudio((const int16_t*) &buffer_backing, (max_size - remaining_size) / 2);
LibRetro::SubmitAudio((const int16_t*)&buffer_backing, (max_size - remaining_size) / 2);
}
void audio_set_state(bool state) {}
} // namespace AudioCore
void LibRetro::SubmitAudio(const int16_t *data,
size_t frames) {
void LibRetro::SubmitAudio(const int16_t *data, size_t frames) {
LibRetro::audio_batch_cb(data, frames);
}
......
......@@ -6,15 +6,14 @@
#include <cstddef>
#include <memory>
#include "libretro.h"
#include "audio_core/sink.h"
#include "libretro.h"
namespace LibRetro {
static retro_audio_sample_batch_t audio_batch_cb;
void SubmitAudio(const int16_t *data,
size_t frames);
void SubmitAudio(const int16_t *data, size_t frames);
} // namespace LibRetro
......@@ -35,8 +34,7 @@ public:
void SetDevice(int device_id) override;
/// Function provided by Retroarch dynamically to submit audio frames.
void SubmitAudioFrames(const int16_t *data,
size_t frames);
void SubmitAudioFrames(const int16_t *data, size_t frames);
private:
struct Impl;
......
This diff is collapsed.
......@@ -7,6 +7,4 @@
#include "core/core.h"
#include "emu_window/libretro_window.h"
namespace LibRetro {
} // namespace LibRetro
\ No newline at end of file
namespace LibRetro {} // namespace LibRetro
......@@ -8,11 +8,7 @@
namespace LibRetro {
enum CStickFunction {
Both,
CStick,
Touchscreen
};
enum CStickFunction { Both, CStick, Touchscreen };
struct CoreSettings {
......
......@@ -4,12 +4,12 @@
#include <glad/glad.h>
#include "core/settings.h"
#include "core/3ds.h"
#include "libretro.h"
#include "citra_libretro/input/input_factory.h"
#include "citra_libretro/citra_libretro.h"
#include "citra_libretro/environment.h"
#include "citra_libretro/input/input_factory.h"
#include "core/3ds.h"
#include "core/settings.h"
#include "libretro.h"
/// LibRetro expects a "default" GL state.
void ResetGLState() {
......@@ -54,8 +54,8 @@ void EmuWindow_LibRetro::SwapBuffers() {
tracker.Render(width, height);
}
LibRetro::UploadVideoFrame(RETRO_HW_FRAME_BUFFER_VALID,
static_cast<unsigned>(width), static_cast<unsigned>(height), 0);
LibRetro::UploadVideoFrame(RETRO_HW_FRAME_BUFFER_VALID, static_cast<unsigned>(width),
static_cast<unsigned>(height), 0);
glUseProgram(0);
ResetGLState();
......@@ -109,7 +109,8 @@ void EmuWindow_LibRetro::DoneCurrent() {
// They don't get any say in the matter - GL context is always current!
}
void EmuWindow_LibRetro::OnMinimalClientAreaChangeRequest(const std::pair<unsigned, unsigned> &minimal_size) {
void EmuWindow_LibRetro::OnMinimalClientAreaChangeRequest(
const std::pair<unsigned, unsigned> &minimal_size) {
width = minimal_size.first;
height = minimal_size.second;
}
......@@ -126,55 +127,55 @@ void EmuWindow_LibRetro::Prepare(bool hasOGL) {
enableEmulatedPointer = true;
switch(Settings::values.layout_option) {
case Settings::LayoutOption::SingleScreen:
if (swapped) { // Bottom screen visible
baseX = Core::kScreenBottomWidth;
baseY = Core::kScreenBottomHeight;
} else { // Top screen visible
baseX = Core::kScreenTopWidth;
baseY = Core::kScreenTopHeight;
enableEmulatedPointer = false;
}
baseX *= scaling;
baseY *= scaling;
break;
case Settings::LayoutOption::LargeScreen:
if (swapped) { // Bottom screen biggest
baseX = Core::kScreenBottomWidth + Core::kScreenTopWidth / 4;
baseY = Core::kScreenBottomHeight;
} else { // Top screen biggest
baseX = Core::kScreenTopWidth + Core::kScreenBottomWidth / 4;
baseY = Core::kScreenTopHeight;
}
case Settings::LayoutOption::SingleScreen:
if (swapped) { // Bottom screen visible
baseX = Core::kScreenBottomWidth;
baseY = Core::kScreenBottomHeight;
} else { // Top screen visible
baseX = Core::kScreenTopWidth;
baseY = Core::kScreenTopHeight;
enableEmulatedPointer = false;
}
baseX *= scaling;
baseY *= scaling;
break;
case Settings::LayoutOption::LargeScreen:
if (swapped) { // Bottom screen biggest
baseX = Core::kScreenBottomWidth + Core::kScreenTopWidth / 4;
baseY = Core::kScreenBottomHeight;
} else { // Top screen biggest
baseX = Core::kScreenTopWidth + Core::kScreenBottomWidth / 4;
baseY = Core::kScreenTopHeight;
}
if (scaling < 4) {
// Unfortunately, to get this aspect ratio correct (and have non-blurry 1x scaling),
// we have to have a pretty large buffer for the minimum ratio.
baseX *= 4;
baseY *= 4;
} else {
baseX *= scaling;
baseY *= scaling;
}
break;
case Settings::LayoutOption::Default:
default:
if (swapped) { // Bottom screen on top
baseX = Core::kScreenBottomWidth;
} else { // Top screen on top
baseX = Core::kScreenTopWidth;
}
baseY = Core::kScreenTopHeight + Core::kScreenBottomHeight;
if (scaling < 4) {
// Unfortunately, to get this aspect ratio correct (and have non-blurry 1x scaling),
// we have to have a pretty large buffer for the minimum ratio.
baseX *= 4;
baseY *= 4;
} else {
baseX *= scaling;
baseY *= scaling;
break;
}
break;
case Settings::LayoutOption::Default:
default:
if (swapped) { // Bottom screen on top
baseX = Core::kScreenBottomWidth;
} else { // Top screen on top
baseX = Core::kScreenTopWidth;
}
baseY = Core::kScreenTopHeight + Core::kScreenBottomHeight;
baseX *= scaling;
baseY *= scaling;
break;
}
// Update Libretro with our status
struct retro_system_av_info info;
struct retro_system_av_info info{};
info.timing.fps = 60.0;
info.timing.sample_rate = 41000;
info.geometry.aspect_ratio = (float) baseX / (float) baseY;
info.geometry.aspect_ratio = (float)baseX / (float)baseY;
info.geometry.base_width = baseX;
info.geometry.base_height = baseY;
info.geometry.max_width = baseX;
......
......@@ -48,7 +48,7 @@ public:
private:
/// Called when a configuration change affects the minimal size of the window
void OnMinimalClientAreaChangeRequest(
const std::pair<unsigned, unsigned>& minimal_size) override;
const std::pair<unsigned, unsigned>& minimal_size) override;
float scale = 2;
int width;
......
......@@ -19,8 +19,7 @@ static retro_environment_t environ_cb;
static retro_input_poll_t input_poll_cb;
static retro_input_state_t input_state_cb;
void UploadVideoFrame(const void* data, unsigned width,
unsigned height, size_t pitch) {
void UploadVideoFrame(const void* data, unsigned width, unsigned height, size_t pitch) {
return video_cb(data, width, height, pitch);
}
......@@ -33,15 +32,15 @@ void PollInput() {
}
bool SetVariables(const retro_variable vars[]) {
return environ_cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void *) vars);
return environ_cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void*)vars);
}
bool SetControllerInfo(const retro_controller_info info[]) {
return environ_cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void *) info);
return environ_cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void*)info);
}
bool SetPixelFormat(const retro_pixel_format fmt) {
return environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, (void *) &fmt);
return environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, (void*)&fmt);
}
bool SetHWRenderer(retro_hw_render_callback* cb) {
......@@ -57,7 +56,7 @@ bool SetGeometry(retro_system_av_info* cb) {
}
bool SetInputDescriptors(const retro_input_descriptor desc[]) {
return environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, (void *) desc);
return environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, (void*)desc);
}
bool HasUpdatedConfig() {
......@@ -88,14 +87,12 @@ std::string FetchVariable(std::string key, std::string def) {
return std::string(var.value);
}
int16_t CheckInput(unsigned port, unsigned device,
unsigned index, unsigned id) {
int16_t CheckInput(unsigned port, unsigned device, unsigned index, unsigned id) {
return input_state_cb(port, device, index, id);
}
};
void retro_get_system_info(struct retro_system_info *info) {
void retro_get_system_info(struct retro_system_info* info) {
memset(info, 0, sizeof(*info));
info->library_name = "Citra";
info->library_version = Common::g_scm_desc;
......
......@@ -5,19 +5,18 @@
#pragma once
#include <cstdint>
#include "core/core.h"
#include "citra_libretro.h"
#include "common/logging/backend.h"
#include "common/logging/filter.h"
#include "common/logging/log.h"
#include "core/core.h"
#include "libretro.h"
#include "citra_libretro.h"
namespace LibRetro {
/// Calls back to LibRetro to upload a particular video frame.
/// @see retro_video_refresh_t
void UploadVideoFrame(const void* data, unsigned width,
unsigned height, size_t pitch);
void UploadVideoFrame(const void* data, unsigned width, unsigned height, size_t pitch);
/// Calls back to LibRetro to poll input.
/// @see retro_input_poll_t
......@@ -50,16 +49,14 @@ bool SetGeometry(retro_system_av_info* cb);
bool SetInputDescriptors(const retro_input_descriptor desc[]);
/// Returns the current status of a input.
int16_t CheckInput(unsigned port, unsigned device,
unsigned index, unsigned id);
int16_t CheckInput(unsigned port, unsigned device, unsigned index, unsigned id);
/// Called when the emulator environment is ready to be configured.
void OnConfigureEnvironment();
/// Submits audio frames to LibRetro.
/// @see retro_audio_sample_batch_t
void SubmitAudio(const int16_t *data,
size_t frames);
void SubmitAudio(const int16_t *data, size_t frames);
/// Checks to see if the frontend configuration has been updated.
bool HasUpdatedConfig();
......
......@@ -7,11 +7,11 @@
#include <unordered_map>
#include <libretro.h>
#include "core/frontend/input.h"
#include "common/math_util.h"
#include "core/frontend/input.h"
#include "citra_libretro/input/input_factory.h"
#include "citra_libretro/environment.h"
#include "citra_libretro/input/input_factory.h"
namespace LibRetro {
......@@ -22,11 +22,10 @@ class LibRetroAxisFactory;
class LibRetroButton final : public ::Input::ButtonDevice {
public:
explicit LibRetroButton(int joystick_, int button_)
: joystick(joystick_), button(button_) {}
explicit LibRetroButton(int joystick_, int button_) : joystick(joystick_), button(button_) {}
bool GetStatus() const override {
return CheckInput((unsigned int) joystick, RETRO_DEVICE_JOYPAD, 0, (unsigned int) button) > 0;
return CheckInput((unsigned int)joystick, RETRO_DEVICE_JOYPAD, 0, (unsigned int)button) > 0;
}
private:
......@@ -54,12 +53,13 @@ public:
/// A axis device factory that creates axis devices from LibRetro joystick
class LibRetroAxis final : public ::Input::AnalogDevice {
public:
explicit LibRetroAxis(int joystick_, int button_)
: joystick(joystick_), button(button_) {}
explicit LibRetroAxis(int joystick_, int button_) : joystick(joystick_), button(button_) {}
std::tuple<float, float> GetStatus() const override {
auto axis_x = (float) CheckInput((unsigned int) joystick, RETRO_DEVICE_ANALOG, (unsigned int) button, 0);
auto axis_y = (float) CheckInput((unsigned int) joystick, RETRO_DEVICE_ANALOG, (unsigned int) button, 1);
auto axis_x =
(float)CheckInput((unsigned int)joystick, RETRO_DEVICE_ANALOG, (unsigned int)button, 0);
auto axis_y =
(float)CheckInput((unsigned int)joystick, RETRO_DEVICE_ANALOG, (unsigned int)button, 1);
return std::make_tuple(axis_x / INT16_MAX, -axis_y / INT16_MAX);
}
......
......@@ -4,9 +4,9 @@
#include <glad/glad.h>
#include "citra_libretro/input/mouse_tracker.h"
#include "citra_libretro/core_settings.h"
#include "citra_libretro/environment.h"
#include "citra_libretro/input/mouse_tracker.h"
#include "video_core/renderer_opengl/gl_shader_util.h"
......@@ -47,7 +47,7 @@ void MouseTracker::InitOpenGL() {
shader = GLShader::LoadProgram(vertex, fragment);
GLuint positionVariable = (GLuint) glGetAttribLocation(shader, "position");
auto positionVariable = (GLuint)glGetAttribLocation(shader, "position");
glEnableVertexAttribArray(positionVariable);
glVertexAttribPointer(positionVariable, 2, GL_FLOAT, GL_FALSE, 0, 0);
......@@ -66,24 +66,23 @@ void MouseTracker::Restrict(int minX, int minY, int maxX, int maxY) {
void MouseTracker::Update(int bufferWidth, int bufferHeight,
MathUtil::Rectangle<unsigned> bottomScreen) {
// Check mouse input
bool state = (bool) (LibRetro::CheckInput(0, RETRO_DEVICE_MOUSE,
0, RETRO_DEVICE_ID_MOUSE_LEFT))
|| (bool) (LibRetro::CheckInput(0, RETRO_DEVICE_JOYPAD,
0, RETRO_DEVICE_ID_JOYPAD_R3));
auto mouseX = LibRetro::CheckInput(0, RETRO_DEVICE_MOUSE,
0, RETRO_DEVICE_ID_MOUSE_X) * 2;
auto mouseY = LibRetro::CheckInput(0, RETRO_DEVICE_MOUSE,
0, RETRO_DEVICE_ID_MOUSE_Y) * 2;
bool state =
(bool)(LibRetro::CheckInput(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_LEFT)) ||
(bool)(LibRetro::CheckInput(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3));
auto mouseX = LibRetro::CheckInput(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_X) * 2;
auto mouseY = LibRetro::CheckInput(0, RETRO_DEVICE_MOUSE, 0, RETRO_DEVICE_ID_MOUSE_Y) * 2;
OnMouseMove(mouseX, mouseY);
if (LibRetro::settings.analog_function != LibRetro::CStickFunction::CStick) {
float controllerX = ((float) LibRetro::CheckInput(0, RETRO_DEVICE_ANALOG,
RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X) /
INT16_MAX);
float controllerY = ((float) LibRetro::CheckInput(0, RETRO_DEVICE_ANALOG,
RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y) /
INT16_MAX);
float controllerX =
((float)LibRetro::CheckInput(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT,
RETRO_DEVICE_ID_ANALOG_X) /
INT16_MAX);
float controllerY =
((float)LibRetro::CheckInput(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT,
RETRO_DEVICE_ID_ANALOG_Y) /
INT16_MAX);
// Deadzone the controller inputs
if (std::abs(controllerX) < LibRetro::settings.deadzone) {
......@@ -93,7 +92,7 @@ void MouseTracker::Update(int bufferWidth, int bufferHeight,
controllerY = 0;
}
OnMouseMove((int) (controllerX * 20), (int) (controllerY * 20));
OnMouseMove((int)(controllerX * 20), (int)(controllerY * 20));
}
Restrict(0, 0, bufferWidth, bufferHeight);
......@@ -104,15 +103,15 @@ void MouseTracker::Update(int bufferWidth, int bufferHeight,
// Ensure that the projected position doesn't overlap outside the bottom screen framebuffer.
// TODO: Provide config option
renderRatio = (float) (bottomScreen.bottom - bottomScreen.top) / bufferHeight / 30;
renderRatio = (float)(bottomScreen.bottom - bottomScreen.top) / bufferHeight / 30;
float renderWidth = renderRatio * bufferWidth / 2;
float renderHeight = renderRatio * bufferHeight / 2 * ((float) bufferWidth / bufferHeight);
float renderHeight = renderRatio * bufferHeight / 2 * ((float)bufferWidth / bufferHeight);
// Map the mouse coord to the bottom screen's position (with a little margin)
projectedX = bottomScreen.left + renderWidth + projectedX
* (bottomScreen.right - bottomScreen.left - renderWidth * 2);
projectedY = bottomScreen.top + renderHeight + projectedY
* (bottomScreen.bottom - bottomScreen.top - renderHeight * 2);
projectedX = bottomScreen.left + renderWidth +
projectedX * (bottomScreen.right - bottomScreen.left - renderWidth * 2);
projectedY = bottomScreen.top + renderHeight +
projectedY * (bottomScreen.bottom - bottomScreen.top - renderHeight * 2);
isPressed = state;
......@@ -120,14 +119,14 @@ void MouseTracker::Update(int bufferWidth, int bufferHeight,
void MouseTracker::Render(int bufferWidth, int bufferHeight) {
// Convert to OpenGL coordinates
float centerX = (projectedX / bufferWidth) * 2 - 1;
float centerX = (projectedX / bufferWidth) * 2 - 1;
float centerY = -((projectedY / bufferHeight) * 2 - 1);
float renderWidth = renderRatio;
float renderHeight = renderRatio * ((float) bufferWidth / bufferHeight);
float renderWidth = renderRatio;
float renderHeight = renderRatio * ((float)bufferWidth / bufferHeight);
float projectedLeft = centerX - renderWidth;
float projectedTop = centerY - renderHeight;
float projectedLeft = centerX - renderWidth;
float projectedTop = centerY - renderHeight;
float projectedRight = centerX + renderWidth;
float projectedBottom = centerY + renderHeight;
......@@ -135,6 +134,7 @@ void MouseTracker::Render(int bufferWidth, int bufferHeight) {
glBindVertexArray(vao);
// clang-format off
GLfloat cursor[] = {
projectedLeft, projectedTop,
projectedRight, projectedTop,
......@@ -144,6 +144,7 @@ void MouseTracker::Render(int bufferWidth, int bufferHeight) {
projectedRight, projectedBottom,
projectedLeft, projectedBottom
};
// clang-format on
glEnable(GL_BLEND);
glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_SRC_COLOR);
......
......@@ -38,6 +38,7 @@ public:
std::pair<unsigned, unsigned> GetPressedPosition() {
return std::pair<unsigned, unsigned>(projectedX, projectedY);
}
private:
int x;
int y;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment