So I'm trying to program a server for my game. I want the server to look beautiful and organised and cross-platfrom too so I decided to you ncurses..
I'm trying to show at the top a loading the classical { '-', '\\', '|', '/' }
thing
but the problem when I try to print player connected or data it write on the loading bar and its annoying.
Some picture here gonna explain the situation
What I want
What it's actually doing
and this is my code:
//INCLUDEs
int clients = 0;
char chars[] = { '-', '\\', '|', '/' };
unsigned int i;
void showStatus(char a)
{
attron(COLOR_PAIR(1));
mvprintw(2, 101 - 25, "%c\r", a);
mvprintw(2, 59, "%d\r", clients);
refresh();
}
void caller()
{
for (i = 0; ; ++i) {
showStatus(chars[i % sizeof(chars)]);
//fflush(stdout);
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
}
int main(int argc, char ** argv){
//init everything..
printw("-------------- ~~ BS SERVER PRE-ALPHA (v0.0.1) | Clients: (%d/32) | Running (%c) ~~ ---------------\n\r", 0, '|');
//more code....
std::thread thr(caller);
while (1) {
//check for connections...
}
thr.join();
endwin();
}
PS: I tried removing the thread repacing it with for, I want the thread so the char can rotate and the server can keep receiving data in the same time.
Thanks
Well, it actually works, my idea, was to draw a window for the status and update it whenver we need to, and output logs in the main window and its working like charm.