summaryrefslogtreecommitdiffhomepage
path: root/tracker-wii/wiiyourself
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2018-10-25 03:38:09 +0200
committerStanislaw Halik <sthalik@misaki.pl>2018-10-25 03:54:09 +0200
commit25b7bf6a9750f92bd75850740002d32dcf08470e (patch)
tree314e994452a3b56af7b9a9d7465e9f8c92cad791 /tracker-wii/wiiyourself
parent0a1a0e9df00f37a210b67a11cf8f99550cafeeaf (diff)
tracker/wii: fix for mingw-w64
The module loses auto-pairing functionality, but it's at least useful to see GCC warnings. I don't intend to use GCC for actually running the module. Fix some warnings emitted by GCC, such as - memset(3) of non-POD struct - depending on "new T[0]" to return a null pointer - dependence on MSVC-specific pragmas for external libraries - lack of header guards - unintended usage of trigraph syntax Disable some GCC warnings for the "wiiyourself" library. It's not possible to patch it up, the code quality is that awful. Disable the builtin debug functionality since it depends on non-standard __VA_OPT__ (due in C++20). It's not possible to disable the warning emitted on the __VA_ARGS__ usage in GCC.
Diffstat (limited to 'tracker-wii/wiiyourself')
-rw-r--r--tracker-wii/wiiyourself/CMakeLists.txt5
-rw-r--r--tracker-wii/wiiyourself/warns-begin.hpp9
-rw-r--r--tracker-wii/wiiyourself/warns-end.hpp3
-rw-r--r--tracker-wii/wiiyourself/wiimote.cpp45
-rw-r--r--tracker-wii/wiiyourself/wiimote.h10
-rw-r--r--tracker-wii/wiiyourself/wiimote_common.h2
6 files changed, 46 insertions, 28 deletions
diff --git a/tracker-wii/wiiyourself/CMakeLists.txt b/tracker-wii/wiiyourself/CMakeLists.txt
index 614ff1c3..fe6d62e8 100644
--- a/tracker-wii/wiiyourself/CMakeLists.txt
+++ b/tracker-wii/wiiyourself/CMakeLists.txt
@@ -1 +1,4 @@
-otr_module(wiiyourself STATIC NO-COMPAT NO-QT)
+if(WIN32)
+ otr_module(wiiyourself STATIC NO-COMPAT NO-QT)
+ target_link_libraries(${self} setupapi hid winmm)
+endif()
diff --git a/tracker-wii/wiiyourself/warns-begin.hpp b/tracker-wii/wiiyourself/warns-begin.hpp
new file mode 100644
index 00000000..ca2b6b93
--- /dev/null
+++ b/tracker-wii/wiiyourself/warns-begin.hpp
@@ -0,0 +1,9 @@
+#ifdef __GNUG__
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wswitch"
+# pragma GCC diagnostic ignored "-Wreorder"
+# pragma GCC diagnostic ignored "-Wunused-variable"
+# pragma GCC diagnostic ignored "-Wunused-but-set-variable"
+# pragma GCC diagnostic ignored "-Wunused-parameter"
+# pragma GCC diagnostic ignored "-Wcast-function-type"
+#endif
diff --git a/tracker-wii/wiiyourself/warns-end.hpp b/tracker-wii/wiiyourself/warns-end.hpp
new file mode 100644
index 00000000..beaf245d
--- /dev/null
+++ b/tracker-wii/wiiyourself/warns-end.hpp
@@ -0,0 +1,3 @@
+#ifdef __GNUG__
+# pragma GCC diagnostic pop
+#endif
diff --git a/tracker-wii/wiiyourself/wiimote.cpp b/tracker-wii/wiiyourself/wiimote.cpp
index f53e1acf..0da0113b 100644
--- a/tracker-wii/wiiyourself/wiimote.cpp
+++ b/tracker-wii/wiiyourself/wiimote.cpp
@@ -8,15 +8,17 @@
//
// wiimote.cpp (tab = 4 spaces)
+#include "warns-begin.hpp"
+
// VC-specifics:
#ifdef _MSC_VER
// disable warning "C++ exception handler used, but unwind semantics are not enabled."
// in <xstring> (I don't use it - or just enable C++ exceptions)
# pragma warning(disable: 4530)
// auto-link with the necessary libs
-# pragma comment(lib, "setupapi.lib")
-# pragma comment(lib, "hid.lib") // for HID API (from DDK)
-# pragma comment(lib, "winmm.lib") // for timeGetTime()
+//# pragma comment(lib, "setupapi.lib")
+//# pragma comment(lib, "hid.lib") // for HID API (from DDK)
+//# pragma comment(lib, "winmm.lib") // for timeGetTime()
#endif // _MSC_VER
#include "wiimote.h"
@@ -24,14 +26,13 @@
extern "C" {
#include <hidsdi.h>// from WinDDK
}
+
#include <sys/types.h> // for _stat
#include <sys/stat.h> // "
+#include <cstring>
+#include <cstdio>
#include <process.h> // for _beginthreadex()
-#ifdef __BORLANDC__
-# include <cmath.h> // for orientation
-#else
-# include <math.h> // "
-#endif
+#include <math.h> // for orientation
#include <mmreg.h> // for WAVEFORMATEXTENSIBLE
#include <mmsystem.h> // for timeGetTime()
@@ -49,17 +50,12 @@ template<class T> inline T square(const T& val) { return val * val; }
// ------------------------------------------------------------------------------------
// Tracing & Debugging
// ------------------------------------------------------------------------------------
-#define PREFIX _T("WiiYourself! : ")
+#define PREFIX "WiiYourself: "
// comment these to auto-strip their code from the library:
// (they currently use OutputDebugString() via _TRACE() - change to suit)
-#if (_MSC_VER >= 1400) // VC 2005+ (earlier versions don't support variable args)
-# define TRACE(fmt, ...) _TRACE(PREFIX fmt _T("\n"), __VA_ARGS__)
-# define WARN(fmt, ...) _TRACE(PREFIX _T("* ") fmt _T(" *") _T("\n"), __VA_ARGS__)
-#elif defined(__MINGW32__)
-# define TRACE(fmt, ...) _TRACE(PREFIX fmt _T("\n") , ##__VA_ARGS__)
-# define WARN(fmt, ...) _TRACE(PREFIX _T("* ") fmt _T(" *") _T("\n") , ##__VA_ARGS__)
-#endif
+# define TRACE _TRACE
+# define WARN _TRACE
// uncomment any of these for deeper debugging:
//#define DEEP_TRACE(fmt, ...) _TRACE(PREFIX _T("|") fmt _T("\n"), __VA_ARGS__) // VC 2005+
//#define DEEP_TRACE(fmt, ...) _TRACE(PREFIX _T("|") fmt _T("\n") , ##__VA_ARGS__) // mingw
@@ -745,7 +741,7 @@ void wiimote::SetReportType(input_report type, bool continuous)
TYPE2NAME(IN_BUTTONS_ACCEL_EXT) :
TYPE2NAME(IN_BUTTONS_ACCEL_IR_EXT) :
TYPE2NAME(IN_BUTTONS_BALANCE_BOARD) :
- _T("(unknown??)");
+ _T("(unknown?)");
TRACE(_T("ReportType: %s (%s)"), name, (continuous ? _T("continuous") :
_T("non-continuous")));
#endif
@@ -2372,10 +2368,10 @@ unsigned __stdcall wiimote::SampleStreamThreadfunc(void* param)
// ------------------------------------------------------------------------------------
bool wiimote::Load16bitMonoSampleWAV(const TCHAR* filepath, wiimote_sample &out)
{
+ out = {};
// converts unsigned 16bit mono .wav audio data to the 4bit ADPCM variant
// used by the Wiimote (at least the closest match so far), and returns
// the data in a BYTE array (caller must delete[] it when no longer needed):
- memset(&out, 0, sizeof(out));
TRACE(_T("Loading '%s'"), filepath);
@@ -2543,10 +2539,10 @@ bool wiimote::Load16BitMonoSampleRAW(const TCHAR* filepath,
speaker_freq freq,
wiimote_sample &out)
{
+ out = {};
// converts (.wav style) unsigned 16bit mono raw data to the 4bit ADPCM variant
// used by the Wiimote, and returns the data in a BYTE array (caller must
// delete[] it when no longer needed):
- memset(&out, 0, sizeof(out));
// get the length of the file
struct _stat file_info;
@@ -2564,12 +2560,11 @@ bool wiimote::Load16BitMonoSampleRAW(const TCHAR* filepath,
unsigned total_samples = (len + 1) / 2; // round up just in case file is corrupt
// allocate a buffer to hold the samples to convert
- short *samples = new short[total_samples];
- _ASSERT(samples);
- if (!samples) {
+ if (!total_samples) {
TRACE(_T("Couldn't open '%s"), filepath);
return false;
}
+ short *samples = new short[total_samples];
// load them
FILE *file;
@@ -2608,10 +2603,11 @@ bool wiimote::Convert16bitMonoSamples(const short* samples,
speaker_freq freq,
wiimote_sample &out)
{
+ out = {};
+
// converts 16bit mono sample data to the native 4bit format used by the Wiimote,
// and returns the data in a BYTE array (caller must delete[] when no
// longer needed):
- memset(&out, 0, sizeof(0));
_ASSERT(samples && length);
if (!samples || !length)
@@ -2815,3 +2811,6 @@ void wiimote::StopRecording()
}
// ------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------
+
+#include "warns-end.hpp"
+
diff --git a/tracker-wii/wiiyourself/wiimote.h b/tracker-wii/wiiyourself/wiimote.h
index 3588b7c7..dac949c7 100644
--- a/tracker-wii/wiiyourself/wiimote.h
+++ b/tracker-wii/wiiyourself/wiimote.h
@@ -10,15 +10,15 @@
#pragma once
+#include "warns-begin.hpp"
+
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <tchar.h> // auto Unicode/Ansi support
#include <queue> // for HID write method
#include <list> // for state recording
-#ifndef QWORD
- typedef unsigned __int64 QWORD;
-#endif
+typedef unsigned __int64 QWORD;
#ifdef _MSC_VER // VC-specific: _DEBUG build only _ASSERT() sanity checks
# include <crtdbg.h>
@@ -181,7 +181,7 @@ class wiimote : public wiimote_state
// get the frequency from speaker_freq enum
static const unsigned FreqLookup [TOTAL_FREQUENCIES];
- static const unsigned GetFreqLookup (unsigned index)
+ static unsigned GetFreqLookup(unsigned index)
{
_ASSERT(index < TOTAL_FREQUENCIES);
if(index >= TOTAL_FREQUENCIES)
@@ -486,3 +486,5 @@ volatile int MotionPlusDetectCount; // waiting for the result
unsigned ExtTriggerFlags;// extension changes "
} Recording;
};
+
+#include "warns-end.hpp"
diff --git a/tracker-wii/wiiyourself/wiimote_common.h b/tracker-wii/wiiyourself/wiimote_common.h
index c0fd01e1..9934d6ec 100644
--- a/tracker-wii/wiiyourself/wiimote_common.h
+++ b/tracker-wii/wiiyourself/wiimote_common.h
@@ -1,3 +1,5 @@
+#pragma once
+
// _______________________________________________________________________________
//
// - WiiYourself! - native C++ Wiimote library v1.15 RC