Autor Beitrag
maximus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Fr 31.01.03 12:47 
Hallo,

ich hab mal den PixelCollision bug in DelphiX gefixed (bin wahrscheinlich nicht der erste)! Sobald eines der zu testenden sprite eine animation ist, war die pixelCollision wertlos. Nur weil Mr. Hoshi vergessen hat das XOffset des PatternRects zu addieren.

Bugfix für die function 'ImageCollisionTest' in der unit 'DXSprite':

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
function ImageCollisionTest(suf1, suf2: TDirectDrawSurface; const rect1, rect2: TRect;
  x1,y1,x2,y2: Integer; DoPixelCheck: Boolean): Boolean;

  Procedure AddXOffs(var r:TRect;ofs:Integer);
  begin
    r.Left  := r.Left  + ofs;
    r.Right := r.Right + ofs;
  end;

  ...
    if DoPixelCheck and Result then
  begin
    {  Get Overlapping rectangle  }
    with r1 do r1 := Bounds(Max(x2-x1, 0), Max(y2-y1, 0), Right-Left, Bottom-Top);
    with r2 do r2 := Bounds(Max(x1-x2, 0), Max(y1-y2, 0), Right-Left, Bottom-Top);
    
    // fix
    AddXOffs(r1,rect1.Left);
    AddXOffs(r2,rect2.Left);

    ClipRect(r1, rect1);
    ClipRect(r2, rect2);
   ...


Viel spass damit...persöhnlich arbeite ich auch nicht mehr mit DelphiX, muss nur noch'n projekt für die firma fertigstellen. Kann nur jedem empfehlen mit den jedi-headern zu arbeiten...solche bugs hat man dann wenigstens selbst zu verantworten.

mfg mx

Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.
Mape
Hält's aus hier
Beiträge: 5



BeitragVerfasst: Sa 08.02.03 21:16 
Titel: bugfix
ich suche grade eine seite wegen dem üblichen bug, finde aber nur italiänische...hat nicht noch einer ne idee, oder direkt die lösung?
maximus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Mo 10.02.03 11:22 
HALLO! 8)

Siehe oben! Dies ist die lösung!
Elite
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 07.11.04 14:58 
Sorry, dass ich einen so alten Post wieder rauskramen muss, aber meine TestImageCollision sieht ander aus als hier beschrieben:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
function ImageCollisionTest(suf1, suf2: TDirectDrawSurface; const rect1, rect2: TRect;
  x1,y1,x2,y2: Integer; DoPixelCheck: Boolean): Boolean;

  function ClipRect(var DestRect: TRect; const DestRect2: TRect): Boolean;
  begin
    with DestRect do
    begin
      Left := Max(Left, DestRect2.Left);
      Right := Min(Right, DestRect2.Right);
      Top := Max(Top, DestRect2.Top);
      Bottom := Min(Bottom, DestRect2.Bottom);

      Result := (Left < Right) and (Top < Bottom);
    end;
  end;

type
  PRGB = ^TRGB;
  TRGB = packed record
    R, G, B: Byte;
  end;
var
  ddsd1, ddsd2: TDDSurfaceDesc;
  r1, r2: TRect;
  tc1, tc2: DWORD;
  x, y, w, h: Integer;
  P1, P2: Pointer;
begin
  r1 := rect1;
  with rect2 do r2 := Bounds(x2-x1, y2-y1, Right-Left, Bottom-Top);

  Result := OverlapRect(r1, r2);

  if (suf1=nil) or (suf2=nil) then Exit;

  if DoPixelCheck and Result then
  begin
    {  Get Overlapping rectangle  }
    with r1 do r1 := Bounds(Max(x2-x1, 0), Max(y2-y1, 0), Right-Left, Bottom-Top);
    with r2 do r2 := Bounds(Max(x1-x2, 0), Max(y1-y2, 0), Right-Left, Bottom-Top);

    ClipRect(r1, rect1);
    ClipRect(r2, rect2);

    w := Min(r1.Right-r1.Left, r2.Right-r2.Left);
    h := Min(r1.Bottom-r1.Top, r2.Bottom-r2.Top);

    ClipRect(r1, bounds(r1.Left, r1.Top, w, h));
    ClipRect(r2, bounds(r2.Left, r2.Top, w, h));
                               
    {  Pixel check !!!  }
    ddsd1.dwSize := SizeOf(ddsd1);
    if suf1.Lock(r1, ddsd1) then
    begin
      try
        ddsd2.dwSize := SizeOf(ddsd2);
        if (suf1=suf2) or suf2.Lock(r2, ddsd2) then
        begin
          try
            if suf1=suf2 then ddsd2 := ddsd1;
            if ddsd1.ddpfPixelFormat.dwRGBBitCount<>ddsd2.ddpfPixelFormat.dwRGBBitCount then Exit;
                                     
            {  Get transparent color  }
            tc1 := ddsd1.ddckCKSrcBlt.dwColorSpaceLowValue;
            tc2 := ddsd2.ddckCKSrcBlt.dwColorSpaceLowValue;

            case ddsd1.ddpfPixelFormat.dwRGBBitCount of
              8 : begin
                    for y:=0 to h-1 do
                    begin
                      P1 := Pointer(Integer(ddsd1.lpSurface)+y*ddsd1.lPitch);
                      P2 := Pointer(Integer(ddsd2.lpSurface)+y*ddsd2.lPitch);
                      for x:=0 to w-1 do
                      begin
                        if (PByte(P1)^<>tc1) and (PByte(P2)^<>tc2) then Exit;
                        Inc(PByte(P1));
                        Inc(PByte(P2));
                      end;
                    end;
                  end;
              16: begin
                    for y:=0 to h-1 do
                    begin
                      P1 := Pointer(Integer(ddsd1.lpSurface)+y*ddsd1.lPitch);
                      P2 := Pointer(Integer(ddsd2.lpSurface)+y*ddsd2.lPitch);
                      for x:=0 to w-1 do
                      begin
                        if (PWord(P1)^<>tc1) and (PWord(P2)^<>tc2) then Exit;
                        Inc(PWord(P1));
                        Inc(PWord(P2));
                      end;
                    end;
                  end;
              24: begin
                    for y:=0 to h-1 do
                    begin
                      P1 := Pointer(Integer(ddsd1.lpSurface)+y*ddsd1.lPitch);
                      P2 := Pointer(Integer(ddsd2.lpSurface)+y*ddsd2.lPitch);
                      for x:=0 to w-1 do
                      begin        
                        if ((PRGB(P1)^.R shl 16) or (PRGB(P1)^.G shl 8) or PRGB(P1)^.B<>tc1) and
                          ((PRGB(P2)^.R shl 16) or (PRGB(P2)^.G shl 8) or PRGB(P2)^.B<>tc2) then Exit;
                        Inc(PRGB(P1));
                        Inc(PRGB(P2));
                      end;
                    end;
                  end;
              32: begin
                    for y:=0 to h-1 do
                    begin
                      P1 := Pointer(Integer(ddsd1.lpSurface)+y*ddsd1.lPitch);
                      P2 := Pointer(Integer(ddsd2.lpSurface)+y*ddsd2.lPitch);
                      for x:=0 to w-1 do
                      begin
                        if (PDWORD(P1)^ and $FFFFFF<>tc1) and (PDWORD(P2)^ and $FFFFFF<>tc2) then Exit;
                        Inc(PDWORD(P1));
                        Inc(PDWORD(P2));
                      end;
                    end;
                  end;
            end;
          finally
            if suf1<>suf2 then suf2.UnLock;
          end;
        end;
      finally
        suf1.UnLock;
      end;
    end;

    Result := False;
  end;
end;

Fühlt sich irgendwer im Stande, auch hier den Bugfix zu erläutern?
maximus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Mo 08.11.04 17:35 
Moin,

das is schon eine ewigkeit her, dass ich diesen patch veröffentlicht habe. Wenn ich das richtig sehe, dann musst du nur diese zeilen...

ausblenden Delphi-Quelltext
1:
2:
3:
// fix  
    AddXOffs(r1,rect1.Left);  
    AddXOffs(r2,rect2.Left);

...einfügen. Sonnst sieht doch alles gleich aus. Hab halt nur den wichtigen, kontextbezogenen code hingeschrieben :wink:

_________________
mfg.
mâximôv
Elite
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 08.11.04 17:43 
Der Punkt ist, dass in meiner DelphiX-Version (für D7) keine Prozedur namens AddXOffS existiert. Ich sagte ja schon, dass die Funktion ImageCollisionTest komlett anders aufgebaut ist. Offenbar gilt das für die komplette Unit. Siehst du oder irgendwer anders trotzdem eine Möglichkeit, das zu fixen?
maximus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Mo 08.11.04 19:54 
JA! Die procedure AddXOffs hab ich selbst geschrieben, was auch erklärt, dass du sie nicht hast. Allerdings hält dich niemand davon ab, sie einfach zu kopieren. Oben ist sie vollständig implementiert ;) ...und nein das ist alles identisch aufgebaut, hab nur den kontext gepostet.

_________________
mfg.
mâximôv
Elite
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 08.11.04 21:12 
user defined image
*sich in die Ecke stellt und schämt*
maximus Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Di 09.11.04 10:08 
:shock: Wenn du das meinst. Da is wohl einer im verein der bibeltrueen Christen :twisted:

Gern geschehen.

_________________
mfg.
mâximôv