mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-09-01 04:22:38 +02:00
Update to v093r05 release.
byuu says: Library concept has been refined as per the general forum discussion.
This commit is contained in:
@@ -8,7 +8,7 @@ namespace nall {
|
||||
struct beatArchive : beatBase {
|
||||
bool create(const string& beatname, string pathname, const string& metadata = "") {
|
||||
if(fp.open(beatname, file::mode::write) == false) return false;
|
||||
if(pathname.endswith("/") == false) pathname.append("/");
|
||||
if(pathname.endsWith("/") == false) pathname.append("/");
|
||||
|
||||
checksum = ~0;
|
||||
writeString("BPA1");
|
||||
@@ -18,7 +18,7 @@ struct beatArchive : beatBase {
|
||||
lstring list;
|
||||
ls(list, pathname, pathname);
|
||||
for(auto &name : list) {
|
||||
if(name.endswith("/")) {
|
||||
if(name.endsWith("/")) {
|
||||
name.rtrim<1>("/");
|
||||
writeNumber(0 | ((name.length() - 1) << 1));
|
||||
writeString(name);
|
||||
@@ -46,7 +46,7 @@ struct beatArchive : beatBase {
|
||||
|
||||
bool unpack(const string& beatname, string pathname) {
|
||||
if(fp.open(beatname, file::mode::read) == false) return false;
|
||||
if(pathname.endswith("/") == false) pathname.append("/");
|
||||
if(pathname.endsWith("/") == false) pathname.append("/");
|
||||
|
||||
checksum = ~0;
|
||||
if(readString(4) != "BPA1") return false;
|
||||
|
@@ -34,7 +34,7 @@ struct bpsmulti {
|
||||
ls(targetList, targetPath, targetPath);
|
||||
|
||||
for(auto& targetName : targetList) {
|
||||
if(targetName.endswith("/")) {
|
||||
if(targetName.endsWith("/")) {
|
||||
targetName.rtrim<1>("/");
|
||||
writeNumber(CreatePath | ((targetName.length() - 1) << 2));
|
||||
writeString(targetName);
|
||||
|
@@ -168,7 +168,7 @@ private:
|
||||
inline bool directory::remove(const string& pathname) {
|
||||
lstring list = directory::contents(pathname);
|
||||
for(auto& name : list) {
|
||||
if(name.endswith("/")) directory::remove({pathname, name});
|
||||
if(name.endsWith("/")) directory::remove({pathname, name});
|
||||
else file::remove({pathname, name});
|
||||
}
|
||||
return rmdir(pathname) == 0;
|
||||
|
@@ -38,7 +38,7 @@ private:
|
||||
#if defined(PLATFORM_X)
|
||||
inline bool library::open(const string& name, const string& path) {
|
||||
if(handle) close();
|
||||
handle = (uintptr_t)dlopen(string(path, !path.empty() && !path.endswith("/") ? "/" : "", "lib", name, ".so"), RTLD_LAZY);
|
||||
handle = (uintptr_t)dlopen(string(path, !path.empty() && !path.endsWith("/") ? "/" : "", "lib", name, ".so"), RTLD_LAZY);
|
||||
if(!handle) handle = (uintptr_t)dlopen(string("/usr/local/lib/lib", name, ".so"), RTLD_LAZY);
|
||||
return handle;
|
||||
}
|
||||
@@ -62,7 +62,7 @@ inline void library::close() {
|
||||
#elif defined(PLATFORM_MACOSX)
|
||||
inline bool library::open(const string& name, const string& path) {
|
||||
if(handle) close();
|
||||
handle = (uintptr_t)dlopen(string(path, !path.empty() && !path.endswith("/") ? "/" : "", "lib", name, ".dylib"), RTLD_LAZY);
|
||||
handle = (uintptr_t)dlopen(string(path, !path.empty() && !path.endsWith("/") ? "/" : "", "lib", name, ".dylib"), RTLD_LAZY);
|
||||
if(!handle) handle = (uintptr_t)dlopen(string("/usr/local/lib/lib", name, ".dylib"), RTLD_LAZY);
|
||||
return handle;
|
||||
}
|
||||
@@ -86,7 +86,7 @@ inline void library::close() {
|
||||
#elif defined(PLATFORM_WINDOWS)
|
||||
inline bool library::open(const string& name, const string& path) {
|
||||
if(handle) close();
|
||||
string filepath(path, !path.empty() && !path.endswith("/") && !path.endswith("\\") ? "/" : "", name, ".dll");
|
||||
string filepath(path, !path.empty() && !path.endswith("/") && !path.endsWith("\\") ? "/" : "", name, ".dll");
|
||||
handle = (uintptr_t)LoadLibraryW(utf16_t(filepath));
|
||||
return handle;
|
||||
}
|
||||
|
@@ -41,11 +41,11 @@ template<typename T> struct group : protected vector<T*> {
|
||||
return false;
|
||||
}
|
||||
|
||||
struct iterator : protected vector<T*>::const_iterator {
|
||||
T& operator*() const { return *vector<T*>::const_iterator::operator*(); }
|
||||
bool operator!=(const iterator& source) const { return vector<T*>::const_iterator::operator!=(source); }
|
||||
iterator& operator++() { vector<T*>::const_iterator::operator++(); return *this; }
|
||||
iterator(const group& source, unsigned position) : vector<T*>::const_iterator(source, position) {}
|
||||
struct iterator : protected vector<T*>::constIterator {
|
||||
T& operator*() const { return *vector<T*>::constIterator::operator*(); }
|
||||
bool operator!=(const iterator& source) const { return vector<T*>::constIterator::operator!=(source); }
|
||||
iterator& operator++() { vector<T*>::constIterator::operator++(); return *this; }
|
||||
iterator(const group& source, unsigned position) : vector<T*>::constIterator(source, position) {}
|
||||
};
|
||||
|
||||
const iterator begin() const { return iterator(*this, 0); }
|
||||
|
@@ -81,7 +81,7 @@ struct http {
|
||||
if(length <= 0) return output;
|
||||
buffer[1] = 0;
|
||||
output.append(buffer);
|
||||
} while(output.endswith("\r\n\r\n") == false);
|
||||
} while(output.endsWith("\r\n\r\n") == false);
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ struct http {
|
||||
if(length <= 0) return output;
|
||||
buffer[1] = 0;
|
||||
output.append(buffer);
|
||||
} while(output.endswith("\r\n") == false);
|
||||
} while(output.endsWith("\r\n") == false);
|
||||
return output;
|
||||
}
|
||||
|
||||
|
@@ -113,6 +113,7 @@ unsigned image::bitShift(uint64_t color) {
|
||||
}
|
||||
|
||||
uint64_t image::normalize(uint64_t color, unsigned sourceDepth, unsigned targetDepth) {
|
||||
if(sourceDepth == 0 || targetDepth == 0) return 0;
|
||||
while(sourceDepth < targetDepth) {
|
||||
color = (color << sourceDepth) | color;
|
||||
sourceDepth += sourceDepth;
|
||||
|
@@ -176,6 +176,10 @@ struct context {
|
||||
|
||||
if(mosaicWidth < 1) mosaicWidth = 1;
|
||||
if(mosaicHeight < 1) mosaicHeight = 1;
|
||||
|
||||
//set alpha to full opacity
|
||||
paddingColor |= 255u << 24;
|
||||
for(auto& color : palette) color |= 255u << 24;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
@@ -208,7 +212,7 @@ struct context {
|
||||
|
||||
paddingWidth = 0;
|
||||
paddingHeight = 0;
|
||||
paddingColor = 0x000000;
|
||||
paddingColor = 0;
|
||||
palette.reset();
|
||||
}
|
||||
|
||||
|
@@ -9,7 +9,7 @@ struct parser {
|
||||
//export from bitstream to canvas
|
||||
void load(bitstream& stream, uint64_t offset, context& ctx, unsigned width, unsigned height) {
|
||||
canvas.allocate(width, height);
|
||||
canvas.clear(ctx.paddingColor);
|
||||
canvas.fill(ctx.paddingColor);
|
||||
parse(1, stream, offset, ctx, width, height);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ struct parser {
|
||||
return true;
|
||||
}
|
||||
|
||||
inline parser() : canvas(0, 32, 0u, 255u << 16, 255u << 8, 255u << 0) {
|
||||
inline parser() : canvas(0, 32, 255u << 24, 255u << 16, 255u << 8, 255u << 0) {
|
||||
}
|
||||
|
||||
private:
|
||||
|
@@ -6,9 +6,9 @@ namespace nall {
|
||||
#define autostream(...) (*makestream(__VA_ARGS__))
|
||||
|
||||
inline std::unique_ptr<stream> makestream(const string& path) {
|
||||
if(path.ibeginswith("http://")) return std::unique_ptr<stream>(new httpstream(path, 80));
|
||||
if(path.iendswith(".gz")) return std::unique_ptr<stream>(new gzipstream(filestream{path}));
|
||||
if(path.iendswith(".zip")) return std::unique_ptr<stream>(new zipstream(filestream{path}));
|
||||
if(path.ibeginsWith("http://")) return std::unique_ptr<stream>(new httpstream(path, 80));
|
||||
if(path.iendsWith(".gz")) return std::unique_ptr<stream>(new gzipstream(filestream{path}));
|
||||
if(path.iendsWith(".zip")) return std::unique_ptr<stream>(new zipstream(filestream{path}));
|
||||
return std::unique_ptr<stream>(new mmapstream(path));
|
||||
}
|
||||
|
||||
|
@@ -81,10 +81,10 @@ public:
|
||||
inline bool match(rstring) const;
|
||||
inline bool imatch(rstring) const;
|
||||
|
||||
inline bool beginswith(rstring) const;
|
||||
inline bool ibeginswith(rstring) const;
|
||||
inline bool endswith(rstring) const;
|
||||
inline bool iendswith(rstring) const;
|
||||
inline bool beginsWith(rstring) const;
|
||||
inline bool ibeginsWith(rstring) const;
|
||||
inline bool endsWith(rstring) const;
|
||||
inline bool iendsWith(rstring) const;
|
||||
|
||||
inline string slice(unsigned offset, unsigned length = ~0u) const;
|
||||
|
||||
|
@@ -39,11 +39,11 @@ inline string evaluateExpression(Node* node) {
|
||||
|
||||
inline int64_t evaluateInteger(Node* node) {
|
||||
if(node->type == Node::Type::Literal) {
|
||||
if(node->literal.beginswith("0b")) return nall::binary(node->literal);
|
||||
if(node->literal.beginswith("0o")) return nall::octal(node->literal);
|
||||
if(node->literal.beginswith("0x")) return nall::hex(node->literal);
|
||||
if(node->literal.beginswith("%")) return nall::binary(node->literal);
|
||||
if(node->literal.beginswith("$")) return nall::hex(node->literal);
|
||||
if(node->literal.beginsWith("0b")) return nall::binary(node->literal);
|
||||
if(node->literal.beginsWith("0o")) return nall::octal(node->literal);
|
||||
if(node->literal.beginsWith("0x")) return nall::hex(node->literal);
|
||||
if(node->literal.beginsWith("%")) return nall::binary(node->literal);
|
||||
if(node->literal.beginsWith("$")) return nall::hex(node->literal);
|
||||
return nall::integer(node->literal);
|
||||
}
|
||||
|
||||
|
@@ -4,7 +4,7 @@ namespace nall {
|
||||
namespace Markup {
|
||||
|
||||
inline Node Document(const string& markup) {
|
||||
if(markup.beginswith("<")) return XML::Document(markup);
|
||||
if(markup.beginsWith("<")) return XML::Document(markup);
|
||||
return BML::Document(markup);
|
||||
}
|
||||
|
||||
|
@@ -131,8 +131,8 @@ struct Node {
|
||||
vector<Node>::iterator begin() { return children.begin(); }
|
||||
vector<Node>::iterator end() { return children.end(); }
|
||||
|
||||
const vector<Node>::const_iterator begin() const { return children.begin(); }
|
||||
const vector<Node>::const_iterator end() const { return children.end(); }
|
||||
const vector<Node>::constIterator begin() const { return children.begin(); }
|
||||
const vector<Node>::constIterator end() const { return children.end(); }
|
||||
|
||||
Node() : attribute(false), level(0) {}
|
||||
|
||||
|
@@ -8,7 +8,7 @@ string activepath() {
|
||||
string result = path;
|
||||
if(result.empty()) result = ".";
|
||||
result.transform("\\", "/");
|
||||
if(result.endswith("/") == false) result.append("/");
|
||||
if(result.endsWith("/") == false) result.append("/");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ string realpath(const string& name) {
|
||||
if(::realpath(name, path)) result = path;
|
||||
if(result.empty()) result = {activepath(), name};
|
||||
result.transform("\\", "/");
|
||||
if(result.endswith("/") == false) result.append("/");
|
||||
if(result.endsWith("/") == false) result.append("/");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ string userpath() {
|
||||
result = userinfo->pw_dir;
|
||||
#endif
|
||||
if(result.empty()) result = ".";
|
||||
if(result.endswith("/") == false) result.append("/");
|
||||
if(result.endsWith("/") == false) result.append("/");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ string configpath() {
|
||||
result = {userpath(), ".config/"};
|
||||
#endif
|
||||
if(result.empty()) result = ".";
|
||||
if(result.endswith("/") == false) result.append("/");
|
||||
if(result.endsWith("/") == false) result.append("/");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ string sharedpath() {
|
||||
result = "/usr/share/";
|
||||
#endif
|
||||
if(result.empty()) result = ".";
|
||||
if(result.endswith("/") == false) result.append("/");
|
||||
if(result.endsWith("/") == false) result.append("/");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@@ -28,22 +28,22 @@ bool string::iequals(rstring source) const {
|
||||
return icompare(source) == 0;
|
||||
}
|
||||
|
||||
bool string::beginswith(rstring source) const {
|
||||
bool string::beginsWith(rstring source) const {
|
||||
if(source.size() > size()) return false;
|
||||
return memcmp(data(), source.data(), source.size()) == 0;
|
||||
}
|
||||
|
||||
bool string::ibeginswith(rstring source) const {
|
||||
bool string::ibeginsWith(rstring source) const {
|
||||
if(source.size() > size()) return false;
|
||||
return imemcmp(data(), source.data(), source.size()) == 0;
|
||||
}
|
||||
|
||||
bool string::endswith(rstring source) const {
|
||||
bool string::endsWith(rstring source) const {
|
||||
if(source.size() > size()) return false;
|
||||
return memcmp(data() + size() - source.size(), source.data(), source.size()) == 0;
|
||||
}
|
||||
|
||||
bool string::iendswith(rstring source) const {
|
||||
bool string::iendsWith(rstring source) const {
|
||||
if(source.size() > size()) return false;
|
||||
return imemcmp(data() + size() - source.size(), source.data(), source.size()) == 0;
|
||||
}
|
||||
|
@@ -102,7 +102,7 @@ public:
|
||||
return last();
|
||||
}
|
||||
|
||||
bool appendonce(const T& data) {
|
||||
bool appendOnce(const T& data) {
|
||||
if(find(data)) return false;
|
||||
return append(data), true;
|
||||
}
|
||||
@@ -136,8 +136,8 @@ public:
|
||||
objectsize -= length;
|
||||
}
|
||||
|
||||
void removefirst() { return remove(0); }
|
||||
void removelast() { return remove(~0u); }
|
||||
void removeFirst() { return remove(0); }
|
||||
void removeLast() { return remove(~0u); }
|
||||
|
||||
T take(unsigned position = ~0u) {
|
||||
if(position == ~0u) position = objectsize - 1;
|
||||
@@ -146,8 +146,8 @@ public:
|
||||
return object;
|
||||
}
|
||||
|
||||
T takefirst() { return take(0); }
|
||||
T takelast() { return take(~0u); }
|
||||
T takeFirst() { return take(0); }
|
||||
T takeLast() { return take(~0u); }
|
||||
|
||||
void reverse() {
|
||||
unsigned pivot = size() / 2;
|
||||
@@ -226,19 +226,19 @@ public:
|
||||
iterator begin() { return iterator(*this, 0); }
|
||||
iterator end() { return iterator(*this, size()); }
|
||||
|
||||
struct const_iterator {
|
||||
struct constIterator {
|
||||
const T& operator*() const { return source.operator[](position); }
|
||||
bool operator!=(const const_iterator& source) const { return position != source.position; }
|
||||
const_iterator& operator++() { position++; return *this; }
|
||||
const_iterator(const vector& source, unsigned position) : source(source), position(position) {}
|
||||
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) {}
|
||||
|
||||
private:
|
||||
const vector& source;
|
||||
unsigned position;
|
||||
};
|
||||
|
||||
const const_iterator begin() const { return const_iterator(*this, 0); }
|
||||
const const_iterator end() const { return const_iterator(*this, size()); }
|
||||
const constIterator begin() const { return constIterator(*this, 0); }
|
||||
const constIterator end() const { return constIterator(*this, size()); }
|
||||
|
||||
//copy
|
||||
inline vector& operator=(const vector& source) {
|
||||
|
Reference in New Issue
Block a user