Skip to content

Commit bc4af4c

Browse files
committed
Maybe fix multi start crash
1 parent dddf317 commit bc4af4c

File tree

2 files changed

+36
-206
lines changed

2 files changed

+36
-206
lines changed

src/ScreenNetSelectMusic.cpp

Lines changed: 35 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -54,35 +54,14 @@ ScreenNetSelectMusic::Init()
5454
{
5555
ScreenSelectMusic::Init();
5656
GAMESTATE->m_bPlayingMulti = true;
57-
SAMPLE_MUSIC_PREVIEW_MODE.Load(m_sName, "SampleMusicPreviewMode");
58-
MUSIC_WHEEL_TYPE.Load(m_sName, "MusicWheelType");
59-
60-
// todo: handle me theme-side -aj
61-
FOREACH_EnabledPlayer(p)
62-
{
63-
m_ModIconRow[p].SetName(ssprintf("ModIconsP%d", p + 1));
64-
m_ModIconRow[p].Load("ModIconRowSelectMusic", p);
65-
m_ModIconRow[p].SetFromGameState();
66-
LOAD_ALL_COMMANDS_AND_SET_XY(m_ModIconRow[p]);
67-
this->AddChild(&m_ModIconRow[p]);
68-
}
69-
7057
// Load SFX and music
7158
m_soundChangeOpt.Load(THEME->GetPathS(m_sName, "change opt"));
7259
m_soundChangeSel.Load(THEME->GetPathS(m_sName, "change sel"));
73-
m_sSectionMusicPath = THEME->GetPathS(m_sName, "section music");
74-
m_sRouletteMusicPath = THEME->GetPathS(m_sName, "roulette music");
75-
m_sRandomMusicPath = THEME->GetPathS(m_sName, "random music");
7660

7761
NSMAN->OnMusicSelect();
7862

7963
m_bInitialSelect = false;
8064
m_bAllowInput = NSMAN->IsETTP();
81-
82-
SAMPLE_MUSIC_FALLBACK_FADE_IN_SECONDS.Load(
83-
m_sName, "SampleMusicFallbackFadeInSeconds");
84-
SAMPLE_MUSIC_FADE_OUT_SECONDS.Load(m_sName, "SampleMusicFadeOutSeconds");
85-
ALIGN_MUSIC_BEATS.Load(m_sName, "AlignMusicBeat");
8665
}
8766

8867
void
@@ -113,133 +92,38 @@ ScreenNetSelectMusic::Input(const InputEventPlus& input)
11392
if (input.type != IET_FIRST_PRESS && input.type != IET_REPEAT)
11493
return false;
11594

116-
bool bHoldingCtrl =
117-
INPUTFILTER->IsBeingPressed(DeviceInput(DEVICE_KEYBOARD, KEY_LCTRL)) ||
118-
INPUTFILTER->IsBeingPressed(DeviceInput(DEVICE_KEYBOARD, KEY_RCTRL)) ||
119-
(!NSMAN->useSMserver); // If we are disconnected, assume no chatting
120-
121-
bool holding_shift =
122-
INPUTFILTER->IsBeingPressed(DeviceInput(DEVICE_KEYBOARD, KEY_LSHIFT)) ||
123-
INPUTFILTER->IsBeingPressed(DeviceInput(DEVICE_KEYBOARD, KEY_RSHIFT));
124-
125-
wchar_t c = INPUTMAN->DeviceInputToChar(input.DeviceI, false);
126-
MakeUpper(&c, 1);
127-
128-
bool handled = false;
129-
130-
/* I'm commenting this here and adding the 2 ctrl+key and the ctrl+shift+key
131-
inputs
132-
// Ctrl+[A-Z] to go to that letter of the alphabet
133-
if( bHoldingCtrl && ( c >= 'A' ) && ( c <= 'Z' ) )
134-
{
135-
SortOrder so = GAMESTATE->m_SortOrder;
136-
if( ( so != SORT_TITLE ) && ( so != SORT_ARTIST ) )
137-
{
138-
so = SORT_TITLE;
139-
140-
GAMESTATE->m_PreferredSortOrder = so;
141-
GAMESTATE->m_SortOrder.Set( so );
142-
// Odd, changing the sort order requires us to call SetOpenSection
143-
more than once m_MusicWheel.ChangeSort( so ); m_MusicWheel.SetOpenSection(
144-
ssprintf("%c", c ) );
145-
}
146-
m_MusicWheel.SelectSection( ssprintf("%c", c ) );
147-
m_MusicWheel.ChangeSort( so );
148-
m_MusicWheel.SetOpenSection( ssprintf("%c", c ) );
149-
m_MusicWheel.Move(+1);
150-
handled = true;
151-
}
152-
*/
153-
if (holding_shift && bHoldingCtrl && input.type == IET_FIRST_PRESS &&
154-
m_MusicWheel.IsSettled()) {
155-
if (c == 'R') {
156-
// Reload the currently selected song. -Kyz
157-
Song* to_reload = m_MusicWheel.GetSelectedSong();
158-
if (to_reload != nullptr) {
159-
to_reload->ReloadFromSongDir();
160-
this->AfterMusicChange();
161-
handled = true;
162-
}
163-
} else if (c == 'F') {
164-
// Favorite the currently selected song. -Not Kyz
165-
Song* fav_me_biatch = m_MusicWheel.GetSelectedSong();
166-
if (fav_me_biatch) {
167-
Profile* pProfile = PROFILEMAN->GetProfile(PLAYER_1);
168-
169-
if (!fav_me_biatch->IsFavorited()) {
170-
fav_me_biatch->SetFavorited(true);
171-
pProfile->AddToFavorites(
172-
GAMESTATE->m_pCurSteps[PLAYER_1]->GetChartKey());
173-
} else {
174-
fav_me_biatch->SetFavorited(false);
175-
pProfile->RemoveFromFavorites(
176-
GAMESTATE->m_pCurSteps[PLAYER_1]->GetChartKey());
177-
}
178-
Message msg("FavoritesUpdated");
179-
MESSAGEMAN->Broadcast(msg);
180-
m_MusicWheel.ChangeMusic(0);
181-
return true;
182-
}
183-
} else if (c == 'M') {
184-
// PermaMirror the currently selected song. -Not Kyz
185-
Song* alwaysmirrorsmh = m_MusicWheel.GetSelectedSong();
186-
if (alwaysmirrorsmh) {
187-
Profile* pProfile = PROFILEMAN->GetProfile(PLAYER_1);
188-
189-
if (!alwaysmirrorsmh->IsPermaMirror()) {
190-
alwaysmirrorsmh->SetPermaMirror(true);
191-
pProfile->AddToPermaMirror(
192-
GAMESTATE->m_pCurSteps[PLAYER_1]->GetChartKey());
193-
} else {
194-
alwaysmirrorsmh->SetPermaMirror(false);
195-
pProfile->RemoveFromPermaMirror(
196-
GAMESTATE->m_pCurSteps[PLAYER_1]->GetChartKey());
197-
}
198-
Message msg("FavoritesUpdated");
199-
MESSAGEMAN->Broadcast(msg);
200-
m_MusicWheel.ChangeMusic(0);
201-
return true;
202-
}
203-
} else if (c == 'G') {
204-
Profile* pProfile = PROFILEMAN->GetProfile(PLAYER_1);
205-
pProfile->AddGoal(GAMESTATE->m_pCurSteps[PLAYER_1]->GetChartKey());
206-
Song* asonglol = m_MusicWheel.GetSelectedSong();
207-
asonglol->SetHasGoal(true);
208-
MESSAGEMAN->Broadcast("FavoritesUpdated");
209-
m_MusicWheel.ChangeMusic(0);
210-
return true;
211-
} else if (c == 'Q') {
212-
DifferentialReload();
213-
return true;
214-
} else if (c == 'S') {
215-
PROFILEMAN->SaveProfile(PLAYER_1);
216-
SCREENMAN->SystemMessage("Profile Saved");
217-
return true;
218-
} else if (input.DeviceI.device == DEVICE_KEYBOARD &&
219-
input.DeviceI.button == KEY_BACK) {
220-
// Keyboard shortcut to delete a song from disk (ctrl + backspace)
221-
Song* songToDelete = m_MusicWheel.GetSelectedSong();
222-
if (songToDelete && PREFSMAN->m_bAllowSongDeletion.Get()) {
223-
m_pSongAwaitingDeletionConfirmation = songToDelete;
224-
ScreenPrompt::Prompt(
225-
SM_ConfirmDeleteSong,
226-
ssprintf(PERMANENTLY_DELETE.GetValue(),
227-
songToDelete->m_sMainTitle.c_str(),
228-
songToDelete->GetSongDir().c_str()),
229-
PROMPT_YES_NO);
230-
return true;
231-
}
232-
}
233-
}
234-
return ScreenSelectMusic::Input(input) || handled;
95+
return ScreenSelectMusic::Input(input);
23596
}
23697

23798
void
23899
ScreenNetSelectMusic::HandleScreenMessage(const ScreenMessage SM)
239100
{
240-
if (SM == SM_GoToNextScreen)
101+
if (SM == SM_GoToNextScreen) {
241102
SOUND->StopMusic();
242-
else if (SM == SM_UsersUpdate) {
103+
if (NSMAN->song != nullptr) {
104+
GAMESTATE->m_pCurSong.Set(NSMAN->song);
105+
if (NSMAN->steps != nullptr) {
106+
GAMESTATE->m_pCurSteps[PLAYER_1].Set(NSMAN->steps);
107+
GAMESTATE->m_PreferredDifficulty[PLAYER_1].Set(
108+
NSMAN->steps->GetDifficulty());
109+
}
110+
if (!m_MusicWheel.SelectSong(NSMAN->song)) {
111+
m_MusicWheel.ChangeSort(SORT_GROUP);
112+
m_MusicWheel.FinishTweening();
113+
SCREENMAN->PostMessageToTopScreen(SM_SetWheelSong, 0.710f);
114+
m_MusicWheel.SelectSong(NSMAN->song);
115+
}
116+
if (NSMAN->rate > 0) {
117+
GAMESTATE->m_SongOptions.GetPreferred().m_fMusicRate =
118+
NSMAN->rate / 1000.f;
119+
MESSAGEMAN->Broadcast("RateChanged");
120+
}
121+
m_MusicWheel.Select();
122+
m_MusicWheel.Move(-1);
123+
m_MusicWheel.Move(1);
124+
m_MusicWheel.Move(0);
125+
}
126+
} else if (SM == SM_UsersUpdate) {
243127
MESSAGEMAN->Broadcast("UsersUpdate");
244128
} else if (SM == SM_FriendsUpdate) {
245129
MESSAGEMAN->Broadcast("FriendsUpdate");
@@ -261,10 +145,6 @@ ScreenNetSelectMusic::HandleScreenMessage(const ScreenMessage SM)
261145
m_MusicWheel.Move(0);
262146
} else if (SM == SM_NoSongs) {
263147
SCREENMAN->SetNewScreen(THEME->GetMetric(m_sName, "NoSongsScreen"));
264-
} else if (SM == SM_SetWheelSong) // After we've done the sort on wheel,
265-
// select song.
266-
{
267-
m_MusicWheel.SelectSong(m_cSong);
268148
} else if (SM == SM_RefreshWheelLocation) {
269149
m_MusicWheel.Select();
270150
m_MusicWheel.Move(-1);
@@ -275,9 +155,6 @@ ScreenNetSelectMusic::HandleScreenMessage(const ScreenMessage SM)
275155
GAMESTATE->m_EditMode = EditMode_Invalid;
276156
// XXX HACK: This will cause ScreenSelectOptions to go back here.
277157
NSMAN->OffOptions();
278-
279-
// Update changes
280-
FOREACH_EnabledPlayer(p) m_ModIconRow[p].SetFromGameState();
281158
} else if (SM == SM_SongChanged) {
282159
if (m_MusicWheel.GetNumItems() > 0) {
283160
GAMESTATE->m_pCurSong.Set(m_MusicWheel.GetSelectedSong());
@@ -287,7 +164,6 @@ ScreenNetSelectMusic::HandleScreenMessage(const ScreenMessage SM)
287164
if (NSMAN->song != nullptr) {
288165
GAMESTATE->m_pCurSong.Set(NSMAN->song);
289166
if (NSMAN->steps != nullptr) {
290-
m_vpSteps[m_iSelection[PLAYER_1]] = NSMAN->steps;
291167
GAMESTATE->m_pCurSteps[PLAYER_1].Set(NSMAN->steps);
292168
GAMESTATE->m_PreferredDifficulty[PLAYER_1].Set(
293169
NSMAN->steps->GetDifficulty());
@@ -313,7 +189,6 @@ ScreenNetSelectMusic::HandleScreenMessage(const ScreenMessage SM)
313189
if (NSMAN->song != nullptr) {
314190
GAMESTATE->m_pCurSong.Set(NSMAN->song);
315191
if (NSMAN->steps != nullptr) {
316-
m_vpSteps[m_iSelection[PLAYER_1]] = NSMAN->steps;
317192
GAMESTATE->m_pCurSteps[PLAYER_1].Set(NSMAN->steps);
318193
GAMESTATE->m_PreferredDifficulty[PLAYER_1].Set(
319194
NSMAN->steps->GetDifficulty());
@@ -382,6 +257,12 @@ ScreenNetSelectMusic::LeftAndRightPressed(const PlayerNumber pn)
382257
INPUTMAPPER->IsBeingPressed(GAME_BUTTON_RIGHT, pn);
383258
}
384259

260+
ScreenNetSelectMusic::~ScreenNetSelectMusic()
261+
{
262+
if (PREFSMAN->m_verbose_log > 1)
263+
LOG->Trace("ScreenNetSelectMusic::~ScreenNetSelectMusic()");
264+
}
265+
385266
bool
386267
ScreenNetSelectMusic::MenuLeft(const InputEventPlus& input)
387268
{
@@ -441,7 +322,8 @@ ScreenNetSelectMusic::SelectCurrent()
441322

442323
if (pSong == NULL)
443324
return false;
444-
325+
if (m_vpSteps.size() <= m_iSelection[PLAYER_1])
326+
return false;
445327
GAMESTATE->m_pCurSong.Set(pSong);
446328
Steps* pSteps = m_vpSteps[m_iSelection[PLAYER_1]];
447329
GAMESTATE->m_pCurSteps[PLAYER_1].Set(pSteps);
@@ -478,19 +360,8 @@ ScreenNetSelectMusic::TweenOffScreen()
478360
void
479361
ScreenNetSelectMusic::StartSelectedSong()
480362
{
481-
Song* pSong = m_MusicWheel.GetSelectedSong();
482-
GAMESTATE->m_pCurSong.Set(pSong);
483-
FOREACH_EnabledPlayer(pn)
484-
{
485-
StepsType st = GAMESTATE->GetCurrentStyle(pn)
486-
->m_StepsType; // StepsType_dance_single;
487-
Steps* pSteps = m_vpSteps[m_iSelection[PLAYER_1]];
488-
GAMESTATE->m_PreferredDifficulty[pn].Set(pSteps->GetDifficulty());
489-
GAMESTATE->m_pCurSteps[pn].Set(pSteps);
490-
}
491-
492363
GAMESTATE->m_PreferredSortOrder = GAMESTATE->m_SortOrder;
493-
GAMESTATE->m_pPreferredSong = pSong;
364+
GAMESTATE->m_pPreferredSong = GAMESTATE->m_pCurSong;
494365

495366
// force event mode
496367
GAMESTATE->m_bTemporaryEventMode = true;
@@ -499,32 +370,6 @@ ScreenNetSelectMusic::StartSelectedSong()
499370
StartTransitioningScreen(SM_GoToNextScreen);
500371
}
501372

502-
/*
503-
void
504-
ScreenNetSelectMusic::UpdateDifficulties(PlayerNumber pn)
505-
{
506-
if (GAMESTATE->m_pCurSong == NULL) {
507-
m_StepsDisplays[pn].SetFromStepsTypeAndMeterAndDifficultyAndCourseType(
508-
StepsType_Invalid, 0, Difficulty_Beginner);
509-
// m_DifficultyIcon[pn].SetFromSteps( pn, NULL ); // It will blank it
510-
// out
511-
return;
512-
}
513-
514-
StepsType st = GAMESTATE->GetCurrentStyle(pn)->m_StepsType;
515-
516-
Steps* pSteps =
517-
SongUtil::GetStepsByDifficulty(GAMESTATE->m_pCurSong, st, m_DC[pn]);
518-
GAMESTATE->m_pCurSteps[pn].Set(pSteps);
519-
520-
if ((m_DC[pn] < NUM_Difficulty) && (m_DC[pn] >= Difficulty_Beginner))
521-
m_StepsDisplays[pn].SetFromSteps(pSteps);
522-
else
523-
m_StepsDisplays[pn].SetFromStepsTypeAndMeterAndDifficultyAndCourseType(
524-
StepsType_Invalid, 0, Difficulty_Beginner);
525-
}
526-
*/
527-
528373
void
529374
ScreenNetSelectMusic::BeginScreen()
530375
{

src/ScreenNetSelectMusic.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
class ScreenNetSelectMusic : public ScreenSelectMusic
1717
{
1818
public:
19+
~ScreenNetSelectMusic() override;
1920
void Init() override;
2021
void BeginScreen() override;
2122

@@ -47,26 +48,10 @@ class ScreenNetSelectMusic : public ScreenSelectMusic
4748

4849
void TweenOffScreen() override;
4950

50-
ThemeMetric<SampleMusicPreviewMode> SAMPLE_MUSIC_PREVIEW_MODE;
51-
RString m_sSectionMusicPath;
52-
RString m_sRouletteMusicPath;
53-
RString m_sRandomMusicPath;
54-
55-
ThemeMetric<RString> MUSIC_WHEEL_TYPE;
56-
57-
ThemeMetric<float> SAMPLE_MUSIC_FALLBACK_FADE_IN_SECONDS;
58-
ThemeMetric<float> SAMPLE_MUSIC_FADE_OUT_SECONDS;
59-
ThemeMetric<bool> ALIGN_MUSIC_BEATS;
60-
6151
private:
6252
RageSound m_soundChangeOpt;
6353
RageSound m_soundChangeSel;
6454

65-
// todo: do this theme-side instead. -aj
66-
ModIconRow m_ModIconRow[NUM_PLAYERS];
67-
68-
Song* m_cSong;
69-
7055
bool m_bInitialSelect;
7156
bool m_bAllowInput;
7257
};

0 commit comments

Comments
 (0)