Tetris: move generating of new blocks after restart to main thread

This commit is contained in:
zvon 2020-09-26 20:13:27 +02:00
parent 96c54454f7
commit 883ad19a50
2 changed files with 5 additions and 4 deletions

View File

@ -121,10 +121,6 @@ void resetGame() {
g_main_scene->setPrevTicks( SDL_GetTicks() ); g_main_scene->setPrevTicks( SDL_GetTicks() );
// TODO maybe move to main thread // TODO maybe move to main thread
g_next_object = g_tetrisFunctions[std::rand() / ( ( RAND_MAX + 1u ) / 7 )](
g_main_scene->getRendererShared(), g_main_scene );
g_next_object->setPos( 0.9, 0.5 );
g_active_scenes.push_back( g_main_scene );
g_active_scenes = {g_main_scene}; g_active_scenes = {g_main_scene};
g_input_functions = {mainSceneInput}; g_input_functions = {mainSceneInput};
for(int i = 0; i < 7; i++) for(int i = 0; i < 7; i++)

View File

@ -89,6 +89,11 @@ int main() {
SDL_framerateDelay( &gFPS ); SDL_framerateDelay( &gFPS );
if ( !g_cur_object && g_checked_line ) { if ( !g_cur_object && g_checked_line ) {
std::lock_guard< std::mutex > guard( g_movement_mutex ); std::lock_guard< std::mutex > guard( g_movement_mutex );
if ( !g_next_object ) {
g_next_object = g_tetrisFunctions[std::rand() / ( ( RAND_MAX + 1u ) / 7 )](
g_main_scene->getRendererShared(), g_main_scene );
g_next_object->setPos( 0.9, 0.5 );
}
g_cur_object = g_next_object; g_cur_object = g_next_object;
g_cur_object->setPos( 0.5, TOP_BORDER - BLOCK_SIZE ); g_cur_object->setPos( 0.5, TOP_BORDER - BLOCK_SIZE );