예제 #1
0
    bool NextStep() {
        if(actions_.Count() == 0) return false;
        List<Point>* prevPoints = points_[points_.Count() - 1];

        // Check if the next action should be executed.
        if(currentStep_ == currentAction_->Steps()) {
            // Skip over all connected actions.
            size_t nextPosition = currentPosition_ + 1;
            while(nextPosition < actions_.Count() && actions_[nextPosition]->WithPrevious()) {
                nextPosition++;
            }

            size_t i = nextPosition + 1;
            while((i < actions_.Count()) && actions_[i]->WithPrevious()) {
                actions_[i]->Initialize(*prevPoints);
                i++;
            }

            if(nextPosition < actions_.Count()) {
                // Advance to the next action.
                currentAction_ = actions_[nextPosition];
                currentAction_->Initialize(*prevPoints);
                currentPosition_ = nextPosition;
                currentStep_ = 0;
            }
            else {
                // All actions have been executed.
                return false; 
            }
        }

        // Compute the next state of the shape.
        // The generated points depend directly on the previous ones.
        List<Point>* newPoints = new List<Point>(*prevPoints);
        points_.Add(newPoints);

        // Apply to the points the current action and all actions liked with it.
        currentAction_->Execute(currentStep_, *newPoints);

        for(size_t i = currentPosition_ + 1; i < actions_.Count(); i++) {
            if(actions_[i]->WithPrevious()) {
                actions_[i]->Execute(currentStep_, *newPoints);
            }
            else break;
        }

        currentStep_++;
        return true;
    }
예제 #2
0
    void Play() {
        if(actions_.Count() == 0) return;

        currentAction_ = actions_[0];
        currentPosition_ = 0;
        currentStep_ = 0;

        List<Point> *firstPoints = new List<Point>(shape_->Points());
        points_.Add(firstPoints);

        // Initialize the start action and the ones connected to it.
        currentAction_->Initialize(*firstPoints);

        for(size_t i = 1; i < actions_.Count(); i++) {
            if(actions_[i]->WithPrevious() == false) return;
            actions_[i]->Initialize(*firstPoints);
        }
    }