Clean up many nits found by linter.

This commit is contained in:
BearOso 2025-06-07 15:13:49 -05:00
parent 366cde5cd3
commit d65a2b31a0
83 changed files with 597 additions and 929 deletions

View File

@ -4,18 +4,14 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __S9X_SOUND_DRIVER_HPP
#define __S9X_SOUND_DRIVER_HPP
#pragma once
#include <cstdint>
#include <tuple>
class S9xSoundDriver
{
public:
virtual ~S9xSoundDriver()
{
}
virtual ~S9xSoundDriver() = default;
virtual bool write_samples(int16_t *data, int samples) = 0;
virtual int space_free() = 0;
virtual std::pair<int, int> buffer_level() = 0;
@ -24,6 +20,4 @@ class S9xSoundDriver
virtual bool open_device(int playback_rate, int buffer_size) = 0;
virtual void start() = 0;
virtual void stop() = 0;
};
#endif /* __S9X_SOUND_DRIVER_HPP */
};

View File

@ -41,7 +41,6 @@ void S9xAlsaSoundDriver::stop()
bool S9xAlsaSoundDriver::open_device(int playback_rate, int buffer_size_ms)
{
int err;
unsigned int periods = 8;
unsigned int buffer_size = buffer_size_ms * 1000;
snd_pcm_sw_params_t *sw_params;
@ -54,7 +53,7 @@ bool S9xAlsaSoundDriver::open_device(int playback_rate, int buffer_size_ms)
printf("ALSA sound driver initializing...\n");
printf(" --> (Device: default)...\n");
err = snd_pcm_open(&pcm, "default", SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
int err = snd_pcm_open(&pcm, "default", SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
if (err < 0)
{
@ -141,14 +140,11 @@ fail:
bool S9xAlsaSoundDriver::write_samples(int16_t *data, int samples)
{
snd_pcm_sframes_t frames_written, frames;
size_t bytes;
frames = snd_pcm_avail(pcm);
snd_pcm_sframes_t frames = snd_pcm_avail(pcm);
if (frames < 0)
{
frames = snd_pcm_recover(pcm, frames, 1);
snd_pcm_recover(pcm, frames, 1);
return false;
}
@ -160,18 +156,16 @@ bool S9xAlsaSoundDriver::write_samples(int16_t *data, int samples)
result = false;
}
bytes = snd_pcm_frames_to_bytes(pcm, frames);
size_t bytes = snd_pcm_frames_to_bytes(pcm, frames);
if (bytes <= 0)
return false;
frames_written = 0;
snd_pcm_sframes_t frames_written = 0;
while (frames_written < frames)
{
int result;
result = snd_pcm_writei(pcm,
&data[snd_pcm_frames_to_bytes(pcm, frames_written) / 2],
frames - frames_written);
int result = snd_pcm_writei(pcm,
&data[snd_pcm_frames_to_bytes(pcm, frames_written) / 2],
frames - frames_written);
if (result < 0)
{

View File

@ -4,9 +4,7 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __S9X_SOUND_DRIVER_ALSA_HPP
#define __S9X_SOUND_DRIVER_ALSA_HPP
#pragma once
#include "s9x_sound_driver.hpp"
#include "alsa/asoundlib.h"
@ -26,6 +24,4 @@ class S9xAlsaSoundDriver : public S9xSoundDriver
private:
snd_pcm_t *pcm;
int output_buffer_size_bytes;
};
#endif /* __S9X_SOUND_DRIVER_ALSA_HPP */
};

View File

@ -22,13 +22,9 @@ bool S9xCubebSoundDriver::write_samples(int16_t *data, int samples)
return retval;
}
S9xCubebSoundDriver::S9xCubebSoundDriver()
{
}
S9xCubebSoundDriver::~S9xCubebSoundDriver()
{
deinit();
S9xCubebSoundDriver::deinit();
}
void S9xCubebSoundDriver::init()

View File

@ -4,9 +4,7 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __S9X_SOUND_DRIVER_CUBEB_HPP
#define __S9X_SOUND_DRIVER_CUBEB_HPP
#pragma once
#include "s9x_sound_driver.hpp"
#include <cstdint>
#include "cubeb/cubeb.h"
@ -15,8 +13,7 @@
class S9xCubebSoundDriver : public S9xSoundDriver
{
public:
S9xCubebSoundDriver();
~S9xCubebSoundDriver();
~S9xCubebSoundDriver() override;
void init() override;
void deinit() override;
bool open_device(int playback_rate, int buffer_size) override;
@ -31,6 +28,4 @@ class S9xCubebSoundDriver : public S9xSoundDriver
Resampler buffer;
cubeb *context = nullptr;
cubeb_stream *stream = nullptr;
};
#endif /* __S9X_SOUND_DRIVER_SDL_HPP */
};

View File

@ -9,7 +9,6 @@
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/soundcard.h>
#include <sys/time.h>
#include <unistd.h>
#include <cstdio>
@ -164,9 +163,6 @@ std::pair<int, int> S9xOSSSoundDriver::buffer_level()
bool S9xOSSSoundDriver::write_samples(int16_t *data, int samples)
{
audio_buf_info info;
int bytes_to_write;
int bytes_written;
ioctl(filedes, SNDCTL_DSP_GETOSPACE, &info);
if (samples > info.bytes / 2)
@ -175,16 +171,15 @@ bool S9xOSSSoundDriver::write_samples(int16_t *data, int samples)
if (samples == 0)
return false;
bytes_written = 0;
bytes_to_write = samples * 2;
int bytes_written = 0;
int bytes_to_write = samples * 2;
while (bytes_to_write > bytes_written)
{
int result;
result = write(filedes,
((char *)data) + bytes_written,
bytes_to_write - bytes_written);
int result = write(filedes,
((char *)data) + bytes_written,
bytes_to_write - bytes_written);
if (result < 0)
break;

View File

@ -4,9 +4,7 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __S9X_SOUND_DRIVER_OSS_HPP
#define __S9X_SOUND_DRIVER_OSS_HPP
#pragma once
#include "s9x_sound_driver.hpp"
class S9xOSSSoundDriver : public S9xSoundDriver
@ -25,6 +23,4 @@ class S9xOSSSoundDriver : public S9xSoundDriver
private:
int filedes;
int output_buffer_size_bytes;
};
#endif /* __S9X_SOUND_DRIVER_OSS_HPP */
};

View File

@ -7,25 +7,23 @@
#include "s9x_sound_driver_portaudio.hpp"
#include <cstring>
#include <cstdio>
#include <cstdint>
#include <vector>
#include <string>
S9xPortAudioSoundDriver::S9xPortAudioSoundDriver()
{
audio_stream = NULL;
audio_stream = nullptr;
}
S9xPortAudioSoundDriver::~S9xPortAudioSoundDriver()
{
deinit();
S9xPortAudioSoundDriver::deinit();
}
void S9xPortAudioSoundDriver::init()
{
PaError err;
err = Pa_Initialize();
PaError err = Pa_Initialize();
if (err != paNoError)
fprintf(stderr,
@ -36,20 +34,17 @@ void S9xPortAudioSoundDriver::init()
void S9xPortAudioSoundDriver::deinit()
{
stop();
Pa_Terminate();
}
void S9xPortAudioSoundDriver::start()
{
PaError err;
if (audio_stream != NULL)
if (audio_stream != nullptr)
{
if ((Pa_IsStreamActive(audio_stream)))
return;
err = Pa_StartStream(audio_stream);
PaError err = Pa_StartStream(audio_stream);
if (err != paNoError)
{
@ -60,7 +55,7 @@ void S9xPortAudioSoundDriver::start()
void S9xPortAudioSoundDriver::stop()
{
if (audio_stream != NULL)
if (audio_stream != nullptr)
{
Pa_StopStream(audio_stream);
}
@ -87,7 +82,7 @@ bool S9xPortAudioSoundDriver::tryHostAPI(int index)
param.suggestedLatency = buffer_size_ms * 0.001;
param.channelCount = 2;
param.sampleFormat = paInt16;
param.hostApiSpecificStreamInfo = NULL;
param.hostApiSpecificStreamInfo = nullptr;
printf("(%s : %s, latency %dms)...\n",
hostapi_info->name,
@ -95,13 +90,13 @@ bool S9xPortAudioSoundDriver::tryHostAPI(int index)
(int)(param.suggestedLatency * 1000.0));
auto err = Pa_OpenStream(&audio_stream,
NULL,
nullptr,
&param,
playback_rate,
0,
paNoFlag,
NULL,
NULL);
nullptr,
nullptr);
int frames = Pa_GetStreamWriteAvailable(audio_stream);
if (frames < 0)
@ -126,11 +121,9 @@ bool S9xPortAudioSoundDriver::tryHostAPI(int index)
bool S9xPortAudioSoundDriver::open_device(int playback_rate, int buffer_size_ms)
{
const PaDeviceInfo *device_info;
const PaHostApiInfo *hostapi_info;
PaError err = paNoError;
if (audio_stream != NULL)
if (audio_stream != nullptr)
{
printf("Shutting down sound for reset\n");
err = Pa_CloseStream(audio_stream);
@ -141,7 +134,7 @@ bool S9xPortAudioSoundDriver::open_device(int playback_rate, int buffer_size_ms)
return true;
}
audio_stream = NULL;
audio_stream = nullptr;
}
this->playback_rate = playback_rate;
@ -189,9 +182,7 @@ std::pair<int, int> S9xPortAudioSoundDriver::buffer_level()
bool S9xPortAudioSoundDriver::write_samples(int16_t *data, int samples)
{
int frames;
frames = Pa_GetStreamWriteAvailable(audio_stream);
int frames = Pa_GetStreamWriteAvailable(audio_stream);
if (frames == output_buffer_size)
{

View File

@ -4,10 +4,7 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __S9X_SOUND_DRIVER_PORTAUDIO_HPP
#define __S9X_SOUND_DRIVER_PORTAUDIO_HPP
#include <errno.h>
#pragma once
#include <portaudio.h>
#include "s9x_sound_driver.hpp"
@ -16,7 +13,7 @@ class S9xPortAudioSoundDriver : public S9xSoundDriver
{
public:
S9xPortAudioSoundDriver();
~S9xPortAudioSoundDriver();
~S9xPortAudioSoundDriver() override;
void init() override;
void deinit() override;
bool open_device(int playback_rate, int buffer_size) override;
@ -25,7 +22,6 @@ class S9xPortAudioSoundDriver : public S9xSoundDriver
bool write_samples(int16_t *data, int samples) override;
int space_free() override;
std::pair<int, int> buffer_level() override;
void samples_available();
bool tryHostAPI(int index);
private:
@ -33,6 +29,4 @@ class S9xPortAudioSoundDriver : public S9xSoundDriver
int playback_rate;
int buffer_size_ms;
int output_buffer_size;
};
#endif /* __S9X_SOUND_DRIVER_PORTAUDIO_HPP */
};

View File

@ -9,7 +9,6 @@
#include <cstring>
#include <cstdio>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include "fmt/format.h"
#include "messages.h"
@ -17,7 +16,7 @@
S9xPulseSoundDriver::S9xPulseSoundDriver()
{
init();
S9xPulseSoundDriver::init();
}
void S9xPulseSoundDriver::init()
@ -76,10 +75,9 @@ void S9xPulseSoundDriver::wait()
static void context_state_cb(pa_context *c, void *userdata)
{
S9xPulseSoundDriver *driver = (S9xPulseSoundDriver *)userdata;
int state;
auto driver = (S9xPulseSoundDriver *)userdata;
state = pa_context_get_state(c);
int state = pa_context_get_state(c);
if (state == PA_CONTEXT_READY ||
state == PA_CONTEXT_FAILED ||
@ -91,10 +89,9 @@ static void context_state_cb(pa_context *c, void *userdata)
static void stream_state_callback(pa_stream *p, void *userdata)
{
S9xPulseSoundDriver *driver = (S9xPulseSoundDriver *)userdata;
int state;
auto *driver = (S9xPulseSoundDriver *)userdata;
state = pa_stream_get_state(p);
int state = pa_stream_get_state(p);
if (state == PA_STREAM_READY ||
state == PA_STREAM_FAILED ||
@ -126,7 +123,6 @@ bool S9xPulseSoundDriver::open_device(int playback_rate, int buffer_size_ms)
playback_rate,
buffer_size_ms).c_str());
int err = PA_ERR_UNKNOWN;
mainloop = pa_threaded_mainloop_new();
context = pa_context_new(pa_threaded_mainloop_get_api(mainloop), "Snes9x");
pa_context_set_state_callback(context, context_state_cb, this);
@ -136,7 +132,7 @@ bool S9xPulseSoundDriver::open_device(int playback_rate, int buffer_size_ms)
pa_threaded_mainloop_start(mainloop);
wait();
if ((err = pa_context_get_state(context)) != PA_CONTEXT_READY)
if (pa_context_get_state(context) != PA_CONTEXT_READY)
return false;
stream = pa_stream_new(context, "Game", &ss, nullptr);

View File

@ -4,9 +4,7 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __S9X_SOUND_DRIVER_PULSE_HPP
#define __S9X_SOUND_DRIVER_PULSE_HPP
#pragma once
#include "s9x_sound_driver.hpp"
#include "pulse/pulseaudio.h"
@ -33,6 +31,4 @@ class S9xPulseSoundDriver : public S9xSoundDriver
int buffer_size;
bool draining = false;
};
#endif /* __S9X_SOUND_DRIVER_PULSE_HPP */
};

View File

@ -32,13 +32,11 @@ void S9xSDLSoundDriver::mix(unsigned char *output, int bytes)
}
}
S9xSDLSoundDriver::S9xSDLSoundDriver()
{
}
S9xSDLSoundDriver::S9xSDLSoundDriver() = default;
S9xSDLSoundDriver::~S9xSDLSoundDriver()
{
deinit();
S9xSDLSoundDriver::deinit();
}
void S9xSDLSoundDriver::init()
@ -82,7 +80,7 @@ bool S9xSDLSoundDriver::open_device(int playback_rate, int buffer_size)
audiospec.freq,
(audiospec.samples * 1000 / audiospec.freq));
if (SDL_OpenAudio(&audiospec, NULL) < 0)
if (SDL_OpenAudio(&audiospec, nullptr) < 0)
{
printf("Failed\n");
return false;

View File

@ -4,9 +4,7 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __S9X_SOUND_DRIVER_SDL_HPP
#define __S9X_SOUND_DRIVER_SDL_HPP
#pragma once
#include "SDL.h"
// SDL.h may include altivec.h which redefines vector and bool
#undef vector
@ -22,7 +20,7 @@ class S9xSDLSoundDriver : public S9xSoundDriver
{
public:
S9xSDLSoundDriver();
~S9xSDLSoundDriver();
~S9xSDLSoundDriver() override;
void init() override;
void deinit() override;
bool open_device(int playback_rate, int buffer_size) override;
@ -39,6 +37,4 @@ class S9xSDLSoundDriver : public S9xSoundDriver
Resampler buffer;
std::mutex mutex;
int16_t temp[512];
};
#endif /* __S9X_SOUND_DRIVER_SDL_HPP */
};

View File

@ -57,7 +57,7 @@ S9xSDL3SoundDriver::S9xSDL3SoundDriver()
S9xSDL3SoundDriver::~S9xSDL3SoundDriver()
{
deinit();
S9xSDL3SoundDriver::deinit();
}
void S9xSDL3SoundDriver::init()

View File

@ -4,9 +4,7 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __S9X_SOUND_DRIVER_SDL3_HPP
#define __S9X_SOUND_DRIVER_SDL3_HPP
#pragma once
#include "SDL3/SDL.h"
// SDL.h may include altivec.h which redefines vector and bool
#undef vector
@ -16,14 +14,13 @@
#include "../../apu/resampler.h"
#include <mutex>
#include <cstdint>
#include <vector>
class S9xSDL3SoundDriver : public S9xSoundDriver
{
public:
S9xSDL3SoundDriver();
~S9xSDL3SoundDriver();
~S9xSDL3SoundDriver() override;
void init() override;
void deinit() override;
bool open_device(int playback_rate, int buffer_size) override;
@ -41,6 +38,4 @@ class S9xSDL3SoundDriver : public S9xSoundDriver
Resampler buffer;
std::mutex mutex;
std::vector<int16_t> tmp;
};
#endif /* __S9X_SOUND_DRIVER_SDL3_HPP */
};

View File

@ -5,16 +5,16 @@
\*****************************************************************************/
#include <cstdlib>
#include <stdio.h>
#include <string.h>
#include <cstdio>
#include <cstring>
#include <unistd.h>
#include "glx_context.hpp"
GTKGLXContext::GTKGLXContext()
{
display = NULL;
context = NULL;
display = nullptr;
context = nullptr;
version_major = -1;
version_minor = -1;
@ -30,18 +30,6 @@ GTKGLXContext::~GTKGLXContext()
bool GTKGLXContext::attach(Display *dpy, Window xid)
{
GLXFBConfig *fbconfigs;
int num_fbconfigs;
int attribs[] = {
GLX_DOUBLEBUFFER, True,
GLX_X_RENDERABLE, True,
GLX_RED_SIZE, 8,
GLX_GREEN_SIZE, 8,
GLX_BLUE_SIZE, 8,
None
};
this->xid = xid;
display = dpy;
@ -53,7 +41,16 @@ bool GTKGLXContext::attach(Display *dpy, Window xid)
if (version_major < 2 && version_minor < 3)
return false;
fbconfigs = glXChooseFBConfig(display, screen, attribs, &num_fbconfigs);
int attribs[] = {
GLX_DOUBLEBUFFER, True,
GLX_X_RENDERABLE, True,
GLX_RED_SIZE, 8,
GLX_GREEN_SIZE, 8,
GLX_BLUE_SIZE, 8,
None
};
int num_fbconfigs;
GLXFBConfig *fbconfigs = glXChooseFBConfig(display, screen, attribs, &num_fbconfigs);
if (!fbconfigs || num_fbconfigs < 1)
{
@ -83,9 +80,9 @@ bool GTKGLXContext::create_context()
return X_OK;
});
if (strstr(extensions, "GLX_ARB_create_context"))
context = glXCreateContextAttribsARB(display, fbconfig, NULL, True, context_attribs);
context = glXCreateContextAttribsARB(display, fbconfig, nullptr, True, context_attribs);
if (!context)
context = glXCreateNewContext(display, fbconfig, GLX_RGBA_TYPE, NULL, True);
context = glXCreateNewContext(display, fbconfig, GLX_RGBA_TYPE, nullptr, True);
XSetErrorHandler(nullptr);
if (!context)

View File

@ -4,9 +4,7 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __GLX_CONTEXT_HPP
#define __GLX_CONTEXT_HPP
#pragma once
#include "opengl_context.hpp"
#include <glad/glx.h>
@ -15,14 +13,14 @@ class GTKGLXContext : public OpenGLContext
{
public:
GTKGLXContext();
~GTKGLXContext();
~GTKGLXContext() override;
bool attach(Display *dpy, Window xid);
bool create_context();
void resize();
void swap_buffers();
void swap_interval(int frames);
void make_current();
bool ready();
bool create_context() override;
void resize() override;
void swap_buffers() override;
void swap_interval(int frames) override;
void make_current() override;
bool ready() override;
GLXContext context;
GLXFBConfig fbconfig;
@ -32,6 +30,4 @@ class GTKGLXContext : public OpenGLContext
int version_major;
int version_minor;
};
#endif
};

View File

@ -4,13 +4,12 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __GTK_OPENGL_CONTEXT_H
#define __GTK_OPENGL_CONTEXT_H
#pragma once
class OpenGLContext
{
public:
virtual ~OpenGLContext(){};
virtual ~OpenGLContext() = default;
virtual bool create_context() = 0;
virtual void resize() = 0;
virtual void swap_buffers() = 0;
@ -25,6 +24,4 @@ class OpenGLContext
int y;
int width;
int height;
};
#endif
};

View File

@ -6,7 +6,6 @@
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
#include <map>
#include "glsl.h"
@ -24,18 +23,18 @@ static const GLfloat mvp_ortho[16] = { 2.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, -1.0f, 0.0f,
-1.0f, -1.0f, 0.0f, 1.0f };
static int scale_string_to_enum(std::string string)
static int scale_string_to_enum(const std::string &string)
{
const struct { const char *string; int value; } map[] =
constexpr struct { const char *string; int value; } map[] =
{
{ "source", GLSL_SOURCE },
{ "viewport", GLSL_VIEWPORT },
{ "absolute", GLSL_ABSOLUTE }
};
for (size_t i = 0; i < 3; i++)
if (string == map[i].string)
return map[i].value;
for (auto &i : map)
if (string == i.string)
return i.value;
return GLSL_NONE;
}
@ -54,7 +53,7 @@ static const char *scale_enum_to_string(int val)
}
}
static int wrap_mode_string_to_enum(std::string string)
static int wrap_mode_string_to_enum(const std::string &string)
{
if (string == "repeat")
{
@ -102,19 +101,19 @@ bool GLSLShader::load_shader_preset_file(const char *filename)
if (ends_with(filename, ".glsl") || ends_with(filename, ".slang"))
{
GLSLPass pass;
this->pass.push_back(GLSLPass());
this->pass.emplace_back();
pass.scale_type_x = pass.scale_type_y = GLSL_VIEWPORT;
pass.filter = GLSL_UNDEFINED;
pass.wrap_mode = GL_CLAMP_TO_BORDER;
strcpy(pass.filename, filename);
pass.frame_count_mod = 0;
pass.frame_count = 0;
pass.fp = 0;
pass.scale_x = 1.0;
pass.scale_y = 1.0;
this->pass.push_back(pass);
GLSLPass new_pass;
new_pass.scale_type_x = new_pass.scale_type_y = GLSL_VIEWPORT;
new_pass.filter = GLSL_UNDEFINED;
new_pass.wrap_mode = GL_CLAMP_TO_BORDER;
strcpy(new_pass.filename, filename);
new_pass.frame_count_mod = 0;
new_pass.frame_count = 0;
new_pass.fp = false;
new_pass.scale_x = 1.0;
new_pass.scale_y = 1.0;
this->pass.push_back(new_pass);
return true;
}
@ -126,7 +125,7 @@ bool GLSLShader::load_shader_preset_file(const char *filename)
if (shader_count < 1)
return false;
this->pass.push_back(GLSLPass());
this->pass.emplace_back();
for (int i = 0; i < shader_count; i++)
{
@ -138,7 +137,7 @@ bool GLSLShader::load_shader_preset_file(const char *filename)
std::string scaleType = ini.get_string("scale_type" + num, "");
if (scaleType == "")
if (scaleType.empty())
{
std::string scaleTypeX = ini.get_string("scale_type_x" + num, "");
pass.scale_type_x = scale_string_to_enum(scaleTypeX);
@ -183,7 +182,7 @@ bool GLSLShader::load_shader_preset_file(const char *filename)
for (auto &id : ids)
{
GLSLLut lut;
GLSLLut lut{};
strcpy(lut.id, id.c_str());
strcpy(lut.filename, ini.get_string(id, "").c_str());
@ -201,18 +200,18 @@ bool GLSLShader::load_shader_preset_file(const char *filename)
return true;
}
static std::string folder_from_path(std::string filename)
static std::string folder_from_path(const std::string &filename)
{
for (int i = filename.length() - 1; i >= 0; i--)
if (filename[i] == '\\' || filename[i] == '/')
return filename.substr(0, i);
return std::string(".");
return ".";
}
static std::string canonicalize(const std::string &noncanonical)
{
char *temp = realpath(noncanonical.c_str(), NULL);
char *temp = realpath(noncanonical.c_str(), nullptr);
std::string filename_string(temp);
free(temp);
return filename_string;
@ -263,7 +262,7 @@ static GLuint string_to_format(char *format)
#endif
// filename must be canonical
void GLSLShader::read_shader_file_with_includes(std::string filename,
void GLSLShader::read_shader_file_with_includes(const std::string& filename,
std::vector<std::string> &lines,
int p)
{
@ -285,10 +284,10 @@ void GLSLShader::read_shader_file_with_includes(std::string filename,
if (line.compare(0, 8, "#include") == 0)
{
char tmp[PATH_MAX];
sscanf(line.c_str(), "#include \"%[^\"]\"", tmp);
sscanf(line.c_str(), R"(#include "%[^"]")", tmp);
std::string fullpath = canonicalize(folder_from_path(filename) + "/" + tmp);
read_shader_file_with_includes(fullpath.c_str(), lines, p);
read_shader_file_with_includes(fullpath, lines, p);
continue;
}
else if (line.compare(0, 17, "#pragma parameter") == 0)
@ -297,12 +296,12 @@ void GLSLShader::read_shader_file_with_includes(std::string filename,
char name[PATH_MAX];
GLSLParam par;
sscanf(line.c_str(), "#pragma parameter %s \"%[^\"]\" %f %f %f %f",
sscanf(line.c_str(), R"(#pragma parameter %s "%[^"]" %f %f %f %f)",
id, name, &par.val, &par.min, &par.max, &par.step);
par.id = id;
par.name = name;
unsigned int last_decimal = line.rfind(".") + 1;
unsigned int last_decimal = line.rfind('.') + 1;
unsigned int index = last_decimal;
while (isdigit(line[index]) && index < line.length())
index++;
@ -343,8 +342,6 @@ void GLSLShader::read_shader_file_with_includes(std::string filename,
#endif
lines.push_back(line);
}
return;
}
GLuint GLSLShader::compile_shader(std::vector<std::string> &lines,
@ -383,14 +380,14 @@ GLuint GLSLShader::compile_shader(std::vector<std::string> &lines,
GLuint shader = glCreateShader(type);
GLint status;
GLint length = source.length();
GLchar *prog = (GLchar *)source.c_str();
auto prog = (GLchar *)source.c_str();
glShaderSource(shader, 1, &prog, &length);
glCompileShader(shader);
glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
info_log[0] = '\0';
glGetShaderInfoLog(shader, 1024, NULL, info_log);
glGetShaderInfoLog(shader, 1024, nullptr, info_log);
if (*info_log)
printf("%s\n", info_log);
*out = shader;
@ -402,11 +399,10 @@ bool GLSLShader::load_shader(const char *filename)
{
char shader_path[PATH_MAX];
char temp[PATH_MAX];
std::string aliases = "";
GLint status;
char log[1024];
if (this->pass.size())
if (!this->pass.empty())
return false;
if (!filename || *filename == '\0')
@ -439,8 +435,7 @@ bool GLSLShader::load_shader(const char *filename)
#ifdef USE_SLANG
if (using_slang)
{
GLint retval;
retval = slang_compile(lines, "vertex");
GLint retval = slang_compile(lines, "vertex");
if (retval < 0)
{
printf("Vertex shader in \"%s\" failed to compile.\n", p->filename);
@ -461,7 +456,7 @@ bool GLSLShader::load_shader(const char *filename)
{
if (!compile_shader(lines,
"#define VERTEX\n#define PARAMETER_UNIFORM\n",
aliases.c_str(),
"",
GL_VERTEX_SHADER,
&vertex_shader) || !vertex_shader)
{
@ -471,7 +466,7 @@ bool GLSLShader::load_shader(const char *filename)
if (!compile_shader(lines,
"#define FRAGMENT\n#define PARAMETER_UNIFORM\n",
aliases.c_str(),
"",
GL_FRAGMENT_SHADER,
&fragment_shader) || !fragment_shader)
{
@ -488,7 +483,7 @@ bool GLSLShader::load_shader(const char *filename)
glLinkProgram(p->program);
glGetProgramiv(p->program, GL_LINK_STATUS, &status);
log[0] = '\0';
glGetProgramInfoLog(p->program, 1024, NULL, log);
glGetProgramInfoLog(p->program, 1024, nullptr, log);
if (*log)
printf("%s\n", log);
@ -603,13 +598,13 @@ bool GLSLShader::load_shader(const char *filename)
}
// Check for parameters specified in file
for (unsigned int i = 0; i < param.size(); i++)
for (auto &p : param)
{
param[i].val = ini.get_float(param[i].id, param[i].val);
if (param[i].val < param[i].min)
param[i].val = param[i].min;
if (param[i].val > param[i].max)
param[i].val = param[i].max;
p.val = ini.get_float(p.id, p.val);
if (p.val < p.min)
p.val = p.min;
if (p.val > p.max)
p.val = p.max;
}
glActiveTexture(GL_TEXTURE0);
@ -623,10 +618,10 @@ bool GLSLShader::load_shader(const char *filename)
prev_frame.resize(max_prev_frame);
for (unsigned int i = 0; i < prev_frame.size(); i++)
for (auto &frame : prev_frame)
{
glGenTextures(1, &(prev_frame[i].texture));
prev_frame[i].width = prev_frame[i].height = 0;
glGenTextures(1, &(frame.texture));
frame.width = frame.height = 0;
}
glGenBuffers(1, &vbo);
@ -731,7 +726,7 @@ void GLSLShader::render(GLuint &orig,
0,
GL_RGBA,
GL_UNSIGNED_INT_8_8_8_8,
NULL);
nullptr);
}
else
{
@ -743,7 +738,7 @@ void GLSLShader::render(GLuint &orig,
0,
GL_RGBA,
(pass[i].fp ? GL_FLOAT : GL_UNSIGNED_INT_8_8_8_8),
NULL);
nullptr);
}
// viewport determines the area we render into the output texture
@ -859,13 +854,13 @@ void GLSLShader::render(GLuint &orig,
glUseProgram(0);
// Pop back of previous frame stack and use as upload buffer
if (prev_frame.size() > 0)
if (!prev_frame.empty())
{
GLint internal_format;
orig = prev_frame.back().texture;
prev_frame.pop_back();
GLSLPass *newprevframe = new GLSLPass;
auto newprevframe = new GLSLPass;
newprevframe->width = width;
newprevframe->height = height;
newprevframe->texture = pass[0].texture;
@ -885,7 +880,7 @@ void GLSLShader::render(GLuint &orig,
0,
GL_RGB,
GL_UNSIGNED_BYTE,
NULL);
nullptr);
}
glBindTexture(GL_TEXTURE_2D, orig);
@ -1121,8 +1116,8 @@ void GLSLShader::set_shader_vars(unsigned int p, bool inverted)
void GLSLShader::clear_shader_vars()
{
for (unsigned int i = 0; i < vaos.size(); i++)
glDisableVertexAttribArray(vaos[i]);
for (unsigned int vao : vaos)
glDisableVertexAttribArray(vao);
vaos.clear();
}
@ -1177,7 +1172,7 @@ void GLSLShader::save(const char *filename)
outd("frame_count_mod", p->frame_count_mod);
}
if (param.size() > 0)
if (!param.empty())
{
fprintf(file, "parameters = \"");
for (unsigned int i = 0; i < param.size(); i++)
@ -1187,12 +1182,12 @@ void GLSLShader::save(const char *filename)
fprintf(file, "\n");
}
for (unsigned int i = 0; i < param.size(); i++)
for (auto &p : param)
{
fprintf(file, "%s = \"%f\"\n", param[i].id.c_str(), param[i].val);
fprintf(file, "%s = \"%f\"\n", p.id.c_str(), p.val);
}
if (lut.size() > 0)
if (!lut.empty())
{
fprintf(file, "textures = \"");
for (unsigned int i = 0; i < lut.size(); i++)
@ -1202,12 +1197,12 @@ void GLSLShader::save(const char *filename)
fprintf(file, "\n");
}
for (unsigned int i = 0; i < lut.size(); i++)
for (auto &l : lut)
{
fprintf(file, "%s = \"%s\"\n", lut[i].id, lut[i].filename);
fprintf(file, "%s_linear = \"%s\"\n", lut[i].id, lut[i].filter == GL_LINEAR || lut[i].filter == GL_LINEAR_MIPMAP_LINEAR ? "true" : "false");
fprintf(file, "%s_wrap_mode = \"%s\"\n", lut[i].id, wrap_mode_enum_to_string(lut[i].wrap_mode));
fprintf(file, "%s_mipmap = \"%s\"\n", lut[i].id, lut[i].mipmap ? "true" : "false");
fprintf(file, "%s = \"%s\"\n", l.id, l.filename);
fprintf(file, "%s_linear = \"%s\"\n", l.id, l.filter == GL_LINEAR || l.filter == GL_LINEAR_MIPMAP_LINEAR ? "true" : "false");
fprintf(file, "%s_wrap_mode = \"%s\"\n", l.id, wrap_mode_enum_to_string(l.wrap_mode));
fprintf(file, "%s_mipmap = \"%s\"\n", l.id, l.mipmap ? "true" : "false");
}
fclose(file);
@ -1233,20 +1228,20 @@ void GLSLShader::destroy()
{
if (pass[i].uses_feedback)
glDeleteTextures(1, &pass[i].feedback_texture);
if (pass[i].ubo_buffer.size() > 0)
if (!pass[i].ubo_buffer.empty())
glDeleteBuffers(1, &pass[i].ubo);
}
#endif
}
for (unsigned int i = 0; i < lut.size(); i++)
for (auto &l : lut)
{
glDeleteTextures(1, &lut[i].texture);
glDeleteTextures(1, &l.texture);
}
for (unsigned int i = 0; i < prev_frame.size(); i++)
for (auto &frame: prev_frame)
{
glDeleteTextures(1, &prev_frame[i].texture);
glDeleteTextures(1, &frame.texture);
}
glDeleteBuffers(1, &vbo);

View File

@ -164,7 +164,7 @@ struct GLSLShader
GLSLViewportCallback vpcallback);
void set_shader_vars(unsigned int pass, bool inverted);
void clear_shader_vars();
void read_shader_file_with_includes(std::string filename,
void read_shader_file_with_includes(const std::string& filename,
std::vector<std::string> &lines,
int p);
GLuint compile_shader(std::vector<std::string> &lines, const char *aliases,
@ -190,8 +190,8 @@ struct GLSLShader
bool using_slang;
#ifdef USE_SLANG
std::string slang_get_stage(std::vector<std::string> &lines,
std::string name);
GLint slang_compile(std::vector<std::string> &lines, std::string stage);
const std::string &name);
GLint slang_compile(std::vector<std::string> &lines, const std::string& stage);
void slang_introspect();
void slang_set_shader_vars(int p, bool inverted);
void slang_clear_shader_vars();

View File

@ -5,8 +5,8 @@
\*****************************************************************************/
#include <png.h>
#include <stdlib.h>
#include <string.h>
#include <cstdlib>
#include <cstring>
#include "shader_helpers.h"
#include "shader_platform.h"
@ -18,16 +18,13 @@ static void gl_error_callback(GLenum source, GLenum type, GLuint id,
if (type == GL_DEBUG_TYPE_ERROR)
{
fprintf(stderr, "GL: %s type = 0x%x, severity = 0x%x, \n %s\n",
(type == GL_DEBUG_TYPE_ERROR ? "*ERROR*" : ""), type, severity,
message);
"*ERROR*", type, severity, message);
}
else
{
fprintf(stderr, "GL type = 0x%x, severity = 0x%x, \n %s\n", type,
severity, message);
}
return;
}
int gl_version()
@ -47,7 +44,7 @@ int gl_version()
return version;
}
bool gl_srgb_available(void)
bool gl_srgb_available()
{
if (gl_version() >= 30)
return true;
@ -61,7 +58,7 @@ bool gl_srgb_available(void)
return false;
}
bool gl_float_texture_available(void)
bool gl_float_texture_available()
{
if (gl_version() >= 32)
return true;
@ -74,10 +71,10 @@ bool gl_float_texture_available(void)
return false;
}
void gl_log_errors(void)
void gl_log_errors()
{
glEnable(GL_DEBUG_OUTPUT);
glDebugMessageCallback((GLDEBUGPROC)gl_error_callback, 0);
glDebugMessageCallback((GLDEBUGPROC)gl_error_callback, nullptr);
}
bool loadPngImage(const char *name, int &outWidth, int &outHeight,
@ -89,28 +86,28 @@ bool loadPngImage(const char *name, int &outWidth, int &outHeight,
unsigned int sig_read = 0;
FILE *fp;
if ((fp = fopen(name, "rb")) == NULL)
if ((fp = fopen(name, "rb")) == nullptr)
return false;
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
if (png_ptr == NULL)
if (png_ptr == nullptr)
{
fclose(fp);
return false;
}
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL)
if (info_ptr == nullptr)
{
fclose(fp);
png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
png_destroy_read_struct(&png_ptr, (png_infopp)nullptr, (png_infopp)nullptr);
return false;
}
if (setjmp(png_jmpbuf(png_ptr)))
{
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)nullptr);
fclose(fp);
return false;
}
@ -122,7 +119,7 @@ bool loadPngImage(const char *name, int &outWidth, int &outHeight,
png_read_png(png_ptr, info_ptr,
PNG_TRANSFORM_STRIP_16 | PNG_TRANSFORM_PACKING |
PNG_TRANSFORM_EXPAND,
(png_voidp)NULL);
(png_voidp)nullptr);
outWidth = png_get_image_width(png_ptr, info_ptr);
outHeight = png_get_image_height(png_ptr, info_ptr);
@ -141,7 +138,7 @@ bool loadPngImage(const char *name, int &outWidth, int &outHeight,
grayscale = true;
break;
default:
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
png_destroy_read_struct(&png_ptr, &info_ptr, nullptr);
fclose(fp);
return false;
}
@ -156,7 +153,7 @@ bool loadPngImage(const char *name, int &outWidth, int &outHeight,
memcpy(*outData + (row_bytes * i), row_pointers[i], row_bytes);
}
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)nullptr);
fclose(fp);
@ -168,11 +165,10 @@ bool loadPngImage(const char *name, int &outWidth, int &outHeight,
bool loadTGA(const char *filename, STGA &tgaFile)
{
FILE *file;
unsigned char type[4];
unsigned char info[6];
file = fopen(filename, "rb");
FILE *file = fopen(filename, "rb");
if (!file)
return false;

View File

@ -8,9 +8,6 @@
#define __SHADER_HELPERS_H
#include "shader_platform.h"
#include <vector>
#include <string>
#include <sstream>
typedef struct _STGA
{

View File

@ -4,9 +4,7 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __SHADER_PLATFORM_H
#define __SHADER_PLATFORM_H
#pragma once
#include "port.h"
#if defined(SNES9X_QT)
@ -30,6 +28,4 @@
#define chdir(dir) _chdir(dir)
#define realpath(src, resolved) _fullpath(resolved, src, PATH_MAX)
#endif
#endif
#endif /* __SHADER_PLATFORM_H */
#endif

View File

@ -16,13 +16,13 @@
#include "external/SPIRV-Cross/spirv_glsl.hpp"
std::string GLSLShader::slang_get_stage(std::vector<std::string> &lines,
std::string name)
const std::string &name)
{
std::ostringstream output;
bool in_stage = true;
if (name.empty())
return std::string("");
return {};
for (auto &line : lines)
{
@ -85,7 +85,7 @@ static void printuniforms(std::vector<SlangUniform> &unif)
#endif // #if 0
GLint GLSLShader::slang_compile(std::vector<std::string> &lines,
std::string stage)
const std::string& stage)
{
static bool ProcessInitialized = false;
@ -98,7 +98,7 @@ GLint GLSLShader::slang_compile(std::vector<std::string> &lines,
std::string source = slang_get_stage(lines, stage);
EShLanguage language;
if (!stage.compare("fragment"))
if (stage == "fragment")
language = EShLangFragment;
else
language = EShLangVertex;
@ -107,8 +107,7 @@ GLint GLSLShader::slang_compile(std::vector<std::string> &lines,
const char *csource = source.c_str();
shader.setStrings(&csource, 1);
EShMessages messages =
(EShMessages)(EShMsgDefault | EShMsgVulkanRules | EShMsgSpvRules);
auto messages = (EShMessages)(EShMsgDefault | EShMsgVulkanRules | EShMsgSpvRules);
std::string debug;
auto forbid_includer = glslang::TShader::ForbidIncluder();
@ -175,17 +174,17 @@ GLint GLSLShader::slang_compile(std::vector<std::string> &lines,
std::string glsl_source = glsl.compile();
GLint status = 0;
GLchar *cstring = (GLchar *)glsl_source.c_str();
auto cstring = (GLchar *)glsl_source.c_str();
GLint shaderid = glCreateShader(
language == EShLangFragment ? GL_FRAGMENT_SHADER : GL_VERTEX_SHADER);
glShaderSource(shaderid, 1, &cstring, NULL);
glShaderSource(shaderid, 1, &cstring, nullptr);
glCompileShader(shaderid);
glGetShaderiv(shaderid, GL_COMPILE_STATUS, &status);
char info_log[1024];
glGetShaderInfoLog(shaderid, 1024, NULL, info_log);
glGetShaderInfoLog(shaderid, 1024, nullptr, info_log);
if (*info_log)
puts(info_log);
@ -195,7 +194,7 @@ GLint GLSLShader::slang_compile(std::vector<std::string> &lines,
return shaderid;
}
static inline bool isalldigits(std::string str)
static inline bool isalldigits(const std::string &str)
{
for (auto c : str)
{
@ -233,8 +232,8 @@ void GLSLShader::slang_introspect()
for (int j = 0; j < num_uniforms; j++)
{
char name[1024];
glGetActiveUniformName(p.program, j, 1024, NULL, name);
names.push_back(std::string(name));
glGetActiveUniformName(p.program, j, 1024, nullptr, name);
names.emplace_back(name);
locations[j] = glGetUniformLocation(p.program, name);
}
@ -258,7 +257,7 @@ void GLSLShader::slang_introspect()
else
name = names[j];
auto indexedtexorsize = [&](std::string needle, int type) -> bool {
auto indexedtexorsize = [&](const std::string &needle, int type) -> bool {
if (name.find(needle) == 0)
{
std::string tmp = name.substr(needle.length());
@ -279,36 +278,36 @@ void GLSLShader::slang_introspect()
return false;
};
if (!name.compare("MVP"))
if (name == "MVP")
{
u.type = SL_MVP;
}
else if (!name.compare("Original"))
else if (name == "Original")
{
u.type = SL_PASSTEXTURE;
u.num = 0;
}
else if (!name.compare("OriginalSize"))
else if (name == "OriginalSize")
{
u.type = SL_PASSSIZE;
u.num = 0;
}
else if (!name.compare("Source"))
else if (name == "Source")
{
u.type = SL_PASSTEXTURE;
u.num = i - 1;
}
else if (!name.compare("SourceSize"))
else if (name == "SourceSize")
{
u.type = SL_PASSSIZE;
u.num = i - 1;
}
else if (!name.compare("OutputSize"))
else if (name == "OutputSize")
{
u.type = SL_PASSSIZE;
u.num = i;
}
else if (!name.compare("FrameCount"))
else if (name == "FrameCount")
{
u.type = SL_FRAMECOUNT;
}
@ -354,13 +353,13 @@ void GLSLShader::slang_introspect()
{
std::string lutname(lut[k].id);
if (name.compare(lutname) == 0)
if (name == lutname)
{
u.type = SL_LUTTEXTURE;
u.num = k;
matched_lut = true;
}
else if (name.compare(lutname + "Size") == 0)
else if (name == lutname + "Size")
{
u.type = SL_LUTSIZE;
u.num = k;
@ -378,13 +377,13 @@ void GLSLShader::slang_introspect()
{
std::string alias(pass[k].alias);
if (name.compare(alias) == 0)
if (name == alias)
{
u.type = SL_PASSTEXTURE;
u.num = k;
matched_alias = true;
}
else if (name.compare(alias + "Size") == 0)
else if (name == alias + "Size")
{
u.type = SL_PASSSIZE;
u.num = k;
@ -400,7 +399,7 @@ void GLSLShader::slang_introspect()
u.type = SL_INVALID;
for (int k = 0; k < (int)param.size(); k++)
{
if (name.compare(param[k].id) == 0)
if (name == param[k].id)
{
u.type = SL_PARAM;
u.num = k;
@ -475,7 +474,7 @@ void GLSLShader::slang_set_shader_vars(int p, bool inverted)
attr = glGetAttribLocation(pass[p].program, "TexCoord");
if (attr > -1)
{
GLfloat *offset = 0;
GLfloat *offset = nullptr;
offset += 16;
if (inverted)
offset += 8;
@ -546,7 +545,7 @@ void GLSLShader::slang_set_shader_vars(int p, bool inverted)
if (u.location == -1)
{
GLfloat *data = (GLfloat *)(ubo + u.offset);
auto data = (GLfloat *)(ubo + u.offset);
data[0] = size[0];
data[1] = size[1];
data[2] = size[2];
@ -560,8 +559,7 @@ void GLSLShader::slang_set_shader_vars(int p, bool inverted)
case SL_MVP:
if (u.location == -1)
{
GLfloat *data = (GLfloat *)(ubo + u.offset);
auto data = (GLfloat *)(ubo + u.offset);
for (int i = 0; i < 16; i++)
data[i] = mvp_ortho[i];
}
@ -585,7 +583,7 @@ void GLSLShader::slang_set_shader_vars(int p, bool inverted)
}
}
if (pass[p].ubo_buffer.size() > 0)
if (!pass[p].ubo_buffer.empty())
{
glBindBuffer(GL_UNIFORM_BUFFER, pass[p].ubo);
glBufferData(GL_UNIFORM_BUFFER, pass[p].ubo_buffer.size(), ubo,

View File

@ -4,18 +4,17 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <cstdio>
#include "wayland_egl_context.hpp"
WaylandEGLContext::WaylandEGLContext()
{
egl_display = NULL;
egl_surface = NULL;
egl_context = NULL;
egl_config = NULL;
egl_window = NULL;
egl_display = nullptr;
egl_surface = nullptr;
egl_context = nullptr;
egl_config = nullptr;
egl_window = nullptr;
x = 0;
y = 0;
}
@ -95,7 +94,7 @@ bool WaylandEGLContext::create_context()
return false;
}
egl_surface = eglCreateWindowSurface(egl_display, egl_config, (EGLNativeWindowType)egl_window, NULL);
egl_surface = eglCreateWindowSurface(egl_display, egl_config, (EGLNativeWindowType)egl_window, nullptr);
if (!egl_surface)
{
printf("Couldn't create surface.\n");

View File

@ -4,9 +4,7 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __WAYLAND_EGL_CONTEXT_H
#define __WAYLAND_EGL_CONTEXT_H
#pragma once
#include "opengl_context.hpp"
#include "common/video/wayland/wayland_surface.hpp"
@ -18,17 +16,17 @@ class WaylandEGLContext : public OpenGLContext
{
public:
WaylandEGLContext();
~WaylandEGLContext();
~WaylandEGLContext() override;
bool attach(wl_display *display, wl_surface *surface, WaylandSurface::Metrics m);
bool create_context();
void resize() {};
bool create_context() override;
void resize() override {};
void resize(WaylandSurface::Metrics m);
void swap_buffers();
void swap_interval(int frames);
void make_current();
void swap_buffers() override;
void swap_interval(int frames) override;
void make_current() override;
void shrink();
void regrow();
bool ready();
bool ready() override;
EGLDisplay egl_display;
EGLSurface egl_surface;
@ -38,6 +36,4 @@ class WaylandEGLContext : public OpenGLContext
wl_egl_window *egl_window;
std::unique_ptr<WaylandSurface> wayland_surface;
};
#endif
};

View File

@ -4,9 +4,6 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#include <cstdlib>
#include <cstdio>
#include "wgl_context.hpp"
WGLContext::WGLContext()

View File

@ -9,13 +9,11 @@
#include "opengl_context.hpp"
#include <glad/wgl.h>
class WGLContext : public OpenGLContext
{
public:
WGLContext();
~WGLContext();
~WGLContext() override;
bool attach(HWND xid);
bool create_context() override;
void resize() override;

View File

@ -18,10 +18,10 @@ int mipmap_levels_for_size(int width, int height)
void trim(string_view &view)
{
while (view.length() > 0 && isspace((unsigned char)view.at(0)))
while (!view.empty() && isspace((unsigned char)view.at(0)))
view.remove_prefix(1);
while (view.length() > 0 && isspace((unsigned char)view.at(view.length() - 1)))
while (!view.empty() && isspace((unsigned char)view.at(view.length() - 1)))
view.remove_suffix(1);
}
@ -78,11 +78,10 @@ vector<string> split_string(const string_view &str, unsigned char delim)
{
vector<string> tokens;
size_t pos = 0;
size_t index;
while (pos < str.length())
{
index = str.find(delim, pos);
size_t index = str.find(delim, pos);
if (index == string::npos)
{
if (pos < str.length())

View File

@ -17,7 +17,7 @@
using std::string;
using std::to_string;
bool SlangPreset::load_preset_file(string filename)
bool SlangPreset::load_preset_file(const string &filename)
{
if (!ends_with(filename, ".slangp"))
return false;
@ -35,17 +35,17 @@ bool SlangPreset::load_preset_file(string filename)
passes.resize(num_passes);
int index;
auto key = [&](string s) -> string { return s + to_string(index); };
auto iGetBool = [&](string s, bool def = false) -> bool {
auto key = [&](const string &s) -> string { return s + to_string(index); };
auto iGetBool = [&](const string &s, bool def = false) -> bool {
return conf.get_bool(key(s), def);
};
auto iGetString = [&](string s, string def = "") -> string {
auto iGetString = [&](const string &s, const string &def = "") -> string {
return conf.get_string(key(s), def);
};
auto iGetFloat = [&](string s, float def = 1.0f) -> float {
auto iGetFloat = [&](const string &s, float def = 1.0f) -> float {
return conf.get_float(key(s), def);
};
auto iGetInt = [&](string s, int def = 0) -> int {
auto iGetInt = [&](const string &s, int def = 0) -> int {
return conf.get_int(key(s), def);
};
@ -99,10 +99,10 @@ bool SlangPreset::load_preset_file(string filename)
SlangShader::initialize_glslang();
std::vector<std::future<bool>> futures;
for (size_t i = 0; i < passes.size(); i++)
for (auto &pass : passes)
{
futures.push_back(std::async(std::launch::async, [this, i]() -> bool {
return passes[i].load_file();
futures.push_back(std::async(std::launch::async, [this, &pass]() -> bool {
return pass.load_file();
}));
}
if (!std::all_of(futures.begin(), futures.end(), [](auto &f) { return f.get(); }))
@ -115,7 +115,7 @@ bool SlangPreset::load_preset_file(string filename)
auto value_str = conf.get_string(p.id, "");
if (!value_str.empty())
{
p.val = atof(value_str.c_str());
p.val = std::stof(value_str);
if (p.val < p.min)
p.val = p.min;
else if (p.val > p.max)
@ -137,7 +137,7 @@ void SlangPreset::gather_parameters()
{
for (auto &p : s.parameters)
{
auto it = std::find_if(parameters.begin(), parameters.end(), [&p](SlangShader::Parameter &needle) {
auto it = std::find_if(parameters.begin(), parameters.end(), [&p](const SlangShader::Parameter &needle) {
return (needle.id == p.id);
});
@ -154,37 +154,36 @@ void SlangPreset::gather_parameters()
void SlangPreset::print()
{
printf("Number of Shaders: %zu\n", passes.size());
for (size_t i = 0; i < passes.size(); i++)
for (auto &pass : passes)
{
auto &s = passes[i];
printf(" Shader \n");
printf(" filename: %s\n", s.filename.c_str());
printf(" alias: %s\n", s.alias.c_str());
printf(" filter_linear: %d\n", s.filter_linear);;
printf(" mipmap_input: %d\n", s.mipmap_input);
printf(" float_framebuffer: %d\n", s.float_framebuffer);
printf(" srgb_framebuffer: %d\n", s.srgb_framebuffer);
printf(" frame_count_mod: %d\n", s.frame_count_mod);
printf(" wrap_mode: %s\n", s.wrap_mode.c_str());
printf(" scale_type_x: %s\n", s.scale_type_x.c_str());
printf(" scale_type_y: %s\n", s.scale_type_y.c_str());
printf(" scale_x: %f\n", s.scale_x);
printf(" scale_y: %f\n", s.scale_y);
printf(" filename: %s\n", pass.filename.c_str());
printf(" alias: %s\n", pass.alias.c_str());
printf(" filter_linear: %d\n", pass.filter_linear);;
printf(" mipmap_input: %d\n", pass.mipmap_input);
printf(" float_framebuffer: %d\n", pass.float_framebuffer);
printf(" srgb_framebuffer: %d\n", pass.srgb_framebuffer);
printf(" frame_count_mod: %d\n", pass.frame_count_mod);
printf(" wrap_mode: %s\n", pass.wrap_mode.c_str());
printf(" scale_type_x: %s\n", pass.scale_type_x.c_str());
printf(" scale_type_y: %s\n", pass.scale_type_y.c_str());
printf(" scale_x: %f\n", pass.scale_x);
printf(" scale_y: %f\n", pass.scale_y);
printf(" pragma lines: ");
for (auto &p : s.pragma_stage_lines)
for (auto &p : pass.pragma_stage_lines)
printf("%zu ", p);
printf("\n");
printf(" Number of parameters: %zu\n", s.parameters.size());
for (auto &p : s.parameters)
printf(" Number of parameters: %zu\n", pass.parameters.size());
for (auto &p : pass.parameters)
{
printf(" %s \"%s\" min: %f max: %f val: %f step: %f digits: %d\n",
p.id.c_str(), p.name.c_str(), p.min, p.max, p.val, p.step, p.significant_digits);
}
printf(" Uniforms: %zu\n", s.uniforms.size());
printf(" UBO size: %zu, binding: %d\n", s.ubo_size, s.ubo_binding);
printf(" Push Constant block size: %zu\n", s.push_constant_block_size);
for (auto &u : s.uniforms)
printf(" Uniforms: %zu\n", pass.uniforms.size());
printf(" UBO size: %zu, binding: %d\n", pass.ubo_size, pass.ubo_binding);
printf(" Push Constant block size: %zu\n", pass.push_constant_block_size);
for (auto &u : pass.uniforms)
{
const char *strings[] = {
"Output Size",
@ -223,8 +222,8 @@ void SlangPreset::print()
}
}
printf(" Samplers: %zu\n", s.samplers.size());
for (auto &sampler : s.samplers)
printf(" Samplers: %zu\n", pass.samplers.size());
for (auto &sampler : pass.samplers)
{
const char *strings[] =
{
@ -285,7 +284,7 @@ void SlangPreset::print()
bool SlangPreset::match_sampler_semantic(const string &name, int pass, SlangShader::Sampler::Type &type, int &specifier)
{
auto match_with_specifier = [&name, &specifier](string prefix) -> bool {
auto match_with_specifier = [&name, &specifier](const string &prefix) -> bool {
if (name.compare(0, prefix.length(), prefix) != 0)
return false;
@ -394,7 +393,7 @@ bool SlangPreset::match_buffer_semantic(const string &name, int pass, SlangShade
if (name.find("Size") != string::npos)
{
auto match = [&name, &specifier](string prefix) -> bool {
auto match = [&name, &specifier](const string &prefix) -> bool {
if (name.compare(0, prefix.length(), prefix) != 0)
return false;
@ -514,7 +513,7 @@ bool SlangPreset::introspect_shader(SlangShader &shader, int pass, SlangShader::
return false;
};
if (res.push_constant_buffers.size() == 0)
if (res.push_constant_buffers.empty())
{
shader.push_constant_block_size = 0;
}
@ -548,7 +547,7 @@ bool SlangPreset::introspect_shader(SlangShader &shader, int pass, SlangShader::
}
}
if (res.uniform_buffers.size() == 0)
if (res.uniform_buffers.empty())
{
shader.ubo_size = 0;
}
@ -583,13 +582,13 @@ bool SlangPreset::introspect_shader(SlangShader &shader, int pass, SlangShader::
}
}
if (res.sampled_images.size() == 0 && stage == SlangShader::Stage::Fragment)
if (res.sampled_images.empty() && stage == SlangShader::Stage::Fragment)
{
printf("No sampled images found in fragment shader.\n");
return false;
}
if (res.sampled_images.size() > 0 && stage == SlangShader::Stage::Vertex)
if (!res.sampled_images.empty() && stage == SlangShader::Stage::Vertex)
{
printf("Sampled image found in vertex shader.\n");
return false;
@ -653,22 +652,22 @@ bool SlangPreset::introspect()
return true;
}
bool SlangPreset::save_to_file(std::string filename)
bool SlangPreset::save_to_file(const std::string& filename)
{
std::ofstream out(filename);
if (!out.is_open())
return false;
auto outs = [&](std::string key, std::string value) { out << key << " = \"" << value << "\"\n"; };
auto outb = [&](std::string key, bool value) { outs(key, value ? "true" : "false"); };
auto outa = [&](std::string key, auto value) { outs(key, to_string(value)); };
auto outs = [&](const std::string &key, const std::string &value) { out << key << " = \"" << value << "\"\n"; };
auto outb = [&](const std::string &key, bool value) { outs(key, value ? "true" : "false"); };
auto outa = [&](const std::string &key, auto value) { outs(key, to_string(value)); };
outa("shaders", passes.size());
for (size_t i = 0; i < passes.size(); i++)
{
auto &pass = passes[i];
auto indexed = [i](std::string str) { return str + to_string(i); };
auto indexed = [i](const std::string &str) { return str + to_string(i); };
outs(indexed("shader"), pass.filename);
outb(indexed("filter_linear"), pass.filter_linear);
outs(indexed("wrap_mode"), pass.wrap_mode);
@ -683,9 +682,9 @@ bool SlangPreset::save_to_file(std::string filename)
outa(indexed("frame_count_mod"), pass.frame_count_mod);
}
if (parameters.size() > 0)
if (!parameters.empty())
{
std::string parameter_list = "";
std::string parameter_list;
for (size_t i = 0; i < parameters.size(); i++)
{
parameter_list += parameters[i].id;
@ -698,9 +697,9 @@ bool SlangPreset::save_to_file(std::string filename)
for (auto &item : parameters)
outa(item.id, item.val);
if (textures.size() > 0)
if (!textures.empty())
{
std::string texture_list = "";
std::string texture_list;
for (size_t i = 0; i < textures.size(); i++)
{
texture_list += textures[i].id;

View File

@ -8,13 +8,13 @@
struct SlangPreset
{
void print();
bool load_preset_file(std::string filename);
bool load_preset_file(const std::string &filename);
bool introspect();
bool introspect_shader(SlangShader &s, int index, SlangShader::Stage stage);
bool match_buffer_semantic(const std::string &name, int pass, SlangShader::Uniform::Type &type, int &specifier);
bool match_sampler_semantic(const std::string &name, int pass, SlangShader::Sampler::Type &type, int &specifier);
void gather_parameters();
bool save_to_file(std::string filename);
bool save_to_file(const std::string& filename);
struct Texture
{

View File

@ -23,10 +23,10 @@ static std::string trim_quotes(std::string str)
return str;
}
bool IniFile::load_file(std::string filename)
bool IniFile::load_file(const std::string& filename)
{
std::ifstream file;
file.open(filename.c_str(), std::ios_base::binary);
file.open(filename, std::ios_base::binary);
if (!file.is_open())
{
printf("No file %s\n", filename.c_str());
@ -34,7 +34,7 @@ bool IniFile::load_file(std::string filename)
}
std::string line;
while (1)
while (true)
{
if (file.eof())
break;
@ -58,7 +58,7 @@ bool IniFile::load_file(std::string filename)
line = trim_comments(line);
if (line.length() == 0)
if (line.empty())
continue;
auto equals = line.find('=');
@ -74,7 +74,7 @@ bool IniFile::load_file(std::string filename)
return true;
}
std::string IniFile::get_string(std::string key, std::string default_value = "")
std::string IniFile::get_string(const std::string &key, std::string default_value = "")
{
auto it = keys.find(key);
if (it == keys.end())
@ -83,7 +83,7 @@ std::string IniFile::get_string(std::string key, std::string default_value = "")
return it->second.first;
}
int IniFile::get_int(std::string key, int default_value = 0)
int IniFile::get_int(const std::string &key, int default_value = 0)
{
auto it = keys.find(key);
if (it == keys.end())
@ -92,7 +92,7 @@ int IniFile::get_int(std::string key, int default_value = 0)
return std::stoi(it->second.first);
}
float IniFile::get_float(std::string key, float default_value = 0.0f)
float IniFile::get_float(const std::string &key, float default_value = 0.0f)
{
auto it = keys.find(key);
if (it == keys.end())
@ -101,7 +101,7 @@ float IniFile::get_float(std::string key, float default_value = 0.0f)
return std::stof(it->second.first);
}
std::string IniFile::get_source(std::string key)
std::string IniFile::get_source(const std::string &key)
{
auto it = keys.find(key);
if (it == keys.end())
@ -110,7 +110,7 @@ std::string IniFile::get_source(std::string key)
return it->second.second;
}
bool IniFile::get_bool(std::string key, bool default_value = false)
bool IniFile::get_bool(const std::string &key, bool default_value = false)
{
auto it = keys.find(key);
if (it == keys.end())
@ -127,7 +127,7 @@ bool IniFile::get_bool(std::string key, bool default_value = false)
return false;
}
bool IniFile::exists(std::string key)
bool IniFile::exists(const std::string &key)
{
auto it = keys.find(key);
if (it == keys.end())

View File

@ -4,12 +4,12 @@
struct IniFile
{
bool load_file(std::string filename);
std::string get_string(std::string key, std::string default_string);
int get_int(std::string key, int default_int);
float get_float(std::string key, float default_float);
bool get_bool(std::string key, bool default_bool);
std::string get_source(std::string key);
bool exists(std::string key);
bool load_file(const std::string& filename);
std::string get_string(const std::string &key, std::string default_string);
int get_int(const std::string &key, int default_int);
float get_float(const std::string &key, float default_float);
bool get_bool(const std::string &key, bool default_bool);
std::string get_source(const std::string &key);
bool exists(const std::string &key);
std::unordered_map<std::string, std::pair<std::string, std::string>> keys;
};

View File

@ -19,7 +19,7 @@ using std::vector;
#include and #pragma directives. Will strip all directives except
#pragma stage.
*/
bool SlangShader::preprocess_shader_file(string filename, vector<string> &lines)
bool SlangShader::preprocess_shader_file(const string& filename, vector<string> &lines)
{
std::ifstream stream(filename.c_str(), std::ios::binary);
@ -39,7 +39,7 @@ bool SlangShader::preprocess_shader_file(string filename, vector<string> &lines)
{
sv.remove_prefix(8);
trim(sv);
if (sv.length() && sv[0] == '\"' && sv[sv.length() - 1] == '\"')
if (!sv.empty() && sv[0] == '\"' && sv[sv.length() - 1] == '\"')
{
sv.remove_prefix(1);
sv.remove_suffix(1);
@ -152,7 +152,7 @@ void SlangShader::divide_into_stages(const std::vector<std::string> &lines)
Load a shader file into memory, preprocess, divide and compile it to
SPIRV bytecode. Returns true on success.
*/
bool SlangShader::load_file(string new_filename)
bool SlangShader::load_file(const string &new_filename)
{
if (!new_filename.empty())
filename = new_filename;
@ -182,10 +182,10 @@ void SlangShader::initialize_glslang()
}
}
std::vector<uint32_t> SlangShader::generate_spirv(std::string shader_string, std::string stage)
std::vector<uint32_t> SlangShader::generate_spirv(const std::string &shader_string, const std::string &stage)
{
initialize_glslang();
const EShMessages messages = (EShMessages)(EShMsgDefault | EShMsgVulkanRules | EShMsgSpvRules);
const auto messages = (EShMessages)(EShMsgDefault | EShMsgVulkanRules | EShMsgSpvRules);
string debug;
auto forbid_includer = glslang::TShader::ForbidIncluder();
@ -193,8 +193,8 @@ std::vector<uint32_t> SlangShader::generate_spirv(std::string shader_string, std
glslang::TShader shaderTShader(language);
auto compile = [&](glslang::TShader &shader, string &shader_string, std::vector<uint32_t> &spirv) -> bool {
const char *source = shader_string.c_str();
auto compile = [&](glslang::TShader &shader, const string &source_string, std::vector<uint32_t> &spirv) -> bool {
const char *source = source_string.c_str();
shader.setStrings(&source, 1);
if (!shader.preprocess(GetDefaultResources(), 450, ENoProfile, false, false, messages, &debug, forbid_includer))
return false;

View File

@ -65,13 +65,13 @@ struct SlangShader
Fragment
};
bool preprocess_shader_file(std::string filename, std::vector<std::string> &lines);
bool preprocess_shader_file(const std::string& filename, std::vector<std::string> &lines);
void set_base_path(std::string filename);
bool load_file(std::string new_filename = "");
bool load_file(const std::string &new_filename = "");
void divide_into_stages(const std::vector<std::string> &lines);
bool generate_spirv();
static void initialize_glslang();
static std::vector<uint32_t> generate_spirv(std::string shader_string, std::string stage);
static std::vector<uint32_t> generate_spirv(const std::string &shader_string, const std::string &stage);
std::string filename;
std::string alias;

View File

@ -48,7 +48,7 @@ void ShaderChain::construct_buffer_objects()
for (auto &uniform : pipeline.shader->uniforms)
{
void *location = 0;
void *location = nullptr;
const float MVP[16] = { 1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
@ -188,7 +188,7 @@ void ShaderChain::update_and_propagate_sizes(int original_width_new, int origina
}
}
bool ShaderChain::load_shader_preset(std::string filename)
bool ShaderChain::load_shader_preset(const std::string &filename)
{
if (!ends_with(filename, ".slangp"))
printf("Warning: loading preset without .slangp extension\n");
@ -232,7 +232,7 @@ bool ShaderChain::load_shader_preset(std::string filename)
if (p.ubo_size)
num_ubos++;
if (p.samplers.size() > 0)
if (!p.samplers.empty())
num_samplers += p.samplers.size();
}
@ -438,7 +438,7 @@ bool ShaderChain::do_frame_without_swap(uint8_t *data, int width, int height, in
cmd.bindPipeline(vk::PipelineBindPoint::eGraphics, pipe.pipeline.get());
cmd.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, pipe.pipeline_layout.get(), 0, frame.descriptor_set.get(), {});
cmd.bindVertexBuffers(0, vertex_buffer, { 0 });
if (pipe.push_constants.size() > 0)
if (!pipe.push_constants.empty())
cmd.pushConstants(pipe.pipeline_layout.get(), vk::ShaderStageFlagBits::eAllGraphics, 0, pipe.push_constants.size(), pipe.push_constants.data());
if (is_last_pass)
@ -544,7 +544,7 @@ void ShaderChain::upload_original(uint8_t *data, int width, int height, int stri
bool ShaderChain::load_lookup_textures()
{
if (preset->textures.size() < 1)
if (preset->textures.empty())
return true;
lookup_textures.clear();

View File

@ -16,7 +16,7 @@ class ShaderChain
ShaderChain(Context *context_);
~ShaderChain();
bool load_shader_preset(std::string filename);
bool load_shader_preset(const std::string &filename);
void update_and_propagate_sizes(int original_width_, int original_height_, int viewport_width_, int viewport_height_);
bool load_lookup_textures();
bool do_frame(uint8_t *data, int width, int height, int stride, vk::Format format, int viewport_x, int viewport_y, int viewport_width, int viewport_height);

View File

@ -3,7 +3,7 @@
namespace Vulkan
{
static VkFormat format_string_to_format(std::string target, VkFormat default_format)
static VkFormat format_string_to_format(const std::string &target, VkFormat default_format)
{
struct
{
@ -51,13 +51,13 @@ static VkFormat format_string_to_format(std::string target, VkFormat default_for
return default_format;
}
vk::SamplerAddressMode wrap_mode_from_string(std::string s)
vk::SamplerAddressMode wrap_mode_from_string(const std::string &mode_string)
{
if (s == "clamp_to_border")
if (mode_string == "clamp_to_border")
return vk::SamplerAddressMode::eClampToBorder;
if (s == "repeat")
if (mode_string == "repeat")
return vk::SamplerAddressMode::eRepeat;
if (s == "mirrored_repeat")
if (mode_string == "mirrored_repeat")
return vk::SamplerAddressMode::eMirroredRepeat;
return vk::SamplerAddressMode::eClampToBorder;

View File

@ -46,6 +46,6 @@ class SlangPipeline
int destination_height;
};
vk::SamplerAddressMode wrap_mode_from_string(std::string s);
vk::SamplerAddressMode wrap_mode_from_string(const std::string &mode_string);
} // namespace Vulkan

View File

@ -14,10 +14,6 @@ Swapchain::Swapchain(Context &context_)
{
}
Swapchain::~Swapchain()
{
}
void Swapchain::set_vsync(bool new_setting)
{
if (vsync != new_setting)
@ -28,7 +24,7 @@ void Swapchain::set_vsync(bool new_setting)
}
}
void Swapchain::on_render_pass_end(std::function<void ()> function)
void Swapchain::on_render_pass_end(const std::function<void()> &function)
{
end_render_pass_function = function;
}
@ -93,15 +89,6 @@ vk::Image Swapchain::get_image()
return image_data[current_swapchain_image].image;
}
template<typename T>
static bool vector_find(std::vector<T> haystack, T&& needle)
{
for (auto &elem : haystack)
if (elem == needle)
return true;
return false;
}
vk::PresentModeKHR Swapchain::get_present_mode() {
auto present_mode = vk::PresentModeKHR::eFifo;
@ -121,11 +108,9 @@ vk::PresentModeKHR Swapchain::get_present_mode() {
bool Swapchain::check_and_resize(int width, int height)
{
vk::SurfaceCapabilitiesKHR surface_capabilities;
if (width == -1 && height == -1)
{
surface_capabilities = physical_device.getSurfaceCapabilitiesKHR(surface).value;
vk::SurfaceCapabilitiesKHR surface_capabilities = physical_device.getSurfaceCapabilitiesKHR(surface).value;
width = surface_capabilities.currentExtent.width;
height = surface_capabilities.currentExtent.height;
}

View File

@ -11,8 +11,7 @@ class Context;
class Swapchain
{
public:
Swapchain(Context &);
~Swapchain();
explicit Swapchain(Context &);
bool create();
bool uncreate();
bool recreate();
@ -31,7 +30,7 @@ class Swapchain
bool swap();
void present_wait();
void set_vsync(bool on);
void on_render_pass_end(std::function<void()> function);
void on_render_pass_end(const std::function<void()> &function);
int get_num_frames() { return num_swapchain_images; }
vk::PresentModeKHR get_present_mode();

View File

@ -83,10 +83,10 @@ value. */
/* Interface for user-defined custom blitters */
enum { snes_ntsc_in_chunk = 3 }; /* number of input pixels read per chunk */
enum { snes_ntsc_out_chunk = 7 }; /* number of output pixels generated per chunk */
enum { snes_ntsc_black = 0 }; /* palette index for black */
enum { snes_ntsc_burst_count = 3 }; /* burst phase cycles through 0, 1, and 2 */
const int snes_ntsc_in_chunk = 3; /* number of input pixels read per chunk */
const int snes_ntsc_out_chunk = 7; /* number of output pixels generated per chunk */
const int snes_ntsc_black = 0; /* palette index for black */
const int snes_ntsc_burst_count = 3; /* burst phase cycles through 0, 1, and 2 */
/* Begins outputting row and starts three pixels. First pixel will be cut off a bit.
Use snes_ntsc_black for unused pixels. Declares variables, so must be before first
@ -143,13 +143,13 @@ statement in a block (unless you're using C++). */
/* private */
enum { snes_ntsc_entry_size = 128 };
enum { snes_ntsc_palette_size = 0x2000 };
static const int snes_ntsc_entry_size = 128;
static const int snes_ntsc_palette_size = 0x2000;
typedef unsigned long snes_ntsc_rgb_t;
struct snes_ntsc_t {
snes_ntsc_rgb_t table [snes_ntsc_palette_size] [snes_ntsc_entry_size];
snes_ntsc_rgb_t table [0x2000][128];
};
enum { snes_ntsc_burst_size = snes_ntsc_entry_size / snes_ntsc_burst_count };
const int snes_ntsc_burst_size = snes_ntsc_entry_size / snes_ntsc_burst_count;
#define SNES_NTSC_RGB16( ktable, n ) \
(snes_ntsc_rgb_t const*) (ktable + ((n & 0x001E) | (n >> 1 & 0x03E0) | (n >> 2 & 0x3C00)) * \

View File

@ -44,9 +44,9 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
#define rgb_unit (1 << rgb_bits)
#define rgb_offset (rgb_unit * 2 + 0.5f)
enum { burst_size = snes_ntsc_entry_size / burst_count };
enum { kernel_half = 16 };
enum { kernel_size = kernel_half * 2 + 1 };
const int burst_size = snes_ntsc_entry_size / burst_count;
const int kernel_half = 16;
const int kernel_size = 31;
typedef struct init_t
{
@ -56,7 +56,7 @@ typedef struct init_t
float brightness;
float artifacts;
float fringing;
float kernel [rescale_out * kernel_size * 2];
float kernel [7 * 31 * 2];
} init_t;
#define ROTATE_IQ( i, q, sin_b, cos_b ) {\
@ -284,8 +284,8 @@ static void init( init_t* impl, snes_ntsc_setup_t const* setup )
#define PACK_RGB( r, g, b ) ((r) << 21 | (g) << 11 | (b) << 1)
enum { rgb_kernel_size = burst_size / alignment_count };
enum { rgb_bias = rgb_unit * 2 * snes_ntsc_rgb_builder };
const int rgb_kernel_size = burst_size / alignment_count;
const int rgb_bias = rgb_unit * 2 * snes_ntsc_rgb_builder;
typedef struct pixel_info_t
{

View File

@ -14,7 +14,7 @@ option(USE_SYSTEMZIP "Force use of system minizip" ON)
option(USE_WAYLAND "Build support for Wayland" ON)
option(DANGEROUS_HACKS "Allow dangerous hacks to be used" ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

View File

@ -1,7 +1,6 @@
#include "background_particles.h"
#include <cstring>
#include <cmath>
#include <cstdio>
#include <random>
static const double pi = 3.141592;
@ -15,10 +14,6 @@ Particles::Particles(enum Mode mode)
setmode(mode);
}
Particles::~Particles()
{
}
void Particles::setmode(enum Mode mode)
{
if (mode == this->mode)
@ -91,7 +86,7 @@ void Particles::advance_starfield()
std::uniform_real_distribution<double> realrand(0.0, 1.0);
if (realrand(mt) <= rate)
{
Particle pt;
Particle pt{};
double angle = realrand(mt) * 2 * pi;
pt.dx = cos(angle);
@ -159,7 +154,7 @@ void Particles::advance_snow()
for (double new_snowflakes = rate; new_snowflakes >= 1.0; new_snowflakes -= 1.0)
{
Particle pt;
Particle pt{};
realrand = std::uniform_real_distribution<double>(0.0, 1.0);
pt.x = ((wind + 0.8) / 1.6) * -192.0 + realrand(mt) * 384.0;

View File

@ -1,5 +1,4 @@
#ifndef __BACKGROUND_PARTICLES_H
#define __BACKGROUND_PARTICLES_H
#pragma once
#include <vector>
#include <list>
#include <cstdint>
@ -26,11 +25,9 @@ class Particles
unsigned int intensity;
};
Particles(enum Mode = Stars);
~Particles();
explicit Particles(enum Mode = Stars);
void advance();
void copyto(uint16_t *dst, int pitch);
enum Mode getmode();
void setmode(enum Mode);
void set_game_image(uint16_t *src, int pitch);
@ -51,4 +48,3 @@ class Particles
};
} // namespace Background
#endif // __BACKGROUND_PARTICLES_H

View File

@ -4,11 +4,7 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __FILTER_EPX_UNSAFE_H
#define __FILTER_EPX_UNSAFE_H
#pragma once
#include <cstdint>
void EPX_16_unsafe(uint8_t *, int, uint8_t *, int, int, int);
void EPX_16_smooth_unsafe(uint8_t *, int, uint8_t *, int, int, int);
#endif /* __FILTER_EPX_UNSAFE_H */
void EPX_16_smooth_unsafe(uint8_t *, int, uint8_t *, int, int, int);

View File

@ -84,18 +84,7 @@ Binding::Binding(unsigned int val)
value = val;
}
Binding::Binding(const Binding &binding)
{
this->value = binding.value;
}
Binding &Binding::operator=(const Binding &binding)
{
this->value = binding.value;
return *this;
}
bool Binding::operator==(const Binding &binding)
bool Binding::operator==(const Binding &binding) const
{
if ((value & ~BINDING_THRESHOLD_MASK) == (binding.value & ~BINDING_THRESHOLD_MASK))
return true;
@ -254,7 +243,7 @@ std::string Binding::to_string(bool translate)
if (c == '_')
c = ' ';
str = fmt::format(maybegettext("Keyboard {}{}{}{}"),
str = fmt::format(fmt::runtime(maybegettext("Keyboard {}{}{}{}")),
(value & BINDING_SHIFT) ? "Shift+" : "",
(value & BINDING_CTRL) ? "Ctrl+" : "",
(value & BINDING_ALT) ? "Alt+" : "",
@ -264,14 +253,14 @@ std::string Binding::to_string(bool translate)
else if (is_joy())
{
if ((get_key()) >= 512)
str = fmt::format(maybegettext("Axis {} {} {}%"),
str = fmt::format(fmt::runtime(maybegettext("Axis {} {} {}%")),
get_axis(),
is_positive() ? "+" : "-",
get_threshold());
else
str = fmt::format(maybegettext("Button {}"), get_key());
str = fmt::format(fmt::runtime(maybegettext("Button {}")), get_key());
str = fmt::format(maybegettext("Joystick {} {}"), get_device(), str);
str = fmt::format(fmt::runtime(maybegettext("Joystick {} {}")), get_device(), str);
}
else

View File

@ -4,9 +4,7 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __GTK_BINDING_H
#define __GTK_BINDING_H
#pragma once
#include "gtk_compat.h"
#include <string>
@ -32,14 +30,11 @@
#define BINDING_MOUSE_BUTTON1 0x42000001
#define BINDING_MOUSE_BUTTON2 0x42000002
class Binding
struct Binding
{
public:
Binding(unsigned int key, bool ctrl, bool shift, bool alt);
Binding(unsigned int device, unsigned int button, unsigned int threshold);
Binding(const Binding &binding);
Binding &operator=(const Binding &binding);
bool operator==(const Binding &binding);
bool operator==(const Binding &binding) const;
Binding(GdkEventKey *event);
Binding(unsigned int);
Binding();
@ -60,8 +55,5 @@ class Binding
unsigned int get_axis();
Gdk::ModifierType get_gdk_modifiers();
private:
unsigned int value;
};
#endif /* __GTK_BINDING_H_ */
};

View File

@ -4,7 +4,7 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#include <stdlib.h>
#include <cstdlib>
#include "gtk_builder_window.h"
extern const unsigned char snes9x_ui[];
@ -25,10 +25,6 @@ GtkBuilderWindow::GtkBuilderWindow(const char *root)
window = get_object<Gtk::Window>(root);
}
GtkBuilderWindow::~GtkBuilderWindow()
{
}
void GtkBuilderWindow::enable_widget(const char *name, bool state)
{
auto widget = get_object<Gtk::Widget>(name);
@ -144,11 +140,9 @@ void GtkBuilderWindow::combo_box_append(const char *name, const char *value)
void GtkBuilderWindow::combo_box_append(Gtk::ComboBox *combo, const char *value)
{
GtkListStore *store;
GtkListStore *store = GTK_LIST_STORE(combo->get_model()->gobj());
GtkTreeIter iter;
store = GTK_LIST_STORE(combo->get_model()->gobj());
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, 0, value, -1);
}

View File

@ -4,9 +4,7 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __GTK_BUILDER_WINDOW_H
#define __GTK_BUILDER_WINDOW_H
#pragma once
#include "gtk_compat.h"
extern Glib::RefPtr<Gtk::Builder> global_builder;
@ -14,8 +12,7 @@ extern Glib::RefPtr<Gtk::Builder> global_builder;
class GtkBuilderWindow
{
public:
GtkBuilderWindow(const char *root);
~GtkBuilderWindow();
explicit GtkBuilderWindow(const char *root);
template <typename T>
Glib::RefPtr<T> get_object(const char *name)
@ -37,7 +34,7 @@ class GtkBuilderWindow
void enable_widget(const char *name, bool state);
void show_widget(const char *name, bool state);
void set_label(const char * const name, const char * const label);
void set_label(const char *name, const char *label);
void set_button_label(const char *name, const char *label);
bool get_check(const char *name);
int get_entry_value(const char *name);
@ -57,6 +54,4 @@ class GtkBuilderWindow
bool has_focus(const char *widget);
Glib::RefPtr<Gtk::Window> window;
};
#endif /* __GTK_BUILDER_WINDOW_H */
};

View File

@ -15,8 +15,6 @@ enum {
NUM_COLS
};
extern SCheatData Cheat;
static void display_errorbox(const char *error)
{
auto dialog = Gtk::MessageDialog(error, false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
@ -97,10 +95,6 @@ Snes9xCheats::Snes9xCheats()
gtk_widget_realize(GTK_WIDGET(window->gobj()));
}
Snes9xCheats::~Snes9xCheats()
{
}
void Snes9xCheats::enable_dnd(bool enable)
{
if (enable)
@ -197,7 +191,7 @@ void Snes9xCheats::refresh_tree_view()
auto list_size = store->children().size();
if (Cheat.group.size() == 0)
if (Cheat.group.empty())
return;
for (unsigned int i = 0; i < Cheat.group.size() - list_size; i++)

View File

@ -4,9 +4,7 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __GTK_CHEAT_H
#define __GTK_CHEAT_H
#pragma once
#include "gtk_builder_window.h"
void open_snes9x_cheats_dialog();
@ -21,7 +19,6 @@ class Snes9xCheats : public GtkBuilderWindow
{
public:
Snes9xCheats();
~Snes9xCheats();
void show();
void add_code();
void remove_code();
@ -46,6 +43,4 @@ class Snes9xCheats : public GtkBuilderWindow
sigc::connection delete_id;
int dst_row;
Glib::RefPtr<Gtk::ListStore> store;
};
#endif /* __GTK_CHEAT_H */
};

View File

@ -4,9 +4,7 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __GTK_COMPAT_H
#define __GTK_COMPAT_H
#pragma once
#include <gtkmm.h>
#include <gtk/gtk.h>
@ -33,5 +31,3 @@ inline bool is_x11()
return GDK_IS_X11_DISPLAY(gdk_display_get_default());
}
#endif
#endif

View File

@ -4,7 +4,7 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#include <stdlib.h>
#include <cstdlib>
#include <sys/stat.h>
#include <filesystem>
@ -182,6 +182,7 @@ int Snes9xConfig::load_defaults()
Settings.NetPlay = false;
NetPlay.Paused = false;
NetPlay.MaxFrameSkip = 10;
Settings.TurboSkipFrames = 15;
Settings.DisplayPressedKeys = false;
#ifdef ALLOW_CPU_OVERCLOCK
Settings.MaxSpriteTilesPerLine = 34;
@ -205,15 +206,15 @@ int Snes9xConfig::save_config_file()
ConfigFile cf;
std::string section;
auto outbool = [&](std::string name, bool b, std::string comment = "") {
auto outbool = [&](const std::string &name, bool b, const std::string &comment = "") {
cf.SetBool((section + "::" + name).c_str(), b, "true", "false", comment.c_str());
};
auto outstring = [&](std::string name, std::string str, std::string comment = "") {
auto outstring = [&](const std::string &name, const std::string &str, const std::string &comment = "") {
cf.SetString((section + "::" + name).c_str(), str, comment.c_str());
};
auto outint = [&](std::string name, int i, std::string comment = "") {
auto outint = [&](const std::string &name, int i, const std::string &comment = "") {
cf.SetInt((section + "::" + name).c_str(), i, comment.c_str());
};
@ -288,7 +289,7 @@ int Snes9xConfig::save_config_file()
outbool("UIVisible", ui_visible);
outbool("EnableIcons", enable_icons);
if (default_esc_behavior != ESC_TOGGLE_MENUBAR)
outbool("Fullscreen", 0);
outbool("Fullscreen", false);
else
outbool("Fullscreen", fullscreen);
@ -325,8 +326,8 @@ int Snes9xConfig::save_config_file()
section = "Hacks";
outint("SuperFXClockMultiplier", Settings.SuperFXClockMultiplier);
outint("SoundInterpolationMethod", Settings.InterpolationMethod, "0: None, 1: Linear, 2: Gaussian (what the hardware uses), 3: Cubic, 4: Sinc");
outbool("RemoveSpriteLimit", Settings.MaxSpriteTilesPerLine == 34 ? 0 : 1);
outbool("OverclockCPU", Settings.OneClockCycle == 6 ? 0 : 1);
outbool("RemoveSpriteLimit", Settings.MaxSpriteTilesPerLine != 34);
outbool("OverclockCPU", Settings.OneClockCycle != 6);
outbool("EchoBufferHack", Settings.SeparateEchoBuffer, "Prevents echo buffer from overwriting APU RAM");
section = "Input";
@ -384,8 +385,8 @@ int Snes9xConfig::save_config_file()
outstring(b_links[i].snes9x_name, shortcut[i - NUM_JOYPAD_LINKS].as_string());
}
cf.SetNiceAlignment(true);
cf.SetShowComments(true);
ConfigFile::SetNiceAlignment(true);
ConfigFile::SetShowComments(true);
cf.SaveTo(get_config_file_name().c_str());
return 0;
@ -401,7 +402,7 @@ int Snes9xConfig::load_config_file()
{
if (!fs::create_directory(path))
{
fmt::print(stderr, _("Couldn't create config directory: {}\n"), path.string());
fmt::print(stderr, fmt::runtime(_("Couldn't create config directory: {}\n")), path.string());
return -1;
}
}
@ -424,22 +425,22 @@ int Snes9xConfig::load_config_file()
std::string none;
std::string section;
auto inbool = [&](std::string name, auto &b) {
auto inbool = [&](const std::string &name, auto &b) {
if (cf.Exists((section + "::" + name).c_str()))
b = cf.GetBool((section + "::" + name).c_str());
};
auto inint = [&](std::string name, auto &i) {
auto inint = [&](const std::string &name, auto &i) {
if (cf.Exists((section + "::" + name).c_str()))
i = cf.GetInt((section + "::" + name).c_str());
};
auto indouble = [&](std::string name, double &d) {
auto indouble = [&](const std::string &name, double &d) {
if (cf.Exists((section + "::" + name).c_str()))
d = atof(cf.GetString((section + "::" + name).c_str()));
};
auto instr = [&](std::string name, std::string &str) {
auto instr = [&](const std::string &name, std::string &str) {
str = cf.GetString((section + "::" + name).c_str(), none);
};

View File

@ -4,13 +4,10 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __GTK_CONFIG_H
#define __GTK_CONFIG_H
#pragma once
#include "gtk_control.h"
#include "filter/snes_ntsc.h"
#include <X11/Xlib.h>
#include <X11/extensions/Xrandr.h>
#include <string>
#include <array>
@ -162,6 +159,4 @@ class Snes9xConfig
};
std::string get_config_dir();
std::string get_config_file_name();
#endif /* __GTK_CONFIG_H */
std::string get_config_file_name();

View File

@ -110,7 +110,7 @@ const BindingLink b_links[] =
{ "b_rewind", "GTK_rewind" },
{ "b_grab_mouse", "GTK_grab_mouse" },
{ NULL, NULL }
{ nullptr, nullptr }
};
/* Where the page breaks occur in the preferences pane */
@ -198,9 +198,7 @@ void S9xReleaseJoysticks()
static void swap_controllers_1_2()
{
JoypadBinding interrim;
interrim = gui_config->pad[0];
JoypadBinding interrim = gui_config->pad[0];
gui_config->pad[0] = gui_config->pad[1];
gui_config->pad[1] = interrim;
@ -219,7 +217,7 @@ static void change_slot(int difference)
char extension_string[5];
snprintf(extension_string, 5, ".%03d", gui_config->current_save_slot);
auto filename = S9xGetFilename(extension_string, SNAPSHOT_DIR);
struct stat info;
struct stat info{};
std::string exists = "empty";
if (stat(filename.c_str(), &info) == 0)
exists = "used";
@ -330,7 +328,7 @@ Binding S9xGetBindingByName(const char *name)
}
}
return Binding();
return {};
}
s9xcommand_t S9xGetPortCommandT(const char *name)
@ -456,18 +454,16 @@ s9xcommand_t S9xGetPortCommandT(const char *name)
void S9xProcessEvents(bool8 block)
{
JoyEvent event;
Binding binding;
if (S9xGrabJoysticks())
{
gui_config->joysticks.poll_events();
for (auto &j : gui_config->joysticks)
{
JoyEvent event;
while (j.second->get_event(&event))
{
binding = Binding(j.second->joynum, event.parameter, 0);
S9xReportButton(binding.hex(), event.state == JOY_PRESSED ? 1 : 0);
Binding binding(j.second->joynum, event.parameter, 0);
S9xReportButton(binding.hex(), event.state == JOY_PRESSED);
gui_config->screensaver_needs_reset = true;
}
}
@ -501,7 +497,7 @@ void S9xDeinitInputDevices()
JoyDevice::JoyDevice()
{
enabled = false;
filedes = NULL;
filedes = nullptr;
mode = JOY_MODE_INDIVIDUAL;
}
@ -773,7 +769,7 @@ void JoyDevices::clear()
bool JoyDevices::add(int sdl_device_index)
{
std::array<bool, NUM_JOYPADS> joynums;
std::array<bool, NUM_JOYPADS> joynums{};
joynums.fill(false);
for (auto &j : joysticks)
{
@ -781,8 +777,8 @@ bool JoyDevices::add(int sdl_device_index)
}
// New joystick always gets the lowest available joynum
int joynum(0);
for (; joynum < NUM_JOYPADS && joynums[joynum]; ++joynum);
int joynum = 0;
for (; joynum < NUM_JOYPADS && joynums[joynum]; ++joynum) {};
if (joynum == NUM_JOYPADS)
{
@ -799,7 +795,7 @@ bool JoyDevices::add(int sdl_device_index)
bool JoyDevices::remove(SDL_JoystickID instance_id)
{
if (!joysticks.count(instance_id))
if (!joysticks.contains(instance_id))
{
printf("joystick_remove: invalid instance id %d", instance_id);
return false;
@ -811,11 +807,11 @@ bool JoyDevices::remove(SDL_JoystickID instance_id)
JoyDevice *JoyDevices::get_joystick(SDL_JoystickID instance_id)
{
if (joysticks.count(instance_id)){
if (joysticks.contains(instance_id)){
return joysticks[instance_id].get();
}
printf("BUG: Event for unknown joystick instance id: %d", instance_id);
return NULL;
return nullptr;
}
void JoyDevices::register_centers()

View File

@ -4,9 +4,7 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __GTK_CONTROL_H
#define __GTK_CONTROL_H
#pragma once
#include <queue>
#include <array>
@ -101,7 +99,6 @@ class JoyDevice
void handle_event(SDL_Event *event);
void register_centers();
bool set_sdl_joystick(unsigned int device_index, int slot);
static void poll_joystick_events();
std::string description;
SDL_Joystick *filedes;
@ -139,6 +136,4 @@ class JoyDevices
void S9xDeinitInputDevices();
Binding S9xGetBindingByName(const char *name);
bool S9xIsMousePluggedIn();
#endif /* __GTK_CONTROL_H*/
bool S9xIsMousePluggedIn();

View File

@ -27,6 +27,16 @@
#include "snes9x_imgui.h"
#include "filter/2xsai.h"
#ifdef USE_HQ2X
#include "filter/hq2x.h"
#endif
#ifdef USE_XBRZ
#include "filter_xbrz.h"
#endif
#include "filter_epx_unsafe.h"
#include "filter/snes_ntsc.h"
void filter_scanlines(uint8 *, int, uint8 *, int, int, int);
void filter_2x(uint8 *, int, uint8 *, int, int, int);
void filter_3x(uint8 *, int, uint8 *, int, int, int);
@ -210,20 +220,16 @@ static void internal_convert_16_yuv(void *src_buffer,
int height,
int bpp)
{
int x, y;
uint16 *src;
uint8 *dst;
uint16 p0, p1;
for (y = 0; y < height; y++)
for (int y = 0; y < height; y++)
{
src = (uint16 *)(((uint8 *)src_buffer) + src_pitch * y);
dst = (uint8 *)(((uint8 *)dst_buffer) + dst_pitch * y);
auto src = (uint16_t *)(((uint8_t *)src_buffer) + src_pitch * y);
auto dst = (uint8_t *)dst_buffer + dst_pitch * y;
for (x = 0; x < width / 2; x++)
for (int x = 0; x < width / 2; x++)
{
p0 = *src++;
p1 = *src++;
uint16_t p0 = *src++;
uint16_t p1 = *src++;
*dst++ = y_table[p0];
*dst++ = (u_table[p0] + u_table[p1]) >> 1;
@ -480,7 +486,6 @@ void apply_filter_scale(int &width, int &height)
const auto &filter = filter_data[gui_config->scale_method];
width *= filter.xscale;
height *= filter.yscale;
return;
}
static void internal_filter(uint8 *src_buffer,
@ -547,22 +552,24 @@ static void internal_threaded_convert(void *src_buffer,
create_thread_pool();
auto func = (bpp == -1) ? internal_convert_16_yuv : internal_convert;
int coverage = 0;
int lines_handled = 0;
for (int i = 0; i < gui_config->num_threads; i++)
{
int job_height = (height / gui_config->num_threads) & 3;
job_height = height - coverage;
if (i == gui_config->num_threads - 1)
job_height = height - lines_handled;
pool->queue([=] {
func((uint8 *)src_buffer + (src_pitch * coverage),
(uint8 *)dst_buffer + (dst_pitch * coverage),
func((uint8 *)src_buffer + (src_pitch * lines_handled),
(uint8 *)dst_buffer + (dst_pitch * lines_handled),
src_pitch,
dst_pitch,
width,
job_height,
bpp);
});
lines_handled += job_height;
}
pool->wait_idle();
@ -582,10 +589,10 @@ static void internal_threaded_convert_mask(void *src_buffer,
create_thread_pool();
int lines_handled = 0;
int job_height = height / gui_config->num_threads;
for (int i = 0; i < gui_config->num_threads; i++)
{
int job_height = height / gui_config->num_threads & 3;
if (i == gui_config->num_threads - 1)
job_height = height - lines_handled;
pool->queue([=] {
@ -600,6 +607,7 @@ static void internal_threaded_convert_mask(void *src_buffer,
inv_bmask,
bpp);
});
lines_handled += job_height;
}
pool->wait_idle();
@ -620,23 +628,23 @@ static void internal_threaded_filter(uint8 *src_buffer,
create_thread_pool();
int yscale = filter_data[gui_config->scale_method].yscale;
int coverage = 0;
int lines_handled = 0;
for (int i = 0; i < gui_config->num_threads; i++)
{
int job_height = height / gui_config->num_threads & ~3;
if (i == gui_config->num_threads - 1)
job_height = height - coverage;
job_height = height - lines_handled;
pool->queue([=] {
internal_filter(src_buffer + (src_pitch * coverage),
internal_filter(src_buffer + (src_pitch * lines_handled),
src_pitch,
dst_buffer + (dst_pitch * coverage * yscale),
dst_buffer + (dst_pitch * lines_handled * yscale),
dst_pitch,
width,
job_height);
});
coverage += job_height;
lines_handled += job_height;
}
pool->wait_idle();
@ -947,7 +955,7 @@ static void S9xInitDriver()
dialog.run();
}
pool = NULL;
pool = nullptr;
}
S9xDisplayDriver *S9xDisplayGetDriver()
@ -971,14 +979,12 @@ void S9xDeinitDisplay()
void S9xReinitDisplay()
{
uint16_t *buffer = NULL;
int width, height;
uint16_t buffer[512 * 512];
buffer = new uint16_t[512 * 512];
memmove(buffer, GFX.Screen, 512 * 478 * 2);
width = top_level->last_width;
height = top_level->last_height;
int width = top_level->last_width;
int height = top_level->last_height;
S9xDeinitDisplay();
S9xInitDriver();
@ -988,8 +994,6 @@ void S9xReinitDisplay()
top_level->last_height = height;
memmove(GFX.Screen, buffer, 512 * 478 * 2);
delete[] buffer;
}
bool8 S9xContinueUpdate(int width, int height)
@ -1016,7 +1020,7 @@ void S9xInitDisplay(int argc, char **argv)
S9xBlit2xSaIFilterInit();
#ifdef USE_HQ2X
S9xBlitHQ2xFilterInit();
#endif /* USE_HQ2SX */
#endif /* USE_HQ2X */
S9xQueryDrivers();
S9xInitDriver();
S9xGraphicsInit();

View File

@ -4,21 +4,9 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __GTK_DISPLAY_H
#define __GTK_DISPLAY_H
#pragma once
#include "gtk_s9x.h"
#include "gtk_display_driver.h"
#include "filter/2xsai.h"
#ifdef USE_HQ2X
#include "filter/hq2x.h"
#endif
#ifdef USE_XBRZ
#include "filter_xbrz.h"
#endif
#include "filter/epx.h"
#include "filter_epx_unsafe.h"
#include "filter/snes_ntsc.h"
enum {
FILTER_NONE = 0,
@ -93,6 +81,4 @@ void S9xReinitDisplay();
void S9xDisplayReconfigure();
void S9xQueryDrivers();
S9xDisplayDriver *S9xDisplayGetDriver();
bool S9xDisplayDriverIsReady();
#endif /* __GTK_DISPLAY_H */
bool S9xDisplayDriverIsReady();

View File

@ -4,23 +4,19 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __GTK_DISPLAY_DRIVER_H
#define __GTK_DISPLAY_DRIVER_H
#pragma once
#include "gtk_s9x.h"
class S9xDisplayDriver
{
public:
virtual ~S9xDisplayDriver()
{
}
virtual ~S9xDisplayDriver() = default;
virtual void refresh() = 0;
virtual int init() = 0;
virtual void deinit() = 0;
virtual void update(uint16_t *buffer, int width, int height, int stride_in_pixels) = 0;
virtual void *get_parameters() = 0;
virtual void save(const char *filename) = 0;
virtual void save(const std::string &filename) = 0;
virtual bool is_ready() = 0;
virtual bool can_throttle() { return false; };
virtual int get_width() = 0;
@ -29,9 +25,7 @@ class S9xDisplayDriver
virtual void regrow() {};
protected:
Snes9xWindow *window;
Snes9xConfig *config;
Gtk::DrawingArea *drawing_area;
};
#endif /* __GTK_DISPLAY_DRIVER_H*/
Snes9xWindow *window = nullptr;
Snes9xConfig *config = nullptr;
Gtk::DrawingArea *drawing_area = nullptr;
};

View File

@ -43,9 +43,8 @@ void S9xGTKDisplayDriver::output(void *src,
}
cairo_t *cr = window->get_cairo();
cairo_surface_t *surface;
surface = cairo_image_surface_create_for_data((unsigned char *)src, CAIRO_FORMAT_RGB16_565, width, height, src_pitch);
cairo_surface_t *surface = cairo_image_surface_create_for_data((unsigned char *)src, CAIRO_FORMAT_RGB16_565, width, height, src_pitch);
cairo_set_source_surface(cr, surface, 0, 0);
@ -103,7 +102,7 @@ void S9xGTKDisplayDriver::clear()
return;
}
S9xRect dst;
S9xRect dst{};
dst.w = window->last_width;
dst.h = window->last_height;
apply_filter_scale(dst.w, dst.h);

View File

@ -4,32 +4,22 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __GTK_DISPLAY_DRIVER_GTK_H
#define __GTK_DISPLAY_DRIVER_GTK_H
#pragma once
#include "gtk_display_driver.h"
class S9xGTKDisplayDriver : public S9xDisplayDriver
{
public:
S9xGTKDisplayDriver(Snes9xWindow *window, Snes9xConfig *config);
void refresh();
int init();
void deinit();
void update(uint16_t *buffer, int width, int height, int stride_in_pixels);
void *get_parameters()
{
return NULL;
}
void save(const char *filename)
{
}
bool is_ready()
{
return true;
}
int get_width() { return last_known_width; }
int get_height() { return last_known_height; }
void refresh() override;
int init() override;
void deinit() override;
void update(uint16_t *buffer, int width, int height, int stride_in_pixels) override;
void *get_parameters() override { return nullptr; }
void save(const std::string &filename) override {}
bool is_ready() override { return true; }
int get_width() override { return last_known_width; }
int get_height() override { return last_known_height; }
private:
void clear();
@ -44,6 +34,4 @@ class S9xGTKDisplayDriver : public S9xDisplayDriver
int last_known_width;
int last_known_height;
};
#endif /* __GTK_DISPLAY_DRIVER_GTK_H */
};

View File

@ -162,11 +162,11 @@ void *S9xOpenGLDisplayDriver::get_parameters()
return NULL;
}
void S9xOpenGLDisplayDriver::save(const char *filename)
void S9xOpenGLDisplayDriver::save(const std::string &filename)
{
if (using_glsl_shaders && glsl_shader)
{
glsl_shader->save(filename);
glsl_shader->save(filename.c_str());
}
}

View File

@ -4,9 +4,7 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __GTK_DISPLAY_DRIVER_OPENGL_H
#define __GTK_DISPLAY_DRIVER_OPENGL_H
#pragma once
#include "gtk_s9x.h"
#include "gtk_display_driver.h"
@ -36,12 +34,12 @@ class S9xOpenGLDisplayDriver : public S9xDisplayDriver
void deinit() override;
void update(uint16_t *buffer, int width, int height, int stride_in_pixels) override;
void *get_parameters() override;
void save(const char *filename) override;
void save(const std::string &filename) override;
static int query_availability();
bool is_ready() override;
bool can_throttle() override { return true; }
int get_width() final override { return output_window_width; }
int get_height() final override { return output_window_height; }
int get_width() override { return output_window_width; }
int get_height() override { return output_window_height; }
void shrink() override;
void regrow() override;
@ -81,6 +79,4 @@ class S9xOpenGLDisplayDriver : public S9xDisplayDriver
#ifdef GDK_WINDOWING_WAYLAND
WaylandEGLContext wl;
#endif
};
#endif /* __GTK_DISPLAY_DRIVER_OPENGL_H */
};

View File

@ -33,10 +33,6 @@ S9xVulkanDisplayDriver::S9xVulkanDisplayDriver(Snes9xWindow *_window, Snes9xConf
context.reset();
}
S9xVulkanDisplayDriver::~S9xVulkanDisplayDriver()
{
}
bool S9xVulkanDisplayDriver::init_imgui()
{
auto defaults = S9xImGuiGetDefaults();
@ -257,7 +253,7 @@ void *S9xVulkanDisplayDriver::get_parameters()
return nullptr;
}
void S9xVulkanDisplayDriver::save(const char *filename)
void S9xVulkanDisplayDriver::save(const std::string &filename)
{
setlocale(LC_NUMERIC, "C");
if (shaderchain)

View File

@ -20,17 +20,16 @@ class S9xVulkanDisplayDriver : public S9xDisplayDriver
{
public:
S9xVulkanDisplayDriver(Snes9xWindow *window, Snes9xConfig *config);
~S9xVulkanDisplayDriver();
void refresh() override;
int init() override;
void deinit() override;
void update(uint16_t *buffer, int width, int height, int stride_in_pixels) override;
void *get_parameters() override;
void save(const char *filename) override;
void save(const std::string &filename) override;
bool is_ready() override;
bool can_throttle() override { return true; }
int get_width() final override { return current_width; }
int get_height() final override { return current_height; }
int get_width() override { return current_width; }
int get_height() override { return current_height; }
void shrink() override;
void regrow() override;

View File

@ -4,9 +4,7 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __GTK_DISPLAY_DRIVER_XV_H
#define __GTK_DISPLAY_DRIVER_XV_H
#pragma once
#include "gtk_s9x.h"
#include "gtk_display_driver.h"
@ -21,16 +19,16 @@ class S9xXVDisplayDriver : public S9xDisplayDriver
{
public:
S9xXVDisplayDriver(Snes9xWindow *window, Snes9xConfig *config);
void refresh();
int init();
void deinit();
void update(uint16_t *buffer, int width, int height, int stride_in_pixels);
void *get_parameters() { return nullptr; }
void save(const char *filename) {}
void refresh() override;
int init() override;
void deinit() override;
void update(uint16_t *buffer, int width, int height, int stride_in_pixels) override;
void *get_parameters() override { return nullptr; }
void save(const std::string &filename) override {}
static int query_availability();
bool is_ready() { return true; }
int get_width() { return output_window_width; }
int get_height() { return output_window_height; }
bool is_ready() override { return true; }
int get_width() override { return output_window_width; }
int get_height() override { return output_window_height; }
private:
void clear();
@ -62,6 +60,4 @@ class S9xXVDisplayDriver : public S9xDisplayDriver
uint8 y_table[65536];
uint8 u_table[65536];
uint8 v_table[65536];
};
#endif /* __GTK_DISPLAY_DRIVER_XV_H */
};

View File

@ -4,14 +4,10 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __GTK_NETPLAY_H
#define __GTK_NETPLAY_H
#pragma once
void S9xNetplayDialogOpen();
int S9xNetplayPush();
void S9xNetplayPop();
int S9xNetplaySyncSpeed();
void S9xNetplaySyncClients();
void S9xNetplayDisconnect();
#endif /* __GTK_NETPLAY_H */
void S9xNetplayDisconnect();

View File

@ -4,9 +4,7 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __GTK_NETPLAY_DIALOG_H
#define __GTK_NETPLAY_DIALOG_H
#pragma once
#include "gtk_builder_window.h"
#include "gtk_config.h"
@ -22,6 +20,4 @@ class Snes9xNetplayDialog : public GtkBuilderWindow
Snes9xConfig *config;
void settings_to_dialog();
void settings_from_dialog();
};
#endif /* __GTK_NETPLAY_DIALOG_H */
};

View File

@ -42,9 +42,8 @@ void snes9x_preferences_open(Snes9xWindow *window)
gboolean poll_joystick(gpointer data)
{
Snes9xPreferences *window = (Snes9xPreferences *)data;
auto window = (Snes9xPreferences *)data;
JoyEvent event;
Binding binding;
int focus;
window->config->joysticks.poll_events();
@ -56,9 +55,9 @@ gboolean poll_joystick(gpointer data)
{
if ((focus = window->get_focused_binding()) >= 0)
{
binding = Binding(j.second->joynum,
event.parameter,
window->config->joystick_threshold);
Binding binding(j.second->joynum,
event.parameter,
window->config->joystick_threshold);
window->store_binding(b_links[focus].button_name,
binding);
@ -106,7 +105,7 @@ Snes9xPreferences::Snes9xPreferences(Snes9xConfig *config)
if (m->modeFlags & RR_DoubleClock)
dotClock *= 2;
auto str = fmt::format(_("{0:Ld}×{1:Ld} @ {2:.3Lf} Hz"),
auto str = fmt::format("{0:Ld}×{1:Ld} @ {2:.3Lf} Hz",
m->width,
m->height,
(double)dotClock / m->hTotal / m->vTotal);
@ -156,10 +155,6 @@ Snes9xPreferences::Snes9xPreferences(Snes9xConfig *config)
}
}
Snes9xPreferences::~Snes9xPreferences ()
{
}
void Snes9xPreferences::connect_signals()
{
window->signal_key_press_event().connect(sigc::mem_fun(*this, &Snes9xPreferences::key_pressed), false);
@ -291,7 +286,7 @@ void Snes9xPreferences::about_dialog()
about_dialog.window->hide();
}
void Snes9xPreferences::game_data_browse(std::string folder)
void Snes9xPreferences::game_data_browse(const std::string &folder)
{
auto entry = get_object<Gtk::Entry>((folder + "_directory").c_str());
auto dialog = Gtk::FileChooserDialog(*window.get(), _("Select directory"), Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
@ -319,12 +314,12 @@ void Snes9xPreferences::input_rate_changed()
32040.0 * NTSC_PROGRESSIVE_FRAME_RATE;
set_label(
"relative_video_rate",
fmt::format(_("{0:.4Lf} Hz"), value).c_str());
fmt::format("{0:.4Lf} Hz", value).c_str());
}
Glib::ustring Snes9xPreferences::format_sound_input_rate_value(double value)
{
return fmt::format(_("{0:Ld} Hz"), (uint32_t)std::round(value));
return fmt::format("{0:Ld} Hz", (uint32_t)std::round(value));
}
bool Snes9xPreferences::key_pressed(GdkEventKey *event)
@ -350,7 +345,7 @@ bool Snes9xPreferences::key_pressed(GdkEventKey *event)
}
}
Binding key_binding = Binding(event);
Binding key_binding(event);
// Allows ESC key to clear the key binding
if (event->keyval == GDK_Escape)
@ -487,7 +482,7 @@ void Snes9xPreferences::move_settings_to_dialog()
set_slider("sound_input_rate", config->sound_input_rate);
if (top_level->get_auto_input_rate() == 0)
{
config->auto_input_rate = 0;
config->auto_input_rate = false;
enable_widget("auto_input_rate", false);
}
set_check ("auto_input_rate", config->auto_input_rate);
@ -708,11 +703,11 @@ void Snes9xPreferences::get_settings_from_dialog()
&config->cheat_directory,
&config->export_directory })
{
if (!i->compare(SAME_AS_GAME))
if (*i == SAME_AS_GAME)
i->clear();
}
if (new_sram_directory.compare(config->sram_directory) && config->rom_loaded)
if (new_sram_directory != config->sram_directory && config->rom_loaded)
{
auto msg = Gtk::MessageDialog(
*window.get(),
@ -767,7 +762,7 @@ void Snes9xPreferences::get_settings_from_dialog()
top_level->leave_fullscreen_mode();
}
int Snes9xPreferences::combo_value(std::string driver_name)
int Snes9xPreferences::combo_value(const std::string &driver_name)
{
for (size_t i = 0; i < config->display_drivers.size(); i++)
{
@ -780,13 +775,10 @@ int Snes9xPreferences::combo_value(std::string driver_name)
void Snes9xPreferences::show()
{
bool close_dialog;
guint source_id = -1;
move_settings_to_dialog();
S9xGrabJoysticks();
source_id = g_timeout_add(100, poll_joystick, (gpointer)this);
guint source_id = g_timeout_add(100, poll_joystick, (gpointer)this);
if (config->preferences_width > 0 && config->preferences_height > 0)
resize (config->preferences_width, config->preferences_height);
@ -795,7 +787,7 @@ void Snes9xPreferences::show()
auto dialog = Glib::RefPtr<Gtk::Dialog>::cast_static(window);
for (close_dialog = false; !close_dialog; )
for (bool close_dialog = false; !close_dialog; )
{
dialog->show();
auto result = dialog->run();
@ -852,11 +844,10 @@ void Snes9xPreferences::focus_next()
void Snes9xPreferences::swap_with()
{
JoypadBinding tmp;
int source_joypad = get_combo("control_combo");
int dest_joypad = get_combo("joypad_to_swap_with");
tmp = pad[source_joypad];
JoypadBinding tmp = pad[source_joypad];
pad[source_joypad] = pad[dest_joypad];
pad[dest_joypad] = tmp;

View File

@ -4,9 +4,7 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __GTK_PREFERENCES_H
#define __GTK_PREFERENCES_H
#pragma once
#include "gtk_compat.h"
#include "gtk_s9x.h"
#include "gtk_builder_window.h"
@ -17,14 +15,12 @@ void snes9x_preferences_open(Snes9xWindow *window);
class Snes9xPreferences final : public GtkBuilderWindow
{
public:
Snes9xPreferences(Snes9xConfig *config);
~Snes9xPreferences();
explicit Snes9xPreferences(Snes9xConfig *config);
void show();
void bindings_to_dialog(int joypad);
int get_focused_binding();
void store_binding(const char *string, Binding binding);
int hw_accel_value(int combo_value);
int combo_value(std::string driver_name);
int combo_value(const std::string &driver_name);
void focus_next();
void swap_with();
void clear_binding(const char *name);
@ -35,9 +31,8 @@ class Snes9xPreferences final : public GtkBuilderWindow
void connect_signals();
void input_rate_changed();
bool key_pressed(GdkEventKey *event);
void scale_method_changed();
void shader_select();
void game_data_browse(std::string folder);
void game_data_browse(const std::string &folder);
void about_dialog();
Snes9xConfig *config;
@ -50,6 +45,4 @@ class Snes9xPreferences final : public GtkBuilderWindow
void get_settings_from_dialog();
void move_settings_to_dialog();
Glib::ustring format_sound_input_rate_value(double);
};
#endif /* __GTK_PREFERENCES_H */
};

View File

@ -4,7 +4,7 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#include <signal.h>
#include <csignal>
#define G_LOG_USE_STRUCTURED
#define G_LOG_DOMAIN GETTEXT_PACKAGE
#include "gtk_compat.h"
@ -42,11 +42,6 @@ gint64 pointer_timestamp = -1;
Background::Particles particles(Background::Particles::Snow);
static void S9xTerm(int signal)
{
S9xExit();
}
int main(int argc, char *argv[])
{
auto app = Gtk::Application::create("com.snes9x.gtk", Gio::APPLICATION_NON_UNIQUE);
@ -56,17 +51,18 @@ int main(int argc, char *argv[])
bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
textdomain(GETTEXT_PACKAGE);
auto signal_handler = [](int signal) {
printf("Received signal %d\n", signal);
S9xExit();
};
struct sigaction sig_callback{};
sig_callback.sa_handler = S9xTerm;
sigaction(15, &sig_callback, NULL); // SIGTERM
sigaction(3, &sig_callback, NULL); // SIGQUIT
sigaction(2, &sig_callback, NULL); // SIGINT
sig_callback.sa_handler = signal_handler;
sigaction(15, &sig_callback, nullptr); // SIGTERM
sigaction(3, &sig_callback, nullptr); // SIGQUIT
sigaction(2, &sig_callback, nullptr); // SIGINT
Settings = {};
// Original config fills out values this port doesn't.
S9xLoadConfigFiles(argv, argc);
gui_config = new Snes9xConfig();
gui_config->sound_drivers = S9xGetSoundDriverNames();
@ -150,6 +146,7 @@ int main(int argc, char *argv[])
gui_config->joysticks.flush_events();
Glib::signal_timeout().connect_once([]() { top_level->refresh(); }, 10);
Glib::signal_timeout().connect(sigc::ptr_fun(S9xPauseFunc), 100);
Glib::signal_timeout().connect(sigc::ptr_fun(S9xScreenSaverCheckFunc), 10000);
app->run(*top_level->window.get());
@ -158,9 +155,6 @@ int main(int argc, char *argv[])
int S9xOpenROM(const char *rom_filename)
{
uint32 flags;
bool loaded;
if (gui_config->rom_loaded)
{
S9xAutoSaveSRAM();
@ -168,10 +162,9 @@ int S9xOpenROM(const char *rom_filename)
S9xNetplayDisconnect();
flags = CPU.Flags;
loaded = false;
uint32 flags = CPU.Flags;
bool loaded = false;
if (Settings.Multi)
loaded = Memory.LoadMultiCart(Settings.CartAName, Settings.CartBName);
else if (rom_filename)
@ -201,7 +194,7 @@ int S9xOpenROM(const char *rom_filename)
S9xMessage(
S9X_INFO,
S9X_NO_INFO,
fmt::format(_("Using rewind buffer of {0}\n"),
fmt::format(fmt::runtime(_("Using rewind buffer of {0}\n")),
Glib::format_size(
gui_config->rewind_buffer_size * 1024 * 1024,
Glib::FORMAT_SIZE_IEC_UNITS).c_str()).c_str());
@ -236,14 +229,6 @@ void S9xNoROMLoaded()
static bool S9xPauseFunc()
{
static bool first_clear = false;
if (!first_clear)
{
top_level->refresh();
first_clear = true;
}
S9xProcessEvents(true);
if (!S9xNetplayPush())
@ -265,7 +250,6 @@ static bool S9xPauseFunc()
/* Resume high-performance callback */
Glib::signal_idle().connect(sigc::ptr_fun(S9xIdleFunc));
return false;
}
@ -285,9 +269,7 @@ static bool S9xPauseFunc()
}
}
Glib::signal_timeout().connect(sigc::ptr_fun(S9xPauseFunc), 8);
return false;
return true;
}
static bool S9xIdleFunc()
@ -457,12 +439,10 @@ void S9xParseArg(char **argv, int &i, int argc)
static void S9xThrottle(int method)
{
gint64 now;
if (S9xNetplaySyncSpeed())
return;
now = g_get_monotonic_time();
gint64 now = g_get_monotonic_time();
if (Settings.HighSpeedSeek > 0)
{
@ -589,7 +569,7 @@ void S9xExit()
const char *S9xStringInput(const char *message)
{
return NULL;
return nullptr;
}
void S9xExtraUsage()

View File

@ -4,9 +4,7 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __GTK_S9X_H
#define __GTK_S9X_H
#pragma once
#include "gtk_config.h"
#include "gtk_s9xwindow.h"
@ -21,5 +19,3 @@ extern Snes9xConfig *gui_config;
int S9xOpenROM(const char *filename);
void S9xNoROMLoaded();
void S9xROMLoaded();
#endif /* __GTK_S9X_H */

View File

@ -4,9 +4,7 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __GTK_S9XCORE_H
#define __GTK_S9XCORE_H
#pragma once
#include "snes9x.h"
#include "memmap.h"
#include "debug.h"
@ -24,7 +22,5 @@
#include "netplay.h"
#include <sys/types.h>
#include <ctype.h>
#include <cctype>
#include <dirent.h>
#endif /* __GTK_S9XCORE_H */

View File

@ -21,7 +21,6 @@
#include "gtk_s9x.h"
#include "gtk_preferences.h"
#include "gtk_icon.h"
#include "gtk_display.h"
#include "gtk_file.h"
#include "gtk_sound.h"
@ -31,6 +30,7 @@
#include "gtk_s9xwindow.h"
#include "fmt/format.h"
#include <utility>
#include "snes9x.h"
#include "controls.h"
@ -43,12 +43,13 @@
static Glib::RefPtr<Gtk::FileFilter> get_save_states_file_filter()
{
const char *exts[] = { "*.sst", "*.000", "*.001", "*.002", "*.003", "*.004",
"*.005", "*.006", "*.007", "*.008", "*.009", nullptr };
const auto extensions = { "*.sst", "*.000", "*.001", "*.002", "*.003", "*.004",
"*.005", "*.006", "*.007", "*.008", "*.009" };
auto filter = Gtk::FileFilter::create();
filter->set_name(_("Save States"));
for (int i = 0; exts[i]; i++)
filter->add_pattern(exts[i]);
for (auto &ext : extensions)
filter->add_pattern(ext);
return filter;
}
@ -80,7 +81,7 @@ Snes9xWindow::Snes9xWindow(Snes9xConfig *config)
if (Gtk::IconTheme::get_default()->has_icon("snes9x"))
{
window->set_default_icon_name("snes9x");
Gtk::Window::set_default_icon_name("snes9x");
}
else
{
@ -89,15 +90,13 @@ Snes9xWindow::Snes9xWindow(Snes9xConfig *config)
auto loader = Gdk::PixbufLoader::create();
loader->write(mini_icon, mini_icon_size);
loader->close();
auto pixbuf = loader->get_pixbuf();
if (pixbuf)
window->set_default_icon(pixbuf);
if (auto pixbuf = loader->get_pixbuf())
Gtk::Window::set_default_icon(pixbuf);
}
drawing_area = get_object<Gtk::DrawingArea>("drawingarea").get();
gtk_widget_realize(GTK_WIDGET(window->gobj()));
gtk_widget_realize(GTK_WIDGET(drawing_area->gobj()));
window->show();
drawing_area->show();
enable_widget("shader_parameters_item", false);
@ -311,10 +310,10 @@ bool Snes9xWindow::motion_notify(GdkEventMotion *event)
int scale_factor = window->get_scale_factor();
snes_mouse_x = (uint16)((int)(event->x * scale_factor) - mouse_region_x) * 256 /
snes_mouse_x = ((int)(event->x * scale_factor) - mouse_region_x) * 256 /
(mouse_region_width <= 0 ? 1 : mouse_region_width);
snes_mouse_y = (uint16)((int)(event->y * scale_factor) - mouse_region_y) * (gui_config->overscan ? SNES_HEIGHT_EXTENDED : SNES_HEIGHT) /
snes_mouse_y = ((int)(event->y * scale_factor) - mouse_region_y) * (gui_config->overscan ? SNES_HEIGHT_EXTENDED : SNES_HEIGHT) /
(mouse_region_height <= 0 ? 1 : mouse_region_height);
if (!config->pointer_is_visible)
@ -338,7 +337,7 @@ void Snes9xWindow::port_activate(const char *name)
const char *name;
int port;
enum controllers controller;
uint8_t id1, id2, id3, id4;
int8_t id1, id2, id3, id4;
} map[] = {
{ "joypad1", 0, CTL_JOYPAD, 0, 0, 0, 0 },
{ "joypad2", 1, CTL_JOYPAD, 1, 0, 0, 0 },
@ -418,6 +417,8 @@ extern unsigned char gtk_splash_pattern[];
void Snes9xWindow::setup_splash()
{
uint16 *screen_ptr = GFX.Screen;
if (!screen_ptr)
return;
// Load splash image (RGB24) into Snes9x buffer (RGB15)
last_width = 256;
@ -481,11 +482,6 @@ void Snes9xWindow::setup_splash()
return;
}
return;
for (int y = 0; y < 224; y++, screen_ptr += (GFX.Pitch / 2)) {
memset(screen_ptr, 0, 256 * sizeof(uint16));
}
}
bool Snes9xWindow::draw(const Cairo::RefPtr<Cairo::Context> &cr)
@ -536,7 +532,6 @@ void Snes9xWindow::focus_notify(bool state)
void Snes9xWindow::open_multicart_dialog()
{
int result;
GtkBuilderWindow dialog_builder("multicart_dialog");
auto dialog = Glib::RefPtr<Gtk::Dialog>::cast_static(dialog_builder.window);
@ -550,7 +545,7 @@ void Snes9xWindow::open_multicart_dialog()
slota->set_current_folder(config->last_directory);
slotb->set_current_folder(config->last_directory);
result = dialog->run();
int result = dialog->run();
dialog->hide();
if (result == GTK_RESPONSE_OK)
@ -636,11 +631,10 @@ std::string Snes9xWindow::open_movie_dialog(bool readonly)
std::string Snes9xWindow::open_rom_dialog(bool run)
{
const char *extensions[] = {
const auto extensions = {
"*.smc", "*.SMC", "*.fig", "*.FIG", "*.sfc", "*.SFC",
"*.jma", "*.JMA", "*.zip", "*.ZIP", "*.gd3", "*.GD3",
"*.swc", "*.SWC", "*.gz", "*.GZ", "*.bs", "*.BS",
NULL
"*.swc", "*.SWC", "*.gz", "*.GZ", "*.bs", "*.BS"
};
pause_from_focus_change();
@ -652,8 +646,9 @@ std::string Snes9xWindow::open_rom_dialog(bool run)
auto filter = Gtk::FileFilter::create();
filter->set_name(_("SNES ROM Images"));
for (int i = 0; extensions[i]; i++)
filter->add_pattern(extensions[i]);
for (const auto &ext : extensions)
filter->add_pattern(ext);
dialog.add_filter(filter);
dialog.add_filter(get_all_files_filter());
@ -688,7 +683,7 @@ std::string Snes9xWindow::open_rom_dialog(bool run)
return filename;
}
bool Snes9xWindow::try_open_rom(std::string filename)
bool Snes9xWindow::try_open_rom(const std::string &filename)
{
pause_from_focus_change();
@ -752,7 +747,7 @@ void Snes9xWindow::movie_seek_dialog()
{
std::string str;
str = fmt::format(_("The current frame in the movie is <b>{0:Ld}</b>."), S9xMovieGetFrameCounter());
str = fmt::format(fmt::runtime(_("The current frame in the movie is <b>{0:Ld}</b>.")), S9xMovieGetFrameCounter());
seek_dialog.get_object<Gtk::Label>("current_frame_label")->set_label(str);
str = fmt::format("{0:d}", S9xMovieGetFrameCounter());
@ -766,17 +761,14 @@ void Snes9xWindow::movie_seek_dialog()
int entry_value = seek_dialog.get_entry_value("frame_entry");
switch (result)
if (result == Gtk::RESPONSE_OK)
{
case Gtk::RESPONSE_OK:
if (entry_value > 0 &&
entry_value > (int)S9xMovieGetFrameCounter())
{
Settings.HighSpeedSeek =
entry_value - S9xMovieGetFrameCounter();
}
break;
}
unpause_from_focus_change();
@ -977,7 +969,6 @@ void Snes9xWindow::reset_screensaver()
if (!focused)
return;
GdkWindow *gdk_window = window->get_window()->gobj();
GdkDisplay *gdk_display = window->get_display()->gobj();
#ifdef GDK_WINDOWING_X11
@ -1007,7 +998,6 @@ static double XRRGetExactRefreshRate(Display *dpy, Window window)
int version_major;
int version_minor;
double refresh_rate = 0.0;
int i;
if (!XRRQueryExtension(dpy, &event_base, &error_base) ||
!XRRQueryVersion(dpy, &version_major, &version_minor))
@ -1021,7 +1011,7 @@ static double XRRGetExactRefreshRate(Display *dpy, Window window)
resources = XRRGetScreenResourcesCurrent(dpy, window);
crtc_info = XRRGetCrtcInfo(dpy, resources, resources->crtcs[0]);
for (i = 0; i < resources->nmode; i++)
for (int i = 0; i < resources->nmode; i++)
{
if (resources->modes[i].id == crtc_info->mode)
{
@ -1097,7 +1087,7 @@ int Snes9xWindow::get_auto_input_rate()
if (new_input_rate > 32040.0 * 1.05 || new_input_rate < 32040.0 * 0.95)
new_input_rate = 0.0;
return new_input_rate;
return static_cast<int>(new_input_rate);
}
@ -1121,7 +1111,6 @@ void Snes9xWindow::set_custom_video_mode(bool enable)
{
#ifdef GDK_WINDOWING_X11
GdkDisplay *gdk_display = window->get_display()->gobj();
GdkWindow *gdk_window = window->get_window()->gobj();
if (!is_x11())
return;
@ -1145,7 +1134,7 @@ void Snes9xWindow::set_custom_video_mode(bool enable)
&config->xrr_crtc_info->outputs[0],
1) != 0)
{
config->change_display_resolution = 0;
config->change_display_resolution = false;
}
if (gui_config->auto_input_rate)
@ -1320,13 +1309,13 @@ void Snes9xWindow::show()
recent_menu->set_sort_type(Gtk::RECENT_SORT_MRU);
get_object<Gtk::MenuItem>("open_recent_item")->set_submenu(*recent_menu);
recent_menu->signal_item_activated().connect([&] {
try_open_rom(Glib::filename_from_uri(recent_menu->get_current_uri()).c_str());
try_open_rom(Glib::filename_from_uri(recent_menu->get_current_uri()));
});
recent_menu->show();
auto clear_recent = get_object<Gtk::MenuItem>("clear_recent_items");
clear_recent->signal_activate().connect([&] {
clear_recent->signal_activate().connect([] {
auto manager = Gtk::RecentManager::get_default();
auto items = manager->get_items();
for (auto &i : items)
@ -1443,41 +1432,47 @@ void Snes9xWindow::update_accelerators()
}
accelerators.clear();
set_accelerator_to_binding("fullscreen_item", "GTK_fullscreen");
set_accelerator_to_binding("reset_item", "SoftReset");
set_accelerator_to_binding("save_state_0", "QuickSave000");
set_accelerator_to_binding("save_state_1", "QuickSave001");
set_accelerator_to_binding("save_state_2", "QuickSave002");
set_accelerator_to_binding("save_state_3", "QuickSave003");
set_accelerator_to_binding("save_state_4", "QuickSave004");
set_accelerator_to_binding("save_state_5", "QuickSave005");
set_accelerator_to_binding("save_state_6", "QuickSave006");
set_accelerator_to_binding("save_state_7", "QuickSave007");
set_accelerator_to_binding("save_state_8", "QuickSave008");
set_accelerator_to_binding("save_state_9", "QuickSave009");
set_accelerator_to_binding("load_state_0", "QuickLoad000");
set_accelerator_to_binding("load_state_1", "QuickLoad001");
set_accelerator_to_binding("load_state_2", "QuickLoad002");
set_accelerator_to_binding("load_state_3", "QuickLoad003");
set_accelerator_to_binding("load_state_4", "QuickLoad004");
set_accelerator_to_binding("load_state_5", "QuickLoad005");
set_accelerator_to_binding("load_state_6", "QuickLoad006");
set_accelerator_to_binding("load_state_7", "QuickLoad007");
set_accelerator_to_binding("load_state_8", "QuickLoad008");
set_accelerator_to_binding("load_state_9", "QuickLoad009");
set_accelerator_to_binding("pause_item", "GTK_pause");
set_accelerator_to_binding("save_spc_item", "GTK_save_spc");
set_accelerator_to_binding("open_rom_item", "GTK_open_rom");
set_accelerator_to_binding("record_movie_item", "BeginRecordingMovie");
set_accelerator_to_binding("open_movie_item", "LoadMovie");
set_accelerator_to_binding("stop_recording_item", "EndRecordingMovie");
set_accelerator_to_binding("jump_to_frame_item", "GTK_seek_to_frame");
set_accelerator_to_binding("reset_item", "SoftReset");
set_accelerator_to_binding("hard_reset_item", "Reset");
set_accelerator_to_binding("exit_item", "GTK_quit");
std::initializer_list<const char *[2]> pairs =
{
{ "fullscreen_item", "GTK_fullscreen" },
{ "reset_item", "SoftReset" },
{ "save_state_0", "QuickSave000" },
{ "save_state_1", "QuickSave001" },
{ "save_state_2", "QuickSave002" },
{ "save_state_3", "QuickSave003" },
{ "save_state_4", "QuickSave004" },
{ "save_state_5", "QuickSave005" },
{ "save_state_6", "QuickSave006" },
{ "save_state_7", "QuickSave007" },
{ "save_state_8", "QuickSave008" },
{ "save_state_9", "QuickSave009" },
{ "load_state_0", "QuickLoad000" },
{ "load_state_1", "QuickLoad001" },
{ "load_state_2", "QuickLoad002" },
{ "load_state_3", "QuickLoad003" },
{ "load_state_4", "QuickLoad004" },
{ "load_state_5", "QuickLoad005" },
{ "load_state_6", "QuickLoad006" },
{ "load_state_7", "QuickLoad007" },
{ "load_state_8", "QuickLoad008" },
{ "load_state_9", "QuickLoad009" },
{ "pause_item", "GTK_pause" },
{ "save_spc_item", "GTK_save_spc" },
{ "open_rom_item", "GTK_open_rom" },
{ "record_movie_item", "BeginRecordingMovie" },
{ "open_movie_item", "LoadMovie" },
{ "stop_recording_item", "EndRecordingMovie" },
{ "jump_to_frame_item", "GTK_seek_to_frame" },
{ "reset_item", "SoftReset" },
{ "hard_reset_item", "Reset" },
{ "exit_item", "GTK_quit" },
// Special UI assignment
{ "hide_ui", "Escape Key" }
};
// Special UI assignment
set_accelerator_to_binding("hide_ui", "Escape Key");
for (auto &[accelerator, binding_name] : pairs) {
set_accelerator_to_binding(accelerator, binding_name);
}
}
void Snes9xWindow::resize_to_multiple(int factor)

View File

@ -4,9 +4,7 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __GTK_S9XWINDOW_H
#define __GTK_S9XWINDOW_H
#pragma once
#include "gtk_compat.h"
#include "port.h"
@ -16,7 +14,7 @@
class Snes9xWindow : public GtkBuilderWindow
{
public:
Snes9xWindow(Snes9xConfig *config);
explicit Snes9xWindow(Snes9xConfig *config);
struct AcceleratorEntry
{
@ -38,7 +36,6 @@ class Snes9xWindow : public GtkBuilderWindow
void enter_fullscreen_mode();
void leave_fullscreen_mode();
void toggle_fullscreen_mode();
void finish_fullscreen();
void set_bypass_compositor(bool bypass);
void set_custom_video_mode(bool enable);
@ -54,7 +51,7 @@ class Snes9xWindow : public GtkBuilderWindow
void load_state_dialog();
void configure_widgets();
void save_spc_dialog();
bool try_open_rom(std::string filename);
bool try_open_rom(const std::string &filename);
std::string open_movie_dialog(bool readonly);
void movie_seek_dialog();
void open_multicart_dialog();
@ -121,5 +118,3 @@ typedef struct gtk_splash_t
unsigned int bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */
unsigned char pixel_data[256 * 224 * 3 + 1];
} gtk_splash_t;
#endif /* __GTK_S9XWINDOW_H */

View File

@ -6,7 +6,7 @@
#include "gtk_compat.h"
#include <vector>
#include <math.h>
#include <cmath>
#include "gtk_s9x.h"
#include "gtk_display.h"
@ -41,12 +41,11 @@ static void dialog_response(int response_id)
config_file += "/snes9x.slangp";
else
config_file = get_config_dir() + "/snes9x.glslp";
S9xDisplayGetDriver()->save(config_file.c_str());
S9xDisplayGetDriver()->save(config_file);
realpath(config_file.c_str(), path);
gui_config->shader_filename = path;
if (dialog)
delete dialog;
delete dialog;
dialog = nullptr;
break;
}
@ -54,8 +53,7 @@ static void dialog_response(int response_id)
case Gtk::RESPONSE_CANCEL:
case Gtk::RESPONSE_DELETE_EVENT:
case Gtk::RESPONSE_NONE:
if (dialog)
delete dialog;
delete dialog;
dialog = nullptr;
*params = saved_params;
if (Settings.Paused)
@ -94,7 +92,7 @@ static void dialog_response(int response_id)
auto result = dialog.run();
if (result == GTK_RESPONSE_ACCEPT)
S9xDisplayGetDriver()->save(dialog.get_filename().c_str());
S9xDisplayGetDriver()->save(dialog.get_filename());
break;
}
@ -125,7 +123,7 @@ bool gtk_shader_parameters_dialog(GtkWindow *parent)
params = (std::vector<GLSLParam> *)S9xDisplayGetDriver()->get_parameters();
saved_params = *params;
if (!params || params->size() == 0)
if (!params || params->empty())
return false;
dialog = new Gtk::Dialog(_("Shader Parameters"), Gtk::DIALOG_DESTROY_WITH_PARENT);

View File

@ -4,12 +4,8 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __GTK_SHADER_PARAMETERS_H
#define __GTK_SHADER_PARAMETERS_H
#pragma once
#include "gtk_compat.h"
bool gtk_shader_parameters_dialog(GtkWindow *parent);
void gtk_shader_parameters_dialog_close();
#endif // __GTK_SHADER_PARAMETERS_H

View File

@ -33,26 +33,6 @@ static int playback_rates[8] =
static S9xSoundDriver *driver;
int S9xSoundBase2log(int num)
{
int power;
if (num < 1)
return 0;
for (power = 0; num > 1; power++)
{
num >>= 1;
}
return power;
}
int S9xSoundPowerof2(int num)
{
return (1 << num);
}
std::vector<std::string> S9xGetSoundDriverNames()
{
std::vector<std::string> names;
@ -104,7 +84,7 @@ void S9xPortSoundInit()
if (name == "SDL")
driver = new S9xSDLSoundDriver();
if (driver != NULL)
if (driver != nullptr)
{
driver->init();
@ -114,7 +94,7 @@ void S9xPortSoundInit()
if (Settings.SoundInputRate == 0.0)
{
Settings.SoundInputRate = 31950;
gui_config->auto_input_rate = 0;
gui_config->auto_input_rate = false;
}
}
else

View File

@ -4,9 +4,7 @@
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef __GTK_SOUND_H
#define __GTK_SOUND_H
#pragma once
#include <vector>
#include <string>
@ -16,8 +14,4 @@ void S9xPortSoundReinit();
void S9xSoundStart();
void S9xSoundStop();
int S9xSoundBase2log(int num);
int S9xSoundPowerof2(int num);
std::vector<std::string> S9xGetSoundDriverNames();
#endif /* __GTK_SOUND_H */

View File

@ -3,7 +3,7 @@
void threadpool::thread_func()
{
while (1)
while (true)
{
std::unique_lock<std::mutex> lock(mutex);
cond.wait_for(lock, std::chrono::microseconds(100), [this] {
@ -69,7 +69,7 @@ void threadpool::stop()
started = false;
}
void threadpool::queue(std::function<void()> func)
void threadpool::queue(const std::function<void()>& func)
{
std::unique_lock<std::mutex> lock(mutex);
@ -81,5 +81,4 @@ void threadpool::queue(std::function<void()> func)
lock.unlock();
cond.notify_all();
return;
}

View File

@ -13,7 +13,7 @@ class threadpool
public:
void start(int num_threads);
void stop();
void queue(std::function<void()> func);
void queue(const std::function<void()>& func);
void wait_idle();
private: