2010-08-09 13:28:56 +00:00
|
|
|
#ifndef NALL_VECTOR_HPP
|
|
|
|
#define NALL_VECTOR_HPP
|
|
|
|
|
2011-09-27 11:55:02 +00:00
|
|
|
#include <algorithm>
|
2010-08-09 13:28:56 +00:00
|
|
|
#include <initializer_list>
|
|
|
|
#include <new>
|
|
|
|
#include <utility>
|
|
|
|
#include <nall/algorithm.hpp>
|
|
|
|
#include <nall/bit.hpp>
|
2014-02-09 05:59:46 +00:00
|
|
|
#include <nall/maybe.hpp>
|
2012-01-26 06:50:09 +00:00
|
|
|
#include <nall/sort.hpp>
|
2010-08-09 13:28:56 +00:00
|
|
|
#include <nall/utility.hpp>
|
|
|
|
|
|
|
|
namespace nall {
|
2011-10-16 09:44:48 +00:00
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
template<typename T> struct vector {
|
|
|
|
struct exception_out_of_bounds{};
|
|
|
|
|
|
|
|
protected:
|
|
|
|
T* pool = nullptr;
|
|
|
|
unsigned poolbase = 0;
|
|
|
|
unsigned poolsize = 0;
|
|
|
|
unsigned objectsize = 0;
|
|
|
|
|
|
|
|
public:
|
Update to v093r01 release.
byuu says:
Changelog:
- added SA-1 MDR; fixes bug in SD Gundam G-Next where the main
battleship was unable to fire
- added out-of-the-box support for any BSD running Clang 3.3+ (FreeBSD
10+, notably)
- added new video shader, "Display Emulation", which changes the shader
based on the emulated system
- fixed the home button to go to your default library path
- phoenix: Windows port won't send onActivate unless an item is selected
(prevents crashing on pressing enter in file dialog)
- ruby: removed vec4 position from out Vertex {} (helps AMD cards)
- shaders: updated all shaders to use texture() instead of texture2D()
(helps AMD cards)
The "Display Emulation" option works like this: when selected, it tries
to load "<path>/Video Shaders/Emulation/<systemName>.shader/"; otherwise
it falls back to the blur shader. <path> is the usual (next to binary,
then in <config>/higan, then in /usr/share/higan, etc); and <systemName>
is "Famicom", "Super Famicom", "Game Boy", "Game Boy Color", "Game Boy
Advance"
To support BSD, I had to modify the $(platform) variable to
differentiate between Linux and BSD.
As such, the new $(platform) values are:
win -> windows
osx -> macosx
x -> linux or bsd
I am also checking uname -s instead of uname -a now. No reason to
potentially match the hostname to the wrong OS type.
2013-10-21 11:45:39 +00:00
|
|
|
explicit operator bool() const { return objectsize; }
|
2013-05-02 11:25:45 +00:00
|
|
|
T* data() { return pool + poolbase; }
|
|
|
|
const T* data() const { return pool + poolbase; }
|
|
|
|
|
|
|
|
bool empty() const { return objectsize == 0; }
|
|
|
|
unsigned size() const { return objectsize; }
|
|
|
|
unsigned capacity() const { return poolsize; }
|
|
|
|
|
|
|
|
T* move() {
|
|
|
|
T* result = pool + poolbase;
|
|
|
|
pool = nullptr;
|
|
|
|
poolbase = 0;
|
|
|
|
poolsize = 0;
|
|
|
|
objectsize = 0;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset() {
|
|
|
|
if(pool) {
|
|
|
|
for(unsigned n = 0; n < objectsize; n++) pool[poolbase + n].~T();
|
2011-10-16 09:44:48 +00:00
|
|
|
free(pool);
|
|
|
|
}
|
2013-05-02 11:25:45 +00:00
|
|
|
pool = nullptr;
|
|
|
|
poolbase = 0;
|
|
|
|
poolsize = 0;
|
|
|
|
objectsize = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void reserve(unsigned size) {
|
|
|
|
if(size <= poolsize) return;
|
|
|
|
size = bit::round(size); //amortize growth
|
|
|
|
|
|
|
|
T* copy = (T*)calloc(size, sizeof(T));
|
|
|
|
for(unsigned n = 0; n < objectsize; n++) new(copy + n) T(std::move(pool[poolbase + n]));
|
|
|
|
free(pool);
|
|
|
|
pool = copy;
|
|
|
|
poolbase = 0;
|
|
|
|
poolsize = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void resize(unsigned size) {
|
|
|
|
T* copy = (T*)calloc(size, sizeof(T));
|
|
|
|
for(unsigned n = 0; n < size && n < objectsize; n++) new(copy + n) T(std::move(pool[poolbase + n]));
|
|
|
|
reset();
|
|
|
|
pool = copy;
|
|
|
|
poolbase = 0;
|
|
|
|
poolsize = size;
|
|
|
|
objectsize = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename... Args> void prepend(const T& data, Args&&... args) {
|
|
|
|
prepend(std::forward<Args>(args)...);
|
|
|
|
prepend(data);
|
|
|
|
}
|
|
|
|
|
2013-07-29 09:42:45 +00:00
|
|
|
T& prepend(const T& data) {
|
2013-05-02 11:25:45 +00:00
|
|
|
reserve(objectsize + 1);
|
|
|
|
if(poolbase == 0) {
|
|
|
|
unsigned available = poolsize - objectsize;
|
|
|
|
poolbase = max(1u, available >> 1);
|
|
|
|
for(signed n = objectsize - 1; n >= 0; n--) {
|
|
|
|
pool[poolbase + n] = std::move(pool[n]);
|
2012-07-08 02:57:34 +00:00
|
|
|
}
|
|
|
|
}
|
2013-05-02 11:25:45 +00:00
|
|
|
new(pool + --poolbase) T(data);
|
|
|
|
objectsize++;
|
2013-07-29 09:42:45 +00:00
|
|
|
return first();
|
2013-05-02 11:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename... Args> void append(const T& data, Args&&... args) {
|
|
|
|
append(data);
|
|
|
|
append(std::forward<Args>(args)...);
|
|
|
|
}
|
|
|
|
|
2013-07-29 09:42:45 +00:00
|
|
|
T& append(const T& data) {
|
2013-05-02 11:25:45 +00:00
|
|
|
reserve(poolbase + objectsize + 1);
|
|
|
|
new(pool + poolbase + objectsize++) T(data);
|
2013-07-29 09:42:45 +00:00
|
|
|
return last();
|
2013-05-02 11:25:45 +00:00
|
|
|
}
|
|
|
|
|
2013-12-03 10:01:59 +00:00
|
|
|
bool appendOnce(const T& data) {
|
2013-05-02 11:25:45 +00:00
|
|
|
if(find(data)) return false;
|
|
|
|
return append(data), true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void insert(unsigned position, const T& data) {
|
Update to v094r09 release.
byuu says:
This will easily be the biggest diff in the history of higan. And not in
a good way.
* target-higan and target-loki have been blown away completely
* nall and ruby massively updated
* phoenix replaced with hiro (pretty near a total rewrite)
* target-higan restarted using hiro (just a window for now)
* all emulation cores updated to compile again
* installation changed to not require root privileges (installs locally)
For the foreseeable future (maybe even permanently?), the new higan UI
will only build under Linux/BSD with GTK+ 2.20+. Probably the most
likely route for Windows/OS X will be to try and figure out how to build
hiro/GTK on those platforms, as awful as that would be. The other
alternative would be to produce new UIs for those platforms ... which
would actually be a good opportunity to make something much more user
friendly.
Being that I just started on this a few hours ago, that means that for
at least a few weeks, don't expect to be able to actually play any
games. Right now, you can pretty much just compile the binary and that's
it. It's quite possible that some nall changes didn't produce
compilation errors, but will produce runtime errors. So until the UI can
actually load games, we won't know if anything is broken. But we should
mostly be okay. It was mostly just trim<1> -> trim changes, moving to
Hash::SHA256 (much cleaner), and patching some reckless memory copy
functions enough to compile.
Progress isn't going to be like it was before: I'm now dividing my time
much thinner between studying and other hobbies.
My aim this time is not to produce a binary for everyone to play games
on. Rather, it's to keep the emulator alive. I want to be able to apply
critical patches again. And I would also like the base of the emulator
to live on, for use in other emulator frontends that utilize higan.
2015-02-26 10:10:46 +00:00
|
|
|
if(position == 0) {
|
|
|
|
prepend(data);
|
|
|
|
return;
|
|
|
|
}
|
2013-05-02 11:25:45 +00:00
|
|
|
append(data);
|
|
|
|
if(position == ~0u) return;
|
|
|
|
for(signed n = objectsize - 1; n > position; n--) {
|
|
|
|
pool[poolbase + n] = std::move(pool[poolbase + n - 1]);
|
2012-01-26 06:50:09 +00:00
|
|
|
}
|
2013-05-02 11:25:45 +00:00
|
|
|
pool[poolbase + position] = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void remove(unsigned position = ~0u, unsigned length = 1) {
|
|
|
|
if(position == ~0u) position = objectsize - 1;
|
|
|
|
if(position + length > objectsize) throw exception_out_of_bounds{};
|
|
|
|
|
|
|
|
if(position == 0) {
|
|
|
|
for(unsigned n = 0; n < length; n++) pool[poolbase + n].~T();
|
|
|
|
poolbase += length;
|
|
|
|
} else {
|
|
|
|
for(unsigned n = position; n < objectsize; n++) {
|
|
|
|
if(n + length < objectsize) {
|
|
|
|
pool[poolbase + n] = std::move(pool[poolbase + n + length]);
|
|
|
|
} else {
|
|
|
|
pool[poolbase + n].~T();
|
|
|
|
}
|
|
|
|
}
|
2011-10-16 09:44:48 +00:00
|
|
|
}
|
2013-05-02 11:25:45 +00:00
|
|
|
objectsize -= length;
|
|
|
|
}
|
|
|
|
|
2013-12-03 10:01:59 +00:00
|
|
|
void removeFirst() { return remove(0); }
|
|
|
|
void removeLast() { return remove(~0u); }
|
Update to v093r01 release.
byuu says:
Changelog:
- added SA-1 MDR; fixes bug in SD Gundam G-Next where the main
battleship was unable to fire
- added out-of-the-box support for any BSD running Clang 3.3+ (FreeBSD
10+, notably)
- added new video shader, "Display Emulation", which changes the shader
based on the emulated system
- fixed the home button to go to your default library path
- phoenix: Windows port won't send onActivate unless an item is selected
(prevents crashing on pressing enter in file dialog)
- ruby: removed vec4 position from out Vertex {} (helps AMD cards)
- shaders: updated all shaders to use texture() instead of texture2D()
(helps AMD cards)
The "Display Emulation" option works like this: when selected, it tries
to load "<path>/Video Shaders/Emulation/<systemName>.shader/"; otherwise
it falls back to the blur shader. <path> is the usual (next to binary,
then in <config>/higan, then in /usr/share/higan, etc); and <systemName>
is "Famicom", "Super Famicom", "Game Boy", "Game Boy Color", "Game Boy
Advance"
To support BSD, I had to modify the $(platform) variable to
differentiate between Linux and BSD.
As such, the new $(platform) values are:
win -> windows
osx -> macosx
x -> linux or bsd
I am also checking uname -s instead of uname -a now. No reason to
potentially match the hostname to the wrong OS type.
2013-10-21 11:45:39 +00:00
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
T take(unsigned position = ~0u) {
|
|
|
|
if(position == ~0u) position = objectsize - 1;
|
|
|
|
T object = pool[poolbase + position];
|
|
|
|
remove(position);
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2013-12-03 10:01:59 +00:00
|
|
|
T takeFirst() { return take(0); }
|
|
|
|
T takeLast() { return take(~0u); }
|
Update to v093r01 release.
byuu says:
Changelog:
- added SA-1 MDR; fixes bug in SD Gundam G-Next where the main
battleship was unable to fire
- added out-of-the-box support for any BSD running Clang 3.3+ (FreeBSD
10+, notably)
- added new video shader, "Display Emulation", which changes the shader
based on the emulated system
- fixed the home button to go to your default library path
- phoenix: Windows port won't send onActivate unless an item is selected
(prevents crashing on pressing enter in file dialog)
- ruby: removed vec4 position from out Vertex {} (helps AMD cards)
- shaders: updated all shaders to use texture() instead of texture2D()
(helps AMD cards)
The "Display Emulation" option works like this: when selected, it tries
to load "<path>/Video Shaders/Emulation/<systemName>.shader/"; otherwise
it falls back to the blur shader. <path> is the usual (next to binary,
then in <config>/higan, then in /usr/share/higan, etc); and <systemName>
is "Famicom", "Super Famicom", "Game Boy", "Game Boy Color", "Game Boy
Advance"
To support BSD, I had to modify the $(platform) variable to
differentiate between Linux and BSD.
As such, the new $(platform) values are:
win -> windows
osx -> macosx
x -> linux or bsd
I am also checking uname -s instead of uname -a now. No reason to
potentially match the hostname to the wrong OS type.
2013-10-21 11:45:39 +00:00
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
void reverse() {
|
|
|
|
unsigned pivot = size() / 2;
|
|
|
|
for(unsigned l = 0, r = size() - 1; l < pivot; l++, r--) {
|
|
|
|
std::swap(pool[poolbase + l], pool[poolbase + r]);
|
2011-10-16 09:44:48 +00:00
|
|
|
}
|
2013-05-02 11:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void sort() {
|
|
|
|
nall::sort(pool + poolbase, objectsize);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Comparator> void sort(const Comparator &lessthan) {
|
|
|
|
nall::sort(pool + poolbase, objectsize, lessthan);
|
|
|
|
}
|
|
|
|
|
Update to v094r09 release.
byuu says:
This will easily be the biggest diff in the history of higan. And not in
a good way.
* target-higan and target-loki have been blown away completely
* nall and ruby massively updated
* phoenix replaced with hiro (pretty near a total rewrite)
* target-higan restarted using hiro (just a window for now)
* all emulation cores updated to compile again
* installation changed to not require root privileges (installs locally)
For the foreseeable future (maybe even permanently?), the new higan UI
will only build under Linux/BSD with GTK+ 2.20+. Probably the most
likely route for Windows/OS X will be to try and figure out how to build
hiro/GTK on those platforms, as awful as that would be. The other
alternative would be to produce new UIs for those platforms ... which
would actually be a good opportunity to make something much more user
friendly.
Being that I just started on this a few hours ago, that means that for
at least a few weeks, don't expect to be able to actually play any
games. Right now, you can pretty much just compile the binary and that's
it. It's quite possible that some nall changes didn't produce
compilation errors, but will produce runtime errors. So until the UI can
actually load games, we won't know if anything is broken. But we should
mostly be okay. It was mostly just trim<1> -> trim changes, moving to
Hash::SHA256 (much cleaner), and patching some reckless memory copy
functions enough to compile.
Progress isn't going to be like it was before: I'm now dividing my time
much thinner between studying and other hobbies.
My aim this time is not to produce a binary for everyone to play games
on. Rather, it's to keep the emulator alive. I want to be able to apply
critical patches again. And I would also like the base of the emulator
to live on, for use in other emulator frontends that utilize higan.
2015-02-26 10:10:46 +00:00
|
|
|
maybe<unsigned> find(const T& data) const {
|
2014-02-09 05:59:46 +00:00
|
|
|
for(unsigned n = 0; n < objectsize; n++) if(pool[poolbase + n] == data) return n;
|
|
|
|
return nothing;
|
2013-05-02 11:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
T& first() {
|
|
|
|
if(objectsize == 0) throw exception_out_of_bounds();
|
|
|
|
return pool[poolbase];
|
|
|
|
}
|
|
|
|
|
|
|
|
const T& first() const {
|
|
|
|
if(objectsize == 0) throw exception_out_of_bounds();
|
|
|
|
return pool[poolbase];
|
|
|
|
}
|
|
|
|
|
|
|
|
T& last() {
|
|
|
|
if(objectsize == 0) throw exception_out_of_bounds();
|
|
|
|
return pool[poolbase + objectsize - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
const T& last() const {
|
|
|
|
if(objectsize == 0) throw exception_out_of_bounds();
|
|
|
|
return pool[poolbase + objectsize - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
//access
|
|
|
|
inline T& operator[](unsigned position) {
|
|
|
|
if(position >= objectsize) throw exception_out_of_bounds();
|
|
|
|
return pool[poolbase + position];
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const T& operator[](unsigned position) const {
|
|
|
|
if(position >= objectsize) throw exception_out_of_bounds();
|
|
|
|
return pool[poolbase + position];
|
|
|
|
}
|
|
|
|
|
|
|
|
inline T& operator()(unsigned position) {
|
|
|
|
if(position >= poolsize) reserve(position + 1);
|
|
|
|
while(position >= objectsize) append(T());
|
|
|
|
return pool[poolbase + position];
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const T& operator()(unsigned position, const T& data) const {
|
|
|
|
if(position >= objectsize) return data;
|
|
|
|
return pool[poolbase + position];
|
|
|
|
}
|
|
|
|
|
|
|
|
//iteration
|
|
|
|
struct iterator {
|
|
|
|
T& operator*() { return source.operator[](position); }
|
|
|
|
bool operator!=(const iterator& source) const { return position != source.position; }
|
|
|
|
iterator& operator++() { position++; return *this; }
|
|
|
|
iterator(vector& source, unsigned position) : source(source), position(position) {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
vector& source;
|
|
|
|
unsigned position;
|
|
|
|
};
|
2011-10-16 09:44:48 +00:00
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
iterator begin() { return iterator(*this, 0); }
|
|
|
|
iterator end() { return iterator(*this, size()); }
|
2011-10-16 09:44:48 +00:00
|
|
|
|
2013-12-03 10:01:59 +00:00
|
|
|
struct constIterator {
|
2013-05-02 11:25:45 +00:00
|
|
|
const T& operator*() const { return source.operator[](position); }
|
2013-12-03 10:01:59 +00:00
|
|
|
bool operator!=(const constIterator& source) const { return position != source.position; }
|
|
|
|
constIterator& operator++() { position++; return *this; }
|
|
|
|
constIterator(const vector& source, unsigned position) : source(source), position(position) {}
|
2011-10-16 09:44:48 +00:00
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
private:
|
|
|
|
const vector& source;
|
|
|
|
unsigned position;
|
|
|
|
};
|
2011-10-16 09:44:48 +00:00
|
|
|
|
2013-12-03 10:01:59 +00:00
|
|
|
const constIterator begin() const { return constIterator(*this, 0); }
|
|
|
|
const constIterator end() const { return constIterator(*this, size()); }
|
2013-05-02 11:25:45 +00:00
|
|
|
|
|
|
|
//copy
|
|
|
|
inline vector& operator=(const vector& source) {
|
Update to v094r09 release.
byuu says:
This will easily be the biggest diff in the history of higan. And not in
a good way.
* target-higan and target-loki have been blown away completely
* nall and ruby massively updated
* phoenix replaced with hiro (pretty near a total rewrite)
* target-higan restarted using hiro (just a window for now)
* all emulation cores updated to compile again
* installation changed to not require root privileges (installs locally)
For the foreseeable future (maybe even permanently?), the new higan UI
will only build under Linux/BSD with GTK+ 2.20+. Probably the most
likely route for Windows/OS X will be to try and figure out how to build
hiro/GTK on those platforms, as awful as that would be. The other
alternative would be to produce new UIs for those platforms ... which
would actually be a good opportunity to make something much more user
friendly.
Being that I just started on this a few hours ago, that means that for
at least a few weeks, don't expect to be able to actually play any
games. Right now, you can pretty much just compile the binary and that's
it. It's quite possible that some nall changes didn't produce
compilation errors, but will produce runtime errors. So until the UI can
actually load games, we won't know if anything is broken. But we should
mostly be okay. It was mostly just trim<1> -> trim changes, moving to
Hash::SHA256 (much cleaner), and patching some reckless memory copy
functions enough to compile.
Progress isn't going to be like it was before: I'm now dividing my time
much thinner between studying and other hobbies.
My aim this time is not to produce a binary for everyone to play games
on. Rather, it's to keep the emulator alive. I want to be able to apply
critical patches again. And I would also like the base of the emulator
to live on, for use in other emulator frontends that utilize higan.
2015-02-26 10:10:46 +00:00
|
|
|
if(this == &source) return *this;
|
2013-05-02 11:25:45 +00:00
|
|
|
reset();
|
|
|
|
reserve(source.size());
|
|
|
|
for(auto& data : source) append(data);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//move
|
|
|
|
inline vector& operator=(vector&& source) {
|
Update to v094r09 release.
byuu says:
This will easily be the biggest diff in the history of higan. And not in
a good way.
* target-higan and target-loki have been blown away completely
* nall and ruby massively updated
* phoenix replaced with hiro (pretty near a total rewrite)
* target-higan restarted using hiro (just a window for now)
* all emulation cores updated to compile again
* installation changed to not require root privileges (installs locally)
For the foreseeable future (maybe even permanently?), the new higan UI
will only build under Linux/BSD with GTK+ 2.20+. Probably the most
likely route for Windows/OS X will be to try and figure out how to build
hiro/GTK on those platforms, as awful as that would be. The other
alternative would be to produce new UIs for those platforms ... which
would actually be a good opportunity to make something much more user
friendly.
Being that I just started on this a few hours ago, that means that for
at least a few weeks, don't expect to be able to actually play any
games. Right now, you can pretty much just compile the binary and that's
it. It's quite possible that some nall changes didn't produce
compilation errors, but will produce runtime errors. So until the UI can
actually load games, we won't know if anything is broken. But we should
mostly be okay. It was mostly just trim<1> -> trim changes, moving to
Hash::SHA256 (much cleaner), and patching some reckless memory copy
functions enough to compile.
Progress isn't going to be like it was before: I'm now dividing my time
much thinner between studying and other hobbies.
My aim this time is not to produce a binary for everyone to play games
on. Rather, it's to keep the emulator alive. I want to be able to apply
critical patches again. And I would also like the base of the emulator
to live on, for use in other emulator frontends that utilize higan.
2015-02-26 10:10:46 +00:00
|
|
|
if(this == &source) return *this;
|
2013-05-02 11:25:45 +00:00
|
|
|
reset();
|
|
|
|
pool = source.pool;
|
|
|
|
poolbase = source.poolbase;
|
|
|
|
poolsize = source.poolsize;
|
|
|
|
objectsize = source.objectsize;
|
|
|
|
source.pool = nullptr;
|
|
|
|
source.poolbase = 0;
|
|
|
|
source.poolsize = 0;
|
|
|
|
source.objectsize = 0;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//construction and destruction
|
|
|
|
vector() = default;
|
|
|
|
vector(std::initializer_list<T> list) { for(auto& data : list) append(data); }
|
|
|
|
vector(const vector& source) { operator=(source); }
|
|
|
|
vector(vector&& source) { operator=(std::move(source)); }
|
|
|
|
~vector() { reset(); }
|
|
|
|
};
|
2011-10-16 09:44:48 +00:00
|
|
|
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|