Jump to content

Hide paint?


Recommended Posts

Posted (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 by Khaleesi Scripts
  • Like 2
Posted (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 by FrostBug
Posted (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 by BrownBird
Posted (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 by FrostBug
Posted

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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...