Bug report + fix: Shadows
Posted: Fri May 21, 2010 2:56 pm
Well most of you already know the shadow bug (it hasn't been posted here though).
Anyway I've been looking at the shadow bug and I know what's wrong and I know how to fix it.
First of all let me explain how shadows are done in Dragon Raja, consider this image:

The red box displays the image for the character (some pixels are transparent). The green box (parallelogram) is how the image is of the character is warped to show a shadow.
Notice in the next image that as soon as the image of the character is partly out of screen (the red box goes out of screen), the shadow disappears as indicated by the yellow box.

So why is this? Well because of two things:
1. There is no function that deals with a shadow partly being drawn out of screen.
2. The code of deciding when to draw a shadow is wrong.
Currently Dragon Raja draws a shadow when the image of the character is fully in screen. This is wrong because the shadow is warped and does not occupy the same space as the image of the character.
Another bug that occurs because of this is shown here (and as most of you know it):

Here the red boxes shows two parts of the shadow. In this case the image of the character is fully in screen (almost partly out of screen) and Dragon Raja assumes it can draw the shadow as well. But as already mentioned, the shadow is warped (to the right). As a result the shadow is drawn over the end of the screen and because of the way the screen is stored in memory it ends up at the other side of the screen (and one line lower, but that's hard to see).
Now the fix:
The fix as you might have guessed is easy. Simply solve issue 2 by determining where the shadow will be drawn on the screen and if the shadow is partly out of screen, don't draw it. This will fix having the shadow end up at the other side of the screen as well as draw a shadow in the second image at the yellow box because the shadow is not out of screen there.
Ok, that was easy, but what I was really interested in was doing it right: When characters/items/objects are partly out of screen they don't just disappear, they are just partly drawn. I want to see the same for shadows. And therefore I had to write some new code, which was kind of tricky (had to write ASM code for it and I haven't really done that before), but I believe it's correct now. Unfortunately I haven't checked my fix in Dragon Raja because I don't have a compiling version of Dragon Raja. I did write my own program that works in the same way, here are the results:

Notice that in the first image the shadow is partly out of screen, but does not end up at the other side of the screen.
The second image is fully in screen and Dragon Raja would show it the same way.
In the third and fourth image shadows are drawn at the top of the screen where Dragon Raja currently would not draw them. In the fourth image the shadow is fully in screen.
The last two images show when the shadow is at the bottom of the screen and at the left of the screen. These are currently also not drawn in Dragon Raja.
I hope the GM team will consider asking me for the source code that fixes these problems (1 new function and 1 function that replaces a current function). I'll be happy to give it to them.
I think I spent about 15 hours writing the code. I'm not part of the GM team and have no obligations to any one and so it would be nice to get a reward of some kind for this fix (should it work). Of course I didn't do this for a reward, but to improve Dragon Raja. So reward or no reward, I'll still be happy.
Anyway I've been looking at the shadow bug and I know what's wrong and I know how to fix it.
First of all let me explain how shadows are done in Dragon Raja, consider this image:

The red box displays the image for the character (some pixels are transparent). The green box (parallelogram) is how the image is of the character is warped to show a shadow.
Notice in the next image that as soon as the image of the character is partly out of screen (the red box goes out of screen), the shadow disappears as indicated by the yellow box.

So why is this? Well because of two things:
1. There is no function that deals with a shadow partly being drawn out of screen.
2. The code of deciding when to draw a shadow is wrong.
Currently Dragon Raja draws a shadow when the image of the character is fully in screen. This is wrong because the shadow is warped and does not occupy the same space as the image of the character.
Another bug that occurs because of this is shown here (and as most of you know it):

Here the red boxes shows two parts of the shadow. In this case the image of the character is fully in screen (almost partly out of screen) and Dragon Raja assumes it can draw the shadow as well. But as already mentioned, the shadow is warped (to the right). As a result the shadow is drawn over the end of the screen and because of the way the screen is stored in memory it ends up at the other side of the screen (and one line lower, but that's hard to see).
Now the fix:
The fix as you might have guessed is easy. Simply solve issue 2 by determining where the shadow will be drawn on the screen and if the shadow is partly out of screen, don't draw it. This will fix having the shadow end up at the other side of the screen as well as draw a shadow in the second image at the yellow box because the shadow is not out of screen there.
Ok, that was easy, but what I was really interested in was doing it right: When characters/items/objects are partly out of screen they don't just disappear, they are just partly drawn. I want to see the same for shadows. And therefore I had to write some new code, which was kind of tricky (had to write ASM code for it and I haven't really done that before), but I believe it's correct now. Unfortunately I haven't checked my fix in Dragon Raja because I don't have a compiling version of Dragon Raja. I did write my own program that works in the same way, here are the results:

Notice that in the first image the shadow is partly out of screen, but does not end up at the other side of the screen.
The second image is fully in screen and Dragon Raja would show it the same way.
In the third and fourth image shadows are drawn at the top of the screen where Dragon Raja currently would not draw them. In the fourth image the shadow is fully in screen.
The last two images show when the shadow is at the bottom of the screen and at the left of the screen. These are currently also not drawn in Dragon Raja.
I hope the GM team will consider asking me for the source code that fixes these problems (1 new function and 1 function that replaces a current function). I'll be happy to give it to them.
I think I spent about 15 hours writing the code. I'm not part of the GM team and have no obligations to any one and so it would be nice to get a reward of some kind for this fix (should it work). Of course I didn't do this for a reward, but to improve Dragon Raja. So reward or no reward, I'll still be happy.