1 #include "debugscript.h"
7 void DebugScript::ParseAction()
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;
124 bool DebugScript::Execute(View *view, Screen *scr)
126 if (currentAction.loops <= 0)
128 if (m_index >= m_actions.size())
131 if (m_labels.size() > 0)
133 m_actions.push_back(currentAction);
139 currentAction = m_actions[m_index++];
142 switch(currentAction.type)
149 view->Translate(currentAction.x, currentAction.y);
152 view->Translate(Real(currentAction.ix)/Real(scr->ViewportWidth()), Real(currentAction.iy)/Real(scr->ViewportHeight()));
155 view->ScaleAroundPoint(currentAction.x, currentAction.y, currentAction.z);
158 view->ScaleAroundPoint(Real(currentAction.ix)/Real(scr->ViewportWidth()),Real(currentAction.iy)/Real(scr->ViewportHeight()), Real(expf(-currentAction.iz/20.f)));
160 case AT_SetGPURendering:
161 view->SetGPURendering(true);
163 case AT_SetCPURendering:
164 view->SetGPURendering(false);
166 case AT_EnableLazyRendering:
167 view->SetLazyRendering(true);
169 case AT_DisableLazyRendering:
170 view->SetLazyRendering(false);
174 #ifdef TRANSFORM_OBJECTS_NOT_VIEW
175 view->Doc().LoadSVG(currentAction.textargs, Rect(Real(1)/Real(2),Real(1)/Real(2),Real(1)/Real(800),Real(1)/Real(600)));
177 const Rect & bounds = view->GetBounds();
178 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)));
180 currentAction.type = AT_WaitFrame;
181 view->ForceRenderDirty();
182 view->ForceBufferDirty();
183 view->ForceBoundsDirty();
184 currentAction.loops = 1;
188 m_labels[currentAction.textargs] = m_index;
189 currentAction.type = AT_WaitFrame;
190 currentAction.loops = 1;
193 m_index = m_labels[currentAction.textargs];
194 currentAction.loops = 1;
197 Debug("View bounds: %s", view->GetBounds().Str().c_str());
198 if (currentAction.textargs.size() > 0)
199 Debug("%s", currentAction.textargs.c_str());
201 case AT_ClearDocument:
202 view->Doc().ClearObjects();
203 currentAction.loops = 1;
205 case AT_ClearPerformance:
206 ClearPerformance(view, scr);
207 currentAction.loops = 1;
209 case AT_PrintPerformance:
210 PrintPerformance(view, scr);
211 currentAction.loops = 1;
213 case AT_RecordPerformance:
214 PrintPerformance(view, scr);
217 scr->ShowDebugFont(currentAction.textargs == "1" || currentAction.textargs == "on");
218 currentAction.loops = 1;
221 Fatal("Unknown script command in queue.");
223 currentAction.loops--;
227 void DebugScript::ClearPerformance(View * view, Screen * scr)
229 m_perf_start.clock = clock();
230 m_perf_start.object_count = view->Doc().ObjectCount();
231 m_perf_start.view_bounds = view->GetBounds();
232 m_perf_last = m_perf_start;
235 void DebugScript::PrintPerformance(View * view, Screen * scr)
237 DebugScript::PerformanceData now;
239 now.object_count = view->Doc().ObjectCount();
240 now.view_bounds = view->GetBounds();
242 // object_count clock delta_clock x Log10(x) y Log10(y) w Log10(w) Size(w)
243 #ifdef QUADTREE_DISABLED
244 printf("%d\t%llu\t%llu\t%s\t%f\t%s\t%f\t%s\t%f\t%u\n",
245 now.object_count, (long long unsigned)now.clock,
246 (long long unsigned)(now.clock - m_perf_last.clock),
247 Str(now.view_bounds.x).c_str(), Log10(Abs(now.view_bounds.x)),
248 Str(now.view_bounds.y).c_str(), Log10(Abs(now.view_bounds.y)),
249 Str(now.view_bounds.w).c_str(), Log10(now.view_bounds.w),
250 (unsigned)Size(now.view_bounds.w));