p->r = get_random() % 256;
p->g = get_random() % 256;
p->b = get_random() % 256;
+
+ LIST_HEAD_INIT(p->list);
}
void draw_planet(SDL_Surface *screen, struct planet *p)
#include <SDL.h>
#include "vector.h"
+#include "list.h"
+#include "utils.h"
struct planet {
struct vector speed;
struct vector pos;
+ struct list_head list;
double mass;
float size;
unsigned char r, g, b;
};
+#define list_to_planet(planet) container_of((planet), struct planet, list)
+
void init_planet(const SDL_Surface *screen, struct planet *p);
void draw_planet(SDL_Surface *screen, struct planet *p);
void gravitize_planets(struct planet *a, struct planet *b, const double time);
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
+/**
+ * container_of - cast a member of a structure out to the containing structure
+ * @ptr: the pointer to the member.
+ * @type: the type of the container struct this is embedded in.
+ * @member: the name of the member within the struct.
+ *
+ */
+#define container_of(ptr, type, member) ({ \
+ const typeof( ((type *)0)->member ) *__mptr = (ptr); \
+ (type *)( (char *)__mptr - offsetof(type,member) );})
+
#endif