Exemplo n.º 1
0
        internal static void GetAllFramesSince(AnimationResourceSection section, int timeSinceStart, int duration, int millisecondsPerFrame,
            out int startIndex, out int count)
        {
            startIndex = -1;
            count = 0;

            int startFrame = timeSinceStart / millisecondsPerFrame;
            int stopFrame = (timeSinceStart + duration) / millisecondsPerFrame;
            for (int i = 0; i < section.Lines.Count; i++)
            {
                // is this frame inside the time range we're looking for?
                if (section.Lines[i].FrameNum >= startFrame && section.Lines[i].FrameNum <= stopFrame)
                {
                    // is this the first frame?
                    if (startIndex < 0)
                    {
                        startIndex = i;
                    }
                    
                    count++;
                }
                else if (startIndex >= 0)
                {
                    // we've already found the first frame, and now we've
                    // gone past the range of frames, so we're done!
                    return;
                }
            }
        }
Exemplo n.º 2
0
        public MomResource(string name, System.IO.Stream stream, Resource.ResourceManager content)
            : base(name, stream)
        {
            if (content == null)
            {
                throw new ArgumentNullException("content");
            }

            _content = content;

            foreach (AnimationResourceSection section in Sections)
            {
                if (section.SectionName.Equals("ACTIONS", StringComparison.OrdinalIgnoreCase))
                {
                    _actionSection = section;
                }
                else if (section.SectionName.Equals("MVISIBILITY", StringComparison.OrdinalIgnoreCase))
                {
                    _modelVisibilitySection = section;
                }
                else if (section.SectionName.Equals("MTEXTURES", StringComparison.OrdinalIgnoreCase))
                {
                    _modelTexturesSection = section;
                }
                else if (section.SectionName.Equals("SOUNDS", StringComparison.OrdinalIgnoreCase))
                {
                    _soundSection = section;

                    // preload the sounds
                    foreach (AnimationResourceSectionLine line in section.Lines)
                    {
                        string soundName = line.Params[0].StringValue;
                        Sound.AudioEngine.SoundEffect sound = content.Load <Sound.AudioEngine.SoundEffect>(soundName);
                        _sounds.Add(sound);
                    }
                }
                else if (section.SectionName.Equals("GK3", StringComparison.OrdinalIgnoreCase))
                {
                    _gk3Section = section;
                }
            }
        }
Exemplo n.º 3
0
        public YakResource(string name, System.IO.Stream stream, Resource.ResourceManager content)
            : base(name, stream)
        {
            foreach (AnimationResourceSection section in Sections)
            {
                if (section.SectionName.Equals("SOUNDS", StringComparison.OrdinalIgnoreCase))
                {
                    foreach (AnimationResourceSectionLine line in section.Lines)
                    {
                        string soundName = line.Params[0].StringValue;
                        _sounds.Add(content.Load <Sound.AudioEngine.SoundEffect>(soundName, true));
                    }
                }
                else if (section.SectionName.Equals("GK3", StringComparison.OrdinalIgnoreCase))
                {
                    // look for then DIALOGUECUE and SPEAKER
                    for (int i = 0; i < section.Lines.Count; i++)
                    {
                        string param1 = section.Lines[i].Params[0].StringValue;

                        if (param1 != null)
                        {
                            if (param1.Equals("DIALOGUECUE", StringComparison.OrdinalIgnoreCase))
                            {
                                _cueTime = section.Lines[i].FrameNum * MillisecondsPerFrame;
                            }
                            else if (param1.Equals("SPEAKER", StringComparison.OrdinalIgnoreCase))
                            {
                                string speaker = section.Lines[i].Params[1].StringValue;
                                if (speaker.Equals("UNKNOWN", StringComparison.OrdinalIgnoreCase) == false)
                                {
                                    _speaker = speaker;
                                }
                            }
                        }
                    }

                    _gk3Section = section;
                }
            }
        }
Exemplo n.º 4
0
        public const int MillisecondsPerFrame = 67; // about 15 fps

        public AnimationResource(string name, System.IO.Stream stream)
            : base(name, stream)
        {
            _sections = new List<AnimationResourceSection>();

            string[] lines = Text.Split('\n');

            bool readingFileHeaderSection = false;
            bool expectingLineCount = false;
            bool expectingSectionHeader = true;
            int currentSectionLineCount = 0;
            int linesReadInCurrentSection = 0;

            foreach (string line in lines)
            {
                if (expectingSectionHeader)
                {
                    // read the section header
                    if (line.StartsWith("["))
                    {
                        string sectionName = line.Substring(1, line.IndexOf(']') - 1);
                        expectingLineCount = true;
                        expectingSectionHeader = false;

                        // create a new section if this isn't the header
                        if (sectionName.Equals("HEADER", StringComparison.OrdinalIgnoreCase) == false)
                        {
                            AnimationResourceSection section = new AnimationResourceSection();
                            section.SectionName = sectionName;
                            _sections.Add(section);
                            readingFileHeaderSection = false;
                        }
                        else
                        {
                            readingFileHeaderSection = true;
                        }
                    }
                }
                else if (expectingLineCount)
                {
                    if (int.TryParse(line, out currentSectionLineCount))
                    {
                        if (currentSectionLineCount == 0)
                        {
                            expectingLineCount = false;
                            expectingSectionHeader = true;
                        }
                        else
                        {
                            expectingLineCount = false;
                            linesReadInCurrentSection = 0;
                        }
                        
                        // was this the header?
                        if (readingFileHeaderSection)
                        {
                            _numFrames = currentSectionLineCount;
                            expectingSectionHeader = true;
                        }
                    }
                }
                else
                {
                    // very first thing on each line should be an integer, so try that first
                    int frame;
                    if (Utils.TryParseInt(line, 0, line.IndexOf(','), out frame))
                    {
                        // yay! this must be a valid line!
                        AnimationResourceSectionLine sectionLine = new AnimationResourceSectionLine();
                        sectionLine.FrameNum = frame;

                        linesReadInCurrentSection++;

                        int nextComma = line.IndexOf(',');
                        while (nextComma > 0)
                        {
                            AnimationResourceSectionLineParam param = new AnimationResourceSectionLineParam();

                            int prevComma = nextComma;
                            nextComma = line.IndexOf(',', nextComma + 1);

                            string svalue;
                            if (nextComma < 0)
                                svalue = line.Substring(prevComma + 1).Trim();
                            else
                                svalue = line.Substring(prevComma + 1, nextComma - prevComma - 1);

                            int ivalue;
                            float fvalue;
                            if (int.TryParse(svalue, out ivalue))
                            {
                                param.IntValue = ivalue;
                            }
                            else if (float.TryParse(svalue, out fvalue))
                            {
                                param.FloatValue = fvalue;
                            }
                            else
                            {
                                param.StringValue = svalue;
                            }

                            // add the parameter to the line
                            sectionLine.Params.Add(param);
                        }

                        // now add the line to the section
                        _sections[_sections.Count - 1].Lines.Add(sectionLine);

                        if (linesReadInCurrentSection >= currentSectionLineCount)
                        {
                            // all lines were read, so we're ready for another section
                            expectingSectionHeader = true;

                            // sort the lines by frame # for easier usage later
                            _sections[_sections.Count - 1].Lines.Sort(LineComparer.Instance);
                        }
                    }
                }
            }
        }