From 1f5c05ac77c6a977cb21eac8b1a161c21b46b44f Mon Sep 17 00:00:00 2001 From: Allanis Date: Wed, 15 May 2013 22:36:10 +0100 Subject: [PATCH] [Change] It's about time I optimised space_render. --- src/space.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/space.c b/src/space.c index 5fa3ba3..bcbdcca 100644 --- a/src/space.c +++ b/src/space.c @@ -958,7 +958,7 @@ int space_load(void) { void space_render(double dt) { int i; unsigned int t, timer; - double x, y, m; + double x, y, m, b; glMatrixMode(GL_MODELVIEW); glPushMatrix(); // Translation matrix. @@ -992,26 +992,30 @@ void space_render(double dt) { glShadeModel(GL_FLAT); } else { - glBegin(GL_POINTS); - - for(i = 0; i < nstars; i++) { - if(!paused && !toolkit) { - // Update position. - if(!player_isFlag(PLAYER_DESTROYED)) { - stars[i].x -= VX(player->solid->vel)/(13.-10.*stars[i].brightness)*dt; - stars[i].y -= VY(player->solid->vel)/(13.-10.*stars[i].brightness)*dt; - } - // Scroll those stars bitch! + glBegin(GL_POINTS); // Normal rendering. + if(!paused && !player_isFlag(PLAYER_DESTROYED)) { // Update position. + for(i = 0; i < nstars; i++) { + b = 13.-10.*stars[i].brightness; + stars[i].x -= player->solid->vel.x/b*dt; + stars[i].y -= player->solid->vel.y/b*dt; + + // Check for boundaries. if(stars[i].x > gl_screen.w + STAR_BUF) stars[i].x = -STAR_BUF; else if(stars[i].x < -STAR_BUF) stars[i].x = gl_screen.w + STAR_BUF; if(stars[i].y > gl_screen.h + STAR_BUF) stars[i].y = -STAR_BUF; else if(stars[i].y < -STAR_BUF) stars[i].y = gl_screen.h + STAR_BUF; + + // Render. + glColor4d(1., 1., 1., stars[i].brightness); + glVertex2d(stars[i].x, stars[i].y); + } + } else { // Just render. + for(i = 0; i < nstars; i++) { + glColor4d(1., 1., 1., stars[i].brightness); + glVertex2d(stars[i].x, stars[i].y); } - // Render. - glColor4d(1., 1., 1., stars[i].brightness); - glVertex2d(stars[i].x, stars[i].y); } - glEnd(); + glEnd(); // GL_POINTS } glPopMatrix(); // Translation matrix. }