separate state-update function for profiling.

This commit is contained in:
Antonio Carzaniga 2019-08-19 10:45:55 +02:00
parent a71096699b
commit a8e616a608
2 changed files with 16 additions and 8 deletions

View File

@ -2,7 +2,8 @@ GTK_PACKAGES=gdk-pixbuf-2.0 gtk+-2.0
GTK_CFLAGS=$(shell pkg-config --cflags $(GTK_PACKAGES)) GTK_CFLAGS=$(shell pkg-config --cflags $(GTK_PACKAGES))
GTK_LIBS=$(shell pkg-config --libs $(GTK_PACKAGES)) GTK_LIBS=$(shell pkg-config --libs $(GTK_PACKAGES))
CFLAGS=-Wall -g -O2 $(GTK_CFLAGS) # PROFILING_CFLAGS=-pg
CFLAGS=-Wall -g -O2 $(PROFILING_CFLAGS) $(GTK_CFLAGS)
LIBS=$(GTK_LIBS) LIBS=$(GTK_LIBS)

19
balls.c
View File

@ -97,7 +97,7 @@ static void ball_collision (struct ball * p, struct ball * q) {
} }
} }
static void ball_update_state (struct ball * p) { void ball_update_state (struct ball * p) {
p->x += delta*p->v_x + delta*delta*g_x/2.0; p->x += delta*p->v_x + delta*delta*g_x/2.0;
p->v_x += delta*g_x; p->v_x += delta*g_x;
@ -129,14 +129,21 @@ static void ball_update_state (struct ball * p) {
} }
} }
static void update_state () { void movement_and_borders () {
if (collisions) { for(int i = 0; i < n_balls; ++i)
ball_update_state(balls + i);
}
void check_collisions () {
for(int i = 0; i < n_balls; ++i) for(int i = 0; i < n_balls; ++i)
for(int j = i + 1; j < n_balls; ++j) for(int j = i + 1; j < n_balls; ++j)
ball_collision(balls + i, balls + j); ball_collision(balls + i, balls + j);
} }
for(int i = 0; i < n_balls; ++i)
ball_update_state(balls + i); static void update_state () {
if (collisions)
check_collisions();
movement_and_borders();
} }
/* Graphics System /* Graphics System