Skip to content

Commit 47035d5

Browse files
committed
static FileSystem
1 parent a63ae3a commit 47035d5

File tree

11 files changed

+66
-78
lines changed

11 files changed

+66
-78
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ find_package(OpenGL REQUIRED)
55

66
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
77

8-
set(SOURCES src/main.cpp src/WindowManager.cpp src/WindowManager.h src/Window.cpp src/Window.h src/graphics/Shader.cpp src/graphics/Shader.h src/graphics/ShaderType.h src/graphics/ShaderProgram.cpp src/graphics/ShaderProgram.h src/FileManager.cpp src/FileManager.h src/graphics/Texture.cpp src/graphics/Texture.h src/ResourceManager.cpp src/ResourceManager.h src/input/InputManager.cpp src/input/InputManager.h src/input/EventHandlers.h src/Game.cpp src/Game.h src/game/GameState.h src/graphics/SpriteRenderer.cpp src/graphics/SpriteRenderer.h src/Singleton.h src/game/GameObject.cpp src/game/GameObject.h src/game/Brick.cpp src/game/Brick.h src/game/GameLevel.cpp src/game/GameLevel.h src/game/Player.cpp src/game/Player.h src/game/Ball.cpp src/game/Ball.h src/physics/Direction.h src/physics/Collision.h src/physics/CollisionDetector.cpp src/physics/CollisionDetector.h src/graphics/Particle.h src/graphics/ParticleEmitter.cpp src/graphics/ParticleEmitter.h src/graphics/PostProcessor.cpp src/graphics/PostProcessor.h src/graphics/PostProcessingEffect.h src/game/PowerUp.cpp src/game/PowerUp.h src/game/PowerUpType.h src/utils/Random.cpp src/utils/Random.h src/audio/AudioManager.h src/audio/AudioManager.cpp src/audio/AudioFile.h src/graphics/TextRenderer.h src/graphics/TextRenderer.cpp src/graphics/Font.h src/graphics/GlyphInfo.h)
8+
set(SOURCES src/main.cpp src/WindowManager.cpp src/WindowManager.h src/Window.cpp src/Window.h src/graphics/Shader.cpp src/graphics/Shader.h src/graphics/ShaderType.h src/graphics/ShaderProgram.cpp src/graphics/ShaderProgram.h src/utils/FileManager.cpp src/utils/FileManager.h src/graphics/Texture.cpp src/graphics/Texture.h src/ResourceManager.cpp src/ResourceManager.h src/input/InputManager.cpp src/input/InputManager.h src/input/EventHandlers.h src/Game.cpp src/Game.h src/game/GameState.h src/graphics/SpriteRenderer.cpp src/graphics/SpriteRenderer.h src/Singleton.h src/game/GameObject.cpp src/game/GameObject.h src/game/Brick.cpp src/game/Brick.h src/game/GameLevel.cpp src/game/GameLevel.h src/game/Player.cpp src/game/Player.h src/game/Ball.cpp src/game/Ball.h src/physics/Direction.h src/physics/Collision.h src/physics/CollisionDetector.cpp src/physics/CollisionDetector.h src/graphics/Particle.h src/graphics/ParticleEmitter.cpp src/graphics/ParticleEmitter.h src/graphics/PostProcessor.cpp src/graphics/PostProcessor.h src/graphics/PostProcessingEffect.h src/game/PowerUp.cpp src/game/PowerUp.h src/game/PowerUpType.h src/utils/Random.cpp src/utils/Random.h src/audio/AudioManager.h src/audio/AudioManager.cpp src/audio/AudioFile.h src/graphics/TextRenderer.h src/graphics/TextRenderer.cpp src/graphics/Font.h src/graphics/GlyphInfo.h)
99

1010
# GLFW build configuration
1111

src/FileManager.h

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

src/Game.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ void Game::initGL() {
155155
void Game::initResources() {
156156
auto spriteShader = resourceManager_.createShaderProgram("sprite",
157157
Shader(ShaderType::VERTEX,
158-
"../../../resources/shaders/sprite/shader.vert"),
158+
"../resources/shaders/sprite/shader.vert"),
159159
Shader(ShaderType::FRAGMENT,
160-
"../../../resources/shaders/sprite/shader.frag"));
160+
"../resources/shaders/sprite/shader.frag"));
161161
glm::mat4 projection = glm::ortho(0.0f, static_cast<GLfloat>(window_->width()),
162162
static_cast<GLfloat>(window_->height()), 0.0f,
163163
-1.0f, 1.0f);
@@ -169,70 +169,70 @@ void Game::initResources() {
169169

170170
auto textRenderingShader = resourceManager_.createShaderProgram("text",
171171
Shader(ShaderType::VERTEX,
172-
"../../../resources/shaders/textrendering/shader.vert"),
172+
"../resources/shaders/textrendering/shader.vert"),
173173
Shader(ShaderType::FRAGMENT,
174-
"../../../resources/shaders/textrendering/shader.frag"));
174+
"../resources/shaders/textrendering/shader.frag"));
175175
textRenderingShader->use();
176176
textRenderingShader->setUniform("projection", projection);
177-
textRenderer_.init("../../../resources/fonts/ocraext.ttf", textRenderingShader);
177+
textRenderer_.init("../resources/fonts/ocraext.ttf", textRenderingShader);
178178

179179
auto particleShader = resourceManager_.createShaderProgram("particle",
180180
Shader(ShaderType::VERTEX,
181-
"../../../resources/shaders/particle/shader.vert"),
181+
"../resources/shaders/particle/shader.vert"),
182182
Shader(ShaderType::FRAGMENT,
183-
"../../../resources/shaders/particle/shader.frag"));
183+
"../resources/shaders/particle/shader.frag"));
184184
particleShader->use();
185185
particleShader->setUniform("projection", projection);
186186
particleShader->setUniform("sprite", 0);
187187

188188
resourceManager_.createShaderProgram("postprocessing",
189189
Shader(ShaderType::VERTEX,
190-
"../../../resources/shaders/postprocessing/shader.vert"),
190+
"../resources/shaders/postprocessing/shader.vert"),
191191
Shader(ShaderType::FRAGMENT,
192-
"../../../resources/shaders/postprocessing/shader.frag"));
192+
"../resources/shaders/postprocessing/shader.frag"));
193193

194194
resourceManager_.createTexture("background",
195-
"../../../resources/textures/background.jpg",
195+
"../resources/textures/background.jpg",
196196
1600, 900);
197197
resourceManager_.createTexture("face",
198-
"../../../resources/textures/awesome_face.png",
198+
"../resources/textures/awesome_face.png",
199199
512, 512, 4, GL_RGBA);
200200
resourceManager_.createTexture("block",
201-
"../../../resources/textures/block.png",
201+
"../resources/textures/block.png",
202202
128, 128);
203203
resourceManager_.createTexture("block_solid",
204-
"../../../resources/textures/block_solid.png",
204+
"../resources/textures/block_solid.png",
205205
128, 128);
206206
resourceManager_.createTexture("paddle",
207-
"../../../resources/textures/paddle.png",
207+
"../resources/textures/paddle.png",
208208
512, 128, 4, GL_RGBA);
209209
resourceManager_.createTexture("particle",
210-
"../../../resources/textures/particle.png",
210+
"../resources/textures/particle.png",
211211
500, 500, 4, GL_RGBA);
212212
resourceManager_.createTexture("speedUp",
213-
"../../../resources/textures/powerups/powerup_speedup.png",
213+
"../resources/textures/powerups/powerup_speedup.png",
214214
512, 128, 4, GL_RGBA);
215215
resourceManager_.createTexture("sticky",
216-
"../../../resources/textures/powerups/powerup_sticky.png",
216+
"../resources/textures/powerups/powerup_sticky.png",
217217
512, 128, 4, GL_RGBA);
218218
resourceManager_.createTexture("passThrough",
219-
"../../../resources/textures/powerups/powerup_passthrough.png",
219+
"../resources/textures/powerups/powerup_passthrough.png",
220220
512, 128, 4, GL_RGBA);
221221
resourceManager_.createTexture("padSizeIncrease",
222-
"../../../resources/textures/powerups/powerup_increase.png",
222+
"../resources/textures/powerups/powerup_increase.png",
223223
512, 128, 4, GL_RGBA);
224224
resourceManager_.createTexture("confuse",
225-
"../../../resources/textures/powerups/powerup_confuse.png",
225+
"../resources/textures/powerups/powerup_confuse.png",
226226
512, 128, 4, GL_RGBA);
227227
resourceManager_.createTexture("chaos",
228-
"../../../resources/textures/powerups/powerup_chaos.png",
228+
"../resources/textures/powerups/powerup_chaos.png",
229229
512, 128, 4, GL_RGBA);
230230

231-
audioManager_.createSource("background", "../../../resources/audio/background.ogg", true);
232-
audioManager_.createSource("bleep", "../../../resources/audio/bleep.ogg", false);
233-
audioManager_.createSource("bleepPaddle", "../../../resources/audio/bleep_paddle.ogg", false);
234-
audioManager_.createSource("solid", "../../../resources/audio/solid.ogg", false);
235-
audioManager_.createSource("powerup", "../../../resources/audio/powerup.ogg", false);
231+
audioManager_.createSource("background", "../resources/audio/background.ogg", true);
232+
audioManager_.createSource("bleep", "../resources/audio/bleep.ogg", false);
233+
audioManager_.createSource("bleepPaddle", "../resources/audio/bleep_paddle.ogg", false);
234+
audioManager_.createSource("solid", "../resources/audio/solid.ogg", false);
235+
audioManager_.createSource("powerup", "../resources/audio/powerup.ogg", false);
236236

237237
particleEmitter_ = std::make_unique<ParticleEmitter>(resourceManager_.shaderProgram("particle"),
238238
resourceManager_.texture("particle"),
@@ -241,13 +241,13 @@ void Game::initResources() {
241241
window_->width(), window_->height());
242242

243243
levels_.push_back(std::make_unique<GameLevel>(
244-
"../../../resources/levels/1.txt", window_->width(), window_->height() / 2));
244+
"../resources/levels/1.txt", window_->width(), window_->height() / 2));
245245
levels_.push_back(std::make_unique<GameLevel>(
246-
"../../../resources/levels/2.txt", window_->width(), window_->height() / 2));
246+
"../resources/levels/2.txt", window_->width(), window_->height() / 2));
247247
levels_.push_back(std::make_unique<GameLevel>(
248-
"../../../resources/levels/3.txt", window_->width(), window_->height() / 2));
248+
"../resources/levels/3.txt", window_->width(), window_->height() / 2));
249249
levels_.push_back(std::make_unique<GameLevel>(
250-
"../../../resources/levels/4.txt", window_->width(), window_->height() / 2));
250+
"../resources/levels/4.txt", window_->width(), window_->height() / 2));
251251
currentLevel_ = 3;
252252

253253
glm::vec2 playerSize = glm::vec2(150, 20) * scales_;

src/ResourceManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "graphics/ShaderProgram.h"
33
#include "graphics/Shader.h"
44
#include "graphics/Texture.h"
5-
#include "FileManager.h"
5+
#include "utils/FileManager.h"
66
#include <memory>
77
#include <string>
88
#include <iostream>
@@ -44,7 +44,7 @@ Texture* ResourceManager::createTexture(const std::string& name,
4444
GLuint height,
4545
GLint channels,
4646
GLuint format) {
47-
unsigned char *image = FileManager::Instance().readImage(path, width, height, channels);
47+
unsigned char *image = FileManager::readImage(path, width, height, channels);
4848

4949
textures_[name] = std::unique_ptr<Texture>(
5050
new Texture(width, height, image, format)

src/Window.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ Window::Window(int width, int height, const std::string& title, bool isFullScree
1414

1515
if (window_ == nullptr) {
1616
std::cerr << "Failed to create GLFW window" << std::endl;
17-
}
17+
}
18+
19+
glfwSetInputMode(window_, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
1820

1921
if (!isFullScreen) {
2022
// Center window on screen

src/audio/AudioManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "AudioManager.h"
22
#include "AudioFile.h"
3-
#include "../FileManager.h"
3+
#include "../utils/FileManager.h"
44
#include <iostream>
55

66
AudioManager::AudioManager() {
@@ -32,7 +32,7 @@ void AudioManager::shutDown() {
3232
}
3333

3434
void AudioManager::createSource(const std::string& name, const std::string& path, bool isLooping) {
35-
AudioFile audioFile = FileManager::Instance().readOggFile(path);
35+
AudioFile audioFile = FileManager::readOggFile(path);
3636
ALuint source, buffer;
3737

3838
alGenSources(1, &source);

src/game/GameLevel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "GameLevel.h"
2-
#include "../FileManager.h"
2+
#include "../utils/FileManager.h"
33
#include "../ResourceManager.h"
44
#include <glm/vec2.hpp>
55
#include <glm/vec3.hpp>
@@ -33,7 +33,7 @@ std::vector<std::vector<int>> GameLevel::loadTiles(const std::string &path) {
3333
std::vector<std::vector<int>> tiles;
3434

3535
int tile;
36-
std::stringstream level(FileManager::Instance().readAsText(path));
36+
std::stringstream level(FileManager::readAsText(path));
3737
std::string line;
3838
while (std::getline(level, line)) {
3939
std::istringstream rowStream(line);

src/graphics/Shader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "Shader.h"
22
#include "ShaderType.h"
3-
#include "../FileManager.h"
3+
#include "../utils/FileManager.h"
44
#include <GL/glew.h>
55
#include <iostream>
66
#include <string>
@@ -10,7 +10,7 @@
1010
Shader::Shader(ShaderType type, const std::string& path) {
1111
std::cout << "Shader constructor" << std::endl;
1212

13-
std::string source = FileManager::Instance().readAsText(path);
13+
std::string source = FileManager::readAsText(path);
1414

1515
id_ = glCreateShader(type);
1616

src/graphics/TextRenderer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "TextRenderer.h"
2-
#include "../FileManager.h"
2+
#include "../utils/FileManager.h"
33
#define STB_TRUETYPE_IMPLEMENTATION
44
#include "stb_truetype.h"
55
#include <iostream>
@@ -70,7 +70,7 @@ void TextRenderer::renderText(const std::string& text, const glm::vec2& position
7070
}
7171

7272
void TextRenderer::initFont(const std::string& path) {
73-
auto fontData = FileManager::Instance().readAsBinary(path);
73+
auto fontData = FileManager::readAsBinary(path);
7474
auto atlasData = std::vector<unsigned char>(font_.atlasWidth * font_.atlasHeight);
7575
font_.charInfo = std::vector<stbtt_packedchar>(font_.charCount);
7676

src/FileManager.cpp renamed to src/utils/FileManager.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,7 @@
77
#include <fstream>
88
#include <sstream>
99

10-
FileManager::FileManager() {
11-
std::cout << "FileManager constructor" << std::endl;
12-
}
13-
14-
FileManager::~FileManager() {
15-
std::cout << "FileManager destructor" << std::endl;
16-
}
17-
18-
std::string FileManager::readAsText(const std::string &path) const {
10+
std::string FileManager::readAsText(const std::string &path) {
1911
std::string content{""};
2012
std::ifstream file(path);
2113

@@ -33,7 +25,7 @@ std::string FileManager::readAsText(const std::string &path) const {
3325
return content;
3426
}
3527

36-
std::vector<unsigned char> FileManager::readAsBinary(const std::string& path) const {
28+
std::vector<unsigned char> FileManager::readAsBinary(const std::string& path) {
3729
std::ifstream file(path, std::ios::binary | std::ios::ate);
3830

3931
if (!file.is_open()) {
@@ -53,7 +45,7 @@ unsigned char* FileManager::readImage(const std::string& path,
5345
GLint width,
5446
GLint height,
5547
GLint channels,
56-
bool flip) const {
48+
bool flip) {
5749
stbi_set_flip_vertically_on_load(flip);
5850
unsigned char* image = stbi_load(path.c_str(), &width, &height, &channels, 0);
5951
if (image == nullptr) {
@@ -64,7 +56,7 @@ unsigned char* FileManager::readImage(const std::string& path,
6456
return image;
6557
}
6658

67-
AudioFile FileManager::readOggFile(const std::string& path) const {
59+
AudioFile FileManager::readOggFile(const std::string& path) {
6860
AudioFile audioFile;
6961
short* output;
7062
audioFile.samples = stb_vorbis_decode_filename(path.c_str(),

0 commit comments

Comments
 (0)