Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Colour cycling Atari Style?

Author
Message
Paisleys finest
19
Years of Service
User Offline
Joined: 11th Nov 2005
Location: In a house
Posted: 26th Mar 2007 01:56
Hi, I'm creating a Robotron 2084 clone and wish to implement colour cycling.

I tried using the following code:



Where _colours is a list of RGBs to replace almost invisible (0,0, 0-15) with.

The problem is, this code is slow as hell. I really mean it, it slows the game down to 5FPS and that's only on 640 x 480 x 32bpp!! Remove the code and I get 64FPS (it won't go any higher, wonder why???)

Now, can anyone tell me how I can speed this up? It seems that unlocking the back buffer causes mega slowdown. That's not the most complex code in the world either.

I thought of using a pixel shader but I don't know how to program them, nor do I know how to implement true randomness.

Any advice would be appreciated.

Regards, Scott T.

Looking for mature software developer to finish my Bruce Lee remake.. apply via email to MSN address.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Mar 2007 15:41
What you are doing in inherently a slow process. What's making it worse, is the fact that you are reading from a device through a pipe meant to feed data out from the processor as fast as possible. Reading and writing at the same time will stall this pipe every time it just gets started.

One thing for you to try is to read the whole backbuffer into a block of memory using one big memcpy, update the whole thing, then write it back using memcpy (or whatever the equivalent is of memcpy in the .NET world).

A better way to do the job would be to get the colours rigth before they hit the backbuffer..

Paisleys finest
19
Years of Service
User Offline
Joined: 11th Nov 2005
Location: In a house
Posted: 26th Mar 2007 16:05
Colours right before they hit the backbuffer?

Intriguing - but how do you mean?

Right now I'm actually trying to access the image data itself, changing colours in the images I'm going to paste.

I'm trying to convert the Image to a memblock, then writing to the memblock, changing the colours and then writing the results back to a temporary image which I then paste (I don't want to update the original images)


Here's my code: do you think this is optimal? (ImageID is a parameter, I'm writing an overloaded version of PasteImage which applies a colour cycle)



Regards, Scott T.

Looking for mature software developer to finish my Bruce Lee remake.. apply via email to MSN address.
Gervais
20
Years of Service
User Offline
Joined: 11th Mar 2004
Location: Canada
Posted: 26th Mar 2007 21:29
You could declare the pointer as an integer this way you would be moving 4 bytes in and out with each read write and at the same time you will get the hole color but remember to moving the pointer +1 not +4 you are moving as integer not byte

This would be a faster way to move memory
Paisleys finest
19
Years of Service
User Offline
Joined: 11th Nov 2005
Location: In a house
Posted: 26th Mar 2007 21:37
Yeah I already am doing that in the code. It's cast to uint * when reading.

Regards, Scott T.

Looking for mature software developer to finish my Bruce Lee remake.. apply via email to MSN address.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Mar 2007 22:45 Edited at: 26th Mar 2007 22:48
Quote: "Colours right before they hit the backbuffer?

Intriguing - but how do you mean?

Right now I'm actually trying to access the image data itself, changing colours in the images I'm going to paste."


That's what I mean. Rather than draw then correct the colours, get the colours right first, then draw them.

If you can find a way to keep the memblocks allocated so you don't need to keep creating them, then that's even better - making the memblock from an image will copy data from the graphics memory into main memory (again, data travelling in the wrong direction).

Might be marginally faster ...


- Removed 'i' variable, replacing it with pointer comparisons - 'i' didn't add to the code in any way, and running a division/multiplication every loop isn't good.
- Replaced '&' and comparisons with 2 smaller operations (not and '&') - replaces 2 jumps with a single jump and cuts out a few operations at the assembly level.
- Made ptr a uint*, no quicker, just makes the pointer arithmetic easier to read and avoids casts.
- I left the 'index' variable alone, as it keeps the code clean, and will get optimised away anyway.

Paisleys finest
19
Years of Service
User Offline
Joined: 11th Nov 2005
Location: In a house
Posted: 26th Mar 2007 23:35
Ah bugger. I got it working when you PasteImage(X,Y) without transparency, and it flies, but it's not working WITH transparency.

Any ideas how I can recreate the mask?



Regards, Scott T.

Looking for mature software developer to finish my Bruce Lee remake.. apply via email to MSN address.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Mar 2007 00:09 Edited at: 27th Mar 2007 00:10
Hmm, you've put the old masking and comparisons back in - I see that I got something wrong there.

Change the code in the loop to this:


Make sure that the alpha in your _colours array is set to 0 - the alternative is to mask it away inside the loop, which will waste cycles:


Paisleys finest
19
Years of Service
User Offline
Joined: 11th Nov 2005
Location: In a house
Posted: 27th Mar 2007 00:37
Nope, still not working.

Thanks for your help Ian, this must be very trying, but believe me this is the easiest task of writing the game, lol

I have an image with colorkey 64,64,64 and the code works just fine if I PasteImage it without processing (as expected).

When I run an image through my colour cycling routine, and paste the image from the memblock using transparency, it seems to forget the changed colours!!

Without transparency the "cycled" image works like it's supposed to. Any way of setting the color key for the image again? Or is it something in the DGDK itself that's wrong?




Regards, Scott T.

Looking for mature software developer to finish my Bruce Lee remake.. apply via email to MSN address.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Mar 2007 00:44
No, you can't just use the value of 'val' like that - when you first read a colour from *ptr, you masked out the alpha portion. There's nothing left to combine back in when your use the _colours array.

Try using the code I posted in its entirety - that code keeps the whole colour value so that it can still extract the alpha later.

Paisleys finest
19
Years of Service
User Offline
Joined: 11th Nov 2005
Location: In a house
Posted: 27th Mar 2007 13:10
Ian, I just looked at that code with a fresh pair of eyes and went "durrrr"

I've been working on this game for 10 hour shifts (for fun, not profit) - maybe its a sign for me to get a life

I'll let you know how this goes.

Thanks again. Much appreciated

Regards, Scott T.

Looking for mature software developer to finish my Bruce Lee remake.. apply via email to MSN address.
Paisleys finest
19
Years of Service
User Offline
Joined: 11th Nov 2005
Location: In a house
Posted: 27th Mar 2007 13:16
That did the trick!

Ian, you're a genius. Thanks for your help.

Regards, Scott T.

Looking for mature software developer to finish my Bruce Lee remake.. apply via email to MSN address.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 27th Mar 2007 15:38
Hooray!

Login to post a reply

Server time is: 2024-11-19 12:30:57
Your offset time is: 2024-11-19 12:30:57