Incomplete implementation of 'special points' in drawn maps (crashes engine)
authorunc0rr
Mon, 30 Sep 2013 00:20:58 +0400
changeset 9472 265e5997580e
parent 9470 9ed07a96349d
child 9475 619920c6aea0
Incomplete implementation of 'special points' in drawn maps (crashes engine)
QTfrontend/drawmapscene.cpp
QTfrontend/drawmapscene.h
QTfrontend/ui/widget/drawmapwidget.cpp
hedgewars/uLandPainted.pas
share/hedgewars/Data/Scripts/Multiplayer/Racer.lua
--- a/QTfrontend/drawmapscene.cpp	Fri Sep 27 21:52:21 2013 -0400
+++ b/QTfrontend/drawmapscene.cpp	Mon Sep 30 00:20:58 2013 +0400
@@ -156,7 +156,7 @@
     if(m_isCursorShown)
         return;
 
-    if(items().size())
+    if(paths.size())
     {
         removeItem(items().first());
         paths.removeFirst();
@@ -183,10 +183,11 @@
     if(!items().size())
         return;
 
+    m_specialPoints.clear();
     oldItems.clear();
 
     // do this since clear() would _destroy_ all items
-    while(items().size())
+    for(int i = paths.size() - 1; i >= 0; --i)
     {
         oldItems.push_front(items().first());
         removeItem(items().first());
@@ -211,7 +212,7 @@
 
 QByteArray DrawMapScene::encode()
 {
-    QByteArray b;
+    QByteArray b(m_specialPoints);
 
     for(int i = paths.size() - 1; i >= 0; --i)
     {
@@ -247,9 +248,12 @@
     oldPaths.clear();
     clear();
     paths.clear();
+    m_specialPoints.clear();
 
     PathParams params;
 
+    bool isSpecial = true;
+
     while(data.size() >= 5)
     {
         qint16 px = qFromBigEndian(*(qint16 *)data.data());
@@ -258,9 +262,11 @@
         data.remove(0, 2);
         quint8 flags = *(quint8 *)data.data();
         data.remove(0, 1);
-
+        qDebug() << px << py;
         if(flags & 0x80)
         {
+            isSpecial = false;
+
             if(params.points.size())
             {
                 addPath(pointsToPath(params.points), m_pen);
@@ -278,9 +284,23 @@
             else
                 m_pen.setBrush(m_brush);
             params.width = penWidth;
-        }
+        } else
+            if(isSpecial)
+            {
+                QPainterPath path;
+                path.addEllipse(QPointF(px, py), 10, 10);
+
+                addPath(path);
 
-        params.points.append(QPoint(px, py));
+                qint16 x = qToBigEndian(px);
+                qint16 y = qToBigEndian(py);
+                m_specialPoints.append((const char *)&x, 2);
+                m_specialPoints.append((const char *)&y, 2);
+                m_specialPoints.append((const char *)&flags, 1);
+            }
+
+        if(!isSpecial)
+            params.points.append(QPoint(px, py));
     }
 
     if(params.points.size())
--- a/QTfrontend/drawmapscene.h	Fri Sep 27 21:52:21 2013 -0400
+++ b/QTfrontend/drawmapscene.h	Mon Sep 30 00:20:58 2013 +0400
@@ -66,6 +66,7 @@
         QList<QGraphicsItem *> oldItems;
         QGraphicsEllipseItem * m_cursor;
         bool m_isCursorShown;
+        QByteArray m_specialPoints;
 
         virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent);
         virtual void mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent);
--- a/QTfrontend/ui/widget/drawmapwidget.cpp	Fri Sep 27 21:52:21 2013 -0400
+++ b/QTfrontend/ui/widget/drawmapwidget.cpp	Mon Sep 30 00:20:58 2013 +0400
@@ -160,6 +160,7 @@
         }
         else
             m_scene->decode(qUncompress(QByteArray::fromBase64(f.readAll())));
+            //m_scene->decode(f.readAll());
     }
 }
 
--- a/hedgewars/uLandPainted.pas	Fri Sep 27 21:52:21 2013 -0400
+++ b/hedgewars/uLandPainted.pas	Mon Sep 30 00:20:58 2013 +0400
@@ -27,7 +27,7 @@
 procedure freeModule;
 
 implementation
-uses uLandGraphics, uConsts, uVariables, uUtils, SDLh, uCommands, uDebug;
+uses uLandGraphics, uConsts, uVariables, uUtils, SDLh, uCommands, uDebug, uScript;
 
 type PointRec = packed record
     X, Y: SmallInt;
@@ -88,7 +88,11 @@
     radius:= 0;
 
     pe:= pointsListHead;
-    TryDo((pe = nil) or (pe^.point.flags and $80 <> 0), 'Corrupted draw data', true);
+    while (pe <> nil) and (pe^.point.flags and $80 = 0) do
+        begin
+        ScriptCall('onSpecialPoint', pe^.point.X, pe^.point.Y, pe^.point.flags);
+        pe:= pe^.next;
+        end;
 
     while(pe <> nil) do
         begin
@@ -110,7 +114,7 @@
             end;
 
         prevPoint:= pe^.point;
-        pe:= pe^.next;  
+        pe:= pe^.next;
         end;
 end;
 
--- a/share/hedgewars/Data/Scripts/Multiplayer/Racer.lua	Fri Sep 27 21:52:21 2013 -0400
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Racer.lua	Mon Sep 30 00:20:58 2013 +0400
@@ -524,6 +524,10 @@
 
 end
 
+function onSpecialPoint(x,y,flag)
+    PlaceWayPoint(x,y)
+end
+
 function onNewTurn()
 
         CheckForNewRound()