Update to v088r02 release.

byuu says:

Basically, the current implementation of nall/array is deprecated now.
The old method was for non-reference types, it acted like a vector for
POD types (raw memory allocation instead of placement new construction.)
And for reference types, it acted like an unordered set. Yeah, not good.

As of right now, nall/array is no longer used. The vector type usage was
replaced with actual vectors.
I've created nall/set, which now contains the specialization for
reference types.
nall/set basically acts much like std::unordered_set. No auto-sort, only
one of each type is allowed, automatic growth.
This will be the same both for reference and non-reference types ...
however, the non-reference type wasn't implemented just yet.
Future plans for nall/array are for it to be a statically allocated
block of memory, ala array<type, size>, which is meant for RAII memory
usage.
Have to work on the specifics, eg the size as a template parameter may
be problematic. I'd like to return allocated chunks of memory (eg
file::read) in this container so that I don't have to manually free the
data anymore.

I also removed nall/moduloarray, and moved that into the SNES DSP class,
since that's the only thing that uses it.
This commit is contained in:
Tim Allen 2012-04-26 20:56:15 +10:00
parent abe639ea91
commit bba597fc6f
31 changed files with 256 additions and 374 deletions

View File

@ -1,19 +1,15 @@
#ifndef BASE_HPP
#define BASE_HPP
static const char Version[] = "088.01";
static const char Version[] = "088.02";
#include <nall/platform.hpp>
#include <nall/algorithm.hpp>
#include <nall/any.hpp>
#include <nall/array.hpp>
#include <nall/bitarray.hpp>
#include <nall/dl.hpp>
#include <nall/dsp.hpp>
#include <nall/endian.hpp>
#include <nall/file.hpp>
#include <nall/function.hpp>
#include <nall/moduloarray.hpp>
#include <nall/priorityqueue.hpp>
#include <nall/property.hpp>
#include <nall/random.hpp>

View File

@ -13,12 +13,7 @@
namespace nall {
template<typename T, typename Enable = void> struct array;
//non-reference array
//===================
template<typename T> struct array<T, typename std::enable_if<!std::is_reference<T>::value>::type> {
template<typename T> struct array {
struct exception_out_of_bounds{};
protected:
@ -159,131 +154,6 @@ public:
const T* end() const { return &pool[objectsize]; }
};
//reference array
//===============
template<typename TR> struct array<TR, typename std::enable_if<std::is_reference<TR>::value>::type> {
struct exception_out_of_bounds{};
protected:
typedef typename std::remove_reference<TR>::type T;
T **pool;
unsigned poolsize, objectsize;
public:
unsigned size() const { return objectsize; }
unsigned capacity() const { return poolsize; }
void reset() {
if(pool) free(pool);
pool = nullptr;
poolsize = 0;
objectsize = 0;
}
void reserve(unsigned newsize) {
if(newsize == poolsize) return;
pool = (T**)realloc(pool, sizeof(T*) * newsize);
poolsize = newsize;
objectsize = min(objectsize, newsize);
}
void resize(unsigned newsize) {
if(newsize > poolsize) reserve(bit::round(newsize));
objectsize = newsize;
}
template<typename... Args>
bool append(T& data, Args&&... args) {
bool result = append(data);
append(std::forward<Args>(args)...);
return result;
}
bool append(T& data) {
if(find(data)) return false;
unsigned offset = objectsize++;
if(offset >= poolsize) resize(offset + 1);
pool[offset] = &data;
return true;
}
bool remove(T& data) {
if(auto position = find(data)) {
for(signed i = position(); i < objectsize - 1; i++) pool[i] = pool[i + 1];
resize(objectsize - 1);
return true;
}
return false;
}
optional<unsigned> find(const T& data) {
for(unsigned n = 0; n < objectsize; n++) if(pool[n] == &data) return { true, n };
return { false, 0u };
}
template<typename... Args> array(Args&&... args) : pool(nullptr), poolsize(0), objectsize(0) {
construct(std::forward<Args>(args)...);
}
~array() {
reset();
}
array& operator=(const array &source) {
if(pool) free(pool);
objectsize = source.objectsize;
poolsize = source.poolsize;
pool = (T**)malloc(sizeof(T*) * poolsize);
memcpy(pool, source.pool, sizeof(T*) * objectsize);
return *this;
}
array& operator=(const array &&source) {
if(pool) free(pool);
pool = source.pool;
poolsize = source.poolsize;
objectsize = source.objectsize;
source.pool = nullptr;
source.reset();
return *this;
}
T& operator[](unsigned position) const {
if(position >= objectsize) throw exception_out_of_bounds();
return *pool[position];
}
//iteration
struct iterator {
bool operator!=(const iterator &source) const { return position != source.position; }
T& operator*() { return source.operator[](position); }
iterator& operator++() { position++; return *this; }
iterator(const array &source, unsigned position) : source(source), position(position) {}
private:
const array &source;
unsigned position;
};
iterator begin() { return iterator(*this, 0); }
iterator end() { return iterator(*this, objectsize); }
const iterator begin() const { return iterator(*this, 0); }
const iterator end() const { return iterator(*this, objectsize); }
private:
void construct() {
}
void construct(const array& source) { operator=(source); }
void construct(const array&& source) { operator=(std::move(source)); }
template<typename... Args> void construct(T& data, Args&&... args) {
append(data);
construct(std::forward<Args>(args)...);
}
};
}
#endif

View File

@ -1,40 +0,0 @@
#ifndef NALL_MODULO_HPP
#define NALL_MODULO_HPP
#include <nall/serializer.hpp>
namespace nall {
template<typename T, int size> class modulo_array {
public:
inline T operator[](int index) const {
return buffer[size + index];
}
inline T read(int index) const {
return buffer[size + index];
}
inline void write(unsigned index, const T value) {
buffer[index] =
buffer[index + size] =
buffer[index + size + size] = value;
}
void serialize(serializer &s) {
s.array(buffer, size * 3);
}
modulo_array() {
buffer = new T[size * 3]();
}
~modulo_array() {
delete[] buffer;
}
private:
T *buffer;
};
}
#endif

View File

@ -17,24 +17,24 @@ struct context {
unsigned blockHeight;
unsigned blockStride;
unsigned blockOffset;
array<unsigned> block;
vector<unsigned> block;
unsigned tileWidth;
unsigned tileHeight;
unsigned tileStride;
unsigned tileOffset;
array<unsigned> tile;
vector<unsigned> tile;
unsigned mosaicWidth;
unsigned mosaicHeight;
unsigned mosaicStride;
unsigned mosaicOffset;
array<unsigned> mosaic;
vector<unsigned> mosaic;
unsigned paddingWidth;
unsigned paddingHeight;
unsigned paddingColor;
array<unsigned> palette;
vector<unsigned> palette;
inline unsigned objectWidth() const { return blockWidth * tileWidth * mosaicWidth + paddingWidth; }
inline unsigned objectHeight() const { return blockHeight * tileHeight * mosaicHeight + paddingHeight; }
@ -52,7 +52,7 @@ struct context {
return result;
}
inline void eval(array<unsigned> &buffer, const string &expression_) {
inline void eval(vector<unsigned> &buffer, const string &expression_) {
string expression = expression_;
bool function = false;
for(auto &c : expression) {

View File

@ -1,142 +0,0 @@
#ifndef NALL_REFERENCE_ARRAY_HPP
#define NALL_REFERENCE_ARRAY_HPP
#include <algorithm>
#include <type_traits>
#include <nall/bit.hpp>
namespace nall {
template<typename T> struct reference_array {
struct exception_out_of_bounds{};
protected:
typedef typename std::remove_reference<T>::type type_t;
type_t **pool;
unsigned poolsize, buffersize;
public:
unsigned size() const { return buffersize; }
unsigned capacity() const { return poolsize; }
void reset() {
if(pool) free(pool);
pool = nullptr;
poolsize = 0;
buffersize = 0;
}
void reserve(unsigned newsize) {
if(newsize == poolsize) return;
pool = (type_t**)realloc(pool, sizeof(type_t*) * newsize);
poolsize = newsize;
buffersize = min(buffersize, newsize);
}
void resize(unsigned newsize) {
if(newsize > poolsize) reserve(bit::round(newsize));
buffersize = newsize;
}
template<typename... Args>
bool append(type_t& data, Args&&... args) {
bool result = append(data);
append(std::forward<Args>(args)...);
return result;
}
bool append(type_t& data) {
for(unsigned index = 0; index < buffersize; index++) {
if(pool[index] == &data) return false;
}
unsigned index = buffersize++;
if(index >= poolsize) resize(index + 1);
pool[index] = &data;
return true;
}
bool remove(type_t& data) {
for(unsigned index = 0; index < buffersize; index++) {
if(pool[index] == &data) {
for(unsigned i = index; i < buffersize - 1; i++) pool[i] = pool[i + 1];
resize(buffersize - 1);
return true;
}
}
return false;
}
template<typename... Args> reference_array(Args&... args) : pool(nullptr), poolsize(0), buffersize(0) {
construct(args...);
}
~reference_array() {
reset();
}
reference_array& operator=(const reference_array &source) {
if(pool) free(pool);
buffersize = source.buffersize;
poolsize = source.poolsize;
pool = (type_t**)malloc(sizeof(type_t*) * poolsize);
memcpy(pool, source.pool, sizeof(type_t*) * buffersize);
return *this;
}
reference_array& operator=(const reference_array &&source) {
if(pool) free(pool);
pool = source.pool;
poolsize = source.poolsize;
buffersize = source.buffersize;
source.pool = nullptr;
source.reset();
return *this;
}
inline type_t& operator[](unsigned index) {
if(index >= buffersize) throw exception_out_of_bounds();
return *pool[index];
}
inline type_t& operator[](unsigned index) const {
if(index >= buffersize) throw exception_out_of_bounds();
return *pool[index];
}
//iteration
struct iterator {
bool operator!=(const iterator &source) const { return index != source.index; }
type_t& operator*() { return array.operator[](index); }
iterator& operator++() { index++; return *this; }
iterator(const reference_array &array, unsigned index) : array(array), index(index) {}
private:
const reference_array &array;
unsigned index;
};
iterator begin() { return iterator(*this, 0); }
iterator end() { return iterator(*this, buffersize); }
const iterator begin() const { return iterator(*this, 0); }
const iterator end() const { return iterator(*this, buffersize); }
private:
void construct() {
}
void construct(const reference_array &source) {
operator=(source);
}
void construct(const reference_array &&source) {
operator=(std::move(source));
}
template<typename... Args> void construct(T data, Args&... args) {
append(data);
construct(args...);
}
};
}
#endif

158
bsnes/nall/set.hpp Executable file
View File

@ -0,0 +1,158 @@
#ifndef NALL_SET_HPP
#define NALL_SET_HPP
//set
//* unordered
//* intended for unique items
//* dynamic growth
//* reference-based variant
#include <stdlib.h>
#include <algorithm>
#include <initializer_list>
#include <utility>
#include <nall/algorithm.hpp>
#include <nall/bit.hpp>
#include <nall/sort.hpp>
#include <nall/type_traits.hpp>
#include <nall/utility.hpp>
namespace nall {
template<typename T, typename Enable = void> struct set;
template<typename T> struct set<T, typename std::enable_if<!std::is_reference<T>::value>::type> {
struct exception_out_of_bounds{};
protected:
T *pool;
unsigned poolsize, objectsize;
public:
unsigned size() const { return objectsize; }
unsigned capacity() const { return poolsize; }
};
//reference set
template<typename TR> struct set<TR, typename std::enable_if<std::is_reference<TR>::value>::type> {
struct exception_out_of_bounds{};
protected:
typedef typename std::remove_reference<TR>::type T;
T **pool;
unsigned poolsize, objectsize;
public:
unsigned size() const { return objectsize; }
unsigned capacity() const { return poolsize; }
void reset() {
if(pool) free(pool);
pool = nullptr;
poolsize = 0;
objectsize = 0;
}
void reserve(unsigned size) {
if(size == poolsize) return;
pool = (T**)realloc(pool, sizeof(T*) * size);
poolsize = size;
objectsize = min(objectsize, size);
}
void resize(unsigned size) {
if(size > poolsize) reserve(bit::round(size)); //amortize growth
objectsize = size;
}
bool append(T& data) {
if(find(data)) return false;
unsigned offset = objectsize++;
if(offset >= poolsize) resize(offset + 1);
pool[offset] = &data;
return true;
}
template<typename... Args>
bool append(T& data, Args&&... args) {
bool result = append(data);
append(std::forward<Args>(args)...);
return result;
}
bool remove(T& data) {
if(auto position = find(data)) {
for(signed i = position(); i < objectsize - 1; i++) pool[i] = pool[i + 1];
resize(objectsize - 1);
return true;
}
return false;
}
optional<unsigned> find(const T& data) {
for(unsigned n = 0; n < objectsize; n++) if(pool[n] == &data) return {true, n};
return {false, 0u};
}
template<typename... Args> set(Args&&... args) : pool(nullptr), poolsize(0), objectsize(0) {
construct(std::forward<Args>(args)...);
}
~set() {
reset();
}
set& operator=(const set &source) {
if(&source == this) return *this;
if(pool) free(pool);
objectsize = source.objectsize;
poolsize = source.poolsize;
pool = (T**)malloc(sizeof(T*) * poolsize);
memcpy(pool, source.pool, sizeof(T*) * objectsize);
return *this;
}
set& operator=(const set &&source) {
if(&source == this) return *this;
if(pool) free(pool);
pool = source.pool;
poolsize = source.poolsize;
objectsize = source.objectsize;
source.pool = nullptr;
source.reset();
return *this;
}
T& operator[](unsigned position) const {
if(position >= objectsize) throw exception_out_of_bounds();
return *pool[position];
}
struct iterator {
bool operator!=(const iterator &source) const { return position != source.position; }
T& operator*() { return source.operator[](position); }
iterator& operator++() { position++; return *this; }
iterator(const set &source, unsigned position) : source(source), position(position) {}
private:
const set &source;
unsigned position;
};
iterator begin() { return iterator(*this, 0); }
iterator end() { return iterator(*this, objectsize); }
const iterator begin() const { return iterator(*this, 0); }
const iterator end() const { return iterator(*this, objectsize); }
private:
void construct() {}
void construct(const set &source) { operator=(source); }
void construct(const set &&source) { operator=(std::move(source)); }
template<typename... Args> void construct(T& data, Args&&... args) {
append(data);
construct(std::forward<Args>(args)...);
}
};
}
#endif

View File

@ -7,12 +7,12 @@ namespace nall {
namespace BML {
inline static string indent(const char *s, unsigned depth) {
array<char> output;
vector<char> output;
do {
for(unsigned n = 0; n < depth; n++) output.append('\t');
do output.append(*s); while(*s && *s++ != '\n');
} while(*s);
return output.get();
return output.data();
}
struct Node {

View File

@ -10,7 +10,7 @@ struct Node {
string name;
string data;
bool attribute;
array<Node*> children;
vector<Node*> children;
inline bool exists() const {
return !name.empty();

View File

@ -21,6 +21,7 @@ namespace nall {
unsigned objectsize;
public:
T* data() { return pool; }
unsigned size() const { return objectsize; }
unsigned capacity() const { return poolsize; }
@ -45,6 +46,13 @@ namespace nall {
objectsize = min(size, objectsize);
}
//requires trivial constructor
void resize(unsigned size) {
if(size == objectsize) return;
if(size < objectsize) return reserve(size);
while(size > objectsize) append(T());
}
template<typename... Args>
void append(const T& data, Args&&... args) {
append(data);

View File

@ -83,7 +83,7 @@ bool Keyboard::released(Keyboard::Scancode scancode) {
return !pressed(scancode);
}
array<bool> Keyboard::state() {
vector<bool> Keyboard::state() {
return pKeyboard::state();
}
@ -423,7 +423,7 @@ Action::~Action() {
//Menu
//====
void Menu::append(const array<Action&> &list) {
void Menu::append(const set<Action&> &list) {
for(auto &action : list) {
if(state.action.append(action)) {
action.state.menu = this;
@ -432,7 +432,7 @@ void Menu::append(const array<Action&> &list) {
}
}
void Menu::remove(const array<Action&> &list) {
void Menu::remove(const set<Action&> &list) {
for(auto &action : list) {
if(state.action.remove(action)) {
action.state.menu = 0;
@ -537,7 +537,7 @@ CheckItem::~CheckItem() {
//RadioItem
//=========
void RadioItem::group(const array<RadioItem&> &list) {
void RadioItem::group(const set<RadioItem&> &list) {
for(auto &item : list) item.p.setGroup(item.state.group = list);
if(list.size()) list[0].setChecked();
}
@ -1121,7 +1121,7 @@ ProgressBar::~ProgressBar() {
//RadioBox
//========
void RadioBox::group(const array<RadioBox&> &list) {
void RadioBox::group(const set<RadioBox&> &list) {
for(auto &item : list) item.p.setGroup(item.state.group = list);
if(list.size()) list[0].setChecked();
}

View File

@ -91,7 +91,7 @@ struct Keyboard {
#include "keyboard.hpp"
static bool pressed(Scancode scancode);
static bool released(Scancode scancode);
static nall::array<bool> state();
static nall::vector<bool> state();
Keyboard() = delete;
};
@ -234,8 +234,8 @@ struct Menu : private nall::base_from_member<pMenu&>, Action {
template<typename... Args> void append(Args&... args) { append({ args... }); }
template<typename... Args> void remove(Args&... args) { remove({ args... }); }
void append(const nall::array<Action&> &list);
void remove(const nall::array<Action&> &list);
void append(const nall::set<Action&> &list);
void remove(const nall::set<Action&> &list);
void setImage(const nall::image &image);
void setText(const nall::string &text);
@ -281,7 +281,7 @@ struct CheckItem : private nall::base_from_member<pCheckItem&>, Action {
struct RadioItem : private nall::base_from_member<pRadioItem&>, Action {
template<typename... Args> static void group(Args&... args) { group({ args... }); }
static void group(const nall::array<RadioItem&> &list);
static void group(const nall::set<RadioItem&> &list);
nall::function<void ()> onActivate;
@ -524,7 +524,7 @@ struct ProgressBar : private nall::base_from_member<pProgressBar&>, Widget {
struct RadioBox : private nall::base_from_member<pRadioBox&>, Widget {
template<typename... Args> static void group(Args&... args) { group({ args... }); }
static void group(const nall::array<RadioBox&> &list);
static void group(const nall::set<RadioBox&> &list);
nall::function<void ()> onActivate;

View File

@ -14,8 +14,8 @@ struct Window::State {
bool fullScreen;
Geometry geometry;
bool ignore;
array<Layout&> layout;
array<Menu&> menu;
set<Layout&> layout;
set<Menu&> menu;
string menuFont;
bool menuVisible;
bool resizable;
@ -24,7 +24,7 @@ struct Window::State {
bool statusVisible;
string title;
bool visible;
array<Widget&> widget;
set<Widget&> widget;
string widgetFont;
State() {
@ -55,7 +55,7 @@ struct Action::State {
};
struct Menu::State {
array<Action&> action;
set<Action&> action;
nall::image image;
string text;
@ -82,7 +82,7 @@ struct CheckItem::State {
struct RadioItem::State {
bool checked;
array<RadioItem&> group;
set<RadioItem&> group;
string text;
State() {
@ -208,7 +208,7 @@ struct LineEdit::State {
struct ListView::State {
bool checkable;
array<bool> checked;
vector<bool> checked;
lstring headerText;
bool headerVisible;
bool selected;
@ -233,7 +233,7 @@ struct ProgressBar::State {
struct RadioBox::State {
bool checked;
array<RadioBox&> group;
set<RadioBox&> group;
string text;
State() {

View File

@ -14,7 +14,7 @@ void pRadioItem::setChecked() {
locked = false;
}
void pRadioItem::setGroup(const array<RadioItem&> &group) {
void pRadioItem::setGroup(const set<RadioItem&> &group) {
for(unsigned n = 0; n < group.size(); n++) {
if(n == 0) continue;
GSList *currentGroup = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(group[0].p.widget));

View File

@ -125,8 +125,8 @@ bool pKeyboard::pressed(Keyboard::Scancode scancode) {
return state[id >> 3] & (1 << (id & 7));
}
array<bool> pKeyboard::state() {
array<bool> output;
vector<bool> pKeyboard::state() {
vector<bool> output;
output.resize((unsigned)Keyboard::Scancode::Limit);
for(auto &n : output) n = false;

View File

@ -36,7 +36,7 @@ struct pDesktop {
struct pKeyboard {
static bool pressed(Keyboard::Scancode scancode);
static array<bool> state();
static vector<bool> state();
static void initialize();
};
@ -202,7 +202,7 @@ struct pRadioItem : public pAction {
bool checked();
void setChecked();
void setGroup(const array<RadioItem&> &group);
void setGroup(const set<RadioItem&> &group);
void setText(const string &text);
pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {}
@ -428,7 +428,7 @@ struct pRadioBox : public pWidget {
bool checked();
Geometry minimumGeometry();
void setChecked();
void setGroup(const array<RadioBox&> &group);
void setGroup(const set<RadioBox&> &group);
void setText(const string &text);
pRadioBox(RadioBox &radioBox) : pWidget(radioBox), radioBox(radioBox) {}

View File

@ -19,7 +19,7 @@ void pRadioBox::setChecked() {
locked = false;
}
void pRadioBox::setGroup(const array<RadioBox&> &group) {
void pRadioBox::setGroup(const set<RadioBox&> &group) {
for(unsigned n = 0; n < group.size(); n++) {
if(n == 0) continue;
GSList *currentGroup = gtk_radio_button_get_group(GTK_RADIO_BUTTON(group[0].p.gtkWidget));

View File

@ -2,11 +2,11 @@
#define PHOENIX_HPP
#include <nall/platform.hpp>
#include <nall/array.hpp>
#include <nall/config.hpp>
#include <nall/function.hpp>
#include <nall/image.hpp>
#include <nall/map.hpp>
#include <nall/set.hpp>
#include <nall/stdint.hpp>
#include <nall/string.hpp>
#include <nall/utility.hpp>

View File

@ -12,7 +12,7 @@ void pRadioItem::setChecked() {
locked = false;
}
void pRadioItem::setGroup(const array<RadioItem&> &group) {
void pRadioItem::setGroup(const set<RadioItem&> &group) {
}
void pRadioItem::setText(const string &text) {

View File

@ -125,8 +125,8 @@ bool pKeyboard::pressed(Keyboard::Scancode scancode) {
return state[id >> 3] & (1 << (id & 7));
}
array<bool> pKeyboard::state() {
array<bool> output;
vector<bool> pKeyboard::state() {
vector<bool> output;
output.resize((unsigned)Keyboard::Scancode::Limit);
for(auto &n : output) n = false;

View File

@ -1,7 +1,7 @@
/****************************************************************************
** Meta object code from reading C++ file 'platform.moc.hpp'
**
** Created: Thu Mar 22 11:27:37 2012
** Created: Thu Apr 26 04:47:17 2012
** by: The Qt Meta Object Compiler version 62 (Qt 4.6.3)
**
** WARNING! All changes made in this file will be lost!

View File

@ -34,7 +34,7 @@ struct pDesktop {
struct pKeyboard {
static bool pressed(Keyboard::Scancode scancode);
static array<bool> state();
static vector<bool> state();
static void initialize();
};
@ -230,7 +230,7 @@ public:
bool checked();
void setChecked();
void setGroup(const array<RadioItem&> &group);
void setGroup(const set<RadioItem&> &group);
void setText(const string &text);
pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {}
@ -530,7 +530,7 @@ public:
bool checked();
Geometry minimumGeometry();
void setChecked();
void setGroup(const array<RadioBox&> &group);
void setGroup(const set<RadioBox&> &group);
void setText(const string &text);
pRadioBox(RadioBox &radioBox) : pWidget(radioBox), radioBox(radioBox) {}

View File

@ -17,7 +17,7 @@ void pRadioBox::setChecked() {
locked = false;
}
void pRadioBox::setGroup(const array<RadioBox&> &group) {
void pRadioBox::setGroup(const set<RadioBox&> &group) {
locked = true;
if(qtGroup) {
delete qtGroup;

View File

@ -11,7 +11,7 @@ void pRadioItem::setChecked() {
}
}
void pRadioItem::setGroup(const array<RadioItem&> &group) {
void pRadioItem::setGroup(const set<RadioItem&> &group) {
}
void pRadioItem::setText(const string &text) {

View File

@ -122,8 +122,8 @@ bool pKeyboard::pressed(Keyboard::Scancode scancode) {
return GetAsyncKeyState(settings->keymap.lhs[scancode]) & 0x8000;
}
array<bool> pKeyboard::state() {
array<bool> output;
vector<bool> pKeyboard::state() {
vector<bool> output;
output.resize((unsigned)Keyboard::Scancode::Limit);
for(auto &n : output) n = false;

View File

@ -188,7 +188,7 @@ struct pRadioItem : public pAction {
bool checked();
void setChecked();
void setGroup(const array<RadioItem&> &group);
void setGroup(const set<RadioItem&> &group);
void setText(const string &text);
pRadioItem(RadioItem &radioItem) : pAction(radioItem), radioItem(radioItem) {}
@ -403,7 +403,7 @@ struct pRadioBox : public pWidget {
bool checked();
Geometry minimumGeometry();
void setChecked();
void setGroup(const array<RadioBox&> &group);
void setGroup(const set<RadioBox&> &group);
void setText(const string &text);
pRadioBox(RadioBox &radioBox) : pWidget(radioBox), radioBox(radioBox) {}

View File

@ -13,7 +13,7 @@ void pRadioBox::setChecked() {
}
}
void pRadioBox::setGroup(const array<RadioBox&> &group) {
void pRadioBox::setGroup(const set<RadioBox&> &group) {
}
void pRadioBox::setText(const string &text) {

View File

@ -2,7 +2,7 @@ struct CPU : Thread, public CPUcore, public PPUcounter {
uint8 wram[128 * 1024];
enum : bool { Threaded = true };
array<Thread*> coprocessors;
vector<Thread*> coprocessors;
alwaysinline void step(unsigned clocks);
alwaysinline void synchronize_smp();
void synchronize_ppu();

View File

@ -15,6 +15,8 @@ struct DSP : Thread {
~DSP();
privileged:
#include "moduloarray.hpp"
//global registers
enum global_reg_t {
r_mvoll = 0x0c, r_mvolr = 0x1c,
@ -48,7 +50,7 @@ privileged:
struct state_t {
uint8 regs[128];
modulo_array<int, echo_hist_size> echo_hist[2]; //echo history keeps most recent 8 samples
moduloarray<int, echo_hist_size> echo_hist[2]; //echo history keeps most recent 8 samples
int echo_hist_pos;
bool every_other_sample; //toggles every sample
@ -97,7 +99,7 @@ privileged:
//voice state
struct voice_t {
modulo_array<int, brr_buf_size> buffer; //decoded samples
moduloarray<int, brr_buf_size> buffer; //decoded samples
int buf_pos; //place in buffer where next samples will be decoded
int interp_pos; //relative fractional position in sample (0x1000 = 1.0)
int brr_addr; //address of current BRR block

30
bsnes/snes/dsp/moduloarray.hpp Executable file
View File

@ -0,0 +1,30 @@
template<typename T, unsigned size> struct moduloarray {
inline T operator[](int index) const {
return buffer[size + index];
}
inline T read(int index) const {
return buffer[size + index];
}
inline void write(unsigned index, const T value) {
buffer[index] =
buffer[index + size] =
buffer[index + size + size] = value;
}
void serialize(serializer &s) {
s.array(buffer, size * 3);
}
moduloarray() {
buffer = new T[size * 3]();
}
~moduloarray() {
delete[] buffer;
}
private:
T *buffer;
};

View File

@ -388,7 +388,7 @@ void MainWindow::setupVideoFilters() {
path = { application->userpath, "filters/" };
files = directory::files(path, "*.filter");
}
array<RadioItem&> group;
set<RadioItem&> group;
settingsVideoFilterList = new RadioItem[files.size()];
for(unsigned n = 0; n < files.size(); n++) {
@ -419,7 +419,7 @@ void MainWindow::setupVideoShaders() {
path = { application->userpath, "shaders/" };
files = directory::files(path, { "*.", config->video.driver, ".shader" });
}
array<RadioItem&> group;
set<RadioItem&> group;
settingsVideoShaderList = new RadioItem[files.size()];
for(unsigned n = 0; n < files.size(); n++) {

View File

@ -27,7 +27,7 @@ struct TurboInput : DigitalInput {
TurboInput();
};
struct TertiaryInput : array<AbstractInput&> {
struct TertiaryInput : set<AbstractInput&> {
string name;
virtual void attach(const string &primaryName, const string &secondaryName);
@ -35,14 +35,14 @@ struct TertiaryInput : array<AbstractInput&> {
virtual int16_t poll(unsigned n);
};
struct SecondaryInput : array<TertiaryInput&> {
struct SecondaryInput : set<TertiaryInput&> {
string name;
virtual void attach(const string &primaryName);
virtual void bind();
};
struct PrimaryInput : array<SecondaryInput&> {
struct PrimaryInput : set<SecondaryInput&> {
string name;
virtual void attach();
@ -60,7 +60,7 @@ struct InputManager {
int16_t scancode[2][Scancode::Limit];
bool activeScancode;
array<PrimaryInput&> inputList;
set<PrimaryInput&> inputList;
NesInput nes;
SnesInput snes;
GbInput gb;