Add BakingEnabled protocol

This commit is contained in:
Atlante45 2017-08-24 11:14:09 -07:00
parent 9e6502fe92
commit 348be788f7
16 changed files with 205 additions and 32 deletions

View file

@ -334,11 +334,10 @@ void AssetServer::completeSetup() {
QRegExp hashFileRegex { "^[a-f0-9]{" + QString::number(SHA256_HASH_HEX_LENGTH) + "}" }; QRegExp hashFileRegex { "^[a-f0-9]{" + QString::number(SHA256_HASH_HEX_LENGTH) + "}" };
auto files = _filesDirectory.entryInfoList(QDir::Files); auto files = _filesDirectory.entryInfoList(QDir::Files);
auto mappedHashes = _fileMappings.values(); for (auto& it = _fileMappings.cbegin(); it != _fileMappings.cend(); ++it) {
for (const auto& fileInfo : files) { AssetPath path = it.key();
AssetHash hash = fileInfo.fileName(); AssetHash hash = it.value().toString();
bool isAsset = hashFileRegex.exactMatch(hash); if (_baker.assetNeedsBaking(path, hash)) {
if (isAsset && _baker.assetNeedsBaking(hash)) {
_baker.addPendingBake(hash); _baker.addPendingBake(hash);
} }
} }
@ -381,26 +380,24 @@ void AssetServer::handleAssetMappingOperation(QSharedPointer<ReceivedMessage> me
replyPacket->writePrimitive(messageID); replyPacket->writePrimitive(messageID);
switch (operationType) { switch (operationType) {
case AssetMappingOperationType::Get: { case AssetMappingOperationType::Get:
handleGetMappingOperation(*message, senderNode, *replyPacket); handleGetMappingOperation(*message, senderNode, *replyPacket);
break; break;
} case AssetMappingOperationType::GetAll:
case AssetMappingOperationType::GetAll: {
handleGetAllMappingOperation(*message, senderNode, *replyPacket); handleGetAllMappingOperation(*message, senderNode, *replyPacket);
break; break;
} case AssetMappingOperationType::Set:
case AssetMappingOperationType::Set: {
handleSetMappingOperation(*message, senderNode, *replyPacket); handleSetMappingOperation(*message, senderNode, *replyPacket);
break; break;
} case AssetMappingOperationType::Delete:
case AssetMappingOperationType::Delete: {
handleDeleteMappingsOperation(*message, senderNode, *replyPacket); handleDeleteMappingsOperation(*message, senderNode, *replyPacket);
break; break;
} case AssetMappingOperationType::Rename:
case AssetMappingOperationType::Rename: {
handleRenameMappingOperation(*message, senderNode, *replyPacket); handleRenameMappingOperation(*message, senderNode, *replyPacket);
break; break;
} case AssetMappingOperationType::SetBakingEnabled:
handleSetBakingEnabledOperation(*message, senderNode, *replyPacket);
break;
} }
auto nodeList = DependencyManager::get<NodeList>(); auto nodeList = DependencyManager::get<NodeList>();
@ -545,6 +542,30 @@ void AssetServer::handleRenameMappingOperation(ReceivedMessage& message, SharedN
} }
} }
void AssetServer::handleSetBakingEnabledOperation(ReceivedMessage& message, SharedNodePointer senderNode, NLPacketList& replyPacket) {
if (senderNode->getCanWriteToAssetServer()) {
bool enabled { true };
message.readPrimitive(&enabled);
int numberOfMappings{ 0 };
message.readPrimitive(&numberOfMappings);
QStringList mappings;
for (int i = 0; i < numberOfMappings; ++i) {
mappings << message.readString();
}
if (setBakingEnabled(mappings, enabled)) {
replyPacket.writePrimitive(AssetServerError::NoError);
} else {
replyPacket.writePrimitive(AssetServerError::MappingOperationFailed);
}
} else {
replyPacket.writePrimitive(AssetServerError::PermissionDenied);
}
}
void AssetServer::handleAssetGetInfo(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode) { void AssetServer::handleAssetGetInfo(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode) {
QByteArray assetHash; QByteArray assetHash;
MessageID messageID; MessageID messageID;
@ -1100,4 +1121,7 @@ bool AssetServer::createMetaFile(AssetHash originalAssetHash) {
} else { } else {
return false; return false;
} }
bool AssetServer::setBakingEnabled(AssetPathList& paths, bool enabled) {
return "test";
} }

View file

@ -64,6 +64,7 @@ private:
void handleSetMappingOperation(ReceivedMessage& message, SharedNodePointer senderNode, NLPacketList& replyPacket); void handleSetMappingOperation(ReceivedMessage& message, SharedNodePointer senderNode, NLPacketList& replyPacket);
void handleDeleteMappingsOperation(ReceivedMessage& message, SharedNodePointer senderNode, NLPacketList& replyPacket); void handleDeleteMappingsOperation(ReceivedMessage& message, SharedNodePointer senderNode, NLPacketList& replyPacket);
void handleRenameMappingOperation(ReceivedMessage& message, SharedNodePointer senderNode, NLPacketList& replyPacket); void handleRenameMappingOperation(ReceivedMessage& message, SharedNodePointer senderNode, NLPacketList& replyPacket);
void handleSetBakingEnabledOperation(ReceivedMessage& message, SharedNodePointer senderNode, NLPacketList& replyPacket);
// Mapping file operations must be called from main assignment thread only // Mapping file operations must be called from main assignment thread only
bool loadMappingsFromFile(); bool loadMappingsFromFile();
@ -78,6 +79,8 @@ private:
/// Rename mapping from `oldPath` to `newPath`. Returns true if successful /// Rename mapping from `oldPath` to `newPath`. Returns true if successful
bool renameMapping(AssetPath oldPath, AssetPath newPath); bool renameMapping(AssetPath oldPath, AssetPath newPath);
bool setBakingEnabled(AssetPathList& paths, bool enabled);
/// Delete any unmapped files from the local asset directory /// Delete any unmapped files from the local asset directory
void cleanupUnmappedFiles(); void cleanupUnmappedFiles();

View file

@ -20,8 +20,8 @@ void AutoBaker::addPendingBake(AssetHash hash) {
// Maybe start baking it right away // Maybe start baking it right away
} }
bool AutoBaker::assetNeedsBaking(AssetHash hash) { bool AutoBaker::assetNeedsBaking(AssetPath path, AssetHash hash) {
return true; return path.endsWith(".fbx");
} }
BakingStatus AutoBaker::getAssetStatus(AssetHash hash) { BakingStatus AutoBaker::getAssetStatus(AssetHash hash) {
@ -33,9 +33,5 @@ BakingStatus AutoBaker::getAssetStatus(AssetHash hash) {
return Baking; return Baking;
} }
if (assetNeedsBaking(hash)) { return NotBaked;
return NotBaked;
} else {
return Baked;
}
} }

View file

@ -20,7 +20,7 @@ class AutoBaker {
public: public:
void addPendingBake(AssetHash hash); void addPendingBake(AssetHash hash);
bool assetNeedsBaking(AssetHash hash); bool assetNeedsBaking(AssetPath path, AssetHash hash);
BakingStatus getAssetStatus(AssetHash hash); BakingStatus getAssetStatus(AssetHash hash);

View file

@ -542,7 +542,7 @@ ScrollingWindow {
id: bakedColumn id: bakedColumn
title: "Use Baked?" title: "Use Baked?"
role: "baked" role: "baked"
width: 120 width: 140
} }
MouseArea { MouseArea {
@ -596,14 +596,17 @@ ScrollingWindow {
anchors.bottomMargin: hifi.dimensions.contentSpacing.y anchors.bottomMargin: hifi.dimensions.contentSpacing.y
spacing: hifi.dimensions.contentSpacing.x spacing: hifi.dimensions.contentSpacing.x
HifiControls.Label { RalewayRegular {
text: treeView.selection.selectedIndexes.length + " ITEMS SELECTED" size: hifi.fontSizes.sectionName
colorScheme: root.colorScheme font.capitalization: Font.AllUppercase
text: selectedItems + " items selected"
color: hifi.colors.lightGrayText
} }
HifiControls.CheckBox { HifiControls.CheckBox {
text: "Use baked (optimized) versions" text: "Use baked (optimized) versions"
colorScheme: root.colorScheme colorScheme: root.colorScheme
enabled: selectedItems > 0
} }
} }

View file

@ -212,12 +212,16 @@ TreeView {
if (treeView.canEdit && styleData.selected) { if (treeView.canEdit && styleData.selected) {
return textFieldComponent; return textFieldComponent;
} else { } else {
return labelComponent; if (styleData.value.startsWith("HifiGlyphs#")) {
return glyphComponent;
} else {
return labelComponent;
}
} }
} }
sourceComponent: getComponent() sourceComponent: getComponent()
Component { Component {
id: labelComponent id: labelComponent
FiraSansSemiBold { FiraSansSemiBold {
@ -231,6 +235,18 @@ TreeView {
elide: Text.ElideRight elide: Text.ElideRight
} }
} }
Component {
id: glyphComponent
HiFiGlyphs {
text: styleData.value.replace("HifiGlyphs#", "")
size: hifi.fontSizes.tableText
color: colorScheme == hifi.colorSchemes.light
? (styleData.selected ? hifi.colors.black : hifi.colors.baseGrayHighlight)
: (styleData.selected ? hifi.colors.black : hifi.colors.lightGrayText)
elide: Text.ElideRight
}
}
Component { Component {
id: textFieldComponent id: textFieldComponent

View file

@ -185,6 +185,14 @@ RenameMappingRequest* AssetClient::createRenameMappingRequest(const AssetPath& o
return request; return request;
} }
SetBakingEnabledRequest* AssetClient::createSetBakingEnabledRequest(const AssetPathList& path, bool enabled) {
auto bakingEnabledRequest = new SetBakingEnabledRequest(path, enabled);
bakingEnabledRequest->moveToThread(thread());
return bakingEnabledRequest;
}
AssetRequest* AssetClient::createRequest(const AssetHash& hash, const ByteRange& byteRange) { AssetRequest* AssetClient::createRequest(const AssetHash& hash, const ByteRange& byteRange) {
auto request = new AssetRequest(hash, byteRange); auto request = new AssetRequest(hash, byteRange);
@ -585,6 +593,38 @@ MessageID AssetClient::renameAssetMapping(const AssetPath& oldPath, const AssetP
return INVALID_MESSAGE_ID; return INVALID_MESSAGE_ID;
} }
MessageID AssetClient::setBakingEnabled(const AssetPathList& paths, bool enabled, MappingOperationCallback callback) {
auto nodeList = DependencyManager::get<NodeList>();
SharedNodePointer assetServer = nodeList->soloNodeOfType(NodeType::AssetServer);
if (assetServer) {
auto packetList = NLPacketList::create(PacketType::AssetMappingOperation, QByteArray(), true, true);
auto messageID = ++_currentID;
packetList->writePrimitive(messageID);
packetList->writePrimitive(AssetMappingOperationType::SetBakingEnabled);
packetList->writePrimitive(enabled);
packetList->writePrimitive(int(paths.size()));
for (auto& path : paths) {
packetList->writeString(path);
}
if (nodeList->sendPacketList(std::move(packetList), *assetServer) != -1) {
_pendingMappingRequests[assetServer][messageID] = callback;
return messageID;
}
}
callback(false, AssetServerError::NoError, QSharedPointer<ReceivedMessage>());
return INVALID_MESSAGE_ID;
}
bool AssetClient::cancelMappingRequest(MessageID id) { bool AssetClient::cancelMappingRequest(MessageID id) {
Q_ASSERT(QThread::currentThread() == thread()); Q_ASSERT(QThread::currentThread() == thread());

View file

@ -32,6 +32,7 @@ class SetMappingRequest;
class GetAllMappingsRequest; class GetAllMappingsRequest;
class DeleteMappingsRequest; class DeleteMappingsRequest;
class RenameMappingRequest; class RenameMappingRequest;
class SetBakingEnabledRequest;
class AssetRequest; class AssetRequest;
class AssetUpload; class AssetUpload;
@ -56,6 +57,7 @@ public:
Q_INVOKABLE DeleteMappingsRequest* createDeleteMappingsRequest(const AssetPathList& paths); Q_INVOKABLE DeleteMappingsRequest* createDeleteMappingsRequest(const AssetPathList& paths);
Q_INVOKABLE SetMappingRequest* createSetMappingRequest(const AssetPath& path, const AssetHash& hash); Q_INVOKABLE SetMappingRequest* createSetMappingRequest(const AssetPath& path, const AssetHash& hash);
Q_INVOKABLE RenameMappingRequest* createRenameMappingRequest(const AssetPath& oldPath, const AssetPath& newPath); Q_INVOKABLE RenameMappingRequest* createRenameMappingRequest(const AssetPath& oldPath, const AssetPath& newPath);
Q_INVOKABLE SetBakingEnabledRequest* createSetBakingEnabledRequest(const AssetPathList& path, bool enabled);
Q_INVOKABLE AssetRequest* createRequest(const AssetHash& hash, const ByteRange& byteRange = ByteRange()); Q_INVOKABLE AssetRequest* createRequest(const AssetHash& hash, const ByteRange& byteRange = ByteRange());
Q_INVOKABLE AssetUpload* createUpload(const QString& filename); Q_INVOKABLE AssetUpload* createUpload(const QString& filename);
Q_INVOKABLE AssetUpload* createUpload(const QByteArray& data); Q_INVOKABLE AssetUpload* createUpload(const QByteArray& data);
@ -81,6 +83,7 @@ private:
MessageID setAssetMapping(const QString& path, const AssetHash& hash, MappingOperationCallback callback); MessageID setAssetMapping(const QString& path, const AssetHash& hash, MappingOperationCallback callback);
MessageID deleteAssetMappings(const AssetPathList& paths, MappingOperationCallback callback); MessageID deleteAssetMappings(const AssetPathList& paths, MappingOperationCallback callback);
MessageID renameAssetMapping(const AssetPath& oldPath, const AssetPath& newPath, MappingOperationCallback callback); MessageID renameAssetMapping(const AssetPath& oldPath, const AssetPath& newPath, MappingOperationCallback callback);
MessageID setBakingEnabled(const AssetPathList& paths, bool enabled, MappingOperationCallback callback);
MessageID getAssetInfo(const QString& hash, GetInfoCallback callback); MessageID getAssetInfo(const QString& hash, GetInfoCallback callback);
MessageID getAsset(const QString& hash, DataOffset start, DataOffset end, MessageID getAsset(const QString& hash, DataOffset start, DataOffset end,
@ -119,6 +122,7 @@ private:
friend class SetMappingRequest; friend class SetMappingRequest;
friend class DeleteMappingsRequest; friend class DeleteMappingsRequest;
friend class RenameMappingRequest; friend class RenameMappingRequest;
friend class SetBakingEnabledRequest;
}; };
#endif #endif

View file

@ -87,6 +87,8 @@ bool isValidHash(const AssetHash& hash) {
QString bakingStatusToString(BakingStatus status) { QString bakingStatusToString(BakingStatus status) {
switch (status) { switch (status) {
case Unrelevant:
return "--";
case NotBaked: case NotBaked:
return "Not Baked"; return "Not Baked";
case Pending: case Pending:
@ -95,5 +97,7 @@ QString bakingStatusToString(BakingStatus status) {
return "Baking"; return "Baking";
case Baked: case Baked:
return "Baked"; return "Baked";
case Error:
return "Error";
} }
} }

View file

@ -48,14 +48,17 @@ enum AssetMappingOperationType : uint8_t {
GetAll, GetAll,
Set, Set,
Delete, Delete,
Rename Rename,
SetBakingEnabled
}; };
enum BakingStatus { enum BakingStatus {
Unrelevant,
NotBaked, NotBaked,
Pending, Pending,
Baking, Baking,
Baked Baked,
Error
}; };
struct MappingInfo { struct MappingInfo {

View file

@ -273,3 +273,46 @@ void RenameMappingRequest::doStart() {
emit finished(this); emit finished(this);
}); });
} }
SetBakingEnabledRequest::SetBakingEnabledRequest(const AssetPathList& paths, bool enabled) : _paths(paths), _enabled(enabled) {
for (auto& path : _paths) {
path = path.trimmed();
}
};
void SetBakingEnabledRequest::doStart() {
// short circuit the request if any of the paths are invalid
for (auto& path : _paths) {
if (!isValidPath(path)) {
_error = MappingRequest::InvalidPath;
emit finished(this);
return;
}
}
auto assetClient = DependencyManager::get<AssetClient>();
_mappingRequestID = assetClient->setBakingEnabled(_paths, _enabled,
[this, assetClient](bool responseReceived, AssetServerError error, QSharedPointer<ReceivedMessage> message) {
_mappingRequestID = INVALID_MESSAGE_ID;
if (!responseReceived) {
_error = NetworkError;
} else {
switch (error) {
case AssetServerError::NoError:
_error = NoError;
break;
case AssetServerError::PermissionDenied:
_error = PermissionDenied;
break;
default:
_error = UnknownError;
break;
}
}
emit finished(this);
});
};

View file

@ -133,5 +133,20 @@ private:
AssetMapping _mappings; AssetMapping _mappings;
}; };
class SetBakingEnabledRequest : public MappingRequest {
Q_OBJECT
public:
SetBakingEnabledRequest(const AssetPathList& path, bool enabled);
signals:
void finished(SetBakingEnabledRequest* thisRequest);
private:
virtual void doStart() override;
AssetPathList _paths;
bool _enabled;
};
#endif // hifi_MappingRequest_h #endif // hifi_MappingRequest_h

View file

@ -67,7 +67,9 @@ PacketVersion versionForPacketType(PacketType packetType) {
case PacketType::MicrophoneAudioWithEcho: case PacketType::MicrophoneAudioWithEcho:
case PacketType::AudioStreamStats: case PacketType::AudioStreamStats:
return static_cast<PacketVersion>(AudioVersion::HighDynamicRangeVolume); return static_cast<PacketVersion>(AudioVersion::HighDynamicRangeVolume);
case PacketType::AssetMappingOperation:
case PacketType::AssetMappingOperationReply:
return static_cast<PacketVersion>(AssetMappingOperationVersion::SetBakingEnabledOperation);
default: default:
return 17; return 17;
} }

View file

@ -336,4 +336,8 @@ enum class MessageDataVersion : PacketVersion {
TextOrBinaryData = 18 TextOrBinaryData = 18
}; };
enum class AssetMappingOperationVersion : PacketVersion {
SetBakingEnabledOperation = 18
};
#endif // hifi_PacketHeaders_h #endif // hifi_PacketHeaders_h

View file

@ -88,6 +88,20 @@ void AssetScriptingInterface::downloadData(QString urlString, QScriptValue callb
assetRequest->start(); assetRequest->start();
} }
void AssetScriptingInterface::setBakingEnabled(QString path, bool enabled, QScriptValue callback) {
auto setBakingEnabledRequest = DependencyManager::get<AssetClient>()->createSetBakingEnabledRequest({ path }, enabled);
QObject::connect(setBakingEnabledRequest, &SetBakingEnabledRequest::finished, this, [this, callback](SetBakingEnabledRequest* request) mutable {
if (callback.isFunction()) {
QString error = request->getErrorString();
QScriptValueList args{ error };
callback.call(_engine->currentContext()->thisObject(), args);
}
request->deleteLater();
});
setBakingEnabledRequest->start();
}
#if (PR_BUILD || DEV_BUILD) #if (PR_BUILD || DEV_BUILD)
void AssetScriptingInterface::sendFakedHandshake() { void AssetScriptingInterface::sendFakedHandshake() {
auto nodeList = DependencyManager::get<NodeList>(); auto nodeList = DependencyManager::get<NodeList>();

View file

@ -75,6 +75,8 @@ public:
* @param {string} error * @param {string} error
*/ */
Q_INVOKABLE void setMapping(QString path, QString hash, QScriptValue callback); Q_INVOKABLE void setMapping(QString path, QString hash, QScriptValue callback);
Q_INVOKABLE void setBakingEnabled(QString path, bool enabled, QScriptValue callback);
#if (PR_BUILD || DEV_BUILD) #if (PR_BUILD || DEV_BUILD)
Q_INVOKABLE void sendFakedHandshake(); Q_INVOKABLE void sendFakedHandshake();