00001
00007
00008
00009 #include "KX_SoundActuator.h"
00010 #include "SND_SoundObject.h"
00011 #include "KX_GameObject.h"
00012 #include <iostream>
00013
00014
00015
00016
00017 KX_SoundActuator::KX_SoundActuator(SCA_IObject* gameobj,
00018 SND_SoundObject* sndobj,
00019 KX_SOUNDACT_TYPE type,
00020 short start,
00021 short end,
00022 PyTypeObject* T)
00023 : SCA_IActuator(gameobj,T)
00024 {
00025 m_soundObject = sndobj;
00026 m_type = type;
00027 m_lastEvent = true;
00028 m_startFrame = start;
00029 m_endFrame = end;
00030 }
00031
00032 KX_SoundActuator::~KX_SoundActuator()
00033 {
00034 ;
00035 }
00036
00037 bool KX_SoundActuator::Update(double curtime,double deltatime)
00038 {
00039 bool result = false;
00040 bool bNegativeEvent = IsNegativeEvent();
00041
00042
00043 if (m_lastEvent != bNegativeEvent) {
00044
00045
00046 if (bNegativeEvent) {
00047
00048 switch (m_type) {
00049 case KX_SOUNDACT_PLAYSTOP:
00050 case KX_SOUNDACT_LOOPSTOP:
00051 m_soundObject->stopSound();
00052 break;
00053 case KX_SOUNDACT_PLAYEND:
00054 break;
00055 case KX_SOUNDACT_LOWERPITCH:
00056 case KX_SOUNDACT_RAISEPITCH:
00057 break;
00058 default:
00059
00060 break;
00061 }
00062 }
00063 else {
00064 if (m_soundObject) {
00065
00066
00067
00068
00069 switch (m_type) {
00070 case KX_SOUNDACT_LOOPEND:
00071 case KX_SOUNDACT_LOOPSTOP:
00072
00073
00074 m_soundObject->setLooping(true);
00075 m_soundObject->startSound();
00076 break;
00077 case KX_SOUNDACT_PLAYSTOP:
00078 case KX_SOUNDACT_PLAYEND:
00079 m_soundObject->startSound();
00080 break;
00081 case KX_SOUNDACT_LOWERPITCH:
00082 m_soundObject->setPitch(m_soundObject->getPitch() - 0.05);
00083 break;
00084 case KX_SOUNDACT_RAISEPITCH:
00085 m_soundObject->setPitch(m_soundObject->getPitch() + 0.05);
00086 break;
00087 default:
00088
00089 break;
00090 }
00091 }
00092 m_lastEvent = bNegativeEvent;
00093 }
00094 }
00095
00096 switch (m_soundObject->getPlaystate()) {
00097 case SND_PLAYING:
00098 case SND_MUST_PLAY:
00099
00100 m_soundObject->setPosition(((KX_GameObject*)this->GetParent())->NodeGetWorldPosition());
00101 m_soundObject->setOrientation(((KX_GameObject*)this->GetParent())->NodeGetWorldOrientation());
00102 result = true;
00103 break;
00104
00105 default:
00106 result = false;
00107 m_lastEvent = true;
00108 }
00109
00110 return result;
00111 }
00112
00113
00114
00115
00116
00117 PyTypeObject KX_SoundActuator::Type = {
00118 PyObject_HEAD_INIT(&PyType_Type)
00119 0,
00120 "KX_SoundActuator",
00121 sizeof(KX_SoundActuator),
00122 0,
00123 PyDestructor,
00124 0,
00125 __getattr,
00126 __setattr,
00127 0,
00128 __repr,
00129 0,
00130 0,
00131 0,
00132 0,
00133 0
00134 };
00135
00136 PyParentObject KX_SoundActuator::Parents[] = {
00137 &KX_SoundActuator::Type,
00138 &SCA_IActuator::Type,
00139 &SCA_ILogicBrick::Type,
00140 &CValue::Type,
00141 NULL
00142 };
00143
00144 PyMethodDef KX_SoundActuator::Methods[] = {
00145 {"setFilename", (PyCFunction) KX_SoundActuator::sPySetFilename, METH_VARARGS},
00146 {"getFilename", (PyCFunction) KX_SoundActuator::sPyGetFilename, METH_VARARGS},
00147 {NULL,NULL}
00148 };
00149
00150 PyObject* KX_SoundActuator::_getattr(char* attr) {
00151 _getattr_up(SCA_IActuator);
00152 }
00153
00154
00155 PyObject* KX_SoundActuator::PySetFilename(PyObject* self,
00156 PyObject* args,
00157 PyObject* kwds) {
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172 Py_Return;
00173
00174 }
00175
00176
00177 PyObject* KX_SoundActuator::PyGetFilename(PyObject* self,
00178 PyObject* args,
00179 PyObject* kwds) {
00180
00181
00182
00183 char *name = "kip";
00184
00185
00186
00187
00188
00189 return PyString_FromString(name);
00190 }
00191
00192