// old bool Scene::LoadStartPos(Ogre::String file) { CONFIGFILE param; if (!param.Load(file)) return false; float f3[3], f1; QUATERNION <float> fixer; fixer.Rotate(3.141593, 0,0,1); param.GetParam("start position 0", f3); MATHVECTOR <float, 3> pos(f3[2], f3[0], f3[1]); if (!param.GetParam("start orientation-xyz 0", f3)) return false; if (!param.GetParam("start orientation-w 0", f1)) return false; QUATERNION <float> rot(f3[2], f3[0], f3[1], f1); rot = fixer * rot; startPos = pos; startRot = rot; return true; }
void GAME::LoadSaveOptions(OPTION_ACTION action, std::map<string, string> & options) { if (action == LOAD) //load from the settings class to the options map { CONFIGFILE tempconfig; settings->Serialize(true, tempconfig); std::list <string> paramlistoutput; tempconfig.GetParamList(paramlistoutput); for (std::list <string>::iterator i = paramlistoutput.begin(); i != paramlistoutput.end(); ++i) { string val; tempconfig.GetParam(*i, val); options[*i] = val; //std::cout << "LOAD - PARAM: " << *i << " = " << val << endl; } } else //save from the options map to the settings class { CONFIGFILE tempconfig; for (std::map<string, string>::iterator i = options.begin(); i != options.end(); ++i) { tempconfig.SetParam(i->first, i->second); //std::cout << "SAVE - PARAM: " << i->first << " = " << i->second << endl; } settings->Serialize(false, tempconfig); //account for new settings ProcessNewSettings(); } }
/// Surfaces all in data/cars/surfaces.cfg //------------------------------------------------------------------------------------------------------------------------------ bool App::LoadAllSurfaces() { surfaces.clear(); surf_map.clear(); std::string path = PATHMANAGER::CarSim() + "/normal/surfaces.cfg"; CONFIGFILE param; if (!param.Load(path)) { LogO("Can't find surfaces configfile: " + path); return false; } std::list <std::string> sectionlist; param.GetSectionList(sectionlist); for (std::list<std::string>::const_iterator section = sectionlist.begin(); section != sectionlist.end(); ++section) { TRACKSURFACE surf; surf.name = *section; int id; param.GetParam(*section + ".ID", id); // for sound.. //-assert(indexnum >= 0 && indexnum < (int)tracksurfaces.size()); surf.setType(id); float temp = 0.0; param.GetParam(*section + ".BumpWaveLength", temp); surf.bumpWaveLength = temp; param.GetParam(*section + ".BumpAmplitude", temp); surf.bumpAmplitude = temp; //frictionX, frictionY, bumpWaveLength2, bumpAmplitude2, not shown .. param.GetParam(*section + ".FrictionTread", temp); surf.friction = temp; if (param.GetParam(*section + ".RollResistance", temp)) surf.rollingResist = temp; param.GetParam(*section + ".RollingDrag", temp); surf.rollingDrag = temp; ///--- Tire --- std::string tireFile; if (!param.GetParam(*section + "." + "Tire", tireFile)) tireFile = "Default"; // default surface if not found surf.tireName = tireFile; ///--- surfaces.push_back(surf); surf_map[surf.name] = (int)surfaces.size(); //+1, 0 = not found } return true; }
//---------------------------------------------------------------------------------------------------------------------------------- /// Load (.car file) //---------------------------------------------------------------------------------------------------------------------------------- bool CARDYNAMICS::Load(GAME* pGame, CONFIGFILE & c, ostream & error_output) { QTimer ti; ti.update(); /// time //bTerrain = false; string drive = "RWD"; int version(1); c.GetParam("version", version); if (version > 2) { error_output << "Unsupported car version: " << version << endl; return false; } float temp_vec3[3]; //load the engine { float mass, rpm_limit, inertia, friction, start_rpm, stall_rpm, fuel_consumption; MATHVECTOR<double,3> position; if (!c.GetParam("engine.rpm-limit", rpm_limit, error_output)) return false; engine.SetRpmMax(rpm_limit); if (!c.GetParam("engine.inertia", inertia, error_output)) return false; engine.SetInertia(inertia); if (!c.GetParam("engine.friction", friction, error_output)) return false; engine.SetFrictionB(friction); if (!c.GetParam("engine.start-rpm", start_rpm, error_output)) return false; engine.SetStartRPM(start_rpm); if (!c.GetParam("engine.stall-rpm", stall_rpm, error_output)) return false; engine.SetStallRPM(stall_rpm); if (!c.GetParam("engine.fuel-consumption", fuel_consumption, error_output)) return false; engine.SetFuelConsumption(fuel_consumption); if (!c.GetParam("engine.mass", mass, error_output)) return false; if (!c.GetParam("engine.position", temp_vec3, error_output)) return false; if (version == 2) ConvertV2to1(temp_vec3[0],temp_vec3[1],temp_vec3[2]); position.Set(temp_vec3[0],temp_vec3[1],temp_vec3[2]); engine.SetMass(mass); engine.SetPosition(position); AddMassParticle(mass, position); float mul = 1.f, max_torque = 0; c.GetParam("engine.torque-val-mul", mul); float torque_point[3]; string torque_str("engine.torque-curve-00"); vector <pair <double, double> > torques; int curve_num = 0; while (c.GetParam(torque_str, torque_point)) { max_torque = max(max_torque, torque_point[1] * mul); torques.push_back(pair <float, float> (torque_point[0], torque_point[1] * mul)); curve_num++; stringstream str; str << "engine.torque-curve-"; str.width(2); str.fill('0'); str << curve_num; torque_str = str.str(); } if (torques.size() <= 1) { error_output << "You must define at least 2 torque curve points." << endl; return false; } engine.SetTorqueCurve(rpm_limit, torques); //load the clutch { float mul; //max_torque = sliding * radius * area * max_pressure; //if (!c.GetParam("clutch.max-torque", max_torque, error_output)) return false; if (!c.GetParam("clutch.max-torque-mul", mul, error_output)) return false; clutch.SetMaxTorque(max_torque * mul); } // factor for stats - mul = 1.f; if (c.GetParam("engine.real-pow-tq-mul", mul)) engine.real_pow_tq_mul = mul; mul = 1.f; if (c.GetParam("engine.sound-vol-mul", mul)) engine_vol_mul = mul; } //load the transmission { float time = 0; float ratio; int gears; c.GetParam("transmission.shift-delay", time); shift_time = time; if (!c.GetParam("transmission.gear-ratio-r", ratio, error_output)) return false; transmission.SetGearRatio(-1, ratio); if (!c.GetParam("transmission.gears", gears, error_output)) return false; for (int i = 0; i < gears; i++) { stringstream s; s << "transmission.gear-ratio-" << i+1; if (!c.GetParam(s.str(), ratio, error_output)) return false; transmission.SetGearRatio(i+1, ratio); } } //load the differential(s) string drivetype; if (!c.GetParam("drive", drivetype, error_output)) return false; SetDrive(drivetype); float final_drive, a, a_tq(0), a_tq_dec(0); /// new 3 sets if (drivetype == "AWD" && c.GetParam("diff-center.final-drive", a)) { c.GetParam("diff-rear.anti-slip", a, error_output); c.GetParam("diff-rear.torque", a_tq); c.GetParam("diff-rear.torque-dec", a_tq_dec); diff_rear.SetFinalDrive(1.0); diff_rear.SetAntiSlip(a, a_tq, a_tq_dec); c.GetParam("diff-front.anti-slip", a, error_output); c.GetParam("diff-front.torque", a_tq); c.GetParam("diff-front.torque-dec", a_tq_dec); diff_front.SetFinalDrive(1.0); diff_front.SetAntiSlip(a, a_tq, a_tq_dec); c.GetParam("diff-center.final-drive", final_drive, error_output); c.GetParam("diff-center.anti-slip", a, error_output); c.GetParam("diff-center.torque", a_tq); c.GetParam("diff-center.torque-dec", a_tq_dec); diff_center.SetFinalDrive(final_drive); diff_center.SetAntiSlip(a, a_tq, a_tq_dec); } else // old 1 for all { if (!c.GetParam("differential.final-drive", final_drive, error_output)) return false; if (!c.GetParam("differential.anti-slip", a, error_output)) return false; c.GetParam("differential.torque", a_tq); c.GetParam("differential.torque-dec", a_tq_dec); if (drivetype == "RWD") { diff_rear.SetFinalDrive(final_drive); diff_rear.SetAntiSlip(a, a_tq, a_tq_dec); } else if (drivetype == "FWD") { diff_front.SetFinalDrive(final_drive); diff_front.SetAntiSlip(a, a_tq, a_tq_dec); } else if (drivetype == "AWD") { diff_rear.SetFinalDrive(1.0); diff_rear.SetAntiSlip(a, a_tq, a_tq_dec); diff_front.SetFinalDrive(1.0); diff_front.SetAntiSlip(a, a_tq, a_tq_dec); diff_center.SetFinalDrive(final_drive); diff_center.SetAntiSlip(a, a_tq, a_tq_dec); }else { error_output << "Unknown drive type: " << drive << endl; return false; } } //load the brake { for (int i = 0; i < 2; i++) { string pos = "front"; WHEEL_POSITION left = FRONT_LEFT; WHEEL_POSITION right = FRONT_RIGHT; if (i == 1) { left = REAR_LEFT; right = REAR_RIGHT; pos = "rear"; } float friction, max_pressure, area, bias, radius, handbrake(0); if (!c.GetParam("brakes-"+pos+".friction", friction, error_output)) return false; brake[left].SetFriction(friction); brake[right].SetFriction(friction); if (!c.GetParam("brakes-"+pos+".area", area, error_output)) return false; brake[left].SetArea(area); brake[right].SetArea(area); if (!c.GetParam("brakes-"+pos+".radius", radius, error_output)) return false; brake[left].SetRadius(radius); brake[right].SetRadius(radius); c.GetParam("brakes-"+pos+".handbrake", handbrake); brake[left].SetHandbrake(handbrake); brake[right].SetHandbrake(handbrake); if (!c.GetParam("brakes-"+pos+".bias", bias, error_output)) return false; brake[left].SetBias(bias); brake[right].SetBias(bias); if (!c.GetParam("brakes-"+pos+".max-pressure", max_pressure, error_output)) return false; brake[left].SetMaxPressure(max_pressure*bias); brake[right].SetMaxPressure(max_pressure*bias); } } //load the fuel tank { float pos[3]; MATHVECTOR<double,3> position; float capacity, volume, fuel_density; if (!c.GetParam("fuel-tank.capacity", capacity, error_output)) return false; fuel_tank.SetCapacity(capacity); if (!c.GetParam("fuel-tank.volume", volume, error_output)) return false; fuel_tank.SetVolume(volume); if (!c.GetParam("fuel-tank.fuel-density", fuel_density, error_output)) return false; fuel_tank.SetDensity(fuel_density); if (!c.GetParam("fuel-tank.position", pos, error_output)) return false; if (version == 2) ConvertV2to1(pos[0],pos[1],pos[2]); position.Set(pos[0],pos[1],pos[2]); fuel_tank.SetPosition(position); //AddMassParticle(fuel_density*volume, position); } //load the suspension { for (int i = 0; i < 2; i++) { string posstr = "front"; string posshortstr = "F"; WHEEL_POSITION posl = FRONT_LEFT; WHEEL_POSITION posr = FRONT_RIGHT; if (i == 1) { posstr = "rear"; posshortstr = "R"; posl = REAR_LEFT; posr = REAR_RIGHT; } float spring_constant, bounce, rebound, travel, camber, caster, toe, anti_roll;//, maxcompvel; float hinge[3]; MATHVECTOR<double,3> tempvec; if (!c.GetParam("suspension-"+posstr+".spring-constant", spring_constant, error_output)) return false; suspension[posl].SetSpringConstant(spring_constant); suspension[posr].SetSpringConstant(spring_constant); if (!c.GetParam("suspension-"+posstr+".bounce", bounce, error_output)) return false; suspension[posl].SetBounce(bounce); suspension[posr].SetBounce(bounce); if (!c.GetParam("suspension-"+posstr+".rebound", rebound, error_output)) return false; suspension[posl].SetRebound(rebound); suspension[posr].SetRebound(rebound); string file; if (c.GetParam("suspension-"+posstr+".factors-file", file)) { int id = pGame->suspS_map[file]-1; if (id == -1) { id = 0; error_output << "Can't find suspension spring factors file: " << file << endl; } suspension[posl].SetSpringFactorPoints(pGame->suspS[id]); suspension[posr].SetSpringFactorPoints(pGame->suspS[id]); id = pGame->suspD_map[file]-1; if (id == -1) { id = 0; error_output << "Can't find suspension damper factors file: " << file << endl; } suspension[posl].SetDamperFactorPoints(pGame->suspD[id]); suspension[posr].SetDamperFactorPoints(pGame->suspD[id]); }else { // factor points vector <pair <double, double> > damper, spring; c.GetPoints("suspension-"+posstr, "damper-factor", damper); suspension[posl].SetDamperFactorPoints(damper); suspension[posr].SetDamperFactorPoints(damper); c.GetPoints("suspension-"+posstr, "spring-factor", spring); suspension[posl].SetSpringFactorPoints(spring); suspension[posr].SetSpringFactorPoints(spring); } if (!c.GetParam("suspension-"+posstr+".travel", travel, error_output)) return false; suspension[posl].SetTravel(travel); suspension[posr].SetTravel(travel); if (!c.GetParam("suspension-"+posstr+".camber", camber, error_output)) return false; suspension[posl].SetCamber(camber); suspension[posr].SetCamber(camber); if (!c.GetParam("suspension-"+posstr+".caster", caster, error_output)) return false; suspension[posl].SetCaster(caster); suspension[posr].SetCaster(caster); if (!c.GetParam("suspension-"+posstr+".toe", toe, error_output)) return false; suspension[posl].SetToe(toe); suspension[posr].SetToe(toe); if (!c.GetParam("suspension-"+posstr+".anti-roll", anti_roll, error_output)) return false; suspension[posl].SetAntiRollK(anti_roll); suspension[posr].SetAntiRollK(anti_roll); if (!c.GetParam("suspension-"+posshortstr+"L.hinge", hinge, error_output)) return false; //cap hinge to reasonable values for (int i = 0; i < 3; i++) { if (hinge[i] < -100) hinge[i] = -100; if (hinge[i] > 100) hinge[i] = 100; } if (version == 2) ConvertV2to1(hinge[0],hinge[1],hinge[2]); tempvec.Set(hinge[0],hinge[1], hinge[2]); suspension[posl].SetHinge(tempvec); if (!c.GetParam("suspension-"+posshortstr+"R.hinge", hinge, error_output)) return false; for (int i = 0; i < 3; i++) { if (hinge[i] < -100) hinge[i] = -100; if (hinge[i] > 100) hinge[i] = 100; } if (version == 2) ConvertV2to1(hinge[0],hinge[1],hinge[2]); tempvec.Set(hinge[0],hinge[1], hinge[2]); suspension[posr].SetHinge(tempvec); } } //load the wheels { for (int i = 0; i < 4; i++) { string sPos; WHEEL_POSITION wp; if (i == 0) { sPos = "FL"; wp = FRONT_LEFT; } else if (i == 1){ sPos = "FR"; wp = FRONT_RIGHT; } else if (i == 2){ sPos = "RL"; wp = REAR_LEFT; } else { sPos = "RR"; wp = REAR_RIGHT; } float roll_h, mass; float pos[3]; MATHVECTOR<double,3> vec; if (!c.GetParam("wheel-"+sPos+".mass", mass, error_output)) return false; wheel[wp].SetMass(mass); if (!c.GetParam("wheel-"+sPos+".roll-height", roll_h, error_output)) return false; wheel[wp].SetRollHeight(roll_h); if (!c.GetParam("wheel-"+sPos+".position", pos, error_output)) return false; if (version == 2) ConvertV2to1(pos[0],pos[1],pos[2]); vec.Set(pos[0],pos[1], pos[2]); wheel[wp].SetExtendedPosition(vec); AddMassParticle(mass, vec); } //load the rotational inertia parameter from the tire section float front_inertia; float rear_inertia; if (c.GetParam("tire-both.rotational-inertia", front_inertia, error_output)) rear_inertia = front_inertia; else { if (!c.GetParam("tire-front.rotational-inertia", front_inertia, error_output)) return false; if (!c.GetParam("tire-rear.rotational-inertia", rear_inertia, error_output)) return false; } wheel[FRONT_LEFT].SetInertia(front_inertia); wheel[FRONT_RIGHT].SetInertia(front_inertia); wheel[REAR_LEFT].SetInertia(rear_inertia); wheel[REAR_RIGHT].SetInertia(rear_inertia); } //load the tire parameters { WHEEL_POSITION leftside = FRONT_LEFT; WHEEL_POSITION rightside = FRONT_RIGHT; float value; bool both = c.GetParam("tire-both.radius", value); string posstr = both ? "both" : "front"; for (int p = 0; p < 2; ++p) { if (p == 1) { leftside = REAR_LEFT; rightside = REAR_RIGHT; if (!both) posstr = "rear"; } float rolling_resistance[3]; if (!c.GetParam("tire-"+posstr+".rolling-resistance", rolling_resistance, error_output)) return false; wheel[leftside].SetRollingResistance(rolling_resistance[0], rolling_resistance[1]); wheel[rightside].SetRollingResistance(rolling_resistance[0], rolling_resistance[1]); float radius; if (!c.GetParam("tire-"+posstr+".radius", radius, error_output)) return false; wheel[leftside].SetRadius(radius); wheel[rightside].SetRadius(radius); } } //load the mass-only particles { MATHVECTOR<double,3> position; float pos[3], mass; if (c.GetParam("contact-points.mass", mass)) { int paramnum(0); string paramname("contact-points.position-00"); stringstream output_supression; while (c.GetParam(paramname, pos)) { if (version == 2) ConvertV2to1(pos[0],pos[1],pos[2]); position.Set(pos[0],pos[1],pos[2]); AddMassParticle(mass, position); paramnum++; stringstream str; str << "contact-points.position-"; str.width(2); str.fill('0'); str << paramnum; paramname = str.str(); } } string paramname = "particle-00"; int paramnum = 0; while (c.GetParam(paramname+".mass", mass)) { if (!c.GetParam(paramname+".position", pos, error_output)) return false; if (version == 2) ConvertV2to1(pos[0],pos[1],pos[2]); position.Set(pos[0],pos[1],pos[2]); AddMassParticle(mass, position); paramnum++; stringstream str; str << "particle-"; str.width(2); str.fill('0'); str << paramnum; paramname = str.str(); } } //load the max steering angle { float maxangle = 26.f; if (!c.GetParam("steering.max-angle", maxangle, error_output)) return false; SetMaxSteeringAngle( maxangle ); float a = 1.f; c.GetParam("steering.flip-pow-mul", a); flip_mul = a; } ///car angular damping -new { float a = 0.4f; c.GetParam("steering.angular-damping", a, error_output); SetAngDamp(a); a=0.f; c.GetParam("rot_drag.roll", a); rot_coef[0] = a; a=0.f; c.GetParam("rot_drag.pitch", a); rot_coef[1] = a; a=0.f; c.GetParam("rot_drag.yaw", a); rot_coef[2] = a; a=0.f; c.GetParam("rot_drag.yaw2", a); rot_coef[3] = a; } //load the driver { float mass; float pos[3]; MATHVECTOR<double,3> position; if (!c.GetParam("driver.mass", mass, error_output)) return false; if (!c.GetParam("driver.position", pos, error_output)) return false; if (version == 2) ConvertV2to1(pos[0],pos[1],pos[2]); position.Set(pos[0], pos[1], pos[2]); AddMassParticle(mass, position); } //load the aerodynamics { float drag_area, drag_c, lift_area, lift_c, lift_eff; float pos[3]; MATHVECTOR<double,3> position; if (!c.GetParam("drag.frontal-area", drag_area, error_output)) return false; if (!c.GetParam("drag.drag-coefficient", drag_c, error_output)) return false; if (!c.GetParam("drag.position", pos, error_output)) return false; if (version == 2) ConvertV2to1(pos[0],pos[1],pos[2]); position.Set(pos[0], pos[1], pos[2]); AddAerodynamicDevice(position, drag_area, drag_c, 0,0,0); for (int i = 0; i < 2; i++) { string wingpos = "front"; if (i == 1) wingpos = "rear"; if (!c.GetParam("wing-"+wingpos+".frontal-area", drag_area, error_output)) return false; if (!c.GetParam("wing-"+wingpos+".drag-coefficient", drag_c, error_output)) return false; if (!c.GetParam("wing-"+wingpos+".surface-area", lift_area, error_output)) return false; if (!c.GetParam("wing-"+wingpos+".lift-coefficient", lift_c, error_output)) return false; if (!c.GetParam("wing-"+wingpos+".efficiency", lift_eff, error_output)) return false; if (!c.GetParam("wing-"+wingpos+".position", pos, error_output)) return false; if (version == 2) ConvertV2to1(pos[0],pos[1],pos[2]); position.Set(pos[0], pos[1], pos[2]); AddAerodynamicDevice(position, drag_area, drag_c, lift_area, lift_c, lift_eff); } } UpdateMass(); ti.update(); /// time float dt = ti.dt * 1000.f; LogO(Ogre::String(":::: Time car dynamics load: ") + fToStr(dt,0,3) + " ms"); return true; }
//-------------------------------------------------------------------------------------------------------------------------- bool CAR::LoadSounds( const std::string & carpath, const std::string & carname, const SOUNDINFO & sound_device_info, const SOUNDBUFFERLIBRARY & sndLib, std::ostream & info_output, std::ostream & errOut) { //check for sound specification file CONFIGFILE aud; if (aud.Load(carpath+"/"+carname+"/"+carname+".aud")) // ? { std::list <std::string> sections; aud.GetSectionList(sections); for (std::list <std::string>::iterator i = sections.begin(); i != sections.end(); ++i) { //load the buffer std::string filename; if (!aud.GetParam(*i+".filename", filename, errOut)) return false; if (!soundbuffers[filename].GetLoaded()) if (!soundbuffers[filename].Load(carpath+"/"+carname+"/"+filename, sound_device_info, errOut)) { errOut << "Error loading sound: " << carpath+"/"+carname+"/"+filename << std::endl; return false; } enginesounds.push_back(std::pair <ENGINESOUNDINFO, SOUNDSOURCE> ()); ENGINESOUNDINFO & info = enginesounds.back().first; SOUNDSOURCE & sound = enginesounds.back().second; if (!aud.GetParam(*i+".MinimumRPM", info.minrpm, errOut)) return false; if (!aud.GetParam(*i+".MaximumRPM", info.maxrpm, errOut)) return false; if (!aud.GetParam(*i+".NaturalRPM", info.naturalrpm, errOut)) return false; std::string powersetting; if (!aud.GetParam(*i+".power", powersetting, errOut)) return false; if (powersetting == "on") info.power = ENGINESOUNDINFO::POWERON; else if (powersetting == "off") info.power = ENGINESOUNDINFO::POWEROFF; else //assume it's used in both ways info.power = ENGINESOUNDINFO::BOTH; sound.Setup(soundbuffers[filename], true, true, 0.f); sound.Play(); } //set blend start and end locations -- requires multiple passes std::map <ENGINESOUNDINFO *, ENGINESOUNDINFO *> temporary_to_actual_map; std::list <ENGINESOUNDINFO> poweron_sounds; std::list <ENGINESOUNDINFO> poweroff_sounds; for (std::list <std::pair <ENGINESOUNDINFO, SOUNDSOURCE> >::iterator i = enginesounds.begin(); i != enginesounds.end(); ++i) { ENGINESOUNDINFO & info = i->first; if (info.power == ENGINESOUNDINFO::POWERON) { poweron_sounds.push_back(info); temporary_to_actual_map[&poweron_sounds.back()] = &info; } else if (info.power == ENGINESOUNDINFO::POWEROFF) { poweroff_sounds.push_back(info); temporary_to_actual_map[&poweroff_sounds.back()] = &info; } } poweron_sounds.sort(); poweroff_sounds.sort(); //we only support 2 overlapping sounds at once each for poweron and poweroff; this // algorithm fails for other cases (undefined behavior) std::list <ENGINESOUNDINFO> * cursounds = &poweron_sounds; for (int n = 0; n < 2; n++) { if (n == 1) cursounds = &poweroff_sounds; for (std::list <ENGINESOUNDINFO>::iterator i = (*cursounds).begin(); i != (*cursounds).end(); ++i) { //set start blend if (i == (*cursounds).begin()) i->fullgainrpmstart = i->minrpm; //else, the blend start has been set already by the previous iteration //set end blend std::list <ENGINESOUNDINFO>::iterator inext = i; ++inext; if (inext == (*cursounds).end()) i->fullgainrpmend = i->maxrpm; else { i->fullgainrpmend = inext->minrpm; inext->fullgainrpmstart = i->maxrpm; } } //now assign back to the actual infos for (std::list <ENGINESOUNDINFO>::iterator i = (*cursounds).begin(); i != (*cursounds).end(); ++i) { assert(temporary_to_actual_map.find(&(*i)) != temporary_to_actual_map.end()); *temporary_to_actual_map[&(*i)] = *i; } } } else // car engine { if (!soundbuffers["engine.wav"].Load(carpath+"/"+carname+"/engine.wav", sound_device_info, errOut)) { errOut << "Unable to load engine sound: "+carpath+"/"+carname+"/engine.wav" << std::endl; return false; } enginesounds.push_back(std::pair <ENGINESOUNDINFO, SOUNDSOURCE> ()); SOUNDSOURCE & enginesound = enginesounds.back().second; enginesound.Setup(soundbuffers["engine.wav"], true, true, 0.f); enginesound.Play(); } int i; for (i = 0; i < 4; ++i) // tires { if (!tiresqueal[i] .Setup(sndLib, "tire_squeal", errOut, true, true, 0.f)) return false; tiresqueal[i].Seek4(i); if (!gravelsound[i] .Setup(sndLib, "gravel", errOut, true, true, 0.f)) return false; gravelsound[i].Seek4(i); if (!grasssound[i] .Setup(sndLib, "grass", errOut, true, true, 0.f)) return false; grasssound[i].Seek4(i); if (!tirebump[i].Setup(sndLib, i >= 2 ? "bump_rear" : "bump_front", errOut, true, false,1.f)) return false; } for (i = 1; i <= Ncrashsounds; ++i) // crashes if (!crashsound[i-1].Setup(sndLib, toStr(i/10)+toStr(i%10), errOut, true, false,1.f)) return false; if (!crashscrap .Setup(sndLib, "scrap", errOut, true, true, 0.f)) return false; crashscrap.Play(); if (!crashscreech.Setup(sndLib, "screech", errOut, true, true, 0.f)) return false; crashscreech.Play(); if (!roadnoise .Setup(sndLib, "wind", errOut, true, true, 0.f)) return false; roadnoise.Play(); if (!boostsnd .Setup(sndLib, "boost", errOut, true, true, 0.f)) return false; boostsnd.Play(); for (i = 0; i < Nwatersounds; ++i) // fluids if (!watersnd[i].Setup(sndLib, "water"+toStr(i+1), errOut, true, false,0.f)) return false; if (!mudsnd .Setup(sndLib, "mud1", errOut, true, false,0.f)) return false; if (!mud_cont .Setup(sndLib, "mud_cont", errOut, true, true, 0.f)) return false; mud_cont.Play(); if (!water_cont .Setup(sndLib, "water_cont", errOut, true, true, 0.f)) return false; water_cont.Play(); return true; }
void CarModel::LoadConfig(const std::string & pathCar) { Defaults(); /// load ----- CONFIGFILE cf; if (!cf.Load(pathCar)) { LogO("!! CarModel: Can't load .car "+pathCar); return; } //- custom interior model offset cf.GetParam("model_ofs.interior-x", interiorOffset[0]); cf.GetParam("model_ofs.interior-y", interiorOffset[1]); cf.GetParam("model_ofs.interior-z", interiorOffset[2]); cf.GetParam("model_ofs.rot_fix", bRotFix); //~ boost offset cf.GetParam("model_ofs.boost-x", boostOffset[0]); cf.GetParam("model_ofs.boost-y", boostOffset[1]); cf.GetParam("model_ofs.boost-z", boostOffset[2]); cf.GetParam("model_ofs.boost-size-z", boostSizeZ); cf.GetParam("model_ofs.boost-name", sBoostParName); // thruster spaceship hover cf.GetParam("model_ofs.thrust-x", thrusterOfs[0]); cf.GetParam("model_ofs.thrust-y", thrusterOfs[1]); cf.GetParam("model_ofs.thrust-z", thrusterOfs[2]); cf.GetParam("model_ofs.thrust-size-z", thrusterSizeZ); cf.GetParam("model_ofs.thrust-name", sThrusterPar); //~ brake flares float pos[3]; bool ok=true; int i=0; while (ok) { ok = cf.GetParam("flares.brake-pos"+toStr(i), pos); ++i; if (ok) brakePos.push_back(bRotFix ? Vector3(-pos[0],pos[2],pos[1]) : Vector3(-pos[1],-pos[2],pos[0])); } cf.GetParam("flares.brake-color", pos); brakeClr = ColourValue(pos[0],pos[1],pos[2]); cf.GetParam("flares.brake-size", brakeSize); //- custom exhaust pos for boost particles if (cf.GetParam("model_ofs.exhaust-x", exhaustPos[0])) { manualExhaustPos = true; cf.GetParam("model_ofs.exhaust-y", exhaustPos[1]); cf.GetParam("model_ofs.exhaust-z", exhaustPos[2]); }else manualExhaustPos = false; if (!cf.GetParam("model_ofs.exhaust-mirror-second", has2exhausts)) has2exhausts = false; //- load cameras pos cf.GetParam("driver.view-position", pos, pGame->error_output); driver_view[0]=pos[1]; driver_view[1]=-pos[0]; driver_view[2]=pos[2]; cf.GetParam("driver.hood-position", pos, pGame->error_output); hood_view[0]=pos[1]; hood_view[1]=-pos[0]; hood_view[2]=pos[2]; // tire params WHEEL_POSITION leftside = FRONT_LEFT, rightside = FRONT_RIGHT; float value; bool both = cf.GetParam("tire-both.radius", value); std::string posstr = both ? "both" : "front"; for (int p = 0; p < 2; ++p) { if (p == 1) { leftside = REAR_LEFT; rightside = REAR_RIGHT; if (!both) posstr = "rear"; } float radius; cf.GetParam("tire-"+posstr+".radius", radius, pGame->error_output); whRadius[leftside] = radius; whRadius[rightside] = radius; float width = 0.2f; cf.GetParam("tire-"+posstr+".width-trail", width); whWidth[leftside] = width; whWidth[rightside] = width; } // wheel pos // for track's ghost or garage view int version(1); cf.GetParam("version", version); for (int i = 0; i < 4; ++i) { std::string sPos; if (i == 0) sPos = "FL"; else if (i == 1) sPos = "FR"; else if (i == 2) sPos = "RL"; else sPos = "RR"; float pos[3]; MATHVECTOR<float,3> vec; cf.GetParam("wheel-"+sPos+".position", pos, pGame->error_output); if (version == 2) ConvertV2to1(pos[0],pos[1],pos[2]); vec.Set(pos[0],pos[1], pos[2]); whPos[i] = vec; } // steer angle maxangle = 26.f; cf.GetParam("steering.max-angle", maxangle, pGame->error_output); maxangle *= pGame->GetSteerRange(); }
bool LoadWorld() { UnloadWorld(); editordata.helppage = 0; editordata.numbezinput = 0; editordata.mousebounce[1] = false; //teststrip = track.AddNewRoad(); //begin loading world LoadingScreen("Loading...\nConfiguration files"); CONFIGFILE setupfile; setupfile.Load(settings.GetDataDir() + "/tracks/editor.config"); setupfile.GetParam("active track", editordata.activetrack); if (editordata.activetrack == "") editordata.activetrack = "default"; objects.LoadObjectsFromFolder(settings.GetDataDir() + "/tracks/" + editordata.activetrack + "/objects/"); track.Load(editordata.activetrack); //float aangle[] = {0, 1, 0, 0}; //track.GetStartOrientation(0).GetAxisAngle(aangle); //cam.Rotate(aangle[0], aangle[1], aangle[2], aangle[3]); VERTEX start = track.GetStart(0); cam.Move(-start.x, -start.y, -start.z); cam.Update(); cam.LoadVelocityIdentity(); //car_file = "s2000"; //ifstream csfile; //car_file = ""; //csfile.open((settings.GetSettingsDir() + "/selected_car").c_str()); //car_paint = 0; /* if (csfile) { state.SetCarName(0, utility.sGetLine(csfile)); state.SetCarPaint(0, utility.iGetParam(csfile)); csfile.close(); } */ //LoadingScreen("Loading...\nLoading scenery objects"); //objects.LoadObjectsFromFolder(settings.GetDataDir() + "/tracks/" + state.GetTrackName() + "/objects"); /*trees.DeleteAll(); int numtrees = 200; for (i = 0; i < numtrees/2; i++) { VERTEX tp; tp.x = ((float) rand()/RAND_MAX)*(param[0]/2.0)+param[0]/4.0; tp.z = ((float) rand()/RAND_MAX)*(param[2]/2.0)+param[2]/4.0; tp.x += param[3]; tp.z += param[4]; tp.y = terrain.GetHeight(tp.x, tp.z); trees.Add(tp, 40.0, 0, 5); } for (i = 0; i < numtrees/2; i++) { VERTEX tp; tp.x = ((float) rand()/RAND_MAX)*(param[0]/2.0)+param[0]/4.0; tp.z = ((float) rand()/RAND_MAX)*(param[2]/2.0)+param[2]/4.0; tp.x += param[3]; tp.z += param[4]; tp.y = terrain.GetHeight(tp.x, tp.z); trees.Add(tp, 60.0, 1, 5); }*/ LoadingScreen("Loading...\nDone"); mq1.AddMessage("Editor started, press H for help"); return true; }