- Add state to engine callback for it to know what engine is sending qmlfrontend
authorunc0rr
Tue, 17 May 2016 23:18:08 +0300
branchqmlfrontend
changeset 11827 8c71c5a1172f
parent 11787 bcba7938ccb5
child 11828 a69124eb7ce7
- Add state to engine callback for it to know what engine is sending - Display suggested hogs number in preview
hedgewars/hwengine.pas
hedgewars/uFLTypes.pas
hedgewars/uFLUICallback.pas
qmlFrontend/flib.h
qmlFrontend/hwengine.cpp
qmlFrontend/hwengine.h
qmlFrontend/qml/qmlFrontend/GameConfig.qml
--- a/hedgewars/hwengine.pas	Sun May 01 21:09:45 2016 +0200
+++ b/hedgewars/hwengine.pas	Tue May 17 23:18:08 2016 +0300
@@ -427,6 +427,7 @@
 procedure Game;
 begin
     initEverything(true);
+    SendIPC('TG');
     GameRoutine;
     // clean up all the memory allocated
     freeEverything(true);
@@ -548,6 +549,7 @@
         GenPreviewAlpha(Preview);
     {$ENDIF}
         WriteLnToConsole('Sending preview...');
+        SendIPC('TP');
         SendIPCRaw(@Preview, sizeof(Preview));
         SendIPCRaw(@MaxHedgehogs, sizeof(byte));
         WriteLnToConsole('Preview sent, disconnect');
--- a/hedgewars/uFLTypes.pas	Sun May 01 21:09:45 2016 +0200
+++ b/hedgewars/uFLTypes.pas	Tue May 17 23:18:08 2016 +0300
@@ -6,8 +6,10 @@
     MAXARGS = 32;
 
 type
-    TMessageType = (mtRenderingPreview, mtPreview, mtAddPlayingTeam, mtRemovePlayingTeam
-                    , mtAddTeam, mtRemoveTeam, mtTeamColor, mtHedgehogsNumber, mtNetData
+    TMessageType = (mtRenderingPreview, mtPreview, mtPreviewHogCount
+                    , mtAddPlayingTeam, mtRemovePlayingTeam
+                    , mtAddTeam, mtRemoveTeam, mtTeamColor, mtHedgehogsNumber
+                    , mtNetData
                     , mtFlibEvent, mtConnected, mtDisconnected, mtAddLobbyClient
                     , mtRemoveLobbyClient, mtLobbyChatLine, mtAddRoomClient
                     , mtRemoveRoomClient, mtRoomChatLine, mtAddRoom, mtUpdateRoom
--- a/hedgewars/uFLUICallback.pas	Sun May 01 21:09:45 2016 +0200
+++ b/hedgewars/uFLUICallback.pas	Tue May 17 23:18:08 2016 +0300
@@ -10,10 +10,26 @@
 
 var uiCallbackPointer: pointer;
     uiCallbackFunction: TUICallback;
+    isGame: boolean;
 
 procedure engineMessageCallback(p: pointer; msg: PChar; len: Longword);
 begin
-    if len = 128 * 256 then uiCallbackFunction(uiCallbackPointer, mtPreview, msg, len)
+    if msg^ = 'T' then
+    begin
+        inc(msg);
+        isGame:= msg^ = 'G';
+        exit;
+    end;
+
+    if isGame then
+    begin
+    end
+    else begin
+        if len = 128 * 256 then
+            uiCallbackFunction(uiCallbackPointer, mtPreview, msg, len)
+        else if len = 1 then
+            uiCallbackFunction(uiCallbackPointer, mtPreviewHogCount, msg, len)
+    end;
 end;
 
 procedure registerUIMessagesCallback(p: pointer; f: TUICallback); cdecl;
--- a/qmlFrontend/flib.h	Sun May 01 21:09:45 2016 +0200
+++ b/qmlFrontend/flib.h	Tue May 17 23:18:08 2016 +0300
@@ -10,6 +10,7 @@
 enum MessageType {
     MSG_RENDERINGPREVIEW
     , MSG_PREVIEW
+    , MSG_PREVIEWHOGCOUNT
     , MSG_ADDPLAYINGTEAM
     , MSG_REMOVEPLAYINGTEAM
     , MSG_ADDTEAM
--- a/qmlFrontend/hwengine.cpp	Sun May 01 21:09:45 2016 +0200
+++ b/qmlFrontend/hwengine.cpp	Tue May 17 23:18:08 2016 +0300
@@ -166,6 +166,10 @@
         emit previewImageChanged();
         break;
     }
+    case MSG_PREVIEWHOGCOUNT: {
+        emit previewHogCountChanged((quint8)msg.data()[0]);
+        break;
+    }
     case MSG_ADDPLAYINGTEAM: {
         QStringList l = QString::fromUtf8(msg).split('\n');
         emit playingTeamAdded(l[1], l[0].toInt(), true);
--- a/qmlFrontend/hwengine.h	Sun May 01 21:09:45 2016 +0200
+++ b/qmlFrontend/hwengine.h	Tue May 17 23:18:08 2016 +0300
@@ -49,6 +49,7 @@
 
     void previewIsRendering();
     void previewImageChanged();
+    void previewHogCountChanged(int count);
     void localTeamAdded(const QString & teamName, int aiLevel);
     void localTeamRemoved(const QString & teamName);
 
--- a/qmlFrontend/qml/qmlFrontend/GameConfig.qml	Sun May 01 21:09:45 2016 +0200
+++ b/qmlFrontend/qml/qmlFrontend/GameConfig.qml	Tue May 17 23:18:08 2016 +0300
@@ -26,6 +26,9 @@
                 previewImage.visible = false
                 previewWaitImage.visible = true
             }
+            onPreviewHogCountChanged: {
+                hogCount.text = count
+            }
         }
 
         Image {