Where are the read/write methods for CvTerrain?

Voyhkah

Undead
Joined
Apr 25, 2009
Messages
1,444
Location
Earth
I was just adding two new XML tags for my mod, but I was unable to locate the ::Read and ::Write tags\. I found the tag "bool CvTerrainInfo::Read(CvXMLLoadUtility* pXML)", which, reads the XML file (right?). But the read method that reads saves and the write method that writes them, I could not find. Does anyone know where they are?
 
for many objects in CvInfos they do not exist. Those read and write methods are only used for one gameplay option anyway so personally I allways ignore them when adding tags.
 
Many people have complained the game crashes while loading a saved game, when they are working on sdk mods. Many times the problem turns out to be that the read and write functions had fields in different orders. For example, a field was read but not written, or two fields were written in one order and read in the opposite order. So, I am not sure I agree with the suggestion to ignore the read and write functions. In this particular case when there are no read or write functions I agree that is fine. But in general if a class has read/write, I feel it is important to update with your new fields.
 
Aaaahhhhh.
 
Many people have complained the game crashes while loading a saved game, when they are working on sdk mods. Many times the problem turns out to be that the read and write functions had fields in different orders. For example, a field was read but not written, or two fields were written in one order and read in the opposite order. So, I am not sure I agree with the suggestion to ignore the read and write functions.
yeah, exactly that's why I am not modifying read/write methods in CvInfos anymore. Net effect is a lot less possible bugs without any loss for me.

In this particular case when there are no read or write functions I agree that is fine. But in general if a class has read/write, I feel it is important to update with your new fields.

well, whatever works for you is great :goodjob:
 
yeah, exactly that's why I am not modifying read/write methods in CvInfos anymore. Net effect is a lot less possible bugs without any loss for me.

Are you sure that your fields are stored in savegames? As opposed to being reset to zero or garbage?
 
Are you sure that your fields are stored in savegames? As opposed to being reset to zero or garbage?

AFAIK read/write for CvInfos (unlike units, cities, players etc.) are not used when saving games - I tried it once with a breakpoint and it wasn't called there.
I always assumed it was related to the cache...
 
Are you sure that your fields are stored in savegames? As opposed to being reset to zero or garbage?

they work exactly the same way the tags in CvTerrain work. They aren't saved in savegames, but they are loaded from XML everytime you load the mod.
 
OK, so for cvinfos, they are read from the xml every time, and there aren't any binary read/write functions anyway. The same is true for cvterrains. All of those are constant across any savegame of the mod. However, things like units, need to store different information during the game. So it is still critical to update the binary read/write functions for this type of thing. Does that cover everything?
 
yes. basically in cvinfos.cpp you don't have to modify read/write functions, in all other files you have to if such a function exists.
 
I have a stupid-ish question for you: What are read/write functions? I bet this is common knowledge for anyone working with C++ and I can't claim to belong to this category. But in the spirit of learning more - could someone explain this concept is some depth - or perhaps point to a entry-level online source for said information?
 
when you save or load a game, some information is written/read from a savegame. This is all done in the dll in the so called read/write functions.
 
So all (or most) classes have these function then? Because the OP was about finding the r/w functionality of specifically CvTerrain. One would except there to be read/write functions in CvUnit, CvCity and so on?
 
Yes, most classes in Civ's DLL have both a read() and a write() method.
For classes such as CvCity, CvUnit it's used for saved games.

Some (mainly all the Cv*Info classes) have more than one read() method - to read from the XML or from a binary stream.
 
Back
Top Bottom