diff options
-rw-r--r-- | match.c | 51 | ||||
-rw-r--r-- | match.h | 4 | ||||
-rw-r--r-- | web/static/sw.js | 2 |
3 files changed, 36 insertions, 21 deletions
@@ -11,7 +11,7 @@ struct leg *leg_init(int pts) l->start = l->rem = pts; l->size_visits = 16; - l->visits = calloc(l->size_visits, sizeof(*(l->visits))); + l->visits = calloc(l->size_visits, sizeof(*l->visits)); return l; } @@ -31,19 +31,43 @@ void leg_free(struct leg *l) void leg_grow_visits(struct leg *l) { - size_t bytes = l->size_visits * sizeof(*(l->visits)); + size_t bytes = l->size_visits * sizeof(*l->visits); l->size_visits *= 2; l->visits = realloc(l->visits, 2 * bytes); memset((char *)l->visits + bytes, 0, bytes); } +void leg_undo_visit(struct leg *l) +{ + l->rem += l->visits[--l->n_visits].points; + ++l->undone_visits; +} + +struct visit *leg_redo_visit(struct leg *l) +{ + struct visit *v = l->visits + l->n_visits++; + l->rem = v->rem; + --l->undone_visits; + return v; +} + +static void leg_clear_first_undone(struct leg *l) +{ + free(l->visits[l->n_visits].darts); + free(l->visits[l->n_visits].ccoords); + memset(l->visits + l->n_visits, 0, sizeof(*l->visits)); + --l->undone_visits; +} + struct visit *leg_comp_visit(struct leg *l, bool redo_undone) { - // FIXME redo_undone=false should free next undone if (redo_undone && l->undone_visits) - leg_redo_visit(l); - else - comp_visit(l); + return leg_redo_visit(l); + + if (l->undone_visits) + leg_clear_first_undone(l); + + comp_visit(l); struct visit *v = l->visits + l->n_visits - 1; return v; @@ -54,6 +78,9 @@ struct visit *leg_pts_visit(struct leg *l, int pts) if (!is_points_valid(pts, l->rem)) return NULL; + if (l->undone_visits) + leg_clear_first_undone(l); + if (l->n_visits == l->size_visits) leg_grow_visits(l); struct visit *v = l->visits + l->n_visits++; @@ -64,18 +91,6 @@ struct visit *leg_pts_visit(struct leg *l, int pts) return v; } -void leg_undo_visit(struct leg *l) -{ - l->rem += l->visits[--l->n_visits].points; - ++l->undone_visits; -} - -void leg_redo_visit(struct leg *l) -{ - l->rem = l->visits[l->n_visits++].rem; - --l->undone_visits; -} - struct match *match_init() { struct match *m = calloc(1, sizeof(*m)); @@ -41,10 +41,10 @@ struct leg *leg_init(int pts); void leg_free(struct leg *l); void leg_grow_visits(struct leg *l); +void leg_undo_visit(struct leg *l); +struct visit *leg_redo_visit(struct leg *l); struct visit *leg_comp_visit(struct leg *l, bool redo_undone); struct visit *leg_pts_visit(struct leg *l, int pts); -void leg_undo_visit(struct leg *l); -void leg_redo_visit(struct leg *l); struct match *match_init(); void match_free(struct match *m); diff --git a/web/static/sw.js b/web/static/sw.js index 5760aaf..f09f5fc 100644 --- a/web/static/sw.js +++ b/web/static/sw.js @@ -1,5 +1,5 @@ const CACHE_PREFIX = 'dartboat-' -const CACHE_VERSION = '23'; +const CACHE_VERSION = '24'; const CACHE_NAME = `${CACHE_PREFIX}${CACHE_VERSION}`; const CACHE_FILES = [ |