Exemplo n.º 1
0
Score::FileError MasterScore::read301(XmlReader& e)
      {
      bool top = true;
      while (e.readNextStartElement()) {
            const QStringRef& tag(e.name());
            if (tag == "programVersion") {
                  setMscoreVersion(e.readElementText());
                  parseVersion(mscoreVersion());
                  }
            else if (tag == "programRevision")
                  setMscoreRevision(e.readIntHex());
            else if (tag == "Score") {
                  MasterScore* score;
                  if (top) {
                        score = this;
                        top   = false;
                        }
                  else {
                        score = new MasterScore();
                        score->setMscVersion(mscVersion());
                        addMovement(score);
                        }
                  if (!score->read(e))
                        return FileError::FILE_BAD_FORMAT;
                  }
            else if (tag == "Revision") {
                  Revision* revision = new Revision;
                  revision->read(e);
                  revisions()->add(revision);
                  }
            }
      return FileError::FILE_NO_ERROR;
      }
void TrainingsController::load() {
    //movements
    std::ifstream confIn(rootPath + CONF_FILE);
    if (confIn.is_open()) {
        std::string name;
        while (std::getline(confIn, name)) {
            Properties prop(rootPath + name + ".txt");
            Movement *movement = new Movement(prop.get("name"), prop.get("desc"), prop.getDouble("trans_x"),
                                          prop.getDouble("trans_y"), prop.getDouble("rotation"), prop.getDouble("compression"));
            addMovement(movement);
        }
    }
    else
        initDefault();
    confIn.close();

    //trainings
    confIn.open(rootPath + TRAININGS_FILE);
    int i = 0;
    if (confIn.is_open()) {
        std::string name;
        while (std::getline(confIn, name)) {
            std::ifstream in(rootPath + name + ".txt");
            std::string mov;
            std::vector<Movement*> vec;
            while (std::getline(in, mov))
                vec.push_back(getMovement(mov));
            in.close();
            trainings.push_back(new TrainingsProcedure(name, vec, i++));
        }
    }
    confIn.close();
}
Exemplo n.º 3
0
//--------------------------------------------------------------
void box2dScene::update(){
    box2d.update();
    
    addMovement();
    // ofRemove(circles, ofxBox2dBaseShape::shouldRemoveOffScreen);
    //     ofRemove(customParticles, ofxBox2dBaseShape::shouldRemoveOffScreen);
    
    box2d.setGravity(gravityH, gravityV);
}
Exemplo n.º 4
0
void InsertSort::insert(int *array, int top, int number) {
    for (int i = 0; i <= top; i++) {
        if (array[i] > number) {
            addComparement();
            for (int j = top + 1; j > i; j--) {
                array[j] = array[j - 1];
                addMovement();
            }
            array[i] = number;
            break;
        }
        addComparement();
    }
}
Exemplo n.º 5
0
int QuickSort::partition(int *array, int bottom, int top) {
    //采取随机数为标杆的策略
    int randomnum = creatnum(bottom, top);
    int temp = array[randomnum];
    array[randomnum] = array[top];
    array[top] = temp;
    addMovement();

    int middle = array[top];

    int i = bottom;
    int j = bottom - 1;

    for (; i < top; i++) {
        if (array[i] <= middle) {
            j++;
            addComparement();
            if (i != j) {
                temp = array[i];
                array[i] = array[j];
                array[j] = temp;
                addMovement();
            }
        }
        addComparement();
    }

    temp = array[j + 1];
    array[j + 1] = array[top];
    array[top] = temp;
    addMovement();


    return (j + 1);

}
void JacobsLadder::addMovement(MovementType type, int velocity, byte angle, LadderCallback onStart, LadderCallback onEnd) {
  if(queue.count() > 4) {
    return;
  }
  
  if (!hasPriority(type)) {
    return;
  }
  byte startingAngle = getFinalDestinationAngle();
  byte destinationAngle = 0;
  byte buzzAngle = 0;
  int updateDelay = 0;
  bool needsResetting = false;
  bool shouldSendOnStart = true;
  bool shouldSendOnEnd = true;
  
  switch(type) {
    case Cascade:
      destinationAngle = 0;
      if (startingAngle < 90) {
        destinationAngle = 180;
      }
      updateDelay = calculateUpdateDelay(velocity, destinationAngle, startingAngle);
      break;

    case Buzz:
      addMovement(Reset, velocity, 0, NULL, NULL);
      buzzAngle = 30;
      if (angle != 0) {
         buzzAngle = angle;
      }
      destinationAngle = buzzAngle;
      if (startingAngle > 90) {
        destinationAngle = 180 - buzzAngle;
      }
      updateDelay = calculateUpdateDelay(velocity, destinationAngle, startingAngle);
      needsResetting = true;
      shouldSendOnEnd = false;
      break;

    case Reset:
      if (startingAngle != 0 || startingAngle != 180) {
        destinationAngle = 0;
        if (startingAngle > 90) {
          destinationAngle = 180;
        }
        updateDelay = calculateUpdateDelay(velocity, destinationAngle, startingAngle);
      }
      break;

    case Timeout:
      destinationAngle = startingAngle;
      updateDelay = velocity;
      break;
  }

  struct Movement movement;
  movement.type = type;
  movement.destinationAngle = destinationAngle;
  movement.updateDelay = updateDelay;
  movement.ratio = (float) movement.updateDelay / (int) (abs(movement.destinationAngle - startingAngle) != 0 ? abs(movement.destinationAngle - startingAngle) : 1);
  if (shouldSendOnStart) {
    movement.onStart = onStart;
  } else {
    movement.onStart = NULL;
  }
  if (shouldSendOnEnd) {
    movement.onEnd = onEnd;
  } else {
    movement.onEnd = NULL;
  }
  queue.push(movement);
  if (movement.type != Timeout) addMovement(Timeout, 10, 0, NULL, NULL);
  if (needsResetting) {
    addMovement(Reset, velocity, 0, NULL, onEnd);
    addMovement(Timeout, 10, 0, NULL, NULL);
  }
}
void JacobsLadder::addMovement(MovementType type, int velocity, LadderCallback onStart, LadderCallback onEnd) {
  addMovement(type, velocity, 0, onStart, onEnd);
}
void TrainingsController::initDefault() {
    addMovement(new Movement("Rest Position", "", 0, 0, 0, 0));
    addMovement(new Movement("Wrist Flexion", "", 0, 1, 0, 0));
    addMovement(new Movement("Wrist Extension", "", 0, -1, 0, 0));
    addMovement(new Movement("Radial Deviation (r)", "Right hand", -1, 0, 0, 0));
    addMovement(new Movement("Ulnar Deviation (r)", "Right hand", 1, 0, 0, 0));
    addMovement(new Movement("Forarm Pronation (r)", "Right hand", 0, 0, -1, 0));
    addMovement(new Movement("Forarm Supination (r)", "Right hand", 0, 0, 1, 0));
    addMovement(new Movement("Radial Deviation (l)", "Left hand", 1, 0, 0, 0));
    addMovement(new Movement("Ulnar Deviation (l)", "Left hand", -1, 0, 0, 0));
    addMovement(new Movement("Forarm Pronation (l)", "Left hand", 0, 0, 1, 0));
    addMovement(new Movement("Forarm Supination (l)", "Left hand", 0, 0, -1, 0));
    addMovement(new Movement("Hand Close", "", 0, 0, 0, -1));
    addMovement(new Movement("Hand Open", "", 0, 0, 0, 1));
    store();
}
Exemplo n.º 9
0
void VelocityTracker::addMovement(const MotionEvent* event) {
    int32_t actionMasked = event->getActionMasked();

    switch (actionMasked) {
    case AMOTION_EVENT_ACTION_DOWN:
    case AMOTION_EVENT_ACTION_HOVER_ENTER:
        // Clear all pointers on down before adding the new movement.
        clear();
        break;
    case AMOTION_EVENT_ACTION_POINTER_DOWN: {
        // Start a new movement trace for a pointer that just went down.
        // We do this on down instead of on up because the client may want to query the
        // final velocity for a pointer that just went up.
        BitSet32 downIdBits;
        downIdBits.markBit(event->getPointerId(event->getActionIndex()));
        clearPointers(downIdBits);
        break;
    }
    case AMOTION_EVENT_ACTION_MOVE:
    case AMOTION_EVENT_ACTION_HOVER_MOVE:
        break;
    default:
        // Ignore all other actions because they do not convey any new information about
        // pointer movement.  We also want to preserve the last known velocity of the pointers.
        // Note that ACTION_UP and ACTION_POINTER_UP always report the last known position
        // of the pointers that went up.  ACTION_POINTER_UP does include the new position of
        // pointers that remained down but we will also receive an ACTION_MOVE with this
        // information if any of them actually moved.  Since we don't know how many pointers
        // will be going up at once it makes sense to just wait for the following ACTION_MOVE
        // before adding the movement.
        return;
    }

    size_t pointerCount = event->getPointerCount();
    if (pointerCount > MAX_POINTERS) {
        pointerCount = MAX_POINTERS;
    }

    BitSet32 idBits;
    for (size_t i = 0; i < pointerCount; i++) {
        idBits.markBit(event->getPointerId(i));
    }

    uint32_t pointerIndex[MAX_POINTERS];
    for (size_t i = 0; i < pointerCount; i++) {
        pointerIndex[i] = idBits.getIndexOfBit(event->getPointerId(i));
    }

    nsecs_t eventTime;
    Position positions[pointerCount];

    size_t historySize = event->getHistorySize();
    for (size_t h = 0; h < historySize; h++) {
        eventTime = event->getHistoricalEventTime(h);
        for (size_t i = 0; i < pointerCount; i++) {
            uint32_t index = pointerIndex[i];
            positions[index].x = event->getHistoricalX(i, h);
            positions[index].y = event->getHistoricalY(i, h);
        }
        addMovement(eventTime, idBits, positions);
    }

    eventTime = event->getEventTime();
    for (size_t i = 0; i < pointerCount; i++) {
        uint32_t index = pointerIndex[i];
        positions[index].x = event->getX(i);
        positions[index].y = event->getY(i);
    }
    addMovement(eventTime, idBits, positions);
}
Exemplo n.º 10
0
void ArmyRole::setMovements()
{
	if (!gp) return;
	if(gp->vMovements.size()>0) return;
	//char aFile_run[]="run_test6_1.amn\0";//"walkman6.amn\0";

	char aFile1[]="enemy_run2_1.amn\0";//"jump_forward1_1.amn\0";//"jump_test5_1.amn\0";//"walkManNew1.amn\0";
	char aFile2[]="hit_hand_leg1.amn\0";//"hit_test4.amn\0";//"jump_hide2.amn\0";//"jump_test5_2.amn\0";
	char aFile3[]="behitted5_1.amn\0";
	char aFile4[]="hit_hand5_1.amn\0";
	char aFile5[]="falldownup1.amn\0";//"falldown1_1.amn\0";

	char aFile6[]="getup1_1.amn\0";

	//addMovement( ID_RUN, aFile_run);

	addMovement( ID_RUN2, aFile1,0, 0);

	int keyLen=2;
	int keyFrames[]={0,gp->vMovements.back()->getAnimation()->frameNum};

	for(int i=0; i<keyLen;i++)
	{
		KeyFrame *pKF=new KeyFrame();
		pKF->setKeyFrameNum(keyFrames[i]);
		gp->vMovements.back()->getAnimation()->addKeyFrame(pKF);
	}
	//KeyFrame *pKF=new KeyFrame();
	//pKF->setKeyFrameNum(gp->vMovements.back()->getAnimation()->frameNum);
	//gp->vMovements.back()->getAnimation()->addKeyFrame(pKF);

	int infoLen=1;
	int info0[]={
			45,Frame::TYPE_HIT1,
	};

	addMovement( ID_HIT2, aFile2, infoLen, info0);

	addMovement( ID_BEHIT1, aFile3,0, 0);

	keyFrames[1]=gp->vMovements.back()->getAnimation()->frameNum;

	for(int i=0; i<keyLen;i++)
	{
		KeyFrame *pKF=new KeyFrame();
		pKF->setKeyFrameNum(keyFrames[i]);
		gp->vMovements.back()->getAnimation()->addKeyFrame(pKF);
	}

	infoLen=4;
	int info[]={
			9,Frame::TYPE_HIT1,
			24,Frame::TYPE_HIT1,
			38,Frame::TYPE_HIT1,
			53,Frame::TYPE_HIT1
	};

	addMovement( ID_HIT4, aFile4,infoLen, info);

	addMovement( ID_FALLDOWN1, aFile5, 0, 0);
	keyFrames[1]=gp->vMovements.back()->getAnimation()->frameNum;

	for(int i=0; i<keyLen;i++)
	{
		KeyFrame *pKF=new KeyFrame();
		pKF->setKeyFrameNum(keyFrames[i]);
		gp->vMovements.back()->getAnimation()->addKeyFrame(pKF);
	}

	delete[] gp->vp_;
	gp->vp_=0;

}