diff --git a/src/entity/satellite.c b/src/entity/satellite.c index ea1e85c..cb9bed3 100644 --- a/src/entity/satellite.c +++ b/src/entity/satellite.c @@ -110,9 +110,7 @@ static const char *CACHE_FILENAME = ".sat_cache"; static GThreadPool *thread_pool; static guint32 *thread_pool_indices_sync; -static guint32 n_thread_pool_indices_sync; static guint32 *thread_pool_indices = NULL; -static guint32 n_thread_pool_indices = 0; static void satellite_toggle_orbit(guint32 idx); static void gen_satellite_orbit(guint32 idx); @@ -338,9 +336,9 @@ void satellites_get(void) for (i = 0; i < n_satellites_sync; i++) set_satellite_color(satellites_sync[i].satcat.opstat, vert_colors_sync[i]); - n_thread_pool_indices_sync = (SATELLITE_CALC_STEP - 1 + n_satellites_sync) / SATELLITE_CALC_STEP; - thread_pool_indices_sync = g_malloc(sizeof(guint32) * n_thread_pool_indices_sync); - for (i = 0; i < n_thread_pool_indices_sync; i++) + guint32 n_thread_pool_indices = (SATELLITE_CALC_STEP - 1 + n_satellites_sync) / SATELLITE_CALC_STEP; + thread_pool_indices_sync = g_malloc(sizeof(guint32) * n_thread_pool_indices); + for (i = 0; i < n_thread_pool_indices; i++) thread_pool_indices_sync[i] = SATELLITE_CALC_STEP * i; } @@ -389,7 +387,6 @@ void satellites_get_sync(void) g_free(thread_pool_indices); thread_pool_indices = thread_pool_indices_sync; - n_thread_pool_indices = n_thread_pool_indices_sync; catalog_satellites_fill(satellites, n_satellites); perf_set_num_satellites(n_satellites); @@ -415,8 +412,10 @@ void satellites_tic(void) if (!n_satellites) return; + guint32 n_indices = (SATELLITE_CALC_STEP - 1 + n_satellites_render) / SATELLITE_CALC_STEP; + guint32 i; - for (i = 0; i < n_thread_pool_indices; i++) + for (i = 0; i < n_indices; i++) g_thread_pool_push(thread_pool, &thread_pool_indices[i], NULL); } @@ -424,12 +423,12 @@ void satellites_calc_pos(gpointer data, gpointer user_data) { (void)user_data; guint32 start = *((guint32 *)data); - guint32 end = MIN(n_satellites, start + SATELLITE_CALC_STEP); + guint32 end = MIN(n_satellites_render, start + SATELLITE_CALC_STEP); guint32 i; for (i = start; i < end; i++) { double r[3], v[3]; - getRVForDate(&satellites[i].tle, e_phys.epoch_ms, r, v); - glm_vec3_copy((vec3){ r[0], r[1], r[2] }, satellite_verts[i]); + getRVForDate(&satellites[satellite_indices[i]].tle, e_phys.epoch_ms, r, v); + glm_vec3_copy((vec3){ r[0], r[1], r[2] }, satellite_verts[satellite_indices[i]]); } }