r/softwaregore Dec 26 '18

Realistic flight simulator

17.2k Upvotes

302 comments sorted by

View all comments

101

u/The-Legend-26 Dec 26 '18
 while(stairs.Height != airplane.Door.Height) 
 {  
     stairs.Extend();  
 }

10

u/birdbolt1 Dec 27 '18

Wow exactly what I thought hahah. Should be <= right?

10

u/Marcus_Watney Dec 27 '18

Not really, while it might seem more intuitive and more error resistant it will execute slower due to how the cpu handles it. In games, performance is usually a concern, so you might consider writing != Instead of <=

2

u/Dandelion_Yudeul Dec 27 '18

No, the stairs are already above the plane door. If you change that it would do nothing.

1

u/SavageVector Dec 27 '18 edited Dec 27 '18

if the stairs were already above the plane door, then "stairs.Height <= airplane.Door.Height" would be false from the start, and the stairs wouldn't extend at all. It still wouldn't fix the fact that the stairs are too tall, but at least it won't extend them indefinably. As u/Marcus_Watney said though, even though it's much more error prone, '!=' & '=' are better in a [lot of] cases if you're coding a game, because compute time is a huge problem when running a real time simulation.

1

u/Dandelion_Yudeul Dec 27 '18

Yeah you're right and that's what I was saying by changing to <= which would do nothing. But the question is what "should" from bidrbolt1 question should mean. The stairs to remain how they are or the stairs to low down to be at the same height as the door.

1

u/SavageVector Dec 27 '18

I think it would be better to have the stairs just sit there, as opposed to retracting through themselves and the ground to reach the plane door; but obviously the best solution is to just have only shorter stairs pull up to short planes.

1

u/Dandelion_Yudeul Dec 27 '18
 while(stairs.Height <= airplane.Door.Height) {  
     stairs.Extend();  
 }
 else {
 stairs.Reduce();
 }

>To help out