Don’t Cry For Me Ubuntu (Cry for Sata 6G)

Apparently Ubuntu is not for me 🙁

I have have this commodity PC that I snapped together to play Windows games. (Gaming is about all that Windows is good for these days.) So I though I would install Ubuntu and find some other fun things to do besides killing trolls and jumping through portals.

Every time I attempt to install Ubuntu the installer politely informs me that I do not have a hard disk attached to my PC. This is odd because I remember snapping it inside the case myself. (In fact I slid it in backwards the first time around and it got stuck and I had one of those classic /faceplam moments.)

I’ve tried both Ubuntu 10.10 and 11.4 to with no joy. I get stuck in the place inside the installer with the message:

(X) Has at least 4.4 GB available drive space

(The X above is a bad thing.)

I can run Ubuntu off the CD and Disk Utility doesn’t see the drive while GParted states tersely: No devices detected in the lower left corner of it’s status bar. The Unix command fdisk -l returns nothing.

Windows 7 has never had a problem detecting my hard disk. It’s pretty vanilla Western Digital Caviar Black with 1TB of space. It’s not some exotic brand or tech.

When I turn to Google for help I can see immediately this is not a common problem–not many search results. I found this post on the Ubuntu forums that describes a similar problem. Except that the poster has an HHD drive (which is part SSD and part normal drive). But the responses to his problem are not helpful and the thread just dies.

Western Digital’s support forum was not helpful. With the drive invisible tips for tuning it’s performance are just mean.

Currently I have 3, no 2, theories:

  1. I didn’t set a jumper properly or I somehow wired up the drive in a crazy way when I assembled the computer. That Windows 7 can work with my drive seems to disprove this theory but maybe I accidentally hit the Hide from Ubuntu DIP switch.
  2. My BIOS is not setup properly or my drive settings are screwed up. I don’t know much about BIOS but initial Google searches seem promising. I tried changing the SATA configuration settings from IDE to AHCI and from Enhanced to Compatible but without making a dent in the problem. Windows 7 boots no matter how I configure my SATA drive while Ubuntu continues to ignore the drive. This post on the ASUS Suport forum might yet bear fruit.
  3. Windows 7 has a clever hack that prevents Ubuntu’s installer from recognizing hard drives. (I’m just not this paranoid!)

I could just post on some forum but I’m kinda of bullheaded an want to figure it all out for myself. It’s hard for me to believe I have an actual new problem that the world has never seen before.

I will update this post as I progress. Comments welcome 🙂

UPDATE #1:

Theory 2 is disproved. I used ASUS Update to bring my motherboard’s bios up to date and the Ubuntu installer is still not cooperating!

UPDATE #2

Theory 1 is proven! Kinda. My WD Caviar Black drive supports SATA 3G and SATA 6G. So when I originally built my gaming machine I plugged the drive cable into the SATA 6G connector on my Asus P6x58D Premium motherboard. Windows 7 is ok with SATA 6G but I guess Ubuntu is not. SATA 6G is a new standard that is supposed be faster–but IRL isn’t much better than SATA 3G. (At least according to these guys.) When I wired up my drive to the SATA 3G connector Ubuntu recognized it!

So it’s not me that Ubuntu dislikes–it’s new fangled drive interfaces that don’t provide real value!

Cocos2d Tip#3: Making Your iPhone Game Fast

My first iPhone game, that might actually make it to the App Store, is just about done. (Not done done but almost ready for testing and tweaking.)

With the idea that other people beside me might actually play my game I’ve started to do a very dangerous and high risk activity: Optimization!

The all the famous Computer Scientists and Software Architects agree: Optimizing your program is a necessary evil, like the death penalty or bug tracking systems, and to be avoided at all costs.

Well, that’s not quite true. It’s premature optimization that is the bad guy here. Don’t start out programming with performance or scalability in mind, least you optimize code that doesn’t need it and miss optimizing code that really needs it. (It’s the same for bug tracking systems–don’t put all your junk in Jira or Bugzilla–just the verifiable, repeatable bugs that you might actually fix one day.)

When I started my game I knew my ideas were going to evolve and I didn’t want to hard code myself into a corner. I consciously wrote code that I knew would be slow but flexible.

For example I used expensive string comparisons instead of testing for cheap numeric constants. During the initial development phases of my game the strings were self-documenting (I could read them like little notes to myself) and easy to change. Later, when my game solidified and the string comparison were easy to find using Xcode’s Find in Project command (which is now Xcode 4’s Find in Workspace command)…

Changing the type of Character’s role property from NSString* to CharacterRole (a typedef’ed int) sped up my game in update methods which were called with every frame change. It was a pain to add all the constants but at least I only had to do it once–even though my conception of a Character and a role changed quite a bit.

Another big optimization I did was to replace for-loops and with Cocos2d’s fast enumeration macros…

My list of good guys changes during the game so I stored them in a CCArray–Cocos2d’s version of a NSMutuableArray. CCARRAY_FOREACH is a Cocos2d macro supercharged for fast array access. I could have used the Objective-C version of a fast numerator but I like to use as much of Cocos2d as I can. That way when I port my game to Cocos2d-x (C++ cross-platform version) it will be less work 🙂

One of the biggest optimizations I did was to upgrade from Cocos2d 0.99.5-rc1 to 1.0.0-rc. You have to be smart about when you upgrade to a new version of a framework. I don’t agree with the idea of living on the bleeding edge–stability of the platform allows me to focus on my own bugs!

Upgrading from Xcode 3 to Xcode 4 also seemed to help, or at least not hurt, performance. The new version of Cocos2d seems to work better with Xcode 4. I’m still getting used to the shiny new Xcode–it acts weird and slow on my Mac Mini.

To make framework and Xcode upgrades easy I put very little code into my app delegate class. All I have to do is to comment out…

and replace it with…

There are lots more optimization I can do if my performance isn’t where I want it to be: Unroll my loops and get rid of Character lists altogether. But I’ll lose a lot of abstraction and flexibility so I’m not going to optimize anything more unless my beta testers complain!

 

 

Cocos2d Tip #2: Using CCTimer in Your iPhone Game

If you’re writing almost any type of game, from a puzzler to a FPS to an RTS, tracking time is critical element of the game play. (Except for Angry Birds. You can ponder an Angry Birds level until your iPhone battery runs dry without penalty.)

Cocos2d-iPhone provides several means for tracking time in your game and scheduling methods to be called at both regular heartbeats and at arbitrary points in the future. The easiest way to manage time in a Cocos2d-based game is to use a CCLayer’s scheduleUpdate or schedule methods. Both methods are explained nicely in the timers section of the Cococ2d Best Practices guide. The guide also explains why you should try to avoid using iOS’s NSTimer class. (Your game will miss out on automatic pause and resume if do use NSTimer.)

But what if you can’t use scheduleUpdate or schedule in your game because you’re putting your game logic into a custom class instead of a CCLayer or CCSprite?

For the sake of simplicity and portability I don’t subclass CCSprite in my games. Instead, I create custom classes to represent my game objects and call update:(ccTime)delta on them from CCLayer objects to make stuff happen. I needed a nice timer class and started to write my own. About halfway though this project I ran into Cocos2d’s CCTimer. Since I’m trying to write as little code as possible I abandoned my timer. CCTimer is a nicely written, lightweight timer class that uses NSInvoker to create callbacks and still integrates will with the rest of the Cocos2d-iPhone framework.

Here’s how it use it…

First, I store a reference to a timer in my non-Cocos2d class:

Second, I define a call back method to stop the timer:

Third, I define a method to start the timer:

Fourth, I add a call to update the timer in my CCLayer’s update method:

Finally, Somewhere deep in my game logic I start the timer at the right dramatic moment.

It’s important to note that at the time of this blogging, the CCTimer documentation claims the interval value used to determine the length is in seconds, but really it’s in milliseconds (that is 1/60 of a second). If want your timer’s call back to run in 2 minutes set the CCTimer interval to 160.0f.

It’s also important to note that CCTimer is independent of frame rate: This might be obvious but sometime you want to execute an action every frame an sometime you want to execute it every few milliseconds.

If things aren’t working make sure you’ve told your layer to schedule updates in it’s init method and make sure you are updating your timers from your layer 🙂

Objective-C Memory Management For Newbies

Below you will find a list of memory management rules that will make your Coco2d game coding experience easier and your games less buggy. But before you dive in please read the caveats below:

  • These rules are based on several sources written by engineers with much more experienced than me in Objective-C and Cocos2D development. Any mistakes are my own, any good idea belong to them.
  • My sources include this tutorial by Ray Wenderlich and the comments by fufie. Ray’s tutorials should be read by every aspiring Coco2d-iPhone developer!
  • I also found this Stack Overflow question and answer on property declarations and this blog post on properties by CocoaCast really helpful as well.
  • Of course all this info is contained in Apple’s Memory Management Programming Guide in greater detail. RTFM, as they cheerfully remind us in IRC, is a great way to learn.
  • In many ways this blog post is just a briefing on all of the above material and my motivation for posting this info is just to have it all in once place and neatly summarized.
  • Finally, these rules are guidelines for inexperienced developers, not laws. Engineers who are experienced with Objective-C memory management and Cocos2d don’t need these rules and shouldn’t even bother to waste their time and read my post. Following these rules will keep newbies out of trouble with their first game or two.

10 rules that make memory management a breeze…

Rule #1: Always create properties for your ivars in your .h and synthesize them in your .m.

Rule #2: Use an underscore so the compiler can distinguish an ivar from a property with a common root name. When synthesizing remember to associate the ivar with the property. This way the compiler will yell at you if you try to set an ivar as if it were a property.

Rule #3: Always access your internal properties through self using dot syntax to ensure proper memory management through property declarations.

Note: In C, C++, and Objective-C the operand on the left must be an lvalue so you can’t chain assignments. Code like

generates a compiler error.
Instead you have to unpack the object and assign it back to the property:

Rule #4: Always provide an object factory class method to create an instance of your custom objects using autorelease for simple memory management.

Rule #5. When declaring a property for a basic type or for objects you don’t own use the assign attribute.

Rule #6: When declaring a property for a subclass of NSObject use the retain attribute to retain the object on assignment and release the original object (if any) associated with the property.

Rule #7: When declaring a property for an NSString use the copy attribute to create a copy on assignment and release the original string (if any) associated with the property. You probably want the assigned string and the original string to be two independent objects.

Rule #8: Use the autorelease to automatically release objects when you are done with them.

Rule #9: Apple API calls that begin with “init” or “copy” need to be managed by you and released when you’re done with them. You can use rule #8 to make releasing objects at the end of a method painless.

Rule #10: Always use the nonatomic attribute when declaring properties unless you are working with multiple threads–and if you are working with multiple threads you are way above the level of these rules.

Rule #11: Always use the ivar in your delloc method to release objects you own and set them to nil (to ensure safe subclassing).

A thought on static analysis…

Xcode’s Build and Analyze (Shift-Cmd-A) always drives me crazy with false positives. First, it finds potential issues with the Cocos2D framework source files and I’m not about to worry about or fix any of those. Second, all the issues it finds in my source files are either trivial non-issues (an assignment hidden inside an if-then-else block) or not problems at all (releasing object that it thinks I don’t own). But perhaps it’s my coding style that needs to improve. I hate letting warnings go by unresolved and as soon as figure out a way to write code the makes static analysis happy I’ll let you know.

Cocos2d Tip #1: Changing a Sprite’s Image Simply

I’m writing an iPhone game using the Cocos2d-iPhone framework. It’s been smooth sailing except for one little detail: I want a sprite to change it’s image based on a touch.

I think the problem is that there are a dozen ways to do this in Cocos2d. I wanted to find the simplest way to do it. A quick Google search pointed me in the direction of CCAnimationCache and CCTextureCache.

CCAnimationCache is used for running multi-frame animations inside a single sprite. I only have 2 frames for my sprite! CCAnimationCache could do it but it’s a more power than I need to respond to a touch. (If you want to give animation a try check out Ray Wenderlich’s wonderful tutorial.)

CCTextureCache would have been the way to go if I hadn’t already used CCSpriteFrameCache to load all my sprite images at the start of my game. CCSpriteFrameCache uses a plist that divides up a large image into rectangle so you can pack all your sprite images into one memory saving “texture atlas.” And you can use Zwoptex to generate the image and the plist for you. CCTextureCache is the manual way to do what CCSpriteFrameCache and Zwoptex automates for you. (If you like to be hard core check out Ben’s post on optimizing texture loading.)

I figured there had to be a way to use my sprite frames in my existing cache without having to resort to manually loading textures or creating animations I didn’t need.

There was! It’s simple and here’s how to do it…

First, create your texture atlas with Zwoptex and add the .plist and .png files to your Resources folder in your Xcode project.

Second, load the texture atlas into the shared frame cache early in your game…

Third, create your sprite in your layer’s – init method…

Fourth, in your – ccTouchBegan or – ccTouchesBegan method add the following code to change the image associated with your sprite…

That was easy!

I Bought A New MacBook Pro and Didn’t Pay an Arm and Leg!

Apple had a sale over the Thanksgiving weekend. The savings we’re exactly in Crazy Edie territory but $101 off a new MacBook Pro just about covers the tax (in NJ). My last MBP has been sitting in pieces on the bookshelf behind my desk at home. I bought it in 2008 and two years of daily commuting between NJ and NYC literally shook it apart. I used Apple’s sale as the thin, poorly veiled, excuse to buy a new MBP. The truth is I’m just addicted to shiny new computers and I had to feed the monster.

When it comes to buying a computer I have three criteria:

  1. Don’t buy something that will become obsolete in a quarter.
  2. Don’t buy less or more power than I need.
  3. Pay as little as possible while still buying something that won’t embarrass me in front on the cool kids.

When I met my wife she explained to me that you can tell a lot about a person by their shoes. A cool hip guy might walk around in an outfit from Target but the brand of his shoes will tell you if he is being ironic or a showoff or a cheapskate. In the 21st century you can apply the same criteria to computer laptops. Some guys (or gals) buy the most expensive luxury desktop replacement money can buy as if to say: “I’m bad!” Other guys buy the cheapest under powered plastic toy “puter” that buy.com has on sale as to say: “I make Scrooge McDuck look like Bill Gates! (The current Bill Gates not the earlier one who acted a lot like Scrooge McDuck before he got married.) Then there are understated nerds like me who try to say something nuanced with their laptops: “Yes it’s not the fastest, but we know that RAM and HD speed are more important than raw CPU speed for real world applications.”

After much research and discussion with my hardware otakus this is what I bought and why:

I bought a 15″ MacBook Pro with a 2.40 GHz Intel i5 core CPU with 320 GB hard disk and 4 GB of RAM. This is the least expensive 15″ model Apple sells at $1799. I asked Apple for one extra: A higher resolution LCD display (1680 x 1050 instead of 1440 x 900) at only $100 more. With the Apple sale I got the hires screen for free but at only $100 for 30% more pixels it’s a bargain–one of the few true steals to be found in the Apple Store.

The display resolution is why I bought the 15″ and not the 13″. More pixels means less scrolling and more productivity. But I could have bought the 17″ MBP with a whopping 1920 x 1200 screen resolution. But I’ve used the 17″ model before and it’s not really portable. As a hard core northeastern corridor commuter I need something that fits into a standard backpack, weighs less then a 3KG medicine ball, and actually fits on my lap in the crowded train car.

Apple has options for much more powerful (i7 core) and faster (2.8 GHz) CPUs. But while benchmark software will show you a 25% to 30% performance boost between the 2.40 GHz i5 and the 2.80 GHz i7 pure CPU speed isn’t the problem unless you’ve unclogged all the other performance bottlenecks in your laptop.

The the real roadblocks to a laptop snappiness are memory and storage speed and size. Modern operating systems accommodate today’s bloated software applications by organizing memory usage into “pages” and swapping these pages in and out of disk as needed. Adobe Photoshop is the exemplar: It can’t let you edit that 21.1 megapixel image without shuffling pages of memory around. Some operations, like filters, are CPU intensive, but most operations (reading, writing, zooming, scrolling, copying, pasting, …) are memory bound.

To lessen the bound of memory I ordered a 4 GB ram stick and a 7200 RPM 500 GB hard disk from a third party: Not Apple! Apple charges extraordinarily high prices for RAM and hard disk upgrades. To buff up my MBP would have cost an additional $550. The third party RAM and HD only cost me $154.31 and 1/2 hour to unscrew the back of the MBP and install everything. In the end I had a sweet new MBP with 6 GB of RAM and 1/2 a terabyte of storage. Photoshop is happy.

There is a risk that by upgrading you’re Mac you’ll ruin it and void the warrantee to boot. I alway get help from my hardware friends who show me how. There are also some good videos from MacSales that we’re really helpful. The voiding of the warrantee went from a definite yes to a maybe in the last few years. Apple reserves the right to blame your MacBook problems on you if you don’t use an authorized service provider.

For me, it was worth the Geek Cred to personally upgrade my MBP so I could have a great ice breaker at Starbucks:

“Oh, this that new MBP you got there?”

“Yes, but I haved $400 bucks by upgrading it myself and I got the hires screen for free on Black Friday.”

“OMG! 2G2BT! CSA!”

The Three Laws of Agile Process

As early as 2007 Agile practitioners, or at least people who blog about Agile, began to observe that we live in a post-agile world. I’m not sure what means but Agile is a conversation about the best way to manage the software development process that has been going on for a long time. Has it been too long? What comes after Agile?

Eventually all wisdom becomes dogma.  Many engineers feel strongly that we’re already there with the process for process’ sake when the scrum master moves into the cubicle next door. Fair or unfair it’s a criticism needs to be explored. However nobody has put forth a process to succeed Agile–one that builds upon it’s strengths and shores up it’s weaknesses. At this point in the history of software development were we to abandon Agile we might as well go to ouija boards and seances to plan our projects.

So in truth, we make it up as we go along. That’s what most experienced scrum masters mean when they say they are flexible about adapting the processes of Agile to the culture and business needs of an organization. Poor Agile implementations are only a few second-guesses away from good ones.

Perhaps it’s time to take what we’ve learned in the 10 years since the framers of the Agile Manifesto met in Snowbird and create something that fits even better with the technological and business climate of the Mobile-Cloud-Long Tail-Social-Search Driven-Virtual world we log into every morning.

I’d like to start with the very first value of the Agile Manifesto:

Individuals and interactions over processes and tools

Do we still value people over process? Is it that simple? From this value the principles of customer satisfaction, working with business people, building projects around motivated individuals, face-to-face conversation, sustainable development, and team reflection are derived. Change this value and we change the equation for all of Agile. Do we weaken it? strengthen it? or replace it with something else?

Even with the unique challenges of developing software for servers you can’t touch and cell phones with fingerprints all over them we know what true process-for-process’ sake is like. We call that Waterfall but it was many more manifestations. It’s the paperwork you fill out in the emergency room and the electronic EULA you click “agree to” without ever reading.

So we have to keep it. In fact I would argue we have to make it much more imperative: A rule that is never broken which says it’s OK to break the rules!

I don’t mean we should give up our process at the drop of a hat (or the crash of a market). But we must give it up when our people will be rendered ineffectual. Issac Asimov’s Three Laws of Robotics can inspire us with a new rendering of what is, perhaps, the most important value of Agile:

  1. A process may not injure a team or, through inaction, allow a team to come to harm.
  2. A process must obey any orders given to it by a team, except where such orders would conflict with the First Law.
  3. A process must protect its own existence as long as such protection does not conflict with the First or Second Law.

If it will keep our robot overlords from killing us it will work for keeping an overzealous Agile process in check!

Turning Bold into Strong with Regex & NotePad++

I’ve been hand coding a site and I was a little lazy. Instead in using the strong tag to make text look bold I used the bold tag.

Ok, that might not be a big deal to you but to some HTML fanatics the difference between <b>Hi There</b> and <strong>Hi There</strong> is ground for excommunication from the cool kids club. Being lazing I figured the difference was not important enough to warrant me typing an extra 10 characters for each tag. But in the middle of the project I saw the light. (Modern browsers, text readers, and future things we have not invented yet will “do the right thing” with strong tags. Bold tags are just fossilized formatting.)

So now I had a bigger problem: How do I turn all those <b>’s and </b>’s into <strong>’s and </strong>’s? Of course regular expressions would work–if I could figure out the syntax. I mean, it’s been a long time and I always found regex to be the classical Latin of the programming world. Boring but important 🙂

To complicate things I am using NotePad++ to edit my hand hold HTML. NotePad++ is a great editor (and it’s free) but often does things it’s own way. It’s the Frank Sinatra of Window’s text editors.

To refresh my memory of regex syntax I found a great site, RegExr, that let’s you experiment with regular expressions until you beat them into submission. It’s written in Flex 3 and is a fine example of both a programmer’s tool and an Adobe rich media application.

After a bit of fooling around I discovered the pattern to capture a string inside a bold tag…

and to replacement was

This magic would not work if the bold tags had any attributes but I would have used an actual CSS style if I needed any more complexity than bold text.

Anyway this didn’t quite work with NotePad++. A little more digging (via Google and Stack Overflow not the NotePad++ help system) and I discovered that NotePad++ doesn’t need the regex switches and uses / instead of $ for captures. The working search and replace strings are…

Yey! Now I can continue to be lazy and fix it later!

Android SDK Compatibility with Eclipse and JDK

I recently switched my development workstation from a MacBook Pro to a Windows desktop PC. Yeah, I know, I’m going against the trends but it’s a sweet machine I assembled myself based on recommendations from Ash.

Immediately I ran into compatibility problems with Google’s Android SDK and the current versions of Eclipse (Helios) and the Java Developer Kit (JDK Version 6). In a nutshell Google’s cool Android dev tools don’t work with Helios–you need to install Eclipse 3.5 (Galileo). Galileo require’s JDK Version 5. All this info is prominently featured on the Android system reqs page–but who reads any more?

Digging up old versions of Eclipse is easy. You can find Galileo here.

Digging up old versions of the JDK is a bureaucratic nightmare. You can find JDK Version 5 here but to install it you have to fill out a form, give away PII, and then wait for an email.

One way around Sun Oracle’s walled garden is to install Open Office 3.2.1 which installs Java 1.6 (JDK Version 6) in such away that everything compiles.

Now that Google is throwing away all their Windows PC’s I’m sure this compatibility nonsense will get even worse. Here is a note from Google about enabling debugging of Android Phones:

If you develop on Mac OS X or Linux, you do not need a special driver to debug your application on an Android-powered device.

Damn it! I might have to go back to coding on the Mac and only using my PC for trival tasks like gaming and web browsing. Ironic huh?

Communication Flavors

Found a Bug

It’s not even funny how human networks and computer networks exhibit the same behaviors. I know we’re all patiently waiting for the singularity, for the event where computer networks become sentient and life as we know it changes forever. But given how the current example of networked sentient beings behave I fear that switching platforms (from organic to silicon) won’t improve anything. Collaborators will still compete, confuse, and confound each other, just at faster bit rates.

Dynamic network communication behavior is important to help us understand the 6th principle of the Agile Manifesto:

The most efficient and effective method of conveying information to and within a development team is face-to-face conversation.

At first glance the idea that F2F (face-to-face a type of peer-to-peer) communication is the most efficient and effective method of communication is non-obvious. After all, if I want to tell something to many people a broadcast is much quicker than a pointcast. Implicit in the idea of F2F communication is talking. (I doubt the framers of the Agile Principles want us to pass notes to each other.)

It’s not immediately clear that talking (realtime streaming) it is much more effective than detailed written instructions (store and forward). F2F communication means lots of clarifications, and repetitions when words and whole sentences can be lost due to network noise or an inattentive client.

The problem is that we are comparing F2F and written instructions in terms of abstract efficiency outside of the time-bound world we live in. This is a common error. We tend to think of our priorities and tasks as critters that live in independent time-space bubbles. Thus we don’t take into account logistics, dependencies, and elapsed time when estimating how effective or efficient a flavor of communication is.

There are not 24 hours in a work day. Really there are 4. The other 20 are taken up with sleeping, eating, commuting, and status meetings. That leaves 4 uninterrupted hours for work. Imagine if you baked this idea into your communications habit. You don’t have the time waste on writing or reading long, detailed emails and wiki posts. You need a communication strategy where you can cut to the important stuff. That means finding the right co-worker (peer) and talking to them directly.

A true co-worker is someone who knows you’re strengths and weaknesses, knows when you are joking, respects you, and doesn’t want to you see fail. Unfortunately, even if you have super social skills, you can only manage 5-7 relationships like those at a time, and most of these are with your family members. Most of the people you are working with either just don’t know you very well to be able to parse your text get the message without errors. You can’t simply write a detailed enough specification or requirements document to get though the noise.

Given the shortage of time and deep relationships you have to talk to co-workers F2F. You have to interrupt and be interrupted. What seems like a slow process, like a four hour F2F planning meeting, is actually much more efficient than a  100 page document.