Skip to content

Commit

Permalink
Filter rendered satellites.
Browse files Browse the repository at this point in the history
  • Loading branch information
wojciech-graj committed Aug 21, 2022
1 parent 3f6681e commit 92b8558
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/entity/satellite.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "catalog.h"
#include "download.h"
#include "error.h"
#include "filter.h"
#include "gfx.h"
#include "perf.h"
#include "phys.h"
Expand All @@ -46,6 +47,7 @@
#define WAIT_USEC 100UL
#define SATELLITE_CALC_STEP 2000
#define MAX_THREAD_TIC 2
#define CACHE_INVAL_MS 43200000LL

enum LayoutLoc {
LOCL_APOS = 0u,
Expand Down Expand Up @@ -90,6 +92,8 @@ static struct Satellite *satellites = NULL;
static size_t n_satellites = 0;
static gboolean satellites_renderable = FALSE;
static vec3 *satellite_verts = NULL;
static size_t n_satellites_render = 0;
static GLuint *satellite_indices = NULL;

static size_t n_satellite_orbits = 0;
static size_t satellite_orbits_size = 0;
Expand Down Expand Up @@ -192,6 +196,19 @@ void satellite_deinit(void)
g_thread_pool_free(thread_pool, TRUE, FALSE);
}

void satellites_filter(void)
{
n_satellites_render = 0;
size_t i;
for (i = 0; i < n_satellites; i++) {
if (filter_func(&satellites[i])) {
satellite_indices[n_satellites_render] = i;
n_satellites_render++;
} else if (satellites[i].orbit_idx != UINT32_MAX)
satellite_select_ptr(&satellites[i]);
}
}

void satellites_get_prep(void)
{
status_push(STAT_FETCHING_SAT, "Fetching satellite data...");
Expand Down Expand Up @@ -257,7 +274,7 @@ void satellites_get(void)
} else {
gint64 cache_time;
fread(&cache_time, 8, 1, cache);
if (system_epoch_ms() - cache_time > 43200000LL) {
if (system_epoch_ms() - cache_time > CACHE_INVAL_MS) {
fclose(cache);
dl_multi_perform(&dl_multi);
save_satellite_cache();
Expand Down Expand Up @@ -358,6 +375,9 @@ void satellites_get_sync(void)
bo_buffer(&vbo_vert_colors, vert_colors_sync, sizeof(vec3) * n_satellites);
g_free(vert_colors_sync);

g_free(satellite_indices);
satellite_indices = g_malloc(sizeof(GLuint) * n_satellites);

n_satellite_orbits = 0;
satellite_orbits_size = 0;
dealloc_orbit_arrays();
Expand All @@ -373,6 +393,7 @@ void satellites_get_sync(void)

catalog_satellites_fill(satellites, n_satellites);
perf_set_num_satellites(n_satellites);
satellites_filter();

status_pop(STAT_FETCHING_SAT);
}
Expand Down Expand Up @@ -402,7 +423,7 @@ void satellites_tic(void)
void satellites_calc_pos(gpointer data, gpointer user_data)
{
(void)user_data;
guint32 start = *((guint32*)data);
guint32 start = *((guint32 *)data);
guint32 end = MIN(n_satellites, start + SATELLITE_CALC_STEP);
guint32 i;
for (i = start; i < end; i++) {
Expand Down Expand Up @@ -457,7 +478,7 @@ void satellites_render(void)
if (satellites_renderable) {
vao_bind(&vao_satellites);
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
glDrawArrays(GL_POINTS, 0, n_satellites);
glDrawElements(GL_POINTS, n_satellites_render, GL_UNSIGNED_INT, satellite_indices);
glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);

vao_bind(&vao_orbits);
Expand Down
2 changes: 2 additions & 0 deletions src/entity/satellite.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ void satellite_select_ptr(struct Satellite *satellite);

void satellite_clear_cache(void);

void satellites_filter(void);

#endif /* __SATELLITE_H__ */
2 changes: 2 additions & 0 deletions src/ui/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ void on_filter_clear_clicked(GtkButton *button, gpointer user_data)

active = FALSE;
gtk_tree_model_filter_refilter(e_catalog_filter);
satellites_filter();
}

void filter_set_from_entry(enum FilterEntry entry, enum FilterField field, double *target, double dflt[2])
Expand Down Expand Up @@ -205,6 +206,7 @@ void on_filter_apply_clicked(GtkButton *button, gpointer user_data)

active = TRUE;
gtk_tree_model_filter_refilter(e_catalog_filter);
satellites_filter();
}

gboolean filter_func(struct Satellite *satellite)
Expand Down

0 comments on commit 92b8558

Please sign in to comment.