cepheid

An Aurora 4X clone
Log | Files | Refs | README

commit e647526f7b8a4f77664ad9b239b7ce2b20fd2a6b
parent 45af01adb87a528cd1e741ddb42ca81793eadf06
Author: hhvn <dev@hhvn.uk>
Date:   Wed, 30 Nov 2022 23:39:03 +0000

Add polar coordinates to bdb interface

Diffstat:
Msrc/bdb.c | 12++++++++++++
Mtests/bdb.test | 26+++++++++++++++++---------
2 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/src/bdb.c b/src/bdb.c @@ -18,6 +18,7 @@ * 'i' - int * 'f' - float * 'v' - vector + * 'p' - polar coordinate * 'S' - array of strings (will allocate memory for elements on get) * 'I' - array of ints * 'F' - array of floats @@ -39,6 +40,7 @@ _bdbset(char *dir, char *group, ...) { int i; float f; Vector v; + Polar p; char **S; int *I; float *F; @@ -71,6 +73,10 @@ _bdbset(char *dir, char *group, ...) { v.v = va_arg(ap, Vector); dbsetf(dir, group, key, "%f\t%f", v.v.x, v.v.y); break; + case 'p': + v.p = va_arg(ap, Polar); + dbsetf(dir, group, key, "%f\t%f", v.p.r, v.p.theta); + break; case 'S': v.S = va_arg(ap, char **); n = va_arg(ap, int); @@ -121,6 +127,7 @@ _bdbget(char *dir, char *group, ...) { int *i; float *f; Vector *v; + Polar *p; char **S; int *I; float *F; @@ -157,6 +164,11 @@ _bdbget(char *dir, char *group, ...) { dbgetf(dir, group, key, "%f\t%f", &(*v.v).x, &(*v.v).y); break; + case 'p': + v.p = va_arg(ap, Polar *); + dbgetf(dir, group, key, "%f\t%f", + &(*v.p).r, &(*v.p).theta); + break; case 'S': v.S = va_arg(ap, char **); n = va_arg(ap, int); diff --git a/tests/bdb.test b/tests/bdb.test @@ -8,13 +8,15 @@ static unsigned char output[] = { 0x6e, 0x74, 0x09, 0x32, 0x0a, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x09, 0x33, 0x2e, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x0a, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x09, 0x34, 0x2e, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x09, - 0x35, 0x2e, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x0a, 0x41, 0x73, 0x74, - 0x72, 0x69, 0x6e, 0x67, 0x09, 0x73, 0x69, 0x78, 0x09, 0x73, 0x65, 0x76, - 0x65, 0x6e, 0x0a, 0x41, 0x69, 0x6e, 0x74, 0x09, 0x38, 0x09, 0x39, 0x09, - 0x31, 0x30, 0x0a, 0x41, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x09, 0x31, 0x31, - 0x2e, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x09, 0x31, 0x32, 0x2e, 0x30, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x09, 0x30, 0x2e, 0x30, 0x30, 0x30, 0x30, - 0x30, 0x30, 0x0a, 0x00 + 0x35, 0x2e, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x0a, 0x70, 0x6f, 0x6c, + 0x61, 0x72, 0x09, 0x32, 0x38, 0x2e, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x09, 0x39, 0x30, 0x2e, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x0a, 0x41, + 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x09, 0x73, 0x69, 0x78, 0x09, 0x73, + 0x65, 0x76, 0x65, 0x6e, 0x0a, 0x41, 0x69, 0x6e, 0x74, 0x09, 0x38, 0x09, + 0x39, 0x09, 0x31, 0x30, 0x0a, 0x41, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x09, + 0x31, 0x31, 0x2e, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x09, 0x31, 0x32, + 0x2e, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x09, 0x30, 0x2e, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x0a, 0x00 }; %{ @@ -28,6 +30,7 @@ static unsigned char output[] = { int i = 2; float f = 3; Vector v = {4, 5}; + Polar p = {28, 90}; char *S[3] = {"six", "seven", NULL}; int I[3] = {8, 9, 10}; float F[4] = {11, 12, 0, 0}; @@ -39,6 +42,7 @@ static unsigned char output[] = { 'i', "int", i, 'f', "float", f, 'v', "vector", v, + 'p', "polar", p, 'S', "Astring", S, 2, 'I', "Aint", I, 3, 'F', "Afloat", F, 3); @@ -58,6 +62,7 @@ static unsigned char output[] = { SET(i); SET(f); SET(v); + SET(p); #undef SET #define SET(var) memset(var, 57, sizeof(var)); SET(S); @@ -69,6 +74,7 @@ static unsigned char output[] = { 'i', "int", &i, 'f', "float", &f, 'v', "vector", &v, + 'p', "polar", &p, 'S', "Astring", S, 3, 'I', "Aint", I, 3, 'F', "Afloat", F, 4); @@ -76,8 +82,6 @@ static unsigned char output[] = { A(streq(s, "one")); A(i == 2); A(f == 3); - A(v.x == 4); - A(v.y == 5); A(streq(S[0], "six")); A(streq(S[1], "seven")); A(S[2] == NULL); @@ -87,6 +91,10 @@ static unsigned char output[] = { #undef A #define A(x, y) ck_assert_float_eq_tol(x, y, 0.1) + A(v.x, 4.0); + A(v.y, 5.0); + A(p.r, 28.0); + A(p.theta, 90.0); A(F[0], 11.0); A(F[1], 12.0); A(F[2], 0.0);