From 61620bb6f56c3e3659d4e1c606cb881cd9f0646e Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 12 Jul 2005 21:12:12 +0000 Subject: [PATCH] fix course mode. We've been using the environment and Lua globals as "parameters" to treat broadcasts as "functions called on every object". That doesn't work with queued message handling. It's also a bit confusing; it means there are "parameters" available only for some messages. It's cleaner to just make the information available as a function. --- stepmania/src/ScreenGameplay.cpp | 33 +++++++++++++++++++++++++++----- stepmania/src/ScreenGameplay.h | 6 ++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/stepmania/src/ScreenGameplay.cpp b/stepmania/src/ScreenGameplay.cpp index f99b5b4520..c41ebced98 100644 --- a/stepmania/src/ScreenGameplay.cpp +++ b/stepmania/src/ScreenGameplay.cpp @@ -2197,12 +2197,7 @@ void ScreenGameplay::HandleScreenMessage( const ScreenMessage SM ) int iPlaySongIndex = GAMESTATE->GetCourseSongIndex()+1; iPlaySongIndex %= m_apSongsQueue.size(); - Lua *L = LUA->Get(); - m_apSongsQueue[iPlaySongIndex]->PushSelf( L ); - GAMESTATE->m_Environment->Set( L, "NextSong" ); MESSAGEMAN->Broadcast( "NextCourseSong" ); - GAMESTATE->m_Environment->Unset( L, "NextSong" ); - LUA->Release( L ); m_NextSong.PlayCommand( "Start" ); m_NextSong.Reset(); m_NextSong.StartTransitioning( SM_LoadNextSong ); @@ -2414,6 +2409,34 @@ void ScreenGameplay::ShowOniGameOver( PlayerNumber pn ) m_sprOniGameOver[pn].PlayCommand( "Die" ); } +Song *ScreenGameplay::GetNextCourseSong() const +{ + ASSERT( GAMESTATE->IsCourseMode() ); + + int iPlaySongIndex = GAMESTATE->GetCourseSongIndex()+1; + iPlaySongIndex %= m_apSongsQueue.size(); + + return m_apSongsQueue[iPlaySongIndex]; +} + +// lua start +#include "LuaBinding.h" + +class LunaScreenGameplay: public Luna +{ +public: + LunaScreenGameplay() { LUA->Register( Register ); } + + static int GetNextCourseSong( T* p, lua_State *L ) { p->GetNextCourseSong()->PushSelf(L); return 1; } + static void Register( Lua *L ) + { + ADD_METHOD( GetNextCourseSong ) + Luna::Register( L ); + } +}; + +LUA_REGISTER_DERIVED_CLASS( ScreenGameplay, ScreenWithMenuElements ) +// lua end /* * (c) 2001-2004 Chris Danford, Glenn Maynard diff --git a/stepmania/src/ScreenGameplay.h b/stepmania/src/ScreenGameplay.h index 62dd02ef53..c207ed9f89 100644 --- a/stepmania/src/ScreenGameplay.h +++ b/stepmania/src/ScreenGameplay.h @@ -44,6 +44,12 @@ public: virtual bool UsesBackground() const { return false; } virtual ScreenType GetScreenType() const { return gameplay; } + // + // Lua + // + virtual void PushSelf( lua_State *L ); + Song *GetNextCourseSong() const; + protected: ThemeMetric PLAYER_TYPE; ThemeMetric GIVE_UP_TEXT;