ref: 3e0f56f7ab7607d2250eb1c0c26559a3cade148b
parent: 8c0e2a0259906c9b5cc495a24ce07f8cca44cb71
author: Simon Howard <fraggle@gmail.com>
date: Sat Sep 17 16:50:46 EDT 2005
Mouse acceleration code to emulate old DOS drivers Subversion-branch: /trunk/chocolate-doom Subversion-revision: 111
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,6 @@
+ Mouse acceleration code to emulate the behaviour of old
+ DOS mouse drivers (thanks to Toke for information about
+ this and suggestions)
Lock surfaces properly when we have to (fixes crash under
Windows 98)
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: i_video.c 105 2005-09-14 21:55:47Z fraggle $
+// $Id: i_video.c 111 2005-09-17 20:50:46Z fraggle $
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2005 Simon Howard
@@ -22,6 +22,9 @@
// 02111-1307, USA.
//
// $Log$
+// Revision 1.27 2005/09/17 20:50:46 fraggle
+// Mouse acceleration code to emulate old DOS drivers
+//
// Revision 1.26 2005/09/14 21:55:47 fraggle
// Lock surfaces properly when we have to (fixes crash under Windows 98)
//
@@ -118,31 +121,29 @@
//-----------------------------------------------------------------------------
static const char
-rcsid[] = "$Id: i_video.c 105 2005-09-14 21:55:47Z fraggle $";
+rcsid[] = "$Id: i_video.c 111 2005-09-17 20:50:46Z fraggle $";
-#include <ctype.h>
#include <SDL.h>
+#include <ctype.h>
+#include <math.h>
#include "config.h"
-#include "w_wad.h"
-#include "z_zone.h"
+#include "doomdef.h"
#include "doomstat.h"
+#include "d_main.h"
#include "i_system.h"
-#include "v_video.h"
#include "m_argv.h"
#include "m_swap.h"
-#include "d_main.h"
#include "s_sound.h"
#include "sounds.h"
+#include "v_video.h"
+#include "w_wad.h"
+#include "z_zone.h"
-#include "doomdef.h"
-
extern void M_QuitDOOM();
static SDL_Surface *screen;
-#define POINTER_WARP_COUNTDOWN 1
-
// palette
static SDL_Color palette[256];
static boolean palette_to_set;
@@ -177,6 +178,15 @@
static byte *saved_background;
static boolean window_focused;
+// mouse acceleration
+// We accelerate the mouse by raising the mouse movement values to
+// the power of this value, to simulate the acceleration in DOS
+// mouse drivers
+//
+// TODO: See what is a sensible default value for this
+
+float mouse_acceleration = 1.5;
+
static boolean MouseShouldBeGrabbed()
{
// if the window doesnt have focus, never grab it
@@ -418,8 +428,14 @@
return result;
}
-boolean mousemoved = false;
+static int AccelerateMouse(int val)
+{
+ if (val < 0)
+ return -AccelerateMouse(-val);
+ return (int) pow(val, mouse_acceleration);
+}
+
void I_GetEvent(void)
{
SDL_Event sdlevent;
@@ -457,8 +473,8 @@
case SDL_MOUSEMOTION:
event.type = ev_mouse;
event.data1 = MouseButtonState();
- event.data2 = sdlevent.motion.xrel * 8;
- event.data3 = -sdlevent.motion.yrel * 8;
+ event.data2 = AccelerateMouse(sdlevent.motion.xrel);
+ event.data3 = -AccelerateMouse(sdlevent.motion.yrel);
D_PostEvent(&event);
break;
case SDL_MOUSEBUTTONDOWN:
--- a/src/m_misc.c
+++ b/src/m_misc.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: m_misc.c 110 2005-09-17 20:25:56Z fraggle $
+// $Id: m_misc.c 111 2005-09-17 20:50:46Z fraggle $
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2005 Simon Howard
@@ -23,6 +23,9 @@
//
//
// $Log$
+// Revision 1.12 2005/09/17 20:50:46 fraggle
+// Mouse acceleration code to emulate old DOS drivers
+//
// Revision 1.11 2005/09/17 20:25:56 fraggle
// Set the default values for variables in their initialisers. Remove the
// "defaultvalue" parameter and associated code from the configuration
@@ -75,7 +78,7 @@
//-----------------------------------------------------------------------------
static const char
-rcsid[] = "$Id: m_misc.c 110 2005-09-17 20:25:56Z fraggle $";
+rcsid[] = "$Id: m_misc.c 111 2005-09-17 20:50:46Z fraggle $";
#include <stdio.h>
#include <stdlib.h>
@@ -363,6 +366,7 @@
{"fullscreen", &fullscreen},
{"screenmultiply", &screenmultiply},
{"novert", &novert},
+ {"mouse_acceleration", &mouse_acceleration, DEFAULT_FLOAT},
};
static default_collection_t extra_defaults =