- Implement engine runs queue qmlfrontend
authorunc0rr
Mon, 30 Nov 2015 23:25:18 +0300
branchqmlfrontend
changeset 11439 23912c93935a
parent 11438 bca9afcc3a72
child 11440 28fb618d99c4
- Implement engine runs queue - Many small improvements
hedgewars/CMakeLists.txt
hedgewars/hwLibrary.pas
hedgewars/hwengine.pas
hedgewars/uFLGameConfig.pas
hedgewars/uFLNet.pas
hedgewars/uFLNetProtocol.pas
hedgewars/uFLRunQueue.pas
hedgewars/uFLTypes.pas
qmlFrontend/flib.h
qmlFrontend/hwengine.cpp
qmlFrontend/hwengine.h
qmlFrontend/qml/qmlFrontend/Chat.qml
qmlFrontend/qml/qmlFrontend/GameConfig.qml
qmlFrontend/qml/qmlFrontend/Lobby.qml
qmlFrontend/qml/qmlFrontend/Room.qml
qmlFrontend/qml/qmlFrontend/main.qml
qmlFrontend/qmlFrontend.qrc
qmlFrontend/res/iconTime.png
--- a/hedgewars/CMakeLists.txt	Sat Nov 28 00:18:04 2015 +0300
+++ b/hedgewars/CMakeLists.txt	Mon Nov 30 23:25:18 2015 +0300
@@ -113,6 +113,7 @@
     uFLNet.pas
     uFLNetProtocol.pas
     uFLNetTypes.pas
+    uFLRunQueue.pas
     uFLScripts.pas
     uFLSchemes.pas
     uFLTeams.pas
--- a/hedgewars/hwLibrary.pas	Sat Nov 28 00:18:04 2015 +0300
+++ b/hedgewars/hwLibrary.pas	Mon Nov 30 23:25:18 2015 +0300
@@ -50,6 +50,7 @@
     , uFLNet
     , uFLNetProtocol
     , uFLUICallback
+    , uFLRunQueue
     ;
 
 {$INCLUDE "config.inc"}
@@ -180,6 +181,7 @@
     // network
     connectOfficialServer,
     passNetData,
+    passFlibEvent,
     sendChatLine,
     joinRoom,
     partRoom,
--- a/hedgewars/hwengine.pas	Sat Nov 28 00:18:04 2015 +0300
+++ b/hedgewars/hwengine.pas	Mon Nov 30 23:25:18 2015 +0300
@@ -40,6 +40,7 @@
 procedure freeEverything(complete:boolean);
 
 implementation
+uses uFLUICallback, uFLTypes;
 
 ///////////////////////////////////////////////////////////////////////////////
 function DoTimer(Lag: LongInt): boolean;
@@ -518,16 +519,20 @@
 end;
 
 function EngineThread(p: pointer): Longint; cdecl; export;
+var e: TFLIBEvent;
 begin
     if GameType = gmtLandPreview then
         GenLandPreview()
     else Game();
 
+    e:= flibGameFinished;
+    sendUI(mtFlibEvent, @e, sizeof(e));
     EngineThread:= 0
 end;
 
 
 function RunEngine(argc: LongInt; argv: PPChar): Longint; cdecl; export;
+var t: PSDL_Thread;
 begin
     operatingsystem_parameter_argc:= argc;
     operatingsystem_parameter_argv:= argv;
@@ -545,6 +550,7 @@
     else
     begin
         SDL_CreateThread(@EngineThread, 'engine', nil);
+        SDL_DetachThread(t);
         RunEngine:= 0
     end
 end;
--- a/hedgewars/uFLGameConfig.pas	Sat Nov 28 00:18:04 2015 +0300
+++ b/hedgewars/uFLGameConfig.pas	Mon Nov 30 23:25:18 2015 +0300
@@ -28,32 +28,10 @@
 procedure netSetTemplate(template: LongInt);
 procedure updatePreviewIfNeeded;
 
-implementation
-uses uFLIPC, hwengine, uFLUtils, uFLTeams, uFLData, uFLSChemes, uFLAmmo, uFLUICallback;
-
-const
-    MAXCONFIGS = 5;
-    MAXARGS = 32;
+procedure sendConfig(config: PGameConfig);
 
-type
-    TGameConfig = record
-            seed: shortstring;
-            theme: shortstring;
-            script: shortstring;
-            map: shortstring;
-            scheme: TScheme;
-            ammo: TAmmo;
-            mapgen: LongInt;
-            featureSize: LongInt;
-            mazesize: LongInt;
-            template: LongInt;
-            gameType: TGameType;
-            teams: array[0..7] of TTeam;
-            arguments: array[0..Pred(MAXARGS)] of shortstring;
-            argv: array[0..Pred(MAXARGS)] of PChar;
-            argumentsNumber: Longword;
-            end;
-    PGameConfig = ^TGameConfig;
+implementation
+uses uFLIPC, uFLUtils, uFLTeams, uFLData, uFLSChemes, uFLAmmo, uFLUICallback, uFLRunQueue;
 
 var
     currentConfig: TGameConfig;
@@ -75,12 +53,16 @@
                 ipcToEngine('escript ' + getScriptPath(script));
             ipcToEngine('eseed ' + seed);
             ipcToEngine('e$mapgen ' + intToStr(mapgen));
+            ipcToEngine('e$template_filter ' + intToStr(template));
+            ipcToEngine('e$feature_size ' + intToStr(featureSize));
         end;
     gtLocal: begin
             if script <> 'Normal' then
                 ipcToEngine('escript ' + getScriptPath(script));
             ipcToEngine('eseed ' + seed);
             ipcToEngine('e$mapgen ' + intToStr(mapgen));
+            ipcToEngine('e$template_filter ' + intToStr(template));
+            ipcToEngine('e$feature_size ' + intToStr(featureSize));
             ipcToEngine('e$theme ' + theme);
 
             sendSchemeConfig(scheme);
@@ -100,28 +82,6 @@
 end;
 end;
 
-procedure queueExecution;
-var pConfig: PGameConfig;
-    i: Longword;
-begin
-    new(pConfig);
-    pConfig^:= currentConfig;
-
-    with pConfig^ do
-        for i:= 0 to Pred(MAXARGS) do
-        begin
-            if arguments[i][0] = #255 then 
-                arguments[i][255]:= #0
-            else
-                arguments[i][byte(arguments[i][0]) + 1]:= #0;
-            argv[i]:= @arguments[i][1]
-        end;
-
-    RunEngine(pConfig^.argumentsNumber, @pConfig^.argv);
-
-    sendConfig(pConfig)
-end;
-
 procedure resetGameConfig; cdecl;
 var i: Longword;
 begin
@@ -183,7 +143,7 @@
         teams[1].color:= 1;
         teams[1].botLevel:= 3;
 
-        queueExecution;
+        queueExecution(currentConfig);
     end;
 end;
 
@@ -200,7 +160,7 @@
         arguments[2]:= '--landpreview';
         argumentsNumber:= 3;
 
-        queueExecution;
+        queueExecution(currentConfig);
     end;
 end;
 
@@ -214,7 +174,7 @@
         arguments[2]:= '--nomusic';
         argumentsNumber:= 3;
 
-        queueExecution;
+        queueExecution(currentConfig);
     end;
 end;
 
--- a/hedgewars/uFLNet.pas	Sat Nov 28 00:18:04 2015 +0300
+++ b/hedgewars/uFLNet.pas	Mon Nov 30 23:25:18 2015 +0300
@@ -126,7 +126,6 @@
 var cmd: TCmdParami;
     s: shortstring;
 begin
-    writeln('handler__i');
     s:= getShortString();
     if s[0] = #0 then exit;
     cmd.cmd:= state.cmd;
@@ -138,8 +137,14 @@
 end;
 
 procedure handler_i;
+var cmd: TCmdParami;
+    s: shortstring;
 begin
-    writeln('handler_i');
+    s:= getShortString();
+    if s[0] = #0 then exit;
+    cmd.cmd:= state.cmd;
+    cmd.param1:= strToInt(s);
+    sendUI(mtNetData, @cmd, sizeof(cmd));
     handleTail()
 end;
 
--- a/hedgewars/uFLNetProtocol.pas	Sat Nov 28 00:18:04 2015 +0300
+++ b/hedgewars/uFLNetProtocol.pas	Mon Nov 30 23:25:18 2015 +0300
@@ -165,6 +165,7 @@
 procedure handler_CONNECTED(var p: TCmdParami);
 begin
     sendUI(mtConnected, nil, 0);
+    writeln('Server features version ', p.param1);
     sendNet('PROTO' + #10 + '51');
     sendNet('NICK' + #10 + 'qmlfrontend');
 end;
@@ -274,6 +275,7 @@
 
 procedure handler_PROTO(var p: TCmdParami);
 begin
+    writeln('Protocol ', p.param1)
 end;
 
 procedure handler_REMOVE_TEAM(var p: TCmdParamS);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hedgewars/uFLRunQueue.pas	Mon Nov 30 23:25:18 2015 +0300
@@ -0,0 +1,89 @@
+unit uFLRunQueue;
+interface
+uses uFLTypes;
+
+procedure queueExecution(var config: TGameConfig);
+procedure passFlibEvent(p: pointer); cdecl;
+
+implementation
+uses uFLGameConfig, hwengine, uFLData, uFLUICallback;
+
+var runQueue: PGameConfig = nil;
+
+procedure nextRun;
+begin
+    if runQueue <> nil then
+    begin
+        if runQueue^.gameType = gtPreview then
+            sendUI(mtRenderingPreview, nil, 0);
+
+        RunEngine(runQueue^.argumentsNumber, @runQueue^.argv);
+
+        sendConfig(runQueue)
+    end
+end;
+
+procedure cleanupConfig;
+var t: PGameConfig;
+begin
+    t:= runQueue;
+    runQueue:= t^.nextConfig;
+    dispose(t)
+end;
+
+procedure queueExecution(var config: TGameConfig);
+var pConfig, t, tt: PGameConfig;
+    i: Longword;
+begin
+    new(pConfig);
+    pConfig^:= config;
+
+    with pConfig^ do
+    begin
+        nextConfig:= nil;
+
+        for i:= 0 to Pred(MAXARGS) do
+        begin
+            if arguments[i][0] = #255 then
+                arguments[i][255]:= #0
+            else
+                arguments[i][byte(arguments[i][0]) + 1]:= #0;
+            argv[i]:= @arguments[i][1]
+        end;
+    end;
+
+    if runQueue = nil then
+    begin
+        runQueue:= pConfig;
+
+        nextRun
+    end else
+    begin
+        t:= runQueue;
+        while t^.nextConfig <> nil do 
+        begin
+            if (pConfig^.gameType = gtPreview) and (t^.nextConfig^.gameType = gtPreview) then
+            begin
+                tt:= t^.nextConfig;
+                pConfig^.nextConfig:= tt^.nextConfig;
+                t^.nextConfig:= pConfig;
+                dispose(tt);
+                exit // boo
+            end;
+            t:= t^.nextConfig;
+        end;
+        t^.nextConfig:= pConfig
+    end;
+end;
+
+procedure passFlibEvent(p: pointer); cdecl;
+begin
+    case TFLIBEvent(p^) of
+        flibGameFinished: begin
+                cleanupConfig;
+                nextRun
+                end;
+    end;
+end;
+
+end.
--- a/hedgewars/uFLTypes.pas	Sat Nov 28 00:18:04 2015 +0300
+++ b/hedgewars/uFLTypes.pas	Mon Nov 30 23:25:18 2015 +0300
@@ -1,15 +1,20 @@
 unit uFLTypes;
 interface
 
+const
+    MAXARGS = 32;
+
 type
-    TMessageType = (mtPreview, mtAddPlayingTeam, mtRemovePlayingTeam, mtAddTeam, mtRemoveTeam
-                    , mtTeamColor, mtNetData, mtConnected, mtDisconnected, mtAddLobbyClient
+    TMessageType = (mtRenderingPreview, mtPreview, mtAddPlayingTeam, mtRemovePlayingTeam, mtAddTeam, mtRemoveTeam
+                    , mtTeamColor, mtNetData, mtFlibEvent, mtConnected, mtDisconnected, mtAddLobbyClient
                     , mtRemoveLobbyClient, mtLobbyChatLine, mtAddRoomClient
                     , mtRemoveRoomClient, mtRoomChatLine, mtAddRoom, mtUpdateRoom
                     , mtRemoveRoom, mtError, mtWarning, mtMoveToLobby, mtMoveToRoom
                     , mtNickname, mtSeed, mtTheme, mtScript, mtFeatureSize, mtMapGen
                     , mtMap, mtMazeSize, mtTemplate);
 
+    TFLIBEvent = (flibGameFinished);
+
     TIPCMessage = record
                    str: shortstring;
                    len: Longword;
@@ -86,6 +91,26 @@
         end;
     PAmmo = ^TAmmo;
 
+    PGameConfig = ^TGameConfig;
+    TGameConfig = record
+            seed: shortstring;
+            theme: shortstring;
+            script: shortstring;
+            map: shortstring;
+            scheme: TScheme;
+            ammo: TAmmo;
+            mapgen: LongInt;
+            featureSize: LongInt;
+            mazesize: LongInt;
+            template: LongInt;
+            gameType: TGameType;
+            teams: array[0..7] of TTeam;
+            arguments: array[0..Pred(MAXARGS)] of shortstring;
+            argv: array[0..Pred(MAXARGS)] of PChar;
+            argumentsNumber: Longword;
+            nextConfig: PGameConfig;
+            end;
+
 implementation
 
 end.
--- a/qmlFrontend/flib.h	Sat Nov 28 00:18:04 2015 +0300
+++ b/qmlFrontend/flib.h	Mon Nov 30 23:25:18 2015 +0300
@@ -8,13 +8,15 @@
 #endif
 
 enum MessageType {
-    MSG_PREVIEW
+    MSG_RENDERINGPREVIEW
+    , MSG_PREVIEW
     , MSG_ADDPLAYINGTEAM
     , MSG_REMOVEPLAYINGTEAM
     , MSG_ADDTEAM
     , MSG_REMOVETEAM
     , MSG_TEAMCOLOR
     , MSG_NETDATA
+    , MSG_FLIBEVENT
     , MSG_CONNECTED
     , MSG_DISCONNECTED
     , MSG_ADDLOBBYCLIENT
@@ -67,6 +69,7 @@
 typedef void flibInit_t(const char * localPrefix, const char * userPrefix);
 typedef void flibFree_t();
 typedef void passNetData_t(const char * data);
+typedef void passFlibEvent_t(const char * data);
 typedef void sendChatLine_t(const char * msg);
 typedef void joinRoom_t(const char * roomName);
 typedef void partRoom_t(const char * message);
--- a/qmlFrontend/hwengine.cpp	Sat Nov 28 00:18:04 2015 +0300
+++ b/qmlFrontend/hwengine.cpp	Mon Nov 30 23:25:18 2015 +0300
@@ -36,6 +36,7 @@
 
     connectOfficialServer_t * flibConnectOfficialServer;
     passNetData_t * flibPassNetData;
+    passFlibEvent_t * flibPassFlibEvent;
     sendChatLine_t * flibSendChatLine;
     joinRoom_t * flibJoinRoom;
     partRoom_t * flibPartRoom;
@@ -85,6 +86,7 @@
 
     flibConnectOfficialServer = (connectOfficialServer_t*) hwlib.resolve("connectOfficialServer");
     flibPassNetData = (passNetData_t*) hwlib.resolve("passNetData");
+    flibPassFlibEvent = (passFlibEvent_t*) hwlib.resolve("passFlibEvent");
     flibSendChatLine = (sendChatLine_t*) hwlib.resolve("sendChatLine");
     flibJoinRoom = (joinRoom_t*) hwlib.resolve("joinRoom");
     flibPartRoom = (partRoom_t*) hwlib.resolve("partRoom");
@@ -141,7 +143,7 @@
     HWEngine * obj = (HWEngine *)context;
     QByteArray b = QByteArray(msg, len);
 
-    //qDebug() << "FLIPC in" << b.size() << b;
+    //qDebug() << "FLIPC in" << mt << " size = " << b.size();
 
     QMetaObject::invokeMethod(obj, "engineMessageHandler", Qt::QueuedConnection, Q_ARG(MessageType, mt), Q_ARG(QByteArray, b));
 }
@@ -150,6 +152,10 @@
 {
     switch(mt)
     {
+    case MSG_RENDERINGPREVIEW: {
+        emit previewIsRendering();
+        break;
+    }
     case MSG_PREVIEW: {
         PreviewImageProvider * preview = (PreviewImageProvider *)m_engine->imageProvider(QLatin1String("preview"));
         preview->setPixmap(msg);
@@ -182,6 +188,10 @@
         flibPassNetData(msg.constData());
         break;
     }
+    case MSG_FLIBEVENT: {
+        flibPassFlibEvent(msg.constData());
+        break;
+    }
     case MSG_CONNECTED: {
         emit netConnected();
         break;
--- a/qmlFrontend/hwengine.h	Sat Nov 28 00:18:04 2015 +0300
+++ b/qmlFrontend/hwengine.h	Mon Nov 30 23:25:18 2015 +0300
@@ -47,6 +47,7 @@
     void errorMessage(const QString & message);
     void warningMessage(const QString & message);
 
+    void previewIsRendering();
     void previewImageChanged();
     void localTeamAdded(const QString & teamName, int aiLevel);
     void localTeamRemoved(const QString & teamName);
--- a/qmlFrontend/qml/qmlFrontend/Chat.qml	Sat Nov 28 00:18:04 2015 +0300
+++ b/qmlFrontend/qml/qmlFrontend/Chat.qml	Mon Nov 30 23:25:18 2015 +0300
@@ -106,7 +106,6 @@
                     }
                 }
             }
-
         }
     }
 
@@ -128,6 +127,11 @@
             chatLines.addLine("***", qsTr("%1 quit (%2)").arg(clientName).arg(reason))
         }
     }
+
+    function clear() {
+        chatClientsModel.clear()
+        chatLinesModel.clear()
+    }
 }
 
 
--- a/qmlFrontend/qml/qmlFrontend/GameConfig.qml	Sat Nov 28 00:18:04 2015 +0300
+++ b/qmlFrontend/qml/qmlFrontend/GameConfig.qml	Mon Nov 30 23:25:18 2015 +0300
@@ -15,7 +15,8 @@
 
         Connections {
             target: HWEngine
-            onPreviewImageChanged: previewImage.source = "image://preview/" + HWEngine.currentSeed()
+            onPreviewImageChanged: previewImage.source = "image://preview/image"
+            onPreviewIsRendering: previewImage.source = "qrc:/res/iconTime.png"
         }
 
         Image {
@@ -25,6 +26,7 @@
             width: 256
             height: 128
             cache: false
+            source: "qrc:/res/iconTime.png"
         }
     }
 
--- a/qmlFrontend/qml/qmlFrontend/Lobby.qml	Sat Nov 28 00:18:04 2015 +0300
+++ b/qmlFrontend/qml/qmlFrontend/Lobby.qml	Mon Nov 30 23:25:18 2015 +0300
@@ -100,6 +100,7 @@
 
         Connections {
             target: HWEngine
+            onNetConnected: lobbyChat.clear()
             onLobbyChatLine: lobbyChat.addChatLine(nickname, line)
             onLobbyClientAdded: lobbyChat.addClient(clientName)
             onLobbyClientRemoved: lobbyChat.removeClient(clientName, reason)
--- a/qmlFrontend/qml/qmlFrontend/Room.qml	Sat Nov 28 00:18:04 2015 +0300
+++ b/qmlFrontend/qml/qmlFrontend/Room.qml	Mon Nov 30 23:25:18 2015 +0300
@@ -29,6 +29,7 @@
 
         Connections {
             target: HWEngine
+            onMovedToRoom: roomChat.clear()
             onRoomChatLine: roomChat.addChatLine(nickname, line)
             onRoomClientAdded: roomChat.addClient(clientName)
             onRoomClientRemoved: roomChat.removeClient(clientName, reason)
--- a/qmlFrontend/qml/qmlFrontend/main.qml	Sat Nov 28 00:18:04 2015 +0300
+++ b/qmlFrontend/qml/qmlFrontend/main.qml	Mon Nov 30 23:25:18 2015 +0300
@@ -84,7 +84,10 @@
         }
         onMovedToLobby: currentPage = "Lobby";
         onMovedToRoom: currentPage = "Room";
-        onNetDisconnected: currentPage = "First";
+        onNetDisconnected: {
+            currentPage = "First";
+            warningsBox.showMessage(message);
+        }
         onWarningMessage: warningsBox.showMessage(message);
         onErrorMessage: warningsBox.showMessage(message);
     }
--- a/qmlFrontend/qmlFrontend.qrc	Sat Nov 28 00:18:04 2015 +0300
+++ b/qmlFrontend/qmlFrontend.qrc	Mon Nov 30 23:25:18 2015 +0300
@@ -11,5 +11,6 @@
         <file>qml/qmlFrontend/Room.qml</file>
         <file>qml/qmlFrontend/Lobby.qml</file>
         <file>qml/qmlFrontend/Multiplayer.qml</file>
+        <file>res/iconTime.png</file>
     </qresource>
 </RCC>
Binary file qmlFrontend/res/iconTime.png has changed