simplifying logging, changing App events to std::function

This commit is contained in:
Noel Berry
2021-02-21 18:43:42 -08:00
parent f8741e27e2
commit a72cd5cab6
4 changed files with 30 additions and 20 deletions

View File

@ -1,8 +1,13 @@
#pragma once
#include <memory>
#include <functional>
#include <blah/core/log.h>
namespace Blah
{
using AppEventFn = std::function<void()>;
using AppLogFn = std::function<void(const char* message, Log::Category category)>;
struct Config
{
const char* name;
@ -11,15 +16,12 @@ namespace Blah
int max_updates;
int target_framerate;
void (*on_startup)();
void (*on_shutdown)();
void (*on_update)();
void (*on_render)();
void (*on_exit_request)();
void (*on_info)(const char* text);
void (*on_warn)(const char* text);
void (*on_error)(const char* text);
AppEventFn on_startup;
AppEventFn on_shutdown;
AppEventFn on_update;
AppEventFn on_render;
AppEventFn on_exit_request;
AppLogFn on_log;
Config();
};

View File

@ -23,6 +23,9 @@
#define BLAH_ASSERT(condition, message) \
do { if (!(condition)) { BLAH_ERROR(message); } } while(0)
#define BLAH_ASSERT_FMT(condition, message, ...) \
do { if (!(condition)) { BLAH_ERROR_FMT(message, __VA_ARGS__); } } while(0)
// maximum length of a print/warn/error message
#ifndef BLAH_MESSAGE
#define BLAH_MESSAGE 1024
@ -32,6 +35,13 @@ namespace Blah
{
namespace Log
{
enum class Category
{
Info,
Warning,
Error
};
void print(const char* info, ...);
void warn(const char* info, ...);
void error(const char* info, ...);