Start work on running engine in network game qmlfrontend
authorunc0rr
Thu, 10 Dec 2015 23:49:12 +0300
branchqmlfrontend
changeset 11451 6e9b12864856
parent 11450 0c75fa9ce340
child 11452 78860824b5a5
Start work on running engine in network game
hedgewars/uFLGameConfig.pas
hedgewars/uFLIPC.pas
hedgewars/uFLNet.pas
hedgewars/uFLNetProtocol.pas
hedgewars/uFLRunQueue.pas
hedgewars/uFLTypes.pas
--- a/hedgewars/uFLGameConfig.pas	Thu Dec 10 00:33:45 2015 +0300
+++ b/hedgewars/uFLGameConfig.pas	Thu Dec 10 23:49:12 2015 +0300
@@ -37,6 +37,7 @@
 procedure updatePreviewIfNeeded;
 
 procedure sendConfig(config: PGameConfig);
+procedure runNetGame();
 
 implementation
 uses uFLIPC, uFLUtils, uFLTeams, uFLThemes, uFLSChemes, uFLAmmo, uFLUICallback, uFLRunQueue, uFLNet;
@@ -191,6 +192,20 @@
     end;
 end;
 
+procedure runNetGame();
+begin
+    with currentConfig do
+    begin
+        gameType:= gtNet;
+        arguments[0]:= '';
+        arguments[1]:= '--internal';
+        arguments[2]:= '--nomusic';
+        argumentsNumber:= 3;
+
+        queueExecution(currentConfig);
+    end;
+end;
+
 procedure tryAddTeam(teamName: PChar); cdecl;
 var msg: ansistring;
     i, hn, hedgehogsNumber: Longword;
--- a/hedgewars/uFLIPC.pas	Thu Dec 10 00:33:45 2015 +0300
+++ b/hedgewars/uFLIPC.pas	Thu Dec 10 23:49:12 2015 +0300
@@ -7,6 +7,7 @@
 
 procedure ipcToEngine(s: shortstring);
 procedure ipcToEngineRaw(p: pointer; len: Longword);
+procedure ipcCleanEngineQueue();
 //function  ipcReadFromEngine: shortstring;
 //function  ipcCheckFromEngine: boolean;
 
@@ -99,6 +100,36 @@
     ipcSend(msg, queueFrontend)
 end;
 
+procedure ipcCleanEngineQueue();
+var pmsg, t: PIPCMessage;
+    q: PIPCQueue;
+begin
+    q:= queueEngine;
+
+    SDL_LockMutex(q^.mut);
+
+    pmsg:= @q^.msg;
+    q^.last:= pmsg;
+
+    while pmsg <> nil do
+    begin
+        t:= pmsg^.next;
+
+        if pmsg^.buf <> nil then
+            FreeMem(pmsg^.buf, pmsg^.len);
+
+        if pmsg <> @q^.msg then
+            dispose(pmsg);
+        pmsg:= t
+    end;
+
+    q^.msg.next:= nil;
+    q^.msg.str[0]:= #0;
+    q^.msg.buf:= nil;
+
+    SDL_UnlockMutex(q^.mut);
+end;
+
 procedure ipcToNet(s: shortstring);
 var msg: TIPCMessage;
 begin
--- a/hedgewars/uFLNet.pas	Thu Dec 10 00:33:45 2015 +0300
+++ b/hedgewars/uFLNet.pas	Thu Dec 10 23:49:12 2015 +0300
@@ -53,7 +53,6 @@
 var cmd: TCmdParamL;
     f: boolean;
 begin
-    writeln('handler_ML');
     sendUI(mtNetData, @state.cmd, sizeof(state.cmd));
     cmd.cmd:= Succ(state.cmd);
 
--- a/hedgewars/uFLNetProtocol.pas	Thu Dec 10 00:33:45 2015 +0300
+++ b/hedgewars/uFLNetProtocol.pas	Thu Dec 10 23:49:12 2015 +0300
@@ -484,7 +484,10 @@
 end;
 
 procedure handler_RUN_GAME(var p: TCmdParam);
+var e: TFLIBEvent;
 begin
+    e:= flibRunNetGame;
+    sendUI(mtFlibEvent, @e, sizeof(e));
 end;
 
 procedure handler_SERVER_AUTH(var p: TCmdParamS);
--- a/hedgewars/uFLRunQueue.pas	Thu Dec 10 00:33:45 2015 +0300
+++ b/hedgewars/uFLRunQueue.pas	Thu Dec 10 23:49:12 2015 +0300
@@ -6,7 +6,7 @@
 procedure passFlibEvent(p: pointer); cdecl;
 
 implementation
-uses uFLGameConfig, hwengine, uFLData, uFLUICallback;
+uses uFLGameConfig, hwengine, uFLData, uFLUICallback, uFLIPC;
 
 var runQueue: PGameConfig = nil;
 
@@ -17,6 +17,7 @@
         if runQueue^.gameType = gtPreview then
             sendUI(mtRenderingPreview, nil, 0);
 
+        ipcCleanEngineQueue();
         RunEngine(runQueue^.argumentsNumber, @runQueue^.argv);
 
         sendConfig(runQueue)
@@ -82,7 +83,10 @@
         flibGameFinished: begin
                 cleanupConfig;
                 nextRun
-                end;
+            end;
+        flibRunNetGame: begin
+                runNetGame
+            end;
     end;
 end;
 
--- a/hedgewars/uFLTypes.pas	Thu Dec 10 00:33:45 2015 +0300
+++ b/hedgewars/uFLTypes.pas	Thu Dec 10 23:49:12 2015 +0300
@@ -15,7 +15,7 @@
                     , mtNickname, mtSeed, mtTheme, mtScript, mtFeatureSize, mtMapGen
                     , mtMap, mtMazeSize, mtTemplate, mtAmmo, mtScheme);
 
-    TFLIBEvent = (flibGameFinished);
+    TFLIBEvent = (flibGameFinished, flibRunNetGame);
 
     TClientFlag = (cfReady, cfRegistered, cfInRoom, cfContributor, cfInGame, cfRoomAdmin, cfServerAdmin);
 
@@ -37,7 +37,7 @@
     TIPCCallback = procedure (p: pointer; msg: PChar; len: Longword);
     TUICallback = procedure (p: pointer; msgType: TMessageType; msg: PChar; len: Longword); cdecl;
 
-    TGameType = (gtPreview, gtLocal);
+    TGameType = (gtPreview, gtLocal, gtNet);
     THedgehog = record
             name: shortstring;
             hat: shortstring;