I've been wondering about how everyone else does this. Is it possible to print messages from a vector every second while continuously loading more messages into the vector?
I admit I don't really understand how doing something like time(&start); works - I pretty much just modified what I found on the difftime C++ Reference page.
void Game::PrintMessages()
{
time_t start, end;
vector<string>::iterator iter;
iter = EventLog.begin();
while (true)
{
time(&start);
while (true)
{
time(&end);
double dif = difftime(end, start);
if (dif > waitTime) // if enough time has elapsed
break;
}
if (iter != EventLog.end())
{
cout << *iter << endl; // print a message
EventLog.erase(iter);
}
elsebreak;
}
}
As you can see, this requires that I've already stored all the events into the vector - I can't load anything while doing it this way. I don't really need to, but I'm curious.
It's not really a game - it's part of one of the beginner exercises I found on this site.
★ Modify the program to run in real time, with each turn lasting 2 seconds, and a one second pause between each announcement.
What I'm trying to figure out there was a way to make the messages (dependant on stuff happening in the program) update and display in timed intervals - assuming that there is a message.
I do have SFML installed for if I want to work with graphics, fancier UI, etc, but I'm still more used to the console at this point.
(Btw, is there anything you'd recommend for getting started with programming simplistic games? I get confused with concepts like game states, framerates, etc.. I've read through SFML tutorials, but I don't really understand that well.)
however, to use these functions effectively, you may have to use something like POSIX threads so your machine can do work (like adding to that vector - this may require a mutex) while it's sleeping.