Sorting render groups by render layer

master
Joey Pollack 3 years ago
parent 2279b3ff45
commit 4b9bbc8991

@ -126,6 +126,7 @@ ECS:
☐ Box Collider (Box2D) ☐ Box Collider (Box2D)
World (Lunariums version of a "Scene"): World (Lunariums version of a "Scene"):
☐ Add Render layer property to all renderable components
☐ Implement memento pattern to save the initial state of the world ☐ Implement memento pattern to save the initial state of the world
☐ Implement running the world and resetting to initial state ☐ Implement running the world and resetting to initial state
☐ Implement the world without Regions first ☐ Implement the world without Regions first

@ -1,6 +1,10 @@
Editor: Editor:
☐ Give Entities a name property separate from the tag component ☐ Remove Entity
☐ Remove Component
✔ Add Entity children @done(22-09-14 15:07)
✔ Entity Parent/Child hierarchy system @done(22-09-14 15:07)
✔ Give Entities a name property separate from the tag component @done(22-09-14 15:06)
☐ Add button to flip image assets vertically ☐ Add button to flip image assets vertically
☐ Design a custom editor style @low ☐ Design a custom editor style @low
☐ Save and unload world data when a new world is selected ☐ Save and unload world data when a new world is selected

@ -107,5 +107,9 @@ namespace lunarium { namespace editor
comp.Size.x = _size.x; comp.Size.x = _size.x;
comp.Size.y = _size.y; comp.Size.y = _size.y;
} }
ImGui::Text("Render Layer: ");
ImGui::SameLine();
ImGui::InputInt("##Render Layer", &comp.RenderLayer, 1, 10);
} }
}} }}

@ -78,6 +78,7 @@ namespace lunarium
{ {
glm::vec4 Color; glm::vec4 Color;
glm::vec2 Size; glm::vec2 Size;
int RenderLayer;
BlockOutComponent() = default; BlockOutComponent() = default;
BlockOutComponent(const BlockOutComponent&) = default; BlockOutComponent(const BlockOutComponent&) = default;

@ -247,6 +247,8 @@ namespace lunarium
size["width"] = comp.Size.x; size["width"] = comp.Size.x;
size["height"] = comp.Size.y; size["height"] = comp.Size.y;
blockout["render_layer"] = comp.RenderLayer;
components.emplace_back(blockout); components.emplace_back(blockout);
} }
@ -384,7 +386,9 @@ namespace lunarium
auto& size = comp["size"]; auto& size = comp["size"];
glm::vec2 Size(size["width"].get<f32>(), size["height"].get<f32>()); glm::vec2 Size(size["width"].get<f32>(), size["height"].get<f32>());
AddComponent<BlockOutComponent>(Color, Size); int layer = comp["render_layer"].get<int>();
AddComponent<BlockOutComponent>(Color, Size, layer);
} }
if ("ParentEntityComponent" == comp_type_name) if ("ParentEntityComponent" == comp_type_name)

@ -79,17 +79,42 @@ namespace lunarium
// pGraphics->DrawQuad(rect, color, nullptr, 0.0f, Rectangle(-1, -1, -1, -1), parent_transform); // pGraphics->DrawQuad(rect, color, nullptr, 0.0f, Rectangle(-1, -1, -1, -1), parent_transform);
// }); // });
mECSRegistry.view<TransformComponent, BlockOutComponent>().each([&](auto entity, auto &transform, auto &blockout) // OLD RENDER HEIRARCHY RENDER SYSTEM
// mECSRegistry.view<TransformComponent, BlockOutComponent>().each([&](auto entity, auto &transform, auto &blockout)
// {
// Rectangle rect(transform.Position.x, transform.Position.y, blockout.Size.x, blockout.Size.y);
// Color color(blockout.Color.x, blockout.Color.y, blockout.Color.z, blockout.Color.w);
// if (!mECSRegistry.all_of<ParentEntityComponent>(entity))
// {
// DrawHeirarchy(pGraphics, entity, transform, blockout, glm::mat4(1.0f));
// }
// });
// NEW RENDER SYSTEM
// First get the group we want
auto group = mECSRegistry.group<>(entt::get<BlockOutComponent, TransformComponent>);
// Next sort the group
group.sort<BlockOutComponent>([](const BlockOutComponent &lhs, const BlockOutComponent &rhs)
{ {
return lhs.RenderLayer < rhs.RenderLayer;
});
// Render the group
for(auto entity: group)
{
auto &transform = group.get<TransformComponent>(entity);
auto &blockout = group.get<BlockOutComponent>(entity);
Rectangle rect(transform.Position.x, transform.Position.y, blockout.Size.x, blockout.Size.y); Rectangle rect(transform.Position.x, transform.Position.y, blockout.Size.x, blockout.Size.y);
Color color(blockout.Color.x, blockout.Color.y, blockout.Color.z, blockout.Color.w); Color color(blockout.Color.x, blockout.Color.y, blockout.Color.z, blockout.Color.w);
if (!mECSRegistry.all_of<ParentEntityComponent>(entity)) // TODO: Get and apply parent transforms
{
DrawHeirarchy(pGraphics, entity, transform, blockout, glm::mat4(1.0f));
}
});
pGraphics->DrawQuad(rect, color, nullptr, -transform.Rotation.z, Rectangle(-1, -1, -1, -1), glm::mat4(1.0f));
}
} }

Loading…
Cancel
Save