From 2d0f0799917e37e387f101800bc5470fec85b688 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Tue, 9 Jan 2018 20:16:18 -1000 Subject: [PATCH] Add CVarCommons; hecl-light library --- hecl/driver/CMakeLists.txt | 2 +- hecl/driver/ToolBase.hpp | 37 +++++++++--- hecl/driver/main.cpp | 1 + hecl/extern/boo | 2 +- hecl/include/hecl/CVarCommons.hpp | 80 +++++++++++++++++++++++++ hecl/lib/Blender/CMakeLists.txt | 2 +- hecl/lib/Blender/Connection.cpp | 3 +- hecl/lib/CMakeLists.txt | 97 +++++++++++++++++-------------- hecl/lib/WideStringConvert.cpp | 9 +-- hecl/test/CMakeLists.txt | 5 +- 10 files changed, 174 insertions(+), 64 deletions(-) create mode 100644 hecl/include/hecl/CVarCommons.hpp diff --git a/hecl/driver/CMakeLists.txt b/hecl/driver/CMakeLists.txt index d0890eab7..abecf08d1 100644 --- a/hecl/driver/CMakeLists.txt +++ b/hecl/driver/CMakeLists.txt @@ -23,7 +23,7 @@ endif() target_link_libraries(hecl ${DATA_SPEC_LIBS} - hecl-common hecl-blender-addon athena-core nod + hecl-full hecl-blender-addon athena-core nod logvisor athena-libyaml ${PNG_LIB} squish xxhash zeus boo ${ZLIB_LIBRARIES} ${LZO_LIB} ${PLAT_LIBS} ${BOO_SYS_LIBS}) diff --git a/hecl/driver/ToolBase.hpp b/hecl/driver/ToolBase.hpp index 16d5717f5..c57bb8a3c 100644 --- a/hecl/driver/ToolBase.hpp +++ b/hecl/driver/ToolBase.hpp @@ -63,6 +63,7 @@ protected: hecl::Printf(_S("\n" BLUE BOLD "Continue?" NORMAL " (Y/n) ")); else hecl::Printf(_S("\nContinue? (Y/n) ")); + fflush(stdout); int ch; #ifndef _WIN32 @@ -269,9 +270,27 @@ 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(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; @@ -297,17 +316,17 @@ void ToolPrintProgress(const hecl::SystemChar* message, const hecl::SystemChar* if (!message) message = _S(""); - size_t messageLen = hecl::StrLen(message); + int messageLen = hecl::StrLen(message); if (!submessage) submessage = _S(""); - size_t submessageLen = hecl::StrLen(submessage); + 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-int(submessageLen)-4, message, submessage); + hecl::Printf(_S("%.*s... %s "), half-submessageLen-4, message, submessage); else { hecl::Printf(_S("%s"), message); @@ -332,9 +351,9 @@ void ToolPrintProgress(const hecl::SystemChar* message, const hecl::SystemChar* { if (XTERM_COLOR) { - size_t blocks = half - 7; - size_t filled = blocks * factor; - size_t rem = blocks - filled; + int blocks = half - 7; + int filled = blocks * factor; + int rem = blocks - filled; hecl::Printf(_S("" BOLD "%3d%% ["), iFactor); for (int b=0 ; btoLiteral(); + } + + void setGraphicsApi(std::string_view api) + { + m_graphicsApi->fromLiteral(api); + } + + uint32_t getSamples() const + { + return uint32_t(std::max(1, m_drawSamples->toInteger())); + } + + void setSamples(uint32_t v) + { + m_drawSamples->fromInteger(std::max(uint32_t(1), v)); + } + + uint32_t getAnisotropy() const + { + return uint32_t(std::max(1, m_texAnisotropy->toInteger())); + } + + void setAnisotropy(uint32_t v) const + { + m_texAnisotropy->fromInteger(std::max(uint32_t(1), v)); + } + + void serialize() + { + m_mgr.serialize(); + } +}; + +} + +#endif // CVARCOMMONS_HPP diff --git a/hecl/lib/Blender/CMakeLists.txt b/hecl/lib/Blender/CMakeLists.txt index a0d1d45fb..6634e8f9e 100644 --- a/hecl/lib/Blender/CMakeLists.txt +++ b/hecl/lib/Blender/CMakeLists.txt @@ -1,5 +1,5 @@ set(BLENDER_SOURCES - Connection.cpp + Connection.cpp HMDL.cpp) hecl_add_list(Blender BLENDER_SOURCES) diff --git a/hecl/lib/Blender/Connection.cpp b/hecl/lib/Blender/Connection.cpp index 06b1cb2c6..827a864a4 100644 --- a/hecl/lib/Blender/Connection.cpp +++ b/hecl/lib/Blender/Connection.cpp @@ -278,7 +278,6 @@ Connection::Connection(int verbosityLevel) int installAttempt = 0; while (true) { - /* Construct communication pipes */ #if _WIN32 _pipe(m_readpipe, 2048, _O_BINARY); @@ -1648,7 +1647,7 @@ Action::Action(Connection& conn) subtypeAABBs.reserve(aabbCount); for (uint32_t i=0 ; i(mb), c); @@ -32,7 +33,7 @@ std::string Char16ToUTF8(std::u16string_view src) utf8proc_ssize_t c = utf8proc_encode_char(utf8proc_int32_t(ch), mb); if (c < 0) { - LogModule.report(logvisor::Warning, "invalid UTF-8 character while encoding"); + Log.report(logvisor::Warning, "invalid UTF-8 character while encoding"); return retval; } retval.append(reinterpret_cast(mb), c); @@ -51,7 +52,7 @@ std::wstring UTF8ToWide(std::string_view src) utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc); if (len < 0) { - LogModule.report(logvisor::Warning, "invalid UTF-8 character while decoding"); + Log.report(logvisor::Warning, "invalid UTF-8 character while decoding"); return retval; } buf += len; @@ -71,7 +72,7 @@ std::u16string UTF8ToChar16(std::string_view src) utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc); if (len < 0) { - LogModule.report(logvisor::Warning, "invalid UTF-8 character while decoding"); + Log.report(logvisor::Warning, "invalid UTF-8 character while decoding"); return retval; } buf += len; diff --git a/hecl/test/CMakeLists.txt b/hecl/test/CMakeLists.txt index fbf634557..1b64110b2 100644 --- a/hecl/test/CMakeLists.txt +++ b/hecl/test/CMakeLists.txt @@ -1,4 +1,5 @@ add_executable(heclTest WIN32 main.cpp) target_link_libraries(heclTest - hecl-common hecl-blender-addon athena-core athena-libyaml xxhash - logvisor boo ${ZLIB_LIBRARIES} ${LZO_LIB} ${BOO_SYS_LIBS}) + hecl-full hecl-blender-addon + athena-core athena-libyaml xxhash logvisor boo + ${ZLIB_LIBRARIES} ${LZO_LIB} ${BOO_SYS_LIBS})