Our attempt to implement Tetris in C++
internal_clock
description:The internal clock class consists of:
std::thread
object:
A thread is created and the clock "runs" inside of it. It is simply a combination of std::this_thread::sleep_for
internal_clock my_clock(std::chrono::milliseconds(200));
std::thread
)my_clock.run();
std::thread
object and make the private variable internal_clock::is_interval_elapsed
fire according to the set interval. You may check it with:my_clock.get_is_elapsed();
As of now, the game engine will have to regularly check the clock and may also use a sleep function, such as std::this_thread::sleep_for
, which misses the point of creating an independent clock. A possible (currently under consideration) solution is using a <condition_variable>
or <mutex>
. Although condition variables could indeed solve this problem, they cannot target specific threads. This might not cause any problem in this implementation, but, IMHO this is not a good pratice/solution. <mutex>
option was not yet thoroughly studied.
There are still some issues regarding expected behavior x actual implementation of some methods, but they will be addressed as the project evolves.