[Change] It's about time I optimised space_render.

This commit is contained in:
Allanis 2013-05-15 22:36:10 +01:00
parent 7b509e4e08
commit 1f5c05ac77

View File

@ -958,7 +958,7 @@ int space_load(void) {
void space_render(double dt) { void space_render(double dt) {
int i; int i;
unsigned int t, timer; unsigned int t, timer;
double x, y, m; double x, y, m, b;
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glPushMatrix(); // Translation matrix. glPushMatrix(); // Translation matrix.
@ -992,26 +992,30 @@ void space_render(double dt) {
glShadeModel(GL_FLAT); glShadeModel(GL_FLAT);
} else { } else {
glBegin(GL_POINTS); glBegin(GL_POINTS); // Normal rendering.
if(!paused && !player_isFlag(PLAYER_DESTROYED)) { // Update position.
for(i = 0; i < nstars; i++) { for(i = 0; i < nstars; i++) {
if(!paused && !toolkit) { b = 13.-10.*stars[i].brightness;
// Update position. stars[i].x -= player->solid->vel.x/b*dt;
if(!player_isFlag(PLAYER_DESTROYED)) { stars[i].y -= player->solid->vel.y/b*dt;
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; // Check for boundaries.
}
// Scroll those stars bitch!
if(stars[i].x > gl_screen.w + STAR_BUF) stars[i].x = -STAR_BUF; 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; 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; 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; 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. glPopMatrix(); // Translation matrix.
} }