wip: wait until data is ready and has been consumed (couples physics and rendering thread again)

This commit is contained in:
2026-02-24 13:16:00 +01:00
parent 74065b7ea2
commit e7d4170b77
6 changed files with 37 additions and 22 deletions

View File

@ -33,8 +33,7 @@ auto Renderer::UpdateTextureSizes() -> void {
menu_target = LoadRenderTexture(width * 2, MENU_HEIGHT);
}
auto Renderer::AllocateGraphInstancing(const std::vector<Mass> &masses)
-> void {
auto Renderer::AllocateGraphInstancing(std::size_t size) -> void {
cube_instance = GenMeshCube(VERTEX_SIZE, VERTEX_SIZE, VERTEX_SIZE);
instancing_shader = LoadShader("shader/instancing_vertex.glsl",
@ -48,16 +47,14 @@ auto Renderer::AllocateGraphInstancing(const std::vector<Mass> &masses)
vertex_mat.maps[MATERIAL_MAP_DIFFUSE].color = VERTEX_COLOR;
vertex_mat.shader = instancing_shader;
transforms = (Matrix *)MemAlloc(masses.size() * sizeof(Matrix));
transforms_size = masses.size();
transforms = (Matrix *)MemAlloc(size * sizeof(Matrix));
transforms_size = size;
}
auto Renderer::ReallocateGraphInstancingIfNecessary(
const std::vector<Mass> &masses) -> void {
if (transforms_size != masses.size()) {
transforms =
(Matrix *)MemRealloc(transforms, masses.size() * sizeof(Matrix));
transforms_size = masses.size();
auto Renderer::ReallocateGraphInstancingIfNecessary(std::size_t size) -> void {
if (transforms_size != size) {
transforms = (Matrix *)MemRealloc(transforms, size * sizeof(Matrix));
transforms_size = size;
}
}
@ -76,9 +73,9 @@ auto Renderer::DrawMassSprings(
ZoneNamedN(prepare_masses, "PrepareMasses", true);
if (masses.size() < DRAW_VERTICES_LIMIT) {
if (transforms == nullptr) {
AllocateGraphInstancing(masses);
AllocateGraphInstancing(masses.size());
}
ReallocateGraphInstancingIfNecessary(masses);
ReallocateGraphInstancingIfNecessary(masses.size());
int i = 0;
for (const auto &mass : masses) {