Browse files

added isRunning function

  • Loading branch information...
1 parent f3095f5 commit b2b57a8db9df9241acd4fc91cb940fea305ecd4b @cemerick committed May 4, 2011
Showing with 22 additions and 7 deletions.
  1. +18 −6 src/kernel.js
  2. +3 −0 src/physics/system.js
  3. +1 −1 src/physics/worker.js
View
24 src/kernel.js
@@ -25,6 +25,7 @@
var _tickInterval = null
var _lastTick = null
var _paused = false
+ var _running = false
var that = {
system:pSystem,
@@ -98,11 +99,15 @@
},
workerMsg:function(e){
- var type = e.data.type
- if (type=='geometry'){
- that.workerUpdate(e.data)
- }else{
- trace('physics:',e.data)
+ switch (e.data.type) {
+ case 'geometry':
+ that.workerUpdate(e.data)
+ break
+ case 'stopping':
+ _running = false
+ break
+ default:
+ trace('physics:',e.data)
}
},
_lastPositions:null,
@@ -184,6 +189,7 @@
// trace('stopping')
clearInterval(_tickInterval)
_tickInterval = null
+ _running = false;
}else{
// trace('pausing')
}
@@ -222,6 +228,8 @@
_tickInterval = setInterval(that.physicsUpdate,
that.system.parameters().timeout)
}
+
+ _running = true
},
stop:function(){
_paused = true
@@ -233,7 +241,11 @@
_tickInterval = null
}
}
-
+
+ _running = false;
+ },
+ isRunning:function() {
+ return _running;
}
}
View
3 src/physics/system.js
@@ -75,6 +75,9 @@
stop:function(){
state.kernel.stop()
},
+ isRunning:function(){
+ return state.kernel.isRunning()
+ },
addNode:function(name, data){
// return that.newNode(name,data)
View
2 src/physics/worker.js
@@ -70,7 +70,7 @@ var PhysicsWorker = function(){
if (_physicsInterval===null) return
clearInterval(_physicsInterval);
_physicsInterval = null;
- // postMessage('stopping')
+ postMessage({type:'stopping'})
},
tick:function(){
// iterate the system

0 comments on commit b2b57a8

Please sign in to comment.