Skip to content

Commit

Permalink
Merge remote-tracking branch 'vanilla/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
dallmeyer committed Dec 7, 2024
2 parents 4136c60 + a2f9d36 commit 92c5397
Show file tree
Hide file tree
Showing 29 changed files with 410 additions and 103 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/release-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
uses: ./.github/workflows/macos-build.yaml
with:
cmakePreset: "Release-macos-x86_64-clang-static"
cachePrefix: "static"
cachePrefix: "static-arm"
uploadArtifacts: true
secrets: inherit

Expand Down Expand Up @@ -150,13 +150,13 @@ jobs:
- name: Prepare ARM macOS Build Assets
run: |
mkdir -p ./ci-artifacts/macos-arm
./.github/scripts/releases/extract_build_unix.sh ./ci-artifacts/macos-arm ./ci-artifacts/opengoal-macos-arm-static ./
./.github/scripts/releases/extract_build_unix.sh ./ci-artifacts/macos-arm ./ci-artifacts/opengoal-macos-static-arm ./
pushd ci-artifacts/macos-arm
TAG_VAL=${{ needs.cut_release.outputs.new_tag }}
tar czf ../final/opengoal-macos-arm-${TAG_VAL}.tar.gz .
popd
chmod +x ./ci-artifacts/opengoal-macos-arm-static/lsp/lsp
cp ./ci-artifacts/opengoal-macos-arm-static/lsp/lsp ./ci-artifacts/final/opengoal-lsp-macos-arm-${TAG_VAL}.bin
chmod +x ./ci-artifacts/opengoal-macos-static-arm/lsp/lsp
cp ./ci-artifacts/opengoal-macos-static-arm/lsp/lsp ./ci-artifacts/final/opengoal-lsp-macos-arm-${TAG_VAL}.bin
- name: Upload Assets
env:
Expand Down
17 changes: 5 additions & 12 deletions common/util/gltf_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,19 +684,12 @@ bool material_has_envmap(const tinygltf::Material& mat) {
return mat.extensions.contains("KHR_materials_specular");
}

bool envmap_is_valid(const tinygltf::Material& mat, bool die) {
bool envmap_is_valid(const tinygltf::Material& mat) {
if (material_has_envmap(mat) && mat.pbrMetallicRoughness.metallicRoughnessTexture.index < 0) {
std::string error = fmt::format(
"Material \"{}\" has specular property set, but is missing a metallic roughness texture! "
"Check "
"that the Specular IOR level for the material is at the default of 0.5 if this is "
"unintended.",
mat.name);
if (die) {
lg::die(error);
} else {
lg::error(error);
}
lg::warn(fmt::format(
"Material \"{}\" has specular property set, but is missing a metallic roughness texture, "
"ignoring envmap!",
mat.name));
return false;
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion common/util/gltf_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ struct EnvmapSettings {

EnvmapSettings envmap_settings_from_gltf(const tinygltf::Material& mat);
bool material_has_envmap(const tinygltf::Material& mat);
bool envmap_is_valid(const tinygltf::Material& mat, bool die);
bool envmap_is_valid(const tinygltf::Material& mat);

/*!
* Find the index of the skin for this model. Returns nullopt if there is no skin, the index of the
Expand Down
4 changes: 3 additions & 1 deletion decompiler/level_extractor/extract_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,12 @@ void extract_art_groups_from_level(const ObjectFileDB& db,
std::map<std::string, level_tools::ArtData>& art_group_data) {
if (db.obj_files_by_dgo.count(dgo_name)) {
const auto& files = db.obj_files_by_dgo.at(dgo_name);
MercSwapInfo swapped_info;
for (const auto& file : files) {
if (file.name.length() > 3 && !file.name.compare(file.name.length() - 3, 3, "-ag")) {
const auto& ag_file = db.lookup_record(file);
extract_merc(ag_file, tex_db, db.dts, tex_remap, level_data, false, db.version());
extract_merc(ag_file, tex_db, db.dts, tex_remap, level_data, false, db.version(),
swapped_info);
extract_joint_group(ag_file, db.dts, db.version(), art_group_data);
}
}
Expand Down
34 changes: 34 additions & 0 deletions decompiler/level_extractor/extract_level.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,40 @@

namespace decompiler {

// info about what models have been replaced/added per level
struct MercSwapInfo {
std::map<std::string, std::vector<std::string>> per_level_merc_swaps;
std::map<std::string, std::vector<std::string>> per_level_custom_mdls;

bool already_swapped(const std::string& model, const std::string& level) {
auto mdls_it = per_level_merc_swaps.find(level);
if (mdls_it != per_level_merc_swaps.end()) {
auto& mdls = mdls_it->second;
auto mdl = std::find(mdls.begin(), mdls.end(), model);
return mdl != mdls.end();
}
return false;
}

bool already_added(const std::string& model, const std::string& level) {
auto mdls_it = per_level_custom_mdls.find(level);
if (mdls_it != per_level_custom_mdls.end()) {
auto& mdls = mdls_it->second;
auto mdl = std::find(mdls.begin(), mdls.end(), model);
return mdl != mdls.end();
}
return false;
}

void add_to_swapped_list(const std::string& model, const std::string& level) {
per_level_merc_swaps[level].push_back(model);
}

void add_to_custom_list(const std::string& model, const std::string& level) {
per_level_custom_mdls[level].push_back(model);
}
};

// extract everything
void extract_all_levels(const ObjectFileDB& db,
const TextureDB& tex_db,
Expand Down
59 changes: 36 additions & 23 deletions decompiler/level_extractor/extract_merc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1669,7 +1669,8 @@ void extract_merc(const ObjectFileData& ag_data,
const std::vector<level_tools::TextureRemap>& map,
tfrag3::Level& out,
bool dump_level,
GameVersion version) {
GameVersion version,
MercSwapInfo& swapped_info) {
if (dump_level) {
file_util::create_dir_if_needed(file_util::get_file_path({"debug_out/merc"}));
}
Expand Down Expand Up @@ -1795,31 +1796,43 @@ void extract_merc(const ObjectFileData& ag_data,
}
}

// do model replacements if present
auto merc_replacement_folder = file_util::get_jak_project_dir() / "custom_assets" /
game_version_names[version] / "merc_replacements";
if (file_util::file_exists(merc_replacement_folder.string())) {
auto merc_replacements =
file_util::find_files_in_dir(merc_replacement_folder, std::regex(".*\\.glb"));
for (auto& path : merc_replacements) {
auto name = path.stem().string();
auto it = std::find_if(out.merc_data.models.begin(), out.merc_data.models.end(),
[&](const auto& m) { return m.name == name; });
if (it != out.merc_data.models.end()) {
auto& model = *it;
replace_model(out, model, path);
// do model replacement if present
for (auto& ctrl : ctrls) {
auto merc_replacements_path = file_util::get_jak_project_dir() / "custom_assets" /
game_version_names[version] / "merc_replacements";
if (!swapped_info.already_swapped(ctrl.name, out.level_name)) {
if (file_util::file_exists(merc_replacements_path.string())) {
std::string file_name(ctrl.name + ".glb");
auto mdl_path = merc_replacements_path / file_name;
if (file_util::file_exists(mdl_path.string())) {
auto it = std::find_if(out.merc_data.models.begin(), out.merc_data.models.end(),
[&](const auto& m) { return m.name == ctrl.name; });
if (it != out.merc_data.models.end()) {
auto& model = *it;
replace_model(out, model, mdl_path);
swapped_info.add_to_swapped_list(ctrl.name, out.level_name);
}
}
} else {
lg::info("{} in level {} was already swapped, skipping", ctrl.name, out.level_name);
}
}
}

// add custom models if present
auto lvl_name = out.level_name == "" ? "common" : out.level_name;
auto models_folder = file_util::get_jak_project_dir() / "custom_assets" /
game_version_names[version] / "models" / lvl_name;
if (file_util::file_exists(models_folder.string())) {
auto custom_models = file_util::find_files_in_dir(models_folder, std::regex(".*\\.glb"));
for (auto& mdl : custom_models) {
add_custom_model_to_level(out, mdl.stem().string(), mdl);
// add custom models if present
auto lvl_name = out.level_name == "" ? "common" : out.level_name;
auto models_folder = file_util::get_jak_project_dir() / "custom_assets" /
game_version_names[version] / "models" / lvl_name;
if (file_util::file_exists(models_folder.string())) {
auto custom_models = file_util::find_files_in_dir(models_folder, std::regex(".*\\.glb"));
for (auto& mdl : custom_models) {
auto name = mdl.stem().string();
if (!swapped_info.already_added(name, lvl_name)) {
add_custom_model_to_level(out, name, mdl);
swapped_info.add_to_custom_list(name, lvl_name);
} else {
lg::info("custom model {} was already added to level {}, skipping", name, lvl_name);
}
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion decompiler/level_extractor/extract_merc.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "extract_level.h"

#include "common/custom_data/Tfrag3Data.h"

#include "decompiler/ObjectFile/ObjectFileDB.h"
Expand All @@ -14,5 +16,6 @@ void extract_merc(const ObjectFileData& ag_data,
const std::vector<level_tools::TextureRemap>& map,
tfrag3::Level& out,
bool dump_level,
GameVersion version);
GameVersion version,
MercSwapInfo& swapped_info);
} // namespace decompiler
12 changes: 6 additions & 6 deletions decompiler/level_extractor/merc_replacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ void extract(const std::string& name,
std::map<int, tfrag3::MercDraw> draw_by_material;
int mesh_count = 0;
int prim_count = 0;
bool has_envmaps = false;
int joints = 3;
auto skin_idx = find_single_skin(model, all_nodes);
if (skin_idx) {
Expand Down Expand Up @@ -80,8 +79,11 @@ void extract(const std::string& name,

tfrag3::MercEffect e;
tfrag3::MercEffect envmap_eff;
envmap_eff.has_envmap = false;
out.new_model.name = name;
out.new_model.max_bones = joints;
// if we have a skeleton, use that joint count, otherwise use a high default value since the model
// we replace can have more
out.new_model.max_bones = joints != 3 ? joints : 100;
out.new_model.max_draws = 0;

auto process_normal_draw = [&](tfrag3::MercEffect& eff, int mat_idx, const tfrag3::MercDraw& d_) {
Expand Down Expand Up @@ -161,11 +163,9 @@ void extract(const std::string& name,

for (const auto& [mat_idx, d_] : draw_by_material) {
const auto& mat = model.materials[mat_idx];
if (!material_has_envmap(mat)) {
if (!material_has_envmap(mat) || !envmap_is_valid(mat)) {
process_normal_draw(e, mat_idx, d_);
} else {
envmap_is_valid(mat, true);
has_envmaps = true;
envmap_eff.has_envmap = true;
process_envmap_draw(envmap_eff, mat_idx, d_);
}
Expand All @@ -175,7 +175,7 @@ void extract(const std::string& name,
if (!e.all_draws.empty()) {
out.new_model.effects.push_back(e);
}
if (has_envmaps) {
if (envmap_eff.has_envmap) {
out.new_model.effects.push_back(envmap_eff);
}

Expand Down
24 changes: 20 additions & 4 deletions game/graphics/opengl_renderer/debug_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,26 @@ void OpenGlDebugGui::draw(const DmaStats& dma_stats) {
}

if (!Gfx::g_debug_settings.ignore_hide_imgui) {
ImGui::Text("%s", fmt::format("Toggle toolbar with {}",
sdl_util::get_keyboard_button_name(
Gfx::g_debug_settings.hide_imgui_key, InputModifiers()))
.c_str());
std::string button_text =
fmt::format("Click here or Press {} to hide Toolbar",
sdl_util::get_keyboard_button_name(Gfx::g_debug_settings.hide_imgui_key,
InputModifiers()));

ImVec2 text_size = ImGui::CalcTextSize(button_text.c_str());
float button_width = text_size.x + ImGui::GetStyle().FramePadding.x * 2;
float button_height = text_size.y + ImGui::GetStyle().FramePadding.y * 2;

ImGui::PushStyleColor(ImGuiCol_Header, ImGui::GetStyleColorVec4(ImGuiCol_MenuBarBg));
ImGui::PushStyleColor(ImGuiCol_HeaderHovered,
ImGui::GetStyleColorVec4(ImGuiCol_HeaderHovered));
ImGui::PushStyleColor(ImGuiCol_HeaderActive, ImGui::GetStyleColorVec4(ImGuiCol_HeaderActive));

if (ImGui::Selectable(button_text.c_str(), false, ImGuiSelectableFlags_DontClosePopups,
ImVec2(button_width, button_height))) {
std::shared_ptr<GfxDisplay> display = Display::GetMainDisplay();
display->set_imgui_visible(false);
}
ImGui::PopStyleColor(3);
}
}
ImGui::EndMainMenuBar();
Expand Down
59 changes: 57 additions & 2 deletions game/sound/989snd/blocksound_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ BlockSoundHandler::BlockSoundHandler(SoundBank& bank,
s32 sfx_vol,
s32 sfx_pan,
SndPlayParams& params,
u32 sound_id)
: m_group(sfx.VolGroup), m_sfx(sfx), m_vm(vm), m_bank(bank), m_sound_id(sound_id) {
u32 sound_id,
s32 start_tick)
: m_group(sfx.VolGroup),
m_sfx(sfx),
m_vm(vm),
m_bank(bank),
m_sound_id(sound_id),
m_start_tick(start_tick) {
s32 vol, pan, pitch_mod, pitch_bend;
if (sfx_vol == -1) {
sfx_vol = sfx.Vol;
Expand Down Expand Up @@ -298,4 +304,53 @@ void BlockSoundHandler::DoGrain() {
m_countdown = m_sfx.Grains[m_next_grain].Delay + ret;
}

SoundHandler* BlockSoundHandler::CheckInstanceLimit(
const std::map<u32, std::unique_ptr<SoundHandler>>& handlers,
s32 vol) {
if (!m_sfx.InstanceLimit) {
return nullptr;
}

if (!m_sfx.Flags.has_instlimit()) {
return nullptr;
}

BlockSoundHandler* weakest = nullptr;
int inst = 0;

for (const auto& [id, handler_ptr] : handlers) {
// Only compare to BlockSoundHandlers
auto* handler = dynamic_cast<BlockSoundHandler*>(handler_ptr.get());
if (!handler) {
continue;
}

// See if this is playing the same sound
// 989snd checks both an orig_sound and a SH.Sound, but we never change the sound.
// We'd need to revisit this if we eventually support BRANCH grains.
if (&handler->m_sfx == &m_sfx) {
inst++;
if (!weakest || //
(m_sfx.Flags.instlimit_vol() && handler->m_app_volume < weakest->m_app_volume) || //
(m_sfx.Flags.instlimit_tick() && handler->m_start_tick < weakest->m_start_tick)) {
weakest = handler;
}
}
}

// See if this handler would cause us to exceed the limit
if (m_sfx.InstanceLimit - 1 < inst) {
if (weakest && ((m_sfx.Flags.instlimit_vol() && weakest->m_app_volume < vol) ||
m_sfx.Flags.instlimit_tick())) {
// existing weakest is worst
return weakest;
} else {
// new sound is weakest
return this;
}
} else {
return nullptr;
}
}

} // namespace snd
7 changes: 6 additions & 1 deletion game/sound/989snd/blocksound_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class BlockSoundHandler : public SoundHandler {
s32 sfx_vol,
s32 sfx_pan,
SndPlayParams& params,
u32 sound_id);
u32 sound_id,
s32 start_tick);

~BlockSoundHandler() override;
bool Tick() override;
Expand All @@ -46,6 +47,9 @@ class BlockSoundHandler : public SoundHandler {

void UpdatePitch();

SoundHandler* CheckInstanceLimit(const std::map<u32, std::unique_ptr<SoundHandler>>& handlers,
s32 vol) override;

bool m_paused{false};

u8 m_group{0};
Expand Down Expand Up @@ -90,5 +94,6 @@ class BlockSoundHandler : public SoundHandler {
u32 m_next_grain{0};

u32 m_sound_id{0};
s32 m_start_tick{0};
};
} // namespace snd
Loading

0 comments on commit 92c5397

Please sign in to comment.