void TestCase::doTests(dtNavMesh* navmesh, dtNavMeshQuery* navquery) { if (!navmesh || !navquery) return; resetTimes(); static const int MAX_POLYS = 256; dtPolyRef polys[MAX_POLYS]; float straight[MAX_POLYS*3]; const float polyPickExt[3] = {2,4,2}; for (Test* iter = m_tests; iter; iter = iter->next) { delete [] iter->polys; iter->polys = 0; iter->npolys = 0; delete [] iter->straight; iter->straight = 0; iter->nstraight = 0; dtQueryFilter filter; filter.setIncludeFlags(iter->includeFlags); filter.setExcludeFlags(iter->excludeFlags); // Find start points TimeVal findNearestPolyStart = getPerfTime(); dtPolyRef startRef, endRef; navquery->findNearestPoly(iter->spos, polyPickExt, &filter, &startRef, iter->nspos); navquery->findNearestPoly(iter->epos, polyPickExt, &filter, &endRef, iter->nepos); TimeVal findNearestPolyEnd = getPerfTime(); iter->findNearestPolyTime += getPerfTimeUsec(findNearestPolyEnd - findNearestPolyStart); if (!startRef || ! endRef) continue; if (iter->type == TEST_PATHFIND) { // Find path TimeVal findPathStart = getPerfTime(); navquery->findPath(startRef, endRef, iter->spos, iter->epos, &filter, polys, &iter->npolys, MAX_POLYS); TimeVal findPathEnd = getPerfTime(); iter->findPathTime += getPerfTimeUsec(findPathEnd - findPathStart); // Find straight path if (iter->npolys) { TimeVal findStraightPathStart = getPerfTime(); navquery->findStraightPath(iter->spos, iter->epos, polys, iter->npolys, straight, 0, 0, &iter->nstraight, MAX_POLYS); TimeVal findStraightPathEnd = getPerfTime(); iter->findStraightPathTime += getPerfTimeUsec(findStraightPathEnd - findStraightPathStart); } // Copy results if (iter->npolys) { iter->polys = new dtPolyRef[iter->npolys]; memcpy(iter->polys, polys, sizeof(dtPolyRef)*iter->npolys); } if (iter->nstraight) { iter->straight = new float[iter->nstraight*3]; memcpy(iter->straight, straight, sizeof(float)*3*iter->nstraight); } } else if (iter->type == TEST_RAYCAST) { float t = 0; float hitNormal[3], hitPos[3]; iter->straight = new float[2*3]; iter->nstraight = 2; iter->straight[0] = iter->spos[0]; iter->straight[1] = iter->spos[1]; iter->straight[2] = iter->spos[2]; TimeVal findPathStart = getPerfTime(); navquery->raycast(startRef, iter->spos, iter->epos, &filter, &t, hitNormal, polys, &iter->npolys, MAX_POLYS); TimeVal findPathEnd = getPerfTime(); iter->findPathTime += getPerfTimeUsec(findPathEnd - findPathStart); if (t > 1) { // No hit dtVcopy(hitPos, iter->epos); } else { // Hit dtVlerp(hitPos, iter->spos, iter->epos, t); } // Adjust height. if (iter->npolys > 0) { float h = 0; navquery->getPolyHeight(polys[iter->npolys-1], hitPos, &h); hitPos[1] = h; } dtVcopy(&iter->straight[3], hitPos); if (iter->npolys) { iter->polys = new dtPolyRef[iter->npolys]; memcpy(iter->polys, polys, sizeof(dtPolyRef)*iter->npolys); } } } printf("Test Results:\n"); int n = 0; for (Test* iter = m_tests; iter; iter = iter->next) { const int total = iter->findNearestPolyTime + iter->findPathTime + iter->findStraightPathTime; printf(" - Path %02d: %.4f ms\n", n, (float)total/1000.0f); printf(" - poly: %.4f ms\n", (float)iter->findNearestPolyTime/1000.0f); printf(" - path: %.4f ms\n", (float)iter->findPathTime/1000.0f); printf(" - straight: %.4f ms\n", (float)iter->findStraightPathTime/1000.0f); n++; } }
int BuildContext::doGetAccumulatedTime(const rcTimerLabel label) const { return getPerfTimeUsec(m_accTime[label]); }