Files
jak-project/goalc/data_compiler/dir_tpages.cpp
T
water111 6366068bc0 Support dir tpages (#671)
* support dir tpages

* fix warnings and bad return

* one more try

* revive the offline test script

* fix this null bug
2021-07-02 14:50:58 -04:00

37 lines
1.1 KiB
C++

#include "dir_tpages.h"
#include "DataObjectGenerator.h"
#include "common/goos/Reader.h"
#include "common/goos/ParseHelpers.h"
#include "common/util/FileUtil.h"
void compile_dir_tpages(const std::string& filename) {
std::vector<int> lengths;
printf("[Build tpage dir] %s\n", filename.c_str());
goos::Reader reader;
auto code = reader.read_from_file({filename});
std::string err;
goos::for_each_in_list(code.as_pair()->cdr, [&](const goos::Object& obj) {
if (!obj.is_int()) {
throw std::runtime_error("Invalid tpage dir file");
}
lengths.push_back(obj.as_int());
});
DataObjectGenerator gen;
gen.add_type_tag("texture-page-dir");
gen.add_word(lengths.size());
for (auto len : lengths) {
gen.add_word(len);
gen.add_symbol_link("#f");
gen.add_symbol_link("#f");
}
auto data = gen.generate_v4();
file_util::create_dir_if_needed(file_util::get_file_path({"out", "obj"}));
file_util::write_binary_file(file_util::get_file_path({"out", "obj", "dir-tpages.go"}),
data.data(), data.size());
}