Files
itgmania212121/stepmania/src/ActorUtil.h
T

117 lines
5.0 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; \
Actor *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,
FT_Movie,
FT_Directory,
FT_Xml,
2006-10-09 05:51:12 +00:00
FT_Lua,
FT_Model,
NUM_FileType,
FT_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 );
Actor* Create( const RString& sClassName, const XNode* pNode, Actor *pParentActor );
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 );
void LoadCommand( Actor& actor, const RString &sType, const RString &sCommandName );
void LoadCommandFromName( Actor& actor, const RString &sType, const RString &sCommandName, const RString &sName );
2006-08-15 19:19:59 +00:00
void LoadAndPlayCommand( Actor& actor, const RString &sType, const RString &sCommandName );
2006-01-22 01:00:06 +00:00
void LoadAllCommands( Actor& actor, const RString &sType );
void LoadAllCommandsFromName( Actor& actor, const RString &sType, const RString &sName );
2006-08-15 19:19:59 +00:00
inline void OnCommand( Actor& actor, const RString &sType ) { LoadAndPlayCommand( actor, sType, "On" ); }
2006-01-22 01:00:06 +00:00
inline void OffCommand( Actor& actor, const RString &sType ) { LoadAndPlayCommand( actor, sType, "Off" ); }
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 );
2006-08-15 19:19:59 +00:00
OnCommand( actor, sType );
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 ); }
2006-08-15 19:19:59 +00:00
inline void LoadAndPlayCommand( Actor* pActor, const RString &sType, const RString &sCommandName ) { if(pActor) LoadAndPlayCommand( *pActor, sType, sCommandName ); }
inline void OnCommand( Actor* pActor, const RString &sType ) { if(pActor) OnCommand( *pActor, sType ); }
2006-01-22 01:00:06 +00:00
inline void OffCommand( Actor* pActor, const RString &sType ) { if(pActor) OffCommand( *pActor, sType ); }
2006-08-15 19:19:59 +00:00
inline void SetXYAndOnCommand( Actor* pActor, const RString &sType ) { if(pActor) SetXYAndOnCommand( *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 );
2006-08-15 19:25:45 +00:00
Actor* MakeActor( const RString &sPath, const XNode *pParent = NULL, 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 );
2005-02-26 10:07:02 +00:00
2006-01-22 01:00:06 +00:00
void 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 );
2006-01-22 01:00:06 +00:00
void SetParamFromStack( Lua *L, RString sName, LuaReference *pOld=NULL );
void GetParam( Lua *L, const RString &sName );
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 )
#define ON_COMMAND( actor ) ActorUtil::OnCommand( actor, m_sName )
2006-08-18 03:15:48 +00:00
#define OFF_COMMAND( actor ) ActorUtil::OffCommand( actor, m_sName )
#define SET_XY_AND_ON_COMMAND( actor ) ActorUtil::SetXYAndOnCommand( actor, m_sName )
#define COMMAND( actor, command_name ) ActorUtil::LoadAndPlayCommand( actor, m_sName, command_name )
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.
*/