Game programming -- Java performance?

L

Luc The Perverse

Twisted said:
On decent hardware, would a platform game (think SNES console games,
tile graphics, but 1024x768x32bpp) run at a decent rate if implemented
in Java?

Yes sprite games do quite well. You need pretty good hardware though.

http://goldenstudios.or.id/products/GTGE/ (Right now the website is down
because they exceeded bandwidth - I don't know when it will be back up,
sorry.)
 
T

Twisted

On decent hardware, would a platform game (think SNES console games,
tile graphics, but 1024x768x32bpp) run at a decent rate if implemented
in Java?
 
J

Johnny Storm

Twisted said:
On decent hardware, would a platform game (think SNES console games,
tile graphics, but 1024x768x32bpp) run at a decent rate if implemented
in Java?

Yes, it seems possible. People have even been able to run a Quake II engine
in Java with pretty good performance.


Johnny
 
T

Twisted

Started coding a tile/sprite engine. Figuring memory/GC performance
will be important, so a lot of the objects, though serializable, hold
references to one another as a) indices, names, or other things and b)
"transient" object references that need to be initialized by calling a
load() method on the deserialized object. That way, loading one segment
of one level won't load all of the game data recursively into ram. :)
Loaded resources are cached with SoftReferences and retrieved with a
factory object that retrieves the cached object if possible, and if
null (either never loaded this session, or GC'd) goes to the hdd for
the files. Likewise, actual image data (png files) are loaded only
later, into BufferedImage objects. (java.awt.Image objects are
reportedly not portable across hardware architectures anyway -- never
mind PC to Mac, even PC to PC may corrupt if the video hardware differs
it seems); besides, I want to create art in a proper paint app, not
write a paint app as part of making the level editor. :)

I'll post performance results here once I have any. So far I have some
infrastructure and that's it.

Murphy's Laws of java programming:
1. There's always an exception to every rule, especially the
conventions about name
capitalization:
* All methods and member variables in the Java API begin with
lowercase letters.
* Likewise, class names and constants begin with uppercase ones.
* All use capitalization where a new word begins e.g -
getDoubleValue().
* Except, of course, for Character.isWhitespace (not isWhiteSpace).
:p
2. There's always an exception you didn't think to catch.
3. After all the debugging and recompiling, there's always a
RuntimeException you
didn't think to catch.
4. And another. And another... And the API docs don't even declare
most of them.
(Some of the URL and URLConnection methods throw
StringIndexOutOfBoundsExceptions -- why?! Who knows!!)
5. The surest way to ensure a line of code is reached early in program
execution on
the first run attempt is to preface it with "// Can't happen."
6. Usually it's "throw new Error();" of course.
7. Whatever the participants in the ongoing debate about reference
size may think,
the actual empirically-determined size of a Java reference is about
3 megabytes.
8. If the process size is under 50MB, something has gone horribly
wrong with your
program and it actually isn't loading any data or doing anything.
9. If the app seems to have hung and you're sure it's an infinite loop
it will turn out just
to be slow. If you think it's merely slow and leave it running
overnight, it will be dead
by morning and the debugger used on a subsequent run will show you
two
suspended threads, surely in a deadlock. If on the other hand you
suspect
deadlocking and implement a very involved system of deterministic
symmetry-breaking in determining resource locking order, complete
with more
debugging, it will turn out that a loop in a completely unrelated
part of the program
never met its termination condition.
10. And, of course, it is probably a while (true) loop in which you
simply forgot to insert
a break, throw, or return statement, rather than some complex
situation involving
circular object graphs that even a reasonably intelligent
programmer might be
expected to miss.

(Speaking of deterministic symmetry breaking, it would be nice if Java
had a "synchronized(x, y, z, ...) { foo }" syntax that locked the
listed resources in a fixed order -- unspecified and legally considered
"JVM implementation dependent" but almost invariably simply in
ascending order of their machine address pointers, compared as
integers...)
 
O

Oliver Wong

Twisted said:
Started coding a tile/sprite engine. Figuring memory/GC performance
will be important, so a lot of the objects, though serializable, hold
references to one another as a) indices, names, or other things and b)
"transient" object references that need to be initialized by calling a
load() method on the deserialized object. That way, loading one segment
of one level won't load all of the game data recursively into ram. :)
Loaded resources are cached with SoftReferences and retrieved with a
factory object that retrieves the cached object if possible, and if
null (either never loaded this session, or GC'd) goes to the hdd for
the files. Likewise, actual image data (png files) are loaded only
later, into BufferedImage objects. (java.awt.Image objects are
reportedly not portable across hardware architectures anyway -- never
mind PC to Mac, even PC to PC may corrupt if the video hardware differs
it seems); besides, I want to create art in a proper paint app, not
write a paint app as part of making the level editor. :)

Nice, what kind of game is it? I had interest in making SNES-level games
in Java too. My last project is sort of on permanent-hold though... It's an
RPG, about at the Chrono Trigger level of complexity.
I'll post performance results here once I have any. So far I have some
infrastructure and that's it.

Murphy's Laws of java programming:
1. There's always an exception to every rule, especially the
conventions about name
capitalization:
* All methods and member variables in the Java API begin with
lowercase letters.
* Likewise, class names and constants begin with uppercase ones.
* All use capitalization where a new word begins e.g -
getDoubleValue().
* Except, of course, for Character.isWhitespace (not isWhiteSpace).
:p

"Whitespace" might be considered one single word, and not two words
appended together.
2. There's always an exception you didn't think to catch.

Different people have different philosophies about exceptions. In mine,
you should generally only catch checked exceptions, so you can't ever
"forget" to catch them; the compiler will give an error if you do.
3. After all the debugging and recompiling, there's always a
RuntimeException you
didn't think to catch.

As per my comment to #2, don't catch Runtime Exceptions at all.
4. And another. And another... And the API docs don't even declare
most of them.
(Some of the URL and URLConnection methods throw
StringIndexOutOfBoundsExceptions -- why?! Who knows!!)

Haha, well, you should probably try to find out why (perhaps step
through with a debugger, or look at the source code?)
5. The surest way to ensure a line of code is reached early in program
execution on
the first run attempt is to preface it with "// Can't happen."

Have you been using the "assert" keyword?
6. Usually it's "throw new Error();" of course.
7. Whatever the participants in the ongoing debate about reference
size may think,
the actual empirically-determined size of a Java reference is about
3 megabytes.
8. If the process size is under 50MB, something has gone horribly
wrong with your
program and it actually isn't loading any data or doing anything.
9. If the app seems to have hung and you're sure it's an infinite loop
it will turn out just
to be slow. If you think it's merely slow and leave it running
overnight, it will be dead
by morning and the debugger used on a subsequent run will show you
two
suspended threads, surely in a deadlock. If on the other hand you
suspect
deadlocking and implement a very involved system of deterministic
symmetry-breaking in determining resource locking order, complete
with more
debugging, it will turn out that a loop in a completely unrelated
part of the program
never met its termination condition.
10. And, of course, it is probably a while (true) loop in which you
simply forgot to insert
a break, throw, or return statement, rather than some complex
situation involving
circular object graphs that even a reasonably intelligent
programmer might be
expected to miss.

(Speaking of deterministic symmetry breaking, it would be nice if Java
had a "synchronized(x, y, z, ...) { foo }" syntax that locked the
listed resources in a fixed order -- unspecified and legally considered
"JVM implementation dependent" but almost invariably simply in
ascending order of their machine address pointers, compared as
integers...)

Would it be safe to leave this implementation dependent? Can you
synchronize an object on another JVM (e.g. via RMI or something)?

- Oliver
 
T

Twisted

Game: it's going to be on about the "super metroid" level of
complexity. Yours: sounds like you have your work cut out for you. At
least performance is less critical in a turn-based RPG.

Exceptions: For network apps, it's generally good to have fail-soft
characteristics, i.e. if an exception gets thrown unexpectedly the top
level of the thread will catch it and tell whatever spawned it that it
happened, so the thread can be regenerated or otherwise some kind of
recovery/moving-on can be done. Exceptions thrown from URL methods: er,
what source code? These are standard library functions. When Eclipse
tries to step into them it just complains there is no source code, and
possibly even that it's in a native method, and therefore can't tell me
anything. I hope I'm not expected to license Sun's source code just to
be able to debug my own code? (Last I checked, it's *not* open source,
so presumably this would involve some restrictions, signing up for
spam, signing away my firstborn, paying actual money, or something
similarly onerous?)

Assert keyword -- eh. Java's changed a bit since I last dabbled in it.
Generics are useful, and enums. Assert keyword? Is this documented
anywhere?

Synchronized suggestion -- I imagine that synchronizing
persistent/remote objects is going to present special challenges no
matter what, and probably involve different mechanisms than
synchronizing volatile local objects anyway. There are Java APIs for
file locking, but these are library calls, not built-in primitives of
the nature of "synchronized"; and for remote objects you're probably
looking at CVS-style checkout/checkin systems or even some way to try
to merge parallel changes back in, or to otherwise apply finer
granularities. One method could be to require that remote objects be
"live", i.e. accessed via RMI calls to a JVM that gatekeeps the object,
rather than "dead", i.e. hunks of inert data being passed around over
the network like a red-headed stepchild. The object server would spawn
threads to handle incoming requests, and those threads would then
invoke methods on the object. Some of those methods would be
synchronized.
 
T

Thomas Hawtin

Twisted said:
anything. I hope I'm not expected to license Sun's source code just to
be able to debug my own code? (Last I checked, it's *not* open source,
so presumably this would involve some restrictions, signing up for
spam, signing away my firstborn, paying actual money, or something
similarly onerous?)

The source for most of the public packages is in src.zip within Sun's
JDK. You can get the full source (http://tiger.dev.java.net). No spam
that I'm aware of (perhaps I'm just careful to check/uncheck the right
ticky boxes, although they (apparently Sun) once phoned me in 1998), no
money, but it isn't Open Source.
Assert keyword -- eh. Java's changed a bit since I last dabbled in it.
Generics are useful, and enums. Assert keyword? Is this documented
anywhere?

They are all documented in the Java Language Specification. There's also
Sun's generics tutorial:

http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf
http://72.14.203.104/search?q=cache:FiiQnFUy0CsJ:java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf+

Tom Hawtin
 
C

Chris Smith

Twisted said:
I hope I'm not expected to license Sun's source code just to
be able to debug my own code? (Last I checked, it's *not* open source,
so presumably this would involve some restrictions, signing up for
spam, signing away my firstborn, paying actual money, or something
similarly onerous?)

The only additional restriction added by Sun's license have to do with
redistribution... specifically, you may not redistribute the Java source
code unless you license (at some considerable cost) a copy of the
compatibility toolkit and verify that it complies with all aspects of
the Java language and platform. This is intended to prevent anyone from
creating non-portable pseudo-Javas and causing them to become in
widespread use.

If you just want to use the Java source code for debugging, then just
extract src.zip and tell the Eclipse debugger where to find it. For
native code, you will need to jump through more hoops... but that's not
necessary unless you want to actually do something like modify the VM.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
O

Oliver Wong

Thomas Hawtin said:

In summary, you type in something like this:

<example>
assert x != 0 : "X should not have been zero.";
x = 1.0 / x;
</example>

And if the boolean expression after the assert keyword is false, an
AssertionException is thrown with the provided message (which is optional,
so you could have wrote "assert x != 0;" instead).

Pass the "-ea" command line argument to the VM to enable assertions. The
default is to not check assertions at all.

Also, if assertions are NOT enabled, then the expressions are not
evaluated at all, so make sure your expressions don't have any side effects,
unless you want your program to behave differently depending on whether
assertions are enabled or not (this is generally a bad idea).

- Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top