Ticket #1878: 0003-Don-t-call-GetSimulationState-unnecessarily-often.patch

File 0003-Don-t-call-GetSimulationState-unnecessarily-often.patch, 5.9 KB (added by sbte, 11 years ago)
  • binaries/data/mods/public/gui/session/input.js

    From 26729263d24642c004b20570989dd0ec7786ff9a Mon Sep 17 00:00:00 2001
    From: "Sven (Sbte)" <svenb.linux@gmail.com>
    Date: Fri, 22 Mar 2013 22:14:18 +0100
    Subject: Don't call GetSimulationState unnecessarily often
    
    ---
     binaries/data/mods/public/gui/session/input.js | 42 +++++++++++++-------------
     1 file changed, 21 insertions(+), 21 deletions(-)
    
    diff --git a/binaries/data/mods/public/gui/session/input.js b/binaries/data/mods/public/gui/session/input.js
    index 328a220..8fd2e57 100644
    a b function findGatherType(gatherer, supply)  
    159159    return undefined;
    160160}
    161161
    162 function getActionInfo(action, target)
     162function getActionInfo(action, target, simState)
    163163{
    164164    var selection = g_Selection.toList();
    165165
    function getActionInfo(action, target)  
    202202    // e.g. prefer to attack an enemy unit, even if some friendly units are closer to the mouse)
    203203    var targetState = GetEntityState(target);
    204204
    205     // Check if the target entity is a resource, dropsite, foundation, or enemy unit.
    206     // Check if any entities in the selection can gather the requested resource,
    207     // can return to the dropsite, can build the foundation, or can attack the enemy
    208     var simState = Engine.GuiInterfaceCall("GetSimulationState");
    209 
    210205    // Look to see what type of command units going to the rally point should use
    211206    if (haveRallyPoints && action == "set-rallypoint")
    212207    {
    function getActionInfo(action, target)  
    288283        return {"possible": true, "data": data, "position": targetState.position, "cursor": cursor, "tooltip": tooltip};
    289284    }
    290285
     286    // Check if the target entity is a resource, dropsite, foundation, or enemy unit.
     287    // Check if any entities in the selection can gather the requested resource,
     288    // can return to the dropsite, can build the foundation, or can attack the enemy
    291289    for each (var entityID in selection)
    292290    {
    293291        var entState = GetEntityState(entityID);
    function determineAction(x, y, fromMinimap)  
    459457        target = targets[0];
    460458    }
    461459
     460    var simState = Engine.GuiInterfaceCall("GetSimulationState");
     461
    462462    if (preSelectedAction != ACTION_NONE)
    463463    {
    464464        switch (preSelectedAction)
    465465        {
    466466        case ACTION_GARRISON:
    467             if (getActionInfo("garrison", target).possible)
     467            if (getActionInfo("garrison", target, simState).possible)
    468468                return {"type": "garrison", "cursor": "action-garrison", "target": target};
    469469            else
    470470                return  {"type": "none", "cursor": "action-garrison-disabled", "target": undefined};
    471471            break;
    472472        case ACTION_REPAIR:
    473             if (getActionInfo("repair", target).possible)
     473            if (getActionInfo("repair", target, simState).possible)
    474474                return {"type": "repair", "cursor": "action-repair", "target": target};
    475475            else
    476476                return {"type": "none", "cursor": "action-repair-disabled", "target": undefined};
    477477            break;
    478478        }
    479479    }
    480     else if (Engine.HotkeyIsPressed("session.attack") && getActionInfo("attack", target).possible)
     480    else if (Engine.HotkeyIsPressed("session.attack") && getActionInfo("attack", target, simState).possible)
    481481    {
    482482        return {"type": "attack", "cursor": "action-attack", "target": target};
    483483    }
    484     else if (Engine.HotkeyIsPressed("session.garrison") && getActionInfo("garrison", target).possible)
     484    else if (Engine.HotkeyIsPressed("session.garrison") && getActionInfo("garrison", target, simState).possible)
    485485    {
    486486        return {"type": "garrison", "cursor": "action-garrison", "target": target};
    487487    }
    488     else if (Engine.HotkeyIsPressed("session.attackmove") && getActionInfo("attack-move", target).possible)
     488    else if (Engine.HotkeyIsPressed("session.attackmove") && getActionInfo("attack-move", target, simState).possible)
    489489    {
    490490            return {"type": "attack-move", "cursor": "action-attack-move"};
    491491    }
    492492    else
    493493    {
    494494        var actionInfo = undefined;
    495         if ((actionInfo = getActionInfo("setup-trade-route", target)).possible)
     495        if ((actionInfo = getActionInfo("setup-trade-route", target, simState)).possible)
    496496            return {"type": "setup-trade-route", "cursor": "action-setup-trade-route", "tooltip": actionInfo.tooltip, "target": target};
    497         else if ((actionInfo = getActionInfo("gather", target)).possible)
     497        else if ((actionInfo = getActionInfo("gather", target, simState)).possible)
    498498            return {"type": "gather", "cursor": actionInfo.cursor, "target": target};
    499         else if ((actionInfo = getActionInfo("returnresource", target)).possible)
     499        else if ((actionInfo = getActionInfo("returnresource", target, simState)).possible)
    500500            return {"type": "returnresource", "cursor": actionInfo.cursor, "target": target};
    501         else if (getActionInfo("build", target).possible)
     501        else if (getActionInfo("build", target, simState).possible)
    502502            return {"type": "build", "cursor": "action-build", "target": target};
    503         else if (getActionInfo("repair", target).possible)
     503        else if (getActionInfo("repair", target, simState).possible)
    504504            return {"type": "build", "cursor": "action-repair", "target": target};
    505         else if ((actionInfo = getActionInfo("set-rallypoint", target)).possible)
     505        else if ((actionInfo = getActionInfo("set-rallypoint", target, simState)).possible)
    506506            return {"type": "set-rallypoint", "cursor": actionInfo.cursor, "data": actionInfo.data, "tooltip": actionInfo.tooltip, "position": actionInfo.position};
    507         else if (getActionInfo("heal", target).possible)
     507        else if (getActionInfo("heal", target, simState).possible)
    508508            return {"type": "heal", "cursor": "action-heal", "target": target};
    509         else if (getActionInfo("attack", target).possible)
     509        else if (getActionInfo("attack", target, simState).possible)
    510510            return {"type": "attack", "cursor": "action-attack", "target": target};
    511         else if (getActionInfo("unset-rallypoint", target).possible)
     511        else if (getActionInfo("unset-rallypoint", target, simState).possible)
    512512            return {"type": "unset-rallypoint"};
    513         else if (getActionInfo("move", target).possible)
     513        else if (getActionInfo("move", target, simState).possible)
    514514            return {"type": "move"};
    515515    }
    516516    return {"type": type, "cursor": cursor, "target": target};