Behold, Nenya, Ring of Water and repository for our media and animation related

goodies, both Java 2D and LWJGL/JME 3D.


git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@1 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Michael Bayne
2006-06-23 18:07:28 +00:00
commit c2117ee86d
570 changed files with 61913 additions and 0 deletions
@@ -0,0 +1,80 @@
//
// $Id: ImageLoadingSpeed.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.media;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.*;
import com.threerings.media.image.FastImageIO;
/**
* Tests our image loading speed.
*/
public class ImageLoadingSpeed
{
public static void main (String[] args)
{
if (args.length < 1) {
System.err.println("Usage: ImageLoadingTest image");
System.exit(-1);
}
File file = new File(args[0]);
File ffile = new File(args[0] + FastImageIO.FILE_SUFFIX);
try {
BufferedImage image = ImageIO.read(file);
FastImageIO.write(image, new FileOutputStream(ffile));
} catch (IOException ioe) {
ioe.printStackTrace(System.err);
System.exit(-1);
}
long start = System.currentTimeMillis();
int iter = 0;
while (true) {
try {
FastImageIO.read(ffile).getWidth();
} catch (IOException ioe) {
ioe.printStackTrace(System.err);
System.exit(-1);
}
if (++iter == 100) {
long now = System.currentTimeMillis();
long elapsed = now - start;
System.err.println("Loaded " + args.length +
" images a total of " + iter +
" times in " + elapsed + "ms.");
System.err.println("An average of " + (elapsed/iter) +
"ms per image.");
System.gc();
try { Thread.sleep(1000); } catch (Throwable t) {}
start = now;
iter = 0;
}
}
}
}
@@ -0,0 +1,65 @@
//
// $Id: TestIconManager.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.media;
import java.awt.BorderLayout;
import javax.swing.*;
import com.samskivert.swing.HGroupLayout;
import com.samskivert.swing.util.SwingUtil;
import com.threerings.media.image.ImageManager;
import com.threerings.media.tile.TileManager;
import com.threerings.resource.ResourceManager;
/**
* Does something extraordinary.
*/
public class TestIconManager
{
public static void main (String[] args)
{
try {
JFrame frame = new JFrame("TestIconManager");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ResourceManager rmgr = new ResourceManager("rsrc");
ImageManager imgr = new ImageManager(rmgr, frame);
TileManager tmgr = new TileManager(imgr);
IconManager iconmgr = new IconManager(
tmgr, "rsrc/config/media/iconmgr.properties");
JPanel panel = new JPanel(new HGroupLayout());
for (int i = 0; i < 8; i++) {
panel.add(new JButton(iconmgr.getIcon("test", i)));
}
frame.getContentPane().add(panel, BorderLayout.CENTER);
frame.pack();
SwingUtil.centerWindow(frame);
frame.show();
} catch (Exception e) {
e.printStackTrace(System.err);
}
}
}
@@ -0,0 +1,68 @@
//
// $Id: SoundTestApp.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.media.sound;
import com.threerings.resource.ResourceManager;
import com.threerings.media.Log;
public class SoundTestApp
{
public SoundTestApp (String[] args)
{
if (args.length == 0) {
Log.info("Usage: runjava com.threerings.media.SoundTestApp " +
"<key1> [<key2> <key3> ...]");
System.exit(0);
}
ResourceManager rmgr = new ResourceManager("rsrc");
_soundmgr = new SoundManager(rmgr, null, null);
_keys = args;
}
public void run ()
{
for (int ii = 0; ii < _keys.length; ii++) {
System.out.println("Playing " + _keys[ii] + ".");
_soundmgr.play(SoundManager.DEFAULT,
"com/threerings/media/sound/", _keys[ii]);
}
_soundmgr.shutdown();
// the sound manager starts up threads that never seem to exit so
// we have to stick a fork in things after a short while
try {
Thread.sleep(5000L);
} catch (InterruptedException ie) {
}
System.exit(0);
}
public static void main (String[] args)
{
SoundTestApp app = new SoundTestApp(args);
app.run();
}
protected String[] _keys;
protected SoundManager _soundmgr;
}
@@ -0,0 +1,7 @@
#
# $Id: sounds.properties 2051 2002-12-10 21:36:53Z mdb $
#
# Sound test app configuration file
sound1 = media/test.wav
sound2 = foo/bar.wav
@@ -0,0 +1,70 @@
//
// $Id: BundledTileSetRepositoryTest.java 3720 2005-10-05 01:39:45Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.media.tile.bundle;
import java.awt.Component;
import java.util.Iterator;
import com.threerings.media.image.ImageManager;
import com.threerings.resource.ResourceManager;
import junit.framework.Test;
import junit.framework.TestCase;
public class BundledTileSetRepositoryTest extends TestCase
{
public BundledTileSetRepositoryTest ()
{
super(BundledTileSetRepositoryTest.class.getName());
}
public void runTest ()
{
try {
ResourceManager rmgr = new ResourceManager("rsrc");
rmgr.initBundles(
null, "config/resource/manager.properties", null);
BundledTileSetRepository repo = new BundledTileSetRepository(
rmgr, new ImageManager(rmgr, (Component)null), "tilesets");
Iterator sets = repo.enumerateTileSets();
while (sets.hasNext()) {
sets.next();
// System.out.println(sets.next());
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static Test suite ()
{
return new BundledTileSetRepositoryTest();
}
public static void main (String[] args)
{
BundledTileSetRepositoryTest test =
new BundledTileSetRepositoryTest();
test.runTest();
}
}
@@ -0,0 +1,94 @@
//
// $Id: BuildTestTileSetBundle.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.media.tile.bundle.tools;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import com.samskivert.io.PersistenceException;
import com.samskivert.test.TestUtil;
import com.threerings.media.tile.TileSetIDBroker;
public class BuildTestTileSetBundle
{
public static void main (String[] args)
{
try {
TileSetIDBroker broker = new DummyTileSetIDBroker();
// sort out some paths
String configPath = TestUtil.getResourcePath(CONFIG_PATH);
String descPath = TestUtil.getResourcePath(BUNDLE_DESC_PATH);
String targetPath = TestUtil.getResourcePath(TARGET_PATH);
// create our bundler and get going
TileSetBundler bundler = new TileSetBundler(configPath);
File descFile = new File(descPath);
bundler.createBundle(broker, descFile, targetPath);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
/** Dummy tileset id broker that makes up tileset ids (which are
* consistent in the course of execution of the application, but not
* between invocations). */
protected static class DummyTileSetIDBroker
extends HashMap
implements TileSetIDBroker
{
public int getTileSetID (String tileSetName)
throws PersistenceException
{
Integer id = (Integer)get(tileSetName);
if (id == null) {
id = new Integer(++_nextId);
put(tileSetName, id);
}
return id.intValue();
}
public boolean tileSetMapped (String tileSetName)
{
return containsKey(tileSetName);
}
public void commit ()
throws PersistenceException
{
}
protected int _nextId;
}
protected static final String CONFIG_PATH =
"rsrc/media/tile/bundle/tools/bundler-config.xml";
protected static final String BUNDLE_DESC_PATH =
"rsrc/media/tile/bundle/tools/bundle.xml";
protected static final String TARGET_PATH =
"rsrc/media/tile/bundle/tools/bundle.jar";
}
@@ -0,0 +1,78 @@
//
// $Id: XMLTileSetParserTest.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.media.tile.tools.xml;
import java.io.IOException;
import java.util.Iterator;
import java.util.HashMap;
import junit.framework.Test;
import junit.framework.TestCase;
public class XMLTileSetParserTest extends TestCase
{
public XMLTileSetParserTest ()
{
super(XMLTileSetParserTest.class.getName());
}
public void runTest ()
{
HashMap sets = new HashMap();
XMLTileSetParser parser = new XMLTileSetParser();
// add some rulesets
parser.addRuleSet("tilesets/uniform", new UniformTileSetRuleSet());
parser.addRuleSet("tilesets/swissarmy", new SwissArmyTileSetRuleSet());
parser.addRuleSet("tilesets/object", new ObjectTileSetRuleSet());
// load up the tilesets
try {
parser.loadTileSets(TILESET_PATH, sets);
// print them out
Iterator iter = sets.values().iterator();
while (iter.hasNext()) {
iter.next();
// System.out.println(iter.next());
}
} catch (IOException ioe) {
ioe.printStackTrace();
fail("loadTileSets() failed");
}
}
public static Test suite ()
{
return new XMLTileSetParserTest();
}
public static void main (String[] args)
{
XMLTileSetParserTest test = new XMLTileSetParserTest();
test.runTest();
}
protected static final String TILESET_PATH =
"rsrc/media/tile/tools/xml/tilesets.xml";
}
@@ -0,0 +1,111 @@
//
// $Id: PathViz.java 4181 2006-06-07 21:54:12Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.media.util;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import javax.swing.JFrame;
import com.threerings.media.FrameManager;
import com.threerings.media.ManagedJFrame;
import com.threerings.media.MediaPanel;
import com.threerings.media.sprite.Sprite;
/**
* A test app that is useful for visualizing paths during their
* development.
*/
public class PathViz extends MediaPanel
{
public PathViz (FrameManager fmgr)
{
super(fmgr);
// create a sprite that we can send along a path
Sprite sprite = new HappySprite();
addSprite(sprite);
// create a path for our sprite
Point start = new Point(150, 150);
double sangle = -3*Math.PI/4;
ArcPath path = new ArcPath(
start, 64, 48, sangle, -Math.PI/2, MOVE_DURATION, ArcPath.NORMAL);
// LinePath path = new LinePath(0, 0, 300, 300, MOVE_DURATION);
sprite.move(path);
}
// documentation inherited from interface
public void paintBetween (Graphics2D gfx, Rectangle dirtyRect)
{
super.paintBetween(gfx, dirtyRect);
gfx.setColor(Color.gray);
gfx.fill(dirtyRect);
_spritemgr.renderSpritePaths(gfx);
}
public Dimension getPreferredSize ()
{
return new Dimension(300, 300);
}
public static void main (String[] args)
{
ManagedJFrame frame = new ManagedJFrame("Path viz");
FrameManager fmgr = FrameManager.newInstance(frame, frame);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(new PathViz(fmgr));
fmgr.start();
frame.pack();
frame.setVisible(true);
}
protected static class HappySprite extends Sprite
{
public HappySprite ()
{
_bounds.width = 32;
_bounds.height = 32;
_oxoff = 16;
_oyoff = 16;
}
public void paint (Graphics2D gfx)
{
gfx.setColor(Color.blue);
int hx = _bounds.x + _bounds.width/2;
int hy = _bounds.y + _bounds.height/2;
gfx.drawLine(hx, _bounds.y, hx, _bounds.y + _bounds.height-1);
gfx.drawLine(_bounds.x, hy, _bounds.x+_bounds.width-1, hy);
gfx.setColor(Color.black);
gfx.drawRect(_bounds.x, _bounds.y,
_bounds.width-1, _bounds.height-1);
}
}
protected static final long MOVE_DURATION = 10*1000L;
}
@@ -0,0 +1,115 @@
//
// $Id: TraceViz.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.media.util;
import java.awt.Color;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import com.samskivert.swing.VGroupLayout;
import com.samskivert.swing.util.SwingUtil;
import com.threerings.media.Log;
import com.threerings.media.image.ImageManager;
import com.threerings.media.image.ImageUtil;
/**
* Simple application for testing image trace functionality.
*/
public class TraceViz
{
public TraceViz (String[] args)
throws IOException
{
// create the frame and image manager
_frame = new JFrame();
_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageManager imgr = new ImageManager(null, _frame);
// set up the content panel
JPanel content = (JPanel)_frame.getContentPane();
content.setBackground(Color.white);
content.setLayout(new VGroupLayout());
// load the image
BufferedImage image = ImageIO.read(new File(args[0]));
if (image == null) {
throw new RuntimeException("Failed to read file " +
"[file=" + args[0] + "].");
}
// // create a compatible image
// BufferedImage cimage = imgr.createImage(
// image.getWidth(null), image.getHeight(null),
// Transparency.TRANSLUCENT);
// Graphics g = cimage.getGraphics();
// g.drawImage(image, 0, 0, null);
// g.dispose();
// image = cimage;
// create the traced image
Image timage = ImageUtil.createTracedImage(
imgr, image, Color.red, 5, 0.4f, 0.1f);
// display the (prepared) original and traced image
content.add(new JLabel(new ImageIcon(image)));
content.add(new JLabel(new ImageIcon(timage)));
}
public void run ()
{
_frame.pack();
SwingUtil.centerWindow(_frame);
_frame.show();
}
public static void main (String[] args)
{
try {
if (args.length == 0) {
System.out.println(
"Usage: java com.threerings.media.util.TraceViz " +
"<image file>");
return;
}
TraceViz app = new TraceViz(args);
app.run();
} catch (Exception e) {
Log.warning("Failed to run application: " + e);
Log.logStackTrace(e);
}
}
protected JFrame _frame;
}