diff --git a/rwcore/fonts/FontMap.cpp b/rwcore/fonts/FontMap.cpp index c8ba1eae..6e33d4ac 100644 --- a/rwcore/fonts/FontMap.cpp +++ b/rwcore/fonts/FontMap.cpp @@ -12,8 +12,8 @@ using OGameStringStream = std::basic_ostringstream; FontMap::FontMap(std::initializer_list> maps) { for (const auto &map : maps) { m_to_unicode.insert(map.get().cbegin(), map.get().cend()); - for (const auto &m : map.get()) { - m_from_unicode[m.second] = m.first; + for (const auto &[gameStringChar, unicode] : map.get()) { + m_from_unicode[unicode] = gameStringChar; } } const auto &q = m_from_unicode.find(UnicodeValue::UNICODE_QUESTION_MARK); diff --git a/rwengine/src/audio/SoundManager.cpp b/rwengine/src/audio/SoundManager.cpp index 33ae5e62..77cfaf12 100644 --- a/rwengine/src/audio/SoundManager.cpp +++ b/rwengine/src/audio/SoundManager.cpp @@ -110,10 +110,10 @@ bool SoundManager::loadSound(const std::string& name, if (sound_iter != sounds.end()) { sound = &sound_iter->second; } else { - auto emplaced = sounds.emplace(std::piecewise_construct, + auto [it, emplaced] = sounds.emplace(std::piecewise_construct, std::forward_as_tuple(name), std::forward_as_tuple()); - sound = &emplaced.first->second; + sound = &it->second; sound->source = std::make_shared(); sound->buffer = std::make_unique(); @@ -128,10 +128,10 @@ bool SoundManager::loadSound(const std::string& name, void SoundManager::loadSound(size_t index) { Sound* sound = nullptr; - auto emplaced = + auto [it, emplaced] = sfx.emplace(std::piecewise_construct, std::forward_as_tuple(index), std::forward_as_tuple()); - sound = &emplaced.first->second; + sound = &it->second; sound->source = std::make_shared(); sound->source->loadSfx(sdt, index); @@ -149,22 +149,22 @@ size_t SoundManager::createSfxInstance(size_t index) { // Try to reuse first available buffer // (aka with stopped state) - for (auto& sound : buffers) { - if (sound.second.buffer && sound.second.isStopped()) { + for (auto& [id, sound] : buffers) { + if (sound.buffer && sound.isStopped()) { // Let's use this buffer - sound.second.buffer = std::make_unique(); - sound.second.source = soundRef->second.source; - sound.second.isLoaded = - sound.second.buffer->bufferData(*sound.second.source); - return sound.first; + sound.buffer = std::make_unique(); + sound.source = soundRef->second.source; + sound.isLoaded = + sound.buffer->bufferData(*sound.source); + return id; } } // There's no available free buffer, so // we should create a new one. - auto emplaced = buffers.emplace(std::piecewise_construct, + auto [it, emplaced] = buffers.emplace(std::piecewise_construct, std::forward_as_tuple(bufferNr), std::forward_as_tuple()); - sound = &emplaced.first->second; + sound = &it->second; sound->id = bufferNr; sound->buffer = std::make_unique(); diff --git a/rwengine/src/engine/Animator.cpp b/rwengine/src/engine/Animator.cpp index 2c4ee627..7fda5c21 100644 --- a/rwengine/src/engine/Animator.cpp +++ b/rwengine/src/engine/Animator.cpp @@ -24,21 +24,16 @@ void Animator::tick(float dt) { glm::quat rotation{1.0f,0.0f,0.0f,0.0f}; }; -#if 0 - // Blend all active animations together - std::map blendFrames; -#endif - for (AnimationState& state : animations) { if (state.animation == nullptr) continue; if (state.boneInstances.empty()) { - for (const auto& bone : state.animation->bones) { - auto frame = model->findFrame(bone.first); + for (const auto& [name, bonePtr] : state.animation->bones) { + auto frame = model->findFrame(name); if (!frame) { continue; } - state.boneInstances.emplace(bone.second.get(), frame); + state.boneInstances.emplace(bonePtr.get(), frame); } } @@ -51,42 +46,20 @@ void Animator::tick(float dt) { animTime = std::fmod(animTime, state.animation->duration); } - for (auto& b : state.boneInstances) { - if (b.first->frames.empty()) continue; - auto kf = b.first->getInterpolatedKeyframe(animTime); + for (auto& [bonePtr, frame] : state.boneInstances) { + if (bonePtr->frames.empty()) continue; + auto kf = bonePtr->getInterpolatedKeyframe(animTime); BoneTransform xform; xform.rotation = kf.rotation; - if (b.first->type != AnimationBone::R00) { + if (bonePtr->type != AnimationBone::R00) { xform.translation = kf.position; } - -#if 0 - auto prevAnim = blendFrames.find(b.second.frameIndex); - if (prevAnim != blendFrames.end()) - { - prevAnim->second.translation += xform.translation; - prevAnim->second.rotation *= xform.rotation; - } - else - { - blendFrames[b.second.frameIndex] = xform; - } -#else - b.second->setTranslation(b.second->getDefaultTranslation() + + frame->setTranslation(frame->getDefaultTranslation() + xform.translation); - b.second->setRotation(glm::mat3_cast(xform.rotation)); -#endif + frame->setRotation(glm::mat3_cast(xform.rotation)); } } - -#if 0 - for (auto& p : blendFrames) { - p.first->setTranslation(p.first->getDefaultTranslation() + - p.second.translation); - p.first->setRotation(glm::mat3_cast(p.second.rotation)); - } -#endif } bool Animator::isCompleted(unsigned int slot) const { diff --git a/rwengine/src/engine/GameState.cpp b/rwengine/src/engine/GameState.cpp index a9d0a83e..efd6a5c6 100644 --- a/rwengine/src/engine/GameState.cpp +++ b/rwengine/src/engine/GameState.cpp @@ -2,9 +2,9 @@ int GameState::addRadarBlip(BlipData& blip) { int l = 0; - for (const auto& radarBlip : radarBlips) { - if ((radarBlip.first) != l) { - l = radarBlip.first - 1; + for (const auto& [nr, blipData] : radarBlips) { + if ((nr) != l) { + l = nr - 1; } else { l++; } diff --git a/rwengine/src/engine/GameWorld.cpp b/rwengine/src/engine/GameWorld.cpp index 485e7455..ebaa69fa 100644 --- a/rwengine/src/engine/GameWorld.cpp +++ b/rwengine/src/engine/GameWorld.cpp @@ -439,8 +439,8 @@ void GameWorld::ObjectPool::insert(std::unique_ptr object) { if (object->getGameObjectID() == 0) { // Find the lowest free GameObjectID. GameObjectID availID = 1; - for (auto& p : objects) { - if (p.first == availID) availID++; + for (auto& [id, objectPtr] : objects) { + if (id == availID) availID++; } object->setGameObjectID(availID); diff --git a/rwengine/src/objects/VehicleObject.cpp b/rwengine/src/objects/VehicleObject.cpp index 1c8253a1..73b2c0e7 100644 --- a/rwengine/src/objects/VehicleObject.cpp +++ b/rwengine/src/objects/VehicleObject.cpp @@ -458,20 +458,20 @@ void VehicleObject::tickPhysics(float dt) { } // Update passenger positions - for (auto& seat : seatOccupants) { - auto character = static_cast(seat.second); + for (auto& [seatId, objectPtr] : seatOccupants) { + auto character = static_cast(objectPtr); glm::vec3 passPosition{}; if (character->isEnteringOrExitingVehicle()) { - passPosition = getSeatEntryPositionWorld(seat.first); + passPosition = getSeatEntryPositionWorld(seatId); } else { passPosition = getPosition(); - if (seat.first < info->seats.size()) { + if (seatId < info->seats.size()) { passPosition += - getRotation() * (info->seats[seat.first].offset); + getRotation() * (info->seats[seatId].offset); } } - seat.second->updateTransform(passPosition, getRotation()); + objectPtr->updateTransform(passPosition, getRotation()); } if (getVehicle()->vehicletype_ == VehicleModelInfo::BOAT) { diff --git a/rwengine/src/script/modules/GTA3ModuleImpl.inl b/rwengine/src/script/modules/GTA3ModuleImpl.inl index dea641bf..9776749b 100644 --- a/rwengine/src/script/modules/GTA3ModuleImpl.inl +++ b/rwengine/src/script/modules/GTA3ModuleImpl.inl @@ -7719,8 +7719,8 @@ void opcode_02dd(const ScriptArguments& args, const ScriptString areaName, Scrip if (zone) { // Create a list of candidate characters by iterating and checking if the char is in this zone std::vector> candidates; - for (auto& p : args.getWorld()->pedestrianPool.objects) { - auto character = static_cast(p.second.get()); + for (auto& [id, pedestrianPtr] : args.getWorld()->pedestrianPool.objects) { + auto character = static_cast(pedestrianPtr.get()); // We only consider characters walking around normally // @todo not sure if we are able to grab script objects or players too @@ -7735,7 +7735,7 @@ void opcode_02dd(const ScriptArguments& args, const ScriptString areaName, Scrip auto& max = zone->max; if (cp.x > min.x && cp.y > min.y && cp.z > min.z && cp.x < max.x && cp.y < max.y && cp.z < max.z) { - candidates.emplace_back(p.first, p.second.get()); + candidates.emplace_back(id, pedestrianPtr.get()); } } @@ -7746,13 +7746,13 @@ void opcode_02dd(const ScriptArguments& args, const ScriptString areaName, Scrip // @todo verify if the lifetime is actually changed in the original game // husho: lifetime is changed to mission object lifetime unsigned int randomIndex = std::rand() % candidateCount; - const auto p = candidates[randomIndex]; - auto character = static_cast(p.second); + const auto [candidateId, candidatePtr] = candidates.at(randomIndex); + auto character = static_cast(candidatePtr); character->setLifetime(GameObject::MissionLifetime); if (args.getThread()->isMission) { script::addObjectToMissionCleanup(args, character); } - *args[1].globalInteger = p.first; + *args[1].globalInteger = candidateId; return; } } diff --git a/rwgame/GameConfig.cpp b/rwgame/GameConfig.cpp index 576f4573..fcc987d1 100644 --- a/rwgame/GameConfig.cpp +++ b/rwgame/GameConfig.cpp @@ -455,8 +455,8 @@ std::string GameConfig::ParseResult::what() const { } if (!this->m_unknownData.empty()) { oss << "\nUnknown configuration keys:"; - for (const auto &keyvalue : m_unknownData) { - oss << "\n - " << keyvalue.first; + for (const auto &[key, value] : m_unknownData) { + oss << "\n - " << key; } } return oss.str(); diff --git a/rwgame/GameInput.cpp b/rwgame/GameInput.cpp index 0f4caa8d..84886eef 100644 --- a/rwgame/GameInput.cpp +++ b/rwgame/GameInput.cpp @@ -71,8 +71,8 @@ void GameInput::updateGameInputState(GameInputState *state, auto level = event.type == SDL_KEYDOWN ? 1.f : 0.f; auto& levels = state->levels; - auto range = kDefaultControls.equal_range(sym); - for (auto it = range.first; it != range.second; ++it) { + auto [rangeBegin, rangeEnd] = kDefaultControls.equal_range(sym); + for (auto it = rangeBegin; it != rangeEnd; ++it) { levels[it->second] = level; } } break; diff --git a/rwgame/RWGame.cpp b/rwgame/RWGame.cpp index e2f69e09..e9d2b7d9 100644 --- a/rwgame/RWGame.cpp +++ b/rwgame/RWGame.cpp @@ -25,16 +25,13 @@ #include #include -const std::map> - kSpecialModels = { - {GameRenderer::ZoneCylinderA, - std::pair("zonecyla.dff", "particle")}, - {GameRenderer::ZoneCylinderB, - std::pair("zonecylb.dff", "particle")}, - {GameRenderer::Arrow, - std::pair("arrow.dff", "")}}; - namespace { +static constexpr std::array< + std::tuple, 3> + kSpecialModels{{{GameRenderer::ZoneCylinderA, "zonecyla.dff", "particle"}, + {GameRenderer::ZoneCylinderB, "zonecylb.dff", "particle"}, + {GameRenderer::Arrow, "arrow.dff", ""}}}; + constexpr float kMaxPhysicsSubSteps = 2; } // namespace @@ -64,9 +61,9 @@ RWGame::RWGame(Logger& log, int argc, char* argv[]) data.load(); - for (const auto& p : kSpecialModels) { - auto model = data.loadClump(p.second.first, p.second.second); - renderer.setSpecialModel(p.first, model); + for (const auto& [specialModel, fileName, name] : kSpecialModels) { + auto model = data.loadClump(fileName, name); + renderer.setSpecialModel(specialModel, model); } // Set up text renderer @@ -213,7 +210,7 @@ void RWGame::handleCheatInput(char symbol) { }); checkForCheat("GUNSGUNSGUNS", [&] { - constexpr std::array ammo = {{ + static constexpr std::array ammo = {{ 1, //baseball bat 100,//pistol 100,//uzi @@ -226,7 +223,7 @@ void RWGame::handleCheatInput(char symbol) { 200,//m16 5 //sniper rifle }}; - for (std::array::size_type i = 0; i < ammo.size(); i++) + for (auto i = 0u; i < ammo.size(); i++) player->addToInventory(static_cast(i+1),ammo[i]); state.showHelpMessage("CHEAT2"); // III / VC: Inputting weapon cheats. }); diff --git a/rwgame/states/DebugState.cpp b/rwgame/states/DebugState.cpp index 6afafdf0..c3939eaa 100644 --- a/rwgame/states/DebugState.cpp +++ b/rwgame/states/DebugState.cpp @@ -108,7 +108,7 @@ std::shared_ptr DebugState::createMapMenu() { }}, {"Unsolid garage doors", [=] { - std::vector garageDoorModels{ + static constexpr std::array garageDoorModels{{ "8ballsuburbandoor", "amcogaragedoor", "bankjobdoor", "bombdoor", "crushercrush", "crushertop", @@ -125,11 +125,11 @@ std::shared_ptr DebugState::createMapMenu() { "SalvGarage", "shedgaragedoor", "Sub_sprayshopdoor", "towergaragedoor1", "towergaragedoor2", "towergaragedoor3", - "vheistlocdoor"}; + "vheistlocdoor"}}; auto gw = game->getWorld(); - for (auto& i : gw->instancePool.objects) { - auto obj = static_cast(i.second.get()); + for (auto& [id, instancePtr] : gw->instancePool.objects) { + auto obj = static_cast(instancePtr.get()); if (std::find(garageDoorModels.begin(), garageDoorModels.end(), obj->getModelInfo()->name) != @@ -148,18 +148,29 @@ std::shared_ptr DebugState::createVehicleMenu() { auto menu = Menu::create({{"Back", [=] { enterMenu(createDebugMenu()); }}}, kDebugFont, kDebugEntryHeight); - const std::map kVehicleTypes = { - {"Landstalker", 90}, {"Taxi", 110}, {"Firetruck", 97}, - {"Police", 116}, {"Ambulance", 106}, {"Bobcat", 112}, - {"Banshee", 119}, {"Rhino", 122}, {"Barracks", 123}, - {"Rumpo", 130}, {"Columbian", 138}, {"Dodo", 126}, - {"Speeder", 142}, {"Yakuza", 136}, {"Cheetah", 105}, - {"Ambulance", 106}, {"FBI", 107}, {"Mafia", 134}, - {"Infernus", 101}, - }; + static constexpr std::array, 19> + kVehicleTypes{{{"Landstalker", 90}, + {"Taxi", 110}, + {"Firetruck", 97}, + {"Police", 116}, + {"Ambulance", 106}, + {"Bobcat", 112}, + {"Banshee", 119}, + {"Rhino", 122}, + {"Barracks", 123}, + {"Rumpo", 130}, + {"Columbian", 138}, + {"Dodo", 126}, + {"Speeder", 142}, + {"Yakuza", 136}, + {"Cheetah", 105}, + {"Ambulance", 106}, + {"FBI", 107}, + {"Mafia", 134}, + {"Infernus", 101}}}; - for (auto& e : kVehicleTypes) { - menu->lambda(e.first, [=] { spawnVehicle(e.second); }); + for (const auto& [name, id] : kVehicleTypes) { + menu->lambda(name, [this, id = id] { spawnVehicle(id); }); } menu->offset = kDebugMenuOffset; @@ -171,23 +182,29 @@ std::shared_ptr DebugState::createAIMenu() { Menu::create({{"Back", [=] { this->enterMenu(createDebugMenu()); }}}, kDebugFont, kDebugEntryHeight); - const std::map kPedTypes = { - {"Triad", 12}, {"Cop", 1}, {"SWAT", 2}, - {"FBI", 3}, {"Fireman", 6}, {"Construction", 74}, - }; + static constexpr std::array, 6> + kPedTypes{{ + {"Triad", 12}, + {"Cop", 1}, + {"SWAT", 2}, + {"FBI", 3}, + {"Fireman", 6}, + {"Construction", 74}, + }}; - for (auto& e : kPedTypes) { - menu->lambda(e.first + " Follower", [=] { spawnFollower(e.second); }); + for (const auto& [name, id] : kPedTypes) { + menu->lambda(name, [this, id = id] { spawnFollower(id); }); } menu->lambda("Kill All Peds", [=] { - for (auto& p : game->getWorld()->pedestrianPool.objects) { - if (p.second->getLifetime() == GameObject::PlayerLifetime) { + for (auto& [id, pedestrianPtr] : + game->getWorld()->pedestrianPool.objects) { + if (pedestrianPtr->getLifetime() == GameObject::PlayerLifetime) { continue; } - p.second->takeDamage({p.second->getPosition(), - p.second->getPosition(), 100.f, - GameObject::DamageInfo::Explosion, 0.f}); + pedestrianPtr->takeDamage({pedestrianPtr->getPosition(), + pedestrianPtr->getPosition(), 100.f, + GameObject::DamageInfo::Explosion, 0.f}); } }); @@ -214,7 +231,7 @@ std::shared_ptr DebugState::createWeatherMenu() { Menu::create({{"Back", [=] { this->enterMenu(createDebugMenu()); }}}, kDebugFont, kDebugEntryHeight); - const std::array w{{"Sunny", "Cloudy", "Rainy", "Foggy"}}; + static constexpr std::array w{{"Sunny", "Cloudy", "Rainy", "Foggy"}}; for (std::size_t i = 0; i < w.size(); ++i) { menu->lambda(w[i], @@ -230,7 +247,7 @@ std::shared_ptr DebugState::createMissionsMenu() { Menu::create({{"Back", [=] { this->enterMenu(createDebugMenu()); }}}, kDebugFont, kDebugEntryHeightMissions); - const std::array w{{ + static constexpr std::array w{{ "Intro Movie", "Hospital Info Scene", "Police Station Info Scene",