shithub: choc

Download patch

ref: 1658ae111ec89bc32d63dcb12848337a968a0400
parent: b8e861b27e87b35cecc3a057511f65419184cc4d
author: Simon Howard <fraggle@gmail.com>
date: Fri Mar 16 17:43:28 EDT 2007

Add config file option to enable/disable native keyboard bindings.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 860

--- a/setup/configfile.c
+++ b/setup/configfile.c
@@ -188,7 +188,7 @@
     char      *filename;
 } default_collection_t;
 
-static default_t	doom_defaults_list[] =
+static default_t doom_defaults_list[] =
 {
     {"mouse_sensitivity", &mouseSensitivity, DEFAULT_INT, 0, 0},
     {"sfx_volume",&sfxVolume, DEFAULT_INT, 0, 0},
@@ -265,6 +265,7 @@
     {"show_endoom",                 &show_endoom, DEFAULT_INT, 0, 0},
     {"vanilla_savegame_limit",      &vanilla_savegame_limit, DEFAULT_INT, 0, 0},
     {"vanilla_demo_limit",          &vanilla_demo_limit, DEFAULT_INT, 0, 0},
+    {"vanilla_keyboard_mapping",    &vanilla_keyboard_mapping, DEFAULT_INT, 0, 0},
 #ifdef FEATURE_MULTIPLAYER
     {"player_name",                 &net_player_name,          DEFAULT_STRING, 0, 0},
 #endif
--- a/setup/keyboard.c
+++ b/setup/keyboard.c
@@ -37,6 +37,8 @@
 int key_speed = KEY_RSHIFT;
 int joybspeed = 3;
 
+int vanilla_keyboard_mapping = 1;
+
 static int always_run = 0;
 
 static int *allkeys[] = {&key_left, &key_right, &key_up, &key_down, 
@@ -107,10 +109,14 @@
     TXT_AddWidgets(window, 
                    TXT_NewSeparator("Movement"),
                    movement_table = TXT_NewTable(2),
-                   run_control = TXT_NewCheckBox("Always run", &always_run),
 
                    TXT_NewSeparator("Action"),
                    action_table = TXT_NewTable(2),
+
+                   TXT_NewSeparator("Misc."),
+                   run_control = TXT_NewCheckBox("Always run", &always_run),
+                   TXT_NewInvertedCheckBox("Use native keyboard mapping", 
+                                           &vanilla_keyboard_mapping),
                    NULL);
 
     TXT_SetColumnWidths(movement_table, 20, 8);
--- a/setup/keyboard.h
+++ b/setup/keyboard.h
@@ -33,6 +33,7 @@
 extern int key_strafe;
 extern int key_speed;
 extern int joybspeed;
+extern int vanilla_keyboard_mapping;
 
 void ConfigKeyboard(void);
 
--- a/src/am_map.c
+++ b/src/am_map.c
@@ -706,7 +706,7 @@
 	    cheatstate=0;
 	    rc = false;
 	}
-	if (!deathmatch && cht_CheckCheat(&cheat_amap, ev->data1))
+	if (!deathmatch && cht_CheckCheat(&cheat_amap, ev->data2))
 	{
 	    rc = false;
 	    cheating = (cheating+1) % 3;
--- a/src/g_game.c
+++ b/src/g_game.c
@@ -666,7 +666,7 @@
 { 
     // allow spy mode changes even during the demo
     if (gamestate == GS_LEVEL && ev->type == ev_keydown 
-	&& ev->data1 == KEY_F12 && (singledemo || !deathmatch) )
+     && ev->data1 == KEY_F12 && (singledemo || !deathmatch) )
     {
 	// spy mode 
 	do 
--- a/src/hu_stuff.c
+++ b/src/hu_stuff.c
@@ -551,7 +551,7 @@
 	    message_counter = HU_MSGTIMEOUT;
 	    eatkey = true;
 	}
-	else if (netgame && ev->data1 == HU_INPUTTOGGLE)
+	else if (netgame && ev->data2 == HU_INPUTTOGGLE)
 	{
 	    eatkey = chat_on = true;
 	    HUlib_resetIText(&w_chat);
@@ -561,7 +561,7 @@
 	{
 	    for (i=0; i<MAXPLAYERS ; i++)
 	    {
-		if (ev->data1 == destination_keys[i])
+		if (ev->data2 == destination_keys[i])
 		{
 		    if (playeringame[i] && i!=consoleplayer)
 		    {
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -138,6 +138,12 @@
 
 static SDL_Cursor *cursors[2];
 
+// If true, keyboard mapping is ignored, like in Vanilla Doom.
+// The sensible thing to do is to disable this if you have a non-US
+// keyboard.
+
+int vanilla_keyboard_mapping = true;
+
 // Mouse acceleration
 //
 // This emulates some of the behavior of DOS mouse drivers by increasing
@@ -419,7 +425,26 @@
             case SDL_KEYDOWN:
                 event.type = ev_keydown;
                 event.data1 = TranslateKey(&sdlevent.key.keysym);
-		event.data2 = sdlevent.key.keysym.unicode;
+
+                // If Vanilla keyboard mapping enabled, the keyboard
+                // scan code is used to give the character typed.
+                // This does not change depending on keyboard layout.
+                // If you have a German keyboard, pressing 'z' will
+                // give 'y', for example.  It is desirable to be able
+                // to fix this so that people with non-standard 
+                // keyboard mappings can type properly.  If vanilla
+                // mode is disabled, use the properly translated 
+                // version.
+
+                if (vanilla_keyboard_mapping)
+                {
+                    event.data2 = event.data1;
+                }
+                else
+                {
+                    event.data2 = sdlevent.key.keysym.unicode;
+                }
+
                 D_PostEvent(&event);
                 break;
 
--- a/src/m_menu.c
+++ b/src/m_menu.c
@@ -1569,13 +1569,13 @@
     if (messageToPrint)
     {
 	if (messageNeedsInput == true &&
-	    !(key == ' ' || key == 'n' || key == 'y' || key == KEY_ESCAPE))
+	    !(ch == ' ' || ch == 'n' || ch == 'y' || key == KEY_ESCAPE))
 	    return false;
 		
 	menuactive = messageLastMenuActive;
 	messageToPrint = 0;
 	if (messageRoutine)
-	    messageRoutine(key);
+	    messageRoutine(ch);
 			
 	menuactive = false;
 	S_StartSound(NULL,sfx_swtchx);
@@ -1769,7 +1769,7 @@
 	
       default:
 	for (i = itemOn+1;i < currentMenu->numitems;i++)
-	    if (currentMenu->menuitems[i].alphaKey == key)
+	    if (currentMenu->menuitems[i].alphaKey == ch)
 	    {
 		itemOn = i;
 		S_StartSound(NULL,sfx_pstop);
@@ -1776,7 +1776,7 @@
 		return true;
 	    }
 	for (i = 0;i <= itemOn;i++)
-	    if (currentMenu->menuitems[i].alphaKey == key)
+	    if (currentMenu->menuitems[i].alphaKey == ch)
 	    {
 		itemOn = i;
 		S_StartSound(NULL,sfx_pstop);
--- a/src/m_misc.c
+++ b/src/m_misc.c
@@ -280,6 +280,7 @@
 extern int      show_endoom;
 extern int      vanilla_savegame_limit;
 extern int      vanilla_demo_limit;
+extern int      vanilla_keyboard_mapping;
 
 extern int snd_musicdevice;
 extern int snd_sfxdevice;
@@ -408,6 +409,7 @@
     {"show_endoom",                 &show_endoom, DEFAULT_INT, 0, 0},
     {"vanilla_savegame_limit",      &vanilla_savegame_limit, DEFAULT_INT, 0, 0},
     {"vanilla_demo_limit",          &vanilla_demo_limit, DEFAULT_INT, 0, 0},
+    {"vanilla_keyboard_mapping",    &vanilla_keyboard_mapping, DEFAULT_INT, 0, 0},
     {"video_driver",                &video_driver, DEFAULT_STRING, 0, 0},
 #ifdef FEATURE_MULTIPLAYER
     {"player_name",                 &net_player_name,          DEFAULT_STRING, 0, 0},
--- a/src/st_stuff.c
+++ b/src/st_stuff.c
@@ -474,7 +474,7 @@
     if (!netgame && gameskill != sk_nightmare)
     {
       // 'dqd' cheat for toggleable god mode
-      if (cht_CheckCheat(&cheat_god, ev->data1))
+      if (cht_CheckCheat(&cheat_god, ev->data2))
       {
 	plyr->cheats ^= CF_GODMODE;
 	if (plyr->cheats & CF_GODMODE)
@@ -489,7 +489,7 @@
 	  plyr->message = DEH_String(STSTR_DQDOFF);
       }
       // 'fa' cheat for killer fucking arsenal
-      else if (cht_CheckCheat(&cheat_ammonokey, ev->data1))
+      else if (cht_CheckCheat(&cheat_ammonokey, ev->data2))
       {
 	plyr->armorpoints = deh_idfa_armor;
 	plyr->armortype = deh_idfa_armor_class;
@@ -503,7 +503,7 @@
 	plyr->message = DEH_String(STSTR_FAADDED);
       }
       // 'kfa' cheat for key full ammo
-      else if (cht_CheckCheat(&cheat_ammo, ev->data1))
+      else if (cht_CheckCheat(&cheat_ammo, ev->data2))
       {
 	plyr->armorpoints = deh_idkfa_armor;
 	plyr->armortype = deh_idkfa_armor_class;
@@ -520,7 +520,7 @@
 	plyr->message = DEH_String(STSTR_KFAADDED);
       }
       // 'mus' cheat for changing music
-      else if (cht_CheckCheat(&cheat_mus, ev->data1))
+      else if (cht_CheckCheat(&cheat_mus, ev->data2))
       {
 	
 	char	buf[3];
@@ -549,9 +549,9 @@
 	}
       }
       else if ( (gamemission == doom 
-                 && cht_CheckCheat(&cheat_noclip, ev->data1))
+                 && cht_CheckCheat(&cheat_noclip, ev->data2))
              || (gamemission != doom 
-                 && cht_CheckCheat(&cheat_commercial_noclip,ev->data1)))
+                 && cht_CheckCheat(&cheat_commercial_noclip,ev->data2)))
       {	
         // Noclip cheat.
         // For Doom 1, use the idspipsopd cheat; for all others, use
@@ -567,7 +567,7 @@
       // 'behold?' power-up cheats
       for (i=0;i<6;i++)
       {
-	if (cht_CheckCheat(&cheat_powerup[i], ev->data1))
+	if (cht_CheckCheat(&cheat_powerup[i], ev->data2))
 	{
 	  if (!plyr->powers[i])
 	    P_GivePower( plyr, i);
@@ -581,12 +581,12 @@
       }
       
       // 'behold' power-up menu
-      if (cht_CheckCheat(&cheat_powerup[6], ev->data1))
+      if (cht_CheckCheat(&cheat_powerup[6], ev->data2))
       {
 	plyr->message = DEH_String(STSTR_BEHOLD);
       }
       // 'choppers' invulnerability & chainsaw
-      else if (cht_CheckCheat(&cheat_choppers, ev->data1))
+      else if (cht_CheckCheat(&cheat_choppers, ev->data2))
       {
 	plyr->weaponowned[wp_chainsaw] = true;
 	plyr->powers[pw_invulnerability] = true;
@@ -593,7 +593,7 @@
 	plyr->message = DEH_String(STSTR_CHOPPERS);
       }
       // 'mypos' for player position
-      else if (cht_CheckCheat(&cheat_mypos, ev->data1))
+      else if (cht_CheckCheat(&cheat_mypos, ev->data2))
       {
 	static char	buf[ST_MSGWIDTH];
 	sprintf(buf, "ang=0x%x;x,y=(0x%x,0x%x)",
@@ -605,7 +605,7 @@
     }
     
     // 'clev' change-level cheat
-    if (cht_CheckCheat(&cheat_clev, ev->data1))
+    if (cht_CheckCheat(&cheat_clev, ev->data2))
     {
       char		buf[3];
       int		epsd;