X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fsdl%2Fg_system.pas;h=cc8704c9713e76700e0da37c4cdc14c45f9d3d2f;hb=e84299fd3f1bf3f58e7aeddc017d2b6dc835f676;hp=0dee147df9240f2a07624145dc63a074bb8a4c1b;hpb=4d3cccccb71233b7d4b88db73a402ca03838640d;p=d2df-sdl.git diff --git a/src/game/sdl/g_system.pas b/src/game/sdl/g_system.pas index 0dee147..cc8704c 100644 --- a/src/game/sdl/g_system.pas +++ b/src/game/sdl/g_system.pas @@ -40,8 +40,11 @@ interface implementation uses - {$IFDEF DARWIN} + {$IF DEFINED(DARWIN) OR DEFINED(MACOS)} Keyboards, Events, + {$IFDEF CPU64} + {$linkframework Carbon} + {$ENDIF} {$ENDIF} SysUtils, SDL, Math, {$INCLUDE ../nogl/noGLuses.inc} @@ -49,11 +52,12 @@ implementation g_options, g_window, g_console, g_game, g_menu, g_gui, g_main, g_basic; const - GameTitle = 'Doom 2D: Forever (SDL 1.2, %s)'; + GameTitle = 'Doom 2D: Forever (SDL 1.2, %s, %s)'; var userResize: Boolean; modeResize: Integer; + useScancodes: Boolean; screen: PSDL_Surface; JoystickHandle: array [0..e_MaxJoys - 1] of PSDL_Joystick; JoystickHatState: array [0..e_MaxJoys - 1, 0..e_MaxJoyHats - 1, HAT_LEFT..HAT_DOWN] of Boolean; @@ -74,12 +78,22 @@ implementation (* --------- Graphics --------- *) function LoadGL: Boolean; + {$IFNDEF NOGL_INIT} + var + ltmp: Integer; + {$ENDIF} begin result := true; {$IFDEF NOGL_INIT} nogl_Init; if glRenderToFBO and (not nogl_ExtensionSupported('GL_OES_framebuffer_object')) then {$ELSE} + if SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, @ltmp) = 0 then + begin + e_LogWritefln('stencil buffer size: %s', [ltmp]); + gwin_has_stencil := (ltmp > 0); + end; + if glRenderToFBO and (not Load_GL_ARB_framebuffer_object) then {$ENDIF} begin @@ -127,13 +141,21 @@ implementation g_Game_ClearLoading; end; + function GetDriver (): AnsiString; + var buf: array [0..31] of AnsiChar; + begin + buf := ''; + SDL_VideoDriverName(buf, Length(buf)); + result := AnsiString(buf); + end; + function GetTitle (): AnsiString; var info: AnsiString; begin info := g_GetBuildHash(false); if info = 'custom build' then info := info + ' by ' + g_GetBuilderName() + ' ' + GAME_BUILDDATE + ' ' + GAME_BUILDTIME; - result := Format(GameTitle, [info]); + result := Format(GameTitle, [GetDriver(), info]); end; function InitWindow (w, h, bpp: Integer; fullScreen: Boolean): Boolean; @@ -348,7 +370,26 @@ implementation (* --------- Input --------- *) -{$IFDEF DARWIN} +{$IF DEFINED(DARWIN) OR DEFINED(MACOS)} + var + IsMacPlatform: Boolean; + + function IsMacModSym (sym: Integer): Boolean; + begin + case sym of + SDLK_NUMLOCK, + SDLK_CAPSLOCK, + SDLK_RCTRL, SDLK_LCTRL, + SDLK_RSHIFT, SDLK_LSHIFT, + SDLK_RALT, SDLK_LALT, + SDLK_RSUPER, SDLK_LSUPER, + SDLK_RMETA, SDLK_LMETA: + result := true; + otherwise + result := false; + end; + end; + function Mac2Stub (scancode: Integer): Integer; begin (* SDL 2 swap tilda/grave and paragraph/plus-minus buttons on ISO keyboards *) @@ -528,8 +569,8 @@ implementation SDLK_LCTRL: x := IK_CTRL; SDLK_RCTRL: x := IK_RCTRL; SDLK_RALT: x := IK_RALT; - SDLK_LSUPER, SDLK_LMETA: x := IK_WIN; - SDLK_RSUPER, SDLK_RMETA: x := IK_RWIN; + SDLK_LSUPER: x := IK_WIN; + SDLK_RSUPER: x := IK_RWIN; SDLK_MENU: x := IK_MENU; SDLK_PRINT: x := IK_PRINTSCR; SDLK_SCROLLOCK: x := IK_SCROLLLOCK; @@ -581,9 +622,14 @@ implementation var down, repeated: Boolean; key: Integer; ch: Char; begin key := IK_INVALID; - {$IFDEF DARWIN} - key := Mac2Stub(ev.keysym.scancode); - {$ENDIF} + if useScancodes then + begin + {$IF DEFINED(DARWIN) OR DEFINED(MACOS)} + if IsMacPlatform then + if IsMacModSym(ev.keysym.sym) = false then + key := Mac2Stub(ev.keysym.scancode); + {$ENDIF} + end; if key = IK_INVALID then key := Key2Stub(ev.keysym.sym); down := (ev.type_ = SDL_KEYDOWN); @@ -643,7 +689,7 @@ implementation (* --------- Init --------- *) procedure sys_Init; - var flags: Uint32; i: Integer; + var flags: Uint32; i: Integer; name: AnsiString; begin e_WriteLog('Init SDL', TMsgType.Notify); flags := SDL_INIT_VIDEO or SDL_INIT_AUDIO or @@ -651,6 +697,11 @@ implementation (*or SDL_INIT_NOPARACHUTE*); if SDL_Init(flags) <> 0 then raise Exception.Create('SDL: Init failed: ' + SDL_GetError); + name := GetDriver(); + e_LogWritefln('SDL: Video Driver "%s"', [name]); + {$IF DEFINED(DARWIN) OR DEFINED(MACOS)} + IsMacPlatform := (name = 'Quartz') or (name = 'toolbox') or (name = 'DSp'); + {$ENDIF} SDL_EnableUNICODE(1); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); for i := 0 to e_MaxJoys - 1 do @@ -675,6 +726,8 @@ initialization (* window resize are broken both on linux and osx, so disabled by default *) conRegVar('sdl_allow_resize', @userResize, 'allow to resize window by user', 'allow to resize window by user'); conRegVar('sdl_resize_action', @modeResize, 'set window resize mode (0: ignore, 1: change, 2: reset)', ''); + conRegVar('sdl_use_scancodes', @useScancodes, 'use platform-specific scancodes when possible', ''); userResize := false; modeResize := 0; + useScancodes := true; end.