[Nrage-input] Code cleanup

- Defined NOMINMAX macro to disable windef.h's min/max macros; they were clashing with the C++ standard library's std::min/std::max.
- All uses of min/max that had ambiguous type deduction were explicitly instantiated as min<long> and max<long>.
- Header includes were sorted

Many thanks to DKO for the patch.
This commit is contained in:
oddMLan 2020-02-09 04:25:05 -07:00
parent 088dc17556
commit 891e43878b
15 changed files with 73 additions and 53 deletions

View File

@ -21,8 +21,9 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "commonIncludes.h"
#include <windows.h>
#include "commonIncludes.h"
#include "FileAccess.h"
bool bDebug = true;

View File

@ -21,16 +21,21 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <algorithm>
#include <math.h>
#include <InitGuid.h>
#include "commonIncludes.h"
#include <CGuid.h>
#include <dinput.h>
#include "commonIncludes.h"
#include "DirectInput.h"
#include "NRagePluginV2.h"
#include "PakIO.h"
#include "DirectInput.h"
#include "XInputController.h"
#include <math.h>
#include <CGuid.h>
using std::min;
using std::max;
// ProtoTypes //
HRESULT AcquireDevice( LPDIRECTINPUTDEVICE8 lpDirectInputDevice );
@ -377,7 +382,7 @@ bool GetNControllerInput ( const int indexController, LPDWORD pdwData )
{
if( pcController->wAxeBuffer[i] < MAXAXISVALUE )
{
l_Value = pcController->wAxeBuffer[i] = min(( pcController->wAxeBuffer[i] + N64DIVIDER*3), MAXAXISVALUE );
l_Value = pcController->wAxeBuffer[i] = min<long>(( pcController->wAxeBuffer[i] + N64DIVIDER*3), MAXAXISVALUE );
}
else
l_Value = MAXAXISVALUE;
@ -386,7 +391,7 @@ bool GetNControllerInput ( const int indexController, LPDWORD pdwData )
{
if( pcController->wAxeBuffer[i] < MAXAXISVALUE )
{
l_Value = pcController->wAxeBuffer[i] = min(( pcController->wAxeBuffer[i] * 2 + N64DIVIDER*5 ), MAXAXISVALUE );
l_Value = pcController->wAxeBuffer[i] = min<long>(( pcController->wAxeBuffer[i] * 2 + N64DIVIDER*5 ), MAXAXISVALUE );
}
else
l_Value = MAXAXISVALUE;
@ -430,7 +435,7 @@ bool GetNControllerInput ( const int indexController, LPDWORD pdwData )
// wAxeBuffer is negative for axes 1 and 2 if buffer remains, else zero
if(( pcController->bMouseMoveX == MM_ABS && i < 2 ) || ( pcController->bMouseMoveY == MM_ABS && i > 1 ))
pcController->wAxeBuffer[i] = min( max( MINAXISVALUE, pcController->wAxeBuffer[i]) , MAXAXISVALUE);
pcController->wAxeBuffer[i] = min<long>( max<long>( MINAXISVALUE, pcController->wAxeBuffer[i]) , MAXAXISVALUE);
else if (( pcController->bMouseMoveX == MM_BUFF && i < 2 ) || ( pcController->bMouseMoveY == MM_BUFF && i > 1 ))
pcController->wAxeBuffer[i] = pcController->wAxeBuffer[i] * MOUSEBUFFERDECAY / 100;
else // "deadpan" mouse
@ -542,14 +547,14 @@ bool GetNControllerInput ( const int indexController, LPDWORD pdwData )
double dRel = MAXAXISVALUE / dRangeDiagonal;
*pdwData = MAKELONG(w_Buttons,
MAKEWORD( (BYTE)(min( max( MINAXISVALUE, (long)(lAxisValueX * d_ModifierX * dRel )), MAXAXISVALUE) / N64DIVIDER ),
(BYTE)(min( max( MINAXISVALUE, (long)(lAxisValueY * d_ModifierY * dRel )), MAXAXISVALUE) / N64DIVIDER )));
MAKEWORD( (BYTE)(min<long>( max<long>( MINAXISVALUE, (long)(lAxisValueX * d_ModifierX * dRel )), MAXAXISVALUE) / N64DIVIDER ),
(BYTE)(min<long>( max<long>( MINAXISVALUE, (long)(lAxisValueY * d_ModifierY * dRel )), MAXAXISVALUE) / N64DIVIDER )));
}
else
{
*pdwData = MAKELONG(w_Buttons,
MAKEWORD( (BYTE)(min( max( MINAXISVALUE, (long)(lAxisValueX * d_ModifierX )), MAXAXISVALUE) / N64DIVIDER ),
(BYTE)(min( max( MINAXISVALUE, (long)(lAxisValueY * d_ModifierY )), MAXAXISVALUE) / N64DIVIDER )));
MAKEWORD( (BYTE)(min<long>( max<long>( MINAXISVALUE, (long)(lAxisValueX * d_ModifierX )), MAXAXISVALUE) / N64DIVIDER ),
(BYTE)(min<long>( max<long>( MINAXISVALUE, (long)(lAxisValueY * d_ModifierY )), MAXAXISVALUE) / N64DIVIDER )));
}
return true;
@ -887,7 +892,7 @@ bool CreateEffectHandle( HWND hWnd, LPDIRECTINPUTDEVICE8 lpDirectInputDevice, LP
if( nAxes == 0 )
return false;
nAxes = min( nAxes, 2 );
nAxes = min<long>( nAxes, 2 );
// Must be unaquired for setting stuff like Co-op Level

View File

@ -26,6 +26,8 @@
#include <dinput.h>
#include "NRagePluginV2.h"
extern LPDIRECTINPUT8 g_pDIHandle;

View File

@ -21,18 +21,21 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "commonIncludes.h"
#include <string>
#include <stdio.h>
#include <windows.h>
#include <CommDlg.h>
#include <tchar.h>
#include <stdio.h>
#include <shlobj.h>
#include <tchar.h>
#include "commonIncludes.h"
#include "DirectInput.h"
#include "FileAccess.h"
#include "Interface.h"
#include "NRagePluginV2.h"
#include "PakIO.h"
#include "Interface.h"
#include "FileAccess.h"
#include "DirectInput.h"
#include <string>
using std::string;
#ifndef IDR_PROFILE_DEFAULT1

View File

@ -24,9 +24,11 @@
#ifndef _FILEACCESS_H_
#define _FILEACCESS_H_
#include <string>
#include "NRagePluginV2.h"
#include "Version.h"
#include <string>
using std::string;
bool GetDirectory( LPTSTR pszDirectory, WORD wDirID );

View File

@ -10,11 +10,12 @@
**
*/
#include "commonIncludes.h"
#include <windows.h>
#include "commonIncludes.h"
#include "GBCart.h"
#include "NRagePluginV2.h"
#include "PakIO.h"
#include "GBCart.h"
void ClearData(BYTE *Data, int Length);

View File

@ -1,9 +1,10 @@
#ifndef _GBCART_H_
#define _GBCART_H_
#include <windows.h>
#include <time.h>
#include <windows.h>
typedef struct _gbCartRTC {
UINT mapperSeconds;
UINT mapperMinutes;

View File

@ -21,18 +21,20 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "commonIncludes.h"
#include <stdio.h>
#include <windows.h>
#include <Commctrl.h>
#include <stdio.h>
#include "NRagePluginV2.h"
#include "commonIncludes.h"
#include "DirectInput.h"
#include "XInputController.h"
#include "FileAccess.h"
#include "PakIO.h"
#include "Interface.h"
#include "International.h"
#include "NRagePluginV2.h"
#include "PakIO.h"
#include "Version.h"
#include "XInputController.h"
// Prototypes //
BOOL CALLBACK ControllerTabProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam );

View File

@ -23,12 +23,14 @@
// Internationalization routines go in this file.
#include "International.h"
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <stdlib.h>
#include "debug.h"
#include <windows.h>
#include <tchar.h>
#include "International.h"
#include "Debug.h"
LANGID GetNTDLLNativeLangID();
BOOL IsHongKongVersion();

View File

@ -21,9 +21,10 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "settings.h"
#include <windows.h>
#include "settings.h"
#ifndef _NRINTERNATIONAL_
#define _NRINTERNATIONAL_

View File

@ -21,11 +21,13 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "commonIncludes.h"
#include <windows.h>
#include <Commctrl.h>
#include <dinput.h>
#include <Xinput.h>
#include "commonIncludes.h"
#include "NRagePluginV2.h"
#include "Interface.h"
#include "FileAccess.h"

View File

@ -24,6 +24,7 @@
#define _NRAGEPLUGIN_
#include <dinput.h>
#include "XInputController.h"
/////////////////////////////////////////////////////////////////////////////////

View File

@ -21,17 +21,23 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "commonIncludes.h"
#include <algorithm>
#include <stdio.h>
#include <windows.h>
#include <Commctrl.h>
#include <tchar.h>
#include <stdio.h>
#include "NRagePluginV2.h"
#include "commonIncludes.h"
#include "DirectInput.h"
#include "Interface.h"
#include "FileAccess.h"
#include "PakIO.h"
#include "GBCart.h"
#include "Interface.h"
#include "NRagePluginV2.h"
#include "PakIO.h"
using std::min;
using std::max;
// ProtoTypes
BYTE AddressCRC( const unsigned char * Address );

View File

@ -170,16 +170,4 @@ typedef struct _ADAPTOIDPAK
bool fRumblePak;
} ADAPTOIDPAK, *LPADAPTOIDPAK;
/*
* <windef.h> from under <windows.h> with MSVC defines these macros.
* For some reason, they are unavailable with MinGW's copy of <windows.h>.
*/
#ifndef max
#define max(a, b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef min
#define min(a, b) (((a) < (b)) ? (a) : (b))
#endif
#endif // #ifndef _PAKIO_H_

View File

@ -24,11 +24,14 @@
#ifndef _COMMONINCLUDES_H_
#define _COMMONINCLUDES_H_
/*
#undef WIN32_LEAN_AND_MEAN
#pragma warning(disable:4201)
*/
#include <tchar.h>
#include "settings.h"
#include <tchar.h>
#include "resource.h"
#include "Debug.h"