Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • isOnScreen() is terribly inefficient.


    Dorkinator

    Recommended Posts

    						List<Player> players = getPlayers().all(new Filter<Player>() {
    @Override
    public boolean match(Player i) {
    return i != null && i.getName() != null;
    }
    });
    long st = System.nanoTime();
    for(Player i:players){
    i.isOnScreen();
    }
    System.out.println("isOnScreen "+ (st-System.nanoTime()));

    st = System.nanoTime();
    for(Player i:players){
    Point p = getClient().getViewport().tileToScreen(i.getTile());
    if(new Rectangle(100,100,100,100).contains(p)){
    p.getY();
    }
    }
    System.out.println("stupidMethod "+ (st-System.nanoTime()));
    isOnScreen -21865801
    stupidMethod -11401
    isOnScreen -24470355
    stupidMethod -7894
    isOnScreen -18455235
    stupidMethod -11109
    isOnScreen -27057369
    stupidMethod -9648
    isOnScreen -18955740
    stupidMethod -7601
    isOnScreen -20542620
    stupidMethod -8478
    isOnScreen -18806057
    stupidMethod -8479
    isOnScreen -23592425
    stupidMethod -11110
    isOnScreen -22928497
    stupidMethod -9940
    Generating the point and checking if it's in a rectangle is 4 order of magnitude more efficient.
    Link to comment
    Share on other sites

    So are you saying something like this is better to use than the on screen method in the API?

    private boolean isOnScreen(final NPC npc) {
        if (npc == null) {
            return false;
        }
    
        Point p = getClient().getViewport().tileToScreen(npc.getTile());
        return (new Rectangle(1, 1, 515, 338).contains(p));
    }
    Link to comment
    Share on other sites

    So are you saying something like this is better to use than the on screen method in the API?

    private boolean isOnScreen(final NPC npc) {
        if (npc == null) {
            return false;
        }
    
        Point p = getClient().getViewport().tileToScreen(npc.getTile());
        return (new Rectangle(1, 1, 515, 338).contains(p));
    }

     

    I'm saying that you should never use isOnScreen because of how long it takes to execute.
    Link to comment
    Share on other sites

    isOnScreen calculates the model area and checks if it intersects with the viewport area, so of course it'll be slower than using a less precise check like tileToScreen.

     

    However the small difference probably isn't worth the extra processing power, so I'll give it a look :)

    Link to comment
    Share on other sites

    I'm saying that you should never use isOnScreen because of how long it takes to execute.

    Ive started using the method i posted and not sure if its a placebo effect, but I feel the difference.

    Link to comment
    Share on other sites

    isOnScreen calculates the model area and checks if it intersects with the viewport area, so of course it'll be slower than using a less precise check like tileToScreen.

     

    However the small difference probably isn't worth the extra processing power, so I'll give it a look :)

    That's all we can ask for.
    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.