Commit: 56e2b9901dad54b1de5c6257ab5e82e481faf192 Author: Falk David Date: Mon Nov 28 22:17:12 2022 +0100 Branches: gpencil-new-data-proposal https://developer.blender.org/rB56e2b9901dad54b1de5c6257ab5e82e481faf192
Use GPFrameKey instead of std::pair for frame ordering =================================================================== M source/blender/blenkernel/intern/gpencil_new_proposal.cc M source/blender/blenkernel/intern/gpencil_new_proposal.hh =================================================================== diff --git a/source/blender/blenkernel/intern/gpencil_new_proposal.cc b/source/blender/blenkernel/intern/gpencil_new_proposal.cc index e424cd32d37..bf9911b3638 100644 --- a/source/blender/blenkernel/intern/gpencil_new_proposal.cc +++ b/source/blender/blenkernel/intern/gpencil_new_proposal.cc @@ -138,20 +138,17 @@ GPFrame::~GPFrame() this->strokes = nullptr; } -bool GPFrame::operator<(const GPFrame &other) const +bool GPFrame::operator<(const GPFrameKey key) const { - if (this->start_time == other.start_time) { - return this->layer_index < other.layer_index; + if (this->start_time == key.start_time) { + return this->layer_index < key.layer_index; } - return this->start_time < other.start_time; + return this->start_time < key.start_time; } -bool GPFrame::operator<(const std::pair<int, int> elem) const +bool GPFrame::operator<(const GPFrame &other) const { - if (this->start_time == elem.second) { - return this->layer_index < elem.first; - } - return this->start_time < elem.second; + return *this < other.get_frame_key(); } bool GPFrame::operator==(const GPFrame &other) const @@ -606,15 +603,14 @@ int GPData::add_frame_on_layer_initialized(int layer_index, int frame_start, int /* Check if the frame can be appended at the end. */ if (this->frames_size == 0 || this->frames_size == reserved || - this->frames(last_index) < std::pair<int, int>(layer_index, frame_start)) { + this->frames(last_index) < new_frame.get_frame_key()) { this->frames_for_write(last_index + 1) = std::move(new_frame); return last_index + 1; } /* Look for the first frame that is equal or greater than the new frame. */ - auto it = std::lower_bound(this->frames().begin(), - this->frames().drop_back(reserved).end(), - std::pair<int, int>(layer_index, frame_start)); + auto it = std::lower_bound( + this->frames().begin(), this->frames().drop_back(reserved).end(), new_frame.get_frame_key()); /* Get the index of the frame. */ int index = std::distance(this->frames().begin(), it); /* Move all the frames and make space at index. */ diff --git a/source/blender/blenkernel/intern/gpencil_new_proposal.hh b/source/blender/blenkernel/intern/gpencil_new_proposal.hh index c8414713353..ed859e83ad9 100644 --- a/source/blender/blenkernel/intern/gpencil_new_proposal.hh +++ b/source/blender/blenkernel/intern/gpencil_new_proposal.hh @@ -81,7 +81,7 @@ typedef struct GPFrame { CurvesGeometry *strokes; /** - * The frame flag (see `eGPFrameFlag`). + * The frame flag (see `eGPFrameFlag`). */ int flag; @@ -219,6 +219,13 @@ class GPStroke { }; class GPFrame : public ::GPFrame { + + /** Structure that defines a key for a frame. Used for ordering/sorting. */ + struct GPFrameKey { + int layer_index; + int start_time; + }; + public: GPFrame() : GPFrame(-1, -1) { @@ -237,9 +244,8 @@ class GPFrame : public ::GPFrame { ~GPFrame(); + bool operator<(const GPFrameKey key) const; bool operator<(const GPFrame &other) const; - /* Assumes that elem.first is the layer index and elem.second is the start time. */ - bool operator<(const std::pair<int, int> elem) const; bool operator==(const GPFrame &other) const; @@ -250,6 +256,11 @@ class GPFrame : public ::GPFrame { Vector<GPStroke> strokes_for_write(); GPStroke add_new_stroke(int new_points_num); + + constexpr GPFrameKey get_frame_key() const + { + return {layer_index, start_time}; + }; }; class GPLayer : public ::GPLayer { _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs