Files
Diddy-Kong-Racing/tools/dkr_assets_tool_src/builder/buildInfoCollection.cpp
David Benepe e30f1c535a DKR Assets Tool v0.5.2 (Basic glTF support) (#610)
* Removed old unused files

* Added gltf support

* Reverted dkr_assets_tool_settings.json to previous

* Added animated model example

* document audio_vehicle.c (#588)

* wip

* wip

* wip

* wip

* document audio_vehicle.c

* update score once again

* unify function prefix

* small tweaks

* match func_80060910 and func_80060AC8 (#589)

* match func_80060AC8

* reworked func_80060C58

* match func_80060910

* non equivalent func_8006017C

* format

* match calc_env_mapping_for_object

* Homogenate batch flags and render flags and begin the painful task of documenting waves. (#590)

* part one of wave pain

* 2

* littel bit more

* m

* h

* l

* aagghh

* yeah

* :)

* bruh

* b

* m

* faith

* z

* b

* rename batch flags

* Update waves.c

* fix conflicts

* match func_8000B38C (#592)

* match func_8000B38C

* format code

* update score

* match calc_dynamic_lighting_for_object_1 (#594)

* match calc_dynamic_lighting_for_object_1

* format and score

* update score

* update score again

* Document some Boost data (#593)

* Run formatter

* Document some boost info

* decompile and document math_util.c (#595)

* Match func_8002F440 (#596)

* Add a WIP attempt of func_8004447C, and add some scratch links

* match func_8002F440 and run formatter

* Cleanup some comments

* Update score, fix warnings, and run formatter again

* Remove some bad comments

* match: func_8007FFEC (#599)

* feat: allow score script to generate treemap file for decomp progress (#598)

* Various touchups here and there, some renames in camera.c (#597)

* the beginning of the void

* update asset tool

* void :)

* there

* cam

* model

* more

* fix warns

* ok

* whoops missed a rename

* Add a few NON_EQUIVALENT functions from scratches to keep them up to date (#602)

* WIP func_800101AC

* WIP func_800452A0

* cleanup

* Formatter and func_8004CC20 near match

* func_8004CC20 better score and documentation

* func_80049794 WIP and compilable

* Major cleanup of func_80049794

* Formatter

* Update scratch

* Add func_80019808 from scratch

* Cleanup func_80019808

* func_80019808 score improvment

* Improve func_80049794 score (Thanks Dominik!)

* func_8001C6C4 WIP

* func_8001E93C WIP

* small documenting

* Eliminate a lot of Obj64 casts.

* fix: do not pass default to treemap arg (#604)

* Quick fix for score script (#606)

* WIP func_80060EA8

* Quick fix for score script

* name and document lights, CC modes and textures (#607)

* improve match for func_800BDC80 & match func_80060EA8, func_8002F2AC (#609)

* improve match for func_800BDC80 & match func_80060EA8

* match: func_8002F2AC

* match: func_800452A0 & func_80042D20 (#611)

* partial match: func_800452A0, improve from non equiv to non matching

* match: func_800452A0 & func_80042D20

* document: remaining funcs, add decomp.me links (#612)

* match func_8004447C (#615)

* Document camera and sprites (#614)

* Cleanup, and use constants where possible (#617)

* Update func_80060EA8 WIP

* formatter

* More func_80060EA8

* More func_80060EA8

* WIP func_80060EA8

* Minor cleanups and documenting

* minot cleanup

* Define some constant flags properly

* Misc documenting and cleanup

* formatter

* Fix the scratch link for vsprintf (It was DP's)

* Add the WIP version of vsprintf that's 95.82% matching.

* Fix score script (#619)

* Added gltf support

* Allow either commas or vertical pipes for splitting render flags

---------

Co-authored-by: Unnunu <serge_zorkin@mail.ru>
Co-authored-by: Fazana <52551480+FazanaJ@users.noreply.github.com>
Co-authored-by: Ryan Myers <ryan.p.myers@gmail.com>
Co-authored-by: Dominik Peters <github@d-peters.com>
2025-06-12 10:29:08 -04:00

196 lines
7.1 KiB
C++

#include "buildInfoCollection.h"
#include "libs/ThreadPool.h"
#include "helpers/debugHelper.h"
#include "helpers/dataHelper.h"
#include "misc/globalSettings.h"
using namespace DkrAssetsTool;
const size_t MAX_NUMBER_OF_BUILD_INFOS = 10000;
BuildInfoCollection::BuildInfoCollection() {
fs::path assetsPath = GlobalSettings::get_decomp_path_to_output_assets();
_buildInfos.reserve(MAX_NUMBER_OF_BUILD_INFOS); // More than likely overkill, but I REALLY don't want pointers changing mid-build.
}
BuildInfoCollection::~BuildInfoCollection() {
}
void BuildInfoCollection::add_build_info(std::string sectionBuildId, std::string buildId, const JsonFile &src, const fs::path &dir, const BuildInfoContext &infoContext) {
_buildInfoMutex.lock();
if(_buildInfoSections.find(sectionBuildId) == _buildInfoSections.end()) {
_buildInfoSections[sectionBuildId] = {};
// Textures have a lot of files.
if(sectionBuildId == "ASSET_TEXTURES_2D") {
_buildInfoSections[sectionBuildId].reserve(1000);
} else if(sectionBuildId == "ASSET_TEXTURES_3D") {
_buildInfoSections[sectionBuildId].reserve(1500);
}
}
size_t index = _buildInfos.size();
DebugHelper::assert_(index < MAX_NUMBER_OF_BUILD_INFOS,
"(BuildInfoCollection::add_build_info) Max number of assets reached! Limit was ", MAX_NUMBER_OF_BUILD_INFOS);
size_t fileIndex = _buildInfoSections[sectionBuildId].size();
_buildInfos.emplace_back(buildId, sectionBuildId, src, fileIndex, dir, infoContext);
// Add the index to the section.
_buildInfoSections[sectionBuildId].emplace_back(index);
_buildInfoMutex.unlock();
}
size_t BuildInfoCollection::add_deferred_build_info(std::string sectionBuildId, std::string buildId, std::string deferredFromBuildId, std::string deferredFromSectionId,
const std::vector<uint8_t> &out, const fs::path &dir, const BuildInfoContext &infoContext) {
_buildInfoMutex.lock();
if(_buildInfoSections.find(sectionBuildId) == _buildInfoSections.end()) {
_buildInfoSections[sectionBuildId] = {};
}
int index = _buildInfos.size();
DebugHelper::assert_(index < MAX_NUMBER_OF_BUILD_INFOS,
"(BuildInfoCollection::add_build_info) Max number of assets reached! Limit was ", MAX_NUMBER_OF_BUILD_INFOS);
size_t fileIndex = _buildInfoSections[sectionBuildId].size();
_buildInfos.emplace_back(buildId, sectionBuildId, deferredFromBuildId, deferredFromSectionId, out, fileIndex, dir, infoContext);
// Do not process deferred assets.
_buildInfos.back().done();
// Add the index to the section.
_buildInfoSections[sectionBuildId].emplace_back(index);
_buildInfoMutex.unlock();
return fileIndex;
}
void BuildInfoCollection::add_deferred_build_info(std::string sectionBuildId, std::string buildId, std::string deferredFromBuildId, std::string deferredFromSectionId,
size_t fileIndex, const std::vector<uint8_t> &out, const fs::path &dir, const BuildInfoContext &infoContext) {
_buildInfoMutex.lock();
if(_buildInfoSections.find(sectionBuildId) == _buildInfoSections.end()) {
_buildInfoSections[sectionBuildId] = {};
}
if(_buildInfoSections[sectionBuildId].size() <= fileIndex) {
_buildInfoSections[sectionBuildId].resize(fileIndex + 1);
}
size_t index = _buildInfos.size();
DebugHelper::assert_(index < MAX_NUMBER_OF_BUILD_INFOS,
"(BuildInfoCollection::add_build_info) Max number of assets reached! Limit was ", MAX_NUMBER_OF_BUILD_INFOS);
_buildInfos.emplace_back(buildId, sectionBuildId, deferredFromBuildId, deferredFromSectionId, out, fileIndex, dir, infoContext);
// Do not process deferred assets.
_buildInfos.back().done();
// Add the index to the section.
_buildInfoSections[sectionBuildId][fileIndex] = index;
_buildInfoMutex.unlock();
}
void BuildInfoCollection::run_builds(std::function<void(BuildInfo &)> callbackFunction, const std::vector<std::string> &sectionsOrder) {
size_t threadCount = GlobalSettings::get_max_thread_count();
bool multithreaded = threadCount != 1;
DebugHelper::info_verbose("Using ", threadCount, " thread", (multithreaded ? "s" : ""));
if(multithreaded) {
// Multi-threaded (Better for performance)
ThreadPool pool(threadCount);
for(const std::string &sectionBuildId : sectionsOrder) {
if(_buildInfoSections.find(sectionBuildId) == _buildInfoSections.end()) {
// Skip empty sections.
continue;
}
for(int buildInfoIndex : _buildInfoSections[sectionBuildId]) {
BuildInfo &info = _buildInfos[buildInfoIndex];
pool.enqueue([&info, &callbackFunction] {
if(!info.is_complete()) {
callbackFunction(info);
info.done();
}
});
}
}
} else {
// Single-threaded (Better for debugging)
for(const std::string &sectionBuildId : sectionsOrder) {
if(_buildInfoSections.find(sectionBuildId) == _buildInfoSections.end()) {
// Skip empty sections.
continue;
}
for(int buildInfoIndex : _buildInfoSections[sectionBuildId]) {
BuildInfo &info = _buildInfos[buildInfoIndex];
if(!info.is_complete()) {
callbackFunction(info);
info.done();
}
}
}
}
}
void BuildInfoCollection::get_infos_for_section(std::string sectionBuildId, std::function<void(BuildInfo &info)> callbackFunction) {
std::vector<int> &sectionIndices = _buildInfoSections[sectionBuildId];
for(int buildInfoIndex : sectionIndices) {
callbackFunction(_buildInfos[buildInfoIndex]);
}
}
void BuildInfoCollection::create_assets_file() {
}
void BuildInfoCollection::print_section_counts() {
for(auto &pair : _buildInfoSections) {
DebugHelper::info(pair.first, ": ", pair.second.size());
}
}
std::mutex &BuildInfoCollection::get_global_mutex() {
return _globalMutex;
}
size_t BuildInfoCollection::get_section_count() const {
return _buildInfoSections.size();
}
size_t BuildInfoCollection::get_file_count_for_section(std::string sectionBuildId) const {
if(_buildInfoSections.find(sectionBuildId) == _buildInfoSections.end()) {
return 0;
}
return _buildInfoSections.at(sectionBuildId).size();
}
size_t BuildInfoCollection::get_size_of_section(std::string sectionBuildId) const {
if(_buildInfoSections.find(sectionBuildId) == _buildInfoSections.end()) {
return 0;
}
const std::vector<int> &sectionIndices = _buildInfoSections.at(sectionBuildId);
size_t totalSize = 0;
for(int buildInfoIndex : sectionIndices) {
totalSize += _buildInfos.at(buildInfoIndex).out.size();
}
// Make sure the size is 16-byte aligned
totalSize = DataHelper::align16(totalSize);
return totalSize;
}