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:
@@ -0,0 +1,153 @@
|
||||
//
|
||||
// $Id: CharSpriteViz.java 3355 2005-02-17 01:54:54Z 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.cast;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Graphics;
|
||||
|
||||
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.media.image.ImageManager;
|
||||
import com.threerings.resource.ResourceManager;
|
||||
import com.threerings.util.DirectionCodes;
|
||||
import com.threerings.util.DirectionUtil;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
ImageManager imgr = new ImageManager(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.show();
|
||||
|
||||
} 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,76 @@
|
||||
//
|
||||
// $Id: TestApp.java 3355 2005-02-17 01:54:54Z 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.cast.builder;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import com.samskivert.swing.util.SwingUtil;
|
||||
|
||||
import com.threerings.media.image.ImageManager;
|
||||
import com.threerings.resource.ResourceManager;
|
||||
|
||||
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);
|
||||
ImageManager imgr = new ImageManager(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.show();
|
||||
}
|
||||
|
||||
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-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.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,85 @@
|
||||
//
|
||||
// $Id: BundledComponentRepositoryTest.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.cast.bundle;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.threerings.cast.ComponentClass;
|
||||
import com.threerings.media.image.ImageManager;
|
||||
import com.threerings.resource.ResourceManager;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class BundledComponentRepositoryTest extends TestCase
|
||||
{
|
||||
public BundledComponentRepositoryTest ()
|
||||
{
|
||||
super(BundledComponentRepositoryTest.class.getName());
|
||||
}
|
||||
|
||||
public void runTest ()
|
||||
{
|
||||
try {
|
||||
ResourceManager rmgr = new ResourceManager("rsrc");
|
||||
rmgr.initBundles(
|
||||
null, "config/resource/manager.properties", null);
|
||||
ImageManager imgr = new ImageManager(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 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,101 @@
|
||||
//
|
||||
// $Id: NearestViz.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.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);
|
||||
}
|
||||
|
||||
public void doLayout ()
|
||||
{
|
||||
super.doLayout();
|
||||
_center = new Point(getWidth() / 2, getHeight() / 2);
|
||||
}
|
||||
|
||||
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.show();
|
||||
}
|
||||
|
||||
protected float _theta = (float)(3 * Math.PI / 5);
|
||||
protected Point _center;
|
||||
protected Point _spot = new Point();
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
//
|
||||
// $Id: WhichSideViz.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.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);
|
||||
}
|
||||
|
||||
public void doLayout ()
|
||||
{
|
||||
super.doLayout();
|
||||
_center = new Point(getWidth() / 2, getHeight() / 2);
|
||||
}
|
||||
|
||||
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.show();
|
||||
}
|
||||
|
||||
protected float _theta = (float)(3 * Math.PI / 5);
|
||||
protected Point _center;
|
||||
protected Point _spot = new Point();
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
//
|
||||
// $Id$
|
||||
|
||||
package com.threerings.jme;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import com.jme.bounding.BoundingBox;
|
||||
import com.jme.math.Vector3f;
|
||||
import com.jme.scene.shape.Box;
|
||||
|
||||
/**
|
||||
* Tests the JME/AWT integration bits.
|
||||
*/
|
||||
public class JmeCanvasTest extends JmeCanvasApp
|
||||
{
|
||||
public static void main (String[] args)
|
||||
{
|
||||
final JmeCanvasTest app = new JmeCanvasTest();
|
||||
JFrame frame = new JFrame("JmeCanvasTest");
|
||||
frame.getContentPane().add(app.getCanvas(), BorderLayout.CENTER);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setSize(800, 600);
|
||||
frame.setVisible(true);
|
||||
|
||||
JButton button = new JButton("Create box");
|
||||
frame.getContentPane().add(button, BorderLayout.SOUTH);
|
||||
button.addActionListener(new ActionListener() {
|
||||
public void actionPerformed (ActionEvent event) {
|
||||
app.addBox();
|
||||
}
|
||||
});
|
||||
app.run();
|
||||
}
|
||||
|
||||
public void addBox ()
|
||||
{
|
||||
Vector3f max = new Vector3f(5, 5, 5);
|
||||
Vector3f min = new Vector3f(-5, -5, -5);
|
||||
|
||||
Box box = new Box("Box", min, max);
|
||||
box.setModelBound(new BoundingBox());
|
||||
box.updateModelBound();
|
||||
box.setLocalTranslation(new Vector3f(0, 0, -10));
|
||||
_geom.attachChild(box);
|
||||
_geom.updateRenderState();
|
||||
}
|
||||
|
||||
protected JmeCanvasTest ()
|
||||
{
|
||||
super(800, 600);
|
||||
}
|
||||
|
||||
protected void initRoot ()
|
||||
{
|
||||
super.initRoot();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
//
|
||||
// $Id: JabberApp.java 3098 2004-08-27 02:12:55Z 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.jme.client;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import com.jme.bounding.BoundingBox;
|
||||
import com.jme.math.FastMath;
|
||||
import com.jme.math.Matrix3f;
|
||||
import com.jme.math.Vector3f;
|
||||
import com.jme.renderer.ColorRGBA;
|
||||
import com.jme.scene.shape.Box;
|
||||
import com.jme.util.LoggingSystem;
|
||||
import com.jme.util.geom.BufferUtils;
|
||||
import com.jmex.bui.BStyleSheet;
|
||||
|
||||
import com.threerings.util.Name;
|
||||
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.net.UsernamePasswordCreds;
|
||||
|
||||
import com.threerings.jme.Log;
|
||||
import com.threerings.jme.JmeApp;
|
||||
|
||||
/**
|
||||
* The main point of entry for the Jabber client application. It creates
|
||||
* and initializes the myriad components of the client and sets all the
|
||||
* proper wheels in motion.
|
||||
*/
|
||||
public class JabberApp extends JmeApp
|
||||
{
|
||||
/** Used to configure our user interface. */
|
||||
public static BStyleSheet stylesheet;
|
||||
|
||||
// documentation inherited
|
||||
public boolean init ()
|
||||
{
|
||||
if (!super.init()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// initialize our client instance
|
||||
_client = new JabberClient();
|
||||
_client.init(this);
|
||||
|
||||
// add some simple geometry for kicks
|
||||
Vector3f max = new Vector3f(15, 15, 15);
|
||||
Vector3f min = new Vector3f(5, 5, 5);
|
||||
|
||||
Box t = new Box("Box", min, max);
|
||||
t.setModelBound(new BoundingBox());
|
||||
t.updateModelBound();
|
||||
t.setLocalTranslation(new Vector3f(0, 0, -15));
|
||||
ColorRGBA[] colors = new ColorRGBA[24];
|
||||
for (int i = 0; i < 24; i++) {
|
||||
colors[i] = ColorRGBA.randomColor();
|
||||
}
|
||||
t.setColorBuffer(0, BufferUtils.createFloatBuffer(colors));
|
||||
_root.attachChild(t);
|
||||
_root.updateRenderState();
|
||||
|
||||
// set up the camera
|
||||
Vector3f loc = new Vector3f(0, -200, 200);
|
||||
_camera.setLocation(loc);
|
||||
Matrix3f rotm = new Matrix3f();
|
||||
rotm.fromAngleAxis(-FastMath.PI/5, _camera.getLeft());
|
||||
rotm.mult(_camera.getDirection(), _camera.getDirection());
|
||||
rotm.mult(_camera.getUp(), _camera.getUp());
|
||||
rotm.mult(_camera.getLeft(), _camera.getLeft());
|
||||
_camera.update();
|
||||
|
||||
// speed up key input
|
||||
_input.setActionSpeed(100f);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void run (String server, String username, String password)
|
||||
{
|
||||
Client client = _client.getContext().getClient();
|
||||
|
||||
// pass them on to the client
|
||||
Log.info("Using [server=" + server + ".");
|
||||
client.setServer(server, Client.DEFAULT_SERVER_PORTS);
|
||||
|
||||
// configure the client with some credentials and logon
|
||||
if (username != null && password != null) {
|
||||
// create and set our credentials
|
||||
client.setCredentials(
|
||||
new UsernamePasswordCreds(new Name(username), password));
|
||||
client.logon();
|
||||
}
|
||||
|
||||
// now start up the main event loop
|
||||
run();
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void stop ()
|
||||
{
|
||||
// log off before we shutdown
|
||||
Client client = _client.getContext().getClient();
|
||||
if (client.isLoggedOn()) {
|
||||
client.logoff(false);
|
||||
}
|
||||
Log.info("Stopping.");
|
||||
super.stop();
|
||||
}
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
LoggingSystem.getLogger().setLevel(java.util.logging.Level.OFF);
|
||||
|
||||
String server = "localhost";
|
||||
if (args.length > 0) {
|
||||
server = args[0];
|
||||
}
|
||||
|
||||
// load up the default BUI stylesheet
|
||||
try {
|
||||
InputStream stin = JabberApp.class.getClassLoader().
|
||||
getResourceAsStream("rsrc/style.bss");
|
||||
stylesheet = new BStyleSheet(
|
||||
new InputStreamReader(stin),
|
||||
new BStyleSheet.DefaultResourceProvider());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
String username = (args.length > 1) ? args[1] : null;
|
||||
String password = (args.length > 2) ? args[2] : null;
|
||||
|
||||
JabberApp app = new JabberApp();
|
||||
app.init();
|
||||
app.run(server, username, password);
|
||||
}
|
||||
|
||||
protected JabberClient _client;
|
||||
}
|
||||
@@ -0,0 +1,228 @@
|
||||
//
|
||||
// $Id: JabberClient.java 3283 2004-12-22 19:23:00Z ray $
|
||||
//
|
||||
// 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.jme.client;
|
||||
|
||||
import com.jmex.bui.BRootNode;
|
||||
import com.jme.input.InputHandler;
|
||||
import com.jme.renderer.Renderer;
|
||||
import com.jme.scene.Node;
|
||||
import com.jme.system.DisplaySystem;
|
||||
|
||||
import com.samskivert.util.Config;
|
||||
import com.threerings.util.MessageManager;
|
||||
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.client.SessionObserver;
|
||||
import com.threerings.presents.dobj.DObjectManager;
|
||||
|
||||
import com.threerings.crowd.chat.client.ChatDirector;
|
||||
import com.threerings.crowd.client.LocationDirector;
|
||||
import com.threerings.crowd.client.OccupantDirector;
|
||||
import com.threerings.crowd.client.PlaceView;
|
||||
import com.threerings.crowd.util.CrowdContext;
|
||||
|
||||
import com.threerings.jme.JmeContext;
|
||||
import com.threerings.jme.camera.CameraHandler;
|
||||
|
||||
/**
|
||||
* The Jabber client takes care of instantiating all of the proper
|
||||
* managers and loading up all of the necessary configuration and getting
|
||||
* the client bootstrapped. It can be extended by games that require an
|
||||
* extended context implementation.
|
||||
*/
|
||||
public class JabberClient
|
||||
implements SessionObserver
|
||||
{
|
||||
/**
|
||||
* Initializes a new client and provides it with a frame in which to
|
||||
* display everything.
|
||||
*/
|
||||
public void init (JabberApp app)
|
||||
{
|
||||
_app = app;
|
||||
|
||||
// create our context
|
||||
_ctx = createContextImpl();
|
||||
|
||||
// create the directors/managers/etc. provided by the context
|
||||
createContextServices(app);
|
||||
|
||||
// for test purposes, hardcode the server info
|
||||
_client.setServer("localhost", Client.DEFAULT_SERVER_PORTS);
|
||||
_client.addClientObserver(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a reference to the context in effect for this client. This
|
||||
* reference is valid for the lifetime of the application.
|
||||
*/
|
||||
public CrowdContext getContext ()
|
||||
{
|
||||
return _ctx;
|
||||
}
|
||||
|
||||
// documentation inherited from interface SessionObserver
|
||||
public void clientDidLogon (Client client)
|
||||
{
|
||||
// enter the one and only chat room; giant hack warning: we know
|
||||
// that the place we're headed to is ID 2 because there's only one
|
||||
// place on the whole server; a normal client would either issue
|
||||
// an invocation service request at this point or look at
|
||||
// something in the BootstrapData to figure out what to do
|
||||
_ctx.getLocationDirector().moveTo(2);
|
||||
}
|
||||
|
||||
// documentation inherited from interface SessionObserver
|
||||
public void clientObjectDidChange (Client client)
|
||||
{
|
||||
// nada
|
||||
}
|
||||
|
||||
// documentation inherited from interface SessionObserver
|
||||
public void clientDidLogoff (Client client)
|
||||
{
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the {@link JabberContext} implementation that will be
|
||||
* passed around to all of the client code. Derived classes may wish
|
||||
* to override this and create some extended context implementation.
|
||||
*/
|
||||
protected CrowdContext createContextImpl ()
|
||||
{
|
||||
return new JabberContextImpl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and initializes the various services that are provided by
|
||||
* the context. Derived classes that provide an extended context
|
||||
* should override this method and create their own extended
|
||||
* services. They should be sure to call
|
||||
* <code>super.createContextServices</code>.
|
||||
*/
|
||||
protected void createContextServices (JabberApp app)
|
||||
{
|
||||
// create the handles on our various services
|
||||
_client = new Client(null, app);
|
||||
|
||||
// create our managers and directors
|
||||
_locdir = new LocationDirector(_ctx);
|
||||
_occdir = new OccupantDirector(_ctx);
|
||||
_msgmgr = new MessageManager(MESSAGE_MANAGER_PREFIX);
|
||||
_chatdir = new ChatDirector(_ctx, _msgmgr, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* The context implementation. This provides access to all of the
|
||||
* objects and services that are needed by the operating client.
|
||||
*/
|
||||
protected class JabberContextImpl implements CrowdContext, JmeContext
|
||||
{
|
||||
/**
|
||||
* Apparently the default constructor has default access, rather
|
||||
* than protected access, even though this class is declared to be
|
||||
* protected. Why, I don't know, but we need to be able to extend
|
||||
* this class elsewhere, so we need this.
|
||||
*/
|
||||
protected JabberContextImpl () {
|
||||
}
|
||||
|
||||
public Client getClient () {
|
||||
return _client;
|
||||
}
|
||||
|
||||
public DObjectManager getDObjectManager () {
|
||||
return _client.getDObjectManager();
|
||||
}
|
||||
|
||||
public Config getConfig () {
|
||||
return _config;
|
||||
}
|
||||
|
||||
public LocationDirector getLocationDirector () {
|
||||
return _locdir;
|
||||
}
|
||||
|
||||
public OccupantDirector getOccupantDirector () {
|
||||
return _occdir;
|
||||
}
|
||||
|
||||
public ChatDirector getChatDirector () {
|
||||
return _chatdir;
|
||||
}
|
||||
|
||||
public void setPlaceView (PlaceView view) {
|
||||
// TBD
|
||||
}
|
||||
|
||||
public void clearPlaceView (PlaceView view) {
|
||||
// we'll just let the next place view replace our old one
|
||||
}
|
||||
|
||||
public Renderer getRenderer () {
|
||||
return _app.getContext().getRenderer();
|
||||
}
|
||||
|
||||
public DisplaySystem getDisplay () {
|
||||
return _app.getContext().getDisplay();
|
||||
}
|
||||
|
||||
public CameraHandler getCameraHandler () {
|
||||
return _app.getContext().getCameraHandler();
|
||||
}
|
||||
|
||||
public Node getGeometry () {
|
||||
return _app.getContext().getGeometry();
|
||||
}
|
||||
|
||||
public Node getInterface () {
|
||||
return _app.getContext().getInterface();
|
||||
}
|
||||
|
||||
public InputHandler getInputHandler () {
|
||||
return _app.getContext().getInputHandler();
|
||||
}
|
||||
|
||||
// public InputHandler getBufferedInputHandler () {
|
||||
// return _app.getContext().getBufferedInputHandler();
|
||||
// }
|
||||
|
||||
public BRootNode getRootNode () {
|
||||
return _app.getContext().getRootNode();
|
||||
}
|
||||
}
|
||||
|
||||
protected CrowdContext _ctx;
|
||||
protected JabberApp _app;
|
||||
protected Config _config = new Config("jabber");
|
||||
|
||||
protected Client _client;
|
||||
protected LocationDirector _locdir;
|
||||
protected OccupantDirector _occdir;
|
||||
protected ChatDirector _chatdir;
|
||||
protected MessageManager _msgmgr;
|
||||
|
||||
/** The prefix prepended to localization bundle names before looking
|
||||
* them up in the classpath. */
|
||||
protected static final String MESSAGE_MANAGER_PREFIX = "rsrc.i18n";
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// $Id$
|
||||
|
||||
package com.threerings.jme.client;
|
||||
|
||||
import com.threerings.crowd.client.PlaceController;
|
||||
import com.threerings.crowd.client.PlaceView;
|
||||
import com.threerings.crowd.util.CrowdContext;
|
||||
|
||||
/**
|
||||
* Handles the basic bits for our simple chat room.
|
||||
*/
|
||||
public class JabberController extends PlaceController
|
||||
{
|
||||
protected PlaceView createPlaceView (CrowdContext ctx)
|
||||
{
|
||||
return new JabberView(ctx);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// $Id$
|
||||
|
||||
package com.threerings.jme.client;
|
||||
|
||||
import com.jmex.bui.BLabel;
|
||||
import com.jmex.bui.BWindow;
|
||||
import com.jmex.bui.layout.BorderLayout;
|
||||
|
||||
import com.threerings.crowd.client.PlaceView;
|
||||
import com.threerings.crowd.data.PlaceObject;
|
||||
import com.threerings.crowd.util.CrowdContext;
|
||||
|
||||
import com.threerings.jme.JmeContext;
|
||||
import com.threerings.jme.chat.ChatView;
|
||||
|
||||
/**
|
||||
* Manages the "view" when we're in the chat room.
|
||||
*/
|
||||
public class JabberView extends BWindow
|
||||
implements PlaceView
|
||||
{
|
||||
public JabberView (CrowdContext ctx)
|
||||
{
|
||||
super(JabberApp.stylesheet, new BorderLayout());
|
||||
|
||||
_ctx = ctx;
|
||||
_jctx = (JmeContext)ctx;
|
||||
_chat = new ChatView(_jctx, _ctx.getChatDirector());
|
||||
add(_chat, BorderLayout.CENTER);
|
||||
|
||||
_jctx.getRootNode().addWindow(this);
|
||||
setBounds(0, 40, 640, 240);
|
||||
}
|
||||
|
||||
// documentation inherited from interface PlaceView
|
||||
public void willEnterPlace (PlaceObject plobj)
|
||||
{
|
||||
_chat.willEnterPlace(plobj);
|
||||
}
|
||||
|
||||
// documentation inherited from interface PlaceView
|
||||
public void didLeavePlace (PlaceObject plobj)
|
||||
{
|
||||
_chat.didLeavePlace(plobj);
|
||||
}
|
||||
|
||||
protected CrowdContext _ctx;
|
||||
protected JmeContext _jctx;
|
||||
protected ChatView _chat;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// $Id$
|
||||
|
||||
package com.threerings.jme.data;
|
||||
|
||||
import com.threerings.crowd.data.PlaceConfig;
|
||||
import com.threerings.jme.client.JabberController;
|
||||
|
||||
/**
|
||||
* Defines the necessary bits for our chat room.
|
||||
*/
|
||||
public class JabberConfig extends PlaceConfig
|
||||
{
|
||||
// documentation inherited
|
||||
public Class getControllerClass ()
|
||||
{
|
||||
return JabberController.class;
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public String getManagerClassName ()
|
||||
{
|
||||
// nothing special needed on the server side
|
||||
return "com.threerings.crowd.server.PlaceManager";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
//
|
||||
// $Id$
|
||||
|
||||
package com.threerings.jme.server;
|
||||
|
||||
import com.threerings.crowd.Log;
|
||||
import com.threerings.crowd.data.PlaceObject;
|
||||
import com.threerings.crowd.server.CrowdServer;
|
||||
import com.threerings.crowd.server.PlaceManager;
|
||||
import com.threerings.crowd.server.PlaceRegistry;
|
||||
|
||||
import com.threerings.jme.data.JabberConfig;
|
||||
|
||||
/**
|
||||
* A basic server that creates a single room and sticks everyone in it
|
||||
* where they can chat with one another.
|
||||
*/
|
||||
public class JabberServer extends CrowdServer
|
||||
{
|
||||
// documentation inherited
|
||||
public void init ()
|
||||
throws Exception
|
||||
{
|
||||
super.init();
|
||||
|
||||
// create a single location
|
||||
plreg.createPlace(
|
||||
new JabberConfig(), new PlaceRegistry.CreationObserver() {
|
||||
public void placeCreated (PlaceObject place, PlaceManager pmgr) {
|
||||
Log.info("Created chat room " + pmgr.where() + ".");
|
||||
_place = pmgr;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
JabberServer server = new JabberServer();
|
||||
try {
|
||||
server.init();
|
||||
server.run();
|
||||
} catch (Exception e) {
|
||||
Log.warning("Unable to initialize server.");
|
||||
Log.logStackTrace(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected PlaceManager _place;
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
//
|
||||
// $Id$
|
||||
|
||||
package com.threerings.jme.sprite;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.jme.math.FastMath;
|
||||
import com.jme.math.Matrix3f;
|
||||
import com.jme.math.Quaternion;
|
||||
import com.jme.math.Vector3f;
|
||||
import com.jme.renderer.ColorRGBA;
|
||||
import com.jme.scene.shape.Box;
|
||||
import com.jme.scene.shape.Disk;
|
||||
import com.jme.scene.shape.Quad;
|
||||
import com.jme.scene.shape.Sphere;
|
||||
import com.jme.scene.state.LightState;
|
||||
import com.jme.util.LoggingSystem;
|
||||
|
||||
import com.threerings.jme.JmeApp;
|
||||
import com.threerings.jme.sprite.LineSegmentPath;
|
||||
|
||||
/**
|
||||
* Used for testing paths.
|
||||
*/
|
||||
public class PathTest extends JmeApp
|
||||
{
|
||||
protected void initRoot ()
|
||||
{
|
||||
super.initRoot();
|
||||
|
||||
float dist = 10;
|
||||
|
||||
// set up the camera
|
||||
Vector3f loc = new Vector3f(0, -dist, 10);
|
||||
_camera.setLocation(loc);
|
||||
Matrix3f rotm = new Matrix3f();
|
||||
rotm.fromAngleAxis(-FastMath.PI/4, _camera.getLeft());
|
||||
rotm.multLocal(_camera.getDirection());
|
||||
rotm.multLocal(_camera.getUp());
|
||||
rotm.multLocal(_camera.getLeft());
|
||||
_camera.update();
|
||||
|
||||
for (int yy = -1; yy < 1; yy++) {
|
||||
for (int xx = -1; xx < 1; xx++) {
|
||||
Quad quad = new Quad("ground", 10, 10);
|
||||
quad.setLightCombineMode(LightState.OFF);
|
||||
int index = (yy+1)*2 + (xx+1);
|
||||
quad.setSolidColor(COLORS[index]);
|
||||
quad.setLocalTranslation(
|
||||
new Vector3f(xx * 10 + 5, yy * 10 + 5, -1));
|
||||
_geom.attachChild(quad);
|
||||
}
|
||||
}
|
||||
|
||||
for (int yy = -1; yy <= 1; yy++) {
|
||||
for (int xx = -1; xx <= 1; xx++) {
|
||||
if (xx != 0 || yy != 0) {
|
||||
setup(xx * dist, yy * dist);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void setup (float x, float y)
|
||||
{
|
||||
Box target = new Box("target", new Vector3f(-.1f, -.1f, -.1f),
|
||||
new Vector3f(.1f, .1f, .1f));
|
||||
target.setLocalTranslation(new Vector3f(x, y, 0));
|
||||
_geom.attachChild(target);
|
||||
|
||||
Box box = new Box("box", new Vector3f(-1, -0.5f, -0.25f),
|
||||
new Vector3f(1, 0.5f, 0.25f));
|
||||
Disk disk = new Disk("dot", 10, 10, 0.5f);
|
||||
disk.setLightCombineMode(LightState.OFF);
|
||||
disk.setLocalTranslation(new Vector3f(0.5f, 0f, 0.3f));
|
||||
Sprite shot = new Sprite();
|
||||
shot.attachChild(box);
|
||||
shot.attachChild(disk);
|
||||
_geom.attachChild(shot);
|
||||
|
||||
testBallistic(shot, target);
|
||||
// testLineSegment(shot);
|
||||
}
|
||||
|
||||
protected void testBallistic (Sprite shot, Box target)
|
||||
{
|
||||
// start with the "cannon" pointed along the x axis
|
||||
Vector3f diff = target.getLocalTranslation().subtract(
|
||||
shot.getLocalTranslation());
|
||||
Vector3f vel = diff.normalize();
|
||||
float range = diff.length(), angle = -FastMath.PI/4;
|
||||
|
||||
Vector3f axis = UP.cross(vel);
|
||||
axis.normalizeLocal();
|
||||
|
||||
// rotate it up (around the y axis) the necessary elevation
|
||||
Quaternion rot = new Quaternion();
|
||||
rot.fromAngleAxis(angle, axis);
|
||||
rot.multLocal(vel);
|
||||
|
||||
// give the cannon its muzzle velocity
|
||||
float muzvel = FastMath.sqrt(range * BallisticPath.G /
|
||||
FastMath.sin(2*angle));
|
||||
vel.multLocal(muzvel);
|
||||
|
||||
Vector3f start = new Vector3f(0, 0, 0);
|
||||
float time = BallisticPath.computeFlightTime(range, muzvel, angle);
|
||||
shot.move(new OrientingBallisticPath(
|
||||
shot, new Vector3f(1, 0, 0), start, vel, GRAVITY, time));
|
||||
|
||||
System.out.println("Range: " + range);
|
||||
System.out.println("Muzzle velocity: " + muzvel);
|
||||
System.out.println("Rotation axis: " + axis);
|
||||
System.out.println("Angle: " + angle + " (" +
|
||||
(angle * 180 / FastMath.PI) + ")");
|
||||
System.out.println("Flight time: " + time);
|
||||
System.out.println("Velocity: " + vel);
|
||||
}
|
||||
|
||||
protected void testLineSegment (Sprite shot)
|
||||
{
|
||||
Vector3f[] points = new Vector3f[] {
|
||||
new Vector3f(0, 0, 0), new Vector3f(2, 0, 0), new Vector3f(3, 0, 0),
|
||||
new Vector3f(3, 2, 0), new Vector3f(5, 2, 0), new Vector3f(5, -2, 0),
|
||||
new Vector3f(-4, -2, 0)
|
||||
};
|
||||
float[] durations = new float[points.length];
|
||||
Arrays.fill(durations, 1f);
|
||||
Vector3f up = new Vector3f(0, 0, 1);
|
||||
Vector3f orient = new Vector3f(1, 0, 0);
|
||||
shot.move(new LineSegmentPath(shot, up, orient, points, durations));
|
||||
}
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
LoggingSystem.getLogger().setLevel(Level.OFF);
|
||||
PathTest test = new PathTest();
|
||||
if (!test.init()) {
|
||||
System.exit(-1);
|
||||
}
|
||||
test.run();
|
||||
}
|
||||
|
||||
protected static final Vector3f GRAVITY = new Vector3f(0, 0, -9.8f);
|
||||
protected static final Vector3f UP = new Vector3f(0, 0, 1);
|
||||
protected static final ColorRGBA[] COLORS = {
|
||||
ColorRGBA.red, ColorRGBA.green, ColorRGBA.blue, ColorRGBA.gray };
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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-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.miso.client;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import com.samskivert.swing.VGroupLayout;
|
||||
|
||||
import com.threerings.media.SafeScrollPane;
|
||||
|
||||
/**
|
||||
* The main application window.
|
||||
*/
|
||||
public class ScrollingFrame extends JFrame
|
||||
{
|
||||
/**
|
||||
* 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 i = 0; i < 10; i++) {
|
||||
stuff.add(new JButton("Button " + i));
|
||||
}
|
||||
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,124 @@
|
||||
//
|
||||
// $Id: ScrollingScene.java 3355 2005-02-17 01:54:54Z 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.miso.client;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Random;
|
||||
|
||||
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.tile.BaseTile;
|
||||
import com.threerings.miso.tile.BaseTileSet;
|
||||
import com.threerings.miso.util.MisoContext;
|
||||
import com.threerings.miso.util.ObjectSet;
|
||||
import com.threerings.miso.data.ObjectInfo;
|
||||
|
||||
/**
|
||||
* 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 iter = tsrepo.enumerateTileSets();
|
||||
String tsname = null;
|
||||
while (iter.hasNext()) {
|
||||
TileSet tset = (TileSet)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);
|
||||
}
|
||||
}
|
||||
|
||||
public int getBaseTileId (int x, int y)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
public boolean setBaseTile (int fqTileId, int x, int y)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean addObject (ObjectInfo info)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void getObjects (Rectangle region, ObjectSet set)
|
||||
{
|
||||
}
|
||||
|
||||
public void updateObject (ObjectInfo info)
|
||||
{
|
||||
}
|
||||
|
||||
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,234 @@
|
||||
//
|
||||
// $Id: ScrollingTestApp.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.miso.client;
|
||||
|
||||
import java.awt.DisplayMode;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.samskivert.swing.util.SwingUtil;
|
||||
import com.samskivert.util.Config;
|
||||
|
||||
import com.threerings.resource.ResourceManager;
|
||||
|
||||
import com.threerings.media.FrameManager;
|
||||
import com.threerings.media.image.ImageManager;
|
||||
import com.threerings.media.util.LinePath;
|
||||
import com.threerings.media.util.Path;
|
||||
|
||||
import com.threerings.media.sprite.PathAdapter;
|
||||
import com.threerings.media.sprite.Sprite;
|
||||
|
||||
import com.threerings.media.tile.bundle.BundledTileSetRepository;
|
||||
|
||||
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 com.threerings.miso.Log;
|
||||
import com.threerings.miso.MisoConfig;
|
||||
import com.threerings.miso.tile.MisoTileManager;
|
||||
import com.threerings.miso.util.MisoContext;
|
||||
|
||||
/**
|
||||
* 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, _frame);
|
||||
|
||||
// we don't need to configure anything
|
||||
ResourceManager rmgr = new ResourceManager("rsrc");
|
||||
rmgr.initBundles(
|
||||
null, "config/resource/manager.properties", null);
|
||||
ImageManager imgr = new ImageManager(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() {
|
||||
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);
|
||||
Log.logStackTrace(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.show();
|
||||
_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,191 @@
|
||||
//
|
||||
// $Id: ViewerApp.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.miso.viewer;
|
||||
|
||||
import java.awt.DisplayMode;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.samskivert.swing.util.SwingUtil;
|
||||
|
||||
import com.threerings.resource.ResourceManager;
|
||||
|
||||
import com.threerings.media.FrameManager;
|
||||
import com.threerings.media.image.ImageManager;
|
||||
import com.threerings.media.tile.bundle.BundledTileSetRepository;
|
||||
|
||||
import com.threerings.cast.CharacterManager;
|
||||
import com.threerings.cast.bundle.BundledComponentRepository;
|
||||
|
||||
import com.threerings.miso.Log;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 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, _frame);
|
||||
|
||||
// we don't need to configure anything
|
||||
ResourceManager rmgr = new ResourceManager("rsrc");
|
||||
rmgr.initBundles(
|
||||
null, "config/resource/manager.properties", null);
|
||||
ImageManager imgr = new ImageManager(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] + "].");
|
||||
Log.logStackTrace(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.show();
|
||||
_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-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.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.JFrame;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
|
||||
import com.samskivert.swing.util.MenuUtil;
|
||||
|
||||
/**
|
||||
* The viewer frame is the main application window.
|
||||
*/
|
||||
public class ViewerFrame extends JFrame
|
||||
{
|
||||
/**
|
||||
* 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-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.miso.viewer;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import com.samskivert.util.RandomUtil;
|
||||
|
||||
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 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.Log;
|
||||
import com.threerings.miso.MisoConfig;
|
||||
import com.threerings.miso.client.MisoScenePanel;
|
||||
import com.threerings.miso.data.MisoSceneModel;
|
||||
import com.threerings.miso.util.MisoContext;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
public void setSceneModel (MisoSceneModel model)
|
||||
{
|
||||
super.setSceneModel(model);
|
||||
Log.info("Using " + model + ".");
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
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 + "].");
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
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,55 @@
|
||||
//
|
||||
// $Id$
|
||||
|
||||
package com.threerings.openal;
|
||||
|
||||
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");
|
||||
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());
|
||||
}
|
||||
};
|
||||
|
||||
SoundManager smgr = SoundManager.createSoundManager(rqueue);
|
||||
ClipProvider provider = new WaveDataClipProvider();
|
||||
final SoundGroup group = smgr.createGroup(provider, 5);
|
||||
final String path = args[0];
|
||||
|
||||
// queue up an interval to play a sound over and over
|
||||
Interval i = new Interval(rqueue) {
|
||||
public void expired () {
|
||||
Sound sound = group.getSound(path);
|
||||
sound.play(true);
|
||||
}
|
||||
};
|
||||
i.schedule(100L, true);
|
||||
|
||||
while (true) {
|
||||
Runnable r = (Runnable)_queue.get();
|
||||
r.run();
|
||||
}
|
||||
}
|
||||
|
||||
protected static Queue _queue = new Queue();
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
//
|
||||
// $Id: DirectionTest.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.util;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Tests the {@link Direction} class.
|
||||
*/
|
||||
public class DirectionTest extends TestCase
|
||||
implements DirectionCodes
|
||||
{
|
||||
public DirectionTest ()
|
||||
{
|
||||
super(DirectionTest.class.getName());
|
||||
}
|
||||
|
||||
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,86 @@
|
||||
//
|
||||
// $Id: DirectionViz.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.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);
|
||||
}
|
||||
|
||||
public void doLayout ()
|
||||
{
|
||||
super.doLayout();
|
||||
_center = new Point(getWidth() / 2, getHeight() / 2);
|
||||
}
|
||||
|
||||
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.show();
|
||||
}
|
||||
|
||||
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-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.util;
|
||||
|
||||
import java.awt.Frame;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
|
||||
import com.threerings.util.Log;
|
||||
|
||||
public class KeyTimerApp
|
||||
{
|
||||
public KeyTimerApp ()
|
||||
{
|
||||
_frame = new TestFrame();
|
||||
_frame.setSize(400, 300);
|
||||
}
|
||||
|
||||
public void run ()
|
||||
{
|
||||
_frame.show();
|
||||
}
|
||||
|
||||
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-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.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 com.threerings.util.Log;
|
||||
|
||||
public class KeyboardManagerApp
|
||||
{
|
||||
public KeyboardManagerApp ()
|
||||
{
|
||||
_frame = new TestFrame();
|
||||
_frame.setSize(400, 300);
|
||||
}
|
||||
|
||||
public void run ()
|
||||
{
|
||||
_frame.show();
|
||||
}
|
||||
|
||||
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";
|
||||
|
||||
// documentation inherited
|
||||
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,79 @@
|
||||
//
|
||||
// $Id: MessageBundleTest.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.util;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Tests the {@link MessageBundle} class.
|
||||
*/
|
||||
public class MessageBundleTest extends TestCase
|
||||
{
|
||||
public MessageBundleTest ()
|
||||
{
|
||||
super(MessageBundleTest.class.getName());
|
||||
}
|
||||
|
||||
public void runTest ()
|
||||
{
|
||||
try {
|
||||
String path = "rsrc.i18n.messages";
|
||||
ResourceBundle rbundle = ResourceBundle.getBundle(path);
|
||||
MessageBundle bundle = new MessageBundle();
|
||||
bundle.init(null, "test", rbundle, null);
|
||||
|
||||
String key1 = MessageBundle.compose("m.foo",
|
||||
MessageBundle.taint("bar"),
|
||||
MessageBundle.taint("baz"));
|
||||
String key2 = MessageBundle.compose("m.biff",
|
||||
MessageBundle.taint("beep"),
|
||||
MessageBundle.taint("boop"));
|
||||
String key = MessageBundle.compose("m.meta", key1, key2);
|
||||
|
||||
String output = bundle.xlate(key);
|
||||
if (!OUTPUT.equals(output)) {
|
||||
fail("xlate failed: " + output);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
fail("Test failed: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Test suite ()
|
||||
{
|
||||
return new MessageBundleTest();
|
||||
}
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
MessageBundleTest test = new MessageBundleTest();
|
||||
test.runTest();
|
||||
}
|
||||
|
||||
protected static final String OUTPUT =
|
||||
"Meta arg one is 'Foo arg one is 'bar' and two is 'baz'.' and " +
|
||||
"two is 'Biff arg one is 'beep' and two is 'boop'.'.";
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// $Id$
|
||||
|
||||
package com.threerings.util;
|
||||
|
||||
import com.threerings.util.unsafe.Unsafe;
|
||||
|
||||
/**
|
||||
* Does something extraordinary.
|
||||
*/
|
||||
public class UIDTest
|
||||
{
|
||||
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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user