Monday, 31 October 2011

Math(s) puzzle

Work on Topia continues but it's one of those phases where it's all UI and making underlying systems more flexible as it evolves from a tech demo into a real game, all stuff that would be pretty boring to blog about and possibly expose me as a hopelessly retro coder which I could probably attempt to pass off as hardcore optimisation or valid prototyping but, as I said, it would be pretty boring.

Instead, I'm going to set a very simple mathematical problem based on something I saw pointed out last week, I will credit where I saw it but not yet as that kind of ruins the effect. It's really simple maths, or as americans would say "math", I assume they dropped the 's' to make it available for referring to Lego as "Legos"...

The "puzzle"

You have to crack a combination lock with a 7 dials, each dial can be turned to ten positions, showing the digits 0-9, the only slightly weird thing about the lock is that each digit can occur only once in the correct combination.

You can try one combination per second.

How long will it take to try all valid combinations?

Give the answer in weeks, days, hours, minutes & seconds
















(don't scroll down if you want to work it out, this is just padding
in case anyone is actually interested enough 
to post the answer in the comments)















.
..
...
....

Sunday, 9 October 2011

Why iPhone4 - 4S is a more significant upgrade than iPhone3G -3GS was

Since the 4S announcement a lot of people have been saying 'so what?', it's kind of tempting to jump on this bandwagon, specially as I was really looking forward to a bigger screen.

But what of the graphics performance? I've read and heard (including on a few iOS podcasts) that it is a far less significant upgrade from iPhone4 than 3GS was from 3G. This is unarguably true in one way, 3G-3GS introduced OpenGLES2.0 and let us graphics coders start using shaders rather like they had been for years on computers and consoles. 

But what did the introduction of 3Gs mean to developers?

The OpenGLES1.1 on the original iPhone and iPod touch required us to go back to the fixed function programming that we'd cheerfully waved goodbye to some years earlier. Slightly depressing that, to mix two textures in a single pass I had to get my head round ES1.1's texture combiner stuff which was almost but not quite like I remembered it from old fixed function D3D. Still, I managed to get multitexture on the landscape and water of Ground Effect which looked kind of cool at the time. Looking at other games it seems few even took it this far, they mostly just drew textured triangles.

3G - 3GS

So along comes 3GS with it's exciting new system, maybe i'll just add support for it into my game but, what's this? I need to rewrite everything? ES2.0 has no built in transform stuff, lighting, a few missing renderstates. All stuff that now has to be done in the shader rather than through gl calls. Much much better but quite a bit of work to get an app to support GL1.1 and GL2.0 at the same time so, it seems to me, very few developers jumped straight on ES2.0.

By the time iPhone4 and iPad1 came out I don't think I had any apps that were enhanced when run on ES2.0 capable devices (I could be wrong). I had a handful of apps that required ES2 but no more than a handful.

At this point developers started supporting ES2.0 natively, they had to because Retina and iPad1 had pretty crappy emulation of GL1.1 (incredibly slow fog for example). Sadly, when you start trying to use ES2.0 shaders at Retina and iPad resolution you find that, if you want to keep the frame rate reasonable, you aren't going to be using very exciting shaders, barely more than what could be achieved with the fixed function really, maybe some primitive diffuse bump mapping or something but, a year or so after the release of 3GS people were finally starting to support it.

Add iPad2 to the mix and suddenly things get interesting, it has something like 9x the GPU performance, it's actually quick enough to run the same kind of shaders we're seeing on the consoles and using that extra performance is pretty easy. Sometimes, it's as easy as just loading a different, longer, more complex shader and maybe turning on MSAA or writing a cool post processing shader.

So, from a gamer's perspective, iPhone4S is being released into a very different world to the one the 3GS was released into. I've heard people theorising about how Epic and Chair must have had early access to 4S to create the Infinity Blade2 demo when, in reality, all they had to do was run the phone version with their very impressive iPad2 enhancements.

4 - 4S

I suspect there are hundreds of developers who were already including iPad2 enhancements in upcoming apps, thousands who were thinking about it, the 4S is just another very good reason to bother with those bigger, cooler and more fun to write shaders.

Support for 4S will be even easier for those using engines like Unity and Unreal, even if they aren't writing their own shaders, they will simply be able to select more interesting ones.

I guess I'll find out myself on Friday if I manage to get a 4S, unless I've done something really stupid I will see my iPad2 enhancements running on a phone without changing a single line of code.

Wednesday, 5 October 2011

iPhone4S, iOS5 & Ground Effect in Glasses free 3D

Like a lot of people all over the world I was glued to Apple's presentation yesterday. I had two different live blogs and two twitter windows open at the same time.

The 4S looks cool but do I need those features? The new camera looks great but it was good before and those tiny optics are never going to do the job of even a decent compact camera, let alone a real one and 1080p? I've shot maybe two minutes of 720p in my iPhone4 since i've had it.

Of course, as a dev, having something with the power of an iPad2 in my pocket is going to be cool but I don't NEED it, not when i'll have to support iPad1 and iPhone4 for a few games anyway. I have to admit, I'd trade all of the new features for a screen the size of some of the new Android phones.


Anyway, I felt slightly dirty afterwards, as if I'd watched X-Factor or something. At least I could kid myself I was really there for news of the iOS5 GM. I set off downloads for the new XCode, iTunes and the device OSes and a mere four hours later (yeah I know, stupid local cable company stops 30 metres from my home) I had them.

I've had two iPhone/iPod/iPad cables (both falling to bits, like every other dev) hanging out of my mac for a couple of months now and often have two devices plugged in at the same time. I've been impressed with how well iTunes and XCode handle having two devices connected. I thought I'd give iTunes a proper test so I stupidly upgraded and re-synched my phone and iPad at the same time. To my amazement it worked perfectly.

I was rather less impressed with what happened when I tried to build Topia with the new XCode and run it on the new OS. All I got was a blank screen and the music. On trying a debug build OpenGL was throwing up an error on a line of code that hadn't changed for over six months. After a few hours of very depressing and unproductive hacking around I finally went to bed at about 3:30.

I woke up five hours later, instantly remembering that my code was broken. I'd been kind of hoping I'd somehow fix the bug in my sleep and wake up with the answer which isn't the most reliable debugging technique but has worked for me several times over the years. I staggered to the mac and waited for my eyes to focus (getting old is shit) and found myself staring at this line of OpenGL documentation I'd left open last night.

"... The numbers in the command name are interpreted as the dimensionality of the matrix. The number 2 indicates a 2 × 2 matrix..."

Pretty exciting stuff to wake up to I think you'll admit. Weirdly, the answer was there, turns out that where I should have been using:


  glUniformMatrix4fv(parameter, 1, GL_FALSE, matrix);

I had been using

    glUniformMatrix4fv(parameter, 4*4GL_FALSE, matrix);

The real question is how the hell did it ever work before? Anyway, changing that has everything working again, possibly a little faster than before, certainly no slower, which is a big relief on a new OS version. I can't be arsed with getting accurate timings right now to be honest. I might even go back to sleep when I finish typing this...

In other news yesterday, Jeremy from Jakyl who did a great job of the Android version of Ground Effect released a new version which supports the glasses free 3D on the lovely big screens of the HTC Evo 3D and LG Optimus 3D. Sadly it is of course impossible to show how cool this is in a screenshot so here is a quick Topia closeup instead, showing the new soft animal shadows and the footprints we're using to guide herds.