Categories
Coding Experience Fun Opinion Technical

Reading Books in Total Distortion

Greetings everybody! Just before we start, I have something to tell you all, It’s about time and we are in the final phases of GSoC ending, the final mentor evaluation is about to happen (2 weeks~) and unfortunately, that means my tenure will be coming to an end! With that being said let’s start with my work this week! (plus what has been merged)

This week I have worked on fixing more bugs and improve more support, let’s start with the title!

Reading Books in Total Distortion!

Linked to https://trello.com/c/ZMRuRYA0/632-index-books-overflow where in books library the index in book was overflowing (see image)

image.png
bad (or bugged) render of books

Now, like any good sensible developer I took it upon myself to fix this issue! To do that I have to investigate, that how this thing is different from other “texts” in Director.. and I found that:

Style: Scrolling and that’s it! The difference was that this “text cast” has this style “Scrolling”, which was giving issues as in ScummVM we didn’t implement “Scrolling” textcast! You might have been confused about one thing: What is “Cast?” or “Text Cast” here??

Well a cast is like an element of movie, it is like the building blocks of any game/multimedia in director engine, and among these elements, we have many different kinds, for example Image cast, text cast, filmloop (series of frames), digital-video etc etc. Now each of these building blocks can have properties, like here TextCast member has this property of Style, where we can choose what kind of cast that is!

The Cast terms originally coined right after movies

e.g. it is one of the actors in a movie, you put it on a Frame, and Frames compose a Score
~ sev, (#engine-director, discord server)

So as I have previously mentioned, there is only simple text cast implemented in ScummVM, therefore, what I had to do is to simply implement a scrolling cast member! One  that takes into account a scrollbar in side and the logic to click items in it!

Well to do that, I just reused the TextScrollingWindow (ie a special kind of window specially created for displaying text in mac styled windows), well I had to do this because of scrollbar, that I needed in order to implement this scroll behaviour! Now as a part of doing this, what I was basically doing is to reuse the code that was written for text display, google says about code reuse:

Code reuse aims to save time and resources and reduce redundancy by taking advantage of assets that have already been created in some form within the software product development process.
and that serves about right! I could have simply written everything into default text class (which was used to mactexts) however the thing is, to do that I have to add scrollbar, its render, then event functions.. basically all of these were there in textwindow itself, so why do that all again when all you can do is to reuse it!
and that is how, after fixing it up, and making more changes to make it work properly, here’s the final result:

and that’s how the working books look like, Happy Reading!

Link to PR – #5182

More work done

Fixing visibility issues when setting window properties

There was this bug where assigning windows property automatically used to bring them to foreground, but this was not good as it means that sometimes hidden window that are supposed to be hidden are now shown, to fix it all I had to do is to remove the statement that does this and voila, fixed!

Link to PR – #5245

Refactor frames loading, fixing chan command

If you have been reading my blogs for a while, you must be knowing about one of the biggest changes to frames loading, well there are still some things that pop out occasionally, one of them being this debugger command “chan <number>” which was used to list channel information on any specific frame! The fix was simple, to refactor some things and fix the logic!

Link to PR – #5255

The End

Thank you for reading so far, its been great writing and working for scummvm and I really enjoyed this whole journey! Before ending I’d like to say that I have been offered to become member of this organization (Director engine), and I am very happy for that! (the process is still underway but expect the results next week), what that means is I can officially start directly committing codes to scummvm, and get some perks (cool discord roles, etc!). With that being said see you in next article!

Categories
Coding Experience Technical

A background window

Greetings everybody. Welcome to yet another blog post for this week’s work, before starting I would like to express that since my university is started, progress is slowed down! So expect fewer PRs than in previous weeks! (Although trying to catch up on weekends)

So what’s in for this week? This week I am highlighting my work on MacWindows and explaining this new thing implemented that is called “background window”

To understand this, let’s start from the very basics, what is the window for Director Engine?

MacWindows – Why, What are they?

Director engine was first created for Pre-OSX Macintosh computers, thereby the headline being “MacWindows”, so basically, In director we say a window is a place where things happen (ie animations, object movie, you click things) this is like any other typical window that you encounter but with a catch!

They are mac window! Since the original director was built for Machintosh computers, We at scummvm needed to build a subsystem of graphics that wholly dedicate to Mac GUI and elements (ie we simulate a mac-desktop-experience), So we have separate code that mimics the look and feel of MacGUI (buttons, menu, borders etc), these are in “graphics/macgui” folder!

And while simulating the behavior, I mean we build everything from scratch, ie mac styled windows, a window manager that takes care of focusing, switching of windows (for example you click a window and it comes to foreground, etc), We even implement borders and other macgui components, Cool right? I’d say complex!

Now how is this all information even related to Director Engine?

Well… because

Window in Director Engine

Window in director engine uses a derived version of macwindow, and it uses the macgui codepaths for all its events handling/etc related to it! That’s why you can say that our director engine is fully dependent upon macgui for it to work! But what was the problem with existing code?

Well, the problem was…. like any window in machintosh computers, if you click outside window, it will lose it’s focus, if you have two overlapping windows and you click one of those, then one window will come foreground and hide another window! And that exactly was our problem!

There were some lingo commands where multiple windows were to be created in game, now it was all good and fine when there’s only one active window, however the moment we switch to multi-window environment we observed a peculiarity, that is: the hiding of windows due to director engine!

Since both director engine and the newly created window are same kind of windows, therefore if you click on director window anywhere except newly created window, then it will hide in the background (Couldn’t understand? See the gif below!)

 

The Fix? It was simple, to declare the main director window as a kind of background window, so when you click anywhere in background window, it doesn’t make it comes front of other windows on screen! This simple change fixed it all and the final result was:

See how the window is no longer hiding when clicking on title “ball” button? Well, there ya got it!

Link to PR – #5221

More work this week

Scoped and Scopeless Lingo Score

This was a problem with old (pre D4) created movies when used in Director 4, since previously there was scopeless lingo commands, and now director have scoped window, therefore there was some behaviour mismatch, It was fixed with some debugging.

Link to PR – #5216

Improve checking for recursive enterFrame

This was a problem with how checks for how many recursive enterFrame is called was performed, in director 4, you can have at most depth of 2 enterFrame calls, any more and it will ignore the handler! This was previously implemented with counting frozen lingo states, which was not enough to identify since lingo can be frozen for other situations as well.

Fixed it by having proper checking and counting of number of enterFrames in callstack.

Link to PR – #5233

The End

Thank you for reading so far, I hope it was a good read! As usual apologies for any grammatical/writing mistake, do comment our your honest suggestions/thoughts on this and with that being said, see you next week!

Categories
Coding Experience Fun Nerdy Talk Technical

Creating sandwiches in Total Distortion!

Greetings everybody, in this blog I will be going through my work for this week! So first of all like everytime let’s start with title!

Creating Sandwiches in TD!

Well, amazed? Just let me explain what I meant, so in this game of total distortion-win, there is this minigame/feature to create your own food for exploration. Why?

Because the story follows a guitarist who teleported himself to a faraway dimension called “Distortion Dimension”, where he must collect unique sounds and ideas to create his next blockbuster! (And thus make a return trip to earth)! In all of these ventures, He needs to have ample health (including mental and physical prowess), and that is where food comes in! The food in total distortion is created using something called “Food Goo”, and sandwiches are just one of the many things you can craft!

That’s it for background, now when I was playing and testing game, there was this bug where I could not change ingredients while creating food/drinks, and that left me quite unsatisfied (and hungry too, getting to eat only one type!) It has been documented here – https://trello.com/c/CexIGcq8/629-food-maker-up-down-item-change-keys-not-working

So with a sense of responsibility, I took it upon myself to fix this and with some tracing, debugging.. It has been found that the problem lied to this statement:

do("set sProtein2 = the number of items in sProteinDB")

Here, the up/down keys were not working because of the anonymous script that is being executed inside (ie set sProtein…), Why?

Because in traces it has been found that

varFetch: variable sProteinDB not found

and so, the whole logic short-circuited and the change in items were not being registered! Well after debugging it has been found to be a problem with how Lingo anonymous function execution works inside handler of factory!

The part do(…), is anonymous calling of script, because it dynamically compiles and execute whatever script or command you feed to it at runtime (just like Python’s eval function), and just like that when the statement was being executed, It didn’t have any idea about sProteinDB which is instance variable (or object variable) for factory! Now since the command is executed in a different Context (or background) therefore It didn’t have any knowledge of object variables and thus that error!

The Fix? Well it was easy, I added a simple check that allowed me to share underlying factory context when the call is made to an anonymous function belonging to factory/script! This allowed the function to view/modify factory variables and thus fixed Sandwiches in total distortion!

Now that’s what you will call a YUMMY change!

(Please ignore the sound when sandwiches are created.. kinda gross)

PR Link – #5191

Making Buildbot Happy

This week, I also dedicated some time in looking at director build bot leaks. If you don’t have much idea, I strongly advise you to read the section “Leaks are annoying (and dangerous)” from my previous blog, At that time, I broke things due to not checking for leaks which made Buildbot quite unhappy and complaining however this time, I tried looking into some common existing memory leaks and fixing them! While doing that I came across one where an “Archive” (ie a structure to manage resources used by game) was leaking when changing Shared Cast. Well don’t sweat up technical terms but after like 4-5 hrs of debugging through code and frustrating nights, I finally found the problem and fixed it!

Results? A good spam and buildbot happy!

buildbot reports on discord, green means what has been fixed since last build
me and sev agreeing on satisfaction of the green spams

PR Link – #5190

More work done this week

Rebuild frames when jumping to the current frame

As on-demand frames loading has been finished and merged, new bugs and regressions keep popping up, just like how in Majestic-win there was the freezing when opening game, I investigated this and fixed it up with simple change.

Link to PR – #5176

Fixing black patches in Mediaband

and there was this regression, where mediaband had black patches all around the screen, again after tracing and debugging where could be the problem, It was fixed with PR #5178

Improve screenshots comparison for buildbot

This one is an upcoming feature for our buildbot, as you know currently we don’t have any system to compare screenshots of game, we only run them and see debug logs for any problems, However in some time we will be implementing frame-by-frame screenshot comparison, so buildbot can flag changes that potentially can break graphics, palettes, rendering etc! (Just how cool is that!)

As part to support that transition, I improved the algorithm for screenshot comparison, initially MD5 of image bytes were compared but since this method wasn’t foolproof, I implemented logic to simple compare each pixels of two screenshots and check if they are within threshold or not! PR with change – #5196

…and that’s it for this week! Before ending up

I have something to tell you all, my university will be opening tomorrow, and I really hope that it will not affect my pace of working, or fixing bugs. But as much as hopeful I want to be, there’s no telling about delays, or slowing down in the future! So I hope everyone keeps up with it and keep looking forward to next blog post!

The End

Thank you for reading up, If you are still here with me, I’d like to express my sincere gratitude for reading this up, the support of fellow readers is one of the thing that keep me up and inspire me write creative/fun blogs. I hope it was a good read and like always do forgive me for any bad writing/grammatical mistakes, etc. With that being said, Adios!

Categories
Coding Experience Fun Technical

It’s not you, It’s me!

Greetings, everybody. Welcome to this week’s blog post! I hope you are all doing fine, so first of all let’s start by this blog’s name, why “It’s not you, It’s me”, Well there’s the reason behind it as one of the bugs that I encountered has to do something related to this term ‘me‘ and thus when referring to this problem, rvanlaar (discord) used this as a joke… more ahead..

Let’s start with good news

Frame Loading Revamped

As presented in so many previous blogs, we are finally reaching the completion of demand frame loading and successfully working on total distortion’s bed dream games, this single big change took so many weeks, and after much effort frame loading has been completely revamped and the master branch is now updated to use on-demand frame load. If you do no know what I am talking about, read this and this to get a basic idea about the change!

PR #5124 by super mentor Sev laid the groundwork for frame loading by merging some 40 commits into master and thus the era of demand loading came! However, some more tweaking had to be done to get everything working properly and most importantly, getting total distortion bed dream games working, for which all this was started!

So after I made more changes and fine-tuned things after which bed dream games started to function normally.

Preview:

PR Link – #5163

It’s not you, It’s ME

Finally, to the fun part, bed dream games were fixed, so what next? To go next part and play the minigames (the bulb one you see in the above video, at the end).. but while testing it, I encountered another bug documented here, that is:

################ LINGO: syntax error, unexpected tINT at line 1 col 13 in NoneScript id: 0!

What does this mean?

To explain it better, I would have to give you a brief idea of what lingo is, and how is it used! But first, you need to know that the Director engine(for which I fix bugs) is a multimedia authoring platform, oh btw

Multimedia authoring is a process of assembling different types of media contents like text, audio, image, animations and video as a single stream of information with the help of various software tools available in the market.

ie such a platform needs different tools and things to control/create movies, and games.. Similarly in director engine, there is Lingo, a programming language that can be used to control various elements of games, like sound, images, etc!

Quoting from this Wikipedia page about lingo

Lingo is a verbose object-oriented (OO) scripting language developed by John H. Thompson for use in Adobe Director (formerly Macromedia Director). Lingo is used to develop desktop application softwareinteractive kiosksCD-ROMs and Adobe Shockwave content.[1][2]

So it is a language that was originally used with director engines, now to replicate that engine in scummvm, scummvm must support reading/parsing this custom language right?

How is a programming language understood by the computer? or more specifically, how is lingo being read by scummvm? Well to understand so, we have to deep-dive into compiler designs and things even I am not comfortable with, but in a nutshell there are these components:

  1. A compiler, which takes for example Lingo and converts it to C++ comfortable instructions.
  2. AST Trees for operands, operations, etc.

Oh, Lingo is a context-free language, I would really love to go deep inside automata theory but that’s an article for some other time!

But what happens, in a nutshell, is a simple instruction like put “Hello” when read by our compiler/parser, jumps into state, ie, converts everything to the token and then token-by-token creates logic/relations etc about different components of instructions, for example here let’s say our parser was initially in state X where it can accept a,b,c,d…. tokens, “put” being one of them, once it received “put” token, it simultaneously jumps into state Y where now it can only accept token like " , etc.. well, all these are then converted to C++ objects which will later be used to execute lingo!

What did go wrong with this bug?

Well, as seen by the error, called syntax error, what happened was that the game was trying to execute an instruction that is little different than what scummvm expects, here in this case, the game tried to execute lingo instruction

me(bubdie2 5, 75)

however, we expected an instruction of this type to be written something like this:

me(bubdie2, 5, 75)

(Please note the comma there), until now, there were no cases observed when a game used the wrong syntax (well correct, to be precise, just non-documented syntax), which was working fine in the original engine, and once again, we didn’t implement this peculiarity!

To be extra sure that it’s “us” not “them” who did this wrong, I verified this by creating testing movies for the director engine and trying to work this off and as expected our Lingo parsing was incomplete as it didn’t account for this edge case! Well time to fix it (but with a twist)

As this was too difficult for me, again super mentor Sev came to the rescue, he told me the problem and after discussions, djsrv implemented this, Link to PR: #5170

Here’s a working screenshot:

screenshot showing working dreamlights minigame

Oh, by the way, this title was inspired by this message of rvanlaar

You can always join our discord using this link and watch progress, and even better contribute and help improve ScummVM!

More Work this Week:

Fixing leaks in lingo-tests: #5164

This fixes leaks, and errors in lingo-tests which makes the build bot green yet again!

The End

Thanks for reading so far, I hope you like it, as usual apologies for any grammar mistakes, etc! With that being said see you in next week!

Categories
Coding Experience Fun Nerdy Talk Technical

Regressions: I make code, then I break code

Greetings! First of all, I would like to apologize for the long break. I was on leave and thus could not find time to be active here! So it’s time to be twice as hardworking to finish everything that lagged behind! (And create quality blogs as well XD)!

So this post is about regressions, what are they, and how do they work? Well…

A software regression is a type of software bug where a feature that has worked before stops working. This may happen after changes are applied to the software’s source code, including the addition of new features and bug fixes.
Again, google to the rescue! But anyway, so you get the general idea! It is about something that used to work (but not now)! So what happens is that in a big project with many moving parts, It is almost impossible to keep track of what new code changes can break other features. Even a seasoned programmer can make mistakes of accidentally breaking some other parts of code while implementing something new. (or perhaps fixing bugs) 
Although checks are in place, which help avoid frequent regressions like Buildbot tests ScummVM uses where each new addition is checked against several test cases already prepared, and their output is compared to expected ones! This is all automated, so much testing is done without much effort (except for setting it up XD).
So it’s been so many weeks already, and as we speak, I am on my last day for mid-evaluation. One question you might ask is:
“Hey HSK, working for so long, didn’t you break things? ie Regressed something?? I see all the good codes and how everything is magically working but where’s the dark part??”
The answer is

Regressions Introduced:

Popup Menu leaks

Linked to #5005 where I first implemented the popup menu, there are some occasional memory leaks(if you have no idea what this is, read the section “Leaks are dangerous” from my previous blog), which I have yet to find concrete ways to reproduce, however with some time I am sure it will be fixed.

Symbol and String Comparison

Related to #5107 where I fixed a comparison between symbol and string and evidently a lot of bugs in total distortion, Well.. I was wrong, Symbol and String are never equal on basic level, just sometimes when used to retrieve items from list using those as keys, do they behave like same! Fixed in #5158 where I moved the code to appropriate location and get everything working.

BDFScaler Scaling

Related to #5125 where I improved the text font scaling algorithm which was initially implemented by another student, however even though I managed to fix many bugs but there were still some more left which were very tricky and we had to disable that feature again in-favour of better GUI.

WinFonts Scaling Memory Leaks

Related to #5126. where I initially implemented Windows font scaling, well some leaks were not being accounted for (ie, scaling fonts), fixed in #5136

Well, even as we speak, and for the sake of open pull requests, We are never sure when another regression is introduced, but what I can do is make sure to fix the regressions and thus help in improving the stability of the director engine! Let’s look at some of the ways to fix/identify regressions:

Git bisect to save us here!

Read more about the git bisect command from here, what it does is to use Binary searching to systematically checkout commits and ask you if the commit is “good” or “bad”, depending upon your answers it will point out where things broke!

It is such a simple and powerful feature that you can traverse thousands of commits in 10 iterations! (for nerds that will be log2(1000) or 9.965 iterations, don’t ask me how)

It is so good that I once wrote a tweet about it:

that is it for the regressions and the dark part.. let’s see what I fixed for these weeks and my work so far!

This week

Use “me” to set “the perFrameHook”

Implemented in #5152, this allows for expressions like

set the perFrameHook to me

total-distortion was using this to assign hooks to call itself perframe using this expression, this is a special case where “me” is used to point current object instance to set “the perFrameHook” property!

Fix the working of m_perform properly

m_perform is a lingo handler to execute an object’s method, much similar to “do(command)”, there were errors when this was used inside mAtFrame, but after proper debugging and discussions it has been fixed by a change in #5153, however the change was little unorthodox so a test is also created in-case it breaks in future.

Fix the execution sequence of lingo scripts in case of frame jumps!

As fixed in #5156 where lingo executions inside the handler were being called immediately after frame jumps, ie (go commands) without waiting for the frame to load. Fixed this by freezing the execution of lingo and waiting before the frame is properly loaded before executing any remaining window!

 

The End

Thank you for reading so far, I would love to hear your thoughts and any feedback/suggestions, as usual apology for any grammatical mistakes and writing errors and especially the long delay for this blog, anyway with that being said, see you next week!

Categories
Coding Experience Fun Nerdy Talk Opinion Technical

The Butterfly Effect of Fixing Bugs!

Hello! It’s nice to see you again XD Welcome to another blog article demonstrating my progress for this week! How was your week? I hope it was good, for me It was amazing as I was quite productive -> (Read More)

So Let’s start!

Justice for Texts, Granted

In my previous blog post I mentioned this text problem where some texts were getting jumped up while others were overflowing! Well, the great detective (err.. developer) HSK, successfully investigated the problem to be linked with fonts!

What was happening in the original behavior is that, while calculating line height (because look, for rendering all those texts, we need to know the exact dimensions they occupy) with custom fonts, the heights were just a very small magnitude different from what It should be (I mean, for some texts, adding 1 to all line heights fixed the problem, but broke all other fonts)

The Solution?

Was very simple. In the original implementation, they only used the font’s height but didn’t make use of another parameter, that is called “Leading”

The vertical space between lines of type is called leading.

After simply making a change, from

virtual int getFontHeight() const { return_data._fRectHeight }
to
virtual int getFontHeight() const { return_data._fRectHeight + getFontLeading(); }
Everything was fixed, WOOHOO!
Obviously, the warlock-100 (game for which bug was discovered), became very happy, as text alignment now properly works! (Screenshot below)
fixed alignment of “The Blaster” text, now matching with it’s play button!
Merged PR link -> #5100

Game Save loading Error – Total Distortion

This is yet another bug which was discovered while playing through total distortion, where sometimes there is corruption in game properties which, when saved and loaded again, completely crash the game!

This is an interesting bug because It made me unable to progress further (and was quite annoying)

Details for this -> https://trello.com/c/TllLPBYZ/626-game-save-loading-lingo-parse-error-totaldistortion

Oh, by the way, there is a public Trello board for tracking bugs and issues. You can always look there to know the current state of the engine!

So again, after lot of digging through I finally found the rootcause of the problem! That was a simple comparison check:

In certain parts of games, two similar but different types were being compared (for example, you can compare Integer 4 and string “4” and expect them to be true). Similarly, it was happening that two datatypes of Director Engine Symbol and String were being checked for equality, now being similar but also different, ScummVM didn’t take them into account and just returned false even for similar ones and thus, this small issue was giving big troubles! The Fix was very simple, that is to tell scummvm to treat Symbol and String comparison by “String” way!

Just for reference, a symbol in Director looks like #mysymbol, while a string is “mysymbol” like if you also have doubts that WHY? aren’t they same?? Well they are not.. let’s see what books say about this!

A Universal “Name Constant”
Symbols are something special to Lingo. They’re sort
of a “name constant,” giving you the portability of
string names minus the computational and data
overhead.

Lingo! (Tab Juilius)

Well, Let’s not go deep into the technical aspect of this, just know that they are similar but distinct!

And finally, here’s the fix: #5107

Butterfly Effect of Fixing Bugs

Bonus section! So I remember my mentor said this when I was starting to submit a proposal in GSoC! He told me:

and look, we are not testing GAMES, we are testing Director, so, there is a beautiful side effect they break because some feature we implemented is not correct or absent 
How is this relevant to my previous bug fix? Well, those words were precisely correct, they couldn’t be any more truth to what I do every day! The more I get into finding and fixing bugs, the more I realize that they are fixing many other things that I have no idea of!
This was very much visible in my last bugfix of symbols comparison, where once I fixed it and was testing game again, I observed that many big and small bugs were also fixed, and the game suddenly got a lot-lot better… Just like that!
That’s why putting emphasis on the butterfly effect of fixing bugs, you fix one bug, It fixes another, and that.. fixes another as well! (The converse is also true, make one bug, destroy the whole program)!

Listing out things that were successfully working in total distortion:

shops and calling feature working!
video sequencer now opening without crash!

Finishing what I started – Meet Mediaband’s UnDo Me

Now comes the last and most nostalgic part! One of the first things I worked on after being introduced to ScummVM is Quicktime Video playback!

Yes, I cannot remember exactly if this was my 2nd or 3rd task, but what I can remember is this was one of the things that gave me an, even more, deeper understanding of the codebase and made me familiar with how things work when you play video!

Anyways, so in the month of March-April, I was given the task to implement custom playback rate and reverse playback for Quicktime Videos, you can just think of it as how your video player can be set to play at twice the speed skipping boring university lectures (Yes, I have done it too, personal experience), but here It was no movie player, here it was ScummVM, and we needed this functionality for this game meet-mediaband where one of the movies were using a miniature sort of video-player with different playback speed and this was all a part of UnDo Me.

A little bit about “UnDo Me”

well, it is a very simple game where you can choose between four romances for our lady and have two controls, “Ice” and “Fire” for going passive or aggressive to different situations and scenarios that will be played throughout the movie, while there are two buttons “Un” and “Do” for reversing/resetting story and for quickly going forward)! This clever game was implemented by seeking different parts of our QuickTime movie! You can even watch this youtube video of gameplay

Continuing on,

In the months of March-April, I implemented this custom playback but didn’t implement/integrate this with UnDo Me (the very game for which it was made), fast forward to 2 months, and suddenly we got a fully explained video of mechanics, and how it looks like, sev (my mentor) asked me to look into it and I knew, This is destiny… (Well I was supposed to finish it either way :P)

Fast forward to another sleepless night and voila! We have our UnDo Me working with all the controls working and a smooth experience! YAY!

Also, special thanks to fracturehill and their PR #4965 that made this integration possible (because setting custom rate audio was not implemented when I first started looking into video playback)! Not only that I must thank him for finding a bug that I mistakenly thought was due to their work(In the end, it was me who didn’t debug it thoroughly)! And being so helpful!

undome in scummvm!

Link to PR – #5118

Ending Notes

As usual, thanks a lot for reading all the way up to here! Apologies for any grammatical, or writing mistakes (My Grammarly is screaming right now), and with this see you next week!

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!

 

Categories
Coding Experience Fun Nerdy Talk Technical

I am a Developer, and I add bugs in Code

Quite an ironic title, right? Must be thinking I am joking, but hey! What if I say this is all true?

Now before getting to this fun story and about how exactly I am adding bugs in code, let me present to you the definition of a bug! As been talked about by my mentor!

Eugene Sandulenko (aka sev, or my mentor) said:

bug is typically a problem in code of unknown nature

And here is something which I found on Google:

A bug is an unexpected problem with software or hardware. Typical problems are often the result of external interference with the program’s performance that was not anticipated by the developer. Minor bugs can cause small problems like frozen screens or unexplained error messages that do not significantly affect usage.

I hope that makes it clear!

Now coming to the good part, I am a software developer, a GSoC’er this year, and most of the time, I resolve bugs, but sometimes I add them too!

The Story

To start with the story, first you need to understand what exactly is my work as a GSoC’er in this organization called ScummVM! So let’s start with basics:

What is ScummVM?

ScummVM is a program that supports numerous adventure game engines via virtual machines, allowing the user to play supported adventure games on their platform of choice. ScummVM provides none of the original assets for the games it supports, and expects the user to properly own the original game’s media so as to use the software legally.

This is what Wikipedia says about us, but in layman’s terms, What we do is to bring compatibility of these vintage games to our modern platforms! We do this by implementing engines in C++. These engines take in-game files, and are able to run them! If you have even a bit of idea about how Unity works, Unity is a game engine; just like that, there are very, very old studio-made game engines using which games were made! What we do is recreate these engines so that if one has the game files for their favorite old games, they can now play them using our software!

What is my Role for GSoC’23?

quoting the bulletin news board itself, it says:

  • Harishankar Kumar will work on improving Director 4 Compatibility. The goal is to reach full support for Total Distortion & The Journeyman Project. You can follow the progress for this task on Harishankar’s GSoC blog

Oh, by the way, If you don’t know. I am Harishankar Kumar XD (And nice to meet you too)

So, what I do, is to improve compatibility for Director 4 Engines. Now, the fun thing is that these engines are made by taking some real vintage game engines as a reference! (In my case, it is Macromedia Director 4, released February 28, 1994) and with these engines come their own quirks and behaviors.

Do you see where I am getting at?

Replicating the Perfect Engine

As part of replicating the perfect D4 engine, I have had to fix many bugs. These bugs were also what made me reach this point, get selected as a student, and write this blog but It is all great when you are fixing a bug that is in ScummVM by taking reference to how the original (ie Director 4) should work, but what will happen if we were to perfect our code such that it is even better than the original? (In some aspects)

Oh yes, you heard it right! So here’s the STORYTIME!

What happened?

As part of taking reference of original and how documentation, books etc says things should work (in Director 4 Engine), our software at ScummVM was developed such that it followed the rules.. however in pursuit. of this excellence, we made big mistake.. that is

Implementing something that is better than the original!

Oh yes! Now if I delve too deep into technical aspects, It will be too difficult to understand, but let’s just say there was this functionality of engine that allowed it to do something, however as part of doing something, It was also doing something else which it was not supposed to do, this something something was something that our software ScummVM was not doing (so we were good, following rules, documentation, and books) however because we didn’t do this something that the Director 4 was doing, our program has bug..

Well, to be precise, the bug was in the original Director 4, however since we perfected ourselves too much, we surpassed the original engine itself (in this feature only, It would be very, very arrogant of me to say we really surpassed the whole engine itself, if that were the case I wouldn’t be there doing something’s riddle to you)

Adding bugs

Now comes the good part, which is adding bugs! Well, this is only a figure of speech because, in reality, I was not adding bugs to this software. I was implementing this non-documented weird behavior (or a quirk) that is present in Director 4 engine, and thus doing my part as a responsible developer!

Now this is a bug of the original Director 4 because It is not how the games built on D4 were used to use.

It was either a genius or a complete idiot who used a quirk of software to do their own work and release this into production! (I still believe they are genius to use something in such a way that is written nowhere, completely unique)

Only god knows if this were intentional. However, the amount of work this adding “small” bug cannot be underestimated because it made us question the fundamentals of the engine and required some heavy changes!

But one thing is for sure, We are moving forward towards creating a perfect director experience, either its features.. or its peculiarities in the form of BUGS!

My work this week

Even as I am writing this blog, I am side by side working to implement this peculiar behavior I just mentioned, however this week, I managed to get another pull request merged, that is #5074

Not only that, this week was quite hectic with all these findings and verifying proper behaviors with respect to these non-documented quirks. I wrote several tests to check and verify their behavior in scummvm!

Ending

Thanks a lot for reading this! Do comment out your honest thoughts and opinion about this blog and follow the series for more of such interesting content!

Categories
Coding Experience Fun Technical

Implementing Mac Styled PopupMenu’s, First PR After GSoC Accepted!

Introduction

This is a blog and demonstration for my first pull request that got accepted after getting selected into this program! I plan to create a blog entry for each of the features/major changes and keep my audience updated!

Anyways, so the first task was to complete something called Mac popup menus, if you don’t know what it is, then It is nothing but a popup menu (i.e., those whom you click, and they give a bunch of options)! Now this was not completely my work but was of someone else.. I was only tasked to complete their work..!

Menus - Material Design
A typical popup menu

The Menu..

The first thing I did after getting this task was to read the codebase, understand how the menu works and try to understand how the existing code operated! To be frank and honest, this actually took me quite a time, plus university examinations were already taking lots of time!\

Anyways, I kept on reading codes, making changes, getting popup menu to be implemented however..

THE CODE WAS VERY BAD

Ahh.. sorry for shouting, lost my composure there for a second :)! Anyways, by code was very bad I don’t mean the code written at ScummVM (this organization), no it is a piece of art, but I mean the code written by the person before me (the unfinished code).

The more I kept on understanding it, hacking it, etc, The more changes I had to do, at some point of finishing their work, I had to change everything from scratch and implement major functionalities myself.

That day I understood, what happens if you write workaround code in big production software, you make life difficult for the people taking your work, sigh.

Anyways, so getting to the main topic.. I was tasked to implement an unfinished popupmenu, for many of you still not getting feel of what this “MAC STYLED POPUPMENU” (of vintage ages) looks like, here the photo taken from Basilisk II (Mac 7.0 Simulation)

Original Mac Popup Menu, as taken from basilisk II

Looking at the state of the popup menu and current implementation, there were many big and small details that needed to be implemented like:

  1. Alignment issues, the rendered menu was some pixels off it is supposed to be, and in some cases, it was very very far away! (We welcome you, Desktop Mode)
  2. BAD CODE, Improper variable introduction (A variable was there just for bad workaround of bypassing some loops, calling some particular functions.. etc)
  3. Many features not implemented (Like smart menu which remembers your last choice), checkboxes, remember last item, etc!
  4. Some more small bugs that were found on the way, needed to be resolved for proper functioning!

Over time, with proper and lengthy discussions and regular updates to mentor, these bugs were addressed and we reached to a point where popup menu in ScummVM were working (demo gif below):

The final result after implementing the popup menu!

Overall this was quite fun to work with, I got a good understanding of how Mac styled windows (not only popup menu) are created and used throughout the project! Director (the engine I work on) was first built for Mac systems, and thus I believe this knowledge of fundamentals would be very useful for long-term contributions!

Plus it was quite fun to find English-ordered alphabet items on the menu (I bet you didn’t notice) ><! (ie the menu items are Apple, Banana, Cherry, Duck… etc, ordered by first alphabet)

Anyways, with this my first pull request after getting accepted was finished, It was successfully merged (After many review rounds and corrections), here is the link to the pull request – #5005!

It doesn’t end here

My frequency of writing blogs do not match with the speed of my contributions! and thus by the time I started writing this, and by the time I reach to this section.. another two tasks were given, I completed them, and the prs are merged! Giving links, they were #5056 and #5059!

These were technical bugfixes/implementations, things that do not have intuitive GUI that I can show (and you understand)! But hey.. Let’s have an easter egg before I end this, and that is:

The Jumping Windows! #5059

A part of the task given to me, (that I solved in pr #5059), was to implement window location set/get functions, in layman terms basically each Mac window (that’s what they call it XD) has this field called rect which can be used to set/change their location!

Now this function to set the window location was unimplemented, and thus there was this thing where it you are supposed to click on “Change” and it will alternatively teleport(err. move) the window between two positions! Initially before implementing, it was not working but after implementing this function, things successfully worked and the window was happily jumping here and there like a happy kid it is supposed to be.

And if you didn’t realize it, this section was meant to be a troll, (but still, jumping windows were good XDDD), anyways thanks for reading!

The End

Thanks for reading so far, I really appreciate each of you still here with me! Also apologies for bad writing style/punctuation/grammar mistakes, etc! I hope this was a fun read and look forward to the next part!