├── .gitignore ├── src └── com │ └── genome2d │ ├── tween │ ├── easing │ │ ├── GEase.hx │ │ ├── GLinear.hx │ │ ├── GSine.hx │ │ ├── GQuad.hx │ │ ├── GCubic.hx │ │ ├── GQuart.hx │ │ ├── GQuint.hx │ │ ├── GEaseEnum.hx │ │ ├── GExpo.hx │ │ ├── GBack.hx │ │ ├── GBounce.hx │ │ └── GElastic.hx │ ├── IGInterp.hx │ ├── GTweenTimeline.hx │ └── GTween.hx │ ├── utils │ ├── astar │ │ ├── heuristics │ │ │ ├── IGAStarHeuristic.hx │ │ │ ├── GAStarManhattan.hx │ │ │ └── GAStarDiagonal.hx │ │ ├── IGAStarClient.hx │ │ └── GAStarNode.hx │ ├── GRenderTargetStack.hx │ └── GQuadTree.hx │ ├── fbx │ ├── GFbxMatrixInheritMode.hx │ ├── GFbxParserNode.hx │ ├── GFbxTexture.hx │ ├── GFbxMaterial.hx │ ├── GFbxNode.hx │ ├── GFbxModel.hx │ ├── GFbxTools.hx │ └── GFbxGeometry.hx │ ├── g3d │ ├── G3DMatrixInheritMode.hx │ ├── G3DTexture.hx │ ├── G3DNode.hx │ ├── G3DMaterial.hx │ ├── importers │ │ ├── G3DAbstractImporter.hx │ │ ├── G3DFbxImporter.hx │ │ └── G3DImporter.hx │ ├── G3DFactory.hx │ ├── G3DModel.hx │ └── G3DGeometry.hx │ ├── transitions │ ├── IGTransition.hx │ ├── GTransitionManager.hx │ └── GTransition.hx │ ├── proto │ ├── GPrototypeHelper.hx │ ├── GPrototypeExtras.hx │ ├── GPrototypeSpecs.hx │ ├── IGPrototypable.hx │ ├── GPropertyState.hx │ ├── GPrototypeConstructorLookups.hx │ ├── GPrototypeStates.hx │ ├── GPrototypeFactory.hx │ └── parsers │ │ └── GXmlPrototypeParser.hx │ ├── components │ ├── renderable │ │ ├── IGInteractive.hx │ │ ├── IGRenderable.hx │ │ ├── particles │ │ │ └── GParticleSystemComponent.hx │ │ ├── GSlice3Sprite.hx │ │ ├── GSprite.hx │ │ ├── ui │ │ │ └── GUI.hx │ │ ├── GShape.hx │ │ └── GTiledSprite.hx │ ├── GLevel.hx │ ├── GAnimator.hx │ ├── GScriptComponent.hx │ ├── GComponent.hx │ └── GFrameAnimator.hx │ ├── ui │ ├── GUIAlignType.hx │ ├── skin │ │ ├── GUISkinType.hx │ │ ├── GUISkinSheet.hx │ │ ├── GUISkinManager.hx │ │ ├── GUIShapeSkin.hx │ │ └── GUIParticleSkin.hx │ ├── layout │ │ ├── GUILayoutType.hx │ │ ├── GUILayout.hx │ │ ├── GUIHorizontalLayout.hx │ │ └── GUIVerticalLayout.hx │ └── element │ │ └── GUIInputField.hx │ ├── g3d2 │ ├── G3DBase.hx │ ├── G3DGeometry.hx │ ├── G3DPoly.hx │ ├── G3DVertex.hx │ ├── G3DEdge.hx │ └── G3DRenderGeometry.hx │ ├── animation │ └── GAnimatorController.hx │ ├── node │ ├── IGNodeSorter.hx │ └── GNodePool.hx │ ├── geom │ ├── GIntPoint.hx │ ├── GMatrixUtils.hx │ ├── GVector2.hx │ └── GLine.hx │ ├── text │ ├── GTextureTextAccuracy.hx │ ├── GTextFormat.hx │ ├── GFont.hx │ ├── GTextureChar.hx │ ├── GFontManager.hx │ └── GTextureFont.hx │ ├── postprocess │ ├── GFilterPP.hx │ ├── GBloomPP.hx │ └── GHDRPP.hx │ ├── macros │ ├── MGProfiler.hx │ ├── MGBuild.hx │ ├── MGMouseCallbackBuild.hx │ ├── MGProfilerProcessor.hx │ └── MGDebug.hx │ ├── deprecated │ └── particles │ │ ├── IGInitializerD.hx │ │ ├── IGAffectorD.hx │ │ ├── GParticlePoolD.hx │ │ └── GParticleD.hx │ ├── project │ ├── GProjectConfig.hx │ └── GProject.hx │ ├── particles │ ├── modules │ │ ├── GSPHVelocityModule.hx │ │ ├── GParticleEmitterModule.hx │ │ └── GScriptModule.hx │ ├── GParticlePool.hx │ ├── GParticleGroup.hx │ └── GParticle.hx │ ├── scripts │ └── GScriptManager.hx │ └── globals │ └── GParameters.hx └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | -------------------------------------------------------------------------------- /src/com/genome2d/tween/easing/GEase.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.tween.easing; 2 | 3 | typedef GEase = Float->Float; 4 | -------------------------------------------------------------------------------- /src/com/genome2d/tween/easing/GLinear.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.tween.easing; 2 | 3 | class GLinear 4 | { 5 | inline static public function none(p_t:Float):Float { 6 | return p_t; 7 | } 8 | } -------------------------------------------------------------------------------- /src/com/genome2d/utils/astar/heuristics/IGAStarHeuristic.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.utils.astar.heuristics; 2 | 3 | interface IGAStarHeuristic { 4 | function getCost(p_node1:GAStarNode, p_node2:GAStarNode):Float; 5 | } -------------------------------------------------------------------------------- /src/com/genome2d/fbx/GFbxMatrixInheritMode.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.fbx; 2 | 3 | /** 4 | * @author Peter @sHTiF Stefcek 5 | */ 6 | enum GFbxMatrixInheritMode 7 | { 8 | REPLACE; 9 | IGNORE; 10 | APPEND; 11 | 12 | } -------------------------------------------------------------------------------- /src/com/genome2d/fbx/GFbxParserNode.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.fbx; 2 | 3 | typedef GFbxParserNode = { 4 | var name : String; 5 | var props : Array; 6 | var childs : Array; 7 | } 8 | -------------------------------------------------------------------------------- /src/com/genome2d/g3d/G3DMatrixInheritMode.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.g3d; 2 | 3 | /** 4 | * @author Peter @sHTiF Stefcek 5 | */ 6 | enum G3DMatrixInheritMode 7 | { 8 | 9 | REPLACE; 10 | IGNORE; 11 | APPEND; 12 | 13 | } -------------------------------------------------------------------------------- /src/com/genome2d/transitions/IGTransition.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.transitions; 2 | 3 | /** 4 | * @author Peter @sHTiF Stefcek 5 | */ 6 | 7 | interface IGTransition { 8 | function apply(p_instance:Dynamic, p_property:String, p_value:Dynamic):Void; 9 | } -------------------------------------------------------------------------------- /src/com/genome2d/proto/GPrototypeHelper.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.proto; 2 | 3 | class GPrototypeHelper { 4 | 5 | /** 6 | * This class is generated at runtime by a Genome2D build macro, this file is here so your IDE knows about this class and can import it 7 | */ 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/com/genome2d/components/renderable/IGInteractive.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.components.renderable; 2 | import com.genome2d.input.GMouseInput; 3 | interface IGInteractive { 4 | /** 5 | * Capture mouse input 6 | **/ 7 | function captureMouseInput(p_input:GMouseInput):Void; 8 | } 9 | -------------------------------------------------------------------------------- /src/com/genome2d/ui/GUIAlignType.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.ui; 2 | enum GUIAlignType { 3 | NONE; 4 | TOP_LEFT; 5 | TOP_CENTER; 6 | TOP_RIGHT; 7 | MIDDLE_LEFT; 8 | MIDDLE_CENTER; 9 | MIDDLE_RIGHT; 10 | BOTTOM_LEFT; 11 | BOTTOM_CENTER; 12 | BOTTOM_RIGHT; 13 | } -------------------------------------------------------------------------------- /src/com/genome2d/g3d/G3DTexture.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.g3d; 2 | 3 | class G3DTexture extends G3DNode { 4 | public var relativePath:String; 5 | 6 | public function new(p_id:String, p_relativePath:String):Void { 7 | super(p_id); 8 | 9 | relativePath = p_relativePath; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/com/genome2d/components/GLevel.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.components; 2 | import com.genome2d.globals.GParameters; 3 | class GLevel extends GComponent { 4 | private var g2d_parameters:GParameters; 5 | 6 | override public function init():Void { 7 | g2d_parameters = new GParameters(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/com/genome2d/utils/astar/IGAStarClient.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.utils.astar; 2 | 3 | interface IGAStarClient { 4 | var sizeX(default, never):Int; 5 | 6 | var sizeY(default, never):Int; 7 | 8 | function isWalkable(p_x:Int, p_y:Int, p_walker:Int):Bool; 9 | function getCost(p_x:Int, p_y:Int, p_walker:Int):Int; 10 | } -------------------------------------------------------------------------------- /src/com/genome2d/proto/GPrototypeExtras.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.proto; 2 | 3 | /** 4 | * ... 5 | * @author Peter @sHTiF Stefcek 6 | */ 7 | class GPrototypeExtras 8 | { 9 | //inline static public var SETTER:Int = 1; 10 | inline static public var REFERENCE_GETTER:Int = 2; 11 | inline static public var IGNORE_AUTO_BIND:Int = 4; 12 | } -------------------------------------------------------------------------------- /src/com/genome2d/g3d2/G3DBase.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.g3d2; 2 | 3 | /** 4 | 5 | * @author Peter @sHTiF Stefcek 6 | */ 7 | class G3DBase 8 | { 9 | private var g2d_id:String; 10 | inline public function getId():String { 11 | return g2d_id; 12 | } 13 | 14 | public function new(p_id:String) { 15 | g2d_id = p_id; 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /src/com/genome2d/g3d/G3DNode.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.g3d; 2 | 3 | class G3DNode { 4 | public var id:String; 5 | public var name:String; 6 | 7 | public var connections:Map; 8 | 9 | public function new(p_id:String) { 10 | id = p_id; 11 | name = ""; 12 | 13 | connections = new Map(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/com/genome2d/g3d2/G3DGeometry.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.g3d2; 2 | import com.genome2d.g3d2.G3DBase; 3 | 4 | /** 5 | * @author Peter @sHTiF Stefcek 6 | */ 7 | class G3DGeometry extends G3DBase 8 | { 9 | private var g2d_polys:Array; 10 | 11 | public function new(p_id:String, p_polys:Array) { 12 | super(p_id); 13 | g2d_polys = p_polys; 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /src/com/genome2d/animation/GAnimatorController.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2014 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | 10 | package com.genome2d.animation; 11 | 12 | class GAnimatorController 13 | { 14 | 15 | } -------------------------------------------------------------------------------- /src/com/genome2d/components/GAnimator.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2014 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | 10 | package com.genome2d.components; 11 | 12 | class GAnimator extends GComponent 13 | { 14 | 15 | } -------------------------------------------------------------------------------- /src/com/genome2d/ui/skin/GUISkinType.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2015 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.ui.skin; 10 | 11 | enum GUISkinType { 12 | TEXTURE; 13 | TEXT; 14 | } 15 | -------------------------------------------------------------------------------- /src/com/genome2d/g3d2/G3DPoly.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.g3d2; 2 | import com.genome2d.g3d2.G3DBase; 3 | import com.genome2d.g3d2.G3DEdge; 4 | 5 | /** 6 | * ... 7 | * @author ... 8 | */ 9 | class G3DPoly extends G3DBase 10 | { 11 | private var g2d_edges:Array; 12 | 13 | public function new(p_id:String, p_edges:Array) { 14 | super(p_id); 15 | g2d_edges = p_edges; 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /src/com/genome2d/g3d2/G3DVertex.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.g3d2; 2 | 3 | /** 4 | * @author Peter @sHTiF Stefcek 5 | */ 6 | class G3DVertex extends G3DBase 7 | { 8 | public var x:Float; 9 | public var y:Float; 10 | public var z:Float; 11 | 12 | public function new(p_id:String, p_x:Float, p_y:Float, p_z:Float) { 13 | super(p_id); 14 | 15 | x = p_x; 16 | y = p_y; 17 | z = p_z; 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /src/com/genome2d/node/IGNodeSorter.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2014 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.node; 10 | 11 | interface IGNodeSorter 12 | { 13 | function getSortValue(p_node:GNode):Float; 14 | } -------------------------------------------------------------------------------- /src/com/genome2d/g3d/G3DMaterial.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.g3d; 2 | 3 | class G3DMaterial extends G3DNode { 4 | 5 | public function getTexture():G3DTexture { 6 | for (connection in connections) { 7 | if (Std.is(connection, G3DTexture)) return cast connection; 8 | } 9 | 10 | return null; 11 | } 12 | 13 | public function new(p_id:String):Void { 14 | super(p_id); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/com/genome2d/utils/astar/heuristics/GAStarManhattan.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.utils.astar.heuristics; 2 | 3 | class GAStarManhattan implements IGAStarHeuristic 4 | { 5 | public function new() { 6 | } 7 | 8 | public function getCost(p_node1:GAStarNode, p_node2:GAStarNode):Float { 9 | var dx:Int = p_node1.x - p_node2.x; 10 | var dy:Int = p_node1.y - p_node2.y; 11 | 12 | return (dx > 0 ? dx : -dx) + (dy > 0 ? dy : -dy); 13 | } 14 | } -------------------------------------------------------------------------------- /src/com/genome2d/ui/layout/GUILayoutType.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2015 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.ui.layout; 10 | 11 | enum GUILayoutType { 12 | VERTICAL; 13 | HORIZONTAL; 14 | GRID_VERTICAL; 15 | GRID_HORIZONTAL; 16 | } 17 | -------------------------------------------------------------------------------- /src/com/genome2d/fbx/GFbxTexture.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.fbx; 2 | 3 | import com.genome2d.fbx.GFbxTools; 4 | import com.genome2d.fbx.GFbxParserNode; 5 | 6 | class GFbxTexture extends GFbxNode { 7 | public var relativePath:String; 8 | 9 | public function new(p_fbxNode:GFbxParserNode):Void { 10 | super(p_fbxNode); 11 | 12 | relativePath = GFbxTools.toString(GFbxTools.get(p_fbxNode, "RelativeFilename", true).props[0]); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/com/genome2d/geom/GIntPoint.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.geom; 2 | import com.genome2d.proto.IGPrototypable; 3 | class GIntPoint implements IGPrototypable { 4 | public var x:Int = 0; 5 | public var y:Int = 0; 6 | 7 | public function new(p_x:Int = 0, p_y:Int = 0) { 8 | x = p_x; 9 | y = p_y; 10 | } 11 | 12 | public function equals(p_point:GIntPoint):Bool { 13 | return x == p_point.x && y == p_point.y; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/com/genome2d/text/GTextureTextAccuracy.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2014 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.text; 10 | 11 | /** 12 | Texture filtering types 13 | **/ 14 | enum GTextureTextAccuracy 15 | { 16 | OFF; 17 | FLOOR; 18 | ROUND; 19 | CEIL; 20 | } -------------------------------------------------------------------------------- /src/com/genome2d/tween/easing/GSine.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.tween.easing; 2 | 3 | 4 | class GSine { 5 | 6 | inline static public function easeIn(p_t:Float):Float { 7 | return -Math.cos(p_t * (Math.PI / 2)); 8 | } 9 | 10 | inline static public function easeOut(p_t:Float):Float { 11 | return Math.sin(p_t * (Math.PI / 2)); 12 | } 13 | 14 | inline static public function easeInOut(p_t:Float):Float { 15 | return -0.5 * (Math.cos(Math.PI * p_t) - 1); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /src/com/genome2d/utils/astar/GAStarNode.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.utils.astar; 2 | 3 | import com.genome2d.geom.GIntPoint; 4 | 5 | class GAStarNode extends GIntPoint { 6 | public var parent:GAStarNode; 7 | 8 | public var walkable:Bool; 9 | 10 | public var inClosed:Bool = false; 11 | public var inOpen:Bool = false; 12 | 13 | public var f:Float; 14 | public var g:Float; 15 | 16 | inline public function toPoint():GIntPoint { 17 | return new GIntPoint(x, y); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/genome2d/fbx/GFbxMaterial.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.fbx; 2 | 3 | import com.genome2d.fbx.GFbxParserNode; 4 | 5 | class GFbxMaterial extends GFbxNode { 6 | 7 | public function getTexture():GFbxTexture { 8 | for (connection in connections) { 9 | if (Std.is(connection, GFbxTexture)) return cast connection; 10 | } 11 | 12 | return null; 13 | } 14 | 15 | public function new(p_fbxNode:GFbxParserNode):Void { 16 | super(p_fbxNode); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/com/genome2d/tween/easing/GQuad.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.tween.easing; 2 | 3 | class GQuad { 4 | 5 | inline static public function easeIn(p_t:Float):Float { 6 | return p_t * p_t; 7 | } 8 | 9 | inline static public function easeOut(p_t:Float):Float { 10 | return -p_t * (p_t - 2); 11 | } 12 | 13 | inline static public function easeInOut(p_t:Float):Float { 14 | p_t *= 2; 15 | if (p_t < 1) { 16 | return .5 * p_t * p_t; 17 | } 18 | return -.5 * ((p_t - 1) * (p_t - 3) - 1); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/com/genome2d/g3d2/G3DEdge.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.g3d2; 2 | import com.genome2d.g3d2.G3DBase; 3 | import com.genome2d.g3d2.G3DVertex; 4 | 5 | /** 6 | * ... 7 | * @author Peter @sHTiF Stefcek 8 | */ 9 | class G3DEdge extends G3DBase 10 | { 11 | private var g2d_vertex1:G3DVertex; 12 | private var g2d_vertex2:G3DVertex; 13 | 14 | public function new(p_id:String, p_vertex1:G3DVertex, p_vertex2:G3DVertex) { 15 | super(p_id); 16 | 17 | g2d_vertex1 = p_vertex1; 18 | g2d_vertex2 = p_vertex2; 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /src/com/genome2d/tween/easing/GCubic.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.tween.easing; 2 | 3 | class GCubic { 4 | 5 | 6 | inline static public function easeIn(p_t:Float):Float { 7 | return p_t * p_t * p_t; 8 | } 9 | inline static public function easeOut(p_t:Float):Float { 10 | return ((p_t -= 1) * p_t * p_t + 1); 11 | } 12 | inline static public function easeInOut(p_t:Float):Float { 13 | if ((p_t *= 2) < 1) { 14 | return 0.5 * p_t * p_t * p_t; 15 | }else { 16 | return 0.5 * ((p_t -= 2) * p_t * p_t + 2); 17 | } 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /src/com/genome2d/g3d/importers/G3DAbstractImporter.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.g3d.importers; 2 | 3 | import com.genome2d.g3d.G3DScene; 4 | import haxe.io.Bytes; 5 | 6 | /** 7 | * @author Peter @sHTiF Stefcek 8 | */ 9 | class G3DAbstractImporter 10 | { 11 | 12 | public function new() 13 | { 14 | 15 | } 16 | 17 | @:access(com.genome2d.g3d.G3DScene) 18 | public function importScene(p_data:Bytes):G3DScene { 19 | return null; 20 | } 21 | 22 | public function exportScene(p_scene:G3DScene, p_data:Bytes):Void { 23 | 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /src/com/genome2d/fbx/GFbxNode.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.fbx; 2 | import com.genome2d.fbx.GFbxTools; 3 | import com.genome2d.fbx.GFbxParserNode; 4 | 5 | class GFbxNode { 6 | public var id:String; 7 | public var name:String; 8 | 9 | public var connections:Map; 10 | 11 | public function new(p_fbxNode:GFbxParserNode) { 12 | id = Std.string(GFbxTools.toFloat(p_fbxNode.props[0])); 13 | name = GFbxTools.toString(p_fbxNode.props[1]); 14 | 15 | connections = new Map(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/com/genome2d/utils/astar/heuristics/GAStarDiagonal.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.utils.astar.heuristics; 2 | 3 | class GAStarDiagonal implements IGAStarHeuristic 4 | { 5 | public function new() { 6 | } 7 | 8 | public function getCost(p_node1:GAStarNode, p_node2:GAStarNode):Float { 9 | var dx = Math.abs(p_node1.x - p_node2.x); 10 | var dy = Math.abs(p_node1.y - p_node2.y); 11 | 12 | var diag = Math.min(dx, dy); 13 | var straight = dx + dy; 14 | 15 | return GAStar.ADJANCED_COST * (straight - 2 * diag) + GAStar.DIAGONAL_COST * diag; 16 | } 17 | } -------------------------------------------------------------------------------- /src/com/genome2d/tween/IGInterp.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.tween; 2 | 3 | import com.genome2d.tween.easing.GEase; 4 | 5 | @:allow(com.genome2d.tween.GTweenStep) 6 | interface IGInterp { 7 | 8 | public var duration:Float; 9 | public var complete:Bool; 10 | public var property:String; 11 | public var ease:GEase; 12 | public var from:Float; 13 | 14 | public function update(p_delta:Float):Void; 15 | public function setValue(p_value:Float):Void; 16 | public function getFinalValue():Dynamic; 17 | public function reset():Void; 18 | } 19 | -------------------------------------------------------------------------------- /src/com/genome2d/tween/easing/GQuart.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.tween.easing; 2 | 3 | 4 | class GQuart { 5 | 6 | inline static public function easeIn(p_t:Float):Float { 7 | return p_t * p_t * p_t * p_t; 8 | } 9 | 10 | inline static public function easeOut(p_t:Float):Float { 11 | return -((p_t -= 1) * p_t * p_t * p_t - 1); 12 | } 13 | 14 | inline static public function easeInOut(p_t:Float):Float { 15 | p_t *= 2; 16 | if (p_t < 1) { 17 | return .5 * p_t * p_t * p_t * p_t; 18 | } 19 | return -.5 * ((p_t -= 2) * p_t * p_t * p_t - 2); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/com/genome2d/postprocess/GFilterPP.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2014 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.postprocess; 10 | 11 | import com.genome2d.context.filters.GFilter; 12 | 13 | class GFilterPP extends GPostProcess 14 | { 15 | public function new(p_filters:Array) { 16 | super(p_filters.length); 17 | 18 | g2d_passFilters = p_filters; 19 | } 20 | } -------------------------------------------------------------------------------- /src/com/genome2d/tween/easing/GQuint.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.tween.easing; 2 | 3 | 4 | class GQuint { 5 | 6 | inline static public function easeIn(p_t:Float):Float { 7 | return p_t * p_t * p_t * p_t * p_t; 8 | } 9 | 10 | inline static public function easeOut(p_t:Float):Float { 11 | return ((p_t -= 1) * p_t * p_t * p_t * p_t + 1); 12 | } 13 | 14 | inline static public function easeInOut(p_t:Float):Float { 15 | p_t *= 2; 16 | if (p_t < 1) { 17 | return .5 * p_t * p_t * p_t * p_t * p_t; 18 | } 19 | return .5 * ((p_t -= 2) * p_t * p_t * p_t * p_t + 2); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/com/genome2d/tween/easing/GEaseEnum.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.tween.easing; 2 | 3 | enum GEaseEnum { 4 | LINEAR; 5 | BACK_IN; 6 | BACK_OUT; 7 | BACK_IN_OUT; 8 | BOUNCE_IN; 9 | BOUNCE_OUT; 10 | BOUNCE_IN_OUT; 11 | CUBIC_IN; 12 | CUBIC_OUT; 13 | CUBIC_IN_OUT; 14 | EXPO_IN; 15 | EXPO_OUT; 16 | EXPO_IN_OUT; 17 | QUART_IN; 18 | QUART_OUT; 19 | QUART_IN_OUT; 20 | QUINT_IN; 21 | QUINT_OUT; 22 | QUINT_IN_OUT; 23 | SINE_IN; 24 | SINE_OUT; 25 | SINE_IN_OUT; 26 | QUAD_IN; 27 | QUAD_OUT; 28 | QUAD_IN_OUT; 29 | } -------------------------------------------------------------------------------- /src/com/genome2d/tween/easing/GExpo.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.tween.easing; 2 | 3 | class GExpo { 4 | 5 | inline static public function easeIn(p_t:Float):Float { 6 | return p_t == 0 ? 0 : Math.pow(2, 10 * (p_t - 1)); 7 | } 8 | 9 | inline static public function easeOut(p_t:Float):Float { 10 | return p_t == 1 ? 1 : (1 - Math.pow(2, -10 * p_t)); 11 | } 12 | 13 | inline static public function easeInOut(p_t:Float):Float { 14 | if (p_t == 0 || p_t == 1) return p_t; 15 | 16 | if ((p_t *= 2.0) < 1.0) { 17 | return 0.5 * Math.pow(2, 10 * (p_t - 1)); 18 | } 19 | return 0.5 * (2 - Math.pow(2, -10 * --p_t)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/com/genome2d/tween/easing/GBack.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.tween.easing; 2 | 3 | class GBack { 4 | 5 | public static var DRIVE:Float = 1.70158; 6 | inline static public function easeIn(p_t:Float):Float { 7 | return p_t * p_t * ((DRIVE + 1) * p_t - DRIVE); 8 | } 9 | inline static public function easeOut(p_t:Float):Float { 10 | return ((p_t -= 1) * p_t * ((DRIVE + 1) * p_t + DRIVE) + 1); 11 | } 12 | inline static public function easeInOut(p_t:Float):Float { 13 | var s = DRIVE * 1.525; 14 | if ((p_t*=2) < 1) return 0.5 * (p_t * p_t * (((s) + 1) * p_t - s)); 15 | return 0.5 * ((p_t -= 2) * p_t * (((s) + 1) * p_t + s) + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /src/com/genome2d/text/GTextFormat.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.text; 2 | 3 | /** 4 | * ... 5 | * @author Peter @sHTiF Stefcek 6 | */ 7 | class GTextFormat 8 | { 9 | public var g2d_formatMap:Map; 10 | 11 | public function new() { 12 | g2d_formatMap = new Map(); 13 | } 14 | 15 | public function setIndexColor(p_index:Int, p_color:Int):Void { 16 | g2d_formatMap.set(p_index, p_color); 17 | } 18 | 19 | public function getIndexColor(p_index:Int):Int { 20 | var color:Int = -2; 21 | if (g2d_formatMap.exists(p_index)) { 22 | color = g2d_formatMap.get(p_index); 23 | } 24 | 25 | return color; 26 | } 27 | 28 | public function hasIndexColor(p_index:Int):Bool { 29 | return g2d_formatMap.exists(p_index); 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /src/com/genome2d/macros/MGProfiler.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.macros; 2 | 3 | #if macro 4 | import haxe.PosInfos; 5 | 6 | class MGProfiler { 7 | macro static public function PROFILE(expr) { 8 | return macro { 9 | var g2d_profileTime:Int = untyped __global__["flash.utils.getTimer"](); 10 | ${expr}; 11 | g2d_profileTime = untyped __global__["flash.utils.getTimer"]() - g2d_profileTime; 12 | @:pos(expr.pos) MGProfiler.PROFILE_INTERNAL(g2d_profileTime); 13 | } 14 | } 15 | 16 | static public function PROFILE_INTERNAL(p_time:Int, ?pos:PosInfos) { 17 | com.genome2d.debug.GDebug.trace("PROFILE BLOCK ["+pos.className+":"+pos.methodName+"] END Elapsed: "+p_time+"ms"); 18 | } 19 | } 20 | #end -------------------------------------------------------------------------------- /src/com/genome2d/deprecated/particles/IGInitializerD.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2014 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.deprecated.particles; 10 | 11 | import com.genome2d.deprecated.components.renderable.particles.GParticleSystemD; 12 | import com.genome2d.deprecated.particles.GParticleD; 13 | 14 | /** 15 | Interface providing method for `GParticleSystem` particles initialization 16 | **/ 17 | interface IGInitializerD { 18 | 19 | /** 20 | Initialize `p_particle` inside `p_system` 21 | **/ 22 | function initialize(p_system:GParticleSystemD, p_particle:GParticleD):Void; 23 | } -------------------------------------------------------------------------------- /src/com/genome2d/deprecated/particles/IGAffectorD.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2014 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.deprecated.particles; 10 | 11 | import com.genome2d.deprecated.components.renderable.particles.GParticleSystemD; 12 | import com.genome2d.deprecated.particles.GParticleD; 13 | 14 | /** 15 | Interface providing method for `GParticleSystem` particles update 16 | **/ 17 | interface IGAffectorD { 18 | 19 | /** 20 | Update `p_particle` inside `p_system` by `p_deltaTime` 21 | **/ 22 | function update(p_system:GParticleSystemD, p_particle:GParticleD, p_deltaTime:Float):Void; 23 | } -------------------------------------------------------------------------------- /src/com/genome2d/proto/GPrototypeSpecs.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.proto; 2 | 3 | /** 4 | * ... 5 | * @author Peter @sHTiF Stefcek 6 | */ 7 | class GPrototypeSpecs 8 | { 9 | #if genome_editor 10 | inline static public var PROTOTYPE_EDITOR:String = "PROTOTYPE_EDITOR"; 11 | #end 12 | 13 | inline static public var PROTOTYPE_NAME:String = "PROTOTYPE_NAME"; 14 | inline static public var PROTOTYPE_PROPERTY_NAMES:String = "PROTOTYPE_PROPERTY_NAMES"; 15 | inline static public var PROTOTYPE_PROPERTY_TYPES:String = "PROTOTYPE_PROPERTY_TYPES"; 16 | inline static public var PROTOTYPE_PROPERTY_EXTRAS:String = "PROTOTYPE_PROPERTY_EXTRAS"; 17 | inline static public var PROTOTYPE_PROPERTY_DEFAULTS:String = "PROTOTYPE_PROPERTY_DEFAULTS"; 18 | inline static public var PROTOTYPE_DEFAULT_CHILD_GROUP:String = "PROTOTYPE_DEFAULT_CHILD_GROUP"; 19 | } -------------------------------------------------------------------------------- /src/com/genome2d/proto/IGPrototypable.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2014 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.proto; 10 | 11 | /** 12 | Prototypable interface 13 | **/ 14 | @:autoBuild(com.genome2d.macros.MGPrototypeProcessor.build()) 15 | interface IGPrototypable { 16 | public var g2d_prototypeStates:GPrototypeStates; 17 | public var g2d_currentState:String; 18 | 19 | public function getPrototype(p_prototype:GPrototype = null):GPrototype; 20 | public function bindPrototype(p_prototype:GPrototype):Void; 21 | public function toReference():String; 22 | public function setPrototypeState(p_stateName:String):Void; 23 | } 24 | -------------------------------------------------------------------------------- /src/com/genome2d/tween/easing/GBounce.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.tween.easing; 2 | 3 | class GBounce { 4 | 5 | inline static public function easeIn(p_t:Float):Float { 6 | return -easeOut(1 - p_t); 7 | } 8 | inline static public function easeOut(p_t:Float):Float { 9 | if (p_t < (1 / 2.75)) { 10 | return (7.5625 * p_t * p_t); 11 | } else if (p_t < (2 / 2.75)) { 12 | return (7.5625 * (p_t -= (1.5 / 2.75)) * p_t + .75); 13 | } else if (p_t < (2.5 / 2.75)) { 14 | return (7.5625 * (p_t -= (2.25 / 2.75)) * p_t + .9375); 15 | } else { 16 | return (7.5625 * (p_t -= (2.625 / 2.75)) * p_t + .984375); 17 | } 18 | } 19 | inline static public function easeInOut(p_t:Float):Float { 20 | if (p_t < 0.5) { 21 | return easeIn(p_t * 2) * .5; 22 | } else { 23 | return easeOut(p_t *2 - 1) * .5 + .5; 24 | } 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /src/com/genome2d/transitions/GTransitionManager.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.transitions; 2 | 3 | class GTransitionManager { 4 | static public function init():Void { 5 | g2d_references = new Map(); 6 | } 7 | 8 | static private var g2d_references:Map; 9 | static public function getTransition(p_id:String):IGTransition { 10 | return g2d_references.get(p_id); 11 | } 12 | 13 | static public function g2d_addTransition(p_id:String, p_value:IGTransition):Void { 14 | g2d_references.set(p_id,p_value); 15 | } 16 | 17 | static public function g2d_removeTransition(p_id:String):Void { 18 | g2d_references.remove(p_id); 19 | } 20 | 21 | static public function getAllTransitions():Map { 22 | return g2d_references; 23 | } 24 | } -------------------------------------------------------------------------------- /src/com/genome2d/geom/GMatrixUtils.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2014 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.geom; 10 | 11 | class GMatrixUtils { 12 | inline static public function prependMatrix(p_matrix:GMatrix, p_by:GMatrix):Void { 13 | p_matrix.setTo(p_matrix.a * p_by.a + p_matrix.c * p_by.b, 14 | p_matrix.b * p_by.a + p_matrix.d * p_by.b, 15 | p_matrix.a * p_by.c + p_matrix.c * p_by.d, 16 | p_matrix.b * p_by.c + p_matrix.d * p_by.d, 17 | p_matrix.tx + p_matrix.a * p_by.tx + p_matrix.c * p_by.ty, 18 | p_matrix.ty + p_matrix.b * p_by.tx + p_matrix.d * p_by.ty); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/com/genome2d/project/GProjectConfig.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.project; 2 | import com.genome2d.geom.GRectangle; 3 | import com.genome2d.context.GContextConfig; 4 | import com.genome2d.debug.GDebug; 5 | class GProjectConfig { 6 | public var initGenome:Bool = true; 7 | 8 | public var contextConfig:GContextConfig; 9 | 10 | public function new(p_contextConfig:GContextConfig = null) { 11 | #if (!swc && !js && !cs) 12 | contextConfig = p_contextConfig == null ? new GContextConfig() : p_contextConfig; 13 | #end 14 | 15 | #if js 16 | contextConfig = p_contextConfig == null ? new GContextConfig(null) : p_contextConfig; 17 | #end 18 | 19 | #if cs 20 | if (p_contextConfig == null) { 21 | GDebug.error("Need valid context config for cs target."); 22 | } 23 | 24 | contextConfig = p_contextConfig; 25 | #end 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/com/genome2d/utils/GRenderTargetStack.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.utils; 2 | import com.genome2d.context.IGContext; 3 | import com.genome2d.geom.GMatrix3D; 4 | import com.genome2d.textures.GTexture; 5 | class GRenderTargetStack { 6 | static private var g2d_stack:Array; 7 | static private var g2d_transforms:Array; 8 | 9 | static public function pushRenderTarget(p_target:GTexture, p_transform:GMatrix3D):Void { 10 | if (g2d_stack == null) { 11 | g2d_stack = new Array(); 12 | g2d_transforms = new Array(); 13 | } 14 | g2d_stack.push(p_target); 15 | g2d_transforms.push(p_transform); 16 | } 17 | 18 | static public function popRenderTarget(p_context:IGContext):Void { 19 | if (g2d_stack != null) { 20 | p_context.setRenderTarget(g2d_stack.pop(), g2d_transforms.pop(), false); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/com/genome2d/text/GFont.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.text; 2 | import com.genome2d.proto.IGPrototypable; 3 | 4 | @:access(com.genome2d.text.GFontManager) 5 | class GFont implements IGPrototypable { 6 | private var g2d_id:String; 7 | /** 8 | * Id 9 | */ 10 | @prototype 11 | #if swc @:extern #end 12 | public var id(get,set):String; 13 | #if swc @:getter(id) #end 14 | inline private function get_id():String { 15 | return g2d_id; 16 | } 17 | #if swc @:setter(id) #end 18 | inline private function set_id(p_value:String):String { 19 | if (p_value != g2d_id) { 20 | GFontManager.g2d_removeFont(cast this); 21 | g2d_id = p_value; 22 | GFontManager.g2d_addFont(cast this); 23 | } 24 | return g2d_id; 25 | } 26 | 27 | public function dispose():Void { 28 | GFontManager.g2d_removeFont(cast this); 29 | } 30 | 31 | /* 32 | * Get a reference value 33 | */ 34 | public function toReference():String { 35 | return "@"+id; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/com/genome2d/components/renderable/IGRenderable.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2014 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.components.renderable; 10 | 11 | import com.genome2d.geom.GRectangle; 12 | import com.genome2d.context.GCamera; 13 | 14 | /** 15 | Interfaces implemented by all renderable components 16 | 17 | Every `GNode` can have a single `IRenderable` components at any given time 18 | **/ 19 | interface IGRenderable extends IGInteractive { 20 | 21 | /** 22 | * Render the components 23 | **/ 24 | function render(p_camera:GCamera, p_useMatrix:Bool):Void; 25 | 26 | /** 27 | * Get local bounds of the renderable components 28 | **/ 29 | function getBounds(p_target:GRectangle = null):GRectangle; 30 | 31 | /** 32 | * Check for hit test in local space 33 | **/ 34 | function hitTest(p_x:Float, p_y:Float):Bool; 35 | } 36 | -------------------------------------------------------------------------------- /src/com/genome2d/proto/GPropertyState.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.proto; 2 | 3 | import com.genome2d.transitions.GTransitionManager; 4 | import com.genome2d.transitions.IGTransition; 5 | 6 | /** 7 | * ... 8 | * @author Peter @sHTiF Stefcek 9 | */ 10 | class GPropertyState 11 | { 12 | private var g2d_name:String; 13 | private var g2d_value:Dynamic; 14 | private var g2d_transition:String; 15 | private var g2d_extras:Int; 16 | 17 | public function new(p_name:String, p_value:Dynamic, p_extras:Int, p_transition:String) { 18 | g2d_name = p_name; 19 | g2d_value = p_value; 20 | g2d_extras = p_extras; 21 | g2d_transition = p_transition; 22 | } 23 | 24 | public function bind(p_instance:Dynamic):Void { 25 | if (g2d_transition != "") { 26 | var transition:IGTransition = GTransitionManager.getTransition(g2d_transition); 27 | if (transition != null) { 28 | transition.apply(p_instance, g2d_name, g2d_value); 29 | } else { 30 | Reflect.setProperty(p_instance, g2d_name, g2d_value); 31 | } 32 | } else { 33 | Reflect.setProperty(p_instance, g2d_name, g2d_value); 34 | } 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /src/com/genome2d/proto/GPrototypeConstructorLookups.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.proto; 2 | 3 | class GPrototypeConstructorLookups { 4 | static private var _arguments:Map>; 5 | 6 | static public function getArguments(p_prototypeName:String):Array { 7 | var args:Array = _arguments.get(p_prototypeName); 8 | return args == null ? [] : args; 9 | } 10 | 11 | static public function initialize():Void { 12 | _arguments = new Map>(); 13 | _arguments.set("textureSkin", ["", null, true, null]); 14 | _arguments.set("fontSkin", ["", null, 1, true, null]); 15 | _arguments.set("element", [null]); 16 | _arguments.set("particle_emitter", [null]); 17 | _arguments.set("GCurve", [0.0]); 18 | _arguments.set("GIntPoint", [0,0]); 19 | _arguments.set("GPostProcess", [1, null]); 20 | _arguments.set("transition", ["", 0, null, 0]); 21 | _arguments.set("GCurveInterp", [null]); 22 | _arguments.set("tweenFloat", [null]); 23 | _arguments.set("node", [""]); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/com/genome2d/particles/modules/GSPHVelocityModule.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.particles.modules; 2 | 3 | import com.genome2d.macros.MGDebug; 4 | import com.genome2d.particles.GParticleEmitter; 5 | import com.genome2d.particles.GParticle; 6 | 7 | /** 8 | * Update particle velocity based on SPH properties 9 | * 10 | * @author Peter @sHTiF Stefcek 11 | */ 12 | class GSPHVelocityModule extends GParticleEmitterModule 13 | { 14 | public function new() { 15 | super(); 16 | 17 | updateParticleModule = true; 18 | } 19 | 20 | override public function updateParticle(p_emitter:GParticleEmitter, p_particle:GParticle, p_deltaTime:Float):Void { 21 | if (p_particle.density > 0 && !p_particle.fixed && p_particle.group == null) { 22 | p_particle.velocityX += p_particle.fluidX / (p_particle.density * 0.9 + 0.1); 23 | p_particle.velocityY += p_particle.fluidY / (p_particle.density * 0.9 + 0.1); 24 | } 25 | 26 | /* 27 | p_particle.velocityY += .2; 28 | if (!p_particle.fixed) { 29 | p_particle.x += p_particle.velocityX * p_deltaTime/30; 30 | p_particle.y += p_particle.velocityY * p_deltaTime / 30; 31 | } 32 | p_particle.accumulatedTime += p_deltaTime; 33 | 34 | if (p_particle.accumulatedTime > 5000) p_particle.die = true; 35 | /* 36 | */ 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /src/com/genome2d/particles/modules/GParticleEmitterModule.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2014 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.particles.modules; 10 | import com.genome2d.proto.IGPrototypable; 11 | 12 | /** 13 | * Particle emitter module abstract 14 | */ 15 | class GParticleEmitterModule implements IGPrototypable 16 | { 17 | @prototype 18 | public var spawnParticleModule:Bool = false; 19 | 20 | @prototype 21 | public var updateParticleModule:Bool = false; 22 | 23 | @prototype 24 | public var updateEmitterModule:Bool = false; 25 | 26 | @prototype 27 | public var enabled:Bool = true; 28 | 29 | public function new() {} 30 | 31 | public function spawnParticle(p_emitter:GParticleEmitter, p_particle:GParticle):Void {} 32 | 33 | public function updateParticle(p_emitter:GParticleEmitter, p_particle:GParticle, p_deltaTime:Float):Void {} 34 | 35 | public function updateEmitter(p_emitter:GParticleEmitter, p_deltaTime:Float):Void {} 36 | 37 | public function addedToEmitter(p_emitter:GParticleEmitter):Void {} 38 | 39 | public function removedFromEmitter(p_emitter:GParticleEmitter):Void {} 40 | } -------------------------------------------------------------------------------- /src/com/genome2d/fbx/GFbxModel.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.fbx; 2 | 3 | import com.genome2d.fbx.GFbxMatrixInheritMode; 4 | import com.genome2d.context.renderers.G3DRenderer; 5 | import com.genome2d.geom.GMatrix3D; 6 | 7 | class GFbxModel extends GFbxNode { 8 | public var visible:Bool = true; 9 | 10 | public var renderer:G3DRenderer; 11 | 12 | public var inheritSceneMatrixMode:GFbxMatrixInheritMode; 13 | public var modelMatrix:GMatrix3D; 14 | 15 | public function new(p_fbxNode:GFbxParserNode):Void { 16 | super(p_fbxNode); 17 | 18 | inheritSceneMatrixMode = GFbxMatrixInheritMode.REPLACE; 19 | modelMatrix = new GMatrix3D(); 20 | } 21 | 22 | public function getGeometry():GFbxGeometry { 23 | for (connection in connections) { 24 | if (Std.is(connection, GFbxGeometry)) return cast connection; 25 | if (Std.is(connection, GFbxModel)) return cast(connection,GFbxModel).getGeometry(); 26 | } 27 | return null; 28 | } 29 | 30 | public function getMaterial():GFbxMaterial { 31 | for (connection in connections) { 32 | if (Std.is(connection, GFbxMaterial)) return cast connection; 33 | if (Std.is(connection, GFbxModel)) return cast(connection,GFbxModel).getMaterial(); 34 | } 35 | return null; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/com/genome2d/ui/skin/GUISkinSheet.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2015 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.ui.skin; 10 | import com.genome2d.proto.GPrototype; 11 | import com.genome2d.proto.GPrototypeFactory; 12 | import com.genome2d.proto.IGPrototypable; 13 | 14 | /** 15 | * @author Peter @sHTiF Stefcek 16 | */ 17 | @prototypeName("skinSheet") 18 | @prototypeDefaultChildGroup("*") 19 | class GUISkinSheet implements IGPrototypable 20 | { 21 | private var g2d_skins:Array; 22 | 23 | public function new() { 24 | g2d_skins = new Array(); 25 | } 26 | 27 | public function getPrototype(p_prototype:GPrototype = null):GPrototype { 28 | p_prototype = getPrototypeDefault(p_prototype); 29 | 30 | for (skin in g2d_skins) { 31 | p_prototype.addChild(skin.getPrototype(), "*"); 32 | } 33 | 34 | return p_prototype; 35 | } 36 | 37 | public function bindPrototype(p_prototype:GPrototype):Void { 38 | bindPrototypeDefault(p_prototype); 39 | var skinPrototypes:Array = p_prototype.getGroup("*"); 40 | 41 | for (skinPrototype in skinPrototypes) { 42 | var skin:GUISkin = cast GPrototypeFactory.createInstance(skinPrototype); 43 | g2d_skins.push(skin); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /src/com/genome2d/proto/GPrototypeStates.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.proto; 2 | 3 | /** 4 | * ... 5 | * @author Peter @sHTiF Stefcek 6 | */ 7 | class GPrototypeStates 8 | { 9 | private var g2d_states:Map>; 10 | 11 | #if !cs inline #end public function new() { 12 | g2d_states = new Map>(); 13 | } 14 | 15 | #if !cs inline #end public function setProperty(p_property:String, p_value:Dynamic, p_extras:Int, p_stateName:String, p_transition:String):Void { 16 | if (p_stateName == null) p_stateName = "default"; 17 | 18 | var split:Array = p_stateName.split("-"); 19 | 20 | if (split.length > 1) { 21 | for (i in 0...split.length) { 22 | setProperty(p_property, p_value, p_extras, split[i], p_transition); 23 | } 24 | } else { 25 | var state:Map = g2d_states.get(p_stateName); 26 | if (state == null) { 27 | state = new Map(); 28 | g2d_states.set(p_stateName, state); 29 | } 30 | state.set(p_property, new GPropertyState(p_property, p_value, p_extras, p_transition)); 31 | } 32 | } 33 | 34 | #if !cs inline #end public function getState(p_stateName:String = "default"):Map { 35 | return g2d_states.get(p_stateName); 36 | } 37 | 38 | #if !cs inline #end public function hasState(p_stateName:String):Bool { 39 | return g2d_states.exists(p_stateName); 40 | } 41 | } -------------------------------------------------------------------------------- /src/com/genome2d/ui/layout/GUILayout.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2015 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.ui.layout; 10 | 11 | import com.genome2d.ui.element.GUIElement; 12 | import com.genome2d.proto.IGPrototypable; 13 | 14 | @:access(com.genome2d.ui.element.GUIElement) 15 | @prototypeName("layout") 16 | class GUILayout implements IGPrototypable { 17 | @prototype public var type:GUILayoutType = GUILayoutType.HORIZONTAL; 18 | 19 | private function isCalculatingWidth():Bool { 20 | return true; 21 | } 22 | 23 | private function calculateWidth(p_element:GUIElement):Void { 24 | } 25 | 26 | private function invalidateWidth(p_element:GUIElement):Void { 27 | } 28 | 29 | private function isCalculatingHeight():Bool { 30 | return true; 31 | } 32 | 33 | private function calculateHeight(p_element:GUIElement):Void { 34 | } 35 | 36 | private function invalidateHeight(p_element:GUIElement):Void { 37 | } 38 | 39 | public function isHorizontalLayout():Bool { 40 | return type == GUILayoutType.HORIZONTAL; 41 | } 42 | 43 | public function isVerticalLayout():Bool { 44 | return type == GUILayoutType.VERTICAL; 45 | } 46 | 47 | public function toReference():String { 48 | return null; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/com/genome2d/tween/easing/GElastic.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.tween.easing; 2 | 3 | class GElastic { 4 | 5 | inline static public function easeIn(p_t:Float):Float { 6 | if (p_t == 0) return 0; if (p_t == 1) return 1; 7 | var s:Float; 8 | var a:Float = 1; 9 | var p:Float = 0.4; 10 | if (a < 1) { a = 1; s = p / 4; } 11 | else s = p / (2 * Math.PI) * Math.asin (1 / a); 12 | return -(a * Math.pow(2, 10 * (p_t -= 1)) * Math.sin( (p_t - s) * (2 * Math.PI) / p )); 13 | } 14 | 15 | inline static public function easeOut(p_t:Float):Float { 16 | if (p_t == 0) return 0; if (p_t == 1) return 1; 17 | var s:Float; 18 | var a:Float = 1; 19 | var p:Float = 0.4; 20 | if (a < 1) { a = 1; s = p / 4; } 21 | else s = p / (2 * Math.PI) * Math.asin (1 / a); 22 | return (a * Math.pow(2, -10 * p_t) * Math.sin((p_t - s) * (2 * Math.PI) / p ) + 1); 23 | } 24 | 25 | inline static public function easeInOut(p_t:Float):Float { 26 | if (p_t == 0) { 27 | return 0; 28 | } 29 | if ((p_t /= 1 / 2) == 2) { 30 | return 1; 31 | } 32 | 33 | var p:Float = (0.3 * 1.5); 34 | var s:Float = p / 4; 35 | 36 | if (p_t < 1) { 37 | return -0.5 * (Math.pow(2, 10 * (p_t -= 1)) * Math.sin((p_t - s) * (2 * Math.PI) / p)); 38 | } 39 | return Math.pow(2, -10 * (p_t -= 1)) * Math.sin((p_t - s) * (2 * Math.PI) / p) * 0.5 + 1; 40 | } 41 | } -------------------------------------------------------------------------------- /src/com/genome2d/geom/GVector2.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2014 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.geom; 10 | 11 | class GVector2 { 12 | public var x:Float; 13 | public var y:Float; 14 | 15 | public function new(p_x:Float = 0, p_y:Float = 0) { 16 | x = p_x; 17 | y = p_y; 18 | } 19 | 20 | #if swc @:extern #end 21 | public var length(get, never):Float; 22 | #if swc @:getter(length) #end 23 | inline private function get_length():Float { 24 | return Math.sqrt(x * x + y * y); 25 | } 26 | 27 | public function addEq(p_vector:GVector2):Void { 28 | x += p_vector.x; 29 | y += p_vector.y; 30 | } 31 | 32 | public function subEq(p_vector:GVector2):Void { 33 | x -= p_vector.x; 34 | y -= p_vector.y; 35 | } 36 | 37 | public function mulEq(p_s:Float):Void { 38 | x *= p_s; 39 | y *= p_s; 40 | } 41 | 42 | public function dot(p_vector:GVector2):Float { 43 | return x * p_vector.x + y * p_vector.y; 44 | } 45 | 46 | public function normalize():GVector2 { 47 | var l:Float = Math.sqrt(x * x + y * y); 48 | if(l != 0) { 49 | x /= l; 50 | y /= l; 51 | } 52 | return this; 53 | } 54 | 55 | public function toString():String { 56 | return "["+x+","+y+"]"; 57 | } 58 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Genome2D 2 | ======== 3 | What is Genome2D? 4 | ----------------- 5 | Genome2D is a multiplatform 2D GPU framework focused on game development. It is build using [Haxe](www.haxe.org) programming language which enables it to deploy to multiple targets. Currently Genome2D supports HTML target using WebGL with Canvas fallback and Flash/AIR target using Stage3D which enables you to target almost mobile device out there (iOS, Android) as well as desktop (Windows, OSX) and last but not least browser through Flash plugin. 6 | 7 | Genome2D is a node/component based system where nodes are abstract entities defining the scene hierarchy and components which are then added to these entities define their functionality. 8 | 9 | Repositories structure 10 | ---------------------- 11 | * __Genome2D-Core__ - THIS REPOSITORY 12 | 13 | Platform independent high level part of the Genome2D framework. 14 | 15 | * __Genome2D-ContextCommon__ - [REPOSITORY](https://github.com/pshtif/Genome2D-ContextCommon) 16 | 17 | Abstract and common base for all low level Genome2D contexts 18 | 19 | * __Genome2D-ContextFlash__ - [REPOSITORY](https://github.com/pshtif/Genome2D-ContextFlash) 20 | 21 | Low level Flash platform dependent Genome2D context. 22 | 23 | * __Genome2D-ContextHTML5__ - [REPOSITORY](https://github.com/pshtif/Genome2D-ContextHTML5) 24 | 25 | Low level HTML platform dependent Genome2D context. 26 | 27 | * __Genome2D-Examples__ - [REPOSITORY](https://github.com/pshtif/Genome2D-Examples) 28 | 29 | Genome2D examples 30 | 31 | Where to start? 32 | --------------- 33 | The best way to start with Genome2D is at our page www.genome2d.com 34 | -------------------------------------------------------------------------------- /src/com/genome2d/scripts/GScriptManager.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.scripts; 2 | 3 | /** 4 | * ... 5 | * @author Peter @sHTiF Stefcek 6 | */ 7 | import com.genome2d.callbacks.GCallback.GCallback1; 8 | class GScriptManager 9 | { 10 | static private var g2d_onScriptChanged:GCallback1; 11 | 12 | static private var g2d_scripts:Map; 13 | static public function getScript(p_id:String):GScript { 14 | return g2d_scripts != null ? g2d_scripts.get(p_id) : null; 15 | } 16 | 17 | static public function createScript(p_id:String, p_source:String = ""):GScript { 18 | var script:GScript = new GScript(); 19 | script.id = p_id; 20 | if (p_source != "") script.setSource(p_source); 21 | 22 | return script; 23 | } 24 | 25 | @:access(com.genome2d.scripts.GScript) 26 | static public function g2d_addScript(p_script:GScript):Void { 27 | if (g2d_scripts == null) g2d_scripts = new Map(); 28 | var oldScript:GScript = g2d_scripts.get(p_script.id); 29 | g2d_scripts.set(p_script.id, p_script); 30 | if (oldScript != null && oldScript != p_script) { 31 | g2d_onScriptChanged.dispatch(oldScript); 32 | oldScript.internalDispose(); 33 | } 34 | } 35 | 36 | static public function g2d_removeScript(p_script:GScript):Void { 37 | if (g2d_scripts != null) g2d_scripts.remove(p_script.id); 38 | } 39 | 40 | static public function getAllScripts():Map { 41 | return g2d_scripts; 42 | } 43 | 44 | static public function disposeAll():Void { 45 | for (script in g2d_scripts) { 46 | if (script.id.indexOf("g2d_") != 0) script.dispose(); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /src/com/genome2d/tween/GTweenTimeline.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.tween; 2 | 3 | import com.genome2d.macros.MGDebug; 4 | @prototypeName("tweenTimeline") 5 | @:access(com.genome2d.tween.GTweenSequence) 6 | class GTweenTimeline { 7 | private var g2d_dirty:Bool = false; 8 | private var g2d_sequences:Array = []; 9 | 10 | public function new() { 11 | g2d_sequences = new Array(); 12 | } 13 | 14 | inline private function addSequence(p_sequence:GTweenSequence):Void { 15 | p_sequence.g2d_timeline = this; 16 | g2d_sequences.push(p_sequence); 17 | } 18 | 19 | private function removeSequence(p_sequence:GTweenSequence):Void { 20 | g2d_sequences.remove(p_sequence); 21 | p_sequence.dispose(); 22 | } 23 | 24 | public function abortAllSequences():Void { 25 | while (g2d_sequences.length>0) { 26 | var sequence:GTweenSequence = g2d_sequences.shift(); 27 | sequence.dispose(); 28 | } 29 | } 30 | 31 | public function update(p_delta:Float) { 32 | var index:Int = 0; 33 | var length:Int = g2d_sequences.length; 34 | while (index0) { 44 | var sequence:GTweenSequence = g2d_sequences[index]; 45 | if (sequence.isComplete()) { 46 | removeSequence(sequence); 47 | } 48 | } 49 | g2d_dirty = false; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/com/genome2d/globals/GParameters.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.globals; 2 | 3 | class GParameters { 4 | private var g2d_parameters:Map; 5 | 6 | public function new() { 7 | g2d_parameters = new Map(); 8 | } 9 | 10 | public function hasParameter(p_name:String):Bool { 11 | return g2d_parameters.exists(p_name); 12 | } 13 | 14 | public function setParameter(p_name:String, p_value:Dynamic):Void { 15 | g2d_parameters.set(p_name, p_value); 16 | } 17 | 18 | public function getParameter(p_name:String):T { 19 | return cast g2d_parameters.get(p_name); 20 | } 21 | 22 | public function parseParametersString(p_data:String):Void { 23 | var e:EReg = ~/[\s\r\n]+/gim; 24 | 25 | var lines:Array = p_data.split("\n"); 26 | for (line in lines) { 27 | line = e.replace(line,""); 28 | if (line.indexOf("#") != 0) { 29 | var split:Array = line.split("="); 30 | if (split.length == 2) { 31 | // Fix Haxe 4 actually had a problem in correct IMap abstraction doing this in IMap set. 32 | var f:Float = Std.parseFloat(split[1]); 33 | if (split[1].toLowerCase() == "true") { 34 | g2d_parameters.set(split[0], true); 35 | } else if (split[1].toLowerCase() == "false") { 36 | g2d_parameters.set(split[0], false); 37 | } else if (!Math.isNaN(f)) { 38 | g2d_parameters.set(split[0], f); 39 | } else { 40 | g2d_parameters.set(split[0], split[1]); 41 | } 42 | } 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/com/genome2d/components/renderable/particles/GParticleSystemComponent.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2014 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | 10 | package com.genome2d.components.renderable.particles; 11 | 12 | import com.genome2d.components.GComponent; 13 | import com.genome2d.components.renderable.IGRenderable; 14 | import com.genome2d.context.GCamera; 15 | import com.genome2d.geom.GRectangle; 16 | import com.genome2d.input.GMouseInput; 17 | import com.genome2d.particles.GParticleSystem; 18 | 19 | /** 20 | * Component encapsulating the GParticleSystem class 21 | * 22 | * @author Peter @sHTiF Stefcek 23 | */ 24 | class GParticleSystemComponent extends GComponent implements IGRenderable 25 | { 26 | @prototype 27 | public var particleSystem:GParticleSystem; 28 | 29 | override public function init():Void { 30 | particleSystem = new GParticleSystem(); 31 | 32 | node.core.onUpdate.add(update); 33 | } 34 | 35 | private function update(p_deltaTime:Float):Void { 36 | particleSystem.x = node.g2d_worldX; 37 | particleSystem.y = node.g2d_worldY; 38 | 39 | particleSystem.update(p_deltaTime); 40 | } 41 | 42 | public function render(p_camera:GCamera, p_useMatrix:Bool):Void { 43 | particleSystem.render(node.core.getContext()); 44 | } 45 | 46 | public function getBounds(p_target:GRectangle = null):GRectangle { 47 | return null; 48 | } 49 | 50 | public function captureMouseInput(p_input:GMouseInput):Void { 51 | 52 | } 53 | 54 | public function hitTest(p_x:Float, p_y:Float):Bool { 55 | return false; 56 | } 57 | 58 | override public function onDispose():Void { 59 | node.core.onUpdate.remove(update); 60 | } 61 | 62 | } -------------------------------------------------------------------------------- /src/com/genome2d/ui/skin/GUISkinManager.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2015 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.ui.skin; 10 | 11 | import com.genome2d.callbacks.GCallback.GCallback1; 12 | import com.genome2d.ui.skin.GUISkin; 13 | 14 | class GUISkinManager { 15 | static private var g2d_onSkinChanged:GCallback1; 16 | #if swc @:extern #end 17 | static public var onSkinChanged(get, never):GCallback1; 18 | #if swc @:getter(bottom) #end 19 | inline static private function get_onSkinChanged():GCallback1 { 20 | return g2d_onSkinChanged; 21 | } 22 | 23 | static public function init():Void { 24 | g2d_onSkinChanged = new GCallback1(String); 25 | GUISkin.g2d_batchQueue = new Array(); 26 | 27 | g2d_skins = new Map(); 28 | } 29 | 30 | static private var g2d_skins:Map; 31 | static public function getSkin(p_id:String):T { 32 | return cast g2d_skins.get(p_id); 33 | } 34 | 35 | static public function g2d_addSkin(p_id:String, p_value:GUISkin):Void { 36 | var oldSkin:GUISkin = g2d_skins.get(p_id); 37 | g2d_skins.set(p_id, p_value); 38 | if (oldSkin != null) { 39 | g2d_onSkinChanged.dispatch(p_id); 40 | oldSkin.g2d_internalDispose(); 41 | } 42 | } 43 | 44 | static public function g2d_removeSkin(p_id:String):Void { 45 | g2d_skins.remove(p_id); 46 | } 47 | 48 | static public function getAllSkins():Map { 49 | return g2d_skins; 50 | } 51 | 52 | static public function disposeAll():Void { 53 | for (skin in g2d_skins) { 54 | if (skin.id.indexOf("g2d_") != 0) skin.dispose(); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/com/genome2d/transitions/GTransition.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.transitions; 2 | import com.genome2d.debug.GDebug; 3 | import com.genome2d.proto.IGPrototypable; 4 | 5 | @:access(com.genome2d.transitions.GTransitionManager) 6 | @:allow(com.genome2d.transitions.GTransitionManager) 7 | @prototypeName("transition") 8 | class GTransition implements IGPrototypable { 9 | private var g2d_id:String; 10 | #if swc @:extern #end 11 | @prototype 12 | public var id(get, set):String; 13 | #if swc @:getter(id) #end 14 | inline private function get_id():String { 15 | return g2d_id; 16 | } 17 | #if swc @:setter(id) #end 18 | inline private function set_id(p_value:String):String { 19 | if (p_value != g2d_id && p_value.length > 0) { 20 | if (GTransitionManager.getTransition(p_value) != null) GDebug.error("Duplicate transition id: "+p_value); 21 | //GTransitionManager.g2d_references.set(p_value,this); 22 | 23 | if (GTransitionManager.getTransition(g2d_id) != null) GTransitionManager.g2d_references.remove(g2d_id); 24 | g2d_id = p_value; 25 | } 26 | 27 | return g2d_id; 28 | } 29 | 30 | @prototype 31 | public var time:Float = 0; 32 | @prototype 33 | public var delay:Float = 0; 34 | /* 35 | private var ease:IEasing; 36 | 37 | static private var g2d_instanceCount:Int = 0; 38 | public function new(p_id:String = "", p_time:Float, p_ease:IEasing = null, p_delay:Float = 0) { 39 | g2d_instanceCount++; 40 | 41 | id = (p_id != "") ? p_id : "GTransition" + g2d_instanceCount; 42 | time = p_time; 43 | ease = (p_ease == null) ? Linear.easeNone : p_ease; 44 | delay = p_delay; 45 | } 46 | 47 | public function apply(p_instance:Dynamic, p_property:String, p_value:Dynamic):Void { 48 | var prop:Dynamic = { }; 49 | Reflect.setField(prop, p_property, p_value); 50 | //Actuate.tween(p_instance, time, prop).delay(delay); 51 | } 52 | /* 53 | */ 54 | } -------------------------------------------------------------------------------- /src/com/genome2d/utils/GQuadTree.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2014 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.utils; 10 | 11 | import com.genome2d.geom.GRectangle; 12 | import com.genome2d.utils.GQuadTreeNode; 13 | 14 | class GQuadTree { 15 | private var g2d_root:GQuadTreeNode; 16 | 17 | private var g2d_left:Float; 18 | private var g2d_top:Float; 19 | private var g2d_right:Float; 20 | private var g2d_bottom:Float; 21 | 22 | private var g2d_map:Map; 23 | 24 | public function new(p_x:Float, p_y:Float, p_width:Float, p_height:Float) { 25 | g2d_left = p_x; 26 | g2d_top = p_y; 27 | g2d_right = p_x+p_width; 28 | g2d_bottom = p_y+p_height; 29 | 30 | g2d_root = new GQuadTreeNode(g2d_left, g2d_top, g2d_right, g2d_bottom); 31 | 32 | g2d_map = new Map(); 33 | } 34 | 35 | public function add(p_object:Dynamic, p_left:Float, p_top:Float, p_right:Float, p_bottom:Float):Bool { 36 | var node:GQuadTreeNode = g2d_root.add(p_object, p_left, p_top, p_right, p_bottom); 37 | 38 | if (node != null) { 39 | g2d_map.set(p_object, node); 40 | } 41 | 42 | return node != null; 43 | } 44 | 45 | public function remove(p_object:Dynamic):Bool { 46 | var node:GQuadTreeNode = g2d_map.get(p_object.name); 47 | 48 | if (node == null) return false; 49 | 50 | node.remove(p_object); 51 | 52 | g2d_map.remove(p_object.name); 53 | 54 | return true; 55 | } 56 | 57 | public function getObjectsInBounds(p_bounds:GRectangle, p_result:Array):Void { 58 | g2d_root.getObjectsInBounds(p_bounds.x, p_bounds.y, p_bounds.right, p_bounds.bottom, p_result); 59 | } 60 | } -------------------------------------------------------------------------------- /src/com/genome2d/ui/skin/GUIShapeSkin.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2015 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.ui.skin; 10 | import com.genome2d.context.GBlendMode; 11 | import com.genome2d.textures.GTexture; 12 | import com.genome2d.particles.GParticleSystem; 13 | 14 | class GUIShapeSkin extends GUISkin { 15 | 16 | public var texture:GTexture; 17 | public var rotation:Float = 0; 18 | 19 | private var g2d_vertices:Array; 20 | private var g2d_uvs:Array; 21 | 22 | override public function getMinWidth():Float { 23 | return 0; 24 | } 25 | 26 | override public function getMinHeight():Float { 27 | return 0; 28 | } 29 | 30 | public function new(p_id:String = "", p_texture:GTexture, p_vertices:Array, p_uvs:Array, p_origin:GUIShapeSkin = null) { 31 | super(p_id, p_origin); 32 | 33 | texture = p_texture; 34 | g2d_vertices = p_vertices; 35 | g2d_uvs = p_uvs; 36 | } 37 | 38 | override public function render(p_left:Float, p_top:Float, p_right:Float, p_bottom:Float, p_red:Float, p_green:Float, p_blue:Float, p_alpha:Float):Bool { 39 | Genome2D.getInstance().getContext().drawPoly(texture, blendMode, g2d_vertices, g2d_uvs, p_left, p_top, 1, 1, rotation, red, green, blue, alpha, null); 40 | 41 | return true; 42 | } 43 | 44 | override public function clone():GUISkin { 45 | var clone:GUIShapeSkin = new GUIShapeSkin("", texture, g2d_vertices, g2d_uvs, (g2d_origin == null)?this:cast g2d_origin); 46 | clone.red = red; 47 | clone.green = green; 48 | clone.blue = blue; 49 | clone.alpha = alpha; 50 | clone.blendMode = blendMode; 51 | clone.rotation = rotation; 52 | return clone; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/com/genome2d/macros/MGBuild.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.macros; 2 | 3 | import haxe.macro.Type.ModuleType; 4 | import haxe.macro.Expr; 5 | import haxe.macro.Context; 6 | 7 | import haxe.crypto.Md5; 8 | import haxe.Timer; 9 | 10 | class MGBuild { 11 | 12 | macro public static function myFunc() { 13 | trace("Start macro compilation."); 14 | Context.onAfterTyping(onAfterTyping); 15 | Context.onGenerate(onGenerate); 16 | //Context.onTypeNotFound(onTypeNotFound); 17 | return { expr:EBlock([]), pos:Context.currentPos() } 18 | } 19 | 20 | #if macro 21 | static public function onTypeNotFound(p_type:String):TypeDefinition { 22 | trace("onTypeNotFound", p_type); 23 | return null; 24 | } 25 | 26 | static function onAfterTyping(p_types:Array) { 27 | trace("onAfterTyping"); 28 | /* 29 | for (moduleType in p_types) { 30 | trace(moduleType); 31 | } 32 | /* 33 | */ 34 | } 35 | 36 | static function onGenerate(p_types:Array) { 37 | trace("onGenerate"); 38 | } 39 | #end 40 | 41 | macro static public function getBuildId() { 42 | return macro $v{ Md5.encode(Std.string( Timer.stamp()*Math.random() )) }; 43 | } 44 | 45 | macro static public function getBuildDate() { 46 | return macro $v{ Date.now().toString() }; 47 | } 48 | 49 | macro static public function getBuildVersion() { 50 | return macro $v{ loadFile("VERSION") }; 51 | } 52 | 53 | #if macro 54 | static function loadFile(path:String) { 55 | try { 56 | var p = Context.resolvePath(path); 57 | Context.registerModuleDependency(Context.getLocalModule(), p); 58 | return sys.io.File.getContent(p); 59 | } 60 | catch(e:Dynamic) { 61 | return haxe.macro.Context.error('Failed to load file $path: $e', Context.currentPos()); 62 | } 63 | } 64 | #end 65 | } 66 | -------------------------------------------------------------------------------- /src/com/genome2d/components/GScriptComponent.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.components; 2 | 3 | import com.genome2d.context.GCamera; 4 | import com.genome2d.scripts.GScript; 5 | 6 | class GScriptComponent extends GComponent { 7 | private var g2d_script:GScript = null; 8 | @prototype("getReference") 9 | public var script(get,set):GScript; 10 | #if swc @:getter(script) #end 11 | inline private function get_script():GScript { 12 | return g2d_script; 13 | } 14 | #if swc @:setter(script) #end 15 | inline private function set_script(p_value:GScript):GScript { 16 | if (g2d_script != null) { 17 | g2d_script.onInvalidated.remove(invalidate); 18 | if (g2d_executeUpdate != null) node.core.onUpdate.remove(update_handler); 19 | if (g2d_executeDispose != null) g2d_executeDispose(); 20 | } 21 | g2d_script = p_value; 22 | g2d_script.setVariable("node", node); 23 | g2d_script.onInvalidated.add(invalidate); 24 | invalidate(); 25 | return g2d_script; 26 | } 27 | 28 | private var g2d_executeRender:GCamera->Bool->Void; 29 | private var g2d_executeInit:Void->Void; 30 | private var g2d_executeDispose:Void->Void; 31 | private var g2d_executeUpdate:Float->Void; 32 | 33 | override public function onDispose():Void { 34 | if (g2d_executeDispose != null) g2d_executeDispose(); 35 | } 36 | 37 | private function invalidate():Void { 38 | if (g2d_script != null) { 39 | g2d_executeInit = g2d_script.getVariable("init"); 40 | g2d_executeDispose = g2d_script.getVariable("dispose"); 41 | g2d_executeRender = g2d_script.getVariable("render"); 42 | g2d_executeUpdate = g2d_script.getVariable("update"); 43 | } 44 | 45 | if (g2d_executeInit != null) g2d_executeInit(); 46 | if (g2d_executeUpdate != null) node.core.onUpdate.add(update_handler); 47 | } 48 | 49 | private function update_handler(p_deltaTime:Float):Void { 50 | if (g2d_executeUpdate != null) g2d_executeUpdate(p_deltaTime); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/com/genome2d/components/renderable/GSlice3Sprite.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.components.renderable; 2 | 3 | import com.genome2d.context.GCamera; 4 | import com.genome2d.textures.GTexture; 5 | 6 | class GSlice3Sprite extends GTiledSprite { 7 | public var texture1:GTexture; 8 | public var texture2:GTexture; 9 | public var texture3:GTexture; 10 | 11 | @:dox(hide) 12 | override public function render(p_camera:GCamera, p_useMatrix:Bool):Void { 13 | // Calculate rotation 14 | var sin:Float = 0; 15 | var cos:Float = 1; 16 | if (node.g2d_worldRotation != 0) { 17 | sin = Math.sin(node.g2d_worldRotation); 18 | cos = Math.cos(node.g2d_worldRotation); 19 | } 20 | 21 | var ix:Int = Math.ceil(g2d_width/texture1.width); 22 | var iy:Int = Math.ceil(g2d_height/texture1.height); 23 | 24 | var w:Float = texture1.region.width; 25 | var h:Float = texture1.region.height; 26 | var cw:Float = w; 27 | var ch:Float = h; 28 | var cx:Float = 0; 29 | var cy:Float = 0; 30 | 31 | for (j in 0...iy) { 32 | for (i in 0...ix) { 33 | if (i==0) texture = texture1; else if (i==ix-1) texture = texture3; else texture = texture2; 34 | 35 | cw = (i==ix-2 && i!=0 && g2d_width%texture.width!=0) ? w*(g2d_width%texture.width)/texture.width : w; 36 | ch = (j==iy-1 && g2d_height%texture.height!=0) ? h*(g2d_height%texture.height)/texture.height : h; 37 | node.core.getContext().drawSource(texture, blendMode, 38 | texture.region.x, texture.region.y, cw, ch, -cw*.5, -ch*.5, 39 | node.g2d_worldX+cx*cos-cy*sin, node.g2d_worldY+cy*cos+cx*sin, node.g2d_worldScaleX, node.g2d_worldScaleY, node.g2d_worldRotation, 40 | node.g2d_worldRed, node.g2d_worldGreen, node.g2d_worldBlue, node.g2d_worldAlpha, 41 | filter); 42 | cx += cw*node.g2d_worldScaleX; 43 | } 44 | cx = 0; 45 | cy += ch*node.g2d_worldScaleY; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/com/genome2d/ui/skin/GUIParticleSkin.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2015 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.ui.skin; 10 | import com.genome2d.particles.GParticleSystem; 11 | 12 | class GUIParticleSkin extends GUISkin { 13 | @prototype 14 | public var particleSystem:GParticleSystem; 15 | 16 | override public function getMinWidth():Float { 17 | return 0; 18 | } 19 | 20 | override public function getMinHeight():Float { 21 | return 0; 22 | } 23 | 24 | public function new(p_id:String = "", p_particleSystem:GParticleSystem = null, p_origin:GUIParticleSkin = null) { 25 | super(p_id, p_origin); 26 | 27 | particleSystem = p_particleSystem; 28 | if (g2d_origin == null) Genome2D.getInstance().onUpdate.add(update_handler); 29 | } 30 | 31 | override public function render(p_left:Float, p_top:Float, p_right:Float, p_bottom:Float, p_red:Float, p_green:Float, p_blue:Float, p_alpha:Float):Bool { 32 | particleSystem.x = p_left + (p_right - p_left)/2; 33 | particleSystem.y = p_top + (p_bottom - p_top)/2; 34 | 35 | var rendered:Bool = false; 36 | if (super.render(p_left, p_top, p_right, p_bottom, p_red, p_green, p_blue, p_alpha)) { 37 | particleSystem.render(Genome2D.getInstance().getContext()); 38 | rendered = true; 39 | } 40 | return rendered; 41 | } 42 | 43 | private function update_handler(p_deltaTime:Float):Void { 44 | particleSystem.update(p_deltaTime); 45 | } 46 | 47 | override public function clone():GUISkin { 48 | var clone:GUIParticleSkin = new GUIParticleSkin("", particleSystem, (g2d_origin == null)?this:cast g2d_origin); 49 | clone.red = red; 50 | clone.green = green; 51 | clone.blue = blue; 52 | clone.alpha = alpha; 53 | return clone; 54 | } 55 | 56 | override public function dispose():Void { 57 | if (g2d_origin == null) Genome2D.getInstance().onUpdate.remove(update_handler); 58 | 59 | super.dispose(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/com/genome2d/text/GTextureChar.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2014 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.text; 10 | 11 | import com.genome2d.textures.GTexture; 12 | 13 | class GTextureChar { 14 | private var g2d_xoffset:Float = 0; 15 | #if swc @:extern #end 16 | public var xoffset(get, set):Float; 17 | #if swc @:getter(xoffset) #end 18 | inline private function get_xoffset():Float { 19 | return g2d_xoffset * g2d_texture.scaleFactor; 20 | } 21 | #if swc @:setter(xoffset) #end 22 | inline private function set_xoffset(p_value:Float):Float { 23 | g2d_xoffset = p_value / g2d_texture.scaleFactor; 24 | return g2d_xoffset; 25 | } 26 | 27 | private var g2d_yoffset:Float = 0; 28 | #if swc @:extern #end 29 | public var yoffset(get, set):Float; 30 | #if swc @:getter(yoffset) #end 31 | inline private function get_yoffset():Float { 32 | return g2d_yoffset * g2d_texture.scaleFactor; 33 | } 34 | #if swc @:setter(yoffset) #end 35 | inline private function set_yoffset(p_value:Float):Float { 36 | g2d_yoffset = p_value / g2d_texture.scaleFactor; 37 | return g2d_yoffset; 38 | } 39 | 40 | private var g2d_xadvance:Float = 0; 41 | #if swc @:extern #end 42 | public var xadvance(get, set):Float; 43 | #if swc @:getter(xadvance) #end 44 | inline private function get_xadvance():Float { 45 | return g2d_xadvance * g2d_texture.scaleFactor; 46 | } 47 | #if swc @:setter(xadvance) #end 48 | inline private function set_xadvance(p_value:Float):Float { 49 | g2d_xadvance = p_value / g2d_texture.scaleFactor; 50 | return g2d_xadvance; 51 | } 52 | 53 | private var g2d_texture:GTexture; 54 | #if swc @:extern #end 55 | public var texture(get, never):GTexture; 56 | #if swc @:getter(texture) #end 57 | inline private function get_texture():GTexture { 58 | return g2d_texture; 59 | } 60 | 61 | public function new(p_texture:GTexture):Void { 62 | g2d_texture = p_texture; 63 | } 64 | 65 | public function dispose():Void { 66 | g2d_texture = null; 67 | } 68 | } -------------------------------------------------------------------------------- /src/com/genome2d/particles/GParticlePool.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2014 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.particles; 10 | 11 | /** 12 | Particle pool management class, used for pooling `GNewParticle` instances for `GParticleSystem` components instances 13 | **/ 14 | import com.genome2d.particles.GParticle; 15 | @:allow(com.genome2d.particles.GParticle) 16 | @:allow(com.genome2d.particles.GParticleEmitter) 17 | class GParticlePool 18 | { 19 | static public var g2d_defaultPool:GParticlePool = new GParticlePool(); 20 | 21 | public var g2d_availableInstance:GParticle; 22 | private var g2d_count:Int = 0; 23 | 24 | private var g2d_particleClass:Class; 25 | 26 | /** 27 | Create new particles pool, only if you want to implement pooling of custom particles otherwise let Genome2D 28 | use the default precreated pool shared by all `GParticleSystem` instances to save memory 29 | **/ 30 | public function new(p_particleClass:Class = null):Void { 31 | g2d_particleClass = (p_particleClass==null) ? GParticle : p_particleClass; 32 | } 33 | 34 | /** 35 | Precache particles instances 36 | **/ 37 | public function precache(p_precacheCount:Int):Void { 38 | if (p_precacheCount < g2d_count) return; 39 | 40 | var precached:GParticle = g2d_get(); 41 | while (g2d_count; 26 | 27 | /** 28 | Create new particles pool, only if you want to implement pooling of custom particles otherwise let Genome2D 29 | use the default precreated pool shared by all `GParticleSystem` instances to save memory 30 | **/ 31 | public function new(p_particleClass:Class = null):Void { 32 | g2d_particleClass = (p_particleClass==null) ? GParticleD : p_particleClass; 33 | } 34 | 35 | /** 36 | Precache particles instances 37 | **/ 38 | public function precache(p_precacheCount:Int):Void { 39 | if (p_precacheCount < g2d_count) return; 40 | 41 | var precached:GParticleD = g2d_get(); 42 | while (g2d_count { 17 | var fields = Context.getBuildFields(); 18 | 19 | var pos = Context.currentPos(); 20 | var fieldNames = ["onMouseWheel", "onDoubleMouseClick", "onMouseDown", "onMouseUp", "onMouseMove", "onMouseOver", "onMouseOut", "onRightMouseDown", "onRightMouseUp", "onMouseClick", "onRightMouseClick"]; 21 | 22 | for (fieldName in fieldNames) { 23 | 24 | var getterFunc:Function = { 25 | expr: macro return { 26 | if ($i{"g2d_"+fieldName} == null) $i{"g2d_"+fieldName} = new GCallback1(GMouseInput); 27 | return $i{"g2d_"+fieldName}; 28 | }, // actual value 29 | ret: (macro:GCallback1), // return type 30 | args:[] 31 | } 32 | 33 | var privateField:Field = { 34 | name: "g2d_"+fieldName, 35 | access: [Access.APrivate], 36 | kind: FieldType.FVar(macro:GCallback1), 37 | pos: pos 38 | }; 39 | 40 | var propertyField:Field = { 41 | name: fieldName, 42 | access: [Access.APublic], 43 | kind: FieldType.FProp("get", "never", getterFunc.ret), 44 | #if swc 45 | meta: [{name:":extern", pos: pos}], 46 | #end 47 | pos: pos 48 | }; 49 | 50 | var getterField:Field = { 51 | name: "get_" + fieldName, 52 | access: [Access.APrivate, Access.AInline], 53 | kind: FieldType.FFun(getterFunc), 54 | #if swc 55 | meta: [{name:":getter", params : [ { expr:EConst(CIdent(fieldName)), pos:Context.currentPos() } ], pos: pos}], 56 | #end 57 | pos: pos 58 | }; 59 | 60 | fields.push(privateField); 61 | fields.push(propertyField); 62 | fields.push(getterField); 63 | } 64 | 65 | return fields; 66 | } 67 | } 68 | #end -------------------------------------------------------------------------------- /src/com/genome2d/components/renderable/ui/GUI.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.components.renderable.ui; 2 | 3 | import com.genome2d.geom.GPoint; 4 | import com.genome2d.ui.skin.GUISkin; 5 | import com.genome2d.ui.element.GUIElement; 6 | import com.genome2d.input.GMouseInput; 7 | import com.genome2d.geom.GRectangle; 8 | import com.genome2d.context.GCamera; 9 | import com.genome2d.components.renderable.IGRenderable; 10 | 11 | @:access(com.genome2d.ui.element.GUIElement) 12 | @:access(com.genome2d.ui.skin.GUISkin) 13 | class GUI extends GComponent implements IGRenderable { 14 | 15 | public var root:GUIElement; 16 | public var useNodePosition:Bool = false; 17 | public var enableBoundsCulling:Bool = false; 18 | private var g2d_bounds:GRectangle; 19 | 20 | override public function init():Void { 21 | root = new GUIElement(); 22 | root.g2d_gui = this; 23 | root.name = "root"; 24 | root.g2d_root = root; 25 | root.mouseEnabled = false; 26 | 27 | setBounds(new GRectangle(0, 0, node.core.getContext().getStageViewRect().width, node.core.getContext().getStageViewRect().height)); 28 | } 29 | 30 | public function invalidate():Void { 31 | root.g2d_worldLeft = g2d_bounds.left + (useNodePosition ? node.g2d_worldX : 0); 32 | root.g2d_worldRight = g2d_bounds.right + (useNodePosition ? node.g2d_worldX : 0); 33 | root.g2d_worldTop = g2d_bounds.top + (useNodePosition ? node.g2d_worldY : 0); 34 | root.g2d_worldBottom = g2d_bounds.bottom + (useNodePosition ? node.g2d_worldY : 0); 35 | root.g2d_finalWidth = root.g2d_worldRight - root.g2d_worldLeft; 36 | root.g2d_finalHeight = root.g2d_worldBottom - root.g2d_worldTop; 37 | 38 | root.calculateWidth(); 39 | root.invalidateWidth(); 40 | root.calculateHeight(); 41 | root.invalidateHeight(); 42 | } 43 | 44 | public function render(p_camera:GCamera, p_useMatrix:Bool):Void { 45 | invalidate(); 46 | 47 | root.render(1, 1, 1, 1); 48 | GUISkin.flushBatch(); 49 | } 50 | 51 | public function setBounds(p_bounds:GRectangle):Void { 52 | g2d_bounds = p_bounds; 53 | invalidate(); 54 | } 55 | 56 | inline public function getBounds(p_target:GRectangle = null):GRectangle { 57 | return g2d_bounds; 58 | } 59 | 60 | public function captureMouseInput(p_input:GMouseInput):Void { 61 | root.captureMouseInput(p_input); 62 | } 63 | 64 | public function hitTest(p_x:Float, p_y:Float):Bool { 65 | return false; 66 | } 67 | 68 | public function worldToUi(p_world:GPoint, p_result:GPoint = null):GPoint { 69 | if (p_result == null) p_result = new GPoint(0, 0); 70 | 71 | p_result.x = p_world.x - root.g2d_worldLeft; 72 | p_result.y = p_world.y - root.g2d_worldTop; 73 | 74 | return p_result; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/com/genome2d/particles/modules/GScriptModule.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.particles.modules; 2 | 3 | import com.genome2d.scripts.GScript; 4 | import com.genome2d.particles.GParticleEmitter; 5 | import com.genome2d.particles.GParticle; 6 | 7 | class GScriptModule extends GParticleEmitterModule 8 | { 9 | private var g2d_script:GScript = null; 10 | @prototype("getReference") 11 | public var script(get,set):GScript; 12 | #if swc @:getter(script) #end 13 | inline private function get_script():GScript { 14 | return g2d_script; 15 | } 16 | #if swc @:setter(script) #end 17 | inline private function set_script(p_value:GScript):GScript { 18 | if (g2d_script != null) g2d_script.onInvalidated.remove(invalidate); 19 | g2d_script = p_value; 20 | g2d_script.onInvalidated.add(invalidate); 21 | invalidate(); 22 | return g2d_script; 23 | } 24 | 25 | private var g2d_executeSpawnParticle:Dynamic; 26 | private var g2d_executeUpdateParticle:Dynamic; 27 | private var g2d_executeUpdateEmitter:Dynamic; 28 | private var g2d_executeAddedToEmitter:Dynamic; 29 | private var g2d_executeRemovedFromEmitter:Dynamic; 30 | 31 | public function new() { 32 | super(); 33 | } 34 | 35 | private function invalidate():Void { 36 | if (g2d_script != null) { 37 | g2d_executeSpawnParticle = g2d_script.getVariable("spawnParticle"); 38 | g2d_executeUpdateParticle = g2d_script.getVariable("updateParticle"); 39 | g2d_executeUpdateEmitter = g2d_script.getVariable("updateEmitter"); 40 | g2d_executeAddedToEmitter = g2d_script.getVariable("addedToEmitter"); 41 | g2d_executeRemovedFromEmitter = g2d_script.getVariable("removedFromEmitter"); 42 | 43 | spawnParticleModule = g2d_executeSpawnParticle != null; 44 | updateParticleModule = g2d_executeUpdateParticle != null; 45 | updateEmitterModule = g2d_executeUpdateEmitter != null; 46 | } 47 | } 48 | 49 | override public function spawnParticle(p_emitter:GParticleEmitter, p_particle:GParticle):Void { 50 | if (g2d_executeSpawnParticle != null) g2d_executeSpawnParticle(p_emitter, p_particle); 51 | } 52 | 53 | override public function updateParticle(p_emitter:GParticleEmitter, p_particle:GParticle, p_deltaTime:Float):Void { 54 | if (g2d_executeUpdateParticle != null) g2d_executeUpdateParticle(p_emitter, p_particle, p_deltaTime); 55 | } 56 | 57 | override public function updateEmitter(p_emitter:GParticleEmitter, p_deltaTime:Float):Void { 58 | if (g2d_executeUpdateEmitter != null) g2d_executeUpdateEmitter(p_emitter, p_deltaTime); 59 | } 60 | 61 | override public function addedToEmitter(p_emitter:GParticleEmitter):Void { 62 | if (g2d_executeAddedToEmitter != null) g2d_executeAddedToEmitter(p_emitter); 63 | } 64 | 65 | override public function removedFromEmitter(p_emitter:GParticleEmitter):Void { 66 | if (g2d_executeRemovedFromEmitter != null) g2d_executeRemovedFromEmitter(p_emitter); 67 | } 68 | } -------------------------------------------------------------------------------- /src/com/genome2d/geom/GLine.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2014 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.geom; 10 | 11 | import com.genome2d.geom.GRectangle; 12 | import com.genome2d.geom.GVector2; 13 | 14 | class GLine { 15 | public var start:GVector2; 16 | public var end:GVector2; 17 | public var normal:GVector2; 18 | public var vec:GVector2; 19 | public var aabb:GRectangle; 20 | 21 | public function new(p_start:GVector2, p_end:GVector2) { 22 | start = p_start; 23 | end = p_end; 24 | normal = new GVector2(p_end.y - p_start.y, -p_end.x + p_start.x); 25 | normal.normalize(); 26 | vec = new GVector2(p_end.x - p_start.x, p_end.y - p_start.y); 27 | aabb = new GRectangle((start.xend.x)?start.x:end.x) - ((start.xend.y)?start.y:end.y) - ((start.y=0 && ua <= 1) { 61 | return new GVector2(p_line.start.x + (ua * p_line.vec.x), p_line.start.y + (ua * p_line.vec.y)); 62 | } 63 | 64 | if(!p_v2seg && ub >= 0 && ub <= 1) { 65 | return new GVector2(p_line.start.x + (ua * p_line.vec.x), p_line.start.y + (ua * p_line.vec.y)); 66 | } 67 | 68 | if(ua >=0 && ua <= 1 && ub >= 0 && ub <= 1) { 69 | return new GVector2(p_line.start.x + (ua * p_line.vec.x), p_line.start.y + (ua * p_line.vec.y)); 70 | } 71 | 72 | return null; 73 | } 74 | 75 | public function toString():String { 76 | return start+" : "+end; 77 | } 78 | } -------------------------------------------------------------------------------- /src/com/genome2d/particles/GParticleGroup.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.particles; 2 | 3 | /** 4 | * ... 5 | * @author Peter @sHTiF Stefcek 6 | */ 7 | class GParticleGroup 8 | { 9 | public var particles:Array; 10 | public var particleCount:UInt = 0; 11 | public var massX:Float = 0; 12 | public var massY:Float = 0; 13 | public var vx:Float = 0; 14 | public var vy:Float = 0; 15 | public var torque:Float = 0; 16 | public var rigid:Bool = false; 17 | public var rigidAllowTranslation:Bool = true; 18 | public var rigidAllowRotation:Bool = true; 19 | 20 | static private var g2d_id:Int = 0; 21 | public var id:Int = 0; 22 | public function new() { 23 | id = g2d_id++; 24 | particles = new Array(); 25 | } 26 | 27 | inline public function addParticle(p_particle:GParticle):Void { 28 | particles[particleCount++] = p_particle; 29 | massX += p_particle.x; 30 | massY += p_particle.y; 31 | } 32 | 33 | inline public function calculateForce():Void { 34 | massX /= particleCount; 35 | massY /= particleCount; 36 | 37 | if (rigid) { 38 | var t:Float = 0; 39 | var ax:Float = 0; 40 | var ay:Float = 0; 41 | for (i in 0...particleCount) { 42 | var particle:GParticle = particles[i]; 43 | var fx:Float = particle.fluidX / (particle.density * 0.9 + 0.1); 44 | var fy:Float = particle.fluidY / (particle.density * 0.9 + 0.1); 45 | if (rigidAllowRotation) t += crossProduct(massX - particle.x, massY - particle.y, fx, fy); 46 | if (rigidAllowTranslation) { 47 | ax += fx; 48 | ay += fy; 49 | } 50 | } 51 | torque += t / particleCount; 52 | vx += ax / particleCount; 53 | vy += ay / particleCount; 54 | 55 | var sin:Float = Math.sin(-torque/1000); 56 | var cos:Float = Math.cos(-torque/1000); 57 | for (i in 0...particleCount) { 58 | var particle:GParticle = particles[i]; 59 | if (!particle.fixed) { 60 | if (rigidAllowRotation) { 61 | var tx:Float = particle.x - massX; 62 | var ty:Float = particle.y - massY; 63 | var nx = tx * cos - ty * sin; 64 | var ny = tx * sin + ty * cos; 65 | particle.x = massX + nx; 66 | particle.y = massY + ny; 67 | } 68 | 69 | if (rigidAllowTranslation) { 70 | particle.velocityX = vx; 71 | particle.velocityY = vy; 72 | } 73 | } 74 | } 75 | } else { 76 | for (i in 0...particleCount) { 77 | var particle:GParticle = particles[i]; 78 | if (particle.density > 0 && !particle.fixed) { 79 | //particle.velocityY += .1; 80 | particle.velocityX += particle.fluidX / (particle.density * 0.9 + 0.1); 81 | particle.velocityY += particle.fluidY / (particle.density * 0.9 + 0.1); 82 | } 83 | } 84 | } 85 | } 86 | 87 | inline private function crossProduct(p_v1x:Float, p_v1y:Float, p_v2x:Float, p_v2y:Float):Float { 88 | return (p_v1x*p_v2y) - (p_v1y*p_v2x); 89 | } 90 | } -------------------------------------------------------------------------------- /src/com/genome2d/project/GProject.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.project; 2 | 3 | import com.genome2d.callbacks.GCallback.GCallback0; 4 | import com.genome2d.debug.GDebug; 5 | import com.genome2d.macros.MGDebug; 6 | import com.genome2d.assets.GAssetManager; 7 | import com.genome2d.context.GContextConfig; 8 | import com.genome2d.assets.GAsset; 9 | import com.genome2d.assets.GStaticAssetManager; 10 | import com.genome2d.geom.GRectangle; 11 | #if cs 12 | import unityengine.*; 13 | #end 14 | 15 | #if !cs 16 | class GProject { 17 | #else 18 | @:nativeGen 19 | class GProject extends MonoBehaviour { 20 | #end 21 | #if cs 22 | public var onUpdate(default,null):GCallback0; 23 | public var onFrame(default,null):GCallback0; 24 | 25 | // onMouse callback was moved to GUnityContext 26 | #end 27 | 28 | private var g2d_genome:Genome2D; 29 | public function getGenome():Genome2D { 30 | return g2d_genome; 31 | } 32 | 33 | private var g2d_config:GProjectConfig; 34 | 35 | private var g2d_assetManager:GAssetManager; 36 | 37 | #if !cs 38 | public function new(p_config:GProjectConfig) { 39 | g2d_config = p_config; 40 | 41 | g2d_genome = Genome2D.getInstance(); 42 | if (g2d_config.initGenome) { 43 | initGenome(); 44 | } else { 45 | init(); 46 | } 47 | } 48 | #else 49 | private function getConfig():GProjectConfig { 50 | var contextConfig:GContextConfig = new GContextConfig(this, new GRectangle(0,0,Screen.width,Screen.height)); 51 | return new GProjectConfig(contextConfig); 52 | } 53 | 54 | public function Start() { 55 | GDebug.info("Starting project."); 56 | onUpdate = new GCallback0(); 57 | onFrame = new GCallback0(); 58 | 59 | g2d_config = getConfig(); 60 | 61 | g2d_genome = Genome2D.getInstance(); 62 | if (g2d_config.initGenome) { 63 | initGenome(); 64 | } else { 65 | init(); 66 | } 67 | } 68 | 69 | public function Update() { 70 | onUpdate.dispatch(); 71 | } 72 | 73 | public function OnPostRender() { 74 | onFrame.dispatch(); 75 | } 76 | #end 77 | /** 78 | * Initialize Genome2D 79 | **/ 80 | private function initGenome():Void { 81 | GDebug.info("initGenome"); 82 | g2d_genome.onFailed.addOnce(genomeFailed_handler); 83 | g2d_genome.onInitialized.addOnce(genomeInitialized_handler); 84 | g2d_genome.init(g2d_config.contextConfig); 85 | } 86 | 87 | private function init():Void { 88 | } 89 | 90 | /** 91 | * Handlers 92 | **/ 93 | private function genomeInitialized_handler():Void { 94 | GDebug.info("genomeInitialized"); 95 | g2d_assetManager = new GAssetManager(); 96 | init(); 97 | } 98 | 99 | private function genomeFailed_handler(p_msg:String):Void { 100 | GDebug.error("genomeFailed", p_msg); 101 | } 102 | } -------------------------------------------------------------------------------- /src/com/genome2d/components/GComponent.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2014 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.components; 10 | 11 | import com.genome2d.proto.IGPrototypable; 12 | import com.genome2d.node.GNode; 13 | 14 | /** 15 | Component super class all components need to extend it 16 | **/ 17 | @:allow(com.genome2d.node.GNode) 18 | class GComponent implements IGPrototypable 19 | { 20 | /** 21 | Abstract reference to user defined data, if you want keep some custom data binded to component instance use it. 22 | **/ 23 | private var g2d_userData:Map; 24 | #if swc @:extern #end 25 | public var userData(get, never):Map; 26 | #if swc @:getter(userData) #end 27 | inline private function get_userData():Map { 28 | if (g2d_userData == null) g2d_userData = new Map(); 29 | return g2d_userData; 30 | } 31 | 32 | private var g2d_active:Bool = true; 33 | public function isActive():Bool { 34 | return g2d_active; 35 | } 36 | public function setActive(p_value:Bool):Void { 37 | g2d_active = p_value; 38 | } 39 | 40 | private var g2d_enabled:Bool = true; 41 | #if swc @:extern #end 42 | public var enabled(get, set):Bool; 43 | #if swc @:getter(enabled) #end 44 | inline private function get_enabled():Bool { 45 | return g2d_enabled; 46 | } 47 | #if swc @:setter(enabled) #end 48 | inline private function set_enabled(p_value:Bool):Bool { 49 | g2d_enabled = p_value; 50 | if (g2d_enabled && !g2d_started) g2d_start(); 51 | return g2d_enabled; 52 | } 53 | 54 | private var g2d_started:Bool = false; 55 | 56 | private var g2d_node:GNode; 57 | /** 58 | Component's node reference 59 | **/ 60 | #if swc @:extern #end 61 | public var node(get, never):GNode; 62 | #if swc @:getter(node) #end 63 | inline private function get_node():GNode { 64 | return g2d_node; 65 | } 66 | 67 | public function new() { 68 | } 69 | 70 | /** 71 | Abstract method called after components is initialized on the node 72 | **/ 73 | public function init():Void { 74 | } 75 | 76 | private function g2d_start():Void { 77 | if (g2d_active && !g2d_started) { 78 | g2d_started = true; 79 | onStart(); 80 | } 81 | } 82 | 83 | /** 84 | Abstract method called after components is initialized and enabled 85 | **/ 86 | public function onStart():Void { 87 | 88 | } 89 | 90 | /** 91 | Base dispose method, if there is a disposing you need to do in your extending components you should override it and always call super.dispose() its used when a node using this components is being disposed 92 | **/ 93 | public function g2d_dispose():Void { 94 | onDispose(); 95 | 96 | g2d_active = false; 97 | 98 | g2d_node = null; 99 | } 100 | 101 | public function onDispose():Void { 102 | } 103 | 104 | public function toReference():String { 105 | return null; 106 | } 107 | } -------------------------------------------------------------------------------- /src/com/genome2d/tween/GTween.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2014 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.tween; 10 | import com.genome2d.proto.GPrototype; 11 | import com.genome2d.proto.GPrototypeFactory; 12 | import com.genome2d.tween.easing.GLinear; 13 | import com.genome2d.tween.easing.GEase; 14 | 15 | @:access(com.genome2d.tween.GTweenStep) 16 | @:access(com.genome2d.tween.GTweenSequence) 17 | @:access(com.genome2d.tween.GTweenTimeline) 18 | class GTween { 19 | static public var timeScale:Float = 1.0; 20 | static public var defaultEase:GEase = GLinear.none; 21 | static public var enablePooling:Bool = true; 22 | 23 | static private var g2d_currentTimeline:GTweenTimeline; 24 | static private var g2d_timelines:Array; 25 | 26 | inline static private function removeTimeline(p_timeline:GTweenTimeline):Void { 27 | 28 | } 29 | 30 | inline static private function addTimeline(p_timeline:GTweenTimeline, p_setCurrent:Bool = false):Void { 31 | if (p_setCurrent) g2d_currentTimeline = p_timeline; 32 | if (g2d_timelines == null) g2d_timelines = new Array(); 33 | g2d_timelines.push(p_timeline); 34 | } 35 | 36 | static public function createFromSequencePrototype(p_prototype:GPrototype):GTweenStep { 37 | var sequence:GTweenSequence = cast GPrototypeFactory.createInstance(p_prototype); 38 | if (g2d_currentTimeline == null) addTimeline(new GTweenTimeline(), true); 39 | g2d_currentTimeline.addSequence(sequence); 40 | return sequence.getLastStep(); 41 | } 42 | 43 | static public function create(p_target:Dynamic, p_autoRun:Bool = true):GTweenStep { 44 | var sequence:GTweenSequence = GTweenSequence.getPoolInstance(); 45 | 46 | if (g2d_currentTimeline == null) addTimeline(new GTweenTimeline(), true); 47 | g2d_currentTimeline.addSequence(sequence); 48 | 49 | var step:GTweenStep = sequence.addStep(GTweenStep.getPoolInstance()); 50 | if (Std.is(p_target,String)) { 51 | step.targetId = p_target; 52 | } else { 53 | step.g2d_target = p_target; 54 | } 55 | 56 | if (p_autoRun) sequence.run(); 57 | 58 | return step; 59 | } 60 | 61 | static public function delay(p_time:Float, p_callback:Dynamic, p_args:Array = null):GTweenStep { 62 | return create(null).delay(p_time).onComplete(p_callback, p_args); 63 | } 64 | 65 | static public function update(p_delta:Float):Void { 66 | p_delta *= timeScale/1000; 67 | if (g2d_timelines != null) { 68 | for (timeline in g2d_timelines) { 69 | timeline.update(p_delta); 70 | } 71 | } 72 | } 73 | 74 | static public function abortAllTimelines():Void { 75 | if (g2d_timelines != null) { 76 | while (g2d_timelines.length>0) { 77 | var timeline:GTweenTimeline = g2d_timelines.shift(); 78 | timeline.abortAllSequences(); 79 | } 80 | } 81 | g2d_currentTimeline = null; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/com/genome2d/macros/MGProfilerProcessor.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.macros; 2 | 3 | #if macro 4 | class MGProfilerProcessor { 5 | static private var hasReturn:Bool; 6 | 7 | macro static public function build() : Array { 8 | var pos = Context.currentPos(); 9 | var fields = Context.getBuildFields(); 10 | 11 | #if !genome_no_profiles 12 | for (field in fields) { 13 | switch (field.kind) { 14 | case FFun(f): 15 | var metaIndex:Int = getProfileMeta(field.meta); 16 | if (metaIndex>=0) { 17 | // Store the pos info as it will be overwriten by the macro 18 | var currentPos = f.expr.pos; 19 | f.expr = macro { 20 | @:pos(currentPos) com.genome2d.debug.GProfiler.startMethodProfile(); 21 | ${f.expr}; 22 | }; 23 | 24 | hasReturn = false; 25 | f.expr = remapReturn(f.expr); 26 | 27 | if (!hasReturn) { 28 | f.expr = macro { 29 | ${f.expr}; 30 | @:pos(currentPos) com.genome2d.debug.GProfiler.endMethodProfile(); 31 | } 32 | } 33 | // We will restore the pos info, it can be usefull for other build macros such as debug 34 | f.expr.pos = currentPos; 35 | } 36 | case _: 37 | } 38 | } 39 | #end 40 | return fields; 41 | } 42 | 43 | static public function remapReturn(expr) { 44 | return 45 | switch (expr.expr) { 46 | case EReturn(e): 47 | hasReturn = true; 48 | if (e == null) { 49 | macro { 50 | @pos(expr.pos) com.genome2d.debug.GProfiler.endMethodProfile(); 51 | return; 52 | } 53 | } else { 54 | macro { 55 | var ___temp = ${e}; 56 | @:pos(expr.pos) com.genome2d.debug.GProfiler.endMethodProfile(); 57 | return ___temp; 58 | } 59 | } 60 | case _: 61 | ExprTools.map(expr,remapReturn); 62 | } 63 | } 64 | 65 | static public function getProfileMeta(p_meta:Array):Int { 66 | for (i in 0...p_meta.length) { 67 | if (p_meta[i].name == "genome_profile") return i; 68 | } 69 | return -1; 70 | } 71 | 72 | static public function getProfileMetaParam(p_meta:Array):Int { 73 | for (meta in p_meta) { 74 | if (meta.params.length>0) { 75 | switch (meta.params[0].expr) { 76 | case EConst(c): 77 | switch(c) { 78 | case CIdent(s): 79 | default: 80 | } 81 | default: 82 | } 83 | } 84 | } 85 | 86 | return 0; 87 | } 88 | } 89 | #end -------------------------------------------------------------------------------- /src/com/genome2d/text/GFontManager.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2014 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.text; 10 | import com.genome2d.debug.GDebug; 11 | import com.genome2d.textures.GTexture; 12 | 13 | class GFontManager 14 | { 15 | static private function g2d_addFont(p_font:GFont):Void { 16 | if (p_font.id == null || p_font.id.length == 0) GDebug.error("Invalid font id"); 17 | if (g2d_fonts.exists(p_font.id)) GDebug.error("Duplicate font id: "+p_font.id); 18 | g2d_fonts.set(p_font.id, p_font); 19 | } 20 | 21 | static private function g2d_removeFont(p_font:GFont):Void { 22 | if (p_font.id == null) { 23 | return; 24 | } 25 | 26 | g2d_fonts.remove(p_font.id); 27 | } 28 | 29 | static private var g2d_fonts:Map; 30 | static public function getAllFonts():Map { 31 | return g2d_fonts; 32 | } 33 | 34 | static public function init():Void { 35 | g2d_fonts = new Map(); 36 | } 37 | 38 | static public function getFont(p_id:String):GFont { 39 | return g2d_fonts.get(p_id); 40 | } 41 | 42 | static public function createTextureFont(p_id:String, p_texture:GTexture, p_fontXml:Xml, p_regionOffsetX:Int = 0, p_regionOffsetY:Int = 0):GTextureFont { 43 | var textureFont:GTextureFont = new GTextureFont(); 44 | textureFont.id = p_id; 45 | textureFont.texture = p_texture; 46 | textureFont.regionOffsetX = p_regionOffsetX; 47 | textureFont.regionOffsetY = p_regionOffsetY; 48 | 49 | textureFont.addCharsFromXml(p_fontXml); 50 | 51 | return textureFont; 52 | } 53 | 54 | /* 55 | static public function createFromFont(p_id:String, p_textFormat:TextFormat, p_chars:String, p_embedded:Bool = true, p_horizontalPadding:Int = 0, p_verticalPadding:Int = 0, p_filters:Array = null, p_forceMod2:Bool = false, p_format:String = "bgra"):GTextureAtlas { 56 | var text:TextField = GParameters TextField(); 57 | text.embedFonts = p_embedded; 58 | text.defaultTextFormat = p_textFormat; 59 | text.multiline = false; 60 | text.autoSize = TextFieldAutoSize.LEFT; 61 | 62 | if (p_filters != null) { 63 | text.filters = p_filters; 64 | } 65 | 66 | var bitmaps:Array = GParameters Array(); 67 | var ids:Array = GParameters Array(); 68 | var matrix:Matrix = GParameters Matrix(); 69 | matrix.translate(p_horizontalPadding, p_verticalPadding); 70 | 71 | for (i in 0...p_chars.length) { 72 | text.text = p_chars.charAt(i); 73 | var width:Float = (text.width%2 != 0 && p_forceMod2) ? text.width+1 : text.width; 74 | var height:Float = (text.height%2 != 0 && p_forceMod2) ? text.height+1 : text.height; 75 | var bitmapData:BitmapData = GParameters BitmapData(untyped __int__(width+p_horizontalPadding*2), untyped __int__(height+p_verticalPadding*2), true, 0x0); 76 | bitmapData.draw(text, matrix); 77 | bitmaps.push(bitmapData); 78 | 79 | untyped ids.push(String(p_chars.charCodeAt(i))); 80 | } 81 | 82 | return createFromBitmapDatas(p_id, bitmaps, ids, p_format); 83 | } 84 | /* 85 | */ 86 | } -------------------------------------------------------------------------------- /src/com/genome2d/deprecated/particles/GParticleD.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2014 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.deprecated.particles; 10 | 11 | import com.genome2d.deprecated.components.renderable.particles.GParticleSystemD; 12 | import com.genome2d.context.GCamera; 13 | import com.genome2d.textures.GTexture; 14 | 15 | /** 16 | Particle element class used by `GParticlePool` and `GParticleSystem` 17 | **/ 18 | @:allow(com.genome2d.deprecated.particles.GParticlePoolD) 19 | @:allow(com.genome2d.deprecated.components.renderable.particles.GParticleSystem) 20 | class GParticleD 21 | { 22 | public var texture:GTexture; 23 | 24 | public var overrideRender:Bool = false; 25 | 26 | public var scaleX:Float; 27 | public var scaleY:Float; 28 | 29 | public var x:Float = 0; 30 | public var y:Float = 0; 31 | public var rotation:Float = 0; 32 | public var red:Float = 1; 33 | public var green:Float = 1; 34 | public var blue:Float = 1; 35 | public var alpha:Float = 1; 36 | 37 | public var velocityX:Float = 0; 38 | public var velocityY:Float = 0; 39 | 40 | public var totalEnergy:Float = 0; 41 | public var accumulatedEnergy:Float = 0; 42 | 43 | public var accumulatedTime:Float; 44 | public var currentFrame:Float; 45 | 46 | public var overrideUvs:Bool = false; 47 | public var uvX:Float; 48 | public var uvY:Float; 49 | public var uvScaleX:Float; 50 | public var uvScaleY:Float; 51 | 52 | public var die:Bool = false; 53 | 54 | private var g2d_next:GParticleD; 55 | private var g2d_previous:GParticleD; 56 | #if swc @:extern #end 57 | public var previous(get, never):GParticleD; 58 | #if swc @:getter(previous) #end 59 | inline private function get_previous():GParticleD { 60 | return g2d_previous; 61 | } 62 | 63 | private var g2d_nextAvailableInstance:GParticleD; 64 | 65 | public var index:Int = 0; 66 | private var g2d_pool:GParticlePoolD; 67 | 68 | @:dox(hide) 69 | public function new(p_pool:GParticlePoolD):Void { 70 | g2d_pool = p_pool; 71 | index = g2d_pool.g2d_count; 72 | } 73 | 74 | @:dox(hide) 75 | public function spawn(p_particleSystem:GParticleSystemD):Void { 76 | texture = p_particleSystem.texture; 77 | x = p_particleSystem.node.g2d_worldX; 78 | y = p_particleSystem.node.g2d_worldY; 79 | scaleX = scaleY = 1; 80 | rotation = 0; 81 | velocityX = 0; 82 | velocityY = 0; 83 | totalEnergy = 0; 84 | accumulatedEnergy = 0; 85 | red = 1; 86 | green = 1; 87 | blue = 1; 88 | alpha = 1; 89 | 90 | accumulatedTime = 0; 91 | currentFrame = 0; 92 | } 93 | 94 | @:dox(hide) 95 | public function dispose():Void { 96 | die = false; 97 | if (g2d_next != null) g2d_next.g2d_previous = g2d_previous; 98 | if (g2d_previous != null) g2d_previous.g2d_next = g2d_next; 99 | g2d_next = null; 100 | g2d_previous = null; 101 | g2d_nextAvailableInstance = g2d_pool.g2d_availableInstance; 102 | g2d_pool.g2d_availableInstance = this; 103 | } 104 | 105 | public function render(p_camera:GCamera, p_particleSystem:GParticleSystemD):Void {} 106 | } -------------------------------------------------------------------------------- /src/com/genome2d/ui/element/GUIInputField.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2015 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.ui.element; 10 | import com.genome2d.input.GFocusManager; 11 | import com.genome2d.input.GKeyboardInput; 12 | import com.genome2d.input.GKeyboardInputType; 13 | import com.genome2d.ui.skin.GUIFontSkin; 14 | 15 | class GUIInputField extends GUIElement 16 | { 17 | public function new(p_skin:GUIFontSkin) { 18 | super(p_skin); 19 | 20 | cast (g2d_activeSkin,GUIFontSkin).textRenderer.enableCursor = true; 21 | 22 | Genome2D.getInstance().onKeyboardInput.add(keyboardInput_handler); 23 | } 24 | 25 | private function keyboardInput_handler(input:GKeyboardInput):Void { 26 | if (GFocusManager.hasFocus(this) && input.type == GKeyboardInputType.KEY_DOWN && g2d_activeSkin != null) { 27 | var skin:GUIFontSkin = cast g2d_activeSkin; 28 | switch (input.keyCode) { 29 | // ENTER 30 | case 1315251: 31 | var newValue:String = g2d_model.substring(0, skin.cursorStartIndex); 32 | newValue += String.fromCharCode(input.charCode); 33 | newValue += g2d_model.substring(skin.cursorEndIndex, g2d_model.length); 34 | model = newValue; 35 | // BACKSPACE 36 | case 8: 37 | if (skin.cursorStartIndex != skin.cursorEndIndex) { 38 | var newValue:String = g2d_model.substring(0, skin.cursorStartIndex); 39 | newValue += g2d_model.substring(skin.cursorEndIndex, g2d_model.length); 40 | model = newValue; 41 | skin.cursorStartIndex = skin.cursorEndIndex = skin.cursorStartIndex; 42 | } else { 43 | var newValue:String = g2d_model.substring(0, skin.cursorStartIndex-1); 44 | newValue += g2d_model.substring(skin.cursorEndIndex, g2d_model.length); 45 | model = newValue; 46 | skin.cursorStartIndex = skin.cursorEndIndex = skin.cursorStartIndex>0?skin.cursorStartIndex-1:0; 47 | } 48 | // DELETE 49 | case 46: 50 | if (skin.cursorStartIndex != skin.cursorEndIndex) { 51 | var newValue:String = g2d_model.substring(0, skin.cursorStartIndex); 52 | newValue += g2d_model.substring(skin.cursorEndIndex, g2d_model.length); 53 | model = newValue; 54 | skin.cursorStartIndex = skin.cursorEndIndex = skin.cursorStartIndex; 55 | } else { 56 | var newValue:String = g2d_model.substring(0, skin.cursorStartIndex); 57 | newValue += g2d_model.substring(skin.cursorEndIndex+1, g2d_model.length); 58 | model = newValue; 59 | } 60 | // RIGHT ARROW 61 | case 39: 62 | if (skin.cursorStartIndex == skin.cursorEndIndex) { 63 | skin.cursorStartIndex = skin.cursorEndIndex = skin.cursorStartIndex + 1; 64 | } else { 65 | skin.cursorStartIndex = skin.cursorEndIndex; 66 | } 67 | // LEFT ARROW 68 | case 37: 69 | if (skin.cursorStartIndex == skin.cursorEndIndex) { 70 | skin.cursorStartIndex = skin.cursorEndIndex = skin.cursorStartIndex - 1; 71 | } else { 72 | skin.cursorEndIndex = skin.cursorStartIndex; 73 | } 74 | case 16: 75 | case _: 76 | if (input.charCode != 0) { 77 | var newValue:String = g2d_model.substring(0, skin.cursorStartIndex); 78 | newValue += String.fromCharCode(input.charCode); 79 | newValue += g2d_model.substring(skin.cursorEndIndex, g2d_model.length); 80 | model = newValue; 81 | skin.cursorStartIndex = skin.cursorEndIndex = skin.cursorStartIndex + 1; 82 | } 83 | } 84 | } 85 | } 86 | } -------------------------------------------------------------------------------- /src/com/genome2d/node/GNodePool.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2014 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.node; 10 | import com.genome2d.proto.GPrototypeFactory; 11 | import com.genome2d.proto.GPrototype; 12 | 13 | /** 14 | Node pool based on proto 15 | **/ 16 | @:access(com.genome2d.node.GNode) 17 | class GNodePool 18 | { 19 | private var g2d_first:GNode; 20 | private var g2d_last:GNode; 21 | 22 | private var g2d_prototype:GPrototype; 23 | 24 | private var g2d_maxCount:Int; 25 | 26 | private var g2d_cachedCount:Int = 0; 27 | public function getCachedCount():Int { 28 | return g2d_cachedCount; 29 | } 30 | 31 | public function new(p_prototype:GPrototype, p_maxCount:Int = 0, p_precacheCount:Int = 0) { 32 | g2d_prototype = p_prototype; 33 | g2d_maxCount = p_maxCount; 34 | 35 | for (i in 0...p_precacheCount) { 36 | g2d_createNew(true); 37 | } 38 | } 39 | 40 | public function getNext():GNode { 41 | var node:GNode; 42 | 43 | if (g2d_first == null || g2d_first.isActive()) { 44 | node = g2d_createNew(); 45 | } else { 46 | node = g2d_first; 47 | g2d_putToBack(node); 48 | node.setActive(true); 49 | } 50 | return node; 51 | } 52 | 53 | public function recycle(p_node:GNode, p_reset:Bool = false):Void { 54 | p_node.setActive(false); 55 | p_node.bindPrototype(g2d_prototype); 56 | g2d_putToFront(p_node); 57 | } 58 | 59 | private function g2d_putToFront(p_node:GNode):Void { 60 | if (p_node == g2d_first) return; 61 | 62 | if (p_node.g2d_poolNext != null) p_node.g2d_poolNext.g2d_poolPrevious = p_node.g2d_poolPrevious; 63 | if (p_node.g2d_poolPrevious != null) p_node.g2d_poolPrevious.g2d_poolNext = p_node.g2d_poolNext; 64 | if (p_node == g2d_last) g2d_last = g2d_last.g2d_poolPrevious; 65 | 66 | if (g2d_first != null) g2d_first.g2d_poolPrevious = p_node; 67 | p_node.g2d_poolPrevious = null; 68 | p_node.g2d_poolNext = g2d_first; 69 | g2d_first = p_node; 70 | } 71 | 72 | private function g2d_putToBack(p_node:GNode):Void { 73 | if (p_node == g2d_last) return; 74 | 75 | if (p_node.g2d_poolNext != null) p_node.g2d_poolNext.g2d_poolPrevious = p_node.g2d_poolPrevious; 76 | if (p_node.g2d_poolPrevious != null) p_node.g2d_poolPrevious.g2d_poolNext = p_node.g2d_poolNext; 77 | if (p_node == g2d_first) g2d_first = g2d_first.g2d_poolNext; 78 | 79 | if (g2d_last != null) g2d_last.g2d_poolNext = p_node; 80 | p_node.g2d_poolPrevious = g2d_last; 81 | p_node.g2d_poolNext = null; 82 | g2d_last = p_node; 83 | } 84 | 85 | private function g2d_createNew(p_precache:Bool = false):GNode { 86 | var node:GNode = null; 87 | if (g2d_maxCount == 0 || g2d_cachedCount < g2d_maxCount) { 88 | g2d_cachedCount++; 89 | node = GPrototypeFactory.createInstance(g2d_prototype); 90 | if (p_precache) node.setActive(false); 91 | node.g2d_pool = this; 92 | 93 | if (g2d_first == null) { 94 | g2d_first = node; 95 | g2d_last = node; 96 | } else { 97 | node.g2d_poolPrevious = g2d_last; 98 | g2d_last.g2d_poolNext = node; 99 | g2d_last = node; 100 | } 101 | } 102 | 103 | return node; 104 | } 105 | 106 | public function dispose():Void { 107 | while (g2d_first != null) { 108 | var next:GNode = g2d_first.g2d_poolNext; 109 | g2d_first.dispose(); 110 | g2d_first = next; 111 | } 112 | } 113 | } -------------------------------------------------------------------------------- /src/com/genome2d/components/renderable/GShape.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2014 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.components.renderable; 10 | 11 | import com.genome2d.context.IGRenderer; 12 | import com.genome2d.input.GMouseInput; 13 | import com.genome2d.debug.GDebug; 14 | import com.genome2d.geom.GRectangle; 15 | import com.genome2d.context.GBlendMode; 16 | import com.genome2d.context.GCamera; 17 | import com.genome2d.textures.GTexture; 18 | 19 | /** 20 | Component used for shape rendering 21 | **/ 22 | class GShape extends GComponent implements IGRenderable 23 | { 24 | public var texture:GTexture; 25 | public var blendMode:GBlendMode; 26 | 27 | private var g2d_vertices:Array; 28 | private var g2d_uvs:Array; 29 | 30 | private var g2d_shapeRenderer:IGRenderer; 31 | private var g2d_bounds:GRectangle; 32 | 33 | override public function init():Void { 34 | blendMode = GBlendMode.NORMAL; 35 | 36 | g2d_bounds = new GRectangle(0,0,0,0); 37 | } 38 | 39 | public function render(p_camera:GCamera, p_useMatrix:Bool):Void { 40 | if (texture == null || g2d_vertices == null || g2d_uvs == null) return; 41 | if (g2d_shapeRenderer == null) { 42 | node.core.getContext().drawPoly(texture, blendMode, g2d_vertices, g2d_uvs, node.g2d_worldX, node.g2d_worldY, node.g2d_worldScaleX, node.g2d_worldScaleY, node.g2d_worldRotation, node.g2d_worldRed, node.g2d_worldGreen, node.g2d_worldBlue, node.g2d_worldAlpha, null); 43 | } else { 44 | node.core.getContext().setRenderer(g2d_shapeRenderer); 45 | untyped g2d_shapeRenderer.draw(texture); 46 | } 47 | } 48 | 49 | public function setup(p_vertices:Array, p_uvs:Array, p_calculateBounds:Bool = true):Void { 50 | if (p_vertices == null || p_uvs == null) GDebug.error("Vertices and UVs can't be null."); 51 | if (p_vertices.length == 0) GDebug.error("Shape can't have 0 vertices."); 52 | if (p_vertices.length != p_uvs.length) GDebug.error("Vertices and UVs need to have same amount of values."); 53 | g2d_vertices = p_vertices; 54 | // Calculate bounds 55 | if (p_calculateBounds) { 56 | for (i in 0...g2d_vertices.length>>1) { 57 | var vx:Float = g2d_vertices[i*2]; 58 | var vy:Float = g2d_vertices[i*2+1]; 59 | if (vxg2d_bounds.right) g2d_bounds.right = vx; 61 | if (vyg2d_bounds.bottom) g2d_bounds.bottom = vy; 63 | } 64 | } 65 | 66 | g2d_uvs = p_uvs; 67 | } 68 | 69 | public function cache():Void { 70 | //g2d_shapeRenderer = new GCustomRenderer(g2d_vertices, g2d_uvs, false); 71 | } 72 | 73 | public function getBounds(p_bounds:GRectangle = null):GRectangle { 74 | if (p_bounds != null) { 75 | p_bounds.setTo(g2d_bounds.x, g2d_bounds.y, g2d_bounds.width, g2d_bounds.height); 76 | } else { 77 | p_bounds = g2d_bounds.clone(); 78 | } 79 | 80 | return p_bounds; 81 | } 82 | 83 | public function captureMouseInput(p_input:GMouseInput):Void { 84 | p_input.captured = p_input.captured || hitTest(p_input.localX, p_input.localY); 85 | } 86 | 87 | public function hitTest(p_x:Float, p_y:Float):Bool { 88 | var hit:Bool = g2d_bounds.contains(p_x, p_y); 89 | 90 | return hit; 91 | } 92 | } -------------------------------------------------------------------------------- /src/com/genome2d/macros/MGDebug.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.macros; 2 | 3 | import haxe.macro.Expr; 4 | 5 | class MGDebug { 6 | macro static public function DUMP(?p_arg1, ?p_arg2, ?p_arg3, ?p_arg4, ?p_arg5, ?p_arg6, ?p_arg7, ?p_arg8, ?p_arg9, ?p_arg10, ?p_arg11, ?p_arg12, ?p_arg13, ?p_arg14, ?p_arg15, ?p_arg16, ?p_arg17, ?p_arg18, ?p_arg19, ?p_arg20) { 7 | #if genome_debug 8 | return macro @:pos(p_arg1.pos) com.genome2d.debug.GDebug.dump($p_arg1, $p_arg2, $p_arg3, $p_arg4, $p_arg5, $p_arg6, $p_arg7, $p_arg8, $p_arg9, $p_arg10, $p_arg11, $p_arg12, $p_arg13, $p_arg14, $p_arg15, $p_arg16, $p_arg17, $p_arg18, $p_arg19, $p_arg20); 9 | #else 10 | return macro null; 11 | #end 12 | } 13 | 14 | macro static public function INFO(?p_arg1, ?p_arg2, ?p_arg3, ?p_arg4, ?p_arg5, ?p_arg6, ?p_arg7, ?p_arg8, ?p_arg9, ?p_arg10, ?p_arg11, ?p_arg12, ?p_arg13, ?p_arg14, ?p_arg15, ?p_arg16, ?p_arg17, ?p_arg18, ?p_arg19, ?p_arg20) { 15 | return macro @:pos(p_arg1.pos) com.genome2d.debug.GDebug.info($p_arg1, $p_arg2, $p_arg3, $p_arg4, $p_arg5, $p_arg6, $p_arg7, $p_arg8, $p_arg9, $p_arg10, $p_arg11, $p_arg12, $p_arg13, $p_arg14, $p_arg15, $p_arg16, $p_arg17, $p_arg18, $p_arg19, $p_arg20); 16 | } 17 | 18 | macro static public function EDITOR(?p_arg1, ?p_arg2, ?p_arg3, ?p_arg4, ?p_arg5, ?p_arg6, ?p_arg7, ?p_arg8, ?p_arg9, ?p_arg10, ?p_arg11, ?p_arg12, ?p_arg13, ?p_arg14, ?p_arg15, ?p_arg16, ?p_arg17, ?p_arg18, ?p_arg19, ?p_arg20) { 19 | return macro @:pos(p_arg1.pos) com.genome2d.debug.GDebug.editor($p_arg1, $p_arg2, $p_arg3, $p_arg4, $p_arg5, $p_arg6, $p_arg7, $p_arg8, $p_arg9, $p_arg10, $p_arg11, $p_arg12, $p_arg13, $p_arg14, $p_arg15, $p_arg16, $p_arg17, $p_arg18, $p_arg19, $p_arg20); 20 | } 21 | 22 | macro static public function WARNING(?p_arg1, ?p_arg2, ?p_arg3, ?p_arg4, ?p_arg5, ?p_arg6, ?p_arg7, ?p_arg8, ?p_arg9, ?p_arg10, ?p_arg11, ?p_arg12, ?p_arg13, ?p_arg14, ?p_arg15, ?p_arg16, ?p_arg17, ?p_arg18, ?p_arg19, ?p_arg20) { 23 | return macro @:pos(p_arg1.pos) com.genome2d.debug.GDebug.warning($p_arg1, $p_arg2, $p_arg3, $p_arg4, $p_arg5, $p_arg6, $p_arg7, $p_arg8, $p_arg9, $p_arg10, $p_arg11, $p_arg12, $p_arg13, $p_arg14, $p_arg15, $p_arg16, $p_arg17, $p_arg18, $p_arg19, $p_arg20); 24 | } 25 | 26 | macro static public function G2D_WARNING(?p_arg1, ?p_arg2, ?p_arg3, ?p_arg4, ?p_arg5, ?p_arg6, ?p_arg7, ?p_arg8, ?p_arg9, ?p_arg10, ?p_arg11, ?p_arg12, ?p_arg13, ?p_arg14, ?p_arg15, ?p_arg16, ?p_arg17, ?p_arg18, ?p_arg19, ?p_arg20) { 27 | return macro @:pos(p_arg1.pos) com.genome2d.debug.GDebug.g2d_warning($p_arg1, $p_arg2, $p_arg3, $p_arg4, $p_arg5, $p_arg6, $p_arg7, $p_arg8, $p_arg9, $p_arg10, $p_arg11, $p_arg12, $p_arg13, $p_arg14, $p_arg15, $p_arg16, $p_arg17, $p_arg18, $p_arg19, $p_arg20); 28 | } 29 | 30 | macro static public function ERROR(?p_arg1, ?p_arg2, ?p_arg3, ?p_arg4, ?p_arg5, ?p_arg6, ?p_arg7, ?p_arg8, ?p_arg9, ?p_arg10, ?p_arg11, ?p_arg12, ?p_arg13, ?p_arg14, ?p_arg15, ?p_arg16, ?p_arg17, ?p_arg18, ?p_arg19, ?p_arg20) { 31 | return macro @:pos(p_arg1.pos) com.genome2d.debug.GDebug.error($p_arg1, $p_arg2, $p_arg3, $p_arg4, $p_arg5, $p_arg6, $p_arg7, $p_arg8, $p_arg9, $p_arg10, $p_arg11, $p_arg12, $p_arg13, $p_arg14, $p_arg15, $p_arg16, $p_arg17, $p_arg18, $p_arg19, $p_arg20); 32 | } 33 | 34 | macro static public function G2D_ERROR(?p_arg1, ?p_arg2, ?p_arg3, ?p_arg4, ?p_arg5, ?p_arg6, ?p_arg7, ?p_arg8, ?p_arg9, ?p_arg10, ?p_arg11, ?p_arg12, ?p_arg13, ?p_arg14, ?p_arg15, ?p_arg16, ?p_arg17, ?p_arg18, ?p_arg19, ?p_arg20) { 35 | return macro @:pos(p_arg1.pos) com.genome2d.debug.GDebug.g2d_error($p_arg1, $p_arg2, $p_arg3, $p_arg4, $p_arg5, $p_arg6, $p_arg7, $p_arg8, $p_arg9, $p_arg10, $p_arg11, $p_arg12, $p_arg13, $p_arg14, $p_arg15, $p_arg16, $p_arg17, $p_arg18, $p_arg19, $p_arg20); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/com/genome2d/particles/GParticle.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2014 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.particles; 10 | 11 | import com.genome2d.context.GBlendMode; 12 | import com.genome2d.context.IGContext; 13 | import com.genome2d.textures.GTexture; 14 | 15 | /** 16 | Particle class 17 | **/ 18 | @:allow(com.genome2d.particles.GParticlePool) 19 | @:allow(com.genome2d.particles.GParticleEmitter) 20 | class GParticle 21 | { 22 | // SPH Properties 23 | public var fluidX:Float = 0; 24 | public var fluidY:Float = 0; 25 | public var viscosity:Float = .1; 26 | public var gridX:Int = 0; 27 | public var gridY:Int = 0; 28 | public var density:Float = 0; 29 | public var densityNear:Float = 0; 30 | public var fixed:Bool = false; 31 | public var type:Int = 0; 32 | public var group:GParticleGroup; 33 | 34 | public var implementRender:Bool = false; 35 | 36 | // Transform 37 | public var x:Float = 0; 38 | public var y:Float = 0; 39 | public var scaleX:Float; 40 | public var scaleY:Float; 41 | public var rotation:Float = 0; 42 | // Render 43 | public var red:Float = 1; 44 | public var green:Float = 1; 45 | public var blue:Float = 1; 46 | public var alpha:Float = 1; 47 | public var texture:GTexture; 48 | public var blendMode:GBlendMode; 49 | 50 | // Dynamics 51 | public var velocityX:Float = 0; 52 | public var velocityY:Float = 0; 53 | 54 | public var totalEnergy:Float = 0; 55 | public var accumulatedEnergy:Float = 0; 56 | 57 | public var accumulatedTime:Float; 58 | public var currentFrame:Float; 59 | 60 | public var die:Bool = false; 61 | 62 | private var g2d_next:GParticle; 63 | private var g2d_previous:GParticle; 64 | #if swc @:extern #end 65 | public var previous(get, never):GParticle; 66 | #if swc @:getter(previous) #end 67 | inline private function get_previous():GParticle { 68 | return g2d_previous; 69 | } 70 | 71 | private var g2d_nextAvailableInstance:GParticle; 72 | 73 | public var index:Int = 0; 74 | private var g2d_pool:GParticlePool; 75 | 76 | static public var g2d_instanceId:Int = 0; 77 | public var instanceId:Int; 78 | @:dox(hide) 79 | public function new(p_pool:GParticlePool):Void { 80 | instanceId = g2d_instanceId++; 81 | g2d_pool = p_pool; 82 | index = g2d_pool.g2d_count; 83 | 84 | blendMode = GBlendMode.NORMAL; 85 | } 86 | 87 | private function g2d_spawn(p_emitter:GParticleEmitter):Void { 88 | fluidX = fluidY = velocityX = velocityY = 0; 89 | fixed = false; 90 | 91 | texture = p_emitter.texture; 92 | if (p_emitter.useWorldSpace) { 93 | x = p_emitter.getParticleSystem().x + p_emitter.x * p_emitter.getParticleSystem().scaleY; 94 | y = p_emitter.getParticleSystem().y + p_emitter.y * p_emitter.getParticleSystem().scaleX; 95 | } else { 96 | x = 0; 97 | y = 0; 98 | } 99 | scaleX = scaleY = 1; 100 | rotation = 0; 101 | totalEnergy = 0; 102 | accumulatedEnergy = 0; 103 | red = 1; 104 | green = 1; 105 | blue = 1; 106 | alpha = 1; 107 | 108 | accumulatedTime = 0; 109 | currentFrame = 0; 110 | } 111 | 112 | private function g2d_render(p_context:IGContext, p_emitter:GParticleEmitter):Void { } 113 | 114 | private function g2d_dispose():Void { 115 | group = null; 116 | die = false; 117 | if (g2d_next != null) g2d_next.g2d_previous = g2d_previous; 118 | if (g2d_previous != null) g2d_previous.g2d_next = g2d_next; 119 | g2d_next = null; 120 | g2d_previous = null; 121 | g2d_nextAvailableInstance = g2d_pool.g2d_availableInstance; 122 | g2d_pool.g2d_availableInstance = this; 123 | } 124 | } -------------------------------------------------------------------------------- /src/com/genome2d/ui/layout/GUIHorizontalLayout.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2015 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.ui.layout; 10 | 11 | import com.genome2d.ui.element.GUIElement; 12 | 13 | @:access(com.genome2d.ui.element.GUIElement) 14 | @prototypeName("horizontal") 15 | class GUIHorizontalLayout extends GUILayout { 16 | @prototype 17 | public var gap:Float = 0; 18 | 19 | @prototype 20 | public var useChildrenHeight:Bool = false; 21 | 22 | @prototype 23 | public var skipLastGap:Bool = false; 24 | 25 | @prototype 26 | public var skipInvisibleChildren:Bool = false; 27 | 28 | public function new() { 29 | type = GUILayoutType.HORIZONTAL; 30 | } 31 | 32 | override private function calculateWidth(p_element:GUIElement):Void { 33 | p_element.g2d_preferredWidth = p_element.g2d_minWidth = 0; 34 | var layoutGap:Float = gap; 35 | 36 | for (i in 0...p_element.g2d_numChildren) { 37 | var child:GUIElement = p_element.g2d_children[i]; 38 | 39 | if (skipInvisibleChildren && !child.visible) continue; 40 | 41 | child.calculateWidth(); 42 | 43 | if (skipLastGap == true && i >= p_element.g2d_numChildren - 1) { 44 | layoutGap = 0; 45 | } 46 | 47 | p_element.g2d_minWidth += child.g2d_minWidth + layoutGap; 48 | p_element.g2d_preferredWidth += ((child.g2d_preferredWidth>child.g2d_minWidth)?child.g2d_preferredWidth:child.g2d_minWidth) + layoutGap; 49 | } 50 | } 51 | 52 | override private function invalidateWidth(p_element:GUIElement):Void { 53 | var offsetX:Float = 0; 54 | var rest:Float = p_element.g2d_finalWidth - p_element.g2d_minWidth; 55 | if (rest<0) rest = 0; 56 | var layoutGap:Float = gap; 57 | for (i in 0...p_element.g2d_numChildren) { 58 | var child:GUIElement = p_element.g2d_children[i]; 59 | 60 | if (skipInvisibleChildren && !child.visible) continue; 61 | 62 | child.g2d_worldLeft = p_element.g2d_worldLeft + offsetX; 63 | // Left priority rest space distribution 64 | var childDif:Float = (child.g2d_preferredWidth > child.g2d_minWidth)?child.g2d_preferredWidth - child.g2d_minWidth:0; 65 | childDif = rest < childDif?rest:childDif; 66 | rest -= childDif; 67 | child.g2d_worldRight = child.g2d_worldLeft + child.g2d_minWidth + childDif;//rest/p_element.g2d_numChildren; 68 | child.g2d_finalWidth = child.g2d_worldRight - child.g2d_worldLeft; 69 | 70 | if (skipLastGap == true && i >= p_element.g2d_numChildren - 1) { 71 | layoutGap = 0; 72 | } 73 | 74 | offsetX += child.g2d_finalWidth + layoutGap; 75 | 76 | child.invalidateWidth(); 77 | } 78 | } 79 | 80 | override private function calculateHeight(p_element:GUIElement):Void { 81 | p_element.g2d_preferredHeight = p_element.g2d_minHeight = 0; 82 | 83 | for (i in 0...p_element.g2d_numChildren) { 84 | var child:GUIElement = p_element.g2d_children[i]; 85 | child.calculateHeight(); 86 | 87 | p_element.g2d_minHeight = p_element.g2d_minHeight < child.g2d_minHeight ? child.g2d_minHeight : p_element.g2d_minHeight; 88 | if (useChildrenHeight == true) { 89 | p_element.g2d_preferredHeight = p_element.g2d_preferredHeight < child.g2d_preferredHeight ? child.g2d_preferredHeight : p_element.g2d_preferredHeight; 90 | } 91 | } 92 | } 93 | 94 | override private function invalidateHeight(p_element:GUIElement):Void { 95 | for (i in 0...p_element.g2d_numChildren) { 96 | var child:GUIElement = p_element.g2d_children[i]; 97 | child.invalidateHeight(); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/com/genome2d/postprocess/GBloomPP.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2014 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.postprocess; 10 | 11 | import com.genome2d.context.GBlendMode; 12 | import com.genome2d.utils.GRenderTargetStack; 13 | import com.genome2d.context.IGContext; 14 | import com.genome2d.node.GNode; 15 | import com.genome2d.context.GCamera; 16 | import com.genome2d.geom.GRectangle; 17 | #if flash 18 | import com.genome2d.context.filters.GBloomPassFilter; 19 | import com.genome2d.context.filters.GBrightPassFilter; 20 | #end 21 | import com.genome2d.textures.GTexture; 22 | 23 | class GBloomPP extends GPostProcess 24 | { 25 | #if flash 26 | private var g2d_blur:GBlurPP; 27 | private var g2d_bright:GFilterPP; 28 | private var g2d_bloomFilter:GBloomPassFilter; 29 | 30 | public function new(p_blurX:Int = 2, p_blurY:Int = 2, p_blurPasses:Int = 1, p_brightTreshold:Float=.2) { 31 | super(2); 32 | 33 | g2d_blur = new GBlurPP(p_blurX, p_blurY, p_blurPasses); 34 | 35 | g2d_bright = new GFilterPP([new GBrightPassFilter(p_brightTreshold)]); 36 | 37 | g2d_bloomFilter = new GBloomPassFilter(); 38 | 39 | g2d_leftMargin = g2d_rightMargin = Std.int(g2d_blur.blurX*g2d_blur.passes*.5); 40 | g2d_topMargin = g2d_bottomMargin = Std.int(g2d_blur.blurY*g2d_blur.passes*.5); 41 | g2d_bright.setMargins(g2d_leftMargin, g2d_rightMargin, g2d_topMargin, g2d_bottomMargin); 42 | } 43 | 44 | override public function render(p_source:GTexture, p_x:Float, p_y:Float, p_bounds:GRectangle = null, p_target:GTexture = null):Void { 45 | var bounds:GRectangle = (p_bounds == null) ? bounds : p_bounds; 46 | 47 | // Invalid bounds 48 | if (bounds.width > 4096) return; 49 | 50 | updatePassTextures(bounds); 51 | 52 | var context:IGContext = Genome2D.getInstance().getContext(); 53 | 54 | if (p_target == null) GRenderTargetStack.pushRenderTarget(context.getRenderTarget(), context.getRenderTargetMatrix()); 55 | 56 | g2d_bright.render(p_source, p_x, p_y, bounds, g2d_passTextures[0]); 57 | g2d_blur.render(g2d_passTextures[0], 0, 0, bounds, g2d_passTextures[1]); 58 | 59 | g2d_bloomFilter.texture = g2d_bright.getPassTexture(0); 60 | if (p_target == null) { 61 | GRenderTargetStack.popRenderTarget(context); 62 | context.draw(g2d_passTextures[1], GBlendMode.NORMAL, bounds.x-g2d_leftMargin, bounds.y-g2d_topMargin, 1, 1, 0, 1, 1, 1, 1, g2d_bloomFilter); 63 | } else { 64 | context.setRenderTarget(p_target); 65 | context.draw(g2d_passTextures[1], GBlendMode.NORMAL, bounds.x-g2d_leftMargin, bounds.y-g2d_topMargin, 1, 1, 0, 1, 1, 1, 1, g2d_bloomFilter); 66 | } 67 | } 68 | 69 | override public function renderNode(p_parentTransformUpdate:Bool, p_parentColorUpdate:Bool, p_camera:GCamera, p_node:GNode, p_bounds:GRectangle = null, p_source:GTexture = null, p_target:GTexture = null):Void { 70 | var bounds:GRectangle = (bounds != null) ? bounds : p_node.getBounds(null, g2d_activeBounds); 71 | 72 | // Invalid bounds 73 | if (bounds.width > 4096) return; 74 | 75 | updatePassTextures(bounds); 76 | 77 | var context:IGContext = Genome2D.getInstance().getContext(); 78 | 79 | g2d_bright.renderNode(p_parentTransformUpdate, p_parentColorUpdate, p_camera, p_node, bounds, null, g2d_passTextures[0]); 80 | g2d_blur.renderNode(p_parentTransformUpdate, p_parentColorUpdate, p_camera, p_node, bounds, g2d_passTextures[0], g2d_passTextures[1]); 81 | 82 | g2d_bloomFilter.texture = g2d_bright.getPassTexture(0); 83 | 84 | context.setRenderTarget(null); 85 | context.setActiveCamera(p_camera); 86 | context.draw(g2d_passTextures[1], GBlendMode.NORMAL, bounds.x-g2d_leftMargin, bounds.y-g2d_topMargin, 1, 1, 0, 1, 1, 1, 1, g2d_bloomFilter); 87 | } 88 | 89 | override public function dispose():Void { 90 | g2d_blur.dispose(); 91 | g2d_bright.dispose(); 92 | 93 | super.dispose(); 94 | } 95 | #end 96 | } -------------------------------------------------------------------------------- /src/com/genome2d/ui/layout/GUIVerticalLayout.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2015 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.ui.layout; 10 | 11 | import com.genome2d.ui.element.GUIElement; 12 | 13 | @:access(com.genome2d.ui.element.GUIElement) 14 | @prototypeName("vertical") 15 | class GUIVerticalLayout extends GUILayout { 16 | 17 | @prototype 18 | public var gap:Float = 0; 19 | 20 | @prototype 21 | public var useChildrenWidth:Bool = false; 22 | 23 | @prototype 24 | public var skipLastGap:Bool = false; 25 | 26 | @prototype 27 | public var skipInvisibleChildren:Bool = false; 28 | 29 | public function new() { 30 | type = GUILayoutType.VERTICAL; 31 | } 32 | 33 | override private function calculateWidth(p_element:GUIElement):Void { 34 | p_element.g2d_preferredWidth = p_element.g2d_minWidth = 0; 35 | 36 | for (i in 0...p_element.g2d_numChildren) { 37 | var child:GUIElement = p_element.g2d_children[i]; 38 | child.calculateWidth(); 39 | 40 | p_element.g2d_minWidth = p_element.g2d_minWidth < child.g2d_minWidth ? child.g2d_minWidth : p_element.g2d_minWidth; 41 | if (useChildrenWidth == true) { 42 | p_element.g2d_preferredWidth = p_element.g2d_preferredWidth < child.g2d_preferredWidth ? child.g2d_preferredWidth : p_element.g2d_preferredWidth; 43 | } 44 | } 45 | } 46 | 47 | override private function invalidateWidth(p_element:GUIElement):Void { 48 | var rest:Float = p_element.g2d_finalWidth - p_element.g2d_minWidth; 49 | if (rest<0) rest = 0; 50 | for (i in 0...p_element.g2d_numChildren) { 51 | var child:GUIElement = p_element.g2d_children[i]; 52 | 53 | child.g2d_worldLeft = p_element.g2d_worldLeft; 54 | child.g2d_worldRight = child.g2d_worldLeft + p_element.g2d_finalWidth; 55 | child.g2d_finalWidth = p_element.g2d_finalWidth; 56 | 57 | child.invalidateWidth(); 58 | } 59 | } 60 | 61 | override private function calculateHeight(p_element:GUIElement):Void { 62 | p_element.g2d_preferredHeight = p_element.g2d_minHeight = 0; 63 | var layoutGap:Float = gap; 64 | 65 | for (i in 0...p_element.g2d_numChildren) { 66 | var child:GUIElement = p_element.g2d_children[i]; 67 | 68 | if (skipInvisibleChildren && !child.visible) continue; 69 | 70 | child.calculateHeight(); 71 | 72 | if (skipLastGap == true && i >= p_element.g2d_numChildren - 1) { 73 | layoutGap = 0; 74 | } 75 | 76 | p_element.g2d_minHeight += child.g2d_minHeight + layoutGap; 77 | p_element.g2d_preferredHeight += child.g2d_preferredHeight + layoutGap; 78 | } 79 | } 80 | 81 | override private function invalidateHeight(p_element:GUIElement):Void { 82 | var offsetY:Float = 0; 83 | var rest:Float = p_element.g2d_finalHeight - p_element.g2d_minHeight; 84 | if (rest<0) rest = 0; 85 | var layoutGap:Float = gap; 86 | 87 | for (i in 0...p_element.g2d_numChildren) { 88 | var child:GUIElement = p_element.g2d_children[i]; 89 | 90 | if (skipInvisibleChildren && !child.visible) continue; 91 | 92 | child.g2d_worldTop = p_element.g2d_worldTop + offsetY; 93 | // Top priority rest space distribution 94 | var childDif:Float = (child.g2d_preferredHeight > child.g2d_minHeight)?child.g2d_preferredHeight - child.g2d_minHeight:0; 95 | childDif = rest < childDif?rest:childDif; 96 | rest -= childDif; 97 | child.g2d_worldBottom = child.g2d_worldTop + child.g2d_minHeight + childDif; 98 | child.g2d_finalHeight = child.g2d_worldBottom - child.g2d_worldTop; 99 | 100 | if (skipLastGap == true && i >= p_element.g2d_numChildren - 1) { 101 | layoutGap = 0; 102 | } 103 | offsetY += child.g2d_finalHeight + layoutGap; 104 | 105 | child.invalidateHeight(); 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/com/genome2d/g3d/G3DFactory.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.g3d; 2 | import com.genome2d.textures.GTexture; 3 | 4 | /** 5 | * @author Peter @sHTiF Stefcek 6 | */ 7 | @:access(com.genome2d.g3d.G3DScene) 8 | class G3DFactory 9 | { 10 | static private var g2d_ids:Int = 0; 11 | static public function createBox(p_width:Float, p_height:Float, p_depth:Float, p_texture:GTexture):G3DScene { 12 | var id:String = Std.string(g2d_ids++); 13 | var scene:G3DScene = new G3DScene(); 14 | 15 | var texture:G3DTexture = new G3DTexture("gte"+id, p_texture.id); 16 | scene.addNode(texture.id, texture); 17 | 18 | var material:G3DMaterial = new G3DMaterial("gma" + id); 19 | scene.addNode(material.id, material); 20 | 21 | var model:G3DModel = new G3DModel("gmo"+id); 22 | scene.addNode(model.id, model); 23 | 24 | var vertices:Array = [ -p_width / 2, -p_height / 2, -p_depth / 2, -p_width / 2, p_height / 2, -p_depth / 2, p_width / 2, -p_height / 2, -p_depth / 2, p_width / 2, p_height / 2, -p_depth / 2, 25 | -p_width / 2, -p_height / 2, p_depth / 2, -p_width / 2, p_height / 2, p_depth / 2, p_width / 2, -p_height / 2, p_depth / 2, p_width / 2, p_height / 2, p_depth / 2, 26 | -p_width / 2, -p_height / 2, p_depth / 2, -p_width / 2, -p_height / 2, -p_depth / 2, -p_width / 2, p_height / 2, p_depth / 2, -p_width / 2, p_height / 2, -p_depth / 2, 27 | p_width / 2, -p_height / 2, p_depth / 2, p_width / 2, -p_height / 2, -p_depth / 2, p_width / 2, p_height / 2, p_depth / 2, p_width / 2, p_height / 2, -p_depth / 2, 28 | -p_width / 2, -p_height / 2, p_depth / 2, p_width / 2, -p_height / 2, p_depth / 2, -p_width / 2, -p_height / 2, -p_depth / 2, p_width / 2, -p_height / 2, -p_depth / 2, 29 | -p_width / 2, p_height / 2, p_depth / 2, p_width / 2, p_height / 2, p_depth / 2, -p_width / 2, p_height / 2, -p_depth / 2, p_width / 2, p_height / 2, -p_depth / 2]; 30 | var uvs:Array = [ 0, 0, 1, 0, 0, 1, 1, 1, 31 | 0, 0, 1, 0, 0, 1, 1, 1, 32 | 0, 0, 1, 0, 0, 1, 1, 1, 33 | 0, 0, 1, 0, 0, 1, 1, 1, 34 | 0, 0, 1, 0, 0, 1, 1, 1, 35 | 0, 0, 1, 0, 0, 1, 1, 1]; 36 | 37 | var normals:Array = [0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 38 | 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 39 | 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 40 | -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, 41 | 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 42 | 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0]; 43 | 44 | 45 | var indices:Array = [0, 1, 2, 2, 1, 3, 46 | 4, 6, 5, 5, 6, 7, 47 | 8, 10, 9, 9, 10, 11, 48 | 12, 13, 14, 14, 13, 15, 49 | 16, 18, 17, 17, 18, 19, 50 | 20, 21, 22, 22, 21, 23]; 51 | 52 | var geometry:G3DGeometry = new G3DGeometry("gge"+id); 53 | geometry.initProcessed(vertices, uvs, indices, normals); 54 | scene.addNode(geometry.id, geometry); 55 | 56 | scene.addConnection(geometry.id, model.id); 57 | scene.addConnection(material.id, model.id); 58 | scene.addConnection(texture.id, material.id); 59 | 60 | return scene; 61 | } 62 | 63 | static public function createPlane(p_width:Float, p_height:Float, p_texture:GTexture):G3DScene { 64 | var id:String = Std.string(g2d_ids++); 65 | var scene:G3DScene = new G3DScene(); 66 | 67 | var texture:G3DTexture = new G3DTexture("gte"+id, p_texture.id); 68 | scene.addNode(texture.id, texture); 69 | 70 | var material:G3DMaterial = new G3DMaterial("gma" + id); 71 | scene.addNode(material.id, material); 72 | 73 | var model:G3DModel = new G3DModel("gmo"+id); 74 | scene.addNode(model.id, model); 75 | 76 | var vertices:Array = [ -p_width / 2, -p_height / 2, 0, -p_width / 2, p_height / 2, 0, p_width / 2, -p_height / 2, 0, p_width / 2, p_height / 2, 0]; 77 | var uvs:Array = [ 0, 0, 1, 0, 0, 1, 1, 1]; 78 | 79 | var normals:Array = [0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1]; 80 | 81 | 82 | var indices:Array = [0, 1, 2, 2, 1, 3]; 83 | 84 | var geometry:G3DGeometry = new G3DGeometry("gge"+id); 85 | geometry.initProcessed(vertices, uvs, indices, normals); 86 | scene.addNode(geometry.id, geometry); 87 | 88 | scene.addConnection(geometry.id, model.id); 89 | scene.addConnection(material.id, model.id); 90 | scene.addConnection(texture.id, material.id); 91 | 92 | return scene; 93 | } 94 | } -------------------------------------------------------------------------------- /src/com/genome2d/text/GTextureFont.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2014 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.text; 10 | 11 | import com.genome2d.geom.GRectangle; 12 | import com.genome2d.textures.GTexture; 13 | import com.genome2d.textures.GTextureManager; 14 | 15 | class GTextureFont extends GFont { 16 | @prototype("getReference") 17 | public var texture:GTexture; 18 | 19 | @prototype 20 | public var lineHeight:Int = 0; 21 | 22 | @prototype 23 | public var base:Int = 0; 24 | 25 | @prototype 26 | public var face:String; 27 | 28 | @prototype 29 | public var italic:Bool = false; 30 | 31 | @prototype 32 | public var bold:Bool = false; 33 | 34 | @prototype 35 | public var regionOffsetX:Int = 0; 36 | 37 | @prototype 38 | public var regionOffsetY:Int = 0; 39 | 40 | public var kerning:Map>; 41 | 42 | private var g2d_chars:Map; 43 | 44 | public function new():Void { 45 | g2d_chars = new Map(); 46 | } 47 | 48 | public function getChar(p_charId:Int):GTextureChar { 49 | return cast g2d_chars.get(p_charId); 50 | } 51 | 52 | public function addCharsFromXml(p_xml:Xml):Void { 53 | var root:Xml = p_xml.firstElement(); 54 | 55 | var info:Xml = root.elementsNamed("info").next(); 56 | face = info.get("face"); 57 | italic = (info.get("italic") == "1")?true:false; 58 | bold = (info.get("bold") == "1")?true:false; 59 | 60 | var common:Xml = root.elementsNamed("common").next(); 61 | lineHeight = Std.parseInt(common.get("lineHeight")); 62 | base = Std.parseInt(common.get("base")); 63 | 64 | var it:Iterator = root.elementsNamed("chars"); 65 | it = it.next().elements(); 66 | 67 | while(it.hasNext()) { 68 | var node:Xml = it.next(); 69 | var w:Int = Std.parseInt(node.get("width")); 70 | var h:Int = Std.parseInt(node.get("height")); 71 | var region:GRectangle = new GRectangle(Std.parseInt(node.get("x")) + regionOffsetX, Std.parseInt(node.get("y")) + regionOffsetY, w, h); 72 | 73 | addChar(Std.parseInt(node.get("id")), region, Std.parseFloat(node.get("xoffset")), Std.parseFloat(node.get("yoffset")), Std.parseFloat(node.get("xadvance"))); 74 | } 75 | 76 | var kernings:Xml = root.elementsNamed("kernings").next(); 77 | if (kernings != null) { 78 | it = kernings.elements(); 79 | kerning = new Map>(); 80 | 81 | while(it.hasNext()) { 82 | var node:Xml = it.next(); 83 | var first:Int = Std.parseInt(node.get("first")); 84 | var map:Map = kerning.get(first); 85 | if (map == null) { 86 | map = new Map(); 87 | kerning.set(first, map); 88 | } 89 | var second:Int = Std.parseInt(node.get("second")); 90 | map.set(second, Std.parseInt(node.get("amount"))); 91 | } 92 | } 93 | } 94 | 95 | public function addChar(p_charId:Int, p_region:GRectangle, p_xoffset:Float, p_yoffset:Float, p_xadvance:Float):GTextureChar { 96 | var charTexture:GTexture = GTextureManager.createSubTexture(id+"_"+p_charId, texture, p_region); 97 | charTexture.pivotX = -p_region.width/2; 98 | charTexture.pivotY = -p_region.height/2; 99 | 100 | var char:GTextureChar = new GTextureChar(charTexture); 101 | char.xoffset = p_xoffset; 102 | char.yoffset = p_yoffset; 103 | char.xadvance = p_xadvance; 104 | g2d_chars.set(p_charId, char); 105 | 106 | return char; 107 | } 108 | 109 | public function getKerning(p_first:Int, p_second:Int):Float { 110 | if (kerning != null && kerning.exists(p_first)) { 111 | var map:Map = kerning.get(p_first); 112 | if (!map.exists(p_second)) { 113 | return 0; 114 | } else { 115 | return map.get(p_second)*texture.scaleFactor; 116 | } 117 | } 118 | 119 | return 0; 120 | } 121 | 122 | override public function dispose():Void { 123 | super.dispose(); 124 | 125 | for (char in g2d_chars) char.dispose(); 126 | g2d_chars = null; 127 | texture = null; 128 | } 129 | 130 | static public function fromReference(p_reference:String):GTextureFont { 131 | return cast GFontManager.getFont(p_reference.substr(1)); 132 | } 133 | } -------------------------------------------------------------------------------- /src/com/genome2d/g3d/G3DModel.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.g3d; 2 | 3 | import com.genome2d.context.renderers.G3DRenderer; 4 | import com.genome2d.geom.GMatrix3D; 5 | import com.genome2d.geom.GVector3D; 6 | import com.genome2d.macros.MGDebug; 7 | import com.genome2d.textures.GTextureManager; 8 | import com.genome2d.debug.GDebug; 9 | import com.genome2d.geom.GFloat4; 10 | 11 | class G3DModel extends G3DNode { 12 | public var useSceneLighting:Bool = true; 13 | public var lightDirection:GFloat4; 14 | public var ambientColor:GFloat4; 15 | public var lightColor:GFloat4; 16 | public var tintColor:GFloat4; 17 | 18 | public var visible:Bool = true; 19 | 20 | public var renderer:G3DRenderer; 21 | 22 | public var inheritSceneMatrixMode:G3DMatrixInheritMode = G3DMatrixInheritMode.REPLACE; 23 | public var modelMatrix:GMatrix3D; 24 | public var transparent:Bool = false; 25 | public var center:GVector3D; 26 | 27 | public function new(p_id:String):Void { 28 | super(p_id); 29 | 30 | lightDirection = new GFloat4(1,1,1); 31 | ambientColor = new GFloat4(1,1,1,1); 32 | tintColor = new GFloat4(1,1,1,1); 33 | lightColor = new GFloat4(1,1,1,1); 34 | 35 | center = new GVector3D(); 36 | modelMatrix = new GMatrix3D(); 37 | } 38 | 39 | public function getGeometry():G3DGeometry { 40 | for (connection in connections) { 41 | if (Std.is(connection, G3DGeometry)) return cast connection; 42 | if (Std.is(connection, G3DModel)) return cast(connection,G3DModel).getGeometry(); 43 | } 44 | return null; 45 | } 46 | 47 | public function getMaterial():G3DMaterial { 48 | for (connection in connections) { 49 | if (Std.is(connection, G3DMaterial)) return cast connection; 50 | if (Std.is(connection, G3DModel)) return cast(connection,G3DModel).getMaterial(); 51 | } 52 | return null; 53 | } 54 | 55 | public function dispose():Void { 56 | if (renderer != null) renderer.dispose(); 57 | renderer = null; 58 | } 59 | 60 | public function invalidate():Void { 61 | // Hack to check for transparency based on name suffix 62 | transparent = name.indexOf("_T") == name.length - 2; 63 | 64 | var geometry:G3DGeometry = getGeometry(); 65 | if (geometry == null) MGDebug.G2D_ERROR("Model has no geometry."); 66 | 67 | if (renderer == null) { 68 | renderer = new G3DRenderer(geometry.vertices, geometry.uvs, geometry.indices, geometry.normals, false); 69 | } else { 70 | renderer.invalidateGeometry(geometry.vertices, geometry.uvs, geometry.indices, geometry.normals); 71 | } 72 | 73 | 74 | var material:G3DMaterial = getMaterial(); 75 | if (material == null) MGDebug.G2D_ERROR("Model has no material."); 76 | 77 | var texture:G3DTexture = getMaterial().getTexture(); 78 | if (texture == null) { 79 | MGDebug.WARNING("Model material has no texture."); 80 | renderer.texture = GTextureManager.getTexture("g2d_internal"); 81 | } else { 82 | var textureId:String = texture.relativePath; 83 | renderer.texture = GTextureManager.getTexture(textureId); 84 | if (renderer.texture == null) { 85 | MGDebug.WARNING("Couldn't find texture", textureId); 86 | renderer.texture = GTextureManager.getTexture("g2d_internal"); 87 | } 88 | } 89 | } 90 | 91 | public function checkValidity():Bool { 92 | var geometry:G3DGeometry = getGeometry(); 93 | if (geometry == null) { 94 | MGDebug.WARNING("Model has no geometry."); 95 | return false; 96 | } 97 | 98 | var material:G3DMaterial = getMaterial(); 99 | if (material == null) { 100 | MGDebug.WARNING("Model has no material."); 101 | return false; 102 | } 103 | 104 | var texture:G3DTexture = getMaterial().getTexture(); 105 | if (texture == null) { 106 | MGDebug.WARNING("Model material has no texture."); 107 | return false; 108 | } 109 | 110 | return true; 111 | } 112 | 113 | public function calculateCenter():Void { 114 | center = new GVector3D(); 115 | var vertices:Array = getGeometry().vertices; 116 | for (i in 0...Std.int(vertices.length/3)) { 117 | center.x += vertices[i * 3]; 118 | center.y += vertices[i * 3 + 1]; 119 | center.z += vertices[i * 3 + 2]; 120 | } 121 | center.x /= vertices.length; 122 | center.y /= vertices.length; 123 | center.z /= vertices.length; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /src/com/genome2d/g3d/importers/G3DFbxImporter.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.g3d.importers; 2 | 3 | import com.genome2d.fbx.GFbxParser; 4 | import com.genome2d.fbx.GFbxParserNode; 5 | import com.genome2d.fbx.GFbxTools; 6 | import com.genome2d.g3d.G3DScene; 7 | import com.genome2d.g3d.G3DTexture; 8 | import haxe.io.BytesData; 9 | import haxe.io.Bytes; 10 | 11 | /** 12 | * @author Peter @sHTiF Stefcek 13 | */ 14 | class G3DFbxImporter extends G3DAbstractImporter 15 | { 16 | override public function importScene(p_data:Bytes):G3DScene { 17 | var scene:G3DScene = new G3DScene(); 18 | 19 | var fbxData:GFbxParserNode = GFbxParser.parse(p_data.getString(0, p_data.length)); 20 | 21 | g2d_initTextures(scene, fbxData); 22 | g2d_initModels(scene, fbxData); 23 | g2d_initMaterials(scene, fbxData); 24 | g2d_initGeometry(scene, fbxData); 25 | 26 | g2d_initConnections(scene, fbxData); 27 | 28 | return scene; 29 | } 30 | 31 | private function g2d_initTextures(p_scene:G3DScene, p_fbxData:GFbxParserNode):Void { 32 | var textureNodes:Array = GFbxTools.getAll(p_fbxData, "Objects.Texture"); 33 | for (node in textureNodes) { 34 | var id:String = Std.string(GFbxTools.toFloat(node.props[0])); 35 | var relativePathNode:GFbxParserNode = GFbxTools.get(node, "RelativeFilename", true); 36 | var relativePath:String = GFbxTools.toString(relativePathNode.props[0]); 37 | 38 | var texture:G3DTexture = new G3DTexture(id, relativePath); 39 | p_scene.addNode(texture.id, texture); 40 | } 41 | } 42 | 43 | private function g2d_initModels(p_scene:G3DScene, p_fbxData:GFbxParserNode):Void { 44 | var modelNodes:Array = GFbxTools.getAll(p_fbxData, "Objects.Model"); 45 | 46 | for (node in modelNodes) { 47 | var id:String = Std.string(GFbxTools.toFloat(node.props[0])); 48 | 49 | var model:G3DModel = new G3DModel(id); 50 | model.name = GFbxTools.toString(node.props[1]); 51 | p_scene.addNode(model.id, model); 52 | } 53 | } 54 | 55 | private function g2d_initMaterials(p_scene:G3DScene, p_fbxData:GFbxParserNode):Void { 56 | var materialNodes:Array = GFbxTools.getAll(p_fbxData, "Objects.Material"); 57 | 58 | for (node in materialNodes) { 59 | var id:String = Std.string(GFbxTools.toFloat(node.props[0])); 60 | 61 | var material:G3DMaterial = new G3DMaterial(id); 62 | p_scene.addNode(material.id, material); 63 | } 64 | } 65 | 66 | private function g2d_initGeometry(p_scene:G3DScene, p_fbxData:GFbxParserNode):Void { 67 | var geometryNodes:Array = GFbxTools.getAll(p_fbxData,"Objects.Geometry"); 68 | 69 | for (node in geometryNodes) { 70 | var id:String = Std.string(GFbxTools.toFloat(node.props[0])); 71 | 72 | var vertexNode:GFbxParserNode = GFbxTools.getAll(node,"Vertices")[0]; 73 | var vertexIndexNode:GFbxParserNode = GFbxTools.getAll(node,"PolygonVertexIndex")[0]; 74 | 75 | var uvNode:GFbxParserNode = GFbxTools.getAll(node,"LayerElementUV.UV")[0]; 76 | var uvIndexNode:GFbxParserNode = GFbxTools.getAll(node, "LayerElementUV.UVIndex")[0]; 77 | 78 | var normalsNode:GFbxParserNode = GFbxTools.getAll(node, "LayerElementNormal.Normals")[0]; 79 | 80 | var vertices:Array = GFbxTools.getFloats(vertexNode); 81 | var indices:Array = cast GFbxTools.getInts(vertexIndexNode); 82 | 83 | var uvs:Array = GFbxTools.getFloats(uvNode); 84 | var uvIndices:Array = GFbxTools.getInts(uvIndexNode); 85 | 86 | var normals:Array = GFbxTools.getFloats(normalsNode); 87 | 88 | var geometry:G3DGeometry = new G3DGeometry(id); 89 | geometry.initImported(vertices, uvs, indices, uvIndices, normals); 90 | p_scene.addNode(geometry.id, geometry); 91 | } 92 | } 93 | 94 | private function g2d_initConnections(p_scene:G3DScene, p_fbxData:GFbxParserNode):Void { 95 | var connectionNodes:Array = GFbxTools.getAll(p_fbxData, "Connections.C"); 96 | 97 | for (node in connectionNodes) { 98 | var sourceId:String = Std.string(GFbxTools.toFloat(node.props[1])); 99 | var destinationId:String = Std.string(GFbxTools.toFloat(node.props[2])); 100 | p_scene.addConnection(sourceId, destinationId); 101 | } 102 | } 103 | 104 | } -------------------------------------------------------------------------------- /src/com/genome2d/g3d2/G3DRenderGeometry.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.g3d2; 2 | 3 | class G3DRenderGeometry { 4 | 5 | public var importedUvs:Array; 6 | public var importedIndices:Array; 7 | public var importedUvIndices:Array; 8 | //public var importedNormals:Array; 9 | 10 | public var vertices:Array; 11 | public var indices:Array; 12 | public var uvs:Array; 13 | public var vertexNormals:Array; 14 | public var faceNormals:Array; 15 | 16 | public function new() { 17 | } 18 | 19 | public function initProcessed(p_vertices:Array, p_uvs:Array, p_indices:Array, p_normals:Array) { 20 | vertices = p_vertices; 21 | uvs = p_uvs; 22 | indices = p_indices; 23 | vertexNormals = p_normals; 24 | } 25 | 26 | public function initImported(p_vertices:Array, p_uvs:Array, p_indices:Array, p_uvIndices:Array) { 27 | vertices = p_vertices; 28 | //importedNormals = p_normals; 29 | importedUvs = p_uvs; 30 | importedIndices = p_indices; 31 | importedUvIndices = p_uvIndices; 32 | 33 | if (importedUvIndices.length != importedIndices.length) throw "Not same number of vertex and UV indices!"; 34 | // Create array for our reindexed UVs 35 | uvs = new Array(); 36 | for (j in 0...importedUvs.length) { 37 | uvs.push(0); 38 | } 39 | 40 | // Reindex UV coordinates to correspond to vertex indices 41 | indices = new Array(); 42 | for (j in 0...importedUvIndices.length) { 43 | var vertexIndex:Int = importedIndices[j]; 44 | if (vertexIndex < 0) vertexIndex = -vertexIndex-1; 45 | indices.push(vertexIndex); 46 | //mergedVertexIndices.push(vertexIndex+indexOffset); 47 | 48 | var uvIndex:Int = importedUvIndices[j]; 49 | uvs[vertexIndex*2] = importedUvs[uvIndex*2]; 50 | uvs[vertexIndex*2+1] = 1-importedUvs[uvIndex*2+1]; 51 | } 52 | 53 | calculateFaceNormals(); 54 | calculateVertexNormals(); 55 | } 56 | 57 | private function calculateFaceNormals():Void { 58 | faceNormals = new Array(); 59 | var i:Int = 0; 60 | while (i { 91 | var faces:Array = new Array(); 92 | for (i in 0...indices.length) { 93 | if (indices[i] == p_vertexIndex) { 94 | var face:UInt = Std.int(i/3); 95 | if (faces.indexOf(face) == -1) faces.push(face); 96 | } 97 | } 98 | return faces; 99 | } 100 | 101 | private function calculateVertexNormals():Void { 102 | vertexNormals = new Array(); 103 | var vertexCount:Int = Std.int(vertices.length/3); 104 | for (i in 0...vertexCount) { 105 | var sharedFaces:Array = getVertexFaces(i); 106 | var nx:Float = 0; 107 | var ny:Float = 0; 108 | var nz:Float = 0; 109 | for (faceIndex in sharedFaces) { 110 | nx += faceNormals[faceIndex*3]; 111 | ny += faceNormals[faceIndex*3+1]; 112 | nz += faceNormals[faceIndex*3+2]; 113 | } 114 | var nl:Float = Math.sqrt(nx*nx+ny*ny+nz*nz); 115 | vertexNormals.push(nx/nl); 116 | vertexNormals.push(ny/nl); 117 | vertexNormals.push(nz/nl); 118 | } 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/com/genome2d/components/GFrameAnimator.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.components; 2 | import com.genome2d.components.renderable.GSprite; 3 | import com.genome2d.textures.GTexture; 4 | 5 | class GFrameAnimator extends GAnimator 6 | { 7 | public var timeDilation:Float = 1; 8 | 9 | /** 10 | Is animation repeating after reaching the last frame, default true 11 | **/ 12 | public var repeatable:Bool = true; 13 | 14 | /** 15 | Is playback reversed, default false 16 | **/ 17 | public var reversed:Bool = false; 18 | 19 | private var g2d_speed:Float = 1000/30; 20 | private var g2d_accumulatedTime:Float = 0; 21 | private var g2d_lastUpdatedFrameId:Int = 0; 22 | private var g2d_startIndex:Int = -1; 23 | private var g2d_endIndex:Int = -1; 24 | private var g2d_playing:Bool = true; 25 | 26 | private var g2d_sprite:GSprite; 27 | private function getSprite():GSprite { 28 | if (g2d_sprite == null) g2d_sprite = cast node.getComponent(GSprite); 29 | return g2d_sprite; 30 | } 31 | 32 | /** 33 | Get the current frame count 34 | **/ 35 | private var g2d_frameCount:Int; 36 | #if swc @:extern #end 37 | public var frameCount(get, never):Int; 38 | #if swc @:getter(frameCount) #end 39 | inline private function get_frameCount():Int { 40 | return g2d_frameCount; 41 | } 42 | 43 | /** 44 | Get the current frame index the movieclip is at 45 | **/ 46 | private var g2d_currentFrame:Int = -1; 47 | #if swc @:extern #end 48 | public var currentFrame(get, never):Int; 49 | #if swc @:getter(currentFrame) #end 50 | inline private function get_currentFrame():Int { 51 | return g2d_currentFrame; 52 | } 53 | 54 | /** 55 | Textures used for frames 56 | **/ 57 | private var g2d_frameTextures:Array; 58 | #if swc @:extern #end 59 | public var frameTextures(never, set):Array; 60 | #if swc @:setter(frameTextures) #end 61 | inline private function set_frameTextures(p_value:Array):Array { 62 | g2d_frameTextures = p_value; 63 | g2d_frameCount = p_value.length; 64 | g2d_currentFrame = 0; 65 | if (g2d_frameTextures.length>0) { 66 | getSprite().texture = g2d_frameTextures[0]; 67 | } else { 68 | getSprite().texture = null; 69 | } 70 | 71 | return g2d_frameTextures; 72 | } 73 | 74 | /** 75 | Go to a specified frame 76 | **/ 77 | public function gotoFrame(p_frame:Int):Void { 78 | if (g2d_frameTextures == null) return; 79 | g2d_currentFrame = p_frame; 80 | g2d_currentFrame %= g2d_frameCount; 81 | getSprite().texture = g2d_frameTextures[g2d_currentFrame]; 82 | } 83 | 84 | /** 85 | Go to a specified frame and start playing 86 | **/ 87 | public function gotoAndPlay(p_frame:Int):Void { 88 | gotoFrame(p_frame); 89 | play(); 90 | } 91 | 92 | /** 93 | Go to a specified frame and stop playing 94 | **/ 95 | public function gotoAndStop(p_frame:Int):Void { 96 | gotoFrame(p_frame); 97 | stop(); 98 | } 99 | 100 | /** 101 | Stop playback 102 | **/ 103 | public function stop():Void { 104 | g2d_playing = false; 105 | } 106 | 107 | /** 108 | Start the playback 109 | **/ 110 | public function play():Void { 111 | g2d_playing = true; 112 | } 113 | 114 | inline public function update(p_deltaTime:Float):Void { 115 | if (g2d_playing && g2d_frameCount>1) { 116 | g2d_accumulatedTime += p_deltaTime*timeDilation; 117 | 118 | if (g2d_accumulatedTime >= g2d_speed) { 119 | g2d_currentFrame += (reversed) ? -Std.int(g2d_accumulatedTime / g2d_speed) : Std.int(g2d_accumulatedTime / g2d_speed); 120 | if (reversed && g2d_currentFrame<0) { 121 | if (repeatable) { 122 | g2d_currentFrame = g2d_frameCount+g2d_currentFrame%g2d_frameCount; 123 | } else { 124 | g2d_currentFrame = 0; 125 | g2d_playing = false; 126 | } 127 | } else if (!reversed && g2d_currentFrame>=g2d_frameCount) { 128 | if (repeatable) { 129 | g2d_currentFrame = g2d_currentFrame%g2d_frameCount; 130 | } else { 131 | g2d_currentFrame = g2d_frameCount-1; 132 | g2d_playing = false; 133 | } 134 | } 135 | if (g2d_sprite == null) g2d_sprite = cast node.getComponent(GSprite); 136 | if (g2d_sprite != null) g2d_sprite.texture = g2d_frameTextures[g2d_currentFrame]; 137 | } 138 | g2d_accumulatedTime %= g2d_speed; 139 | } 140 | } 141 | } -------------------------------------------------------------------------------- /src/com/genome2d/fbx/GFbxTools.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.fbx; 2 | 3 | enum FbxProp { 4 | PInt( v : Int ); 5 | PFloat( v : Float ); 6 | PString( v : String ); 7 | PIdent( i : String ); 8 | PInts( v : Array ); 9 | PFloats( v : Array ); 10 | } 11 | 12 | class GFbxTools { 13 | 14 | static public function get(p_node:GFbxParserNode, p_path:String, opt = false):GFbxParserNode { 15 | var parts:Array = p_path.split("."); 16 | var cur:GFbxParserNode = p_node; 17 | for(p in parts) { 18 | var found:Bool = false; 19 | for(c in cur.childs) { 20 | if(c.name == p) { 21 | cur = c; 22 | found = true; 23 | break; 24 | } 25 | } 26 | if(!found) { 27 | if(opt) { 28 | return null; 29 | } 30 | throw p_node.name + " does not have " + p_path+" ("+p+" not found)"; 31 | } 32 | } 33 | return cur; 34 | } 35 | 36 | static public function getAll(p_node:GFbxParserNode, p_path:String):Array { 37 | var parts = p_path.split("."); 38 | var cur = [p_node]; 39 | for( p in parts ) { 40 | var out = []; 41 | for( n in cur ) { 42 | for( c in n.childs ) { 43 | if( c.name == p ) { 44 | out.push(c); 45 | } 46 | } 47 | } 48 | cur = out; 49 | if( cur.length == 0 ) { 50 | return cur; 51 | } 52 | } 53 | return cur; 54 | } 55 | 56 | static public function getInts(p_node:GFbxParserNode):Array { 57 | if( p_node.props.length != 1 ) throw p_node.name + " has " + p_node.props + " props"; 58 | 59 | switch(p_node.props[0]) { 60 | case PInts(v): 61 | return v; 62 | default: 63 | throw p_node.name + " has " + p_node.props + " props"; 64 | } 65 | } 66 | 67 | static public function getFloats(p_node:GFbxParserNode):Array { 68 | if(p_node.props.length != 1) throw p_node.name + " has " + p_node.props + " props"; 69 | 70 | switch(p_node.props[0]) { 71 | case PFloats(v): 72 | return v; 73 | case PInts(i): 74 | var fl = new Array(); 75 | for( x in i ) 76 | fl.push(x); 77 | p_node.props[0] = PFloats(fl); // keep data synchronized 78 | // this is necessary for merging geometries since we are pushing directly into the 79 | // float buffer 80 | return fl; 81 | default: 82 | throw p_node.name + " has " + p_node.props + " props"; 83 | } 84 | } 85 | 86 | static public function hasProp(p_node:GFbxParserNode, p_prop:FbxProp):Bool { 87 | for( p2 in p_node.props ) { 88 | if(Type.enumEq(p_prop, p2)) { 89 | return true; 90 | } 91 | } 92 | return false; 93 | } 94 | 95 | static public function toInt(p_prop:FbxProp):Int { 96 | if( p_prop == null ) throw "null prop"; 97 | 98 | return switch(p_prop) { 99 | case PInt(v): 100 | v; 101 | case PFloat(f): 102 | Std.int(f); 103 | default: 104 | throw "Invalid prop " + p_prop; 105 | } 106 | } 107 | 108 | static public function toFloat(p_prop:FbxProp):Float { 109 | if( p_prop == null ) throw "null prop"; 110 | 111 | return switch(p_prop) { 112 | case PInt(v): 113 | v * 1.0; 114 | case PFloat(v): 115 | v; 116 | default: 117 | throw "Invalid prop " + p_prop; 118 | } 119 | } 120 | 121 | static public function toString(p_prop:FbxProp):String { 122 | if( p_prop == null ) throw "null prop"; 123 | return switch( p_prop ) { 124 | case PString(v): 125 | v; 126 | default: 127 | throw "Invalid prop " + p_prop; 128 | } 129 | } 130 | 131 | static public function getId(p_node:GFbxParserNode):Int { 132 | if( p_node.props.length != 3 ) throw p_node.name + " is not an object"; 133 | 134 | return switch( p_node.props[0] ) { 135 | case PInt(id): 136 | id; 137 | case PFloat(id): 138 | Std.int(id); 139 | default: 140 | throw p_node.name + " is not an object " + p_node.props; 141 | } 142 | } 143 | 144 | static public function getName(p_node:GFbxParserNode):String { 145 | if( p_node.props.length != 3 ) throw p_node.name + " is not an object"; 146 | 147 | return switch( p_node.props[1] ) { 148 | case PString(p_node): 149 | p_node.split("::").pop(); 150 | default: 151 | throw p_node.name + " is not an object"; 152 | } 153 | } 154 | 155 | static public function getType(n:GFbxParserNode):String { 156 | if( n.props.length != 3 ) throw n.name + " is not an object"; 157 | 158 | return switch( n.props[2] ) { 159 | case PString(n): 160 | n; 161 | default: 162 | throw n.name + " is not an object"; 163 | } 164 | } 165 | 166 | } -------------------------------------------------------------------------------- /src/com/genome2d/fbx/GFbxGeometry.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.fbx; 2 | 3 | import com.genome2d.fbx.GFbxTools; 4 | import com.genome2d.fbx.GFbxParserNode; 5 | 6 | class GFbxGeometry extends GFbxNode { 7 | 8 | public var vertices:Array; 9 | public var indices:Array; 10 | public var uvs:Array; 11 | //public var importedNormals:Array; 12 | public var vertexNormals:Array; 13 | public var faceNormals:Array; 14 | 15 | public function new(p_fbxNode:GFbxParserNode) { 16 | super(p_fbxNode); 17 | 18 | var vertexNode:GFbxParserNode = GFbxTools.getAll(p_fbxNode,"Vertices")[0]; 19 | var vertexIndexNode:GFbxParserNode = GFbxTools.getAll(p_fbxNode,"PolygonVertexIndex")[0]; 20 | 21 | var normalsNode:GFbxParserNode = GFbxTools.getAll(p_fbxNode, "LayerElementNormal.Normals")[0]; 22 | 23 | var uvNode:GFbxParserNode = GFbxTools.getAll(p_fbxNode,"LayerElementUV.UV")[0]; 24 | var uvIndexNode:GFbxParserNode = GFbxTools.getAll(p_fbxNode,"LayerElementUV.UVIndex")[0]; 25 | 26 | var importedVertices:Array = GFbxTools.getFloats(vertexNode); 27 | vertexNormals = GFbxTools.getFloats(normalsNode); 28 | var currentVertexIndices:Array = cast GFbxTools.getInts(vertexIndexNode); 29 | var currentUVs:Array = GFbxTools.getFloats(uvNode); 30 | var currentUVIndices:Array = GFbxTools.getInts(uvIndexNode); 31 | if (currentUVIndices.length != currentVertexIndices.length) throw "Not same number of vertex and UV indices!"; 32 | // Create array for our reindexed UVs 33 | uvs = new Array(); 34 | for (j in 0...currentUVs.length) { 35 | uvs.push(0); 36 | } 37 | 38 | // Reindex stuff 39 | vertices = new Array(); 40 | indices = new Array(); 41 | for (j in 0...currentVertexIndices.length) { 42 | var vertexIndex:Int = currentVertexIndices[j]; 43 | if (vertexIndex < 0) vertexIndex = -vertexIndex-1; 44 | vertices.push(importedVertices[vertexIndex*3]); 45 | vertices.push(importedVertices[vertexIndex*3+1]); 46 | vertices.push(importedVertices[vertexIndex*3+2]); 47 | indices.push(j); 48 | //mergedVertexIndices.push(vertexIndex+indexOffset); 49 | 50 | var uvIndex:Int = currentUVIndices[j]; 51 | uvs[j*2] = currentUVs[uvIndex*2]; 52 | uvs[j*2+1] = 1-currentUVs[uvIndex*2+1]; 53 | } 54 | 55 | //calculateFaceNormals(); 56 | //calculateVertexNormals(); 57 | } 58 | 59 | private function calculateFaceNormals():Void { 60 | faceNormals = new Array(); 61 | var i:Int = 0; 62 | while (i { 93 | var faces:Array = new Array(); 94 | for (i in 0...indices.length) { 95 | if (indices[i] == p_vertexIndex) { 96 | var face:UInt = Std.int(i/3); 97 | if (faces.indexOf(face) == -1) faces.push(face); 98 | } 99 | } 100 | return faces; 101 | } 102 | 103 | private function calculateVertexNormals():Void { 104 | vertexNormals = new Array(); 105 | var vertexCount:Int = Std.int(vertices.length/3); 106 | for (i in 0...vertexCount) { 107 | var sharedFaces:Array = getVertexFaces(i); 108 | var nx:Float = 0; 109 | var ny:Float = 0; 110 | var nz:Float = 0; 111 | for (faceIndex in sharedFaces) { 112 | nx += faceNormals[faceIndex*3]; 113 | ny += faceNormals[faceIndex*3+1]; 114 | nz += faceNormals[faceIndex*3+2]; 115 | } 116 | var nl:Float = Math.sqrt(nx*nx+ny*ny+nz*nz); 117 | vertexNormals.push(nx/nl); 118 | vertexNormals.push(ny/nl); 119 | vertexNormals.push(nz/nl); 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/com/genome2d/g3d/G3DGeometry.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.g3d; 2 | 3 | import com.genome2d.debug.GDebug; 4 | 5 | class G3DGeometry extends G3DNode { 6 | 7 | public var importedUvs:Array; 8 | public var importedIndices:Array; 9 | public var importedUvIndices:Array; 10 | public var importedNormals:Array; 11 | 12 | public var vertices:Array; 13 | public var indices:Array; 14 | public var uvs:Array; 15 | public var normals:Array; 16 | 17 | public function new(p_id:String) { 18 | super(p_id); 19 | } 20 | 21 | public function initProcessed(p_vertices:Array, p_uvs:Array, p_indices:Array, p_normals:Array) { 22 | vertices = p_vertices; 23 | uvs = p_uvs; 24 | indices = p_indices; 25 | normals = p_normals; 26 | } 27 | 28 | public function initImported(p_vertices:Array, p_uvs:Array, p_indices:Array, p_uvIndices:Array, p_normals:Array) { 29 | importedUvs = p_uvs; 30 | importedIndices = p_indices; 31 | importedUvIndices = p_uvIndices; 32 | importedNormals = p_normals; 33 | 34 | // TODO: assuming that reindexation happens if there is length disparity is a hack, potentionally reindexation should happen even if the length is the same but order doesn't match - sHTiF 35 | var reindexNormals:Bool = p_normals.length != importedIndices.length*3; 36 | normals = reindexNormals ? new Array() : p_normals; 37 | 38 | if (p_uvIndices.length != p_indices.length) throw "Not same number of vertex and UV indices!"; 39 | 40 | vertices = new Array(); 41 | uvs = new Array(); 42 | indices = new Array(); 43 | for (j in 0...p_indices.length) { 44 | var vertexIndex:Int = p_indices[j]; 45 | if (vertexIndex < 0) vertexIndex = -vertexIndex - 1; 46 | vertices.push(p_vertices[vertexIndex * 3]); 47 | vertices.push(p_vertices[vertexIndex * 3 + 1]); 48 | vertices.push(p_vertices[vertexIndex * 3 + 2]); 49 | if (reindexNormals) { 50 | normals.push(p_normals[vertexIndex * 3]); 51 | normals.push(p_normals[vertexIndex * 3 + 1]); 52 | normals.push(p_normals[vertexIndex * 3 + 2]); 53 | } 54 | indices.push(j); 55 | 56 | var uvIndex:Int = p_uvIndices[j]; 57 | uvs.push(p_uvs[uvIndex * 2]); 58 | uvs.push(1 - p_uvs[uvIndex * 2 + 1]); 59 | } 60 | 61 | /* 62 | if (vertexNormals == null) { 63 | calculateFaceNormals(); 64 | calculateVertexNormals(); 65 | } 66 | /* 67 | */ 68 | } 69 | 70 | /* 71 | private function calculateFaceNormals():Void { 72 | faceNormals = new Array(); 73 | var i:Int = 0; 74 | while (i { 105 | var faces:Array = new Array(); 106 | for (i in 0...indices.length) { 107 | if (indices[i] == p_vertexIndex) { 108 | var face:UInt = Std.int(i/3); 109 | if (faces.indexOf(face) == -1) faces.push(face); 110 | } 111 | } 112 | return faces; 113 | } 114 | 115 | private function calculateVertexNormals():Void { 116 | normals = new Array(); 117 | var vertexCount:Int = Std.int(vertices.length/3); 118 | for (i in 0...vertexCount) { 119 | var sharedFaces:Array = getVertexFaces(i); 120 | var nx:Float = 0; 121 | var ny:Float = 0; 122 | var nz:Float = 0; 123 | for (faceIndex in sharedFaces) { 124 | nx += faceNormals[faceIndex*3]; 125 | ny += faceNormals[faceIndex*3+1]; 126 | nz += faceNormals[faceIndex*3+2]; 127 | } 128 | var nl:Float = Math.sqrt(nx*nx+ny*ny+nz*nz); 129 | normals.push(nx/nl); 130 | normals.push(ny/nl); 131 | normals.push(nz/nl); 132 | } 133 | } 134 | /* 135 | */ 136 | } 137 | -------------------------------------------------------------------------------- /src/com/genome2d/postprocess/GHDRPP.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * Genome2D - 2D GPU Framework 3 | * http://www.genome2d.com 4 | * 5 | * Copyright 2011-2014 Peter Stefcek. All rights reserved. 6 | * 7 | * License:: ./doc/LICENSE.md (https://github.com/pshtif/Genome2D/blob/master/LICENSE.md) 8 | */ 9 | package com.genome2d.postprocess; 10 | #if flash 11 | import com.genome2d.context.GBlendMode; 12 | import com.genome2d.utils.GRenderTargetStack; 13 | import com.genome2d.context.IGContext; 14 | import com.genome2d.geom.GRectangle; 15 | import com.genome2d.node.GNode; 16 | import com.genome2d.context.GCamera; 17 | import com.genome2d.context.filters.GHDRPassFilter; 18 | import com.genome2d.textures.GTexture; 19 | 20 | class GHDRPP extends GPostProcess 21 | { 22 | private var g2d_empty:GFilterPP; 23 | private var g2d_blur:GBlurPP; 24 | private var g2d_hdrPassFilter:GHDRPassFilter; 25 | 26 | #if swc @:extern #end 27 | public var blurX(get, set):Int; 28 | #if swc @:getter(blurX) #end 29 | public function get_blurX():Int { 30 | return g2d_blur.blurX; 31 | } 32 | #if swc @:setter(blurX) #end 33 | public function set_blurX(p_value:Int):Int { 34 | g2d_blur.blurX = p_value; 35 | g2d_leftMargin = g2d_rightMargin = p_value*2*g2d_blur.passes; 36 | g2d_empty.setMargins(g2d_leftMargin, g2d_rightMargin, g2d_topMargin, g2d_bottomMargin); 37 | return p_value; 38 | } 39 | 40 | #if swc @:extern #end 41 | public var blurY(get, set):Int; 42 | #if swc @:getter(blurY) #end 43 | public function get_blurY():Int { 44 | return g2d_blur.blurY; 45 | } 46 | #if swc @:setter(blurY) #end 47 | public function set_blurY(p_value:Int):Int { 48 | g2d_blur.blurY = p_value; 49 | g2d_topMargin = g2d_bottomMargin = p_value*2*g2d_blur.passes; 50 | g2d_empty.setMargins(g2d_leftMargin, g2d_rightMargin, g2d_topMargin, g2d_bottomMargin); 51 | return p_value; 52 | } 53 | 54 | #if swc @:extern #end 55 | public var saturation(get, set):Float; 56 | #if swc @:getter(saturation) #end 57 | public function get_saturation():Float { 58 | return g2d_hdrPassFilter.saturation; 59 | } 60 | #if swc @:setter(saturation) #end 61 | public function set_saturation(p_value:Float):Float { 62 | g2d_hdrPassFilter.saturation = p_value; 63 | return p_value; 64 | } 65 | 66 | public function new(p_blurX:Int = 3, p_blurY:Int = 3, p_blurPasses:Int = 2, p_saturation:Float = 1.3) { 67 | super(2); 68 | 69 | g2d_leftMargin = g2d_rightMargin = p_blurX*2*p_blurPasses; 70 | g2d_topMargin = g2d_bottomMargin = p_blurY*2*p_blurPasses; 71 | 72 | g2d_empty = new GFilterPP([null]); 73 | g2d_empty.setMargins(g2d_leftMargin, g2d_rightMargin, g2d_topMargin, g2d_bottomMargin); 74 | 75 | g2d_blur = new GBlurPP(p_blurX, p_blurY, p_blurPasses); 76 | 77 | g2d_hdrPassFilter = new GHDRPassFilter(p_saturation); 78 | } 79 | 80 | override public function render(p_source:GTexture, p_x:Float, p_y:Float, p_bounds:GRectangle = null, p_target:GTexture = null):Void { 81 | var bounds:GRectangle = (p_bounds == null) ? bounds : p_bounds; 82 | // Invalid bounds 83 | if (bounds.x > 4096) return; 84 | 85 | updatePassTextures(bounds); 86 | 87 | var context:IGContext = Genome2D.getInstance().getContext(); 88 | if (p_target == null) GRenderTargetStack.pushRenderTarget(context.getRenderTarget(),context.getRenderTargetMatrix()); 89 | 90 | g2d_empty.render(p_source,p_x,p_y,bounds,g2d_passTextures[0]); 91 | g2d_blur.render(g2d_passTextures[0], 0, 0, bounds, g2d_passTextures[1]); 92 | 93 | g2d_hdrPassFilter.texture = g2d_empty.getPassTexture(0); 94 | 95 | if (p_target == null) { 96 | GRenderTargetStack.popRenderTarget(context); 97 | context.draw(g2d_passTextures[1], GBlendMode.NORMAL, bounds.x-g2d_leftMargin, bounds.y-g2d_topMargin, 1, 1, 0, 1, 1, 1, 1, g2d_hdrPassFilter); 98 | } else { 99 | context.setRenderTarget(p_target); 100 | context.draw(g2d_passTextures[1], GBlendMode.NORMAL, bounds.x-g2d_leftMargin, bounds.y-g2d_topMargin, 1, 1, 0, 1, 1, 1, 1, g2d_hdrPassFilter); 101 | } 102 | } 103 | 104 | override public function renderNode(p_parentTransformUpdate:Bool, p_parentColorUpdate:Bool, p_camera:GCamera, p_node:GNode, p_bounds:GRectangle = null, p_source:GTexture = null, p_target:GTexture = null):Void { 105 | var bounds:GRectangle = (bounds != null) ? bounds : p_node.getBounds(null, g2d_activeBounds); 106 | 107 | // Invalid bounds 108 | if (bounds.x > 4096) return; 109 | 110 | updatePassTextures(bounds); 111 | 112 | g2d_empty.renderNode(p_parentTransformUpdate, p_parentColorUpdate, p_camera, p_node, bounds, null, g2d_passTextures[0]); 113 | g2d_blur.renderNode(p_parentTransformUpdate, p_parentColorUpdate, p_camera, p_node, bounds, g2d_passTextures[0], g2d_passTextures[1]); 114 | 115 | g2d_hdrPassFilter.texture = g2d_empty.getPassTexture(0); 116 | 117 | var context:IGContext = Genome2D.getInstance().getContext(); 118 | 119 | context.setRenderTarget(null); 120 | context.setActiveCamera(p_camera); 121 | context.draw(g2d_passTextures[1], GBlendMode.NORMAL, bounds.x-g2d_leftMargin, bounds.y-g2d_topMargin, 1, 1, 0, 1, 1, 1, 1, g2d_hdrPassFilter); 122 | } 123 | 124 | override public function dispose():Void { 125 | g2d_blur.dispose(); 126 | 127 | super.dispose(); 128 | } 129 | } 130 | #end -------------------------------------------------------------------------------- /src/com/genome2d/g3d/importers/G3DImporter.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.g3d.importers; 2 | import com.genome2d.utils.GBytes; 3 | import com.genome2d.g3d.G3DScene; 4 | import com.genome2d.macros.MGDebug; 5 | import haxe.io.Bytes; 6 | 7 | /** 8 | * @author Peter @sHTiF Stefcek 9 | */ 10 | class G3DImporter extends G3DAbstractImporter 11 | { 12 | inline static private var g2d_version:Int = 102; 13 | 14 | public var processed:Bool = false; 15 | 16 | public function new(p_processed:Bool = false) { 17 | super(); 18 | processed = p_processed; 19 | } 20 | 21 | @:access(com.genome2d.g3d.G3DScene) 22 | override public function exportScene(p_scene:G3DScene, p_data:Bytes):Void { 23 | var wrap:GBytes = new GBytes(p_data); 24 | wrap.writeInt(g2d_version); 25 | for (node in p_scene.g2d_nodes) { 26 | if (Std.is(node, G3DTexture)) { 27 | wrap.writeByte(1); 28 | wrap.writeUTF(node.id); 29 | var texture:G3DTexture = cast node; 30 | wrap.writeUTF(texture.relativePath); 31 | } 32 | 33 | if (Std.is(node, G3DModel)) { 34 | wrap.writeByte(2); 35 | wrap.writeUTF(node.id); 36 | wrap.writeUTF(node.name); 37 | } 38 | 39 | if (Std.is(node, G3DMaterial)) { 40 | wrap.writeByte(3); 41 | wrap.writeUTF(node.id); 42 | } 43 | 44 | if (Std.is(node, G3DGeometry)) { 45 | wrap.writeByte(4); 46 | wrap.writeUTF(node.id); 47 | 48 | var geometry:G3DGeometry = cast node; 49 | wrap.writeInt(geometry.vertices.length); 50 | for (i in 0...geometry.vertices.length) { 51 | wrap.writeFloat(geometry.vertices[i]); 52 | } 53 | 54 | if (processed) { 55 | wrap.writeInt(geometry.uvs.length); 56 | for (i in 0...geometry.uvs.length) { 57 | wrap.writeFloat(geometry.uvs[i]); 58 | } 59 | } else { 60 | wrap.writeInt(geometry.importedUvs.length); 61 | for (i in 0...geometry.importedUvs.length) { 62 | wrap.writeFloat(geometry.importedUvs[i]); 63 | } 64 | } 65 | 66 | if (processed) { 67 | wrap.writeInt(geometry.indices.length); 68 | for (i in 0...geometry.indices.length) { 69 | wrap.writeInt(geometry.indices[i]); 70 | } 71 | } else { 72 | wrap.writeInt(geometry.importedIndices.length); 73 | for (i in 0...geometry.importedIndices.length) { 74 | wrap.writeInt(geometry.importedIndices[i]); 75 | } 76 | } 77 | 78 | wrap.writeInt(geometry.normals.length); 79 | for (i in 0...geometry.normals.length) { 80 | wrap.writeFloat(geometry.normals[i]); 81 | } 82 | 83 | if (!processed) { 84 | wrap.writeInt(geometry.importedUvIndices.length); 85 | for (i in 0...geometry.importedUvIndices.length) { 86 | wrap.writeInt(geometry.importedUvIndices[i]); 87 | } 88 | } 89 | } 90 | } 91 | 92 | var c:Int = 0; 93 | for (connection in p_scene.g2d_connections) { 94 | wrap.writeByte(5); 95 | wrap.writeUTF(connection.sourceId); 96 | wrap.writeUTF(connection.destinationId); 97 | c++; 98 | } 99 | } 100 | 101 | public function getSceneSize(p_scene:G3DScene):Void { 102 | var size:Int = 0; 103 | } 104 | 105 | override public function importScene(p_data:Bytes):G3DScene { 106 | var scene:G3DScene = new G3DScene(); 107 | 108 | var wrap:GBytes = new GBytes(p_data); 109 | var version:Int = wrap.readInt(); 110 | if (version != g2d_version) MGDebug.G2D_ERROR("G3D format version not compatible."); 111 | 112 | while (wrap.getBytesAvailable() > 0) { 113 | var type:Int = wrap.readByte(); 114 | switch (type) { 115 | case 1: 116 | var id:String = wrap.readUTF(); 117 | var relativePath:String = wrap.readUTF(); 118 | var texture:G3DTexture = new G3DTexture(id, relativePath); 119 | scene.addNode(texture.id, texture); 120 | case 2: 121 | var id:String = wrap.readUTF(); 122 | var model:G3DModel = new G3DModel(id); 123 | model.name = wrap.readUTF(); 124 | scene.addNode(model.id, model); 125 | case 3: 126 | var id:String = wrap.readUTF(); 127 | var material:G3DMaterial = new G3DMaterial(id); 128 | scene.addNode(material.id, material); 129 | case 4: 130 | var id:String = wrap.readUTF(); 131 | var count:Int = wrap.readInt(); 132 | var vertices:Array = new Array(); 133 | for (i in 0...count) { 134 | vertices.push(wrap.readFloat()); 135 | } 136 | var count:Int = wrap.readInt(); 137 | var uvs:Array = new Array(); 138 | for (i in 0...count) { 139 | uvs.push(wrap.readFloat()); 140 | } 141 | 142 | var count:Int = wrap.readInt(); 143 | var indices:Array = new Array(); 144 | for (i in 0...count) { 145 | indices.push(wrap.readInt()); 146 | } 147 | 148 | var count:Int = wrap.readInt(); 149 | var normals:Array = new Array(); 150 | for (i in 0...count) { 151 | normals.push(wrap.readFloat()); 152 | } 153 | 154 | var uvIndices:Array = new Array(); 155 | if (!processed) { 156 | var count:Int = wrap.readInt(); 157 | for (i in 0...count) { 158 | uvIndices.push(wrap.readInt()); 159 | } 160 | } 161 | 162 | var geometry:G3DGeometry = new G3DGeometry(id); 163 | if (processed) { 164 | geometry.initProcessed(vertices, uvs, indices, normals); 165 | } else { 166 | geometry.initImported(vertices, uvs, indices, uvIndices, normals); 167 | } 168 | scene.addNode(geometry.id, geometry); 169 | case 5: 170 | var sourceId:String = wrap.readUTF(); 171 | var destinationId:String = wrap.readUTF(); 172 | scene.addConnection(sourceId, destinationId); 173 | } 174 | } 175 | 176 | return scene; 177 | } 178 | 179 | } -------------------------------------------------------------------------------- /src/com/genome2d/proto/GPrototypeFactory.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.proto; 2 | 3 | import com.genome2d.macros.MGDebug; 4 | import com.genome2d.globals.GParameters; 5 | import Reflect; 6 | import com.genome2d.debug.GDebug; 7 | 8 | class GPrototypeFactory { 9 | static private var g2d_helper:GPrototypeHelper; 10 | static private var g2d_lookupsInitialized:Bool = false; 11 | static private var g2d_lookups:Map>; 12 | static private var g2d_prototypeReferences:Map; 13 | 14 | static public function getParameters():GParameters { 15 | // Somewhat of a hack since we use this part for code generation at macro time and even if it isn't executed macro prohibitons apply (platform dependant package import) 16 | #if !macro 17 | return Genome2D.getInstance().getParameters(); 18 | #else 19 | return null; 20 | #end 21 | } 22 | 23 | static private function initializePrototypes():Void { 24 | if (g2d_lookups != null) return; 25 | #if cs 26 | GPrototypeConstructorLookups.initialize(); 27 | #end 28 | g2d_lookups = new Map>(); 29 | g2d_prototypeReferences = new Map(); 30 | 31 | // For some reason when Haxe is compiled to JS it can't find classes generated during macro directly 32 | #if js 33 | var fields:Array = untyped Type.getClassFields(com_genome2d_proto_GPrototypeHelper); 34 | #else 35 | var fields:Array = Type.getClassFields(GPrototypeHelper); 36 | #end 37 | for (field in fields) { 38 | if (field.indexOf("g2d_") == 0) continue; 39 | #if js 40 | var cls:Class = cast Type.resolveClass(Reflect.field(untyped com_genome2d_proto_GPrototypeHelper, field)); 41 | #else 42 | var cls:Class = cast Type.resolveClass(Reflect.field(GPrototypeHelper, field)); 43 | #end 44 | if (cls != null) g2d_lookups.set(field, cls); 45 | } 46 | } 47 | 48 | static public function g2d_addReference(p_prototype:GPrototype):Void { 49 | g2d_prototypeReferences.set(p_prototype.id, p_prototype); 50 | } 51 | 52 | static public function g2d_removeReference(p_prototype:GPrototype):Void { 53 | g2d_prototypeReferences.remove(p_prototype.id); 54 | } 55 | 56 | static public function setPrototypeClass(p_prototypeName:String, p_class:Class):Void { 57 | g2d_lookups.set(p_prototypeName, p_class); 58 | } 59 | 60 | static public function getPrototypeClass(p_prototypeName:String):Class { 61 | return g2d_lookups.get(p_prototypeName); 62 | } 63 | 64 | static public function createInstance(p_prototype:GPrototype, p_args:Array = null):T { 65 | if (p_prototype.prototypeClass == null) { 66 | GDebug.error("Non existing prototype class "+p_prototype.prototypeName); 67 | } 68 | 69 | if (p_args == null) { 70 | #if cs 71 | p_args = GPrototypeConstructorLookups.getArguments(p_prototype.prototypeName); 72 | #else 73 | p_args = []; 74 | #end 75 | } 76 | //GDebug.info(p_prototype.prototypeClass, p_args, p_prototype.prototypeName); 77 | var proto:IGPrototypable = Type.createInstance(p_prototype.prototypeClass, p_args); 78 | if (proto == null) GDebug.error("Invalid prototype class " + p_prototype.prototypeName); 79 | 80 | if (p_prototype.referenceId == "") { 81 | proto.bindPrototype(p_prototype); 82 | } else { 83 | var ref:GPrototype = g2d_prototypeReferences.get(p_prototype.referenceId); 84 | if (ref != null) { 85 | proto.bindPrototype(ref); 86 | } else { 87 | MGDebug.WARNING("Invalid prototype reference "+p_prototype.referenceId); 88 | } 89 | } 90 | 91 | return cast proto; 92 | } 93 | 94 | static public function createPrototypeInstances(p_prototypes:Array):Array { 95 | var prototypeInstances:Array = new Array(); 96 | for (prototype in p_prototypes) { 97 | prototypeInstances.push(createInstance(prototype)); 98 | } 99 | return prototypeInstances; 100 | } 101 | 102 | static public function isValidProtototypeName(p_prototypeName:String):Bool { 103 | return g2d_lookups.exists(p_prototypeName); 104 | } 105 | /* 106 | static public function createEmptyPrototype(p_prototypeName:String):IGPrototypable { 107 | var prototypeClass:Class = g2d_lookups.get(p_prototypeName); 108 | if (prototypeClass == null) { 109 | GDebug.error("Non existing prototype class "+p_prototypeName); 110 | } 111 | 112 | var proto:IGPrototypable = Type.createInstance(prototypeClass,[]); 113 | if (proto == null) GDebug.error("Invalid prototype class "+p_prototypeName); 114 | 115 | return proto; 116 | } 117 | /* 118 | */ 119 | // TODO: Refactor accessibility, macro reading 120 | static public function g2d_getPrototype(p_prototype:GPrototype, p_instance:IGPrototypable, p_prototypeName:String):GPrototype { 121 | if (p_prototype == null) p_prototype = new GPrototype(); 122 | p_prototype.process(p_instance, p_prototypeName); 123 | 124 | return p_prototype; 125 | } 126 | 127 | // TODO: Refactor accessibility, macro reading 128 | static public function g2d_bindPrototype(p_instance:IGPrototypable, p_prototype:GPrototype, p_prototypeName:String):Void { 129 | if (p_prototype == null) GDebug.error("Null prototype"); 130 | if (p_instance.g2d_prototypeStates == null) p_instance.g2d_prototypeStates = new GPrototypeStates(); 131 | 132 | p_prototype.bind(p_instance, p_prototypeName); 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/com/genome2d/components/renderable/GTiledSprite.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.components.renderable; 2 | 3 | import com.genome2d.context.GBlendMode; 4 | import com.genome2d.input.GMouseInput; 5 | import com.genome2d.geom.GRectangle; 6 | import com.genome2d.context.GCamera; 7 | import com.genome2d.context.filters.GFilter; 8 | import com.genome2d.textures.GTexture; 9 | 10 | class GTiledSprite extends GComponent implements IGRenderable { 11 | /** 12 | Blend mode used for rendering 13 | **/ 14 | public var blendMode:GBlendMode; 15 | 16 | /** 17 | Specify alpha treshold for pixel perfect mouse detection, works with mousePixelEnabled true 18 | **/ 19 | public var mousePixelTreshold:Int = 0; 20 | 21 | /** 22 | Texture used for rendering 23 | **/ 24 | public var texture:GTexture; 25 | 26 | /** 27 | Filter used for rendering 28 | **/ 29 | public var filter:GFilter; 30 | 31 | public var ignoreMatrix:Bool = true; 32 | 33 | private var g2d_width:Float = 110; 34 | @prototype 35 | public var width(get, set):Float; 36 | #if swc @:getter(width) #end 37 | inline private function get_width():Float { 38 | return g2d_width; 39 | } 40 | #if swc @:setter(width) #end 41 | inline private function set_width(p_value:Float):Float { 42 | return g2d_width = p_value; 43 | } 44 | 45 | private var g2d_height:Float = 110; 46 | @prototype public var height(get, set):Float; 47 | #if swc @:getter(height) #end 48 | inline private function get_height():Float { 49 | return g2d_height; 50 | } 51 | #if swc @:setter(height) #end 52 | inline private function set_height(p_value:Float):Float { 53 | return g2d_height = p_value; 54 | } 55 | 56 | override public function init():Void { 57 | blendMode = GBlendMode.NORMAL; 58 | } 59 | 60 | @:dox(hide) 61 | public function render(p_camera:GCamera, p_useMatrix:Bool):Void { 62 | if (texture == null) return; 63 | 64 | // Check rotations 65 | var sin:Float = 0; 66 | var cos:Float = 1; 67 | if (node.g2d_worldRotation != 0) { 68 | sin = Math.sin(node.g2d_worldRotation); 69 | cos = Math.cos(node.g2d_worldRotation); 70 | } 71 | 72 | var ix:Int = Math.ceil(g2d_width/texture.width); 73 | var iy:Int = Math.ceil(g2d_height/texture.height); 74 | 75 | var w:Float = texture.region.width; 76 | var h:Float = texture.region.height; 77 | var cw:Float = w; 78 | var ch:Float = h; 79 | var cx:Float = 0; 80 | var cy:Float = 0; 81 | 82 | for (j in 0...iy) { 83 | for (i in 0...ix) { 84 | cw = (i==ix-1 && g2d_width%texture.width!=0) ? w*(g2d_width%texture.width)/texture.width : w; 85 | ch = (j==iy-1 && g2d_height%texture.height!=0) ? h*(g2d_height%texture.height)/texture.height : h; 86 | 87 | node.core.getContext().drawSource(texture, blendMode, 88 | texture.region.x, texture.region.y, cw, ch, -cw*.5, -ch*.5, 89 | node.g2d_worldX+cx*cos-cy*sin, node.g2d_worldY+cy*cos+cx*sin, node.g2d_worldScaleX, node.g2d_worldScaleY, node.g2d_worldRotation, 90 | node.g2d_worldRed, node.g2d_worldGreen, node.g2d_worldBlue, node.g2d_worldAlpha, 91 | filter); 92 | cx += cw*node.g2d_worldScaleX; 93 | } 94 | cx = 0; 95 | cy += ch*node.g2d_worldScaleY; 96 | } 97 | } 98 | 99 | @:dox(hide) 100 | public function captureMouseInput(p_input:GMouseInput):Void { 101 | /* 102 | if (p_captured && p_input.type == GMouseInputType.MOUSE_UP) node.g2d_mouseDownNode = null; 103 | 104 | if (p_captured || texture == null || g2d_width == 0 || g2d_height == 0 || node.g2d_worldScaleX == 0 || node.g2d_worldScaleY == 0) { 105 | if (node.g2d_mouseOverNode == node) node.dispatchMouseCallback(GMouseInputType.MOUSE_OUT, node, 0, 0, p_input); 106 | return false; 107 | } 108 | 109 | // Invert translations 110 | var tx:Float = p_input.worldX - node.g2d_worldX; 111 | var ty:Float = p_input.worldY - node.g2d_worldY; 112 | 113 | if (node.g2d_worldRotation != 0) { 114 | var cos:Float = Math.cos(-node.g2d_worldRotation); 115 | var sin:Float = Math.sin(-node.g2d_worldRotation); 116 | 117 | var ox:Float = tx; 118 | tx = (tx*cos - ty*sin); 119 | ty = (ty*cos + ox*sin); 120 | } 121 | 122 | tx /= node.g2d_worldScaleX*g2d_width; 123 | ty /= node.g2d_worldScaleY*g2d_height; 124 | 125 | if (tx >= 0 && tx <= 1 && ty >= 0 && ty <= 1) { 126 | node.dispatchMouseCallback(p_input.type, node, tx*g2d_width, ty*g2d_height, p_input); 127 | if (node.g2d_mouseOverNode != node) { 128 | node.dispatchMouseCallback(GMouseInputType.MOUSE_OVER, node, tx*g2d_width, ty*g2d_height, p_input); 129 | } 130 | 131 | return true; 132 | } else { 133 | if (node.g2d_mouseOverNode == node) { 134 | node.dispatchMouseCallback(GMouseInputType.MOUSE_OUT, node, tx*g2d_width, ty*g2d_height, p_input); 135 | } 136 | } 137 | /* 138 | */ 139 | } 140 | 141 | /** 142 | Get local bounds 143 | **/ 144 | public function getBounds(p_bounds:GRectangle = null):GRectangle { 145 | if (texture == null) { 146 | if (p_bounds != null) p_bounds.setTo(0, 0, 0, 0); 147 | else p_bounds = new GRectangle(0, 0, 0, 0); 148 | } else { 149 | if (p_bounds != null) p_bounds.setTo(0,0,g2d_width,g2d_height); 150 | else p_bounds = new GRectangle(0,0,g2d_width,g2d_height); 151 | } 152 | 153 | return p_bounds; 154 | } 155 | 156 | public function hitTest(p_x:Float, p_y:Float):Bool { 157 | return false; 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /src/com/genome2d/proto/parsers/GXmlPrototypeParser.hx: -------------------------------------------------------------------------------- 1 | package com.genome2d.proto.parsers; 2 | import haxe.rtti.Meta; 3 | import com.genome2d.macros.MGDebug; 4 | import com.genome2d.debug.GDebug; 5 | import com.genome2d.proto.GPrototype; 6 | import com.genome2d.proto.GPrototypeFactory; 7 | import com.genome2d.proto.GPrototypeSpecs; 8 | import com.genome2d.proto.IGPrototypable; 9 | 10 | /** 11 | * @author Peter @sHTiF Stefcek 12 | */ 13 | class GXmlPrototypeParser 14 | { 15 | static public function createPrototypeFromXmlString(p_xmlString:String):IGPrototypable { 16 | return GPrototypeFactory.createInstance(fromXml(Xml.parse(p_xmlString).firstElement())); 17 | } 18 | 19 | static public function toXml(p_prototype:GPrototype):Xml { 20 | var xml:Xml = Xml.createElement(p_prototype.prototypeName); 21 | for (property in p_prototype.properties) { 22 | if (property.isBasicType() || property.isReference() || property.isEnum) { 23 | xml.set(property.name, Std.string(property.value)); 24 | } else { 25 | if (property.isPrototype()) { 26 | var propertyXml:Xml = Xml.createElement("p:" + property.name); 27 | if (property.value != null) propertyXml.addChild(toXml(property.value)); 28 | xml.addChild(propertyXml); 29 | } else { 30 | GDebug.error("Error during prototype parsing unknown property type", property.type); 31 | } 32 | } 33 | } 34 | 35 | for (groupName in p_prototype.children.keys()) { 36 | var isDefaultChildGroup:Bool = (groupName == Reflect.field(p_prototype.prototypeClass, GPrototypeSpecs.PROTOTYPE_DEFAULT_CHILD_GROUP)); 37 | var groupXml:Xml = (isDefaultChildGroup) ? null : Xml.createElement(groupName); 38 | var group:Array = p_prototype.children.get(groupName); 39 | for (prototype in group) { 40 | if (!isDefaultChildGroup) groupXml.addChild(toXml(prototype)); 41 | else xml.addChild(toXml(prototype)); 42 | } 43 | if (!isDefaultChildGroup) xml.addChild(groupXml); 44 | } 45 | 46 | if (p_prototype.id != "") { 47 | xml.set("prototypeId", p_prototype.id); 48 | } else if (p_prototype.referenceId != ""){ 49 | xml.set("referenceId", p_prototype.referenceId); 50 | } 51 | 52 | return xml; 53 | } 54 | 55 | static private function setPropertyFromXml(p_prototype:GPrototype, p_name:String, p_value:Xml):Void { 56 | var split:Array = p_name.split("."); 57 | var lookupClass:Class = p_prototype.prototypeClass; 58 | var propertyNames:Array = Reflect.field(lookupClass, GPrototypeSpecs.PROTOTYPE_PROPERTY_NAMES); 59 | while (propertyNames.indexOf(split[0]) == -1 && lookupClass != null) { 60 | lookupClass = cast Type.getSuperClass(lookupClass); 61 | if (lookupClass != null) propertyNames = Reflect.field(lookupClass, GPrototypeSpecs.PROTOTYPE_PROPERTY_NAMES); 62 | } 63 | 64 | if (lookupClass != null) { 65 | var propertyTypes:Array = Reflect.field(lookupClass, GPrototypeSpecs.PROTOTYPE_PROPERTY_TYPES); 66 | var propertyExtras:Array = Reflect.field(lookupClass, GPrototypeSpecs.PROTOTYPE_PROPERTY_EXTRAS); 67 | var propertyIndex:Int = propertyNames.indexOf(split[0]); 68 | var meta = Reflect.getProperty(Meta.getFields(lookupClass),p_name); 69 | 70 | p_prototype.createPrototypeProperty(p_name, propertyTypes[propertyIndex], propertyExtras[propertyIndex], meta, fromXml(p_value)); 71 | } 72 | } 73 | 74 | static public function getPrototypeName(p_xml:Xml):String { 75 | if (p_xml.nodeType == Xml.Document) p_xml = p_xml.firstElement(); 76 | return p_xml.nodeName; 77 | } 78 | 79 | static public function fromXml(p_xml:Xml):GPrototype { 80 | if (p_xml.nodeType == Xml.Document) p_xml = p_xml.firstElement(); 81 | 82 | var prototype:GPrototype = new GPrototype(); 83 | 84 | prototype.prototypeName = p_xml.nodeName; 85 | prototype.prototypeClass = GPrototypeFactory.getPrototypeClass(prototype.prototypeName); 86 | if (prototype.prototypeClass == null) MGDebug.ERROR("Invalid prototype type", prototype.prototypeName); 87 | 88 | // This prototype is just a reference 89 | if (p_xml.get("referenceId") != null) { 90 | prototype.referenceId = p_xml.get("referenceId"); 91 | } else { 92 | //var propertyNames:Array = Reflect.field(prototype.prototypeClass, GPrototypeSpecs.PROTOTYPE_PROPERTY_NAMES); 93 | //var propertyDefaults:Array = Reflect.field(prototype.prototypeClass, GPrototypeSpecs.PROTOTYPE_PROPERTY_DEFAULTS); 94 | //var propertyTypes:Array = Reflect.field(prototype.prototypeClass, GPrototypeSpecs.PROTOTYPE_PROPERTY_TYPES); 95 | //var propertyExtras:Array = Reflect.field(prototype.prototypeClass, GPrototypeSpecs.PROTOTYPE_PROPERTY_EXTRAS); 96 | var defaultChildGroup:String = Reflect.field(prototype.prototypeClass, GPrototypeSpecs.PROTOTYPE_DEFAULT_CHILD_GROUP); 97 | 98 | // We are adding properties on attributes 99 | for (attribute in p_xml.attributes()) { 100 | // Special attribute for prototype referencing 101 | if (attribute == "prototypeId") { 102 | prototype.id = p_xml.get(attribute); 103 | } else { 104 | prototype.setPropertyFromString(attribute, p_xml.get(attribute)); 105 | } 106 | } 107 | 108 | for (element in p_xml.elements()) { 109 | // We are adding a node refering to property 110 | if (element.nodeName.indexOf("p:") == 0) { 111 | if (element.firstElement() == null) { 112 | prototype.setPropertyFromString(element.nodeName.substr(2), "null"); 113 | } else { 114 | setPropertyFromXml(prototype, element.nodeName.substr(2), element.firstElement()); 115 | } 116 | 117 | // We are adding a default group node 118 | } else if (element.nodeName == defaultChildGroup || defaultChildGroup == "*") { 119 | prototype.addChild(fromXml(element), defaultChildGroup); 120 | 121 | // Other group nodes 122 | } else { 123 | for (child in element.elements()) { 124 | prototype.addChild(fromXml(child), element.nodeName); 125 | } 126 | } 127 | } 128 | } 129 | 130 | return prototype; 131 | } 132 | 133 | static public function multipleFromXml(p_xml:Xml):Array { 134 | if (p_xml.nodeType == Xml.Document) p_xml = p_xml.firstElement(); 135 | 136 | var prototypes:Array = new Array(); 137 | 138 | for (element in p_xml.elements()) { 139 | var prototype:GPrototype = fromXml(element); 140 | prototypes.push(prototype); 141 | } 142 | 143 | return prototypes; 144 | } 145 | } --------------------------------------------------------------------------------