2016-05-02 09:57:04 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace nall {
|
|
|
|
|
Update to v106r59 release.
byuu says:
Changelog:
- fixed bug in Emulator::Game::Memory::operator bool()
- nall: renamed view<string> back to `string_view`
- nall:: implemented `array_view`
- Game Boy: split cartridge-specific input mappings (rumble,
accelerometer) to their own separate ports
- Game Boy: fixed MBC7 accelerometer x-axis
- icarus: Game Boy, Super Famicom, Mega Drive cores output internal
header game titles to heuristics manifests
- higan, icarus, hiro/gtk: improve viewport geometry configuration;
fixed higan crashing bug with XShm driver
- higan: connect Video::poll(),update() functionality
- hiro, ruby: several compilation / bugfixes, should get the macOS
port compiling again, hopefully [Sintendo]
- ruby/video/xshm: fix crashing bug on window resize
- a bit hacky; it's throwing BadAccess Xlib warnings, but they're
not fatal, so I am catching and ignoring them
- bsnes: removed Application::Windows::onModalChange hook that's no
longer needed [Screwtape]
2018-08-26 06:49:54 +00:00
|
|
|
//nall::vector acts internally as a deque (double-ended queue)
|
|
|
|
//it does this because it's essentially free to do so, only costing an extra integer in sizeof(vector)
|
|
|
|
|
2016-05-02 09:57:04 +00:00
|
|
|
template<typename T> auto vector<T>::reset() -> void {
|
|
|
|
if(!_pool) return;
|
|
|
|
|
2018-12-22 10:28:15 +00:00
|
|
|
for(uint64_t n : range(_size)) _pool[n].~T();
|
2016-05-02 09:57:04 +00:00
|
|
|
memory::free(_pool - _left);
|
|
|
|
|
|
|
|
_pool = nullptr;
|
|
|
|
_size = 0;
|
|
|
|
_left = 0;
|
|
|
|
_right = 0;
|
|
|
|
}
|
|
|
|
|
Update to v106r59 release.
byuu says:
Changelog:
- fixed bug in Emulator::Game::Memory::operator bool()
- nall: renamed view<string> back to `string_view`
- nall:: implemented `array_view`
- Game Boy: split cartridge-specific input mappings (rumble,
accelerometer) to their own separate ports
- Game Boy: fixed MBC7 accelerometer x-axis
- icarus: Game Boy, Super Famicom, Mega Drive cores output internal
header game titles to heuristics manifests
- higan, icarus, hiro/gtk: improve viewport geometry configuration;
fixed higan crashing bug with XShm driver
- higan: connect Video::poll(),update() functionality
- hiro, ruby: several compilation / bugfixes, should get the macOS
port compiling again, hopefully [Sintendo]
- ruby/video/xshm: fix crashing bug on window resize
- a bit hacky; it's throwing BadAccess Xlib warnings, but they're
not fatal, so I am catching and ignoring them
- bsnes: removed Application::Windows::onModalChange hook that's no
longer needed [Screwtape]
2018-08-26 06:49:54 +00:00
|
|
|
//acquire ownership of allocated memory
|
|
|
|
|
2021-05-26 01:25:40 +00:00
|
|
|
template<typename T> auto vector<T>::acquire(T* data, uint64_t size, uint64_t capacity) -> void {
|
Update to v106r59 release.
byuu says:
Changelog:
- fixed bug in Emulator::Game::Memory::operator bool()
- nall: renamed view<string> back to `string_view`
- nall:: implemented `array_view`
- Game Boy: split cartridge-specific input mappings (rumble,
accelerometer) to their own separate ports
- Game Boy: fixed MBC7 accelerometer x-axis
- icarus: Game Boy, Super Famicom, Mega Drive cores output internal
header game titles to heuristics manifests
- higan, icarus, hiro/gtk: improve viewport geometry configuration;
fixed higan crashing bug with XShm driver
- higan: connect Video::poll(),update() functionality
- hiro, ruby: several compilation / bugfixes, should get the macOS
port compiling again, hopefully [Sintendo]
- ruby/video/xshm: fix crashing bug on window resize
- a bit hacky; it's throwing BadAccess Xlib warnings, but they're
not fatal, so I am catching and ignoring them
- bsnes: removed Application::Windows::onModalChange hook that's no
longer needed [Screwtape]
2018-08-26 06:49:54 +00:00
|
|
|
reset();
|
|
|
|
_pool = data;
|
|
|
|
_size = size;
|
|
|
|
_left = 0;
|
|
|
|
_right = capacity ? capacity : size;
|
|
|
|
}
|
|
|
|
|
|
|
|
//release ownership of allocated memory
|
|
|
|
|
2016-05-02 09:57:04 +00:00
|
|
|
template<typename T> auto vector<T>::release() -> T* {
|
|
|
|
auto pool = _pool;
|
|
|
|
_pool = nullptr;
|
|
|
|
_size = 0;
|
|
|
|
_left = 0;
|
|
|
|
_right = 0;
|
|
|
|
return pool;
|
|
|
|
}
|
|
|
|
|
Update to v106r59 release.
byuu says:
Changelog:
- fixed bug in Emulator::Game::Memory::operator bool()
- nall: renamed view<string> back to `string_view`
- nall:: implemented `array_view`
- Game Boy: split cartridge-specific input mappings (rumble,
accelerometer) to their own separate ports
- Game Boy: fixed MBC7 accelerometer x-axis
- icarus: Game Boy, Super Famicom, Mega Drive cores output internal
header game titles to heuristics manifests
- higan, icarus, hiro/gtk: improve viewport geometry configuration;
fixed higan crashing bug with XShm driver
- higan: connect Video::poll(),update() functionality
- hiro, ruby: several compilation / bugfixes, should get the macOS
port compiling again, hopefully [Sintendo]
- ruby/video/xshm: fix crashing bug on window resize
- a bit hacky; it's throwing BadAccess Xlib warnings, but they're
not fatal, so I am catching and ignoring them
- bsnes: removed Application::Windows::onModalChange hook that's no
longer needed [Screwtape]
2018-08-26 06:49:54 +00:00
|
|
|
//reserve allocates memory for objects, but does not initialize them
|
|
|
|
//when the vector desired size is known, this can be used to avoid growing the capacity dynamically
|
|
|
|
//reserve will not actually shrink the capacity, only expand it
|
|
|
|
//shrinking the capacity would destroy objects, and break amortized growth with reallocate and resize
|
|
|
|
|
2018-12-22 10:28:15 +00:00
|
|
|
template<typename T> auto vector<T>::reserveLeft(uint64_t capacity) -> bool {
|
2016-05-02 09:57:04 +00:00
|
|
|
if(_size + _left >= capacity) return false;
|
|
|
|
|
2018-12-22 10:28:15 +00:00
|
|
|
uint64_t left = bit::round(capacity);
|
2018-05-28 01:16:27 +00:00
|
|
|
auto pool = memory::allocate<T>(left + _right) + (left - _size);
|
2018-12-22 10:28:15 +00:00
|
|
|
for(uint64_t n : range(_size)) new(pool + n) T(move(_pool[n]));
|
2016-05-02 09:57:04 +00:00
|
|
|
memory::free(_pool - _left);
|
|
|
|
|
|
|
|
_pool = pool;
|
|
|
|
_left = left - _size;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-12-22 10:28:15 +00:00
|
|
|
template<typename T> auto vector<T>::reserveRight(uint64_t capacity) -> bool {
|
2016-05-02 09:57:04 +00:00
|
|
|
if(_size + _right >= capacity) return false;
|
|
|
|
|
2018-12-22 10:28:15 +00:00
|
|
|
uint64_t right = bit::round(capacity);
|
2018-05-28 01:16:27 +00:00
|
|
|
auto pool = memory::allocate<T>(_left + right) + _left;
|
2018-12-22 10:28:15 +00:00
|
|
|
for(uint64_t n : range(_size)) new(pool + n) T(move(_pool[n]));
|
2016-05-02 09:57:04 +00:00
|
|
|
memory::free(_pool - _left);
|
|
|
|
|
|
|
|
_pool = pool;
|
|
|
|
_right = right - _size;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
Update to v106r59 release.
byuu says:
Changelog:
- fixed bug in Emulator::Game::Memory::operator bool()
- nall: renamed view<string> back to `string_view`
- nall:: implemented `array_view`
- Game Boy: split cartridge-specific input mappings (rumble,
accelerometer) to their own separate ports
- Game Boy: fixed MBC7 accelerometer x-axis
- icarus: Game Boy, Super Famicom, Mega Drive cores output internal
header game titles to heuristics manifests
- higan, icarus, hiro/gtk: improve viewport geometry configuration;
fixed higan crashing bug with XShm driver
- higan: connect Video::poll(),update() functionality
- hiro, ruby: several compilation / bugfixes, should get the macOS
port compiling again, hopefully [Sintendo]
- ruby/video/xshm: fix crashing bug on window resize
- a bit hacky; it's throwing BadAccess Xlib warnings, but they're
not fatal, so I am catching and ignoring them
- bsnes: removed Application::Windows::onModalChange hook that's no
longer needed [Screwtape]
2018-08-26 06:49:54 +00:00
|
|
|
//reallocation is meant for POD types, to avoid the overhead of initialization
|
|
|
|
//do not use with non-POD types, or they will not be properly constructed or destructed
|
|
|
|
|
2018-12-22 10:28:15 +00:00
|
|
|
template<typename T> auto vector<T>::reallocateLeft(uint64_t size) -> bool {
|
Update to v106r59 release.
byuu says:
Changelog:
- fixed bug in Emulator::Game::Memory::operator bool()
- nall: renamed view<string> back to `string_view`
- nall:: implemented `array_view`
- Game Boy: split cartridge-specific input mappings (rumble,
accelerometer) to their own separate ports
- Game Boy: fixed MBC7 accelerometer x-axis
- icarus: Game Boy, Super Famicom, Mega Drive cores output internal
header game titles to heuristics manifests
- higan, icarus, hiro/gtk: improve viewport geometry configuration;
fixed higan crashing bug with XShm driver
- higan: connect Video::poll(),update() functionality
- hiro, ruby: several compilation / bugfixes, should get the macOS
port compiling again, hopefully [Sintendo]
- ruby/video/xshm: fix crashing bug on window resize
- a bit hacky; it's throwing BadAccess Xlib warnings, but they're
not fatal, so I am catching and ignoring them
- bsnes: removed Application::Windows::onModalChange hook that's no
longer needed [Screwtape]
2018-08-26 06:49:54 +00:00
|
|
|
if(size < _size) { //shrink
|
|
|
|
_pool += _size - size;
|
|
|
|
_left += _size - size;
|
|
|
|
_size = size;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if(size > _size) { //grow
|
|
|
|
reserveLeft(size);
|
|
|
|
_pool -= size - _size;
|
|
|
|
_left -= size - _size;
|
|
|
|
_size = size;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-22 10:28:15 +00:00
|
|
|
template<typename T> auto vector<T>::reallocateRight(uint64_t size) -> bool {
|
Update to v106r59 release.
byuu says:
Changelog:
- fixed bug in Emulator::Game::Memory::operator bool()
- nall: renamed view<string> back to `string_view`
- nall:: implemented `array_view`
- Game Boy: split cartridge-specific input mappings (rumble,
accelerometer) to their own separate ports
- Game Boy: fixed MBC7 accelerometer x-axis
- icarus: Game Boy, Super Famicom, Mega Drive cores output internal
header game titles to heuristics manifests
- higan, icarus, hiro/gtk: improve viewport geometry configuration;
fixed higan crashing bug with XShm driver
- higan: connect Video::poll(),update() functionality
- hiro, ruby: several compilation / bugfixes, should get the macOS
port compiling again, hopefully [Sintendo]
- ruby/video/xshm: fix crashing bug on window resize
- a bit hacky; it's throwing BadAccess Xlib warnings, but they're
not fatal, so I am catching and ignoring them
- bsnes: removed Application::Windows::onModalChange hook that's no
longer needed [Screwtape]
2018-08-26 06:49:54 +00:00
|
|
|
if(size < _size) { //shrink
|
|
|
|
_right += _size - size;
|
|
|
|
_size = size;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if(size > _size) { //grow
|
|
|
|
reserveRight(size);
|
|
|
|
_right -= size - _size;
|
|
|
|
_size = size;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//resize is meant for non-POD types, and will properly construct objects
|
|
|
|
|
2018-12-22 10:28:15 +00:00
|
|
|
template<typename T> auto vector<T>::resizeLeft(uint64_t size, const T& value) -> bool {
|
2016-05-02 09:57:04 +00:00
|
|
|
if(size < _size) { //shrink
|
2018-12-22 10:28:15 +00:00
|
|
|
for(uint64_t n : range(_size - size)) _pool[n].~T();
|
2016-05-02 09:57:04 +00:00
|
|
|
_pool += _size - size;
|
|
|
|
_left += _size - size;
|
|
|
|
_size = size;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if(size > _size) { //grow
|
|
|
|
reserveLeft(size);
|
|
|
|
_pool -= size - _size;
|
2018-12-22 10:28:15 +00:00
|
|
|
for(uint64_t n : nall::reverse(range(size - _size))) new(_pool + n) T(value);
|
2016-05-02 09:57:04 +00:00
|
|
|
_left -= size - _size;
|
|
|
|
_size = size;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-12-22 10:28:15 +00:00
|
|
|
template<typename T> auto vector<T>::resizeRight(uint64_t size, const T& value) -> bool {
|
2016-05-02 09:57:04 +00:00
|
|
|
if(size < _size) { //shrink
|
2018-12-22 10:28:15 +00:00
|
|
|
for(uint64_t n : range(size, _size)) _pool[n].~T();
|
2016-05-02 09:57:04 +00:00
|
|
|
_right += _size - size;
|
|
|
|
_size = size;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if(size > _size) { //grow
|
|
|
|
reserveRight(size);
|
2018-12-22 10:28:15 +00:00
|
|
|
for(uint64_t n : range(_size, size)) new(_pool + n) T(value);
|
2016-05-02 09:57:04 +00:00
|
|
|
_right -= size - _size;
|
|
|
|
_size = size;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|