added sync-preferred option to camera path

This commit is contained in:
gnembon committed 2020-06-07 22:44:52 -03:00
1 parent 2f08ee8c01
commit 2739ef9d44
1 file changed
+16
@@ -49,6 +49,11 @@ __command() ->
print(' "/camera show": Show current path particles'); print(' "/camera show": Show current path particles');
print(' color of particles used is different for different players'); print(' color of particles used is different for different players');
print(' "/camera hide": Hide path display'); print(' "/camera hide": Hide path display');
print(' "/camera prefer_smooth_play": ');
print(' Eat CPU spikes and continue as usual');
print(' "/camera prefer_synced_play": ');
print(' After CPU spikes jump to where you should be');
print(''); print('');
'' ''
); );
@@ -483,6 +488,11 @@ hide() ->
); );
// runs the player on the path // runs the player on the path
global_prefer_sync = false;
prefer_smooth_play() -> (global_prefer_sync = false; 'Smooth path play');
prefer_synced_play() -> (global_prefer_sync = true; 'Synchronized path play');
play() -> play() ->
( (
if (err = __is_not_valid_for_motion(), exit(err)); if (err = __is_not_valid_for_motion(), exit(err));
@@ -501,6 +511,7 @@ play() ->
global_playing_path = true; global_playing_path = true;
mspt = 1000 / 60; mspt = 1000 / 60;
start_time = time(); start_time = time();
very_start = start_time;
point = 0; point = 0;
p = __get_player(); p = __get_player();
try ( try (
@@ -514,10 +525,15 @@ play() ->
modify(p, 'location', v); modify(p, 'location', v);
point += 1; point += 1;
end_time = time(); end_time = time();
if (global_prefer_sync,
should_be = very_start + mspt*point;
if (end_time < should_be, sleep(should_be-end_time) )
,
took = end_time - start_time; took = end_time - start_time;
if (took < mspt, sleep(mspt-took)); if (took < mspt, sleep(mspt-took));
start_time = time() start_time = time()
) )
)
); );
); );
sleep(1000); sleep(1000);