diff --git a/assets/hxlogo.png b/assets/hxlogo.png index dc6895c..aa923fd 100755 Binary files a/assets/hxlogo.png and b/assets/hxlogo.png differ diff --git a/bin/html5/bin/assets/hxlogo.png b/bin/html5/bin/assets/hxlogo.png index dc6895c..aa923fd 100755 Binary files a/bin/html5/bin/assets/hxlogo.png and b/bin/html5/bin/assets/hxlogo.png differ diff --git a/bin/html5/bin/glframework.js b/bin/html5/bin/glframework.js index 88a4c43..8b5abe6 100755 --- a/bin/html5/bin/glframework.js +++ b/bin/html5/bin/glframework.js @@ -25,7 +25,52 @@ ApplicationMain.main = function() { ApplicationMain.preloader.onInit(); var urlLoader = new flash.net.URLLoader(); urlLoader.set_dataFormat(flash.net.URLLoaderDataFormat.BINARY); - + ApplicationMain.urlLoaders.set("assets/desert.tmx",urlLoader); + ApplicationMain.total++; + var loader = new flash.display.Loader(); + ApplicationMain.loaders.set("assets/hxlogo.png",loader); + ApplicationMain.total++; + var urlLoader1 = new flash.net.URLLoader(); + urlLoader1.set_dataFormat(flash.net.URLLoaderDataFormat.BINARY); + ApplicationMain.urlLoaders.set("assets/map.tmx",urlLoader1); + ApplicationMain.total++; + var urlLoader2 = new flash.net.URLLoader(); + urlLoader2.set_dataFormat(flash.net.URLLoaderDataFormat.BINARY); + ApplicationMain.urlLoaders.set("assets/mapxml.tmx",urlLoader2); + ApplicationMain.total++; + var loader1 = new flash.display.Loader(); + ApplicationMain.loaders.set("assets/player.png",loader1); + ApplicationMain.total++; + var urlLoader3 = new flash.net.URLLoader(); + urlLoader3.set_dataFormat(flash.net.URLLoaderDataFormat.BINARY); + ApplicationMain.urlLoaders.set("assets/scrol.tmx",urlLoader3); + ApplicationMain.total++; + var urlLoader4 = new flash.net.URLLoader(); + urlLoader4.set_dataFormat(flash.net.URLLoaderDataFormat.BINARY); + ApplicationMain.urlLoaders.set("assets/sewers.tmx",urlLoader4); + ApplicationMain.total++; + var loader2 = new flash.display.Loader(); + ApplicationMain.loaders.set("assets/sewer_tileset.png",loader2); + ApplicationMain.total++; + var loader3 = new flash.display.Loader(); + ApplicationMain.loaders.set("assets/sprites.png",loader3); + ApplicationMain.total++; + var loader4 = new flash.display.Loader(); + ApplicationMain.loaders.set("assets/texture.png",loader4); + ApplicationMain.total++; + var urlLoader5 = new flash.net.URLLoader(); + urlLoader5.set_dataFormat(flash.net.URLLoaderDataFormat.BINARY); + ApplicationMain.urlLoaders.set("assets/TileMap.tmx",urlLoader5); + ApplicationMain.total++; + var loader5 = new flash.display.Loader(); + ApplicationMain.loaders.set("assets/tiles.png",loader5); + ApplicationMain.total++; + var loader6 = new flash.display.Loader(); + ApplicationMain.loaders.set("assets/tmw_desert_spacing.png",loader6); + ApplicationMain.total++; + var loader7 = new flash.display.Loader(); + ApplicationMain.loaders.set("assets/zazaka.png",loader7); + ApplicationMain.total++; var resourcePrefix = "__ASSET__:bitmap_"; var _g = 0, _g1 = haxe.Resource.listNames(); while(_g < _g1.length) { @@ -883,7 +928,6 @@ com.engine.game.Game = function() { openfl.display.OpenGLView.call(this); this.ready = false; this.set_render($bind(this,this.renderView)); - this.viewPort = new flash.geom.Rectangle(0,0,flash.Lib.get_current().get_stage().get_stageWidth(),flash.Lib.get_current().get_stage().get_stageHeight()); this.screenWidth = flash.Lib.get_current().get_stage().get_stageWidth(); this.screenHeight = flash.Lib.get_current().get_stage().get_stageHeight(); com.engine.game.Game.viewWidth = this.screenHeight; @@ -891,7 +935,6 @@ com.engine.game.Game = function() { this.gameWidth = this.screenWidth; this.gameHeight = this.screenHeight; com.engine.game.Game.projMatrix = com.engine.math.Matrix.OrthoOffCenterLH(0,this.gameWidth,this.gameHeight,0,-1,1); - com.engine.game.Game.viewMatrix = com.engine.math.Matrix.FromValues(1.0,0,0,0,0,1.0,0,0,0,0,1.0,0,0,0,0,1.0); this.get_stage().addEventListener(flash.events.Event.RESIZE,$bind(this,this.onResize)); this.get_stage().addEventListener(flash.events.Event.ADDED,$bind(this,this.focusGained)); this.get_stage().addEventListener(flash.events.Event.DEACTIVATE,$bind(this,this.focusLost)); @@ -900,17 +943,14 @@ com.engine.game.Game = function() { this.get_stage().addChild(this.container); this.addChild(new openfl.display.FPS(10,10,1044735)); this.prevFrame = flash.Lib.getTimer(); - openfl.gl.GL.disable(2884); - openfl.gl.GL.enable(2929); - openfl.gl.GL.depthFunc(515); }; $hxClasses["com.engine.game.Game"] = com.engine.game.Game; com.engine.game.Game.__name__ = ["com","engine","game","Game"]; com.engine.game.Game.__super__ = openfl.display.OpenGLView; com.engine.game.Game.prototype = $extend(openfl.display.OpenGLView.prototype,{ renderView: function(rect) { - com.engine.game.Game.viewWidth = rect.width; - com.engine.game.Game.viewHeight = rect.height; + com.engine.game.Game.viewWidth = rect.width | 0; + com.engine.game.Game.viewHeight = rect.height | 0; if(this.rescale == true) { var ar_origin = this.gameWidth / this.gameHeight; var ar_new = this.screenWidth / this.screenHeight; @@ -925,12 +965,10 @@ com.engine.game.Game.prototype = $extend(openfl.display.OpenGLView.prototype,{ openfl.gl.GL.viewport(rect.x | 0,rect.y | 0,rect.width | 0,rect.height | 0); com.engine.game.Game.projMatrix = com.engine.math.Matrix.OrthoOffCenterLH(0,this.gameWidth,this.gameHeight,0,-1,1); } - com.engine.game.Game.viewMatrix = com.engine.math.Matrix.create2D(0,0,1,0); this.nextFrame = flash.Lib.getTimer(); this.deltaTime = (this.nextFrame - this.prevFrame) * 0.001; - openfl.gl.GL.clearColor(1,0,1,1); - openfl.gl.GL.clearDepth(1); - openfl.gl.GL.clear(16640); + openfl.gl.GL.clearColor(this.red,this.green,this.blue,1); + if(this.enableDepth == true) openfl.gl.GL.clear(16640); else openfl.gl.GL.clear(16384); if(this.ready) this.update(this.deltaTime); openfl.gl.GL.bindBuffer(34962,null); openfl.gl.GL.useProgram(null); @@ -942,6 +980,8 @@ com.engine.game.Game.prototype = $extend(openfl.display.OpenGLView.prototype,{ this.screen = screen; this.screen.game = this; if(this.screen != null) { + this.screen.width = this.screenWidth; + this.screen.height = this.screenHeight; this.screen.show(); this.screen.resize(com.engine.game.Game.viewWidth | 0,com.engine.game.Game.viewHeight | 0); } @@ -1017,10 +1057,13 @@ com.engine.game.Game.prototype = $extend(openfl.display.OpenGLView.prototype,{ flash.Lib.get_current().get_stage().addEventListener("touchMove",$bind(this,this.doTouchMove)); flash.Lib.get_current().get_stage().addEventListener("touchEnd",$bind(this,this.doTouchUp)); } - openfl.gl.GL.disable(2929); openfl.gl.GL.disable(2884); openfl.gl.GL.enable(3042); + openfl.gl.GL.blendFunc(770,772); openfl.gl.GL.pixelStorei(3333,2); + this.setDeph(true); + this.clarColor(0,1,0.4); + openfl.gl.GL.clearColor(this.red,this.green,this.blue,1); openfl.gl.GL.depthMask(true); this.begin(); this.ready = true; @@ -1031,6 +1074,18 @@ com.engine.game.Game.prototype = $extend(openfl.display.OpenGLView.prototype,{ ,removeChild: function(child) { this.container.removeChild(child); } + ,clarColor: function(r,g,b) { + this.red = r; + this.green = g; + this.blue = b; + } + ,setDeph: function(v) { + this.enableDepth = v; + if(v == true) openfl.gl.GL.disable(2929); else { + openfl.gl.GL.enable(2929); + openfl.gl.GL.depthFunc(4353); + } + } ,fixRatio: function(w,h) { this.rescale = true; this.gameWidth = w; @@ -1048,7 +1103,7 @@ com.djoker.glteste.Main.__name__ = ["com","djoker","glteste","Main"]; com.djoker.glteste.Main.__super__ = com.engine.game.Game; com.djoker.glteste.Main.prototype = $extend(com.engine.game.Game.prototype,{ begin: function() { - this.setScreen(new com.djoker.glteste.TestePrimitives()); + this.setScreen(new com.djoker.glteste.TestTrasform()); } ,__class__: com.djoker.glteste.Main }); @@ -1121,7 +1176,48 @@ openfl.AssetLibrary.prototype = { } var DefaultAssetLibrary = function() { openfl.AssetLibrary.call(this); - + DefaultAssetLibrary.path.set("assets/desert.tmx","assets/desert.tmx"); + var value = Reflect.field(openfl.AssetType,"binary".toUpperCase()); + DefaultAssetLibrary.type.set("assets/desert.tmx",value); + DefaultAssetLibrary.path.set("assets/hxlogo.png","assets/hxlogo.png"); + var value = Reflect.field(openfl.AssetType,"image".toUpperCase()); + DefaultAssetLibrary.type.set("assets/hxlogo.png",value); + DefaultAssetLibrary.path.set("assets/map.tmx","assets/map.tmx"); + var value = Reflect.field(openfl.AssetType,"binary".toUpperCase()); + DefaultAssetLibrary.type.set("assets/map.tmx",value); + DefaultAssetLibrary.path.set("assets/mapxml.tmx","assets/mapxml.tmx"); + var value = Reflect.field(openfl.AssetType,"binary".toUpperCase()); + DefaultAssetLibrary.type.set("assets/mapxml.tmx",value); + DefaultAssetLibrary.path.set("assets/player.png","assets/player.png"); + var value = Reflect.field(openfl.AssetType,"image".toUpperCase()); + DefaultAssetLibrary.type.set("assets/player.png",value); + DefaultAssetLibrary.path.set("assets/scrol.tmx","assets/scrol.tmx"); + var value = Reflect.field(openfl.AssetType,"binary".toUpperCase()); + DefaultAssetLibrary.type.set("assets/scrol.tmx",value); + DefaultAssetLibrary.path.set("assets/sewers.tmx","assets/sewers.tmx"); + var value = Reflect.field(openfl.AssetType,"binary".toUpperCase()); + DefaultAssetLibrary.type.set("assets/sewers.tmx",value); + DefaultAssetLibrary.path.set("assets/sewer_tileset.png","assets/sewer_tileset.png"); + var value = Reflect.field(openfl.AssetType,"image".toUpperCase()); + DefaultAssetLibrary.type.set("assets/sewer_tileset.png",value); + DefaultAssetLibrary.path.set("assets/sprites.png","assets/sprites.png"); + var value = Reflect.field(openfl.AssetType,"image".toUpperCase()); + DefaultAssetLibrary.type.set("assets/sprites.png",value); + DefaultAssetLibrary.path.set("assets/texture.png","assets/texture.png"); + var value = Reflect.field(openfl.AssetType,"image".toUpperCase()); + DefaultAssetLibrary.type.set("assets/texture.png",value); + DefaultAssetLibrary.path.set("assets/TileMap.tmx","assets/TileMap.tmx"); + var value = Reflect.field(openfl.AssetType,"binary".toUpperCase()); + DefaultAssetLibrary.type.set("assets/TileMap.tmx",value); + DefaultAssetLibrary.path.set("assets/tiles.png","assets/tiles.png"); + var value = Reflect.field(openfl.AssetType,"image".toUpperCase()); + DefaultAssetLibrary.type.set("assets/tiles.png",value); + DefaultAssetLibrary.path.set("assets/tmw_desert_spacing.png","assets/tmw_desert_spacing.png"); + var value = Reflect.field(openfl.AssetType,"image".toUpperCase()); + DefaultAssetLibrary.type.set("assets/tmw_desert_spacing.png",value); + DefaultAssetLibrary.path.set("assets/zazaka.png","assets/zazaka.png"); + var value = Reflect.field(openfl.AssetType,"image".toUpperCase()); + DefaultAssetLibrary.type.set("assets/zazaka.png",value); }; $hxClasses["DefaultAssetLibrary"] = DefaultAssetLibrary; DefaultAssetLibrary.__name__ = ["DefaultAssetLibrary"]; @@ -1305,21 +1401,6 @@ List.prototype = { return x; }}; } - ,remove: function(v) { - var prev = null; - var l = this.h; - while(l != null) { - if(l[0] == v) { - if(prev == null) this.h = l[1]; else prev[1] = l[1]; - if(this.q == l) this.q = prev; - this.length--; - return true; - } - prev = l; - l = l[1]; - } - return false; - } ,isEmpty: function() { return this.h == null; } @@ -1976,8 +2057,8 @@ Type.getEnumConstructs = function(e) { return a.slice(); } com.engine.game.Transform = function() { - this.scrollFactorY = 1; - this.scrollFactorX = 1; + this.scrollFactorY = 0; + this.scrollFactorX = 0; this.y = 0; this.x = 0; this.pivotY = 0; @@ -1987,16 +2068,17 @@ com.engine.game.Transform = function() { this.scaleY = 1; this.scaleX = 1; this.rotation = 0; - this.isDirty = false; this.parent = null; this.mTransformationMatrix = new flash.geom.Matrix(); - this.children = new List(); }; $hxClasses["com.engine.game.Transform"] = com.engine.game.Transform; com.engine.game.Transform.__name__ = ["com","engine","game","Transform"]; com.engine.game.Transform.prototype = { - getLocalToWorldMatrix: function() { - if(this.parent == null) return this.getTransformationMatrix(); else return this.parent.getTransformationMatrix().mult(this.getTransformationMatrix()); + dispose: function() { + this.mTransformationMatrix = null; + } + ,getLocalToWorldMatrix: function() { + if(this.parent == null) return this.getTransformationMatrix(); else return this.getTransformationMatrix().mult(this.parent.getTransformationMatrix()); } ,getTransformationMatrix: function() { this.mTransformationMatrix.identity(); @@ -2014,22 +2096,39 @@ com.engine.game.Transform.prototype = { } return this.mTransformationMatrix; } + ,__class__: com.engine.game.Transform +} +com.engine.game.GameObject = function() { + com.engine.game.Transform.call(this); + this.children = new Array(); +}; +$hxClasses["com.engine.game.GameObject"] = com.engine.game.GameObject; +com.engine.game.GameObject.__name__ = ["com","engine","game","GameObject"]; +com.engine.game.GameObject.__super__ = com.engine.game.Transform; +com.engine.game.GameObject.prototype = $extend(com.engine.game.Transform.prototype,{ + dispose: function() { + this.children = null; + this.mTransformationMatrix = null; + com.engine.game.Transform.prototype.dispose.call(this); + } ,remove: function(child) { - this.children.remove(child); + child.parent = null; + HxOverrides.remove(this.children,child); } ,add: function(child) { - this.children.add(child); + child.parent = this; + this.children.push(child); } - ,__class__: com.engine.game.Transform -} + ,__class__: com.engine.game.GameObject +}); com.engine.game.Screen = function() { this.game = null; - com.engine.game.Transform.call(this); + com.engine.game.GameObject.call(this); }; $hxClasses["com.engine.game.Screen"] = com.engine.game.Screen; com.engine.game.Screen.__name__ = ["com","engine","game","Screen"]; -com.engine.game.Screen.__super__ = com.engine.game.Transform; -com.engine.game.Screen.prototype = $extend(com.engine.game.Transform.prototype,{ +com.engine.game.Screen.__super__ = com.engine.game.GameObject; +com.engine.game.Screen.prototype = $extend(com.engine.game.GameObject.prototype,{ keyUp: function(key) { } ,keyDown: function(key) { @@ -2044,35 +2143,80 @@ com.engine.game.Screen.prototype = $extend(com.engine.game.Transform.prototype,{ } ,render: function(dt) { } - ,dispose: function() { - } ,show: function() { } ,__class__: com.engine.game.Screen }); -com.djoker.glteste.TestePrimitives = function() { +com.djoker.glteste.TestTrasform = function() { + this.skew = 0; com.engine.game.Screen.call(this); }; -$hxClasses["com.djoker.glteste.TestePrimitives"] = com.djoker.glteste.TestePrimitives; -com.djoker.glteste.TestePrimitives.__name__ = ["com","djoker","glteste","TestePrimitives"]; -com.djoker.glteste.TestePrimitives.__super__ = com.engine.game.Screen; -com.djoker.glteste.TestePrimitives.prototype = $extend(com.engine.game.Screen.prototype,{ - render: function(dt) { - this.batch.begin(); - this.batch.line(10,10,100,100,1,0,1); - this.batch.rect(100,100,90,120,1,1,1); - this.batch.circle(100,100,12,8,1,1,1,1); - this.batch.ellipse(300,90,55,15,8,1,1,1,1); - this.batch.fillrect(200,200,50,50,1,0,0,1); - this.batch.fillrect(280,200,50,50,0,1,1,1); - this.batch.fillcircle(200,100,8,18,1,0,1,1); - this.batch.fillellipse(300,100,55,15,8,0,1,1,1); - this.batch.end(); +$hxClasses["com.djoker.glteste.TestTrasform"] = com.djoker.glteste.TestTrasform; +com.djoker.glteste.TestTrasform.__name__ = ["com","djoker","glteste","TestTrasform"]; +com.djoker.glteste.TestTrasform.__super__ = com.engine.game.Screen; +com.djoker.glteste.TestTrasform.prototype = $extend(com.engine.game.Screen.prototype,{ + mouseDown: function(mousex,mousey) { + this.player.x = mousex; + this.player.y = mousey; } - ,show: function() { - this.batch = new com.engine.render.BatchPrimitives(500); + ,render: function(dt) { + this.player.rotation += dt * 2.1; + this.child.rotation -= dt * 2.5; + this.player.skewX += dt * 0.1; + this.skew += dt; + this.logo.skewX = Math.sin(this.skew); + this.logo.skewY = Math.cos(this.skew); + this.batch.Begin(); + this.batch.drawEntity(this.logo); + this.batch.drawEntity(this.player); + this.batch.drawEntity(this.child); + this.batch.End(); } - ,__class__: com.djoker.glteste.TestePrimitives + ,show: function() { + this.playerTex = new com.engine.render.Texture("assets/zazaka.png",true); + this.batch = new com.engine.render.SpriteBatch(500); + var caption = new flash.text.TextField(); + caption.set_x(this.game.gameWidth / 2 - 100); + caption.set_y(20); + caption.set_width(200); + caption.set_defaultTextFormat(new flash.text.TextFormat("_sans",12,16776960)); + caption.set_text("Test trasform sprites by parent "); + caption.selectable = false; + this.game.addChild(caption); + this.logo = new com.engine.game.Entity(this.width / 2,this.height / 2,new com.engine.render.Texture("assets/hxlogo.png",true)); + this.logo.blendMode = com.engine.render.BlendMode.SCREEN; + this.player = new com.engine.game.Entity(300,200,this.playerTex); + this.child = new com.engine.game.Entity(0,0,this.playerTex); + this.child.blue = 0; + this.player.add(this.child); + this.game.clarColor(0,0,0); + } + ,__class__: com.djoker.glteste.TestTrasform +}); +com.engine.game.Entity = function(x,y,image,name) { + if(name == null) name = "solid"; + com.engine.game.GameObject.call(this); + this.flipx = false; + this.flipy = true; + this.image = image; + this.blendMode = com.engine.render.BlendMode.NORMAL; + this.clip = new com.engine.render.Clip(0,0,image.width,image.height); + this.pivotX = this.clip.width / 2; + this.pivotY = this.clip.height / 2; + this.x = x; + this.y = y; + this.depth = 0.0; + this.name = name; + this.red = 1; + this.green = 1; + this.blue = 1; + this.alpha = 1; +}; +$hxClasses["com.engine.game.Entity"] = com.engine.game.Entity; +com.engine.game.Entity.__name__ = ["com","engine","game","Entity"]; +com.engine.game.Entity.__super__ = com.engine.game.GameObject; +com.engine.game.Entity.prototype = $extend(com.engine.game.GameObject.prototype,{ + __class__: com.engine.game.Entity }); com.engine.math = {} com.engine.math.Matrix = function() { @@ -2543,7 +2687,22 @@ com.engine.math.Matrix.ReflectionToRef = function(plane,result) { return result; } com.engine.math.Matrix.prototype = { - clone: function() { + set2Dtransformation: function(x,y,scale,rotation) { + if(rotation == null) rotation = 0; + if(scale == null) scale = 1; + var theta = rotation * Math.PI / 180.0; + var c = Math.cos(theta); + var s = Math.sin(theta); + this.fillArrayTo([c * scale,-s * scale,0,0,s * scale,c * scale,0,0,0,0,1,0,x,y,0,1]); + } + ,fillArrayTo: function(array) { + var _g = 0; + while(_g < 16) { + var index = _g++; + this.m[index] = array[index]; + } + } + ,clone: function() { return com.engine.math.Matrix.FromValues(this.m[0],this.m[1],this.m[2],this.m[3],this.m[4],this.m[5],this.m[6],this.m[7],this.m[8],this.m[9],this.m[10],this.m[11],this.m[12],this.m[13],this.m[14],this.m[15]); } ,equals: function(value) { @@ -2600,6 +2759,24 @@ com.engine.math.Matrix.prototype = { result[offset + 15] = tm12 * om3 + tm13 * om7 + tm14 * om11 + tm15 * om15; return result; } + ,Multiply4x4: function(A,B) { + this.m[0] = A.m[0] * B.m[0] + A.m[4] * B.m[1] + A.m[8] * B.m[2] + A.m[12] * B.m[3]; + this.m[1] = A.m[1] * B.m[0] + A.m[5] * B.m[1] + A.m[9] * B.m[2] + A.m[13] * B.m[3]; + this.m[2] = A.m[2] * B.m[0] + A.m[6] * B.m[1] + A.m[10] * B.m[2] + A.m[14] * B.m[3]; + this.m[3] = A.m[3] * B.m[0] + A.m[7] * B.m[1] + A.m[11] * B.m[2] + A.m[15] * B.m[3]; + this.m[4] = A.m[0] * B.m[4] + A.m[4] * B.m[5] + A.m[8] * B.m[6] + A.m[12] * B.m[7]; + this.m[5] = A.m[1] * B.m[4] + A.m[5] * B.m[5] + A.m[9] * B.m[6] + A.m[13] * B.m[7]; + this.m[6] = A.m[2] * B.m[4] + A.m[6] * B.m[5] + A.m[10] * B.m[6] + A.m[14] * B.m[7]; + this.m[7] = A.m[3] * B.m[4] + A.m[7] * B.m[5] + A.m[11] * B.m[6] + A.m[15] * B.m[7]; + this.m[8] = A.m[0] * B.m[8] + A.m[4] * B.m[9] + A.m[8] * B.m[10] + A.m[12] * B.m[11]; + this.m[9] = A.m[1] * B.m[8] + A.m[5] * B.m[9] + A.m[9] * B.m[10] + A.m[13] * B.m[11]; + this.m[10] = A.m[2] * B.m[8] + A.m[6] * B.m[9] + A.m[10] * B.m[10] + A.m[14] * B.m[11]; + this.m[11] = A.m[3] * B.m[8] + A.m[7] * B.m[9] + A.m[11] * B.m[10] + A.m[15] * B.m[11]; + this.m[12] = A.m[0] * B.m[12] + A.m[4] * B.m[13] + A.m[8] * B.m[14] + A.m[12] * B.m[15]; + this.m[13] = A.m[1] * B.m[12] + A.m[5] * B.m[13] + A.m[9] * B.m[14] + A.m[13] * B.m[15]; + this.m[14] = A.m[2] * B.m[12] + A.m[6] * B.m[13] + A.m[10] * B.m[14] + A.m[14] * B.m[15]; + this.m[15] = A.m[3] * B.m[12] + A.m[7] * B.m[13] + A.m[11] * B.m[14] + A.m[15] * B.m[15]; + } ,multiplyToRef: function(other,result) { this.multiplyToArray(other,result.m,0); } @@ -3394,7 +3571,7 @@ com.engine.misc.MatrixHelp.__name__ = ["com","engine","misc","MatrixHelp"]; com.engine.misc.MatrixHelp.getScaled = function(source,newWidth,newHeight) { var m = new flash.geom.Matrix(); m.scale(newWidth / (source.___textureBuffer != null?source.___textureBuffer.width:0),newHeight / (source.___textureBuffer != null?source.___textureBuffer.height:0)); - var bmp = new flash.display.BitmapData(newWidth,newHeight,true,255); + var bmp = new flash.display.BitmapData(newWidth,newHeight,true); bmp.draw(source,m); return bmp; } @@ -3477,263 +3654,13 @@ com.engine.misc.Util.prototype = { ,__class__: com.engine.misc.Util } com.engine.render = {} -com.engine.render.Buffer = function() { - this.position = new com.engine.math.Vector2(0,0); - this.rotation = 0; - this.scale = 1; - this.viewMatrix = com.engine.math.Matrix.create2D(this.position.x,this.position.y,this.scale,this.rotation); -}; -$hxClasses["com.engine.render.Buffer"] = com.engine.render.Buffer; -com.engine.render.Buffer.__name__ = ["com","engine","render","Buffer"]; -com.engine.render.Buffer.prototype = { - dispose: function() { - } - ,update: function() { - this.viewMatrix = com.engine.math.Matrix.create2D(Math.round(this.position.x),Math.round(this.position.y),this.scale,this.rotation); - } - ,combineMatrix: function(m) { - this.viewMatrix = com.engine.math.Matrix.MatrixMultiply4x4(this.viewMatrix,m); - } - ,getMatrix: function() { - return this.viewMatrix; - } - ,__class__: com.engine.render.Buffer -} -com.engine.render.BatchPrimitives = function(capacity) { - com.engine.render.Buffer.call(this); - this.vertexBuffer = openfl.gl.GL.createBuffer(); - this.colorBuffer = openfl.gl.GL.createBuffer(); - this.fvertexBuffer = openfl.gl.GL.createBuffer(); - this.fcolorBuffer = openfl.gl.GL.createBuffer(); - this.capacity = capacity; - this.idxPos = 0; - this.idxCols = 0; - this.fidxPos = 0; - this.fidxCols = 0; - this.vertices = new Float32Array(capacity * 3 * 4); - openfl.gl.GL.bindBuffer(34962,this.vertexBuffer); - openfl.gl.GL.bufferData(34962,this.vertices,35048); - this.colors = new Float32Array(capacity * 4 * 4); - openfl.gl.GL.bindBuffer(34962,this.colorBuffer); - openfl.gl.GL.bufferData(34962,this.colors,35048); - this.fvertices = new Float32Array(capacity * 3 * 4); - openfl.gl.GL.bindBuffer(34962,this.fvertexBuffer); - openfl.gl.GL.bufferData(34962,this.fvertices,35048); - this.fcolors = new Float32Array(capacity * 4 * 4); - openfl.gl.GL.bindBuffer(34962,this.fcolorBuffer); - openfl.gl.GL.bufferData(34962,this.fcolors,35048); - this.currentBlendMode = com.engine.render.BlendMode.NORMAL; - this.shader = new com.engine.render.PrimitiveShader(); -}; -$hxClasses["com.engine.render.BatchPrimitives"] = com.engine.render.BatchPrimitives; -com.engine.render.BatchPrimitives.__name__ = ["com","engine","render","BatchPrimitives"]; -com.engine.render.BatchPrimitives.__super__ = com.engine.render.Buffer; -com.engine.render.BatchPrimitives.prototype = $extend(com.engine.render.Buffer.prototype,{ - dispose: function() { - this.vertices = null; - this.colors = null; - openfl.gl.GL.deleteBuffer(this.vertexBuffer); - openfl.gl.GL.deleteBuffer(this.colorBuffer); - this.fvertices = null; - this.fcolors = null; - openfl.gl.GL.deleteBuffer(this.fvertexBuffer); - openfl.gl.GL.deleteBuffer(this.fcolorBuffer); - com.engine.render.Buffer.prototype.dispose.call(this); - } - ,fillrect: function(x,y,width,height,r,g,b,a) { - if(a == null) a = 1; - this.fvertex(x,y,0); - this.fcolor(r,g,b,a); - this.fvertex(x + width,y,0); - this.fcolor(r,g,b,a); - this.fvertex(x + width,y + height,0); - this.fcolor(r,g,b,a); - this.fvertex(x + width,y + height,0); - this.fcolor(r,g,b,a); - this.fvertex(x,y + height,0); - this.fcolor(r,g,b,a); - this.fvertex(x,y,0); - this.fcolor(r,g,b,a); - } - ,rect: function(x,y,width,height,r,g,b,a) { - if(a == null) a = 1; - this.vertex(x,y,0); - this.color(r,g,b,a); - this.vertex(x + width,y,0); - this.color(r,g,b,a); - this.vertex(x + width,y,0); - this.color(r,g,b,a); - this.vertex(x + width,y + height,0); - this.color(r,g,b,a); - this.vertex(x + width,y + height,0); - this.color(r,g,b,a); - this.vertex(x,y + height,0); - this.color(r,g,b,a); - this.vertex(x,y + height,0); - this.color(r,g,b,a); - this.vertex(x,y,0); - this.color(r,g,b,a); - } - ,line: function(x1,y1,x2,y2,r,g,b,a) { - if(a == null) a = 1; - this.vertex(x1,y1); - this.color(r,g,b,a); - this.vertex(x2,y2); - this.color(r,g,b,a); - } - ,fillellipse: function(x,y,width,height,segments,r,g,b,a) { - if(a == null) a = 1; - var angle = 6.2831852 / segments; - var cx = x + width / 2; - var cy = y + height / 2; - var _g = 0; - while(_g < segments) { - var i = _g++; - this.fvertex(cx + width * 0.5 * Math.cos(i * angle),cy + height * 0.5 * Math.sin(i * angle),0); - this.fcolor(r,g,b,a); - this.fvertex(cx,cy,0); - this.fcolor(r,g,b,a); - this.fvertex(cx + width * 0.5 * Math.cos((i + 1) * angle),cy + height * 0.5 * Math.sin((i + 1) * angle),0); - this.fcolor(r,g,b,a); - } - } - ,ellipse: function(x,y,width,height,segments,r,g,b,a) { - if(a == null) a = 1; - var angle = 6.2831852 / segments; - var cx = x + width / 2; - var cy = y + height / 2; - var _g = 0; - while(_g < segments) { - var i = _g++; - this.vertex(cx + width * 0.5 * Math.cos(i * angle),cy + height * 0.5 * Math.sin(i * angle),0); - this.color(r,g,b,a); - this.vertex(cx + width * 0.5 * Math.cos((i + 1) * angle),cy + height * 0.5 * Math.sin((i + 1) * angle),0); - this.color(r,g,b,a); - } - } - ,fillcircle: function(x,y,radius,segments,r,g,b,a) { - if(a == null) a = 1; - var angle = 6.2831852 / segments; - var cos = Math.cos(angle); - var sin = Math.sin(angle); - var cx = radius; - var cy = 0; - segments--; - var _g = 0; - while(_g < segments) { - var i = _g++; - this.fvertex(x,y,0); - this.fcolor(r,g,b,a); - this.fvertex(x + cx,y + cy,0); - this.fcolor(r,g,b,a); - var temp = cx; - cx = cos * cx - sin * cy; - cy = sin * temp + cos * cy; - this.fvertex(x + cx,y + cy,0); - this.fcolor(r,g,b,a); - } - this.fvertex(x,y,0); - this.fcolor(r,g,b,a); - this.fvertex(x + cx,y + cy,0); - this.fcolor(r,g,b,a); - var temp = cx; - cx = radius; - cy = 0; - this.fvertex(x + cx,y + cy,0); - this.fcolor(r,g,b,a); - } - ,circle: function(x,y,radius,segments,r,g,b,a) { - if(a == null) a = 1; - var angle = 6.2831852 / segments; - var cos = Math.cos(angle); - var sin = Math.sin(angle); - var cx = radius; - var cy = 0; - var _g = 0; - while(_g < segments) { - var i = _g++; - this.vertex(x + cx,y + cy,0); - this.color(r,g,b,a); - var temp = cx; - cx = cos * cx - sin * cy; - cy = sin * temp + cos * cy; - this.vertex(x + cx,y + cy,0); - this.color(r,g,b,a); - } - this.vertex(x + cx,y + cy,0); - this.color(r,g,b,a); - this.vertex(x,y,0); - this.color(r,g,b,a); - this.vertex(x + cx,y + cy,0); - this.color(r,g,b,a); - var temp = cx; - cx = radius; - cy = 0; - this.vertex(x + cx,y + cy,0); - this.color(r,g,b,a); - } - ,end: function() { - this.shader.Enable(); - com.engine.render.BlendMode.setBlend(this.currentBlendMode); - openfl.gl.GL.uniformMatrix4fv(this.shader.projectionMatrixUniform,false,new Float32Array(com.engine.game.Game.projMatrix.m)); - openfl.gl.GL.uniformMatrix4fv(this.shader.modelViewMatrixUniform,false,new Float32Array(this.viewMatrix.m)); - openfl.gl.GL.bindBuffer(34962,this.fvertexBuffer); - openfl.gl.GL.bufferSubData(34962,0,this.fvertices); - openfl.gl.GL.vertexAttribPointer(this.shader.vertexAttribute,3,5126,false,0,0); - openfl.gl.GL.bindBuffer(34962,this.fcolorBuffer); - openfl.gl.GL.bufferSubData(34962,0,this.fcolors); - openfl.gl.GL.vertexAttribPointer(this.shader.colorAttribute,4,5126,false,0,0); - openfl.gl.GL.drawArrays(4,0,this.fidxPos / 3 | 0); - openfl.gl.GL.bindBuffer(34962,this.vertexBuffer); - openfl.gl.GL.bufferSubData(34962,0,this.vertices); - openfl.gl.GL.vertexAttribPointer(this.shader.vertexAttribute,3,5126,false,0,0); - openfl.gl.GL.bindBuffer(34962,this.colorBuffer); - openfl.gl.GL.bufferSubData(34962,0,this.colors); - openfl.gl.GL.vertexAttribPointer(this.shader.colorAttribute,4,5126,false,0,0); - openfl.gl.GL.drawArrays(1,0,this.idxPos / 3 | 0); - this.shader.Disable(); - } - ,begin: function() { - this.idxPos = 0; - this.idxCols = 0; - this.fidxPos = 0; - this.fidxCols = 0; - } - ,fcolor: function(r,g,b,a) { - if(a == null) a = 0.0; - this.fcolors[this.fidxCols++] = r; - this.fcolors[this.fidxCols++] = g; - this.fcolors[this.fidxCols++] = b; - this.fcolors[this.fidxCols++] = a; - } - ,fvertex: function(x,y,z) { - if(z == null) z = 0.0; - this.fvertices[this.fidxPos++] = x; - this.fvertices[this.fidxPos++] = y; - this.fvertices[this.fidxPos++] = z; - } - ,color: function(r,g,b,a) { - if(a == null) a = 0.0; - this.colors[this.idxCols++] = r; - this.colors[this.idxCols++] = g; - this.colors[this.idxCols++] = b; - this.colors[this.idxCols++] = a; - } - ,vertex: function(x,y,z) { - if(z == null) z = 0.0; - this.vertices[this.idxPos++] = x; - this.vertices[this.idxPos++] = y; - this.vertices[this.idxPos++] = z; - } - ,__class__: com.engine.render.BatchPrimitives -}); com.engine.render.BlendMode = function() { } $hxClasses["com.engine.render.BlendMode"] = com.engine.render.BlendMode; com.engine.render.BlendMode.__name__ = ["com","engine","render","BlendMode"]; com.engine.render.BlendMode.setBlend = function(mode) { switch(mode) { case 0: - openfl.gl.GL.blendFunc(1,771); + openfl.gl.GL.blendFunc(770,771); break; case 1: openfl.gl.GL.blendFunc(770,772); @@ -3748,6 +3675,28 @@ com.engine.render.BlendMode.setBlend = function(mode) { openfl.gl.GL.blendFunc(1,771); } } +com.engine.render.Buffer = function() { + this.position = new com.engine.math.Vector2(0,0); + this.rotation = 0; + this.scale = 1; + this.viewMatrix = com.engine.math.Matrix.FromValues(1.0,0,0,0,0,1.0,0,0,0,0,1.0,0,0,0,0,1.0); +}; +$hxClasses["com.engine.render.Buffer"] = com.engine.render.Buffer; +com.engine.render.Buffer.__name__ = ["com","engine","render","Buffer"]; +com.engine.render.Buffer.prototype = { + dispose: function() { + } + ,update: function() { + this.viewMatrix.set2Dtransformation(Math.round(this.position.x),Math.round(this.position.y),this.scale,this.rotation); + } + ,combineMatrix: function(m) { + this.viewMatrix.Multiply4x4(this.viewMatrix,m); + } + ,getMatrix: function() { + return this.viewMatrix; + } + ,__class__: com.engine.render.Buffer +} com.engine.render.Clip = function(x,y,width,height) { if(height == null) height = 0; if(width == null) width = 0; @@ -3769,13 +3718,676 @@ com.engine.render.Clip.prototype = { } ,__class__: com.engine.render.Clip } -com.engine.render.PrimitiveShader = function() { - var vertexShaderSource = "\r\nattribute vec3 aVertexPosition;\r\nattribute vec4 aColor;\r\n\r\nvarying vec4 vColor;\r\n\r\nuniform mat4 uModelViewMatrix;\r\nuniform mat4 uProjectionMatrix;\r\nvoid main(void) \r\n{\r\nvColor = aColor;\r\ngl_Position = uProjectionMatrix * uModelViewMatrix * vec4 (aVertexPosition, 1.0);\r\n}"; +com.engine.render.Image = function(Tex) { + this.clip = new com.engine.render.Clip(0,0,Tex.width,Tex.height); + this.angle = 0; + this.scaleX = 1; + this.scaleY = 1; + this.originX = 0; + this.originY = 0; + this.red = 1; + this.green = 1; + this.blue = 1; + this.alpha = 1; + this.x = 0; + this.y = 0; + this.width = Tex.width; + this.height = Tex.height; + this.flipX = false; + this.flipY = false; + this.blendMode = com.engine.render.BlendMode.NORMAL; + this.red = 1; + this.green = 1; + this.blue = 1; + this.alpha = 1; + this.texture = Tex; +}; +$hxClasses["com.engine.render.Image"] = com.engine.render.Image; +com.engine.render.Image.__name__ = ["com","engine","render","Image"]; +com.engine.render.Image.prototype = { + __class__: com.engine.render.Image +} +com.engine.render.SpriteBatch = function(capacity) { + this.invTexHeight = 0; + this.invTexWidth = 0; + this.numBlend = 0; + this.numTex = 0; + com.engine.render.Buffer.call(this); + this.capacity = capacity; + this.vertexStrideSize = 36; + this.numVerts = capacity * this.vertexStrideSize * 4; + this.numIndices = capacity * 6; + this.vertices = new Float32Array(this.numVerts); + var indices = []; + var index = 0; + var _g1 = 0, _g = this.numIndices; + while(_g1 < _g) { + var count = _g1++; + indices.push(index); + indices.push(index + 1); + indices.push(index + 2); + indices.push(index); + indices.push(index + 2); + indices.push(index + 3); + index += 4; + } + this.drawing = false; + this.currentBatchSize = 0; + this.currentBlendMode = com.engine.render.BlendMode.NORMAL; + this.currentBaseTexture = null; + this.vertexBuffer = openfl.gl.GL.createBuffer(); + this.indexBuffer = openfl.gl.GL.createBuffer(); + openfl.gl.GL.bindBuffer(34963,this.indexBuffer); + openfl.gl.GL.bufferData(34963,new Int16Array(indices),35044); + openfl.gl.GL.bindBuffer(34962,this.vertexBuffer); + openfl.gl.GL.bufferData(34962,this.vertices,35048); + this.shader = new com.engine.render.SpriteShader(); + this.start(); +}; +$hxClasses["com.engine.render.SpriteBatch"] = com.engine.render.SpriteBatch; +com.engine.render.SpriteBatch.__name__ = ["com","engine","render","SpriteBatch"]; +com.engine.render.SpriteBatch.__super__ = com.engine.render.Buffer; +com.engine.render.SpriteBatch.prototype = $extend(com.engine.render.Buffer.prototype,{ + dispose: function() { + this.vertices = null; + openfl.gl.GL.deleteBuffer(this.indexBuffer); + openfl.gl.GL.deleteBuffer(this.vertexBuffer); + com.engine.render.Buffer.prototype.dispose.call(this); + } + ,setBlendMode: function(blendMode) { + this.flush(); + this.currentBlendMode = blendMode; + com.engine.render.BlendMode.setBlend(this.currentBlendMode); + this.numBlend++; + } + ,switchTexture: function(texture) { + this.flush(); + this.currentBaseTexture = texture; + this.invTexWidth = 1.0 / texture.width; + this.invTexHeight = 1.0 / texture.height; + } + ,flush: function() { + if(this.currentBatchSize == 0) return; + this.update(); + this.currentBaseTexture.Bind(); + this.numTex++; + openfl.gl.GL.uniformMatrix4fv(this.shader.projectionMatrixUniform,false,new Float32Array(com.engine.game.Game.projMatrix.m)); + openfl.gl.GL.uniformMatrix4fv(this.shader.modelViewMatrixUniform,false,new Float32Array(this.viewMatrix.m)); + openfl.gl.GL.uniform1i(this.shader.imageUniform,0); + openfl.gl.GL.bufferSubData(34962,0,this.vertices); + openfl.gl.GL.bindBuffer(34963,this.indexBuffer); + openfl.gl.GL.drawElements(4,this.currentBatchSize * 6,5123,0); + this.currentBatchSize = 0; + } + ,start: function() { + this.shader.Enable(); + openfl.gl.GL.activeTexture(33984); + openfl.gl.GL.bindBuffer(34962,this.vertexBuffer); + openfl.gl.GL.vertexAttribPointer(this.shader.vertexAttribute,3,5126,false,this.vertexStrideSize,0); + openfl.gl.GL.vertexAttribPointer(this.shader.texCoordAttribute,2,5126,false,this.vertexStrideSize,12); + openfl.gl.GL.vertexAttribPointer(this.shader.colorAttribute,4,5126,false,this.vertexStrideSize,20); + if(this.currentBlendMode != com.engine.render.BlendMode.NORMAL) this.setBlendMode(this.currentBlendMode); + } + ,End: function() { + this.flush(); + this.shader.Disable(); + } + ,Begin: function() { + this.numTex = 0; + this.numBlend = 0; + this.currentBatchSize = 0; + this.start(); + } + ,RenderNormal: function(texture,x,y,blendMode) { + if(texture != this.currentBaseTexture || this.currentBatchSize >= this.capacity) this.switchTexture(texture); + if(blendMode != this.currentBlendMode) this.setBlendMode(blendMode); + var u = 0; + var v = 1; + var u2 = 1; + var v2 = 0; + var fx2 = x + texture.width; + var fy2 = y + texture.height; + var index = this.currentBatchSize * this.vertexStrideSize; + this.vertices[index++] = x; + this.vertices[index++] = y; + this.vertices[index++] = 0; + this.vertices[index++] = u; + this.vertices[index++] = v; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = x; + this.vertices[index++] = fy2; + this.vertices[index++] = 0; + this.vertices[index++] = u; + this.vertices[index++] = v2; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = fx2; + this.vertices[index++] = fy2; + this.vertices[index++] = 0; + this.vertices[index++] = u2; + this.vertices[index++] = v2; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = fx2; + this.vertices[index++] = y; + this.vertices[index++] = 0; + this.vertices[index++] = u2; + this.vertices[index++] = v; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.currentBatchSize++; + } + ,drawImage: function(img) { + if(img.texture != this.currentBaseTexture || this.currentBatchSize >= this.capacity) this.switchTexture(img.texture); + if(img.blendMode != this.currentBlendMode) this.setBlendMode(img.blendMode); + var r, g, b, a; + r = img.red; + g = img.green; + b = img.blue; + a = img.alpha; + var index = this.currentBatchSize * this.vertexStrideSize; + var worldOriginX = img.x + img.originX; + var worldOriginY = img.y + img.originY; + var fx = -img.originX; + var fy = -img.originY; + var fx2 = img.width - img.originX; + var fy2 = img.height - img.originY; + if(img.scaleX != 1 || img.scaleY != 1) { + fx *= img.scaleX; + fy *= img.scaleY; + fx2 *= img.scaleX; + fy2 *= img.scaleY; + } + var p1x = fx; + var p1y = fy; + var p2x = fx; + var p2y = fy2; + var p3x = fx2; + var p3y = fy2; + var p4x = fx2; + var p4y = fy; + var x1; + var y1; + var x2; + var y2; + var x3; + var y3; + var x4; + var y4; + if(img.angle != 0) { + var angle = img.angle * Math.PI / 180; + var cos = Math.cos(angle); + var sin = Math.sin(angle); + x1 = cos * p1x - sin * p1y; + y1 = sin * p1x + cos * p1y; + x2 = cos * p2x - sin * p2y; + y2 = sin * p2x + cos * p2y; + x3 = cos * p3x - sin * p3y; + y3 = sin * p3x + cos * p3y; + x4 = x1 + (x3 - x2); + y4 = y3 - (y2 - y1); + } else { + x1 = p1x; + y1 = p1y; + x2 = p2x; + y2 = p2y; + x3 = p3x; + y3 = p3y; + x4 = p4x; + y4 = p4y; + } + x1 += worldOriginX; + y1 += worldOriginY; + x2 += worldOriginX; + y2 += worldOriginY; + x3 += worldOriginX; + y3 += worldOriginY; + x4 += worldOriginX; + y4 += worldOriginY; + var u = img.clip.x * this.invTexWidth; + var u2 = (img.clip.x + img.clip.width) * this.invTexWidth; + var v = (img.clip.y + img.clip.height) * this.invTexHeight; + var v2 = img.clip.y * this.invTexHeight; + if(img.flipX) { + var tmp = u; + u = u2; + u2 = tmp; + } + if(img.flipY) { + var tmp = v; + v = v2; + v2 = tmp; + } + this.vertices[index++] = x1; + this.vertices[index++] = y1; + this.vertices[index++] = 0; + this.vertices[index++] = u; + this.vertices[index++] = v; + this.vertices[index++] = r; + this.vertices[index++] = g; + this.vertices[index++] = b; + this.vertices[index++] = a; + this.vertices[index++] = x2; + this.vertices[index++] = y2; + this.vertices[index++] = 0; + this.vertices[index++] = u; + this.vertices[index++] = v2; + this.vertices[index++] = r; + this.vertices[index++] = g; + this.vertices[index++] = b; + this.vertices[index++] = a; + this.vertices[index++] = x3; + this.vertices[index++] = y3; + this.vertices[index++] = 0; + this.vertices[index++] = u2; + this.vertices[index++] = v2; + this.vertices[index++] = r; + this.vertices[index++] = g; + this.vertices[index++] = b; + this.vertices[index++] = a; + this.vertices[index++] = x4; + this.vertices[index++] = y4; + this.vertices[index++] = 0; + this.vertices[index++] = u2; + this.vertices[index++] = v; + this.vertices[index++] = r; + this.vertices[index++] = g; + this.vertices[index++] = b; + this.vertices[index++] = a; + this.currentBatchSize++; + } + ,RenderClip: function(texture,x,y,c,flipX,flipY,blendMode) { + if(texture != this.currentBaseTexture || this.currentBatchSize >= this.capacity) this.switchTexture(texture); + if(blendMode != this.currentBlendMode) this.setBlendMode(blendMode); + var u = c.x * this.invTexWidth; + var u2 = (c.x + c.width) * this.invTexWidth; + var v = (c.y + c.height) * this.invTexHeight; + var v2 = c.y * this.invTexHeight; + var fx2 = x + c.width; + var fy2 = y + c.height; + if(flipX) { + var tmp = u; + u = u2; + u2 = tmp; + } + if(flipY) { + var tmp = v; + v = v2; + v2 = tmp; + } + var index = this.currentBatchSize * this.vertexStrideSize; + this.vertices[index++] = x; + this.vertices[index++] = y; + this.vertices[index++] = 0; + this.vertices[index++] = u; + this.vertices[index++] = v; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = x; + this.vertices[index++] = fy2; + this.vertices[index++] = 0; + this.vertices[index++] = u; + this.vertices[index++] = v2; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = fx2; + this.vertices[index++] = fy2; + this.vertices[index++] = 0; + this.vertices[index++] = u2; + this.vertices[index++] = v2; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = fx2; + this.vertices[index++] = y; + this.vertices[index++] = 0; + this.vertices[index++] = u2; + this.vertices[index++] = v; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.currentBatchSize++; + } + ,Blt: function(texture,src,dst,flipX,flipY,blendMode) { + if(texture != this.currentBaseTexture || this.currentBatchSize >= this.capacity) this.switchTexture(texture); + if(blendMode != this.currentBlendMode) this.setBlendMode(blendMode); + var fx2 = src.x + src.width; + var fy2 = src.y + src.height; + var u = dst.x * this.invTexWidth; + var u2 = (dst.x + dst.width) * this.invTexWidth; + var v = (dst.y + dst.height) * this.invTexHeight; + var v2 = dst.y * this.invTexHeight; + if(flipX) { + var tmp = u; + u = u2; + u2 = tmp; + } + if(flipY) { + var tmp = v; + v = v2; + v2 = tmp; + } + var index = this.currentBatchSize * this.vertexStrideSize; + this.vertices[index++] = src.x; + this.vertices[index++] = src.y; + this.vertices[index++] = 0; + this.vertices[index++] = u; + this.vertices[index++] = v; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = src.x; + this.vertices[index++] = fy2; + this.vertices[index++] = 0; + this.vertices[index++] = u; + this.vertices[index++] = v2; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = fx2; + this.vertices[index++] = fy2; + this.vertices[index++] = 0; + this.vertices[index++] = u2; + this.vertices[index++] = v2; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = fx2; + this.vertices[index++] = src.y; + this.vertices[index++] = 0; + this.vertices[index++] = u2; + this.vertices[index++] = v; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.currentBatchSize++; + } + ,drawEntity: function(obj) { + if(obj.image != this.currentBaseTexture || this.currentBatchSize >= this.capacity) this.switchTexture(obj.image); + if(obj.blendMode != this.currentBlendMode) this.setBlendMode(obj.blendMode); + var u = obj.clip.x * this.invTexWidth; + var u2 = (obj.clip.x + obj.clip.width) * this.invTexWidth; + var v = (obj.clip.y + obj.clip.height) * this.invTexHeight; + var v2 = obj.clip.y * this.invTexHeight; + if(obj.flipx) { + var tmp = u; + u = u2; + u2 = tmp; + } + if(obj.flipy) { + var tmp = v; + v = v2; + v2 = tmp; + } + var index = this.currentBatchSize * this.vertexStrideSize; + var TempX1 = 0; + var TempY1 = 0; + var TempX2 = obj.clip.width; + var TempY2 = obj.clip.height; + var r = obj.red; + var g = obj.green; + var b = obj.blue; + var a = obj.alpha; + this.vertices[index + 2] = obj.depth; + this.vertices[index + 9 + 2] = obj.depth; + this.vertices[index + 18 + 2] = obj.depth; + this.vertices[index + 27 + 2] = obj.depth; + this.vertices[index] = TempX1; + this.vertices[index + 1] = TempY1; + this.vertices[index + 9] = TempX1; + this.vertices[index + 9 + 1] = TempY2; + this.vertices[index + 18] = TempX2; + this.vertices[index + 18 + 1] = TempX2; + this.vertices[index + 27] = TempX2; + this.vertices[index + 27 + 1] = TempY1; + this.vertices[index + 3] = u; + this.vertices[index + 4] = v2; + this.vertices[index + 9 + 3] = u; + this.vertices[index + 9 + 4] = v; + this.vertices[index + 18 + 3] = u2; + this.vertices[index + 18 + 4] = v; + this.vertices[index + 27 + 3] = u2; + this.vertices[index + 27 + 4] = v2; + this.vertices[index + 5] = r; + this.vertices[index + 6] = g; + this.vertices[index + 7] = b; + this.vertices[index + 8] = a; + this.vertices[index + 9 + 5] = r; + this.vertices[index + 9 + 6] = g; + this.vertices[index + 9 + 7] = b; + this.vertices[index + 9 + 8] = a; + this.vertices[index + 18 + 5] = r; + this.vertices[index + 18 + 6] = g; + this.vertices[index + 18 + 7] = b; + this.vertices[index + 18 + 8] = a; + this.vertices[index + 27 + 5] = r; + this.vertices[index + 27 + 6] = g; + this.vertices[index + 27 + 7] = b; + this.vertices[index + 27 + 8] = a; + var matrix = obj.getLocalToWorldMatrix(); + var _g = 0; + while(_g < 4) { + var i = _g++; + var x = this.vertices[index + i * 9]; + var y = this.vertices[index + i * 9 + 1]; + this.vertices[index + i * 9] = matrix.a * x + matrix.c * y + matrix.tx; + this.vertices[index + i * 9 + 1] = matrix.d * y + matrix.b * x + matrix.ty; + } + this.currentBatchSize++; + } + ,drawEntitys: function(obj) { + var _g1 = 0, _g = obj.children.length; + while(_g1 < _g) { + var i = _g1++; + var o = obj.children[i]; + this.drawEntity(o); + } + } + ,RenderTileScale: function(texture,x,y,width,height,scaleX,scaleY,clip,flipx,flipy,blendMode) { + if(texture != this.currentBaseTexture || this.currentBatchSize >= this.capacity) this.switchTexture(texture); + if(blendMode != this.currentBlendMode) this.setBlendMode(blendMode); + var fx = x; + var fy = y; + var fx2 = x + width; + var fy2 = y + height; + if(scaleX != 1 || scaleY != 1) { + fx *= scaleX; + fy *= scaleY; + fx2 *= scaleX; + fy2 *= scaleY; + } + var u = clip.x * this.invTexWidth; + var u2 = (clip.x + clip.width) * this.invTexWidth; + var v = (clip.y + clip.height) * this.invTexHeight; + var v2 = clip.y * this.invTexHeight; + if(flipx) { + var tmp = u; + u = u2; + u2 = tmp; + } + if(flipy) { + var tmp = v; + v = v2; + v2 = tmp; + } + var index = this.currentBatchSize * this.vertexStrideSize; + this.vertices[index++] = fx; + this.vertices[index++] = fy; + this.vertices[index++] = 0; + this.vertices[index++] = u; + this.vertices[index++] = v; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = fx; + this.vertices[index++] = fy2; + this.vertices[index++] = 0; + this.vertices[index++] = u; + this.vertices[index++] = v2; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = fx2; + this.vertices[index++] = fy2; + this.vertices[index++] = 0; + this.vertices[index++] = u2; + this.vertices[index++] = v2; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = fx2; + this.vertices[index++] = fy; + this.vertices[index++] = 0; + this.vertices[index++] = u2; + this.vertices[index++] = v; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.currentBatchSize++; + } + ,RenderTile: function(texture,x,y,width,height,clip,flipx,flipy,blendMode) { + if(texture != this.currentBaseTexture || this.currentBatchSize >= this.capacity) this.switchTexture(texture); + if(blendMode != this.currentBlendMode) this.setBlendMode(blendMode); + var fx2 = x + width; + var fy2 = y + height; + var u = clip.x * this.invTexWidth; + var u2 = (clip.x + clip.width) * this.invTexWidth; + var v = (clip.y + clip.height) * this.invTexHeight; + var v2 = clip.y * this.invTexHeight; + if(flipx) { + var tmp = u; + u = u2; + u2 = tmp; + } + if(flipy) { + var tmp = v; + v = v2; + v2 = tmp; + } + var index = this.currentBatchSize * this.vertexStrideSize; + this.vertices[index++] = x; + this.vertices[index++] = y; + this.vertices[index++] = 0; + this.vertices[index++] = u; + this.vertices[index++] = v; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = x; + this.vertices[index++] = fy2; + this.vertices[index++] = 0; + this.vertices[index++] = u; + this.vertices[index++] = v2; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = fx2; + this.vertices[index++] = fy2; + this.vertices[index++] = 0; + this.vertices[index++] = u2; + this.vertices[index++] = v2; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = fx2; + this.vertices[index++] = y; + this.vertices[index++] = 0; + this.vertices[index++] = u2; + this.vertices[index++] = v; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.currentBatchSize++; + } + ,Render: function(texture,x,y,srcX,srcY,srcWidth,srcHeight,blendMode) { + if(texture != this.currentBaseTexture || this.currentBatchSize >= this.capacity) this.switchTexture(texture); + if(blendMode != this.currentBlendMode) this.setBlendMode(blendMode); + var u = srcX * this.invTexWidth; + var v = (srcY + srcHeight) * this.invTexHeight; + var u2 = (srcX + srcWidth) * this.invTexWidth; + var v2 = srcY * this.invTexHeight; + var fx2 = x + srcWidth; + var fy2 = y + srcHeight; + var r, g, b, a; + r = 1; + g = 1; + b = 1; + a = 1; + var index = this.currentBatchSize * this.vertexStrideSize; + this.vertices[index++] = x; + this.vertices[index++] = y; + this.vertices[index++] = 0; + this.vertices[index++] = u; + this.vertices[index++] = v; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = x; + this.vertices[index++] = fy2; + this.vertices[index++] = 0; + this.vertices[index++] = u; + this.vertices[index++] = v2; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = fx2; + this.vertices[index++] = fy2; + this.vertices[index++] = 0; + this.vertices[index++] = u2; + this.vertices[index++] = v2; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = fx2; + this.vertices[index++] = y; + this.vertices[index++] = 0; + this.vertices[index++] = u2; + this.vertices[index++] = v; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.vertices[index++] = 1; + this.currentBatchSize++; + } + ,__class__: com.engine.render.SpriteBatch +}); +com.engine.render.SpriteShader = function() { + var vertexShaderSource = "\r\nattribute vec3 aVertexPosition;\r\nattribute vec2 aTexCoord;\r\nattribute vec4 aColor;\r\n\r\nvarying vec2 vTexCoord;\r\nvarying vec4 vColor;\r\n\r\nuniform mat4 uModelViewMatrix;\r\nuniform mat4 uProjectionMatrix;\r\nvoid main(void) \r\n{\r\nvTexCoord = aTexCoord;\r\nvColor = aColor;\r\ngl_Position = uProjectionMatrix * uModelViewMatrix * vec4 (aVertexPosition, 1.0);\r\n\r\n}"; var vertexShader = openfl.gl.GL.createShader(35633); openfl.gl.GL.shaderSource(vertexShader,vertexShaderSource); openfl.gl.GL.compileShader(vertexShader); if(openfl.gl.GL.getShaderParameter(vertexShader,35713) == 0) throw openfl.gl.GL.getShaderInfoLog(vertexShader); - var fragmentShaderSource = "precision mediump float;" + "\r\n\r\nvarying vec4 vColor;\r\nvoid main(void)\r\n{\r\n\tgl_FragColor = vColor;\r\n}"; + var fragmentShaderSource = "precision mediump float;" + "\r\nvarying vec2 vTexCoord;\r\nvarying vec4 vColor;\r\nuniform sampler2D uImage0;\r\n\r\nvoid main(void)\r\n{\r\n\tgl_FragColor = texture2D (uImage0, vTexCoord) * vColor;\r\n\r\n}"; var fragmentShader = openfl.gl.GL.createShader(35632); openfl.gl.GL.shaderSource(fragmentShader,fragmentShaderSource); openfl.gl.GL.compileShader(fragmentShader); @@ -3786,26 +4398,32 @@ com.engine.render.PrimitiveShader = function() { openfl.gl.GL.linkProgram(this.shaderProgram); if(openfl.gl.GL.getProgramParameter(this.shaderProgram,35714) == 0) throw "Unable to initialize the shader program."; this.vertexAttribute = openfl.gl.GL.getAttribLocation(this.shaderProgram,"aVertexPosition"); + this.texCoordAttribute = openfl.gl.GL.getAttribLocation(this.shaderProgram,"aTexCoord"); this.colorAttribute = openfl.gl.GL.getAttribLocation(this.shaderProgram,"aColor"); this.projectionMatrixUniform = openfl.gl.GL.getUniformLocation(this.shaderProgram,"uProjectionMatrix"); this.modelViewMatrixUniform = openfl.gl.GL.getUniformLocation(this.shaderProgram,"uModelViewMatrix"); + this.imageUniform = openfl.gl.GL.getUniformLocation(this.shaderProgram,"uImage0"); }; -$hxClasses["com.engine.render.PrimitiveShader"] = com.engine.render.PrimitiveShader; -com.engine.render.PrimitiveShader.__name__ = ["com","engine","render","PrimitiveShader"]; -com.engine.render.PrimitiveShader.prototype = { +$hxClasses["com.engine.render.SpriteShader"] = com.engine.render.SpriteShader; +com.engine.render.SpriteShader.__name__ = ["com","engine","render","SpriteShader"]; +com.engine.render.SpriteShader.prototype = { Disable: function() { openfl.gl.GL.disableVertexAttribArray(this.vertexAttribute); + openfl.gl.GL.disableVertexAttribArray(this.texCoordAttribute); openfl.gl.GL.disableVertexAttribArray(this.colorAttribute); } ,Enable: function() { openfl.gl.GL.useProgram(this.shaderProgram); openfl.gl.GL.enableVertexAttribArray(this.vertexAttribute); + openfl.gl.GL.enableVertexAttribArray(this.texCoordAttribute); openfl.gl.GL.enableVertexAttribArray(this.colorAttribute); } - ,__class__: com.engine.render.PrimitiveShader + ,__class__: com.engine.render.SpriteShader } -com.engine.render.Texture = function(url) { +com.engine.render.Texture = function(url,flip) { + if(flip == null) flip = false; this.bitmapData = openfl.Assets.getBitmapData(url); + if(flip) this.bitmapData = com.engine.misc.MatrixHelp.flipBitmapData(this.bitmapData,null); this.data = openfl.gl.GL.createTexture(); openfl.gl.GL.bindTexture(3553,this.data); this.width = this.bitmapData.get_width(); @@ -9728,17 +10346,6 @@ flash.ui.Keyboard.__convertWebkitCode = function(code) { throw "Unrecognized key code: " + code; return 0; } -flash.ui.Mouse = function() { -}; -$hxClasses["flash.ui.Mouse"] = flash.ui.Mouse; -flash.ui.Mouse.__name__ = ["flash","ui","Mouse"]; -flash.ui.Mouse.hide = function() { -} -flash.ui.Mouse.show = function() { -} -flash.ui.Mouse.prototype = { - __class__: flash.ui.Mouse -} flash.ui.Multitouch = function() { } $hxClasses["flash.ui.Multitouch"] = flash.ui.Multitouch; flash.ui.Multitouch.__name__ = ["flash","ui","Multitouch"]; diff --git a/bin/windows/neko/bin/assets/hxlogo.png b/bin/windows/neko/bin/assets/hxlogo.png index dc6895c..aa923fd 100755 Binary files a/bin/windows/neko/bin/assets/hxlogo.png and b/bin/windows/neko/bin/assets/hxlogo.png differ diff --git a/bin/windows/neko/bin/glframework.exe b/bin/windows/neko/bin/glframework.exe index b782420..d498cde 100755 Binary files a/bin/windows/neko/bin/glframework.exe and b/bin/windows/neko/bin/glframework.exe differ diff --git a/bin/windows/neko/obj/ApplicationMain.n b/bin/windows/neko/obj/ApplicationMain.n index f528f91..e16bf03 100755 Binary files a/bin/windows/neko/obj/ApplicationMain.n and b/bin/windows/neko/obj/ApplicationMain.n differ diff --git a/src/com/djoker/glteste/Main.hx b/src/com/djoker/glteste/Main.hx index a7715bb..ef127d6 100755 --- a/src/com/djoker/glteste/Main.hx +++ b/src/com/djoker/glteste/Main.hx @@ -54,7 +54,7 @@ override function begin() -this.setScreen(new TesteBatch()); +//this.setScreen(new TesteBatch()); //this.setScreen(new TesteAtlas()); //this.setScreen(new TestneBatch()); //this.setScreen(new TesteCloud()); @@ -64,6 +64,9 @@ this.setScreen(new TesteBatch()); //this.setScreen(new TestePrimitives()); //this.setScreen(new TesteBitmap()); //this.setScreen(new TesteDraTiles()); +this.setScreen(new TestTrasform()); + + } diff --git a/src/com/djoker/glteste/TestTrasform.hx b/src/com/djoker/glteste/TestTrasform.hx new file mode 100755 index 0000000..134dd66 --- /dev/null +++ b/src/com/djoker/glteste/TestTrasform.hx @@ -0,0 +1,109 @@ +package com.djoker.glteste; + + +import com.engine.game.Entity; +import com.engine.game.Screen; +import com.engine.render.SpriteBatch; +import com.engine.render.Texture; +import com.engine.render.BlendMode; + +import flash.events.Event; +import flash.text.TextField; +import flash.text.TextFormat; + +/** + * ... + * @author djoker + */ +class TestTrasform extends Screen +{ + + var tex :Texture; + var batch:SpriteBatch; + + + + var child:Entity; + + var player:Entity; + var logo:Entity; + + + var playerTex :Texture; + var skew:Float = 0; + + + override public function show() + { + + playerTex = new Texture("assets/zazaka.png", true); + + batch = new SpriteBatch(500); + + + var caption:TextField = new TextField(); + caption.x = game.gameWidth / 2-100; + caption.y = 20; + caption.width = 200; + caption.defaultTextFormat = new TextFormat ("_sans", 12, 0xffff00); + caption.text = "Test trasform sprites by parent "; + caption.selectable = false; + game.addChild(caption); + + logo = new Entity(this.width / 2, this.height / 2, new Texture("assets/hxlogo.png", true)); + logo.blendMode = BlendMode.SCREEN; + + player = new Entity(300, 200, playerTex); + child = new Entity(0, 0, playerTex); + child.blue = 0; + + player.add(child); + + + + game.clarColor(0, 0, 0); + + + } + + override public function render(dt:Float) + { + + player.rotation += dt * 2.1; + child.rotation -= dt * 2.5; + player.skewX += dt * 0.1; + + skew += dt * 1; + + logo.skewX = Math.sin(skew)*1; + logo.skewY = Math.cos(skew)*1; + + + batch.Begin(); + + + batch.drawEntity(logo); + batch.drawEntity(player); + batch.drawEntity(child); + + + batch.End(); + + + } + + + + + + +override public function mouseDown(mousex:Float, mousey:Float) +{ + + player.x = mousex; + player.y = mousey; +} + + + +} \ No newline at end of file diff --git a/src/com/djoker/glteste/TesteBatch.hx b/src/com/djoker/glteste/TesteBatch.hx index c26cbf4..b84e76e 100755 --- a/src/com/djoker/glteste/TesteBatch.hx +++ b/src/com/djoker/glteste/TesteBatch.hx @@ -2,14 +2,13 @@ package com.djoker.glteste; import com.engine.game.Entity; import com.engine.game.Screen; +import com.engine.render.BlendMode; import com.engine.render.SpriteBatch; import com.engine.render.Texture; -import com.engine.render.BlendMode; - -import flash.events.Event; import flash.text.TextField; import flash.text.TextFormat; + /** * ... * @author djoker @@ -21,15 +20,23 @@ class TesteBatch extends Screen var batch:SpriteBatch; + + var child:Entity; + var player:Entity; + var logo:Entity; var particles : Array; - + var playerTex :Texture; + var skew:Float = 0; + override public function show() { - tex = new Texture("assets/texture.png",true); + tex = new Texture("assets/texture.png"); + playerTex = new Texture("assets/zazaka.png"); + batch = new SpriteBatch(500); particles = []; for(i in 0...200) @@ -42,9 +49,17 @@ class TesteBatch extends Screen caption.width = 200; caption.defaultTextFormat = new TextFormat ("_sans", 12, 0xffff00); caption.text = "Test 200 sprites with SpriteBatch "; + caption.selectable = false; game.addChild(caption); - player = new Entity(200,200, tex); + player = new Entity(300, 200, playerTex); + child = new Entity(0, 0, playerTex); + child.blue = 0; + player.add(child); + + logo= new Entity(this.width/2,this.height/2,new Texture("assets/hxlogo.png")); + + game.clarColor(0, 0, 0); } @@ -52,13 +67,20 @@ class TesteBatch extends Screen override public function render(dt:Float) { - //player.rotation += dt * 0.1; - player.skewX += dt * 0.1; + player.rotation += dt * 2.1; + child.rotation -= dt * 2.5; + // player.skewX += dt * 0.1; + skew += dt * 1; + logo.skewX = Math.sin(skew)*1; + logo.skewY = Math.cos(skew)*1; + - batch.Begin(); + batch.Begin(); + batch.drawEntity(logo); + for(p in particles) { p.move(dt); @@ -67,6 +89,7 @@ class TesteBatch extends Screen } batch.drawEntity(player); + batch.drawEntity(child); batch.End(); @@ -96,6 +119,8 @@ public function addParticle2(x:Float,y:Float) override public function mouseDown(mousex:Float, mousey:Float) { addParticle2(mousex, mousey); + player.x = mousex; + player.y = mousey; } diff --git a/src/com/engine/game/Entity.hx b/src/com/engine/game/Entity.hx index 1660dad..9662c5f 100755 --- a/src/com/engine/game/Entity.hx +++ b/src/com/engine/game/Entity.hx @@ -19,21 +19,30 @@ public var image:Texture; public var blendMode:Int; public var clip:Clip; public var name:String; +public var red:Float; +public var green:Float; +public var blue:Float; +public var alpha:Float; +public var depth:Float; public function new(x:Float,y:Float,image:Texture,?name:String='solid') { super(); flipx = false; - flipy = false; + flipy = true; this.image = image; this.blendMode = BlendMode.NORMAL; clip = new Clip(0, 0, image.width, image.height); - this.x = 100; + this.pivotX = clip.width/2; + this.pivotY = clip.height/2; + this.x = x; this.y = y; + this.depth = 0.0; this.name = name; - - - + red = 1; + green = 1; + blue = 1; + alpha = 1; diff --git a/src/com/engine/game/Game.hx b/src/com/engine/game/Game.hx index 21582d0..b4a2c0d 100755 --- a/src/com/engine/game/Game.hx +++ b/src/com/engine/game/Game.hx @@ -1,41 +1,23 @@ package com.engine.game; -import flash.display.Sprite; -import flash.geom.Rectangle; -import flash.geom.Matrix3D; -import flash.text.TextField; -import flash.text.TextFormat; -import flash.events.MouseEvent; -import flash.events.KeyboardEvent; -import flash.ui.Keyboard; -import flash.ui.Mouse; - -import flash.events.TouchEvent; -import flash.display.BitmapData; +import com.engine.math.Matrix; import flash.display.DisplayObject; import flash.display.Sprite; -import flash.display.StageAlign; -import flash.display.StageDisplayState; -import flash.display.StageQuality; -import flash.display.StageScaleMode; import flash.events.Event; +import flash.events.KeyboardEvent; +import flash.events.MouseEvent; +import flash.events.TouchEvent; import flash.geom.Rectangle; import flash.Lib; - import flash.ui.Multitouch; import flash.ui.MultitouchInputMode; - -import com.engine.misc.Util; -import com.engine.math.Vector3; -import com.engine.math.Matrix; - +import openfl.display.FPS; import openfl.display.OpenGLView; import openfl.gl.GL; -import openfl.gl.GLBuffer; -import openfl.gl.GLProgram; -import openfl.utils.Float32Array; -import openfl.utils.Int16Array; -import openfl.display.FPS; + + + + /** * ... * @author djoker @@ -43,7 +25,7 @@ import openfl.display.FPS; */ class Game extends OpenGLView { - public var viewPort:Rectangle; + private var ready:Bool; public var deltaTime:Float; private var prevFrame:Int; @@ -53,18 +35,21 @@ class Game extends OpenGLView private var container:Sprite; static public var scrollX:Float = 0; static public var scrollY:Float = 0; - static public var viewWidth:Float = 0; - static public var viewHeight:Float = 0; + static public var viewWidth:Int = 0; + static public var viewHeight:Int = 0; public var screenWidth:Int = 0; public var screenHeight:Int = 0; public var gameWidth:Int=0; public var gameHeight:Int = 0; private var rescale:Bool = false; + private var enableDepth:Bool; +public var red:Float; +public var green:Float; +public var blue:Float; static public var projMatrix:Matrix; - static public var viewMatrix:Matrix; @@ -81,8 +66,14 @@ class Game extends OpenGLView super(); ready = false; this.render = renderView; - viewPort = new Rectangle(0, 0, Lib.current.stage.stageWidth,Lib.current.stage.stageHeight); - + + + + + + + + screenWidth = Lib.current.stage.stageWidth; screenHeight = Lib.current.stage.stageHeight; Game.viewWidth = screenHeight; @@ -93,8 +84,7 @@ class Game extends OpenGLView Game.projMatrix=Matrix.OrthoOffCenterLH(0, gameWidth,gameHeight,0, -1, 1); - Game.viewMatrix = Matrix.Identity(); - + stage.addEventListener(Event.RESIZE, onResize); stage.addEventListener(Event.ADDED, focusGained); @@ -108,17 +98,28 @@ class Game extends OpenGLView prevFrame = Lib.getTimer(); - - - GL.disable(GL.CULL_FACE); - GL.enable(GL.DEPTH_TEST); - GL.depthFunc(GL.LEQUAL); - } - + public function setDeph(v:Bool) + { + enableDepth = v; + if (v == true) + { + GL.disable(GL.DEPTH_TEST); + } else + { + GL.enable(GL.DEPTH_TEST); + GL.depthFunc(GL.FASTEST); + } + } + public function clarColor(r:Float, g:Float, b:Float) + { + red = r; + green = g; + blue = b; + } public function removeChild(child : DisplayObject) { @@ -153,17 +154,22 @@ class Game extends OpenGLView Lib.current.stage.addEventListener(TouchEvent.TOUCH_END, doTouchUp); } - GL.disable(GL.DEPTH_TEST); + + + + // GL.disable(GL.CULL_FACE); GL.enable(GL.BLEND); + GL.blendFunc(GL.SRC_ALPHA,GL.DST_ALPHA ); GL.pixelStorei(GL.PACK_ALIGNMENT, 2); +// GL.enable(GL.DEPTH_TEST); + setDeph(true); + clarColor(0, 1, 0.4); + GL.clearColor(red, green, blue, 1); GL.depthMask(true); + + - - // GL.enable(GL.DEPTH_TEST); - // GL.enable(GL.STENCIL_TEST); - - begin(); ready = true; @@ -256,6 +262,8 @@ class Game extends OpenGLView this.screen.game = this; if (this.screen != null) { + this.screen.width = screenWidth; + this.screen.height = screenHeight; this.screen.show(); this.screen.resize(Std.int(Game.viewWidth),Std.int(Game.viewHeight)); } @@ -264,8 +272,8 @@ class Game extends OpenGLView private function renderView(rect:Rectangle):Void { - viewWidth = rect.width; - viewHeight = rect.height; + viewWidth = Std.int(rect.width); + viewHeight = Std.int(rect.height); if (rescale==true) { @@ -289,21 +297,26 @@ private function renderView(rect:Rectangle):Void } else { GL.viewport (Std.int (rect.x), Std.int (rect.y), Std.int (rect.width), Std.int (rect.height)); - //Game.projMatrix=Matrix.OrthoOffCenterLH(0, rect.width, rect.height,0, -1, 1); - Game.projMatrix=Matrix.OrthoOffCenterLH(0, gameWidth,gameHeight,0, -1, 1); + Game.projMatrix=Matrix.OrthoOffCenterLH(0, gameWidth,gameHeight,0, -1, 1); } - Game.viewMatrix=Matrix.create2D( 0, 0, 1, 0); - + nextFrame = Lib.getTimer(); deltaTime = (nextFrame - prevFrame) * 0.001; - GL.clearColor(1, 0, 1, 1); - GL.clearDepth(1); + GL.clearColor(red, green, blue, 1); + + if (enableDepth == true) + { + GL.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT); + } else + { + GL.clear(GL.COLOR_BUFFER_BIT ); + } + // GL.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT); - GL.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT); @@ -311,6 +324,8 @@ private function renderView(rect:Rectangle):Void { update(deltaTime); } + + GL.bindBuffer (GL.ARRAY_BUFFER, null); GL.useProgram (null); GL.blendFunc(GL.SRC_ALPHA,GL.DST_ALPHA ); diff --git a/src/com/engine/game/GameObject.hx b/src/com/engine/game/GameObject.hx index 57fd482..4f5c28f 100755 --- a/src/com/engine/game/GameObject.hx +++ b/src/com/engine/game/GameObject.hx @@ -9,19 +9,21 @@ import flash.geom.Matrix; */ class GameObject extends Transform { - public var children:List; + public var children:Array; public function new() { super(); - children = new List(); + children = new Array(); } - public function add(child:Transform) + public function add(child:GameObject) { - this.children.add(child); + child.parent=this ; + this.children.push(child); } - public function remove(child:Transform) + public function remove(child:GameObject) { + child.parent = null; this.children.remove(child); } diff --git a/src/com/engine/game/Screen.hx b/src/com/engine/game/Screen.hx index eb07510..ce2d2f0 100755 --- a/src/com/engine/game/Screen.hx +++ b/src/com/engine/game/Screen.hx @@ -6,10 +6,13 @@ package com.engine.game; */ class Screen extends GameObject { + public var width:Int; + public var height:Int; + public var game:Game = null; - public function show() { } + public function show() { } public function render(dt:Float) { } public function resize(width:Int, height:Int) {} diff --git a/src/com/engine/game/Text.hx b/src/com/engine/game/Text.hx new file mode 100755 index 0000000..4b7e771 --- /dev/null +++ b/src/com/engine/game/Text.hx @@ -0,0 +1,24 @@ +package com.engine.game; + +import flash.text.TextField; +import flash.text.TextFormat; +import flash.text.TextFieldType; + +/** + * ... + * @author djoker + */ +class Text extends TextField +{ + + public function new(x:Float = 10, y:Float = 10,caption:String,?size:Int=12, ?color:Int = 0xffffffff) + { + super (); + this.x = x; + this.y = y; + selectable = false; + defaultTextFormat = new TextFormat ("_sans", size, color); + text = caption; + } + +} \ No newline at end of file diff --git a/src/com/engine/game/Transform.hx b/src/com/engine/game/Transform.hx index 46dde4a..8f4d97f 100755 --- a/src/com/engine/game/Transform.hx +++ b/src/com/engine/game/Transform.hx @@ -70,7 +70,7 @@ class Transform } else { - return parent.getTransformationMatrix().mult(getTransformationMatrix()); + return getTransformationMatrix().mult(parent.getTransformationMatrix()); } diff --git a/src/com/engine/misc/MatrixHelp.hx b/src/com/engine/misc/MatrixHelp.hx index f6d7138..561c2bd 100755 --- a/src/com/engine/misc/MatrixHelp.hx +++ b/src/com/engine/misc/MatrixHelp.hx @@ -18,7 +18,7 @@ class MatrixHelp var m:flash.geom.Matrix = new flash.geom.Matrix(); m.scale(newWidth / source.width, newHeight / source.height); - var bmp:BitmapData = new BitmapData(newWidth, newHeight, true,0xff); + var bmp:BitmapData = new BitmapData(newWidth, newHeight, true); bmp.draw(source, m); return bmp; diff --git a/src/com/engine/misc/Util.hx b/src/com/engine/misc/Util.hx index 7628a48..1f35ded 100755 --- a/src/com/engine/misc/Util.hx +++ b/src/com/engine/misc/Util.hx @@ -1,11 +1,7 @@ package com.engine.misc; -import flash.display.Bitmap; -import flash.display.BitmapData; -import com.engine.math.Matrix; -import com.engine.math.Vector3; /** * ... diff --git a/src/com/engine/render/BatchPrimitives.hx b/src/com/engine/render/BatchPrimitives.hx index f2cf065..733f612 100755 --- a/src/com/engine/render/BatchPrimitives.hx +++ b/src/com/engine/render/BatchPrimitives.hx @@ -1,15 +1,10 @@ package com.engine.render; -import openfl.display.OpenGLView; +import com.engine.game.Game; import openfl.gl.GL; import openfl.gl.GLBuffer; -import openfl.gl.GLProgram; import openfl.utils.Float32Array; -import openfl.utils.Int16Array; -import openfl.display.FPS; -import com.engine.misc.Util; -import com.engine.game.Game; /** diff --git a/src/com/engine/render/BlendMode.hx b/src/com/engine/render/BlendMode.hx index 076bd20..e92e78a 100755 --- a/src/com/engine/render/BlendMode.hx +++ b/src/com/engine/render/BlendMode.hx @@ -20,9 +20,10 @@ static public function setBlend(mode:Int ) { switch( mode ) { case 0: - GL.blendFunc(GL.ONE,GL.ONE_MINUS_SRC_ALPHA ); + GL.blendFunc(GL.SRC_ALPHA,GL.ONE_MINUS_SRC_ALPHA ); + case 1: - GL.blendFunc(GL.SRC_ALPHA,GL.DST_ALPHA ); + GL.blendFunc(GL.SRC_ALPHA, GL.DST_ALPHA ); case 2: GL.blendFunc(GL.DST_COLOR,GL.ONE_MINUS_SRC_ALPHA ); case 3: diff --git a/src/com/engine/render/Camera.hx b/src/com/engine/render/Camera.hx index 9f5e26b..37ead2a 100755 --- a/src/com/engine/render/Camera.hx +++ b/src/com/engine/render/Camera.hx @@ -1,23 +1,13 @@ package com.engine.render; -import flash.display.Sprite; -import flash.geom.Rectangle; +import com.engine.game.Game; +import com.engine.math.Matrix; +import com.engine.math.Vector3; -import openfl.display.OpenGLView; -import openfl.gl.GL; -import openfl.gl.GLBuffer; -import openfl.gl.GLProgram; -import openfl.utils.Float32Array; -import openfl.utils.Int16Array; -import openfl.display.FPS; -import com.engine.misc.Util; -import com.engine.math.Vector3; -import com.engine.math.Matrix; -import com.engine.game.Game; /** diff --git a/src/com/engine/render/Image.hx b/src/com/engine/render/Image.hx index 65c4b6a..b448af7 100755 --- a/src/com/engine/render/Image.hx +++ b/src/com/engine/render/Image.hx @@ -1,6 +1,7 @@ package com.engine.render; import flash.geom.Rectangle; +import com.engine.render.BlendMode; /** * ... * @author djoker @@ -47,7 +48,11 @@ public var flipY:Bool; height = Tex.height; flipX = false; flipY = false; - blendMode = BlendMode.SCREEN; + blendMode = BlendMode.NORMAL; + red = 1; + green = 1; + blue = 1; + alpha = 1; texture = Tex; } diff --git a/src/com/engine/render/SpriteBatch.hx b/src/com/engine/render/SpriteBatch.hx index 67664c0..c08a850 100755 --- a/src/com/engine/render/SpriteBatch.hx +++ b/src/com/engine/render/SpriteBatch.hx @@ -1,20 +1,16 @@ package com.engine.render; +import com.engine.game.Entity; +import com.engine.game.Game; +import com.engine.render.BlendMode; import flash.geom.Matrix; - -import openfl.display.OpenGLView; import openfl.gl.GL; import openfl.gl.GLBuffer; -import openfl.gl.GLProgram; import openfl.utils.Float32Array; import openfl.utils.Int16Array; -import openfl.display.FPS; -import com.engine.render.BlendMode; -import com.engine.game.Game; -import com.engine.game.GameObject; -import com.engine.game.Entity; + /** * ... @@ -341,6 +337,15 @@ this.currentBatchSize++; } + public function drawEntitys(obj:Entity) + { + for (i in 0...obj.children.length) + { + var o:Entity = cast obj.children[i]; + + this.drawEntity(o); + } + } public function drawEntity(obj:Entity) { @@ -355,11 +360,8 @@ this.currentBatchSize++; this.setBlendMode(obj.blendMode); } - - - - + var u:Float = obj.clip.x * invTexWidth; var u2:Float = ( obj.clip.x + obj.clip.width) * invTexWidth; var v:Float = ( obj.clip.y + obj.clip.height) * invTexHeight; @@ -389,32 +391,43 @@ var TempX2:Float = obj.clip.width; var TempY2:Float = obj.clip.height; +var r:Float= obj.red; +var g:Float = obj.green; +var b:Float= obj.blue; +var a:Float = obj.alpha; + + +//z +vertices[index+0*9+2] = obj.depth; +vertices[index+1*9+2] = obj.depth; +vertices[index+2*9+2] = obj.depth; +vertices[index+3*9+2] = obj.depth; vertices[index + 0 * 9 + 0] = TempX1; vertices[index + 0 * 9 + 1] = TempY1; -vertices[index+0*9+2] = 0; -vertices[index+0*9+3] = u;vertices[index+0*9+4] = v; -vertices[index+0*9+5] = 1;vertices[index+0*9+6] = 1;vertices[index+0*9+7] = 1;vertices[index+0*9+8] = 1; - vertices[index + 1 * 9 + 0] = TempX1; vertices[index + 1 * 9 + 1] = TempY2; -vertices[index+1*9+2] = 0; -vertices[index+1*9+3] = u;vertices[index+1*9+4] = v2; -vertices[index+1*9+5] = 1;vertices[index+1*9+5] = 1; vertices[index+1*9+7] = 1; vertices[index+1*9+8] = 1; - vertices[index + 2 * 9 + 0] = TempX2; vertices[index + 2 * 9 + 1] = TempX2; -vertices[index+2*9+2] = 0; -vertices[index+2*9+3] = u2;vertices[index+2*9+4] = v2; -vertices[index+2*9+5] = 1; vertices[index+2*9+6] = 1; vertices[index+2*9+7] = 1; vertices[index+2*9+8] = 1; - vertices[index + 3 * 9 + 0] = TempX2; vertices[index + 3 * 9 + 1] = TempY1; -vertices[index+3*9+2] = 0; -vertices[index+3*9+3] = u2;vertices[index+3*9+4] = v; -vertices[index + 3 * 9 + 5] = 1; vertices[index + 3 * 9 + 6] = 1; vertices[index + 3 * 9 + 7] = 1; vertices[index + 3 * 9 + 8] = 1; + + + +vertices[index+0*9+3] = u;vertices[index+0*9+4] =v2; +vertices[index+1*9+3] = u;vertices[index+1*9+4] =v; +vertices[index+2*9+3] =u2;vertices[index+2*9+4] =v; +vertices[index+3*9+3] =u2;vertices[index+3*9+4] =v2; + + + + +vertices[index+0*9+5] = r;vertices[index+0*9+6] = g;vertices[index+0*9+7] = b;vertices[index+0*9+8] = a; +vertices[index+1*9+5] = r;vertices[index+1*9+6] = g;vertices[index+1*9+7] = b;vertices[index+1*9+8] = a; +vertices[index+2*9+5] = r;vertices[index+2*9+6] = g;vertices[index+2*9+7] = b;vertices[index+2*9+8] = a; +vertices[index+3*9+5] = r;vertices[index+3*9+6] = g;vertices[index+3*9+7] = b;vertices[index+3*9+8] = a; var matrix:Matrix = obj.getLocalToWorldMatrix();