Mar
11
2009

FYP Technology: Ok, C… you win this time.

Until now I had avoided globals in my code, which I think is a good idea in general, but when I realised how many times so many of my classes were being access through their singleton accessors, I decided enough is enough and a few regex find and replaces later my code is set up with globals instead.

I don’t know why I didn’t have the confidence to do it before, now that I look at it. I should be saving a hundred or two calls every frame, or maybe about 10,000 every second!

Goodbye, YkdGraphicsSubsystem::getSingletonPtr(), hello gGraphicsSubsystem!!


Yesterday I was having trouble with the iPod accelerometer’s response time on the PC. I found it laggy to the point that it wasn’t really usable, and then realised that since I got rid of any threading on the iPod side, the whole thing blocks while it receives the image to display on the screen (about 50kb per image).

I came up with a way of having one thread receive the image, then set a flag for the main thread to check periodically in its main loop (with an NSTimer), and then receive the next image once the flag was reset by the main thread (indicating it had been consumed and put on the screen).

Before I started hacking into that, it occurred to me that I was sending a UDP datagram to the iPod telling it that an image was on the way first, and then transmitting the image over a TCP stream. I realised how silly that was, swapped the ordering so the datagram came after the image data stream had been written to the TCP socket, and in its new role as indicating that an image had been sent (as opposed to indicating one was about to be sent), the lag disappeared! Turns out that once the data is ready to be retrieved right away, the blocking recv() call in the main thread isn’t anything to be worried about! Hurrah!

Written by ダニエル氏 in: University |

No Comments »

RSS feed for comments on this post. TrackBack URL


Leave a Reply

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