2#include <nlohmann/json.hpp>
6using namespace boost::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( boost::filesystem::exists( boost::filesystem::path( directory ) ) && boost::filesystem::is_directory( boost::filesystem::path( directory ) ) )
142 boost::filesystem::path pathToDirectory = boost::filesystem::path( directory );
144 if( boost::filesystem::is_directory( pathToDirectory ) )
146 for( boost::filesystem::directory_entry& x : boost::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 boost::filesystem::filesystem_error& ex )
161 std::cout << ex.what() <<
'\n';
164 return shaderFileNames;
183boost::filesystem::path Utility::FindPath(std::string fileOrFolderName, std::string searchingFrom)
185 boost::filesystem::path result;
186 for( boost::filesystem::directory_entry& x : boost::filesystem::directory_iterator(searchingFrom) )
188 if( x.path().filename().string() == fileOrFolderName )
190 result = x.path().generic_path();
198 std::vector<std::string> imageFileNames;
203 if( boost::filesystem::exists(boost::filesystem::path(directory)) && boost::filesystem::is_directory(boost::filesystem::path(directory)) )
205 boost::filesystem::path pathToDirectory = boost::filesystem::path(directory);
207 if( boost::filesystem::is_directory(pathToDirectory) )
209 for( boost::filesystem::directory_entry& x : boost::filesystem::directory_iterator(pathToDirectory) )
211 size_t dot = x.path().string().find_last_of(
".");
213 if( extToSearch == x.path().string().substr(dot + 1) )
215 imageFileNames.push_back(x.path().string());
221 catch(
const boost::filesystem::filesystem_error& ex )
223 std::cout << ex.what() <<
'\n';
226 return imageFileNames;
231 auto exeDir = boost::filesystem::canonical(boost::filesystem::path(boost::filesystem::current_path()));
232 if (exeDir.filename() ==
"Debug" || exeDir.filename() ==
"Release")
233 exeDir = exeDir.parent_path();
234 if (exeDir.filename() ==
"Binaries")
235 exeDir = exeDir.parent_path();
291 if (!boost::filesystem::exists(jsonPath))
298 std::ifstream f(jsonPath.string());
301 std::cerr <<
"[ERROR] Failed to open Pack.json\n";
310 for (
auto it = j.begin(); it != j.end(); ++it)
313 entry.
offset = it.value().value(
"offset", 0);
314 entry.
size = it.value().value(
"size", 0);
324 std::vector<std::uint8_t> data;
332 if (!boost::filesystem::exists(binPath) ||
333 !boost::filesystem::exists(jsonPath))
335 std::cerr <<
"[Utility::ReadPackedFile] Missing Pack.bin or Pack.json\n";
344 std::cerr <<
"[Utility::ReadPackedFile] No such packed entry: "
345 << entryPath << std::endl;
351 std::ifstream bin(binPath.string(), std::ios::binary);
354 std::cerr <<
"[Utility::ReadPackedFile] Failed to open Pack.bin: "
355 << binPath.string() << std::endl;
361 data.resize(entry.
size);
363 bin.seekg(entry.
offset, std::ios::beg);
366 std::cerr <<
"[Utility::ReadPackedFile] Seek error for entry: "
367 << entryPath << std::endl;
371 bin.read(
reinterpret_cast<char*
>(data.data()), entry.
size);
374 std::cerr <<
"[Utility::ReadPackedFile] Read error for entry: "
375 << entryPath << std::endl;
static boost::filesystem::path GetConfigFilePath()
Returns absolute path to Config/app_config.json.
static boost::filesystem::path GetShadersFolderPath()
Returns absolute path to Content/Shaders.
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 boost::filesystem::path GetApplicationPath()
Returns the absolute path of the running application.
static boost::filesystem::path GetShadersBinaryPath()
Returns the directory path containing compiled shader binaries.
static boost::filesystem::path sApplicationPath
static boost::filesystem::path sBuildPath
static boost::filesystem::path ResolveProjectRoot()
Resolves project root folder (handles Release/Debug/Binaries layouts).
static boost::filesystem::path GetBuildPath()
Returns the build output directory path.
static boost::filesystem::path const sContentRelativePathFolder
static boost::filesystem::path const sDefaultShadersBinaryRelativePath
static boost::filesystem::path const sAppConfigFilePath
static const PackEntries & GetPackEntries()
Returns the manifest of packed files.
static boost::filesystem::path GetFontsFolderPath()
Returns absolute path to Content/Fonts.
static std::vector< std::string > GetListOfFilesInDirectory(std::string directory)
Returns a list of full file paths in the given directory.
static boost::filesystem::path GetLogsFolderPath()
Returns absolute path to Logs folder.
static boost::filesystem::path const sContentPackageFilePath
static boost::filesystem::path const sLogFolderPath
static AppConfig ReadConfigFile()
Reads application settings from the JSON config file.
static boost::filesystem::path const sTextureRelativePathFolder
static boost::filesystem::path GetTextureFolderPath()
Returns absolute path to Content/Textures.
static boost::filesystem::path const sContentPackEntriesFilePath
static boost::filesystem::path const sShadersRelativePathFolder
static boost::filesystem::path const sFontsRelativePathFolder
static boost::filesystem::path const sModelsRelativePathFolder
static boost::filesystem::path sShadersBinaryPath
static std::vector< uint8_t > ReadPackedFile(const std::string &entryPath)
Reads raw bytes of a file stored inside Pack.bin.
static boost::filesystem::path GetModelsFolderPath()
Returns absolute path to Content/Models.
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 boost::filesystem::path GetContentFolderPath()
Returns absolute path to Content.
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.