Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/common/asset-loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "audio/audio-buffer.hpp"
#include "audio/audio-utils.hpp"
#include "deserialize-utils.hpp"
#include "logger.hpp"
#include "material/material.hpp"
#include "mesh/mesh-utils.hpp"
#include "mesh/mesh.hpp"
Expand All @@ -28,6 +29,8 @@ namespace our {
shader->attach(fsPath, GL_FRAGMENT_SHADER);
shader->link();
assets[name] = shader;
LOG_DEBUG("AssetLoader", "Loaded shader \"%s\" with vs: \"%s\" and fs: \"%s\"", name.c_str(),
vsPath.c_str(), fsPath.c_str());
}
}
};
Expand All @@ -41,6 +44,7 @@ namespace our {
for (auto& [name, desc] : data.items()) {
std::string path = desc.get<std::string>();
assets[name] = texture_utils::loadImage(path);
LOG_DEBUG("AssetLoader", "Loaded texture \"%s\" from path: \"%s\"", name.c_str(), path.c_str());
}
}
};
Expand All @@ -59,6 +63,7 @@ namespace our {
auto sampler = new Sampler();
sampler->deserialize(desc);
assets[name] = sampler;
LOG_DEBUG("AssetLoader", "Loaded sampler \"%s\"", name.c_str());
}
}
};
Expand All @@ -72,6 +77,7 @@ namespace our {
for (auto& [name, desc] : data.items()) {
std::string path = desc.get<std::string>();
assets[name] = mesh_utils::loadOBJ(path);
LOG_DEBUG("AssetLoader", "Loaded mesh \"%s\" from path: \"%s\"", name.c_str(), path.c_str());
}
}
};
Expand All @@ -98,6 +104,7 @@ namespace our {
auto material = createMaterialFromType(type);
material->deserialize(desc);
assets[name] = material;
LOG_DEBUG("AssetLoader", "Loaded material \"%s\" of type \"%s\"", name.c_str(), type.c_str());
}
}
};
Expand All @@ -112,6 +119,7 @@ namespace our {
std::string path = desc.get<std::string>();
AudioBuffer* buffer = audio_utils::loadWAV(path);
if (buffer) assets[name] = buffer;
LOG_DEBUG("AssetLoader", "Loaded audio buffer \"%s\" from path: \"%s\"", name.c_str(), path.c_str());
}
}
}
Expand All @@ -123,6 +131,7 @@ namespace our {
our::Light* light = new our::Light();
light->deserialize(desc);
assets[name] = light;
LOG_DEBUG("AssetLoader", "Loaded light \"%s\"", name.c_str());
}
}
}
Expand All @@ -148,6 +157,8 @@ namespace our {
}

assets[name] = model;
LOG_DEBUG("AssetLoader", "Loaded model \"%s\" from path: \"%s\"", name.c_str(),
desc.get<std::string>().c_str());
}
}
};
Expand Down
44 changes: 44 additions & 0 deletions src/common/logger.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once

#include <cstdarg>
#include <cstdio>
#include <iostream>
#include <string>
#include <string_view>

#define LOG_COLOR_RESET "\033[0m"
#define LOG_COLOR_RED "\033[1;31m"
#define LOG_COLOR_YELLOW "\033[1;33m"
#define LOG_COLOR_BLUE "\033[1;34m"
#define LOG_COLOR_CYAN "\033[0;36m"

namespace our::log {

inline void log_impl(std::ostream& out, const char* color, std::string_view module, const char* fmt, ...) {
out << color << '[' << module << ']' << LOG_COLOR_RESET << ": ";

va_list args;
va_start(args, fmt);
// vfprintf directly to the underlying stream buffer — no heap alloc
if (&out == &std::cout)
std::vfprintf(stdout, fmt, args);
else if (&out == &std::cerr)
std::vfprintf(stderr, fmt, args);
va_end(args);

out << '\n';
}

} // namespace our::log

#define LOG_ERROR(mod, fmt, ...) our::log::log_impl(std::cerr, LOG_COLOR_RED, mod, fmt, ##__VA_ARGS__)
#define LOG_WARN(mod, fmt, ...) our::log::log_impl(std::cerr, LOG_COLOR_YELLOW, mod, fmt, ##__VA_ARGS__)
#define LOG_INFO(mod, fmt, ...) our::log::log_impl(std::cout, LOG_COLOR_BLUE, mod, fmt, ##__VA_ARGS__)

#ifndef NDEBUG
#define LOG_DEBUG(mod, fmt, ...) our::log::log_impl(std::cout, LOG_COLOR_CYAN, mod, fmt, ##__VA_ARGS__)
#else
#define LOG_DEBUG(...) \
do { \
} while (0)
#endif
Loading