Permalink
Browse files

Add a pausable clock.

  • Loading branch information...
1 parent 2750984 commit dc342778106096cc62750c763bdd499e8a1182eb @jverkoey committed Mar 1, 2010
Showing with 65 additions and 1 deletion.
  1. +1 −0 dev/breeze.js
  2. +22 −1 dev/core/class.clock.js
  3. +40 −0 dev/core/class.clock.pausable.js
  4. +2 −0 dev/engine/class.scene.js
View
@@ -1,6 +1,7 @@
goog.require('Breeze');
goog.require('Breeze.Clock');
+goog.require('Breeze.PausableClock');
goog.require('Breeze.StateMachine');
goog.require('Breeze.Timer');
goog.require('Breeze.TimeSource');
View
@@ -104,6 +104,13 @@ Breeze.Clock.getGlobalClock = function() {
};
/**
+ * @param {!Breeze.Clock} clock
+ */
+Breeze.Clock.setGlobalClock = function(clock) {
+ Breeze.Clock.globalClock = clock;
+};
+
+/**
* @param {Breeze.TimeSource} timeSource
*/
Breeze.Clock.prototype.setTimeSource = function(timeSource) {
@@ -142,6 +149,20 @@ Breeze.Clock.prototype.getExactTime = function() {
/**
* @return {number}
*/
+Breeze.Clock.prototype.getTime = function() {
+ return this.currentTime_;
+};
+
+/**
+ * @return {number}
+ */
+Breeze.Clock.prototype.getFrameDuration = function() {
+ return this.frameDuration_;
+};
+
+/**
+ * @return {number}
+ */
Breeze.Clock.prototype.getExactLastFrameDuration = function() {
var sourceTime;
if (null == this.timeSource_) {
@@ -150,7 +171,7 @@ Breeze.Clock.prototype.getExactLastFrameDuration = function() {
sourceTime = this.timeSource_.getTime();
}
- var frameDuration = sourceTime - this.sourceLastValue_;
+ var frameDuration = (sourceTime - this.sourceLastValue_) / 1000;
// If we pause the game to debug, we do not want our time-based algorithms to explode
if (frameDuration > Breeze.Clock.FRAMEMAX) {
@@ -0,0 +1,40 @@
+/**
+ * Copyright 2010 Jeff Verkoeyen
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+goog.provide('Breeze.PausableClock');
+
+goog.require('Breeze.Clock');
+
+/**
+ * @param {Breeze.TimeSource|null} timeSource
+ * @constructor
+ */
+Breeze.PausableClock = function(timeSource) {
+ Breeze.Clock.call(this, timeSource);
+
+ /**
+ * @type {boolean}
+ */
+ this.paused = false;
+};
+goog.inherits(Breeze.PausableClock, Breeze.Clock);
+
+/**
+ * @return {number}
+ */
+Breeze.PausableClock.prototype.getFrameDuration = function() {
+ return this.paused_ ? 0 : Breeze.Clock.prototype.call.getFrameDuration(this);
+};
@@ -147,6 +147,8 @@ Breeze.Engine.Scene.prototype.animate = function() {
this.lastTick_ = currentTick;
Breeze.Engine.Scene.prototype.drawScene.call(this);
+
+ Breeze.Clock.getGlobalClock().frameStep();
};
/**

0 comments on commit dc34277

Please sign in to comment.