Why is this so inefficient?(Random Generation)

Get help using Construct 2

Post » Thu Apr 10, 2014 8:38 pm

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: https://www.youtube.com/watch?v=CnkUTMbli1g
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
Last edited by tarik00555 on Thu Apr 10, 2014 9:13 pm, edited 1 time in total.
Banned User
B
6
S
3
Posts: 105
Reputation: 1,170

Post » Thu Apr 10, 2014 8:47 pm

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?
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Thu Apr 10, 2014 8:58 pm

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.
You do not have the required permissions to view the files attached to this post.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Thu Apr 10, 2014 10:42 pm

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

Image

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.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Fri Apr 11, 2014 1:21 pm

Thanks a lot for such a detailed reply. I heard of tilemaps, but I never looked into them, but I will now.
Banned User
B
6
S
3
Posts: 105
Reputation: 1,170

Post » Fri Apr 11, 2014 1:35 pm

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.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 3 guests