2001-02-19 21:15:25 +00:00
|
|
|
/*
|
|
|
|
cd_win.c
|
|
|
|
|
2001-05-20 20:52:27 +00:00
|
|
|
support for cd in windows
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2001-04-09 21:15:09 +00:00
|
|
|
#include "QF/cdaudio.h"
|
2001-03-27 23:36:02 +00:00
|
|
|
#include "QF/cmd.h"
|
|
|
|
#include "QF/cvar.h"
|
|
|
|
#include "QF/qargs.h"
|
2001-04-09 21:15:09 +00:00
|
|
|
#include "QF/sound.h"
|
2001-09-21 04:22:46 +00:00
|
|
|
#include "QF/sys.h"
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2012-02-13 12:58:34 +00:00
|
|
|
#include "QF/plugin/general.h"
|
|
|
|
#include "QF/plugin/cd.h"
|
|
|
|
|
2001-06-01 22:55:33 +00:00
|
|
|
#include "compat.h"
|
2021-03-27 11:09:37 +00:00
|
|
|
#include "context_win.h"
|
2001-06-01 22:55:33 +00:00
|
|
|
|
2012-05-21 23:23:22 +00:00
|
|
|
static plugin_t plugin_info;
|
|
|
|
static plugin_data_t plugin_info_data;
|
|
|
|
static plugin_funcs_t plugin_info_funcs;
|
|
|
|
static general_data_t plugin_info_general_data;
|
|
|
|
static general_funcs_t plugin_info_general_funcs;
|
2001-08-31 00:16:31 +00:00
|
|
|
static cd_funcs_t plugin_info_cd_funcs;
|
2001-06-01 22:55:33 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
static qboolean cdValid = false;
|
|
|
|
static qboolean playing = false;
|
|
|
|
static qboolean wasPlaying = false;
|
|
|
|
static qboolean initialized = false;
|
|
|
|
static qboolean enabled = false;
|
|
|
|
static qboolean playLooping = false;
|
|
|
|
static float cdvolume;
|
|
|
|
static byte remap[100];
|
|
|
|
static byte playTrack;
|
|
|
|
static byte maxTrack;
|
|
|
|
|
2001-08-31 00:16:31 +00:00
|
|
|
static UINT wDeviceID;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-10-12 19:26:56 +00:00
|
|
|
static void I_CDAudio_Play (int track, qboolean looping);
|
2001-08-31 00:16:31 +00:00
|
|
|
static void I_CDAudio_Stop (void);
|
2001-02-19 21:15:25 +00:00
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
static float bgmvolume;
|
|
|
|
static cvar_t bgmvolume_cvar = {
|
|
|
|
.name = "bgmvolume",
|
|
|
|
.description =
|
|
|
|
"Volume of CD music",
|
|
|
|
.default_value = "1",
|
|
|
|
.flags = CVAR_ARCHIVE,
|
|
|
|
.value = { .type = &cexpr_float, .value = &bgmvolume },
|
|
|
|
};
|
2001-08-27 01:00:03 +00:00
|
|
|
|
2004-02-07 05:35:15 +00:00
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
static void
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_CloseDoor (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
DWORD dwReturn;
|
|
|
|
|
2001-06-01 22:55:33 +00:00
|
|
|
dwReturn =
|
2007-04-04 07:48:14 +00:00
|
|
|
mciSendCommand (wDeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, (DWORD_PTR) NULL);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (dwReturn) {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_snd, "MCI_SET_DOOR_CLOSED failed (%li)\n",
|
2010-11-23 05:09:30 +00:00
|
|
|
dwReturn);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Eject (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
DWORD dwReturn;
|
|
|
|
|
2001-06-01 22:55:33 +00:00
|
|
|
dwReturn = mciSendCommand (wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN,
|
2007-04-04 07:48:14 +00:00
|
|
|
(DWORD_PTR) NULL);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (dwReturn) {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_snd, "MCI_SET_DOOR_OPEN failed (%li)\n", dwReturn);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_GetAudioDiskInfo (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
DWORD dwReturn;
|
|
|
|
MCI_STATUS_PARMS mciStatusParms;
|
|
|
|
|
|
|
|
cdValid = false;
|
|
|
|
|
|
|
|
mciStatusParms.dwItem = MCI_STATUS_READY;
|
|
|
|
dwReturn =
|
|
|
|
mciSendCommand (wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT,
|
2007-04-04 07:48:14 +00:00
|
|
|
(DWORD_PTR) (LPVOID) & mciStatusParms);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (dwReturn) {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_snd,
|
2010-11-23 05:09:30 +00:00
|
|
|
"CDAudio: drive ready test - get status failed\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!mciStatusParms.dwReturn) {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_snd, "CDAudio: drive not ready\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
mciStatusParms.dwItem = MCI_STATUS_NUMBER_OF_TRACKS;
|
|
|
|
dwReturn =
|
|
|
|
mciSendCommand (wDeviceID, MCI_STATUS, MCI_STATUS_ITEM | MCI_WAIT,
|
2007-04-04 07:48:14 +00:00
|
|
|
(DWORD_PTR) (LPVOID) & mciStatusParms);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (dwReturn) {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_snd, "CDAudio: get tracks - status failed\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (mciStatusParms.dwReturn < 1) {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_snd, "CDAudio: no music tracks\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cdValid = true;
|
|
|
|
maxTrack = mciStatusParms.dwReturn;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-09-30 13:05:20 +00:00
|
|
|
#if 0
|
2001-06-01 22:55:33 +00:00
|
|
|
LONG
|
2001-08-31 00:05:58 +00:00
|
|
|
static I_CDAudio_MessageHandler (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
2001-06-01 22:55:33 +00:00
|
|
|
{
|
|
|
|
if (lParam != wDeviceID)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
switch (wParam) {
|
|
|
|
case MCI_NOTIFY_SUCCESSFUL:
|
|
|
|
if (playing) {
|
|
|
|
playing = false;
|
|
|
|
if (playLooping)
|
|
|
|
I_CDAudio_Play (playTrack, true);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MCI_NOTIFY_ABORTED:
|
|
|
|
case MCI_NOTIFY_SUPERSEDED:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MCI_NOTIFY_FAILURE:
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_snd, "MCI_NOTIFY_FAILURE\n");
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Stop ();
|
|
|
|
cdValid = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_snd, "Unexpected MM_MCINOTIFY type (%i)\n",
|
2010-11-23 05:09:30 +00:00
|
|
|
wParam);
|
2001-06-01 22:55:33 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2001-09-30 13:05:20 +00:00
|
|
|
#endif
|
2001-06-01 22:55:33 +00:00
|
|
|
|
2001-08-31 00:05:58 +00:00
|
|
|
static void
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Pause (void)
|
|
|
|
{
|
|
|
|
DWORD dwReturn;
|
|
|
|
MCI_GENERIC_PARMS mciGenericParms;
|
|
|
|
|
|
|
|
if (!enabled)
|
|
|
|
return;
|
|
|
|
if (!playing)
|
|
|
|
return;
|
|
|
|
|
2021-03-27 11:09:37 +00:00
|
|
|
mciGenericParms.dwCallback = (DWORD_PTR) win_mainwindow;
|
2001-06-01 22:55:33 +00:00
|
|
|
dwReturn =
|
|
|
|
mciSendCommand (wDeviceID, MCI_PAUSE, 0,
|
2007-04-04 07:48:14 +00:00
|
|
|
(DWORD_PTR) (LPVOID) & mciGenericParms);
|
2001-06-01 22:55:33 +00:00
|
|
|
if (dwReturn) {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_snd, "MCI_PAUSE failed (%li)", dwReturn);
|
2001-06-01 22:55:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wasPlaying = playing;
|
|
|
|
playing = false;
|
|
|
|
}
|
|
|
|
|
2001-08-31 00:05:58 +00:00
|
|
|
static void
|
2001-10-12 19:26:56 +00:00
|
|
|
I_CDAudio_Play (int track, qboolean looping)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
DWORD dwReturn;
|
|
|
|
MCI_PLAY_PARMS mciPlayParms;
|
|
|
|
MCI_STATUS_PARMS mciStatusParms;
|
|
|
|
|
|
|
|
if (!enabled)
|
|
|
|
return;
|
|
|
|
if (!cdValid) {
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_GetAudioDiskInfo ();
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!cdValid)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-11-06 02:21:00 +00:00
|
|
|
if (track < 0 || track >= (int) sizeof (remap)) {
|
- add some missing boundschecking to CDAudio_Play's track remap (in
specific plugins only)
- convert updateping, updatepl, updateentertime, updatestat,
updatestatlong, cdtrack intermission, finale, muzzleflashchokecount,
maxspeed, entgravity, and setpause on the client. Can you say all
that in one breath? :)
2001-11-05 16:17:45 +00:00
|
|
|
Sys_Printf ("CDAudio: invalid track number\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-02-19 21:15:25 +00:00
|
|
|
track = remap[track];
|
|
|
|
|
|
|
|
if (track < 1 || track > maxTrack) {
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Stop ();
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// don't try to play a non-audio track
|
|
|
|
mciStatusParms.dwItem = MCI_CDA_STATUS_TYPE_TRACK;
|
|
|
|
mciStatusParms.dwTrack = track;
|
|
|
|
dwReturn =
|
|
|
|
mciSendCommand (wDeviceID, MCI_STATUS,
|
|
|
|
MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT,
|
2007-04-04 07:48:14 +00:00
|
|
|
(DWORD_PTR) (LPVOID) & mciStatusParms);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (dwReturn) {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_snd, "MCI_STATUS failed (%li)\n", dwReturn);
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (mciStatusParms.dwReturn != MCI_CDA_TRACK_AUDIO) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("CDAudio: track %i is not audio\n", track);
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// get the length of the track to be played
|
|
|
|
mciStatusParms.dwItem = MCI_STATUS_LENGTH;
|
|
|
|
mciStatusParms.dwTrack = track;
|
|
|
|
dwReturn =
|
|
|
|
mciSendCommand (wDeviceID, MCI_STATUS,
|
|
|
|
MCI_STATUS_ITEM | MCI_TRACK | MCI_WAIT,
|
2007-04-04 07:48:14 +00:00
|
|
|
(DWORD_PTR) (LPVOID) & mciStatusParms);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (dwReturn) {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_snd, "MCI_STATUS failed (%li)\n", dwReturn);
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (playing) {
|
|
|
|
if (playTrack == track)
|
|
|
|
return;
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Stop ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mciPlayParms.dwFrom = MCI_MAKE_TMSF (track, 0, 0, 0);
|
|
|
|
mciPlayParms.dwTo = (mciStatusParms.dwReturn << 8) | track;
|
2021-03-27 11:09:37 +00:00
|
|
|
mciPlayParms.dwCallback = (DWORD_PTR) win_mainwindow;
|
2001-02-19 21:15:25 +00:00
|
|
|
dwReturn =
|
|
|
|
mciSendCommand (wDeviceID, MCI_PLAY, MCI_NOTIFY | MCI_FROM | MCI_TO,
|
2007-04-04 07:48:14 +00:00
|
|
|
(DWORD_PTR) (LPVOID) & mciPlayParms);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (dwReturn) {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_snd, "CDAudio: MCI_PLAY failed (%li)\n", dwReturn);
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
playLooping = looping;
|
|
|
|
playTrack = track;
|
|
|
|
playing = true;
|
|
|
|
|
|
|
|
if (cdvolume == 0.0)
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Pause ();
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-08-31 00:05:58 +00:00
|
|
|
static void
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Resume (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
DWORD dwReturn;
|
2001-06-01 22:55:33 +00:00
|
|
|
MCI_PLAY_PARMS mciPlayParms;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (!enabled)
|
|
|
|
return;
|
2001-06-01 22:55:33 +00:00
|
|
|
if (!cdValid)
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
2001-06-01 22:55:33 +00:00
|
|
|
if (!wasPlaying)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mciPlayParms.dwFrom = MCI_MAKE_TMSF (playTrack, 0, 0, 0);
|
|
|
|
mciPlayParms.dwTo = MCI_MAKE_TMSF (playTrack + 1, 0, 0, 0);
|
2021-03-27 11:09:37 +00:00
|
|
|
mciPlayParms.dwCallback = (DWORD_PTR) win_mainwindow;
|
2001-06-01 22:55:33 +00:00
|
|
|
dwReturn =
|
|
|
|
mciSendCommand (wDeviceID, MCI_PLAY, MCI_TO | MCI_NOTIFY,
|
2007-04-04 07:48:14 +00:00
|
|
|
(DWORD_PTR) (LPVOID) & mciPlayParms);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (dwReturn) {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_snd, "CDAudio: MCI_PLAY failed (%li)\n", dwReturn);
|
2001-06-01 22:55:33 +00:00
|
|
|
return;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
2001-06-01 22:55:33 +00:00
|
|
|
playing = true;
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
|
2001-08-31 00:05:58 +00:00
|
|
|
static void
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Shutdown (void)
|
|
|
|
{
|
|
|
|
if (!initialized)
|
|
|
|
return;
|
|
|
|
I_CDAudio_Stop ();
|
2007-04-04 07:48:14 +00:00
|
|
|
if (mciSendCommand (wDeviceID, MCI_CLOSE, MCI_WAIT, (DWORD_PTR) NULL))
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_snd, "CDAudio_Shutdown: MCI_CLOSE failed\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-08-31 00:05:58 +00:00
|
|
|
static void
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Stop (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
DWORD dwReturn;
|
|
|
|
|
|
|
|
if (!enabled)
|
|
|
|
return;
|
|
|
|
if (!playing)
|
|
|
|
return;
|
|
|
|
|
2007-04-04 07:48:14 +00:00
|
|
|
dwReturn = mciSendCommand (wDeviceID, MCI_STOP, 0, (DWORD_PTR) NULL);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (dwReturn) {
|
2021-03-29 10:58:00 +00:00
|
|
|
Sys_MaskPrintf (SYS_snd, "MCI_STOP failed (%li)", dwReturn);
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
2001-06-01 22:55:33 +00:00
|
|
|
wasPlaying = false;
|
2001-02-19 21:15:25 +00:00
|
|
|
playing = false;
|
|
|
|
}
|
|
|
|
|
2001-08-31 00:05:58 +00:00
|
|
|
static void
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Update (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
if (!enabled)
|
|
|
|
return;
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
if (bgmvolume != cdvolume) {
|
2001-06-01 22:55:33 +00:00
|
|
|
if (cdvolume) {
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
bgmvolume = 0.0;
|
|
|
|
cdvolume = bgmvolume;
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Pause ();
|
|
|
|
} else {
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
bgmvolume = 1.0;
|
|
|
|
cdvolume = bgmvolume;
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Resume ();
|
|
|
|
}
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CD_f (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
2001-08-02 23:00:39 +00:00
|
|
|
const char *command;
|
2004-02-07 05:35:15 +00:00
|
|
|
int ret, n;
|
2001-02-19 21:15:25 +00:00
|
|
|
|
|
|
|
if (Cmd_Argc () < 2)
|
|
|
|
return;
|
|
|
|
|
|
|
|
command = Cmd_Argv (1);
|
|
|
|
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "on")) {
|
2001-02-19 21:15:25 +00:00
|
|
|
enabled = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "off")) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (playing)
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Stop ();
|
2001-02-19 21:15:25 +00:00
|
|
|
enabled = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "reset")) {
|
2001-02-19 21:15:25 +00:00
|
|
|
enabled = true;
|
|
|
|
if (playing)
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Stop ();
|
2001-02-19 21:15:25 +00:00
|
|
|
for (n = 0; n < 100; n++)
|
|
|
|
remap[n] = n;
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_GetAudioDiskInfo ();
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "remap")) {
|
2001-02-19 21:15:25 +00:00
|
|
|
ret = Cmd_Argc () - 2;
|
|
|
|
if (ret <= 0) {
|
|
|
|
for (n = 1; n < 100; n++)
|
|
|
|
if (remap[n] != n)
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf (" %u -> %u\n", n, remap[n]);
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (n = 1; n <= ret; n++)
|
|
|
|
remap[n] = atoi (Cmd_Argv (n + 1));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "close")) {
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_CloseDoor ();
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cdValid) {
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_GetAudioDiskInfo ();
|
2001-02-19 21:15:25 +00:00
|
|
|
if (!cdValid) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("No CD in player.\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "play")) {
|
2001-10-12 23:14:59 +00:00
|
|
|
I_CDAudio_Play (atoi (Cmd_Argv (2)), false);
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "loop")) {
|
2001-10-12 23:14:59 +00:00
|
|
|
I_CDAudio_Play (atoi (Cmd_Argv (2)), true);
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "stop")) {
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Stop ();
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "pause")) {
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Pause ();
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "resume")) {
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Resume ();
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "eject")) {
|
2001-02-19 21:15:25 +00:00
|
|
|
if (playing)
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Stop ();
|
|
|
|
I_CDAudio_Eject ();
|
2001-02-19 21:15:25 +00:00
|
|
|
cdValid = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-04-10 07:26:22 +00:00
|
|
|
if (strequal (command, "info")) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("%u tracks\n", maxTrack);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (playing)
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("Currently %s track %u\n",
|
2001-02-19 21:15:25 +00:00
|
|
|
playLooping ? "looping" : "playing", playTrack);
|
|
|
|
else if (wasPlaying)
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("Paused %s track %u\n",
|
2001-02-19 21:15:25 +00:00
|
|
|
playLooping ? "looping" : "playing", playTrack);
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("Volume is %f\n", cdvolume);
|
2001-02-19 21:15:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-31 00:05:58 +00:00
|
|
|
static void
|
2001-06-01 22:55:33 +00:00
|
|
|
I_CDAudio_Init (void)
|
2001-02-19 21:15:25 +00:00
|
|
|
{
|
|
|
|
DWORD dwReturn;
|
|
|
|
MCI_OPEN_PARMS mciOpenParms;
|
|
|
|
MCI_SET_PARMS mciSetParms;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
mciOpenParms.lpstrDeviceType = "cdaudio";
|
|
|
|
dwReturn =
|
|
|
|
mciSendCommand (0, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_SHAREABLE,
|
2007-04-04 07:48:14 +00:00
|
|
|
(DWORD_PTR) (LPVOID) & mciOpenParms);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (dwReturn) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("CDAudio_Init: MCI_OPEN failed (%li)\n", dwReturn);
|
2001-06-01 22:55:33 +00:00
|
|
|
return; // was -1
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
wDeviceID = mciOpenParms.wDeviceID;
|
|
|
|
|
|
|
|
// Set the time format to track/minute/second/frame (TMSF).
|
|
|
|
mciSetParms.dwTimeFormat = MCI_FORMAT_TMSF;
|
|
|
|
dwReturn =
|
|
|
|
mciSendCommand (wDeviceID, MCI_SET, MCI_SET_TIME_FORMAT,
|
2007-04-04 07:48:14 +00:00
|
|
|
(DWORD_PTR) (LPVOID) & mciSetParms);
|
2001-02-19 21:15:25 +00:00
|
|
|
if (dwReturn) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("MCI_SET_TIME_FORMAT failed (%li)\n", dwReturn);
|
2007-04-04 07:48:14 +00:00
|
|
|
mciSendCommand (wDeviceID, MCI_CLOSE, 0, (DWORD_PTR) NULL);
|
2001-06-01 22:55:33 +00:00
|
|
|
return; // was -1
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (n = 0; n < 100; n++)
|
|
|
|
remap[n] = n;
|
|
|
|
initialized = true;
|
|
|
|
enabled = true;
|
|
|
|
|
[cvar] Make cvars properly typed
This is an extremely extensive patch as it hits every cvar, and every
usage of the cvars. Cvars no longer store the value they control,
instead, they use a cexpr value object to reference the value and
specify the value's type (currently, a null type is used for strings).
Non-string cvars are passed through cexpr, allowing expressions in the
cvars' settings. Also, cvars have returned to an enhanced version of the
original (id quake) registration scheme.
As a minor benefit, relevant code having direct access to the
cvar-controlled variables is probably a slight optimization as it
removed a pointer dereference, and the variables can be located for data
locality.
The static cvar descriptors are made private as an additional safety
layer, though there's nothing stopping external modification via
Cvar_FindVar (which is needed for adding listeners).
While not used yet (partly due to working out the design), cvars can
have a validation function.
Registering a cvar allows a primary listener (and its data) to be
specified: it will always be called first when the cvar is modified. The
combination of proper listeners and direct access to the controlled
variable greatly simplifies the more complex cvar interactions as much
less null checking is required, and there's no need for one cvar's
callback to call another's.
nq-x11 is known to work at least well enough for the demos. More testing
will come.
2022-04-23 03:22:45 +00:00
|
|
|
Cvar_Register (&bgmvolume_cvar, 0, 0);
|
2003-01-31 23:16:28 +00:00
|
|
|
|
2001-06-01 22:55:33 +00:00
|
|
|
if (I_CDAudio_GetAudioDiskInfo ()) {
|
2001-09-21 04:22:46 +00:00
|
|
|
Sys_Printf ("CDAudio_Init: No CD in player.\n");
|
2001-02-19 21:15:25 +00:00
|
|
|
cdValid = false;
|
|
|
|
enabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-20 08:34:57 +00:00
|
|
|
static general_funcs_t plugin_info_general_funcs = {
|
|
|
|
I_CDAudio_Init,
|
|
|
|
I_CDAudio_Shutdown,
|
|
|
|
};
|
|
|
|
|
|
|
|
static cd_funcs_t plugin_info_cd_funcs = {
|
2021-06-26 06:43:17 +00:00
|
|
|
0,
|
2004-01-20 08:34:57 +00:00
|
|
|
I_CD_f,
|
|
|
|
I_CDAudio_Pause,
|
|
|
|
I_CDAudio_Play,
|
|
|
|
I_CDAudio_Resume,
|
|
|
|
I_CDAudio_Update,
|
|
|
|
};
|
|
|
|
|
|
|
|
static plugin_funcs_t plugin_info_funcs = {
|
|
|
|
&plugin_info_general_funcs,
|
|
|
|
0,
|
|
|
|
&plugin_info_cd_funcs,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static plugin_data_t plugin_info_data = {
|
|
|
|
&plugin_info_general_data,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static plugin_t plugin_info = {
|
|
|
|
qfp_cd,
|
|
|
|
0,
|
|
|
|
QFPLUGIN_VERSION,
|
|
|
|
"0.1",
|
|
|
|
"Windows CD Audio output\n",
|
2004-02-07 05:35:15 +00:00
|
|
|
"Copyright (C) 2001 contributors of the QuakeForge project\n"
|
|
|
|
"Please see the file \"AUTHORS\" for a list of contributors\n",
|
2004-01-20 08:34:57 +00:00
|
|
|
&plugin_info_funcs,
|
|
|
|
&plugin_info_data,
|
|
|
|
};
|
2001-06-01 22:55:33 +00:00
|
|
|
|
2004-01-20 08:34:57 +00:00
|
|
|
PLUGIN_INFO (cd, win)
|
|
|
|
{
|
2001-06-01 22:55:33 +00:00
|
|
|
return &plugin_info;
|
2001-02-19 21:15:25 +00:00
|
|
|
}
|