Skip to content

Create Scene Component #2

@thomasnemer

Description

@thomasnemer

Part of #1: Scene-Based Architecture

Overview

Implement a Scene class that acts as the root component, owning the window and renderer lifecycle while providing a simplified interface for applications.

Requirements

  • Scene component should own IWindow* and IRenderer*
  • Manage EventDispatcher internally
  • Automatically fill window dimensions
  • Handle window resize events and propagate to children
  • Provide simple update(), render(), present() interface
  • Support attach/detach from window

Implementation Details

Class Structure

namespace bombfork::prong {

class Scene : public Component {
private:
    IWindow* window;
    IRenderer* renderer; 
    std::unique_ptr<EventDispatcher> eventDispatcher;
    
public:
    Scene(IWindow* window, IRenderer* renderer);
    
    // Lifecycle
    void attach();
    void detach();
    
    // Main loop interface
    void update(double deltaTime) override;
    void render() override;
    void present();
    
    // Window events
    void onWindowResize(int width, int height);
};

}

Key Features

  1. Automatic Bounds: Scene automatically sets its bounds to window size
  2. Event Management: Creates and manages EventDispatcher internally
  3. Child Registration: Automatically registers children with event dispatcher
  4. Resize Propagation: Notifies all children when window resizes

Acceptance Criteria

  • Scene class created in include/bombfork/prong/core/scene.h
  • Scene owns window and renderer references
  • Scene manages EventDispatcher lifecycle
  • Scene automatically fills window dimensions
  • Window resize events propagate to all children
  • Children are automatically registered with event dispatcher
  • Scene can be attached/detached from window
  • Unit tests for Scene component

Example Usage

// In main.cpp
auto window = std::make_unique<GLFWWindowAdapter>(glfwWindow);
auto renderer = std::make_unique<OpenGLRenderer>();
auto scene = std::make_unique<DemoScene>(window.get(), renderer.get());

scene->attach();

while (!window->shouldClose()) {
    double deltaTime = calculateDeltaTime();
    scene->update(deltaTime);
    scene->render();
    scene->present();
}

scene->detach();

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions