Author Topic: Preloading Objects  (Read 18310 times)

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Preloading Objects
« on: 2007-12-19, 02:47:47 PM »
dunno if its only my slow computer or if the animations i am using are too big, but maybe preloading them may help. any chance to do this and how? (searched the help for "preload", found nothing)
and should i use "unloadMap" after "ClearOverlay" to remove the map from the RAM?
« Last Edit: 2007-12-19, 02:59:19 PM by Morgengrauen »

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Preloading Objects
« Reply #1 on: 2007-12-19, 06:11:37 PM »
Where are you seeing slowness?  Once the game is running, all the graphics should be stored in video memory (if I understand how DirectX works).  If your game is slow starting up, it might be because it is generating alpha masks.  If you have a large sprite with lots of states and frames, it can take a while to generate an alpha mask for each frame of each state because it has to look at each individual pixel for each transformed frame of each state in system RAM.

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: Preloading Objects
« Reply #2 on: 2007-12-19, 06:25:04 PM »
when the player touches a plan rectangle, a new map "snowstorm" is set overlay.
this map has three layers, each filled (1 tile, virtual size: 10;10) with one tile that holds an animation. these animations consist of about 48 single images (128x128). the graphic sheet for that is a png, and i use a lot of transparency.
so, when the player touches the rectangle, all movements freeze for about a second, and then the animation is played. that is the "problem".

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Preloading Objects
« Reply #3 on: 2007-12-19, 06:36:14 PM »
Does that happen every time the player touches a snowstorm tile or only the first time?

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: Preloading Objects
« Reply #4 on: 2007-12-19, 06:38:37 PM »
only the first time, when he touches the plan. i could try next time to trigger the storm several times, atm it happens only once in the game. see if it pauses then.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Preloading Objects
« Reply #5 on: 2007-12-19, 07:23:50 PM »
I guess I wasn't entirely accurate when I said all graphics were loaded into video memory.  Only the graphics for the current map(s) are loaded.  If you look at Display.cs you can see a property named "Texture" in a class named TextureRef, which calls a function named GetTexture only if the texture has not already been loaded and cached.  In order to pre-load the graphics, you would have to call GetTexture on the graphics that you want to load.

The reason they aren't being loaded is because SGDK2 has no idea that you are going to load this other overlay map.  If you can do anything to force it to load those graphics, it would work.  Put a sprite that contains a graphic from that graphic sheet somewhere on the map or set the overlay and clear it really quickly at the beginning.  Normally all graphics for a map are loaded, but since the overlay is a whole separate map, SGDK2 did not know you were going to be using the graphics from that map.  There are many ways to deal with this.  Not sure which you would prefer.

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: Preloading Objects
« Reply #6 on: 2007-12-20, 05:29:09 AM »
hm, i took a few tiles from the snowstorm graphic sheet and put them into my ground frameset. then i have put these tiles an one of my layers which are played. but it didn't worked properly, there is still a huge pause when starting the animation.
maybe there is another reason for this. hit me when i did unnecessary work, but i have created three tilesets, one for every snowstorm layer. at every tileset, the base is the snowstorm graphic sheet, but only one tile is animated. and the layers are filled with just this one animated tile.
(i know i need only one tileset for the three animated tiles, but so it is easier to keep the overview for me)

so, the snowstorm graphic sheet is supposed to be in the memory now, but maybe it is not storing the animations properly?
maybe i need to merge the ground and the snowstorm tiles to one frameset, and create the animations in it. (or i try the GetTexture feature you mentioned).

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Preloading Objects
« Reply #7 on: 2007-12-20, 07:09:39 AM »
??? I don't know why that wouldn't fix it.  Maybe like you say the pause is coming from somewhere else.  If you want to post your project at http://sgdk2.enigmadream.com/support/ I can investigate.  :nerd:

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: Preloading Objects
« Reply #8 on: 2007-12-21, 10:10:07 AM »
this GetTexture works for the graphic sheet, right? but the sheet is supposed to be in the memory already, like i described above. hm, i try something tomorrow.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Preloading Objects
« Reply #9 on: 2007-12-22, 09:47:15 AM »
Maybe the sheet isn't in memory unless you can actually see some tiles from that sheet on the screen.

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: Preloading Objects
« Reply #10 on: 2007-12-23, 04:24:29 AM »
no, the tiles were seen.
this brings me to a new question, which actually a fellow student asked. (but i am not sure if i understand him correctly  :laugh:)
when the map is bigger than my screen, is the whole map stored in my RAM? or is the needed part loaded at runtime when i move around?

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Preloading Objects
« Reply #11 on: 2007-12-23, 07:50:21 AM »
The whole map is stored in RAM, but only the tile numbers, not the graphics.  So if you have 1 million tiles on your layer (1000x1000 tiles), that could be 128000x128000 pixels (if your tiles are 128x128 pixels) = 16 billion pixels.  But if your layer is only 1 byte per tile, then it only takes 1 million bytes (less then 1 MB) of RAM.  Or if you use 2 bytes per tile then its 2 million bytes (under 2 MB) of RAM.  Since most systems have more than 512 MB of RAM today, that's pretty small to keep 16 billion pixels of your map in memory  :surprise:.  (If you have multiple layers, all the tiles for each layer are stored in memory.)

The tiles for the maps that aren't loaded are not kept in RAM (this is why there are unload functions for maps).  But if you have an overlay map for your snow it should be a very small map.  The data for the overlay map only needs to be 1 tile because you want the same tile to cover the whole map, so you should make the layer size 1 tile and make the layer's virtual size big enough to fill the map.  Then the map will only take 1 byte! (Actually it will probably take a little more to keep track of a couple other small things, but only 1 byte for the tiles).  The other benefit of using 1 tile and a large virtual size is that you only have to click once to fill the whole layer with the same tile.

Tanja

  • Clever
  • Fanatic
  • ***
  • Posts: 606
    • View Profile
Re: Preloading Objects
« Reply #12 on: 2007-12-23, 01:01:40 PM »
(If you have multiple layers, all the tiles for each layer are stored in memory.)

you mean tile numbers, here, don't you?
i already use a 1-tile-sized-layer with a virtual size, cool.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Preloading Objects
« Reply #13 on: 2007-12-24, 09:14:08 AM »
(If you have multiple layers, all the tiles for each layer are stored in memory.)
you mean tile numbers, here, don't you?

Yes, I use the terms interchangably, I guess, but I mean the tile numbers.

Jam0864

  • Contributor
  • Fanatic
  • **
  • Posts: 744
    • MSN Messenger - marmalade0864@hotmail.com
    • View Profile
    • Jam0864's Content Dump
    • Email
Re: Preloading Objects
« Reply #14 on: 2007-12-24, 05:53:51 PM »
But if your layer is only 1 byte per tile, then it only takes 1 million bytes (less then 1 MB) of RAM.  Or if you use 2 bytes per tile then its 2 million bytes (under 2 MB) of RAM.
is there an upside to using 2 bytes a tile? it seems at the moment that it is just wasting more RAM. lol