1
0
Fork 0

(svn r8860) -Cleanup: some style changes, proper #endif comments, variable initialisation, WINCE ifdef and a vsprintf to vsnprintf change.

release/0.6
Darkvater 2007-02-23 12:56:10 +00:00
parent 6d199fcdb7
commit 1bbbbeeef1
15 changed files with 29 additions and 44 deletions

View File

@ -186,9 +186,7 @@ bool FileExists(const char *filename)
{ {
#if defined(WINCE) #if defined(WINCE)
/* There is always one platform that doesn't support basic commands... */ /* There is always one platform that doesn't support basic commands... */
HANDLE hand; HANDLE hand = CreateFile(OTTD2FS(filename), 0, 0, NULL, OPEN_EXISTING, 0, NULL);
hand = CreateFile(OTTD2FS(filename), 0, 0, NULL, OPEN_EXISTING, 0, NULL);
if (hand == INVALID_HANDLE_VALUE) return 1; if (hand == INVALID_HANDLE_VALUE) return 1;
CloseHandle(hand); CloseHandle(hand);
return 0; return 0;

View File

@ -7,4 +7,4 @@
extern const HalMusicDriver _bemidi_music_driver; extern const HalMusicDriver _bemidi_music_driver;
#endif #endif /* MUSIC_BEMIDI_H */

View File

@ -1,9 +1,8 @@
/* $Id$ */ /* $Id$ */
#include "../stdafx.h"
#ifdef WIN32_ENABLE_DIRECTMUSIC_SUPPORT #ifdef WIN32_ENABLE_DIRECTMUSIC_SUPPORT
#include "../stdafx.h"
#include "../debug.h" #include "../debug.h"
#include "../win32.h" #include "../win32.h"
#include "dmusic.h" #include "dmusic.h"

View File

@ -7,4 +7,4 @@
extern const HalMusicDriver _extmidi_music_driver; extern const HalMusicDriver _extmidi_music_driver;
#endif #endif /* MUSIC_EXTERNAL_H */

View File

@ -1,7 +1,6 @@
/* $Id$ */ /* $Id$ */
#include "../stdafx.h" #include "../stdafx.h"
#include "../openttd.h"
#include "null_m.h" #include "null_m.h"
static const char* NullMidiStart(const char* const* parm) { return NULL; } static const char* NullMidiStart(const char* const* parm) { return NULL; }

View File

@ -7,4 +7,4 @@
extern const HalMusicDriver _os2_music_driver; extern const HalMusicDriver _os2_music_driver;
#endif #endif /* MUSIC_OS2_H */

View File

@ -7,4 +7,4 @@
extern const HalMusicDriver _qtime_music_driver; extern const HalMusicDriver _qtime_music_driver;
#endif /* !MUSIC_MACOSX_QUICKTIME_H */ #endif /* MUSIC_MACOSX_QUICKTIME_H */

View File

@ -1,7 +1,6 @@
/* $Id$ */ /* $Id$ */
#include "../stdafx.h" #include "../stdafx.h"
#include "../openttd.h"
#include "win32_m.h" #include "win32_m.h"
#include <windows.h> #include <windows.h>
#include <mmsystem.h> #include <mmsystem.h>
@ -50,7 +49,7 @@ static MCIERROR CDECL MidiSendCommand(const char* cmd, ...)
char buf[512]; char buf[512];
va_start(va, cmd); va_start(va, cmd);
vsprintf(buf, cmd, va); vsnprintf(buf, lengthof(buf), cmd, va);
va_end(va); va_end(va);
return mciSendStringA(buf, NULL, 0, 0); return mciSendStringA(buf, NULL, 0, 0);
} }
@ -58,12 +57,9 @@ static MCIERROR CDECL MidiSendCommand(const char* cmd, ...)
static bool MidiIntPlaySong(const char *filename) static bool MidiIntPlaySong(const char *filename)
{ {
MidiSendCommand("close all"); MidiSendCommand("close all");
if (MidiSendCommand("open \"%s\" type sequencer alias song", filename) != 0) if (MidiSendCommand("open \"%s\" type sequencer alias song", filename) != 0) return false;
return false;
if (MidiSendCommand("play song from 0") != 0) return MidiSendCommand("play song from 0") == 0;
return false;
return true;
} }
static void MidiIntStopSong(void) static void MidiIntStopSong(void)
@ -104,9 +100,7 @@ static DWORD WINAPI MidiThread(LPVOID arg)
s[0] = '\0'; s[0] = '\0';
// Delay somewhat in case we don't manage to play. // Delay somewhat in case we don't manage to play.
if (!_midi.playing) { if (!_midi.playing) Sleep(5000);
Sleep(5000);
}
} }
if (_midi.stop_song && _midi.playing) { if (_midi.stop_song && _midi.playing) {
@ -115,8 +109,7 @@ static DWORD WINAPI MidiThread(LPVOID arg)
MidiIntStopSong(); MidiIntStopSong();
} }
if (_midi.playing && !MidiIntIsSongPlaying()) if (_midi.playing && !MidiIntIsSongPlaying()) _midi.playing = false;
_midi.playing = false;
WaitForMultipleObjects(1, &_midi.wait_obj, FALSE, 1000); WaitForMultipleObjects(1, &_midi.wait_obj, FALSE, 1000);
} while (!_midi.terminate); } while (!_midi.terminate);
@ -148,8 +141,7 @@ static const char *Win32MidiStart(const char * const *parm)
} }
} }
if (CreateThread(NULL, 8192, MidiThread, 0, 0, &threadId) == NULL) if (CreateThread(NULL, 8192, MidiThread, 0, 0, &threadId) == NULL) return "Failed to create thread";
return "Failed to create thread";
return NULL; return NULL;
} }

View File

@ -422,12 +422,11 @@ static void MusicWindowWndProc(Window *w, WindowEvent *e)
case 5: // start playing case 5: // start playing
msf.playing = true; msf.playing = true;
break; break;
case 6:{ // volume sliders case 6: { // volume sliders
byte *vol,new_vol; byte *vol, new_vol;
int x = e->we.click.pt.x - 88; int x = e->we.click.pt.x - 88;
if (x < 0) if (x < 0) return;
return;
vol = &msf.music_vol; vol = &msf.music_vol;
if (x >= 106) { if (x >= 106) {
@ -435,7 +434,7 @@ static void MusicWindowWndProc(Window *w, WindowEvent *e)
x -= 106; x -= 106;
} }
new_vol = min(max(x-21,0)*2,127); new_vol = min(max(x - 21, 0) * 2, 127);
if (new_vol != *vol) { if (new_vol != *vol) {
*vol = new_vol; *vol = new_vol;
if (vol == &msf.music_vol) if (vol == &msf.music_vol)

View File

@ -37,7 +37,7 @@ void InitializeSoundPool(void)
FileEntry *GetSound(uint index) FileEntry *GetSound(uint index)
{ {
if (index >= _sound_count) return NULL; if (index >= GetNumSounds()) return NULL;
return GetSoundInternal(index); return GetSoundInternal(index);
} }

View File

@ -7,4 +7,4 @@
extern const HalSoundDriver _cocoa_sound_driver; extern const HalSoundDriver _cocoa_sound_driver;
#endif #endif /* SOUND_COCOA_H */

View File

@ -1,10 +1,9 @@
/* $Id$ */ /* $Id$ */
#include "../stdafx.h"
#ifdef WITH_SDL #ifdef WITH_SDL
#include "../openttd.h" #include "../stdafx.h"
#include "../driver.h" #include "../driver.h"
#include "../mixer.h" #include "../mixer.h"
#include "../sdl.h" #include "../sdl.h"

View File

@ -7,4 +7,4 @@
extern const HalSoundDriver _win32_sound_driver; extern const HalSoundDriver _win32_sound_driver;
#endif #endif /* SOUND_WIN32_H */

View File

@ -10,4 +10,4 @@
extern const HalVideoDriver _cocoa_video_driver; extern const HalVideoDriver _cocoa_video_driver;
#endif #endif /* VIDEO_COCOA_H */

View File

@ -868,12 +868,12 @@ void ShowInfo(const char *str)
int _set_error_mode(int); int _set_error_mode(int);
#endif #endif
#if defined(WINCE) #if defined(WINCE) && !defined(_tWinMain)
int APIENTRY WinMain /* GCC crosscompiler for WINCE doesn't support wide version */
#else # define _tWinMain WinMain
int APIENTRY _tWinMain #endif /* WINCE */
#endif
(HINSTANCE hInstance, HINSTANCE hPrevInstance, int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, int nCmdShow) LPTSTR lpCmdLine, int nCmdShow)
{ {
int argc; int argc;
@ -922,12 +922,11 @@ int APIENTRY _tWinMain
#if defined(WINCE) #if defined(WINCE)
void GetCurrentDirectoryW(int length, wchar_t *path) void GetCurrentDirectoryW(int length, wchar_t *path)
{ {
wchar_t *pDest = NULL;
/* Get the name of this module */ /* Get the name of this module */
GetModuleFileName(NULL, path, length); GetModuleFileName(NULL, path, length);
/* Remove the executable name, this we call CurrentDir */ /* Remove the executable name, this we call CurrentDir */
pDest = wcsrchr(path, '\\'); wchar_t *pDest = wcsrchr(path, '\\');
if (pDest != NULL) { if (pDest != NULL) {
int result = pDest - path + 1; int result = pDest - path + 1;
path[result] = '\0'; path[result] = '\0';