Created
October 9, 2015 20:38
-
-
Save laverdet/b7ddacd65175eeb2f526 to your computer and use it in GitHub Desktop.
screeps cpu migration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Put this at the top of your main.js file. Log `extraCPU` at the end to see how much extra CPU will be spent. | |
If you're using the "loop" architecture you have to move some stuff around. Just reset `extraCPU` and `called` every tick. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let extraCPU = 0, called = Object.create(null); | |
[ | |
[ Creep, [ | |
'attack', 'build', 'claimController', 'dropEnergy', 'harvest', 'heal', 'move', 'pickup', 'rangedAttack', 'rangedHeal', | |
'repair', 'reserveController', 'suicide', 'transferEnergy', 'unclaimController', 'upgradeController' ], | |
], | |
[ Spawn, [ | |
'createCreep', 'transferEnergy'], | |
], | |
[ Structure, [ | |
'transferEnergy'] | |
], | |
].forEach(function(info) { | |
let proto = info[0].prototype; | |
info[1].forEach(function(name) { | |
proto[name] = function(fn) { | |
return function() { | |
let key = this.id+ ':'+ name; | |
if (called[key] === undefined) { | |
called[key] = true; | |
extraCPU += 0.2; | |
} | |
return fn.apply(this, arguments); | |
}; | |
}(proto[name]); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment