void Direction::UnserializeFrom(const gd::SerializerElement & element) { SetTimeBetweenFrames(element.GetDoubleAttribute("timeBetweenFrames", 1, "tempsEntre")); SetLoop(element.GetBoolAttribute("looping", false, "boucle")); const gd::SerializerElement & spritesElement = element.GetChild("sprites", 0, "Sprites"); spritesElement.ConsiderAsArrayOf("sprite", "Sprite"); for (unsigned int i = 0; i < spritesElement.GetChildrenCount(); ++i) { const gd::SerializerElement & spriteElement = spritesElement.GetChild(i); Sprite sprite; sprite.SetImageName(spriteElement.GetStringAttribute("image")); OpenPointsSprites(sprite.GetAllNonDefaultPoints(), spriteElement.GetChild("points", 0, "Points")); OpenPoint(sprite.GetOrigin(), spriteElement.GetChild("originPoint" , 0, "PointOrigine")); OpenPoint(sprite.GetCenter(), spriteElement.GetChild("centerPoint" , 0, "PointCentre")); sprite.SetDefaultCenterPoint(spriteElement.GetChild("centerPoint" , 0, "PointCentre").GetBoolAttribute("automatic", true)); if (spriteElement.HasChild("CustomCollisionMask")) sprite.SetCollisionMaskAutomatic(!spriteElement.GetChild("CustomCollisionMask").GetBoolAttribute("custom", false)); else sprite.SetCollisionMaskAutomatic(!spriteElement.GetBoolAttribute("hasCustomCollisionMask", false)); std::vector<Polygon2d> mask; const gd::SerializerElement & collisionMaskElement = spriteElement.GetChild("customCollisionMask", 0, "CustomCollisionMask"); collisionMaskElement.ConsiderAsArrayOf("polygon", "Polygon"); for (unsigned int j = 0; j < collisionMaskElement.GetChildrenCount(); ++j) { Polygon2d polygon; const gd::SerializerElement & polygonElement = collisionMaskElement.GetChild(j); polygonElement.ConsiderAsArrayOf("vertice", "Point"); for (unsigned int k = 0; k < polygonElement.GetChildrenCount(); ++k) { const gd::SerializerElement & verticeElement = polygonElement.GetChild(k); polygon.vertices.push_back(sf::Vector2f(verticeElement.GetDoubleAttribute("x"), verticeElement.GetDoubleAttribute("y"))); } mask.push_back(polygon); } sprite.SetCustomCollisionMask(mask); sprites.push_back(sprite); } };
void OpenPointsSprites(vector < Point > & points, const gd::SerializerElement & element) { element.ConsiderAsArrayOf("point", "Point"); for (unsigned int i = 0; i < element.GetChildrenCount(); ++i) { Point point(""); OpenPoint(point, element.GetChild(i)); points.push_back(point); } }
PROCESS_STATE RoutineD( void ) { typedef enum { POWER_ON_A, WAIT_FOR_SENSOR3, POWER_OFF_A, OPEN_POINT1, OPEN_POINT2, OPEN_POINT3, POWER_ON_B, WAIT_FOR_SENSOR1, WAIT_FOR_TIMER, POWER_OFF_B, CLOSE_POINT1, CLOSE_POINT2, CLOSE_POINT3 } MOVEMENT_STATE; PROCESS_STATE ReturnStatus = In_Progress; static MOVEMENT_STATE MovementState = POWER_ON_A; switch ( MovementState ) { case POWER_ON_A : EnableMotorPower(); if ( TrainMotorHome( 800, 5 ) == Command_Complete ) { MovementState = WAIT_FOR_SENSOR3; } break; case WAIT_FOR_SENSOR3 : if ( TrainPresent( 3 ) == true ) { MovementState = POWER_OFF_A; } break; case POWER_OFF_A : if ( TrainMotorHome( 0, 5 ) == Command_Complete ) { DisableMotorPower(); MovementState = OPEN_POINT1; } break; case OPEN_POINT1 : if ( OpenPoint( 1 ) == Command_Complete ) { MovementState = OPEN_POINT2; } break; case OPEN_POINT2 : if ( OpenPoint( 2 ) == Command_Complete ) { MovementState = OPEN_POINT3; } break; case OPEN_POINT3 : if ( OpenPoint( 3 ) == Command_Complete ) { MovementState = POWER_ON_B; } break; case POWER_ON_B : EnableMotorPower(); if ( TrainMotorAway( 1023, 5 ) == Command_Complete ) { MovementState = WAIT_FOR_SENSOR1; } break; case WAIT_FOR_SENSOR1 : if ( TrainPresent( 1 ) == true ) { MovementState = WAIT_FOR_TIMER; Set_Timer(GENERIC, 0, 6, 0 ); } break; case WAIT_FOR_TIMER : if ( Check_Timer( GENERIC ) == MATURED ) { MovementState = POWER_OFF_B; } break; case POWER_OFF_B : if ( TrainMotorAway( 0, 5 ) == Command_Complete ) { DisableMotorPower(); MovementState = CLOSE_POINT1; } break; case CLOSE_POINT1 : if ( ClosePoint( 1 ) == Command_Complete ) { MovementState = CLOSE_POINT2; } break; case CLOSE_POINT2 : if ( ClosePoint( 2 ) == Command_Complete ) { MovementState = CLOSE_POINT3; } break; case CLOSE_POINT3 : if ( ClosePoint( 3 ) == Command_Complete ) { MovementState = POWER_ON_A; ReturnStatus = Command_Complete; } break; } return ReturnStatus; }