Skip to content

Instantly share code, notes, and snippets.

@laverdet
Created October 9, 2015 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laverdet/b7ddacd65175eeb2f526 to your computer and use it in GitHub Desktop.
Save laverdet/b7ddacd65175eeb2f526 to your computer and use it in GitHub Desktop.
screeps cpu migration
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.
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