Dorkinator 64 Share Posted June 2, 2017 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 -9940Generating the point and checking if it's in a rectangle is 4 order of magnitude more efficient. Link to comment Share on other sites More sharing options...
AHappyHippo 3 Share Posted June 2, 2017 I stopped using it likely because I tracked half my bugs down to it not working. Nice work demonstrating the issue! THIS is how things get changed Link to comment Share on other sites More sharing options...
Noidlox 11 Share Posted June 2, 2017 This will probably be fixed in Dreambot 3.0 Link to comment Share on other sites More sharing options...
Nex 2542 Share Posted June 2, 2017 yea bugged for me aswell Link to comment Share on other sites More sharing options...
Manly 879 Share Posted June 2, 2017 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 More sharing options...
Dorkinator 64 Author Share Posted June 2, 2017 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 More sharing options...
Pandemic 2724 Share Posted June 2, 2017 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 More sharing options...
Manly 879 Share Posted June 2, 2017 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 More sharing options...
Dorkinator 64 Author Share Posted June 2, 2017 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.