Uniformisation des FPS & constante PHYSICS_TIME => FRAME_TIME
This commit is contained in:
		
							parent
							
								
									1e796855b7
								
							
						
					
					
						commit
						d83fdb18fd
					
				|  | @ -11,26 +11,6 @@ namespace Constants { | |||
|      */ | ||||
|     static const float ATTRACTION = 2000000; | ||||
| 
 | ||||
|     /**
 | ||||
|      * Constante de déplacement. Définit la quantité de | ||||
|      * mouvement qui est donnée à un objet lorsqu'il | ||||
|      * est manipulé manuellement par le joueur | ||||
|      */ | ||||
|     static const float MOVE = 200; | ||||
| 
 | ||||
|     /**
 | ||||
|      * Constante de gravité. Utilisée dans la formule | ||||
|      * pour calculer la force de gravité appliquée | ||||
|      * uniformément vers le bas de la fenêtre sur tous | ||||
|      * les objets | ||||
|      */ | ||||
|     static const float GRAVITY = 235; | ||||
| 
 | ||||
|     /**
 | ||||
|      * Durée fixe d'une étape de simulation physique | ||||
|      */ | ||||
|     static const sf::Time PHYSICS_TIME = sf::seconds(1.f / 60); | ||||
| 
 | ||||
|     /**
 | ||||
|      * Correction positionnelle : pourcentage de correction | ||||
|      * et seuil de correction | ||||
|  |  | |||
|  | @ -30,6 +30,16 @@ public: | |||
|      */ | ||||
|     enum class Modifier {CONTROL, ALT, SHIFT, SYSTEM}; | ||||
| 
 | ||||
|     /**
 | ||||
|      * Taux maximal de frames par seconde | ||||
|      */ | ||||
|     static const unsigned int FPS; | ||||
| 
 | ||||
|     /**
 | ||||
|      * Temps idéal entre deux frames | ||||
|      */ | ||||
|     static const sf::Time FRAME_TIME; | ||||
| 
 | ||||
|     Manager(); | ||||
| 
 | ||||
|     /**
 | ||||
|  |  | |||
|  | @ -38,7 +38,7 @@ void Editor::begin() { | |||
|     Level::begin(); | ||||
| 
 | ||||
|     getResourceManager().playMusic("editor.ogg"); | ||||
|     getWindow().setFramerateLimit(60); | ||||
|     getWindow().setFramerateLimit(Manager::FPS); | ||||
| } | ||||
| 
 | ||||
| void Editor::processEvent(const sf::Event& event) { | ||||
|  |  | |||
|  | @ -48,7 +48,7 @@ void Game::frame() { | |||
|     if (current_time >= next_frame_time) { | ||||
|         // si nous sommes en retard ou dans les temps
 | ||||
|         // on replanifie la prochaine frame
 | ||||
|         next_frame_time += Constants::PHYSICS_TIME; | ||||
|         next_frame_time += Manager::FRAME_TIME; | ||||
| 
 | ||||
|         // on met à jour la physique d'un cran temporel,
 | ||||
|         // si on est en mode normal
 | ||||
|  |  | |||
|  | @ -152,7 +152,7 @@ void Level::draw() { | |||
|     // animation de la rotation de la caméra
 | ||||
|     float goal = std::fmod((float) gravity_direction * 90, 360); | ||||
|     float diff = goal - camera_angle; | ||||
|     float speed = diff * Constants::PHYSICS_TIME.asSeconds() * 5; | ||||
|     float speed = diff * Manager::FRAME_TIME.asSeconds() * 5; | ||||
| 
 | ||||
|     if (std::abs(diff) < .05f) { | ||||
|         camera_angle = goal; | ||||
|  |  | |||
|  | @ -1,5 +1,8 @@ | |||
| #include "manager.hpp" | ||||
| 
 | ||||
| const unsigned int Manager::FPS = 60; | ||||
| const sf::Time Manager::FRAME_TIME = sf::seconds(1.f / Manager::FPS); | ||||
| 
 | ||||
| Manager::Manager() : window( | ||||
|     sf::VideoMode(704, 480), "Skizzle", sf::Style::Default, | ||||
|     sf::ContextSettings(0, 0, 2) | ||||
|  |  | |||
|  | @ -12,7 +12,7 @@ void Menu::begin() { | |||
|     loadMainMenu(); | ||||
| 
 | ||||
|     getResourceManager().playMusic("menu.ogg"); | ||||
|     getWindow().setFramerateLimit(60); | ||||
|     getWindow().setFramerateLimit(Manager::FPS); | ||||
| } | ||||
| 
 | ||||
| void Menu::processEvent(const sf::Event& event) { | ||||
|  |  | |||
|  | @ -131,11 +131,11 @@ sf::Vector2f Object::getForces(const Level& level) const { | |||
| 
 | ||||
| void Object::updateVelocity(const Level& level) { | ||||
|     acceleration = getForces(level) * getMassInvert(); | ||||
|     velocity += acceleration * Constants::PHYSICS_TIME.asSeconds(); | ||||
|     velocity += acceleration * Manager::FRAME_TIME.asSeconds(); | ||||
| } | ||||
| 
 | ||||
| void Object::updatePosition() { | ||||
|     position += velocity * Constants::PHYSICS_TIME.asSeconds(); | ||||
|     position += velocity * Manager::FRAME_TIME.asSeconds(); | ||||
| } | ||||
| 
 | ||||
| bool Object::detectCollision(const Object& obj, CollisionData& data) const { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue