]> git.itanic.dy.fi Git - sdl-planets/blob - planet.h
Merge branch 'master' into dirty_work
[sdl-planets] / planet.h
1 #ifndef _PLANET_H
2 #define _PLANET_H
3
4 #include <SDL.h>
5
6 #include "vector.h"
7 #include "list.h"
8 #include "utils.h"
9 #include "camera.h"
10 #include "quadtree.h"
11
12 struct planet {
13         struct vector speed;
14         struct list_head list;
15         struct quadtree tree;
16         double mass;
17         float radius;
18         unsigned char r, g, b;
19         int to_be_deleted;
20
21         /* info about the planets in sub branches */
22         float tree_area;        /* total area occupied by the tree */
23         double tree_mass;       /* total mass occupied by the tree */
24         /* the amount of speed the entire tree has gained */
25         struct vector tree_speed;
26 };
27
28 struct planet_search_iterator {
29         struct quadtree_iterator qt_iterator;
30         struct vector limit[2];
31         struct camera *cam;
32         SDL_Surface *screen;
33         int modify;
34 };
35
36 extern int gravitations, optimizations;
37
38 #define list_to_planet(list_head) container_of((list_head), struct planet, list)
39
40 #define tree_to_planet(qt) container_of((qt), struct planet, tree)
41
42 #define qt_itr_to_planet_itr(qt)                                        \
43         container_of((qt), struct planet_search_iterator, qt_iterator)
44
45 void init_planet(struct planet *p);
46 void create_planets(struct planet *p, int num, double total_mass,
47                     double radius);
48 void draw_planet(SDL_Surface *screen, const struct planet *p,
49                  const struct camera *);
50 void gravitize_planet_tree(struct planet *p, double time);
51 struct planet *merge_planets(struct planet *a, struct planet *b);
52 struct planet *move_planet(struct planet *p, const double time);
53 int propagate_tree_movement(struct planet *p);
54 void print_planet(const struct planet *p);
55 struct planet *prune_planet_tree(struct planet *p);
56
57 int planet_spatial_compare(struct quadtree *a, struct quadtree *b);
58 int planet_search_rectangular(struct quadtree *node,
59                               struct quadtree_iterator *itr);
60 void planet_draw_iterator(struct quadtree *node, struct quadtree_iterator *it);
61
62 #endif