Friday, July 30, 2010

Blocks in Objective C (Update)

Soo as it turns out! The blocks, only work with the arm compiler! Which means you can't even compile the code for your simulator unless you get a 3rd party non-apple GCC compiler. So I think everyone would agree only two words come to mind when updating to a third party compiler.. "F**K THAT!"

On the bright side, I found that there is a foreach loop! Go figure its a mix of C# and Java.

So in java its:
for ( Object obj : objectList) {
doStuff(obj);
}

in C# its:
foreach ( Object obj in objectList) {
doStuff(obj);
}

in Objective-C its:
for( Object obj in objectList ) {
[obj doStuff];
}

Way to fail apple.. way to fail.

Monday, July 19, 2010

iPhone Dev

It's been a while since I wrote anything, so I feel compelled to write a little after reading my friend's blog. I'm not as eloquent as other people, but its fun to try :)

So lately I've been working with the iPhone SDK pretty exclusively when it comes to at home programming. I've found a lot of interesting classes, and I've ever so slowly been re-creating my XNA font engine and refactoring all my code to be nice and neat. When I first started with objective-c it was a nightmare. Everything is so different and ugly, but slowly I'm getting used to it. I already found delegates and function pointer equivalents which is great cuz it really makes some patterns much easier to implement.

None the less, development goes slowly, I worked out a pretty functional level generating algorithm which is great because its a step closer to the end goal. I let some people try my game at dinner today but they all agreed "A game you can't lose at isn't all that fun". So I'm starting to reconsider the whole "Never die" mentality I was going to go with for this game. Perhaps some burning lava pits and sharks are in order... Everyone loves sharks... or pandas... hmm. Something to think about =)

In the mean time, lets talk a little bit about those Objective-C function pointers. They are called Blocks. In the example below I will do Strategy Pattern using a function pointer block. Blocks are sadly are extremely over complicated (as is everything in Objective-C), so to make life easier it's recommended to use typedefs:

typedef void(^BasicBlock)(id);
Breaking down that syntax:

typdef --ReturnType--(^--BlockName--)(--Params--);

Then where you want to use your method you do something like:

-(void) Iterate:(BasicBlock) theStratYouWishToUse;

Then in the definition we need to actually do something with that function like call it:


-(void) Iterate:(BasicBlock) theStratYouWishToUse 
{
NSEnumerator * enumerator = [ spriteList objectEnumerator ];
id obj;

while ( obj = [enumerator nextObject] )
{
theStratYouWishToUse(obj);
}

}



So that takes care of defining it, and calling it, but how do we create the block to pass it into our object? Remember, we have to worry about garabage collection and all that good jazz, but Apple's SDK has some stuff for that =)

BasicBlock myBlock = [[^ (id obj)
{
[obj doSomethingAwesome];

} copy] autorelease];


The copy and autorelease are methods that apple added, onto the block, the block syntax is:
BlockType blockObjectName = [[^--paramList-- { ...do stuff... } copy] autorelease];

After that, you just pass ur block around like it was an object:

[SpriteList Iterate: blockObjectName ];

Thats basically it, if you had a return type, you'd just return it at the end of ur method, and you're all set =)

Anyway, there's my tech for the day, hopefully that helps someone out there one day =)

Tuesday, June 22, 2010

VP8, H.264

So after reading


I've come to the conclusion that VP8, isn't all that and the bag of chips that Google seems to make it out to be. I compiled the SDK and tried using it, but no matter what I do, I can't get past the extremely annoying Quality Popping that the author talks about. I noticed it immediately, and it wasn't until reading his analysis that I realized what he's talking about.

From a patent free point of view... The author seems to know a lot about the h.264 codec and seems to be quite capable of code analysis, from his observations, he seems to feel that VP8 is very similar to h.264 from a conceptual point of view, minus the fact that they took out the features that make h.264 so good. This makes me feel like the only way that google can improve the quality is to be more like h.264 which suggests that it will be closer to patent infringement! But if they leave it as is, its just not good enough, and STILL likely to get sued for patent infringement!

Soo I think Theora is still a good alternative... It sucks SOO bad that no one will even care to sue it even if it does mildly infringe patents, and it at very least doesn't suffer from that incredibly annoying quality popping artifact!

In short... I almost feel like Google is using VP8 to incite a patent war and possibly get the news out there that software patents are evil. Maybe VP8 can be a weapon to help bring down the endless struggle between developer and patent lawyer and patent land mines. If we destory software patents, h.264 becomes what it should be.. free for anyone to implement their own way. The idea that the IDEA of a good video encoder/decoder is something someone can be sued for even if they coded it themselves in a dark room w/ no internet and no other references... Its just stupid. Now if someone took the code and copied it exactly... ya.. they should get sued ( thats copyright ).