New logging system

This commit is contained in:
2021-09-26 12:21:57 +02:00
parent a53db1e7b4
commit 40a1723544
29 changed files with 590 additions and 132 deletions

View File

@@ -6,6 +6,7 @@ add_executable(Fall-Fever
ShaderProgram.cpp
VertexArray.cpp
Texture.cpp
TextureFactory.cpp
Camera.cpp
Mesh.cpp
Model.cpp
@@ -22,6 +23,7 @@ add_executable(Fall-Fever
imgui/GeneralInfoWindow.cpp
imgui/Handler.cpp
imgui/Window.cpp
util/Log.cpp
)
target_link_libraries(
@@ -35,6 +37,7 @@ target_link_libraries(
${FREETYPE_LIBRARIES}
imgui
pthread
spdlog
)
target_compile_options(Fall-Fever PRIVATE -Wall -Wextra -pedantic)

View File

@@ -1,4 +1,3 @@
#include <iostream>
#include <vector>
#include <glad/glad.h>
@@ -30,6 +29,7 @@
#include "VertexArray.h"
#include "Widget.h"
#include "Window.h"
#include "util/Log.h"
Controller::Controller() : m_gameWindow(std::unique_ptr<Window>(new Window))
{
@@ -42,7 +42,7 @@ Controller::Controller() : m_gameWindow(std::unique_ptr<Window>(new Window))
for (auto &prototype : shaderProgramPrototypes) {
m_shaderPrograms.push_back(new ShaderProgram(prototype));
std::cout << "Loaded ShaderProgram \"" << prototype.name << "\"" << std::endl;
Log::logger().info("Loaded shaderprogram \"{}\"", prototype.name);
}
m_postProcessFrameBuffer = new FrameBuffer(m_gameWindow->getWindowWidth(), m_gameWindow->getWindowHeight(),
@@ -105,8 +105,8 @@ void Controller::run()
&lightColor, &m_exposure, &intensity);
m_imguiHandler->addImguiWindow(generalWindow);
std::shared_ptr<Imgui::Window> entityWindow = std::make_shared<Imgui::EntityWindow>(m_scene->getEntities());
m_imguiHandler->addImguiWindow(entityWindow);
// std::shared_ptr<Imgui::Window> entityWindow = std::make_shared<Imgui::EntityWindow>(m_scene->getEntities());
// m_imguiHandler->addImguiWindow(entityWindow);
#endif
// This is the game loop
@@ -236,8 +236,7 @@ ShaderProgram *Controller::getShaderProgramByName(const std::string &name, std::
return program;
}
}
std::cout << "[Warning] ShaderProgram could not be found by name \"" << name << "\"" << std::endl;
Log::logger().critical("Shaderprogram could not be found by name \"{}\"", name);
return nullptr;
}

View File

@@ -135,6 +135,10 @@ ModelEntity::ModelEntity(Prototype prototype, Model *model, ShaderProgram *shade
void ModelEntity::draw(glm::mat4 viewProjMatrix, glm::vec3 viewPosition)
{
for (auto &child : m_children)
if (auto childModel = dynamic_cast<ModelEntity *>(child))
childModel->draw(viewProjMatrix, viewPosition);
m_shaderProgram->bind();
glm::mat4 modelViewProj = viewProjMatrix * m_modelMatrix;
@@ -155,6 +159,10 @@ void ModelEntity::draw(glm::mat4 viewProjMatrix, glm::vec3 viewPosition)
void ModelEntity::drawDirectionalShadows(glm::mat4 viewProjMatrix, ShaderProgram *shaderProgram)
{
for (auto &child : m_children)
if (auto childModel = dynamic_cast<ModelEntity *>(child))
childModel->drawDirectionalShadows(viewProjMatrix, shaderProgram);
shaderProgram->bind();
glm::mat4 modelViewProj = viewProjMatrix * m_modelMatrix;
@@ -168,6 +176,10 @@ void ModelEntity::drawDirectionalShadows(glm::mat4 viewProjMatrix, ShaderProgram
void ModelEntity::drawPointShadows(ShaderProgram *shaderProgram)
{
for (auto &child : m_children)
if (auto childModel = dynamic_cast<ModelEntity *>(child))
childModel->drawPointShadows(shaderProgram);
shaderProgram->bind();
shaderProgram->setUniform("u_modelMatrix", m_modelMatrix);

View File

@@ -1,7 +1,6 @@
#include "EventHandler.h"
#include "GLFW/glfw3.h"
#include <iostream>
CameraActionMap EventHandler::s_cameraActionMap = {{CameraAction::Forward, false}, {CameraAction::Backward, false},
{CameraAction::Up, false}, {CameraAction::Down, false},

View File

@@ -1,10 +1,9 @@
#include "FrameBuffer.h"
#include "ShaderProgram.h"
#include "Texture.h"
#include "util/Log.h"
#include <cstddef>
#include <iostream>
AbstractFrameBuffer::~AbstractFrameBuffer()
{}
@@ -99,7 +98,7 @@ void FrameBuffer::generateTextures(uint32_t width, uint32_t height)
glBindTexture(GL_TEXTURE_2D, 0);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
std::cout << "[Error] FrameBuffer is not complete!" << std::endl;
Log::logger().error("Framebuffer not complete");
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
unbind();
@@ -135,7 +134,7 @@ DepthMap::DepthMap(int RESOLUTION)
glReadBuffer(GL_NONE);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
std::cout << "[Error] FrameBuffer is not complete!" << std::endl;
Log::logger().error("Framebuffer not complete");
unbind();
}
@@ -163,7 +162,7 @@ DepthMapCube::DepthMapCube(int RESOLUTION)
glReadBuffer(GL_NONE);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
std::cout << "[Error] FrameBuffer is not complete!" << std::endl;
Log::logger().error("Framebuffer not complete");
unbind();
}

View File

@@ -1,7 +1,7 @@
#include "Helper.h"
#include "util/Log.h"
#include <algorithm>
#include <iostream>
#ifdef __linux__
#include <unistd.h>
@@ -122,13 +122,13 @@ void Helper::gl_debug_callback(GLenum source, GLenum type, GLuint id, GLenum sev
}
if (severity == GL_DEBUG_SEVERITY_HIGH || severity == GL_DEBUG_SEVERITY_MEDIUM)
std::cout << "[OpenGL Debug Message]" << std::endl
<< "Message: " << _message << std::endl
<< "Source: " << _source << std::endl
<< "Type: " << _type << std::endl
<< "ID: " << id << std::endl
<< "Severity: " << _severity << std::endl
<< std::endl;
Log::logger().info("[OpenGL Debug Message]\n"
"Message: {}\n"
"Source: {}\n"
"Type: {}\n"
"ID: {}\n"
"Severity: {}\n",
_message, _source, _type, id, _severity);
}
Helper::Timer::Timer(const std::string &name) : m_name(name)
@@ -143,5 +143,5 @@ Helper::Timer::~Timer()
m_duration = m_end - m_start;
float ms = m_duration.count() * 1000.0f;
std::cout << "Timer " << m_name << " took " << ms << "ms!" << std::endl;
Log::logger().info("Timer {} took {}", m_name, ms);
}

View File

@@ -1,14 +1,14 @@
#include "JsonParser.h"
#include "util/Log.h"
#include <fstream>
#include <iostream>
JsonParser::JsonParser(const std::string &jsonFilepath)
{
std::ifstream file(jsonFilepath.c_str(), std::ifstream::binary);
if (!file) {
std::cout << "Error reading file \"" << jsonFilepath << "\"." << std::endl;
Log::logger().warn("Could not read json file \"{}\"", jsonFilepath);
return;
}
@@ -17,7 +17,7 @@ JsonParser::JsonParser(const std::string &jsonFilepath)
bool parsingSuccessful = Json::parseFromStream(m_rbuilder, file, &m_root, &errs);
file.close();
if (!parsingSuccessful) {
std::cout << "Failed to parse file\n" << errs << std::endl;
Log::logger().warn("Could not parse json file \"{}\":{}", jsonFilepath, errs);
return;
}
}

View File

@@ -7,8 +7,7 @@
#include "Widget.h"
#include "Window.h"
#include "definitions/eventActions.h"
#include <iostream>
#include "util/Log.h"
Menu::Menu(FrameBuffer *p_framebuffer, ShaderProgram *p_shaderProgram)
: m_frameBuffer(p_framebuffer), m_shaderProgram(p_shaderProgram)

View File

@@ -2,10 +2,10 @@
#include "Mesh.h"
#include "ShaderProgram.h"
#include "Texture.h"
#include "util/Log.h"
#include <fstream>
#include <future>
#include <iostream>
uint32_t Model::s_idCounter = 0;
@@ -59,7 +59,7 @@ void Model::loadModel(const std::string &pathToModel)
std::ifstream input(pathToModel, std::ios::in | std::ios::binary);
if (!input.is_open()) {
std::cerr << "Could not find model file " << pathToModel << std::endl;
Log::logger().warn("Could not find model file {}", pathToModel);
return;
}
@@ -94,9 +94,9 @@ void Model::loadModel(const std::string &pathToModel)
for (unsigned int i = 0; i < numTextures; i++) {
std::string texturePath = m_workingPath + '/' + textureSources[i].c_str();
Texture::Prototype texturePrototype{texturePath, textureTypes[i]};
auto loadModel = [=, &mutex]() {
Texture *currentTex = new Texture(texturePrototype.texturePath, texturePrototype.textureType);
Texture *currentTex = new Texture({texturePath, textureTypes[i]});
std::lock_guard<std::mutex> lock(mutex);
m_textures.push_back(currentTex);
@@ -114,7 +114,7 @@ void Model::loadModel(const std::string &pathToModel)
}
if (!hasNormalMap) {
Texture *currentTex = new Texture("data/res/models/tex/fallback_normal.png", TextureType::Normal);
Texture *currentTex = new Texture({"data/res/models/tex/fallback_normal.png", TextureType::Normal});
m_textures.push_back(currentTex);
}

View File

@@ -8,9 +8,9 @@
#include "Model.h"
#include "ShaderProgram.h"
#include "Texture.h"
#include "util/Log.h"
#include <future>
#include <iostream>
#include <thread>
Scene::Scene(std::vector<ShaderProgram *> shaderPrograms)
@@ -41,8 +41,7 @@ Scene::Scene(std::vector<ShaderProgram *> shaderPrograms)
auto loadModel = [=, &mutex]() {
Model *currentModel = new Model(prototype);
std::cout << "Loaded Model \"" << prototype.modelName << "\" from \"" << prototype.modelPath << "\""
<< std::endl;
Log::logger().info("Loaded model \"{}\": {}", prototype.modelName, prototype.modelPath);
std::lock_guard<std::mutex> lock(mutex);
m_models.push_back(currentModel);
@@ -61,7 +60,7 @@ Scene::Scene(std::vector<ShaderProgram *> shaderPrograms)
m_skybox = new Skybox(skyboxPrototype, getModelByName("cube"),
Controller::getShaderProgramByName("skyboxProgram", shaderPrograms));
std::cout << "Loaded Skybox \"" << skyboxPrototype.texturePath << "\"" << std::endl;
Log::logger().info("Loaded skybox: {}", skyboxPrototype.texturePath);
});
std::vector<ModelEntity::Prototype> entityPrototypes = modelParser.getEntityPrototypes();
@@ -74,8 +73,8 @@ Scene::Scene(std::vector<ShaderProgram *> shaderPrograms)
if (!currentModel) {
// Apply fallback model (first model in vector)
currentModel = m_models[0];
std::cout << "[Warning] Model could not be found by name \"" << prototype.modelName << "\""
<< std::endl;
Log::logger().warn("Model could not be found by name \"{}\"", prototype.modelName);
}
// Get shaderprogram
@@ -88,8 +87,7 @@ Scene::Scene(std::vector<ShaderProgram *> shaderPrograms)
ModelEntity *currentEntity = new ModelEntity(prototype, currentModel, currentProgram);
std::cout << "Loaded Entity \"" << prototype.name << "\" with model \"" << prototype.modelName << "\""
<< std::endl;
Log::logger().info("Loaded entity \"{}\" with model \"{}\"", prototype.name, prototype.modelName);
if (!prototype.parent.empty()) {
Entity *parent = getEntityByName(prototype.parent);
@@ -97,9 +95,8 @@ Scene::Scene(std::vector<ShaderProgram *> shaderPrograms)
parent->addChild(currentEntity);
currentEntity->setParent(parent);
}
}
m_entities.push_back(currentEntity);
} else
m_entities.push_back(currentEntity);
}
}
@@ -156,7 +153,7 @@ void Scene::addEntity(ModelEntity *entity)
m_entities.push_back(entity);
}
void Scene::removeEntityByName(std::string name)
void Scene::removeEntityByName(const std::string &name)
{
for (auto it = m_entities.begin(); it != m_entities.end(); it++) {
if ((*it)->getUniqueName() == name) {
@@ -165,7 +162,7 @@ void Scene::removeEntityByName(std::string name)
}
}
std::cout << "[Warning] Entity with name " << name << " could not be removed." << std::endl;
Log::logger().warn("Entity \"{}\" could not be removed", name);
}
void Scene::clearEntities()
@@ -309,25 +306,25 @@ void Scene::calculateShadows(ShaderProgram *directionalShaderProgram, ShaderProg
glCullFace(GL_FRONT);
}
Model *Scene::getModelByName(std::string name)
Model *Scene::getModelByName(const std::string &name)
{
for (auto it = m_models.begin(); it != m_models.end(); it++) {
if ((*it)->getUniqueName() == name) {
return *it;
}
}
std::cout << "[Warning] Model could not be found by unique name \"" << name << "\"" << std::endl;
Log::logger().warn("Model could not be found by unique name \"{}\"", name);
return nullptr;
}
ModelEntity *Scene::getEntityByName(std::string name)
ModelEntity *Scene::getEntityByName(const std::string &name)
{
for (auto it = m_entities.begin(); it != m_entities.end(); it++) {
if ((*it)->getUniqueName() == name) {
return *it;
}
}
std::cout << "[Warning] Entity could not be found by unique name \"" << name << "\"" << std::endl;
Log::logger().warn("Entity could not be found by unique name \"{}\"", name);
return nullptr;
}
@@ -338,7 +335,7 @@ ModelEntity *Scene::getEntityById(uint32_t id)
return *it;
}
}
std::cout << "[Warning] Entity could not be found by ID \"" << id << "\"" << std::endl;
Log::logger().warn("Entity could not be found by ID \"{}\"", id);
return nullptr;
}

View File

@@ -24,7 +24,7 @@ public:
~Scene();
void addEntity(ModelEntity *entity);
void removeEntityByName(std::string name);
void removeEntityByName(const std::string &name);
void clearEntities();
void updatePointLight(unsigned int lightId, bool active, glm::vec3 position, glm::vec3 color, float intensity);
@@ -34,9 +34,9 @@ public:
std::vector<PointLight *> getPointLights();
DirectionalLight *getDirectionalLight();
Skybox *getSkybox();
ModelEntity *getEntityByName(std::string name);
ModelEntity *getEntityByName(const std::string &name);
ModelEntity *getEntityById(uint32_t id);
Model *getModelByName(std::string name);
Model *getModelByName(const std::string &name);
void draw(glm::mat4 viewProjMatrix, glm::vec3 viewPosition);
void calculateShadows(ShaderProgram *directionalShaderProgram, ShaderProgram *pointShaderProgram);

View File

@@ -13,7 +13,7 @@ Screen::Screen(Prototype prototype, FrameBuffer *framebuffer, ShaderProgram *sha
{
for (auto &prototype : prototype.widgetPrototypes) {
auto texturePrototype = prototype.texturePrototype;
Texture *currentTexture = new Texture(texturePrototype.texturePath, texturePrototype.textureType);
Texture *currentTexture = new Texture({texturePrototype.texturePath, texturePrototype.textureType});
currentTexture->initializeOnGPU();
Widget *currentWidget = new Widget(prototype, currentTexture);

View File

@@ -1,10 +1,8 @@
#include "ShaderProgram.h"
#include "util/Log.h"
#include <fstream>
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <iostream>
#include <string>
ShaderProgram::ShaderProgram(Prototype prototype) : m_uniqueName(prototype.name)
{
@@ -29,10 +27,9 @@ ShaderProgram::ShaderProgram(Prototype prototype) : m_uniqueName(prototype.name)
GLint isLinked = 0;
glGetProgramiv(m_shaderProgramId, GL_LINK_STATUS, &isLinked);
if (!isLinked) {
std::cout << "Failed to link shaderProgram: " << prototype.vertexPath << ", " << prototype.geometryPath << ", "
<< prototype.fragmentPath << std::endl;
}
if (!isLinked)
Log::logger().critical("Failed to link shaderProgram \"{}\", \"{}\", \"{}\"", prototype.vertexPath,
prototype.geometryPath, prototype.fragmentPath);
#ifdef _RELEASE
glDetachShader(program, vs);
@@ -69,7 +66,7 @@ std::string ShaderProgram::parse(const std::string &filename)
shaderfile.open(filename, std::ios::in);
if (!shaderfile.is_open()) {
std::cerr << "Shader " << filename << " not found!" << std::endl;
Log::logger().critical("Shader \"{}\" not found", filename);
exit(-1);
}
@@ -92,7 +89,7 @@ GLuint ShaderProgram::compile(const std::string &shaderSource, GLenum type)
glGetShaderiv(shaderId, GL_INFO_LOG_LENGTH, &length);
char *message = new char[length];
glGetShaderInfoLog(shaderId, length, &length, message);
std::cout << "Shader compile error: " << message << std::endl;
Log::logger().error("Shader compilation failed: {}", message);
delete[] message;
return 0;
}

View File

@@ -1,16 +1,15 @@
#include "Texture.h"
#include "ShaderProgram.h"
#include "util/Log.h"
#include <iostream>
Texture::Texture(const std::string &path, TextureType type) : m_texturePath(path), m_textureType(type)
Texture::Texture(const Prototype &texturePrototype)
: m_texturePath(texturePrototype.texturePath), m_textureType(texturePrototype.textureType)
{
stbi_set_flip_vertically_on_load(1);
m_textureBuffer = stbi_load(m_texturePath.c_str(), &m_textureWidth, &m_textureHeight, &m_numComponents, 0);
if (!m_textureBuffer) {
std::cout << "[Warning] Texture " << m_texturePath << " not found!" << std::endl;
return;
}
if (!m_textureBuffer)
Log::logger().warn("Texture {} could not be loaded", m_texturePath);
}
Texture::~Texture()
@@ -20,11 +19,6 @@ Texture::~Texture()
void Texture::initializeOnGPU()
{
if (m_isInitialized)
return;
m_isInitialized = true;
GLenum internalFormat;
GLenum dataFormat;
@@ -111,7 +105,7 @@ std::string Texture::getPath()
return m_texturePath;
}
GLuint Texture::getTextureId()
GLuint Texture::textureId()
{
return m_textureId;
}
@@ -143,7 +137,7 @@ CubeMap::CubeMap(const std::string &texturePseudoPath)
auto textureBuffer = stbi_load(path.c_str(), &m_textureWidth, &m_textureHeight, &numComponents, 0);
if (!textureBuffer) {
std::cout << "[Warning] CubeMap Texture " << path.c_str() << " not found!" << std::endl;
Log::logger().warn("CubeMap texture {} could not be loaded", path);
return;
}

View File

@@ -31,20 +31,22 @@ public:
TextureType textureType;
};
Texture(const std::string &path, TextureType type);
~Texture();
void initializeOnGPU();
void bind(uint8_t textureUnit, ShaderProgram *shaderProgram, uint8_t textureTypeNum);
void unbind();
TextureType getTextureType();
std::string getPath();
GLuint getTextureId();
GLuint textureId();
Texture(const Prototype &texturePrototype); // TODO make private
void initializeOnGPU(); // TODO make private
~Texture(); // TODO make private
private:
bool m_isInitialized = false;
Texture(const Texture &other) = delete;
Texture(Texture &&other) = delete;
Texture &operator=(const Texture &other) = delete;
Texture &operator=(Texture &&other) = delete;
std::string m_texturePath;
@@ -54,9 +56,11 @@ private:
int32_t m_textureHeight;
int32_t m_numComponents;
GLuint m_textureId;
GLuint m_textureId; // TODO inherit from abstract class resource
TextureType m_textureType;
friend class TextureFactory;
};
class CubeMap

20
src/TextureFactory.cpp Normal file
View File

@@ -0,0 +1,20 @@
#include "TextureFactory.h"
TextureFactory &TextureFactory::instance()
{
static TextureFactory instance;
return instance;
}
void TextureFactory::registerTexture(const Texture::Prototype &prototype)
{
auto texture = std::make_unique<Texture>(prototype);
m_textureMap.insert({texture->textureId(), std::move(texture)});
}
std::unique_ptr<Texture> TextureFactory::texture(uint64_t resourceId)
{
auto texture = std::move(m_textureMap.at(resourceId));
texture->initializeOnGPU();
return texture;
}

18
src/TextureFactory.h Normal file
View File

@@ -0,0 +1,18 @@
#pragma once
#include "Texture.h"
#include <map>
#include <memory>
class TextureFactory // TODO not yet used
{
public:
static TextureFactory &instance();
void registerTexture(const Texture::Prototype &prototype);
std::unique_ptr<Texture> texture(uint64_t resourceId);
private:
std::map<uint64_t, std::unique_ptr<Texture>> m_textureMap;
};

View File

@@ -41,7 +41,7 @@ void Widget::draw(ShaderProgram *shaderProgram)
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_widgetTextures[0]->getTextureId());
glBindTexture(GL_TEXTURE_2D, m_widgetTextures[0]->textureId());
GLint location = glGetUniformLocation(shaderProgram->getShaderProgramId(), "u_texture");
glUniform1i(location, 0);

View File

@@ -2,16 +2,15 @@
#include "Helper.h"
#include "ShaderProgram.h"
#include "definitions/window.h"
#include "util/Log.h"
#include <GLFW/glfw3.h>
#include <iostream>
Window::Window()
{
// Initialize GLFW
if (!glfwInit()) {
if (!glfwInit())
exit(-1);
}
m_width = INIT_WINDOW_WIDTH;
m_height = INIT_WINDOW_HEIGHT;
@@ -29,12 +28,11 @@ Window::Window()
#endif
m_window = glfwCreateWindow(m_width, m_height, "OpenGL", NULL, NULL);
if (!m_window) {
std::cout << "Failed to create window" << std::endl;
}
if (!m_window)
Log::logger().critical("Failed to create window");
// Wait for window to maximize (in case)
Helper::sleep(1000);
// Helper::sleep(1000);
glfwGetWindowPos(m_window, &m_posX, &m_posY);
glfwGetWindowSize(m_window, &m_width, &m_height);
@@ -44,12 +42,12 @@ Window::Window()
// Initialize GLAD
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
std::cout << "Failed to initialize GLAD" << std::endl;
Log::logger().critical("Failed to initialize GLAD");
exit(-1);
}
#ifdef _DEBUG
std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl;
Log::logger().debug("OpenGL version: {}", glGetString(GL_VERSION));
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
glDebugMessageCallback(Helper::gl_debug_callback, NULL);

View File

@@ -3,7 +3,7 @@
#include <imgui.h>
Imgui::EntityWindow::EntityWindow(const std::vector<ModelEntity *> &entities) : Window("Entities"), m_entites(entities)
Imgui::EntityWindow::EntityWindow(const std::vector<ModelEntity *> entities) : Window("Entities"), m_entites(entities)
{}
void Imgui::EntityWindow::addWidgets()
@@ -11,21 +11,28 @@ void Imgui::EntityWindow::addWidgets()
ImGui::Text("Treelist");
for (const auto &entity : m_entites) {
// addChildWidget(*entity);
addChildWidget(*entity);
}
}
void Imgui::EntityWindow::addChildWidget(const ModelEntity &entity)
{
if (entity.getChildren().empty()) {
ImGui::Indent();
ImGui::Text(entity.getUniqueName().c_str());
ImGui::SameLine();
ImGui::SmallButton("Edit");
ImGui::Unindent();
} else {
if (ImGui::TreeNode(entity.getUniqueName().c_str())) {
bool expanded = ImGui::TreeNode(entity.getUniqueName().c_str());
ImGui::SameLine();
ImGui::SmallButton("Edit");
if (expanded) {
for (const auto &child : entity.getChildren()) {
addChildWidget(*(const ModelEntity *)child);
}
ImGui::TreePop();
ImGui::Separator();
}
}
}

View File

@@ -11,14 +11,14 @@ namespace Imgui {
class EntityWindow : public Window
{
public:
EntityWindow(const std::vector<ModelEntity *> &entities);
EntityWindow(const std::vector<ModelEntity *> entities);
private:
void addWidgets() override;
static void addChildWidget(const ModelEntity &entity);
const std::vector<ModelEntity *> &m_entites;
const std::vector<ModelEntity *> m_entites;
};
} // namespace Imgui

17
src/util/Log.cpp Normal file
View File

@@ -0,0 +1,17 @@
#include "Log.h"
#include <spdlog/sinks/stdout_color_sinks.h>
Log Log::s_instance;
Log::Log()
{
m_logger = spdlog::stdout_color_mt("Core");
m_logger->set_level(spdlog::level::debug);
// m_logger->set_pattern("");
}
spdlog::logger &Log::logger()
{
return *s_instance.m_logger;
}

16
src/util/Log.h Normal file
View File

@@ -0,0 +1,16 @@
#pragma once
#include <spdlog/spdlog.h>
class Log
{
public:
static spdlog::logger &logger();
private:
Log();
static Log s_instance;
std::shared_ptr<spdlog::logger> m_logger;
};