Switched (partially) to Maven-based dependency resolution. Further work

forthcoming to fix up the tests.

Peskily, it looks like I'm going to have to take one for the team and become
the maintainer of a Maven artifact for LWJGL. In spite of repeated requests
over the years for Mavenized artifacts for LWJGL, Mazon resists it (he seems to
think he has to use Maven to *build* LWJGL, which he certainly need not do).
There have been a variety of half-assed attempts to maintain third-party Maven
repositories, all of which have petered out a major version or two ago.


git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@1045 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Michael Bayne
2010-11-08 18:51:32 +00:00
parent f1a2fe5e81
commit 63a26726d1
32 changed files with 327 additions and 192 deletions
@@ -0,0 +1,155 @@
//
// $Id: CharSpriteViz.java 3355 2005-02-17 01:54:54Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2010 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.cast;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.samskivert.swing.util.SwingUtil;
import com.threerings.util.DirectionCodes;
import com.threerings.util.DirectionUtil;
import com.threerings.resource.ResourceManager;
import com.threerings.media.image.ClientImageManager;
import com.threerings.cast.bundle.BundledComponentRepository;
/**
* Displays a character sprite in all of the various orientations.
*/
public class CharSpriteViz extends JPanel
implements DirectionCodes, MouseMotionListener
{
public CharSpriteViz (
CharacterManager charmgr, CharacterComponent ccomp, String action)
{
// get a handle on our sprite
_sprite = charmgr.getCharacter(
new CharacterDescriptor(
new int[] { ccomp.componentId }, null));
// put the sprite in the appropriate action mode
_sprite.setRestingAction(action);
_sprite.setFollowingPathAction(action);
_sprite.setActionSequence(action);
addMouseMotionListener(this);
}
public void mouseDragged (MouseEvent event)
{
}
public void mouseMoved (MouseEvent event)
{
int orient = DirectionUtil.getFineDirection(
getWidth()/2, getHeight()/2, event.getX(), event.getY());
if (_orient != orient) {
System.out.println("Switching to " +
DirectionUtil.toShortString(orient) + ".");
_orient = orient;
repaint();
}
}
@Override
public void paintComponent (Graphics g)
{
super.paintComponent(g);
int width = getWidth(), height = getHeight();
int cx = width/2, cy = height/2;
g.setColor(Color.darkGray);
g.drawLine(cx, cy, 0, cy);
g.drawLine(cx, cy, 0, cy/2);
g.drawLine(cx, cy, 0, 0);
g.drawLine(cx, cy, cx/2, 0);
g.drawLine(cx, cy, cx, 0);
g.drawLine(cx, cy, 3*width/4, 0);
g.drawLine(cx, cy, width, 0);
g.drawLine(cx, cy, width, cy/2);
g.drawLine(cx, cy, width, cy);
g.drawLine(cx, cy, width, 3*height/4);
g.drawLine(cx, cy, width, height);
g.drawLine(cx, cy, 3*width/4, height);
g.drawLine(cx, cy, cx, height);
g.drawLine(cx, cy, cx/2, height);
g.drawLine(cx, cy, 0, height);
g.drawLine(cx, cy, 0, 3*height/4);
_sprite.setLocation(cx, cy);
_sprite.setOrientation(_orient);
_sprite.paint((Graphics2D)g);
}
public static void main (String[] args)
{
if (args.length < 3) {
System.err.println("Usage: CharSpriteViz cclass cname action");
System.err.println(" (eg. CharSpriteViz navsail smsloop sailing");
System.exit(-1);
}
JFrame frame = new JFrame("CharSpriteViz");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
try {
ResourceManager rmgr = new ResourceManager("rsrc");
rmgr.initBundles(
null, "config/resource/manager.properties", null);
ClientImageManager imgr = new ClientImageManager(rmgr, frame);
ComponentRepository crepo =
new BundledComponentRepository(rmgr, imgr, "components");
CharacterManager charmgr = new CharacterManager(imgr, crepo);
CharacterComponent ccomp = crepo.getComponent(args[0], args[1]);
frame.getContentPane().add(
new CharSpriteViz(charmgr, ccomp, args[2]),
BorderLayout.CENTER);
frame.setSize(200, 200);
SwingUtil.centerWindow(frame);
frame.setVisible(true);
} catch (NoSuchComponentException nsce) {
System.err.println("No component with specified class " +
"and name [cclass=" + args[0] +
", cname=" + args[1] + "].");
System.exit(-1);
} catch (Exception e) {
e.printStackTrace(System.err);
System.exit(-1);
}
}
protected CharacterSprite _sprite;
protected int _orient = NORTH;
}
@@ -0,0 +1,78 @@
//
// $Id: TestApp.java 3355 2005-02-17 01:54:54Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2010 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.cast.builder;
import java.io.IOException;
import javax.swing.JFrame;
import com.samskivert.swing.util.SwingUtil;
import com.threerings.resource.ResourceManager;
import com.threerings.media.image.ClientImageManager;
import com.threerings.cast.CharacterManager;
import com.threerings.cast.ComponentRepository;
import com.threerings.cast.bundle.BundledComponentRepository;
public class TestApp
{
public TestApp (String[] args)
throws IOException
{
_frame = new TestFrame();
_frame.setSize(800, 600);
SwingUtil.centerWindow(_frame);
ResourceManager rmgr = new ResourceManager("rsrc");
rmgr.initBundles(
null, "config/resource/manager.properties", null);
ClientImageManager imgr = new ClientImageManager(rmgr, _frame);
ComponentRepository crepo =
new BundledComponentRepository(rmgr, imgr, "components");
CharacterManager charmgr = new CharacterManager(imgr, crepo);
// initialize the frame
((TestFrame)_frame).init(charmgr, crepo);
}
public void run ()
{
_frame.pack();
_frame.setVisible(true);
}
public static void main (String[] args)
{
try {
TestApp app = new TestApp(args);
app.run();
} catch (IOException ioe) {
System.err.println("Error initializing app.");
ioe.printStackTrace();
}
}
protected JFrame _frame;
}
@@ -0,0 +1,43 @@
//
// $Id: TestFrame.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2010 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.cast.builder;
import javax.swing.JFrame;
import com.threerings.cast.CharacterManager;
import com.threerings.cast.ComponentRepository;
public class TestFrame extends JFrame
{
public TestFrame ()
{
super("Character Builder");
setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void init (CharacterManager charmgr, ComponentRepository crepo)
{
getContentPane().add(new BuilderPanel(charmgr, crepo, "male/"));
}
}
@@ -0,0 +1,90 @@
//
// $Id: BundledComponentRepositoryTest.java 3720 2005-10-05 01:39:45Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2010 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.cast.bundle;
import java.util.Iterator;
import java.awt.Component;
import junit.framework.Test;
import junit.framework.TestCase;
import com.threerings.resource.ResourceManager;
import com.threerings.media.image.ClientImageManager;
import com.threerings.cast.ComponentClass;
public class BundledComponentRepositoryTest extends TestCase
{
public BundledComponentRepositoryTest ()
{
super(BundledComponentRepositoryTest.class.getName());
}
@Override
public void runTest ()
{
try {
ResourceManager rmgr = new ResourceManager("rsrc");
rmgr.initBundles(
null, "config/resource/manager.properties", null);
ClientImageManager imgr = new ClientImageManager(rmgr, (Component)null);
BundledComponentRepository repo =
new BundledComponentRepository(rmgr, imgr, "components");
// System.out.println("Classes: " + StringUtil.toString(
// repo.enumerateComponentClasses()));
// System.out.println("Actions: " + StringUtil.toString(
// repo.enumerateActionSequences()));
// System.out.println("Action sets: " + StringUtil.toString(
// repo._actionSets.values().iterator()));
Iterator<ComponentClass> iter = repo.enumerateComponentClasses();
while (iter.hasNext()) {
// ComponentClass cclass = (ComponentClass)
iter.next();
// System.out.println("IDs [" + cclass + "]: " +
// StringUtil.toString(
// repo.enumerateComponentIds(cclass)));
}
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
public static void main (String[] args)
{
BundledComponentRepositoryTest test =
new BundledComponentRepositoryTest();
test.runTest();
}
public static Test suite ()
{
return new BundledComponentRepositoryTest();
}
}
@@ -0,0 +1,102 @@
//
// $Id: NearestViz.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2010 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.geom;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.samskivert.swing.util.SwingUtil;
/**
* Renders the nearest point on a line just for kicks.
*/
public class NearestViz extends JPanel
implements MouseMotionListener
{
public NearestViz ()
{
addMouseMotionListener(this);
}
@Override
public void doLayout ()
{
super.doLayout();
_center = new Point(getWidth() / 2, getHeight() / 2);
}
@Override
public void paintComponent (Graphics g)
{
super.paintComponent(g);
int dx = (int)Math.round(Math.cos(_theta) * 200);
int dy = (int)Math.round(Math.sin(_theta) * 200);
g.setColor(Color.blue);
g.drawLine(_center.x, _center.y, _center.x + dx, _center.y - dy);
g.drawLine(_center.x, _center.y, _center.x - dx, _center.y + dy);
// locate the point nearest the spot
Point p2 = new Point(_center.x + dx, _center.y - dy);
Point n = new Point();
GeomUtil.nearestToLine(_center, p2, _spot, n);
g.setColor(Color.red);
g.drawOval(n.x - 4, n.y - 4, 8, 8);
// kick theta along for the next tick because it's fun
_theta += (float)(Math.PI/100);
}
public void mouseDragged (MouseEvent event)
{
}
public void mouseMoved (MouseEvent event)
{
_spot.x = event.getX();
_spot.y = event.getY();
repaint();
}
public static void main (String[] args)
{
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new NearestViz(), BorderLayout.CENTER);
frame.setSize(300, 300);
SwingUtil.centerWindow(frame);
frame.setVisible(true);
}
protected float _theta = (float)(3 * Math.PI / 5);
protected Point _center;
protected Point _spot = new Point();
}
@@ -0,0 +1,114 @@
//
// $Id: WhichSideViz.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2010 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.geom;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.samskivert.swing.util.SwingUtil;
/**
* Renders the nearest point on a line just for kicks.
*/
public class WhichSideViz extends JPanel
implements MouseMotionListener
{
public WhichSideViz ()
{
addMouseMotionListener(this);
}
@Override
public void doLayout ()
{
super.doLayout();
_center = new Point(getWidth() / 2, getHeight() / 2);
}
@Override
public void paintComponent (Graphics g)
{
super.paintComponent(g);
int dx = (int)Math.round(Math.cos(_theta) * 200);
int dy = (int)Math.round(Math.sin(_theta) * 200);
g.setColor(Color.blue);
g.drawLine(_center.x, _center.y, _center.x + dx, _center.y + dy);
g.setColor(Color.white);
g.drawLine(_center.x, _center.y, _center.x - dx, _center.y - dy);
int nx = _center.x + (int)Math.round(1000*Math.cos(_theta + Math.PI/2)),
ny = _center.y + (int)Math.round(1000*Math.sin(_theta + Math.PI/2));
g.setColor(Color.pink);
g.drawLine(_center.x, _center.y, nx, ny);
// figure out which side the line is on
String str;
int side = GeomUtil.whichSide(_center, _theta, _spot);
if (side > 0) {
str = "R";
} else if (side < 0) {
str = "L";
} else {
str = "O";
}
g.setColor(Color.black);
g.drawString(str, _spot.x, _spot.y);
// kick theta along for the next tick because it's fun
_theta += (float)(Math.PI/100);
}
public void mouseDragged (MouseEvent event)
{
}
public void mouseMoved (MouseEvent event)
{
_spot.x = event.getX();
_spot.y = event.getY();
repaint();
}
public static void main (String[] args)
{
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new WhichSideViz(), BorderLayout.CENTER);
frame.setSize(300, 300);
SwingUtil.centerWindow(frame);
frame.setVisible(true);
}
protected float _theta = (float)(3 * Math.PI / 5);
protected Point _center;
protected Point _spot = new Point();
}
@@ -0,0 +1,83 @@
//
// $Id: ImageLoadingSpeed.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2010 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.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import com.threerings.resource.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,69 @@
//
// $Id: TestIconManager.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2010 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.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.samskivert.swing.HGroupLayout;
import com.samskivert.swing.util.SwingUtil;
import com.threerings.resource.ResourceManager;
import com.threerings.media.image.ClientImageManager;
import com.threerings.media.tile.TileManager;
/**
* 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");
ClientImageManager imgr = new ClientImageManager(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.setVisible(true);
} catch (Exception e) {
e.printStackTrace(System.err);
}
}
}
@@ -0,0 +1,69 @@
//
// $Id: SoundTestApp.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2010 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 static com.threerings.media.Log.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 JavaSoundPlayer(rmgr, null, null);
_keys = args;
}
public void run ()
{
for (String _key : _keys) {
System.out.println("Playing " + _key + ".");
_soundmgr.play(JavaSoundPlayer.DEFAULT,
"com/threerings/media/sound/", _key);
}
_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 JavaSoundPlayer _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,74 @@
//
// $Id: BundledTileSetRepositoryTest.java 3720 2005-10-05 01:39:45Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2010 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.util.Iterator;
import java.awt.Component;
import junit.framework.Test;
import junit.framework.TestCase;
import com.threerings.resource.ResourceManager;
import com.threerings.media.image.ClientImageManager;
import com.threerings.media.tile.TileSet;
public class BundledTileSetRepositoryTest extends TestCase
{
public BundledTileSetRepositoryTest ()
{
super(BundledTileSetRepositoryTest.class.getName());
}
@Override
public void runTest ()
{
try {
ResourceManager rmgr = new ResourceManager("rsrc");
rmgr.initBundles(
null, "config/resource/manager.properties", null);
BundledTileSetRepository repo = new BundledTileSetRepository(
rmgr, new ClientImageManager(rmgr, (Component)null), "tilesets");
Iterator<TileSet> 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,88 @@
//
// $Id: BuildTestTileSetBundle.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2010 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.util.HashMap;
import java.io.File;
import java.io.IOException;
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<String,Integer>
implements TileSetIDBroker
{
public int getTileSetID (String tileSetName)
throws PersistenceException
{
Integer id = 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,82 @@
//
// $Id: XMLTileSetParserTest.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2010 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.util.HashMap;
import java.util.Iterator;
import java.io.IOException;
import junit.framework.Test;
import junit.framework.TestCase;
import com.threerings.media.tile.TileSet;
public class XMLTileSetParserTest extends TestCase
{
public XMLTileSetParserTest ()
{
super(XMLTileSetParserTest.class.getName());
}
@Override
public void runTest ()
{
HashMap<String, TileSet> sets = new HashMap<String, TileSet>();
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<TileSet> 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,109 @@
//
// $Id: PathViz.java 4181 2006-06-07 21:54:12Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2010 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);
}
@Override
public void paintBetween (Graphics2D gfx, Rectangle dirtyRect)
{
super.paintBetween(gfx, dirtyRect);
gfx.setColor(Color.gray);
gfx.fill(dirtyRect);
_spritemgr.renderSpritePaths(gfx);
}
@Override
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.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;
}
@Override
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,114 @@
//
// $Id: TraceViz.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2010 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.io.File;
import java.io.IOException;
import java.awt.Color;
import java.awt.Image;
import java.awt.image.BufferedImage;
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.image.ClientImageManager;
import com.threerings.media.image.ImageUtil;
import static com.threerings.media.Log.log;
/**
* 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);
ClientImageManager imgr = new ClientImageManager(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.setVisible(true);
}
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);
}
}
protected JFrame _frame;
}
@@ -0,0 +1,89 @@
//
// $Id: ScrollingFrame.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2010 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.miso.client;
import java.awt.Color;
import java.awt.Component;
import java.awt.GraphicsConfiguration;
import javax.swing.JButton;
import javax.swing.JPanel;
import com.samskivert.swing.VGroupLayout;
import com.threerings.media.ManagedJFrame;
import com.threerings.media.SafeScrollPane;
/**
* The main application window.
*/
public class ScrollingFrame extends ManagedJFrame
{
/**
* Creates a frame in which the scrolling test app can operate.
*/
public ScrollingFrame (GraphicsConfiguration gc)
{
super(gc);
// set up the frame options
setTitle("Scene scrolling test");
// setUndecorated(true);
setIgnoreRepaint(true);
setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);
// set the frame and content panel background to black
setBackground(Color.black);
getContentPane().setBackground(Color.black);
// create some interface elements to go with our scrolling panel
VGroupLayout vgl = new VGroupLayout(VGroupLayout.STRETCH);
vgl.setOffAxisPolicy(VGroupLayout.STRETCH);
getContentPane().setLayout(vgl);
vgl = new VGroupLayout(VGroupLayout.NONE);
vgl.setOffAxisPolicy(VGroupLayout.STRETCH);
JPanel stuff = new JPanel(vgl);
for (int ii = 0; ii < 10; ii++) {
stuff.add(new JButton("Button " + ii));
}
getContentPane().add(new SafeScrollPane(stuff));
}
/**
* Sets the panel displayed by this frame.
*/
public void setPanel (Component panel)
{
// if we had an old panel, remove it
if (_panel != null) {
getContentPane().remove(_panel);
}
// now add the new one
_panel = panel;
getContentPane().add(_panel, 0);
}
protected Component _panel;
}
@@ -0,0 +1,130 @@
//
// $Id: ScrollingScene.java 3355 2005-02-17 01:54:54Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2010 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.miso.client;
import java.util.Iterator;
import java.util.Random;
import java.awt.Rectangle;
import com.samskivert.io.PersistenceException;
import com.threerings.media.tile.NoSuchTileSetException;
import com.threerings.media.tile.TileSet;
import com.threerings.media.tile.TileSetRepository;
import com.threerings.miso.data.MisoSceneModel;
import com.threerings.miso.data.ObjectInfo;
import com.threerings.miso.tile.BaseTile;
import com.threerings.miso.tile.BaseTileSet;
import com.threerings.miso.util.MisoContext;
import com.threerings.miso.util.ObjectSet;
/**
* Provides an infinite array of tiles in which to scroll.
*/
public class ScrollingScene extends MisoSceneModel
{
public ScrollingScene (MisoContext ctx)
throws NoSuchTileSetException, PersistenceException
{
// locate the water tileset
TileSetRepository tsrepo = ctx.getTileManager().getTileSetRepository();
Iterator<TileSet> iter = tsrepo.enumerateTileSets();
String tsname = null;
while (iter.hasNext()) {
TileSet tset = iter.next();
// yay for built-in regex support!
if (tset.getName().matches(".*[Ww]ater.*") &&
tset instanceof BaseTileSet) {
tsname = tset.getName();
break;
}
}
if (tsname == null) {
throw new RuntimeException("Unable to locate water tileset.");
}
// now we look the tileset up by name so that it is properly
// initialized and all that business
TileSet wtset = ctx.getTileManager().getTileSet(tsname);
// grab our four repeating tiles
_tiles = new BaseTile[wtset.getTileCount()];
for (int ii = 0; ii < wtset.getTileCount(); ii++) {
_tiles[ii] = (BaseTile)wtset.getTile(ii);
}
}
@Override
public int getBaseTileId (int x, int y)
{
return -1;
}
@Override
public boolean setBaseTile (int fqTileId, int x, int y)
{
return false;
}
@Override
public boolean addObject (ObjectInfo info)
{
return true;
}
@Override
public void getObjects (Rectangle region, ObjectSet set)
{
}
@Override
public void updateObject (ObjectInfo info)
{
}
@Override
public boolean removeObject (ObjectInfo info)
{
return false;
}
// documentation inherited from interface
public BaseTile getBaseTile (int x, int y)
{
long seed = ((x^y) ^ multiplier) & mask;
long hash = (seed * multiplier + addend) & mask;
int tidx = (int)((hash >> 10) % _tiles.length);
return _tiles[tidx];
}
protected BaseTile[] _tiles;
protected Random _rand = new Random();
protected final static long multiplier = 0x5DEECE66DL;
protected final static long addend = 0xBL;
protected final static long mask = (1L << 48) - 1;
protected static final int WATER_TILESET_ID = 8;
}
@@ -0,0 +1,225 @@
//
// $Id: ScrollingTestApp.java 4181 2006-06-07 21:54:12Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2010 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.miso.client;
import java.io.IOException;
import java.awt.DisplayMode;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import com.samskivert.util.Config;
import com.samskivert.swing.util.SwingUtil;
import com.threerings.resource.ResourceManager;
import com.threerings.media.FrameManager;
import com.threerings.media.image.ClientImageManager;
import com.threerings.media.sprite.PathAdapter;
import com.threerings.media.sprite.Sprite;
import com.threerings.media.tile.bundle.BundledTileSetRepository;
import com.threerings.media.util.LinePath;
import com.threerings.media.util.Path;
import com.threerings.miso.MisoConfig;
import com.threerings.miso.tile.MisoTileManager;
import com.threerings.miso.util.MisoContext;
import com.threerings.cast.CharacterComponent;
import com.threerings.cast.CharacterDescriptor;
import com.threerings.cast.CharacterManager;
import com.threerings.cast.CharacterSprite;
import com.threerings.cast.NoSuchComponentException;
import com.threerings.cast.bundle.BundledComponentRepository;
import static com.threerings.miso.Log.log;
/**
* Tests the scrolling capabilities of the IsoSceneView.
*/
public class ScrollingTestApp
{
/**
* Construct and initialize the scrolling test app.
*/
public ScrollingTestApp (String[] args)
throws IOException
{
// get the graphics environment
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
// get the target graphics device
GraphicsDevice gd = env.getDefaultScreenDevice();
log.info("Graphics device", "dev", gd, "mem", gd.getAvailableAcceleratedMemory(),
"displayChange", gd.isDisplayChangeSupported(), "fullScreen", gd.isFullScreenSupported());
// get the graphics configuration and display mode information
GraphicsConfiguration gc = gd.getDefaultConfiguration();
DisplayMode dm = gd.getDisplayMode();
log.info("Display mode", "bits", dm.getBitDepth(), "wid", dm.getWidth(),
"hei", dm.getHeight(), "refresh", dm.getRefreshRate());
// create the window
_frame = new ScrollingFrame(gc);
// set up our frame manager
_framemgr = FrameManager.newInstance(_frame);
// we don't need to configure anything
ResourceManager rmgr = new ResourceManager("rsrc");
rmgr.initBundles(null, "config/resource/manager.properties", null);
ClientImageManager imgr = new ClientImageManager(rmgr, _frame);
_tilemgr = new MisoTileManager(rmgr, imgr);
_tilemgr.setTileSetRepository(new BundledTileSetRepository(rmgr, imgr, "tilesets"));
// hack in some different MisoProperties
MisoConfig.config = new Config("rsrc/config/miso/scrolling");
// create the context object
MisoContext ctx = new ContextImpl();
// create the various managers
BundledComponentRepository crepo = new BundledComponentRepository(rmgr, imgr, "components");
CharacterManager charmgr = new CharacterManager(imgr, crepo);
// create our scene view panel
_panel = new MisoScenePanel(ctx, MisoConfig.getSceneMetrics());
_frame.setPanel(_panel);
// create our "ship" sprite
String scclass = "navsail", scname = "smsloop";
try {
CharacterComponent ccomp = crepo.getComponent(scclass, scname);
CharacterDescriptor desc = new CharacterDescriptor(
new int[] { ccomp.componentId }, null);
// now create the actual sprite and stick 'em in the scene
_ship = charmgr.getCharacter(desc);
if (_ship != null) {
_ship.setFollowingPathAction("sailing");
_ship.setRestingAction("sailing");
_ship.setActionSequence("sailing");
_ship.setLocation(0, 0);
_panel.addSprite(_ship);
}
} catch (NoSuchComponentException nsce) {
log.warning("Can't locate ship component", "class", scclass, "name", scname);
}
_ship.addSpriteObserver(new PathAdapter() {
@Override
public void pathCompleted (Sprite sprite, Path path, long when) {
// keep scrolling for a spell
if (++_sidx < DX.length) {
int x = _ship.getX(), y = _ship.getY();
LinePath lpath = new LinePath(
x, y, x + DX[_sidx], y + DY[_sidx], 30000l);
_ship.move(lpath);
}
}
protected int _sidx = -1;
protected final int[] DX = { 1620, 0, 1000, -1000, 1000, 2000 };
protected final int[] DY = { 1400, 1000, 0, 1000, -1000, 1000 };
});
// make the panel follow the ship around
_panel.setFollowsPathable(_ship, MisoScenePanel.CENTER_ON_PATHABLE);
int x = _ship.getX(), y = _ship.getY();
_ship.move(new LinePath(x, y, x, y + 1000, 3000l));
// size and position the window, entering full-screen exclusive mode if available
if (gd.isFullScreenSupported()) {
log.info("Entering full-screen exclusive mode.");
gd.setFullScreenWindow(_frame);
_frame.setUndecorated(true);
} else {
log.warning("Full-screen exclusive mode not available.");
// _frame.pack();
_frame.setSize(200, 300);
SwingUtil.centerWindow(_frame);
}
try {
_panel.setSceneModel(new ScrollingScene(ctx));
} catch (Exception e) {
log.warning("Error creating scene.", e);
}
}
/**
* The implementation of the MisoContext interface that provides handles to the manager
* objects that offer commonly used services.
*/
protected class ContextImpl implements MisoContext
{
public MisoTileManager getTileManager () {
return _tilemgr;
}
public FrameManager getFrameManager () {
return _framemgr;
}
}
/**
* Run the application.
*/
public void run ()
{
// show the window
_frame.setVisible(true);
_framemgr.start();
}
/**
* Instantiate the application object and start it running.
*/
public static void main (String[] args)
{
try {
ScrollingTestApp app = new ScrollingTestApp(args);
app.run();
} catch (IOException ioe) {
System.err.println("Error initializing scrolling app.");
ioe.printStackTrace();
}
}
/** The tile manager object. */
protected MisoTileManager _tilemgr;
/** The frame manager. */
protected FrameManager _framemgr;
/** The main application window. */
protected ScrollingFrame _frame;
/** The main panel. */
protected MisoScenePanel _panel;
/** The ship in the center of our screen. */
protected CharacterSprite _ship;
}
@@ -0,0 +1,184 @@
//
// $Id: ViewerApp.java 4181 2006-06-07 21:54:12Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2010 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.miso.viewer;
import java.io.IOException;
import java.awt.DisplayMode;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import com.samskivert.swing.util.SwingUtil;
import com.threerings.resource.ResourceManager;
import com.threerings.media.FrameManager;
import com.threerings.media.image.ClientImageManager;
import com.threerings.media.tile.bundle.BundledTileSetRepository;
import com.threerings.miso.data.SimpleMisoSceneModel;
import com.threerings.miso.tile.MisoTileManager;
import com.threerings.miso.tools.xml.SimpleMisoSceneParser;
import com.threerings.miso.util.MisoContext;
import com.threerings.cast.CharacterManager;
import com.threerings.cast.bundle.BundledComponentRepository;
import static com.threerings.miso.Log.log;
/**
* The ViewerApp is a scene viewing application that allows for trying out game scenes in a
* pseudo-runtime environment.
*/
public class ViewerApp
{
/**
* Construct and initialize the ViewerApp object.
*/
public ViewerApp (String[] args)
throws IOException
{
if (args.length < 1) {
System.err.println("Usage: ViewerApp scene_file.xml");
System.exit(-1);
}
// get the graphics environment
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
// get the target graphics device
GraphicsDevice gd = env.getDefaultScreenDevice();
log.info("Graphics device", "dev", gd, "mem", gd.getAvailableAcceleratedMemory(),
"displayChange", gd.isDisplayChangeSupported(),
"fullScreen", gd.isFullScreenSupported());
// get the graphics configuration and display mode information
GraphicsConfiguration gc = gd.getDefaultConfiguration();
DisplayMode dm = gd.getDisplayMode();
log.info("Display mode", "bits", dm.getBitDepth(), "wid", dm.getWidth(),
"hei", dm.getHeight(), "refresh", dm.getRefreshRate());
// create the window
_frame = new ViewerFrame(gc);
_framemgr = FrameManager.newInstance(_frame);
// we don't need to configure anything
ResourceManager rmgr = new ResourceManager("rsrc");
rmgr.initBundles(null, "config/resource/manager.properties", null);
ClientImageManager imgr = new ClientImageManager(rmgr, _frame);
_tilemgr = new MisoTileManager(rmgr, imgr);
_tilemgr.setTileSetRepository(new BundledTileSetRepository(rmgr, imgr, "tilesets"));
// create the context object
MisoContext ctx = new ContextImpl();
// create the various managers
BundledComponentRepository crepo =
new BundledComponentRepository(rmgr, imgr, "components");
CharacterManager charmgr = new CharacterManager(imgr, crepo);
// create our scene view panel
_panel = new ViewerSceneViewPanel(ctx, charmgr, crepo);
_frame.setPanel(_panel);
// load up the scene specified by the user
try {
SimpleMisoSceneParser parser = new SimpleMisoSceneParser("");
SimpleMisoSceneModel model = parser.parseScene(args[0]);
if (model == null) {
log.warning("No miso scene found in scene file", "path", args[0]);
System.exit(-1);
}
_panel.setSceneModel(model);
} catch (Exception e) {
log.warning("Unable to parse scene", "path", args[0], e);
System.exit(-1);
}
// size and position the window, entering full-screen exclusive
// mode if available
if (gd.isFullScreenSupported()) {
log.info("Entering full-screen exclusive mode.");
gd.setFullScreenWindow(_frame);
} else {
log.warning("Full-screen exclusive mode not available.");
// _frame.pack();
_frame.setSize(600, 400);
SwingUtil.centerWindow(_frame);
}
}
/**
* The implementation of the MisoContext interface that provides
* handles to the config and manager objects that offer commonly used
* services.
*/
protected class ContextImpl implements MisoContext
{
public MisoTileManager getTileManager () {
return _tilemgr;
}
public FrameManager getFrameManager () {
return _framemgr;
}
}
/**
* Run the application.
*/
public void run ()
{
// show the window
_frame.setVisible(true);
_framemgr.start();
}
/**
* Instantiate the application object and start it running.
*/
public static void main (String[] args)
{
try {
ViewerApp app = new ViewerApp(args);
app.run();
} catch (IOException ioe) {
System.err.println("Error initializing viewer app.");
ioe.printStackTrace();
}
}
/** The tile manager object. */
protected MisoTileManager _tilemgr;
/** The frame manager. */
protected FrameManager _framemgr;
/** The main application window. */
protected ViewerFrame _frame;
/** The main panel. */
protected ViewerSceneViewPanel _panel;
}
@@ -0,0 +1,94 @@
//
// $Id: ViewerFrame.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2010 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.miso.viewer;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.GraphicsConfiguration;
import java.awt.event.ActionEvent;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import com.samskivert.swing.util.MenuUtil;
import com.threerings.media.ManagedJFrame;
/**
* The viewer frame is the main application window.
*/
public class ViewerFrame extends ManagedJFrame
{
/**
* Creates a frame in which the viewer application can operate.
*/
public ViewerFrame (GraphicsConfiguration gc)
{
super(gc);
// set up the frame options
setTitle("Scene Viewer");
setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);
// set the frame and content panel background to black
setBackground(Color.black);
getContentPane().setBackground(Color.black);
// create the "Settings" menu
JMenu menuSettings = new JMenu("Settings");
MenuUtil.addMenuItem(menuSettings, "Preferences", this, "handlePreferences");
// create the menu bar
JMenuBar bar = new JMenuBar();
bar.add(menuSettings);
// add the menu bar to the frame
setJMenuBar(bar);
}
/**
* Sets the panel displayed by this frame.
*/
public void setPanel (Component panel)
{
// if we had an old panel, remove it
if (_panel != null) {
getContentPane().remove(_panel);
}
// now add the new one
_panel = panel;
getContentPane().add(_panel, BorderLayout.CENTER);
}
/**
* Dummy callback method.
*/
public void handlePreferences (ActionEvent event)
{
System.err.println("Nothing doing!");
}
protected Component _panel;
}
@@ -0,0 +1,237 @@
//
// $Id: ViewerSceneViewPanel.java 4188 2006-06-13 18:03:48Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2010 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.miso.viewer;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import com.samskivert.util.RandomUtil;
import com.threerings.media.sprite.PathObserver;
import com.threerings.media.sprite.Sprite;
import com.threerings.media.sprite.SpriteManager;
import com.threerings.media.util.LineSegmentPath;
import com.threerings.media.util.Path;
import com.threerings.media.util.PerformanceMonitor;
import com.threerings.media.util.PerformanceObserver;
import com.threerings.miso.MisoConfig;
import com.threerings.miso.client.MisoScenePanel;
import com.threerings.miso.data.MisoSceneModel;
import com.threerings.miso.util.MisoContext;
import com.threerings.cast.CharacterDescriptor;
import com.threerings.cast.CharacterManager;
import com.threerings.cast.CharacterSprite;
import com.threerings.cast.ComponentRepository;
import com.threerings.cast.util.CastUtil;
import static com.threerings.miso.Log.log;
public class ViewerSceneViewPanel extends MisoScenePanel
implements PerformanceObserver, PathObserver
{
/**
* Construct the panel and initialize it with a context.
*/
public ViewerSceneViewPanel (MisoContext ctx,
CharacterManager charmgr,
ComponentRepository crepo)
{
super(ctx, MisoConfig.getSceneMetrics());
// create the character descriptors
_descUser = CastUtil.getRandomDescriptor("female", crepo);
_descDecoy = CastUtil.getRandomDescriptor("male", crepo);
// create the manipulable sprite
_sprite = createSprite(_spritemgr, charmgr, _descUser);
setFollowsPathable(_sprite, CENTER_ON_PATHABLE);
// create the decoy sprites
createDecoys(_spritemgr, charmgr);
PerformanceMonitor.register(this, "paint", 1000);
}
@Override
public void setSceneModel (MisoSceneModel model)
{
super.setSceneModel(model);
log.info("Using " + model + ".");
}
@Override
public void doLayout ()
{
super.doLayout();
// now that we have a scene, we can create valid paths for our
// decoy sprites
createDecoyPaths();
}
/**
* Creates a new sprite.
*/
protected CharacterSprite createSprite (
SpriteManager spritemgr, CharacterManager charmgr,
CharacterDescriptor desc)
{
CharacterSprite s = charmgr.getCharacter(desc);
if (s != null) {
// start 'em out standing
s.setActionSequence(CharacterSprite.STANDING);
s.setLocation(300, 300);
s.addSpriteObserver(this);
spritemgr.addSprite(s);
}
return s;
}
/**
* Creates the decoy sprites.
*/
protected void createDecoys (
SpriteManager spritemgr, CharacterManager charmgr)
{
_decoys = new CharacterSprite[NUM_DECOYS];
for (int ii = 0; ii < NUM_DECOYS; ii++) {
_decoys[ii] = createSprite(spritemgr, charmgr, _descDecoy);
}
}
/**
* Creates paths for the decoy sprites.
*/
protected void createDecoyPaths ()
{
for (int ii = 0; ii < NUM_DECOYS; ii++) {
if (_decoys[ii] != null) {
createRandomPath(_decoys[ii]);
}
}
}
@Override
public void paint (Graphics g)
{
super.paint(g);
PerformanceMonitor.tick(this, "paint");
}
// documentation inherited
public void checkpoint (String name, int ticks)
{
log.info(name + " [ticks=" + ticks + "].");
}
@Override
public void mousePressed (MouseEvent e)
{
super.mousePressed(e);
int x = e.getX(), y = e.getY();
log.info("Mouse pressed +" + x + "+" + y);
switch (e.getModifiers()) {
case MouseEvent.BUTTON1_MASK:
createPath(_sprite, x, y);
break;
case MouseEvent.BUTTON2_MASK:
for (int ii = 0; ii < NUM_DECOYS; ii++) {
createPath(_decoys[ii], x, y);
}
break;
}
}
/**
* Assigns the sprite a path leading to the given destination
* screen coordinates. Returns whether a path was successfully
* assigned.
*/
protected boolean createPath (CharacterSprite s, int x, int y)
{
// get the path from here to there
LineSegmentPath path = (LineSegmentPath)getPath(s, x, y, true);
if (path == null) {
s.cancelMove();
return false;
}
// start the sprite moving along the path
path.setVelocity(100f/1000f);
s.move(path);
return true;
}
/**
* Assigns a new random path to the given sprite.
*/
protected void createRandomPath (CharacterSprite s)
{
Dimension d = _vbounds.getSize();
if (d.width <= 0 || d.height <= 0) {
return;
}
int x, y;
do {
x = RandomUtil.getInt(d.width);
y = RandomUtil.getInt(d.height);
} while (!createPath(s, x, y));
}
// documentation inherited
public void pathCompleted (Sprite sprite, Path path, long when)
{
CharacterSprite s = (CharacterSprite)sprite;
if (s != _sprite) {
// move the sprite to a new random location
createRandomPath(s);
}
}
// documentation inherited
public void pathCancelled (Sprite sprite, Path path)
{
// nothing doing
}
/** The number of decoy characters milling about. */
protected static final int NUM_DECOYS = 5;
/** The character descriptor for the user character. */
protected CharacterDescriptor _descUser;
/** The character descriptor for the decoy characters. */
protected CharacterDescriptor _descDecoy;
/** The sprite we're manipulating within the view. */
protected CharacterSprite _sprite;
/** The test sprites that meander about aimlessly. */
protected CharacterSprite _decoys[];
}
@@ -0,0 +1,75 @@
//
// $Id$
package com.threerings.openal;
import java.io.File;
import java.io.IOException;
import com.samskivert.util.Interval;
import com.samskivert.util.Queue;
import com.samskivert.util.RunQueue;
/**
* Tests the OpenAL sound system.
*/
public class TestSoundManager
{
public static void main (String[] args)
{
if (args.length == 0) {
System.err.println("Usage: TestSoundManager sound.[wav|mp3|ogg]");
System.exit(-1);
}
final Thread current = Thread.currentThread();
RunQueue rqueue = new RunQueue() {
public void postRunnable (Runnable r) {
_queue.append(r);
}
public boolean isDispatchThread () {
return (current == Thread.currentThread());
}
public boolean isRunning() {
return true;
}
};
final SoundManager smgr = SoundManager.createSoundManager(rqueue);
ClipProvider provider = new WaveDataClipProvider();
final SoundGroup group = smgr.createGroup(provider, 5);
final String path = args[0];
String lpath = path.toLowerCase();
if (lpath.endsWith("mp3") || lpath.endsWith(".ogg")) {
// play the mp3/ogg file in a loop
try {
new FileStream(smgr, new File(args[0]), true).play();
} catch (IOException e) {
e.printStackTrace();
}
Interval i = new Interval(rqueue) {
@Override public void expired () {
smgr.updateStreams(0.1f);
}
};
i.schedule(100L, true);
} else {
// queue up an interval to play a sound over and over
Interval i = new Interval(rqueue) {
@Override public void expired () {
Sound sound = group.getSound(path);
sound.play(true);
}
};
i.schedule(100L, true);
}
while (true) {
Runnable r = _queue.get();
r.run();
}
}
protected static Queue<Runnable> _queue = new Queue<Runnable>();
}
@@ -0,0 +1,74 @@
//
// $Id: DirectionTest.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2010 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.util;
import junit.framework.Test;
import junit.framework.TestCase;
/**
* Tests the {@link DirectionUtil} class.
*/
public class DirectionTest extends TestCase
implements DirectionCodes
{
public DirectionTest ()
{
super(DirectionTest.class.getName());
}
@Override
public void runTest ()
{
int orient = NORTH;
for (int i = 0; i < FINE_DIRECTION_COUNT; i++) {
// System.out.print(DirectionUtil.toShortString(orient) + " -> ");
orient = DirectionUtil.rotateCW(orient, 1);
}
// System.out.println(DirectionUtil.toShortString(orient));
assertTrue("CW rotate", orient == NORTH);
for (int i = 0; i < FINE_DIRECTION_COUNT; i++) {
// System.out.print(DirectionUtil.toShortString(orient) + " -> ");
orient = DirectionUtil.rotateCCW(orient, 1);
}
// System.out.println(DirectionUtil.toShortString(orient));
assertTrue("CCW rotate", orient == NORTH);
// for (double theta = -Math.PI; theta <= Math.PI; theta += Math.PI/1000) {
// orient = DirectionUtil.getFineDirection(theta);
// System.out.println(Math.toDegrees(theta) + " => " +
// DirectionUtil.toShortString(orient));
// }
}
public static Test suite ()
{
return new DirectionTest();
}
public static void main (String[] args)
{
DirectionTest test = new DirectionTest();
test.runTest();
}
}
@@ -0,0 +1,87 @@
//
// $Id: DirectionViz.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2010 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.util;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
* Renders the output of {@link DirectionUtil#getDirection} just for
* kicks.
*/
public class DirectionViz extends JPanel
implements MouseMotionListener
{
public DirectionViz ()
{
addMouseMotionListener(this);
}
@Override
public void doLayout ()
{
super.doLayout();
_center = new Point(getWidth() / 2, getHeight() / 2);
}
@Override
public void paintComponent (Graphics g)
{
super.paintComponent(g);
g.setColor(Color.blue);
g.drawLine(_center.x, _center.y, _spot.x, _spot.y);
int orient = DirectionUtil.getFineDirection(_center, _spot);
g.drawString(DirectionUtil.toShortString(orient), _spot.x, _spot.y);
}
public void mouseDragged (MouseEvent event)
{
}
public void mouseMoved (MouseEvent event)
{
_spot.x = event.getX();
_spot.y = event.getY();
repaint();
}
public static void main (String[] args)
{
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new DirectionViz(), BorderLayout.CENTER);
frame.setSize(300, 300);
frame.setVisible(true);
}
protected Point _center;
protected Point _spot = new Point();
}
@@ -0,0 +1,97 @@
//
// $Id: KeyTimerApp.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2010 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.util;
import java.awt.Frame;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import static com.threerings.NenyaLog.log;
public class KeyTimerApp
{
public KeyTimerApp ()
{
_frame = new TestFrame();
_frame.setSize(400, 300);
}
public void run ()
{
_frame.setVisible(true);
}
public static void main (String[] args)
{
KeyTimerApp app = new KeyTimerApp();
app.run();
}
protected class TestFrame extends Frame implements KeyListener
{
public TestFrame ()
{
addKeyListener(this);
_prStart = _rpStart = -1;
}
public void keyPressed (KeyEvent e)
{
long now = System.currentTimeMillis();
_prStart = now;
if (_rpStart != -1) {
log.info("RP\t" + (now - _rpStart));
}
logKey("keyPressed", e);
}
public void keyReleased (KeyEvent e)
{
long now = System.currentTimeMillis();
_rpStart = now;
log.info("PR\t" + (now - _prStart));
logKey("keyReleased", e);
}
public void keyTyped (KeyEvent e)
{
logKey("keyTyped", e);
}
/**
* Logs the given message and key.
*/
protected void logKey (String msg, KeyEvent e)
{
int keyCode = e.getKeyCode();
log.info(msg + " [key=" + KeyEvent.getKeyText(keyCode) + "].");
}
protected long _prStart, _rpStart;
}
protected Frame _frame;
}
@@ -0,0 +1,108 @@
//
// $Id: KeyboardManagerApp.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2010 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.util;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.samskivert.swing.Controller;
import com.samskivert.swing.ControllerProvider;
import static com.threerings.NenyaLog.log;
public class KeyboardManagerApp
{
public KeyboardManagerApp ()
{
_frame = new TestFrame();
_frame.setSize(400, 300);
}
public void run ()
{
_frame.setVisible(true);
}
public static void main (String[] args)
{
KeyboardManagerApp app = new KeyboardManagerApp();
app.run();
}
protected static class TestFrame extends JFrame
implements ControllerProvider
{
public TestFrame ()
{
// create the test controller
_ctrl = new TestController();
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel top = new JPanel();
// add some sample key mappings
KeyTranslatorImpl xlate = new KeyTranslatorImpl();
xlate.addPressCommand(KeyEvent.VK_LEFT, TestController.MOVE_LEFT);
xlate.addPressCommand(
KeyEvent.VK_RIGHT, TestController.MOVE_RIGHT);
xlate.addPressCommand(KeyEvent.VK_SPACE, TestController.DROP);
// create the keyboard manager
KeyboardManager keymgr = new KeyboardManager();
keymgr.setTarget(top, xlate);
keymgr.setEnabled(true);
getContentPane().add(top);
}
// documentation inherited
public Controller getController ()
{
return _ctrl;
}
/** The test controller. */
protected Controller _ctrl;
}
protected static class TestController extends Controller
{
public static final String MOVE_LEFT = "move_left";
public static final String MOVE_RIGHT = "move_right";
public static final String DROP = "drop";
@Override
public boolean handleAction (ActionEvent action)
{
String cmd = action.getActionCommand();
log.info("handleAction [cmd=" + cmd + "].");
return true;
}
}
/** The test frame. */
protected JFrame _frame;
}
@@ -0,0 +1,30 @@
//
// $Id$
package com.threerings.util;
import com.threerings.util.unsafe.Unsafe;
/**
* Does something extraordinary.
*/
public class UIDTestApp
{
public static void main (String[] args)
{
if (Unsafe.setuid(1000)) {
System.err.println("Yay! My uid is changed.");
} else {
System.err.println("Boo hoo! I couldn't change my uid.");
}
if (Unsafe.setgid(60)) {
System.err.println("Yay! My gid is changed.");
} else {
System.err.println("Boo hoo! I couldn't change my gid.");
}
try {
Thread.sleep(60*1000L);
} catch (Exception e) {
}
}
}