Pixel-Composer/scripts/animation_controller/animation_controller.gml

131 lines
3.2 KiB
Plaintext
Raw Normal View History

2023-05-22 20:31:55 +02:00
#region global
global.FLAG.keyframe_override = true;
2023-07-06 19:49:16 +02:00
enum ANIMATOR_END {
loop,
stop
}
2023-07-25 20:12:40 +02:00
#macro ANIMATION_STATIC !(PROJECT.animator.is_playing || PROJECT.animator.frame_progress)
#macro IS_PLAYING PROJECT.animator.is_playing
2023-10-09 16:07:33 +02:00
#macro CURRENT_FRAME PROJECT.animator.current_frame
#macro LAST_FRAME (CURRENT_FRAME == TOTAL_FRAMES - 1)
2023-10-09 16:07:33 +02:00
#macro TOTAL_FRAMES PROJECT.animator.frames_total
#macro RENDERING PROJECT.animator.rendering
2023-11-04 13:22:52 +01:00
#macro IS_RENDERING array_length(PROJECT.animator.rendering)
2023-05-22 20:31:55 +02:00
#endregion
#region animation class
2022-12-10 05:06:01 +01:00
function AnimationManager() constructor {
2023-03-07 14:29:47 +01:00
frames_total = 30;
current_frame = 0;
real_frame = 0;
2023-01-01 02:06:02 +01:00
time_since_last_frame = 0;
2023-03-07 14:29:47 +01:00
framerate = 30;
is_playing = false;
frame_progress = false;
render_stop = false;
2022-12-10 05:06:01 +01:00
2023-11-26 13:16:38 +01:00
__debug_animator_counter = 0;
2023-11-04 13:22:52 +01:00
rendering = [];
playback = ANIMATOR_END.loop;
2022-12-10 05:06:01 +01:00
2023-11-26 13:16:38 +01:00
static setFrame = function(frame, resetTime = true) { #region
var _c = current_frame;
frame = clamp(frame, 0, frames_total);
real_frame = frame;
2022-12-10 05:06:01 +01:00
current_frame = round(frame);
2022-12-12 09:08:03 +01:00
2023-02-14 02:51:14 +01:00
if(current_frame == frames_total) {
if(render_stop) {
2023-02-14 02:51:14 +01:00
is_playing = false;
2023-11-26 13:16:38 +01:00
setFrame(0, resetTime);
render_stop = false;
} else if(playback == ANIMATOR_END.stop) {
2023-06-04 12:38:40 +02:00
is_playing = false;
} else {
2023-11-26 13:16:38 +01:00
setFrame(0, resetTime);
}
2023-02-14 02:51:14 +01:00
}
if(_c != current_frame) {
2022-12-12 09:08:03 +01:00
frame_progress = true;
if(resetTime)
time_since_last_frame = 0;
2023-10-02 10:45:30 +02:00
RENDER_ALL
2023-03-02 07:59:14 +01:00
} else
frame_progress = false;
if(array_length(rendering)) render_stop = true;
2023-11-26 13:16:38 +01:00
} #endregion
2023-04-10 20:02:59 +02:00
2023-11-26 13:16:38 +01:00
static resetAnimation = function() { #region
2023-07-06 19:49:16 +02:00
var _key = ds_map_find_first(PROJECT.nodeMap);
var amo = ds_map_size(PROJECT.nodeMap);
2023-04-10 20:02:59 +02:00
repeat(amo) {
2023-07-06 19:49:16 +02:00
var _node = PROJECT.nodeMap[? _key];
2023-04-10 20:02:59 +02:00
_node.resetAnimation();
2023-07-06 19:49:16 +02:00
_key = ds_map_find_next(PROJECT.nodeMap, _key);
2023-04-10 20:02:59 +02:00
}
2023-11-26 13:16:38 +01:00
} #endregion
2023-05-16 21:28:16 +02:00
2023-11-26 13:16:38 +01:00
static render = function() { #region
2023-07-25 20:12:40 +02:00
setFrame(0);
2023-05-16 21:28:16 +02:00
is_playing = true;
frame_progress = true;
2023-07-25 20:12:40 +02:00
time_since_last_frame = 0;
2023-11-26 13:16:38 +01:00
} #endregion
2023-05-16 21:28:16 +02:00
2023-11-26 13:16:38 +01:00
static toggle = function() { #region
2023-07-06 19:49:16 +02:00
is_playing = !is_playing;
frame_progress = true;
2023-07-25 20:12:40 +02:00
time_since_last_frame = 0;
2023-11-26 13:16:38 +01:00
} #endregion
2023-06-04 12:38:40 +02:00
2023-11-26 13:16:38 +01:00
static pause = function() { #region
2023-07-06 19:49:16 +02:00
is_playing = false;
frame_progress = true;
2023-07-25 20:12:40 +02:00
time_since_last_frame = 0;
2023-11-26 13:16:38 +01:00
} #endregion
2023-05-16 21:28:16 +02:00
2023-11-26 13:16:38 +01:00
static play = function() { #region
2023-07-25 20:12:40 +02:00
setFrame(0);
2023-07-06 19:49:16 +02:00
is_playing = true;
frame_progress = true;
2023-07-25 20:12:40 +02:00
time_since_last_frame = 0;
2023-11-26 13:16:38 +01:00
} #endregion
2023-05-22 20:31:55 +02:00
2023-11-26 13:16:38 +01:00
static resume = function() { #region
2023-07-06 19:49:16 +02:00
is_playing = true;
frame_progress = true;
2023-07-25 20:12:40 +02:00
time_since_last_frame = 0;
2023-11-26 13:16:38 +01:00
} #endregion
2023-05-16 21:28:16 +02:00
2023-11-26 13:16:38 +01:00
static stop = function() { #region
2023-05-16 21:28:16 +02:00
setFrame(0);
2023-07-25 20:12:40 +02:00
is_playing = false;
time_since_last_frame = 0;
2023-11-26 13:16:38 +01:00
} #endregion
2023-07-25 20:12:40 +02:00
2023-11-26 13:16:38 +01:00
static step = function() { #region
if(!is_playing) return;
var _frTime = 1 / framerate;
time_since_last_frame += delta_time / 1_000_000;
var tslf = time_since_last_frame;
2023-07-25 20:12:40 +02:00
2023-11-26 13:16:38 +01:00
if(time_since_last_frame >= _frTime) {
setFrame(real_frame + 1, false);
time_since_last_frame -= _frTime;
//var _t = get_timer();
//print($"Frame progress {current_frame} delay {(_t - __debug_animator_counter) / 1000}");
//__debug_animator_counter = _t;
2023-07-25 20:12:40 +02:00
}
2023-11-26 13:16:38 +01:00
//print($" > TSLF: {tslf} > {_frTime} > {time_since_last_frame}");
} #endregion
2022-12-10 05:06:01 +01:00
}
#endregion