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,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) {
}
}
}