Why is this so inefficient?(Random Generation)

0 favourites
  • 6 posts
From the Asset Store
Template for dungeon/maze generation, using wave function collapse
  • Well, I made a terrain generator in C++(I already posted this in a similiar topic). It is a very simple method. I used pseudo cursor(an integer) which is placed half way down the screen and adds a random number to it(like from 5 to 16), then it places the 'block', increases the number by 1, places another block and so on until it reaches the bottom of the screen. Then we add one to the X coordinate and repeats the same process again, and again until it reaches the far right of the screen.

    I tried this in Construct 2 and the first thing I got was just a black screen, then I made it so that, instead of placing the blocks all over the screen, it repeats the actions 80 times and I get 18 FPS. So I want to know why is this so CPU-intensive.

    Also, in my other game I place clouds that are bigger sprites, apply movement and collision detection and the game runs just fine(60 FPS) and it loads in 0.0001 seconds, too.

    Links:

    For the C++ terrain generator:

    Subscribe to Construct videos now

    The other game(Invasion of planet Zork): http://dl.dropboxusercontent.com/u/2670 ... index.html

    EDIT: I can't believe I forgot to put the example!

    Here it is:

    https://dl.dropboxusercontent.com/u/267 ... cency.capx

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hard to answer as you haven't showed how you made it in C2, but might be because you spawn and have to render sprites in C2, and in the C++ you use colors or do you also spawn images there as well?

  • Here is a very simple "map generator", not really but it does fill the screen using a tilemap with 110040 tiles. Which is quite a few. So you could do it like that if you wanted.

  • The problem is the way you have made it, its very ineffective as you spawn images.

    You spawn 6483 objects which puts a lot of pressure on the performance. The image to the right is the performance uses for your program.

    And you have 6 events that checks these objects 60 times a sec, so it actually does approx. 2333880 checks every seconds. Which will kill performance.

    If you compare it to the one I made with the tilemap there are hardly any impact on the CPU, because its considered 1 object, but if you added a lot of checks to each of the tiles in the tilemap you would kill the performance for that one as well.

    But regardless of doing it the way you have or using a tilemap with as many tiles as I have added, I don't think you will find any program that will deliver good performance working with such amount of objects/tiles. So think your are better off redesigning how you map generator works.

  • Thanks a lot for such a detailed reply. I heard of tilemaps, but I never looked into them, but I will now.

  • No problem, you can easily do it with a tilemap if you only need around 7000 tiles. And even with as many as I did, if you don't have to update them constantly. I use around 62000 in my own game, but they are only updated once when the game starts.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)