xlib_playground

Xlib playground for experiments.
Log | Files | Refs

commit c4a76674993d7e0915aa88ace813459c2e966d5a
parent a20b34d8e11f276e4d2c206ad94a383e97881226
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Tue, 10 Jan 2023 14:16:55 +0900

clean

Diffstat:
Mex9/object.c | 28++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/ex9/object.c b/ex9/object.c @@ -9,6 +9,16 @@ static int test_collision_rr(struct Object *, struct Object *); static void rect_next_tick(struct Object *, long); static void rect_handle_collision_mf(struct Object *, struct Object *); +/* + * Pair of two objects with their distance. + * Used by lhandle_collision(); + */ +struct LLD { + struct Object *o0; + struct Object *o1; + float dist; +}; + struct Object * create_object(enum object_type t, uint32_t color, float px, float py, float vx, float vy, float ax, float ay, @@ -220,12 +230,7 @@ olqsortx(struct List *p) lqsort(p, (int (*)(void *, void *))&olcmpx); } -struct LLD { - struct Object *o0; - struct Object *o1; - float dist; -}; -int +static int lldcmpdst(struct LLD *p, struct LLD *q) { if (p->dist < q->dist) @@ -235,7 +240,8 @@ lldcmpdst(struct LLD *p, struct LLD *q) else return 1; } -void + +static void lldprint(struct LLD *p) { printf("{"); @@ -244,6 +250,7 @@ lldprint(struct LLD *p) oprint(p->o1); printf(", %2.0f}", p->dist); } + /* * The order of list o will be changed. */ @@ -254,14 +261,15 @@ lhandle_collision(struct List *p) struct List *stack, *tmp; stack = NULL; for (; p != NULL; p = p->next) { - // if p doesn't have intersection with an item in the stack + // If p doesn't have intersection with an item in the stack + // Checking only against the first object suffices because stack is sorted. if (stack != NULL && ((struct Object *)stack->item)->p.x + ((struct Object *)stack->item)->body.rectangle.w <= ((struct Object *)p->item)->p.x) { - // handle collision among the items in the stack. + // Handle collision among the items in the stack. // LLD: {struct Object *o0, struct Object *o1, float dist} - // sort LLD according to dist. + // Sort LLD according to dist. struct List *lld, *tmplld; struct List *s, *t; lld = NULL;