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

Ways to disable Python callbacks...

Discussion in 'Civ4 - SDK/Python' started by TC01, Dec 19, 2010.

  1. TC01

    TC01 Deity

    Joined:
    Jun 28, 2009
    Messages:
    2,216
    Location:
    Irregularly Online
    So, I was merging the new components of Sephi's BTS on Speed mod with FF+ (the components I hadn't already merged, that is).

    Most of the new things are just the removal of Python callbacks. Since Final Frontier (Plus) relies heavily on Python callbacks, and since I'd want to have them as options for modders, I was converting them to XML-defined callbacks.

    However, I noticed that there appear to be two different ways to do this. Sephi gave an example like the one below (and I was doing the same thing- this is one of the ones I added):

    Code:
    	if (GC.getDefineINT("USE_CANNOT_MAINTAIN_CALLBACK") == 1)
    	{
    		CyCity* pyCity = new CyCity((CvCity*)this);
    		CyArgsList argsList2; // XXX
    		argsList2.add(gDLL->getPythonIFace()->makePythonObject(pyCity));	// pass in city class
    		argsList2.add(eProcess);
    		argsList2.add(bContinue);
    		long lResult=0;
    		gDLL->getPythonIFace()->callFunction(PYGameModule, "cannotMaintain", argsList2.makeFunctionArgs(), &lResult);
    		delete pyCity;	// python fxn must not hold on to this pointer 
    		if (lResult == 1)
    		{
    			return false;
    		}
    	}
    However, the ones Firaxis added are slightly different. They look more like the sample that Afforess posted ages ago. in the CAR mod thread.

    The Firaxian ones use CvGlobals rather than GC.getDefineINT().

    The question I have is: is there a difference? I mean, there's definitely an implementation difference, but would this translate to a difference in speed?
     
  2. Asaf

    Asaf Sleep Deprived

    Joined:
    Mar 22, 2010
    Messages:
    1,326
    The CvGlobals implementation is just a local caching of the call to getDefineINT(), since getDefineINT() iterates the variables until it finds the correct one (look at CvGlobals::cacheGlobals()).
    So the answer is: using the CvGlobals cache should be slightly faster.
     
  3. TC01

    TC01 Deity

    Joined:
    Jun 28, 2009
    Messages:
    2,216
    Location:
    Irregularly Online
    Ah, thank you!

    I guess it's more advantageous to use the CvGlobals cache then.
     

Share This Page