Game programming -- Java performance?

Discussion in 'Java' started by Luc The Perverse, Feb 21, 2006.

  1. "Twisted" <> wrote in message
    news:...
    > 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.)

    --
    LTP

    :)
    Luc The Perverse, Feb 21, 2006
    #1
    1. Advertising

  2. Luc The Perverse

    Twisted Guest

    On decent hardware, would a platform game (think SNES console games,
    tile graphics, but 1024x768x32bpp) run at a decent rate if implemented
    in Java?
    Twisted, Feb 26, 2006
    #2
    1. Advertising

  3. Luc The Perverse

    Johnny Storm Guest

    "Twisted" <> wrote in message
    news:...
    > 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
    Johnny Storm, Feb 26, 2006
    #3
  4. Luc The Perverse

    Roedy Green Guest

    On 25 Feb 2006 17:02:20 -0800, "Twisted" <> wrote,
    quoted or indirectly quoted someone who 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?


    see http://mindprod.com/jgloss/image.html#VOLATILEIMAGE

    Try a little experiment. The limiting factor in the animation.

    Also look at http://mindprod.com/jgloss/vrml.html
    Try out a little simulation of your game that exercises the video
    about as much as your game would.

    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
    Roedy Green, Feb 26, 2006
    #4
  5. Luc The Perverse

    Twisted Guest

    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...)
    Twisted, Mar 1, 2006
    #5
  6. Luc The Perverse

    Oliver Wong Guest

    "Twisted" <> wrote in message
    news:...
    > 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
    Oliver Wong, Mar 8, 2006
    #6
  7. Luc The Perverse

    Twisted Guest

    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.
    Twisted, Mar 12, 2006
    #7
  8. Twisted wrote:
    > 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
    --
    Unemployed English Java programmer
    http://jroller.com/page/tackline/
    Thomas Hawtin, Mar 12, 2006
    #8
  9. Luc The Perverse

    Chris Smith Guest

    Twisted <> wrote:
    > 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
    Chris Smith, Mar 12, 2006
    #9
  10. Luc The Perverse

    Oliver Wong Guest

    "Thomas Hawtin" <> wrote in message
    news:44148f4a$0$9272$...
    > Twisted wrote:
    >> 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


    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
    Oliver Wong, Mar 13, 2006
    #10
  11. Luc The Perverse

    Roedy Green Guest

    On 12 Mar 2006 12:47:08 -0800, "Twisted" <> wrote,
    quoted or indirectly quoted someone who said :

    >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?


    for an overview and links to the docs I have found see
    http://mindprod.com/jgloss/assert.html
    http://mindprod.com/jgloss/enum.html
    http://mindprod.com/jgloss/generics.html
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
    Roedy Green, Mar 13, 2006
    #11
  12. Luc The Perverse

    Twisted Guest

    Twisted, Mar 14, 2006
    #12
  13. Luc The Perverse

    Roedy Green Guest

    Roedy Green, Mar 14, 2006
    #13
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. BlackHawke
    Replies:
    12
    Views:
    1,569
    Andrew Thompson
    Jan 26, 2004
  2. judith
    Replies:
    0
    Views:
    1,650
    judith
    Nov 1, 2006
  3. Max Kubierschky
    Replies:
    10
    Views:
    1,846
    pabloreda
    Mar 31, 2007
  4. Advertiser for `2D Games Development Central`

    {Game Development} 2D Game Development Central

    Advertiser for `2D Games Development Central`, May 7, 2008, in forum: Java
    Replies:
    2
    Views:
    413
    RedGrittyBrick
    May 8, 2008
  5. Advertiser for `2D Games Development Central`

    {Game Development} 2D Game Development Central

    Advertiser for `2D Games Development Central`, May 7, 2008, in forum: C++
    Replies:
    0
    Views:
    391
    Advertiser for `2D Games Development Central`
    May 7, 2008
Loading...

Share This Page