From dba51bf0f70c15c16ebec37f0bf824d0b0b418e0 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 26 Jun 2014 19:11:34 -0700 Subject: [PATCH 1/4] remove duplicate handling of "speed" attribute in JSON add weight and capacity in this test (still broken) --- src/kernel/jsonconf.c | 3 --- tests/movement.lua | 7 ++++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index 3f977478f..415684e1b 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -260,9 +260,6 @@ void json_race(cJSON *json, race *rc) { else if (strcmp(child->string, "weight")==0) { rc->weight = child->valueint; } - else if (strcmp(child->string, "speed")==0) { - rc->speed = child->valueint; - } else if (strcmp(child->string, "capacity")==0) { rc->capacity = child->valueint; } diff --git a/tests/movement.lua b/tests/movement.lua index 0685c33dc..94080769e 100644 --- a/tests/movement.lua +++ b/tests/movement.lua @@ -9,7 +9,12 @@ function setup() eressea.settings.set("rules.ships.storms", "0") conf = [[{ "races": { - "human" : { "speed" : 1, "flags" : [ "walk" ] }, + "human" : { + "speed" : 1, + "weight" : 1000, + "capacity" : 1500, + "flags" : [ "walk" ] + }, "troll" : {} }, "items" : { From 5e835618f3bf54395dd652d8fd3b075820ffea4a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 26 Jun 2014 21:02:03 -0700 Subject: [PATCH 2/4] fix weight calculation, uninitialized value --- se/server.vpj | 25 ++++++++++++++++--------- src/kernel/config.c | 4 ++-- tests/movement.lua | 2 +- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/se/server.vpj b/se/server.vpj index 9e505b793..e6d5de014 100644 --- a/se/server.vpj +++ b/se/server.vpj @@ -3,7 +3,7 @@ Version="10.0" VendorName="SlickEdit" TemplateName="GNU C/C++" - WorkingDir="." + WorkingDir="../" BuildSystem="vsbuild"> - + - + RunFromDir="%rw"> + - + - + RunFromDir="%rw"> + + diff --git a/src/kernel/config.c b/src/kernel/config.c index d697411d3..0e533f4cf 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -2103,7 +2103,7 @@ bool faction_id_is_unused(int id) int weight(const unit * u) { - int w, n = 0, in_bag = 0; + int w = 0, n = 0, in_bag = 0; const resource_type *rtype = get_resourcetype(R_SACK_OF_CONSERVATION); item *itm; @@ -2120,8 +2120,8 @@ int weight(const unit * u) if (rtype) { w = i_get(u->items, rtype->itype) * BAGCAPACITY; if (w > in_bag) w = in_bag; + n -= w; } - n -= w; return n; } diff --git a/tests/movement.lua b/tests/movement.lua index 94080769e..d5a270088 100644 --- a/tests/movement.lua +++ b/tests/movement.lua @@ -49,7 +49,7 @@ end function test_walk_to_land() local r1 = region.create(0, 0, "plain") local r2 = region.create(1, 0, "plain") - local f = faction.create("test@example.com", "human", "de") + local f = faction.create("walk@example.com", "human", "de") local u = unit.create(f, r1, 1) u:add_order("NACH O") process_orders() From 68aa903130c6f32bbf9d2ac8807ff8de1684d313 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 26 Jun 2014 21:48:01 -0700 Subject: [PATCH 3/4] make tests pass through valgrind introduce more #ifdef LOMEM to bitfield structs. --- src/json.test.c | 4 +++- src/kernel/battle.h | 16 ++++++++++++++++ src/kernel/order.c | 5 +++++ src/kernel/resources.h | 9 +++++++++ src/kernel/skills.h | 7 +++++++ 5 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/json.test.c b/src/json.test.c index 7c1027596..1c6d72d70 100644 --- a/src/json.test.c +++ b/src/json.test.c @@ -21,7 +21,9 @@ static char *strip(char *str) { for (; *b && isspace(*b); ++b) {}; for (e = b; *e && !isspace(*e); ++e) {}; while (*b) { - memcpy(s, b, e - b); + if (s!=b) { + memcpy(s, b, e - b); + } s += e - b; for (b = e; *b && isspace(*b); ++b) {}; for (e = b; *e && !isspace(*e); ++e) {}; diff --git a/src/kernel/battle.h b/src/kernel/battle.h index eb854caeb..95d869ff3 100644 --- a/src/kernel/battle.h +++ b/src/kernel/battle.h @@ -117,8 +117,13 @@ extern "C" { typedef struct weapon { int count, used; const struct weapon_type *type; +# ifdef LOMEM int attackskill:8; int defenseskill:8; +# else + int attackskill; + int defenseskill; +# endif } weapon; /*** fighter::person::flags ***/ @@ -165,6 +170,7 @@ extern "C" { int catmsg; /* Merkt sich, ob Katapultmessage schon generiert. */ struct person { int hp; /* Trefferpunkte der Personen */ +#ifdef LOMEM int attack:8; /* (Magie) Attackenbonus der Personen */ int defence:8; /* (Magie) Paradenbonus der Personen */ int damage:8; /* (Magie) Schadensbonus der Personen im Nahkampf */ @@ -174,6 +180,16 @@ extern "C" { int reload:4; /* Anzahl Runden, die die Waffe x noch laden muss. * dahinter steckt ein array[RL_MAX] wenn er min. eine hat. */ int last_action:4; /* In welcher Runde haben wir zuletzt etwas getan */ +#else + int attack; + int defence; + int damage; + int damage_rear; + int flags; + int speed; + int reload; + int last_action; +#endif struct weapon *missile; /* missile weapon */ struct weapon *melee; /* melee weapon */ } *person; diff --git a/src/kernel/order.c b/src/kernel/order.c index 2ec616eb6..8154f3cda 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -45,8 +45,13 @@ static int nlocales = 0; typedef struct order_data { char *_str; +# ifdef LOMEM int _refcount:20; int _lindex:4; +# else + int _refcount; + int _lindex; +# endif keyword_t _keyword; } order_data; diff --git a/src/kernel/resources.h b/src/kernel/resources.h index d2c229657..ace16a177 100644 --- a/src/kernel/resources.h +++ b/src/kernel/resources.h @@ -22,12 +22,21 @@ extern "C" { typedef struct rawmaterial { const struct rawmaterial_type *type; +#ifdef LOMEM int amount:16; int level:8; int flags:8; int base:8; int divisor:8; int startlevel:8; +#else + int amount; + int level; + int flags; + int base; + int divisor; + int startlevel; +#endif struct rawmaterial *next; } rawmaterial; diff --git a/src/kernel/skills.h b/src/kernel/skills.h index bc7300c02..5d8b3477f 100644 --- a/src/kernel/skills.h +++ b/src/kernel/skills.h @@ -25,10 +25,17 @@ extern "C" { #define SMF_RIDING (1<<2) /* Bonus für berittene - an der rasse */ typedef struct skill { +#ifdef LOMEM int id:8; unsigned int level:8; unsigned int weeks:8; unsigned int old:8; +#else + int id; + unsigned int level; + unsigned int weeks; + unsigned int old; +#endif } skill; typedef int (*skillmod_fun) (const struct unit *, const struct region *, From 06d92181fe7be456dd873bb21774dfe7ae4bf633 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 26 Jun 2014 22:05:17 -0700 Subject: [PATCH 4/4] option for release builds --- src/platform.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/platform.h b/src/platform.h index 593b0dcd0..e83600fa2 100644 --- a/src/platform.h +++ b/src/platform.h @@ -19,6 +19,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef CONFIG_H #define CONFIG_H +#ifdef NDEBUG +#define LOMEM +#endif + #ifdef _MSC_VER # define VC_EXTRALEAN # define WIN32_LEAN_AND_MEAN