1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Question Efficiency and new query calls

Discussion in 'Developer Support' started by generalsensei, Jul 10, 2021.

  1. generalsensei

    Joined:
    Apr 21, 2019
    Messages:
    43
    Likes Received:
    9
    Hey guys im noticing whenever I poll for enemies to attack in my fighter bot I am having substantial stuttering and lag during the new query. The query in question is as follows, and makes sure enemies found are within my defined area constraints.

    Npc cow = Npcs.newQuery().names(Pattern.compile("Cow")).actions("Attack").visible().reachable().within(StoredVariables.CowAreaA, StoredVariables.CowAreaB, StoredVariables.CowAreaC).filter(x -> x != null && x.getHealthGauge() == null && x.getTarget() == null && x.getPosition() != Players.getLocal().getPosition()).results().nearest(bot.StoredVariables.DistanceAlgorithm);

    Is there a more efficient way to write such a query, maybe I don't need as many null checks?
     
    CuppaJava likes this.
  2. dahnae

    Joined:
    Oct 21, 2018
    Messages:
    369
    Likes Received:
    132
    I'm guessing .visible() is what is causing most of the lag
     
  3. generalsensei

    Joined:
    Apr 21, 2019
    Messages:
    43
    Likes Received:
    9
    Do you suggest maybe I use a radius around the players location instead?
     
  4. dahnae

    Joined:
    Oct 21, 2018
    Messages:
    369
    Likes Received:
    132
    .nearest() will already return the nearest npc anyways, but yes, checking only around the players position could improve the performance, but might not be necessary
     
  5. Dark sage

    Dark sage Misfits

    Joined:
    Nov 21, 2016
    Messages:
    1,330
    Likes Received:
    371
    .isReachable can be cpu heavy
     
  6. CuppaJava

    CuppaJava cuppa.drink(java);

    Joined:
    Mar 13, 2018
    Messages:
    6,052
    Likes Received:
    1,359
    Null checking too much is never really an issue as it's so quick

    Honestly I'd just recommend running the line repeatedly, taking out a chunk from it each time and see which removal causes a dramatic speedup. But yeah it's probably the visibility or reachability. Or maybe your sort algorithm depending on what it is.
     

Share This Page

Loading...