Send selected scheme config on engine initialization (WIP) qmlfrontend
authorunc0rr
Sun, 08 Feb 2015 00:10:05 +0300
branchqmlfrontend
changeset 10819 57e21f7621b0
parent 10817 48a53259fad8
child 10821 efb861d1489e
Send selected scheme config on engine initialization (WIP)
hedgewars/hwLibrary.pas
hedgewars/uFLGameConfig.pas
hedgewars/uFLSchemes.pas
hedgewars/uFLTypes.pas
qmlFrontend/CMakeLists.txt
qmlFrontend/flib.h
qmlFrontend/hwengine.cpp
qmlFrontend/hwengine.h
qmlFrontend/qml/qmlFrontend/GameConfig.qml
--- a/hedgewars/hwLibrary.pas	Sat Feb 07 23:26:14 2015 +0300
+++ b/hedgewars/hwLibrary.pas	Sun Feb 08 00:10:05 2015 +0300
@@ -158,6 +158,7 @@
     getSeed,
     setTheme,
     setScript,
+    setScheme,
     getThemesList,
     freeThemesList,
     getThemeIcon,
--- a/hedgewars/uFLGameConfig.pas	Sat Feb 07 23:26:14 2015 +0300
+++ b/hedgewars/uFLGameConfig.pas	Sun Feb 08 00:10:05 2015 +0300
@@ -13,13 +13,14 @@
 function  getSeed: PChar; cdecl;
 procedure setTheme(themeName: PChar); cdecl;
 procedure setScript(scriptName: PChar); cdecl;
+procedure setScheme(schemeName: PChar); cdecl;
 
 procedure tryAddTeam(teamName: PChar); cdecl;
 procedure tryRemoveTeam(teamName: PChar); cdecl;
 procedure changeTeamColor(teamName: PChar; dir: LongInt); cdecl;
 
 implementation
-uses uFLIPC, hwengine, uFLUtils, uFLTeams, uFLData;
+uses uFLIPC, hwengine, uFLUtils, uFLTeams, uFLData, uFLSChemes;
 
 var guiCallbackPointer: pointer;
     guiCallbackFunction: TGUICallback;
@@ -33,6 +34,7 @@
             seed: shortstring;
             theme: shortstring;
             script: shortstring;
+            scheme: TScheme;
             mapgen: Longint;
             gameType: TGameType;
             teams: array[0..7] of TTeam;
@@ -65,6 +67,8 @@
             ipcToEngine('e$mapgen ' + intToStr(mapgen));
             ipcToEngine('e$theme ' + theme);
 
+            sendSchemeConfig(scheme);
+
             i:= 0;
             while (i < 8) and (teams[i].hogsNumber > 0) do
                 begin
@@ -323,4 +327,13 @@
         currentConfig.script:= ''
 end;
 
+procedure setScheme(schemeName: PChar); cdecl;
+var scheme: PScheme;
+begin
+    scheme:= schemeByName(schemeName);
+
+    if scheme <> nil then
+        currentConfig.scheme:= scheme^
+end;
+
 end.
--- a/hedgewars/uFLSchemes.pas	Sat Feb 07 23:26:14 2015 +0300
+++ b/hedgewars/uFLSchemes.pas	Sun Feb 08 00:10:05 2015 +0300
@@ -5,53 +5,14 @@
 function getSchemesList: PPChar; cdecl;
 procedure freeSchemesList;
 
+function schemeByName(s: shortstring): PScheme;
+procedure sendSchemeConfig(var scheme: TScheme);
+
 implementation
 uses uFLUtils, uFLIPC, uPhysFSLayer, uFLData;
 
 const MAX_SCHEME_NAMES = 64;
 type
-    TScheme = record
-            schemeName
-            , scriptparam : shortstring;
-            fortsmode
-            , divteams
-            , solidland
-            , border
-            , lowgrav
-            , laser
-            , invulnerability
-            , mines
-            , vampiric
-            , karma
-            , artillery
-            , randomorder
-            , king
-            , placehog
-            , sharedammo
-            , disablegirders
-            , disablewind
-            , morewind
-            , tagteam
-            , bottomborder: boolean;
-            damagefactor
-            , turntime
-            , health
-            , suddendeath
-            , caseprobability
-            , minestime
-            , landadds
-            , minedudpct
-            , explosives
-            , minesnum
-            , healthprobability
-            , healthcaseamount
-            , waterrise
-            , healthdecrease
-            , ropepct
-            , getawaytime
-            , worldedge: LongInt
-        end;
-    PScheme = ^TScheme;
     TSchemeArray = array [0..0] of TScheme;
     PSchemeArray = ^TSchemeArray;
 var
@@ -152,9 +113,9 @@
                     scheme:= @schemes^[l - 1];
 
                     if copy(s, 1, 5) = 'name=' then
-                        tmpScheme. schemeName:= midStr(s, 6)
+                        tmpScheme.schemeName:= midStr(s, 6)
                     else if copy(s, 1, 12) = 'scriptparam=' then
-                        tmpScheme. schemeName:= midStr(s, 13) else
+                        tmpScheme.scriptparam:= midStr(s, 13) else
                     begin
                         ii:= 0;
                         repeat
@@ -208,6 +169,20 @@
     getSchemesList:= listOfSchemeNames
 end;
 
+function schemeByName(s: shortstring): PScheme;
+var i: Longword;
+    scheme: PScheme;
+begin
+    scheme:= schemesList;
+    i:= 0;
+    while (i < schemesNumber) and (scheme^.schemeName <> s) do
+    begin
+        inc(scheme);
+        inc(i)
+    end;
+
+    if i < schemesNumber then schemeByName:= scheme else schemeByName:= nil
+end;
 
 procedure freeSchemesList;
 begin
@@ -215,4 +190,15 @@
         FreeMem(schemesList, sizeof(schemesList^) * (schemesNumber + 1))
 end;
 
+
+procedure sendSchemeConfig(var scheme: TScheme);
+var i: Longword;
+begin
+    with scheme do
+    begin
+        ipcToEngine('e$turntime ' + inttostr(scheme.turntime));
+        ipcToEngine('e$minesnum ' + inttostr(scheme.minesnum));
+    end
+end;
+
 end.
--- a/hedgewars/uFLTypes.pas	Sat Feb 07 23:26:14 2015 +0300
+++ b/hedgewars/uFLTypes.pas	Sun Feb 08 00:10:05 2015 +0300
@@ -33,6 +33,49 @@
         end;
     PTeam = ^TTeam;
 
+    TScheme = record
+            schemeName
+            , scriptparam : shortstring;
+            fortsmode
+            , divteams
+            , solidland
+            , border
+            , lowgrav
+            , laser
+            , invulnerability
+            , mines
+            , vampiric
+            , karma
+            , artillery
+            , randomorder
+            , king
+            , placehog
+            , sharedammo
+            , disablegirders
+            , disablewind
+            , morewind
+            , tagteam
+            , bottomborder: boolean;
+            damagefactor
+            , turntime
+            , health
+            , suddendeath
+            , caseprobability
+            , minestime
+            , landadds
+            , minedudpct
+            , explosives
+            , minesnum
+            , healthprobability
+            , healthcaseamount
+            , waterrise
+            , healthdecrease
+            , ropepct
+            , getawaytime
+            , worldedge: LongInt
+        end;
+    PScheme = ^TScheme;
+
 implementation
 
 end.
--- a/qmlFrontend/CMakeLists.txt	Sat Feb 07 23:26:14 2015 +0300
+++ b/qmlFrontend/CMakeLists.txt	Sun Feb 08 00:10:05 2015 +0300
@@ -15,6 +15,7 @@
     previewimageprovider
     themeiconprovider
     qtquick2applicationviewer/qtquick2applicationviewer
+    flib.h
     )
 
 include_directories(${OPENGL_INCLUDE_DIR})
--- a/qmlFrontend/flib.h	Sat Feb 07 23:26:14 2015 +0300
+++ b/qmlFrontend/flib.h	Sun Feb 08 00:10:05 2015 +0300
@@ -37,6 +37,7 @@
 typedef char *getSeed_t();
 typedef void setTheme_t(const char * themeName);
 typedef void setScript_t(const char * scriptName);
+typedef void setScheme_t(const char * schemeName);
 typedef void flibInit_t(const char * localPrefix, const char * userPrefix);
 typedef void flibFree_t();
 
--- a/qmlFrontend/hwengine.cpp	Sat Feb 07 23:26:14 2015 +0300
+++ b/qmlFrontend/hwengine.cpp	Sun Feb 08 00:10:05 2015 +0300
@@ -15,6 +15,7 @@
     getSeed_t *flibGetSeed;
     setTheme_t *flibSetTheme;
     setScript_t *flibSetScript;
+    setScheme_t *flibSetScheme;
     getPreview_t *flibGetPreview;
     runQuickGame_t *flibRunQuickGame;
     runLocalGame_t *flibRunLocalGame;
@@ -57,6 +58,7 @@
     flibSetSeed = (setSeed_t*) hwlib.resolve("setSeed");
     flibSetTheme = (setTheme_t*) hwlib.resolve("setTheme");
     flibSetScript = (setScript_t*) hwlib.resolve("setScript");
+    flibSetScheme = (setScheme_t*) hwlib.resolve("setScheme");
 
     flibGetThemesList = (getThemesList_t*) hwlib.resolve("getThemesList");
     flibFreeThemesList = (freeThemesList_t*) hwlib.resolve("freeThemesList");
@@ -233,3 +235,8 @@
 {
     flibSetScript(script.toUtf8().constData());
 }
+
+void HWEngine::setScheme(const QString &scheme)
+{
+    flibSetScheme(scheme.toUtf8().constData());
+}
--- a/qmlFrontend/hwengine.h	Sat Feb 07 23:26:14 2015 +0300
+++ b/qmlFrontend/hwengine.h	Sun Feb 08 00:10:05 2015 +0300
@@ -27,6 +27,7 @@
 
     Q_INVOKABLE void setTheme(const QString & theme);
     Q_INVOKABLE void setScript(const QString & script);
+    Q_INVOKABLE void setScheme(const QString & scheme);
 
     Q_INVOKABLE void tryAddTeam(const QString & teamName);
     Q_INVOKABLE void tryRemoveTeam(const QString & teamName);
--- a/qmlFrontend/qml/qmlFrontend/GameConfig.qml	Sat Feb 07 23:26:14 2015 +0300
+++ b/qmlFrontend/qml/qmlFrontend/GameConfig.qml	Sun Feb 08 00:10:05 2015 +0300
@@ -127,7 +127,7 @@
                  anchors.fill: parent
                  onClicked: {
                      cbScheme.currentIndex = index
-                     //HWEngine.setScheme(schemeName.text)
+                     HWEngine.setScheme(schemeName.text)
                  }
             }
         }