mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-08-31 08:26:14 +02:00
Update to v098r08 release.
byuu says: Changelog: - nall/vector rewritten from scratch - higan/audio uses nall/vector instead of raw pointers - higan/sfc/coprocessor/sdd1 updated with new research information - ruby/video/glx and ruby/video/glx2: fuck salt glXSwapIntervalEXT! The big change here is definitely nall/vector. The Windows, OS X and Qt ports won't compile until you change some first/last strings to left/right, but GTK will compile. I'd be really grateful if anyone could stress-test nall/vector. Pretty much everything I do relies on this class. If we introduce a bug, the worst case scenario is my entire SFC game dump database gets corrupted, or the byuu.org server gets compromised. So it's really critical that we test the hell out of this right now. The S-DD1 changes mean you need to update your installation of icarus again. Also, even though the Lunar FMV never really worked on the accuracy core anyway (it didn't initialize the PPU properly), it really won't work now that we emulate the hard-limit of 16MiB for S-DD1 games.
This commit is contained in:
39
nall/vector/access.hpp
Normal file
39
nall/vector/access.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
namespace nall {
|
||||
|
||||
template<typename T> auto vector<T>::operator[](uint offset) -> T& {
|
||||
return _pool[offset];
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::operator[](uint offset) const -> const T& {
|
||||
return _pool[offset];
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::operator()(uint offset) -> T& {
|
||||
while(offset >= size()) append(T());
|
||||
return _pool[offset];
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::operator()(uint offset, const T& value) const -> const T& {
|
||||
if(offset >= size()) return value;
|
||||
return _pool[offset];
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::left() -> T& {
|
||||
return _pool[0];
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::left() const -> const T& {
|
||||
return _pool[0];
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::right() -> T& {
|
||||
return _pool[_size - 1];
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::right() const -> const T& {
|
||||
return _pool[_size - 1];
|
||||
}
|
||||
|
||||
}
|
28
nall/vector/assign.hpp
Normal file
28
nall/vector/assign.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
namespace nall {
|
||||
|
||||
template<typename T> auto vector<T>::operator=(const vector<T>& source) -> vector<T>& {
|
||||
if(this == &source) return *this;
|
||||
_pool = (T*)memory::allocate(sizeof(T) * source._size);
|
||||
_size = source._size;
|
||||
_left = 0;
|
||||
_right = 0;
|
||||
for(uint n : range(_size)) new(_pool + n) T(source._pool[n]);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::operator=(vector<T>&& source) -> vector<T>& {
|
||||
if(this == &source) return *this;
|
||||
_pool = source._pool;
|
||||
_size = source._size;
|
||||
_left = source._left;
|
||||
_right = source._right;
|
||||
source._pool = nullptr;
|
||||
source._size = 0;
|
||||
source._left = 0;
|
||||
source._right = 0;
|
||||
return *this;
|
||||
}
|
||||
|
||||
}
|
42
nall/vector/core.hpp
Normal file
42
nall/vector/core.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
namespace nall {
|
||||
|
||||
template<typename T> vector<T>::vector(const initializer_list<T>& values) {
|
||||
reserveRight(values.size());
|
||||
for(auto& value : values) append(value);
|
||||
}
|
||||
|
||||
template<typename T> vector<T>::vector(const vector<T>& source) {
|
||||
operator=(source);
|
||||
}
|
||||
|
||||
template<typename T> vector<T>::vector(vector<T>&& source) {
|
||||
operator=(move(source));
|
||||
}
|
||||
|
||||
template<typename T> vector<T>::~vector() {
|
||||
reset();
|
||||
}
|
||||
|
||||
template<typename T> vector<T>::operator bool() const {
|
||||
return _size;
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::capacity() const -> uint {
|
||||
return _left + _size + _right;
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::size() const -> uint {
|
||||
return _size;
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::data() -> T* {
|
||||
return _pool;
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::data() const -> const T* {
|
||||
return _pool;
|
||||
}
|
||||
|
||||
}
|
37
nall/vector/iterator.hpp
Normal file
37
nall/vector/iterator.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
namespace nall {
|
||||
|
||||
template<typename T>
|
||||
struct vector_iterator {
|
||||
vector_iterator(vector<T>& self, uint offset) : self(self), offset(offset) {}
|
||||
auto operator*() -> T& { return self.operator[](offset); }
|
||||
auto operator!=(const vector_iterator& source) const -> bool { return offset != source.offset; }
|
||||
auto operator++() -> vector_iterator& { return offset++, *this; }
|
||||
|
||||
private:
|
||||
vector<T>& self;
|
||||
uint offset;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct vector_iterator_const {
|
||||
vector_iterator_const(const vector<T>& self, uint offset) : self(self), offset(offset) {}
|
||||
auto operator*() -> const T& { return self.operator[](offset); }
|
||||
auto operator!=(const vector_iterator_const& source) const -> bool { return offset != source.offset; }
|
||||
auto operator++() -> vector_iterator_const& { return offset++, *this; }
|
||||
|
||||
private:
|
||||
const vector<T>& self;
|
||||
uint offset;
|
||||
};
|
||||
|
||||
template<typename T> inline auto range(const vector<T>& container) {
|
||||
return range_t{0, (int)container.size(), 1};
|
||||
}
|
||||
|
||||
template<typename T> inline auto rrange(const vector<T>& container) {
|
||||
return range_t{(int)container.size() - 1, -1, -1};
|
||||
}
|
||||
|
||||
}
|
90
nall/vector/memory.hpp
Normal file
90
nall/vector/memory.hpp
Normal file
@@ -0,0 +1,90 @@
|
||||
#pragma once
|
||||
|
||||
namespace nall {
|
||||
|
||||
template<typename T> auto vector<T>::reset() -> void {
|
||||
if(!_pool) return;
|
||||
|
||||
for(uint n : range(_size)) _pool[n].~T();
|
||||
memory::free(_pool - _left);
|
||||
|
||||
_pool = nullptr;
|
||||
_size = 0;
|
||||
_left = 0;
|
||||
_right = 0;
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::release() -> T* {
|
||||
auto pool = _pool;
|
||||
_pool = nullptr;
|
||||
_size = 0;
|
||||
_left = 0;
|
||||
_right = 0;
|
||||
return pool;
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::reserveLeft(uint capacity) -> bool {
|
||||
if(_size + _left >= capacity) return false;
|
||||
|
||||
uint left = bit::round(capacity);
|
||||
auto pool = (T*)memory::allocate(sizeof(T) * (left + _right)) + left;
|
||||
for(uint n : range(_size)) new(pool + n) T(move(_pool[n]));
|
||||
memory::free(_pool - _left);
|
||||
|
||||
_pool = pool;
|
||||
_left = left - _size;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::reserveRight(uint capacity) -> bool {
|
||||
if(_size + _right >= capacity) return false;
|
||||
|
||||
uint right = bit::round(capacity);
|
||||
auto pool = (T*)memory::allocate(sizeof(T) * (_left + right)) + _left;
|
||||
for(uint n : range(_size)) new(pool + n) T(move(_pool[n]));
|
||||
memory::free(_pool - _left);
|
||||
|
||||
_pool = pool;
|
||||
_right = right - _size;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::resizeLeft(uint size, const T& value) -> bool {
|
||||
if(size < _size) { //shrink
|
||||
for(uint n : range(_size - size)) _pool[n].~T();
|
||||
_pool += _size - size;
|
||||
_left += _size - size;
|
||||
_size = size;
|
||||
return true;
|
||||
}
|
||||
if(size > _size) { //grow
|
||||
reserveLeft(size);
|
||||
_pool -= size - _size;
|
||||
for(uint n : rrange(size - _size)) new(_pool + n) T(value);
|
||||
_left -= size - _size;
|
||||
_size = size;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::resizeRight(uint size, const T& value) -> bool {
|
||||
if(size < _size) { //shrink
|
||||
for(uint n = size; n < _size; n++) _pool[n].~T();
|
||||
_right += _size - size;
|
||||
_size = size;
|
||||
return true;
|
||||
}
|
||||
if(size > _size) { //grow
|
||||
reserveRight(size);
|
||||
for(uint n = _size; n < size; n++) new(_pool + n) T(value);
|
||||
_right -= size - _size;
|
||||
_size = size;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
127
nall/vector/modify.hpp
Normal file
127
nall/vector/modify.hpp
Normal file
@@ -0,0 +1,127 @@
|
||||
#pragma once
|
||||
|
||||
namespace nall {
|
||||
|
||||
template<typename T> auto vector<T>::prepend(const T& value) -> void {
|
||||
reserveLeft(size() + 1);
|
||||
new(--_pool) T(value);
|
||||
_left--;
|
||||
_size++;
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::prepend(T&& value) -> void {
|
||||
reserveLeft(size() + 1);
|
||||
new(--_pool) T(move(value));
|
||||
_left--;
|
||||
_size++;
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::prepend(const vector<T>& values) -> void {
|
||||
reserveLeft(size() + values.size());
|
||||
_pool -= values.size();
|
||||
for(uint n : range(values)) new(_pool + n) T(values[n]);
|
||||
_left -= values.size();
|
||||
_size += values.size();
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::prepend(vector<T>&& values) -> void {
|
||||
reserveLeft(size() + values.size());
|
||||
_pool -= values.size();
|
||||
for(uint n : range(values)) new(_pool + n) T(move(values[n]));
|
||||
_left -= values.size();
|
||||
_size += values.size();
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
template<typename T> auto vector<T>::append(const T& value) -> void {
|
||||
reserveRight(size() + 1);
|
||||
new(_pool + _size) T(value);
|
||||
_right--;
|
||||
_size++;
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::append(T&& value) -> void {
|
||||
reserveRight(size() + 1);
|
||||
new(_pool + _size) T(move(value));
|
||||
_right--;
|
||||
_size++;
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::append(const vector<T>& values) -> void {
|
||||
reserveRight(size() + values.size());
|
||||
for(uint n : range(values)) new(_pool + _size + n) T(values[n]);
|
||||
_right -= values.size();
|
||||
_size += values.size();
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::append(vector<T>&& values) -> void {
|
||||
reserveRight(size() + values.size());
|
||||
for(uint n : range(values)) new(_pool + _size + n) T(move(values[n]));
|
||||
_right -= values.size();
|
||||
_size += values.size();
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
template<typename T> auto vector<T>::insert(uint offset, const T& value) -> void {
|
||||
if(offset == 0) return prepend(value);
|
||||
if(offset == size() - 1) return append(value);
|
||||
reserveRight(size() + 1);
|
||||
_size++;
|
||||
for(int n = size() - 1; n > offset; n--) {
|
||||
_pool[n] = move(_pool[n - 1]);
|
||||
}
|
||||
new(_pool + offset) T(value);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
template<typename T> auto vector<T>::removeLeft(uint length) -> void {
|
||||
if(length > size()) length = size();
|
||||
resizeLeft(size() - length);
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::removeRight(uint length) -> void {
|
||||
if(length > size()) length = size();
|
||||
resizeRight(size() - length);
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::remove(uint offset, uint length) -> void {
|
||||
if(offset == 0) return removeLeft(length);
|
||||
if(offset == size() - 1) return removeRight(length);
|
||||
|
||||
for(uint n = offset; n < size(); n++) {
|
||||
if(n + length < size()) {
|
||||
_pool[n] = move(_pool[n + length]);
|
||||
} else {
|
||||
_pool[n].~T();
|
||||
}
|
||||
}
|
||||
_size -= length;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
template<typename T> auto vector<T>::takeLeft() -> T {
|
||||
T value = move(_pool[0]);
|
||||
removeLeft();
|
||||
return value;
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::takeRight() -> T {
|
||||
T value = move(_pool[size() - 1]);
|
||||
removeRight();
|
||||
return value;
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::take(uint offset) -> T {
|
||||
if(offset == 0) return takeLeft();
|
||||
if(offset == size() - 1) return takeRight();
|
||||
|
||||
T value = move(_pool[offset]);
|
||||
remove(offset);
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
15
nall/vector/utility.hpp
Normal file
15
nall/vector/utility.hpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
namespace nall {
|
||||
|
||||
template<typename T> auto vector<T>::sort(const function<bool (const T& lhs, const T& rhs)>& comparator) -> void {
|
||||
if(!comparator) return nall::sort(_pool, _size, [](const T& lhs, const T& rhs) { return lhs < rhs; });
|
||||
nall::sort(_pool, _size, comparator);
|
||||
}
|
||||
|
||||
template<typename T> auto vector<T>::find(const T& value) const -> maybe<uint> {
|
||||
for(uint n : range(size())) if(_pool[n] == value) return n;
|
||||
return nothing;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user