From ad4d7dca53b359de966e79a7e8b8423a061f48b1 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 14 Oct 2018 11:50:52 +0200 Subject: [PATCH 1/6] use latest clibs, like develop --- clibs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clibs b/clibs index d86c85254..12139c7ce 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit d86c8525489d7f11b7ba13e101bb59ecf160b871 +Subproject commit 12139c7ce25e6731393f863e248ab16aa0578a3a From 4056f08afa3849b7e9d892a49801c6ff8917c0aa Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 14 Oct 2018 14:45:05 +0200 Subject: [PATCH 2/6] Switching to VS2017 compiler has found a bug in pofile.c --- src/util/pofile.c | 4 ++-- tests/runtests.bat | 3 ++- vs2015-build.bat | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/util/pofile.c b/src/util/pofile.c index 8de04364d..e1126ba0e 100644 --- a/src/util/pofile.c +++ b/src/util/pofile.c @@ -77,7 +77,7 @@ int pofile_read(const char *filename, int (*callback)(const char *msgid, const c int err = sscanf(line, "%8s", token); if (err == 1) { char *text = NULL; - size_t size, len = strlen(token); + size_t size = 0, len = strlen(token); line = line + len + 1; if (len == 7 && memcmp(token, "msgctxt", 7) == 0) { @@ -99,7 +99,7 @@ int pofile_read(const char *filename, int (*callback)(const char *msgid, const c msgid[0] = 0; } } - if (text) { + if (size > 0) { line = read_multiline(F, line, text, size); } } diff --git a/tests/runtests.bat b/tests/runtests.bat index 95ac17be4..88afc8d31 100644 --- a/tests/runtests.bat +++ b/tests/runtests.bat @@ -3,7 +3,8 @@ IF EXIST ..\build-vs10 SET BUILD=..\build-vs10\eressea\Debug IF EXIST ..\build-vs11 SET BUILD=..\build-vs11\eressea\Debug IF EXIST ..\build-vs12 SET BUILD=..\build-vs12\eressea\Debug IF EXIST ..\build-vs14 SET BUILD=..\build-vs14\eressea\Debug -REM IF EXIST ..\build-vs15 SET BUILD=..\build-vs15\eressea\Debug +IF EXIST ..\build-vs15 SET BUILD=..\build-vs15\eressea\Debug + SET SERVER=%BUILD%\eressea.exe %BUILD%\test_eressea.exe %SERVER% ..\scripts\run-tests.lua diff --git a/vs2015-build.bat b/vs2015-build.bat index 1ad2c8da2..8d5c276ed 100644 --- a/vs2015-build.bat +++ b/vs2015-build.bat @@ -1,5 +1,7 @@ @ECHO OFF -SET VSVERSION=14 +SET VSVERSION=15 +IF NOT "%1" == "" SET VSVERSION=%1% + SET SRCDIR=%CD% CD .. SET ERESSEA=%CD% From 0f3f7a68b977735f0e1662d02786db879a91e446 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 21 Oct 2018 19:10:20 +0200 Subject: [PATCH 3/6] upgrade clibs --- clibs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clibs b/clibs index 12139c7ce..1e1c947c8 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit 12139c7ce25e6731393f863e248ab16aa0578a3a +Subproject commit 1e1c947c8034f071c6848dcf1c11138733949825 From 38c1dfe26f10e898f55feb545176d61d46d82cf8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 21 Oct 2018 19:22:30 +0200 Subject: [PATCH 4/6] BUG 2503: statistics API, logging monster creation --- src/main.c | 2 ++ src/monsters.c | 4 +++ src/test_eressea.c | 2 ++ src/tests.c | 2 ++ src/util/log.c | 76 +++++++++++++++++++++++++++++++++++++++++++++ src/util/log.h | 6 ++++ src/util/log.test.c | 42 ++++++++++++++++++++++++- 7 files changed, 133 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index bb353fc2f..e9d058b28 100644 --- a/src/main.c +++ b/src/main.c @@ -334,6 +334,8 @@ int main(int argc, char **argv) game_done(); lua_done(L); log_close(); + stats_write(stdout, ""); + stats_close(); if (d) { iniparser_freedict(d); } diff --git a/src/monsters.c b/src/monsters.c index d009f8bda..ab465e133 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -606,6 +606,7 @@ static void recruit_dracoids(unit * dragon, int size) region *r = dragon->region; const struct item *weapon = NULL; unit *un = create_unit(r, f, size, get_race(RC_DRACOID), 0, NULL, NULL); + stats_count("monsters.create.dracoid", 1); fset(un, UFL_ISNEW | UFL_MOVED); @@ -863,6 +864,7 @@ static int nrand(int handle_start, int sub) unit *spawn_seaserpent(region *r, faction *f) { unit *u = create_unit(r, f, 1, get_race(RC_SEASERPENT), 0, NULL, NULL); + stats_count("monsters.create.seaserpent", 1); fset(u, UFL_ISNEW | UFL_MOVED); equip_unit(u, "seed_seaserpent"); return u; @@ -903,6 +905,7 @@ void spawn_dragons(void) else { u = create_unit(r, monsters, nrand(30, 20) + 1, get_race(RC_DRAGON), 0, NULL, NULL); } + stats_count("monsters.create.dragon", 1); fset(u, UFL_ISNEW | UFL_MOVED); equip_unit(u, "seed_dragon"); @@ -963,6 +966,7 @@ void spawn_undead(void) } u = create_unit(r, monsters, undead, rc, 0, NULL, NULL); + stats_count("monsters.create.undead", 1); fset(u, UFL_ISNEW | UFL_MOVED); if ((rc == get_race(RC_SKELETON) || rc == get_race(RC_ZOMBIE)) && rng_int() % 10 < 4) { diff --git a/src/test_eressea.c b/src/test_eressea.c index 5684a8ad4..13a638e3b 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -173,6 +173,8 @@ int RunAllTests(int argc, char *argv[]) fail_count = summary->failCount; CuSuiteDelete(summary); game_done(); + log_close(); + stats_close(); return fail_count; } return 0; diff --git a/src/tests.c b/src/tests.c index 4ee38d195..f8035e129 100644 --- a/src/tests.c +++ b/src/tests.c @@ -229,6 +229,8 @@ static void test_reset(void) { default_locale = 0; calendar_cleanup(); close_orders(); + log_close(); + stats_close(); free_special_directions(); free_locales(); free_spells(); diff --git a/src/util/log.c b/src/util/log.c index 4b29332a8..0a24503e1 100644 --- a/src/util/log.c +++ b/src/util/log.c @@ -15,6 +15,8 @@ without prior permission by the authors of Eressea. #include "unicode.h" #include "strings.h" +#include + #include #include #include @@ -317,3 +319,77 @@ int log_level(log_t * log, int flags) log->flags = flags; return old; } + +static critbit_tree stats = CRITBIT_TREE(); + +int stats_count(const char *stat, int delta) { + size_t len; + char data[128]; + void * match; + if (cb_find_prefix_str(&stats, stat, &match, 1, 0) == 0) { + len = cb_new_kv(stat, strlen(stat), &delta, sizeof(delta), data); + cb_insert(&stats, data, len); + return delta; + } + else { + int *num; + cb_get_kv_ex(match, (void **)&num); + return *num += delta; + } +} + +#if 0 +#define STATS_BATCH 8 +void stats_walk(const char *prefix, void(*callback)(const char *, int, void *), void *udata) { + void *match[STATS_BATCH]; + int n, off = 0; + do { + int i; + n = cb_find_prefix_str(&stats, prefix, match, STATS_BATCH, off); + if (n == 0) { + break; + } + off += n; + for (i = 0; i != n; ++i) { + const void *kv = match[i]; + int *num; + cb_get_kv_ex(kv, &(void *)num); + callback(kv, *num, udata); + } + } while (n == STATS_BATCH); +} +#else + +struct walk_data { + int (*callback)(const char *, int, void *); + void *udata; +}; + +static int walk_cb(void * match, const void * key, size_t keylen, void *udata) { + struct walk_data *data = (struct walk_data *)udata; + int *num; + cb_get_kv_ex(match, (void **)&num); + return data->callback((const char*)match, *num, data->udata); +} + +int stats_walk(const char *prefix, int (*callback)(const char *, int, void *), void *udata) { + struct walk_data data; + data.callback = callback; + data.udata = udata; + return cb_foreach(&stats, prefix, strlen(prefix), walk_cb, &data); +} +#endif + +static int write_cb(const char *key, int val, void *udata) { + FILE * F = (FILE *)udata; + fprintf(F, "%s: %d\n", (const char *)key, val); + return 0; +} + +void stats_write(FILE *F, const char *prefix) { + stats_walk(prefix, write_cb, F); +} + +void stats_close(void) { + cb_clear(&stats); +} diff --git a/src/util/log.h b/src/util/log.h index 15872d6dc..98a0d3af6 100644 --- a/src/util/log.h +++ b/src/util/log.h @@ -36,6 +36,12 @@ extern "C" { void log_printf(FILE * ios, const char *format, ...); void errno_check(const char *file, int line); + + int stats_count(const char *stat, int delta); + void stats_write(FILE *F, const char *prefix); + int stats_walk(const char *prefix, int (*callback)(const char *key, int val, void * udata), void *udata); + void stats_close(void); + #define ERRNO_CHECK() errno_check(__FILE__, __LINE__) diff --git a/src/util/log.test.c b/src/util/log.test.c index 86f13ea9c..928ba5660 100644 --- a/src/util/log.test.c +++ b/src/util/log.test.c @@ -1,11 +1,13 @@ #ifdef _MSC_VER #include #endif -#include #include "log.h" #include "macros.h" +#include +#include + #include #include @@ -32,9 +34,47 @@ static void test_logging(CuTest * tc) CuAssertStrEquals(tc, "World", str2); } +static int stats_cb(const char *stat, int num, void *udata) { + int *counter = (int *)udata; + if (counter) { + *counter += num; + } + return 0; +} + +static void test_stats(CuTest * tc) +{ + int n = 0; + test_setup(); + CuAssertIntEquals(tc, 1, stats_count("foobar", 1)); + CuAssertIntEquals(tc, 2, stats_count("test.one", 2)); + CuAssertIntEquals(tc, 1, stats_count("test.two", 1)); + CuAssertIntEquals(tc, 4, stats_count("test.one", 2)); + CuAssertIntEquals(tc, 1, stats_count("test.two", 0)); + + n = 0; + CuAssertIntEquals(tc, 0, stats_walk("", stats_cb, &n)); + CuAssertIntEquals(tc, 6, n); + + n = 0; + CuAssertIntEquals(tc, 0, stats_walk("test", stats_cb, &n)); + CuAssertIntEquals(tc, 5, n); + + n = 0; + CuAssertIntEquals(tc, 0, stats_walk("test.one", stats_cb, &n)); + CuAssertIntEquals(tc, 4, n); + + n = 0; + CuAssertIntEquals(tc, 0, stats_walk("foobar", stats_cb, &n)); + CuAssertIntEquals(tc, 1, n); + + test_teardown(); +} + CuSuite *get_log_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_logging); + SUITE_ADD_TEST(suite, test_stats); return suite; } From 820de2ee35504452cb02d960a2e7f89b2aec94e0 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 21 Oct 2018 19:30:19 +0200 Subject: [PATCH 5/6] fix cont arguments for new clibs version --- clibs | 2 +- src/kernel/item.c | 6 +++--- src/magic.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/clibs b/clibs index 1e1c947c8..ed5c4fee3 160000 --- a/clibs +++ b/clibs @@ -1 +1 @@ -Subproject commit 1e1c947c8034f071c6848dcf1c11138733949825 +Subproject commit ed5c4fee3afbc3d8be79d64857f30702aed522f8 diff --git a/src/kernel/item.c b/src/kernel/item.c index 4e707a48c..00f54a656 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -723,7 +723,7 @@ int change_money(unit * u, int v) return 0; } -static int add_resourcename_cb(const void * match, const void * key, +static int add_resourcename_cb(void * match, const void * key, size_t keylen, void *data) { struct locale * lang = (struct locale *)data; @@ -773,7 +773,7 @@ attrib_type at_showitem = { "showitem" }; -static int add_itemname_cb(const void * match, const void * key, +static int add_itemname_cb(void * match, const void * key, size_t keylen, void *data) { struct locale * lang = (struct locale *)data; @@ -919,7 +919,7 @@ void free_rtype(resource_type *rtype) { free(rtype); } -static int free_rtype_cb(const void * match, const void * key, +static int free_rtype_cb(void * match, const void * key, size_t keylen, void *cbdata) { resource_type *rtype = ((rt_entry *)match)->value;; diff --git a/src/magic.c b/src/magic.c index 7464e286d..415746db0 100644 --- a/src/magic.c +++ b/src/magic.c @@ -2949,7 +2949,7 @@ void free_spellbook(spellbook *sb) { free(sb); } -static int free_spellbook_cb(const void *match, const void *key, size_t keylen, void *data) { +static int free_spellbook_cb(void *match, const void *key, size_t keylen, void *data) { const sb_entry *ent = (const sb_entry *)match; UNUSED_ARG(data); UNUSED_ARG(keylen); From 297312ddb349a413d5936e1372e89a41e49b4e37 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 21 Oct 2018 19:56:46 +0200 Subject: [PATCH 6/6] Hirntoeter auch zaehlen. --- src/teleport.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/teleport.c b/src/teleport.c index 36634c5cd..2d8fafe72 100644 --- a/src/teleport.c +++ b/src/teleport.c @@ -182,6 +182,7 @@ void spawn_braineaters(float chance) u = create_unit(r, f, 1 + rng_int() % 10 + rng_int() % 10, rc_brain, 0, NULL, NULL); equip_unit(u, "seed_braineater"); + stats_count("monsters.create.braineater", 1); next = rng_int() % (int)(chance * 100); }