Categories
amusing programming

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]

Categories
games industry startup advice web 2.0

Amazon and the high-value of a low-margin business model…

Some good observations on tech business strategy here

Low-margin can still mean high-value-business:

“Most people just look at a company’s margins and judge the quality of the business model based on that, but the cash flow characteristics of the business can make one company a far more valuable company than another with the exact same operating margin. Amazon could have had a margin of zero and still made money.”

Preventing the number-1 biggest threat to a mainstream company (disruption):

“Study disruption in most businesses and it almost always comes from the low end. Some competitor grabs a foothold on the bottom rung of the ladder and pulls itself upstream. But if you’re already sitting on that lowest rung as the incumbent, it’s tough for a disruptor to cling to anything to gain traction.”

And … an idea I’d considered more seriously back when I started in iOS development. This was the perfect way to disrupt agencies (tough and unpleasant though it was):

“Not having to sweat a constant onslaught of new competitors is really underrated. You can allocate your best employees to explore new lines of business, you can count on a consistent flow of cash from your more mature product or service lines, and you can focus your management team on offense. I”

Categories
amusing fixing your desktop

Virgin Atlantic – how to get them to phone you back

Here’s the magic URL, that you can’t access directly from the site:

http://www.virgin-atlantic.com/en/gb/bookflightsandmore/bookflights/callme.jsp

Huh?

In 5+ years of flying with Virgin, their online booking system has always, every single time, failed – and redirected me to a page where I get that link to get THEM to phone ME.

(which is useful, since the evil mobile network operators don’t like Virgin’s 08-something numbers, and turn them into premium-rate bills)

It’s a pain going to the site, going through the pointless online booking, knowing that you’ll end up on the “our booking system sucks, click here” page.

So I’m blogging this so I never need to do it again!

Categories
agile games industry marketing startup advice web 2.0

How middleware (and open source) downloads ought to work – Unity3D

While upgrading Unity, I noticed the current download page is a great example of how it SHOULD be done:

Unity 4 has some … issues … with backwards compatibility – but at least they made the “need an older version?” link prominent. And how many old versions can you download?

Many!

(it goes on right back to unity 3.0)

Old versions? Who cares!

Well, that backwards compatibility thing is a *****. If you work on a project with other people, and they’re using Unity 3.5 … you SHOULD NOT (must not?) use Unity 4 (there be Dragons).

But it’s fine; Unity makes it trivial for anyone joining such a project to get exactly the version they need.

Some games middleware *cough*Hansoft*cough* companies declare that everyone must use the latest version, even if it is buggy and breaks existing projects. Or if it requires staff retraining. You must retrain EVERYONE! NOW!

(Hansoft has probably changed by now – maybe unfair to single them out. But for a long time they only allowed you to download the “latest” version, and actively deleted everything else. As soon as a new version existed, BOOM! Everything else got wiped. A happy customer I was not)

Recap

So, here we have a piece of middleware, with a download page:

  • Lives at an obvious, permanent URL: http://unity3d.com/unity/download/
  • Makes it very easy to find the download link (many open-source projects: shame on you)
  • Uncluttered webpage, and makes it easy to understand which download you want (Eclipse.org: shame on you)
  • Every version has its release notes right there, for you to click on! (Apple (every product), and Firefox: shame on you)
  • Every version has BOTH the windows AND the mac downloads (computers today are cheaper than they’ve ever been. Many people have a laptop thats Mac, and desktop that’s Windows, or vice versa. You can’t assume that the browser they’re using dictates the desktop they’ll be working from)

Designing a website to look simple is certainly a difficult and non-trivial task.

But in the case of a download page – where almost everyone has the same needs, and there are many examples to copy (plagiarise) from – it doesn’t take much. More projects (and companies) should at least try to do this.

Categories
fixing your desktop games design games publishing programming

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?

Categories
fixing your desktop

Installing Windows on a Mac: what you need to know (2013)

Prologue: Apple et al recommend you “install new OS’s from USB, not DVD – USB is faster”, but I’ve never bothered before. However, there appears to be a major defect in most Apple iMacs, where the DVD drives fail after only a dozen or so uses (google it and there’s depressingly-long forum threads of people reporting the same problem). When this hit my iMac, I was forced to explore the USB alternatives…

Windows 8 boots the same way Macs do

With the arrival of Windows 8, much of what we see on the web about “installing windows” or “booting windows” is wrong — including Apple’s own Bootcamp (currently: almost a year out of date, badly broken, and Apple hasn’t announced a fix. Sigh).

Allegedly (confirmed by direct experience, but I’m no expert on this) – Windows 7 (and previous versions) used “MBR” booting. Intel Macs use the more modern “GPT” booting – and Windows 8 has finally dropped backwards compatibility, and uses GPT too.

So, as of 2013: there is nothing “special” needed to make a Mac boot in Windows 8

In fact, if you try to, Windows 8 install WILL FAIL because it doesn’t support the old MBR booting any more (it even produces a clear, helpful error message explaining why)…

If something ruins your booting, fix from command line

For power-users who know what they’re doing, this stack-exchange answer gives good step-by-step instructions (with explanations!) on how to “un-break” a broken boot setup on Mac. Worth bookmarking (I used it to fix one of my machines).

NB: all the tools they use in that answer are pre-installed with the Mac and have “man” docs – type “man (command name)” in Terminal to read them.

NB: you can run these tools straight away, but they will probably refuse to “save changes” because you’re using the disk they’re trying to change (mentioned in the link above). You’ll need to boot into a special “repair mode” – see below:

NB: if you mis-type the instructions on that page, you probably will wipe your hard disk. Don’t try this while tired/drunk/etc – or at least take a full backup of your computer first!

An OS X “emergency boot USB drive” is only 1GB

The web is plagued with technically unskilled “journalists” who write articles about “make a USB boot disk for OS X”, and all they do is copy/paste Apple’s own instructions on how to INSTALL OS X (and then they claim credit for it).

The OS X installer requires a 4GB – or, if you’re unlucky, an 8GB – USB key. That’s 8x what you actually need.

It is faster, easier, and safer to use Apple’s own “Make an OS X Bootable USB key” app, which works on any USB drive that’s 1 GB or larger.

You can even create the USB key without downloading the special app – although it requires more fiddling (I recommend: download the app. It’s small and trivial to use).

NB: if you own a mac, make one of these now. Do something useful with those crappy 1GB USB keys you have gathering dust on the shelf!

OS X has an Emergency Partition by default – but you can’t use it

Because those USB boot disks are so massively valuable, Apple now includes a hidden one on your hard disk too, so that you can boot into that and “fix” your main OS X even if you don’t have a USB drive.

Here’s more info on the “Recovery Partition” as its called.

HOWEVER: since that’s installed on the same disk you’re partitioning, … most / all of the disk-repair / disk-alteration utilities are still disabled. That’s why you want/need a USB emergency disk!

Apple’s emergency boot disk doesn’t support all USB devices (e.g. some mice)

Even devices that work during the Apple boot-menu are DISABLED BY APPLE in their “emergency repair / boot” setup.

But without a mouse, you cannot get to the OS X menubar.

And Apple designed their “emergency” system so that most of the features can ONLY be reached viw the menubar (hmm. They really didn’t think that one through…)

So, memorize this keyboard shortcut: ctrl-f2 (or, on a wireless keyboard or laptop: fn-ctrl-f2).

That hilights the “apple symbol” menu, and you can then use cursor keys to reach the other menus.

Apple won’t let you create a USB Windows installer unless you have a MacBook Air

Someone at Apple went out of their way to make life miserable for Apple customers. If you own (or can borrow) a MacBook Air, Apple’s Bootcamp enables an extra “magic feature”: it will create the Windows 8 install USB key for you. (NB: requires a 4GB or greater USB key).

…but if you try this on any other physical Mac, Apple blocks that feature. The key you create will work on EVERY Mac – there’s nothing magical about it.

NB: if you have a Windows 8 DVD but don’t own an Air, and you know someone who does, it’s probably worth borrowing theirs now, to make one of those keys, in case you need it later!

NB: alternatively, if you have access to a machine that already has Windows installed, you can use Microsoft’s “create a Windows8 boot disk / installer” app (says win7, but works for win8 too). Unless you have a recent version of Windows, though, you’ll need to download hundreds of megabytes of .NET updates before this will run – which makes this a slow and irritating option.

Categories
advocacy games industry GamesThatTeach programming web 2.0

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:

Categories
programming startup advice

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.”

Categories
fixing your desktop

How to export timesheets from OfficeTime

OfficeTime is one of the more popular/higher rated time-tracking apps for iOS / OS X. On the whole, it’s fine.

But exporting the data – which is half of the app’s purpose – is extremely difficult. There’s no docs I could find either in the app or on the website. You have to google, get lucky, and find some old blog posts by the author with hints. And even then you still have to jump through a 9-step process.

Every time I need to do this, its sufficiently un-obvious that I forget how and have to figure it out again. So, here’s a step by step:

  1. You must have a wifi network that both your computer and iphone are on
    • Yes, really :(.
  2. Run OfficeTime on the desktop
  3. Create a new project you will never use (author requires you to do this – if you don’t create the blank project, the app quits itself!)
    • I prefer names like “Delete this that Officetime created”
  4. Run the app on iphone
  5. Go to the Settings menu (cog icon from the home screen)
  6. Select “Desktop Sync”
  7. Select “Sync with”
  8. …if everything’s working, your computer name will appear in the list…
  9. On the computer, ACCEPT the sync
  10. …nothing happens. None of your data appears, but don’t panic, this is “as expected”
  11. On the computer, open the Reports menu, and create any report – your data from iPhone will finally appear

…after that, it’s plain sailing. The UX of the desktop app is poor, but it’s trivial from here to get to Excel, and clean up the data.

UPDATE: getting it into Excel…

At first, I thought you should use the “Reports” menu.

Don’t do that – the export GUI is terrible, it saves files in the wrong format, and … the output format is harder for Excel to use. There’s an easier, better way…

Instead:

  1. Open the QuickStart menu
  2. …this will silently, magically, have gained a set of new options now that your iPhone is connected. One for each project on the iPhone
  3. Select the project you want to export. A window will appear with all the data, nicely formatted, easy to read
  4. NB: for me, the desktop app creates a phantom “0 minutes long” additional entry when you do this. Select it and delete it
  5. Select all the rows in the window, then CMD-C (copy), switch to Excel/OpenOffice.org and CMD-V (paste)
    • (this uses a better format than the built-in exporter, and you can manually clean it up)

This gives you the exact times, down to the nearest minute. Most people don’t bill their client that way – although it’s good to show the actual numbers, you usually want to do a precise (accurate) total, and then round to the nearest 15 minutes for each billable period.

Here’s the Excel / OOO formula for that:

Create a SUM cell for all your times (use the appropraite column, not C6:C10):
=SUM(C6:C10)

Create a ROUNDING cell for final number (C12 is wherever you put your SUM cell above):
=CEILING(C12; 1/24/60 * 15 )

NB: the “15” in that last formula is the “number of minutes to round to” … replace it with “30” for half-hours, “60” for hours … etc.

Categories
advocacy bitching web 2.0

Ethics in the modern world: Lessig on Aaron Swartz

I don’t normally blog about this stuff, but here we have the intersection of an eloquent speaker on core matters of modern life and how they intersect the legal systems … with the kind of tragedy that’s often threatened when elements of society have orders of magnitude more power than responsibility:

http://lessig.tumblr.com/post/40347463044/prosecutor-as-bully

The public statement by the prosecutors is worth reading too:

http://0v.org/carmen-ortiz-has-released-a-statement/

UPDATE: according to the United States Department of Justice’s own website (?), in relation to this case:

United States Attorney Carmen M. Ortiz said, “Stealing is stealing whether you use a computer command or a crowbar

It is extremely difficult in practice (practically impossible?) to steal via “a computer command”. To me, the Attorney’s statement has no relevance to what – it is reported – happened in this case.

For reference, type “define: stealing” into Google, and see what you get

Lawyers can *always* hide behind a claim that they’re “only following the letter of the law”; unfortunately, the Western legal system is generally based upon NOT following the letter of the law, but the spirit of the lawmakers (as interpreted by various stages of Judges). Which makes such arguments inherently specious.

I’m not a lawyer, merely a slightly-informed amateur, but … If this is the best defence that the prosecutors can offer, as eloquent lawyers, it appears to me that they knowingly do terrible things.

Categories
computer games design games design games industry network programming programming

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.”

Categories
programming

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 1.0.x version of SVGKit

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

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

Display an SVG file on-screen using an ImageView

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

…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.

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

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

[objc]
// 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];
[/objc]

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

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

[objc]
@interface MyNewClass : NSObject <SVGKSourceReader>

[/objc]

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

[objc]
-(NSObject<SVGKSourceReader>*) newReader:(NSError**) error
[/objc]

Finally, use your customized SVGKSource to load your SVG:

[objc]
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];
[/objc]

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.

[objc]
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;

}
[/objc]

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

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

[objc]
// 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

}
[/objc]

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

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

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:
[objc]
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
[/objc]

NOTE: there are several “newCopy…” methods, and each has different effects and outcomes. Read the method docs for each to decide which one you want to use. In a future version of SVGKit, we’d like to move these methods into a class of their own, and make it easier to see which one does what

Customise the parsing, using your own parser extensions

Create your custom class that adheres to SVGKParserExtension:
[objc]
@interface MyCustomSVGParserExtension : NSObject <SVGKParserExtension>

[/objc]
Then create a parser, INCLUDE THE DEFAULT extensions, and add your one on the end:
[objc]
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];
[/objc]

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

[objc]
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;
[/objc]

And then you have the following info:
[objc]
/* 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;
[/objc]

UPDATE: more Recipes!

For more recipes, see SVGKit Recipes part 2

(this covers answers to some of the common questions asked in the Comments below)