From 9edcd68e7ddcdc4deca8c07b5b1c3c59cef13255 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Wed, 25 May 2022 00:57:32 -0700 Subject: pregenerate segment names to avoid constant mallocs --- board.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'board.h') diff --git a/board.h b/board.h index e5ffb24..4348070 100644 --- a/board.h +++ b/board.h @@ -14,6 +14,14 @@ #define TREBLE_INSIDE_WIDTH 8.0 #define SEGMENT_MAX_LEN 5 + +#define FOREACH_SECTOR(M) \ + M(1) M(2) M(3) M(4) M(5) M(6) M(7) M(8) M(9) M(10) \ + M(11) M(12) M(13) M(14) M(15) M(16) M(17) M(18) M(19) M(20) +#define GEN_SECTOR_STR(X) #X, +#define GEN_SECTOR_STR_D(X) "D" #X, +#define GEN_SECTOR_STR_T(X) "T" #X, + // distance from centre to apex of outer wire // must be ordered outwards from centre #define FOREACH_RING(M) \ @@ -26,7 +34,7 @@ WIRE_WIDTH/2) \ M(DOUBLE, DOUBLE_OUTER_EDGE - WIRE_WIDTH/2) #define GEN_RING_ENUM(X, D) R_ ## X, -#define GEN_RING_STRING(X, D) #X, +#define GEN_RING_STR(X, D) #X, #define GEN_RING_OUTER_DIST(X, D) D, enum ring { FOREACH_RING(GEN_RING_ENUM) @@ -52,7 +60,7 @@ struct pcoords { }; struct segment get_segment(struct pcoords c); -char *segment_name(struct segment seg); +const char *segment_name(struct segment seg); int segment_points(struct segment seg); bool segment_is_double(struct segment seg); struct pcoords segment_centre(struct segment seg); -- cgit v1.2.3-70-g09d2