Changeset View
Changeset View
Standalone View
Standalone View
source/gameengine/GameLogic/SCA_IpoActuator.cpp
- This file was moved from source/gameengine/Ketsji/KX_IpoActuator.cpp.
| Show All 22 Lines | |||||
| * | * | ||||
| * The Original Code is: all of this file. | * The Original Code is: all of this file. | ||||
| * | * | ||||
| * Contributor(s): none yet. | * Contributor(s): none yet. | ||||
| * | * | ||||
| * ***** END GPL LICENSE BLOCK ***** | * ***** END GPL LICENSE BLOCK ***** | ||||
| */ | */ | ||||
| /** \file gameengine/Ketsji/KX_IpoActuator.cpp | /** \file gameengine/GameLogic/SCA_IpoActuator.cpp | ||||
| * \ingroup ketsji | * \ingroup ketsji | ||||
| */ | */ | ||||
| #include <cmath> | #include <cmath> | ||||
| #include "KX_IpoActuator.h" | #include "SCA_IpoActuator.h" | ||||
| #include "KX_GameObject.h" | #include "KX_GameObject.h" | ||||
| #include "FloatValue.h" | #include "FloatValue.h" | ||||
| #include "KX_KetsjiEngine.h" | #include "KX_KetsjiEngine.h" | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| /* Type strings */ | /* Type strings */ | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| const char *KX_IpoActuator::S_KX_ACT_IPO_PLAY_STRING = "Play"; | const char *SCA_IpoActuator::S_KX_ACT_IPO_PLAY_STRING = "Play"; | ||||
| const char *KX_IpoActuator::S_KX_ACT_IPO_PINGPONG_STRING = "PingPong"; | const char *SCA_IpoActuator::S_KX_ACT_IPO_PINGPONG_STRING = "PingPong"; | ||||
| const char *KX_IpoActuator::S_KX_ACT_IPO_FLIPPER_STRING = "Flipper"; | const char *SCA_IpoActuator::S_KX_ACT_IPO_FLIPPER_STRING = "Flipper"; | ||||
| const char *KX_IpoActuator::S_KX_ACT_IPO_LOOPSTOP_STRING = "LoopStop"; | const char *SCA_IpoActuator::S_KX_ACT_IPO_LOOPSTOP_STRING = "LoopStop"; | ||||
| const char *KX_IpoActuator::S_KX_ACT_IPO_LOOPEND_STRING = "LoopEnd"; | const char *SCA_IpoActuator::S_KX_ACT_IPO_LOOPEND_STRING = "LoopEnd"; | ||||
| const char *KX_IpoActuator::S_KX_ACT_IPO_KEY2KEY_STRING = "Key2key"; | const char *SCA_IpoActuator::S_KX_ACT_IPO_KEY2KEY_STRING = "Key2key"; | ||||
| const char *KX_IpoActuator::S_KX_ACT_IPO_FROM_PROP_STRING = "FromProp"; | const char *SCA_IpoActuator::S_KX_ACT_IPO_FROM_PROP_STRING = "FromProp"; | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| /* Native functions */ | /* Native functions */ | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| KX_IpoActuator::KX_IpoActuator(SCA_IObject* gameobj, | SCA_IpoActuator::SCA_IpoActuator(SCA_IObject* gameobj, | ||||
| const STR_String& propname, | const STR_String& propname, | ||||
| const STR_String& framePropname, | const STR_String& framePropname, | ||||
| float starttime, | float starttime, | ||||
| float endtime, | float endtime, | ||||
| bool recurse, | bool recurse, | ||||
| int acttype, | int acttype, | ||||
| bool ipo_as_force, | bool ipo_as_force, | ||||
| bool ipo_add, | bool ipo_add, | ||||
| bool ipo_local) | bool ipo_local) | ||||
| : SCA_IActuator(gameobj, KX_ACT_IPO), | : SCA_IActuator(gameobj, SCA_ACT_IPO), | ||||
| m_bNegativeEvent(false), | m_bNegativeEvent(false), | ||||
| m_startframe (starttime), | m_startframe (starttime), | ||||
| m_endframe(endtime), | m_endframe(endtime), | ||||
| m_recurse(recurse), | m_recurse(recurse), | ||||
| m_localtime(starttime), | m_localtime(starttime), | ||||
| m_direction(1), | m_direction(1), | ||||
| m_propname(propname), | m_propname(propname), | ||||
| m_framepropname(framePropname), | m_framepropname(framePropname), | ||||
| m_ipo_as_force(ipo_as_force), | m_ipo_as_force(ipo_as_force), | ||||
| m_ipo_add(ipo_add), | m_ipo_add(ipo_add), | ||||
| m_ipo_local(ipo_local), | m_ipo_local(ipo_local), | ||||
| m_type(acttype) | m_type(acttype) | ||||
| { | { | ||||
| this->ResetStartTime(); | this->ResetStartTime(); | ||||
| m_bIpoPlaying = false; | m_bIpoPlaying = false; | ||||
| } | } | ||||
| void KX_IpoActuator::SetStart(float starttime) | void SCA_IpoActuator::SetStart(float starttime) | ||||
| { | { | ||||
| m_startframe=starttime; | m_startframe=starttime; | ||||
| } | } | ||||
| void KX_IpoActuator::SetEnd(float endtime) | void SCA_IpoActuator::SetEnd(float endtime) | ||||
| { | { | ||||
| m_endframe=endtime; | m_endframe=endtime; | ||||
| } | } | ||||
| bool KX_IpoActuator::ClampLocalTime() | bool SCA_IpoActuator::ClampLocalTime() | ||||
| { | { | ||||
| if (m_startframe < m_endframe) | if (m_startframe < m_endframe) | ||||
| { | { | ||||
| if (m_localtime < m_startframe) | if (m_localtime < m_startframe) | ||||
| { | { | ||||
| m_localtime = m_startframe; | m_localtime = m_startframe; | ||||
| return true; | return true; | ||||
| } | } | ||||
| Show All 12 Lines | if (m_startframe < m_endframe) | ||||
| { | { | ||||
| m_localtime = m_endframe; | m_localtime = m_endframe; | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| void KX_IpoActuator::SetStartTime(float curtime) | void SCA_IpoActuator::SetStartTime(float curtime) | ||||
| { | { | ||||
| float direction = m_startframe < m_endframe ? 1.0f : -1.0f; | float direction = m_startframe < m_endframe ? 1.0f : -1.0f; | ||||
| if (m_direction > 0) | if (m_direction > 0) | ||||
| m_starttime = curtime - direction*(m_localtime - m_startframe)/KX_KetsjiEngine::GetAnimFrameRate(); | m_starttime = curtime - direction*(m_localtime - m_startframe)/KX_KetsjiEngine::GetAnimFrameRate(); | ||||
| else | else | ||||
| m_starttime = curtime - direction*(m_endframe - m_localtime)/KX_KetsjiEngine::GetAnimFrameRate(); | m_starttime = curtime - direction*(m_endframe - m_localtime)/KX_KetsjiEngine::GetAnimFrameRate(); | ||||
| } | } | ||||
| void KX_IpoActuator::SetLocalTime(float curtime) | void SCA_IpoActuator::SetLocalTime(float curtime) | ||||
| { | { | ||||
| float delta_time = (curtime - m_starttime)*KX_KetsjiEngine::GetAnimFrameRate(); | float delta_time = (curtime - m_starttime)*KX_KetsjiEngine::GetAnimFrameRate(); | ||||
| // negative delta_time is caused by floating point inaccuracy | // negative delta_time is caused by floating point inaccuracy | ||||
| // perhaps the inaccuracy could be reduced a bit | // perhaps the inaccuracy could be reduced a bit | ||||
| if ((m_localtime==m_startframe || m_localtime==m_endframe) && delta_time<0.0) | if ((m_localtime==m_startframe || m_localtime==m_endframe) && delta_time<0.0) | ||||
| { | { | ||||
| delta_time = 0.0; | delta_time = 0.0; | ||||
| } | } | ||||
| if (m_endframe < m_startframe) | if (m_endframe < m_startframe) | ||||
| delta_time = -delta_time; | delta_time = -delta_time; | ||||
| if (m_direction > 0) | if (m_direction > 0) | ||||
| m_localtime = m_startframe + delta_time; | m_localtime = m_startframe + delta_time; | ||||
| else | else | ||||
| m_localtime = m_endframe - delta_time; | m_localtime = m_endframe - delta_time; | ||||
| } | } | ||||
| bool KX_IpoActuator::Update(double curtime, bool frame) | bool SCA_IpoActuator::Update(double curtime, bool frame) | ||||
| { | { | ||||
| // result = true if animation has to be continued, false if animation stops | // result = true if animation has to be continued, false if animation stops | ||||
| // maybe there are events for us in the queue ! | // maybe there are events for us in the queue ! | ||||
| bool bNegativeEvent = false; | bool bNegativeEvent = false; | ||||
| bool numevents = false; | bool numevents = false; | ||||
| bool bIpoStart = false; | bool bIpoStart = false; | ||||
| curtime -= KX_KetsjiEngine::GetSuspendedDelta(); | curtime -= KX_KetsjiEngine::GetSuspendedDelta(); | ||||
| Show All 14 Lines | if (!bNegativeEvent) | ||||
| { | { | ||||
| // start for all Ipo, initial start for LOOP_STOP | // start for all Ipo, initial start for LOOP_STOP | ||||
| m_starttime = curtime; | m_starttime = curtime; | ||||
| m_bIpoPlaying = true; | m_bIpoPlaying = true; | ||||
| bIpoStart = true; | bIpoStart = true; | ||||
| } | } | ||||
| } | } | ||||
| switch ((IpoActType)m_type) | switch (m_type) | ||||
| { | { | ||||
| case KX_ACT_IPO_PLAY: | case KX_ACT_IPO_PLAY: | ||||
| { | { | ||||
| // Check if playing forwards. result = ! finished | // Check if playing forwards. result = ! finished | ||||
| if (start_smaller_then_end > 0.f) | if (start_smaller_then_end > 0.f) | ||||
| result = (m_localtime < m_endframe && m_bIpoPlaying); | result = (m_localtime < m_endframe && m_bIpoPlaying); | ||||
| ▲ Show 20 Lines • Show All 176 Lines • ▼ Show 20 Lines | if (!result) | ||||
| if (m_type != KX_ACT_IPO_LOOPSTOP) | if (m_type != KX_ACT_IPO_LOOPSTOP) | ||||
| this->ResetStartTime(); | this->ResetStartTime(); | ||||
| m_bIpoPlaying = false; | m_bIpoPlaying = false; | ||||
| } | } | ||||
| return result; | return result; | ||||
| } | } | ||||
| void KX_IpoActuator::ResetStartTime() | void SCA_IpoActuator::ResetStartTime() | ||||
| { | { | ||||
| this->m_starttime = -2.0f * fabsf(this->m_endframe - this->m_startframe) - 1.0f; | this->m_starttime = -2.0f * fabsf(this->m_endframe - this->m_startframe) - 1.0f; | ||||
| } | } | ||||
| int KX_IpoActuator::string2mode(const char *modename) | int SCA_IpoActuator::string2mode(const char *modename) | ||||
| { | { | ||||
| IpoActType res = KX_ACT_IPO_NODEF; | IpoActType res = KX_ACT_IPO_NODEF; | ||||
| if (strcmp(modename, S_KX_ACT_IPO_PLAY_STRING)==0) { | if (strcmp(modename, S_KX_ACT_IPO_PLAY_STRING)==0) { | ||||
| res = KX_ACT_IPO_PLAY; | res = KX_ACT_IPO_PLAY; | ||||
| } else if (strcmp(modename, S_KX_ACT_IPO_PINGPONG_STRING)==0) { | } else if (strcmp(modename, S_KX_ACT_IPO_PINGPONG_STRING)==0) { | ||||
| res = KX_ACT_IPO_PINGPONG; | res = KX_ACT_IPO_PINGPONG; | ||||
| } else if (strcmp(modename, S_KX_ACT_IPO_FLIPPER_STRING)==0) { | } else if (strcmp(modename, S_KX_ACT_IPO_FLIPPER_STRING)==0) { | ||||
| res = KX_ACT_IPO_FLIPPER; | res = KX_ACT_IPO_FLIPPER; | ||||
| } else if (strcmp(modename, S_KX_ACT_IPO_LOOPSTOP_STRING)==0) { | } else if (strcmp(modename, S_KX_ACT_IPO_LOOPSTOP_STRING)==0) { | ||||
| res = KX_ACT_IPO_LOOPSTOP; | res = KX_ACT_IPO_LOOPSTOP; | ||||
| } else if (strcmp(modename, S_KX_ACT_IPO_LOOPEND_STRING)==0) { | } else if (strcmp(modename, S_KX_ACT_IPO_LOOPEND_STRING)==0) { | ||||
| Show All 10 Lines | |||||
| #ifdef WITH_PYTHON | #ifdef WITH_PYTHON | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| /* Python functions */ | /* Python functions */ | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| /* Integration hooks ------------------------------------------------------- */ | /* Integration hooks ------------------------------------------------------- */ | ||||
| PyTypeObject KX_IpoActuator::Type = { | PyTypeObject SCA_IpoActuator::Type = { | ||||
| PyVarObject_HEAD_INIT(NULL, 0) | PyVarObject_HEAD_INIT(NULL, 0) | ||||
| "KX_IpoActuator", | "SCA_IpoActuator", | ||||
| sizeof(PyObjectPlus_Proxy), | sizeof(PyObjectPlus_Proxy), | ||||
| 0, | 0, | ||||
| py_base_dealloc, | py_base_dealloc, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| py_base_repr, | py_base_repr, | ||||
| 0,0,0,0,0,0,0,0,0, | 0,0,0,0,0,0,0,0,0, | ||||
| Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, | ||||
| 0,0,0,0,0,0,0, | 0,0,0,0,0,0,0, | ||||
| Methods, | Methods, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| &SCA_IActuator::Type, | &SCA_IActuator::Type, | ||||
| 0,0,0,0,0,0, | 0,0,0,0,0,0, | ||||
| py_base_new | py_base_new | ||||
| }; | }; | ||||
| PyMethodDef KX_IpoActuator::Methods[] = { | PyMethodDef SCA_IpoActuator::Methods[] = { | ||||
| {NULL,NULL} //Sentinel | {NULL,NULL} //Sentinel | ||||
| }; | }; | ||||
| PyAttributeDef KX_IpoActuator::Attributes[] = { | PyAttributeDef SCA_IpoActuator::Attributes[] = { | ||||
| KX_PYATTRIBUTE_RW_FUNCTION("frameStart", KX_IpoActuator, pyattr_get_frame_start, pyattr_set_frame_start), | KX_PYATTRIBUTE_RW_FUNCTION("frameStart", SCA_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_RW_FUNCTION("frameEnd", SCA_IpoActuator, pyattr_get_frame_end, pyattr_set_frame_end), | ||||
| KX_PYATTRIBUTE_STRING_RW("propName", 0, MAX_PROP_NAME, false, KX_IpoActuator, m_propname), | KX_PYATTRIBUTE_STRING_RW("propName", 0, MAX_PROP_NAME, false, SCA_IpoActuator, m_propname), | ||||
| KX_PYATTRIBUTE_STRING_RW("framePropName", 0, MAX_PROP_NAME, false, KX_IpoActuator, m_framepropname), | KX_PYATTRIBUTE_STRING_RW("framePropName", 0, MAX_PROP_NAME, false, SCA_IpoActuator, m_framepropname), | ||||
| KX_PYATTRIBUTE_INT_RW("mode", KX_ACT_IPO_NODEF+1, KX_ACT_IPO_MAX-1, true, KX_IpoActuator, m_type), | KX_PYATTRIBUTE_INT_RW("mode", KX_ACT_IPO_NODEF+1, KX_ACT_IPO_MAX-1, true, SCA_IpoActuator, m_type), | ||||
| KX_PYATTRIBUTE_BOOL_RW("useIpoAsForce", KX_IpoActuator, m_ipo_as_force), | KX_PYATTRIBUTE_BOOL_RW("useIpoAsForce", SCA_IpoActuator, m_ipo_as_force), | ||||
| KX_PYATTRIBUTE_BOOL_RW("useIpoAdd", KX_IpoActuator, m_ipo_add), | KX_PYATTRIBUTE_BOOL_RW("useIpoAdd", SCA_IpoActuator, m_ipo_add), | ||||
| KX_PYATTRIBUTE_BOOL_RW("useIpoLocal", KX_IpoActuator, m_ipo_local), | KX_PYATTRIBUTE_BOOL_RW("useIpoLocal", SCA_IpoActuator, m_ipo_local), | ||||
| KX_PYATTRIBUTE_BOOL_RW("useChildren", KX_IpoActuator, m_recurse), | KX_PYATTRIBUTE_BOOL_RW("useChildren", SCA_IpoActuator, m_recurse), | ||||
| { NULL } //Sentinel | { NULL } //Sentinel | ||||
| }; | }; | ||||
| PyObject *KX_IpoActuator::pyattr_get_frame_start(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | PyObject *SCA_IpoActuator::pyattr_get_frame_start(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | ||||
| { | { | ||||
| KX_IpoActuator* self = static_cast<KX_IpoActuator*>(self_v); | SCA_IpoActuator* self = static_cast<SCA_IpoActuator*>(self_v); | ||||
| return PyFloat_FromDouble(self->m_startframe); | return PyFloat_FromDouble(self->m_startframe); | ||||
| } | } | ||||
| int KX_IpoActuator::pyattr_set_frame_start(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | int SCA_IpoActuator::pyattr_set_frame_start(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | ||||
| { | { | ||||
| KX_IpoActuator* self = static_cast<KX_IpoActuator*>(self_v); | SCA_IpoActuator* self = static_cast<SCA_IpoActuator*>(self_v); | ||||
| float param = PyFloat_AsDouble(value); | float param = PyFloat_AsDouble(value); | ||||
| if (PyErr_Occurred()) { | if (PyErr_Occurred()) { | ||||
| PyErr_SetString(PyExc_AttributeError, "frameStart = float: KX_IpoActuator, expected a float value"); | PyErr_SetString(PyExc_AttributeError, "frameStart = float: SCA_IpoActuator, expected a float value"); | ||||
| return PY_SET_ATTR_FAIL; | return PY_SET_ATTR_FAIL; | ||||
| } | } | ||||
| self->m_startframe = param; | self->m_startframe = param; | ||||
| self->ResetStartTime(); | self->ResetStartTime(); | ||||
| return PY_SET_ATTR_SUCCESS; | return PY_SET_ATTR_SUCCESS; | ||||
| } | } | ||||
| PyObject *KX_IpoActuator::pyattr_get_frame_end(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | PyObject *SCA_IpoActuator::pyattr_get_frame_end(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) | ||||
| { | { | ||||
| KX_IpoActuator* self = static_cast<KX_IpoActuator*>(self_v); | SCA_IpoActuator* self = static_cast<SCA_IpoActuator*>(self_v); | ||||
| return PyFloat_FromDouble(self->m_endframe); | return PyFloat_FromDouble(self->m_endframe); | ||||
| } | } | ||||
| int KX_IpoActuator::pyattr_set_frame_end(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | int SCA_IpoActuator::pyattr_set_frame_end(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | ||||
| { | { | ||||
| KX_IpoActuator* self = static_cast<KX_IpoActuator*>(self_v); | SCA_IpoActuator* self = static_cast<SCA_IpoActuator*>(self_v); | ||||
| float param = PyFloat_AsDouble(value); | float param = PyFloat_AsDouble(value); | ||||
| if (PyErr_Occurred()) { | if (PyErr_Occurred()) { | ||||
| PyErr_SetString(PyExc_AttributeError, "frameEnd = float: KX_IpoActuator, expected a float value"); | PyErr_SetString(PyExc_AttributeError, "frameEnd = float: SCA_IpoActuator, expected a float value"); | ||||
| return PY_SET_ATTR_FAIL; | return PY_SET_ATTR_FAIL; | ||||
| } | } | ||||
| self->m_endframe = param; | self->m_endframe = param; | ||||
| self->ResetStartTime(); | self->ResetStartTime(); | ||||
| return PY_SET_ATTR_SUCCESS; | return PY_SET_ATTR_SUCCESS; | ||||
| } | } | ||||
| #endif // WITH_PYTHON | #endif // WITH_PYTHON | ||||
| /* eof */ | /* eof */ | ||||