mirror of https://github.com/OpenTTD/OpenTTD
(svn r5669) - Backport from trunk (r5464, r3641):
Codechange: verify the presence of music files in the gm folder. Slightly altered r5464 to exclude the addition of music.c and left out the extra functionality. While in essence this is not a true fix, several people have reported a rising CPU usage because Dmusic kept indefinitely looping the file list. This should solve that.release/0.4
parent
f3cce610c8
commit
58b4fd7683
|
@ -0,0 +1,16 @@
|
||||||
|
/* $Id */
|
||||||
|
|
||||||
|
#ifndef MUSIC_H
|
||||||
|
#define MUSIC_H
|
||||||
|
|
||||||
|
#define NUM_SONGS_PLAYLIST 33
|
||||||
|
#define NUM_SONGS_AVAILABLE 22
|
||||||
|
|
||||||
|
typedef struct SongSpecs {
|
||||||
|
char filename[256];
|
||||||
|
char song_name[64];
|
||||||
|
} SongSpecs;
|
||||||
|
|
||||||
|
extern const SongSpecs origin_songs_specs[NUM_SONGS_AVAILABLE];
|
||||||
|
|
||||||
|
#endif //MUSIC_H
|
91
music_gui.c
91
music_gui.c
|
@ -10,12 +10,12 @@
|
||||||
#include "hal.h"
|
#include "hal.h"
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
#include "variables.h"
|
#include "variables.h"
|
||||||
|
#include "music.h"
|
||||||
|
|
||||||
static byte _music_wnd_cursong;
|
static byte _music_wnd_cursong;
|
||||||
static bool _song_is_active;
|
static bool _song_is_active;
|
||||||
static byte _cur_playlist[33];
|
static byte _cur_playlist[NUM_SONGS_PLAYLIST];
|
||||||
|
|
||||||
#define NUM_SONGS_AVAILABLE 22
|
|
||||||
|
|
||||||
|
|
||||||
static byte _playlist_all[] = {
|
static byte _playlist_all[] = {
|
||||||
|
@ -43,33 +43,31 @@ static byte * const _playlists[] = {
|
||||||
msf.custom_2,
|
msf.custom_2,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Map the order of the song names to the numbers of the midi filenames
|
const SongSpecs origin_songs_specs[NUM_SONGS_AVAILABLE] = {
|
||||||
static const byte midi_idx[] = {
|
{"gm_tt00.gm", "Tycoon DELUXE Theme"},
|
||||||
0, // Tycoon DELUXE Theme
|
{"gm_tt02.gm", "Easy Driver"},
|
||||||
2, // Easy Driver
|
{"gm_tt03.gm", "Little Red Diesel"},
|
||||||
3, // Little Red Diesel
|
{"gm_tt17.gm", "Cruise Control"},
|
||||||
17, // Cruise Control
|
{"gm_tt07.gm", "Don't Walk!"},
|
||||||
7, // Don't Walk!
|
{"gm_tt09.gm", "Fell Apart On Me"},
|
||||||
9, // Fell Apart On Me
|
{"gm_tt04.gm", "City Groove"},
|
||||||
4, // City Groove
|
{"gm_tt19.gm", "Funk Central"},
|
||||||
19, // Funk Central
|
{"gm_tt06.gm", "Stoke It"},
|
||||||
6, // Stoke It
|
{"gm_tt12.gm", "Road Hog"},
|
||||||
12, // Road Hog
|
{"gm_tt05.gm", "Aliens Ate My Railway"},
|
||||||
5, // Aliens Ate My Railway
|
{"gm_tt01.gm", "Snarl Up"},
|
||||||
1, // Snarl Up
|
{"gm_tt18.gm", "Stroll On"},
|
||||||
18, // Stroll On
|
{"gm_tt10.gm", "Can't Get There From Here"},
|
||||||
10, // Can't Get There From Here
|
{"gm_tt08.gm", "Sawyer's Tune"},
|
||||||
8, // Sawyer's Tune
|
{"gm_tt13.gm", "Hold That Train!"},
|
||||||
13, // Hold That Train!
|
{"gm_tt21.gm", "Movin' On"},
|
||||||
21, // Movin' On
|
{"gm_tt15.gm", "Goss Groove"},
|
||||||
15, // Goss Groove
|
{"gm_tt16.gm", "Small Town"},
|
||||||
16, // Small Town
|
{"gm_tt14.gm", "Broomer's Oil Rag"},
|
||||||
14, // Broomer's Oil Rag
|
{"gm_tt20.gm", "Jammit"},
|
||||||
20, // Jammit
|
{"gm_tt11.gm", "Hard Drivin'"},
|
||||||
11 // Hard Drivin'
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static void SkipToPrevSong(void)
|
static void SkipToPrevSong(void)
|
||||||
{
|
{
|
||||||
byte *b = _cur_playlist;
|
byte *b = _cur_playlist;
|
||||||
|
@ -118,8 +116,8 @@ static void MusicVolumeChanged(byte new_vol)
|
||||||
static void DoPlaySong(void)
|
static void DoPlaySong(void)
|
||||||
{
|
{
|
||||||
char filename[256];
|
char filename[256];
|
||||||
snprintf(filename, sizeof(filename), "%sgm_tt%.2d.gm",
|
snprintf(filename, sizeof(filename), "%s%s",
|
||||||
_path.gm_dir, midi_idx[_music_wnd_cursong - 1]);
|
_path.gm_dir, origin_songs_specs[_music_wnd_cursong - 1].filename);
|
||||||
_music_driver->play_song(filename);
|
_music_driver->play_song(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,10 +129,19 @@ static void DoStopMusic(void)
|
||||||
static void SelectSongToPlay(void)
|
static void SelectSongToPlay(void)
|
||||||
{
|
{
|
||||||
uint i = 0;
|
uint i = 0;
|
||||||
|
uint j = 0;
|
||||||
|
char filename[256];
|
||||||
|
|
||||||
memset(_cur_playlist, 0, sizeof(_cur_playlist));
|
memset(_cur_playlist, 0, sizeof(_cur_playlist));
|
||||||
do {
|
do {
|
||||||
_cur_playlist[i] = _playlists[msf.playlist][i];
|
snprintf(filename, sizeof(filename), "%s%s",
|
||||||
|
_path.gm_dir, origin_songs_specs[_playlists[msf.playlist][i]].filename);
|
||||||
|
//we are now checking for the existence of that file prior
|
||||||
|
//to add it to the list of available songs
|
||||||
|
if (FileExists(filename)) {
|
||||||
|
_cur_playlist[j] = _playlists[msf.playlist][i];
|
||||||
|
j++;
|
||||||
|
}
|
||||||
} while (_playlists[msf.playlist][i++] != 0 && i < lengthof(_cur_playlist) - 1);
|
} while (_playlists[msf.playlist][i++] != 0 && i < lengthof(_cur_playlist) - 1);
|
||||||
|
|
||||||
if (msf.shuffle) {
|
if (msf.shuffle) {
|
||||||
|
@ -165,7 +172,15 @@ static void PlayPlaylistSong(void)
|
||||||
{
|
{
|
||||||
if (_cur_playlist[0] == 0) {
|
if (_cur_playlist[0] == 0) {
|
||||||
SelectSongToPlay();
|
SelectSongToPlay();
|
||||||
if (_cur_playlist[0] == 0) return;
|
//if there is not songs in the playlist, it may indicate
|
||||||
|
//no file on the gm folder, or even no gm folder.
|
||||||
|
//Stop the playback, then
|
||||||
|
if (_cur_playlist[0] == 0) {
|
||||||
|
_song_is_active = false;
|
||||||
|
_music_wnd_cursong = 0;
|
||||||
|
msf.playing = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_music_wnd_cursong = _cur_playlist[0];
|
_music_wnd_cursong = _cur_playlist[0];
|
||||||
DoPlaySong();
|
DoPlaySong();
|
||||||
|
@ -182,13 +197,13 @@ void ResetMusic(void)
|
||||||
|
|
||||||
void MusicLoop(void)
|
void MusicLoop(void)
|
||||||
{
|
{
|
||||||
if (!msf.btn_down && _song_is_active) {
|
if (!msf.playing && _song_is_active) {
|
||||||
StopMusic();
|
StopMusic();
|
||||||
} else if (msf.btn_down && !_song_is_active) {
|
} else if (msf.playing && !_song_is_active) {
|
||||||
PlayPlaylistSong();
|
PlayPlaylistSong();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_song_is_active == false) return;
|
if (!_song_is_active) return;
|
||||||
|
|
||||||
if (!_music_driver->is_song_playing()) {
|
if (!_music_driver->is_song_playing()) {
|
||||||
if (_game_mode != GM_MENU) {
|
if (_game_mode != GM_MENU) {
|
||||||
|
@ -257,7 +272,7 @@ static void MusicTrackSelectionWndProc(Window *w, WindowEvent *e)
|
||||||
if (!IS_INT_INSIDE(y, 0, NUM_SONGS_AVAILABLE)) return;
|
if (!IS_INT_INSIDE(y, 0, NUM_SONGS_AVAILABLE)) return;
|
||||||
|
|
||||||
p = _playlists[msf.playlist];
|
p = _playlists[msf.playlist];
|
||||||
for (i = 0; i != 32; i++) {
|
for (i = 0; i != NUM_SONGS_PLAYLIST - 1; i++) {
|
||||||
if (p[i] == 0) {
|
if (p[i] == 0) {
|
||||||
p[i] = y + 1;
|
p[i] = y + 1;
|
||||||
p[i + 1] = 0;
|
p[i + 1] = 0;
|
||||||
|
@ -339,7 +354,7 @@ static void MusicWindowWndProc(Window *w, WindowEvent *e)
|
||||||
color = 0xB8;
|
color = 0xB8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GfxFillRect(187, 33 - i * 2, 200, 33 - i * 2, color);
|
GfxFillRect(187, NUM_SONGS_PLAYLIST - i * 2, 200, NUM_SONGS_PLAYLIST - i * 2, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
GfxFillRect(60, 46, 239, 52, 0);
|
GfxFillRect(60, 46, 239, 52, 0);
|
||||||
|
@ -405,10 +420,10 @@ static void MusicWindowWndProc(Window *w, WindowEvent *e)
|
||||||
SkipToNextSong();
|
SkipToNextSong();
|
||||||
break;
|
break;
|
||||||
case 4: // stop playing
|
case 4: // stop playing
|
||||||
msf.btn_down = false;
|
msf.playing = false;
|
||||||
break;
|
break;
|
||||||
case 5: // start playing
|
case 5: // start playing
|
||||||
msf.btn_down = true;
|
msf.playing = true;
|
||||||
break;
|
break;
|
||||||
case 6:{ // volume sliders
|
case 6:{ // volume sliders
|
||||||
byte *vol,new_vol;
|
byte *vol,new_vol;
|
||||||
|
|
|
@ -742,7 +742,7 @@ static const SettingDesc music_settings[] = {
|
||||||
{"effect_vol",SDT_UINT8, (void*)128, &msf.effect_vol, NULL},
|
{"effect_vol",SDT_UINT8, (void*)128, &msf.effect_vol, NULL},
|
||||||
{"custom_1", SDT_INTLIST | SDT_UINT8 | lengthof(msf.custom_1) << 16, NULL, &msf.custom_1, NULL},
|
{"custom_1", SDT_INTLIST | SDT_UINT8 | lengthof(msf.custom_1) << 16, NULL, &msf.custom_1, NULL},
|
||||||
{"custom_2", SDT_INTLIST | SDT_UINT8 | lengthof(msf.custom_2) << 16, NULL, &msf.custom_2, NULL},
|
{"custom_2", SDT_INTLIST | SDT_UINT8 | lengthof(msf.custom_2) << 16, NULL, &msf.custom_2, NULL},
|
||||||
{"playing", SDT_BOOL, (void*)true, &msf.btn_down, NULL},
|
{"playing", SDT_BOOL, (void*)true, &msf.playing, NULL},
|
||||||
{"shuffle", SDT_BOOL, (void*)false, &msf.shuffle, NULL},
|
{"shuffle", SDT_BOOL, (void*)false, &msf.shuffle, NULL},
|
||||||
{"extmidi", SDT_STRINGBUF | (lengthof(msf.extmidi)<<16), EXTERNAL_PLAYER, &msf.extmidi, NULL},
|
{"extmidi", SDT_STRINGBUF | (lengthof(msf.extmidi)<<16), EXTERNAL_PLAYER, &msf.extmidi, NULL},
|
||||||
{NULL, 0, NULL, NULL, NULL}
|
{NULL, 0, NULL, NULL, NULL}
|
||||||
|
|
2
sound.h
2
sound.h
|
@ -9,7 +9,7 @@ typedef struct MusicFileSettings {
|
||||||
byte effect_vol;
|
byte effect_vol;
|
||||||
byte custom_1[33];
|
byte custom_1[33];
|
||||||
byte custom_2[33];
|
byte custom_2[33];
|
||||||
bool btn_down;
|
bool playing;
|
||||||
bool shuffle;
|
bool shuffle;
|
||||||
char extmidi[80];
|
char extmidi[80];
|
||||||
} MusicFileSettings;
|
} MusicFileSettings;
|
||||||
|
|
28
strings.c
28
strings.c
|
@ -16,6 +16,7 @@
|
||||||
#include "waypoint.h"
|
#include "waypoint.h"
|
||||||
#include "industry.h"
|
#include "industry.h"
|
||||||
#include "variables.h"
|
#include "variables.h"
|
||||||
|
#include "music.h"
|
||||||
|
|
||||||
char _userstring[128];
|
char _userstring[128];
|
||||||
|
|
||||||
|
@ -899,31 +900,6 @@ static char *GenPresidentName(char *buff, uint32 x)
|
||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char * const _song_names[] = {
|
|
||||||
"Tycoon DELUXE Theme",
|
|
||||||
"Easy Driver",
|
|
||||||
"Little Red Diesel",
|
|
||||||
"Cruise Control",
|
|
||||||
"Don't Walk!",
|
|
||||||
"Fell Apart On Me",
|
|
||||||
"City Groove",
|
|
||||||
"Funk Central",
|
|
||||||
"Stoke It",
|
|
||||||
"Road Hog",
|
|
||||||
"Aliens Ate My Railway",
|
|
||||||
"Snarl Up",
|
|
||||||
"Stroll On",
|
|
||||||
"Can't Get There From Here",
|
|
||||||
"Sawyer's Tune",
|
|
||||||
"Hold That Train!",
|
|
||||||
"Movin' On",
|
|
||||||
"Goss Groove",
|
|
||||||
"Small Town",
|
|
||||||
"Broomer's Oil Rag",
|
|
||||||
"Jammit",
|
|
||||||
"Hard Drivin'"
|
|
||||||
};
|
|
||||||
|
|
||||||
static char *GetSpecialPlayerNameString(char *buff, int ind, const int32 *argv)
|
static char *GetSpecialPlayerNameString(char *buff, int ind, const int32 *argv)
|
||||||
{
|
{
|
||||||
switch (ind) {
|
switch (ind) {
|
||||||
|
@ -937,7 +913,7 @@ static char *GetSpecialPlayerNameString(char *buff, int ind, const int32 *argv)
|
||||||
return GenPresidentName(buff, GetInt32(&argv));
|
return GenPresidentName(buff, GetInt32(&argv));
|
||||||
|
|
||||||
case 4: // song names
|
case 4: // song names
|
||||||
return strecpy(buff, _song_names[GetInt32(&argv) - 1], NULL);
|
return strecpy(buff, origin_songs_specs[GetInt32(&argv) - 1].song_name, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// town name?
|
// town name?
|
||||||
|
|
Loading…
Reference in New Issue