1 #include "debugscript.h"
8 void DebugScript::ParseAction(View * view, Screen * scr)
11 if (m_input == NULL || !m_input->good())
13 istream & inp = *m_input;
14 Debug("Get action type...");
15 std::string actionType;
17 Debug("Action type: %s", actionType.c_str());
19 while (actionType[0] == '#')
22 std::getline(inp, tmp);
23 inp >> std::ws >> actionType;
25 if (actionType == "loop")
27 inp >> currentAction.loops >> actionType;
31 currentAction.loops = 1;
34 if (actionType == "wait")
36 currentAction.type = AT_WaitFrame;
39 else if (actionType == "translate")
43 currentAction.type = AT_Translate;
44 currentAction.x = RealFromStr(_x.c_str());
45 currentAction.y = RealFromStr(_y.c_str());
48 else if (actionType == "zoom")
50 std::string _x, _y, _z;
51 inp >> _x >> _y >> _z;
52 currentAction.type = AT_Zoom;
53 currentAction.x = RealFromStr(_x.c_str());
54 currentAction.y = RealFromStr(_y.c_str());
55 currentAction.z = RealFromStr(_z.c_str());
57 else if (actionType == "pxtranslate")
59 inp >> currentAction.ix >> currentAction.iy;
60 currentAction.type = AT_TranslatePx;
62 else if (actionType == "pxzoom")
64 inp >> currentAction.ix >> currentAction.iy >> currentAction.iz;
65 currentAction.type = AT_ZoomPx;
67 else if (actionType == "gpu")
69 currentAction.type = AT_SetGPURendering;
71 else if (actionType == "cpu")
73 currentAction.type = AT_SetCPURendering;
75 else if (actionType == "lazy")
77 currentAction.type = AT_EnableLazyRendering;
79 else if (actionType == "nolazy")
81 currentAction.type = AT_DisableLazyRendering;
83 else if (actionType == "quit")
85 currentAction.type = AT_Quit;
87 else if (actionType == "loadsvg")
89 currentAction.type = AT_LoadSVG;
90 inp >> currentAction.textargs;
92 else if (actionType == "label")
94 currentAction.type = AT_Label;
95 inp >> currentAction.textargs;
97 else if (actionType == "goto")
99 currentAction.type = AT_Goto;
100 inp >> currentAction.textargs;
102 else if (actionType == "debug")
104 currentAction.type = AT_Debug;
105 getline(inp,currentAction.textargs);
107 else if (actionType == "clear")
109 currentAction.type = AT_ClearDocument;
111 else if (actionType == "clearperf")
113 currentAction.type = AT_ClearPerformance;
115 else if (actionType == "printperf")
117 currentAction.type = AT_PrintPerformance;
119 else if (actionType == "recordperf")
121 currentAction.type = AT_RecordPerformance;
123 else if (actionType == "debugfont")
125 currentAction.type = AT_DebugFont;
126 inp >> currentAction.textargs;
128 else if (actionType == "approachz") // approach zenoistically
130 currentAction.type = AT_ApproachBoundsZeno;
131 std::string _x, _y, _w, _h, _z;
132 inp >> _x >> _y >> _w >> _h >> _z;
133 currentAction.x = RealFromStr(_x.c_str());
134 currentAction.y = RealFromStr(_y.c_str());
135 currentAction.w = RealFromStr(_w.c_str());
136 currentAction.h = RealFromStr(_h.c_str());
137 currentAction.z = RealFromStr(_z.c_str());
139 else if (actionType == "approachl") // approach linearly
141 currentAction.type = AT_ApproachBoundsLinear;
142 std::string _x, _y, _w, _h, _z;
143 inp >> _x >> _y >> _w >> _h >> _z;
144 currentAction.x = RealFromStr(_x.c_str());
145 currentAction.y = RealFromStr(_y.c_str());
146 currentAction.w = RealFromStr(_w.c_str());
147 currentAction.h = RealFromStr(_h.c_str());
148 currentAction.z = RealFromStr(_z.c_str());
149 currentAction.x = (currentAction.x - view->GetBounds().x)/currentAction.z;
150 currentAction.y = (currentAction.y - view->GetBounds().y)/currentAction.z;
151 currentAction.w = (currentAction.w - view->GetBounds().w)/currentAction.z;
152 currentAction.h = (currentAction.h - view->GetBounds().h)/currentAction.z;
154 else if (actionType == "setbounds")
156 currentAction.type = AT_SetBounds;
157 std::string _x, _y, _w, _h;
158 inp >> _x >> _y >> _w >> _h;
159 currentAction.x = RealFromStr(_x.c_str());
160 currentAction.y = RealFromStr(_y.c_str());
161 currentAction.w = RealFromStr(_w.c_str());
162 currentAction.h = RealFromStr(_h.c_str());
164 else if (actionType == "querygpubounds")
166 currentAction.type = AT_QueryGPUBounds;
167 inp >> currentAction.textargs;
168 currentAction.loops = 1;
170 else if (actionType == "screenshot")
172 currentAction.type = AT_ScreenShot;
173 inp >> currentAction.textargs;
176 Fatal("Unknown action %s", actionType.c_str());
180 bool DebugScript::Execute(View *view, Screen *scr)
182 if (currentAction.loops <= 0)
184 if (m_index >= m_actions.size())
186 ParseAction(view, scr);
187 if (m_labels.size() > 0)
189 m_actions.push_back(currentAction);
195 currentAction = m_actions[m_index++];
198 switch(currentAction.type)
205 view->Translate(currentAction.x, currentAction.y);
208 view->Translate(Real(currentAction.ix)/Real(scr->ViewportWidth()), Real(currentAction.iy)/Real(scr->ViewportHeight()));
211 view->ScaleAroundPoint(currentAction.x, currentAction.y, currentAction.z);
214 view->ScaleAroundPoint(Real(currentAction.ix)/Real(scr->ViewportWidth()),Real(currentAction.iy)/Real(scr->ViewportHeight()), Real(expf(-currentAction.iz/20.f)));
216 case AT_SetGPURendering:
217 view->SetGPURendering(true);
219 case AT_SetCPURendering:
220 view->SetGPURendering(false);
222 case AT_EnableLazyRendering:
223 view->SetLazyRendering(true);
225 case AT_DisableLazyRendering:
226 view->SetLazyRendering(false);
230 #ifdef TRANSFORM_OBJECTS_NOT_VIEW
231 view->Doc().LoadSVG(currentAction.textargs, Rect(Real(1)/Real(2),Real(1)/Real(2),Real(1)/Real(800),Real(1)/Real(600)));
233 const Rect & bounds = view->GetBounds();
234 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)));
236 currentAction.type = AT_WaitFrame;
237 view->ForceRenderDirty();
238 view->ForceBufferDirty();
239 view->ForceBoundsDirty();
240 currentAction.loops = 1;
244 m_labels[currentAction.textargs] = m_index;
245 currentAction.type = AT_WaitFrame;
246 currentAction.loops = 1;
249 m_index = m_labels[currentAction.textargs];
250 currentAction.loops = 1;
253 Debug("View bounds: %s", view->GetBounds().Str().c_str());
254 if (currentAction.textargs.size() > 0)
255 Debug("%s", currentAction.textargs.c_str());
257 case AT_ClearDocument:
258 view->Doc().ClearObjects();
259 currentAction.loops = 1;
261 case AT_ClearPerformance:
262 ClearPerformance(view, scr);
263 currentAction.loops = 1;
265 case AT_PrintPerformance:
266 PrintPerformance(view, scr);
267 currentAction.loops = 1;
269 case AT_RecordPerformance:
270 PrintPerformance(view, scr);
273 scr->ShowDebugFont(currentAction.textargs == "1" || currentAction.textargs == "on");
274 currentAction.loops = 1;
277 case AT_ApproachBoundsZeno:
279 VRect target(currentAction.x, currentAction.y, currentAction.w, currentAction.h);
280 if (currentAction.z != VReal(1))
282 target.x = view->GetBounds().x + (target.x-view->GetBounds().x)/VReal(currentAction.z);
283 target.y = view->GetBounds().y + (target.y-view->GetBounds().y)/VReal(currentAction.z);
284 target.w = view->GetBounds().w + (target.w-view->GetBounds().w)/VReal(currentAction.z);
285 target.h = view->GetBounds().h + (target.h-view->GetBounds().h)/VReal(currentAction.z);
289 VReal s = target.w/(view->GetBounds().w);
294 x0 = (view->GetBounds().x - target.x)/((s - VReal(1))*view->GetBounds().w);
295 y0 = (view->GetBounds().y - target.y)/((s - VReal(1))*view->GetBounds().h);
296 view->ScaleAroundPoint(x0, y0, s);
297 currentAction.loops++;
301 Debug("Already at target view; Waiting for remaining %d frames", currentAction.loops);
302 currentAction.type = AT_WaitFrame;
306 case AT_ApproachBoundsLinear:
308 VRect target(currentAction.x, currentAction.y, currentAction.w, currentAction.h);
309 target.x += view->GetBounds().x;
310 target.y += view->GetBounds().y;
311 target.w += view->GetBounds().w;
312 target.h += view->GetBounds().h;
313 VReal s = target.w/(view->GetBounds().w);
318 x0 = (view->GetBounds().x - target.x)/((s - VReal(1))*view->GetBounds().w);
319 y0 = (view->GetBounds().y - target.y)/((s - VReal(1))*view->GetBounds().h);
320 view->ScaleAroundPoint(x0, y0, s);
321 currentAction.loops++;
325 Debug("Already at target view; Waiting for remaining %d frames", currentAction.loops);
326 currentAction.type = AT_WaitFrame;
332 VRect target(currentAction.x, currentAction.y, currentAction.w, currentAction.h);
333 view->SetBounds(target);
337 case AT_QueryGPUBounds:
339 view->QueryGPUBounds(currentAction.textargs.c_str(), "w");
340 currentAction.loops = 1;
345 view->SaveBMP(currentAction.textargs.c_str());
346 currentAction.loops = 1;
350 Fatal("Unknown script command in queue.");
352 currentAction.loops--;
356 void DebugScript::ClearPerformance(View * view, Screen * scr)
358 m_perf_start.clock = clock();
359 m_perf_start.object_count = view->Doc().ObjectCount();
360 m_perf_start.view_bounds = view->GetBounds();
361 m_perf_last = m_perf_start;
364 void DebugScript::PrintPerformance(View * view, Screen * scr)
366 DebugScript::PerformanceData now;
368 now.object_count = view->Doc().ObjectCount();
369 now.view_bounds = view->GetBounds();
371 // object_count clock delta_clock x Log10(x) y Log10(y) w Log10(w) Size(w)
372 #ifdef QUADTREE_DISABLED
373 printf("%d\t%llu\t%llu\t%s\t%s\t%s\t%s\t%s\t%s\t%u\n",
374 now.object_count, (long long unsigned)now.clock,
375 (long long unsigned)(now.clock - m_perf_last.clock),
376 Str(now.view_bounds.x).c_str(), Str(Log10(Abs(now.view_bounds.x))).c_str(),
377 Str(now.view_bounds.y).c_str(), Str(Log10(Abs(now.view_bounds.y))).c_str(),
378 Str(now.view_bounds.w).c_str(), Str(Log10(now.view_bounds.w)).c_str(),
379 (unsigned)Size(now.view_bounds.w));