Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ var p5 = function(sketch, node, sync) {

//mandatory update values(matrixs and stack)

this._setProperty('frameCount', this.frameCount + 1);
this.redraw();
this._frameRate = 1000.0/(now - this._lastFrameTime);
this._lastFrameTime = now;
Expand Down
1 change: 1 addition & 0 deletions src/core/structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ p5.prototype.redraw = function () {
f.call(self);
};
for (var idxRedraw = 0; idxRedraw < numberOfRedraws; idxRedraw++) {
this._setProperty('frameCount', this.frameCount + 1);
this._registeredMethods.pre.forEach(callMethod);
userDraw();
this._registeredMethods.post.forEach(callMethod);
Expand Down
53 changes: 53 additions & 0 deletions test/unit/core/structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,59 @@ suite('Structure', function() {
myp5.remove();
});

suite('p5.frameCount', function() {
test('starts at zero', function() {
return new Promise(function(resolve, reject) {
// Has to use a custom p5 to hook setup correctly
new p5(function(p) {
p.setup = function() {
if(p.frameCount !== 0) {
reject('frameCount is not 0 in setup');
}
};
p.draw = function() {
if(p.frameCount === 1) {
resolve();
}
};
});
});
});
test('matches draw calls', function() {
return new Promise(function(resolve, reject) {
var frames = myp5.frameCount;
var start = myp5.frameCount;
myp5.draw = function() {
try {
frames += 1;
assert.equal(myp5.frameCount, frames);
if(frames === start + 5) {
// Test 5 seperate redraws
myp5.noLoop();
setTimeout(myp5.redraw.bind(myp5), 10);
setTimeout(myp5.redraw.bind(myp5), 20);
setTimeout(myp5.redraw.bind(myp5), 30);
setTimeout(myp5.redraw.bind(myp5), 40);
setTimeout(myp5.redraw.bind(myp5), 50);
} else if(frames === start + 10) {
// Test loop resuming
myp5.loop();
} else if(frames === start + 15) {
// Test queuing multiple redraws
myp5.noLoop();
setTimeout(myp5.redraw.bind(myp5, 5), 10);
} else if(frames === start + 20) {
resolve();
}
assert.equal(myp5.frameCount, frames);
} catch(err) {
reject(err);
}
};
});
});
});

suite('p5.prototype.loop and p5.prototype.noLoop', function() {
test('noLoop should stop', function() {
return new Promise(function(resolve, reject) {
Expand Down