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

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


git-svn-id: svn+ssh://src.earth.threerings.net/nenya/trunk@1 ed5b42cb-e716-0410-a449-f6a68f950b19
This commit is contained in:
Michael Bayne
2006-06-23 18:07:28 +00:00
commit c2117ee86d
570 changed files with 61913 additions and 0 deletions
@@ -0,0 +1,73 @@
//
// $Id: DirectionTest.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.util;
import junit.framework.Test;
import junit.framework.TestCase;
/**
* Tests the {@link Direction} class.
*/
public class DirectionTest extends TestCase
implements DirectionCodes
{
public DirectionTest ()
{
super(DirectionTest.class.getName());
}
public void runTest ()
{
int orient = NORTH;
for (int i = 0; i < FINE_DIRECTION_COUNT; i++) {
// System.out.print(DirectionUtil.toShortString(orient) + " -> ");
orient = DirectionUtil.rotateCW(orient, 1);
}
// System.out.println(DirectionUtil.toShortString(orient));
assertTrue("CW rotate", orient == NORTH);
for (int i = 0; i < FINE_DIRECTION_COUNT; i++) {
// System.out.print(DirectionUtil.toShortString(orient) + " -> ");
orient = DirectionUtil.rotateCCW(orient, 1);
}
// System.out.println(DirectionUtil.toShortString(orient));
assertTrue("CCW rotate", orient == NORTH);
// for (double theta = -Math.PI; theta <= Math.PI; theta += Math.PI/1000) {
// orient = DirectionUtil.getFineDirection(theta);
// System.out.println(Math.toDegrees(theta) + " => " +
// DirectionUtil.toShortString(orient));
// }
}
public static Test suite ()
{
return new DirectionTest();
}
public static void main (String[] args)
{
DirectionTest test = new DirectionTest();
test.runTest();
}
}
@@ -0,0 +1,86 @@
//
// $Id: DirectionViz.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.util;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
* Renders the output of {@link DirectionUtil#getDirection} just for
* kicks.
*/
public class DirectionViz extends JPanel
implements MouseMotionListener
{
public DirectionViz ()
{
addMouseMotionListener(this);
}
public void doLayout ()
{
super.doLayout();
_center = new Point(getWidth() / 2, getHeight() / 2);
}
public void paintComponent (Graphics g)
{
super.paintComponent(g);
g.setColor(Color.blue);
g.drawLine(_center.x, _center.y, _spot.x, _spot.y);
int orient = DirectionUtil.getFineDirection(_center, _spot);
g.drawString(DirectionUtil.toShortString(orient), _spot.x, _spot.y);
}
public void mouseDragged (MouseEvent event)
{
}
public void mouseMoved (MouseEvent event)
{
_spot.x = event.getX();
_spot.y = event.getY();
repaint();
}
public static void main (String[] args)
{
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new DirectionViz(), BorderLayout.CENTER);
frame.setSize(300, 300);
frame.show();
}
protected Point _center;
protected Point _spot = new Point();
}
@@ -0,0 +1,97 @@
//
// $Id: KeyTimerApp.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.util;
import java.awt.Frame;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import com.threerings.util.Log;
public class KeyTimerApp
{
public KeyTimerApp ()
{
_frame = new TestFrame();
_frame.setSize(400, 300);
}
public void run ()
{
_frame.show();
}
public static void main (String[] args)
{
KeyTimerApp app = new KeyTimerApp();
app.run();
}
protected class TestFrame extends Frame implements KeyListener
{
public TestFrame ()
{
addKeyListener(this);
_prStart = _rpStart = -1;
}
public void keyPressed (KeyEvent e)
{
long now = System.currentTimeMillis();
_prStart = now;
if (_rpStart != -1) {
Log.info("RP\t" + (now - _rpStart));
}
logKey("keyPressed", e);
}
public void keyReleased (KeyEvent e)
{
long now = System.currentTimeMillis();
_rpStart = now;
Log.info("PR\t" + (now - _prStart));
logKey("keyReleased", e);
}
public void keyTyped (KeyEvent e)
{
logKey("keyTyped", e);
}
/**
* Logs the given message and key.
*/
protected void logKey (String msg, KeyEvent e)
{
int keyCode = e.getKeyCode();
Log.info(msg + " [key=" + KeyEvent.getKeyText(keyCode) + "].");
}
protected long _prStart, _rpStart;
}
protected Frame _frame;
}
@@ -0,0 +1,108 @@
//
// $Id: KeyboardManagerApp.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.util;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.samskivert.swing.Controller;
import com.samskivert.swing.ControllerProvider;
import com.threerings.util.Log;
public class KeyboardManagerApp
{
public KeyboardManagerApp ()
{
_frame = new TestFrame();
_frame.setSize(400, 300);
}
public void run ()
{
_frame.show();
}
public static void main (String[] args)
{
KeyboardManagerApp app = new KeyboardManagerApp();
app.run();
}
protected static class TestFrame extends JFrame
implements ControllerProvider
{
public TestFrame ()
{
// create the test controller
_ctrl = new TestController();
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel top = new JPanel();
// add some sample key mappings
KeyTranslatorImpl xlate = new KeyTranslatorImpl();
xlate.addPressCommand(KeyEvent.VK_LEFT, TestController.MOVE_LEFT);
xlate.addPressCommand(
KeyEvent.VK_RIGHT, TestController.MOVE_RIGHT);
xlate.addPressCommand(KeyEvent.VK_SPACE, TestController.DROP);
// create the keyboard manager
KeyboardManager keymgr = new KeyboardManager();
keymgr.setTarget(top, xlate);
keymgr.setEnabled(true);
getContentPane().add(top);
}
// documentation inherited
public Controller getController ()
{
return _ctrl;
}
/** The test controller. */
protected Controller _ctrl;
}
protected static class TestController extends Controller
{
public static final String MOVE_LEFT = "move_left";
public static final String MOVE_RIGHT = "move_right";
public static final String DROP = "drop";
// documentation inherited
public boolean handleAction (ActionEvent action)
{
String cmd = action.getActionCommand();
Log.info("handleAction [cmd=" + cmd + "].");
return true;
}
}
/** The test frame. */
protected JFrame _frame;
}
@@ -0,0 +1,79 @@
//
// $Id: MessageBundleTest.java 3099 2004-08-27 02:21:06Z mdb $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.util;
import java.util.ResourceBundle;
import junit.framework.Test;
import junit.framework.TestCase;
/**
* Tests the {@link MessageBundle} class.
*/
public class MessageBundleTest extends TestCase
{
public MessageBundleTest ()
{
super(MessageBundleTest.class.getName());
}
public void runTest ()
{
try {
String path = "rsrc.i18n.messages";
ResourceBundle rbundle = ResourceBundle.getBundle(path);
MessageBundle bundle = new MessageBundle();
bundle.init(null, "test", rbundle, null);
String key1 = MessageBundle.compose("m.foo",
MessageBundle.taint("bar"),
MessageBundle.taint("baz"));
String key2 = MessageBundle.compose("m.biff",
MessageBundle.taint("beep"),
MessageBundle.taint("boop"));
String key = MessageBundle.compose("m.meta", key1, key2);
String output = bundle.xlate(key);
if (!OUTPUT.equals(output)) {
fail("xlate failed: " + output);
}
} catch (Exception e) {
fail("Test failed: " + e);
}
}
public static Test suite ()
{
return new MessageBundleTest();
}
public static void main (String[] args)
{
MessageBundleTest test = new MessageBundleTest();
test.runTest();
}
protected static final String OUTPUT =
"Meta arg one is 'Foo arg one is 'bar' and two is 'baz'.' and " +
"two is 'Biff arg one is 'beep' and two is 'boop'.'.";
}
@@ -0,0 +1,30 @@
//
// $Id$
package com.threerings.util;
import com.threerings.util.unsafe.Unsafe;
/**
* Does something extraordinary.
*/
public class UIDTest
{
public static void main (String[] args)
{
if (Unsafe.setuid(1000)) {
System.err.println("Yay! My uid is changed.");
} else {
System.err.println("Boo hoo! I couldn't change my uid.");
}
if (Unsafe.setgid(60)) {
System.err.println("Yay! My gid is changed.");
} else {
System.err.println("Boo hoo! I couldn't change my gid.");
}
try {
Thread.sleep(60*1000L);
} catch (Exception e) {
}
}
}