PDA

Click to See Complete Forum and Search --> : WHAT AM I DOING WRONG!!!


Vuen
Sep 13th, 2000, 06:13 PM
Everyone is always saying how FAST set/getpixelling on a memDC is fast and its SLOW LIKE HELL FOR ME! SO WHAT AM I DOING WRONG! Okay. This code WORKS PERFECTLY, except for the fact that its SLOW. This is how my prog makes a DC, and changes some of the colors in it. I think the problem is that it's how I create the memDC, but well here you go.

I've declared all the APIs I'll be using so im not gonna show them, and picGame is a blank picture box, and the Imagelist contains a 50x50 sprite that is being drawn:

UnitSprites(i) = CreateCompatibleDC(frmGame.picGame.hdc)
UnitSpritesBitmaps(i) = CreateCompatibleBitmap(frmGame.picGame.hdc, 50, 50)
SelectObject UnitSprites(i), UnitSpritesBitmaps(i)

frmGame.UnitList(5).ListImages(i).Draw UnitSprites(i), 0, 0, 0
For i2 = 0 To 49
For i3 = 0 To 49
pixel = GetPixel(UnitSprites(i), i2, i3)
If pixel <> RGB(255, 255, 0) Then
For i4 = 0 To 15
If pixel = RGB(90 + i4 * 11, 0, 90 + i4 * 11) Then SetPixelV UnitSprites(i), i2, i3, RGB(Color(1, 1) * (i4 / 16), Color(1, 2) * (i4 / 16), Color(1, 3) * (i4 / 16))
If pixel = RGB(0, 0, 90 + i4 * 11) Then SetPixelV UnitSprites(i), i2, i3, RGB(Color(2, 1) * (i4 / 16), Color(2, 2) * (i4 / 16), Color(2, 3) * (i4 / 16))
If pixel = RGB(0, 90 + i4 * 11, 0) Then SetPixelV UnitSprites(i), i2, i3, RGB(Color(3, 1) * (i4 / 16), Color(3, 2) * (i4 / 16), Color(3, 3) * (i4 / 16))
Next i4
End If
Next i3
Next i2

[Edited by Vuen on 09-13-2000 at 07:24 PM]

PaulLewis
Sep 13th, 2000, 08:55 PM
Your code will iterate through each pixel in the sprite, and then either run a loop (0 to 15) on each one OR move to the next pixel. The loop that is run contains many calculations and each time the loop is run, three If statements are being executed even though it seems unlikely that you rwally want that.

Afterall pixel is not likely to be all three values at once.

Also, wherever possible change calls to functions into constants. For example, RGB(255,255,0) should be changed to &FFFF. This speeds up the loop slightly.

How fast is the loop anyhow? Can you set timers in your code to see how fast it does 100 of these loops?

Regards
Paul Lewis

Vuen
Sep 14th, 2000, 06:30 PM
Thanks but that didnt help... Unfortunately I was already in-the-process of doing those two things you told me but I had to post now or wait a day, so I decided now and show old code. With the new code, it takes about a minute to convert 100 50x50 sprites. AAAAAAHHHHHH!!!!!!!! is right. This is my game (http://www.geocities.com/vvuueenn/rts.ZIP) and it has only 72 50x50 sprites, and I think 11 130x130 sprites, and its over a minute loading time. Try it PLEASE and tell me whats wrong.

OH WAIT AAAAAAHHHHHH!!!!!!!!!!!!!!!!!!! Even if it replaces a pixel it continues the loop! HOLY CRAP IM STUPID!
Screw the loop, I'll write a giant ifelse embedded in 3 ifs:


if {pixel has no green but has blue and red}
if {pixel is highest shade of murple}
SetPixel 4567476
elseif {pixel is 2nd highest shade of murple}
SetPixel 377684
elseif....
endif
elseif {pixel has no blue or red, only green}
if {pixel is highest shade of green}
SetPixel 45674
elseif {pixel is 2nd highest shade of green}
SetPixel 4574
elseif....
endif
elseif....
endif


like that! YAY I'll let ya know how that goes when I write it (sorry right now working on Magic:TG deck for school)

Vuen
Sep 14th, 2000, 06:34 PM
STUPID GEOCITIES my site is down for some "temporary" reason. So get it here (lightning.prohosting.com/~vuen/rts.ZIP) on Prohosting. GO FREEPROHOSTING WOOOO!!!!

PaulLewis
Sep 14th, 2000, 06:35 PM
As frustrating as it is for you, I am sure you will see things alot cleare if you don't panic too much ;) I'm like that myself sometimes so I know how easy it is to not see something so obvious.

It still isn't necessarily going to give you the speed you are after, but we will see huh?

Do you see now what I meant in my post by and each time the loop is run, three If statements are being executed even though it seems unlikely that you rwally want that.

I look forward to hearing how well you have solved the speed problem.

Regards

Vuen
Sep 14th, 2000, 07:25 PM
>>and each time the loop is run, three If statements are being executed even though it seems unlikely that you rwally want that.

I thought you meant that to put it in an elseif at first which was what I was doing. I get it now THANK YOU VERY MUCH!!!!! and no I havent tried it yet...