sprite loading - performance

Help
lickstab
2009-03-15
2013-06-04
  • lickstab
    lickstab
    2009-03-15

    hello all, i have some questions about the speed of loading a lot of sprites at once..

    i'm working on a little tile-based thing that randomly generates a world every time you run it. however, if there there a lot of tiles, it takes a really really long time to set it up. maybe i'm just doing it wrong.

    as a little test, i chose a ridiculously large world (300x300 tiles, or 90,000 sprites), which took several minutes to generate. there are only 3 unique sprites used (grass, tree, water).

    after actually generating it though, the ingame fps isn't completely awful (~40 fps while not scrolling, so a slightly smaller world should be okay.. maybe.)
    i understand that it can't be done instantly, obviously, but is there any way to speed up sprite loading?

     
    • Gustavo Rangel
      Gustavo Rangel
      2009-03-16

      Question, why do you need 90.000 sprites? I mean, are you displaying all 90k sprites at once?
      Do you know if this project still been monitored by some one. Do you know if there are new releases?
      I stuck in a "frame per second" problem.
      Sorry if I did't answer your question

       
      • lickstab
        lickstab
        2009-03-17

        well, my world consists of that many tiles, and i'm always moving the "camera" around in it, it's like a simulated world.. i'm only displaying 20x15 tiles at once (the screen size).

        maybe i should keep an array which stores the type of tile, and load/unload the tiles that are nearby as i need them?
        i didn't think of that until just now.

        as for new releases or anything, i've no idea. i actually wanted to ask that myself..
        and about setting the fps, i'm afraid i don't know. maybe you should write some code that individually advances the frame for each sprite, with a delay to get the desired fps?

         
    • Gustavo Rangel
      Gustavo Rangel
      2009-03-17

      Infact, you don't need to load all the sprites/tiles. You can load the images that r displaying and unload the rest. Do you use VC++6.0 to develop your app? I would like to start a new project, try to remake the Kyra Sprite Editor and make a new frendly windows editor with map editor and maybe menus editor support. My idea is to integrate some like the app "MAPWIN" and to integrate some sort of bitmap editor.

      About the FPS i release that it's very very dificult.

      As soon as I got some examples I'll let you know, maybe we can share ideas.

       
      • lickstab
        lickstab
        2009-03-17

        well, i fixed it. instead of storing all the sprites, i simply store their name.

        and then, for every game loop, i load the sprites that are "on screen" and unload a couple of surrounding ones (a radius of about 4-5 tiles "off" the screen, far enough so that it doesn't miss any tiles if the camera moves too fast).

        i also realized the real reason it loaded so slowly is because of another function call i was making, which i didn't need.

        now it loads relatively fast (large worlds still take a while though), and while ingame, it runs at a decent 200 fps regardless of world size.

        i can try to make an example to limit the fps on a particular sprite, if you want.

         
    • lickstab
      lickstab
      2009-03-17

      here, i wrote a short program.
      is this what you were looking for, or did you mean something else?

      it doesn't get an EXACT fps, since the ticks value would have to include some decimals, but it's an approximation.

      link:
      http://pastebin.ca/1363212

       
    • lickstab
      lickstab
      2009-03-17

      update:
      oops, i looked at your post, i see that you want a separate fps value for each action. well, i'm sure you can modify it to store one variable for each action.

       
    • Gustavo Rangel
      Gustavo Rangel
      2009-03-17

      Well, i really appreciate that.
      I notice that engine->draw it's launch in order to update all the next sprites->actions and tiles. This method is called using a SDL_Timer.
      Maybe I can create another timer which update the next action frame, but if I do that what happend when engine->draw() is called?

       
    • Gustavo Rangel
      Gustavo Rangel
      2009-03-17

      Ok, that migth do the trick. I get it now, sprite->DoStep() is the one which update the next frame action. I could change it in order to have multiples action fps, but I'll remain with multiple sprites fps.
      Thanks a lot
      Ummmm and another question, do you know where I can find some gravity examples, I'm trying to to a simple platform. So i need to manage sprite jump - (go up - then go down)

       
      • lickstab
        lickstab
        2009-03-17

        hmm, i'm terrible at things like that actually, i always have trouble with it.
        one easy way would be to use a physics library and try to set it up so you can control your character with it, then you'll get collision and "falling" for free, you can "jump" by simply applying an upwards force on your player's physics object.

        that's all probably too much for to explain here though, but i'm sure you can find lots of samples.

        here's one 2d physics engine i know of:
        http://www.box2d.org/

        i haven't used it myself yet, but i plan to some day..

         
        • I did some very simple gravity because I needed some bouncing balls.  I manually used SetPos on the sprite and kept a y and x speed where the y speed was updated for each iteration due to gravity, and negated the y speed when the ground was hit.