From c357e513b549203d3c06c7afa420d8cf3c99a610 Mon Sep 17 00:00:00 2001 From: Volodymyr Patuta Date: Thu, 31 Dec 2020 18:18:08 +0100 Subject: [PATCH] optimizing by removing useless loops --- window.c | 52 ++++++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/window.c b/window.c index e24231e..22c1877 100644 --- a/window.c +++ b/window.c @@ -142,9 +142,8 @@ void init(void) { _sun = mkSphere(12, 12); /*ça fait 12x12x2 triangles !*/ for(i = 0; i < 18; ++i) { _moon[i] = mkSphere(12, 12); - } - for(i = 0; i < 9; ++i) { - _planet[i] = mkSphere(12, 12); + if (i < 9) + _planet[i] = mkSphere(12, 12); } // get all textures. @@ -181,30 +180,27 @@ void init(void) { // set texture to an object id and set all options. setTexId(_sun, sun_id); - for(i = 0; i < 18; ++i) - setTexId(_moon[i], moon_id[i]); - for(i = 0; i < 9; ++i) - setTexId(_planet[i], id[i]); - if(_use_tex) { + if(_use_tex) enableSurfaceOption(_sun, SO_USE_TEXTURE); - for(i = 0; i < 18; ++i) - enableSurfaceOption(_moon[i], SO_USE_TEXTURE); - for(i = 0; i < 9; ++i) - enableSurfaceOption(_planet[i], SO_USE_TEXTURE); - } - /* si _use_lighting != 0, on active l'ombrage */ - if(_use_lighting) { + if(_use_lighting) enableSurfaceOption(_sun, SO_USE_LIGHTING); - for(i = 0; i < 18; ++i) - enableSurfaceOption(_moon[i], SO_USE_LIGHTING); - for(i = 0; i < 9; ++i) - enableSurfaceOption(_planet[i], SO_USE_LIGHTING); - } disableSurfaceOption(_sun, SO_USE_COLOR); - for(i = 0; i < 18; ++i) + for(i = 0; i < 18; ++i) { + setTexId(_moon[i], moon_id[i]); disableSurfaceOption(_moon[i], SO_USE_COLOR); - for(i = 0; i < 9; ++i) - disableSurfaceOption(_planet[i], SO_USE_COLOR); + if(_use_tex) + enableSurfaceOption(_moon[i], SO_USE_TEXTURE); + if(_use_lighting) + enableSurfaceOption(_moon[i], SO_USE_LIGHTING); + if (i < 9) { + setTexId(_planet[i], id[i]); + disableSurfaceOption(_planet[i], SO_USE_COLOR); + if(_use_tex) + enableSurfaceOption(_planet[i], SO_USE_TEXTURE); + if(_use_lighting) + enableSurfaceOption(_planet[i], SO_USE_LIGHTING); + } + } atexit(sortie); } @@ -787,11 +783,11 @@ void sortie(void) { freeSurface(_moon[i]); _moon[i] = NULL; } - } - for(i = 0; i < 9; ++i) { - if(_planet[i]){ - freeSurface(_planet[i]); - _planet[i] = NULL; + if(i < 9) { + if(_planet[i]){ + freeSurface(_planet[i]); + _planet[i] = NULL; + } } } if (bsound)