Skip to content

Commit

Permalink
tweaks for merge
Browse files Browse the repository at this point in the history
  • Loading branch information
davidedc committed Nov 12, 2014
1 parent cbdc3f5 commit 2e907d6
Show file tree
Hide file tree
Showing 31 changed files with 313 additions and 5,831 deletions.
54 changes: 53 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,21 @@ module.exports = function (grunt) {
// Project configuration.
grunt.initConfig({

nodeunit: {
files: ['langtests/**/*_test.js']
},


copy: {
buildTimeOptions: {
src: 'build-time-options/languages-build-option.js',
dest: 'dist/js/globals/languages-build-option.js',
options: {
processContent: function (content, srcpath) {
return content.replace(/SET_AT_BUILD_TIME/mgi,"'"+(grunt.option('language') || 'both')+"'");
}
}
},
main: {
files: [{
expand: true,
Expand Down Expand Up @@ -98,7 +112,15 @@ module.exports = function (grunt) {
watch: {
scripts: {
files: ['coffee/**/*.coffee', 'tests/js/*.js', 'tests/testsSource/*.coffee', 'templts/tests.html.templt', 'tests/htmlsWithTests/images/*.png'],
tasks: ['coffee:app','coffee:tests', 'copy']
tasks: ['coffee:app', 'coffee:tests', 'copy']
},
lcllang: {
files: ['grammar/**/*.jison', 'langtests/**/*.js'],
tasks: ['langtest']
},
interpreter: {
files: ['js_lib/lcl/**/*.js', 'langtests/**/*.js'],
tasks: ['copy:main', 'langtest']
}
},
coffeelint: {
Expand Down Expand Up @@ -181,6 +203,15 @@ module.exports = function (grunt) {
out: 'dist/js/lcl.min.js'
}
}
},
jison: {
main: {
options: {
moduleType: 'amd'
},
src: 'grammar/lcl-grammar.jison',
dest: 'dist/js/lib/lcl/parser.js'
}
}
});

Expand All @@ -199,11 +230,30 @@ module.exports = function (grunt) {
'coffee:app',
'coffee:tests',
'copy:main',
'copy:buildTimeOptions',
'jison',
'recess:compile',
'requirejs',
'targethtml'
]);

grunt.registerTask('fastbuild', [
'clean:build',
'coffee:app',
'coffee:tests',
'copy:main',
'copy:buildTimeOptions',
'jison',
'recess:compile',
'targethtml'
]);

grunt.registerTask('langtest', [
'copy:main',
'jison',
'nodeunit'
]);

// Load NPM Task modules
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-recess');
Expand All @@ -215,5 +265,7 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-requirejs');
grunt.loadNpmTasks('grunt-docco');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-nodeunit');
grunt.loadNpmTasks('grunt-jison');

};
82 changes: 35 additions & 47 deletions coffee/core/animation-loop.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,16 @@ define () ->

loopInterval: null
wantedFramesPerSecond: null
liveCodeLabCoreInstance: undefined
AS_HIGH_FPS_AS_POSSIBLE: -1
noDrawFrame: false
fpsHistory: [10]

sleeping: true

constructor: (@eventRouter,
@stats,
@liveCodeLabCoreInstance,
@lclCore,
@graphicsCommands,
@forceUseOfTimeoutForScheduling = false) ->
# Some basic initialisations and constant definitions
@wantedFramesPerSecond = @AS_HIGH_FPS_AS_POSSIBLE
Expand Down Expand Up @@ -123,18 +125,18 @@ define () ->
animate: ->

if @frame is 0
@liveCodeLabCoreInstance.timeKeeper.resetTime()
@lclCore.timeKeeper.resetTime()
else
@liveCodeLabCoreInstance.timeKeeper.updateTime()
@lclCore.timeKeeper.updateTime()

frameStartTime = @liveCodeLabCoreInstance.timeKeeper.milliseconds
frameStartTime = @lclCore.timeKeeper.milliseconds

# do the render ONLY if we are some ms away from the next
# scheduled beat. In other words, stay well clear of the
# sound timer!

forbiddenZone = Math.min(Math.max.apply(Math, @fpsHistory), 1000/30)
if @liveCodeLabCoreInstance.timeKeeper.nextQuarterBeat - frameStartTime < forbiddenZone
if @lclCore.timeKeeper.nextQuarterBeat - frameStartTime < forbiddenZone
@noDrawFrame = true
else
@noDrawFrame = false
Expand All @@ -146,7 +148,7 @@ define () ->
# We'll re-start the animation when the editor content
# changes. Note that this frame goes to completion anyways, because
# we actually do want to render one "empty screen" frame.
if @liveCodeLabCoreInstance.drawFunctionRunner.drawFunction
if not @sleeping
@scheduleNextFrame()

# Now here there is another try/catch check when the draw function is ran.
Expand All @@ -161,84 +163,70 @@ define () ->
# 1. highlight the error
# 2. run the previously known good program.
try
@liveCodeLabCoreInstance.drawFunctionRunner.runDrawFunction()
@lclCore.programRunner.runProgram()
catch e

#alert('runtime error');
# note that this causes the running of the last stable function
# so you could have executed half of the original draw function,
# then got an error, now you are re-running an old draw function.
@eventRouter.emit("runtime-error-thrown", e)
return
drawFunctionRunner = @liveCodeLabCoreInstance.drawFunctionRunner
drawFunctionRunner.putTicksNextToDoOnceBlocksThatHaveBeenRun \
@liveCodeLabCoreInstance.codeCompiler
programRunner = @lclCore.programRunner
programRunner.putTicksNextToDoOnceBlocksThatHaveBeenRun @lclCore.codeCompiler
else
@liveCodeLabCoreInstance.dozingOff = true
# the program is empty and so it's the screen. Effectively, the user
# is starting from scratch, so the frame variable should be reset to zero.
@setFrame(0)

#console.log('dozing off');

# we have to repeat this check because in the case
# the user has set frame = 0,
# then we have to catch that case here
# after the program has executed
@liveCodeLabCoreInstance.timeKeeper.resetTime() if @frame is 0
@liveCodeLabCoreInstance.blendControls.animationStyleUpdateIfChanged()
@liveCodeLabCoreInstance.backgroundPainter.simpleGradientUpdateIfChanged()
@lclCore.timeKeeper.resetTime() if @frame is 0
@lclCore.blendControls.animationStyleUpdateIfChanged()
@lclCore.backgroundPainter.simpleGradientUpdateIfChanged()

# "frame" starts at zero, so we increment after the first time the draw
# function has been run.
@setFrame(@frame + 1)


# We want to avoid the rendering as soon as 2 consecutive
# invocations of the draw method issue no
# primitive-drawing commands
# This applies particularly as the user only does music
# and no graphics: with no 3d rendering the music
# plays much more regularly and laptops' fan is quiet
# and battery life is spared.
geometryOnScreenMightHaveChanged = (@liveCodeLabCoreInstance.graphicsCommands.atLeastOneObjectWasDrawn or
@liveCodeLabCoreInstance.graphicsCommands.atLeastOneObjectIsDrawn)


if (!@noDrawFrame) and geometryOnScreenMightHaveChanged
geometryOnScreenMightHaveChanged = (@graphicsCommands.atLeastOneObjectWasDrawn or @graphicsCommands.atLeastOneObjectIsDrawn)

@liveCodeLabCoreInstance.renderer.render @liveCodeLabCoreInstance.graphicsCommands

@liveCodeLabCoreInstance.graphicsCommands.atLeastOneObjectWasDrawn =
@liveCodeLabCoreInstance.graphicsCommands.atLeastOneObjectIsDrawn


# if livecodelab is dozing off, in that case you do
# want to do a render because it will clear the screen.
# otherwise the last frame of the sketch is going
# to remain painted in the background behind
# the big cursor.
if (!@noDrawFrame or @sleeping) and geometryOnScreenMightHaveChanged
@lclCore.renderer.render @graphicsCommands
# keep the last 10 durations of when we actually
# drew the frame. This is used for trying to
# avoid collision between graphics and sound timers.
@fpsHistory.push(new Date().getTime() - frameStartTime)
if @fpsHistory.length > 60
@fpsHistory.shift()

@graphicsCommands.atLeastOneObjectWasDrawn = @graphicsCommands.atLeastOneObjectIsDrawn


# update stats
if @stats then @stats.update()

cleanStateBeforeRunningDrawAndRendering: ->
@liveCodeLabCoreInstance.renderer.resetExclusionPrincipleWobbleDataIfNeeded @liveCodeLabCoreInstance.graphicsCommands
@lclCore.renderer.resetExclusionPrincipleWobbleDataIfNeeded @graphicsCommands

@liveCodeLabCoreInstance.matrixCommands.resetMatrixStack()
@lclCore.matrixCommands.resetMatrixStack()

# the sound list needs to be cleaned
# so that the user program can create its own from scratch
@liveCodeLabCoreInstance.soundSystem.resetLoops()
@lclCore.soundSystem.resetLoops()

@liveCodeLabCoreInstance.drawFunctionRunner.resetTrackingOfDoOnceOccurrences()
@lclCore.programRunner.resetTrackingOfDoOnceOccurrences()

@liveCodeLabCoreInstance.lightSystem.noLights()
@liveCodeLabCoreInstance.graphicsCommands.reset()
@liveCodeLabCoreInstance.blendControls.animationStyle \
@liveCodeLabCoreInstance.blendControls.animationStyles.normal
@liveCodeLabCoreInstance.backgroundPainter.resetGradientStack()
@lclCore.lightSystem.noLights()
@graphicsCommands.reset()
@lclCore.blendControls.animationStyle @lclCore.blendControls.animationStyles.normal
@lclCore.backgroundPainter.resetGradientStack()

# In case we want to make each frame an actual
# pure function then we need to seed "random" and "noise"
Expand Down
138 changes: 0 additions & 138 deletions coffee/core/code-compiler.coffee

This file was deleted.

Loading

0 comments on commit 2e907d6

Please sign in to comment.