bool ModelTreeElement::updateModel(const ModelItem& model) { // NOTE: this method must first lookup the model by ID, hence it is O(N) // and "model is not found" is worst-case (full N) but maybe we don't care? // (guaranteed that num models per elemen is small?) const bool wantDebug = false; uint16_t numberOfModels = _modelItems->size(); for (uint16_t i = 0; i < numberOfModels; i++) { ModelItem& thisModel = (*_modelItems)[i]; if (thisModel.getID() == model.getID()) { int difference = thisModel.getLastUpdated() - model.getLastUpdated(); bool changedOnServer = thisModel.getLastEdited() < model.getLastEdited(); bool localOlder = thisModel.getLastUpdated() < model.getLastUpdated(); if (changedOnServer || localOlder) { if (wantDebug) { qDebug("local model [id:%d] %s and %s than server model by %d, model.isNewlyCreated()=%s", model.getID(), (changedOnServer ? "CHANGED" : "same"), (localOlder ? "OLDER" : "NEWER"), difference, debug::valueOf(model.isNewlyCreated()) ); } thisModel.copyChangedProperties(model); markWithChangedTime(); } else { if (wantDebug) { qDebug(">>> IGNORING SERVER!!! Would've caused jutter! <<< " "local model [id:%d] %s and %s than server model by %d, model.isNewlyCreated()=%s", model.getID(), (changedOnServer ? "CHANGED" : "same"), (localOlder ? "OLDER" : "NEWER"), difference, debug::valueOf(model.isNewlyCreated()) ); } } return true; } } return false; }
void ModelItemProperties::copyFromModelItem(const ModelItem& modelItem) { _position = modelItem.getPosition() * (float) TREE_SCALE; _color = modelItem.getXColor(); _radius = modelItem.getRadius() * (float) TREE_SCALE; _shouldDie = modelItem.getShouldDie(); _modelURL = modelItem.getModelURL(); _modelRotation = modelItem.getModelRotation(); _id = modelItem.getID(); _idSet = true; _positionChanged = false; _colorChanged = false; _radiusChanged = false; _shouldDieChanged = false; _modelURLChanged = false; _modelRotationChanged = false; _defaultSettings = false; }
void ModelServer::modelCreated(const ModelItem& newModel, const SharedNodePointer& senderNode) { unsigned char outputBuffer[MAX_PACKET_SIZE]; unsigned char* copyAt = outputBuffer; int numBytesPacketHeader = populatePacketHeader(reinterpret_cast<char*>(outputBuffer), PacketTypeModelAddResponse); int packetLength = numBytesPacketHeader; copyAt += numBytesPacketHeader; // encode the creatorTokenID uint32_t creatorTokenID = newModel.getCreatorTokenID(); memcpy(copyAt, &creatorTokenID, sizeof(creatorTokenID)); copyAt += sizeof(creatorTokenID); packetLength += sizeof(creatorTokenID); // encode the model ID uint32_t modelID = newModel.getID(); memcpy(copyAt, &modelID, sizeof(modelID)); copyAt += sizeof(modelID); packetLength += sizeof(modelID); NodeList::getInstance()->writeDatagram((char*) outputBuffer, packetLength, senderNode); }