Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 417dfc1

Browse files
committed
fixed sound on linux; removed stdcall where it wasn't needed
1 parent 5f06b25 commit 417dfc1

6 files changed

Lines changed: 813 additions & 770 deletions

File tree

Engine Source/e_sound.pas

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ implementation
8888

8989

9090
function Channel_Callback(channel: FMOD_CHANNEL; callbacktype: FMOD_CHANNEL_CALLBACKTYPE;
91-
commanddata1: Pointer; commanddata2: Pointer): FMOD_RESULT; stdcall;
91+
commanddata1: Pointer; commanddata2: Pointer): FMOD_RESULT; {$IFDEF WIN32} stdcall; {$ELSE} cdecl; {$ENDIF}
9292
var
9393
res: FMOD_RESULT;
9494
sound: FMOD_SOUND;
@@ -117,6 +117,25 @@ function Channel_Callback(channel: FMOD_CHANNEL; callbacktype: FMOD_CHANNEL_CALL
117117
Result := res;
118118
end;
119119

120+
function TryInitWithOutput(Output: FMOD_OUTPUTTYPE; OutputName: String): FMOD_RESULT;
121+
begin
122+
e_WriteLog('Trying with ' + OutputName + '...', MSG_WARNING);
123+
Result := FMOD_System_SetOutput(F_System, Output);
124+
if Result <> FMOD_OK then
125+
begin
126+
e_WriteLog('Error setting FMOD output to ' + OutputName + '!', MSG_WARNING);
127+
e_WriteLog(FMOD_ErrorString(Result), MSG_WARNING);
128+
Exit;
129+
end;
130+
Result := FMOD_System_Init(F_System, N_CHANNELS, FMOD_INIT_NORMAL, nil);
131+
if Result <> FMOD_OK then
132+
begin
133+
e_WriteLog('Error initializing FMOD system!', MSG_WARNING);
134+
e_WriteLog(FMOD_ErrorString(Result), MSG_WARNING);
135+
Exit;
136+
end;
137+
end;
138+
120139
function e_InitSoundSystem(Freq: Integer): Boolean;
121140
var
122141
res: FMOD_RESULT;
@@ -145,7 +164,7 @@ function e_InitSoundSystem(Freq: Integer): Boolean;
145164

146165
if ver < FMOD_VERSION then
147166
begin
148-
e_WriteLog('FMOD DLL version is too old! Need '+IntToStr(FMOD_VERSION), MSG_FATALERROR);
167+
e_WriteLog('FMOD library version is too old! Need '+IntToStr(FMOD_VERSION), MSG_FATALERROR);
149168
Exit;
150169
end;
151170

@@ -163,19 +182,17 @@ function e_InitSoundSystem(Freq: Integer): Boolean;
163182
begin
164183
e_WriteLog('Error initializing FMOD system!', MSG_WARNING);
165184
e_WriteLog(FMOD_ErrorString(res), MSG_WARNING);
166-
e_WriteLog('Trying with OUTPUTTYPE_NOSOUND...', MSG_WARNING);
167-
res := FMOD_System_SetOutput(F_System, FMOD_OUTPUTTYPE_NOSOUND);
185+
186+
{$IFDEF LINUX}
187+
res := TryInitWithOutput(FMOD_OUTPUTTYPE_ALSA, 'OUTPUTTYPE_ALSA');
168188
if res <> FMOD_OK then
169-
begin
170-
e_WriteLog('Error setting FMOD output to NOSOUND!', MSG_FATALERROR);
171-
e_WriteLog(FMOD_ErrorString(res), MSG_FATALERROR);
172-
Exit;
173-
end;
174-
res := FMOD_System_Init(F_System, N_CHANNELS, FMOD_INIT_NORMAL, nil);
189+
res := TryInitWithOutput(FMOD_OUTPUTTYPE_OSS, 'OUTPUTTYPE_OSS');
190+
{$ENDIF}
191+
if res <> FMOD_OK then
192+
res := TryInitWithOutput(FMOD_OUTPUTTYPE_NOSOUND, 'OUTPUTTYPE_NOSOUND');
175193
if res <> FMOD_OK then
176194
begin
177-
e_WriteLog('Error initializing FMOD system!', MSG_FATALERROR);
178-
e_WriteLog(FMOD_ErrorString(res), MSG_FATALERROR);
195+
e_WriteLog('FMOD: Giving up, can''t init any output.', MSG_FATALERROR);
179196
Exit;
180197
end;
181198
end;

Game Source/g_main.pas

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ procedure Main();
4949
e_WriteLog(gLanguage, MSG_NOTIFY);
5050
g_Language_Set(gLanguage);
5151

52-
if SDL_Init(SDL_INIT_JOYSTICK or SDL_INIT_TIMER or SDL_INIT_AUDIO) < 0 then
52+
if SDL_Init(SDL_INIT_EVERYTHING) < 0 then
5353
raise Exception.Create('SDL: Init failed: ' + SDL_GetError());
5454

5555
e_WriteLog('Entering SDLMain', MSG_NOTIFY);
@@ -79,7 +79,7 @@ procedure Init();
7979
if not gNoSound then
8080
begin
8181
e_WriteLog('Init FMOD', MSG_NOTIFY);
82-
e_InitSoundSystem(48000);
82+
e_InitSoundSystem(44100);
8383
end;
8484

8585
e_WriteLog('Init game', MSG_NOTIFY);
@@ -171,7 +171,7 @@ procedure Cheat();
171171

172172
s := 'SOUND_GAME_RADIO';
173173

174-
//
174+
//
175175
ls1 := CheatEng[I_GAME_CHEAT_GODMODE];
176176
ls2 := Translit(CheatRus[I_GAME_CHEAT_GODMODE]);
177177
if (Copy(charbuff, 17 - Length(ls1), Length(ls1)) = ls1) or
@@ -212,7 +212,7 @@ procedure Cheat();
212212
s := 'SOUND_MONSTER_HAHA';
213213
goto Cheated;
214214
end;
215-
//
215+
//
216216
ls1 := CheatEng[I_GAME_CHEAT_DOORS];
217217
ls2 := Translit(CheatRus[I_GAME_CHEAT_DOORS]);
218218
if (Copy(charbuff, 17 - Length(ls1), Length(ls1)) = ls1) or
@@ -237,7 +237,7 @@ procedure Cheat();
237237
end;
238238
goto Cheated;
239239
end;
240-
//
240+
//
241241
ls1 := CheatEng[I_GAME_CHEAT_CHANGEMAP];
242242
ls2 := Translit(CheatRus[I_GAME_CHEAT_CHANGEMAP]);
243243
s2 := Copy(charbuff, 15, 2);
@@ -255,7 +255,7 @@ procedure Cheat();
255255
end;
256256
goto Cheated;
257257
end;
258-
//
258+
//
259259
ls1 := CheatEng[I_GAME_CHEAT_FLY];
260260
ls2 := Translit(CheatRus[I_GAME_CHEAT_FLY]);
261261
if (Copy(charbuff, 17 - Length(ls1), Length(ls1)) = ls1) or
@@ -292,7 +292,7 @@ procedure Cheat();
292292
if gPlayer2 <> nil then gPlayer2.GiveItem(ITEM_SUIT);
293293
goto Cheated;
294294
end;
295-
//
295+
//
296296
ls1 := CheatEng[I_GAME_CHEAT_AIR];
297297
ls2 := Translit(CheatRus[I_GAME_CHEAT_AIR]);
298298
if (Copy(charbuff, 17 - Length(ls1), Length(ls1)) = ls1) or
@@ -312,7 +312,7 @@ procedure Cheat();
312312
if gPlayer2 <> nil then gPlayer2.GiveItem(ITEM_MEDKIT_BLACK);
313313
goto Cheated;
314314
end;
315-
//
315+
//
316316
ls1 := CheatEng[I_GAME_CHEAT_JETPACK];
317317
ls2 := Translit(CheatRus[I_GAME_CHEAT_JETPACK]);
318318
if (Copy(charbuff, 17 - Length(ls1), Length(ls1)) = ls1) or
@@ -332,7 +332,7 @@ procedure Cheat();
332332
if gPlayer2 <> nil then gPlayer2.SwitchNoClip;
333333
goto Cheated;
334334
end;
335-
//
335+
//
336336
ls1 := CheatEng[I_GAME_CHEAT_NOTARGET];
337337
ls2 := Translit(CheatRus[I_GAME_CHEAT_NOTARGET]);
338338
if (Copy(charbuff, 17 - Length(ls1), Length(ls1)) = ls1) or

Game Source/g_window.pas

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ interface
55
uses
66
WADEDITOR;
77

8-
function SDLMain(): Integer; StdCall;
8+
function SDLMain(): Integer;
99
function GetTimer(): Int64;
1010
procedure ResetTimer();
11-
function CreateGLWindow(Title: PChar): Boolean; StdCall;
11+
function CreateGLWindow(Title: PChar): Boolean;
1212
procedure KillGLWindow();
1313
procedure PushExitEvent();
1414
function ProcessMessage(): Boolean;
@@ -18,7 +18,7 @@ procedure SwapBuffers();
1818
procedure Sleep(ms: LongWord);
1919
function GetDisplayModes(dBPP: DWORD; var SelRes: DWORD): SArray;
2020
function g_Window_SetDisplay(): Boolean;
21-
function g_Window_SetSize(W, H: Word; FScreen: Boolean; Resize: Boolean = False): Boolean;
21+
function g_Window_SetSize(W, H: Word; FScreen: Boolean): Boolean;
2222

2323
implementation
2424

@@ -135,7 +135,7 @@ procedure ChangeWindowSize();
135135
g_Game_ClearLoading();
136136
end;
137137

138-
function g_Window_SetSize(W, H: Word; FScreen: Boolean; Resize: Boolean = False): Boolean;
138+
function g_Window_SetSize(W, H: Word; FScreen: Boolean): Boolean;
139139
var
140140
NeedResize: Boolean;
141141
begin
@@ -156,8 +156,7 @@ function g_Window_SetSize(W, H: Word; FScreen: Boolean; Resize: Boolean = False)
156156
gFullscreen := FScreen;
157157
end;
158158

159-
if not Resize then
160-
g_Window_SetDisplay();
159+
g_Window_SetDisplay();
161160

162161
if NeedResize then
163162
ChangeWindowSize();
@@ -171,7 +170,7 @@ function EventHandler(ev: TSDL_Event): Boolean;
171170
case ev.type_ of
172171
SDL_VIDEORESIZE:
173172
begin
174-
g_Window_SetSize(ev.resize.w, ev.resize.h, gFullscreen, True);
173+
g_Window_SetSize(ev.resize.w, ev.resize.h, gFullscreen);
175174
e_Clear();
176175
end;
177176

@@ -304,7 +303,7 @@ procedure KillGLWindow();
304303
wWindowCreated := False;
305304
end;
306305

307-
function CreateGLWindow(Title: PChar): Boolean; stdcall;
306+
function CreateGLWindow(Title: PChar): Boolean;
308307
var
309308
flags: LongWord;
310309
begin
@@ -481,7 +480,7 @@ procedure InitOpenGL(VSync: Boolean);
481480
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, v);
482481
end;
483482

484-
function SDLMain(): Integer; stdcall;
483+
function SDLMain(): Integer;
485484
begin
486485
e_WriteLog('Creating GL window', MSG_NOTIFY);
487486
if not CreateGLWindow(PChar(Format('Doom 2D: Forever %s', [GAME_VERSION]))) then

0 commit comments

Comments
 (0)