diff --git a/engine/client/clhl_game.c b/engine/client/clhl_game.c index f97ccfc8a..650af27b9 100644 --- a/engine/client/clhl_game.c +++ b/engine/client/clhl_game.c @@ -743,7 +743,7 @@ int CLGHL_checkparm(char *str, const char **next) int CLGHL_keyevent(int key, int down) { if (key >= 241 && key <= 241+5) - Key_Event(K_MOUSE1+key-241, down); + Key_Event(K_MOUSE1+key-241, 0, down); else Con_Printf("CLGHL_keyevent: Unrecognised HL key code\n"); return true; //fixme: check the return type diff --git a/engine/client/in_morphos.c b/engine/client/in_morphos.c index 615016676..a1dcd679d 100644 --- a/engine/client/in_morphos.c +++ b/engine/client/in_morphos.c @@ -168,17 +168,17 @@ void IN_Commands(void) if (imsgs[i].ie_Code == NM_BUTTON_FOURTH) { - Key_Event(K_MOUSE4, true); + Key_Event(K_MOUSE4, 0, true); } else if (imsgs[i].ie_Code == (NM_BUTTON_FOURTH|IECODE_UP_PREFIX)) { - Key_Event(K_MOUSE4, false); + Key_Event(K_MOUSE4, 0, false); } if (key) { - Key_Event(key, 1); - Key_Event(key, 0); + Key_Event(key, 0, 1); + Key_Event(key, 0, 0); } } @@ -194,7 +194,7 @@ void IN_Commands(void) key = keyconv[imsgs[i].ie_Code]; if (key) - Key_Event(key, down); + Key_Event(key, key, down); else { if (developer.value) @@ -205,17 +205,17 @@ void IN_Commands(void) else if (imsgs[i].ie_Class == IECLASS_RAWMOUSE) { if (imsgs[i].ie_Code == IECODE_LBUTTON) - Key_Event(K_MOUSE1, true); + Key_Event(K_MOUSE1, 0, true); else if (imsgs[i].ie_Code == (IECODE_LBUTTON|IECODE_UP_PREFIX)) - Key_Event(K_MOUSE1, false); + Key_Event(K_MOUSE1, 0, false); else if (imsgs[i].ie_Code == IECODE_RBUTTON) - Key_Event(K_MOUSE2, true); + Key_Event(K_MOUSE2, 0, true); else if (imsgs[i].ie_Code == (IECODE_RBUTTON|IECODE_UP_PREFIX)) - Key_Event(K_MOUSE2, false); + Key_Event(K_MOUSE2, 0, false); else if (imsgs[i].ie_Code == IECODE_MBUTTON) - Key_Event(K_MOUSE3, true); + Key_Event(K_MOUSE3, 0, true); else if (imsgs[i].ie_Code == (IECODE_MBUTTON|IECODE_UP_PREFIX)) - Key_Event(K_MOUSE3, false); + Key_Event(K_MOUSE3, 0, false); mouse_x+= imsgs[i].ie_position.ie_xy.ie_x; mouse_y+= imsgs[i].ie_position.ie_xy.ie_y; diff --git a/engine/client/in_sdl.c b/engine/client/in_sdl.c index 842ed5c47..96ba5f1f0 100644 --- a/engine/client/in_sdl.c +++ b/engine/client/in_sdl.c @@ -253,7 +253,7 @@ void Sys_SendKeyEvents(void) case SDL_KEYUP: case SDL_KEYDOWN: - Key_Event(tbl_sdltoquake[event.key.keysym.sym], event.key.state); + Key_Event(tbl_sdltoquake[event.key.keysym.sym], event.key.keysym.unicode, event.key.state); break; case SDL_MOUSEMOTION: @@ -266,7 +266,7 @@ void Sys_SendKeyEvents(void) //Hmm. SDL allows for 255 buttons... if (event.button.button > 10) event.button.button = 10; - Key_Event(K_MOUSE1+event.button.button-1, event.button.state); + Key_Event(K_MOUSE1+event.button.button-1, 0, event.button.state); break; case SDL_QUIT: @@ -288,6 +288,8 @@ void IN_Shutdown (void) void IN_ReInit (void) { IN_ActivateMouse(); + + SDL_EnableUNICODE(SDL_ENABLE); } void IN_Init (void) diff --git a/engine/client/merged.h b/engine/client/merged.h index 12685e788..2855ed0e3 100644 --- a/engine/client/merged.h +++ b/engine/client/merged.h @@ -41,6 +41,11 @@ typedef struct { #if defined(SERVERONLY) #define qrenderer QR_NONE #define FNC(n) (n) //FNC is defined as 'pointer if client build, direct if dedicated server' + +#define Mod_SkinForName Mod_SkinNumForName +#define Mod_FrameForName Mod_FrameNumForName +#define Mod_GetFrameDuration Mod_FrameDuration + #else #define FNC(n) (*n) extern r_qrenderer_t qrenderer; diff --git a/engine/common/com_mesh.c b/engine/common/com_mesh.c index 4ca27d7ba..7870d8612 100644 --- a/engine/common/com_mesh.c +++ b/engine/common/com_mesh.c @@ -2817,7 +2817,7 @@ int Mod_TagNumForName(model_t *model, char *name) return 0; } -#ifndef SERVERONLY + int Mod_FrameNumForName(model_t *model, char *name) { galiasgroup_t *group; @@ -2844,6 +2844,7 @@ int Mod_FrameNumForName(model_t *model, char *name) return -1; } +#ifndef SERVERONLY int Mod_SkinNumForName(model_t *model, char *name) { int i; @@ -2863,6 +2864,7 @@ int Mod_SkinNumForName(model_t *model, char *name) return -1; } +#endif float Mod_FrameDuration(model_t *model, int frameno) { @@ -2880,7 +2882,6 @@ float Mod_FrameDuration(model_t *model, int frameno) group += frameno; return group->numposes/group->rate; } -#endif #ifdef MD3MODELS diff --git a/engine/gl/gl_vidcocoa.m b/engine/gl/gl_vidcocoa.m index 0d0729196..3723ceeef 100644 --- a/engine/gl/gl_vidcocoa.m +++ b/engine/gl/gl_vidcocoa.m @@ -1,634 +1,636 @@ -/* - - Copyright (C) 2001-2002 A Nourai - Copyright (C) 2006 Jacek Piszczek (Mac OSX port) - - This program is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; either version 2 - of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - - See the included (GNU.txt) GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#import -#import -#include "quakedef.h" - -id _p; -extern float mouse_x,mouse_y; -int evcnt = 2; - -// Jacek: some keys are bogus, my ibook kb lacks keys and apple's docs lack -// keyCode documentation - -unsigned char keyconv[] = -{ - 'a', /* 0 */ - 's', - 'd', - 'f', - 'h', - 'g', - 'z', - 'x', - 'c', - 'v', - '0', /* 10 */ - 'b', - 'q', - 'w', - 'e', - 'r', - 'y', - 't', - '1', - '2', - '3', /* 20 */ - '4', - '6', - '5', - '=', - '9', - '7', - '-', - '8', - '0', - ']', /* 30 */ - 'o', - 'u', - '[', - 'i', - 'p', - K_ENTER, - 'l', - 'j', - '\'', - 'k', /* 40 */ - ';', - '\\', - ',', - '/', - 'n', - 'm', - '.', - K_TAB, - K_SPACE, - '`', /* 50 */ - K_BACKSPACE, - 'v', - K_ESCAPE, - 'n', - 'm', - ',', - '.', - '/', - 0, - K_KP_DEL, /* 60 */ - K_KP_HOME, - K_KP_UPARROW, - K_KP_PGUP, - ' ', - K_KP_DEL, - K_TAB, - K_KP_STAR, - K_ENTER, - K_KP_PLUS, - K_DEL, /* 70 */ - K_INS, - K_PGUP, - K_PGDN, - K_KP_MINUS, - K_KP_SLASH, - K_KP_ENTER, - 0, - K_KP_MINUS, - 0, - K_F1, /* 80 */ - K_F2, - K_KP_INS, - K_KP_END, - K_KP_DOWNARROW, - K_KP_PGDN, - K_KP_LEFTARROW, - K_KP_5, - K_KP_RIGHTARROW, - K_KP_HOME, - 0, /* 90 */ - K_KP_UPARROW, - K_KP_PGUP, - 0, - K_KP_PLUS, - 0, - K_LSHIFT, - K_RSHIFT, - 0, - K_RCTRL, - K_ALT, /* 100 */ - K_ALT, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - K_PAUSE, /* 110 */ - K_F12, - 0, - 0, - 0, - K_HOME, - K_PGUP, - K_DEL, - 0, - K_END, - 0, /* 120 */ - K_PGDN, - 0, - K_LEFTARROW, - K_RIGHTARROW, - K_DOWNARROW, - K_UPARROW, - 0, - 0, - 0, - 0, /* 130 */ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, /* 140 */ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, /* 150 */ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, /* 160 */ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, /* 170 */ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, /* 180 */ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, /* 190 */ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, /* 200 */ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, /* 210 */ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, /* 220 */ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, /* 230 */ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, /* 240 */ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, /* 250 */ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 -}; - -// validate the depth -int checkDepth(int d) -{ - if (d == 24) - d = 32; - if (d != 15 && d != 16 && d != 32) - d = 32; - - return d; -} - -@interface FTEApplication : NSApplication -{ - NSOpenGLContext *_openGLContext; - NSTimer *_timer; - double time, oldtime, newtime; - unsigned int oldmflags; - CFDictionaryRef olddmode; -} -- (void)initDisplayWidth:(int)width height:(int)height depth:(int)depth; -- (void)flushBuffer; -- (void)runLoop:(NSTimer *)timer; -@end - -@implementation FTEApplication - -- (id)init -{ - if((self = [super init])) - [self setDelegate:self]; - - oldmflags = 0; - - return self; -} - -- (void)initDisplayWidth:(int)width height:(int)height depth:(int)depth; -{ - long value = 1; - NSOpenGLPixelFormat* format; - NSOpenGLPixelFormatAttribute attributes[] = { - NSOpenGLPFAFullScreen, - NSOpenGLPFAScreenMask, - CGDisplayIDToOpenGLDisplayMask(kCGDirectMainDisplay), - NSOpenGLPFANoRecovery, - NSOpenGLPFADoubleBuffer, - NSOpenGLPFAAccelerated, - NSOpenGLPFADepthSize, checkDepth(depth), - 0}; - - olddmode = CGDisplayCurrentMode(kCGDirectMainDisplay); - - // zeros mean we use the default screen! (but with 32bit depth) - if (!((width == 0) && (height == 0) && (depth == 0))) - { - depth = checkDepth(depth); - if (width == 0) - width = CGDisplayPixelsWide(kCGDirectMainDisplay); - if (height == 0) - height = CGDisplayPixelsHigh(kCGDirectMainDisplay); - CFDictionaryRef dmode = CGDisplayBestModeForParameters( - kCGDirectMainDisplay, - checkDepth(depth), - width, - height, - FALSE); - CGDisplaySwitchToMode(kCGDirectMainDisplay,dmode); - } - - // get screen size - vid.width = CGDisplayPixelsWide(kCGDirectMainDisplay); - vid.height = CGDisplayPixelsHigh(kCGDirectMainDisplay); - - // capture the display! - CGDisplayCapture(kCGDirectMainDisplay); - CGDisplayHideCursor(kCGDirectMainDisplay); - CGAssociateMouseAndMouseCursorPosition(false); - - format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]; - _openGLContext = [[NSOpenGLContext alloc] - initWithFormat:format - shareContext:nil]; - [format release]; - if(_openGLContext == nil) - { - NSLog(@"Cannot create OpenGL context"); - [NSApp terminate:nil]; - return; - } - - [_openGLContext setFullScreen]; - [_openGLContext setValues:&value forParameter:kCGLCPSwapInterval]; - - [_openGLContext makeCurrentContext]; - - _timer = [[NSTimer scheduledTimerWithTimeInterval:1.0/250.0 - target:self - selector:@selector(runLoop:) - userInfo:nil - repeats:YES] - retain]; - - [[NSApp mainWindow] setAcceptsMouseMovedEvents:YES]; -} - -- (void)dealloc -{ - CGAssociateMouseAndMouseCursorPosition(true); - CGDisplayRelease(kCGDirectMainDisplay); - CGDisplayRestoreColorSyncSettings(); - CGDisplaySwitchToMode(kCGDirectMainDisplay,olddmode); - CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, - CGPointMake(vid.width/2,vid.height/2)); - [_openGLContext release]; - [_timer invalidate]; - [_timer release]; - - [super dealloc]; -} - -- (void) sendEvent:(NSEvent*)event -{ - if ([event type] == NSKeyDown) - { - Key_Event(keyconv[[event keyCode]],TRUE); - //printf("%d\n",[event keyCode]); - return; - } - - if ([event type] == NSKeyUp) - { - Key_Event(keyconv[[event keyCode]],FALSE); - return; - } - - if ([event type] == NSFlagsChanged) - { - unsigned int mflags = [event modifierFlags]; - - if ((mflags & NSAlternateKeyMask) ^ (oldmflags & NSAlternateKeyMask)) - { - Key_Event(K_ALT,(mflags & NSAlternateKeyMask) ? TRUE : FALSE); - } - - if ((mflags & NSControlKeyMask) ^ (oldmflags & NSControlKeyMask)) - { - Key_Event(K_LCTRL,(mflags & NSControlKeyMask) ? TRUE : FALSE); - } - - if ((mflags & NSShiftKeyMask) ^ (oldmflags & NSShiftKeyMask)) - { - Key_Event(K_LSHIFT,(mflags & NSShiftKeyMask) ? TRUE : FALSE); - } - - if ((mflags & NSCommandKeyMask) ^ (oldmflags & NSCommandKeyMask)) - { - Key_Event(K_LWIN,(mflags & NSCommandKeyMask) ? TRUE : FALSE); - } - - if ((mflags & NSAlphaShiftKeyMask) ^ (oldmflags & NSAlphaShiftKeyMask)) - { - Key_Event(K_CAPSLOCK,(mflags & NSAlphaShiftKeyMask) ? TRUE : FALSE); - } - - oldmflags = mflags; - return; - } - - if ([event type] == NSMouseMoved) - { - mouse_x += [event deltaX]; - mouse_y += [event deltaY]; - - // lame hack to avoid mouse ptr moving to the top of the screen since - // a click there causes the mouse to appear and lock the event stream - // Apple sucks :( - // NOTE: it seems this is still needed for 10.3.x! - CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, - CGPointMake(vid.width - 1,vid.height - 1)); - return; - } - - if ([event type] == NSLeftMouseDragged) - { - mouse_x += [event deltaX]; - mouse_y += [event deltaY]; - CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, - CGPointMake(vid.width - 1,vid.height - 1)); - return; - } - - if ([event type] == NSRightMouseDragged) - { - mouse_x += [event deltaX]; - mouse_y += [event deltaY]; - CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, - CGPointMake(vid.width - 1,vid.height - 1)); - return; - } - - if ([event type] == NSOtherMouseDragged) - { - mouse_x += [event deltaX]; - mouse_y += [event deltaY]; - CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, - CGPointMake(vid.width - 1,vid.height - 1)); - return; - } - - if ([event type] == NSLeftMouseDown) - { - Key_Event(K_MOUSE1,TRUE); - return; - } - - if ([event type] == NSLeftMouseUp) - { - Key_Event(K_MOUSE1,FALSE); - return; - } - - if ([event type] == NSRightMouseDown) - { - Key_Event(K_MOUSE2,TRUE); - return; - } - - if ([event type] == NSRightMouseUp) - { - Key_Event(K_MOUSE2,FALSE); - return; - } - - if ([event type] == NSOtherMouseDown) - { - Key_Event(K_MOUSE3,TRUE); - return; - } - - if ([event type] == NSOtherMouseUp) - { - Key_Event(K_MOUSE3,FALSE); - return; - } - - if ([event type] == NSScrollWheel) - { - Key_Event(([event deltaY] > 0.0) ? K_MWHEELUP : K_MWHEELDOWN,TRUE); - return; - } -} - -- (void)flushBuffer -{ - // synchronise display - [_openGLContext flushBuffer]; -} - -// called on a timer event -- (void)runLoop:(NSTimer *)timer -{ - newtime = Sys_DoubleTime (); - time = newtime - oldtime; - oldtime = newtime; - - Host_Frame(time); -} - -- (void)run -{ - oldtime = Sys_DoubleTime (); - [super run]; -} - -@end - -static FTEApplication *fteglapp; - -BOOL initCocoa(rendererstate_t *info) -{ - // init the application the hard way since we don't want to run it - // immediately - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - fteglapp = [FTEApplication sharedApplication]; - - // store the var for later disposal - _p = pool; - - // init the display - [fteglapp initDisplayWidth:info->width height:info->height depth:info->bpp]; - - return TRUE; -} - -qboolean glcocoaRunLoop(void) -{ - if (!fteglapp) - return false; - // this will initialise the NSTimer and run the app - [NSApp run]; - - return true; -} - -void killCocoa(void) -{ - // terminates FTEApplicaiton - [NSApp terminate:nil]; - [_p release]; - - fteglapp = NULL; -} - -void flushCocoa(void) -{ - // synchronises display - [NSApp flushBuffer]; -} - -void cocoaGamma(unsigned short *r,unsigned short *g,unsigned short *b) -{ - CGByteValue gammatable[3*256]; - int i; - - // convert the gamma values - for(i=0;i<256;i++) - { - gammatable[i] = r[i] >> 8; - gammatable[i+256] = g[i] >> 8; - gammatable[i+512] = b[i] >> 8; - } - - //... and set them - CGSetDisplayTransferByByteTable(kCGDirectMainDisplay,256, - gammatable, - gammatable + 256, - gammatable + 512); -} +/* + + Copyright (C) 2001-2002 A Nourai + Copyright (C) 2006 Jacek Piszczek (Mac OSX port) + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + See the included (GNU.txt) GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#import +#import +#include "quakedef.h" + +id _p; +extern float mouse_x,mouse_y; +int evcnt = 2; + +// Jacek: some keys are bogus, my ibook kb lacks keys and apple's docs lack +// keyCode documentation + +unsigned char keyconv[] = +{ + 'a', /* 0 */ + 's', + 'd', + 'f', + 'h', + 'g', + 'z', + 'x', + 'c', + 'v', + '0', /* 10 */ + 'b', + 'q', + 'w', + 'e', + 'r', + 'y', + 't', + '1', + '2', + '3', /* 20 */ + '4', + '6', + '5', + '=', + '9', + '7', + '-', + '8', + '0', + ']', /* 30 */ + 'o', + 'u', + '[', + 'i', + 'p', + K_ENTER, + 'l', + 'j', + '\'', + 'k', /* 40 */ + ';', + '\\', + ',', + '/', + 'n', + 'm', + '.', + K_TAB, + K_SPACE, + '`', /* 50 */ + K_BACKSPACE, + 'v', + K_ESCAPE, + 'n', + 'm', + ',', + '.', + '/', + 0, + K_KP_DEL, /* 60 */ + K_KP_HOME, + K_KP_UPARROW, + K_KP_PGUP, + ' ', + K_KP_DEL, + K_TAB, + K_KP_STAR, + K_ENTER, + K_KP_PLUS, + K_DEL, /* 70 */ + K_INS, + K_PGUP, + K_PGDN, + K_KP_MINUS, + K_KP_SLASH, + K_KP_ENTER, + 0, + K_KP_MINUS, + 0, + K_F1, /* 80 */ + K_F2, + K_KP_INS, + K_KP_END, + K_KP_DOWNARROW, + K_KP_PGDN, + K_KP_LEFTARROW, + K_KP_5, + K_KP_RIGHTARROW, + K_KP_HOME, + 0, /* 90 */ + K_KP_UPARROW, + K_KP_PGUP, + 0, + K_KP_PLUS, + 0, + K_LSHIFT, + K_RSHIFT, + 0, + K_RCTRL, + K_ALT, /* 100 */ + K_ALT, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + K_PAUSE, /* 110 */ + K_F12, + 0, + 0, + 0, + K_HOME, + K_PGUP, + K_DEL, + 0, + K_END, + 0, /* 120 */ + K_PGDN, + 0, + K_LEFTARROW, + K_RIGHTARROW, + K_DOWNARROW, + K_UPARROW, + 0, + 0, + 0, + 0, /* 130 */ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, /* 140 */ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, /* 150 */ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, /* 160 */ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, /* 170 */ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, /* 180 */ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, /* 190 */ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, /* 200 */ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, /* 210 */ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, /* 220 */ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, /* 230 */ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, /* 240 */ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, /* 250 */ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 +}; + +// validate the depth +int checkDepth(int d) +{ + if (d == 24) + d = 32; + if (d != 15 && d != 16 && d != 32) + d = 32; + + return d; +} + +@interface FTEApplication : NSApplication +{ + NSOpenGLContext *_openGLContext; + NSTimer *_timer; + double time, oldtime, newtime; + unsigned int oldmflags; + CFDictionaryRef olddmode; +} +- (void)initDisplayWidth:(int)width height:(int)height depth:(int)depth; +- (void)flushBuffer; +- (void)runLoop:(NSTimer *)timer; +@end + +@implementation FTEApplication + +- (id)init +{ + if((self = [super init])) + [self setDelegate:self]; + + oldmflags = 0; + + return self; +} + +- (void)initDisplayWidth:(int)width height:(int)height depth:(int)depth; +{ + long value = 1; + NSOpenGLPixelFormat* format; + NSOpenGLPixelFormatAttribute attributes[] = { + NSOpenGLPFAFullScreen, + NSOpenGLPFAScreenMask, + CGDisplayIDToOpenGLDisplayMask(kCGDirectMainDisplay), + NSOpenGLPFANoRecovery, + NSOpenGLPFADoubleBuffer, + NSOpenGLPFAAccelerated, + NSOpenGLPFADepthSize, checkDepth(depth), + 0}; + + olddmode = CGDisplayCurrentMode(kCGDirectMainDisplay); + + // zeros mean we use the default screen! (but with 32bit depth) + if (!((width == 0) && (height == 0) && (depth == 0))) + { + depth = checkDepth(depth); + if (width == 0) + width = CGDisplayPixelsWide(kCGDirectMainDisplay); + if (height == 0) + height = CGDisplayPixelsHigh(kCGDirectMainDisplay); + CFDictionaryRef dmode = CGDisplayBestModeForParameters( + kCGDirectMainDisplay, + checkDepth(depth), + width, + height, + FALSE); + CGDisplaySwitchToMode(kCGDirectMainDisplay,dmode); + } + + // get screen size + vid.width = CGDisplayPixelsWide(kCGDirectMainDisplay); + vid.height = CGDisplayPixelsHigh(kCGDirectMainDisplay); + + // capture the display! + CGDisplayCapture(kCGDirectMainDisplay); + CGDisplayHideCursor(kCGDirectMainDisplay); + CGAssociateMouseAndMouseCursorPosition(false); + + format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]; + _openGLContext = [[NSOpenGLContext alloc] + initWithFormat:format + shareContext:nil]; + [format release]; + if(_openGLContext == nil) + { + NSLog(@"Cannot create OpenGL context"); + [NSApp terminate:nil]; + return; + } + + [_openGLContext setFullScreen]; + [_openGLContext setValues:&value forParameter:kCGLCPSwapInterval]; + + [_openGLContext makeCurrentContext]; + + _timer = [[NSTimer scheduledTimerWithTimeInterval:1.0/250.0 + target:self + selector:@selector(runLoop:) + userInfo:nil + repeats:YES] + retain]; + + [[NSApp mainWindow] setAcceptsMouseMovedEvents:YES]; +} + +- (void)dealloc +{ + CGAssociateMouseAndMouseCursorPosition(true); + CGDisplayRelease(kCGDirectMainDisplay); + CGDisplayRestoreColorSyncSettings(); + CGDisplaySwitchToMode(kCGDirectMainDisplay,olddmode); + CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, + CGPointMake(vid.width/2,vid.height/2)); + [_openGLContext release]; + [_timer invalidate]; + [_timer release]; + + [super dealloc]; +} + +- (void) sendEvent:(NSEvent*)event +{ + if ([event type] == NSKeyDown) + { + int code = keyconv[[event keyCode]] + Key_Event(code, code, TRUE); + //printf("%d\n",[event keyCode]); + return; + } + + if ([event type] == NSKeyUp) + { + int code = keyconv[[event keyCode]]; + Key_Event(code, code, FALSE); + return; + } + + if ([event type] == NSFlagsChanged) + { + unsigned int mflags = [event modifierFlags]; + + if ((mflags & NSAlternateKeyMask) ^ (oldmflags & NSAlternateKeyMask)) + { + Key_Event(K_ALT, 0, (mflags & NSAlternateKeyMask) ? TRUE : FALSE); + } + + if ((mflags & NSControlKeyMask) ^ (oldmflags & NSControlKeyMask)) + { + Key_Event(K_LCTRL, 0, (mflags & NSControlKeyMask) ? TRUE : FALSE); + } + + if ((mflags & NSShiftKeyMask) ^ (oldmflags & NSShiftKeyMask)) + { + Key_Event(K_LSHIFT, 0, (mflags & NSShiftKeyMask) ? TRUE : FALSE); + } + + if ((mflags & NSCommandKeyMask) ^ (oldmflags & NSCommandKeyMask)) + { + Key_Event(K_LWIN, 0, (mflags & NSCommandKeyMask) ? TRUE : FALSE); + } + + if ((mflags & NSAlphaShiftKeyMask) ^ (oldmflags & NSAlphaShiftKeyMask)) + { + Key_Event(K_CAPSLOCK, 0, (mflags & NSAlphaShiftKeyMask) ? TRUE : FALSE); + } + + oldmflags = mflags; + return; + } + + if ([event type] == NSMouseMoved) + { + mouse_x += [event deltaX]; + mouse_y += [event deltaY]; + + // lame hack to avoid mouse ptr moving to the top of the screen since + // a click there causes the mouse to appear and lock the event stream + // Apple sucks :( + // NOTE: it seems this is still needed for 10.3.x! + CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, + CGPointMake(vid.width - 1,vid.height - 1)); + return; + } + + if ([event type] == NSLeftMouseDragged) + { + mouse_x += [event deltaX]; + mouse_y += [event deltaY]; + CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, + CGPointMake(vid.width - 1,vid.height - 1)); + return; + } + + if ([event type] == NSRightMouseDragged) + { + mouse_x += [event deltaX]; + mouse_y += [event deltaY]; + CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, + CGPointMake(vid.width - 1,vid.height - 1)); + return; + } + + if ([event type] == NSOtherMouseDragged) + { + mouse_x += [event deltaX]; + mouse_y += [event deltaY]; + CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, + CGPointMake(vid.width - 1,vid.height - 1)); + return; + } + + if ([event type] == NSLeftMouseDown) + { + Key_Event(K_MOUSE1, 0, TRUE); + return; + } + + if ([event type] == NSLeftMouseUp) + { + Key_Event(K_MOUSE1, 0, FALSE); + return; + } + + if ([event type] == NSRightMouseDown) + { + Key_Event(K_MOUSE2, 0, TRUE); + return; + } + + if ([event type] == NSRightMouseUp) + { + Key_Event(K_MOUSE2, 0, FALSE); + return; + } + + if ([event type] == NSOtherMouseDown) + { + Key_Event(K_MOUSE3, 0, TRUE); + return; + } + + if ([event type] == NSOtherMouseUp) + { + Key_Event(K_MOUSE3, 0, FALSE); + return; + } + + if ([event type] == NSScrollWheel) + { + Key_Event(([event deltaY] > 0.0) ? K_MWHEELUP : K_MWHEELDOWN, 0, TRUE); + return; + } +} + +- (void)flushBuffer +{ + // synchronise display + [_openGLContext flushBuffer]; +} + +// called on a timer event +- (void)runLoop:(NSTimer *)timer +{ + newtime = Sys_DoubleTime (); + time = newtime - oldtime; + oldtime = newtime; + + Host_Frame(time); +} + +- (void)run +{ + oldtime = Sys_DoubleTime (); + [super run]; +} + +@end + +static FTEApplication *fteglapp; + +BOOL initCocoa(rendererstate_t *info) +{ + // init the application the hard way since we don't want to run it + // immediately + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + fteglapp = [FTEApplication sharedApplication]; + + // store the var for later disposal + _p = pool; + + // init the display + [fteglapp initDisplayWidth:info->width height:info->height depth:info->bpp]; + + return TRUE; +} + +qboolean glcocoaRunLoop(void) +{ + if (!fteglapp) + return false; + // this will initialise the NSTimer and run the app + [NSApp run]; + + return true; +} + +void killCocoa(void) +{ + // terminates FTEApplicaiton + [NSApp terminate:nil]; + [_p release]; + + fteglapp = NULL; +} + +void flushCocoa(void) +{ + // synchronises display + [NSApp flushBuffer]; +} + +void cocoaGamma(unsigned short *r,unsigned short *g,unsigned short *b) +{ + CGByteValue gammatable[3*256]; + int i; + + // convert the gamma values + for(i=0;i<256;i++) + { + gammatable[i] = r[i] >> 8; + gammatable[i+256] = g[i] >> 8; + gammatable[i+512] = b[i] >> 8; + } + + //... and set them + CGSetDisplayTransferByByteTable(kCGDirectMainDisplay,256, + gammatable, + gammatable + 256, + gammatable + 512); +} diff --git a/engine/gl/gl_vidlinuxglx.c b/engine/gl/gl_vidlinuxglx.c index a59a22604..78521bb37 100644 --- a/engine/gl/gl_vidlinuxglx.c +++ b/engine/gl/gl_vidlinuxglx.c @@ -369,7 +369,7 @@ void ClearAllStates (void) // send an up event for each key, to make sure the server clears them all for (i=0 ; i<256 ; i++) { - Key_Event (i, false); + Key_Event (i, 0, false); } Key_ClearStates (); @@ -399,7 +399,8 @@ static void GetEvent(void) break; case KeyPress: case KeyRelease: - Key_Event(XLateKey(&event.xkey), event.type == KeyPress); + int b = XLateKey(&event.xkey); + Key_Event(b, b, event.type == KeyPress); break; case MotionNotify: @@ -458,7 +459,7 @@ static void GetEvent(void) b = x11violations?K_MOUSE10:-1; if (b>=0) - Key_Event(b, true); + Key_Event(b, 0, true); #ifdef WITH_VMODE if (vidmode_ext && vidmode_usemode>=0) if (!ActiveApp) @@ -501,7 +502,7 @@ static void GetEvent(void) b = x11violations?K_MOUSE10:-1; if (b>=0) - Key_Event(b, false); + Key_Event(b, 0, false); break; case FocusIn: diff --git a/engine/server/pr_cmds.c b/engine/server/pr_cmds.c index 5bd7fdf47..01c2e88ba 100644 --- a/engine/server/pr_cmds.c +++ b/engine/server/pr_cmds.c @@ -2023,6 +2023,7 @@ static void PF_frameduration (progfuncs_t *prinst, struct globalvars_s *pr_globa } static void PF_skinforname (progfuncs_t *prinst, struct globalvars_s *pr_globals) { +#ifndef SERVERONLY unsigned int modelindex = G_FLOAT(OFS_PARM0); char *str = PF_VarString(prinst, 1, pr_globals); model_t *mod = (modelindex>= MAX_MODELS)?NULL:sv.models[modelindex]; @@ -2031,6 +2032,7 @@ static void PF_skinforname (progfuncs_t *prinst, struct globalvars_s *pr_globals if (mod && Mod_SkinForName) G_FLOAT(OFS_RETURN) = Mod_SkinForName(mod, str); else +#endif G_FLOAT(OFS_RETURN) = -1; }