2005-09-03 17:37:42 +00:00
|
|
|
#include "global.h"
|
|
|
|
|
#include "LuaExpressionTransform.h"
|
|
|
|
|
#include "LuaReference.h"
|
|
|
|
|
#include "LuaManager.h"
|
2005-10-07 01:58:41 +00:00
|
|
|
#include "RageUtil.h"
|
2005-09-03 17:37:42 +00:00
|
|
|
|
|
|
|
|
LuaExpressionTransform::LuaExpressionTransform()
|
|
|
|
|
{
|
2006-09-21 02:09:44 +00:00
|
|
|
m_pexprTransformFunction = new LuaReference;
|
2005-09-03 17:37:42 +00:00
|
|
|
m_iNumSubdivisions = 1;
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-20 21:44:58 +00:00
|
|
|
LuaExpressionTransform::~LuaExpressionTransform()
|
|
|
|
|
{
|
|
|
|
|
delete m_pexprTransformFunction;
|
|
|
|
|
}
|
|
|
|
|
|
2006-09-22 03:22:08 +00:00
|
|
|
void LuaExpressionTransform::SetFromReference( const LuaReference &ref )
|
|
|
|
|
{
|
|
|
|
|
*m_pexprTransformFunction = ref;
|
|
|
|
|
}
|
|
|
|
|
|
2005-09-03 23:07:28 +00:00
|
|
|
const Actor::TweenState &LuaExpressionTransform::GetPosition( float fPositionOffsetFromCenter, int iItemIndex, int iNumItems ) const
|
2005-09-03 17:37:42 +00:00
|
|
|
{
|
|
|
|
|
PositionOffsetAndItemIndex key = { fPositionOffsetFromCenter, iItemIndex };
|
|
|
|
|
|
2005-09-03 23:07:28 +00:00
|
|
|
map<PositionOffsetAndItemIndex,Actor::TweenState>::const_iterator iter = m_mapPositionToTweenStateCache.find( key );
|
2005-09-03 17:37:42 +00:00
|
|
|
if( iter != m_mapPositionToTweenStateCache.end() )
|
|
|
|
|
return iter->second;
|
|
|
|
|
|
|
|
|
|
Actor a;
|
|
|
|
|
|
|
|
|
|
Lua *L = LUA->Get();
|
|
|
|
|
m_pexprTransformFunction->PushSelf( L );
|
|
|
|
|
ASSERT( !lua_isnil(L, -1) );
|
|
|
|
|
a.PushSelf( L );
|
|
|
|
|
LuaHelpers::Push( fPositionOffsetFromCenter, L );
|
|
|
|
|
LuaHelpers::Push( iItemIndex, L );
|
|
|
|
|
LuaHelpers::Push( iNumItems, L );
|
|
|
|
|
lua_call( L, 4, 0 ); // 4 args, 0 results
|
|
|
|
|
LUA->Release(L);
|
|
|
|
|
|
|
|
|
|
return m_mapPositionToTweenStateCache[key] = a.DestTweenState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LuaExpressionTransform::PositionItem( Actor *pActor, float fPositionOffsetFromCenter, int iItemIndex, int iNumItems )
|
|
|
|
|
{
|
|
|
|
|
float fInterval = 1.0f / m_iNumSubdivisions;
|
|
|
|
|
float fFloor = QuantizeDown( fPositionOffsetFromCenter, fInterval );
|
|
|
|
|
float fCeil = QuantizeUp( fPositionOffsetFromCenter, fInterval );
|
|
|
|
|
|
|
|
|
|
if( fFloor == fCeil )
|
|
|
|
|
{
|
|
|
|
|
pActor->DestTweenState() = GetPosition( fCeil, iItemIndex, iNumItems );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const Actor::TweenState &tsFloor = GetPosition( fFloor, iItemIndex, iNumItems );
|
|
|
|
|
const Actor::TweenState &tsCeil = GetPosition( fCeil, iItemIndex, iNumItems );
|
|
|
|
|
|
|
|
|
|
float fPercentTowardCeil = SCALE( fPositionOffsetFromCenter, fFloor, fCeil, 0.0f, 1.0f );
|
|
|
|
|
Actor::TweenState::MakeWeightedAverage( pActor->DestTweenState(), tsFloor, tsCeil, fPercentTowardCeil );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* (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.
|
|
|
|
|
*/
|