]> git.itanic.dy.fi Git - sdl-planets/blob - planet.h
planet: Add tree statistics
[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 vector pos;
15         struct list_head list;
16         struct quadtree tree;
17         double mass;
18         float radius;
19         unsigned char r, g, b;
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 };
25
26 struct planet_search_iterator {
27         struct quadtree_iterator qt_iterator;
28         struct vector limit[2];
29         struct camera *cam;
30         SDL_Surface *screen;
31 };
32
33 #define list_to_planet(list_head) container_of((list_head), struct planet, list)
34
35 #define tree_to_planet(qt) container_of((qt), struct planet, tree)
36
37 #define qt_itr_to_planet_itr(qt)                                        \
38         container_of((qt), struct planet_search_iterator, qt_iterator)
39
40 void init_planet(struct planet *p);
41 void create_planets(struct planet *p, int num, double total_mass,
42                     double radius);
43 void draw_planet(SDL_Surface *screen, struct planet *p, const struct camera *);
44 int gravitize_planets(struct planet *a, struct planet *b, const double time);
45 struct planet *merge_planets(struct planet *a, struct planet *b);
46 struct planet *move_planet(struct planet *p, const double time);
47 void print_planet(const struct planet *p);
48
49 int planet_spatial_compare(struct quadtree *a, struct quadtree *b);
50 int planet_search_rectangular(struct quadtree *node,
51                               struct quadtree_iterator *itr);
52 void planet_draw_iterator(struct quadtree *node, struct quadtree_iterator *it);
53
54 #endif