From 26ed5a1398ae39c4f246ce28a95588da5c12ab9e Mon Sep 17 00:00:00 2001 From: tobid7 Date: Sat, 9 Mar 2024 16:52:26 +0100 Subject: [PATCH] Compile Shaders now as well --- include/fileHash.hpp | 10 +++++--- source/helper.cpp | 57 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 61 insertions(+), 6 deletions(-) diff --git a/include/fileHash.hpp b/include/fileHash.hpp index 76bcdf1..1bd2808 100644 --- a/include/fileHash.hpp +++ b/include/fileHash.hpp @@ -20,7 +20,8 @@ inline std::string fix_path(const std::string &path) inline std::string stupid_hash(const std::string &file) { std::ifstream iff(file); - if(!iff.is_open()) { + if (!iff.is_open()) + { return std::to_string(rand()); } unsigned long long check_sum = 0x0ULL; @@ -44,10 +45,13 @@ createHashes(const std::vector &dirs, { for (const auto &file : std::filesystem::directory_iterator(it)) { - if (file.is_regular_file() && file.path().extension() == extension) + if (file.is_regular_file()) { std::string path = fix_path(file.path().string()); - hashes[path] = stupid_hash(path); + if (path.length() > extension.length() && path.ends_with(extension)) + { + hashes[path] = stupid_hash(path); + } } } } diff --git a/source/helper.cpp b/source/helper.cpp index 4392177..93efbe4 100644 --- a/source/helper.cpp +++ b/source/helper.cpp @@ -42,6 +42,11 @@ std::pair js_catch(const nlohmann::json &js, const std::string &at) return std::make_pair(js[at].get(), exists); } +void recursive_repl(std::string &i, char v1, char v2) +{ + std::replace(i.begin(), i.end(), v1, v2); +} + std::vector get_files_in_dir(const std::vector &dir_paths, const std::string &extension) @@ -54,10 +59,16 @@ get_files_in_dir(const std::vector &dir_paths, continue; for (const auto &entry : std::filesystem::directory_iterator(dir_path)) { - if (std::filesystem::is_regular_file(entry.path()) && - entry.path().extension() == extension) + if (std::filesystem::is_regular_file(entry.path())) { - files.push_back(fix_path(entry.path().string())); + std::string fn = entry.path().string(); + if (fn.length() > extension.length()) + { + if (fn.ends_with(extension)) + { + files.push_back(fix_path(entry.path().string())); + } + } } } } @@ -344,6 +355,9 @@ void CompileProject(NpiProject &prj, std::string dir_) AutoVecRepl(prj.source_dirs); AutoVecRepl(prj.include_dirs); + // Inject build dir as include dir + prj.include_dirs.push_back(dir_ + "/build"); + std::vector cpp_files = get_files_in_dir(prj.source_dirs, ".cpp"); std::vector c_files = @@ -445,6 +459,43 @@ void CompileProject(NpiProject &prj, std::string dir_) any_errors = true; } + for (auto const &it : v_pica_files_) + { + std::string res_f = dir_ + "/build/" + fix_path(it.stem().stem().string()) + ".shbin "; + std::string command = dkp_env + "/tools/bin/picasso -o " + + res_f + fix_path(it.string()); + std::cout << CCMAGENTA << "Generating: " << CCCYAN << fix_path(it.filename().string()) + << std::endl; + int reqres = system(command.c_str()); + std::cout << (reqres == 0 ? CCGREEN : CCRED) + << (reqres == 0 ? "[+] " : "[-] ") << fix_path(it.filename().string()) + << std::endl; + if (reqres != 0) + any_errors = true; + // Bin2o action + // Mod res_f + std::string erf = res_f; + recursive_repl(erf, '.', '_'); + erf = erf.substr(0, erf.length() - 1); + std::string tmp = "t.s"; + std::string obj = erf + ".o"; + std::string hdr = erf + ".h"; + + // Convert bin2asm + std::string cmd = "bin2s -a 4 -H " + hdr + ' ' + res_f + " > " + tmp; + reqres = system(cmd.c_str()); + if (reqres != 0) + any_errors = true; + + cmd = prj.cxx_compiler + " -x assembler-with-cpp " + tmp + " -c -o " + obj; + reqres = system(cmd.c_str()); + if (reqres != 0) + any_errors = true; + + // remove asm file + remove(tmp.c_str()); + } + for (auto const &it : cpp_files_) { std::string command =