home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 15 / MA_Cover_15.iso / source / winquake / in_amiga.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-02-10  |  5.3 KB  |  225 lines

  1. /*
  2. Copyright (C) 2000 Peter McGavin.
  3.  
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
  12.  
  13. See the GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. */
  20. // in_null.c -- for systems without a mouse
  21.  
  22. #include "quakedef.h"
  23.  
  24. #include <exec/exec.h>
  25. #include <libraries/lowlevel.h>
  26. #if defined(__STORM__) || defined(__VBCC__)
  27. #include <clib/exec_protos.h>
  28. #include <clib/lowlevel_protos.h>
  29. #else
  30. #include <proto/exec.h>
  31. #include <proto/lowlevel.h>
  32. #endif
  33.  
  34. struct Library *LowLevelBase = NULL;
  35.  
  36. cvar_t m_filter = {"m_filter", "1"};
  37.  
  38. qboolean using_mouse = false;
  39. qboolean mouse_has_moved = false;
  40. qboolean using_joypad = false;
  41. short int last_mouse[2] = {0, 0};
  42.  
  43. /**********************************************************************/
  44. static void Init_Joypad (void)
  45. {
  46.   LowLevelBase = OpenLibrary ("lowlevel.library", 0);
  47.   if (LowLevelBase != NULL) {
  48.     Con_Printf ("Joypad enabled\n");
  49.     using_joypad = true;
  50.   } else {
  51.     Con_Printf ("Can't open lowlevel.libary\n");
  52.     using_joypad = false;
  53.   }
  54. }
  55.  
  56. /**********************************************************************/
  57. void IN_Init (void)
  58. {
  59.   using_mouse = COM_CheckParm("-mouse");
  60.   if (using_mouse)
  61.     Cvar_RegisterVariable (&m_filter);
  62.  
  63.   using_joypad = COM_CheckParm ("-joypad");
  64.   if (using_joypad)
  65.     Init_Joypad ();
  66. }
  67.  
  68. /**********************************************************************/
  69. void IN_Shutdown (void)
  70. {
  71.   if (LowLevelBase != NULL) {
  72.     CloseLibrary (LowLevelBase);
  73.     LowLevelBase = NULL;
  74.   }
  75. }
  76.  
  77. /**********************************************************************/
  78. static void Read_Joypad (void)
  79. {
  80.   ULONG joypos;
  81.  
  82.   joypos = ReadJoyPort (1);
  83.  
  84.   if (joypos & JPF_JOY_LEFT)
  85.     Key_Event (K_AUX1, true);
  86.   else
  87.     Key_Event (K_AUX1, false);
  88.  
  89.   if (joypos & JPF_JOY_RIGHT)
  90.     Key_Event (K_AUX2, true);
  91.   else
  92.     Key_Event (K_AUX2, false);
  93.  
  94.   if (joypos & JPF_JOY_UP)
  95.     Key_Event (K_AUX3, true);
  96.   else
  97.     Key_Event (K_AUX3, false);
  98.  
  99.   if (joypos & JPF_JOY_DOWN)
  100.     Key_Event (K_AUX4, true);
  101.   else
  102.     Key_Event (K_AUX4, false);
  103.  
  104.   if (joypos & JPF_BUTTON_RED)
  105.     Key_Event (K_AUX5, true);
  106.   else
  107.     Key_Event (K_AUX5, false);
  108.  
  109.   if (joypos & JPF_BUTTON_GREEN)
  110.     Key_Event (K_AUX6, true);
  111.   else
  112.     Key_Event (K_AUX6, false);
  113.  
  114.   if (joypos & JPF_BUTTON_YELLOW)
  115.     Key_Event (K_AUX7, true);
  116.   else
  117.     Key_Event (K_AUX7, false);
  118.  
  119.   if (joypos & JPF_BUTTON_BLUE)
  120.     Key_Event (K_AUX8, true);
  121.   else
  122.     Key_Event (K_AUX8, false);
  123.  
  124.   if (joypos & JPF_BUTTON_PLAY)
  125.     Key_Event (K_AUX9, true);
  126.   else
  127.     Key_Event (K_AUX9, false);
  128.  
  129.   if (joypos & JPF_BUTTON_FORWARD)
  130.     Key_Event (K_AUX10, true);
  131.   else
  132.     Key_Event (K_AUX10, false);
  133.  
  134.   if (joypos & JPF_BUTTON_REVERSE)
  135.     Key_Event (K_AUX11 ,true);
  136.   else
  137.     Key_Event (K_AUX11, false);
  138. }
  139.  
  140. /**********************************************************************/
  141. void IN_Commands (void)
  142. {
  143.   if (using_joypad)
  144.     Read_Joypad ();
  145. }
  146.  
  147. /**********************************************************************/
  148. void IN_Move (usercmd_t *cmd)
  149. {
  150.   short int mx, my;
  151.   double mouse_x, mouse_y;
  152.   static int old_mouse_x = 0, old_mouse_y = 0;
  153.  
  154.   if (!mouse_has_moved)
  155.     return;
  156.   mouse_has_moved = false;
  157.  
  158.   mx = (last_mouse[0] >> 1) << 3;
  159.   my = (last_mouse[1] >> 1) << 3;
  160.  
  161.   if (m_filter.value) {
  162.     mouse_x = 0.5 * (mx + old_mouse_x);
  163.     mouse_y = 0.5 * (my + old_mouse_y);
  164.   } else {
  165.     mouse_x = (double)mx;
  166.     mouse_y = (double)my;
  167.   }
  168.   old_mouse_x = mx;
  169.   old_mouse_y = my;
  170.  
  171.   mouse_x *= sensitivity.value;
  172.   mouse_y *= sensitivity.value;
  173.  
  174.   /* add mouse X/Y movement to cmd */
  175.   if ((in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1)))
  176.     cmd->sidemove += m_side.value * mouse_x;
  177.   else
  178.     cl.viewangles[YAW] -= m_yaw.value * mouse_x;
  179.  
  180.   if (in_mlook.state & 1)
  181.     V_StopPitchDrift ();
  182.  
  183.   if ((in_mlook.state & 1) && !(in_strafe.state & 1)) {
  184.     cl.viewangles[PITCH] += m_pitch.value * mouse_y;
  185.     if (cl.viewangles[PITCH] > 80)
  186.       cl.viewangles[PITCH] = 80;
  187.     if (cl.viewangles[PITCH] < -70)
  188.       cl.viewangles[PITCH] = -70;
  189.   } else {
  190.     if ((in_strafe.state & 1) && noclip_anglehack)
  191.       cmd->upmove -= m_forward.value * mouse_y;
  192.     else
  193.       cmd->forwardmove -= m_forward.value * mouse_y;
  194.   }
  195. }
  196.  
  197. /**********************************************************************/
  198. #ifdef __SASC
  199. void _STD_IN_Shutdown (void)
  200. {
  201. //  printf ("_STD_IN_Shutdown\n");
  202.   IN_Shutdown ();
  203. }
  204. #endif
  205.  
  206. /**********************************************************************/
  207. #ifdef __STORM__
  208. void EXIT_9_IN_Shutdown (void)
  209. {
  210. //  printf ("EXIT_9_IN_Shutdown\n");
  211.   IN_Shutdown ();
  212. }
  213. #endif
  214.  
  215. /**********************************************************************/
  216. #ifdef __VBCC__
  217. void _EXIT_9_IN_Shutdown (void)
  218. {
  219. //  printf ("_EXIT_9_IN_Shutdown\n");
  220.   IN_Shutdown ();
  221. }
  222. #endif
  223.  
  224. /**********************************************************************/
  225.