Exemple #1
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 #2
0
        private void SetCurrent(BitmapEntry value, bool fromCache = false) {
            ++_loading;

            _current = value;
            _broken = value.IsBroken;
            _fromCache = fromCache;

            if (fromCache) {
                if (_broken && Filename != null) {
                    RemoveFromCache(Filename);
                }
            } else if (!_broken) {
                AddToCache(Filename, _current);
            }

            InvalidateMeasure();
            InvalidateVisual();
        }
Exemple #3
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 #4
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;
            }
        }
            public static Entry CreateEntry( string name, object value, string defaultNamespace, string defaultDeclaringClass )
            {
                string stringValue = value as string;
                System.Drawing.Bitmap bitmapValue = value as System.Drawing.Bitmap;
                byte[] rawValue = value as byte[];
                Entry entry = null;

                if(stringValue != null)
                {
                    entry = new StringEntry( name, stringValue );
                }
                else if(bitmapValue != null)
                {
                    entry = new BitmapEntry( name, bitmapValue );
                }
                if(rawValue != null)
                {
                    entry = TinyResourcesEntry.TryCreateTinyResourcesEntry( name, rawValue );

                    if(entry == null)
                    {
                        entry = new BinaryEntry( name, rawValue );
                    }
                }

                if(entry == null)
                {
                    throw new Exception();
                }

                if(entry.Namespace.Length == 0)
                {
                    entry.Namespace = defaultNamespace;
                }

                if(entry.ClassName.Length == 0)
                {
                    ResourceTypeDescription typeDescription = ResourceTypeDescriptionFromResourceType( entry.ResourceType );
                    entry.ClassName = typeDescription.defaultEnum;

                    if(!string.IsNullOrEmpty( defaultDeclaringClass ))
                    {
                        entry.ClassName = string.Format( "{0}+{1}", defaultDeclaringClass, entry.ClassName );
                    }
                }

                return entry;
            }
Exemple #6
0
 private void OnFilenameChanged() {
     ReloadImage();
     if (DelayedCreation && ClearOnChange) {
         _current = new BitmapEntry();
         InvalidateVisual();
     }
 }
Exemple #7
0
        private async void ReloadImageAsync() {
            var loading = ++_loading;
            _broken = false;

            var filename = Filename;

            byte[] data;
            if (string.IsNullOrEmpty(filename)) {
                data = null;
            } else {
                try {
                    data = await ReadAllBytesAsync(filename);
                } catch (Exception) {
                    data = null;
                }
            }

            if (loading != _loading) return;
            if (data == null) {
                _current = new BitmapEntry();
                _broken = true;

                InvalidateMeasure();
                InvalidateVisual();
                return;
            }

            var innerDecodeWidth = InnerDecodeWidth;
            var innerDecodeHeight = InnerDecodeHeight;

            UpdateLoaded();
            if (RecentlyLoaded.Count < 2 || data.Length < 1000) {
                _current = LoadBitmapSourceFromBytes(data, innerDecodeWidth, innerDecodeHeight);
                _broken = _current.BitmapSource == null;
                if (!_broken) {
                    AddToCache(Filename, _current);
                }

                InvalidateMeasure();
                InvalidateVisual();
                return;
            }

            if (RecentlyLoaded.Count > 5) {
                await Task.Delay((RecentlyLoaded.Count - 3) * 10);
                if (loading != _loading) return;
            }

            ThreadPool.QueueUserWorkItem(o => {
                var current = LoadBitmapSourceFromBytes(data, innerDecodeWidth, innerDecodeHeight);
                Dispatcher.BeginInvoke(DispatcherPriority.Render, (Action)(() => {
                    if (loading != _loading) return;

                    _current = current;
                    _broken = _current.BitmapSource == null;
                    if (!_broken) {
                        AddToCache(Filename, _current);
                    }

                    InvalidateMeasure();
                    InvalidateVisual();
                }));
            });
        }
Exemple #8
0
        private async void ReloadImageAsyncOld() {
            var loading = ++_loading;
            _broken = false;

            var current = await LoadBitmapSourceAsync(Filename, InnerDecodeWidth, InnerDecodeHeight);
            if (loading != _loading) return;

            _current = current;
            _broken = _current.BitmapSource == null;
            if (!_broken) {
                AddToCache(Filename, _current);
            }

            InvalidateMeasure();
            InvalidateVisual();
        }
Exemple #9
0
        private void ReloadImage() {
            if (OptionCacheTotalSize != 0) {
                var cached = GetCached(Filename);
                if (cached.BitmapSource != null) {
                    _current = cached;
                    _broken = false;
                    InvalidateMeasure();
                    return;
                }
            }

            if (DelayedCreation) {
                if (OptionBackgroundLoading) {
                    ReloadImageAsync();
                } else {
                    ReloadImageAsyncOld();
                }
            } else {
                ++_loading;
                _current = LoadBitmapSource(Filename, InnerDecodeWidth, InnerDecodeHeight);
                _broken = _current.BitmapSource == null;
                if (!_broken) {
                    AddToCache(Filename, _current);
                }

                InvalidateMeasure();
            }
        }
Exemple #10
0
        private static void AddToCache(string filename, BitmapEntry entry) {
            if (OptionCacheTotalSize == 0 || entry.Size > OptionCacheLimitSize) return;

            lock (Cache) {
                var i = Cache.FindIndex(x => string.Equals(x.Key, filename, StringComparison.OrdinalIgnoreCase));
                CacheEntry item;
                if (i == -1) {
                    item = new CacheEntry {
                        Key = filename,
                        Value = entry
                    };
                    Cache.Insert(0, item);
                } else {
                    item = Cache[i];
                    item.Value = entry;

                    if (i > 0) {
                        Cache.RemoveAt(i);
                        Cache.Insert(0, item);
                    }
                }

                // removing old entries
                var total = item.Value.Size;
                for (i = 1; i < Cache.Count; i++) {
                    total += Cache[i].Value.Size;
                    if (total > OptionCacheTotalSize) {
                        Cache.RemoveRange(i, Cache.Count - i);
                        return;
                    }
                }
            }
        }
Exemple #11
0
 private void ClearCurrent() {
     _current = BitmapEntry.Empty;
     _broken = false;
     InvalidateVisual();
 }
Exemple #12
0
        private void AddToCache(string filename, BitmapEntry entry) {
            _fromCache = false;
            if (OptionCacheTotalEntries <= 0 || OptionCacheTotalSize <= 0 ||
                    entry.Size < OptionCacheMinSize || entry.Size > OptionCacheMaxSize) return;

            var cache = Cache;
            var lastIndex = cache.Count - 1;

            lock (cache) {
                var index = -1;
                for (var i = lastIndex; i >= 0; i--) {
                    if (string.Equals(cache[i].Key, filename, OptionCacheStringComparison)) {
                        index = i;
                        break;
                    }
                }
                
                CacheEntry item;
                if (index == -1) {
                    // item does not exist now, let’s add it
                    item = new CacheEntry {
                        Key = filename,
                        Value = entry
                    };

                    // if queue is full, remove the first entry to avoid re-creating
                    // array thing inside of the list
                    if (cache.Count == OptionCacheTotalEntries) {
                        if (OptionMarkCached) {
                            Logging.Debug($"total cached: {cache.Count} entries (capacity: {cache.Capacity})");
                        }

                        cache.RemoveAt(0);
                    }

                    cache.Add(item);
                } else {
                    // item already exists, let’s update its value
                    item = cache[index];
                    item.Value = entry;

                    if (index < lastIndex) {
                        // and move it to the end of removal queue if needed
                        cache.RemoveAt(index);
                        cache.Add(item);
                    }
                }

                // remove old entries
                var total = item.Value.Size;
                for (var i = lastIndex - 1; i >= 0; i--) {
                    total += cache[i].Value.Size;
                    if (total > OptionCacheTotalSize) {
                        if (OptionMarkCached) {
                            Logging.Debug($"total cached size: {total / 1024d / 1024:F2} MB, let’s remove first {i + 1} image{(i > 0 ? "s" : "")}");
                        }

                        cache.RemoveRange(0, i + 1);
                        return;
                    }
                }

                if (OptionMarkCached) {
                    Logging.Debug($"total cached size: {total / 1024d / 1024:F2} MB, no need to remove anything");
                }
            }
        }
Exemple #13
0
 private void SetBitmapEntryDirectly(BitmapEntry value) {
     Filename = null;
     SetCurrent(value);
 }