[game] subtitles support (tools + goal + text file). (#1174)

* add subtitles support (tools + goal + text file).

* add to build system proper

* better handling of line speakers

* billy test subtitles

* adjust timings

* better handling of subtitle timing + citadel subs

* press square to toggle cutscene subtitles

* improve DirectRenderer performance

* clang

* dont error out if there's no user files

* make system supports multiple inputs for subtitles

* clang

* oh no typo!!

* avoid future issues

* fix warp gate crash

* remove no longer necessary code in DirectRenderer

* remove temp prints

* delete triplicate code

* i found a better way

* fix make issues with subtitles

* force avx compilation
This commit is contained in:
ManDude
2022-02-19 18:10:10 +00:00
committed by GitHub
parent f91d1f4056
commit af447aeab7
46 changed files with 1160 additions and 148 deletions
+50 -17
View File
@@ -11,7 +11,15 @@
#include "goalc/make/Tools.h"
std::string MakeStep::print() const {
std::string result = fmt::format("Tool {} with input \"{}\" and deps:\n ", tool, input);
std::string result = fmt::format("Tool {} with inputs", tool);
int i = 0;
for (auto& in : input) {
if (i++ > 0) {
result += ", ";
}
result += fmt::format("\"{}\"", in);
}
result += " and deps:\n ";
for (auto& dep : deps) {
result += dep;
result += '\n';
@@ -75,8 +83,9 @@ goos::Object MakeSystem::handle_defstep(const goos::Object& form,
va_check(form, args, {},
{{"out", {true, {goos::ObjectType::PAIR}}},
{"tool", {true, {goos::ObjectType::SYMBOL}}},
{"in", {false, {goos::ObjectType::STRING}}},
{"dep", {false, {}}}});
{"in", {false, {}}},
{"dep", {false, {}}},
{"arg", {false, {}}}});
auto step = std::make_shared<MakeStep>();
@@ -91,7 +100,14 @@ goos::Object MakeSystem::handle_defstep(const goos::Object& form,
}
if (args.has_named("in")) {
step->input = args.get_named("in").as_string()->data;
const auto& in = args.get_named("in");
if (in.is_pair()) {
step->input.clear();
goos::for_each_in_list(
in, [&](const goos::Object& o) { step->input.push_back(o.as_string()->data); });
} else {
step->input = {in.as_string()->data};
}
}
if (args.has_named("dep")) {
@@ -100,6 +116,12 @@ goos::Object MakeSystem::handle_defstep(const goos::Object& form,
});
}
if (args.has_named("arg")) {
step->arg = args.get_named("arg");
} else {
step->arg = goos::Object::make_empty_list();
}
for (auto& output : step->outputs) {
auto existing = m_output_to_step.find(output);
if (existing != m_output_to_step.end()) {
@@ -172,8 +194,9 @@ void MakeSystem::get_dependencies(const std::string& master_target,
}
const auto& rule = rule_it->second;
for (auto& dep : m_tools.at(rule->tool)
->get_additional_dependencies({rule->input, rule->deps, rule->outputs})) {
for (auto& dep :
m_tools.at(rule->tool)
->get_additional_dependencies({rule->input, rule->deps, rule->outputs, rule->arg})) {
get_dependencies(master_target, dep, result, result_set);
}
@@ -212,10 +235,11 @@ std::vector<std::string> MakeSystem::filter_dependencies(const std::vector<std::
for (auto& to_make : all_deps) {
auto& rule = m_output_to_step.at(to_make);
auto& tool = m_tools.at(rule->tool);
const ToolInput task = {rule->input, rule->deps, rule->outputs, rule->arg};
bool added = false;
if (tool->needs_run({rule->input, rule->deps, rule->outputs})) {
if (tool->needs_run(task)) {
result.push_back(to_make);
stale_deps.insert(to_make);
added = true;
@@ -235,8 +259,7 @@ std::vector<std::string> MakeSystem::filter_dependencies(const std::vector<std::
if (!added) {
// check transitive dependencies
for (auto& dep :
tool->get_additional_dependencies({rule->input, rule->deps, rule->outputs})) {
for (auto& dep : tool->get_additional_dependencies(task)) {
if (stale_deps.find(dep) != stale_deps.end()) {
result.push_back(to_make);
stale_deps.insert(to_make);
@@ -253,11 +276,19 @@ std::vector<std::string> MakeSystem::filter_dependencies(const std::vector<std::
}
namespace {
void print_input(const std::string& in, char end) {
if (in.length() > 70) {
fmt::print("{}...{}", in.substr(0, 70 - 3), end);
void print_input(const std::vector<std::string>& in, char end) {
int i = 0;
std::string all_names;
for (auto& name : in) {
if (i++ > 0) {
all_names += ", ";
}
all_names += name;
}
if (all_names.length() > 70) {
fmt::print("{}...{}", all_names.substr(0, 70 - 3), end);
} else {
fmt::print("{}{}{}", in, std::string(70 - in.length(), ' '), end);
fmt::print("{}{}{}", all_names, std::string(70 - all_names.length(), ' '), end);
}
}
} // namespace
@@ -286,7 +317,8 @@ bool MakeSystem::make(const std::string& target, bool force, bool verbose) {
auto& tool = m_tools.at(rule->tool);
int percent = (100.0 * (1 + (i++)) / (deps.size())) + 0.5;
if (verbose) {
fmt::print("[{:3d}%] [{:8s}] {}\n", percent, tool->name(), rule->input);
fmt::print("[{:3d}%] [{:8s}] {}{}\n", percent, tool->name(), rule->input.at(0),
rule->input.size() > 1 ? ", ..." : "");
} else {
fmt::print("[{:3d}%] [{:8s}] ", percent, tool->name());
print_input(rule->input, '\r');
@@ -294,13 +326,14 @@ bool MakeSystem::make(const std::string& target, bool force, bool verbose) {
bool success = false;
try {
success = tool->run({rule->input, rule->deps, rule->outputs});
success = tool->run({rule->input, rule->deps, rule->outputs, rule->arg});
} catch (std::exception& e) {
fmt::print("\n");
fmt::print("Error: {}\n", e.what());
}
if (!success) {
fmt::print("Build failed on {}.\n", rule->input);
fmt::print("Build failed on {}{}.\n", rule->input.at(0),
rule->input.size() > 1 ? ", ..." : "");
throw std::runtime_error("Build failed.");
return false;
}
@@ -329,4 +362,4 @@ bool MakeSystem::make(const std::string& target, bool force, bool verbose) {
fmt::print("\nSuccessfully built all {} targets in {:.3f}s\n", deps.size(),
make_timer.getSeconds());
return true;
}
}