1 #include "debugscript.h"
8 void DebugScript::ParseAction(View * view, Screen * scr)
10 if (m_input == NULL || !m_input->good())
12 istream & inp = *m_input;
13 Debug("Get action type...");
14 std::string actionType;
16 Debug("Action type: %s", actionType.c_str());
18 while (actionType[0] == '#')
21 std::getline(inp, tmp);
22 inp >> std::ws >> actionType;
24 if (actionType == "loop")
26 inp >> currentAction.loops >> actionType;
30 currentAction.loops = 1;
33 if (actionType == "wait")
35 currentAction.type = AT_WaitFrame;
38 else if (actionType == "translate")
42 currentAction.type = AT_Translate;
43 currentAction.x = RealFromStr(_x.c_str());
44 currentAction.y = RealFromStr(_y.c_str());
47 else if (actionType == "zoom")
49 std::string _x, _y, _z;
50 inp >> _x >> _y >> _z;
51 currentAction.type = AT_Zoom;
52 currentAction.x = RealFromStr(_x.c_str());
53 currentAction.y = RealFromStr(_y.c_str());
54 currentAction.z = RealFromStr(_z.c_str());
56 else if (actionType == "pxtranslate")
58 inp >> currentAction.ix >> currentAction.iy;
59 currentAction.type = AT_TranslatePx;
61 else if (actionType == "pxzoom")
63 inp >> currentAction.ix >> currentAction.iy >> currentAction.iz;
64 currentAction.type = AT_ZoomPx;
66 else if (actionType == "gpu")
68 currentAction.type = AT_SetGPURendering;
70 else if (actionType == "cpu")
72 currentAction.type = AT_SetCPURendering;
74 else if (actionType == "lazy")
76 currentAction.type = AT_EnableLazyRendering;
78 else if (actionType == "nolazy")
80 currentAction.type = AT_DisableLazyRendering;
82 else if (actionType == "quit")
84 currentAction.type = AT_Quit;
86 else if (actionType == "loadsvg")
88 currentAction.type = AT_LoadSVG;
89 inp >> currentAction.textargs;
91 else if (actionType == "label")
93 currentAction.type = AT_Label;
94 inp >> currentAction.textargs;
96 else if (actionType == "goto")
98 currentAction.type = AT_Goto;
99 inp >> currentAction.textargs;
101 else if (actionType == "debug")
103 currentAction.type = AT_Debug;
104 getline(inp,currentAction.textargs);
106 else if (actionType == "clear")
108 currentAction.type = AT_ClearDocument;
110 else if (actionType == "clearperf")
112 currentAction.type = AT_ClearPerformance;
114 else if (actionType == "printperf")
116 currentAction.type = AT_PrintPerformance;
118 else if (actionType == "recordperf")
120 currentAction.type = AT_RecordPerformance;
122 else if (actionType == "debugfont")
124 currentAction.type = AT_DebugFont;
125 inp >> currentAction.textargs;
127 else if (actionType == "approachz") // approach zenoistically
129 currentAction.type = AT_ApproachBoundsZeno;
130 std::string _x, _y, _w, _h, _z;
131 inp >> _x >> _y >> _w >> _h >> _z;
132 currentAction.x = RealFromStr(_x.c_str());
133 currentAction.y = RealFromStr(_y.c_str());
134 currentAction.w = RealFromStr(_w.c_str());
135 currentAction.h = RealFromStr(_h.c_str());
136 currentAction.z = RealFromStr(_z.c_str());
138 else if (actionType == "approachl") // approach linearly
140 currentAction.type = AT_ApproachBoundsLinear;
141 std::string _x, _y, _w, _h, _z;
142 inp >> _x >> _y >> _w >> _h >> _z;
143 currentAction.x = RealFromStr(_x.c_str());
144 currentAction.y = RealFromStr(_y.c_str());
145 currentAction.w = RealFromStr(_w.c_str());
146 currentAction.h = RealFromStr(_h.c_str());
147 currentAction.z = RealFromStr(_z.c_str());
148 currentAction.x = (currentAction.x - view->GetBounds().x)/currentAction.z;
149 currentAction.y = (currentAction.y - view->GetBounds().y)/currentAction.z;
150 currentAction.w = (currentAction.w - view->GetBounds().w)/currentAction.z;
151 currentAction.h = (currentAction.h - view->GetBounds().h)/currentAction.z;
153 else if (actionType == "setbounds")
155 currentAction.type = AT_SetBounds;
156 std::string _x, _y, _w, _h;
157 inp >> _x >> _y >> _w >> _h;
158 currentAction.x = RealFromStr(_x.c_str());
159 currentAction.y = RealFromStr(_y.c_str());
160 currentAction.w = RealFromStr(_w.c_str());
161 currentAction.h = RealFromStr(_h.c_str());
163 else if (actionType == "querygpubounds")
165 currentAction.type = AT_QueryGPUBounds;
166 inp >> currentAction.textargs;
167 currentAction.loops = 1;
169 else if (actionType == "screenshot")
171 currentAction.type = AT_ScreenShot;
172 inp >> currentAction.textargs;
175 Fatal("Unknown action %s", actionType.c_str());
179 bool DebugScript::Execute(View *view, Screen *scr)
181 if (currentAction.loops <= 0)
183 if (m_index >= m_actions.size())
185 ParseAction(view, scr);
186 if (m_labels.size() > 0)
188 m_actions.push_back(currentAction);
194 currentAction = m_actions[m_index++];
197 switch(currentAction.type)
204 view->Translate(currentAction.x, currentAction.y);
207 view->Translate(Real(currentAction.ix)/Real(scr->ViewportWidth()), Real(currentAction.iy)/Real(scr->ViewportHeight()));
210 view->ScaleAroundPoint(currentAction.x, currentAction.y, currentAction.z);
213 view->ScaleAroundPoint(Real(currentAction.ix)/Real(scr->ViewportWidth()),Real(currentAction.iy)/Real(scr->ViewportHeight()), Real(expf(-currentAction.iz/20.f)));
215 case AT_SetGPURendering:
216 view->SetGPURendering(true);
218 case AT_SetCPURendering:
219 view->SetGPURendering(false);
221 case AT_EnableLazyRendering:
222 view->SetLazyRendering(true);
224 case AT_DisableLazyRendering:
225 view->SetLazyRendering(false);
229 #ifdef TRANSFORM_OBJECTS_NOT_VIEW
230 view->Doc().LoadSVG(currentAction.textargs, Rect(Real(1)/Real(2),Real(1)/Real(2),Real(1)/Real(800),Real(1)/Real(600)));
232 const Rect & bounds = view->GetBounds();
233 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)));
235 currentAction.type = AT_WaitFrame;
236 view->ForceRenderDirty();
237 view->ForceBufferDirty();
238 view->ForceBoundsDirty();
239 currentAction.loops = 1;
243 m_labels[currentAction.textargs] = m_index;
244 currentAction.type = AT_WaitFrame;
245 currentAction.loops = 1;
248 m_index = m_labels[currentAction.textargs];
249 currentAction.loops = 1;
252 Debug("View bounds: %s", view->GetBounds().Str().c_str());
253 if (currentAction.textargs.size() > 0)
254 Debug("%s", currentAction.textargs.c_str());
256 case AT_ClearDocument:
257 view->Doc().ClearObjects();
258 currentAction.loops = 1;
260 case AT_ClearPerformance:
261 ClearPerformance(view, scr);
262 currentAction.loops = 1;
264 case AT_PrintPerformance:
265 PrintPerformance(view, scr);
266 currentAction.loops = 1;
268 case AT_RecordPerformance:
269 PrintPerformance(view, scr);
272 scr->ShowDebugFont(currentAction.textargs == "1" || currentAction.textargs == "on");
273 currentAction.loops = 1;
276 case AT_ApproachBoundsZeno:
278 VRect target(currentAction.x, currentAction.y, currentAction.w, currentAction.h);
279 if (currentAction.z != VReal(1))
281 target.x = view->GetBounds().x + (target.x-view->GetBounds().x)/VReal(currentAction.z);
282 target.y = view->GetBounds().y + (target.y-view->GetBounds().y)/VReal(currentAction.z);
283 target.w = view->GetBounds().w + (target.w-view->GetBounds().w)/VReal(currentAction.z);
284 target.h = view->GetBounds().h + (target.h-view->GetBounds().h)/VReal(currentAction.z);
288 VReal s = target.w/(view->GetBounds().w);
293 x0 = (view->GetBounds().x - target.x)/((s - VReal(1))*view->GetBounds().w);
294 y0 = (view->GetBounds().y - target.y)/((s - VReal(1))*view->GetBounds().h);
295 view->ScaleAroundPoint(x0, y0, s);
296 currentAction.loops++;
300 Debug("Already at target view; Waiting for remaining %d frames", currentAction.loops);
301 currentAction.type = AT_WaitFrame;
305 case AT_ApproachBoundsLinear:
307 VRect target(currentAction.x, currentAction.y, currentAction.w, currentAction.h);
308 target.x += view->GetBounds().x;
309 target.y += view->GetBounds().y;
310 target.w += view->GetBounds().w;
311 target.h += view->GetBounds().h;
312 VReal s = target.w/(view->GetBounds().w);
317 x0 = (view->GetBounds().x - target.x)/((s - VReal(1))*view->GetBounds().w);
318 y0 = (view->GetBounds().y - target.y)/((s - VReal(1))*view->GetBounds().h);
319 view->ScaleAroundPoint(x0, y0, s);
320 currentAction.loops++;
324 Debug("Already at target view; Waiting for remaining %d frames", currentAction.loops);
325 currentAction.type = AT_WaitFrame;
331 VRect target(currentAction.x, currentAction.y, currentAction.w, currentAction.h);
332 view->SetBounds(target);
336 case AT_QueryGPUBounds:
338 view->QueryGPUBounds(currentAction.textargs.c_str(), "w");
339 currentAction.loops = 1;
344 view->SaveBMP(currentAction.textargs.c_str());
345 currentAction.loops = 1;
349 Fatal("Unknown script command in queue.");
351 currentAction.loops--;
355 void DebugScript::ClearPerformance(View * view, Screen * scr)
357 m_perf_start.clock = clock();
358 m_perf_start.object_count = view->Doc().ObjectCount();
359 m_perf_start.view_bounds = view->GetBounds();
360 m_perf_last = m_perf_start;
363 void DebugScript::PrintPerformance(View * view, Screen * scr)
365 DebugScript::PerformanceData now;
367 now.object_count = view->Doc().ObjectCount();
368 now.view_bounds = view->GetBounds();
370 // object_count clock delta_clock x Log10(x) y Log10(y) w Log10(w) Size(w)
371 #ifdef QUADTREE_DISABLED
372 printf("%d\t%llu\t%llu\t%s\t%s\t%s\t%s\t%s\t%s\t%u\n",
373 now.object_count, (long long unsigned)now.clock,
374 (long long unsigned)(now.clock - m_perf_last.clock),
375 Str(now.view_bounds.x).c_str(), Str(Log10(Abs(now.view_bounds.x))).c_str(),
376 Str(now.view_bounds.y).c_str(), Str(Log10(Abs(now.view_bounds.y))).c_str(),
377 Str(now.view_bounds.w).c_str(), Str(Log10(now.view_bounds.w)).c_str(),
378 (unsigned)Size(now.view_bounds.w));