|
|
#1 |
|
Pacing (as in timing or delaying) in C++ console?
Hi,
I need to animate something in a C++ console application (it's a class assignment.) Right now I just print out all the frames back to back as quickly as possible, but it has two issues: 1 - Several "frames" end up being visible half drawn (I suppose we can call it a "screen tear".) 2 - The "frames" go by much too quickly on some (most) computers. What would be the best way of pacing in a C++ console application? I want it to be cross platform and not waste system resources (IE, locking the entire computer up during the animation would be undesirable.)
__________________
Battery Status - On the Mac App Store
The only app that'll estimate when your wireless devices will need their batteries changed. Like it on Facebook! |
|
|
|
0
|
|
|
#2 |
|
This is what I now have:
With my other headers: Code:
#if defined _WIN32 #include <windows.h> #else #include <unistd.h> #endif Code:
for (unsigned long i = 0, n = moves.size(); i < n; i++)
{
// ... code calculating position values
print(endX, endY, x, y); // function that prints a frame
#if defined _WIN32
Sleep(100);
#else
usleep(100000);
#endif
The output seems pretty nice, and usleep doesn't seem to block me from doing other things between frames. It remains to be seen whether the windows code also works.
__________________
Battery Status - On the Mac App Store
The only app that'll estimate when your wireless devices will need their batteries changed. Like it on Facebook! |
|
|
|
0
|
|
|
#3 | |
|
Quote:
That being said, in general you need to use a timer: http://gafferongames.com/game-physic...your-timestep/ http://www.gamedev.net/topic/626794-...ps-and-clocks/ I'd recommend using chrono for this: http://en.cppreference.com/w/cpp/chrono For more details, see: http://www.informit.com/articles/art...81386&seqNum=2 http://stackoverflow.com/a/5524138/859774 |
||
|
|
0
|
|
|
#4 |
|
All of that comes from C++11 which has only limited support on Windows, I thought.
|
|
|
|
0
|
|
|
#5 | |
|
Quote:
http://cpprocks.com/c11-compiler-sup...c-clang-intel/ There's only an issue with std::chrono::high_resolution_clock in VS11[*] -- you can either: (a) use the workaround here: http://stackoverflow.com/a/5524138/859774, (b) use Boost.Chrono -- http://www.boost.org/libs/chrono/ -- a fully compatible drop-in replacement, which also doesn't suffer from any issues (and will work with C++98 compilers). [*] upvote to make it higher priority: https://connect.microsoft.com/Visual...igh-resolution Last edited by N-M; Mar 18, 2013 at 08:06 AM. |
||
|
|
0
|
|
|
#6 |
|
Is it supported by Dev-C++/MinGW? That's what the TAs in class use to compile our submitted assignments.
|
|
|
|
0
|
|
|
#7 | |
|
Quote:
See the following for better alternatives: http://clicktobegin.net/programming/...dnt-use-dev-c/ If you're using one of the current and maintained versions (e.g., Orwell Dev-C++, or wxDev-C++), they should ship with a relatively recent GCC (MinGW is just a Windows port of GCC) and you should be just fine :-) |
||
|
|
0
|
|
|
#8 | |
|
Quote:
|
||
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 07:44 PM.







Linear Mode
