Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): none yet. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00033 #include "SCA_IActuator.h" 00034 #include <stdio.h> 00035 00036 using namespace std; 00037 00038 SCA_IActuator::SCA_IActuator(SCA_IObject* gameobj, KX_ACTUATOR_TYPE type) : 00039 SCA_ILogicBrick(gameobj), 00040 m_type(type), 00041 m_links(0), 00042 m_posevent(false), 00043 m_negevent(false) 00044 { 00045 // nothing to do 00046 } 00047 00048 bool SCA_IActuator::Update(double curtime, bool frame) 00049 { 00050 if (frame) 00051 return Update(); 00052 00053 return true; 00054 } 00055 00056 bool SCA_IActuator::Update() 00057 { 00058 assert(false && "Actuators should override an Update method."); 00059 return false; 00060 } 00061 00062 void SCA_IActuator::Activate(SG_DList& head) 00063 { 00064 if (QEmpty()) 00065 { 00066 InsertActiveQList(m_gameobj->m_activeActuators); 00067 head.AddBack(&m_gameobj->m_activeActuators); 00068 } 00069 } 00070 00071 // this function is only used to deactivate actuators outside the logic loop 00072 // e.g. when an object is deleted. 00073 void SCA_IActuator::Deactivate() 00074 { 00075 if (QDelink()) 00076 { 00077 // the actuator was in the active list 00078 if (m_gameobj->m_activeActuators.QEmpty()) 00079 // the owner object has no more active actuators, remove it from the global list 00080 m_gameobj->m_activeActuators.Delink(); 00081 } 00082 } 00083 00084 00085 void SCA_IActuator::ProcessReplica() 00086 { 00087 SCA_ILogicBrick::ProcessReplica(); 00088 RemoveAllEvents(); 00089 m_linkedcontrollers.clear(); 00090 } 00091 00092 00093 00094 SCA_IActuator::~SCA_IActuator() 00095 { 00096 RemoveAllEvents(); 00097 } 00098 00099 void SCA_IActuator::DecLink() 00100 { 00101 m_links--; 00102 if (m_links < 0) 00103 { 00104 printf("Warning: actuator %s has negative m_links: %d\n", m_name.Ptr(), m_links); 00105 m_links = 0; 00106 } 00107 } 00108 00109 void SCA_IActuator::LinkToController(SCA_IController* controller) 00110 { 00111 m_linkedcontrollers.push_back(controller); 00112 } 00113 00114 void SCA_IActuator::UnlinkController(SCA_IController* controller) 00115 { 00116 std::vector<class SCA_IController*>::iterator contit; 00117 for (contit = m_linkedcontrollers.begin();!(contit==m_linkedcontrollers.end());++contit) 00118 { 00119 if ((*contit) == controller) 00120 { 00121 *contit = m_linkedcontrollers.back(); 00122 m_linkedcontrollers.pop_back(); 00123 return; 00124 } 00125 } 00126 printf("Missing link from actuator %s:%s to controller %s:%s\n", 00127 m_gameobj->GetName().ReadPtr(), GetName().ReadPtr(), 00128 controller->GetParent()->GetName().ReadPtr(), controller->GetName().ReadPtr()); 00129 } 00130 00131 void SCA_IActuator::UnlinkAllControllers() 00132 { 00133 std::vector<class SCA_IController*>::iterator contit; 00134 for (contit = m_linkedcontrollers.begin();!(contit==m_linkedcontrollers.end());++contit) 00135 { 00136 (*contit)->UnlinkActuator(this); 00137 } 00138 m_linkedcontrollers.clear(); 00139 } 00140