Forum

IN_Accumulate

Discuss programming topics for the various GPL'd game engine sources.

Moderator: InsideQC Admins

IN_Accumulate

Postby r00k » Mon Jul 11, 2011 9:13 pm

Can anyone really tell me what's the purpose of this function? It's called every frame in snd_ExtraUpdate...

Code: Select all
void IN_Accumulate (void)
{
   if (mouseactive)
   {
      if (!dinput)
      {
         GetCursorPos (&current_pos);

         if (key_dest == key_game)
         {
            mx_accum += current_pos.x - window_center_x;
            my_accum += current_pos.y - window_center_y;
         }
         else
         {
            mx_accum = 0;
            my_accum = 0;
         }
   
         // Force the mouse to the center, so there's room to move.
         if (key_dest == key_game)
            SetCursorPos (window_center_x, window_center_y);
      }
   }
}


so within in_win.c we use it ..
Code: Select all
...
   {
      GetCursorPos (&current_pos);
      mx = current_pos.x - window_center_x + mx_accum;
      my = current_pos.y - window_center_y + my_accum;
      mx_accum = my_accum = 0;
   }

   if (m_filter.value)
   {
      mouse_x = (mx + old_mouse_x * 0.5);
      mouse_y = (my + old_mouse_y * 0.5);
   }
...


So, each frame it looks like
mx = (current_pos.x - window_center_x) + (current_pos.x - window_center_x)
my = (current_pos.y - window_center_y) + (current_pos.y - window_center_y);

?!?!?
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Postby mh » Mon Jul 11, 2011 10:00 pm

Best guess.

Because Snd_ExtraUpdate is for handling the case where you're running slow, IN_Accumulate is also for handling the same case for input. It's purpose therefore is to accumulate mouse movement and re-center the cursor in such a scenario. Otherwise, when running slow there is a possibility that mouse movement may go beyond the window bounds, therefore get clipped to the window, and therefore you won't get a full move reflecting how far you actually moved the mouse. (Alternatively, if running slow you might go outside the window bounds temporarily before windows can clip your movement to back inside the bounds, and therefore lose the mouse in-game - haven't tested this and it would only be relevant for windowed modes).

It doesn't get called with DirectInput because if using DirectInput - at least on XP or earlier - mouse cursor clipping is not an issue; DirectInput will handle that automatically for you.

The net movement should be the very same if not running slow, so it should be safe to call at any time. There may be a perfomance decrease from sampling the mouse so many times per frame (particularly in software Quake) but I doubt if it's measurable on modern PCs.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
User avatar
mh
 
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Postby r00k » Tue Jul 12, 2011 12:19 am

So, it's pretty safe to obliterate this code?
I've noticed even cl_maxfps 10 the sound skips even with this code enabled...
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm


Return to Engine Programming

Who is online

Users browsing this forum: No registered users and 1 guest