aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/src/core/script/util
diff options
context:
space:
mode:
authorPierre Frisch2011-12-22 07:25:50 -0800
committerValerio Virgillito2012-01-27 11:18:17 -0800
commitb89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch)
tree0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /js/helper-classes/RDGE/src/core/script/util
parent2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff)
downloadninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/util')
-rw-r--r--js/helper-classes/RDGE/src/core/script/util/dbgpanel.js237
-rw-r--r--js/helper-classes/RDGE/src/core/script/util/fpsTracker.js51
-rw-r--r--js/helper-classes/RDGE/src/core/script/util/statTracker.js338
3 files changed, 626 insertions, 0 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/util/dbgpanel.js b/js/helper-classes/RDGE/src/core/script/util/dbgpanel.js
new file mode 100644
index 00000000..f5b9d76d
--- /dev/null
+++ b/js/helper-classes/RDGE/src/core/script/util/dbgpanel.js
@@ -0,0 +1,237 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7var g_dbgPanel = null;
8
9/**
10 * Implements an easy to use debugging panel.
11 * @param id - element id of a <div> to convert into a debug panel
12 * @param title - header title for the panel
13 */
14function utilDbgPanel(id, title)
15{
16 this.id = id;
17 this.root = '#' + id;
18 this.accordion = this.root + ' .dbgpanel-accordion';
19 this.categories = {};
20 this.counter = 0;
21
22 $(this.root).addClass('dbgpanel-outer ui-widget-content');
23 $(this.root).draggable({handle: this.root, containment: 'body'});
24 $(this.root).resizable({minWidth: $(this.root).width(), minHeight: $(this.root).height()});
25
26 $(this.root).append('<h3 class="dbgpanel-title">' + title + '</h3>');
27 $(this.root).append('<div class="dbgpanel-accordion" />');
28 $(this.accordion).accordion({clearStyle: true});
29}
30
31/**
32 * Adds a label to the debug panel.
33 * @param category - category to which to append a label
34 */
35utilDbgPanel.prototype.appendLabel = function(category, label)
36{
37 var cat = this.getCategorySelector(category);
38 $(cat).append('<p class="dbgpanel-label">' + label + '</p>');
39}
40
41/**
42 * Adds a toggle button to the debug panel.
43 * @param category - category to which to append a toggle
44 * @param value - current value of the boolean
45 * @param label - button label
46 * @param onChange - function that receives an updated value upon a change
47 */
48utilDbgPanel.prototype.appendBoolean = function(category, value, label, onChange)
49{
50 var cat = this.getCategorySelector(category);
51
52 var button = this.getUniqueID();
53 $(cat).append('<div class="dbgpanel-button"><input type="checkbox" id="' + button + '"><label for="' + button + '" class="dbgpanel-button-label"/></div>');
54
55 $('#'+button).prop('checked', (value || (value != 0.0)));
56 $('#'+button).button({label: label});
57 $('#'+button).change(function(e) {
58 if (e.target.checked)
59 value = (typeof value == "number") ? 1.0 : true;
60 else
61 value = (typeof value == "number") ? 0.0 : false;
62
63 if(onChange)
64 onChange(value);
65 });
66}
67
68/**
69 * Adds a slider to the debug panel.
70 * @param category - category to which to append a slider
71 * @param value - current value of the number
72 * @param rangeMin - minimum permitted value
73 * @param rangeMax - maximum permitted value
74 * @param stepSize - granularity of allowable values
75 * @param onChange - function that receives an updated value upon a change
76 */
77utilDbgPanel.prototype.appendNumber = function(category, value, rangeMin, rangeMax, stepSize, onChange)
78{
79 var cat = this.getCategorySelector(category);
80
81 var slider = this.getUniqueID();
82 $(cat).append('<div id="' + slider + '" class="dbgpanel-slider"/>');
83
84 $('#'+slider).slider({
85 min: rangeMin, max: rangeMax,
86 value: value,
87 step: stepSize,
88 slide: function(event, ui) {
89 value = ui.value;
90 if(onChange)
91 onChange(value);
92 },
93 change: function(event, ui) {
94 value = ui.value;
95 if(onChange)
96 onChange(value);
97 }
98 });
99}
100
101
102/**
103 * Returns a unique id that can be used with child elements of this debug panel.
104 */
105utilDbgPanel.prototype.getUniqueID = function()
106{
107 return this.id + '_' + this.counter++;
108}
109
110/**
111 * Queries the jquery selector corresponding to the passed accordion category.
112 * @param category - category div for which to return a selector
113 */
114utilDbgPanel.prototype.getCategorySelector = function(category)
115{
116 var selector = this.categories[category];
117
118 if (selector == undefined)
119 {
120 // Generate a selector for this category
121 selector = this.getUniqueID();
122
123 // Add a new div to the accordion ui
124 $(this.accordion).accordion("destroy");
125 $(this.accordion).append('<h3 class="dbgpanel-category-title">' + category +
126 '</h3><div id="' + selector + '" class="dbgpanel-category-content"></div>');
127 $(this.accordion).accordion({clearStyle: true});
128
129 // Store the selector
130 selector = '#' + selector;
131 this.categories[category] = selector;
132 }
133
134 return selector;
135}
136
137//////////////////////////////////
138g_sg=null;
139g_wireframe=false;
140g_initializedDbgPanel=false;
141g_showScene=true;
142g_showBloom=true;
143enableNormalMapping=true;
144g_bloomIntensity1=0.7;
145g_bloomIntensity2=0.5;
146g_bloomIntensity3=1.0;
147g_bloomIntensity4=0.2;
148g_mainLight=null;
149g_shadowLigthSize=7.93;
150g_shadowColor=[1.0 - 0.922, 1.0 - 0.7373, 1.0 - 0.4824, 0.5];
151g_depthMapGenShader=null;
152g_showSSAO=true;
153g_enableShadowMapping=true;
154g_sampleRadius=0.36;
155g_intensity=0.75;
156g_distScale=0.60;
157g_bias=0.05;
158g_animationRate=1.0;
159//////////////////////////////////
160
161utilDbgPanel.prototype.enableFXDebug = function( )
162{
163 this.appendBoolean("General",g_showScene,"Enable scene render",function(val) { g_showScene=val; });
164 this.appendBoolean("General",g_wireframe,"Enable wireframe",function(val) { g_wireframe=val; });
165 this.appendBoolean("General",true,"Enable frustum culling",function(val) { g_sg.frustumCulling=val; });
166 this.appendBoolean("General",enableNormalMapping,"Enable normal mapping",function(val) { enableNormalMapping=val; });
167
168
169 this.appendBoolean("Shadows",g_enableShadowMapping,"Enable shadow mapping",function(val) { var scene = g_Engine.getContext().getScene();
170 scene.renderGraph.shadowDepthMap.visibility = (!val ? 0 : 1);
171 var scene = g_Engine.getContext().getScene();
172 scene.renderGraph.finalPass.shader.screenQuad.u_shadowMap.set("assets/images/white");
173 scene.renderGraph.finalPass.textures[2].enabled = val;
174 });
175 this.appendLabel("Shadows","Light Size");
176 this.appendNumber("Shadows",g_shadowLigthSize, 1.0, 32.0, 0.01, function(val) { var scene = g_Engine.getContext().getScene();
177 scene.renderGraph.shadowMap.shader.shadowMap.u_lightSize.set([val]);});
178
179 this.appendLabel("Shadows","Color-R");
180 this.appendNumber("Shadows",g_shadowColor[0], 0.0, 1.0, 0.001, function(val) { var scene = g_Engine.getContext().getScene();
181 g_shadowColor[0] = 1.0 - val;
182 scene.renderGraph.shadowMap.shader.shadowMap.u_shadowColor.set(g_shadowColor);});
183 this.appendLabel("Shadows","Color-G");
184 this.appendNumber("Shadows",g_shadowColor[1], 0.0, 1.0, 0.001, function(val) { var scene = g_Engine.getContext().getScene();
185 g_shadowColor[1] = 1.0 - val;
186 scene.renderGraph.shadowMap.shader.shadowMap.u_shadowColor.set(g_shadowColor);});
187 this.appendLabel("Shadows","Color-B");
188 this.appendNumber("Shadows",g_shadowColor[2], 0.0, 1.0, 0.001, function(val) { var scene = g_Engine.getContext().getScene();
189 g_shadowColor[2] = 1.0 - val;
190 scene.renderGraph.shadowMap.shader.shadowMap.u_shadowColor.set(g_shadowColor);});
191 this.appendLabel("Shadows","Color-A");
192 this.appendNumber("Shadows",g_shadowColor[3], 0.0, 1.0, 0.001, function(val) { var scene = g_Engine.getContext().getScene();
193 g_shadowColor[3] = val;
194 scene.renderGraph.shadowMap.shader.shadowMap.u_shadowColor.set(g_shadowColor);});
195
196
197 this.appendLabel("Animation","Rate");
198 this.appendNumber("Animation",g_animationRate,-4.0,4.0,0.1,function(val) { g_animationRate=val; });
199
200 this.appendBoolean("Bloom",g_showBloom,"Enable bloom",function(val) { var scene = g_Engine.getContext().getScene();
201 scene.renderGraph.glowMap.visibility = (!val ? 0 : 1);