MCPcopy Create free account
hub / github.com/atraczyk/2d-engine / resolveResourcePath

Function resolveResourcePath

engine/src/utils.cpp:92–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92std::string resolveResourcePath(const std::string &relativePath) {
93 if (relativePath.empty()) {
94 return relativePath;
95 }
96
97 const std::string normalizedRelative = normalizePath(relativePath);
98 std::vector<std::string> roots;
99
100 const char *envRoot = std::getenv("ENGINE_RESOURCE_ROOT");
101 if (envRoot && envRoot[0] != '\0') {
102 roots.push_back(envRoot);
103 }
104
105 char *basePath = SDL_GetBasePath();
106 if (basePath) {
107 roots.push_back(std::string(basePath) + "resources");
108 roots.push_back(basePath);
109 SDL_free(basePath);
110 }
111
112 roots.push_back("resources");
113 roots.push_back(".");
114
115 for (const std::string &root : roots) {
116 const std::string candidate = buildCandidate(root, normalizedRelative);
117 if (fileExists(candidate)) {
118 return candidate;
119 }
120 }
121
122 return normalizedRelative;
123}
124
125std::string resolveResourcePath(const char *relativePath) {
126 return resolveResourcePath(std::string(relativePath ? relativePath : ""));

Callers 8

loadLevelMethod · 0.85
loadTextureARGBfromfileFunction · 0.85
initializeTexturesMethod · 0.85
loadConfigMethod · 0.85
loadMethod · 0.85
loadMethod · 0.85
loadFromFileMethod · 0.85
textFileReadFunction · 0.85

Calls 3

normalizePathFunction · 0.85
buildCandidateFunction · 0.85
fileExistsFunction · 0.85

Tested by

no test coverage detected