diff --git a/extensions/advanced_ballistics/AdvancedBallistics.cpp b/extensions/advanced_ballistics/AdvancedBallistics.cpp index 6e964f8921..554c21b601 100644 --- a/extensions/advanced_ballistics/AdvancedBallistics.cpp +++ b/extensions/advanced_ballistics/AdvancedBallistics.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #define M_PI 3.14159265358979323846f @@ -57,7 +57,7 @@ struct Map { }; std::vector bulletDatabase; -std::map mapDatabase; +std::unordered_map mapDatabase; std::string worldName = ""; Map* map = &mapDatabase[""]; @@ -339,10 +339,8 @@ void __stdcall RVExtension(char *output, int outputSize, const char *function) tickTime = strtod(strtok_s(NULL, ":", &next_token), NULL); tickTime += strtod(strtok_s(NULL, ":", &next_token), NULL); - while (index >= bulletDatabase.size()) { - Bullet bullet; - bulletDatabase.push_back(bullet); - } + if (index >= bulletDatabase.size()) + bulletDatabase.resize(index); bulletDatabase[index].airFriction = airFriction; bulletDatabase[index].ballisticCoefficients = ballisticCoefficients; @@ -611,8 +609,12 @@ void __stdcall RVExtension(char *output, int outputSize, const char *function) mapGrids = (int)ceil((double)mapSize / 50.0) + 1; gridCells = mapGrids * mapGrids; + + auto map_iter = mapDatabase.find(worldName); + if (map_iter == mapDatabase.end()) + return; + map = &map_iter->second; - map = &mapDatabase[worldName]; if (map->gridHeights.size() == gridCells) { int n = sprintf_s(output, outputSize, "%s", "Terrain already initialized"); return;