Power Spawns use expensive utils.checkStructureAgainstController on processPower


  • Culture

    Can a cheaper function be utilized for this, like just checking if the RCL is == 8 or something?

     

    It would be nice to see these process 5 power every tick and have a cooldown as well, similar to labs (if you guys don't want to remove the utils function)

     

     

    Observers also have the same problem with observeRoom(), making it very expensive to call as well.


  • Culture

    Can we get an update on this ticket? It's quite limiting the observer code.


  • Dev Team

    OK, it is now changed to a simple RCL == 8 check for edge cases when there is only one possible structure per room. Here is function’s source code:

    exports.checkStructureAgainstController = function(object, roomObjects, roomController) {
    
    <span class="hljs-keyword">if</span>(!<span class="hljs-keyword">object</span>.user) {
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">true</span>;
    }
    
    <span class="hljs-keyword">if</span>(!roomController || roomController.level &lt; <span class="hljs-number">1</span> || <span class="hljs-keyword">object</span>.user &amp;&amp; roomController.user != <span class="hljs-keyword">object</span>.user) {
        <span class="hljs-keyword">return</span> <span class="hljs-keyword">false</span>;
    }
    
    <span class="hljs-keyword">if</span>(C.CONTROLLER_STRUCTURES[<span class="hljs-keyword">object</span>.<span class="hljs-keyword">type</span>][<span class="hljs-number">8</span>] == <span class="hljs-number">1</span>) {
        <span class="hljs-keyword">return</span> C.CONTROLLER_STRUCTURES[<span class="hljs-keyword">object</span>.<span class="hljs-keyword">type</span>][roomController.level] != <span class="hljs-number">0</span>;
    }
    
    <span class="hljs-keyword">var</span> objects = _.filter(roomObjects, {<span class="hljs-keyword">type</span>: <span class="hljs-keyword">object</span>.<span class="hljs-keyword">type</span>, user: <span class="hljs-keyword">object</span>.user});
    
    <span class="hljs-keyword">if</span>(objects.length &gt; C.CONTROLLER_STRUCTURES[<span class="hljs-keyword">object</span>.<span class="hljs-keyword">type</span>][roomController.level]) {
        objects.sort(exports.comparatorDistance(roomController));
        objects = _.take(objects, C.CONTROLLER_STRUCTURES[<span class="hljs-keyword">object</span>.<span class="hljs-keyword">type</span>][roomController.level]);
        <span class="hljs-keyword">if</span>(!_.contains(objects, <span class="hljs-keyword">object</span>)) {
            <span class="hljs-keyword">return</span> <span class="hljs-keyword">false</span>;
        }
    }
    <span class="hljs-keyword">return</span> <span class="hljs-keyword">true</span>;
    

    };