~Revo Fora~

Life, School, Programming, and Whatever Random Thoughts Cross My Mind…

Fixing Frequent Crashes in Railroads (and other poorly memory managed games)

Sid Meier’s Railroads crashes on Windows Vista/7 fairly frequently. This turns out to be due to the fact that Railroads and many other games targeted to XP share a 2GB RAM portion with the OS (simplified description but good enough). In other words Railroads gets 2 minus the amount Windows is using as RAM. This doesn’t leave much RAM available and the higher detail you’re playing the game in the quicker that RAM gets used up causing the game to crash.

There is an updated patch available that seems might fix the issue but I’m unaware how to get the patch installer to recognize my Steam installed copy.

So as an alternative it’s possible to make the game aware that your computer does actually have more RAM available by modifying the programs executable file:

  1. First I’d recommend making a back up of the RailRoads.exe just in case.
  2. Now download editbin.exe (if you’re afraid I stuck a virus in my copy of the file then you can find this same file at Microsoft’s website. I believe it’s included with Visual Studio)
  3. Go to the start menu and click Run..
  4. Type <path to editbin>\editbin.exe /LARGEADDRESSAWARE <path to RailRoads>/RailRoads.exe
    ex. C:\editbin.exe /LARGEADDRESSAWARE “C:\Program Files (x86)\Steam\steamapps\common\sid meier’s railroads\RailRoads.exe”
  5. That’s it! :)

Dell E153FPT Vista/7 Drivers

Just in case anyone still uses this old Dell touchscreen monitor and can’t seem to find the drivers..because Dell doesn’t support the screen anymore and the company responsible for the touch pad has changed it’s company name from MicroTouch to 3M Touch Systems.

Anyway, the new drivers from 3M Touch Systems works fine with the Dell E153FPT still so just download the driver here.

Barchart.com iGoogle Gadget

Just made up a quick helper gadget for newer people to stocks. It just gives the barchart.com overall opinion of each stock you enter and serves as a nice quick overview of which stocks to sell, or a check of whether you should buy it.

Obviously it isn’t something to go on by itself, but I’m sure someone will find it useful in combination with their other stock tools.

Barchart

Add Gadget

After adding it just click the down arrow, go into settings, and add a comma separated list of your stocks.

Rogers APN Configuration for Android Phones

Getting the T-Mobile G1 or any Android phone to work on the Rogers network isn’t too difficult. When you first start the phone and you’re at the Touch the Android screen just press the menu button and go into the APN settings. Remove any existing APN configurations that aren’t related to your carrier. Then add the following two new ones.

For Internet Access/Texting

Name
Rogers
APN
internet.com
Username
wapuser1
Password
wap
MCC
302 (should already be filled in)
MNC
either 720 or 72 depending on your SIM card (should already be filled in)

Leave all other settings blank.

For Media Messaging (Picture/Video)

Name
Rogers MMS
APN
media.com
Username
media
Password
mda01
Server
172.25.0.107
MMSC
http://mms.gprs.rogers.com
MMS Proxy
10.128.1.69
MMS Port
80
MCC
302 (should already be filled in)
MNC
either 720 or 72 depending on your SIM card (should already be filled in)
APN Type
mms

Leave all other settings blank.

Simple as that :) Hope you like your new phone!

Scribbles – Playing with SVG & Greasemonkey

Keith Wood has an excellent jQuery plugin for interacting with an SVG canvas which can be found here. I’m using it in a research project I’m working on currently and will talk about in a later post.

For now though the fact that my project involves Greasemonkey, tracking the mouse cursor, and dynamically displaying visual feedback has led to a nice unintended combination of being able to draw all over webpages with the cursor :)

1. Load jQuery and SVG

The first thing you’ll need is to make Greasemonkey load jQuery. Now the usual way to do this on your own webpage would be to include <script style="text/javascript" src="<url to jquery.js file>" />. This is the same way you’ll be loading the script with Greasemonkey, essentially you make Greasemonkey add a script line to the pages header.

var GM_JQ = document.createElement('script');
GM_JQ.src = 'http://jquery.com/src/jquery-latest.js';
GM_JQ.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(GM_JQ);

2. Wait for it to load

Your going to be loading jQuery and SVG from a different server and it may be quick anyway but it won’t be instantaneous so you don’t want to try and run the rest of the jQuery dependent part of the script until jQuery has fully loaded.

function loading() {
   if(typeof unsafeWindow.jQuery == 'undefined'
        || unsafeWindow.jQuery.svg == 'undefined') {
		window.setTimeout(loading,100);
	} else {
		$ = unsafeWindow.jQuery; startPlugin();
	}
}
loading();


This will loop and wait until the jQuery variable isn’t undefined anymore (ie. it’s loaded), and then afterwords assign it to ‘$’ just like you’re used to, and start the drawing goodness.

3. Activate SVG and listen for mouse events

Ok, everythings almost ready to run. Next your going to need a transparent div covering the entire webpage that the SVG canvas can then attach to and draw on.

$("body").prepend("<div id='svg' style='z-index: 999;
        position: absolute; width:100%; height:" +
        document.height + "px'></div>");
$("div#svg").svg();
window.svg = $("div#svg").svg('get');

Also your going to need assign functions to listen for when the mouse is pressed and released and disable the ability to click on anything on the page so your not accidentally clicking a link and leaving the page as you try to draw.

$("body").bind("click", function(e) { return false; });
$("body").bind("mousedown", startingDrawing);
$("body").bind("mouseup", endingDrawing);

4. Drawing :)

Simple enough now. When the mouse is pressed start the mousemove listener and draw a line from the previous mouse position to the next one, and then turn back off the mousemove listener when the mouse button is released.

window.oldX;
window.oldY;
window.startingDrawing = function(event) {
	window.oldX = event.pageX;
	window.oldY = event.pageY;
	$(document).bind("mousemove", mouseMoving);
    return false;
}

window.mouseMoving = function(event) {
	window.svg.line(null, window.oldX, window.oldY,
               event.pageX, event.pageY,
               {'stroke': window.STROKE_COLOR,
               'stroke-width': window.STROKE_WIDTH});
	window.oldX = event.pageX;
	window.oldY = event.pageY;
}

window.endingDrawing = function(event) {
	$(document).unbind('mousemove', mouseMoving);
}

The full script with all the other little details like support for enabling and disabling the script with a keyboard shortcut is available here. The download page also works as a live demo and runs an alternate way not involving Greasemonkey so you can test how the script would work without needing to download it and Greasemonkey.

Bypassing UOIT Restrictions

Printing from your own Laptop (or reconfiguring your broken Thinkpad)

I have one of the school laptops but it’s been configured wrong for printing since I got it in September. Not wanting to go to IT (and have them try to reformat it). I’ve been using the Library computers anytime I need to print something and needless to say it’s a pain. So a big thanks to Chris for finding out how to fix the printer setup.

  1. Start Menu -> Run
  2. Type in: \\osfp01.oncampus.local
  3. A prompt will ask for your:
    Username: oncampus\<Your Student ID>
    Password: <your password for logging onto the school computers>
  4. After this a list of all the printers will popup. Simply double-click whatever printer(s) you want to install.

Note that the first three steps will need to be repeated each time you restart your computer.

Accessing MyCampus Email through IMAP

I know none of you ever check MyCampus because your forgetful, it’s to much work etc. So here’s the settings to have your MyCampus mail be readable in Thunderbird or whichever email client you happen to use.

Protocol: IMAP
Server: itsosims02.mycampus.ca
Port: 143, no SSL
Username: Your Student ID
Password: your original MyCampus password (most likely your birthday in the format MMDDYY)

Accessing the BIOS on T61p’s

Password: br82gt

Java Optimizing Switch Statements

The Java compiler has two different ways it can compile your switch statements.

Fast – tableswitch

switch(num) {
case 1: func2();
case 2: funct2();
case 3: funct3();
}

If it sees that your case values are all close to each other then it optimizes it such that either:

  • The value does not lie within the range: jump to default
  • The value is within the range: calculate correct offset and directly jump to it

This always takes O(1) time since the value does not need to be compared to every possible case; or any of the cases for that mater.

Slow – lookupswitch

switch(num) {
case 1: funct1();
case 42: funct2();
case 9001: funct3();
}

If your values aren’t close to each other then the compiler compiles the switch into a similar manner as an if statement and each value is compared to the cases one after another until the result is found.

This takes O(n) time since a switch that goes to default will have had to compare itself with every single case.

Forcing a compile to tableswitch

So tableswitch is obviously better when you’ve got many cases in your switch but that doesn’t mean the Java compiler will always use it.

If you want to check which was the compiler compiled it run:

javap <class file> > out.txt

and search out.txt for tableswitch or lookupswitch.

If it used lookupswitch where you think tableswitch would be better then you have two options:

  • Add extra empty cases into the switch to make the compiler think the cases are all in a close range, note that you don’t have to add every case. The Java compiler automatically adds missing empty cases and uses tableswitch if just most values within the range are being used
  • Split the switch statement into multiple switch statements so each group of statements fall within a range