diff --git a/Makefile b/Makefile index a273b12..b5a02af 100755 --- a/Makefile +++ b/Makefile @@ -3,15 +3,15 @@ TARGET := orbvis CC := gcc WARNINGS := -Wall -Wextra -Wpedantic -Wdouble-promotion -Wstrict-prototypes -Wshadow -Wduplicated-cond -Wduplicated-branches -Wjump-misses-init -Wnull-dereference -Wrestrict -Wlogical-op -Walloc-zero -Wformat-security -Wformat-signedness -Winit-self -Wlogical-op -Wmissing-declarations -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wswitch-enum -Wundef -Wwrite-strings -Wno-discarded-qualifiers CFLAGS := -O3 `pkg-config --cflags gtk+-3.0 cglm libcurl epoxy` -std=c11 -LDFLAGS := -lm +LDFLAGS := -lm `pkg-config --libs gtk+-3.0 cglm libcurl epoxy` COMMANDS := $(CC) pkg-config xxd sed PACKAGES := gtk+-3.0 cglm libcurl epoxy ifeq ($(MAKECMDGOALS),windows) CFLAGS += -march=core2 -flto - LDFLAGS += -lopengl32 `pkg-config --libs gtk+-3.0 cglm libcurl epoxy` -mwindows -flto + LDFLAGS += -lopengl32 -mwindows -flto else - LDFLAGS += -ldl `pkg-config --libs gl gtk+-3.0 cglm libcurl epoxy` + LDFLAGS += -ldl ifeq ($(MAKECMDGOALS),debug) CFLAGS += -march=native -fsanitize=address -fsanitize=undefined -g -ftrapv -fno-omit-frame-pointer -lrt -DDEBUG LDFLAGS += -fsanitize=address -fsanitize=undefined -g -ftrapv -fno-omit-frame-pointer -lrt diff --git a/res/ui/ui.glade b/res/ui/ui.glade index b6a2847..ffc538a 100644 --- a/res/ui/ui.glade +++ b/res/ui/ui.glade @@ -1560,7 +1560,6 @@ False True True - True diff --git a/src/core/type.h b/src/core/type.h index a7c0c36..f364b93 100644 --- a/src/core/type.h +++ b/src/core/type.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Wojciech Graj + * Copyright (c) 2022-2023 Wojciech Graj * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -22,8 +22,6 @@ #define likely(x) __builtin_expect((x), TRUE) #define unlikely(x) __builtin_expect((x), FALSE) -#define arrlen(a) (sizeof(a) / sizeof(a[0])) - #define SWAP(a, b) \ do { \ __typeof__(a) temp_ = a; \ @@ -31,8 +29,6 @@ b = temp_; \ } while (0) -#define sgn(x) (signbit(x) ? -1 : 1) - #define XSTR(s) STR(s) #define STR(s) #s diff --git a/src/entity/entity.c b/src/entity/entity.c index 678a84e..89ed48b 100644 --- a/src/entity/entity.c +++ b/src/entity/entity.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Wojciech Graj + * Copyright (c) 2022-2023 Wojciech Graj * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -22,9 +22,7 @@ void entity_init(void) { earth_init(); -#ifndef NO_SATELLITE satellite_init(); -#endif sky_init(); } @@ -33,12 +31,9 @@ void entity_render(void) glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace(GL_CW); - glEnable(GL_DEPTH_TEST); earth_render(); -#ifndef NO_SATELLITE satellites_render(); -#endif glCullFace(GL_FRONT); sky_render(); } @@ -46,8 +41,6 @@ void entity_render(void) void entity_deinit(void) { earth_deinit(); -#ifndef NO_SATELLITE satellite_deinit(); -#endif sky_deinit(); } diff --git a/src/entity/satellite.c b/src/entity/satellite.c index 5ee14de..1fd7c51 100644 --- a/src/entity/satellite.c +++ b/src/entity/satellite.c @@ -222,14 +222,14 @@ void *satellites_get_thrd(void *arguments) return NULL; } -static guint64 sc_hash(const void *item, guint64 seed0, guint64 seed1) +guint64 sc_hash(const void *item, guint64 seed0, guint64 seed1) { (void)seed0; (void)seed1; return ((struct SatCat *)item)->catnum; } -static int sc_compare(const void *a, const void *b, void *udata) +int sc_compare(const void *a, const void *b, void *udata) { (void)udata; return (int)(((struct SatCat *)a)->catnum) - (int)(((struct SatCat *)b)->catnum); @@ -344,7 +344,7 @@ void satellites_get(void) thread_pool_indices_sync[i] = SATELLITE_CALC_STEP * i; } -static void set_satellite_color(char code, vec3 color) +void set_satellite_color(char code, vec3 color) { switch (code) { case SCSTAT_OPERATIONAL: @@ -494,7 +494,7 @@ void gen_satellite_orbit(guint32 idx) } } -static void satellite_toggle_orbit(guint32 idx) +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) */ diff --git a/src/gfx/gfx.c b/src/gfx/gfx.c index 43c6376..9e00a45 100644 --- a/src/gfx/gfx.c +++ b/src/gfx/gfx.c @@ -16,14 +16,9 @@ #include "camera.h" #include "error.h" -#include "info.h" -#include "perf.h" -#include "render.h" -#include "thread.h" -#include "toolbar.h" +#include "mainloop.h" struct GLCtx e_gl_ctx; -static GtkGLArea *glarea; static void on_glarea_realize(GtkWidget *widget, gpointer user_data); static void on_glarea_resize(GtkGLArea *area, int width, int height, gpointer user_data); @@ -32,7 +27,8 @@ static gboolean on_glarea_render(GtkGLArea *area, GdkGLContext *context, gpointe void on_glarea_realize(GtkWidget *widget, gpointer user_data) { (void)user_data; - (void)widget; + + GtkGLArea *glarea = GTK_GL_AREA(widget); error_check(!gtk_gl_area_get_error(glarea), "Failed to create OpenGL context"); @@ -57,24 +53,13 @@ void on_glarea_resize(GtkGLArea *area, int width, int height, gpointer user_data camera_proj_update(&e_camera); } -/* Main Loop */ gboolean on_glarea_render(GtkGLArea *area, GdkGLContext *context, gpointer user_data) { (void)area; (void)context; (void)user_data; - thread_dispatch(THRD_PHYS, NULL); - satellites_tic(); - render_process(); - toolbar_tic(); - info_tic(); - perf_tic(); - thread_join(THRD_PHYS); - satellites_tic_sync(); -#ifndef NO_SATELLITE - thread_join_if_finished(THRD_SATELLITES_GET); -#endif + mainloop(); return TRUE; } @@ -87,6 +72,6 @@ void gfx_init(GtkBuilder *builder) "on_glarea_realize", G_CALLBACK(on_glarea_realize), NULL); - glarea = GTK_GL_AREA(gtk_builder_get_object(builder, "glarea")); + GtkGLArea *glarea = GTK_GL_AREA(gtk_builder_get_object(builder, "glarea")); gtk_gl_area_set_required_version(glarea, 4, 1); } diff --git a/src/gfx/render.c b/src/gfx/render.c index 848fc71..94495cd 100644 --- a/src/gfx/render.c +++ b/src/gfx/render.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Wojciech Graj + * Copyright (c) 2022-2023 Wojciech Graj * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -14,21 +14,13 @@ #include "render.h" -#include "bo.h" #include "camera.h" #include "entity.h" -#include "error.h" #include "gfx.h" -#include "icosphere.h" -#include "idx_obj.h" -#include "model.h" -#include "shader.h" -#include "system.h" #include "texture.h" -#include "ui.h" -#include "vao.h" +#include "type.h" -#include +#include #define DEFAULT_CAMERA_POS ((vec3){ 0.f, 5.f, 0.f }) #define DEFAULT_CAMERA_RAD 5.f @@ -50,18 +42,19 @@ void render_init(void) camera_view_update(&e_camera); camera_proj_update(&e_camera); + textures_init(); + + glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - glEnable(GL_STENCIL_TEST); } 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); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); entity_render(); } diff --git a/src/gfx/shader.c b/src/gfx/shader.c index 1a09325..2378de9 100644 --- a/src/gfx/shader.c +++ b/src/gfx/shader.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Wojciech Graj + * Copyright (c) 2022-2023 Wojciech Graj * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -20,7 +20,7 @@ static GLint shader_compile(char *str, unsigned int len, GLenum type); -static GLint shader_compile(char *str, unsigned int len, GLenum type) +GLint shader_compile(char *str, unsigned int len, GLenum type) { GLuint handle = glCreateShader(type); glShaderSource(handle, 1, (const GLchar *const *)&str, (const GLint *)&len); diff --git a/src/gfx/texture.c b/src/gfx/texture.c index 250c653..8755704 100644 --- a/src/gfx/texture.c +++ b/src/gfx/texture.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Wojciech Graj + * Copyright (c) 2022-2023 Wojciech Graj * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -18,6 +18,11 @@ #include "error.h" +void textures_init(void) +{ + stbi_set_flip_vertically_on_load(TRUE); +} + void texture_init(struct Texture *texture, GLenum unit, GLenum type) { texture->unit = unit; @@ -30,7 +35,6 @@ void texture_init(struct Texture *texture, GLenum unit, GLenum type) void texture_init_from_image(struct Texture *texture, unsigned char *buffer, unsigned int len, GLenum unit, GLenum type) { int width, height, n_channels; - stbi_set_flip_vertically_on_load(TRUE); /* TODO: Move to init */ unsigned char *data = stbi_load_from_memory(buffer, len, &width, &height, &n_channels, 0); error_check(data, "Failed to open texture."); diff --git a/src/gfx/texture.h b/src/gfx/texture.h index f1bdf61..6f319e1 100644 --- a/src/gfx/texture.h +++ b/src/gfx/texture.h @@ -23,6 +23,8 @@ struct Texture { GLenum type; }; +void textures_init(void); + void texture_init(struct Texture *texture, GLenum unit, GLenum type); void texture_init_from_image(struct Texture *texture, unsigned char *buffer, unsigned int len, GLenum unit, GLenum type); diff --git a/src/main.c b/src/main.c index a054cd7..356c639 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Wojciech Graj + * Copyright (c) 2022-2023 Wojciech Graj * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -33,10 +33,7 @@ int main(int argc, char *argv[]) render_init(); phys_init(); entity_init(); - -#ifndef NO_SATELLITE thread_dispatch(THRD_SATELLITES_GET, NULL); -#endif gtk_main(); diff --git a/src/mainloop.c b/src/mainloop.c new file mode 100644 index 0000000..4835f9f --- /dev/null +++ b/src/mainloop.c @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 Wojciech Graj + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + **/ + +#include "mainloop.h" + +#include "info.h" +#include "perf.h" +#include "render.h" +#include "satellite.h" +#include "thread.h" +#include "toolbar.h" + +void mainloop(void) +{ + thread_dispatch(THRD_PHYS, NULL); + satellites_tic(); + render_process(); + toolbar_tic(); + info_tic(); + perf_tic(); + thread_join(THRD_PHYS); + satellites_tic_sync(); + thread_join_if_finished(THRD_SATELLITES_GET); +} diff --git a/src/mainloop.h b/src/mainloop.h new file mode 100644 index 0000000..f9f7a8b --- /dev/null +++ b/src/mainloop.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2023 Wojciech Graj + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + **/ + +#ifndef __MAINLOOP_H__ +#define __MAINLOOP_H__ + +void mainloop(void); + +#endif /* __MAINLOOP_H__ */ diff --git a/src/phys/phys.c b/src/phys/phys.c index 703735d..43f1eed 100644 --- a/src/phys/phys.c +++ b/src/phys/phys.c @@ -85,12 +85,10 @@ void phys_init(void) phys_phys_sync(); } -static void phys(void) +void phys(void) { phys_phys(); -#ifndef NO_SATELLITE satellites_phys(); -#endif } void *phys_thrd(void *arguments) @@ -117,7 +115,5 @@ void phys_phys_sync(void) void phys_sync(void) { phys_phys_sync(); -#ifndef NO_SATELLITE satellites_phys_sync(); -#endif } diff --git a/src/ui/toolbar.c b/src/ui/toolbar.c index 085f4fc..5a9bbe3 100644 --- a/src/ui/toolbar.c +++ b/src/ui/toolbar.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Wojciech Graj + * Copyright (c) 2022-2023 Wojciech Graj * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -70,7 +70,7 @@ void on_accelerate_clicked(GtkToolButton *toolbutton, gpointer user_data) e_timescale *= 1.05f; } -static void on_zoom_out_clicked(GtkToolButton *toolbutton, gpointer user_data) +void on_zoom_out_clicked(GtkToolButton *toolbutton, gpointer user_data) { (void)toolbutton; (void)user_data; @@ -78,7 +78,7 @@ static void on_zoom_out_clicked(GtkToolButton *toolbutton, gpointer user_data) camera_zoom(&e_camera, -ZOOM_DIST); } -static void on_zoom_in_clicked(GtkToolButton *toolbutton, gpointer user_data) +void on_zoom_in_clicked(GtkToolButton *toolbutton, gpointer user_data) { (void)toolbutton; (void)user_data; diff --git a/src/ui/ui.c b/src/ui/ui.c index 9d9ffc5..3364c50 100644 --- a/src/ui/ui.c +++ b/src/ui/ui.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Wojciech Graj + * Copyright (c) 2022-2023 Wojciech Graj * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -32,8 +32,6 @@ extern const unsigned char res_ui_ui_glade[]; extern const unsigned int res_ui_ui_glade_len; -const gchar *FILENAME_GUI = "res/ui/ui.glade"; - GtkWindow *e_window_main; static void on_window_main_destroy(GtkWidget *widget, gpointer user_data); @@ -65,7 +63,7 @@ void ui_init(int argc, char ***argv) { gtk_init(&argc, argv); - GtkBuilder *builder = gtk_builder_new_from_string(res_ui_ui_glade, res_ui_ui_glade_len); + GtkBuilder *builder = gtk_builder_new_from_string((const gchar *)res_ui_ui_glade, res_ui_ui_glade_len); gtk_builder_add_callback_symbols(builder, "on_window_main_destroy", G_CALLBACK(on_window_main_destroy), diff --git a/src/util/download.c b/src/util/download.c index b6d8475..a87517c 100644 --- a/src/util/download.c +++ b/src/util/download.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Wojciech Graj + * Copyright (c) 2022-2023 Wojciech Graj * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -18,7 +18,7 @@ static size_t write_memory_callback(void *contents, size_t size, size_t nmemb, void *userp); -static size_t write_memory_callback(void *contents, size_t size, size_t nmemb, void *userp) +size_t write_memory_callback(void *contents, size_t size, size_t nmemb, void *userp) { size_t realsize = size * nmemb; struct DLHandle *mem = (struct DLHandle *)userp; diff --git a/src/util/icosphere.c b/src/util/icosphere.c index dd78e87..3d57c8a 100644 --- a/src/util/icosphere.c +++ b/src/util/icosphere.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Wojciech Graj + * Copyright (c) 2022-2023 Wojciech Graj * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -85,33 +85,33 @@ static void fix_uv_wrapping(vec3 *verts, guint32 *faces, vec2 *uv, size_t *vert_ static void separate_pole_vertex(unsigned idx, guint32 *trig, gboolean *fnd, vec3 *verts, vec2 *uv, size_t *vert_cnt); static void separate_pole_vertices(vec3 *verts, guint32 *faces, vec2 *uv, size_t *vert_cnt, size_t n_faces); -static guint64 edge_hash(const void *item, guint64 seed0, guint64 seed1) +guint64 edge_hash(const void *item, guint64 seed0, guint64 seed1) { (void)seed0; (void)seed1; return ((struct Edge *)item)->edge.hash; } -static int edge_compare(const void *a, const void *b, void *udata) +int edge_compare(const void *a, const void *b, void *udata) { (void)udata; return ((struct Edge *)a)->edge.hash - ((struct Edge *)b)->edge.hash; } -static guint64 vertex_hash(const void *item, guint64 seed0, guint64 seed1) +guint64 vertex_hash(const void *item, guint64 seed0, guint64 seed1) { (void)seed0; (void)seed1; return ((struct Vertex *)item)->orig; } -static int vertex_compare(const void *a, const void *b, void *udata) +int vertex_compare(const void *a, const void *b, void *udata) { (void)udata; return (((struct Vertex *)a)->orig) - (((struct Vertex *)b)->orig); } -static void subdivide(guint32 *face, guint32 *next_faces, vec3 *verts, size_t *vert_cnt, struct hashmap *map) +void subdivide(guint32 *face, guint32 *next_faces, vec3 *verts, size_t *vert_cnt, struct hashmap *map) { /* Generate vertices */ static const unsigned face_idxs[3][2] = { @@ -209,7 +209,7 @@ void icosphere_generate(const unsigned n_sub, vec3 **verts, guint32 **faces, vec separate_pole_vertices(*verts, *faces, *uv, &vert_cnt, *n_faces); } -static void fix_uv_wrapping(vec3 *verts, guint32 *faces, vec2 *uv, size_t *vert_cnt, size_t n_faces) +void fix_uv_wrapping(vec3 *verts, guint32 *faces, vec2 *uv, size_t *vert_cnt, size_t n_faces) { struct hashmap *map = hashmap_new(sizeof(struct Vertex), 10, 0, 0, vertex_hash, vertex_compare, NULL, NULL); @@ -245,7 +245,7 @@ static void fix_uv_wrapping(vec3 *verts, guint32 *faces, vec2 *uv, size_t *vert_ hashmap_free(map); } -static void separate_pole_vertex(unsigned idx, guint32 *trig, gboolean *fnd, vec3 *verts, vec2 *uv, size_t *vert_cnt) +void separate_pole_vertex(unsigned idx, guint32 *trig, gboolean *fnd, vec3 *verts, vec2 *uv, size_t *vert_cnt) { float u_avg; switch (idx) { @@ -275,7 +275,7 @@ static void separate_pole_vertex(unsigned idx, guint32 *trig, gboolean *fnd, vec } } -static void separate_pole_vertices(vec3 *verts, guint32 *faces, vec2 *uv, size_t *vert_cnt, size_t n_faces) +void separate_pole_vertices(vec3 *verts, guint32 *faces, vec2 *uv, size_t *vert_cnt, size_t n_faces) { size_t i; guint32 north, south; diff --git a/src/util/version.h b/src/util/version.h index 37fdfe0..087ef26 100644 --- a/src/util/version.h +++ b/src/util/version.h @@ -31,7 +31,7 @@ XSTR(VERSION_MAJOR) \ "." XSTR(VERSION_MINOR) "." XSTR(VERSION_PATCH) DEBUG_STRING -#define ABOUT_STRING "OrbVis " VERSION_STRING "\nCopyright (c) 2022 Wojciech Graj" \ +#define ABOUT_STRING "OrbVis " VERSION_STRING "\nCopyright (c) 2022-2023 Wojciech Graj" \ "\nLicense GPLv2+: GNU GPL version 2 or later." #endif /* __VERSION_H__ */