2#include <nlohmann/json.hpp>
6using namespace std::filesystem;
46 nlohmann::json appConfigData = nlohmann::json::parse(f);
48 if (appConfigData.contains(
"appName"))
49 cfg.
appName = appConfigData[
"appName"].get<std::string>();
51 if (appConfigData.contains(
"isFullScreen"))
52 cfg.
isFullScreen = appConfigData[
"isFullScreen"].get<
bool>();
54 if (appConfigData.contains(
"screenWidth"))
55 cfg.
screenWidth = appConfigData[
"screenWidth"].get<
float>();
57 if (appConfigData.contains(
"screenHeight"))
58 cfg.
screenHeight = appConfigData[
"screenHeight"].get<
float>();
60 if (appConfigData.contains(
"text"))
62 const auto& textNode = appConfigData[
"text"];
64 if (textNode.contains(
"scripts") && textNode[
"scripts"].is_array())
66 for (
const auto& script : textNode[
"scripts"])
68 if (script.is_string())
73 cfg.
textScripts.push_back(script.get<std::string>());
79 if (textNode.contains(
"fontSizePreload") && textNode[
"fontSizePreload"].is_array())
81 for (
const auto& fontSize : textNode[
"fontSizePreload"])
92 if (appConfigData.contains(
"logLevel"))
93 cfg.
logLevel = appConfigData[
"logLevel"].get<std::string>();
95 if (appConfigData.contains(
"useSmoothedFPS"))
98 if (appConfigData.contains(
"targetFPS"))
99 cfg.
targetFPS = appConfigData[
"targetFPS"].get<
float>();
101 if (appConfigData.contains(
"showStatsOverlay"))
105 catch (
const std::exception& e)
115 std::ifstream file(filename, std::ios::ate | std::ios::binary);
119 throw std::runtime_error(
"failed to open shader binary file!");
122 size_t fileSize = (size_t) file.tellg();
123 std::vector<char> buffer(fileSize);
126 file.read(buffer.data(), fileSize);
135 std::vector<std::string> shaderFileNames;
140 if( std::filesystem::exists( std::filesystem::path( directory ) ) && std::filesystem::is_directory(std::filesystem::path( directory ) ) )
142 std::filesystem::path pathToDirectory = std::filesystem::path( directory );
144 if(std::filesystem::is_directory( pathToDirectory ) )
146 for(
const std::filesystem::directory_entry& x : std::filesystem::directory_iterator( pathToDirectory ) )
148 size_t dot = x.path().string().find_last_of(
"." );
150 if( std::string{
"spv" } == x.path().string().substr( dot + 1 ) )
152 std::cout <<
"Shader binary file: " << x.path().string() <<
"\n";
153 shaderFileNames.push_back( x.path().string() );
159 catch(
const std::filesystem::filesystem_error& ex )
161 std::cout << ex.what() <<
'\n';
164 return shaderFileNames;
183std::filesystem::path Utility::FindPath(std::string fileOrFolderName, std::string searchingFrom)
185 std::filesystem::path result;
186 for(
const std::filesystem::directory_entry& entry : std::filesystem::directory_iterator(searchingFrom) )
188 if( entry.path().filename().string() == fileOrFolderName )
190 result = entry.path();
199 std::vector<std::string> imageFileNames;
204 if(std::filesystem::exists(std::filesystem::path(directory)) && std::filesystem::is_directory(std::filesystem::path(directory)) )
206 std::filesystem::path pathToDirectory = std::filesystem::path(directory);
208 if(std::filesystem::is_directory(pathToDirectory) )
210 for(
const std::filesystem::directory_entry& x : std::filesystem::directory_iterator(pathToDirectory) )
212 size_t dot = x.path().string().find_last_of(
".");
214 if( extToSearch == x.path().string().substr(dot + 1) )
216 imageFileNames.push_back(x.path().string());
222 catch(
const std::filesystem::filesystem_error& ex )
224 std::cout << ex.what() <<
'\n';
227 return imageFileNames;
232 auto exeDir = std::filesystem::canonical(std::filesystem::path(std::filesystem::current_path()));
233 if (exeDir.filename() ==
"Debug" || exeDir.filename() ==
"Release")
234 exeDir = exeDir.parent_path();
235 if (exeDir.filename() ==
"Binaries")
236 exeDir = exeDir.parent_path();
292 if (!std::filesystem::exists(jsonPath))
299 std::ifstream f(jsonPath.string());
302 std::cerr <<
"[ERROR] Failed to open Pack.json\n";
311 for (
auto it = j.begin(); it != j.end(); ++it)
314 entry.
offset = it.value().value(
"offset", 0);
315 entry.
size = it.value().value(
"size", 0);
325 std::vector<std::uint8_t> data;
333 if (!std::filesystem::exists(binPath) ||
334 !std::filesystem::exists(jsonPath))
336 std::cerr <<
"[Utility::ReadPackedFile] Missing Pack.bin or Pack.json\n";
345 std::cerr <<
"[Utility::ReadPackedFile] No such packed entry: "
346 << entryPath << std::endl;
352 std::ifstream bin(binPath.string(), std::ios::binary);
355 std::cerr <<
"[Utility::ReadPackedFile] Failed to open Pack.bin: "
356 << binPath.string() << std::endl;
362 data.resize(entry.
size);
364 bin.seekg(entry.
offset, std::ios::beg);
367 std::cerr <<
"[Utility::ReadPackedFile] Seek error for entry: "
368 << entryPath << std::endl;
372 bin.read(
reinterpret_cast<char*
>(data.data()), entry.
size);
375 std::cerr <<
"[Utility::ReadPackedFile] Read error for entry: "
376 << entryPath << std::endl;
static std::vector< std::string > GetListOfFileNamesInDirectory(const char *directory, std::string extToSearch)
Returns a list of file names in a directory matching the specified extension.
static std::vector< char > ReadShaderBinaryFile(std::string const &filename)
Reads a binary shader file from disk.
static std::filesystem::path GetShadersBinaryPath()
Returns the directory path containing compiled shader binaries.
static std::filesystem::path sApplicationPath
static std::filesystem::path sBuildPath
static std::filesystem::path GetConfigFilePath()
Returns absolute path to Config/app_config.json.
static std::filesystem::path GetTextureFolderPath()
Returns absolute path to Content/Textures.
static std::filesystem::path GetFontsFolderPath()
Returns absolute path to Content/Fonts.
static std::filesystem::path ResolveProjectRoot()
Resolves project root folder (handles Release/Debug/Binaries layouts).
static std::filesystem::path const sContentRelativePathFolder
static std::filesystem::path GetLogsFolderPath()
Returns absolute path to Logs folder.
static std::filesystem::path const sDefaultShadersBinaryRelativePath
static std::filesystem::path const sAppConfigFilePath
static const PackEntries & GetPackEntries()
Returns the manifest of packed files.
static std::vector< std::string > GetListOfFilesInDirectory(std::string directory)
Returns a list of full file paths in the given directory.
static std::filesystem::path GetApplicationPath()
Returns the absolute path of the running application.
static std::filesystem::path const sContentPackageFilePath
static std::filesystem::path const sLogFolderPath
static std::filesystem::path GetContentFolderPath()
Returns absolute path to Content.
static AppConfig ReadConfigFile()
Reads application settings from the JSON config file.
static std::filesystem::path const sTextureRelativePathFolder
static std::filesystem::path const sContentPackEntriesFilePath
static std::filesystem::path const sShadersRelativePathFolder
static std::filesystem::path const sFontsRelativePathFolder
static std::filesystem::path const sModelsRelativePathFolder
static std::filesystem::path GetModelsFolderPath()
Returns absolute path to Content/Models.
static std::filesystem::path GetBuildPath()
Returns the build output directory path.
static std::filesystem::path sShadersBinaryPath
static std::vector< uint8_t > ReadPackedFile(const std::string &entryPath)
Reads raw bytes of a file stored inside Pack.bin.
static bool IsPackageProvided()
Checks whether packed assets (Pack.bin / Pack.json) exist.
static void InitializePaths(int argc, char *argv[])
Initializes engine paths based on the executable location.
static std::filesystem::path GetShadersFolderPath()
Returns absolute path to Content/Shaders.
static PackEntries sPackEntries
std::unordered_map< std::string, PackEntry > PackEntries
static bool sPackEntriesLoaded
Basic application settings loaded from a configuration file.
float targetFPS
Target frame rate (0 = uncapped).
float screenWidth
Desired window width in pixels (ignored in full-screen mode).
bool isFullScreen
Whether the application should start in full-screen mode.
std::string appName
Name of the application.
bool useSmoothedFPS
Enable FPS smoothing and frame pacing behavior.
bool showStatsOverlay
Enable on-screen statistics overlay.
float screenHeight
Desired window height in pixels (ignored in full-screen mode).
std::vector< std::string > textScripts
Unicode scripts to preload for text rendering.
std::string logLevel
Logging verbosity level ("Error", "Warning", "Info", "Debug").
std::vector< int > fontSizePreload
Font sizes to preload at startup.
Metadata describing one file stored inside a packed asset archive.