Sign in to follow this  

Need help improving the efficiency for my cursor in console...

This topic is 3320 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This code runs every time there's a mouse event (this is in the console window). My problem is when doing this the cursor is really choppy in it's movement, and it's obvious why it is. It just can't keep up trying to redraw the cursor and the temp tiles every space the cursor moves. The problem is, I don't know how to go about improving this. I might have approached this whole thing the wrong way. Thanks for any help that can be given!
    if(mouse.x != mouse.tempX && mouse.y != mouse.tempY)
    {
        // Redraws the temp tile stored when the cursor went over it before.
        DrawChar(mouse.tempX, mouse.tempY, mouse.tempChar, mouse.tempAttributes);

        // Store the tile properties to redraw it when the cursor moves off it.
        mouse.tempChar = buffer[mouse.x + mouse.y * screenWidth].Char.AsciiChar;
        mouse.tempAttributes = buffer[mouse.x + mouse.y * screenWidth].Attributes;
        mouse.tempX = mouse.x;
        mouse.tempY = mouse.y;

        // Draw the cursor.
        DrawChar(mouse.x, mouse.y, mouse.icon, mouse.fgColor, mouse.bgColor);
    }



[Edited by - Jaqen on November 15, 2008 4:41:55 PM]

Share this post


Link to post
Share on other sites
Honestly, this code performs an insignificant amount of processing. Unless DrawChar is incredibly badly implemented, doing this every time the mouse moves should not produce any sort of "choppiness" (other, of course, than the fact that the pointer can only move from one character position to another).

Share this post


Link to post
Share on other sites
You know what? I'm an idiot. My if statement needs to be OR and not AND... that fixed it. It was only drawing the cursor if I changed coordinates on the y-axis so it looked choppy. Fixed now! Sorry to waste anyone's time.

Share this post


Link to post
Share on other sites

This topic is 3320 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

Sign in to follow this