1
/* -*- Mode: JavaScript; coding: utf-8; tab-width: 3; indent-tabs-mode: tab; c-basic-offset: 3 -*-
2
*******************************************************************************
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6
* Copyright create3000, Scheffelstraße 31a, Leipzig, Germany 2011.
8
* All rights reserved. Holger Seelig <holger.seelig@yahoo.de>.
10
* The copyright notice above does not evidence any actual of intended
11
* publication of such source code, and is an unpublished work by create3000.
12
* This material contains CONFIDENTIAL INFORMATION that is the property of
15
* No permission is granted to copy, distribute, or create derivative works from
16
* the contents of this software, in whole or in part, without the prior written
17
* permission of create3000.
19
* NON-MILITARY USE ONLY
21
* All create3000 software are effectively free software with a non-military use
22
* restriction. It is free. Well commented source is provided. You may reuse the
23
* source in any way you please with the exception anything that uses it must be
24
* marked to indicate is contains 'non-military use only' components.
26
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
28
* Copyright 2015, 2016 Holger Seelig <holger.seelig@yahoo.de>.
30
* This file is part of the Cobweb Project.
32
* Cobweb is free software: you can redistribute it and/or modify it under the
33
* terms of the GNU General Public License version 3 only, as published by the
34
* Free Software Foundation.
36
* Cobweb is distributed in the hope that it will be useful, but WITHOUT ANY
37
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
38
* A PARTICULAR PURPOSE. See the GNU General Public License version 3 for more
39
* details (a copy is included in the LICENSE file that accompanied this code).
41
* You should have received a copy of the GNU General Public License version 3
42
* along with Cobweb. If not, see <http://www.gnu.org/licenses/gpl.html> for a
43
* copy of the GPLv3 License.
45
* For Silvio, Joy and Adi.
47
******************************************************************************/
52
"cobweb/Fields/SFBool",
53
"cobweb/Basic/X3DBaseNode",
63
function f2 (n) { return Math .floor (n * 100) / 100; }
65
function BrowserTimings (executionContext)
67
X3DBaseNode .call (this, executionContext);
69
this .addChildObjects ("enabled", new SFBool ());
72
BrowserTimings .prototype = $.extend (Object .create (X3DBaseNode .prototype),
74
constructor: BrowserTimings,
75
getTypeName: function ()
77
return "BrowserTimings";
79
getComponentName: function ()
83
getContainerField: function ()
85
return "browserTimings";
87
initialize: function ()
89
X3DBaseNode .prototype .initialize .call (this);
91
this .enabled_ .addInterest ("set_enabled__", this);
93
this .localeOptions = { minimumFractionDigits: 2, maximumFractionDigits: 2 };
94
this .type = this .getBrowser () .getDataStorage () ["BrowserTimings.type"] || "LESS";
98
this .element = $("<div></div>") .addClass ("cobweb-browser-timings") .appendTo (this .getBrowser () .getElement () .find (".cobweb-surface"));
99
this .table = $("<table></table>") .appendTo (this .element);
100
this .header = $("<thead></thead>") .append ($("<tr></tr>") .append ($("<th colspan='2'></th>"))) .appendTo (this .table);
101
this .body = $("<tbody></tbody>") .appendTo (this .table);
102
this .footer = $("<tfoot></tfoot>") .append ($("<tr></tr>") .append ($("<td colspan='2'></td>"))) .appendTo (this .table);
103
this .button = $("<button></button>") .click (this .set_type__ .bind (this)) .appendTo (this .footer .find ("td"));
106
this .set_button__ ();
108
if (this .getBrowser () .getDataStorage () ["BrowserTimings.enabled"])
109
this .enabled_ = true;
111
set_enabled__: function (enabled)
113
if (! this .getBrowser () .getBrowserOptions () .getTimings ())
116
this .getBrowser () .getDataStorage () ["BrowserTimings.enabled"] = enabled .getValue ();
118
if (enabled .getValue ())
120
this .element .fadeIn ();
121
this .getBrowser () .prepareEvents () .addInterest ("update", this);
126
this .element .fadeOut ();
127
this .getBrowser () .prepareEvents () .removeInterest ("update", this);
130
set_type__: function ()
132
if (this .type === "MORE")
137
this .getBrowser () .getDataStorage () ["BrowserTimings.type"] = this .type;
139
this .set_button__ ();
142
set_button__: function ()
144
if (this .type === "MORE")
145
this .button .text (_("Less Properties"));
147
this .button .text (_("More Properties"));
151
var currentTime = this .getBrowser () .getCurrentTime ();
153
if (currentTime - this .startTime > 1)
158
this .startTime = currentTime;
166
browser = this .getBrowser (),
167
currentTime = browser .getCurrentTime (),
168
language = navigator .language || navigator .userLanguage,
169
fixed = this .localeOptions,
173
rows [r++] = $("<tr></tr>") .append ($("<td></td>") .text (_("Frame rate") + ":")) .append ($("<td></td>") .text (f2(this .frames / (currentTime - this .startTime)) .toLocaleString (language, fixed) + " " + _("fps")));
174
rows [r++] = $("<tr></tr>") .append ($("<td></td>") .text (_("Speed") + ":")) .append ($("<td></td>") .text (f2(this .getSpeed (browser .currentSpeed)) .toLocaleString (language, fixed) + " " + this .getSpeedUnit (browser .currentSpeed)));
176
if (this .type === "MORE")
179
layers = browser .getWorld () .getLayerSet () .getLayers (),
180
activeLayer = browser .getActiveLayer (),
181
systemTime = browser .systemTime,
182
navigationTime = activeLayer && browser .getCollisionCount () ? activeLayer .collisionTime : 0,
183
collisionTime = browser .collisionTime + navigationTime,
184
routingTime = browser .browserTime - (browser .cameraTime + browser .collisionTime + browser .displayTime + navigationTime),
185
prepareEvents = Object .keys (browser .prepareEvents () .getInterests ()) .length - 1,
186
sensors = Object .keys (browser .sensors () .getInterests ()) .length,
188
transparentShapes = 0;
190
for (var l = 0; l < layers .length; ++ l)
192
var layer = layers [l];
193
opaqueShapes += layer .numOpaqueShapes;
194
transparentShapes += layer .numTransparentShapes;
197
rows [1] .addClass ("cobweb-more");
199
rows [r++] = $("<tr></tr>") .append ($("<td></td>") .text (_("Browser") + ":")) .append ($("<td></td>") .text (f2(systemTime) .toLocaleString (language, fixed) + " " + _("ms")));
200
rows [r++] = $("<tr></tr>") .append ($("<td></td>") .text (_("X3D") + ":")) .append ($("<td></td>") .text (f2(browser .browserTime) .toLocaleString (language, fixed) + " " + _("ms")));
201
rows [r++] = $("<tr></tr>") .append ($("<td></td>") .text (_("Routing") + ":")) .append ($("<td></td>") .text (f2(routingTime) .toLocaleString (language, fixed) + " " + _("ms")));
202
rows [r++] = $("<tr></tr>") .append ($("<td></td>") .text (_("Picking") + ":")) .append ($("<td></td>") .text (f2(browser .pickingTime) .toLocaleString (language, fixed) + " " + _("ms")));
203
rows [r++] = $("<tr></tr>") .append ($("<td></td>") .text (_("Camera") + ":")) .append ($("<td></td>") .text (f2(browser .cameraTime) .toLocaleString (language, fixed) + " " + _("ms")));
204
rows [r++] = $("<tr></tr>") .append ($("<td></td>") .text (_("Collision") + ":")) .append ($("<td></td>") .text (f2(collisionTime) .toLocaleString (language, fixed) + " " + _("ms")));
205
rows [r++] = $("<tr></tr>") .append ($("<td></td>") .text (_("Display") + ":")) .append ($("<td></td>") .text (f2(browser .displayTime) .toLocaleString (language, fixed) + " " + _("ms")));
206
rows [r++] = $("<tr></tr>") .append ($("<td></td>") .text (_("Shapes") + ":")) .append ($("<td></td>") .text (opaqueShapes + " + " + transparentShapes));
207
rows [r++] = $("<tr></tr>") .append ($("<td></td>") .text (_("Sensors") + ":")) .append ($("<td></td>") .text (prepareEvents + sensors));
212
this .header .find ("th") .text (_("Browser Timings"));
213
this .body .empty ();
214
this .body .append (rows);
216
getSpeed: function (speed)
223
getSpeedUnit: function (speed)
232
return BrowserTimings;