DavidMcLaughlin208 / FallingSandJava

Falling Sand Simulation implemented in Java. Every pixel is simulated every frame and has its own state and intrinsic motivations.
151 stars 17 forks source link

Suggestions to improve program efficiency. #3

Closed PandaDecSt closed 3 years ago

PandaDecSt commented 3 years ago

Hello, I found that your program does not run very smoothly on Android, so I have a few suggestions here, which may be able to help you.

1.Emptycell may not be drawn.

2.Use multiple threads to calculate parameters and draw.

Waiting for completion...

DavidMcLaughlin208 commented 3 years ago

I had previously tried not drawing EmptyCells and it caused some weird drawing behavior with the other elements. I have on my to-do list enabling multithreading on drawing but haven't gotten around to it yet.

Also want to try populating a pixmap (using multithreading and performing one draw call on the pixmap. But have yet to try it.

I have become very busy with work recently and have not had time to work on this project. I will be picking this back up in the second half of 2021

DavidMcLaughlin208 commented 3 years ago

I tried two different ways to multithread and change the drawing logic.

  1. Use multiple ShapeRenderers and multithread the existing drawing logic. This did not work since beginning a draw call on the ShapeRenderer modifies the OpenGL context and you cannot being another draw call until the previous one is closed.
  2. Use multithreading to update a pixmap with the correct colors, apply it to a texture, and draw the texture. This was significantly less performant than ShapeRenderer.

There is one other approach I can try to improve drawing performance but inevitably I will need to migrate this project to c++ since it is more performant and I am running into issues with LIBGDX.

PandaDecSt commented 3 years ago

Recently I have thought of several funny ways to improve performance.

1.Update the screen when a cell in the matrix changes, this will have better performance at least in static images.

2.Render the element itself through the element itself, Avoid traversing the array to render one by one.

3.Subdivide the matrix into chunks, then use the same principle as the first method.

Maybe it can be useful.

I also think that using c++ would be a good choice. At the same time, I also regret this version written in Java. I think this is the best FallingSand engine written in Java. Good luck!

DavidMcLaughlin208 commented 3 years ago

Subdivide the matrix into chunks, then use the same principle as the first method

This is a good idea! I will try this out. Should be an easy change.

At the same time, I also regret this version written in Java. I think this is the best FallingSand engine written in Java. Good luck!

Thanks for the kind words! I mostly am running into issues with the framework I am using and not Java itself. So if I can find a good alternative I will just migrate the java code to a framework.

DavidMcLaughlin208 commented 3 years ago

Subdivide the matrix into chunks, then use the same principle as the first method

Ok I just tried it and I definitely doesn't work. But just because of the weird drawing behavior of LIBGDX. I will definitely have to switch to another framework either way.