Quick Game PoC qmlfrontend
authorunc0rr
Sun, 28 Sep 2014 21:33:14 +0400
branchqmlfrontend
changeset 10432 b0abef0ee78c
parent 10430 899a30018ede
child 10434 1614b13ad35e
Quick Game PoC
hedgewars/CMakeLists.txt
hedgewars/uFLGameConfig.pas
hedgewars/uFLTypes.pas
qmlFrontend/flib.h
qmlFrontend/hwengine.cpp
qmlFrontend/hwengine.h
qmlFrontend/qml/qmlFrontend/GameConfig.qml
qmlFrontend/qml/qmlFrontend/LocalGame.qml
--- a/hedgewars/CMakeLists.txt	Sun Sep 28 01:17:55 2014 +0400
+++ b/hedgewars/CMakeLists.txt	Sun Sep 28 21:33:14 2014 +0400
@@ -103,6 +103,8 @@
     uFLIPC.pas
     uFLTypes.pas
     uFLGameConfig.pas
+    uFLTeams.pas
+    uFLUtils.pas
 
     #these interact with everything, so compile last
     uScript.pas
--- a/hedgewars/uFLGameConfig.pas	Sun Sep 28 01:17:55 2014 +0400
+++ b/hedgewars/uFLGameConfig.pas	Sun Sep 28 21:33:14 2014 +0400
@@ -12,7 +12,7 @@
 function  getSeed: PChar; cdecl;
 
 implementation
-uses uFLIPC, hwengine;
+uses uFLIPC, hwengine, uFLUtils, uFLTeams;
 
 var guiCallbackPointer: pointer;
     guiCallbackFunction: TGUICallback;
@@ -22,26 +22,11 @@
     MAXARGS = 32;
 
 type
-    TGameType = (gtPreview, gtLocal);
-    THedgehog = record
-            name: shortstring;
-            hat: shortstring;
-            end;
-    TTeam = record
-            teamName: shortstring;
-            flag: shortstring;
-            graveName: shortstring;
-            fortName: shortstring;
-            owner: shortstring;
-            extDriven: boolean;
-            botLevel: Longword;
-            hedgehogs: array[0..7] of THedgehog;
-            hogsNumber: Longword;
-            end;
     TGameConfig = record
             seed: shortstring;
             theme: shortstring;
             script: shortstring;
+            mapgen: Longint;
             gameType: TGameType;
             teams: array[0..7] of TTeam;
             arguments: array[0..Pred(MAXARGS)] of shortstring;
@@ -50,19 +35,40 @@
             end;
     PGameConfig = ^TGameConfig;
 
-var currentConfig: TGameConfig;
-    str2PCharBuffer: array[0..255] of char;
+var
+    currentConfig: TGameConfig;
+
 
-function str2PChar(const s: shortstring): PChar;
-var i: Integer;
+procedure sendConfig(config: PGameConfig);
+var i: Longword;
+begin
+with config^ do
 begin
-   for i:= 1 to Length(s) do
-      begin
-      str2PCharBuffer[i - 1] := s[i];
-      end;
-   str2PCharBuffer[Length(s)]:= #0;
-   str2PChar:= @(str2PCharBuffer[0]);
-end;    
+    case gameType of
+    gtPreview: begin
+            ipcToEngine('eseed ' + seed);
+            ipcToEngine('e$mapgen ' + intToStr(mapgen));
+        end;
+    gtLocal: begin
+            ipcToEngine('eseed ' + seed);
+            ipcToEngine('e$mapgen ' + intToStr(mapgen));
+            i:= 0;
+            while (i < 8) and (teams[i].hogsNumber > 0) do
+                begin
+                    ipcToEngine('eammloadt 93919294221991210322351110012000000002111001010111110001');
+                    ipcToEngine('eammprob 04050405416006555465544647765766666661555101011154111111');
+                    ipcToEngine('eammdelay 00000000000002055000000400070040000000002200000006000200');
+                    ipcToEngine('eammreinf 13111103121111111231141111111111111112111111011111111111');
+                    ipcToEngine('eammstore');
+                    sendTeamConfig(teams[i]);
+                    inc(i)
+                end;
+        end;
+    end;
+
+    ipcToEngine('!');
+end;
+end;
 
 procedure queueExecution;
 var pConfig: PGameConfig;
@@ -82,6 +88,8 @@
         end;
 
     RunEngine(pConfig^.argumentsNumber, @pConfig^.argv);
+
+    sendConfig(pConfig)
 end;
 
 procedure resetGameConfig; cdecl;
@@ -100,7 +108,22 @@
 
 procedure runQuickGame; cdecl;
 begin
+    with currentConfig do
+    begin
+        gameType:= gtLocal;
+        arguments[0]:= '';
+        arguments[1]:= '--internal';
+        arguments[2]:= '--nosound';
+        argumentsNumber:= 3;
 
+        teams[0]:= createRandomTeam;
+        teams[0].color:= '6341088';
+        teams[1]:= createRandomTeam;
+        teams[1].color:= '2113696';
+        teams[1].botLevel:= 1;
+
+        queueExecution;
+    end;
 end;
 
 procedure getPreview; cdecl;
@@ -114,10 +137,6 @@
         argumentsNumber:= 3;
 
         queueExecution;
-
-        ipcToEngine('eseed ' + seed);
-        ipcToEngine('e$mapgen 0');
-        ipcToEngine('!');
     end;
 end;
 
--- a/hedgewars/uFLTypes.pas	Sun Sep 28 01:17:55 2014 +0400
+++ b/hedgewars/uFLTypes.pas	Sun Sep 28 21:33:14 2014 +0400
@@ -9,9 +9,28 @@
                    len: Longword;
                    buf: Pointer
                end;
+
     TIPCCallback = procedure (p: pointer; msg: PChar; len: Longword);
     TGUICallback = procedure (p: pointer; msgType: TMessageType; msg: PChar; len: Longword); cdecl;
 
+    TGameType = (gtPreview, gtLocal);
+    THedgehog = record
+            name: shortstring;
+            hat: shortstring;
+            end;
+    TTeam = record
+            teamName: shortstring;
+            flag: shortstring;
+            graveName: shortstring;
+            fortName: shortstring;
+            owner: shortstring;
+            color: shortstring;
+            extDriven: boolean;
+            botLevel: Longword;
+            hedgehogs: array[0..7] of THedgehog;
+            hogsNumber: Longword;
+            end;
+
 implementation
 
 end.
--- a/qmlFrontend/flib.h	Sun Sep 28 01:17:55 2014 +0400
+++ b/qmlFrontend/flib.h	Sun Sep 28 21:33:14 2014 +0400
@@ -25,6 +25,7 @@
 typedef void RunEngine_t(int argc, const char ** argv);
 typedef void registerGUIMessagesCallback_t(void * context, void (*)(void * context, MessageType mt, const char * msg, uint32_t len));
 typedef void getPreview_t();
+typedef void runQuickGame_t();
 typedef void setSeed_t(const char * seed);
 typedef char *getSeed_t();
 typedef void flibInit_t(const char * localPrefix, const char * userPrefix);
--- a/qmlFrontend/hwengine.cpp	Sun Sep 28 01:17:55 2014 +0400
+++ b/qmlFrontend/hwengine.cpp	Sun Sep 28 21:33:14 2014 +0400
@@ -13,6 +13,7 @@
     setSeed_t *flibSetSeed;
     getSeed_t *flibGetSeed;
     getPreview_t *flibGetPreview;
+    runQuickGame_t *flibRunQuickGame;
     flibInit_t *flibInit;
     flibFree_t *flibFree;
 }
@@ -35,10 +36,11 @@
     flibSetSeed = (setSeed_t*) hwlib.resolve("setSeed");
     flibGetSeed = (getSeed_t*) hwlib.resolve("getSeed");
     flibGetPreview = (getPreview_t*) hwlib.resolve("getPreview");
+    flibRunQuickGame = (runQuickGame_t*) hwlib.resolve("runQuickGame");
     flibInit = (flibInit_t*) hwlib.resolve("flibInit");
     flibFree = (flibFree_t*) hwlib.resolve("flibFree");
 
-    flibInit(".", "~/.hedgewars");
+    flibInit("/usr/home/unC0Rr/Sources/Hedgewars/Hedgewars-GC/share/hedgewars/Data", "~/.hedgewars");
     flibRegisterGUIMessagesCallback(this, &guiMessagesCallback);
 }
 
@@ -53,6 +55,12 @@
     flibGetPreview();
 }
 
+void HWEngine::runQuickGame()
+{
+    flibSetSeed(QUuid::createUuid().toString().toLatin1());
+    flibRunQuickGame();
+}
+
 static QObject *hwengine_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
 {
     Q_UNUSED(scriptEngine)
--- a/qmlFrontend/hwengine.h	Sun Sep 28 01:17:55 2014 +0400
+++ b/qmlFrontend/hwengine.h	Sun Sep 28 21:33:14 2014 +0400
@@ -19,6 +19,7 @@
 
     static void exposeToQML();
     Q_INVOKABLE void getPreview();
+    Q_INVOKABLE void runQuickGame();
     Q_INVOKABLE QString currentSeed();
     
 signals:
--- a/qmlFrontend/qml/qmlFrontend/GameConfig.qml	Sun Sep 28 01:17:55 2014 +0400
+++ b/qmlFrontend/qml/qmlFrontend/GameConfig.qml	Sun Sep 28 21:33:14 2014 +0400
@@ -9,9 +9,7 @@
         width: 150
         height: 150
 
-        onClicked: {
-            HWEngine.getPreview()
-        }
+        onClicked: HWEngine.getPreview()
 
         Connections {
             target: HWEngine
--- a/qmlFrontend/qml/qmlFrontend/LocalGame.qml	Sun Sep 28 01:17:55 2014 +0400
+++ b/qmlFrontend/qml/qmlFrontend/LocalGame.qml	Sun Sep 28 21:33:14 2014 +0400
@@ -1,5 +1,5 @@
 import QtQuick 2.0
-//import Hedgewars.Engine 1.0
+import Hedgewars.Engine 1.0
 
 Rectangle {
     HWButton {
@@ -8,6 +8,8 @@
         y: 66
         width: 150
         height: 150
+
+        onClicked: HWEngine.runQuickGame()
     }
 
     HWButton {