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 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 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
Experience Nerdy Talk Opinion

The road to GSoC’23 proposal acceptance!

Greetings everybody,

This is my first blog post after getting my GSoC proposal selected for this wonderful organization, ScummVm!

So here I am expressing my journey and experience before 4th May 2023 (GSoC proposal out), have fun reading!

The Start (Needle in Haystack)

How did I find this organization? What was it that told me this is where I want to contribute?

An interesting quote from an article i stumbled upon!

20. “This is going to sound crazy, but… from the moment I first set eyes on you I haven’t been able to stop thinking about you.” – Leigh Fallon

So how did I set my eyes on ScummVM?

It was April 1st, the organizations were announced, and I was running late in finding my match..

I am, but a very enthusiastic computer guy (the one people love to call tech nerd, but no, I’m not), so from a young age, I have been tinkering with technology, learning new things on the way and experimenting with systems, languages, and technology! Now that’s enough for my introduction. How does this answer the question you may ask, don’t worry, I got you covered! ?

So it was 1st March, and I was scrolling here and there, finding interesting organizations that align with my interests, etc. I shortlisted them, but it was ScummVM, the one and only one to which I decided to actively contribute in and submit a proposal! GSoC permits 3 proposals, but I couldn’t care less because what I found at ScummVM is something that just hooked me up to the community of these crazy game porters!

Listing some things out

The Vision

The Vision of ScummVM and what they are trying to build is so cool that it just attracted me to view their project out and consider contributing! What else could be cooler than something which allows me to play old games ? Look its GAME, I repeat, It’s GAME!!!

For someone like me who played lot of old school RPG games in childhood and have attachments to many of them, I could see why I instantly checked out their project and decided to join discord server of scummvm!

Why in italics? Because that was the most important decision I could take, just joining the discord server and introducing myself in #gsoc-channel resulted in a series of cascades of events that resulted in me writing this blog post!

Explaining better in next:

The Community (AND THE BEST MENTOR SEV)

I cannot stress this out enough, I joined server out of enthusiasm but I stayed because of community, the friendliness of everyone and most important the amazing of a mentor that Sev is!

Who is sev?

If you are associated with ScummVM, I don’t even need to tell you about him, but just in case you have no idea then sev is..

Owner, lead, mentor, and developer for ScummVM (as per discord tags) but for me, he’s one of the best mentors I met till now, from the moment I joined the server and introduced myself in the channel, sev created a separate thread for communications (It was a custom to create a separate thread for each student to avoid spam in main channel) and assigned tasks after some communication! What I really loved about this guy is how he used to treat everyone, with kindness, politeness, and in a friendly way!

and most of all how committed he is to ScummVM, this guy has worked over in this organization for years more than I can count doing my computer science degree.

First Pull Request (Assigned Task)

So I was assigned my first task to implement a wrapper around an external library called mikmod for playing impulse tracker files (basically a very old audio format)! If you couldn’t understand, then don’t worry. Just think of I was assigned a technical task and have to implement an easy feature!

While trying to experiment and work on this, I experienced a lot of troubles, and every time I was gravely stuck, sev helped me out! Finally, after a week or two of tinkering and finishing pr, I got it merged! (With thousands of small code corrections, formatting, changes, etc)

What this first pull request taught me is about code conventions and how strictly it is to be followed!

The codes written for scummvm (and applies are not simply written or programmed. They are, instead, I believe, designed!

While the first pr was accepted, It was the 15th of March already, and I still lacked a lot of preparation, study, and commitment to the organization! Seeing the deadline (4th April) approaching, I decided to one-up my game and start actively working!

Link to merged pr

2nd & 3rd Pull Request

Before 2nd and 3rd pull request, I looked into recommended GSoC projects. I decided to work for the Director engine (after discussion with mentor and finding the priority of what is more needed for scummvm). Finding a goal, I started looking deeply into the director engine and getting some bug fixes, etc. to make me understand the engine before writing a proposal!

In the time span of another 2 weeks (by the end of March), I got another two pull requests accepted, link 1 and link 2

Working was very interesting, and I loved playing games, finding bugs, and fixing them! Not only that, but even the developer documentations are great. What I really loved about ScummVM is about how well-documented their codes are, with such a detailed description of almost everything, It was a lot easier to traverse and find relevant functions, classes, etc!

It didn’t feel like I was working with something that consisted of more than 5 Million lines of code.

But regardless, the journey was fun! I got these two pr accepted and finally wrote out a proposal For which I received a lot of scoldings (Thanks to comic-sans font, never using them again) and suggestions!

The Submission

It was the 4th of April, 2023, I double-checked everything and finally submitted it through the GSoC portal!

What I had to do now, is to wait!

The Result Day

It was the 4th of May 2023, as you have guessed right! The day when the accepted contributor’s list is out! This was the day I was very anxious about, being pessimistic I was hoping I could get selected and contribute to ScummVM during the summer vacations!

Finally, the results were out, as usual, the GSoC dashboard site was crashing and I was very anxious trying to open it and checking my emails every second, in the end since it was quite late in my country, I went to sleep giving up, thought wasn’t selected or so I thought, some one hours and minutes later I got an email from Google informing about my proposal being selected! This was a very happy moment and my friends around me were shouting and cheering for getting it!

Now I know that getting selected and completing the project is a different thing, but I plan to stay committed to this organization and finish all the deliverables, passing the project with flying colors!

The End

Thank you for reading this so far, This was just a small excerpt of events happening around me, but I very strongly believe that this is just the starting! For now, expect more blog posts every week following my adventures!