diff --git a/engine/core/Async.js b/engine/core/Async.js new file mode 100644 index 0000000..621073e --- /dev/null +++ b/engine/core/Async.js @@ -0,0 +1,17 @@ +export default class Async { + constructor() { + this.loaded = false; + this.urls = []; + this.assets = null; + } + + load() { + return cache.getAll(this.urls).then((assets) => { + this.assets = assets; + this.loaded = true; + return assets; + }, (err) => { + return err; + }) + } +} \ No newline at end of file diff --git a/engine/core/Scene2D.js b/engine/core/Scene2D.js index 8da7734..a4b09f4 100644 --- a/engine/core/Scene2D.js +++ b/engine/core/Scene2D.js @@ -1,5 +1,7 @@ import Actor2D from "./Actor2D"; + +//todo add scale export default class Scene2D extends Actor2D{ constructor() { super(); diff --git a/engine/graphics/Program.js b/engine/graphics/Program.js new file mode 100644 index 0000000..1944cf9 --- /dev/null +++ b/engine/graphics/Program.js @@ -0,0 +1,5 @@ +export default class Program { + constructor() { + + } +} \ No newline at end of file diff --git a/engine/graphics/ProgramManager.js b/engine/graphics/ProgramManager.js new file mode 100644 index 0000000..50d3b36 --- /dev/null +++ b/engine/graphics/ProgramManager.js @@ -0,0 +1,5 @@ +export default class ProgramManager { + constructor() { + + } +} \ No newline at end of file diff --git a/engine/graphics/Sprite.js b/engine/graphics/Sprite.js new file mode 100644 index 0000000..31e887d --- /dev/null +++ b/engine/graphics/Sprite.js @@ -0,0 +1,158 @@ +import Component from "core/engine/Component"; + +//think about makeing a "dirtable class " +//possibly make a global array for vertices so we arent creating a lot of arrays :/. +//or just make a vertices cache thingy +class GLSprite { + + constructor() { + this.initialized = false; + this.gl = null; + this.vertices = null + this.texCoords = null + this.buffers = null; + this.lastDirt = null; + } + + initialize(gl, sprite) { + this.gl = gl; + this.sprite = sprite; + this.vertices = new Float32Array(8); + this.texCoords = new Float32Array(8); + this.buffers = [gl.createBuffer(), gl.createBuffer()]; + this.initialized = true; + } + + update() { + if(this.lastDirt === sprite.dirt) return; + this.lastDirt = sprite.dirt; + + var gl = this.gl; + var sprite = this.sprite; + var vertices = this.vertices; + var texCoords = this.texCoords; + var buffers = this.buffers; + + + + vertices[0] = hw; + vertices[1] = hh; + vertices[2] = -hw; + vertices[3] = hh; + vertices[4] = -hw; + vertices[5] = -hh; + + + vertices[6] = hw; + vertices[7] = hh; + vertices[8] = -hw; + vertices[9] = -hh; + vertices[10] = hw; + vertices[11] = -hh; + + + + texCoords[0] = 1; + texCoords[1] = 1; + texCoords[2] = 0; + texCoords[3] = 1 + texCoords[4] = 0; + texCoords[5] = 0; + + + texCoords[0] = 1; + texCoords[1] = 1; + texCoords[2] = 0; + texCoords[3] = 0; + texCoords[4] = 1; + texCoords[5] = 0; + + gl.bindBuffer(gl.ARRAY_BUFFER, buffers[0]); + gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW); + gl.bindBuffer(gl.ARRAY_BUFFER, buffers[1]); + gl.bufferData(gl.ARRAY_BUFFER, texCoords, gl.STATIC_DRAW); + gl.bindBuffer(gl.ARRAY_BUFFER, null); + } + + destroy() { + gl.deleteBuffer(buffers[0]); + gl.deleteBuffer(buffers[1]); + } + + preRender(programManager) { + var gl = this.gl; + + var program = programManager.current; + + gl.bindBuffer(gl.ARRAY_BUFFER, buffers[0]); + gl.vertexAttribPointer(program.attributes.aPosition, 2, gl.FLOAT, false, 0, 0); + + gl.bindBuffer(gl.ARRAY_BUFFER, buffers[1]); + gl.vertexAttribPointer(program.attributes.aTexCoord, 2, gl.FLOAT, false, 0, 0); + + + } + + render() { + + } + + postRender() { + + } + +} + +export default class Sprite extends Component { + constructor() { + super("sprite"); + this.dirt = 0; + this._width = null; + this._height = null; + this._image = null; + } + + dirty () { + this.dirt++; + } + + get width() { + return this._width; + } + + set width (width) { + this._width = width; + this.dirt++; + } + + get height() { + return this._height; + } + + set height(height) { + this._height = height; + this.dirt++; + } + + get image () { + return this._image; + } + + set image (image) { + this._image = image; + + if(!this._width) this._width = image.width; + if(!this.height) this._height = image.height; + dirty(); + } + + + createGL(gl) { + return new SpriteGlob(gl); + } + + updateGL(glob) { + return glob.update(); + } + +} \ No newline at end of file diff --git a/example/public/Sprite.js b/example/public/Sprite.js deleted file mode 100644 index 82245bf..0000000 --- a/example/public/Sprite.js +++ /dev/null @@ -1,26 +0,0 @@ -import Component from "core/engine/Component"; - -//think about makeing a "dirtable class " -export default class Sprite extends Component { - constructor() { - super("sprite"); - - this.dirt = 0; - this._image = null; - } - - dirty () { - this.dirt++;n - } - get image () { - return this._image; - } - - set image (image) { - this._image = image; - dirty(); - } - - - -} \ No newline at end of file diff --git a/package.json b/package.json index f304b02..228f8c2 100644 --- a/package.json +++ b/package.json @@ -29,5 +29,8 @@ "gulp-live-server": "0.0.29", "express": "~4.13.4", "run-sequence": "~1.1.5" + }, + "scripts" : { + "test" : "gulp" } }