mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-24 11:50:58 -04:00
Shouldn't use much CPU when totally paused on Surface.
This commit is contained in:
parent
a74d015d18
commit
6040d3b225
2 changed files with 19 additions and 1 deletions
app
|
@ -65,6 +65,7 @@ module.exports = Surface = class Surface extends CocoClass
|
|||
'god:new-world-created': 'onNewWorld'
|
||||
'tome:cast-spells': 'onCastSpells'
|
||||
'level-set-letterbox': 'onSetLetterbox'
|
||||
'application:idle-changed': 'onIdleChanged'
|
||||
|
||||
shortcuts:
|
||||
'ctrl+\\, ⌘+\\': 'onToggleDebug'
|
||||
|
@ -304,15 +305,32 @@ module.exports = Surface = class Surface extends CocoClass
|
|||
@spriteBoss.stop()
|
||||
@playbackOverScreen.show()
|
||||
@ended = true
|
||||
@setPaused true
|
||||
Backbone.Mediator.publish 'surface:playback-ended'
|
||||
else if @currentFrame < @world.totalFrames and @ended
|
||||
@spriteBoss.play()
|
||||
@playbackOverScreen.hide()
|
||||
@ended = false
|
||||
@setPaused false
|
||||
Backbone.Mediator.publish 'surface:playback-restarted'
|
||||
|
||||
@lastFrame = @currentFrame
|
||||
|
||||
onIdleChanged: (e) ->
|
||||
@setPaused e.idle unless @ended
|
||||
|
||||
setPaused: (to) ->
|
||||
# We want to be able to essentially stop rendering the surface if it doesn't need to animate anything.
|
||||
# If pausing, though, we want to give it enough time to finish any tweens.
|
||||
performToggle = =>
|
||||
createjs.Ticker.setFPS if to then 1 else @options.frameRate
|
||||
@surfacePauseInterval = null
|
||||
clearTimeout @surfacePauseInterval if @surfacePauseInterval
|
||||
if to
|
||||
@surfacePauseInterval = _.delay performToggle, 2000
|
||||
else
|
||||
performToggle()
|
||||
|
||||
onCastSpells: ->
|
||||
@casting = true
|
||||
@wasPlayingWhenCastingBegan = @playing
|
||||
|
|
|
@ -38,7 +38,7 @@ module.exports = class LadderView extends RootView
|
|||
super(options)
|
||||
@level = @supermodel.loadModel(new Level(_id:@levelID), 'level').model
|
||||
@sessions = @supermodel.loadCollection(new LevelSessionsCollection(levelID), 'your_sessions').model
|
||||
|
||||
|
||||
@teams = []
|
||||
|
||||
onLoaded: ->
|
||||
|
|
Loading…
Add table
Reference in a new issue