Page 1 of 1

Tweaking the programming...

PostPosted: Thu Aug 25, 2005 1:39 pm
by BeyondtheTech
One of my biggest concerns of a game of such magnitude (as in Battlestar, where a bunch of operations are going at every frame), is how GE handles math and logic operations.

Would the game increase in performance if I used Integers instead of Real variables? For instance, I have the shields set at 100.00%. Shields regeneration is based on the efficiency of another variable, the Shield Generator, and the speed of its repair is based on the Crew Complement. Imagine this with all the other functions of the Battlestar, such as Weapons, Engines, Hull, etc.. If I used all integers and started with a large number like 100000 and when it comes to display it, I just show the value divided by 1000, would that help any?

Also, I have a bunch of logic statements that are have multiple conditions and/or nested if's. Which one is theoretically faster?

Code: Select all
if (condition1)
{
   if (condition 2)
   {
      if (condition 3)
      {
         perform function;
      }
   }
}


or:
Code: Select all
if (condition1 && condition2 && condition3) perform function;


I'm assuming the first one would be faster, even though the code is longer, since it only has to perform the first condition test and bypass the rest. Then, it would have to be up to my logic to make sure I ask the right question (test) in the right order.

But, according to GE, which would perform better?

Thanks.

PostPosted: Thu Aug 25, 2005 1:42 pm
by willg101
I know this probably won't help, but I remember reading a C/C++ book, and it said that trying to shorten commands or make the computer do something through shorter commands doesn't nessescarily speed things up, but of course, I'm absolutely no expert, so my advice should be taken with a grain of salt...

Re: Tweaking the programming...

PostPosted: Thu Aug 25, 2005 2:01 pm
by makslane
BeyondtheTech wrote:Would the game increase in performance if I used Integers instead of Real variables?


I think that not

Which one is theoretically faster?

Code: Select all
if (condition1)
{
   if (condition 2)
   {
      if (condition 3)
      {
         perform function;
      }
   }
}


or:
Code: Select all
if (condition1 && condition2 && condition3) perform function;




The second code will be executed a little bit more fast

PostPosted: Thu Aug 25, 2005 6:53 pm
by ondy1985
Indeed. IF is a simple boolean operation and should not consume much of CPU cycles.

PostPosted: Thu Aug 25, 2005 9:38 pm
by Fuzzy
Another option, but one that would make the game itself larger, is to build lookup tables.

Either at the beginning of the game, or as part of the compiled game, you build an array containing a multiplication table, or division... or any sort of logic table..