Switch to std::span (#3376)

Now that we have cpp20 we can ditch nonstd::span.

Depends on #3375
This commit is contained in:
Ziemas 2024-02-18 19:23:19 +01:00 committed by GitHub
parent 0011fb4b2b
commit 4e569f0115
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 32 additions and 1917 deletions

View file

@ -31,10 +31,15 @@ jobs:
run: | run: |
sudo apt update sudo apt update
sudo apt install build-essential cmake \ sudo apt install build-essential cmake \
clang gcc g++ lcov make nasm libxrandr-dev \ clang gcc-10 g++-10 lcov make nasm libxrandr-dev \
libxinerama-dev libxcursor-dev libpulse-dev \ libxinerama-dev libxcursor-dev libpulse-dev \
libxi-dev zip ninja-build libgl1-mesa-dev libssl-dev libxi-dev zip ninja-build libgl1-mesa-dev libssl-dev
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 100
sudo update-alternatives --set gcc /usr/bin/gcc-10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 100
sudo update-alternatives --set g++ /usr/bin/g++-10
- name: Setup Buildcache - name: Setup Buildcache
uses: mikehardy/buildcache-action@v2.1.0 uses: mikehardy/buildcache-action@v2.1.0
with: with:

View file

@ -7,16 +7,15 @@
#include <cstdint> #include <cstdint>
#include <cstring> #include <cstring>
#include <span>
#include <vector> #include <vector>
#include "common/common_types.h" #include "common/common_types.h"
#include "common/util/Assert.h" #include "common/util/Assert.h"
#include "third-party/span.hpp"
class BinaryReader { class BinaryReader {
public: public:
explicit BinaryReader(nonstd::span<const uint8_t> _span) : m_span(_span) {} explicit BinaryReader(std::span<const uint8_t> _span) : m_span(_span) {}
template <typename T> template <typename T>
T read() { T read() {
@ -39,6 +38,6 @@ class BinaryReader {
void set_seek(u32 seek) { m_seek = seek; } void set_seek(u32 seek) { m_seek = seek; }
private: private:
nonstd::span<const u8> m_span; std::span<const u8> m_span;
uint32_t m_seek = 0; uint32_t m_seek = 0;
}; };

View file

@ -210,7 +210,7 @@ struct AudioFileInfo {
}; };
AudioFileInfo process_audio_file(const fs::path& output_folder, AudioFileInfo process_audio_file(const fs::path& output_folder,
nonstd::span<const uint8_t> data, std::span<const uint8_t> data,
const std::string& name, const std::string& name,
const std::string& suffix, const std::string& suffix,
bool stereo) { bool stereo) {
@ -276,7 +276,7 @@ void process_streamed_audio(const decompiler::Config& config,
} }
lg::info("File {}, total {:.2f} minutes", entry.name, audio_len / 60.0); lg::info("File {}, total {:.2f} minutes", entry.name, audio_len / 60.0);
auto data = nonstd::span(wad_data).subspan(entry.start_byte); auto data = std::span(wad_data).subspan(entry.start_byte);
auto info = process_audio_file(output_path, data, entry.name, suffix, entry.stereo); auto info = process_audio_file(output_path, data, entry.name, suffix, entry.stereo);
audio_len += info.length_seconds; audio_len += info.length_seconds;
filename_data[i][lang_id + 1] = info.filename; filename_data[i][lang_id + 1] = info.filename;

View file

@ -191,7 +191,7 @@ static Grain ReadGrainV2(BinaryReader& data, BinaryReader grainData, u8* samples
return grain; return grain;
}; };
SFXBlock* SFXBlock::ReadBlock(nonstd::span<u8> bank_data, nonstd::span<u8> samples) { SFXBlock* SFXBlock::ReadBlock(std::span<u8> bank_data, std::span<u8> samples) {
BinaryReader data(bank_data); BinaryReader data(bank_data);
// auto block = std::make_unique<SFXBlock>(); // auto block = std::make_unique<SFXBlock>();
auto block = new SFXBlock(); auto block = new SFXBlock();
@ -313,9 +313,9 @@ SFXBlock* SFXBlock::ReadBlock(nonstd::span<u8> bank_data, nonstd::span<u8> sampl
return block; return block;
} }
MusicBank* MusicBank::ReadBank(nonstd::span<u8> bank_data, MusicBank* MusicBank::ReadBank(std::span<u8> bank_data,
nonstd::span<u8> samples, std::span<u8> samples,
nonstd::span<u8> midi_data) { std::span<u8> midi_data) {
BinaryReader data(bank_data); BinaryReader data(bank_data);
// auto bank = std::make_unique<MusicBank>(); // auto bank = std::make_unique<MusicBank>();
auto bank = new MusicBank(); auto bank = new MusicBank();
@ -388,7 +388,7 @@ MusicBank* MusicBank::ReadBank(nonstd::span<u8> bank_data,
} }
} }
auto seq_buf = nonstd::span<u8>(bank->SeqData.get(), midi_data.size_bytes()); auto seq_buf = std::span<u8>(bank->SeqData.get(), midi_data.size_bytes());
BinaryReader seq_data(seq_buf); BinaryReader seq_data(seq_buf);
FileAttributes fa; FileAttributes fa;
fa.Read(seq_data); fa.Read(seq_data);
@ -407,7 +407,7 @@ MusicBank* MusicBank::ReadBank(nonstd::span<u8> bank_data,
return bank; return bank;
} }
BankHandle Loader::BankLoad(nonstd::span<u8> bank) { BankHandle Loader::BankLoad(std::span<u8> bank) {
BinaryReader reader(bank); BinaryReader reader(bank);
FileAttributes fa; FileAttributes fa;
fa.Read(reader); fa.Read(reader);
@ -419,17 +419,15 @@ BankHandle Loader::BankLoad(nonstd::span<u8> bank) {
reader.set_seek(fa.where[0].offset); reader.set_seek(fa.where[0].offset);
u32 fourcc = reader.read<u32>(); u32 fourcc = reader.read<u32>();
nonstd::span<u8> bank_data(nonstd::span<u8>(bank).subspan(fa.where[0].offset, fa.where[0].size)); std::span<u8> bank_data(std::span<u8>(bank).subspan(fa.where[0].offset, fa.where[0].size));
nonstd::span<u8> sample_data( std::span<u8> sample_data(std::span<u8>(bank).subspan(fa.where[1].offset, fa.where[1].size));
nonstd::span<u8>(bank).subspan(fa.where[1].offset, fa.where[1].size));
if (fourcc == snd::fourcc("SBv2")) { if (fourcc == snd::fourcc("SBv2")) {
if (fa.num_chunks != 3) { if (fa.num_chunks != 3) {
fmt::print("SBv2 without midi data not supported\n"); fmt::print("SBv2 without midi data not supported\n");
return 0; return 0;
} }
nonstd::span<u8> midi_data( std::span<u8> midi_data(std::span<u8>(bank).subspan(fa.where[2].offset, fa.where[2].size));
nonstd::span<u8>(bank).subspan(fa.where[2].offset, fa.where[2].size));
auto bank = MusicBank::ReadBank(bank_data, sample_data, midi_data); auto bank = MusicBank::ReadBank(bank_data, sample_data, midi_data);
mBanks.emplace_back(bank); mBanks.emplace_back(bank);

View file

@ -3,6 +3,7 @@
#pragma once #pragma once
#include <memory> #include <memory>
#include <span>
#include <vector> #include <vector>
#include "soundbank.h" #include "soundbank.h"
@ -10,8 +11,6 @@
#include "common/common_types.h" #include "common/common_types.h"
#include "common/util/BinaryReader.h" #include "common/util/BinaryReader.h"
#include "third-party/span.hpp"
namespace snd { namespace snd {
using BankHandle = SoundBank*; using BankHandle = SoundBank*;
@ -37,7 +36,7 @@ class Loader {
void UnloadBank(BankHandle id); void UnloadBank(BankHandle id);
BankHandle BankLoad(nonstd::span<u8> bank); BankHandle BankLoad(std::span<u8> bank);
private: private:
std::vector<std::unique_ptr<SoundBank>> mBanks; std::vector<std::unique_ptr<SoundBank>> mBanks;

View file

@ -1,11 +1,10 @@
#pragma once #pragma once
#include <span>
#include <variant> #include <variant>
#include <vector> #include <vector>
#include "soundbank.h" #include "soundbank.h"
#include "third-party/span.hpp"
namespace snd { namespace snd {
struct Midi { struct Midi {
@ -63,9 +62,9 @@ class MusicBank : public SoundBank {
std::unique_ptr<u8[]> SeqData; std::unique_ptr<u8[]> SeqData;
std::variant<Midi, MultiMidi> MidiData; std::variant<Midi, MultiMidi> MidiData;
static MusicBank* ReadBank(nonstd::span<u8> bank_data, static MusicBank* ReadBank(std::span<u8> bank_data,
nonstd::span<u8> samples, std::span<u8> samples,
nonstd::span<u8> midi_data); std::span<u8> midi_data);
std::optional<std::unique_ptr<SoundHandler>> MakeHandler(VoiceManager& vm, std::optional<std::unique_ptr<SoundHandler>> MakeHandler(VoiceManager& vm,
u32 sound_id, u32 sound_id,

View file

@ -233,7 +233,7 @@ void Player::SetMasterVolume(u32 group, s32 volume) {
} }
} }
BankHandle Player::LoadBank(nonstd::span<u8> bank) { BankHandle Player::LoadBank(std::span<u8> bank) {
std::scoped_lock lock(mTickLock); std::scoped_lock lock(mTickLock);
return mLoader.BankLoad(bank); return mLoader.BankLoad(bank);
} }

View file

@ -4,6 +4,7 @@
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <span>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
@ -18,7 +19,6 @@
#include "game/sound/989snd/vagvoice.h" #include "game/sound/989snd/vagvoice.h"
#include "third-party/cubeb/cubeb/include/cubeb/cubeb.h" #include "third-party/cubeb/cubeb/include/cubeb/cubeb.h"
#include "third-party/span.hpp"
namespace snd { namespace snd {
@ -32,7 +32,7 @@ class Player {
// player(player&& other) noexcept = default; // player(player&& other) noexcept = default;
// player& operator=(player&& other) noexcept = default; // player& operator=(player&& other) noexcept = default;
BankHandle LoadBank(nonstd::span<u8> bank); BankHandle LoadBank(std::span<u8> bank);
u32 PlaySound(BankHandle bank, u32 sound, s32 vol, s32 pan, s32 pm, s32 pb); u32 PlaySound(BankHandle bank, u32 sound, s32 vol, s32 pan, s32 pm, s32 pb);
u32 PlaySoundByName(BankHandle bank, u32 PlaySoundByName(BankHandle bank,

View file

@ -1,11 +1,10 @@
#pragma once #pragma once
#include <span>
#include <vector> #include <vector>
#include "sfxgrain.h" #include "sfxgrain.h"
#include "soundbank.h" #include "soundbank.h"
#include "third-party/span.hpp"
namespace snd { namespace snd {
struct SFXUserData { // 0x10 struct SFXUserData { // 0x10
@ -46,7 +45,7 @@ class SFXBlock : public SoundBank {
std::map<std::string, u32> Names; std::map<std::string, u32> Names;
std::unique_ptr<u8[]> SampleData; std::unique_ptr<u8[]> SampleData;
static SFXBlock* ReadBlock(nonstd::span<u8> bank_data, nonstd::span<u8> samples); static SFXBlock* ReadBlock(std::span<u8> bank_data, std::span<u8> samples);
std::optional<std::unique_ptr<SoundHandler>> MakeHandler(VoiceManager& vm, std::optional<std::unique_ptr<SoundHandler>> MakeHandler(VoiceManager& vm,
u32 sound_id, u32 sound_id,

View file

@ -214,7 +214,7 @@ snd::BankHandle snd_BankLoadEx(const char* filename,
if (player) { if (player) {
// TODO put the load on the thread pool? // TODO put the load on the thread pool?
auto file_buf = file_util::read_binary_file(std::string(filename)); auto file_buf = file_util::read_binary_file(std::string(filename));
return player->LoadBank(nonstd::span(file_buf).subspan(offset)); return player->LoadBank(std::span(file_buf).subspan(offset));
} else { } else {
return 0; return 0;
} }

1884
third-party/span.hpp generated vendored

File diff suppressed because it is too large Load diff