Skip to content

Commit

Permalink
Only calculate positions of visible satellites.
Browse files Browse the repository at this point in the history
  • Loading branch information
wojciech-graj committed Aug 22, 2022
1 parent 92b8558 commit de1e0ad
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/entity/satellite.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand All @@ -415,21 +412,23 @@ 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);
}

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]]);
}
}

Expand Down

0 comments on commit de1e0ad

Please sign in to comment.