Exemple #1
0
 // The brakes are painted with palette color #254. Remember what color that maps to now so we can generate brake on/off textures later
 void CfmFile_TextureGenerated(BitmapEntry entry, byte[] palette, byte[] pixelData)
 {
     if (entry.Id == "rsid")
     {
         _brakeColor = new Color(palette[254 * 3], palette[254 * 3 + 1], palette[254 * 3 + 2]);
     }
 }
Exemple #2
0
        private void ReadEntry(BinaryReader reader, BitmapEntry entry)
        {
            int iCode = reader.ReadInt32();

            entry.Type = (BitmapEntryType)(iCode & 0x7F);

            entry.Length = iCode >> 8;

            int width  = reader.ReadInt16();
            int height = reader.ReadInt16();

            if (entry.Type == BitmapEntryType.TextureTrailer)
            {
                return;
            }

            entry.Misc[0] = reader.ReadInt16();
            entry.Misc[1] = reader.ReadInt16();
            entry.Misc[2] = reader.ReadInt16();
            entry.Misc[3] = reader.ReadInt16();

            switch (entry.Type)
            {
            case BitmapEntryType.DosPalette:
            case BitmapEntryType.Palette:
                _lastPalette = LoadPalette(reader, entry.Type);
                entry.Type   = BitmapEntryType.Palette;
                break;

            case BitmapEntryType.Texture:
                ReadTexture(reader, entry, width, height);
                break;
            }
        }
Exemple #3
0
        private void ReadTexture(BinaryReader reader, BitmapEntry entry, int width, int height)
        {
            byte[] pixelData = reader.ReadBytes(width * height);

            if (EnableTextureAttachments)
            {
                while (entry.Length > 0)
                {
                    var childEntry = new BitmapEntry();
                    ReadEntry(reader, childEntry);
                    if (childEntry.Type == BitmapEntryType.DosPalette || childEntry.Type == BitmapEntryType.Palette)
                    {
                        _palette = _lastPalette;
                    }
                    if (childEntry.Length == 0)
                    {
                        break;
                    }
                }
            }

            if (_palette == null)
            {
                _palette = _lastPalette;
            }
            TextureGenerator tg = new TextureGenerator(_palette);

            entry.Texture = tg.Generate(pixelData, width, height);
            entry.Type    = BitmapEntryType.Texture;
            if (TextureGenerated != null)
            {
                TextureGenerated(entry, _palette, pixelData);
            }
        }
Exemple #4
0
 // The brakes are painted with palette color #254. Remember what color that maps to now so we can generate brake on/off textures later
 void CfmFile_TextureGenerated(BitmapEntry entry, byte[] palette, byte[] pixelData)
 {
     if (entry.Id == "rsid")
     {
         _brakeColor = new Color(palette[254 * 3], palette[254 * 3 + 1], palette[254 * 3 + 2]);
     }
 }
Exemple #5
0
        public HomeScreen()
            : base()
        {
            QfsFile qfs = new QfsFile(@"FRONTEND\ART\control\central.qfs");
            _background = qfs.Content.Header.FindByName("bgnd");
            _vehicleSelection = qfs.Content.Header.FindByName("Tlb1");
            _trackSelection = qfs.Content.Header.FindByName("Brb4");
            _raceButtonSelection = qfs.Content.Header.FindByName("Ra1l");

            foreach (var vehicle in VehicleDescription.Descriptions)
            {
                _vehicles.Add(new VehicleUIControl(vehicle));
            }

            foreach (var track in TrackDescription.Descriptions)
            {
                if (!track.HideFromMenu)
                {
                    _track.Add(new TrackUIControl(track));
                }
            }

            if (GameConfig.SelectedTrackDescription != null)
                _currentTrack = _track.FindIndex(a => a.Descriptor == GameConfig.SelectedTrackDescription);
            if (GameConfig.SelectedVehicle != null)
                _currentVehicle = _vehicles.FindIndex(a => a.Descriptor == GameConfig.SelectedVehicle);

            if (_currentTrack == -1) _currentTrack = 0;
        }
Exemple #6
0
        public Dashboard(DrivableVehicle car, DashboardDescription descriptor)
        {
            _car = car;
            _descriptor = descriptor;
            _car.Motor.Gearbox.GearChangeStarted += new EventHandler(Gearbox_GearChangeStarted);

            _gearBoxAnimation = new GearboxAnimation();

            //_instrumentLine = Engine.Instance.ContentManager.Load<Texture2D>("Content\\SpeedoLine");
            if (_tachLineTexture == null)
            {
                _tachLineTexture = new Texture2D(Engine.Instance.Device, (int)3, 25);
                Color[] pixels = new Color[_tachLineTexture.Width * _tachLineTexture.Height];
                for (int i = 0; i < pixels.Length; i++) pixels[i] = Color.Red;
                _tachLineTexture.SetData<Color>(pixels);
            }

            FshFile fsh = new FshFile(Path.Combine(@"SIMDATA\DASH", descriptor.Filename));
            var bitmaps = fsh.Header;

            Dash = bitmaps.FindByName("dash");
            GearGate = bitmaps.FindByName("gate");
            GearKnob = bitmaps.FindByName("nob1");

            Leather1 = bitmaps.FindByName("lth1");
            Leather2 = bitmaps.FindByName("lth2");
            Leather3 = bitmaps.FindByName("lth3");

            //steering wheel images, from straight to left, then to the right.  Not all cars have all steering angles
            Wstr = bitmaps.FindByName("wstr");
            Wl06 = bitmaps.FindByName("wl06");
            Wl14 = bitmaps.FindByName("wl14");
            Wl22 = bitmaps.FindByName("wl22");
            Wl32 = bitmaps.FindByName("wl32");
            if (Wl32 == null)
                Wl32 = Wl22;
            Wl45 = bitmaps.FindByName("wl45");
            if (Wl45 == null)
                Wl45 = Wl32;
            Wr06 = bitmaps.FindByName("wr06");
            Wr14 = bitmaps.FindByName("wr14");
            Wr22 = bitmaps.FindByName("wr22");
            Wr32 = bitmaps.FindByName("wr32");
            if (Wr32 == null)
                Wr32 = Wr22;
            Wr45 = bitmaps.FindByName("wr45");
            if (Wr45 == null)
                Wr45 = Wr32;
        }
Exemple #7
0
        public override Texture2D GetSceneryTexture(int textureNbr)
        {
            textureNbr /= 4;
            BitmapEntry found = _root.HeaderChunks[SCENERY_CHUNK].BitmapChunks[textureNbr].Bitmaps.Find(a => a.Id == "0000");

            if (found == null)
            {
                Debug.WriteLine("Warning: Scenery texture not found: " + textureNbr);
                return(null);
            }
            else
            {
                return(found.Texture);
            }
        }
Exemple #8
0
        public virtual Texture2D GetSceneryTexture(int textureNbr)
        {
            textureNbr /= 4;
            string      texture = textureNbr.ToString("00") + "00";
            BitmapEntry found   = _root.HeaderChunks[SCENERY_CHUNK].BitmapChunks[0].Bitmaps.Find(a => a.Id == texture);

            if (found == null)
            {
                Debug.WriteLine("Warning: Scenery texture not found: " + textureNbr);
                return(null);
            }
            else
            {
                return(found.Texture);
            }
        }
Exemple #9
0
        public BaseExternalView()
        {
            if (_bottomBar == null)
            {
                var fsh = new FshFile(@"Simdata\Misc\MaskHi.fsh");
                _bottomBar = fsh.Header.Bitmaps.Find(a => a.Id == "b00b");
                _bottomFill = fsh.Header.Bitmaps.Find(a => a.Id == "0002");
                _tacho = fsh.Header.Bitmaps.Find(a => a.Id == "tach");
                _map = fsh.Header.Bitmaps.Find(a => a.Id == "mpbd");

                _tachLineTexture = new Texture2D(Engine.Instance.Device, (int)_needleWidth, 25);
                Color[] pixels = new Color[_tachLineTexture.Width * _tachLineTexture.Height];
                for (int i = 0; i < pixels.Length; i++) pixels[i] = Color.Red;
                _tachLineTexture.SetData<Color>(pixels);
            }
        }
Exemple #10
0
        private static byte[] _lastPalette;          //some files don't have their own palettes, in that case, use the last palette we loaded

        public override void Read(BinaryReader reader)
        {
            base.Read(reader);

            int    itemCount     = reader.ReadInt32();
            string directoryName = new string(reader.ReadChars(4));

            Debug.WriteLine(">> Loading bitmap chunk " + directoryName);

            for (int i = 0; i < itemCount; i++)
            {
                BitmapEntry entry = new BitmapEntry();
                entry.Id     = new string(reader.ReadChars(4));
                entry.Offset = reader.ReadInt32();
                _bitmaps.Add(entry);
            }

            //Load global palette first
            foreach (BitmapEntry entry in _bitmaps)
            {
                if (entry.Id.ToUpper() == "!PAL")
                {
                    reader.BaseStream.Position = Offset + entry.Offset;
                    ReadEntry(reader, entry);
                    _palette = _lastPalette;
                    Debug.WriteLine("\tLoaded global palette");
                    break;
                }
            }

            for (int i = 0; i < _bitmaps.Count; i++)
            {
                BitmapEntry entry = _bitmaps[i];
                if (entry.Type == BitmapEntryType.Unknown)
                {
                    reader.BaseStream.Position = Offset + entry.Offset;
                    ReadEntry(reader, entry);
                    Debug.WriteLine("\tLoaded bitmap " + entry.Id);
                }
            }
        }
Exemple #11
0
        public void ResolveTexture(BitmapEntry bmpEntry)
        {
            if (bmpEntry == null)
            {
                return;
            }

            Texture = bmpEntry.Texture;
            if (_computeUvs)  //don't need to scale our uvs based on the texture size
            {
                return;
            }

            // otherwise, because the uvs are in the range 0,0,tex_width,tex_height we need to scale them to the 0,1 range
            for (int i = 0; i < VertexCount; i++)
            {
                Vector2 coord = TextureUVs[i];
                coord.X      /= bmpEntry.Texture.Width;
                coord.Y      /= bmpEntry.Texture.Height;
                TextureUVs[i] = coord;
            }
        }
Exemple #12
0
        public virtual Texture2D GetGroundTexture(int textureNbr)
        {
            int groupId2  = textureNbr / 3;
            int remainder = textureNbr % 3;

            string id = null;

            if (remainder == 0)
            {
                id = groupId2.ToString("00") + "A0";
            }
            else if (remainder == 1)
            {
                id = groupId2.ToString("00") + "B0";
            }
            else if (remainder == 2)
            {
                id = groupId2.ToString("00") + "C0";
            }
            else
            {
                throw new NotImplementedException();
            }

            BitmapEntry found = _root.HeaderChunks[TERRAIN_CHUNK].BitmapChunks[0].Bitmaps.Find(a => a.Id == id);

            if (found == null)
            {
                Debug.WriteLine("Warning: Ground texture not found: " + textureNbr);
                return(null);
            }
            else
            {
                return(found.Texture);
            }
        }
Exemple #13
0
        public override void Read(BinaryReader reader)
        {
            base.Read(reader);

            int itemCount = reader.ReadInt32();
            string directoryName = new string(reader.ReadChars(4));

            Debug.WriteLine(">> Loading bitmap chunk " + directoryName);

            for (int i = 0; i < itemCount; i++)
            {
                BitmapEntry entry = new BitmapEntry();
                entry.Id = new string(reader.ReadChars(4));
                entry.Offset = reader.ReadInt32();
                _bitmaps.Add(entry);
            }

            //Load global palette first
            foreach (BitmapEntry entry in _bitmaps)
            {
                if (entry.Id.ToUpper() == "!PAL")
                {
                    reader.BaseStream.Position = Offset + entry.Offset;
                    ReadEntry(reader, entry);
                    _palette = _lastPalette;
                    Debug.WriteLine("\tLoaded global palette");
                    break;
                }
            }

            for (int i = 0; i < _bitmaps.Count; i++)
            {
                BitmapEntry entry = _bitmaps[i];
                if (entry.Type == BitmapEntryType.Unknown)
                {
                    reader.BaseStream.Position = Offset + entry.Offset;
                    ReadEntry(reader, entry);
                    Debug.WriteLine("\tLoaded bitmap " + entry.Id);
                }
            }
        }
Exemple #14
0
        private void ReadTexture(BinaryReader reader, BitmapEntry entry, int width, int height)
        {
            byte[] pixelData = reader.ReadBytes(width * height);

            if (EnableTextureAttachments)
            {
                while (entry.Length > 0)
                {
                    var childEntry = new BitmapEntry();
                    ReadEntry(reader, childEntry);
                    if (childEntry.Type == BitmapEntryType.DosPalette || childEntry.Type == BitmapEntryType.Palette)
                    {
                        _palette = _lastPalette;
                    }
                    if (childEntry.Length == 0)
                        break;
                }
            }

            if (_palette == null)
            {
                _palette = _lastPalette;
            }
            TextureGenerator tg = new TextureGenerator(_palette);
            entry.Texture = tg.Generate(pixelData, width, height);
            entry.Type = BitmapEntryType.Texture;
            if (TextureGenerated != null) TextureGenerated(entry, _palette, pixelData);
        }
Exemple #15
0
        private void ReadEntry(BinaryReader reader, BitmapEntry entry)
        {
            int iCode = reader.ReadInt32();

            entry.Type = (BitmapEntryType)(iCode & 0x7F);

            entry.Length = iCode >> 8;

            int width = reader.ReadInt16();
            int height = reader.ReadInt16();

            if (entry.Type == BitmapEntryType.TextureTrailer)
                return;

            entry.Misc[0] = reader.ReadInt16();
            entry.Misc[1] = reader.ReadInt16();
            entry.Misc[2] = reader.ReadInt16();
            entry.Misc[3] = reader.ReadInt16();

            switch (entry.Type)
            {
                case BitmapEntryType.DosPalette:
                case BitmapEntryType.Palette:
                    _lastPalette = LoadPalette(reader, entry.Type);
                    entry.Type = BitmapEntryType.Palette;
                    break;
                case BitmapEntryType.Texture:
                    ReadTexture(reader, entry, width, height);
                    break;
            }
        }
Exemple #16
0
        public void ResolveTexture(BitmapEntry bmpEntry)
        {
            if (bmpEntry == null)
            {
                return;
            }

            Texture = bmpEntry.Texture;
            if (_computeUvs)  //don't need to scale our uvs based on the texture size
                return;

            // otherwise, because the uvs are in the range 0,0,tex_width,tex_height we need to scale them to the 0,1 range
            for (int i =0; i < VertexCount; i++)
            {
                Vector2 coord = TextureUVs[i];
                coord.X /= bmpEntry.Texture.Width;
                coord.Y /= bmpEntry.Texture.Height;
                TextureUVs[i] = coord;
            }
        }