Tales from the front line S01E04
Tales from the front line S01E04
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.
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.
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 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.
That's pretty good, elDiablo, but you could do better. (Apologies in advance to Byron, and well, everyone else who can read code.
)
I'm making a couple assumptions here:
Beware! Pseudocode!
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:Voila! See how easy and elegant that was! 
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;
...
}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.
Or maybe an array. I dunno, first sounds more elegant to me.
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.)
I'm making a couple assumptions here:This is code that swaps to the next available weapon in a numerical order
Beware! Pseudocode!
There is some sort of eval function available
Some basics about string concatination etc.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:Voila! See how easy and elegant that was!Code: Select all
switch (currentWeaponType)
{
case (item0.type):
currentWeaponType = nextWeaponType(0);
break;
case (item1.type):
currentWeaponType = nextWeaponType(1);
break;
...
}
Eval - are you an Actionscript coder?
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!
Who is online
Users browsing this forum: No registered users and 3 guests







