From 5b094c2aa1030abba145e094c2e324c961599a93 Mon Sep 17 00:00:00 2001 From: Loring Holden Date: Fri, 26 May 2000 03:55:27 +0000 Subject: [PATCH] Reapply changes - this time tested w/ svga under Linux --- acconfig.h | 3 + configure.in | 59 ++++++++++-- source/Makefile.am | 45 +++++---- source/buildnum.c | 3 + source/cl_cmd.c | 3 + source/cl_main.c | 14 +++ source/cl_model.c | 3 + source/cl_parse.c | 3 + source/cl_tent.c | 3 + source/cl_trans.c | 3 + source/cmd.c | 3 + source/com.c | 2 +- source/gl_draw.c | 20 +++- source/gl_rmisc.c | 3 + source/gl_warp.c | 3 + source/info.c | 3 + source/keys.c | 3 + source/mathlib.c | 3 + source/net_chan.c | 3 + source/net_udp.c | 20 ++-- source/pmovetst.c | 3 + source/pr_edict.c | 3 + source/r_main.c | 3 + source/snd_mix.c | 3 + source/snd_sun.c | 224 +++++++++++++++++++++++++++++++++++++++++++ source/sv_ccmds.c | 3 + source/sv_ents.c | 3 + source/sv_main.c | 3 + source/sv_nchan.c | 3 + source/sv_sys_unix.c | 6 ++ source/world.c | 3 + 31 files changed, 428 insertions(+), 31 deletions(-) create mode 100644 source/snd_sun.c diff --git a/acconfig.h b/acconfig.h index d3b9e5c..b85dd3d 100644 --- a/acconfig.h +++ b/acconfig.h @@ -85,5 +85,8 @@ /* If your version of OpenGL uses APIENTRY, define GLAPIENTRY to be APIENTRY */ #undef GLAPIENTRY +/* Define this to something sane if you don't have stricmp */ +#undef stricmp + @BOTTOM@ #endif // _CONFIG_H diff --git a/configure.in b/configure.in index d7eef9c..d5a98f0 100644 --- a/configure.in +++ b/configure.in @@ -84,11 +84,13 @@ AC_TYPE_SIZE_T AC_STRUCT_ST_BLKSIZE AC_HEADER_TIME AC_STRUCT_TM +AC_C_BIGENDIAN AC_TRY_COMPILE( [#include ], [ socklen_t x = 0;], - AC_DEFINE(HAVE_SOCKLEN_T) + AC_DEFINE(HAVE_SOCKLEN_T) AC_MSG_RESULT(yes), + AC_MSG_RESULT(no) dnl FreeBSD 4.0 has it in sys/socket.h AC_MSG_CHECKING(for socklen_t in sys/socket.h) AC_TRY_COMPILE( @@ -462,13 +464,14 @@ case "${host}" in [ --disable-asmopt disable assembler optimization], ASM_ARCH=none AC_MSG_RESULT(yes), - AC_DEFINE(USE_INTEL_ASM) + AC_DEFINE(USE_INTEL_ASM) + ASM_ARCH=yes AC_MSG_RESULT(no) ) ;; *) AC_MSG_RESULT(no) esac -AC_SUBST(ASM_ARCH) +AM_CONDITIONAL(ASM_ARCH, test "$ASM_ARCH" = "yes") dnl ================================================================== dnl Checks for sound @@ -546,6 +549,15 @@ QF_maGiC_VALUE ], SNDTYPE="WIN32" SOUND_LIBS="-lwinmm") fi +dnl Sun +if test -z "$SNDTYPE" -a "x$ac_cv_header_sys_audioio_h" = "xyes"; then + AC_EGREP_CPP([QF_maGiC_VALUE],[ +#include +#ifdef AUDIO_SETINFO +QF_maGiC_VALUE +#endif + ], SNDTYPE="SUN") +fi AC_MSG_RESULT([yes ($SNDTYPE)]) AC_SUBST(SOUND_LIBS) @@ -553,8 +565,7 @@ AM_CONDITIONAL(SNDTYPE_MME, test "$SNDTYPE" = "MME") AM_CONDITIONAL(SNDTYPE_OSS, test "$SNDTYPE" = "OSS") AM_CONDITIONAL(SNDTYPE_ALSA, test "$SNDTYPE" = "ALSA") AM_CONDITIONAL(SNDTYPE_WIN32, test "$SNDTYPE" = "WIN32") -AM_CONDITIONAL(SNDTYPE_NULL, test "$SNDTYPE" != "WIN32" -a "$SNDTYPE" != "ALSA" -a "$SNDTYPE" != "OSS" -a "$SNDTYPE" != "MME") - +AM_CONDITIONAL(SNDTYPE_SUN, test "$SNDTYPE" = "SUN") dnl ================================================================== dnl Checks for CD-ROM @@ -595,7 +606,43 @@ dnl ================================================================== dnl Checks for networking dnl ================================================================== -NET_LIBS="" +if test "x$ac_cv_func_connect" != "xyes"; then + AC_CHECK_LIB(socket,connect, + NET_LIBS="$NET_LIBS -lsocket" + ac_cv_func_connect=yes) +fi +if test "x$ac_cv_func_gethostbyname" != "xyes"; then + AC_CHECK_LIB(nsl,gethostbyname, + NET_LIBS="$NET_LIBS -lnsl" + ac_cv_func_gethostbyname=yes) +fi + +AC_MSG_CHECKING([for connect in -lwsock32]) +SAVELIBS="$LIBS" +LIBS="$LIBS -lwsock32" +AC_TRY_LINK([ +#include +],[ +connect(0, NULL, 42); +], + NET_LIBS="$NET_LIBS -lwsock32 -lwinmm" + ac_cv_func_connect=yes + ac_cv_func_gethostbyname=yes + HAVE_WSOCK=yes + AC_MSG_RESULT(yes), + AC_MSG_RESULT(no)) +LIBS="$SAVELIBS" + +AC_MSG_CHECKING(for UDP support) +if test "x$ac_cv_func_connect" = "xyes" -a \ + "x$ac_cv_func_gethostbyname" = "xyes"; then + HAVE_UDP=yes + AC_MSG_RESULT(yes) +else + AC_MSG_RESULT(no) +fi + + if test "x$ac_cv_func_connect" != "xyes"; then AC_MSG_CHECKING([for connect in -lwsock32]) SAVELIBS="$LIBS" diff --git a/source/Makefile.am b/source/Makefile.am index 158a658..45d003e 100644 --- a/source/Makefile.am +++ b/source/Makefile.am @@ -17,21 +17,35 @@ libqfsys_cl_a_SOURCES = sys_unix.c cl_sys_unix.c libqfsys_sv_a_SOURCES = sys_unix.c sv_sys_unix.c endif +if ASM_ARCH +MATH_ASM = math.S +WORLDA_ASM = worlda.S +CL_ASM = snd_mixa.S cl_math.S sys_x86.S +SOFT_ASM = d_draw.S d_draw16.S d_parta.S d_polysa.S d_scana.S \ + d_spr8.S d_varsa.S r_aclipa.S r_aliasa.S r_drawa.S r_edgea.S \ + r_varsa.S surf16.S surf8.S +endif + EXTRA_libqfsys_cl_a_SOURCES = cl_sys_unix.c cl_sys_win.c sys_win.c sys_unix.c fnmatch.c dirent.c EXTRA_libqfsys_sv_a_SOURCES = sv_sys_unix.c sv_sys_win.c sys_win.c sys_unix.c fnmatch.c dirent.c if SNDTYPE_WIN32 -libqfsnd_a_SOURCES = snd_dma.c snd_win.c -endif +libqfsnd_a_SOURCES = snd_win.c snd_dma.c snd_mem.c snd_mix.c +else if SNDTYPE_OSS -libqfsnd_a_SOURCES = snd_dma.c snd_oss.c -endif +libqfsnd_a_SOURCES = snd_oss.c snd_dma.c snd_mem.c snd_mix.c +else if SNDTYPE_ALSA -libqfsnd_a_SOURCES = snd_dma.c snd_alsa.c -endif -if SNDTYPE_NULL +libqfsnd_a_SOURCES = snd_alsa.c snd_dma.c snd_mem.c snd_mix.c +else +if SNDTYPE_SUN +libqfsnd_a_SOURCES = snd_sun.c snd_dma.c snd_mem.c snd_mix.c +else libqfsnd_a_SOURCES = snd_null.c endif +endif +endif +endif EXTRA_libqfsnd_a_SOURCES = snd_dma.c snd_win.c snd_oss.c snd_alsa.c snd_null.c if CDTYPE_WIN32 @@ -46,26 +60,23 @@ endif EXTRA_libqfcd_a_SOURCES = cd_win.c cd_linux.c cd_null.c common_SOURCES= net_chan.c net_com.c net_udp.c pmove.c pmovetst.c zone.c \ - mdfour.c mathlib.c math.S cvar.c crc.c model.c cmd.c \ + mdfour.c mathlib.c cvar.c crc.c model.c cmd.c \ qargs.c qendian.c quakefs.c quakeio.c msg.c sizebuf.c info.c \ - checksum.c link.c buildnum.c va.c com.c + checksum.c link.c buildnum.c va.c com.c $(MATH_ASM) server_SOURCES= pr_cmds.c pr_edict.c pr_exec.c sv_init.c sv_main.c sv_misc.c \ sv_model.c sv_nchan.c sv_ents.c sv_send.c sv_move.c sv_phys.c \ - sv_user.c sv_ccmds.c world.c worlda.S sv_cvar.c + sv_user.c sv_ccmds.c world.c sv_cvar.c $(WORLDA_ASM) client_SOURCES= cl_cmd.c cl_cvar.c cl_demo.c cl_ents.c cl_input.c cl_main.c \ - cl_math.S cl_misc.c cl_parse.c cl_pred.c cl_tent.c cl_cam.c \ - r_view.c wad.c snd_mem.c snd_mix.c snd_mixa.S \ + cl_misc.c cl_parse.c cl_pred.c cl_tent.c cl_cam.c \ + r_view.c wad.c \ skin.c sbar.c nonintel.c menu.c keys.c console.c \ - sys_x86.S cl_slist.c + cl_slist.c $(CL_ASM) soft_SOURCES= cl_model.c cl_trans.c d_edge.c d_fill.c d_init.c d_modech.c \ d_part.c d_polyse.c d_scan.c d_sky.c d_sprite.c d_surf.c \ d_vars.c d_zpoint.c draw.c r_aclip.c r_alias.c r_bsp.c \ r_draw.c r_edge.c r_efrag.c r_light.c r_main.c r_misc.c \ r_part.c r_sky.c r_sprite.c r_surf.c r_vars.c sw_view.c \ - screen.c \ - d_draw.S d_draw16.S d_parta.S d_polysa.S d_scana.S \ - d_spr8.S d_varsa.S r_aclipa.S r_aliasa.S r_drawa.S r_edgea.S \ - r_varsa.S surf16.S surf8.S + screen.c $(SOFT_ASM) ogl_SOURCES= gl_draw.c gl_mesh.c gl_model.c gl_ngraph.c gl_part.c \ gl_refrag.c gl_rlight.c gl_rmain.c gl_rmisc.c gl_rsurf.c \ gl_screen.c gl_trans.c gl_view.c gl_warp.c diff --git a/source/buildnum.c b/source/buildnum.c index cecfc74..568b7c8 100644 --- a/source/buildnum.c +++ b/source/buildnum.c @@ -32,6 +32,9 @@ #include #include +#ifdef HAVE_STRINGS_H +#include +#endif //char *date = "Dec 21 1999"; static char *date = __DATE__ ; diff --git a/source/cl_cmd.c b/source/cl_cmd.c index 855b539..7839dd1 100644 --- a/source/cl_cmd.c +++ b/source/cl_cmd.c @@ -35,6 +35,9 @@ #include "msg.h" #include +#ifdef HAVE_STRINGS_H +#include +#endif /* =================== diff --git a/source/cl_main.c b/source/cl_main.c index 2b4f6a2..11206b6 100644 --- a/source/cl_main.c +++ b/source/cl_main.c @@ -58,6 +58,12 @@ #include "draw.h" #include "qargs.h" #include "cdaudio.h" + +#ifdef __sun +/* Sun's model_t in sys/model.h conflicts w/ Quake's model_t */ +#define model_t sunmodel_t +#endif + #ifdef _WIN32 #include "winquake.h" #include "winsock.h" @@ -65,7 +71,15 @@ #else #include #endif + +#ifdef __sun +#undef model_t +#endif + #include +#ifdef HAVE_STRINGS_H +#include +#endif // we need to declare some mouse variables here, because the menu system diff --git a/source/cl_model.c b/source/cl_model.c index cc7df45..44b02b2 100644 --- a/source/cl_model.c +++ b/source/cl_model.c @@ -32,6 +32,9 @@ #ifdef HAVE_CONFIG_H # include #endif +#ifdef HAVE_STRING_H +#include +#endif #include "model.h" #include "crc.h" #include "msg.h" diff --git a/source/cl_parse.c b/source/cl_parse.c index aae7487..89af99c 100644 --- a/source/cl_parse.c +++ b/source/cl_parse.c @@ -40,6 +40,9 @@ #include "msg.h" #include "pmove.h" #include "sbar.h" +#ifdef HAVE_STRINGS_H +#include +#endif extern cvar_t *gl_flashblend; extern cvar_t *cl_autoexec; diff --git a/source/cl_tent.c b/source/cl_tent.c index cd8fdf8..7e7299a 100644 --- a/source/cl_tent.c +++ b/source/cl_tent.c @@ -39,6 +39,9 @@ #include #include +#ifdef HAVE_STRING_H +#include +#endif #define MAX_BEAMS 8 typedef struct diff --git a/source/cl_trans.c b/source/cl_trans.c index e0ed87b..0451ceb 100644 --- a/source/cl_trans.c +++ b/source/cl_trans.c @@ -34,6 +34,9 @@ #include "client.h" #include +#ifdef HAVE_STRINGS_H +#include +#endif /* ===================== diff --git a/source/cmd.c b/source/cmd.c index 95decd6..7e1a4c4 100644 --- a/source/cmd.c +++ b/source/cmd.c @@ -41,6 +41,9 @@ #include #include +#ifdef HAVE_STRINGS_H +#include +#endif void Cmd_ForwardToServer (void); diff --git a/source/com.c b/source/com.c index b8a5807..4c575ef 100644 --- a/source/com.c +++ b/source/com.c @@ -88,7 +88,7 @@ COM_Init */ void COM_Init (void) { -#ifndef WORDS_BIGENDIEN +#ifndef WORDS_BIGENDIAN bigendien = false; BigShort = ShortSwap; LittleShort = ShortNoSwap; diff --git a/source/gl_draw.c b/source/gl_draw.c index 821b595..e8918ef 100644 --- a/source/gl_draw.c +++ b/source/gl_draw.c @@ -32,6 +32,9 @@ #include #include +#ifdef HAVE_STRINGS_H +#include +#endif #include "bothdefs.h" // needed by: common.h, net.h, client.h @@ -1240,7 +1243,12 @@ void GL_Upload8_EXT (byte *data, int width, int height, qboolean mipmap, qboole { if (!mipmap) { +/* FIXME - what if this extension isn't available? */ +#ifdef HAVE_GL_COLOR_INDEX8_EXT glTexImage2D (GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, scaled_width, scaled_height, 0, GL_COLOR_INDEX , GL_UNSIGNED_BYTE, data); +#else + /* FIXME - should warn that this isn't available */ +#endif goto done; } memcpy (scaled, data, width*height); @@ -1248,7 +1256,12 @@ void GL_Upload8_EXT (byte *data, int width, int height, qboolean mipmap, qboole else GL_Resample8BitTexture (data, width, height, scaled, scaled_width, scaled_height); +// FIXME - what if this extension isn't available? +#ifdef HAVE_GL_COLOR_INDEX8_EXT glTexImage2D (GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, scaled_width, scaled_height, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, scaled); +#else + /* FIXME - should warn that this isn't available */ +#endif if (mipmap) { int miplevel; @@ -1264,7 +1277,12 @@ void GL_Upload8_EXT (byte *data, int width, int height, qboolean mipmap, qboole if (scaled_height < 1) scaled_height = 1; miplevel++; +/* FIXME - what if this extension isn't available? */ +#ifdef HAVE_GL_COLOR_INDEX8_EXT glTexImage2D (GL_TEXTURE_2D, miplevel, GL_COLOR_INDEX8_EXT, scaled_width, scaled_height, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, scaled); +#else + /* FIXME - should warn that this isn't available */ +#endif } } done: ; @@ -1401,7 +1419,7 @@ void GL_SelectTexture (GLenum target) { if (!gl_mtexable) return; -#ifndef __linux__ // no multitexture under Linux yet +#ifdef _WIN32 // FIXME - only multi-texture under Win32 qglSelectTextureSGIS(target); #endif if (target == oldtarget) diff --git a/source/gl_rmisc.c b/source/gl_rmisc.c index 1873a38..fd852e6 100644 --- a/source/gl_rmisc.c +++ b/source/gl_rmisc.c @@ -31,6 +31,9 @@ #endif #include #include +#ifdef HAVE_STRINGS_H +#include +#endif #include "bothdefs.h" // needed by: common.h, net.h, client.h diff --git a/source/gl_warp.c b/source/gl_warp.c index c5a7727..055002f 100644 --- a/source/gl_warp.c +++ b/source/gl_warp.c @@ -34,6 +34,9 @@ #include #include #include +#ifdef HAVE_STRINGS_H +#include +#endif #include "bothdefs.h" #include "console.h" diff --git a/source/info.c b/source/info.c index 587ab3e..e6e5349 100644 --- a/source/info.c +++ b/source/info.c @@ -34,6 +34,9 @@ #include #include #include +#ifdef HAVE_STRINGS_H +#include +#endif /* ===================================================================== diff --git a/source/keys.c b/source/keys.c index b9e1ddb..7a174bd 100644 --- a/source/keys.c +++ b/source/keys.c @@ -35,6 +35,9 @@ #include #include +#ifdef HAVE_STRINGS_H +#include +#endif #include "qtypes.h" #include "sys.h" diff --git a/source/mathlib.c b/source/mathlib.c index 2973852..4701a8e 100644 --- a/source/mathlib.c +++ b/source/mathlib.c @@ -29,6 +29,9 @@ #ifdef HAVE_CONFIG_H # include #endif +#ifdef HAVE_STRING_H +#include +#endif #include #include "qtypes.h" #include "mathlib.h" diff --git a/source/net_chan.c b/source/net_chan.c index 90929c8..f45aa32 100644 --- a/source/net_chan.c +++ b/source/net_chan.c @@ -34,6 +34,9 @@ #else # include #endif +#ifdef HAVE_STRING_H +#include +#endif #include #include diff --git a/source/net_udp.c b/source/net_udp.c index 08773e4..ac1370e 100644 --- a/source/net_udp.c +++ b/source/net_udp.c @@ -82,6 +82,14 @@ # define MAXHOSTNAMELEN 512 #endif +#ifndef HAVE_SOCKLEN_T +# ifdef HAVE_SIZE +typedef size_t socklen_t; +# else +typedef unsigned int socklen_t; +# endif +#endif + netadr_t net_local_adr; netadr_t net_from; @@ -230,13 +238,13 @@ qboolean NET_IsClientLegal(netadr_t *adr) qboolean NET_GetPacket (void) { - int ret; - struct sockaddr_in from; - int fromlen; + int ret; + struct sockaddr_in from; + socklen_t fromlen; fromlen = sizeof(from); - ret = recvfrom(net_socket, net_message_buffer, sizeof(net_message_buffer), - 0, (struct sockaddr *)&from, &fromlen); + ret = recvfrom(net_socket, (void*)net_message_buffer, sizeof(net_message_buffer), 0, (struct sockaddr *)&from, &fromlen); + SockadrToNetadr (&from, &net_from); SockadrToNetadr(&from, &net_from); if (ret == -1) { @@ -337,7 +345,7 @@ void NET_GetLocalAddress (void) { char buff[MAXHOSTNAMELEN]; struct sockaddr_in address; - int namelen; + socklen_t namelen; gethostname(buff, MAXHOSTNAMELEN); buff[MAXHOSTNAMELEN-1] = 0; diff --git a/source/pmovetst.c b/source/pmovetst.c index 514e7f8..4a89850 100644 --- a/source/pmovetst.c +++ b/source/pmovetst.c @@ -29,6 +29,9 @@ #ifdef HAVE_CONFIG_H # include #endif +#ifdef HAVE_STRING_H +#include +#endif #include "sys.h" #include "qtypes.h" #include "pmove.h" diff --git a/source/pr_edict.c b/source/pr_edict.c index 2f07bcb..15effbd 100644 --- a/source/pr_edict.c +++ b/source/pr_edict.c @@ -44,6 +44,9 @@ #include #include #include +#ifdef HAVE_STRINGS_H +#include +#endif void SV_Error (char *error, ...); diff --git a/source/r_main.c b/source/r_main.c index a823e97..d94f38c 100644 --- a/source/r_main.c +++ b/source/r_main.c @@ -29,6 +29,9 @@ #ifdef HAVE_CONFIG_H # include #endif +#ifdef HAVE_STRING_H +#include +#endif #include "sys.h" #include "cmd.h" #include "bothdefs.h" diff --git a/source/snd_mix.c b/source/snd_mix.c index 4dc3dac..7de7d53 100644 --- a/source/snd_mix.c +++ b/source/snd_mix.c @@ -29,6 +29,9 @@ #ifdef HAVE_CONFIG_H # include #endif +#ifdef HAVE_STRING_H +#include +#endif #include "sound.h" #include "console.h" diff --git a/source/snd_sun.c b/source/snd_sun.c new file mode 100644 index 0000000..3b6d21d --- /dev/null +++ b/source/snd_sun.c @@ -0,0 +1,224 @@ +/* + snd_sun.c + + (description) + + Copyright (C) 1996-1997 Id Software, Inc. + Copyright (C) 1999,2000 contributors of the QuakeForge project + Please see the file "AUTHORS" for a list of contributors + + 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 + + $Id$ +*/ + +#include +#include +#include +#include +#include + +#ifdef HAVE_UNISTD_H +#include +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int audio_fd; +int snd_inited; + +static int wbufp; +static audio_info_t info; + +#define BUFFER_SIZE 8192 + +unsigned char dma_buffer[BUFFER_SIZE]; +unsigned char pend_buffer[BUFFER_SIZE]; +int pending; + +qboolean SNDDMA_Init(void) +{ + if (snd_inited) { + printf("Sound already init'd\n"); + return 0; + } + + shm = &sn; + shm->splitbuffer = 0; + + audio_fd = open("/dev/audio", O_WRONLY|O_NDELAY); + + if (audio_fd < 0) { + if (errno == EBUSY) { + Con_Printf("Audio device is being used by another process\n"); + } + perror("/dev/audio"); + Con_Printf("Could not open /dev/audio\n"); + return (0); + } + + if (ioctl(audio_fd, AUDIO_GETINFO, &info) < 0) { + perror("/dev/audio"); + Con_Printf("Could not communicate with audio device.\n"); + close(audio_fd); + return 0; + } + + // + // set to nonblock + // + if (fcntl(audio_fd, F_SETFL, O_NONBLOCK) < 0) { + perror("/dev/audio"); + close(audio_fd); + return 0; + } + + AUDIO_INITINFO(&info); + + shm->speed = 11025; + + // try 16 bit stereo + info.play.encoding = AUDIO_ENCODING_LINEAR; + info.play.sample_rate = 11025; + info.play.channels = 2; + info.play.precision = 16; + + if (ioctl(audio_fd, AUDIO_SETINFO, &info) < 0) { + info.play.encoding = AUDIO_ENCODING_LINEAR; + info.play.sample_rate = 11025; + info.play.channels = 1; + info.play.precision = 16; + if (ioctl(audio_fd, AUDIO_SETINFO, &info) < 0) { + Con_Printf("Incapable sound hardware.\n"); + close(audio_fd); + return 0; + } + Con_Printf("16 bit mono sound initialized\n"); + shm->samplebits = 16; + shm->channels = 1; + } else { // 16 bit stereo + Con_Printf("16 bit stereo sound initialized\n"); + shm->samplebits = 16; + shm->channels = 2; + } + + shm->soundalive = true; + shm->samples = sizeof(dma_buffer) / (shm->samplebits/8); + shm->samplepos = 0; + shm->submission_chunk = 1; + shm->buffer = (unsigned char *)dma_buffer; + + snd_inited = 1; + + return 1; +} + +int SNDDMA_GetDMAPos(void) +{ + if (!snd_inited) + return (0); + + if (ioctl(audio_fd, AUDIO_GETINFO, &info) < 0) { + perror("/dev/audio"); + Con_Printf("Could not communicate with audio device.\n"); + close(audio_fd); + snd_inited = 0; + return (0); + } + + return ((info.play.samples*shm->channels) % shm->samples); +} + +int SNDDMA_GetSamples(void) +{ + if (!snd_inited) + return (0); + + if (ioctl(audio_fd, AUDIO_GETINFO, &info) < 0) { + perror("/dev/audio"); + Con_Printf("Could not communicate with audio device.\n"); + close(audio_fd); + snd_inited = 0; + return (0); + } + + return info.play.samples; +} + +void SNDDMA_Shutdown(void) +{ + if (snd_inited) { + close(audio_fd); + snd_inited = 0; + } +} + +/* +============== +SNDDMA_Submit + +Send sound to device if buffer isn't really the dma buffer +=============== +*/ +void SNDDMA_Submit(void) +{ + int bsize; + int bytes, b; + static unsigned char writebuf[1024]; + unsigned char *p; + int idx; + int stop = paintedtime; + + if (paintedtime < wbufp) + wbufp = 0; // reset + + bsize = shm->channels * (shm->samplebits/8); + bytes = (paintedtime - wbufp) * bsize; + + if (!bytes) + return; + + if (bytes > sizeof(writebuf)) { + bytes = sizeof(writebuf); + stop = wbufp + bytes/bsize; + } + + p = writebuf; + idx = (wbufp*bsize) & (BUFFER_SIZE - 1); + + for (b = bytes; b; b--) { + *p++ = dma_buffer[idx]; + idx = (idx + 1) & (BUFFER_SIZE - 1); + } + + wbufp = stop; + + if (write(audio_fd, writebuf, bytes) < bytes) + printf("audio can't keep up!\n"); + +} + diff --git a/source/sv_ccmds.c b/source/sv_ccmds.c index fef8f46..2fbfc0e 100644 --- a/source/sv_ccmds.c +++ b/source/sv_ccmds.c @@ -45,6 +45,9 @@ #include #include +#ifdef HAVE_STRINGS_H +#include +#endif qboolean sv_allow_cheats; diff --git a/source/sv_ents.c b/source/sv_ents.c index 241af6c..3c936d0 100644 --- a/source/sv_ents.c +++ b/source/sv_ents.c @@ -29,6 +29,9 @@ #ifdef HAVE_CONFIG_H # include #endif +#ifdef HAVE_STRING_H +#include +#endif #include "server.h" #include "crc.h" #include "msg.h" diff --git a/source/sv_main.c b/source/sv_main.c index 5df2697..495ad57 100644 --- a/source/sv_main.c +++ b/source/sv_main.c @@ -45,6 +45,9 @@ #include #include #include +#ifdef HAVE_STRINGS_H +#include +#endif quakeparms_t host_parms; diff --git a/source/sv_nchan.c b/source/sv_nchan.c index 6270a01..de7c5dd 100644 --- a/source/sv_nchan.c +++ b/source/sv_nchan.c @@ -29,6 +29,9 @@ #ifdef HAVE_CONFIG_H # include #endif +#ifdef HAVE_STRING_H +#include +#endif #include "server.h" #include "crc.h" #include "msg.h" diff --git a/source/sv_sys_unix.c b/source/sv_sys_unix.c index 33514dd..e40393a 100644 --- a/source/sv_sys_unix.c +++ b/source/sv_sys_unix.c @@ -31,6 +31,9 @@ # include #endif #include +#ifdef HAVE_STRINGS_H +#include +#endif #include "qargs.h" #include "cvar.h" #include "server.h" @@ -46,6 +49,9 @@ #include #include #include +#ifdef HAVE_STRING_H +#include +#endif /* cvar_t sys_extrasleep = {"sys_extrasleep","0"}; diff --git a/source/world.c b/source/world.c index 9b4eaef..c96fe75 100644 --- a/source/world.c +++ b/source/world.c @@ -36,6 +36,9 @@ #include "console.h" #include +#ifdef HAVE_STRING_H +#include +#endif /*