Create profile entry point for MG
parent
7191ae0cda
commit
ba52e24ab9
Binary file not shown.
After Width: | Height: | Size: 222 B |
Binary file not shown.
After Width: | Height: | Size: 222 B |
|
@ -0,0 +1,70 @@
|
|||
package net.mosstest.swingui;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
|
||||
|
||||
|
||||
import java.awt.MouseInfo;
|
||||
import java.awt.Point;
|
||||
import java.awt.PointerInfo;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
|
||||
public class DnDListener implements MouseListener {
|
||||
|
||||
private double startX, startY;
|
||||
private double endX, endY;
|
||||
private JLabel holder;
|
||||
|
||||
public DnDListener (JLabel parent) {
|
||||
startX = 0;
|
||||
startY = 0;
|
||||
endX = 0;
|
||||
endY = 0;
|
||||
holder = parent;
|
||||
}
|
||||
|
||||
public void printDiagnostics () {
|
||||
System.out.println("START X: "+startX+" START Y: "+startY);
|
||||
System.out.println("END X: "+endX+" END Y: "+endY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent arg0) {
|
||||
PointerInfo info = MouseInfo.getPointerInfo();
|
||||
Point location = info.getLocation();
|
||||
startX = location.getX();
|
||||
startY = location.getY();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent arg0) {
|
||||
PointerInfo info = MouseInfo.getPointerInfo();
|
||||
Point location = info.getLocation();
|
||||
endX = location.getX() - 35; //35, 60: modifiers that need to be present or there
|
||||
endY = location.getY() - 60; //is a significant offset when placement occurs.
|
||||
holder.setLocation((int)endX, (int)endY);
|
||||
printDiagnostics();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent arg0) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package net.mosstest.swingui;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
|
||||
public class SwingDragDrop {
|
||||
static JFrame frame;
|
||||
static JLabel picture;
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
setupFrame();
|
||||
setupLabels();
|
||||
frame.repaint();
|
||||
}
|
||||
|
||||
public static void setupFrame() {
|
||||
frame = new JFrame("Drag and Drop Test");
|
||||
frame.setSize(800, 600);
|
||||
frame.setVisible(true);
|
||||
frame.setLayout(null);
|
||||
}
|
||||
|
||||
public static void setupLabels() throws IOException {
|
||||
ImageIcon icon = new ImageIcon(ImageIO
|
||||
.read(new File("item_switch.png")).getScaledInstance(64, 64,
|
||||
Image.SCALE_REPLICATE));
|
||||
picture = new JLabel(icon);
|
||||
picture.setSize(64, 64);
|
||||
picture.setLocation(200, 200);
|
||||
picture.addMouseListener(new DnDListener(picture));
|
||||
frame.add(picture);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package net.mosstest.tests;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Random;
|
||||
|
||||
import net.mosstest.scripting.MapChunk;
|
||||
import net.mosstest.scripting.MapGenerators;
|
||||
import net.mosstest.scripting.Position;
|
||||
import net.mosstest.scripting.SimplexMapGenerator;
|
||||
import net.mosstest.servercore.MapGeneratorException;
|
||||
|
||||
public class MapGenProfilerEntryPoint {
|
||||
public static void main(String[] args) throws MapGeneratorException, InterruptedException {
|
||||
int chks = 0;
|
||||
Thread.sleep(10000); // sleep to allow profiler launch
|
||||
MapGenerators.setDefaultMapGenerator(new SimplexMapGenerator(),
|
||||
new MockNodeManager(), 1011, null);
|
||||
HashMap<Position, MapChunk> chunks = new HashMap<>();
|
||||
Random rand = new Random();
|
||||
whileLoop: while (true) {
|
||||
long sTime = System.currentTimeMillis();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
Position pos = new Position(rand.nextInt(), rand.nextInt(),
|
||||
rand.nextInt(), 0);
|
||||
|
||||
MapChunk chk = MapGenerators.getDefaultMapgen().generateChunk(
|
||||
pos);
|
||||
|
||||
chunks.put(pos, chk);
|
||||
chks++;
|
||||
if(chks > 10000) {
|
||||
break whileLoop;
|
||||
}
|
||||
}
|
||||
System.err.println(System.currentTimeMillis() - sTime + ", " + chks);
|
||||
}
|
||||
while(true) {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package net.mosstest.tests;
|
||||
|
||||
import net.mosstest.scripting.AirNodeParams;
|
||||
import net.mosstest.scripting.DefaultNodeParams;
|
||||
import net.mosstest.scripting.MapNode;
|
||||
import net.mosstest.servercore.INodeManager;
|
||||
import net.mosstest.servercore.MossWorldLoadException;
|
||||
|
||||
public class MockNodeManager implements INodeManager {
|
||||
private static final MapNode MOCK_SOLID_MAPNODE = new MapNode(
|
||||
new DefaultNodeParams(), "mock", "!mock:mock", "Mock node", 1);
|
||||
|
||||
@Override
|
||||
public MapNode getNode(short nodeId) {
|
||||
return MOCK_SOLID_MAPNODE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short putNode(MapNode node) throws MossWorldLoadException {
|
||||
// TODO Auto-generated method stub
|
||||
return 1337;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putNodeAlias(String alias, String dst) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapNode getNode(String string, boolean isModified) {
|
||||
return MOCK_SOLID_MAPNODE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapNode getNode(String string) {
|
||||
return MOCK_SOLID_MAPNODE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue