]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Optimize label code by avoiding to exec recalcPositionWithText every frame. It fixes...
authorterencehill <piuntn@gmail.com>
Mon, 6 May 2013 16:55:05 +0000 (18:55 +0200)
committerterencehill <piuntn@gmail.com>
Mon, 6 May 2013 18:00:32 +0000 (20:00 +0200)
qcsrc/menu/item/label.c

index 378e74adbcb1268ddaa34d7c33af0bb9031bce2e..5d0e7437fa8de17e77b93e7514918077cc6019eb 100644 (file)
@@ -8,6 +8,7 @@ CLASS(Label) EXTENDS(Item)
        METHOD(Label, recalcPositionWithText, void(entity, string))
        ATTRIB(Label, isBold, float, 0)
        ATTRIB(Label, text, string, string_null)
+       ATTRIB(Label, currentText, string, string_null)
        ATTRIB(Label, fontSize, float, 8)
        ATTRIB(Label, align, float, 0.5)
        ATTRIB(Label, allowCut, float, 0)
@@ -39,7 +40,13 @@ string Label_toString(entity me)
 void Label_setText(entity me, string txt)
 {
        me.text = txt;
-       me.recalcPos = 1;
+       if(txt != me.currentText)
+       {
+               if(me.currentText)
+                       strunzone(me.currentText);
+               me.currentText = strzone(txt);
+               me.recalcPos = 1;
+       }
 }
 void Label_recalcPositionWithText(entity me, string t)
 {
@@ -146,7 +153,13 @@ void Label_draw(entity me)
        if(me.textEntity)
        {
                t = me.textEntity.toString(me.textEntity);
-               me.recalcPos = 1;
+               if(t != me.currentText)
+               {
+                       if(me.currentText)
+                               strunzone(me.currentText);
+                       me.currentText = strzone(t);
+                       me.recalcPos = 1;
+               }
        }
        else
                t = me.text;