Forráskód Böngészése

Migrate to qtprotobuf 0.1.0

Alexey Edelev 5 éve
szülő
commit
5146ca6dac
4 módosított fájl, 19 hozzáadás és 29 törlés
  1. 1 0
      gui/qtprotobuf
  2. 8 8
      gui/visualizermodel.cpp
  3. 1 1
      qtprotobuf
  4. 9 20
      snakesimulator/snakesimulatorui/main.cpp

+ 1 - 0
gui/qtprotobuf

@@ -0,0 +1 @@
+../qtprotobuf

+ 8 - 8
gui/visualizermodel.cpp

@@ -69,29 +69,29 @@ VisualizerModel::VisualizerModel(std::shared_ptr<RemoteControlClient> &client, Q
         sizesChanged();
     });
 
-    QObject::connect(client.get(), &remotecontrol::RemoteControlClient::ActivationsUpdated, [this](const remotecontrol::LayerMatrix &activations) {
+    auto subscription = client->subscribeActivationsUpdates({});
+    QObject::connect(subscription, &QtProtobuf::QGrpcSubscription::updated, [this, subscription]() {
         if (m_layers.isEmpty()) {
             return;
         }
+        auto activations = subscription->read<remotecontrol::LayerMatrix>();
         auto layer = m_layers[activations.layer()];
         layer->m_activations.updateValues(Dense(activations.matrix().matrix()));
         layer->m_actiovationTrigger.updateLayer();
     });
-    QObject::connect(client.get(), &remotecontrol::RemoteControlClient::WeightsUpdated, [this](const remotecontrol::LayerMatrix &weights) {
+
+    subscription = client->subscribeWeightsUpdates({});
+    QObject::connect(subscription, &QtProtobuf::QGrpcSubscription::updated, [this, subscription]() {
         if (m_layers.isEmpty()) {
             return;
         }
+        auto weights = subscription->read<remotecontrol::LayerMatrix>();
         auto layer = m_layers[weights.layer()];
         layer->m_weights.updateValues(Dense(weights.matrix().matrix()));
         layer->m_weightTrigger.updateLayer();
     });
 
-    QObject::connect(client.get(), &remotecontrol::RemoteControlClient::StateUpdated, [this](const remotecontrol::NetworkState &state) {
-        m_networkState->setState(state.state());
-    });
-    client->subscribeActivationsUpdates({});
-    client->subscribeWeightsUpdates({});
-    client->subscribeStateUpdates({});
+    subscription = client->subscribeStateUpdates({}, m_networkState);
 }
 
 ValueIndicator *VisualizerModel::activation(int layer, int row)

+ 1 - 1
qtprotobuf

@@ -1 +1 @@
-Subproject commit c8eb828acfabd26e09dea95865a00ab40833ee96
+Subproject commit 6742f1167b945f2eee5032b997cf9250778a0e93

+ 9 - 20
snakesimulator/snakesimulatorui/main.cpp

@@ -50,31 +50,20 @@ int main(int argc, char *argv[])
     ClientWrapper *wrap = new ClientWrapper(client.get());
 
     snakesimulator::Snake *snake = new snakesimulator::Snake;
-    snakesimulator::Field *field = new snakesimulator::Field;
-    snakesimulator::Stats *stats = new snakesimulator::Stats;
-    snakesimulator::PlayingBestState *isPlaying = new snakesimulator::PlayingBestState;
+    QPointer<snakesimulator::Field> field = new snakesimulator::Field;
+    QPointer<snakesimulator::Stats> stats = new snakesimulator::Stats;
+    QPointer<snakesimulator::PlayingBestState> isPlaying = new snakesimulator::PlayingBestState;
 
-    QObject::connect(client.get(), &snakesimulator::SnakeSimulatorClient::isPlayingUpdated, [isPlaying](const snakesimulator::PlayingBestState & _isPlaying){
-        *isPlaying = _isPlaying;
-    });
+    client->subscribeFieldUpdates({}, field);
+    client->subscribeStatsUpdates({}, stats);
+    client->subscribeIsPlayingUpdates({}, isPlaying);
 
-    QObject::connect(client.get(), &snakesimulator::SnakeSimulatorClient::fieldUpdated, [field](const snakesimulator::Field & _field){
-        *field = _field;
-    });
+    auto subscription = client->subscribeSnakeUpdates({});
 
-    QObject::connect(client.get(), &snakesimulator::SnakeSimulatorClient::snakeUpdated, [snake](const snakesimulator::Snake & _snake){
-        *snake = _snake;
+    QObject::connect(subscription, &QtProtobuf::QGrpcSubscription::updated, [subscription, snake](){
+        snake->setPoints(subscription->read<snakesimulator::Snake>().points()); //Issue https://github.com/semlanik/qtprotobuf/issues/48
     });
 
-    QObject::connect(client.get(), &snakesimulator::SnakeSimulatorClient::statsUpdated, [stats](const snakesimulator::Stats & _stats){
-        *stats = _stats;
-    });
-
-    client->subscribeFieldUpdates({});
-    client->subscribeSnakeUpdates({});
-    client->subscribeStatsUpdates({});
-    client->subscribeIsPlayingUpdates({});
-
     QQmlApplicationEngine engine;
     engine.rootContext()->setContextProperty("field", field);
     engine.rootContext()->setContextProperty("snake", snake);