HitCoder
|
|
Posted on: April 28, 2015, 03:15:35 pm |
|
|
Location: Oxford, England Joined: Aug 2014
Posts: 157
|
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
|
Computer Scientist, Programmer in C#, C/C++, Java, Python, GML, EDL, and more. Hobbyist musician. DISCORD: HitCoder#4530
|
|
|
|
HitCoder
|
|
Reply #2 Posted on: April 28, 2015, 05:01:48 pm |
|
|
Location: Oxford, England Joined: Aug 2014
Posts: 157
|
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
|
Computer Scientist, Programmer in C#, C/C++, Java, Python, GML, EDL, and more. Hobbyist musician. DISCORD: HitCoder#4530
|
|
|
|
HitCoder
|
|
Reply #4 Posted on: April 29, 2015, 09:57:21 am |
|
|
Location: Oxford, England Joined: Aug 2014
Posts: 157
|
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
|
Computer Scientist, Programmer in C#, C/C++, Java, Python, GML, EDL, and more. Hobbyist musician. DISCORD: HitCoder#4530
|
|
|
|
HitCoder
|
|
Reply #6 Posted on: April 29, 2015, 02:22:18 pm |
|
|
Location: Oxford, England Joined: Aug 2014
Posts: 157
|
I was trying to run the instance_activate function through deactivated instances, that's all. lmao.
|
|
|
Logged
|
Computer Scientist, Programmer in C#, C/C++, Java, Python, GML, EDL, and more. Hobbyist musician. DISCORD: HitCoder#4530
|
|
|
|