Fix some warnings.

Removed sstrncpy function.
Changed bindings in GTK port to std::array and fixed packing nonsense.
This commit is contained in:
Brandon Wright 2020-06-20 10:44:11 -05:00
parent 995f0be52c
commit 5c3fbf6740
11 changed files with 52 additions and 53 deletions

View File

@ -81,8 +81,7 @@ Binding &Binding::operator=(const Binding &binding)
return *this;
}
bool
Binding::matches (Binding &binding)
bool Binding::operator==(const Binding &binding)
{
if ((value & ~BINDING_THRESHOLD_MASK) ==
(binding.value & ~BINDING_THRESHOLD_MASK))

View File

@ -38,6 +38,7 @@ class Binding
Binding (unsigned int device, unsigned int button, unsigned int threshold);
Binding (const Binding &binding);
Binding &operator=(const Binding &binding);
bool operator==(const Binding &binding);
Binding (GdkEventKey *event);
Binding (unsigned int);
Binding ();
@ -45,7 +46,6 @@ class Binding
void to_string (char *str, bool translate = true);
unsigned int hex ();
unsigned int base_hex ();
bool matches (Binding &binding);
void clear ();
bool is_joy ();
bool is_key ();

View File

@ -194,8 +194,12 @@ int Snes9xConfig::load_defaults ()
Settings.TwoClockCycles = 12;
#endif
memset (pad, 0, sizeof (JoypadBinding) * NUM_JOYPADS);
memset (shortcut, 0, sizeof (Binding) * NUM_EMU_LINKS);
for (auto &joypad : pad)
{
joypad.data.fill(Binding());
}
shortcut.fill(Binding());
return 0;
}
@ -399,12 +403,12 @@ int Snes9xConfig::save_config_file ()
for (int i = 0; i < NUM_JOYPADS; i++)
{
Binding *joypad = (Binding *) &pad[i];
auto &joypad = pad[i];
for (int j = 0; j < NUM_JOYPAD_LINKS; j++)
{
snprintf (key, PATH_MAX, "Joypad %d::%s", i, b_links[j].snes9x_name);
joypad[j].to_string (buffer, false);
joypad.data[j].to_string (buffer, false);
cf.SetString (key, std::string (buffer));
}
}
@ -620,13 +624,13 @@ int Snes9xConfig::load_config_file ()
for (int i = 0; i < NUM_JOYPADS; i++)
{
Binding *joypad = (Binding *) &pad[i];
auto &joypad = pad[i];
for (int j = 0; j < NUM_JOYPAD_LINKS; j++)
{
snprintf (key, PATH_MAX, "Joypad %d::%s", i, b_links[j].snes9x_name);
instr (key, buffer);
joypad[j] = Binding (buffer.c_str ());
joypad.data[j] = Binding (buffer.c_str ());
}
}
@ -714,14 +718,14 @@ void Snes9xConfig::rebind_keys()
for (int joypad_i = 0; joypad_i < NUM_JOYPADS; joypad_i++)
{
Binding *bin = (Binding *)&pad[joypad_i];
auto &bin = pad[joypad_i].data;
for (int button_i = 0; button_i < NUM_JOYPAD_LINKS; button_i++)
{
int dupe;
for (dupe = button_i + 1; dupe < NUM_JOYPAD_LINKS; dupe++)
{
if (bin[button_i].matches(bin[dupe]) && bin[button_i].hex() != 0)
if (bin[button_i] == bin[dupe] && bin[button_i].hex() != 0)
break;
}
if (dupe < NUM_JOYPAD_LINKS || bin[button_i].hex() == 0)
@ -733,7 +737,7 @@ void Snes9xConfig::rebind_keys()
bool ismulti = false;
for (dupe = button_i - 1; dupe > 0; dupe--)
{
if (bin[button_i].matches(bin[dupe]))
if (bin[button_i] == bin[dupe])
{
ismulti = true;
string += ",Joypad" + std::to_string((joypad_i % 5) + 1) + " ";

View File

@ -10,6 +10,7 @@
#include <X11/Xlib.h>
#include <X11/extensions/Xrandr.h>
#include <string>
#include <array>
#include "gtk_control.h"
#include "filter/snes_ntsc.h"
@ -110,8 +111,8 @@ class Snes9xConfig
std::string last_shader_directory;
/* Controls */
JoypadBinding pad[NUM_JOYPADS];
Binding shortcut[NUM_EMU_LINKS];
std::array<JoypadBinding, NUM_JOYPADS> pad;
std::array<Binding, NUM_EMU_LINKS> shortcut;
/* Netplay */
bool netplay_is_server;

View File

@ -8,6 +8,7 @@
#define __GTK_CONTROL_H
#include <queue>
#include <array>
#include "gtk_binding.h"
#include "SDL.h"
@ -73,7 +74,7 @@ const int NUM_EMU_LINKS = 62;
typedef struct JoypadBinding
{
Binding data[NUM_JOYPAD_LINKS]; /* Avoid packing issues */
std::array<Binding, NUM_JOYPAD_LINKS> data;
} JoypadBinding;
bool S9xGrabJoysticks ();

View File

@ -139,33 +139,33 @@ S9xGetDirectory (enum s9x_getdirtype dirtype)
switch (dirtype)
{
case HOME_DIR:
sstrncpy (path, get_config_dir ().c_str (), PATH_MAX + 1);
break;
case HOME_DIR:
snprintf(path, PATH_MAX + 1, get_config_dir().c_str());
break;
case SNAPSHOT_DIR:
sstrncpy (path, gui_config->savestate_directory.c_str (), PATH_MAX + 1);
break;
case SNAPSHOT_DIR:
snprintf(path, PATH_MAX + 1, gui_config->savestate_directory.c_str());
break;
case PATCH_DIR:
sstrncpy (path, gui_config->patch_directory.c_str (), PATH_MAX + 1);
break;
case PATCH_DIR:
snprintf(path, PATH_MAX + 1, gui_config->patch_directory.c_str());
break;
case CHEAT_DIR:
sstrncpy (path, gui_config->cheat_directory.c_str (), PATH_MAX + 1);
break;
case CHEAT_DIR:
snprintf(path, PATH_MAX + 1, gui_config->cheat_directory.c_str());
break;
case SRAM_DIR:
sstrncpy (path, gui_config->sram_directory.c_str (), PATH_MAX + 1);
break;
case SRAM_DIR:
snprintf(path, PATH_MAX + 1, gui_config->sram_directory.c_str());
break;
case SCREENSHOT_DIR:
case SPC_DIR:
sstrncpy (path, gui_config->export_directory.c_str (), PATH_MAX + 1);
break;
case SCREENSHOT_DIR:
case SPC_DIR:
snprintf(path, PATH_MAX + 1, gui_config->export_directory.c_str());
break;
default:
path[0] = '\0';
default:
path[0] = '\0';
}
/* Check if directory exists, make it and/or set correct permissions */
@ -249,7 +249,7 @@ S9xBasenameNoExt (const char *f)
ext = strrchr (f, '.');
if (!ext)
sstrncpy (filename, base, PATH_MAX);
snprintf (filename, PATH_MAX, base);
else
{
int len = ext - base;
@ -288,7 +288,7 @@ S9xOpenSnapshotFile (const char *fname, bool8 read_only, STREAM *file)
if (*drive || *dir == '/' || (*dir == '.' && (*(dir + 1) == '/')))
{
sstrncpy (filename, fname, PATH_MAX + 1);
snprintf (filename, PATH_MAX + 1, fname);
if (!file_exists (filename))
{

View File

@ -733,8 +733,8 @@ Snes9xPreferences::move_settings_to_dialog ()
set_spin ("joystick_threshold", config->joystick_threshold);
/* Control bindings */
memcpy (pad, config->pad, (sizeof (JoypadBinding)) * NUM_JOYPADS);
memcpy (shortcut, config->shortcut, (sizeof (Binding)) * NUM_EMU_LINKS);
pad = config->pad;
shortcut = config->shortcut;
bindings_to_dialog (0);
set_combo ("joypad_to_swap_with", 0);
@ -966,8 +966,8 @@ Snes9xPreferences::get_settings_from_dialog ()
config->sram_directory = new_sram_directory;
}
memcpy (config->pad, pad, (sizeof (JoypadBinding)) * NUM_JOYPADS);
memcpy (config->shortcut, shortcut, (sizeof (Binding)) * NUM_EMU_LINKS);
config->pad = pad;
config->shortcut = shortcut;
if (sound_needs_restart)
{
@ -1266,7 +1266,7 @@ Snes9xPreferences::store_binding (const char *string, Binding binding)
}
else
{
if (shortcut[i - NUM_JOYPAD_LINKS].matches (binding))
if (shortcut[i - NUM_JOYPAD_LINKS] == binding)
{
shortcut[i - NUM_JOYPAD_LINKS].clear ();
}

View File

@ -38,8 +38,8 @@ class Snes9xPreferences : public GtkBuilderWindow
GtkToggleButton *last_toggled;
bool awaiting_key;
bool polling_joystick;
JoypadBinding pad[NUM_JOYPADS];
Binding shortcut[NUM_EMU_LINKS];
std::array<JoypadBinding, NUM_JOYPADS> pad;
std::array<Binding, NUM_EMU_LINKS> shortcut;
private:
void get_settings_from_dialog ();

View File

@ -2531,7 +2531,7 @@ void CMemory::InitROM (void)
if (Settings.ForcePAL)
Settings.PAL = TRUE;
else
if (!Settings.BS && ((ROMRegion >= 2) && (ROMRegion <= 12) || ROMRegion == 18)) // 18 is used by "Tintin in Tibet (Europe) (En,Es,Sv)"
if (!Settings.BS && (((ROMRegion >= 2) && (ROMRegion <= 12)) || ROMRegion == 18)) // 18 is used by "Tintin in Tibet (Europe) (En,Es,Sv)"
Settings.PAL = TRUE;
else
Settings.PAL = FALSE;

View File

@ -434,7 +434,7 @@ static int read_movie_extrarominfo (FILE *fd, SMovie *movie)
ptr += 3; // zero bytes
movie->ROMCRC32 = Read32(ptr);
sstrncpy(movie->ROMName, (char *) ptr, 23);
memcpy(movie->ROMName, (char *) ptr, 23);
return (SUCCESS);
}

6
port.h
View File

@ -151,12 +151,6 @@ void SetInfoDlgColor(unsigned char, unsigned char, unsigned char);
#endif // __LIBRETRO__
#endif // __WIN32__
inline void sstrncpy(char *dst, const char *src, size_t size)
{
strncpy(dst, src, size - 1);
dst[size - 1] = '\0';
}
#if defined(__DJGPP) || defined(__WIN32__)
#define SLASH_STR "\\"
#define SLASH_CHAR '\\'