Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (546)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  How to load a lot of images or spritesheets efficiently?  (Read 2624 times)
0 Members and 1 Guest are viewing this topic.
Offline vspin

Junior Newbie





« Posted 2012-07-02 03:21:47 »

I am recreating an old game that was created in the late 90's (I've received permission to use the game images). The game has about 6000 100x100 images, which are mostly character frames for animation. The game (C++) was able to load the images and keep memory usage for the entire game around 50,000K. I know that the original game stored all the bitmaps in a special MultiBitMap format.

I am willing to change the images' format to any format. I just want to get memory usage down significantly. I tried creating 15 (2048x2048, with transparency)  PNG spritesheets, and then loading them using the Slick 2D game library, however, memory usage went through the roof. I thought about making smaller spritesheets, and loading just the sheets I need for the scene, however, it's possible the a single scene would need all the spritesheets loaded to render the scene. I am even considering the DDS file format..

Any suggestions?


Thank you
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2012-07-02 03:38:04 »

My understanding is that Slick2D creates multiple copies of the image data. If you're only using Slick2D for the texture loading, you might want to write your own texture loading code, that doesn't make any copies and doesn't keep it all in RAM, after it has been sent to the GPU.



BTW: 6000 x 100x100 PNG = 6000 x 100x100x4 = 240000000 bytes (228MB)


Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline vspin

Junior Newbie





« Reply #2 - Posted 2012-07-02 05:20:15 »

I'll give that a try. Thank you for your help.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline vspin

Junior Newbie





« Reply #3 - Posted 2012-07-02 13:21:19 »

I found a great solution for myself!

I just used java.awt.Image (ImageIO.read) and created a class to store every tile information (6000 of them) with a cache expiration time property, Image property, etc. When a file needs to be drawn, it checks if it's loaded, if not, it loads it. Then it updates the cache expire time plus one second, and finally draws. At the end of every scene, I expire unused tiles. My memory use is at 40,000K and my CPU is VERY low too. This works great for me, but I bet it wouldn't work in a lot of other situations.
Offline delt0r

JGO Knight


Medals: 27
Exp: 18 years


Computers can do that?


« Reply #4 - Posted 2012-07-02 14:20:08 »

There are some very efficient loaders in TWL and exist as an independent package if you need it. They load png and jpg directly into a byte buffer.

I have no special talents. I am only passionately curious.--Albert Einstein
Offline vspin

Junior Newbie





« Reply #5 - Posted 2012-07-02 21:00:36 »

Thank you. I'm going to look into it right now.
Offline davedes
« Reply #6 - Posted 2012-07-03 03:06:31 »

ImageIO is an OK solution if you just want something quick and easy. For better efficiency, here is what I would recommend:

  • Determine a way to only store what sprites are necessary in memory. This might involve extending Image with custom timers and an "expiration time." Or this may be "zone-based" (i.e. if the player exits the snow level, you can destroy the snow tiles..).
  • Allocate some empty textures -- how many depends on how much memory you want to allot to texture data, and how many sprites will be needed in memory at once. (Sounds effects also tend to take up a lot of memory.)
  • When the textures are needed (e.g. user enters snow level) then decode the sprite using PNGDecoder (or another of Matthias' decoders) and upload the byte buffer to one of your textures using glTexSubImage2D or a utility like this (note: if you use my PixelData utility, you'll want to add your own methods to deal more directly with the byte buffer).
  • Ideally threading would be used to load data in the background, as to not hog the CPU
This technique has the downside of being rather complicated. Truth is, your game probably doesn't require a very complex system like this. Most games that require thousands of sprites do not require them all to be rendered at the same time, and so it would be better to design a simple loading/unloading system based on levels or zones. You can use Image() to load the image, and destroy() to unload the image. Or you can just stick to ImageIO, which seems to be working for your needs. Smiley

Offline vspin

Junior Newbie





« Reply #7 - Posted 2012-07-03 04:56:28 »

Wonderful suggestions. Smiley

My game has no levels. Nearly all my sprites are apart of character animations. I removed a signification amount of sprites, which I didn't really need. I went from about 6000 to 3600. Everything is rendering smoothly.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (20 views)
2014-08-19 09:29:53

Tekkerue (21 views)
2014-08-16 06:45:27

Tekkerue (21 views)
2014-08-16 06:22:17

Tekkerue (12 views)
2014-08-16 06:20:21

Tekkerue (19 views)
2014-08-16 06:12:11

Rayexar (55 views)
2014-08-11 02:49:23

BurntPizza (37 views)
2014-08-09 21:09:32

BurntPizza (27 views)
2014-08-08 02:01:56

Norakomi (35 views)
2014-08-06 19:49:38

BurntPizza (64 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!