Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGermano Cavalcante <germano.costa@ig.com.br>2021-10-26 02:16:28 +0300
committerGermano Cavalcante <germano.costa@ig.com.br>2021-10-26 02:16:28 +0300
commit32cc9ff037465e5522b1f6ee7139f6665975a106 (patch)
tree89f3a7350462461bf1bcf117af1878f925cd786c /source/blender/editors/space_view3d/view3d_cursor_snap.c
parent40f59b5dad15eab01ddd326fbffd59846f398c34 (diff)
View3D Snap Cursor: don't limit the number of states
The benefit of a flat array in this case is small and limiting, so use a linklist.
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_cursor_snap.c')
-rw-r--r--source/blender/editors/space_view3d/view3d_cursor_snap.c64
1 files changed, 18 insertions, 46 deletions
diff --git a/source/blender/editors/space_view3d/view3d_cursor_snap.c b/source/blender/editors/space_view3d/view3d_cursor_snap.c
index 9c45a89c3ff..5db9dd5d0a7 100644
--- a/source/blender/editors/space_view3d/view3d_cursor_snap.c
+++ b/source/blender/editors/space_view3d/view3d_cursor_snap.c
@@ -54,22 +54,19 @@
#include "WM_api.h"
-#define STATE_LEN 8
+#define STATE_INTERN_GET(state) \
+ (SnapStateIntern *)((char *)state - offsetof(SnapStateIntern, snap_state))
typedef struct SnapStateIntern {
+ struct SnapStateIntern *next, *prev;
V3DSnapCursorState snap_state;
- int state_active_prev;
- bool is_active;
} SnapStateIntern;
typedef struct SnapCursorDataIntern {
V3DSnapCursorState state_default;
- SnapStateIntern state_intern[STATE_LEN];
+ ListBase state_intern;
V3DSnapCursorData snap_data;
- int state_active_len;
- int state_active;
-
struct SnapObjectContext *snap_context_v3d;
const Scene *scene;
short snap_elem_hidden;
@@ -852,10 +849,11 @@ static void v3d_cursor_snap_draw_fn(bContext *C, int x, int y, void *UNUSED(cust
V3DSnapCursorState *ED_view3d_cursor_snap_state_get(void)
{
- if (!g_data_intern.state_active_len) {
+ SnapCursorDataIntern *data_intern = &g_data_intern;
+ if (BLI_listbase_is_empty(&data_intern->state_intern)) {
return &g_data_intern.state_default;
}
- return (V3DSnapCursorState *)&g_data_intern.state_intern[g_data_intern.state_active];
+ return &((SnapStateIntern *)data_intern->state_intern.last)->snap_state;
}
static void v3d_cursor_snap_activate(void)
@@ -894,11 +892,7 @@ static void v3d_cursor_snap_free(void)
data_intern->snap_context_v3d = NULL;
}
- for (SnapStateIntern *state_intern = data_intern->state_intern;
- state_intern < &data_intern->state_intern[STATE_LEN];
- state_intern++) {
- state_intern->is_active = false;
- }
+ BLI_freelistN(&data_intern->state_intern);
}
void ED_view3d_cursor_snap_state_default_set(V3DSnapCursorState *state)
@@ -909,51 +903,29 @@ void ED_view3d_cursor_snap_state_default_set(V3DSnapCursorState *state)
V3DSnapCursorState *ED_view3d_cursor_snap_active(void)
{
SnapCursorDataIntern *data_intern = &g_data_intern;
- if (!data_intern->state_active_len) {
+ if (!data_intern->handle) {
v3d_cursor_snap_activate();
}
- data_intern->state_active_len++;
- for (int i = 0; i < STATE_LEN; i++) {
- SnapStateIntern *state_intern = &g_data_intern.state_intern[i];
- if (!state_intern->is_active) {
- state_intern->snap_state = g_data_intern.state_default;
- state_intern->is_active = true;
- state_intern->state_active_prev = data_intern->state_active;
- data_intern->state_active = i;
- return (V3DSnapCursorState *)state_intern;
- }
- }
+ SnapStateIntern *state_intern = MEM_mallocN(sizeof(*state_intern), __func__);
+ state_intern->snap_state = g_data_intern.state_default;
+ BLI_addtail(&g_data_intern.state_intern, state_intern);
- data_intern->state_active_len--;
- return NULL;
+ return (V3DSnapCursorState *)&state_intern->snap_state;
}
void ED_view3d_cursor_snap_deactive(V3DSnapCursorState *state)
{
SnapCursorDataIntern *data_intern = &g_data_intern;
- if (!data_intern->state_active_len) {
- BLI_assert(false);
+ if (BLI_listbase_is_empty(&data_intern->state_intern)) {
return;
}
- if (!state) {
- return;
- }
-
- SnapStateIntern *state_intern = (SnapStateIntern *)state;
- if (!state_intern->is_active) {
- return;
- }
-
- state_intern->is_active = false;
- data_intern->state_active_len--;
- if (!data_intern->state_active_len) {
+ SnapStateIntern *state_intern = STATE_INTERN_GET(state);
+ BLI_remlink(&data_intern->state_intern, state_intern);
+ if (BLI_listbase_is_empty(&data_intern->state_intern)) {
v3d_cursor_snap_free();
}
- else {
- data_intern->state_active = state_intern->state_active_prev;
- }
}
void ED_view3d_cursor_snap_prevpoint_set(V3DSnapCursorState *state, const float prev_point[3])
@@ -977,7 +949,7 @@ V3DSnapCursorData *ED_view3d_cursor_snap_data_get(V3DSnapCursorState *state,
const int y)
{
SnapCursorDataIntern *data_intern = &g_data_intern;
- if (C && data_intern->state_active_len) {
+ if (C) {
wmWindowManager *wm = CTX_wm_manager(C);
if (v3d_cursor_eventstate_has_changed(data_intern, state, wm, x, y)) {
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);