diff --git a/chesterGL/actions.js b/chesterGL/actions.js index b96e969..8df75bc 100644 --- a/chesterGL/actions.js +++ b/chesterGL/actions.js @@ -30,8 +30,8 @@ goog.require("chesterGL.Block"); /** * @constructor - * @param {number} totalTime - * @param {chesterGL.Block=} block + * @param {number} totalTime in seconds + * @param {chesterGL.Block=} block The target block */ chesterGL.Action = function (totalTime, block) { this.totalTime = totalTime * 1000; @@ -81,7 +81,7 @@ chesterGL.Action.prototype.finished = false; chesterGL.Action.prototype.running = false; /** - * This is the default delta function (does nothing) + * This is the default update function (does nothing) * @param {number} delta */ chesterGL.Action.prototype.update = function (delta) { @@ -103,9 +103,9 @@ chesterGL.Action.prototype.begin = function () { /** * @constructor - * @param {Array|Float32Array} finalPosition - * @param {number} totalTime - * @param {chesterGL.Block=} block + * @param {Array|Float32Array} finalPosition The final position (the initial position is the current one of the block) + * @param {number} totalTime The total time in seconds that this action should take + * @param {chesterGL.Block=} block The block that will execute this action * @extends {chesterGL.Action} */ chesterGL.MoveToAction = function (finalPosition, totalTime, block) { @@ -128,10 +128,11 @@ chesterGL.MoveToAction.prototype.startPosition = null; * @type {goog.vec.Vec3.Type} * @ignore */ -var __tmp_pos = goog.vec.Vec3.createFloat32(); +chesterGL.MoveToAction__tmp_pos = goog.vec.Vec3.createFloat32(); /** * @param {number} delta miliseconds from last time we updated + * @ignore */ chesterGL.MoveToAction.prototype.update = function (delta) { chesterGL.Action.prototype.update.call(this, delta); @@ -141,13 +142,14 @@ chesterGL.MoveToAction.prototype.update = function (delta) { } else { var t = Math.min(1, this.elapsed / this.totalTime); // console.log("t: " + t + "\t(" + dx + ")"); - goog.vec.Vec3.lerp(this.startPosition, this.finalPosition, t, __tmp_pos); - block.setPosition(__tmp_pos); + goog.vec.Vec3.lerp(this.startPosition, this.finalPosition, t, chesterGL.MoveToAction__tmp_pos); + block.setPosition(chesterGL.MoveToAction__tmp_pos); } }; /** * just set the initial position + * @ignore */ chesterGL.MoveToAction.prototype.begin = function () { if (!this.block) { @@ -158,18 +160,18 @@ chesterGL.MoveToAction.prototype.begin = function () { /** * @constructor - * @param {number} delay in seconds - * @param {Array.} frames - * @param {boolean?} loop - * @param {chesterGL.Block=} block + * @param {number} delay in seconds between frames + * @param {Array.} frames The frames of the animation + * @param {boolean=} loop Whether or not this animation should loop + * @param {chesterGL.Block=} block The block that will receive this action * @extends {chesterGL.Action} */ chesterGL.AnimateAction = function (delay, frames, loop, block) { this.delay = delay * 1000.0; var totalTime = this.delay * frames.length; - if (loop == true) totalTime = -1; + if (loop === true) totalTime = -1; chesterGL.Action.call(this, totalTime, block); - this.shouldLoop = (loop == true); + this.shouldLoop = (loop === true); this.frames = frames.slice(0); }; goog.inherits(chesterGL.AnimateAction, chesterGL.Action); @@ -177,18 +179,21 @@ goog.inherits(chesterGL.AnimateAction, chesterGL.Action); /** * the current frame * @type {number} + * @ignore */ chesterGL.AnimateAction.prototype.currentFrame = 0; /** * The delay between frames * @type {number} + * @ignore */ chesterGL.AnimateAction.prototype.delay = 0.0; /** * The total frames of the animation * @type {Array.} + * @ignore */ chesterGL.AnimateAction.prototype.frames = null; @@ -200,6 +205,7 @@ chesterGL.AnimateAction.prototype.shouldLoop = false; /** * @param {number} delta + * @ignore */ chesterGL.AnimateAction.prototype.update = function (delta) { chesterGL.Action.prototype.update.call(this, delta); @@ -246,6 +252,7 @@ chesterGL.ActionManager.scheduleAction = function (action) { /** * Iterate over all scheduled actions * @param {number} delta number of miliseconds to run in all actions + * @ignore */ chesterGL.ActionManager.tick = function (delta) { var i = 0, len = chesterGL.ActionManager.scheduledActions_.length; diff --git a/chesterGL/block.js b/chesterGL/block.js index 2a2ae6e..056af44 100644 --- a/chesterGL/block.js +++ b/chesterGL/block.js @@ -114,6 +114,7 @@ chesterGL.Block.TYPE = { * 12 (verts, 3 floats) + 8 (tex coords, 2 floats) + 16 (color, 4 floats) * @const * @type {number} + * @ignore */ chesterGL.Block.QUAD_SIZE = 36; @@ -122,6 +123,7 @@ chesterGL.Block.QUAD_SIZE = 36; * 3 (vert) + 2 (tex) + 4 (color) = 9; 9 * 4 (verts) = 36 * @const * @type {number} + * @ignore */ chesterGL.Block.BUFFER_SIZE = 36; @@ -137,6 +139,13 @@ chesterGL.Block.DEG_TO_RAD = Math.PI / 180.0; */ chesterGL.Block.RAD_TO_DEG = 180.0 / Math.PI; +/** + * One degree in radians + * @const + * @type {number} + */ +chesterGL.Block.ONE_DEG = 1 * chesterGL.Block.DEG_TO_RAD; + /** * the full frame * @@ -154,6 +163,7 @@ chesterGL.Block.FullFrame = goog.vec.Vec4.createFloat32FromValues(0.0, 0.0, 1.0, chesterGL.Block.SizeZero = new goog.math.Size(0.0, 0.0); /** + * Sets the title of this block, only used in the scenes right now (for analytics) * @type {string} */ chesterGL.Block.prototype.title = ""; @@ -220,24 +230,25 @@ chesterGL.Block.prototype.glBuffer = null; chesterGL.Block.prototype.glBufferData = null; /** - * the position of the center of the block + * the position of the center of the block. Use the setter to modify this property * @type {goog.vec.Vec3.Type} */ chesterGL.Block.prototype.position = goog.vec.Vec3.createFloat32(); /** - * the content size of the block + * the content size of the block. Use the setter to modify this property * @type {?goog.math.Size} */ chesterGL.Block.prototype.contentSize = null; /** - * the color of the block + * the color of the block. Use the setter to modify this property * @type {goog.vec.Vec4.Type} */ chesterGL.Block.prototype.color = goog.vec.Vec4.createFloat32FromValues(1.0, 1.0, 1.0, 1.0); /** + * The name of the texture associated with this block. Use the setter to modify this property * @type {?string} */ chesterGL.Block.prototype.texture = null; @@ -248,37 +259,37 @@ chesterGL.Block.prototype.texture = null; chesterGL.Block.prototype.opacity = 1.0; /** - * rotation of the box - in radians + * rotation of the box - in radians. Use the setter to modify this property * @type {number} */ chesterGL.Block.prototype.rotation = 0; /** - * the scale of the box + * the scale of the box. Use the setter to modify this property * @type {number} */ chesterGL.Block.prototype.scale = 1.0; /** - * update function + * update function - called every frame with the delta in milliseconds since last frame * @type {?function(number)} */ chesterGL.Block.prototype.update = null; /** - * the texture frame + * the texture frame. Use the setter to modify this property * @type {?goog.vec.Vec4.Type} */ chesterGL.Block.prototype.frame = null; /** - * the block group this block belongs to + * the block group this block belongs to. Read only * @type {?chesterGL.Block} */ chesterGL.Block.prototype.parent = null; /** - * the array to hold children blocks + * the array to hold children blocks. Read only, to modify use addChild or removeChild * @type {?Array.} */ chesterGL.Block.prototype.children = null; @@ -459,6 +470,7 @@ chesterGL.Block.prototype.removeChild = function (block) { /** * actually performs the transformation + * @ignore */ chesterGL.Block.prototype.transform = function () { var gl = chesterGL.gl; @@ -553,6 +565,7 @@ chesterGL.Block.prototype.transform = function () { /** * prepares the block for the rendering (transforms if necessary) + * @ignore */ chesterGL.Block.prototype.visit = function () { this._inVisit = true; @@ -591,6 +604,7 @@ chesterGL.Block.prototype.visit = function () { /** * render (only will work for non-blockgroup blocks) + * @ignore */ chesterGL.Block.prototype.render = function () { if (this.type == chesterGL.Block.TYPE['BLOCKGROUP']) { @@ -658,6 +672,9 @@ goog.exportSymbol('chesterGL.Block.SizeZero', chesterGL.Block.SizeZero); goog.exportSymbol('chesterGL.Block.TYPE', chesterGL.Block.TYPE); goog.exportSymbol('chesterGL.Block.PROGRAM', chesterGL.Block.PROGRAM); goog.exportSymbol('chesterGL.Block.PROGRAM_NAME', chesterGL.Block.PROGRAM_NAME); +goog.exportSymbol('chesterGL.Block.DEG_TO_RAD', chesterGL.Block.DEG_TO_RAD); +goog.exportSymbol('chesterGL.Block.RAD_TO_DEG', chesterGL.Block.RAD_TO_DEG); +goog.exportSymbol('chesterGL.Block.ONE_DEG', chesterGL.Block.ONE_DEG); // properties goog.exportProperty(chesterGL.Block.prototype, 'title', chesterGL.Block.prototype.title); // instance methods diff --git a/chesterGL/blockGroup.js b/chesterGL/blockGroup.js index 5e4419e..5cb84f4 100644 --- a/chesterGL/blockGroup.js +++ b/chesterGL/blockGroup.js @@ -58,21 +58,25 @@ goog.inherits(chesterGL.BlockGroup, chesterGL.Block); /** * The max number of children this blockgroup can hold (this is here for the buffer data) * @type {number} + * @ignore */ chesterGL.BlockGroup.prototype.maxChildren = 0; /** * @type {boolean} + * @ignore */ chesterGL.BlockGroup.prototype.isChildDirty = false; /** * @type {?WebGLBuffer} + * @ignore */ chesterGL.BlockGroup.prototype.indexBuffer = null; /** * @type {?Uint16Array} + * @ignore */ chesterGL.BlockGroup.prototype.indexBufferData = null; @@ -156,6 +160,7 @@ chesterGL.BlockGroup.prototype.removeBlock = function (b) { /** * where the fun begins + * @ignore */ chesterGL.BlockGroup.prototype.visit = function () { if (this.update) { @@ -191,6 +196,7 @@ chesterGL.BlockGroup.prototype.visit = function () { /** * actually render the block group + * @ignore */ chesterGL.BlockGroup.prototype.render = function () { var gl = chesterGL.gl; diff --git a/chesterGL/core.js b/chesterGL/core.js index ab6f375..475b934 100644 --- a/chesterGL/core.js +++ b/chesterGL/core.js @@ -64,7 +64,10 @@ window.requestAnimFrame = (function(){ })(); goog.exportSymbol('requestAnimationFrame', window.requestAnimationFrame); -/** @define {boolean} */ +/** + * @define {boolean} + * @ignore + */ var ENABLE_DEBUG = false; /** @ignore */ @@ -72,13 +75,23 @@ function throwOnGLError(err, funcName, args) { console.log(WebGLDebugUtils.glEnumToString(err) + " was caused by call to " + funcName); } +/** @namespace */ +// var chesterGL = {}; + /** * This is the WebGL context * * @type {?WebGLRenderingContext} + * @ignore */ chesterGL.gl = null; +/** + * chesterGL version + * @type {string} + */ +chesterGL.version = '0.2'; + /** * @type {boolean} * @ignore @@ -95,16 +108,19 @@ chesterGL.useGoogleAnalytics = false; /** * @type {Object.} + * @ignore */ chesterGL.programs = {}; /** * @type {?string} + * @ignore */ chesterGL.currentProgram = null; /** * @type {?goog.vec.Mat4.Type} + * @ignore */ chesterGL.pMatrix = null; @@ -115,6 +131,7 @@ chesterGL.runningScene = null; /** * @type {?Element} + * @ignore */ chesterGL.canvas = null; @@ -127,6 +144,7 @@ chesterGL.projection = "3d"; /** * are we on webgl? + * You can force canvas mode by setting this to false before calling setupPerspective() * @type {boolean} */ chesterGL.webglMode = true; @@ -147,12 +165,14 @@ chesterGL.usesOffscreenBuffer = false; /** * @type {Object.} + * @ignore */ chesterGL.assets = {}; /** * the asset-loaded handlers * @type {Object.} + * @ignore */ chesterGL.assetsHandlers = {}; @@ -161,35 +181,41 @@ chesterGL.assetsHandlers = {}; * The default for textures is creating a new Image() element, the default for any other * type is jquery's $.ajax asynchronously. * @type {Object.} + * @ignore */ chesterGL.assetsLoaders = {}; /** * @type {Object.} + * @ignore */ chesterGL.assetsLoadedListeners = {}; /** * the time last frame was rendered * @type {number} + * @ignore */ chesterGL.lastTime = Date.now(); /** * delta in seconds from last frame * @type {number} + * @ignore */ chesterGL.delta = 0; /** * the current number of frames per second * @type {number} + * @ignore */ chesterGL.fps = 0; /** * the span that will hold the debug info * @type {?Element} + * @ignore */ chesterGL.debugSpan = null; @@ -219,6 +245,7 @@ chesterGL.mouseEvents = { /** * the global list of mouse down handlers * @type {Array.} + * @ignore */ chesterGL.mouseHandlers = []; @@ -227,6 +254,7 @@ chesterGL.mouseHandlers = []; * * @param {string} program * @return {WebGLProgram} + * @ignore */ chesterGL.selectProgram = function (program) { var prog = chesterGL.programs[program]; @@ -319,6 +347,7 @@ chesterGL.initGraphics = function (canvas) { /** * called when the canvas is resized + * @ignore */ chesterGL.canvasResized = function () { var canvas = chesterGL.canvas; @@ -337,6 +366,7 @@ chesterGL.viewportSize = function () { /** * init the default shader + * @ignore */ chesterGL.initDefaultShaders = function () { var gl = chesterGL.gl; @@ -369,6 +399,7 @@ chesterGL.initDefaultShaders = function () { * init shaders (fetches data - in a sync way) * @param {string} prefix * @param {function(WebGLProgram)} callback + * @ignore */ chesterGL.initShader = function (prefix, callback) { var gl = chesterGL.gl; @@ -399,6 +430,7 @@ chesterGL.initShader = function (prefix, callback) { /** * loads the shader data * @return {string} + * @ignore */ chesterGL.loadShader = function (prefix, type) { var shaderData = ""; @@ -423,6 +455,7 @@ chesterGL.loadShader = function (prefix, type) { * @param {WebGLShader|null} fragmentData * @param {WebGLShader|null} vertexData * @return {WebGLProgram} + * @ignore */ chesterGL.createShader = function (prefix, fragmentData, vertexData) { var gl = chesterGL.gl; @@ -527,7 +560,7 @@ chesterGL.loadAsset = function (type, assetPath, cb) { }; /** - * adds a listener for when all assets are loaded + * adds a listener/query for when all assets are loaded * * @param {string} type You can query for all types if you pass "all" as type * @param {function()=} callback The callback to be executed when all assets of that type are loaded @@ -587,6 +620,7 @@ chesterGL.getAsset = function (type, path) { * handles a loaded texture - should only be called on a webGL mode * @param {HTMLImageElement} texture * @return {boolean} + * @ignore */ chesterGL.prepareWebGLTexture = function (texture) { var gl = chesterGL.gl; @@ -619,6 +653,7 @@ chesterGL.prepareWebGLTexture = function (texture) { * @param {string} path * @param {Object|HTMLImageElement} img * @return {boolean} + * @ignore */ chesterGL.defaultTextureHandler = function (path, img) { if (chesterGL.webglMode) { @@ -635,6 +670,7 @@ chesterGL.defaultTextureHandler = function (path, img) { /** * @param {string} type * @param {Object.|null|string} params + * @ignore */ chesterGL.defaultTextureLoader = function (type, params) { var img = new Image(); @@ -661,6 +697,7 @@ chesterGL.defaultTextureLoader = function (type, params) { /** * @param {string} type * @param {Object.|null|string} params + * @ignore */ chesterGL.defaultAssetLoader = function (type, params) { var path = params.url; @@ -739,6 +776,7 @@ chesterGL.setupPerspective = function () { }; /** + * Sets the current running scene * @param {chesterGL.Block} block */ chesterGL.setRunningScene = function (block) { @@ -749,6 +787,7 @@ chesterGL.setRunningScene = function (block) { /** * main draw function, will call the root block + * @ignore */ chesterGL.drawScene = function () { var gl = undefined; @@ -823,7 +862,7 @@ chesterGL.updateDebugTime = function () { '_trackEvent', 'chesterGL', // Let us know if this is WebGL or canvas mode - 'renderTime-' + (chesterGL.webglMode), + 'renderTime-' + (chesterGL.webglMode) + chesterGL.version, chesterGL.runningScene.title, Math.floor(chesterGL.sumAvg/chesterGL.sampledAvg) ]); @@ -845,22 +884,21 @@ chesterGL.installMouseHandlers = function () { }; /** - * @type {goog.vec.Vec3.Type} + * @type {Float32Array} * @ignore */ -var __tmp_mouse_vec = new Float32Array(3); +chesterGL.__tmp_mouse_vec = new Float32Array(3); /** * @param {Event} event * @ignore */ chesterGL.mouseDownHandler = function (event) { - /** @type {goog.math.Vec2} */ var pt = chesterGL.canvas.relativePosition(event); var i = 0, len = chesterGL.mouseHandlers.length; - __tmp_mouse_vec.set([pt.x, pt.y]); + chesterGL.__tmp_mouse_vec.set([pt.x, pt.y, 0]); for (; i < len; i++) { - chesterGL.mouseHandlers[i](__tmp_mouse_vec, chesterGL.mouseEvents.DOWN); + chesterGL.mouseHandlers[i](chesterGL.__tmp_mouse_vec, chesterGL.mouseEvents.DOWN); } }; @@ -871,9 +909,9 @@ chesterGL.mouseDownHandler = function (event) { chesterGL.mouseMoveHandler = function (event) { var pt = chesterGL.canvas.relativePosition(event); var i = 0, len = chesterGL.mouseHandlers.length; - __tmp_mouse_vec.set([pt.x, pt.y]); + chesterGL.__tmp_mouse_vec.set([pt.x, pt.y, 0]); for (; i < len; i++) { - chesterGL.mouseHandlers[i](__tmp_mouse_vec, chesterGL.mouseEvents.MOVE); + chesterGL.mouseHandlers[i](chesterGL.__tmp_mouse_vec, chesterGL.mouseEvents.MOVE); } }; @@ -884,15 +922,28 @@ chesterGL.mouseMoveHandler = function (event) { chesterGL.mouseUpHandler = function (event) { var pt = chesterGL.canvas.relativePosition(event); var i = 0, len = chesterGL.mouseHandlers.length; - __tmp_mouse_vec.set([pt.x, pt.y]); + chesterGL.__tmp_mouse_vec.set([pt.x, pt.y, 0]); for (; i < len; i++) { - chesterGL.mouseHandlers[i](__tmp_mouse_vec, chesterGL.mouseEvents.UP); + chesterGL.mouseHandlers[i](chesterGL.__tmp_mouse_vec, chesterGL.mouseEvents.UP); } }; /** - * @param {function(goog.math.Vec2, number)} callback - * @ignore + * Adds a mouse handler: the function will be called for every mouse event on the main canvas + * @param {function((Array|Float32Array), chesterGL.mouseEvents)} callback + * @example + * var stPoint = null; + * chesterGL.addMouseHandler(function (pt, type) { + * if (type == chesterGL.mouseEvents.DOWN) { + * stPoint = new Float32Array(pt); + * } else if (type == chesterGL.mouseEvents.MOVE && stPoint) { + * var tmp = [pt[0] - stPoint[0], pt[1] - stPoint[1], pt[2] - stPoint[2]]; + * tmx.setPosition([tmx.position[0] + tmp[0], tmx.position[1] + tmp[1], tmx.position[2] + tmp[2]]); + * stPoint.set(pt); + * } else { + * stPoint = null; + * } + * }); */ chesterGL.addMouseHandler = function (callback) { if (chesterGL.mouseHandlers.indexOf(callback) == -1) { @@ -901,8 +952,8 @@ chesterGL.addMouseHandler = function (callback) { }; /** - * @param {function(goog.vec.Vec3.Vec3Like, number)} callback - * @ignore + * Removes a specific mouse handler. + * @param {function((Array|Float32Array), chesterGL.mouseEvents)} callback */ chesterGL.removeMouseHandler = function (callback) { var idx = chesterGL.mouseHandlers.indexOf(callback); @@ -938,6 +989,7 @@ chesterGL.togglePause = function () { }; // properties +goog.exportSymbol('chesterGL.version', chesterGL.version); goog.exportSymbol('chesterGL.useGoogleAnalytics', chesterGL.useGoogleAnalytics); goog.exportSymbol('chesterGL.projection', chesterGL.projection); goog.exportSymbol('chesterGL.webglMode', chesterGL.webglMode); diff --git a/chesterGL/tmxBlock.js b/chesterGL/tmxBlock.js index a99e6a7..bd9b178 100644 --- a/chesterGL/tmxBlock.js +++ b/chesterGL/tmxBlock.js @@ -103,32 +103,38 @@ chesterGL.TMXBlock.prototype.render = function () {}; * The size (in pixels) of the tiles (in the texture) * * @type {?goog.math.Size} + * @ignore */ chesterGL.TMXBlock.prototype.tileSize = null; /** * The tile size in the map * @type {?goog.math.Size} + * @ignore */ chesterGL.TMXBlock.prototype.mapTileSize = null; /** * @type {number} + * @ignore */ chesterGL.TMXBlock.prototype.totalTiles = 0; /** * @type {number} + * @ignore */ chesterGL.TMXBlock.prototype.spacing = 0; /** * @type {number} + * @ignore */ chesterGL.TMXBlock.prototype.margin = 0; /** * @type {Object.} + * @ignore */ chesterGL.TMXBlock.maps = {}; diff --git a/html/test_particles.html b/html/test_particles.html index aed06f4..06dd5d0 100644 --- a/html/test_particles.html +++ b/html/test_particles.html @@ -133,19 +133,6 @@ showData(); } - var fullScreen = false; - $("#fullScreen").click(function () { - var canvas = document.getElementById("game-container"); - canvas.onwebkitfullscreenchange = function () { - fullScreen = !fullScreen; - console.log("we went full screen: " + fullScreen); - canvas.webkitCancelFullScreen(); - } - if (!fullScreen) { - canvas.webkitRequestFullScreen(); - } - }); - $("#initial_color").ColorPicker({ onSubmit: function(hsb, hex, rgb, el) { $(el).val("#" + hex); @@ -198,7 +185,6 @@
- 00 ms per frame
diff --git a/html/test_tmx_iso_loader.html b/html/test_tmx_iso_loader.html index 000d0d6..913332d 100644 --- a/html/test_tmx_iso_loader.html +++ b/html/test_tmx_iso_loader.html @@ -48,18 +48,6 @@ }); } // setupGame() - var fullScreen = false; - $("#fullScreen").click(function () { - var canvas = document.getElementById("game-container"); - canvas.onwebkitfullscreenchange = function () { - fullScreen = !fullScreen; - console.log("we went full screen: " + fullScreen); - canvas.webkitCancelFullScreen(); - } - if (!fullScreen) { - canvas.webkitRequestFullScreen(); - } - }); });