mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-08 13:44:56 +00:00
Add parallel progress printing
This commit is contained in:
@@ -270,115 +270,4 @@ static hecl::SystemString MakePathArgAbsolute(const hecl::SystemString& arg,
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool g_HasLastProgTime = false;
|
||||
static std::chrono::steady_clock::time_point g_LastProgTime;
|
||||
|
||||
void ToolPrintProgress(const hecl::SystemChar* message, const hecl::SystemChar* submessage,
|
||||
int lidx, float factor, int& lineIdx)
|
||||
{
|
||||
if (g_HasLastProgTime)
|
||||
{
|
||||
std::chrono::steady_clock::time_point newPoint = std::chrono::steady_clock::now();
|
||||
std::chrono::milliseconds::rep delta =
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(newPoint - g_LastProgTime).count();
|
||||
if (delta < 50)
|
||||
return;
|
||||
g_LastProgTime = newPoint;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_HasLastProgTime = true;
|
||||
g_LastProgTime = std::chrono::steady_clock::now();
|
||||
}
|
||||
|
||||
auto lk = logvisor::LockLog();
|
||||
|
||||
bool blocks = factor >= 0.0;
|
||||
factor = std::max(0.0f, std::min(1.0f, factor));
|
||||
int iFactor = factor * 100.0;
|
||||
if (XTERM_COLOR)
|
||||
hecl::Printf(_S("" HIDE_CURSOR ""));
|
||||
|
||||
if (lidx > lineIdx)
|
||||
{
|
||||
hecl::Printf(_S("\n "));
|
||||
lineIdx = lidx;
|
||||
}
|
||||
else
|
||||
hecl::Printf(_S(" "));
|
||||
|
||||
int width = (hecl::GuiMode ? 120 : std::max(80, hecl::ConsoleWidth()));
|
||||
int half;
|
||||
if (blocks)
|
||||
half = width / 2 - 2;
|
||||
else
|
||||
half = width - 4;
|
||||
|
||||
if (!message)
|
||||
message = _S("");
|
||||
int messageLen = hecl::StrLen(message);
|
||||
if (!submessage)
|
||||
submessage = _S("");
|
||||
int submessageLen = hecl::StrLen(submessage);
|
||||
if (half - messageLen < submessageLen-2)
|
||||
submessageLen = 0;
|
||||
|
||||
if (submessageLen)
|
||||
{
|
||||
if (messageLen > half-submessageLen-1)
|
||||
hecl::Printf(_S("%.*s... %s "), half-submessageLen-4, message, submessage);
|
||||
else
|
||||
{
|
||||
hecl::Printf(_S("%s"), message);
|
||||
for (int i=half-messageLen-submessageLen-1 ; i>=0 ; --i)
|
||||
hecl::Printf(_S(" "));
|
||||
hecl::Printf(_S("%s "), submessage);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (messageLen > half)
|
||||
hecl::Printf(_S("%.*s... "), half-3, message);
|
||||
else
|
||||
{
|
||||
hecl::Printf(_S("%s"), message);
|
||||
for (int i=half-messageLen ; i>=0 ; --i)
|
||||
hecl::Printf(_S(" "));
|
||||
}
|
||||
}
|
||||
|
||||
if (blocks)
|
||||
{
|
||||
if (XTERM_COLOR)
|
||||
{
|
||||
int blocks = half - 7;
|
||||
int filled = blocks * factor;
|
||||
int rem = blocks - filled;
|
||||
hecl::Printf(_S("" BOLD "%3d%% ["), iFactor);
|
||||
for (int b=0 ; b<filled ; ++b)
|
||||
hecl::Printf(_S("#"));
|
||||
for (int b=0 ; b<rem ; ++b)
|
||||
hecl::Printf(_S("-"));
|
||||
hecl::Printf(_S("]" NORMAL ""));
|
||||
}
|
||||
else
|
||||
{
|
||||
int blocks = half - 7;
|
||||
int filled = blocks * factor;
|
||||
int rem = blocks - filled;
|
||||
hecl::Printf(_S("%3d%% ["), iFactor);
|
||||
for (int b=0 ; b<filled ; ++b)
|
||||
hecl::Printf(_S("#"));
|
||||
for (int b=0 ; b<rem ; ++b)
|
||||
hecl::Printf(_S("-"));
|
||||
hecl::Printf(_S("]"));
|
||||
}
|
||||
}
|
||||
|
||||
hecl::Printf(_S("\r"));
|
||||
if (XTERM_COLOR)
|
||||
hecl::Printf(_S("" SHOW_CURSOR ""));
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
#endif // CTOOL_BASE
|
||||
|
||||
@@ -10,6 +10,7 @@ class ToolCook final : public ToolBase
|
||||
std::vector<hecl::ProjectPath> m_selectedItems;
|
||||
std::unique_ptr<hecl::Database::Project> m_fallbackProj;
|
||||
hecl::Database::Project* m_useProj;
|
||||
const hecl::Database::DataSpecEntry* m_spec = nullptr;
|
||||
bool m_recursive = false;
|
||||
bool m_fast = false;
|
||||
public:
|
||||
@@ -35,6 +36,21 @@ public:
|
||||
m_fast = true;
|
||||
continue;
|
||||
}
|
||||
else if (arg.size() >= 8 && !arg.compare(0, 7, _S("--spec=")))
|
||||
{
|
||||
hecl::SystemString specName(arg.begin() + 7, arg.end());
|
||||
for (const hecl::Database::DataSpecEntry* spec : hecl::Database::DATA_SPEC_REGISTRY)
|
||||
{
|
||||
if (!hecl::StrCaseCmp(spec->m_name.data(), specName.c_str()))
|
||||
{
|
||||
m_spec = spec;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!m_spec)
|
||||
LogModule.report(logvisor::Fatal, "unable to find data spec '%s'", specName.c_str());
|
||||
continue;
|
||||
}
|
||||
else if (arg.size() >= 2 && arg[0] == _S('-') && arg[1] == _S('-'))
|
||||
continue;
|
||||
|
||||
@@ -80,7 +96,7 @@ public:
|
||||
|
||||
help.secHead(_S("SYNOPSIS"));
|
||||
help.beginWrap();
|
||||
help.wrap(_S("hecl cook [-rf] [--fast] [<pathspec>...]\n"));
|
||||
help.wrap(_S("hecl cook [-rf] [--fast] [--spec=<spec>] [<pathspec>...]\n"));
|
||||
help.endWrap();
|
||||
|
||||
help.secHead(_S("DESCRIPTION"));
|
||||
@@ -131,18 +147,29 @@ public:
|
||||
help.beginWrap();
|
||||
help.wrap(_S("Performs draft-optimization cooking for supported data types.\n"));
|
||||
help.endWrap();
|
||||
|
||||
help.optionHead(_S("--spec=<spec>"), _S("data specification"));
|
||||
help.beginWrap();
|
||||
help.wrap(_S("Specifies a DataSpec to use when cooking. ")
|
||||
_S("This build of hecl supports the following values of <spec>:\n"));
|
||||
for (const hecl::Database::DataSpecEntry* spec : hecl::Database::DATA_SPEC_REGISTRY)
|
||||
{
|
||||
if (!spec->m_factory)
|
||||
continue;
|
||||
help.wrap(_S(" "));
|
||||
help.wrapBold(spec->m_name.data());
|
||||
help.wrap(_S("\n"));
|
||||
}
|
||||
}
|
||||
|
||||
hecl::SystemString toolName() const {return _S("cook");}
|
||||
|
||||
int run()
|
||||
{
|
||||
hecl::ClientProcess cp(m_info.verbosityLevel, m_fast, m_info.force);
|
||||
hecl::MultiProgressPrinter printer(true);
|
||||
hecl::ClientProcess cp(&printer, m_info.verbosityLevel);
|
||||
for (const hecl::ProjectPath& path : m_selectedItems)
|
||||
{
|
||||
int lineIdx = 0;
|
||||
m_useProj->cookPath(path, {}, m_recursive, m_info.force, m_fast, &cp);
|
||||
}
|
||||
m_useProj->cookPath(path, printer, m_recursive, m_info.force, m_fast, m_spec, &cp);
|
||||
cp.waitUntilComplete();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#include <termios.h>
|
||||
#endif
|
||||
|
||||
#include "hecl/MultiProgressPrinter.hpp"
|
||||
|
||||
class ToolExtract final : public ToolBase
|
||||
{
|
||||
hecl::Database::IDataSpec::ExtractPassInfo m_einfo;
|
||||
@@ -177,12 +179,7 @@ public:
|
||||
else
|
||||
hecl::Printf(_S("Using DataSpec %s:\n"), ds.m_entry->m_name.data());
|
||||
|
||||
int lineIdx = 0;
|
||||
ds.m_instance->doExtract(m_einfo,
|
||||
[&lineIdx](const hecl::SystemChar* message,
|
||||
const hecl::SystemChar* submessage,
|
||||
int lidx, float factor)
|
||||
{ToolPrintProgress(message, submessage, lidx, factor, lineIdx);});
|
||||
ds.m_instance->doExtract(m_einfo, {true});
|
||||
hecl::Printf(_S("\n\n"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ class ToolPackage final : public ToolBase
|
||||
std::vector<hecl::ProjectPath> m_selectedItems;
|
||||
std::unique_ptr<hecl::Database::Project> m_fallbackProj;
|
||||
hecl::Database::Project* m_useProj;
|
||||
const hecl::Database::DataSpecEntry* m_spec = nullptr;
|
||||
bool m_fast = false;
|
||||
|
||||
void AddSelectedItem(const hecl::ProjectPath& path)
|
||||
@@ -85,6 +86,21 @@ public:
|
||||
m_fast = true;
|
||||
continue;
|
||||
}
|
||||
else if (arg.size() >= 8 && !arg.compare(0, 7, _S("--spec=")))
|
||||
{
|
||||
hecl::SystemString specName(arg.begin() + 7, arg.end());
|
||||
for (const hecl::Database::DataSpecEntry* spec : hecl::Database::DATA_SPEC_REGISTRY)
|
||||
{
|
||||
if (!hecl::StrCaseCmp(spec->m_name.data(), specName.c_str()))
|
||||
{
|
||||
m_spec = spec;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!m_spec)
|
||||
LogModule.report(logvisor::Fatal, "unable to find data spec '%s'", specName.c_str());
|
||||
continue;
|
||||
}
|
||||
else if (arg.size() >= 2 && arg[0] == _S('-') && arg[1] == _S('-'))
|
||||
continue;
|
||||
|
||||
@@ -133,7 +149,7 @@ public:
|
||||
|
||||
help.secHead(_S("SYNOPSIS"));
|
||||
help.beginWrap();
|
||||
help.wrap(_S("hecl package [-a] [-o <package-out>] [<input-dir>]\n"));
|
||||
help.wrap(_S("hecl package [--spec=<spec>] [<input-dir>]\n"));
|
||||
help.endWrap();
|
||||
|
||||
help.secHead(_S("DESCRIPTION"));
|
||||
@@ -144,23 +160,26 @@ public:
|
||||
help.endWrap();
|
||||
|
||||
help.secHead(_S("OPTIONS"));
|
||||
help.optionHead(_S("<dir>"), _S("input directory"));
|
||||
help.optionHead(_S("--spec=<spec>"), _S("data specification"));
|
||||
help.beginWrap();
|
||||
help.wrap(_S("Specifies a DataSpec to use when cooking and generating the package. ")
|
||||
_S("This build of hecl supports the following values of <spec>:\n"));
|
||||
for (const hecl::Database::DataSpecEntry* spec : hecl::Database::DATA_SPEC_REGISTRY)
|
||||
{
|
||||
if (!spec->m_factory)
|
||||
continue;
|
||||
help.wrap(_S(" "));
|
||||
help.wrapBold(spec->m_name.data());
|
||||
help.wrap(_S("\n"));
|
||||
}
|
||||
help.endWrap();
|
||||
|
||||
help.secHead(_S("OPTIONS"));
|
||||
help.optionHead(_S("<input-dir>"), _S("input directory"));
|
||||
help.beginWrap();
|
||||
help.wrap(_S("Specifies a project subdirectory to root the resulting package from. ")
|
||||
_S("If any dependent-files fall outside this subdirectory, they will implicitly ")
|
||||
_S("be gathered and packaged.\n"));
|
||||
help.endWrap();
|
||||
|
||||
help.optionHead(_S("-o <package-out>"), _S("output package file"));
|
||||
help.beginWrap();
|
||||
help.wrap(_S("Specifies a target path to write the package. If not specified, the package ")
|
||||
_S("is written into <project-root>/out/<relative-input-dirs>/<input-dir>.upak\n"));
|
||||
help.endWrap();
|
||||
|
||||
help.optionHead(_S("-a"), _S("auto cook"));
|
||||
help.beginWrap();
|
||||
help.wrap(_S("Any referenced objects that haven't already been cooked are automatically cooked as ")
|
||||
_S("part of the packaging process. If this flag is omitted, the packaging process will abort.\n"));
|
||||
_S("If any dependent files fall outside this subdirectory, they will be implicitly ")
|
||||
_S("gathered and packaged.\n"));
|
||||
help.endWrap();
|
||||
}
|
||||
|
||||
@@ -179,10 +198,11 @@ public:
|
||||
|
||||
if (continuePrompt())
|
||||
{
|
||||
hecl::ClientProcess cp(m_info.verbosityLevel, m_fast, m_info.force);
|
||||
hecl::MultiProgressPrinter printer(true);
|
||||
hecl::ClientProcess cp(&printer, m_info.verbosityLevel);
|
||||
for (const hecl::ProjectPath& path : m_selectedItems)
|
||||
{
|
||||
if (!m_useProj->packagePath(path, {}, m_fast, &cp))
|
||||
if (!m_useProj->packagePath(path, printer, m_fast, m_spec, &cp))
|
||||
LogModule.report(logvisor::Error, _S("Unable to package %s"), path.getAbsolutePath().data());
|
||||
}
|
||||
cp.waitUntilComplete();
|
||||
|
||||
Reference in New Issue
Block a user