Replace custom FixedVector with sfl::static_vector

This commit is contained in:
ζeh Matt 2024-12-02 02:21:52 +02:00
parent e8c7a8909a
commit b0fc76fdd0
No known key found for this signature in database
GPG key ID: 18CE582C71A225B0
5 changed files with 7 additions and 186 deletions

View file

@ -11,12 +11,12 @@
#include <openrct2/audio/AudioChannel.h>
#include <openrct2/audio/AudioMixer.h>
#include <openrct2/audio/audio.h>
#include <openrct2/core/FixedVector.h>
#include <openrct2/entity/EntityRegistry.h>
#include <openrct2/profiling/Profiling.h>
#include <openrct2/ride/TrainManager.h>
#include <openrct2/ride/Vehicle.h>
#include <openrct2/world/tile_element/SurfaceElement.h>
#include <sfl/static_vector.hpp>
namespace OpenRCT2::Audio
{
@ -236,7 +236,7 @@ namespace OpenRCT2::Audio
* rct2: 0x006BB9FF
*/
static void UpdateSoundParams(
const Vehicle& vehicle, FixedVector<VehicleSoundParams, kMaxVehicleSounds>& vehicleSoundParamsList)
const Vehicle& vehicle, sfl::static_vector<VehicleSoundParams, kMaxVehicleSounds>& vehicleSoundParamsList)
{
if (!SoundCanPlay(vehicle))
return;
@ -536,7 +536,7 @@ namespace OpenRCT2::Audio
if (!IsAvailable())
return;
FixedVector<VehicleSoundParams, kMaxVehicleSounds> vehicleSoundParamsList;
sfl::static_vector<VehicleSoundParams, kMaxVehicleSounds> vehicleSoundParamsList;
VehicleSoundsUpdateWindowSetup();

View file

@ -1,178 +0,0 @@
/*****************************************************************************
* Copyright (c) 2014-2024 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#pragma once
#include "Guard.hpp"
#include <algorithm>
#include <array>
#include <utility>
template<typename T, size_t MAX>
class FixedVector
{
public:
using container = std::array<T, MAX>;
using iterator = typename container::iterator;
using const_iterator = typename container::const_iterator;
using reverse_iterator = typename container::reverse_iterator;
using const_reverse_iterator = typename container::const_reverse_iterator;
using value_type = typename container::value_type;
using reference_type = value_type&;
using const_reference_type = const value_type&;
constexpr iterator begin()
{
if (_count == 0)
return _data.end();
return _data.begin();
}
constexpr iterator end()
{
if (_count == 0)
return _data.end();
return begin() + _count;
}
constexpr const_iterator cbegin() const
{
if (_count == 0)
return _data.cend();
return _data.cbegin();
}
constexpr const_iterator cend() const
{
if (_count == 0)
return _data.cend();
return cbegin() + _count;
}
constexpr reverse_iterator rbegin()
{
if (_count == 0)
return _data.rend();
return _data.rbegin() + (MAX - _count);
}
constexpr reverse_iterator rend()
{
return _data.rend();
}
constexpr const_reverse_iterator rbegin() const
{
return _data.rbegin() + (MAX - _count);
}
constexpr const_reverse_iterator rend() const
{
return _data.rend();
}
constexpr reference_type back()
{
return _data[_count - 1];
}
constexpr const_reference_type back() const
{
return _data[_count - 1];
}
constexpr void push_back(const T& val)
{
OpenRCT2::Guard::Assert(_count < MAX);
_data[_count++] = val;
}
constexpr void push_back(T&& val)
{
OpenRCT2::Guard::Assert(_count < MAX);
_data[_count++] = std::move(val);
}
constexpr iterator insert(iterator pos, const T& val)
{
// Make sure the end iterator is correct.
auto itCurEnd = end();
push_back(val);
// Shift all elements to the right
auto offset = pos - begin();
std::rotate(_data.begin(), pos, itCurEnd);
return _data.begin() + offset;
}
constexpr iterator insert(iterator pos, T&& val)
{
// Make sure the end iterator is correct.
auto itCurEnd = end();
emplace_back(std::move(val));
// Shift all elements to the right
auto offset = pos - begin();
std::rotate(_data.begin() + offset, itCurEnd, end());
return _data.begin() + offset;
}
template<typename... Args>
constexpr reference_type emplace_back(Args&&... args)
{
OpenRCT2::Guard::Assert(_count < MAX);
reference_type res = _data[_count++];
::new (&res) T(std::forward<Args&&>(args)...);
return res;
}
constexpr reference_type operator[](const size_t n)
{
return _data[n];
}
constexpr const_reference_type operator[](const size_t n) const
{
return _data[n];
}
constexpr void pop_back()
{
_count--;
}
constexpr void clear()
{
_count = 0;
}
constexpr size_t size() const
{
return _count;
}
constexpr size_t capacity() const
{
return _data.size();
}
constexpr bool empty() const
{
return _count == 0;
}
private:
size_t _count = 0;
container _data;
};

View file

@ -203,7 +203,6 @@
<ClInclude Include="core\FileSystem.hpp" />
<ClInclude Include="core\FileWatcher.h" />
<ClInclude Include="core\FixedPoint.hpp" />
<ClInclude Include="core\FixedVector.h" />
<ClInclude Include="core\FlagHolder.hpp" />
<ClInclude Include="core\GroupVector.hpp" />
<ClInclude Include="core\Guard.hpp" />
@ -1135,4 +1134,4 @@
</ClCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>
</Project>

View file

@ -25,7 +25,6 @@
#include "../audio/audio.h"
#include "../config/Config.h"
#include "../core/BitSet.hpp"
#include "../core/FixedVector.h"
#include "../core/Guard.hpp"
#include "../core/Numerics.hpp"
#include "../entity/EntityRegistry.h"
@ -84,6 +83,7 @@
#include <iterator>
#include <limits>
#include <optional>
#include <sfl/static_vector.hpp>
using namespace OpenRCT2;
using namespace OpenRCT2::TrackMetaData;

View file

@ -18,7 +18,6 @@
#include "../actions/RideSetStatusAction.h"
#include "../actions/RideSetVehicleAction.h"
#include "../actions/TrackRemoveAction.h"
#include "../core/FixedVector.h"
#include "../entity/EntityList.h"
#include "../entity/EntityRegistry.h"
#include "../entity/Staff.h"
@ -50,6 +49,7 @@
#include "Vehicle.h"
#include <cassert>
#include <sfl/static_vector.hpp>
using namespace OpenRCT2;
using namespace OpenRCT2::TrackMetaData;
@ -1255,7 +1255,7 @@ void Ride::ValidateStations()
}
}
// determine what entrances and exits exist
FixedVector<TileCoordsXYZD, MAX_STATION_LOCATIONS> locations;
sfl::static_vector<TileCoordsXYZD, MAX_STATION_LOCATIONS> locations;
for (auto& station : stations)
{
if (!station.Entrance.IsNull())