Pages: 1
  Print  
Author Topic: Infinite world generation lag  (Read 1630 times)
Offline (Male) HitCoder
Posted on: April 28, 2015, 03:15:35 PM

Member
Location: King's Lynn, England
Joined: Aug 2014
Posts: 151

View Profile WWW Email
My current sonic fangame project is on hold for now for some reasons that are unimportant here.

Anyway, onto the topic. I have made a 2D Minecraft fangame engine so far, and I added infinite world generation. The issue is that it really lags once it generates 5 to 6 chunks. A chunk is made up of X/Y 20,64 (this is measured in blocks, each block is 32 pixels, but I'm pretty sure the only info needed is the amount of objects, so a chunk is made of 1280 blocks), is that an insanely large number? Should I change the depth of the world or something? Is there a way to unload all of the blocks in chunks outside of the view? Should I somehow make it not use objects for blocks, but rather somehow come up with a method for using arrays that draw sprites? If I did that, would it make it run faster? Are there any other methods?

I have already tried deactivating all the blocks that are off screen; It crashes the game for some reason.
I have also tried making all blocks offscreen invisible and non-solid.

Any suggestions?

Also, sorry for large paragraph full of questions.
« Last Edit: April 28, 2015, 03:30:26 PM by HitCoder » Logged
DISCORD: HitCoder#4530
hi my name is John Cooper and i'm not good at anything
Offline (Unknown gender) TheExDeus
Reply #1 Posted on: April 28, 2015, 04:49:36 PM

Developer
Joined: Apr 2008
Posts: 1872

View Profile
Is the "lag" low fps or is it a short freeze when generating?

Normally deactivation would be the way to go. The segfault should be investigated. Is there maybe a simple example you can post? Making blocks invisible should also help.
It will still be slower because instances have overhead. They require updates in cases you wouldn't need, like every block calculates direction based on speed and gravity all the time, even though speed and gravity is zero (there is probably a check in this case, but it is still a few "if checks" per instance). It also requires iteration and call for events. So I would suggest maybe using a grid or an array (maybe one instance and one grid per n number of blocks). Tiles would help with rendering, as right now backgrounds (tiles) can be drawn with one texture. This means all your world could end up as one draw call. Tile functions should work, so you could and and remove tiles at runtime. In my branch I have added texture atlases that allow you to put sprites, backgrounds and fonts into one texture. If you can post an example, I could see if that improves performance.
Logged
Offline (Male) HitCoder
Reply #2 Posted on: April 28, 2015, 05:01:48 PM

Member
Location: King's Lynn, England
Joined: Aug 2014
Posts: 151

View Profile WWW Email
Is the "lag" low fps or is it a short freeze when generating?

Normally deactivation would be the way to go. The segfault should be investigated. Is there maybe a simple example you can post? Making blocks invisible should also help.
It will still be slower because instances have overhead. They require updates in cases you wouldn't need, like every block calculates direction based on speed and gravity all the time, even though speed and gravity is zero (there is probably a check in this case, but it is still a few "if checks" per instance). It also requires iteration and call for events. So I would suggest maybe using a grid or an array (maybe one instance and one grid per n number of blocks). Tiles would help with rendering, as right now backgrounds (tiles) can be drawn with one texture. This means all your world could end up as one draw call. Tile functions should work, so you could and and remove tiles at runtime. In my branch I have added texture atlases that allow you to put sprites, backgrounds and fonts into one texture. If you can post an example, I could see if that improves performance.

It's low FPS after generating more and more chunks, it just makes the game lag more and more as you keep moving left/right.

I'll try executing instance_deactivate some other way though.

EDIT: I redid the instance_deactivate thing, it fixes lots of the lag now, I think the only issues is the drawing of the remaining sprites. I think I shall make them hidden outside view once again.
« Last Edit: April 28, 2015, 05:24:46 PM by HitCoder » Logged
DISCORD: HitCoder#4530
hi my name is John Cooper and i'm not good at anything
Offline (Unknown gender) TheExDeus
Reply #3 Posted on: April 28, 2015, 05:25:57 PM

Developer
Joined: Apr 2008
Posts: 1872

View Profile
I would probably try doing it via some datastructures though. But drawing is probably a problem too. Try using some kind of visual debugger (like CodeXL) to see how much draw calls are made. Batching textures is the perfect thing for a game like this, because then you would draw all of the ground in one draw call. That usually gives 5-10x performance improvement.

edit: So now it doesn't crash anymore with instance_deactivate?
Logged
Offline (Male) HitCoder
Reply #4 Posted on: April 29, 2015, 09:57:21 AM

Member
Location: King's Lynn, England
Joined: Aug 2014
Posts: 151

View Profile WWW Email
I would probably try doing it via some datastructures though. But drawing is probably a problem too. Try using some kind of visual debugger (like CodeXL) to see how much draw calls are made. Batching textures is the perfect thing for a game like this, because then you would draw all of the ground in one draw call. That usually gives 5-10x performance improvement.

edit: So now it doesn't crash anymore with instance_deactivate?

Nope, I made a stupid mistake the first time around, but now there's no issue with lag. Thanks! :)
Logged
DISCORD: HitCoder#4530
hi my name is John Cooper and i'm not good at anything
Offline (Unknown gender) TheExDeus
Reply #5 Posted on: April 29, 2015, 11:56:16 AM

Developer
Joined: Apr 2008
Posts: 1872

View Profile
No stupid mistake should create a segfault though. That seems to be a stupid mistake on our part. So maybe you want to show how to replicate the crash? If not, then I'm just happy you got everything working. :)
Logged
Offline (Male) HitCoder
Reply #6 Posted on: April 29, 2015, 02:22:18 PM

Member
Location: King's Lynn, England
Joined: Aug 2014
Posts: 151

View Profile WWW Email
I was trying to run the instance_activate function through deactivated instances, that's all. lmao.
Logged
DISCORD: HitCoder#4530
hi my name is John Cooper and i'm not good at anything
Pages: 1
  Print