Core/Dependencies: Update G3D to version 8.01
This commit is contained in:
@@ -282,6 +282,10 @@ bool AABox::culledBy(
|
||||
return false;
|
||||
}
|
||||
|
||||
void AABox::getBounds(Sphere& s) const {
|
||||
s.center = center();
|
||||
s.radius = extent().length() / 2;
|
||||
}
|
||||
|
||||
bool AABox::intersects(const class Sphere& sphere) const {
|
||||
double d = 0;
|
||||
|
||||
@@ -23,23 +23,23 @@
|
||||
namespace G3D {
|
||||
|
||||
void logPrintf(const char* fmt, ...) {
|
||||
va_list arg_list;
|
||||
va_start(arg_list, fmt);
|
||||
va_list arg_list;
|
||||
va_start(arg_list, fmt);
|
||||
Log::common()->vprintf(fmt, arg_list);
|
||||
va_end(arg_list);
|
||||
}
|
||||
|
||||
|
||||
void logLazyPrintf(const char* fmt, ...) {
|
||||
va_list arg_list;
|
||||
va_start(arg_list, fmt);
|
||||
va_list arg_list;
|
||||
va_start(arg_list, fmt);
|
||||
Log::common()->lazyvprintf(fmt, arg_list);
|
||||
va_end(arg_list);
|
||||
}
|
||||
|
||||
Log* Log::commonLog = NULL;
|
||||
|
||||
Log::Log(const std::string& filename, int stripFromStackBottom) :
|
||||
Log::Log(const std::string& filename, int stripFromStackBottom) :
|
||||
stripFromStackBottom(stripFromStackBottom) {
|
||||
|
||||
this->filename = filename;
|
||||
@@ -50,7 +50,7 @@ Log::Log(const std::string& filename, int stripFromStackBottom) :
|
||||
std::string drive, base, ext;
|
||||
Array<std::string> path;
|
||||
parseFilename(filename, drive, path, base, ext);
|
||||
std::string logName = base + ((ext != "") ? ("." + ext) : "");
|
||||
std::string logName = base + ((ext != "") ? ("." + ext) : "");
|
||||
|
||||
// Write time is greater than 1ms. This may be a network drive.... try another file.
|
||||
#ifdef G3D_WIN32
|
||||
@@ -80,7 +80,7 @@ Log::Log(const std::string& filename, int stripFromStackBottom) :
|
||||
Log::~Log() {
|
||||
section("Shutdown");
|
||||
println("Closing log file");
|
||||
|
||||
|
||||
// Make sure we don't leave a dangling pointer
|
||||
if (Log::commonLog == this) {
|
||||
Log::commonLog = NULL;
|
||||
|
||||
@@ -257,7 +257,7 @@ bool RegistryUtil::writeString(const std::string& key, const std::string& value,
|
||||
|
||||
|
||||
// static helpers
|
||||
static HKEY getRootKeyFromString(const char* str, size_t length) {
|
||||
static HKEY getRootKeyFromString(const char* str, uint32 length) {
|
||||
debugAssert(str);
|
||||
|
||||
if (str) {
|
||||
|
||||
@@ -920,9 +920,12 @@ RealTime System::time() {
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
#define REALPTR_TO_USERPTR(x) ((uint8*)(x) + sizeof (void *))
|
||||
#define USERPTR_TO_REALPTR(x) ((uint8*)(x) - sizeof (void *))
|
||||
#define REALBLOCK_SIZE(x) ((x) + sizeof (void *))
|
||||
|
||||
#define REALPTR_TO_USERPTR(x) ((uint8*)(x) + sizeof(uint32))
|
||||
#define USERPTR_TO_REALPTR(x) ((uint8*)(x) - sizeof(uint32))
|
||||
#define USERSIZE_TO_REALSIZE(x) ((x) + sizeof(uint32))
|
||||
#define REALSIZE_FROM_USERPTR(u) (*(uint32*)USERPTR_TO_REALPTR(ptr) + sizeof(uint32))
|
||||
#define USERSIZE_FROM_USERPTR(u) (*(uint32*)USERPTR_TO_REALPTR(ptr))
|
||||
|
||||
class BufferPool {
|
||||
public:
|
||||
@@ -947,13 +950,19 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
/** Pointer given to the program. Unless in the tiny heap, the user size of the block is stored right in front of the pointer as a uint32.*/
|
||||
typedef void* UserPtr;
|
||||
|
||||
/** Actual block allocated on the heap */
|
||||
typedef void* RealPtr;
|
||||
|
||||
class MemBlock {
|
||||
public:
|
||||
void* ptr;
|
||||
size_t bytes;
|
||||
UserPtr ptr;
|
||||
size_t bytes;
|
||||
|
||||
inline MemBlock() : ptr(NULL), bytes(0) {}
|
||||
inline MemBlock(void* p, size_t b) : ptr(p), bytes(b) {}
|
||||
inline MemBlock(UserPtr p, size_t b) : ptr(p), bytes(b) {}
|
||||
};
|
||||
|
||||
MemBlock smallPool[maxSmallBuffers];
|
||||
@@ -1010,13 +1019,13 @@ private:
|
||||
/**
|
||||
Malloc out of the tiny heap. Returns NULL if allocation failed.
|
||||
*/
|
||||
inline void* tinyMalloc(size_t bytes) {
|
||||
inline UserPtr tinyMalloc(size_t bytes) {
|
||||
// Note that we ignore the actual byte size
|
||||
// and create a constant size block.
|
||||
(void)bytes;
|
||||
assert(tinyBufferSize >= bytes);
|
||||
|
||||
void* ptr = NULL;
|
||||
UserPtr ptr = NULL;
|
||||
|
||||
if (tinyPoolSize > 0) {
|
||||
--tinyPoolSize;
|
||||
@@ -1040,20 +1049,20 @@ private:
|
||||
}
|
||||
|
||||
/** Returns true if this is a pointer into the tiny heap. */
|
||||
bool inTinyHeap(void* ptr) {
|
||||
bool inTinyHeap(UserPtr ptr) {
|
||||
return
|
||||
(ptr >= tinyHeap) &&
|
||||
(ptr < (uint8*)tinyHeap + maxTinyBuffers * tinyBufferSize);
|
||||
}
|
||||
|
||||
void tinyFree(void* ptr) {
|
||||
void tinyFree(UserPtr ptr) {
|
||||
assert(ptr);
|
||||
assert(tinyPoolSize < maxTinyBuffers);
|
||||
// "Tried to free a tiny pool buffer when the tiny pool freelist is full.");
|
||||
|
||||
# ifdef G3D_DEBUG
|
||||
if (tinyPoolSize > 0) {
|
||||
void* prevOnHeap = tinyPool[tinyPoolSize - 1];
|
||||
UserPtr prevOnHeap = tinyPool[tinyPoolSize - 1];
|
||||
assert(prevOnHeap != ptr);
|
||||
// "System::malloc heap corruption detected: "
|
||||
// "the last two pointers on the freelist are identical (during tinyFree).");
|
||||
@@ -1070,7 +1079,8 @@ private:
|
||||
|
||||
void flushPool(MemBlock* pool, int& poolSize) {
|
||||
for (int i = 0; i < poolSize; ++i) {
|
||||
::free(pool[i].ptr);
|
||||
bytesAllocated -= USERSIZE_TO_REALSIZE(pool[i].bytes);
|
||||
::free(USERPTR_TO_REALPTR(pool[i].ptr));
|
||||
pool[i].ptr = NULL;
|
||||
pool[i].bytes = 0;
|
||||
}
|
||||
@@ -1078,24 +1088,23 @@ private:
|
||||
}
|
||||
|
||||
|
||||
/** Allocate out of a specific pool-> Return NULL if no suitable
|
||||
memory was found.
|
||||
|
||||
*/
|
||||
void* malloc(MemBlock* pool, int& poolSize, size_t bytes) {
|
||||
/** Allocate out of a specific pool. Return NULL if no suitable
|
||||
memory was found. */
|
||||
UserPtr malloc(MemBlock* pool, int& poolSize, size_t bytes) {
|
||||
|
||||
// OPT: find the smallest block that satisfies the request.
|
||||
|
||||
// See if there's something we can use in the buffer pool->
|
||||
// See if there's something we can use in the buffer pool.
|
||||
// Search backwards since usually we'll re-use the last one.
|
||||
for (int i = (int)poolSize - 1; i >= 0; --i) {
|
||||
if (pool[i].bytes >= bytes) {
|
||||
// We found a suitable entry in the pool->
|
||||
// We found a suitable entry in the pool.
|
||||
|
||||
// No need to offset the pointer; it is already offset
|
||||
void* ptr = pool[i].ptr;
|
||||
UserPtr ptr = pool[i].ptr;
|
||||
|
||||
// Remove this element from the pool
|
||||
// Remove this element from the pool, replacing it with
|
||||
// the one from the end (same as Array::fastRemove)
|
||||
--poolSize;
|
||||
pool[i] = pool[poolSize];
|
||||
|
||||
@@ -1159,6 +1168,8 @@ public:
|
||||
|
||||
~BufferPool() {
|
||||
::free(tinyHeap);
|
||||
flushPool(smallPool, smallPoolSize);
|
||||
flushPool(medPool, medPoolSize);
|
||||
#if 0 //-------------------------------- old mutex
|
||||
# ifdef G3D_WIN32
|
||||
DeleteCriticalSection(&mutex);
|
||||
@@ -1169,7 +1180,7 @@ public:
|
||||
}
|
||||
|
||||
|
||||
void* realloc(void* ptr, size_t bytes) {
|
||||
UserPtr realloc(UserPtr ptr, size_t bytes) {
|
||||
if (ptr == NULL) {
|
||||
return malloc(bytes);
|
||||
}
|
||||
@@ -1181,7 +1192,7 @@ public:
|
||||
} else {
|
||||
// Free the old pointer and malloc
|
||||
|
||||
void* newPtr = malloc(bytes);
|
||||
UserPtr newPtr = malloc(bytes);
|
||||
System::memcpy(newPtr, ptr, tinyBufferSize);
|
||||
tinyFree(ptr);
|
||||
return newPtr;
|
||||
@@ -1191,28 +1202,28 @@ public:
|
||||
// In one of our heaps.
|
||||
|
||||
// See how big the block really was
|
||||
size_t realSize = *(uint32*)USERPTR_TO_REALPTR(ptr);
|
||||
if (bytes <= realSize) {
|
||||
size_t userSize = USERSIZE_FROM_USERPTR(ptr);
|
||||
if (bytes <= userSize) {
|
||||
// The old block was big enough.
|
||||
return ptr;
|
||||
}
|
||||
|
||||
// Need to reallocate
|
||||
void* newPtr = malloc(bytes);
|
||||
System::memcpy(newPtr, ptr, realSize);
|
||||
// Need to reallocate and move
|
||||
UserPtr newPtr = malloc(bytes);
|
||||
System::memcpy(newPtr, ptr, userSize);
|
||||
free(ptr);
|
||||
return newPtr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void* malloc(size_t bytes) {
|
||||
UserPtr malloc(size_t bytes) {
|
||||
lock();
|
||||
++totalMallocs;
|
||||
|
||||
if (bytes <= tinyBufferSize) {
|
||||
|
||||
void* ptr = tinyMalloc(bytes);
|
||||
UserPtr ptr = tinyMalloc(bytes);
|
||||
|
||||
if (ptr) {
|
||||
++mallocsFromTinyPool;
|
||||
@@ -1226,7 +1237,7 @@ public:
|
||||
// through to a small buffer
|
||||
if (bytes <= smallBufferSize) {
|
||||
|
||||
void* ptr = malloc(smallPool, smallPoolSize, bytes);
|
||||
UserPtr ptr = malloc(smallPool, smallPoolSize, bytes);
|
||||
|
||||
if (ptr) {
|
||||
++mallocsFromSmallPool;
|
||||
@@ -1239,7 +1250,7 @@ public:
|
||||
// through into a medium allocation because that would
|
||||
// waste the medium buffer's resources.
|
||||
|
||||
void* ptr = malloc(medPool, medPoolSize, bytes);
|
||||
UserPtr ptr = malloc(medPool, medPoolSize, bytes);
|
||||
|
||||
if (ptr) {
|
||||
++mallocsFromMedPool;
|
||||
@@ -1249,37 +1260,37 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
bytesAllocated += REALBLOCK_SIZE(bytes);
|
||||
bytesAllocated += USERSIZE_TO_REALSIZE(bytes);
|
||||
unlock();
|
||||
|
||||
// Heap allocate
|
||||
|
||||
// Allocate 4 extra bytes for our size header (unfortunate,
|
||||
// since malloc already added its own header).
|
||||
void* ptr = ::malloc(REALBLOCK_SIZE(bytes));
|
||||
RealPtr ptr = ::malloc(USERSIZE_TO_REALSIZE(bytes));
|
||||
|
||||
if (ptr == NULL) {
|
||||
// Flush memory pools to try and recover space
|
||||
flushPool(smallPool, smallPoolSize);
|
||||
flushPool(medPool, medPoolSize);
|
||||
ptr = ::malloc(REALBLOCK_SIZE(bytes));
|
||||
ptr = ::malloc(USERSIZE_TO_REALSIZE(bytes));
|
||||
}
|
||||
|
||||
if (ptr == NULL) {
|
||||
if ((System::outOfMemoryCallback() != NULL) &&
|
||||
(System::outOfMemoryCallback()(REALBLOCK_SIZE(bytes), true) == true)) {
|
||||
(System::outOfMemoryCallback()(USERSIZE_TO_REALSIZE(bytes), true) == true)) {
|
||||
// Re-attempt the malloc
|
||||
ptr = ::malloc(REALBLOCK_SIZE(bytes));
|
||||
ptr = ::malloc(USERSIZE_TO_REALSIZE(bytes));
|
||||
}
|
||||
}
|
||||
|
||||
if (ptr == NULL) {
|
||||
if (System::outOfMemoryCallback() != NULL) {
|
||||
// Notify the application
|
||||
System::outOfMemoryCallback()(REALBLOCK_SIZE(bytes), false);
|
||||
System::outOfMemoryCallback()(USERSIZE_TO_REALSIZE(bytes), false);
|
||||
}
|
||||
# ifdef G3D_DEBUG
|
||||
debugPrintf("::malloc(%d) returned NULL\n", (int)REALBLOCK_SIZE(bytes));
|
||||
debugPrintf("::malloc(%d) returned NULL\n", (int)USERSIZE_TO_REALSIZE(bytes));
|
||||
# endif
|
||||
debugAssertM(ptr != NULL,
|
||||
"::malloc returned NULL. Either the "
|
||||
@@ -1294,7 +1305,7 @@ public:
|
||||
}
|
||||
|
||||
|
||||
void free(void* ptr) {
|
||||
void free(UserPtr ptr) {
|
||||
if (ptr == NULL) {
|
||||
// Free does nothing on null pointers
|
||||
return;
|
||||
@@ -1309,7 +1320,7 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
uint32 bytes = *(uint32*)USERPTR_TO_REALPTR(ptr);
|
||||
uint32 bytes = USERSIZE_FROM_USERPTR(ptr);
|
||||
|
||||
lock();
|
||||
if (bytes <= smallBufferSize) {
|
||||
@@ -1327,7 +1338,7 @@ public:
|
||||
return;
|
||||
}
|
||||
}
|
||||
bytesAllocated -= REALBLOCK_SIZE(bytes);
|
||||
bytesAllocated -= USERSIZE_TO_REALSIZE(bytes);
|
||||
unlock();
|
||||
|
||||
// Free; the buffer pools are full or this is too big to store.
|
||||
|
||||
@@ -128,32 +128,34 @@ Token TextInput::read() {
|
||||
}
|
||||
|
||||
|
||||
std::string TextInput::readUntilNewlineAsString() {
|
||||
// Go to the front of the next token
|
||||
Token t = read();
|
||||
|
||||
// Reset the position to the start of this token
|
||||
std::string TextInput::readUntilNewlineAsString() {
|
||||
/*
|
||||
// Reset the read position back to the start of that token
|
||||
currentCharOffset = t.bytePosition();
|
||||
lineNumber = t.line();
|
||||
charNumber = t.character();
|
||||
stack.clear();
|
||||
|
||||
if (currentCharOffset == buffer.size()) {
|
||||
// End of file
|
||||
return "";
|
||||
}
|
||||
|
||||
*/
|
||||
std::string s;
|
||||
|
||||
// Read until newline or eof
|
||||
char c = '\0';
|
||||
do {
|
||||
c = buffer[currentCharOffset];
|
||||
if (c == '\r' || c == '\n') {
|
||||
// Done
|
||||
break;
|
||||
} else {
|
||||
s += c;
|
||||
++currentCharOffset;
|
||||
}
|
||||
c = buffer[currentCharOffset];
|
||||
if (c == '\r' || c == '\n') {
|
||||
// Done
|
||||
break;
|
||||
} else {
|
||||
s += c;
|
||||
++currentCharOffset;
|
||||
++charNumber;
|
||||
}
|
||||
} while (currentCharOffset < buffer.size());
|
||||
|
||||
return s;
|
||||
|
||||
@@ -41,7 +41,7 @@ double inf() {
|
||||
}
|
||||
|
||||
bool isNaN(float x) {
|
||||
static const float n = fnan();
|
||||
static const float n = nan();
|
||||
return memcmp(&x, &n, sizeof(float)) == 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user