Interface Subsystem

Overview

The Interface Subsystem is a critical component responsible for managing the user interface of the game engine. Leveraging the SFML (Simple and Fast Multimedia Library), this subsystem handles several key responsibilities:

  • Window rendering

  • Drawable component management

  • User input processing

  • Sound component handling

Initialization

Constructor

The subsystem’s constructor sets up the initial game window with specific configuration parameters:

1
2
3
4
5
6
7
8
9
InterfaceSubsystem::InterfaceSubsystem() {
    constexpr int x = 1024;
    constexpr int y = 768;

    _window.create(sf::VideoMode(x, y), "BBOC Engine");
    _view.setSize(x / 4, y / 4);
    _view.setCenter(x / 8, y / 8);
    _window.setView(_view);
}

Note

The window view is scaled up by a factor of 4 to enhance visibility on modern high-resolution screens. This approach ensures that low-resolution game elements remain clear and visually appealing. The lines emphasized in the code snippet highlight the view configuration.

Update Cycle Methods

The Interface Subsystem implements two primary update methods that are crucial to each subsystems:

Pre-Update Method

The preUpdate() function is called before the game state update. Its primary responsibilities include:

  • Clearing the current frame

  • Processing input events

void InterfaceSubsystem::preUpdate() {
    _window.clear();

    while (_window.pollEvent(_event)) {
        if (_event.type == sf::Event::Closed) {
            _window.close();
        }
    }
}

Post-Update Method

The postUpdate() function is called after the game state update. Its key tasks are:

  • Displaying the current frame

  • Updating the subsystem’s current time using delta time

void InterfaceSubsystem::postUpdate(double delta) {
    (void)(delta);
    _window.display();
}

Note

For now the delta parameter is not currently used in the postUpdate() method.

Component Handling

Drawable Components

The subsystem provides specialized handling for drawable components through the handleDrawable() method.

This function:

  • Draws components to the screen

  • Utilizes the actor’s position and rotation

  • Renders based on the component’s specific details

void InterfaceSubsystem::handleDrawable(const std::shared_ptr<Actor> &actor, const std::shared_ptr<Component> &component)

Animated Drawable Components

The subsystem also supports animated drawable components through the handleAnimatedDrawable() method.

This function:

void handleAnimatedDrawable(const std::shared_ptr<Actor> &actor, const std::shared_ptr<Component> &component);

Music Components

The subsystem manages music components through the handleMusic() method.

This function:

handleMusic(const std::shared_ptr<Actor> &actor, const std::shared_ptr<Component> &component);

Key Design Considerations

  • Modularity: The subsystem follows a modular design, separating concerns between window management, event processing, and rendering.

  • Performance: The subsystem launches in its own thread, ensuring that the game loop runs independently of the interface subsystem.

  • Simplicity: The subsystem’s design is straightforward, making it easy to understand and modify as needed.