00001 //////////////////////////////////////////////////////////////////////////////// 00002 // Scorched3D (c) 2000-2009 00003 // 00004 // This file is part of Scorched3D. 00005 // 00006 // Scorched3D is free software; you can redistribute it and/or modify 00007 // it under the terms of the GNU General Public License as published by 00008 // the Free Software Foundation; either version 2 of the License, or 00009 // (at your option) any later version. 00010 // 00011 // Scorched3D is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU General Public License 00017 // along with Scorched3D; if not, write to the Free Software 00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 //////////////////////////////////////////////////////////////////////////////// 00020 00021 #include <engine/ScorchedContext.h> 00022 #include <engine/ActionController.h> 00023 #include <actions/CameraPositionAction.h> 00024 00025 CameraPositionAction::CameraPositionAction(FixedVector &showPosition, 00026 fixed showTime, 00027 unsigned int priority) : 00028 ActionReferenced("CameraPositionAction"), 00029 totalTime_(0), showTime_(showTime), 00030 showPosition_(showPosition), showPriority_(priority) 00031 { 00032 00033 } 00034 00035 CameraPositionAction::~CameraPositionAction() 00036 { 00037 if (!context_->getServerMode()) 00038 { 00039 CameraPositionActionRegistry::rmCameraPositionAction(this); 00040 } 00041 } 00042 00043 void CameraPositionAction::init() 00044 { 00045 if (!context_->getServerMode()) 00046 { 00047 CameraPositionActionRegistry::addCameraPositionAction(this); 00048 } 00049 startTime_ = context_->getActionController().getActionTime(); 00050 } 00051 00052 void CameraPositionAction::simulate(fixed frameTime, bool &remove) 00053 { 00054 totalTime_ += frameTime; 00055 if (totalTime_ > showTime_) 00056 { 00057 remove = true; 00058 } 00059 00060 Action::simulate(frameTime, remove); 00061 } 00062 00063 std::set<CameraPositionAction *> CameraPositionActionRegistry::actions_; 00064 CameraPositionAction *CameraPositionActionRegistry::currentAction_ = 0; 00065 00066 void CameraPositionActionRegistry::addCameraPositionAction(CameraPositionAction *action) 00067 { 00068 actions_.insert(action); 00069 } 00070 00071 void CameraPositionActionRegistry::rmCameraPositionAction(CameraPositionAction *action) 00072 { 00073 if (currentAction_ == action) currentAction_ = 0; 00074 actions_.erase(action); 00075 } 00076 00077 CameraPositionAction *CameraPositionActionRegistry::getCurrentAction() 00078 { 00079 // Check if the current action is still active 00080 if (actions_.find(currentAction_) == actions_.end()) 00081 { 00082 // If the current action is not still going get another one 00083 currentAction_ = getCurrentBest(); 00084 } 00085 else 00086 { 00087 // If it is check that it is the best action 00088 CameraPositionAction *bestAction = getCurrentBest(); 00089 if (bestAction) 00090 { 00091 if (bestAction->getShowPriority() > currentAction_->getShowPriority()) 00092 { 00093 currentAction_ = bestAction; 00094 } 00095 } 00096 } 00097 00098 return currentAction_; 00099 } 00100 00101 CameraPositionAction *CameraPositionActionRegistry::getCurrentBest() 00102 { 00103 CameraPositionAction *currentBest = 0; 00104 if (!actions_.empty()) 00105 { 00106 std::set<CameraPositionAction *>::iterator itor; 00107 for (itor = actions_.begin(); 00108 itor != actions_.end(); 00109 itor++) 00110 { 00111 CameraPositionAction *action = (*itor); 00112 00113 // Check that this action is near the beginning 00114 fixed currentTime = action->getScorchedContext()-> 00115 getActionController().getActionTime(); 00116 fixed actionTime = action->getStartTime(); 00117 if (currentTime - actionTime < 1) 00118 { 00119 // Is there an action to beat 00120 if (!currentBest) currentBest = action; 00121 else 00122 { 00123 // Yes, so check if it beats it 00124 if (currentBest->getShowPriority() < action->getShowPriority()) 00125 { 00126 // There is a new current best 00127 currentBest = action; 00128 } 00129 } 00130 } 00131 } 00132 } 00133 return currentBest; 00134 } 00135
1.5.3