mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-08-16 22:34:00 +02:00
Update to v093 release.
byuu says: Changelog: - added Cocoa target: higan can now be compiled for OS X Lion [Cydrak, byuu] - SNES/accuracy profile hires color blending improvements - fixes Marvelous text [AWJ] - fixed a slight bug in SNES/SA-1 VBR support caused by a typo - added support for multi-pass shaders that can load external textures (requires OpenGL 3.2+) - added game library path (used by ananke->Import Game) to Settings->Advanced - system profiles, shaders and cheats database can be stored in "all users" shared folders now (eg /usr/share on Linux) - all configuration files are in BML format now, instead of XML (much easier to read and edit this way) - main window supports drag-and-drop of game folders (but not game files / ZIP archives) - audio buffer clears when entering a modal loop on Windows (prevents audio repetition with DirectSound driver) - a substantial amount of code clean-up (probably the biggest refactoring to date) One highly desired target for this release was to default to the optimal drivers instead of the safest drivers, but because AMD drivers don't seem to like my OpenGL 3.2 driver, I've decided to postpone that. AMD has too big a market share. Hopefully with v093 officially released, we can get some public input on what AMD doesn't like.
This commit is contained in:
117
nall/string/utility.hpp
Normal file
117
nall/string/utility.hpp
Normal file
@@ -0,0 +1,117 @@
|
||||
#ifdef NALL_STRING_INTERNAL_HPP
|
||||
|
||||
namespace nall {
|
||||
|
||||
string substr(rstring source, unsigned offset, unsigned length) {
|
||||
string result;
|
||||
if(length == ~0u) length = source.size() - offset;
|
||||
result.resize(length);
|
||||
memcpy(result.data(), source.data() + offset, length);
|
||||
return result;
|
||||
}
|
||||
|
||||
string sha256(const uint8_t* data, unsigned size) {
|
||||
sha256_ctx sha;
|
||||
uint8_t hash[32];
|
||||
sha256_init(&sha);
|
||||
sha256_chunk(&sha, data, size);
|
||||
sha256_final(&sha);
|
||||
sha256_hash(&sha, hash);
|
||||
string result;
|
||||
for(auto& byte : hash) result.append(hex<2>(byte));
|
||||
return result;
|
||||
}
|
||||
|
||||
bool tokenize(lstring& list, const char* s, const char* p) {
|
||||
while(*s) {
|
||||
if(*p == '*') {
|
||||
const char* b = s;
|
||||
while(*s) {
|
||||
if(tokenize(list, s++, p + 1)) {
|
||||
list.prepend(substr(b, 0, --s - b));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
list.prepend(b);
|
||||
return !*++p;
|
||||
}
|
||||
if(*s++ != *p++) return false;
|
||||
}
|
||||
while(*p == '*') { list.prepend(s); p++; }
|
||||
return !*p;
|
||||
}
|
||||
|
||||
char* integer(char* result, intmax_t value) {
|
||||
bool negative = value < 0;
|
||||
if(negative) value = -value;
|
||||
|
||||
char buffer[64];
|
||||
unsigned size = 0;
|
||||
|
||||
do {
|
||||
unsigned n = value % 10;
|
||||
buffer[size++] = '0' + n;
|
||||
value /= 10;
|
||||
} while(value);
|
||||
if(negative) buffer[size++] = '-';
|
||||
//buffer[size++] = negative ? '-' : '+';
|
||||
|
||||
for(signed x = size - 1, y = 0; x >= 0 && y < size; x--, y++) result[x] = buffer[y];
|
||||
result[size] = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
char* decimal(char* result, uintmax_t value) {
|
||||
char buffer[64];
|
||||
unsigned size = 0;
|
||||
|
||||
do {
|
||||
unsigned n = value % 10;
|
||||
buffer[size++] = '0' + n;
|
||||
value /= 10;
|
||||
} while(value);
|
||||
|
||||
for(signed x = size - 1, y = 0; x >= 0 && y < size; x--, y++) result[x] = buffer[y];
|
||||
result[size] = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
//using sprintf is certainly not the most ideal method to convert
|
||||
//a double to a string ... but attempting to parse a double by
|
||||
//hand, digit-by-digit, results in subtle rounding errors.
|
||||
unsigned real(char* str, long double value) {
|
||||
char buffer[256];
|
||||
#ifdef _WIN32
|
||||
//Windows C-runtime does not support long double via sprintf()
|
||||
sprintf(buffer, "%f", (double)value);
|
||||
#else
|
||||
sprintf(buffer, "%Lf", value);
|
||||
#endif
|
||||
|
||||
//remove excess 0's in fraction (2.500000 -> 2.5)
|
||||
for(char* p = buffer; *p; p++) {
|
||||
if(*p == '.') {
|
||||
char* p = buffer + strlen(buffer) - 1;
|
||||
while(*p == '0') {
|
||||
if(*(p - 1) != '.') *p = 0; //... but not for eg 1.0 -> 1.
|
||||
p--;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned length = strlen(buffer);
|
||||
if(str) strcpy(str, buffer);
|
||||
return length + 1;
|
||||
}
|
||||
|
||||
string real(long double value) {
|
||||
string temp;
|
||||
temp.resize(real(nullptr, value));
|
||||
real(temp.data(), value);
|
||||
return temp;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user