Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize _draw_tiles function #7

Closed
BenjaTK opened this issue Jul 30, 2023 · 8 comments
Closed

Optimize _draw_tiles function #7

BenjaTK opened this issue Jul 30, 2023 · 8 comments
Labels
Milestone

Comments

@BenjaTK
Copy link
Owner

BenjaTK commented Jul 30, 2023

HeightmapGenerator2D takes a very long time to generate. Tested with a 1750x900 world, it takes about 25 seconds with no modifiers, and the carver modifier only seems to add only about 2 seconds.

@Nemesis-AS
Copy link

image
This is the result I got when generating a 1750x900 world in the heightmap_demo scene. I used Time.get_ticks_msec() to measure time

It seems like most of the time is spent on the _draw_tiles function, which is hard to optimize any further. I believe chunking can help in this case. It would be easier to draw the terrain in chunks instead of drawing it all at once but the solution may end up adding a slight overhead so it might take longer than 25s(324 in my case) to generate but at least it would be a smoother experience

@BenjaTK
Copy link
Owner Author

BenjaTK commented Jul 31, 2023

Hi! Thanks for checking it out.
Yeah, I suspected it was _draw_tiles. It's really slow, ESPECIALLY if you use terrains. I think chunking would be the best solution, but should we add chunking to all generators or just this one? As far as I've seen, they're all pretty slow with a large world size.

@BenjaTK BenjaTK changed the title Optimize HeightmapGenerator2D Optimize _draw_tiles function Jul 31, 2023
@Nemesis-AS
Copy link

Since all the generators will benefit from chunking, we should add chunking to the GaeaGenerator class. And for fine tuning, properties like chunk size could be exposed in the editor

@BenjaTK
Copy link
Owner Author

BenjaTK commented Aug 1, 2023

Yeah that sounds like the right idea!

@Salodo
Copy link

Salodo commented Aug 4, 2023

I think that the main problem with the drawing is that you are drawing everything at once. Even if its as efficient as possible you are still drawing millions of blocks, I had this problems with my game where the problems isn't the function itself it only took about 0.001 seconds, but rather the amount of times the function needed to happen. I don't know if its possible, but you don't technically have to draw everything at once you could just do it asynchronous by drawing 100 blocks every frame or something. If you unblock the main thread you realise that there was no performance problem in the first place.

@Nemesis-AS
Copy link

I did give this some thought, but in the end it seems like a chunk system will be implemented anyway so I don't think we need to make any optimization here. But if needed I support moving the tile rendering to another thread

@BenjaTK
Copy link
Owner Author

BenjaTK commented Aug 4, 2023

That makes sense though! I've never worked with threads so I'll have to look into it but that sounds better than implementing a chunk system for generators that don't need it (I'd prefer chunking to be only used for infinite worlds rather than static ones).

@BenjaTK BenjaTK added this to the v1.0.0 milestone Aug 8, 2023
@BenjaTK
Copy link
Owner Author

BenjaTK commented Sep 7, 2023

Should we close this now that #29 was merged?

@BenjaTK BenjaTK closed this as completed Sep 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants