TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
G3D::System Class Reference

OS and processor abstraction. More...

#include <System.h>

Public Types

typedef bool(* OutOfMemoryCallback )(size_t size, bool recoverable)
 

Static Public Member Functions

static void cleanup ()
 
static int cpuSpeedMHz ()
 
static int numCores ()
 
static bool hasCPUID ()
 
static bool hasRDTSC ()
 
static bool hasSSE ()
 
static bool hasSSE2 ()
 
static bool hasSSE3 ()
 
static bool hasMMX ()
 
static bool has3DNow ()
 
static const std::string & cpuVendor ()
 
static G3DEndian machineEndian ()
 
static const std::string & operatingSystem ()
 
static const std::string & cpuArchitecture ()
 
static std::string currentDateString ()
 
static std::string currentTimeString ()
 
static void * malloc (size_t bytes)
 
static void * calloc (size_t n, size_t x)
 
static void * realloc (void *block, size_t bytes)
 
static std::string mallocPerformance ()
 
static void resetMallocPerformanceCounters ()
 
static std::string mallocStatus ()
 
static void free (void *p)
 
static void * alignedMalloc (size_t bytes, size_t alignment)
 
static void alignedFree (void *ptr)
 
static void memcpy (void *dst, const void *src, size_t numBytes)
 
static void memset (void *dst, uint8 value, size_t numBytes)
 
static std::string currentProgramFilename ()
 
static std::string & appName ()
 
static const std::string & version ()
 
static const std::string & build ()
 The optimization status of the G3D library (not the program compiled against it) More...
 
static void sleep (RealTime t)
 
static void consoleClearScreen ()
 
static bool consoleKeyPressed ()
 
static int consoleReadKey ()
 
static RealTime time ()
 
static void beginCycleCount (uint64 &cycleCount)
 
static void endCycleCount (uint64 &cycleCount)
 
static uint64 getCycleCount ()
 
static void setOutOfMemoryCallback (OutOfMemoryCallback c)
 
static OutOfMemoryCallback outOfMemoryCallback ()
 
static void setEnv (const std::string &name, const std::string &value)
 
static const char * getEnv (const std::string &name)
 
static void describeSystem (class TextOutput &t)
 
static void describeSystem (std::string &s)
 
static std::string findDataFile (const std::string &full, bool exceptionIfNotFound=true, bool caseSensitive=true)
 
static void setAppDataDir (const std::string &path)
 

Private Types

enum  CPUIDFunction {
  CPUID_VENDOR_ID = 0x00000000, CPUID_PROCESSOR_FEATURES = 0x00000001, CPUID_NUM_CORES = 0x00000004, CPUID_GET_HIGHEST_FUNCTION = 0x80000000,
  CPUID_EXTENDED_FEATURES = 0x80000001
}
 

Private Member Functions

 System ()
 Used for the singleton instance only. More...
 
void getStandardProcessorExtensions ()
 
void initTime ()
 
void init ()
 

Static Private Member Functions

static Systeminstance ()
 The singleton instance. More...
 
static void cpuid (CPUIDFunction func, uint32 &areg, uint32 &breg, uint32 &creg, uint32 &dreg)
 

Private Attributes

bool m_initialized
 
int m_cpuSpeed
 
bool m_hasCPUID
 
bool m_hasRDTSC
 
bool m_hasMMX
 
bool m_hasSSE
 
bool m_hasSSE2
 
bool m_hasSSE3
 
bool m_has3DNOW
 
bool m_has3DNOW2
 
bool m_hasAMDMMX
 
std::string m_cpuVendor
 
int m_numCores
 
std::string m_appDataDir
 
G3DEndian m_machineEndian
 
std::string m_cpuArch
 
std::string m_operatingSystem
 
struct timeval m_start
 
std::string m_version
 
OutOfMemoryCallback m_outOfMemoryCallback
 
RealTime m_realWorldGetTickTime0
 
uint32 m_highestCPUIDFunction
 

Detailed Description

OS and processor abstraction.

The first time any method is called the processor will be analyzed. Future calls are then fast.

Timing function overview: System::getCycleCount

  • actual cycle count

System::getTick

  • High-resolution time in seconds since program started

System::getLocalTime

  • High-resolution time in seconds since Jan 1, 1970 (because it is stored in a double, this may be less accurate than getTick)

Member Typedef Documentation

typedef bool(* G3D::System::OutOfMemoryCallback)(size_t size, bool recoverable)
Parameters
sizeSize of memory that the system was trying to allocate
recoverableIf true, the system will attempt to allocate again if the callback returns true. If false, malloc is going to return NULL and this invocation is just to notify the application.
Returns
Return true to force malloc to attempt allocation again if the error was recoverable.

Member Enumeration Documentation

Enumerator
CPUID_VENDOR_ID 
CPUID_PROCESSOR_FEATURES 
CPUID_NUM_CORES 
CPUID_GET_HIGHEST_FUNCTION 
CPUID_EXTENDED_FEATURES 
142  {
143  CPUID_VENDOR_ID = 0x00000000,
144  CPUID_PROCESSOR_FEATURES = 0x00000001,
145  CPUID_NUM_CORES = 0x00000004,
146  CPUID_GET_HIGHEST_FUNCTION = 0x80000000,
147  CPUID_EXTENDED_FEATURES = 0x80000001};
Definition: System.h:145
Definition: System.h:147
Definition: System.h:143

Constructor & Destructor Documentation

G3D::System::System ( )
private

Used for the singleton instance only.

102  :
103  m_initialized(false),
104  m_cpuSpeed(0),
105  m_hasCPUID(false),
106  m_hasRDTSC(false),
107  m_hasMMX(false),
108  m_hasSSE(false),
109  m_hasSSE2(false),
110  m_hasSSE3(false),
111  m_has3DNOW(false),
112  m_has3DNOW2(false),
113  m_hasAMDMMX(false),
114  m_cpuVendor("Uninitialized"),
115  m_numCores(1),
117  m_cpuArch("Uninitialized"),
118  m_operatingSystem("Uninitialized"),
119  m_version("Uninitialized"),
123 
124  init();
125 }
OutOfMemoryCallback m_outOfMemoryCallback
Definition: System.h:118
RealTime m_realWorldGetTickTime0
Definition: System.h:127
void init()
Definition: System.cpp:128
std::string m_operatingSystem
Definition: System.h:107
uint32 m_highestCPUIDFunction
Definition: System.h:129
arena_t NULL
Definition: jemalloc_internal.h:624
bool m_has3DNOW
Definition: System.h:95
bool m_hasSSE
Definition: System.h:92
int m_numCores
Definition: System.h:99
std::string m_version
Definition: System.h:117
G3DEndian m_machineEndian
Definition: System.h:105
bool m_hasMMX
Definition: System.h:91
bool m_hasRDTSC
Definition: System.h:90
bool m_hasAMDMMX
Definition: System.h:97
bool m_hasCPUID
Definition: System.h:89
bool m_hasSSE3
Definition: System.h:94
Definition: System.h:50
bool m_has3DNOW2
Definition: System.h:96
bool m_hasSSE2
Definition: System.h:93
bool m_initialized
Definition: System.h:87
std::string m_cpuArch
Definition: System.h:106
std::string m_cpuVendor
Definition: System.h:98
int m_cpuSpeed
Definition: System.h:88

+ Here is the call graph for this function:

Member Function Documentation

void G3D::System::alignedFree ( void *  ptr)
static

Frees memory allocated with alignedMalloc.

1546  {
1547  if (_ptr == NULL) {
1548  return;
1549  }
1550 
1551  size_t alignedPtr = (size_t)_ptr;
1552 
1553  // Back up one word from the pointer the user passed in.
1554  // We now have a pointer to a pointer to the true start
1555  // of the memory block.
1556  size_t* redirectPtr = (size_t*)(alignedPtr - sizeof(void *));
1557 
1558  // Dereference that pointer so that ptr = true start
1559  void* truePtr = (void*)redirectPtr[0];
1560 
1561  debugAssert(isValidHeapPointer((void*)truePtr));
1562  System::free(truePtr);
1563 }
arena_t NULL
Definition: jemalloc_internal.h:624
#define debugAssert(exp)
Definition: debugAssert.h:160
static void free(void *p)
Definition: System.cpp:1473
bool isValidHeapPointer(const void *x)
Definition: debug.h:38

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void * G3D::System::alignedMalloc ( size_t  bytes,
size_t  alignment 
)
static

Guarantees that the start of the array is aligned to the specified number of bytes.

1482  {
1483 
1484  alwaysAssertM(isPow2((uint32)alignment), "alignment must be a power of 2");
1485 
1486  // We must align to at least a word boundary.
1487  alignment = max(alignment, sizeof(void *));
1488 
1489  // Pad the allocation size with the alignment size and the size of
1490  // the redirect pointer. This is the worst-case size we'll need.
1491  // Since the alignment size is at least teh word size, we don't
1492  // need to allocate space for the redirect pointer. We repeat the max here
1493  // for clarity.
1494  size_t totalBytes = bytes + max(alignment, sizeof(void*));
1495 
1496  size_t truePtr = (size_t)System::malloc(totalBytes);
1497 
1498  if (truePtr == 0) {
1499  // malloc returned NULL
1500  return NULL;
1501  }
1502 
1503  debugAssert(isValidHeapPointer((void*)truePtr));
1504  #ifdef G3D_WINDOWS
1505  // The blocks we return will not be valid Win32 debug heap
1506  // pointers because they are offset
1507  // debugAssert(_CrtIsValidPointer((void*)truePtr, totalBytes, TRUE) );
1508  #endif
1509 
1510 
1511  // We want alignedPtr % alignment == 0, which we'll compute with a
1512  // binary AND because 2^n - 1 has the form 1111... in binary.
1513  const size_t bitMask = (alignment - 1);
1514 
1515  // The return pointer will be the next aligned location that is at
1516  // least sizeof(void*) after the true pointer. We need the padding
1517  // to have a place to write the redirect pointer.
1518  size_t alignedPtr = truePtr + sizeof(void*);
1519 
1520  const size_t remainder = alignedPtr & bitMask;
1521 
1522  // Add what we need to make it to the next alignment boundary, but
1523  // if the remainder was zero, let it wrap to zero and don't add
1524  // anything.
1525  alignedPtr += ((alignment - remainder) & bitMask);
1526 
1527  debugAssert((alignedPtr & bitMask) == 0);
1528  debugAssert((alignedPtr - truePtr + bytes) <= totalBytes);
1529 
1530  // Immediately before the aligned location, write the true array location
1531  // so that we can free it correctly.
1532  size_t* redirectPtr = (size_t *)(alignedPtr - sizeof(void *));
1533  redirectPtr[0] = truePtr;
1534 
1535  debugAssert(isValidHeapPointer((void*)truePtr));
1536 
1537  #if defined(G3D_WINDOWS) && defined(G3D_DEBUG)
1538  if (bytes < 0xFFFFFFFF) {
1539  debugAssert( _CrtIsValidPointer((void*)alignedPtr, (int)bytes, TRUE) );
1540  }
1541  #endif
1542  return (void *)alignedPtr;
1543 }
arena_t NULL
Definition: jemalloc_internal.h:624
bool isPow2(int num)
Definition: g3dmath.h:776
T max(const T &x, const T &y)
Definition: g3dmath.h:320
static void * malloc(size_t bytes)
Definition: System.cpp:1441
#define debugAssert(exp)
Definition: debugAssert.h:160
uint32_t uint32
Definition: Define.h:150
#define alwaysAssertM(exp, message)
Definition: debugAssert.h:165
bool isValidHeapPointer(const void *x)
Definition: debug.h:38

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string & G3D::System::appName ( )
static

Name of this program. Note that you can mutate this string to set your app name explicitly.

740  {
741  static std::string n = computeAppName(filenameBase(currentProgramFilename()));
742  return n;
743 }
static std::string currentProgramFilename()
Definition: System.cpp:746
std::string filenameBase(const std::string &filename)
Definition: fileutils.cpp:848
static std::string computeAppName(const std::string &start)
Definition: System.cpp:712

+ Here is the call graph for this function:

void G3D::System::beginCycleCount ( uint64 cycleCount)
inlinestatic

To count the number of cycles a given operation takes:

unsigned long count;
System::beginCycleCount(count);
...
System::endCycleCount(count);
// count now contains the cycle count for the intervening operation.

525  {
526  cycleCount = getCycleCount();
527 }
static uint64 getCycleCount()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const std::string & G3D::System::build ( )
static

The optimization status of the G3D library (not the program compiled against it)

Either "Debug" or "Release", depending on whether _DEBUG was defined at compile-time for the library.

524  {
525  const static std::string b =
526 # ifdef _DEBUG
527  "Debug";
528 # else
529  "Release";
530 # endif
531 
532  return b;
533 }
void * G3D::System::calloc ( size_t  n,
size_t  x 
)
static
1450  {
1451 #ifndef NO_BUFFERPOOL
1452  void* b = System::malloc(n * x);
1453  debugAssertM(b != NULL, "System::malloc returned NULL");
1454  debugAssertM(isValidHeapPointer(b), "System::malloc returned an invalid pointer");
1455  System::memset(b, 0, n * x);
1456  return b;
1457 #else
1458  return ::calloc(n, x);
1459 #endif
1460 }
static void memset(void *dst, uint8 value, size_t numBytes)
Definition: System.cpp:695
arena_t NULL
Definition: jemalloc_internal.h:624
#define debugAssertM(exp, message)
Definition: debugAssert.h:161
static void * malloc(size_t bytes)
Definition: System.cpp:1441
G3D::int16 x
Definition: Vector2int16.h:37
bool isValidHeapPointer(const void *x)
Definition: debug.h:38

+ Here is the call graph for this function:

void G3D::System::cleanup ( )
static

atexit handling code invoked from G3DCleanupHook.

518  {
519  lastFound.clear();
521 }
static Table< std::string, std::string > lastFound
Definition: System.cpp:357
static Array< std::string > directoryArray
Definition: System.cpp:360
void clear(bool shrink=true)
Definition: Array.h:407

+ Here is the call graph for this function:

void G3D::System::consoleClearScreen ( )
static

Clears the console. Console programs only.

837  {
838 # ifdef G3D_WINDOWS
839  (void)system("cls");
840 # else
841  (void)system("clear");
842 # endif
843 }
bool G3D::System::consoleKeyPressed ( )
static

Returns true if a key is waiting. Console programs only.

846  {
847  #ifdef G3D_WINDOWS
848 
849  return _kbhit() != 0;
850 
851  #else
852 
853  static const int STDIN = 0;
854  static bool initialized = false;
855 
856  if (! initialized) {
857  // Use termios to turn off line buffering
858  termios term;
859  tcgetattr(STDIN, &term);
860  term.c_lflag &= ~ICANON;
861  tcsetattr(STDIN, TCSANOW, &term);
862  setbuf(stdin, NULL);
863  initialized = true;
864  }
865 
866  #ifdef G3D_LINUX
867 
868  int bytesWaiting;
869  ioctl(STDIN, FIONREAD, &bytesWaiting);
870  return bytesWaiting;
871 
872  #else
873 
874  timeval timeout;
875  fd_set rdset;
876 
877  FD_ZERO(&rdset);
878  FD_SET(STDIN, &rdset);
879  timeout.tv_sec = 0;
880  timeout.tv_usec = 0;
881 
882  return select(STDIN + 1, &rdset, NULL, NULL, &timeout);
883  #endif
884  #endif
885 }
arena_t NULL
Definition: jemalloc_internal.h:624
int G3D::System::consoleReadKey ( )
static

Blocks until a key is read (use consoleKeyPressed to determine if a key is waiting to be read) then returns the character code for that key.

888  {
889 # ifdef G3D_WINDOWS
890  return _getch();
891 # else
892  char c;
893  (void)read(0, &c, 1);
894  return c;
895 # endif
896 }
#define _getch
Definition: prompt.cpp:21
static const std::string& G3D::System::cpuArchitecture ( )
inlinestatic

e.g., 80686

229  {
230  return instance().m_cpuArch;
231  }
static System & instance()
The singleton instance.
Definition: System.cpp:96
std::string m_cpuArch
Definition: System.h:106

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::System::cpuid ( CPUIDFunction  func,
uint32 areg,
uint32 breg,
uint32 creg,
uint32 dreg 
)
staticprivate

Helper macro to call cpuid functions and return all values

See http://software.intel.com/en-us/articles/intel-64-architecture-processor-topology-enumeration/ or http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/25481.pdf

for description of the arguments.

1704  {
1705 #if ! defined(__PIC__) || defined(__x86_64__)
1706  // AT&T assembler syntax
1707  asm volatile(
1708  "movl $0, %%ecx \n\n" /* Wipe ecx */
1709  "cpuid \n\t"
1710  : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
1711  : "a"(func));
1712 #else
1713  // AT&T assembler syntax
1714  asm volatile(
1715  "pushl %%ebx \n\t" /* save ebx */
1716  "movl $0, %%ecx \n\n" /* Wipe ecx */
1717  "cpuid \n\t"
1718  "movl %%ebx, %1 \n\t" /* save what cpuid just put in %ebx */
1719  "popl %%ebx \n\t" /* restore the old ebx */
1720  : "=a"(eax), "=r"(ebx), "=c"(ecx), "=d"(edx)
1721  : "a"(func));
1722 #endif
1723 }

+ Here is the caller graph for this function:

static int G3D::System::cpuSpeedMHz ( )
inlinestatic

Returns the speed of processor 0 in MHz. Always returns 0 on linux.

174  {
175  return instance().m_cpuSpeed;
176  }
static System & instance()
The singleton instance.
Definition: System.cpp:96
int m_cpuSpeed
Definition: System.h:88

+ Here is the call graph for this function:

static const std::string& G3D::System::cpuVendor ( )
inlinestatic
212  {
213  return instance().m_cpuVendor;
214  }
static System & instance()
The singleton instance.
Definition: System.cpp:96
std::string m_cpuVendor
Definition: System.h:98

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string G3D::System::currentDateString ( )
static

Returns the current date as a string in the form YYYY-MM-DD

1673  {
1674  time_t t1;
1675  ::time(&t1);
1676  tm* t = localtime(&t1);
1677  return format("%d-%02d-%02d", t->tm_year + 1900, t->tm_mon + 1, t->tm_mday);
1678 }
std::string __cdecl format(const char *fmt...) G3D_CHECK_PRINTF_ARGS
static RealTime time()
Definition: System.cpp:934

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string G3D::System::currentProgramFilename ( )
static

Returns the fully qualified filename for the currently running executable.

This is more reliable than arg[0], which may be intentionally set to an incorrect value by a calling program, relative to a now non-current directory, or obfuscated by sym-links.

[Linux] version written by Nicolai Haehnle prefe[email protected][email protected][email protected]gmx.n[email protected]et, http://www.flipcode.com/cgi-bin/msg.cgi?showThread=COTD-getexename&forum=cotd&id=-1

746  {
747  char filename[2048];
748 
749 # ifdef G3D_WINDOWS
750  {
751  GetModuleFileNameA(NULL, filename, sizeof(filename));
752  }
753 # elif defined(G3D_OSX)
754  {
755  // Run the 'ps' program to extract the program name
756  // from the process ID.
757  int pid;
758  FILE* fd;
759  char cmd[80];
760  pid = getpid();
761  sprintf(cmd, "ps -p %d -o comm=\"\"", pid);
762 
763  fd = popen(cmd, "r");
764  int s = fread(filename, 1, sizeof(filename), fd);
765  // filename will contain a newline. Overwrite it:
766  filename[s - 1] = '\0';
767  pclose(fd);
768  }
769 # else
770  {
771  int ret = readlink("/proc/self/exe", filename, sizeof(filename));
772 
773  // In case of an error, leave the handling up to the caller
774  if (ret == -1) {
775  return "";
776  }
777 
778  debugAssert((int)sizeof(filename) > ret);
779 
780  // Ensure proper NULL termination
781  filename[ret] = 0;
782  }
783  #endif
784 
785  return filename;
786 }
arena_t NULL
Definition: jemalloc_internal.h:624
std::string sprintf(CStringRef format, ArgList args)
Definition: format.h:3096
#define debugAssert(exp)
Definition: debugAssert.h:160

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string G3D::System::currentTimeString ( )
static

Returns the current 24-hour local time as a string in the form HH:MM:SS

1680  {
1681  time_t t1;
1682  ::time(&t1);
1683  tm* t = localtime(&t1);
1684  return format("%02d:%02d:%02d", t->tm_hour, t->tm_min, t->tm_sec);
1685 }
std::string __cdecl format(const char *fmt...) G3D_CHECK_PRINTF_ARGS
static RealTime time()
Definition: System.cpp:934

+ Here is the call graph for this function:

void G3D::System::describeSystem ( class TextOutput t)
static

Prints a human-readable description of this machine to the text output stream. Either argument may be NULL.

1611  {
1612 
1613  t.writeSymbols("App", "{");
1614  t.writeNewline();
1615  t.pushIndent();
1616  {
1617  var(t, "Name", System::currentProgramFilename());
1618  char cwd[1024];
1619  (void)getcwd(cwd, 1024);
1620  var(t, "cwd", std::string(cwd));
1621  }
1622  t.popIndent();
1623  t.writeSymbols("}");
1624  t.writeNewline();
1625  t.writeNewline();
1626 
1627  t.writeSymbols("OS", "{");
1628  t.writeNewline();
1629  t.pushIndent();
1630  {
1631  var(t, "Name", System::operatingSystem());
1632  }
1633  t.popIndent();
1634  t.writeSymbols("}");
1635  t.writeNewline();
1636  t.writeNewline();
1637 
1638  t.writeSymbols("CPU", "{");
1639  t.writeNewline();
1640  t.pushIndent();
1641  {
1642  var(t, "Vendor", System::cpuVendor());
1643  var(t, "Architecture", System::cpuArchitecture());
1644  var(t, "hasCPUID", System::hasCPUID());
1645  var(t, "hasMMX", System::hasMMX());
1646  var(t, "hasSSE", System::hasSSE());
1647  var(t, "hasSSE2", System::hasSSE2());
1648  var(t, "hasSSE3", System::hasSSE3());
1649  var(t, "has3DNow", System::has3DNow());
1650  var(t, "hasRDTSC", System::hasRDTSC());
1651  var(t, "numCores", System::numCores());
1652  }
1653  t.popIndent();
1654  t.writeSymbols("}");
1655  t.writeNewline();
1656  t.writeNewline();
1657 
1658  t.writeSymbols("G3D", "{");
1659  t.writeNewline();
1660  t.pushIndent();
1661  {
1662  const char* g3dPath = getenv("G3D9DATA");
1663  var(t, "Link version", G3D_VER);
1664  var(t, "Compile version", System::version());
1665  var(t, "G3D9DATA", std::string(g3dPath ? g3dPath : ""));
1666  }
1667  t.popIndent();
1668  t.writeSymbols("}");
1669  t.writeNewline();
1670  t.writeNewline();
1671 }
static void var(TextOutput &t, const std::string &name, const std::string &val)
Definition: System.cpp:1582
#define G3D_VER
Definition: platform.h:23
static bool has3DNow()
Definition: System.h:208
static const std::string & cpuVendor()
Definition: System.h:212
static std::string currentProgramFilename()
Definition: System.cpp:746
static bool hasRDTSC()
Definition: System.h:188
static bool hasMMX()
Definition: System.h:204
static bool hasSSE3()
Definition: System.h:200
static int numCores()
Definition: System.h:180
static bool hasSSE2()
Definition: System.h:196
static const std::string & version()
Definition: System.h:317
static const std::string & cpuArchitecture()
Definition: System.h:229
static bool hasSSE()
Definition: System.h:192
static bool hasCPUID()
Definition: System.h:184
static const std::string & operatingSystem()
Definition: System.h:224

+ Here is the call graph for this function:

void G3D::System::describeSystem ( std::string &  s)
static
1603  {
1604 
1605  TextOutput t;
1606  describeSystem(t);
1607  t.commitString(s);
1608 }
static void describeSystem(class TextOutput &t)
Definition: System.cpp:1610

+ Here is the call graph for this function:

void G3D::System::endCycleCount ( uint64 cycleCount)
inlinestatic
530  {
531 #ifndef G3D_OSX
532  cycleCount = getCycleCount() - cycleCount;
533 #else
534  AbsoluteTime end = UpTime();
535  Nanoseconds diffNS =
536  AbsoluteDeltaToNanoseconds(end, UInt64ToUnsignedWide(cycleCount));
537  cycleCount =
538  (uint64) ((double) (instance().m_OSXCPUSpeed) *
539  (double) UnsignedWideToUInt64(diffNS) * instance().m_secondsPerNS);
540 #endif
541 }
static System & instance()
The singleton instance.
Definition: System.cpp:96
uint64_t uint64
Definition: g3dmath.h:170
static uint64 getCycleCount()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string G3D::System::findDataFile ( const std::string &  full,
bool  exceptionIfNotFound = true,
bool  caseSensitive = true 
)
static

Tries to locate the resource by looking in related directories. If found, returns the full path to the resource, otherwise returns the empty string.

Looks in:

- Literal interpretation of full (i.e., if it contains a fully-qualified name)
- Last directory in which a file was found
- Current directory
- System::appDataDir (which is usually GApp::Settings.dataDir, which defaults to the directory containing the program binary)
- $G3D9DATA directory
- System::appDataDir() + "data/"  (note that this may be a zipfile named "data" with no extension)
- System::appDataDir() + "data.zip/"
- ../data-files/  (windows)
- ../../data-files/ (windows)
- ../../../data-files/ (windows)

Plus the following subdirectories of those:

  • cubemap
  • gui
  • font
  • icon
  • models
  • image
  • sky
  • md2
  • md3
  • ifs
  • 3ds
Parameters
exceptionIfNotFoundIf true and the file is not found, throws G3D::FileNotFound.
367  {
368 MARK_LOG();
369 
370  const std::string full = FilePath::expandEnvironmentVariables(_full);
371 
372  // First check if the file exists as requested. This will go
373  // through the FileSystemCache, so most calls do not touch disk.
374  if (FileSystem::exists(full, true, caseSensitive)) {
375  return full;
376  }
377 
378 MARK_LOG();
379  // Now check where we previously found this file.
380  std::string* last = lastFound.getPointer(full);
381  if (last != NULL) {
382  if (FileSystem::exists(*last, true, caseSensitive)) {
383  // Even if cwd has changed the file is still present.
384  // We won't notice if it has been deleted, however.
385  return *last;
386  } else {
387  // Remove this from the cache it is invalid
388  lastFound.remove(full);
389  }
390  }
391 
392 MARK_LOG();
393 
394  const std::string initialAppDataDir(instance().m_appDataDir);
395  const char* g3dPath = getenv("G3D9DATA");
396 
397  if (directoryArray.size() == 0) {
398  // Initialize the directory array
399  RealTime t0 = System::time();
400 
401  Array<std::string> baseDirArray;
402 
403  baseDirArray.append(FileSystem::currentDirectory());
404 MARK_LOG();
405  if (! initialAppDataDir.empty()) {
406 MARK_LOG();
407  baseDirArray.append(initialAppDataDir);
408  baseDirArray.append(pathConcat(initialAppDataDir, "data"));
409  baseDirArray.append(pathConcat(initialAppDataDir, "data.zip"));
410  } else {
411 MARK_LOG();
412  baseDirArray.append("data");
413  baseDirArray.append("data.zip");
414  }
415 MARK_LOG();
416 
417 # ifdef G3D_WINDOWS
418  if (g3dPath == NULL) {
419  // If running the demos under visual studio from the G3D.sln file,
420  // this will locate the data directory.
421  const char* paths[] = {"../data-files/", "../../data-files/", "../../../data-files/", NULL};
422  for (int i = 0; paths[i]; ++i) {
423  if (FileSystem::exists(pathConcat(paths[i], "G3D-DATA-README.TXT"), true, caseSensitive)) {
424  g3dPath = paths[i];
425  break;
426  }
427  }
428  }
429 # endif
430 
431  if (g3dPath && (initialAppDataDir != g3dPath)) {
432  baseDirArray.append(g3dPath);
433  }
434 
435  static const std::string subdirs[] =
436  {"font", "gui", "shader", "model", "cubemap", "icon", "material", "image", "md2", "md3", "ifs", "3ds", "sky", "music", "sound", "scene", ""};
437  for (int j = 0; j < baseDirArray.size(); ++j) {
438  std::string d = baseDirArray[j];
439 //logPrintf("%s", d.c_str());
440  if ((d == "") || FileSystem::exists(d)) {
441 //logPrintf(" exists\n");
443  for (int i = 0; ! subdirs[i].empty(); ++i) {
444  const std::string& p = pathConcat(d, subdirs[i]);
445  if (FileSystem::exists(p, true, caseSensitive)) {
447  }
448  }
449  } else {
450 //logPrintf(" does not exist\n");
451  }
452  }
453 
454  logLazyPrintf("Initializing System::findDataFile took %fs\n", System::time() - t0);
455 
456  }
457 MARK_LOG();
458 
459  for (int i = 0; i < directoryArray.size(); ++i) {
460  const std::string& p = pathConcat(directoryArray[i], full);
461  if (FileSystem::exists(p, true, caseSensitive)) {
462  lastFound.set(full, p);
463  return p;
464  }
465  }
466 MARK_LOG();
467 
468  if (errorIfNotFound) {
469  // Generate an error message. Delay this operation until we know that we need it;
470  // otherwise all of the string concatenation would run on each successful find.
471  std::string locations;
472  for (int i = 0; i < directoryArray.size(); ++i) {
473  locations += "\'" + pathConcat(directoryArray[i], full) + "'\n";
474  }
475 MARK_LOG();
476 
477  std::string msg = "Could not find '" + full + "'.\n\n";
478  msg += " cwd = '" + FileSystem::currentDirectory() + "'\n";
479  if (g3dPath) {
480  msg += " G3D9DATA = '" + std::string(g3dPath) + "'";
481  if (! FileSystem::exists(g3dPath, true, caseSensitive)) {
482  msg += " (illegal path!)";
483  }
484  msg += "\n";
485  } else {
486  msg += " G3D9DATA = (environment variable is not defined)\n";
487  }
488 MARK_LOG();
489  msg += " GApp::Settings.dataDir = '" + initialAppDataDir + "'";
490  if (! FileSystem::exists(initialAppDataDir, true, caseSensitive)) {
491  msg += " (illegal path!)";
492  }
493  msg += "\n";
494 
495  msg += "\nFilenames tested:\n" + locations;
496 
497 MARK_LOG();
498 logPrintf("%s\n", msg.c_str());
499  throw FileNotFound(full, msg);
500  alwaysAssertM(false, msg);
501  }
502 MARK_LOG();
503 
504  // Not found
505  return "";
506 }
void logLazyPrintf(const char *fmt,...)
Definition: Log.cpp:33
#define MARK_LOG()
Definition: System.cpp:362
static std::string expandEnvironmentVariables(const std::string &path)
Replaces $VAR and patterns with the corresponding environment variable. Throws std::string if the en...
Definition: FileSystem.cpp:949
static System & instance()
The singleton instance.
Definition: System.cpp:96
arena_t NULL
Definition: jemalloc_internal.h:624
static Table< std::string, std::string > lastFound
Definition: System.cpp:357
double RealTime
Definition: G3DGameUnits.h:27
static bool exists(const std::string &f, bool trustCache=true, bool caseSensitive=true)
Definition: FileSystem.h:401
static Array< std::string > directoryArray
Definition: System.cpp:360
static std::string currentDirectory()
Definition: FileSystem.h:364
int size() const
Definition: Array.h:430
std::string pathConcat(const std::string &dirname, const std::string &file)
Definition: fileutils.cpp:47
static RealTime time()
Definition: System.cpp:934
void logPrintf(const char *fmt,...)
Definition: Log.cpp:25
std::string m_appDataDir
Definition: System.h:103
void append(const T &value)
Definition: Array.h:583
#define alwaysAssertM(exp, message)
Definition: debugAssert.h:165

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::System::free ( void *  p)
static

Free data allocated with System::malloc.

Threadsafe on Win32.

1473  {
1474 #ifndef NO_BUFFERPOOL
1475  bufferpool->free(p);
1476 #else
1477  return ::free(p);
1478 #endif
1479 }
void free(UserPtr ptr)
Definition: System.cpp:1327
static BufferPool * bufferpool
Definition: System.cpp:1399

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static uint64 G3D::System::getCycleCount ( )
static

+ Here is the caller graph for this function:

const char * G3D::System::getEnv ( const std::string &  name)
static

Get an environment variable for the current process. Returns NULL if the variable doesn't exist.

1577  {
1578  return getenv(name.c_str());
1579 }
void G3D::System::getStandardProcessorExtensions ( )
private

Called from init()

555  {
556 #if ! defined(G3D_OSX) || defined(G3D_OSX_INTEL)
557  if (! m_hasCPUID) {
558  return;
559  }
560 
561  uint32 eaxreg = 0, ebxreg = 0, ecxreg = 0, features = 0;
562 
563  cpuid(CPUID_PROCESSOR_FEATURES, eaxreg, ebxreg, ecxreg, features);
564 
565 # define checkBit(var, bit) ((var & (1 << bit)) ? true : false)
566 
567  m_hasRDTSC = checkBit(features, 4);
568  m_hasMMX = checkBit(features, 23);
569  m_hasSSE = checkBit(features, 25);
570  m_hasSSE2 = checkBit(features, 26);
571  // Bit 28 is HTT; not checked by G3D
572 
573  m_hasSSE3 = checkBit(ecxreg, 0);
574 
576  cpuid(CPUID_EXTENDED_FEATURES, eaxreg, ebxreg, ecxreg, features);
577  m_hasAMDMMX = checkBit(features, 22); // Only on AMD
578  m_has3DNOW = checkBit(features, 31); // Only on AMD
579  m_has3DNOW2 = checkBit(features, 30); // Only on AMD
580  } else {
581  m_hasAMDMMX = false;
582  m_has3DNOW = false;
583  m_has3DNOW2 = false;
584  }
585 
586 # undef checkBit
587 #endif
588 }
static void cpuid(CPUIDFunction func, uint32 &areg, uint32 &breg, uint32 &creg, uint32 &dreg)
Definition: System.cpp:1704
uint32 m_highestCPUIDFunction
Definition: System.h:129
bool m_has3DNOW
Definition: System.h:95
bool m_hasSSE
Definition: System.h:92
Definition: System.h:147
bool m_hasMMX
Definition: System.h:91
bool m_hasRDTSC
Definition: System.h:90
uint32_t uint32
Definition: Define.h:150
bool m_hasAMDMMX
Definition: System.h:97
bool m_hasCPUID
Definition: System.h:89
#define checkBit(var, bit)
bool m_hasSSE3
Definition: System.h:94
bool m_has3DNOW2
Definition: System.h:96
bool m_hasSSE2
Definition: System.h:93

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool G3D::System::has3DNow ( )
inlinestatic
208  {
209  return instance().m_has3DNOW;
210  }
static System & instance()
The singleton instance.
Definition: System.cpp:96
bool m_has3DNOW
Definition: System.h:95

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool G3D::System::hasCPUID ( )
inlinestatic
184  {
185  return instance().m_hasCPUID;
186  }
static System & instance()
The singleton instance.
Definition: System.cpp:96
bool m_hasCPUID
Definition: System.h:89

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool G3D::System::hasMMX ( )
inlinestatic
204  {
205  return instance().m_hasMMX;
206  }
static System & instance()
The singleton instance.
Definition: System.cpp:96
bool m_hasMMX
Definition: System.h:91

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool G3D::System::hasRDTSC ( )
inlinestatic
188  {
189  return instance().m_hasRDTSC;
190  }
static System & instance()
The singleton instance.
Definition: System.cpp:96
bool m_hasRDTSC
Definition: System.h:90

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool G3D::System::hasSSE ( )
inlinestatic
192  {
193  return instance().m_hasSSE;
194  }
static System & instance()
The singleton instance.
Definition: System.cpp:96
bool m_hasSSE
Definition: System.h:92

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool G3D::System::hasSSE2 ( )
inlinestatic
196  {
197  return instance().m_hasSSE2;
198  }
static System & instance()
The singleton instance.
Definition: System.cpp:96
bool m_hasSSE2
Definition: System.h:93

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool G3D::System::hasSSE3 ( )
inlinestatic
200  {
201  return instance().m_hasSSE3;
202  }
static System & instance()
The singleton instance.
Definition: System.cpp:96
bool m_hasSSE3
Definition: System.h:94

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::System::init ( )
private
128  {
129  // NOTE: Cannot use most G3D data structures or utility functions
130  // in here because they are not initialized.
131 
132  if (m_initialized) {
133  return;
134  } else {
135  m_initialized = true;
136  }
137 
139 
141 
143  // Process the CPUID information
144  if (m_hasCPUID) {
145  // We read the standard CPUID level 0x00000000 which should
146  // be available on every x86 processor. This fills out
147  // a string with the processor vendor tag.
148  unsigned int eaxreg = 0, ebxreg = 0, ecxreg = 0, edxreg = 0;
149 
150  cpuid(CPUID_VENDOR_ID, eaxreg, ebxreg, ecxreg, edxreg);
151 
152  {
153  char c[100];
154  // Then we connect the single register values to the vendor string
155  *((unsigned int*) c) = ebxreg;
156  *((unsigned int*) (c + 4)) = edxreg;
157  *((unsigned int*) (c + 8)) = ecxreg;
158  c[12] = '\0';
159  m_cpuVendor = c;
160  }
161 
162  switch (ebxreg) {
163  case 0x756E6547: // GenuineIntel
164  m_cpuArch = "Intel Processor";
165  break;
166 
167  case 0x68747541: // AuthenticAMD
168  m_cpuArch = "AMD Processor";
169  break;
170 
171  default:
172  m_cpuArch = "Unknown Processor Vendor";
173  break;
174  }
175 
176 
177  unsigned int highestFunction = eaxreg;
178  if (highestFunction >= CPUID_NUM_CORES) {
179  cpuid(CPUID_NUM_CORES, eaxreg, ebxreg, ecxreg, edxreg);
180  // Number of cores is in (eax>>26) + 1
181  m_numCores = (eaxreg >> 26) + 1;
182  }
183 
184  cpuid(CPUID_GET_HIGHEST_FUNCTION, m_highestCPUIDFunction, ebxreg, ecxreg, edxreg);
185  }
186 
187 
188  // Get the operating system name (also happens to read some other information)
189 # ifdef G3D_WINDOWS
190  HRESULT r = OleInitialize(NULL);
191  // Note that this overrides some of the values computed above
192  bool success = RegistryUtil::readInt32
193  ("HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
194  "~MHz", m_cpuSpeed);
195  HRESULT s = OleInitialize(NULL);
196  SYSTEM_INFO systemInfo;
197  GetSystemInfo(&systemInfo);
198  const char* arch = NULL;
199  switch (systemInfo.wProcessorArchitecture) {
200  case PROCESSOR_ARCHITECTURE_INTEL:
201  arch = "x86 Intel";
202  break;
203 
204  case PROCESSOR_ARCHITECTURE_AMD64:
205  arch = "x64 Intel/AMD";
206  break;
207 
208  case PROCESSOR_ARCHITECTURE_ARM:
209  arch = "ARM";
210  break;
211 
212  default:
213  arch = "Unknown";
214  break;
215  }
216 
217  m_numCores = systemInfo.dwNumberOfProcessors;
218  uint64_t maxAddr = reinterpret_cast<uint64_t>(systemInfo.lpMaximumApplicationAddress);
219  {
220  char c[1024];
221  sprintf(c, "%d - %s cores",
222  systemInfo.dwNumberOfProcessors,
223  arch);
224  m_cpuArch = c;
225  }
226 
227  OSVERSIONINFO osVersionInfo;
228  osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
229  success = GetVersionEx(&osVersionInfo) != 0;
230 
231  if (success) {
232  char c[1000];
233  sprintf(c, "Windows %d.%d build %d Platform %d %s",
234  osVersionInfo.dwMajorVersion,
235  osVersionInfo.dwMinorVersion,
236  osVersionInfo.dwBuildNumber,
237  osVersionInfo.dwPlatformId,
238  osVersionInfo.szCSDVersion);
239  m_operatingSystem = c;
240  } else {
241  m_operatingSystem = "Windows";
242  }
243 
244 # elif defined(G3D_LINUX) || defined(G3D_FREEBSD)
245 
246  {
247  // Find the operating system using the 'uname' command
248  FILE* f = popen("uname -a", "r");
249 
250  int len = 100;
251  char* r = (char*)::malloc(len * sizeof(char));
252  (void)fgets(r, len, f);
253  // Remove trailing newline
254  if (r[strlen(r) - 1] == '\n') {
255  r[strlen(r) - 1] = '\0';
256  }
257  fclose(f);
258  f = NULL;
259 
260  m_operatingSystem = r;
261  ::free(r);
262  }
263 
264 # elif defined(G3D_OSX)
265 
266  // Operating System:
267  SInt32 macVersion;
268  Gestalt(gestaltSystemVersion, &macVersion);
269 
270  int major = (macVersion >> 8) & 0xFF;
271  int minor = (macVersion >> 4) & 0xF;
272  int revision = macVersion & 0xF;
273 
274  {
275  char c[1000];
276  sprintf(c, "OS X %x.%x.%x", major, minor, revision);
277  m_operatingSystem = c;
278  }
279 
280  // Clock Cycle Timing Information:
281  Gestalt('pclk', &m_OSXCPUSpeed);
282  m_cpuSpeed = iRound((double)m_OSXCPUSpeed / (1024 * 1024));
283  m_secondsPerNS = 1.0 / 1.0e9;
284 
285  // System Architecture:
286  const NXArchInfo* pInfo = NXGetLocalArchInfo();
287 
288  if (pInfo) {
289  m_cpuArch = pInfo->description;
290 
291  switch (pInfo->cputype) {
292  case CPU_TYPE_POWERPC:
293  switch(pInfo->cpusubtype){
294  case CPU_SUBTYPE_POWERPC_750:
295  case CPU_SUBTYPE_POWERPC_7400:
296  case CPU_SUBTYPE_POWERPC_7450:
297  m_cpuVendor = "Motorola";
298  break;
299  case CPU_SUBTYPE_POWERPC_970:
300  m_cpuVendor = "IBM";
301  break;
302  }
303  break;
304 
305  case CPU_TYPE_I386:
306  m_cpuVendor = "Intel";
307  break;
308  }
309  }
310 # endif
311 
312  initTime();
313 
315 
317 }
static void cpuid(CPUIDFunction func, uint32 &areg, uint32 &breg, uint32 &creg, uint32 &dreg)
Definition: System.cpp:1704
void getStandardProcessorExtensions()
Definition: System.cpp:555
Definition: System.h:145
std::string m_operatingSystem
Definition: System.h:107
int iRound(double fValue)
Definition: g3dmath.h:226
uint32 m_highestCPUIDFunction
Definition: System.h:129
static bool checkForCPUID()
Definition: System.cpp:546
arena_t NULL
Definition: jemalloc_internal.h:624
static std::string currentProgramFilename()
Definition: System.cpp:746
int m_numCores
Definition: System.h:99
static void * malloc(size_t bytes)
Definition: System.cpp:1441
std::string m_version
Definition: System.h:117
static std::string parent(const std::string &path)
Definition: FileSystem.cpp:795
std::string sprintf(CStringRef format, ArgList args)
Definition: format.h:3096
G3DEndian m_machineEndian
Definition: System.h:105
unsigned __int64 uint64_t
Definition: stdint.h:90
bool m_hasCPUID
Definition: System.h:89
static void free(void *p)
Definition: System.cpp:1473
Definition: System.h:143
static G3DEndian checkEndian()
Definition: System.cpp:536
void initTime()
Definition: System.cpp:899
static void getG3DVersion(std::string &s)
Definition: System.cpp:320
bool m_initialized
Definition: System.h:87
std::string m_cpuArch
Definition: System.h:106
std::string m_cpuVendor
Definition: System.h:98
std::string m_appDataDir
Definition: System.h:103
int m_cpuSpeed
Definition: System.h:88

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::System::initTime ( )
private

Called from init()

899  {
900  #ifdef G3D_WINDOWS
901  if (QueryPerformanceFrequency(&m_counterFrequency)) {
902  QueryPerformanceCounter(&m_start);
903  }
904 
905  struct _timeb t;
906  _ftime(&t);
907 
908  m_realWorldGetTickTime0 = (RealTime)t.time - t.timezone * G3D::MINUTE + (t.dstflag ? G3D::HOUR : 0);
909 
910  #else
911  gettimeofday(&m_start, NULL);
912  // "sse" = "seconds since epoch". The time
913  // function returns the seconds since the epoch
914  // GMT (perhaps more correctly called UTC).
915  time_t gmt = ::time(NULL);
916 
917  // No call to free or delete is needed, but subsequent
918  // calls to asctime, ctime, mktime, etc. might overwrite
919  // local_time_vals.
920  tm* localTimeVals = localtime(&gmt);
921 
922  time_t local = gmt;
923 
924  if (localTimeVals) {
925  // tm_gmtoff is already corrected for daylight savings.
926  local = local + localTimeVals->tm_gmtoff;
927  }
928 
930  #endif
931 }
RealTime m_realWorldGetTickTime0
Definition: System.h:127
Definition: G3DGameUnits.h:32
arena_t NULL
Definition: jemalloc_internal.h:624
double RealTime
Definition: G3DGameUnits.h:27
Definition: G3DGameUnits.h:32
#define local
Definition: gzguts.h:107
struct timeval m_start
Definition: System.h:114
static RealTime time()
Definition: System.cpp:934

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

System & G3D::System::instance ( )
staticprivate

The singleton instance.

Used instead of a global variable to ensure that the order of intialization is correct, which is critical because other globals may allocate memory using System::malloc.

96  {
97  static System thesystem;
98  return thesystem;
99 }
System()
Used for the singleton instance only.
Definition: System.cpp:102

+ Here is the caller graph for this function:

static G3DEndian G3D::System::machineEndian ( )
inlinestatic

Returns the endianness of this machine.

219  {
220  return instance().m_machineEndian;
221  }
static System & instance()
The singleton instance.
Definition: System.cpp:96
G3DEndian m_machineEndian
Definition: System.h:105

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void * G3D::System::malloc ( size_t  bytes)
static

Uses pooled storage to optimize small allocations (1 byte to 5 kilobytes). Can be 10x to 100x faster than calling malloc or new.

The result must be freed with free.

Threadsafe on Win32.

See also
calloc realloc OutOfMemoryCallback free
1441  {
1442 #ifndef NO_BUFFERPOOL
1443  initMem();
1444  return bufferpool->malloc(bytes);
1445 #else
1446  return ::malloc(bytes);
1447 #endif
1448 }
static BufferPool * bufferpool
Definition: System.cpp:1399
UserPtr malloc(MemBlock *pool, int &poolSize, size_t bytes)
Definition: System.cpp:1107
void initMem()
Definition: System.cpp:1429

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string G3D::System::mallocPerformance ( )
static

Returns a string describing how well System::malloc is using its internal pooled storage. "heap" memory was slow to allocate; the other data sizes are comparatively fast.

1401  {
1402 #ifndef NO_BUFFERPOOL
1403  return bufferpool->performance();
1404 #else
1405  return "NO_BUFFERPOOL";
1406 #endif
1407 }
std::string performance() const
Definition: System.cpp:1367
static BufferPool * bufferpool
Definition: System.cpp:1399

+ Here is the call graph for this function:

std::string G3D::System::mallocStatus ( )
static

Returns a string describing the current usage of the buffer pools used for optimizing System::malloc.

1409  {
1410 #ifndef NO_BUFFERPOOL
1411  return bufferpool->status();
1412 #else
1413  return "NO_BUFFERPOOL";
1414 #endif
1415 }
std::string status() const
Definition: System.cpp:1390
static BufferPool * bufferpool
Definition: System.cpp:1399

+ Here is the call graph for this function:

void G3D::System::memcpy ( void *  dst,
const void *  src,
size_t  numBytes 
)
static

An implementation of memcpy that may be up to 2x as fast as the C library one on some processors. Guaranteed to have the same behavior as memcpy in all cases.

643  {
644 #if defined(G3D_WINDOWS) && defined(_M_IX86) && !defined(__MINGW32__) /* G3DFIX: Don't check if on 64-bit Windows platforms or using MinGW */
645  // The overhead of our memcpy seems to only be worthwhile on large arrays
646  if (((size_t)dst % 16 == 0) && ((size_t)src % 16 == 0) && (numBytes > 3400000)) {
647  memcpyMMX(dst, src, numBytes);
648  } else {
649  ::memcpy(dst, src, numBytes);
650  }
651 #else
652  ::memcpy(dst, src, numBytes);
653 #endif
654 }
static void memcpy(void *dst, const void *src, size_t numBytes)
Definition: System.cpp:643

+ Here is the caller graph for this function:

void G3D::System::memset ( void *  dst,
uint8  value,
size_t  numBytes 
)
static

An implementation of memset that may be up to 2x as fast as the C library one on some processors. Guaranteed to have the same behavior as memset in all cases.

Michael Herf's fastest memset. n32 must be filled with the same character repeated.

695  {
696  alwaysAssertM(dst != NULL, "Cannot memset NULL address.");
697 #if defined(G3D_WINDOWS) && defined(_M_IX86) && !defined(__MINGW32__) /* G3DFIX: Don't check if on 64-bit Windows platforms or using MinGW */
698  if ((((size_t)dst % 16) == 0) && (numBytes >= 512*1024)) {
699  uint32 v = value;
700  v = v + (v << 8) + (v << 16) + (v << 24);
701  G3D::memfill(dst, v, numBytes);
702  } else {
703  ::memset(dst, value, numBytes);
704  }
705 #else
706  ::memset(dst, value, numBytes);
707 #endif
708 }
static void memset(void *dst, uint8 value, size_t numBytes)
Definition: System.cpp:695
arena_t NULL
Definition: jemalloc_internal.h:624
uint32_t uint32
Definition: Define.h:150
const FieldDescriptor value
Definition: descriptor.h:1522
#define alwaysAssertM(exp, message)
Definition: debugAssert.h:165

+ Here is the caller graph for this function:

static int G3D::System::numCores ( )
inlinestatic

Returns the number of logical processor cores (i.e., the number of execution units for threads)

180  {
181  return instance().m_numCores;
182  }
static System & instance()
The singleton instance.
Definition: System.cpp:96
int m_numCores
Definition: System.h:99

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static const std::string& G3D::System::operatingSystem ( )
inlinestatic

e.g., "Windows", "GNU/Linux"

224  {
225  return instance().m_operatingSystem;
226  }
std::string m_operatingSystem
Definition: System.h:107
static System & instance()
The singleton instance.
Definition: System.cpp:96

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static OutOfMemoryCallback G3D::System::outOfMemoryCallback ( )
inlinestatic

When System::malloc fails to allocate memory because the system is out of memory, it invokes this handler (if it is not NULL). The argument to the callback is the amount of memory that malloc was trying to allocate when it ran out. If the callback returns true, System::malloc will attempt to allocate the memory again. If the callback returns false, then System::malloc will return NULL.

You can use outOfMemoryCallback to free data structures or to register the failure.

398  {
400  }
OutOfMemoryCallback m_outOfMemoryCallback
Definition: System.h:118
static System & instance()
The singleton instance.
Definition: System.cpp:96

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void * G3D::System::realloc ( void *  block,
size_t  bytes 
)
static

Version of realloc that works with System::malloc.

1463  {
1464 #ifndef NO_BUFFERPOOL
1465  initMem();
1466  return bufferpool->realloc(block, bytes);
1467 #else
1468  return ::realloc(block, bytes);
1469 #endif
1470 }
UserPtr realloc(UserPtr ptr, size_t bytes)
Definition: System.cpp:1197
static BufferPool * bufferpool
Definition: System.cpp:1399
void initMem()
Definition: System.cpp:1429

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void G3D::System::resetMallocPerformanceCounters ( )
static
1418  {
1419 #ifndef NO_BUFFERPOOL
1420  bufferpool->totalMallocs = 0;
1424 #endif
1425 }
int mallocsFromTinyPool
Definition: System.cpp:1136
static BufferPool * bufferpool
Definition: System.cpp:1399
int mallocsFromMedPool
Definition: System.cpp:1138
int mallocsFromSmallPool
Definition: System.cpp:1137
int totalMallocs
Definition: System.cpp:1135
void G3D::System::setAppDataDir ( const std::string &  path)
static

Sets the path that the application is using as its data directory. Used by findDataDir as an initial search location. GApp sets this upon constrution.

509  {
510  instance().m_appDataDir = path;
511 
512  // Wipe the findDataFile cache
513  lastFound.clear();
515 }
static System & instance()
The singleton instance.
Definition: System.cpp:96
static Table< std::string, std::string > lastFound
Definition: System.cpp:357
static Array< std::string > directoryArray
Definition: System.cpp:360
void clear(bool shrink=true)
Definition: Array.h:407
std::string m_appDataDir
Definition: System.h:103

+ Here is the call graph for this function:

void G3D::System::setEnv ( const std::string &  name,
const std::string &  value 
)
static

Set an environment variable for the current process

1566  {
1567  std::string cmd = name + "=" + value;
1568 # ifdef G3D_WINDOWS
1569  _putenv(cmd.c_str());
1570 # else
1571  // Many linux implementations of putenv expect char*
1572  putenv(const_cast<char*>(cmd.c_str()));
1573 # endif
1574 }
const FieldDescriptor value
Definition: descriptor.h:1522
static void G3D::System::setOutOfMemoryCallback ( OutOfMemoryCallback  c)
inlinestatic
383  {
385  }
OutOfMemoryCallback m_outOfMemoryCallback
Definition: System.h:118
static System & instance()
The singleton instance.
Definition: System.cpp:96

+ Here is the call graph for this function:

void G3D::System::sleep ( RealTime  t)
static

Causes the current thread to yield for the specified duration and consume almost no CPU. The sleep will be extremely precise; it uses System::time() to calibrate the exact yeild time.

15 {
16  ::Sleep( ms );
17 }

+ Here is the caller graph for this function:

RealTime G3D::System::time ( )
static

The actual time (measured in seconds since Jan 1 1970 midnight).

Adjusted for local timezone and daylight savings time. This is as accurate and fast as getCycleCount().

934  {
935 # ifdef G3D_WINDOWS
936  LARGE_INTEGER now;
937  QueryPerformanceCounter(&now);
938 
939  return ((RealTime)(now.QuadPart - instance().m_start.QuadPart) /
940  instance().m_counterFrequency.QuadPart) + instance().m_realWorldGetTickTime0;
941 # else
942  // Linux resolution defaults to 100Hz.
943  // There is no need to do a separate RDTSC call as gettimeofday
944  // actually uses RDTSC when on systems that support it, otherwise
945  // it uses the system clock.
946  struct timeval now;
947  gettimeofday(&now, NULL);
948 
949  return (now.tv_sec - instance().m_start.tv_sec) +
950  (now.tv_usec - instance().m_start.tv_usec) / 1e6
952 # endif
953 }
RealTime m_realWorldGetTickTime0
Definition: System.h:127
static System & instance()
The singleton instance.
Definition: System.cpp:96
arena_t NULL
Definition: jemalloc_internal.h:624
double RealTime
Definition: G3DGameUnits.h:27
struct timeval m_start
Definition: System.h:114

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static const std::string& G3D::System::version ( )
inlinestatic

G3D Version string

317  {
318  return instance().m_version;
319  }
static System & instance()
The singleton instance.
Definition: System.cpp:96
std::string m_version
Definition: System.h:117

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

std::string G3D::System::m_appDataDir
private

this holds the data directory set by the application (currently GApp) for use by findDataFile

std::string G3D::System::m_cpuArch
private
int G3D::System::m_cpuSpeed
private
std::string G3D::System::m_cpuVendor
private
bool G3D::System::m_has3DNOW
private
bool G3D::System::m_has3DNOW2
private
bool G3D::System::m_hasAMDMMX
private
bool G3D::System::m_hasCPUID
private
bool G3D::System::m_hasMMX
private
bool G3D::System::m_hasRDTSC
private
bool G3D::System::m_hasSSE
private
bool G3D::System::m_hasSSE2
private
bool G3D::System::m_hasSSE3
private
uint32 G3D::System::m_highestCPUIDFunction
private
bool G3D::System::m_initialized
private
G3DEndian G3D::System::m_machineEndian
private
int G3D::System::m_numCores
private
std::string G3D::System::m_operatingSystem
private
OutOfMemoryCallback G3D::System::m_outOfMemoryCallback
private
RealTime G3D::System::m_realWorldGetTickTime0
private

The Real-World time of System::getTick() time 0. Set by initTime

struct timeval G3D::System::m_start
private
std::string G3D::System::m_version
private

The documentation for this class was generated from the following files: