Skip to content

Commit c9cefb0

Browse files
committed
Simple input system and changed all the absolute paths
1 parent 58b1862 commit c9cefb0

File tree

2 files changed

+139
-0
lines changed

2 files changed

+139
-0
lines changed

.gitignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Compiled Object files
5+
*.slo
6+
*.lo
7+
*.o
8+
*.obj
9+
10+
# Precompiled Headers
11+
*.gch
12+
*.pch
13+
14+
# Compiled Dynamic libraries
15+
*.so
16+
*.dylib
17+
*.dll
18+
19+
# Fortran module files
20+
*.mod
21+
*.smod
22+
23+
# Compiled Static libraries
24+
*.lai
25+
*.la
26+
*.a
27+
*.lib
28+
29+
# Executables
30+
*.exe
31+
*.out
32+
*.app

src/Systems/OS.hpp

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//
2+
3+
// Created by carlo on 2024-11-22.
4+
//
5+
6+
#ifndef OS_HPP
7+
#define OS_HPP
8+
9+
namespace SYSTEMS
10+
{
11+
12+
class OS
13+
{
14+
public:
15+
OS()
16+
{
17+
workingDir = std::filesystem::current_path();
18+
projectPath = GetProjectPath(workingDir);
19+
shadersPath = projectPath / "src" / "Shaders";
20+
assetsPath = projectPath / "Resources"/"Assets";
21+
engineResourcesPath = projectPath / "Resources"/"Engine";
22+
23+
}
24+
25+
26+
static OS* GetInstance()
27+
{
28+
if (instance == nullptr)
29+
{
30+
instance = new OS;
31+
}
32+
return instance;
33+
}
34+
35+
std::string ReadFile(std::string path)
36+
{
37+
std::ifstream inFile(path);
38+
std::string data;
39+
40+
while (std::getline(inFile, data))
41+
{
42+
}
43+
return data;
44+
}
45+
46+
std::filesystem::path GetProjectPath(std::filesystem::path& workDir)
47+
{
48+
std::filesystem::path projectPath = workDir;
49+
bool solutionPathFind = false;
50+
while (!solutionPathFind)
51+
{
52+
for (auto element : std::filesystem::directory_iterator(projectPath))
53+
{
54+
if (element.path().filename() == ".gitignore")
55+
{
56+
solutionPathFind = true;
57+
break;
58+
}
59+
}
60+
if (solutionPathFind)
61+
{
62+
break;
63+
}
64+
65+
projectPath = projectPath.parent_path();
66+
if (projectPath == workDir.root_path())
67+
{
68+
break;
69+
}
70+
}
71+
assert(solutionPathFind && "The project dir was not find");
72+
73+
return projectPath;
74+
}
75+
bool IsPathAbsolute(std::string path)
76+
{
77+
if (!std::filesystem::exists(path))
78+
{
79+
return false;
80+
}
81+
return true;
82+
}
83+
std::string GetEngineResourcesPath()
84+
{
85+
return engineResourcesPath.string();
86+
}
87+
88+
std::string GetAssetsPath()
89+
{
90+
return assetsPath.string();
91+
}
92+
std::string GetShadersPath()
93+
{
94+
return shadersPath.string();
95+
}
96+
std::filesystem::path workingDir;
97+
std::filesystem::path projectPath;
98+
std::filesystem::path engineResourcesPath;
99+
std::filesystem::path assetsPath;
100+
std::filesystem::path shadersPath;
101+
static OS* instance;
102+
};
103+
104+
OS* OS::instance = nullptr;
105+
}
106+
107+
#endif //OS_HPP

0 commit comments

Comments
 (0)