Tales from the front line S01E04

The only place you'll ever hear the truth
User avatar
Byron
level2
level2
Posts: 147
Joined: Tue May 13, 2008 3:48 pm

Tales from the front line S01E04

Postby Byron » Fri Jul 18, 2008 11:55 am

Multiwinia is now approaching that time in a projects life-cycle that in all of the other companies I have worked for has been marked by the sudden appearance of the take-away menu from all the local restaurants. That’s right – its cruch time because we have a release coming soon.

Except, IV don’t do crunch.

Problem with this is that my poor tiny brain can’t quite cope with this fact and I find myself doing crunch just to satisfy the massive hole left behind by the culture at IV. Crunch is quintessential to the games industry. I can’t think of a single place I have worked in where we didn’t do crunch, I mean, at EA I worked on a team where the mantra was ‘lets have a summer this year’!

Most of my work has been to get the network as stable as possible. There was an issue where the server stopped broadcasting its presence after a LAN game had been played and that was trivial to solve, some of the other bugs only appear now and then and they are what I like to call Heisenbugs , i.e. observance changes outcome and are a bitch to find. It usually means a lot of trial and error and running the game lots of times in the hope you will catch the scrawny little thing eating away at some random variable and then you can tonk it.

Going through the code you come across bits that make you cringe. One bit of code that is sure to do that for me is anything that involved a ternary operator. If you need a little brushing up on what such an operator is, it looks a little like this:

(condition 1) ? (expression 1) : (expression 2 )

I hate that operator with a passion. The root of my hatred comes from working on the NT device driver for the Playstation 1 development kit for SN Systems where the code base had an example nested 5 deep using obscure variable names. It took a while to unravel what the heck it was producing and left me with a nervous twitch whenever I see one now. Leander loves them and Chris uses them. I agree in certain circumstances it can make code more compact and maintainable but I just can’t get past my prejudice that the ternary operator is in fact the spawn of Satan and should be banished to the 9th level of hell where it truly belongs. So now Leander takes great pleasure in pointing out to me all the places it has been used.

At the end of a hot day at the Flying Hamster this week Mark declared pub o’clock, which meant we had to down tools and go off to the pub and consume various liquids. It was during this trip that Mark regaled the story to me about how the name ‘Flying Hamster’ came about. When Mark, Tom and Chris were working at another location to the present one the room they worked in had a hamster cage above the TV. Unknown to them the hamsters water supply was leaking down into the back of the TV. Mark sat down one night to watch a educationally well balanced documentary on Channel 4 when ‘boom’ – the TV exploded. This blew off the front of the hamster cage, propelling said hamster through the air and straight into Marks forehead and in a fit of pure genius (bit like Newton and the apple) Mark declared ‘The flying hamster’ and the rest is history.

He later told me that the real reason it’s called the ‘Flying Hamster’ was because they used to have a flat in Hamstead and Chris once mistook Mark saying ‘going to the Flying Hamster’ instead of ‘going to flat in Hamstead’, but to be honest this story seems too far-fetched to be real so I will be sticking with the first story.
User avatar
Xarlaxas
level5
level5
Posts: 1525
Joined: Sat Apr 15, 2006 4:48 pm
Location: Edinburgh
Contact:

Postby Xarlaxas » Fri Jul 18, 2008 12:28 pm

Damn, internet ate my post.

Love this company, you guys never cease to amuse, you make awesome games and keep your fans informed. Rock on!
User avatar
ynbniar
level5
level5
Posts: 2028
Joined: Wed Nov 08, 2006 10:36 pm
Location: Home again...

Postby ynbniar » Fri Jul 18, 2008 12:34 pm

Hang on...isn't that first Flying Hamster tale an episode of The Young Ones... :?:
Mas Tnega
level5
level5
Posts: 7898
Joined: Sat Mar 02, 2002 11:54 pm
Location: Edinburgh
Contact:

Postby Mas Tnega » Fri Jul 18, 2008 12:34 pm

Definitely the first story, and the relevant wikipedia entry should be edited to reflect this.
User avatar
Pox
level5
level5
Posts: 1786
Joined: Sat Mar 03, 2007 11:23 am
Location: Melbourne

Postby Pox » Fri Jul 18, 2008 1:29 pm

Hahahaha... I love this weboblagospheroid.

On the subject of ternaries: they're good if they're being used for value selection, with no nesting. If it's nesting, I expand to a proper conditional for readability... 5-deep ternaries sound very frightening. O_O
elDiablo
level5
level5
Posts: 3111
Joined: Thu Mar 14, 2002 12:23 pm
Location: London, UK

Postby elDiablo » Fri Jul 18, 2008 1:35 pm

Code: Select all

switch (currentWeaponType)
{
    case (item0.type):
        currentWeaponType = item1.researchLevel > 0 ? item1.type :
                            item2.researchLevel > 0 ? item2.type :
                            item3.researchLevel > 0 ? item3.type :
                            item4.researchLevel > 0 ? item4.type :
                            item0.type;
        break;

    ...

}


That is so much better than a massive mess of if/else code. Byron is a crazy man. Ignore him from now on please.

Edit - also, it looks dead sexy!
User avatar
Byron
level2
level2
Posts: 147
Joined: Tue May 13, 2008 3:48 pm

Postby Byron » Fri Jul 18, 2008 1:38 pm

elDiablo wrote:

Code: Select all

switch (currentWeaponType)
{
    case (item0.type):
        currentWeaponType = item1.researchLevel > 0 ? item1.type :
                            item2.researchLevel > 0 ? item2.type :
                            item3.researchLevel > 0 ? item3.type :
                            item4.researchLevel > 0 ? item4.type :
                            item0.type;
        break;

    ...

}


That is so much better than a massive mess of if/else code. Byron is a crazy man. Ignore him from now on please.

Edit - also, it looks dead sexy!


'elDiablo' is sooooo fitting a name.
User avatar
Pox
level5
level5
Posts: 1786
Joined: Sat Mar 03, 2007 11:23 am
Location: Melbourne

Postby Pox » Fri Jul 18, 2008 2:45 pm

The hard-coded non-abstracted-ness, it burns!
User avatar
BiG D
level2
level2
Posts: 138
Joined: Thu Apr 13, 2006 1:14 pm
Location: Ontario
Contact:

Postby BiG D » Fri Jul 18, 2008 2:48 pm

That's pretty good, elDiablo, but you could do better. (Apologies in advance to Byron, and well, everyone else who can read code. :D)

I'm making a couple assumptions here:
    This is code that swaps to the next available weapon in a numerical order
    There is some sort of eval function available
    Some basics about string concatination etc.

Beware! Pseudocode!

Code: Select all

function nextWeaponType(itemNum)
{
   nextItem = "item" + (itemNum + 1 > 4) ? 0 : itemNum + 1;
   eval("return " +  nextItem + ".researchLevel > 0 ? " +  nextItem + ".type : nextWeaponType(" + (itemNum + 1) + ");");
}


Now all you need to do is call that function using the number of the item! If there's no easy way to get that, we can just load it right into your switch from earlier:

Code: Select all

switch (currentWeaponType)
{
    case (item0.type):
        currentWeaponType = nextWeaponType(0);
        break;
    case (item1.type):
        currentWeaponType = nextWeaponType(1);
        break;
   ...
}
Voila! See how easy and elegant that was! :P
User avatar
Pox
level5
level5
Posts: 1786
Joined: Sat Mar 03, 2007 11:23 am
Location: Melbourne

Postby Pox » Fri Jul 18, 2008 2:53 pm

Wouldn't it be even better to make a system call to start a browser to open a page with a dynamically-embedded javascript function which chooses the item, then uses questionable measures to save it to the hard drive, after which it is but a trivial measure to read it back in?
Or maybe an array. I dunno, first sounds more elegant to me. :P
User avatar
Byron
level2
level2
Posts: 147
Joined: Tue May 13, 2008 3:48 pm

Postby Byron » Fri Jul 18, 2008 2:58 pm

BiG D wrote:That's pretty good, elDiablo, but you could do better. (Apologies in advance to Byron, and well, everyone else who can read code. :D)

I'm making a couple assumptions here:
    This is code that swaps to the next available weapon in a numerical order
    There is some sort of eval function available
    Some basics about string concatination etc.
Beware! Pseudocode!

Code: Select all

function nextWeaponType(itemNum)
{
   nextItem = "item" + (itemNum + 1 > 4) ? 0 : itemNum + 1;
   eval("return " +  nextItem + ".researchLevel > 0 ? " +  nextItem + ".type : nextWeaponType(" + (itemNum + 1) + ");");
}


Now all you need to do is call that function using the number of the item! If there's no easy way to get that, we can just load it right into your switch from earlier:

Code: Select all

switch (currentWeaponType)
{
    case (item0.type):
        currentWeaponType = nextWeaponType(0);
        break;
    case (item1.type):
        currentWeaponType = nextWeaponType(1);
        break;
   ...
}
Voila! See how easy and elegant that was! :P


Eval - are you an Actionscript coder?
elDiablo
level5
level5
Posts: 3111
Joined: Thu Mar 14, 2002 12:23 pm
Location: London, UK

Postby elDiablo » Fri Jul 18, 2008 3:04 pm

Both of those are possible solutions, but lack the beauty (read: ability to make Byron's mind pop) that I required!
We dont stop playing cos we get old... We get old cos we stop playing.
User avatar
BiG D
level2
level2
Posts: 138
Joined: Thu Apr 13, 2006 1:14 pm
Location: Ontario
Contact:

Postby BiG D » Fri Jul 18, 2008 3:06 pm

I dabble in most everything, but I'm employed to do PHP (and the javascript that all that ajaxy web stuff requires these days.)

Still, I wouldn't normally get anywhere near eval :p
nea
level0
Posts: 3
Joined: Wed Mar 05, 2008 7:35 pm
Location: Germany

Postby nea » Fri Jul 18, 2008 3:12 pm

elDiablo wrote:

Code: Select all

switch (currentWeaponType)
{
    case (item0.type):
        currentWeaponType = item1.researchLevel > 0 ? item1.type :
                            item2.researchLevel > 0 ? item2.type :
                            item3.researchLevel > 0 ? item3.type :
                            item4.researchLevel > 0 ? item4.type :
                            item0.type;
        break;

    ...

}


That is so much better than a massive mess of if/else code. Byron is a crazy man. Ignore him from now on please.

Edit - also, it looks dead sexy!


Uhhh... you could at least indent the further ternaries. My sympathy is with Byron, I'm no big fan of ternary myself. One level deep for a direct allocation, ok, I can live with that but your nesting is truly... DIABOLIC!
elDiablo
level5
level5
Posts: 3111
Joined: Thu Mar 14, 2002 12:23 pm
Location: London, UK

Postby elDiablo » Fri Jul 18, 2008 3:19 pm

nea wrote:Uhhh... you could at least indent the further ternaries...


Now THAT would look nasty. You'd have a massive tail going across your screen, stretching your document out :(
We dont stop playing cos we get old... We get old cos we stop playing.

Return to “Introversion Blog”

Who is online

Users browsing this forum: No registered users and 3 guests