├── Assets └── mainfont.ttf ├── Libraries ├── Format │ └── format │ │ ├── abc │ │ ├── Context.hx │ │ ├── Data.hx │ │ ├── OpReader.hx │ │ ├── OpWriter.hx │ │ ├── Reader.hx │ │ └── Writer.hx │ │ ├── agal │ │ ├── Data.hx │ │ ├── Tools.hx │ │ └── Writer.hx │ │ ├── amf │ │ ├── Reader.hx │ │ ├── Tools.hx │ │ ├── Value.hx │ │ └── Writer.hx │ │ ├── amf3 │ │ ├── Amf3Array.hx │ │ ├── Reader.hx │ │ ├── Tools.hx │ │ ├── Value.hx │ │ └── Writer.hx │ │ ├── as1 │ │ ├── Constants.hx │ │ ├── Data.hx │ │ ├── Reader.hx │ │ └── Writer.hx │ │ ├── bmp │ │ ├── Data.hx │ │ ├── Reader.hx │ │ ├── Tools.hx │ │ └── Writer.hx │ │ ├── elf │ │ ├── Data.hx │ │ └── Reader.hx │ │ ├── flv │ │ ├── Data.hx │ │ ├── Reader.hx │ │ ├── Tools.hx │ │ └── Writer.hx │ │ ├── gif │ │ ├── Data.hx │ │ ├── Reader.hx │ │ ├── Tools.hx │ │ └── Writer.hx │ │ ├── gz │ │ ├── Data.hx │ │ └── Reader.hx │ │ ├── hl │ │ ├── Data.hx │ │ ├── Reader.hx │ │ └── Tools.hx │ │ ├── jpg │ │ ├── Data.hx │ │ └── Writer.hx │ │ ├── lz4 │ │ ├── Reader.hx │ │ └── Uncompress.hx │ │ ├── mp3 │ │ ├── Constants.hx │ │ ├── Data.hx │ │ ├── Reader.hx │ │ ├── Tools.hx │ │ └── Writer.hx │ │ ├── neko │ │ ├── Builtins.hx │ │ ├── Data.hx │ │ ├── Reader.hx │ │ ├── Templo.hx │ │ ├── VM.hx │ │ └── Value.hx │ │ ├── pbj │ │ ├── Data.hx │ │ ├── Reader.hx │ │ ├── Tools.hx │ │ └── Writer.hx │ │ ├── pdf │ │ ├── Crypt.hx │ │ ├── Data.hx │ │ ├── Extract.hx │ │ ├── Filter.hx │ │ └── Reader.hx │ │ ├── pex │ │ ├── Data.hx │ │ └── Reader.hx │ │ ├── png │ │ ├── Data.hx │ │ ├── Reader.hx │ │ ├── Tools.hx │ │ └── Writer.hx │ │ ├── swf │ │ ├── Constants.hx │ │ ├── Data.hx │ │ ├── Reader.hx │ │ ├── Tools.hx │ │ └── Writer.hx │ │ ├── tar │ │ ├── Data.hx │ │ ├── Reader.hx │ │ └── Writer.hx │ │ ├── tga │ │ ├── Data.hx │ │ ├── Reader.hx │ │ ├── Tools.hx │ │ └── Writer.hx │ │ ├── tgz │ │ ├── Data.hx │ │ └── Reader.hx │ │ ├── tools │ │ ├── Adler32.hx │ │ ├── ArcFour.hx │ │ ├── BitsInput.hx │ │ ├── BitsOutput.hx │ │ ├── BufferInput.hx │ │ ├── CRC32.hx │ │ ├── Deflate.hx │ │ ├── Huffman.hx │ │ ├── IO.hx │ │ ├── Image.hx │ │ ├── Inflate.hx │ │ ├── InflateImpl.hx │ │ ├── MD5.hx │ │ ├── MemoryBytes.hx │ │ └── MemoryInput.hx │ │ ├── wav │ │ ├── Data.hx │ │ ├── Reader.hx │ │ └── Writer.hx │ │ └── zip │ │ ├── Data.hx │ │ ├── Reader.hx │ │ ├── Tools.hx │ │ └── Writer.hx └── hxGeomAlgo │ ├── .gitignore │ ├── CHANGELOG.md │ ├── CREDITS.md │ ├── DrawUtils.hx │ ├── GeomAlgoTest.hx │ ├── LICENSE.md │ ├── OpenflDemo.hx │ ├── README.md │ ├── Test.hx │ └── hxGeomAlgo │ ├── Bayazit.hx │ ├── CCLabeler.hx │ ├── Debug.hx │ ├── EarCut.hx │ ├── Heap.hx │ ├── HertelMehlhorn.hx │ ├── HomogCoord.hx │ ├── HxPoint.hx │ ├── IsoContours.hx │ ├── MarchingSquares.hx │ ├── PairDeque.hx │ ├── PoleOfInaccessibility.hx │ ├── PolyTools.hx │ ├── RamerDouglasPeucker.hx │ ├── SnoeyinkKeil.hx │ ├── Tess2.hx │ ├── Version.hx │ ├── Visibility.hx │ └── VisvalingamWhyatt.hx ├── README.md ├── Shaders ├── 3d │ ├── mesh.frag.glsl │ ├── mesh.vert.glsl │ ├── meshBones.vert.glsl │ └── meshNoShade.frag.glsl └── Shaders │ ├── HighPassFilter.frag.glsl │ ├── ShBrightness.frag.glsl │ ├── alpha.vert.glsl │ ├── blurFragmentShader.frag.glsl │ ├── blur_pass.frag.glsl │ ├── filmGrain.frag.glsl │ ├── fov.frag.glsl │ ├── fxaa.frag.glsl │ ├── hBlurVertexShader.vert.glsl │ ├── mirage.frag.glsl │ ├── mosaic.frag.glsl │ ├── multiplyColor.frag.glsl │ ├── outline.frag.glsl │ ├── poly.frag.glsl │ ├── poly.vert.glsl │ ├── renderAreaTint.frag.glsl │ ├── rgbSplit.frag.glsl │ ├── shInverseMask.frag.glsl │ ├── shMask.frag.glsl │ ├── shMask.vert.glsl │ ├── shMaxBlend.frag.glsl │ ├── shMixGlow.frag.glsl │ ├── simple.frag.glsl │ ├── simple.vert.glsl │ ├── simpleAlpha.frag.glsl │ ├── simpleAlpha.vert.glsl │ ├── simpleColorTransformation.frag.glsl │ ├── simpleColorTransformation.vert.glsl │ ├── simpleLight.frag.glsl │ ├── simpleRgbSplit.frag.glsl │ ├── simpleTime.vert.glsl │ └── vBlurVertexShader.vert.glsl ├── Sources └── com │ ├── TimeManager.hx │ ├── basicDisplay │ └── SpriteSheetDB.hx │ ├── collision │ ├── box2d │ │ ├── Const.hx │ │ ├── DebugDisplay.hx │ │ ├── SimplePlayerCollision.hx │ │ └── Tilemap.hx │ └── platformer │ │ ├── Body.hx │ │ ├── Cart.hx │ │ ├── CollisionBox.hx │ │ ├── CollisionCircle.hx │ │ ├── CollisionEngine.hx │ │ ├── CollisionGroup.hx │ │ ├── CollisionTileMap.hx │ │ ├── CollisionType.hx │ │ ├── ICollider.hx │ │ ├── Sides.hx │ │ ├── Tilemap.hx │ │ ├── Track.hx │ │ └── TrackTools.hx │ ├── debug │ └── Profiler.hx │ ├── framework │ ├── Simulation.hx │ └── utils │ │ ├── Entity.hx │ │ ├── Input.hx │ │ ├── Interpolation.hx │ │ ├── JoystickProxy.hx │ │ ├── LERP.hx │ │ ├── Perlin.hx │ │ ├── Random.hx │ │ ├── SaveFile.hx │ │ ├── State.hx │ │ ├── UIComponent.hx │ │ ├── VirtualGamepad.hx │ │ └── XboxJoystick.hx │ ├── fx │ ├── Emitter.hx │ └── Particle.hx │ ├── g3d │ ├── Bone.hx │ ├── MeshExtractor.hx │ ├── Object3d.hx │ ├── Object3dBonesPainter.hx │ ├── Object3dDB.hx │ ├── Object3dData.hx │ ├── Object3dLoader.hx │ ├── Object3dPainter.hx │ ├── OgexData.hx │ ├── SkeletonD.hx │ ├── SkeletonLoader.hx │ ├── Skinning.hx │ └── fbx │ │ ├── Data.hx │ │ └── Parser.hx │ ├── gEngine │ ├── AnimationData.hx │ ├── AnimationTilesheetLinker.hx │ ├── DrawArea.hx │ ├── Filter.hx │ ├── FontData.hx │ ├── Frame.hx │ ├── GEngine.hx │ ├── Label.hx │ ├── PainterGarbage.hx │ ├── display │ │ ├── AreaEffect.hx │ │ ├── AreaEffectCircular.hx │ │ ├── BakeLayer.hx │ │ ├── Blend.hx │ │ ├── BlendMode.hx │ │ ├── Camera.hx │ │ ├── DisplayObject.hx │ │ ├── IAnimation.hx │ │ ├── IContainer.hx │ │ ├── IRotation.hx │ │ ├── Layer.hx │ │ ├── Polygon.hx │ │ ├── Sprite.hx │ │ ├── Stage.hx │ │ ├── StaticLayer.hx │ │ ├── Text.hx │ │ ├── TextNativeKha.hx │ │ └── extra │ │ │ ├── BakePainter.hx │ │ │ ├── MultiTileMapDisplay.hx │ │ │ ├── TileMapAdvanceDisplay.hx │ │ │ ├── TileMapDisplay.hx │ │ │ └── VertexBakeLayer.hx │ ├── helpers │ │ ├── FastmMatrix.hx │ │ ├── RectangleDisplay.hx │ │ ├── RenderTargetPool.hx │ │ ├── Screen.hx │ │ ├── SliderLayer.hx │ │ ├── Timeline.hx │ │ ├── UIComponent.hx │ │ ├── UIContainer.hx │ │ └── WaveText.hx │ ├── painters │ │ ├── IPainter.hx │ │ ├── PaintInfo.hx │ │ ├── PaintMode.hx │ │ ├── Painter.hx │ │ ├── PainterAlpha.hx │ │ ├── PainterColorTransform.hx │ │ └── PolyPainter.hx │ └── shaders │ │ ├── CacheTexture.hx │ │ ├── RenderPass.hx │ │ ├── ShAlpha.hx │ │ ├── ShBlurH.hx │ │ ├── ShBlurPass.hx │ │ ├── ShBlurV.hx │ │ ├── ShBrightness.hx │ │ ├── ShColorMul.hx │ │ ├── ShDontRender.hx │ │ ├── ShFOV.hx │ │ ├── ShFXAA.hx │ │ ├── ShFilmGrain.hx │ │ ├── ShHighPassFilter.hx │ │ ├── ShInverseMask.hx │ │ ├── ShMask.hx │ │ ├── ShMaxBlend.hx │ │ ├── ShMirage.hx │ │ ├── ShMixGlow.hx │ │ ├── ShMosaic.hx │ │ ├── ShOutline.hx │ │ ├── ShRender.hx │ │ ├── ShRenderCache.hx │ │ ├── ShRetro.hx │ │ ├── ShRgbSplit.hx │ │ └── ShTintRenderArea.hx │ ├── helpers │ ├── FastPoint.hx │ ├── MinMax.hx │ ├── Point.hx │ ├── Rectangle.hx │ ├── SIMDOperations.hx │ └── TilesToPolygons.hx │ ├── imageAtlas │ ├── AtlasGenerator.hx │ ├── Bitmap.hx │ ├── ImageTree.hx │ ├── Node.hx │ └── SingleImagePainter.hx │ ├── loading │ ├── AtlasJoinable.hx │ ├── Resource.hx │ ├── ResourceHandler.hx │ ├── Resources.hx │ └── basicResources │ │ ├── DataLoader.hx │ │ ├── FontKhaLoader.hx │ │ ├── FontLoader.hx │ │ ├── ImageLoader.hx │ │ ├── JoinAtlas.hx │ │ ├── SoundLoader.hx │ │ ├── SparrowLoader.hx │ │ ├── SpriteSheetLoader.hx │ │ └── TilesheetLoader.hx │ ├── sequencer │ └── SequenceCode.hx │ ├── soundLib │ └── SoundManager.hx │ └── target │ └── Html5.hx ├── haxelib.json └── khafile.js /Assets/mainfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juakob/khawy/164ba54f484060da505a8f8024d5ee9dfcdb5ee3/Assets/mainfont.ttf -------------------------------------------------------------------------------- /Libraries/Format/format/amf/Value.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * format - haXe File Formats 3 | * 4 | * Copyright (c) 2008, The haXe Project Contributors 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * - Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR 19 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25 | * DAMAGE. 26 | */ 27 | package format.amf; 28 | 29 | enum Value { 30 | ANumber( f : Float ); 31 | ABool( b : Bool ); 32 | AString( s : String ); 33 | AObject( fields : Map, ?size : Int ); 34 | ADate( d : Date ); 35 | AUndefined; 36 | ANull; 37 | AArray( values : Array ); 38 | } -------------------------------------------------------------------------------- /Libraries/Format/format/amf3/Amf3Array.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * format - haXe File Formats 3 | * 4 | * Copyright (c) 2008, The haXe Project Contributors 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * - Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR 19 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25 | * DAMAGE. 26 | */ 27 | package format.amf3; 28 | 29 | class Amf3Array 30 | { 31 | public var a:Array; 32 | @optional public var extra:Map; 33 | 34 | public function new(initA:Array, ?initExtra:Map) 35 | { 36 | a = initA; 37 | extra = initExtra; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Libraries/Format/format/amf3/Value.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * format - haXe File Formats 3 | * 4 | * Copyright (c) 2008, The haXe Project Contributors 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * - Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR 19 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25 | * DAMAGE. 26 | */ 27 | package format.amf3; 28 | 29 | import haxe.ds.Vector; 30 | 31 | enum Value { 32 | AUndefined; 33 | ANull; 34 | ABool( b : Bool ); 35 | AInt( i : Int ); 36 | ANumber( f : Float ); 37 | AString( s : String ); 38 | ADate( d : Date ); 39 | AObject( fields : Map, ?size : Int ); 40 | AArray( values : Array, ?extra : Map ); 41 | AVector( values : Vector ); 42 | AXml( x : Xml ); 43 | ABytes( b : haxe.io.Bytes ); 44 | AMap( m : Map ); 45 | } -------------------------------------------------------------------------------- /Libraries/Format/format/bmp/Data.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * format - haXe File Formats 3 | * 4 | * BMP File Format 5 | * Copyright (C) 2007-2009 Trevor McCauley, Baluta Cristian (hx port) & Robert Sköld (format conversion) 6 | * 7 | * Copyright (c) 2009, The haXe Project Contributors 8 | * All rights reserved. 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 12 | * - Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * - Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY 19 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 28 | * DAMAGE. 29 | */ 30 | package format.bmp; 31 | 32 | typedef Data = { 33 | var header : format.bmp.Header; 34 | var pixels : haxe.io.Bytes; 35 | } 36 | 37 | typedef Header = { 38 | var width : Int; // real width (in pixels) 39 | var height : Int; // real height (in pixels) 40 | var paddedStride : Int; // number of bytes in a stride (including padding) 41 | var topToBottom : Bool; // whether the bitmap is stored top to bottom 42 | var bpp : Int; // bits per pixel 43 | var dataLength : Int; // equal to `paddedStride` * `height` 44 | } -------------------------------------------------------------------------------- /Libraries/Format/format/elf/Data.hx: -------------------------------------------------------------------------------- 1 | package format.elf; 2 | 3 | typedef Address = haxe.Int64; 4 | 5 | typedef Header = { 6 | var is64 : Bool; 7 | var isBigEndian : Bool; 8 | var elfVersion : Int; 9 | var abiVersion : Int; 10 | var abiSubVersion : Int; 11 | var elfType : Int; 12 | var elfInstruction : Int; 13 | var entryPoint : Address; 14 | var programHeader : Address; 15 | var sectionHeader : Address; 16 | var flags : Int; 17 | var headerSize : Int; 18 | var programHeaderSize : Int; 19 | var programHeaderEntries : Int; 20 | var sectionHeaderSize : Int; 21 | var sectionHeaderEntries : Int; 22 | var sectionNameIndex : Int; 23 | } 24 | 25 | typedef SectionHeader = { 26 | var nameIndex : Int; 27 | var type : Int; 28 | var flags : haxe.Int64; 29 | var address : Address; 30 | var offset : Address; 31 | var size : haxe.Int64; 32 | var link : Int; 33 | var info : Int; 34 | var addressAlign : Int; 35 | var entSize : Int; 36 | } 37 | 38 | typedef Data = { 39 | var header : Header; 40 | var sections : Array; 41 | var data : haxe.io.Bytes; 42 | } -------------------------------------------------------------------------------- /Libraries/Format/format/elf/Reader.hx: -------------------------------------------------------------------------------- 1 | package format.elf; 2 | import format.elf.Data; 3 | 4 | class Reader { 5 | 6 | var i : haxe.io.Input; 7 | var is64 : Bool; 8 | var data : haxe.io.Bytes; 9 | 10 | public function new(i) { 11 | this.i = i; 12 | } 13 | 14 | public function read() : Data { 15 | var h = readHeader(); 16 | data = i.read(h.sectionHeader.low - h.headerSize); // go to section header 17 | var sections = [for( i in 0...h.sectionHeaderEntries ) readSectionHeader()]; 18 | return { 19 | header : h, 20 | sections : sections, 21 | data : data, 22 | }; 23 | } 24 | 25 | function readAddress() : Address { 26 | return is64 ? haxe.Int64.make(i.readInt32(), i.readInt32()) : i.readInt32(); 27 | } 28 | 29 | inline function read64() { 30 | return readAddress(); 31 | } 32 | 33 | function readSectionHeader() { 34 | return { 35 | nameIndex : i.readInt32(), 36 | type : i.readInt32(), 37 | flags : read64(), 38 | address : readAddress(), 39 | offset : readAddress(), 40 | size : read64(), 41 | link : i.readInt32(), 42 | info : i.readInt32(), 43 | addressAlign : i.readInt32(), 44 | entSize : i.readInt32(), 45 | }; 46 | } 47 | 48 | function readHeader() : Header { 49 | if( i.readString(4) != "\x7fELF" ) throw "Invalid ELF file"; 50 | is64 = i.readByte() == 2; 51 | var isBE = i.readByte() == 2; 52 | return { 53 | is64 : is64, 54 | isBigEndian : isBE, 55 | elfVersion : i.readByte(), 56 | abiVersion : i.readByte(), 57 | abiSubVersion : i.readByte(), 58 | elfType : { 59 | i.readString(7); // unused 60 | i.readUInt16(); 61 | }, 62 | elfInstruction : i.readUInt16(), 63 | entryPoint : { 64 | var v = i.readInt32(); 65 | if( v != 1 ) throw "Invalid version "+v; 66 | readAddress(); 67 | }, 68 | programHeader : readAddress(), 69 | sectionHeader : readAddress(), 70 | flags : i.readInt32(), 71 | headerSize : i.readUInt16(), 72 | programHeaderSize : i.readUInt16(), 73 | programHeaderEntries : i.readUInt16(), 74 | sectionHeaderSize : i.readUInt16(), 75 | sectionHeaderEntries : i.readUInt16(), 76 | sectionNameIndex : i.readUInt16(), 77 | }; 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /Libraries/Format/format/flv/Data.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * format - haXe File Formats 3 | * 4 | * Copyright (c) 2008, The haXe Project Contributors 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * - Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR 19 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25 | * DAMAGE. 26 | */ 27 | package format.flv; 28 | 29 | typedef Header = { 30 | var hasAudio : Bool; 31 | var hasVideo : Bool; 32 | var hasMeta : Bool; 33 | } 34 | 35 | enum Data { 36 | FLVAudio( data : haxe.io.Bytes, time : Int ); 37 | FLVVideo( data : haxe.io.Bytes, time : Int ); 38 | FLVMeta( data : haxe.io.Bytes, time : Int ); 39 | } -------------------------------------------------------------------------------- /Libraries/Format/format/flv/Tools.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * format - haXe File Formats 3 | * 4 | * Copyright (c) 2008, The haXe Project Contributors 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * - Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR 19 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25 | * DAMAGE. 26 | */ 27 | package format.flv; 28 | 29 | class Tools { 30 | 31 | public static function isVideoKeyFrame( data : haxe.io.Bytes ) { 32 | return (data.get(0) >> 4) == 1; 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /Libraries/Format/format/flv/Writer.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * format - haXe File Formats 3 | * 4 | * Copyright (c) 2008, The haXe Project Contributors 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * - Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR 19 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25 | * DAMAGE. 26 | */ 27 | package format.flv; 28 | import format.flv.Data; 29 | 30 | class Writer { 31 | 32 | var ch : haxe.io.Output; 33 | 34 | public function new(o) { 35 | this.ch = o; 36 | o.bigEndian = true; 37 | } 38 | 39 | public function close() { 40 | ch.close(); 41 | } 42 | 43 | public function writeHeader( h : Header ) { 44 | ch.writeString("FLV"); 45 | ch.writeByte(0x01); 46 | ch.writeByte( (h.hasAudio?1:0) | (h.hasVideo?4:0) | (h.hasMeta?8:0) ); 47 | #if haxe3 48 | ch.writeInt32(0x09); 49 | ch.writeInt32(0x00); 50 | #else 51 | ch.writeUInt30(0x09); 52 | ch.writeUInt30(0x00); 53 | #end 54 | } 55 | 56 | public function writeChunk( chunk : Data ) { 57 | var k, data, time; 58 | switch( chunk ) { 59 | case FLVAudio(d,t): k = 0x08; data = d; time = t; 60 | case FLVVideo(d,t): k = 0x09; data = d; time = t; 61 | case FLVMeta(d,t): k = 0x12; data = d; time = t; 62 | } 63 | ch.writeByte(k); 64 | ch.writeUInt24(data.length); 65 | ch.writeUInt24(time); 66 | #if haxe3 67 | ch.writeInt32(0); 68 | ch.write(data); 69 | ch.writeInt32(data.length + 11); 70 | #else 71 | ch.writeUInt30(0); 72 | ch.write(data); 73 | ch.writeUInt30(data.length + 11); 74 | #end 75 | } 76 | 77 | } -------------------------------------------------------------------------------- /Libraries/Format/format/gz/Data.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * format - haXe File Formats 3 | * 4 | * Copyright (c) 2008, The haXe Project Contributors 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * - Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR 19 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25 | * DAMAGE. 26 | */ 27 | package format.gz; 28 | 29 | typedef Header = { 30 | var fileName : String; 31 | var comments : String; 32 | var extraData : haxe.io.Bytes; 33 | } 34 | -------------------------------------------------------------------------------- /Libraries/Format/format/jpg/Data.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * format - haXe File Formats 3 | * 4 | * JPG File Format 5 | * Copyright (C) 2007-2009 Trevor McCauley, Baluta Cristian (hx port) & Robert Sköld (format conversion) 6 | * 7 | * Copyright (c) 2009, The haXe Project Contributors 8 | * All rights reserved. 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 12 | * - Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * - Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY 19 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 28 | * DAMAGE. 29 | */ 30 | package format.jpg; 31 | 32 | typedef Data = { 33 | var width : Int; 34 | var height : Int; 35 | var quality : Float; 36 | var pixels : haxe.io.Bytes; 37 | } 38 | -------------------------------------------------------------------------------- /Libraries/Format/format/lz4/Reader.hx: -------------------------------------------------------------------------------- 1 | package format.lz4; 2 | 3 | class Reader { 4 | 5 | var bytes : haxe.io.Bytes; 6 | var pos : Int; 7 | 8 | public function new() { 9 | } 10 | 11 | inline function b() { 12 | return bytes.get(pos++); 13 | } 14 | 15 | function grow( out : haxe.io.Bytes, pos : Int, len : Int ) { 16 | var size = out.length; 17 | do { 18 | size = (size * 3) >> 1; 19 | } while( size < pos + len ); 20 | var out2 = haxe.io.Bytes.alloc(size); 21 | out2.blit(0, out, 0, pos); 22 | return out2; 23 | } 24 | 25 | public function read( bytes : haxe.io.Bytes ) : haxe.io.Bytes { 26 | this.bytes = bytes; 27 | this.pos = 0; 28 | if( b() != 0x04 || b() != 0x22 || b() != 0x4D || b() != 0x18 ) 29 | throw "Invalid header"; 30 | var flags = b(); 31 | 32 | if( flags >> 6 != 1 ) 33 | throw "Invalid version " + (flags >> 6); 34 | var blockChecksum = flags & 16 != 0; 35 | var streamSize = flags & 8 != 0; 36 | var streamChecksum = flags & 4 != 0; 37 | if( flags & 2 != 0 ) throw "assert"; 38 | var presetDict = flags & 1 != 0; 39 | 40 | var bd = b(); 41 | if( bd & 128 != 0 ) throw "assert"; 42 | var maxBlockSize = [0, 0, 0, 0, 1 << 16, 1 << 18, 1 << 20, 1 << 22][(bd >> 4) & 7]; 43 | if( maxBlockSize == 0 ) throw "assert"; 44 | if( bd & 15 != 0 ) throw "assert"; 45 | 46 | if( streamSize ) 47 | pos += 8; 48 | if( presetDict ) 49 | throw "Preset dictionary not supported"; 50 | 51 | var headerChk = b(); // does not check 52 | 53 | var out = haxe.io.Bytes.alloc(128); 54 | var outPos = 0; 55 | 56 | while( true ) { 57 | var size = b() | (b() << 8) | (b() << 16) | (b() << 24); 58 | if( size == 0 ) break; 59 | // skippable chunk 60 | if( size & 0xFFFFFFF0 == 0x184D2A50 ) { 61 | var dataSize = b() | (b() << 8) | (b() << 16) | (b() << 24); 62 | pos += dataSize; 63 | continue; 64 | } 65 | if( size & 0x80000000 != 0 ) { 66 | // uncompressed block 67 | size &= 0x7FFFFFFF; 68 | if( outPos + out.length < size ) out = grow(out,outPos, size); 69 | out.blit(outPos, bytes, pos, size); 70 | outPos += size; 71 | pos += size; 72 | } else { 73 | if( outPos + out.length < size ) out = grow(out, outPos, 3000000); 74 | outPos += Uncompress.run(bytes, pos, size, out, outPos); 75 | pos += size; 76 | } 77 | if( blockChecksum ) pos += 4; 78 | } 79 | 80 | return out.sub(0, outPos); 81 | } 82 | 83 | } -------------------------------------------------------------------------------- /Libraries/Format/format/lz4/Uncompress.hx: -------------------------------------------------------------------------------- 1 | package format.lz4; 2 | 3 | class Uncompress { 4 | 5 | public static function run( src : haxe.io.Bytes, srcPos : Int, srcLen : Int, out : haxe.io.Bytes, outPos : Int ) { 6 | var outSave = outPos; 7 | var srcEnd = srcPos + srcLen; 8 | if( srcLen == 0 ) 9 | return 0; 10 | #if flash 11 | flash.Memory.select(out.getData()); 12 | #end 13 | while( true ) { 14 | var tk = src.get(srcPos++); 15 | var litLen = tk >> 4; 16 | var matchLen = tk & 15; 17 | if( litLen == 15 ) { 18 | var b; 19 | do { 20 | b = src.get(srcPos++); 21 | litLen += b; 22 | } while( b == 0xFF ); 23 | } 24 | inline function write(v) { 25 | #if flash 26 | flash.Memory.setByte(outPos, v); 27 | #else 28 | out.set(outPos, v); 29 | #end 30 | outPos++; 31 | } 32 | switch( litLen ) { 33 | case 0: 34 | case 1: 35 | write(src.get(srcPos++)); 36 | case 2: 37 | write(src.get(srcPos++)); 38 | write(src.get(srcPos++)); 39 | case 3: 40 | write(src.get(srcPos++)); 41 | write(src.get(srcPos++)); 42 | write(src.get(srcPos++)); 43 | default: 44 | out.blit(outPos, src, srcPos, litLen); 45 | outPos += litLen; 46 | srcPos += litLen; 47 | } 48 | if( srcPos >= srcEnd ) break; 49 | var offset = src.get(srcPos++); 50 | offset |= src.get(srcPos++) << 8; 51 | if( matchLen == 15 ) { 52 | var b; 53 | do { 54 | b = src.get(srcPos++); 55 | matchLen += b; 56 | } while( b == 0xFF ); 57 | } 58 | matchLen += 4; 59 | if( matchLen >= 64 && matchLen <= offset ) { 60 | out.blit(outPos, out, outPos - offset, matchLen); 61 | outPos += matchLen; 62 | } else { 63 | var copyEnd = outPos + matchLen; 64 | while( outPos < copyEnd ) 65 | write(#if flash flash.Memory.getByte(outPos - offset) #else out.get(outPos - offset) #end); 66 | } 67 | } 68 | if( srcPos != srcEnd ) throw "Read too much data " + (srcPos - srcLen); 69 | return outPos - outSave; 70 | } 71 | 72 | } -------------------------------------------------------------------------------- /Libraries/Format/format/pdf/Data.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * format - haXe File Formats 3 | * 4 | * Copyright (c) 2008, The haXe Project Contributors 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * - Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR 19 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25 | * DAMAGE. 26 | */ 27 | package format.pdf; 28 | 29 | enum Data { 30 | DNull; 31 | DBool( b : Bool ); 32 | DNumber( n : Float ); 33 | DString( s : String ); 34 | DHexString( s : String ); 35 | DName( s : String ); 36 | DArray( a : Array ); 37 | DDict( h : Map ); 38 | DIndirect( id : Int, rev : Int, v : Data ); 39 | DStream( b : haxe.io.Bytes, props : Map ); 40 | DRef( id : Int, rev : Int ); 41 | DXRefTable( t : Array<{ start : Int, entries : Array<{ offset : Int, gen : Int, used : Bool }> }> ); 42 | DTrailer( o : Data ); 43 | DStartXRef( pos : Int ); 44 | DComment( s : String ); 45 | } 46 | -------------------------------------------------------------------------------- /Libraries/Format/format/pdf/Extract.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * format - haXe File Formats 3 | * 4 | * Copyright (c) 2008, The haXe Project Contributors 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * - Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR 19 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25 | * DAMAGE. 26 | */ 27 | package format.pdf; 28 | 29 | class Extract { 30 | 31 | static function expect( kind, o : Data ) : Dynamic { 32 | return throw kind+" expected but "+Std.string(o)+" found"; 33 | } 34 | 35 | public static function int( o : Data ) { 36 | if( o == null ) expect("int",o); 37 | return switch( o ) { 38 | case DNumber(n): 39 | var i = Std.int(n); 40 | if( i != n ) expect("int",o); 41 | i; 42 | default: 43 | expect("int",o); 44 | } 45 | } 46 | 47 | public static function string( o : Data ) { 48 | if( o == null ) expect("string",o); 49 | return switch( o ) { 50 | case DString(s), DHexString(s): s; 51 | default: expect("string",o); 52 | } 53 | } 54 | 55 | public static function bool( o : Data, ?def : Bool ) { 56 | if( o == null ) { 57 | if( def == null ) expect("bool",o); 58 | return def; 59 | } 60 | return switch( o ) { 61 | case DBool(b): b; 62 | default: expect("bool",o); 63 | } 64 | } 65 | 66 | } -------------------------------------------------------------------------------- /Libraries/Format/format/pex/Data.hx: -------------------------------------------------------------------------------- 1 | package format.pex; 2 | 3 | @:enum 4 | abstract EmitterType(Int) from Int to Int 5 | { 6 | var Gravity = 0; 7 | var Radial = 1; 8 | } 9 | 10 | @:enum 11 | abstract BlendFunction(Int) from Int to Int 12 | { 13 | var Zero = 0; 14 | var One = 1; 15 | var SourceColor = 0x300; 16 | var OneMinusSourceColor = 0x301; 17 | var SourceAlpha = 0x302; 18 | var OneMinusSourceAlpha = 0x303; 19 | var DestinationAlpha = 0x304; 20 | var OneMinusDestinationAlpha = 0x305; 21 | var DestinationColor = 0x306; 22 | var OneMinusDestinationColor = 0x307; 23 | } 24 | 25 | @:forward(base, variance) 26 | abstract ValueWithVariance({base:T, variance:T}) 27 | { 28 | public inline function new(base:T, variance:T) 29 | { 30 | this = {base:base, variance:variance}; 31 | } 32 | 33 | /** 34 | * Choose a random float within this range. 35 | */ 36 | public inline function random():Float 37 | { 38 | return this.base + (Math.random() * 2 - 1) * this.variance; 39 | } 40 | 41 | /** 42 | * Choose a random integer within this range. 43 | */ 44 | public inline function randomInt():Int 45 | { 46 | return Std.int(Math.round(random())); 47 | } 48 | } 49 | 50 | typedef FloatWithVariance = ValueWithVariance; 51 | typedef UIntWithVariance = ValueWithVariance; 52 | 53 | class PexParticle 54 | { 55 | public var emitterType:EmitterType = EmitterType.Gravity; 56 | public var textureName:String; 57 | public var emitterXVariance:Float = 0; 58 | public var emitterYVariance:Float = 0; 59 | public var duration:Float = 0; 60 | public var maxParticles:Int = 0; 61 | 62 | public var lifespan:FloatWithVariance; 63 | public var startSize:FloatWithVariance; 64 | public var endSize:FloatWithVariance; 65 | public var emitAngle:FloatWithVariance; 66 | public var startRotation:FloatWithVariance; 67 | public var endRotation:FloatWithVariance; 68 | 69 | public var speed:FloatWithVariance; 70 | public var gravityX:Float = 0; 71 | public var gravityY:Float = 0; 72 | public var radialAcceleration:FloatWithVariance; 73 | public var tangentialAcceleration:FloatWithVariance; 74 | 75 | public var maxRadius:FloatWithVariance; 76 | public var minRadius:FloatWithVariance; 77 | public var rotatePerSecond:FloatWithVariance; 78 | 79 | public var startColor:UIntWithVariance; 80 | public var endColor:UIntWithVariance; 81 | 82 | public var blendSource:BlendFunction; 83 | public var blendDestination:BlendFunction; 84 | 85 | public function new() {} 86 | } 87 | -------------------------------------------------------------------------------- /Libraries/Format/format/png/Data.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * format - haXe File Formats 3 | * 4 | * Copyright (c) 2008-2009, The haXe Project Contributors 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * - Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR 19 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25 | * DAMAGE. 26 | */ 27 | package format.png; 28 | 29 | enum Color { 30 | ColGrey( alpha : Bool ) ; // 1|2|4|8|16 without alpha , 8|16 with alpha 31 | ColTrue( alpha : Bool ); // 8|16 32 | ColIndexed; // 1|2|4|8 33 | } 34 | 35 | typedef Header = { 36 | var width : Int; 37 | var height : Int; 38 | var colbits : Int; 39 | var color : Color; 40 | var interlaced : Bool; 41 | } 42 | 43 | enum Chunk { 44 | CEnd; 45 | CHeader( h : Header ); 46 | CData( b : haxe.io.Bytes ); 47 | CPalette( b : haxe.io.Bytes ); 48 | CUnknown( id : String, data : haxe.io.Bytes ); 49 | } 50 | 51 | typedef Data = List; 52 | -------------------------------------------------------------------------------- /Libraries/Format/format/tar/Data.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * format - haXe File Formats 3 | * 4 | * Copyright (c) 2008, The haXe Project Contributors 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * - Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR 19 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25 | * DAMAGE. 26 | */ 27 | package format.tar; 28 | 29 | typedef Entry = { 30 | var fileName : String; 31 | var fileSize : Int; 32 | var fileTime : Date; 33 | var fmod : Int; 34 | var uid : Int; 35 | var gid : Int; 36 | var uname : String; 37 | var gname : String; 38 | var data : Null; 39 | } 40 | 41 | typedef Data = List; -------------------------------------------------------------------------------- /Libraries/Format/format/tgz/Data.hx: -------------------------------------------------------------------------------- 1 | package format.tgz; 2 | 3 | typedef Data = format.tar.Data; -------------------------------------------------------------------------------- /Libraries/Format/format/tgz/Reader.hx: -------------------------------------------------------------------------------- 1 | package format.tgz; 2 | 3 | class Reader { 4 | 5 | var i : haxe.io.Input; 6 | 7 | public function new(i) { 8 | this.i = i; 9 | } 10 | 11 | public function read() : Data { 12 | var tmp = new haxe.io.BytesOutput(); 13 | var gz = new format.gz.Reader(i); 14 | gz.readHeader(); 15 | gz.readData(tmp); 16 | return new format.tar.Reader(new haxe.io.BytesInput(tmp.getBytes())).read(); 17 | } 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /Libraries/Format/format/tools/Adler32.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * format - haXe File Formats 3 | * 4 | * Copyright (c) 2008, The haXe Project Contributors 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * - Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR 19 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25 | * DAMAGE. 26 | */ 27 | package format.tools; 28 | 29 | class Adler32 { 30 | 31 | var a1 : Int; 32 | var a2 : Int; 33 | 34 | public function new() { 35 | a1 = 1; 36 | a2 = 0; 37 | } 38 | 39 | public function update( b : haxe.io.Bytes, pos, len ) { 40 | var a1 = a1, a2 = a2; 41 | for( p in pos...pos + len ) { 42 | var c = b.get(p); 43 | a1 = (a1 + c) % 65521; 44 | a2 = (a2 + a1) % 65521; 45 | } 46 | this.a1 = a1; 47 | this.a2 = a2; 48 | } 49 | 50 | public function equals( a : Adler32 ) { 51 | return a.a1 == a1 && a.a2 == a2; 52 | } 53 | 54 | public static function read( i : haxe.io.Input ) { 55 | var a = new Adler32(); 56 | var a2a = i.readByte(); 57 | var a2b = i.readByte(); 58 | var a1a = i.readByte(); 59 | var a1b = i.readByte(); 60 | a.a1 = (a1a << 8) | a1b; 61 | a.a2 = (a2a << 8) | a2b; 62 | return a; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /Libraries/Format/format/tools/ArcFour.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * format - haXe File Formats 3 | * 4 | * Copyright (c) 2008, The haXe Project Contributors 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * - Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR 19 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25 | * DAMAGE. 26 | */ 27 | package format.tools; 28 | 29 | class ArcFour { 30 | 31 | var s : haxe.io.Bytes; 32 | var sbase : haxe.io.Bytes; 33 | var i : Int; 34 | var j : Int; 35 | 36 | public function new( key : haxe.io.Bytes ) { 37 | var s = haxe.io.Bytes.alloc(256); 38 | for( i in 0...256 ) 39 | s.set(i,i); 40 | var j = 0; 41 | var klen = key.length; 42 | for( i in 0...256 ) { 43 | j = (j + s.get(i) + key.get(i % klen)) & 255; 44 | var tmp = s.get(i); 45 | s.set(i,s.get(j)); 46 | s.set(j,tmp); 47 | } 48 | sbase = s; 49 | this.s = sbase.sub(0,256); 50 | this.i = 0; 51 | this.j = 0; 52 | } 53 | 54 | public function reset() { 55 | this.i = 0; 56 | this.j = 0; 57 | this.s.blit(0,sbase,0,256); 58 | } 59 | 60 | public function run( input : haxe.io.Bytes, ipos : Int, length : Int, output : haxe.io.Bytes, opos : Int ) { 61 | var i = this.i; 62 | var j = this.j; 63 | var s = this.s; 64 | for( p in 0...length ) { 65 | i = (i + 1) & 255; 66 | var a = s.get(i); 67 | j = (j + a) & 255; 68 | var b = s.get(j); 69 | s.set(i,b); 70 | s.set(j,a); 71 | output.set(opos + p, input.get(ipos + p) ^ s.get((a+b)&255) ); 72 | } 73 | this.i = i; 74 | this.j = j; 75 | } 76 | 77 | } -------------------------------------------------------------------------------- /Libraries/Format/format/tools/BitsInput.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * format - haXe File Formats 3 | * 4 | * Copyright (c) 2008, The haXe Project Contributors 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * - Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR 19 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25 | * DAMAGE. 26 | */ 27 | package format.tools; 28 | 29 | class BitsInput { 30 | 31 | var i : haxe.io.Input; 32 | var nbits : Int; 33 | var bits : Int; 34 | 35 | public function new(i) { 36 | this.i = i; 37 | nbits = 0; 38 | bits = 0; 39 | } 40 | 41 | public function readBits(n) { 42 | if( nbits >= n ) { 43 | var c = nbits - n; 44 | var k = (bits >>> c) & ((1 << n) - 1); 45 | nbits = c; 46 | return k; 47 | } 48 | var k = i.readByte(); 49 | if( nbits >= 24 ) { 50 | if( n > 31 ) throw "Bits error"; 51 | var c = 8 + nbits - n; 52 | var d = bits & ((1 << nbits) - 1); 53 | d = (d << (8 - c)) | (k << c); 54 | bits = k; 55 | nbits = c; 56 | return d; 57 | } 58 | bits = (bits << 8) | k; 59 | nbits += 8; 60 | return readBits(n); 61 | } 62 | 63 | public function readBit() { 64 | if( nbits == 0 ) { 65 | bits = i.readByte(); 66 | nbits = 8; 67 | } 68 | nbits--; 69 | return ((bits >>> nbits) & 1) == 1; 70 | } 71 | 72 | public inline function reset() { 73 | nbits = 0; 74 | } 75 | 76 | } 77 | 78 | -------------------------------------------------------------------------------- /Libraries/Format/format/tools/BitsOutput.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * format - haXe File Formats 3 | * 4 | * Copyright (c) 2008, The haXe Project Contributors 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * - Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR 19 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25 | * DAMAGE. 26 | */ 27 | package format.tools; 28 | 29 | class BitsOutput { 30 | 31 | public var o : haxe.io.Output; 32 | var nbits : Int; 33 | var bits : Int; 34 | 35 | public function new(o) { 36 | this.o = o; 37 | nbits = 0; 38 | bits = 0; 39 | } 40 | 41 | public function writeBits(n: Int, v: Int) { 42 | // Clear unused bits 43 | v = v & ((1 << n ) - 1); 44 | if( n + nbits >= 32 ) { 45 | if( n >= 31 ) throw "Bits error"; 46 | var n2 = 32 - nbits - 1; 47 | var n3 = n - n2; 48 | writeBits(n2,v >>> n3); 49 | writeBits(n3,v & ((1 << n3) - 1)); 50 | return; 51 | } 52 | if( n < 0 ) throw "Bits error"; 53 | //if(n < 31) 54 | //if( (v < 0 || v > (1 << n) - 1) && n != 31 ) throw "Bits error"; 55 | bits = (bits << n) | v; 56 | nbits += n; 57 | while( nbits >= 8 ) { 58 | nbits -= 8; 59 | o.writeByte((bits >>> nbits) & 0xFF); 60 | } 61 | } 62 | 63 | public function writeBit(flag) { 64 | bits <<= 1; 65 | if( flag ) bits |= 1; 66 | nbits++; 67 | if( nbits == 8 ) { 68 | nbits = 0; 69 | o.writeByte(bits & 0xFF); 70 | } 71 | } 72 | 73 | public inline function flush() { 74 | if( nbits > 0 ) { 75 | writeBits(8-nbits,0); 76 | nbits = 0; 77 | } 78 | } 79 | 80 | } 81 | 82 | -------------------------------------------------------------------------------- /Libraries/Format/format/tools/BufferInput.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * format - haXe File Formats 3 | * 4 | * inflate format decompression algorithm 5 | * Copyright (C) 2004-2008 Nicolas Cannasse 6 | * Compliant with RFC 1950 and 1951 7 | * 8 | * Copyright (c) 2008, The haXe Project Contributors 9 | * All rights reserved. 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * 13 | * - Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * - Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY 20 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 29 | * DAMAGE. 30 | */ 31 | package format.tools; 32 | 33 | class BufferInput extends haxe.io.Input { 34 | 35 | public var i : haxe.io.Input; 36 | public var buf : haxe.io.Bytes; 37 | public var available : Int; 38 | public var pos : Int; 39 | 40 | public function new(i, buf, ?pos = 0, ?available = 0) { 41 | this.i = i; 42 | this.buf = buf; 43 | this.pos = pos; 44 | this.available = available; 45 | } 46 | 47 | public function refill() { 48 | if( pos > 0 ) { 49 | buf.blit(0, buf, pos, available); 50 | pos = 0; 51 | } 52 | available += i.readBytes(buf, available, buf.length - available); 53 | } 54 | 55 | override function readByte() { 56 | if( available == 0 ) refill(); 57 | var c = buf.get(pos); 58 | pos++; 59 | available--; 60 | return c; 61 | } 62 | 63 | override function readBytes( buf : haxe.io.Bytes, pos : Int, len : Int ) { 64 | if( available == 0 ) refill(); 65 | var size = if( len > available ) available else len; 66 | buf.blit(pos, this.buf, this.pos, size); 67 | this.pos += size; 68 | this.available -= size; 69 | return size; 70 | } 71 | 72 | } -------------------------------------------------------------------------------- /Libraries/Format/format/tools/Deflate.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * format - haXe File Formats 3 | * 4 | * Copyright (c) 2008, The haXe Project Contributors 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * - Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR 19 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25 | * DAMAGE. 26 | */ 27 | package format.tools; 28 | 29 | class Deflate { 30 | 31 | public static function run( b : haxe.io.Bytes, ?level = 9 ) : haxe.io.Bytes { 32 | #if (haxe_ver >= 3.2) 33 | 34 | return haxe.zip.Compress.run(b,level); 35 | 36 | #else 37 | // legacy 38 | #if neko 39 | return neko.zip.Compress.run(b,level); 40 | #elseif flash9 41 | var bytes = b.sub(0,b.length); 42 | var data = bytes.getData(); 43 | data.compress(); 44 | return haxe.io.Bytes.ofData(data); 45 | #elseif cpp 46 | return cpp.zip.Compress.run(b,level); 47 | #elseif ( java || php ) 48 | return haxe.zip.Compress.run(b,level); 49 | #else 50 | throw "Deflate is not supported on this platform"; 51 | return null; 52 | #end 53 | 54 | #end 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /Libraries/Format/format/tools/IO.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * format - haXe File Formats 3 | * 4 | * Copyright (c) 2008, The haXe Project Contributors 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * - Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR 19 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25 | * DAMAGE. 26 | */ 27 | package format.tools; 28 | 29 | class IO { 30 | 31 | public static function copy( i : haxe.io.Input, o : haxe.io.Output, buf : haxe.io.Bytes, size : Int ) { 32 | var bufsize = buf.length; 33 | while( size > 0 ) { 34 | var n = i.readBytes(buf,0,if( size > bufsize ) bufsize else size); 35 | size -= n; 36 | o.writeFullBytes(buf,0,n); 37 | } 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /Libraries/Format/format/tools/Image.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * format - haXe File Formats 3 | * 4 | * Copyright (c) 2008-2009, The haXe Project Contributors 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * - Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR 19 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25 | * DAMAGE. 26 | */ 27 | package format.tools; 28 | 29 | class Image { 30 | 31 | #if flash 32 | 33 | public static function getBytesARGB( bmp : flash.display.BitmapData ) : haxe.io.Bytes { 34 | #if flash9 35 | return haxe.io.Bytes.ofData( bmp.getPixels(bmp.rect) ); 36 | #else 37 | var a = new Array(); 38 | for( y in 0...bmp.height ) 39 | for( x in 0...bmp.width ) { 40 | var b = bmp.getPixel32(x,y); 41 | a.push(b>>>24); 42 | a.push((b>>16)&0xFF); 43 | a.push((b>>8)&0xFF); 44 | a.push(b&0xFF); 45 | } 46 | return haxe.io.Bytes.ofData(a); 47 | #end 48 | } 49 | 50 | public static function makeBitmapARGB( width : Int, height : Int, bytes : haxe.io.Bytes ) : flash.display.BitmapData { 51 | var bmp = new flash.display.BitmapData(width,height,true); 52 | var ba = bytes.getData(); 53 | #if flash9 54 | ba.position = 0; 55 | bmp.setPixels(bmp.rect,ba); 56 | #else 57 | var p = 0; 58 | for( y in 0...height ) 59 | for( x in 0...width ) { 60 | bmp.setPixel32( x , y , (ba[p]<<24) | (ba[p+1]<<16) | (ba[p+2]<<8) | ba[p+3] ); 61 | p += 4; 62 | } 63 | #end 64 | return bmp; 65 | } 66 | 67 | #end 68 | 69 | } -------------------------------------------------------------------------------- /Libraries/Format/format/tools/Inflate.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * format - haXe File Formats 3 | * 4 | * Copyright (c) 2008, The haXe Project Contributors 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * - Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR 19 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25 | * DAMAGE. 26 | */ 27 | package format.tools; 28 | 29 | class Inflate { 30 | 31 | public static function run( bytes : haxe.io.Bytes ) { 32 | #if (haxe_ver >= 3.2) 33 | 34 | return haxe.zip.Uncompress.run(bytes); 35 | 36 | #else 37 | 38 | // legacy support 39 | #if neko 40 | return neko.zip.Uncompress.run(bytes); 41 | #elseif cpp 42 | return cpp.zip.Uncompress.run(bytes); 43 | #elseif flash9 44 | var b = new flash.utils.ByteArray(); 45 | b.writeBytes(bytes.getData(),0,bytes.length); 46 | b.uncompress(); 47 | return haxe.io.Bytes.ofData(b); 48 | #elseif php 49 | return haxe.zip.Uncompress.run(bytes); 50 | #else 51 | return InflateImpl.run(new haxe.io.BytesInput(bytes)); 52 | #end 53 | 54 | #end 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /Libraries/Format/format/tools/MemoryBytes.hx: -------------------------------------------------------------------------------- 1 | package format.tools; 2 | 3 | @:native('Int') 4 | extern class MemoryBytes { 5 | 6 | public static inline function make( pos : Int ) : MemoryBytes { 7 | return cast pos; 8 | } 9 | 10 | inline function getPos() : Int { 11 | return cast this; 12 | } 13 | 14 | public inline function get( p : Int ) : Int { 15 | return flash.Memory.getByte(getPos() + p); 16 | } 17 | 18 | public inline function set( p : Int, v : Int ) : Void { 19 | flash.Memory.setByte(getPos() + p, v); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Libraries/Format/format/wav/Data.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * format - haXe File Formats 3 | * 4 | * WAVE File Format 5 | * Copyright (C) 2009 Robin Palotai 6 | * 7 | * Copyright (c) 2009, The haXe Project Contributors 8 | * All rights reserved. 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 12 | * - Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * - Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY 19 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 28 | * DAMAGE. 29 | */ 30 | package format.wav; 31 | 32 | typedef WAVE = { 33 | header : WAVEHeader, 34 | data : haxe.io.Bytes, 35 | } 36 | 37 | typedef WAVEHeader = { 38 | format : WAVEFormat, 39 | channels : Int, 40 | samplingRate : Int, 41 | byteRate : Int, // samplingRate * channels * bitsPerSample / 8 42 | blockAlign : Int, // channels * bitsPerSample / 8 43 | bitsPerSample : Int 44 | } 45 | 46 | enum WAVEFormat { 47 | WF_PCM; 48 | } 49 | 50 | 51 | -------------------------------------------------------------------------------- /Libraries/Format/format/wav/Writer.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * format - haXe File Formats 3 | * 4 | * WAVE File Format 5 | * Copyright (C) 2009 Robin Palotai 6 | * 7 | * Copyright (c) 2009, The haXe Project Contributors 8 | * All rights reserved. 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are met: 11 | * 12 | * - Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * - Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY 19 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR 22 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 28 | * DAMAGE. 29 | */ 30 | 31 | package format.wav; 32 | import format.wav.Data; 33 | 34 | class Writer { 35 | 36 | var o : haxe.io.Output; 37 | 38 | public function new(output : haxe.io.Output) { 39 | o = output; 40 | o.bigEndian = false; 41 | } 42 | 43 | public function write(wav : WAVE) { 44 | var hdr = wav.header; 45 | 46 | o.writeString("RIFF"); 47 | writeInt(36 + wav.data.length); 48 | o.writeString("WAVE"); 49 | 50 | o.writeString("fmt "); 51 | writeInt(16); 52 | o.writeUInt16(1); 53 | o.writeUInt16(hdr.channels); 54 | writeInt(hdr.samplingRate); 55 | writeInt(hdr.byteRate); 56 | o.writeUInt16(hdr.blockAlign); 57 | o.writeUInt16(hdr.bitsPerSample); 58 | 59 | o.writeString("data"); 60 | writeInt(wav.data.length); 61 | o.write(wav.data); 62 | } 63 | 64 | inline function writeInt( v : Int ) { 65 | #if haxe3 66 | o.writeInt32(v); 67 | #else 68 | o.writeUInt30(v); 69 | #end 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /Libraries/Format/format/zip/Data.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * format - haXe File Formats 3 | * 4 | * Copyright (c) 2008, The haXe Project Contributors 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * - Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR 19 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25 | * DAMAGE. 26 | */ 27 | package format.zip; 28 | 29 | #if haxe3 30 | 31 | typedef ExtraField = haxe.zip.Entry.ExtraField; 32 | 33 | typedef Entry = haxe.zip.Entry; 34 | 35 | #else 36 | 37 | enum ExtraField { 38 | FUnknown( tag : Int, bytes : haxe.io.Bytes ); 39 | FInfoZipUnicodePath( name : String, crc : haxe.Int32 ); 40 | FUtf8; 41 | } 42 | 43 | typedef Entry = { 44 | var fileName : String; 45 | var fileSize : Int; 46 | var fileTime : Date; 47 | var compressed : Bool; 48 | var dataSize : Int; 49 | var data : Null; 50 | var crc32 : Null; 51 | var extraFields : Null>; 52 | } 53 | 54 | #end 55 | 56 | typedef Data = List 57 | -------------------------------------------------------------------------------- /Libraries/Format/format/zip/Tools.hx: -------------------------------------------------------------------------------- 1 | /* 2 | * format - haXe File Formats 3 | * 4 | * Copyright (c) 2008, The haXe Project Contributors 5 | * All rights reserved. 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * - Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE HAXE PROJECT CONTRIBUTORS "AS IS" AND ANY 16 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | * DISCLAIMED. IN NO EVENT SHALL THE HAXE PROJECT CONTRIBUTORS BE LIABLE FOR 19 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 25 | * DAMAGE. 26 | */ 27 | package format.zip; 28 | import format.zip.Data; 29 | 30 | class Tools { 31 | 32 | public static function uncompress( f : Entry ) { 33 | if( !f.compressed ) 34 | return; 35 | #if neko 36 | var c = new neko.zip.Uncompress(-15); 37 | var s = haxe.io.Bytes.alloc(f.fileSize); 38 | var r = c.execute(f.data,0,s,0); 39 | c.close(); 40 | if( !r.done || r.read != f.data.length || r.write != f.fileSize ) 41 | throw "Invalid compressed data for "+f.fileName; 42 | f.compressed = false; 43 | f.dataSize = f.fileSize; 44 | f.data = s; 45 | #else 46 | throw "No uncompress support"; 47 | #end 48 | } 49 | 50 | public static function compress( f : Entry, level : Int ) { 51 | if( f.compressed ) 52 | return; 53 | #if neko 54 | // this should be optimized with a temp buffer 55 | // that would discard the first two bytes 56 | // (in order to prevent 2x mem usage for large files) 57 | var data = neko.zip.Compress.run( f.data, level ); 58 | f.compressed = true; 59 | f.data = data.sub(2,data.length-6); 60 | f.dataSize = f.data.length; 61 | #else 62 | throw "No compress support"; 63 | #end 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /Libraries/hxGeomAlgo/.gitignore: -------------------------------------------------------------------------------- 1 | # Build and Release Folders 2 | bin/ 3 | bin-debug/ 4 | bin-release/ 5 | 6 | # Other files and folders 7 | .settings/ 8 | 9 | # Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties` 10 | # should NOT be excluded as they contain compiler settings and other important 11 | # information for Eclipse / Flash Builder. 12 | -------------------------------------------------------------------------------- /Libraries/hxGeomAlgo/CREDITS.md: -------------------------------------------------------------------------------- 1 | **hxGeomAlgo** is based on: 2 | 3 | - HaxeFoundation (http://haxe-foundation.org/) 4 | - OpenFL (http://www.openfl.org/) 5 | - Marching Squares (Contour Tracing) 6 | - http://devblog.phillipspiess.com/2010/02/23/better-know-an-algorithm-1-marching-squares/ (Phil Spiess) 7 | - http://www.tomgibara.com/computer-vision/marching-squares (Tom Gibara) 8 | - Ramer-Douglas-Peucker (Polyline Simplification) 9 | - http://karthaus.nl/rdp/ (Marius Karthaus) 10 | - http://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment (Grumdrig) 11 | - Ear Clipping (Triangulation and Poly Decomposition) 12 | - https://github.com/mapbox/earcut (Vladimir Agafonkin) 13 | - http://www.ewjordan.com/earClip/ (Java - by Eric Jordan) 14 | - Bayazit (Poly Decomposition) 15 | - http://mnbayazit.com/406/bayazit (Mark Bayazit) 16 | - http://mnbayazit.com/406/credit 17 | - http://www.dyn4j.org/ (Java - by William Bittle) 18 | - Visibilty Polygon and Homogeneous Coords (2D) 19 | - http://www.cs.ubc.ca/~snoeyink/demos/convdecomp/VPDemo.html (Jack Snoeyink) 20 | - Snoeyink-Keil (Minimum Convex Decomposition) 21 | - http://www.cs.ubc.ca/~snoeyink/demos/convdecomp/MCDDemo.html (Jack Snoeyink & Mark Keil) 22 | - [J. Mark Keil](http://www.informatik.uni-trier.de/~ley/pers/hd/k/Keil:J=_Mark), [Jack Snoeyink](http://www.informatik.uni-trier.de/~ley/pers/hd/s/Snoeyink:Jack.html): On the Time Bound for Convex Decomposition of Simple Polygons. [Int. J. Comput. Geometry Appl. 12](http://www.informatik.uni-trier.de/~ley/db/journals/ijcga/ijcga12.html#KeilS02)(3): 181-192 (2002) 23 | - Connected Components Labeling and Contour Tracing (w/ Holes) 24 | - Fu Chang, Chun-jen Chen, Chi-jen Lu: [A linear-time component-labeling algorithm using contour tracing technique](http://www.iis.sinica.edu.tw/papers/fchang/1362-F.pdf) (2004) 25 | - Visvalingam-Whyatt (Polyline Simplification) 26 | - Visvalingam M., Whyatt J. D.: [Line generalisation by repeated elimination of the smallest area](https://hydra.hull.ac.uk/resources/hull:8338) (1992) 27 | - http://bost.ocks.org/mike/simplify/ (Mike Bostock) 28 | - https://github.com/jonasmalacofilho/dheap (Jonas Malaco Filho) 29 | - http://en.wikipedia.org/wiki/Binary_heap (Binary (Min)Heap) 30 | - Tess2 (Tesselation to Triangles and Convex Polygons, Poly Boolean Ops) 31 | - GLU Libtess (by Eric Veach, July 1994) 32 | - https://github.com/memononen/tess2.js (Mikko Mononen, Aug 2013) 33 | - IsoContours (Contour Tracing) 34 | - http://en.wikipedia.org/wiki/Marching_squares 35 | - https://github.com/deltaluca/nape (Luca Deltodesco) 36 | - https://github.com/scikit-image/scikit-image (scikit-image team) 37 | - Hertel-Mehlhorn (Convex Polygons from Arbitrary Triangulation) 38 | - https://github.com/ivanfratric/polypartition (Ivan Fratric) 39 | - http://www.philvaz.com/compgeom (Phil Porvaznik) 40 | -------------------------------------------------------------------------------- /Libraries/hxGeomAlgo/hxGeomAlgo/Debug.hx: -------------------------------------------------------------------------------- 1 | package hxGeomAlgo; 2 | 3 | import haxe.PosInfos; 4 | 5 | 6 | /** 7 | * @author azrafe7 8 | */ 9 | class Debug 10 | { 11 | /** 12 | * Used for sanity-checks throughout the code when in debug mode (or if -D GEOM_CHECKS is passed to the compiler). 13 | * Should be automatically stripped out by the compiler in release mode (or if -D NO_GEOM_CHECKS is passed to the compiler). 14 | */ 15 | #if ((debug && !NO_GEOM_CHECKS) || GEOM_CHECKS) 16 | static public function assert(cond:Bool, ?message:String, ?pos:PosInfos) { 17 | if (!cond) { 18 | throw pos.fileName + ":" + pos.lineNumber + ": ASSERT FAILED! " + (message != null ? message : ""); 19 | } 20 | } 21 | #elseif (!debug || NO_GEOM_CHECKS) 22 | inline static public function assert(cond:Bool, ?message:String, ?pos:PosInfos) { 23 | return; 24 | } 25 | #end 26 | } -------------------------------------------------------------------------------- /Libraries/hxGeomAlgo/hxGeomAlgo/HxPoint.hx: -------------------------------------------------------------------------------- 1 | package hxGeomAlgo; 2 | 3 | /** 4 | * Minimal Point class (auto-converting to/from flash.geom.Point and {x:Float, y:Float}). 5 | * 6 | * @author azrafe7 7 | */ 8 | @:expose 9 | abstract HxPoint(HxPointData) from HxPointData to HxPointData 10 | { 11 | static public var EMPTY(default, never) = new HxPoint(Math.NaN, Math.NaN); 12 | 13 | public var x(get, set):Float; 14 | inline private function get_x():Float { return this.x; } 15 | inline private function set_x(value:Float):Float { return this.x = value; } 16 | 17 | public var y(get, set):Float; 18 | inline private function get_y():Float { return this.y; } 19 | inline private function set_y(value:Float):Float { return this.y = value; } 20 | 21 | public function new(x:Float=0, y:Float=0) 22 | { 23 | this = new HxPointData(x, y); 24 | } 25 | 26 | public function setTo(newX:Float, newY:Float):Void 27 | { 28 | x = newX; 29 | y = newY; 30 | } 31 | 32 | inline public function equals(p:HxPoint):Bool 33 | { 34 | return (p != null && this.x == p.x && this.y == p.y); 35 | } 36 | 37 | inline public function clone():HxPoint 38 | { 39 | return new HxPoint(x, y); 40 | } 41 | 42 | inline public function toString() 43 | { 44 | return '(${x}, ${y})'; 45 | } 46 | 47 | #if (flash || openfl) 48 | @:from inline static function fromFlashPoint(p:flash.geom.Point) 49 | { 50 | return new HxPoint(p.x, p.y); 51 | } 52 | 53 | @:to inline function toFlashPoint() 54 | { 55 | return new flash.geom.Point(x, y); 56 | } 57 | #end 58 | 59 | @:from inline static function fromPointStruct(p:{x:Float, y:Float}) 60 | { 61 | return new HxPoint(p.x, p.y); 62 | } 63 | 64 | @:to inline function toPointStruct() 65 | { 66 | return { x:x, y:y }; 67 | } 68 | } 69 | 70 | 71 | class HxPointData 72 | { 73 | public var x:Float; 74 | public var y:Float; 75 | 76 | inline public function new(x:Float=0, y:Float=0) 77 | { 78 | this.x = x; 79 | this.y = y; 80 | } 81 | 82 | inline public function toString() 83 | { 84 | return '(${x}, ${y})'; 85 | } 86 | } -------------------------------------------------------------------------------- /Libraries/hxGeomAlgo/hxGeomAlgo/RamerDouglasPeucker.hx: -------------------------------------------------------------------------------- 1 | /** 2 | * Ramer-Douglas-Peucker implementation. 3 | * 4 | * Based on: 5 | * 6 | * @see http://karthaus.nl/rdp/ (JS - by Marius Karthaus) 7 | * @see http://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment (JS - Grumdrig) 8 | * 9 | * @author azrafe7 10 | */ 11 | 12 | package hxGeomAlgo; 13 | 14 | 15 | import hxGeomAlgo.PolyTools; 16 | 17 | @:expose 18 | class RamerDouglasPeucker 19 | { 20 | /** 21 | * Simplify polyline. 22 | * 23 | * @param points Array of points defining the polyline. 24 | * @param epsilon Perpendicular distance threshold (typically in the range (0..2]). 25 | * @return An array of points defining the simplified polyline. 26 | */ 27 | static public function simplify(points:Array, epsilon:Float = 1):Array 28 | { 29 | var firstPoint = points[0]; 30 | var lastPoint = points[points.length - 1]; 31 | 32 | if (points.length < 2) { 33 | return [].concat(points); 34 | } 35 | 36 | var index = -1; 37 | var dist = 0.; 38 | for (i in 1...points.length - 1) { 39 | var currDist = PolyTools.distanceToSegment(points[i], firstPoint, lastPoint); 40 | if (currDist > dist) { 41 | dist = currDist; 42 | index = i; 43 | } 44 | } 45 | 46 | if (dist > epsilon){ 47 | // recurse 48 | var l1 = points.slice(0, index + 1); 49 | var l2 = points.slice(index); 50 | var r1 = simplify(l1, epsilon); 51 | var r2 = simplify(l2, epsilon); 52 | // concat r2 to r1 minus the end/startpoint that will be the same 53 | var rs = r1.slice(0, r1.length - 1).concat(r2); 54 | return rs; 55 | } else { 56 | return [firstPoint, lastPoint]; 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /Libraries/hxGeomAlgo/hxGeomAlgo/Version.hx: -------------------------------------------------------------------------------- 1 | package hxGeomAlgo; 2 | 3 | /** 4 | * @author azrafe7 5 | */ 6 | @:expose 7 | class Version 8 | { 9 | inline public static var major:Int = 0; 10 | inline public static var minor:Int = 3; 11 | inline public static var patch:Int = 14; 12 | 13 | static public function toString():String 14 | { 15 | return '$major.$minor.$patch'; 16 | } 17 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # khawy 2 | Kha game framework inspire in haxeflixel but with a more flexible design (aggregation instead of inheritance). 3 | Also is power by the awesome Kha engine that enables khawy to run in almost any device and it makes it super fast. 4 | 5 | 6 | 7 | Web: 8 | https://juakob.github.io/khawy-web 9 | 10 | Examples: 11 | ludum dare: http://maleficgames.com/web/FireLogs/ 12 | source: https://github.com/juakob/LD46 13 | 14 | (under work) 15 | https://juakob.github.io/LD45/ 16 | source: https://github.com/juakob/LD45 17 | -------------------------------------------------------------------------------- /Shaders/3d/mesh.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | precision mediump float; 4 | 5 | uniform sampler2D tex; 6 | in vec3 norm; 7 | in vec2 texCoord; 8 | out vec4 color; 9 | 10 | 11 | void kore() { 12 | vec4 texcolor = texture(tex, texCoord.xy); 13 | vec3 lightdir = vec3(-0.2, 0.5, -0.3); 14 | color = texcolor*vec4(dot(norm, lightdir) * vec3(1.0, 1.0, 1.0)+vec3(0.75),1.0); 15 | } 16 | -------------------------------------------------------------------------------- /Shaders/3d/mesh.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | in vec3 pos; 4 | in vec3 normal; 5 | in vec2 uv; 6 | 7 | 8 | uniform mat4 mvp; 9 | 10 | 11 | //uniform mat4 depthBias; 12 | 13 | //out vec3 norm; 14 | out vec2 texCoord; 15 | //out vec4 shadowCoord; 16 | 17 | void kore() { 18 | 19 | texCoord=uv; 20 | //shadowCoord = depthBias*vec4(pos,1); 21 | gl_Position = mvp * vec4(pos, 1.0); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /Shaders/3d/meshBones.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | in vec3 pos; 4 | in vec3 normal; 5 | in vec2 uv; 6 | in vec4 weights; 7 | in vec4 boneIndex; 8 | 9 | uniform mat4 projection; 10 | uniform mat4 view; 11 | uniform mat4 model; 12 | uniform mat4 bones[23]; 13 | 14 | //out vec3 norm; 15 | out vec2 texCoord; 16 | 17 | void kore() { 18 | 19 | vec4 newVertex; 20 | vec4 newNormal; 21 | int index; 22 | // -------------------- 23 | index=int(boneIndex.x); // Cast to int 24 | newVertex = (bones[index] * vec4(pos, 1.0)) * weights.x; 25 | newNormal = (bones[index] * vec4(normal, 0.0)) * weights.x; 26 | index=int(boneIndex.y); //Cast to int 27 | newVertex = (bones[index] * vec4(pos, 1.0)) * weights.y + newVertex; 28 | newNormal = (bones[index] * vec4(normal, 0.0)) * weights.y + newNormal; 29 | index=int(boneIndex.z); //Cast to int 30 | newVertex = (bones[index] * vec4(pos, 1.0)) * weights.z + newVertex; 31 | newNormal = (bones[index] * vec4(normal, 0.0)) * weights.z + newNormal; 32 | index=int(boneIndex.w); //Cast to int 33 | newVertex = (bones[index] * vec4(pos, 1.0)) * weights.w + newVertex; 34 | newNormal = (bones[index] * vec4(normal, 0.0)) * weights.w + newNormal; 35 | // norm = vec3(model* view * newNormal); 36 | texCoord=uv; 37 | gl_Position = projection * view * model * vec4(newVertex.xyz, 1.0); 38 | ///// 39 | /* int index; 40 | vec4 newVertex; 41 | index=int(boneIndex.x); // Cast to int 42 | newVertex = (bones[index] * vec4(pos, 1.0)) * weights.x; 43 | norm = (model * vec4(normal, 0.0)).xyz; 44 | gl_Position = projection * view * model * vec4(pos, 1.0);*/ 45 | } 46 | -------------------------------------------------------------------------------- /Shaders/3d/meshNoShade.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | precision mediump float; 4 | 5 | uniform sampler2D tex; 6 | //in vec3 norm; 7 | in vec2 texCoord; 8 | out vec4 color; 9 | 10 | 11 | void kore() { 12 | color = texture(tex, texCoord.xy); 13 | } 14 | -------------------------------------------------------------------------------- /Shaders/Shaders/HighPassFilter.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #ifdef GL_ES 4 | precision mediump float; 5 | #endif 6 | 7 | uniform sampler2D tex; 8 | uniform vec3 brightIndex; 9 | uniform vec3 darkColor; 10 | uniform vec3 tintColor; 11 | uniform float tolerance; 12 | in vec2 texCoord; 13 | out vec4 FragColor; 14 | 15 | void kore() { 16 | vec4 color = texture( tex, texCoord ); 17 | // check whether fragment output is higher than threshold, if so output as brightness color 18 | float brightness = dot(color.rgb, brightIndex); 19 | if(brightness > tolerance) 20 | FragColor = vec4(color.rgb, 1.0); 21 | else 22 | FragColor = vec4(darkColor.rgb, 1.0); 23 | 24 | FragColor*= vec4(tintColor.rgb, 1.0); 25 | } 26 | -------------------------------------------------------------------------------- /Shaders/Shaders/ShBrightness.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #ifdef GL_ES 4 | precision mediump float; 5 | #endif 6 | 7 | 8 | uniform sampler2D tex; 9 | uniform float brightness; 10 | in vec2 texCoord; 11 | out vec4 color; 12 | 13 | void main() 14 | { 15 | vec4 col = texture( tex, texCoord); 16 | col.rgb*=brightness; 17 | color= col; 18 | } -------------------------------------------------------------------------------- /Shaders/Shaders/alpha.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | in vec3 vertexPosition; 4 | in vec2 texPosition; 5 | 6 | uniform mat4 projectionMatrix; 7 | uniform float alpha; 8 | out vec3 texCoord; 9 | 10 | 11 | void kore() { 12 | 13 | gl_Position = projectionMatrix*vec4(vertexPosition.xyz, 1.0); 14 | texCoord = vec3(texPosition,alpha); 15 | } 16 | -------------------------------------------------------------------------------- /Shaders/Shaders/blurFragmentShader.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | precision mediump float; 3 | 4 | uniform sampler2D tex; 5 | 6 | in vec2 v_texCoord; 7 | in vec2 v_blurCoord0; 8 | in vec2 v_blurCoord1; 9 | in vec2 v_blurCoord2; 10 | in vec2 v_blurCoord3; 11 | in vec2 v_blurCoord4; 12 | in vec2 v_blurCoord5; 13 | out vec4 color; 14 | 15 | void main() 16 | { 17 | 18 | vec4 texcolor = texture(tex, v_blurCoord2); 19 | color=texcolor; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Shaders/Shaders/blur_pass.frag.glsl: -------------------------------------------------------------------------------- 1 | 2 | #version 450 3 | 4 | uniform sampler2D tex; 5 | 6 | uniform vec2 dirInv; 7 | 8 | in vec2 texCoord; 9 | out vec4 fragColor; 10 | 11 | void main() { 12 | fragColor = texture(tex, texCoord + (dirInv * 5.5)); 13 | fragColor += texture(tex, texCoord + (dirInv * 4.5)); 14 | fragColor += texture(tex, texCoord + (dirInv * 3.5)); 15 | fragColor += texture(tex, texCoord + (dirInv * 2.5)); 16 | fragColor += texture(tex, texCoord + dirInv * 1.5); 17 | fragColor += texture(tex, texCoord); 18 | fragColor += texture(tex, texCoord - dirInv * 1.5); 19 | fragColor += texture(tex, texCoord - (dirInv * 2.5)); 20 | fragColor += texture(tex, texCoord - (dirInv * 3.5)); 21 | fragColor += texture(tex, texCoord - (dirInv * 4.5)); 22 | fragColor += texture(tex, texCoord - (dirInv * 5.5)); 23 | fragColor.rgba /= 11; 24 | //fragColor.rgb *= fragColor.a; 25 | } -------------------------------------------------------------------------------- /Shaders/Shaders/filmGrain.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #ifdef GL_ES 4 | precision mediump float; 5 | #endif 6 | 7 | uniform sampler2D tex; 8 | uniform vec2 resolution; 9 | in vec2 texCoord; 10 | out vec4 FragColor; 11 | 12 | void kore() { 13 | float strength = 5.0; 14 | float x = (texCoord.x + 4.0 ) * (texCoord.y + 4.0 ) * (1. * 10.0); 15 | vec4 grain = vec4(mod((mod(x, 13.0) + 1.0) * (mod(x, 123.0) + 1.0), 0.01)-0.005) * strength; 16 | grain = 1.0 - grain; 17 | vec2 value = resolution*grain.xy*0.0; 18 | 19 | vec4 c1 = texture( tex, texCoord - value ); 20 | vec4 c2 = texture( tex, texCoord ); 21 | vec4 c3 = texture( tex, texCoord + value); 22 | 23 | vec4 col = vec4( c1.r, c2.g, c3.b, c1.a + c2.a + c3.b ); 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | FragColor = col* grain; 32 | } 33 | -------------------------------------------------------------------------------- /Shaders/Shaders/fxaa.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | uniform sampler2D tex; 4 | uniform vec2 screenSizeInv; 5 | 6 | in vec2 texCoord; 7 | out vec4 fragColor; 8 | 9 | void main() { 10 | const float FXAA_REDUCE_MIN = 1.0 / 50.0; 11 | const float FXAA_REDUCE_MUL = 1.0 / 3.0; 12 | const float FXAA_SPAN_MAX = 2.0; 13 | 14 | vec2 tcrgbNW = (texCoord + vec2(-1.0, -1.0) * screenSizeInv); 15 | vec2 tcrgbNE = (texCoord + vec2(1.0, -1.0) * screenSizeInv); 16 | vec2 tcrgbSW = (texCoord + vec2(-1.0, 1.0) * screenSizeInv); 17 | vec2 tcrgbSE = (texCoord + vec2(1.0, 1.0) * screenSizeInv); 18 | vec2 tcrgbM = vec2(texCoord); 19 | 20 | vec3 rgbNW = texture(tex, tcrgbNW).rgb; 21 | vec3 rgbNE = texture(tex, tcrgbNE).rgb; 22 | vec3 rgbSW = texture(tex, tcrgbSW).rgb; 23 | vec3 rgbSE = texture(tex, tcrgbSE).rgb; 24 | vec4 texColor = texture(tex, tcrgbM); 25 | vec3 rgbM = texColor.rgb; 26 | vec3 luma = vec3(0.299, 0.587, 0.114); 27 | float lumaNW = dot(rgbNW, luma); 28 | float lumaNE = dot(rgbNE, luma); 29 | float lumaSW = dot(rgbSW, luma); 30 | float lumaSE = dot(rgbSE, luma); 31 | float lumaM = dot(rgbM, luma); 32 | float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE))); 33 | float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE))); 34 | 35 | vec2 dir; 36 | dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE)); 37 | dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE)); 38 | 39 | float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * 40 | (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN); 41 | 42 | float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce); 43 | dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX), 44 | max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX), 45 | dir * rcpDirMin)) * screenSizeInv; 46 | 47 | vec4 rgbA = 0.5 * ( 48 | texture(tex, texCoord + dir * (1.0 / 3.0 - 0.5)) + 49 | texture(tex, texCoord + dir * (2.0 / 3.0 - 0.5))); 50 | fragColor.rgba = rgbA * 0.5 + 0.25 * ( // vec3 rgbB 51 | texture(tex, texCoord + dir * -0.5).rgba + 52 | texture(tex, texCoord + dir * 0.5).rgba); 53 | 54 | // float lumaB = dot(rgbB, luma); 55 | float lumaB = dot(fragColor.rgb, luma); 56 | if ((lumaB < lumaMin) || (lumaB > lumaMax)) fragColor.rgba = rgbA; 57 | 58 | // else fragColor.rgb = rgbB; 59 | } -------------------------------------------------------------------------------- /Shaders/Shaders/hBlurVertexShader.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | in vec3 vertexPosition; 4 | in vec2 texPosition; 5 | 6 | 7 | out vec2 v_texCoord; 8 | out vec2 v_blurCoord0; 9 | out vec2 v_blurCoord1; 10 | out vec2 v_blurCoord2; 11 | out vec2 v_blurCoord3; 12 | out vec2 v_blurCoord4; 13 | out vec2 v_blurCoord5; 14 | 15 | 16 | 17 | uniform mat4 projectionMatrix; 18 | uniform vec2 resolution; 19 | 20 | void main() 21 | { 22 | gl_Position = projectionMatrix*vec4(vertexPosition.xyz, 1.0) ; 23 | v_texCoord = texPosition.xy; 24 | v_blurCoord0 = texPosition.xy+ vec2(-3.0,-3.0)*resolution; 25 | v_blurCoord1 = texPosition.xy+ vec2(-2.0,-2.0)*resolution; 26 | v_blurCoord2 = texPosition.xy+ vec2(-1.0,-1.0)*resolution; 27 | v_blurCoord3 = texPosition.xy+ vec2(1.0,1.0)*resolution; 28 | v_blurCoord4 = texPosition.xy+ vec2(2.0, 2.0)*resolution; 29 | v_blurCoord5 = texPosition.xy+ vec2(3.0, 3.0)*resolution; 30 | 31 | 32 | } -------------------------------------------------------------------------------- /Shaders/Shaders/mirage.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | 4 | uniform float time; 5 | const float A = 0.009; 6 | const float B = 200.0; 7 | const float C = 100.0; 8 | 9 | const float D = 0.009; 10 | const float E = 13.0; 11 | const float F = 100.0; 12 | 13 | 14 | uniform sampler2D tex; 15 | in vec2 texCoord; 16 | out vec4 FragColor; 17 | 18 | void kore() { 19 | FragColor = texture(tex, texCoord); 20 | FragColor.a = 1.0; //Best to make sure nothing seems transparent 21 | float x = A * texCoord.x * sin(C * time); 22 | float y = D * texCoord.y * cos(F * time); 23 | vec2 c = vec2(texCoord.x + x, texCoord.y +y); 24 | vec4 diffuse_color = texture(tex, c); 25 | FragColor = diffuse_color; 26 | } 27 | -------------------------------------------------------------------------------- /Shaders/Shaders/mosaic.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #ifdef GL_ES 4 | precision mediump float; 5 | #endif 6 | 7 | uniform sampler2D tex; 8 | uniform float tiles; 9 | in vec2 texCoord; 10 | out vec4 FragColor; 11 | 12 | void kore() { 13 | vec2 uv = texCoord.xy; 14 | uv = floor(uv*tiles)/tiles; 15 | FragColor = texture( tex, uv ); 16 | } 17 | -------------------------------------------------------------------------------- /Shaders/Shaders/multiplyColor.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #ifdef GL_ES 4 | precision mediump float; 5 | #endif 6 | 7 | uniform sampler2D tex; 8 | uniform vec4 colorMul; 9 | in vec2 texCoord; 10 | out vec4 FragColor; 11 | 12 | void kore() { 13 | vec4 texcolor = texture(tex, texCoord)*colorMul; 14 | FragColor = texcolor; 15 | } 16 | -------------------------------------------------------------------------------- /Shaders/Shaders/outline.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #ifdef GL_ES 4 | precision mediump float; 5 | #endif 6 | 7 | uniform sampler2D tex; 8 | uniform vec3 color; 9 | uniform vec2 stepSize; 10 | in vec2 texCoord; 11 | out vec4 FragColor; 12 | 13 | void kore() { 14 | vec4 base= texture( tex, texCoord); 15 | float alpha1 = texture( tex, texCoord + vec2(0,stepSize.y)).a; 16 | float alpha3=abs(alpha1-base.a); 17 | float alpha1_ = texture( tex, texCoord + vec2(0,-stepSize.y)).a; 18 | alpha1=abs(alpha1-alpha1_); 19 | float alpha5=abs(alpha1_-base.a); 20 | float alpha2 = texture( tex, texCoord + vec2(stepSize.x,0)).a; 21 | float alpha4=abs(alpha2-base.a); 22 | float alpha2_ = texture( tex, texCoord + vec2(-stepSize.x,0)).a; 23 | alpha2=abs(alpha2-alpha2_); 24 | float alpha6=abs(alpha2_-base.a); 25 | 26 | 27 | float alpha=clamp((alpha1+alpha2+alpha3+alpha4+alpha5+alpha6)*(1-base.a),0,1); 28 | //float inverse=1-alpha; 29 | // calculate resulting color 30 | FragColor = vec4( base.rgb+color*alpha, base.a+alpha); 31 | // FragColor = vec4( base.rgb*inverse+color*(alpha*base.a), base.a*inverse+(alpha*base.a)); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Shaders/Shaders/poly.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #ifdef GL_ES 4 | precision mediump float; 5 | #endif 6 | 7 | uniform vec4 color; 8 | out vec4 FragColor; 9 | 10 | void kore() { 11 | FragColor = color; 12 | } 13 | -------------------------------------------------------------------------------- /Shaders/Shaders/poly.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | in vec3 vertexPosition; 4 | 5 | uniform mat4 projectionMatrix; 6 | 7 | void kore() { 8 | gl_Position = projectionMatrix*vec4(vertexPosition.xyz, 1.0) ; 9 | } 10 | -------------------------------------------------------------------------------- /Shaders/Shaders/renderAreaTint.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #ifdef GL_ES 4 | precision mediump float; 5 | #endif 6 | 7 | uniform sampler2D tex; 8 | in vec2 texCoord; 9 | out vec4 FragColor; 10 | 11 | void kore() { 12 | vec4 texcolor = texture(tex, texCoord) ; 13 | vec4 col=vec4(texcolor.x+0.1,texcolor.y,texcolor.z,texcolor.w+0.1); 14 | 15 | FragColor = col; 16 | } 17 | -------------------------------------------------------------------------------- /Shaders/Shaders/rgbSplit.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #ifdef GL_ES 4 | precision mediump float; 5 | #endif 6 | 7 | uniform sampler2D tex; 8 | uniform float time; 9 | 10 | in vec2 texCoord; 11 | out vec4 FragColor; 12 | 13 | void kore() { 14 | vec2 value = vec2(1/1280,1/720); 15 | 16 | vec4 c1 = texture( tex, texCoord - value ); 17 | vec4 c2 = texture( tex, texCoord ); 18 | vec4 c3 = texture( tex, texCoord + value ); 19 | 20 | vec4 col = vec4( c1.r, c2.g, c3.b, c1.a + c2.a + c3.b ); 21 | float scanLines =cos( time+texCoord.y * 300.5); 22 | 23 | float saturation = scanLines*scanLines; 24 | col.xyz = col.xyz * vec3(1.0 + 0.2 * saturation); 25 | 26 | FragColor = col; 27 | } 28 | -------------------------------------------------------------------------------- /Shaders/Shaders/shInverseMask.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #ifdef GL_ES 4 | precision mediump float; 5 | #endif 6 | 7 | uniform sampler2D tex; 8 | uniform sampler2D mask; 9 | in vec2 texCoord; 10 | in vec2 texCoordMask; 11 | out vec4 FragColor; 12 | 13 | void kore() { 14 | vec4 texcolor = texture(tex, texCoord) ; 15 | vec4 maskColor=texture(mask, texCoordMask) ; 16 | texcolor.xyz*=(1.-maskColor.w); 17 | 18 | FragColor = vec4(texcolor.x,texcolor.y,texcolor.z,(1.-maskColor.a)*texcolor.a); 19 | } 20 | -------------------------------------------------------------------------------- /Shaders/Shaders/shMask.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #ifdef GL_ES 4 | precision mediump float; 5 | #endif 6 | 7 | uniform sampler2D tex; 8 | uniform sampler2D mask; 9 | in vec2 texCoord; 10 | in vec2 texCoordMask; 11 | out vec4 FragColor; 12 | 13 | void kore() { 14 | vec4 texcolor = texture(tex, texCoord) ; 15 | vec4 maskColor=texture(mask, texCoordMask) ; 16 | texcolor.xyz*=maskColor.w; 17 | 18 | FragColor = vec4(texcolor.x,texcolor.y,texcolor.z,maskColor.a*texcolor.a); 19 | } 20 | -------------------------------------------------------------------------------- /Shaders/Shaders/shMask.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | in vec3 vertexPosition; 4 | in vec2 texPosition; 5 | 6 | uniform mat4 projectionMatrix; 7 | out vec2 texCoord; 8 | out vec2 texCoordMask; 9 | 10 | void kore() { 11 | vec4 pos = projectionMatrix*vec4(vertexPosition.xyz, 1.0) ; 12 | texCoord = texPosition; 13 | 14 | vec2 v_texCoordMask= texPosition; //vec2((1.0 + pos.x)*0.5,(1.0 + pos.y)*-0.5); 15 | texCoordMask=v_texCoordMask; 16 | gl_Position=pos; 17 | 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Shaders/Shaders/shMaxBlend.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #ifdef GL_ES 4 | precision mediump float; 5 | #endif 6 | 7 | uniform sampler2D tex; 8 | uniform sampler2D mask; 9 | in vec2 texCoord; 10 | in vec2 texCoordMask; 11 | out vec4 FragColor; 12 | 13 | void kore() { 14 | vec4 texcolor = texture(tex, texCoord) ; 15 | vec4 maskColor=texture(mask, texCoordMask) ; 16 | FragColor = max(texcolor,maskColor); 17 | } 18 | -------------------------------------------------------------------------------- /Shaders/Shaders/shMixGlow.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #ifdef GL_ES 4 | precision mediump float; 5 | #endif 6 | 7 | uniform sampler2D tex; 8 | uniform sampler2D baseColor; 9 | uniform float amount; 10 | in vec2 texCoord; 11 | out vec4 FragColor; 12 | 13 | void kore() { 14 | vec4 texcolor = texture(tex, texCoord) ; 15 | vec4 texcolor2 = texture(baseColor, texCoord) ; 16 | FragColor = texcolor*0.5+texcolor2; 17 | } 18 | -------------------------------------------------------------------------------- /Shaders/Shaders/simple.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #ifdef GL_ES 4 | precision mediump float; 5 | #endif 6 | 7 | uniform sampler2D tex; 8 | in vec2 texCoord; 9 | out vec4 FragColor; 10 | 11 | void kore() { 12 | vec4 texcolor = texture(tex, texCoord) ; 13 | FragColor = texcolor; 14 | } 15 | -------------------------------------------------------------------------------- /Shaders/Shaders/simple.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | in vec3 vertexPosition; 4 | in vec2 texPosition; 5 | 6 | uniform mat4 projectionMatrix; 7 | out vec2 texCoord; 8 | 9 | 10 | void kore() { 11 | gl_Position = projectionMatrix*vec4(vertexPosition.xyz, 1.0) ; 12 | texCoord = texPosition; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /Shaders/Shaders/simpleAlpha.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #ifdef GL_ES 4 | precision mediump float; 5 | #endif 6 | 7 | uniform sampler2D tex; 8 | in vec3 texCoord; 9 | out vec4 FragColor; 10 | 11 | void kore() { 12 | vec4 texcolor = texture(tex, texCoord.xy)*texCoord.z; 13 | FragColor = texcolor; 14 | } 15 | -------------------------------------------------------------------------------- /Shaders/Shaders/simpleAlpha.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | in vec3 vertexPosition; 4 | in vec3 texPosition; 5 | 6 | uniform mat4 projectionMatrix; 7 | out vec3 texCoord; 8 | 9 | 10 | void kore() { 11 | gl_Position = projectionMatrix*vec4(vertexPosition.xyz, 1.0); 12 | 13 | texCoord = texPosition; 14 | 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Shaders/Shaders/simpleColorTransformation.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #ifdef GL_ES 4 | precision mediump float; 5 | #endif 6 | 7 | uniform sampler2D tex; 8 | in vec2 texCoord; 9 | in vec4 _colorMul; 10 | in vec4 _colorAdd; 11 | out vec4 FragColor; 12 | 13 | void kore() { 14 | vec4 texcolor = texture(tex, texCoord)*_colorMul; 15 | texcolor.xyz*=_colorMul.w; 16 | texcolor+=_colorAdd*texcolor.w; 17 | 18 | FragColor = texcolor; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Shaders/Shaders/simpleColorTransformation.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | in vec3 vertexPosition; 4 | in vec2 texPosition; 5 | in vec4 colorMul; 6 | in vec4 colorAdd; 7 | 8 | uniform mat4 projectionMatrix; 9 | out vec2 texCoord; 10 | out vec4 _colorMul; 11 | out vec4 _colorAdd; 12 | 13 | 14 | void kore() { 15 | gl_Position = projectionMatrix*vec4(vertexPosition.xyz, 1.0) ; 16 | texCoord = texPosition; 17 | _colorMul = colorMul; 18 | _colorAdd = colorAdd; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Shaders/Shaders/simpleLight.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #ifdef GL_ES 4 | precision mediump float; 5 | #endif 6 | 7 | uniform sampler2D tex; 8 | uniform sampler2D tex2; 9 | in vec2 texCoord; 10 | out vec4 FragColor; 11 | 12 | void kore() { 13 | vec4 light = texture(tex, texCoord) ; 14 | vec4 texcolor = texture(tex2, texCoord) ; 15 | texcolor.xyz=texcolor.xyz*light.xyz; 16 | FragColor = texcolor; 17 | } 18 | -------------------------------------------------------------------------------- /Shaders/Shaders/simpleRgbSplit.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | #ifdef GL_ES 4 | precision mediump float; 5 | #endif 6 | 7 | uniform sampler2D tex; 8 | uniform vec2 resolution; 9 | in vec2 texCoord; 10 | out vec4 FragColor; 11 | 12 | void kore() { 13 | vec2 value = resolution; 14 | vec4 c1 = texture( tex, texCoord - value ); 15 | vec4 c2 = texture( tex, texCoord ); 16 | vec4 c3 = texture( tex, texCoord + value); 17 | vec4 col = vec4( c1.r, c2.g, c3.b, c1.a + c2.a + c3.b ); 18 | FragColor = col; 19 | } 20 | -------------------------------------------------------------------------------- /Shaders/Shaders/simpleTime.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | in vec3 vertexPosition; 4 | in vec2 texPosition; 5 | 6 | uniform mat4 projectionMatrix; 7 | out vec2 texCoord; 8 | 9 | 10 | void kore() { 11 | gl_Position = projectionMatrix*vec4(vertexPosition.xyz, 1.0) ; 12 | texCoord = texPosition; 13 | } 14 | -------------------------------------------------------------------------------- /Shaders/Shaders/vBlurVertexShader.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | in vec3 vertexPosition; 4 | in vec2 texPosition; 5 | 6 | out vec2 v_texCoord; 7 | out vec2 v_blurCoord0; 8 | out vec2 v_blurCoord1; 9 | out vec2 v_blurCoord2; 10 | out vec2 v_blurCoord3; 11 | out vec2 v_blurCoord4; 12 | out vec2 v_blurCoord5; 13 | 14 | 15 | 16 | uniform mat4 projectionMatrix; 17 | 18 | void main() 19 | { 20 | gl_Position = projectionMatrix*vec4(vertexPosition.xyz, 1.0) ; 21 | v_texCoord = texPosition.xy; 22 | v_blurCoord0= texPosition.xy + vec2(-0.00018, 0.0); 23 | v_blurCoord1 = texPosition.xy + vec2(-0.0009, 0.0); 24 | v_blurCoord2 = texPosition.xy+ vec2(-0.0035, 0.0); 25 | v_blurCoord3 = texPosition.xy+ vec2(0.0035, 0.0); 26 | v_blurCoord4 = texPosition.xy+ vec2(0.0009, 0.0); 27 | v_blurCoord5 = texPosition.xy+ vec2(0.00018, 0.0); 28 | 29 | 30 | } -------------------------------------------------------------------------------- /Sources/com/TimeManager.hx: -------------------------------------------------------------------------------- 1 | package com; 2 | 3 | class TimeManager { 4 | public static var delta(default, null):Float; 5 | public static var time(default, null):Float = 0; 6 | public static var realDelta(default, null):Float; 7 | public static var multiplier:Float = 1; 8 | public static var fixedTime:Bool; 9 | 10 | public static function setDelta(delta:Float):Void { 11 | if(fixedTime)delta=1/60; 12 | time += delta; 13 | realDelta = delta; 14 | if (delta > 1 / 20) 15 | delta = 1 / 20; 16 | TimeManager.delta = delta; 17 | } 18 | public static function reset() { 19 | time=0; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Sources/com/basicDisplay/SpriteSheetDB.hx: -------------------------------------------------------------------------------- 1 | package com.basicDisplay; 2 | 3 | import com.framework.Simulation; 4 | import com.gEngine.AnimationData; 5 | import com.loading.ResourceHandler; 6 | 7 | class SpriteSheetDB implements ResourceHandler { 8 | var animations:Array; 9 | 10 | public static var i(get, null):SpriteSheetDB; 11 | 12 | public static function get_i() { 13 | if (i == null) { 14 | i = new SpriteSheetDB(); 15 | } 16 | return i; 17 | } 18 | 19 | private function new() { 20 | animations = new Array(); 21 | Simulation.i.addResourceHandler(this); 22 | } 23 | 24 | public function add(data:AnimationData) { 25 | animations.push(data); 26 | } 27 | 28 | public function getData(name:String):AnimationData { 29 | for (animation in animations) { 30 | if (animation.name == name) 31 | return animation; 32 | } 33 | throw "spriteSheet with name " + name + " not found. Make sure it's loaded"; 34 | } 35 | 36 | public function clear():Void { 37 | animations.splice(0, animations.length); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Sources/com/collision/box2d/Const.hx: -------------------------------------------------------------------------------- 1 | package com.collision.box2d; 2 | 3 | class Const { 4 | public static inline var worldScale:Int = 30; 5 | public static inline var invWorldScale:Float = 1 / 30; 6 | } 7 | -------------------------------------------------------------------------------- /Sources/com/collision/box2d/SimplePlayerCollision.hx: -------------------------------------------------------------------------------- 1 | package com.collision.box2d; 2 | 3 | import box2D.common.math.B2Vec2; 4 | import box2D.dynamics.B2Fixture; 5 | import box2D.collision.shapes.B2PolygonShape; 6 | import box2D.dynamics.B2FixtureDef; 7 | import box2D.dynamics.B2BodyType; 8 | import box2D.dynamics.B2BodyDef; 9 | import box2D.dynamics.B2World; 10 | import box2D.dynamics.B2Body; 11 | 12 | class SimplePlayerCollision { 13 | public var body:B2Body; 14 | public var shape:B2Fixture; 15 | public var dragX:Float = 1; 16 | public var dragY:Float = 1; 17 | 18 | var moving:Bool = false; 19 | 20 | public var velocityX(get, set):Float; 21 | public var velocityY(get, set):Float; 22 | public var x(get, set):Float; 23 | public var y(get, set):Float; 24 | 25 | public function new(x:Float, y:Float, width:Float, height:Float, world:B2World) { 26 | createBody(width, height, world); 27 | body.setPosition(new B2Vec2(x * Const.invWorldScale, y * Const.invWorldScale)); 28 | body.setFixedRotation(true); 29 | } 30 | function createBody(width:Float, height:Float, world:B2World) { 31 | var bodyDef = new B2BodyDef(); 32 | bodyDef.type = B2BodyType.DYNAMIC_BODY; 33 | body = world.createBody(bodyDef); 34 | var box = new B2PolygonShape(); 35 | box.setAsBox(width * Const.invWorldScale, height * Const.invWorldScale); 36 | var fixture = new B2FixtureDef(); 37 | fixture.friction = 0; 38 | fixture.shape = box; 39 | fixture.density = 1; 40 | shape = body.createFixture(fixture); 41 | } 42 | public function set_velocityX(velX:Float):Float { 43 | moving = true; 44 | body.setAwake(true); 45 | body.getLinearVelocity().x = velX * Const.invWorldScale; 46 | return velX; 47 | } 48 | 49 | public function get_velocityX():Float { 50 | return body.getLinearVelocity().x * Const.worldScale; 51 | } 52 | 53 | public function set_velocityY(velY:Float):Float { 54 | moving = true; 55 | body.setAwake(true); 56 | body.getLinearVelocity().y = velY * Const.invWorldScale; 57 | return velY; 58 | } 59 | 60 | public function get_velocityY():Float { 61 | return body.getLinearVelocity().y * Const.worldScale; 62 | } 63 | 64 | public function set_x(x:Float):Float { 65 | var pos=body.getPosition(); 66 | pos.x= x * Const.invWorldScale; 67 | body.setPosition(pos); 68 | return x; 69 | } 70 | 71 | public function get_x():Float { 72 | return body.getPosition().x * Const.worldScale; 73 | } 74 | 75 | public function set_y(y:Float):Float { 76 | var pos=body.getPosition(); 77 | pos.y = y * Const.invWorldScale; 78 | body.setPosition(pos); 79 | return y; 80 | } 81 | 82 | public function get_y():Float { 83 | return body.getPosition().y * Const.worldScale; 84 | } 85 | 86 | public function update(dt:Float) { 87 | if (!moving) { 88 | body.getLinearVelocity().x *= dragX; 89 | body.getLinearVelocity().y *= dragY; 90 | } 91 | moving = false; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Sources/com/collision/box2d/Tilemap.hx: -------------------------------------------------------------------------------- 1 | package com.collision.box2d; 2 | 3 | import box2D.dynamics.B2World; 4 | import com.gEngine.display.extra.TileMapDisplay; 5 | import format.tmx.Data.TmxTile; 6 | import com.helpers.TilesToPolygons; 7 | import format.tmx.Data.TmxLayer; 8 | import kha.Assets; 9 | import format.tmx.Data.TmxMap; 10 | import box2D.dynamics.B2BodyType; 11 | import com.gEngine.display.Layer; 12 | import box2D.dynamics.B2BodyDef; 13 | 14 | class Tilemap { 15 | public function new() {} 16 | 17 | public function init(tmxData:String, tilesImg:String, tileWidth:Int, tileHeight:Int, world:B2World, displayLayer:Layer) { 18 | var body = new B2BodyDef(); 19 | body.type = B2BodyType.STATIC_BODY; 20 | var floor = world.createBody(body); 21 | var r:format.tmx.Reader = new format.tmx.Reader(); 22 | var t:TmxMap = r.read(Xml.parse(Assets.blobs.get(tmxData).toString())); 23 | for (layer in t.layers) { 24 | switch (layer) { 25 | case TmxLayer.LTileLayer(tileMap): 26 | { 27 | // if (!tileMap.properties.exists("collision")) { 28 | TilesToPolygons.applyTo(tileMap, tileWidth * Const.invWorldScale, tileHeight * Const.invWorldScale, floor, 1); 29 | } 30 | default: 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Sources/com/collision/platformer/Body.hx: -------------------------------------------------------------------------------- 1 | package com.collision.platformer; 2 | 3 | class Body { 4 | public var lastX:Float = 0; 5 | public var lastY:Float = 0; 6 | public var x:Float = 0; 7 | public var y:Float = 0; 8 | public var velocityX:Float = 0; 9 | public var velocityY:Float = 0; 10 | public var lastVelocityX:Float = 0; 11 | public var lastVelocityY:Float = 0; 12 | public var bounce:Float = 0; 13 | public var accelerationX:Float = 0; 14 | public var accelerationY:Float = 0; 15 | public var dragX:Float = 1; 16 | public var dragY:Float = 1; 17 | public var staticObject:Bool = false; 18 | public var maxVelocityX:Float = Math.POSITIVE_INFINITY; 19 | public var maxVelocityY:Float = Math.POSITIVE_INFINITY; 20 | public var touching:Int = Sides.NONE; 21 | 22 | public function new() {} 23 | 24 | public function update(dt:Float):Void { 25 | touching = Sides.NONE; 26 | lastX = x; 27 | lastY = y; 28 | lastVelocityX = velocityX; 29 | lastVelocityY = velocityY; 30 | velocityX += accelerationX * dt; 31 | velocityY += accelerationY * dt; 32 | if (Math.abs(velocityX) > maxVelocityX) { 33 | if (velocityX > 0) { 34 | velocityX = maxVelocityX; 35 | } else { 36 | velocityX = -maxVelocityX; 37 | } 38 | } 39 | if (Math.abs(velocityY) > maxVelocityY) { 40 | if (velocityY > 0) { 41 | velocityY = maxVelocityY; 42 | } else { 43 | velocityY = -maxVelocityY; 44 | } 45 | } 46 | x += velocityX * dt; 47 | y += velocityY * dt; 48 | 49 | if (accelerationX == 0) { 50 | velocityX *= dragX; 51 | if (velocityX*velocityX < 0.5*0.5) { 52 | velocityX = 0; 53 | } 54 | } 55 | if (accelerationY == 0) { 56 | velocityY *= dragY; 57 | if (velocityY*velocityY < 0.5*0.5) { 58 | velocityY = 0; 59 | } 60 | } 61 | } 62 | public function isTouching(side:Int):Bool { 63 | return side & touching > 0; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Sources/com/collision/platformer/Cart.hx: -------------------------------------------------------------------------------- 1 | package com.collision.platformer; 2 | 3 | import kha.math.FastVector2; 4 | 5 | class Cart implements ICollider extends Body { 6 | var normal:FastVector2; 7 | 8 | public var lastStickY:Float = 0; 9 | 10 | public var stick:Bool; 11 | 12 | public var width:Float; 13 | public var height:Float; 14 | public var track:Track; 15 | public var userData:Dynamic; 16 | public var parent:CollisionGroup; 17 | public var distanceFromOrigin:Float=0; 18 | public var length:Float = 0; 19 | 20 | public function new() { 21 | super(); 22 | } 23 | 24 | public function collide(collider:ICollider, ?notifyCallback:ICollider->ICollider->Void):Bool { 25 | return false; 26 | } 27 | 28 | public function overlap(collider:ICollider, ?notifyCallback:ICollider->ICollider->Void):Bool { 29 | return false; 30 | } 31 | 32 | public function collisionType():CollisionType { 33 | return CollisionType.Cart; 34 | } 35 | 36 | public function removeFromParent():Void { 37 | if (parent != null) { 38 | parent.remove(this); 39 | } 40 | } 41 | 42 | #if DEBUGDRAW 43 | public function debugDraw(canvas:kha.Canvas):Void {} 44 | #end 45 | 46 | override function update(dt:Float) { 47 | // if (stick) { 48 | // // if(track.updated){ 49 | // //var pos=track.dir.mult(distanceFromOrigin).add(track.pos); 50 | // var scale = distanceFromOrigin / track.dir.x; 51 | // y = scale * track.dir.y + track.pos.y; 52 | // x=track.pos.x+distanceFromOrigin; 53 | // //y=pos.y; 54 | // lastStickY=y; 55 | // // } 56 | // } 57 | 58 | 59 | if (velocityY < 0 || (stick&& track.isDestroy)) { 60 | clearTrack(); 61 | return; 62 | } 63 | if (stick) { 64 | //var distance = Math.sqrt(velocityX*velocityX+velocityY*velocityY); 65 | length += velocityX*dt; 66 | if (length>0 && length > track.length) { 67 | if (track.nextEdge != null) { 68 | length = length - track.length; 69 | lastStickY=track.pos.y+track.dir.y*track.length; 70 | lastX=track.pos.x+track.dir.x*track.length; 71 | track = track.nextEdge; 72 | } else { 73 | clearTrack(); 74 | return; 75 | } 76 | } else if (length < 0) { 77 | if (track.prevEdge != null) { 78 | track = track.prevEdge; 79 | length = track.length+length; 80 | lastStickY=track.pos.y; 81 | lastX=track.pos.x; 82 | } else { 83 | clearTrack(); 84 | return; 85 | } 86 | }else{ 87 | super.update(dt); 88 | } 89 | var finalPos = track.dir.mult(length); 90 | x = track.pos.x + finalPos.x; 91 | y = track.pos.y + finalPos.y; 92 | lastStickY=y; 93 | velocityY = 0; 94 | distanceFromOrigin=x-track.pos.x; 95 | } 96 | } 97 | 98 | public function clearTrack() { 99 | stick = false; 100 | track = null; 101 | distanceFromOrigin=0; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /Sources/com/collision/platformer/CollisionCircle.hx: -------------------------------------------------------------------------------- 1 | package com.collision.platformer; 2 | 3 | class CollisionCircle extends Body implements ICollider { 4 | public var radio:Float = 0; 5 | 6 | public function new(radio) { 7 | super(); 8 | this.radio = radio; 9 | } 10 | 11 | public function collide(aCollider:ICollider, ?NotifyCallback:ICollider->ICollider->Void):Bool { 12 | if (aCollider.collisionType() == CollisionType.Circle) {} 13 | return false; 14 | } 15 | 16 | public function overlap(collider:ICollider, ?notifyCallback:ICollider->ICollider->Void):Bool { 17 | if (collider.collisionType() == CollisionType.Circle) { 18 | var circle:CollisionCircle = cast collider; 19 | var deltaDistanceX = circle.x - x; 20 | var deltaDistanceY = circle.y - y; 21 | if ((deltaDistanceX * deltaDistanceX + deltaDistanceY * deltaDistanceY) < (circle.radio + radio) * (circle.radio + radio)) { 22 | if (notifyCallback != null) { 23 | notifyCallback(this, collider); 24 | } 25 | return true; 26 | } 27 | return false; 28 | } else if (collider.collisionType() == CollisionType.Group) { 29 | return collider.overlap(this, notifyCallback); 30 | } else if (collider.collisionType() == CollisionType.Box) { 31 | var box:CollisionBox = cast collider; 32 | return this.x>box.x && this.x< box.x+box.width && this.x>box.y && this.y< box.y+box.height; //temp calculation 33 | } 34 | return false; 35 | } 36 | 37 | public function collisionType():CollisionType { 38 | return CollisionType.Circle; 39 | } 40 | 41 | public var userData:Dynamic; 42 | public var parent:CollisionGroup; 43 | 44 | public function removeFromParent():Void { 45 | if (parent != null) { 46 | parent.remove(this); 47 | } 48 | } 49 | 50 | #if DEBUGDRAW 51 | public function debugDraw(canvas:kha.Canvas):Void { 52 | var g2 = canvas.g2; 53 | var iterations = Std.int(radio); 54 | var angle = Math.PI * 2 / iterations; 55 | 56 | for (i in 0...iterations) { 57 | g2.drawLine(x + Math.cos(angle * i) * radio, y + Math.sin(angle * i) * radio, x + Math.cos(angle * (i + 1)) * radio, y + Math.sin(angle * (i + 58 | 1)) * radio); 59 | } 60 | } 61 | #end 62 | } 63 | -------------------------------------------------------------------------------- /Sources/com/collision/platformer/CollisionEngine.hx: -------------------------------------------------------------------------------- 1 | package com.collision.platformer; 2 | 3 | import com.framework.utils.LERP; 4 | import kha.Color; 5 | import kha.math.FastMatrix3; 6 | import com.gEngine.display.Camera; 7 | 8 | /** 9 | * ... 10 | * @author Joaquin 11 | */ 12 | class CollisionEngine { 13 | public function new() {} 14 | 15 | #if DEBUGDRAW 16 | private static var colliders:Array = new Array(); 17 | 18 | public static function renderDebug(canvas:kha.Canvas, camera:Camera) { 19 | canvas.g2.begin(false); 20 | canvas.g2.color = Color.Yellow; 21 | var cV = camera.view; 22 | var scaleX = canvas.width / camera.width; 23 | var scaleY = canvas.height / camera.height; 24 | canvas.g2.transformation = FastMatrix3.scale(scaleX, scaleY).multmat(new FastMatrix3(cV._00, cV._10, cV._30 + camera.width * 0.5, cV._01, cV._11, cV 25 | ._31 + camera.height * 0.5, cV._03, cV._13, cV._33)); 26 | for (collider in colliders) { 27 | collider.debugDraw(canvas); 28 | } 29 | canvas.g2.end(); 30 | colliders.splice(0, colliders.length); 31 | } 32 | #end 33 | 34 | public static function collide(A:ICollider, B:ICollider, aCallBack:ICollider->ICollider->Void = null):Bool { 35 | #if DEBUGDRAW 36 | colliders.push(A); 37 | colliders.push(B); 38 | #end 39 | return A.collide(B, aCallBack); 40 | } 41 | 42 | // temporal function needs to be more generic 43 | public static function bulletCollide(A:CollisionBox, B:ICollider, iterations:Int, aCallBack:ICollider->ICollider->Void = null):Bool { 44 | #if DEBUGDRAW 45 | colliders.push(A); 46 | colliders.push(B); 47 | #end 48 | var returnValue:Bool=false; 49 | var AendX:Float = A.x; 50 | var AendY:Float = A.y; 51 | for (i in 1...(iterations + 1)) { 52 | //avoid interpolation if they are the same value, it can add a rounding error 53 | if(A.x!=A.lastX) A.x = LERP.f(A.lastX, AendX, i / iterations); 54 | if(A.y!=A.lastY) A.y = LERP.f(A.lastY, AendY, i / iterations); 55 | returnValue = A.collide(B, aCallBack)||returnValue; 56 | if(A.y==A.lastY&&A.x==A.lastX)break; 57 | } 58 | 59 | return returnValue; 60 | } 61 | 62 | public static function overlap(A:ICollider, B:ICollider, aCallBack:ICollider->ICollider->Void = null):Bool { 63 | #if DEBUGDRAW 64 | colliders.push(A); 65 | colliders.push(B); 66 | #end 67 | return A.overlap(B, aCallBack); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Sources/com/collision/platformer/CollisionType.hx: -------------------------------------------------------------------------------- 1 | package com.collision.platformer; 2 | 3 | /** 4 | * @author Joaquin 5 | */ 6 | enum abstract CollisionType(Int) { 7 | var Box; 8 | var TileMap; 9 | var Group; 10 | var Circle; 11 | var Track; 12 | var Cart; 13 | } 14 | -------------------------------------------------------------------------------- /Sources/com/collision/platformer/ICollider.hx: -------------------------------------------------------------------------------- 1 | package com.collision.platformer; 2 | 3 | /** 4 | * @author Joaquin 5 | */ 6 | interface ICollider { 7 | public function collide(collider:ICollider, ?notifyCallback:ICollider->ICollider->Void):Bool; 8 | public function overlap(collider:ICollider, ?notifyCallback:ICollider->ICollider->Void):Bool; 9 | public function collisionType():CollisionType; 10 | public var userData:Dynamic; 11 | public var parent:CollisionGroup; // TODO create ICollisionContainer 12 | public function removeFromParent():Void; 13 | #if DEBUGDRAW 14 | public function debugDraw(canvas:kha.Canvas):Void; 15 | #end 16 | } 17 | -------------------------------------------------------------------------------- /Sources/com/collision/platformer/Sides.hx: -------------------------------------------------------------------------------- 1 | package com.collision.platformer; 2 | 3 | /** 4 | * @author Joaquin 5 | */ 6 | class Sides { 7 | public inline static var NONE:Int = 0x00000; 8 | public inline static var LEFT:Int = 0x00001; 9 | public inline static var RIGHT:Int = 0x00002; 10 | public inline static var TOP:Int = 0x00004; 11 | public inline static var BOTTOM:Int = 0x00008; 12 | public inline static var ALL:Int = LEFT | RIGHT | TOP | BOTTOM; 13 | } 14 | -------------------------------------------------------------------------------- /Sources/com/debug/Profiler.hx: -------------------------------------------------------------------------------- 1 | package com.debug; 2 | 3 | import kha.Scheduler; 4 | 5 | class Profiler { 6 | #if profile 7 | static var functionsTimes:Array> = new Array(); 8 | static var functionsNames:Array = new Array(); 9 | static var counter:Int=0; 10 | #end 11 | 12 | public inline static function startMeasure(name:String) { 13 | #if profile 14 | var index = functionsNames.indexOf(name); 15 | if (index < 0) { 16 | index = functionsNames.push(name) - 1; 17 | functionsTimes.push(new Array()); 18 | } 19 | functionsTimes[index].push(Scheduler.realTime()); 20 | ++counter; 21 | #end 22 | } 23 | 24 | public inline static function endMeasure(name:String) { 25 | #if profile 26 | var time = Scheduler.realTime(); 27 | var index = functionsNames.indexOf(name); 28 | if (index >= 0) { 29 | var times = functionsTimes[index]; 30 | var endIndex = times.length - 1; 31 | var startTime = times[endIndex]; 32 | times[endIndex] = time - startTime; 33 | }else{ 34 | throw "call startMeasure before ending it"; 35 | } 36 | --counter; 37 | #end 38 | } 39 | 40 | public inline static function show() { 41 | #if (!worker && profile) 42 | if(counter!=0){ 43 | throw "close all measures before calling show"; 44 | } 45 | trace("Profiler///////////////////////////////"); 46 | var i:Int = 0; 47 | for (name in functionsNames) { 48 | var activeTime:Float = 0; 49 | var times:Array = functionsTimes[i]; 50 | for (time in times) { 51 | activeTime += time; 52 | } 53 | trace(name + " total: " + activeTime + " avg: " + activeTime / times.length + " frame% " + 100*((activeTime / times.length) / (1 / 60))); 54 | ++i; 55 | } 56 | #end 57 | } 58 | 59 | public inline static function clear() { 60 | #if profile 61 | functionsNames.splice(0, functionsNames.length); 62 | functionsTimes.splice(0, functionsTimes.length); 63 | #end 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Sources/com/framework/utils/Interpolation.hx: -------------------------------------------------------------------------------- 1 | package com.framework.utils; 2 | 3 | class Interpolation { 4 | public static function easingOut(a:Float, b:Float, s:Float):Float { 5 | return -b * s * (s - 2) + a; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Sources/com/framework/utils/JoystickProxy.hx: -------------------------------------------------------------------------------- 1 | package com.framework.utils; 2 | 3 | import kha.input.Gamepad; 4 | 5 | class JoystickProxy { 6 | var buttons:Array; 7 | var axes:Array; 8 | var pressed:Array; 9 | var released:Array; 10 | var gamepad:Gamepad; 11 | var onAxisChange:Int->Float->Void; 12 | var onButtonChange:Int->Float->Void; 13 | var id:Int; 14 | 15 | public var active(default, null):Bool; 16 | 17 | public function new(id:Int) { 18 | this.id = id; 19 | buttons = new Array(); 20 | axes = new Array(); 21 | pressed = new Array(); 22 | released = new Array(); 23 | 24 | onConnect(); 25 | // add more than needed just to be safe 26 | for (i in 0...20) { 27 | buttons.push(0); 28 | } 29 | for (i in 0...7) { 30 | axes.push(0); 31 | } 32 | } 33 | 34 | public function notify(onAxisChange:Int->Float->Void, onButtonChange:Int->Float->Void) { 35 | this.onAxisChange = onAxisChange; 36 | this.onButtonChange = onButtonChange; 37 | } 38 | 39 | public function onConnect() { 40 | if (!active) { 41 | gamepad = Gamepad.get(id); 42 | if (gamepad != null) { 43 | gamepad.notify(onAxis, onButton); 44 | active = true; 45 | } 46 | } 47 | } 48 | 49 | public function onDisconnect() { 50 | if (active) { 51 | gamepad = Gamepad.get(id); 52 | if (gamepad != null) { 53 | gamepad.remove(onAxis, onButton); 54 | active = false; 55 | } 56 | } 57 | } 58 | 59 | function onAxis(id:Int, value:Float) { 60 | axes[id] = value; 61 | if (onAxisChange != null) 62 | onAxisChange(id, value); 63 | } 64 | 65 | function onButton(id:Int, value:Float) { 66 | buttons[id] = value; 67 | if (value == 0) { 68 | released.push(id); 69 | } else { 70 | pressed.push(id); 71 | } 72 | if (onButtonChange != null) 73 | onButtonChange(id, value); 74 | } 75 | 76 | public function update() { 77 | released.splice(0, released.length); 78 | pressed.splice(0, pressed.length); 79 | } 80 | 81 | public function clearInput() { 82 | released.splice(0, released.length); 83 | pressed.splice(0, pressed.length); 84 | for (i in 0...buttons.length) { 85 | buttons[i] = 0; 86 | } 87 | onButtonChange = null; 88 | onAxisChange = null; 89 | } 90 | 91 | public function buttonPressed(id:Int):Bool { 92 | for (i in pressed) { 93 | if (i == id) 94 | return true; 95 | } 96 | return false; 97 | } 98 | 99 | public function buttonReleased(id:Int):Bool { 100 | for (i in released) { 101 | if (i == id) 102 | return true; 103 | } 104 | return false; 105 | } 106 | 107 | public function buttonDown(id:Int):Bool { 108 | return buttons[id] == 1; 109 | } 110 | 111 | public function axis(id:Int):Float { 112 | return axes[id]; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /Sources/com/framework/utils/LERP.hx: -------------------------------------------------------------------------------- 1 | package com.framework.utils; 2 | 3 | class LERP { 4 | public static inline function f(aA:Float, aB:Float, aS:Float):Float { 5 | return aB * aS - aA * (aS - 1); 6 | } 7 | 8 | public static inline function s(current:Float, total:Float):Float { 9 | return current / total; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Sources/com/framework/utils/Random.hx: -------------------------------------------------------------------------------- 1 | package com.framework.utils; 2 | 3 | class Random { 4 | inline public static function getRandom():Float { 5 | return kha.math.Random.getFloat(); 6 | } 7 | 8 | inline public static function getRandomIn(min:Float, max:Float):Float { 9 | return kha.math.Random.getFloatIn(min, max); 10 | } 11 | 12 | inline public static function init(seed:Int) { 13 | kha.math.Random.init(seed); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Sources/com/framework/utils/SaveFile.hx: -------------------------------------------------------------------------------- 1 | package com.framework.utils; 2 | #if js 3 | import js.lib.DataView; 4 | import js.lib.ArrayBuffer; 5 | import js.html.FileReader; 6 | import js.html.Attr; 7 | import js.html.InputElement; 8 | import haxe.io.Bytes; 9 | 10 | import js.Browser; 11 | import js.html.Blob; 12 | import js.html.URL; 13 | import js.html.AnchorElement; 14 | #end 15 | class SaveFile { 16 | 17 | private static function _saveBytes(bytes:Bytes, name:String , type:String ) 18 | { 19 | #if js 20 | var a = Browser.document.createAnchorElement(); 21 | var blob = new Blob([bytes.getData()], {type: type}); 22 | var url = URL.createObjectURL(blob); 23 | 24 | a.href = url; 25 | a.download = name; 26 | Browser.document.body.appendChild(a); 27 | 28 | a.click(); 29 | 30 | Browser.window.setTimeout(function() 31 | { 32 | Browser.document.body.removeChild(a); 33 | URL.revokeObjectURL(url); 34 | }, 0); 35 | #end 36 | 37 | trace("Saved"); 38 | } 39 | public static function saveBytes(bytes:Bytes, name:String , type:String ) 40 | { 41 | _saveBytes(bytes, name, type); 42 | } 43 | 44 | public static function openFile(onRead:StreamReader->Void) { 45 | var input:InputElement = Browser.document.createInputElement(); 46 | input.type="file"; 47 | input.onchange=function handleFile() { 48 | var reader = new FileReader(); 49 | reader.onload = function() { 50 | var arrayBuffer:ArrayBuffer =cast reader.result; 51 | var dataView=new DataView(arrayBuffer); 52 | onRead(new StreamReader(dataView)); 53 | } 54 | reader.readAsArrayBuffer(input.files[0]); 55 | } 56 | input.click(); 57 | 58 | //input.op 59 | //input.attributes.setNamedItem({"type", "file"}); 60 | // add onchange handler if you wish to get the file :) 61 | //input.tr("click"); // opening dialog 62 | return false; // avoiding navigation 63 | } 64 | 65 | } 66 | class StreamReader { 67 | #if js 68 | var data:DataView; 69 | #end 70 | var offset:Int; 71 | 72 | public function new(data:DataView) { 73 | this.data=data; 74 | offset=0; 75 | } 76 | public function readInt32() { 77 | var value=data.getInt32(offset,true); 78 | offset+=4; 79 | return value; 80 | } 81 | public function readFloat() { 82 | var value=data.getFloat32(offset,true); 83 | offset+=4; 84 | return value; 85 | } 86 | public function finish() { 87 | return data.byteLength==offset; 88 | } 89 | } -------------------------------------------------------------------------------- /Sources/com/framework/utils/UIComponent.hx: -------------------------------------------------------------------------------- 1 | package com.framework.utils; 2 | 3 | interface UIComponent { 4 | public function handleInput():Void; 5 | } 6 | -------------------------------------------------------------------------------- /Sources/com/framework/utils/XboxJoystick.hx: -------------------------------------------------------------------------------- 1 | package com.framework.utils; 2 | 3 | class XboxJoystick { 4 | public static inline var A:Int = 0; 5 | public static inline var B:Int = 1; 6 | public static inline var X:Int = 2; 7 | public static inline var Y:Int = 3; 8 | public static inline var LB:Int = 4; 9 | public static inline var RB:Int = 5; 10 | public static inline var LT:Int = 6; 11 | public static inline var RT:Int = 7; 12 | public static inline var SELECT:Int = 8; 13 | public static inline var START:Int = 9; 14 | public static inline var LEFT_ANALOG:Int = 10; 15 | public static inline var RIGHT_ANALOG:Int = 11; 16 | public static inline var UP_DPAD:Int = 12; 17 | public static inline var DOWN_DPAD:Int = 13; 18 | public static inline var LEFT_DPAD:Int = 14; 19 | public static inline var RIGHT_DPAD:Int = 15; 20 | public static inline var AXIS_LEFTX:Int = 0; 21 | public static inline var AXIS_LEFTY:Int = 1; 22 | public static inline var AXIS_RIGHTX:Int = 2; 23 | public static inline var AXIS_RIGHTY:Int = 3; 24 | public static inline var ANALOG_LT:Int = 4; 25 | public static inline var ANALOG_RT:Int = 5; 26 | } 27 | -------------------------------------------------------------------------------- /Sources/com/fx/Particle.hx: -------------------------------------------------------------------------------- 1 | package com.fx; 2 | 3 | import com.gEngine.display.IRotation; 4 | import com.framework.utils.Entity; 5 | import com.gEngine.display.Layer; 6 | import com.helpers.FastPoint; 7 | 8 | class Particle extends Entity { 9 | public var animation:IRotation; 10 | 11 | private var mX:Float = 0; 12 | private var mY:Float = 0; 13 | private var mLife:Float = 0; 14 | private var mTotalLife:Float = 0; 15 | private var mVelocity:FastPoint = new FastPoint(); 16 | public var dragX:Float = 1; 17 | public var dragY:Float = 1; 18 | 19 | public var gravity:Float = 100; 20 | public var accelerationX:Float = 0; 21 | public var mAngularVelocity:Float = 0; 22 | 23 | public function new(display:IRotation) { 24 | super(); 25 | die(); 26 | setAnimation(display); 27 | } 28 | 29 | public function setAnimation(display:IRotation):Void { 30 | animation = display; 31 | } 32 | 33 | public function reset(x:Float, y:Float, life:Float, speedX:Float, speedY:Float, layer:Layer, angularVelocity:Float, scale:Float = 1):Void { 34 | mX = x; 35 | mY = y; 36 | mLife = mTotalLife = life; 37 | mVelocity.x = speedX; 38 | mVelocity.y = speedY; 39 | layer.addChild(animation); 40 | animation.x = x; 41 | animation.y = y; 42 | mAngularVelocity = angularVelocity; 43 | animation.scaleX = animation.scaleY = mInitialScale = scale; 44 | animation.rotation = 0; 45 | } 46 | 47 | override private function limboStart():Void { 48 | animation.removeFromParent(); 49 | } 50 | 51 | public var scaleAtDeath:Bool; 52 | 53 | private var mInitialScale:Float; 54 | 55 | override public function update(aDt:Float):Void { 56 | mLife -= aDt; 57 | if (mLife < 0) { 58 | die(); 59 | return; 60 | } 61 | if (scaleAtDeath) { 62 | animation.scaleX = animation.scaleY = mInitialScale * mLife / mTotalLife; 63 | } 64 | 65 | mVelocity.x = mVelocity.x*dragX + accelerationX * aDt; 66 | mVelocity.y = mVelocity.y*dragY + gravity * aDt; 67 | mX += mVelocity.x * aDt; 68 | mY += mVelocity.y * aDt; 69 | animation.x = mX; 70 | animation.y = mY; 71 | animation.rotation += mAngularVelocity * aDt; 72 | 73 | // if (mAnimation.TotalFrames > 0) 74 | { 75 | // mAnimation.goToAndStop(Std.int((mAnimation.TotalFrames - 1) * (1-mLife / mTotalLife))); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Sources/com/g3d/Bone.hx: -------------------------------------------------------------------------------- 1 | package com.g3d; 2 | 3 | import kha.math.FastMatrix4; 4 | 5 | class Bone { 6 | public var bindTransform:FastMatrix4; 7 | public var finalTransform:FastMatrix4; 8 | public var children:Array; 9 | public var animations:Array; 10 | public var id:String; 11 | public var animated:Bool; 12 | 13 | public function new() { 14 | children = new Array(); 15 | finalTransform = FastMatrix4.identity(); 16 | } 17 | 18 | public function clone():Bone { 19 | var cl = new Bone(); 20 | cl.id = id; 21 | 22 | for (child in children) { 23 | cl.children.push(child.clone()); 24 | } 25 | if (animated) { 26 | cl.animations = new Array(); 27 | for (animation in animations) { 28 | cl.animations.push(animation); 29 | } 30 | } 31 | cl.bindTransform = bindTransform; 32 | cl.animated = animated; 33 | return cl; 34 | } 35 | 36 | public function addChild(bone:Bone) { 37 | children.push(bone); 38 | } 39 | 40 | public function setFrame(frame:Int, transform:FastMatrix4) { 41 | if (!animated) { 42 | finalTransform = bindTransform; 43 | } else { 44 | matrixFromArray(animations, frame * 16, finalTransform); 45 | } 46 | var toPass:FastMatrix4 = transform.multmat(finalTransform); 47 | finalTransform = toPass.multmat(bindTransform.inverse()); 48 | 49 | for (child in children) { 50 | child.setFrame(frame, toPass); 51 | } 52 | } 53 | 54 | public function getBone(id:String):Bone { 55 | for (child in children) { 56 | if (child.id == id) 57 | return child; 58 | var result = child.getBone(id); 59 | if (result != null) 60 | return result; 61 | } 62 | return null; 63 | } 64 | 65 | public static function matrixFromArray(values:Array, offset:Int, matrix:FastMatrix4):Void { 66 | matrix._00 = values[offset++]; 67 | matrix._01 = values[offset++]; 68 | matrix._02 = values[offset++]; 69 | matrix._03 = values[offset++]; 70 | 71 | matrix._10 = values[offset++]; 72 | matrix._11 = values[offset++]; 73 | matrix._12 = values[offset++]; 74 | matrix._13 = values[offset++]; 75 | 76 | matrix._20 = values[offset++]; 77 | matrix._21 = values[offset++]; 78 | matrix._22 = values[offset++]; 79 | matrix._23 = values[offset++]; 80 | 81 | matrix._30 = values[offset++]; 82 | matrix._31 = values[offset++]; 83 | matrix._32 = values[offset++]; 84 | matrix._33 = values[offset++]; 85 | matrix.inverse(); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /Sources/com/g3d/Object3dDB.hx: -------------------------------------------------------------------------------- 1 | package com.g3d; 2 | 3 | import com.gEngine.GEngine; 4 | import com.framework.Simulation; 5 | import com.loading.ResourceHandler; 6 | 7 | class Object3dDB implements ResourceHandler { 8 | var objects:Map>; 9 | var skeletons:Map; 10 | 11 | public static var i(get, null):Object3dDB; 12 | 13 | public static function get_i() { 14 | if (i == null) { 15 | i = new Object3dDB(); 16 | } 17 | return i; 18 | } 19 | 20 | private function new() { 21 | objects = new Map(); 22 | skeletons = new Map(); 23 | Simulation.i.addResourceHandler(this); 24 | } 25 | 26 | public function add(name:String, data:Array) { 27 | for (parts in data) { 28 | GEngine.i.addTexture(parts.texture); 29 | } 30 | objects.set(name, data); 31 | } 32 | 33 | public function addSkeleton(name:String, skeleton:SkeletonD) { 34 | skeletons.set(name, skeleton); 35 | } 36 | 37 | public function getData(name:String):Array { 38 | #if debug 39 | if (!objects.exists(name)) 40 | throw "object3d with name " + name + " not found. Make sure it's loaded"; 41 | #end 42 | return objects.get(name); 43 | } 44 | 45 | public function getSkeleton(name:String):SkeletonD { 46 | if (!skeletons.exists(name)) 47 | return null; 48 | return skeletons.get(name); 49 | } 50 | 51 | public function clear():Void { 52 | for (object in objects) { 53 | for (part in object) { 54 | part.unload(); 55 | } 56 | } 57 | objects = new Map(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Sources/com/g3d/Object3dData.hx: -------------------------------------------------------------------------------- 1 | package com.g3d; 2 | 3 | import kha.math.FastMatrix4; 4 | import kha.graphics4.IndexBuffer; 5 | import kha.graphics4.VertexBuffer; 6 | import kha.Image; 7 | 8 | class Object3dData { 9 | public var vertexBuffer:VertexBuffer; 10 | public var indexBuffer:IndexBuffer; 11 | public var skin:Skinning; 12 | public var animated:Bool; 13 | public var texture:Image; 14 | public var modelTransform:FastMatrix4; 15 | 16 | public function new() {} 17 | 18 | public function unload() { 19 | vertexBuffer.delete(); 20 | indexBuffer.delete(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Sources/com/g3d/Object3dLoader.hx: -------------------------------------------------------------------------------- 1 | package com.g3d; 2 | 3 | import kha.Image; 4 | import kha.Blob; 5 | import com.loading.Resource; 6 | import kha.Assets; 7 | 8 | class Object3dLoader implements Resource { 9 | var name:String; 10 | var onLoad:Void->Void; 11 | var neededResources:Int = 0; 12 | var data:OgexData; 13 | 14 | public function new(dataName:String) { 15 | name = dataName; 16 | } 17 | 18 | public function load(callback:Void->Void):Void { 19 | onLoad = callback; 20 | ++neededResources; 21 | Assets.loadBlob(name, loadBlob); 22 | } 23 | 24 | public function loadLocal(callback:Void->Void):Void { 25 | onLoad = callback; 26 | ++neededResources; 27 | loadBlob(cast Reflect.field(Assets.blobs, name)); 28 | } 29 | 30 | function loadBlob(b:Blob) { 31 | data = new OgexData(b.toString()); 32 | for (material in data.materials) { 33 | for (tex in material.texture) { 34 | ++neededResources; 35 | var parts = tex.path.split("/"); 36 | var ss = parts[parts.length - 1]; 37 | ss = StringTools.replace(ss, "-", "_"); 38 | ss = StringTools.replace(ss, " ", "_"); 39 | Assets.loadImage(ss.split(".")[0], function(i) { 40 | somthingLoaded(); 41 | }); 42 | } 43 | } 44 | somthingLoaded(); 45 | } 46 | 47 | function somthingLoaded() { 48 | --neededResources; 49 | if (neededResources <= 0) { 50 | var sk = SkeletonLoader.getSkeleton(data); 51 | var obj3d = MeshExtractor.extract(data, sk); 52 | Object3dDB.i.add(name, obj3d); 53 | if (sk.length > 0) { 54 | sk[0].setFrame(0); 55 | Object3dDB.i.addSkeleton(name, sk[0]); 56 | } 57 | 58 | onLoad(); 59 | } 60 | } 61 | 62 | public function unload():Void { 63 | Reflect.callMethod(Assets.blobs, Reflect.field(Assets.blobs, name + "Unload"), []); 64 | } 65 | 66 | public function unloadLocal():Void {} 67 | } 68 | -------------------------------------------------------------------------------- /Sources/com/g3d/SkeletonD.hx: -------------------------------------------------------------------------------- 1 | package com.g3d; 2 | 3 | import kha.math.FastMatrix4; 4 | 5 | class SkeletonD { 6 | public var transformation:FastMatrix4; 7 | public var bones:Array; 8 | public var ID:String; 9 | 10 | public function new() { 11 | transformation = FastMatrix4.identity(); 12 | bones = new Array(); 13 | } 14 | 15 | public function setFrame(frame:Int) { 16 | for (child in bones) { 17 | child.setFrame(frame, transformation); 18 | } 19 | } 20 | 21 | public function totalFrames():Int { 22 | if (!bones[0].animated) 23 | return 0; 24 | return Std.int(bones[0].animations.length / 16); 25 | } 26 | 27 | public function getBone(id:String):Bone { 28 | for (child in bones) { 29 | if (child.id == id) 30 | return child; 31 | var result = child.getBone(id); 32 | if (result != null) 33 | return result; 34 | } 35 | return null; 36 | } 37 | 38 | public function clone():SkeletonD { 39 | var cl = new SkeletonD(); 40 | cl.transformation = transformation; 41 | cl.ID = ID; 42 | for (bone in bones) { 43 | cl.bones.push(bone.clone()); 44 | } 45 | 46 | return cl; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Sources/com/g3d/SkeletonLoader.hx: -------------------------------------------------------------------------------- 1 | package com.g3d; 2 | 3 | import com.g3d.OgexData.BoneNode; 4 | import com.g3d.OgexData.Node; 5 | 6 | class SkeletonLoader { 7 | public static function getSkeleton(data:OgexData):Array { 8 | var skeletons:Array = new Array(); 9 | for (child in data.children) { 10 | findSkeleton(child, skeletons, null); 11 | } 12 | return skeletons; 13 | } 14 | 15 | public static function findSkeleton(node:Node, skeletons:Array, current:Bone) { 16 | var skeleton:SkeletonD = null; 17 | for (node in node.children) { 18 | if (Std.is(node, BoneNode)) { 19 | var boneNode:BoneNode = cast node; 20 | if (skeleton == null && current == null) { 21 | skeleton = new SkeletonD(); 22 | skeleton.ID = node.ref; 23 | skeletons.push(skeleton); 24 | } 25 | var bone = createBone(boneNode); 26 | if (current != null) { 27 | current.addChild(bone); 28 | } else { 29 | skeleton.bones.push(bone); 30 | } 31 | findSkeleton(boneNode, skeletons, bone); 32 | } 33 | } 34 | } 35 | 36 | static private function createBone(boneNode:BoneNode):Bone { 37 | var bone:Bone = new Bone(); 38 | bone.id = boneNode.ref; 39 | if (boneNode.animation != null) { 40 | bone.animated = true; 41 | bone.animations = boneNode.animation.track.value.key.values; 42 | } else { 43 | bone.animated = false; 44 | // bone.animations = boneNode.transform.values; 45 | } 46 | return bone; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Sources/com/g3d/Skinning.hx: -------------------------------------------------------------------------------- 1 | package com.g3d; 2 | 3 | import kha.math.FastMatrix4; 4 | import kha.arrays.Float32Array; 5 | 6 | class Skinning { 7 | private var bones:Array; 8 | private var matrices:Float32Array; 9 | 10 | public function new(bones:Array) { 11 | this.bones = bones; 12 | matrices = new Float32Array(bones.length * 16); 13 | } 14 | 15 | public function getBonesTransformations():Float32Array { 16 | var offset:Int = 0; 17 | for (bone in bones) { 18 | appendMatrix(matrices, bone.finalTransform, offset); 19 | offset += 16; 20 | } 21 | return matrices; 22 | } 23 | 24 | function appendMatrix(list:Float32Array, matrix:FastMatrix4, offset:Int):Void { 25 | list.set(offset + 0, matrix._00); 26 | list.set(offset + 1, matrix._01); 27 | list.set(offset + 2, matrix._02); 28 | list.set(offset + 3, matrix._03); 29 | list.set(offset + 4, matrix._10); 30 | list.set(offset + 5, matrix._11); 31 | list.set(offset + 6, matrix._12); 32 | list.set(offset + 7, matrix._13); 33 | list.set(offset + 8, matrix._20); 34 | list.set(offset + 9, matrix._21); 35 | list.set(offset + 10, matrix._22); 36 | list.set(offset + 11, matrix._23); 37 | list.set(offset + 12, matrix._30); 38 | list.set(offset + 13, matrix._31); 39 | list.set(offset + 14, matrix._32); 40 | list.set(offset + 15, matrix._33); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Sources/com/gEngine/AnimationData.hx: -------------------------------------------------------------------------------- 1 | package com.gEngine; 2 | 3 | class AnimationData { 4 | public var name:String; 5 | public var texturesID:Int = -1; 6 | public var frames:Array; 7 | public var labels:Array