Merge MAP, MAPGEN and SEED params into one on room join, so engine isn't spawned three times for a preview. Not tested as I'm unable to see my rooms (why?)
authorunc0rr
Tue, 08 Feb 2011 22:24:30 +0300
changeset 4936 d65d438acd23
parent 4935 27fb500dd6b1
child 4937 55b9145fea94
Merge MAP, MAPGEN and SEED params into one on room join, so engine isn't spawned three times for a preview. Not tested as I'm unable to see my rooms (why?)
QTfrontend/gamecfgwidget.cpp
QTfrontend/gamecfgwidget.h
QTfrontend/mapContainer.cpp
QTfrontend/mapContainer.h
gameServer/HWProtoLobbyState.hs
gameServer/Utils.hs
--- a/QTfrontend/gamecfgwidget.cpp	Tue Feb 08 02:43:07 2011 +0100
+++ b/QTfrontend/gamecfgwidget.cpp	Tue Feb 08 22:24:30 2011 +0300
@@ -33,7 +33,9 @@
 #include "proto.h"
 
 GameCFGWidget::GameCFGWidget(QWidget* parent) :
-  QGroupBox(parent), mainLayout(this)
+  QGroupBox(parent)
+  , mainLayout(this)
+  , seedRegexp("\\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\\}")
 {
     mainLayout.setMargin(0);
 //  mainLayout.setSizeConstraint(QLayout::SetMinimumSize);
@@ -332,7 +334,7 @@
         }
         if (param == "SEED") {
             pMapContainer->setSeed(value);
-            if (!QRegExp("\\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\\}").exactMatch(value)) {
+            if (!seedRegexp.exactMatch(value)) {
                 pMapContainer->seedEdit->setVisible(true);
                 }
             return;
@@ -371,6 +373,19 @@
         }
     }
 
+    if (slValue.size() == 3)
+    {
+        if (param == "FULLGENCFG")
+        {
+            QString seed = slValue[2];
+            if (!seedRegexp.exactMatch(seed))
+                pMapContainer->seedEdit->setVisible(true);
+
+            pMapContainer->setMapMapgenSeed(slValue[0], (MapGenerator)slValue[1].toUInt(), seed);
+            return;
+        }
+    }
+
     qWarning("Got bad config param from net");
 }
 
--- a/QTfrontend/gamecfgwidget.h	Tue Feb 08 02:43:07 2011 +0100
+++ b/QTfrontend/gamecfgwidget.h	Tue Feb 08 22:24:30 2011 +0300
@@ -23,6 +23,7 @@
 #include <QStringList>
 #include <QGroupBox>
 #include <QSpinBox>
+#include <QRegExp>
 
 #include "mapContainer.h"
 
@@ -77,6 +78,7 @@
     QCheckBox * bindEntries;
     QString curNetAmmoName;
     QString curNetAmmo;
+    QRegExp seedRegexp;
 
     void setNetAmmo(const QString& name, const QString& ammo);
 
--- a/QTfrontend/mapContainer.cpp	Tue Feb 08 02:43:07 2011 +0100
+++ b/QTfrontend/mapContainer.cpp	Tue Feb 08 22:24:30 2011 +0300
@@ -425,16 +425,21 @@
   //imageButt->setIconSize(imageButt->size());
 }
 
-void HWMapContainer::setSeed(const QString & seed)
+void HWMapContainer::intSetSeed(const QString & seed)
 {
     m_seed = seed;
     if (seed != seedEdit->text())
         seedEdit->setText(seed);
+}
+
+void HWMapContainer::setSeed(const QString & seed)
+{
+    intSetSeed(seed);
     if (chooseMap->currentIndex() < MAPGEN_MAP)
         updatePreview();
 }
 
-void HWMapContainer::setMap(const QString & map)
+void HWMapContainer::intSetMap(const QString & map)
 {
     int id = 0;
     for(int i = 0; i < chooseMap->count(); i++)
@@ -452,10 +457,15 @@
             pMap = 0;
         }
         chooseMap->setCurrentIndex(id);
-        updatePreview();
     }
 }
 
+void HWMapContainer::setMap(const QString &map)
+{
+    intSetMap(map);
+    updatePreview();
+}
+
 void HWMapContainer::setTheme(const QString & theme)
 {
     QList<QListWidgetItem *> items = lwThemes->findItems(theme, Qt::MatchExactly);
@@ -543,11 +553,16 @@
     updatePreview();
 }
 
-void HWMapContainer::setMapgen(MapGenerator m)
+void HWMapContainer::intSetMapgen(MapGenerator m)
 {
     mapgen = m;
     chooseMap->setCurrentIndex(m);
     emit mapgenChanged(m);
+}
+
+void HWMapContainer::setMapgen(MapGenerator m)
+{
+    intSetMapgen(m);
     updatePreview();
 }
 
@@ -620,3 +635,12 @@
         addInfoToPreview(mapImage);
     }
 }
+
+void HWMapContainer::setMapMapgenSeed(const QString & map, MapGenerator m, const QString & seed)
+{
+    setMap(map);
+    setMapgen(m);
+    setSeed(seed);
+
+    updatePreview();
+}
--- a/QTfrontend/mapContainer.h	Tue Feb 08 02:43:07 2011 +0100
+++ b/QTfrontend/mapContainer.h	Tue Feb 08 22:24:30 2011 +0300
@@ -67,6 +67,7 @@
   void setMapgen(MapGenerator m);
   void setMaze_size(int size);
   void setDrawnMapData(const QByteArray & ar);
+  void setMapMapgenSeed(const QString & map, MapGenerator m, const QString & seed);
 
  signals:
   void seedChanged(const QString & seed);
@@ -116,6 +117,9 @@
   int numMissions;
   DrawMapScene drawMapScene;
 
+  void intSetSeed(const QString & seed);
+  void intSetMap(const QString & map);
+  void intSetMapgen(MapGenerator m);
   void updatePreview();
 };
 
--- a/gameServer/HWProtoLobbyState.hs	Tue Feb 08 02:43:07 2011 +0100
+++ b/gameServer/HWProtoLobbyState.hs	Tue Feb 08 22:24:30 2011 +0300
@@ -42,7 +42,10 @@
                 nick $ irnc `client` masterID r,
                 head (Map.findWithDefault ["+gen+"] "MAP" (params r)),
                 head (Map.findWithDefault ["Default"] "SCHEME" (params r)),
-                head (Map.findWithDefault ["Default"] "AMMO" (params r))
+                head (Map.findWithDefault ["Default"] "AMMO" (params r)),
+                head (Map.findWithDefault ["Default"] "SCHEME" (params r)),
+                head (Map.findWithDefault ["0"] "MAPGEN" (params r)),
+                head (Map.findWithDefault ["seed"] "SEED" (params r))
                 ]
 
 
@@ -102,9 +105,10 @@
 
         toAnswer cl (paramName, paramStrs) = AnswerClients [sendChan cl] $ "CFG" : paramName : paramStrs
 
-        answerFullConfig cl pr = map (toAnswer cl) (leftConfigPart ++ rightConfigPart)
-            where
-            (leftConfigPart, rightConfigPart) = partition (\(p, _) -> p /= "MAP") $ Map.toList pr
+        answerFullConfig cl pr = map (toAnswer cl) $
+                 ("FULLMAPCONFIG", concatMap ((Map.!) pr) ["MAP", "MAPGEN", "SEED"])
+                 : ("SCHEME", pr Map.! "SCHEME")
+                 : (filter (\(p, _) -> p /= "SCHEME" && p /= "MAP" && p /= "MAPGEN" && p /= "SEED") $ Map.toList pr)
 
         answerTeams cl jRoom = let f = if gameinprogress jRoom then teamsAtStart else teams in answerAllTeams cl $ f jRoom
 
--- a/gameServer/Utils.hs	Tue Feb 08 02:43:07 2011 +0100
+++ b/gameServer/Utils.hs	Tue Feb 08 22:24:30 2011 +0300
@@ -80,26 +80,27 @@
 protoNumber2ver v = Map.findWithDefault "Unknown" v vermap
     where
         vermap = Map.fromList [
-            (17, "0.9.7-dev"),
-            (19, "0.9.7"),
-            (20, "0.9.8-dev"),
-            (21, "0.9.8"),
-            (22, "0.9.9-dev"),
-            (23, "0.9.9"),
-            (24, "0.9.10-dev"),
-            (25, "0.9.10"),
-            (26, "0.9.11-dev"),
-            (27, "0.9.11"),
-            (28, "0.9.12-dev"),
-            (29, "0.9.12"),
-            (30, "0.9.13-dev"),
-            (31, "0.9.13"),
-            (32, "0.9.14-dev"),
-            (33, "0.9.14"),
-            (34, "0.9.15-dev"),
-            (35, "0.9.14.1"),
-            (37, "0.9.15"),
-            (38, "0.9.16-dev")]
+            (17, "0.9.7-dev")
+            , (19, "0.9.7")
+            , (20, "0.9.8-dev")
+            , (21, "0.9.8")
+            , (22, "0.9.9-dev")
+            , (23, "0.9.9")
+            , (24, "0.9.10-dev")
+            , (25, "0.9.10")
+            , (26, "0.9.11-dev")
+            , (27, "0.9.11")
+            , (28, "0.9.12-dev")
+            , (29, "0.9.12")
+            , (30, "0.9.13-dev")
+            , (31, "0.9.13")
+            , (32, "0.9.14-dev")
+            , (33, "0.9.14")
+            , (34, "0.9.15-dev")
+            , (35, "0.9.14.1")
+            , (37, "0.9.15")
+            , (38, "0.9.16-dev")
+            ]
 
 askFromConsole :: B.ByteString -> IO B.ByteString
 askFromConsole msg = do