26 #ifndef __AIBO_BUILD__ 33 #if defined(__unix__) && !defined(__ANDROID__) && !defined(__AIBO_BUILD__) 47 #if defined(__AIBO_BUILD__) 51 int JumpPointValid = 0;
53 void RaiseCppException()
55 if (JumpPointValid == 1)
56 longjmp(JumpPoint, 1);
63 #ifndef __AIBO_BUILD__ 66 static QStringList SearchPaths;
92 Wait(msecs*1000*1000);
99 #if !defined(__AIBO_BUILD__) && defined(__unix__) 100 int MCGetSystemMemorySize()
102 long pages = sysconf(_SC_PHYS_PAGES);
103 long page_size = sysconf(_SC_PAGE_SIZE);
105 return (
int)((float)pages / 1024*page_size / 1024);
112 return std::numeric_limits<float>::infinity();
118 return std::numeric_limits<double>::infinity();
124 #ifdef __AIBO_BUILD__ 125 return __isinff(value);
127 return std::isinf(value);
134 #ifdef __AIBO_BUILD__ 135 return __isinfd(value);
137 return std::isinf(value);
144 double IntPart = 0.0;
145 float FracPart = (float)modf((
double)number, &IntPart);
148 return (
float)(FracPart >= 0.5 ? IntPart+1 : IntPart);
150 return (
float)(FracPart <= -0.5 ? IntPart-1 : IntPart);
157 MCIsFloatInfinity(new_max) || min > max || min > new_max || value < min || value > max)
161 float CurrentValueRate = (value-min) / (max-min);
163 return min+CurrentValueRate*(new_max-min);
167 int MCCompare(
const std::string& item,
const std::string& a,
const std::string& b)
169 std::string Item = item;
173 boost::algorithm::to_lower(Item);
174 boost::algorithm::to_lower(A);
175 boost::algorithm::to_lower(B);
180 if (Item.size() == 0 || (A.size() == 0 && B.size() == 0))
198 int MCCompare(
const std::string& a,
const std::string& b)
203 boost::algorithm::to_lower(A);
204 boost::algorithm::to_lower(B);
209 if (A.size() == 0 && B.size() == 0)
228 std::ifstream InputFile(file_name.c_str(), std::ios::in | std::ios::binary);
230 if (!InputFile.is_open())
241 std::ifstream InputFile(file_name.c_str(), std::ios::in | std::ios::binary);
243 if (!InputFile.is_open())
247 InputFile.seekg(0, std::ifstream::end);
248 return (
int)InputFile.tellg();
252 #ifndef __AIBO_BUILD__ 253 #if defined(__unix__) && !defined(__ANDROID__) 255 bool MCRealBacktraceEntry(
const std::string& str)
257 if (str.length() < 5)
260 if (str.c_str()[0] !=
'[' || str.c_str()[1] !=
'0' || str.c_str()[2] !=
'x' ||
261 str.c_str()[str.length()-1] !=
']')
271 void MCGenerateBacktrace()
274 int Size = backtrace(Array, 100);
276 char **Messages = backtrace_symbols(Array, Size);
279 for (
int i = 1; i < Size && Messages !=
nullptr; ++i)
281 char* MangledName =
nullptr;
282 char* OffsetBegin =
nullptr;
283 char* OffsetEnd =
nullptr;
286 for (
char *Chr = Messages[i]; *Chr; ++Chr)
292 else if (*Chr ==
'+')
296 else if (*Chr ==
')')
304 if (MangledName && OffsetBegin && OffsetEnd && MangledName < OffsetBegin)
306 *MangledName++ =
'\0';
307 *OffsetBegin++ =
'\0';
311 char *RealName = abi::__cxa_demangle(MangledName, 0, 0, &Status);
319 if (strcmp(
"", MangledName) != 0)
322 if (strcmp(
"main", MangledName) == 0)
332 if (!Messages[i] && strcmp(
"", Messages[i]) != 0 && MCRealBacktraceEntry(Messages[0]))
356 if (!Path.mkpath(Path.absolutePath()))
358 MC_WARNING(
"Cannot create the directory: %s\n", qPrintable(path));
361 MC_LOG(
"Create directory: %s", qPrintable(path));
377 QFileInfoList InfoList = Dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden |
378 QDir::AllDirs | QDir::Files, QDir::DirsFirst);
380 for (
int i = 0; i < InfoList.size(); ++i)
382 if (InfoList[i].isDir())
386 Result = QFile::remove(InfoList[i].absoluteFilePath());
393 Result = Dir.rmdir(Dir.absolutePath());
406 #if defined(__MINGW32__) || defined(__MINGW64__) 407 return QString(path).replace(
'/',
'\\');
409 return QString(path).replace(
'\\',
'/');
418 MC_WARNING(
"Empty path is not valid as a search path.");
427 if (file_name.isEmpty())
432 QStringList Paths = SearchPaths;
434 Paths += QString(
'.');
435 for (
int i = 0; i < Paths.size(); ++i)
439 location =
MCFixPath(Paths[i]+QDir::separator())+file_name;
440 if (QFile::exists(location))
448 MC_LOG(
"Not found (%s)", qPrintable(file_name));
455 if (subdirectory.isEmpty())
460 QStringList Paths = SearchPaths;
462 Paths += QString(
'.');
463 for (
int i = 0; i < Paths.size(); ++i)
467 location =
MCFixPath(Paths[i]+QDir::separator())+subdirectory;
468 if (QDir(location).exists())
470 MC_LOG(
"Found: %s", qPrintable(location));
473 MC_LOG(
"Missing: %s", qPrintable(location));
476 MC_LOG(
"Not found (%s)", qPrintable(subdirectory));
bool MCCreatePath(const QString &path)
Create a new path if it does not exist.
int MCCompare(const std::string &item, const std::string &a, const std::string &b)
Decide whether a string is relative closer to other strings.
int MCGetFileSize(const std::string &file_name)
Get file size.
double MCDoubleInfinity()
Get double infinity.
bool MCIsDoubleInfinity(const double value)
Check a value for double infinity.
#define MC_WARNING(...)
Warning macro.
T MCRand(const T &min, const T &max)
Get a random number generated with standard calls.
void MCSleep(unsigned int msecs)
Wait for some milliseconds.
QString MCGetDataFile(const QString &file_name)
Search a data file.
bool MCIsFloatInfinity(const float value)
Check a value for float infinity.
#define MC_PRINT(color,...)
Print macro with normal letters.
bool MCFileExists(const std::string &file_name)
Check whether a file exists.
QString MCFixPath(const QString &path)
Fix the (back)slashes in a path according to the platform.
static boost::mt19937 Algorithm
Random number generation algorithm.
float MCRound(float number)
Round a float number.
static void SetNewSeed(int seed=(int) time(nullptr))
Set a new global random seed based on the system time.
float MCFloatInfinity()
Get float infinity.
bool MCRemoveDirectory(const QString &dir_str)
Remove a directory with its content.
float MCScaleValue(float value, float min, float max, float new_max)
Scale a value to a new range.
int MCRandSign()
Generate a random sign.
#define MC_LOG(...)
Debug macro.
QString MCGetDataSubdirectory(const QString &subdirectory)
Get a data subdirectory.
void MCAddSearchPath(const QString &path)
Add a location to the search path for data files.