Any specific hints for dress-up games?
by baylor wetzel · in iTorque 2D · 07/19/2009 (8:34 am) · 1 replies
i have an app that works well on the PC but hangs the iPhone. i'm actually having more problems than friends making more complex games - unlike them, i don't have physics, collisions, particles or even movement (right now, i don't even have animation, although that will be eventually added). You've seen a million of them as Flash games - drag the clothes onto the doll. My game is a little more complicated (since there's an audience of dolls to watch) but that's the basic idea
While i don't have a lot of action, i have a lot of clothes, which means a lot of images, all of which need to look nice and which have significant alpha channels (the 4bpp PVRs aren't awful, but they're still unacceptably bad). i also have a lot of layers. Specifically, there are 25 ImageMaps mounted to the doll, one for each allowed type of clothing (and you can potentially see several on top of each other at one time, for example, chest tattoo, bra, see-through shirt, vest, coat, overcoat, necklace and hair)
The version being tested on the iPhone has 6MB in PNGs, of which 1.1MB represents the clothes (32 articles of clothing; does not include thumbnails). At current size, clothes range from 3k-85k as PNGs, with most 10-25k. PVR files are significantly larger. Clothes, taken from the PC game, are 370x434 - obviously we'll be shrinking these (at 128x128, images range from 2k-15k). If we say 5 choices for each layer (5 pants, 5 hair styles, etc.), 25 layers and 8 poses (which require images for each), that's roughly 800 articles of clothing. i've heard either the iPhone has 24MB texture memory or the iPhone has 40MB for code, textures and audio (no dedicated VRAM). If the former is true, that's 30k per article if there's no other graphics (i.e., thumbnails, buttons, backgrounds, audience, splash screens, etc.). My understanding is that PNGs are uncompressed in memory and so take up a lot more room than the disk size but i don't know exact numbers for my art. Regardless, i would think the current version of the game is well under the memory limit (although i have no clue as to how to verify this)
The game loads fine (under the 35 seconds or whatever Apple gives you) but when you press New Game and i load the clothing, the iPhone hangs (works perfectly on the PC version). The load clothes function creates the ImageMaps and sticks them in SimSets (technically, dictionaries i hacked together out of SimSets). Each article of clothing has a "dictionary" with 8 ImageMap entries (one per pose), so those 32 clothes take up roughly 240 SimSet entries, but since i haven't added unique pose images yet, the 8 entries all point to the same ImageMap (object ID?), so i assume it only takes up 1 int of memory
Brett has made several posts that, the way i read them, sound like iTGB developers should give up on TorqueScript and write everything (or at least a significant part) in C++. i see where that would help for processor-intensive stuff, but for this particular game, where nothing happens except in response to button clicks (and then only swaps images), i don't see where changing to C++ would help (although using real dictionaries would be nice :) )
i'm currently using a button behavior. When i trace (with TGB's trace(true) command), i see that behaviors (every button) run onUpdate, which sounds expensive (especially given that a button doesn't do anything until you click on it), so i'll probably toss all the behaviors
Drawing 25 layers on top of each other, with the top ones potentially blocking the bottom ones (coats partially covering shirts), feels wasteful but i don't see a better way to do that
PVRs don't look like they'll work. We've cut a lot of clothes (and thus images), but since that's the key to a dress-up game, there's a limit to how many of those we can cut
My biggest problem right now is trying to figure out why the game always crashes the iPhone (6 weeks and it's NEVER run on an iPhone past New Game) despite running perfectly in TGB (and sometimes in iTGB; the same code will run a couple of times then blue screen my laptop, leaving no useful crash info in the console.log; it sounds like that might be specific to my PC, which is why i have other people on their PCs push the game to the phone). i have yet to figure out how to debug something that works locally but not on the phone
But once (if) i get past that, anyone have any advice on what types of optimizations might work for this kind of game?
While i don't have a lot of action, i have a lot of clothes, which means a lot of images, all of which need to look nice and which have significant alpha channels (the 4bpp PVRs aren't awful, but they're still unacceptably bad). i also have a lot of layers. Specifically, there are 25 ImageMaps mounted to the doll, one for each allowed type of clothing (and you can potentially see several on top of each other at one time, for example, chest tattoo, bra, see-through shirt, vest, coat, overcoat, necklace and hair)
The version being tested on the iPhone has 6MB in PNGs, of which 1.1MB represents the clothes (32 articles of clothing; does not include thumbnails). At current size, clothes range from 3k-85k as PNGs, with most 10-25k. PVR files are significantly larger. Clothes, taken from the PC game, are 370x434 - obviously we'll be shrinking these (at 128x128, images range from 2k-15k). If we say 5 choices for each layer (5 pants, 5 hair styles, etc.), 25 layers and 8 poses (which require images for each), that's roughly 800 articles of clothing. i've heard either the iPhone has 24MB texture memory or the iPhone has 40MB for code, textures and audio (no dedicated VRAM). If the former is true, that's 30k per article if there's no other graphics (i.e., thumbnails, buttons, backgrounds, audience, splash screens, etc.). My understanding is that PNGs are uncompressed in memory and so take up a lot more room than the disk size but i don't know exact numbers for my art. Regardless, i would think the current version of the game is well under the memory limit (although i have no clue as to how to verify this)
The game loads fine (under the 35 seconds or whatever Apple gives you) but when you press New Game and i load the clothing, the iPhone hangs (works perfectly on the PC version). The load clothes function creates the ImageMaps and sticks them in SimSets (technically, dictionaries i hacked together out of SimSets). Each article of clothing has a "dictionary" with 8 ImageMap entries (one per pose), so those 32 clothes take up roughly 240 SimSet entries, but since i haven't added unique pose images yet, the 8 entries all point to the same ImageMap (object ID?), so i assume it only takes up 1 int of memory
Brett has made several posts that, the way i read them, sound like iTGB developers should give up on TorqueScript and write everything (or at least a significant part) in C++. i see where that would help for processor-intensive stuff, but for this particular game, where nothing happens except in response to button clicks (and then only swaps images), i don't see where changing to C++ would help (although using real dictionaries would be nice :) )
i'm currently using a button behavior. When i trace (with TGB's trace(true) command), i see that behaviors (every button) run onUpdate, which sounds expensive (especially given that a button doesn't do anything until you click on it), so i'll probably toss all the behaviors
Drawing 25 layers on top of each other, with the top ones potentially blocking the bottom ones (coats partially covering shirts), feels wasteful but i don't see a better way to do that
PVRs don't look like they'll work. We've cut a lot of clothes (and thus images), but since that's the key to a dress-up game, there's a limit to how many of those we can cut
My biggest problem right now is trying to figure out why the game always crashes the iPhone (6 weeks and it's NEVER run on an iPhone past New Game) despite running perfectly in TGB (and sometimes in iTGB; the same code will run a couple of times then blue screen my laptop, leaving no useful crash info in the console.log; it sounds like that might be specific to my PC, which is why i have other people on their PCs push the game to the phone). i have yet to figure out how to debug something that works locally but not on the phone
But once (if) i get past that, anyone have any advice on what types of optimizations might work for this kind of game?
About the author
#2
Our characters have to be large to see the expressions. In testing, it looks like we can fit 3 high and 5 wide, so roughly 100 pixels high. TGB can scale images up, so i think we'd be fine with good quality 64x64 images and sizing the t2dStaticSprite larger. i'll try that
You're correct, i don't need all 800 loaded concurrently. If we have 8 poses for 100 items, on the dress-up screen you see all the clothes but only in the default pose and on the runway screen you see the poses but only for the items being worn (max=25). So it sounds like i need to write a decent asset/memory manager for my game. If the "hard drive" is flash RAM, re-loading images as needed hopefully won't be too bad
This is perhaps a separate question but...
1. How does one force TGB to free the memory used by an image?
2. Is there a way to view memory usage?
If so, is there a way to view VRAM (max 24M?) and general (max 35?) memory separately?
1. How does one, from script, unload an image? In the loading code, i've set preload=false and allowUnload=true but presumably that just lets the TGB memory manager flush memory, it doesn't mean it will. Is there a way to force (or strongly suggest) that TGB release the memory from an image?
2.Is there a way to monitor my memory usage? Maybe a call i can make and show it like a frame counter on the app (or, on the PC, log after loading each image) so i can see when i'm approaching danger territory?
07/19/2009 (2:11 pm)
Thanks for the method of calculating memory usage. i feel a lot better when i have hard numbers available to me :) Based on your numbers, maybe memory really is what's killing me right now (hurray problems under my control!)Our characters have to be large to see the expressions. In testing, it looks like we can fit 3 high and 5 wide, so roughly 100 pixels high. TGB can scale images up, so i think we'd be fine with good quality 64x64 images and sizing the t2dStaticSprite larger. i'll try that
You're correct, i don't need all 800 loaded concurrently. If we have 8 poses for 100 items, on the dress-up screen you see all the clothes but only in the default pose and on the runway screen you see the poses but only for the items being worn (max=25). So it sounds like i need to write a decent asset/memory manager for my game. If the "hard drive" is flash RAM, re-loading images as needed hopefully won't be too bad
This is perhaps a separate question but...
1. How does one force TGB to free the memory used by an image?
2. Is there a way to view memory usage?
If so, is there a way to view VRAM (max 24M?) and general (max 35?) memory separately?
1. How does one, from script, unload an image? In the loading code, i've set preload=false and allowUnload=true but presumably that just lets the TGB memory manager flush memory, it doesn't mean it will. Is there a way to force (or strongly suggest) that TGB release the memory from an image?
2.Is there a way to monitor my memory usage? Maybe a call i can make and show it like a frame counter on the app (or, on the PC, log after loading each image) so i can see when i'm approaching danger territory?
Torque Owner Bret Patterson
512 * 512 * 4 = 1 megabyte of iphone memory for each one you load. You can use that image on the screen as many time as you want without using much more memory, but you can only load about 16 to 20 of those size images into memory.
If you did 256x256 you can load 4 times as many images into memory, and if you did 128x128 you could load 16 times as many images into memory.
For what your doing it's likely the graphics need to be optimized to the right sizes. The size of the PNG file has nothing to do with the memory it uses, because that's the compressed size.
If you want 800 pieces loaded into memory, all at the same time, and you want to use PNG then you will only be able to use 64x64 images and still fit into memory.
In reality you will never have all 800 loaded at once and on the screen, so your best bet is to load and unload the images as they are selected and put on the doll. When you show the selection images load a small icon version of the image and then when they select it load the full sized version.
For what your doing you don't need c++, script is perfect.