diff options
Diffstat (limited to 'src/jake2')
-rw-r--r-- | src/jake2/render/LwjglRenderer.java | 244 | ||||
-rw-r--r-- | src/jake2/render/opengl/LwjglDriver.java | 331 | ||||
-rw-r--r-- | src/jake2/render/opengl/LwjglGL.java | 311 | ||||
-rw-r--r-- | src/jake2/sound/lwjgl/Channel.java | 450 | ||||
-rw-r--r-- | src/jake2/sound/lwjgl/LWJGLSoundImpl.java | 554 | ||||
-rw-r--r-- | src/jake2/sound/lwjgl/PlaySound.java | 169 | ||||
-rw-r--r-- | src/jake2/sys/LWJGLKBD.java | 214 |
7 files changed, 0 insertions, 2273 deletions
diff --git a/src/jake2/render/LwjglRenderer.java b/src/jake2/render/LwjglRenderer.java deleted file mode 100644 index 1add3d3..0000000 --- a/src/jake2/render/LwjglRenderer.java +++ /dev/null @@ -1,244 +0,0 @@ -/* - * LwjglRenderer.java - * Copyright (C) 2004 - * - * $Id: LwjglRenderer.java,v 1.5 2007-01-11 23:20:40 cawe Exp $ - */ -/* -Copyright (C) 1997-2001 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 the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ -package jake2.render; - -import jake2.Defines; -import jake2.client.refdef_t; -import jake2.client.refexport_t; -import jake2.render.opengl.LwjglDriver; -import jake2.sys.KBD; -import jake2.sys.LWJGLKBD; - -import java.awt.Dimension; - -/** - * LwjglRenderer - * - * @author dsanders/cwei - */ -final class LwjglRenderer extends LwjglDriver implements refexport_t, Ref { - - public static final String DRIVER_NAME = "lwjgl"; - - private KBD kbd = new LWJGLKBD(); - - // is set from Renderer factory - private RenderAPI impl; - - static { - Renderer.register(new LwjglRenderer()); - }; - - private LwjglRenderer() { - } - - // ============================================================================ - // public interface for Renderer implementations - // - // refexport_t (ref.h) - // ============================================================================ - - /** - * @see jake2.client.refexport_t#Init() - */ - public boolean Init(int vid_xpos, int vid_ypos) { - // init the OpenGL drivers - impl.setGLDriver(this); - - // pre init - if (!impl.R_Init(vid_xpos, vid_ypos)) return false; - // post init - return impl.R_Init2(); - } - - /** - * @see jake2.client.refexport_t#Shutdown() - */ - public void Shutdown() { - impl.R_Shutdown(); - } - - /** - * @see jake2.client.refexport_t#BeginRegistration(java.lang.String) - */ - public final void BeginRegistration(String map) { - impl.R_BeginRegistration(map); - } - - /** - * @see jake2.client.refexport_t#RegisterModel(java.lang.String) - */ - public final model_t RegisterModel(String name) { - return impl.R_RegisterModel(name); - } - - /** - * @see jake2.client.refexport_t#RegisterSkin(java.lang.String) - */ - public final image_t RegisterSkin(String name) { - return impl.R_RegisterSkin(name); - } - - /** - * @see jake2.client.refexport_t#RegisterPic(java.lang.String) - */ - public final image_t RegisterPic(String name) { - return impl.Draw_FindPic(name); - } - /** - * @see jake2.client.refexport_t#SetSky(java.lang.String, float, float[]) - */ - public final void SetSky(String name, float rotate, float[] axis) { - impl.R_SetSky(name, rotate, axis); - } - - /** - * @see jake2.client.refexport_t#EndRegistration() - */ - public final void EndRegistration() { - impl.R_EndRegistration(); - } - - /** - * @see jake2.client.refexport_t#RenderFrame(jake2.client.refdef_t) - */ - public final void RenderFrame(refdef_t fd) { - impl.R_RenderFrame(fd); - } - - /** - * @see jake2.client.refexport_t#DrawGetPicSize(java.awt.Dimension, java.lang.String) - */ - public final void DrawGetPicSize(Dimension dim, String name) { - impl.Draw_GetPicSize(dim, name); - } - - /** - * @see jake2.client.refexport_t#DrawPic(int, int, java.lang.String) - */ - public final void DrawPic(int x, int y, String name) { - impl.Draw_Pic(x, y, name); - } - - /** - * @see jake2.client.refexport_t#DrawStretchPic(int, int, int, int, java.lang.String) - */ - public final void DrawStretchPic(int x, int y, int w, int h, String name) { - impl.Draw_StretchPic(x, y, w, h, name); - } - - /** - * @see jake2.client.refexport_t#DrawChar(int, int, int) - */ - public final void DrawChar(int x, int y, int num) { - impl.Draw_Char(x, y, num); - } - - /** - * @see jake2.client.refexport_t#DrawTileClear(int, int, int, int, java.lang.String) - */ - public final void DrawTileClear(int x, int y, int w, int h, String name) { - impl.Draw_TileClear(x, y, w, h, name); - } - - /** - * @see jake2.client.refexport_t#DrawFill(int, int, int, int, int) - */ - public final void DrawFill(int x, int y, int w, int h, int c) { - impl.Draw_Fill(x, y, w, h, c); - } - - /** - * @see jake2.client.refexport_t#DrawFadeScreen() - */ - public final void DrawFadeScreen() { - impl.Draw_FadeScreen(); - } - - /** - * @see jake2.client.refexport_t#DrawStretchRaw(int, int, int, int, int, int, byte[]) - */ - public final void DrawStretchRaw(int x, int y, int w, int h, int cols, int rows, byte[] data) { - impl.Draw_StretchRaw(x, y, w, h, cols, rows, data); - } - - /** - * @see jake2.client.refexport_t#CinematicSetPalette(byte[]) - */ - public final void CinematicSetPalette(byte[] palette) { - impl.R_SetPalette(palette); - } - - /** - * @see jake2.client.refexport_t#BeginFrame(float) - */ - public final void BeginFrame(float camera_separation) { - impl.R_BeginFrame(camera_separation); - } - - /** - * @see jake2.client.refexport_t#EndFrame() - */ - public final void EndFrame() { - endFrame(); - } - - /** - * @see jake2.client.refexport_t#AppActivate(boolean) - */ - public final void AppActivate(boolean activate) { - appActivate(activate); - } - - public void screenshot() { - impl.GL_ScreenShot_f(); - } - - public final int apiVersion() { - return Defines.API_VERSION; - } - - public KBD getKeyboardHandler() { - return kbd; - } - - // ============================================================================ - // Ref interface - // ============================================================================ - - public final String getName() { - return DRIVER_NAME; - } - - public final String toString() { - return DRIVER_NAME; - } - - public final refexport_t GetRefAPI(RenderAPI renderer) { - this.impl = renderer; - return this; - } -}
\ No newline at end of file diff --git a/src/jake2/render/opengl/LwjglDriver.java b/src/jake2/render/opengl/LwjglDriver.java deleted file mode 100644 index e44dffc..0000000 --- a/src/jake2/render/opengl/LwjglDriver.java +++ /dev/null @@ -1,331 +0,0 @@ -/* - * LWJGLBase.java - * Copyright (C) 2004 - * - * $Id: LwjglDriver.java,v 1.5 2007-11-03 13:04:23 cawe Exp $ - */ -/* - Copyright (C) 1997-2001 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 the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - */ -package jake2.render.opengl; - -import jake2.Defines; -import jake2.client.VID; -import jake2.qcommon.Com; -import jake2.qcommon.xcommand_t; -import jake2.render.Base; - -import java.awt.Dimension; -import java.util.LinkedList; - -import org.lwjgl.LWJGLException; -import org.lwjgl.opengl.Display; -import org.lwjgl.opengl.DisplayMode; - -/** - * LWJGLBase - * - * @author dsanders/cwei - */ -public abstract class LwjglDriver extends LwjglGL implements GLDriver { - - protected LwjglDriver() { - // see LwjglRenderer - } - - private DisplayMode oldDisplayMode; - - // window position on the screen - int window_xpos, window_ypos; - - private java.awt.DisplayMode toAwtDisplayMode(DisplayMode m) { - return new java.awt.DisplayMode(m.getWidth(), m.getHeight(), m - .getBitsPerPixel(), m.getFrequency()); - } - - public java.awt.DisplayMode[] getModeList() { - DisplayMode[] modes; - try { - modes = Display.getAvailableDisplayModes(); - } catch (LWJGLException e) { - Com.Println(e.getMessage()); - return new java.awt.DisplayMode[0]; - } - LinkedList l = new LinkedList(); - l.add(toAwtDisplayMode(oldDisplayMode)); - - for (int i = 0; i < modes.length; i++) { - DisplayMode m = modes[i]; - - if (m.getBitsPerPixel() != oldDisplayMode.getBitsPerPixel()) - continue; - if (m.getFrequency() > oldDisplayMode.getFrequency()) - continue; - if (m.getHeight() < 240 || m.getWidth() < 320) - continue; - - int j = 0; - java.awt.DisplayMode ml = null; - for (j = 0; j < l.size(); j++) { - ml = (java.awt.DisplayMode) l.get(j); - if (ml.getWidth() > m.getWidth()) - break; - if (ml.getWidth() == m.getWidth() - && ml.getHeight() >= m.getHeight()) - break; - } - if (j == l.size()) { - l.addLast(toAwtDisplayMode(m)); - } else if (ml.getWidth() > m.getWidth() - || ml.getHeight() > m.getHeight()) { - l.add(j, toAwtDisplayMode(m)); - } else if (m.getFrequency() > ml.getRefreshRate()) { - l.remove(j); - l.add(j, toAwtDisplayMode(m)); - } - } - java.awt.DisplayMode[] ma = new java.awt.DisplayMode[l.size()]; - l.toArray(ma); - return ma; - } - - public DisplayMode[] getLWJGLModeList() { - DisplayMode[] modes; - try { - modes = Display.getAvailableDisplayModes(); - } catch (LWJGLException e) { - Com.Println(e.getMessage()); - return new DisplayMode[0]; - } - - LinkedList l = new LinkedList(); - l.add(oldDisplayMode); - - for (int i = 0; i < modes.length; i++) { - DisplayMode m = modes[i]; - - if (m.getBitsPerPixel() != oldDisplayMode.getBitsPerPixel()) - continue; - if (m.getFrequency() > Math.max(60, oldDisplayMode.getFrequency())) - continue; - if (m.getHeight() < 240 || m.getWidth() < 320) - continue; - if (m.getHeight() > oldDisplayMode.getHeight() || m.getWidth() > oldDisplayMode.getWidth()) - continue; - - int j = 0; - DisplayMode ml = null; - for (j = 0; j < l.size(); j++) { - ml = (DisplayMode) l.get(j); - if (ml.getWidth() > m.getWidth()) - break; - if (ml.getWidth() == m.getWidth() - && ml.getHeight() >= m.getHeight()) - break; - } - if (j == l.size()) { - l.addLast(m); - } else if (ml.getWidth() > m.getWidth() - || ml.getHeight() > m.getHeight()) { - l.add(j, m); - } else if (m.getFrequency() > ml.getFrequency()) { - l.remove(j); - l.add(j, m); - } - } - DisplayMode[] ma = new DisplayMode[l.size()]; - l.toArray(ma); - return ma; - } - - private DisplayMode findDisplayMode(Dimension dim) { - DisplayMode mode = null; - DisplayMode m = null; - DisplayMode[] modes = getLWJGLModeList(); - int w = dim.width; - int h = dim.height; - - for (int i = 0; i < modes.length; i++) { - m = modes[i]; - if (m.getWidth() == w && m.getHeight() == h) { - mode = m; - break; - } - } - if (mode == null) - mode = oldDisplayMode; - return mode; - } - - String getModeString(DisplayMode m) { - StringBuffer sb = new StringBuffer(); - sb.append(m.getWidth()); - sb.append('x'); - sb.append(m.getHeight()); - sb.append('x'); - sb.append(m.getBitsPerPixel()); - sb.append('@'); - sb.append(m.getFrequency()); - sb.append("Hz"); - return sb.toString(); - } - - /** - * @param dim - * @param mode - * @param fullscreen - * @return enum rserr_t - */ - public int setMode(Dimension dim, int mode, boolean fullscreen) { - - Dimension newDim = new Dimension(); - - VID.Printf(Defines.PRINT_ALL, "Initializing OpenGL display\n"); - - VID.Printf(Defines.PRINT_ALL, "...setting mode " + mode + ":"); - - /* - * fullscreen handling - */ - if (oldDisplayMode == null) { - oldDisplayMode = Display.getDisplayMode(); - } - - if (!VID.GetModeInfo(newDim, mode)) { - VID.Printf(Defines.PRINT_ALL, " invalid mode\n"); - return Base.rserr_invalid_mode; - } - - VID.Printf(Defines.PRINT_ALL, " " + newDim.width + " " + newDim.height - + '\n'); - - // destroy the existing window - shutdown(); - - Display.setTitle("Jake2 (lwjgl)"); - - DisplayMode displayMode = findDisplayMode(newDim); - newDim.width = displayMode.getWidth(); - newDim.height = displayMode.getHeight(); - - if (fullscreen) { - try { - Display.setDisplayMode(displayMode); - } catch (LWJGLException e) { - return Base.rserr_invalid_mode; - } - - Display.setLocation(0, 0); - - try { - Display.setFullscreen(fullscreen); - } catch (LWJGLException e) { - return Base.rserr_invalid_fullscreen; - } - - VID.Printf(Defines.PRINT_ALL, "...setting fullscreen " - + getModeString(displayMode) + '\n'); - - } else { - try { - Display.setDisplayMode(displayMode); - } catch (LWJGLException e) { - return Base.rserr_invalid_mode; - } - - try { - Display.setFullscreen(false); - } catch (LWJGLException e) { - return Base.rserr_invalid_fullscreen; - } - //Display.setLocation(window_xpos, window_ypos); - } - - Base.setVid(newDim.width, newDim.height); - - // vid.width = newDim.width; - // vid.height = newDim.height; - - try { - Display.create(); - } catch (LWJGLException e) { - return Base.rserr_unknown; - } - - // let the sound and input subsystems know about the new window - VID.NewWindow(newDim.width, newDim.height); - return Base.rserr_ok; - } - - public void shutdown() { - if (oldDisplayMode != null && Display.isFullscreen()) { - try { - Display.setDisplayMode(oldDisplayMode); - } catch (Exception e) { - e.printStackTrace(); - } - } - - while (Display.isCreated()) { - Display.destroy(); - } - } - - /** - * @return true - */ - public boolean init(int xpos, int ypos) { - // do nothing - window_xpos = xpos; - window_ypos = ypos; - return true; - } - - public void beginFrame(float camera_separation) { - // do nothing - } - - public void endFrame() { - glFlush(); - // swap buffers - Display.update(); - } - - public void appActivate(boolean activate) { - // do nothing - } - - public void enableLogging(boolean enable) { - // do nothing - } - - public void logNewFrame() { - // do nothing - } - - /** - * this is a hack for jogl renderers. - * - * @param callback - */ - public final void updateScreen(xcommand_t callback) { - callback.execute(); - } - -} diff --git a/src/jake2/render/opengl/LwjglGL.java b/src/jake2/render/opengl/LwjglGL.java deleted file mode 100644 index c248c3a..0000000 --- a/src/jake2/render/opengl/LwjglGL.java +++ /dev/null @@ -1,311 +0,0 @@ -package jake2.render.opengl; - -import java.nio.*; - -import org.lwjgl.opengl.*; - -public class LwjglGL implements QGL { - - LwjglGL() { - // singleton - } - - public final void glAlphaFunc(int func, float ref) { - GL11.glAlphaFunc(func, ref); - } - - public final void glBegin(int mode) { - GL11.glBegin(mode); - } - - public final void glBindTexture(int target, int texture) { - GL11.glBindTexture(target, texture); - } - - public final void glBlendFunc(int sfactor, int dfactor) { - GL11.glBlendFunc(sfactor, dfactor); - } - - public final void glClear(int mask) { - GL11.glClear(mask); - } - - public final void glClearColor(float red, float green, float blue, float alpha) { - GL11.glClearColor(red, green, blue, alpha); - } - - public final void glColor3f(float red, float green, float blue) { - GL11.glColor3f(red, green, blue); - } - - public final void glColor3ub(byte red, byte green, byte blue) { - GL11.glColor3ub(red, green, blue); - } - - public final void glColor4f(float red, float green, float blue, float alpha) { - GL11.glColor4f(red, green, blue, alpha); - } - - public final void glColor4ub(byte red, byte green, byte blue, byte alpha) { - GL11.glColor4ub(red, green, blue, alpha); - } - - public final void glColorPointer(int size, boolean unsigned, int stride, - ByteBuffer pointer) { - GL11.glColorPointer(size, unsigned, stride, pointer); - } - - public final void glColorPointer(int size, int stride, FloatBuffer pointer) { - GL11.glColorPointer(size, stride, pointer); - } - - public final void glCullFace(int mode) { - GL11.glCullFace(mode); - } - - public final void glDeleteTextures(IntBuffer textures) { - GL11.glDeleteTextures(textures); - } - - public final void glDepthFunc(int func) { - GL11.glDepthFunc(func); - } - - public final void glDepthMask(boolean flag) { - GL11.glDepthMask(flag); - } - - public final void glDepthRange(double zNear, double zFar) { - GL11.glDepthRange(zNear, zFar); - } - - public final void glDisable(int cap) { - GL11.glDisable(cap); - } - - public final void glDisableClientState(int cap) { - GL11.glDisableClientState(cap); - } - - public final void glDrawArrays(int mode, int first, int count) { - GL11.glDrawArrays(mode, first, count); - } - - public final void glDrawBuffer(int mode) { - GL11.glDrawBuffer(mode); - } - - public final void glDrawElements(int mode, IntBuffer indices) { - GL11.glDrawElements(mode, indices); - } - - public final void glEnable(int cap) { - GL11.glEnable(cap); - } - - public final void glEnableClientState(int cap) { - GL11.glEnableClientState(cap); - } - - public final void glEnd() { - GL11.glEnd(); - } - - public final void glFinish() { - GL11.glFinish(); - } - - public final void glFlush() { - GL11.glFlush(); - } - - public final void glFrustum(double left, double right, double bottom, - double top, double zNear, double zFar) { - GL11.glFrustum(left, right, bottom, top, zNear, zFar); - } - - public final int glGetError() { - return GL11.glGetError(); - } - - public final void glGetFloat(int pname, FloatBuffer params) { - GL11.glGetFloat(pname, params); - } - - public final String glGetString(int name) { - return GL11.glGetString(name); - } - - public void glHint(int target, int mode) { - GL11.glHint(target, mode); - } - - public final void glInterleavedArrays(int format, int stride, - FloatBuffer pointer) { - GL11.glInterleavedArrays(format, stride, pointer); - } - - public final void glLoadIdentity() { - GL11.glLoadIdentity(); - } - - public final void glLoadMatrix(FloatBuffer m) { - GL11.glLoadMatrix(m); - } - - public final void glMatrixMode(int mode) { - GL11.glMatrixMode(mode); - } - - public final void glOrtho(double left, double right, double bottom, - double top, double zNear, double zFar) { - GL11.glOrtho(left, right, bottom, top, zNear, zFar); - } - - public final void glPixelStorei(int pname, int param) { - GL11.glPixelStorei(pname, param); - } - - public final void glPointSize(float size) { - GL11.glPointSize(size); - } - - public final void glPolygonMode(int face, int mode) { - GL11.glPolygonMode(face, mode); - } - - public final void glPopMatrix() { - GL11.glPopMatrix(); - } - - public final void glPushMatrix() { - GL11.glPushMatrix(); - } - - public final void glReadPixels(int x, int y, int width, int height, - int format, int type, ByteBuffer pixels) { - GL11.glReadPixels(x, y, width, height, format, type, pixels); - } - - public final void glRotatef(float angle, float x, float y, float z) { - GL11.glRotatef(angle, x, y, z); - } - - public final void glScalef(float x, float y, float z) { - GL11.glScalef(x, y, z); - } - - public final void glScissor(int x, int y, int width, int height) { - GL11.glScissor(x, y, width, height); - } - - public final void glShadeModel(int mode) { - GL11.glShadeModel(mode); - } - - public final void glTexCoord2f(float s, float t) { - GL11.glTexCoord2f(s, t); - } - - public final void glTexCoordPointer(int size, int stride, FloatBuffer pointer) { - GL11.glTexCoordPointer(size, stride, pointer); - } - - public final void glTexEnvi(int target, int pname, int param) { - GL11.glTexEnvi(target, pname, param); - } - - public final void glTexImage2D(int target, int level, int internalformat, - int width, int height, int border, int format, int type, - ByteBuffer pixels) { - GL11.glTexImage2D(target, level, internalformat, width, height, border, - format, type, pixels); - } - - public final void glTexImage2D(int target, int level, int internalformat, - int width, int height, int border, int format, int type, - IntBuffer pixels) { - GL11.glTexImage2D(target, level, internalformat, width, height, border, - format, type, pixels); - } - - public final void glTexParameterf(int target, int pname, float param) { - GL11.glTexParameterf(target, pname, param); - } - - public final void glTexParameteri(int target, int pname, int param) { - GL11.glTexParameteri(target, pname, param); - } - - public final void glTexSubImage2D(int target, int level, int xoffset, - int yoffset, int width, int height, int format, int type, - IntBuffer pixels) { - GL11.glTexSubImage2D(target, level, xoffset, yoffset, width, height, - format, type, pixels); - } - - public final void glTranslatef(float x, float y, float z) { - GL11.glTranslatef(x, y, z); - } - - public final void glVertex2f(float x, float y) { - GL11.glVertex2f(x, y); - } - - public final void glVertex3f(float x, float y, float z) { - GL11.glVertex3f(x, y, z); - } - - public final void glVertexPointer(int size, int stride, FloatBuffer pointer) { - GL11.glVertexPointer(size, stride, pointer); - } - - public final void glViewport(int x, int y, int width, int height) { - GL11.glViewport(x, y, width, height); - } - - public final void glColorTable(int target, int internalFormat, int width, - int format, int type, ByteBuffer data) { - EXTPalettedTexture.glColorTableEXT(target, internalFormat, width, format, type, data); - } - - public final void glActiveTextureARB(int texture) { - ARBMultitexture.glActiveTextureARB(texture); - } - - public final void glClientActiveTextureARB(int texture) { - ARBMultitexture.glClientActiveTextureARB(texture); - } - - public final void glPointParameterEXT(int pname, FloatBuffer pfParams) { - EXTPointParameters.glPointParameterEXT(pname, pfParams); - } - - public final void glPointParameterfEXT(int pname, float param) { - EXTPointParameters.glPointParameterfEXT(pname, param); - } - - public final void glLockArraysEXT(int first, int count) { - EXTCompiledVertexArray.glLockArraysEXT(first, count); - } - - public final void glArrayElement(int index) { - GL11.glArrayElement(index); - } - - public final void glUnlockArraysEXT() { - EXTCompiledVertexArray.glUnlockArraysEXT(); - } - - public final void glMultiTexCoord2f(int target, float s, float t) { - GL13.glMultiTexCoord2f(target, s, t); - } - - /* - * util extensions - */ - public void setSwapInterval(int interval) { - Display.setSwapInterval(interval); - } - -} diff --git a/src/jake2/sound/lwjgl/Channel.java b/src/jake2/sound/lwjgl/Channel.java deleted file mode 100644 index 05a2802..0000000 --- a/src/jake2/sound/lwjgl/Channel.java +++ /dev/null @@ -1,450 +0,0 @@ -/* - * Created on Jun 19, 2004 - * - * Copyright (C) 2003 - * - * $Id: Channel.java,v 1.12 2006-11-23 13:31:58 cawe Exp $ - */ -/* -Copyright (C) 1997-2001 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 the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - */ -package jake2.sound.lwjgl; - -import jake2.Defines; -import jake2.Globals; -import jake2.client.CL_ents; -import jake2.game.entity_state_t; -import jake2.qcommon.Com; -import jake2.sound.*; -import jake2.util.Lib; -import jake2.util.Math3D; - -import java.nio.*; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.Map; - -import org.lwjgl.openal.AL10; -import org.lwjgl.openal.OpenALException; - -/** - * Channel - * - * @author dsanders/cwei - */ -public class Channel { - - final static int LISTENER = 0; - final static int FIXED = 1; - final static int DYNAMIC = 2; - final static int MAX_CHANNELS = 32; - private final static FloatBuffer NULLVECTOR = Lib.newFloatBuffer(3); - - private static Channel[] channels = new Channel[MAX_CHANNELS]; - private static IntBuffer sources = Lib.newIntBuffer(MAX_CHANNELS); - // a reference of L:WJGLSoundImpl.buffers - private static IntBuffer buffers; - private static Map looptable = new Hashtable(MAX_CHANNELS); - - private static int numChannels; - - // stream handling - private static boolean streamingEnabled = false; - private static int streamQueue = 0; - - // sound attributes - private int type; - private int entnum; - private int entchannel; - private int bufferId; - private int sourceId; - private float volume; - private float rolloff; - private float[] origin = {0, 0, 0}; - - // update flags - private boolean autosound; - private boolean active; - private boolean modified; - private boolean bufferChanged; - private boolean volumeChanged; - - private Channel(int sourceId) { - this.sourceId = sourceId; - clear(); - volumeChanged = false; - volume = 1.0f; - } - - private void clear() { - entnum = entchannel = bufferId = -1; - bufferChanged = false; - rolloff = 0; - autosound = false; - active = false; - modified = false; - } - - private static IntBuffer tmp = Lib.newIntBuffer(1); - - static int init(IntBuffer buffers) { - Channel.buffers = buffers; - // create channels - int sourceId; - numChannels = 0; - for (int i = 0; i < MAX_CHANNELS; i++) { - try { - AL10.alGenSources(tmp); - sourceId = tmp.get(0); - // can't generate more sources - if (sourceId <= 0) break; - } catch (OpenALException e) { - // can't generate more sources - break; - } - - sources.put(i, sourceId); - - channels[i] = new Channel(sourceId); - numChannels++; - - // set default values for AL sources - AL10.alSourcef (sourceId, AL10.AL_GAIN, 1.0f); - AL10.alSourcef (sourceId, AL10.AL_PITCH, 1.0f); - AL10.alSourcei (sourceId, AL10.AL_SOURCE_RELATIVE, AL10.AL_FALSE); - AL10.alSource(sourceId, AL10.AL_VELOCITY, NULLVECTOR); - AL10.alSourcei (sourceId, AL10.AL_LOOPING, AL10.AL_FALSE); - AL10.alSourcef (sourceId, AL10.AL_REFERENCE_DISTANCE, 200.0f); - AL10.alSourcef (sourceId, AL10.AL_MIN_GAIN, 0.0005f); - AL10.alSourcef (sourceId, AL10.AL_MAX_GAIN, 1.0f); - } - sources.limit(numChannels); - return numChannels; - } - - static void reset() { - for (int i = 0; i < numChannels; i++) { - AL10.alSourceStop(sources.get(i)); - AL10.alSourcei(sources.get(i), AL10.AL_BUFFER, 0); - channels[i].clear(); - } - } - - static void shutdown() { - AL10.alDeleteSources(sources); - numChannels = 0; - } - - static void enableStreaming() { - if (streamingEnabled) return; - - // use the last source - numChannels--; - streamingEnabled = true; - streamQueue = 0; - - int source = channels[numChannels].sourceId; - AL10.alSourcei (source, AL10.AL_SOURCE_RELATIVE, AL10.AL_TRUE); - AL10.alSourcef(source, AL10.AL_GAIN, 1.0f); - channels[numChannels].volumeChanged = true; - - Com.DPrintf("streaming enabled\n"); - } - - static void disableStreaming() { - if (!streamingEnabled) return; - unqueueStreams(); - int source = channels[numChannels].sourceId; - AL10.alSourcei (source, AL10.AL_SOURCE_RELATIVE, AL10.AL_FALSE); - - // free the last source - numChannels++; - streamingEnabled = false; - Com.DPrintf("streaming disabled\n"); - } - - static void unqueueStreams() { - if (!streamingEnabled) return; - int source = channels[numChannels].sourceId; - - // stop streaming - AL10.alSourceStop(source); - int count = AL10.alGetSourcei(source, AL10.AL_BUFFERS_QUEUED); - Com.DPrintf("unqueue " + count + " buffers\n"); - while (count-- > 0) { - AL10.alSourceUnqueueBuffers(source, tmp); - } - streamQueue = 0; - } - - static void updateStream(ByteBuffer samples, int count, int format, int rate) { - enableStreaming(); - int source = channels[numChannels].sourceId; - int processed = AL10.alGetSourcei(source, AL10.AL_BUFFERS_PROCESSED); - - boolean playing = (AL10.alGetSourcei(source, AL10.AL_SOURCE_STATE) == AL10.AL_PLAYING); - boolean interupted = !playing && streamQueue > 2; - - IntBuffer buffer = tmp; - if (interupted) { - unqueueStreams(); - buffer.put(0, buffers.get(Sound.MAX_SFX + streamQueue++)); - Com.DPrintf("queue " + (streamQueue - 1) + '\n'); - } else if (processed < 2) { - // check queue overrun - if (streamQueue >= Sound.STREAM_QUEUE) return; - buffer.put(0, buffers.get(Sound.MAX_SFX + streamQueue++)); - Com.DPrintf("queue " + (streamQueue - 1) + '\n'); - } else { - // reuse the buffer - AL10.alSourceUnqueueBuffers(source, buffer); - } - - samples.position(0); - samples.limit(count); - AL10.alBufferData(buffer.get(0), format, samples, rate); - AL10.alSourceQueueBuffers(source, buffer); - - if (streamQueue > 1 && !playing) { - Com.DPrintf("start sound\n"); - AL10.alSourcePlay(source); - } - } - - static void addPlaySounds() { - while (Channel.assign(PlaySound.nextPlayableSound())); - } - - private static boolean assign(PlaySound ps) { - if (ps == null) return false; - Channel ch = null; - int i; - for (i = 0; i < numChannels; i++) { - ch = channels[i]; - - if (ps.entchannel != 0 && ch.entnum == ps.entnum && ch.entchannel == ps.entchannel) { - // always override sound from same entity - if (ch.bufferId != ps.bufferId) { - AL10.alSourceStop(ch.sourceId); - } - break; - } - - // don't let monster sounds override player sounds - if ((ch.entnum == Globals.cl.playernum+1) && (ps.entnum != Globals.cl.playernum+1) && ch.bufferId != -1) - continue; - - // looking for a free AL source - if (!ch.active) { - break; - } - } - - if (i == numChannels) - return false; - - ch.type = ps.type; - if (ps.type == Channel.FIXED) - Math3D.VectorCopy(ps.origin, ch.origin); - ch.entnum = ps.entnum; - ch.entchannel = ps.entchannel; - ch.bufferChanged = (ch.bufferId != ps.bufferId); - ch.bufferId = ps.bufferId; - ch.rolloff = ps.attenuation * 2; - ch.volumeChanged = (ch.volume != ps.volume); - ch.volume = ps.volume; - ch.active = true; - ch.modified = true; - return true; - } - - private static Channel pickForLoop(int bufferId, float attenuation) { - Channel ch; - for (int i = 0; i < numChannels; i++) { - ch = channels[i]; - // looking for a free AL source - if (!ch.active) { - ch.entnum = 0; - ch.entchannel = 0; - ch.bufferChanged = (ch.bufferId != bufferId); - ch.bufferId = bufferId; - ch.volumeChanged = (ch.volume != 1.0f); - ch.volume = 1.0f; - ch.rolloff = attenuation * 2; - ch.active = true; - ch.modified = true; - return ch; - } - } - return null; - } - - private static FloatBuffer sourceOriginBuffer = Lib.newFloatBuffer(3); - - //stack variable - private static float[] entityOrigin = {0, 0, 0}; - - static void playAllSounds(FloatBuffer listenerOrigin) { - FloatBuffer sourceOrigin = sourceOriginBuffer; - Channel ch; - int sourceId; - int state; - - for (int i = 0; i < numChannels; i++) { - ch = channels[i]; - if (ch.active) { - sourceId = ch.sourceId; - switch (ch.type) { - case Channel.LISTENER: - sourceOrigin.put(0, listenerOrigin.get(0)); - sourceOrigin.put(1, listenerOrigin.get(1)); - sourceOrigin.put(2, listenerOrigin.get(2)); - break; - case Channel.DYNAMIC: - CL_ents.GetEntitySoundOrigin(ch.entnum, entityOrigin); - convertVector(entityOrigin, sourceOrigin); - break; - case Channel.FIXED: - convertVector(ch.origin, sourceOrigin); - break; - } - - if (ch.modified) { - if (ch.bufferChanged) { - try { - AL10.alSourcei(sourceId, AL10.AL_BUFFER, ch.bufferId); - } catch (OpenALException e) { - // fallback for buffer changing - AL10.alSourceStop(sourceId); - AL10.alSourcei(sourceId, AL10.AL_BUFFER, ch.bufferId); - } - } - if (ch.volumeChanged) { - AL10.alSourcef (sourceId, AL10.AL_GAIN, ch.volume); - } - AL10.alSourcef (sourceId, AL10.AL_ROLLOFF_FACTOR, ch.rolloff); - AL10.alSource(sourceId, AL10.AL_POSITION, sourceOrigin); - AL10.alSourcePlay(sourceId); - ch.modified = false; - } else { - state = AL10.alGetSourcei(sourceId, AL10.AL_SOURCE_STATE); - if (state == AL10.AL_PLAYING) { - AL10.alSource(sourceId, AL10.AL_POSITION, sourceOrigin); - } else { - ch.clear(); - } - } - ch.autosound = false; - } - } - } - - /* - * adddLoopSounds - * Entities with a ->sound field will generated looped sounds - * that are automatically started, stopped, and merged together - * as the entities are sent to the client - */ - static void addLoopSounds() { - - if ((Globals.cl_paused.value != 0.0f) || (Globals.cls.state != Globals.ca_active) || !Globals.cl.sound_prepped) { - removeUnusedLoopSounds(); - return; - } - - Channel ch; - sfx_t sfx; - sfxcache_t sc; - int num; - entity_state_t ent; - Object key; - int sound = 0; - - for (int i=0 ; i<Globals.cl.frame.num_entities ; i++) { - num = (Globals.cl.frame.parse_entities + i)&(Defines.MAX_PARSE_ENTITIES-1); - ent = Globals.cl_parse_entities[num]; - sound = ent.sound; - - if (sound == 0) continue; - - key = new Integer(ent.number); - ch = (Channel)looptable.get(key); - - if (ch != null) { - // keep on looping - ch.autosound = true; - Math3D.VectorCopy(ent.origin, ch.origin); - continue; - } - - sfx = Globals.cl.sound_precache[sound]; - if (sfx == null) - continue; // bad sound effect - - sc = sfx.cache; - if (sc == null) - continue; - - // allocate a channel - ch = Channel.pickForLoop(buffers.get(sfx.bufferId), 6); - if (ch == null) - break; - - ch.type = FIXED; - Math3D.VectorCopy(ent.origin, ch.origin); - ch.autosound = true; - - looptable.put(key, ch); - AL10.alSourcei(ch.sourceId, AL10.AL_LOOPING, AL10.AL_TRUE); - } - - removeUnusedLoopSounds(); - - } - - private static void removeUnusedLoopSounds() { - Channel ch; - // stop unused loopsounds - for (Iterator iter = looptable.values().iterator(); iter.hasNext();) { - ch = (Channel)iter.next(); - if (!ch.autosound) { - AL10.alSourceStop(ch.sourceId); - AL10.alSourcei(ch.sourceId, AL10.AL_LOOPING, AL10.AL_FALSE); - iter.remove(); - ch.clear(); - } - } - } - - static void convertVector(float[] from, FloatBuffer to) { - to.put(0, from[0]); - to.put(1, from[2]); - to.put(2, -from[1]); - } - - static void convertOrientation(float[] forward, float[] up, FloatBuffer orientation) { - orientation.put(0, forward[0]); - orientation.put(1, forward[2]); - orientation.put(2, -forward[1]); - orientation.put(3, up[0]); - orientation.put(4, up[2]); - orientation.put(5, -up[1]); - } - -} diff --git a/src/jake2/sound/lwjgl/LWJGLSoundImpl.java b/src/jake2/sound/lwjgl/LWJGLSoundImpl.java deleted file mode 100644 index 3a12494..0000000 --- a/src/jake2/sound/lwjgl/LWJGLSoundImpl.java +++ /dev/null @@ -1,554 +0,0 @@ -/* - * LWJGLSoundImpl.java - * Copyright (C) 2004 - * - * $Id: LWJGLSoundImpl.java,v 1.10 2007-05-11 20:33:53 cawe Exp $ - */ -package jake2.sound.lwjgl; - -import jake2.Defines; -import jake2.Globals; -import jake2.game.Cmd; -import jake2.game.cvar_t; -import jake2.game.entity_state_t; -import jake2.qcommon.*; -import jake2.sound.*; -import jake2.util.Lib; -import jake2.util.Vargs; - -import java.nio.*; - -import org.lwjgl.LWJGLException; -import org.lwjgl.openal.*; - - -/** - * LWJGLSoundImpl - * - * @author dsanders/cwei - */ -public final class LWJGLSoundImpl implements Sound { - - static { - S.register(new LWJGLSoundImpl()); - }; - - private cvar_t s_volume; - - // the last 4 buffers are used for cinematics streaming - private IntBuffer buffers = Lib.newIntBuffer(MAX_SFX + STREAM_QUEUE); - - // singleton - private LWJGLSoundImpl() { - } - - /* (non-Javadoc) - * @see jake2.sound.SoundImpl#Init() - */ - public boolean Init() { - - try { - initOpenAL(); - checkError(); - } catch (OpenALException e) { - Com.Printf(e.getMessage() + '\n'); - return false; - } catch (Exception e) { - Com.DPrintf(e.getMessage() + '\n'); - return false; - } - - // set the listerner (master) volume - s_volume = Cvar.Get("s_volume", "0.7", Defines.CVAR_ARCHIVE); - AL10.alGenBuffers(buffers); - int count = Channel.init(buffers); - Com.Printf("... using " + count + " channels\n"); - AL10.alDistanceModel(AL10.AL_INVERSE_DISTANCE_CLAMPED); - Cmd.AddCommand("play", new xcommand_t() { - public void execute() { - Play(); - } - }); - Cmd.AddCommand("stopsound", new xcommand_t() { - public void execute() { - StopAllSounds(); - } - }); - Cmd.AddCommand("soundlist", new xcommand_t() { - public void execute() { - SoundList(); - } - }); - Cmd.AddCommand("soundinfo", new xcommand_t() { - public void execute() { - SoundInfo_f(); - } - }); - - num_sfx = 0; - - Com.Printf("sound sampling rate: 44100Hz\n"); - - StopAllSounds(); - Com.Printf("------------------------------------\n"); - return true; - } - - - private void initOpenAL() throws OpenALException - { - try { AL.create(); } catch (LWJGLException e) { throw new OpenALException(e); } - String deviceName = null; - - String os = System.getProperty("os.name"); - if (os.startsWith("Windows")) { - deviceName = "DirectSound3D"; - } - - String defaultSpecifier = ALC10.alcGetString(AL.getDevice(), ALC10.ALC_DEFAULT_DEVICE_SPECIFIER); - - Com.Printf(os + " using " + ((deviceName == null) ? defaultSpecifier : deviceName) + '\n'); - - // Check for an error. - if (ALC10.alcGetError(AL.getDevice()) != ALC10.ALC_NO_ERROR) - { - Com.DPrintf("Error with SoundDevice"); - } - } - - void exitOpenAL() - { - AL.destroy(); - } - - // TODO check the sfx direct buffer size - // 2MB sfx buffer - private ByteBuffer sfxDataBuffer = Lib.newByteBuffer(2 * 1024 * 1024); - - /* (non-Javadoc) - * @see jake2.sound.SoundImpl#RegisterSound(jake2.sound.sfx_t) - */ - private void initBuffer(byte[] samples, int bufferId, int freq) { - ByteBuffer data = sfxDataBuffer.slice(); - data.put(samples).flip(); - AL10.alBufferData(buffers.get(bufferId), AL10.AL_FORMAT_MONO16, - data, freq); - } - - private void checkError() { - Com.DPrintf("AL Error: " + alErrorString() +'\n'); - } - - private String alErrorString(){ - int error; - String message = ""; - if ((error = AL10.alGetError()) != AL10.AL_NO_ERROR) { - switch(error) { - case AL10.AL_INVALID_OPERATION: message = "invalid operation"; break; - case AL10.AL_INVALID_VALUE: message = "invalid value"; break; - case AL10.AL_INVALID_ENUM: message = "invalid enum"; break; - case AL10.AL_INVALID_NAME: message = "invalid name"; break; - default: message = "" + error; - } - } - return message; - } - - /* (non-Javadoc) - * @see jake2.sound.SoundImpl#Shutdown() - */ - public void Shutdown() { - StopAllSounds(); - Channel.shutdown(); - AL10.alDeleteBuffers(buffers); - exitOpenAL(); - - Cmd.RemoveCommand("play"); - Cmd.RemoveCommand("stopsound"); - Cmd.RemoveCommand("soundlist"); - Cmd.RemoveCommand("soundinfo"); - - // free all sounds - for (int i = 0; i < num_sfx; i++) { - if (known_sfx[i].name == null) - continue; - known_sfx[i].clear(); - } - num_sfx = 0; - } - - /* (non-Javadoc) - * @see jake2.sound.SoundImpl#StartSound(float[], int, int, jake2.sound.sfx_t, float, float, float) - */ - public void StartSound(float[] origin, int entnum, int entchannel, sfx_t sfx, float fvol, float attenuation, float timeofs) { - - if (sfx == null) - return; - - if (sfx.name.charAt(0) == '*') - sfx = RegisterSexedSound(Globals.cl_entities[entnum].current, sfx.name); - - if (LoadSound(sfx) == null) - return; // can't load sound - - if (attenuation != Defines.ATTN_STATIC) - attenuation *= 0.5f; - - PlaySound.allocate(origin, entnum, entchannel, buffers.get(sfx.bufferId), fvol, attenuation, timeofs); - } - - private FloatBuffer listenerOrigin = Lib.newFloatBuffer(3); - private FloatBuffer listenerOrientation = Lib.newFloatBuffer(6); - - /* (non-Javadoc) - * @see jake2.sound.SoundImpl#Update(float[], float[], float[], float[]) - */ - public void Update(float[] origin, float[] forward, float[] right, float[] up) { - - Channel.convertVector(origin, listenerOrigin); - AL10.alListener(AL10.AL_POSITION, listenerOrigin); - - Channel.convertOrientation(forward, up, listenerOrientation); - AL10.alListener(AL10.AL_ORIENTATION, listenerOrientation); - - // set the master volume - AL10.alListenerf(AL10.AL_GAIN, s_volume.value); - - Channel.addLoopSounds(); - Channel.addPlaySounds(); - Channel.playAllSounds(listenerOrigin); - } - - /* (non-Javadoc) - * @see jake2.sound.SoundImpl#StopAllSounds() - */ - public void StopAllSounds() { - // mute the listener (master) - AL10.alListenerf(AL10.AL_GAIN, 0); - PlaySound.reset(); - Channel.reset(); - } - - /* (non-Javadoc) - * @see jake2.sound.Sound#getName() - */ - public String getName() { - return "lwjgl"; - } - - int s_registration_sequence; - boolean s_registering; - - /* (non-Javadoc) - * @see jake2.sound.Sound#BeginRegistration() - */ - public void BeginRegistration() { - s_registration_sequence++; - s_registering = true; - } - - /* (non-Javadoc) - * @see jake2.sound.Sound#RegisterSound(java.lang.String) - */ - public sfx_t RegisterSound(String name) { - sfx_t sfx = FindName(name, true); - sfx.registration_sequence = s_registration_sequence; - - if (!s_registering) - LoadSound(sfx); - - return sfx; - } - - /* (non-Javadoc) - * @see jake2.sound.Sound#EndRegistration() - */ - public void EndRegistration() { - int i; - sfx_t sfx; - // free any sounds not from this registration sequence - for (i = 0; i < num_sfx; i++) { - sfx = known_sfx[i]; - if (sfx.name == null) - continue; - if (sfx.registration_sequence != s_registration_sequence) { - // don't need this sound - sfx.clear(); - } - } - - // load everything in - for (i = 0; i < num_sfx; i++) { - sfx = known_sfx[i]; - if (sfx.name == null) - continue; - LoadSound(sfx); - } - - s_registering = false; - } - - sfx_t RegisterSexedSound(entity_state_t ent, String base) { - - sfx_t sfx = null; - - // determine what model the client is using - String model = null; - int n = Globals.CS_PLAYERSKINS + ent.number - 1; - if (Globals.cl.configstrings[n] != null) { - int p = Globals.cl.configstrings[n].indexOf('\\'); - if (p >= 0) { - p++; - model = Globals.cl.configstrings[n].substring(p); - //strcpy(model, p); - p = model.indexOf('/'); - if (p > 0) - model = model.substring(0, p); - } - } - // if we can't figure it out, they're male - if (model == null || model.length() == 0) - model = "male"; - - // see if we already know of the model specific sound - String sexedFilename = "#players/" + model + "/" + base.substring(1); - //Com_sprintf (sexedFilename, sizeof(sexedFilename), "#players/%s/%s", model, base+1); - sfx = FindName(sexedFilename, false); - - if (sfx != null) return sfx; - - // - // fall back strategies - // - // not found , so see if it exists - if (FS.FileLength(sexedFilename.substring(1)) > 0) { - // yes, register it - return RegisterSound(sexedFilename); - } - // try it with the female sound in the pak0.pak - if (model.equalsIgnoreCase("female")) { - String femaleFilename = "player/female/" + base.substring(1); - if (FS.FileLength("sound/" + femaleFilename) > 0) - return AliasName(sexedFilename, femaleFilename); - } - // no chance, revert to the male sound in the pak0.pak - String maleFilename = "player/male/" + base.substring(1); - return AliasName(sexedFilename, maleFilename); - } - - - static sfx_t[] known_sfx = new sfx_t[MAX_SFX]; - static { - for (int i = 0; i< known_sfx.length; i++) - known_sfx[i] = new sfx_t(); - } - static int num_sfx; - - sfx_t FindName(String name, boolean create) { - int i; - sfx_t sfx = null; - - if (name == null) - Com.Error(Defines.ERR_FATAL, "S_FindName: NULL\n"); - if (name.length() == 0) - Com.Error(Defines.ERR_FATAL, "S_FindName: empty name\n"); - - if (name.length() >= Defines.MAX_QPATH) - Com.Error(Defines.ERR_FATAL, "Sound name too long: " + name); - - // see if already loaded - for (i = 0; i < num_sfx; i++) - if (name.equals(known_sfx[i].name)) { - return known_sfx[i]; - } - - if (!create) - return null; - - // find a free sfx - for (i = 0; i < num_sfx; i++) - if (known_sfx[i].name == null) - // registration_sequence < s_registration_sequence) - break; - - if (i == num_sfx) { - if (num_sfx == MAX_SFX) - Com.Error(Defines.ERR_FATAL, "S_FindName: out of sfx_t"); - num_sfx++; - } - - sfx = known_sfx[i]; - sfx.clear(); - sfx.name = name; - sfx.registration_sequence = s_registration_sequence; - sfx.bufferId = i; - - return sfx; - } - - /* - ================== - S_AliasName - - ================== - */ - sfx_t AliasName(String aliasname, String truename) - { - sfx_t sfx = null; - String s; - int i; - - s = new String(truename); - - // find a free sfx - for (i=0 ; i < num_sfx ; i++) - if (known_sfx[i].name == null) - break; - - if (i == num_sfx) - { - if (num_sfx == MAX_SFX) - Com.Error(Defines.ERR_FATAL, "S_FindName: out of sfx_t"); - num_sfx++; - } - - sfx = known_sfx[i]; - sfx.clear(); - sfx.name = new String(aliasname); - sfx.registration_sequence = s_registration_sequence; - sfx.truename = s; - // set the AL bufferId - sfx.bufferId = i; - - return sfx; - } - - /* - ============== - S_LoadSound - ============== - */ - public sfxcache_t LoadSound(sfx_t s) { - if (s.isCached) return s.cache; - sfxcache_t sc = WaveLoader.LoadSound(s); - if (sc != null) { - initBuffer(sc.data, s.bufferId, sc.speed); - s.isCached = true; - // free samples for GC - s.cache.data = null; - } - return sc; - } - - /* (non-Javadoc) - * @see jake2.sound.Sound#StartLocalSound(java.lang.String) - */ - public void StartLocalSound(String sound) { - sfx_t sfx; - - sfx = RegisterSound(sound); - if (sfx == null) { - Com.Printf("S_StartLocalSound: can't cache " + sound + "\n"); - return; - } - StartSound(null, Globals.cl.playernum + 1, 0, sfx, 1, 1, 0); - } - - private ShortBuffer streamBuffer = sfxDataBuffer.slice().order(ByteOrder.BIG_ENDIAN).asShortBuffer(); - - /* (non-Javadoc) - * @see jake2.sound.Sound#RawSamples(int, int, int, int, byte[]) - */ - public void RawSamples(int samples, int rate, int width, int channels, ByteBuffer data) { - int format; - if (channels == 2) { - format = (width == 2) ? AL10.AL_FORMAT_STEREO16 - : AL10.AL_FORMAT_STEREO8; - } else { - format = (width == 2) ? AL10.AL_FORMAT_MONO16 - : AL10.AL_FORMAT_MONO8; - } - - // convert to signed 16 bit samples - if (format == AL10.AL_FORMAT_MONO8) { - ShortBuffer sampleData = streamBuffer; - int value; - for (int i = 0; i < samples; i++) { - value = (data.get(i) & 0xFF) - 128; - sampleData.put(i, (short) value); - } - format = AL10.AL_FORMAT_MONO16; - width = 2; - data = sfxDataBuffer.slice(); - } - - Channel.updateStream(data, samples * channels * width, format, rate); - } - - public void disableStreaming() { - Channel.disableStreaming(); - } - /* - =============================================================================== - - console functions - - =============================================================================== - */ - - void Play() { - int i; - String name; - sfx_t sfx; - - i = 1; - while (i < Cmd.Argc()) { - name = new String(Cmd.Argv(i)); - if (name.indexOf('.') == -1) - name += ".wav"; - - sfx = RegisterSound(name); - StartSound(null, Globals.cl.playernum + 1, 0, sfx, 1.0f, 1.0f, 0.0f); - i++; - } - } - - void SoundList() { - int i; - sfx_t sfx; - sfxcache_t sc; - int size, total; - - total = 0; - for (i = 0; i < num_sfx; i++) { - sfx = known_sfx[i]; - if (sfx.registration_sequence == 0) - continue; - sc = sfx.cache; - if (sc != null) { - size = sc.length * sc.width * (sc.stereo + 1); - total += size; - if (sc.loopstart >= 0) - Com.Printf("L"); - else - Com.Printf(" "); - Com.Printf("(%2db) %6i : %s\n", new Vargs(3).add(sc.width * 8).add(size).add(sfx.name)); - } else { - if (sfx.name.charAt(0) == '*') - Com.Printf(" placeholder : " + sfx.name + "\n"); - else - Com.Printf(" not loaded : " + sfx.name + "\n"); - } - } - Com.Printf("Total resident: " + total + "\n"); - } - - void SoundInfo_f() { - - Com.Printf("%5d stereo\n", new Vargs(1).add(1)); - Com.Printf("%5d samples\n", new Vargs(1).add(22050)); - Com.Printf("%5d samplebits\n", new Vargs(1).add(16)); - Com.Printf("%5d speed\n", new Vargs(1).add(44100)); - } - -} diff --git a/src/jake2/sound/lwjgl/PlaySound.java b/src/jake2/sound/lwjgl/PlaySound.java deleted file mode 100644 index 1e3c4f8..0000000 --- a/src/jake2/sound/lwjgl/PlaySound.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Created on Dec 22, 2004 - * - * Copyright (C) 2003 - * - * $Id: PlaySound.java,v 1.2 2005-05-08 13:37:46 cawe Exp $ - */ -/* -Copyright (C) 1997-2001 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 the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ -package jake2.sound.lwjgl; - -import jake2.Globals; -import jake2.util.Math3D; - -/** - * PlaySound - * - * @author cwei - */ -public class PlaySound { - - final static int MAX_PLAYSOUNDS = 128; - - // list with sentinel - private static PlaySound freeList; - private static PlaySound playableList; - - private static PlaySound[] backbuffer = new PlaySound[MAX_PLAYSOUNDS]; - static { - for (int i = 0; i < backbuffer.length; i++) { - backbuffer[i] = new PlaySound(); - } - // init the sentinels - freeList = new PlaySound(); - playableList = new PlaySound(); - // reset the lists - reset(); - } - - // sound attributes - int type; - int entnum; - int entchannel; - int bufferId; - float volume; - float attenuation; - float[] origin = {0,0,0}; - - // begin time in ms - private long beginTime; - - // for linked list - private PlaySound prev, next; - - private PlaySound() { - prev = next = null; - this.clear(); - } - - private void clear() { - type = bufferId = entnum = entchannel = -1; - // volume = attenuation = beginTime = 0; - attenuation = beginTime = 0; - // Math3D.VectorClear(origin); - } - - static void reset() { - // init the sentinels - freeList.next = freeList.prev = freeList; - playableList.next = playableList.prev = playableList; - - // concat the the freeList - PlaySound ps; - for (int i = 0; i < backbuffer.length; i++) { - ps = backbuffer[i]; - ps.clear(); - ps.prev = freeList; - ps.next = freeList.next; - ps.prev.next = ps; - ps.next.prev = ps; - } - } - - static PlaySound nextPlayableSound() { - PlaySound ps = null; - while (true) { - ps = playableList.next; - if (ps == playableList || ps.beginTime > Globals.cl.time) - return null; - PlaySound.release(ps); - return ps; - } - } - - private static PlaySound get() { - PlaySound ps = freeList.next; - if (ps == freeList) - return null; - - ps.prev.next = ps.next; - ps.next.prev = ps.prev; - return ps; - } - - private static void add(PlaySound ps) { - - PlaySound sort = playableList.next; - - for (; sort != playableList && sort.beginTime < ps.beginTime; sort = sort.next); - ps.next = sort; - ps.prev = sort.prev; - ps.next.prev = ps; - ps.prev.next = ps; - } - - private static void release(PlaySound ps) { - ps.prev.next = ps.next; - ps.next.prev = ps.prev; - // add to free list - ps.next = freeList.next; - freeList.next.prev = ps; - ps.prev = freeList; - freeList.next = ps; - } - - static void allocate(float[] origin, int entnum, int entchannel, - int bufferId, float volume, float attenuation, float timeoffset) { - - PlaySound ps = PlaySound.get(); - - if (ps != null) { - // find the right sound type - if (entnum == Globals.cl.playernum + 1) { - ps.type = Channel.LISTENER; - } else if (origin != null) { - ps.type = Channel.FIXED; - Math3D.VectorCopy(origin, ps.origin); - } else { - ps.type = Channel.DYNAMIC; - } - ps.entnum = entnum; - ps.entchannel = entchannel; - ps.bufferId = bufferId; - ps.volume = volume; - ps.attenuation = attenuation; - ps.beginTime = Globals.cl.time + (long)(timeoffset * 1000); - PlaySound.add(ps); - } else { - System.err.println("PlaySounds out of Limit"); - } - } -} diff --git a/src/jake2/sys/LWJGLKBD.java b/src/jake2/sys/LWJGLKBD.java deleted file mode 100644 index 8826360..0000000 --- a/src/jake2/sys/LWJGLKBD.java +++ /dev/null @@ -1,214 +0,0 @@ -package jake2.sys; - -import jake2.Defines; -import jake2.Globals; -import jake2.client.Key; -import jake2.qcommon.Cbuf; - -import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.Display; - -/** - * @author dsanders - */ -public class LWJGLKBD extends KBD { - - private char[] lwjglKeycodeMap = null; - private int pressed[] = null; - - public void Init() - { - try - { - if (!Keyboard.isCreated()) Keyboard.create(); - if (!Mouse.isCreated()) Mouse.create(); - - if (lwjglKeycodeMap == null) lwjglKeycodeMap = new char[256]; - if (pressed == null) pressed = new int[256]; - - lastRepeat = Timer.Milliseconds(); - } catch (Exception e) {;} - } - - public void Update() { - // get events - HandleEvents(); - } - - public void Close() { - Keyboard.destroy(); - Mouse.destroy(); - // free the memory for GC - lwjglKeycodeMap = null; - pressed = null; - } - - private void HandleEvents() - { - Keyboard.poll(); - - if (Display.isCloseRequested()) - { - Cbuf.ExecuteText(Defines.EXEC_APPEND, "quit"); - } - - while (Keyboard.next()) - { - int key = Keyboard.getEventKey(); - char ch = Keyboard.getEventCharacter(); - boolean down = Keyboard.getEventKeyState(); - - // fill the character translation table - // this is needed because the getEventCharacter() returns \0 if a key is released - // keycode is correct but the charachter value is not - if (down) { - lwjglKeycodeMap[key] = ch; - pressed[key] = Globals.sys_frame_time; - } else { - pressed[key] = 0; - } - - Do_Key_Event(XLateKey(key,ch), down); - } - - generateRepeats(); - - if (IN.mouse_active) - { - mx = Mouse.getDX() << 1; - my = -Mouse.getDY() << 1; - } - else - { - mx=0; - my=0; - } - - while (Mouse.next()) { - int button = Mouse.getEventButton(); - if (button >= 0) { - Do_Key_Event(Key.K_MOUSE1 + button, Mouse.getEventButtonState()); - } else { - button = Mouse.getEventDWheel(); - if (button > 0) { - Do_Key_Event(Key.K_MWHEELUP, true); - Do_Key_Event(Key.K_MWHEELUP, false); - } else if (button < 0) { - Do_Key_Event(Key.K_MWHEELDOWN, true); - Do_Key_Event(Key.K_MWHEELDOWN, false); - } - } - } - } - - private static int lastRepeat; - private void generateRepeats() { - int time = Globals.sys_frame_time; - if (time - lastRepeat > 50) { - for (int i = 0; i < pressed.length; i++) { - if (pressed[i] > 0 && time - pressed[i] > 500) - Do_Key_Event(XLateKey(i, lwjglKeycodeMap[i]), true); - } - lastRepeat = time; - } - } - - private int XLateKey(int code, int ch) - { - int key = 0; - - switch(code) - { -// 00626 case XK_KP_Page_Up: key = K_KP_PGUP; break; - case Keyboard.KEY_PRIOR: key = Key.K_PGUP; break; - -// 00629 case XK_KP_Page_Down: key = K_KP_PGDN; break; - case Keyboard.KEY_NEXT: key = Key.K_PGDN; break; - -// 00632 case XK_KP_Home: key = K_KP_HOME; break; - case Keyboard.KEY_HOME: key = Key.K_HOME; break; - -// 00635 case XK_KP_End: key = K_KP_END; break; - case Keyboard.KEY_END: key = Key.K_END; break; - - // case Keyboard.KEY_LEFT: key = Key.K_KP_LEFTARROW; break; - case Keyboard.KEY_LEFT: key = Key.K_LEFTARROW; break; - - // case Keyboard.KEY_RIGHT: key = Key.K_KP_RIGHTARROW; break; - case Keyboard.KEY_RIGHT: key = Key.K_RIGHTARROW; break; - - // case Keyboard.KEY_DOWN: key = Key.K_KP_DOWNARROW; break; - case Keyboard.KEY_DOWN: key = Key.K_DOWNARROW; break; - - // case Keyboard.KEY_UP: key = Key.K_KP_UPARROW; break; - case Keyboard.KEY_UP: key = Key.K_UPARROW; break; - - case Keyboard.KEY_ESCAPE: key = Key.K_ESCAPE; break; - - - case Keyboard.KEY_RETURN: key = Key.K_ENTER; break; -// 00652 case XK_KP_Enter: key = K_KP_ENTER; break; - - case Keyboard.KEY_TAB: key = Key.K_TAB; break; - - case Keyboard.KEY_F1: key = Key.K_F1; break; - case Keyboard.KEY_F2: key = Key.K_F2; break; - case Keyboard.KEY_F3: key = Key.K_F3; break; - case Keyboard.KEY_F4: key = Key.K_F4; break; - case Keyboard.KEY_F5: key = Key.K_F5; break; - case Keyboard.KEY_F6: key = Key.K_F6; break; - case Keyboard.KEY_F7: key = Key.K_F7; break; - case Keyboard.KEY_F8: key = Key.K_F8; break; - case Keyboard.KEY_F9: key = Key.K_F9; break; - case Keyboard.KEY_F10: key = Key.K_F10; break; - case Keyboard.KEY_F11: key = Key.K_F11; break; - case Keyboard.KEY_F12: key = Key.K_F12; break; - - case Keyboard.KEY_BACK: key = Key.K_BACKSPACE; break; - - case Keyboard.KEY_DELETE: key = Key.K_DEL; break; -// 00683 case XK_KP_Delete: key = K_KP_DEL; break; - - case Keyboard.KEY_PAUSE: key = Key.K_PAUSE; break; - - case Keyboard.KEY_RSHIFT: - case Keyboard.KEY_LSHIFT: key = Key.K_SHIFT; break; - - case Keyboard.KEY_RCONTROL: - case Keyboard.KEY_LCONTROL: key = Key.K_CTRL; break; - - case Keyboard.KEY_LMENU: - case Keyboard.KEY_RMENU: key = Key.K_ALT; break; - -// 00700 case XK_KP_Begin: key = K_KP_5; break; -// 00701 - case Keyboard.KEY_INSERT: key = Key.K_INS; break; - // toggle console for DE and US keyboards - case Keyboard.KEY_GRAVE: - case Keyboard.KEY_CIRCUMFLEX: key = '`'; break; - - default: - key = lwjglKeycodeMap[code]; - if (key >= 'A' && key <= 'Z') - key = key - 'A' + 'a'; - break; - } - if (key > 255) key = 0; - return key; - } - - public void Do_Key_Event(int key, boolean down) { - Key.Event(key, down, Timer.Milliseconds()); - } - - public void installGrabs() - { - Mouse.setGrabbed(true); - } - - public void uninstallGrabs() - { - Mouse.setGrabbed(false); - } -} |