From 681c1fa10d6cc9999d4cd0a284723fa0a8f4dec6 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Tue, 1 Aug 2017 05:51:23 +0300 Subject: [PATCH] fixed pointer arithmetics; headless uses dummy audio with sdl_mixer --- src/engine/e_fixedbuffer.pas | 12 ++++----- src/game/Doom2DF.dpr | 3 ++- src/game/g_main.pas | 22 +++++++++++++++-- src/shared/envvars.pas | 48 ++++++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 9 deletions(-) create mode 100644 src/shared/envvars.pas diff --git a/src/engine/e_fixedbuffer.pas b/src/engine/e_fixedbuffer.pas index e71445f..92c984c 100644 --- a/src/engine/e_fixedbuffer.pas +++ b/src/engine/e_fixedbuffer.pas @@ -110,7 +110,7 @@ begin if (B^.WritePos + N > B^.Len) then B^.Len := B^.WritePos + N + 1; - CopyMemory(Pointer(Cardinal(Addr(B^.Data)) + B^.WritePos), + CopyMemory(Pointer(NativeUInt(Addr(B^.Data)) + B^.WritePos), @V, N); B^.WritePos := B^.WritePos + N; @@ -119,7 +119,7 @@ procedure e_Buffer_Read_Generic(B: pTBuffer; var V; N: Cardinal); begin if (B^.ReadPos + N >= BUF_SIZE) then Exit; - CopyMemory(@V, Pointer(Cardinal(Addr(B^.Data)) + B^.ReadPos), N); + CopyMemory(@V, Pointer(NativeUInt(Addr(B^.Data)) + B^.ReadPos), N); B^.ReadPos := B^.ReadPos + N; end; @@ -179,7 +179,7 @@ begin if (P > B^.Len) then B^.Len := P; - CopyMemory(Pointer(Cardinal(Addr(B^.Data)) + B^.WritePos), + CopyMemory(Pointer(NativeUInt(Addr(B^.Data)) + B^.WritePos), @V[1], Len); B^.WritePos := P; @@ -241,7 +241,7 @@ begin Len := B^.Len - B^.ReadPos; SetLength(Result, Len); - CopyMemory(@Result[1], Pointer(Cardinal(Addr(B^.Data)) + B^.ReadPos), Len); + CopyMemory(@Result[1], Pointer(NativeUInt(Addr(B^.Data)) + B^.ReadPos), Len); B^.ReadPos := B^.ReadPos + Len; end; @@ -256,7 +256,7 @@ end; procedure e_Raw_Read_Generic(P: Pointer; var V; N: Cardinal); begin - CopyMemory(@V, Pointer(Cardinal(P) + RawPos), N); + CopyMemory(@V, Pointer(NativeUInt(P) + RawPos), N); RawPos := RawPos + N; end; @@ -301,7 +301,7 @@ begin if Len = 0 then Exit; SetLength(Result, Len); - CopyMemory(@Result[1], Pointer(Cardinal(P) + RawPos), Len); + CopyMemory(@Result[1], Pointer(NativeUInt(P) + RawPos), Len); RawPos := RawPos + Len; end; diff --git a/src/game/Doom2DF.dpr b/src/game/Doom2DF.dpr index 3fbd829..a410545 100644 --- a/src/game/Doom2DF.dpr +++ b/src/game/Doom2DF.dpr @@ -102,6 +102,7 @@ uses fmodtypes in '../lib/FMOD/fmodtypes.pas', {$ENDIF} BinEditor in '../shared/BinEditor.pas', + envvars in '../shared/envvars.pas', g_panel in 'g_panel.pas', g_language in 'g_language.pas', ImagingTypes, @@ -132,6 +133,6 @@ begin on E: Exception do e_WriteLog(Format(_lc[I_SYSTEM_ERROR_MSG], [E.Message]), MSG_FATALERROR); else - e_WriteLog(Format(_lc[I_SYSTEM_ERROR_UNKNOWN], [LongWord(ExceptAddr())]), MSG_FATALERROR); + e_WriteLog(Format(_lc[I_SYSTEM_ERROR_UNKNOWN], [NativeUInt(ExceptAddr())]), MSG_FATALERROR); end; end. diff --git a/src/game/g_main.pas b/src/game/g_main.pas index 59e7870..2d9d7e4 100644 --- a/src/game/g_main.pas +++ b/src/game/g_main.pas @@ -40,7 +40,8 @@ uses e_graphics, e_input, g_game, g_console, g_gui, e_sound, g_options, g_sound, g_player, g_weapons, SysUtils, g_triggers, MAPDEF, g_map, - MAPSTRUCT, g_menu, g_language, g_net, utils, conbuf; + MAPSTRUCT, g_menu, g_language, g_net, + utils, conbuf, envvars; var charbuff: Array [0..15] of Char; @@ -75,7 +76,13 @@ begin g_Language_Set(gLanguage); {$IFDEF HEADLESS} + {$IFDEF USE_SDLMIXER} + sdlflags := SDL_INIT_TIMER or SDL_INIT_AUDIO or $00004000; + // HACK: shit this into env and hope for the best + SetEnvVar('SDL_AUDIODRIVER', 'dummy'); + {$ELSE} sdlflags := SDL_INIT_TIMER or $00004000; + {$ENDIF} {$ELSE} {$IFDEF USE_SDLMIXER} sdlflags := SDL_INIT_EVERYTHING; @@ -107,9 +114,20 @@ end; procedure Init(); var a: Integer; + NoSound: Boolean; begin Randomize; +{$IFDEF HEADLESS} + {$IFDEF USE_SDLMIXER} + NoSound := False; // hope env has set SDL_AUDIODRIVER to dummy + {$ELSE} + NoSound := True; // FMOD backend will sort it out + {$ENDIF} +{$ELSE} + NoSound := False; +{$ENDIF} + e_WriteLog('Init Input', MSG_NOTIFY); e_InitInput(); @@ -121,7 +139,7 @@ begin if (not gNoSound) then begin e_WriteLog('Initializing sound system', MSG_NOTIFY); - e_InitSoundSystem({$IFDEF HEADLESS}True{$ELSE}False{$ENDIF}); + e_InitSoundSystem(NoSound); end; e_WriteLog('Init game', MSG_NOTIFY); diff --git a/src/shared/envvars.pas b/src/shared/envvars.pas new file mode 100644 index 0000000..6f92b40 --- /dev/null +++ b/src/shared/envvars.pas @@ -0,0 +1,48 @@ +(* Copyright (C) DooM 2D:Forever Developers + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + *) +{$MODE OBJFPC} +unit envvars; + +interface + +uses SysUtils, CTypes; + +function SetEnvVar(const VarName: AnsiString; const VarVal: AnsiString): Boolean; + +implementation + +{$IFDEF WINDOWS} +uses Windows; +function setenv(const VarStr: PChar; const VarVal: PChar; Repl: cint): cint; +begin + if (SetEnvironmentVariable(VarStr, VarVal)) then + Result := 0 + else + Result := -1; +end; +{$ELSE} +{$LINKLIB c} +const clib = 'c'; +function setenv(const VarStr: PChar; const VarVal: PChar; Repl: cint): cint; +cdecl; external clib name 'setenv'; +{$ENDIF} + +function SetEnvVar(const VarName: AnsiString; const VarVal: AnsiString): Boolean; +begin + Result := (setenv(PChar(VarName), PChar(VarVal), 1) = 0); +end; + +end. -- 2.29.2