1 #include "debugscript.h"
7 void DebugScript::ParseAction(View * view, Screen * scr)
9 std::string actionType;
12 while (actionType[0] == '#')
15 std::getline(inp, tmp);
16 inp >> std::ws >> actionType;
18 if (actionType == "loop")
20 inp >> currentAction.loops >> actionType;
24 currentAction.loops = 1;
27 if (actionType == "wait")
29 currentAction.type = AT_WaitFrame;
32 else if (actionType == "translate")
36 currentAction.type = AT_Translate;
37 currentAction.x = RealFromStr(_x.c_str());
38 currentAction.y = RealFromStr(_y.c_str());
41 else if (actionType == "zoom")
43 std::string _x, _y, _z;
44 inp >> _x >> _y >> _z;
45 currentAction.type = AT_Zoom;
46 currentAction.x = RealFromStr(_x.c_str());
47 currentAction.y = RealFromStr(_y.c_str());
48 currentAction.z = RealFromStr(_z.c_str());
50 else if (actionType == "pxtranslate")
52 inp >> currentAction.ix >> currentAction.iy;
53 currentAction.type = AT_TranslatePx;
55 else if (actionType == "pxzoom")
57 inp >> currentAction.ix >> currentAction.iy >> currentAction.iz;
58 currentAction.type = AT_ZoomPx;
60 else if (actionType == "gpu")
62 currentAction.type = AT_SetGPURendering;
64 else if (actionType == "cpu")
66 currentAction.type = AT_SetCPURendering;
68 else if (actionType == "lazy")
70 currentAction.type = AT_EnableLazyRendering;
72 else if (actionType == "nolazy")
74 currentAction.type = AT_DisableLazyRendering;
76 else if (actionType == "quit")
78 currentAction.type = AT_Quit;
80 else if (actionType == "loadsvg")
82 currentAction.type = AT_LoadSVG;
83 inp >> currentAction.textargs;
85 else if (actionType == "label")
87 currentAction.type = AT_Label;
88 inp >> currentAction.textargs;
90 else if (actionType == "goto")
92 currentAction.type = AT_Goto;
93 inp >> currentAction.textargs;
95 else if (actionType == "debug")
97 currentAction.type = AT_Debug;
98 getline(inp,currentAction.textargs);
100 else if (actionType == "clear")
102 currentAction.type = AT_ClearDocument;
104 else if (actionType == "clearperf")
106 currentAction.type = AT_ClearPerformance;
108 else if (actionType == "printperf")
110 currentAction.type = AT_PrintPerformance;
112 else if (actionType == "recordperf")
114 currentAction.type = AT_RecordPerformance;
116 else if (actionType == "debugfont")
118 currentAction.type = AT_DebugFont;
119 inp >> currentAction.textargs;
121 else if (actionType == "approachz") // approach zenoistically
123 currentAction.type = AT_ApproachBoundsZeno;
124 std::string _x, _y, _w, _h, _z;
125 inp >> _x >> _y >> _w >> _h >> _z;
126 currentAction.x = RealFromStr(_x.c_str());
127 currentAction.y = RealFromStr(_y.c_str());
128 currentAction.w = RealFromStr(_w.c_str());
129 currentAction.h = RealFromStr(_h.c_str());
130 currentAction.z = RealFromStr(_z.c_str());
132 else if (actionType == "approachl") // approach linearly
134 currentAction.type = AT_ApproachBoundsLinear;
135 std::string _x, _y, _w, _h, _z;
136 inp >> _x >> _y >> _w >> _h >> _z;
137 currentAction.x = RealFromStr(_x.c_str());
138 currentAction.y = RealFromStr(_y.c_str());
139 currentAction.w = RealFromStr(_w.c_str());
140 currentAction.h = RealFromStr(_h.c_str());
141 currentAction.z = RealFromStr(_z.c_str());
142 currentAction.x = (currentAction.x - view->GetBounds().x)/currentAction.z;
143 currentAction.y = (currentAction.y - view->GetBounds().y)/currentAction.z;
144 currentAction.w = (currentAction.w - view->GetBounds().w)/currentAction.z;
145 currentAction.h = (currentAction.h - view->GetBounds().h)/currentAction.z;
147 else if (actionType == "setbounds")
149 currentAction.type = AT_SetBounds;
150 std::string _x, _y, _w, _h;
151 inp >> _x >> _y >> _w >> _h;
152 currentAction.x = RealFromStr(_x.c_str());
153 currentAction.y = RealFromStr(_y.c_str());
154 currentAction.w = RealFromStr(_w.c_str());
155 currentAction.h = RealFromStr(_h.c_str());
157 else if (actionType == "querygpubounds")
159 currentAction.type = AT_QueryGPUBounds;
160 inp >> currentAction.textargs;
162 else if (actionType == "screenshot")
164 currentAction.type = AT_ScreenShot;
165 inp >> currentAction.textargs;
170 bool DebugScript::Execute(View *view, Screen *scr)
172 if (currentAction.loops <= 0)
174 if (m_index >= m_actions.size())
176 ParseAction(view, scr);
177 if (m_labels.size() > 0)
179 m_actions.push_back(currentAction);
185 currentAction = m_actions[m_index++];
188 switch(currentAction.type)
195 view->Translate(currentAction.x, currentAction.y);
198 view->Translate(Real(currentAction.ix)/Real(scr->ViewportWidth()), Real(currentAction.iy)/Real(scr->ViewportHeight()));
201 view->ScaleAroundPoint(currentAction.x, currentAction.y, currentAction.z);
204 view->ScaleAroundPoint(Real(currentAction.ix)/Real(scr->ViewportWidth()),Real(currentAction.iy)/Real(scr->ViewportHeight()), Real(expf(-currentAction.iz/20.f)));
206 case AT_SetGPURendering:
207 view->SetGPURendering(true);
209 case AT_SetCPURendering:
210 view->SetGPURendering(false);
212 case AT_EnableLazyRendering:
213 view->SetLazyRendering(true);
215 case AT_DisableLazyRendering:
216 view->SetLazyRendering(false);
220 #ifdef TRANSFORM_OBJECTS_NOT_VIEW
221 view->Doc().LoadSVG(currentAction.textargs, Rect(Real(1)/Real(2),Real(1)/Real(2),Real(1)/Real(800),Real(1)/Real(600)));
223 const Rect & bounds = view->GetBounds();
224 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)));
226 currentAction.type = AT_WaitFrame;
227 view->ForceRenderDirty();
228 view->ForceBufferDirty();
229 view->ForceBoundsDirty();
230 currentAction.loops = 1;
234 m_labels[currentAction.textargs] = m_index;
235 currentAction.type = AT_WaitFrame;
236 currentAction.loops = 1;
239 m_index = m_labels[currentAction.textargs];
240 currentAction.loops = 1;
243 Debug("View bounds: %s", view->GetBounds().Str().c_str());
244 if (currentAction.textargs.size() > 0)
245 Debug("%s", currentAction.textargs.c_str());
247 case AT_ClearDocument:
248 view->Doc().ClearObjects();
249 currentAction.loops = 1;
251 case AT_ClearPerformance:
252 ClearPerformance(view, scr);
253 currentAction.loops = 1;
255 case AT_PrintPerformance:
256 PrintPerformance(view, scr);
257 currentAction.loops = 1;
259 case AT_RecordPerformance:
260 PrintPerformance(view, scr);
263 scr->ShowDebugFont(currentAction.textargs == "1" || currentAction.textargs == "on");
264 currentAction.loops = 1;
267 case AT_ApproachBoundsZeno:
269 VRect target(currentAction.x, currentAction.y, currentAction.w, currentAction.h);
270 if (currentAction.z != VReal(1))
272 target.x = view->GetBounds().x + (target.x-view->GetBounds().x)/VReal(currentAction.z);
273 target.y = view->GetBounds().y + (target.y-view->GetBounds().y)/VReal(currentAction.z);
274 target.w = view->GetBounds().w + (target.w-view->GetBounds().w)/VReal(currentAction.z);
275 target.h = view->GetBounds().h + (target.h-view->GetBounds().h)/VReal(currentAction.z);
279 VReal s = target.w/(view->GetBounds().w);
284 x0 = (view->GetBounds().x - target.x)/((s - VReal(1))*view->GetBounds().w);
285 y0 = (view->GetBounds().y - target.y)/((s - VReal(1))*view->GetBounds().h);
286 view->ScaleAroundPoint(x0, y0, s);
287 currentAction.loops++;
291 Debug("Already at target view; Waiting for remaining %d frames", currentAction.loops);
292 currentAction.type = AT_WaitFrame;
296 case AT_ApproachBoundsLinear:
298 VRect target(currentAction.x, currentAction.y, currentAction.w, currentAction.h);
299 target.x += view->GetBounds().x;
300 target.y += view->GetBounds().y;
301 target.w += view->GetBounds().w;
302 target.h += view->GetBounds().h;
303 VReal s = target.w/(view->GetBounds().w);
308 x0 = (view->GetBounds().x - target.x)/((s - VReal(1))*view->GetBounds().w);
309 y0 = (view->GetBounds().y - target.y)/((s - VReal(1))*view->GetBounds().h);
310 view->ScaleAroundPoint(x0, y0, s);
311 currentAction.loops++;
315 Debug("Already at target view; Waiting for remaining %d frames", currentAction.loops);
316 currentAction.type = AT_WaitFrame;
322 VRect target(currentAction.x, currentAction.y, currentAction.w, currentAction.h);
323 view->SetBounds(target);
327 case AT_QueryGPUBounds:
329 view->QueryGPUBounds(currentAction.textargs.c_str(), "w");
330 currentAction.loops = 1;
335 view->SaveBMP(currentAction.textargs.c_str());
336 currentAction.loops = 1;
340 Fatal("Unknown script command in queue.");
342 currentAction.loops--;
346 void DebugScript::ClearPerformance(View * view, Screen * scr)
348 m_perf_start.clock = clock();
349 m_perf_start.object_count = view->Doc().ObjectCount();
350 m_perf_start.view_bounds = view->GetBounds();
351 m_perf_last = m_perf_start;
354 void DebugScript::PrintPerformance(View * view, Screen * scr)
356 DebugScript::PerformanceData now;
358 now.object_count = view->Doc().ObjectCount();
359 now.view_bounds = view->GetBounds();
361 // object_count clock delta_clock x Log10(x) y Log10(y) w Log10(w) Size(w)
362 #ifdef QUADTREE_DISABLED
363 printf("%d\t%llu\t%llu\t%s\t%s\t%s\t%s\t%s\t%s\t%u\n",
364 now.object_count, (long long unsigned)now.clock,
365 (long long unsigned)(now.clock - m_perf_last.clock),
366 Str(now.view_bounds.x).c_str(), Str(Log10(Abs(now.view_bounds.x))).c_str(),
367 Str(now.view_bounds.y).c_str(), Str(Log10(Abs(now.view_bounds.y))).c_str(),
368 Str(now.view_bounds.w).c_str(), Str(Log10(now.view_bounds.w)).c_str(),
369 (unsigned)Size(now.view_bounds.w));