void BigBall::Move() { if (IsTime()) { m_vel.Set((-10.f + (rand() % 20)) / 10.f, (-10.f + (rand() % 20)) / 10.f); SetTimer(rand() % 100); } }
void Platform2::Move() { if (IsTime()) { m_vel.Set((-10.f + (rand() % 20)) / 10.f, (-10.f + (rand() % 20)) / 10.f); SetTimer(rand() % 100); } }
void Medusa::Move() { if (IsTime()) { //m_acc.Set((-Debug::A + (rand() % int(2 * Debug::A))) / 100.f, (-Debug::A + (rand() % int(2 * Debug::A))) / 100.f); //TODO Move to GetSteering() SetTimer(rand() % int(Debug::B)); } }
static int FormatMatch(const char *str,int format)/*does format of timestamp match format*/ { switch(format) { case TSF_Undefined:return False; case TSF_Seconds:if(False==IsSecond(str))return False;else return True; case TSF_Time:if(False==IsTime(str))return False;else return True; case TSF_DateTime:if(False==IsDateTime(str))return False; else return True; default:return False; } }
Value StdValueFromEsc(const EscValue& v) { if(v.IsNumber()) return v.GetNumber(); if(v.IsArray()) return (WString)v; if(IsTime(v)) return Time(v.GetFieldInt("year"), v.GetFieldInt("month"), v.GetFieldInt("day"), v.GetFieldInt("hour"), v.GetFieldInt("minute"), v.GetFieldInt("second")); if(IsDate(v)) return Date(v.GetFieldInt("year"), v.GetFieldInt("month"), v.GetFieldInt("day")); return Value(); }
Parameter::CurveParameterType Parameter::GetCurveType() { if (IsRadial()) return cptRadial; if (IsTime()) return cptTime; if (IsNonLinear()) return cptPressure; GenAppInternalError("Parameter::GetCurveType"); return cptRadial; }
void PositionMessageSenderSystem::Update( double DeltaTime ) { MessageSenderSystem::Update( DeltaTime ); mActorFrequencyTimerHolder.Update( DeltaTime ); if ( !IsTime() ) { return; } if ( mProgramState.mMode == ProgramState::Server ) { mSendPositions = mActorFrequencyTimerHolder.GetActorIds(); if ( mSendPositions.empty() ) { return; } for ( ActorList_t::iterator it = mScene.GetActors().begin(), e = mScene.GetActors().end(); it != e; ++it ) { Actor& actor = **it; if ( mSendPositions.find( actor.GetId() ) == mSendPositions.end() ) { continue; } std::auto_ptr<PositionMessage> positionMessage( GeneratePositionMessage( actor ) ); if ( positionMessage.get() != NULL ) { mSingleMessageSender.Add( actor.GetGUID(), positionMessage ); } } } else if ( mProgramState.mMode == ProgramState::Client ) { Opt<Actor> player( mScene.GetActor( mProgramState.mControlledActorGUID ) ); if ( player.IsValid() ) { std::auto_ptr<PositionMessage> positionMessage( GeneratePositionMessage( *player ) ); if ( positionMessage.get() != NULL ) { mSingleMessageSender.Add( player->GetGUID(), positionMessage ); } } } }
/* formats: DateTime: yyyy/Mon/dd hh:mm:ss.us Time: hh:mm:ss.us Second: s.us */ static enum TimeStampFormats GetTimeStampFormat(const char *filename) { /*get timestamp format used in file*/ enum TimeStampFormats ret_val = TSF_Undefined; char str[MAXTIMESTAMPLENGTH + 1]; FILE *fp = fopen(filename, FOPEN_READ); if (fp == NULL) { fprintf(stderr, "%s: warning: cannot open %s: %s\n", progname, filename, strerror(errno)); return TSF_Undefined; } if (fgets(str, sizeof(str), fp) != NULL) { if (IsSecond(str)) ret_val = TSF_Seconds; else if (IsTime(str)) ret_val = TSF_Time; else if (IsDateTime(str)) ret_val = TSF_DateTime; } fclose(fp); return ret_val; }
static int IsDateTime(const char *str)/*is timestamp format Date/Time*/ { int a,b; if(False==IsTime(str+12))return False; for(a=0;a<FIRST_LEN;a++) {/*YYYY or DD*/ if(*str<'0'||*str>'9')return False; str++; } if(*str!='/')return False;/* '/' */ str++; for(a=0,b=0;a<12;a++)if(0==strncmp(str,MON[a],3)){b=1;break;}/*MON*/ if(!b)return False; str+=3; if(*str!='/')return False;/* '/' */ str++; for(a=0;a<THIRD_LEN;a++) {/*DD or YYYY*/ if(*str<'0'||*str>'9')return False; str++; } return True; }
double Parameter::GetParValue() const { // sanity checks if (IsCurve()) GenAppInternalError("Parameter::GetParValue() #1"); if (IsRadial()) GenAppInternalError("Parameter::GetParValue() #2"); if (IsTime()) GenAppInternalError("Parameter::GetParValue() #3"); switch (parameterType) { case ptFixed : { return parVal.GetMetricVal(); } case ptVary : { if (varyParVal.varyIndex < 0) return nullReal; return varyParVal.GetVaryVal(); } case ptOpt : { return optParVal.GetParEstimate(); } case ptSample : { int currIndex = sampParVal.GetTrialIndex(); if (currIndex < 0) return nullReal; return sampParVal.GetCurrentValue(currIndex); } } GenAppInternalError("Parameter::GetParValue() #3"); // to satisfy the compiler return nullReal; }
DVT_STATUS VALUE_TM_CLASS::Check (UINT32 flags, BASE_VALUE_CLASS **, LOG_MESSAGE_CLASS *messages, SPECIFIC_CHARACTER_SET_CLASS *) // DESCRIPTION : Checks TM value encoding. // PRECONDITIONS : // POSTCONDITIONS : // EXCEPTIONS : // NOTES : Format: // : A string of charactersof the format hhmmss.frac, where // : hh = hour // : mm = minute // : ss = second // : frac = fractional part of a second. // : // : Some elements of this format are optional, so the // : actual format becomes: // : hh[mm[ss[.frac]]] // : // : For backward compatibility with older versions of the // : Standard, the format hh:mm:ss.frac should also be // : supported. // : // : Some elements of this format are optional, so the // : actual format becomes: // : hh[:mm[:ss[.frac]]] //<<=========================================================================== { int length = valueM.length(); int maxLength; int index; DVT_STATUS result = MSG_OK; bool frac = false; bool range = false; bool time1_old_format = false; bool time2_old_format = false; int time1_index = -1; int time2_index = -1; string time1; string time2; string conv_time1; string conv_time2; string frac1; string frac2; char message[256]; if (length == 0) return (MSG_OK); // check length if (flags & ATTR_FLAG_RANGES_ALLOWED) { maxLength = TM_QR_LENGTH; } else { maxLength = TM_LENGTH; } if (length > maxLength) { sprintf (message, "value length %i exceeds maximum length %i - truncated for value(%s)", length, maxLength, valueM.c_str()); messages->AddMessage (VAL_RULE_D_TM_1, message); length = maxLength; result= MSG_ERROR; } for (index=0 ; index<length ; index++) { if ((valueM[index] >= '0') && (valueM[index] <= '9')) { if (range == false) { // We don't know if we're parsing a range. We do know this is the start time in case of a range. if (frac == false) { time1 += valueM[index]; if (time1_index < 0) { // store the index at which the first time starts time1_index = index; } } else { frac1 += valueM[index]; } } else { // We're parsing a range time. The time to parse now is the end time of the range. if (frac == false) { time2 += valueM[index]; if (time2_index < 0) { // store the index at which the second time starts time2_index = index; } } else { frac2 += valueM[index]; } } } else { switch (valueM[index]) { case ':': if (frac == false) { if (range == false) { if (time1_index < 0) { // ':' is not allowed as a starting character sprintf (message, "colon ':' not allowed at position %d", index); messages->AddMessage (VAL_RULE_D_TM_7, message); return (MSG_ERROR); } time1 += ':'; time1_old_format = true; } else { if (time2_index < 0) { // ':' is not allowed as a starting character sprintf (message, "colon ':' not allowed at position %d", index); messages->AddMessage (VAL_RULE_D_TM_7, message); return (MSG_ERROR); } time2 += ':'; time2_old_format = true; } } else { // ':' is not allowed in a frac sprintf (message, "colon ':' not allowed in fraction at position %d", index); messages->AddMessage (VAL_RULE_D_TM_7, message); return (MSG_ERROR); } break; case '-': if (!(flags & ATTR_FLAG_RANGES_ALLOWED)) { sprintf (message, "time range not allowed"); messages->AddMessage (VAL_RULE_D_TM_3, message); return (MSG_ERROR); } if (range == true) { sprintf (message, "more than one '-' Character found at position %d", index); messages->AddMessage (VAL_RULE_D_TM_8, message); return (MSG_ERROR); } range = true; // fractions are allowed now since we are now parsing the second time frac = false; break; case '.': if (frac == true) { sprintf (message, "more than one '.' Character found at position %d", index); messages->AddMessage (VAL_RULE_D_TM_2, message); return MSG_ERROR; } if ((valueM[index + 1] < '0') || (valueM[index + 1] > '9')) { sprintf (message, "'.' found without an actual fraction at position %d", index); messages->AddMessage (VAL_RULE_D_TM_2, message); return MSG_ERROR; } frac = true; break; case ' ': if ( (index + 1 < length) || // A space char can only occur at the end of the time string. ((index + 1) % 2 != 0)) // A space char may only be used for padding { sprintf (message, "unexpected SPACE character at offset %d", index+1); messages->AddMessage (VAL_RULE_D_TM_2, message); return MSG_ERROR; } break; case 0x00: sprintf (message, "unexpected character [NUL]=0x00 at offset %d", index+1); messages->AddMessage (VAL_RULE_D_TM_2, message); return MSG_ERROR; case 0x0a: // Fall through. case 0x0d: sprintf (message, "unexpected character 0x%02X at offset %d", (int)(valueM[index]), index+1); messages->AddMessage (VAL_RULE_D_TM_2, message); return MSG_ERROR; default: sprintf (message, "unexpected character %c=0x%02X at offset %d", valueM[index], (int)(valueM[index]), index+1); messages->AddMessage (VAL_RULE_D_TM_2, message); return MSG_ERROR; } } } if ((time1_old_format == true) || (time2_old_format == true)) { sprintf (message, "old style time format - 'HH:MM:SS' should not be used"); messages->AddMessage (VAL_RULE_D_TM_6, message); } // convert the times from the old format to the new format. This can be // done even if the times are already in the new format. ConvertOldTime (time1, conv_time1); ConvertOldTime (time2, conv_time2); if (IsTime (conv_time1, time1_index, messages) != MSG_OK) { result = MSG_ERROR; } else { if (frac1.length() > 0) { switch (conv_time1.length()) { case 2: sprintf (message, "A fraction is not allowed when only HH is specified - expected [HH[MM[SS[.FRAC]]]]"); messages->AddMessage (VAL_RULE_D_TM_2, message); result = MSG_ERROR; break; case 4: sprintf (message, "A fraction is not allowed when only HHMM is specified - expected [HH[MM[SS[.FRAC]]]]"); messages->AddMessage (VAL_RULE_D_TM_2, message); result = MSG_ERROR; break; case 6: // only when HHMMSS is correct, a fraction is allowed. if (IsNumeric (frac1, frac1.length()) == false) { sprintf (message, "invalid fraction part"); messages->AddMessage (VAL_RULE_D_TM_2, message); result = MSG_ERROR; } break; } } } if (range == true) { if (conv_time2.length() > 0) { if (IsTime (conv_time2, time2_index, messages) != MSG_OK) { result = MSG_ERROR; } else { if (frac2.length() > 0) { switch (conv_time2.length()) { case 2: sprintf (message, "A fraction is not allowed when only HH is specified - expected [HH[MM[SS[.FRAC]]]]"); messages->AddMessage (VAL_RULE_D_TM_2, message); result = MSG_ERROR; break; case 4: sprintf (message, "A fraction is not allowed when only HHMM is specified - expected [HH[MM[SS[.FRAC]]]]"); messages->AddMessage (VAL_RULE_D_TM_2, message); result = MSG_ERROR; break; case 6: // only when HHMMSS is correct, a fraction is allowed. if (IsNumeric (frac2, frac2.length()) == false) { sprintf (message, "invalid fraction part"); messages->AddMessage (VAL_RULE_D_TM_2, message); result = MSG_ERROR; } break; } } } if (atoi (conv_time1.c_str()) == atoi (conv_time2.c_str())) { if (atoi (frac1.c_str()) == atoi (frac2.c_str())) { sprintf (message, "start time and end time in range are equal"); messages->AddMessage (VAL_RULE_D_TM_A, message); result = MSG_ERROR; } if (atoi (frac1.c_str()) > atoi (frac2.c_str())) { sprintf (message, "start time is later than end time in range"); messages->AddMessage (VAL_RULE_D_TM_A, message); result = MSG_ERROR; } } if (atoi (conv_time1.c_str()) > atoi (conv_time2.c_str())) { // No need to check for frac since we already know that time1 is later than time2 sprintf (message, "start time is later than end time in range"); messages->AddMessage (VAL_RULE_D_TM_A, message); result = MSG_ERROR; } } } return result; }