vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 TITAN_PERFORMANCE_ID = "Performance";
2 TITAN_PERFORMANCE_FREQUENCY = 1;
3  
4 TITAN_FPS_THRESHOLD_TABLE = {
5 Values = { 20, 30 },
6 Colors = { RED_FONT_COLOR, NORMAL_FONT_COLOR, GREEN_FONT_COLOR },
7 }
8 TITAN_LATENCY_THRESHOLD_TABLE = {
9 Values = { PERFORMANCEBAR_LOW_LATENCY, PERFORMANCEBAR_MEDIUM_LATENCY },
10 Colors = { GREEN_FONT_COLOR, NORMAL_FONT_COLOR, RED_FONT_COLOR },
11 }
12 TITAN_MEMORY_RATE_THRESHOLD_TABLE = {
13 Values = { 1, 2 },
14 Colors = { GREEN_FONT_COLOR, NORMAL_FONT_COLOR, RED_FONT_COLOR },
15 }
16 TITAN_MEMORY_TIMETOGC_THRESHOLD_TABLE = {
17 Values = { 60, 300 },
18 Colors = { RED_FONT_COLOR, NORMAL_FONT_COLOR, GREEN_FONT_COLOR },
19 }
20 TITAN_MEMORY_MENU_TOGGLE_TABLE = {
21 "ShowFPS", "ShowLatency", "ShowMemory",
22 }
23  
24 function TitanPanelPerformanceButton_OnLoad()
25 this.registry = {
26 id = TITAN_PERFORMANCE_ID,
27 builtIn = 1,
28 version = TITAN_VERSION,
29 menuText = TITAN_PERFORMANCE_MENU_TEXT,
30 buttonTextFunction = "TitanPanelPerformanceButton_GetButtonText";
31 tooltipCustomFunction = TitanPanelPerformanceButton_SetTooltip;
32 icon = TITAN_ARTWORK_PATH.."TitanPerformance",
33 iconWidth = 16,
34 frequency = TITAN_PERFORMANCE_FREQUENCY,
35 savedVariables = {
36 ShowFPS = 1,
37 ShowLatency = 1,
38 ShowMemory = 1,
39 ShowIcon = 1,
40 ShowLabelText = TITAN_NIL,
41 ShowColoredText = 1,
42 }
43 };
44  
45 this.fpsSampleCount = 0;
46 end
47  
48 function TitanPanelPerformanceButton_GetButtonText(id)
49 local button = TitanPanelPerformanceButton;
50 local color, fpsRichText, latencyRichText, memoryRichText;
51 local showFPS = TitanGetVar(TITAN_PERFORMANCE_ID, "ShowFPS");
52 local showLatency = TitanGetVar(TITAN_PERFORMANCE_ID, "ShowLatency");
53 local showMemory = TitanGetVar(TITAN_PERFORMANCE_ID, "ShowMemory");
54  
55 -- Update real time data
56 TitanPanelPerformanceButton_UpdateData()
57  
58 -- FPS text
59 if ( showFPS ) then
60 local fpsText = format(TITAN_FPS_FORMAT, button.fps);
61 if ( TitanGetVar(TITAN_PERFORMANCE_ID, "ShowColoredText") ) then
62 color = TitanUtils_GetThresholdColor(TITAN_FPS_THRESHOLD_TABLE, button.fps);
63 fpsRichText = TitanUtils_GetColoredText(fpsText, color);
64 else
65 fpsRichText = TitanUtils_GetHighlightText(fpsText);
66 end
67 end
68  
69 -- Latency text
70 if ( showLatency ) then
71 local latencyText = format(TITAN_LATENCY_FORMAT, button.latency);
72 if ( TitanGetVar(TITAN_PERFORMANCE_ID, "ShowColoredText") ) then
73 color = TitanUtils_GetThresholdColor(TITAN_LATENCY_THRESHOLD_TABLE, button.latency);
74 latencyRichText = TitanUtils_GetColoredText(latencyText, color);
75 else
76 latencyRichText = TitanUtils_GetHighlightText(latencyText);
77 end
78 end
79  
80 -- Memory text
81 if ( showMemory ) then
82 local memoryText = format(TITAN_MEMORY_FORMAT, button.memory/1024);
83 memoryRichText = TitanUtils_GetHighlightText(memoryText);
84 end
85  
86 if ( showFPS ) then
87 if ( showLatency ) then
88 if ( showMemory ) then
89 return TITAN_FPS_BUTTON_LABEL, fpsRichText, TITAN_LATENCY_BUTTON_LABEL, latencyRichText, TITAN_MEMORY_BUTTON_LABEL, memoryRichText;
90 else
91 return TITAN_FPS_BUTTON_LABEL, fpsRichText, TITAN_LATENCY_BUTTON_LABEL, latencyRichText;
92 end
93 else
94 if ( showMemory ) then
95 return TITAN_FPS_BUTTON_LABEL, fpsRichText, TITAN_MEMORY_BUTTON_LABEL, memoryRichText;
96 else
97 return TITAN_FPS_BUTTON_LABEL, fpsRichText;
98 end
99 end
100 else
101 if ( showLatency ) then
102 if ( showMemory ) then
103 return TITAN_LATENCY_BUTTON_LABEL, latencyRichText, TITAN_MEMORY_BUTTON_LABEL, memoryRichText;
104 else
105 return TITAN_LATENCY_BUTTON_LABEL, latencyRichText;
106 end
107 else
108 if ( showMemory ) then
109 return TITAN_MEMORY_BUTTON_LABEL, memoryRichText;
110 else
111 return;
112 end
113 end
114 end
115 end
116  
117 function TitanPanelPerformanceButton_SetTooltip()
118 local showFPS = TitanGetVar(TITAN_PERFORMANCE_ID, "ShowFPS");
119 local showLatency = TitanGetVar(TITAN_PERFORMANCE_ID, "ShowLatency");
120 local showMemory = TitanGetVar(TITAN_PERFORMANCE_ID, "ShowMemory");
121  
122 -- Tooltip title
123 GameTooltip:SetText(TITAN_PERFORMANCE_TOOLTIP, HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
124  
125 -- FPS tooltip
126 if ( showFPS ) then
127 local fpsText = format(TITAN_FPS_FORMAT, this.fps);
128 local avgFPSText = format(TITAN_FPS_FORMAT, this.avgFPS);
129 local minFPSText = format(TITAN_FPS_FORMAT, this.minFPS);
130 local maxFPSText = format(TITAN_FPS_FORMAT, this.maxFPS);
131  
132 GameTooltip:AddLine("\n");
133 GameTooltip:AddLine(TitanUtils_GetHighlightText(TITAN_FPS_TOOLTIP));
134 GameTooltip:AddDoubleLine(TITAN_FPS_TOOLTIP_CURRENT_FPS, TitanUtils_GetHighlightText(fpsText));
135 GameTooltip:AddDoubleLine(TITAN_FPS_TOOLTIP_AVG_FPS, TitanUtils_GetHighlightText(avgFPSText));
136 GameTooltip:AddDoubleLine(TITAN_FPS_TOOLTIP_MIN_FPS, TitanUtils_GetHighlightText(minFPSText));
137 GameTooltip:AddDoubleLine(TITAN_FPS_TOOLTIP_MAX_FPS, TitanUtils_GetHighlightText(maxFPSText));
138 end
139  
140 -- Latency tooltip
141 if ( showLatency ) then
142 local latencyText = format(TITAN_LATENCY_FORMAT, this.latency);
143 local bandwidthInText = format(TITAN_LATENCY_BANDWIDTH_FORMAT, this.bandwidthIn);
144 local bandwidthOutText = format(TITAN_LATENCY_BANDWIDTH_FORMAT, this.bandwidthOut);
145  
146 GameTooltip:AddLine("\n");
147 GameTooltip:AddLine(TitanUtils_GetHighlightText(TITAN_LATENCY_TOOLTIP));
148 GameTooltip:AddDoubleLine(TITAN_LATENCY_TOOLTIP_LATENCY, TitanUtils_GetHighlightText(latencyText));
149 GameTooltip:AddDoubleLine(TITAN_LATENCY_TOOLTIP_BANDWIDTH_IN, TitanUtils_GetHighlightText(bandwidthInText));
150 GameTooltip:AddDoubleLine(TITAN_LATENCY_TOOLTIP_BANDWIDTH_OUT, TitanUtils_GetHighlightText(bandwidthOutText));
151 end
152  
153 -- Memory tooltip
154 if ( showMemory ) then
155 local memoryText = format(TITAN_MEMORY_FORMAT, this.memory/1024);
156 local initialMemoryText = format(TITAN_MEMORY_FORMAT, this.initialMemory/1024);
157 local gcThresholdText = format(TITAN_MEMORY_FORMAT, this.gcThreshold/1024);
158 local sessionTime = TitanUtils_GetSessionTime() - this.startSessionTime;
159 local rateRichText, timeToGCRichText, rate, timeToGC, color;
160 if ( sessionTime == 0 ) then
161 rateRichText = TitanUtils_GetHighlightText("N/A");
162 else
163 rate = (this.memory - this.initialMemory) / sessionTime;
164 color = TitanUtils_GetThresholdColor(TITAN_MEMORY_RATE_THRESHOLD_TABLE, rate);
165 rateRichText = TitanUtils_GetColoredText(format(TITAN_MEMORY_RATE_FORMAT, rate), color);
166 end
167 if ( this.memory == this.initialMemory ) then
168 timeToGCRichText = TitanUtils_GetHighlightText("N/A");
169 else
170 timeToGC = (this.gcThreshold - this.memory) / (this.memory - this.initialMemory) * sessionTime;
171 color = TitanUtils_GetThresholdColor(TITAN_MEMORY_TIMETOGC_THRESHOLD_TABLE, timeToGC);
172 timeToGCRichText = TitanUtils_GetColoredText(TitanUtils_GetAbbrTimeText(timeToGC), color);
173 end
174  
175 GameTooltip:AddLine("\n");
176 GameTooltip:AddLine(TitanUtils_GetHighlightText(TITAN_MEMORY_TOOLTIP));
177 GameTooltip:AddDoubleLine(TITAN_MEMORY_TOOLTIP_CURRENT_MEMORY, TitanUtils_GetHighlightText(memoryText));
178 GameTooltip:AddDoubleLine(TITAN_MEMORY_TOOLTIP_INITIAL_MEMORY, TitanUtils_GetHighlightText(initialMemoryText));
179 GameTooltip:AddDoubleLine(TITAN_MEMORY_TOOLTIP_INCREASING_RATE, rateRichText);
180 GameTooltip:AddLine("\n");
181 GameTooltip:AddLine(TitanUtils_GetHighlightText(TITAN_MEMORY_TOOLTIP_GC_INFO));
182 GameTooltip:AddDoubleLine(TITAN_MEMORY_TOOLTIP_GC_THRESHOLD, TitanUtils_GetHighlightText(gcThresholdText));
183 GameTooltip:AddDoubleLine(TITAN_MEMORY_TOOLTIP_TIME_TO_GC, timeToGCRichText);
184 end
185 end
186  
187 function TitanPanelRightClickMenu_PreparePerformanceMenu()
188 TitanPanelRightClickMenu_AddTitle(TitanPlugins[TITAN_PERFORMANCE_ID].menuText);
189 TitanPanelRightClickMenu_AddToggleVar(TITAN_PERFORMANCE_MENU_SHOW_FPS, TITAN_PERFORMANCE_ID, "ShowFPS");
190 TitanPanelRightClickMenu_AddToggleVar(TITAN_PERFORMANCE_MENU_SHOW_LATENCY, TITAN_PERFORMANCE_ID, "ShowLatency");
191 TitanPanelRightClickMenu_AddToggleVar(TITAN_PERFORMANCE_MENU_SHOW_MEMORY, TITAN_PERFORMANCE_ID, "ShowMemory");
192  
193 TitanPanelRightClickMenu_AddSpacer();
194 TitanPanelRightClickMenu_AddToggleIcon(TITAN_PERFORMANCE_ID);
195 TitanPanelRightClickMenu_AddToggleLabelText(TITAN_PERFORMANCE_ID);
196 TitanPanelRightClickMenu_AddToggleColoredText(TITAN_PERFORMANCE_ID);
197  
198 TitanPanelRightClickMenu_AddSpacer();
199 TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, TITAN_PERFORMANCE_ID, TITAN_PANEL_MENU_FUNC_HIDE);
200 end
201  
202 function TitanPanelPerformanceButton_UpdateData()
203 local button = TitanPanelPerformanceButton;
204 local showFPS = TitanGetVar(TITAN_PERFORMANCE_ID, "ShowFPS");
205 local showLatency = TitanGetVar(TITAN_PERFORMANCE_ID, "ShowLatency");
206 local showMemory = TitanGetVar(TITAN_PERFORMANCE_ID, "ShowMemory");
207  
208 -- FPS Data
209 if ( showFPS ) then
210 button.fps = GetFramerate();
211 button.fpsSampleCount = button.fpsSampleCount + 1;
212 if (button.fpsSampleCount == 1) then
213 button.minFPS = button.fps;
214 button.maxFPS = button.fps;
215 button.avgFPS = button.fps;
216 else
217 if (button.fps < button.minFPS) then
218 button.minFPS = button.fps;
219 elseif (button.fps > button.maxFPS) then
220 button.maxFPS = button.fps;
221 end
222 button.avgFPS = (button.avgFPS * (button.fpsSampleCount - 1) + button.fps) / button.fpsSampleCount;
223 end
224 end
225  
226 -- Latency Data
227 if ( showLatency ) then
228 button.bandwidthIn, button.bandwidthOut, button.latency = GetNetStats();
229 end
230  
231 -- Memory data
232 if ( showMemory ) then
233 local previousMemory = button.memory;
234 button.memory, button.gcThreshold = gcinfo();
235 if ( not button.startSessionTime ) then
236 -- Initial data
237 button.startSessionTime = TitanUtils_GetSessionTime();
238 button.initialMemory = button.memory;
239 elseif (previousMemory and button.memory and previousMemory > button.memory) then
240 -- Reset data after garbage collection
241 button.startSessionTime = TitanUtils_GetSessionTime();
242 button.initialMemory = button.memory;
243 end
244 end
245 end
246  
247 function TitanPanelPerformanceButton_ResetMemory()
248 local button = TitanPanelPerformanceButton;
249 button.memory, button.gcThreshold = gcinfo();
250 button.initialMemory = button.memory;
251 button.startSessionTime = TitanUtils_GetSessionTime();
252 end