Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDalai Felinto <dfelinto@gmail.com>2010-12-07 04:54:25 +0300
committerDalai Felinto <dfelinto@gmail.com>2010-12-07 04:54:25 +0300
commitfe0f78a66978f52eac94199baffc577cbf7c1123 (patch)
treedfe249c1e8683560c4032f98b67fa764906f7db0 /source/gameengine/Ketsji
parent7b39a7cdb9a1fd6dc08b3098800e0edce9d8a28e (diff)
BGE BugFix: [#21246] Some values for ipoactuator.frameEnd and frameStart make ipo not play the first time
This is a bug as old as the ability to change the actuator values through Python. For the records: although Blender supports floats as frame values BGE doesn't. It could but it doesn't. So only integers (longs) will be valid start/end frames.
Diffstat (limited to 'source/gameengine/Ketsji')
-rw-r--r--source/gameengine/Ketsji/KX_IpoActuator.cpp57
-rw-r--r--source/gameengine/Ketsji/KX_IpoActuator.h8
2 files changed, 60 insertions, 5 deletions
diff --git a/source/gameengine/Ketsji/KX_IpoActuator.cpp b/source/gameengine/Ketsji/KX_IpoActuator.cpp
index 605aea5f592..7bc85f5f262 100644
--- a/source/gameengine/Ketsji/KX_IpoActuator.cpp
+++ b/source/gameengine/Ketsji/KX_IpoActuator.cpp
@@ -81,7 +81,7 @@ KX_IpoActuator::KX_IpoActuator(SCA_IObject* gameobj,
m_ipo_local(ipo_local),
m_type(acttype)
{
- m_starttime = -2.0*fabs(m_endframe - m_startframe) - 1.0;
+ this->ResetStartTime();
m_bIpoPlaying = false;
}
@@ -176,7 +176,7 @@ bool KX_IpoActuator::Update(double curtime, bool frame)
bool result=true;
if (!bNegativeEvent)
{
- if (m_starttime < -2.0f*start_smaller_then_end*(m_endframe - m_startframe))
+ if (m_starttime < -2.0f*fabs(m_endframe - m_startframe))
{
// start for all Ipo, initial start for LOOP_STOP
m_starttime = curtime;
@@ -371,13 +371,18 @@ bool KX_IpoActuator::Update(double curtime, bool frame)
if (!result)
{
if (m_type != KX_ACT_IPO_LOOPSTOP)
- m_starttime = -2.0*start_smaller_then_end*(m_endframe - m_startframe) - 1.0;
+ this->ResetStartTime();
m_bIpoPlaying = false;
}
return result;
}
+void KX_IpoActuator::ResetStartTime()
+{
+ this->m_starttime = -2.0*fabs(this->m_endframe - this->m_startframe) - 1.0;
+}
+
int KX_IpoActuator::string2mode(char* modename) {
IpoActType res = KX_ACT_IPO_NODEF;
@@ -435,8 +440,8 @@ PyMethodDef KX_IpoActuator::Methods[] = {
};
PyAttributeDef KX_IpoActuator::Attributes[] = {
- KX_PYATTRIBUTE_FLOAT_RW("frameStart", 0, 300000, KX_IpoActuator, m_startframe),
- KX_PYATTRIBUTE_FLOAT_RW("frameEnd", 0, 300000, KX_IpoActuator, m_endframe),
+ KX_PYATTRIBUTE_RW_FUNCTION("frameStart", KX_IpoActuator, pyattr_get_frame_start, pyattr_set_frame_start),
+ KX_PYATTRIBUTE_RW_FUNCTION("frameEnd", KX_IpoActuator, pyattr_get_frame_end, pyattr_set_frame_end),
KX_PYATTRIBUTE_STRING_RW("propName", 0, 64, false, KX_IpoActuator, m_propname),
KX_PYATTRIBUTE_STRING_RW("framePropName", 0, 64, false, KX_IpoActuator, m_framepropname),
KX_PYATTRIBUTE_INT_RW("mode", KX_ACT_IPO_NODEF+1, KX_ACT_IPO_MAX-1, true, KX_IpoActuator, m_type),
@@ -448,6 +453,48 @@ PyAttributeDef KX_IpoActuator::Attributes[] = {
{ NULL } //Sentinel
};
+PyObject* KX_IpoActuator::pyattr_get_frame_start(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+ KX_IpoActuator* self= static_cast<KX_IpoActuator*>(self_v);
+ return PyLong_FromDouble(self->m_startframe);
+}
+
+int KX_IpoActuator::pyattr_set_frame_start(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
+{
+ KX_IpoActuator* self= static_cast<KX_IpoActuator*>(self_v);
+ float param = PyLong_AsDouble(value);
+
+ if (PyErr_Occurred()) {
+ PyErr_SetString(PyExc_AttributeError, "frameStart = integer: KX_IpoActuator, expected an integer value");
+ return PY_SET_ATTR_FAIL;
+ }
+
+ self->m_startframe = param;
+ self->ResetStartTime();
+ return PY_SET_ATTR_SUCCESS;
+}
+
+PyObject* KX_IpoActuator::pyattr_get_frame_end(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+ KX_IpoActuator* self= static_cast<KX_IpoActuator*>(self_v);
+ return PyLong_FromDouble(self->m_endframe);
+}
+
+int KX_IpoActuator::pyattr_set_frame_end(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
+{
+ KX_IpoActuator* self= static_cast<KX_IpoActuator*>(self_v);
+ float param = PyLong_AsDouble(value);
+
+ if (PyErr_Occurred()) {
+ PyErr_SetString(PyExc_AttributeError, "frameEnd = integer: KX_IpoActuator, expected an integer value");
+ return PY_SET_ATTR_FAIL;
+ }
+
+ self->m_endframe = param;
+ self->ResetStartTime();
+ return PY_SET_ATTR_SUCCESS;
+}
+
#endif // WITH_PYTHON
/* eof */
diff --git a/source/gameengine/Ketsji/KX_IpoActuator.h b/source/gameengine/Ketsji/KX_IpoActuator.h
index cefd00c4ae3..dc3ff5543f9 100644
--- a/source/gameengine/Ketsji/KX_IpoActuator.h
+++ b/source/gameengine/Ketsji/KX_IpoActuator.h
@@ -86,6 +86,9 @@ protected:
bool m_bIpoPlaying;
+ /** Reset/Update the start time*/
+ void ResetStartTime();
+
public:
enum IpoActType
{
@@ -100,6 +103,11 @@ public:
KX_ACT_IPO_MAX
};
+ static PyObject* pyattr_get_frame_start(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+ static int pyattr_set_frame_start(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+ static PyObject* pyattr_get_frame_end(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
+ static int pyattr_set_frame_end(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
+
static const char *S_KX_ACT_IPO_PLAY_STRING;
static const char *S_KX_ACT_IPO_PINGPONG_STRING;
static const char *S_KX_ACT_IPO_FLIPPER_STRING;