Converting Python to C++

Joined
Sep 24, 2007
Messages
108
Location
Houston,TX
I have found a number of good mod components that include python changes, however when I merge them, the game slows down a lot :mad:

I know C++ is much faster than Python, so is there any way to convert some of the python code to C++? :confused: I have no idea how to go about doing this, so any suggestions are welcome.

Thanks in advance!
 
Most of it will be similar to an extent, aside from the obvious differences. Basically any Civ4 specific function you see used in Python is coming from C++ anyway so the function will be very similar if not identical. The biggest differences will be the syntax which is considerably different. I do it all the time though, heres a link to an example modcomp thread with the original author's python code and then my C++ code later in the thread.

http://forums.civfanatics.com/showthread.php?t=204847
 
My actual coding abilities are fairly limited, but I looked at your example and I think I might be able to figure that out. As far as finding which file to edit, is there any general file? Saw that in the example CvEventManager changes are made to CvPlayer. What about screen changes?
 
Hmm... well it takes some getting used to and sometimes a bit of searching through the files for specific functions to see where they were used. In the example I posted I knew where to put it because it was an action performed at the start of a player's turn which is handled in CvPlayer. Screen changes are one of the few mods that's best left in python since a lot of it has to be there anyway. A good rule is to look for loops (while ..., for ...) in the python code, if you don't see any loops you can probably leave it in python. Code that only has to run at infrequent intervals (such as the start of the game or specific turns or even random events) can normally stay in python too since they won't occur too often.
 
Back
Top Bottom