1 (* Copyright (C) DooM 2D:Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 {$INCLUDE ../shared/a_modes.inc}
24 function SDLMain(): Integer;
25 function GetTimer(): Int64;
26 procedure ResetTimer();
27 function CreateGLWindow(Title
: PChar): Boolean;
28 procedure KillGLWindow();
29 procedure PushExitEvent();
30 function ProcessMessage(): Boolean;
31 procedure ProcessLoading (forceUpdate
: Boolean=false);
32 procedure ReDrawWindow();
33 procedure SwapBuffers();
34 procedure Sleep(ms
: LongWord);
35 function GetDisplayModes(dBPP
: DWORD
; var SelRes
: DWORD
): SArray
;
36 function g_Window_SetDisplay(PreserveGL
: Boolean = False): Boolean;
37 function g_Window_SetSize(W
, H
: Word; FScreen
: Boolean): Boolean;
40 gwin_dump_extensions
: Boolean = false;
41 gwin_has_stencil
: Boolean = false;
42 gwin_k8_enable_light_experiments
: Boolean = false;
43 g_dbg_aimline_on
: Boolean = false;
49 {$IFDEF WINDOWS}Windows
,{$ENDIF}
50 SDL2
, GL
, GLExt
, e_graphics
, e_log
, g_main
,
51 g_console
, SysUtils
, e_input
, g_options
, g_game
,
52 g_basic
, g_textures
, e_sound
, g_sound
, g_menu
, ENet
, g_net
,
53 g_map
, g_gfx
, g_monsters
, g_holmes
, xprofiler
, utils
;
59 Time
, Time_Delta
, Time_Old
: Int64;
62 wNeedTimeReset
: Boolean = False;
63 //wWindowCreated: Boolean = False;
64 //wCursorShown: Boolean = False;
65 wMinimized
: Boolean = False;
66 //wNeedFree: Boolean = True;
67 wLoadingProgress
: Boolean = False;
68 wLoadingQuit
: Boolean = False;
69 {wWinPause: Byte = 0;}
71 ticksOverflow
: Int64 = -1;
72 lastTicks
: Uint32
= 0; // to detect overflow
74 curMsButState
: Word = 0;
79 function g_Window_SetDisplay(PreserveGL
: Boolean = False): Boolean;
81 mode
, cmode
: TSDL_DisplayMode
;
90 e_WriteLog('Setting display mode...', MSG_NOTIFY
);
92 wFlags
:= SDL_WINDOW_OPENGL
or SDL_WINDOW_RESIZABLE
;
93 if gFullscreen
then wFlags
:= wFlags
or SDL_WINDOW_FULLSCREEN
;
94 if gWinMaximized
then wFlags
:= wFlags
or SDL_WINDOW_MAXIMIZED
;
98 SDL_DestroyWindow(h_Wnd
);
104 mode
.w
:= gScreenWidth
;
105 mode
.h
:= gScreenHeight
;
107 mode
.refresh_rate
:= 0;
108 mode
.driverdata
:= nil;
109 if SDL_GetClosestDisplayMode(0, @mode
, @cmode
) = nil then
112 gScreenHeight
:= 600;
116 gScreenWidth
:= cmode
.w
;
117 gScreenHeight
:= cmode
.h
;
121 h_Wnd
:= SDL_CreateWindow(PChar(wTitle
), gWinRealPosX
, gWinRealPosY
, gScreenWidth
, gScreenHeight
, wFlags
);
122 if h_Wnd
= nil then Exit
;
124 SDL_GL_MakeCurrent(h_Wnd
, h_GL
);
125 SDL_ShowCursor(SDL_DISABLE
);
130 procedure ReShowCursor();
132 // TODO: what was this for?
135 function GetDisplayModes(dBPP
: DWORD
; var SelRes
: DWORD
): SArray
;
137 mode
: TSDL_DisplayMode
;
138 res
, i
, k
, n
, pw
, ph
: Integer;
140 SetLength(Result
, 0);
141 {$IFDEF HEADLESS}Exit
;{$ENDIF}
143 n
:= SDL_GetNumDisplayModes(0);
147 res
:= SDL_GetDisplayMode(0, i
, @mode
);
148 if res
< 0 then continue
;
149 if SDL_BITSPERPIXEL(mode
.format
) = gBPP
then continue
;
150 if (mode
.w
= pw
) and (mode
.h
= ph
) then continue
;
151 if (mode
.w
= gScreenWidth
) and (mode
.h
= gScreenHeight
) then
154 SetLength(Result
, k
);
155 Result
[k
-1] := IntToStr(mode
.w
) + 'x' + IntToStr(mode
.h
);
156 pw
:= mode
.w
; ph
:= mode
.h
159 e_WriteLog('SDL: Got ' + IntToStr(k
) + ' resolutions.', MSG_NOTIFY
);
162 procedure Sleep(ms
: LongWord);
167 procedure ChangeWindowSize();
169 gWinSizeX
:= gScreenWidth
;
170 gWinSizeY
:= gScreenHeight
;
171 {$IFDEF HEADLESS}Exit
;{$ENDIF}
172 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
173 g_Game_SetupScreenSize();
175 g_Game_ClearLoading();
176 g_Holmes_VidModeChanged();
179 function g_Window_SetSize(W
, H
: Word; FScreen
: Boolean): Boolean;
184 {$IFDEF HEADLESS}Exit
;{$ENDIF}
187 if (gScreenWidth
<> W
) or (gScreenHeight
<> H
) then
194 if gFullscreen
<> FScreen
then
197 gFullscreen
:= FScreen
;
203 g_Window_SetDisplay(Preserve
);
208 function WindowEventHandler(ev
: TSDL_WindowEvent
): Boolean;
210 wActivate
, wDeactivate
: Boolean;
214 wDeactivate
:= False;
217 SDL_WINDOWEVENT_MOVED
:
219 if not (gFullscreen
or gWinMaximized
) then
221 gWinRealPosX
:= ev
.data1
;
222 gWinRealPosY
:= ev
.data2
;
226 SDL_WINDOWEVENT_MINIMIZED
:
231 if not wMinimized
then
233 e_ResizeWindow(0, 0);
236 if g_debug_WinMsgs
then
238 g_Console_Add('Now minimized');
239 e_WriteLog('[DEBUG] WinMsgs: Now minimized', MSG_NOTIFY
);
245 SDL_WINDOWEVENT_RESIZED
:
249 gScreenWidth
:= ev
.data1
;
250 gScreenHeight
:= ev
.data2
;
253 if g_debug_WinMsgs
then
255 g_Console_Add('Resized to ' + IntToStr(ev
.data1
) + 'x' + IntToStr(ev
.data2
));
256 e_WriteLog('[DEBUG] WinMsgs: Resized to ' + IntToStr(ev
.data1
) + 'x' + IntToStr(ev
.data2
), MSG_NOTIFY
);
260 SDL_WINDOWEVENT_EXPOSED
:
263 SDL_WINDOWEVENT_MAXIMIZED
:
269 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
273 if not gWinMaximized
then
275 gWinMaximized
:= True;
276 if g_debug_WinMsgs
then
278 g_Console_Add('Now maximized');
279 e_WriteLog('[DEBUG] WinMsgs: Now maximized', MSG_NOTIFY
);
284 SDL_WINDOWEVENT_RESTORED
:
290 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
294 if gWinMaximized
then
295 gWinMaximized
:= False;
296 if g_debug_WinMsgs
then
298 g_Console_Add('Now restored');
299 e_WriteLog('[DEBUG] WinMsgs: Now restored', MSG_NOTIFY
);
303 SDL_WINDOWEVENT_FOCUS_GAINED
:
308 //e_WriteLog('window gained focus!', MSG_NOTIFY);
309 g_Holmes_WindowFocused();
312 SDL_WINDOWEVENT_FOCUS_LOST
:
318 //e_WriteLog('window lost focus!', MSG_NOTIFY);
319 g_Holmes_WindowBlured();
327 e_WriteLog('deactivating window', MSG_NOTIFY
);
328 e_EnableInput
:= False;
329 e_ClearInputBuffer();
331 if gMuteWhenInactive
then
333 //e_WriteLog('deactivating sounds', MSG_NOTIFY);
334 e_MuteChannels(True);
337 if g_debug_WinMsgs
then
339 g_Console_Add('Now inactive');
340 e_WriteLog('[DEBUG] WinMsgs: Now inactive', MSG_NOTIFY
);
346 else if wActivate
then
348 if not gWinActive
then
350 //e_WriteLog('activating window', MSG_NOTIFY);
351 e_EnableInput
:= True;
353 if gMuteWhenInactive
then
355 //e_WriteLog('activating sounds', MSG_NOTIFY);
356 e_MuteChannels(False);
359 if g_debug_WinMsgs
then
361 g_Console_Add('Now active');
362 e_WriteLog('[DEBUG] WinMsgs: Now active', MSG_NOTIFY
);
370 function EventHandler(ev
: TSDL_Event
): Boolean;
378 function buildBut (b
: Byte): Word;
382 SDL_BUTTON_LEFT
: result
:= result
or THMouseEvent
.Left
;
383 SDL_BUTTON_MIDDLE
: result
:= result
or THMouseEvent
.Middle
;
384 SDL_BUTTON_RIGHT
: result
:= result
or THMouseEvent
.Right
;
388 procedure updateKBState ();
393 kbstate
:= SDL_GetKeyboardState(nil);
394 if (kbstate
[SDL_SCANCODE_LCTRL
] <> 0) or (kbstate
[SDL_SCANCODE_RCTRL
] <> 0) then curKbState
:= curKbState
or THKeyEvent
.ModCtrl
;
395 if (kbstate
[SDL_SCANCODE_LALT
] <> 0) or (kbstate
[SDL_SCANCODE_RALT
] <> 0) then curKbState
:= curKbState
or THKeyEvent
.ModAlt
;
396 if (kbstate
[SDL_SCANCODE_LSHIFT
] <> 0) or (kbstate
[SDL_SCANCODE_RSHIFT
] <> 0) then curKbState
:= curKbState
or THKeyEvent
.ModShift
;
405 Result
:= WindowEventHandler(ev
.window
);
409 if gExit
<> EXIT_QUIT
then
411 if not wLoadingProgress
then
417 wLoadingQuit
:= True;
422 SDL_KEYDOWN
, SDL_KEYUP
:
424 key
:= ev
.key
.keysym
.scancode
;
425 if (g_holmes_enabled
) then
427 if (ev
.type_
= SDL_KEYDOWN
) then kbev
.kind
:= THKeyEvent
.Press
else kbev
.kind
:= THKeyEvent
.Release
;
428 kbev
.scan
:= ev
.key
.keysym
.scancode
;
429 kbev
.sym
:= ev
.key
.keysym
.sym
;
430 kbev
.bstate
:= curMsButState
;
431 kbev
.kstate
:= curKbState
;
432 {$IF not DEFINED(HEADLESS)}
433 if g_Holmes_keyEvent(kbev
) then
435 if (ev
.type_
<> SDL_KEYDOWN
) then e_KeyUpDown(ev
.key
.keysym
.scancode
, false);
440 if (ev
.type_
= SDL_KEYDOWN
) then KeyPress(key
);
441 e_KeyUpDown(ev
.key
.keysym
.scancode
, (ev
.type_
= SDL_KEYDOWN
));
444 {$IF not DEFINED(HEADLESS)}
445 SDL_MOUSEBUTTONDOWN
, SDL_MOUSEBUTTONUP
:
447 msev
.dx
:= ev
.button
.x
-curMsX
;
448 msev
.dy
:= ev
.button
.y
-curMsY
;
449 curMsX
:= ev
.button
.x
;
450 curMsY
:= ev
.button
.y
;
451 if (ev
.type_
= SDL_MOUSEBUTTONDOWN
) then msev
.kind
:= THMouseEvent
.Press
else msev
.kind
:= THMouseEvent
.Release
;
452 msev
.but
:= buildBut(ev
.button
.button
);
455 if (msev
.but
<> 0) then
457 // ev.button.clicks: Byte
458 if (ev
.type_
= SDL_MOUSEBUTTONDOWN
) then curMsButState
:= curMsButState
or msev
.but
else curMsButState
:= curMsButState
and (not msev
.but
);
459 msev
.bstate
:= curMsButState
;
460 msev
.kstate
:= curKbState
;
461 if (g_holmes_enabled
) then g_Holmes_mouseEvent(msev
);
466 if (ev
.wheel
.y
<> 0) then
469 msev
.dy
:= ev
.wheel
.y
;
470 msev
.kind
:= THMouseEvent
.Press
;
471 if (ev
.wheel
.y
< 0) then msev
.but
:= THMouseEvent
.WheelUp
else msev
.but
:= THMouseEvent
.WheelDown
;
474 msev
.bstate
:= curMsButState
;
475 msev
.kstate
:= curKbState
;
476 if (g_holmes_enabled
) then g_Holmes_mouseEvent(msev
);
481 msev
.dx
:= ev
.button
.x
-curMsX
;
482 msev
.dy
:= ev
.button
.y
-curMsY
;
483 curMsX
:= ev
.button
.x
;
484 curMsY
:= ev
.button
.y
;
485 msev
.kind
:= THMouseEvent
.Motion
;
489 msev
.bstate
:= curMsButState
;
490 msev
.kstate
:= curKbState
;
491 if (g_holmes_enabled
) then g_Holmes_mouseEvent(msev
);
497 Utf8ToUnicode(@uc
, PChar(ev
.text.text), 1);
499 if (keychr
> 127) then keychr
:= Word(wchar2win(WideChar(keychr
)));
500 CharPress(AnsiChar(keychr
));
503 // other key presses and joysticks are handled in e_input
507 procedure SwapBuffers();
509 {$IFDEF HEADLESS}Exit
;{$ENDIF}
510 SDL_GL_SwapWindow(h_Wnd
);
513 procedure KillGLWindow();
515 if h_Wnd
<> nil then SDL_DestroyWindow(h_Wnd
);
516 if h_GL
<> nil then SDL_GL_DeleteContext(h_GL
);
519 //wWindowCreated := False;
522 function CreateGLWindow(Title
: PChar): Boolean;
528 gWinSizeX
:= gScreenWidth
;
529 gWinSizeY
:= gScreenHeight
;
532 e_WriteLog('Creating window', MSG_NOTIFY
);
534 if not g_Window_SetDisplay() then
537 e_WriteLog('Window creation error (resolution not supported?)', MSG_FATALERROR
);
542 h_Gl
:= SDL_GL_CreateContext(h_Wnd
);
543 if h_Gl
= nil then Exit
;
545 //wWindowCreated := True;
547 e_ResizeWindow(gScreenWidth
, gScreenHeight
);
554 // windoze sux; in headless mode `GetTickCount()` (and SDL) returns shit
555 function GetTimer(): Int64;
559 QueryPerformanceFrequency(F
);
560 QueryPerformanceCounter(C
);
561 Result
:= Round(C
/F
*1000{000});
564 function GetTimer(): Int64;
569 t
:= SDL_GetTicks() {* 1000}; // TODO: do we really need microseconds here? k8: NOPE!
570 if ticksOverflow
= -1 then
577 if lastTicks
> t
then
579 // overflow, increment overflow ;-)
580 ticksOverflow
:= ticksOverflow
+(Int64($ffffffff)+Int64(1));
581 tt
:= (Int64($ffffffff)+Int64(1))+Int64(t
);
582 t
:= Uint32(tt
-lastTicks
);
586 result
:= ticksOverflow
+Int64(t
);
590 procedure ResetTimer();
592 wNeedTimeReset
:= True;
595 procedure PushExitEvent();
599 ev
.type_
:= SDL_QUITEV
;
605 prevLoadingUpdateTime
: UInt64 = 0;
607 procedure ProcessLoading (forceUpdate
: Boolean=false);
613 FillChar(ev
, SizeOf(ev
), 0);
614 //wNeedFree := False;
615 wLoadingProgress
:= True;
616 while SDL_PollEvent(@ev
) > 0 do
618 if (ev
.type_
= SDL_QUITEV
) then
623 if (ev
.type_
= SDL_QUITEV
) or (gExit
= EXIT_QUIT
) then
625 wLoadingProgress
:= False;
629 if not wMinimized
then
633 prevLoadingUpdateTime
:= curTimeMilli();
637 stt
:= curTimeMilli();
638 if (stt
< prevLoadingUpdateTime
) or (stt
-prevLoadingUpdateTime
>= 400) then
640 prevLoadingUpdateTime
:= stt
;
647 if g_Texture_Get('INTER', ID
) then
649 e_DrawSize(ID
, 0, 0, 0, False, False, gScreenWidth
, gScreenHeight
)
653 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
665 if NetMode
= NET_SERVER
then
671 if (NetMode
= NET_CLIENT
) and (NetState
<> NET_STATE_AUTH
) then g_Net_Client_UpdateWhileLoading();
673 wLoadingProgress
:= False;
676 function ProcessMessage(): Boolean;
682 FillChar(ev
, SizeOf(ev
), 0);
684 while SDL_PollEvent(@ev
) > 0 do
686 Result
:= EventHandler(ev
);
687 if ev
.type_
= SDL_QUITEV
then exit
;
691 Time_Delta
:= Time
- Time_Old
;
695 if wNeedTimeReset
then
697 Time_Delta
:= 28{(27777 div 1000)};
698 wNeedTimeReset
:= False;
701 g_Map_ProfilersBegin();
702 g_Mons_ProfilersBegin();
704 t
:= Time_Delta
div 28{(27777 div 1000)};
710 if NetMode
= NET_SERVER
then g_Net_Host_Update()
711 else if NetMode
= NET_CLIENT
then g_Net_Client_Update();
717 if NetMode
= NET_SERVER
then g_Net_Host_Update()
718 else if NetMode
= NET_CLIENT
then g_Net_Client_Update();
721 g_Map_ProfilersEnd();
722 g_Mons_ProfilersEnd();
730 if gExit
= EXIT_QUIT
then
736 // Âðåìÿ ïðåäûäóùåãî îáíîâëåíèÿ:
739 Time_Old
:= Time
- (Time_Delta
mod 28{(27777 div 1000)});
740 if (not wMinimized
) then
753 procedure ReDrawWindow
;
759 procedure InitOpenGL(VSync
: Boolean);
763 {$IFDEF HEADLESS}Exit
;{$ENDIF}
764 if VSync
then v
:= 1 else v
:= 0;
765 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION
, 2);
766 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION
, 1);
767 SDL_GL_SetAttribute(SDL_GL_RED_SIZE
, 8);
768 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE
, 8);
769 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE
, 8);
770 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE
, 16);
771 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER
, 1);
772 if gwin_k8_enable_light_experiments
then
774 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE
, 1); // lights; it is enough to have 1-bit stencil buffer for lighting
776 SDL_GL_SetSwapInterval(v
);
779 function glHasExtension (name
: AnsiString): Boolean;
784 extName
: ShortString;
787 if length(name
) = 0 then exit
;
788 exts
:= glGetString(GL_EXTENSIONS
);
789 if exts
= nil then exit
;
790 while (exts
[0] <> #0) and (exts
[0] = ' ') do Inc(exts
);
791 while exts
[0] <> #0 do
793 if gwin_dump_extensions
then
796 while (exts
[i
] <> #0) and (exts
[i
] <> ' ') do Inc(i
);
799 e_WriteLog('FUUUUUUUUUUUUU', MSG_WARNING
);
803 Move(exts
^, extName
[1], i
);
804 extName
[0] := Char(i
);
805 e_WriteLog(Format('EXT: %s', [extName
]), MSG_NOTIFY
);
809 for i
:= 0 to length(name
)-1 do
811 if exts
[i
] = #0 then begin found
:= false; break
; end;
812 if exts
[i
] <> name
[i
+1] then begin found
:= false; break
; end;
814 if found
and ((exts
[length(name
)] = #0) or (exts
[length(name
)] = ' ')) then begin result
:= true; exit
; end;
815 while (exts
[0] <> #0) and (exts
[0] <> ' ') do Inc(exts
);
816 while (exts
[0] <> #0) and (exts
[0] = ' ') do Inc(exts
);
820 function SDLMain(): Integer;
827 e_NoGraphics
:= True;
831 while (idx
<= ParamCount
) do
833 arg
:= ParamStr(idx
);
835 if arg
= '--opengl-dump-exts' then gwin_dump_extensions
:= true;
836 if arg
= '--twinkletwinkle' then gwin_k8_enable_light_experiments
:= true;
837 if arg
= '--jah' then g_profile_history_size
:= 100;
838 if arg
= '--no-particles' then gpart_dbg_enabled
:= false;
839 if arg
= '--no-los' then gmon_dbg_los_enabled
:= false;
841 if arg
= '--profile-render' then g_profile_frame_draw
:= true;
842 if arg
= '--profile-coldet' then g_profile_collision
:= true;
843 if arg
= '--profile-los' then g_profile_los
:= true;
845 if arg
= '--no-part-phys' then gpart_dbg_phys_enabled
:= false;
846 if arg
= '--no-part-physics' then gpart_dbg_phys_enabled
:= false;
847 if arg
= '--no-particles-phys' then gpart_dbg_phys_enabled
:= false;
848 if arg
= '--no-particles-physics' then gpart_dbg_phys_enabled
:= false;
849 if arg
= '--no-particle-phys' then gpart_dbg_phys_enabled
:= false;
850 if arg
= '--no-particle-physics' then gpart_dbg_phys_enabled
:= false;
852 {$IF DEFINED(D2F_DEBUG)}
853 if arg
= '--aimline' then g_dbg_aimline_on
:= false;
856 if arg
= '--holmes' then begin g_holmes_enabled
:= true; g_Game_SetDebugMode(); end;
857 if (arg
= '--holmes-ui-scale') or (arg
= '-holmes-ui-scale') then
859 if (idx
<= ParamCount
) then
861 if not conParseFloat(g_holmes_ui_scale
, ParamStr(idx
)) then g_holmes_ui_scale
:= 1.0;
866 {$IF DEFINED(D2F_DEBUG)}
867 if (arg
= '--game-scale') or (arg
= '-game-scale') then
869 if (idx
<= ParamCount
) then
871 if not conParseFloat(g_dbg_scale
, ParamStr(idx
)) then g_dbg_scale
:= 1.0;
878 e_WriteLog('Initializing OpenGL', MSG_NOTIFY
);
881 e_WriteLog('Creating GL window', MSG_NOTIFY
);
882 if not CreateGLWindow(PChar(Format('Doom 2D: Forever %s', [GAME_VERSION
]))) then
888 {EnumDisplayModes();}
890 if gwin_k8_enable_light_experiments
then
892 SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE
, @ltmp
);
893 e_WriteLog(Format('stencil buffer size: %d', [ltmp
]), MSG_WARNING
);
894 gwin_has_stencil
:= (ltmp
> 0);
898 gwin_has_stencil
:= false;
901 if not glHasExtension('GL_ARB_texture_non_power_of_two') then
903 e_WriteLog('Driver DID''T advertised NPOT textures support', MSG_WARNING
);
904 glLegacyNPOT
:= true;
908 e_WriteLog('Driver advertised NPOT textures support', MSG_NOTIFY
);
909 glLegacyNPOT
:= false;
911 gwin_dump_extensions
:= false;
914 Time_Old
:= GetTimer();
917 if ParamCount
> 0 then
918 g_Game_Process_Params();
921 if (not gGameOn
) and gAskLanguage
then
922 g_Menu_AskLanguage();
924 e_WriteLog('Entering the main loop', MSG_NOTIFY
);
926 while not ProcessMessage() do