Initial implementation.

This commit is contained in:
2025-03-02 16:01:30 +01:00
parent 1aa4656eb0
commit f51dd5b437
9 changed files with 503 additions and 12 deletions

133
public/raid/raid.hpp Normal file
View File

@@ -0,0 +1,133 @@
#pragma once
#if !defined(RAID_PUBLIC_RAID_RAID_HPP_INCLUDED)
#define RAID_PUBLIC_RAID_RAID_HPP_INCLUDED 1
#include <cstdint>
#include <functional>
#include <fmt/format.h>
#include <SDL3/SDL.h>
namespace raid
{
inline constexpr int ERR_INIT_FAILED = 100;
enum class MessageSeverity : unsigned char
{
INFO,
WARNING,
ERROR
};
struct Message
{
MessageSeverity severity;
const char* text;
};
class Application
{
private:
bool mRunning = true;
SDL_Window* mWindow = nullptr;
SDL_GLContext mGLContext = nullptr;
using glClear_fn_t = void (*)(std::uint32_t);
using glClearColor_fn_t = void (*)(float, float, float, float);
glClear_fn_t glClear;
glClearColor_fn_t glClearColor;
public:
virtual ~Application() = default;
[[nodiscard]]
int run(int argc, char* argv[]);
protected:
virtual void render() = 0;
virtual void handleMessage(const Message& message);
virtual void handleSDLEvent(const SDL_Event& event);
void msgInfo(const char* text)
{
handleMessage({
.severity = MessageSeverity::INFO,
.text = text
});
}
void msgWarning(const char* text)
{
handleMessage({
.severity = MessageSeverity::WARNING,
.text = text
});
}
void msgError(const char* text)
{
handleMessage({
.severity = MessageSeverity::ERROR,
.text = text
});
}
void msgInfo(const std::string& text)
{
msgInfo(text.c_str());
}
void msgWarning(const std::string& text)
{
msgWarning(text.c_str());
}
void msgError(const std::string& text)
{
msgError(text.c_str());
}
template<typename TArg, typename... TArgs>
void msgInfo(fmt::format_string<TArg, TArgs...> format, TArg&& arg, TArgs&&... args)
{
std::string text = fmt::format(format, std::forward<TArg>(arg), std::forward<TArgs>(args)...);
msgInfo(text);
}
template<typename TArg, typename... TArgs>
void msgWarning(fmt::format_string<TArg, TArgs...> format, TArg&& arg, TArgs&&... args)
{
std::string text = fmt::format(format, std::forward<TArg>(arg), std::forward<TArgs>(args)...);
msgWarning(text);
}
template<typename TArg, typename... TArgs>
void msgError(fmt::format_string<TArg, TArgs...> format, TArg&& arg, TArgs&&... args)
{
std::string text = fmt::format(format, std::forward<TArg>(arg), std::forward<TArgs>(args)...);
msgError(text);
}
private:
bool initSDL();
bool initGL();
bool initImGui();
void cleanup();
void handleSDLEvents();
};
using render_cb_t = std::function<void()>;
struct QuickAppOptions
{
struct
{
render_cb_t render;
} callbacks;
};
class QuickApp : public Application
{
private:
QuickAppOptions mOptions;
public:
void init(QuickAppOptions options);
void render() override;
};
[[nodiscard]]
int runQuick(int argc, char* argv[], QuickAppOptions options);
} // namespace raid
#endif // !defined(RAID_PUBLIC_RAID_RAID_HPP_INCLUDED)