Program Listing for File application.h

Return to documentation for file (portal/application/application.h)

//
// Copyright © 2025 Jonatan Nevo.
// Distributed under the MIT license (see LICENSE file).
//

#pragma once
#include <filesystem>
#include <entt/signal/dispatcher.hpp>

#include <llvm/ADT/SmallVector.h>
#include <portal/core/strings/string_id.h>

#include "settings.h"
#include "modules/module_stack.h"

namespace portal
{
class Project;
struct ApplicationProperties
{
    StringId name = STRING_ID("Portal Engine");
    size_t width = 1600;
    size_t height = 900;

    bool resizeable = true;
};

class Application
{
public:
    explicit Application(const ApplicationProperties& properties);
    virtual ~Application();

    virtual void build_dependency_graph();

    virtual void prepare() {};

    void run();

    void stop();

    virtual void process_events() {};

    [[nodiscard]] virtual bool should_run() const;

protected:
    virtual ProjectSettings& get_settings() const = 0;

protected:
    ApplicationProperties properties;
    ModuleStack modules;

    size_t current_frame = 0;
    float last_frame_time = 0;
    float frame_time = 0;
    float time_step = 0;

    std::atomic_flag should_stop;
    entt::dispatcher engine_event_dispatcher;
    entt::dispatcher input_event_dispatcher;
};

std::unique_ptr<Application> create_application(int arc, char** argv);
} // portal