00001 // execution.cpp 00002 // 00003 // Copyright (C) 2001 Chris Laurel <claurel@shatters.net> 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 #include "execution.h" 00011 00012 using namespace std; 00013 00014 00015 Execution::Execution(CommandSequence& cmd, ExecutionEnvironment& _env) : 00016 currentCommand(cmd.begin()), 00017 finalCommand(cmd.end()), 00018 env(_env), 00019 commandTime(-1.0) 00020 { 00021 } 00022 00023 00024 bool Execution::tick(double dt) 00025 { 00026 // ignore the very first call to tick, because on windows dt may include the 00027 // time spent in the "Open File" dialog. Using commandTime < 0 as a flag 00028 // to recognize the first call: 00029 if (commandTime < 0.0) 00030 { 00031 commandTime = 0.0; 00032 return false; 00033 } 00034 00035 while (dt > 0.0 && currentCommand != finalCommand) 00036 { 00037 Command* cmd = *currentCommand; 00038 00039 double timeLeft = cmd->getDuration() - commandTime; 00040 if (dt >= timeLeft) 00041 { 00042 cmd->process(env, cmd->getDuration(), timeLeft); 00043 dt -= timeLeft; 00044 commandTime = 0.0; 00045 currentCommand++; 00046 } 00047 else 00048 { 00049 commandTime += dt; 00050 cmd->process(env, commandTime, dt); 00051 dt = 0.0; 00052 } 00053 } 00054 00055 return currentCommand == finalCommand; 00056 } 00057 00058 00059 void Execution::reset(CommandSequence& cmd) 00060 { 00061 currentCommand = cmd.begin(); 00062 finalCommand = cmd.end(); 00063 commandTime = -1.0; 00064 } 00065 00066
1.4.1