Archive for March, 2009

Why do I have to fill out the exact the form…

Sunday, March 15th, 2009

This is the 21st century. Virtually everybody has some sort of computrized database for storing contact or other meta-personal information and yet anytime I change my address (e.g. physical, e-mail, IM, phone number, etc.) or some other piece of information (e.g. credit card, insurance carrier, etc.) I have to send out  e-mails, make phone calls, fill out a change of address form at the post office, call creditors and banks, inform family and friends, or something equally painful and mind-numbing about a few dozen times. This is bizzare.

It would be much better if we had something like a DNS system, but for people instead of IP addresses. This type of system can work transparently on top of already existing systems. I haven’t really hashed out all the details of this but it would work something like this:

You give whoever you want to be able to contact you or know some information about you some identifier. They then use this identifier for everything related to you. So when they want to write you an e-mail they put in this identifier and their e-mail client requests your e-mail address from the system given that identifier and then sends the e-mail to that address. If you change your address at a later time, then the next time that identifier is used it will automatically follow you. The same goes for phone systems, chat systems, physical addresses etc.

Although it would make usability a bit clumsy a security layer could be added using public-key cryptography. So when you give out your identifier they also give out theirs. Then you log-in to a central system and authorize their identifier for only certain parts of your data, or perhaps slightly different data than you give out to others (e.g. you authorize a shady site for the e-mail address myspam@mydomain.com instead of myemailaddress@mydomain.com that everyone else gets). That way you can only give out the information you want to give out. Then at any time you can change or update your information and authorize/deauthorize keys to access that information.

Essentially this kind of system would remove the need for filling out multiple change of information forms and making multiple calls, e-mails, IMs, etc. You would just go into the system, update your info, and it would get propogated out the next time it is requested. No more change of address forms, everything just follows you if you want it to, and stops when you don’t.

Radial Breakout Woes

Sunday, March 15th, 2009

For a project in CS U540 I had to create an interactive 2D program that supported a few linear transformation (e.g. scaling, rotation, reflection, etc.). I decided to make a break out type game. However, I didn’t want to create a normal break out clone as that seemed a little boring. In hindsight I should have. Getting the physics right on this game has proven to be quite a challenge. Moreover, I shouldn’t have chosen Java as the language to write it in. I still can’t figure out a way to keep the mouse pointer inside the game window while the game has focus and keeping it cross platform. Below is a screenshot of the game in an early stage:

Radial Breakout Screenshot

Radial Breakout Screenshot

Basically I now have several issues:

  • The game is a CPU hog. Coding it to use Windows messages will limit it to running on Windows only. Using a Java timer for updates will mess around with the fluidity and essentially keep it being a CPU hog, just one that hogs slightly less often.
  • The only way I have found to get the mouse to stay within the game window is to use the Robot class. This unfortunately would fail if I wanted to distribute the game using applets or Java Web Start.
  • The hit detection for the paddles isn’t quite where I want it to be.
  • The ball movement isn’t quite right either. This stems from the rather messed up deflection algorithm I am using:
    • If the ball hits a paddle. Determine the intersection of the ball’s current vector with the tangent line crossing the apex of the paddle. Determine the angle between the normal of the ball’s velocity vector and the intersection. Rotate the ball’s movement vector by this angle. (Currently this is not only slow, but buggy)
    • If the ball hits a paddle and after rotation it is still going out of bounds reflect the ball back in bounds. (This should never have to be done.
    • If the ball hits a brick swap the movement vectors. Essentially reflecting the ball 90 degrees.
  • The ball ends up moving so fast that it becomes very difficult to play.
  • If I stuck with my original intention of having the bricks damage, stun, or anything else detrimental to the paddles the game wouldn’t be very fun or playable.

So I’m not really sure what I’m going to do now. I’m thinking of scrapping the project all together as far as its Java implementation goes and starting it back up in C#/XNA. I think having two joysticks to control the paddle(s) rather than a mouse and key modifiers will feel much more natural. Plus it will give me some nice experience with XNA.

For those interested. The Functional Specification and Game Files for the first build of Radial Breakout are available. The jar inside the game files archive is executable and all source code as well as a manual is there as well.

Internet Explorer, Tables, the DOM, and what not to do…

Saturday, March 14th, 2009

A post on reddit a few weeks ago finally inticed me enough to sign up for an account on the popular social link sharing site. The post was at a blog by Eric Vasilik (who supposedly had something to do with making IE a horrible platform to develop for) that dealt with having to insert the new rows into an existing table. Intuitively, most coders would just use the .innerHTML property and go about their day until they later test their code in IE and then everything explodes because IE doesn’t play nice when it comes to tables and .innerHTML. Especially when inserting new rows. What really irked me about the whole thing though was the way Mr. Vasilik was going about solving his problem.

For reasons beyond me Mr. Vasilik decided that it would be best to not just use the DOM methods and insert rows in that manner. Instead Eric wrapped his newly created HTML for table rows inside of <table> and <tbody> tags, put them into a hidden element on the page, and then looped over rows in the currently visible table calling the replaceChild method on the table in order to swap out the rows. This solution does, in fact swap out all of the rows. Unfortunately it is painfully slow.  Having to use the DOM alone for this is already significantly slower than using innerHTML (but IE makes this impossible, at least for versions 7 and lower) but using both innerHTML and the DOM is even slower than that. Instead of creating the table rows as strings Mr. Vasilik should have JSON encoded the tables so that he would’ve had them as objects after a quick eval or if he had to create them in the code then he should’ve used the DOM to create the objects and used insertRow, insertCell, etc. on the table object instead of using the least efficient approach he could think of.

I ended up writing a few speed tests to test innerHTML, DOM, DOM/appendChild, and DOM/innerHTML/replaceChild which can be found here (needs Firebug to run).  Not surprisingly, using innerHTML to create a new table, then calling replaceChild to swap table rows was the slowest of the tests. Full code below:

(function()

{

var table = document.getElementById(‘test’);

var tr, td;
<pre id="line1">  console.time("DOM Manipulation");
  for(var i = 0; i &lt; 1000; i++)
  {
      tr = table.insertRow(-1);
      td = tr.insertCell(-1);
      td.innerHTML = "Test";
  }
  console.timeEnd("DOM Manipulation");
  table.innerHTML = "";
  console.time("innerHTML");
  var rows = "";
  for(var i = 0; i &lt; 1000; i++)
  {
     rows += "&lt;tr&gt;&lt;td&gt;test&lt;/td&gt;&lt;/tr&gt;";
  }
  table.innerHTML = rows;
  console.timeEnd("innerHTML");
  table.innerHTML = "";
  console.time("DOM, appendChild");
  for(var i = 0; i &lt; 1000; i++)
  {
    tr = document.createElement("TR");
    td = document.createElement("TD");
    td.innerHTML = "Test";
    tr.appendChild(td);
    table.appendChild(tr);
  }

  console.timeEnd("DOM, appendChild");
  rows = "&lt;table id=’test2′&gt;";
  console.time("DOM, span, replaceChild");
  for(var i = 0; i &lt; 1000; i++)
  {
    rows += "&lt;tr&gt;&lt;td&gt;test DOM, span, replaceChild&lt;/td&gt;&lt;/tr&gt;";
  }
  rows += "&lt;/table&gt;";

  var spanTemp = document.getElementById("temp");
  spanTemp.innerHTML = rows;
  var varTempTableRows = spanTemp.getElementsByTagName("table")[0].getElementsByTagName("TR");
  for(var i = 0; i &lt; varTempTableRows.length; i++)
  {
     table.replaceChild(varTempTableRows[i], table.childNodes[i]);
  }
  console.timeEnd("DOM, span, replaceChild");
})();

UPDATE: Seems like this completely changed in FF3.5 and using innerHTML is significantly faster than any of the previous methods.