News:

Welcome to the new Sinister Design forums!

Main Menu

mouse lags

Started by Mithaldu, April 18, 2015, 10:09:54 AM

Previous topic - Next topic

Mithaldu

This is a standard issue that occurs with many games that hide the windows mouse cursor and render their own. Your game+render loop introduces a noticable delay of over ~30 ms to the time from mouse movement to mouse reaction.

Typically the easiest way to fix this is to make an optional toggle to allow the user to use the operating system mouse cursor directly and not render a software mouse cursor.

Mithaldu

No response to this in 2 months. Does this mean it's in the work, or that there'll never be a latency-free mouse?

CraigStern

Hey! Sorry--I must have missed this one.

I can add in an option for that, although I'm surprised to hear that there's so much mouse lag on your computer; I never see any mouse lag in the game except when the game is experiencing general slowdown. Is this something that is always present when you play, or does it start to show up gradually during longer battles?

Mithaldu

Sorry from my side too. I did not realize you had answered, since the forum had not auto-subscribed me to this topic i made. Odd.

As for the mouse issue, there are two separate problems here. However both are subtle and may slip by the attention of people who are not experienced enough to tell small differences in latency or framerate.

And no, this is not any kind of accumulative lag, but constant and universal in the game.

1. On the title screen, the game runs at sub-60 fps by default. Although that is, in fact, inaccurate. The game doesn't run at any FPS, since it doesn't even update the title screen unless the mouse is moved. I'm sure you know about that bit. What you may not know about is that when simply moving the mouse in a circle, the screen will update at roughly 45 fps; unless you mouse over the title screen menu entries, which can make it go to 60 fps.

2. Latency. This one's a little harder to explain. I don't know how much detail you want, and/or need to be convinced, so i will keep it to the most simple and solid facts: For every computer UI experience there is one very important number, the time spent between user input occurring and being acknowledged. This is usually called UI latency and measured in milliseconds. In more simple terms: How much time passes between the hand on the mouse moving, and the brain having interpreted the image of the cursor having moved.

In windows itself that latency is extremely low due to being handled almost entirely in the kernel and with hardware blitting. It is for all intents and purposes imperceptible. In your game the way your game loop works adds a constent and noticable amount of time to this latency, making it feel like one's dragging the mouse cursor around with a rubber band, though a very small one. I'd say there's about 16-32 ms latency added by your render engine.

Note that while not many may consciously notice this happening, you will definitely see people give you feedback along the lines of "this feels better" if you allow them to use the hardware mouse cursor.

Also note this video for a more in-depth explanation of the various layers at which latency is incurred: https://www.youtube.com/watch?v=4GnKsqDAmgY

CraigStern

Hm. Well, the game itself is set to run at 45 frames per second--about 3 times the 15 frames per second at which the game's frame-by-frame pixel animations are rendered, which is itself a bit higher than the 12 FPS for traditional 2D frame-by-frame animations. That's probably not the cause of the mouse latency, though. Unfortunately, I'm not aware of anything that would directly impact mouse latency in the engine I'm using; it may be that AIR simply doesn't get on well with your hardware configuration. :(

Mithaldu

Dangit, i'm subscribed to the thread, but the forum didn't send me an email ...

> Well, the game itself is set to run at 45 frames per second--about 3 times the 15 frames per second at which the game's frame-by-frame pixel animations are rendered, which is itself a bit higher than the 12 FPS for traditional 2D frame-by-frame animations.

That is a rather unfortunate choice, since it doesn't match any computer animation, which is wildly different than non-interactive TV animation seem to refer to. I can go into more detail on that if you wish, but for now i'll leave it at that.

> That's probably not the cause of the mouse latency

It is, in part, since the mouse is drawn by your game itself, which takes at least 22ms, probably more, to react to user input; compared to the OS mouse cursor, which is hardware-blitted on top of your game whenever the OS pleases, how often the OS pleases, and in literally every instance faster and with less latency than any game's engine.

I strongly recommend you try the following:

1. Compile a version of the game that does not hide the OS mouse cursor, so you can see both the game and the OS cursor.
2. Start it up and run your mouse in circles.
3. Note how the game cursor is always lagging behind slighty, and also updating position less often.

(Though you might need to do that with a mouse that has a high polling, 1000+ or so, to see an appreciable difference.)

This video also explains the mechanics behind it a little: https://youtu.be/hjWSRTYV8e0?t=101

Keep in mind, all i'm asking for is an option to do the opposite of the current state:

Hide the ingame cursor and display only the OS cursor. Maybe dress it up a little with a custom .ico, but i don't really care for that.