(Fix) Memory Leaks: Ajax page replacement

Resolving memory issues with HTML replacement and Ajax

In Illyriad we do very large numbers of ajax requests using jQuery over a players session. Some of these are pure data requests, but many of them are navigational HTML page replacements.

A simple replacement seems to leak memory in various browsers:

[code lang=”js”]
$(‘#ElementToReplaceContents’).html(htmlToReplaceWith);
[/code]

Even calling the jQuery function .empty() before the replacement doesn’t seem to help in all cases. To fix this we have created a clean up function which is a common or garden “overkill” variety which seems to do the trick. Usage below:

[code lang=”js”]
function ChangeLocationSucess(data, textStatus, XHR) {
if (XHR.status == 200) {
var div = $(‘#ElementToReplaceContents’);
DoUnload(); // More on this further down
div.RemoveChildrenFromDom(); // Clean up call
div.html(data); // HTML replacement
}

[/code]

Clearing the memory from the existing HTML is done with the clean up code below:

[code lang=”js” title=”Added: RemoveChildrenFromDom jQuery plugin”]
(function( $ ){
$.fn.RemoveChildrenFromDom = function (i) {
if (!this) return;
this.find(‘input[type="submit"]’).unbind(); // Unwire submit buttons
this.children()
.empty() // jQuery empty of children
.each(function (index, domEle) {
try { domEle.innerHTML = ""; } catch (e) {} // HTML child element clear
});
this.empty(); // jQuery Empty
try { this.get().innerHTML = ""; } catch (e) {} // HTML element clear
};
})( jQuery );
[/code]

Some pages have extra resources cached and extra elements with wired up events. For these we have introduced a DoUnload function which also gets called before the replacement. This runs through the list of on page clean up functions and calls them one by one:

[code lang=”js” title=”Extra clean up system”]
var unloadFuncs = [];
function DoUnload() {
while (unloadFuncs.length > 0) {
var f = unloadFuncs.pop();
f();
f = null;
}
}
[/code]

We create these unload functions on the page that has any extra clean up to do by using the following code; which adds clean up functions to the unloadFuncs array above. This code looks like the code below:

[code lang=”js” title=”On page clean up registration”]
var unload = function() {
OnPageCachedResources.clear(); // Clear array of cached resources
OnPageCachedResources = null;
$("#OnPageElementWithWiredUpEvents")
.unbind()
.undelegate(); // Remove attached events
}
unloadFuncs.push(unload);
[/code]

Obviously this varies from page to page and most of our pages don’t need it – at which point the DoUnload function just returns with out doing work.

This coupled with the Fix for IE and JQuery 1.4 Ajax deal with most of the regular unexpected leaks.

(As an aside: When replacing HTML with Ajax, do not wire up events using onclick=”” etc in the HTML or this will also leak. Use event binding from script – a third party library like jQuery, Prototype or Dojo will make this very straight forward)

Extreme Perspective: On the Shoulders of Giants

I have always believed that all artwork should inspire some sort of emotion, regardless of how minor the task or piece of artwork is it should trigger something.

To this end, I have found that the propaganda works World War II to be some of the most thought provoking and inspiring works of our time.  They were simple, yet powerful. They communicated a complex message to onlookers and were successful at motivating fear, anger, patriotism, and a myriad emotions in just moments.

I was also fortunate enough in my early years to stumble upon an artist by the name of Aidan Hughes a.k.a. “Brute”, a propaganda artist in the U.K. that has been working for years on a style that I feel I am just now coming into my own in implementing.  Aidan’s work is by far my greatest inspiration, as he takes what was done for art in WWII and takes it to the next level.  Each piece of artwork he produces drips with feeling and radiates a zeal unmatched anywhere else.

That sort of emotion and energy is something I try to portray in every piece I work on, be it a simple image such as Inventory Management or something more energetic like Raid.  In the game, my goal is for each piece to give an idea of what that technology brings without having to read the description, and to have that image be memorable.  I accomplish this through bold, powerful lines and exaggerated perspectives.  I attempt this also through bringing focus to the main idea of the piece with color transitions, star bursts (perhaps a bit excessively), and sweeping lines that guide the viewer through the piece.  With these components I attempt to meld them into a powerful and thought provoking image.

I can safely say that without inspiration from great World War II artists and Aidan Hughes, I wouldn’t be where I am today.  As eloquently put by Sir Issac Newton: “If I have seen further it is only by standing on the shoulders of giants.”

Extreme Perspective: Ex Nihilo

Just thought I’d take this opportunity to introduce myself and share a bit about myself.

I signed up with the Illyriad staff in taking the daunting task of providing a graphic for each individual technology in each tree.  This overwhelming project has been a wonderful experience for me to both learn and grow as an artist and designer, and I have been grateful for the task and look forward to more.

I was pulled into the staff mainly due to my work with a prior project using a unique style of “propaganda” artwork.  My use of bold lines and extreme perspectives was just what was needed for my particular project; the developers wanted to be able to tell an entire story in just a single panel…something I have proved at having an aptitude in doing.

I showed the staff some of my previous works, all of which had been strictly black and white.  Following are a couple of examples:

The staff liked what they saw and brought me on.  I will be honest I was a bit intimidated at first as I knew I was going to have to move out my my Black and White comfort zone; I had never worked with color before beyond a monochromatic color scheme…this would be new territory for me.

Fortunately the Illyriad project fit like a glove and I have been steaming along creating a unique piece of art for each technology available (and some that aren’t yet released).  I hope you all enjoy what is to come and I welcome any feedback and critiques you may have.

Please enjoy this sneak peak of an as of yet unreleased technology (Shhh! don’t tell anyone):

Chrome Web Store

When you’re a small indie game developer and you’ve just released your very first game, “getting the word out” is just about the most important thing left to do.

It’s also typically the biggest budget expense item via the traditional method of online advertising.

You can have all the upgrades and expansion packs in the pipeline that you like, but if no one is playing the game – or if the cost per acquisition of new players via advertising is astronomical and ever increasing due to the number of competitors vying for the same keywords – then you’re in no small amount of trouble.

Sometimes, however, you get lucky (or make your own luck!) – and an influential big brother steps onto the scene to champion your efforts.  We’ve been very lucky with massively.com’s coverage of Illyriad, and now we have our second champion!

Largely, we think, thanks to our move to an HTML5 Canvas environment on the World Map, Illyriad came to the attention of those mighty, mighty fine people at the Google Chrome Web Store (CWS) at the end of last week; and they’ve been helping to promote Illyriad since.

The first we knew about our presence on the CWS homepage was when the ‘new player has joined’ “bing” noise (yes, I have a desktop dashboard that goes “bing”… I know, I know. Don’t say anything) changed from a “bing” into a continuous drone.

Not only are CWS promoting us on the homepage, but we’re also in the rotation for the Games and Entertainment categories.

Since we’ve been this visible on the CWS platform, new player acquisitions have increased 412%.  No, that’s not a typo. That’s four hundred and twelve percent.

As if that wasn’t enough, the icing on the proverbial cake is that the Chrome browser itself runs HTML5 and the Canvas technology very fast and very smoothly (in our opinion, Chrome is far-and-away the best browser out there for developing and rendering HTML5 technologies).   Whilst we do, and will, continue to support earlier, non-HTML5 browser versions of all the major browsers, it’s been fantastic knowing that the huge new influx of users coming to Illyriad from the CWS are getting the best possible HTML5 experience once they log in.

Since we  integrated OpenID over the last weekend, CWS users are also getting a streamlined one-click login experience using their Google credentials.  Now we’re moving onto Google pay integration, and can’t wait to see what the Google plus platform can do for us in the future.

In short: if you write any kind of app then getting it onto the Google Chrome Web Store is an absolute “must-do” when it comes to promoting your game, and (especially compared to some of the other app platforms) it’s remarkably easy to do.

As you can imagine, we’re over the moon about this!

World Map: Early Thoughts Revisited

In the same vein as the last blog of “Illyriad dev history” regarding factions

Here’re the first drafts of various elements of the World Map, along with a tiny sample of some of the incredibly pedantic arguments (my fault entirely) that went on about region naming; the amount of detail that went into all of this, I hope, shows through…

BIOMES

The Biomes, Fractally generated, and using the WWF biome classification (https://en.wikipedia.org/wiki/Biome#Map_of_Biomes) as source

TOPOGRAPHY

The Illyriad Topography (height, fractally generated) that overlaid the biomes

We loved the mountain range that looked like a skull’s head, or a netherworld demon wielding a whip… and, given it was entirely fractally generated, we saw this as some kind of sign – and this is the candidate that was chosen.

SEAS

Seas, fractally generated and overlaid on the previous two layers

Rivers & Fresh Water

The first pass freshwater layer

These were all then edited (quite substantially in many ways), especially the water.

We then applied over the political regions (manually drawn, largely around topographic boundaries, as a natural barrier to regional development).

Here’s the first draft, with some region names that never made it to the final cut.

The first pass at regions

Up until now, the entire world was randomly generated, just like all the other browser-based games – and we were deeply unhappy with that idea, hence this project.

iirc, due to a small corp forum accident, about 2 players saw this first map before it was released. They were sworn to secrecy – and they kept it. We remember you guys, tyvm!

Should anyone doubt the level of anal-retentiveness that went into all of this, please allow me to reproduce a small sample of a conversation from the inhouse corp forums regarding the naming of a region:

Originally posted by GM ThunderCat
“Qef” as a region – Not sure about this one as it reminds me of [redacted], not sure if that’s my dyslexia or disturbed mind…

Originally posted by GM Stormcrow
Definitely your disturbed mind, TC.

“Qaf” is the 50th Sura of the Qur’an – and it’s very much an Arabic “mystic word” – but by using an “e” (which doesn’t exist in Arabic) instead of the “a” we might escape the inevitable fatwa via transliteration Wink.

Originally posted by GM ThunderCat
How about “Kul Tor” for Qef?

Originally posted by GM Stormcrow
Because mixing base languages (Kul – Sanskrit meaning “family” or “gathering”; Tor – OE, Gaelic twr meaning “Heap” or “Pile” and from where we get the word “Tower”) is bad m’kay?

We could mix Sanskrit and Arabic though, as that’s a fair enough mix.

Kul Qassim – where Qassim means the sand dunes from which the white Saxaul trees grow…?

PPS Edit. There’s actually no reason why we can’t have Kul Tor… Going back to my endlessly tedious “Why do all the names of the rivers on the East Coast of the UK begin with the letter ‘T’ (Thames, Tees, Tyne, Tweed, Tay etc etc)” party-stopper…  It’s because they’re all Sanskrit, from “Tayus”.

So, actually TC, there’s no reason not to have “Kul Tor”. If we can have the river Ketterick (from the sanskrit iekti, where we also get the word “projectile”) and we can have the the river Ale and places Alncromb and Alnwick (from Alaunna – sanskrit plus “combe” & “wick” – OE), then why not Kul Tor?

I sometimes worry for our sanity.

Factions: Early Thoughts Revisited

Factions are now, of course, ingame  (at least textually at the moment and via hubs on the world map), but I thought it might be interesting to share a first draft of a thematic map from the dev forums that I put together last year, illustrating my initial thoughts on how these might all fit together thematically (rather than geographically).

No, it didn’t make a huge amount of sense to the team either…!   But it’s still quite close to my heart.

Some faction concepts didn’t make it to live; most did.  And, of course, the ones up in the top right have, mostly, yet to be seen ingame.

Illyriad Guiding Principles

We’re gamers, not game-industry insiders, and we’ve written a game that we’d like to play ourselves [but are unfortunately forbidden from doing so, as apparently summoning eleventy-thousand Enraged Mammoths to win a battle would be unfair… sheesh, some people…]

You can boil down our philosophy on game design at Illyriad into some general principles that we adhere to with everything we do:

  • Persistence
    2D MMORPG Strategy games should be truly persistent – the world should carry on changing when you log out. We also believe that servers shouldn’t reset after an arbitrary endgame, destroying all the players’ emotional investment in the gameworld.  Why can’t browser games grow, evolve and change with updates and expansion packs so that the ‘endgame’ doesn’t arrive – except when *you* want it to? Just like, in fact, a “triple-A” box-set game.
  • Depth
    There’s no reason why 2D browser games can’t have depth of gameplay, hand-crafted (rather than random) world maps, and lovingly-detailed NPC environments. Why can’t these worlds live, breathe and be truly immersive?  Browser games can be sandbox games, and you really don’t have to insult players’ intelligence and dumb down everything to the lowest common denominator.  Things should be as simple and intuitive to do as possible, but should have levels of depth as deep as the player wishes them to be.
  • Participation
    In a strategy-focused empire-building game we can meddle with catalysts, but there’s no in-game content that’s as compelling to players as player-created content. Our job is to enable that to happen seamlessly.
  • Platforms
    Long-term games should work on as many browsers and platforms as possible; you should be able to play this on your home computer, your iPad, your Android or iPhone when you’re out-and-about.
  • Pay-To-Win
    Yes, the dev team has bills to pay and mouths to feed but so, actually, do the players.  Games that allow “Pay-To-Win” are short-term and self-defeating for everyone.
  • Playerbase
    It’s not how smart your technology is.  It’s not how beautiful your graphics look.  It’s not how many new spells you added.  Sure, all these things are super-important and will help you get new and retain existing players… but the players themselves are far-and-away the greatest asset of an MMO game.  Players also often know better than the design and dev team when something should be changed, and player suggestions should be listened to and acted upon if the idea is sound; don’t be precious about where a good idea came from!  Players also set the entire tone for the game, and disruptive trolls (apart from the NPC kind!) should be sent on their way as fast a humanly possible.  If you let them thrive they will end up driving your core playerbase away, and putting your potential new players off.
I hope someone can come up with a decent synonym for “Depth” that starts with the letter “P”, and then these can be the 6 P’s of our Philosophy 🙂 My thesaurus is sadly, failing me, and my search fu is weak.

MMObility: How to real-time-strategize your way into my heart

Illyriad was mentioned in Massively’s MMObility column:

“I love the look of Illyriad, one of my recent MMORTS obsessions. It has a nice, hand-drawn feel to it and appears warm, inviting, and epic. Scrolling across the map feels like scanning an actual cloth map, complete with hidden areas and scattered empires. The graphics of Illyriad also bring up the fact that an MMORTS can be more accessible than a client-based MMO, especially when you get into the HTML and Flash varieties.”

You can read the full article here.

Integration: Chrome Web Store

Publishing your web app on the Chrome Web Store is so straight forward, not doing so almost seems foolish!

Create a zip file containing a folder “chrome_app” and inside that two files:

  1. 128×128 png icon file
  2. manifest.json file
The manifest we use for Illyriad looks similar to this (make sure the icon field matches the name and case of the icon in the zip):

[code lang=”javascript” title=”manifest.json”]
{
"name": "Illyriad Test",
"description": "Real-time massively-multiplayer…",
"version": "1.0",
"app": {
"urls": [
"https://www.illyriad.co.uk/",
"https://uk1.illyriad.co.uk/",
"https://img3.illyriad.co.uk/",
"https://img4.illyriad.co.uk/",
"https://img5.illyriad.co.uk/",
"https://img6.illyriad.co.uk/"
],
"launch": {
"web_url": "https://www.illyriad.co.uk/loginOAuth.asp"
}
},
"icons": {
"128": "Logo-128.png"
},
"permissions": [
"unlimitedStorage",
"notifications"
]
}
[/code]

Your launch web_url should be either your login page, or if not required the main app page. If you do require a login page it’s also advisable to accept Google OpenId, at which point you can bypass the login page for CWS users who have a Google account and have approved you; but more on this in a later post.

To publish your app and access the developer dashboard a one-off developer registration fee of US$5.00 is required to verify your account, and presumably to cut down on spammers.

In the CWS developer dashboard click the Add new item button, which will take you to the upload app page:

Choose the zip file you created earlier and upload it:

Once you have uploaded your zip you will be taken to the Edit item page. First thing to do is upload the Icon you used in the zip file (unless you want a different icon in the Web Store to the one to be displayed in Chrome)

Now you’ll want to marketing materials. You can choose at the bottom of the page “Save draft and return to dashboard” if you don’t have these ready yet, so you can return to editing later. The items you’ll want are:

  1. A detailed description (Focus on explaining what the item does and why users should install it)
  2. Some screenshots (400 x 275 pixels or proportionally larger)
  3. (Optional) A YouTube video
  4. (Optional) A background image to show on your app page
  5. (Optional) 2 promotional images

After adding these on the edit item page, choose a category to publish in and then click “Preview changes” to see what your item will look like. If you like it hit publish, else return to editing. At this point you are published! Easy!

There is lots more you can do, of course, you can publish to test users first, use a verified website,  change your pricing – your apps don’t have to be free, you can change the pricing and also sell apps from the Web Store – it is a store after all! But this should get you on your way…