mirror of
https://github.com/libretro/bsnes-libretro.git
synced 2024-11-27 11:00:47 +00:00
d87a0f633d
byuu says: - bsnes: added video filters from bsnes v082 - bsnes: added ZSNES snow effect option when games paused or unloaded (no, I'm not joking) - bsnes: added 7-zip support (LZMA 19.00 SDK) [Recent higan WIPs have also mentioned bsnes changes, although the higan code no longer includes the bsnes code. These changes include: - higan, bsnes: added EXLOROM, EXLOROM-RAM, EXHIROM mappings - higan, bsnes: focus the viewport after leaving fullscreen exclusive mode - bsnes: re-added mightymo's cheat code database - bsnes: improved make install rules for the game and cheat code databases - bsnes: delayed construction of hiro::Window objects to properly show bsnes window icons - Ed.]
90 lines
2.1 KiB
C++
90 lines
2.1 KiB
C++
#pragma once
|
|
|
|
#include <nall/array-span.hpp>
|
|
#include <nall/array-view.hpp>
|
|
#include <nall/range.hpp>
|
|
#include <nall/view.hpp>
|
|
|
|
namespace nall {
|
|
|
|
template<typename T> struct array;
|
|
|
|
//usage: int x[256] => array<int[256]> x
|
|
template<typename T, uint Size> struct array<T[Size]> {
|
|
array() = default;
|
|
|
|
array(const initializer_list<T>& source) {
|
|
uint index = 0;
|
|
for(auto& value : source) {
|
|
operator[](index++) = value;
|
|
}
|
|
}
|
|
|
|
operator array_span<T>() {
|
|
return {data(), size()};
|
|
}
|
|
|
|
operator array_view<T>() const {
|
|
return {data(), size()};
|
|
}
|
|
|
|
alwaysinline auto operator[](uint index) -> T& {
|
|
#ifdef DEBUG
|
|
struct out_of_bounds {};
|
|
if(index >= Size) throw out_of_bounds{};
|
|
#endif
|
|
return values[index];
|
|
}
|
|
|
|
alwaysinline auto operator[](uint index) const -> const T& {
|
|
#ifdef DEBUG
|
|
struct out_of_bounds {};
|
|
if(index >= Size) throw out_of_bounds{};
|
|
#endif
|
|
return values[index];
|
|
}
|
|
|
|
alwaysinline auto operator()(uint index, const T& fallback = {}) const -> const T& {
|
|
if(index >= Size) return fallback;
|
|
return values[index];
|
|
}
|
|
|
|
auto fill(const T& fill = {}) -> array& {
|
|
for(auto& value : values) value = fill;
|
|
return *this;
|
|
}
|
|
|
|
auto data() -> T* { return values; }
|
|
auto data() const -> const T* { return values; }
|
|
auto size() const -> uint { return Size; }
|
|
|
|
auto begin() -> T* { return &values[0]; }
|
|
auto end() -> T* { return &values[Size]; }
|
|
|
|
auto begin() const -> const T* { return &values[0]; }
|
|
auto end() const -> const T* { return &values[Size]; }
|
|
|
|
private:
|
|
T values[Size];
|
|
};
|
|
|
|
template<typename T, T... p> auto from_array(uint index) -> T {
|
|
static const array<T[sizeof...(p)]> table{p...};
|
|
struct out_of_bounds {};
|
|
#if defined(DEBUG)
|
|
if(index >= sizeof...(p)) throw out_of_bounds{};
|
|
#endif
|
|
return table[index];
|
|
}
|
|
|
|
template<int64_t... p> auto from_array(uint index) -> int64_t {
|
|
static const array<int64_t[sizeof...(p)]> table{p...};
|
|
struct out_of_bounds {};
|
|
#if defined(DEBUG)
|
|
if(index >= sizeof...(p)) throw out_of_bounds{};
|
|
#endif
|
|
return table[index];
|
|
}
|
|
|
|
}
|