Esempio n. 1
0
        /// <summary>
        /// Load the TRN direct from a binary reader stream.
        /// Stream must be aligned with the beginning of a TRN
        /// </summary>
        /// <param name="reader"></param>
        public void Load(System.IO.BinaryReader reader)
        {
            OEIShared.Utils.FourCC cc = new OEIShared.Utils.FourCC(reader.ReadChars(4));

            if (cc != this._fourCC)
            {
                throw new ApplicationException(this._fourCC.ToString() + " not found in stream");
            }

            this._majorFileVersion = reader.ReadUInt16();
            this._minorFileVersion = reader.ReadUInt16();
            this._numPackets       = reader.ReadInt32();

            PacketPointer[] packetPointers = new PacketPointer[this._numPackets];
            for (int i = 0; i < this._numPackets; i++)
            {
                packetPointers[i].Type    = new OEIShared.Utils.FourCC(reader.ReadChars(4));
                packetPointers[i].Address = reader.ReadInt32();
            }

            int curTRRNIndex = 0;
            int curTRRNX     = 0;
            int curTRRNY     = 0;

            // use the above info to find the TRWH
            foreach (PacketPointer ptr in packetPointers)
            {
                if (ptr.Type == new OEIShared.Utils.FourCC("TRWH"))
                {
                    if (this._TRWH == null)
                    {
                        reader.BaseStream.Position = ptr.Address;
                        this._TRWH  = new TRWH(reader);
                        this._TRRNs = new TRRN[this.Width, this.Height];
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show("Ignoring Additional TRWH");
                    }
                }
                else if (ptr.Type == new OEIShared.Utils.FourCC("TRRN"))
                {
                    if (this._TRWH == null)
                    {
                        throw new ApplicationException("TRRN found but no TRWH. Can't load TRRN.");
                    }
                    else
                    {
                        curTRRNX = curTRRNIndex % Width;
                        curTRRNY = int.Parse(Math.Floor(curTRRNIndex / (double)Width).ToString());
                        curTRRNIndex++;

                        reader.BaseStream.Position      = ptr.Address;
                        this._TRRNs[curTRRNX, curTRRNY] = new TRRN(reader);
                        this._vertices.AddRange(this._TRRNs[curTRRNX, curTRRNY].Vertices);
                        this._ddsGroups.Add(this._TRRNs[curTRRNX, curTRRNY].DDSGroup);
                    }
                }
                else if (ptr.Type == new OEIShared.Utils.FourCC("ASWM"))
                {
                    reader.BaseStream.Position = ptr.Address;
                    this._ASWMs.Add(new ASWM(reader));
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Load the TRN direct from a binary reader stream.
        /// Stream must be aligned with the beginning of a TRN
        /// </summary>
        /// <param name="reader"></param>
        public void Load( System.IO.BinaryReader reader )
        {
            OEIShared.Utils.FourCC cc = new OEIShared.Utils.FourCC( reader.ReadChars( 4 ) );

            if ( cc != this._fourCC )
                throw new ApplicationException( this._fourCC.ToString() + " not found in stream" );

            this._majorFileVersion = reader.ReadUInt16();
            this._minorFileVersion = reader.ReadUInt16();
            this._numPackets = reader.ReadInt32();

            PacketPointer[] packetPointers = new PacketPointer[this._numPackets];
            for ( int i = 0; i < this._numPackets; i++ )
            {
                packetPointers[i].Type = new OEIShared.Utils.FourCC( reader.ReadChars( 4 ) );
                packetPointers[i].Address = reader.ReadInt32();
            }

            int curTRRNIndex = 0;
            int curTRRNX = 0;
            int curTRRNY = 0;
            // use the above info to find the TRWH
            foreach( PacketPointer ptr in packetPointers )
            {
                if ( ptr.Type == new OEIShared.Utils.FourCC( "TRWH" ) )
                {
                    if ( this._TRWH == null )
                    {
                        reader.BaseStream.Position = ptr.Address;
                        this._TRWH = new TRWH( reader );
                        this._TRRNs = new TRRN[ this.Width, this.Height ];
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show( "Ignoring Additional TRWH" );
                    }
                }
                else if ( ptr.Type == new OEIShared.Utils.FourCC( "TRRN" ) )
                {
                    if ( this._TRWH == null )
                        throw new ApplicationException( "TRRN found but no TRWH. Can't load TRRN." );
                    else
                    {
                        curTRRNX = curTRRNIndex % Width;
                        curTRRNY = int.Parse( Math.Floor( curTRRNIndex / (double)Width ).ToString() );
                        curTRRNIndex++;

                        reader.BaseStream.Position = ptr.Address;
                        this._TRRNs[curTRRNX, curTRRNY] = new TRRN( reader );
                        this._vertices.AddRange(this._TRRNs[curTRRNX, curTRRNY].Vertices);
                        this._ddsGroups.Add(this._TRRNs[curTRRNX, curTRRNY].DDSGroup);
                    }
                }
                else if ( ptr.Type == new OEIShared.Utils.FourCC( "ASWM" ) )
                {
                    reader.BaseStream.Position = ptr.Address;
                    this._ASWMs.Add( new ASWM( reader ) );
                }
            }
        }