diff --git a/.gitignore b/.gitignore index 36ffb7f..8dc6d2d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ .vscode -build \ No newline at end of file +build + +dependencies/ps2gl \ No newline at end of file diff --git a/assets/models/kettle.fbx b/assets/models/kettle.fbx index ff8b68c..0f0a648 100644 Binary files a/assets/models/kettle.fbx and b/assets/models/kettle.fbx differ diff --git a/assets/models/testmap.fbx b/assets/models/testmap.fbx index c9736f4..fa855d8 100644 Binary files a/assets/models/testmap.fbx and b/assets/models/testmap.fbx differ diff --git a/dependencies/egg-library/include/egg/assert.hpp b/dependencies/egg-library/include/egg/assert.hpp index 8314877..33c1eac 100644 --- a/dependencies/egg-library/include/egg/assert.hpp +++ b/dependencies/egg-library/include/egg/assert.hpp @@ -17,7 +17,7 @@ init_scr(); \ printf("ERROR! Check failed! file: %s, function: %s, line: %d\n", \ __FILE__, __func__, __LINE__); \ - print_stack_trace(); \ + init_scr(); \ scr_printf("ERROR! Check failed! file: %s, function: %s, line: %d\n", \ __FILE__, __func__, __LINE__); \ SleepThread(); \ @@ -32,7 +32,7 @@ printf("ERROR! Check failed! file: %s, function: %s, line: %d\n", \ __FILE__, __func__, __LINE__); \ printf("Check msg: %s\n", (msg)); \ - print_stack_trace(); \ + init_scr(); \ scr_printf("ERROR! Check failed! file: %s, function: %s, line: %d\n", \ __FILE__, __func__, __LINE__); \ scr_printf("Check msg: %s\n", (msg)); \ diff --git a/dependencies/egg-library/include/egg/filesystem.hpp b/dependencies/egg-library/include/egg/filesystem.hpp index e62980e..5a03db8 100644 --- a/dependencies/egg-library/include/egg/filesystem.hpp +++ b/dependencies/egg-library/include/egg/filesystem.hpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace Filesystem { @@ -94,6 +95,8 @@ static constexpr const char* constexpr_convert_filepath_to_systempath(std::strin // Returns true if the file was loaded succesfully bool load_file(const Path& path, std::vector& out_bytes); bool load_file(const Path& path, std::unique_ptr& out_bytes, size_t& size, size_t alignment = 1); +bool file_exists(const Path& path); +void iterate_dir(const Path& dir, std::function itr_func, bool recursive = false); struct Path { @@ -111,6 +114,18 @@ struct Path } } + Path(const char* in_path, bool convert_path = true) + { + if (convert_path) + { + _path_str = convert_filepath_to_systempath(in_path); + } + else + { + _path_str = in_path; + } + } + inline const char* c_str() const { return _path_str.c_str(); diff --git a/dependencies/egg-library/src/filesystem.cc b/dependencies/egg-library/src/filesystem.cc index a7fc228..22e7b63 100644 --- a/dependencies/egg-library/src/filesystem.cc +++ b/dependencies/egg-library/src/filesystem.cc @@ -5,6 +5,7 @@ #include #include #include +#include #include "egg/assert.hpp" @@ -26,6 +27,41 @@ static constexpr std::size_t constexpr_strlen(const char* s) return std::char_traits::length(s); } +static void convert_to_83_path(std::string_view path, char* buffer, size_t len) +{ + // Iterate backwards and look for the beginning of the filename + size_t filename_begin = 0; + size_t extension_begin = path.size(); + for (int i = path.size(); i >= 0; --i) + { + if (path[i] == '.') + { + extension_begin = i; + } + else if (path[i] == '/' || path[i] == '\\') + { + filename_begin = i + 1; + break; + } + } + + // Copy up to the first 8 filename characters over + size_t itr_end = std::min(filename_begin + 8, extension_begin); + itr_end = std::min(itr_end, path.size()); + for (size_t i = 0; i < itr_end; ++i) + { + buffer[i] = path[i]; + } + + // Copy the extension over + size_t itr_extension_end = std::min(4U, path.size() - extension_begin); + for (size_t i = 0; i < itr_extension_end; ++i) + { + buffer[itr_end + i] = path[extension_begin + i]; + } + buffer[itr_end + itr_extension_end] = '\0'; +} + template static std::string convert_filepath_to_systempath_impl(std::string_view path) { @@ -36,9 +72,6 @@ static std::string convert_filepath_to_systempath_impl(std::string_view path) static char out_path_chars[256]; - // snprintf(out_path_chars, host_string_length + 1, "%s%c%.*s", - // get_filesystem_prefix(type), get_filesystem_separator(type), path.length(), path.data()); - constexpr const char* filesystem_prefix = get_filesystem_prefix(type); constexpr int filesystem_prefix_len = constexpr_strlen(filesystem_prefix); @@ -50,39 +83,49 @@ static std::string convert_filepath_to_systempath_impl(std::string_view path) int index = filesystem_prefix_len; - if (path[0] != '\\' || path[0] != '/') + int path_start = 0; + if constexpr (type != Type::host) { - out_path_chars[index] = get_filesystem_separator(); - index++; - } - - // Write out the filename - int filename_start_index = -1; - int extension_start_index = -1; - for (size_t i = 0; i < host_string_length; ++i) - { - if (path[i] == '\\' || path[i] == '/') + if (path[0] != '\\' && path[0] != '/') { - out_path_chars[index + i] = get_filesystem_separator(type); - - filename_start_index = i + 1; + out_path_chars[index] = get_filesystem_separator(); + index++; } - else if (path[i] == '-') + } + else + { + // iterate past the start of the path on host filesystem + while (path[path_start] == '\\' || path[path_start] == '/') { - out_path_chars[index + i] = '_'; + path_start++; } - else if (get_filesystem_type() == Type::cdrom) + } + + path = std::string_view(path.data() + path_start, path.end()); + + if constexpr (type == Type::cdrom) + { + convert_to_83_path(path, out_path_chars + filesystem_prefix_len, (256 - filesystem_prefix_len) - 1); + } + else + { + strncpy(out_path_chars + filesystem_prefix_len, path.data(), (256 - filesystem_prefix_len) - 1); + } + + // Convert to uppercase, etc + for (size_t i = filesystem_prefix_len - 1; i < host_string_length; ++i) + { + if (out_path_chars[i] == '\\' || out_path_chars[i] == '/') { - out_path_chars[index + i] = toupper(path[i]); + out_path_chars[i] = get_filesystem_separator(type); } - else + else if (out_path_chars[i] == '-') { - out_path_chars[index + i] = path[i]; + out_path_chars[i] = '_'; } - - if (path[i] == '.') + else if (get_filesystem_type() == Type::cdrom) { - extension_start_index = i + 1; + out_path_chars[i] = toupper(out_path_chars[i]); } } @@ -150,6 +193,34 @@ bool load_file(const Path& path, std::unique_ptr& out_bytes, size_t return false; } +bool file_exists(const Path& path) +{ + return std::filesystem::exists(path.c_str()); +} + +void iterate_dir(const Path& dir, std::function itr_func, bool recursive) +{ + checkf(itr_func, "iterate_dir called with empty itr_func!"); + + namespace fs = std::filesystem; + if (recursive) + { + for (const fs::directory_entry& dir_entry : + fs::recursive_directory_iterator(dir.c_str())) + { + itr_func(Path(dir_entry.path().c_str(), false)); + } + } + else + { + for (const fs::directory_entry& dir_entry : + fs::directory_iterator(dir.c_str())) + { + itr_func(Path(dir_entry.path().c_str(), false)); + } + } +} + void run_tests() { switch (get_filesystem_type()) diff --git a/src/Makefile b/src/Makefile index 9cb1f95..f67a120 100644 --- a/src/Makefile +++ b/src/Makefile @@ -67,7 +67,8 @@ $(OUTPUT_DIR)/$(VU_OUTPUT_DIR)/%.vsm: $(PS2_VCL) -o$@ $(dir $@)$*.pp.vcl run: $(EE_BIN) - ps2client -h $(PS2HOST) execee host:$(EE_BIN) + cd $(dir $(EE_BIN)) + ps2client -h $(PS2HOST) execee host:$(notdir $(EE_BIN)) reset: ps2client -h $(PS2HOST) reset \ No newline at end of file diff --git a/src/engine.cc b/src/engine.cc index db9029c..a6066d4 100644 --- a/src/engine.cc +++ b/src/engine.cc @@ -35,22 +35,25 @@ static u32 frameCounter = 0; void init() { - SifExitIopHeap(); - SifLoadFileExit(); - SifExitRpc(); + Filesystem::set_filesystem_type(Filesystem::Type::host); - SifInitRpc(0); + if (Filesystem::get_filesystem_type() != Filesystem::Type::host) + { + SifExitIopHeap(); + SifLoadFileExit(); + SifExitRpc(); - while (!SifIopReset("", 0)) - ; - while (!SifIopSync()) - ; + SifInitRpc(0); + + while (!SifIopReset("", 0)) + ; + while (!SifIopSync()) + ; + } SifInitRpc(0); SifLoadFileInit(); SifInitIopHeap(); - Filesystem::set_filesystem_type(Filesystem::Type::cdrom); - check(SifLoadModule("rom0:LIBSD", 0, NULL) > 0); check(SifLoadModule("rom0:SIO2MAN", 0, NULL) > 0); @@ -72,7 +75,7 @@ void init() Stats::init(); Input::init(); //Filesystem::run_tests(); - //sound::init(); + //Sound::init(); GS::init(); printf("Graph mode (region): "); diff --git a/src/objects/teapot.cc b/src/objects/teapot.cc index a0f6d23..828464a 100644 --- a/src/objects/teapot.cc +++ b/src/objects/teapot.cc @@ -25,7 +25,7 @@ static class teapot_render_proxy void on_gs_init() { teapot_mesh = new Mesh("/assets/models/kettle.mdl"_p); //&Mesh::loaded_meshes["/assets/models/kettle.ps2_model"_p]; - //teapot_mesh = nullptr; + //teapot_mesh = nullptr; teapot_mesh->compile(); } diff --git a/src/renderer/gs.cc b/src/renderer/gs.cc index 1c8aaed..63a2533 100644 --- a/src/renderer/gs.cc +++ b/src/renderer/gs.cc @@ -101,7 +101,7 @@ static void init_renderer() glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); + //glEnableClientState(GL_COLOR_ARRAY); //glEnableClientState(GL_TEXTURE_COORD_ARRAY); diff --git a/src/renderer/mesh.cc b/src/renderer/mesh.cc index f448c66..554f351 100644 --- a/src/renderer/mesh.cc +++ b/src/renderer/mesh.cc @@ -59,8 +59,8 @@ void Mesh::compile() check(num_lists <= 4096); glNewList(list, GL_COMPILE); { - glEnable(GL_COLOR_MATERIAL); - glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); + //glEnable(GL_COLOR_MATERIAL); + //glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); //glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); //static float material_diff_amb[] = {0.5f, 0.5f, 0.5f, 0}; //glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, material_diff_amb); @@ -81,13 +81,13 @@ void Mesh::compile() if (mesh->uvs.offset > 0) { - glTexCoordPointer(2, GL_FLOAT, 0, mesh->uvs.get_ptr()); + //glTexCoordPointer(2, GL_FLOAT, 0, mesh->uvs.get_ptr()); } if (mesh->colors.offset > 0) { printf("Mesh: %d has colors\n", list); - glColorPointer(4, GL_FLOAT, 0, mesh->colors.get_ptr()); + //glColorPointer(4, GL_FLOAT, 0, mesh->colors.get_ptr()); } int i = 0; diff --git a/src/sound/sound.cc b/src/sound/sound.cc index 3e21251..2543fa3 100644 --- a/src/sound/sound.cc +++ b/src/sound/sound.cc @@ -58,7 +58,7 @@ void init() { int ret = SifLoadModule("AUDSRV.IRX"_p.c_str(), 0, nullptr); printf("ret: %d\n", ret); - check(ret >= 0); + checkf(ret >= 0, "AUDSRV.IRX"_p.c_str()); } printf("initializing audiosrv...\n"); @@ -102,7 +102,7 @@ void init() } } - song_file = std::ifstream("/assets/sounds/white_wa.wav"_p.c_str()); + song_file = std::ifstream("/assets/sounds/white_waking.wav"_p.c_str()); check(song_file.is_open()); song_file.seekg(0x30, std::ios_base::beg); chunkReadStatus = -1;