Skip to content

Coding Style #1

@mallory-scotton

Description

@mallory-scotton

GP Engine Coding Styling

What do you prefer ?

bool gp::application::start()
{
    gp::math::vec2<gp::u32> size(1920, 1080);
    gp::rhi::device device = gp::rhi::device::create();
    gp::hal::window window(size, "Graphical Playground");

    if (!window.isValid())
    {
        gp::error::raise(gp::error::fatal, "Window creation failed");
        // or
        gp::error::raise(window.getError());
        // or error is automatically raised by the window creation failure
        return false;
    }

    window.bindDevice(device);

    bool isInitialized = device.initialize(gp::rhi::backend::vulkan);
    if (!isInitialized)
    {
        gp::error::raise(gp::error::fatal, "Device initialization failed");
        // or
        gp::error::raise(device.getError());
        // or error is automatically raised by the device creation failure
        return false;
    }

    window.onClosed      += [](const auto&) { gp::hal::requestExit(); };
    window.onFocusLost   += [](const auto&) { gp::audio::mute(); };
    window.onFocusGained += [](const auto&) { gp::audio::restore(); };

    window.onCloseRequested.add([](const auto&) { return true; }, gp::event::critical);
    // or
    window.onCloseRequested << gp::event::critical;
    window.onCloseRequested += [](const auto&) { return true; };

    while (window.isOpen())
    {
        // Simplified version
        gp::hal::pollSystemEvents();
        device.present();
    }
}

or

bool GP::Application::Start()
{
    GP::Vector2<GP::UInt32> size(1920, 1080);
    GP::RHIDevice device = GP::RHIDevice::Create();
    GP::Window window(size, "Graphical Playground");

    if (!window.IsValid())
    {
        GP::RaiseError(GP::EErrorType::Fatal, "Window creation failed");
        // or
        GP::RaiseError(window.GetError());
        // or error is automatically raised by the window creation failure
        return false;
    }

    window.BindDevice(device);

    bool isInitialized = device.Initialize(GP::EBackend::Vulkan);
    if (!isInitialized)
    {
        GP::RaiseError(GP::EErrorType::Fatal, "Device initialization failed");
        // or
        GP::RaiseError(device.getError());
        // or error is automatically raised by the device creation failure
        return false;
    }

    window.OnClosed      += [](const auto&) { GP::Platform::RequestExit(); };
    window.OnFocusLost   += [](const auto&) { GP::AudioSystem::Mute(); };
    window.OnFocusGained += [](const auto&) { GP::AudioSystem::Restore(); };

    window.OnCloseRequested.Add([](const auto&) { return true; }, GP::EEventPriority::Critical);
    // or
    window.OnCloseRequested << GP::EEventPriority::Critical;
    window.OnCloseRequested += [](const auto&) { return true; };

    while (window.IsOpen())
    {
        // Simplified version
        GP::Platform::PollEvents();
        device.Present();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions