void GenerateTopology (CUniverse &Universe, CXMLElement *pCmdLine) { int i, j, k; int iCount = pCmdLine->GetAttributeIntegerBounded(COUNT_SWITCH, 1, -1, 1); STopologyStats Stats; for (k = 0; k < iCount; k++) { if (iCount > 1) printf("sample %d", k+1); TSortMap<CString, SNodeInfo> NodeData; TSortMap<CString, int> AttribCount; // Initialize the topology CString sError; Universe.GetFirstTopologyNode(); // Loop over all nodes for (i = 0; i < Universe.GetTopologyNodeCount(); i++) { CTopologyNode *pNode = Universe.GetTopologyNode(i); SNodeInfo *pNewNode = NodeData.Insert(pNode->GetID()); pNewNode->sID = pNode->GetID(); pNewNode->sName = pNode->GetSystemName(); pNewNode->dwSystemUNID = pNode->GetSystemDescUNID(); pNewNode->sAttribs = pNode->GetAttributes(); // Add the attributes in this node to the list of // attributes for this try. TArray<CString> Attribs; ParseAttributes(pNewNode->sAttribs, &Attribs); for (j = 0; j < Attribs.GetCount(); j++) { int *pCount = AttribCount.GetAt(Attribs[j]); if (pCount == NULL) { pCount = AttribCount.Insert(Attribs[j]); *pCount = 0; } *pCount = (*pCount) + 1; } } // Compute topology stats // Add the node count for this try Stats.NodeCount.Insert(NodeData.GetCount()); // Loop over all attributes that we know about. If one doesn't // exist in this try, then we set its min to 0 if (k > 0) { for (i = 0; i < Stats.Attribs.GetCount(); i++) { if (AttribCount.GetAt(Stats.Attribs.GetKey(i)) == NULL) Stats.Attribs[i].SetMin(0); } } // Loop over all attributes in this try and add them to the stats SStat *pAttribStat; for (i = 0; i < AttribCount.GetCount(); i++) { // If we have some attributes that no other try had, then // that means that the minimum value is 0. if (pAttribStat = Stats.Attribs.GetAt(AttribCount.GetKey(i))) pAttribStat->Insert(AttribCount[i]); else { pAttribStat = Stats.Attribs.Insert(AttribCount.GetKey(i)); pAttribStat->Insert(AttribCount[i]); if (k > 0) pAttribStat->SetMin(0); } } // Output all the nodes if (iCount == 1) { printf("Node\tSystemType\tName\tStargates\tAttributes\n"); for (i = 0; i < NodeData.GetCount(); i++) { SNodeInfo *pNode = &NodeData.GetValue(i); printf("%s\t%08x\t%s\t%d\t%s\n", pNode->sID.GetASCIIZPointer(), pNode->dwSystemUNID, pNode->sName.GetASCIIZPointer(), pNode->Stargates.GetCount(), pNode->sAttribs.GetASCIIZPointer()); } } else { Universe.Reinit(); printf("\n"); } } // Output stats if (iCount > 0) { printf("\n"); printf("STATS\n\n"); Stats.NodeCount.Print(CONSTLIT("Nodes"), iCount, Stats.NodeCount.GetAverage(iCount)); printf("\n"); printf("ATTRIBS\n\n"); for (i = 0; i < Stats.Attribs.GetCount(); i++) Stats.Attribs[i].Print(Stats.Attribs.GetKey(i), iCount, Stats.NodeCount.GetAverage(iCount)); printf("\n"); } }
void TestUpdate (CUniverse &Universe, CXMLElement *pCmdLine) { int i; int iTrial; TArray<DWORD> Trials; DWORD dwLastAverage; // How many tests int iCount = pCmdLine->GetAttributeInteger(CONSTLIT("count")); if (iCount == 0) iCount = 1; // How long do we update int iUpdateCount = pCmdLine->GetAttributeInteger(CONSTLIT("updateCount")); if (iUpdateCount == 0) iUpdateCount = DEFAULT_UPDATE; // Create the fist system for (iTrial = 0; iTrial < iCount; iTrial++) { TArray<SSample> Timings; printf("Trial: %d\n", iTrial + 1); // Initialize the universe CString sError; if (Universe.InitGame(0, &sError) != NOERROR) { printf("ERROR: %s", sError.GetASCIIZPointer()); return; } // Create the first system CTopologyNode *pNode = Universe.GetFirstTopologyNode(); if (pNode == NULL) { printf("ERROR: Cannot find first node.\n"); return; } CSystem *pSystem; if (Universe.CreateStarSystem(pNode, &pSystem) != NOERROR) { printf("ERROR: Unable to create star system.\n"); return; } // Set the POV CSpaceObject *pPOV = pSystem->GetObject(0); Universe.SetPOV(pPOV); pSystem->SetPOVLRS(pPOV); // Prepare system Universe.UpdateExtended(); Universe.GarbageCollectLibraryBitmaps(); Universe.StartGame(true); // Update context SSystemUpdateCtx Ctx; Ctx.bForceEventFiring = true; Ctx.bForcePainted = true; // Update for a while DWORD dwStart = ::GetTickCount(); for (i = 0; i < iUpdateCount; i++) { Universe.Update(Ctx); if (i > 0 && (i % SAMPLE_SIZE) == 0) { DWORD dwEnd = ::GetTickCount(); DWORD dwTime = dwEnd - dwStart; SSample *pSample = Timings.Insert(); pSample->dwTime = dwTime; pSample->iObjCount = GetValidObjCount(pSystem); CString sTime = strFormatMilliseconds(dwTime); CString sObjTime = strFormatMicroseconds(1000 * dwTime / pSample->iObjCount); printf("Objs: %d Total time: %s Per obj: %s\n", pSample->iObjCount, sTime.GetASCIIZPointer(), sObjTime.GetASCIIZPointer()); dwStart = ::GetTickCount(); } } // Compute trial average DWORD dwTotal = 0; DWORD dwAverage = 0; for (i = 0; i < Timings.GetCount(); i++) dwTotal += Timings[i].dwTime; if (Timings.GetCount() > 0) { dwAverage = dwTotal / Timings.GetCount(); CString sTime = strFormatMilliseconds(dwAverage); printf("Trial average: %s\n", sTime.GetASCIIZPointer()); } Trials.Insert(dwAverage); // Compute total average dwTotal = 0; for (i = 0; i < Trials.GetCount(); i++) dwTotal += Trials[i]; dwLastAverage = dwTotal / Trials.GetCount(); CString sTime = strFormatMilliseconds(dwLastAverage); printf("\n"); printf("Running average: %s\n", sTime.GetASCIIZPointer()); printf("\n"); } // Final tally CString sTime = strFormatMilliseconds(dwLastAverage); CString sTime2 = strFormatMicroseconds(1000 * dwLastAverage / SAMPLE_SIZE); printf("Total updates: %d\n", iUpdateCount * iCount); printf("Average time for %d updates: %s\n", SAMPLE_SIZE, sTime.GetASCIIZPointer()); printf("Average time per update: %s\n", sTime2.GetASCIIZPointer()); }
void GenerateTopologyMap (CUniverse &Universe, CXMLElement *pCmdLine) { int i; // Some parameters int iScale = pCmdLine->GetAttributeIntegerBounded(CONSTLIT("scale"), 100, -1, -1); // We need to create all systems so that the global object table is // initialized. for (i = 0; i < Universe.GetTopologyNodeCount(); i++) { CTopologyNode *pNode = Universe.GetTopologyNode(i); // Do not try to create end game nodes if (pNode->IsEndGame()) continue; // Node is known pNode->SetKnown(); // Create this system CSystem *pNewSystem; CString sError; if (Universe.CreateStarSystem(pNode, &pNewSystem, &sError) != NOERROR) { printf("ERROR: creating system %s: %s\n", (LPSTR)pNode->GetSystemName(), (LPSTR)sError); continue; } // Delete the system Universe.FlushStarSystem(pNode); } // Initialize the output COutputChart Output; Output.SetStyleFont(STYLE_NAME, pCmdLine->GetAttribute(CONSTLIT("font"))); Output.SetStyleColor(STYLE_NAME, CG32bitPixel(0xFF, 0xFF, 0xFF)); Output.SetOutputFilespec(pCmdLine->GetAttribute(CONSTLIT("output"))); // Get the topology node CTopologyNode *pFirstNode = Universe.GetFirstTopologyNode(); if (pFirstNode == NULL) { printf("ERROR: Unable to find topology node.\n"); return; } // Get the system map for the node CSystemMap *pMap = pFirstNode->GetDisplayPos(); if (pMap == NULL) { printf("ERROR: No system map for node %s.\n", pFirstNode->GetID().GetASCIIZPointer()); return; } // If we didn't set a scale, use the map's initial scale if (iScale == -1) pMap->GetScale(&iScale); // Initialize painting structures CSystemMapThumbnails Thumbs; Thumbs.Init(Universe.GetGlobalObjects()); CGalacticMapPainter Painter(Universe, pMap, Thumbs); int cxMap = Painter.GetWidth() * iScale / 100; int cyMap = Painter.GetHeight() * iScale / 100; // Compute the size of the map RECT rcView; rcView.left = 0; rcView.top = 0; rcView.right = cxMap; rcView.bottom = cyMap; // Create the output Output.SetContentSize(cxMap, cyMap); CG32bitImage &Dest = Output.GetOutputImage(); // Paint Painter.SetViewport(rcView); Painter.SetScale(iScale); Painter.SetPos(0, 0); Painter.Paint(Dest); // Done Output.Output(); }
void GenerateTopologyMap (CUniverse &Universe, CXMLElement *pCmdLine) { int i, j; STopologyMapCtx Ctx; // Initialize the output COutputChart Output; Output.SetStyleFont(STYLE_NAME, pCmdLine->GetAttribute(CONSTLIT("font"))); Output.SetStyleColor(STYLE_NAME, CG16bitImage::RGBValue(0xFF, 0xFF, 0xFF)); Output.SetOutputFilespec(pCmdLine->GetAttribute(CONSTLIT("output"))); // Get the topology node CTopologyNode *pFirstNode = Universe.GetFirstTopologyNode(); if (pFirstNode == NULL) { printf("ERROR: Unable to find topology node.\n"); return; } // Get the system map for the node Ctx.pMap = pFirstNode->GetDisplayPos(); if (Ctx.pMap == NULL) { printf("ERROR: No system map for node %s.\n", pFirstNode->GetID().GetASCIIZPointer()); return; } // Create a background image CG16bitImage *pImage = Ctx.pMap->CreateBackgroundImage(); // Create the output Output.SetContentSize((pImage ? pImage->GetWidth() : 1024), (pImage ? pImage->GetHeight() : 1024)); CG16bitImage &Dest = Output.GetOutputImage(); // Blt if (pImage) Dest.Blt(0, 0, pImage->GetWidth(), pImage->GetHeight(), *pImage, 0, 0); // Done with background image delete pImage; pImage = NULL; // Compute the size of the map (in pixels) Ctx.cxMap = Dest.GetWidth(); Ctx.cyMap = Dest.GetHeight(); Ctx.xCenter = Ctx.cxMap / 2; Ctx.yCenter = Ctx.cyMap / 2; // Loop over all nodes and clear marks on the ones that we need to draw for (i = 0; i < Universe.GetTopologyNodeCount(); i++) { CTopologyNode *pNode = Universe.GetTopologyNode(i); int xPos, yPos; pNode->SetMarked(pNode->GetDisplayPos(&xPos, &yPos) != Ctx.pMap || pNode->IsEndGame()); } // Paint the nodes for (i = 0; i < Universe.GetTopologyNodeCount(); i++) { CTopologyNode *pNode = Universe.GetTopologyNode(i); if (!pNode->IsMarked()) { int xPos, yPos; pNode->GetDisplayPos(&xPos, &yPos); // Convert to view coordinates int x = Ctx.xCenter + xPos; int y = Ctx.yCenter - yPos; // Draw gate connections for (j = 0; j < pNode->GetStargateCount(); j++) { CTopologyNode *pDestNode = pNode->GetStargateDest(j); if (pDestNode && !pDestNode->IsMarked()) { int xPos, yPos; pDestNode->GetDisplayPos(&xPos, &yPos); int xDest = Ctx.xCenter + xPos; int yDest = Ctx.yCenter - yPos; Dest.DrawLine(x, y, xDest, yDest, STARGATE_LINE_WIDTH, STARGATE_LINE_COLOR); } } // Draw star system DrawNode(Ctx, Output, pNode, x, y); pNode->SetMarked(); } } // Done Output.Output(); }
void DoSmokeTest (CUniverse &Universe, CXMLElement *pCmdLine) { ALERROR error; int i, j; int iSystemSample = pCmdLine->GetAttributeInteger(CONSTLIT("count")); if (iSystemSample == 0) iSystemSample = DEFAULT_SYSTEM_SAMPLE; int iSystemUpdateTime = 100; // Generate systems for multiple games CSymbolTable AllSystems(TRUE, TRUE); for (i = 0; i < iSystemSample; i++) { printf("sample %d", i+1); CTopologyNode *pNode = Universe.GetFirstTopologyNode(); while (true) { // Create the system CSystem *pSystem; if (error = Universe.CreateStarSystem(pNode, &pSystem)) { printf("ERROR: Unable to create star system.\n"); return; } // Set the POV CSpaceObject *pPOV = pSystem->GetObject(0); Universe.SetPOV(pPOV); pSystem->SetPOVLRS(pPOV); // Prepare system Universe.UpdateExtended(); Universe.GarbageCollectLibraryBitmaps(); Universe.LoadLibraryBitmaps(); // Update for a while for (j = 0; j < iSystemUpdateTime; j++) Universe.Update(g_SecondsPerUpdate, true); // Get the next node CString sEntryPoint; pNode = pSystem->GetStargateDestination(CONSTLIT("Outbound"), &sEntryPoint); if (pNode == NULL || pNode->IsEndGame()) break; // Done with old system Universe.DestroySystem(pSystem); printf("."); } Universe.Reinit(); printf("\n"); } // Done printf("Test successful.\n"); }