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