Destructor method for a multidimensional array

Drawmeus

Emperor
Joined
Jul 25, 2007
Messages
1,213
I'm working essentially off the following example in the existing code:

Code:
	if (m_ppiImprovementYieldChanges != NULL)
	{
		for (iI=0;iI<GC.getNumImprovementInfos();iI++)
		{
			SAFE_DELETE_ARRAY(m_ppiImprovementYieldChanges[iI]);
		}
		SAFE_DELETE_ARRAY(m_ppiImprovementYieldChanges);
	}

This is from the CvInfos.cpp entry for the CvCivicInfo, because the ImprovementYieldChanges stuff is similar to what I'm trying to do.

The hang-up I'm having is figuring out what value I should use for the array I've created in place of the "GC.getNumImprovementInfos()" component. I need to figure out the index of the last entry in this array.

I have a sneaking suspicion (from tracing GC.getNumImprovementInfos) that I'm going to have to add functions to keep count wherever the game reads in the XML, but I'm not really sure how I would go about doing that, because I couldn't really follow the code where the getNumImprovementInfos function does its work.



And for the true coders who read this, yes, my knowledge of C++ really is so uneven that I can get this far without knowing the answer to this.
 
If you're adding the TerrainYieldChanges, like I think you are, you need to use GC.getNumTerrainInfos() instead.

Basically, GC.getNumImprovementInfos() just counts the number of individual improvements in the XML, it's variable depending on the mod. GC.getNum_SOMETHING_Infos() all do the same thing, depending on the XML section in question.
 
Much appreciated. And yes, I'm continuing to bang on that small bit of modding I was talking about earlier.
 
In C++, an Array is a specific size, from the moment it is first created until it is destroyed. This makes looking up items in it much quicker, as long as those items were enumerated somewhere, but also wastes some memory space (since maybe you only wanted to store a single entry, but the array winds up being hundreds of elements long).

Thus, the reason this was size of GC.getNumImprovementInfos(), is because it was an array for improvements, so each space in the array corresponds to a single improvement.

There won't be any counting when you load the XML, just each item will get placed in the appropriate space in the array you are creating so it can be easily found at a later time.


What you are thinking of, where you would have to count as you load, would be what is known as a List in C++, Civ tends to avoid those for the most part, so no real need to worry about them.
 
My old C++ classes are starting to come back to me now... not that it will do me any good, because frankly they were just the first few programming courses my university offered. I had been spoiled on LUA and Python at work >.> and having four software engineers seated within 8 feet of my desk (I am distinctly NOT a software engineer) to answer questions in the rare case that I'm doing anything complex enough to need to ask.

P.s. CvInfos compiled successfully. Gonna try and run it when everything finishes compiling, then time to make this data actually do something ^_^ Thanks for all the help, and get kind of used to me, because frankly I need all the help I can get on this stuff.
 
Top Bottom