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 #ifndef ActionComponent_hpp 00023 #define ActionComponent_hpp 00024 00025 #include "sim_action.hpp" 00026 #include "comp/Component.hpp" 00027 #include "comp/Composite.hpp" 00028 #include "../sim.hpp" 00029 #include "Action.hpp" 00030 #include "ActionQueue.hpp" 00031 #include "ActionAndParameter.hpp" 00032 #include "ActionFeed.hpp" 00033 00034 namespace se_core { 00035 00041 class _SeCoreExport ActionComponent : public Component { 00042 public: 00043 typedef ComponentPtr<ActionComponent, sct_ACTION> Ptr; 00044 00047 ActionComponent(Composite* owner); 00048 00050 ~ActionComponent(); 00051 00058 void planAction(short channel, const Action& action, const Parameter* parameter = 0) const; 00059 void planAction(short channel, const ActionAndParameter& action) const; 00060 void planActionIfNone(short channel, const ActionAndParameter& action) const; 00061 00068 void clearPlannedAction(short channel) const; 00069 00075 void disrupt(); 00076 00079 void resume(); 00080 00086 bool disrupt(short channel); 00087 00090 void unpause(short channel); 00091 00098 void scheduleForDestruction(); 00099 00100 void resetActionFeed() { 00101 feed_ = 0; 00102 } 00103 00104 enum { fb_UNDEFINED, fb_SPEECH_FINISHED, fb_USER_DEFINED }; 00105 void castFeedbackEvent(int type); 00106 void setActionFeed(ActionFeed* feed); 00107 00108 void setActive(bool state); 00109 void setScriptActive(bool state); 00110 00111 protected: 00112 friend class ActionQueue; 00113 00114 void cleanup(); 00115 00120 inline void perform(long when, short channel); 00121 00132 inline void scheduleNextAction(long when, short channel); 00133 00138 unsigned short actionSchedule(short channel) { return presentActionScheduledComplete_[channel]; } 00139 00140 // Helper function for planAction and scheduleNextAction(long when, short channel); 00141 void continueAction(long when, short channel); 00142 void scheduleNextAction(short channel); 00143 00146 void nextScriptAction(short channel); 00147 00148 protected: 00149 mutable ActionAndParameter presentAction_[CHANNEL_COUNT]; 00150 mutable ActionAndParameter plannedAction_[CHANNEL_COUNT]; 00151 00152 mutable unsigned short presentActionScheduledComplete_[CHANNEL_COUNT]; 00153 00154 00155 ActionFeed* feed_; 00156 00157 protected: 00158 }; 00159 00160 00161 inline void ActionComponent 00162 ::perform(long when, short channel) { 00163 const Action* a = presentAction_[channel].action(); 00164 Parameter& p = presentAction_[channel].parameter(); 00165 a->perform(when, *this, p); 00166 } 00167 00168 00169 inline void ActionComponent 00170 ::scheduleNextAction(long when, short channel) { 00171 if(!isActive() || isDead()) { 00172 presentAction_[ channel ].resetAction(); 00173 return; 00174 } 00175 00176 ActionAndParameter& aap = presentAction_[channel]; 00177 if(aap.isDisrupted()) { 00178 aap.resetAction(); 00179 aap.setDisrupted(false); 00180 return; 00181 } 00182 00183 if(aap.hasAction() && aap.action()->isContinuing(*this, aap.parameter())) { 00184 continueAction(when, channel); 00185 return; 00186 } 00187 00188 if(!plannedAction_[channel].hasAction()) { 00189 nextScriptAction(channel); 00190 } 00191 00192 // No action planned? 00193 if(aap.hasAction() && !plannedAction_[channel].hasAction()) { 00194 // Is present action repeating (until another is planned)? 00195 //ActionAndParameter& aap = presentAction_[channel]; 00196 if(aap.action()->isRepeating(when, *this, aap.parameter())) { 00197 // If, yeah - plan to do present action again 00198 plannedAction_[channel] = presentAction_[channel]; 00199 } 00200 else { 00201 // Or not, present action is complete 00202 presentAction_[channel].resetAction(); 00203 } 00204 } 00205 00206 // Still no action planned? Then we are finished 00207 if(!plannedAction_[channel].hasAction()) { 00208 return; 00209 } 00210 00211 // Put planned action into action queue 00212 scheduleNextAction(channel); 00213 } 00214 00215 } 00216 00217 #endif
Home Page | SagaEngine trunk (updated nightly) reference generated Sun Dec 2 20:06:11 2007 by Doxygen version 1.3.9.1.