Image loading/holding optimizations

i have quite big problems to get a heap overflow in control.
the reason is the large amount of graphics data (spoken in the dimensions of series40).

its an animated board game so there are no levels or stages where gfx-sets change, so most images are needed at the same time.
the hard problems are the animation-strips for both players:
all frames for one player are stored in one file. the frames are all in one row and packed together as close as possible.
nevertheless one character image has a dimension of 750x22px (x2 for each).
beside the background tiles these big images are the heap killers. i tried to split them into smaller files to load some animations only on demand (e.g. victory pose) but loading an image during game causes some heavy lag. besides the garbage collector often reacts very slow (even called).

any hints or techniques are very welcomed.

I think your only choice is a different set of art for the under powered phones. Essentially a different app. Something with smaller characters and possibly less frames per animation.

Hopefully in doing something like this you could keep a lot of the existing code, but it would still require a heavy port and a splitting of the source.

Wood

sadly, these at currently are the lowe res versions :-/
im doing porting for about 25 phones so code splitting has already happened (though i really, really hate it)

after experimenting a while with memory optimizing i noticed big differences in which order objects get loaded. it seems that heap fragmentation is a serious problem.

to demonstrate my problem:
the game has two splash screens where the resources (bg gfx, the sprites with big animation strips, and some text strings) get loaded. because the heap got an overflow i tried to load some things later, earlier or whatever.

the only time, i got all working (and now i know that it is possible to get the game work with the existing artwork) was to load text and some gfx while displaying splash, enter the main menu and then load via button press(!) first the bg then the sprites ;D

i really thought that it is better to load big memory chunk at the beginning of the midlet, but it seems that im wrong …

One thing I do to limit this is limiting the use of dynamic variables. My games typically have no more than four class files and all my data is stored in arrays. I know it’s arcane, but it does relieve a lot of these problems on underpowered phones.

The classes on my last game were: Main (which included a network thread), Data, Canvas (which included an animation/tick thread), and Menu. I have my own custom menu system because the List class requires a new instance for every menu. I like having one instance and repopulating it and it uses arrays internally.

I have some instances where I have to use strings, I try to limit them as much as possible. I try to keep most strings static final, but there is always the case where you need to concatinate two strings and I typically don’t use +, I create a new StringBuffer, just so I know exactly what is happening, not relying on a translation. That’s typically the only dynamic allocation I allow in my games. Everything else is locked down up front.

[quote] im doing porting for about 25 phones so code splitting has already happened (though i really, really hate it)
[/quote]

This is actually the worst possible development scenario I could possibly imagine and I hate it too. I don’t think Sun really cares though? Conditional compilation (#ifdef) would tend to make life much much easier, but that seems to be taboo to even mention. Sort of like saying the Emperor isn’t wearing any cloths and Java is so portable that conditional compiliation has no place in such a perfect system. That said, I’m sure I could build some sort of Ant system to preprocess the conditional stuff for me, but as I’ve said in earlier posts, I’m lazy and that sort of Ant system would require a ton of work. Especially to get it front ended on WTK which I use for my final builds. Just the thought hurts my brain.

I noticed recently that NetBeans has some sort of code splitting management system to make this easier. Seemed like a sledgehammer to drive a carpet nail that conditional compilation would easily solve.

Wood

[quote]Conditional compilation (#ifdef) would tend to make life much much easier, but that seems to be taboo to even mention. Sort of like saying the Emperor isn’t wearing any cloths and Java is so portable that conditional compiliation has no place in such a perfect system. That said, I’m sure I could build some sort of Ant system to preprocess the conditional stuff for me, but as I’ve said in earlier posts, I’m lazy and that sort of Ant system would require a ton of work.
[/quote]
I gather you haven’t heard of Antenna?

Conditional compilation might be evil, but with J2ME it’s a necessary evil.

shmoove

shudder

In my experience precompilers are often abused, and used in scenarios that they are quite unnecessary.

A good build process, with a complete common source tree, and device specific classes overwriting any necessary classes from common - tends to give a clearer, more portable code base.

i.e.


gamename/
      src/
            common/
                  some.class
                  other.class
                  etc.class
            samsung_d500/  
                  other.class
            sonyericsson_k700i/
                  other.class
                  etc.class

A single source tree, with precompiler statements becomes unwieldy when it has been ported to a large number of handsets (above 10-15 ports the precompiler statements start to count for more lines of code than the game itself does!)

It also adds the risk that making a modification to the code used by 1 port, could potencially break any of the other ports.

Both systems are bad and I was not trying to state what was best. I would personally like to use a precompiler as I think it is much better when you have design changes late in the process. For long term both methods are just plain broken and subject to all sorts of human errors.

Wood

first i have to say that we are using antenna here in comination with a self-writte build system for generic resource management.
looking at the overall dissatisfying j2me development (a good development environment would only patch the bad device implementations) i can really live with preprocessing statements. the big problem with antenna is its lack of (future) features:
i would give my motorola v525 for the use of variables within the statements (no, i wouldnt really … =)

but the game architecture is a much bigger probelem: at first i really tried to hold the number of classes and instances down. but with more incoming protings you really need some generic solutions (tool classes) to keep the development time down.
for example, i cant hardcode every change of textpassages or language porting. so i had to write a class which works hand in hand with the build system, loads the text resource and formats it so that it fits the screen of the actual device.
though you can really save some heap avoid such things i noticed that the monster part goes to loaded graphics.

i cant really trust the memory profiler from nokia but to give a relation, the whole game without gfx needs about 55kb of heap. in difference there comes an overload of 130kb of images…

Hi,

I work for a company building specifically multiplayers j2me and Doja games.
After a lot of experiments (antenna etc…), we found better to use a combinaison of:

  • A in-house ant-task code precompiler (able to use simple logic like “var1 and|or var2”) that comment/uncomment code based on enabled vars.
  • A ressources_by_device directory system.
  • A Custom ant script (preparse-build-dist-push-emul).

All of thems under eclipse directly.
It’s not the best but it allow fast build time (10-20 seconds) and also it push using webdav (common-vfs project ant tasks) to the developpement server.
Finally, we have a shell script on the server that everybody can call to sync dev & prod (rsync based).

The precompiler Ant Task should be released on Sourceforge very soon (project: “Satori”), I hope someone will find it useful.

Was my 2 cents, :slight_smile:

Seb

an antenna precompiler. sounds very interesting. because antenaa does not seem to be updated very often i really would like to change to another system.
please post some notice when your system is available

[quote] because antenaa does not seem to be updated very often i really would like to change to another system.
[/quote]
J2ME Polish gets updated quite often.

shmoove

sure, but polish needs to be licensed for commercial use ;D

Only if you include one of it’s libraries in your application. If you just use it as a build environment I don’t think you need to get a license.

shmoove