--- a/hedgewars/CMakeLists.txt Tue Aug 18 09:59:19 2009 +0000
+++ b/hedgewars/CMakeLists.txt Wed Aug 19 13:49:47 2009 +0000
@@ -1,7 +1,7 @@
configure_file(${hedgewars_SOURCE_DIR}/hedgewars/proto.inc.in ${CMAKE_CURRENT_BINARY_DIR}/proto.inc)
set(fpc_tryexe fpc)
-set(hwengine_project ${hedgewars_SOURCE_DIR}/hedgewars/hwengine.dpr)
+set(hwengine_project ${hedgewars_SOURCE_DIR}/hedgewars/hwengine.pas)
set(engine_sources
${hwengine_project}
--- a/hedgewars/hwengine.dpr Tue Aug 18 09:59:19 2009 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,466 +0,0 @@
- (*
- * Hedgewars, a free turn based strategy game
- * Copyright (c) 2004-2007 Andrey Korotaev <unC0Rr@gmail.com>
- *
- * 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; version 2 of the License
- *
- * 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, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- *)
-
-{$IFNDEF FPC}
-WriteLn('Only Freepascal supported');
-{$ENDIF}
-
-program hwengine;
-uses
- SDLh in 'SDLh.pas',
-{$IFDEF GLES11}
- gles11,
-{$ELSE}
- GL,
-{$ENDIF}
- uConsts in 'uConsts.pas',
- uGame in 'uGame.pas',
- uMisc in 'uMisc.pas',
- uStore in 'uStore.pas',
- uWorld in 'uWorld.pas',
- uIO in 'uIO.pas',
- uGears in 'uGears.pas',
- uVisualGears in 'uVisualGears.pas',
- uConsole in 'uConsole.pas',
- uKeys in 'uKeys.pas',
- uTeams in 'uTeams.pas',
- uSound in 'uSound.pas',
- uRandom in 'uRandom.pas',
- uAI in 'uAI.pas',
- uAIMisc in 'uAIMisc.pas',
- uAIAmmoTests in 'uAIAmmoTests.pas',
- uAIActions in 'uAIActions.pas',
- uCollisions in 'uCollisions.pas',
- uLand in 'uLand.pas',
- uLandTemplates in 'uLandTemplates.pas',
- uLandObjects in 'uLandObjects.pas',
- uLandGraphics in 'uLandGraphics.pas',
- uLocale in 'uLocale.pas',
- uAmmos in 'uAmmos.pas',
- uSHA in 'uSHA.pas',
- uFloat in 'uFloat.pas',
- uStats in 'uStats.pas',
- uChat in 'uChat.pas',
- uLandTexture in 'uLandTexture.pas';
-
-{$INCLUDE options.inc}
-
-// also: GSHandlers.inc
-// CCHandlers.inc
-// HHHandlers.inc
-// SinTable.inc
-// proto.inc
-
-var recordFileName : shortstring = '';
-
-procedure OnDestroy; forward;
-
-////////////////////////////////
-procedure DoTimer(Lag: LongInt);
-{$IFNDEF IPHONEOS}
-var s: string;
-{$ENDIF}
-begin
-inc(RealTicks, Lag);
-
-case GameState of
- gsLandGen: begin
- GenMap;
- GameState:= gsStart;
- end;
- gsStart: begin
- if HasBorder then DisableSomeWeapons;
- AddClouds;
- AssignHHCoords;
- AddMiscGears;
- StoreLoad;
- InitWorld;
- ResetKbd;
- SoundLoad;
- if GameType = gmtSave then
- begin
- isSEBackup:= isSoundEnabled;
- isSoundEnabled:= false
- end;
- FinishProgress;
- PlayMusic;
- SetScale(zoom);
- GameState:= gsGame
- end;
- gsConfirm,
- gsGame: begin
- DrawWorld(Lag); // never place between ProcessKbd and DoGameTick - bugs due to /put cmd and isCursorVisible
- ProcessKbd;
- DoGameTick(Lag);
- ProcessVisualGears(Lag);
- end;
- gsChat: begin
- DrawWorld(Lag);
- DoGameTick(Lag);
- ProcessVisualGears(Lag);
- end;
- gsExit: begin
- OnDestroy;
- end;
- end;
-
-SDL_GL_SwapBuffers();
-{$IFNDEF IPHONEOS}
-//not going to make captures on the iPhone
-if flagMakeCapture then
- begin
- flagMakeCapture:= false;
- s:= 'hw_' + cSeed + '_' + inttostr(GameTicks) + '.tga';
- WriteLnToConsole('Saving ' + s);
- MakeScreenshot(s);
-// SDL_SaveBMP_RW(SDLPrimSurface, SDL_RWFromFile(Str2PChar(s), 'wb'), 1)
- end;
-{$ENDIF}
-end;
-
-////////////////////
-procedure OnDestroy;
-begin
-{$IFDEF DEBUGFILE}AddFileLog('Freeing resources...');{$ENDIF}
-if isSoundEnabled then ReleaseSound;
-StoreRelease;
-FreeLand;
-SendKB;
-CloseIPC;
-TTF_Quit;
-SDL_Quit;
-halt
-end;
-
-////////////////////////////////
-procedure Resize(w, h: LongInt);
-begin
-cScreenWidth:= w;
-cScreenHeight:= h;
-if cFullScreen then
- ParseCommand('/fullscr 1', true)
-else
- ParseCommand('/fullscr 0', true);
-end;
-
-///////////////////
-procedure MainLoop;
-var PrevTime,
- CurrTime: Longword;
- event: TSDL_Event;
-begin
-PrevTime:= SDL_GetTicks;
-repeat
-while SDL_PollEvent(@event) <> 0 do
- case event.type_ of
- {$IFDEF IPHONEOS}
- SDL_MOUSEMOTION: WriteLnToConsole('mouse number ' + inttostr(SDL_SelectMouse(event.motion.which)) + ' over ' + inttostr(SDL_GetNumMice()));
- {$ELSE}
- SDL_KEYDOWN: if GameState = gsChat then KeyPressChat(event.key.keysym.unicode);
- {$ENDIF}
- SDL_ACTIVEEVENT: if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then
- cHasFocus:= event.active.gain = 1;
- //SDL_VIDEORESIZE: Resize(max(event.resize.w, 600), max(event.resize.h, 450));
- SDL_QUITEV: isTerminated:= true
- end;
-CurrTime:= SDL_GetTicks;
-if PrevTime + cTimerInterval <= CurrTime then
- begin
- DoTimer(CurrTime - PrevTime);
- PrevTime:= CurrTime
- end else SDL_Delay(1);
-IPCCheckSock
-until isTerminated
-end;
-
-/////////////////////
-procedure DisplayUsage;
-begin
- WriteLn('Wrong argument format: correct configurations is');
- WriteLn();
- WriteLn(' hwengine <path to data folder> <path to replay file> [option]');
- WriteLn();
- WriteLn('where [option] must be specified either as');
- WriteLn(' --set-video [screen width] [screen height] [color dept]');
- WriteLn(' --set-audio [volume] [enable music] [enable sounds]');
- WriteLn(' --set-other [language file] [full screen] [show FPS]');
- WriteLn(' --set-multimedia [screen height] [screen width] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen]');
- WriteLn(' --set-everything [screen height] [screen width] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen] [show FPS] [alternate damage] [timer value] [reduced quality]');
- WriteLn();
- WriteLn('Read documentation online at http://www.hedgewars.org/node/1465 for more information');
- halt(1);
-end;
-
-////////////////////
-procedure GetParams;
-var
-{$IFDEF DEBUGFILE}
- i: LongInt;
-{$ENDIF}
- p: TPathType;
-begin
-{$IFDEF DEBUGFILE}
-AddFileLog('Prefix: "' + PathPrefix +'"');
-for i:= 0 to ParamCount do
- AddFileLog(inttostr(i) + ': ' + ParamStr(i));
-{$ENDIF}
-
-case ParamCount of
- 16: begin
- val(ParamStr(2), cScreenWidth);
- val(ParamStr(3), cScreenHeight);
- cInitWidth:= cScreenWidth;
- cInitHeight:= cScreenHeight;
- cBitsStr:= ParamStr(4);
- val(cBitsStr, cBits);
- val(ParamStr(5), ipcPort);
- cFullScreen:= ParamStr(6) = '1';
- isSoundEnabled:= ParamStr(7) = '1';
- cLocaleFName:= ParamStr(8);
- val(ParamStr(9), cInitVolume);
- val(ParamStr(10), cTimerInterval);
- PathPrefix:= ParamStr(11);
- cShowFPS:= ParamStr(12) = '1';
- cAltDamage:= ParamStr(13) = '1';
- UserNick:= DecodeBase64(ParamStr(14));
- isMusicEnabled:= ParamStr(15) = '1';
- cReducedQuality:= ParamStr(16) = '1';
- for p:= Succ(Low(TPathType)) to High(TPathType) do
- if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p]
- end;
- {$IFDEF IPHONEOS}
- 0: begin
- PathPrefix:= 'hedgewars/Data';
- recordFileName:= 'hedgewars/save.hws';
- val('320', cScreenWidth);
- val('480', cScreenHeight);
- cInitWidth:= cScreenWidth;
- cInitHeight:= cScreenHeight;
- cBitsStr:= '32';
- val(cBitsStr, cBits);
- val('100', cInitVolume);
- isMusicEnabled:= false;
- isSoundEnabled:= false;
- cLocaleFName:= 'en.txt';
- cFullScreen:= false;
- cAltDamage:= false;
- cShowFPS:= false;
- val('8', cTimerInterval);
- cReducedQuality:= false;
-
- for p:= Succ(Low(TPathType)) to High(TPathType) do
- if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p]
- end;
- {$ENDIF}
- 3: begin
- val(ParamStr(2), ipcPort);
- GameType:= gmtLandPreview;
- if ParamStr(3) <> 'landpreview' then OutError(errmsgShouldntRun, true);
- end;
- 2: begin
- PathPrefix:= ParamStr(1);
- recordFileName:= ParamStr(2);
-
- for p:= Succ(Low(TPathType)) to High(TPathType) do
- if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p]
- end;
- 6: begin
- PathPrefix:= ParamStr(1);
- recordFileName:= ParamStr(2);
-
- if ParamStr(3) = '--set-video' then
- begin
- val(ParamStr(4), cScreenWidth);
- val(ParamStr(5), cScreenHeight);
- cInitWidth:= cScreenWidth;
- cInitHeight:= cScreenHeight;
- cBitsStr:= ParamStr(6);
- val(cBitsStr, cBits);
- end
- else
- begin
- if ParamStr(3) = '--set-audio' then
- begin
- val(ParamStr(4), cInitVolume);
- isMusicEnabled:= ParamStr(5) = '1';
- isSoundEnabled:= ParamStr(6) = '1';
- end
- else
- begin
- if ParamStr(3) = '--set-other' then
- begin
- cLocaleFName:= ParamStr(4);
- cFullScreen:= ParamStr(5) = '1';
- cShowFPS:= ParamStr(6) = '1';
- end
- else DisplayUsage;
- end
- end;
-
- for p:= Succ(Low(TPathType)) to High(TPathType) do
- if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p]
- end;
- 11: begin
- PathPrefix:= ParamStr(1);
- recordFileName:= ParamStr(2);
-
- if ParamStr(3) = '--set-multimedia' then
- begin
- val(ParamStr(4), cScreenWidth);
- val(ParamStr(5), cScreenHeight);
- cInitWidth:= cScreenWidth;
- cInitHeight:= cScreenHeight;
- cBitsStr:= ParamStr(6);
- val(cBitsStr, cBits);
- val(ParamStr(7), cInitVolume);
- isMusicEnabled:= ParamStr(8) = '1';
- isSoundEnabled:= ParamStr(9) = '1';
- cLocaleFName:= ParamStr(10);
- cFullScreen:= ParamStr(11) = '1';
- end
- else DisplayUsage;
-
- for p:= Succ(Low(TPathType)) to High(TPathType) do
- if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p]
- end;
- 15: begin
- PathPrefix:= ParamStr(1);
- recordFileName:= ParamStr(2);
- if ParamStr(3) = '--set-everything' then
- begin
- val(ParamStr(4), cScreenWidth);
- val(ParamStr(5), cScreenHeight);
- cInitWidth:= cScreenWidth;
- cInitHeight:= cScreenHeight;
- cBitsStr:= ParamStr(6);
- val(cBitsStr, cBits);
- val(ParamStr(7), cInitVolume);
- isMusicEnabled:= ParamStr(8) = '1';
- isSoundEnabled:= ParamStr(9) = '1';
- cLocaleFName:= ParamStr(10);
- cFullScreen:= ParamStr(11) = '1';
- cAltDamage:= ParamStr(12) = '1';
- cShowFPS:= ParamStr(13) = '1';
- val(ParamStr(14), cTimerInterval);
- cReducedQuality:= ParamStr(15) = '1';
- end
- else DisplayUsage;
-
- for p:= Succ(Low(TPathType)) to High(TPathType) do
- if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p]
- end;
- else DisplayUsage;
- end;
-end;
-
-/////////////////////////
-procedure ShowMainWindow;
-begin
-if cFullScreen then ParseCommand('fullscr 1', true)
- else ParseCommand('fullscr 0', true);
-SDL_ShowCursor(0)
-end;
-
-///////////////
-procedure Game;
-var s: shortstring;
-begin
-WriteToConsole('Init SDL... ');
-SDLTry(SDL_Init(SDL_INIT_VIDEO) >= 0, true);
-WriteLnToConsole(msgOK);
-
-SDL_EnableUNICODE(1);
-
-WriteToConsole('Init SDL_ttf... ');
-SDLTry(TTF_Init <> -1, true);
-WriteLnToConsole(msgOK);
-
-ShowMainWindow;
-
-InitKbdKeyTable;
-
-if recordFileName = '' then InitIPC;
-WriteLnToConsole(msgGettingConfig);
-
-if cLocaleFName <> 'en.txt' then
- LoadLocale(Pathz[ptLocale] + '/en.txt');
-LoadLocale(Pathz[ptLocale] + '/' + cLocaleFName);
-
-if recordFileName = '' then
- SendIPCAndWaitReply('C') // ask for game config
-else
- begin
- LoadRecordFromFile(recordFileName);
- end;
-
-s:= 'eproto ' + inttostr(cNetProtoVersion);
-SendIPCRaw(@s[0], Length(s) + 1); // send proto version
-
-InitTeams;
-AssignStores;
-
-if isSoundEnabled then InitSound;
-
-StoreInit;
-
-isDeveloperMode:= false;
-
-TryDo(InitStepsFlags = cifAllInited,
- 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')',
- true);
-
-MainLoop
-end;
-
-/////////////////////////
-procedure GenLandPreview;
-var Preview: TPreview;
- h: byte;
-begin
-InitIPC;
-IPCWaitPongEvent;
-TryDo(InitStepsFlags = cifRandomize,
- 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')',
- true);
-
-Preview:= GenPreview;
-WriteLnToConsole('Sending preview...');
-SendIPCRaw(@Preview, sizeof(Preview));
-h:= MaxHedgehogs;
-SendIPCRaw(@h, sizeof(h));
-WriteLnToConsole('Preview sent, disconnect');
-CloseIPC
-end;
-
-////////////////////////////////////////////////////////////////////////////////
-/////////////////////////////// m a i n ////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////
-
-begin
-WriteLnToConsole('Hedgewars ' + cVersionString + ' engine');
-GetParams;
-// FIXME - hack in font with support for CJK
-if (cLocaleFName = 'zh_CN.txt') or (cLocaleFName = 'zh_TW.txt') or (cLocaleFName = 'ja.txt') then
- Fontz:= FontzCJK;
-
-Randomize;
-
-if GameType = gmtLandPreview then GenLandPreview
- else Game
-end.
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hedgewars/hwengine.pas Wed Aug 19 13:49:47 2009 +0000
@@ -0,0 +1,466 @@
+ (*
+ * Hedgewars, a free turn based strategy game
+ * Copyright (c) 2004-2007 Andrey Korotaev <unC0Rr@gmail.com>
+ *
+ * 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; version 2 of the License
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *)
+
+{$IFNDEF FPC}
+WriteLn('Only Freepascal supported');
+{$ENDIF}
+
+program hwengine;
+uses
+ SDLh in 'SDLh.pas',
+{$IFDEF GLES11}
+ gles11,
+{$ELSE}
+ GL,
+{$ENDIF}
+ uConsts in 'uConsts.pas',
+ uGame in 'uGame.pas',
+ uMisc in 'uMisc.pas',
+ uStore in 'uStore.pas',
+ uWorld in 'uWorld.pas',
+ uIO in 'uIO.pas',
+ uGears in 'uGears.pas',
+ uVisualGears in 'uVisualGears.pas',
+ uConsole in 'uConsole.pas',
+ uKeys in 'uKeys.pas',
+ uTeams in 'uTeams.pas',
+ uSound in 'uSound.pas',
+ uRandom in 'uRandom.pas',
+ uAI in 'uAI.pas',
+ uAIMisc in 'uAIMisc.pas',
+ uAIAmmoTests in 'uAIAmmoTests.pas',
+ uAIActions in 'uAIActions.pas',
+ uCollisions in 'uCollisions.pas',
+ uLand in 'uLand.pas',
+ uLandTemplates in 'uLandTemplates.pas',
+ uLandObjects in 'uLandObjects.pas',
+ uLandGraphics in 'uLandGraphics.pas',
+ uLocale in 'uLocale.pas',
+ uAmmos in 'uAmmos.pas',
+ uSHA in 'uSHA.pas',
+ uFloat in 'uFloat.pas',
+ uStats in 'uStats.pas',
+ uChat in 'uChat.pas',
+ uLandTexture in 'uLandTexture.pas';
+
+{$INCLUDE options.inc}
+
+// also: GSHandlers.inc
+// CCHandlers.inc
+// HHHandlers.inc
+// SinTable.inc
+// proto.inc
+
+var recordFileName : shortstring = '';
+
+procedure OnDestroy; forward;
+
+////////////////////////////////
+procedure DoTimer(Lag: LongInt);
+{$IFNDEF IPHONEOS}
+var s: string;
+{$ENDIF}
+begin
+inc(RealTicks, Lag);
+
+case GameState of
+ gsLandGen: begin
+ GenMap;
+ GameState:= gsStart;
+ end;
+ gsStart: begin
+ if HasBorder then DisableSomeWeapons;
+ AddClouds;
+ AssignHHCoords;
+ AddMiscGears;
+ StoreLoad;
+ InitWorld;
+ ResetKbd;
+ SoundLoad;
+ if GameType = gmtSave then
+ begin
+ isSEBackup:= isSoundEnabled;
+ isSoundEnabled:= false
+ end;
+ FinishProgress;
+ PlayMusic;
+ SetScale(zoom);
+ GameState:= gsGame
+ end;
+ gsConfirm,
+ gsGame: begin
+ DrawWorld(Lag); // never place between ProcessKbd and DoGameTick - bugs due to /put cmd and isCursorVisible
+ ProcessKbd;
+ DoGameTick(Lag);
+ ProcessVisualGears(Lag);
+ end;
+ gsChat: begin
+ DrawWorld(Lag);
+ DoGameTick(Lag);
+ ProcessVisualGears(Lag);
+ end;
+ gsExit: begin
+ OnDestroy;
+ end;
+ end;
+
+SDL_GL_SwapBuffers();
+{$IFNDEF IPHONEOS}
+//not going to make captures on the iPhone
+if flagMakeCapture then
+ begin
+ flagMakeCapture:= false;
+ s:= 'hw_' + cSeed + '_' + inttostr(GameTicks) + '.tga';
+ WriteLnToConsole('Saving ' + s);
+ MakeScreenshot(s);
+// SDL_SaveBMP_RW(SDLPrimSurface, SDL_RWFromFile(Str2PChar(s), 'wb'), 1)
+ end;
+{$ENDIF}
+end;
+
+////////////////////
+procedure OnDestroy;
+begin
+{$IFDEF DEBUGFILE}AddFileLog('Freeing resources...');{$ENDIF}
+if isSoundEnabled then ReleaseSound;
+StoreRelease;
+FreeLand;
+SendKB;
+CloseIPC;
+TTF_Quit;
+SDL_Quit;
+halt
+end;
+
+////////////////////////////////
+procedure Resize(w, h: LongInt);
+begin
+cScreenWidth:= w;
+cScreenHeight:= h;
+if cFullScreen then
+ ParseCommand('/fullscr 1', true)
+else
+ ParseCommand('/fullscr 0', true);
+end;
+
+///////////////////
+procedure MainLoop;
+var PrevTime,
+ CurrTime: Longword;
+ event: TSDL_Event;
+begin
+PrevTime:= SDL_GetTicks;
+repeat
+while SDL_PollEvent(@event) <> 0 do
+ case event.type_ of
+ {$IFDEF IPHONEOS}
+ SDL_MOUSEMOTION: WriteLnToConsole('mouse number ' + inttostr(SDL_SelectMouse(event.motion.which)) + ' over ' + inttostr(SDL_GetNumMice()));
+ {$ELSE}
+ SDL_KEYDOWN: if GameState = gsChat then KeyPressChat(event.key.keysym.unicode);
+ {$ENDIF}
+ SDL_ACTIVEEVENT: if (event.active.state and SDL_APPINPUTFOCUS) <> 0 then
+ cHasFocus:= event.active.gain = 1;
+ //SDL_VIDEORESIZE: Resize(max(event.resize.w, 600), max(event.resize.h, 450));
+ SDL_QUITEV: isTerminated:= true
+ end;
+CurrTime:= SDL_GetTicks;
+if PrevTime + cTimerInterval <= CurrTime then
+ begin
+ DoTimer(CurrTime - PrevTime);
+ PrevTime:= CurrTime
+ end else SDL_Delay(1);
+IPCCheckSock
+until isTerminated
+end;
+
+/////////////////////
+procedure DisplayUsage;
+begin
+ WriteLn('Wrong argument format: correct configurations is');
+ WriteLn();
+ WriteLn(' hwengine <path to data folder> <path to replay file> [option]');
+ WriteLn();
+ WriteLn('where [option] must be specified either as');
+ WriteLn(' --set-video [screen width] [screen height] [color dept]');
+ WriteLn(' --set-audio [volume] [enable music] [enable sounds]');
+ WriteLn(' --set-other [language file] [full screen] [show FPS]');
+ WriteLn(' --set-multimedia [screen height] [screen width] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen]');
+ WriteLn(' --set-everything [screen height] [screen width] [color dept] [volume] [enable music] [enable sounds] [language file] [full screen] [show FPS] [alternate damage] [timer value] [reduced quality]');
+ WriteLn();
+ WriteLn('Read documentation online at http://www.hedgewars.org/node/1465 for more information');
+ halt(1);
+end;
+
+////////////////////
+procedure GetParams;
+var
+{$IFDEF DEBUGFILE}
+ i: LongInt;
+{$ENDIF}
+ p: TPathType;
+begin
+{$IFDEF DEBUGFILE}
+AddFileLog('Prefix: "' + PathPrefix +'"');
+for i:= 0 to ParamCount do
+ AddFileLog(inttostr(i) + ': ' + ParamStr(i));
+{$ENDIF}
+
+case ParamCount of
+ 16: begin
+ val(ParamStr(2), cScreenWidth);
+ val(ParamStr(3), cScreenHeight);
+ cInitWidth:= cScreenWidth;
+ cInitHeight:= cScreenHeight;
+ cBitsStr:= ParamStr(4);
+ val(cBitsStr, cBits);
+ val(ParamStr(5), ipcPort);
+ cFullScreen:= ParamStr(6) = '1';
+ isSoundEnabled:= ParamStr(7) = '1';
+ cLocaleFName:= ParamStr(8);
+ val(ParamStr(9), cInitVolume);
+ val(ParamStr(10), cTimerInterval);
+ PathPrefix:= ParamStr(11);
+ cShowFPS:= ParamStr(12) = '1';
+ cAltDamage:= ParamStr(13) = '1';
+ UserNick:= DecodeBase64(ParamStr(14));
+ isMusicEnabled:= ParamStr(15) = '1';
+ cReducedQuality:= ParamStr(16) = '1';
+ for p:= Succ(Low(TPathType)) to High(TPathType) do
+ if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p]
+ end;
+ {$IFDEF IPHONEOS}
+ 0: begin
+ PathPrefix:= 'hedgewars/Data';
+ recordFileName:= 'hedgewars/save.hws';
+ val('320', cScreenWidth);
+ val('480', cScreenHeight);
+ cInitWidth:= cScreenWidth;
+ cInitHeight:= cScreenHeight;
+ cBitsStr:= '32';
+ val(cBitsStr, cBits);
+ val('100', cInitVolume);
+ isMusicEnabled:= false;
+ isSoundEnabled:= false;
+ cLocaleFName:= 'en.txt';
+ cFullScreen:= false;
+ cAltDamage:= false;
+ cShowFPS:= false;
+ val('8', cTimerInterval);
+ cReducedQuality:= false;
+
+ for p:= Succ(Low(TPathType)) to High(TPathType) do
+ if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p]
+ end;
+ {$ENDIF}
+ 3: begin
+ val(ParamStr(2), ipcPort);
+ GameType:= gmtLandPreview;
+ if ParamStr(3) <> 'landpreview' then OutError(errmsgShouldntRun, true);
+ end;
+ 2: begin
+ PathPrefix:= ParamStr(1);
+ recordFileName:= ParamStr(2);
+
+ for p:= Succ(Low(TPathType)) to High(TPathType) do
+ if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p]
+ end;
+ 6: begin
+ PathPrefix:= ParamStr(1);
+ recordFileName:= ParamStr(2);
+
+ if ParamStr(3) = '--set-video' then
+ begin
+ val(ParamStr(4), cScreenWidth);
+ val(ParamStr(5), cScreenHeight);
+ cInitWidth:= cScreenWidth;
+ cInitHeight:= cScreenHeight;
+ cBitsStr:= ParamStr(6);
+ val(cBitsStr, cBits);
+ end
+ else
+ begin
+ if ParamStr(3) = '--set-audio' then
+ begin
+ val(ParamStr(4), cInitVolume);
+ isMusicEnabled:= ParamStr(5) = '1';
+ isSoundEnabled:= ParamStr(6) = '1';
+ end
+ else
+ begin
+ if ParamStr(3) = '--set-other' then
+ begin
+ cLocaleFName:= ParamStr(4);
+ cFullScreen:= ParamStr(5) = '1';
+ cShowFPS:= ParamStr(6) = '1';
+ end
+ else DisplayUsage;
+ end
+ end;
+
+ for p:= Succ(Low(TPathType)) to High(TPathType) do
+ if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p]
+ end;
+ 11: begin
+ PathPrefix:= ParamStr(1);
+ recordFileName:= ParamStr(2);
+
+ if ParamStr(3) = '--set-multimedia' then
+ begin
+ val(ParamStr(4), cScreenWidth);
+ val(ParamStr(5), cScreenHeight);
+ cInitWidth:= cScreenWidth;
+ cInitHeight:= cScreenHeight;
+ cBitsStr:= ParamStr(6);
+ val(cBitsStr, cBits);
+ val(ParamStr(7), cInitVolume);
+ isMusicEnabled:= ParamStr(8) = '1';
+ isSoundEnabled:= ParamStr(9) = '1';
+ cLocaleFName:= ParamStr(10);
+ cFullScreen:= ParamStr(11) = '1';
+ end
+ else DisplayUsage;
+
+ for p:= Succ(Low(TPathType)) to High(TPathType) do
+ if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p]
+ end;
+ 15: begin
+ PathPrefix:= ParamStr(1);
+ recordFileName:= ParamStr(2);
+ if ParamStr(3) = '--set-everything' then
+ begin
+ val(ParamStr(4), cScreenWidth);
+ val(ParamStr(5), cScreenHeight);
+ cInitWidth:= cScreenWidth;
+ cInitHeight:= cScreenHeight;
+ cBitsStr:= ParamStr(6);
+ val(cBitsStr, cBits);
+ val(ParamStr(7), cInitVolume);
+ isMusicEnabled:= ParamStr(8) = '1';
+ isSoundEnabled:= ParamStr(9) = '1';
+ cLocaleFName:= ParamStr(10);
+ cFullScreen:= ParamStr(11) = '1';
+ cAltDamage:= ParamStr(12) = '1';
+ cShowFPS:= ParamStr(13) = '1';
+ val(ParamStr(14), cTimerInterval);
+ cReducedQuality:= ParamStr(15) = '1';
+ end
+ else DisplayUsage;
+
+ for p:= Succ(Low(TPathType)) to High(TPathType) do
+ if p <> ptMapCurrent then Pathz[p]:= PathPrefix + '/' + Pathz[p]
+ end;
+ else DisplayUsage;
+ end;
+end;
+
+/////////////////////////
+procedure ShowMainWindow;
+begin
+if cFullScreen then ParseCommand('fullscr 1', true)
+ else ParseCommand('fullscr 0', true);
+SDL_ShowCursor(0)
+end;
+
+///////////////
+procedure Game;
+var s: shortstring;
+begin
+WriteToConsole('Init SDL... ');
+SDLTry(SDL_Init(SDL_INIT_VIDEO) >= 0, true);
+WriteLnToConsole(msgOK);
+
+SDL_EnableUNICODE(1);
+
+WriteToConsole('Init SDL_ttf... ');
+SDLTry(TTF_Init <> -1, true);
+WriteLnToConsole(msgOK);
+
+ShowMainWindow;
+
+InitKbdKeyTable;
+
+if recordFileName = '' then InitIPC;
+WriteLnToConsole(msgGettingConfig);
+
+if cLocaleFName <> 'en.txt' then
+ LoadLocale(Pathz[ptLocale] + '/en.txt');
+LoadLocale(Pathz[ptLocale] + '/' + cLocaleFName);
+
+if recordFileName = '' then
+ SendIPCAndWaitReply('C') // ask for game config
+else
+ begin
+ LoadRecordFromFile(recordFileName);
+ end;
+
+s:= 'eproto ' + inttostr(cNetProtoVersion);
+SendIPCRaw(@s[0], Length(s) + 1); // send proto version
+
+InitTeams;
+AssignStores;
+
+if isSoundEnabled then InitSound;
+
+StoreInit;
+
+isDeveloperMode:= false;
+
+TryDo(InitStepsFlags = cifAllInited,
+ 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')',
+ true);
+
+MainLoop
+end;
+
+/////////////////////////
+procedure GenLandPreview;
+var Preview: TPreview;
+ h: byte;
+begin
+InitIPC;
+IPCWaitPongEvent;
+TryDo(InitStepsFlags = cifRandomize,
+ 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')',
+ true);
+
+Preview:= GenPreview;
+WriteLnToConsole('Sending preview...');
+SendIPCRaw(@Preview, sizeof(Preview));
+h:= MaxHedgehogs;
+SendIPCRaw(@h, sizeof(h));
+WriteLnToConsole('Preview sent, disconnect');
+CloseIPC
+end;
+
+////////////////////////////////////////////////////////////////////////////////
+/////////////////////////////// m a i n ////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
+
+begin
+WriteLnToConsole('Hedgewars ' + cVersionString + ' engine');
+GetParams;
+// FIXME - hack in font with support for CJK
+if (cLocaleFName = 'zh_CN.txt') or (cLocaleFName = 'zh_TW.txt') or (cLocaleFName = 'ja.txt') then
+ Fontz:= FontzCJK;
+
+Randomize;
+
+if GameType = gmtLandPreview then GenLandPreview
+ else Game
+end.
+
--- a/openalbridge/CMakeLists.txt Tue Aug 18 09:59:19 2009 +0000
+++ b/openalbridge/CMakeLists.txt Wed Aug 19 13:49:47 2009 +0000
@@ -8,7 +8,7 @@
#list of source files for libraries
set(openal_src
- openalwrap.c loaders.c endianness.c wrappers.c
+ openalbridge.c loaders.c endianness.c wrappers.c
)
#build a static library for human systems
@@ -18,7 +18,7 @@
if(WIN32)
#workaround for visualstudio (wants headers in the source list)
set(openal_src
- openalwrap.h loaders.h endianness.h wrappers.h globals.h oggvorbis.h ${openal_src}
+ openalbridge.h loaders.h endianness.h wrappers.h globals.h oggvorbis.h ${openal_src}
)
#deps for the shared library
link_libraries(${OPENAL_LIBRARY})
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/openalbridge/openalbridge.c Wed Aug 19 13:49:47 2009 +0000
@@ -0,0 +1,464 @@
+/*
+ * OpenAL Bridge - a simple portable library for OpenAL interface
+ * Copyright (c) 2009 Vittorio Giovara <vittorio.giovara@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#include "openalbridge.h"
+#include "wrappers.h"
+#include "alc.h"
+#include "loaders.h"
+#include "endianness.h"
+
+#ifdef __CPLUSPLUS
+extern "C" {
+#endif
+
+ /*Sources are points emitting sound*/
+ ALuint *Sources;
+ /*Buffers hold sound data*/
+ ALuint *Buffers;
+ /*index for Sources and Buffers*/
+ ALuint globalindex, globalsize, increment;
+
+ ALboolean openalReady = AL_FALSE;
+
+ ALboolean openal_close (void) {
+ /*Stop all sounds, deallocate all memory and close OpenAL */
+ ALCcontext *context;
+ ALCdevice *device;
+
+ if(openalReady == AL_FALSE) {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+
+ alSourceStopv (globalsize, Sources);
+ alDeleteSources (globalsize, Sources);
+ alDeleteBuffers (globalsize, Buffers);
+
+ free(Sources);
+ free(Buffers);
+
+ context = alcGetCurrentContext();
+ device = alcGetContextsDevice(context);
+
+ alcMakeContextCurrent(NULL);
+ alcDestroyContext(context);
+ alcCloseDevice(device);
+
+ openalReady = AL_FALSE;
+
+ return AL_TRUE;
+ }
+
+ ALboolean openal_ready(void) {
+ return openalReady;
+ }
+
+ ALboolean openal_init(uint32_t memorysize) {
+ /*Initialize an OpenAL contex and allocate memory space for data and buffers*/
+ ALCcontext *context;
+ ALCdevice *device;
+ const ALCchar *default_device;
+
+ /*Position of the listener*/
+ ALfloat ListenerPos[] = { 0.0, 0.0, 0.0 };
+ /*Velocity of the listener*/
+ ALfloat ListenerVel[] = { 0.0, 0.0, 0.0 };
+ /*Orientation of the listener. (first 3 elements are "at", second 3 are "up")*/
+ ALfloat ListenerOri[] = { 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 };
+
+ if(openalReady == AL_TRUE) {
+ fprintf(stderr, "ERROR: OpenAL already initialized\n");
+ return AL_FALSE;
+ }
+
+ default_device = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
+ fprintf(stderr, "Using default device: %s\n", default_device);
+
+ if ((device = alcOpenDevice(default_device)) == NULL) {
+ fprintf(stderr, "ERROR: Failed to open sound device\n");
+ return AL_FALSE;
+ }
+
+ context = alcCreateContext(device, NULL);
+ alcMakeContextCurrent(context);
+ alcProcessContext(context);
+
+ if (AlGetError("ERROR %d: Creating a new contex\n") != AL_TRUE)
+ return AL_FALSE;
+
+ /*allocate memory space for buffers and sources*/
+ if (memorysize == 0)
+ globalsize = 50;
+ else
+ globalsize = memorysize;
+ increment = globalsize;
+ Buffers = (ALuint*) Malloc(sizeof(ALuint)*globalsize);
+ Sources = (ALuint*) Malloc(sizeof(ALuint)*globalsize);
+
+ /*set the listener gain, position (on xyz axes), velocity (one value for each axe) and orientation*/
+ alListenerf (AL_GAIN, 1.0f );
+ alListenerfv(AL_POSITION, ListenerPos);
+ alListenerfv(AL_VELOCITY, ListenerVel);
+ alListenerfv(AL_ORIENTATION, ListenerOri);
+
+ if (AlGetError("ERROR %d: Setting Listener properties\n") != AL_TRUE)
+ return AL_FALSE;
+
+ openalReady = AL_TRUE;
+
+ alGetError(); /* clear any AL errors beforehand */
+ return AL_TRUE;
+ }
+
+
+ ALboolean helper_realloc (void) {
+ /*expands allocated memory when loading more sound files than expected*/
+ int oldsize = globalsize;
+ globalsize += increment;
+
+#ifdef DEBUG
+ fprintf(stderr, "OpenAL: Realloc in process from %d to %d\n", oldsize, globalsize);
+#endif
+
+ Buffers = (ALuint*) Realloc(Buffers, sizeof(ALuint)*globalsize);
+ Sources = (ALuint*) Realloc(Sources, sizeof(ALuint)*globalsize);
+
+ return AL_TRUE;
+ }
+
+
+ ALint openal_loadfile (const char *filename){
+ /*Open a file, load into memory and allocate the Source buffer for playing*/
+ ALfloat SourcePos[] = { 0.0, 0.0, 0.0 }; /*Position of the source sound*/
+ ALfloat SourceVel[] = { 0.0, 0.0, 0.0 }; /*Velocity of the source sound*/
+ ALenum format;
+ ALsizei bitsize, freq;
+ char *data;
+ uint32_t fileformat;
+ ALenum error;
+ FILE *fp;
+
+ if(openalReady == AL_FALSE) {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+
+ /*when the buffers are all used, we can expand memory to accept new files*/
+ if (globalindex == globalsize)
+ helper_realloc();
+
+ /*detect the file format, as written in the first 4 bytes of the header*/
+ fp = Fopen (filename, "rb");
+ if (fp == NULL)
+ return -1;
+ error = fread (&fileformat, sizeof(uint32_t), 1, fp);
+ fclose (fp);
+
+ if (error < 0) {
+ fprintf(stderr, "ERROR: file %s is too short \n", filename);
+ return -2;
+ }
+
+ /*prepare the buffer to receive data*/
+ alGenBuffers(1, &Buffers[globalindex]);
+
+ if (AlGetError("ERROR %d: Allocating memory for buffers\n") != AL_TRUE)
+ return -3;
+
+ /*prepare the source to emit sound*/
+ alGenSources(1, &Sources[globalindex]);
+
+ if (AlGetError("ERROR %d: Allocating memory for sources\n") != AL_TRUE)
+ return -4;
+
+
+ if (fileformat == 0x5367674F) /*check if ogg*/
+ error = load_oggvorbis (filename, &format, &data, &bitsize, &freq);
+ else {
+ if (fileformat == 0x46464952) /*check if wav*/
+ error = load_wavpcm (filename, &format, &data, &bitsize, &freq);
+ else {
+ fprintf(stderr, "ERROR: File format (%08X) not supported!\n", invert_endianness(fileformat));
+ return -5;
+ }
+ }
+
+ /*copy pcm data in one buffer*/
+ alBufferData(Buffers[globalindex], format, data, bitsize, freq);
+ free(data); /*deallocate data to save memory*/
+
+ if (AlGetError("ERROR %d: Writing data to buffer\n") != AL_TRUE)
+ return -6;
+
+ /*set source properties that it will use when it's in playback*/
+ alSourcei (Sources[globalindex], AL_BUFFER, Buffers[globalindex] );
+ alSourcef (Sources[globalindex], AL_PITCH, 1.0f );
+ alSourcef (Sources[globalindex], AL_GAIN, 1.0f );
+ alSourcefv(Sources[globalindex], AL_POSITION, SourcePos );
+ alSourcefv(Sources[globalindex], AL_VELOCITY, SourceVel );
+ alSourcei (Sources[globalindex], AL_LOOPING, 0 );
+
+ if (AlGetError("ERROR %d: Setting source properties\n") != AL_TRUE)
+ return -7;
+
+ alGetError(); /* clear any AL errors beforehand */
+
+ /*returns the index of the source you just loaded, increments it and exits*/
+ return globalindex++;
+ }
+
+
+ ALboolean openal_toggleloop (uint32_t index){
+ /*Set or unset looping mode*/
+ ALint loop;
+
+ if(openalReady == AL_FALSE) {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+
+ if (index >= globalsize) {
+ fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
+ return AL_FALSE;
+ }
+
+ alGetSourcei (Sources[index], AL_LOOPING, &loop);
+ alSourcei (Sources[index], AL_LOOPING, !((uint8_t) loop) & 0x00000001);
+ if (AlGetError("ERROR %d: Getting or setting loop property\n") != AL_TRUE)
+ return AL_FALSE;
+
+ alGetError(); /* clear any AL errors beforehand */
+
+ return AL_TRUE;
+ }
+
+
+ ALboolean openal_setvolume (uint32_t index, uint8_t percentage) {
+ if(openalReady == AL_FALSE) {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+
+ /*Set volume for sound number index*/
+ if (index >= globalindex) {
+ fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
+ return AL_FALSE;
+ }
+
+ if (percentage > 100)
+ percentage = 100;
+ alSourcef (Sources[index], AL_GAIN, (float) percentage/100.0f);
+ if (AlGetError2("ERROR %d: setting volume for sound %d\n", index) != AL_TRUE)
+ return AL_FALSE;
+
+ alGetError(); /* clear any AL errors beforehand */
+
+ return AL_TRUE;
+ }
+
+
+ ALboolean openal_setglobalvolume (uint8_t percentage) {
+ if(openalReady == AL_FALSE) {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+
+ /*Set volume for all sounds*/
+ if (percentage > 100)
+ percentage = 100;
+ alListenerf (AL_GAIN, (float) percentage/100.0f);
+ if (AlGetError("ERROR %d: Setting global volume\n") != AL_TRUE)
+ return AL_FALSE;
+
+ alGetError(); /* clear any AL errors beforehand */
+
+ return AL_TRUE;
+ }
+
+
+ ALboolean openal_togglemute () {
+ /*Mute or unmute sound*/
+ ALfloat mute;
+
+ if(openalReady == AL_FALSE) {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+
+ alGetListenerf (AL_GAIN, &mute);
+ if (mute > 0)
+ mute = 0;
+ else
+ mute = 1.0;
+ alListenerf (AL_GAIN, mute);
+ if (AlGetError("ERROR %d: Setting mute property\n") != AL_TRUE)
+ return AL_FALSE;
+
+ alGetError(); /* clear any AL errors beforehand */
+
+ return AL_TRUE;
+ }
+
+
+ ALboolean openal_fade (uint32_t index, uint16_t quantity, ALboolean direction) {
+ /*Fade in or out by calling a helper thread*/
+#ifndef _WIN32
+ pthread_t thread;
+#else
+ HANDLE Thread;
+ DWORD threadID;
+#endif
+ fade_t *fade;
+
+ if(openalReady == AL_FALSE) {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+
+ fade = (fade_t*) Malloc(sizeof(fade_t));
+ fade->index = index;
+ fade->quantity = quantity;
+
+ if (index >= globalindex) {
+ fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
+ return AL_FALSE;
+ }
+
+ if (direction == FADE_IN)
+#ifndef _WIN32
+ pthread_create(&thread, NULL, helper_fadein, (void*) fade);
+#else
+ Thread = _beginthread(&helper_fadein, 0, (void*) fade);
+#endif
+ else {
+ if (direction == FADE_OUT)
+#ifndef _WIN32
+ pthread_create(&thread, NULL, helper_fadeout, (void*) fade);
+#else
+ Thread = _beginthread(&helper_fadeout, 0, (void*) fade);
+#endif
+ else {
+ fprintf(stderr, "ERROR: unknown direction for fade (%d)\n", direction);
+ free(fade);
+ return AL_FALSE;
+ }
+ }
+
+#ifndef _WIN32
+ pthread_detach(thread);
+#endif
+
+ alGetError(); /* clear any AL errors beforehand */
+
+ return AL_TRUE;
+ }
+
+
+ ALboolean openal_fadeout (uint32_t index, uint16_t quantity) {
+ /*wrapper for fadeout*/
+ return openal_fade(index, quantity, FADE_OUT);
+ }
+
+
+ ALboolean openal_fadein (uint32_t index, uint16_t quantity) {
+ /*wrapper for fadein*/
+ return openal_fade(index, quantity, FADE_IN);
+ }
+
+
+ ALboolean openal_setposition (uint32_t index, float x, float y, float z) {
+ if(openalReady == AL_FALSE) {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+ if (index >= globalindex) {
+ fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
+ return AL_FALSE;
+ }
+
+ alSource3f(Sources[index], AL_POSITION, x, y, z);
+ if (AlGetError2("ERROR %d: setting position for sound %d\n", index) != AL_TRUE)
+ return AL_FALSE;
+
+ return AL_TRUE;
+ }
+
+
+ ALboolean openal_playsound (uint32_t index){
+ if(openalReady == AL_FALSE) {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+
+ /*Play sound number index*/
+ if (index >= globalindex) {
+ fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
+ return AL_FALSE;
+ }
+ alSourcePlay(Sources[index]);
+ if (AlGetError2("ERROR %d: Playing sound %d\n", index) != AL_TRUE)
+ return AL_FALSE;
+
+ alGetError(); /* clear any AL errors beforehand */
+
+ return AL_TRUE;
+ }
+
+
+ ALboolean openal_pausesound(uint32_t index){
+ if(openalReady == AL_FALSE) {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+
+ /*Pause sound number index*/
+ if (index >= globalindex) {
+ fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
+ return AL_FALSE;
+ }
+ alSourcePause(Sources[index]);
+ if (AlGetError2("ERROR %d: Pausing sound %d\n", index) != AL_TRUE)
+ return AL_FALSE;
+
+ return AL_TRUE;
+ }
+
+
+ ALboolean openal_stopsound(uint32_t index){
+ if(openalReady == AL_FALSE) {
+ fprintf(stderr, "ERROR: OpenAL not initialized\n");
+ return AL_FALSE;
+ }
+
+ /*Stop sound number index*/
+ if (index >= globalindex) {
+ fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
+ return AL_FALSE;
+ }
+ alSourceStop(Sources[index]);
+ if (AlGetError2("ERROR %d: Stopping sound %d\n", index) != AL_TRUE)
+ return AL_FALSE;
+
+ alGetError(); /* clear any AL errors beforehand */
+
+ return AL_TRUE;
+ }
+
+#ifdef __CPLUSPLUS
+}
+#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/openalbridge/openalbridge.h Wed Aug 19 13:49:47 2009 +0000
@@ -0,0 +1,47 @@
+/*
+ * OpenAL Bridge - a simple portable library for OpenAL interface
+ * Copyright (c) 2009 Vittorio Giovara <vittorio.giovara@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; version 2 of the License
+ *
+ * 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+
+#ifndef _OALB_INTERFACE_H
+#define _OALB_INTERFACE_H
+
+#include "globals.h"
+
+#ifdef __CPLUSPLUS
+extern "C" {
+#endif
+
+ ALboolean openal_init (unsigned int memorysize);
+ ALboolean openal_close (void);
+ ALint openal_loadfile (const char *filename);
+ ALboolean openal_toggleloop (unsigned int index);
+ ALboolean openal_setposition (unsigned int index, float x, float y, float z);
+ ALboolean openal_setvolume (unsigned int index, unsigned char percentage);
+ ALboolean openal_setglobalvolume (unsigned char percentage);
+ ALboolean openal_togglemute (void);
+ ALboolean openal_fadeout (unsigned int index, unsigned short int quantity);
+ ALboolean openal_fadein (unsigned int index, unsigned short int quantity);
+ ALboolean openal_fade (unsigned int index, unsigned short int quantity, ALboolean direction);
+ ALboolean openal_playsound (unsigned int index);
+ ALboolean openal_pausesound (unsigned int index);
+ ALboolean openal_stopsound (unsigned int index);
+
+#ifdef __CPLUSPLUS
+}
+#endif
+
+#endif /*_OALB_INTERFACE_H*/
--- a/openalbridge/openalwrap.c Tue Aug 18 09:59:19 2009 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,461 +0,0 @@
-/*
- * OpenAL Bridge - a simple portable library for OpenAL interface
- * Copyright (c) 2009 Vittorio Giovara <vittorio.giovara@gmail.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; version 2 of the License
- *
- * 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 Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-
-#include "openalwrap.h"
-#include "wrappers.h"
-#include "alc.h"
-#include "loaders.h"
-#include "endianness.h"
-
-#ifdef __CPLUSPLUS
-extern "C" {
-#endif
-
- /*Sources are points emitting sound*/
- ALuint *Sources;
- /*Buffers hold sound data*/
- ALuint *Buffers;
- /*index for Sources and Buffers*/
- ALuint globalindex, globalsize, increment;
-
- ALboolean openalReady = AL_FALSE;
-
- ALboolean openal_close (void) {
- /*Stop all sounds, deallocate all memory and close OpenAL */
- ALCcontext *context;
- ALCdevice *device;
-
- if(openalReady == AL_FALSE) {
- fprintf(stderr, "ERROR: OpenAL not initialized\n");
- return AL_FALSE;
- }
-
- alSourceStopv (globalsize, Sources);
- alDeleteSources (globalsize, Sources);
- alDeleteBuffers (globalsize, Buffers);
-
- free(Sources);
- free(Buffers);
-
- context = alcGetCurrentContext();
- device = alcGetContextsDevice(context);
-
- alcMakeContextCurrent(NULL);
- alcDestroyContext(context);
- alcCloseDevice(device);
-
- openalReady = AL_FALSE;
-
- return AL_TRUE;
- }
-
- ALboolean openal_ready(void) {
- return openalReady;
- }
-
- ALboolean openal_init(uint32_t memorysize) {
- /*Initialize an OpenAL contex and allocate memory space for data and buffers*/
- ALCcontext *context;
- ALCdevice *device;
- const ALCchar *default_device;
-
- /*Position of the listener*/
- ALfloat ListenerPos[] = { 0.0, 0.0, 0.0 };
- /*Velocity of the listener*/
- ALfloat ListenerVel[] = { 0.0, 0.0, 0.0 };
- /*Orientation of the listener. (first 3 elements are "at", second 3 are "up")*/
- ALfloat ListenerOri[] = { 0.0, 0.0, -1.0, 0.0, 1.0, 0.0 };
-
- if(openalReady == AL_TRUE) {
- fprintf(stderr, "ERROR: OpenAL already initialized\n");
- return AL_FALSE;
- }
-
- default_device = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
- fprintf(stderr, "Using default device: %s\n", default_device);
-
- if ((device = alcOpenDevice(default_device)) == NULL) {
- fprintf(stderr, "ERROR: Failed to open sound device\n");
- return AL_FALSE;
- }
-
- context = alcCreateContext(device, NULL);
- alcMakeContextCurrent(context);
- alcProcessContext(context);
-
- if (AlGetError("ERROR %d: Creating a new contex\n") != AL_TRUE)
- return AL_FALSE;
-
- /*allocate memory space for buffers and sources*/
- globalsize = memorysize;
- increment = memorysize;
- Buffers = (ALuint*) Malloc(sizeof(ALuint)*globalsize);
- Sources = (ALuint*) Malloc(sizeof(ALuint)*globalsize);
-
- /*set the listener gain, position (on xyz axes), velocity (one value for each axe) and orientation*/
- alListenerf (AL_GAIN, 1.0f );
- alListenerfv(AL_POSITION, ListenerPos);
- alListenerfv(AL_VELOCITY, ListenerVel);
- alListenerfv(AL_ORIENTATION, ListenerOri);
-
- if (AlGetError("ERROR %d: Setting Listener properties\n") != AL_TRUE)
- return AL_FALSE;
-
- openalReady = AL_TRUE;
-
- alGetError(); /* clear any AL errors beforehand */
- return AL_TRUE;
- }
-
-
- ALboolean helper_realloc (void) {
- /*expands allocated memory when loading more sound files than expected*/
- int oldsize = globalsize;
- globalsize += increment;
-
-#ifdef DEBUG
- fprintf(stderr, "OpenAL: Realloc in process from %d to %d\n", oldsize, globalsize);
-#endif
-
- Buffers = (ALuint*) Realloc(Buffers, sizeof(ALuint)*globalsize);
- Sources = (ALuint*) Realloc(Sources, sizeof(ALuint)*globalsize);
-
- return AL_TRUE;
- }
-
-
- ALint openal_loadfile (const char *filename){
- /*Open a file, load into memory and allocate the Source buffer for playing*/
- ALfloat SourcePos[] = { 0.0, 0.0, 0.0 }; /*Position of the source sound*/
- ALfloat SourceVel[] = { 0.0, 0.0, 0.0 }; /*Velocity of the source sound*/
- ALenum format;
- ALsizei bitsize, freq;
- char *data;
- uint32_t fileformat;
- ALenum error;
- FILE *fp;
-
- if(openalReady == AL_FALSE) {
- fprintf(stderr, "ERROR: OpenAL not initialized\n");
- return AL_FALSE;
- }
-
- /*when the buffers are all used, we can expand memory to accept new files*/
- if (globalindex == globalsize)
- helper_realloc();
-
- /*detect the file format, as written in the first 4 bytes of the header*/
- fp = Fopen (filename, "rb");
- if (fp == NULL)
- return -1;
- error = fread (&fileformat, sizeof(uint32_t), 1, fp);
- fclose (fp);
-
- if (error < 0) {
- fprintf(stderr, "ERROR: file %s is too short \n", filename);
- return -2;
- }
-
- /*prepare the buffer to receive data*/
- alGenBuffers(1, &Buffers[globalindex]);
-
- if (AlGetError("ERROR %d: Allocating memory for buffers\n") != AL_TRUE)
- return -3;
-
- /*prepare the source to emit sound*/
- alGenSources(1, &Sources[globalindex]);
-
- if (AlGetError("ERROR %d: Allocating memory for sources\n") != AL_TRUE)
- return -4;
-
-
- if (fileformat == 0x5367674F) /*check if ogg*/
- error = load_oggvorbis (filename, &format, &data, &bitsize, &freq);
- else {
- if (fileformat == 0x46464952) /*check if wav*/
- error = load_wavpcm (filename, &format, &data, &bitsize, &freq);
- else {
- fprintf(stderr, "ERROR: File format (%08X) not supported!\n", invert_endianness(fileformat));
- return -5;
- }
- }
-
- /*copy pcm data in one buffer*/
- alBufferData(Buffers[globalindex], format, data, bitsize, freq);
- free(data); /*deallocate data to save memory*/
-
- if (AlGetError("ERROR %d: Writing data to buffer\n") != AL_TRUE)
- return -6;
-
- /*set source properties that it will use when it's in playback*/
- alSourcei (Sources[globalindex], AL_BUFFER, Buffers[globalindex] );
- alSourcef (Sources[globalindex], AL_PITCH, 1.0f );
- alSourcef (Sources[globalindex], AL_GAIN, 1.0f );
- alSourcefv(Sources[globalindex], AL_POSITION, SourcePos );
- alSourcefv(Sources[globalindex], AL_VELOCITY, SourceVel );
- alSourcei (Sources[globalindex], AL_LOOPING, 0 );
-
- if (AlGetError("ERROR %d: Setting source properties\n") != AL_TRUE)
- return -7;
-
- alGetError(); /* clear any AL errors beforehand */
-
- /*returns the index of the source you just loaded, increments it and exits*/
- return globalindex++;
- }
-
-
- ALboolean openal_toggleloop (uint32_t index){
- /*Set or unset looping mode*/
- ALint loop;
-
- if(openalReady == AL_FALSE) {
- fprintf(stderr, "ERROR: OpenAL not initialized\n");
- return AL_FALSE;
- }
-
- if (index >= globalsize) {
- fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
- return AL_FALSE;
- }
-
- alGetSourcei (Sources[index], AL_LOOPING, &loop);
- alSourcei (Sources[index], AL_LOOPING, !((uint8_t) loop) & 0x00000001);
- if (AlGetError("ERROR %d: Getting or setting loop property\n") != AL_TRUE)
- return AL_FALSE;
-
- alGetError(); /* clear any AL errors beforehand */
-
- return AL_TRUE;
- }
-
-
- ALboolean openal_setvolume (uint32_t index, uint8_t percentage) {
- if(openalReady == AL_FALSE) {
- fprintf(stderr, "ERROR: OpenAL not initialized\n");
- return AL_FALSE;
- }
-
- /*Set volume for sound number index*/
- if (index >= globalindex) {
- fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
- return AL_FALSE;
- }
-
- if (percentage > 100)
- percentage = 100;
- alSourcef (Sources[index], AL_GAIN, (float) percentage/100.0f);
- if (AlGetError2("ERROR %d: setting volume for sound %d\n", index) != AL_TRUE)
- return AL_FALSE;
-
- alGetError(); /* clear any AL errors beforehand */
-
- return AL_TRUE;
- }
-
-
- ALboolean openal_setglobalvolume (uint8_t percentage) {
- if(openalReady == AL_FALSE) {
- fprintf(stderr, "ERROR: OpenAL not initialized\n");
- return AL_FALSE;
- }
-
- /*Set volume for all sounds*/
- if (percentage > 100)
- percentage = 100;
- alListenerf (AL_GAIN, (float) percentage/100.0f);
- if (AlGetError("ERROR %d: Setting global volume\n") != AL_TRUE)
- return AL_FALSE;
-
- alGetError(); /* clear any AL errors beforehand */
-
- return AL_TRUE;
- }
-
-
- ALboolean openal_togglemute () {
- /*Mute or unmute sound*/
- ALfloat mute;
-
- if(openalReady == AL_FALSE) {
- fprintf(stderr, "ERROR: OpenAL not initialized\n");
- return AL_FALSE;
- }
-
- alGetListenerf (AL_GAIN, &mute);
- if (mute > 0)
- mute = 0;
- else
- mute = 1.0;
- alListenerf (AL_GAIN, mute);
- if (AlGetError("ERROR %d: Setting mute property\n") != AL_TRUE)
- return AL_FALSE;
-
- alGetError(); /* clear any AL errors beforehand */
-
- return AL_TRUE;
- }
-
-
- ALboolean openal_fade (uint32_t index, uint16_t quantity, ALboolean direction) {
- /*Fade in or out by calling a helper thread*/
-#ifndef _WIN32
- pthread_t thread;
-#else
- HANDLE Thread;
- DWORD threadID;
-#endif
- fade_t *fade;
-
- if(openalReady == AL_FALSE) {
- fprintf(stderr, "ERROR: OpenAL not initialized\n");
- return AL_FALSE;
- }
-
- fade = (fade_t*) Malloc(sizeof(fade_t));
- fade->index = index;
- fade->quantity = quantity;
-
- if (index >= globalindex) {
- fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
- return AL_FALSE;
- }
-
- if (direction == FADE_IN)
-#ifndef _WIN32
- pthread_create(&thread, NULL, helper_fadein, (void*) fade);
-#else
- Thread = _beginthread(&helper_fadein, 0, (void*) fade);
-#endif
- else {
- if (direction == FADE_OUT)
-#ifndef _WIN32
- pthread_create(&thread, NULL, helper_fadeout, (void*) fade);
-#else
- Thread = _beginthread(&helper_fadeout, 0, (void*) fade);
-#endif
- else {
- fprintf(stderr, "ERROR: unknown direction for fade (%d)\n", direction);
- free(fade);
- return AL_FALSE;
- }
- }
-
-#ifndef _WIN32
- pthread_detach(thread);
-#endif
-
- alGetError(); /* clear any AL errors beforehand */
-
- return AL_TRUE;
- }
-
-
- ALboolean openal_fadeout (uint32_t index, uint16_t quantity) {
- /*wrapper for fadeout*/
- return openal_fade(index, quantity, FADE_OUT);
- }
-
-
- ALboolean openal_fadein (uint32_t index, uint16_t quantity) {
- /*wrapper for fadein*/
- return openal_fade(index, quantity, FADE_IN);
- }
-
-
- ALboolean openal_setposition (uint32_t index, float x, float y, float z) {
- if(openalReady == AL_FALSE) {
- fprintf(stderr, "ERROR: OpenAL not initialized\n");
- return AL_FALSE;
- }
- if (index >= globalindex) {
- fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
- return AL_FALSE;
- }
-
- alSource3f(Sources[index], AL_POSITION, x, y, z);
- if (AlGetError2("ERROR %d: setting position for sound %d\n", index) != AL_TRUE)
- return AL_FALSE;
-
- return AL_TRUE;
- }
-
-
- ALboolean openal_playsound (uint32_t index){
- if(openalReady == AL_FALSE) {
- fprintf(stderr, "ERROR: OpenAL not initialized\n");
- return AL_FALSE;
- }
-
- /*Play sound number index*/
- if (index >= globalindex) {
- fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
- return AL_FALSE;
- }
- alSourcePlay(Sources[index]);
- if (AlGetError2("ERROR %d: Playing sound %d\n", index) != AL_TRUE)
- return AL_FALSE;
-
- alGetError(); /* clear any AL errors beforehand */
-
- return AL_TRUE;
- }
-
-
- ALboolean openal_pausesound(uint32_t index){
- if(openalReady == AL_FALSE) {
- fprintf(stderr, "ERROR: OpenAL not initialized\n");
- return AL_FALSE;
- }
-
- /*Pause sound number index*/
- if (index >= globalindex) {
- fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
- return AL_FALSE;
- }
- alSourcePause(Sources[index]);
- if (AlGetError2("ERROR %d: Pausing sound %d\n", index) != AL_TRUE)
- return AL_FALSE;
-
- return AL_TRUE;
- }
-
-
- ALboolean openal_stopsound(uint32_t index){
- if(openalReady == AL_FALSE) {
- fprintf(stderr, "ERROR: OpenAL not initialized\n");
- return AL_FALSE;
- }
-
- /*Stop sound number index*/
- if (index >= globalindex) {
- fprintf(stderr, "ERROR: index out of bounds (got %d, max %d)\n", index, globalindex);
- return AL_FALSE;
- }
- alSourceStop(Sources[index]);
- if (AlGetError2("ERROR %d: Stopping sound %d\n", index) != AL_TRUE)
- return AL_FALSE;
-
- alGetError(); /* clear any AL errors beforehand */
-
- return AL_TRUE;
- }
-
-#ifdef __CPLUSPLUS
-}
-#endif
--- a/openalbridge/openalwrap.h Tue Aug 18 09:59:19 2009 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-/*
- * OpenAL Bridge - a simple portable library for OpenAL interface
- * Copyright (c) 2009 Vittorio Giovara <vittorio.giovara@gmail.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; version 2 of the License
- *
- * 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 Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
- */
-
-#ifndef _OALB_INTERFACE_H
-#define _OALB_INTERFACE_H
-
-#include "globals.h"
-
-#ifdef __CPLUSPLUS
-extern "C" {
-#endif
-
- ALboolean openal_init (unsigned int memorysize);
- ALboolean openal_close (void);
- ALint openal_loadfile (const char *filename);
- ALboolean openal_toggleloop (unsigned int index);
- ALboolean openal_setposition (unsigned int index, float x, float y, float z);
- ALboolean openal_setvolume (unsigned int index, unsigned char percentage);
- ALboolean openal_setglobalvolume (unsigned char percentage);
- ALboolean openal_togglemute (void);
- ALboolean openal_fadeout (unsigned int index, unsigned short int quantity);
- ALboolean openal_fadein (unsigned int index, unsigned short int quantity);
- ALboolean openal_fade (unsigned int index, unsigned short int quantity, ALboolean direction);
- ALboolean openal_playsound (unsigned int index);
- ALboolean openal_pausesound (unsigned int index);
- ALboolean openal_stopsound (unsigned int index);
-
-#ifdef __CPLUSPLUS
-}
-#endif
-
-#endif /*_OALB_INTERFACE_H*/
Binary file share/hedgewars/Data/Graphics/AmmoMenu/Ammos.png has changed
Binary file share/hedgewars/Data/Graphics/AmmoMenu/Ammos_bw.png has changed
Binary file share/hedgewars/Data/Themes/City/Sky-lowres.png has changed