1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

CyGame::getActivePlayer() runs Out of Sync

Discussion in 'Civ4 - Creation & Customization' started by Caesium, Jun 19, 2006.

  1. Caesium

    Caesium Radiant!

    Joined:
    Jan 14, 2006
    Messages:
    526
    You can use them, but you shouldn't use them in if cases, if they depend on active player
     
  2. Gerikes

    Gerikes User of Run-on Sentences.

    Joined:
    Jul 26, 2005
    Messages:
    1,753
    Location:
    Massachusetts
    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().
     
  3. Gaurav

    Gaurav Prince

    Joined:
    May 14, 2006
    Messages:
    402
    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. ;)
     
  4. Jeckel

    Jeckel Great Reverend

    Joined:
    Nov 16, 2005
    Messages:
    1,637
    Location:
    Peoria, IL
    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..
     
  5. Gaurav

    Gaurav Prince

    Joined:
    May 14, 2006
    Messages:
    402
    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:
     
  6. Gerikes

    Gerikes User of Run-on Sentences.

    Joined:
    Jul 26, 2005
    Messages:
    1,753
    Location:
    Massachusetts
    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.
     
  7. Gaurav

    Gaurav Prince

    Joined:
    May 14, 2006
    Messages:
    402
    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.
     
  8. Gerikes

    Gerikes User of Run-on Sentences.

    Joined:
    Jul 26, 2005
    Messages:
    1,753
    Location:
    Massachusetts
    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).
     
  9. Gaurav

    Gaurav Prince

    Joined:
    May 14, 2006
    Messages:
    402
    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.
     
  10. Gerikes

    Gerikes User of Run-on Sentences.

    Joined:
    Jul 26, 2005
    Messages:
    1,753
    Location:
    Massachusetts
    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)
     
  11. Gaurav

    Gaurav Prince

    Joined:
    May 14, 2006
    Messages:
    402
    Thanks, it sounds like it might actually work!
     
  12. MatzeHH

    MatzeHH Warlord

    Joined:
    Jan 8, 2006
    Messages:
    210
    Location:
    Germany
    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
     
  13. Teg_Navanis

    Teg_Navanis King

    Joined:
    Jan 21, 2006
    Messages:
    737
    Yay, now I'm finally able to test my mod for multiplayer compatibility. :)
     
  14. mrgenie

    mrgenie King

    Joined:
    Feb 28, 2002
    Messages:
    830
    could anyone tell me in which "file" should i add this
    multiple // allow multiple civ instances to run
    line?
     
  15. MatzeHH

    MatzeHH Warlord

    Joined:
    Jan 8, 2006
    Messages:
    210
    Location:
    Germany
    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
     
  16. Gerikes

    Gerikes User of Run-on Sentences.

    Joined:
    Jul 26, 2005
    Messages:
    1,753
    Location:
    Massachusetts
    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
     

Share This Page