Restored progress display in CLI render
This commit is contained in:
parent
6f8e0c3cfd
commit
a4edc9568b
2 changed files with 56 additions and 24 deletions
|
@ -9,17 +9,48 @@
|
|||
#include "Scenery.h"
|
||||
#include "RenderConfig.h"
|
||||
#include "ColorProfile.h"
|
||||
#include "Thread.h"
|
||||
|
||||
void startRender(SoftwareCanvasRenderer *renderer, char *outputpath)
|
||||
class RenderThread: public Thread
|
||||
{
|
||||
public:
|
||||
RenderThread(SoftwareCanvasRenderer *renderer, char *outputpath):
|
||||
renderer(renderer), outputpath(outputpath)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void run() override
|
||||
{
|
||||
renderer->render();
|
||||
}
|
||||
|
||||
private:
|
||||
SoftwareCanvasRenderer *renderer;
|
||||
char *outputpath;
|
||||
};
|
||||
|
||||
static void startRender(SoftwareCanvasRenderer *renderer, char *outputpath)
|
||||
{
|
||||
RenderThread thread(renderer, outputpath);
|
||||
|
||||
printf("\rRendering %s ... \n", outputpath);
|
||||
renderer->render();
|
||||
thread.start();
|
||||
|
||||
while (thread.isWorking())
|
||||
{
|
||||
Thread::timeSleepMs(200);
|
||||
|
||||
printf("\rProgress : %0.1f%% ", renderer->getProgress() * 100.0);
|
||||
fflush(stdout);
|
||||
}
|
||||
thread.join();
|
||||
|
||||
printf("\rSaving %s ... \n", outputpath);
|
||||
remove(outputpath);
|
||||
renderer->saveToDisk(outputpath);
|
||||
}
|
||||
|
||||
void displayHelp()
|
||||
static void displayHelp()
|
||||
{
|
||||
printf("Usage : paysages-cli [options]\n");
|
||||
printf("Options :\n");
|
||||
|
@ -37,17 +68,11 @@ void displayHelp()
|
|||
printf(" -cz z Camera Z step (double)\n");
|
||||
}
|
||||
|
||||
void _previewUpdate(double progress)
|
||||
{
|
||||
printf("\rProgress : %0.1f%% ", progress * 100.0);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
SoftwareCanvasRenderer* renderer;
|
||||
char* conf_file_path = NULL;
|
||||
RenderConfig conf_render_params(800, 600, 1, 5);
|
||||
RenderConfig conf_render_params(400, 300, 1, 3);
|
||||
int conf_first_picture = 0;
|
||||
int conf_nb_pictures = 1;
|
||||
double conf_daytime_start = 0.4;
|
||||
|
@ -185,7 +210,7 @@ int main(int argc, char** argv)
|
|||
|
||||
if (outputcount >= conf_first_picture)
|
||||
{
|
||||
sprintf(outputpath, "output/pic%05d.png", outputcount);
|
||||
sprintf(outputpath, "pic%05d.png", outputcount);
|
||||
startRender(renderer, outputpath);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,37 +11,44 @@ namespace system
|
|||
|
||||
typedef void* (*ThreadFunction)(void* data);
|
||||
|
||||
/*!
|
||||
* \brief System thread
|
||||
/**
|
||||
* System thread
|
||||
*/
|
||||
class SYSTEMSHARED_EXPORT Thread: private QThread
|
||||
{
|
||||
public:
|
||||
/*!
|
||||
* \brief Create a new thread
|
||||
/**
|
||||
* Create a new thread.
|
||||
*
|
||||
* The thread is not started automatically. A call to method start() needs to be done.
|
||||
* \param function Function to call inside the thread once it is started
|
||||
*
|
||||
* Either the *function* argument should be provided (with the function to call from the
|
||||
* thread), or the *run* method overridden.
|
||||
*/
|
||||
Thread(ThreadFunction function=0);
|
||||
|
||||
/*!
|
||||
* \brief Start the thread
|
||||
* \param data User data to pass to the threaded function
|
||||
/**
|
||||
* Start the thread, with custom data.
|
||||
*/
|
||||
void start(void* data=0);
|
||||
|
||||
/*!
|
||||
* \brief Wait for the thread to end, and collect its result.
|
||||
* \return The value returned by the threaded function.
|
||||
/**
|
||||
* Wait for the thread to end, and collect its result.
|
||||
*
|
||||
* Returns the value returned by the threaded function.
|
||||
*/
|
||||
void* join();
|
||||
|
||||
/**
|
||||
* Return true if the thread is currently running.
|
||||
*/
|
||||
inline bool isWorking() const {return not isFinished();}
|
||||
|
||||
static inline void timeSleepMs(unsigned long ms){ QThread::msleep(ms); }
|
||||
|
||||
protected:
|
||||
/*!
|
||||
* \brief Function to reimplement if no ThreadFunction has been passed to the constructor.
|
||||
/**
|
||||
* Function to reimplement if no ThreadFunction has been passed to the constructor.
|
||||
*/
|
||||
virtual void run();
|
||||
|
||||
|
|
Loading…
Reference in a new issue