Add asserts, update application->singleton, log defines
This commit is contained in:
@@ -3,13 +3,19 @@
|
|||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
#include "application.h"
|
#include "engine/application.h"
|
||||||
#include "log.h"
|
#include "engine/core.h"
|
||||||
|
#include "engine/event/event.h"
|
||||||
|
#include "engine/log.h"
|
||||||
|
|
||||||
namespace Engine {
|
namespace Engine {
|
||||||
|
|
||||||
|
Application* Application::s_instance = nullptr;
|
||||||
|
|
||||||
Application::Application()
|
Application::Application()
|
||||||
{
|
{
|
||||||
|
NF_CORE_ASSERT(!s_instance, "Application already exists!");
|
||||||
|
s_instance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Application::~Application()
|
Application::~Application()
|
||||||
@@ -18,7 +24,9 @@ namespace Engine {
|
|||||||
|
|
||||||
void Application::run()
|
void Application::run()
|
||||||
{
|
{
|
||||||
LOG_ENGINE_LOG("Startup!");
|
NF_CORE_LOG("Startup!");
|
||||||
|
|
||||||
|
Event event;
|
||||||
|
|
||||||
glfwInit();
|
glfwInit();
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||||
@@ -28,14 +36,14 @@ namespace Engine {
|
|||||||
|
|
||||||
GLFWwindow* window = glfwCreateWindow(1280, 720, "Engine", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(1280, 720, "Engine", NULL, NULL);
|
||||||
if (window == NULL) {
|
if (window == NULL) {
|
||||||
LOG_ENGINE_DANGER("Failed to create GLFW window");
|
NF_CORE_DANGER("Failed to create GLFW window");
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return;// -1;
|
return;// -1;
|
||||||
}
|
}
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(window);
|
||||||
|
|
||||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
||||||
LOG_ENGINE_DANGER("Failed to initialize GLAD");
|
NF_CORE_DANGER("Failed to initialize GLAD");
|
||||||
return;// -1;
|
return;// -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +64,7 @@ namespace Engine {
|
|||||||
|
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
||||||
LOG_ENGINE_LOG("Shutdown!");
|
NF_CORE_LOG("Shutdown!");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,11 +10,24 @@ namespace Engine {
|
|||||||
virtual ~Application();
|
virtual ~Application();
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
|
inline static Application &get() { return *s_instance; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
static Application* s_instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
// To be defined in the game
|
// To be defined in the game
|
||||||
Application *createApplication();
|
Application* createApplication();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // APPLICATION_H
|
#endif // APPLICATION_H
|
||||||
|
|
||||||
|
// @Todo
|
||||||
|
// v Application -> Singleton
|
||||||
|
// - Add assert
|
||||||
|
// - Event class
|
||||||
|
// - Event Dispatcher
|
||||||
|
// - template
|
||||||
|
// - Implement event in Application::OnEvent(Event& e);
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#ifndef CORE_H
|
||||||
|
#define CORE_H
|
||||||
|
|
||||||
|
#include <csignal>
|
||||||
|
|
||||||
|
// Debugging defines
|
||||||
|
#ifndef NDEBUG
|
||||||
|
#define NF_ENABLE_ASSERTS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Asserts
|
||||||
|
#ifdef NF_ENABLE_ASSERTS
|
||||||
|
// Check if SIGTRAP is available
|
||||||
|
#ifdef SIGTRAP
|
||||||
|
#define ABORT_SIGNAL SIGTRAP
|
||||||
|
#else
|
||||||
|
#define ABORT_SIGNAL SIGABRT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define NF_ASSERT(x, y) if(!(x)) { NF_DANGER(y); raise(ABORT_SIGNAL); }
|
||||||
|
#define NF_CORE_ASSERT(x, y) if(!(x)) { NF_CORE_DANGER(y); raise(ABORT_SIGNAL); }
|
||||||
|
#else
|
||||||
|
#define NF_ASSERT(x, y)
|
||||||
|
#define NF_CORE_ASSERT(x, y)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // CORE_H
|
||||||
@@ -10,9 +10,9 @@
|
|||||||
#include "application.h"
|
#include "application.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
extern Engine::Application *Engine::createApplication();
|
extern Engine::Application* Engine::createApplication();
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
// Supress unused warning
|
// Supress unused warning
|
||||||
(void)argc;
|
(void)argc;
|
||||||
@@ -20,6 +20,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// Initialize Log
|
// Initialize Log
|
||||||
Engine::Log::init();
|
Engine::Log::init();
|
||||||
|
NF_CORE_INFO("Initialized Log!");
|
||||||
|
|
||||||
// Start application
|
// Start application
|
||||||
auto app = Engine::createApplication();
|
auto app = Engine::createApplication();
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace Engine {
|
|||||||
m_gameLogger = std::make_shared<Logger>("Game");
|
m_gameLogger = std::make_shared<Logger>("Game");
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::Logger(const char *name) :
|
Logger::Logger(const char* name) :
|
||||||
m_name(name)
|
m_name(name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -25,27 +25,27 @@ namespace Engine {
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::log(const char *message, const char *level)
|
void Logger::log(const char* message, const char* level)
|
||||||
{
|
{
|
||||||
printf("%s%s: %s\033[0m\n", level, m_name, message);
|
printf("%s%s: %s\033[0m\n", level, m_name, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::info(const char *message)
|
void Logger::info(const char* message)
|
||||||
{
|
{
|
||||||
this->log(message, "\x1B[34m");
|
this->log(message, "\x1B[34m");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::warn(const char *message)
|
void Logger::warn(const char* message)
|
||||||
{
|
{
|
||||||
this->log(message, "\x1B[33m");
|
this->log(message, "\x1B[33m");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::danger(const char *message)
|
void Logger::danger(const char* message)
|
||||||
{
|
{
|
||||||
this->log(message, "\x1B[31m");
|
this->log(message, "\x1B[31m");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::success(const char *message)
|
void Logger::success(const char* message)
|
||||||
{
|
{
|
||||||
this->log(message, "\x1B[32m");
|
this->log(message, "\x1B[32m");
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-17
@@ -25,31 +25,31 @@ namespace Engine {
|
|||||||
class Logger
|
class Logger
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Logger(const char *name);
|
Logger(const char* name);
|
||||||
~Logger();
|
~Logger();
|
||||||
|
|
||||||
void log(const char *message, const char *level = "");
|
void log(const char* message, const char* level = "");
|
||||||
void info(const char *message);
|
void info(const char* message);
|
||||||
void warn(const char *message);
|
void warn(const char* message);
|
||||||
void danger(const char *message);
|
void danger(const char* message);
|
||||||
void success(const char *message);
|
void success(const char* message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char *m_name;
|
const char* m_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define LOG_ENGINE_LOG(x) Engine::Log::getEngineLogger()->log(x)
|
#define NF_CORE_LOG(x) Engine::Log::getEngineLogger()->log(x)
|
||||||
#define LOG_ENGINE_INFO(x) Engine::Log::getEngineLogger()->info(x)
|
#define NF_CORE_INFO(x) Engine::Log::getEngineLogger()->info(x)
|
||||||
#define LOG_ENGINE_WARN(x) Engine::Log::getEngineLogger()->warn(x)
|
#define NF_CORE_WARN(x) Engine::Log::getEngineLogger()->warn(x)
|
||||||
#define LOG_ENGINE_DANGER(x) Engine::Log::getEngineLogger()->danger(x)
|
#define NF_CORE_DANGER(x) Engine::Log::getEngineLogger()->danger(x)
|
||||||
#define LOG_ENGINE_SUCCESS(x) Engine::Log::getEngineLogger()->success(x)
|
#define NF_CORE_SUCCESS(x) Engine::Log::getEngineLogger()->success(x)
|
||||||
|
|
||||||
#define LOG_LOG(x) Engine::Log::getGameLogger()->log(x)
|
#define NF_LOG(x) Engine::Log::getGameLogger()->log(x)
|
||||||
#define LOG_INFO(x) Engine::Log::getGameLogger()->info(x)
|
#define NF_INFO(x) Engine::Log::getGameLogger()->info(x)
|
||||||
#define LOG_WARN(x) Engine::Log::getGameLogger()->warn(x)
|
#define NF_WARN(x) Engine::Log::getGameLogger()->warn(x)
|
||||||
#define LOG_DANGER(x) Engine::Log::getGameLogger()->danger(x)
|
#define NF_DANGER(x) Engine::Log::getGameLogger()->danger(x)
|
||||||
#define LOG_SUCCESS(x) Engine::Log::getGameLogger()->success(x)
|
#define NF_SUCCESS(x) Engine::Log::getGameLogger()->success(x)
|
||||||
|
|
||||||
#endif // LOG_H
|
#endif // LOG_H
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@ public:
|
|||||||
~Game() {};
|
~Game() {};
|
||||||
};
|
};
|
||||||
|
|
||||||
Engine::Application *Engine::createApplication()
|
Engine::Application* Engine::createApplication()
|
||||||
{
|
{
|
||||||
return new Game();
|
return new Game();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user