[Change] Renamed pilots and mpilots to pilot_nstack and pilot_mstack.
This commit is contained in:
		
							parent
							
								
									c20fe36c27
								
							
						
					
					
						commit
						19e3e818a4
					
				
							
								
								
									
										4
									
								
								src/ai.c
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								src/ai.c
									
									
									
									
									
								
							| @ -71,7 +71,7 @@ static int nprofiles = 0; | ||||
| 
 | ||||
| /* Extern pilot hacks. */ | ||||
| extern Pilot** pilot_stack; | ||||
| extern int pilots; | ||||
| extern int pilot_nstack; | ||||
| 
 | ||||
| static int ai_minbrakedist(lua_State* L); /* Minimal breaking distance. */ | ||||
| static int ai_accel(lua_State* L); /* Accelerate. */ | ||||
| @ -477,7 +477,7 @@ static int ai_gettargetid(lua_State* L) { | ||||
| } | ||||
| 
 | ||||
| static int ai_getrndpilot(lua_State* L) { | ||||
|   lua_pushnumber(L, pilot_stack[RNG(0, pilots-1)]->id); | ||||
|   lua_pushnumber(L, pilot_stack[RNG(0, pilot_nstack-1)]->id); | ||||
|   return 1; | ||||
| } | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										27
									
								
								src/pause.c
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								src/pause.c
									
									
									
									
									
								
							| @ -10,21 +10,21 @@ int paused = 0; /* Are we paused. */ | ||||
| 
 | ||||
| /* From pilot.c */ | ||||
| extern Pilot** pilot_stack; | ||||
| extern int pilots; | ||||
| extern int pilot_nstack; | ||||
| /* From space.c */ | ||||
| extern unsigned int spawn_timer; | ||||
| /* From main.c */ | ||||
| extern unsigned int gtime; | ||||
| 
 | ||||
| static void pilots_pause(void); | ||||
| static void pilots_unpause(void); | ||||
| static void pilots_delay(unsigned int delay); | ||||
| static void pilot_nstack_pause(void); | ||||
| static void pilot_nstack_unpause(void); | ||||
| static void pilot_nstack_delay(unsigned int delay); | ||||
| 
 | ||||
| /* Pause the game. */ | ||||
| void pause_game(void) { | ||||
|   if(paused) return; /* Well well.. We are paused already. */ | ||||
| 
 | ||||
|   pilots_pause(); | ||||
|   pilot_nstack_pause(); | ||||
|   weapons_pause(); | ||||
|   spfx_pause(); | ||||
|   spawn_timer -= SDL_GetTicks(); | ||||
| @ -35,7 +35,7 @@ void pause_game(void) { | ||||
| void unpause_game(void) { | ||||
|   if(!paused) return; /* We are unpaused already. */ | ||||
| 
 | ||||
|   pilots_unpause(); | ||||
|   pilot_nstack_unpause(); | ||||
|   weapons_unpause(); | ||||
|   spfx_unpause(); | ||||
|   spawn_timer += SDL_GetTicks(); | ||||
| @ -45,15 +45,16 @@ void unpause_game(void) { | ||||
| 
 | ||||
| /* Set the timers back. */ | ||||
| void pause_delay(unsigned int delay) { | ||||
|   pilots_delay(delay); | ||||
|   pilot_nstack_delay(delay); | ||||
|   weapons_delay(delay); | ||||
|   spfx_delay(delay); | ||||
| } | ||||
| 
 | ||||
| static void pilots_pause(void) { | ||||
| /* Pilots pausing/unpausing. */ | ||||
| static void pilot_nstack_pause(void) { | ||||
|   int i, j; | ||||
|   unsigned int t = SDL_GetTicks(); | ||||
|   for(i = 0; i < pilots; i++) { | ||||
|   for(i = 0; i < pilot_nstack; i++) { | ||||
|     pilot_stack[i]->ptimer -= t; | ||||
| 
 | ||||
|     pilot_stack[i]->tcontrol -= t; | ||||
| @ -62,10 +63,10 @@ static void pilots_pause(void) { | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| static void pilots_unpause(void) { | ||||
| static void pilot_nstack_unpause(void) { | ||||
|   int i, j; | ||||
|   unsigned int t = SDL_GetTicks(); | ||||
|   for(i = 0; i < pilots; i++) { | ||||
|   for(i = 0; i < pilot_nstack; i++) { | ||||
|     pilot_stack[i]->ptimer += t; | ||||
| 
 | ||||
|     pilot_stack[i]->tcontrol += t; | ||||
| @ -74,9 +75,9 @@ static void pilots_unpause(void) { | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| static void pilots_delay(unsigned int delay) { | ||||
| static void pilot_nstack_delay(unsigned int delay) { | ||||
|   int i, j; | ||||
|   for(i = 0; i < pilots; i++) { | ||||
|   for(i = 0; i < pilot_nstack; i++) { | ||||
|     pilot_stack[i]->ptimer += delay; | ||||
| 
 | ||||
|     pilot_stack[i]->tcontrol += delay; | ||||
|  | ||||
							
								
								
									
										52
									
								
								src/pilot.c
									
									
									
									
									
								
							
							
						
						
									
										52
									
								
								src/pilot.c
									
									
									
									
									
								
							| @ -26,10 +26,10 @@ static unsigned int pilot_id = PLAYER_ID; | ||||
| /* id for special mission cargo. */ | ||||
| static unsigned int mission_cargo_id = 0; | ||||
| 
 | ||||
| /* Stack of pilots - yes, they come in stacks now. */ | ||||
| /* Stack of pilots. */ | ||||
| Pilot** pilot_stack = NULL; /* Not static, it is used in player.c and weapon.c and ai.c */ | ||||
| int pilots = 0; | ||||
| static int mpilots = 0; | ||||
| int pilot_nstack = 0; | ||||
| static int pilot_mstack = 0; | ||||
| 
 | ||||
| extern Pilot* player; | ||||
| extern unsigned int player_crating; | ||||
| @ -66,15 +66,15 @@ unsigned int pilot_getNext(const unsigned int id) { | ||||
|   /* Binary search. */ | ||||
|   int l, m, h; | ||||
|   l = 0; | ||||
|   h = pilots-1; | ||||
|   h = pilot_nstack-1; | ||||
|   while(l <= h) { | ||||
|     m = (l+h)/2; | ||||
|     m = l+(h-l)/2; /* For impossible overflow returning negative value. */ | ||||
|     if(pilot_stack[m]->id > id) h = m-1; | ||||
|     else if(pilot_stack[m]->id < id) l = m+1; | ||||
|     else break; | ||||
|   } | ||||
| 
 | ||||
|   if(m == (pilots-1)) return PLAYER_ID; | ||||
|   if(m == (pilot_nstack-1)) return PLAYER_ID; | ||||
|   else return pilot_stack[m+1]->id; | ||||
| } | ||||
| 
 | ||||
| @ -84,7 +84,7 @@ unsigned int pilot_getNearest(const Pilot* p) { | ||||
|   int i; | ||||
|   double d, td; | ||||
| 
 | ||||
|   for(tp = 0, d = 0., i = 0; i < pilots; i++) | ||||
|   for(tp = 0, d = 0., i = 0; i < pilot_nstack; i++) | ||||
|     if(areEnemies(p->faction, pilot_stack[i]->faction)) { | ||||
|       td = vect_dist(&pilot_stack[i]->solid->pos, &p->solid->pos); | ||||
|       if(!pilot_isDisabled(pilot_stack[i]) && ((!tp) || (td < d))) { | ||||
| @ -100,7 +100,7 @@ unsigned pilot_getHostile(void) { | ||||
|   unsigned int tp; | ||||
|   int i; | ||||
|   double d, td; | ||||
|   for(tp = PLAYER_ID, d = 0., i = 0; i < pilots; i++) | ||||
|   for(tp = PLAYER_ID, d = 0., i = 0; i < pilot_nstack; i++) | ||||
|     if(pilot_isFlag(pilot_stack[i], PILOT_HOSTILE)) { | ||||
|       td = vect_dist(&pilot_stack[i]->solid->pos, &player->solid->pos); | ||||
|       if(!pilot_isDisabled(pilot_stack[i]) && ((tp == PLAYER_ID) || (td < d))) { | ||||
| @ -118,7 +118,7 @@ Pilot* pilot_get(const unsigned int id) { | ||||
|   /* Binary search. */ | ||||
|   int l, m, h; | ||||
|   l = 0; | ||||
|   h = pilots-1; | ||||
|   h = pilot_nstack-1; | ||||
|   while(l <= h) { | ||||
|     m = (l+h)/2; | ||||
|     if(pilot_stack[m]->id > id) h = m-1; | ||||
| @ -954,25 +954,25 @@ unsigned int pilot_create(Ship* ship, char* name, int faction, | ||||
|     /* Player. */ | ||||
|     if(!pilot_stack) { | ||||
|       pilot_stack = MALLOC_L(Pilot*); | ||||
|       pilots = 1; | ||||
|       mpilots = 1; | ||||
|       pilot_nstack = 1; | ||||
|       pilot_mstack = 1; | ||||
|     } | ||||
|     pilot_stack[0] = dyn; | ||||
|   } else { | ||||
|     /* Add to the stack. */ | ||||
|     pilots++; /* There is a new pilot. */ | ||||
|     pilot_nstack++; /* There is a new pilot. */ | ||||
| 
 | ||||
|     if(pilots >= mpilots) { | ||||
|     if(pilot_nstack >= pilot_mstack) { | ||||
|       /* Need to grow. About 20 at a time. */ | ||||
|       mpilots += PILOT_CHUNK; | ||||
|       pilot_mstack += PILOT_CHUNK; | ||||
|       tp = pilot_stack; | ||||
|       pilot_stack = realloc(pilot_stack, mpilots*sizeof(Pilot*)); | ||||
|       pilot_stack = realloc(pilot_stack, pilot_mstack*sizeof(Pilot*)); | ||||
|       if((pilot_stack != tp) && player) | ||||
|         /* Take into account possible mem move. */ | ||||
|         player = pilot_stack[0]; | ||||
|     } | ||||
| 
 | ||||
|     pilot_stack[pilots-1] = dyn; | ||||
|     pilot_stack[pilot_nstack-1] = dyn; | ||||
|   } | ||||
|   return dyn->id; | ||||
| } | ||||
| @ -1032,13 +1032,13 @@ void pilot_free(Pilot* p) { | ||||
| /* Destroy pilot from stack. */ | ||||
| void pilot_destroy(Pilot* p) { | ||||
|   int i; | ||||
|   for(i = 0; i < pilots; i++) | ||||
|   for(i = 0; i < pilot_nstack; i++) | ||||
|     if(pilot_stack[i] == p) | ||||
|       break; | ||||
| 
 | ||||
|   pilots--; | ||||
|   pilot_nstack--; | ||||
| 
 | ||||
|   while(i < pilots) { | ||||
|   while(i < pilot_nstack) { | ||||
|     pilot_stack[i] = pilot_stack[i+1]; | ||||
|     i++; | ||||
|   } | ||||
| @ -1049,19 +1049,19 @@ void pilot_destroy(Pilot* p) { | ||||
| void pilots_free(void) { | ||||
|   int i; | ||||
|   if(player) pilot_free(player); | ||||
|   for(i = 1; i < pilots; i++) | ||||
|   for(i = 1; i < pilot_nstack; i++) | ||||
|     pilot_free(pilot_stack[i]); | ||||
|   free(pilot_stack); | ||||
|   pilot_stack = NULL; | ||||
|   pilots = 0; | ||||
|   pilot_nstack = 0; | ||||
| } | ||||
| 
 | ||||
| /* Clean up the pilots - Leaves the player. */ | ||||
| void pilots_clean(void) { | ||||
|   int i; | ||||
|   for(i = 1; i < pilots; i++) | ||||
|   for(i = 1; i < pilot_nstack; i++) | ||||
|     pilot_free(pilot_stack[i]); | ||||
|   pilots = 1; | ||||
|   pilot_nstack = 1; | ||||
| } | ||||
| 
 | ||||
| void pilots_cleanAll(void) { | ||||
| @ -1070,13 +1070,13 @@ void pilots_cleanAll(void) { | ||||
|     pilot_free(player); | ||||
|     player = NULL; | ||||
|   } | ||||
|   pilots = 0; | ||||
|   pilot_nstack = 0; | ||||
| } | ||||
| 
 | ||||
| /* Update all pilots. */ | ||||
| void pilots_update(double dt) { | ||||
|   int i; | ||||
|   for(i = 0; i < pilots; i++) { | ||||
|   for(i = 0; i < pilot_nstack; i++) { | ||||
|     if(pilot_stack[i]->think && !pilot_isDisabled(pilot_stack[i])) { | ||||
|       /* Hyperspace gets special treatment. */ | ||||
|       if(pilot_isFlag(pilot_stack[i], PILOT_HYP_PREP)) | ||||
| @ -1096,7 +1096,7 @@ void pilots_update(double dt) { | ||||
| /* Render all the pilots. */ | ||||
| void pilots_render(void) { | ||||
|   int i; | ||||
|   for(i = 1; i < pilots; i++) | ||||
|   for(i = 1; i < pilot_nstack; i++) | ||||
|     /* Skip the player. */ | ||||
|     if(pilot_stack[i]->render) | ||||
|       pilot_stack[i]->render(pilot_stack[i]); | ||||
|  | ||||
| @ -73,7 +73,7 @@ static int  missions_ndone = 0; | ||||
| 
 | ||||
| /* Pilot stuff for GUI. */ | ||||
| extern Pilot** pilot_stack; | ||||
| extern int pilots; | ||||
| extern int pilot_nstack; | ||||
| 
 | ||||
| /* Space stuff for GUI. */ | ||||
| extern StarSystem* systems_stack; | ||||
| @ -641,7 +641,7 @@ void player_render(void) { | ||||
|   glEnd(); | ||||
| 
 | ||||
|   /* Render the pilots. */ | ||||
|   for(j = 0, i = 1; i < pilots; i++) { | ||||
|   for(j = 0, i = 1; i < pilot_nstack; i++) { | ||||
|     /* Skip the player. */ | ||||
|     if(pilot_stack[i]->id == player_target) j = i; | ||||
|     else gui_renderPilot(pilot_stack[i]); | ||||
|  | ||||
| @ -23,7 +23,7 @@ | ||||
| 
 | ||||
| /* Some stuff from pilot. */ | ||||
| extern Pilot** pilot_stack; | ||||
| extern int pilots; | ||||
| extern int pilot_nstack; | ||||
| 
 | ||||
| /* Player stuff. */ | ||||
| extern unsigned int player_target; | ||||
| @ -291,7 +291,7 @@ static void weapon_update(Weapon* w, const double dt, WeaponLayer layer) { | ||||
| 
 | ||||
|   gl_getSpriteFromDir(&wsx, &wsy, gfx, w->solid->dir); | ||||
| 
 | ||||
|   for(i = 0; i < pilots; i++) { | ||||
|   for(i = 0; i < pilot_nstack; i++) { | ||||
|     psx = pilot_stack[i]->tsx; | ||||
|     psy = pilot_stack[i]->tsy; | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Allanis
						Allanis