mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Refactor ingame profiling display & remove profiling at begining of scene
This commit is contained in:
@@ -75,23 +75,19 @@ gdjs.RuntimeSceneCocosRenderer.prototype.render = function() {
|
||||
};
|
||||
|
||||
gdjs.RuntimeSceneCocosRenderer.prototype._renderProfileText = function() {
|
||||
if (!this._runtimeScene.getProfiler()) return;
|
||||
|
||||
if (!this._profilerText) {
|
||||
this._profilerText = new cc.LabelTTF(" ", "Arial", 30);
|
||||
this._profilerText = new cc.LabelTTF(" ", "Arial", 20);
|
||||
this._profilerText.setAnchorPoint(cc.p(0, -1.2));
|
||||
this._cocosScene.addChild(this._profilerText, 100);
|
||||
}
|
||||
|
||||
var average = this._runtimeScene._profiler.getSectionAverage("Frame");
|
||||
var total = Object.keys(average).reduce(function(sum, key) {
|
||||
return sum + (key !== 'total' ? average[key] : 0);
|
||||
}, 0);
|
||||
|
||||
var text = '';
|
||||
for (var p in average) {
|
||||
text += p + ': ' + average[p].toFixed(2) +'ms' + '('+(average[p]/total*100).toFixed(1)+'%)\n';
|
||||
}
|
||||
|
||||
this._profilerText.setString(text);
|
||||
var average = this._runtimeScene.getProfiler().getFramesAverageMeasures();
|
||||
var outputs = [];
|
||||
gdjs.Profiler.getProfilerSectionTexts("All", average, outputs);
|
||||
|
||||
this._profilerText.setString(outputs.join("\n"));
|
||||
};
|
||||
|
||||
gdjs.RuntimeSceneCocosRenderer.prototype.makeEventListeners = function() {
|
||||
|
@@ -21,41 +21,16 @@ gdjs.RuntimeScenePixiRenderer.prototype.onCanvasResized = function() {
|
||||
gdjs.RuntimeScenePixiRenderer.prototype.render = function() {
|
||||
if (!this._pixiRenderer) return;
|
||||
|
||||
this._renderProfileText(); //Uncomment to display profiling times
|
||||
// this._renderProfileText(); //Uncomment to display profiling times
|
||||
|
||||
// render the PIXI container of the scene
|
||||
this._pixiRenderer.backgroundColor = this._runtimeScene.getBackgroundColor();
|
||||
this._pixiRenderer.render(this._pixiContainer);
|
||||
};
|
||||
|
||||
gdjs.RuntimeScenePixiRenderer._getProfilerSectionTexts = function(
|
||||
sectionName,
|
||||
profilerSection,
|
||||
outputs
|
||||
) {
|
||||
var percent =
|
||||
profilerSection.parent && profilerSection.parent.time !== 0
|
||||
? ((profilerSection.time / profilerSection.parent.time) * 100).toFixed(1)
|
||||
: "100%";
|
||||
var time = profilerSection.time.toFixed(2);
|
||||
outputs.push(
|
||||
sectionName + ": " + time + "ms (" + percent + ")"
|
||||
);
|
||||
var subsectionsOutputs = [];
|
||||
|
||||
for (var subsectionName in profilerSection.subsections) {
|
||||
if (profilerSection.subsections.hasOwnProperty(subsectionName)) {
|
||||
gdjs.RuntimeScenePixiRenderer._getProfilerSectionTexts(
|
||||
subsectionName,
|
||||
profilerSection.subsections[subsectionName],
|
||||
subsectionsOutputs
|
||||
);
|
||||
}
|
||||
}
|
||||
outputs.push.apply(outputs, subsectionsOutputs);
|
||||
};
|
||||
|
||||
gdjs.RuntimeScenePixiRenderer.prototype._renderProfileText = function() {
|
||||
if (!this._runtimeScene.getProfiler()) return;
|
||||
|
||||
if (!this._profilerText) {
|
||||
this._profilerText = new PIXI.Text(" ", {
|
||||
align: "left",
|
||||
@@ -65,9 +40,9 @@ gdjs.RuntimeScenePixiRenderer.prototype._renderProfileText = function() {
|
||||
this._pixiContainer.addChild(this._profilerText);
|
||||
}
|
||||
|
||||
var average = this._runtimeScene._profiler.getFramesAverageMeasures();
|
||||
var average = this._runtimeScene.getProfiler().getFramesAverageMeasures();
|
||||
var outputs = [];
|
||||
gdjs.RuntimeScenePixiRenderer._getProfilerSectionTexts("All", average, outputs);
|
||||
gdjs.Profiler.getProfilerSectionTexts("All", average, outputs);
|
||||
|
||||
this._profilerText.text = outputs.join("\n");
|
||||
};
|
||||
|
@@ -111,3 +111,38 @@ gdjs.Profiler.prototype.getFramesAverageMeasures = function() {
|
||||
|
||||
return framesAverageMeasures;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Convert measures for a section into texts.
|
||||
* Useful for ingame profiling.
|
||||
*
|
||||
* @param {*} sectionName The name of the section
|
||||
* @param {*} profilerSection The section measures
|
||||
* @param {*} outputs The array where to push the results
|
||||
*/
|
||||
gdjs.Profiler.getProfilerSectionTexts = function(
|
||||
sectionName,
|
||||
profilerSection,
|
||||
outputs
|
||||
) {
|
||||
var percent =
|
||||
profilerSection.parent && profilerSection.parent.time !== 0
|
||||
? ((profilerSection.time / profilerSection.parent.time) * 100).toFixed(1)
|
||||
: "100%";
|
||||
var time = profilerSection.time.toFixed(2);
|
||||
outputs.push(
|
||||
sectionName + ": " + time + "ms (" + percent + ")"
|
||||
);
|
||||
var subsectionsOutputs = [];
|
||||
|
||||
for (var subsectionName in profilerSection.subsections) {
|
||||
if (profilerSection.subsections.hasOwnProperty(subsectionName)) {
|
||||
gdjs.Profiler.getProfilerSectionTexts(
|
||||
subsectionName,
|
||||
profilerSection.subsections[subsectionName],
|
||||
subsectionsOutputs
|
||||
);
|
||||
}
|
||||
}
|
||||
outputs.push.apply(outputs, subsectionsOutputs);
|
||||
};
|
@@ -369,8 +369,8 @@ gdjs.RuntimeGame.prototype.adaptRendererSizeToFillScreen = function(mode) {
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @param {*} mode
|
||||
* Start the profiler for the currently running scene.
|
||||
* @method startCurrentSceneProfiler
|
||||
*/
|
||||
gdjs.RuntimeGame.prototype.startCurrentSceneProfiler = function() {
|
||||
var currentScene = this._sceneStack.getCurrentScene();
|
||||
@@ -381,8 +381,9 @@ gdjs.RuntimeGame.prototype.startCurrentSceneProfiler = function() {
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @param {*} mode
|
||||
* Stop the profiler for the currently running scene and return the measure.
|
||||
* @return The average measures.
|
||||
* @method stopCurrentSceneProfiler
|
||||
*/
|
||||
gdjs.RuntimeGame.prototype.stopCurrentSceneProfiler = function() {
|
||||
var currentScene = this._sceneStack.getCurrentScene();
|
||||
|
@@ -33,7 +33,7 @@ gdjs.RuntimeScene = function(runtimeGame)
|
||||
this._allInstancesList = []; //An array used to create a list of all instance when necessary ( see _constructListOfAllInstances )
|
||||
this._instancesRemoved = []; //The instances removed from the scene and waiting to be sent to the cache.
|
||||
|
||||
this._profiler = new gdjs.Profiler();
|
||||
this._profiler = null; // Set to `new gdjs.Profiler()` to have profiling done on the scene.
|
||||
|
||||
this.onCanvasResized();
|
||||
};
|
||||
|
Reference in New Issue
Block a user