# HG changeset patch # User unc0rr # Date 1291494599 -10800 # Node ID 7351e6f1ee281f72f2df5ca9ddd075efad2da15b # Parent ffb766e85150172e829dff1aae9327f6964ab6fb Halfplement decode/drawing routine diff -r ffb766e85150 -r 7351e6f1ee28 hedgewars/uLand.pas --- a/hedgewars/uLand.pas Sat Dec 04 22:33:14 2010 +0300 +++ b/hedgewars/uLand.pas Sat Dec 04 23:29:59 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 ffb766e85150 -r 7351e6f1ee28 hedgewars/uLandPainted.pas --- a/hedgewars/uLandPainted.pas Sat Dec 04 22:33:14 2010 +0300 +++ b/hedgewars/uLandPainted.pas Sat Dec 04 23:29:59 2010 +0300 @@ -25,18 +25,83 @@ procedure LoadFromFile(fileName: shortstring); implementation +uses uLandGraphics, uConsts, uUtils, SDLh; type PointRec = packed record - x, y: ShortInt; + 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: PointRec; + rec, prevRec: PointRec; begin - fileMode = foReadOnly; + fileMode:= 0; assignFile(f, fileName); reset(f); @@ -44,6 +109,15 @@ 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); diff -r ffb766e85150 -r 7351e6f1ee28 tools/drawMapTest/mainwindow.cpp --- a/tools/drawMapTest/mainwindow.cpp Sat Dec 04 22:33:14 2010 +0300 +++ b/tools/drawMapTest/mainwindow.cpp Sat Dec 04 23:29:59 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); } }