Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ add_library(bald_engine
${CMAKE_CURRENT_SOURCE_DIR}/src/core/platform/opengl/buffers/opengl_index_buffer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/core/platform/opengl/buffers/opengl_vertex_array.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/core/platform/opengl/shaders/opengl_shader.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/core/utils/file_manager.cpp
src/core/utils/file_manager/file_manager.cpp
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add ${CMAKE_CURRENT_SOURCE_DIR}/

${CMAKE_CURRENT_SOURCE_DIR}/src/core/utils/split_string.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/core/utils/timer.cpp)

Expand Down
6 changes: 3 additions & 3 deletions engine/src/core/platform/opengl/shaders/opengl_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "opengl_shader.h"
#include <unordered_map>
#include "file_manager.h"
#include "src/core/utils/file_manager/file_manager.h"
#include "pch.h"
#include "glad/glad.h"

Expand Down Expand Up @@ -101,7 +101,7 @@ namespace Bald::Platform::Graphics {
vertexShader = glCreateShader(GL_VERTEX_SHADER);

std::string vertexShaderSource = Utils::FileManager::ReadFile(m_VertexPath,
Utils::FileManager::Size::SMALL_FILE);
Utils::FileManager::Size::small_file);
const char* vertexData = vertexShaderSource.c_str();

glShaderSource(vertexShader, 1, &vertexData, nullptr);
Expand All @@ -127,7 +127,7 @@ namespace Bald::Platform::Graphics {
fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);

std::string fragmentShaderSource = Utils::FileManager::ReadFile(m_FragmentPath,
Utils::FileManager::Size::SMALL_FILE);
Utils::FileManager::Size::small_file);
const char* fragmentData = fragmentShaderSource.c_str();

glShaderSource(fragmentShader, 1, &fragmentData, nullptr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace Bald::Utils {

std::string FileManager::ReadFile(const char* filePath, Size size) {
if (size == Size::SMALL_FILE)
if (size == Size::small_file)
return ReadSmallFile(filePath);
return ReadBigFile(filePath);
}
Expand Down Expand Up @@ -74,10 +74,32 @@ namespace Bald::Utils {
return result;
}

#elif WINDOWS
#else
#include <fstream>
std::string FileManager::ReadBigFile(const char *filePath) {
CORE_LOG_INFO("[FILE_MANAGER] Error: Windows implementation is not done yet! Using slower reading method!");
ReadSmallFile(filePath);
// CORE_LOG_INFO("[FILE_MANAGER] Error: Windows implementation is not done yet! Using slower reading method!");
// ReadSmallFile(filePath);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comments

std::streampos begin,end;
std::ifstream file(filePath, std::ios::in);
char* buffer;
if(file.is_open()){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you do some research on the performance of this code?

begin = file.tellg();
file.seekg (0, std::ios::end);
end = file.tellg();
auto size = static_cast<size_t>(end-begin);
buffer = new char[static_cast<unsigned long>(size)];
std::memset(buffer, '\0', static_cast<unsigned long>(size));
file.seekg(0, std::ios::beg);
file.read(buffer, static_cast<std::streamsize>(size));
file.close();
std::string result(buffer);
delete[] buffer;
return result;
}

CORE_LOG_WARN("[FileManager] Couldn't get size of the file. Check if the file exists at path: " + static_cast<std::string>(filePath));
return "[FileManager] Couldn't get size of the file. Check if the file exists at path: " + static_cast<std::string>(filePath);

}
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Bald::Utils {
* ENUM which determines size of file and therefor methods, which will be used to read it
*/
enum class Size : char {
SMALL_FILE, BIG_FILE
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to have fixed convention for enum naming

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

small_file, big_file
};
public:

Expand Down
10 changes: 5 additions & 5 deletions engine/tests/test_file_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@

#include "core/pch.h"
#include "gtest/gtest.h"
#include "utils/file_manager.h"
#include "src/core/utils/file_manager/file_manager.h"

TEST(FileManager, GoodSmallFileOpening) { //NOLINT

std::string file_result = Bald::Utils::FileManager::ReadFile("../engine/test_file_manager.txt", Bald::Utils::FileManager::Size::SMALL_FILE);
std::string file_result = Bald::Utils::FileManager::ReadFile("../engine/test_file_manager.txt", Bald::Utils::FileManager::Size::small_file);

EXPECT_EQ("plik testowy\ndo odczytu", file_result);
}

TEST(FileManager, GoodBigFileOpening) { //NOLINT

std::string file_result = Bald::Utils::FileManager::ReadFile("../engine/test_file_manager.txt", Bald::Utils::FileManager::Size::BIG_FILE);
std::string file_result = Bald::Utils::FileManager::ReadFile("../engine/test_file_manager.txt", Bald::Utils::FileManager::Size::big_file);

EXPECT_EQ("plik testowy\ndo odczytu", file_result);
}

TEST(FileManager, WrongSmallFileOpening) { //NOLINT

std::string file_result = Bald::Utils::FileManager::ReadFile("no_such_file.cpp", Bald::Utils::FileManager::Size::SMALL_FILE);
std::string file_result = Bald::Utils::FileManager::ReadFile("no_such_file.cpp", Bald::Utils::FileManager::Size::small_file);

EXPECT_EQ("[FileManager] Couldn't open the file at path: no_such_file.cpp", file_result);
}

TEST(FileManager, WrongBigFileOpening) { //NOLINT

std::string file_result = Bald::Utils::FileManager::ReadFile("no_such_file.cpp", Bald::Utils::FileManager::Size::BIG_FILE);
std::string file_result = Bald::Utils::FileManager::ReadFile("no_such_file.cpp", Bald::Utils::FileManager::Size::big_file);

EXPECT_EQ("[FileManager] Couldn't get size of the file. Check if the file exists at path: no_such_file.cpp", file_result);
}