# HG changeset patch # User unc0rr # Date 1411925594 -14400 # Node ID b0abef0ee78c133ffa963f56aa8816e08f825e7c # Parent 899a30018ede8de91e936999633edaa3e397bdb8 Quick Game PoC diff -r 899a30018ede -r b0abef0ee78c hedgewars/CMakeLists.txt --- 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 diff -r 899a30018ede -r b0abef0ee78c hedgewars/uFLGameConfig.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; diff -r 899a30018ede -r b0abef0ee78c hedgewars/uFLTypes.pas --- 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. diff -r 899a30018ede -r b0abef0ee78c qmlFrontend/flib.h --- 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); diff -r 899a30018ede -r b0abef0ee78c qmlFrontend/hwengine.cpp --- 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) diff -r 899a30018ede -r b0abef0ee78c qmlFrontend/hwengine.h --- 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: diff -r 899a30018ede -r b0abef0ee78c qmlFrontend/qml/qmlFrontend/GameConfig.qml --- 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 diff -r 899a30018ede -r b0abef0ee78c qmlFrontend/qml/qmlFrontend/LocalGame.qml --- 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 {