# HG changeset patch # User unc0rr # Date 1291494620 -10800 # Node ID 6de30ddc184e7b32bdeb4d733b19d19bef832c98 # Parent 7351e6f1ee281f72f2df5ca9ddd075efad2da15b# Parent b69f43f07cd7c56445c033798a8ab3c7bfb86030 merge diff -r b69f43f07cd7 -r 6de30ddc184e hedgewars/CMakeLists.txt --- a/hedgewars/CMakeLists.txt Sat Dec 04 15:09:19 2010 -0500 +++ b/hedgewars/CMakeLists.txt Sat Dec 04 23:30:20 2010 +0300 @@ -60,6 +60,7 @@ uLand.pas uLandGraphics.pas uLandObjects.pas + uLandPainted.pas uLandTemplates.pas uLandTexture.pas uLocale.pas diff -r b69f43f07cd7 -r 6de30ddc184e hedgewars/uLand.pas --- a/hedgewars/uLand.pas Sat Dec 04 15:09:19 2010 -0500 +++ b/hedgewars/uLand.pas Sat Dec 04 23:30:20 2010 +0300 @@ -35,7 +35,7 @@ implementation uses uConsole, uStore, uRandom, uLandObjects, uIO, uLandTexture, sysutils, - uVariables, uUtils, uCommands, Adler32, uDebug; + uVariables, uUtils, uCommands, Adler32, uDebug, uLandPainted; operator=(const a, b: direction) c: Boolean; begin @@ -496,57 +496,57 @@ i: Longword; y, x: Longword; begin -for y:= 0 to LAND_HEIGHT - 1 do - for x:= 0 to LAND_WIDTH - 1 do - Land[y, x]:= lfBasic; - -{$HINTS OFF} -SetPoints(Template, pa); -{$HINTS ON} -for i:= 1 to Template.BezierizeCount do - begin - BezierizeEdge(pa, _0_5); - RandomizePoints(pa); - RandomizePoints(pa) - end; -for i:= 1 to Template.RandPassesCount do RandomizePoints(pa); -BezierizeEdge(pa, _0_1); - -DrawEdge(pa, 0); - -with Template do - for i:= 0 to pred(FillPointsCount) do - with FillPoints^[i] do - FillLand(x, y); - -DrawEdge(pa, lfBasic); - -MaxHedgehogs:= Template.MaxHedgehogs; -hasGirders:= Template.hasGirders; -playHeight:= Template.TemplateHeight; -playWidth:= Template.TemplateWidth; -leftX:= ((LAND_WIDTH - playWidth) div 2); -rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1; -topY:= LAND_HEIGHT - playHeight; - -// force to only cavern even if a cavern map is invertable if cTemplateFilter = 4 ? -if (cTemplateFilter = 4) or - (Template.canInvert and (getrandom(2) = 0)) or - (not Template.canInvert and Template.isNegative) then - begin - hasBorder:= true; for y:= 0 to LAND_HEIGHT - 1 do for x:= 0 to LAND_WIDTH - 1 do - if (y < topY) or (x < leftX) or (x > rightX) then - Land[y, x]:= 0 - else - begin - if Land[y, x] = 0 then - Land[y, x]:= lfBasic - else if Land[y, x] = lfBasic then - Land[y, x]:= 0; - end; - end; + Land[y, x]:= lfBasic; + {$HINTS OFF} + SetPoints(Template, pa); + {$HINTS ON} + for i:= 1 to Template.BezierizeCount do + begin + BezierizeEdge(pa, _0_5); + RandomizePoints(pa); + RandomizePoints(pa) + end; + for i:= 1 to Template.RandPassesCount do RandomizePoints(pa); + BezierizeEdge(pa, _0_1); + + + DrawEdge(pa, 0); + + with Template do + for i:= 0 to pred(FillPointsCount) do + with FillPoints^[i] do + FillLand(x, y); + + DrawEdge(pa, lfBasic); + + MaxHedgehogs:= Template.MaxHedgehogs; + hasGirders:= Template.hasGirders; + playHeight:= Template.TemplateHeight; + playWidth:= Template.TemplateWidth; + leftX:= ((LAND_WIDTH - playWidth) div 2); + rightX:= (playWidth + ((LAND_WIDTH - playWidth) div 2)) - 1; + topY:= LAND_HEIGHT - playHeight; + + // HACK: force to only cavern even if a cavern map is invertable if cTemplateFilter = 4 ? + if (cTemplateFilter = 4) or + (Template.canInvert and (getrandom(2) = 0)) or + (not Template.canInvert and Template.isNegative) then + begin + hasBorder:= true; + for y:= 0 to LAND_HEIGHT - 1 do + for x:= 0 to LAND_WIDTH - 1 do + if (y < topY) or (x < leftX) or (x > rightX) then + Land[y, x]:= 0 + else + begin + if Land[y, x] = 0 then + Land[y, x]:= lfBasic + else if Land[y, x] = lfBasic then + Land[y, x]:= 0; + end; + end; end; function SelectTemplate: LongInt; diff -r b69f43f07cd7 -r 6de30ddc184e hedgewars/uLandPainted.pas --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hedgewars/uLandPainted.pas Sat Dec 04 23:30:20 2010 +0300 @@ -0,0 +1,126 @@ +(* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2010 Andrey Korotaev + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + *) + +{$INCLUDE "options.inc"} + +unit uLandPainted; + +interface + +procedure LoadFromFile(fileName: shortstring); + +implementation +uses uLandGraphics, uConsts, uUtils, SDLh; + +type PointRec = packed record + X, Y: SmallInt; + flags: byte; + end; + +procedure DrawLineOnLand(X1, Y1, X2, Y2: LongInt); +var eX, eY, dX, dY: LongInt; + i, sX, sY, x, y, d: LongInt; + b: boolean; + len: LongWord; +begin + len:= 0; + if (X1 = X2) and (Y1 = Y2) then + begin + exit + end; + eX:= 0; + eY:= 0; + dX:= X2 - X1; + dY:= Y2 - Y1; + + if (dX > 0) then sX:= 1 + else + if (dX < 0) then + begin + sX:= -1; + dX:= -dX + end else sX:= dX; + + if (dY > 0) then sY:= 1 + else + if (dY < 0) then + begin + sY:= -1; + dY:= -dY + end else sY:= dY; + + if (dX > dY) then d:= dX + else d:= dY; + + x:= X1; + y:= Y1; + + for i:= 0 to d do + begin + inc(eX, dX); + inc(eY, dY); + b:= false; + if (eX > d) then + begin + dec(eX, d); + inc(x, sX); + b:= true + end; + if (eY > d) then + begin + dec(eY, d); + inc(y, sY); + b:= true + end; + if b then + begin + inc(len); + if (len mod 4) = 0 then FillRoundInLand(X, Y, 34, lfBasic) + end + end +end; + + +procedure LoadFromFile(fileName: shortstring); +var + f: file of PointRec; + rec, prevRec: PointRec; +begin + fileMode:= 0; + + assignFile(f, fileName); + reset(f); + + while not eof(f) do + begin + read(f, rec); + rec.X:= SDLNet_Read16(@rec.X); + rec.Y:= SDLNet_Read16(@rec.Y); + + // FIXME: handle single point + if eof(f) or (rec.flags and $80 <> 0) then + else + DrawLineOnLand(prevRec.X, prevRec.Y, rec.X, rec.Y); + + prevRec:= rec; + end; + + closeFile(f); +end; + +end. diff -r b69f43f07cd7 -r 6de30ddc184e tools/drawMapTest/drawmapscene.cpp --- a/tools/drawMapTest/drawmapscene.cpp Sat Dec 04 15:09:19 2010 -0500 +++ b/tools/drawMapTest/drawmapscene.cpp Sat Dec 04 23:30:20 2010 +0300 @@ -94,9 +94,9 @@ qint16 py = qToBigEndian((qint16)point.y()); quint8 flags = 2; if(!cnt) flags |= 0x80; - b.append((const char *)&flags, 1); b.append((const char *)&px, 2); b.append((const char *)&py, 2); + b.append((const char *)&flags, 1); ++cnt; } @@ -115,12 +115,12 @@ while(data.size() >= 5) { - quint8 flags = *(quint8 *)data.data(); - data.remove(0, 1); qint16 px = qFromBigEndian(*(qint16 *)data.data()); data.remove(0, 2); qint16 py = qFromBigEndian(*(qint16 *)data.data()); data.remove(0, 2); + quint8 flags = *(quint8 *)data.data(); + data.remove(0, 1); //last chunk or first point if((data.size() < 5) || (flags & 0x80)) diff -r b69f43f07cd7 -r 6de30ddc184e tools/drawMapTest/mainwindow.cpp --- a/tools/drawMapTest/mainwindow.cpp Sat Dec 04 15:09:19 2010 -0500 +++ b/tools/drawMapTest/mainwindow.cpp Sat Dec 04 23:30:20 2010 +0300 @@ -63,7 +63,7 @@ QFile f(fileName); f.open(QIODevice::WriteOnly); - f.write(qCompress(scene->encode()).toBase64()); + f.write(scene->encode()); } } @@ -76,7 +76,7 @@ QFile f(fileName); f.open(QIODevice::ReadOnly); - QByteArray data = qUncompress(QByteArray::fromBase64(f.readAll())); + QByteArray data = f.readAll(); scene->decode(data); } }