Tag Archive for 'ethernet'

Parenthesis, how I hate thine treacherous ways

I’ve been struggling with a programming problem for last few days, and today I found out that it was caused by a pair of insidious parenthesis.

What I was doing was changing my code to use fixed point for the position and speed of the ball. The problem I was having is that the speed was being rounded down to zero. So when I had 64 (or anything else under 256) and bit-shifted it to the right, it came out zero. I asked on the PAlib forums and a guy directed me to a website explaining how fixed point math works. As it turns out, my problem was not a glitch or bug, that’s just how fixed point works. And after some thought, I realized that my number would either it round down to zero or up to one, and never get the answer I wanted.

So I was stuck. I needed a speed of 1/4th pixels per frame, and didn’t want to use floating point (decimals). But then as I was screwing around with another test project, I noticed that it was working exactly as I wanted it to! I looked at the code and at first didn’t notice anything different… then of course I saw the parenthesis and probably uttered a swear word.

It make sense, now that I see it. I had been bit-shifting the speed before multiplying it with the result of PA_Cos and Sin — the correct method was to multiply them and then bit-shift the whole thing.

The working code…
ball.x += PA_Cos(ball.angle) * ball.speed>>8;
ball.y -= PA_Sin(ball.angle) * ball.speed>>8;

…and the non-working code.
ball.x += PA_Cos(ball.angle) * (ball.speed>>8);
ball.y -= PA_Sin(ball.angle) * (ball.speed>>8);

And now for some stuff about my awesome, totally interesting life.

I, with a great deal of help from my dad, finished threading an Ethernet cable through 60 feet of pipe. Much more difficult then it sounds. Then, inside, I ran the cable up the wall, across the ceiling, into my room… and immediately ran out of cable. DAMMIT. So today, I’m going to have to pick up another cable as well as an RJ45 coupler. Unfortunately I live in a teeny-tiny town with no large tech stores. We have one small computer repair shop that sells some stuff, so they might have some cables… but an RJ45 coupler? Considering even I didn’t know they existed before today, I’m going to guess no. But I’m hoping they do, because I don’t want to wait a week for shipping by buying it online.

I’ve been playing StarCraft a lot recently. I’m still quite crappy, but getting better. At least I can survive a zealot rush. I remember a time when I’d get attacked by ten or so zealots and all I’d have is 6 ‘lings. Now I have at least 12 ‘lings, a couple hydras and a sunken.

But I still get killed by human players. Like today, this guy massed marines — he must of had at least 40 or 50 by the end, with a few tanks thrown in for kicks. I was slaughtered. I asked him what he thought I did wrong, and he suggested that I memorize a few build orders, which I think I shall go do right now.

Oh, and one last thing: I mentioned that I was going to watch Castle a few weeks ago? Never did, because *gasp* our TV no longer received anything because we’d never gotten a digital converter box. Just yesterday I went to wal-mart to get one, but they were out. It sounded like they’d been out for a while, and probably would be out until the end of time. If they don’t have ‘em back in stock before Friday, I’ll get one when I go to Spokane.

Color gels and pipe

Two interesting things happened today:

Firstly, my color gels arrived. I was a bit surprised at first, because the word “gel” made me think that they’d be… more gel-ish. But when I opened the box, I was what confronted with what looked like colored paper! And then I realized that was part of the packaging. Oops. So then I took the paper off and found that the color gels were, in fact, more like color cellophane. Well, not quite as thin as cellophane, but close. But what’s important is that they work — I tested them all out, and decided that they were everything I needed. However, one thing that I’ve put on my to-do list is building a set of frames to hold the gels, and facilitate easier mounting on the light.

Secondly, I finished digging a hundred-foot pipe out from where it was stuck underneath five feet of snow. I’ve been working at it for about a month, off and on, so it gives me a warm and fuzzy feeling to know that I finally defeated a length of inanimate plastic. Er. Anyways…

The pipe is what I’m going to put an Ethernet cable through, so I can finally get internet to my room. In case you’re kinda scratching your head over that, suffice it to say that we’ve got a rather weird differentially normal housing arrangement.