00001 /* 00002 SagaEngine library 00003 Copyright (c) 2002-2006 Skalden Studio AS 00004 00005 This software is provided 'as-is', without any express or implied 00006 warranty. In no event will the authors be held liable for any 00007 damages arising from the use of this software. 00008 00009 Permission is granted to distribute the library under the terms of the 00010 Q Public License version 1.0. Be sure to read and understand the license 00011 before using the library. It should be included here, or you may read it 00012 at http://www.trolltech.com/products/qt/licenses/licensing/qpl 00013 00014 The original version of this library can be located at: 00015 http://www.sagaengine.com/ 00016 00017 Rune Myrland 00018 rune@skalden.com 00019 */ 00020 00021 00022 #include "SignalComponent.hpp" 00023 #include "SignalAreaComponent.hpp" 00024 #include "../SimEngine.hpp" 00025 #include "../action/all.hpp" 00026 #include "../thing/Actor.hpp" 00027 #include "../schema/SimSchema.hpp" 00028 #include "util/type/String.hpp" 00029 #include "util/error/Log.hpp" 00030 00031 00032 namespace se_core { 00033 SignalComponent 00034 ::SignalComponent(Composite* owner, const ComponentFactory* factory) 00035 : AreaChildComponent(sct_SIGNAL, owner), sendState_(false), sendId_(-1), sentWhen_(0), recieveMask_(0) 00036 , signal_(0) { 00037 } 00038 00039 00040 SignalComponent 00041 ::~SignalComponent() { 00042 cleanup(); 00043 } 00044 00045 00046 void SignalComponent 00047 ::cleanup() { 00048 signal_ = 0; 00049 sendId_ = -1; 00050 recieveMask_ = 0; 00051 } 00052 00053 void SignalComponent 00054 ::setDead() { 00055 if(sendId_ >= 0) 00056 send(true); 00057 } 00058 00059 bool SignalComponent 00060 ::send(bool state) { 00061 sentWhen_ = SimSchema::simEngine.when(); 00062 if(sendState_ == state) 00063 return false; 00064 sendState_ = state; 00065 00066 if(parent()) { 00067 SignalAreaComponent* areaSignal = SignalAreaComponent::get(*parent()); 00068 areaSignal->setSignalActive(sendId_, sendState_); 00069 } 00070 return true; 00071 } 00072 00073 long SignalComponent 00074 ::sentAge() const { 00075 return (SimSchema::simEngine.when() - sentWhen_); 00076 } 00077 00078 void SignalComponent 00079 ::recieve(int id, bool state) { 00080 if(signal_ && (recieveMask_ & (1L << id)) != 0) { 00081 signal_->recieve(*this, id, state); 00082 } 00083 } 00084 00085 00086 void SignalComponent 00087 ::zoneChanged(int zoneType, Composite* newArea, Composite* oldArea) { 00088 if(zoneType != st_AREA) 00089 return; 00090 00091 if(oldArea && !sendState_ && sendId_ >= 0) { 00092 SignalAreaComponent::Ptr oAreaSignal(*oldArea); 00093 oAreaSignal->setSignalActive(sendId_, sendState_); 00094 } 00095 if(newArea && !sendState_ && sendId_ >= 0) { 00096 SignalAreaComponent::Ptr nAreaSignal(*newArea); 00097 nAreaSignal->setSignalActive(sendId_, sendState_); 00098 } 00099 00100 if(newArea) { 00101 NodeComponent* n = static_cast<NodeComponent*>(newArea->component(type())); 00102 setParent(*n); 00103 } 00104 else { 00105 resetParent(); 00106 } 00107 } 00108 00109 }
Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:12 2007 by Doxygen version 1.3.9.1.