Coder Social home page Coder Social logo

Optimize _draw_tiles function about gaea HOT 8 CLOSED

benjatk avatar benjatk commented on August 24, 2024
Optimize _draw_tiles function

from gaea.

Comments (8)

Salodo avatar Salodo commented on August 24, 2024 1

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.

from gaea.

BenjaTK avatar BenjaTK commented on August 24, 2024 1

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).

from gaea.

BenjaTK avatar BenjaTK commented on August 24, 2024 1

Should we close this now that #29 was merged?

from gaea.

Nemesis-AS avatar Nemesis-AS commented on August 24, 2024

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

from gaea.

BenjaTK avatar BenjaTK commented on August 24, 2024

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.

from gaea.

Nemesis-AS avatar Nemesis-AS commented on August 24, 2024

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

from gaea.

BenjaTK avatar BenjaTK commented on August 24, 2024

Yeah that sounds like the right idea!

from gaea.

Nemesis-AS avatar Nemesis-AS commented on August 24, 2024

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

from gaea.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.