Files
itgmania212121/stepmania/src/ActorUtil.h
T

156 lines
6.6 KiB
C++
Raw Normal View History

2005-02-09 05:31:14 +00:00
/* ActorUtil - Utility functions for creating and manipulating Actors. */
2005-02-09 05:27:51 +00:00
2003-04-13 21:52:50 +00:00
#ifndef ActorUtil_H
#define ActorUtil_H
#include "Actor.h"
#include "RageTexture.h"
2003-04-13 21:52:50 +00:00
class XNode;
2003-04-13 21:52:50 +00:00
2006-10-11 07:33:38 +00:00
typedef Actor* (*CreateActorFn)();
template<typename T>
Actor *CreateActor() { return new T; }
2005-02-09 05:31:14 +00:00
// Each Actor class should have a REGISTER_ACTOR_CLASS in its CPP file.
2005-03-01 02:49:57 +00:00
#define REGISTER_ACTOR_CLASS_WITH_NAME( className, externalClassName ) \
2006-10-11 07:33:38 +00:00
struct Register##className { \
Register##className() { ActorUtil::Register(#externalClassName, CreateActor<className>); } \
2005-02-09 05:31:14 +00:00
}; \
2005-07-18 22:00:19 +00:00
static Register##className register##className; \
2006-10-20 00:17:51 +00:00
className *className::Copy() const { return new className(*this); }
2003-04-13 21:52:50 +00:00
2005-03-01 02:49:57 +00:00
#define REGISTER_ACTOR_CLASS( className ) REGISTER_ACTOR_CLASS_WITH_NAME( className, className )
enum FileType
{
FT_Bitmap,
2006-12-04 22:32:53 +00:00
FT_Sound,
FT_Movie,
FT_Directory,
2006-10-09 05:51:12 +00:00
FT_Lua,
FT_Model,
NUM_FileType,
2006-10-14 02:59:24 +00:00
FileType_Invalid
};
2006-01-22 01:00:06 +00:00
const RString& FileTypeToString( FileType ft );
2005-01-17 05:42:52 +00:00
namespace ActorUtil
{
2005-02-09 05:31:14 +00:00
// Every screen should register its class at program initialization.
2006-01-22 01:00:06 +00:00
void Register( const RString& sClassName, CreateActorFn pfn );
2005-02-09 05:31:14 +00:00
2006-09-29 07:24:40 +00:00
apActorCommands ParseActorCommands( const RString &sCommands, const RString &sName = "" );
2006-01-22 01:00:06 +00:00
void SetXY( Actor& actor, const RString &sType );
2007-02-19 09:30:07 +00:00
inline void PlayCommand( Actor& actor, const RString &sCommandName ) { actor.PlayCommand( sCommandName ); }
inline void OnCommand( Actor& actor )
{
ASSERT_M( actor.HasCommand("On"), ssprintf("%s is missing an OnCommand.", actor.GetName().c_str()) );
2007-02-19 09:30:07 +00:00
actor.PlayCommand("On");
}
inline void OffCommand( Actor& actor )
{
// HACK: It's very often that we command things to TweenOffScreen
// that we aren't drawing. We know that an Actor is not being
// used if its name is blank. So, do nothing on Actors with a blank name.
// (Do "playcommand" anyway; BGAs often have no name.)
if( actor.GetName().empty() )
return;
ASSERT_M( actor.HasCommand("Off"), ssprintf("Actor %s is missing an OffCommand.", actor.GetName().c_str()) );
2007-02-19 09:30:07 +00:00
actor.PlayCommand("Off");
}
2006-01-22 01:00:06 +00:00
void LoadCommand( Actor& actor, const RString &sType, const RString &sCommandName );
void LoadCommandFromName( Actor& actor, const RString &sType, const RString &sCommandName, const RString &sName );
void LoadAllCommands( Actor& actor, const RString &sType );
void LoadAllCommandsFromName( Actor& actor, const RString &sType, const RString &sName );
2007-02-19 09:30:07 +00:00
inline void LoadAllCommandsAndSetXY( Actor& actor, const RString &sType )
{
LoadAllCommands( actor, sType );
SetXY( actor, sType );
}
inline void LoadAllCommandsAndOnCommand( Actor& actor, const RString &sType )
{
LoadAllCommands( actor, sType );
OnCommand( actor );
}
2006-08-15 19:19:59 +00:00
inline void SetXYAndOnCommand( Actor& actor, const RString &sType )
2005-01-17 05:42:52 +00:00
{
2005-02-23 22:21:39 +00:00
SetXY( actor, sType );
2007-02-19 09:30:07 +00:00
OnCommand( actor );
}
inline void LoadAllCommandsAndSetXYAndOnCommand( Actor& actor, const RString &sType )
{
LoadAllCommands( actor, sType );
SetXY( actor, sType );
OnCommand( actor );
2005-01-17 05:42:52 +00:00
}
2005-01-17 05:42:52 +00:00
/* convenience */
2006-01-22 01:00:06 +00:00
inline void SetXY( Actor* pActor, const RString &sType ) { SetXY( *pActor, sType ); }
2007-02-19 09:30:07 +00:00
inline void PlayCommand( Actor* pActor, const RString &sCommandName ) { if(pActor) pActor->PlayCommand( sCommandName ); }
inline void OnCommand( Actor* pActor ) { if(pActor) ActorUtil::OnCommand( *pActor ); }
inline void OffCommand( Actor* pActor ) { if(pActor) ActorUtil::OffCommand( *pActor ); }
inline void LoadAllCommands( Actor* pActor, const RString &sType ) { if(pActor) LoadAllCommands( *pActor, sType ); }
inline void LoadAllCommandsAndSetXY( Actor* pActor, const RString &sType ) { if(pActor) LoadAllCommandsAndSetXY( *pActor, sType ); }
inline void LoadAllCommandsAndOnCommand( Actor* pActor, const RString &sType ) { if(pActor) LoadAllCommandsAndOnCommand( *pActor, sType ); }
2006-08-15 19:19:59 +00:00
inline void SetXYAndOnCommand( Actor* pActor, const RString &sType ) { if(pActor) SetXYAndOnCommand( *pActor, sType ); }
2007-02-19 09:30:07 +00:00
inline void LoadAllCommandsAndSetXYAndOnCommand( Actor* pActor, const RString &sType ) { if(pActor) LoadAllCommandsAndSetXYAndOnCommand( *pActor, sType ); }
2005-01-17 05:42:52 +00:00
// Return a Sprite, BitmapText, or Model depending on the file type
Actor* LoadFromNode( const XNode* pNode, Actor *pParentActor = NULL );
2007-05-27 07:25:33 +00:00
Actor* MakeActor( const RString &sPath, Actor *pParentActor = NULL );
RString GetSourcePath( const XNode *pNode );
2006-10-09 08:08:17 +00:00
RString GetWhere( const XNode *pNode );
bool GetAttrPath( const XNode *pNode, const RString &sName, RString &sOut );
2007-02-06 08:03:34 +00:00
bool LoadTableFromStackShowErrors( Lua *L );
2005-02-26 10:07:02 +00:00
bool ResolvePath( RString &sPath, const RString &sName );
2005-05-03 09:29:54 +00:00
void SortByZPosition( vector<Actor*> &vActors );
2006-01-22 01:00:06 +00:00
FileType GetFileType( const RString &sPath );
2005-01-17 05:42:52 +00:00
};
2003-09-21 02:36:48 +00:00
2005-02-09 05:27:51 +00:00
#define SET_XY( actor ) ActorUtil::SetXY( actor, m_sName )
2007-02-19 09:30:07 +00:00
#define ON_COMMAND( actor ) ActorUtil::OnCommand( actor )
#define OFF_COMMAND( actor ) ActorUtil::OffCommand( actor )
2006-08-18 03:15:48 +00:00
#define SET_XY_AND_ON_COMMAND( actor ) ActorUtil::SetXYAndOnCommand( actor, m_sName )
2007-02-19 09:30:07 +00:00
#define COMMAND( actor, command_name ) ActorUtil::PlayCommand( actor, command_name )
#define LOAD_ALL_COMMANDS( actor ) ActorUtil::LoadAllCommands( actor, m_sName )
#define LOAD_ALL_COMMANDS_AND_SET_XY( actor ) ActorUtil::LoadAllCommandsAndSetXY( actor, m_sName )
#define LOAD_ALL_COMMANDS_AND_ON_COMMAND( actor ) ActorUtil::LoadAllCommandsAndOnCommand( actor, m_sName )
#define LOAD_ALL_COMMANDS_AND_SET_XY_AND_ON_COMMAND( actor ) ActorUtil::LoadAllCommandsAndSetXYAndOnCommand( actor, m_sName )
2003-09-21 02:36:48 +00:00
2003-06-30 06:05:05 +00:00
#endif
2004-06-08 00:47:53 +00:00
/*
* (c) 2003-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.
*/