diff --git a/src/game/g_window.pas b/src/game/g_window.pas
index a40441b492a7d6fee0db0eb2a6c206aafb031e3f..d790c4f852c9f468bd51c39ba4a9fd1b221faa20 100644 (file)
--- a/src/game/g_window.pas
+++ b/src/game/g_window.pas
function GetDisplayModes (dbpp: LongWord; var selres: LongWord): SSArray;
function g_Window_SetDisplay (preserveGL: Boolean=false): Boolean;
function g_Window_SetSize (w, h: Word; fullscreen: Boolean): Boolean;
function GetDisplayModes (dbpp: LongWord; var selres: LongWord): SSArray;
function g_Window_SetDisplay (preserveGL: Boolean=false): Boolean;
function g_Window_SetSize (w, h: Word; fullscreen: Boolean): Boolean;
+procedure g_SetVSync (vsync: Boolean);
procedure ProcessLoading (forceUpdate: Boolean=false);
procedure ProcessLoading (forceUpdate: Boolean=false);
gwin_has_stencil: Boolean = false;
gwin_k8_enable_light_experiments: Boolean = false;
g_dbg_aimline_on: Boolean = false;
gwin_has_stencil: Boolean = false;
gwin_k8_enable_light_experiments: Boolean = false;
g_dbg_aimline_on: Boolean = false;
+ g_dbg_input: Boolean = False;
implementation
uses
{$IFDEF WINDOWS}Windows,{$ENDIF}
implementation
uses
{$IFDEF WINDOWS}Windows,{$ENDIF}
- SysUtils, Classes, MAPDEF,
- SDL2, GL, GLExt, e_graphics, e_log, e_texture, g_main,
+{$INCLUDE ../nogl/noGLuses.inc}
+{$IFDEF ENABLE_HOLMES}
+ g_holmes, sdlcarcass, fui_ctls,
+{$ENDIF}
+ SysUtils, Classes, MAPDEF, Math,
+ SDL2, e_graphics, e_log, e_texture, g_main,
g_console, e_input, g_options, g_game,
g_basic, g_textures, e_sound, g_sound, g_menu, ENet, g_net,
g_console, e_input, g_options, g_game,
g_basic, g_textures, e_sound, g_sound, g_menu, ENet, g_net,
- g_map, g_gfx, g_monsters, g_holmes, xprofiler,
- sdlcarcass, fui_ctls;
+ g_map, g_gfx, g_monsters, xprofiler,
+ g_touch, g_gui;
const
const
flag: Boolean;
{$IF not DEFINED(HEADLESS)}
wTitle: PChar = nil;
flag: Boolean;
{$IF not DEFINED(HEADLESS)}
wTitle: PChar = nil;
+ wasFullscreen: Boolean = true; // so we need to recreate the window
{$ENDIF}
wNeedTimeReset: Boolean = false;
wMinimized: Boolean = false;
{$ENDIF}
wNeedTimeReset: Boolean = false;
wMinimized: Boolean = false;
+ wMaximized: Boolean = false;
wLoadingProgress: Boolean = false;
wLoadingQuit: Boolean = false;
{$IFNDEF WINDOWS}
ticksOverflow: Int64 = -1;
lastTicks: Uint32 = 0; // to detect overflow
{$ENDIF}
wLoadingProgress: Boolean = false;
wLoadingQuit: Boolean = false;
{$IFNDEF WINDOWS}
ticksOverflow: Int64 = -1;
lastTicks: Uint32 = 0; // to detect overflow
{$ENDIF}
-
+ 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;
+ JoystickZeroAxes: array [0..e_MaxJoys - 1, 0..e_MaxJoyAxes - 1] of Integer;
procedure KillGLWindow (preserveGL: Boolean);
begin
procedure KillGLWindow (preserveGL: Boolean);
begin
+{$IFDEF ENABLE_HOLMES}
if (h_GL <> nil) and (not preserveGL) then begin if (assigned(oglDeinitCB)) then oglDeinitCB(); end;
if (h_GL <> nil) and (not preserveGL) then begin if (assigned(oglDeinitCB)) then oglDeinitCB(); end;
+{$ENDIF}
if (h_Wnd <> nil) then SDL_DestroyWindow(h_Wnd);
if (h_Wnd <> nil) then SDL_DestroyWindow(h_Wnd);
- if (h_GL <> nil) and (not preserveGL) then SDL_GL_DeleteContext(h_GL);
+ if (h_GL <> nil) and (not preserveGL) then
+ begin
+
+{$IFDEF USE_NANOGL}
+ nanoGL_Destroy;
+{$ENDIF}
+
+{$IFDEF USE_NOGL}
+ nogl_Quit;
+{$ENDIF}
+
+ SDL_GL_DeleteContext(h_GL);
+ end;
h_Wnd := nil;
if (not preserveGL) then h_GL := nil;
end;
h_Wnd := nil;
if (not preserveGL) then h_GL := nil;
end;
e_WriteLog('Setting display mode...', TMsgType.Notify);
e_WriteLog('Setting display mode...', TMsgType.Notify);
- wFlags := SDL_WINDOW_OPENGL; // or SDL_WINDOW_RESIZABLE;
- if gFullscreen then wFlags := wFlags or SDL_WINDOW_FULLSCREEN or SDL_WINDOW_BORDERLESS else wFlags := wFlags or SDL_WINDOW_RESIZABLE;
- //if gWinMaximized then wFlags := wFlags or SDL_WINDOW_MAXIMIZED;
+ wFlags := SDL_WINDOW_OPENGL {or SDL_WINDOW_RESIZABLE};
+ if gFullscreen then wFlags := wFlags {or SDL_WINDOW_FULLSCREEN} else wFlags := wFlags or SDL_WINDOW_RESIZABLE;
+ if (not gFullscreen) and (not preserveGL) and gWinMaximized then wFlags := wFlags or SDL_WINDOW_MAXIMIZED else gWinMaximized := false;
if gFullscreen then
begin
if gFullscreen then
begin
end;
end;
end;
end;
- KillGLWindow(preserveGL);
-
- h_Wnd := SDL_CreateWindow(PChar(wTitle), gWinRealPosX, gWinRealPosY, gScreenWidth, gScreenHeight, wFlags);
- if (h_Wnd = nil) then exit;
+ if (preserveGL) and (h_Wnd <> nil) and (not gFullscreen) and (not wasFullscreen) then
+ begin
+ //SDL_SetWindowMaximumSize(h_Wnd, gScreenWidth, gScreenHeight);
+ //SDL_SetWindowDisplayMode(h_Wnd, @cmode);
+ if (wMaximized) then SDL_RestoreWindow(h_Wnd);
+ wMaximized := false;
+ gWinMaximized := false;
+ SDL_SetWindowSize(h_Wnd, gScreenWidth, gScreenHeight);
+ //SDL_SetWindowFullscreen(h_Wnd, SDL_WINDOW_FULLSCREEN);
+ //SDL_SetWindowFullscreen(h_Wnd, 0);
+ end
+ else
+ begin
+ KillGLWindow(preserveGL);
+ h_Wnd := SDL_CreateWindow(PChar(wTitle), gWinRealPosX, gWinRealPosY, gScreenWidth, gScreenHeight, wFlags);
+ if gFullscreen then
+ SDL_SetWindowFullscreen(h_Wnd, SDL_WINDOW_FULLSCREEN);
+ if (h_Wnd = nil) then exit;
+ end;
+ wasFullscreen := gFullscreen;
SDL_GL_MakeCurrent(h_Wnd, h_GL);
SDL_ShowCursor(SDL_DISABLE);
SDL_GL_MakeCurrent(h_Wnd, h_GL);
SDL_ShowCursor(SDL_DISABLE);
+ if (h_GL <> nil) then g_SetVSync(gVSync);
if (gFullscreen) then
begin
nw := 0;
if (gFullscreen) then
begin
nw := 0;
e_WriteLog('SDL: fullscreen window got invalid size: '+IntToStr(nw)+'x'+IntToStr(nh), TMsgType.Notify);
end;
end;
e_WriteLog('SDL: fullscreen window got invalid size: '+IntToStr(nw)+'x'+IntToStr(nh), TMsgType.Notify);
end;
end;
- fuiScrWdt := gScreenWidth;
- fuiScrHgt := gScreenHeight;
- if (h_GL <> nil) and (not preserveGL) then begin if (assigned(oglInitCB)) then oglInitCB(); end;
+
+ {$IFDEF ENABLE_HOLMES}
+ fuiScrWdt := gScreenWidth;
+ fuiScrHgt := gScreenHeight;
+ if (h_GL <> nil) and (not preserveGL) then begin if (assigned(oglInitCB)) then oglInitCB(); end;
+ {$ENDIF}
{$ENDIF}
result := true;
{$ENDIF}
result := true;
end;
end;
-procedure ChangeWindowSize ();
+procedure ChangeWindowSize (requested: Boolean);
begin
begin
+ e_LogWritefln(' ChangeWindowSize: (ws=%dx%d) (ss=%dx%d)', [gWinSizeX, gWinSizeY, gScreenWidth, gScreenHeight]);
gWinSizeX := gScreenWidth;
gWinSizeY := gScreenHeight;
{$IF not DEFINED(HEADLESS)}
gWinSizeX := gScreenWidth;
gWinSizeY := gScreenHeight;
{$IF not DEFINED(HEADLESS)}
- fuiScrWdt := gScreenWidth;
- fuiScrHgt := gScreenHeight;
+ {$IFDEF ENABLE_HOLMES}
+ fuiScrWdt := gScreenWidth;
+ fuiScrHgt := gScreenHeight;
+ {$ENDIF}
e_ResizeWindow(gScreenWidth, gScreenHeight);
g_Game_SetupScreenSize();
e_ResizeWindow(gScreenWidth, gScreenHeight);
g_Game_SetupScreenSize();
- g_Menu_Reset();
+ {$IF DEFINED(ANDROID)}
+ (* This will fix menu reset on keyboard showing *)
+ if requested then
+ g_Menu_Reset;
+ {$ELSE}
+ g_Menu_Reset;
+ {$ENDIF}
g_Game_ClearLoading();
{$ENDIF}
end;
g_Game_ClearLoading();
{$ENDIF}
end;
if result then
begin
g_Window_SetDisplay(preserve);
if result then
begin
g_Window_SetDisplay(preserve);
- ChangeWindowSize();
+ ChangeWindowSize(true);
end;
{$ENDIF}
end;
end;
{$ENDIF}
end;
SDL_WINDOWEVENT_RESIZED:
begin
SDL_WINDOWEVENT_RESIZED:
begin
- gScreenWidth := ev.data1;
- gScreenHeight := ev.data2;
- ChangeWindowSize();
+ e_LogWritefln('Resize: (os=%dx%d) (ns=%dx%d)', [gScreenWidth, gScreenHeight, Integer(ev.data1), Integer(ev.data2)]);
+ {if (gFullscreen) then
+ begin
+ e_LogWriteln(' fullscreen fix applied.');
+ if (gScreenWidth <> ev.data1) or (gScreenHeight <> ev.data2) then
+ begin
+ SDL_SetWindowSize(h_Wnd, gScreenWidth, gScreenHeight);
+ end;
+ end
+ else}
+ begin
+ gScreenWidth := ev.data1;
+ gScreenHeight := ev.data2;
+ end;
+ ChangeWindowSize(false);
SwapBuffers();
if g_debug_WinMsgs then
begin
SwapBuffers();
if g_debug_WinMsgs then
begin
SDL_WINDOWEVENT_MAXIMIZED:
begin
SDL_WINDOWEVENT_MAXIMIZED:
begin
+ wMaximized := true;
if wMinimized then
begin
e_ResizeWindow(gScreenWidth, gScreenHeight);
wMinimized := false;
wActivate := true;
end;
if wMinimized then
begin
e_ResizeWindow(gScreenWidth, gScreenHeight);
wMinimized := false;
wActivate := true;
end;
- if not gWinMaximized then
+ if (not gWinMaximized) and (not gFullscreen) then
begin
gWinMaximized := true;
if g_debug_WinMsgs then
begin
gWinMaximized := true;
if g_debug_WinMsgs then
SDL_WINDOWEVENT_RESTORED:
begin
SDL_WINDOWEVENT_RESTORED:
begin
+ wMaximized := false;
if wMinimized then
begin
e_ResizeWindow(gScreenWidth, gScreenHeight);
wMinimized := false;
wActivate := true;
end;
if wMinimized then
begin
e_ResizeWindow(gScreenWidth, gScreenHeight);
wMinimized := false;
wActivate := true;
end;
- if gWinMaximized then gWinMaximized := false;
+ gWinMaximized := false;
if g_debug_WinMsgs then
begin
g_Console_Add('Now restored');
if g_debug_WinMsgs then
begin
g_Console_Add('Now restored');
if gWinActive then
begin
e_WriteLog('deactivating window', TMsgType.Notify);
if gWinActive then
begin
e_WriteLog('deactivating window', TMsgType.Notify);
- e_EnableInput := false;
- e_ClearInputBuffer();
+ e_UnpressAllKeys;
if gMuteWhenInactive then
begin
if gMuteWhenInactive then
begin
gWinActive := false;
gWinActive := false;
- if assigned(winBlurCB) then winBlurCB();
+ {$IFDEF ENABLE_HOLMES}
+ if assigned(winBlurCB) then winBlurCB();
+ {$ENDIF}
end;
end
else if wActivate then
end;
end
else if wActivate then
if not gWinActive then
begin
//e_WriteLog('activating window', MSG_NOTIFY);
if not gWinActive then
begin
//e_WriteLog('activating window', MSG_NOTIFY);
- e_EnableInput := true;
if gMuteWhenInactive then
begin
if gMuteWhenInactive then
begin
end;
gWinActive := true;
end;
gWinActive := true;
- if assigned(winFocusCB) then winFocusCB();
+
+ {$IFDEF ENABLE_HOLMES}
+ if assigned(winFocusCB) then winFocusCB();
+ {$ENDIF}
end;
end;
end;
end;
end;
end;
function EventHandler (var ev: TSDL_Event): Boolean;
var
function EventHandler (var ev: TSDL_Event): Boolean;
var
- key, keychr: Word;
+ key, keychr, minuskey: Word;
uc: UnicodeChar;
down: Boolean;
uc: UnicodeChar;
down: Boolean;
+ i: Integer;
+ hat: array [HAT_LEFT..HAT_DOWN] of Boolean;
begin
result := false;
begin
result := false;
SDL_KEYDOWN, SDL_KEYUP:
begin
key := ev.key.keysym.scancode;
SDL_KEYDOWN, SDL_KEYUP:
begin
key := ev.key.keysym.scancode;
+ if key = SDL_SCANCODE_AC_BACK then
+ key := SDL_SCANCODE_ESCAPE;
down := (ev.type_ = SDL_KEYDOWN);
down := (ev.type_ = SDL_KEYDOWN);
- {$IF not DEFINED(HEADLESS)}
+ {$IF not DEFINED(HEADLESS) and DEFINED(ENABLE_HOLMES)}
if fuiOnSDLEvent(ev) then
begin
// event eaten, but...
if fuiOnSDLEvent(ev) then
begin
// event eaten, but...
exit;
end;
{$ENDIF}
exit;
end;
{$ENDIF}
- if down then KeyPress(key);
+ if ev.key._repeat = 0 then
+ begin
+ if g_dbg_input then
+ e_LogWritefln('Input Debug: keysym, press=%s, scancode=%s', [down, key]);
+ e_KeyUpDown(key, down);
+ g_Console_ProcessBind(key, down);
+ end
+ else if gConsoleShow or gChatShow or (g_ActiveWindow <> nil) then
+ begin
+ // key repeat in menus and shit
+ KeyPress(key);
+ end;
+ end;
+
+ SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP:
+ if (ev.jbutton.which < e_MaxJoys) and (ev.jbutton.button < e_MaxJoyBtns) then
+ begin
+ key := e_JoyButtonToKey(ev.jbutton.which, ev.jbutton.button);
+ down := ev.type_ = SDL_JOYBUTTONDOWN;
+ if g_dbg_input then
+ e_LogWritefln('Input Debug: jbutton, joy=%s, button=%s, keycode=%s, press=%s', [ev.jbutton.which, ev.jbutton.button, key, down]);
e_KeyUpDown(key, down);
e_KeyUpDown(key, down);
+ g_Console_ProcessBind(key, down);
+ end
+ else
+ begin
+ if g_dbg_input then
+ begin
+ down := ev.type_ = SDL_JOYBUTTONDOWN;
+ e_LogWritefln('Input Debug: NOT IN RANGE! jbutton, joy=%s, button=%s, press=%s', [ev.jbutton.which, ev.jbutton.button, down])
+ end
+ end;
+
+ SDL_JOYAXISMOTION:
+ if (ev.jaxis.which < e_MaxJoys) and (ev.jaxis.axis < e_MaxJoyAxes) then
+ begin
+ key := e_JoyAxisToKey(ev.jaxis.which, ev.jaxis.axis, AX_PLUS);
+ minuskey := e_JoyAxisToKey(ev.jaxis.which, ev.jaxis.axis, AX_MINUS);
+
+ if g_dbg_input then
+ e_LogWritefln('Input Debug: jaxis, joy=%s, axis=%s, value=%s, zeroaxes=%s, deadzone=%s', [ev.jaxis.which, ev.jaxis.axis, ev.jaxis.value, JoystickZeroAxes[ev.jaxis.which, ev.jaxis.axis], e_JoystickDeadzones[ev.jaxis.which]]);
+
+ if ev.jaxis.value < JoystickZeroAxes[ev.jaxis.which, ev.jaxis.axis] - e_JoystickDeadzones[ev.jaxis.which] then
+ begin
+ if (e_KeyPressed(key)) then
+ begin
+ e_KeyUpDown(key, False);
+ g_Console_ProcessBind(key, False);
+ end;
+ e_KeyUpDown(minuskey, True);
+ g_Console_ProcessBind(minuskey, True);
+ end
+ else if ev.jaxis.value > JoystickZeroAxes[ev.jaxis.which, ev.jaxis.axis] + e_JoystickDeadzones[ev.jaxis.which] then
+ begin
+ if (e_KeyPressed(minuskey)) then
+ begin
+ e_KeyUpDown(minuskey, False);
+ g_Console_ProcessBind(minuskey, False);
+ end;
+ e_KeyUpDown(key, True);
+ g_Console_ProcessBind(key, True);
+ end
+ else
+ begin
+ if (e_KeyPressed(minuskey)) then
+ begin
+ e_KeyUpDown(minuskey, False);
+ g_Console_ProcessBind(minuskey, False);
+ end;
+ if (e_KeyPressed(key)) then
+ begin
+ e_KeyUpDown(key, False);
+ g_Console_ProcessBind(key, False);
+ end;
+ end;
+ end
+ else
+ begin
+ if g_dbg_input then
+ e_LogWritefln('Input Debug: NOT IN RANGE! jaxis, joy=%s, axis=%s, value=%s, zeroaxes=%s, deadzone=%s', [ev.jaxis.which, ev.jaxis.axis, ev.jaxis.value, JoystickZeroAxes[ev.jaxis.which, ev.jaxis.axis], e_JoystickDeadzones[ev.jaxis.which]])
+ end;
+
+ SDL_JOYHATMOTION:
+ if (ev.jhat.which < e_MaxJoys) and (ev.jhat.hat < e_MaxJoyHats) then
+ begin
+ if g_dbg_input then
+ e_LogWritefln('Input Debug: jhat, joy=%s, hat=%s, value=%s', [ev.jhat.which, ev.jhat.hat, ev.jhat.value]);
+ hat[HAT_UP] := LongBool(ev.jhat.value and SDL_HAT_UP);
+ hat[HAT_DOWN] := LongBool(ev.jhat.value and SDL_HAT_DOWN);
+ hat[HAT_LEFT] := LongBool(ev.jhat.value and SDL_HAT_LEFT);
+ hat[HAT_RIGHT] := LongBool(ev.jhat.value and SDL_HAT_RIGHT);
+ for i := HAT_LEFT to HAT_DOWN do
+ begin
+ if JoystickHatState[ev.jhat.which, ev.jhat.hat, i] <> hat[i] then
+ begin
+ down := hat[i];
+ key := e_JoyHatToKey(ev.jhat.which, ev.jhat.hat, i);
+ e_KeyUpDown(key, down);
+ g_Console_ProcessBind(key, down);
+ end
+ end;
+ JoystickHatState[ev.jhat.which, ev.jhat.hat] := hat
+ end
+ else
+ begin
+ if g_dbg_input then
+ e_LogWritefln('Input Debug: NOT IN RANGE! jhat, joy=%s, hat=%s, value=%s', [ev.jhat.which, ev.jhat.hat, ev.jhat.value])
+ end;
+
+ SDL_JOYDEVICEADDED:
+ if (ev.jdevice.which < e_MaxJoys) then
+ begin
+ JoystickHandle[ev.jdevice.which] := SDL_JoystickOpen(ev.jdevice.which);
+ if JoystickHandle[ev.jdevice.which] <> nil then
+ begin
+ e_LogWritefln('Added Joystick %s', [ev.jdevice.which]);
+ e_JoystickAvailable[ev.jdevice.which] := True;
+ for i := 0 to Min(SDL_JoystickNumAxes(JoystickHandle[ev.jdevice.which]), e_MaxJoyAxes) - 1 do
+ JoystickZeroAxes[ev.jdevice.which, i] := SDL_JoystickGetAxis(JoystickHandle[ev.jdevice.which], i)
+ end
+ else
+ e_LogWritefln('Warning! Failed to open Joystick %s', [ev.jdevice.which])
+ end
+ else
+ begin
+ e_LogWritefln('Warning! Added Joystick %s, but we support only <= %s', [ev.jdevice.which, e_MaxJoys])
end;
end;
- {$IF not DEFINED(HEADLESS)}
+ SDL_JOYDEVICEREMOVED:
+ begin
+ e_LogWritefln('Removed Joystick %s', [ev.jdevice.which]);
+ if (ev.jdevice.which < e_MaxJoys) then
+ begin
+ e_JoystickAvailable[ev.jdevice.which] := False;
+ if JoystickHandle[ev.jdevice.which] <> nil then
+ SDL_JoystickClose(JoystickHandle[ev.jdevice.which]);
+ JoystickHandle[ev.jdevice.which] := nil
+ end
+ end;
+
+ {$IF not DEFINED(HEADLESS) and DEFINED(ENABLE_HOLMES)}
SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONUP, SDL_MOUSEWHEEL, SDL_MOUSEMOTION:
fuiOnSDLEvent(ev);
{$ENDIF}
SDL_TEXTINPUT:
begin
SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONUP, SDL_MOUSEWHEEL, SDL_MOUSEMOTION:
fuiOnSDLEvent(ev);
{$ENDIF}
SDL_TEXTINPUT:
begin
+ if g_dbg_input then
+ e_LogWritefln('Input Debug: text, text=%s', [ev.text.text]);
Utf8ToUnicode(@uc, PChar(ev.text.text), 1);
keychr := Word(uc);
if (keychr > 127) then keychr := Word(wchar2win(WideChar(keychr)));
if (keychr > 0) and (keychr <= 255) then CharPress(AnsiChar(keychr));
end;
Utf8ToUnicode(@uc, PChar(ev.text.text), 1);
keychr := Word(uc);
if (keychr > 127) then keychr := Word(wchar2win(WideChar(keychr)));
if (keychr > 0) and (keychr <= 255) then CharPress(AnsiChar(keychr));
end;
+ SDL_FINGERMOTION, SDL_FINGERDOWN, SDL_FINGERUP:
+ g_Touch_HandleEvent(ev.tfinger);
+
// other key presses and joysticks are handled in e_input
end;
end;
// other key presses and joysticks are handled in e_input
end;
end;
{$IF not DEFINED(HEADLESS)}
h_GL := SDL_GL_CreateContext(h_Wnd);
if (h_GL = nil) then exit;
{$IF not DEFINED(HEADLESS)}
h_GL := SDL_GL_CreateContext(h_Wnd);
if (h_GL = nil) then exit;
- fuiScrWdt := gScreenWidth;
- fuiScrHgt := gScreenHeight;
- if (assigned(oglInitCB)) then oglInitCB();
+ {$IFDEF ENABLE_HOLMES}
+ fuiScrWdt := gScreenWidth;
+ fuiScrHgt := gScreenHeight;
+ {$ENDIF}
+ SDL_GL_MakeCurrent(h_Wnd, h_GL);
+{$IFDEF USE_NANOGL}
+ if nanoGL_Init() = 0 then
+ begin
+ KillGLWindow(false);
+ e_WriteLog('nanoGL initialization error', TMsgType.Fatal);
+ exit;
+ end;
+{$ENDIF}
+{$IFDEF USE_NOGL}
+ nogl_Init;
+{$ENDIF}
+ {$IFDEF ENABLE_HOLMES}
+ if (assigned(oglInitCB)) then oglInitCB();
+ {$ENDIF}
+ if (h_GL <> nil) then g_SetVSync(gVSync);
{$ENDIF}
e_ResizeWindow(gScreenWidth, gScreenHeight);
{$ENDIF}
e_ResizeWindow(gScreenWidth, gScreenHeight);
procedure ProcessLoading (forceUpdate: Boolean=false);
var
ev: TSDL_Event;
procedure ProcessLoading (forceUpdate: Boolean=false);
var
ev: TSDL_Event;
- ID: LongWord;
stt: UInt64;
begin
FillChar(ev, sizeof(ev), 0);
stt: UInt64;
begin
FillChar(ev, sizeof(ev), 0);
EventHandler(ev);
if (ev.type_ = SDL_QUITEV) then break;
end;
EventHandler(ev);
if (ev.type_ = SDL_QUITEV) then break;
end;
- e_PollJoysticks();
+ //e_PollJoysticks();
if (ev.type_ = SDL_QUITEV) or (gExit = EXIT_QUIT) then
begin
if (ev.type_ = SDL_QUITEV) or (gExit = EXIT_QUIT) then
begin
if forceUpdate then
begin
if forceUpdate then
begin
- if g_Texture_Get('INTER', ID) then
- begin
- e_DrawSize(ID, 0, 0, 0, false, false, gScreenWidth, gScreenHeight);
- e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
- end
- else
- begin
- e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
- end;
+ DrawMenuBackground('INTER');
+ e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
DrawLoadingStat();
SwapBuffers();
DrawLoadingStat();
SwapBuffers();
result := EventHandler(ev);
if (ev.type_ = SDL_QUITEV) then exit;
end;
result := EventHandler(ev);
if (ev.type_ = SDL_QUITEV) then exit;
end;
- e_PollJoysticks();
+ //e_PollJoysticks();
end;
end;
end;
end;
-procedure InitOpenGL (vsync: Boolean);
+procedure g_SetVSync (vsync: Boolean);
{$IF not DEFINED(HEADLESS)}
var
v: Byte;
{$IF not DEFINED(HEADLESS)}
var
v: Byte;
begin
{$IF not DEFINED(HEADLESS)}
if vsync then v := 1 else v := 0;
begin
{$IF not DEFINED(HEADLESS)}
if vsync then v := 1 else v := 0;
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
- SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
- SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); // lights; it is enough to have 1-bit stencil buffer for lighting, but...
- SDL_GL_SetSwapInterval(v);
+ if (SDL_GL_SetSwapInterval(v) <> 0) then
+ begin
+ e_WriteLog('oops; can''t change vsync option, restart required', TMsgType.Warning);
+ end
+ else
+ begin
+ if vsync then e_WriteLog('VSync: ON', TMsgType.Notify) else e_WriteLog('VSync: OFF', TMsgType.Notify);
+ end;
+{$ENDIF}
+end;
+
+
+procedure InitOpenGL ();
+begin
+{$IF not DEFINED(HEADLESS)}
+ {$IFDEF USE_GLES1}
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
+ {$ELSE}
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
+ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+ SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); // lights; it is enough to have 1-bit stencil buffer for lighting, but...
+ {$ENDIF}
{$ENDIF}
end;
{$ENDIF}
end;
{$ENDIF}
arg: AnsiString;
mdfo: TStream;
{$ENDIF}
arg: AnsiString;
mdfo: TStream;
+ {$IFDEF ENABLE_HOLMES}
itmp: Integer;
valres: Word;
itmp: Integer;
valres: Word;
+ {$ENDIF}
begin
{$IFDEF HEADLESS}
e_NoGraphics := true;
{$ELSE}
begin
{$IFDEF HEADLESS}
e_NoGraphics := true;
{$ELSE}
- if (not g_holmes_imfunctional) then
- begin
- uiInitialize();
- uiContext.font := 'win14';
- end;
+ {$IFDEF ENABLE_HOLMES}
+ if (not g_holmes_imfunctional) then
+ begin
+ uiInitialize();
+ uiContext.font := 'win14';
+ end;
+ {$ENDIF}
{$ENDIF}
idx := 1;
{$ENDIF}
idx := 1;
if arg = '--no-particle-phys' then gpart_dbg_phys_enabled := false;
if arg = '--no-particle-physics' then gpart_dbg_phys_enabled := false;
if arg = '--no-particle-phys' then gpart_dbg_phys_enabled := false;
if arg = '--no-particle-physics' then gpart_dbg_phys_enabled := false;
+ if arg = '--debug-input' then g_dbg_input := True;
+
{.$IF DEFINED(D2F_DEBUG)}
if arg = '--aimline' then g_dbg_aimline_on := true;
{.$ENDIF}
{.$IF DEFINED(D2F_DEBUG)}
if arg = '--aimline' then g_dbg_aimline_on := true;
{.$ENDIF}
+{$IFDEF ENABLE_HOLMES}
if arg = '--holmes' then begin g_holmes_enabled := true; g_Game_SetDebugMode(); end;
if (arg = '--holmes-ui-scale') or (arg = '-holmes-ui-scale') then
if arg = '--holmes' then begin g_holmes_enabled := true; g_Game_SetDebugMode(); end;
if (arg = '--holmes-ui-scale') or (arg = '-holmes-ui-scale') then
Inc(idx);
end;
end;
Inc(idx);
end;
end;
+{$ENDIF}
if (arg = '--game-scale') or (arg = '-game-scale') then
begin
if (arg = '--game-scale') or (arg = '-game-scale') then
begin
end;
e_WriteLog('Initializing OpenGL', TMsgType.Notify);
end;
e_WriteLog('Initializing OpenGL', TMsgType.Notify);
- InitOpenGL(gVSync);
+ InitOpenGL();
e_WriteLog('Creating GL window', TMsgType.Notify);
if not CreateGLWindow(PChar(Format('Doom 2D: Forever %s', [GAME_VERSION]))) then
begin
result := 0;
e_WriteLog('Creating GL window', TMsgType.Notify);
if not CreateGLWindow(PChar(Format('Doom 2D: Forever %s', [GAME_VERSION]))) then
begin
result := 0;
+ e_WriteLog('Unable to create GL window: ' + SDL_GetError(), TMsgType.Fatal);
exit;
end;
exit;
end;
e_LogWritefln('stencil buffer size: %s', [ltmp]);
gwin_has_stencil := (ltmp > 0);
e_LogWritefln('stencil buffer size: %s', [ltmp]);
gwin_has_stencil := (ltmp > 0);
- if not glHasExtension('GL_ARB_texture_non_power_of_two') then
+ if glHasExtension('GL_ARB_texture_non_power_of_two') or
+ glHasExtension('GL_OES_texture_npot') then
begin
begin
- e_WriteLog('NPOT textures: NO', TMsgType.Warning);
- glLegacyNPOT := true;
+ e_WriteLog('NPOT textures: YES', TMsgType.Notify);
+ glLegacyNPOT := false;
end
else
begin
end
else
begin
- e_WriteLog('NPOT textures: YES', TMsgType.Notify);
- glLegacyNPOT := false;
+ e_WriteLog('NPOT textures: NO', TMsgType.Warning);
+ glLegacyNPOT := true;
end;
gwin_dump_extensions := false;
{$ENDIF}
end;
gwin_dump_extensions := false;
{$ENDIF}
end;
end;
+initialization
+ conRegVar('d_input', @g_dbg_input, '', '')
end.
end.