载入中...
搜索中...
未找到
EditorVolumeTarget.cpp
浏览该文件的文档.
2
3#include <utility>
4
5namespace eve::editor {
6
9
10bool IntVolumeEditCommand::record(int x, int y, int z, int after) {
11 auto* volume = target_ ? target_->query<IIntVolumeTarget>() : nullptr;
12 if (!volume) return false;
13 for (auto& change : changes_) {
14 if (change.x == x && change.y == y && change.z == z) {
15 change.after = after;
16 return true;
17 }
18 }
19 const int before = volume->readInt3(x, y, z);
20 if (before == after) return false;
21 changes_.push_back({x, y, z, before, after});
22 dirty_.include(x, y, z);
23 return true;
24}
25
27 auto* volume = target_ ? target_->query<IIntVolumeTarget>() : nullptr;
28 if (!volume || changes_.empty()) return false;
29 for (std::size_t i = 0; i < changes_.size(); ++i) {
30 if (volume->writeInt3(changes_[i].x, changes_[i].y, changes_[i].z, changes_[i].after) ==
32 while (i > 0) {
33 --i;
34 (void)volume->writeInt3(changes_[i].x, changes_[i].y, changes_[i].z, changes_[i].before);
35 }
36 return false;
37 }
38 }
39 return true;
40}
41
43 auto* volume = target_ ? target_->query<IIntVolumeTarget>() : nullptr;
44 if (!volume) return;
45 for (auto it = changes_.rbegin(); it != changes_.rend(); ++it)
46 (void)volume->writeInt3(it->x, it->y, it->z, it->before);
47}
48
49std::unique_ptr<IEditCommand> IntVolumeEditCommand::clone() const {
50 return std::make_unique<IntVolumeEditCommand>(*this);
51}
52
54 const auto* later = dynamic_cast<const IntVolumeEditCommand*>(&laterBase);
55 if (!later || later->target_ != target_) return false;
56 for (const auto& incoming : later->changes_) {
57 bool merged = false;
58 for (auto& current : changes_) {
59 if (current.x == incoming.x && current.y == incoming.y && current.z == incoming.z) {
60 current.after = incoming.after;
61 merged = true;
62 break;
63 }
64 }
65 if (!merged) changes_.push_back(incoming);
66 }
67 dirty_.include(later->dirty_);
68 return true;
69}
70
71} // namespace eve::editor
LogicalId target
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
double volume
std::string name
double current
IEditableTarget public API.
Stable capability for sparse integer volumes.
Reversible unit accepted by the editor transaction manager.
Definition EditCommand.h:14
Reversible integer-volume command shared by voxel and custom volume targets.
std::unique_ptr< IEditCommand > clone() const override
Deep copy. @ownership Caller deletes.
bool record(int x, int y, int z, int after)
Record a desired value without applying it.
bool mergeWith(const IEditCommand &later) override
Merge with.
IntVolumeEditCommand(std::string name, IEditableTarget *target)
Create an unapplied command for one editable volume target.
void include(int x, int y, int z)
Include.