Author Topic: Network Game Speed  (Read 2161 times)

Offline Hidiot

  • Hero Member
  • *****
  • Posts: 1018
Network Game Speed
« on: August 09, 2008, 03:55:33 AM »
There's something related to game speed I noticed and wonder if it's netfix related... but I'm more inclined to believe it's game-related:

Whilst playing multi player, the actual game speed would go down towards 4-5, sometimes 6. Now, if you change the game speed by one level and then change it back, you will get a temporary speed boost. The actual game speed climbs up to 7-8. And this whilst using a set game speed of 9. Like I said, it's temporary and will go back down pretty fast. But each time you repeat the process, you get a temporary speed boost.

Of course, when you get a lot of units and buildings, it will stay at 4-5 anyway :)

Something hints to me that after short periods of time, the actual game speed is kinda forced down to half of the selected game speed (the one you set).
"Nothing from nowhere, I'm no one at all"

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Network Game Speed
« Reply #1 on: August 09, 2008, 07:40:13 PM »
Most likely game related.

There are a number of things that affect game speed. Processor speed is obviously part of it. I've noticed that in single player, my computer will slow noticably if I maximize the window.

There are also a number of network factors. Most of the variables that balance command lag and game speed are just set to hard coded defaults, but we could try experimenting with them. If a CommandPacket for some player is not ready when it's needed, it will cause a wait, which will reduce the game speed. This depends not only on CPU speed, but also network lag. You can help to reduce the impact of network lag on game speed by increasing the command lag. Currently, a ComandPacket is executed every 4 ticks, and there is an additional delay of 4 ticks. This should allow about 5-8 ticks for a command to be sent over the network before it's needed for processing. If the packet reaches it's destination in that time, there will be no wait. We could change both the processing interval, and the delay. By delaying command processing longer, units will be slower to react to commands (at least in terms of game ticks, if not real time), but the game speed will be higher.

I've noticed there are usually quite a few waits caused whenever I check, which means there's probably reason to try tweaking these values. I've thought maybe we could add some interface to tweak these values in game. Changing some of them could cause some sync issues if it's not done right though.
 

Offline Hidiot

  • Hero Member
  • *****
  • Posts: 1018
Network Game Speed
« Reply #2 on: August 10, 2008, 02:07:24 AM »
Ok... CPU would make a more constant lagging and a pretty constant speed decrease. Network lag can be constant or variable.

But why, when you change the Game Speed by a unit, even if you change it from 9 to 8, the actual game speed shown in the net stats increases for a few seconds, while that actual game speed will always sit at 4-5 when it should stay at 7-8?

To make it clearer:
You could run a whole game with the speed set to 9 and the actual game speed shown in the net stats showing as 4-5

OR:

You could have someone change the game speed from 9 to 8 and 8 to 9 about once a minute or two and get an average actual game speed of 6-7.

I should mention the well-known fact that game speed decreasing starts from the moment you start. LR games are a good example: the speed goes down to 4-5 when you're still crawling towards a position.

Anyways... Since it's not a netfix-related topic, it should be put i nits own thread now...
"Nothing from nowhere, I'm no one at all"

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Network Game Speed
« Reply #3 on: August 10, 2008, 04:14:49 PM »
Because the game speed isn't calculated very accurately.

It seems the code that calculates game speed uses a few variables I'd left as unknowns. I suppose this might help determine what they are. At any rate though, they don't do a very good job of calculating game speed. Using two copies on the same computer, I get a consistent game speed of about 1 higher in one of the two copies. This would be impossible to maintain over anything but the very short term. Yet the different game speeds stayed about an average of 1 apart for as long as I watched them. This would suggest that the calculation is not very accurate.

I suspect the momentary spike in the displayed value is more of a flaw in the calculation than any increase in real game speed.

As of yet, I'm not entirely sure why this would happen.
 

Offline Hidiot

  • Hero Member
  • *****
  • Posts: 1018
Network Game Speed
« Reply #4 on: August 10, 2008, 04:32:18 PM »
I have tested it and it's not just a calculation flaw... the game really speeds up in those moments.
"Nothing from nowhere, I'm no one at all"

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Network Game Speed
« Reply #5 on: August 17, 2008, 01:18:57 AM »
You're quite right.

I spent some time looking at the code, and I think I know what's going on now. In multiplayer games, it will dynamically adjust the delay between ticks to account for network lag. However, there seems to be a slight flaw in the calculation, so that it tends to slightly less than half of what it should be at. Of course when you set the game speed, it will reset the real delay between ticks to the desired value, and it takes a bit of time for the algorithm to slow the game down to where it thinks it can properly hide the network lag.

I think I have a quick fix that should get games running at about the speed they should be at. Just NOP out the following instruction:

Code: [Select]
0049C3EC      FEC1             INC CL

That works out to file offset: 0x9B7EC
Just replace the two bytes FE C1, with the NOP bytes 90 90.

This fix should prevent your copy from artifically lowering the game speed to about a little less than half of what it should be at. I don't forsee any compatability issues if some people make this change and others don't. The game will probably just run at about the rate of the slowest person.

Btw, this has the potential to slightly increase choppyness. By slowing the game down, you don't experience network lag issues as much, so the game would run smoother. But increasing the speed, you tend to notice network delays more, so the game might become a little more jerky. If that happens, just set the game speed down yourself. Setting the speed to half of what it is with this patch should make it run at the same speed as it would have without this patch. Of course I didn't disable the speed adjusting algorithm, so it should still lower the game speed if it can't keep up, and try to smooth out the game play. It just shouldn't lower it by quite as much.
 

Offline Hidiot

  • Hero Member
  • *****
  • Posts: 1018
Network Game Speed
« Reply #6 on: August 17, 2008, 03:44:26 AM »
Nice work Hooman.

Now... let's see if I can force myself and learn how to patch the exe with this before someone else does  :)

Ok, so I managed to patch it... changed useing the guidelines, so I hope I made it right.


I'll attach the exe. It's the most recent .exe I know of, with unit limit included.
« Last Edit: August 17, 2008, 02:26:41 PM by Hidiot »
"Nothing from nowhere, I'm no one at all"

Offline Hooman

  • Administrator
  • Hero Member
  • *****
  • Posts: 4955
Network Game Speed
« Reply #7 on: August 17, 2008, 09:02:51 PM »
Err, wait, I forgot something. The exe is checksummed. So if not all the players have the patch, you will get checksum errors.

I tend to forget about that, since earlier versions had the exe checksum disabled. The newer versions didn't have much reason to disable it so we reenabled it.

Make sure everyone playing either has this patch, or they all don't have this patch.

 

Offline Hidiot

  • Hero Member
  • *****
  • Posts: 1018
Network Game Speed
« Reply #8 on: August 18, 2008, 02:05:16 AM »
I do that by standard, but thanks for letting us all know.


The patch works nicely and an occasional one or two disconnect boxes that last a few milliseconds on average once every two minutes is not as bad as playing the game at a crawl. The general game speed should be at around 7-8, or there'll generally be big problems with disconnect boxes.

Another big thank you to Hooman, people :)
"Nothing from nowhere, I'm no one at all"