Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: components/neterror/resources/offline.js

Issue 2243293002: Reduce memory and CPU resources on offline interstitial while idle. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Switch to activate check rather than crashed Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 (function() { 4 (function() {
5 'use strict'; 5 'use strict';
6 /** 6 /**
7 * T-Rex runner. 7 * T-Rex runner.
8 * @param {string} outerContainerId Outer containing element id. 8 * @param {string} outerContainerId Outer containing element id.
9 * @param {Object} opt_config 9 * @param {Object} opt_config
10 * @constructor 10 * @constructor
(...skipping 26 matching lines...) Expand all
37 this.highestScore = 0; 37 this.highestScore = 0;
38 38
39 this.time = 0; 39 this.time = 0;
40 this.runningTime = 0; 40 this.runningTime = 0;
41 this.msPerFrame = 1000 / FPS; 41 this.msPerFrame = 1000 / FPS;
42 this.currentSpeed = this.config.SPEED; 42 this.currentSpeed = this.config.SPEED;
43 43
44 this.obstacles = []; 44 this.obstacles = [];
45 45
46 this.started = false; 46 this.started = false;
47 this.activated = false; 47 this.activated = false;
mmenke 2016/08/15 19:23:32 Can you document this value? It's not clear what
edwardjung 2016/08/16 21:06:19 Reading through I can see how this is confusing, s
48 this.crashed = false; 48 this.crashed = false;
49 this.paused = false; 49 this.paused = false;
50 this.inverted = false; 50 this.inverted = false;
51 this.invertTimer = 0; 51 this.invertTimer = 0;
52 this.resizeTimerId_ = null; 52 this.resizeTimerId_ = null;
53 53
54 this.playCount = 0; 54 this.playCount = 0;
55 55
56 // Sound FX. 56 // Sound FX.
57 this.audioBuffer = null; 57 this.audioBuffer = null;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 BG_CLOUD_SPEED: 0.2, 107 BG_CLOUD_SPEED: 0.2,
108 BOTTOM_PAD: 10, 108 BOTTOM_PAD: 10,
109 CLEAR_TIME: 3000, 109 CLEAR_TIME: 3000,
110 CLOUD_FREQUENCY: 0.5, 110 CLOUD_FREQUENCY: 0.5,
111 GAMEOVER_CLEAR_TIME: 750, 111 GAMEOVER_CLEAR_TIME: 750,
112 GAP_COEFFICIENT: 0.6, 112 GAP_COEFFICIENT: 0.6,
113 GRAVITY: 0.6, 113 GRAVITY: 0.6,
114 INITIAL_JUMP_VELOCITY: 12, 114 INITIAL_JUMP_VELOCITY: 12,
115 INVERT_FADE_DURATION: 12000, 115 INVERT_FADE_DURATION: 12000,
116 INVERT_DISTANCE: 700, 116 INVERT_DISTANCE: 700,
117 MAX_BLINK_COUNT: 3,
117 MAX_CLOUDS: 6, 118 MAX_CLOUDS: 6,
118 MAX_OBSTACLE_LENGTH: 3, 119 MAX_OBSTACLE_LENGTH: 3,
119 MAX_OBSTACLE_DUPLICATION: 2, 120 MAX_OBSTACLE_DUPLICATION: 2,
120 MAX_SPEED: 13, 121 MAX_SPEED: 13,
121 MIN_JUMP_HEIGHT: 35, 122 MIN_JUMP_HEIGHT: 35,
122 MOBILE_SPEED_COEFFICIENT: 1.2, 123 MOBILE_SPEED_COEFFICIENT: 1.2,
123 RESOURCE_TEMPLATE_ID: 'audio-resources', 124 RESOURCE_TEMPLATE_ID: 'audio-resources',
124 SPEED: 6, 125 SPEED: 6,
125 SPEED_DROP_COEFFICIENT: 3 126 SPEED_DROP_COEFFICIENT: 3
126 }; 127 };
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 window.addEventListener(Runner.events.FOCUS, 504 window.addEventListener(Runner.events.FOCUS,
504 this.onVisibilityChange.bind(this)); 505 this.onVisibilityChange.bind(this));
505 }, 506 },
506 507
507 clearCanvas: function() { 508 clearCanvas: function() {
508 this.canvasCtx.clearRect(0, 0, this.dimensions.WIDTH, 509 this.canvasCtx.clearRect(0, 0, this.dimensions.WIDTH,
509 this.dimensions.HEIGHT); 510 this.dimensions.HEIGHT);
510 }, 511 },
511 512
512 /** 513 /**
513 * Update the game frame. 514 * Update the game frame.
mmenke 2016/08/15 19:23:32 +"And schedules next frame update" (I'm asking fo
edwardjung 2016/08/16 21:06:19 Sure thing, appreciate the input. Added the commen
514 */ 515 */
515 update: function() { 516 update: function() {
516 this.drawPending = false; 517 this.drawPending = false;
517 518
518 var now = getTimeStamp(); 519 var now = getTimeStamp();
519 var deltaTime = now - (this.time || now); 520 var deltaTime = now - (this.time || now);
520 this.time = now; 521 this.time = now;
521 522
522 if (this.activated) { 523 if (this.activated) {
523 this.clearCanvas(); 524 this.clearCanvas();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 this.config.INVERT_DISTANCE); 581 this.config.INVERT_DISTANCE);
581 582
582 if (this.invertTrigger && this.invertTimer === 0) { 583 if (this.invertTrigger && this.invertTimer === 0) {
583 this.invertTimer += deltaTime; 584 this.invertTimer += deltaTime;
584 this.invert(); 585 this.invert();
585 } 586 }
586 } 587 }
587 } 588 }
588 } 589 }
589 590
590 if (!this.crashed) { 591 if (this.activated || (!this.activated &&
592 this.tRex.blinkCount < Runner.config.MAX_BLINK_COUNT)) {
591 this.tRex.update(deltaTime); 593 this.tRex.update(deltaTime);
592 this.raq(); 594 this.raq();
mmenke 2016/08/15 19:23:32 Would you mind renaming this method? "raq" does n
mmenke 2016/08/15 19:52:27 Or if you rename update to draw, scheduleNextDraw
edwardjung 2016/08/16 21:06:19 Updated. It's shorthand for requestAnimationFrame
593 } 595 }
594 }, 596 },
595 597
596 /** 598 /**
597 * Event handler. 599 * Event handler.
598 */ 600 */
599 handleEvent: function(e) { 601 handleEvent: function(e) {
600 return (function(evtType, events) { 602 return (function(evtType, events) {
601 switch (evtType) { 603 switch (evtType) {
602 case events.KEYDOWN: 604 case events.KEYDOWN:
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 if (IS_MOBILE && this.activated) { 661 if (IS_MOBILE && this.activated) {
660 e.preventDefault(); 662 e.preventDefault();
661 } 663 }
662 664
663 if (e.target != this.detailsButton) { 665 if (e.target != this.detailsButton) {
664 if (!this.crashed && (Runner.keycodes.JUMP[e.keyCode] || 666 if (!this.crashed && (Runner.keycodes.JUMP[e.keyCode] ||
665 e.type == Runner.events.TOUCHSTART)) { 667 e.type == Runner.events.TOUCHSTART)) {
666 if (!this.activated) { 668 if (!this.activated) {
667 this.loadSounds(); 669 this.loadSounds();
668 this.activated = true; 670 this.activated = true;
671 this.update();
mmenke 2016/08/15 19:23:32 Think this is worth a comment. Or could call this
edwardjung 2016/08/16 21:06:20 Done.
669 if (window.errorPageController) { 672 if (window.errorPageController) {
670 errorPageController.trackEasterEgg(); 673 errorPageController.trackEasterEgg();
671 } 674 }
mmenke 2016/08/15 19:23:32 Should we return early here, or is the game delibe
edwardjung 2016/08/16 21:06:20 This is deliberate, we start on a jump and sound e
672 } 675 }
673 676
674 if (!this.tRex.jumping && !this.tRex.ducking) { 677 if (!this.tRex.jumping && !this.tRex.ducking) {
675 this.playSound(this.soundFx.BUTTON_PRESS); 678 this.playSound(this.soundFx.BUTTON_PRESS);
676 this.tRex.startJump(this.currentSpeed); 679 this.tRex.startJump(this.currentSpeed);
677 } 680 }
678 } 681 }
679 682
680 if (this.crashed && e.type == Runner.events.TOUCHSTART && 683 if (this.crashed && e.type == Runner.events.TOUCHSTART &&
681 e.currentTarget == this.containerEl) { 684 e.currentTarget == this.containerEl) {
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after
1481 this.canvas = canvas; 1484 this.canvas = canvas;
1482 this.canvasCtx = canvas.getContext('2d'); 1485 this.canvasCtx = canvas.getContext('2d');
1483 this.spritePos = spritePos; 1486 this.spritePos = spritePos;
1484 this.xPos = 0; 1487 this.xPos = 0;
1485 this.yPos = 0; 1488 this.yPos = 0;
1486 // Position when on the ground. 1489 // Position when on the ground.
1487 this.groundYPos = 0; 1490 this.groundYPos = 0;
1488 this.currentFrame = 0; 1491 this.currentFrame = 0;
1489 this.currentAnimFrames = []; 1492 this.currentAnimFrames = [];
1490 this.blinkDelay = 0; 1493 this.blinkDelay = 0;
1494 this.blinkCount = 0;
1491 this.animStartTime = 0; 1495 this.animStartTime = 0;
1492 this.timer = 0; 1496 this.timer = 0;
1493 this.msPerFrame = 1000 / FPS; 1497 this.msPerFrame = 1000 / FPS;
1494 this.config = Trex.config; 1498 this.config = Trex.config;
1495 // Current status. 1499 // Current status.
1496 this.status = Trex.status.WAITING; 1500 this.status = Trex.status.WAITING;
1497 1501
1498 this.jumping = false; 1502 this.jumping = false;
1499 this.ducking = false; 1503 this.ducking = false;
1500 this.jumpVelocity = 0; 1504 this.jumpVelocity = 0;
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1593 } 1597 }
1594 }; 1598 };
1595 1599
1596 1600
1597 Trex.prototype = { 1601 Trex.prototype = {
1598 /** 1602 /**
1599 * T-rex player initaliser. 1603 * T-rex player initaliser.
1600 * Sets the t-rex to blink at random intervals. 1604 * Sets the t-rex to blink at random intervals.
1601 */ 1605 */
1602 init: function() { 1606 init: function() {
1603 this.blinkDelay = this.setBlinkDelay();
1604 this.groundYPos = Runner.defaultDimensions.HEIGHT - this.config.HEIGHT - 1607 this.groundYPos = Runner.defaultDimensions.HEIGHT - this.config.HEIGHT -
mmenke 2016/08/15 19:23:32 So does the first blink happen instantly now?
edwardjung 2016/08/16 21:06:19 No, this was a duplicate as the blink delay is alr
1605 Runner.config.BOTTOM_PAD; 1608 Runner.config.BOTTOM_PAD;
1606 this.yPos = this.groundYPos; 1609 this.yPos = this.groundYPos;
1607 this.minJumpHeight = this.groundYPos - this.config.MIN_JUMP_HEIGHT; 1610 this.minJumpHeight = this.groundYPos - this.config.MIN_JUMP_HEIGHT;
1608 1611
1609 this.draw(0, 0); 1612 this.draw(0, 0);
1610 this.update(0, Trex.status.WAITING); 1613 this.update(0, Trex.status.WAITING);
1611 }, 1614 },
1612 1615
1613 /** 1616 /**
1614 * Setter for the jump velocity. 1617 * Setter for the jump velocity.
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1722 blink: function(time) { 1725 blink: function(time) {
1723 var deltaTime = time - this.animStartTime; 1726 var deltaTime = time - this.animStartTime;
1724 1727
1725 if (deltaTime >= this.blinkDelay) { 1728 if (deltaTime >= this.blinkDelay) {
1726 this.draw(this.currentAnimFrames[this.currentFrame], 0); 1729 this.draw(this.currentAnimFrames[this.currentFrame], 0);
1727 1730
1728 if (this.currentFrame == 1) { 1731 if (this.currentFrame == 1) {
1729 // Set new random delay to blink. 1732 // Set new random delay to blink.
1730 this.setBlinkDelay(); 1733 this.setBlinkDelay();
1731 this.animStartTime = time; 1734 this.animStartTime = time;
1735 this.blinkCount++;
1732 } 1736 }
1733 } 1737 }
1734 }, 1738 },
1735 1739
1736 /** 1740 /**
1737 * Initialise a jump. 1741 * Initialise a jump.
1738 * @param {number} speed 1742 * @param {number} speed
1739 */ 1743 */
1740 startJump: function(speed) { 1744 startJump: function(speed) {
1741 if (!this.jumping) { 1745 if (!this.jumping) {
(...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after
2688 2692
2689 /** 2693 /**
2690 * Add a new cloud to the horizon. 2694 * Add a new cloud to the horizon.
2691 */ 2695 */
2692 addCloud: function() { 2696 addCloud: function() {
2693 this.clouds.push(new Cloud(this.canvas, this.spritePos.CLOUD, 2697 this.clouds.push(new Cloud(this.canvas, this.spritePos.CLOUD,
2694 this.dimensions.WIDTH)); 2698 this.dimensions.WIDTH));
2695 } 2699 }
2696 }; 2700 };
2697 })(); 2701 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698