Defining some constants to replace variables that should have never been.
modified: src/nms.c
This commit is contained in:
parent
b97d1cbc4a
commit
17348f7c85
24
src/nms.c
24
src/nms.c
@ -15,6 +15,12 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
|
#define TAB_SIZE 4
|
||||||
|
#define TYPE_EFFECT_SPEED 4 // miliseconds per char
|
||||||
|
#define JUMBLE_SECONDS 2 // number of seconds for jumble effect
|
||||||
|
#define JUMBLE_LOOP_SPEED 35 // miliseconds between each jumble
|
||||||
|
#define REVEAL_LOOP_SPEED 100 // miliseconds (must be evenly divisible by 5)
|
||||||
|
|
||||||
#define SPACE 32
|
#define SPACE 32
|
||||||
#define NEWLINE 10
|
#define NEWLINE 10
|
||||||
#define TAB 9
|
#define TAB 9
|
||||||
@ -76,7 +82,7 @@ void nmsexec(char *src) {
|
|||||||
++y;
|
++y;
|
||||||
x = 0;
|
x = 0;
|
||||||
} else if (c == TAB && x + 4 <= termSizeCols) {
|
} else if (c == TAB && x + 4 <= termSizeCols) {
|
||||||
x += 4;
|
x += TAB_SIZE;
|
||||||
} else if (isspace(c)) {
|
} else if (isspace(c)) {
|
||||||
if (++x > termSizeCols) {
|
if (++x > termSizeCols) {
|
||||||
++y;
|
++y;
|
||||||
@ -115,14 +121,13 @@ void nmsexec(char *src) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initially display the characters in the terminal with a 'type effect'.
|
// Initially display the characters in the terminal with a 'type effect'.
|
||||||
ms = 4; // miliseconds, used for usleep()
|
|
||||||
list_pointer = start;
|
list_pointer = start;
|
||||||
while (list_pointer != NULL && list_pointer->row <= termSizeRows) {
|
while (list_pointer != NULL && list_pointer->row <= termSizeRows) {
|
||||||
mvaddch(list_pointer->row, list_pointer->col, list_pointer->mask);
|
mvaddch(list_pointer->row, list_pointer->col, list_pointer->mask);
|
||||||
refresh();
|
refresh();
|
||||||
list_pointer->mask = getMaskChar();
|
list_pointer->mask = getMaskChar();
|
||||||
list_pointer = list_pointer->next;
|
list_pointer = list_pointer->next;
|
||||||
usleep(ms * 1000);
|
usleep(TYPE_EFFECT_SPEED * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reopen stdin for interactive input (keyboard), then require user
|
// Reopen stdin for interactive input (keyboard), then require user
|
||||||
@ -136,10 +141,8 @@ void nmsexec(char *src) {
|
|||||||
getch();
|
getch();
|
||||||
|
|
||||||
// Jumble loop
|
// Jumble loop
|
||||||
ms = 35; // miliseconds, used for usleep()
|
|
||||||
ls = 2; // loop seconds, number of seconds to loop
|
|
||||||
x = 0;
|
x = 0;
|
||||||
while (x < (ls * 1000) / ms) {
|
while (x < (JUMBLE_SECONDS * 1000) / JUMBLE_LOOP_SPEED) {
|
||||||
list_pointer = start;
|
list_pointer = start;
|
||||||
while (list_pointer != NULL && list_pointer->row <= termSizeRows) {
|
while (list_pointer != NULL && list_pointer->row <= termSizeRows) {
|
||||||
mvaddch(list_pointer->row, list_pointer->col, list_pointer->mask);
|
mvaddch(list_pointer->row, list_pointer->col, list_pointer->mask);
|
||||||
@ -147,13 +150,12 @@ void nmsexec(char *src) {
|
|||||||
list_pointer->mask = getMaskChar();
|
list_pointer->mask = getMaskChar();
|
||||||
list_pointer = list_pointer->next;
|
list_pointer = list_pointer->next;
|
||||||
}
|
}
|
||||||
usleep(ms * 1000);
|
usleep(JUMBLE_LOOP_SPEED * 1000);
|
||||||
++x;
|
++x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Reveal loop
|
// Reveal loop
|
||||||
ms = 100; // miliseconds to sleep (must always evenly divisible by 5)
|
|
||||||
int s1_remask_time = 500; // time, in milliseconds, we change the mask for stage 1
|
int s1_remask_time = 500; // time, in milliseconds, we change the mask for stage 1
|
||||||
bool loop = true;
|
bool loop = true;
|
||||||
while (loop) {
|
while (loop) {
|
||||||
@ -162,13 +164,13 @@ void nmsexec(char *src) {
|
|||||||
while (list_pointer != NULL && list_pointer->row <= termSizeRows) {
|
while (list_pointer != NULL && list_pointer->row <= termSizeRows) {
|
||||||
if (list_pointer->s1_time > 0) {
|
if (list_pointer->s1_time > 0) {
|
||||||
loop = true;
|
loop = true;
|
||||||
list_pointer->s1_time -= ms;
|
list_pointer->s1_time -= REVEAL_LOOP_SPEED;
|
||||||
if (list_pointer->s1_time % s1_remask_time == 0) {
|
if (list_pointer->s1_time % s1_remask_time == 0) {
|
||||||
list_pointer->mask = getMaskChar();
|
list_pointer->mask = getMaskChar();
|
||||||
}
|
}
|
||||||
} else if (list_pointer->s2_time > 0) {
|
} else if (list_pointer->s2_time > 0) {
|
||||||
loop = true;
|
loop = true;
|
||||||
list_pointer->s2_time -= ms;
|
list_pointer->s2_time -= REVEAL_LOOP_SPEED;
|
||||||
list_pointer->mask = getMaskChar();
|
list_pointer->mask = getMaskChar();
|
||||||
} else {
|
} else {
|
||||||
list_pointer->mask = list_pointer->source;
|
list_pointer->mask = list_pointer->source;
|
||||||
@ -184,7 +186,7 @@ void nmsexec(char *src) {
|
|||||||
if (has_colors())
|
if (has_colors())
|
||||||
attroff(COLOR_PAIR(1));
|
attroff(COLOR_PAIR(1));
|
||||||
}
|
}
|
||||||
usleep(ms * 1000);
|
usleep(REVEAL_LOOP_SPEED * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Printing remaining characters from list if we stopped short due to
|
// Printing remaining characters from list if we stopped short due to
|
||||||
|
Loading…
Reference in New Issue
Block a user