/* Makes a stack profile on file stackFile. */ void MakeStackProfile(void) { int i, no, sampleNo; TickList *newTick; int *sampleNoTab; float sampleTime; char idStr[100]; GraphReset(); if ((outfp = fopen((char *) &stackName, "w")) == NULL) { printf("Can not open stackfile: %s.\n", stackName); exit(-1); } sprintf(idStr, "%s - Stack profiling", name); jobstring = MallocString(idStr); sprintf(idStr, "%s", timeStr); datestring = MallocString(idStr); sampleNoTab = xmalloc(noOfSamples * sizeof(int)); no = sortSamples(sortOpt, sampleNoTab); i = 0; sampleNo = 0; for (newTick=firstTick;newTick!=NULL;newTick=newTick->nTick,i++) { if ((sampleNo < no) && (sampleNoTab[sampleNo] == i)) { if (useTickNo) { sampleTime = (float)i; } else { sampleTime = (float)newTick->time/(float)CLOCKS_PER_SEC; } /*printf("sampleNo %3d SampleTime %5.2f\n", sampleNo, sampleTime);*/ allocNewSample(sampleNo, sampleTime); storeSampleEntry(sampleNo, sampleTime, "stack", ((float)(newTick->stackUse))*4.0); storeSampleEntry(sampleNo, sampleTime, "rDesc", ((float)(newTick->regionDescUse))*4.0); sampleNo++; } } if (sampleNo != nsamples) /* These two variables have to follow each other. */ Disaster("sampleNo <> nsamples"); if ((noOfSamples >= SampleMax) && (SampleMax != nsamples)) /* If we have more than SampleMax samples, */ Disaster("noOfSamples >= SampleMax and SampleMax <> nsamples."); /* then we keep exactly SampleMax samples. */ showMax = 0; /* Do not show a maximum line. */ yLab = MallocString("bytes"); PutFile(); return; }
// This method gets called when the user presses a key bool CGame::KeyPress(int c) { if (c == 'W') { m_hPlayer->m_vecMovementGoal.x = m_hPlayer->m_flSpeed; return true; } else if (c == 'A') { m_hPlayer->m_vecMovementGoal.z = m_hPlayer->m_flSpeed; return true; } else if (c == 'S') { m_hPlayer->m_vecMovementGoal.x = -m_hPlayer->m_flSpeed; return true; } else if (c == 'D') { m_hPlayer->m_vecMovementGoal.z = -m_hPlayer->m_flSpeed; return true; } else if (c == ' ') { m_hPlayer->m_vecVelocity.y = 7; return true; } else if (c == 'G') { GraphStep(); return true; } else if (c == 'H') { GraphComplete(); return true; } else if (c == 'R') { GraphReset(); return true; } else return CApplication::KeyPress(c); }
void CGame::Load() { m_iMonsterTexture = GetRenderer()->LoadTextureIntoGL("monster.png"); m_iCrateTexture = GetRenderer()->LoadTextureIntoGL("crate.png"); m_iNormalTexture = GetRenderer()->LoadTextureIntoGL("normal.png"); GraphReset(); m_projectile_initial_time = Game()->GetTime(); m_projectile_initial_position = Vector(2, 1, 2); m_projectile_initial_velocity = Vector(-1, 3, -1) * 5; m_projectile_gravity = Vector(0, -5, 0); m_projectile_break_time = Game()->GetTime() + PredictProjectileMaximumHeightTime(m_projectile_initial_velocity, m_projectile_gravity); m_projectile_number = 1; // Fire the first one m_projectile_position[0] = m_projectile_initial_position; m_projectile_velocity[0] = m_projectile_initial_velocity; }
void CGame::GraphComplete() { GraphReset(); node_t current_node_index = 0; m_Graph.GetNode(current_node_index)->seen = true; m_Graph.GetNode(current_node_index)->path_weight = 0; for (int i = 1; i < m_Graph.GetNumNodes(); i++) m_aiUnvisitedNodes.push_back(i); while (m_aiUnvisitedNodes.size()) { CGraph::CNode* current_node = m_Graph.GetNode(current_node_index); size_t i; for (i = 0; i < current_node->edges.size(); i++) { edge_t edge = current_node->edges[i]; node_t test_node = m_Graph.FollowEdge(current_node_index, edge); if (m_Graph.GetNode(test_node)->seen) continue; float g_weight = m_Graph.GetEdge(edge)->weight + current_node->path_weight; float h_weight = (m_Graph.GetNode(test_node)->debug_position - m_pTargetNode->debug_position).Length(); float f_weight = g_weight + h_weight; if (f_weight < m_Graph.GetNode(test_node)->path_weight) { m_Graph.GetNode(test_node)->path_weight = f_weight; m_Graph.GetNode(test_node)->path_from = current_node_index; } } // We made changes to our node weights. Make sure it's still a heap by remaking the heap. std::make_heap(m_aiUnvisitedNodes.begin(), m_aiUnvisitedNodes.end(), smaller_weight); // Pop the smallest item off the heap. std::pop_heap(m_aiUnvisitedNodes.begin(), m_aiUnvisitedNodes.end(), smaller_weight); node_t lowest_path_node = m_aiUnvisitedNodes.back(); float lowest_path_weight = m_Graph.GetNode(lowest_path_node)->path_weight; m_aiUnvisitedNodes.pop_back(); if (lowest_path_node < 0) return; current_node_index = lowest_path_node; m_Graph.GetNode(current_node_index)->seen = true; if (m_Graph.GetNode(lowest_path_node) == m_pTargetNode) { m_aiPathStack.push_back(current_node_index); while (m_Graph.GetNode(current_node_index)->path_from != ~0) { current_node_index = m_Graph.GetNode(current_node_index)->path_from; m_aiPathStack.push_back(current_node_index); } return; } } }
/* Makes a region profile. */ void MakeObjectProfile(int region) { int i, sampleNo, no; TickList *newTick; ObjectList *newObj; RegionList *newRegion; int *sampleNoTab; float sampleTime; char idStr[100]; int success = 0; GraphReset(); if ((outfp = fopen((char *) &objName, "w")) == NULL) { printf("Cannot open output file %s.\n", objName); exit(-1); } sprintf(idStr, "%s - Object profiling on region %d", name, region); jobstring = MallocString(idStr); sprintf(idStr, "%s", timeStr); datestring = MallocString(idStr); sampleNoTab = xmalloc(noOfSamples * sizeof(int)); no = sortSamples(sortOpt, sampleNoTab); i = 0; sampleNo = 0; for (newTick=firstTick;newTick!=NULL;newTick=newTick->nTick,i++) { if ((sampleNo < no) && (sampleNoTab[sampleNo] == i)) { if (useTickNo) { sampleTime = (float)i; } else { sampleTime = (float)newTick->time/(float)CLOCKS_PER_SEC; } /*printf("sampleNo %3d SampleTime %5.2f\n", sampleNo, sampleTime);*/ allocNewSample(sampleNo, sampleTime); for (newRegion=newTick->fRegion;newRegion!=NULL;newRegion=newRegion->nRegion) { if (newRegion->regionId == region) for (newObj=newRegion->fObj;newObj!=NULL;newObj=newObj->nObj) { success = 1; sprintf(idStr, "pp%d", newObj->atId); storeSampleEntry(sampleNo, sampleTime, idStr, ((float)(newObj->size))*4.0); } } sampleNo++; } } if (success == 0) { printf("There is no profiling information for region r%d, so I could not \ncreate a PostScript file for you.\n", region); exit(-1); } if (sampleNo != nsamples) /* These two variables have to follow each other. */ Disaster("sampleNo <> nsamples"); if ((noOfSamples >= SampleMax) && (SampleMax != nsamples)) /* If we have more than SampleMax samples, */ Disaster("noOfSamples >= SampleMax and SampleMax <> nsamples."); /* then we keep exactly SampleMax samples. */ showMax = 1; maxValue = profTabGetMaxAlloc(region)*4; sprintf(maxValueStr, "Maximum allocated bytes in this region: %2.0f.", maxValue); yLab = MallocString("bytes"); PutFile(); return; }
/* Makes a region profile. */ void MakeRegionProfile(void) { int i, sampleNo, no; TickList *newTick; RegionList *newRegion; int *sampleNoTab; float sampleTime; float maxStack = 0.0; char idStr[100]; GraphReset(); if ((outfp = fopen((char *) &rpName, "w")) == NULL) { printf("Can not open output file %s.\n", rpName); exit(-1); } sprintf(idStr, "%s - Region profiling", name); jobstring = MallocString(idStr); sprintf(idStr, "%s", timeStr); datestring = MallocString(idStr); sampleNoTab = xmalloc(noOfSamples * sizeof(int)); no = sortSamples(sortOpt, sampleNoTab); i = 0; sampleNo = 0; for (newTick=firstTick;newTick!=NULL;newTick=newTick->nTick,i++) { if ((sampleNo < no) && (sampleNoTab[sampleNo] == i)) { if (useTickNo) { sampleTime = (float)i; } else { sampleTime = (float)newTick->time/(float)CLOCKS_PER_SEC; } /*printf("sampleNo %3d SampleTime %5.2f\n", sampleNo, sampleTime);*/ allocNewSample(sampleNo, sampleTime); storeSampleEntry(sampleNo, sampleTime, "stack", ((float)(newTick->stackUse))*4.0); storeSampleEntry(sampleNo, sampleTime, "rDesc", ((float)(newTick->regionDescUse))*4.0); if (((((float)(newTick->stackUse))+((float)(newTick->regionDescUse)))*4.0) > maxStack) /* To ajust the max. */ maxStack = (((float)(newTick->stackUse))+((float)(newTick->regionDescUse)))*4.0; /* allocation line. */ for (newRegion=newTick->fRegion;newRegion!=NULL;newRegion=newRegion->nRegion) { if (newRegion->infinite) sprintf(idStr, "r%dinf", newRegion->regionId); else sprintf(idStr, "r%dfin", newRegion->regionId); storeSampleEntry(sampleNo, sampleTime, idStr, ((float)(newRegion->used))*4.0); } sampleNo++; } } if (sampleNo != nsamples) /* These two variables have to follow each other. */ Disaster("sampleNo <> nsamples"); if ((noOfSamples >= SampleMax) && (SampleMax != nsamples)) /* If we have more than SampleMax samples, */ Disaster("noOfSamples >= SampleMax and SampleMax <> nsamples."); /* then we keep exactly SampleMax samples. */ showMax = 1; maxValue = maxRegions*4; /* The total memory used is often lower than what the line suggests * because the time the stack is maximal may not be the same time * that allocation in regions is maximal! mael 2001-05-22 */ sprintf(maxValueStr, "Maximum allocated bytes in regions (%2.0f) and on stack (%2.0f)", maxValue, maxStack); maxValue += maxStack; /* Ajusting the max. allocation line. */ yLab = MallocString("bytes"); PutFile(); return; }