Skip to content

Commit

Permalink
Replace magic numbers with named constants.
Browse files Browse the repository at this point in the history
  • Loading branch information
wojciech-graj committed Aug 20, 2022
1 parent fb98646 commit 2b499c5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
19 changes: 13 additions & 6 deletions src/entity/satellite.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
#include "thread.h"
#include "vao.h"

#define SATELLITE_COLOR_ACTIVE ((vec3){ 0.f, 0.9f, 0.f })
#define SATELLITE_COLOR_NONOPERATIONAL ((vec3){ 0.9f, 0.0f, 0.f })
#define SATELLITE_COLOR_OTHER ((vec3){ 0.6f, 0.6f, 0.6f })
#define ORBIT_SEGMENT_LENGTH 250.f
#define ORBIT_MAX_DELTA_DIV 4L
#define SATELLITE_SELECT_MIN_COS_ANG2 0.9995f

enum LayoutLoc {
LOCL_APOS = 0u,
LOCL_COLOR,
Expand Down Expand Up @@ -294,15 +301,15 @@ static void set_satellite_color(char code, vec3 color)
case SCSTAT_BACKUP:
case SCSTAT_SPARE:
case SCSTAT_EXTENDED_MISSION:
glm_vec3_copy((vec3){ 0.f, 0.9f, 0.f }, color);
glm_vec3_copy(SATELLITE_COLOR_ACTIVE, color);
break;
case SCSTAT_NONOPERATIONAL:
glm_vec3_copy((vec3){ 0.9f, 0.0f, 0.f }, color);
glm_vec3_copy(SATELLITE_COLOR_NONOPERATIONAL, color);
break;
/*case SCSTAT_UNKNOWN:
case ' ':*/
default:
glm_vec3_copy((vec3){ 0.6f, 0.6f, 0.6f }, color);
glm_vec3_copy(SATELLITE_COLOR_OTHER, color);
}
}

Expand Down Expand Up @@ -413,14 +420,14 @@ static void satellite_toggle_orbit(guint32 idx)
{
if (satellites[idx].orbit_idx == UINT32_MAX) { /* Enable orbit */
/* For similar-length line segments, apply Kepler's Third Law (T^2 prop. r^3) */
int count = 250.f / cbrtf(satellites[idx].tle.n * satellites[idx].tle.n);
int count = ORBIT_SEGMENT_LENGTH / cbrtf(satellites[idx].tle.n * satellites[idx].tle.n);

satellites[idx].orbit_idx = n_satellite_orbits;

struct OrbitData new_orbit_data = (struct OrbitData){
.idx = idx,
.start_epoch_ms = e_phys.epoch_ms,
.max_delta_ms = satellites[idx].satcat.period * (60000L / 4L),
.max_delta_ms = satellites[idx].satcat.period * (60000L / ORBIT_MAX_DELTA_DIV),
};
g_array_append_val(satellite_orbit_data, new_orbit_data);
g_array_append_val(satellite_orbit_counts, count);
Expand Down Expand Up @@ -487,7 +494,7 @@ void satellite_select(double xpos, double ypos)
float dp = glm_vec3_dot(dir, p1sat);
float dist2 = glm_vec3_norm2(p1sat);
float cos_ang2 = (dp * dp * dir_inv_len2) / dist2;
if (unlikely(cos_ang2 > 0.9994f && dp > 0 && dist2 < min_dist2)) {
if (unlikely(cos_ang2 > SATELLITE_SELECT_MIN_COS_ANG2 && dp > 0 && dist2 < min_dist2)) {
idx = i;
min_dist2 = dist2;
}
Expand Down
21 changes: 11 additions & 10 deletions src/gfx/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,22 @@

#include <cglm/cglm.h>

#define DEFAULT_CAMERA_POS ((vec3){ 0.f, 5.f, 0.f })
#define DEFAULT_CAMERA_RAD 5.f
#define CAMERA_FOV ((float)G_PI / 2.f)
#define CAMERA_NEAR 0.05f
#define CAMERA_FAR 100.f

void render_init(void)
{
glm_vec3_copy((vec3){ 0, 5.0, 0 }, e_camera.pos);
glm_vec3_copy(DEFAULT_CAMERA_POS, e_camera.pos);
glm_vec3_copy((vec3){ 0, 0, 0 }, e_camera.target);
glm_vec3_copy((vec3){ 0, 0, 1 }, e_camera.up);

e_camera.rad = 5.f;
e_camera.fov = (float)G_PI / 2.f;
e_camera.near = 0.05f;
e_camera.far = 100.f;
e_camera.rad = DEFAULT_CAMERA_RAD;
e_camera.fov = CAMERA_FOV;
e_camera.near = CAMERA_NEAR;
e_camera.far = CAMERA_FAR;

camera_view_update(&e_camera);
camera_proj_update(&e_camera);
Expand All @@ -38,15 +44,10 @@ void render_init(void)
glEnable(GL_STENCIL_TEST);
}

void render_deinit(void)
{
}

void render_process(void)
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

entity_render();
//ui_render();
}
1 change: 0 additions & 1 deletion src/gfx/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define __RENDER_H__

void render_init(void);
void render_deinit(void);
void render_process(void);

#endif /* __RENDER_H__ */
1 change: 0 additions & 1 deletion src/ui/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ gboolean on_window_main_delete_event(GtkWidget *widget, GdkEvent *event, gpointe
(void)user_data;

thread_deinit();
render_deinit();
entity_deinit();
ui_deinit();
system_deinit();
Expand Down

0 comments on commit 2b499c5

Please sign in to comment.