BrownBird Posted September 29, 2015 Share Posted September 29, 2015 Morning, I have my MouseEvent, rectangle and booleans; I've tried to add the MouseLisenter with @Override yet nothing happens. Also when adding in MouseLisenter it adds other unneeded methods.. Any help is much appreciated thank you! Quote Link to comment Share on other sites More sharing options...
Khaleesi Posted September 29, 2015 Share Posted September 29, 2015 (edited) Morning, I have my MouseEvent, rectangle and booleans; I've tried to add the MouseLisenter with @Override yet nothing happens. Also when adding in MouseLisenter it adds other unneeded methods.. Any help is much appreciated thank you! Just add this to your onStart(); There are better ways to do it, but this is the most easy ^^ bot.addMouseListener(new MouseListener() { @Override public void mouseReleased(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseClicked(MouseEvent arg0) { } @Override public void mouseEntered(MouseEvent arg0) { } @Override public void mouseExited(MouseEvent arg0) { } }); Edited September 29, 2015 by Khaleesi Scripts 2 Quote Link to comment Share on other sites More sharing options...
BrownBird Posted September 29, 2015 Author Share Posted September 29, 2015 Thanks, instead I just put it into my paint method to keep it clean Quote Link to comment Share on other sites More sharing options...
FrostBug Posted September 29, 2015 Share Posted September 29, 2015 Thanks, instead I just put it into my paint method to keep it clean You wat? Just making sure here; but you should under no circumstance register the event listener in onPaint :E 2 Quote Link to comment Share on other sites More sharing options...
BrownBird Posted September 29, 2015 Author Share Posted September 29, 2015 You wat? Just making sure here; but you should under no circumstance register the event listener in onPaint :E Why not? lol.. It seems to be running just fine, is there something else I wouldn't know about? Quote Link to comment Share on other sites More sharing options...
liverare Posted September 29, 2015 Share Posted September 29, 2015 Why not? lol.. It seems to be running just fine, is there something else I wouldn't know about? Do you hate us or something? Has OSBot wronged you in any way? 1 Quote Link to comment Share on other sites More sharing options...
BrownBird Posted September 29, 2015 Author Share Posted September 29, 2015 Do you hate us or something? Has OSBot wronged you in any way? Oh my.. something occurred without me knowing Quote Link to comment Share on other sites More sharing options...
FrostBug Posted September 29, 2015 Share Posted September 29, 2015 (edited) Why not? lol.. It seems to be running just fine, is there something else I wouldn't know about? Well, onPaint is called 60 times per second (or 30, I don't remember). The bot holds a collection of MouseListeners. Each time you register a listener, it's added to this collection. Registering 60 new mouse listeners per second is not only a fairly critical memory leak; but will increase your CPU usage over time, since every single mouse event has to be processed by the constantly growing number of listeners ;o. I'm fairly surprised if you've been able to run it for ~30 minutes without seeing poor performance Edited September 29, 2015 by FrostBug Quote Link to comment Share on other sites More sharing options...
BrownBird Posted September 29, 2015 Author Share Posted September 29, 2015 (edited) Well, onPaint is called 60 times per second (or 30, I don't remember). The bot holds a collection of MouseListeners. Each time you register a listener, it's added to this collection. Registering 60 new mouse listeners per second is not only a fairly critical memory leak; but will increase your CPU usage over time, since every single mouse event has to be processed by the constantly growing number of listeners ;o. I'm fairly surprised if you've been able to run it for ~30 minutes without seeing poor performance That's what I initially thought when you said this but I've ran it for about 3 hours today with CPU usage staying under 20%, now I'm not quite sure if that's high or not for a single script but it hasn't went past this at all.. Also been browsing the web and such, now for memory i haven't been keeping an eye on that. I will as of now! Edit: I think I understand why I haven't noticed any performance loss.. I have a memcleaner program installed; clearing it every 5 minutes.. Edited September 29, 2015 by BrownBird Quote Link to comment Share on other sites More sharing options...
FrostBug Posted September 29, 2015 Share Posted September 29, 2015 (edited) That's what I initially thought when you said this but I've ran it for about 3 hours today with CPU usage staying under 20%, now I'm not quite sure if that's high or not for a single script but it hasn't went past this at all.. Also been browsing the web and such, now for memory i haven't been keeping an eye on that. I will as of now! Edit: I think I understand why I haven't noticed any performance loss.. I have a memcleaner program installed; clearing it every 5 minutes.. Well, you can easily debug it. int totalListeners = bot.getMouseListeners().size(); If this is constantly increasing, then you have a memory leak Edited September 29, 2015 by FrostBug Quote Link to comment Share on other sites More sharing options...
BrownBird Posted September 29, 2015 Author Share Posted September 29, 2015 Unfortunately there is a leak, I'll have to put it in my onStart Quote Link to comment Share on other sites More sharing options...
Joseph Posted September 30, 2015 Share Posted September 30, 2015 Unfortunately there is a leak, I'll have to put it in my onStart If it's because of the unwanted methods then create a class and extend mouse adapter. Then add that class to the bit's mouselistener Quote Link to comment Share on other sites More sharing options...
Bobrocket Posted October 1, 2015 Share Posted October 1, 2015 Well, onPaint is called 60 times per second (or 30, I don't remember). The bot holds a collection of MouseListeners. Each time you register a listener, it's added to this collection. Registering 60 new mouse listeners per second is not only a fairly critical memory leak; but will increase your CPU usage over time, since every single mouse event has to be processed by the constantly growing number of listeners ;o. I'm fairly surprised if you've been able to run it for ~30 minutes without seeing poor performance I think onPaint (in this context) would be called 50 times per second (syncing with the RS client). The reason we add our listeners in onStart is because otherwise we're creating a new listener 50 times per second (every 20ms), as well as assigning it to the bot to listen. When we click then, something along this would occur: //when clicked for (MouseListener ml : listeners) ml.onClick(mouseArgs); So that means your mouse listeners will also be executing many times in tandem. Quote Link to comment Share on other sites More sharing options...