That seems to have fixed it, with one small caveat. Calling shipWillLaunchFromStation() awards me the equipment, so that's good, but it makes an assumption, that you're looking forward. If you have, say, a mining laser w/ different crosshairs in a side view and are in that view when you change HUDs, you get the wrong crosshairs until you cycle your weapon. It's a simple fix, just change line 356 from
Code: Select all
p.script._currentCrosshairs = this.$selectCrosshairs("VIEW_FORWARD");
to
Code: Select all
p.script._currentCrosshairs = this.$selectCrosshairs(p.viewDirection);
I was having fun testing this, in that HUDselector was blowing up, but I cannot reproduce it after all the changes you made. There's a programmer's axiom that says "if you can't reproduce a bug, it never happened"
I'd be interested to know why you (or phkb) switched to storing data in the player's ship's script. You take a bit of a performance hit doing that. You can get much of that back by following Norby's rule that if you use it more than once, store it locally. For example, change
Code: Select all
this.shipWillLaunchFromStation = function(station) {
var p = player.ship;
// reset the missile monitoring array
p.script._missiles = [];
p.script._missileWarning = false;
p.script._missileWarningChanged = false;
...
to
Code: Select all
this.shipWillLaunchFromStation = function(station) {
var p = player.ship;
var ps = p.script;
// reset the missile monitoring array
ps._missiles = [];
ps._missileWarning = false;
ps._missileWarningChanged = false;
...
so you only looking for the script object once for the entire function. 'p.script...' appears 179 times over ~20 functions. Same goes for player.ship.
Take $scannerAnimationFrame2 for example. It profiles at 1.263 ms on my machine. By changing it to:
Code: Select all
this.$scannerAnimationFrame2 = function() {
var p = player.ship;
p.removeEquipment("EQ_SCANNER_FRAME_1");
p.awardEquipment("EQ_SCANNER_FRAME_2");
}
it now takes only 0.307 ms. Not much, you say? On my PC, your HUD runs at just under 40 frames/sec. That means there's only 25 ms between frames (1/40) so every little bit helps.
Let me know when you settle on a stable version of the script. I want to take a crack at putting it all in a 'closure', where for some objects, you only fetch them once per
game.
"Better to be thought a fool, boy, than to open your trap and remove all doubt." - Grandma [over time, just "Shut your trap... fool"]
"The only stupid questions are the ones you fail to ask." - Dad
How do I...? Nevermind.