mirror of
https://github.com/JoeyDeVries/LearnOpenGL.git
synced 2026-01-02 04:37:54 +08:00
Using CMake's configure_file command to generate a header file defining a C string containing the path to the source root directory; the directory where the resource folder is. Textures and models can now be found directly as long the user doesn't move stuff around. Shaders are still a problem.
52 lines
1.2 KiB
C++
52 lines
1.2 KiB
C++
#ifndef FILESYSTEM_H
|
|
#define FILESYSTEM_H
|
|
|
|
#include <string>
|
|
#include "root_directory.h" // This is a configuration file generated by CMake.
|
|
|
|
class FileSystem
|
|
{
|
|
private:
|
|
typedef std::string (*Builder) (const std::string& path);
|
|
|
|
public:
|
|
static std::string getPath(const std::string& path)
|
|
{
|
|
static std::string(*pathBuilder)(std::string const &) = getPathBuilder();
|
|
return (*pathBuilder)(path);
|
|
}
|
|
|
|
private:
|
|
static std::string const & getRoot()
|
|
{
|
|
static char const * envRoot = getenv("LOGL_ROOT_PATH");
|
|
static char const * givenRoot {envRoot != nullptr ? envRoot : logl_root};
|
|
static std::string root {givenRoot != nullptr ? givenRoot : ""};
|
|
return root;
|
|
}
|
|
|
|
//static std::string(*foo (std::string const &)) getPathBuilder()
|
|
static Builder getPathBuilder()
|
|
{
|
|
if (getRoot() != "")
|
|
return &FileSystem::getPathRelativeRoot;
|
|
else
|
|
return &FileSystem::getPathRelativeBinary;
|
|
}
|
|
|
|
static std::string getPathRelativeRoot(const std::string& path)
|
|
{
|
|
return getRoot() + std::string("/") + path;
|
|
}
|
|
|
|
static std::string getPathRelativeBinary(const std::string& path)
|
|
{
|
|
return "../../../" + path;
|
|
}
|
|
|
|
|
|
};
|
|
|
|
// FILESYSTEM_H
|
|
#endif
|