Speed 4793

adds speed on states!

currently just to animation states 👇
<img width="1121" alt="image" src="https://user-images.githubusercontent.com/1216025/217915050-0bea976f-88b1-4aef-aeb0-bed6f36cc577.png">

I've called this 'AdvanceableState', which we could make blendstates/etc inherit from to give em the powers... not sure if there's a better name people can come up with here... also not sure if that empty lookin' class is the right way to do it, so i'd love feedback on that (and if there's a different example somewhere that would be super helpful to see as well)

also fixed up the generator scripts for dart 3, at least the dart ones, the cpp ones were beyond my patience, gotta dart 2.12 for those...

also fixed an issue where we were checking speed against playing backwards, not speed and direction!

@alxgibsn going to bug you for some styling input

works in both editor and viewer!

going to look about adding a test.. or two....

https://user-images.githubusercontent.com/1216025/217915843-6126d3cf-bf19-4a9d-9a95-adb3a498e75d.mov

https://user-images.githubusercontent.com/1216025/217915852-252d4f78-280e-4a63-838c-39d6b27e3e31.mov

Diffs=
ffeb9afaf Speed 4793 (#4806)
This commit is contained in:
mjtalbot
2023-02-16 10:29:00 +00:00
parent 27be816a46
commit 236ae26640
2 changed files with 20 additions and 10 deletions

View File

@ -1 +1 @@
aa8c750bd077f4260c0daf0de988aeae65a07614
ffeb9afafb69c3bf34e2df8c4c0c205083f2aabf

View File

@ -62,22 +62,31 @@ class LinearAnimationInstance {
bool advance(double elapsedSeconds) {
var deltaSeconds = elapsedSeconds * animation.speed * _direction;
if (deltaSeconds == 0) {
// we say keep going, if you advance by 0.
// could argue that any further advances by 0 result in nothing so you should not keep going
// could argue its saying, we are not at the end of the animation yet, so keep going
// our runtimes currently expect the latter, so we say keep going!
_didLoop = false;
return true;
}
_lastTotalTime = _totalTime;
_totalTime += deltaSeconds;
_totalTime += deltaSeconds.abs();
_time += deltaSeconds;
double frames = _time * animation.fps;
var fps = animation.fps;
double frames = _time * fps;
var start = animation.enableWorkArea ? animation.workStart : 0;
var end = animation.enableWorkArea ? animation.workEnd : animation.duration;
var range = end - start;
bool keepGoing = true;
_didLoop = false;
bool didLoop = false;
_spilledTime = 0;
int direction = animation.speed < 0 ? -_direction : _direction;
int direction = deltaSeconds < 0 ? -1 : 1;
switch (animation.loop) {
case Loop.oneShot:
if (direction == 1 && frames > end) {
@ -85,13 +94,13 @@ class LinearAnimationInstance {
_spilledTime = (frames - end) / fps;
frames = end.toDouble();
_time = frames / fps;
_didLoop = true;
didLoop = true;
} else if (direction == -1 && frames < start) {
keepGoing = false;
_spilledTime = (start - frames) / fps;
frames = start.toDouble();
_time = frames / fps;
_didLoop = true;
didLoop = true;
}
break;
case Loop.loop:
@ -100,13 +109,13 @@ class LinearAnimationInstance {
frames = _time * fps;
frames = start + (frames - start) % range;
_time = frames / fps;
_didLoop = true;
didLoop = true;
} else if (direction == -1 && frames <= start) {
_spilledTime = (start - frames) / fps;
frames = _time * fps;
frames = end - (start - frames) % range;
_time = frames / fps;
_didLoop = true;
didLoop = true;
}
break;
case Loop.pingPong:
@ -129,10 +138,11 @@ class LinearAnimationInstance {
_time = frames / animation.fps;
_direction *= -1;
direction *= -1;
_didLoop = true;
didLoop = true;
}
break;
}
_didLoop = didLoop;
return keepGoing;
}
}