CyGame::getActivePlayer() runs Out of Sync

Gaurav said:
Should I replace all calls from the mod to getSorenRandNum() with an alternative random number generator? There are plenty of those to choose from for python.
You can use them, but you shouldn't use them in if cases, if they depend on active player
 
Gaurav said:
Should I replace all calls from the mod to getSorenRandNum() with an alternative random number generator? There are plenty of those to choose from for python.

Since my mod doesn't alter gameplay, I don't see why I would need to use it at all. For example, who cares if after a reload you get a different unit name?

Edit: On second thought, it may be important that the other players generate the same random unit name.

Exactly as Caesium said. It really doesn't matter, just make sure you keep it similar on all machines. Even if the exact number generated doesn't matter, the fact that you actually went ahead and made the call does. It's probably more safe to use it than not to use it, since most code is probably going to be in the realm of "run on all machines" rather than the little bits of code that are run only on some of the machines. If you find code that is going to only run on one machine (such as if it's located somewhere within an if block that checks the getActivePlayer) then you should use a non-synchronous random number generator.

Caesium had a good idea for the Caesium mod, where if unsure about whether or not it's needed, use a sorenRandNum call, but do it early in the function, before you get into problems of possibly entering into computer-independent code such as if-blocks with getActivePlayer().
 
Gerikes said:
Exactly as Caesium said. It really doesn't matter, just make sure you keep it similar on all machines. Even if the exact number generated doesn't matter, the fact that you actually went ahead and made the call does. It's probably more safe to use it than not to use it, since most code is probably going to be in the realm of "run on all machines" rather than the little bits of code that are run only on some of the machines. If you find code that is going to only run on one machine (such as if it's located somewhere within an if block that checks the getActivePlayer) then you should use a non-synchronous random number generator.

Caesium had a good idea for the Caesium mod, where if unsure about whether or not it's needed, use a sorenRandNum call, but do it early in the function, before you get into problems of possibly entering into computer-independent code such as if-blocks with getActivePlayer().

Thanks again. Maybe I'll follow all the advice, fix it the best I can, check that it works in hotseat, and then publish a beta for volunteers to test.

Damn, I found a lot of calls to getActivePlayer() :sad:

I hope I will be able to find volunteers with a 2+ computer LAN setup. ;)
 
I've had two instances of civ running, by accident, but problems come up when alt-tabing between them. I can alttab all day long in and out of one instance of civ, but when I do it between to running civ4s thing just start getting weird, missing buttons, lags, hangups, and I have dual proccessors and it maxes both of them..
 
Hi, again.

I think you guys explained the sorenRand instance of CvRandom very well, and I suppose the ASyncRand instance we get from CyGlobalContext.getASyncRand() is fully asynchronous, so I guess I can use it as if it were Python's random number generator, only maybe faster or using less memory. But TheLopez is using CyGame.getMapRand() in his RandomNameUtils.py. What is the mapRand instance of CvRandom all about? Staring at the SDK source is giving me such a headache. :wallbash:
 
Gaurav said:
Hi, again.

I think you guys explained the sorenRand instance of CvRandom very well, and I suppose the ASyncRand instance we get from CyGlobalContext.getASyncRand() is fully asynchronous, so I guess I can use it as if it were Python's random number generator, only maybe faster or using less memory. But TheLopez is using CyGame.getMapRand() in his RandomNameUtils.py. What is the mapRand instance of CvRandom all about? Staring at the SDK source is giving me such a headache. :wallbash:

I'm not too sure why the two different sync RNG's, but I would guess that you have two so that the map RNG can have it's seed set to a value if you want to, say, have a game with the same map random seed (thus the map generator script will generate the exact same map) while still having a different synchronous RNG for other purposes, such as combat, random events and AI. I don't think using the map RNG over the soren RNG will make a big difference, as long as all computers use the same one at the same time.
 
Gerikes said:
I'm not too sure why the two different sync RNG's, but I would guess that you have two so that the map RNG can have it's seed set to a value if you want to, say, have a game with the same map random seed (thus the map generator script will generate the exact same map) while still having a different synchronous RNG for other purposes, such as combat, random events and AI. I don't think using the map RNG over the soren RNG will make a big difference, as long as all computers use the same one at the same time.

Ah yes the mapRand cannot be serialized (pickled in python parlance) and stored in a Civ4 savegame file, so it is probably synchronized when a new multiplayer game is started only and then either it is not saved at all or the sorenRand is pointed to it once the game has started.

It does not matter which, it won't work for unit naming, so I'll edit the RandomNameUtils.py to change the random number generator to sorenRand. I know that is only step 1.
 
Gaurav said:
Ah yes the mapRand cannot be serialized (pickled in python parlance) and stored in a Civ4 savegame file, so it is probably synchronized when a new multiplayer game is started only and then either it is not saved at all or the sorenRand is pointed to it once the game has started.

It does not matter which, it won't work for unit naming, so I'll edit the RandomNameUtils.py to change the random number generator to sorenRand. I know that is only step 1.

Actually, the map rand seed is stored in save game. Also interesting is how it works. This is from CvGame::read

Code:
	m_mapRand.read(pStream);
	m_sorenRand.read(pStream);

	[b]// --- SNIP ---[/b]

	if (isOption(GAMEOPTION_NEW_RANDOM_SEED))
	{
		if (!isNetworkMultiPlayer())
		{
			m_sorenRand.reseed(timeGetTime());
		}
	}

I guess this explains the difference between the two. On a saved game reload, the map rand will always stay the same, whereas the sorenRand will be reseeded if the option to get a new random seed on game load is on (there is some other place where they might be changed during the load that I don't know about).
 
Gerikes said:
Actually, the map rand seed is stored in save game. Also interesting is how it works. This is from CvGame::read

Code:
	m_mapRand.read(pStream);
	m_sorenRand.read(pStream);

	[b]// --- SNIP ---[/b]

	if (isOption(GAMEOPTION_NEW_RANDOM_SEED))
	{
		if (!isNetworkMultiPlayer())
		{
			m_sorenRand.reseed(timeGetTime());
		}
	}

I guess this explains the difference between the two. On a saved game reload, the map rand will always stay the same, whereas the sorenRand will be reseeded if the option to get a new random seed on game load is on (there is some other place where they might be changed during the load that I don't know about).

I can't imagine going through the trouble of maintaining an extra instance of CvRandom just for that.

I looked at the sync check and checksums and it seems like unit names aren't even checked. Maybe it does not even matter if they are different on each client.

I could be barking up the wrong tree trying to fix this.
 
Gaurav said:
Since I only have a single PC, I may only be able to use the simultaneous turns PBEM to test, which is far too tedious. Do you have any other ideas on how to test with a single PC? Perhaps if I turn down the graphics to the lowest settings, do you think it is possible to run two Civ4 clients on a single PC? Would that work any differently from the regular LAN configuration?

Sorry, bit old, but while looking through Firaxis site, I found the list of command line options available:

Firaxis Site said:
mod=foo // specify the modname
multiple // allow multiple civ instances to run
ini=foo // specify the ini file
/altroot=foo // specify alternate root for save files
/FXSLOAD=foo // specify file to load

So, I guess if you really want to try it, you can append the "multiple" command line option and have multiple instances : o)
 
Gerikes said:
Sorry, bit old, but while looking through Firaxis site, I found the list of command line options available:

So, I guess if you really want to try it, you can append the "multiple" command line option and have multiple instances : o)

Thanks, it sounds like it might actually work!
 
Gaurav said:
Thanks, it sounds like it might actually work!

Yes, it does. I just tried to start two games in windowed mode and run a multiplayer game, works fine.
But I recommend to have two displays for that.
Depending on your PC it might be very slow.

Matze
 
Yay, now I'm finally able to test my mod for multiplayer compatibility. :)
 
could anyone tell me in which "file" should i add this
multiple // allow multiple civ instances to run
line?
 
You have to start the game with a link like in your start menu.
The link should look like this:
"F:\Sid Meier's Civilization 4\Civilization4.exe" multiple

Matze
 
MatzeHH said:
You have to start the game with a link like in your start menu.
The link should look like this:
"F:\Sid Meier's Civilization 4\Civilization4.exe" multiple

Matze

Or, if you're starting a mod (and using the default install directory...)

"C:\Program Files\Firaxis Games\Sid Meier's Civilization 4\Civilization4.exe" multiple mod=\MyModName
 
Top Bottom