Skip to content

Commit

Permalink
[Nrage-input] Code cleanup
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
oddMLan committed Feb 9, 2020
1 parent 088dc17 commit 891e438
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 53 deletions.
3 changes: 2 additions & 1 deletion Source/nragev20/Debug.cpp
Expand Up @@ -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;
Expand Down
29 changes: 17 additions & 12 deletions Source/nragev20/DirectInput.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Source/nragev20/DirectInput.h
Expand Up @@ -26,6 +26,8 @@

#include <dinput.h>

#include "NRagePluginV2.h"

extern LPDIRECTINPUT8 g_pDIHandle;


Expand Down
17 changes: 10 additions & 7 deletions Source/nragev20/FileAccess.cpp
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion Source/nragev20/FileAccess.h
Expand Up @@ -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 );
Expand Down
5 changes: 3 additions & 2 deletions Source/nragev20/GBCart.cpp
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion Source/nragev20/GBCart.h
@@ -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;
Expand Down
12 changes: 7 additions & 5 deletions Source/nragev20/Interface.cpp
Expand Up @@ -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 );
Expand Down
10 changes: 6 additions & 4 deletions Source/nragev20/International.cpp
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion Source/nragev20/International.h
Expand Up @@ -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_

Expand Down
4 changes: 3 additions & 1 deletion Source/nragev20/NRagePluginV2.cpp
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions Source/nragev20/NRagePluginV2.h
Expand Up @@ -24,6 +24,7 @@
#define _NRAGEPLUGIN_

#include <dinput.h>

#include "XInputController.h"

/////////////////////////////////////////////////////////////////////////////////
Expand Down
16 changes: 11 additions & 5 deletions Source/nragev20/PakIO.cpp
Expand Up @@ -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 );
Expand Down
12 changes: 0 additions & 12 deletions Source/nragev20/PakIO.h
Expand Up @@ -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_
5 changes: 4 additions & 1 deletion Source/nragev20/commonIncludes.h
Expand Up @@ -24,11 +24,14 @@
#ifndef _COMMONINCLUDES_H_
#define _COMMONINCLUDES_H_

/*
#undef WIN32_LEAN_AND_MEAN
#pragma warning(disable:4201)
*/

#include "settings.h"
#include <tchar.h>

#include "settings.h"
#include "resource.h"
#include "Debug.h"

Expand Down

0 comments on commit 891e438

Please sign in to comment.