- this means that dinput and dsound is not removed but is disabled,
making it easier to compile with Dev-C++ and stock MSVS, this may have
bad consequences (some people swear by -dinput, and dsound was used by
default unless -wavonly was specified, so this is a behavior change)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8118
d7cf8633-e32d-0410-b094-
e92efae38249
#include "quakedef.h"
#include "snd_main.h"
#include "quakedef.h"
#include "snd_main.h"
#ifndef DIRECTSOUND_VERSION
# define DIRECTSOUND_VERSION 0x0500 /* Version 5.0 */
#endif
#ifndef DIRECTSOUND_VERSION
# define DIRECTSOUND_VERSION 0x0500 /* Version 5.0 */
#endif
#include <windows.h>
#include <mmsystem.h>
#include <windows.h>
#include <mmsystem.h>
// ==============================================================================
// ==============================================================================
HRESULT (WINAPI *pDirectSoundCreate)(GUID FAR *lpGUID, LPDIRECTSOUND FAR *lplpDS, IUnknown FAR *pUnkOuter);
HRESULT (WINAPI *pDirectSoundCreate)(GUID FAR *lpGUID, LPDIRECTSOUND FAR *lplpDS, IUnknown FAR *pUnkOuter);
// Wave output: 64KB in 64 buffers of 1KB
// (64KB is > 1 sec at 16-bit 22050 Hz mono, and is 1/3 sec at 16-bit 44100 Hz stereo)
// Wave output: 64KB in 64 buffers of 1KB
// (64KB is > 1 sec at 16-bit 22050 Hz mono, and is 1/3 sec at 16-bit 44100 Hz stereo)
typedef enum sndinitstat_e {SIS_SUCCESS, SIS_FAILURE, SIS_NOTAVAIL} sndinitstat;
typedef enum sndinitstat_e {SIS_SUCCESS, SIS_FAILURE, SIS_NOTAVAIL} sndinitstat;
static qboolean dsound_init;
static qboolean dsound_init;
-static qboolean wav_init;
+static unsigned int dsound_time;
static qboolean primary_format_set;
static qboolean primary_format_set;
+#endif
+
+static qboolean wav_init;
static int snd_sent, snd_completed;
static int prev_painted;
static unsigned int paintpot;
static int snd_sent, snd_completed;
static int prev_painted;
static unsigned int paintpot;
-static unsigned int dsound_time;
LPDIRECTSOUND pDS;
LPDIRECTSOUNDBUFFER pDSBuf, pDSPBuf;
HINSTANCE hInstDS;
LPDIRECTSOUND pDS;
LPDIRECTSOUNDBUFFER pDSBuf, pDSPBuf;
HINSTANCE hInstDS;
qboolean SNDDMA_InitWav (void);
qboolean SNDDMA_InitWav (void);
sndinitstat SNDDMA_InitDirect (void);
sndinitstat SNDDMA_InitDirect (void);
/*
==================
SndSys_InitDirectSound
/*
==================
SndSys_InitDirectSound
*/
qboolean SndSys_Init (const snd_format_t* requested, snd_format_t* suggested)
{
*/
qboolean SndSys_Init (const snd_format_t* requested, snd_format_t* suggested)
{
sndinitstat stat;
Con_Print ("SndSys_Init: using the Win32 module\n");
sndinitstat stat;
Con_Print ("SndSys_Init: using the Win32 module\n");
// COMMANDLINEOPTION: Windows Sound: -wavonly uses wave sound instead of DirectSound
wavonly = (COM_CheckParm ("-wavonly") != 0);
dsound_init = false;
// COMMANDLINEOPTION: Windows Sound: -wavonly uses wave sound instead of DirectSound
wavonly = (COM_CheckParm ("-wavonly") != 0);
dsound_init = false;
wav_init = false;
stat = SIS_FAILURE; // assume DirectSound won't initialize
wav_init = false;
stat = SIS_FAILURE; // assume DirectSound won't initialize
// Init DirectSound
if (!wavonly)
{
// Init DirectSound
if (!wavonly)
{
else
Con_Print("DirectSound failed to init\n");
}
else
Con_Print("DirectSound failed to init\n");
}
// if DirectSound didn't succeed in initializing, try to initialize
// waveOut sound, unless DirectSound failed because the hardware is
// already allocated (in which case the user has already chosen not
// to have sound)
// if DirectSound didn't succeed in initializing, try to initialize
// waveOut sound, unless DirectSound failed because the hardware is
// already allocated (in which case the user has already chosen not
// to have sound)
if (!dsound_init && (stat != SIS_NOTAVAIL))
if (!dsound_init && (stat != SIS_NOTAVAIL))
{
if (SndSys_InitMmsystem (requested))
Con_Print("Wave sound (MMSYSTEM) initialized\n");
{
if (SndSys_InitMmsystem (requested))
Con_Print("Wave sound (MMSYSTEM) initialized\n");
Con_Print("Wave sound failed to init\n");
}
Con_Print("Wave sound failed to init\n");
}
return (dsound_init || wav_init);
return (dsound_init || wav_init);
+#else
+ return wav_init;
+#endif
*/
void SndSys_Shutdown (void)
{
*/
void SndSys_Shutdown (void)
{
if (pDSBuf)
{
IDirectSoundBuffer_Stop(pDSBuf);
if (pDSBuf)
{
IDirectSoundBuffer_Stop(pDSBuf);
IDirectSound_SetCooperativeLevel (pDS, mainwindow, DSSCL_NORMAL);
IDirectSound_Release(pDS);
}
IDirectSound_SetCooperativeLevel (pDS, mainwindow, DSSCL_NORMAL);
IDirectSound_Release(pDS);
}
snd_renderbuffer = NULL;
}
snd_renderbuffer = NULL;
}
pDS = NULL;
pDSBuf = NULL;
pDSPBuf = NULL;
pDS = NULL;
pDSBuf = NULL;
pDSPBuf = NULL;
+ dsound_init = false;
+#endif
hWaveOut = 0;
hData = 0;
hWaveHdr = 0;
lpData = NULL;
lpWaveHdr = NULL;
hWaveOut = 0;
hData = 0;
hWaveHdr = 0;
lpData = NULL;
lpWaveHdr = NULL;
factor = snd_renderbuffer->format.width * snd_renderbuffer->format.channels;
factor = snd_renderbuffer->format.width * snd_renderbuffer->format.channels;
if (dsound_init)
{
DWORD dwTime;
if (dsound_init)
{
DWORD dwTime;
dsound_time += diff / factor;
return dsound_time;
}
dsound_time += diff / factor;
return dsound_time;
}
static DWORD dsound_dwSize;
static DWORD dsound_dwSize2;
static DWORD *dsound_pbuf;
static DWORD *dsound_pbuf2;
static DWORD dsound_dwSize;
static DWORD dsound_dwSize2;
static DWORD *dsound_pbuf;
static DWORD *dsound_pbuf2;
*/
qboolean SndSys_LockRenderBuffer (void)
{
*/
qboolean SndSys_LockRenderBuffer (void)
{
int reps;
HRESULT hresult;
DWORD dwStatus;
int reps;
HRESULT hresult;
DWORD dwStatus;
Sys_Error("SndSys_LockRenderBuffer: the ring address has changed!!!\n");
return true;
}
Sys_Error("SndSys_LockRenderBuffer: the ring address has changed!!!\n");
return true;
}
*/
void SndSys_UnlockRenderBuffer (void)
{
*/
void SndSys_UnlockRenderBuffer (void)
{
if (pDSBuf)
IDirectSoundBuffer_Unlock(pDSBuf, dsound_pbuf, dsound_dwSize, dsound_pbuf2, dsound_dwSize2);
if (pDSBuf)
IDirectSoundBuffer_Unlock(pDSBuf, dsound_pbuf, dsound_dwSize, dsound_pbuf2, dsound_dwSize2);
#include "quakedef.h"
#include <windows.h>
#include <mmsystem.h>
#include "quakedef.h"
#include <windows.h>
#include <mmsystem.h>
#include "errno.h"
#include "resource.h"
#include "conproc.h"
#include "errno.h"
#include "resource.h"
#include "conproc.h"
#include "quakedef.h"
#include <windows.h>
#include <mmsystem.h>
#include "quakedef.h"
#include <windows.h>
#include <mmsystem.h>
#include "resource.h"
#include <commctrl.h>
#include "resource.h"
#include <commctrl.h>
extern HINSTANCE global_hInstance;
extern HINSTANCE global_hInstance;
static void IN_Activate (qboolean grab);
static qboolean mouseinitialized;
static void IN_Activate (qboolean grab);
static qboolean mouseinitialized;
-static qboolean dinput;
-
-// input code
+#ifdef SUPPORTDIRECTX
+static qboolean dinput;
#define DINPUT_BUFFERSIZE 16
#define iDirectInputCreate(a,b,c,d) pDirectInputCreate(a,b,c,d)
static HRESULT (WINAPI *pDirectInputCreate)(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUT * lplpDirectInput, LPUNKNOWN punkOuter);
#define DINPUT_BUFFERSIZE 16
#define iDirectInputCreate(a,b,c,d) pDirectInputCreate(a,b,c,d)
static HRESULT (WINAPI *pDirectInputCreate)(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUT * lplpDirectInput, LPUNKNOWN punkOuter);
// LordHavoc: thanks to backslash for this support for mouse buttons 4 and 5
/* backslash :: imouse explorer buttons */
// LordHavoc: thanks to backslash for this support for mouse buttons 4 and 5
/* backslash :: imouse explorer buttons */
static int mouse_oldbuttonstate;
static unsigned int uiWheelMessage;
static int mouse_oldbuttonstate;
static unsigned int uiWheelMessage;
static qboolean dinput_acquired;
static unsigned int mstate_di;
static qboolean dinput_acquired;
static unsigned int mstate_di;
// joystick defines and variables
// where should defines be moved?
// joystick defines and variables
// where should defines be moved?
static DWORD joy_flags;
static DWORD joy_numbuttons;
static DWORD joy_flags;
static DWORD joy_numbuttons;
static LPDIRECTINPUT g_pdi;
static LPDIRECTINPUTDEVICE g_pMouse;
static LPDIRECTINPUT g_pdi;
static LPDIRECTINPUTDEVICE g_pMouse;
+static HINSTANCE hInstDI;
+#endif
-static HINSTANCE hInstDI;
-
// forward-referenced functions
static void IN_StartupJoystick (void);
static void Joy_AdvancedUpdate_f (void);
// forward-referenced functions
static void IN_StartupJoystick (void);
static void Joy_AdvancedUpdate_f (void);
if (wParam & MK_XBUTTON7)
temp |= 512;
if (wParam & MK_XBUTTON7)
temp |= 512;
if (vid_usingmouse && !dinput_acquired)
if (vid_usingmouse && !dinput_acquired)
+#else
+ if (vid_usingmouse)
+#endif
{
// perform button actions
int i;
{
// perform button actions
int i;
{
vid_usingmouse = true;
cl_ignoremousemoves = 2;
{
vid_usingmouse = true;
cl_ignoremousemoves = 2;
if (dinput && g_pMouse)
{
IDirectInputDevice_Acquire(g_pMouse);
dinput_acquired = true;
}
else
if (dinput && g_pMouse)
{
IDirectInputDevice_Acquire(g_pMouse);
dinput_acquired = true;
}
else
{
RECT window_rect;
window_rect.left = window_x;
{
RECT window_rect;
window_rect.left = window_x;
{
vid_usingmouse = false;
cl_ignoremousemoves = 2;
{
vid_usingmouse = false;
cl_ignoremousemoves = 2;
if (dinput_acquired)
{
IDirectInputDevice_Unacquire(g_pMouse);
dinput_acquired = false;
}
else
if (dinput_acquired)
{
IDirectInputDevice_Unacquire(g_pMouse);
dinput_acquired = false;
}
else
{
// restore system mouseparms if we changed them
if (restore_spi)
{
// restore system mouseparms if we changed them
if (restore_spi)
/*
===========
IN_InitDInput
/*
===========
IN_InitDInput
// COMMANDLINEOPTION: Windows Input: -dinput enables DirectInput for mouse/joystick input
if (COM_CheckParm ("-dinput"))
dinput = IN_InitDInput ();
// COMMANDLINEOPTION: Windows Input: -dinput enables DirectInput for mouse/joystick input
if (COM_CheckParm ("-dinput"))
dinput = IN_InitDInput ();
Con_Print("DirectInput initialized\n");
else
Con_Print("DirectInput not initialized\n");
Con_Print("DirectInput initialized\n");
else
Con_Print("DirectInput not initialized\n");
*/
static void IN_MouseMove (void)
{
*/
static void IN_MouseMove (void)
{
POINT current_pos;
if (!vid_usingmouse)
POINT current_pos;
if (!vid_usingmouse)
DIDEVICEOBJECTDATA od;
DWORD dwElements;
HRESULT hr;
DIDEVICEOBJECTDATA od;
DWORD dwElements;
HRESULT hr;
{
GetCursorPos (¤t_pos);
mx = current_pos.x - (window_x + vid.width / 2);
{
GetCursorPos (¤t_pos);
mx = current_pos.x - (window_x + vid.width / 2);
if (g_pMouse)
IDirectInputDevice_Release(g_pMouse);
g_pMouse = NULL;
if (g_pMouse)
IDirectInputDevice_Release(g_pMouse);
g_pMouse = NULL;
if (g_pdi)
IDirectInput_Release(g_pdi);
g_pdi = NULL;
if (g_pdi)
IDirectInput_Release(g_pdi);
g_pdi = NULL;