/// 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; }
//-------------------------------------------------------------------------------------------------------------------------- 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; }