347 } |
347 } |
348 |
348 |
349 if (down) { |
349 if (down) { |
350 uint32 pressed_key = QZ_MapKey(keycode) | unicode; |
350 uint32 pressed_key = QZ_MapKey(keycode) | unicode; |
351 HandleKeypress(pressed_key); |
351 HandleKeypress(pressed_key); |
352 DEBUG(driver, 2)("cocoa_v: QZ_KeyEvent: %x (%x), down, mapping: %x", keycode, unicode, pressed_key); |
352 DEBUG(driver, 2, "cocoa_v: QZ_KeyEvent: %x (%x), down, mapping: %x", keycode, unicode, pressed_key); |
353 } else { |
353 } else { |
354 DEBUG(driver, 2)("cocoa_v: QZ_KeyEvent: %x (%x), up", keycode, unicode); |
354 DEBUG(driver, 2, "cocoa_v: QZ_KeyEvent: %x (%x), up", keycode, unicode); |
355 } |
355 } |
356 } |
356 } |
357 |
357 |
358 static void QZ_DoUnsidedModifiers(unsigned int newMods) |
358 static void QZ_DoUnsidedModifiers(unsigned int newMods) |
359 { |
359 { |
740 } |
738 } |
741 |
739 |
742 #ifdef _DEBUG |
740 #ifdef _DEBUG |
743 et = GetTick(); |
741 et = GetTick(); |
744 |
742 |
745 DEBUG(driver, 1)("cocoa_v: nextEventMatchingMask took %i ms total", _cocoa_video_data.tEvent); |
743 DEBUG(driver, 1, "cocoa_v: nextEventMatchingMask took %i ms total", _cocoa_video_data.tEvent); |
746 DEBUG(driver, 1)("cocoa_v: game loop took %i ms total (%i ms without sleep)", et - et0, et - et0 - st); |
744 DEBUG(driver, 1, "cocoa_v: game loop took %i ms total (%i ms without sleep)", et - et0, et - et0 - st); |
747 DEBUG(driver, 1)("cocoa_v: (nextEventMatchingMask total)/(game loop total) is %f%%", (double)_cocoa_video_data.tEvent / (double)(et - et0) * 100); |
745 DEBUG(driver, 1, "cocoa_v: (nextEventMatchingMask total)/(game loop total) is %f%%", (double)_cocoa_video_data.tEvent / (double)(et - et0) * 100); |
748 DEBUG(driver, 1)("cocoa_v: (nextEventMatchingMask total)/(game loop without sleep total) is %f%%", (double)_cocoa_video_data.tEvent / (double)(et - et0 - st) * 100); |
746 DEBUG(driver, 1, "cocoa_v: (nextEventMatchingMask total)/(game loop without sleep total) is %f%%", (double)_cocoa_video_data.tEvent / (double)(et - et0 - st) * 100); |
749 #endif |
747 #endif |
750 } |
748 } |
751 |
749 |
752 |
750 |
753 /****************************************************************************** |
751 /****************************************************************************** |
1934 * Video driver interface * |
1932 * Video driver interface * |
1935 ******************************************************************************/ |
1933 ******************************************************************************/ |
1936 |
1934 |
1937 static void CocoaVideoStop(void) |
1935 static void CocoaVideoStop(void) |
1938 { |
1936 { |
1939 DEBUG(driver, 1)("cocoa_v: CocoaVideoStop"); |
|
1940 |
|
1941 if (!_cocoa_video_started) return; |
1937 if (!_cocoa_video_started) return; |
1942 |
1938 |
1943 if (_cocoa_video_data.isset) QZ_UnsetVideoMode(); |
1939 if (_cocoa_video_data.isset) QZ_UnsetVideoMode(); |
1944 |
1940 |
1945 [_ottd_main release]; |
1941 [_ottd_main release]; |
1948 } |
1944 } |
1949 |
1945 |
1950 static const char *CocoaVideoStart(const char * const *parm) |
1946 static const char *CocoaVideoStart(const char * const *parm) |
1951 { |
1947 { |
1952 const char *ret; |
1948 const char *ret; |
1953 |
|
1954 DEBUG(driver, 1)("cocoa_v: CocoaVideoStart"); |
|
1955 |
1949 |
1956 if (_cocoa_video_started) return "Already started"; |
1950 if (_cocoa_video_started) return "Already started"; |
1957 _cocoa_video_started = true; |
1951 _cocoa_video_started = true; |
1958 |
1952 |
1959 memset(&_cocoa_video_data, 0, sizeof(_cocoa_video_data)); |
1953 memset(&_cocoa_video_data, 0, sizeof(_cocoa_video_data)); |
1982 _cocoa_video_data.num_dirty_rects++; |
1976 _cocoa_video_data.num_dirty_rects++; |
1983 } |
1977 } |
1984 |
1978 |
1985 static void CocoaVideoMainLoop(void) |
1979 static void CocoaVideoMainLoop(void) |
1986 { |
1980 { |
1987 DEBUG(driver, 1)("cocoa_v: CocoaVideoMainLoop"); |
|
1988 |
|
1989 /* Start the main event loop */ |
1981 /* Start the main event loop */ |
1990 [NSApp run]; |
1982 [NSApp run]; |
1991 } |
1983 } |
1992 |
1984 |
1993 static bool CocoaVideoChangeRes(int w, int h) |
1985 static bool CocoaVideoChangeRes(int w, int h) |
1994 { |
1986 { |
1995 const char *ret; |
1987 const char *ret = QZ_SetVideoModeAndRestoreOnFailure((uint)w, (uint)h, _cocoa_video_data.fullscreen); |
1996 DEBUG(driver, 1)("cocoa_v: CocoaVideoChangeRes"); |
|
1997 |
|
1998 ret = QZ_SetVideoModeAndRestoreOnFailure((uint)w, (uint)h, _cocoa_video_data.fullscreen); |
|
1999 if (ret != NULL) { |
1988 if (ret != NULL) { |
2000 DEBUG(driver, 1)("cocoa_v: failed with message: %s", ret); |
1989 DEBUG(driver, 0, "cocoa_v: CocoaVideoChangeRes failed with message: %s", ret); |
2001 } |
1990 } |
2002 |
1991 |
2003 return ret == NULL; |
1992 return ret == NULL; |
2004 } |
1993 } |
2005 |
1994 |
2006 static void CocoaVideoFullScreen(bool full_screen) |
1995 static void CocoaVideoFullScreen(bool full_screen) |
2007 { |
1996 { |
2008 const char *ret; |
1997 const char *ret = QZ_SetVideoModeAndRestoreOnFailure(_cocoa_video_data.width, _cocoa_video_data.height, full_screen); |
2009 |
|
2010 DEBUG(driver, 1)("cocoa_v: CocoaVideoFullScreen"); |
|
2011 |
|
2012 ret = QZ_SetVideoModeAndRestoreOnFailure(_cocoa_video_data.width, _cocoa_video_data.height, full_screen); |
|
2013 if (ret != NULL) { |
1998 if (ret != NULL) { |
2014 DEBUG(driver, 1)("cocoa_v: failed with message: %s", ret); |
1999 DEBUG(driver, 0, "cocoa_v: CocoaVideoFullScreen failed with message: %s", ret); |
2015 } |
2000 } |
2016 |
2001 |
2017 _fullscreen = _cocoa_video_data.fullscreen; |
2002 _fullscreen = _cocoa_video_data.fullscreen; |
2018 } |
2003 } |
2019 |
2004 |