Hold onto your hats kids, it's the biggest little refactor this side of the

Pecos. I'll sort out the per-project niggling bits in just a moment.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4209 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2006-06-23 18:12:45 +00:00
parent 5ceed9c8b2
commit c0a244cb8d
594 changed files with 17 additions and 96041 deletions
@@ -1,153 +0,0 @@
//
// $Id$
//
// 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;
}
@@ -1,76 +0,0 @@
//
// $Id$
//
// 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;
}
@@ -1,43 +0,0 @@
//
// $Id: TestFrame.java,v 1.7 2004/08/27 02:20:54 mdb Exp $
//
// 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/"));
}
}
@@ -1,85 +0,0 @@
//
// $Id$
//
// 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();
}
}
@@ -9,8 +9,8 @@ import javax.swing.JPanel;
import com.threerings.crowd.data.PlaceObject;
import com.threerings.crowd.util.CrowdContext;
import com.threerings.micasa.client.ChatPanel;
import com.threerings.micasa.client.OccupantList;
// import com.threerings.micasa.client.ChatPanel;
// import com.threerings.micasa.client.OccupantList;
/**
* Displays a simple chat view.
@@ -22,8 +22,8 @@ public class JabberPanel extends JPanel
{
_ctx = ctx;
setLayout(new BorderLayout());
add(new ChatPanel(ctx), BorderLayout.CENTER);
add(new OccupantList(ctx), BorderLayout.EAST);
// add(new ChatPanel(ctx), BorderLayout.CENTER);
// add(new OccupantList(ctx), BorderLayout.EAST);
}
// documentation inherited from interface PlaceView
@@ -1,101 +0,0 @@
//
// $Id: NearestViz.java,v 1.3 2004/08/27 02:20:56 mdb Exp $
//
// 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();
}
@@ -1,113 +0,0 @@
//
// $Id: WhichSideViz.java,v 1.3 2004/08/27 02:20:56 mdb Exp $
//
// 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();
}
@@ -1,62 +0,0 @@
//
// $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();
}
}
@@ -1,160 +0,0 @@
//
// $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;
}
@@ -1,228 +0,0 @@
//
// $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";
}
@@ -1,19 +0,0 @@
//
// $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);
}
}
@@ -1,51 +0,0 @@
//
// $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;
}
@@ -1,26 +0,0 @@
//
// $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";
}
}
@@ -1,49 +0,0 @@
//
// $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;
}
@@ -1,150 +0,0 @@
//
// $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 };
}
@@ -1,80 +0,0 @@
//
// $Id: ImageLoadingSpeed.java,v 1.6 2004/08/27 02:20:57 mdb Exp $
//
// 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;
}
}
}
}
@@ -1,65 +0,0 @@
//
// $Id: TestIconManager.java,v 1.4 2004/08/27 02:20:57 mdb Exp $
//
// 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);
}
}
}
@@ -1,68 +0,0 @@
//
// $Id: SoundTestApp.java,v 1.7 2004/08/27 02:20:58 mdb Exp $
//
// 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;
}
@@ -1,7 +0,0 @@
#
# $Id: sounds.properties,v 1.1 2002/12/10 21:36:53 mdb Exp $
#
# Sound test app configuration file
sound1 = media/test.wav
sound2 = foo/bar.wav
@@ -1,70 +0,0 @@
//
// $Id$
//
// 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();
}
}
@@ -1,94 +0,0 @@
//
// $Id: BuildTestTileSetBundle.java,v 1.8 2004/08/27 02:20:59 mdb Exp $
//
// 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";
}
@@ -1,78 +0,0 @@
//
// $Id: XMLTileSetParserTest.java,v 1.5 2004/08/27 02:21:00 mdb Exp $
//
// 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";
}
@@ -1,111 +0,0 @@
//
// $Id$
//
// 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;
}
@@ -1,115 +0,0 @@
//
// $Id: TraceViz.java,v 1.6 2004/08/27 02:21:00 mdb Exp $
//
// 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;
}
@@ -1,89 +0,0 @@
//
// $Id: ScrollingFrame.java,v 1.6 2004/08/27 02:21:01 mdb Exp $
//
// 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;
}
@@ -1,124 +0,0 @@
//
// $Id$
//
// 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;
}
@@ -1,234 +0,0 @@
//
// $Id$
//
// 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;
}
@@ -1,191 +0,0 @@
//
// $Id$
//
// 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;
}
@@ -1,94 +0,0 @@
//
// $Id: ViewerFrame.java,v 1.35 2004/08/27 02:21:01 mdb Exp $
//
// 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;
}
@@ -1,237 +0,0 @@
//
// $Id$
//
// 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[];
}
@@ -1,55 +0,0 @@
//
// $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();
}
@@ -1,127 +0,0 @@
//
// $Id$
//
// 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.parlor;
import com.threerings.util.Name;
import com.threerings.presents.client.*;
import com.threerings.presents.net.*;
import com.threerings.crowd.client.*;
import com.threerings.crowd.data.BodyObject;
import com.threerings.crowd.util.CrowdContext;
import com.threerings.parlor.Log;
import com.threerings.parlor.client.*;
import com.threerings.parlor.game.client.*;
import com.threerings.parlor.game.data.*;
import com.threerings.parlor.util.ParlorContext;
public class TestClient extends com.threerings.crowd.client.TestClient
implements InvitationHandler, InvitationResponseObserver
{
public TestClient (String username)
{
super(username);
// create the handles on our various services
_pardtr = new ParlorDirector(_ctx);
// register ourselves as the invitation handler
_pardtr.setInvitationHandler(this);
}
public void clientDidLogon (Client client)
{
// we intentionally don't call super()
Log.info("Client did logon [client=" + client + "].");
// get a casted reference to our body object
_body = (BodyObject)client.getClientObject();
// if we're the inviter, do some inviting
if (_body.username.equals("inviter")) {
// send the invitation
TestConfig config = new TestConfig();
_pardtr.invite(new Name("invitee"), config, this);
}
}
public void invitationReceived (Invitation invite)
{
Log.info("Invitation received [invite=" + invite + "].");
// accept the invitation. we're game...
invite.accept();
}
public void invitationCancelled (Invitation invite)
{
Log.info("Invitation cancelled [invite=" + invite + "].");
}
public void invitationAccepted (Invitation invite)
{
Log.info("Invitation accepted [invite=" + invite + "].");
}
public void invitationRefused (Invitation invite, String message)
{
Log.info("Invitation refused [invite=" + invite +
", message=" + message + "].");
}
public void invitationCountered (Invitation invite, GameConfig config)
{
Log.info("Invitation countered [invite=" + invite +
", config=" + config + "].");
}
protected CrowdContext createContext ()
{
return (_ctx = new ParlorContextImpl());
}
public static void main (String[] args)
{
// create our test client
TestClient tclient = new TestClient(
System.getProperty("username", "test"));
// start it running
tclient.run();
}
protected class ParlorContextImpl
extends com.threerings.crowd.client.TestClient.CrowdContextImpl
implements ParlorContext
{
public ParlorDirector getParlorDirector ()
{
return _pardtr;
}
}
protected ParlorContext _ctx;
protected ParlorDirector _pardtr;
protected BodyObject _body;
}
@@ -1,57 +0,0 @@
//
// $Id$
//
// 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.parlor;
import com.threerings.parlor.game.client.GameConfigurator;
import com.threerings.parlor.game.data.GameConfig;
public class TestConfig extends GameConfig
{
/** The foozle parameter. */
public int foozle;
public GameConfigurator createConfigurator ()
{
return null;
}
public Class getControllerClass ()
{
return TestController.class;
}
public String getBundleName ()
{
return "test";
}
public String getManagerClassName ()
{
return "com.threerings.parlor.test.TestManager";
}
protected void toString (StringBuilder buf)
{
super.toString(buf);
buf.append(", foozle=").append(foozle);
}
}
@@ -1,35 +0,0 @@
//
// $Id$
//
// 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.parlor;
import com.threerings.crowd.client.PlaceView;
import com.threerings.crowd.util.CrowdContext;
import com.threerings.parlor.game.client.GameController;
public class TestController extends GameController
{
public PlaceView createPlaceView (CrowdContext ctx)
{
// nothing doing
return null;
}
}
@@ -1,29 +0,0 @@
//
// $Id$
//
// 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.parlor;
import com.threerings.parlor.game.server.GameManager;
public class TestManager extends GameManager
{
// nothing doing
}
@@ -1,61 +0,0 @@
//
// $Id: TestServer.java,v 1.6 2004/08/27 02:21:02 mdb Exp $
//
// 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.parlor;
import com.threerings.crowd.server.CrowdServer;
import com.threerings.parlor.Log;
import com.threerings.parlor.server.ParlorManager;
/**
* A test server for the Parlor services.
*/
public class TestServer extends CrowdServer
{
/** The parlor manager in operation on this server. */
public static ParlorManager parmgr = new ParlorManager();
/** Initializes the Parlor test server. */
public void init ()
throws Exception
{
super.init();
// initialize our parlor manager
parmgr.init(invmgr, plreg);
Log.info("Parlor server initialized.");
}
/** Main entry point for test server. */
public static void main (String[] args)
{
TestServer server = new TestServer();
try {
server.init();
server.run();
} catch (Exception e) {
Log.warning("Unable to initialize server.");
Log.logStackTrace(e);
}
}
}
@@ -1,73 +0,0 @@
//
// $Id: DirectionTest.java,v 1.3 2004/08/27 02:21:05 mdb Exp $
//
// 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();
}
}
@@ -1,86 +0,0 @@
//
// $Id: DirectionViz.java,v 1.2 2004/08/27 02:21:05 mdb Exp $
//
// 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();
}
@@ -1,97 +0,0 @@
//
// $Id: KeyTimerApp.java,v 1.3 2004/08/27 02:21:05 mdb Exp $
//
// 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;
}
@@ -1,108 +0,0 @@
//
// $Id: KeyboardManagerApp.java,v 1.6 2004/08/27 02:21:05 mdb Exp $
//
// 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;
}
@@ -1,30 +0,0 @@
//
// $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) {
}
}
}
@@ -1,59 +0,0 @@
//
// $Id: DummyClientSceneRepository.java,v 1.7 2004/08/27 02:21:05 mdb Exp $
//
// 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.whirled;
import java.io.IOException;
import com.threerings.whirled.Log;
import com.threerings.whirled.client.persist.SceneRepository;
import com.threerings.whirled.data.SceneModel;
import com.threerings.whirled.util.NoSuchSceneException;
/**
* The dummy scene repository just pretends to load and store scenes, but
* in fact it just creates new blank scenes when requested to load a scene
* and does nothing when requested to save one.
*/
public class DummyClientSceneRepository implements SceneRepository
{
// documentation inherited
public SceneModel loadSceneModel (int sceneId)
throws IOException, NoSuchSceneException
{
Log.info("Creating dummy scene model [id=" + sceneId + "].");
return new SceneModel();
}
// documentation inherited
public void storeSceneModel (SceneModel model)
throws IOException
{
// nothing doing
}
// documentation inherited
public void deleteSceneModel (int sceneId)
throws IOException
{
// nothing doing
}
}
@@ -1,115 +0,0 @@
//
// $Id$
//
// 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.whirled;
import com.threerings.presents.client.Client;
import com.threerings.crowd.Log;
import com.threerings.crowd.client.*;
import com.threerings.crowd.data.PlaceConfig;
import com.threerings.crowd.data.PlaceObject;
import com.threerings.crowd.util.CrowdContext;
import com.threerings.whirled.client.SceneDirector;
import com.threerings.whirled.client.persist.SceneRepository;
import com.threerings.whirled.data.Scene;
import com.threerings.whirled.data.SceneImpl;
import com.threerings.whirled.data.SceneModel;
import com.threerings.whirled.util.SceneFactory;
import com.threerings.whirled.util.WhirledContext;
public class TestClient extends com.threerings.crowd.client.TestClient
implements LocationObserver
{
public TestClient (String username)
{
super(username);
// create the handles for our various services
_screp = new DummyClientSceneRepository();
SceneFactory sfact = new SceneFactory() {
public Scene createScene (SceneModel model, PlaceConfig config) {
return new SceneImpl(model, config);
}
};
_scdir = new SceneDirector(_ctx, _locdir, _screp, sfact);
// we want to know about location changes
_locdir.addLocationObserver(this);
}
public void clientDidLogon (Client client)
{
// we specifically do not call super()
Log.info("Client did logon [client=" + client + "].");
// request to move to scene 0
_ctx.getSceneDirector().moveTo(0);
}
public boolean locationMayChange (int placeId)
{
// we're easy
return true;
}
public void locationDidChange (PlaceObject place)
{
Log.info("At new location [plobj=" + place +
", scene=" + _scdir.getScene() + "].");
}
public void locationChangeFailed (int placeId, String reason)
{
Log.warning("Location change failed [plid=" + placeId +
", reason=" + reason + "].");
}
protected CrowdContext createContext ()
{
return (_ctx = new WhirledContextImpl());
}
public static void main (String[] args)
{
// create our test client
TestClient tclient = new TestClient("test");
// start it running
tclient.run();
}
protected class WhirledContextImpl
extends com.threerings.crowd.client.TestClient.CrowdContextImpl
implements WhirledContext
{
public SceneDirector getSceneDirector ()
{
return _scdir;
}
}
protected WhirledContext _ctx;
protected SceneDirector _scdir;
protected SceneRepository _screp;
}
@@ -1,38 +0,0 @@
//
// $Id: TestConfig.java,v 1.4 2004/08/27 02:21:05 mdb Exp $
//
// 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.whirled;
import com.threerings.crowd.data.PlaceConfig;
import com.threerings.whirled.server.SceneManager;
public class TestConfig extends PlaceConfig
{
public Class getControllerClass ()
{
return TestController.class;
}
public String getManagerClassName ()
{
return SceneManager.class.getName();
}
}
@@ -1,34 +0,0 @@
//
// $Id$
//
// 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.whirled;
import com.threerings.crowd.client.*;
import com.threerings.crowd.util.CrowdContext;
public class TestController extends PlaceController
{
protected PlaceView createPlaceView (CrowdContext ctx)
{
// nothing doing
return null;
}
}
@@ -1,74 +0,0 @@
//
// $Id$
//
// 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.whirled.spot.tools.xml;
import com.samskivert.test.TestUtil;
import junit.framework.Test;
import junit.framework.TestCase;
import com.threerings.whirled.data.SceneModel;
import com.threerings.whirled.spot.data.Location;
import com.threerings.whirled.tools.xml.SceneParser;
import com.threerings.stage.data.StageLocation;
public class SpotSceneParserTest extends TestCase
{
public SpotSceneParserTest ()
{
super(SpotSceneParserTest.class.getName());
}
public void runTest ()
{
try {
SceneParser parser = new SceneParser("scene");
parser.registerAuxRuleSet(new SpotSceneRuleSet() {
protected Location createLocation () {
return new StageLocation(); // breaks package, but ok
}
});
String tspath = TestUtil.getResourcePath(TEST_SCENE_PATH);
SceneModel scene = parser.parseScene(tspath);
System.out.println("Parsed " + scene + ".");
} catch (Exception e) {
e.printStackTrace();
fail("Test threw exception");
}
}
public static Test suite ()
{
return new SpotSceneParserTest();
}
public static void main (String[] args)
{
SpotSceneParserTest test = new SpotSceneParserTest();
test.runTest();
}
protected static final String TEST_SCENE_PATH =
"rsrc/whirled/spot/tools/xml/scene.xml";
}
@@ -1,65 +0,0 @@
//
// $Id: SceneParserTest.java,v 1.6 2004/08/27 02:21:06 mdb Exp $
//
// 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.whirled.tools.xml;
import com.samskivert.test.TestUtil;
import junit.framework.Test;
import junit.framework.TestCase;
import com.threerings.whirled.data.SceneModel;
public class SceneParserTest extends TestCase
{
public SceneParserTest ()
{
super(SceneParserTest.class.getName());
}
public void runTest ()
{
try {
SceneParser parser = new SceneParser("scene");
String tspath = TestUtil.getResourcePath(TEST_SCENE_PATH);
SceneModel scene = parser.parseScene(tspath);
System.out.println("Parsed " + scene + ".");
} catch (Exception e) {
e.printStackTrace();
fail("Test threw exception");
}
}
public static Test suite ()
{
return new SceneParserTest();
}
public static void main (String[] args)
{
SceneParserTest test = new SceneParserTest();
test.runTest();
}
protected static final String TEST_SCENE_PATH =
"rsrc/whirled/tools/xml/scene.xml";
}