diff options
author | Tavian Barnes <tavianator@gmail.com> | 2009-11-20 16:23:49 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2009-11-20 16:23:49 -0500 |
commit | 68bf4e11ac1e4f2866a1948406762931d5fd7e9a (patch) | |
tree | 31203a6b12b476ec6686fa375ac39737a529ebde | |
parent | cb7c2622f6771292b7345a17bb69520a75de27a8 (diff) | |
download | dimension-68bf4e11ac1e4f2866a1948406762931d5fd7e9a.tar.xz |
Make `dimension' output some things as it works.
-rw-r--r-- | dimension/Makefile.am | 2 | ||||
-rw-r--r-- | dimension/main.c | 27 | ||||
-rw-r--r-- | dimension/parse.h | 5 | ||||
-rw-r--r-- | dimension/progressbar.c | 39 | ||||
-rw-r--r-- | dimension/progressbar.h | 28 | ||||
-rw-r--r-- | dimension/realize.h | 5 | ||||
-rw-r--r-- | dimension/tokenize.h | 5 |
7 files changed, 109 insertions, 2 deletions
diff --git a/dimension/Makefile.am b/dimension/Makefile.am index 5445c80..421681f 100644 --- a/dimension/Makefile.am +++ b/dimension/Makefile.am @@ -24,6 +24,8 @@ bin_PROGRAMS = dimension dimension_SOURCES = main.c \ parse.c \ parse.h \ + progressbar.c \ + progressbar.h \ realize.c \ realize.h \ tokenize.c \ diff --git a/dimension/main.c b/dimension/main.c index 9f2ab3f..3f1c807 100644 --- a/dimension/main.c +++ b/dimension/main.c @@ -20,6 +20,7 @@ #include "tokenize.h" #include "parse.h" #include "realize.h" +#include "progressbar.h" #include "../libdimension/dimension.h" #include <stdlib.h> #include <getopt.h> @@ -101,6 +102,7 @@ main(int argc, char **argv) { } /* Tokenize the input file */ + printf("Tokenizing input...\n"); dmnsn_array *tokens = dmnsn_tokenize(input, input_file); if (!tokens) { fclose(input_file); @@ -119,6 +121,7 @@ main(int argc, char **argv) { } /* Parse the input */ + printf("Parsing input...\n"); dmnsn_array *astree = dmnsn_parse(tokens); if (!astree) { dmnsn_delete_tokens(tokens); @@ -134,6 +137,7 @@ main(int argc, char **argv) { } /* Realize the input */ + printf("Generating scene...\n"); dmnsn_scene *scene = dmnsn_realize(astree); if (!scene) { dmnsn_delete_astree(astree); @@ -149,7 +153,15 @@ main(int argc, char **argv) { fprintf(stderr, "WARNING: Couldn't optimize canvas for PNG\n"); } - if (dmnsn_raytrace_scene(scene) != 0) { + dmnsn_progress *render_progress = dmnsn_raytrace_scene_async(scene); + if (!render_progress) { + dmnsn_delete_scene(scene); + dmnsn_error(DMNSN_SEVERITY_HIGH, "Error starting render."); + } + + dmnsn_progressbar("Rendering scene: ", render_progress); + + if (dmnsn_finish_progress(render_progress) != 0) { dmnsn_delete_scene(scene); dmnsn_error(DMNSN_SEVERITY_HIGH, "Error rendering scene."); } @@ -160,8 +172,19 @@ main(int argc, char **argv) { dmnsn_error(DMNSN_SEVERITY_HIGH, "Couldn't open output file."); } - if (dmnsn_png_write_canvas(scene->canvas, output_file) != 0) { + dmnsn_progress *output_progress + = dmnsn_png_write_canvas_async(scene->canvas, output_file); + if (!output_progress) { + fclose(output_file); + dmnsn_delete_scene(scene); + dmnsn_error(DMNSN_SEVERITY_HIGH, "Couldn't initialize PNG export."); + } + + dmnsn_progressbar("Writing PNG: ", output_progress); + + if (dmnsn_finish_progress(output_progress) != 0) { fclose(output_file); + dmnsn_delete_scene(scene); dmnsn_error(DMNSN_SEVERITY_HIGH, "Couldn't write output."); } fclose(output_file); diff --git a/dimension/parse.h b/dimension/parse.h index 2dd31be..b55588b 100644 --- a/dimension/parse.h +++ b/dimension/parse.h @@ -17,6 +17,9 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * *************************************************************************/ +#ifndef PARSE_H +#define PARSE_H + #include "../libdimension/dimension.h" typedef enum { @@ -59,3 +62,5 @@ void dmnsn_print_astree_sexpr(FILE *file, const dmnsn_array *astree); /* Returns a readable name for a token type (ex. DMNSN_T_FLOAT -> float) */ const char *dmnsn_astnode_string(dmnsn_astnode_type astnode_type); + +#endif /* PARSE_H */ diff --git a/dimension/progressbar.c b/dimension/progressbar.c new file mode 100644 index 0000000..ac5f899 --- /dev/null +++ b/dimension/progressbar.c @@ -0,0 +1,39 @@ +/************************************************************************* + * Copyright (C) 2009 Tavian Barnes <tavianator@gmail.com> * + * * + * This file is part of Dimension. * + * * + * Dimension is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the * + * Free Software Foundation; either version 3 of the License, or (at * + * your option) any later version. * + * * + * Dimension is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + *************************************************************************/ + +#include "progressbar.h" +#include <stdio.h> + +void +dmnsn_progressbar(const char *str, const dmnsn_progress *progress) +{ + const unsigned int increments = 32; + unsigned int i; + + printf("%s|", str); + fflush(stdout); + for (i = 0; i < increments; ++i) { + dmnsn_wait_progress(progress, ((double)(i + 1))/increments); + + printf("="); + fflush(stdout); + } + printf("|\n"); + fflush(stdout); +} diff --git a/dimension/progressbar.h b/dimension/progressbar.h new file mode 100644 index 0000000..0bf14e1 --- /dev/null +++ b/dimension/progressbar.h @@ -0,0 +1,28 @@ +/************************************************************************* + * Copyright (C) 2009 Tavian Barnes <tavianator@gmail.com> * + * * + * This file is part of Dimension. * + * * + * Dimension is free software; you can redistribute it and/or modify it * + * under the terms of the GNU General Public License as published by the * + * Free Software Foundation; either version 3 of the License, or (at * + * your option) any later version. * + * * + * Dimension is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + *************************************************************************/ + +#ifndef PROGRESSBAR_H +#define PROGRESSBAR_H + +#include "../libdimension/dimension.h" + +/* Print a progress bar of the progress of `progress' */ +void dmnsn_progressbar(const char *str, const dmnsn_progress *progress); + +#endif /* PROGRESSBAR_H */ diff --git a/dimension/realize.h b/dimension/realize.h index d6c7d51..d6f2539 100644 --- a/dimension/realize.h +++ b/dimension/realize.h @@ -17,6 +17,11 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * *************************************************************************/ +#ifndef REALIZE_H +#define REALIZE_H + #include "../libdimension/dimension.h" dmnsn_scene *dmnsn_realize(const dmnsn_array *astree); + +#endif /* REALIZE_H */ diff --git a/dimension/tokenize.h b/dimension/tokenize.h index 4eb1109..98a9c2f 100644 --- a/dimension/tokenize.h +++ b/dimension/tokenize.h @@ -17,6 +17,9 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * *************************************************************************/ +#ifndef TOKENIZE_H +#define TOKENIZE_H + #include "../libdimension/dimension.h" typedef enum { @@ -536,3 +539,5 @@ void dmnsn_print_token_sexpr(FILE *file, const dmnsn_array *tokens); /* Returns a readable name for a token type (ex. DMNSN_T_FLOAT -> float) */ const char *dmnsn_token_string(dmnsn_token_type token_type); + +#endif /* TOKENIZE_H */ |