X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Fdebugscript.cpp;h=64cbf49dcffc12efaa2b86fe9ea13c7cddaf0969;hp=59631aa79b7083ad8d2e31f0065cf05723c5f7b4;hb=f28146cf72fc68c8d3690814b1f89d47b8c4e7b9;hpb=c786732a062b493be1e53c0223d7cb1858fd3d0f diff --git a/src/debugscript.cpp b/src/debugscript.cpp index 59631aa..64cbf49 100644 --- a/src/debugscript.cpp +++ b/src/debugscript.cpp @@ -1,4 +1,5 @@ #include "debugscript.h" +#include "profiler.h" #include @@ -7,6 +8,7 @@ using namespace std; void DebugScript::ParseAction(View * view, Screen * scr) { + *m_input >> std::ws; if (m_input == NULL || !m_input->good()) return; istream & inp = *m_input; @@ -171,6 +173,29 @@ void DebugScript::ParseAction(View * view, Screen * scr) currentAction.type = AT_ScreenShot; inp >> currentAction.textargs; } + else if (actionType == "printfps") + { + currentAction.type = AT_PrintFPS; + currentAction.iz = currentAction.loops; + m_fps_cpu_mean = 0; + m_fps_gpu_mean = 0; + m_fps_cpu_stddev = 0; + m_fps_gpu_stddev = 0; + } + else if (actionType == "printbounds") + { + currentAction.type = AT_PrintBounds; + } + else if (actionType == "profileon") + { + currentAction.type = AT_ProfileDisplay; + currentAction.iz = 1; + } + else if (actionType == "profileoff") + { + currentAction.type = AT_ProfileDisplay; + currentAction.iz = 0; + } else Fatal("Unknown action %s", actionType.c_str()); @@ -226,12 +251,18 @@ bool DebugScript::Execute(View *view, Screen *scr) break; case AT_LoadSVG: { +#ifndef QUADTREE_DISABLED + view->Doc().SetQuadtreeInsertNode(view->GetCurrentQuadtreeNode()); +#endif #ifdef TRANSFORM_OBJECTS_NOT_VIEW view->Doc().LoadSVG(currentAction.textargs, Rect(Real(1)/Real(2),Real(1)/Real(2),Real(1)/Real(800),Real(1)/Real(600))); #else const Rect & bounds = view->GetBounds(); view->Doc().LoadSVG(currentAction.textargs, Rect(bounds.x+bounds.w/Real(2),bounds.y+bounds.h/Real(2),bounds.w/Real(800),bounds.h/Real(600))); #endif +#ifndef QUADTREE_DISABLED + view->Doc().PropagateQuadChanges(view->GetCurrentQuadtreeNode()); +#endif currentAction.type = AT_WaitFrame; view->ForceRenderDirty(); view->ForceBufferDirty(); @@ -345,6 +376,53 @@ bool DebugScript::Execute(View *view, Screen *scr) currentAction.loops = 1; break; } + case AT_PrintFPS: + { + // Using a (apparently) Soviet trick to calculate the stddev in one pass + // This was my favourite algorithm in my Physics honours project + // Ah the memories + // The horrible horrible memories + // At least things won't get that bad + // Right? + if (currentAction.loops <= 1) + { + double n = double(currentAction.iz); + m_fps_cpu_mean /= n; + m_fps_gpu_mean /= n; + + m_fps_cpu_stddev = sqrt(m_fps_cpu_stddev / n - m_fps_cpu_mean*m_fps_cpu_mean); + m_fps_gpu_stddev = sqrt(m_fps_gpu_stddev / n - m_fps_gpu_mean*m_fps_gpu_mean); + + + + printf("%d\t%f\t%f\t%f\t%f\n", currentAction.iz, + m_fps_gpu_mean, m_fps_gpu_stddev, + m_fps_cpu_mean, m_fps_cpu_stddev); + } + else + { + + double fps_cpu = 1.0/scr->GetLastFrameTimeCPU(); + double fps_gpu = 1.0/scr->GetLastFrameTimeGPU(); + + m_fps_cpu_mean += fps_cpu; + m_fps_gpu_mean += fps_gpu; + + m_fps_cpu_stddev += fps_cpu*fps_cpu; + m_fps_gpu_stddev += fps_gpu*fps_gpu; + } + break; + } + case AT_PrintBounds: + { + printf("%s\t%s\t%s\t%s\n", Str(view->GetBounds().x).c_str(), Str(view->GetBounds().y).c_str(), Str(view->GetBounds().w).c_str(), Str(view->GetBounds().h).c_str()); + break; + } + case AT_ProfileDisplay: + { + g_profiler.Enable(currentAction.iz); + break; + } default: Fatal("Unknown script command in queue."); }