From b91fe123b535bcccb0180af5b0565f4862e9fe5e Mon Sep 17 00:00:00 2001 From: poikilos <7557867+poikilos@users.noreply.github.com> Date: Sun, 28 Mar 2021 06:08:53 -0400 Subject: [PATCH] Add a --test-and-exit option. --- Engine.cpp | 28 ++++++++++++++++++++++++++++ Engine.h | 2 ++ UserInterface.cpp | 17 +++++++++++++---- build.sh | 2 +- changelog.md | 3 +++ main.cpp | 13 ++++++++++--- readme.md | 2 ++ 7 files changed, 59 insertions(+), 8 deletions(-) diff --git a/Engine.cpp b/Engine.cpp index eb09fc7..98fd3c6 100644 --- a/Engine.cpp +++ b/Engine.cpp @@ -340,6 +340,7 @@ s32 Engine::getNumberOfVertices() Engine::Engine() { + this->m_EnableTestAndExit = false; settings.set_int("max_recent", 10); std::string profile = std::getenv("HOME"); std::string appdataParent; @@ -582,6 +583,19 @@ bool Engine::loadMesh(const wstring& fileName) return ret; } +bool Engine::pushOption(const std::wstring& optionStr) +{ + if (optionStr == L"--test-and-exit") { + this->m_EnableTestAndExit = true; + std::cerr << "* using option --test-and-exit" << std::endl; + } + else { + std::cerr << "The option is not valid: " << Utility::toString(optionStr) << std::endl; + return false; + } + return true; +} + bool Engine::reloadMesh() { bool ret = false; @@ -885,6 +899,20 @@ void Engine::run() // Run the Device with fps frames/sec while (m_Device->run() && m_RunEngine) { + if (this->m_EnableTestAndExit) { + std::cerr << "* running tests..." << std::endl; + this->m_EnableTestAndExit = false; + std::cerr << "* loading test model..." << std::endl; + if (!this->loadMesh(L"dist/share/b3view/meshes/penguin-lowpoly-poikilos.b3d")) { + throw "loading dist/share/b3view/meshes/penguin-lowpoly-poikilos.b3d failed."; + } + std::cerr << "* loading test model's next texture..." << std::endl; + if (!this->m_UserInterface->loadNextTexture(1)) { + throw "loading the next texture for dist/share/b3view/meshes/penguin-lowpoly-poikilos.b3d failed."; + } + this->m_RunEngine = false; + // Don't break yet. Test the main event loop tooo. + } u32 startTime = timer->getRealTime(); checkResize(); diff --git a/Engine.h b/Engine.h index d7c790a..342a09c 100644 --- a/Engine.h +++ b/Engine.h @@ -40,6 +40,7 @@ private: bool m_EnableWireframe; bool m_EnableLighting; bool m_EnableTextureInterpolation; + bool m_EnableTestAndExit; EventHandler* m_EventHandler; UserInterface* m_UserInterface; @@ -81,6 +82,7 @@ public: void run(); bool loadScene(const std::wstring& fileName); bool loadMesh(const std::wstring& fileName); + bool pushOption(const std::wstring& optionStr); bool reloadMesh(); std::wstring saveMesh(const irr::io::path path, const std::string& nameOrBlank, const std::string& extension); void reloadTexture(); diff --git a/UserInterface.cpp b/UserInterface.cpp index 9009605..40f7243 100644 --- a/UserInterface.cpp +++ b/UserInterface.cpp @@ -713,9 +713,9 @@ bool UserInterface::loadNextTexture(int direction) vector paths = this->m_MatchingTextures; if (this->m_MatchingTextures.size() < 1) { paths = this->m_AllTextures; - debug() << "There were no matching textures." - << " The entire list of " << this->m_AllTextures.size() - << " found textures will be used." << std::endl; + debug() << "There were no matching textures so" + << " the entire list of " << this->m_AllTextures.size() + << " found textures will be used..." << std::flush; } else { // Assume the user wants to view name-matched texture using @@ -763,25 +763,34 @@ bool UserInterface::loadNextTexture(int direction) } if (lastTexture.length() > 0) { if (direction < 0) { + cerr << "loading the previous texture..."; ret = this->m_Engine->loadTexture(prevTexture); } else if (direction > 0) { + cerr << "loading the next texture..."; ret = this->m_Engine->loadTexture(nextTexture); } else { // If direction is 0 (such as when a model is loaded that has - // no texture), only load a preloaded or matching texture. + // no texture), only load a specified or matching texture. if (this->m_Engine->m_LoadedTexturePath.length() > 0) { + cerr << "using a specified texture..."; ret = this->m_Engine->loadTexture( this->m_Engine->m_LoadedTexturePath ); } else if (this->m_MatchingTextures.size() >= 1) { + cerr << "loading matching texture..."; ret = this->m_Engine->loadTexture(firstTexture); } + else { + ret = true; + cerr << "(cycling was off and there is no matching texture) "; + } } } else if (this->m_Engine->m_LoadedTexturePath.length() > 0) { + cerr << "loading the first texture..."; ret = this->m_Engine->loadTexture( this->m_Engine->m_LoadedTexturePath ); diff --git a/build.sh b/build.sh index 201d761..a2cb77c 100755 --- a/build.sh +++ b/build.sh @@ -116,7 +116,7 @@ fi if [ "@$DEBUG" != "@true" ]; then if [ -f "$INSTALLED_BIN" ]; then echo "* updating $INSTALLED_BIN..." - ./$OUT_BIN --test-and-quit + ./$OUT_BIN --test-and-exit if [ $? -eq 0 ]; then # if no errors occur, install it rm "$INSTALLED_BIN" diff --git a/changelog.md b/changelog.md index 5950d65..f70fd0f 100644 --- a/changelog.md +++ b/changelog.md @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## [git] - 2021-03-28 +### Added +- a `--test-and-exit ` option ## [git] - 2021-02-22 ### Added diff --git a/main.cpp b/main.cpp index b395363..3bb9251 100644 --- a/main.cpp +++ b/main.cpp @@ -39,9 +39,16 @@ int main(int argc, char** argv) Engine* engine = new Engine(); if (argc >= 2) { - wchar_t* initialFileName = getWideCharString(argv[1]); - engine->loadMesh(wstring(initialFileName)); - free(initialFileName); + for (int i = 1; i < argc; i++) { + wchar_t* optionCS = getWideCharString(argv[1]); + if ((strlen(argv[i]) >=2) && (argv[i][0] == '-') && argv[i][1] == '-') { + engine->pushOption(wstring(optionCS)); + } + else { + engine->loadMesh(wstring(optionCS)); + } + free(optionCS); + } } //else // engine->loadMesh(L"test.b3d"); diff --git a/readme.md b/readme.md index 6b6e1d0..e214233 100644 --- a/readme.md +++ b/readme.md @@ -218,6 +218,8 @@ only applies to Visual Studio users.) * View, choose "Up" axis: change camera "up" axis to Z or Y (Y is default; automatically changed to Z when 3ds file is loaded) +### Command-line arguments +- `--test-and-exit`: This option is primarily for test scripts to run the program and see if it is working. It loads "dist/share/b3view/meshes/penguin-lowpoly-poikilos.b3d", loads the next texture, and (may perform other tests and) exits. It only works if the file exists such as if you are running from the repo directory. ## Known Issues * Warn on missing texture.