From 9e1a2441b07aafd04a6d7fee3bbdcab0a2e5b577 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 28 Apr 2007 19:27:36 +0000 Subject: [PATCH] optimize. GetLuaType is fast, but still locks Lua and impacts gameplay a bit when ARROW_SPACING is looked up hundreds of times per frame. --- stepmania/src/ThemeMetric.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/stepmania/src/ThemeMetric.h b/stepmania/src/ThemeMetric.h index afd2603bc7..3b0aad5dba 100644 --- a/stepmania/src/ThemeMetric.h +++ b/stepmania/src/ThemeMetric.h @@ -35,6 +35,7 @@ protected: RString m_sName; LuaReference m_Value; mutable T m_currentValue; + bool m_bCallEachTime; public: /* Initializing with no group and name is allowed; if you do this, you must @@ -87,10 +88,14 @@ public: m_currentValue = T(); lua_pop( L, 1 ); LUA->Release(L); + + /* If the value is a function, evaluate it every time. */ + m_bCallEachTime = ThemeMetricTypeTraits::Callable && m_Value.GetLuaType() == LUA_TFUNCTION; } else { m_Value.Unset(); + m_bCallEachTime = false; } } @@ -114,8 +119,7 @@ public: ASSERT( m_sName != "" ); ASSERT_M( m_Value.IsSet(), m_sGroup + " " + m_sName ); - /* If the value is a function, evaluate it every time. */ - if( ThemeMetricTypeTraits::Callable && m_Value.GetLuaType() == LUA_TFUNCTION ) + if( m_bCallEachTime ) { Lua *L = LUA->Get();