From: FGSFDSFGS Date: Tue, 12 Apr 2016 19:32:53 +0000 (+0300) Subject: added headless mode X-Git-Url: http://deadsoftware.ru/gitweb?p=d2df-sdl.git;a=commitdiff_plain;h=0968d19494ddf24230a822c02acbe3a3334bc3ad added headless mode --- diff --git a/build_headless.bat b/build_headless.bat new file mode 100644 index 0000000..9580d69 --- /dev/null +++ b/build_headless.bat @@ -0,0 +1,5 @@ +@echo off +cd "./src/game" +fpc -dUSE_FMOD -dHEADLESS -MDELPHI -O2 -FE../../bin -FU../../tmp -oDoom2DF_H.exe Doom2DF.dpr +cd ".." +pause \ No newline at end of file diff --git a/src/engine/e_graphics.pas b/src/engine/e_graphics.pas index 67cdb65..4312312 100644 --- a/src/engine/e_graphics.pas +++ b/src/engine/e_graphics.pas @@ -102,9 +102,6 @@ procedure e_Clear(Mask: TGLbitfield; Red, Green, Blue: Single); overload; procedure e_Clear(); overload; procedure e_EndRender(); -procedure e_SaveGLContext(); -procedure e_RestoreGLContext(); - function e_GetGamma(win: PSDL_Window): Byte; procedure e_SetGamma(win: PSDL_Window;Gamma: Byte); @@ -118,6 +115,7 @@ function _TRect(L, T, R, B: LongInt): TRect; var e_Colors: TRGB; + e_NoGraphics: Boolean = False; implementation @@ -167,11 +165,16 @@ var //------------------------------------------------------------------ procedure e_InitGL(); begin - glDisable(GL_DEPTH_TEST); - glEnable(GL_SCISSOR_TEST); + if e_NoGraphics then + begin + e_DummyTextures := True; + Exit; + end; e_Colors.R := 255; e_Colors.G := 255; e_Colors.B := 255; + glDisable(GL_DEPTH_TEST); + glEnable(GL_SCISSOR_TEST); glClearColor(0, 0, 0, 0); end; @@ -180,6 +183,7 @@ var mat: Array [0..15] of GLDouble; begin + if e_NoGraphics then Exit; glLoadIdentity(); glScissor(X, Y, Width, Height); glViewport(X, Y, Width, Height); @@ -337,15 +341,18 @@ var begin w := e_Textures[ID].Width; h := e_Textures[ID].Height; - data := GetMemory(w*h*4); - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, e_Textures[ID].tx.id); - glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); Result.Y := 0; Result.X := 0; Result.Width := w; Result.Height := h; + + if e_NoGraphics then Exit; + + data := GetMemory(w*h*4); + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, e_Textures[ID].tx.id); + glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); for y := h-1 downto 0 do begin @@ -434,6 +441,7 @@ procedure e_Draw(ID: DWORD; X, Y: Integer; Alpha: Byte; AlphaChannel: Boolean; var u, v: Single; begin + if e_NoGraphics then Exit; glColor4ub(e_Colors.R, e_Colors.G, e_Colors.B, 255); if (Alpha > 0) or (AlphaChannel) or (Blending) then @@ -491,6 +499,7 @@ procedure e_DrawSize(ID: DWORD; X, Y: Integer; Alpha: Byte; AlphaChannel: Boolea var u, v: Single; begin + if e_NoGraphics then Exit; glColor4ub(e_Colors.R, e_Colors.G, e_Colors.B, 255); if (Alpha > 0) or (AlphaChannel) or (Blending) then @@ -528,6 +537,7 @@ procedure e_DrawSizeMirror(ID: DWORD; X, Y: Integer; Alpha: Byte; AlphaChannel: var u, v: Single; begin + if e_NoGraphics then Exit; glColor4ub(e_Colors.R, e_Colors.G, e_Colors.B, 255); if (Alpha > 0) or (AlphaChannel) or (Blending) then @@ -586,6 +596,7 @@ var X2, Y2, dx, w, h: Integer; u, v: Single; begin + if e_NoGraphics then Exit; glColor4ub(e_Colors.R, e_Colors.G, e_Colors.B, 255); if (Alpha > 0) or (AlphaChannel) or (Blending) then @@ -660,6 +671,7 @@ procedure e_DrawAdv(ID: DWORD; X, Y: Integer; Alpha: Byte; AlphaChannel: Boolean var u, v: Single; begin + if e_NoGraphics then Exit; glColor4ub(e_Colors.R, e_Colors.G, e_Colors.B, 255); if (Alpha > 0) or (AlphaChannel) or (Blending) then @@ -726,6 +738,7 @@ end; procedure e_DrawPoint(Size: Byte; X, Y: Integer; Red, Green, Blue: Byte); begin + if e_NoGraphics then Exit; glDisable(GL_TEXTURE_2D); glColor3ub(Red, Green, Blue); glPointSize(Size); @@ -766,6 +779,7 @@ procedure e_DrawQuad(X1, Y1, X2, Y2: Integer; Red, Green, Blue: Byte; Alpha: Byt var nX1, nY1, nX2, nY2: Integer; begin + if e_NoGraphics then Exit; // Only top-left/bottom-right quad if X1 > X2 then begin @@ -825,6 +839,7 @@ end; procedure e_DrawFillQuad(X1, Y1, X2, Y2: Integer; Red, Green, Blue, Alpha: Byte; Blending: TBlending = B_NONE); begin + if e_NoGraphics then Exit; if (Alpha > 0) or (Blending <> B_NONE) then glEnable(GL_BLEND) else @@ -862,6 +877,7 @@ end; procedure e_DrawLine(Width: Byte; X1, Y1, X2, Y2: Integer; Red, Green, Blue: Byte; Alpha: Byte = 0); begin + if e_NoGraphics then Exit; // Pixel-perfect lines if Width = 1 then e_LineCorrection(X1, Y1, X2, Y2); @@ -892,7 +908,8 @@ end; //------------------------------------------------------------------ procedure e_DeleteTexture(ID: DWORD); begin - glDeleteTextures(1, @e_Textures[ID].tx.id); + if not e_NoGraphics then + glDeleteTextures(1, @e_Textures[ID].tx.id); e_Textures[ID].tx.id := 0; e_Textures[ID].Width := 0; e_Textures[ID].Height := 0; @@ -923,29 +940,34 @@ end; procedure e_BeginRender(); begin + if e_NoGraphics then Exit; glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.0); end; procedure e_Clear(Mask: TGLbitfield; Red, Green, Blue: Single); overload; begin - glClearColor(Red, Green, Blue, 0); - glClear(Mask); + if e_NoGraphics then Exit; + glClearColor(Red, Green, Blue, 0); + glClear(Mask); end; procedure e_Clear(); overload; begin - glClearColor(0, 0, 0, 0); - glClear(GL_COLOR_BUFFER_BIT); + if e_NoGraphics then Exit; + glClearColor(0, 0, 0, 0); + glClear(GL_COLOR_BUFFER_BIT); end; procedure e_EndRender(); begin + if e_NoGraphics then Exit; glPopMatrix(); end; procedure e_MakeScreenshot(FileName: String; Width, Height: Word); begin + if e_NoGraphics then Exit; end; {type @@ -1025,6 +1047,8 @@ var A, B: double; i, j: integer; begin + Result := 0; + if e_NoGraphics then Exit; rgb[0] := 1.0; rgb[1] := 1.0; rgb[2] := 1.0; @@ -1059,6 +1083,7 @@ var r: double; g: double; begin + if e_NoGraphics then Exit; g := (100 - Gamma)*(2.7 - 0.23)/100 + 0.23; for i := 0 to 255 do @@ -1125,6 +1150,7 @@ procedure e_CharFont_Print(FontID: DWORD; X, Y: Integer; Text: string); var a: Integer; begin + if e_NoGraphics then Exit; if Text = '' then Exit; if e_CharFonts = nil then Exit; if Integer(FontID) > High(e_CharFonts) then Exit; @@ -1147,6 +1173,7 @@ var a: Integer; c: TRGB; begin + if e_NoGraphics then Exit; if Text = '' then Exit; if e_CharFonts = nil then Exit; if Integer(FontID) > High(e_CharFonts) then Exit; @@ -1181,6 +1208,7 @@ var tc, c: TRGB; w, h: Word; begin + if e_NoGraphics then Exit; if Text = '' then Exit; if e_CharFonts = nil then Exit; if Integer(FontID) > High(e_CharFonts) then Exit; @@ -1397,6 +1425,7 @@ var cx, cy : real; i, id: DWORD; begin + if e_NoGraphics then Exit; e_WriteLog('Creating texture font...', MSG_NOTIFY); id := DWORD(-1); @@ -1454,56 +1483,16 @@ begin FontID := id; end; -procedure e_TextureFontBuildInPlace(id: DWORD); -var - loop1 : GLuint; - cx, cy : real; - XCount, YCount, Space: Integer; - {i,} Tex: DWORD; -begin - with e_TextureFonts[id] do - begin - Base := glGenLists(XC*YC); - TextureID := e_Textures[Texture].tx.id; - XCount := XC; - YCount := YC; - Space := SPC; - Tex := Texture; - end; - - glBindTexture(GL_TEXTURE_2D, e_Textures[Tex].tx.id); - for loop1 := 0 to XCount*YCount-1 do - begin - cx := (loop1 mod XCount)/XCount; - cy := (loop1 div YCount)/YCount; - - glNewList(e_TextureFonts[id].Base+loop1, GL_COMPILE); - glBegin(GL_QUADS); - glTexCoord2f(cx, 1.0-cy-1/YCount); - glVertex2d(0, e_Textures[Tex].Height div YCount); - - glTexCoord2f(cx+1/XCount, 1.0-cy-1/YCount); - glVertex2i(e_Textures[Tex].Width div XCount, e_Textures[Tex].Height div YCount); - - glTexCoord2f(cx+1/XCount, 1.0-cy); - glVertex2i(e_Textures[Tex].Width div XCount, 0); - - glTexCoord2f(cx, 1.0-cy); - glVertex2i(0, 0); - glEnd(); - glTranslated((e_Textures[Tex].Width div XCount)+Space, 0, 0); - glEndList(); - end; -end; - procedure e_TextureFontKill(FontID: DWORD); begin + if e_NoGraphics then Exit; glDeleteLists(e_TextureFonts[FontID].Base, 256); e_TextureFonts[FontID].Base := 0; end; procedure e_TextureFontPrint(X, Y: GLint; Text: string; FontID: DWORD); begin + if e_NoGraphics then Exit; if Integer(FontID) > High(e_TextureFonts) then Exit; if Text = '' then Exit; @@ -1527,6 +1516,7 @@ end; // god forgive me for this, but i cannot figure out how to do it without lists procedure e_TextureFontPrintChar(X, Y: Integer; Ch: Char; FontID: DWORD; Shadow: Boolean = False); begin + if e_NoGraphics then Exit; glPushMatrix; if Shadow then @@ -1551,6 +1541,7 @@ var tc, c: TRGB; w: Word; begin + if e_NoGraphics then Exit; if Text = '' then Exit; if e_TextureFonts = nil then Exit; if Integer(FontID) > High(e_TextureFonts) then Exit; @@ -1640,6 +1631,7 @@ end; procedure e_TextureFontPrintEx(X, Y: GLint; Text: string; FontID: DWORD; Red, Green, Blue: Byte; Scale: Single; Shadow: Boolean = False); begin + if e_NoGraphics then Exit; if Text = '' then Exit; glPushMatrix; @@ -1673,6 +1665,9 @@ end; procedure e_TextureFontGetSize(ID: DWORD; var CharWidth, CharHeight: Byte); begin + CharWidth := 16; + CharHeight := 16; + if e_NoGraphics then Exit; if Integer(ID) > High(e_TextureFonts) then Exit; CharWidth := e_TextureFonts[ID].CharWidth; @@ -1683,6 +1678,7 @@ procedure e_RemoveAllTextureFont(); var i: integer; begin + if e_NoGraphics then Exit; if e_TextureFonts = nil then Exit; for i := 0 to High(e_TextureFonts) do @@ -1695,94 +1691,6 @@ begin e_TextureFonts := nil; end; -procedure e_SaveGLContext(); -var - PxLen: Cardinal; - i: Integer; -begin - e_WriteLog('Backing up GL context:', MSG_NOTIFY); - - glPushAttrib(GL_ALL_ATTRIB_BITS); - glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS); - - if e_Textures <> nil then - begin - e_WriteLog(' Backing up textures...', MSG_NOTIFY); - SetLength(e_SavedTextures, Length(e_Textures)); - for i := Low(e_Textures) to High(e_Textures) do - begin - e_SavedTextures[i].Pixels := nil; - if e_Textures[i].Width > 0 then - begin - with e_SavedTextures[i] do - begin - PxLen := 3; - if e_Textures[i].Fmt = GL_RGBA then Inc(PxLen); - Pixels := GetMem(PxLen * e_Textures[i].Width * e_Textures[i].Height); - glBindTexture(GL_TEXTURE_2D, e_Textures[i].tx.id); - glGetTexImage(GL_TEXTURE_2D, 0, e_Textures[i].Fmt, GL_UNSIGNED_BYTE, Pixels); - glBindTexture(GL_TEXTURE_2D, 0); - OldID := e_Textures[i].tx.id; - TexId := i; - end; - end; - end; - end; - - if e_TextureFonts <> nil then - begin - e_WriteLog(' Releasing texturefonts...', MSG_NOTIFY); - for i := 0 to High(e_TextureFonts) do - if e_TextureFonts[i].Base <> 0 then - begin - glDeleteLists(e_TextureFonts[i].Base, 256); - e_TextureFonts[i].Base := 0; - end; - end; -end; - -procedure e_RestoreGLContext(); -var - //GLID: GLuint; - i: Integer; -begin - e_WriteLog('Restoring GL context:', MSG_NOTIFY); - - glPopClientAttrib(); - glPopAttrib(); - - if e_SavedTextures <> nil then - begin - e_WriteLog(' Regenerating textures...', MSG_NOTIFY); - for i := Low(e_SavedTextures) to High(e_SavedTextures) do - begin - if e_SavedTextures[i].Pixels <> nil then - with e_SavedTextures[i] do - begin - CreateTexture(e_Textures[TexID].tx, e_Textures[TexID].Width, e_Textures[TexID].Height, e_Textures[TexID].Fmt, Pixels); - //GLID := CreateTexture(e_Textures[TexID].Width, e_Textures[TexID].Height, e_Textures[TexID].Fmt, Pixels); - //e_Textures[TexID].tx := GLID; - FreeMem(Pixels); - end; - end; - end; - - if e_TextureFonts <> nil then - begin - e_WriteLog(' Regenerating texturefonts...', MSG_NOTIFY); - for i := Low(e_TextureFonts) to High(e_TextureFonts) do - with e_TextureFonts[i] do - begin - TextureID := e_Textures[Texture].tx.id; - Base := 0; - e_TextureFontBuildInPlace(i); - end; - end; - - SetLength(e_SavedTextures, 0); -end; - - function _RGB(Red, Green, Blue: Byte): TRGB; begin Result.R := Red; diff --git a/src/engine/e_log.pas b/src/engine/e_log.pas index e82bfb4..e524c1a 100644 --- a/src/engine/e_log.pas +++ b/src/engine/e_log.pas @@ -15,6 +15,9 @@ procedure e_WriteLog(TextLine: String; RecordCategory: TRecordCategory; WriteTime: Boolean = True); function DecodeIPV4(ip: LongWord): string; +var + e_WriteToStdOut: Boolean = False; + implementation var @@ -33,6 +36,7 @@ procedure e_WriteLog(TextLine: String; RecordCategory: TRecordCategory; var LogFile: TextFile; Prefix: ShortString = ''; + OutStr: String; begin if FileName = '' then Exit; @@ -54,9 +58,12 @@ begin MSG_NOTIFY: Prefix := '***'; end; if WriteTime then - Writeln(LogFile, '['+TimeToStr(Time)+'] '+Prefix+' '+TextLine) + OutStr := '['+TimeToStr(Time)+'] '+Prefix+' '+TextLine else - Writeln(LogFile, Prefix+' '+TextLine); + OutStr := Prefix+' '+TextLine; + Writeln(LogFile, OutStr); + if e_WriteToStdOut then + Writeln(OutStr); finally Close(LogFile); end; diff --git a/src/engine/e_sound_fmod.inc b/src/engine/e_sound_fmod.inc index 123db2c..acfd069 100644 --- a/src/engine/e_sound_fmod.inc +++ b/src/engine/e_sound_fmod.inc @@ -50,7 +50,7 @@ type const NO_SOUND_ID = DWORD(-1); -function e_InitSoundSystem(): Boolean; +function e_InitSoundSystem(NoOutput: Boolean = False): Boolean; function e_LoadSound(FileName: string; var ID: DWORD; bLoop: Boolean): Boolean; function e_LoadSoundMem(pData: Pointer; Length: Integer; var ID: DWORD; bLoop: Boolean): Boolean; @@ -134,7 +134,7 @@ begin end; end; -function e_TrySS (Freq: Integer; forceNoSound: Boolean): Boolean; +function e_TrySS (Freq: Integer; forceNoSound: Integer): Boolean; var res: FMOD_RESULT; ver: Cardinal; @@ -175,25 +175,37 @@ begin Exit; end; - res := FMOD_System_Init(F_System, N_CHANNELS, FMOD_INIT_NORMAL, nil); - if res <> FMOD_OK then + if forceNoSound = 2 then begin - e_WriteLog('Error initializing FMOD system!', MSG_WARNING); - e_WriteLog(FMOD_ErrorString(res), MSG_WARNING); - - {$IFDEF LINUX} - res := TryInitWithOutput(FMOD_OUTPUTTYPE_ALSA, 'OUTPUTTYPE_ALSA'); - if res <> FMOD_OK then - res := TryInitWithOutput(FMOD_OUTPUTTYPE_OSS, 'OUTPUTTYPE_OSS'); - {$ENDIF} - if (res <> FMOD_OK) and not forceNoSound then Exit; - if res <> FMOD_OK then - res := TryInitWithOutput(FMOD_OUTPUTTYPE_NOSOUND, 'OUTPUTTYPE_NOSOUND'); + res := TryInitWithOutput(FMOD_OUTPUTTYPE_NOSOUND, 'OUTPUTTYPE_NOSOUND'); if res <> FMOD_OK then begin - e_WriteLog('FMOD: Giving up, can''t init any output.', MSG_FATALERROR); + e_WriteLog('FMOD: Giving up, can''t init with NOSOUND.', MSG_FATALERROR); Exit; end; + end + else + begin + res := FMOD_System_Init(F_System, N_CHANNELS, FMOD_INIT_NORMAL, nil); + if res <> FMOD_OK then + begin + e_WriteLog('Error initializing FMOD system!', MSG_WARNING); + e_WriteLog(FMOD_ErrorString(res), MSG_WARNING); + + {$IFDEF LINUX} + res := TryInitWithOutput(FMOD_OUTPUTTYPE_ALSA, 'OUTPUTTYPE_ALSA'); + if res <> FMOD_OK then + res := TryInitWithOutput(FMOD_OUTPUTTYPE_OSS, 'OUTPUTTYPE_OSS'); + {$ENDIF} + if (res <> FMOD_OK) and (forceNoSound <> 1) then Exit; + if res <> FMOD_OK then + res := TryInitWithOutput(FMOD_OUTPUTTYPE_NOSOUND, 'OUTPUTTYPE_NOSOUND'); + if res <> FMOD_OK then + begin + e_WriteLog('FMOD: Giving up, can''t init any output.', MSG_FATALERROR); + Exit; + end; + end; end; res := FMOD_System_GetOutput(F_System, output); @@ -222,10 +234,15 @@ begin Result := True; end; -function e_InitSoundSystem(): Boolean; +function e_InitSoundSystem(NoOutput: Boolean = False): Boolean; begin - Result := e_TrySS(48000, False); - if not Result then Result := e_TrySS(44100, True); + if NoOutput then + begin + Result := e_TrySS(48000, 2); + Exit; + end; + Result := e_TrySS(48000, 0); + if not Result then Result := e_TrySS(44100, 1); end; function FindESound(): DWORD; diff --git a/src/engine/e_sound_sdl.inc b/src/engine/e_sound_sdl.inc index 541f31a..0104f3a 100644 --- a/src/engine/e_sound_sdl.inc +++ b/src/engine/e_sound_sdl.inc @@ -53,7 +53,7 @@ type const NO_SOUND_ID = DWORD(-1); -function e_InitSoundSystem(): Boolean; +function e_InitSoundSystem(NoOutput: Boolean = False): Boolean; function e_LoadSound(FileName: string; var ID: DWORD; isMusic: Boolean): Boolean; function e_LoadSoundMem(pData: Pointer; Length: Integer; var ID: DWORD; isMusic: Boolean): Boolean; @@ -152,7 +152,7 @@ begin end; end; -function e_InitSoundSystem(): Boolean; +function e_InitSoundSystem(NoOutput: Boolean = False): Boolean; var res, i: Integer; rfreq: Integer; @@ -163,6 +163,8 @@ begin Result := False; SoundInitialized := False; + + if NoOutput then begin Result := true; Exit end; // wow, this is actually MIDI player! // we need module player diff --git a/src/engine/e_textures.pas b/src/engine/e_textures.pas index ef9b660..2a4300b 100644 --- a/src/engine/e_textures.pas +++ b/src/engine/e_textures.pas @@ -18,6 +18,7 @@ type end; var + e_DummyTextures: Boolean = False; TEXTUREFILTER: Integer = GL_NEAREST; function CreateTexture(var tex: GLTexture; Width, Height, aFormat: Word; pData: Pointer ): Boolean; @@ -94,6 +95,13 @@ begin e_WriteLog(Format('NPOT: orig is %ux%u; gl is %ux%u; u=%f; v=%f', [Width, Height, tex.glwidth, tex.glheight, tex.u, tex.v]), MSG_NOTIFY); end; + if e_DummyTextures then + begin + tex.id := GLuint(-1); + Result := True; + Exit; + end; + glGenTextures(1, @Texture); tex.id := Texture; glBindTexture(GL_TEXTURE_2D, Texture); diff --git a/src/game/Doom2DF.dpr b/src/game/Doom2DF.dpr index 57f516d..df5de45 100644 --- a/src/game/Doom2DF.dpr +++ b/src/game/Doom2DF.dpr @@ -1,6 +1,8 @@ program Doom2DF; -{$IFDEF WIN32} - {$APPTYPE GUI} +{$IFNDEF HEADLESS} + {$IFDEF WIN32} + {$APPTYPE GUI} + {$ENDIF} {$ENDIF} {$HINTS OFF} diff --git a/src/game/g_console.pas b/src/game/g_console.pas index 4898bfb..27ca859 100644 --- a/src/game/g_console.pas +++ b/src/game/g_console.pas @@ -28,7 +28,7 @@ implementation uses g_textures, g_main, e_graphics, e_input, g_game, SysUtils, g_basic, g_options, WADEDITOR, Math, - g_menu, g_language, g_net, g_netmsg; + g_menu, g_language, g_net, g_netmsg, e_log; type TCmdProc = procedure (P: SArray); @@ -820,6 +820,10 @@ begin Time := MsgTime; end; end; + +{$IFDEF HEADLESS} + e_WriteLog('CON: ' + L, MSG_NOTIFY); +{$ENDIF} end; procedure g_Console_Clear(); diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 3bb18b7..30605bf 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -6306,7 +6306,7 @@ begin if (s <> '') then begin gMapToDelete := MapsDir + map; - e_WriteLog('"--testdelete" argument doesn''t supported anymore!', MSG_FATALERROR); + e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', MSG_FATALERROR); Halt(1); end; diff --git a/src/game/g_main.pas b/src/game/g_main.pas index 1840635..d78c84e 100644 --- a/src/game/g_main.pas +++ b/src/game/g_main.pas @@ -30,6 +30,8 @@ var charbuff: Array [0..15] of Char; procedure Main(); +var + sdlflags: LongWord; begin GetDir(0, GameDir); MapsDir := GameDir + '/maps/'; @@ -41,6 +43,8 @@ begin e_WriteLog('Read config file', MSG_NOTIFY); g_Options_Read(GameDir + '/' + CONFIG_FILENAME); + + e_WriteToStdOut := {$IFDEF HEADLESS}True;{$ELSE}False;{$ENDIF} //GetSystemDefaultLCID() @@ -48,23 +52,32 @@ begin //g_Language_Load(DataDir + gLanguage + '.txt'); e_WriteLog(gLanguage, MSG_NOTIFY); g_Language_Set(gLanguage); - -{$IFDEF USE_SDLMIXER} - if SDL_Init({SDL_INIT_JOYSTICK or SDL_INIT_TIMER or SDL_INIT_VIDEO or SDL_INIT_AUDIO}SDL_INIT_EVERYTHING) < 0 then + +{$IFDEF HEADLESS} + sdlflags := SDL_INIT_TIMER or $00004000; {$ELSE} - if SDL_Init(SDL_INIT_JOYSTICK or SDL_INIT_TIMER or SDL_INIT_VIDEO) < 0 then + {$IFDEF USE_SDLMIXER} + sdlflags := SDL_INIT_EVERYTHING; + {$ELSE} + sdlflags := SDL_INIT_JOYSTICK or SDL_INIT_TIMER or SDL_INIT_VIDEO; + {$ENDIF} {$ENDIF} + if SDL_Init(sdlflags) < 0 then raise Exception.Create('SDL: Init failed: ' + SDL_GetError()); - + +{$IFDEF HEADLESS} SDL_StartTextInput(); +{$ENDIF} e_WriteLog('Entering SDLMain', MSG_NOTIFY); - {$WARNINGS OFF} +{$WARNINGS OFF} SDLMain(); - {$WARNINGS ON} +{$WARNINGS ON} +{$IFDEF HEADLESS} SDL_StopTextInput(); +{$ENDIF} e_WriteLog('Releasing SDL', MSG_NOTIFY); SDL_Quit(); @@ -84,10 +97,10 @@ begin else e_WriteLog('Input: No Joysticks.', MSG_NOTIFY); - if not gNoSound then + if (not gNoSound) then begin e_WriteLog('Initializing sound system', MSG_NOTIFY); - e_InitSoundSystem(); + e_InitSoundSystem({$IFDEF HEADLESS}True{$ELSE}False{$ENDIF}); end; e_WriteLog('Init game', MSG_NOTIFY); diff --git a/src/game/g_sound.pas b/src/game/g_sound.pas index f5ce6c7..b1e09f8 100644 --- a/src/game/g_sound.pas +++ b/src/game/g_sound.pas @@ -309,8 +309,8 @@ begin end; WAD.Free(); - - if not ok then +{$IFNDEF HEADLESS} + if (not ok) then begin if isMusic then e_WriteLog(Format('Error loading music %s', [Resource]), MSG_WARNING) @@ -318,7 +318,7 @@ begin e_WriteLog(Format('Error loading sound %s', [Resource]), MSG_WARNING); Exit; end; - +{$ENDIF} Result := True; end; @@ -359,8 +359,8 @@ begin end; WAD.Free(); - - if not ok then +{$IFNDEF HEADLESS} + if (not ok) then begin if isMusic then e_WriteLog(Format('Error loading music %s', [Resource]), MSG_WARNING) @@ -368,7 +368,7 @@ begin e_WriteLog(Format('Error loading sound %s', [Resource]), MSG_WARNING); Exit; end; - +{$ENDIF} Result := True; end; diff --git a/src/game/g_window.pas b/src/game/g_window.pas index 33fc80c..c159ddd 100644 --- a/src/game/g_window.pas +++ b/src/game/g_window.pas @@ -73,6 +73,11 @@ function g_Window_SetDisplay(PreserveGL: Boolean = False): Boolean; var mode, cmode: TSDL_DisplayMode; begin +{$IFDEF HEADLESS} + Result := True; + Exit; +{$ENDIF} + Result := False; e_WriteLog('Setting display mode...', MSG_NOTIFY); @@ -126,7 +131,7 @@ var res, i, k, n, pw, ph: Integer; begin SetLength(Result, 0); - + {$IFDEF HEADLESS}Exit;{$ENDIF} k := 0; SelRes := 0; n := SDL_GetNumDisplayModes(0); pw := 0; ph := 0; @@ -156,6 +161,7 @@ procedure ChangeWindowSize(); begin gWinSizeX := gScreenWidth; gWinSizeY := gScreenHeight; + {$IFDEF HEADLESS}Exit;{$ENDIF} e_ResizeWindow(gScreenWidth, gScreenHeight); g_Game_SetupScreenSize(); g_Menu_Reset(); @@ -167,6 +173,7 @@ var Preserve: Boolean; begin Result := False; + {$IFDEF HEADLESS}Exit;{$ENDIF} Preserve := False; if (gScreenWidth <> W) or (gScreenHeight <> H) then @@ -383,6 +390,7 @@ end; procedure SwapBuffers(); begin + {$IFDEF HEADLESS}Exit;{$ENDIF} SDL_GL_SwapWindow(h_Wnd); end; @@ -414,9 +422,10 @@ begin exit; end; +{$IFNDEF HEADLESS} h_Gl := SDL_GL_CreateContext(h_Wnd); if h_Gl = nil then Exit; - +{$ENDIF} //wWindowCreated := True; e_ResizeWindow(gScreenWidth, gScreenHeight); @@ -588,6 +597,7 @@ procedure InitOpenGL(VSync: Boolean); var v: Byte; begin + {$IFDEF HEADLESS}Exit;{$ENDIF} 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); @@ -601,6 +611,10 @@ end; function SDLMain(): Integer; begin +{$IFDEF HEADLESS} + e_NoGraphics := True; +{$ENDIF} + e_WriteLog('Creating GL window', MSG_NOTIFY); if not CreateGLWindow(PChar(Format('Doom 2D: Forever %s', [GAME_VERSION]))) then begin