Jump to content
  • Advertisement
Sign in to follow this  
Prog101

cut large code to smaller code

This topic is 3901 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am using C and windows, i have the following code , this is just a snipit there is loads more all in the same format, can i make a function to handle all this
		name = pVehicleData->pCarInfo[pEntrantData->pEntrants.chassis].name;
		for(j = 0; j < gNumberOfChassis; j++)
		{
			if (name == gStringTable[ST_Chassis+j])
			{
				goto donechassis;

			}
		}
		gStringTable[ST_Chassis+gNumberOfChassis] = name;
		Chassis2ChassisIdMap[gNumberOfChassis] = pEntrantData->pEntrants.chassis;
		gNumberOfChassis++;
donechassis:

		name = pVehicleData->pEngineInfo[pEntrantData->pEntrants.engine].name;
		for(j = 0; j < gNumberOfEngines; j++)
		{
			if (name == gStringTable[ST_Engines+j])
			{
				goto doneengine;
			}
		}
		gStringTable[ST_Engines+gNumberOfEngines] = name;
		Engine2EngineIdMap[gNumberOfEngines] = pEntrantData->pEntrants.engine;
		gNumberOfEngines++;
doneengine:


		name = pVehicleData->pTyreInfo[pEntrantData->pEntrants.tyre].name;
		for(j = 0; j < gNumberOfTyres; j++)
		{
			if (name == gStringTable[ST_Tyres+j])
			{
				goto donetyre;
			}
		}
		gStringTable[ST_Tyres+gNumberOfTyres] = name;
		Tyre2TyreIdMap[gNumberOfTyres] = pEntrantData->pEntrants.tyre;
		gNumberOfTyres++;
donetyre:

Share this post


Link to post
Share on other sites
Advertisement
could i not do something like


void SetArrayMaps(const char* cName, int iNum, int *iSize, _StringID sID, int* iArray)
{
int i;
for(i = 0; i < iSize; i++)
{
if (cName == gStringTable[sID+i])
{
return;

}
}
gStringTable[sID+iSize] = cName;
iArray[iSize] = iNum;
iSize++;
}



but i get an error for

gStringTable[sID+iSize] = cName;

error = error C2107: illegal index, indirection not allowed

[Edited by - Prog101 on September 19, 2007 5:38:18 AM]

Share this post


Link to post
Share on other sites
It's because iSize is a pointer to an integer.
Don't you mean something like
gStringTable[sID+(*iSize)] = cName;

Share this post


Link to post
Share on other sites
Quote:
Original post by Prog101
I am using C and windows, i have the following code , this is just a snipit there is loads more all in the same format, can i make a function to handle all this

*** Source Snippet Removed ***


Uh... what the hell are you doing?

Why would you build a "string table" using strings that are already stored within the objects? (Keeping in mind that your table doesn't really store the strings, but simply copies the pointers?)

Why would you merge all the names into one "string table" - using some magic offsets - instead of separate ones?

As for your attempt - why would you pass 'iSize' by pointer?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!