commit 4969daddd2c6a5994c0afec977b172e61c732e7c
parent 1fda0881eb5d297cb202289501b27734f7151ac6
Author: amin <dev@aminmesbah.com>
Date: Sun, 30 Jul 2017 05:26:51 +0000
Clean up and minimize #includes.
FossilOrigin-Name: 7843f743a006cad42ca3ff65f38379cf269c2a3ed2078cd13bc4d05aede24fab
Diffstat:
8 files changed, 27 insertions(+), 28 deletions(-)
diff --git a/src/barnes_hut.c b/src/barnes_hut.c
@@ -1,5 +1,10 @@
#include "barnes_hut.h"
+#include "star.h"
+
+#include "math.h"
+#include "stdlib.h"
+
struct Cell *cell_init(float center_x, float center_y, float distance_x, float distance_y)
{
diff --git a/src/barnes_hut.h b/src/barnes_hut.h
@@ -6,14 +6,14 @@
#define BARNES_HUT_H
#include <stdbool.h>
-// TODO: Remove this.
-#include "star.h"
// TODO: Limit tree depth
#ifndef THETA
#define THETA 0.5f
#endif
+struct Star;
+
struct Cell
{
float center_x;
diff --git a/src/platform_sdl.c b/src/platform_sdl.c
@@ -1,25 +1,13 @@
+#include "platform_sdl.h"
+
#include "star_garden.h"
-#include <inttypes.h>
-#include <math.h>
-#include <SDL.h>
#include <stdbool.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-
-#include "platform_sdl.h"
#ifndef MAP_ANONYMOUS
#define MAP_ANONYMOUS MAP_ANON
#endif
-#ifndef M_PI
-#define M_PI (3.14159265358979323846264338327950288)
-#endif
-
extern bool PAUSED;
extern bool BRUTE_FORCE;
extern bool RENDER_GRID;
diff --git a/src/platform_sdl.h b/src/platform_sdl.h
@@ -1,6 +1,6 @@
#ifndef PLATFORM_SDL_H
-#include <SDL.h>
+#include "SDL.h"
struct SDLOffscreenBuffer
{
diff --git a/src/star.c b/src/star.c
@@ -1,5 +1,9 @@
#include "star.h"
+#include <math.h>
+#include <stdlib.h>
+
+
// TODO: Test whether making this function return a struct (rather than a
// struct pointer) makes a significant performance difference.
struct Vec2d *vec2d_add(float angle1, float length1, float angle2, float length2)
@@ -13,6 +17,7 @@ struct Vec2d *vec2d_add(float angle1, float length1, float angle2, float length2
return new_vec;
}
+
void star_accelerate(struct Star *s, float angle, float acceleration)
{
struct Vec2d *new_vec = vec2d_add(s->angle, s->speed, angle, acceleration);
@@ -21,11 +26,13 @@ void star_accelerate(struct Star *s, float angle, float acceleration)
free(new_vec);
}
+
float star_calc_size(float mass)
{
return 0.5 * (powf(mass, 0.5));
}
+
void star_attract(struct Star *s1, struct Star *s2)
{
float dx = s1->x - s2->x;
@@ -42,6 +49,7 @@ void star_attract(struct Star *s1, struct Star *s2)
}
}
+
void star_attract_to_mass(struct Star *star, float mass, float mass_x, float mass_y)
{
float dx = star->x - mass_x;
diff --git a/src/star.h b/src/star.h
@@ -1,9 +1,7 @@
#ifndef STAR_H
#define STAR_H
-#include <math.h>
#include <stdint.h>
-#include <stdlib.h>
#ifndef M_PI
#define M_PI (3.14159265358979323846264338327950288)
diff --git a/src/star_garden.c b/src/star_garden.c
@@ -1,5 +1,7 @@
#include "star_garden.h"
+#include <stdbool.h>
+
bool PAUSED = false;
bool BRUTE_FORCE = false;
bool RENDER_GRID = false;
diff --git a/src/star_garden.h b/src/star_garden.h
@@ -1,17 +1,11 @@
#ifndef STAR_GARDEN_H
-#include <inttypes.h>
+#include "barnes_hut.h"
+#include "star.h"
+
#include <math.h>
-#include <SDL.h>
-#include <stdbool.h>
-#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-
-#include "star.h"
-#include "barnes_hut.h"
#define FULLSCREEN
#define RESPAWN_STARS
@@ -30,6 +24,10 @@
#define UPDATES_PER_SECOND 120
#define MS_PER_UPDATE (SECOND / UPDATES_PER_SECOND)
+#ifndef M_PI
+#define M_PI (3.14159265358979323846264338327950288)
+#endif
+
#define COLOR_WHITE 0xFFFFFF
#define COLOR_BLACK 0x000000
#define COLOR_SOL_BG 0x002B36