载入中...
搜索中...
未找到
AssetDiff.cpp
浏览该文件的文档.
1#include "asset/AssetDiff.h"
2
3#include <algorithm>
4#include <map>
5#include <set>
6#include <tuple>
7
8namespace eve::asset {
9namespace {
10using DependencyKey = std::tuple<PersistentId, PersistentId, EvaDependencyKind, std::string,
11 std::string, std::string, std::string>;
12Result<std::set<DependencyKey>> dependencyKeys(const EvaManifest& manifest) {
13 std::set<DependencyKey> result;
14 for (const auto& value : manifest.dependencies) {
15 auto predicate = Value(value.predicate).toJson();
16 if (!predicate)
17 return Result<std::set<DependencyKey>>::failure(predicate.status());
18 auto fallback = Value(value.fallback).toJson();
19 if (!fallback)
20 return Result<std::set<DependencyKey>>::failure(fallback.status());
21 result.emplace(value.from.id(), value.to.id(), value.kind, value.path,
22 value.expectedType, std::move(predicate).takeValue(),
23 std::move(fallback).takeValue());
24 }
25 return Result<std::set<DependencyKey>>::success(std::move(result));
26}
27} // namespace
28
30 std::map<PersistentId, const EvaAssetEntry*> left, right;
31 for (const auto& asset : before.assets) left.emplace(asset.asset.id(), &asset);
32 for (const auto& asset : after.assets) right.emplace(asset.asset.id(), &asset);
33 EvaPackageDiff result;
34 for (const auto& [id, asset] : left) {
35 const auto found = right.find(id);
36 if (found == right.end()) {
37 result.assets.push_back({id, EvaAssetChangeKind::Removed, asset->type,
38 asset->schemaVersion, asset->contentHash, {}, {}, {}});
39 } else if (asset->type != found->second->type || asset->schemaVersion != found->second->schemaVersion ||
40 asset->contentHash != found->second->contentHash) {
41 result.assets.push_back({id, EvaAssetChangeKind::Changed, asset->type,
42 asset->schemaVersion, asset->contentHash, found->second->type,
43 found->second->schemaVersion, found->second->contentHash});
44 }
45 }
46 for (const auto& [id, asset] : right)
47 if (!left.contains(id))
48 result.assets.push_back({id, EvaAssetChangeKind::Added, {}, {}, {}, asset->type,
49 asset->schemaVersion, asset->contentHash});
50 std::sort(result.assets.begin(), result.assets.end(), [](const auto& a, const auto& b) {
51 return a.assetId < b.assetId;
52 });
53 const auto leftDependencies = dependencyKeys(before);
54 if (!leftDependencies) return Result<EvaPackageDiff>::failure(leftDependencies.status());
55 const auto rightDependencies = dependencyKeys(after);
56 if (!rightDependencies) return Result<EvaPackageDiff>::failure(rightDependencies.status());
57 std::vector<DependencyKey> added, removed;
58 std::set_difference(rightDependencies.value().begin(), rightDependencies.value().end(),
59 leftDependencies.value().begin(), leftDependencies.value().end(),
60 std::back_inserter(added));
61 std::set_difference(leftDependencies.value().begin(), leftDependencies.value().end(),
62 rightDependencies.value().begin(), rightDependencies.value().end(),
63 std::back_inserter(removed));
64 result.addedDependencies = static_cast<std::uint32_t>(added.size());
65 result.removedDependencies = static_cast<std::uint32_t>(removed.size());
66 result.entrypointsChanged = before.entrypoints != after.entrypoints;
67 return Result<EvaPackageDiff>::success(std::move(result));
68}
69} // namespace eve::asset
double value
Deterministic semantic comparison of two `.eva` manifests.
HexVec3 left
HexVec3 right
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
std::string id
Definition PlayHost.cpp:108
bool found
int removed
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Result< EvaPackageDiff > diffEvaManifests(const EvaManifest &before, const EvaManifest &after)
Compare two admitted manifests without using paths, timestamps or archive order.
Definition AssetDiff.cpp:29
EvaDependencyKind
Dependency role recorded by a source asset archive.
Definition EvaManifest.h:21
std::variant< std::monostate, std::int64_t, double, std::string, bool > Value
Definition Database.h:26
StrongUuid< detail::PersistentIdTag > PersistentId
Stable instance identity for persistence, networking and process boundaries.
Definition Identity.h:254
Validated, owning .eva manifest.
Definition EvaManifest.h:62
std::vector< EvaAssetEntry > assets
Definition EvaManifest.h:69
Deterministically ordered semantic package difference.
Definition AssetDiff.h:27
std::vector< EvaAssetChange > assets
Definition AssetDiff.h:28