From d1f083e05e4072dc571c02780eca49fd576a19bf Mon Sep 17 00:00:00 2001 From: Ivan Mahonin Date: Mar 14 2020 16:21:46 +0000 Subject: fix bugs2 --- diff --git a/helianthus/SConstruct b/helianthus/SConstruct index e8e3231..d0e63b6 100644 --- a/helianthus/SConstruct +++ b/helianthus/SConstruct @@ -23,6 +23,7 @@ sources = [ 'common.c', 'drawing.c', 'group.c', + 'test.c', 'sprite.c', 'world.c', 'main.c' ] diff --git a/helianthus/array.c b/helianthus/array.c index 6e87b14..d6b56d2 100644 --- a/helianthus/array.c +++ b/helianthus/array.c @@ -84,9 +84,13 @@ HeliPair* heliStringmapFind(HeliArray *a, const char *k, int *gtOrEqIndex) { return cmp ? NULL : &a->items[i0]; } if (i1 > i0) cmp = strcmp((char*)a->items[i1].key, k); - if (cmp <= 0) { + if (cmp < 0) { if (gtOrEqIndex) *gtOrEqIndex = a->count; - return cmp ? NULL : &a->items[i1]; + return NULL; + } + if (cmp == 0) { + if (gtOrEqIndex) *gtOrEqIndex = i1; + return &a->items[i1]; } while(i0 + 1 < i1) { diff --git a/helianthus/main.c b/helianthus/main.c index b0c0a49..0749ec6 100644 --- a/helianthus/main.c +++ b/helianthus/main.c @@ -8,15 +8,12 @@ Sprite ball, brick1, brick2; void init() { ball = createSpriteEx(200, 200, 64, 64); spriteSetAnimation(ball, "data/sprites/breadball.png"); - spriteSetDebug(ball, TRUE); brick1 = createSpriteEx(200-32, 200+64, 64, 64); spriteSetAnimation(brick1, "data/sprites/bricks.png"); - spriteSetDebug(brick1, TRUE); brick2 = createSpriteEx(200+32, 200+64, 64, 64); spriteSetAnimation(brick2, "data/sprites/bricks.png"); - spriteSetDebug(brick2, TRUE); } void draw() { @@ -32,6 +29,8 @@ void draw() { if (keyDown("up")) spriteSetY(ball, y - speed*dt); if (keyDown("down")) spriteSetY(ball, y + speed*dt); + spriteSetSpeedAndDirection(ball, speed, spriteGetRotation(ball)); + drawSprites(); } diff --git a/helianthus/private.h b/helianthus/private.h index 9949c2d..bd90baf 100644 --- a/helianthus/private.h +++ b/helianthus/private.h @@ -104,3 +104,9 @@ void heliSpriteFinish(); void heliDrawingPrepareFrame(); void heliDrawingFinish(); + + +// test + +void heliDoTests(); + diff --git a/helianthus/sprite.c b/helianthus/sprite.c index 57fb407..a6aaf81 100644 --- a/helianthus/sprite.c +++ b/helianthus/sprite.c @@ -331,15 +331,16 @@ static void drawSprite(cairo_t *cr, Sprite s) { } // tint + #warning "TODO: tint was not implemented yet" cairo_save(cr); cairo_set_source_rgba(cr, s->tintColor[0], s->tintColor[1], s->tintColor[2], s->tintColor[3]); - cairo_set_operator(cr, CAIRO_OPERATOR_MULTIPLY); + cairo_set_operator(cr, CAIRO_OPERATOR_OUT); cairo_move_to(cr, -hw, -hh); cairo_line_to(cr, hw, -hh); cairo_line_to(cr, hw, hh); cairo_line_to(cr, -hw, hh); cairo_close_path(cr); - cairo_fill(cr); + //cairo_fill(cr); cairo_restore(cr); cairo_pop_group_to_source(cr); diff --git a/helianthus/test.c b/helianthus/test.c new file mode 100644 index 0000000..713f2cd --- /dev/null +++ b/helianthus/test.c @@ -0,0 +1,60 @@ + +#include "private.h" + +//#define HELI_DO_TESTS + +#ifndef HELI_DO_TESTS +void heliDoTests() { } +#else + + +static printStringset(HeliArray *a) { + for(int i = 0; i < a->count; ++i) + printf(" %s\n", (const char*)a->items[i].key); +} + +static void testStringSet() { + printf("-- testStringSet\n"); + + static char *strings[] = { + "hello", + "apple", + "orange", + "pineapple", + "potato", + "carrot", + "grape", + "cucumber" + }; + + HeliArray a = {}; + for(int i = 0; i < (int)(sizeof(strings)/sizeof(*strings)); ++i) + heliStringmapAdd(&a, strings[i], NULL, NULL); + + printf(" fill:\n"); + printStringset(&a); + + printf("\n -remove %s:\n", "hello"); + heliStringmapRemove(&a, "hello"); + printStringset(&a); + + printf("\n -remove %s:\n", "apple"); + heliStringmapRemove(&a, "apple"); + printStringset(&a); + + printf("\n -remove %s:\n", "potato"); + heliStringmapRemove(&a, "potato"); + printStringset(&a); + + heliArrayDestroy(&a); + + printf("-- end\n"); +} + +void heliDoTests() { + printf("---- doTests\n"); + testStringSet(); + printf("---- end\n"); +} + +#endif diff --git a/helianthus/world.c b/helianthus/world.c index 6a79902..df20ecf 100644 --- a/helianthus/world.c +++ b/helianthus/world.c @@ -168,6 +168,8 @@ static gboolean draw(GtkWidget *widget G_GNUC_UNUSED, cairo_t *cr, gpointer data guint64 newTime = g_get_monotonic_time(); heliCairo = cr; + if (frameCount == 0) heliDoTests(); + double dt = 1/frameRate; guint64 timeStep = (guint64)round(dt*1e6); while(currentTime < newTime) { @@ -200,7 +202,6 @@ static gboolean handleEvent(GtkWidget *widget G_GNUC_UNUSED, GdkEvent *event, gp heliLowercase(keyname); heliStringmapAdd(&keysPressed, keyname, NULL, NULL); heliStringmapAdd(&keysPressedInFrame, keyname, NULL, NULL); - //printf("key pressed: %s\n", keyname); free(keyname); return TRUE; case GDK_KEY_RELEASE: