diff options
Diffstat (limited to 'test/jake2')
-rw-r--r-- | test/jake2/imageio/TestImage.java | 160 | ||||
-rw-r--r-- | test/jake2/qcommon/TestCMD.java | 3 | ||||
-rw-r--r-- | test/jake2/qcommon/TestFS.java | 132 | ||||
-rw-r--r-- | test/jake2/qcommon/TestLoadMap.java | 12 | ||||
-rw-r--r-- | test/jake2/qcommon/TestMD4.java | 31 | ||||
-rw-r--r-- | test/jake2/qcommon/TestTGA.java | 327 | ||||
-rw-r--r-- | test/jake2/render/DancingQueens.java | 6 | ||||
-rw-r--r-- | test/jake2/render/TestMap.java | 58 | ||||
-rw-r--r-- | test/jake2/render/TestRenderer.java | 52 |
9 files changed, 105 insertions, 676 deletions
diff --git a/test/jake2/imageio/TestImage.java b/test/jake2/imageio/TestImage.java deleted file mode 100644 index 4290359..0000000 --- a/test/jake2/imageio/TestImage.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Created on Nov 17, 2003 - * - */ -package jake2.imageio; - -import java.awt.geom.AffineTransform; -import java.awt.image.AffineTransformOp; -import java.awt.image.BufferedImage; -import java.awt.image.BufferedImageOp; -import java.io.File; -import java.io.FileFilter; -import java.io.FilenameFilter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import javax.imageio.*; - -/** - * @author cwei - * - */ -public class TestImage { - - static final String TEST_FILE = "pics/colormap.pcx"; - static final long PAUSE = 15; // ms - static final int ENTRIES = 2501; - - File pakPath; - List imageFiles; - - TestImage(File pakPath) { - this.pakPath = pakPath; - this.imageFiles = new ArrayList(ENTRIES); - } - - public static void main(String[] args) throws Exception { - - - if (args == null || args.length == 0) { - usage(); - } - - File path = new File(args[0]); - - if (!path.isDirectory()) { - System.err.println(path.toString() + " is not a directory"); - usage(); - } - - if (!new File(path.getPath() + "/" + TEST_FILE).canRead()) { - System.err.println( - path.getPath() + " is not a unpacked quake2-pak file location"); - usage(); - } - - System.out.println("*** Start Image test ***\n"); - - ImageIO.scanForPlugins(); - - TestImage test = new TestImage(path); - test.run(); - - System.gc(); - Runtime rt = Runtime.getRuntime(); - System.out.println( - "JVM total memory: " + rt.totalMemory() / 1024 + " Kbytes\n"); - - System.out.println("*** Image test is succeeded :-) ***\n"); - } - - static void usage() { - System.out.println( - "usage: TestImage <path to unpacked quake2-pak file>"); - System.exit(0); - } - - void run() { - - System.out.println("begin directory scanning ..."); - scanDirectory(pakPath); - System.out.println(imageFiles.size() + " graphic files found\n"); - - ImageFrame frame = new ImageFrame(null); - frame.setVisible(true); - - File f = null; - BufferedImage image = null; - - for (Iterator it = imageFiles.iterator(); it.hasNext();) { - f = (File) it.next(); - try { - image = scale(ImageIO.read(f)); - frame.showImage(image); - frame.setTitle(f.getPath()); - - Thread.sleep(PAUSE); - - } catch (IOException e) { - System.err.println(e.getMessage()); - } catch (InterruptedException e) { - } - } - frame.dispose(); - imageFiles.clear(); - } - - void scanDirectory(File dir) { - File[] files = dir.listFiles(new FilenameFilter() { - public boolean accept(File dir, String name) { - /* matches *.pcx or *.wal files */ - return name.matches(".*(pcx|wal)$"); - } - }); - - if (files != null && files.length > 0) { - imageFiles.addAll(Arrays.asList(files)); - } - - File[] dirs = dir.listFiles(new FileFilter() { - public boolean accept(File pathname) { - return pathname.isDirectory(); - } - }); - - if (dirs != null && dirs.length > 0) { - for (int i = 0; i < dirs.length; i++) { - System.out.println(dirs[i]); - // recursive directory scanning - scanDirectory(dirs[i]); - } - } - } - - BufferedImage scale(BufferedImage src) { - BufferedImage dst = null; - - int size = Math.max(src.getHeight(), src.getWidth()); - - double scale = 1.5; - - if (size < 50) { - scale = 4.0; - } else if (size < 200) { - scale = 2.5; - } else if (size > 400) { - scale = 1.5; - } - BufferedImageOp op = - new AffineTransformOp( - AffineTransform.getScaleInstance(scale, scale), - AffineTransformOp.TYPE_NEAREST_NEIGHBOR/*TYPE_BILINEAR*/); - dst = op.filter(src, null); - - return (dst != null) ? dst : src; - } -} diff --git a/test/jake2/qcommon/TestCMD.java b/test/jake2/qcommon/TestCMD.java index 140f075..3316fd7 100644 --- a/test/jake2/qcommon/TestCMD.java +++ b/test/jake2/qcommon/TestCMD.java @@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 29.12.2003 by RST. -// $Id: TestCMD.java,v 1.1 2004-07-07 19:59:56 hzi Exp $ +// $Id: TestCMD.java,v 1.2 2004-07-09 06:50:51 hzi Exp $ package jake2.qcommon; @@ -49,7 +49,6 @@ public class TestCMD { } } catch (Exception e) { - // TODO: handle exception e.printStackTrace(); } } diff --git a/test/jake2/qcommon/TestFS.java b/test/jake2/qcommon/TestFS.java deleted file mode 100644 index f46f43f..0000000 --- a/test/jake2/qcommon/TestFS.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * TestFS.java - * Copyright (C) 2003 - * - * $Id: TestFS.java,v 1.1 2004-07-07 19:59:56 hzi 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.qcommon; - -import jake2.game.Cmd; -import jake2.imageio.ImageFrame; - -import java.awt.image.BufferedImage; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.util.Collection; -import java.util.Iterator; -import java.util.TreeSet; -import java.util.logging.*; - -import javax.imageio.ImageIO; -import javax.imageio.stream.MemoryCacheImageInputStream; - -/** - * TestFS - * - * @author cwei - */ -public class TestFS { - - public static void main(String[] args) { - System.out.println("*** Start FS test ***\n"); - - init(); - - FS.InitFilesystem(); - - Cmd.ExecuteString("link unknown.pcx ../../baseq2/space.pcx"); - Cmd.ExecuteString("link unknown1.pcx ../../baseq2/config.cfg"); - - FS.Path_f(); - - // loescht den link - Cmd.ExecuteString("link unknown1.pcx"); - - FS.Path_f(); - - Cmd.ExecuteString("dir players/male/*.[a-zA-Z_0-9]?x"); - - // search for pack_t - FS.searchpath_t search; - Collection filenames = new TreeSet(); - for (search = FS.fs_searchpaths; search != null; search = search.next) { - // is the element a pak file? - if (search.pack != null) { - // add all the pak file names - filenames.addAll(search.pack.files.keySet()); - } - } - - ImageFrame frame = new ImageFrame(null); - frame.setVisible(true); - byte[] buffer = null; - - BufferedImage image = null; - for (Iterator it = filenames.iterator(); it.hasNext();) { - - String filename = it.next().toString(); - if (!filename.endsWith(".wal") && !filename.endsWith(".pcx")) continue; - - buffer = FS.LoadFile(filename); - - if (buffer != null) { - try { - image = - ImageIO.read( - new MemoryCacheImageInputStream( - new ByteArrayInputStream(buffer))); - - frame.showImage(image); - frame.setTitle(filename); - - Thread.sleep(15); - - } catch (IOException e) { - e.printStackTrace(); - } catch (InterruptedException e1) { - } - } - } - frame.dispose(); - - System.gc(); - Runtime rt = Runtime.getRuntime(); - System.out.println( - "\nJVM total memory: " + rt.totalMemory() / 1024 + " Kbytes"); - - System.out.println("\n*** FS test is succeeded :-) ***"); - } - - static void init() { - // init the global LogManager with the logging.properties file - try { - LogManager.getLogManager().readConfiguration( - TestFS.class.getResourceAsStream("/jake2/logging.properties")); - } catch (SecurityException secEx) { - secEx.printStackTrace(); - } catch (IOException ioEx) { - System.err.println( - "FATAL Error: can't load /jake2/logging.properties (classpath)"); - ioEx.printStackTrace(); - } - } -} diff --git a/test/jake2/qcommon/TestLoadMap.java b/test/jake2/qcommon/TestLoadMap.java index 3410ca2..bc3efca 100644 --- a/test/jake2/qcommon/TestLoadMap.java +++ b/test/jake2/qcommon/TestLoadMap.java @@ -19,24 +19,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 02.01.2004 by RST. -// $Id: TestLoadMap.java,v 1.1 2004-07-07 19:59:56 hzi Exp $ +// $Id: TestLoadMap.java,v 1.2 2004-07-09 06:50:51 hzi Exp $ package jake2.qcommon; - -// import jake2.*; -// import jake2.client.*; -// import jake2.game.*; -// import jake2.qcommon.*; -// import jake2.render.*; -// import jake2.server.*; - public class TestLoadMap { public static void main(String[] args) { Com.DPrintf("hello!\n"); FS.InitFilesystem(); - CM.CM_LoadMap("maps/base1.bsp", true, new CM.intwrap(0)); + CM.CM_LoadMap("maps/base1.bsp", true, new int[]{0}); } } diff --git a/test/jake2/qcommon/TestMD4.java b/test/jake2/qcommon/TestMD4.java index 9b86058..5a0d84a 100644 --- a/test/jake2/qcommon/TestMD4.java +++ b/test/jake2/qcommon/TestMD4.java @@ -19,7 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 02.02.2004 by RST. -// $Id: TestMD4.java,v 1.1 2004-07-07 19:59:57 hzi Exp $ +// $Id: TestMD4.java,v 1.2 2004-07-09 06:50:51 hzi Exp $ package jake2.qcommon; @@ -1133,6 +1133,35 @@ public class TestMD4 { test("abc"); test("abcdefghijklmnopqrstuvwxyz"); test("hi"); + MD4 md4 = new MD4(); + + byte data[]= + { + (byte) 0x71, + (byte) 0xa9, + (byte) 0x05, + (byte) 0xce, + (byte) 0x8d, + (byte) 0x75, + (byte) 0x28, + (byte) 0xc8, + (byte) 0xba, + (byte) 0x97, + + (byte) 0x45, + (byte) 0xe9, + (byte) 0x8a, + (byte) 0xe0, + (byte) 0x37, + (byte) 0xbd, + (byte) 0x6c, + (byte) 0x6d, + (byte) 0x67, + (byte) 0x4a, + (byte) 0x21 }; + + System.out.println("checksum=" + MD4.Com_BlockChecksum(data, 21)); + } public static void test(String s) { diff --git a/test/jake2/qcommon/TestTGA.java b/test/jake2/qcommon/TestTGA.java deleted file mode 100644 index 32d45cd..0000000 --- a/test/jake2/qcommon/TestTGA.java +++ /dev/null @@ -1,327 +0,0 @@ -/* - * TestTGA.java - * Copyright (C) 2003 - * - * $Id: TestTGA.java,v 1.1 2004-07-08 20:24:31 hzi 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.qcommon; - -import jake2.game.Cmd; -import jake2.imageio.ImageFrame; - -import java.awt.Dimension; -import java.awt.geom.AffineTransform; -import java.awt.image.AffineTransformOp; -import java.awt.image.BufferedImage; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.IntBuffer; -import java.util.Collection; -import java.util.Iterator; -import java.util.TreeSet; -import java.util.logging.*; - -import javax.imageio.stream.MemoryCacheImageInputStream; - - - -/** - * TestTGA - * - * @author cwei - */ -public class TestTGA { - - public static void main(String[] args) { - System.out.println("*** Start TGA test ***\n"); - - init(); - - FS.InitFilesystem(); - - // search for pack_t - FS.searchpath_t search; - Collection filenames = new TreeSet(); - for (search = FS.fs_searchpaths; search != null; search = search.next) { - // is the element a pak file? - if (search.pack != null) { - // add all the pak file names - filenames.addAll(search.pack.files.keySet()); - } - } - - ImageFrame frame = new ImageFrame(null); - frame.setVisible(true); - frame.setLocation(50, 50); - frame.setSize(800, 800); - - byte[] buffer = null; - Dimension dim = new Dimension(); - BufferedImage image = null; - - int[] pixel = new int[512 * 512]; - - - for (Iterator it = filenames.iterator(); it.hasNext();) { - - String filename = it.next().toString(); - if (!filename.endsWith(".tga")) continue; - - System.out.println(filename); - buffer = LoadTGA(filename, dim); - - if (buffer != null) { - try { - - int w = dim.width; - int h = dim.height; - int size = w * h; - - int r, g, b, a; - - for (int i = 0; i < size; i++) - { - r = buffer[4* i + 0] & 0xFF; - g = buffer[4* i + 1] & 0xFF; - b = buffer[4* i + 2] & 0xFF; - a = buffer[4* i +3] & 0xFF; - - pixel[i] = (a << 24) | (r << 16) | (g << 8) | (b << 0); - } - - image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); - image.setRGB(0, 0, w, h, pixel, 0, w); - - AffineTransformOp op = new AffineTransformOp(AffineTransform.getScaleInstance(3, 3), AffineTransformOp.TYPE_NEAREST_NEIGHBOR); - BufferedImage tmp = op.filter(image, null); - - frame.showImage(tmp); - frame.setTitle(filename); - - Thread.sleep(500); - - } catch (InterruptedException e) { - } - } - } - frame.dispose(); - - System.gc(); - Runtime rt = Runtime.getRuntime(); - System.out.println( - "\nJVM total memory: " + rt.totalMemory() / 1024 + " Kbytes"); - - System.out.println("\n*** TGA test is succeeded :-) ***"); - } - - static void init() { - // init the global LogManager with the logging.properties file - try { - LogManager.getLogManager().readConfiguration( - TestFS.class.getResourceAsStream("/jake2/logging.properties")); - } catch (SecurityException secEx) { - secEx.printStackTrace(); - } catch (IOException ioEx) { - System.err.println( - "FATAL Error: can't load /jake2/logging.properties (classpath)"); - ioEx.printStackTrace(); - } - } - - /* - ============= - LoadTGA - ============= - */ - static byte[] LoadTGA(String name, Dimension dim) { - int columns, rows, numPixels; - int pixbuf; // index into pic - int row, column; - byte[] raw; - ByteBuffer buf_p; - int length; - qfiles.tga_t targa_header; - byte[] pic = null; - - // - // load the file - // - raw = FS.LoadFile(name); - - if (raw == null) - { - System.out.println("Bad tga file "+ name +'\n'); - return null; - } - - targa_header = new qfiles.tga_t(raw); - - if (targa_header.image_type != 2 && targa_header.image_type != 10) - System.out.println("LoadTGA: Only type 2 and 10 targa RGB images supported\n"); - - if (targa_header.colormap_type != 0 || (targa_header.pixel_size != 32 && targa_header.pixel_size != 24)) - System.out.println("LoadTGA: Only 32 or 24 bit images supported (no colormaps)\n"); - - columns = targa_header.width; - rows = targa_header.height; - numPixels = columns * rows; - - if (dim != null) { - dim.width = columns; - dim.height = rows; - } - - pic = new byte[numPixels * 4]; // targa_rgba; - - if (targa_header.id_length != 0) - targa_header.data.position(targa_header.id_length); // skip TARGA image comment - - buf_p = targa_header.data; - - byte red,green,blue,alphabyte; - red = green = blue = alphabyte = 0; - int packetHeader, packetSize, j; - - if (targa_header.image_type==2) { // Uncompressed, RGB images - for(row=rows-1; row>=0; row--) { - - pixbuf = row * columns * 4; - - for(column=0; column<columns; column++) { - switch (targa_header.pixel_size) { - case 24: - - blue = buf_p.get(); - green = buf_p.get(); - red = buf_p.get(); - pic[pixbuf++] = red; - pic[pixbuf++] = green; - pic[pixbuf++] = blue; - pic[pixbuf++] = (byte)255; - break; - case 32: - blue = buf_p.get(); - green = buf_p.get(); - red = buf_p.get(); - alphabyte = buf_p.get(); - pic[pixbuf++] = red; - pic[pixbuf++] = green; - pic[pixbuf++] = blue; - pic[pixbuf++] = alphabyte; - break; - } - } - } - } - else if (targa_header.image_type==10) { // Runlength encoded RGB images - for(row=rows-1; row>=0; row--) { - - pixbuf = row * columns * 4; - try { - - for(column=0; column<columns; ) { - - packetHeader= buf_p.get() & 0xFF; - packetSize = 1 + (packetHeader & 0x7f); - - if ((packetHeader & 0x80) != 0) { // run-length packet - switch (targa_header.pixel_size) { - case 24: - blue = buf_p.get(); - green = buf_p.get(); - red = buf_p.get(); - alphabyte = (byte)255; - break; - case 32: - blue = buf_p.get(); - green = buf_p.get(); - red = buf_p.get(); - alphabyte = buf_p.get(); - break; - } - - for(j=0;j<packetSize;j++) { - pic[pixbuf++]=red; - pic[pixbuf++]=green; - pic[pixbuf++]=blue; - pic[pixbuf++]=alphabyte; - column++; - if (column==columns) { // run spans across rows - column=0; - if (row>0) - row--; - else - // goto label breakOut; - throw new longjmpException(); - - pixbuf = row * columns * 4; - } - } - } - else { // non run-length packet - for(j=0;j<packetSize;j++) { - switch (targa_header.pixel_size) { - case 24: - blue = buf_p.get(); - green = buf_p.get(); - red = buf_p.get(); - pic[pixbuf++] = red; - pic[pixbuf++] = green; - pic[pixbuf++] = blue; - pic[pixbuf++] = (byte)255; - break; - case 32: - blue = buf_p.get(); - green = buf_p.get(); - red = buf_p.get(); - alphabyte = buf_p.get(); - pic[pixbuf++] = red; - pic[pixbuf++] = green; - pic[pixbuf++] = blue; - pic[pixbuf++] = alphabyte; - break; - } - column++; - if (column==columns) { // pixel packet run spans across rows - column=0; - if (row>0) - row--; - else - // goto label breakOut; - throw new longjmpException(); - - pixbuf = row * columns * 4; - } - } - } - } - } catch (longjmpException e){ - // label breakOut: - } - } - } - return pic; - } - -} diff --git a/test/jake2/render/DancingQueens.java b/test/jake2/render/DancingQueens.java index d7d2ea4..db4200c 100644 --- a/test/jake2/render/DancingQueens.java +++ b/test/jake2/render/DancingQueens.java @@ -2,7 +2,7 @@ * DancingQueens.java * Copyright (C) 2003 * - * $Id: DancingQueens.java,v 1.2 2004-07-08 20:24:31 hzi Exp $ + * $Id: DancingQueens.java,v 1.3 2004-07-09 06:50:51 hzi Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. @@ -152,14 +152,14 @@ public class DancingQueens }; - Qcommon.InitForTestMap(new String[] {"DancingQueens"}); + Qcommon.Init(new String[] {"DancingQueens"}); // sehr wichtig !!! VID.Shutdown(); String[] names = Renderer.getDriverNames(); System.out.println("Registered Drivers: " + Arrays.asList(names)); - this.re = Renderer.getDriver("jogl", ri); + this.re = Renderer.getDriver("fastjogl", ri); System.out.println("Use driver: " + re); System.out.println(); diff --git a/test/jake2/render/TestMap.java b/test/jake2/render/TestMap.java index 711b159..e6670dc 100644 --- a/test/jake2/render/TestMap.java +++ b/test/jake2/render/TestMap.java @@ -2,7 +2,7 @@ * TestMap.java * Copyright (C) 2003 * - * $Id: TestMap.java,v 1.2 2004-07-08 20:24:31 hzi Exp $ + * $Id: TestMap.java,v 1.3 2004-07-09 06:50:51 hzi Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. @@ -36,6 +36,7 @@ import jake2.sys.KBD; import jake2.util.*; import java.awt.Dimension; +import java.nio.FloatBuffer; import java.util.*; /** @@ -177,7 +178,7 @@ public class TestMap } }; - Qcommon.InitForTestMap(new String[] { "TestMap $Id: TestMap.java,v 1.2 2004-07-08 20:24:31 hzi Exp $" }); + Qcommon.Init(new String[] { "TestMap $Id: TestMap.java,v 1.3 2004-07-09 06:50:51 hzi Exp $" }); // sehr wichtig !!! VID.Shutdown(); @@ -246,8 +247,8 @@ public class TestMap break; case 1 : // register the map - re.SetSky("space1", 0, new float[]{ 0, 0, 0 }); re.BeginRegistration("base1"); + re.SetSky("space1", 0, new float[]{ 0, 0, 0 }); re.EndRegistration(); currentState = 2; //break; @@ -431,7 +432,7 @@ public class TestMap refdef.time = time() * 0.001f; // particle init - particles.clear(); + r_numparticles = 0; // check the enemy distance float[] diff = {0, 0, 0}; @@ -451,11 +452,7 @@ public class TestMap // particles animateParticles(); - particle_t[] tmp = new particle_t[particles.size()]; - particles.toArray(tmp); - - refdef.particles = tmp; - refdef.num_particles = tmp.length; + refdef.num_particles = r_numparticles; } else { ent.frame = 0; @@ -463,10 +460,11 @@ public class TestMap } } + refdef.num_dlights = 0; + re.RenderFrame(refdef); } - private Vector particles = new Vector(1024); // = new particle_t[20]; private LinkedList active_particles = new LinkedList(); private boolean explode = false; private float[] target; @@ -480,8 +478,7 @@ public class TestMap float time, time2; float[] org = {0, 0, 0}; int color; - particle_t particle; - + time = 0.0f; for (Iterator it = active_particles.iterator(); it.hasNext();) @@ -514,13 +511,8 @@ public class TestMap org[1] = p.org[1] + p.vel[1]*time + p.accel[1]*time2; org[2] = p.org[2] + p.vel[2]*time + p.accel[2]*time2; - particle = new particle_t(); - particle.alpha = alpha; - Math3D.VectorCopy(org, particle.origin); - particle.color = color; - - particles.add(particle); - + AddParticle(org, color, alpha); + // PMM if (p.alphavel == INSTANT_PARTICLE) { @@ -565,7 +557,7 @@ public class TestMap Math3D.VectorMA (dir, s, up, dir); p.alpha = 1.0f; - p.alphavel = -1.0f / (1 + Lib.frand() * 0.2f); + p.alphavel = -1.0f / (1 + Globals.rnd.nextFloat() * 0.2f); p.color = 0x74 + (Lib.rand() & 7); for (j=0 ; j<3 ; j++) { @@ -592,7 +584,7 @@ public class TestMap Math3D.VectorClear (p.accel); p.alpha = 1.0f; - p.alphavel = -1.0f / (0.6f + Lib.frand() * 0.2f); + p.alphavel = -1.0f / (0.6f + Globals.rnd.nextFloat() * 0.2f); p.color = 0x0 + Lib.rand()&15; for (j=0 ; j<3 ; j++) @@ -625,4 +617,28 @@ public class TestMap IN.toggleMouse(); } }; + + int r_numparticles = 0; + /* + ===================== + V_AddParticle + + ===================== + */ + void AddParticle(float[] org, int color, float alpha) { + if (r_numparticles >= Defines.MAX_PARTICLES) + return; + + int i = r_numparticles++; + + int c = particle_t.colorTable[color]; + c |= (int)(alpha * 255) << 24; + particle_t.colorArray.put(i, c); + + i *= 3; + FloatBuffer vertexBuf = particle_t.vertexArray; + vertexBuf.put(i++, org[0]); + vertexBuf.put(i++, org[1]); + vertexBuf.put(i++, org[2]); + } } diff --git a/test/jake2/render/TestRenderer.java b/test/jake2/render/TestRenderer.java index e152747..376bb60 100644 --- a/test/jake2/render/TestRenderer.java +++ b/test/jake2/render/TestRenderer.java @@ -2,7 +2,7 @@ * TestRenderer.java * Copyright (C) 2003 * - * $Id: TestRenderer.java,v 1.2 2004-07-08 20:24:31 hzi Exp $ + * $Id: TestRenderer.java,v 1.3 2004-07-09 06:50:51 hzi Exp $ */ /* Copyright (C) 1997-2001 Id Software, Inc. @@ -26,6 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. package jake2.render; import java.awt.Dimension; +import java.nio.FloatBuffer; import java.util.Arrays; import java.util.Iterator; import java.util.LinkedList; @@ -441,7 +442,6 @@ public class TestRenderer { re.RenderFrame(refdef); } - private Vector particles = new Vector(1024); // = new particle_t[20]; private LinkedList active_particles = new LinkedList(); private boolean explode = false; private float[] target; @@ -450,7 +450,7 @@ public class TestRenderer { private void testParticles() { - particles.clear(); + r_numparticles = 0; if (active_particles.size() == 0) { if (explode) @@ -474,14 +474,9 @@ public class TestRenderer { animateParticles(); - drawString(refdef.x, refdef.y - 20, "active particles: " + particles.size()); + drawString(refdef.x, refdef.y - 20, "active particles: " + r_numparticles); - particle_t[] tmp = new particle_t[particles.size()]; - - particles.toArray(tmp); - - refdef.particles = tmp; - refdef.num_particles = tmp.length; + refdef.num_particles = r_numparticles; refdef.areabits = null; refdef.num_entities = 0; @@ -582,7 +577,7 @@ public class TestRenderer { p.accel[0] = p.accel[1] = 0; p.accel[2] = -PARTICLE_GRAVITY; p.alpha = 1.0f; - p.alphavel = -0.8f / (0.5f + Lib.frand() * 0.3f); + p.alphavel = -0.8f / (0.5f + Globals.rnd.nextFloat() * 0.3f); active_particles.add(p); } @@ -604,7 +599,6 @@ public class TestRenderer { float time, time2; float[] org = {0, 0, 0}; int color; - particle_t particle; time = 0.0f; @@ -637,13 +631,8 @@ public class TestRenderer { org[0] = p.org[0] + p.vel[0]*time + p.accel[0]*time2; org[1] = p.org[1] + p.vel[1]*time + p.accel[1]*time2; org[2] = p.org[2] + p.vel[2]*time + p.accel[2]*time2; - - particle = new particle_t(); - particle.alpha = alpha; - Math3D.VectorCopy(org, particle.origin); - particle.color = color; - particles.add(particle); + AddParticle(org, color, alpha); // PMM if (p.alphavel == INSTANT_PARTICLE) @@ -778,7 +767,7 @@ public class TestRenderer { Math3D.VectorMA (dir, s, up, dir); p.alpha = 1.0f; - p.alphavel = -1.0f / (1 + Lib.frand() * 0.2f); + p.alphavel = -1.0f / (1 + Globals.rnd.nextFloat() * 0.2f); p.color = 0x74 + (Lib.rand() & 7); for (j=0 ; j<3 ; j++) { @@ -805,7 +794,7 @@ public class TestRenderer { Math3D.VectorClear (p.accel); p.alpha = 1.0f; - p.alphavel = -1.0f / (0.6f + Lib.frand() * 0.2f); + p.alphavel = -1.0f / (0.6f + Globals.rnd.nextFloat() * 0.2f); p.color = 0x0 + Lib.rand()&15; for (j=0 ; j<3 ; j++) @@ -830,5 +819,28 @@ public class TestRenderer { testnr = testnr % 3; } }; + + int r_numparticles = 0; + /* + ===================== + V_AddParticle + ===================== + */ + void AddParticle(float[] org, int color, float alpha) { + if (r_numparticles >= Defines.MAX_PARTICLES) + return; + + int i = r_numparticles++; + + int c = particle_t.colorTable[color]; + c |= (int)(alpha * 255) << 24; + particle_t.colorArray.put(i, c); + + i *= 3; + FloatBuffer vertexBuf = particle_t.vertexArray; + vertexBuf.put(i++, org[0]); + vertexBuf.put(i++, org[1]); + vertexBuf.put(i++, org[2]); + } } |