X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=universe.cc;h=4a2e4f9e1189a8d4921c853a316d477a56686e8b;hb=e9a44449a4002827894a51cdbb9072d423cba765;hp=48d8efc288cd661a65b8264f32d377a9d160e0b0;hpb=3e51d77116e49ba279a6cbbf1dbbc893c4117eb4;p=universe.git diff --git a/universe.cc b/universe.cc index 48d8efc..4a2e4f9 100644 --- a/universe.cc +++ b/universe.cc @@ -7,18 +7,20 @@ #include "universe.h" Universe::Universe(int nb_max_polygons, - scalar_t xmax, scalar_t ymax) : _xmax(xmax), _ymax(ymax), - _nb_max_polygons(nb_max_polygons), _nb_polygons(0) { + scalar_t width, scalar_t height) : _width(width), + _height(height), + _nb_max_polygons(nb_max_polygons), + _nb_polygons(0) { _polygons = new Polygon *[_nb_max_polygons]; for(int n = 0; n < _nb_max_polygons; n++) _polygons[n] = 0; } Universe::~Universe() { - for(int n = 0; n < _nb_polygons; n++) if(_polygons[n]) delete _polygons[n]; + clear(); delete[] _polygons; } -void Universe::initialize(Polygon *p) { +void Universe::initialize_polygon(Polygon *p) { p->initialize(_nb_max_polygons); } @@ -104,7 +106,7 @@ bool Universe::update(scalar_t dt) { bool result = false; apply_collision_forces(dt); for(int n = 0; n < _nb_polygons; n++) if(_polygons[n]) { - _polygons[n]->apply_border_forces(dt, _xmax, _ymax); + _polygons[n]->apply_border_forces(dt, _width, _height); result |= _polygons[n]->update(dt); } return result; @@ -116,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]) { @@ -128,10 +131,36 @@ void Universe::print_xfig(XFigTracer *tracer) { } } } +#endif +#ifdef X11_SUPPORT void Universe::draw(SimpleWindow *window) { - for(int n = 0; n < _nb_polygons; n++) if(_polygons[n]) _polygons[n]->draw(window); - for(int n = 0; n < _nb_polygons; n++) if(_polygons[n]) _polygons[n]->draw_contours(window); + for(int n = 0; n < _nb_polygons; n++) { + if(_polygons[n]) { + _polygons[n]->draw(window); + } + } + + for(int n = 0; n < _nb_polygons; n++) { + if(_polygons[n]) { + _polygons[n]->draw_contours(window); + } + } +} +#endif + +void Universe::draw(Canvas *canvas) { + for(int n = 0; n < _nb_polygons; n++) { + if(_polygons[n]) { + _polygons[n]->draw(canvas); + } + } + + for(int n = 0; n < _nb_polygons; n++) { + if(_polygons[n]) { + _polygons[n]->draw_contours(canvas); + } + } } void Universe::apply_collision_forces(scalar_t dt) {