Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

KX_SoundActuator.cpp

Go to the documentation of this file.
00001 
00007 
00008 
00009 #include "KX_SoundActuator.h"
00010 #include "SND_SoundObject.h"
00011 #include "KX_GameObject.h"
00012 #include <iostream>
00013 
00014 /* ------------------------------------------------------------------------- */
00015 /* Native functions                                                          */
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         ; /* intentionally empty */     
00035 }
00036 
00037 bool KX_SoundActuator::Update(double curtime,double deltatime)

00038 {
00039         bool result = false;
00040         bool bNegativeEvent = IsNegativeEvent();
00041 
00042         // check if the bNegativeEvent has changed
00043         if (m_lastEvent != bNegativeEvent) {
00044                 
00045                 // do nothing on negative events, otherwise sounds are played twice!
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                                 /* implement me  !! */
00060                                 break;
00061                         }
00062                 }
00063                 else {
00064                         if (m_soundObject) {
00065                                 // not yet
00066                                 //const MT_Transform& trans = GetParent()->GetTransform();
00067                                 //trans.getValue((float*)mat);
00068                                 
00069                                 switch (m_type) {
00070                                 case KX_SOUNDACT_LOOPEND:
00071                                 case KX_SOUNDACT_LOOPSTOP:
00072                                         // todo: set looping on
00073                                         // no break, just fall through
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                                         /* implement me  !! */
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 /* Python functions                                                          */
00114 /* ------------------------------------------------------------------------- */
00115 
00116 /* Integration hooks ------------------------------------------------------- */
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, //&MyPyCompare,
00128         __repr,
00129         0, //&cvalue_as_number,
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} //Sentinel
00148 };
00149 
00150 PyObject* KX_SoundActuator::_getattr(char* attr) {
00151         _getattr_up(SCA_IActuator);
00152 }
00153 
00154 /* 1. getFilename                                                            */
00155 PyObject* KX_SoundActuator::PySetFilename(PyObject* self, 
00156                                                                                   PyObject* args, 
00157                                                                                   PyObject* kwds) {
00158         /* take a sound name, and set that as sound to use */
00159 /*      char *soundName    = NULL;

00160         void *soundPointer = NULL;

00161 
00162         if (!PyArg_ParseTuple(args, "s", &soundName)) {

00163                 return NULL;

00164         }

00165 */      
00166         /* now find the link in Blender */
00167 /*      if (soundName) {

00168                 soundPointer = KX_BlenderAudioDevice::FindSound(soundName);

00169         }

00170         if (soundPointer) m_sound_data = soundPointer;

00171 */
00172         Py_Return;
00173 
00174 }
00175 
00176 /* 2. getFilename                                                            */
00177 PyObject* KX_SoundActuator::PyGetFilename(PyObject* self, 
00178                                                                                   PyObject* args, 
00179                                                                                   PyObject* kwds) {
00180         /* Since we only store references to existing sound data blocks, this    */
00181         /* always succeeds. For now at least... What do we do when it isn't?     */
00182         
00183         char *name = "kip";
00184         /*      char *name = KX_BlenderAudioDevice::FindSoundName(m_sound_data);

00185         if (!name) {

00186                 /* internal error */
00187 /*              Py_Return;

00188         } else {*/
00189                 return PyString_FromString(name);
00190 }
00191 
00192 /* eof */

Generated at Thu Feb 1 13:03:07 2001 for Ketsji Game Engine by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000