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 "../sim.hpp" 00023 #include "SignalAreaComponent.hpp" 00024 #include "SignalManager.hpp" 00025 #include "SignalComponent.hpp" 00026 #include "../schema/SimSchema.hpp" 00027 #include "comp/list/NodeComponentList.hpp" 00028 #include "../react/CollisionAreaComponent.hpp" 00029 #include "../react/CollisionComponent.hpp" 00030 #include "util/error/Log.hpp" 00031 #include "util/bounds/BoundingBox.hpp" 00032 #include "../thing/Actor.hpp" 00033 00034 00035 00036 namespace se_core { 00037 00038 SignalAreaComponent 00039 ::SignalAreaComponent(Composite* owner) 00040 : RootChildComponent(sct_SIGNAL, owner), changed_(0) { 00041 for(int i = 0; i < MAX_SIGNALS; ++i) { 00042 inactiveSignals_[i] = 0; 00043 } 00044 } 00045 00046 00047 SignalAreaComponent 00048 ::~SignalAreaComponent() { 00049 } 00050 00051 00052 void SignalAreaComponent 00053 ::init() { 00054 } 00055 00056 void SignalAreaComponent 00057 ::cleanup() { 00058 changed_ = 0; 00059 for(int i = 0; i < MAX_SIGNALS; ++i) { 00060 inactiveSignals_[i] = 0; 00061 } 00062 } 00063 00064 void SignalAreaComponent 00065 ::setActive(bool state) { 00066 if(state) { 00067 NodeComponent* c = static_cast<NodeComponent*>(CompSchema::activeRoot().component(type_)); 00068 if(c) { 00069 setParent(*c); 00070 } 00071 } 00072 else { 00073 resetParent(); 00074 } 00075 } 00076 00077 00078 void SignalAreaComponent 00079 ::initSignalActive(int id, bool state) { 00080 Assert(id >= 0 && id < MAX_SIGNALS); 00081 if(!state) { 00082 if(inactiveSignals_[id] == 0) { 00083 changed_ = 1L << id; 00084 } 00085 ++inactiveSignals_[id]; 00086 } 00087 Assert(inactiveSignals_[id] >= 0); 00088 } 00089 00090 00091 void SignalAreaComponent 00092 ::setSignalActive(int id, bool state) { 00093 Assert(id >= 0 && id < MAX_SIGNALS); 00094 if(state) { 00095 --inactiveSignals_[id]; 00096 if(inactiveSignals_[id] == 0) { 00097 changed_ = 1 << id; 00098 } 00099 } 00100 else { 00101 if(inactiveSignals_[id] == 0) { 00102 changed_ = 1 << id; 00103 } 00104 ++inactiveSignals_[id]; 00105 } 00106 Assert(inactiveSignals_[id] >= 0); 00107 } 00108 00109 00110 void SignalAreaComponent 00111 ::propagate() { 00112 for(int i = 0; i < MAX_SIGNALS; ++i) { 00113 if(changed_ & (1 << i)) { 00114 propagate(i, inactiveSignals_[i] == 0); 00115 } 00116 } 00117 changed_ = 0; 00118 } 00119 00120 00121 void SignalAreaComponent 00122 ::propagate(int id, bool state) { 00123 NodeComponentList::Iterator it(children_); 00124 while(it.hasNext()) { 00125 SignalComponent& c = static_cast<SignalComponent&>(it.next()); 00126 c.recieve(id, state); 00127 } 00128 } 00129 }
Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:12 2007 by Doxygen version 1.3.9.1.