Christopher Angelico

Coding to Scale

Tuesday, March 28, 2017

A recent freelance project taught me a valuable lesson in writing code to scale. It’s easy to fall into the trap of writing code for the situation you have and not the one you may ultimately have later. I won’t get into too much detail of the project itself, what I will say is that my focus was on character customization, it was planned to have online capabilities where people can see each others character, and would possibly be mobile. The characters were formed using overlapping layers of sprite sheets. The base layer was the character’s skin while the character features such as hair, shirt, etc. were layered on top. Initially as a MVP I had all sprite sheets loaded into individual arrays for each layer and allowed the user to control the index of each. The class would then take the appropriate sprite sheets, draw one on top of another to form the character, and crop the sheet to just the forward facing position.

This implementation was incredibly inefficient and had a second or two delay whenever you changed one of the character’s layers. I was able to greatly reduce the loading and drawing time by loading only the first column of the sprite sheet instead of the entire sprite sheet. Since the first column contained all eight standing angles, it allowed me to add a rotation feature to the character creation menu. I was eventually given more assets to add to the customizer and it was at this point I learned my first scaling mistake. Loading in every asset into memory was not a viable option, especially if the project would be adding more assets in the future and might be mobile at some point.

My solution was to load them dynamically as needed instead of all together at the beginning of runtime. I created a class called character dictionary that stores a list of strings for each layer of the character and each list contains the paths to assets for that layer. The indexes of each layer that the GUI displays for the user to see and change are stored in an array. Since the array’s size is the number of layers of the character and the dictionary has a list for each layer I used the layer’s index as the key for the character dictionary so it would be easy to iterate through the layers and load the appropriate sprite sheets to create the character sprite sheet.


Character Dictionary
Key Value
0 List<string> Hairs
1 List<string> Shirts
List<string> Hairs
Index String
0 "…./Assets/Male/Hair/Hair01.png"
1 "…./Assets/Male/Hair/Hair02.png"
Index Array
Index Layer Index
0 1
1 4
Example: characterDictionary.getValueAt(0)[indexArray[0]] would result in loading Hair02.png


By loading assets dynamically I made it so that during character creation only the sprite sheets that are needed are loaded into memory. As I am writing the finishing touches on saving and loading their character for the rest of the game when I realize I’ve hit another scaling problem. The players will end up saving a sprite sheet of themselves on their system for the game to reference, but what about everyone else they see in the game? Everyone will need their sprite sheet loaded onto the players system as well. This could translate into dozens if not more sprite sheets cached onto the player’s system and some only really needed for a few seconds depending on how long they are in the player’s line of sight. Now I already knew it would be silly to try to download sprite sheets of each player. Instead, similar to how the character creator does it, they would be generated by the player’s system using a string of numbers received from the server that represent layer indexes that make up other player’s characters. This still doesn’t solve the problem of having to generate dozens or more sprite sheets for each visible player.

The solution was to draw the sprite sheets individually to display the character instead of merging them together and saving it as a sprite sheet. At first this would seem like its more resource intensive because you now have ten or so sprite sheets loaded into memory for a character instead of just one. The truth is that not only is this better, but it fixed another issue that I hadn’t thought of before which is what if two people have the same character with only one difference. With how I originally handled characters that would mean there are two sprite sheets in memory that are near identical except for one feature. With the new way the game already has most of the pieces loaded into memory and only needs to load in one new sprite sheet. This means fewer assets are loaded for characters that share features.

This experience gave me a great lesson on how to better plan my coding in the future, making sure my solutions consider the end goal as best as possible.


Freelance, and Game Jams, and GDC oh my!

Tuesday, March 7, 2017

It's been a while since I posted anything and while I have had topics of interest that I want to write about I figured it would be better to put out a progress post at the very least and maybe a glimpse at what those might be.

One area of interest will be what I have learned from one of my freelance jobs. That lesson was in making code that scales. I learned that sometimes the code you write works for the small scale you are working with, but ultimately you need to write your code in a way that is efficient regardless of how much content is thrown at it.

I may go into what my first game jam was like, but I have other topics I would like to cover like dynamic gameplay/difficulty and haptic feedback in VR. The latter of which I got to experience at GDC.

Lastly, I just want to say out of the entire GDC experience, outside of the people I met, the most amazing thing I experienced was the VR game Robo Recall by Epic Games. If you get a chance, do yourself a favor and play it because it's amazingly fun.

Programming DIY Dilemma

Friday, June 24, 2016

Originally posted on my LinkedIn page on January 29th, 2016.

The age old question a programmer will face many times in his life is "Should I use pre-written code for this or write it myself?" I started thinking about this as a more simplified version of the question presented in an article I read called "License an engine or create your own?" by Dietmar Hauser. Much like the topic of the article there are many pros and cons to using code or even a library instead of writing it yourself.

Starting with pros we have the fact that it saves you time...well slightly, I'll touch on this later, but the time you save from not having to write it may be lost later from a few cons I mention later. If the code is part of a library it maybe be maintained and updated by someone else offloading the need for you to tweak and refactor the code yourself. Lastly, if its publicly available code and widely used, there may be lots of useful documentation on it and how to best implement it.

On the other hand the cons for using pre-written code is that you need to fully understand how it works to make it work with your own code. Not having a full understanding of a piece of your game or program can lead to a ton of headaches down the road all of which may waste more time than you saved not writing the code yourself. If the code is part of a library the changes made to the library over time may be out of your control and counterproductive to your needs. Also if only a small part of the library is being used, then you have more resources than you need and as another article I read, "Avoid adding a new library to the project" by Irina Zamogilnaya, has shown there are many reasons why adding libraries that are not essential is a bad idea. Lastly a flip side to the last pro I mentioned previously is if the code is instead not well documented. Like the first con, if you don't fully understand how the code works you're going to run into problems later on and if you're working with a team things can get even more complicated as now everyone needs to learn how to interact with this code even if it's not well understood or documented.

So to answer the initial question "Should I use pre-written code for this or write it myself?" the answer is it depends. Is it a crucial piece of your game or program? Is it used more than one place? Is it coded poorly or not well documented? Is it small part of a large library? If the answer is yes to any of these questions, then the answer is you should probably write it yourself.

I'm back

Thursday, June 2, 2016

It's been a while since my last post and figure it was time to break the silence. I just graduated with my Bachelors in Computer Science and am now on the hunt for jobs. While I haven't posted here in a while I have actually written blogs involving game design/programming, but they are posted on my LinkedIn account. I will probably repost a couple of them on here as well as some newer content.

I am in the process of making it look a bit less like a geocities or homestead website so please bare with me on the aesthetics and formatting. I hope to start posting on here semi-regularly.

10 ways Animal Crossing could turn over it's next leaf

Monday, August 17, 2015




If you have been a fan of Nintendo since 2001 and owned a console or handheld of theirs, chances are you’ve heard of a game called Animal Crossing. Starting with its debut on the Gamecube (although originally for the N64, which was only released in Japan) the series has found itself among the ranks of Nintendo’s popular IP’s by having an iteration of itself released on nearly all of Nintendo’s systems since then.

In most versions of these games, sans the latest, you are a young boy (or girl) who has traveled to a strange town with humanoid animals to begin living on your own. If this sounds bizarre, it’s because it is, but it’s also strangely appealing and incredibly addictive. Even the creators themselves have a hard time explaining the addiction.

Evolution of Fighting Games

Tuesday, July 30, 2013


Image by jinxonhog


From Karate Champ to Street Fighter II, Virtua Fighter to Tekken, Dead or Alive, Soulcalibur and beyond fighting games have come a long way since their arcade debut. Starting from just a two button karate game and working up to six buttons, special moves, super meters, and even a third dimension; fighting games have evolved a lot over the years, but have since become quite stagnant in terms of innovation.

Calm before the storm, nevermind it's just a drizzle

Monday, July 15, 2013

It's been more then a year since my last post and I figured since I am not a gaming news website I can actually post something on here that just relates to me and what I've been up to.

Well I graduated with my second associates in Game & Simulation Design: Programming Track. Amazing name choice I know. Since then I had quickly gained and unfortunately lost an internship although I am still grateful for the experience and may still end up back with it. I have another big blog topic planned for my next big post so anyone actually paying attention stay tuned.