Drawn maps optimizer - first steps:
authorunc0rr
Wed, 30 Apr 2014 15:26:50 +0400
changeset 10235 bafca1686867
parent 10234 a3a200e35c6e
child 10236 8fa1ccfba752
Drawn maps optimizer - first steps: - Break paths into segments
QTfrontend/drawmapscene.cpp
QTfrontend/drawmapscene.h
QTfrontend/ui/page/pagedrawmap.cpp
QTfrontend/ui/page/pagedrawmap.h
QTfrontend/ui/widget/drawmapwidget.cpp
QTfrontend/ui/widget/drawmapwidget.h
QTfrontend/util/FileEngine.cpp
misc/libphyslayer/hwpacksmounter.h
project_files/hedgewars.pro
--- a/QTfrontend/drawmapscene.cpp	Wed Apr 30 14:17:06 2014 +0400
+++ b/QTfrontend/drawmapscene.cpp	Wed Apr 30 15:26:50 2014 +0400
@@ -304,6 +304,8 @@
 
 void DrawMapScene::decode(QByteArray data)
 {
+    hideCursor();
+
     bool erasing = m_isErasing;
 
     oldItems.clear();
@@ -324,7 +326,7 @@
         data.remove(0, 2);
         quint8 flags = *(quint8 *)data.data();
         data.remove(0, 1);
-        qDebug() << px << py;
+        //qDebug() << px << py;
         if(flags & 0x80)
         {
             isSpecial = false;
@@ -485,3 +487,51 @@
 
     return point;
 }
+
+void DrawMapScene::optimize()
+{
+    if(!paths.size()) return;
+
+    // break paths into segments
+    Paths pth;
+
+    foreach(const PathParams & pp, paths)
+    {
+        int l = pp.points.size();
+
+        if(l == 1)
+        {
+            pth.prepend(pp);
+        } else
+        {
+            for(int i = l - 2; i >= 0; --i)
+            {
+                PathParams p = pp;
+                p.points = QList<QPoint>() << p.points[i] << p.points[i + 1];
+                pth.prepend(pp);
+            }
+        }
+    }
+
+    // clear the scene
+    oldItems.clear();
+    oldPaths.clear();
+    clear();
+    paths.clear();
+    m_specialPoints.clear();
+
+    // render the result
+    foreach(const PathParams & p, pth)
+    {
+        if(p.erasing)
+            m_pen.setBrush(m_eraser);
+        else
+            m_pen.setBrush(m_brush);
+
+        m_pen.setWidth(deserializePenWidth(p.width));
+
+        addPath(pointsToPath(p.points), m_pen);
+    }
+
+    emit pathChanged();
+}
--- a/QTfrontend/drawmapscene.h	Wed Apr 30 14:17:06 2014 +0400
+++ b/QTfrontend/drawmapscene.h	Wed Apr 30 15:26:50 2014 +0400
@@ -58,6 +58,7 @@
         void undo();
         void clearMap();
         void simplifyLast();
+        void optimize();
         void setErasing(bool erasing);
         void showCursor();
         void hideCursor();
--- a/QTfrontend/ui/page/pagedrawmap.cpp	Wed Apr 30 14:17:06 2014 +0400
+++ b/QTfrontend/ui/page/pagedrawmap.cpp	Wed Apr 30 15:26:50 2014 +0400
@@ -44,11 +44,12 @@
     rbPolyline->setChecked(true);
 
     pbClear = addButton(tr("Clear"), pageLayout, 5, 0);
-    pbLoad = addButton(tr("Load"), pageLayout, 6, 0);
-    pbSave = addButton(tr("Save"), pageLayout, 7, 0);
+    pbOptimize = addButton(tr("Optimize"), pageLayout, 6, 0);
+    pbLoad = addButton(tr("Load"), pageLayout, 7, 0);
+    pbSave = addButton(tr("Save"), pageLayout, 8, 0);
 
     drawMapWidget = new DrawMapWidget(this);
-    pageLayout->addWidget(drawMapWidget, 0, 1, 9, 1);
+    pageLayout->addWidget(drawMapWidget, 0, 1, 10, 1);
 
     return pageLayout;
 }
@@ -58,6 +59,7 @@
     connect(cbEraser, SIGNAL(toggled(bool)), drawMapWidget, SLOT(setErasing(bool)));
     connect(pbUndo, SIGNAL(clicked()), drawMapWidget, SLOT(undo()));
     connect(pbClear, SIGNAL(clicked()), drawMapWidget, SLOT(clear()));
+    connect(pbOptimize, SIGNAL(clicked()), drawMapWidget, SLOT(optimize()));
     connect(pbLoad, SIGNAL(clicked()), this, SLOT(load()));
     connect(pbSave, SIGNAL(clicked()), this, SLOT(save()));
 
--- a/QTfrontend/ui/page/pagedrawmap.h	Wed Apr 30 14:17:06 2014 +0400
+++ b/QTfrontend/ui/page/pagedrawmap.h	Wed Apr 30 15:26:50 2014 +0400
@@ -42,6 +42,7 @@
         QPushButton * pbClear;
         QPushButton * pbLoad;
         QPushButton * pbSave;
+        QPushButton * pbOptimize;
         QCheckBox * cbEraser;
         QRadioButton * rbPolyline;
         QRadioButton * rbRectangle;
--- a/QTfrontend/ui/widget/drawmapwidget.cpp	Wed Apr 30 14:17:06 2014 +0400
+++ b/QTfrontend/ui/widget/drawmapwidget.cpp	Wed Apr 30 15:26:50 2014 +0400
@@ -118,6 +118,11 @@
     if(m_scene) m_scene->clearMap();
 }
 
+void DrawMapWidget::optimize()
+{
+    if(m_scene) m_scene->optimize();
+}
+
 void DrawMapWidget::setErasing(bool erasing)
 {
     if(m_scene) m_scene->setErasing(erasing);
--- a/QTfrontend/ui/widget/drawmapwidget.h	Wed Apr 30 14:17:06 2014 +0400
+++ b/QTfrontend/ui/widget/drawmapwidget.h	Wed Apr 30 15:26:50 2014 +0400
@@ -97,6 +97,7 @@
     public slots:
         void undo();
         void clear();
+        void optimize();
         void setErasing(bool erasing);
         void save(const QString & fileName);
         void load(const QString & fileName);
--- a/QTfrontend/util/FileEngine.cpp	Wed Apr 30 14:17:06 2014 +0400
+++ b/QTfrontend/util/FileEngine.cpp	Wed Apr 30 15:26:50 2014 +0400
@@ -2,8 +2,8 @@
  * TODO: add copyright header, determine license
  */
 
+#include "FileEngine.h"
 #include "hwpacksmounter.h"
-#include "FileEngine.h"
 
 
 const QString FileEngineHandler::scheme = "physfs:/";
--- a/misc/libphyslayer/hwpacksmounter.h	Wed Apr 30 14:17:06 2014 +0400
+++ b/misc/libphyslayer/hwpacksmounter.h	Wed Apr 30 15:26:50 2014 +0400
@@ -5,8 +5,10 @@
 #include "physfscompat.h"
 
 #ifndef PAS2C
+#ifndef QT_VERSION
 #include "lua.h"
 #endif
+#endif
 
 #ifdef __cplusplus
 extern "C" {
@@ -15,7 +17,9 @@
 PHYSFS_DECL void hedgewarsMountPackages();
 PHYSFS_DECL void hedgewarsMountPackage(char * fileName);
 
+#ifndef QT_VERSION
 PHYSFS_DECL const char * physfsReader(lua_State *L, PHYSFS_File *f, size_t *size);
+#endif
 PHYSFS_DECL void physfsReaderSetBuffer(void *buffer);
 
 #ifdef __cplusplus
--- a/project_files/hedgewars.pro	Wed Apr 30 14:17:06 2014 +0400
+++ b/project_files/hedgewars.pro	Wed Apr 30 15:26:50 2014 +0400
@@ -12,7 +12,7 @@
 INCLUDEPATH += ../QTfrontend/util/platform
 INCLUDEPATH += ../misc/libphysfs
 INCLUDEPATH += ../misc/libphyslayer
-INCLUDEPATH += /usr/local/include/lua51/
+INCLUDEPATH += /usr/local/include/lua52/
 
 DESTDIR = ../bin
 
@@ -221,21 +221,21 @@
     ../share/hedgewars/Data/Locale/hedgewars_bg.ts \
     ../share/hedgewars/Data/Locale/hedgewars_cs.ts \
     ../share/hedgewars/Data/Locale/hedgewars_da.ts \
-    ../share/hedgewars/Data/Locale/hedgewars_de.ts \ 
+    ../share/hedgewars/Data/Locale/hedgewars_de.ts \
     ../share/hedgewars/Data/Locale/hedgewars_el.ts \
-    ../share/hedgewars/Data/Locale/hedgewars_en.ts \ 
+    ../share/hedgewars/Data/Locale/hedgewars_en.ts \
     ../share/hedgewars/Data/Locale/hedgewars_es.ts \
     ../share/hedgewars/Data/Locale/hedgewars_fi.ts \
-    ../share/hedgewars/Data/Locale/hedgewars_fr.ts \ 
+    ../share/hedgewars/Data/Locale/hedgewars_fr.ts \
     ../share/hedgewars/Data/Locale/hedgewars_gl.ts \
-    ../share/hedgewars/Data/Locale/hedgewars_hu.ts \ 
-    ../share/hedgewars/Data/Locale/hedgewars_it.ts \ 
-    ../share/hedgewars/Data/Locale/hedgewars_ja.ts \ 
-    ../share/hedgewars/Data/Locale/hedgewars_ko.ts \ 
+    ../share/hedgewars/Data/Locale/hedgewars_hu.ts \
+    ../share/hedgewars/Data/Locale/hedgewars_it.ts \
+    ../share/hedgewars/Data/Locale/hedgewars_ja.ts \
+    ../share/hedgewars/Data/Locale/hedgewars_ko.ts \
     ../share/hedgewars/Data/Locale/hedgewars_lt.ts \
     ../share/hedgewars/Data/Locale/hedgewars_ms.ts \
-    ../share/hedgewars/Data/Locale/hedgewars_nl.ts \ 
-    ../share/hedgewars/Data/Locale/hedgewars_pl.ts \ 
+    ../share/hedgewars/Data/Locale/hedgewars_nl.ts \
+    ../share/hedgewars/Data/Locale/hedgewars_pl.ts \
     ../share/hedgewars/Data/Locale/hedgewars_pt_BR.ts \
     ../share/hedgewars/Data/Locale/hedgewars_pt_PT.ts \
     ../share/hedgewars/Data/Locale/hedgewars_ro.ts \
@@ -249,7 +249,7 @@
 
 RESOURCES += ../QTfrontend/hedgewars.qrc
 
-LIBS += -L../bin -lphysfs -lphyslayer
+LIBS += -L../bin -lhwphysfs -lphyslayer
 
 macx {
     QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.6