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"
|
2004-01-07 04:37:00 +00:00
|
|
|
#include "RageUtil.h"
|
2005-01-16 23:40:21 +00:00
|
|
|
#include "XmlFile.h"
|
|
|
|
|
#include "ActorUtil.h"
|
2005-01-26 11:21:43 +00:00
|
|
|
#include "LuaBinding.h"
|
|
|
|
|
#include "ActorCommands.h"
|
2005-02-28 04:14:25 +00:00
|
|
|
#include "RageDisplay.h"
|
|
|
|
|
#include "ScreenDimensions.h"
|
2005-01-26 11:21:43 +00:00
|
|
|
|
|
|
|
|
// lua start
|
|
|
|
|
LUA_REGISTER_CLASS( ActorFrame )
|
|
|
|
|
// lua end
|
2005-03-01 02:50:23 +00:00
|
|
|
|
|
|
|
|
/* Tricky: We need ActorFrames created in XML to auto delete their children.
|
|
|
|
|
* We don't want classes that derive from ActorFrame to auto delete their
|
|
|
|
|
* children. The name "ActorFrame" is widely used in XML, so we'll have
|
|
|
|
|
* that string instead create an ActorFrameAutoDeleteChildren object.
|
|
|
|
|
*/
|
|
|
|
|
//REGISTER_ACTOR_CLASS( ActorFrame )
|
|
|
|
|
class ActorFrameAutoDeleteChildren : public ActorFrame
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ActorFrameAutoDeleteChildren() { DeleteChildrenWhenDone(true); }
|
|
|
|
|
void LoadFromNode( const CString& sDir, const XNode* pNode )
|
|
|
|
|
{
|
|
|
|
|
ActorFrame::LoadFromNode( sDir, pNode );
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Load children
|
|
|
|
|
//
|
|
|
|
|
const XNode* pChildren = pNode->GetChild("children");
|
|
|
|
|
if( pChildren )
|
|
|
|
|
{
|
|
|
|
|
FOREACH_CONST_Child( pChildren, pChild )
|
|
|
|
|
{
|
|
|
|
|
Actor* pChildActor = ActorUtil::LoadFromActorFile( sDir, pChild );
|
|
|
|
|
if( pChildActor )
|
|
|
|
|
AddChild( pChildActor );
|
|
|
|
|
}
|
|
|
|
|
SortByDrawOrder();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
REGISTER_ACTOR_CLASS_WITH_NAME( ActorFrameAutoDeleteChildren, ActorFrame )
|
|
|
|
|
|
2001-12-11 11:44:26 +00:00
|
|
|
|
2004-10-16 02:46:10 +00:00
|
|
|
ActorFrame::ActorFrame()
|
|
|
|
|
{
|
|
|
|
|
m_bPropagateCommands = false;
|
2005-01-15 20:32:35 +00:00
|
|
|
m_bDeleteChildren = false;
|
2005-02-28 04:14:25 +00:00
|
|
|
m_fUpdateRate = 1;
|
|
|
|
|
m_fFOV = -1;
|
|
|
|
|
m_bOverrideLighting = false;
|
|
|
|
|
m_bLighting = false;
|
2005-01-15 20:32:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ActorFrame::~ActorFrame()
|
|
|
|
|
{
|
|
|
|
|
if( m_bDeleteChildren )
|
|
|
|
|
DeleteAllChildren();
|
2004-10-16 02:46:10 +00:00
|
|
|
}
|
|
|
|
|
|
2005-01-17 05:28:16 +00:00
|
|
|
void ActorFrame::LoadFromNode( const CString& sDir, const XNode* pNode )
|
2005-01-16 23:40:21 +00:00
|
|
|
{
|
2005-01-17 05:28:16 +00:00
|
|
|
Actor::LoadFromNode( sDir, pNode );
|
2005-01-16 23:40:21 +00:00
|
|
|
|
2005-02-28 04:14:25 +00:00
|
|
|
pNode->GetAttrValue( "UpdateRate", m_fUpdateRate );
|
|
|
|
|
pNode->GetAttrValue( "FOV", m_fFOV );
|
|
|
|
|
m_bOverrideLighting = pNode->GetAttrValue( "Lighting", m_bLighting );
|
2005-01-16 23:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
2003-01-11 08:55:21 +00:00
|
|
|
void ActorFrame::AddChild( Actor* pActor )
|
2002-06-14 22:25:22 +00:00
|
|
|
{
|
2003-08-23 22:04:57 +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()) );
|
2003-08-23 22:04:57 +00:00
|
|
|
#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 );
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-20 10:12:50 +00:00
|
|
|
void ActorFrame::RemoveAllChildren()
|
|
|
|
|
{
|
|
|
|
|
m_SubActors.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2003-01-20 05:08:35 +00:00
|
|
|
void ActorFrame::MoveToTail( Actor* pActor )
|
2003-01-11 08:55:21 +00:00
|
|
|
{
|
|
|
|
|
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 )
|
2003-01-11 08:55:21 +00:00
|
|
|
{
|
|
|
|
|
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
|
|
|
{
|
2005-02-28 04:14:25 +00:00
|
|
|
if( m_fFOV != -1 )
|
|
|
|
|
{
|
|
|
|
|
DISPLAY->CameraPushMatrix();
|
|
|
|
|
DISPLAY->LoadMenuPerspective( m_fFOV, SCREEN_CENTER_X, SCREEN_CENTER_Y );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( m_bOverrideLighting )
|
|
|
|
|
{
|
|
|
|
|
DISPLAY->SetLighting( m_bLighting );
|
|
|
|
|
if( m_bLighting )
|
|
|
|
|
DISPLAY->SetLightDirectional(
|
|
|
|
|
0,
|
|
|
|
|
RageColor(1,1,1,1),
|
|
|
|
|
RageColor(1,1,1,1),
|
|
|
|
|
RageColor(1,1,1,1),
|
|
|
|
|
RageVector3(0,0,1) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-05-15 06:09:19 +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();
|
2005-02-28 04:14:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( m_bOverrideLighting )
|
|
|
|
|
{
|
|
|
|
|
// TODO: pop state instead of turning lighting off
|
|
|
|
|
DISPLAY->SetLightOff( 0 );
|
|
|
|
|
DISPLAY->SetLighting( false );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( m_fFOV != -1 )
|
|
|
|
|
{
|
|
|
|
|
DISPLAY->CameraPopMatrix();
|
|
|
|
|
}
|
2001-12-11 11:44:26 +00:00
|
|
|
}
|
|
|
|
|
|
2005-02-17 05:12:23 +00:00
|
|
|
void ActorFrame::RunCommandsOnChildren( const LuaReference& cmds )
|
2004-10-16 02:46:10 +00:00
|
|
|
{
|
|
|
|
|
for( unsigned i=0; i<m_SubActors.size(); i++ )
|
2005-01-26 11:21:43 +00:00
|
|
|
m_SubActors[i]->RunCommands( cmds );
|
2004-10-16 02:46:10 +00:00
|
|
|
}
|
|
|
|
|
|
2001-12-11 11:44:26 +00:00
|
|
|
void ActorFrame::Update( float fDeltaTime )
|
|
|
|
|
{
|
2002-07-31 19:40:40 +00:00
|
|
|
// LOG->Trace( "ActorFrame::Update( %f )", fDeltaTime );
|
2005-02-28 04:14:25 +00:00
|
|
|
|
|
|
|
|
fDeltaTime *= m_fUpdateRate;
|
|
|
|
|
|
2002-01-16 10:01:32 +00:00
|
|
|
Actor::Update( fDeltaTime );
|
2001-12-11 11:44:26 +00:00
|
|
|
|
2004-02-02 01:10:56 +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 )
|
2003-05-15 06:09:19 +00:00
|
|
|
|
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++ )
|
2005-01-17 04:08:08 +00:00
|
|
|
{
|
|
|
|
|
const Actor* pActor = m_SubActors[i];
|
|
|
|
|
m = max(m, m_fHibernateSecondsLeft + pActor->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();
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-17 05:12:23 +00:00
|
|
|
void ActorFrame::RunCommands( const LuaReference& cmds )
|
2005-01-26 11:21:43 +00:00
|
|
|
{
|
|
|
|
|
if( m_bPropagateCommands )
|
|
|
|
|
RunCommandsOnChildren( cmds );
|
|
|
|
|
else
|
|
|
|
|
Actor::RunCommands( cmds );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ActorFrame::SetPropagateCommands( bool b )
|
|
|
|
|
{
|
|
|
|
|
m_bPropagateCommands = b;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
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();
|
2004-10-16 02:46:10 +00:00
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
if( sName=="propagate" )
|
|
|
|
|
{
|
2004-12-03 05:19:46 +00:00
|
|
|
m_bPropagateCommands = bArg(1);
|
2004-10-16 02:46:10 +00:00
|
|
|
RunCommandOnChildren( command );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Actor::HandleCommand( command );
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-12-03 05:19:46 +00:00
|
|
|
EndHandleArgs;
|
2004-10-16 02:46:10 +00:00
|
|
|
} while(0);
|
|
|
|
|
|
2005-01-26 11:21:43 +00:00
|
|
|
// 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.
|
2004-10-16 02:46:10 +00:00
|
|
|
if( m_bPropagateCommands && sName!="propagate" )
|
|
|
|
|
RunCommandOnChildren( command );
|
2004-01-20 03:31:08 +00:00
|
|
|
}
|
2005-01-26 11:21:43 +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 )
|
|
|
|
|
{
|
2005-02-23 20:37:21 +00:00
|
|
|
// HACK: Don't propogate Init. It gets called once for every Actor when the
|
|
|
|
|
// Actor is loaded, and we don't want to call it again.
|
2004-02-01 05:03:45 +00:00
|
|
|
Actor::PlayCommand( sCommandName );
|
|
|
|
|
|
2005-02-23 20:37:21 +00:00
|
|
|
if( sCommandName == "Init" )
|
|
|
|
|
return;
|
|
|
|
|
|
2004-02-01 03:14:37 +00:00
|
|
|
for( unsigned i=0; i<m_SubActors.size(); i++ )
|
2005-01-17 04:08:08 +00:00
|
|
|
{
|
|
|
|
|
Actor* pActor = m_SubActors[i];
|
|
|
|
|
pActor->PlayCommand( sCommandName );
|
|
|
|
|
}
|
2004-02-01 03:14:37 +00:00
|
|
|
}
|
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.
|
|
|
|
|
*/
|