mirror of https://github.com/snes9xgit/snes9x.git
Fix some warnings.
Removed sstrncpy function. Changed bindings in GTK port to std::array and fixed packing nonsense.
This commit is contained in:
parent
995f0be52c
commit
5c3fbf6740
|
@ -81,8 +81,7 @@ Binding &Binding::operator=(const Binding &binding)
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool Binding::operator==(const Binding &binding)
|
||||||
Binding::matches (Binding &binding)
|
|
||||||
{
|
{
|
||||||
if ((value & ~BINDING_THRESHOLD_MASK) ==
|
if ((value & ~BINDING_THRESHOLD_MASK) ==
|
||||||
(binding.value & ~BINDING_THRESHOLD_MASK))
|
(binding.value & ~BINDING_THRESHOLD_MASK))
|
||||||
|
|
|
@ -38,6 +38,7 @@ class Binding
|
||||||
Binding (unsigned int device, unsigned int button, unsigned int threshold);
|
Binding (unsigned int device, unsigned int button, unsigned int threshold);
|
||||||
Binding (const Binding &binding);
|
Binding (const Binding &binding);
|
||||||
Binding &operator=(const Binding &binding);
|
Binding &operator=(const Binding &binding);
|
||||||
|
bool operator==(const Binding &binding);
|
||||||
Binding (GdkEventKey *event);
|
Binding (GdkEventKey *event);
|
||||||
Binding (unsigned int);
|
Binding (unsigned int);
|
||||||
Binding ();
|
Binding ();
|
||||||
|
@ -45,7 +46,6 @@ class Binding
|
||||||
void to_string (char *str, bool translate = true);
|
void to_string (char *str, bool translate = true);
|
||||||
unsigned int hex ();
|
unsigned int hex ();
|
||||||
unsigned int base_hex ();
|
unsigned int base_hex ();
|
||||||
bool matches (Binding &binding);
|
|
||||||
void clear ();
|
void clear ();
|
||||||
bool is_joy ();
|
bool is_joy ();
|
||||||
bool is_key ();
|
bool is_key ();
|
||||||
|
|
|
@ -194,8 +194,12 @@ int Snes9xConfig::load_defaults ()
|
||||||
Settings.TwoClockCycles = 12;
|
Settings.TwoClockCycles = 12;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
memset (pad, 0, sizeof (JoypadBinding) * NUM_JOYPADS);
|
for (auto &joypad : pad)
|
||||||
memset (shortcut, 0, sizeof (Binding) * NUM_EMU_LINKS);
|
{
|
||||||
|
joypad.data.fill(Binding());
|
||||||
|
}
|
||||||
|
|
||||||
|
shortcut.fill(Binding());
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -399,12 +403,12 @@ int Snes9xConfig::save_config_file ()
|
||||||
|
|
||||||
for (int i = 0; i < NUM_JOYPADS; i++)
|
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++)
|
for (int j = 0; j < NUM_JOYPAD_LINKS; j++)
|
||||||
{
|
{
|
||||||
snprintf (key, PATH_MAX, "Joypad %d::%s", i, b_links[j].snes9x_name);
|
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));
|
cf.SetString (key, std::string (buffer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -620,13 +624,13 @@ int Snes9xConfig::load_config_file ()
|
||||||
|
|
||||||
for (int i = 0; i < NUM_JOYPADS; i++)
|
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++)
|
for (int j = 0; j < NUM_JOYPAD_LINKS; j++)
|
||||||
{
|
{
|
||||||
snprintf (key, PATH_MAX, "Joypad %d::%s", i, b_links[j].snes9x_name);
|
snprintf (key, PATH_MAX, "Joypad %d::%s", i, b_links[j].snes9x_name);
|
||||||
instr (key, buffer);
|
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++)
|
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++)
|
for (int button_i = 0; button_i < NUM_JOYPAD_LINKS; button_i++)
|
||||||
{
|
{
|
||||||
int dupe;
|
int dupe;
|
||||||
for (dupe = button_i + 1; dupe < NUM_JOYPAD_LINKS; 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;
|
break;
|
||||||
}
|
}
|
||||||
if (dupe < NUM_JOYPAD_LINKS || bin[button_i].hex() == 0)
|
if (dupe < NUM_JOYPAD_LINKS || bin[button_i].hex() == 0)
|
||||||
|
@ -733,7 +737,7 @@ void Snes9xConfig::rebind_keys()
|
||||||
bool ismulti = false;
|
bool ismulti = false;
|
||||||
for (dupe = button_i - 1; dupe > 0; dupe--)
|
for (dupe = button_i - 1; dupe > 0; dupe--)
|
||||||
{
|
{
|
||||||
if (bin[button_i].matches(bin[dupe]))
|
if (bin[button_i] == bin[dupe])
|
||||||
{
|
{
|
||||||
ismulti = true;
|
ismulti = true;
|
||||||
string += ",Joypad" + std::to_string((joypad_i % 5) + 1) + " ";
|
string += ",Joypad" + std::to_string((joypad_i % 5) + 1) + " ";
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/extensions/Xrandr.h>
|
#include <X11/extensions/Xrandr.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <array>
|
||||||
|
|
||||||
#include "gtk_control.h"
|
#include "gtk_control.h"
|
||||||
#include "filter/snes_ntsc.h"
|
#include "filter/snes_ntsc.h"
|
||||||
|
@ -110,8 +111,8 @@ class Snes9xConfig
|
||||||
std::string last_shader_directory;
|
std::string last_shader_directory;
|
||||||
|
|
||||||
/* Controls */
|
/* Controls */
|
||||||
JoypadBinding pad[NUM_JOYPADS];
|
std::array<JoypadBinding, NUM_JOYPADS> pad;
|
||||||
Binding shortcut[NUM_EMU_LINKS];
|
std::array<Binding, NUM_EMU_LINKS> shortcut;
|
||||||
|
|
||||||
/* Netplay */
|
/* Netplay */
|
||||||
bool netplay_is_server;
|
bool netplay_is_server;
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#define __GTK_CONTROL_H
|
#define __GTK_CONTROL_H
|
||||||
|
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
#include <array>
|
||||||
|
|
||||||
#include "gtk_binding.h"
|
#include "gtk_binding.h"
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
@ -73,7 +74,7 @@ const int NUM_EMU_LINKS = 62;
|
||||||
|
|
||||||
typedef struct JoypadBinding
|
typedef struct JoypadBinding
|
||||||
{
|
{
|
||||||
Binding data[NUM_JOYPAD_LINKS]; /* Avoid packing issues */
|
std::array<Binding, NUM_JOYPAD_LINKS> data;
|
||||||
} JoypadBinding;
|
} JoypadBinding;
|
||||||
|
|
||||||
bool S9xGrabJoysticks ();
|
bool S9xGrabJoysticks ();
|
||||||
|
|
|
@ -139,33 +139,33 @@ S9xGetDirectory (enum s9x_getdirtype dirtype)
|
||||||
|
|
||||||
switch (dirtype)
|
switch (dirtype)
|
||||||
{
|
{
|
||||||
case HOME_DIR:
|
case HOME_DIR:
|
||||||
sstrncpy (path, get_config_dir ().c_str (), PATH_MAX + 1);
|
snprintf(path, PATH_MAX + 1, get_config_dir().c_str());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SNAPSHOT_DIR:
|
case SNAPSHOT_DIR:
|
||||||
sstrncpy (path, gui_config->savestate_directory.c_str (), PATH_MAX + 1);
|
snprintf(path, PATH_MAX + 1, gui_config->savestate_directory.c_str());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PATCH_DIR:
|
case PATCH_DIR:
|
||||||
sstrncpy (path, gui_config->patch_directory.c_str (), PATH_MAX + 1);
|
snprintf(path, PATH_MAX + 1, gui_config->patch_directory.c_str());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CHEAT_DIR:
|
case CHEAT_DIR:
|
||||||
sstrncpy (path, gui_config->cheat_directory.c_str (), PATH_MAX + 1);
|
snprintf(path, PATH_MAX + 1, gui_config->cheat_directory.c_str());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SRAM_DIR:
|
case SRAM_DIR:
|
||||||
sstrncpy (path, gui_config->sram_directory.c_str (), PATH_MAX + 1);
|
snprintf(path, PATH_MAX + 1, gui_config->sram_directory.c_str());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SCREENSHOT_DIR:
|
case SCREENSHOT_DIR:
|
||||||
case SPC_DIR:
|
case SPC_DIR:
|
||||||
sstrncpy (path, gui_config->export_directory.c_str (), PATH_MAX + 1);
|
snprintf(path, PATH_MAX + 1, gui_config->export_directory.c_str());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
path[0] = '\0';
|
path[0] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if directory exists, make it and/or set correct permissions */
|
/* Check if directory exists, make it and/or set correct permissions */
|
||||||
|
@ -249,7 +249,7 @@ S9xBasenameNoExt (const char *f)
|
||||||
ext = strrchr (f, '.');
|
ext = strrchr (f, '.');
|
||||||
|
|
||||||
if (!ext)
|
if (!ext)
|
||||||
sstrncpy (filename, base, PATH_MAX);
|
snprintf (filename, PATH_MAX, base);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int len = ext - base;
|
int len = ext - base;
|
||||||
|
@ -288,7 +288,7 @@ S9xOpenSnapshotFile (const char *fname, bool8 read_only, STREAM *file)
|
||||||
|
|
||||||
if (*drive || *dir == '/' || (*dir == '.' && (*(dir + 1) == '/')))
|
if (*drive || *dir == '/' || (*dir == '.' && (*(dir + 1) == '/')))
|
||||||
{
|
{
|
||||||
sstrncpy (filename, fname, PATH_MAX + 1);
|
snprintf (filename, PATH_MAX + 1, fname);
|
||||||
|
|
||||||
if (!file_exists (filename))
|
if (!file_exists (filename))
|
||||||
{
|
{
|
||||||
|
|
|
@ -733,8 +733,8 @@ Snes9xPreferences::move_settings_to_dialog ()
|
||||||
set_spin ("joystick_threshold", config->joystick_threshold);
|
set_spin ("joystick_threshold", config->joystick_threshold);
|
||||||
|
|
||||||
/* Control bindings */
|
/* Control bindings */
|
||||||
memcpy (pad, config->pad, (sizeof (JoypadBinding)) * NUM_JOYPADS);
|
pad = config->pad;
|
||||||
memcpy (shortcut, config->shortcut, (sizeof (Binding)) * NUM_EMU_LINKS);
|
shortcut = config->shortcut;
|
||||||
bindings_to_dialog (0);
|
bindings_to_dialog (0);
|
||||||
|
|
||||||
set_combo ("joypad_to_swap_with", 0);
|
set_combo ("joypad_to_swap_with", 0);
|
||||||
|
@ -966,8 +966,8 @@ Snes9xPreferences::get_settings_from_dialog ()
|
||||||
config->sram_directory = new_sram_directory;
|
config->sram_directory = new_sram_directory;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy (config->pad, pad, (sizeof (JoypadBinding)) * NUM_JOYPADS);
|
config->pad = pad;
|
||||||
memcpy (config->shortcut, shortcut, (sizeof (Binding)) * NUM_EMU_LINKS);
|
config->shortcut = shortcut;
|
||||||
|
|
||||||
if (sound_needs_restart)
|
if (sound_needs_restart)
|
||||||
{
|
{
|
||||||
|
@ -1266,7 +1266,7 @@ Snes9xPreferences::store_binding (const char *string, Binding binding)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (shortcut[i - NUM_JOYPAD_LINKS].matches (binding))
|
if (shortcut[i - NUM_JOYPAD_LINKS] == binding)
|
||||||
{
|
{
|
||||||
shortcut[i - NUM_JOYPAD_LINKS].clear ();
|
shortcut[i - NUM_JOYPAD_LINKS].clear ();
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,8 +38,8 @@ class Snes9xPreferences : public GtkBuilderWindow
|
||||||
GtkToggleButton *last_toggled;
|
GtkToggleButton *last_toggled;
|
||||||
bool awaiting_key;
|
bool awaiting_key;
|
||||||
bool polling_joystick;
|
bool polling_joystick;
|
||||||
JoypadBinding pad[NUM_JOYPADS];
|
std::array<JoypadBinding, NUM_JOYPADS> pad;
|
||||||
Binding shortcut[NUM_EMU_LINKS];
|
std::array<Binding, NUM_EMU_LINKS> shortcut;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void get_settings_from_dialog ();
|
void get_settings_from_dialog ();
|
||||||
|
|
|
@ -2531,7 +2531,7 @@ void CMemory::InitROM (void)
|
||||||
if (Settings.ForcePAL)
|
if (Settings.ForcePAL)
|
||||||
Settings.PAL = TRUE;
|
Settings.PAL = TRUE;
|
||||||
else
|
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;
|
Settings.PAL = TRUE;
|
||||||
else
|
else
|
||||||
Settings.PAL = FALSE;
|
Settings.PAL = FALSE;
|
||||||
|
|
|
@ -434,7 +434,7 @@ static int read_movie_extrarominfo (FILE *fd, SMovie *movie)
|
||||||
|
|
||||||
ptr += 3; // zero bytes
|
ptr += 3; // zero bytes
|
||||||
movie->ROMCRC32 = Read32(ptr);
|
movie->ROMCRC32 = Read32(ptr);
|
||||||
sstrncpy(movie->ROMName, (char *) ptr, 23);
|
memcpy(movie->ROMName, (char *) ptr, 23);
|
||||||
|
|
||||||
return (SUCCESS);
|
return (SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
6
port.h
6
port.h
|
@ -151,12 +151,6 @@ void SetInfoDlgColor(unsigned char, unsigned char, unsigned char);
|
||||||
#endif // __LIBRETRO__
|
#endif // __LIBRETRO__
|
||||||
#endif // __WIN32__
|
#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__)
|
#if defined(__DJGPP) || defined(__WIN32__)
|
||||||
#define SLASH_STR "\\"
|
#define SLASH_STR "\\"
|
||||||
#define SLASH_CHAR '\\'
|
#define SLASH_CHAR '\\'
|
||||||
|
|
Loading…
Reference in New Issue