Send seed to engine to receive random map previews
authorunC0Rr
Thu, 22 Nov 2018 13:40:58 +0100
changeset 14273 645e4591361f
parent 14272 3152d9fdb499
child 14274 0ae9885e1535
Send seed to engine to receive random map previews
qmlfrontend/game_config.cpp
qmlfrontend/game_config.h
qmlfrontend/hwengine.cpp
qmlfrontend/hwengine.h
rust/hedgewars-engine-messages/src/parser.rs
--- a/qmlfrontend/game_config.cpp	Thu Nov 22 13:39:51 2018 +0100
+++ b/qmlfrontend/game_config.cpp	Thu Nov 22 13:40:58 2018 +0100
@@ -1,6 +1,6 @@
 #include "game_config.h"
 
-GameConfig::GameConfig() : m_isPreview(true) { setPreview(m_isPreview); }
+GameConfig::GameConfig() {}
 
 const char** GameConfig::argv() const {
   m_argv.resize(m_arguments.size());
@@ -53,25 +53,6 @@
   cfgAppend("eammstore");
 }
 
-bool GameConfig::isPreview() const { return m_isPreview; }
-
-void GameConfig::setPreview(bool isPreview) {
-  m_isPreview = isPreview;
-
-  m_arguments.clear();
-
-  if (m_isPreview) {
-    m_arguments << ""
-                << "--internal"
-                << "--landpreview";
-
-  } else {
-    m_arguments << ""
-                << "--internal"
-                << "--nomusic";
-  }
-}
-
 void GameConfig::cfgAppend(const QByteArray& cmd) {
   Q_ASSERT(cmd.size() < 256);
 
--- a/qmlfrontend/game_config.h	Thu Nov 22 13:39:51 2018 +0100
+++ b/qmlfrontend/game_config.h	Thu Nov 22 13:40:58 2018 +0100
@@ -20,15 +20,11 @@
   void cmdMapgen(int mapgen);
   void cmdTeam(const Team& team);
 
-  bool isPreview() const;
-  void setPreview(bool isPreview);
-
  private:
   mutable QVector<const char*> m_argv;
   QList<QByteArray> m_arguments;
   QList<QByteArray> m_cfg;
   QList<Team> m_teams;
-  bool m_isPreview;
 
   void cfgAppend(const QByteArray& cmd);
 };
--- a/qmlfrontend/hwengine.cpp	Thu Nov 22 13:39:51 2018 +0100
+++ b/qmlfrontend/hwengine.cpp	Thu Nov 22 13:40:58 2018 +0100
@@ -34,9 +34,10 @@
 }
 
 void HWEngine::getPreview() {
-  m_seed = QUuid::createUuid().toByteArray();
-  m_gameConfig.cmdSeed(m_seed);
-  m_gameConfig.setPreview(true);
+  emit previewIsRendering();
+
+  m_gameConfig = GameConfig();
+  m_gameConfig.cmdSeed(QUuid::createUuid().toByteArray());
 
   EngineInstance engine;
   engine.sendConfig(m_gameConfig);
@@ -47,7 +48,8 @@
   colorTable.resize(256);
   for (int i = 0; i < 256; ++i) colorTable[i] = qRgba(255, 255, 0, i);
 
-  QImage previewImage(preview.land, preview.width, preview.height,
+  QImage previewImage(preview.land, static_cast<int>(preview.width),
+                      static_cast<int>(preview.height),
                       QImage::Format_Indexed8);
   previewImage.setColorTable(colorTable);
   previewImage.detach();
@@ -59,7 +61,6 @@
 }
 
 void HWEngine::runQuickGame() {
-  m_gameConfig.cmdSeed(m_seed);
   m_gameConfig.cmdTheme("Nature");
   Team team1;
   team1.name = "team1";
@@ -68,7 +69,6 @@
   team2.color = "7654321";
   m_gameConfig.cmdTeam(team1);
   m_gameConfig.cmdTeam(team2);
-  m_gameConfig.setPreview(false);
 
   // m_runQueue->queue(m_gameConfig);
 }
--- a/qmlfrontend/hwengine.h	Thu Nov 22 13:39:51 2018 +0100
+++ b/qmlfrontend/hwengine.h	Thu Nov 22 13:40:58 2018 +0100
@@ -38,7 +38,6 @@
   QQmlEngine* m_engine;
   PreviewImageProvider* m_previewProvider;
   GameConfig m_gameConfig;
-  QByteArray m_seed;
   int m_previewHedgehogsCount;
 };
 
--- a/rust/hedgewars-engine-messages/src/parser.rs	Thu Nov 22 13:39:51 2018 +0100
+++ b/rust/hedgewars-engine-messages/src/parser.rs	Thu Nov 22 13:40:58 2018 +0100
@@ -69,7 +69,7 @@
 
 named!(unordered_message<&[u8], UnorderedEngineMessage>, alt!(
       do_parse!(tag!("?") >> ( Ping ))
-    | do_parse!(tag!("!") >> ( Ping ))
+    | do_parse!(tag!("!") >> ( Pong ))
     | do_parse!(tag!("E") >> s: string_tail >> ( UnorderedEngineMessage::Error(s)) )
     | do_parse!(tag!("W") >> s: string_tail >> ( Warning(s)) )
     | do_parse!(tag!("s") >> s: string_tail >> ( ChatMessage(s)) )
@@ -81,6 +81,7 @@
 
 named!(config_message<&[u8], ConfigEngineMessage>, alt!(
     do_parse!(tag!("C") >> (ConfigRequest))
+    | do_parse!(tag!("eseed ") >> s: string_tail >> ( SetSeed(s)) )
 ));
 
 named!(timestamped_message<&[u8], (SyncedEngineMessage, u16)>,