separate state-update function for profiling.
This commit is contained in:
parent
a71096699b
commit
a8e616a608
3
Makefile
3
Makefile
@ -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
19
balls.c
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user