diff --git a/src/v_text.cpp b/src/v_text.cpp index 6fea75bb5..7e4a44b89 100644 --- a/src/v_text.cpp +++ b/src/v_text.cpp @@ -45,6 +45,7 @@ #include "gstrings.h" #include "vm.h" +#include "serializer.h" int ListGetInt(VMVa_List &tags); @@ -345,7 +346,7 @@ static void breakit (FBrokenLines *line, FFont *font, const uint8_t *start, cons line->Width = font->StringWidth (line->Text); } -TArray V_BreakLines (FFont *font, int maxwidth, const uint8_t *string, bool preservecolor, unsigned int *count) +TArray V_BreakLines (FFont *font, int maxwidth, const uint8_t *string, bool preservecolor) { TArray Lines(128); @@ -451,28 +452,40 @@ TArray V_BreakLines (FFont *font, int maxwidth, const uint8_t *str return Lines; } -void V_FreeBrokenLines (FBrokenLines *lines) +FSerializer &Serialize(FSerializer &arc, const char *key, FBrokenLines& g, FBrokenLines *def) { - if (lines) + if (arc.BeginObject(key)) { - delete[] lines; + arc("text", g.Text) + ("width", g.Width) + .EndObject(); } + return arc; } + + class DBrokenLines : public DObject { - DECLARE_ABSTRACT_CLASS(DBrokenLines, DObject) + DECLARE_CLASS(DBrokenLines, DObject) public: TArray mBroken; + DBrokenLines() = default; + DBrokenLines(TArray &broken) { mBroken = std::move(broken); } + + void Serialize(FSerializer &arc) override + { + arc("lines", mBroken); + } }; -IMPLEMENT_CLASS(DBrokenLines, true, false); +IMPLEMENT_CLASS(DBrokenLines, false, false); DEFINE_ACTION_FUNCTION(DBrokenLines, Count) { @@ -500,7 +513,6 @@ DEFINE_ACTION_FUNCTION(FFont, BreakLines) PARAM_STRING(text); PARAM_INT(maxwidth); - unsigned int count; - TArray broken = V_BreakLines(self, maxwidth, text, true, &count); + auto broken = V_BreakLines(self, maxwidth, text, true); ACTION_RETURN_OBJECT(Create(broken)); } diff --git a/src/v_text.h b/src/v_text.h index 1ae2ca3a5..30efa286f 100644 --- a/src/v_text.h +++ b/src/v_text.h @@ -79,11 +79,11 @@ struct FBrokenLines #define TEXTCOLOR_CHAT "\034*" #define TEXTCOLOR_TEAMCHAT "\034!" -TArray V_BreakLines (FFont *font, int maxwidth, const uint8_t *str, bool preservecolor = false, unsigned int *count = nullptr); -inline TArray V_BreakLines (FFont *font, int maxwidth, const char *str, bool preservecolor = false, unsigned int *count = nullptr) - { return V_BreakLines (font, maxwidth, (const uint8_t *)str, preservecolor, count); } -inline TArray V_BreakLines (FFont *font, int maxwidth, const FString &str, bool preservecolor = false, unsigned int *count = nullptr) - { return V_BreakLines (font, maxwidth, (const uint8_t *)str.GetChars(), preservecolor, count); } +TArray V_BreakLines (FFont *font, int maxwidth, const uint8_t *str, bool preservecolor = false); +inline TArray V_BreakLines (FFont *font, int maxwidth, const char *str, bool preservecolor = false) + { return V_BreakLines (font, maxwidth, (const uint8_t *)str, preservecolor); } +inline TArray V_BreakLines (FFont *font, int maxwidth, const FString &str, bool preservecolor = false) + { return V_BreakLines (font, maxwidth, (const uint8_t *)str.GetChars(), preservecolor); } int GetCharFromString(const uint8_t *&string);