Files
itgmania212121/stepmania/src/ActorFrame.cpp
T

233 lines
6.3 KiB
C++
Raw Normal View History

2004-06-08 00:47:53 +00:00
#include "global.h"
2001-12-11 11:44:26 +00:00
#include "ActorFrame.h"
2004-06-10 22:47:51 +00:00
#include "arch/Dialog/Dialog.h"
#include "RageUtil.h"
2001-12-11 11:44:26 +00:00
ActorFrame::ActorFrame()
{
m_bPropagateCommands = false;
}
void ActorFrame::AddChild( Actor* pActor )
2002-06-14 22:25:22 +00:00
{
#if _DEBUG
// check that this Actor isn't already added.
vector<Actor*>::iterator iter = find( m_SubActors.begin(), m_SubActors.end(), pActor );
2003-10-10 23:42:02 +00:00
if( iter != m_SubActors.end() )
2004-06-10 22:47:51 +00:00
Dialog::OK( ssprintf("Actor \"%s\" adds child \"%s\" more than once", m_sName.c_str(), pActor->m_sName.c_str()) );
#endif
2002-07-23 01:41:40 +00:00
ASSERT( pActor );
ASSERT( (void*)pActor != (void*)0xC0000005 );
2002-10-31 04:23:39 +00:00
m_SubActors.push_back( pActor );
2002-06-14 22:25:22 +00:00
}
2001-12-11 11:44:26 +00:00
2004-05-02 03:01:27 +00:00
void ActorFrame::RemoveChild( Actor* pActor )
{
vector<Actor*>::iterator iter = find( m_SubActors.begin(), m_SubActors.end(), pActor );
if( iter != m_SubActors.end() )
m_SubActors.erase( iter );
}
2003-01-20 05:08:35 +00:00
void ActorFrame::MoveToTail( Actor* pActor )
{
vector<Actor*>::iterator iter = find( m_SubActors.begin(), m_SubActors.end(), pActor );
if( iter == m_SubActors.end() ) // didn't find
{
ASSERT(0); // called with a pActor that doesn't exist
return;
}
m_SubActors.erase( iter );
m_SubActors.push_back( pActor );
}
2003-01-20 05:08:35 +00:00
void ActorFrame::MoveToHead( Actor* pActor )
{
vector<Actor*>::iterator iter = find( m_SubActors.begin(), m_SubActors.end(), pActor );
if( iter == m_SubActors.end() ) // didn't find
{
ASSERT(0); // called with a pActor that doesn't exist
return;
}
m_SubActors.erase( iter );
m_SubActors.insert( m_SubActors.begin(), pActor );
}
2002-05-19 01:59:48 +00:00
void ActorFrame::DrawPrimitives()
2001-12-11 11:44:26 +00:00
{
// Don't set Actor-defined render states because we won't be drawing
// any geometry that belongs to this object.
// Actor::DrawPrimitives();
2002-01-16 10:01:32 +00:00
// draw all sub-ActorFrames while we're in the ActorFrame's local coordinate space
2004-01-11 07:12:13 +00:00
for( unsigned i=0; i<m_SubActors.size(); i++ )
2001-12-11 11:44:26 +00:00
m_SubActors[i]->Draw();
}
2004-12-03 05:19:46 +00:00
void ActorFrame::RunCommandOnChildren( const Commands &cmd )
2004-01-11 07:12:13 +00:00
{
for( unsigned i=0; i<m_SubActors.size(); i++ )
2004-12-03 05:19:46 +00:00
m_SubActors[i]->RunCommands( cmd );
2004-01-11 07:12:13 +00:00
}
2001-12-11 11:44:26 +00:00
2004-12-03 05:19:46 +00:00
void ActorFrame::RunCommandOnChildren( const Command &cmd )
{
for( unsigned i=0; i<m_SubActors.size(); i++ )
m_SubActors[i]->HandleCommand( cmd );
}
2001-12-11 11:44:26 +00:00
void ActorFrame::Update( float fDeltaTime )
{
// LOG->Trace( "ActorFrame::Update( %f )", fDeltaTime );
2002-01-16 10:01:32 +00:00
Actor::Update( fDeltaTime );
2001-12-11 11:44:26 +00:00
if( m_fHibernateSecondsLeft > 0 )
return;
2002-01-16 10:01:32 +00:00
// update all sub-Actors
2003-10-07 06:00:33 +00:00
for( vector<Actor*>::iterator it=m_SubActors.begin(); it!=m_SubActors.end(); it++ )
(*it)->Update(fDeltaTime);
2001-12-11 11:44:26 +00:00
}
2004-01-11 05:33:24 +00:00
#define PropagateActorFrameCommand( cmd, type ) \
void ActorFrame::cmd( type f ) \
{ \
Actor::cmd( f ); \
\
/* set all sub-Actors */ \
for( unsigned i=0; i<m_SubActors.size(); i++ ) \
m_SubActors[i]->cmd( f ); \
}
2001-12-11 11:44:26 +00:00
2004-01-11 05:33:24 +00:00
PropagateActorFrameCommand( SetDiffuse, RageColor )
2004-05-15 09:26:21 +00:00
PropagateActorFrameCommand( SetZTestMode, ZTestMode )
2004-01-11 05:33:24 +00:00
PropagateActorFrameCommand( SetZWrite, bool )
PropagateActorFrameCommand( HurryTweening, float )
2004-02-01 04:41:48 +00:00
void ActorFrame::SetDiffuseAlpha( float f )
{
Actor::SetDiffuseAlpha( f );
/* set all sub-Actors */
for( unsigned i=0; i<m_SubActors.size(); i++ )
m_SubActors[i]->SetDiffuseAlpha( f );
}
2003-07-20 01:32:42 +00:00
void ActorFrame::FinishTweening()
{
Actor::FinishTweening();
// set all sub-Actors
for( unsigned i=0; i<m_SubActors.size(); i++ )
m_SubActors[i]->FinishTweening();
}
2003-03-02 01:43:33 +00:00
float ActorFrame::GetTweenTimeLeft() const
2003-01-01 09:05:21 +00:00
{
2003-03-02 01:43:33 +00:00
float m = Actor::GetTweenTimeLeft();
2003-01-01 09:05:21 +00:00
for( unsigned i=0; i<m_SubActors.size(); i++ )
m = max(m, m_fHibernateSecondsLeft + m_SubActors[i]->GetTweenTimeLeft());
2003-01-01 09:05:21 +00:00
return m;
}
2004-05-02 03:01:27 +00:00
bool CompareActorsByDrawOrder(const Actor *p1, const Actor *p2)
2003-06-19 18:05:52 +00:00
{
2004-05-02 03:01:27 +00:00
return p1->GetDrawOrder() < p2->GetDrawOrder();
2003-06-20 23:07:45 +00:00
}
2003-06-19 18:05:52 +00:00
2004-05-02 03:01:27 +00:00
void ActorFrame::SortByDrawOrder()
2003-06-20 23:07:45 +00:00
{
2004-05-02 03:01:27 +00:00
// Preserve ordering of Actors with equal DrawOrders.
stable_sort( m_SubActors.begin(), m_SubActors.end(), CompareActorsByDrawOrder );
2003-06-19 18:05:52 +00:00
}
2004-01-17 23:14:56 +00:00
void ActorFrame::DeleteAllChildren()
{
for( unsigned i=0; i<m_SubActors.size(); i++ )
delete m_SubActors[i];
m_SubActors.clear();
}
2004-12-03 05:19:46 +00:00
void ActorFrame::HandleCommand( const Command &command )
2004-01-20 03:31:08 +00:00
{
2004-12-03 05:19:46 +00:00
BeginHandleArgs;
2004-02-04 11:05:33 +00:00
2004-12-03 05:19:46 +00:00
const CString& sName = command.GetName();
do
{
if( sName=="propagate" )
{
2004-12-03 05:19:46 +00:00
m_bPropagateCommands = bArg(1);
RunCommandOnChildren( command );
}
else
{
Actor::HandleCommand( command );
break;
}
2004-12-03 05:19:46 +00:00
EndHandleArgs;
} while(0);
/* By default, don't propograte most commands to children; it makes no sense
* to run "x,50" recursively. If m_bPropagateCommands is set, propagate all
* commands. */
if( m_bPropagateCommands && sName!="propagate" )
RunCommandOnChildren( command );
2004-01-20 03:31:08 +00:00
}
2004-02-01 03:14:37 +00:00
2004-08-22 02:16:31 +00:00
void ActorFrame::GainFocus( float fRate, bool bRewindMovie, bool bLoop )
2004-02-01 03:14:37 +00:00
{
2004-08-22 02:16:31 +00:00
Actor::GainFocus( fRate, bRewindMovie, bLoop );
2004-02-01 05:03:45 +00:00
2004-02-01 03:14:37 +00:00
for( unsigned i=0; i<m_SubActors.size(); i++ )
2004-08-22 02:16:31 +00:00
m_SubActors[i]->GainFocus( fRate, bRewindMovie, bLoop );
2004-02-01 03:14:37 +00:00
}
2004-08-22 02:16:31 +00:00
void ActorFrame::LoseFocus()
2004-02-01 03:14:37 +00:00
{
2004-08-22 02:16:31 +00:00
Actor::LoseFocus();
2004-02-01 05:03:45 +00:00
2004-02-01 03:14:37 +00:00
for( unsigned i=0; i<m_SubActors.size(); i++ )
2004-08-22 02:16:31 +00:00
m_SubActors[i]->LoseFocus();
2004-02-01 03:14:37 +00:00
}
void ActorFrame::PlayCommand( const CString &sCommandName )
{
2004-02-01 05:03:45 +00:00
Actor::PlayCommand( sCommandName );
2004-02-01 03:14:37 +00:00
for( unsigned i=0; i<m_SubActors.size(); i++ )
m_SubActors[i]->PlayCommand( sCommandName );
}
2004-06-08 00:47:53 +00:00
/*
* (c) 2001-2004 Chris Danford
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/