diff --git a/bsnes/base/base.hpp b/bsnes/base/base.hpp index ce00777a..13a9295c 100755 --- a/bsnes/base/base.hpp +++ b/bsnes/base/base.hpp @@ -1,19 +1,15 @@ #ifndef BASE_HPP #define BASE_HPP -static const char Version[] = "088.01"; +static const char Version[] = "088.02"; #include #include -#include -#include -#include #include #include #include #include #include -#include #include #include #include diff --git a/bsnes/nall/array.hpp b/bsnes/nall/array.hpp index e05c646c..a38355ba 100755 --- a/bsnes/nall/array.hpp +++ b/bsnes/nall/array.hpp @@ -13,12 +13,7 @@ namespace nall { -template struct array; - -//non-reference array -//=================== - -template struct array::value>::type> { +template struct array { struct exception_out_of_bounds{}; protected: @@ -159,131 +154,6 @@ public: const T* end() const { return &pool[objectsize]; } }; -//reference array -//=============== - -template struct array::value>::type> { - struct exception_out_of_bounds{}; - -protected: - typedef typename std::remove_reference::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 - bool append(T& data, Args&&... args) { - bool result = append(data); - append(std::forward(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 find(const T& data) { - for(unsigned n = 0; n < objectsize; n++) if(pool[n] == &data) return { true, n }; - return { false, 0u }; - } - - template array(Args&&... args) : pool(nullptr), poolsize(0), objectsize(0) { - construct(std::forward(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 void construct(T& data, Args&&... args) { - append(data); - construct(std::forward(args)...); - } -}; - } #endif diff --git a/bsnes/nall/moduloarray.hpp b/bsnes/nall/moduloarray.hpp deleted file mode 100755 index be549ae9..00000000 --- a/bsnes/nall/moduloarray.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef NALL_MODULO_HPP -#define NALL_MODULO_HPP - -#include - -namespace nall { - template 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 diff --git a/bsnes/nall/mosaic/context.hpp b/bsnes/nall/mosaic/context.hpp index 2d8c71ca..bc7a518a 100755 --- a/bsnes/nall/mosaic/context.hpp +++ b/bsnes/nall/mosaic/context.hpp @@ -17,24 +17,24 @@ struct context { unsigned blockHeight; unsigned blockStride; unsigned blockOffset; - array block; + vector block; unsigned tileWidth; unsigned tileHeight; unsigned tileStride; unsigned tileOffset; - array tile; + vector tile; unsigned mosaicWidth; unsigned mosaicHeight; unsigned mosaicStride; unsigned mosaicOffset; - array mosaic; + vector mosaic; unsigned paddingWidth; unsigned paddingHeight; unsigned paddingColor; - array palette; + vector 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 &buffer, const string &expression_) { + inline void eval(vector &buffer, const string &expression_) { string expression = expression_; bool function = false; for(auto &c : expression) { diff --git a/bsnes/nall/reference_array.hpp b/bsnes/nall/reference_array.hpp deleted file mode 100755 index 7c915090..00000000 --- a/bsnes/nall/reference_array.hpp +++ /dev/null @@ -1,142 +0,0 @@ -#ifndef NALL_REFERENCE_ARRAY_HPP -#define NALL_REFERENCE_ARRAY_HPP - -#include -#include -#include - -namespace nall { - template struct reference_array { - struct exception_out_of_bounds{}; - - protected: - typedef typename std::remove_reference::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 - bool append(type_t& data, Args&&... args) { - bool result = append(data); - append(std::forward(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 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 void construct(T data, Args&... args) { - append(data); - construct(args...); - } - }; -} - -#endif diff --git a/bsnes/nall/set.hpp b/bsnes/nall/set.hpp new file mode 100755 index 00000000..1666c8cd --- /dev/null +++ b/bsnes/nall/set.hpp @@ -0,0 +1,158 @@ +#ifndef NALL_SET_HPP +#define NALL_SET_HPP + +//set +//* unordered +//* intended for unique items +//* dynamic growth +//* reference-based variant + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace nall { + +template struct set; + +template struct set::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 struct set::value>::type> { + struct exception_out_of_bounds{}; + +protected: + typedef typename std::remove_reference::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 + bool append(T& data, Args&&... args) { + bool result = append(data); + append(std::forward(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 find(const T& data) { + for(unsigned n = 0; n < objectsize; n++) if(pool[n] == &data) return {true, n}; + return {false, 0u}; + } + + template set(Args&&... args) : pool(nullptr), poolsize(0), objectsize(0) { + construct(std::forward(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 void construct(T& data, Args&&... args) { + append(data); + construct(std::forward(args)...); + } +}; + +} + +#endif diff --git a/bsnes/nall/string/bml.hpp b/bsnes/nall/string/bml.hpp index d2fa60e3..de1f07a0 100755 --- a/bsnes/nall/string/bml.hpp +++ b/bsnes/nall/string/bml.hpp @@ -7,12 +7,12 @@ namespace nall { namespace BML { inline static string indent(const char *s, unsigned depth) { - array output; + vector 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 { diff --git a/bsnes/nall/string/xml.hpp b/bsnes/nall/string/xml.hpp index e08a354f..937436c8 100755 --- a/bsnes/nall/string/xml.hpp +++ b/bsnes/nall/string/xml.hpp @@ -10,7 +10,7 @@ struct Node { string name; string data; bool attribute; - array children; + vector children; inline bool exists() const { return !name.empty(); diff --git a/bsnes/nall/vector.hpp b/bsnes/nall/vector.hpp index ddf84ca5..19ae4270 100755 --- a/bsnes/nall/vector.hpp +++ b/bsnes/nall/vector.hpp @@ -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 void append(const T& data, Args&&... args) { append(data); diff --git a/bsnes/phoenix/core/core.cpp b/bsnes/phoenix/core/core.cpp index 8d202602..ec4aca3f 100755 --- a/bsnes/phoenix/core/core.cpp +++ b/bsnes/phoenix/core/core.cpp @@ -83,7 +83,7 @@ bool Keyboard::released(Keyboard::Scancode scancode) { return !pressed(scancode); } -array Keyboard::state() { +vector Keyboard::state() { return pKeyboard::state(); } @@ -423,7 +423,7 @@ Action::~Action() { //Menu //==== -void Menu::append(const array &list) { +void Menu::append(const set &list) { for(auto &action : list) { if(state.action.append(action)) { action.state.menu = this; @@ -432,7 +432,7 @@ void Menu::append(const array &list) { } } -void Menu::remove(const array &list) { +void Menu::remove(const set &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 &list) { +void RadioItem::group(const set &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 &list) { +void RadioBox::group(const set &list) { for(auto &item : list) item.p.setGroup(item.state.group = list); if(list.size()) list[0].setChecked(); } diff --git a/bsnes/phoenix/core/core.hpp b/bsnes/phoenix/core/core.hpp index d3506235..241d7552 100755 --- a/bsnes/phoenix/core/core.hpp +++ b/bsnes/phoenix/core/core.hpp @@ -91,7 +91,7 @@ struct Keyboard { #include "keyboard.hpp" static bool pressed(Scancode scancode); static bool released(Scancode scancode); - static nall::array state(); + static nall::vector state(); Keyboard() = delete; }; @@ -234,8 +234,8 @@ struct Menu : private nall::base_from_member, Action { template void append(Args&... args) { append({ args... }); } template void remove(Args&... args) { remove({ args... }); } - void append(const nall::array &list); - void remove(const nall::array &list); + void append(const nall::set &list); + void remove(const nall::set &list); void setImage(const nall::image &image); void setText(const nall::string &text); @@ -281,7 +281,7 @@ struct CheckItem : private nall::base_from_member, Action { struct RadioItem : private nall::base_from_member, Action { template static void group(Args&... args) { group({ args... }); } - static void group(const nall::array &list); + static void group(const nall::set &list); nall::function onActivate; @@ -524,7 +524,7 @@ struct ProgressBar : private nall::base_from_member, Widget { struct RadioBox : private nall::base_from_member, Widget { template static void group(Args&... args) { group({ args... }); } - static void group(const nall::array &list); + static void group(const nall::set &list); nall::function onActivate; diff --git a/bsnes/phoenix/core/state.hpp b/bsnes/phoenix/core/state.hpp index e64881c9..33dd0c52 100755 --- a/bsnes/phoenix/core/state.hpp +++ b/bsnes/phoenix/core/state.hpp @@ -14,8 +14,8 @@ struct Window::State { bool fullScreen; Geometry geometry; bool ignore; - array layout; - array menu; + set layout; + set menu; string menuFont; bool menuVisible; bool resizable; @@ -24,7 +24,7 @@ struct Window::State { bool statusVisible; string title; bool visible; - array widget; + set widget; string widgetFont; State() { @@ -55,7 +55,7 @@ struct Action::State { }; struct Menu::State { - array action; + set action; nall::image image; string text; @@ -82,7 +82,7 @@ struct CheckItem::State { struct RadioItem::State { bool checked; - array group; + set group; string text; State() { @@ -208,7 +208,7 @@ struct LineEdit::State { struct ListView::State { bool checkable; - array checked; + vector checked; lstring headerText; bool headerVisible; bool selected; @@ -233,7 +233,7 @@ struct ProgressBar::State { struct RadioBox::State { bool checked; - array group; + set group; string text; State() { diff --git a/bsnes/phoenix/gtk/action/radio-item.cpp b/bsnes/phoenix/gtk/action/radio-item.cpp index 783d7545..a599d70b 100755 --- a/bsnes/phoenix/gtk/action/radio-item.cpp +++ b/bsnes/phoenix/gtk/action/radio-item.cpp @@ -14,7 +14,7 @@ void pRadioItem::setChecked() { locked = false; } -void pRadioItem::setGroup(const array &group) { +void pRadioItem::setGroup(const set &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)); diff --git a/bsnes/phoenix/gtk/keyboard.cpp b/bsnes/phoenix/gtk/keyboard.cpp index 4e45fe13..5b346406 100755 --- a/bsnes/phoenix/gtk/keyboard.cpp +++ b/bsnes/phoenix/gtk/keyboard.cpp @@ -125,8 +125,8 @@ bool pKeyboard::pressed(Keyboard::Scancode scancode) { return state[id >> 3] & (1 << (id & 7)); } -array pKeyboard::state() { - array output; +vector pKeyboard::state() { + vector output; output.resize((unsigned)Keyboard::Scancode::Limit); for(auto &n : output) n = false; diff --git a/bsnes/phoenix/gtk/platform.hpp b/bsnes/phoenix/gtk/platform.hpp index 56534ca6..6fc0203f 100755 --- a/bsnes/phoenix/gtk/platform.hpp +++ b/bsnes/phoenix/gtk/platform.hpp @@ -36,7 +36,7 @@ struct pDesktop { struct pKeyboard { static bool pressed(Keyboard::Scancode scancode); - static array state(); + static vector state(); static void initialize(); }; @@ -202,7 +202,7 @@ struct pRadioItem : public pAction { bool checked(); void setChecked(); - void setGroup(const array &group); + void setGroup(const set &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 &group); + void setGroup(const set &group); void setText(const string &text); pRadioBox(RadioBox &radioBox) : pWidget(radioBox), radioBox(radioBox) {} diff --git a/bsnes/phoenix/gtk/widget/radio-box.cpp b/bsnes/phoenix/gtk/widget/radio-box.cpp index 3aa39693..36aff3fa 100755 --- a/bsnes/phoenix/gtk/widget/radio-box.cpp +++ b/bsnes/phoenix/gtk/widget/radio-box.cpp @@ -19,7 +19,7 @@ void pRadioBox::setChecked() { locked = false; } -void pRadioBox::setGroup(const array &group) { +void pRadioBox::setGroup(const set &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)); diff --git a/bsnes/phoenix/phoenix.hpp b/bsnes/phoenix/phoenix.hpp index e4bb3f4c..8a6129c4 100755 --- a/bsnes/phoenix/phoenix.hpp +++ b/bsnes/phoenix/phoenix.hpp @@ -2,11 +2,11 @@ #define PHOENIX_HPP #include -#include #include #include #include #include +#include #include #include #include diff --git a/bsnes/phoenix/qt/action/radio-item.cpp b/bsnes/phoenix/qt/action/radio-item.cpp index 8fcc1c22..66cf6c6a 100755 --- a/bsnes/phoenix/qt/action/radio-item.cpp +++ b/bsnes/phoenix/qt/action/radio-item.cpp @@ -12,7 +12,7 @@ void pRadioItem::setChecked() { locked = false; } -void pRadioItem::setGroup(const array &group) { +void pRadioItem::setGroup(const set &group) { } void pRadioItem::setText(const string &text) { diff --git a/bsnes/phoenix/qt/keyboard.cpp b/bsnes/phoenix/qt/keyboard.cpp index 4e45fe13..5b346406 100755 --- a/bsnes/phoenix/qt/keyboard.cpp +++ b/bsnes/phoenix/qt/keyboard.cpp @@ -125,8 +125,8 @@ bool pKeyboard::pressed(Keyboard::Scancode scancode) { return state[id >> 3] & (1 << (id & 7)); } -array pKeyboard::state() { - array output; +vector pKeyboard::state() { + vector output; output.resize((unsigned)Keyboard::Scancode::Limit); for(auto &n : output) n = false; diff --git a/bsnes/phoenix/qt/platform.moc b/bsnes/phoenix/qt/platform.moc index 645f7457..81420cee 100755 --- a/bsnes/phoenix/qt/platform.moc +++ b/bsnes/phoenix/qt/platform.moc @@ -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! diff --git a/bsnes/phoenix/qt/platform.moc.hpp b/bsnes/phoenix/qt/platform.moc.hpp index 9a98f96e..dfb05cc1 100755 --- a/bsnes/phoenix/qt/platform.moc.hpp +++ b/bsnes/phoenix/qt/platform.moc.hpp @@ -34,7 +34,7 @@ struct pDesktop { struct pKeyboard { static bool pressed(Keyboard::Scancode scancode); - static array state(); + static vector state(); static void initialize(); }; @@ -230,7 +230,7 @@ public: bool checked(); void setChecked(); - void setGroup(const array &group); + void setGroup(const set &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 &group); + void setGroup(const set &group); void setText(const string &text); pRadioBox(RadioBox &radioBox) : pWidget(radioBox), radioBox(radioBox) {} diff --git a/bsnes/phoenix/qt/widget/radio-box.cpp b/bsnes/phoenix/qt/widget/radio-box.cpp index 4f37a884..bf640fd2 100755 --- a/bsnes/phoenix/qt/widget/radio-box.cpp +++ b/bsnes/phoenix/qt/widget/radio-box.cpp @@ -17,7 +17,7 @@ void pRadioBox::setChecked() { locked = false; } -void pRadioBox::setGroup(const array &group) { +void pRadioBox::setGroup(const set &group) { locked = true; if(qtGroup) { delete qtGroup; diff --git a/bsnes/phoenix/windows/action/radio-item.cpp b/bsnes/phoenix/windows/action/radio-item.cpp index fa961239..6b4f3a31 100755 --- a/bsnes/phoenix/windows/action/radio-item.cpp +++ b/bsnes/phoenix/windows/action/radio-item.cpp @@ -11,7 +11,7 @@ void pRadioItem::setChecked() { } } -void pRadioItem::setGroup(const array &group) { +void pRadioItem::setGroup(const set &group) { } void pRadioItem::setText(const string &text) { diff --git a/bsnes/phoenix/windows/keyboard.cpp b/bsnes/phoenix/windows/keyboard.cpp index e007916d..1edffcb3 100755 --- a/bsnes/phoenix/windows/keyboard.cpp +++ b/bsnes/phoenix/windows/keyboard.cpp @@ -122,8 +122,8 @@ bool pKeyboard::pressed(Keyboard::Scancode scancode) { return GetAsyncKeyState(settings->keymap.lhs[scancode]) & 0x8000; } -array pKeyboard::state() { - array output; +vector pKeyboard::state() { + vector output; output.resize((unsigned)Keyboard::Scancode::Limit); for(auto &n : output) n = false; diff --git a/bsnes/phoenix/windows/platform.hpp b/bsnes/phoenix/windows/platform.hpp index 8abb93f3..1cdc04a1 100755 --- a/bsnes/phoenix/windows/platform.hpp +++ b/bsnes/phoenix/windows/platform.hpp @@ -188,7 +188,7 @@ struct pRadioItem : public pAction { bool checked(); void setChecked(); - void setGroup(const array &group); + void setGroup(const set &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 &group); + void setGroup(const set &group); void setText(const string &text); pRadioBox(RadioBox &radioBox) : pWidget(radioBox), radioBox(radioBox) {} diff --git a/bsnes/phoenix/windows/widget/radio-box.cpp b/bsnes/phoenix/windows/widget/radio-box.cpp index 37e9905f..ebcb1edc 100755 --- a/bsnes/phoenix/windows/widget/radio-box.cpp +++ b/bsnes/phoenix/windows/widget/radio-box.cpp @@ -13,7 +13,7 @@ void pRadioBox::setChecked() { } } -void pRadioBox::setGroup(const array &group) { +void pRadioBox::setGroup(const set &group) { } void pRadioBox::setText(const string &text) { diff --git a/bsnes/snes/cpu/cpu.hpp b/bsnes/snes/cpu/cpu.hpp index b44dc8c6..268760fb 100755 --- a/bsnes/snes/cpu/cpu.hpp +++ b/bsnes/snes/cpu/cpu.hpp @@ -2,7 +2,7 @@ struct CPU : Thread, public CPUcore, public PPUcounter { uint8 wram[128 * 1024]; enum : bool { Threaded = true }; - array coprocessors; + vector coprocessors; alwaysinline void step(unsigned clocks); alwaysinline void synchronize_smp(); void synchronize_ppu(); diff --git a/bsnes/snes/dsp/dsp.hpp b/bsnes/snes/dsp/dsp.hpp index c5f14e6c..8700396c 100755 --- a/bsnes/snes/dsp/dsp.hpp +++ b/bsnes/snes/dsp/dsp.hpp @@ -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 echo_hist[2]; //echo history keeps most recent 8 samples + moduloarray 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 buffer; //decoded samples + moduloarray 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 diff --git a/bsnes/snes/dsp/moduloarray.hpp b/bsnes/snes/dsp/moduloarray.hpp new file mode 100755 index 00000000..75352247 --- /dev/null +++ b/bsnes/snes/dsp/moduloarray.hpp @@ -0,0 +1,30 @@ +template 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; +}; diff --git a/bsnes/target-ui/general/main-window.cpp b/bsnes/target-ui/general/main-window.cpp index 1bf88d75..045294b7 100755 --- a/bsnes/target-ui/general/main-window.cpp +++ b/bsnes/target-ui/general/main-window.cpp @@ -388,7 +388,7 @@ void MainWindow::setupVideoFilters() { path = { application->userpath, "filters/" }; files = directory::files(path, "*.filter"); } - array group; + set 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 group; + set group; settingsVideoShaderList = new RadioItem[files.size()]; for(unsigned n = 0; n < files.size(); n++) { diff --git a/bsnes/target-ui/input/input.hpp b/bsnes/target-ui/input/input.hpp index ec83e960..b60d7bce 100755 --- a/bsnes/target-ui/input/input.hpp +++ b/bsnes/target-ui/input/input.hpp @@ -27,7 +27,7 @@ struct TurboInput : DigitalInput { TurboInput(); }; -struct TertiaryInput : array { +struct TertiaryInput : set { string name; virtual void attach(const string &primaryName, const string &secondaryName); @@ -35,14 +35,14 @@ struct TertiaryInput : array { virtual int16_t poll(unsigned n); }; -struct SecondaryInput : array { +struct SecondaryInput : set { string name; virtual void attach(const string &primaryName); virtual void bind(); }; -struct PrimaryInput : array { +struct PrimaryInput : set { string name; virtual void attach(); @@ -60,7 +60,7 @@ struct InputManager { int16_t scancode[2][Scancode::Limit]; bool activeScancode; - array inputList; + set inputList; NesInput nes; SnesInput snes; GbInput gb;