Jan
24
2009
2

FYP Technology: Identity/Multithreaded Network IO/more iPhone SDK

I finally decided on a name for the software I’m developing for my FYP, and it’s Yakumo. Sounds cute, silly and abstract… perfect for a modern technology.

One of my most admired authors is Patrick Lafcadio Hearn, a man born in 1850 to an Irishman and Greek woman, and who spent much of his life in one of the most exciting eras of Japanese history, writing passionately all the while about his experiences of Japanese society. He married a Samurai’s daughter, Setsu Koizumi, and changed his name to Yakumo Koizumi when he received his naturalised citizenship. It literally means “Eight Clouds” and is also the name of a couple of small villages in Japan.

Yakumo iconThe temporary icon that I threw together today is the top two thirds of a white “8″ on a deep blue background. You should be able to see it beside this paragraph. This is the auto-prettified version that the SDK kindly fixed up for me. The gloss and rounded corners are not my own doing. I don’t think I’ll take advantage of this functionality in the end, as lots of apps use it and I think it might stand out a little more if I make it a bit different.

Yesterday I was a bit worried about the lag I was seeing on the input from the iPod but I set up some basic multithreading today and the lag is no longer very noticeable. Unfortunately, it’s not quite jerky. It feels like it’s only getting updated four times a second instead of sixty. I have the problem narrowed down to two possible locations anyway (either side of the communication between the the local socket and game input on the PC).

I spent a bit more time today with UIKit, the iPhone/iPod’s UI library. Apart from the apparent but in UIViewController’s hidesBottomBarWhenPushed method, it’s been an entirely pleasant and encouraging experience! Coming from the world of PHP, of course I’m going to find documentation lacking, but that’s made up for by the intuitiveness of the various frameworks available and, of course, the named parameter lists. Hate to keep picking on the fat, unpopular, oh-so-easy-to-bully kid, but when I start a thread on Windows, 4 of the 6 parameters I enter are 0 or NULL.

Also, a gripe with C++ that the dynamicness (is that a work?) of Objective-C has amplified: I can’t define the entry-point of the thread to be a non-static class member. Why this is is obvious to anyone who knows their C++, and they might sent a superior snort my way for complaining about it… but I do understand the benefits of such a static environment, and my frustration isn’t from a lack of understanding or familiarity with C++, it’s from seeing how easy it is when I can just say @selector(threadEntryPoint). Here’s my compromise:

  • Since we’re going static, and then calling an instance member from there, create a ThreadPayload struct to contain both pointers:
    struct ThreadPayload {
    	YkRemote* self;
    	AccelerationData **accel;
    };
  • Change the call to dynamically allocate and popular the struct. (Anyone know how to initialise a dynamically allocated struct immediately? i.e., dynamic equivalent of struct myStruct s = { 1, 2, 3 } syntax)
    	struct ThreadPayload *payload = new struct ThreadPayload;
    	payload->self =  this;
    	payload->accel = accel;
    	CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) YkRemote::startThread, payload, 0, NULL);
  • Set up a static entry-point which calls the instance’s non-static member, then frees the memory when it’s no longer needed:
    DWORD YkRemote::startThread (void *payload)
    {
    	struct ThreadPayload *p = (struct ThreadPayload*)payload;
    	((YkRemote*)(p->self))->threadLoop(p->accel);
    	delete p;
    	return TRUE;
    }

Update: Boost threads/bind to the rescue! I replaced all the code above with this:

boost::thread newThread(boost::bind(boost::mem_fn(&YkRemote::threadLoop), this, accel));
2 comments »
Written by in: University |

Powered by WordPress | Theme: Aeros 2.0 by TheBuckmaker.com