pre-refactor
authorJimmy Christensen <dusted@dusted.dk>
Sun, 14 Feb 2016 16:13:34 +0000 (17:13 +0100)
committerJimmy Christensen <dusted@dusted.dk>
Sun, 14 Feb 2016 16:13:34 +0000 (17:13 +0100)
game/data/gl/2d_fragment.js
game/data/gl/2d_vertex.js
game/data/packs/000_wizznic/themes/thor/tiles/thor.png
game/src/DstEng-first.js [deleted file]
game/src/DstEng.js
game/src/DstEng2.js [deleted file]
game/src/Wizznic.js
package.json

index aaf20b5..67d7ad7 100644 (file)
@@ -1,4 +1,4 @@
-precision lowp float;
+precision highp float;
  
 // our texture
 uniform sampler2D u_image; 
@@ -9,5 +9,9 @@ varying vec2 v_texCoord;
 
 void main() {
    // Look up a color from the texture.
-   gl_FragColor = texture2D(u_image, v_texCoord);
+   vec4 col = texture2D(u_image, v_texCoord);
+   if( col.rgb == vec3( 0.0, 1.0, 1.0 ) )
+   discard;
+   
+   gl_FragColor = col;
 }
\ No newline at end of file
index 587047d..09968f2 100644 (file)
@@ -13,7 +13,7 @@ varying vec2 v_texCoord;
 void main() {
     // convert the rectangle from pixels to 0.0 to 1.0
     vec2 position = a_position + u_translation;
 //  vec2 position = a_position + floor(u_translation);
//   vec2 position = a_position + floor(u_translation);
     
     vec2 zeroToOne = position / u_resolution;
  
index 0d41384..6890adb 100644 (file)
Binary files a/game/data/packs/000_wizznic/themes/thor/tiles/thor.png and b/game/data/packs/000_wizznic/themes/thor/tiles/thor.png differ
diff --git a/game/src/DstEng-first.js b/game/src/DstEng-first.js
deleted file mode 100644 (file)
index 8348cb0..0000000
+++ /dev/null
@@ -1,656 +0,0 @@
-/* globals $ */
-
-var timeScale=1;
-
-function DstEng(config) {
-this.accTs =0;
-    this.res = {};
-
-
-    this.state = {
-        timeDelta: 0,
-        tdAvg: 0.0,
-        lastTime: 0,
-        frame: 0,
-        virtRes: [320, 240],
-        pointer: {
-            pos: [0, 0],
-            down: false
-        }
-    };
-
-
-    var ok = true;
-    this.cfg = config;
-
-    this.log("DstEng Startup:", this.cfg);
-
-    this.cfg.screen.width = this.cfg.width;
-    this.cfg.screen.height = this.cfg.height;
-    console.log(this.cfg.screen.height);
-
-    if (this.initGl()) {
-        this.log("Configured gl rendering");
-    } else {
-        this.log("Fail, no rendering available");
-        ok = false;
-    }
-
-    if (ok) {
-        this.preLoad();
-    } else {
-        this.cfg.readyCallback(false);
-    }
-
-
-
-}
-
-DstEng.prototype.log = function() {
-    console.log.apply(console, arguments);
-};
-
-DstEng.prototype.initGl = function() {
-    try {
-        this.gl = this.cfg.screen.getContext("experimental-webgl");
-        this.gl.viewportWidth = this.cfg.screen.width;
-        this.gl.viewportHeight = this.cfg.screen.height;
-    } catch (e) {}
-
-    return !!this.gl;
-};
-
-
-
-DstEng.prototype.isPowerOf2 = function(value) {
-    return (value & (value - 1)) === 0;
-};
-
-DstEng.prototype.setupTextureFiltering = function(width, height) {
-    if (this.isPowerOf2(width) && this.isPowerOf2(height)) {
-        // the dimensions are power of 2 so generate mips and turn on 
-        // tri-linear filtering.
-        this.gl.generateMipmap(this.gl.TEXTURE_2D);
-        //             this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MIN_FILTER, this.gl.LINEAR_MIPMAP_LINEAR);
-        this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MIN_FILTER, this.gl.NEAREST_MIPMAP_NEAREST);
-    } else {
-        // at least one of the dimensions is not a power of 2 so set the filtering
-        // so WebGL will render it.
-        this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_S, this.gl.CLAMP_TO_EDGE);
-        this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_T, this.gl.CLAMP_TO_EDGE);
-        this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MIN_FILTER, this.gl.LINEAR);
-        this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MAG_FILTER, this.gl.NEAREST);
-    }
-};
-
-
-DstEng.prototype.imgLoader = function(obj, cb) {
-
-    var image = new Image();
-    image.src = obj.url;
-    image.addEventListener('load', function() {
-
-        var texture = this.gl.createTexture();
-        this.gl.bindTexture(this.gl.TEXTURE_2D, texture);
-        // Fill the texture with a 1x1 blue pixel.
-        this.gl.texImage2D(this.gl.TEXTURE_2D, 0, this.gl.RGBA, 1, 1, 0, this.gl.RGBA, this.gl.UNSIGNED_BYTE,
-            new Uint8Array([0, 0, 255, 255]));
-        // Asynchronously load an image
-
-        this.gl.bindTexture(this.gl.TEXTURE_2D, texture);
-        this.gl.texImage2D(this.gl.TEXTURE_2D, 0, this.gl.RGBA, this.gl.RGBA, this.gl.UNSIGNED_BYTE, image);
-
-        this.setupTextureFiltering(image.width, image.height);
-
-        cb({
-            valid: true,
-            resType: 'img',
-            image: image,
-            texture: texture
-        });
-    }.bind(this));
-    image.addEventListener('error', function(e) {
-        cb({
-            valid: false,
-            error: 'Could not load the image'
-        });
-    });
-};
-
-DstEng.prototype.compileShader = function(gl, shaderSource, shaderType) {
-    // Create the shader object
-    var obj = {
-        valid: true
-    };
-    var shader = gl.createShader(shaderType);
-
-
-    // Set the shader source code.
-    gl.shaderSource(shader, shaderSource);
-
-    // Compile the shader
-    gl.compileShader(shader);
-
-    // Check if it compiled
-    var success = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
-    if (!success) {
-        // Something went wrong during compilation; get the error
-        obj.valid = false;
-        obj.error = 'Compilation failed: ' + gl.getShaderInfoLog(shader);
-
-    } else {
-        obj.shaderType = shaderType;
-        obj.resType = (shaderType === gl.FRAGMENT_SHADER) ? 'fragment_shader' : 'vertex_shader';
-        obj.shader = shader;
-    }
-
-    return obj;
-};
-
-DstEng.prototype.createProgram = function(gl, vertexShader, fragmentShader) {
-    // create a program.
-    var program = gl.createProgram();
-
-    // attach the shaders.
-    gl.attachShader(program, vertexShader);
-    gl.attachShader(program, fragmentShader);
-
-    // link the program.
-    gl.linkProgram(program);
-
-    // Check if it linked.
-    var success = gl.getProgramParameter(program, gl.LINK_STATUS);
-    if (!success) {
-        // something went wrong with the link
-        throw ("program failed to link:" + gl.getProgramInfoLog(program));
-    }
-
-    var resObj = {
-        resType: 'shader_program',
-        program: program,
-        a_texCoord: gl.getAttribLocation(program, "a_texCoord"),
-        a_pos: gl.getAttribLocation(program, "a_position"),
-        u_frameSize: gl.getUniformLocation(program, "u_frameSize"),
-        u_frameGridPos: gl.getUniformLocation(program, "u_frameGridPos"),
-        u_res: gl.getUniformLocation(program, "u_resolution"),
-        u_translation: gl.getUniformLocation(program, "u_translation")
-    };
-
-    //Enable textures and verticies for out programs
-    gl.enableVertexAttribArray(resObj.a_pos);
-    gl.enableVertexAttribArray(resObj.a_texCoord);
-
-    //Set default resolution
-    gl.useProgram(program);
-    gl.uniform2fv(resObj.u_res, this.state.virtRes);
-
-    return resObj;
-};
-
-
-DstEng.prototype.shaderLoader = function(obj, cb) {
-    $.ajax({
-        url: obj.url,
-        dataType: 'text',
-        success: function(data) {
-            cb(this.compileShader(this.gl, data, obj.shaderType));
-        }.bind(this),
-        error: function(e) {
-            cb({
-                valid: false,
-                error: e.status + ' ' + e.statusText
-            });
-        }
-    });
-};
-
-
-DstEng.prototype.resLoader = function(loadList, done) {
-    var left = loadList.length;
-    var loaded = 0;
-
-    loadList.forEach(function(r) {
-        r.loader(r, function(data) {
-            if (data) {
-                this.addRes(r.name, data);
-                loaded++;
-            }
-            left--;
-
-            if (!data.valid) {
-                this.log('Resource loading failed for "' + r.name + '" from "' + r.url + '" error:', data.error);
-            }
-            if (left === 0) {
-                done((loaded != loadList.length));
-            }
-        }.bind(this));
-    }, this);
-};
-
-DstEng.prototype.preLoad = function() {
-    var res = [{
-            name: 'img_DstEng',
-            url: '/data/img/DstEng.jpg',
-            loader: this.imgLoader.bind(this)
-        }, {
-            name: 'img_tiles',
-            url: '/data/packs/000_wizznic/themes/thor/tiles/thor.png',
-            loader: this.imgLoader.bind(this)
-        }, {
-            name: 'shader_vertex2d',
-            url: '/data/gl/2d_vertex.js',
-            shaderType: this.gl.VERTEX_SHADER,
-            loader: this.shaderLoader.bind(this)
-        }, {
-            name: 'shader_fragment2d',
-            url: '/data/gl/2d_fragment.js',
-            shaderType: this.gl.FRAGMENT_SHADER,
-            loader: this.shaderLoader.bind(this)
-        }, {
-            name: 'shader_fragment2d_sat',
-            url: '/data/gl/2d_fragment_sat.js',
-            shaderType: this.gl.FRAGMENT_SHADER,
-            loader: this.shaderLoader.bind(this)
-        }
-
-    ];
-
-    this.resLoader(res, function(err) {
-        if (!err) {
-            this.startLoader();
-        } else {
-            this.cfg.readyCallback(true);
-        }
-    }.bind(this));
-
-
-};
-
-DstEng.prototype.realCoordsToGl = function(evt) {
-    var r = this.cfg.screen.getBoundingClientRect();
-    var sx = this.state.virtRes[0] / this.cfg.screen.width;
-    var sy = this.state.virtRes[1] / this.cfg.screen.height;
-    return ([(evt.clientX - r.left) * sx, (evt.clientY - r.top) * sy]);
-};
-
-DstEng.prototype.setPointerState = function(e) {
-    this.state.pointer.pos = this.realCoordsToGl(e);
-};
-
-
-DstEng.prototype.onMouseMove = function(cb) {
-    this.cfg.screen.addEventListener('mousemove', function(e) {
-        this.setPointerState(e);
-        cb(this.state.pointer);
-    }.bind(this));
-};
-
-DstEng.prototype.onMouseClick = function(cb) {
-    this.cfg.screen.addEventListener('mousedown', function(e) {
-        this.setPointerState(e);
-        this.state.pointer.down = true;
-        cb(this.state.pointer);
-    }.bind(this));
-
-    this.cfg.screen.addEventListener('mouseup', function(e) {
-        this.setPointerState(e);
-        this.state.pointer.down = false;
-        cb(this.state.pointer);
-    }.bind(this));
-};
-
-
-DstEng.prototype.randomInt = function(range) {
-    return Math.floor(Math.random() * range);
-};
-
-DstEng.prototype.addRes = function(name, resource) {
-
-    if (this.res.hasOwnProperty(name)) {
-        this.log('Note: Overriding existing resource ' + name);
-        this.log('Ow: ', this.res[name]);
-        this.log('By: ', resource);
-
-    }
-    if (resource.type) {
-        this.log('No type defined for ' + name);
-    }
-
-    this.res[name] = resource;
-
-    return (resource);
-};
-
-
-DstEng.prototype.startLoader = function() {
-
-    this.addRes('glPrg', this.createProgram(this.gl, this.res.shader_vertex2d.shader, this.res.shader_fragment2d.shader));
-    this.addRes('glPrgSat', this.createProgram(this.gl, this.res.shader_vertex2d.shader, this.res.shader_fragment2d_sat.shader));
-
-    //this.gl.useProgram( this.res.glPrg.program );
-
-    // The idea is to have:
-    // DrawGroups, each member of this group will be drawn using the same program
-    //  - PolyGroups, each member will be drawn using the same program and vertex geometry
-    //     - TexGroups, each member will be drawn using the same program, vertex, geometry and texture, it will contain an array of texCoord arrays to be used
-    //        - Sprite, each sprite will be drawn at a desired position, using the desired texCoord array, optional array of program params may be supplied
-    // Usage:
-    // Create a vertexbuffers
-    // Create a dg
-    // Create a pg and add to dg
-    // Create a tg and add to pg
-    // Create a sp and add to tg
-    // draw dgs
-
-    // "Add object: thisProgram, thatimage, " = { dg, pg, tg, sp } ?
-
-
-    /*...*/
-
-    var texture = new this.Texture(this.gl, {
-        img: this.res.img_DstEng,
-        cut: [0, 0, 160, 120],
-        numFrames: 1,
-        animate: false,
-        frameTime: 0
-    });
-
-
-
-
-    var drawGroup = new this.DrawGroup(this.gl, this.res.glPrg);
-
-
-
-    var w = 320,
-        h = 240;
-
-    var polyBuffer = this.gl.createBuffer();
-    this.gl.bindBuffer(this.gl.ARRAY_BUFFER, polyBuffer);
-    this.gl.bufferData(this.gl.ARRAY_BUFFER, new Float32Array([
-        0, 0,
-        0.0, 0.0,
-        w, 0,
-        1.0, 0.0,
-        0, h,
-        0.0, 1.0,
-        0, h,
-        0.0, 1.0,
-        w, 0,
-        1.0, 0.0,
-        w, h,
-        1.0, 1.0
-    ]), this.gl.STATIC_DRAW);
-
-    var brick = this.gl.createBuffer();
-    this.gl.bindBuffer(this.gl.ARRAY_BUFFER, brick);
-    w = h = 20;
-    var glw = 20 / 480;
-    this.gl.bufferData(this.gl.ARRAY_BUFFER, new Float32Array([
-        0, 0,
-        0.0, 0.0,
-        w, 0,
-        glw, 0.0,
-        0, h,
-        0.0, 1.0,
-        0, h,
-        0.0, 1.0,
-        w, 0,
-        glw, 0.0,
-        w, h,
-        glw, 1.0
-    ]), this.gl.STATIC_DRAW);
-
-    var bricks = new this.PolyGroup(brick);
-    var brickTex = new this.Texture(this.gl, {
-        img: this.res.img_tiles,
-        cut: [0, 0, 20, 20],
-        numFrames: 10,
-        frameTime: 100,
-        animate: true
-    });
-
-
-
-    var brickTexGroup = new this.TexGroup(brickTex);
-
-    var sprite;
-    this.Sprite.prototype.animate = function() {
-        this.pos[0] += this.vx*timeScale;
-        this.pos[1] += this.vy*timeScale;
-
-        if (this.pos[0] < 0) {
-            this.pos[0] = 0;
-            this.vx *= -1;
-            this.frameGridPos[0]++;
-            if(this.frameGridPos[0] > 9) {
-                this.frameGridPos[0]=0;
-            }
-        } else if (this.pos[0] > 320 - 20) {
-            this.pos[0] = 320 - 20;
-            this.vx *= -1;
-//            this.frameGridPos = [Math.floor(Math.random() * 10), 0];
-            this.frameGridPos[0]++;
-            if(this.frameGridPos[0] > 9) {
-                this.frameGridPos[0]=0;
-            }
-        }
-
-        if (this.pos[1] < 0) {
-            this.frameGridPos[0]++;
-            if(this.frameGridPos[0] > 9) {
-                this.frameGridPos[0]=0;
-            }
-  //          this.frameGridPos = [Math.floor(Math.random() * 10), 0];
-            this.pos[1] = 0;
-            this.vy *= -1;
-        } else if (this.pos[1] > 240 - 20) {
-    //        this.frameGridPos = [Math.floor(Math.random() * 10), 0];
-            this.frameGridPos[0]++;
-            if(this.frameGridPos[0] > 9) {
-                this.frameGridPos[0]=0;
-            }
-            this.pos[1] = 240 - 20;
-            this.vy *= -1;
-        }
-
-    };
-
-    for (var i = 0; i < 100000; ++i) {
-        sprite = new this.Sprite();
-        sprite.frameGridPos = [Math.floor(Math.random() * 10), 0];
-        sprite.vx = Math.random()*4-2;
-        sprite.vy = Math.random()*4-2;
-        
-       // sprite.animate = animate.bind(sprite);
-        brickTexGroup.addSprite(sprite);
-    }
-
-
-    bricks.addTexGroup(brickTexGroup);
-
-    var backgrounds = new this.PolyGroup(polyBuffer);
-
-    drawGroup.addPolyGroup(backgrounds);
-
-    drawGroup.addPolyGroup(bricks);
-
-    var bgTexSingle = new this.TexGroup(texture);
-
-
-    //Add an empty s
-    bgTexSingle.addSprite(new this.Sprite());
-
-
-    backgrounds.addTexGroup(bgTexSingle);
-
-
-
-
-    this.dg = drawGroup;
-
-
-
-    this.drawFrame();
-    //Say we are ready
-    this.cfg.readyCallback(true);
-};
-
-DstEng.prototype.Texture = (function() {
-    function Tex(gl, setup) {
-
-        if (!gl) {
-            throw Error('Need gl');
-        }
-
-        if (!setup.img.resType) {
-            throw Error('Required: img.');
-        }
-
-        if (!setup.img.image || !setup.img.image.height) {
-            throw Error('Invalid or no image in setup.img');
-        }
-
-        this.w = setup.img.image.width;
-        this.h = setup.img.image.height;
-
-        this.numFrames = setup.numFrames || 1;
-        this.animate = setup.animate || false;
-        this.frameTime = setup.frameTime || false;
-
-        this.pxCut = setup.cut || [0, 0, this.w, this.h];
-
-        this.glTex = setup.img.texture;
-
-        this.glFrameSize = new Float32Array([(this.pxCut[2] / this.w), (this.pxCut[3] / this.h)]);
-
-    }
-
-    return Tex;
-}());
-
-DstEng.prototype.DrawGroup = (function() {
-    function Dg(gl, prgInfo) {
-        this.prgInfo = prgInfo;
-        this.polyGroups = [];
-    }
-
-    Dg.prototype.addPolyGroup = function(pg) {
-        this.polyGroups.push(pg);
-    };
-
-    Dg.prototype.draw = function(gl) {
-
-        //Program is same for all drawGroups
-        var prgInfo = this.prgInfo;
-        gl.useProgram(prgInfo.program);
-
-        this.polyGroups.forEach(function drawPolyGroup(pg) {
-
-            //VertexBuffer is the same for a polygroup
-            gl.bindBuffer(gl.ARRAY_BUFFER, pg.buffer);
-            gl.vertexAttribPointer(prgInfo.a_pos, 2, gl.FLOAT, false, pg.stride, pg.vertexOffset);
-            gl.vertexAttribPointer(prgInfo.a_texCoord, 2, gl.FLOAT, false, pg.stride, pg.texCoordOffset);
-
-            pg.texGroups.forEach(function drawTexGroup(tg) {
-                //Texture is the same for each texGroup
-                gl.bindTexture(gl.TEXTURE_2D, tg.texture.glTex);
-
-                gl.uniform2fv(prgInfo.u_frameSize, tg.texture.glFrameSize);
-                tg.sprites.forEach(function drawSprite(spr) {
-                    //Set geometry location and texture location
-                    if (spr.vx) spr.animate();
-
-                    gl.uniform2fv(prgInfo.u_translation, spr.pos);
-                    gl.uniform2fv(prgInfo.u_frameGridPos, spr.frameGridPos);
-
-
-
-                    gl.drawArrays(gl.TRIANGLES, 0, 6);
-                });
-            });
-        });
-    };
-
-    return Dg;
-}());
-
-DstEng.prototype.PolyGroup = (function() {
-    function Pg(buffer) {
-        this.buffer = buffer;
-        this.vertexOffset = 0;
-        this.texCoordOffset = Float32Array.BYTES_PER_ELEMENT * 2;
-        this.stride = Float32Array.BYTES_PER_ELEMENT * 4;
-        this.texGroups = [];
-    }
-
-    Pg.prototype.addTexGroup = function(tg) {
-        this.texGroups.push(tg);
-    };
-
-    return Pg;
-}());
-
-DstEng.prototype.TexGroup = (function() {
-    function Tg(texture) {
-        this.texture = texture;
-        this.sprites = [];
-    }
-
-    Tg.prototype.addSprite = function(spr) {
-        this.sprites.push(spr);
-    };
-
-    return Tg;
-}());
-
-
-DstEng.prototype.Sprite = (function() {
-    function Spr() {
-        this.pos = new Float32Array([0, 0]);
-        this.frameGridPos = [0, 0];
-    }
-
-    Spr.prototype.setPos = function(pos) {
-        this.pos = pos;
-    };
-
-
-    return Spr;
-}());
-
-
-
-DstEng.prototype.drawFrame = function(timeStamp) {
-
-    timeStamp = timeStamp || 16.0;
-
-    this.state.timeDelta = timeStamp - this.state.lastTime;
-    
-    timeScale = this.state.timeDelta/16.00;
-    this.accTs +=timeScale;
-  //  console.log(timeScale);
-    
-    this.state.lastTime = timeStamp;
-
-    this.state.frame++;
-    this.state.tdAvg += this.state.timeDelta;
-
-
-
-
-    if (this.state.frame % 120 === 0) {
-        this.state.fps = 1000 / this.state.timeDelta;
-        console.log(this.state.fps, (1000.0 / (this.state.tdAvg / this.state.frame)), this.state.tdAvg - timeStamp, this.state.frame, this.accTs/this.state.frame);
-    }
-
-
-    //  this.spr.pos = this.state.pointer.pos;
-    //    this.spr.frameGridPos = [ Math.floor(this.state.pointer.pos[0]) % 10, 0 ];
-    this.dg.draw(this.gl);
-
-
-    window.requestAnimationFrame(this.drawFrame.bind(this));
-
-};
\ No newline at end of file
index ad05e81..0e0e764 100644 (file)
@@ -50,9 +50,20 @@ DstEng.prototype.log = function() {
 
 DstEng.prototype.initGl = function() {
     try {
-        this.gl = this.cfg.screen.getContext("experimental-webgl");
+        this.gl = this.cfg.screen.getContext("webgl");
+        if(! this.gl ) { 
+            this.gl = this.cfg.screen.getContext("experimental-webgl");
+        }
         this.gl.viewportWidth = this.cfg.screen.width;
         this.gl.viewportHeight = this.cfg.screen.height;
+  
+  
+  //http://mrdoob.github.io/webgl-blendfunctions/blendfunc.html      
+/*        var gl = this.gl;
+gl.enable( gl.BLEND );
+gl.blendEquation( gl.FUNC_ADD );
+gl.blendFunc( gl.SRC_ALPHA, gl.DST_ALPHA ); */
     } catch (e) {}
 
     return !!this.gl;
@@ -69,7 +80,7 @@ DstEng.prototype.setupTextureFiltering = function(width, height) {
         // the dimensions are power of 2 so generate mips and turn on 
         // tri-linear filtering.
         this.gl.generateMipmap(this.gl.TEXTURE_2D);
-        //             this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MIN_FILTER, this.gl.LINEAR_MIPMAP_LINEAR);
+        this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MAG_FILTER, this.gl.LINEAR_MIPMAP_LINEAR);
         this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MIN_FILTER, this.gl.NEAREST_MIPMAP_NEAREST);
     } else {
         // at least one of the dimensions is not a power of 2 so set the filtering
@@ -78,6 +89,8 @@ DstEng.prototype.setupTextureFiltering = function(width, height) {
         this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_T, this.gl.CLAMP_TO_EDGE);
         this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MIN_FILTER, this.gl.LINEAR);
         this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MAG_FILTER, this.gl.NEAREST);
+
+
     }
 };
 
@@ -241,11 +254,9 @@ DstEng.prototype.sndLoader = function(obj, cb) {
             var snd = {
                 valid: true,
                 resType: 'snd',
-                sound: this.audio.add(buffer)
+                play: this.audio.play.bind(this.audio, buffer)
             };
 
-
-
             console.log(snd);
             cb(snd);
 
@@ -257,24 +268,131 @@ DstEng.prototype.sndLoader = function(obj, cb) {
 
 };
 
+DstEng.prototype.jsonLoader = function(obj, cb) {
+    $.ajax({
+        url: obj.url,
+        dataType: 'text',
+        success: function(data) {
+
+            var ret = false;
+
+            try {
+                ret = JSON.parse(data);
+            } catch (e) {
+                ret = false;
+            }
+            cb({
+                valid: !!(ret),
+                value: ret
+            });
+        }.bind(this),
+        error: function(e) {
+            cb({
+                valid: false,
+                error: e.status + ' ' + e.statusText
+            });
+        }
+    });
+};
+
+DstEng.prototype.parseIni = function(txt) {
+
+    var ret = {};
+
+    var lines = txt.split('\n');
+
+    var trimmed = [];
+
+    var curSegment = '_root';
+
+    lines.forEach(function(l) {
+        //Strip comments
+        var idx = l.indexOf('#');
+        if (idx !== -1) {
+            l = l.substring(0, idx);
+        }
+
+        //Trim trailing whitespace
+        l = l.trim();
+
+        if (l.length > 0) {
+            trimmed.push(l);
+        }
+    });
+
+
+    trimmed.forEach(function(l) {
+        //Is this line an assignment?
+        var eqIdx = l.indexOf('=');
+        if (eqIdx !== -1) {
+            var spl = l.split('=');
+            var keyName = spl[0];
+            var val = spl.slice(1).join('=');
+
+            if (!ret[curSegment]) {
+                ret[curSegment] = {};
+            }
+
+            if (!ret[curSegment][keyName]) {
+                ret[curSegment][keyName] = val;
+            } else {
+                if (!Array.isArray(ret[curSegment][keyName])) {
+                    ret[curSegment][keyName] = [ret[curSegment][keyName]];
+                }
+                ret[curSegment][keyName].push(val);
+            }
+        } else if (l.charAt(0) === '[' && l.charAt(l.length - 1) === ']') {
+            curSegment = l.substring(1, l.length - 1);
+        } else {
+            if (!ret[curSegment]) {
+                ret[curSegment] = {
+                    _block: []
+                };
+            }
+
+            ret[curSegment]._block.push(l);
+        }
+    });
+
+    return (ret);
+};
+
+DstEng.prototype.iniLoader = function(obj, cb) {
+    $.ajax({
+        url: obj.url,
+        dataType: 'text',
+        success: function(data) {
+
+            var ret = this.parseIni(data);
+
+            cb({
+                valid: !!(ret),
+                value: ret
+            });
+        }.bind(this),
+        error: function(e) {
+            cb({
+                valid: false,
+                error: e.status + ' ' + e.statusText
+            });
+        }
+    });
+};
+
 DstEng.prototype.audio = (function() {
     function Aud() {
-        this.sounds = [];
+
         window.AudioContext = window.AudioContext || window.webkitAudioContext;
         this.ctx = new AudioContext();
     }
 
-    Aud.prototype.play = function(idx) {
+    Aud.prototype.play = function(buffer) {
         var source = this.ctx.createBufferSource();
-        source.buffer = this.sounds[idx];
+        source.buffer = buffer;
         source.connect(this.ctx.destination);
         source.start(0);
     };
 
-    Aud.prototype.add = function(buffer) {
-        return this.sounds.push(buffer) - 1;
-    };
-
     return new Aud();
 }());
 
@@ -294,6 +412,14 @@ DstEng.prototype.preLoad = function() {
             url: '/data/packs/000_wizznic/themes/oldskool/snd/click.ogg',
             loader: this.sndLoader.bind(this)
         }, {
+            name: 'structure_test',
+            url: '/data/test.json',
+            loader: this.jsonLoader.bind(this)
+        }, {
+            name: 'ini_test',
+            url: '/data/packs/000_wizznic/info.ini',
+            loader: this.iniLoader.bind(this)
+        }, {
             name: 'shader_vertex2d',
             url: '/data/gl/2d_vertex.js',
             shaderType: this.gl.VERTEX_SHADER,
@@ -316,7 +442,7 @@ DstEng.prototype.preLoad = function() {
         if (!err) {
             this.startLoader();
         } else {
-            this.cfg.readyCallback(true);
+            this.cfg.readyCallback(false);
         }
     }.bind(this));
 
@@ -372,10 +498,6 @@ DstEng.prototype.onMouseClick = function(cb) {
 };
 
 
-DstEng.prototype.randomInt = function(range) {
-    return Math.floor(Math.random() * range);
-};
-
 DstEng.prototype.addRes = function(name, resource) {
 
     if (this.res.hasOwnProperty(name)) {
@@ -393,32 +515,11 @@ DstEng.prototype.addRes = function(name, resource) {
     return (resource);
 };
 
-
 DstEng.prototype.startLoader = function() {
 
     this.addRes('glPrg', this.createProgram(this.gl, this.res.shader_vertex2d.shader, this.res.shader_fragment2d.shader));
     this.addRes('glPrgSat', this.createProgram(this.gl, this.res.shader_vertex2d.shader, this.res.shader_fragment2d_sat.shader));
 
-    //this.gl.useProgram( this.res.glPrg.program );
-
-    // The idea is to have:
-    // DrawGroups, each member of this group will be drawn using the same program
-    //  - PolyGroups, each member will be drawn using the same program and vertex geometry
-    //     - TexGroups, each member will be drawn using the same program, vertex, geometry and texture, it will contain an array of texCoord arrays to be used
-    //        - Sprite, each sprite will be drawn at a desired position, using the desired texCoord array, optional array of program params may be supplied
-    // Usage:
-    // Create a vertexbuffers
-    // Create a dg
-    // Create a pg and add to dg
-    // Create a tg and add to pg
-    // Create a sp and add to tg
-    // draw dgs
-
-    // "Add object: thisProgram, thatimage, " = { dg, pg, tg, sp } ?
-
-
-    /*...*/
-
     var texture = new this.Texture(this.gl, {
         img: this.res.img_DstEng,
         cut: [0, 0, 160, 120],
@@ -428,10 +529,9 @@ DstEng.prototype.startLoader = function() {
     });
 
 
-
-
     var drawGroup = new this.DrawGroup(this.gl, this.res.glPrg);
 
+    console.log(this.res);
 
 
     var w = 320,
@@ -488,7 +588,7 @@ DstEng.prototype.startLoader = function() {
 
     var sprite;
 
-    var audio = this.audio;
+    var snd = this.res.snd_click;
 
     this.Sprite.prototype.animate = function() {
         this.pos[0] += this.vx * timeScale;
@@ -497,7 +597,7 @@ DstEng.prototype.startLoader = function() {
         if (this.pos[0] < 0) {
             this.pos[0] = 0;
             this.vx *= -1;
-            audio.play(0);
+            //   snd.play();
             this.frameGridPos[0]++;
             if (this.frameGridPos[0] > 9) {
                 this.frameGridPos[0] = 0;
@@ -534,15 +634,14 @@ DstEng.prototype.startLoader = function() {
 
     for (var i = 0; i < 10; ++i) {
         sprite = new this.Sprite([300, 220]);
-        sprite.frameGridPos = [Math.floor(Math.random() * 10), 0];
-        sprite.vx = Math.random() * 16 - 8;
-        sprite.vy = Math.random() * 16 - 8;
+        sprite.frameGridPos = [Math.floor(Math.random() * 15), 0];
+        sprite.vx = Math.random() * 0.5 - 0.25;
+        sprite.vy = Math.random() * 0.5 - 0.25;
 
         // sprite.animate = animate.bind(sprite);
         brickTexGroup.addSprite(sprite);
     }
 
-
     bricks.addTexGroup(brickTexGroup);
 
     var backgrounds = new this.PolyGroup(polyBuffer);
@@ -561,17 +660,16 @@ DstEng.prototype.startLoader = function() {
     backgrounds.addTexGroup(bgTexSingle);
 
 
-
-
     this.dg = drawGroup;
 
 
-
     this.drawFrame();
     //Say we are ready
     this.cfg.readyCallback(true);
 };
 
+
+//TODO: Rewrite to use vertex arrays for texture coords instead.
 DstEng.prototype.Texture = (function() {
     function Tex(gl, setup) {
 
@@ -704,7 +802,6 @@ DstEng.prototype.drawFrame = function(timeStamp) {
     } else {
         this.state.timeDelta = 16.0;
         this.state.lastTime = performance.now();
-        console.log('aa', this.state.timeDelta, this.state.lastTime);
     }
 
 
@@ -717,7 +814,11 @@ DstEng.prototype.drawFrame = function(timeStamp) {
 
 
     if (timeScale > 10) {
-        console.log('warning, timescale is large', timeScale);
+        console.log('warning, timescale is large (' + timeScale + ') clipping to 10 frames');
+        timeScale = 10;
+    } else if (timeScale < 0.25) {
+        console.log('warning, timescale is very small (' + timeScale + ') clipping to 0.25 frames');
+        timeScale = 0.25;
     }
 
 
diff --git a/game/src/DstEng2.js b/game/src/DstEng2.js
deleted file mode 100644 (file)
index 68b01e9..0000000
+++ /dev/null
@@ -1,632 +0,0 @@
-/* globals $ */
-
-var timeScale = 1;
-
-function DstEng(config) {
-    this.accTs = 0;
-    this.res = {};
-
-    this.drawGroups = [];
-
-    this.timeScale = 1.0;
-
-    this.state = {
-        timeDelta: 0,
-        tdAvg: 0.0,
-        lastTime: 0,
-        frame: 0,
-        virtRes: [320, 240],
-        pointer: {
-            pos: [0, 0],
-            down: false
-        }
-    };
-
-
-    var ok = true;
-    this.cfg = config;
-
-    this.log("DstEng Startup:", this.cfg);
-
-    this.cfg.screen.width = this.cfg.width;
-    this.cfg.screen.height = this.cfg.height;
-
-    if (this.initGl()) {
-        this.log("Configured gl rendering");
-    } else {
-        this.log("Fail, no rendering available");
-        ok = false;
-    }
-
-    if (ok) {
-        this.preLoad();
-    } else {
-        this.cfg.readyCallback(false);
-    }
-
-
-
-}
-
-DstEng.prototype.log = function() {
-    console.log.apply(console, arguments);
-};
-
-DstEng.prototype.initGl = function() {
-    try {
-        this.gl = this.cfg.screen.getContext("experimental-webgl");
-        this.gl.viewportWidth = this.cfg.screen.width;
-        this.gl.viewportHeight = this.cfg.screen.height;
-    } catch (e) {}
-
-    return !!this.gl;
-};
-
-
-
-DstEng.prototype.isPowerOf2 = function(value) {
-    return (value & (value - 1)) === 0;
-};
-
-DstEng.prototype.setupTextureFiltering = function(width, height) {
-    if (this.isPowerOf2(width) && this.isPowerOf2(height)) {
-        // the dimensions are power of 2 so generate mips and turn on 
-        // tri-linear filtering.
-        this.gl.generateMipmap(this.gl.TEXTURE_2D);
-        //             this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MIN_FILTER, this.gl.LINEAR_MIPMAP_LINEAR);
-        this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MIN_FILTER, this.gl.NEAREST_MIPMAP_NEAREST);
-    } else {
-        // at least one of the dimensions is not a power of 2 so set the filtering
-        // so WebGL will render it.
-        this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_S, this.gl.CLAMP_TO_EDGE);
-        this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_WRAP_T, this.gl.CLAMP_TO_EDGE);
-        this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MIN_FILTER, this.gl.LINEAR);
-        this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MAG_FILTER, this.gl.NEAREST);
-    }
-};
-
-
-DstEng.prototype.imgLoader = function(obj, cb) {
-
-    var image = new Image();
-    image.src = obj.url;
-    image.addEventListener('load', function() {
-
-        var texture = this.gl.createTexture();
-        this.gl.bindTexture(this.gl.TEXTURE_2D, texture);
-        // Fill the texture with a 1x1 blue pixel.
-        this.gl.texImage2D(this.gl.TEXTURE_2D, 0, this.gl.RGBA, 1, 1, 0, this.gl.RGBA, this.gl.UNSIGNED_BYTE,
-            new Uint8Array([0, 0, 255, 255]));
-        // Asynchronously load an image
-
-        this.gl.bindTexture(this.gl.TEXTURE_2D, texture);
-        this.gl.texImage2D(this.gl.TEXTURE_2D, 0, this.gl.RGBA, this.gl.RGBA, this.gl.UNSIGNED_BYTE, image);
-
-        this.setupTextureFiltering(image.width, image.height);
-
-        cb({
-            valid: true,
-            resType: 'img',
-            image: image,
-            texture: texture
-        });
-    }.bind(this));
-    image.addEventListener('error', function(e) {
-        cb({
-            valid: false,
-            error: 'Could not load the image'
-        });
-    });
-};
-
-DstEng.prototype.compileShader = function(gl, shaderSource, shaderType) {
-    // Create the shader object
-    var obj = {
-        valid: true
-    };
-    var shader = gl.createShader(shaderType);
-
-
-    // Set the shader source code.
-    gl.shaderSource(shader, shaderSource);
-
-    // Compile the shader
-    gl.compileShader(shader);
-
-    // Check if it compiled
-    var success = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
-    if (!success) {
-        // Something went wrong during compilation; get the error
-        obj.valid = false;
-        obj.error = 'Compilation failed: ' + gl.getShaderInfoLog(shader);
-
-    } else {
-        obj.shaderType = shaderType;
-        obj.resType = (shaderType === gl.FRAGMENT_SHADER) ? 'fragment_shader' : 'vertex_shader';
-        obj.shader = shader;
-    }
-
-    return obj;
-};
-
-DstEng.prototype.createProgram = function(gl, vertexShader, fragmentShader) {
-    // create a program.
-    var program = gl.createProgram();
-
-    // attach the shaders.
-    gl.attachShader(program, vertexShader);
-    gl.attachShader(program, fragmentShader);
-
-    // link the program.
-    gl.linkProgram(program);
-
-    // Check if it linked.
-    var success = gl.getProgramParameter(program, gl.LINK_STATUS);
-    if (!success) {
-        // something went wrong with the link
-        throw ("program failed to link:" + gl.getProgramInfoLog(program));
-    }
-
-    var resObj = {
-        resType: 'shader_program',
-        program: program,
-        a_texCoord: gl.getAttribLocation(program, "a_texCoord"),
-        a_pos: gl.getAttribLocation(program, "a_position"),
-        u_frameSize: gl.getUniformLocation(program, "u_frameSize"),
-        u_frameGridPos: gl.getUniformLocation(program, "u_frameGridPos"),
-        u_res: gl.getUniformLocation(program, "u_resolution"),
-        u_translation: gl.getUniformLocation(program, "u_translation")
-    };
-
-    //Enable textures and verticies for out programs
-    gl.enableVertexAttribArray(resObj.a_pos);
-    gl.enableVertexAttribArray(resObj.a_texCoord);
-
-    //Set default resolution
-    gl.useProgram(program);
-    gl.uniform2fv(resObj.u_res, this.state.virtRes);
-
-    return resObj;
-};
-
-
-DstEng.prototype.shaderLoader = function(obj, cb) {
-    $.ajax({
-        url: obj.url,
-        dataType: 'text',
-        success: function(data) {
-            cb(this.compileShader(this.gl, data, obj.shaderType));
-        }.bind(this),
-        error: function(e) {
-            cb({
-                valid: false,
-                error: e.status + ' ' + e.statusText
-            });
-        }
-    });
-};
-
-
-DstEng.prototype.resLoader = function(loadList, done) {
-    var left = loadList.length;
-    var loaded = 0;
-
-    loadList.forEach(function(r) {
-        r.loader(r, function(data) {
-            if (data) {
-                this.addRes(r.name, data);
-                loaded++;
-            }
-            left--;
-
-            if (!data.valid) {
-                this.log('Resource loading failed for "' + r.name + '" from "' + r.url + '" error:', data.error);
-            }
-            if (left === 0) {
-                done((loaded != loadList.length));
-            }
-        }.bind(this));
-    }, this);
-};
-
-DstEng.prototype.preLoad = function() {
-    var res = [{
-            name: 'img_DstEng',
-            url: '/data/img/DstEng.jpg',
-            loader: this.imgLoader.bind(this)
-        }, {
-            name: 'img_tiles',
-            url: '/data/packs/000_wizznic/themes/thor/tiles/thor.png',
-            loader: this.imgLoader.bind(this)
-        }, {
-            name: 'shader_vertex2d',
-            url: '/data/gl/2d_vertex.js',
-            shaderType: this.gl.VERTEX_SHADER,
-            loader: this.shaderLoader.bind(this)
-        }, {
-            name: 'shader_fragment2d',
-            url: '/data/gl/2d_fragment.js',
-            shaderType: this.gl.FRAGMENT_SHADER,
-            loader: this.shaderLoader.bind(this)
-        }, {
-            name: 'shader_fragment2d_sat',
-            url: '/data/gl/2d_fragment_sat.js',
-            shaderType: this.gl.FRAGMENT_SHADER,
-            loader: this.shaderLoader.bind(this)
-        }
-
-    ];
-
-    this.resLoader(res, function(err) {
-        if (!err) {
-            this.startLoader();
-        } else {
-            this.cfg.readyCallback(true);
-        }
-    }.bind(this));
-
-
-};
-
-DstEng.prototype.realCoordsToGl = function(evt) {
-    var r = this.cfg.screen.getBoundingClientRect();
-    var sx = this.state.virtRes[0] / this.cfg.screen.width;
-    var sy = this.state.virtRes[1] / this.cfg.screen.height;
-    return ([(evt.clientX - r.left) * sx, (evt.clientY - r.top) * sy]);
-};
-
-DstEng.prototype.setPointerState = function(e) {
-    this.state.pointer.pos = this.realCoordsToGl(e);
-};
-
-
-DstEng.prototype.onMouseMove = function(cb) {
-    this.cfg.screen.addEventListener('mousemove', function(e) {
-        this.setPointerState(e);
-        cb(this.state.pointer);
-    }.bind(this));
-};
-
-DstEng.prototype.onMouseClick = function(cb) {
-    this.cfg.screen.addEventListener('mousedown', function(e) {
-        this.setPointerState(e);
-        this.state.pointer.down = true;
-        cb(this.state.pointer);
-    }.bind(this));
-
-    this.cfg.screen.addEventListener('mouseup', function(e) {
-        this.setPointerState(e);
-        this.state.pointer.down = false;
-        cb(this.state.pointer);
-    }.bind(this));
-};
-
-
-DstEng.prototype.randomInt = function(range) {
-    return Math.floor(Math.random() * range);
-};
-
-DstEng.prototype.addRes = function(name, resource) {
-
-    if (this.res.hasOwnProperty(name)) {
-        this.log('Note: Overriding existing resource ' + name);
-        this.log('old: ', this.res[name]);
-        this.log('new: ', resource);
-
-    }
-    if (resource.type) {
-        this.log('No type defined for ' + name);
-    }
-
-    this.res[name] = resource;
-
-    return (resource);
-};
-
-
-DstEng.prototype.startLoader = function() {
-
-    this.addRes('glPrg', this.createProgram(this.gl, this.res.shader_vertex2d.shader, this.res.shader_fragment2d.shader));
-    this.addRes('glPrgSat', this.createProgram(this.gl, this.res.shader_vertex2d.shader, this.res.shader_fragment2d_sat.shader));
-
-    //this.gl.useProgram( this.res.glPrg.program );
-
-    // The idea is to have:
-    // DrawGroup (program)
-    //  - SpriteGroup (vertex, tex)
-    //    - Sprite, each sprite will be drawn at a desired position, using the desired texCoord array, optional array of program params may be supplied
-    // Usage:
-    // Create a vertexbuffer
-    // Create a dg
-    // Create a sg and add to dg
-    // Create a sp and add to sg
-    // draw dg
-
-    // newSprite( program, tex ) = { dg, sg, sp }
-    // newPsys( program, tex, type )
-
-
-    /*...*/
-
-    var texture = new this.Texture(this.gl, {
-        img: this.res.img_DstEng,
-        cut: [0, 0, 320, 240],
-        numFrames: 1,
-        animate: false,
-        frameTime: 0
-    });
-
-    var brickTex = new this.Texture(this.gl, {
-        img: this.res.img_tiles,
-        cut: [20, 0, 40, 20],
-        numFrames: 10,
-        frameTime: 100,
-        animate: true
-    });
-
-
-    var sprInfo = this.newSprite(this.gl, this.res.glPrg, texture, [0, 0]);
-
-
-
-    this.Sprite.prototype.aniCallback = function(ts) {
-        this.pos[0]+= this.vl[0]*ts;
-        this.pos[1]+= this.vl[1]*ts;
-        if(this.pos[0] > 320-this.size[0]) {
-            this.pos[0]=320-this.size[0];
-            this.vl[0] *= -1;
-            this.frameGridPos = [ this.frameGridPos[0]+1, 0 ];
-            if( this.frameGridPos[0] > 10 ) {
-                this.frameGridPos[0]=0;
-            }
-        } else if(this.pos[0] < 0) {
-            this.pos[0]=0;
-            this.vl[0] *= -1;
-        }
-        
-        if(this.pos[1] > 240-this.size[1]) {
-            this.pos[1]=240-this.size[1];
-            this.vl[1] *= -1;
-        } else if(this.pos[1] < 0) {
-            this.pos[1]=0;
-            this.vl[1] *= -1;
-        }
-        
-    };
-    
-    for(var i=0; i < 1000;++i) {
-        sprInfo.sp.vl = [Math.random()*4-2,Math.random()*4-2];
-        sprInfo = this.newSprite(this.gl, this.res.glPrg, brickTex, [160, 120]);
-    }
-
-
-    //
-
-    //Say we are ready
-    this.cfg.readyCallback(true);
-    
-    this.drawFrame();
-};
-
-DstEng.prototype.newSprite = function(gl, program, tex, pos) {
-
-    var useDg = null;
-    var useSg = null;
-
-    //Find dg using this program
-    for (var dgi = 0, dgl = this.drawGroups.length; dgi < dgl; ++dgi) {
-        if (this.drawGroups[dgi].prgInfo === program) {
-            useDg = this.drawGroups[dgi];
-            break;
-        }
-    }
-
-    if (!useDg) {
-        useDg = new this.DrawGroup(program);
-        this.drawGroups.push(useDg);
-    }
-
-    //Find sg using this texture
-    for (var sgi = 0, sgl = useDg.spriteGroups.length; sgi < sgl; ++sgi) {
-        if (useDg.spriteGroups[sgi].tex === tex) {
-            useSg = useDg.spriteGroups[sgi];
-            break;
-        }
-    }
-
-    if (!useSg) {
-        useSg = new this.SpriteGroup(gl, tex);
-        useDg.addSpriteGroup(useSg);
-    }
-
-    var sprite = useSg.addSprite(new this.Sprite(pos));
-
-    return {
-        dg: useDg,
-        sg: useSg,
-        sp: sprite
-    };
-};
-
-
-DstEng.prototype.Texture = (function() {
-    function Tex(gl, setup) {
-
-        if (!gl) {
-            throw Error('Need gl');
-        }
-
-        if (!setup.img.resType) {
-            throw Error('Required: img.');
-        }
-
-        if (!setup.img.image || !setup.img.image.height) {
-            throw Error('Invalid or no image in setup.img');
-        }
-
-        this.w = setup.img.image.width;
-        this.h = setup.img.image.height;
-
-        this.numFrames = setup.numFrames || 1;
-        this.animate = setup.animate || false;
-        this.frameTime = setup.frameTime || false;
-
-        this.pxFrameSize = [setup.cut[2] - setup.cut[0], setup.cut[3] - setup.cut[1]] || [this.w, this.h];
-
-        this.glTex = setup.img.texture;
-
-        this.glFrameSize = new Float32Array([(this.pxFrameSize[0] / this.w), (this.pxFrameSize[1] / this.h)]);
-
-        this.glCut = [
-            setup.cut[2] / this.w, setup.cut[3] / this.h,
-            setup.cut[0] / this.w, setup.cut[1] / this.h
-        ];
-
-    }
-
-    return Tex;
-}());
-
-DstEng.prototype.DrawGroup = (function() {
-    function Dg(prgInfo) {
-        this.prgInfo = prgInfo;
-        this.spriteGroups = [];
-    }
-
-    Dg.prototype.addSpriteGroup = function(pg) {
-        this.spriteGroups.push(pg);
-    };
-
-    Dg.prototype.draw = function(gl, timeScale) {
-
-        timeScale = timeScale || 1.0;
-
-        //Program is same for all drawGroups
-        var prgInfo = this.prgInfo;
-        gl.useProgram(prgInfo.program);
-
-        for (var sgi = 0, sgl = this.spriteGroups.length; sgi < sgl; ++sgi) {
-            var sg = this.spriteGroups[sgi];
-
-            //VertexBuffer shared by all sprites in group
-            gl.bindBuffer(gl.ARRAY_BUFFER, sg.buffer);
-            gl.vertexAttribPointer(prgInfo.a_pos, 2, gl.FLOAT, false, sg.stride, sg.vertexOffset);
-            gl.vertexAttribPointer(prgInfo.a_texCoord, 2, gl.FLOAT, false, sg.stride, sg.texCoordOffset);
-
-            //Texure info shared by all sprites in group
-            gl.bindTexture(gl.TEXTURE_2D, sg.texture.glTex);
-            gl.uniform2fv(prgInfo.u_frameSize, sg.texture.glFrameSize);
-
-            for (var spi = 0, spl = sg.sprites.length; spi < spl; ++spi) {
-
-                //Set geometry location and texture location
-                var spr = sg.sprites[spi];
-                if (spr.aniCallback) {
-                    spr.aniCallback(timeScale);
-                }
-
-                gl.uniform2fv(prgInfo.u_translation, spr.pos);
-                gl.uniform2fv(prgInfo.u_frameGridPos, spr.frameGridPos);
-                gl.drawArrays(gl.TRIANGLES, 0, 6);
-            }
-        }
-    };
-
-    return Dg;
-}());
-
-DstEng.prototype.SpriteGroup = (function() {
-    function Sg(gl, texture) {
-        this.buffer = gl.createBuffer();
-        var w = texture.pxFrameSize[0];
-        h = texture.pxFrameSize[1];
-
-        var glwa = texture.glCut[0];
-        var glha = texture.glCut[1];
-        var glwb = texture.glCut[2];
-        var glhb = texture.glCut[3];
-
-
-        gl.bindBuffer(gl.ARRAY_BUFFER, this.buffer);
-        gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
-            0, 0,
-            glwb, glhb,
-            w, 0,
-            glwa, glhb,
-            0, h,
-            glwb, glha,
-            0, h,
-            glwb, glha,
-            w, 0,
-            glwa, glhb,
-            w, h,
-            glwa, glha
-        ]), gl.STATIC_DRAW);
-
-
-        this.vertexOffset = 0;
-        this.texCoordOffset = Float32Array.BYTES_PER_ELEMENT * 2;
-        this.stride = Float32Array.BYTES_PER_ELEMENT * 4;
-        this.texture = texture;
-        this.sprites = [];
-    }
-
-    Sg.prototype.addSprite = function(sprite) {
-        sprite.size = this.texture.pxFrameSize;
-        this.sprites.push(sprite);
-        return sprite;
-    };
-
-    return Sg;
-}());
-
-
-DstEng.prototype.Sprite = (function() {
-    function Spr(pos) {
-        this.pos = new Float32Array(pos);
-        this.frameGridPos = [0, 0];
-    }
-
-    Spr.prototype.setPos = function(pos) {
-        this.pos = pos;
-    };
-
-
-    return Spr;
-}());
-
-
-
-DstEng.prototype.drawFrame = function(timeStamp) {
-
-    timeStamp = timeStamp || 16.0;
-
-    this.state.timeDelta = timeStamp - this.state.lastTime;
-
-    this.timeScale = this.state.timeDelta / 16.00;
-    this.accTs += timeScale;
-    //  console.log(timeScale);
-
-    this.state.lastTime = timeStamp;
-
-    this.state.frame++;
-    this.state.tdAvg += this.state.timeDelta;
-
-
-
-
-    if (this.state.frame % 120 === 0) {
-        this.state.fps = 1000 / this.state.timeDelta;
-        console.log(this.state.fps, (1000.0 / (this.state.tdAvg / this.state.frame)), this.state.tdAvg - timeStamp, this.state.frame, this.accTs / this.state.frame);
-    }
-
-
-    //  this.spr.pos = this.state.pointer.pos;
-    //    this.spr.frameGridPos = [ Math.floor(this.state.pointer.pos[0]) % 10, 0 ];
-    
-
-    this.drawGroups[0].draw(this.gl, this.timeScale);
-
-    window.requestAnimationFrame(this.drawFrame.bind(this));
-
-};
\ No newline at end of file
index 7c49096..ae18cb4 100644 (file)
@@ -25,3 +25,10 @@ Wizznic.prototype.onMouseClick = function(ptr) {
 
 };
 
+Wizznic.prototype.setPack = function(url) {
+    
+};
+
+Wizznic.prototype.setLevel = function(url) {
+    
+};
\ No newline at end of file
index 9047a20..c8967d9 100644 (file)
@@ -16,6 +16,7 @@
     "grunt-contrib-jshint": "^0.12.0",
     "grunt-js-beautify": "^0.1.4",
     "js-beautify": "^1.5.10",
+    "jsdoc": "^3.4.0",
     "jshint": "^2.9.1",
     "nodemon": "^1.8.1"
   }