Categories
Coding Experience Technical

Because spaces should have height too!

Greetings! This is yet another blog documenting my work for this week. Also, before starting, I want to mention that this will be slightly more technical!

So let’s start!

Wrapping Loose Ends

This section is in continuation of my previous blog post – https://blogs.scummvm.org/hsk/2023/06/10/i-am-a-developer-and-i-add-bugs-in-code/

I mentioned this something’s something riddle but didn’t go into technical terms, so here I am mentioning it:

Also, read that blog if you haven’t still, or skip this section.

The task was to modify how the frame’s loading in the director engine works. This is quite a big and deep change that changes the fundamental of the engine.

So currently, in the Director engine, we load all the frames before starting a movie (or a game in layman’s terms), now this was good till now, but it has some disadvantages that were not yet explored. (Until we found that genius game exploiting it).

So, in conventional frame loading, It used to work by first precalculating all frames, creating an array where we have all the frames loaded by frame number and this was later on used in all parts of the engine (rendering, configuration, properties assignment/change, etc.), This was good however it has the disadvantage of being inflexible, that is, it was all good and fine when we precomputed all frames and use them, because conventionally these frames were not meant to be changed anyways.. (ie imagine a developer created a game with a rolling ball, means the engine created series of the frame with this information, etc..) but once we have that all, we don’t need to worry about things changing in-between.. well sure they can and if you have any idea you will argue that things can change with code, and that is correct but only the case when the particular is set to be Puppet (A command which give control to script about different properties of object, or sprite without bothering to see how they moved in original movie). In essence:

A non-puppet (or not controlled by script) is meant to behave like how the frames define them, ie, if Frame 1 says the object ball is at position 10, 10, then Frame 2 says it is now at position 20, 20, then there’s no doubt that it will be the same! (Because that’s how the movie is created). or, giving a better example, imagine you created a gif (or series of images), now to view its motion, a player (or any digital software) can preload first all images in memory and then serially display them.. It doesn’t have to bother fetching each image at every frame!

We thought it too until this game called “Total Distortion” broke the way we used to see the director! This game used a peculiarity (or I mentioned in the last post as a bug) of the director, which made it have changes on frame independent of how the movie defined it! (i.e., runtime changes).. so now the concept of loading everything at the start and then sequentially playing failed because this game at runtime was making some changes which, when doing precomputation, were not visible (As they are overridden because that sprite is never announced as puppet)

What’s the solution?

On-demand frame loading! Yes, as per the name already suggests, this type of frame loading doesn’t compute all frames at once but instead do it when required! Ie it only fetches the frame that is to be displayed next, then add in the information that is changed and finally you have your new frame!

One important thing to mention is that Director engine works on concept of deltas, that is if it only records the difference in a frame from previous one! This saves quite some storage and prevent duplication of data, and due to this concept of delta’s do we need to have ondemand loading, because now We will overlap the changes of next frame to current state of frame (which might be modified externally), rather than precomputing all frames and always replacing whole state of frame at once!

PR Link – #5089

Also linked to this pull request is #5074, merged the day after my last blog post! This built some initial groundwork for the on-demand frame and D6 auto puppet property!

Fast forward to the present:

Let’s break down this week’s work into these sections and fun short stories so it becomes easier to read!

GSoC is all about Mentorship and Communication:

Yes, you heard it right! I cannot emphasize this because this program is about mentorship and communication. How well you can communicate and fulfill the tasks given by your mentor and how efficient you are will decide if you are being able to contribute or not! In this regard I got hard times, especially at the start when there were issues in communication, often time I asked the same questions again and again before getting something done.. and in that sense A big shoutout to super-mentor sev for having the patience to deal with such a clumsy student, and for quotes that I will be using throughout my coding career)

Leaks are annoying (and dangerous):

Part of my work here also includes finding/making sure that there are no memory leaks! If you don’t know what is memory leak then it is:

In computer science, a memory leak is a type of resource leak that occurs when a computer program incorrectly manages memory allocations in a way that memory which is no longer needed is not released.
Memory leak, although often times seen harmless (in way that there is no immediate errors, etc) are not good when they accumulates, also these are especially not good for low-end device where resources are already a problem!
So there was this problem where part of code which was responsible for opening executable files was leaking some memory in cases where the file is invalid, this was not noticeable because this problem happens at this specific corner case, and it was all good when the file is read successfully! While working on some different feature I encountered this leak and was horrified (because each leaks are really, really dangerous, especially at scummvm.. I will tell later the reason why), So i fixed this before resuming my work!
Link to commit with fix – 7d8dcebeb70776a3e388c387541c877ba6675892
Why are leaks dangerous?

Remember I mentioned something about leaks and why they are dangerous? Well the reason is, our buildbot doesn’t like them!

What is build bot?

Buildbot is a software development continuous integration tool which automates the compile or test cycle required to validate changes to the project code base.

In essence, for each change, it goes through a set of testing that tells if the changes are good enough, and here at scummvm, we believe at code quality! So anything that leaks is not accepted by build bot and thus in cases when something did leak, our build bot flags it and send lots and lots of errors.

The time when I spammed channel with leaking code..

And it has happened that I made code without checking for leaks and had a nightmare of error messages flooding the channel..

Because Spaces should have height too!

And finally, to the last section, that is fixing this bug where there were alignment issues in multiline texts!

This was observed in Spaceship Warlock https://trello.com/c/Mc8OITwf/549-spaceship-warlock-guide-line-spacing-not-respected where the alignment was off, to test this sample test movie was created to see the behavior

scummvm.png
the issue, the texts are not aligned with their buttons!
on the left is ScummVM, on right, is the original Director 4

As you can see, the different height and END tag for first column of text! It was due to this specific code

if (!hastext && _textLines.size() > 1)
height = height > 3 ? height - 3 : 0;

Which was calculating the height of each line in this text, in essence, what code says if there has been no text (ie empty line) and there is multiple lines, then shrink the height of this specific line by 3 units!

As usual, as a good developer with some responsibility, It was up to me to bring these to justice, and as usual, I did just that (by removing that check)! However this change was not very comfortable with different texts in other games, I am still testing more and improving it!

Link to pr – #5100

Bonus Fix: The Apartment 4 Font Fix

While testing for this existing patch, I found yet another bug where apartment 4 was getting font problems in text, as usual being a responsible developer it was fixed and added to pr #5100! The changes in fix:

before the patch, there is font problems in text
after the fix, fonts are good

Ending

Thanks for reading the blog, I hope it was good read! As usual apologies for any grammatical mistakes, typing errors! And that’s it for this one, look forward to my progress next week!

 

2 replies on “Because spaces should have height too!”

Leave a Reply

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