0
\$\begingroup\$

I am making a real time strategy game in XNA. I have separated the Client (rendering, input, sound) code from the Sim (game logic).

I want to have features like replaying and fast forwarding. Also, I would like to give the Sim longer time intervals in its Update to finish its work without having to always implement time slicing to prevent frame rate stuttering. I imagine I can do this when the two systems become decoupled and have their own update frequency.

So, how can I run the Client and Sim at two different update intervals? How should I code it?

Currently I am running with FixedTimeStep = false and using ElapsedGameTime in Update() computations. Can I create new GameTime instances to leverage this existing code..?

\$\endgroup\$
2
  • \$\begingroup\$ I would try something like that : *note that I normally use Managers, and manually handle the update/draw, etc, and dont use a gamecomponent iherited class. if you do it might require a little more work. simple put, I'd place an IF statement before the manager's update. If it pass the condition ( something like : if elapseGameTime%10 = 0 depending on the speed you want) you update, else you skip it. I normally have a speed variable for units movement and anima \$\endgroup\$ – Thierry Savard Dec 9 '13 at 16:14
  • \$\begingroup\$ So I can create a new GameTime object with the elapsed value that I want..? I will need it for my replay feature as well because each frame has a variable duration. \$\endgroup\$ – Rye bread Dec 9 '13 at 23:19
1
\$\begingroup\$

you dont need to use another gameTime object, since its just a clock. you just have to build yourself different timer.

there might be easier/better way to do it, but since I dont know them, here how i'd try 1st.

What you want to update base on a different elapse time. just use different variable for when you want your update. lets set update speed for replay to 1/10 of normal (normal = 60 times per second, so once about each 16.66 elapseGameTime, lets say 15 to be safe. you want 10x that, roughly so about once each 150 ms )

bool replayMode = True;
int UpdateSpeed = 170;
double elapseTimer ;

public override void Update(gameTime GameTime)
{
   elapseTimer += GameTime
   if (replayMode)
     UpdateSpeed = 150;
   else
     UpdateSpeed = 15;
   if (elapseTimer > UpdateSpeed ){
        elapseTimer = 0 ;
        foreach (Manager manager in MyManagerList) {           
            manager.UPDATE();
         }
   }
}

Since elapseGameTime will reset to 0 after each update, you can set updateSpeed base on different value you want. Might not be perfect, but it should help you get started.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.