hello, i'm making a simple text based strategy game in C++, using ncurses for the ‘terminal screen’ and SFML for audio. I'm using std::chrono for timers. This is the first time i've dealt with a game loop proper and a concept of time in my games. There is 1 game timer, which “ticks” every 5 seconds, and runs all my update functions. The (basic) problem I have now is I need all this to happen silently in the background, while the player goes about their business, navigating text menus etc. Right now as soon as the loop starts, the game is locked in the while loop and input is impossible. I assume I need some kind of “getscreen()” function that redraws whatever the player is looking at, and a “getinput()” function, to keep checking for a character input, but i'm not exactly sure how best to implement this without the screen constantly “locking”. Any advice would be appreciated. Current main is below, and just to give you an idea for what a “screen” is to me, an example menu
int main()
{
auto start_time = std::chrono::system_clock::now();
initscr(); --start ncurses
createMap();
gameMenu();
gameTick();
while (true)
{
auto end_time = std::chrono::system_clock::now();
std::chrono::duration<double> diff = end_time - start_time;
if (diff.count() > 5.0)
{
start_time = end_time;
g_gameTick++;
gameTick();
}
//getinput(), getscreen()?
}
return 0;
}
//example menu
void buildingsMenu(race* self)
{
clear();
title();
int line = LINE_START;
int pos = POS_START;
jprint("=== BUILDING MANAGER ===", line, pos); line += 3;
jprint("1. Shipyard", line, pos); line++;
jprint("(1000 Metal, 500 Steel)", line, pos); line += 3;
line = LINE_START;
pos = POS_START + 40;
jprint("=== UNDER CONSTRUCTION ===", line, pos); line += 3;
for (auto& i : self->getBuildingsUnderConstruction())
{
jprint(i.getName(), line, pos); pos += 10;
jprint("Completion Tick: ", line, pos); pos += 5;
jprint(i.completionTick(), line, pos);
line += 2; pos = POS_START + 40;
}
line = 20;
pos = POS_START;
jprint("> ", line, pos);
char c = input(); //"scanw"
switch (c)
{
case '1': building shipyard("Shipyard", 0, 5);
self->build(shipyard);
break;
}
}