void plPageInfo::write(hsStream* S) { if (S->getVer().isUniversal()) { S->writeShort(-1); fLocation.write(S); S->writeSafeStr(fAge); S->writeSafeStr(fPage); S->writeInt(fFlags); } else if (S->getVer().isEoa()) { S->writeShort(6); S->writeShort(fClassList.size()); for (size_t i=0; i<fClassList.size(); i++) { S->writeShort(pdUnifiedTypeMap::MappedToPlasma(fClassList[i], S->getVer())); S->writeShort(pdUnifiedTypeMap::ClassVersion(fClassList[i], S->getVer())); } fLocation.write(S); S->writeSafeStr(getAge()); S->writeSafeStr(getPage()); } else if (S->getVer().isHexIsle()) { S->writeShort(9); S->writeShort(fClassList.size()); for (size_t i=0; i<fClassList.size(); i++) { S->writeShort(pdUnifiedTypeMap::MappedToPlasma(fClassList[i], S->getVer())); S->writeShort(pdUnifiedTypeMap::ClassVersion(fClassList[i], S->getVer())); } fLocation.write(S); S->writeSafeStr(getAge()); S->writeSafeStr(getPage()); } else if (S->getVer().isMoul()) { S->writeInt(6); fLocation.write(S); S->writeSafeStr(getAge()); S->writeSafeStr(getPage()); S->writeShort(70); } else { S->writeInt(5); fLocation.write(S); S->writeSafeStr(getAge()); S->writeSafeStr(getChapter()); S->writeSafeStr(getPage()); S->writeShort(63); S->writeShort(S->getVer().revMinor()); S->writeInt(fReleaseVersion); S->writeInt(fFlags); } S->writeInt(fChecksum); S->writeInt(fDataStart); S->writeInt(fIdxStart); if (S->getVer().isMoul()) { S->writeShort(fClassList.size()); for (size_t i=0; i<fClassList.size(); i++) { S->writeShort(pdUnifiedTypeMap::MappedToPlasma(fClassList[i], S->getVer())); S->writeShort(pdUnifiedTypeMap::ClassVersion(fClassList[i], S->getVer())); } } }
void MovingDots::updateDots() { // // Update positions // const GLint numValidDots = std::min(previousNumDots, currentNumDots); const GLfloat dt = GLfloat(currentTime - previousTime) / 1.0e6f; const GLfloat dr = dt * previousSpeed / previousFieldRadius; for (GLint i = 0; i < numValidDots; i++) { GLfloat &age = getAge(i); age += dt; if ((age <= previousLifetime) || (previousLifetime == 0.0f)) { advanceDot(i, dt, dr); } else { replaceDot(i, newDirection(previousCoherence), 0.0f); } } // // Update directions // if (currentCoherence != previousCoherence) { for (GLint i = 0; i < numValidDots; i++) { getDirection(i) = newDirection(currentCoherence); } } // // Update lifetimes // if (currentLifetime != previousLifetime) { for (GLint i = 0; i < numValidDots; i++) { getAge(i) = newAge(currentLifetime); } } // // Add/remove dots // if (currentNumDots != previousNumDots) { dotPositions.resize(currentNumDots * componentsPerDot); dotDirections.resize(currentNumDots); dotAges.resize(currentNumDots); for (GLint i = previousNumDots; i < currentNumDots; i++) { replaceDot(i, newDirection(currentCoherence), newAge(currentLifetime)); } } }
void Plante::actualiser (sf::Time deltaT ) { m_ageBack = getAge(); m_age += deltaT.asSeconds(); for (auto racine : m_racines ) racine->pousser(); // chaque 1 secondes if ( m_ageBack == getAge() ) return; creerNouvelleRacine (); }
QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine) const { QScriptValue properties = engine->newObject(); if (_idSet) { COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(id, _id.toString()); COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(isKnownID, (_id != UNKNOWN_ENTITY_ID)); } else { COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(isKnownID, false); } COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(type, EntityTypes::getEntityTypeName(_type)); COPY_PROPERTY_TO_QSCRIPTVALUE_VEC3(position); COPY_PROPERTY_TO_QSCRIPTVALUE_VEC3(dimensions); COPY_PROPERTY_TO_QSCRIPTVALUE_VEC3(naturalDimensions); // gettable, but not settable COPY_PROPERTY_TO_QSCRIPTVALUE_QUAT(rotation); COPY_PROPERTY_TO_QSCRIPTVALUE_VEC3(velocity); COPY_PROPERTY_TO_QSCRIPTVALUE_VEC3(gravity); COPY_PROPERTY_TO_QSCRIPTVALUE(damping); COPY_PROPERTY_TO_QSCRIPTVALUE(lifetime); COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(age, getAge()); // gettable, but not settable COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(ageAsText, formatSecondsElapsed(getAge())); // gettable, but not settable COPY_PROPERTY_TO_QSCRIPTVALUE(script); COPY_PROPERTY_TO_QSCRIPTVALUE_VEC3(registrationPoint); COPY_PROPERTY_TO_QSCRIPTVALUE_VEC3(angularVelocity); COPY_PROPERTY_TO_QSCRIPTVALUE(angularDamping); COPY_PROPERTY_TO_QSCRIPTVALUE(visible); COPY_PROPERTY_TO_QSCRIPTVALUE_COLOR(color); COPY_PROPERTY_TO_QSCRIPTVALUE(modelURL); COPY_PROPERTY_TO_QSCRIPTVALUE(animationURL); COPY_PROPERTY_TO_QSCRIPTVALUE(animationIsPlaying); COPY_PROPERTY_TO_QSCRIPTVALUE(animationFrameIndex); COPY_PROPERTY_TO_QSCRIPTVALUE(animationFPS); COPY_PROPERTY_TO_QSCRIPTVALUE(glowLevel); // Sitting properties support QScriptValue sittingPoints = engine->newObject(); for (int i = 0; i < _sittingPoints.size(); ++i) { QScriptValue sittingPoint = engine->newObject(); sittingPoint.setProperty("name", _sittingPoints[i].name); sittingPoint.setProperty("position", vec3toScriptValue(engine, _sittingPoints[i].position)); sittingPoint.setProperty("rotation", quatToScriptValue(engine, _sittingPoints[i].rotation)); sittingPoints.setProperty(i, sittingPoint); } sittingPoints.setProperty("length", _sittingPoints.size()); COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(sittingPoints, sittingPoints); // gettable, but not settable return properties; }
uint32_t NativeExeSymbol::getAge() const { auto IS = File.getPDBInfoStream(); if (IS) return IS->getAge(); consumeError(IS.takeError()); return 0; }
std::string VacuumEnvironment::outputToJson() { Json::Value outputRoot; std::string result; //general environment info outputRoot["Environment"]["age"] = (int) getAge(); outputRoot["Environment"]["size"]["x"] = state->getWidth(); outputRoot["Environment"]["size"]["y"] = state->getHeight(); //handling all entity info in the environment outputRoot["Environment"]["entities"] = Json::arrayValue; for (int row = 0; row < this->state->getHeight(); row++) { for (int col = 0; col < state->getWidth(); col++) { TileLocation location(col, row); std::vector<Entity *> onTile = state->getEntitiesAt(&location); for (auto current : onTile) { Json::Value currentEntity; //current entity on a tile we're making info for currentEntity["type"] = current->getType(); currentEntity["id"] = current->getId(); currentEntity["location"]["x"] = col; currentEntity["location"]["y"] = row; outputRoot["Environment"]["entities"].append(currentEntity); } } } outputRoot["debug"]["performance_measure"] = getPerformanceMeasure(); result = outputRoot.toStyledString(); return result; }
void Sensor::printValues(void) { Serial.print(F("Sensor: ")); if (getName().length() > 0) { Serial.print(getName()); } Serial.println(""); for (int i = 0; i < getSensorValueCount(); i++) { if (value[i].enabled) { Serial.print(F(" Val[")); Serial.print(i); Serial.print(F(",")); Serial.print(value[i].vname); Serial.print(F("]=")); Serial.print(getValue(i)); Serial.print(F(", Age=")); Serial.println(getAge(i)); Serial.print(F(" Raw[")); Serial.print(i); Serial.print(F(",")); Serial.print(value[i].vname); Serial.print(F("]=")); Serial.print(getRawValue(i)); Serial.print(F(", Age=")); Serial.println(getRawAge(i)); } } Serial.println(""); }
int getAge(int n,int m) { if (n == 1) { return 10; }else{ return getAge(n - 1,m) + m; } }
jstring Java_io_koz_targetApp1_targetApp1_doThings( JNIEnv* env, jobject thiz ) { int r = arc4random() % 10000; LOGI("[+] John Smith is %d years old.\n", getAge()); LOGI("[+] The totally reliable random seed is: %d\n\n", r); return 0; }
int main(int argc, const char * argv[]) { //第一个人10岁,第n个你前面大m岁,问第n个对少岁 //p(1) = 10 //p(2) = p(1) + 2 //p(n) = p(n-1) + 2 int n = 4; int m = 2; int result = getAge(n, m); printf("result = %i",result); return 0; }
void MovingDots::replaceDot(GLint i, GLfloat direction, GLfloat age) { GLfloat &x = getX(i); GLfloat &y = getY(i); do { x = rand(-1.0f, 1.0f); y = rand(-1.0f, 1.0f); } while (x*x + y*y > 1.0f); getDirection(i) = direction; getAge(i) = age; }
void MovingDots::advanceDot(GLint i, GLfloat dt, GLfloat dr) { GLfloat &x = getX(i); GLfloat &y = getY(i); GLfloat &theta = getDirection(i); x += dr * std::cos(theta); y += dr * std::sin(theta); if (x*x + y*y > 1.0f) { theta = newDirection(previousCoherence); GLfloat y1 = rand(-1.0f, 1.0f); GLfloat x1 = -std::sqrt(1.0f - y1*y1) + rand(0.0f, dr); x = x1*std::cos(theta) - y1*std::sin(theta); y = x1*std::sin(theta) + y1*std::cos(theta); getAge(i) = newAge(previousLifetime); } }
int main(int argc, string argv[]){ if (argc != 2 || atoi(argv[1]) <= 0) { printf("My programm doesn't work with dummies\n"); return 1; } else { int numDolph = atoi(argv[1]); int* ageDolph[numDolph]; int maxAge = 0; for (int i = 0; i < numDolph; i++){ ageDolph[i] = getAge(); if (*ageDolph[i] > maxAge){ maxAge = *ageDolph[i]; } } printf("Max dolphin's age is %d\n", maxAge); } }
/////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// // // // Retrieve the age in years as a double // // /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// double dataHandlerStringAS::getDouble(const std::uint32_t index) const { PUNTOEXE_FUNCTION_START(L"dataHandlerStringAS::getDouble"); tAgeUnit ageUnit; double age = (double)getAge(index, &ageUnit); if(ageUnit == days) { return age / (double)365; } if(ageUnit == weeks) { return age / 52.14; } if(ageUnit == months) { return age / (double)12; } return age; PUNTOEXE_FUNCTION_END(); }
int main(int argc, string argv[]) { //make sure there is only one comand line argument to signifiy # of dolphins if (argc != 2) { return 1; } //string argv to int through atoi int dolphins = atoi(argv[1]); //check to be sure it is > 0 if (dolphins <= 0) { printf ("enter a positive dolphin amount, bitch.\n"); return 2; } //create array of size of the arg int* dolphin_ages [dolphins]; //for each dolphin we call getAge for (int i = 0; i < dolphins; i++) { dolphin_ages[i] = getAge(); } //create oldest variable int oldest = 0; //search for oldest dolphin for (int i = 0; i < dolphins; i++) { if (*dolphin_ages[i] > oldest) { oldest = *dolphin_ages[i]; } } //print out the age of the oldest dolphin printf("the oldest dolphin is %i years old... whoop de shit.\n", oldest); }
bool ofAgingMesh::isAlive() { return getAge() < maxAgeInSeconds; }
int main(){ student_t *head, *newStudent,*temp; int age,major; float gpa; char * name, *name1, cr; char *msg; int i; int answer,data; head = NULL; printf("You are now entering the student zone!\n"); answer = menu(); while(answer != 7){ switch (answer) { case 1: printf("enter age:\n"); scanf("%d%c",&age,&cr); printf("enter gpa:\n"); scanf("%f%c",&gpa,&cr); printf("enter major:\n"); scanf("%d%c",&major,&cr); printf("enter name:\n"); name = getline(); //printf("length: %d\n",strlen(name)); newStudent = createStudent(age, name,major,gpa); break; case 2: insertStudent(&head,newStudent); break; case 3: printf("enter student name to delete\n"); name1 = getline(); deleteStudent(&head,name1); free(name1); break; case 4: printf("enter student name to investigate\n"); name1 = getline(); data = dataMenu(); switch (data) { case 1: temp = findStudent(head, name1); if(temp == NULL){ printf("Student %s not found \n",name1); break; } age = getAge( temp); printf("The age of %s, is %d\n",name1,age); break; case 2: temp = findStudent(head, name1); if(temp == NULL){ printf("Student %s not found \n",name1); break; } gpa = getGpa( temp); printf("The gpa of %s, is %f\n",name1,gpa); break; case 3: temp = findStudent(head, name1); if(temp == NULL){ printf("Student %s not found \n",name1); break; } major = getMajor( temp); printf("The gpa of %s, is %d\n",name1,major); break; default: break; } break; case 5: temp = head; while(temp != NULL){ msg = toString( temp); printf("%s\n",msg); temp = temp->link; } break; case 6: insertStudentRear(&head,newStudent); break; default: break; } answer = menu(); } printf("BYE\n"); return(0); }
void main() { printf("your age is %i\n", getAge()); printf("hello %s\n", getName()); }
bool EntityItem::lifetimeHasExpired() const { return isMortal() && (getAge() > getLifetime()); }
void EntityItem::update(const quint64& updateTime) { bool wantDebug = false; if (_lastUpdated == 0) { _lastUpdated = updateTime; } float timeElapsed = (float)(updateTime - _lastUpdated) / (float)(USECS_PER_SECOND); if (wantDebug) { qDebug() << "********** EntityItem::update()"; qDebug() << " entity ID=" << getEntityItemID(); qDebug() << " updateTime=" << updateTime; qDebug() << " _lastUpdated=" << _lastUpdated; qDebug() << " timeElapsed=" << timeElapsed; qDebug() << " hasVelocity=" << hasVelocity(); qDebug() << " hasGravity=" << hasGravity(); qDebug() << " isRestingOnSurface=" << isRestingOnSurface(); qDebug() << " hasAngularVelocity=" << hasAngularVelocity(); qDebug() << " getAngularVelocity=" << getAngularVelocity(); qDebug() << " isMortal=" << isMortal(); qDebug() << " getAge()=" << getAge(); qDebug() << " getLifetime()=" << getLifetime(); if (hasVelocity() || (hasGravity() && !isRestingOnSurface())) { qDebug() << " MOVING...="; qDebug() << " hasVelocity=" << hasVelocity(); qDebug() << " hasGravity=" << hasGravity(); qDebug() << " isRestingOnSurface=" << isRestingOnSurface(); qDebug() << " hasAngularVelocity=" << hasAngularVelocity(); qDebug() << " getAngularVelocity=" << getAngularVelocity(); } if (hasAngularVelocity()) { qDebug() << " CHANGING...="; qDebug() << " hasAngularVelocity=" << hasAngularVelocity(); qDebug() << " getAngularVelocity=" << getAngularVelocity(); } if (isMortal()) { qDebug() << " MORTAL...="; qDebug() << " isMortal=" << isMortal(); qDebug() << " getAge()=" << getAge(); qDebug() << " getLifetime()=" << getLifetime(); } } _lastUpdated = updateTime; if (wantDebug) { qDebug() << " ********** EntityItem::update() .... SETTING _lastUpdated=" << _lastUpdated; } if (hasAngularVelocity()) { glm::quat rotation = getRotation(); glm::vec3 angularVelocity = glm::radians(getAngularVelocity()); float angularSpeed = glm::length(angularVelocity); if (angularSpeed < EPSILON_VELOCITY_LENGTH) { setAngularVelocity(NO_ANGULAR_VELOCITY); } else { float angle = timeElapsed * angularSpeed; glm::quat dQ = glm::angleAxis(angle, glm::normalize(angularVelocity)); rotation = dQ * rotation; setRotation(rotation); // handle damping for angular velocity if (getAngularDamping() > 0.0f) { glm::vec3 dampingResistance = getAngularVelocity() * getAngularDamping(); glm::vec3 newAngularVelocity = getAngularVelocity() - (dampingResistance * timeElapsed); setAngularVelocity(newAngularVelocity); if (wantDebug) { qDebug() << " getDamping():" << getDamping(); qDebug() << " dampingResistance:" << dampingResistance; qDebug() << " newAngularVelocity:" << newAngularVelocity; } } } } if (hasVelocity() || hasGravity()) { glm::vec3 position = getPosition(); glm::vec3 velocity = getVelocity(); glm::vec3 newPosition = position + (velocity * timeElapsed); if (wantDebug) { qDebug() << " EntityItem::update()...."; qDebug() << " timeElapsed:" << timeElapsed; qDebug() << " old AACube:" << getMaximumAACube(); qDebug() << " old position:" << position; qDebug() << " old velocity:" << velocity; qDebug() << " old getAABox:" << getAABox(); qDebug() << " getDistanceToBottomOfEntity():" << getDistanceToBottomOfEntity() * (float)TREE_SCALE << " in meters"; qDebug() << " newPosition:" << newPosition; qDebug() << " glm::distance(newPosition, position):" << glm::distance(newPosition, position); } position = newPosition; // handle bounces off the ground... We bounce at the distance to the bottom of our entity if (position.y <= getDistanceToBottomOfEntity()) { velocity = velocity * glm::vec3(1,-1,1); // if we've slowed considerably, then just stop moving if (glm::length(velocity) <= EPSILON_VELOCITY_LENGTH) { velocity = NO_VELOCITY; } position.y = getDistanceToBottomOfEntity(); } // handle gravity.... if (hasGravity() && !isRestingOnSurface()) { velocity += getGravity() * timeElapsed; } // handle resting on surface case, this is definitely a bit of a hack, and it only works on the // "ground" plane of the domain, but for now it if (hasGravity() && isRestingOnSurface()) { velocity.y = 0.0f; position.y = getDistanceToBottomOfEntity(); } // handle damping for velocity glm::vec3 dampingResistance = velocity * getDamping(); if (wantDebug) { qDebug() << " getDamping():" << getDamping(); qDebug() << " dampingResistance:" << dampingResistance; qDebug() << " dampingResistance * timeElapsed:" << dampingResistance * timeElapsed; } velocity -= dampingResistance * timeElapsed; if (wantDebug) { qDebug() << " velocity AFTER dampingResistance:" << velocity; qDebug() << " glm::length(velocity):" << glm::length(velocity); qDebug() << " EPSILON_VELOCITY_LENGTH:" << EPSILON_VELOCITY_LENGTH; } // round velocity to zero if it's close enough... if (glm::length(velocity) <= EPSILON_VELOCITY_LENGTH) { velocity = NO_VELOCITY; } setPosition(position); // this will automatically recalculate our collision shape setVelocity(velocity); if (wantDebug) { qDebug() << " new position:" << position; qDebug() << " new velocity:" << velocity; qDebug() << " new AACube:" << getMaximumAACube(); qDebug() << " old getAABox:" << getAABox(); } } }
int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args) { bool wantDebug = false; if (args.bitstreamVersion < VERSION_ENTITIES_SUPPORT_SPLIT_MTU) { // NOTE: This shouldn't happen. The only versions of the bit stream that didn't support split mtu buffers should // be handled by the model subclass and shouldn't call this routine. qDebug() << "EntityItem::readEntityDataFromBuffer()... " "ERROR CASE...args.bitstreamVersion < VERSION_ENTITIES_SUPPORT_SPLIT_MTU"; return 0; } // Header bytes // object ID [16 bytes] // ByteCountCoded(type code) [~1 byte] // last edited [8 bytes] // ByteCountCoded(last_edited to last_updated delta) [~1-8 bytes] // PropertyFlags<>( everything ) [1-2 bytes] // ~27-35 bytes... const int MINIMUM_HEADER_BYTES = 27; int bytesRead = 0; if (bytesLeftToRead >= MINIMUM_HEADER_BYTES) { int originalLength = bytesLeftToRead; QByteArray originalDataBuffer((const char*)data, originalLength); int clockSkew = args.sourceNode ? args.sourceNode->getClockSkewUsec() : 0; const unsigned char* dataAt = data; // id QByteArray encodedID = originalDataBuffer.mid(bytesRead, NUM_BYTES_RFC4122_UUID); // maximum possible size _id = QUuid::fromRfc4122(encodedID); _creatorTokenID = UNKNOWN_ENTITY_TOKEN; // if we know the id, then we don't care about the creator token _newlyCreated = false; dataAt += encodedID.size(); bytesRead += encodedID.size(); // type QByteArray encodedType = originalDataBuffer.mid(bytesRead); // maximum possible size ByteCountCoded<quint32> typeCoder = encodedType; encodedType = typeCoder; // determine true length dataAt += encodedType.size(); bytesRead += encodedType.size(); quint32 type = typeCoder; _type = (EntityTypes::EntityType)type; bool overwriteLocalData = true; // assume the new content overwrites our local data // _created quint64 createdFromBuffer = 0; memcpy(&createdFromBuffer, dataAt, sizeof(createdFromBuffer)); dataAt += sizeof(createdFromBuffer); bytesRead += sizeof(createdFromBuffer); createdFromBuffer -= clockSkew; _created = createdFromBuffer; // TODO: do we ever want to discard this??? if (wantDebug) { quint64 lastEdited = getLastEdited(); float editedAgo = getEditedAgo(); QString agoAsString = formatSecondsElapsed(editedAgo); QString ageAsString = formatSecondsElapsed(getAge()); qDebug() << "Loading entity " << getEntityItemID() << " from buffer..."; qDebug() << " _created =" << _created; qDebug() << " age=" << getAge() << "seconds - " << ageAsString; qDebug() << " lastEdited =" << lastEdited; qDebug() << " ago=" << editedAgo << "seconds - " << agoAsString; } quint64 now = usecTimestampNow(); quint64 lastEditedFromBuffer = 0; quint64 lastEditedFromBufferAdjusted = 0; // TODO: we could make this encoded as a delta from _created // _lastEdited memcpy(&lastEditedFromBuffer, dataAt, sizeof(lastEditedFromBuffer)); dataAt += sizeof(lastEditedFromBuffer); bytesRead += sizeof(lastEditedFromBuffer); lastEditedFromBufferAdjusted = lastEditedFromBuffer - clockSkew; bool fromSameServerEdit = (lastEditedFromBuffer == _lastEditedFromRemoteInRemoteTime); if (wantDebug) { qDebug() << "data from server **************** "; qDebug() << " entityItemID=" << getEntityItemID(); qDebug() << " now=" << now; qDebug() << " getLastEdited()=" << getLastEdited(); qDebug() << " lastEditedFromBuffer=" << lastEditedFromBuffer << " (BEFORE clockskew adjust)"; qDebug() << " clockSkew=" << clockSkew; qDebug() << " lastEditedFromBufferAdjusted=" << lastEditedFromBufferAdjusted << " (AFTER clockskew adjust)"; qDebug() << " _lastEditedFromRemote=" << _lastEditedFromRemote << " (our local time the last server edit we accepted)"; qDebug() << " _lastEditedFromRemoteInRemoteTime=" << _lastEditedFromRemoteInRemoteTime << " (remote time the last server edit we accepted)"; qDebug() << " fromSameServerEdit=" << fromSameServerEdit; } bool ignoreServerPacket = false; // assume we're use this server packet // If this packet is from the same server edit as the last packet we accepted from the server // we probably want to use it. if (fromSameServerEdit) { // If this is from the same sever packet, then check against any local changes since we got // the most recent packet from this server time if (_lastEdited > _lastEditedFromRemote) { ignoreServerPacket = true; } } else { // If this isn't from the same sever packet, then honor our skew adjusted times... // If we've changed our local tree more recently than the new data from this packet // then we will not be changing our values, instead we just read and skip the data if (_lastEdited > lastEditedFromBufferAdjusted) { ignoreServerPacket = true; } } if (ignoreServerPacket) { overwriteLocalData = false; if (wantDebug) { qDebug() << "IGNORING old data from server!!! ****************"; } } else { if (wantDebug) { qDebug() << "USING NEW data from server!!! ****************"; } _lastEdited = lastEditedFromBufferAdjusted; _lastEditedFromRemote = now; _lastEditedFromRemoteInRemoteTime = lastEditedFromBuffer; somethingChangedNotification(); // notify derived classes that something has changed } // last updated is stored as ByteCountCoded delta from lastEdited QByteArray encodedUpdateDelta = originalDataBuffer.mid(bytesRead); // maximum possible size ByteCountCoded<quint64> updateDeltaCoder = encodedUpdateDelta; quint64 updateDelta = updateDeltaCoder; if (overwriteLocalData) { _lastUpdated = lastEditedFromBufferAdjusted + updateDelta; // don't adjust for clock skew since we already did that for _lastEdited if (wantDebug) { qDebug() << "_lastUpdated=" << _lastUpdated; qDebug() << "_lastEdited=" << _lastEdited; qDebug() << "lastEditedFromBufferAdjusted=" << lastEditedFromBufferAdjusted; } } encodedUpdateDelta = updateDeltaCoder; // determine true length dataAt += encodedUpdateDelta.size(); bytesRead += encodedUpdateDelta.size(); // Property Flags QByteArray encodedPropertyFlags = originalDataBuffer.mid(bytesRead); // maximum possible size EntityPropertyFlags propertyFlags = encodedPropertyFlags; dataAt += propertyFlags.getEncodedLength(); bytesRead += propertyFlags.getEncodedLength(); READ_ENTITY_PROPERTY(PROP_POSITION, glm::vec3, _position); // Old bitstreams had PROP_RADIUS, new bitstreams have PROP_DIMENSIONS if (args.bitstreamVersion < VERSION_ENTITIES_SUPPORT_DIMENSIONS) { if (propertyFlags.getHasProperty(PROP_RADIUS)) { float fromBuffer; memcpy(&fromBuffer, dataAt, sizeof(fromBuffer)); dataAt += sizeof(fromBuffer); bytesRead += sizeof(fromBuffer); if (overwriteLocalData) { setRadius(fromBuffer); } if (wantDebug) { qDebug() << " readEntityDataFromBuffer() OLD FORMAT... found PROP_RADIUS"; } } } else { READ_ENTITY_PROPERTY(PROP_DIMENSIONS, glm::vec3, _dimensions); if (wantDebug) { qDebug() << " readEntityDataFromBuffer() NEW FORMAT... look for PROP_DIMENSIONS"; } } if (wantDebug) { qDebug() << " readEntityDataFromBuffer() _dimensions:" << getDimensionsInMeters() << " in meters"; } READ_ENTITY_PROPERTY_QUAT(PROP_ROTATION, _rotation); READ_ENTITY_PROPERTY(PROP_MASS, float, _mass); READ_ENTITY_PROPERTY(PROP_VELOCITY, glm::vec3, _velocity); READ_ENTITY_PROPERTY(PROP_GRAVITY, glm::vec3, _gravity); READ_ENTITY_PROPERTY(PROP_DAMPING, float, _damping); READ_ENTITY_PROPERTY(PROP_LIFETIME, float, _lifetime); READ_ENTITY_PROPERTY_STRING(PROP_SCRIPT,setScript); READ_ENTITY_PROPERTY(PROP_REGISTRATION_POINT, glm::vec3, _registrationPoint); READ_ENTITY_PROPERTY(PROP_ANGULAR_VELOCITY, glm::vec3, _angularVelocity); READ_ENTITY_PROPERTY(PROP_ANGULAR_DAMPING, float, _angularDamping); READ_ENTITY_PROPERTY(PROP_VISIBLE, bool, _visible); READ_ENTITY_PROPERTY(PROP_IGNORE_FOR_COLLISIONS, bool, _ignoreForCollisions); READ_ENTITY_PROPERTY(PROP_COLLISIONS_WILL_MOVE, bool, _collisionsWillMove); if (wantDebug) { qDebug() << " readEntityDataFromBuffer() _registrationPoint:" << _registrationPoint; qDebug() << " readEntityDataFromBuffer() _visible:" << _visible; qDebug() << " readEntityDataFromBuffer() _ignoreForCollisions:" << _ignoreForCollisions; qDebug() << " readEntityDataFromBuffer() _collisionsWillMove:" << _collisionsWillMove; } bytesRead += readEntitySubclassDataFromBuffer(dataAt, (bytesLeftToRead - bytesRead), args, propertyFlags, overwriteLocalData); recalculateCollisionShape(); } return bytesRead; }
static bool isKeyhoteeFounder(const bts::addressbook::contact& id) { return getAge(id) == 1; }
float ofAgingMesh::getAgePercent() { return (maxAgeInSeconds - getAge()) / maxAgeInSeconds; }
int ModelEntityItem::oldVersionReadEntityDataFromBuffer(const unsigned char* data, int bytesLeftToRead, ReadBitstreamToTreeParams& args) { int bytesRead = 0; if (bytesLeftToRead >= expectedBytes()) { int clockSkew = args.sourceNode ? args.sourceNode->getClockSkewUsec() : 0; const unsigned char* dataAt = data; // id // this old bitstream format had 32bit IDs. They are obsolete and need to be replaced with our new UUID // format. We can simply read and ignore the old ID since they should not be repeated. This code should only // run on loading from an old file. quint32 oldID; memcpy(&oldID, dataAt, sizeof(oldID)); dataAt += sizeof(oldID); bytesRead += sizeof(oldID); _id = QUuid::createUuid(); // _lastUpdated memcpy(&_lastUpdated, dataAt, sizeof(_lastUpdated)); dataAt += sizeof(_lastUpdated); bytesRead += sizeof(_lastUpdated); _lastUpdated -= clockSkew; // _lastEdited memcpy(&_lastEdited, dataAt, sizeof(_lastEdited)); dataAt += sizeof(_lastEdited); bytesRead += sizeof(_lastEdited); _lastEdited -= clockSkew; _created = _lastEdited; // NOTE: old models didn't have age or created time, assume their last edit was a create QString ageAsString = formatSecondsElapsed(getAge()); qDebug() << "Loading old model file, _created = _lastEdited =" << _created << " age=" << getAge() << "seconds - " << ageAsString << "old ID=" << oldID << "new ID=" << _id; // radius float radius; memcpy(&radius, dataAt, sizeof(radius)); dataAt += sizeof(radius); bytesRead += sizeof(radius); setRadius(radius); // position memcpy(&_position, dataAt, sizeof(_position)); dataAt += sizeof(_position); bytesRead += sizeof(_position); // color memcpy(&_color, dataAt, sizeof(_color)); dataAt += sizeof(_color); bytesRead += sizeof(_color); // TODO: how to handle this? Presumable, this would only ever be true if the model file was saved with // a model being in a shouldBeDeleted state. Which seems unlikely. But if it happens, maybe we should delete the entity after loading? // shouldBeDeleted bool shouldBeDeleted = false; memcpy(&shouldBeDeleted, dataAt, sizeof(shouldBeDeleted)); dataAt += sizeof(shouldBeDeleted); bytesRead += sizeof(shouldBeDeleted); if (shouldBeDeleted) { qDebug() << "UNEXPECTED - read shouldBeDeleted=TRUE from an old format file"; } // modelURL uint16_t modelURLLength; memcpy(&modelURLLength, dataAt, sizeof(modelURLLength)); dataAt += sizeof(modelURLLength); bytesRead += sizeof(modelURLLength); QString modelURLString((const char*)dataAt); setModelURL(modelURLString); dataAt += modelURLLength; bytesRead += modelURLLength; // rotation int bytes = unpackOrientationQuatFromBytes(dataAt, _rotation); dataAt += bytes; bytesRead += bytes; if (args.bitstreamVersion >= VERSION_ENTITIES_HAVE_ANIMATION) { // animationURL uint16_t animationURLLength; memcpy(&animationURLLength, dataAt, sizeof(animationURLLength)); dataAt += sizeof(animationURLLength); bytesRead += sizeof(animationURLLength); QString animationURLString((const char*)dataAt); setAnimationURL(animationURLString); dataAt += animationURLLength; bytesRead += animationURLLength; // animationIsPlaying bool animationIsPlaying; memcpy(&animationIsPlaying, dataAt, sizeof(animationIsPlaying)); dataAt += sizeof(animationIsPlaying); bytesRead += sizeof(animationIsPlaying); setAnimationIsPlaying(animationIsPlaying); // animationFrameIndex float animationFrameIndex; memcpy(&animationFrameIndex, dataAt, sizeof(animationFrameIndex)); dataAt += sizeof(animationFrameIndex); bytesRead += sizeof(animationFrameIndex); setAnimationFrameIndex(animationFrameIndex); // animationFPS float animationFPS; memcpy(&animationFPS, dataAt, sizeof(animationFPS)); dataAt += sizeof(animationFPS); bytesRead += sizeof(animationFPS); setAnimationFPS(animationFPS); } } return bytesRead; }
void Pupil::incrementAge() { int curr_age = getAge(); setAge(++curr_age); }