Esempio n. 1
0
        /// <summary>Registeres a texture and returns a handle to the texture.</summary>
        /// <param name="path">The path to the texture.</param>
        /// <param name="parameters">The parameters that specify how to process the texture.</param>
        /// <param name="handle">Receives a handle to the texture.</param>
        /// <returns>Whether registering the texture was successful.</returns>
        internal static bool RegisterTexture(string path, OpenBveApi.Textures.TextureParameters parameters, out Texture handle)
        {
            /*
             * Check if the texture is already registered.
             * If so, return the existing handle.
             * */
            for (int i = 0; i < RegisteredTexturesCount; i++)
            {
                PathOrigin source = RegisteredTextures[i].Origin as PathOrigin;
                if (source != null && source.Path == path && source.Parameters == parameters)
                {
                    handle = RegisteredTextures[i];
                    return(true);
                }
            }

            /*
             * Register the texture and return the newly created handle.
             * */
            if (RegisteredTextures.Length == RegisteredTexturesCount)
            {
                Array.Resize <Texture>(ref RegisteredTextures, RegisteredTextures.Length << 1);
            }
            RegisteredTextures[RegisteredTexturesCount] = new Texture(path, parameters);
            RegisteredTexturesCount++;
            handle = RegisteredTextures[RegisteredTexturesCount - 1];
            return(true);
        }
Esempio n. 2
0
        private static bool TryEnsureFullPath(IEnumerable <string> paths, PathOrigin kind, out ImmutableArray <PathInfo> fullPaths)
        {
            ImmutableArray <PathInfo> .Builder builder = ImmutableArray.CreateBuilder <PathInfo>();

            foreach (string path in paths)
            {
                if (!ParseHelpers.TryEnsureFullPath(path, out string?fullPath))
                {
                    return(false);
                }

                builder.Add(new PathInfo(fullPath, kind));
            }

            fullPaths = builder.ToImmutableArray();
            return(true);
        }
Esempio n. 3
0
        // --- registering buffers ---

        /// <summary>Registers a sound buffer and returns a handle to the buffer.</summary>
        /// <param name="path">The path to the sound.</param>
        /// <param name="radius">The default effective radius.</param>
        /// <returns>The handle to the sound buffer.</returns>
        internal static SoundBuffer RegisterBuffer(string path, double radius)
        {
            for (int i = 0; i < BufferCount; i++)
            {
                PathOrigin pathOrigin = Buffers[i].Origin as PathOrigin;
                if (pathOrigin != null && pathOrigin.Path == path)
                {
                    return(Buffers[i]);
                }
            }
            if (Buffers.Length == BufferCount)
            {
                Array.Resize <SoundBuffer>(ref Buffers, Buffers.Length << 1);
            }
            Buffers[BufferCount] = new SoundBuffer(path, radius);
            BufferCount++;
            return(Buffers[BufferCount - 1]);
        }
Esempio n. 4
0
        /// <summary>Registeres a texture and returns a handle to the texture.</summary>
        /// <param name="path">The path to the texture.</param>
        /// <param name="parameters">The parameters that specify how to process the texture.</param>
        /// <param name="handle">Receives a handle to the texture.</param>
        /// <returns>Whether registering the texture was successful.</returns>
        public bool RegisterTexture(string path, TextureParameters parameters, out Texture handle)
        {
            /* BUG:
             * Attempt to delete null texture handles from the end of the array
             * These sometimes seem to end up there
             *
             * Have also seen a registered textures count of 72 and an array length of 64
             * Is it possible for a texture to fail to register, but still increment the registered textures count?
             *
             * There appears to be a timing issue somewhere whilst loading, as this only happens intermittantly
             */
            if (RegisteredTexturesCount > RegisteredTextures.Length)
            {
                /* BUG:
                 * The registered textures count very occasional becomes greater than the array length (Texture loader crashses possibly?)
                 * This then crashes when we attempt to itinerate the array, so reset it...
                 */
                RegisteredTexturesCount = RegisteredTextures.Length;
            }

            if (RegisteredTexturesCount != 0)
            {
                try
                {
                    for (int i = RegisteredTexturesCount - 1; i > 0; i--)
                    {
                        if (RegisteredTextures[i] != null)
                        {
                            break;
                        }

                        Array.Resize(ref RegisteredTextures, RegisteredTextures.Length - 1);
                    }
                }
                catch
                {
                    // ignored
                }
            }

            /*
             * Check if the texture is already registered.
             * If so, return the existing handle.
             * */
            for (int i = 0; i < RegisteredTexturesCount; i++)
            {
                if (RegisteredTextures[i] != null)
                {
                    try
                    {
                        //The only exceptions thrown were these when it barfed
                        PathOrigin source = RegisteredTextures[i].Origin as PathOrigin;

                        if (source != null && source.Path == path && source.Parameters == parameters)
                        {
                            handle = RegisteredTextures[i];
                            return(true);
                        }
                    }
                    catch
                    {
                        // ignored
                    }
                }
            }

            /*
             * Register the texture and return the newly created handle.
             * */
            int idx = GetNextFreeTexture();

            RegisteredTextures[idx] = new Texture(path, parameters, currentHost);
            RegisteredTexturesCount++;
            handle = RegisteredTextures[idx];
            return(true);
        }
Esempio n. 5
0
 public PathInfo(string path, PathOrigin origin)
 {
     Path   = path;
     Origin = origin;
 }