Category Archives: programming

Mirrors in Unity Free version – almost works

UPDATE: see end of post for another idea…

One of the ways they make you buy Unity Pro is gimping the non-Pro version by taking away Stencil Buffer and Render-to-Texture (needed for … many (most?) of the truly interesting effect you can think of). Except … it’s only needed by old-school OpenGL programmers, because everything RtT does can be mimicked in Shaders. Stencils … maybe also?

Anyway, I’m working on a hobby project and don’t need or want the Pro version for now (I’d like to support Unity, but these days the jump in price is way too expensive, at $X000 (they price-gouge you if you’re purchasing from within EU) for a simple hobby project). If/when we’re using it at work, and I have lots of cash, sure – but for now: can’t find that much money.

For the most part, I’m happy to go without RtT for now – generally speaking, hobby projects don’t “need” those kind of effects (and if they do: maybe it’s not a hobby any more?). There’s just one exception: reflections.
Continue reading

App takes all the RAM on a Windows tablet; turns out to be debug code the manufacturer left in by accident

http://www.veracode.com/blog/2013/05/executable-archaeology-the-case-of-the-stupid-thing-eating-all-my-ram/ – Doh!

Everyone has had that dreaded experience: you open up the task manager on your computer… and there’s a program name you don’t recognize. It gets worse when you google the name and can’t find a concrete answer on what it is and why it’s there. It gets even worse when you remove it from Autoruns and it comes back. It gets terrible when you realize it has keylogger functionality. The icing on the cake, however, is when the mystery program is also eating up all your RAM.

The application does not store or transmit or even display the information polled. It does nothing. I spent the better part of two hours scouring the obscure corners of the binary, thinking surely I must be missing some cleverly hidden method that actually uses this data. I couldn’t find one.

that still leaves the question of why it’s doing this at all. The clues are there, vestigial remnants of removed code, exciting to any Executable Archaeologist: The generically named “Form1” of the application contains several widgets which are never actually displayed: a start button, a stop button, a place for displaying mouse coordinates, and a text box for displaying some other unspecified data. I believe this was originally a debugging utility used by “Spacer” engineers to calibrate the accelerometer so that it would not go off when one simply tapped on the touchscreen (triggering a mouse event or keyboard event). They didn’t bother to rigorously prevent memory leaks because it was never intended to run for more than a few minutes at a time. Somehow, through some miscommunication, a copy of this program with the logic for rendering the visuals stripped ended up on the list of utilities that needed to be kept in the final version of “Spacer’s” Windows 8 image for this model of tablet.

Parse.com install is broken; silently requires Facebook SDK

…and the last working version of Parse.com’s SDK isn’t listed on their website any more.

So … if you see this (which you probably will, on any non-trivial project):

Undefined symbols for architecture i386:
“_FBTokenInformationExpirationDateKey”, referenced from:

…then you MUST download and install the Facebook API into your iOS / Xcode project. Especially if you’re not actually using Facebook!

Why?

Parse.com for iOS is currently setup so that you CANNOT use ANY LIBRARIES AT ALL, unless you ALSO use the Facebook library. Oops.

A little bit of naive linking by the Parse.com engineers. C-linking is a PITA to get right, so I don’t blame them.

More problems

1. Facebook won’t let you download their API / library any more.

Instead you have to “install an application” on your system that spews to random places on your machine (where? Well … the app won’t tell you, but on the Facebook website they say it all goes in ~/Documents) – and you’re not allowed to change them.

Wrong place, wrong installer (shouldn’t be hard-coded, shouldn’t “hide” the location). And a pain to deal with, when all that was needed or wanted was a simple ZIP file…

2. Facebook’s latest SDK requires iOS 6 to even compile it – even if you’re not using iOS 6. No-one should be hard-coding to iOS 6, though – so I’m surprised that FB is targetting it as default. iOS 5 is the main target version of iOS for now.

3. Once you find a 6 SDK, you have to add a bunch of extra frameworks which don’t exist except on iOS 6, and set them to “Optional” in the “Project Settings > Build Phases > Link with Libraries” phase.

Details are on the FB iOS Getting Started page, although they’re pretty hard to find (they’re hidden inside a drop-down with an unrelated title).

(incidentally: the FB iOS install page has always been way too long, so I suspect someone decided to “tidy it up” by hiding 95% of it. I think a better solution would have been to remove all the cruft, and fix the install process :))

…anyway, once you get past all that, things go smoothly. NB: when I wrote this, I was on a hack-day at Facebook’s offices, and it took 30 minutes to get Parse’s API installed, because of the above problems. It would have been even longer if I’d not used Facebook in the past, and knew how to navigate their install page.

SVGs, silhouettes, and … dinosaurs

With my recent fixes to “auto-scaling” in SVGKit, I can now take in images, apply various effects, and lay them out in a grid:

Screen Shot 2013-04-14 at 16.04.11

  • Top row: input SVGs of arbitrary size, auto-scaled to fit
  • Middle row: applying a 2 lines of code filter to remove the colours
  • Bottom row: applying a 2 lines of code filter to convert to a solid silhouette

…next step: get this stickers-game working…

SVG Spec: missing documentation: the “Viewport” (and <svg width=”…”>)

In app development, the most common thing people do with an SVG is “render it to fit a specific area on screen”. This is very wise – it’s making use of the core feature of Scalable Vector Graphics: resolution independence.

Unfortunately, achieving that aim is a lot less obvious than you would expect. Most of the SVG Spec is extremely well written, but for this aspect the authors “had a bad day”, and wrote some rubbish prose that’s not technically possible. This leads to a lot of confusion…

I’m trying to make SVGKit for iOS/Mac be 100% standards compliant, and the lack of specification in this area has made it very difficult. Worse … people using the library are often confused by simple items like “how do I make the SVG file fit into a small area on screen?”.

It’s been difficult to work through, and I’ve decided to document what I *think* the authors intended – and how I’m implementing it in our open-source library.

Continue reading

Compiler author demanded ownership of all programs written using his compiler

(from 1982. Blogged now because … the named individual who apparently came up with this scam)

http://imgur.com/a/P9kFa

(for those that haven’t been following: four years after Langdell tried to bully an award-winning iPhone game into giving him their money, using his invalid trademark to threaten legal action … the USPTO has finally started cancelling each of his trademarks. Trademark law is FUBAR: 4 years for a fraudulent(*) TM to be cancelled? Ouch.)

(*) – my opinion, but: read the case notes … he apparently committed blatant fraud to keep-alive a trademark that legally had already expired

Android Dev: Eclipse won’t start? Hangs at splash screen? Kill Mylyn…

For the last couple of months, one of our dev machines has been literally incapable of opening a simple Android project. It crashes every time, on startup, while displaying the Eclipse logo:

Screen Shot 2013-04-05 at 14.45.54

Re-installing everything had no effect. We tried everything, and the only thing that worked reliably was to keep deleting the project and re-synching from SVN every time we wanted to start Eclipse

Today I finally discovered the cause: Mylyn

Continue reading

Apple finally supports Windows 8

Apple has finally released drivers for Windows 8 (NB: because Apple takes standard PC hardware and then customizes it, Apple customers are reliant on Apple for “custom” drivers; the manufacturer drivers don’t work)

Download link for the new drivers (March 2013)

Also: the built-in copy of BootCamp has been updated, if you upgrade OS X to version 10.8.3 or later.

To recap:

  • 2011 September: Microsoft releases first beta of Windows 8
  • 2012 May: Microsoft releases final beta of Windows 8
  • 2012 September: Windows 8 (final) goes on sale
  • 2013 March: Apple enables their customers to install Windows 8

Even being generous, that’s an 11 month delay between “the world discovering that Apple hardware needed a new set of drivers, or Windows 8 wouldn’t run” and “Apple delivering the drivers”. Many Apple machines were fine, but a large proportion were effectively blocked from running Windows 8 at all. It’s good to see this finally released, but … that’s a pretty poor service from a company the size of Apple.

Worst was the iMacs, where even machines less than 18 months old were (allegedly, according to the Apple.com forums) unusable on Windows 8. You could install it (with some hacks), but then the graphics card was disabled. This means: most major software won’t run (because the graphics card is used so heavily on modern computers you got corruption of on-screen info, or just massive drops in performance, so that apps were unusable), and definitely: no games.

…which, after all, is one of the main reasons for Mac users to dual-install Windows.

Interestingly, it seems this was caused by Apple’s modifications of the ATI graphics card, so that the ATI drivers were convinced there was an external monitor (which Apple didn’t provide a socket for, so there was nothing you could do – even if you owned a second monitor).

Interesting because: in the PC world, ATi used to be famous for writing low-quality, poorly-tested graphics drivers. ATi owners were accustomed to poring over every new minor version update “just in case” it fixed the glaring bugs in the previous one – and spent a lot of time de-installing and re-installing the older versions (when the newest version frequently introduced major new bugs).

So … although it’s ostensibly Apple to blame here in being so late to fix it, my suspicion is that it was some shoddy code in ATi’s driver that (accidentally) only affected Apple-modified cards.

3rd Party Device drivers: every OS-developer’s nightmare!

Every size you need to know when designing for iOS

References

Building an app, the basics

iPhone launchimage/splash

Default.png Default-568@2x.png
Model Size Model Size
3 + 3GS 320×480
4 + 4S 640×960
5 640×1136

iPad launchimage/splash

Default.png Default@2x.png
Model Size Model Size
1 + 2 768×1004
or 1024×748
3 + 4 1536×2008
or 2048×1496

iPhone fullscreen

No status bar with status bar with status bar + navbar
Model Size Model Size Model Size
3 + 3GS 320×480 3 + 3GS 320×460
or 480×300
3 + 3GS 320×416
or 480×268
4 + 4S 640×960 4 + 4S 640×920
or 960×600
4S 640×832
or 960×536
5 640×1136 5 640×1096
or 1136×600
5 640×1008
or 1136×512

iPad fullscreen

No status bar with status bar with status bar + navbar
Model Size Model Size Model Size
1 + 2 768×1024 1 + 2 768×1004
or 1024×748
1 + 2 768×960
or 1024×704
3 + 4 1536×2048 3 + 4 1536×2008
or 2048×1496
3 + 4 1536×1920
or 2048×1408

iPhone app icons

App iTunes Spotlight
Model Size Model Size Model Size
3 + 3GS 57×57 3 + 3GS 512×512 3 + 3GS 29×29
4 + 4S + 5 114×114 4 + 4S + 5 1024×1024 4 + 4S + 5 58×58

iPad app icons

REQUIRED
App iTunes NewsStand (if Newsstand app)
Model Size Model Size Model Size
1 + 2 72×72 1 + 2 512×512 1 + 2 >= 512
3 + 4 144×144 3 + 4 1024×1024 3 + 4 >= 1024
OPTIONAL
Spotlight Settings
Model Size Model Size
1 + 2 50×50 1 + 2 29×29
3 + 4 100×100 1 + 2 58×58

Touch interfaces: Help for new users (any app)

I’m writing an iPad game that’s designed to be self-evident and trivial to use.

Today, I made a re-usable “tell the user how many fingers to use” animation that would work well with any app. So, I decided to open-source it and stick it on github.

Screenshot from my current app (NB: you need to photo YOUR fingers – not mine! – if you want it to look like this)

Usage

Instructions are in the source code, but my intention is for this to be ULTRA SIMPLE for you to use, so here goes:


// Add this to the main UIViewController for your app - the one that displays
//   when you're ready for user interaction
-(void)viewDidAppear:(BOOL)animated
{
	VFingersHelp* helpView = [[[VFingersHelp alloc] init] autorelease];
	/** This will position the helpview in bottom-left corner. Bottom left/right corners are where 
	users prefer to "touch" (c.f. Disney's style guide for toddlers).
	While they're watching the help, we don't want them touching, so we deliberately place in bottom corner.
	(feel free to move to top corner if you prefer).
	NB: it's easy to take a photo of your fingers and display at bottom of screen...
	*/
	helpView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin;
	helpView.center = CGPointMake( 0 + helpView.bounds.size.width/2.0, 2.0 + self.view.bounds.size.height - helpView.bounds.size.height + helpView.bounds.size.height/2.0);
	[self.view addSubview:helpView];
}

Teenagers learn to program, write own 3D game, in 3 weeks

Background

Last year, Pearson ran the first ever Innov8 competition, giving tech startups a chance to make their own innovative new product/project. The grand prize was £5,000 towards building the product.

Most of the teams were adults (even: real companies), but a team of students from Blatchington Mill School won, with their idea for an iPhone/iPad app: “My Science Lab”.

Team: Quantum Games

The three students named themselves “Quantum Games”: Jon, Nick, and Oli. All three of them have been studying for their GCSE’s in parallel with this project.

They’ve been supported by Mark Leighton, Assistant Head / ICT Director at the school.

For mentoring and game-development expertise, they had me – Adam Martin – previously CTO at MindCandy and NCsoft Europe, now an iPhone/Android developer

Previously

The students chose to focus on a game that would help other students revise the “Momentum” part of GCSE Physics.

In summer/autumn 2012, they learnt the basics of game design and development. We didn’t do any formal teaching – they simply had to pick up the skills they needed as we went along. YouTube videos, and “trial and error”, were our primary techniques…

In particular, they learnt 3D-modelling and texturing (using Wings3D and Photoshop) and game-programming (using Unity3D and Javascript).

By the end of 2012, they’d written their own physics engine, some basic gameplay, and a simple simulation of an exercise/problem in Momentum.

Last month

The big thing this month has been BETT. Pearson had a large stand, and asked the students along to talk about the project. They gave an excellent presentation to an audience of approx 30 people at BETT, covering the background and some of the things that went well, that didn’t, and what they’d learnt from it.

Leading up to BETT, they worked hard to squeeze in a new build of the game, with a rethink on the interactive sections and how they hang together. Unfortunately, we hit what seemed to be a major bug in Unity’s camera-handling, and none of us could fix it in time (nor could we get an answer from Unity support in time). But the students managed to invent a workaround at the last minute which worked fine for demoing at BETT.

The game isn’t finished yet – GCSE’s and schoolwork left too little time to complete it before BETT – but we’re very close now. The students are aiming to finish it off this month and next, and I’m hoping I might even be able to take a copy to the GDC conference in March (taking place in San Francisco, GDC is the commercial games industry’s main annual conference).

In the meantime … you can sign up now on the Quantum Games website (http://quantumgames.co.uk), and we’ll email you as soon as the game is ready – or sooner, with a private beta-test!

Modem dialup noises … visualised (and transcribed)

Visual spectral diagram showing the noises modems make, and box-outs for what they’re actually saying:

…and Transcription for txtrs

Modem A: hey babe, you dtmf?
Modem B: u know it
Modem A: what u up 4 2nite? wanna v.8?
Modem B: i wanna ack u like my daddy net2phone use 2 ack me
Modem A: um ok… v.8 then
Modem B: lol jk, u comin?
Modem A: brt just gotta turn off echo suppressors n cancellers
Modem B: ok i wait
Modem B: my pcm is so modulated
Modem A: lol rly? u think u can handle V.90/V.92?
Modem B: D/A?
Modem A: …D?
Modem B: wtf no, im not into that
Modem A: lol jk we can do V.42 LAPM if u want im down 4 nething
Modem A: up to 3429 o/c
Modem A: u know i give as good as i get, ne way u want it, loud or soft, high or low, fast or slow, i got all the time in the world 4 u babe, my clock source is internal
Modem B: of course no 3429. and same 4 me. except i might lose track of time, lol
Modem B: and honey if u with me we gon be makin sum NOISE
Modem B: 6db at LEAST u know how i like it
Modem A: lol i hear ya, 3200 all nite long, the way u get me goin maybe we even go 2 4800 lol
Modem A: set ur pre-emphasis filter params n put on that 1920 hz carrier frequency i got u
Modem A: im here baby
[SCRAMBLED]

Unity crash: “type == kMetaAssetType && pathName.find (“library/metadata”) != 0″

Unity’s QA dept needs a smack up-side the head. If you get this bug, you’re a bit screwed – the only “fix” is to go into system settings and wipe Unity’s crud.

Error message:

type == kMetaAssetType && pathName.find (“library/metadata”) != 0

Thanks, Unity, that’s very human-readable and helpful. Not.

(appears to be an Assert written by a junior programmer – or a debug-only Assert that got left in the shipping version(!))\

Problem:

  1. Unity’s tech team wrote Unity 3 so that it would open projects BEFORE checking if there was a new version available
  2. Unity 4 is NOT backwards compatible; it corrupts projects so that they will NEVER load in Unity 3.x
  3. …also: Unity 3.5 will FATAL CRASH if it tries to open a Unity 4 project
  4. Unity (generally) is badly written and auto-opens the last project, even if you don’t want to, and EVEN IF ITS CORRUPT
  5. Unity (generally) DOESN’T BOTHER to offer any way of starting “safely”

Solution (OS X):

  1. Force-quit Unity (not only does it crash, but it hangs forever) – RMB on the icon, hold down alt/option, and the Force Quit option appears
  2. run Finder, go to (your user)/Library, aka “~/Library”. If you don’t know how, then do ONE OF the following (either works):
    • EITHER: Start at your username folder (it’s the parent folder of your Desktop folder, parent of your Documents folder, etc), un-break OS X (Apple ships it as broken-by-default): google for “enable see Library folder in Finder”, follow the instructions
    • OR: In Finder’s “Go” menu, select “Go to folder”, and type “~/Library”
      • Inside Library, find “Preferences” folder
      • Find *everything* that begins “com.unity3d.” and delete it (there are approx 20 files, of 2 different file types)
      • Re-start Unity, and it will open the default project
      • …And this time, Unity will offer to upgrade to Unity 4

UPDATE

For bonus points, the Unity 4 “upgrade” isn’t an upgrade: it’s a replacement. I expected it to download “the bits that have changed”. Nuh-uh. One gigabyte download! (try getting that in a hurry, when your project has suddenly imploded in front of you, because of the non-existent backwards-compatibility :( ).

Some idle thoughts…

I’ve seen similar behaviour before when writing very simple OS X apps. There’s some massive bugs in Apple’s code that have been around for 5+ years (and Apple shows no intention of fixing), which cause “startup actions” to happen in a semi-random order, depending on the NAME and NUMBER of recently-opened projects.

It takes very little testing to discover this. If it’s the problem with the Unity software, then Unity needs to seriously improve their testing on OS X – they should have discovered this easily.

But also … why on earth are they using the NSDocument loading system? Apple never finished writing the docs for it, they seem to have never finished implementing it (major bits of the API seem to be missing) – in general, OS X authors don’t seem to use it any more. Probably because it doesn’t work?

Free art can help create a generation of non-pirates

The 21st century will be dominated by “digital” culture and art. History suggests that non-digital art will flourish too (while becoming a smaller, more specialized, part of a larger pie). So it’s all good: more people will have more opportunities to create – and more access to experience – a wider array of art. Win/win!

Except … our societies are struggling to work out how we’ll pay our artists when the marginal price of a copy is less than a penny.

Last week, something interesting happened when several unrelated projects I’m in all came together at once.

Someone is ‘stealing’ from CGTextures.com

Marcel at http://www.cgtextures.com/ gives away a huge library of high-res photo textures, aimed at game-developers, entirely for free. You don’t pay for access, you don’t pay to use them. You can include them in commercial games, make a million dollars – and you owe him nothing (bar gratitude).

Last week he came to a private forum asking for advice on suspected copyright infringers, who might have been taking his free images, removing the attribute/authorship info, and selling them for themselves.

Copying the images, and charging for them, is not theft. It’s illegal, but it’s not stealing. The original source is still available – free – to anyone who wants it. And many authors in this case are inclined to let the scummers go free, so long as they stop charging innocent users for something that’s free to all.

But CGTextures isn’t free to run; if they ever need to raise funds to pay for it, some of that money – which the community would happily donate – is being taken right now by a selfish scummer. Hmm. Tricky.

3D art is hard

If you’re “not an artist” (which for most people means: “I’m crap at drawing/painting!”) then making any kind of 2D art is very difficult, and tends to look like utter crap.

Computer games are dominated by good or great art. Even in the Indie scene, where “teams” are often no more than 2 people working together, we have a blinding array of beautiful artworks. At the opposite end of the spectrum – the AAA titles with budgets counted in “tens of millions” of dollars – it only gets better.

People love playing games – and they love making them too. Many people – artists and programmers – dream of “making a game”. But … just like “I’ve a great idea for a book” … the vast majority never manage it.

Two of the most common reasons they fail:

  1. Aiming too high: games require a lot more work than people imagine, and most people get 10% in and discover they’ve bitten off way too much to chew
  2. The artwork looks crap: everyone they show it to hates it (or they dont dare show it), the author hates it, they realise that no-one will play it, let alone pay for it, and they gradually lose the will to finish the project

Anyone can make a game: even un-trained teenagers

We’re in the final few weeks of proving this (a team of three 15-year-olds are about to publish their iPhone game that they designed, built, tested, and launched from scratch).

Starting with nothing but beginner-level knowledge of Javascript (not enough to write an app), they’ve:

  1. Learnt Javascript
  2. Learnt 3D-modelling
  3. Created all their own 3D models, with textures
  4. Built, tested, and refined a working game

Sounds hard, right? Well, yes, it was. But – if you know enough tricks of the trade – most of that can be made easy enough for anyone to do themselves.

  1. Game structure – use an established game engine
  2. Programming – stick to “simple” programming concepts
  3. In-game artwork – “stylised” 3D models are trivial to create (c.f. Minecraft)
  4. Testing – use a modern IDE with a decent debugger

This is all great, but I’ve glossed-over one item there: textures. You can avoid the need for painting skills by making your game-items 3D instead of 2D, but sooner or later you’re going to need to texture them.

JFGI

With the programming, one of the skills I’ve drummed into them is JFGI (Just F’ing Google It). Everytime you get stuck: google it. If you get no hits – fine, you’ll have to work it out yourself. But often you’ll find:

  1. It’s a bug in your tools, not your fault! Here’s a workaround…
  2. It’s practically impossible; don’t waste time trying to solve it…
  3. Your software documentation / manual was missing the following info: …
  4. It’s a generic boilerplate piece of code. Don’t worry about it, but use this copy/pasteable code solution: …

Leveraging the internet as a resource is fundamental to being a great programmer. I’ll gloss over the risks / dangers for now (I’ll write another post on that later), but most of the time you cannot JFGI too often.

But … with the 2D artwork, with the textures for 3D models … Google becomes a danger.

Google Images: the devil on your shoulder

Writing a presentation, and need an image? Google Images it!

…making a game, and need a “wood texture”? Google Images it!

WHOA THERE, JOHNNY!

Doesn’t feel like stealing (that’s cos it isn’t) – but it is something illegal: copyright infringement. It’s precisely why “copyright” was invented in the first place.

And yet: this single problem can make all your effort, all your hard work on your own creative artwork (your game), invalid. You can have the most sublime game design, a control system that a toddler can master, a frame-rate as smooth as silk … but if the 2D graphics (or the textures) are crap … the whole thing falls flat on its face. And most people can’t draw.

How the pros do it

There are simple techniques for making very good textures starting from random photographs. Even a novice can create something perfectly “good enough” in a short amount of time.

Only one thing is needed: a big library of photographs, MORE THAN ONE per real-world “texture” you need to create. If you have the money, there are dozens of Stock Photography resources, each one costing hundreds (or: thousands) of dollars a year.

But if you’re students – undergraduates, high-schoolers – or simply “not rich” (“artist” isnt’ exactly a high-paid career) and working on your own, you probably don’t have “hundreds of dollars”.

Hey, I know! Let’s use Google Imag- … crap.

Enter stage left: > http://www.cgtextures.com/ – a FREE, ROYALTY-FREE, MASSIVE collection of photographs DESIGNED FOR USING IN COMPUTER GAMES. Why? I guess Marcel is just a naturally generous person.

I showed the guys CGT. No problem; texture sources a-plenty. And it’s all free. And legal…

Full circle

  1. potential pirates who are ‘creating’ are happy to respect copyright, if you educate them early enough … so long as they have viable alternatives
  2. if you take away the alternatives, they must weigh up the moral “cost” of infringement against the moral “benefit” (and personal satisfaction) of completing their own work
    • I’m not advocating this piracy; but where no theft is involved, to most people’s minds the cost is tiny and the benefit is huge. Realistically I expected few people to resist when he temptations – both moral and practical – are so big
  3. sites like CGTextures put “artistic creation with 3D” in reach of everyone
  4. pirating art from CGTextures is – AFAICS – only a criminal activity: illegally extract money from someone else’s work, with no ‘creation’ involved
  5. …but if sites like CGTextures go away (if Marcel gives up), and the next generation of artists lose their alternatives, “copyright” has no chance at all

IMNSHO, anti-software-piracy organizations tend to be idiotic, amoral, and begging to be nuked from orbit. They’re often part of the problem, not the solution. If they genuinely wanted to reduce piracy, they should be creating sites like Marcel’s: royalty-free resources of reduced cost that their industries could easily afford to give away for free.

The debate has – for way too long – characterized software pirates as “inherently evil; bad-doers; malicious”. This is undoubtedly true of some (my opionions of anyone re-selling CGT’s free art are unprintable). But we’re not born as software-pirates; we get that way because of the culture and society we grow up in. We have the opportunity to teach new generations respect for copyright – but that cuts both ways.

In the Digital Age, copyright needs to deserve our respect, not simply demand it.

Some other free texture sites

While checking some of the points in this post, I noticed a few other photo-texture sites that offer royalty-free images suitable for games dev, worth checking out:

The cost of interrupting someone … analysed

“Based on a analysis of 10,000 programming sessions recorded from 86 programmers using Eclipse and Visual Studio and a survey of 414 programmers (Parnin:10), we found:

  • A programmer takes between 10-15 minutes to start editing code after resuming work from an interruption.

  • When interrupted during an edit of a method, only 10% of times did a programmer resume work in less than a minute.
  • A programmer is likely to get just one uninterrupted 2-hour session in a day

We also looked at some of the ways programmers coped with interruption:

  • Most sessions programmers navigated to several locations to rebuild context before resuming an edit.
  • Programmers insert intentional compile errors to force a “roadblock” reminder.
  • A source diff is seen as a last resort way to recover state but can be cumbersome to review

The full article – http://blog.ninlabs.com/2013/01/programmer-interrupted/ – includes graphs, analysis techniques, suggested tools / features that help to fix the problems, etc. Good reading.

Also some good comments, for instance:

The less-quoted benefit of Pair Programming

“I was surprised to discover whenI first started pair programming 13 years ago, how one person ia a pair can hold the context while the other person in the pair gets interrupted. We could get back to work in seconds.”

The less-quoted benefit of TDD

“I was also surprised by test-driven development, how it helps keep track of where you are. Here are some of the factors I’ve noticed:
* The test tell you how far you have gone.
* Your test list serves as a reminder of where you need to still get to.
* The focus on small steps meas at any instance there are fewer balls in the air.”

All Game Developers should read Pat Wyatt’s blog…

I noticed a few months back that Pat Wyatt has been blogging rgularly and in a lot of detail last year. This (IMHO) is big news: Pat is an awesome developer who held key positions in the teams behind many of the bestselling computer games (e.g.: Diablo 1 + 2, Starcraft, Warcraft) and went on to co-found Arena.Net (creators of Guild Wars).

I worked with him briefly in the past, and he’s friendly and full of advice and knowledge – but while he was happy to share, IIRC it was rarely in published form.

I’ve had a tough few months, but I’ve been dipping into his blog a few times, and it delivers in spades. Here’s a few hilights:

Assertions: enable them in live builds

(I’ve always felt this was the “right” way to do it for servers – where you don’t have to worry so much about frame-time, and assertions are more valuable at runtime because they help with the hardest-to-trace bugs … but it’s hard to get broad data on what the performance cost is)
http://www.codeofhonor.com/blog/whose-bug-is-this-anyway:

“The bug was easily fixed by upgrading the build server, but in the end we decided to leave assertions enabled even for live builds. The anticipated cost-savings in CPU utilization (or more correctly, the anticipated savings from being able to purchase fewer computers in the future) were lost due to the programming effort required to identify the bug, so we felt it better to avoid similar issues in future.”

…and a great rule of thumb for any Programmer:

“After my experience reporting a non-bug to the folks at Microsoft, I was notably more shy about suggesting that bugs might be caused by anything other than the code I or one of my teammates wrote.”

Some bugs are due to … user’s broken hardware

http://www.codeofhonor.com/blog/whose-bug-is-this-anyway:

“Mike O’Brien, one of the co-founders and a crack programmer, eventually came up with the idea that they were related to computer hardware failures rather than programming failures. More importantly he had the bright idea for how to test that hypothesis, which is the mark of an excellent scientist.

He wrote a module (“OsStress”) which would allocate a block of memory, perform calculations in that memory block, and then compare the results of the calculation to a table of known answers. He encoded this stress-test into the main game loop so that the computer would perform this verification step about 30-50 times per second.

On a properly functioning computer this stress test should never fail, but surprisingly we discovered that on about 1% of the computers being used to play Guild Wars it did fail! One percent might not sound like a big deal, but when one million gamers play the game on any given day that means 10,000 would have at least one crash bug. Our programming team could spend weeks researching the bugs for just one day at that rate!”

AI cheats to improve game balance in RTS’s, starting with Warcraft/Starcraft

http://www.codeofhonor.com/blog/the-making-of-warcraft-part-3:

In most Warcraft missions the enemy computer players are given entire cities and armies to start with when battling human players. Moreover, Warcraft contains several asymmetric rules which make it easier for the AI player to compete, though these rules would perhaps be called outright cheating by most players.

One rule we created to help the computer AI was to reduce the amount of gold removed from gold mines to prevent them from being mined-out. When a human player’s workers emerge from a gold mine those workers remove 100 units of ore from the mine and deliver it back to the player’s town hall on each trip, and eventually the gold mine is exhausted by these mining efforts. However, when an AI-controlled worker makes the same trip, the worker only remove 8 units of ore from the mine, while still delivering 100 units into the AI treasury.

This asymmetric rule actually makes the game more fun in two respects: it prevents humans from “turtling”, which is to say building an unassailable defense and using their superior strategic skills to overcome the computer AI. Turtling is a doomed strategy against computer AIs because the human player’s gold-mines will run dry long before those of the computer.

Secondarily, when the human player eventually does destroy the computer encampment there will still be gold left for the player to harvest, which makes the game run faster and is more fun than grinding out a victory with limited resources.”

SVGKit 2013 – Recipes

SVG is an awesome image format thats widely used, works in all browsers. SVG graphics make better apps and better games – and automatically “upgrade” themselves for future devices.

This post gives some simple 1-line / few lines of code recipes for using some of the main features of SVGKit – SVG implementation for iOS/OS X.

NOTE: this post refers to the new version of SVGKit, currently found at https://github.com/SVGKit/SVGKit/tree/2013base. The main version will soon be upgraded with this version – but for now, you should the 2013base link in this paragraph

Basic usage / installation

Install instructions are on the main GitHub page.

Basic usage / first-time usage info is on SVGKit 2013 – Usage.

Recipes

Load an SVG file like loading a PNG file

SVGKImage* newImage = [SVGKImage imageNamed:@"imagename"];

Display an SVG file on-screen using an ImageView

[self.view addSubView: [[SVGKFastImageView alloc] initWithImage:newImage];

…or an ImageView that supports CoreAnimation for every element

NB: the “Fast” imageview above saves everything as a single layer. Good for rendering, but bad for interaction. The “Layered” imageview here allows you to tap on any layer, rotate/animate/fade/drop-shadow/glow any element, etc.

[self.view addSubView:  [[SVGKLayeredImageView alloc] initWithImage:newImage];

Use a URL to load an SVG (open an SVG file *directly* from the web)

// Splitting URL to multiple lines to make blogpost
//    easier to read...
NSString* longURL = [NSString stringWithFormat:@"%@%@%@",
@"http://upload.wikimedia.org/",
@"wikipedia/commons/f/fd/",
@"Ghostscript_Tiger.svg";
NSURL* url = [NSURL urlWithString:longURL];
SVGKImage* newImage = [SVGKImage imageWithContentsOfURL:url];

Open an SVG from a custom source (maybe an in-memory SVG creation method)

First, create a class that conforms to SVGKSourceReader, i.e.:

@interface MyNewClass : NSObject <SVGKSourceReader>
...

…then subclass SVGKSource, and over-ride the method:

-(NSObject<SVGKSourceReader>*) newReader:(NSError**) error

Finally, use your customized SVGKSource to load your SVG:

SVGKSource* myCustomSource = [[[MyCustomClass alloc] init] newReader:nil];

/** Other examples, using the default SVGKSource class:
SVGKSource* urlSource = [SVGKSource sourceFromURL: [NSURL ...];
SVGKSource* fileSource = [SVGKSource sourceFromFilename: @"monkey.svg"];
*/

SVGKImage* newImage = [SVGKImage imageWithSource:myCustomSource];

Search an SVG file for particular tags / nodes / elements

SVG is an XML file, containing XML tags/nodes such as: “<svg>”, “<g>”, “<path>”, “<linearGradient>”, etc.

NSString* tagToFind = @"linearGradient";
NodeList* result = [svgImage.DOMDocument getElementsByTagName:tagToFind];

for( Element* domElement in result )
{
   // You can use the Element object directly:
   domElement.tagName;
   ...

   // ...or, if it was parsed by the SVG parser, you can convert it to an SVGElement:
   SVGElement* svgElement = (SVGElement*) domElement; 
   ...
}

Search for sub-tags / sub-nodes of a particular tag/node

If you already have an SVGElement reference, you can search all its descendants:

// To search the entire document, use:

// SVGElement* startPoint = newImage.DOMTree;
SVGElement* startPoint = ... // from your code

NSString* tagToFind = @"linearGradient";
NodeList* result = [startPoint getElementsByTagName:tagToFind];

for( Element* domElement in result )
{
   SVGElement* svgElement = (SVGElement*) domElement; // if your tags are all supported by SVGKit, they will be converted to SVGElement instances
   ...
}

Get a list of ALL descendant tags (from a particular node down)

SVGElement* startPoint = ... // e.g. for whole SVG doc, use: newImage.DOMDocument;
NodeList* allElements = [startPoint getElementsByTagName:@"*"];

Render one small part of the SVG file on its own

E.g. if you want to display a subset of the SVG, or want to export a single element:

NSString* idInSVGFile = ... // assuming your SVG file has an "id" attribute for this node
CALayer* absoluteLayer = [newImage.newCopyPositionedAbsoluteLayerWithIdentifier:isInSVGFile];

...

// NB: "absoluteLayer" is now positioned in absolute space;
//   if you add it to your window using e.g.:
[self.view.layer addSublayer: absoluteLayer];
// ...it will appear in the same place as it appeared before,
//   keeping all the offsets, rotations, etc

Customise the parsing, using your own parser extensions

Create your custom class that adheres to SVGKParserExtension:

@interface MyCustomSVGParserExtension : NSObject <SVGKParserExtension>
...

Then create a parser, INCLUDE THE DEFAULT extensions, and add your one on the end:

MyCustomSVGParserExtension* myCustomExtension = [[MyCustomSVGParserExtension alloc] init];

SVGKParser* parser = [[SVGKParser alloc] init];
[parser addDefaultSVGParserExtensions]; // HIGHLY RECOMMENDED
[parser addParserExtension:myCustomExtension];

SVGKParseResult* result = [parser parseSynchronously];

SVGKImage* newImage = [[SVGKImage alloc] initWithParsedSVG:result];

Get help on why parsing failed (and warnings and line numbers!)

SVGKImage* newImage = ... // use methods above

// EITHER: parse using default parser:
SVGKParseResult* parseResult1 = newImage.parseErrorsAndWarnings; // this is a convenience pointer to (SVGKParser*).currentParseRun

// OR: use a custom parser:
SVGKParser* parser = ... // use methods above
SVGKParseResult* parseResult2 = parser.currentParseRun;

And then you have the following info:

/*  array of NSError objects, each one a "WARNING" from the parser */
parseResult.warnings;

/* array of NSError objects, each one a "FATAL ERROR" from the parser - if your SVG didn't render at all, this is why! */
parseResult.errorsFatal;

/* array of NSError objects, each one a "RECOVERABLE ERROR" from the parser - if your SVG didn't render correctly, this is why! (although you probably still got to see something) */
parseResult.errorsRecoverable;

SVGKit 2013 – Usage

SVG is an awesome image format thats widely used, works in all browsers. SVG graphics make better apps and better games – and automatically “upgrade” themselves for future devices.

This post explains how you can use SVGKit – the open-source SVG implementation for iOS/OS X in your own apps

NOTE: this post refers to the new version of SVGKit, currently found at https://github.com/SVGKit/SVGKit/tree/2013base. The main version will soon be upgraded with this version – but for now, you should the 2013base link in this paragraph

(NB: basic installation is covered on the GitHub page – this is about how you *use* it)

SVGKit is like Apple’s UIKit

Originally, SVGKit was a bit tricky to use. I re-architected it to be an exact clone of Apple’s UIKit – same classes, same class structure, same method names.

So, we have:

UIKit SVGKit Notes
UI* SVGK* Apple’s standard: library names start with abbreviation of the library name
UIImage SVGKImage SVGKImage.h started as a copy/paste of UIImage.h
UIImageView SVGKImageView You cannot instantiate it directly, have to use a subclass
SVGKFastImageView Renders your SVG as a single layer, fast.
SVGKLayeredImageView Renders your SVG one CALayer per SVG element; you can hilight individual elements, tap them, animatet hem, etc

(a side note: We couldn’t use a classname prefix of “SVG” because the SVG spec reserves all classnames beginning “SVG”. Apple had a similar problem when they invented GLKit – the prefix “GL” was already used in the OpenGL library they were extending, so they named their classes “GLK” prefix. Hence … “SVGK”)

Loading an image

You already know how to load a UIImage, the “easy way”:

UIImage* newImage = [UIImage imageNamed:@"myImage.png"];

Well, SVGKit is … the same:

SVGKImage* newImage = [SVGKImage imageNamed:@"myImage.svg"];

Displaying an image: UIImageView

And how do you create a UIImageView?

UIImageView* imageView = [[UIImageView alloc] initWithImage:newImage];

…so, for SVGKit:

SVGKImageView* imageView = [[SVGKFastImageView alloc] initWithImage:newImage];
// ..... or: 
SVGKImageView* imageView = [[SVGKLayeredImageView alloc] initWithImage:newImage];

Wait – why is this different?

The reference in both cases is an SVGKImageView – but you cannot alloc-init that class directly. Why?

Different people use the library in different ways. Some people need performance, others need detailed aniamtion. SVG’s contain a lot of bonus info, and it’s not possible to support every use case with a single class. So, you get to choose which one fits your needs

Advanced uses

So far, so easy. What about when you want more control? And how do you load an SVG over the internet (can you load an SVG directly from the web?)

Time to delve a little deeper…

Loading an SVG: in detail

There are four steps to loading an SVG (all of which are done automatically by SVGKImage above):

  1. SVGKSource: specify a location (a file, a filename – or an HTTP URL)
  2. SVGKParser: parse the file (all SVG’s are XML files, so your file can contain any custom XML you want)
  3. SVG classes: convert to SVG’s custom classes (from the SVG Spec); includes automatic support for CSS styling, cascades, etc
  4. SVGKImage: export the SVG to something Apple can render: e.g. a flat CALayer, or a hierarchy of CALayers, etc

Ultimately, I want to add a fifth (optional) stage, where you can “export” the SVG back to a new file. This should be very easy using the SVG classes (they are DOM compliant already).

Every stage is extensible, so you can either add features, or custommize it

Extend SVGKSource: adding new sources

Easy: create a new subclass of SVGKSource, and implement the two methods.

The method signatures are a little strange, because they have to support fast file-access (a C native library from Apple) as well as modern Objective-C methods.

One example of each: the supplied SVGKSource for loading from disk uses C methods, and the supplied one for loading from a URL uses Objective-C methods.

Extend SVGKParser: custom SVG files and formats

NOTE: do NOT subclass SVGKParser; parsing is very complex, and there’s a special mechanism that makes it easy to extend the parser (read on…)

Parsing is complex, so our parser is modular (based on ideas from a modular XML parser I wrote years ago). The SVGKParser class doesn’t parse SVG direclty: instead, it parses raw XML, and converts it to a higher-level version that’s much faster to work with. It also manages error handling, loading bytes from an SVGKSource, etc.

You create a new parser instance with a helper method that includes all the modules you need by default:

SVGKParser* parser = [SVGKParser parserWithDefaultParseExtensions];
SVGKParserExtension: adding your own custom parsing

Our SVG implementation is already split into sub-modules. This makes the code easier to maintain – and it makes it much easier to add support for SVG features one-by-one, in parallel with other developers.

Example classes:

  • SVGKParserSVG: parses “Basic” SVG – obvious things that require no special handling. NB: this is the most complex parser extension we have. Most are much simpler
  • SVGKParserGradients: parses SVG Gradients – because these were added later by a different developer (Stich) … likewise, if you’re adding a msising SVG feature, feel free to make a new parser-extension for it, it’s easier!
  • SVGKParserDefsAndUse: the SVG <defs> and <use> tags are much harder to parse than 99% of SVG, since they require complex cross-referencing and instancing. So, we use a separate parser extension to isolate this code.

For one of my games, I wanted to store gameplay data inside the SVG – attach info to particular SVG tags (e.g. give each SVG path a “bonusPoints” attribute).

To do this in a spec-compliant way, you should:

  1. Create a new XML namespace (requires no code: you simply invent a URL on a domain that you own)
  2. Put the namespace in your SVG file, using an <xmlns> tag, and give it a “prefix”, e.g. “my-game”
  3. Everywhere you want your custom attributes, or custom tags, prefix them, e.g.: “
  4. Write an SVGKParserExtension, and in the “supportedTags” and “supportedNamespaces” methods, return ONLY your namespace, and either nil, or the set of tags you’ve invented

Once the file is parsed, use the DOM to fetch your data (by definition, SVG parsers are required to be DOM-compliant parsers too)

e.g.:

NodeList* myCustomNodes = [svgImage.DOMDocument getElementsByTagNameNS:@"http://my.custom.namespace" localName:@"my-custom-tag"];

(NB: NodeList is defined by the DOM, and is just a wrapper for an NSArray. If you #import “NodeList+Mutable.h”, you can access the NSArray directly, and use ObjectiveC fast enumeration. This is cheating, it’s not in the core SVG spec, which is why it’s hidden inside a separate header file)

Extend SVG Classes: the core SVG Spec

Don’t.

(the only valid reason for doing this is if you find features in the spec that are missing or broken in SVGKit. All other usages, you should be able to do in some other way, more easily, with less risk of your changes being broken when we upgrade SVGKit)

Extend SVGKImage export: export your SVG into custom rendering or to a new file on disk

NB: this is subject to change; we will probably invent an interface for exporting at some point. For now, use SVGKImage directly.

All the parsed data for the SVGKImage is available to you directly, for exporting:

  • (SVGKImage* image).DOMTree : this property contains the entire parsed SVG-DOM (all the SVG* classes)
  • (SVGKImage* image).CALayerTree : this property contains the SVG converted into Apple’s CALayer classes, renderable directly in OS X and iOS

To save memory and CPU, the “CALayerTree” property isn’t created until you request it; if you don’t want the CALayer’s, they’ll never get created.

Improving SVGKit, fixing bugs, and ultra-advanced development

But SVGKit isn’t perfect: there are still missing features, bugs, etc.\

If you find a bug but can’t understand / fix it, please create a simple-as-possible SVG file and send it to us (create an Issue on the GitHub page, and include a link to the file). If you give us permission, we’ll add it to the suite of “test” images we use to verify each version of SVGKit, and that way it will always work, even with future versions.

If you fix bugs, or have bits you want to fix, please have a look at the SVGKit Development guide.

If you want support or help with SVGKit, the very best thing to do is create an Issue on the SVGKit page. That way, any of the contributors can see your problem and help you out. If you email me directly for help, you’re less likely to get a response (I’m busy, and I work on SVGKit entirely unpaid).