libs/GameSimulator.cpp
/**
	 * @brief This function provide space for doing handle input on all the entities.
	 *
	 * @param delta The time difference between two frames
	 */
@brief This function provide space for doing handle input on all the entities.
@param delta The time difference between two frames
@brief This function provide space for doing handle input on all the entities . @param delta The time difference between two frames
void GameSimulator::handle_input(float delta) {
		sf::Event event;
		while (resource_store->window.pollEvent(event)) {
			if (sf::Event::Closed == event.type) {
				resource_store->machine.add_state(StateRef(new GameOverState(resource_store)), true);
			}
			if (sf::Keyboard::isKeyPressed(sf::Keyboard::Q)) {
				std::cout << "Exiting ClientState" << std::endl;
				resource_store->machine.add_state(StateRef(new MainMenuState(resource_store)), true);
			}
			if(sf::Keyboard::isKeyPressed(sf::Keyboard::U)) {
				generate_log();
			}
			if (sf::Keyboard::isKeyPressed(sf::Keyboard::B)) {
				if(pool.max_pool_size > pool.obj_made){
					bullet = pool.getObject(resource_store, 5);
					bullet->init(players_map.at(main_player_id).e_position);
					bullet_set[current].insert(bullet);
				}
			}
		}
		AI_bot_output();
		update_controllable(delta);
		if (players_map.at(main_player_id).e_speed.z > 0)
			score += delta * (players_map.at(main_player_id).e_speed.z);
		map.bound_entity(main_camera);
		for (auto &player_i : players_map) {
			map.bound_entity(player_i.second);
		}
		int i=0;
		for (auto itr : bullet_set[current]){
			async_update[i] = std::async(update_bullets, itr,&map,&delta);
			i++;
		}
		for(int i=0; i<bullet_set[current].size(); i++) {
			async_update[i].get();
		}
		std::vector<Car *> entities = get_entity_list();
		Collision::simulate_physics(entities, map);
		for(auto &b: players_map){
			if (b.first == main_player_id)continue;
				for (auto itr : bullet_set[current])
				{
					if (itr->e_position.z - players_map.at(main_player_id).e_position.z > 10000)
						itr->in_use = false;
					collision.handle_collision(*itr, b.second, map, 0);
					if (itr->in_use)
						bullet_set[!current].insert(itr);
					else
						pool.returnObject(itr);
				}
			bullet_set[current].clear();
			current = !current;
		}
		bar.percentage = (players_map.at(main_player_id).health);
		text[1].setString(std::to_string(score));
	}
void GameSimulator :: handle_input ( float delta ) { sf :: Event event ; while ( resource_store -> window . pollEvent ( event ) ) { if ( sf :: Event :: Closed == event . type ) { resource_store -> machine . add_state ( StateRef ( new GameOverState ( resource_store ) ) , true ) ; } if ( sf :: Keyboard :: isKeyPressed ( sf :: Keyboard :: Q ) ) { std :: cout << " " << std :: endl ; resource_store -> machine . add_state ( StateRef ( new MainMenuState ( resource_store ) ) , true ) ; } if ( sf :: Keyboard :: isKeyPressed ( sf :: Keyboard :: U ) ) { generate_log ( ) ; } if ( sf :: Keyboard :: isKeyPressed ( sf :: Keyboard :: B ) ) { if ( pool . max_pool_size > pool . obj_made ) { bullet = pool . getObject ( resource_store , 5 ) ; bullet -> init ( players_map . at ( main_player_id ) . e_position ) ; bullet_set [ current ] . insert ( bullet ) ; } } } AI_bot_output ( ) ; update_controllable ( delta ) ; if ( players_map . at ( main_player_id ) . e_speed . z > 0 ) score += delta * ( players_map . at ( main_player_id ) . e_speed . z ) ; map . bound_entity ( main_camera ) ; for ( auto & player_i : players_map ) { map . bound_entity ( player_i . second ) ; } int i = 0 ; for ( auto itr : bullet_set [ current ] ) { async_update [ i ] = std :: async ( update_bullets , itr , & map , & delta ) ; i ++ ; } for ( int i = 0 ; i < bullet_set [ current ] . size ( ) ; i ++ ) { async_update [ i ] . get ( ) ; } std :: vector < Car * > entities = get_entity_list ( ) ; Collision :: simulate_physics ( entities , map ) ; for ( auto & b : players_map ) { if ( b . first == main_player_id ) continue ; for ( auto itr : bullet_set [ current ] ) { if ( itr -> e_position . z - players_map . at ( main_player_id ) . e_position . z > 10000 ) itr -> in_use = false ; collision . handle_collision ( * itr , b . second , map , 0 ) ; if ( itr -> in_use ) bullet_set [ ! current ] . insert ( itr ) ; else pool . returnObject ( itr ) ; } bullet_set [ current ] . clear ( ) ; current = ! current ; } bar . percentage = ( players_map . at ( main_player_id ) . health ) ; text [ 1 ] . setString ( std :: to_string ( score ) ) ; }
@brief This function provide space for doing handle input on all the entities.
@brief This function provide space for doing handle input on all the entities .
//Score done. // for (auto itr : bullet_set[current]){ // 	map.bound_entity(*itr); // 	itr->update_car(delta, map.lines, map.getSegL()); // } // for(int i=0;i<bullet_set[current].size();i++){ // Collision working // std::cout << "CAR health" << players_map.at(main_player_id).health << std::endl;