From 848a5e120df84bba501e263d1da55291d8c09d0a Mon Sep 17 00:00:00 2001
From: Allanis <allanis@saracraft.net>
Date: Sat, 1 Jun 2013 18:39:37 +0100
Subject: [PATCH] [Fix] Added PLAYER_CREATING flag to fix all creation/death
 issues propperly.

---
 src/player.c | 20 ++++++++++++--------
 src/player.h |  1 +
 src/space.c  |  5 +++--
 3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/src/player.c b/src/player.c
index 3e5a650..aaa41d6 100644
--- a/src/player.c
+++ b/src/player.c
@@ -154,7 +154,7 @@ void player_new(void) {
   int r;
   // Let's not seg fault due to a lack of environment.
   player_flags = 0;
-  player_setFlag(PLAYER_DESTROYED);
+  player_setFlag(PLAYER_CREATING);
   vectnull(&player_cam);
   gl_bindCamera(&player_cam);
 
@@ -296,7 +296,7 @@ static void player_newShipMake(char* name) {
   }
 
   // In case we're respawning.
-  player_rmFlag(PLAYER_DESTROYED);
+  player_rmFlag(PLAYER_CREATING);
 
   vect_cset(&vp, player_px, player_py);
   vect_cset(&vv, player_vx, player_vy);
@@ -456,8 +456,8 @@ void player_renderBG(void) {
   glColour* c;
   Planet* planet;
 
-  if(player_isFlag(PLAYER_DESTROYED) ||
-     pilot_isFlag(player, PILOT_DEAD)) return;
+  if(player_isFlag(PLAYER_DESTROYED) || player_isFlag(PLAYER_CREATING) ||
+      pilot_isFlag(player, PLAYER_DESTROYED)) return;
 
   if(planet_target >= 0) {
     planet = &cur_system->planets[planet_target];
@@ -489,13 +489,17 @@ void player_render(void) {
   glColour* c;
   glFont* f;
 
-  // Pilot is dead, just render her and stop.
-  if(player_isFlag(PLAYER_DESTROYED) || pilot_isFlag(player, PILOT_DEAD)) {
+  // Pilot is dead or being created, just render her and stop.
+  if(player_isFlag(PLAYER_DESTROYED) || player_isFlag(PLAYER_CREATING) ||
+      pilot_isFlag(player, PILOT_DEAD)) {
+
     if(player_isFlag(PLAYER_DESTROYED)) {
-      if(!toolkit && (player != NULL) && (SDL_GetTicks() > player_timer)) {
+      if(!toolkit && !player_isFlag(PLAYER_CREATING) &&
+          (SDL_GetTicks() > player_timer)) {
         menu_death();
       }
-    } else
+    }
+    else if(!player_isFlag(PLAYER_CREATING))
       pilot_render(player);
 
     // Fancy cinematic scene borders.
diff --git a/src/player.h b/src/player.h
index 6bfbc36..175a55b 100644
--- a/src/player.h
+++ b/src/player.h
@@ -11,6 +11,7 @@
 #define PLAYER_PRIMARY      (1<<11)   // Player is shooting primary weapon.
 #define PLAYER_SECONDARY    (1<<12)   // Player is shooting secondary weapon.
 #define PLAYER_LANDACK      (1<<13)   // Player has permission to land.
+#define PLAYER_CREATING     (1<<14)   // Player is being created.
 
 // Flag functions.
 #define player_isFlag(f)  (player_flags  & f)
diff --git a/src/space.c b/src/space.c
index 09bfce1..6b02e4e 100644
--- a/src/space.c
+++ b/src/space.c
@@ -972,7 +972,7 @@ void space_render(double dt) {
   glTranslated(-(double)gl_screen.w/2., -(double)gl_screen.h/2., 0);
 
   t = SDL_GetTicks();
-  if(!player_isFlag(PLAYER_DESTROYED) &&
+  if(!player_isFlag(PLAYER_DESTROYED) && !player_isFlag(PLAYER_CREATING) &&
      pilot_isFlag(player, PILOT_HYPERSPACE) && // Hyperspace fancy effect.
      !paused && (player->ptimer-HYPERSPACE_STARS_BLUR < t)) {
 
@@ -1000,7 +1000,8 @@ void space_render(double dt) {
 
   } else {
     glBegin(GL_POINTS); // Normal rendering.
-    if(!paused && !player_isFlag(PLAYER_DESTROYED)) { // Update position.
+    if(!paused && !player_isFlag(PLAYER_DESTROYED) &&
+        !player_isFlag(PLAYER_CREATING)) { // Update position.
       for(i = 0; i < nstars; i++) {
         b = 13.-10.*stars[i].brightness;
         stars[i].x -= player->solid->vel.x/b*dt;