--- a/hedgewars/uLandGraphics.pas Sun Aug 06 20:08:15 2006 +0000
+++ b/hedgewars/uLandGraphics.pas Sun Aug 06 20:58:05 2006 +0000
@@ -7,7 +7,7 @@
end;
procedure DrawExplosion(X, Y, Radius: integer);
-procedure DrawHLinesExplosions(ar: PRangeArray; Radius: Longword; y, dY: integer; Count: Byte);
+procedure DrawHLinesExplosions(ar: PRangeArray; Radius: integer; y, dY: integer; Count: Byte);
procedure DrawTunnel(X, Y, dX, dY: real; ticks, HalfWidth: integer);
procedure FillRoundInLand(X, Y, Radius: integer; Value: Longword);
@@ -48,35 +48,35 @@
end;
procedure ClearLandPixel(y, x: integer);
-var p: integer;
+var p: PByteArray;
begin
-p:= integer(LandSurface.pixels);
+p:= @PByteArray(LandSurface.pixels)^[LandSurface.pitch*y];
case LandSurface.format.BytesPerPixel of
1: ;// not supported
- 2: PWord(p + LandSurface.pitch*y + x * 2)^:= 0;
+ 2: PWord(@p[x * 2])^:= 0;
3: begin
- PByte(p + LandSurface.pitch*y + x * 3 + 0)^:= 0;
- PByte(p + LandSurface.pitch*y + x * 3 + 1)^:= 0;
- PByte(p + LandSurface.pitch*y + x * 3 + 2)^:= 0;
+ p[x * 3 + 0]:= 0;
+ p[x * 3 + 1]:= 0;
+ p[x * 3 + 2]:= 0;
end;
- 4: PLongword(p + LandSurface.pitch*y + x * 4)^:= 0;
- end;
+ 4: PLongword(@p[x * 4])^:= 0;
+ end
end;
procedure SetLandPixel(y, x: integer);
-var p: integer;
+var p: PByteArray;
begin
-p:= integer(LandSurface.pixels);
+p:= @PByteArray(LandSurface.pixels)^[LandSurface.pitch*y];
case LandSurface.format.BytesPerPixel of
1: ;// not supported
- 2: PWord(p + LandSurface.pitch*y + x * 2)^:= cExplosionBorderColor;
+ 2: PWord(@p[x * 2])^:= cExplosionBorderColor;
3: begin
- PByte(p + LandSurface.pitch*y + x * 3 + 0)^:= cExplosionBorderColor and $FF;
- PByte(p + LandSurface.pitch*y + x * 3 + 1)^:= (cExplosionBorderColor shr 8) and $FF;
- PByte(p + LandSurface.pitch*y + x * 3 + 2)^:= (cExplosionBorderColor shr 16);
+ p[x * 3 + 0]:= cExplosionBorderColor and $FF;
+ p[x * 3 + 1]:= (cExplosionBorderColor shr 8) and $FF;
+ p[x * 3 + 2]:= cExplosionBorderColor shr 16;
end;
- 4: PLongword(p + LandSurface.pitch*y + x * 4)^:= cExplosionBorderColor;
- end;
+ 4: PLongword(@p[x * 4])^:= cExplosionBorderColor;
+ end
end;
procedure FillLandCircleLines0(x, y, dx, dy: integer);
@@ -153,31 +153,17 @@
SDL_UnlockSurface(LandSurface);
end;
-procedure DrawHLinesExplosions(ar: PRangeArray; Radius: Longword; y, dY: integer; Count: Byte);
-var tx, ty, i, p: integer;
+procedure DrawHLinesExplosions(ar: PRangeArray; Radius: integer; y, dY: integer; Count: Byte);
+var tx, ty, i: integer;
begin
if SDL_MustLock(LandSurface) then
SDL_LockSurface(LandSurface);
-p:= integer(LandSurface.pixels);
for i:= 0 to Pred(Count) do
begin
- case LandSurface.format.BytesPerPixel of
- 1: ;
- 2: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
- for tx:= max(0, round(ar[i].Left - radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(ar[i].Right + radius*sqrt(1-sqr(ty/radius)))) do
- PWord(p + LandSurface.pitch*(y + ty) + tx * 2)^:= 0;
- 3: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
- for tx:= max(0, round(ar[i].Left - radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(ar[i].Right + radius*sqrt(1-sqr(ty/radius)))) do
- begin
- PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 0)^:= 0;
- PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 1)^:= 0;
- PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 2)^:= 0;
- end;
- 4: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
- for tx:= max(0, round(ar[i].Left - radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(ar[i].Right + radius*sqrt(1-sqr(ty/radius)))) do
- PLongword(p + LandSurface.pitch*(y + ty) + tx * 4)^:= 0;
- end;
+ for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
+ for tx:= max(0, ar[i].Left - Radius) to min(2047, ar[i].Right + Radius) do
+ ClearLandPixel(y + ty, tx);
inc(y, dY)
end;
@@ -186,25 +172,10 @@
for i:= 0 to Pred(Count) do
begin
- case LandSurface.format.BytesPerPixel of
- 1: ;
- 2: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
- for tx:= max(0, round(ar[i].Left - radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(ar[i].Right + radius*sqrt(1-sqr(ty/radius)))) do
- if Land[y + ty, tx] = $FFFFFF then
- PWord(p + LandSurface.pitch*(y + ty) + tx * 2)^:= cExplosionBorderColor;
- 3: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
- for tx:= max(0, round(ar[i].Left - radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(ar[i].Right + radius*sqrt(1-sqr(ty/radius)))) do
- if Land[y + ty, tx] = $FFFFFF then
- begin
- PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 0)^:= cExplosionBorderColor and $FF;
- PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 1)^:= (cExplosionBorderColor shr 8) and $FF;
- PByte(p + LandSurface.pitch*(y + ty) + tx * 3 + 2)^:= (cExplosionBorderColor shr 16);
- end;
- 4: for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
- for tx:= max(0, round(ar[i].Left - radius*sqrt(1-sqr(ty/radius)))) to min(2047, round(ar[i].Right + radius*sqrt(1-sqr(ty/radius)))) do
- if Land[y + ty, tx] = $FFFFFF then
- PLongword(p + LandSurface.pitch*(y + ty) + tx * 4)^:= cExplosionBorderColor;
- end;
+ for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
+ for tx:= max(0, ar[i].Left - Radius) to min(2047, ar[i].Right + Radius) do
+ if Land[y + ty, tx] = $FFFFFF then
+ SetLandPixel(y + ty, tx);
inc(y, dY)
end;
@@ -217,14 +188,13 @@
//
procedure DrawTunnel(X, Y, dX, dY: real; ticks, HalfWidth: integer);
var nx, ny: real;
- i, t, tx, ty, p: integer;
+ i, t, tx, ty: integer;
begin // (-dY, dX) is (dX, dY) turned by PI/2
if SDL_MustLock(LandSurface) then
SDL_LockSurface(LandSurface);
nx:= X + dY * (HalfWidth + 8);
ny:= Y - dX * (HalfWidth + 8);
-p:= integer(LandSurface.pixels);
for i:= 0 to 7 do
begin
@@ -253,16 +223,7 @@
if ((ty and $FFFFFC00) = 0) and ((tx and $FFFFF800) = 0) then
begin
Land[ty, tx]:= 0;
- case LandSurface.format.BytesPerPixel of
- 1: ;
- 2: PWord(p + LandSurface.pitch * ty + tx * 2)^:= 0;
- 3: begin
- PByte(p + LandSurface.pitch * ty + tx * 3 + 0)^:= 0;
- PByte(p + LandSurface.pitch * ty + tx * 3 + 1)^:= 0;
- PByte(p + LandSurface.pitch * ty + tx * 3 + 2)^:= 0;
- end;
- 4: PLongword(p + LandSurface.pitch * ty + tx * 4)^:= 0;
- end
+ ClearLandPixel(ty, tx);
end
end;
for t:= 0 to 7 do
--- a/hedgewars/uSHA.pas Sun Aug 06 20:08:15 2006 +0000
+++ b/hedgewars/uSHA.pas Sun Aug 06 20:58:05 2006 +0000
@@ -51,11 +51,7 @@
function SHA1Final(Context: TSHA1Context): TSHA1Digest;
implementation
-
-function _bswap(X: LongWord): LongWord;
-begin
- Result:= (X shr 24) or ((X shr 8) and $FF00) or ((X shl 8) and $FF0000) or (X shl 24)
-end;
+uses SDLh;
function rol(x: LongWord; y: Byte): LongWord;
begin
@@ -90,8 +86,12 @@
i, t: LongWord;
begin
move(Context.H, S, sizeof(S));
-for i:= 0 to 15 do
- W[i]:= _bswap(PLongWord(LongWord(@Context.Buf)+i*4)^);
+for i:= 0 to 3 do
+ begin
+ t:= i * 4;
+ with Context do
+ W[i]:= Buf[t + 3] or (Buf[t + 2] shl 8) or (Buf[t + 1] shl 16) or (Buf[t] shl 24);
+ end;
for i := 16 to 79 do
W[i] := rol(W[i - 3] xor W[i - 8] xor W[i - 14] xor W[i - 16], 1);
for i := 0 to 79 do
@@ -124,11 +124,10 @@
procedure SHA1Update(var Context: TSHA1Context; Buf: Pointer; Length: LongWord);
var i: integer;
begin
-for i:= 1 to Length do
+for i:= 0 to Pred(Length) do
begin
- Context.Buf[Context.CurrLength]:= PByte(Buf)^;
+ Context.Buf[Context.CurrLength]:= PByteArray(Buf)^[i];
inc(Context.CurrLength);
- inc(LongWord(Buf));
if Context.CurrLength=64 then
begin
SHA1Hash(Context);