feat(ui): rework renderer to work with deltatime and ui rendering

This commit is contained in:
illyum 2024-09-13 07:44:55 -06:00
parent b359f36fb7
commit 842c8fb19d

View File

@ -5,50 +5,14 @@
class SceneManager {
public:
SceneManager(entt::registry& registry) : registry(registry), activeScene(entt::null) {}
void SetActiveScene(entt::entity scene) {
if (activeScene != entt::null) {
auto& currentScene = registry.get<SceneComponent>(activeScene);
currentScene.isActive = false;
}
activeScene = scene;
auto& newScene = registry.get<SceneComponent>(activeScene);
newScene.isActive = true;
}
entt::entity CreateScene() {
entt::entity scene = registry.create();
registry.emplace<SceneComponent>(scene, false);
return scene;
}
void UpdateActiveScene() {
if (activeScene != entt::null) {
// Iterate over entities in the active scene that have an InputComponent
auto view = registry.view<InputComponent>();
for (auto entity : view) {
auto& inputComponent = view.get<InputComponent>(entity);
inputComponent.Update(); // This will call the input logic
}
}
}
void RenderActiveScene() {
if (activeScene != entt::null) {
// Iterate over entities in the active scene that have both SpriteComponent and TransformComponent
auto view = registry.view<SpriteComponent, TransformComponent>();
for (auto entity : view) {
auto& sprite = view.get<SpriteComponent>(entity);
auto& transform = view.get<TransformComponent>(entity);
// Render the sprite at the position defined by the TransformComponent
sprite.Render(transform);
}
}
}
SceneManager(entt::registry& registry);
void SetActiveScene(entt::entity scene);
entt::entity CreateScene();
void UpdateActiveScene(float delta);
void RenderActiveScene();
void UpdateUI(entt::registry& registry);
void RenderUI(entt::registry& registry);
private:
entt::registry& registry;