From 6408d9fe6e1b82ad9aa71d6e1702ec100a8c3ca1 Mon Sep 17 00:00:00 2001 From: Francois Fleuret Date: Fri, 9 Sep 2016 12:08:22 +0200 Subject: [PATCH] Update. --- Makefile | 9 ++++++++- generate.cc | 40 ++++++++++++++++++++++++++++++++++++++++ main.cc | 2 ++ polygon.cc | 2 ++ polygon.h | 4 ++++ universe.cc | 2 ++ universe.h | 2 ++ 7 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 generate.cc diff --git a/Makefile b/Makefile index b5eef5e..953f4ac 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ LDFLAGS += -lcairo TASK_SRC = dummy.cc move_square.cc hit_shape.cc TASK_OBJ = $(TASK_SRC:.cc=.so) -all: main TAGS $(TASK_OBJ) +all: main generate TAGS $(TASK_OBJ) TAGS: *.cc *.h etags *.cc *.h @@ -54,6 +54,13 @@ main: main.o misc.o \ intelligence.o $(CXX) $(CXXFLAGS) $(LDFLAGS) -lX11 -o $@ $^ +generate: generate.o misc.o \ + universe.o \ + plotter.o \ + polygon.o \ + canvas.o canvas_cairo.o + $(CXX) $(CXXFLAGS) $(LDFLAGS) -lX11 -o $@ $^ + %.so: %.cc misc.o universe.o polygon.o xfig_tracer.o map.o task.o manipulator.o $(CXX) $(CXXFLAGS) -shared -Wl,-soname,$@ -o $@ $^ diff --git a/generate.cc b/generate.cc new file mode 100644 index 0000000..e41fbe3 --- /dev/null +++ b/generate.cc @@ -0,0 +1,40 @@ + +//////////////////////////////////////////////////////////////////// +// START_IP_HEADER // +// // +// Written by Francois Fleuret // +// Contact for comments & bug reports // +// // +// END_IP_HEADER // +//////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +#include "misc.h" +#include "task.h" +#include "simple_window.h" +#include "universe.h" +#include "plotter.h" +#include "retina.h" +#include "manipulator.h" +#include "intelligence.h" +#include "canvas_cairo.h" + +void generate_png(Universe *universe, scalar_t scale, FILE *file) { + CanvasCairo canvas(scale, universe->width(), universe->height()); + universe->draw(&canvas); + canvas.write_png(file); +} + +int main(int argc, char **argv) { + +} diff --git a/main.cc b/main.cc index d3b3833..974cbea 100644 --- a/main.cc +++ b/main.cc @@ -428,10 +428,12 @@ int main(int argc, char **argv) { plotter.save_as_ppm(&universe, "/tmp/plotter.ppm", 16); } +#ifdef XFIG_SUPPORT { XFigTracer tracer("/tmp/universe.fig"); universe.print_xfig(&tracer); } +#endif #ifdef CAIRO_SUPPORT { diff --git a/polygon.cc b/polygon.cc index 4068919..9e55d80 100644 --- a/polygon.cc +++ b/polygon.cc @@ -47,6 +47,7 @@ Polygon *Polygon::clone() { return new Polygon(_mass, _red, _green, _blue, _relative_x, _relative_y, _nb_vertices); } +#ifdef XFIG_SUPPORT void Polygon::color_xfig(XFigTracer *tracer) { tracer->add_color(int(255 * _red), int(255 * _green), int(255 * _blue)); } @@ -55,6 +56,7 @@ void Polygon::print_xfig(XFigTracer *tracer) { tracer->draw_polygon(int(255 * _red), int(255 * _green), int(255 * _blue), _nb_vertices, _x, _y); } +#endif #ifdef X11_SUPPORT void Polygon::draw(SimpleWindow *window) { diff --git a/polygon.h b/polygon.h index 5a000be..e2d35f6 100644 --- a/polygon.h +++ b/polygon.h @@ -8,7 +8,9 @@ #include "misc.h" #include "canvas.h" +#ifdef XFIG_SUPPORT #include "xfig_tracer.h" +#endif #ifdef X11_SUPPORT #include "simple_window.h" @@ -71,8 +73,10 @@ public: Polygon *clone(); +#ifdef XFIG_SUPPORT void color_xfig(XFigTracer *tracer); void print_xfig(XFigTracer *tracer); +#endif #ifdef X11_SUPPORT void draw(SimpleWindow *window); diff --git a/universe.cc b/universe.cc index 55e1a6d..47d7c88 100644 --- a/universe.cc +++ b/universe.cc @@ -118,6 +118,7 @@ Polygon *Universe::pick_polygon(scalar_t x, scalar_t y) { return 0; } +#ifdef XFIG_SUPPORT void Universe::print_xfig(XFigTracer *tracer) { for(int n = 0; n < _nb_polygons; n++) { if(_polygons[n]) { @@ -130,6 +131,7 @@ void Universe::print_xfig(XFigTracer *tracer) { } } } +#endif #ifdef X11_SUPPORT void Universe::draw(SimpleWindow *window) { diff --git a/universe.h b/universe.h index b164d0b..a521f59 100644 --- a/universe.h +++ b/universe.h @@ -44,7 +44,9 @@ public: Polygon *pick_polygon(scalar_t x, scalar_t y); +#ifdef XFIG_SUPPORT void print_xfig(XFigTracer *tracer); +#endif #ifdef X11_SUPPORT void draw(SimpleWindow *window); -- 2.39.5