Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmds] Add accurate train timing to sl #1723

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion elkscmd/tui/sl.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#include "curses.h"
#include <signal.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#include "sl.h"

void add_smoke(int y, int x);
Expand All @@ -56,6 +58,7 @@ int LOGO = 0;
int FLY = 0;
int C51 = 0;
int SLOW = 0;
int FAST = 0;

int my_mvaddstr(int y, int x, char *str)
{
Expand Down Expand Up @@ -84,11 +87,29 @@ void option(char *str)
case 'l': LOGO = 1; break;
case 'c': C51 = 1; break;
case 's': SLOW = 1; break;
case 'f': FAST = 1; break;
default: break;
}
}
}

void cycle(unsigned long usecs)
{
unsigned long elapsed;
struct timeval now;
static long start;

if (usecs == 0) {
gettimeofday(&now, NULL);
start = now.tv_sec * 1000000L + now.tv_usec;
return;
}
gettimeofday(&now, NULL);
elapsed = now.tv_sec * 1000000L + now.tv_usec - start;
if (elapsed < usecs)
usleep(usecs - elapsed);
}

int main(int argc, char *argv[])
{
int x, i;
Expand All @@ -107,6 +128,9 @@ int main(int argc, char *argv[])
scrollok(stdscr, FALSE);

for (x = COLS - 1; ; --x) {
if (!FAST && !SLOW) {
cycle(0);
}
if (LOGO == 1) {
if (add_sl(x) == ERR) break;
}
Expand All @@ -117,7 +141,9 @@ int main(int argc, char *argv[])
if (add_D51(x) == ERR) break;
}
refresh();
//usleep(40000);
if (!FAST && !SLOW) {
cycle(40000);
}
}
mvcur(0, COLS - 1, LINES - 2, 0);
endwin();
Expand Down
Loading