Add a --test-and-exit option.

master
poikilos 2021-03-28 06:08:53 -04:00
parent 9b40a9b32a
commit b91fe123b5
7 changed files with 59 additions and 8 deletions

View File

@ -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();

View File

@ -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();

View File

@ -713,9 +713,9 @@ bool UserInterface::loadNextTexture(int direction)
vector<wstring> 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
);

View File

@ -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"

View File

@ -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

View File

@ -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");

View File

@ -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.