Skip to content

Commit

Permalink
Merge pull request #8 from quinton-ashley/patch-1
Browse files Browse the repository at this point in the history
Fixed debug draw offset and added stats level param
  • Loading branch information
Birch-san authored Dec 26, 2024
2 parents e6a0136 + 07d5818 commit 9952607
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions demo/modern/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ Box2DFactory_().then(box2d => {
const pixelsPerMeter = 10;
const subStepCount = 4;

const cameraOffsetMetres = {
x: 11,
y: -12
};

const debugDraw = new DebugDrawRenderer(box2d, ctx, pixelsPerMeter);
debugDraw.offset = {
x: 40,
y: -29
};


const {
Expand Down Expand Up @@ -56,6 +55,8 @@ Box2DFactory_().then(box2d => {

const params = new URLSearchParams(window.location.search);

const statsLevel = params.get('stats') || 2;

if(params.get('threading') === '1') {
sample = new Sample(navigator.hardwareConcurrency);
worldId = createThreadedSampleWorld(worldDef, sample);
Expand Down Expand Up @@ -191,9 +192,11 @@ Box2DFactory_().then(box2d => {
function drawProfile(stepDuration, profile) {
ctx.font = "16px Arial";
ctx.fillStyle = "black";
if (statsLevel < 1) return;
ctx.fillText(`fps: ${Math.floor(1000/stepDuration)}`, 10, 20);
ctx.fillText(`threading: ${sample ? 'on' : 'off'}`, 100, 20);
ctx.fillText(`memory: ${performance.memory.usedJSHeapSize}`, 300, 20);
if (statsLevel < 2) return;
ctx.fillText(`step: ${profile.step.toFixed(2)}ms`, 10, 40);
ctx.fillText(`pairs: ${profile.pairs.toFixed(2)}ms`, 10, 60);
ctx.fillText(`collide: ${profile.collide.toFixed(2)}ms`, 10, 80);
Expand Down

0 comments on commit 9952607

Please sign in to comment.