2#include <nlohmann/json.hpp>
6using namespace boost::filesystem;
44 nlohmann::json appConfigData = nlohmann::json::parse(f);
46 if (appConfigData.contains(
"appName"))
47 cfg.
appName = appConfigData[
"appName"].get<std::string>();
49 if (appConfigData.contains(
"isFullScreen"))
50 cfg.
isFullScreen = appConfigData[
"isFullScreen"].get<
bool>();
52 if (appConfigData.contains(
"screenWidth"))
53 cfg.
screenWidth = appConfigData[
"screenWidth"].get<
float>();
55 if (appConfigData.contains(
"screenHeight"))
56 cfg.
screenHeight = appConfigData[
"screenHeight"].get<
float>();
58 catch (
const std::exception& e)
68 std::ifstream file(filename, std::ios::ate | std::ios::binary);
72 throw std::runtime_error(
"failed to open shader binary file!");
75 size_t fileSize = (size_t) file.tellg();
76 std::vector<char> buffer(fileSize);
79 file.read(buffer.data(), fileSize);
88 std::vector<std::string> shaderFileNames;
93 if( boost::filesystem::exists( boost::filesystem::path( directory ) ) && boost::filesystem::is_directory( boost::filesystem::path( directory ) ) )
95 boost::filesystem::path pathToDirectory = boost::filesystem::path( directory );
97 if( boost::filesystem::is_directory( pathToDirectory ) )
99 for( boost::filesystem::directory_entry& x : boost::filesystem::directory_iterator( pathToDirectory ) )
101 size_t dot = x.path().string().find_last_of(
"." );
103 if( std::string{
"spv" } == x.path().
string().substr( dot + 1 ) )
105 std::cout <<
"Shader binary file: " << x.path().string() <<
"\n";
106 shaderFileNames.push_back( x.path().string() );
112 catch(
const boost::filesystem::filesystem_error& ex )
114 std::cout << ex.what() <<
'\n';
117 return shaderFileNames;
136boost::filesystem::path Utility::FindPath(std::string fileOrFolderName, std::string searchingFrom)
138 boost::filesystem::path result;
139 for( boost::filesystem::directory_entry& x : boost::filesystem::directory_iterator(searchingFrom) )
141 if( x.path().filename().string() == fileOrFolderName )
143 result = x.path().generic_path();
151 std::vector<std::string> imageFileNames;
156 if( boost::filesystem::exists(boost::filesystem::path(directory)) && boost::filesystem::is_directory(boost::filesystem::path(directory)) )
158 boost::filesystem::path pathToDirectory = boost::filesystem::path(directory);
160 if( boost::filesystem::is_directory(pathToDirectory) )
162 for( boost::filesystem::directory_entry& x : boost::filesystem::directory_iterator(pathToDirectory) )
164 size_t dot = x.path().string().find_last_of(
".");
166 if( extToSearch == x.path().string().substr(dot + 1) )
168 imageFileNames.push_back(x.path().string());
174 catch(
const boost::filesystem::filesystem_error& ex )
176 std::cout << ex.what() <<
'\n';
179 return imageFileNames;
184 auto exeDir = boost::filesystem::canonical(boost::filesystem::path(boost::filesystem::current_path()));
185 if (exeDir.filename() ==
"Debug" || exeDir.filename() ==
"Release")
186 exeDir = exeDir.parent_path();
187 if (exeDir.filename() ==
"Binaries")
188 exeDir = exeDir.parent_path();
229 if (!boost::filesystem::exists(jsonPath))
236 std::ifstream f(jsonPath.string());
239 std::cerr <<
"[ERROR] Failed to open Pack.json\n";
248 for (
auto it = j.begin(); it != j.end(); ++it)
251 entry.
offset = it.value().value(
"offset", 0);
252 entry.
size = it.value().value(
"size", 0);
262 std::vector<std::uint8_t> data;
270 if (!boost::filesystem::exists(binPath) ||
271 !boost::filesystem::exists(jsonPath))
273 std::cerr <<
"[Utility::ReadPackedFile] Missing Pack.bin or Pack.json\n";
282 std::cerr <<
"[Utility::ReadPackedFile] No such packed entry: "
283 << entryPath << std::endl;
289 std::ifstream bin(binPath.string(), std::ios::binary);
292 std::cerr <<
"[Utility::ReadPackedFile] Failed to open Pack.bin: "
293 << binPath.string() << std::endl;
299 data.resize(entry.
size);
301 bin.seekg(entry.
offset, std::ios::beg);
304 std::cerr <<
"[Utility::ReadPackedFile] Seek error for entry: "
305 << entryPath << std::endl;
309 bin.read(
reinterpret_cast<char*
>(data.data()), entry.
size);
312 std::cerr <<
"[Utility::ReadPackedFile] Read error for entry: "
313 << 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 std::vector< std::string > GetListOfFilesInDirectory(std::string directory)
Returns a list of full file paths in the given directory.
static boost::filesystem::path const sContentPackageFilePath
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 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 PackEntries sPackEntries
std::unordered_map< std::string, PackEntry > PackEntries
static bool sPackEntriesLoaded
Basic application settings loaded from a configuration file.
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.
float screenHeight
Desired window height in pixels (ignored in full-screen mode).
Metadata describing one file stored inside a packed asset archive.