- Currently, the slowest tyhing is the rendering as not much else happens (yet)
- Cache the mesh for each chunk
- This could even be split further into sub-chunks (perhaps 4x4x4 or 8x8x8)
- Every tick/frame (same thing for now),
hasChanged
set tofalse
in each chunk - If a block is changed, set
hasChanged
totrue
in that chunk
- Rendering is done after the tick takes place
- Each chunk has its own mesh
- Those meshes are
concat
-ed together into a single mesh - For each chunk:
- If
hasChanged
istrue
for that chunk, recalculate the mesh and re-insert it into global mesh table - If
hasChanged
isfalse
for that chunk, continue onto next chunk
- If
- Same as above except:
- When a chunk needs to be recalculated, make an async thing that reinserts it into global mesh table once complete.
- This way, the main 'thread' isn't blocked by recalculating the mesh
- Also, a serial number also needs to exist so that an earlier mesh doesn't accidentally override later mesh that finished earlier
- Actually, there is no real way to make it truly async apart from using workers (?)
- is the time creating a worker worth it for doing the calculaion that should take < 10ms
- Could reuse workers to avoid the long (?) creation times
- However, if 2 changes happened very quickly it might be a waste to recalculate the mesh twice (if the first one has not been calculated by the time the second changes take place).
- This should only be done if
- a new one comes in within a certain amount of the previous calculation and
- the first one isn't already complete / has just started
- Is there an easy way to cancel the previous calculation?
- There is no built-in way to cancel promises
- Perhaps this could be done by checking for the condition every
n
vertices
- However, the calculations will probably be quite small so cancelling them probably won't be worth it as they will have already completed
- Also, if lots of events happen very closes together (eg. insta-mining), the mesh might not be updated at all as the previous one keep getting discarded before being complete
- Therefore, this isn't really needed because of all the drawbacks