mirror of
https://github.com/open-goal/jak-project
synced 2026-07-08 14:36:52 -04:00
port pckernel to Jak 2 (#2248)
Adds the `pckernel` system to Jak 2, allowing you to do the PC-specific things that Jak 1 lets you do like change game resolution, etc. In other to reduce the amount of code duplication for something that we're gonna be changing a lot over time, I split it into a few more code files. In this new system, `pckernel-h.gc`, `pckernel-common.gc` (previously `pckernel.gc`) and `pc-debug-common.gc` are the files that should be shared across all games (I hacked the Jak 2 project to pull these files from the Jak 1 folder), while `pckernel-impl.gc`, `pckernel.gc` and `pc-debug-methods.gc` are their respective game-specific counterparts that should be loaded after. I'm not fully happy with this, I think it's slightly messy, but it cleanly separates code that should be game-specific and not accidentally copied around and code that should be the same for all games anyway.
This commit is contained in:
+39
-17
@@ -76,6 +76,11 @@ MakeSystem::MakeSystem(const std::string& username) : m_goos(username) {
|
||||
return handle_set_gsrc_folder(obj, args, env);
|
||||
});
|
||||
|
||||
m_goos.register_form("get-gsrc-folder", [=](const goos::Object& obj, goos::Arguments& args,
|
||||
const std::shared_ptr<goos::EnvironmentObject>& env) {
|
||||
return handle_get_gsrc_folder(obj, args, env);
|
||||
});
|
||||
|
||||
m_goos.set_global_variable_to_symbol("ASSETS", "#t");
|
||||
|
||||
set_constant("*iso-data*", file_util::get_file_path({"iso_data"}));
|
||||
@@ -209,28 +214,13 @@ goos::Object MakeSystem::handle_get_gsrc_path(const goos::Object& form,
|
||||
goos::Arguments& args,
|
||||
const std::shared_ptr<goos::EnvironmentObject>& env) {
|
||||
if (m_gsrc_folder.empty()) {
|
||||
throw std::runtime_error("`set-gsrc-folder!` was not called before a `get-src-path`");
|
||||
throw std::runtime_error("`set-gsrc-folder!` was not called before a `get-gsrc-path`");
|
||||
}
|
||||
m_goos.eval_args(&args, env);
|
||||
va_check(form, args, {goos::ObjectType::STRING}, {});
|
||||
|
||||
const auto& file_name = args.unnamed.at(0).as_string()->data;
|
||||
|
||||
// Keep things fast by scanning the gsrc directory _once_ on the first call
|
||||
if (m_gsrc_files.empty()) {
|
||||
auto folder = file_util::get_file_path(m_gsrc_folder);
|
||||
auto src_files = file_util::find_files_recursively(folder, std::regex(".*\\.gc"));
|
||||
|
||||
for (const auto& path : src_files) {
|
||||
auto name = file_util::base_name_no_ext(path.u8string());
|
||||
auto gsrc_path =
|
||||
file_util::convert_to_unix_path_separators(file_util::split_path_at(path, m_gsrc_folder));
|
||||
// TODO - this is only "safe" because the current OpenGOAL system requires globally unique
|
||||
// file names
|
||||
m_gsrc_files.emplace(name, gsrc_path);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_gsrc_files.count(file_name) != 0) {
|
||||
return goos::StringObject::make_new(m_gsrc_files.at(file_name));
|
||||
} else {
|
||||
@@ -271,7 +261,39 @@ goos::Object MakeSystem::handle_set_gsrc_folder(
|
||||
|
||||
const auto& folder = args.unnamed.at(0).as_string()->data;
|
||||
m_gsrc_folder = str_util::split(folder, '/');
|
||||
return goos::Object::make_empty_list();
|
||||
m_gsrc_files.clear();
|
||||
|
||||
auto folder_scan = file_util::get_file_path(m_gsrc_folder);
|
||||
auto src_files = file_util::find_files_recursively(folder_scan, std::regex(".*\\.gc"));
|
||||
|
||||
for (const auto& path : src_files) {
|
||||
auto name = file_util::base_name_no_ext(path.u8string());
|
||||
auto gsrc_path =
|
||||
file_util::convert_to_unix_path_separators(file_util::split_path_at(path, m_gsrc_folder));
|
||||
// TODO - this is only "safe" because the current OpenGOAL system requires globally unique
|
||||
// file names
|
||||
m_gsrc_files.emplace(name, gsrc_path);
|
||||
}
|
||||
|
||||
return args.unnamed.at(0);
|
||||
}
|
||||
|
||||
goos::Object MakeSystem::handle_get_gsrc_folder(
|
||||
const goos::Object& form,
|
||||
goos::Arguments& args,
|
||||
const std::shared_ptr<goos::EnvironmentObject>& env) {
|
||||
m_goos.eval_args(&args, env);
|
||||
va_check(form, args, {}, {});
|
||||
|
||||
std::string out;
|
||||
int idx = 0;
|
||||
for (const auto& part : m_gsrc_folder) {
|
||||
if (idx++ > 0) {
|
||||
out += '/';
|
||||
}
|
||||
out += part;
|
||||
}
|
||||
return goos::StringObject::make_new(out);
|
||||
}
|
||||
|
||||
void MakeSystem::get_dependencies(const std::string& master_target,
|
||||
|
||||
Reference in New Issue
Block a user