Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Get Image VS Load Image

Author
Message
D a r k
20
Years of Service
User Offline
Joined: 21st Jun 2004
Location: In ur fridge, eatin ur foodz.
Posted: 31st Oct 2007 08:34
I'm working on a 2D map editor. In the editor I load each tile as an image and paste that image onto the grid space selected. The grid size is 30x25, making it 750 images on screen for a filled map. As you can guess, loading time is horific. I decided that a better way to approach this would be to use the GET IMAGE command instead of the LOAD IMAGE command. That way I can load a single .bmp and rip the tile images off of that. My question is, would this decrease the loading time. Or would it take just as much time to GET IMAGE as it would to LOAD IMAGE (Assuming I'm not going in and out of directory's each time when using LOAD IMAGE). I figured that GET IMAGE would be faster because im technically just loading one single .bmp. However, there will still be 750 images on screen at one time (Which isn't a problem as far as I can tell, the only problem is when you first load them it takes forever.)

With this current problem, loading a single 30x25 map takes 1-3 minutes.

If anyone knows of any other way to do this then let me know. And sprites won't work, that would make it 10x worse.
demons breath
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 31st Oct 2007 10:23
I think it would be quicker to load bitmap, then use get image. Then I'd create a NEW bitmap to copy all the images to in the tile shapes you want, and keep updating that and copying it to the screen, as it takes forever to draw to the screen compared to a hidden bitmap...

D a r k
20
Years of Service
User Offline
Joined: 21st Jun 2004
Location: In ur fridge, eatin ur foodz.
Posted: 31st Oct 2007 18:24
Your post was a little confusing.

So your saying GET IMAGE would be faster?

I have 50 tiles on a single bitmap. And I should just rip tiles from that bitmap using GET IMAGE.

Anyone know of another way?
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 31st Oct 2007 21:12
@Dark

One thing to note, file operations are considerably faster if you have enabled SYNC ON sometime before the file operation. I made a file parser that took about 3 minutes without SYNC ON and it reduced to about 2 seconds with SYNC ON.

Ultimately the method you choose would depend on a few things. For instance, how big is a single file? When you say 750 tiles - do you mean there are 750 possible images (actual individual pictures - 1 tree, 1 dog, 1 house, etc), thus 750 files of different pictures? Or are there say 32 different pictures someone could use on a map that can be 750 tiles? If there are 750 individual pictures, then loading them all into memory at any given time could affect performance and depending on the size of an individual picture, might eat up the available video memory.

Whatever the case, one thing you want to avoid is repeating the loading of an image. If you have an image of sand that appears 30 times on the map to show a beach, you don't want to load sand 30 times. Instead, you load sand once and you use an index (an array)to a tile on your map to paste the image of sand.

If you absolutely have to load all 750 images at once, a very fast method is to store all of the images in a memblock or a few memblocks and save those memblocks as files. The memblock files are what you will load your images from. The actual saving the images to the memblock is something you do outside of the editor. For the editor you are only interested in using those memblock files - understand? Creating the memblocks is prep work. When the editor runs, it doesn't have to create the memblocks - it uses memblock files you created previously.

I was able to place 750 256x256x32 pictures into a single memblock. The file was around 200 megabytes though. However, I tested loading it and it loaded in about 1 sec. If you used this method you might want to use more memblocks of grouped files and only load what you need so you keep memory usage down.

Assuming all of the original image files are the same size, then each image would be in a relative position inside the memblock. So if each image took up 100 bytes in a memblock, then every 100 bytes would be the location of an image. You would go to that position, copy the bytes to another memblock, then make an image from the new memblock.

assuming memblock 1 has all of the image files in it:



If you have converted as many images as you need, there's no reason to keep the memblock(s) around so you can delete them and free up memory.

delete memblock 1
delete memblock 2

Enjoy your day.

Login to post a reply

Server time is: 2025-05-31 21:15:34
Your offset time is: 2025-05-31 21:15:34