optimizing by removing useless loops

This commit is contained in:
Volodymyr Patuta 2020-12-31 18:18:08 +01:00
parent 4f75b647bf
commit c357e513b5
1 changed files with 24 additions and 28 deletions

View File

@ -142,9 +142,8 @@ void init(void) {
_sun = mkSphere(12, 12); /*ça fait 12x12x2 triangles !*/ _sun = mkSphere(12, 12); /*ça fait 12x12x2 triangles !*/
for(i = 0; i < 18; ++i) { for(i = 0; i < 18; ++i) {
_moon[i] = mkSphere(12, 12); _moon[i] = mkSphere(12, 12);
} if (i < 9)
for(i = 0; i < 9; ++i) { _planet[i] = mkSphere(12, 12);
_planet[i] = mkSphere(12, 12);
} }
// get all textures. // get all textures.
@ -181,30 +180,27 @@ void init(void) {
// set texture to an object id and set all options. // set texture to an object id and set all options.
setTexId(_sun, sun_id); setTexId(_sun, sun_id);
for(i = 0; i < 18; ++i) if(_use_tex)
setTexId(_moon[i], moon_id[i]);
for(i = 0; i < 9; ++i)
setTexId(_planet[i], id[i]);
if(_use_tex) {
enableSurfaceOption(_sun, SO_USE_TEXTURE); enableSurfaceOption(_sun, SO_USE_TEXTURE);
for(i = 0; i < 18; ++i) if(_use_lighting)
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) {
enableSurfaceOption(_sun, SO_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); 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); disableSurfaceOption(_moon[i], SO_USE_COLOR);
for(i = 0; i < 9; ++i) if(_use_tex)
disableSurfaceOption(_planet[i], SO_USE_COLOR); 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); atexit(sortie);
} }
@ -787,11 +783,11 @@ void sortie(void) {
freeSurface(_moon[i]); freeSurface(_moon[i]);
_moon[i] = NULL; _moon[i] = NULL;
} }
} if(i < 9) {
for(i = 0; i < 9; ++i) { if(_planet[i]){
if(_planet[i]){ freeSurface(_planet[i]);
freeSurface(_planet[i]); _planet[i] = NULL;
_planet[i] = NULL; }
} }
} }
if (bsound) if (bsound)