Created
February 2, 2017 00:31
-
-
Save mschultheiss83/d25cc6b54cb03934f6007cfbe6bcd1d4 to your computer and use it in GitHub Desktop.
[Enhancement] CPU Conservation https://github.com/TooAngel/screeps/issues/118
This file contains 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
'use strict'; | |
require('require'); | |
require('prototype_creep_startup_tasks'); | |
require('prototype_creep_move'); | |
require('prototype_roomPosition'); | |
require('prototype_room_init'); | |
require('prototype_room_costmatrix'); | |
require('visualizer'); | |
require('screepsplus'); | |
if (config.profiler.enabled) { | |
try { | |
var profiler = require('screeps-profiler'); | |
profiler.enable(); | |
} catch (e) { | |
console.log('screeps-profiler not found'); | |
config.profiler.enabled = false; | |
} | |
} | |
brain.stats.init(); | |
var main = function() { | |
if (Game.cpu.bucket < Game.cpu.tickLimit) { | |
console.log('Skipping tick ' + Game.time + ' due to lack of CPU.'); | |
return; | |
//} else { | |
// console.log('bCPU:',Game.cpu.bucket, 'r:', _.size(Game.rooms), 'exec:',(Game.cpu.bucket > Game.cpu.tickLimit * 2) || Game.time % 2 === 0 && Game.time % 3 === 0); | |
} | |
brain.prepareMemory(); | |
brain.handleNextroom(); | |
brain.handleSquadmanager(); | |
brain.handleIncomingTransactions(); | |
brain.stats.addRoot(); | |
// @todo change 2 or 3 to only to primes ;-) use && or || | |
// exec if double Game.cpu.tickLimit or ever 6 ticks | |
if ((Game.cpu.bucket > Game.cpu.tickLimit * 2) || (Game.time % 2 === 0 && Game.time % 3 === 0)) { | |
Memory.myRooms = _.map(_.filter(Game.rooms, r => r.execute()), r => r.name); | |
} | |
if (config.visualizer.enabled && config.visualizer.refresh) { | |
visualizer.render(); | |
} | |
brain.stats.add(['cpu'], { | |
used: Game.cpu.getUsed() | |
}); | |
}; | |
module.exports.loop = function() { | |
if (config.profiler.enabled) { | |
profiler.wrap(function() { | |
main(); | |
}); | |
} else { | |
main(); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(Game.time % 2 === 0 && Game.time % 3 === 0) === Game.time % 6 === 0 :)