Saturday, May 23, 2009

random() on the iphone SDK giving same values

I obviously had changed the random seed with srand(time(NULL)) however when generating 4 random numbers they were always the same although always different with each run. I thought I was going insane as when I tried debugging it step by step the numbers generated were different.

After googling a bit I found that it is better to use arc4random(). That fixed it.

Breakpoints stopped working in XCode

Suddenl, the breakpoints stopped working. Usually I just clean all targets and empty XCode's cache. But this time that trick didn't work. Then I found this solution, to disable Load Symbols Lazily from XCode Preferences->Debugging. That worked like a charm.

Wednesday, May 20, 2009

Got my Apple Developer Program Activation Code

Yippeee! Finally after 3 weeks!

This morning I sent Apple an email telling them that this sending of the activation code was agrivating. I told them that I bought a macbook, switched from windows, bought an ipod touch, but I'm still waiting for the activation code. Later this afternoon I just received the activation code.

Setting up the device was quite straightforward. They provide a very helpful wizard-like experience. But then I got a CodeSign error when I tried Build&Go. I discovered that the Code Signing properties in the project were not set. I just had to select the developer provisioning certificate and presto... I was debugging my buggy prototype on my iPod touch :D

Monday, May 18, 2009

Got my cracked iPod touch

Have been busy preparing for a web development course I'm giving right now.
I've also been busy with making my time logging web app compatible with iphone. I will soon publish it on apple's webapp listings. 

I've got my iPod touch... ok it's cracked, but I will replace the glass later.
It's a pretty cool device, very addictive actually.

I'm still trying to get the fax through the apple developer program...

Saturday, May 09, 2009

iPhone-izing a webapp

I need a break from Objective-C :) after fixing some glitches in the collision detection. I'm still waiting for my iPod-touch and yesterday I resent the fax to enroll to the apple developer program. Hope this time they received it fine.

So I'm currently tempted to convert my mini time management webapp to be iPhone-friendly. My eclipse/rad rails setup is still on my windows machine, so I needed a quick way how to test the changes on a simulated iphone. I found this quick iphone Windows simulator that uses Safari for Windows 3.2 underneath (webkit). It's not perfect, but it does the job for now.

I need the CSS styles and images used to make the iphone native apps look and feel. And in fact there is this iui open source project which gives you the necessary CSS and samples to get you started quickly.

Will see how it goes... the samples provided seem to be exactly what I need!

Wednesday, May 06, 2009

Windows 7 RC on my Macbook

I downloaded the Windows 7 RC which should be fully working until March 2010, after which they said it will start to shutdown every 2hrs.

I found a how-to run Windows 7 RC on a Mac using VMWare but first I downloaded the Windows 7 RC from Microsoft. Just need a Live account.

Ok, why VMWare and not bootcamp? I don't want to depend on Windows. I just want it to be able to run something quickly on Windows without having to reboot. I only plan to do this until I phase out Windows from my life, if I ever manage. I don't want to be switching between computers/OSes. I'm already frying my brain with switching between shortcuts and swapped positions of the minimize/maximize/close buttons.

The installation was a breeze, although it took some time to finish, but maybe because I only have 1gig on my macbook. It's a pain running a win7 with just 512megs reserved for it, when the recommended amount is 1gig! My macbook came to a crawl haha. First time I saw my macbook on its knees. I will be upgrading its RAM this summer. So I will retry running it then. For now I suggest that if you have just 1gig in your macbook, give up and don't waste your time.

Final note, I have an original Windows Vista, and I never got myself to install it. It's crap. I have worked with it for a year where I used to work, 8+ hours a day and it was a nightmare. I think Vista should have remained a beta. But Windows 7 looks promising. Personally I prefer the new Windows taskbar than the Mac's dock.

Tuesday, May 05, 2009

Fast flood fill implementation

I'm keeping an array of bytes (unsigned char) to keep some collision map. I could probably later on improve on it to make it use a bit for each pixel, but for now I'm going to keep it simple.

At first I was going to create a gray scale CGBitmapContext to store the data, but I wasn't going to actually draw it. Just wanted a collision map to be used underneath so I opted for a simple array.

Of course this meant that I needed some Bresenham line algorithm implementation and also a quick floodfill for the game prototype I'm doing. For the floodfill I first did a naive recursive version of it, but that can easily give you a stack overflow. So I did some searches on faster implementations. I found a couple. The QuickFill algorithm seemed a bit overkill to convert it to Objective-C (and looked complicated as well). Remember I'm still prototyping, so it's not the right time for a lot of optimizations. I settled for the implementation found at codecodex which seems to be a compromise between recursive and iterative approach. Seems to do the job for now. Not the fastest, but better than the pure recursive version.

Need to fix some collision detection problems next, and also double check the line algorithm, since I think it's not behaving right at the edges right now.

Monday, May 04, 2009

Mac - I'm Lovin' it


It's been slightly over a month with my second hand MacBook. I'm simply lovin' it. I'm still migrating from windows. I'm only using my windows machine through remote desktop. In fact I unplugged the monitor, keyboard and mouse and hooked them to the laptop :)

Still getting used to XCode, Objective-C and OpenGl but it's fun.

The MacBook came pre-installed with MS Office 2008, but I wasn't impressed with it. I must admit that MS Office is better on the Windows platform, more responsive.

The other complaint I got is when minimizing a window, won't get restored when you switch back to the application. It makes sense when you think that the Macs are application oriented and not window oriented, but still is frustrating having to get hold of the mouse to go over the dock and restore it. The work around using Command-H to hide the window instead.

But besides these minor details, I still think that a mac is better than windows. We'll see how I'll feel in a couple of months down the line.

Saturday, May 02, 2009

Be careful of constructor helper methods

I forgot that constructor helper methods (e.g. +arrayWithCapacity) would make the array autoreleased leading to an EXC_BAD_ACCESS. Still getting used to the reference counting mechanism and conventions :).

I was using such a method for an instance variable. The solution was either to retain it or to use the alloc method, which gives you an object with a retain count of 1.

_replayLines = [[NSMutableArray alloc] initWithCapacity:5];

iPod Touch soon on its way

I have bought a non-badly cracked iPod touch 8gig 2nd generation on ebay - want to keep expenses as low as possible. However since the guy had several of them, he shipped the wrong one. The screen is badly cracked. Will have to replace the glass later.

Can't wait to be able to test on the device directly! Just have to wait for the iPod touch to arrive in Malta from the US, since I had to ship it by proxy to a friend of mine who lives there. Here's a photo he took for me to show me what he called "almost artistic" cracks.

Making reproducible bugs

I got some bugs lurking around related with collision detection. So the first rule when debugging is to make the bugs reproducible. I'm currently trying to record the user interactions and frame number at which they occurred, into an NSMutableArray, and then dumping it to NSDefaults when exiting the application (should be enough for now). Then I will load them back up when the application is relaunched. At the frame number at which the user interactions (basically lines) were originally made, I recreate the lines. Also I had to remove any randomness if I want that each time I play the recorded actions, I get the same outcomes (i.e. bugs). So the ball(s) will always start from the same position.

Will try to finish this interactions playback later on. Have to prepare for next week's lectures.