# HG changeset patch # User unc0rr # Date 1158776653 0 # Node ID 401f4ea24715e85b4f4de64d6c2ec1f923d2f7fb # Parent 5667e6f387043da3594ee39cbfe78ab8e00b2504 Engine can generate land preview and send it via IPC diff -r 5667e6f38704 -r 401f4ea24715 hedgewars/hwengine.dpr --- a/hedgewars/hwengine.dpr Wed Sep 20 15:33:47 2006 +0000 +++ b/hedgewars/hwengine.dpr Wed Sep 20 18:24:13 2006 +0000 @@ -184,17 +184,25 @@ for i:= 0 to ParamCount do AddFileLog(inttostr(i) + ': ' + ParamStr(i)); {$ENDIF} -if ParamCount = 7 then - begin - val(ParamStr(1), cScreenWidth, c); - val(ParamStr(2), cScreenHeight, c); - cBitsStr:= ParamStr(3); - val(cBitsStr, cBits, c); - val(ParamStr(4), ipcPort, c); - cFullScreen:= ParamStr(5) = '1'; - isSoundEnabled:= ParamStr(6) = '1'; - cLocaleFName:= ParamStr(7); - end else OutError(errmsgShouldntRun, true) +case ParamCount of + 7: begin + val(ParamStr(1), cScreenWidth, c); + val(ParamStr(2), cScreenHeight, c); + cBitsStr:= ParamStr(3); + val(cBitsStr, cBits, c); + val(ParamStr(4), ipcPort, c); + cFullScreen:= ParamStr(5) = '1'; + isSoundEnabled:= ParamStr(6) = '1'; + cLocaleFName:= ParamStr(7); + end; + 2: begin + val(ParamStr(1), ipcPort, c); + GameType:= gmtLandPreview; + if ParamStr(2) <> 'landpreview' then OutError(errmsgShouldntRun, true); + end + else + OutError(errmsgShouldntRun, true) + end end; procedure ShowMainWindow; @@ -208,16 +216,10 @@ PixelFormat:= SDLPrimSurface.format; SDL_ShowCursor(0); end; + //////////////////////////////////////////////////////////////////////////////// -/////////////////////////////// m a i n //////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// - +procedure Game; begin -WriteLnToConsole('-= HedgeWars 0.2 =-'); -WriteLnToConsole(' -= by unC0Rr =- '); -GetParams; -Randomize; - WriteToConsole('Init SDL... '); SDLTry(SDL_Init(SDL_INIT_VIDEO) >= 0, true); WriteLnToConsole(msgOK); @@ -249,5 +251,30 @@ true); MainLoop +end; +procedure GenLandPreview; +begin +InitIPC; +SendIPCAndWaitReply('C'); +TryDo(InitStepsFlags = cifRandomize, + 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', + true); +GenPreview; +SendIPCRaw(@Preview, sizeof(Preview)); +SendIPCAndWaitReply('+'); +end; + +//////////////////////////////////////////////////////////////////////////////// +/////////////////////////////// m a i n //////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// + +begin +WriteLnToConsole('-= HedgeWars 0.2 =-'); +WriteLnToConsole(' -= by unC0Rr =- '); +GetParams; +Randomize; + +if GameType = gmtLandPreview then GenLandPreview + else Game end. diff -r 5667e6f38704 -r 401f4ea24715 hedgewars/uConsts.pas --- a/hedgewars/uConsts.pas Wed Sep 20 15:33:47 2006 +0000 +++ b/hedgewars/uConsts.pas Wed Sep 20 18:24:13 2006 +0000 @@ -38,7 +38,7 @@ type TStuff = (sConsoleBG, sPowerBar, sQuestion, sWindBar, sWindL, sWindR, sRopeNode); TGameState = (gsLandGen, gsStart, gsGame, gsConsole, gsExit); - TGameType = (gmtLocal, gmtDemo, gmtNet, gmtSave); + TGameType = (gmtLocal, gmtDemo, gmtNet, gmtSave, gmtLandPreview); TPathType = (ptNone, ptData, ptGraphics, ptThemes, ptCurrTheme, ptTeams, ptMaps, ptMapCurrent, ptDemos, ptSounds, ptGraves, ptFonts, ptForts, ptLocale); diff -r 5667e6f38704 -r 401f4ea24715 hedgewars/uIO.pas --- a/hedgewars/uIO.pas Wed Sep 20 15:33:47 2006 +0000 +++ b/hedgewars/uIO.pas Wed Sep 20 18:24:13 2006 +0000 @@ -40,6 +40,7 @@ procedure SendIPC(s: shortstring); procedure SendIPCXY(cmd: char; X, Y: SmallInt); +procedure SendIPCRaw(p: pointer; len: Longword); procedure SendIPCAndWaitReply(s: shortstring); procedure IPCCheckSock; procedure InitIPC; @@ -145,6 +146,11 @@ end end; +procedure SendIPCRaw(p: pointer; len: Longword); +begin +SDLNet_TCP_Send(IPCSock, p, len) +end; + procedure SendIPCXY(cmd: char; X, Y: SmallInt); var s: shortstring; begin diff -r 5667e6f38704 -r 401f4ea24715 hedgewars/uLand.pas --- a/hedgewars/uLand.pas Wed Sep 20 15:33:47 2006 +0000 +++ b/hedgewars/uLand.pas Wed Sep 20 18:24:13 2006 +0000 @@ -33,17 +33,21 @@ unit uLand; interface -uses SDLh, uGears; +uses SDLh, uGears, uLandTemplates; {$include options.inc} type TLandArray = packed array[0..1023, 0..2047] of LongWord; + TPreview = packed array[0..127, 0..31] of byte; var Land: TLandArray; LandSurface: PSDL_Surface; + Preview: TPreview; procedure GenMap; +procedure GenPreview; + implementation -uses uConsole, uStore, uMisc, uConsts, uRandom, uTeams, uIO, uLandTemplates, uLandObjects; +uses uConsole, uStore, uMisc, uConsts, uRandom, uTeams, uIO, uLandObjects; type TPixAr = record Count: Longword; @@ -420,7 +424,12 @@ procedure GenBlank(var Template: TEdgeTemplate); var pa: TPixAr; i: Longword; + y, x: Longword; begin +for y:= 0 to 1023 do + for x:= 0 to 2047 do + Land[y, x]:= COLOR_LAND; + with Template do begin if canMirror then @@ -462,12 +471,9 @@ procedure GenLandSurface; var tmpsurf: PSDL_Surface; - y, x: Longword; begin WriteLnToConsole('Generating land...'); -for y:= 0 to 1023 do - for x:= 0 to 2047 do - Land[y, x]:= COLOR_LAND; + GenBlank(EdgeTemplates[getrandom(Succ(High(EdgeTemplates)))]); AddProgress; @@ -562,6 +568,26 @@ {$IFDEF DEBUGFILE}LogLandDigest{$ENDIF} end; +procedure GenPreview; +var x, y, xx, yy, t, bit: integer; +begin +GenBlank(EdgeTemplates[getrandom(Succ(High(EdgeTemplates)))]); + +for y:= 0 to 127 do + for x:= 0 to 31 do + begin + Preview[y, x]:= 0; + for bit:= 0 to 7 do + begin + t:= 0; + for yy:= y * 8 to y * 8 + 7 do + for xx:= x * 64 + bit * 8 to x * 64 + bit * 8 + 7 do + if Land[yy, xx] <> 0 then inc(t); + if t > 31 then Preview[y, x]:= Preview[y, x] or ($80 shr bit) + end + end +end; + initialization end. diff -r 5667e6f38704 -r 401f4ea24715 hedgewars/uRandom.pas --- a/hedgewars/uRandom.pas Wed Sep 20 15:33:47 2006 +0000 +++ b/hedgewars/uRandom.pas Wed Sep 20 18:24:13 2006 +0000 @@ -57,6 +57,8 @@ procedure SetRandomSeed(Seed: shortstring); var i: Longword; begin +n:= 54; + if Length(Seed) > 54 then Seed:= copy(Seed, 1, 54); // not 55 to ensure we have odd numbers in cirbuf for i:= 0 to pred(Length(Seed)) do