xlib_playground

Xlib playground for experiments.
Log | Files | Refs

commit 3e95708f12e1d914a256d850d04d630b2b043fb5
parent 84d158fd94f64aa03ec493d0346e23afe6752c99
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Tue, 10 Jan 2023 13:10:14 +0900

Fix bug

Fixed the order of stack in collision handler.

Diffstat:
Mex9/object.c | 21+++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/ex9/object.c b/ex9/object.c @@ -227,22 +227,22 @@ void lhandle_collision(struct List *p) { olqsortx(p); - struct List *stack, *last, *tmp; - stack = last = NULL; + struct List *stack, *tmp; + stack = NULL; for (; p != NULL; p = p->next) { - //printf("last: "); - //lprint(last, (void (*)(void *))&oprint); // if p doesn't have intersection with an item in the stack - if (last != NULL && - ((struct Object *)last->item)->p.x + - ((struct Object *)last->item)->body.rectangle.w <= + 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. struct List *s, *t; - for (s = stack; s != NULL && s->next != NULL; s = s->next) - for (t = s->next; t != NULL; t = t->next) + for (s = stack; s != NULL && s->next != NULL; s = s->next) { + for (t = s->next; t != NULL; t = t->next) { ohandle_collision((struct Object *)s->item, (struct Object *)t->item); + } + } lfree(stack); stack = NULL; } @@ -251,9 +251,6 @@ lhandle_collision(struct List *p) fprintf(stderr, "lhandle_collision: Error. add item to stack\n"); exit(1); } - if (stack == NULL) { - last = tmp; - } stack = tmp; } return;