From 2f1fc1c9c83f5d0fd7a3995496a5b7672ff0c002 Mon Sep 17 00:00:00 2001 From: ac-stef Date: Sun, 24 May 2015 11:35:42 +0200 Subject: [PATCH] cleanup formatted output of entity attributes --- source/src/editing.cpp | 4 +--- source/src/entities.cpp | 11 +++++++++++ source/src/protos.h | 1 + source/src/world.cpp | 8 ++------ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/source/src/editing.cpp b/source/src/editing.cpp index 2919229d..0445ccee 100644 --- a/source/src/editing.cpp +++ b/source/src/editing.cpp @@ -106,9 +106,7 @@ char *editinfo() { entity &c = ents[e]; int t = c.type < MAXENTTYPES ? c.type : 0; - #define AA(x) floatstr(float(c.attr##x) / entscale[t][x - 1], true) - formatstring(info)("closest entity: %s (%s, %s, %s, %s, %s, %s, %s)", entnames[t], AA(1), AA(2), AA(3), AA(4), AA(5), AA(6), AA(7)); - #undef AA + formatstring(info)("closest entity: %s (%s)", entnames[t], formatentityattributes(c, true)); const char *slotinfo = "unassigned slot"; if(t == MAPMODEL) { diff --git a/source/src/entities.cpp b/source/src/entities.cpp index d2bc611e..6e7a228d 100644 --- a/source/src/entities.cpp +++ b/source/src/entities.cpp @@ -705,3 +705,14 @@ void clampentityattributes(persistent_entity &e) CLAMPATTR(7); } } + +const char *formatentityattributes(const persistent_entity &e, bool withcomma) +{ + static string res; + int t = e.type < MAXENTTYPES ? e.type : 0; + const char *c = withcomma ? "," : ""; + #define AA(x) floatstr(float(e.attr##x) / entscale[t][x - 1], true) + formatstring(res)("%s%s %s%s %s%s %s%s %s%s %s%s %s", AA(1), c, AA(2), c, AA(3), c, AA(4), c, AA(5), c, AA(6), c, AA(7)); + #undef AA + return res; +} diff --git a/source/src/protos.h b/source/src/protos.h index ab3885a5..be6936bf 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -790,6 +790,7 @@ extern void checkitems(playerent *d); extern vector changedents; extern void syncentchanges(bool force = false); extern void clampentityattributes(persistent_entity &e); +extern const char *formatentityattributes(const persistent_entity &e, bool withcomma = false); // rndmap extern void perlinarea(block &b, int scale, int seed, int psize); diff --git a/source/src/world.cpp b/source/src/world.cpp index 97af6e0c..7ca8e535 100644 --- a/source/src/world.cpp +++ b/source/src/world.cpp @@ -300,9 +300,7 @@ void getdeletedentities() { persistent_entity &e = deleted_ents[i]; int t = e.type < MAXENTTYPES ? e.type : NOTUSED; - #define AA(x) floatstr(float(e.attr##x) / entscale[t][x - 1], true) - cvecprintf(res,"%s %d %d %d %s %s %s %s %s %s %s\n", entnames[e.type], e.x, e.y, e.z, AA(1), AA(2), AA(3), AA(4), AA(5), AA(6), AA(7)); - #undef AA + cvecprintf(res,"%s %d %d %d %s\n", entnames[t], e.x, e.y, e.z, formatentityattributes(e)); } if(res.length()) res.last() = '\0'; else res.add('\0'); @@ -483,9 +481,7 @@ void editentity(char **args, int numargs) // index x y z a1 a2 a3 a4 ... unsavededits++; } // give back unchanged or new entity properties - #define AA(x) floatstr(float(e.attr##x) / entscale[t][x - 1], true) - formatstring(res)("%s %d %d %d %s %s %s %s %s %s %s", entnames[e.type], e.x, e.y, e.z, AA(1), AA(2), AA(3), AA(4), AA(5), AA(6), AA(7)); - #undef AA + formatstring(res)("%s %d %d %d %s", entnames[t], e.x, e.y, e.z, formatentityattributes(e)); } result(res); }