[Fix] Changing from floating point to doubles.

This commit is contained in:
Allanis 2013-02-02 14:21:05 +00:00
parent 978df483bf
commit b5a7ba8919
13 changed files with 124 additions and 92 deletions

View File

@ -6,7 +6,5 @@
#define ABS(X) ((X<0)?-X:X) #define ABS(X) ((X<0)?-X:X)
#define FABS(X) ((X<0.)?-X:X) #define FABS(X) ((X<0.)?-X:X)
typedef float FP;
#define DATA "data" #define DATA "data"

View File

@ -172,7 +172,7 @@ int main(int argc, char** argv) {
// -- Think (ai). // -- Think (ai).
// -- Solid. // -- Solid.
static void update_all(void) { static void update_all(void) {
FP dt = (FP)(SDL_GetTicks() - time) / 1000.0; double dt = (double)(SDL_GetTicks() - time) / 1000.0;
time = SDL_GetTicks(); time = SDL_GetTicks();
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);

View File

@ -162,15 +162,15 @@ gl_texture* gl_loadImage(SDL_Surface* surface) {
// Set up the texture defaults. // Set up the texture defaults.
gl_texture* texture = MALLOC_L(gl_texture); gl_texture* texture = MALLOC_L(gl_texture);
texture->w = (FP)surface->w; texture->w = (double)surface->w;
texture->h = (FP)surface->h; texture->h = (double)surface->h;
texture->sx = 1.; texture->sx = 1.;
texture->sy = 1.; texture->sy = 1.;
texture->texture = gl_loadSurface(surface, &rw, &rh); texture->texture = gl_loadSurface(surface, &rw, &rh);
texture->rw = (FP)rw; texture->rw = (double)rw;
texture->rh = (FP)rh; texture->rh = (double)rh;
texture->sw = texture->w; texture->sw = texture->w;
texture->sh = texture->h; texture->sh = texture->h;
@ -207,8 +207,8 @@ gl_texture* gl_newSprite(const char* path, const int sx, const int sy) {
gl_texture* texture; gl_texture* texture;
if((texture = gl_newImage(path)) == NULL) if((texture = gl_newImage(path)) == NULL)
return NULL; return NULL;
texture->sx = (FP)sx; texture->sx = (double)sx;
texture->sy = (FP)sy; texture->sy = (double)sy;
texture->sw = texture->w/texture->sx; texture->sw = texture->w/texture->sx;
texture->sh = texture->h/texture->sy; texture->sh = texture->h/texture->sy;
return texture; return texture;
@ -232,26 +232,27 @@ void gl_blitSprite(const gl_texture* sprite, const Vec2* pos, const int sx, cons
return; return;
glMatrixMode(GL_TEXTURE); glMatrixMode(GL_TEXTURE);
glPushMatrix(); glPushMatrix();
glTranslatef(sprite->sw * (FP)(sx)/sprite->rw, glTranslated(sprite->sw * (double)(sx)/sprite->rw,
sprite->sh*(sprite->sy-(FP)sy-1)/sprite->rh, 0.); sprite->sh*(sprite->sy-(double)sy-1)/sprite->rh, 0.);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glPushMatrix(); // Projection translation matrix. glPushMatrix(); // Projection translation matrix.
glTranslatef(pos->x - gl_camera->x - sprite->sw/2., glTranslated(pos->x - gl_camera->x - sprite->sw/2.,
pos->y - gl_camera->y - sprite->sh/2., 0.); pos->y - gl_camera->y - sprite->sh/2., 0.);
glScalef((FP)gl_screen.w/SCREEN_W, (FP)gl_screen.h/SCREEN_H, 0.); glScalef((double)gl_screen.w/SCREEN_W, (double)gl_screen.h/SCREEN_H, 0.);
// Actual blitting.... // Actual blitting....
glBindTexture(GL_TEXTURE_2D, sprite->texture); glBindTexture(GL_TEXTURE_2D, sprite->texture);
glColor4ub(255, 255, 255, 255);
glBegin(GL_TRIANGLE_STRIP); glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(0., 0.); glTexCoord2d(0., 0.);
glVertex2f(0., 0.); glVertex2d(0., 0.);
glTexCoord2f(sprite->sw/sprite->rw, 0.); glTexCoord2d(sprite->sw/sprite->rw, 0.);
glVertex2f(sprite->sw, 0.); glVertex2d(sprite->sw, 0.);
glTexCoord2f(0., sprite->sh/sprite->rh); glTexCoord2d(0., sprite->sh/sprite->rh);
glVertex2f(0., sprite->sh); glVertex2d(0., sprite->sh);
glTexCoord2f(sprite->sw/sprite->rw, sprite->sh/sprite->rh); glTexCoord2d(sprite->sw/sprite->rw, sprite->sh/sprite->rh);
glVertex2f(sprite->sw, sprite->sh); glVertex2d(sprite->sw, sprite->sh);
glEnd(); glEnd();
glPopMatrix(); // Projection translation matrix. glPopMatrix(); // Projection translation matrix.
@ -264,20 +265,21 @@ void gl_blitSprite(const gl_texture* sprite, const Vec2* pos, const int sx, cons
void gl_blitStatic(const gl_texture* texture, const Vec2* pos) { void gl_blitStatic(const gl_texture* texture, const Vec2* pos) {
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glPushMatrix(); // Set up translation matrix. glPushMatrix(); // Set up translation matrix.
glTranslatef(pos->x - (FP)gl_screen.w/2., pos->y - (FP)gl_screen.h/2., 0); glTranslated(pos->x - (double)gl_screen.w/2., pos->y - (double)gl_screen.h/2., 0);
glScalef((FP)gl_screen.w/SCREEN_W, (FP)gl_screen.h/SCREEN_H, 0.); glScaled((double)gl_screen.w/SCREEN_W, (double)gl_screen.h/SCREEN_H, 0.);
// Actual blitting.. // Actual blitting..
glBindTexture(GL_TEXTURE_2D, texture->texture); glBindTexture(GL_TEXTURE_2D, texture->texture);
glColor4ub(255, 255, 255, 255);
glBegin(GL_TRIANGLE_STRIP); glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(0., 0.); glTexCoord2d(0., 0.);
glVertex2f(0., 0.); glVertex2d(0., 0.);
glTexCoord2f(texture->w/texture->rw, 0.); glTexCoord2d(texture->w/texture->rw, 0.);
glVertex2f(texture->w, 0.); glVertex2d(texture->w, 0.);
glTexCoord2f(0., texture->h/texture->rh); glTexCoord2d(0., texture->h/texture->rh);
glVertex2f(0., texture->h); glVertex2d(0., texture->h);
glTexCoord2f(texture->w/texture->rw, texture->h/texture->rh); glTexCoord2d(texture->w/texture->rw, texture->h/texture->rh);
glVertex2f(texture->w, texture->h); glVertex2d(texture->w, texture->h);
glEnd(); glEnd();
glPopMatrix(); // Pop the translation matrix. glPopMatrix(); // Pop the translation matrix.
@ -309,7 +311,8 @@ void gl_print(const gl_font* ft_font, Vec2* pos, const char* fmt, ...) {
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
//for(i = 0; i < strlen(text); i++) { //for(i = 0; i < strlen(text); i++) {
glPushMatrix(); glPushMatrix();
glTranslatef(pos->x - (FP)gl_screen.w/2., pos->y - (FP)gl_screen.h/2., 0); glTranslated(pos->x - (double)gl_screen.w/2., pos->y - (double)gl_screen.h/2., 0);
glColor4ub(255, 255, 255, 255);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, &text); glCallLists(strlen(text), GL_UNSIGNED_BYTE, &text);
glPopMatrix(); glPopMatrix();
//} //}
@ -366,29 +369,29 @@ static void gl_fontMakeDList(FT_Face face, char ch, GLuint list_base, GLuint* te
glPushMatrix(); glPushMatrix();
// Corrects a spacing flaw between letters. // Corrects a spacing flaw between letters.
glTranslatef(bitmap_glyph->left, 0,0); glTranslated(bitmap_glyph->left, 0,0);
// Downwards correction for letters like g or y. // Downwards correction for letters like g or y.
glTranslatef(0, bitmap_glyph->top-bitmap.rows,0); glTranslated(0, bitmap_glyph->top-bitmap.rows,0);
// Take the opengl POT wrapping into account. // Take the opengl POT wrapping into account.
FP x = (FP)bitmap.width/(FP)w; double x = (double)bitmap.width/(double)w;
FP y = (FP)bitmap.rows/(FP)h; double y = (double)bitmap.rows/(double)h;
// Draw the texture mapped quad. // Draw the texture mapped quad.
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2d(0, 0); glTexCoord2d(0, 0);
glVertex2f(0, bitmap.rows); glVertex2d(0, bitmap.rows);
glTexCoord2d(0, y); glTexCoord2d(0, y);
glVertex2f(0, 0); glVertex2d(0, 0);
glTexCoord2d(x, y); glTexCoord2d(x, y);
glVertex2f(bitmap.width, 0); glVertex2d(bitmap.width, 0);
glTexCoord2d(x, 0); glTexCoord2d(x, 0);
glVertex2f(bitmap.width, bitmap.rows); glVertex2d(bitmap.width, bitmap.rows);
glEnd(); glEnd();
glPopMatrix(); glPopMatrix();
glTranslatef(face->glyph->advance.x >> 6, 0,0); glTranslated(face->glyph->advance.x >> 6, 0,0);
// End of the display list. // End of the display list.
glEndList(); glEndList();

View File

@ -32,10 +32,10 @@ extern gl_info gl_screen; // Local structure set with gl_init etc.
// Spritesheet info. // Spritesheet info.
typedef struct { typedef struct {
FP w, h; // Real size of the image (excluding POT buffer. double w, h; // Real size of the image (excluding POT buffer.
FP rw, rh; // Size of POT surface. double rw, rh; // Size of POT surface.
FP sx, sy; // Number of sprites on x and y axes. double sx, sy; // Number of sprites on x and y axes.
FP sw, sh; // Size of each sprite. double sw, sh; // Size of each sprite.
GLuint texture; // The opengl texture itself. GLuint texture; // The opengl texture itself.
} gl_texture; } gl_texture;

View File

@ -23,7 +23,7 @@
// error, so watch out with big values for dt. // error, so watch out with big values for dt.
// ======================================================== // ========================================================
#if 0 #if 0
static void simple_update(Solid* obj, const FP dt) { static void simple_update(Solid* obj, const double dt) {
// Make sure angle doesn't flip. // Make sure angle doesn't flip.
obj->dir += obj->dir_vel/360.0*dt; obj->dir += obj->dir_vel/360.0*dt;
if(obj->dir > 2*M_PI) obj->dir -= 2*M_PI; if(obj->dir > 2*M_PI) obj->dir -= 2*M_PI;
@ -61,13 +61,13 @@ static void simple_update(Solid* obj, const FP dt) {
// ======================================================== // ========================================================
#define RK4_N 4 #define RK4_N 4
static void rk4_update(Solid* obj, const FP dt) { static void rk4_update(Solid* obj, const double dt) {
// Make sure angle doesn't flip. // Make sure angle doesn't flip.
obj->dir += obj->dir_vel/360.0*dt; obj->dir += obj->dir_vel/360.0*dt;
if(obj->dir > 2*M_PI) obj->dir -= 2*M_PI; if(obj->dir > 2*M_PI) obj->dir -= 2*M_PI;
if(obj->dir < 0.0) obj->dir += 2*M_PI; if(obj->dir < 0.0) obj->dir += 2*M_PI;
FP h = dt / RK4_N; // Step. double h = dt / RK4_N; // Step.
if(obj->force) { // Force applied on object. if(obj->force) { // Force applied on object.
int i; int i;
@ -105,7 +105,7 @@ static void rk4_update(Solid* obj, const FP dt) {
} }
// Initialize a new solid. // Initialize a new solid.
void solid_init(Solid* dest, const FP mass, const Vec2* vel, const Vec2* pos) { void solid_init(Solid* dest, const double mass, const Vec2* vel, const Vec2* pos) {
dest->mass = mass; dest->mass = mass;
dest->force = 0; dest->force = 0;
@ -129,7 +129,7 @@ void solid_init(Solid* dest, const FP mass, const Vec2* vel, const Vec2* pos) {
} }
// Create a new solid. // Create a new solid.
Solid* solid_create(const FP mass, const Vec2* vel, const Vec2* pos) { Solid* solid_create(const double mass, const Vec2* vel, const Vec2* pos) {
Solid* dyn = MALLOC_L(Solid); Solid* dyn = MALLOC_L(Solid);
assert(dyn != NULL); assert(dyn != NULL);
solid_init(dyn, mass, vel, pos); solid_init(dyn, mass, vel, pos);

View File

@ -3,19 +3,19 @@
// Base of 2D vectors. // Base of 2D vectors.
typedef struct { typedef struct {
FP x, y; // Basic 2D vector components. double x, y; // Basic 2D vector components.
} Vec2; } Vec2;
// Describe any solid in 2D space. // Describe any solid in 2D space.
struct Solid { struct Solid {
FP mass, force, dir, dir_vel; // Properties. double mass, force, dir, dir_vel; // Properties.
Vec2 vel, pos; // Position/velocity vectors. Vec2 vel, pos; // Position/velocity vectors.
void(*update)(struct Solid*, const FP); // Update method. void(*update)(struct Solid*, const double); // Update method.
}; };
typedef struct Solid Solid; typedef struct Solid Solid;
void solid_init(Solid* dest, const FP mass, const Vec2* vel, const Vec2* pos); void solid_init(Solid* dest, const double mass, const Vec2* vel, const Vec2* pos);
Solid* solid_create(const FP mass, const Vec2* vel, const Vec2* pos); Solid* solid_create(const double mass, const Vec2* vel, const Vec2* pos);
void solid_free(Solid* src); void solid_free(Solid* src);

View File

@ -14,9 +14,9 @@ static unsigned int pilot_id = 0;
static Pilot** pilot_stack; static Pilot** pilot_stack;
static int pilots = 0; static int pilots = 0;
extern void player_think(Pilot* pilot, const FP dt); // Player.c extern void player_think(Pilot* pilot, const double dt); // Player.c
extern void ai_think(Pilot* pilot); // Ai.c extern void ai_think(Pilot* pilot); // Ai.c
static void pilot_update(Pilot* pilot, const FP dt); static void pilot_update(Pilot* pilot, const double dt);
static void pilot_render(Pilot* pilot); static void pilot_render(Pilot* pilot);
// Pull a pilot out of the pilot_stack based on id. // Pull a pilot out of the pilot_stack based on id.
@ -47,7 +47,7 @@ static void pilot_render(Pilot* pilot) {
} }
// Update the pilot. // Update the pilot.
static void pilot_update(Pilot* pilot, const FP dt) { static void pilot_update(Pilot* pilot, const double dt) {
if(pilot->solid->dir > 2*M_PI) pilot->solid->dir -= 2*M_PI; if(pilot->solid->dir > 2*M_PI) pilot->solid->dir -= 2*M_PI;
if(pilot->solid->dir < 0.0) pilot->solid->dir += 2*M_PI; if(pilot->solid->dir < 0.0) pilot->solid->dir += 2*M_PI;
@ -118,7 +118,7 @@ void pilots_free(void) {
} }
// Update all pilots. // Update all pilots.
void pilots_update(FP dt) { void pilots_update(double dt) {
int i; int i;
for(i = pilots-1; i >= 0; i--) { for(i = pilots-1; i >= 0; i--) {
if(pilot_stack[i]->think != NULL) if(pilot_stack[i]->think != NULL)

View File

@ -30,9 +30,9 @@ struct Pilot {
Solid* solid; // Associated solid (physics). Solid* solid; // Associated solid (physics).
// Current health. // Current health.
FP armor, shield, energy; double armor, shield, energy;
void (*update)(struct Pilot*, const FP); // Update the pilot. void (*update)(struct Pilot*, const double); // Update the pilot.
unsigned int properties; // Used for AI etc. unsigned int properties; // Used for AI etc.
@ -56,5 +56,5 @@ unsigned int pilot_create(Ship* ship, char* name, const Vec2* vel,
void pilots_free(void); void pilots_free(void);
// Update. // Update.
void pilots_update(FP dt); void pilots_update(double dt);

View File

@ -6,14 +6,14 @@
Pilot* player = NULL; Pilot* player = NULL;
static unsigned int player_flags = PLAYER_FLAG_NULL; static unsigned int player_flags = PLAYER_FLAG_NULL;
static FP player_turn = 0.; static double player_turn = 0.;
static FP player_acc = 0.; static double player_acc = 0.;
// To be used in pilot.c // To be used in pilot.c
void player_think(Pilot* player, const FP dt) { void player_think(Pilot* player, const double dt) {
player->solid->dir_vel = 0.; player->solid->dir_vel = 0.;
if(player_turn) if(player_turn)
player->solid->dir_vel -= player->ship->turn*player_turn/(FP)(1<<15); player->solid->dir_vel -= player->ship->turn*player_turn/(double)(1<<15);
#if 0 #if 0
if(player_isFlag(PLAYER_FLAG_MOV_LEFT)) if(player_isFlag(PLAYER_FLAG_MOV_LEFT))
player->solid->dir_vel += player->ship->turn; player->solid->dir_vel += player->ship->turn;
@ -21,7 +21,7 @@ void player_think(Pilot* player, const FP dt) {
player->solid->dir_vel -= player->ship->turn; player->solid->dir_vel -= player->ship->turn;
#endif #endif
player->solid->force = player->ship->thrust*player_acc/(FP)(1<<15); player->solid->force = player->ship->thrust*player_acc/(double)(1<<15);
} }
// Flag manipulationz. // Flag manipulationz.
@ -45,11 +45,11 @@ void player_rmFlag(unsigned int flag) {
static void handle_joyaxis(int axis, int value) { static void handle_joyaxis(int axis, int value) {
switch(axis) { switch(axis) {
case 0: case 0:
player_turn = (FP)value; player_turn = (double)value;
break; break;
case 1: case 1:
if(value <= 0) if(value <= 0)
player_acc = (FP)-value; player_acc = (double)-value;
break; break;
} }
} }
@ -57,7 +57,7 @@ static void handle_joyaxis(int axis, int value) {
static void handle_joydown(int button) { static void handle_joydown(int button) {
switch(button) { switch(button) {
case 0: case 0:
player_acc += (FP)(1<<15); player_acc += (double)(1<<15);
break; break;
case 1: case 1:
break; break;
@ -67,7 +67,7 @@ static void handle_joydown(int button) {
static void handle_joyup(int button) { static void handle_joyup(int button) {
switch(button) { switch(button) {
case 0: case 0:
player_acc -=(FP)(1<<15); player_acc -=(double)(1<<15);
break; break;
case 1: case 1:
break; break;
@ -84,15 +84,15 @@ static void handle_keydown(SDLKey key) {
break; break;
case SDLK_LEFT: case SDLK_LEFT:
case SDLK_a: case SDLK_a:
player_turn -= (FP)(1<<15); player_turn -= (double)(1<<15);
break; break;
case SDLK_RIGHT: case SDLK_RIGHT:
case SDLK_d: case SDLK_d:
player_turn += (FP)(1<<15); player_turn += (double)(1<<15);
break; break;
case SDLK_UP: case SDLK_UP:
case SDLK_w: case SDLK_w:
player_acc += (FP)(1<<15); player_acc += (double)(1<<15);
break; break;
default: default:
break; break;
@ -103,15 +103,15 @@ static void handle_keyup(SDLKey key) {
switch(key) { switch(key) {
case SDLK_LEFT: case SDLK_LEFT:
case SDLK_a: case SDLK_a:
player_turn += (FP)(1<<15); player_turn += (double)(1<<15);
break; break;
case SDLK_RIGHT: case SDLK_RIGHT:
case SDLK_d: case SDLK_d:
player_turn -= (FP)(1<<15); player_turn -= (double)(1<<15);
break; break;
case SDLK_UP: case SDLK_UP:
case SDLK_w: case SDLK_w:
player_acc -= (FP)(1<<15); player_acc -= (double)(1<<15);
//break; //break;
default: default:
break; break;

View File

@ -69,17 +69,17 @@ Ship* ship_parse(xmlNodePtr node) {
cur = node->children; cur = node->children;
while((cur = cur->next)) { while((cur = cur->next)) {
if(strcmp((char*)cur->name, "armor")==0) if(strcmp((char*)cur->name, "armor")==0)
tmp->armor = (FP)atoi((char*)cur->children->content); tmp->armor = (double)atoi((char*)cur->children->content);
else if(strcmp((char*)cur->name, "shield")==0) else if(strcmp((char*)cur->name, "shield")==0)
tmp->shield = (FP)atoi((char*)cur->children->content); tmp->shield = (double)atoi((char*)cur->children->content);
else if(strcmp((char*)cur->name, "energy")==0) else if(strcmp((char*)cur->name, "energy")==0)
tmp->energy = (FP)atoi((char*)cur->children->content); tmp->energy = (double)atoi((char*)cur->children->content);
else if(strcmp((char*)cur->name, "armor_regen")==0) else if(strcmp((char*)cur->name, "armor_regen")==0)
tmp->armor_regen = (FP)(atoi((char*)cur->children->content))/60.0; tmp->armor_regen = (double)(atoi((char*)cur->children->content))/60.0;
else if(strcmp((char*)cur->name, "shield_regen")==0) else if(strcmp((char*)cur->name, "shield_regen")==0)
tmp->shield_regen = (FP)(atoi((char*)cur->children->content))/60.0; tmp->shield_regen = (double)(atoi((char*)cur->children->content))/60.0;
else if(strcmp((char*)cur->name, "energy_regen")==0) else if(strcmp((char*)cur->name, "energy_regen")==0)
tmp->energy_regen = (FP)(atoi((char*)cur->children->content))/60.0; tmp->energy_regen = (double)(atoi((char*)cur->children->content))/60.0;
} }
} }
else if(strcmp((char*)node->name, "characteristics")==0) { else if(strcmp((char*)node->name, "characteristics")==0) {
@ -88,7 +88,7 @@ Ship* ship_parse(xmlNodePtr node) {
if(strcmp((char*)cur->name, "crew")==0) if(strcmp((char*)cur->name, "crew")==0)
tmp->crew = atoi((char*)cur->children->content); tmp->crew = atoi((char*)cur->children->content);
else if(strcmp((char*)cur->name, "mass")==0) else if(strcmp((char*)cur->name, "mass")==0)
tmp->mass = (FP)atoi((char*)cur->children->content); tmp->mass = (double)atoi((char*)cur->children->content);
else if(strcmp((char*)cur->name, "cap_weapon")==0) else if(strcmp((char*)cur->name, "cap_weapon")==0)
tmp->cap_weapon = atoi((char*)cur->children->content); tmp->cap_weapon = atoi((char*)cur->children->content);
else if(strcmp((char*)cur->name, "cap_cargo")==0) else if(strcmp((char*)cur->name, "cap_cargo")==0)

View File

@ -10,7 +10,7 @@ typedef struct {
ship_class class; // Ship class. ship_class class; // Ship class.
// Movement. // Movement.
FP thrust, turn, speed; double thrust, turn, speed;
// Graphics. // Graphics.
gl_texture* gfx_ship, *gfx_target; gl_texture* gfx_ship, *gfx_target;
@ -20,9 +20,9 @@ typedef struct {
int mass; int mass;
// Health. // Health.
FP armor, armor_regen; double armor, armor_regen;
FP shield, shield_regen; double shield, shield_regen;
FP energy, energy_regen; double energy, energy_regen;
// Capacity. // Capacity.
int cap_cargo, cap_weapon; int cap_cargo, cap_weapon;

View File

@ -5,11 +5,20 @@
#include "pilot.h" #include "pilot.h"
#include "space.h" #include "space.h"
#define STAR_LAYERS 3 #define STAR_LAYERS 1
static gl_texture* starBG[STAR_LAYERS]; static gl_texture* starBG[STAR_LAYERS];
static Vec2 starPos[STAR_LAYERS]; static Vec2 starPos[STAR_LAYERS];
#define STAR_BUF 100 // Area to leave around screen.
typedef struct {
Vec2 pos;
Uint8 brightness;
} Star;
Star* stars;
int nstars;
static gl_texture* starBG_create(const int density); static gl_texture* starBG_create(const int density);
static void put_pixel(SDL_Surface* surface, const int x, const int y, static void put_pixel(SDL_Surface* surface, const int x, const int y,
const Uint8 R, const Uint8 G, const Uint8 B, const Uint8 A); const Uint8 R, const Uint8 G, const Uint8 B, const Uint8 A);
@ -77,7 +86,7 @@ static gl_texture* starBG_create(const int density) {
SDL_LockSurface(surface); SDL_LockSurface(surface);
d = (int)((FP)(density)*(FP)(gl_screen.w)*(FP)(gl_screen.h)/1000./1000.); d = (int)((double)(density)*(double)(gl_screen.w)*(double)(gl_screen.h)/1000./1000.);
for(i = 0; i < d; i++) for(i = 0; i < d; i++)
put_pixel(surface, RNG(0,w-1), RNG(0,h-1), 255, 255, 255, RNG(50, 255)); put_pixel(surface, RNG(0,w-1), RNG(0,h-1), 255, 255, 255, RNG(50, 255));
@ -88,15 +97,33 @@ static gl_texture* starBG_create(const int density) {
void space_init(void) { void space_init(void) {
int i; int i;
nstars = 2000;
stars = malloc(sizeof(Star)*nstars);
for(i = 0; i < nstars; i++) {
stars[i].brightness = RNG(50, 255);
stars[i].pos.x = RNG(STAR_BUF, gl_screen.w + STAR_BUF);
stars[i].pos.y = RNG(-STAR_BUF, gl_screen.h + STAR_BUF);
}
#if 0
for(i = 0; i < STAR_LAYERS; i++) { for(i = 0; i < STAR_LAYERS; i++) {
starBG[i] = starBG_create(1000); starBG[i] = starBG_create(1000);
starPos[i].x = 0.; starPos[i].x = 0.;
starPos[i].y = 0.; starPos[i].y = 0.;
} }
#endif
} }
void space_render(FP dt) { void space_render(double dt) {
int i; int i;
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glBegin(GL_POINTS);
glColor4ub(255, 255, 255, stars[i].brightness);
glVertex2d(stars[i].pos.x, stars[i].pos.y);
glEnd();
glPopMatrix();
#if 0
Vec2 tmp; Vec2 tmp;
FP f; FP f;
@ -146,11 +173,15 @@ void space_render(FP dt) {
else if(tmp.x != starPos[i].x || tmp.y != starPos[i].y) else if(tmp.x != starPos[i].x || tmp.y != starPos[i].y)
gl_blitStatic(starBG[i], &tmp); gl_blitStatic(starBG[i], &tmp);
} }
#endif
} }
void space_exit(void) { void space_exit(void) {
free(stars);
#if 0
int i; int i;
for(i = 0; i < STAR_LAYERS; i++) for(i = 0; i < STAR_LAYERS; i++)
gl_freeTexture(starBG[i]); gl_freeTexture(starBG[i]);
#endif
} }

View File

@ -4,5 +4,5 @@
void space_init(void); void space_init(void);
void space_exit(void); void space_exit(void);
void space_render(FP dt); void space_render(double dt);