Show Posts
|
|
Pages: [1] 2 3
|
|
2
|
Discussions / Miscellaneous Topics / Re: Weirdest and rarest bug in Java!
|
on: 2011-07-07 04:01:27
|
|
Approximately 2% of the time, trying to run my game applet in the browser causes the JVM to crash. It never happens when debugging in NetBeans, and nobody has reported this bug since we switched from Java Web Start to applets 2 months ago. It's a little disturbing, but since it doesn't seem to affect any players I haven't been motivated to debug it.
Also, once or twice while playing Minecraft Classic (this was probably 1-2 years ago) my whole screen starting flashing black very quickly, then I got an Nvidia driver error: "This application has caused too many errors and must be closed." Could have been my driver version, but I've never seen that error with any other game.
|
|
|
|
|
5
|
Java Game APIs & Engines / Java 2D / Realtime effects in Java2D?
|
on: 2011-06-05 02:10:36
|
|
I would like to add a couple rendering effects to my online game creation tool that users can use in their own games. These would be simple effects like blur, grayscale, and colorize - nothing too fancy.
I read that some of the RasterOps are accelerated using shaders, but I'm not sure how the compatibility for that is, or if it's even practical to do in realtime at all. Obviously, speed is a requirement.
Thanks!
|
|
|
|
|
6
|
Game Development / Networking & Multiplayer / Files downloaded from an applet are getting corrupted?
|
on: 2011-06-01 18:23:39
|
I'm trying to make an applet loader for my game. Once downloaded, the 3 .jar files it needs are the correct size, but they don't work. I opened them with a hex editor and found that some bytes are being changed to other bytes, seemingly at random. However, it isn't random because if I delete the files and have them download again, the same incorrect bytes are in the same places! It's really weird. Here is the code. 1 2 3 4 5 6 7 8 9 10 11 12 13
| URL url = new URL(urlString); URLConnection conn = url.openConnection(); int len = conn.getContentLength(); downloadStream = new ProgressBarInputStream(conn.getInputStream(), updatePanel.progressBar, len); String filePath = gamePath + "/" + urlString.replace("http://mydomain.net/game/", ""); FileOutputStream out = new FileOutputStream(filePath); int bytes = 0; while (bytes < len) { out.write(downloadStream.read()); bytes++; } out.close(); downloadStream.close(); |
|
|
|
|
|
9
|
Discussions / General Discussions / Re: Lots of doors are being closed for Java
|
on: 2011-03-20 01:14:50
|
|
For a highly website-integrated GUI application like my own, Java was the best way to go. .NET ClickOnce sucks and is Windows-only, and system GUI widgets don't work in Flash. The second best way would be to use a custom protocol handler, but that would require an installation... with Web Start you just have to click a link. Putting out updates is a snap too.
Beyond desktop games, I think mobile gaming is where it's at, but Oracle seems more interested in pushing their server technologies than anything else.
|
|
|
|
|
12
|
Game Development / Newbie & Debugging Questions / What might make Graphics2D.drawImage() slow?
|
on: 2011-02-25 20:43:15
|
I'm developing a physics sandbox game. I can easily fill the whole screen with rotated, scaled, textured boxes without noticing any FPS drops or excessive CPU usage, and drawing the character without a rotate transformation is fast. However, if I rotate the character image, or scale it, CPU usage goes through the roof and there is a small but noticable FPS decrease. Using a profiler, I determined that drawImage() was the problem. As far as I can tell the character and texture images are being drawn the same way... It's really confounding. From the character: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| private VolatileImage character = Util.getGraphicsConfiguration().createCompatibleVolatileImage(200, 200, Transparency.BITMASK); [...] public void draw(Graphics g) throws BuildismException { updateImage(); Vec2D pos = getPart().getPosition().worldToScreen(Main.getView()); int w = (int) (200*(Main.getView().scaleFactor/8)); int h = (int) (200*(Main.getView().scaleFactor/8)); int imgX = (int) pos.getX() - w/2; int imgY = (int) pos.getY() - h/2; AffineTransform orig = ((Graphics2D)g).getTransform(); AffineTransform rotate = AffineTransform.getRotateInstance(-Math.toRadians(getPart().getRotation()), pos.getX(), pos.getY()); ((Graphics2D)g).setTransform(rotate); g.drawImage(character, imgX, imgY, w, h, null); ((Graphics2D)g).setTransform(orig); } |
For textured boxes (yes, I know this code is messy and unoptimized... but it works faster than the much simpler code for drawing a character!) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| public void setTexture(BufferedImage t) { if(t != null) { VolatileImage i = Util.getGraphicsConfiguration().createCompatibleVolatileImage(t.getWidth(), t.getHeight(), Transparency.TRANSLUCENT); Graphics2D g2 = (Graphics2D) i.getGraphics(); Composite old = g2.getComposite(); g2.setColor(transparent); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OUT)); g2.fillRect(0, 0, t.getWidth(), t.getHeight()); g2.setComposite(old); g2.drawImage(t, 0, 0, null); texture = i; } else texture = null; }
[...]
Graphics2D g2 = (Graphics2D) g; Vec2D worldPos = new Vec2D(body.getPosition()); Vec2D imgPos = worldPos.add(new Vec2D(-getVec2DProp("Size").getX(), getVec2DProp("Size").getY()).mul(0.5)).worldToScreen(Main.getView()); Vec2D rotateCenter = worldPos.worldToScreen(Main.getView()); AffineTransform original = g2.getTransform(); AffineTransform scale = AffineTransform.getScaleInstance(scaleDimensionForScreen(texture.getWidth(), getVec2DProp("Size").getX()), scaleDimensionForScreen(texture.getHeight(), getVec2DProp("Size").getY())); AffineTransform rotate = AffineTransform.getRotateInstance(-body.getAngle(), rotateCenter.getX(), rotateCenter.getY()); g2.setTransform(rotate); g2.transform(scale); g2.drawImage(texture, (int) (imgPos.getX() / ((Main.getView().scaleFactor * getVec2DProp("Size").getX())/texture.getWidth())), (int) (imgPos.getY() / ((Main.getView().scaleFactor * getVec2DProp("Size").getY())/texture.getHeight())), null); g2.setTransform(original); |
Does anyone see a problem?
|
|
|
|
|
13
|
Java Game APIs & Engines / Java 2D / What might make Graphics2D.drawImage() slow?
|
on: 2011-02-25 00:05:55
|
I'm developing a physics sandbox game. I can easily fill the whole screen with rotated, scaled, textured boxes without noticing any FPS drops or excessive CPU usage, and drawing the character without a rotate transformation is fast. However, if I rotate the character image, or scale it, CPU usage goes through the roof and there is a small but noticable FPS decrease. Using a profiler, I determined that drawImage() was the problem. As far as I can tell the character and texture images are being drawn the same way... It's really confounding. From the character: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| private VolatileImage character = Util.getGraphicsConfiguration().createCompatibleVolatileImage(200, 200, Transparency.BITMASK); [...] public void draw(Graphics g) throws BuildismException { updateImage(); Vec2D pos = getPart().getPosition().worldToScreen(Main.getView()); int w = (int) (200*(Main.getView().scaleFactor/8)); int h = (int) (200*(Main.getView().scaleFactor/8)); int imgX = (int) pos.getX() - w/2; int imgY = (int) pos.getY() - h/2; AffineTransform orig = ((Graphics2D)g).getTransform(); AffineTransform rotate = AffineTransform.getRotateInstance(-Math.toRadians(getPart().getRotation()), pos.getX(), pos.getY()); ((Graphics2D)g).setTransform(rotate); g.drawImage(character, imgX, imgY, w, h, null); ((Graphics2D)g).setTransform(orig); } |
For textured boxes (yes, I know this code is messy and unoptimized... but it works faster than the much simpler code for drawing a character!) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| public void setTexture(BufferedImage t) { if(t != null) { VolatileImage i = Util.getGraphicsConfiguration().createCompatibleVolatileImage(t.getWidth(), t.getHeight(), Transparency.TRANSLUCENT); Graphics2D g2 = (Graphics2D) i.getGraphics(); Composite old = g2.getComposite(); g2.setColor(transparent); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OUT)); g2.fillRect(0, 0, t.getWidth(), t.getHeight()); g2.setComposite(old); g2.drawImage(t, 0, 0, null); texture = i; } else texture = null; }
[...]
Graphics2D g2 = (Graphics2D) g; Vec2D worldPos = new Vec2D(body.getPosition()); Vec2D imgPos = worldPos.add(new Vec2D(-getVec2DProp("Size").getX(), getVec2DProp("Size").getY()).mul(0.5)).worldToScreen(Main.getView()); Vec2D rotateCenter = worldPos.worldToScreen(Main.getView()); AffineTransform original = g2.getTransform(); AffineTransform scale = AffineTransform.getScaleInstance(scaleDimensionForScreen(texture.getWidth(), getVec2DProp("Size").getX()), scaleDimensionForScreen(texture.getHeight(), getVec2DProp("Size").getY())); AffineTransform rotate = AffineTransform.getRotateInstance(-body.getAngle(), rotateCenter.getX(), rotateCenter.getY()); g2.setTransform(rotate); g2.transform(scale); g2.drawImage(texture, (int) (imgPos.getX() / ((Main.getView().scaleFactor * getVec2DProp("Size").getX())/texture.getWidth())), (int) (imgPos.getY() / ((Main.getView().scaleFactor * getVec2DProp("Size").getY())/texture.getHeight())), null); g2.setTransform(original); |
Does anyone see a problem?
|
|
|
|
|
14
|
Game Development / Newbie & Debugging Questions / Re: What's wrong with this JNLP file?
|
on: 2011-01-14 01:37:49
|
Figured it out--I recently added a script to stop other websites from hotlinking the game file. However, I accidentally blocked blank referers too, and some firewalls strip all referers from HTTP requests.
Why hotlinking the game file is a problem for you? Personally I don't like the websites that used hot links to the JARs because it is silly (it does not work, my game requires several JARs and some native libraries) but hotlinking the JNLP file is not a problem. Maybe you'd like people to get to your website to launch your game. I'm making a tool that allows users to create games and share them on the website. The .jnlp file tells the game to do different things depending on what parameters you give to it. In this case a software web site just linked to the file without any parameters, which would cause anybody that clicked the link to see the game editor and not have any idea what to do or what they could make with it.
|
|
|
|
|
16
|
Game Development / Newbie & Debugging Questions / What's wrong with this JNLP file?
|
on: 2011-01-02 03:32:19
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| <?xml version="1.0" encoding="UTF-8" standalone="no"?> <jnlp codebase="http://buildism.net/game" href="play.jnlp" spec="1.0+"> <information> <title>Buildism</title> <vendor>Jacob Morgan</vendor> <homepage href="http://buildism.net"/> <description>Buildism</description> <description kind="short">Buildism</description> <icon href="http://buildism.net/buildismicon.png" kind="default"/> </information> <security> <all-permissions/> </security> <resources> <j2se java-vm-args="-Xms512m -Xmx1024m" version="1.5+"/> <jar eager="true" href="Buildism.jar" main="true"/> <jar href="lib/swing-layout-1.0.4.jar"/> <jar href="lib/jsyntaxpane.jar"/> </resources> <application-desc main-class="net.buildism.Main"> <argument>1</argument> <argument>Jacob_</argument> <argument>[...]</argument> <argument>play</argument> <argument>false</argument> <argument>http: </application-desc> </jnlp> |
I've tested it with Java 1.6/Windows and Java 1.5/Mac OS X without any trouble, but some users are reporting errors-namely, a syntax error on line 20 and a required field missing. Anyone spot the problem?
|
|
|
|
|
17
|
Games Center / WIP games, tools & toy projects / Game Creation Tool/Virtual World in Java (alpha)
|
on: 2010-12-18 22:07:27
|
This is my current project:  It's a community where you can build your own game in the editor and share it online--complete with physics and Lua scripting! I posted a game similar to this several months ago, but that one didn't work out--some of the code was written over a year ago, when I didn't really know what I was doing. So after distracting myself with some other projects for a while, I decided to start over from scratch a few months ago. I've already added quite a lot of features, but there's still work to be done--namely, online multiplayer. You can try it yourself here.
|
|
|
|
|
19
|
Game Development / Newbie & Debugging Questions / What's wrong with this isometric rendering code?
|
on: 2010-11-02 22:03:16
|
This is supposed to draw a heightmap to the screen using isometric 3D (has not yet been optimized). 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| public class IsometricRenderer { private int scaleFactor = 10; private double xOrigin = 0; private double yOrigin = 0; private final double angle = 0.46365; private final double a = Math.cos(angle); private final double b = Math.sin(angle); private int worldXToScreenX(double x, double y, double z) { int xC = (int) Math.round((x * scaleFactor - z * scaleFactor) * a); int xS = (int) Math.round(xC + xOrigin * scaleFactor); return xS; } private int worldYToScreenY(double x, double y, double z) { int yC = (int) Math.round((x * scaleFactor + z * scaleFactor) * b + y * scaleFactor); int yS = (int) Math.round(-yC + yOrigin * scaleFactor); return yS; } public double getScaleFactor() { return scaleFactor; } public void translateCam(double tx, double ty) { xOrigin += tx; yOrigin += ty; } public void setCam(double x, double y) { xOrigin = x; yOrigin = y; } private Point getScreenPoint(double x, double y, double z) { return new Point(worldXToScreenX(x, y, z), worldYToScreenY(x, y, z)); } public void drawWorld(World w, Graphics2D g2) { for(int x = 0; x < w.width; x ++) { for(int z = 0; z < w.height; z ++) { int h = w.heightmap[x][z]; Point p = getScreenPoint(x, h, z);
int rightX = x + 1; int frontZ = z - 1; if(x >= w.width - 1) rightX = x; if(frontZ < 0) frontZ = z; Point right = getScreenPoint(x + 1, w.heightmap[rightX][z], z); Point front = getScreenPoint(x, w.heightmap[x][frontZ], z - 1); Point frontRight = getScreenPoint(x, w.heightmap[rightX][frontZ], z - 1);
g2.setColor(Color.gray); g2.drawLine(p.x, p.y, front.x, front.y); g2.drawLine(p.x, p.y, right.x, right.y); } } } } |
It works almost perfectly, but the lines are uneven:  Anyone spot the problem? According to some stuff I read online, the angle I used is supposed to make pretty lines.
|
|
|
|
|
22
|
Game Development / Newbie & Debugging Questions / Re: Converting AWT key codes to characters
|
on: 2010-10-19 22:05:36
|
What about KeyEvent.getKeyText(int keyCode)
But for symbols that returns stuff like "Equals" and "Left Bracket"; I need the actual character. I'm not actually going to display the character, so modifier keys don't matter. The game has Lua scripting so I want to give the user something more friendly than the code to work with. I suppose I could just make an empty hashtable of key codes/characters and add values to it in my key event handler.
|
|
|
|
|
23
|
Games Center / WIP games, tools & toy projects / Re: [WIP] Buildsim
|
on: 2010-10-19 02:54:29
|
I'm working on this again! Since a lot of the old code was written when I was just learning Java, I had to completely dump it and start over, but I think it was worth it. I haven't made a game with this yet, but here is a quick demo: http://buildism.net/game.php?id=28 (you can also click Launch Editor in the top right corner of the page to open the editor) I'd like to have some Mac/Linux testing if possible, so tell me if you use a non-Windows OS.
|
|
|
|
|
28
|
Game Development / Newbie & Debugging Questions / Problem with JTree - Changing the model
|
on: 2010-09-28 23:03:22
|
Last time I had to work with the JTree class, I decided that it was one of the worst parts of Swing, and as of my current project, my mind is unchanged  When the UI is initialized, there are no game objects in the world yet so the tree is empty (constructed using a null root node). So, when the root object is added I need to add a root node for it and update the tree: 1 2 3 4 5 6 7 8 9 10 11 12 13 14
| public void create(final MyTreeNode root) { rootNode = root; model = new MyTreeModel(root); SwingUtilities.invokeLater(new Runnable() { public void run() { setModel(model); model.reload(); model.nodeStructureChanged(root); } }); } |
But, this has no effect--the tree is still blank. I found some stuff about a treeStructureChanged() event in the TreeModelListener, but I couldn't find a way to fire it. How do I change the model?
|
|
|
|
|
29
|
Game Development / Newbie & Debugging Questions / Re: Making a task queue
|
on: 2010-09-28 22:55:01
|
ConcurrentModificationException doesn't necessarily mean it's been changed in another thread - could Runable.run() also be creating extra tasks and trying to insert them onto the queue while you're iterating over it? That was the problem! It wasn't supposed to be doing that, but in the future I might make a copy of the queue and iterate over the copy, rather than the original.
|
|
|
|
|
30
|
Game Development / Newbie & Debugging Questions / Making a task queue
|
on: 2010-09-27 23:00:41
|
In my current project, the game entities can be affected by the main game loop, the AWT thread, and later on, network packets or Lua scripts. To make things simple, I want to make a task queue to ensure that all of the actual changes happen in the main thread. This seems like it should work: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| private static final Vector<Runnable> tasks = new Vector<Runnable>(Settings.MAX_TASKS);
public static void addTask(Runnable r) { synchronized(tasks) { tasks.add(r); } } private static void processTasks() { synchronized(tasks) { Iterator<Runnable> itr = tasks.iterator(); while(itr.hasNext()) { itr.next().run(); itr.remove(); } } } |
It usually works OK, but if I get unlucky I get a ConcurrentModificationException in the processTasks() method when changing something using the GUI. Am I doing the synchronization wrong?
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|