Exemplo n.º 1
0
 private void LoadModel()
 {
     try
     {
         var carfile = new VehicleFile(GameVars.BasePath + "cars\\" + _info.FileName);
         _model = new VehicleModel(carfile, true);
     }
     catch (Exception ex)
     {
         _loadException = "Error: " + ex.Message;
     }
 }
Exemplo n.º 2
0
        public Vehicle(string filename, IDriver driver)
        {
            Driver         = driver;
            Driver.Vehicle = this;

            Config = new VehicleFile(filename);

            if (driver is PlayerDriver)
            {
                if (Config.WindscreenMaterial != "none")
                {
                    Config.Funks.Add(new WindscreenFunk(Config.WindscreenMaterial, this));
                }
            }

            _model = new VehicleModel(Config, false);

            Audio = new VehicleAudio(this);

            Chassis = new VehicleChassis(this);

            CActor actor2 = _model.GetActor(Path.GetFileNameWithoutExtension(_model.ModelName));

            if (actor2 != null)
            {
                _deformableModel          = (CDeformableModel)actor2.Model;
                _deformableModel._actor   = Chassis.Actor;
                _deformableModel._carFile = Config;
            }

            _crushSection = Config.CrushSections[1];

            CMaterial crashMat = ResourceCache.GetMaterial(Config.CrashMaterialFiles[0]);

            _vehicleBitsEmitter = new ParticleEmitter(new VehicleBitsParticleSystem(crashMat), 3, Vector3.Zero);
            _vehicleBitsEmitter.DumpsPerSecond = 0.7f;

            DamageSmokeEmitter         = new ParticleEmitter(new DamageSmokeParticleSystem(Color.Gray), 5, Vector3.Zero);
            DamageSmokeEmitter.Enabled = false;

            _flames        = new PixmapBillboard(new Vector2(0.7f, 0.25f), "flames.pix");
            SkidMarkBuffer = new SkidMarkBuffer(this, 150);
        }
Exemplo n.º 3
0
        public VehicleModel(VehicleFile file, bool forDisplayOnly)
        {
            Config = file;

            if (file.DrivenWheelRefs.Count == 0 || file.NonDrivenWheelRefs.Count == 0)
            {
                throw new Exception("No wheel refs specified");
            }

            foreach (string pixFileName in file.PixFiles)
            {
                PixFile pixFile = new PixFile(pixFileName);
                ResourceCache.Add(pixFile);
            }

            foreach (string matFileName in file.MaterialFiles)
            {
                MatFile matFile = new MatFile(matFileName);
                ResourceCache.Add(matFile);
            }

            foreach (string matFileName in file.CrashMaterialFiles)
            {
                MatFile matFile = new MatFile(matFileName);
                ResourceCache.Add(matFile);
            }

            ResourceCache.ResolveMaterials();

            _grooves = new List <BaseGroove>();
            foreach (BaseGroove g in file.Grooves)
            {
                if (!g.IsWheelActor)
                {
                    _grooves.Add(g);
                }
            }

            ActFile actFile = new ActFile(file.ActorFile);

            _actors = actFile.Hierarchy;
            DatFile modelFile = new DatFile(_actors.Root.ModelName, !forDisplayOnly);

            ModelName = _actors.Root.ModelName;

            _actors.AttachModels(modelFile.Models);
            _actors.ResolveTransforms(!forDisplayOnly, _grooves);

            foreach (BaseGroove g in _grooves)
            {
                g.SetActor(_actors.GetByName(g.ActorName));
            }

            // link the funks and materials
            foreach (BaseFunk f in file.Funks)
            {
                f.Resolve();
            }

            Vector3 tireWidth = new Vector3(0.034f, 0, 0) * GameVars.Scale;

            foreach (int id in file.DrivenWheelRefs)
            {
                BaseGroove g = file.Grooves.Find(a => a.Id == id);
                if (g == null)
                {
                    continue;
                }
                CActor      actor = _actors.GetByName(g.ActorName);
                CWheelActor ca    = new CWheelActor(actor, true, false);
                ca.Position = actor.Matrix.Translation + (ca.IsLeft ? -1 * tireWidth : tireWidth);
                file.WheelActors.Add(ca);
            }
            foreach (int id in file.NonDrivenWheelRefs)
            {
                BaseGroove g     = file.Grooves.Find(a => a.Id == id);
                CActor     actor = _actors.GetByName(g.ActorName);
                if (actor == null)
                {
                    continue;                 //BUSTER.TXT does some weird shit for cockpit view of the front wheels
                }
                CWheelActor ca = new CWheelActor(actor, false, true);
                ca.Position = actor.Matrix.Translation + (ca.IsLeft ? -1 * tireWidth : tireWidth);
                file.WheelActors.Add(ca);
            }

            if (forDisplayOnly)
            {
                _actors.RenderWheelsSeparately = false;
            }
        }
Exemplo n.º 4
0
        ///////////////////////////////////////////////////
        // Member Functions
        ///////////////////////////////////////////////////
        /// <summary>
        /// Loads all game assets
        /// </summary>
        public bool load(CfgInfo zoneConf, string configFilename)
        {
            _singleton = this;

            _assetList = new List <AssetInfo>();

            //Add the game config
            addAssetData(AssetFileFactory.CreateFromFile <AssetFile>(configFilename));

            //Load shit up
            ItemFile    itms = AssetFileFactory.CreateFromFile <ItemFile>(zoneConf.level.itmFile);
            LioFile     lios = AssetFileFactory.CreateFromFile <LioFile>(zoneConf.level.lioFile);
            SkillFile   rpgs = AssetFileFactory.CreateFromFile <SkillFile>(zoneConf.level.rpgFile);
            VehicleFile vehs = AssetFileFactory.CreateFromFile <VehicleFile>(zoneConf.level.vehFile);
            LevelFile   lvl  = AssetFileFactory.CreateFromFile <LevelFile>(zoneConf.level.lvlFile);

            if (itms == null || lios == null || rpgs == null || vehs == null || lvl == null)
            {                   //Missing a core file
                foreach (string missing in AssetFileFactory._missingFiles)
                {
                    Log.write(TLog.Error, "Missing file: {0}", missing);
                }
                return(false);
            }

            Level = lvl.Data;

            //Save checksums to send to clients
            addAssetData(itms);
            addAssetData(lios);
            addAssetData(rpgs);
            addAssetData(vehs);
            addAssetData(lvl);

            //Make item maps
            _idToItem   = new SortedDictionary <int, ItemInfo>();
            _nameToItem = new SortedDictionary <string, ItemInfo>();
            foreach (ItemInfo it in itms.Data)
            {
                _idToItem.Add(it.id, it);
            }
            foreach (ItemInfo it in itms.Data)
            {
                if (!_nameToItem.ContainsKey(it.name.ToLower()))
                {
                    _nameToItem.Add(it.name.ToLower(), it);
                }
            }

            //Make skill maps
            _idToSkill   = new SortedDictionary <int, SkillInfo>();
            _nameToSkill = new SortedDictionary <string, SkillInfo>();
            foreach (SkillInfo it in rpgs.Data)
            {
                _idToSkill.Add(it.SkillId, it);
            }
            foreach (SkillInfo it in rpgs.Data)
            {
                if (!_nameToSkill.ContainsKey(it.Name.ToLower()))
                {
                    _nameToSkill.Add(it.Name.ToLower(), it);
                }
            }

            //Make lio map
            _idToLio = new SortedDictionary <int, LioInfo>();
            foreach (LioInfo it in lios.Data)
            {
                _idToLio.Add(it.GeneralData.Id, it);
            }

            //Load blo files
            _bloList = new List <string>();

            foreach (string file in ItemInfo.BlobsToLoad)
            {
                loadBloFile(file + ".blo");
            }
            foreach (string file in CfgInfo.BlobsToLoad)
            {
                loadBloFile(file + ".blo");
            }
            foreach (string file in LioInfo.BlobsToLoad)
            {
                loadBloFile(file + ".blo");
            }
            foreach (string file in SkillInfo.BlobsToLoad)
            {
                loadBloFile(file + ".blo");
            }
            foreach (LvlInfo.BlobReference blob in Level.ObjectBlobs)
            {
                loadBloFile(blob.FileName);
            }
            foreach (LvlInfo.BlobReference blob in Level.FloorBlobs)
            {
                loadBloFile(blob.FileName);
            }

            //Make vehicle map
            _idToVehicle = new SortedDictionary <int, VehInfo>();
            foreach (VehInfo it in vehs.Data)
            {
                _idToVehicle.Add(it.Id, it);
                foreach (string blo in it.blofiles)
                {
                    loadBloFile(blo + ".blo");
                }
            }
            foreach (string blo in _bloList)
            {                   //Attempt to load it
                BloFile blof = AssetFileFactory.LoadBlobFromFile <BloFile>(blo);
                if (blof != null)
                {
                    addAssetData(blof);
                }
            }

            //For debugging
            _bloList.Sort();
            _bloListFileName = "bloList_" + configFilename + ".txt";
            System.IO.File.WriteAllLines(string.Format("{0}/{1}", Environment.CurrentDirectory, _bloListFileName), _bloList);

            //Update our asset server
            sendDataToDirectory();

            //Initialize our lio data
            Lios = new Lio(this);

            //Load news file
            AssetFile nws = AssetFileFactory.CreateFromFile <AssetFile>(zoneConf.level.nwsFile);

            if (nws != null)
            {
                addAssetData(nws);
            }

            //Load the helpMenu files
            for (int i = 0; i <= zoneConf.helpMenu.links.Count - 1; i++)
            {
                AssetFile helpMenu = AssetFileFactory.CreateFromFile <AssetFile>(zoneConf.helpMenu.links[i].name);
                if (helpMenu != null)
                {
                    addAssetData(helpMenu);
                }
            }

            //Load everything else
            loadAdditionalAssets();

            //Are we missing files?
            if (AssetFileFactory.IsIncomplete)
            {                   //Missing a core file
                foreach (string missing in AssetFileFactory._missingFiles)
                {
                    Log.write(TLog.Error, "Missing file: {0}", missing);
                }
                return(false);
            }

            //Cache all our assets
            AssetCache = new Cache(this);
            AssetCache.prepareCache(_assetList);
            return(true);
        }
Exemplo n.º 5
0
        public VehicleChassis(Vehicle vehicle)
        {
            Vehicle = vehicle;

            Wheels = new List <VehicleWheel>();

            VehicleFile carFile = vehicle.Config;

            ActorDescription actorDesc = new ActorDescription();

            actorDesc.BodyDescription      = new BodyDescription();
            actorDesc.BodyDescription.Mass = carFile.Mass;
            var boxDesc = new BoxShapeDescription();

            boxDesc.Size          = carFile.BoundingBox.GetSize();
            boxDesc.LocalPosition = carFile.BoundingBox.GetCenter();
            boxDesc.Name          = PhysXConsts.VehicleBody;
            boxDesc.Flags        |= ShapeFlag.PointContactForce;
            actorDesc.Shapes.Add(boxDesc);

            foreach (Vector3 extraPoint in carFile.ExtraBoundingBoxPoints)
            {
                var extraDesc = new SphereShapeDescription(0.2f);
                extraDesc.LocalPosition = extraPoint;
                extraDesc.Mass          = 0;
                actorDesc.Shapes.Add(extraDesc);
            }

            using (UtilitiesLibrary lib = new UtilitiesLibrary())
            {
                Vector3 size          = carFile.Size;
                Vector3 inertiaTensor = lib.ComputeBoxInteriaTensor(Vector3.Zero, carFile.Mass, size);
                //actorDesc.BodyDescription.MassSpaceInertia = inertiaTensor;
            }


            TireFunctionDescription lngTFD = new TireFunctionDescription();

            lngTFD.ExtremumSlip   = 0.1f;
            lngTFD.ExtremumValue  = 4f;
            lngTFD.AsymptoteSlip  = 2.0f;
            lngTFD.AsymptoteValue = 3.2f;

            _rearLateralTireFn = new TireFunctionDescription();

            _rearLateralTireFn.ExtremumSlip   = 0.2f;
            _rearLateralTireFn.ExtremumValue  = 2.1f;
            _rearLateralTireFn.AsymptoteSlip  = 0.0013f * carFile.Mass;
            _rearLateralTireFn.AsymptoteValue = 0.02f;

            _frontLateralTireFn = _rearLateralTireFn;
            _frontLateralTireFn.ExtremumValue = 1.9f;

            MaterialDescription md = new MaterialDescription();

            md.Flags = MaterialFlag.DisableFriction;
            Material m = PhysX.Instance.Scene.CreateMaterial(md);

            int wheelIndex = 0;

            foreach (CWheelActor wheel in carFile.WheelActors)
            {
                WheelShapeDescription wheelDesc = new WheelShapeDescription();
                wheelDesc.InverseWheelMass            = 0.08f;
                wheelDesc.LongitudalTireForceFunction = lngTFD;
                wheelDesc.Flags    = WheelShapeFlag.ClampedFriction;
                wheelDesc.Material = m;

                wheelDesc.Radius           = wheel.IsDriven ? carFile.DrivenWheelRadius : carFile.NonDrivenWheelRadius;
                wheelDesc.SuspensionTravel = (wheel.IsFront ? carFile.SuspensionGiveFront : carFile.SuspensionGiveRear) * 18;

                float heightModifier = (wheelDesc.SuspensionTravel + wheelDesc.Radius) / wheelDesc.SuspensionTravel;

                SpringDescription spring = new SpringDescription();
                if (carFile.Mass > 3000)
                {
                    spring.SpringCoefficient = 10.5f * heightModifier * carFile.Mass;
                }
                else
                {
                    spring.SpringCoefficient = 6.5f * heightModifier * Math.Min(1000, carFile.Mass);
                }
                spring.DamperCoefficient = carFile.SuspensionDamping * 6f;

                wheelDesc.Suspension    = spring;
                wheelDesc.LocalPosition = wheel.Position;
                wheelDesc.Name          = (wheelIndex).ToString();
                wheelIndex++;

                wheelDesc.LateralTireForceFunction = wheel.IsFront ? _frontLateralTireFn : _rearLateralTireFn;
                actorDesc.Shapes.Add(wheelDesc);
            }

            _physXActor = PhysX.Instance.Scene.CreateActor(actorDesc);


            _heightOffset = _physXActor.Shapes[0].LocalPosition.Y * -2;
            if (_heightOffset < 0)
            {
                _heightOffset = 0;
            }

            foreach (Shape shape in _physXActor.Shapes)
            {
                shape.LocalPosition += new Vector3(0, _heightOffset, 0);
                if (shape is WheelShape)
                {
                    wheelIndex = int.Parse(shape.Name);
                    Wheels.Add(new VehicleWheel(this, carFile.WheelActors[wheelIndex], (WheelShape)shape, carFile.WheelActors[wheelIndex].IsLeft ? 0.17f : -0.17f)
                    {
                        Index = wheelIndex
                    });
                }
            }

            _physXActor.Group    = PhysXConsts.VehicleId;
            _physXActor.UserData = vehicle;

            _physXActor.WakeUp(60.0f);

            //_physXActor.RaiseBodyFlag(BodyFlag.DisableGravity);

            //set center of mass
            Vector3 massPos = carFile.CenterOfMass;

            massPos.Y = carFile.WheelActors[0].Position.Y - carFile.NonDrivenWheelRadius + _heightOffset + 0.35f;
            _massPos  = massPos;
            _physXActor.SetCenterOfMassOffsetLocalPosition(massPos);

            //a real power curve doesnt work too well :)
            List <float> power  = new List <float>(new float[] { 0.5f, 0.5f, 0.5f, 1f, 1f, 1.0f, 1.0f, 0 });
            List <float> ratios = new List <float>(new float[] { 3.227f, 2.360f, 1.685f, 1.312f, 1.000f, 0.793f });

            BaseGearbox gearbox = BaseGearbox.Create(false, ratios, 0.4f);

            Motor = new Motor(power, carFile.EnginePower, 6f, carFile.TopSpeed, gearbox);
            Motor.Gearbox.CurrentGear = 0;
        }