From 1d9dc31a82d761a3f998fe8efdf5c69878d60aab Mon Sep 17 00:00:00 2001 From: Tanasart Date: Wed, 17 Jul 2024 11:50:02 +0700 Subject: [PATCH] - [Strand Create] Fix error when loading baked strands. --- objects/o_dialog_preference/Create_0.gml | 6 +++ objects/o_main/Other_20.gml | 5 +- objects/o_main/Step_1.gml | 4 +- scripts/__initPen/__initPen.gml | 5 +- scripts/__strandSim/__strandSim.gml | 65 +++++++++++++++--------- scripts/preferences/preferences.gml | 2 + 6 files changed, 60 insertions(+), 27 deletions(-) diff --git a/objects/o_dialog_preference/Create_0.gml b/objects/o_dialog_preference/Create_0.gml index f7546a9f7..22984ecfb 100644 --- a/objects/o_dialog_preference/Create_0.gml +++ b/objects/o_dialog_preference/Create_0.gml @@ -163,6 +163,12 @@ event_inherited(); new checkBox(function() /*=>*/ { PREFERENCES.slider_lock_mouse = !PREFERENCES.slider_lock_mouse; PREF_SAVE(); }) )); + ds_list_add(pref_global, new __Panel_Linear_Setting_Item_Preference( + __txtx("pref_pen_pool_delay", "Pen leave delay"), + "pen_pool_delay", + new textBox(TEXTBOX_INPUT.number, function(val) /*=>*/ { PREFERENCES.pen_pool_delay = max(0, val); PREF_SAVE(); }) + )); + ds_list_add(pref_global, __txt("Save/Load")); ds_list_add(pref_global, new __Panel_Linear_Setting_Item_Preference( diff --git a/objects/o_main/Other_20.gml b/objects/o_main/Other_20.gml index f0d8eea4d..4c02b27e4 100644 --- a/objects/o_main/Other_20.gml +++ b/objects/o_main/Other_20.gml @@ -44,4 +44,7 @@ if(PEN_RIGHT_CLICK && !b2) PEN_RIGHT_RELEASE = true; PEN_RIGHT_CLICK = b2; //print($"{PEN_RIGHT_CLICK} | {PEN_RIGHT_PRESS}, {PEN_RIGHT_RELEASE}"); -PEN_USE = true; \ No newline at end of file +if(f & 0x2) { + PEN_POOL = PREFERENCES.pen_pool_delay; + PEN_USE = true; +} \ No newline at end of file diff --git a/objects/o_main/Step_1.gml b/objects/o_main/Step_1.gml index f6ad1665e..669209e39 100644 --- a/objects/o_main/Step_1.gml +++ b/objects/o_main/Step_1.gml @@ -60,7 +60,9 @@ FILE_DROPPED = false; watcher_surface = surface_create(1, 1); } - PEN_USE = false; + if(PEN_POOL <= 0) PEN_USE = false; + else PEN_POOL--; + PEN_RELEASED = false; PEN_RIGHT_PRESS = false; PEN_RIGHT_RELEASE = false; diff --git a/scripts/__initPen/__initPen.gml b/scripts/__initPen/__initPen.gml index a8c9e7bb3..197eebd2c 100644 --- a/scripts/__initPen/__initPen.gml +++ b/scripts/__initPen/__initPen.gml @@ -1,8 +1,9 @@ -globalvar PEN_USE, PEN_CONTACT, PEN_RELEASED, PEN_PRESSURE; +globalvar PEN_USE, PEN_POOL, PEN_CONTACT, PEN_RELEASED, PEN_PRESSURE; globalvar PEN_X, PEN_Y, PEN_X_DELTA, PEN_Y_DELTA; globalvar PEN_RIGHT_CLICK, PEN_RIGHT_PRESS, PEN_RIGHT_RELEASE; -PEN_USE = false; +PEN_USE = false; +PEN_POOL = 0; PEN_X = 0; PEN_Y = 0; diff --git a/scripts/__strandSim/__strandSim.gml b/scripts/__strandSim/__strandSim.gml index a39439024..0635ecea3 100644 --- a/scripts/__strandSim/__strandSim.gml +++ b/scripts/__strandSim/__strandSim.gml @@ -1,4 +1,4 @@ -function StrandPoint(x, y) constructor { +function StrandPoint(x = 0, y = 0) constructor { self.x = x; self.y = y; @@ -16,10 +16,7 @@ function StrandPoint(x, y) constructor { air_resist = 0.5; - static set = function(x ,y) { - self.x = x; - self.y = y; - } + static set = function(x ,y) { self.x = x; self.y = y; } static motionDelta = function() { dx = x - px; @@ -35,22 +32,44 @@ function StrandPoint(x, y) constructor { } static clone = function() { return new StrandPoint(x, y); } + + static serialize = function(s) { + x = s.x; + y = s.y; + + px = s.px; + py = s.py; + + ppx = s.ppx; + ppy = s.ppy; + + dx = s.dx; + dy = s.dy; + + ikx = s.ikx; + iky = s.iky; + + air_resist = s.air_resist; + + return self; + } } -function Strand(sx = 0, sy = 0, amount = 5, _length = 8, direct = 0, curlFreq = 4, curlSize = 8) constructor { - points = []; +function Strand(sx = 0, sy = 0, amount = 5, _length = 8, _direct = 0, curlFreq = 4, curlSize = 8) constructor { id = irandom_range(10000, 99999); - self.length = array_create(amount, _length); - self.direct = direct; + + points = []; + length = array_create(amount, _length); + direct = _direct; curl_freq = curlFreq; curl_size = curlSize; - tension = 0.8; - spring = 0.1; + tension = 0.8; + spring = 0.1; angularTension = 0.1; + rootStrength = -1; + rootForce = 0; - rootStrength = -1; - rootForce = 0; free = false; var _sx = sx; @@ -62,8 +81,8 @@ function Strand(sx = 0, sy = 0, amount = 5, _length = 8, direct = 0, curlFreq = } setOrigin(_sx, _sy); - for( var i = 1; i < array_length(points); i++ ) - restAngle[i] = 0; + + restAngle = array_create(array_length(points), 0); restAngle[0] = direct; static motionDelta = function() { @@ -361,24 +380,24 @@ function Strand(sx = 0, sy = 0, amount = 5, _length = 8, direct = 0, curlFreq = var s = new Strand(points[0].x, points[0].y, array_length(points), length[0], direct, curl_freq, curl_size); for( var i = 0, n = array_length(points); i < n; i++ ) s.points[i] = points[i].clone(); + s.restAngle = array_clone(restAngle); s.length = array_clone(length); return s; } - static serialize = function() { - return { - points: points, - restAngle: restAngle, - length: length, - }; - } + static serialize = function() { return { points, restAngle, length }; } static deserialize = function(s) { - points = s.points; restAngle = s.restAngle; length = s.length; + + var _p = s.points; + points = array_create(array_length(_p)); + for (var i = 0, n = array_length(_p); i < n; i++) + points[i] = new StrandPoint().serialize(_p[i]); + return self; } } diff --git a/scripts/preferences/preferences.gml b/scripts/preferences/preferences.gml index c15b0fc86..1a67c78d2 100644 --- a/scripts/preferences/preferences.gml +++ b/scripts/preferences/preferences.gml @@ -38,6 +38,8 @@ PREFERENCES.double_click_delay = 0.25; PREFERENCES.mouse_wheel_speed = 1.00; + + PREFERENCES.pen_pool_delay = 1; PREFERENCES.slider_lock_mouse = true; PREFERENCES.keyboard_repeat_start = 0.50;