camera using threading

This commit is contained in:
gnembon committed 2019-12-19 01:49:00 -04:00
1 parent 0e9566a58d
commit 54308bb131
1 file changed
+49 -26
@@ -140,42 +140,65 @@ __get_path_at(segment, start, index) ->
v v
); );
__invalidate_points_cache() -> global_path_precalculated = map(range(global_points:(-1):1), null); __invalidate_points_cache() -> global_path_precalculated = map(range(global_points:(-1):1), null);
global_showing_path = false;
global_playing_path = false;
stop() ->
(
if (!global_playing_path && !global_showing_path, return('You can only stop playing or showing the path'));
if (global_showing_path,
global_showing_path = false;
print('stopped showing path');
);
if (global_playing_path,
global_playing_path = false;
print('stopped playing path');
);
''
);
show() -> show() ->
( (
loop(100, global_showing_path = true;
_show_path_tick('dust 0.9 0.1 0.1 1', 100); task( _() -> (
game_tick(50) loop(100,
); if(!global_showing_path, break());
'Done!' _show_path_tick('dust 0.9 0.1 0.1 1', 100);
sleep(50);
);
print('Done!');
));
'';
); );
play(fps) -> play(fps) ->
( (
p = player(); p = player();
__assert_valid_for_motion(); __assert_valid_for_motion();
__prepare_path_if_needed(); __prepare_path_if_needed();
global_playing_path = true;
task( _(outer(fps), outer(p)) -> ( task( _(outer(fps), outer(p)) -> (
//if ((fps % 20 != 0) || fps < 20, exit('FPS needs to be multiples of 20') ); mspt = 1000 / fps;
tpt = fps / 20; start_time = time();
mspt = 50 / tpt; point = 0;
start_time = time(); loop( length(global_points)-1, segment = _;
point = 0; if (!global_playing_path, break());
loop( length(global_points)-1, start = global_points:segment:1;
segment = _; end = global_points:(segment+1):1;
start = global_points:segment:1; loop(end-start,
end = global_points:(segment+1):1; v = __get_path_at(segment, start, _);
loop(end-start, modify(p, 'location', v);
v = __get_path_at(segment, start, _); point += 1;
modify(p, 'location', v); end_time = time();
point += 1; took = end_time - start_time;
end_time = time(); if (took < mspt, sleep(mspt-took));
took = end_time - start_time; start_time = time()
if (took < mspt, sleep(mspt-took)); )
start_time = time() );
) print('Done!');
);
'Done!'
)); ));
'';
); );
_show_path_tick(particle_type, total) -> _show_path_tick(particle_type, total) ->
( (