From 7906cdbcb6450fc71d253bbebf372d97f33590a1 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 12 Sep 2015 16:49:18 +0200 Subject: [PATCH] do not read gamename from XML, read it from JSON only (two mechanisms for the same feature are too many) --- conf/e2/config.xml | 2 +- conf/e3/config.xml | 2 +- conf/e4/config.xml | 2 +- src/kernel/config.h | 6 ++++-- src/kernel/unit.c | 4 ++-- src/kernel/xmlreader.c | 10 +--------- 6 files changed, 10 insertions(+), 16 deletions(-) diff --git a/conf/e2/config.xml b/conf/e2/config.xml index 45870fded..98c118088 100644 --- a/conf/e2/config.xml +++ b/conf/e2/config.xml @@ -53,7 +53,7 @@ - + diff --git a/conf/e3/config.xml b/conf/e3/config.xml index 663b56d26..6a32c95da 100644 --- a/conf/e3/config.xml +++ b/conf/e3/config.xml @@ -42,7 +42,7 @@ - + diff --git a/conf/e4/config.xml b/conf/e4/config.xml index 2e68f6bf2..bbf712c09 100644 --- a/conf/e4/config.xml +++ b/conf/e4/config.xml @@ -42,7 +42,7 @@ - + diff --git a/src/kernel/config.h b/src/kernel/config.h index ade8bfa63..00518c37b 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -261,8 +261,6 @@ extern "C" { unsigned int data_turn; struct param *parameters; void *vm_state; - double producexpchance; - int cookie; int data_version; /* TODO: eliminate in favor of gamedata.version */ struct _dictionary_ *inifile; @@ -271,6 +269,10 @@ extern "C" { const struct race * rc, int in_turn); int(*maintenance) (const struct unit * u); } functions; + /* the following are some cached values, because get_param can be slow. + * you should almost never need to touch them */ + int cookie; + double producexpchance_; } settings; typedef struct helpmode { diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 696015aef..a12edd310 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -1937,10 +1937,10 @@ bool unit_can_study(const unit *u) { static double produceexp_chance(void) { static int update = 0; if (update != global.cookie) { - global.producexpchance = get_param_flt(global.parameters, "study.from_use", 1.0 / 3); + global.producexpchance_ = get_param_flt(global.parameters, "study.from_use", 1.0 / 3); update = global.cookie; } - return global.producexpchance; + return global.producexpchance_; } void produceexp_ex(struct unit *u, skill_t sk, int n, bool (*learn)(unit *, skill_t, double)) diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index d87caaef7..c2114641d 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -2060,16 +2060,9 @@ static int parse_main(xmlDocPtr doc) xmlNodeSetPtr nodes = result->nodesetval; int i; - xmlChar *propValue; if (nodes->nodeNr > 0) { xmlNodePtr node = nodes->nodeTab[0]; - propValue = xmlGetProp(node, BAD_CAST "name"); - if (propValue != NULL) { - global.gamename = _strdup((const char *)propValue); - xmlFree(propValue); - } - xmlXPathFreeObject(result); xpath->node = node; @@ -2079,9 +2072,8 @@ static int parse_main(xmlDocPtr doc) for (i = 0; i != nodes->nodeNr; ++i) { xmlNodePtr node = nodes->nodeTab[i]; xmlChar *propName = xmlGetProp(node, BAD_CAST "name"); - bool disable = xml_bvalue(node, "disable", false); - if (disable) { + if (xml_bvalue(node, "disable", false)) { int k; for (k = 0; k != MAXKEYWORDS; ++k) { if (strcmp(keywords[k], (const char *)propName) == 0) {