Debugging Graphics

This week was majorly spent on starting the majority of the graphics work, which comprises the most hefty part of the project. This week made me realise the complexity of the task. The engine is really complicated, and has many layers of abstraction. The hardest part of this week was to tackle this challenge and hence even though the code changes made were very small, they required hours and hours of debugging.

Initial Graphics

Currently the engine shows just the splash screen. The challenge is to find what is stopping it from rendering the next frame. This was particularly hard to debug as we didn’t see any STUB messages, stopping from rendering the next scene. I did struggle here, however sev came here for the rescue. Sev was of great help over here. He managed to track down the exact place where the next frame was being rendered.

Debugging Graphical Glitches

Even though we managed to render the initial main menu on the screen, we still had three problems to deal with.

  1. The menu items on the screen were distorted
  2. On hover the menu items started glitching
  3. Missing cursor

The first problem was quite simple to solve. As you can see that the screen is sort of distorted. Sev gave me the hint that the sprite coordinates are being calculated incorrectly. With a little bit of investigation I found the problem. The x coordinate was being multiplied by two in the code, which messed up the graphics for the main menu. This commit solved the issue.

The second problem however was a little more difficult to solve. I tried very hard to investigate the issue, but I could not find any success with this. Once again Sev had a look at the code and helped me out, in investigating the issue. The final fix was a simple one line fix, but was very hard to debug. If you observer carefully you can see that on hover we were rendering the top portion of the screen each time. So the issue was that our method to copy the buffer to screen was incorrect. We were giving it the pointer corresponding to the top corner, even though we were rendering the screen partially. What was required to be done was to give it the pointer corresponding to the top left corner of the rectangle to be updated. Hence were facing issues when we had to partially copy the buffer to the screen, because when you have to copy the complete buffer we were giving it the correct pointer. You can look at this commit to understand the fix better.

After solving these two issues our main menu looked something like this

Even though we managed to fix the first two problems, the third problem still persists at the moment I am writing this blog. Sev hacked this for the moment by rendering a simple arrow cursor, but we still have to manage to render their custom cursor, which they have used in the game. Not just this we are not able to render the first scene after pressing new game. It just shows us a blank screen. There is still a lot of work to be done, but we are taking those baby steps.

Debug Channels

This week we also adopted the use of debug channels through out the codebase. Debug channels help you selectively print things to the terminal, depending upon your use case. Since too many messages in the terminal can make it really hard to investigate issues. So let’s say you only wanted to print statements regarding graphics or sound. So you can run the binary with the respective flags and levels and you will only see those debug messages and the rest will be silent. You can run the debug flags like the following.
./scummvm --debugflags=save --debuglevel=3 shveik-ru
This is a very helpful technique to debug your code, since you don’t need to remove the your debug statements ¬†immediately and they can sit in the code without causing too much trouble. You can checkout this commit to understand how to use debug channels.

Lastly we got the music to work as well. ScummVM already had their own APIs which were equivalent to those in the original engine. As I am writing this I have already started working on the save/load game feature of the engine. I will be spending the coming week on debugging the graphics properly and hopefully be able to play the game without glitches.

Leave a Reply

Your email address will not be published. Required fields are marked *