Example #1
0
        /// <summary>
        /// Loads a config from disk and applies it to the specified object
        /// </summary>
        /// <param name="configName">The XML file containing the config data</param>
        /// <param name="obj">The object that contains the CustomAttribute on one or more fields/properties</param>
        public static void LoadConfig(string configName, ref object obj)
        {
            if (!IOManager.FileExists(configName))
            {
                Logger.Crash(new InvalidFilePathException(configName), true);
                return;
            }

            List <Tuple <string, MemberInfo> > serializedObjs =
                GetPropertiesWithAttribute(obj.GetType(), BindingFlags.Instance | BindingFlags.Public).ToList();
            XmlDocument doc = new XmlDocument();

            doc.Load(IOManager.GetStream(configName));
            foreach (Tuple <string, MemberInfo> serializedObj in serializedObjs)
            {
                XmlNode node = GetObject(doc, serializedObj.Item1 + "." + serializedObj.Item2.Name);
                if (node != null)
                {
                    XmlSerializer xserializer = new XmlSerializer(GetMemberType(serializedObj.Item2));
                    TextReader    tr          = new StringReader(node.InnerXml);
                    XmlReader     xr          = XmlReader.Create(tr);
                    SetValue(serializedObj.Item2, obj, xserializer.Deserialize(xr));
                }
            }
        }
Example #2
0
        public static GameFont LoadFontDirect(string filename, int pixelSize)
        {
            if (IOManager.FileExists(filename))
            {
                return(LoadFontInternal(IOManager.GetStream(filename), pixelSize, out string _));
            }

            Logger.Log(DebugChannel.Log, "Not found File: " + filename, 10);
            Logger.Crash(new InvalidFilePathException(filename), true);
            return(DefaultFilepaths.DefaultFont);
        }
Example #3
0
        /// <summary>
        /// Loads a Assimp Model From File
        /// </summary>
        /// <param name="path">The path to the file</param>
        /// <returns>The loaded AssimpModel</returns>
        private static List <Mesh> LoadModel(string path)
        {
            if (!IOManager.FileExists(path))
            {
                Logger.Crash(new InvalidFolderPathException(path), true);
                return(new List <Mesh> {
                    DefaultFilepaths.DefaultMesh
                });
            }

            return(LoadModel(IOManager.GetStream(path), path, Path.GetExtension(path), path));
        }
Example #4
0
        /// <summary>
        /// Public Constructor
        /// </summary>
        /// <param name="size">The initial size of the pool</param>
        /// <param name="maxSize">The maximum size of the pool</param>
        /// <param name="factory">The factory that is providing the new objects</param>
        public ObjectPool(int size, int maxSize, CreateNew factory)
        {
            if (size > maxSize)
            {
                Logger.Crash(new ObjectPoolException("Object Pool size is bigger than its defined max size."), true);
            }

            if (factory == null)
            {
                Logger.Crash(new ObjectPoolException("No Factory passted to ObjectPool Constructor"), false);
            }


            this.factory = factory;

            maxItems = Math.Min(maxSize, size);
            InitializeSize(size);
        }
Example #5
0
        /// <summary>
        /// Resolves layer id to Layer conversion
        /// </summary>
        /// <param name="layer">the layer index</param>
        /// <returns>The layer associated with the index</returns>
        private static Layer IDToInternalLayer(int layer)
        {
            if (layer >= 0 && layer < _internalLayerStore.Count)
            {
                return(_internalLayerStore[layer].Item1);
            }

            bool rec = _registeredLayers.Count > 0;

            Logger.Crash(new LayerNotFoundException(layer), rec);
            return(_internalLayerStore[_registeredLayers.ElementAt(0).Value].Item1);
        }
Example #6
0
        /// <summary>
        /// Tries to Create a Shader from source
        /// </summary>
        /// <param name="subshaders">Dictionary of ShaderType, Path To File</param>
        /// <param name="program">Resulting Shader Program</param>
        /// <returns>The Success State of the Compilation</returns>
        internal static bool TryCreateFromSource(Dictionary <ShaderType, string> subshaders, out ShaderProgram program)
        {
            bool ret = true;

            program = new ShaderProgram();
            List <int> shaders = new List <int>();

            foreach (KeyValuePair <ShaderType, string> shader in subshaders)
            {
                Logger.Log(DebugChannel.Log | DebugChannel.EngineRendering, "Compiling Shader: " + shader.Key, 5);

                bool r = TryCompileShader(shader.Key, shader.Value, out int id);
                ret &= r;
                if (r)
                {
                    shaders.Add(id);
                }
            }


            for (int i = 0; i < shaders.Count; i++)
            {
                Logger.Log(DebugChannel.Log | DebugChannel.EngineRendering,
                           "Attaching Shader to Program: " + subshaders.ElementAt(i).Key, 6);
                GL.AttachShader(program.prgId, shaders[i]);
            }

            Logger.Log(DebugChannel.Log | DebugChannel.EngineRendering, "Linking Program...", 5);
            GL.LinkProgram(program.prgId);

            GL.GetProgram(program.prgId, GetProgramParameterName.LinkStatus, out int success);
            if (success == 0)
            {
                Logger.Crash(new OpenGLShaderException(GL.GetProgramInfoLog(program.prgId)), true);
                return(false);
            }

            return(ret);
        }
Example #7
0
        /// <summary>
        /// Texture a file from disk
        /// </summary>
        /// <param name="file">The file to load</param>
        /// <returns>The GL Texture</returns>
        public static Texture FileToTexture(string file)
        {
            if (!IOManager.FileExists(file))
            {
                Logger.Crash(new InvalidFilePathException(file), true);
                return(DefaultFilepaths.DefaultTexture);
            }

            Bitmap  bmp = new Bitmap(IOManager.GetStream(file));
            Texture t   = BitmapToTexture(bmp, file);

            bmp.Dispose();
            return(t);
        }
Example #8
0
        /// <summary>
        /// Tries to load the specified file and pass the loaded data through the out parameters
        /// </summary>
        /// <param name="fileStream">Input File Stream</param>
        /// <param name="data">Data that has been loaded</param>
        /// <param name="channel">The channel count of the file</param>
        /// <param name="bits">The bits per sample(or the BitDepth)</param>
        /// <param name="bitRate">The bitrate of the Audio File</param>
        /// <returns></returns>
        public bool TryLoadFile(Stream fileStream, out byte[] data, out int channel, out int bits, out int bitRate)
        {
            if (fileStream == null)
            {
                Logger.Crash(new AudioFileInvalidException("Filestream is null"), true);
                data    = null;
                channel = bits = bitRate = 0;
                return(false);
            }

            using (BinaryReader reader = new BinaryReader(fileStream))
            {
                // RIFF header
                string signature = new string(reader.ReadChars(4));
                if (signature != "RIFF")
                {
                    Logger.Crash(new AudioFileInvalidException("Specified stream is not a wave file."), false);
                }

                /*int riff_chunck_size = */
                reader.ReadInt32();

                string format = new string(reader.ReadChars(4));
                if (format != "WAVE")
                {
                    Logger.Crash(new AudioFileInvalidException("Specified stream is not a wave file."), false);
                }

                // WAVE header
                string formatSignature = new string(reader.ReadChars(4));
                if (formatSignature != "fmt ")
                {
                    Logger.Crash(new AudioFileInvalidException("Specified wave file is not supported."), false);
                }

                /*int format_chunk_size = */
                reader.ReadInt32();
                /*int audio_format = */
                reader.ReadInt16();
                int numChannels = reader.ReadInt16();
                int sampleRate  = reader.ReadInt32();
                /*int byte_rate = */
                reader.ReadInt32();
                /*int block_align = */
                reader.ReadInt16();
                int bitsPerSample = reader.ReadInt16();

                string dataSignature = new string(reader.ReadChars(4));
                if (dataSignature != "data")
                {
                    Logger.Crash(new AudioFileInvalidException("Specified wave file is not supported."), false);
                }

                /*int data_chunk_size = */
                reader.ReadInt32();

                channel = numChannels;
                bits    = bitsPerSample;
                bitRate = sampleRate;
                data    = reader.ReadBytes((int)reader.BaseStream.Length);
                return(true);
            }
        }