Annotation of quake2/rhapsody/in_next.m, revision 1.1

1.1     ! root        1: // in_next.m
        !             2: 
        !             3: #import <AppKit/AppKit.h>
        !             4: #import <drivers/event_status_driver.h>
        !             5: #include "../client/client.h"
        !             6: 
        !             7: float  mousex, mousey;
        !             8: 
        !             9: float  mouse_center_x = 160;
        !            10: float  mouse_center_y = 100;
        !            11: 
        !            12: void PSsetmouse (float x, float y);
        !            13: void PSshowcursor (void);
        !            14: void PShidecursor (void);
        !            15: void PScurrentmouse (int win, float *x, float *y);
        !            16: 
        !            17: extern NSView  *vid_view_i;
        !            18: extern NSWindow        *vid_window_i;
        !            19: 
        !            20: qboolean       mlooking;
        !            21: qboolean       mouseinitialized;
        !            22: int            mouse_buttons;
        !            23: int            mouse_oldbuttonstate;
        !            24: int            mouseactive;
        !            25: int            mousereset;
        !            26: int            mx_accum, my_accum;
        !            27: int            window_center_x, window_center_y;
        !            28: int            old_mouse_x, old_mouse_y;
        !            29: 
        !            30: cvar_t in_mouse = {"in_mouse", "0", CVAR_ARCHIVE};
        !            31: cvar_t m_filter = {"m_filter", "0", CVAR_ARCHIVE};
        !            32: cvar_t freelook = {"in_freelook", "0", CVAR_ARCHIVE};
        !            33: 
        !            34: 
        !            35: /*
        !            36: ===========
        !            37: IN_ActivateMouse
        !            38: 
        !            39: Called when the window gains focus or changes in some way
        !            40: ===========
        !            41: */
        !            42: void IN_ActivateMouse (void)
        !            43: {
        !            44:     NSRect     r;
        !            45:   
        !            46:         if (!mouseinitialized)
        !            47:                 return;
        !            48:         if (!in_mouse.value)
        !            49:                 return;
        !            50: 
        !            51:         r = [vid_window_i frame];
        !            52:         window_center_x = r.size.width / 2;
        !            53:         window_center_y = r.size.height / 2;
        !            54: 
        !            55:         if (!mouseactive)
        !            56:             PShidecursor ();
        !            57:  
        !            58:         mouseactive = true;
        !            59:         mousereset = true;
        !            60: }
        !            61: 
        !            62: 
        !            63: /*
        !            64: ===========
        !            65: IN_DeactivateMouse
        !            66: 
        !            67: Called when the window loses focus
        !            68: ===========
        !            69: */
        !            70: void IN_DeactivateMouse (void)
        !            71: {
        !            72:         if (!mouseinitialized)
        !            73:                 return;
        !            74: 
        !            75:     if (mouseactive)
        !            76:         PSshowcursor ();
        !            77: 
        !            78:     mouseactive = false;
        !            79: }
        !            80: 
        !            81: 
        !            82: /*
        !            83: ===========
        !            84: IN_StartupMouse
        !            85: ===========
        !            86: */
        !            87: void IN_StartupMouse (void)
        !            88: {
        !            89:         if ( COM_CheckParm ("-nomouse") ) 
        !            90:                 return; 
        !            91: 
        !            92:         mouseinitialized = true;
        !            93: 
        !            94:         mouse_buttons = 3;
        !            95: 
        !            96:         IN_ActivateMouse ();
        !            97: }
        !            98: 
        !            99: /*
        !           100: ===========
        !           101: IN_MouseEvent
        !           102: ===========
        !           103: */
        !           104: void IN_MouseEvent (int mstate)
        !           105: {
        !           106:         int            i;
        !           107: 
        !           108:         if (!mouseactive)
        !           109:                 return;
        !           110: 
        !           111: // perform button actions
        !           112:         for (i=0 ; i<mouse_buttons ; i++)
        !           113:         {
        !           114:                 if ( (mstate & (1<<i)) &&
        !           115:                         !(mouse_oldbuttonstate & (1<<i)) )
        !           116:                 {
        !           117:                         Key_Event (K_MOUSE1 + i, true);
        !           118:                 }
        !           119: 
        !           120:                 if ( !(mstate & (1<<i)) &&
        !           121:                         (mouse_oldbuttonstate & (1<<i)) )
        !           122:                 {
        !           123:                                 Key_Event (K_MOUSE1 + i, false);
        !           124:                 }
        !           125:         }      
        !           126: 
        !           127:         mouse_oldbuttonstate = mstate;
        !           128: }
        !           129: 
        !           130: 
        !           131: 
        !           132: /*
        !           133: ===========
        !           134: IN_Accumulate
        !           135: ===========
        !           136: */
        !           137: void IN_Accumulate (void)
        !           138: {
        !           139:         int            dx, dy;
        !           140:         static int             old_x, old_y;
        !           141: 
        !           142:         if (!mouseinitialized)
        !           143:                 return;
        !           144: 
        !           145:         if (in_mouse.modified)
        !           146:         {
        !           147:             in_mouse.modified = false;
        !           148:             IN_DeactivateMouse ();
        !           149:             IN_ActivateMouse ();
        !           150:         }
        !           151: 
        !           152:         if (!mouseactive)
        !           153:                 return;
        !           154: 
        !           155: //       [vid_view_i lockFocus];
        !           156: 
        !           157:         if (mousereset)
        !           158:         {      // we haven't centered cursor yet
        !           159:                 mousereset = false;
        !           160:         }
        !           161:         else
        !           162:         {
        !           163:         NSPoint        p;
        !           164: 
        !           165:             PScurrentmouse ([vid_window_i windowNumber], &mousex, &mousey);
        !           166: 
        !           167:                p.x = mousex;
        !           168:                p.y = mousey;
        !           169:                p = [vid_view_i convertPoint:p fromView: nil];
        !           170: 
        !           171:             mousex = p.x;
        !           172:             mousey = p.y;
        !           173:             
        !           174:             dx = mousex - old_x;
        !           175:             dy = old_y - mousey;
        !           176: 
        !           177:                 if (!dx && !dy)
        !           178:                         return;
        !           179:                 mx_accum += dx;
        !           180:                 my_accum += dy;
        !           181:         }
        !           182: 
        !           183:         // force the mouse to the center, so there's room to move
        !           184:         PSsetmouse (window_center_x, window_center_y);
        !           185:         PScurrentmouse ([vid_window_i windowNumber], &mousex, &mousey);
        !           186: //        PSsetmouse (window_center_x, window_center_y);
        !           187:         old_x = window_center_x;
        !           188:         old_y = window_center_y;
        !           189: 
        !           190: //        [vid_view_i unlockFocus];
        !           191: }
        !           192: 
        !           193: 
        !           194: /*
        !           195: ===========
        !           196: IN_MouseMove
        !           197: ===========
        !           198: */
        !           199: void IN_MouseMove (usercmd_t *cmd)
        !           200: {
        !           201:         int            mx, my;
        !           202:        int             mouse_x, mouse_y;
        !           203:        
        !           204:         IN_Accumulate ();
        !           205: 
        !           206:         mx = mx_accum;
        !           207:         my = my_accum;
        !           208: 
        !           209:         mx_accum = 0;
        !           210:         my_accum = 0;
        !           211: 
        !           212:         if (m_filter.value)
        !           213:         {
        !           214:                 mouse_x = (mx + old_mouse_x) * 0.5;
        !           215:                 mouse_y = (my + old_mouse_y) * 0.5;
        !           216:         }
        !           217:         else
        !           218:         {
        !           219:                 mouse_x = mx;
        !           220:                 mouse_y = my;
        !           221:         }
        !           222: 
        !           223:         old_mouse_x = mx;
        !           224:         old_mouse_y = my;
        !           225: 
        !           226:         if (!mx && !my)
        !           227:                 return;
        !           228: 
        !           229:         if (!mouseactive)
        !           230:                 return;
        !           231: 
        !           232:         mouse_x *= sensitivity.value;
        !           233:         mouse_y *= sensitivity.value;
        !           234: 
        !           235: // add mouse X/Y movement to cmd
        !           236:         if ( (in_strafe.state & 1) || (lookstrafe.value && mlooking ))
        !           237:                 cmd->sidemove += m_side.value * mouse_x;
        !           238:         else
        !           239:                 cl.viewangles[YAW] -= m_yaw.value * mouse_x;
        !           240: 
        !           241:         if ( (mlooking || freelook.value) && !(in_strafe.state & 1))
        !           242:         {
        !           243:                 cl.viewangles[PITCH] += m_pitch.value * mouse_y;
        !           244:                 if (cl.viewangles[PITCH] > 80)
        !           245:                         cl.viewangles[PITCH] = 80;
        !           246:                 if (cl.viewangles[PITCH] < -70)
        !           247:                         cl.viewangles[PITCH] = -70;
        !           248:         }
        !           249:         else
        !           250:         {
        !           251:                 cmd->forwardmove -= m_forward.value * mouse_y;
        !           252:         }
        !           253: 
        !           254: }
        !           255: 
        !           256: void IN_ShowMouse (void)
        !           257: {
        !           258:     PSshowcursor ();
        !           259: }
        !           260: 
        !           261: void IN_HideMouse (void)
        !           262: {
        !           263:     PShidecursor ();
        !           264: }
        !           265: 
        !           266: NXEventHandle  eventhandle;
        !           267: NXMouseScaling oldscaling, newscaling;
        !           268: NXMouseButton  oldbutton;
        !           269: 
        !           270: /*
        !           271:  =============
        !           272:  IN_Init
        !           273:  =============
        !           274:  */
        !           275: void IN_Init (void)
        !           276: {
        !           277:     Cvar_RegisterVariable (&in_mouse);
        !           278:     Cvar_RegisterVariable (&m_filter);
        !           279:     Cvar_RegisterVariable (&freelook);
        !           280: 
        !           281:     Cmd_AddCommand ("showmouse", IN_ShowMouse);
        !           282:     Cmd_AddCommand ("hidemouse", IN_HideMouse);
        !           283:     
        !           284:     IN_StartupMouse ();
        !           285: 
        !           286:     // open the event status driver
        !           287:     eventhandle = NXOpenEventStatus();
        !           288:     NXGetMouseScaling (eventhandle, &oldscaling);
        !           289:     NXSetMouseScaling (eventhandle, &newscaling);
        !           290:     oldbutton = NXMouseButtonEnabled (eventhandle);
        !           291:     NXEnableMouseButton (eventhandle, 2);
        !           292: }
        !           293: 
        !           294: /*
        !           295:  =============
        !           296:  IN_Shutdown
        !           297:  =============
        !           298:  */
        !           299: void IN_Shutdown (void)
        !           300: {
        !           301:     IN_DeactivateMouse ();
        !           302: 
        !           303:     // put mouse scaling back the way it was
        !           304:     NXSetMouseScaling (eventhandle, &oldscaling);
        !           305:     NXEnableMouseButton (eventhandle, oldbutton);
        !           306:     NXCloseEventStatus (eventhandle);
        !           307: }
        !           308: 
        !           309: void IN_Move (usercmd_t *cmd)
        !           310: {
        !           311:     IN_MouseMove (cmd);
        !           312: }
        !           313: 
        !           314: void IN_Commands (void)
        !           315: {
        !           316: }
        !           317: 
        !           318: 
        !           319: /*
        !           320: =========================================================================
        !           321: 
        !           322: VIEW CENTERING
        !           323: 
        !           324: =========================================================================
        !           325: */
        !           326: 
        !           327: void V_StopPitchDrift (void)
        !           328: {
        !           329:        cl.laststop = cl.time;
        !           330:        cl.nodrift = true;
        !           331:        cl.pitchvel = 0;
        !           332: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.