Skip to content

Commit 6cfb426

Browse files
Add freetype to build and implement GfxAnimation loading
Integrated freetype into the Makefile build process and updated related clean/help targets. Added static animation loading and caching to GfxAnimation, including initial SMD file parsing logic in model.cpp. Updated .gitignore and project configuration files accordingly.
1 parent ebc3b85 commit 6cfb426

File tree

7 files changed

+102
-10
lines changed

7 files changed

+102
-10
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,5 @@
5252
Makefile
5353
*.user
5454
*.slnx
55+
Makefile
56+
/.idea

.idea/runConfigurations/borealis_test.xml

Lines changed: 0 additions & 7 deletions
This file was deleted.

.idea/vcs.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ifeq ($(config),debug)
1515
glfw3_config = debug
1616
stb_config = debug
1717
glm_config = debug
18+
freetype_config = debug
1819

1920
else ifeq ($(config),release)
2021
borealis_config = release
@@ -23,18 +24,19 @@ else ifeq ($(config),release)
2324
glfw3_config = release
2425
stb_config = release
2526
glm_config = release
27+
freetype_config = release
2628

2729
else
2830
$(error "invalid configuration $(config)")
2931
endif
3032

31-
PROJECTS := borealis resource_packer glad glfw3 stb glm
33+
PROJECTS := borealis resource_packer glad glfw3 stb glm freetype
3234

3335
.PHONY: all clean help $(PROJECTS)
3436

3537
all: $(PROJECTS)
3638

37-
borealis: glad glfw3 resource_packer
39+
borealis: glad glfw3 resource_packer freetype
3840
ifneq (,$(borealis_config))
3941
@echo "==== Building borealis ($(borealis_config)) ===="
4042
@${MAKE} --no-print-directory -C . -f borealis.make config=$(borealis_config)
@@ -70,13 +72,20 @@ ifneq (,$(glm_config))
7072
@${MAKE} --no-print-directory -C ext/glm -f Makefile config=$(glm_config)
7173
endif
7274

75+
freetype:
76+
ifneq (,$(freetype_config))
77+
@echo "==== Building freetype ($(freetype_config)) ===="
78+
@${MAKE} --no-print-directory -C ext/freetype -f Makefile config=$(freetype_config)
79+
endif
80+
7381
clean:
7482
@${MAKE} --no-print-directory -C . -f borealis.make clean
7583
@${MAKE} --no-print-directory -C . -f resource_packer.make clean
7684
@${MAKE} --no-print-directory -C ext/glad -f Makefile clean
7785
@${MAKE} --no-print-directory -C ext/glfw -f Makefile clean
7886
@${MAKE} --no-print-directory -C ext/stb -f Makefile clean
7987
@${MAKE} --no-print-directory -C ext/glm -f Makefile clean
88+
@${MAKE} --no-print-directory -C ext/freetype -f Makefile clean
8089

8190
help:
8291
@echo "Usage: make [config=name] [target]"
@@ -94,5 +103,6 @@ help:
94103
@echo " glfw3"
95104
@echo " stb"
96105
@echo " glm"
106+
@echo " freetype"
97107
@echo ""
98108
@echo "For more information, see https://github.com/premake/premake-core/wiki"

ext/glfw

include/borealis/gfx/model.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ namespace brl
143143
std::vector<Channel> channels;
144144
float length = 0;
145145

146+
static GfxAnimation* loadAnimation(std::string path);
147+
148+
private:
149+
friend GfxModel;
150+
151+
GfxAnimation(std::string path);
152+
GfxAnimation() = default;
153+
154+
static std::map<std::string, brl::GfxAnimation*> cachedAnimations;
146155
};
147156

148157

src/brl/gfx/model.cpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,83 @@ brl::GfxShaderProgram* GetSkinningShader()
104104
return defaultSkinningShader;
105105
}
106106

107+
brl::GfxAnimation *brl::GfxAnimation::loadAnimation(std::string path)
108+
{
109+
if (cachedAnimations.contains(path))
110+
return cachedAnimations[path];
111+
112+
return new GfxAnimation(path);
113+
}
114+
115+
std::vector<std::string> splitFileByCharacter(const std::string& data, char delim = '\n') {
116+
std::vector<std::string> lines;
117+
// Open the file for reading
118+
std::stringstream file(data);
119+
120+
std::string line;
121+
// Read each line using std::getline() until the end of the file
122+
while (std::getline(file, line, delim)) {
123+
lines.push_back(line);
124+
}
125+
126+
// The file is automatically closed when the ifstream object goes out of scope,
127+
// but you can also call file.close() explicitly.
128+
129+
return lines;
130+
}
131+
132+
brl::GfxAnimation::GfxAnimation(std::string path)
133+
{
134+
135+
if (path.ends_with(".smd")) {
136+
// smd loading
137+
138+
std::string data = brl::readFileString(path);
139+
140+
const auto& lines = splitFileByCharacter(data);
141+
142+
int version = 0;
143+
144+
enum smd_stage {
145+
none,
146+
nodes
147+
};
148+
smd_stage cur_stage = none;
149+
150+
for (const auto & line : lines) {
151+
if (line.starts_with("version")) {
152+
using namespace std::literals::string_literals; // Bring the "s" suffix into scope
153+
154+
std::string verStr = line.substr(("version "s).length(),1);
155+
156+
version = std::atoi(verStr.c_str());
157+
continue;
158+
}
159+
160+
if (line.starts_with("nodes")) {
161+
cur_stage = nodes;
162+
continue;
163+
}
164+
165+
if (line.starts_with("end")) {
166+
cur_stage = none;
167+
continue;
168+
}
169+
170+
if (cur_stage == nodes) {
171+
auto data = splitFileByCharacter(line,' ');
172+
173+
int id = std::atoi(data[0].c_str());
174+
std::string name = data[1].c_str();
175+
int parentId = std::atoi(data[2].c_str());
176+
177+
}
178+
}
179+
180+
}
181+
182+
}
183+
107184
brl::GfxSubMesh::~GfxSubMesh()
108185
{
109186
delete buffer;

0 commit comments

Comments
 (0)