Exemplo n.º 1
0
        public static SourceBuffer[] Generate(int count)
        {
            OpenAL.DebugFormat("Generating {0} source buffers", count);

            lock (lck)
            {
                if (Buffers == null)
                {
                    Buffers = new Dictionary <uint, SourceBuffer> (count);
                }

                SourceBuffer[] buffers = new SourceBuffer[count];

                uint[] bufferIDs = new uint[count];
                alGenBuffers(count, bufferIDs);
                OpenAL.ErrorCheck();

                for (int i = 0; i < count; ++i)
                {
                    OpenAL.DebugFormat("Generated source buffer {0}", bufferIDs[i]);

                    buffers[i] = new SourceBuffer(bufferIDs[i]);
                    Buffers.Add(buffers[i].bufferID, buffers[i]);
                }

                return(buffers);
            }
        }
        public void sampleData()
        {
            clearData();
            Machines        = 3;
            ProcessesAmount = 2;
            for (int p = 0; p < ProcessesAmount; p++)
            {
                var process = new Process(p + 1);
                if (p == 0)
                {
                    process.Operations.Add(new Operation(10, 1, 1, p + 1));
                    process.Operations.Add(new Operation(20, 2, 2, p + 1));
                    process.Operations.Add(new Operation(30, 3, 3, p + 1));
                }
                if (p == 1)
                {
                    process.Operations.Add(new Operation(5, 1, 3, p + 1));
                    process.Operations.Add(new Operation(15, 2, 2, p + 1));
                    process.Operations.Add(new Operation(25, 3, 1, p + 1));
                }
                Processes.Add(process);

                Inputs.Add(new Input(p + 1, p * 2 + 2));
            }
            for (int m = 0; m < Machines; m++)
            {
                Buffers.Add(new Buffer(m + 1, 2));
            }
        }
Exemplo n.º 3
0
        public Hunterpie()
        {
            if (CheckIfHunterPieOpen())
            {
                Close();
                return;
            }

            AppDomain.CurrentDomain.UnhandledException += ExceptionLogger;

            SetDPIAwareness();

            Buffers.Initialize(1024);
            Buffers.Add <byte>(64);

            // Initialize debugger and player config
            Debugger.InitializeDebugger();
            UserSettings.InitializePlayerConfig();

            // Initialize localization
            GStrings.InitStrings(UserSettings.PlayerConfig.HunterPie.Language);

            // Load custom theme and console colors
            LoadCustomTheme();
            Debugger.LoadNewColors();

            InitializeComponent();

            OpenDebugger();
            // Initialize everything under this line
            if (!CheckIfUpdateEnableAndStart())
            {
                return;
            }

            Width  = UserSettings.PlayerConfig.HunterPie.Width;
            Height = UserSettings.PlayerConfig.HunterPie.Height;

            // Convert the old HotKey to the new one
            ConvertOldHotkeyToNew(UserSettings.PlayerConfig.Overlay.ToggleDesignModeKey);

            IsUpdating = false;
            InitializeTrayIcon();

            // Update version text
            this.version_text.Text = GStrings.GetLocalizationByXPath("/Console/String[@ID='CONSOLE_VERSION']").Replace("{HunterPie_Version}", HUNTERPIE_VERSION).Replace("{HunterPie_Branch}", UserSettings.PlayerConfig.HunterPie.Update.Branch);

            // Initializes the rest of HunterPie
            LoadData();
            Debugger.Warn(GStrings.GetLocalizationByXPath("/Console/String[@ID='MESSAGE_HUNTERPIE_INITIALIZED']"));

            BUTTON_UPLOADBUILD.IsEnabled = false;
            BUTTON_UPLOADBUILD.Opacity   = 0.5;

            SetHotKeys();
            StartEverything();
        }
Exemplo n.º 4
0
 /// <summary>
 /// Creates a UISpriteBatch. Same as spritebatch with some extra functionality
 /// required by the UI system of this game.
 ///
 /// NumBuffers refers to a number of RenderTarget2D objects to create up front.
 /// These should be used for temp rendering for special effects. E.g. rendering
 /// part of the GUI to a texture and then painting it with opacity onto the main
 /// target.
 /// </summary>
 /// <param name="gd"></param>
 /// <param name="numBuffers">The number of rendering buffers to pre-alloc</param>
 public UISpriteBatch(GraphicsDevice gd, int numBuffers)
     : base(gd)
 {
     for (var i = 0; i < numBuffers; i++)
     {
         Buffers.Add(
             RenderUtils.CreateRenderTarget(gd, 1, SurfaceFormat.Color, gd.Viewport.Width, gd.Viewport.Height)
             );
     }
 }
Exemplo n.º 5
0
        public void Push(T[] buffer, bool isLastBuffer)
        {
            Buffers.Add(buffer);
            reachLast = isLastBuffer;

            if (IsFilled)
            {
                Filled?.Invoke(this, EventArgs.Empty);
            }
        }
Exemplo n.º 6
0
        //データのバイナリ読み込み
        public void Read(BinaryReader reader)
        {
            Buffers.Clear();
            int count = reader.ReadInt32();

            for (int i = 0; i < count; ++i)
            {
                Buffers.Add(reader.ReadString(), reader.ReadBuffer());
            }
        }
Exemplo n.º 7
0
        public void Push(T[] buffer, bool isLastBuffer)
        {
            Buffers.Add(buffer);
            BufferedDataCount += buffer.Length;
            reachLast          = isLastBuffer;

            if (IsFilled)
            {
                Filled?.Invoke(this, EventArgs.Empty);
            }
        }
Exemplo n.º 8
0
 public GraphicsBuffer <T> CreateBuffer <T>(string attributeName, GraphicsBufferBase.BufferType bufferType) where T : struct
 {
     if (Buffers.ContainsKey(bufferType))
     {
         return(Buffers[bufferType] as GraphicsBuffer <T>);
     }
     else
     {
         var vbo = new GraphicsBuffer <T>(this, bufferType.ToString(), attributeName, bufferType);
         Buffers.Add(bufferType, vbo);
         return(vbo);
     }
 }
Exemplo n.º 9
0
 public override void Write(byte[] buffer, int offset, int count)
 {
     if (KeepReferences && offset == 0 && count == buffer.Length)
     {
         //Keep the reference to the original buffer
         Buffers.Add(buffer);
     }
     else
     {
         Buffers.Add(Utils.SliceBuffer(buffer, offset, count));
     }
     TotalLength   += count;
     this._position = TotalLength;
 }
Exemplo n.º 10
0
        public _2DWorldBatch(GraphicsDevice device, int numBuffers, SurfaceFormat[] surfaceFormats)
        {
            this.Device = device;
            this.Effect = WorldContent._2DWorldBatchEffect;
            //TODO: World size
            ResetMatrices(device.Viewport.Width, device.Viewport.Height);

            for (var i = 0; i < numBuffers; i++)
            {
                Buffers.Add(
                    RenderUtils.CreateRenderTarget(device, 1, surfaceFormats[i], device.Viewport.Width, device.Viewport.Height)
                    );
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Creates a UISpriteBatch. Same as spritebatch with some extra functionality
        /// required by the UI system of this game.
        ///
        /// NumBuffers refers to a number of RenderTarget2D objects to create up front.
        /// These should be used for temp rendering for special effects. E.g. rendering
        /// part of the GUI to a texture and then painting it with opacity onto the main
        /// target.
        /// </summary>
        /// <param name="gd"></param>
        /// <param name="numBuffers">The number of rendering buffers to pre-alloc</param>
        public UISpriteBatch(GraphicsDevice gd, int numBuffers, int width, int height, int multisample)
            : base(gd)
        {
            _Width  = width;
            _Height = height;

            for (var i = 0; i < numBuffers; i++)
            {
                Buffers.Add(
                    RenderUtils.CreateRenderTarget(gd, 1, multisample, SurfaceFormat.Color, width, height)
                    );
            }

            base.GraphicsDevice.DeviceReset += new EventHandler <EventArgs>(gd_DeviceReset);
        }
Exemplo n.º 12
0
        private void gd_DeviceReset(object sender, EventArgs e)
        {
            Invalidated = true;

            Buffers.Clear();
            for (var i = 0; i < 3; i++)
            {
                Buffers.Add(
                    PPXDepthEngine.CreateRenderTarget(base.GraphicsDevice, 1, 0, SurfaceFormat.Color,
                                                      Width, Height, DepthFormat.None)
                    );
            }

            Invalidated = false;
        }
Exemplo n.º 13
0
        private void gd_DeviceReset(object sender, EventArgs e)
        {
            Invalidated = true;

            Buffers.Clear();
            for (var i = 0; i < 3; i++)
            {
                Buffers.Add(
                    RenderUtils.CreateRenderTarget(base.GraphicsDevice, 1, SurfaceFormat.Color,
                                                   base.GraphicsDevice.Viewport.Width, base.GraphicsDevice.Viewport.Height)
                    );
            }

            Invalidated = false;
        }
Exemplo n.º 14
0
        public void GenBuffers(int bwidth, int bheight)
        {
            foreach (var buffer in Buffers)
            {
                buffer.Dispose();
            }
            Buffers.Clear();

            ResetMatrices(bwidth, bheight);

            ScreenWidth  = bwidth;
            ScreenHeight = bheight;

            for (var i = 0; i < NumBuffers; i++)
            {
                int width  = bwidth + ScrollBuffer;
                int height = bheight + ScrollBuffer;

                switch (i)
                {
                case 2:     //World2D.BUFFER_OBJID
                    width  = 1;
                    height = 1;
                    break;

                case 3:     //World2D.BUFFER_THUMB
                case 4:
                    width  = 1024;
                    height = 1024;
                    break;

                case 5:
                    width  = 576;
                    height = 576;
                    break;
                }

                if (NumBuffers == 2)
                {
                    width = height = 1024;                                                                          //special case, thumb only.
                }
                var depthformat = FSOEnvironment.SoftwareDepth ? DepthFormat.Depth24Stencil8 : DepthFormat.Depth24; //stencil is used for software depth
                Buffers.Add(
                    PPXDepthEngine.CreateRenderTarget(Device, 1, 0, SurfaceFormats[i], width, height,
                                                      (AlwaysDS[i] || (!FSOEnvironment.UseMRT && !FSOEnvironment.SoftwareDepth)) ? depthformat : DepthFormat.None)
                    );
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Creates a UISpriteBatch. Same as spritebatch with some extra functionality
        /// required by the UI system of this game.
        ///
        /// NumBuffers refers to a number of RenderTarget2D objects to create up front.
        /// These should be used for temp rendering for special effects. E.g. rendering
        /// part of the GUI to a texture and then painting it with opacity onto the main
        /// target.
        /// </summary>
        /// <param name="gd"></param>
        /// <param name="numBuffers">The number of rendering buffers to pre-alloc</param>
        public UISpriteBatch(GraphicsDevice gd, int numBuffers, int width, int height, int multisample)
            : base(gd)
        {
            _Width  = width;
            _Height = height;

            for (var i = 0; i < numBuffers; i++)
            {
                Buffers.Add(
                    PPXDepthEngine.CreateRenderTarget(gd, 1, multisample, SurfaceFormat.Color, width, height, DepthFormat.None)
                    );
            }
            AllBuffers = new List <RenderTarget2D>(Buffers);

            //base.GraphicsDevice.DeviceReset += new EventHandler<EventArgs>(gd_DeviceReset);
        }
Exemplo n.º 16
0
            void CreateDrawBuffer(int tileCount, int firstTileId)
            {
                int vertsInThisBuffer   = tileCount * NumOfCornersPerQuad;
                int indicesInThisBuffer = tileCount * NumOfVerticesPerQuad;

                var buffer = new CCTileMapVertAndIndexBuffer
                {
                    TileStartIndex    = firstTileId,
                    TileEndIndex      = firstTileId + tileCount - 1,
                    QuadsVertexBuffer = new CCVertexBuffer <CCV3F_C4B_T2F>(vertsInThisBuffer, CCBufferUsage.WriteOnly),
                    IndexBuffer       = new CCIndexBuffer <ushort>(indicesInThisBuffer, BufferUsage.WriteOnly),
                    TileMapLayer      = TileMapLayer,
                    TileSetInfo       = TileSetInfo
                };

                Buffers.Add(buffer);
            }
        public sealed override void CreateBuffer(dynamic obj = null)
        {
            var request      = new SquareRoomBufferRequest();
            var actionBuffer = new ActionBuffer <SquareRoomBufferRequest>(request);

            actionBuffer.BeforeSendBuffer +=
                (sender, args) =>
            {
                actionBuffer.Connections = ClientSingleton.Instance.Users.ToReadonlyList().GetAllConnections();

                var packet = actionBuffer.RequestPacket;
                actionBuffer.CanSend = packet.InsertRooms.Any() ||
                                       packet.RemoveRooms.Any() ||
                                       packet.UpdatedRooms.Any();
            };

            Buffers.Add(actionBuffer);
        }
Exemplo n.º 18
0
        public _2DWorldBatch(GraphicsDevice device, int numBuffers, SurfaceFormat[] surfaceFormats, bool[] alwaysDS, int scrollBuffer)
        {
            this.Device = device;
            this.Effect = WorldContent._2DWorldBatchEffect;
            //TODO: World size
            Sprites = new List <_2DSpriteGroup>();

            ScrollBuffer = scrollBuffer;

            ResetMatrices(device.Viewport.Width, device.Viewport.Height);

            for (var i = 0; i < numBuffers; i++)
            {
                int width  = device.Viewport.Width + scrollBuffer;
                int height = device.Viewport.Height + scrollBuffer;

                switch (i)
                {
                case 4:     //World2D.BUFFER_OBJID
                    width  = 1;
                    height = 1;
                    break;

                case 0:     //World2D.BUFFER_THUMB
                case 10:
                    width  = 1024;
                    height = 1024;
                    break;
                }
                if (numBuffers == 2 && i == 1)
                {
                    width = height = 1024;                            //special case, thumb only.
                }
                Buffers.Add(
                    PPXDepthEngine.CreateRenderTarget(device, 1, 0, surfaceFormats[i], width, height,
                                                      (alwaysDS[i] || (!FSOEnvironment.UseMRT && !FSOEnvironment.SoftwareDepth))?DepthFormat.Depth24Stencil8:DepthFormat.None)
                    );
            }

            ScrollBuffer   = scrollBuffer;
            NumBuffers     = numBuffers;
            SurfaceFormats = surfaceFormats;
            AlwaysDS       = alwaysDS;
        }
Exemplo n.º 19
0
        public _2DWorldBatch(GraphicsDevice device, int numBuffers, SurfaceFormat[] surfaceFormats)
        {
            this.Device = device;
            this.Effect = WorldContent._2DWorldBatchEffect;
            //TODO: World size
            Sprites.Add(_2DBatchRenderMode.NO_DEPTH, new List <_2DSprite>());
            Sprites.Add(_2DBatchRenderMode.RESTORE_DEPTH, new List <_2DSprite>());
            Sprites.Add(_2DBatchRenderMode.WALL, new List <_2DSprite>());
            Sprites.Add(_2DBatchRenderMode.Z_BUFFER, new List <_2DSprite>());

            ResetMatrices(device.Viewport.Width, device.Viewport.Height);

            for (var i = 0; i < numBuffers; i++)
            {
                Buffers.Add(
                    RenderUtils.CreateRenderTarget(device, 1, surfaceFormats[i], (i == 4) ? 1 : device.Viewport.Width, (i == 4) ? 1 : device.Viewport.Height) //buffer 4 (objid) is 1x1
                    );
            }
        }
 public bool defineBufferCapacity(int buffer, int capacity)
 {
     if (buffer > Machines)
     {
         return(false);
     }
     else
     {
         if (Buffers.Any(i => i.Number == buffer))
         {
             Buffers.First(i => i.Number == buffer).Capacity = capacity;
         }
         else
         {
             Buffers.Add(new Buffer(buffer, capacity));
         }
         return(true);
     }
 }
Exemplo n.º 21
0
 //データを書き込み
 public void MakeBuffer(List <T> ioList)
 {
     Buffers.Clear();
     ioList.ForEach(
         x =>
     {
         if (Buffers.ContainsKey(x.SaveKey))
         {
             Debug.LogError(string.Format("Save data Key [{0}] is already exsits. Please use another key.", x.SaveKey));
         }
         else
         {
             Profiler.BeginSample("MakeBuffer : " + x.SaveKey);
             byte[] buffer = BinaryUtil.BinaryWrite(x.OnWrite);
             Buffers.Add(x.SaveKey, buffer);
             Profiler.EndSample();
         }
     }
         );
 }
Exemplo n.º 22
0
        public override void CreateBuffer(dynamic roomId)
        {
            var request = new RoomUserListBufferRequest(roomId);
            var buffer  = new ActionBuffer <RoomUserListBufferRequest>(request);

            buffer.BeforeSendBuffer += (sender, args) =>
            {
                var roomInstance = RoomSingleton.Instance.RoomInstances
                                   .FirstOrDefault(x => x.Id == roomId);

                buffer.Connections = new List <Connection>(roomInstance.TemporaryRoomHelper.GetConnections);

                var packet = buffer.RequestPacket;
                buffer.CanSend = (packet.InsertUsers.Any() ||
                                  packet.RemoveUsers.Any() ||
                                  packet.UpdateUsers.Any());
            };

            Buffers.Add(buffer);
        }
        // On tap, either get related records for the tapped well or find nearby wells if no well was tapped
        private async void mapView1_Tap(object sender, MapViewInputEventArgs e)
        {
            // Show busy UI
            BusyVisibility = Visibility.Visible;

            // Get the map
            if (m_mapView == null)
            {
                m_mapView = (MapView)sender;
            }


            // Create graphic and add to tap points
            var g = new Graphic()
            {
                Geometry = e.Location
            };

            TapPoints.Add(g);

            // Buffer graphic by 100 meters, create graphic with buffer, add to buffers
            var buffer = GeometryEngine.Buffer(g.Geometry, 100);

            Buffers.Add(new Graphic()
            {
                Geometry = buffer
            });

            // Find intersecting parcels and show them on the map
            var result = await doQuery(buffer);

            if (result != null && result.FeatureSet != null && result.FeatureSet.Features.Count > 0)
            {
                // Instead of adding parcels one-by-one, update the Parcels collection all at once to
                // allow the map to render the new features in one rendering pass.
                Parcels = new ObservableCollection <Graphic>(Parcels.Union(result.FeatureSet.Features));
            }

            // Hide busy UI
            BusyVisibility = Visibility.Collapsed;
        }
Exemplo n.º 24
0
        private bool CreateBuffer()
        {
            lock (lockObj) {
                if (MaximumBufferSize > 0 && Buffers.Count + 1 * BufferSize > MaximumBufferSize)
                {
                    return(false);
                }

                Buffers.Add(new byte[BufferSize]);

                int         index = Buffers.Count - 1;
                Stack <int> pool  = new Stack <int>();

                for (int i = 0; i < BufferSize; i += BufferChunkSize)
                {
                    pool.Push(i);
                }

                Indices.Add(index, pool);
                return(true);
            }
        }
Exemplo n.º 25
0
        public void ResizeBuffer(int width, int height)
        {
            _Width  = width;
            _Height = height;

            var numBuffers = AllBuffers.Count;

            foreach (var buf in AllBuffers)
            {
                buf.Dispose();
            }

            Buffers.Clear();
            AllBuffers.Clear();
            for (var i = 0; i < numBuffers; i++)
            {
                Buffers.Add(
                    PPXDepthEngine.CreateRenderTarget(base.GraphicsDevice, 1, 0, SurfaceFormat.Color,
                                                      Width, Height, DepthFormat.None)
                    );
            }
            AllBuffers = new List <RenderTarget2D>(Buffers);
        }
Exemplo n.º 26
0
        public _2DWorldBatch(GraphicsDevice device, int numBuffers, SurfaceFormat[] surfaceFormats, int scrollBuffer)
        {
            this.Device = device;
            this.Effect = WorldContent._2DWorldBatchEffect;
            //TODO: World size
            Sprites.Add(_2DBatchRenderMode.NO_DEPTH, new List <_2DSprite>());
            Sprites.Add(_2DBatchRenderMode.RESTORE_DEPTH, new List <_2DSprite>());
            Sprites.Add(_2DBatchRenderMode.WALL, new List <_2DSprite>());
            Sprites.Add(_2DBatchRenderMode.Z_BUFFER, new List <_2DSprite>());

            ScrollBuffer = scrollBuffer;

            ResetMatrices(device.Viewport.Width, device.Viewport.Height);

            for (var i = 0; i < numBuffers; i++)
            {
                int width  = device.Viewport.Width + scrollBuffer;
                int height = device.Viewport.Height + scrollBuffer;

                switch (i)
                {
                case 4:     //World2D.BUFFER_OBJID
                    width  = 1;
                    height = 1;
                    break;

                case 0:     //World2D.BUFFER_THUMB
                    width  = 1024;
                    height = 1024;
                    break;
                }
                Buffers.Add(
                    RenderUtils.CreateRenderTarget(device, 1, 0, surfaceFormats[i], width, height)
                    );
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// Takes the intermediate geometry data and performs the calculations
        /// to convert that into glTF buffers, views, and accessors.
        /// </summary>
        /// <param name="geomData"></param>
        /// <param name="name">Unique name for the .bin file that will be produced.</param>
        /// <param name="elementId">Revit element's Element ID that will be used as the batchId value.</param>
        /// <returns></returns>
        public glTFBinaryData AddGeometryMeta(GeometryData geomData, string name, int elementId)
        {
            // add a buffer
            glTFBuffer buffer = new glTFBuffer();

            buffer.uri = name + ".bin";
            Buffers.Add(buffer);
            int bufferIdx = Buffers.Count - 1;

            /**
             * Buffer Data
             **/
            glTFBinaryData bufferData = new glTFBinaryData();

            bufferData.name = buffer.uri;
            foreach (var coord in geomData.vertices)
            {
                float vFloat = Convert.ToSingle(coord);
                bufferData.vertexBuffer.Add(vFloat);
            }
            //foreach (var normal in geomData.normals)
            //{
            //    bufferData.normalBuffer.Add((float)normal);
            //}
            foreach (var index in geomData.faces)
            {
                bufferData.indexBuffer.Add(index);
            }
            foreach (var coord in geomData.vertices)
            {
                bufferData.batchIdBuffer.Add(elementId);
            }

            // Get max and min for vertex data
            float[] vertexMinMax = Util.GetVec3MinMax(bufferData.vertexBuffer);
            // Get max and min for normal data
            //float[] normalMinMax = Util.GetVec3MinMax(bufferData.normalBuffer);
            // Get max and min for index data
            int[] faceMinMax = Util.GetScalarMinMax(bufferData.indexBuffer);
            // Get max and min for batchId data
            float[] batchIdMinMax = Util.GetVec3MinMax(bufferData.batchIdBuffer);

            /**
             * BufferViews
             **/
            // Add a vec3 buffer view
            int            elementsPerVertex = 3;
            int            bytesPerElement   = 4;
            int            bytesPerVertex    = elementsPerVertex * bytesPerElement;
            int            numVec3           = (geomData.vertices.Count) / elementsPerVertex;
            int            sizeOfVec3View    = numVec3 * bytesPerVertex;
            glTFBufferView vec3View          = new glTFBufferView();

            vec3View.buffer     = bufferIdx;
            vec3View.byteOffset = 0;
            vec3View.byteLength = sizeOfVec3View;
            vec3View.target     = Targets.ARRAY_BUFFER;
            BufferViews.Add(vec3View);
            int vec3ViewIdx = BufferViews.Count - 1;

            // Add a normals (vec3) buffer view
            //int elementsPerNormal = 3;
            //int bytesPerNormalElement = 4;
            //int bytesPerNormal = elementsPerNormal * bytesPerNormalElement;
            //int numVec3Normals = (geomData.normals.Count) / elementsPerNormal;
            //int sizeOfVec3ViewNormals = numVec3Normals * bytesPerNormal;
            //glTFBufferView vec3ViewNormals = new glTFBufferView();
            //vec3ViewNormals.buffer = bufferIdx;
            //vec3ViewNormals.byteOffset = vec3View.byteLength;
            //vec3ViewNormals.byteLength = sizeOfVec3ViewNormals;
            //vec3ViewNormals.target = Targets.ELEMENT_ARRAY_BUFFER;
            //BufferViews.Add(vec3ViewNormals);
            //int vec3ViewNormalsIdx = BufferViews.Count - 1;

            // Add a faces / indexes buffer view
            int            elementsPerIndex     = 1;
            int            bytesPerIndexElement = 4;
            int            bytesPerIndex        = elementsPerIndex * bytesPerIndexElement;
            int            numIndexes           = geomData.faces.Count;
            int            sizeOfIndexView      = numIndexes * bytesPerIndex;
            glTFBufferView facesView            = new glTFBufferView();

            facesView.buffer     = bufferIdx;
            facesView.byteOffset = vec3View.byteLength;
            //facesView.byteOffset = vec3ViewNormals.byteOffset + vec3ViewNormals.byteLength;
            facesView.byteLength = sizeOfIndexView;
            facesView.target     = Targets.ELEMENT_ARRAY_BUFFER;
            BufferViews.Add(facesView);
            int facesViewIdx = BufferViews.Count - 1;

            // Add a batchId buffer view
            glTFBufferView batchIdsView = new glTFBufferView();

            batchIdsView.buffer     = bufferIdx;
            batchIdsView.byteOffset = facesView.byteOffset + facesView.byteLength;
            batchIdsView.byteLength = sizeOfVec3View;
            batchIdsView.target     = Targets.ARRAY_BUFFER;
            BufferViews.Add(batchIdsView);
            int batchIdsViewIdx = BufferViews.Count - 1;

            //Buffers[bufferIdx].byteLength = vec3View.byteLength + vec3ViewNormals.byteLength + facesView.byteLength + batchIdsView.byteLength;
            Buffers[bufferIdx].byteLength = vec3View.byteLength + facesView.byteLength + batchIdsView.byteLength;

            /**
             * Accessors
             **/
            // add a position accessor
            glTFAccessor positionAccessor = new glTFAccessor();

            positionAccessor.bufferView    = vec3ViewIdx;
            positionAccessor.byteOffset    = 0;
            positionAccessor.componentType = ComponentType.FLOAT;
            positionAccessor.count         = geomData.vertices.Count / elementsPerVertex;
            positionAccessor.type          = "VEC3";
            positionAccessor.max           = new List <float>()
            {
                vertexMinMax[1], vertexMinMax[3], vertexMinMax[5]
            };
            positionAccessor.min = new List <float>()
            {
                vertexMinMax[0], vertexMinMax[2], vertexMinMax[4]
            };
            positionAccessor.name = "POSITION";
            Accessors.Add(positionAccessor);
            bufferData.vertexAccessorIndex = Accessors.Count - 1;

            //add a normals accessor
            //glTFAccessor normalsAccessor = new glTFAccessor();
            //normalsAccessor.bufferView = vec3ViewNormalsIdx;
            //normalsAccessor.byteOffset = 0;
            //normalsAccessor.componentType = ComponentType.FLOAT;
            //normalsAccessor.count = geomData.normals.Count / elementsPerNormal;
            //normalsAccessor.type = "VEC3";
            //normalsAccessor.max = new List<float>() { normalMinMax[1], normalMinMax[3], normalMinMax[5] };
            //normalsAccessor.min = new List<float>() { normalMinMax[0], normalMinMax[2], normalMinMax[4] };
            //normalsAccessor.name = "NORMALS";
            //Accessors.Add(normalsAccessor);
            //bufferData.normalsAccessorIndex = Accessors.Count - 1;

            // add a face accessor
            glTFAccessor faceAccessor = new glTFAccessor();

            faceAccessor.bufferView    = facesViewIdx;
            faceAccessor.byteOffset    = 0;
            faceAccessor.componentType = ComponentType.UNSIGNED_INT;
            //faceAccessor.count = numIndexes;
            faceAccessor.count = geomData.faces.Count / elementsPerIndex;
            faceAccessor.type  = "SCALAR";
            faceAccessor.max   = new List <float>()
            {
                faceMinMax[1]
            };
            faceAccessor.min = new List <float>()
            {
                faceMinMax[0]
            };
            faceAccessor.name = "FACE";
            Accessors.Add(faceAccessor);
            bufferData.indexAccessorIndex = Accessors.Count - 1;

            // add a batchId accessor
            glTFAccessor batchIdAccessor = new glTFAccessor();

            batchIdAccessor.bufferView    = batchIdsViewIdx;
            batchIdAccessor.byteOffset    = 0;
            batchIdAccessor.componentType = ComponentType.FLOAT;
            //batchIdAccessor.count = numIndexes;
            batchIdAccessor.count = geomData.vertices.Count / elementsPerVertex;
            batchIdAccessor.type  = "VEC3";
            //batchIdAccessor.max = new List<float>() { batchIdMinMax[1] };
            //batchIdAccessor.min = new List<float>() { batchIdMinMax[0] };
            batchIdAccessor.max = new List <float>()
            {
                batchIdMinMax[1], batchIdMinMax[3], batchIdMinMax[5]
            };
            batchIdAccessor.min = new List <float>()
            {
                batchIdMinMax[0], batchIdMinMax[2], batchIdMinMax[4]
            };
            batchIdAccessor.name = "BATCH_ID";
            Accessors.Add(batchIdAccessor);
            bufferData.batchIdAccessorIndex = Accessors.Count - 1;

            return(bufferData);
        }
Exemplo n.º 28
0
#pragma warning disable SA1313 // Variable names must begin with lower-case letter
        private Buffers BeamSearch(Buffers flip, Buffers flop, int T, int A, float[] ylog)
#pragma warning restore SA1313 // Variable names must begin with lower-case letter
        {
            // create array that contains classes indexes
            // and then sort both probabilities and indexes
            int[] cls = new int[ylog.Length];
            for (int t = 0, off = 0; t < T; t++, off += A)
            {
                for (int i = 0; i < A; i++)
                {
                    cls[off + i] = i;
                }

                Vectors.Sort(A, ylog, off, cls, off, false);
            }

            // initialize first buffer
            int[] initial = new int[1];
            for (int i = 0; i < A && i < 3; i++)
            {
                int   idx  = cls[i];
                float prob = ylog[i];

                if (idx == this.BlankLabelIndex)
                {
                    flop.Add(initial, 0, Buffer.InitialHash, prob, float.NegativeInfinity, null);
                }
                else if (idx != this.spaceLabelIndex)
                {
                    // do not start with spaces
                    initial[0] = idx;
                    flop.Add(initial, 1, Buffer.HashCode(Buffer.InitialHash, idx), float.NegativeInfinity, prob, null);
                }
            }

            // flip between buffers
            for (int t = 1, off = A; t < T; t++, off += A)
            {
                Swapping.Swap(ref flip, ref flop);

                for (Buffer buffer = flip.Head; buffer != null; buffer = buffer.Next)
                {
                    int[] values = buffer.Classes;
                    int   length = buffer.Length;

                    int lastIdx = length > 0 ? values[length - 1] : CTCBeamSearch.NoClass;

                    float probBlank   = float.NegativeInfinity;
                    float probNoBlank = float.NegativeInfinity;

                    for (int i = 0; i < A && i < 3; i++)
                    {
                        int   idx  = cls[off + i];
                        float prob = ylog[off + i];

                        if (idx == this.BlankLabelIndex)
                        {
                            // get probability of blank character
                            probBlank = buffer.Prob + prob;
                        }
                        else
                        {
                            if (idx == lastIdx)
                            {
                                // get probability of duplicated last character
                                if (!float.IsNegativeInfinity(buffer.ProbNoBlank))
                                {
                                    probNoBlank = buffer.ProbNoBlank + prob;
                                }

                                // when there are two consecutive same characters -
                                // append only there is a blank between them
                                if (float.IsNegativeInfinity(buffer.ProbBlank))
                                {
                                    continue;
                                }

                                // do not repeat blanks
                                if (idx == this.spaceLabelIndex)
                                {
                                    continue;
                                }

                                // same character - append to blank path only
                                prob += buffer.ProbBlank;
                            }
                            else
                            {
                                // different character - append to both blank and noblank paths
                                prob += buffer.Prob;
                            }

                            values[length] = idx;
                            flop.Add(values, length + 1, Buffer.HashCode(buffer.Hash, idx), float.NegativeInfinity, prob, null);
                        }
                    }

                    // repeat buffer with blank and duplicated characters
                    if (!float.IsNegativeInfinity(probBlank) || !float.IsNegativeInfinity(probNoBlank))
                    {
                        flop.Add(values, length, buffer.Hash, probBlank, probNoBlank, null);
                    }
                }

                flip.Free();
            }

            return(flop);
        }
Exemplo n.º 29
0
#pragma warning disable SA1313 // Variable names must begin with lower-case letter
        private Buffers BeamSearch(Buffers flip, Buffers flop, int T, int A, float[] ylog, Context context)
#pragma warning restore SA1313 // Variable names must begin with lower-case letter
        {
            State initialState = context.InitialState;

            // add blank
            int[] initial = new int[1];
            flop.Add(initial, 0, Buffer.InitialHash, ylog[this.BlankLabelIndex], float.NegativeInfinity, initialState);

            // add characters from context
            IDictionary <char, State> nextstates = initialState.NextStates();

            if (nextstates != null)
            {
                foreach (State nextstate in nextstates.Values)
                {
                    int   idx  = this.TryGetClass(nextstate.Char);
                    float prob = idx >= 0 ? ylog[idx] : this.missingProb;

                    if (this.UseStatistics)
                    {
                        prob += nextstate.CharProbability;
                    }

                    initial[0] = idx;
                    flop.Add(initial, 1, Buffer.HashCode(Buffer.InitialHash, idx), float.NegativeInfinity, prob, nextstate);
                }
            }

            // flip between buffers
            for (int t = 1, off = A; t < T; t++, off += A)
            {
                Swapping.Swap(ref flip, ref flop);

                for (Buffer buffer = flip.Head; buffer != null; buffer = buffer.Next)
                {
                    int[] values = buffer.Classes;
                    int   length = buffer.Length;
                    State state  = buffer.State;

                    int lastIdx = length > 0 ? values[length - 1] : CTCBeamSearch.NoClass;

                    // repeat buffer with added blank and duplicated last character
                    float probBlank = buffer.Prob + ylog[off + this.BlankLabelIndex];

                    // no length check here -
                    // if prob is not neg. infinity it means there is at least one character
                    float probNoBlank = float.NegativeInfinity;
                    if (!float.IsNegativeInfinity(buffer.ProbNoBlank))
                    {
                        probNoBlank = buffer.ProbNoBlank + (lastIdx >= 0 ? ylog[off + lastIdx] : this.missingProb);
                    }

                    flop.Add(values, length, buffer.Hash, probBlank, probNoBlank, state);

                    // add context characters
                    nextstates = state.NextStates();
                    if (nextstates != null)
                    {
                        foreach (State nextstate in nextstates.Values)
                        {
                            int   idx  = this.TryGetClass(nextstate.Char);
                            float prob = idx >= 0 ? ylog[off + idx] : this.missingProb;

                            if (idx == lastIdx)
                            {
                                // when there are two consecutive same characters -
                                // append only there is a blank between them
                                if (float.IsNegativeInfinity(buffer.ProbBlank))
                                {
                                    continue;
                                }

                                // same character - append to blank path only
                                prob += buffer.ProbBlank;
                            }
                            else
                            {
                                // different character - append to both blank and noblank paths
                                prob += buffer.Prob;
                            }

                            if (this.UseStatistics)
                            {
                                prob += nextstate.CharProbability;
                            }

                            values[length] = idx;
                            flop.Add(values, length + 1, Buffer.HashCode(buffer.Hash, idx), float.NegativeInfinity, prob, nextstate);
                        }
                    }
                }

                flip.Free();
            }

            return(flop);
        }
Exemplo n.º 30
0
		public void Create(CommandBuffer commandBuffer) {
			var surfaceCapabilities = PhysicalDevice.GetSurfaceCapabilitiesKHR(Surface);
			Extent2D swapChainExtend = new Extent2D {
				Width = surfaceCapabilities.CurrentExtent.Width,
				Height = surfaceCapabilities.CurrentExtent.Height
			};

			var presentModes = PhysicalDevice.GetSurfacePresentModesKHR(Surface);
			PresentModeKhr presentMode = GetBestPresentMode(presentModes);

			var desiredImages = surfaceCapabilities.MinImageCount + 1;
			if (surfaceCapabilities.MaxImageCount > 0 && desiredImages > surfaceCapabilities.MaxImageCount) {
				desiredImages = surfaceCapabilities.MaxImageCount;
			}

			var preTransform = surfaceCapabilities.CurrentTransform;
			if (surfaceCapabilities.SupportedTransforms.HasFlag(SurfaceTransformFlagsKhr.Identity)) {
				preTransform = SurfaceTransformFlagsKhr.Identity;
			}

			var oldSwapChain = Swapchain;
			var swapChainCreateInfo = new SwapchainCreateInfoKhr {
				Surface = Surface,
				MinImageCount = desiredImages,
				ImageFormat = ColorFormat,
				ImageColorSpace = ColorSpace,
				ImageExtent = swapChainExtend,
				ImageUsage = ImageUsageFlags.ColorAttachment,
				PreTransform = preTransform,
				ImageArrayLayers = 1,
				ImageSharingMode = SharingMode.Exclusive,
				QueueFamilyIndexCount = 0,
				QueueFamilyIndices = null,
				PresentMode = presentMode,
				Clipped = true,

				// Alpha on the window surface should be opaque:
				// If it was not we could create transparent regions of our window which
				// would require support from the Window compositor. You can totally do
				// that if you wanted though ;)
				CompositeAlpha = CompositeAlphaFlagsKhr.Opaque
			};
			Swapchain = Device.CreateSwapchainKHR(swapChainCreateInfo);

			if (oldSwapChain != null) {
				Device.DestroySwapchainKHR(oldSwapChain);
			}

			Images = Device.GetSwapchainImagesKHR(Swapchain).ToList();

			// Create the image views for the swap chain. They will all be single
			// layer, 2D images, with no mipmaps.
			// Check the VkImageViewCreateInfo structure to see other views you
			// can potentially create.
			for (var i = 0; i < Images.Count; i++) {
				var buffer = new SwapChainBuffer();

				var colorAttachmentView = new ImageViewCreateInfo {
					Format = ColorFormat,
					Components = new ComponentMapping {
						R = ComponentSwizzle.R,
						G = ComponentSwizzle.G,
						B = ComponentSwizzle.B,
						A = ComponentSwizzle.A
					},
					SubresourceRange = new ImageSubresourceRange {
						AspectMask = ImageAspectFlags.Color,
						BaseMipLevel = 0,
						LevelCount = 1,
						BaseArrayLayer = 0,
						LayerCount = 1
					},
					ViewType = ImageViewType.View2D
				};
				buffer.Image = Images[i];
				SetImageLayout(commandBuffer, buffer.Image, ImageAspectFlags.Color, ImageLayout.Undefined, ImageLayout.PresentSrcKhr);
				buffer.View = Device.CreateImageView(colorAttachmentView);
				Buffers.Add(buffer);
			}
		}