fabiangreffrath / woof

Woof! is a continuation of the Boom/MBF bloodline of Doom source ports.
GNU General Public License v2.0
186 stars 32 forks source link

Add advanced version of coordinates widget #1760

Closed ceski-1 closed 2 weeks ago

ceski-1 commented 2 weeks ago

Added by request. I'll fix any conflicts from https://github.com/fabiangreffrath/woof/pull/1759.

fabiangreffrath commented 2 weeks ago

Somehow can't get it to work. If I select "Show player coords: advanced", nothing shows up.

ceski-1 commented 2 weeks ago

Somehow can't get it to work. If I select "Show player coords: advanced", nothing shows up.

Maybe I'm doing bad string manipulation here: https://github.com/fabiangreffrath/woof/pull/1760/files#diff-a4f029940e50c96b9e3766ac0da54d42f3a3f0fbd915269dc0b4b4c1c2e3f9f3R97-R98

fabiangreffrath commented 2 weeks ago

This works, but well...

--- a/src/hu_coordinates.c
+++ b/src/hu_coordinates.c
@@ -94,9 +94,10 @@ static split_angle_t SplitAngle(angle_t x)

 static void BuildString(hu_multiline_t *const w_coord, char *buf, int len)
 {
-    const char *s = buf;
+    char *s = M_StringDuplicate(buf);
     M_snprintf(buf, len, "%-*s", WIDGET_WIDTH, s);
     HUlib_add_string_keep_space(w_coord, buf);
+    free(s);
 }

 static void FixedToString(hu_multiline_t *const w_coord, const char *label,
ceski-1 commented 2 weeks ago

This works, but well...

Thanks! Fixed here: https://github.com/fabiangreffrath/woof/pull/1760/commits/566e848d4f9e73afbb88436deb2c47c837df0c59

fabiangreffrath commented 2 weeks ago

There must be a better solution than running strdup() several times per tic on the same string.

ceski-1 commented 2 weeks ago

There must be a better solution than running strdup() several times per tic on the same string.

Different approach here: https://github.com/fabiangreffrath/woof/pull/1760/commits/bc8e19b48687f8592b21778612d2d464df0e0e18