This commit was manufactured by cvs2svn to create tag 'lwjgl05'.
256
build.xml
|
@ -1,256 +0,0 @@
|
|||
<project name="LWJGL" default="compile" basedir=".">
|
||||
|
||||
<!-- set global properties for this build -->
|
||||
<property name="lwjgl.src" value="./src"/>
|
||||
<property name="lwjgl.bin" value="./bin"/>
|
||||
<property name="lwjgl.lib" value="./lib"/>
|
||||
<property name="lwjgl.dist" value="./dist"/>
|
||||
<property name="lwjgl.docs" value="./doc"/>
|
||||
<property name="lwjgl.temp" value="./temp"/>
|
||||
<property name="lwjgl.res" value="./res"/>
|
||||
<property name="lwjgl.version" value="0.5"/>
|
||||
<property name="lwjgl.src.headers" value="${lwjgl.src}/native/common"/>
|
||||
|
||||
<!-- Creates a splash screen -->
|
||||
<target name="splash">
|
||||
<splash imageurl="http://java-game-lib.sourceforge.net/images/logo.png" showduration="0" taskname="progressscreen"/>
|
||||
</target>
|
||||
|
||||
<!-- Initializes whatever needs to be done before any targets are executed -->
|
||||
<target name="initialize">
|
||||
<mkdir dir="${lwjgl.bin}" taskname="initialiazing bin folder"/>
|
||||
<mkdir dir="${lwjgl.lib}" taskname="initialiazing lib folder"/>
|
||||
<mkdir dir="${lwjgl.dist}" taskname="initialiazing dist folder"/>
|
||||
<mkdir dir="${lwjgl.docs}/javadoc" taskname="initialiazing docs folder"/>
|
||||
<mkdir dir="${lwjgl.res}" taskname="initialiazing res folder"/>
|
||||
<mkdir dir="${lwjgl.temp}" taskname="initialiazing temp folder"/>
|
||||
</target>
|
||||
|
||||
<target name="all" depends="splash" description="compile. package. javadoc and distribute">
|
||||
|
||||
<!--
|
||||
Though we perform all targets, we do it in somewhat mixed.
|
||||
This is because we want the 'distribution_application' target to be
|
||||
executed as soon as possible, since this target is most likely to fail.
|
||||
That way we don't spend time doing javadocs, if the 'distribution_application'
|
||||
target is going to fail anyway. However we cannot call the 'distribution' before
|
||||
the javadoc target, since the 'distribution' target will try to create the javadoc
|
||||
archive.
|
||||
-->
|
||||
|
||||
<antcall target="clean"/>
|
||||
<antcall target="compile"/>
|
||||
<antcall target="package"/>
|
||||
<antcall target="distribution_application"/>
|
||||
<antcall target="javadoc"/>
|
||||
<antcall target="distribution_javadoc"/>
|
||||
<antcall target="distribution_source"/>
|
||||
<antcall target="internal_clean"/>
|
||||
</target>
|
||||
|
||||
<target name="clean" description="Cleans the diectories controlled by this ant script (temp, dist, lib, javadoc, class files in bin)">
|
||||
<delete dir="${lwjgl.temp}" quiet="true" taskname="cleaning temp folder"/>
|
||||
<delete dir="${lwjgl.dist}" quiet="true" taskname="cleaning dist folder"/>
|
||||
<delete dir="${lwjgl.docs}/javadoc" quiet="true" taskname="cleaning javadoc folder"/>
|
||||
<delete dir="${lwjgl.bin}/org" quiet="true" taskname="cleaning bin folder"/>
|
||||
<delete taskname="cleaning bin folder">
|
||||
<fileset dir="${lwjgl.bin}" includes="*.class"/>
|
||||
</delete>
|
||||
</target>
|
||||
|
||||
<target name="compile" depends="initialize" description="Compiles the java source directory">
|
||||
<javac srcdir="${lwjgl.src}/java/" destdir="${lwjgl.bin}" includes="org/lwjgl/**.java" source="1.4" taskname="lwjgl"/>
|
||||
<javac srcdir="${lwjgl.src}/java/" destdir="${lwjgl.bin}" includes="org/lwjgl/input/**" source="1.4" taskname="input"/>
|
||||
<javac srcdir="${lwjgl.src}/java/" destdir="${lwjgl.bin}" includes="org/lwjgl/openal/**" source="1.4" taskname="openal"/>
|
||||
<javac srcdir="${lwjgl.src}/java/" destdir="${lwjgl.bin}" includes="org/lwjgl/opengl/**" source="1.4" taskname="opengl"/>
|
||||
<javac srcdir="${lwjgl.src}/java/" destdir="${lwjgl.bin}" includes="org/lwjgl/test/**" source="1.4" taskname="test"/>
|
||||
<javac srcdir="${lwjgl.src}/java/" destdir="${lwjgl.bin}" includes="org/lwjgl/vector/**" source="1.4" taskname="vector"/>
|
||||
<javac srcdir="examples/" destdir="${lwjgl.bin}/" includes="**" source="1.4" taskname="examples"/>
|
||||
</target>
|
||||
|
||||
<target name="package" depends="compile" description="packages the java source files">
|
||||
<!-- Create lwjgl.jar -->
|
||||
<jar destfile="${lwjgl.lib}/lwjgl.jar" taskname="lwjgl.jar">
|
||||
<fileset dir="${lwjgl.bin}">
|
||||
<include name="**"/>
|
||||
<exclude name="**.*"/>
|
||||
<exclude name="org/lwjgl/test/**"/>
|
||||
</fileset>
|
||||
</jar>
|
||||
|
||||
<!-- Create lwjgl_test.jar -->
|
||||
<jar destfile="${lwjgl.lib}/lwjgl_test.jar" taskname="lwjgl_test.jar">
|
||||
<fileset dir="${lwjgl.bin}">
|
||||
<exclude name="**.*"/>
|
||||
<include name="org/lwjgl/test/**"/>
|
||||
</fileset>
|
||||
</jar>
|
||||
|
||||
<!-- Create examples.jar -->
|
||||
<jar destfile="${lwjgl.lib}/examples.jar" taskname="examples.jar">
|
||||
<fileset dir="${lwjgl.bin}">
|
||||
<include name="**.class"/>
|
||||
</fileset>
|
||||
<fileset dir="${lwjgl.res}">
|
||||
<include name="data/**"/>
|
||||
</fileset>
|
||||
</jar>
|
||||
|
||||
<!-- copy dll/so to lib directory -->
|
||||
<copy todir="${lwjgl.lib}" taskname="libraries">
|
||||
<fileset dir="${lwjgl.bin}">
|
||||
<include name="lwjgl.dll"/>
|
||||
<include name="lwjgl_d.dll"/>
|
||||
<include name="liblwjgl.so"/>
|
||||
<include name="liblwjgl_d.so"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="javadoc" description="Creates javadoc from java source code">
|
||||
<javadoc destdir="${lwjgl.docs}/javadoc" author="true" version="true" use="true" source="1.4" windowtitle="LWJGL API">
|
||||
|
||||
<fileset dir="${lwjgl.src}/java">
|
||||
<include name="**" />
|
||||
<exclude name="org/lwjgl/test/**"/>
|
||||
</fileset>
|
||||
|
||||
<doctitle><![CDATA[<h1>Lightweight Java Game Toolkit</h1>]]></doctitle>
|
||||
<bottom><![CDATA[<i>Copyright © 2002 lwjgl.org. All Rights Reserved.</i>]]></bottom>
|
||||
</javadoc>
|
||||
</target>
|
||||
|
||||
<target name="distribution" depends="package" description="Creates a versioned distribution of lwjgl">
|
||||
<antcall target="distribution_application"/>
|
||||
<antcall target="distribution_javadoc"/>
|
||||
<antcall target="distribution_source"/>
|
||||
<antcall target="internal_clean"/>
|
||||
</target>
|
||||
|
||||
<target name="cvsbuild" description="Builds lwjgl, by exporting files from cvs into a LWJGL folder and executing the package target on that folders build file">
|
||||
<available file="LWJGL/build.xml" property="lwjgl.preexistingfiles"/>
|
||||
<available file="${lwjgl.src}/java/org/lwjgl/Sys.java" property="lwjgl.preexistingfiles"/>
|
||||
<fail if="lwjgl.preexistingfiles" message="Cannot perform webbuild from nonempty folder"/>
|
||||
<cvs command="export -D 'now'" compressionlevel="3" cvsRoot=":pserver:anonymous@cvs.sf.net:/cvsroot/java-game-lib" package="LWJGL/build.xml" dest="."/>
|
||||
<cvs command="export -D 'now'" compressionlevel="3" cvsRoot=":pserver:anonymous@cvs.sf.net:/cvsroot/java-game-lib" package="LWJGL/src" dest="."/>
|
||||
<cvs command="export -D 'now'" compressionlevel="3" cvsRoot=":pserver:anonymous@cvs.sf.net:/cvsroot/java-game-lib" package="LWJGL/examples" dest="."/>
|
||||
<cvs command="export -D 'now'" compressionlevel="3" cvsRoot=":pserver:anonymous@cvs.sf.net:/cvsroot/java-game-lib" package="LWJGL/doc" dest="."/>
|
||||
<ant dir="LWJGL" target="package"/>
|
||||
</target>
|
||||
|
||||
<target name="headers" description="invokes javah on java classes, producing the headers needed for native compilation" depends="compile">
|
||||
<javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.headers}" force="yes">
|
||||
<class name="org.lwjgl.Display"/>
|
||||
<class name="org.lwjgl.Sys"/>
|
||||
<class name="org.lwjgl.input.Controller"/>
|
||||
<class name="org.lwjgl.input.Keyboard"/>
|
||||
<class name="org.lwjgl.input.Mouse"/>
|
||||
<class name="org.lwjgl.Math$MatrixOpAdd$MatrixOpSafe"/>
|
||||
<class name="org.lwjgl.Math$MatrixOpAdd$MatrixOpDirect"/>
|
||||
<class name="org.lwjgl.Math$MatrixOpCopy$MatrixOpSafe"/>
|
||||
<class name="org.lwjgl.Math$MatrixOpCopy$MatrixOpDirect"/>
|
||||
<class name="org.lwjgl.Math$MatrixOpInvert$MatrixOpSafe"/>
|
||||
<class name="org.lwjgl.Math$MatrixOpInvert$MatrixOpDirect"/>
|
||||
<class name="org.lwjgl.Math$MatrixOpMultiply$MatrixOpSafe"/>
|
||||
<class name="org.lwjgl.Math$MatrixOpMultiply$MatrixOpDirect"/>
|
||||
<class name="org.lwjgl.Math$MatrixOpNegate$MatrixOpSafe"/>
|
||||
<class name="org.lwjgl.Math$MatrixOpNegate$MatrixOpDirect"/>
|
||||
<class name="org.lwjgl.Math$MatrixOpNormalise$MatrixOpSafe"/>
|
||||
<class name="org.lwjgl.Math$MatrixOpNormalise$MatrixOpDirect"/>
|
||||
<class name="org.lwjgl.Math$MatrixOpSubtract$MatrixOpSafe"/>
|
||||
<class name="org.lwjgl.Math$MatrixOpSubtract$MatrixOpDirect"/>
|
||||
<class name="org.lwjgl.openal.ALC"/>
|
||||
<class name="org.lwjgl.openal.BaseAL"/>
|
||||
<class name="org.lwjgl.openal.CoreAL"/>
|
||||
<class name="org.lwjgl.openal.eax.BaseEAX"/>
|
||||
<class name="org.lwjgl.openal.eax.CoreEAX"/>
|
||||
<class name="org.lwjgl.openal.eax.EAXBufferProperties"/>
|
||||
<class name="org.lwjgl.openal.eax.EAXListenerProperties"/>
|
||||
<class name="org.lwjgl.opengl.BaseGL"/>
|
||||
<class name="org.lwjgl.opengl.CoreGL"/>
|
||||
<class name="org.lwjgl.opengl.GL"/>
|
||||
<class name="org.lwjgl.opengl.GLU"/>
|
||||
</javah>
|
||||
</target>
|
||||
|
||||
<!-- Creates a versioned distribution of dll's and jars -->
|
||||
<target name="distribution_application">
|
||||
<!-- check for file presence -->
|
||||
<available file="${lwjgl.lib}/OpenAL32.dll" property="lwjgl.OpenAL32_dll.exists"/>
|
||||
<fail unless="lwjgl.OpenAL32_dll.exists" message="Missing OpenAL32.dll in lib directory"/>
|
||||
|
||||
<available file="${lwjgl.lib}/libopenal.so" property="lwjgl.libopenal_so.exists"/>
|
||||
<fail unless="lwjgl.libopenal_so.exists" message="Missing libopenal.so in lib directory"/>
|
||||
|
||||
<available file="${lwjgl.lib}/lwjgl.dll" property="lwjgl.lwjgl_dll.exists"/>
|
||||
<fail unless="lwjgl.lwjgl_dll.exists" message="Missing lwjgl.dll in lib directory"/>
|
||||
|
||||
<available file="${lwjgl.lib}/lwjgl_d.dll" property="lwjgl.lwjgl_d_dll.exists"/>
|
||||
<fail unless="lwjgl.lwjgl_d_dll.exists" message="Missing lwjgl_d.dll in lib directory"/>
|
||||
|
||||
<available file="${lwjgl.lib}/liblwjgl.so" property="lwjgl.liblwjgl_so.exists"/>
|
||||
<fail unless="lwjgl.liblwjgl_so.exists" message="Missing liblwjgl.so in lib directory"/>
|
||||
|
||||
<available file="${lwjgl.lib}/liblwjgl_d.so" property="lwjgl.liblwjgl_d_so.exists"/>
|
||||
<fail unless="lwjgl.liblwjgl_d_so.exists" message="Missing liblwjgl_d.so in lib directory"/>
|
||||
|
||||
<available file="${lwjgl.lib}/lwjgl.jar" property="lwjgl.lwjgl_jar.exists"/>
|
||||
<fail unless="lwjgl.lwjgl_jar.exists" message="Missing lwjgl.jar in lib directory"/>
|
||||
|
||||
<available file="${lwjgl.lib}/lwjgl_test.jar" property="lwjgl.lwjgl_test_jar.exists"/>
|
||||
<fail unless="lwjgl.lwjgl_test_jar.exists" message="Missing lwjgl_test.jar in lib directory"/>
|
||||
|
||||
<available file="${lwjgl.lib}/examples.jar" property="lwjgl.examples_jar.exists"/>
|
||||
<fail unless="lwjgl.examples_jar.exists" message="Missing examples.jar in lib directory"/>
|
||||
|
||||
<mkdir dir="${lwjgl.temp}/lwjgl-${lwjgl.version}"/>
|
||||
|
||||
<!-- copy files to lwjgl directory for proper zipping -->
|
||||
<copy todir="${lwjgl.temp}/lwjgl-${lwjgl.version}">
|
||||
<fileset dir="${lwjgl.lib}/">
|
||||
<include name="lwjgl.dll"/>
|
||||
<include name="lwjgl_d.dll"/>
|
||||
<include name="lwjgl.so"/>
|
||||
<include name="lwjgl_d.so"/>
|
||||
<include name="lwjgl.jar"/>
|
||||
<include name="lwjgl_test.jar"/>
|
||||
<include name="examples.jar"/>
|
||||
</fileset>
|
||||
<fileset dir="${lwjgl.docs}">
|
||||
<include name="CREDITS"/>
|
||||
<include name="LICENSE"/>
|
||||
<include name="README"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
|
||||
<!-- zip 'em up -->
|
||||
<zip destfile="${lwjgl.dist}/lwjgl-${lwjgl.version}.zip" basedir="${lwjgl.temp}/"/>
|
||||
</target>
|
||||
|
||||
<!-- Creates a versioned distribution of javadocs -->
|
||||
<target name="distribution_javadoc">
|
||||
<zip destfile="${lwjgl.dist}/lwjgl-docs-${lwjgl.version}.zip" basedir="${lwjgl.docs}" includes="javadoc/**"/>
|
||||
</target>
|
||||
|
||||
<!-- Creates a versioned distribution of the source code -->
|
||||
<target name="distribution_source">
|
||||
<zip destfile="${lwjgl.dist}/lwjgl-source-${lwjgl.version}.zip">
|
||||
<fileset dir="${lwjgl.src}/">
|
||||
<patternset>
|
||||
<include name="**/*.java"/>
|
||||
<include name="**/*.cpp"/>
|
||||
<include name="**/*.c"/>
|
||||
<include name="**/*.h"/>
|
||||
<include name="**/*.am"/>
|
||||
<exclude name="**/*CVS*"/>
|
||||
<exclude name="**/.*"/>
|
||||
</patternset>
|
||||
</fileset>
|
||||
</zip>
|
||||
</target>
|
||||
|
||||
<!-- clean internal temporary directories -->
|
||||
<target name="internal_clean">
|
||||
<delete dir="${lwjgl.temp}" taskname="cleanup"/>
|
||||
</target>
|
||||
</project>
|
12
doc/CREDITS
|
@ -1,12 +0,0 @@
|
|||
The following people have helped to make this project what it is today:
|
||||
- Caspian Rychlik-Prince <cprince@shavenpuppy.com>
|
||||
- Brian Matzon <brian@matzon.dk>
|
||||
- Niels Jørgensen <nj@niemo.com>
|
||||
- Tristan Campbell <tristan@happypedestrian.com>
|
||||
- Gregory Pierce <gregorypierce@yahoo.com>
|
||||
- Elias Naur <naur@odense.kollegienet.dk>
|
||||
- Luke Holden <lholden@users.sf.net>
|
||||
|
||||
additional credits goes to:
|
||||
- Joseph I. Valenzuela [OpenAL]
|
||||
- Lev Povalahev [OpenGL Extensions]
|
31
doc/LICENSE
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002 Lightweight Java Game Library Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'Light Weight Java Game Library' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
52
doc/README
|
@ -1,52 +0,0 @@
|
|||
This is the official readme file for lwjgl.
|
||||
|
||||
Unless otherwise stated, all files distributed or in CVS are covered by
|
||||
the license as stated in the LICENSE file. If you have not received this
|
||||
file, please download it from the cvs server.
|
||||
|
||||
To run any openal tests, you need to download the media file too, and
|
||||
extract it to the root directory.
|
||||
|
||||
To run some of the included tests:
|
||||
Extract the archive, and cd into directory
|
||||
Extract the media files into lwjgl folder (only needed for openal tests)
|
||||
|
||||
NeHe ports:
|
||||
java -cp .;examples.jar;lwjgl.jar; DEMO
|
||||
where DEMO is one of the following:
|
||||
BitmapFonts
|
||||
Blending
|
||||
DisplayLists
|
||||
FiltersLightingAndControl
|
||||
FirstPersonWorld
|
||||
FlagEffect
|
||||
Fog
|
||||
MovingStarBitmaps
|
||||
Polygon
|
||||
PolygonColored
|
||||
PolygonColoredRotating3D
|
||||
PolygonColoredRotating
|
||||
Quadrics
|
||||
TextureMapping
|
||||
|
||||
LWJGL Tests:
|
||||
java -cp .;lwjgl_test.jar;lwjgl.jar; DEMO
|
||||
where DEMO is one of the following:
|
||||
org.lwjgl.test.input.ControllerCreationTest (Requires attached Controller)
|
||||
org.lwjgl.test.input.ControllerTest (Requires attached Controller)
|
||||
org.lwjgl.test.input.MouseCreationTest
|
||||
org.lwjgl.test.input.MouseTest
|
||||
org.lwjgl.test.openal.ALCTest
|
||||
org.lwjgl.test.openal.ALTest
|
||||
org.lwjgl.test.openal.ALCTest
|
||||
org.lwjgl.test.openal.EAXTest (Requires EAX compatible hardware)
|
||||
org.lwjgl.test.openal.MovingSoundTest
|
||||
org.lwjgl.test.openal.PlayTest
|
||||
org.lwjgl.test.openal.PlayTestMemory
|
||||
org.lwjgl.test.openal.SourceLimitTest
|
||||
org.lwjgl.test.openal.StressTest
|
||||
org.lwjgl.test.opengl.Grass (Requires nVidia hardware)
|
||||
org.lwjgl.test.opengl.Game
|
||||
org.lwjgl.test.vector.MathTest
|
||||
|
||||
Project Webpage: http://sourceforge.net/projects/java-game-lib
|
|
@ -1 +0,0 @@
|
|||
Lightweight Java Game Library Javadocs
|
|
@ -1,87 +0,0 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>OpenAL Tutoral</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=windows-1252">
|
||||
<meta name="author" content="Brian Matzon">
|
||||
<meta name="description" content="Basic sound using OpenAL">
|
||||
</head>
|
||||
<body>
|
||||
<h1 align="center">Array Conversion<br>
|
||||
<font size="-1">(by Brian Matzon <<a href="mailto:brian@matzon.dk">brian@matzon.dk</a>>)</font><br>
|
||||
</h1>
|
||||
<b>1.0 About this document</b><br>
|
||||
This document describes the typical rules for converting arrays often used in
|
||||
C/C++ OpenAL (and indeed OpenGL too) code.<br>
|
||||
It is not bullet proof, but should handle most cases.<br>
|
||||
<br>
|
||||
<b>1.1 Array to ByteBuffer<br>
|
||||
</b>When using an array of some data type in C/C++
|
||||
you will typically convert that<br>
|
||||
to the corresponding ByteBuffer type. ie:<p
|
||||
style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"><tt>ALfloat
|
||||
floatv[3];</tt></p>
|
||||
<p>becomes</p>
|
||||
<p
|
||||
style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"><tt>
|
||||
FloatBuffer floatv = createFloatBuffer(3);</tt></p>
|
||||
<p>In this example, <tt>createFloatBuffer</tt>
|
||||
is this utility method:</p>
|
||||
<p
|
||||
style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"><tt>
|
||||
public FloatBuffer createFloatBuffer(int size) {<br>
|
||||
|
||||
//allocate bytebuffer, using 4 bytes per float<br>
|
||||
|
||||
ByteBuffer temp = ByteBuffer.allocateDirect(4*size);<br>
|
||||
|
||||
temp.order(ByteOrder.nativeOrder());<br>
|
||||
|
||||
<br>
|
||||
|
||||
return temp.asFloatBuffer();<br>
|
||||
}</tt></p>
|
||||
<p>
|
||||
<b>1.2 Examples</b><br>
|
||||
Using the above FloatBuffer, you would typically use it like this (examples
|
||||
taken from altest.c/ALTest.java):</p>
|
||||
<p>
|
||||
<b>1.2.1 Example 1</b></p>
|
||||
<p
|
||||
style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"><tt>
|
||||
alGetListenerfv(AL_POSITION, floatv);</tt></p>
|
||||
<p>
|
||||
becomes</p>
|
||||
<p
|
||||
style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"><tt>
|
||||
al.getListenerfv(AL.POSITION, Sys.getDirectBufferAddress(floatv));</tt></p>
|
||||
<p><b>1.2.2 Example 2</b></p>
|
||||
<p
|
||||
style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"><tt>
|
||||
if (floatv[0] != 100.0)) {</tt></p>
|
||||
<p>becomes:</p>
|
||||
<p
|
||||
style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"><tt>
|
||||
if (floatv.get(0) != 100.0f) {</tt></p>
|
||||
<p><b>1.2.3 Example 3</b></p>
|
||||
<p
|
||||
style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"><tt>
|
||||
alGetListener3f(AL_POSITION, &floatv[0], <br>
|
||||
|
||||
&floatv[1], <br>
|
||||
|
||||
&floatv[2]);</tt></p>
|
||||
<p>becomes</p>
|
||||
<p
|
||||
style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"><tt>
|
||||
al.getListener3f(AL.POSITION, Sys.getDirectBufferAddress(floatv), <br>
|
||||
|
||||
Sys.getDirectBufferAddress(floatv) + 4, <br>
|
||||
|
||||
Sys.getDirectBufferAddress(floatv) + 8);</tt></p>
|
||||
<p>the last case is a bit special, since we start of by getting the base
|
||||
address of the buffer, and then add the datatype size to the base address<br>
|
||||
to get the address of that specific index. This is just how it has to
|
||||
be in Java.</p>
|
||||
</body>
|
||||
</html>
|
|
@ -1,157 +0,0 @@
|
|||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Language" content="en-gb">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
||||
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
|
||||
<meta name="ProgId" content="FrontPage.Editor.Document">
|
||||
<title>Lightweight Java Game Library Tutorial Index</title>
|
||||
<style>
|
||||
<!--
|
||||
.document_title { text-align: Center; font-size: 24pt; letter-spacing: 4 }
|
||||
.code_snippet { font-family: Courier New }
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<p class="document_title">Lightweight Java Game Library</p>
|
||||
<p class="document_title">Tutorial</p>
|
||||
<p align="center">Written by Caspian Rychlik-Prince</p>
|
||||
<p align="center">Please direct comments, errata, and flames to the author at <a href="mailto:cix_foo@users.sourceforge.net">cix_foo@users.sourceforge.net</a></p>
|
||||
<p align="center">Last modified <!--webbot bot="Timestamp" S-Type="EDITED"
|
||||
S-Format="%d %B %Y" startspan -->23 August 2002<!--webbot bot="Timestamp" endspan i-checksum="31308" -->
|
||||
</p>
|
||||
<p> </p>
|
||||
<p><a name="Introduction">1.0 Introduction</a></p>
|
||||
<p>The Lightweight Java Game Library (LWJGL) is a solution aimed directly at
|
||||
professional and amateur Java programmers alike to enable commercial quality
|
||||
games to be written in Java. This tutorial is nonetheless aimed at <i>experienced
|
||||
</i>programmers and won't be explaining some obvious techniques. Currently the
|
||||
LWJGL supports only the Win32 platform, and JDK1.4. </p>
|
||||
<p>LWJGL is not meant to make writing games particularly <i>easy;</i> it is
|
||||
primarily an <i>enabling technology </i>which allows developers to get at
|
||||
resources that are simply otherwise unavailable or poorly implemented on the
|
||||
existing Java platform. We anticipate that the LWJGL will, through evolution and
|
||||
extension, become the foundation for more complete game libraries and "game
|
||||
engines" as they have popularly become known, and hide some of the new
|
||||
evils we have had to expose in the APIs.</p>
|
||||
<p>2.0 Contents</p>
|
||||
<p> </p>
|
||||
<p>3.0 Aims & Design</p>
|
||||
<p>Because the LWJGL API is not meant to be a fully featured game engine it has
|
||||
been ruthlessly pruned of all non-essential code. Its ultimate philosophy is
|
||||
that it provides the <i>bare minimum</i> of API functionality which will let a
|
||||
game programmer produce games in Java without having to write native code in
|
||||
order to get <i>performance </i>or <i>access some hardware feature not exposed
|
||||
by Java 2</i>. We settled on using two other open technologies as our major
|
||||
foundations, namely OpenGL and OpenAL for graphics and sound respectively.</p>
|
||||
<p>A sub-requirement of the LWJGL is that it be freed Java programmers from the
|
||||
requirement to ship a whole JRE with their games. Currently the Sun licensing
|
||||
terms dictate that J2SE be shipped in its entirety, even for the tiniest of
|
||||
demos. As this could easily triple the size of a demo and discourage end users
|
||||
with configuration issues we have made it a primary concern that games written
|
||||
using LWJGL can be compiled into completely standalone native binary executables
|
||||
by compilers such as GNU's GCJ and Excelsior's JET. We have done this by
|
||||
implementing the library in such a way that <i>no dependencies </i>on Sun's
|
||||
proprietry JRE binaries are present in the library.</p>
|
||||
<p>The final aim of LWJGL is to make the library available for Win32 systems
|
||||
above all others, for that is what most commercial programmers need.</p>
|
||||
<p>Linuxians and Macophiles do not despair! There's nothing inherently
|
||||
non-portable about the LWJGL - we just don't have the time and expertise to do
|
||||
it yet. But it will happen.</p>
|
||||
<p>3.1 General API</p>
|
||||
<p>The general API gives us the foundations of game programming: we have a
|
||||
Display class, for initialising the display and querying its available modes; we
|
||||
have a Math class to provide us with some floating point maths functions (rather
|
||||
than the double-precision ones provided by Java), and matrix batch operations;
|
||||
and a Sys class, which gives us our <i>most useful gaming functions:</i> the
|
||||
ability to get the address of a direct byte buffer so we can cache it on the
|
||||
Java side of the JNI barrier, and hence access all those lovely hardware calls
|
||||
we need for performance; and the ability to use the system's <i>hires timer</i>,
|
||||
which is so critical for animation timing. In addition we can also create a
|
||||
direct byte buffer at <i>any address in memory.</i></p>
|
||||
<p>The Evil Of Pointers And What It Means For Security</p>
|
||||
<p>Yes, we have exposed <i>pointers</i> to Java programmers. Yes, you can write
|
||||
to just about any bit of memory you so please, and cause untold havoc. You can
|
||||
break things. You can bypass security constraints and exploit the dreaded <i>buffer
|
||||
vuln.</i></p>
|
||||
<p>But <i>why?</i> Because without pointers, all those nice easy native API
|
||||
calls would suddenly become complex and behave slightly differently to their C
|
||||
counterparts, and require us to pass direct ByteBuffers to JNI for every call.
|
||||
This requires that every single call which takes a pointer calls the JNI method
|
||||
GetDirectBufferAddress every time, which is an unnecessary overhead.</p>
|
||||
<p>The implications for security are simple and final: your game can <b>no
|
||||
longer be considered secure</b> and part of the Java security model. This puts
|
||||
it in exactly the same boat as any other application on the user's system. This
|
||||
also means you will not be able to use it in applets or with Webstart without
|
||||
getting your code signed and trusted. LWJGL itself will not be signed nor
|
||||
trusted; you are expected to deliver it bundled in with every application you
|
||||
ship and verify that your entire distribution is safe.</p>
|
||||
<p>We feel that our target developer, the commercial game developer, should not
|
||||
be concerned with this issue as the status quo is merely maintained from the old
|
||||
ways of programming with any other language; and used wisely, your exposure to
|
||||
pointers is unlikely to cause you any problems.</p>
|
||||
<p>If you are concerned about security, or wish to write games which will run as
|
||||
applets or from Webstart, or would rather have a full game library which takes
|
||||
care of things for you, you don't want to use LWJGL at all - it's that simple!
|
||||
What you need is Sun's Java Gaming Profile, or Java3D. If you feel a need to
|
||||
argue, you're using LWJGL for the wrong reasons.</p>
|
||||
<p>3.2 Graphics</p>
|
||||
<p>Graphics is based on the latest OpenGL1.4, and all the extensions we could
|
||||
implement that might be vaguely useful for games programmers. These include <i>all</i>
|
||||
of Nvidia's and ATI's proprietry extensions, and <i>all</i> the ARB extensions,
|
||||
and most of the EXT extensions, as well as numerous other miscellaneous ones.</p>
|
||||
<p>For Windows programmers, our primary target, the WGL extensions are present.</p>
|
||||
<p>All OpenGL functions that take pointers are passed ints. These pointers can
|
||||
be obtained from direct ByteBuffers using the Sys.getDirectBufferAddress()
|
||||
method. There are a very few native methods that return pointers as ints as
|
||||
well. Be sure to read the caveat about using pointers in Java!</p>
|
||||
<p>3.3 Sounds</p>
|
||||
<p>Sound is based on the latest OpenAL1.0 specification, which comes with but
|
||||
one extension, EAX, for interesting environmental effects. The LWJGL binary
|
||||
distribution includes the OpenAL .dlls for Win32.</p>
|
||||
<p>3.4 Input</p>
|
||||
<p>Input can be a complicated topic. A user can have all sorts of strange fancy
|
||||
force-feedback hardware installed on their systems, with scrolly knobs and
|
||||
twistgrips and bristling with many buttons. However, the vast majority of gamers
|
||||
have just a keyboard and a mouse; some of them have analogue joysticks too, and
|
||||
some of them have a gamepad attached from some console or other. For our first
|
||||
cut of the input library we've just kept it all rather simple, and decided that
|
||||
there is but one of each of these devices, and that force feedback and multiple
|
||||
potentiometers is a feature we may add another time.</p>
|
||||
<p>So in the interests of keeping things simple, the four input classes -
|
||||
Keyboard, Mouse, Gamepad and Joystick - are all static, and can all be polled
|
||||
once per game loop iteration to determine where they've moved since you last
|
||||
looked and what buttons are down at the time. The Gamepad and Keyboard may
|
||||
additionally support <i>buffering</i> which is a more reliable way of detecting
|
||||
rapid changes of state which may occur rather more quickly than your framerate.</p>
|
||||
<p>3.5 Maths</p>
|
||||
<p>Java's maths performance leaves much to be desired, particularly with respect
|
||||
to bulk operations for 3D rendering engines. The main problem is that the
|
||||
existing maths libraries use double precision when single precision is entirely
|
||||
adequate for most realtime games programming; and that no clever
|
||||
processor-specific optimisations can be done because the Hotspot compiler is
|
||||
simply not supplied enough semantic context to understand that it could use some
|
||||
special SIMD instruction to achieve the effect you desire in a fraction of the
|
||||
cycles. Furthermore, all maths in Java is done in Java - and once you've
|
||||
computed the results you usually have to subsequently copy them into a buffer to
|
||||
pass to a native rendering method in OpenGL anyway.</p>
|
||||
<p>The Math class provides two <i>totally generic</i> vector operators for unary
|
||||
and binary vector operations performed on direct ByteBuffers containing packed
|
||||
floating point vectors. The idea is to set up the source(s) of the operations
|
||||
and then perform a single call to JNI to perform a <i>highly optimised operation</i>
|
||||
on the whole lot in one go. The JNI code is specially optimised for the common
|
||||
cases in 3d games programming to use processor-specific instructions and take
|
||||
advantage, where feasible, of memory caching architecture. And the end result is
|
||||
placed directly back in memory, ready to simply send as a pointer direct to
|
||||
OpenGL or some other API.</p>
|
||||
<p>In addition we provide implementations of common Vector and Matrix sizes
|
||||
similar to those provided by the javax.vecmath package, but ours are <i>open
|
||||
source</i> and available without downloading the whole of Java3D.</p>
|
||||
<p> </p>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -1,203 +0,0 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>OpenAL Tutoral</title>
|
||||
|
||||
<meta http-equiv="content-type"
|
||||
content="text/html; charset=windows-1252">
|
||||
<meta name="author" content="Brian Matzon">
|
||||
<meta name="description" content="Basic sound using OpenAL">
|
||||
</head>
|
||||
<body>
|
||||
<h1 align="center">OpenAL Tutorial<br>
|
||||
<font size="-1">(by Brian Matzon <<a href="mailto:brian@matzon.dk">brian@matzon.dk</a>>)</font><br>
|
||||
</h1>
|
||||
<b>1.0 OpenAL Basics</b><br>
|
||||
Before embarking on our little OpenAL adventure, some tools are needed.<br>
|
||||
<br>
|
||||
<b>1.0.1 Ingredients</b><br>
|
||||
Head on over to Creatives <a
|
||||
href="http://developer.creative.com/scripts/DC_D&H_Games-Downloads.asp?opt=2">site</a>
|
||||
and snag a copy of the OpenAL specification along with a copy of the Programmers
|
||||
reference.<br>
|
||||
If you haven't already done so, get a copy of the OpenAL runtime environment
|
||||
too (and install it).<br>
|
||||
<br>
|
||||
<b>1.1 OpenAL theory</b><br>
|
||||
Uhm... I'm not going to write this... In all honesty reading the specification
|
||||
would be a good thing before continuing - but it isn't required...<br>
|
||||
<br>
|
||||
<b>1.2 Basic setup</b><br>
|
||||
Lets start out by creating a skeleton class for some very basic sound. We'll
|
||||
start of by creating the required OpenAL objects<br>
|
||||
<p
|
||||
style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"><tt>import
|
||||
org.lwjgl.openal.AL;<br>
|
||||
import org.lwjgl.openal.ALC;<br>
|
||||
import org.lwjgl.openal.ALCcontext;<br>
|
||||
import org.lwjgl.openal.ALCdevice;<br>
|
||||
<br>
|
||||
<br>
|
||||
public class PlayTest {<br>
|
||||
<br>
|
||||
/** OpenAL instance */<br>
|
||||
protected AL al;<br>
|
||||
<br>
|
||||
/** OpenAL Context instance */<br>
|
||||
protected ALC alc;<br>
|
||||
<br>
|
||||
/** OpenAL context */<br>
|
||||
protected ALCcontext context;<br>
|
||||
<br>
|
||||
/** OpenAL device */<br>
|
||||
protected ALCdevice device; <br>
|
||||
<br>
|
||||
/**<br>
|
||||
* Creates an instance of PlayTest<br>
|
||||
*/<br>
|
||||
public PlayTest() {<br>
|
||||
try {<br>
|
||||
</tt>
|
||||
<tt> al = new AL();<br>
|
||||
alc = new ALC();<br>
|
||||
<br>
|
||||
al.create();<br>
|
||||
alc.create();<br>
|
||||
} catch (Exception e) {<br>
|
||||
e.printStackTrace();<br>
|
||||
}</tt><tt><br>
|
||||
}<br>
|
||||
}</tt><code></code></p>
|
||||
We need instances of the following classes:<br>
|
||||
<ul>
|
||||
<li><tt>AL </tt>- basic source, buffer and listener interaction</li>
|
||||
<li><tt>ALC </tt>- context and device creatiuon</li>
|
||||
</ul>
|
||||
<b>1.3 OpenAL initialization</b><br>
|
||||
Now that we have created a basic class containing instances of the relevant
|
||||
OpenAL classes, lets start of by initializing OpenAL - that is create a device
|
||||
and a context:<br>
|
||||
<p
|
||||
style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"> <tt>
|
||||
/**<br>
|
||||
* Initializes OpenAL<br>
|
||||
*/<br>
|
||||
protected void alInitialize() { <br>
|
||||
//get default device<br>
|
||||
device = alc.openDevice(null);<br>
|
||||
<br>
|
||||
//create context (no attributes specified)<br>
|
||||
context = alc.createContext(device, 0);<br>
|
||||
<br>
|
||||
//make context current<br>
|
||||
alc.makeContextCurrent(context);<br>
|
||||
}</tt><code><br>
|
||||
</code></p>
|
||||
Start of by opening a device using the <tt>openDevice </tt>method. <tt>openDevice
|
||||
</tt>takes a <tt>String </tt>as argument, containing the name of the device
|
||||
to open. If no name is supplied, the default device will be used (OpenAL
|
||||
currently doesn't support enumeration of devices available).<br>
|
||||
<br>
|
||||
Having opened a device, create a context to that device using <tt>createContext</tt>.
|
||||
<tt>createContext</tt> takes two arguments: device to use and a list of attributes
|
||||
(see specification for list of attributes). Since we're going by default context,
|
||||
we just specify <tt>0</tt> for attributes.<br>
|
||||
<br>
|
||||
Finish of by making the created context current. Do this by calling <tt>makeContextCurrent</tt>,
|
||||
supplying just created context as argument.<br>
|
||||
<p><b>1.4 Buffer and Source creation</b><br>
|
||||
Now that we have opened a device and gotten a context, we need to create
|
||||
two things to actually get some sound. We need to create a buffer to hold
|
||||
sounddata, and a source that is to play the sounddata.<br>
|
||||
Lets start of by creating one source, and one buffer:</p>
|
||||
<p
|
||||
style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"><tt>
|
||||
//create one IntBuffer as buffer and one as source<br>
|
||||
IntBuffer buffers = createIntBuffer(1);<br>
|
||||
IntBuffer sources = createIntBuffer(1);<br>
|
||||
<br>
|
||||
//generate buffers and sources<br>
|
||||
al.genBuffers(1, Sys.getDirectBufferAddress(buffers));<br>
|
||||
al.genSources(1, Sys.getDirectBufferAddress(sources));</tt></p>
|
||||
<p>There, all set for actually loading some sounddata into the buffer.<br>
|
||||
</p>
|
||||
<b>1.5 Loading sounddata and setting up a buffer</b><br>
|
||||
Now that we have a buffer, we need to load some sound data into this buffer.
|
||||
This is done using the <tt>al.bufferData</tt> method. In our example we will
|
||||
"cheat" a bit, by using the <tt>WaveData</tt> class to load
|
||||
a wave file, and copy this into the buffer:<br>
|
||||
<p
|
||||
style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"><tt>
|
||||
//load wave data<br>
|
||||
WaveData wavefile = WaveData.create("mywavefile.wav");<br>
|
||||
<br>
|
||||
//copy to buffer<br>
|
||||
al.bufferData(buffers.get(0), wavefile.format, Sys.getDirectBufferAddress(wavefile.data), wavefile.data.capacity(), wavefile.samplerate);<br>
|
||||
<br>
|
||||
//unload file again<br>
|
||||
wavefile.dispose(); <br>
|
||||
</tt></p>
|
||||
Having loaded the data, we pass it to <tt>bufferData</tt>. Once the buffer
|
||||
has been filled with sounddata, we unload it from the system using <tt>wavefile.dispose()</tt>.
|
||||
Don't worry about deleting it this soon - the sounddata has been <b>copied</b>
|
||||
to the buffer.<br>
|
||||
<br>
|
||||
<b>1.6 Associating sources and buffers</b><br>
|
||||
To associate a source to a buffer we set the integer BUFFER attribute on
|
||||
the source, and assign it a value of the buffer to play:<br>
|
||||
<p
|
||||
style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"><tt>
|
||||
//set up source input<br>
|
||||
al.sourcei(sources.get(0), AL.BUFFER, buffers.get(0));</tt><tt><br>
|
||||
</tt></p>
|
||||
<b>1.7 Setting source properties</b><br>
|
||||
Having set up the source, it is time to set some attributes on the source
|
||||
- there are many that can be set, but in this example we only set the looping
|
||||
attribute to true by doing the following:<br>
|
||||
<p
|
||||
style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"><tt>
|
||||
//loop source<br>
|
||||
al.sourcei(sources.get(0), AL.LOOPING, AL.TRUE);</tt><tt><br>
|
||||
</tt></p>
|
||||
<b>1.8 Sound...<br>
|
||||
</b>There, ready to play the sound, do this using the <tt>sourcePlay </tt>method
|
||||
of the <tt>AL </tt>class. to stop and pause use <tt>sourcePause </tt>and
|
||||
<tt>sourceStop </tt>respectively, and supply the source to affect:<br>
|
||||
<p
|
||||
style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"><tt>
|
||||
//play source 0<br>
|
||||
al.sourcePlay(sources.get(0));<br>
|
||||
<br>
|
||||
//wait 5 secs<br>
|
||||
try {<br>
|
||||
System.out.println("Waiting 5 seconds for sound to complete");<br>
|
||||
Thread.sleep(5000);<br>
|
||||
} catch (InterruptedException inte) {<br>
|
||||
}<br>
|
||||
<br>
|
||||
//stop source 0<br>
|
||||
al.sourceStop(sources.get(0));</tt></p>
|
||||
<b>1.9 Cleaning up<br>
|
||||
</b>Having had loads of fun playing a sound (!), it is now time to do some
|
||||
house chores. We need to clean up what we have created, this amounts to:<br>
|
||||
- deleting source and buffer<br>
|
||||
- deleting context<br>
|
||||
- closing devce<br>
|
||||
as is shown here:<b><br>
|
||||
</b>
|
||||
<p
|
||||
style="border-style: solid; border-width: 1px; padding: 3px; background-color: rgb(255,255,204);"><tt>
|
||||
//delete buffers and sources<br>
|
||||
al.deleteSources(1, Sys.getDirectBufferAddress(sources));<br>
|
||||
al.deleteBuffers(1, Sys.getDirectBufferAddress(buffers));<br>
|
||||
<br>
|
||||
//shutdown<br>
|
||||
alc.makeContextCurrent(null);<br>
|
||||
alc.destroyContext(context);<br>
|
||||
alc.closeDevice(device);</tt></p>
|
||||
There, all set. Now you should be able to play some basic sound!<br>
|
||||
This tutorial is rather short, and the above examples feature no error checking.
|
||||
For the complete source code, look at the classes in the <br>
|
||||
<a href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/src/java/org/lwjgl/test/openal/" target="_blank"><tt>org.lwjgl.test.openal</tt></a> package.<br>
|
||||
</body>
|
||||
</html>
|
|
@ -1,275 +0,0 @@
|
|||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Language" content="en-gb">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
||||
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
|
||||
<meta name="ProgId" content="FrontPage.Editor.Document">
|
||||
<title>4</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<p>4.0 Skeleton Game Code</p>
|
||||
<p>So now you want to know how to just get stuck in and start writing games.
|
||||
First you need to understand a couple of game programming design patterns and
|
||||
why they'll make your life easier; and then you'll want to fill in the gaps in a
|
||||
bit of skeleton code that we're going to discuss below.</p>
|
||||
<p>4.1 Design Decisions</p>
|
||||
<p>4.1.1 Static Game Class</p>
|
||||
<p>How many instances of your game do you expect to be running in a JVM? One,
|
||||
and only one. Given this, you may feel the urge to implement the singleton
|
||||
pattern on your game, where your game class holds a single instance of itself
|
||||
and a method to retrieve that instance, something like:</p>
|
||||
<p style="background-color: #FFFFCC; border-style: solid; border-width: 1; padding: 3"><code>public
|
||||
class Game {</code><code><br>
|
||||
<br>
|
||||
/** The single instance of the Game */<br>
|
||||
private final Game game = new Game();<br>
|
||||
<br>
|
||||
/** Don't allow construction from anywhere else */<br>
|
||||
private Game() {</code><code><br>
|
||||
}<br>
|
||||
</code><code><br>
|
||||
/** @return the game instance */<br>
|
||||
public static Game getGame() {<br>
|
||||
return game;</code><code><br>
|
||||
}<br>
|
||||
<br>
|
||||
/** Start a new game */<br>
|
||||
public void newGame() {<br>
|
||||
// etc<br>
|
||||
}<br>
|
||||
<br>
|
||||
/** The main game loop */<br>
|
||||
public void mainLoop() {<br>
|
||||
// etc<br>
|
||||
}<br>
|
||||
<br>
|
||||
// etc<br>
|
||||
}</code></p>
|
||||
<p>However this does result in code all over your application calling
|
||||
Game.getGame().someMethod() - and to what end? It might <i>look</i> like
|
||||
object-oriented code but in reality you're just making things harder for
|
||||
yourself. It's far more intuitive to write your class purely statically, like
|
||||
this:</p>
|
||||
<p style="background-color: #FFFFCC; border-style: solid; border-width: 1; padding: 3"><code>public
|
||||
class Game {</code><code><br>
|
||||
<br>
|
||||
/** Don't allow construction from anywhere else */<br>
|
||||
private Game() {</code><code><br>
|
||||
}<br>
|
||||
<br>
|
||||
/** Start a new game */<br>
|
||||
public static void newGame() {<br>
|
||||
// etc<br>
|
||||
}<br>
|
||||
<br>
|
||||
/** The main game loop */<br>
|
||||
public static void mainLoop() {<br>
|
||||
// etc<br>
|
||||
}<br>
|
||||
<br>
|
||||
// etc<br>
|
||||
}</code></p>
|
||||
<p>Now you can just call your methods directly on the Game class. We're going to
|
||||
use this pattern in the forthcoming skeleton game code.</p>
|
||||
<p>4.1.2 About Threads and Timeslicing</p>
|
||||
<p>There is a tendency for Java programs to be heavily multithreaded, simply
|
||||
because you <i>can</i> in Java, whereas it is exceedingly difficult to do
|
||||
properly in C++. However, you are likely to fall into a number of pitfalls in
|
||||
game programming above and beyond those experienced in general multithreaded
|
||||
programming:</p>
|
||||
<p>Firstly, threads were designed a long time ago for a specific purpose, and
|
||||
that purpose is keeping the processor busy whilst some slow I/O operation is
|
||||
being carried out. How many slow I/O operations are you going to do in your
|
||||
game? Apart from loading the graphics, sounds, and level data at the start -
|
||||
none (unless you're doing networking but that's a whole other issue).</p>
|
||||
<p>What does this mean for you? Well, in normal Java, programmers will tend to
|
||||
set off a number of threads and expect them to more or less behave like <i>time
|
||||
slices</i> rather than <i>threads.</i> Time slices work in a rather different
|
||||
way to threads: each is executed, in turn, for a finite amount of time. You can
|
||||
more or less guarantee that a slice will execute for its allotted time, and that
|
||||
all slices will get a look-in.</p>
|
||||
<p>Threads don't work like this. To put it bluntly, you can't <i>accurately</i>
|
||||
predict when a thread is going to execute (or if it will ever be executed), or
|
||||
even how long it will execute for. Therefore you should not be using threads to
|
||||
do stuff that you expect to occur in a timely fashion. This includes <i>collision
|
||||
detection, animation, sound playback</i> and <i>device input, </i>and the
|
||||
ultimate blow, <i>event handling.</i></p>
|
||||
<p>In the absence of threads to do this useful stuff, we have to resort to a <i>single-threaded
|
||||
model</i> where the game effectively runs in one, very busy, thread - the
|
||||
"main loop". This is quite convenient, however, because it highlights
|
||||
another problem with multithreaded game code that is not immediately obvious.</p>
|
||||
<p>4.1.3 About Threads and Hardware</p>
|
||||
<p>Your machine's <i>hardware</i> is only ever in <i>one state at a time, </i>unless
|
||||
it is some kind of quantum computer. The device drivers for the hardware -
|
||||
namely OpenGL and the like - keep track of this state in order to send the
|
||||
correct hardware setup commands to the device. Can you imagine what might happen
|
||||
if one thread is trying to do some drawing at the same time that another thread
|
||||
is trying to do some drawing? Yes, you get a mess. You will discover that in
|
||||
order to draw in a thread in OpenGL that you need to associate the current
|
||||
rendering thread with the current state of the hardware (the
|
||||
"context"). Suddenly you need to synchronize every method which can
|
||||
alter the hardware state. Suddenly your application looks <i>incredibly
|
||||
complicated</i> and <i>runs like a dog!</i> So much for threads.</p>
|
||||
<p>So be aware of this next time you think it's a good idea to load your
|
||||
textures in a background thread, and remember that only one thread - the main
|
||||
thread - is allowed to execute any commands on your hardware devices.</p>
|
||||
<p>It is for this reason that we use <i>polling </i>to read input devices as
|
||||
well. Not to mention the fact that we can't guarantee that an event loop will be
|
||||
executed every game frame, and so our input will be erratic.</p>
|
||||
<p>4.1.4 Object-orientation</p>
|
||||
<p>Object-orientation is <i>good</i> when it's done right. It makes your code
|
||||
much, much, easier to understand and work on. However you may be led astray by <i>parrots
|
||||
who repeat mantras.</i> There are some programmers that say <i>everything should
|
||||
be private</i> and you should expose your instance variables with getters and
|
||||
setters. The Hotspot virtual machine is even cleverly optimised to make this
|
||||
operation almost entirely free. <i>But wait! </i>Ask yourself why you're filling
|
||||
your classes up with getters and setters <i>when a dot would do the same job
|
||||
without any need to maintain it.</i></p>
|
||||
<p>You're writing a game: the source code is probably only going to be used
|
||||
once, or by a very few people. Most of your game code is so unique to your
|
||||
actual game that it is <i>disposable code.</i> So save yourself some effort and
|
||||
use a dot if you can. A critical mistake I have observed time and time again in
|
||||
object-oriented projects is to get so bogged down trying to design a perfect
|
||||
object-oriented model that the project takes absolutely ages to design. Before
|
||||
you know it there are hundreds of getters and setters to maintain, and
|
||||
interfaces all over the place to keep the reuse of your classes to a maximum -
|
||||
when <i>all along the project design goal was not reuse but to get the bloody
|
||||
thing finished on time and under budget!</i></p>
|
||||
<p>Your mileage may vary...</p>
|
||||
<p>4.2 Show Me The Money</p>
|
||||
<p>Ok, ok, without further ado, here is a skeleton listing which you can use to
|
||||
write a fullscreen Java game using LWJGL. Because we're games programmers, we
|
||||
don't want to do a Hello World as we'd probably rather shoot it. But before we
|
||||
can make bullets we must pay homage to the <i>rotating square!</i></p>
|
||||
<p style="background-color: #FFFFCC; border-style: solid; border-width: 1; padding: 3"><code>import
|
||||
org.lwjgl.*;<br>
|
||||
import org.lwjgl.opengl.*;<br>
|
||||
import org.lwjgl.input.*;<br>
|
||||
<br>
|
||||
<br>
|
||||
public
|
||||
final class Game {<br>
|
||||
static {<br>
|
||||
try {<br>
|
||||
DisplayMode[] modes = Display.getAvailableDisplayModes();<br>
|
||||
System.out.println("Available display modes:");<br>
|
||||
for (int i = 0; i < modes.length; i ++)<br>
|
||||
|
||||
System.out.println(modes[i]);<br>
|
||||
// For now let's just pick a mode we're certain to have<br>
|
||||
Display.create(new DisplayMode(640, 480, 16, 60), true);<br>
|
||||
System.out.println("Created display.");<br>
|
||||
} catch (Exception e) {<br>
|
||||
System.err.println("Failed to create display due to "+e);<br>
|
||||
System.exit(1);<br>
|
||||
}<br>
|
||||
}<br>
|
||||
<br>
|
||||
public static final GL gl = new GL(16, 0, 16, 8);<br>
|
||||
static {<br>
|
||||
try {<br>
|
||||
gl.create();<br>
|
||||
System.out.println("Created OpenGL.");<br>
|
||||
} catch (Exception e) {<br>
|
||||
System.err.println("Failed to create OpenGL due to "+e);<br>
|
||||
System.exit(1);<br>
|
||||
}<br>
|
||||
}<br>
|
||||
public static final GLU glu = new GLU(gl);<br>
|
||||
<br>
|
||||
/** Is the game finished? */<br>
|
||||
private static boolean finished;<br>
|
||||
<br>
|
||||
/** A rotating square! */<br>
|
||||
private static float angle;<br>
|
||||
<br>
|
||||
/**<br>
|
||||
* No construction allowed<br>
|
||||
*/<br>
|
||||
private Game() {<br>
|
||||
}<br>
|
||||
<br>
|
||||
public static void main(String[] arguments) {<br>
|
||||
try {<br>
|
||||
init();<br>
|
||||
while (!finished) {<br>
|
||||
|
||||
Keyboard.poll();<br>
|
||||
|
||||
mainLoop();<br>
|
||||
|
||||
render();<br>
|
||||
|
||||
gl.swapBuffers();<br>
|
||||
}</code> <code><br>
|
||||
} catch (Throwable t) {<br>
|
||||
|
||||
t.printStackTrace();<br>
|
||||
} finally {<br>
|
||||
cleanup();<br>
|
||||
}<br>
|
||||
}<br>
|
||||
<br>
|
||||
/**<br>
|
||||
* All calculations are done in here<br>
|
||||
*/<br>
|
||||
private static void mainLoop() {<br>
|
||||
angle += 1f;<br>
|
||||
if (angle > 360.0f)<br>
|
||||
angle = 0.0f;<br>
|
||||
<br>
|
||||
Keyboard.poll();
|
||||
<br>
|
||||
if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))<br>
|
||||
finished = true;<br>
|
||||
}<br>
|
||||
<br>
|
||||
/**<br>
|
||||
* All rendering is done in here<br>
|
||||
*/<br>
|
||||
private static void render() {<br>
|
||||
gl.clear(GL.COLOR_BUFFER_BIT);<br>
|
||||
gl.pushMatrix();<br>
|
||||
gl.translatef(Display.getWidth() / 2, Display.getHeight() / 2, 0.0f);<br>
|
||||
gl.rotatef(angle, 0, 0, 1.0f);<br>
|
||||
gl.begin(GL.QUADS);<br>
|
||||
gl.vertex2i(-50, -50);<br>
|
||||
gl.vertex2i(50, -50);<br>
|
||||
gl.vertex2i(50, 50);<br>
|
||||
gl.vertex2i(-50, 50);<br>
|
||||
gl.end();<br>
|
||||
gl.popMatrix();<br>
|
||||
}<br>
|
||||
<br>
|
||||
/**<br>
|
||||
* Initialize<br>
|
||||
*/<br>
|
||||
private static void init() throws Exception {<br>
|
||||
Keyboard.create();<br>
|
||||
// Go into orthographic projection mode.<br>
|
||||
gl.matrixMode(GL.PROJECTION);<br>
|
||||
gl.loadIdentity();<br>
|
||||
glu.ortho2D(0, Display.getWidth(), 0, Display.getHeight());<br>
|
||||
gl.matrixMode(GL.MODELVIEW);<br>
|
||||
gl.loadIdentity();<br>
|
||||
gl.viewport(0, 0, Display.getWidth(), Display.getHeight());<br>
|
||||
// Fix the refresh rate to the display frequency.<br>
|
||||
gl.wglSwapIntervalEXT(1);<br>
|
||||
}<br>
|
||||
<br>
|
||||
/**<br>
|
||||
* Cleanup<br>
|
||||
*/<br>
|
||||
private static void cleanup() {<br>
|
||||
Keyboard.destroy();<br>
|
||||
</code> <code>gl.destroy();<br>
|
||||
Display.destroy();<br>
|
||||
}<br>
|
||||
}</code></p>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
BIN
res/Wave1.WAV
BIN
res/Wave2.WAV
BIN
res/Wave3.WAV
BIN
res/Wave4.WAV
Before Width: | Height: | Size: 40 KiB |
Before Width: | Height: | Size: 125 KiB |
Before Width: | Height: | Size: 42 KiB |
Before Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 41 KiB |
BIN
res/data/mud.png
Before Width: | Height: | Size: 126 KiB |
Before Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 8.4 KiB |
BIN
res/data/tim.png
Before Width: | Height: | Size: 102 KiB |
Before Width: | Height: | Size: 7.6 KiB |
|
@ -1,160 +0,0 @@
|
|||
|
||||
NUMPOLLIES 36
|
||||
|
||||
// Floor 1
|
||||
-3.0 0.0 -3.0 0.0 6.0
|
||||
-3.0 0.0 3.0 0.0 0.0
|
||||
3.0 0.0 3.0 6.0 0.0
|
||||
|
||||
-3.0 0.0 -3.0 0.0 6.0
|
||||
3.0 0.0 -3.0 6.0 6.0
|
||||
3.0 0.0 3.0 6.0 0.0
|
||||
|
||||
// Ceiling 1
|
||||
-3.0 1.0 -3.0 0.0 6.0
|
||||
-3.0 1.0 3.0 0.0 0.0
|
||||
3.0 1.0 3.0 6.0 0.0
|
||||
-3.0 1.0 -3.0 0.0 6.0
|
||||
3.0 1.0 -3.0 6.0 6.0
|
||||
3.0 1.0 3.0 6.0 0.0
|
||||
|
||||
// A1
|
||||
|
||||
-2.0 1.0 -2.0 0.0 1.0
|
||||
-2.0 0.0 -2.0 0.0 0.0
|
||||
-0.5 0.0 -2.0 1.5 0.0
|
||||
-2.0 1.0 -2.0 0.0 1.0
|
||||
-0.5 1.0 -2.0 1.5 1.0
|
||||
-0.5 0.0 -2.0 1.5 0.0
|
||||
|
||||
// A2
|
||||
|
||||
2.0 1.0 -2.0 2.0 1.0
|
||||
2.0 0.0 -2.0 2.0 0.0
|
||||
0.5 0.0 -2.0 0.5 0.0
|
||||
2.0 1.0 -2.0 2.0 1.0
|
||||
0.5 1.0 -2.0 0.5 1.0
|
||||
0.5 0.0 -2.0 0.5 0.0
|
||||
|
||||
// B1
|
||||
|
||||
-2.0 1.0 2.0 2.0 1.0
|
||||
-2.0 0.0 2.0 2.0 0.0
|
||||
-0.5 0.0 2.0 0.5 0.0
|
||||
-2.0 1.0 2.0 2.0 1.0
|
||||
-0.5 1.0 2.0 0.5 1.0
|
||||
-0.5 0.0 2.0 0.5 0.0
|
||||
|
||||
// B2
|
||||
|
||||
2.0 1.0 2.0 2.0 1.0
|
||||
2.0 0.0 2.0 2.0 0.0
|
||||
0.5 0.0 2.0 0.5 0.0
|
||||
2.0 1.0 2.0 2.0 1.0
|
||||
0.5 1.0 2.0 0.5 1.0
|
||||
0.5 0.0 2.0 0.5 0.0
|
||||
|
||||
// C1
|
||||
|
||||
-2.0 1.0 -2.0 0.0 1.0
|
||||
-2.0 0.0 -2.0 0.0 0.0
|
||||
-2.0 0.0 -0.5 1.5 0.0
|
||||
-2.0 1.0 -2.0 0.0 1.0
|
||||
-2.0 1.0 -0.5 1.5 1.0
|
||||
-2.0 0.0 -0.5 1.5 0.0
|
||||
|
||||
// C2
|
||||
|
||||
-2.0 1.0 2.0 2.0 1.0
|
||||
-2.0 0.0 2.0 2.0 0.0
|
||||
-2.0 0.0 0.5 0.5 0.0
|
||||
-2.0 1.0 2.0 2.0 1.0
|
||||
-2.0 1.0 0.5 0.5 1.0
|
||||
-2.0 0.0 0.5 0.5 0.0
|
||||
|
||||
// D1
|
||||
|
||||
2.0 1.0 -2.0 0.0 1.0
|
||||
2.0 0.0 -2.0 0.0 0.0
|
||||
2.0 0.0 -0.5 1.5 0.0
|
||||
2.0 1.0 -2.0 0.0 1.0
|
||||
2.0 1.0 -0.5 1.5 1.0
|
||||
2.0 0.0 -0.5 1.5 0.0
|
||||
|
||||
// D2
|
||||
|
||||
2.0 1.0 2.0 2.0 1.0
|
||||
2.0 0.0 2.0 2.0 0.0
|
||||
2.0 0.0 0.5 0.5 0.0
|
||||
2.0 1.0 2.0 2.0 1.0
|
||||
2.0 1.0 0.5 0.5 1.0
|
||||
2.0 0.0 0.5 0.5 0.0
|
||||
|
||||
// Upper hallway - L
|
||||
-0.5 1.0 -3.0 0.0 1.0
|
||||
-0.5 0.0 -3.0 0.0 0.0
|
||||
-0.5 0.0 -2.0 1.0 0.0
|
||||
-0.5 1.0 -3.0 0.0 1.0
|
||||
-0.5 1.0 -2.0 1.0 1.0
|
||||
-0.5 0.0 -2.0 1.0 0.0
|
||||
|
||||
// Upper hallway - R
|
||||
0.5 1.0 -3.0 0.0 1.0
|
||||
0.5 0.0 -3.0 0.0 0.0
|
||||
0.5 0.0 -2.0 1.0 0.0
|
||||
0.5 1.0 -3.0 0.0 1.0
|
||||
0.5 1.0 -2.0 1.0 1.0
|
||||
0.5 0.0 -2.0 1.0 0.0
|
||||
|
||||
// Lower hallway - L
|
||||
-0.5 1.0 3.0 0.0 1.0
|
||||
-0.5 0.0 3.0 0.0 0.0
|
||||
-0.5 0.0 2.0 1.0 0.0
|
||||
-0.5 1.0 3.0 0.0 1.0
|
||||
-0.5 1.0 2.0 1.0 1.0
|
||||
-0.5 0.0 2.0 1.0 0.0
|
||||
|
||||
// Lower hallway - R
|
||||
0.5 1.0 3.0 0.0 1.0
|
||||
0.5 0.0 3.0 0.0 0.0
|
||||
0.5 0.0 2.0 1.0 0.0
|
||||
0.5 1.0 3.0 0.0 1.0
|
||||
0.5 1.0 2.0 1.0 1.0
|
||||
0.5 0.0 2.0 1.0 0.0
|
||||
|
||||
|
||||
// Left hallway - Lw
|
||||
|
||||
-3.0 1.0 0.5 1.0 1.0
|
||||
-3.0 0.0 0.5 1.0 0.0
|
||||
-2.0 0.0 0.5 0.0 0.0
|
||||
-3.0 1.0 0.5 1.0 1.0
|
||||
-2.0 1.0 0.5 0.0 1.0
|
||||
-2.0 0.0 0.5 0.0 0.0
|
||||
|
||||
// Left hallway - Hi
|
||||
|
||||
-3.0 1.0 -0.5 1.0 1.0
|
||||
-3.0 0.0 -0.5 1.0 0.0
|
||||
-2.0 0.0 -0.5 0.0 0.0
|
||||
-3.0 1.0 -0.5 1.0 1.0
|
||||
-2.0 1.0 -0.5 0.0 1.0
|
||||
-2.0 0.0 -0.5 0.0 0.0
|
||||
|
||||
// Right hallway - Lw
|
||||
|
||||
3.0 1.0 0.5 1.0 1.0
|
||||
3.0 0.0 0.5 1.0 0.0
|
||||
2.0 0.0 0.5 0.0 0.0
|
||||
3.0 1.0 0.5 1.0 1.0
|
||||
2.0 1.0 0.5 0.0 1.0
|
||||
2.0 0.0 0.5 0.0 0.0
|
||||
|
||||
// Right hallway - Hi
|
||||
|
||||
3.0 1.0 -0.5 1.0 1.0
|
||||
3.0 0.0 -0.5 1.0 0.0
|
||||
2.0 0.0 -0.5 0.0 0.0
|
||||
3.0 1.0 -0.5 1.0 1.0
|
||||
2.0 1.0 -0.5 0.0 1.0
|
||||
2.0 0.0 -0.5 0.0 0.0
|
BIN
res/ding.wav
BIN
res/mono.wav
BIN
res/stereo.wav
|
@ -4660,17 +4660,17 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL_writeMaskEXT(JNIEnv * env, jobje
|
|||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL_checkWGLExtensionsString(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
|
||||
#ifdef _WIN32
|
||||
jfieldID fid_WGL_ARB_extensions_string = env->GetStaticFieldID(clazz, "WGL_ARB_extensions_string", "Z");
|
||||
jfieldID fid_WGL_EXT_extensions_string = env->GetStaticFieldID(clazz, "WGL_EXT_extensions_string", "Z");
|
||||
#ifdef _WIN32
|
||||
|
||||
if (wglGetExtensionsStringARB)
|
||||
env->SetStaticBooleanField(clazz, fid_WGL_ARB_extensions_string, JNI_TRUE);
|
||||
if (wglGetExtensionsStringEXT)
|
||||
env->SetStaticBooleanField(clazz, fid_WGL_EXT_extensions_string, JNI_TRUE);
|
||||
#else
|
||||
CHECK_EXISTS(NULL)
|
||||
env->SetStaticBooleanField(clazz, fid_WGL_ARB_extensions_string, JNI_FALSE);
|
||||
env->SetStaticBooleanField(clazz, fid_WGL_EXT_extensions_string, JNI_FALSE);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -1,162 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2002 Light Weight Java Game Library Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'Light Weight Java Game Library' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/* remember to turn on the -faltivec flag for gcc compilation */
|
||||
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
*
|
||||
* math library.
|
||||
*
|
||||
* @author cix_foo <cix_foo@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include "org_lwjgl_Math_MatrixOpCopy_MatrixOpSafe.h"
|
||||
#include "MatrixOpCommon.h"
|
||||
|
||||
|
||||
void altivec_CopyPackedSafe (char * src, char * dst, int length);
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_Math_MatrixOpCopy_MatrixOpSafe
|
||||
* Method: execute
|
||||
* Signature: (IIIIIZIIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_Math_00024MatrixOpCopy_00024MatrixOpSafe_execute
|
||||
(
|
||||
JNIEnv * env,
|
||||
jobject obj,
|
||||
jint sourceAddress,
|
||||
jint sourceStride,
|
||||
jint numElements,
|
||||
jint sourceWidth,
|
||||
jint sourceHeight,
|
||||
jboolean transposeSource,
|
||||
jint destAddress,
|
||||
jint destStride,
|
||||
jboolean transposeDest
|
||||
)
|
||||
{
|
||||
// remove any unnecessary copying
|
||||
if (transposeSource == transposeDest)
|
||||
{
|
||||
transposeSource = false;
|
||||
transposeDest = false;
|
||||
}
|
||||
|
||||
/* handle all cases where the data is packed and transposition is not necessary */
|
||||
if ((transposeSource == transposeDest)
|
||||
&& ((sourceWidth * sourceHeight * 4) == sourceStride))
|
||||
{
|
||||
altivec_CopyPackedSafe((char *)sourceAddress, (char *)destAddress, numElements*sourceWidth*sourceHeight*4);
|
||||
return;
|
||||
}
|
||||
|
||||
MatrixSrc source (sourceAddress, sourceStride, sourceWidth, sourceHeight, numElements, transposeSource);
|
||||
MatrixDst dest (destAddress, destStride, source.width, source.height, source.elements, transposeDest);
|
||||
|
||||
float * srcMatrix, * destMatrix;
|
||||
int matrixByteCount = source.width*source.height*sizeof(jfloat);
|
||||
|
||||
for (int i = 0; i < source.elements; i++)
|
||||
{
|
||||
srcMatrix = source.nextMatrix();
|
||||
destMatrix = dest.nextMatrix();
|
||||
|
||||
// just do a straight memory copy
|
||||
memcpy(destMatrix, srcMatrix, matrixByteCount);
|
||||
dest.writeComplete();
|
||||
}
|
||||
}
|
||||
|
||||
void altivec_CopyPackedSafe (char * src, char * dst, int length)
|
||||
{
|
||||
int src_a = (int)src;
|
||||
int dst_a = (int)dst;
|
||||
|
||||
//std::cout << "src: " << src_a << " dst: " << dst_a <<"\n";
|
||||
|
||||
if ((src_a & 0x0F) == (dst_a & 0x0F))
|
||||
{
|
||||
|
||||
//std::cout << "same alignment\n" << "\n";
|
||||
int first_bytes = 16 - ((int)(src) & 0x0000000F);
|
||||
|
||||
//std::cout << "first bytes" << first_bytes << "\n";
|
||||
int i = first_bytes;
|
||||
if (first_bytes > length)
|
||||
first_bytes = length;
|
||||
if (first_bytes == 16)
|
||||
first_bytes = 0;
|
||||
|
||||
while (i--)
|
||||
dst[i] = src[i];
|
||||
|
||||
src = &src[first_bytes];
|
||||
dst = &dst[first_bytes];
|
||||
|
||||
length -= first_bytes;
|
||||
//std::cout << "new length" << length << "\n";
|
||||
|
||||
// figure out how many 16 byte chunks there are
|
||||
int middle_cycles = (length >> 4); // ignore any other bytes
|
||||
length -= (middle_cycles << 4);
|
||||
|
||||
while (middle_cycles --)
|
||||
{
|
||||
// load a vector, set the cache line to be LRU
|
||||
vector float a = (vector float) vec_ldl(0, (float *) src);
|
||||
src += 16;
|
||||
|
||||
// write it back, set cache line LRU, gets flushed back to RAM (not L2 or L3)
|
||||
vec_stl(a, 0, (float *) dst);
|
||||
dst += 16;
|
||||
}
|
||||
|
||||
// write back any remaining bytes
|
||||
while(length--)
|
||||
dst[length] = src[length];
|
||||
|
||||
}
|
||||
else
|
||||
{ //std::cout << "different alignment\n";
|
||||
// differing offsets (byte by byte copy)
|
||||
while (length--)
|
||||
dst[length] = src[length];
|
||||
}
|
||||
}
|