[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39853] trunk/blender/source/gameengine/ Converter: BGE animations: This is an attempt to help smooth out some more compatibility issues with the new action actuator .
Mitchell Stokes
mogurijin at gmail.com
Thu Sep 1 23:47:47 CEST 2011
Revision: 39853
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39853
Author: moguri
Date: 2011-09-01 21:47:46 +0000 (Thu, 01 Sep 2011)
Log Message:
-----------
BGE animations: This is an attempt to help smooth out some more compatibility issues with the new action actuator. It now has a similar pulse behavior to the old actuator. This has worked well in most of my tests, but YoFrankie still has problems, and it appears to have gotten a little worse.
Modified Paths:
--------------
trunk/blender/source/gameengine/Converter/BL_ActionActuator.cpp
trunk/blender/source/gameengine/Converter/BL_ActionActuator.h
Modified: trunk/blender/source/gameengine/Converter/BL_ActionActuator.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_ActionActuator.cpp 2011-09-01 20:20:29 UTC (rev 39852)
+++ trunk/blender/source/gameengine/Converter/BL_ActionActuator.cpp 2011-09-01 21:47:46 UTC (rev 39853)
@@ -129,6 +129,50 @@
m_blendframe = newtime;
}
+void BL_ActionActuator::SetLocalTime(float curtime)
+{
+ float dt = (curtime-m_starttime)*KX_KetsjiEngine::GetAnimFrameRate();
+
+ if (m_endframe < m_startframe)
+ dt = -dt;
+
+ m_localtime = m_startframe + dt;
+
+ // Handle wrap around
+ if (m_localtime < min(m_startframe, m_endframe) || m_localtime > max(m_startframe, m_endframe))
+ {
+ switch(m_playtype)
+ {
+ case ACT_ACTION_PLAY:
+ // Clamp
+ m_localtime = m_endframe;
+ break;
+ case ACT_ACTION_LOOP_END:
+ // Put the time back to the beginning
+ m_localtime = m_startframe;
+ m_starttime = curtime;
+ break;
+ case ACT_ACTION_PINGPONG:
+ // Swap the start and end frames
+ float temp = m_startframe;
+ m_startframe = m_endframe;
+ m_endframe = temp;
+
+ m_starttime = curtime;
+
+ break;
+ }
+ }
+}
+
+void BL_ActionActuator::ResetStartTime(float curtime)
+{
+ float dt = m_localtime - m_startframe;
+
+ m_starttime = curtime - dt / (KX_KetsjiEngine::GetAnimFrameRate());
+ //SetLocalTime(curtime);
+}
+
CValue* BL_ActionActuator::GetReplica() {
BL_ActionActuator* replica = new BL_ActionActuator(*this);//m_float,GetName());
replica->ProcessReplica();
@@ -194,11 +238,46 @@
RemoveAllEvents();
}
+ if (m_flag & ACT_FLAG_ATTEMPT_PLAY)
+ SetLocalTime(curtime);
+
if (bUseContinue && (m_flag & ACT_FLAG_ACTIVE))
+ {
m_localtime = obj->GetActionFrame(m_layer);
+ ResetStartTime(curtime);
+ }
+
+ // Handle a frame property if it's defined
+ if ((m_flag & ACT_FLAG_ACTIVE) && m_framepropname[0] != 0)
+ {
+ CValue* oldprop = obj->GetProperty(m_framepropname);
+ CValue* newval = new CFloatValue(obj->GetActionFrame(m_layer));
+ if (oldprop)
+ oldprop->SetValue(newval);
+ else
+ obj->SetProperty(m_framepropname, newval);
+
+ newval->Release();
+ }
+
+ // Handle a finished animation
+ if ((m_flag & ACT_FLAG_PLAY_END) && obj->IsActionDone(m_layer))
+ {
+ m_flag &= ~ACT_FLAG_ACTIVE;
+ m_flag &= ~ACT_FLAG_ATTEMPT_PLAY;
+ obj->StopAction(m_layer);
+ return false;
+ }
- if (bPositiveEvent)
+ // If a different action is playing, we've been overruled and are no longer active
+ if (obj->GetCurrentAction(m_layer) != m_action)
+ m_flag &= ~ACT_FLAG_ACTIVE;
+
+ if (bPositiveEvent || (m_flag & ACT_FLAG_ATTEMPT_PLAY && !(m_flag & ACT_FLAG_ACTIVE)))
{
+ if (bPositiveEvent)
+ ResetStartTime(curtime);
+
if (obj->PlayAction(m_action->id.name+2, start, end, m_layer, m_priority, m_blendin, playtype, m_layer_weight, m_ipo_flags))
{
m_flag |= ACT_FLAG_ACTIVE;
@@ -210,11 +289,11 @@
else
m_flag &= ~ACT_FLAG_PLAY_END;
}
- else
- return false;
+ m_flag |= ACT_FLAG_ATTEMPT_PLAY;
}
else if ((m_flag & ACT_FLAG_ACTIVE) && bNegativeEvent)
{
+ m_flag &= ~ACT_FLAG_ATTEMPT_PLAY;
bAction *curr_action = obj->GetCurrentAction(m_layer);
if (curr_action && curr_action != m_action)
{
@@ -259,27 +338,6 @@
}
}
- // Handle a frame property if it's defined
- if ((m_flag & ACT_FLAG_ACTIVE) && m_framepropname[0] != 0)
- {
- CValue* oldprop = obj->GetProperty(m_framepropname);
- CValue* newval = new CFloatValue(obj->GetActionFrame(m_layer));
- if (oldprop)
- oldprop->SetValue(newval);
- else
- obj->SetProperty(m_framepropname, newval);
-
- newval->Release();
- }
-
- // Handle a finished animation
- if ((m_flag & ACT_FLAG_PLAY_END) && obj->IsActionDone(m_layer))
- {
- m_flag &= ~ACT_FLAG_ACTIVE;
- obj->StopAction(m_layer);
- return false;
- }
-
return true;
}
Modified: trunk/blender/source/gameengine/Converter/BL_ActionActuator.h
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_ActionActuator.h 2011-09-01 20:20:29 UTC (rev 39852)
+++ trunk/blender/source/gameengine/Converter/BL_ActionActuator.h 2011-09-01 21:47:46 UTC (rev 39853)
@@ -64,6 +64,8 @@
virtual void ProcessReplica();
void SetBlendTime (float newtime);
+ void SetLocalTime (float curtime);
+ void ResetStartTime (float curtime);
bAction* GetAction() { return m_action; }
void SetAction(bAction* act) { m_action= act; }
@@ -150,7 +152,7 @@
ACT_FLAG_ACTIVE = 1<<3,
ACT_FLAG_CONTINUE = 1<<4,
ACT_FLAG_PLAY_END = 1<<5,
-
+ ACT_FLAG_ATTEMPT_PLAY = 1<<6,
};
#endif
More information about the Bf-blender-cvs
mailing list