示例#1
0
文件: uqmdebug.c 项目: intgr/sc2-uqm
static void
tallySystemPostCallback (const STAR_DESC *star, const SOLARSYS_STATE *system,
		void *arg)
{
	UNICODE name[256];
	TallyResourcesArg *tallyResourcesArg = (TallyResourcesArg *) arg;
	FILE *out = tallyResourcesArg->out;

	GetClusterName (star, name);
	fprintf (out, "%s\t%d\t%d\n", name, tallyResourcesArg->mineralCount,
			tallyResourcesArg->bioCount);

	(void) star;  /* satisfy compiler */
	(void) system;  /* satisfy compiler */
}
示例#2
0
文件: uqmdebug.c 项目: intgr/sc2-uqm
void
dumpSystem (FILE *out, const STAR_DESC *star, const SOLARSYS_STATE *system)
{
	UNICODE name[256];
	UNICODE buf[40];

	GetClusterName (star, name);
	snprintf (buf, sizeof buf, "%s %s",
			bodyColorString (STAR_COLOR(star->Type)),
			starTypeString (STAR_TYPE(star->Type)));
	fprintf (out, "%-22s  (%3d.%1d, %3d.%1d) %-19s  %s\n",
			name,
			star->star_pt.x / 10, star->star_pt.x % 10,
			star->star_pt.y / 10, star->star_pt.y % 10,
			buf,
			starPresenceString (star->Index));

	(void) system;  /* satisfy compiler */
}
ERRORCODE NodeSimCodeGenerator::GenerateHeaderFile(std::fstream& fileHeader, INsCodeGenHelper* codeGenHelper, ICluster* cluster)
{
    //1. includes
    std::string headers;
    fileHeader << codeGenHelper->GetProtocolIncludesHeaderName(cluster) << std::endl;

    //2. cluster NameSpace;
    std::string clusterName = GetClusterName(cluster);

    fileHeader << defNameSpace << TAG_SPACE << clusterName << TAG_OPENFBRACE << std::endl;

    //3. Pdu namespace
    fileHeader << defNameSpace  <<" " <<"PDU" << TAG_OPENFBRACE <<std::endl;

    //4. Pdu Decl

    char chTemp[256];
    std::string pduName;
    std::map<UID_ELEMENT, IElement*> pduList;
    cluster->GetElementList(ePduElement, pduList);
    IPduCodeGenHelper* pduCodeGenHelper = codeGenHelper->GetPduCodeGenHelper();
    PduProps pduProps;
    for ( auto itrPdu : pduList )
    {
        IPdu* pdu = (IPdu*)(itrPdu.second);
        pdu->GetProperties(pduProps);
        fileHeader << pduCodeGenHelper->GetDecl(pdu) << std::endl;
        fileHeader << TAG_OPENFBRACE << std::endl;
        fileHeader << TAG_PUBLICSTART << std::endl;

        sprintf_s(chTemp, sizeof(chTemp), TAG_DATABYTEDECL, pduProps.m_unByteLength);
        fileHeader << chTemp;

        fileHeader << pduCodeGenHelper->GetBaseClassDecl(pdu) << std::endl;

        fileHeader << pduCodeGenHelper->GetSignalsDecl(pdu)<< std::endl;

        fileHeader << "};" << std::endl;

        pduName = pduCodeGenHelper->GetUniqueName(pdu);
        fileHeader << "typedef" << " " << "_" << pduName << " " << pduName <<TAG_SEMICOLON << std::endl;
    }

    //5. Endl Pdu namespace
    fileHeader << TAG_CLOSEFBRACE << std::endl;

    //6. Frame Namespace start
    fileHeader << defNameSpace <<" " <<"Frame" << TAG_OPENFBRACE <<std::endl;

    //7. Using namespace
    fileHeader <<"using namespace PDU;" << std::endl;

    //8. Class Decleration

    std::string frameName;
    std::map<UID_ELEMENT, IElement*> frameList;
    cluster->GetElementList(eFrameElement, frameList);
    IFrameCodeGenHelper* frameCodeGenHelper = codeGenHelper->GetFrameCodeGenHelper();
    std::map<IPdu*, PduInstanse> pduMap;
for ( auto itrPdu : frameList )
    {
        IFrame* frame = (IFrame*)(itrPdu.second);

        fileHeader << frameCodeGenHelper->GetDecl(frame) << std::endl;
        fileHeader << TAG_OPENFBRACE << std::endl;
        fileHeader << TAG_PUBLICSTART << std::endl;

        fileHeader << frameCodeGenHelper->GetBaseClassDecl(frame) << std::endl;

        fileHeader << frameCodeGenHelper->GetPdusDecl(frame)<< std::endl;

        pduMap.clear();
        frame->GetPduList(pduMap);
        if ( pduMap.size() == 0 )
        {
            fileHeader << frameCodeGenHelper->GetSignalsDecl(frame)<< std::endl;
        }

        fileHeader << "};" << std::endl;
    }

    //9. Endl Frame namespace
    fileHeader << TAG_CLOSEFBRACE << std::endl;

    //10. Endl cluster namespace
    fileHeader << TAG_CLOSEFBRACE << std::endl;

    //11. using namespaces
    fileHeader << "using namespace" << " " <<clusterName << "::" << "Frame" <<TAG_SEMICOLON << std::endl;
    fileHeader << "using namespace" << " " <<clusterName << "::" << "PDU" <<TAG_SEMICOLON << std::endl;

    return EC_SUCCESS;

}
示例#4
0
文件: orbits.c 项目: intgr/sc2-uqm
void
FillOrbits (SOLARSYS_STATE *system, BYTE NumPlanets,
		PLANET_DESC *pBaseDesc, BOOLEAN TypesDefined)
{ /* Generate Planets in orbit around star */
	BYTE StarColor, PlanetCount, MaxPlanet;
	BOOLEAN GeneratingMoons;
	COUNT StarSize;
	PLANET_DESC *pPD;
	struct
	{
		COUNT MinRockyDist, MinGasGDist;
	} Suns[] =
	{
		{DWARF_ROCK_DIST, DWARF_GASG_DIST},
		{GIANT_ROCK_DIST, GIANT_GASG_DIST},
		{SUPERGIANT_ROCK_DIST, SUPERGIANT_GASG_DIST},
	};
#ifdef DEBUG_ORBITS
UNICODE buf[256];
char stype[] = {'D', 'G', 'S'};
char scolor[] = {'B', 'G', 'O', 'R', 'W', 'Y'};
#endif /* DEBUG_ORBITS */

	pPD = pBaseDesc;
	StarSize = system->SunDesc[0].data_index;
	StarColor = STAR_COLOR (CurStarDescPtr->Type);

	if (NumPlanets == (BYTE)~0)
	{
#define MAX_GENERATED_PLANETS 9
		// XXX: This is pretty funny. Instead of calling RNG once, like so:
		//     1 + Random % MAX_GENERATED_PLANETS
		//   we spin in a loop until the result > 0.
		//   Note that this behavior must be kept to preserve the universe.
		do
			NumPlanets = LOWORD (RandomContext_Random (SysGenRNG))
					% (MAX_GENERATED_PLANETS + 1);
		while (NumPlanets == 0);
		system->SunDesc[0].NumPlanets = NumPlanets;
	}

#ifdef DEBUG_ORBITS
	GetClusterName (CurStarDescPtr, buf);
	log_add (log_Debug, "cluster name = %s  color = %c type = %c", buf,
			scolor[STAR_COLOR (CurStarDescPtr->Type)],
			stype[STAR_TYPE (CurStarDescPtr->Type)]);
#endif /* DEBUG_ORBITS */
	GeneratingMoons = (BOOLEAN) (pBaseDesc == system->MoonDesc);
	if (GeneratingMoons)
		MaxPlanet = FIRST_LARGE_ROCKY_WORLD;
	else
		MaxPlanet = NUMBER_OF_PLANET_TYPES;
	PlanetCount = NumPlanets;
	while (NumPlanets--)
	{
		BYTE chance;
		DWORD rand_val;
		COUNT min_radius, angle;
		SIZE delta_r;
		PLANET_DESC *pLocPD;

		do
		{
			rand_val = RandomContext_Random (SysGenRNG);
			if (TypesDefined)
				rand_val = 0;
			else
				pPD->data_index =
						(BYTE)(HIBYTE (LOWORD (rand_val)) % MaxPlanet);

			chance = PLANET_NEVER;
			switch (StarColor)
			{
				case BLUE_BODY:
					chance = BlueDistribution (pPD->data_index);
					break;
				case GREEN_BODY:
					chance = GreenDistribution (pPD->data_index);
					break;
				case ORANGE_BODY:
					chance = OrangeDistribution (pPD->data_index);
					break;
				case RED_BODY:
					chance = RedDistribution (pPD->data_index);
					break;
				case WHITE_BODY:
					chance = WhiteDistribution (pPD->data_index);
					break;
				case YELLOW_BODY:
					chance = YellowDistribution (pPD->data_index);
					break;
			}
		} while (LOBYTE (LOWORD (rand_val)) >= chance);

		if (pPD->data_index < FIRST_GAS_GIANT)
			min_radius = Suns[StarSize].MinRockyDist;
		else
			min_radius = Suns[StarSize].MinGasGDist;
RelocatePlanet:
		rand_val = RandomContext_Random (SysGenRNG);
		if (GeneratingMoons)
		{
			pPD->radius = MIN_MOON_RADIUS
					+ ((LOWORD (rand_val) % MAX_MOONS) * MOON_DELTA);
			for (pLocPD = pPD - 1; pLocPD >= pBaseDesc; --pLocPD)
			{
				if (pPD->radius == pLocPD->radius)
					goto RelocatePlanet;
			}
			pPD->NumPlanets = 0;
		}
		else
		{
			pPD->radius =
					(LOWORD (rand_val) % (MAX_PLANET_RADIUS - min_radius))
					+ min_radius;
			for (pLocPD = pPD - 1; pLocPD >= pBaseDesc; --pLocPD)
			{
				delta_r = UNSCALE_RADIUS (pLocPD->radius) / 5
						- UNSCALE_RADIUS (pPD->radius) / 5;
				if (delta_r < 0)
					delta_r = -delta_r;
				if (delta_r <= 1)
					goto RelocatePlanet;
			}
		}

		rand_val = RandomContext_Random (SysGenRNG);
		angle = NORMALIZE_ANGLE (LOWORD (rand_val));
		pPD->location.x = COSINE (angle, pPD->radius);
		pPD->location.y = SINE (angle, pPD->radius);
		pPD->rand_seed = MAKE_DWORD (pPD->location.x, pPD->location.y);

		++pPD;
	}

	{
		BYTE i;

		for (i = 0; i < PlanetCount; ++i)
		{
			BYTE j;

			for (j = (BYTE)(PlanetCount - 1); j > i; --j)
			{
				if (pBaseDesc[i].radius > pBaseDesc[j].radius)
				{
					PLANET_DESC temp;

					temp = pBaseDesc[i];
					pBaseDesc[i] = pBaseDesc[j];
					pBaseDesc[j] = temp;
				}
			}
		}
	}
}
ERRORCODE NodeSimCodeGenerator::GenerateCppFile(std::fstream& fileHeader, INsCodeGenHelper* codeGenHelper, ICluster* cluster)
{
    //1. Header path
    std::string dbAppPath;
    GetBusMasterDBCachePath(dbAppPath);
    std::string strChkSum;
    std::string headerfilePath;
    cluster->GetDBFileChecksum(strChkSum);

    char headerFilePath[MAX_PATH*2];
    headerfilePath = strChkSum + ".h";
    PathCombine(headerFilePath, dbAppPath.c_str(), headerfilePath.c_str());
    fileHeader <<"#include " << AddDoubleQuotes(headerFilePath) <<std::endl ;

    //2. namespace cluster
    std::string clusterName = GetClusterName(cluster);

    fileHeader <<defNameSpace <<" " << clusterName <<"{" <<std::endl ;

    //3. Cluster Id
    fileHeader << "unsigned long long g_strClusterPath = " <<"0x" << strChkSum  <<TAG_SEMICOLON << std::endl ;

    //4. Pdu namespace
    fileHeader << defNameSpace  <<" " <<"PDU" << TAG_OPENFBRACE <<std::endl;

    //5. pdu definition
	std::string pduName;
    std::map<UID_ELEMENT, IElement*> pduList;
    cluster->GetElementList(ePduElement, pduList);
    IPduCodeGenHelper* pduCodeGenHelper = codeGenHelper->GetPduCodeGenHelper();
    PduProps pduProps;
for ( auto itrPdu : pduList )
    {
        IPdu* pdu = (IPdu*)(itrPdu.second);
        fileHeader << pduCodeGenHelper->GetConstructorDef(pdu) <<":"  <<std::endl;
        fileHeader << pduCodeGenHelper->GetBaseClassConstructorDef(pdu) <<std::endl;
        fileHeader << pduCodeGenHelper->GetSignalsConstructorDef(pdu) << std::endl;
        fileHeader << TAG_OPENFBRACE << std::endl << TAG_CLOSEFBRACE <<std::endl;
    }

    //6. Endl Pdu namespace
    fileHeader << TAG_CLOSEFBRACE << std::endl;

    //7. Frame Namespace start
    fileHeader << defNameSpace <<" " <<"Frame" << TAG_OPENFBRACE <<std::endl;

    //8. Using namespace
    fileHeader <<"using namespace PDU;" << std::endl;

    //9. Frame definition

    std::string frameName;
    std::map<UID_ELEMENT, IElement*> frameList;
    std::map<IPdu*, PduInstanse> pduMap;
    cluster->GetElementList(eFrameElement, frameList);
    IFrameCodeGenHelper* frameCodeGenHelper = codeGenHelper->GetFrameCodeGenHelper();

for ( auto itrFrame : frameList )
    {
        IFrame* frame = (IFrame*)(itrFrame.second);
        fileHeader << frameCodeGenHelper->GetConstructorDef(frame) <<":"  <<std::endl;
        fileHeader << frameCodeGenHelper->GetBaseClassConstructorDef(frame) <<std::endl;
        fileHeader << frameCodeGenHelper->GetPdusConstructorDef(frame) << std::endl;

        pduMap.clear();
        frame->GetPduList(pduMap);
        if ( pduMap.size() == 0 )
        {
            fileHeader << frameCodeGenHelper->GetSignalsConstructorDef(frame) << std::endl;
        }

        fileHeader << TAG_OPENFBRACE << std::endl << TAG_CLOSEFBRACE <<std::endl;
    }

    //10. Endl Frame namespace
    fileHeader << TAG_CLOSEFBRACE << std::endl;

    //11. Cluster namespace
    fileHeader << TAG_CLOSEFBRACE << std::endl;


    return EC_SUCCESS;
}