Core/Dependency: Upgrade G3d-library to v8.0-release (patched version!)

Note: Due to issues with G3D (normally requiring X11 and the ZIP-library),
the sourcetree version contains a modified version. The applied patch is
commited to the repository for future reference.

--HG--
branch : trunk
This commit is contained in:
click
2010-08-27 01:52:05 +02:00
parent 1d3deae555
commit 7686d6ee57
229 changed files with 22599 additions and 1074 deletions
+1 -5
View File
@@ -10,7 +10,7 @@ bzip2 (a freely available, patent free, high-quality data compressor)
G3D (a commercial-grade C++ 3D engine available as Open Source (BSD License)
http://g3d.sourceforge.net/
Version: 6.09
Version: 8.0-Release
jemalloc (a general-purpose scalable concurrent malloc-implementation)
http://www.canonware.com/jemalloc/
@@ -36,10 +36,6 @@ utf8-cpp (UTF-8 with C++ in a Portable Way)
http://utfcpp.sourceforge.net/
Version: 2.3
vld (a free open-source memory leak detection system for Visual C++)
http://sites.google.com/site/dmoulding/vld
Version: 1.0
zlib (A Massively Spiffy Yet Delicately Unobtrusive Compression Library)
http://www.zlib.net/
Version: 1.2.5
+42 -4
View File
@@ -8,19 +8,57 @@
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
file(GLOB sources *.cpp)
set(g3dlib_STAT_SRCS
${sources}
source/AABox.cpp
source/Any.cpp
source/BinaryFormat.cpp
source/BinaryInput.cpp
source/BinaryOutput.cpp
source/Box.cpp
source/Capsule.cpp
source/CollisionDetection.cpp
source/CoordinateFrame.cpp
source/Crypto.cpp
source/Cylinder.cpp
source/debugAssert.cpp
source/fileutils.cpp
source/format.cpp
source/g3dfnmatch.cpp
source/g3dmath.cpp
source/Line.cpp
source/LineSegment.cpp
source/Log.cpp
source/Matrix3.cpp
source/Matrix4.cpp
source/MemoryManager.cpp
source/Plane.cpp
source/prompt.cpp
source/Quat.cpp
source/Random.cpp
source/Ray.cpp
source/ReferenceCount.cpp
source/RegistryUtil.cpp
source/Sphere.cpp
source/stringutils.cpp
source/System.cpp
source/TextInput.cpp
source/TextOutput.cpp
source/Triangle.cpp
source/UprightFrame.cpp
source/Vector2.cpp
source/Vector3.cpp
source/Vector4.cpp
)
if(WIN32)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/dep/zlib
)
else()
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
)
endif()
+440
View File
@@ -0,0 +1,440 @@
diff -urN g3d-beta4/include/G3D/debugAssert.h g3d-mangos/include/G3D/debugAssert.h
--- g3d-beta4/include/G3D/debugAssert.h 2010-02-07 23:39:20.000000000 +0100
+++ g3d-mangos/include/G3D/debugAssert.h 2010-08-26 21:36:32.000000000 +0200
@@ -39,10 +39,12 @@
#ifdef G3D_LINUX
// Needed so we can define a global display
// pointer for debugAssert.
+#if 0 /* G3DFIX: Disabled to avoid requirement for X11 libraries */
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#endif
+#endif
/**
@@ -178,6 +180,7 @@
namespace G3D { namespace _internal {
#ifdef G3D_LINUX
+#if 0 /* G3DFIX: Disabled to avoid requirement for X11 libraries */
/**
A pointer to the X11 display. Initially NULL. If set to a
non-null value (e.g. by SDLWindow), debugAssert attempts to use
@@ -194,6 +197,7 @@
*/
extern Window x11Window;
#endif
+#endif
/**
Pops up an assertion dialog or prints an assertion
diff -urN g3d-beta4/include/G3D/g3dmath.h g3d-mangos/include/G3D/g3dmath.h
--- g3d-beta4/include/G3D/g3dmath.h 2010-02-07 23:39:20.000000000 +0100
+++ g3d-mangos/include/G3D/g3dmath.h 2010-08-26 21:36:32.000000000 +0200
@@ -65,6 +65,8 @@
return ::rand() / double(RAND_MAX);
}
+#if !defined(_WIN64)
+
/**
Win32 implementation of the C99 fast rounding routines.
@@ -99,6 +101,19 @@
return intgr;
}
+
+#else
+
+ __inline long int lrint (double flt) {
+ return (long int)floor(flt+0.5f);
+ }
+
+ __inline long int lrintf(float flt) {
+ return (long int)floorf(flt+0.5f);
+ }
+
+#endif
+
#endif
diff -urN g3d-beta4/include/G3D/platform.h g3d-mangos/include/G3D/platform.h
--- g3d-beta4/include/G3D/platform.h 2010-02-07 23:39:20.000000000 +0100
+++ g3d-mangos/include/G3D/platform.h 2010-08-26 21:36:32.000000000 +0200
@@ -56,12 +57,15 @@
// pi as a constant, which creates a conflict with G3D
#define __FP__
#else
- #error Unknown platform
+ #error Unknown platform
#endif
// Detect 64-bit under various compilers
#if (defined(_M_X64) || defined(_WIN64) || defined(__LP64__) || defined(_LP64))
# define G3D_64BIT
+ #if defined(WIN32)
+ #include <intrin.h>
+ #endif
#else
# define G3D_32BIT
#endif
@@ -126,13 +130,11 @@
// TODO: remove
# pragma warning (disable : 4244)
-# define ZLIB_WINAPI
-
# define restrict
/** @def G3D_CHECK_PRINTF_METHOD_ARGS()
Enables printf parameter validation on gcc. */
-# define G3D_CHECK_PRINTF_ARGS
+# define G3D_CHECK_PRINTF_ARGS
/** @def G3D_CHECK_PRINTF_METHOD_ARGS()
Enables printf parameter validation on gcc. */
diff -urN g3d-beta4/include/G3D/System.h g3d-mangos/include/G3D/System.h
--- g3d-beta4/include/G3D/System.h 2010-02-07 23:39:20.000000000 +0100
+++ g3d-mangos/include/G3D/System.h 2010-08-26 21:36:32.000000000 +0200
@@ -375,10 +375,10 @@
// count now contains the cycle count for the intervening operation.
</PRE>
*/
- static void beginCycleCount(uint64& cycleCount);
+ /* static void beginCycleCount(uint64& cycleCount);
static void endCycleCount(uint64& cycleCount);
- static uint64 getCycleCount();
+ static uint64 getCycleCount(); */
inline static void setOutOfMemoryCallback(OutOfMemoryCallback c) {
instance().m_outOfMemoryCallback = c;
@@ -438,7 +438,7 @@
};
-
+/* don't need that for MaNGOS, not portable to Win64...
#ifdef _MSC_VER
inline uint64 System::getCycleCount() {
uint32 timehi, timelo;
@@ -493,14 +493,14 @@
cycleCount = getCycleCount() - cycleCount;
#else
AbsoluteTime end = UpTime();
- Nanoseconds diffNS =
+ Nanoseconds diffNS =
AbsoluteDeltaToNanoseconds(end, UInt64ToUnsignedWide(cycleCount));
- cycleCount =
- (uint64) ((double) (instance().m_OSXCPUSpeed) *
+ cycleCount =
+ (uint64) ((double) (instance().m_OSXCPUSpeed) *
(double) UnsignedWideToUInt64(diffNS) * instance().m_secondsPerNS);
#endif
}
-
+ */
} // namespace
diff -urN g3d-beta4/source/debugAssert.cpp g3d-mangos/source/debugAssert.cpp
--- g3d-beta4/source/debugAssert.cpp 2010-02-07 23:39:20.000000000 +0100
+++ g3d-mangos/source/debugAssert.cpp 2010-08-15 11:37:26.000000000 +0200
@@ -37,9 +37,11 @@
AssertionHook _failureHook = _handleErrorCheck_;
#ifdef G3D_LINUX
+#if 0 /* G3DFIX: Disabled to avoid requirement for X11 libraries */
Display* x11Display = NULL;
Window x11Window = 0;
#endif
+#endif
#ifdef G3D_WIN32
@@ -250,6 +252,7 @@
ClipCursor(NULL);
#elif defined(G3D_LINUX)
+#if 0 /* G3DFIX: Disabled to avoid requirement for X11 libraries */
if (x11Display != NULL) {
XUngrabPointer(x11Display, CurrentTime);
XUngrabKeyboard(x11Display, CurrentTime);
@@ -264,6 +267,7 @@
XAllowEvents(x11Display, AsyncPointer, CurrentTime);
XFlush(x11Display);
}
+#endif
#elif defined(G3D_OSX)
// TODO: OS X
#endif
diff -urN g3d-beta4/source/fileutils.cpp g3d-mangos/source/fileutils.cpp
--- g3d-beta4/source/fileutils.cpp 2010-02-07 23:39:20.000000000 +0100
+++ g3d-mangos/source/fileutils.cpp 2010-08-15 11:37:26.000000000 +0200
@@ -20,7 +20,9 @@
#include <sys/stat.h>
#include <sys/types.h>
-#include "zip.h"
+#if _HAVE_ZIP /* G3DFIX: Use ZIP-library only if defined */
+ #include "zip.h"
+#endif
#ifdef G3D_WIN32
// Needed for _getcwd
@@ -144,7 +146,7 @@
void*& data,
size_t& length) {
std::string zip, desiredFile;
-
+#if _HAVE_ZIP /* G3DFIX: Use ZIP-library only if defined */
if (zipfileExists(file, zip, desiredFile)) {
struct zip *z = zip_open( zip.c_str(), ZIP_CHECKCONS, NULL );
{
@@ -167,6 +169,9 @@
} else {
data = NULL;
}
+#else
+ data = NULL;
+#endif
}
@@ -180,6 +185,7 @@
int result = _stat(filename.c_str(), &st);
if (result == -1) {
+#if _HAVE_ZIP /* G3DFIX: Use ZIP-library only if defined */
std::string zip, contents;
if(zipfileExists(filename, zip, contents)){
int64 requiredMem;
@@ -198,6 +204,9 @@
} else {
return -1;
}
+#else
+ return -1;
+#endif
}
return st.st_size;
@@ -518,6 +527,7 @@
///////////////////////////////////////////////////////////////////////////////
+#if _HAVE_ZIP /* G3DFIX: Use ZIP-library only if defined */
/* Helper methods for zipfileExists()*/
// Given a string (the drive) and an array (the path), computes the directory
static void _zip_resolveDirectory(std::string& completeDir, const std::string& drive, const Array<std::string>& path, const int length){
@@ -551,12 +561,12 @@
}
return true;
}
-
+#endif
// If no zipfile exists, outZipfile and outInternalFile are unchanged
bool zipfileExists(const std::string& filename, std::string& outZipfile,
std::string& outInternalFile){
-
+#if _HAVE_ZIP /* G3DFIX: Use ZIP-library only if defined */
Array<std::string> path;
std::string drive, base, ext, zipfile, infile;
parseFilename(filename, drive, path, base, ext);
@@ -618,7 +628,7 @@
}
}
-
+#endif
// not a valid directory structure ever,
// obviously no .zip was found within the path
return false;
@@ -900,7 +910,7 @@
# endif
}
-
+#if _HAVE_ZIP /* G3DFIX: Use ZIP-library only if defined */
/**
@param path The zipfile name (no trailing slash)
@param prefix Directory inside the zipfile. No leading slash, must have trailing slash if non-empty.
@@ -951,13 +961,14 @@
}
}
}
-
+#endif
static void getFileOrDirListZip(const std::string& path,
const std::string& prefix,
Array<std::string>& files,
bool wantFiles,
bool includePath){
+#if _HAVE_ZIP /* G3DFIX: Use ZIP-library only if defined */
struct zip *z = zip_open( path.c_str(), ZIP_CHECKCONS, NULL );
Set<std::string> fileSet;
@@ -973,6 +984,7 @@
zip_close( z );
fileSet.getMembers(files);
+#endif
}
diff -urN g3d-beta4/source/prompt.cpp g3d-mangos/source/prompt.cpp
--- g3d-beta4/source/prompt.cpp 2010-02-07 23:39:20.000000000 +0100
+++ g3d-mangos/source/prompt.cpp 2010-08-15 11:37:26.000000000 +0200
@@ -21,6 +21,7 @@
# define _getch getchar
#endif
+#if 0 /* G3DFIX: exclude GUI prompt code */
#ifdef G3D_OSX
/*#ifdef __LP64__
@@ -37,9 +38,11 @@
*/
#endif
+#endif /* G3DFIX: exclude GUI prompt code */
namespace G3D {
+#if 0 /* G3DFIX: exclude GUI prompt code */
#ifdef G3D_WIN32
namespace _internal {
@@ -469,6 +472,7 @@
}
#endif
+#endif /* G3DFIX: exclude GUI prompt code */
/**
@@ -531,6 +535,8 @@
return c;
}
+#if 0 /* G3DFIX: exclude GUI prompt code */
+
#ifdef G3D_OSX
// See http://developer.apple.com/documentation/Carbon/Reference/Carbon_Event_Manager_Ref/index.html
@@ -689,13 +695,15 @@
#endif
+#endif /* G3DFIX: exclude GUI prompt code */
+
int prompt(
const char* windowTitle,
const char* prompt,
const char** choice,
int numChoices,
bool useGui) {
-
+#if 0 /* G3DFIX: exclude GUI prompt code */
#ifdef G3D_WIN32
if (useGui) {
// Build the message box
@@ -709,6 +717,7 @@
return guiPrompt(windowTitle, prompt, choice, numChoices);
}
#endif
+#endif /* G3DFIX: exclude GUI prompt code */
return textPrompt(windowTitle, prompt, choice, numChoices);
}
diff -urN g3d-beta4/source/RegistryUtil.cpp g3d-mangos/source/RegistryUtil.cpp
--- g3d-beta4/source/RegistryUtil.cpp 2010-02-07 23:39:20.000000000 +0100
+++ g3d-mangos/source/RegistryUtil.cpp 2010-08-15 11:37:26.000000000 +0200
@@ -257,7 +257,7 @@
// static helpers
-static HKEY getRootKeyFromString(const char* str, uint32 length) {
+static HKEY getRootKeyFromString(const char* str, size_t length) {
debugAssert(str);
if (str) {
diff -urN g3d-beta4/source/System.cpp g3d-mangos/source/System.cpp
--- g3d-beta4/source/System.cpp 2010-02-07 23:39:20.000000000 +0100
+++ g3d-mangos/source/System.cpp 2010-08-15 11:37:26.000000000 +0200
@@ -80,8 +80,9 @@
#endif
// SIMM include
+#ifdef __SSE__
#include <xmmintrin.h>
-
+#endif
namespace G3D {
@@ -559,7 +560,7 @@
#endif
}
-#if defined(G3D_WIN32)
+#if defined(G3D_WIN32) && !defined(G3D_64BIT) /* G3DFIX: Don't check if on 64-bit Windows platforms */
#pragma message("Port System::memcpy SIMD to all platforms")
/** Michael Herf's fast memcpy */
void memcpyMMX(void* dst, const void* src, int nbytes) {
@@ -610,7 +611,7 @@
#endif
void System::memcpy(void* dst, const void* src, size_t numBytes) {
-#if defined(G3D_WIN32)
+#if defined(G3D_WIN32) && !defined(G3D_64BIT) /* G3DFIX: Don't check if on 64-bit Windows platforms */
memcpyMMX(dst, src, numBytes);
#else
::memcpy(dst, src, numBytes);
@@ -620,7 +621,7 @@
/** Michael Herf's fastest memset. n32 must be filled with the same
character repeated. */
-#if defined(G3D_WIN32)
+#if defined(G3D_WIN32) && !defined(G3D_64BIT) /* G3DFIX: Don't check if on 64-bit Windows platforms */
#pragma message("Port System::memfill SIMD to all platforms")
// On x86 processors, use MMX
@@ -659,7 +660,7 @@
void System::memset(void* dst, uint8 value, size_t numBytes) {
-#if defined(G3D_WIN32)
+#if defined(G3D_WIN32) && !defined(G3D_64BIT) /* G3DFIX: Don't check if on 64-bit Windows platforms */
uint32 v = value;
v = v + (v << 8) + (v << 16) + (v << 24);
G3D::memfill(dst, v, numBytes);
@@ -1676,6 +1677,7 @@
// VC on Intel
void System::cpuid(CPUIDFunction func, uint32& areg, uint32& breg, uint32& creg, uint32& dreg) {
+#if !defined(G3D_64BIT) /* G3DFIX: Don't check if on 64-bit platform */
// Can't copy from assembler direct to a function argument (which is on the stack) in VC.
uint32 a,b,c,d;
@@ -1693,6 +1695,14 @@
breg = b;
creg = c;
dreg = d;
+#else
+ int CPUInfo[4];
+ __cpuid(CPUInfo, func);
+ memcpy(&areg, &CPUInfo[0], 4);
+ memcpy(&breg, &CPUInfo[1], 4);
+ memcpy(&creg, &CPUInfo[2], 4);
+ memcpy(&dreg, &CPUInfo[3], 4);
+#endif
}
#elif defined(G3D_OSX) && ! defined(G3D_OSX_INTEL)
+3
View File
@@ -0,0 +1,3 @@
Due to issues with G3D (normally requiring X11 and the ZIP-library), the
sourcetree version contains a modified version. The applied patch is
commited to the repository for future reference.
-204
View File
@@ -1,204 +0,0 @@
/*-
* Copyright (c) 1992, 1993
*The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
*This product includes software developed by the University of
*California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*@(#)fnmatch.h8.1 (Berkeley) 6/2/93
*
* From FreeBSD fnmatch.h 1.7
* $Id: g3dfnmatch.cpp,v 1.2 2010/02/06 10:03:24 corey_taylor Exp $
*/
#include "G3D/g3dfnmatch.h"
#ifdef G3D_WIN32
#include <ctype.h>
#include <string.h>
#include <stdio.h>
namespace G3D {
#define EOS '\0'
static const char *rangematch(const char *, char, int);
int g3dfnmatch(const char *pattern, const char *string, int flags)
{
const char *stringstart;
char c, test;
for (stringstart = string;;)
switch (c = *pattern++) {
case EOS:
if ((flags & FNM_LEADING_DIR) && *string == '/')
return (0);
return (*string == EOS ? 0 : FNM_NOMATCH);
case '?':
if (*string == EOS)
return (FNM_NOMATCH);
if (*string == '/' && (flags & FNM_PATHNAME))
return (FNM_NOMATCH);
if (*string == '.' && (flags & FNM_PERIOD) &&
(string == stringstart ||
((flags & FNM_PATHNAME) && *(string - 1) == '/')))
return (FNM_NOMATCH);
++string;
break;
case '*':
c = *pattern;
/* Collapse multiple stars. */
while (c == '*')
c = *++pattern;
if (*string == '.' && (flags & FNM_PERIOD) &&
(string == stringstart ||
((flags & FNM_PATHNAME) && *(string - 1) == '/')))
return (FNM_NOMATCH);
/* Optimize for pattern with * at end or before /. */
if (c == EOS)
if (flags & FNM_PATHNAME)
return ((flags & FNM_LEADING_DIR) ||
strchr(string, '/') == NULL ?
0 : FNM_NOMATCH);
else
return (0);
else if (c == '/' && flags & FNM_PATHNAME) {
if ((string = strchr(string, '/')) == NULL)
return (FNM_NOMATCH);
break;
}
/* General case, use recursion. */
while ((test = *string) != EOS) {
if (!rangematch(pattern, *string, flags & ~FNM_PERIOD))
return (0);
if (test == '/' && flags & FNM_PATHNAME)
break;
++string;
}
return (FNM_NOMATCH);
case '[':
if (*string == EOS)
return (FNM_NOMATCH);
if (*string == '/' && flags & FNM_PATHNAME)
return (FNM_NOMATCH);
if ((pattern =
rangematch(pattern, *string, flags)) == NULL)
return (FNM_NOMATCH);
++string;
break;
case '\\':
if (!(flags & FNM_NOESCAPE)) {
if ((c = *pattern++) == EOS) {
c = '\\';
--pattern;
}
}
/* FALLTHROUGH */
default:
if (c == *string)
;
else if ((flags & FNM_CASEFOLD) &&
(tolower((unsigned char)c) ==
tolower((unsigned char)*string)))
;
else if ((flags & FNM_PREFIX_DIRS) && *string == EOS &&
((c == '/' && string != stringstart) ||
(string == stringstart+1 && *stringstart == '/')))
return (0);
else
return (FNM_NOMATCH);
string++;
break;
}
/* NOTREACHED */
}
static const char *
rangematch(const char *pattern, char test, int flags)
{
int negate, ok;
char c, c2;
/*
* A bracket expression starting with an unquoted circumflex
* character produces unspecified results (IEEE 1003.2-1992,
* 3.13.2). This implementation treats it like '!', for
* consistency with the regular expression syntax.
* J.T. Conklin ([email protected])
*/
if ( (negate = (*pattern == '!' || *pattern == '^')) )
++pattern;
if (flags & FNM_CASEFOLD)
test = tolower((unsigned char)test);
for (ok = 0; (c = *pattern++) != ']';) {
if (c == '\\' && !(flags & FNM_NOESCAPE))
c = *pattern++;
if (c == EOS)
return (NULL);
if (flags & FNM_CASEFOLD)
c = tolower((unsigned char)c);
if (*pattern == '-'
&& (c2 = *(pattern+1)) != EOS && c2 != ']') {
pattern += 2;
if (c2 == '\\' && !(flags & FNM_NOESCAPE))
c2 = *pattern++;
if (c2 == EOS)
return (NULL);
if (flags & FNM_CASEFOLD)
c2 = tolower((unsigned char)c2);
if ((unsigned char)c <= (unsigned char)test &&
(unsigned char)test <= (unsigned char)c2)
ok = 1;
} else if (c == test)
ok = 1;
}
return (ok == negate ? NULL : pattern);
}
}
#else
namespace G3D {
int g3dfnmatch(const char * a, const char *b, int c) {
return fnmatch(a, b, c);
}
}
#endif
@@ -5,7 +5,7 @@
@maintainer Morgan McGuire
@created 2006-06-11
@edited 2009-12-16
@edited 2010-03-16
Copyright 2000-2010, Morgan McGuire.
All rights reserved.
@@ -34,11 +34,14 @@ class TextOutput;
/**
\brief Easy loading and saving of human-readable configuration files.
Encodes typed, structured data and can serialize it to a human
Any encodes typed, structured data and can serialize it to a human
readable format that is very similar to the Python language's data
syntax. Well-suited for quickly creating human-readable file formats,
especially since deserialization and serialization preserve comments and
an Any can tell you what file and line it came from.
syntax. It is well-suited for quickly creating human-readable file
formats, especially since deserialization and serialization preserve
comments and an Any can tell you what file and line it came from. The
syntax allows most C++ editors to properly highlight Any files, and
makes it easy to design little ad-hoc C-like languages in
configuration files.
The class is designed so that copying Anys generally is fast, even if
it is a large array or table. This is because data is shared between
@@ -50,15 +53,17 @@ Sample File:
{
shape = "round",
# in meters
// in meters
radius = 3.7,
position = Vector3(1.0, -1.0, 0.0),
texture = { format = "RGB8", size = (320, 200)}
video = { format = "RGB8", size = (320, 200)},
material = #include("rocks.mat")
}
</pre>
Sample code using:
Sample code using Any:
<pre>
Any x;
x.load("ball.txt");
@@ -110,6 +115,21 @@ Vector3::Vector3(const Any& any) {
}
</pre>
It is often convenient to iterate through the table portion:
<pre>
for (Any::AnyTable::Iterator it = any.table().begin(); it.hasMore(); ++it) {
const std::string& k = toLower(it->key);
if (key == "hello") {
...
} else if (key == "goodbye") {
...
} else {
any.verify(false, "Unsupported key: " + it->key);
}
}
</pre>
\section BNF
Serialized format BNF:
@@ -119,27 +139,38 @@ identifier-op ::= "::" | "->" | "."
identifier-exp ::= [identifier-op] identifier (identifier-op identifier)*
comment ::= "#" <any characters> "\n"
comment ::= C++ single or multi-line comments
separator ::= "," | ";"
number ::= <legal C printf number format>
string ::= <legal C double-quoted string; backslashes must be escaped>
boolean ::= "True" | "False"
none ::= "None"
array ::= "(" [value ("," value)*] ")"
array ::= ("(" | "[") [ value (separator value)* [separator] ] (")" | "]")
pair ::= (identifier | string) "=" value
table ::= "{" [pair (separator pair)*] "}"
named-array ::= identifier-exp tuple
named-table ::= identifier-exp dict
table ::= "{" [ pair (separator pair)* [separator] ] "}"
named-array ::= identifier-exp array
named-table ::= identifier-exp table
include ::= "#" "include" "(" string ")"
value ::= [comment] (none | number | boolean | string | array | table | named-array | named-table)
value ::= [comment] (none | number | boolean | string | array | table | named-array | named-table | include)
</pre>
Except for single-line comments, whitespace is not significant.
All parsing is case-insensitive.
The include expression pastes the contents of the named file in as if
they appeared in the original source. Note that an include expression
can only appear in the locations where a value is expected. This means
that it cannot yield more than one element of an array and cannot serve
as the pair in a table.
The deserializer allows the substitution of [] for () when writing
tuples and ";" for ",".
tuples and ";" for ",". These are convenient when mimicing a
programming language, e.g., <code>"[ printf("hello world."); clearScreen();]"</code>
parses as an array containing two named arrays within it. The
deserializer also allows a trailing comma inside any array or table,
which also convenient when commenting out the last element.
The serializer indents four spaces for each level of nesting.
Tables are written with the keys in alphabetic order.
@@ -407,9 +438,32 @@ public:
const std::string& string() const;
bool boolean() const;
/** If a valid string, takes the string value and creates a fully qualified filename.
If not found, the returned string is empty.
The file is searched for the following ways:
- In the directory from which the Any was loaded.
- By calling System::findDataFile as you would with other data files.
*/
std::string resolveStringAsFilename() const;
/** If this is named ARRAY or TABLE, returns the name. */
const std::string& name() const;
/** If this is named ARRAY or TABLE, returns true if the name begins with \a s. The comparision is case insensitive. */
bool nameBeginsWith(const std::string& s) const;
/** If this is named ARRAY or TABLE, returns true if the name begins with \a s. The comparision is case insensitive. */
bool nameBeginsWith(const char* s) const;
/** If this is named ARRAY or TABLE, returns true if the name is \a s. The comparision is case insensitive. */
bool nameEquals(const std::string& s) const;
/** If this is named ARRAY or TABLE, returns true if the name is\a s. The comparision is case insensitive. */
bool nameEquals(const char* s) const;
/** \brief Set the name used when serializing an ARRAY or TABLE.
Only legal for ARRAY or TABLE. The \a name must begin with a letter
@@ -439,6 +493,14 @@ public:
const Any& operator[](int i) const;
Any& operator[](int i);
const Any& last() const {
return (*this)[size() - 1];
}
Any& last() {
return (*this)[size() - 1];
}
/** Directly exposes the underlying data structure for an ARRAY. */
const Array<Any>& array() const;
void append(const Any& v0);
@@ -503,6 +565,10 @@ public:
/** for an ARRAY, resizes and returns the last element */
Any& next();
/** The parent directory of the location from which this Any was loaded. This is useful for
interpreting filenames relative to the Any's source location,
which may not match the current directory if the Any was from an included file. */
std::string sourceDirectory() const;
/** True if the Anys are exactly equal, ignoring comments. Applies deeply on arrays and tables. */
bool operator==(const Any& x) const;
@@ -542,10 +608,15 @@ public:
*/
void verify(bool value, const std::string& message = "") const;
/** Verifies that the name begins with identifier \a n. It may contain
identifier operators after this */
/** Verifies that the name <i>begins with</i> identifier \a n (case insensitive).
It may contain identifier operators after this */
void verifyName(const std::string& n) const;
/** Verifies that the name <i>begins with</i> identifier \a n or \a m (case insensitive).
It may contain identifier operators after this */
void verifyName(const std::string& n, const std::string& m) const;
/** Verifies that the type is \a t. */
void verifyType(Type t) const;
@@ -1,12 +1,12 @@
/**
@file BinaryInput.h
@maintainer Morgan McGuire, graphics3d.com
@maintainer Morgan McGuire, http://graphics.cs.williams.edu
@created 2001-08-09
@edited 2006-07-19
@edited 2010-03-19
Copyright 2000-2009, Morgan McGuire.
Copyright 2000-2010, Morgan McGuire.
All rights reserved.
*/
@@ -370,6 +370,9 @@ public:
*/
std::string readString();
/** Reads until \r, \r\n, \n\r, \n or the end of the file is encountered. Consumes the newline.*/
std::string readStringNewline();
/**
Reads until NULL or the end of the file is encountered.
If the string has odd length (including NULL), reads
@@ -1,20 +1,27 @@
/**
@file Color3uint8.h
@maintainer Morgan McGuire, graphics3d.com
@maintainer Morgan McGuire, http://graphics.cs.williams.edu
@created 2003-04-07
@edited 2006-06-24
@edited 2010-03-24
Copyright 2000-2006, Morgan McGuire.
Copyright 2000-2010, Morgan McGuire.
All rights reserved.
*/
#ifndef G3D_COLOR3UINT8_H
#define G3D_COLOR3UINT8_H
#ifndef G3D_Color3uint8_h
#define G3D_Color3uint8_h
#include "G3D/platform.h"
#include "G3D/g3dmath.h"
#ifdef max
#undef max
#endif
#ifdef min
#undef min
#endif
namespace G3D {
@@ -53,7 +60,7 @@ public:
Color3uint8(class BinaryInput& bi);
inline static Color3uint8 fromARGB(uint32 i) {
static Color3uint8 fromARGB(uint32 i) {
Color3uint8 c;
c.r = (i >> 16) & 0xFF;
c.g = (i >> 8) & 0xFF;
@@ -61,15 +68,23 @@ public:
return c;
}
inline Color3uint8 bgr() const {
Color3uint8 bgr() const {
return Color3uint8(b, g, r);
}
Color3uint8 max(const Color3uint8 x) const {
return Color3uint8(G3D::max(r, x.r), G3D::max(g, x.g), G3D::max(b, x.b));
}
Color3uint8 min(const Color3uint8 x) const {
return Color3uint8(G3D::min(r, x.r), G3D::min(g, x.g), G3D::min(b, x.b));
}
/**
Returns the color packed into a uint32
(the upper byte is 0xFF)
*/
inline uint32 asUInt32() const {
uint32 asUInt32() const {
return (0xFF << 24) + ((uint32)r << 16) + ((uint32)g << 8) + b;
}
@@ -95,12 +110,12 @@ public:
return (uint8*)this;
}
bool operator==(const Color3uint8& other) const {
bool operator==(const Color3uint8 other) const {
return (other.r == r) && (other.g == g) && (other.b == b);
}
bool operator!=(const Color3uint8& other) const {
return (other.r != r) && (other.g != g) && (other.b != b);
bool operator!=(const Color3uint8 other) const {
return ! (*this == other);
}
}
G3D_END_PACKED_CLASS(1)
@@ -117,9 +117,18 @@ public:
Color4 operator+ (const Color4& rkVector) const;
Color4 operator- (const Color4& rkVector) const;
Color4 operator* (float fScalar) const;
inline Color4 operator* (const Color4& k) const {
Color4 operator* (const Color4& k) const {
return Color4(r*k.r, g*k.g, b*k.b, a * k.a);
}
Color4& operator*= (const Color4& c) {
r *= c.r;
g *= c.g;
b *= c.b;
a *= c.a;
return *this;
}
Color4 operator/ (float fScalar) const;
Color4 operator- () const;
friend Color4 operator* (double fScalar, const Color4& rkVector);
@@ -1,12 +1,12 @@
/**
@file Color4uint8.h
@maintainer Morgan McGuire, graphics3d.com
@maintainer Morgan McGuire, http://graphics.cs.williams.edu
@created 2003-04-07
@edited 2006-03-24
@edited 2010-03-24
Copyright 2000-2006, Morgan McGuire.
Copyright 2000-2010, Morgan McGuire.
All rights reserved.
*/
@@ -50,6 +50,14 @@ public:
Color4uint8(const class Color4& c);
Color4uint8 max(const Color4uint8 x) const {
return Color4uint8(G3D::max(r, x.r), G3D::max(g, x.g), G3D::max(b, x.b), G3D::max(a, x.a));
}
Color4uint8 min(const Color4uint8 x) const {
return Color4uint8(G3D::min(r, x.r), G3D::min(g, x.g), G3D::min(b, x.b), G3D::min(a, x.a));
}
Color4uint8(const uint8 _r, const uint8 _g, const uint8 _b, const uint8 _a) : r(_r), g(_g), b(_b), a(_a) {}
Color4uint8(const Color3uint8& c, const uint8 _a) : r(c.r), g(c.g), b(c.b), a(_a) {}
@@ -68,6 +68,8 @@ public:
- CFrame((matrix3 expr), (vector3 expr))
- CFrame::fromXYZYPRDegrees(#, #, #, #, #, #)
- CFrame { rotation = (matrix3 expr), translation = (vector3 expr) }
- Vector3( ... )
- Matrix3( ... )
*/
CoordinateFrame(const Any& any);
@@ -109,6 +111,8 @@ public:
static CoordinateFrame fromXYZYPRRadians(float x, float y, float z, float yaw = 0.0f, float pitch = 0.0f, float roll = 0.0f);
std::string toXYZYPRDegreesString() const;
/** Construct a coordinate frame from translation = (x,y,z) and
rotations (in that order) about Y, object space X, object space
Z. Note that because object-space axes are used, these are not
+466
View File
@@ -0,0 +1,466 @@
/**
@file FileSystem.h
@author Morgan McGuire, http://graphics.cs.williams.edu
@author 2002-06-06
@edited 2010-02-05
*/
#ifndef G3D_FileSystem_h
#define G3D_FileSystem_h
#include "G3D/platform.h"
#include "G3D/Array.h"
#include "G3D/Table.h"
namespace G3D {
/**
OS-independent file system layer that optimizes the performance
of queries by caching and prefetching.
This class uses the following definitions:
<ul>
<li> "file" = document that can be opened for reading or writing
<li> "directory" = folder containing files and other directories
<li> "node" = file or directory
<li> "path" = string identifying a (see the FSPath class)
<li> "zipfile" = a compressed file storing an archive of files and directories in the zip format
</ul>
In G3D, Zipfiles are transparently treated as if they were directories, provided:
<ul>
<li> The zipfile name contains an extension (e.g., map.pk3, files.zip)
<li> There are no nested zipfiles
</ul>
The extension requirement allows G3D to quickly identify whether a path could enter a
zipfile without forcing it to open all parent directories for reading.
\sa FilePath
TODO: make threadsafe!
*/
class FileSystem {
public:
class ListSettings {
public:
/** Defaults to true */
bool files;
/** Defaults to true */
bool directories;
/** Defaults to true on Windows, false on other platforms.*/
bool caseSensitive;
/** Can get recurse into subdirectories? Defaults to true. */
bool recursive;
/** Prefix the full path onto names that are returned. Defaults to true */
bool includeParentPath;
ListSettings() :
files(true),
directories(true),
# ifdef G3D_WIN32
caseSensitive(true),
# else
caseSensitive(false),
# endif
recursive(false),
includeParentPath(true) {}
};
private:
/** Drive letters. Only used on windows, but defined on all platforms to help
avoid breaking the Windows build when compiling on another platform. */
Array<std::string> m_winDrive;
float m_cacheLifetime;
enum Type {
/** Not yet checked */
UNKNOWN,
FILE_TYPE,
DIR_TYPE
};
class Entry {
public:
/** Name, not including parent path */
std::string name;
Type type;
Entry() : type(UNKNOWN) {}
Entry(const char* n) : name(n), type(UNKNOWN) {}
};
class Dir {
public:
/** If false, this path did not exist (even inside a zipfile) when last checked, or it is not a directory. */
bool exists;
bool isZipfile;
bool inZipfile;
/** Files and directories */
Array<Entry> nodeArray;
/** When this entry was last updated */
double lastChecked;
/** Case-independent comparison on Windows */
bool contains(const std::string& child) const;
/** Compute the contents of nodeArray from this zipfile. */
void computeZipListing(const std::string& zipfile, const std::string& pathInsideZipfile);
Dir() : exists(false), isZipfile(false), inZipfile(false), lastChecked(0) {}
};
/** Maps path names (without trailing slashes, except for the file system root) to contents.
On Windows, all paths are lowercase */
Table<std::string, Dir> m_cache;
/** Update the cache entry for path if it is not already present.
\param forceUpdate If true, always override the current cache value.*/
Dir& getContents(const std::string& path, bool forceUpdate);
/** Don't allow public construction. */
FileSystem();
static FileSystem& instance();
# ifdef G3D_WIN32
/** On Windows, the drive letters that form the file system roots.*/
const Array<std::string>& _drives();
# endif
/** Returns true if some sub-path of \a path is a zipfile.
If the path itself is a zipfile, returns false.
\param zipfile The part of \a path that was the zipfile */
bool _inZipfile(const std::string& path, std::string& zipfile);
/** Clears old cache entries so that exists() and list() will reflect recent changes to the file system.
\param path Clear only \a path and its subdirectories ("" means clear the entire cache) */
void _clearCache(const std::string& path);
bool _inZipfile(const std::string& path) {
std::string ignore;
return inZipfile(path, ignore);
}
/** Set the cacheLifetime().
\param t in seconds */
void _setCacheLifetime(float t);
/** A cache is used to optimize repeated calls. A cache entry is considered
valid for this many seconds after it has been checked. */
float _cacheLifetime() const {
return m_cacheLifetime;
}
/** Creates the directory named, including any subdirectories
that do not already exist.
The directory must not be inside a zipfile.
Flushes the cache.
*/
void _createDirectory(const std::string& path);
/** Returns true if a node named \a f exists.
\param f If \a f contains wildcards, the function returns true if any file
matches those wildcards. Wildcards may only appear in the base or ext, not the
path.
\param trustCache If true, uses the cache for optimizing repeated calls
in the same parent directory.
*/
bool _exists(const std::string& f, bool trustCache = true);
/** Known bug: does not work inside zipfiles */
bool _isDirectory(const std::string& path);
/** Known bug: does not work inside zipfiles */
bool _isFile(const std::string& path) {
return ! isDirectory(path);
}
/**
\param srcPath Must name a file.
\param dstPath Must not contain a zipfile.
Flushes the cache.
*/
void _copyFile(const std::string& srcPath, const std::string& dstPath);
/** Fully qualifies a filename.
The filename may contain wildcards, in which case the wildcards will be preserved in the returned value.
\param cwd The directory to treat as the "current" directory when resolving a relative path. The default
value is the actual current directory. (G3D::Any::sourceDirectory is a common alternative)
*/
std::string _resolve(const std::string& path, const std::string& cwd = currentDirectory());
/** Returns true if \param dst does not exist or \param src is newer than \param dst,
according to their time stamps.
Known bug: does not work inside zipfiles.
*/
bool _isNewer(const std::string& src, const std::string& dst);
/** The current working directory (cwd). Only ends in a slash if this is the root of the file system. */
std::string _currentDirectory();
/** Returns the length of the file in bytes, or -1 if the file could not be opened. */
int64 _size(const std::string& path);
/** Called from list() */
void listHelper(const std::string& shortSpec, const std::string& parentPath, Array<std::string>& result, const ListSettings& settings);
/** Appends all nodes matching \a spec to the \a result array.
Wildcards can only appear to the right of the last slash in \a spec.
The names will not contain parent paths unless \a includePath == true.
These may be relative to the current directory unless \a spec
is fully qualified (can be done with resolveFilename).
*/
void _list(const std::string& spec, Array<std::string>& result, const ListSettings& listSettings = ListSettings());
/** Returns true if \a path is a file that is a zipfile. Note that G3D requires zipfiles to have
some extension, although it is not required to be "zip" */
bool _isZipfile(const std::string& path);
/** list() files */
void _getFiles(const std::string& spec, Array<std::string>& result, bool includeParentPath = false) {
ListSettings set;
set.includeParentPath = includeParentPath;
set.directories = false;
set.files = true;
return list(spec, result, set);
}
/** list() directories */
void _getDirectories(const std::string& spec, Array<std::string>& result, bool includeParentPath = false) {
ListSettings set;
set.includeParentPath = includeParentPath;
set.directories = true;
set.files = false;
return list(spec, result, set);
}
/** Same as the C standard library fopen, but updates the file cache
to acknowledge the new file on a write operation. */
FILE* _fopen(const char* filename, const char* mode);
public:
/** Create the common instance. */
static void init();
/** Destroy the common instance. */
static void cleanup();
# ifdef G3D_WIN32
/** \copydoc _drives */
static const Array<std::string>& drives() {
return instance()._drives();
}
# endif
/** \copydoc _inZipfile */
static bool inZipfile(const std::string& path, std::string& zipfile) {
return instance()._inZipfile(path, zipfile);
}
/** \copydoc _clearCache */
static void clearCache(const std::string& path = "") {
instance()._clearCache(path);
}
/** \copydoc _fopen */
static FILE* fopen(const char* filename, const char* mode) {
return instance()._fopen(filename, mode);
}
static void fclose(FILE* f) {
::fclose(f);
}
static bool inZipfile(const std::string& path) {
return instance()._inZipfile(path);
}
/** \copydoc isZipfile */
static bool isZipfile(const std::string& path) {
return instance()._isZipfile(path);
}
/** \copydoc _setCacheLifetime */
void setCacheLifetime(float t) {
instance()._setCacheLifetime(t);
}
/** \copydoc _cacheLifetime */
static float cacheLifetime() {
return instance()._cacheLifetime();
}
/** \copydoc _createDirectory */
static void createDirectory(const std::string& path) {
instance()._createDirectory(path);
}
/** \copydoc _currentDirectory */
static std::string currentDirectory() {
return instance()._currentDirectory();
}
/** \copydoc _copyFile */
static void copyFile(const std::string& srcPath, const std::string& dstPath) {
instance()._copyFile(srcPath, dstPath);
}
/** \copydoc _exists */
static bool exists(const std::string& f, bool trustCache = true) {
return instance()._exists(f, trustCache);
}
/** \copydoc _isDirectory */
static bool isDirectory(const std::string& path) {
return instance()._isDirectory(path);
}
/** \copydoc _isFile */
static bool isFile(const std::string& path) {
return instance()._isFile(path);
}
/** \copydoc _resolve */
static std::string resolve(const std::string& path, const std::string& cwd = currentDirectory()) {
return instance()._resolve(path, cwd);
}
/** \copydoc _isNewer */
static bool isNewer(const std::string& src, const std::string& dst) {
return instance()._isNewer(src, dst);
}
/** \copydoc _size */
static int64 size(const std::string& path) {
return instance()._size(path);
}
/** \copydoc _list */
static void list(const std::string& spec, Array<std::string>& result,
const ListSettings& listSettings = ListSettings()) {
return instance()._list(spec, result, listSettings);
}
/** \copydoc _getFiles */
static void getFiles(const std::string& spec, Array<std::string>& result, bool includeParentPath = false) {
return instance()._getFiles(spec, result, includeParentPath);
}
/** \copydoc getDirectories */
static void getDirectories(const std::string& spec, Array<std::string>& result, bool includeParentPath = false) {
return instance()._getDirectories(spec, result, includeParentPath);
}
};
/** \brief Parsing of file system paths.
None of these routines touch the disk--they are purely string manipulation.
In "/a/b/base.ext",
<ul>
<li> base = "base"
<li> ext = "ext"
<li> parentPath = "/a/b"
<li> baseExt = "base.ext"
</ul>
*/
class FilePath {
public:
/** Appends file onto dirname, ensuring a / if needed. */
static std::string concat(const std::string& a, const std::string& b);
static bool isRoot(const std::string& f);
/** Removes the trailing slash unless \a f is a filesystem root */
static std::string removeTrailingSlash(const std::string& f);
/** Returns everything to the right of the last '.' */
static std::string ext(const std::string& path);
/** Returns everything to the right of the last slash (or, on Windows, the last ':') */
static std::string baseExt(const std::string& path);
/** Returns everything between the right-most slash and the following '.' */
static std::string base(const std::string& path);
/** Returns everything to the left of the right-most slash */
static std::string parent(const std::string& path);
/** Returns true if '*' or '?' appear in the filename */
static bool containsWildcards(const std::string& p);
/** Convert all slashes to '/' */
static std::string canonicalize(std::string x);
/**
Parses a filename into four useful pieces.
Examples:
c:\\a\\b\\d.e
root = "c:\\"
path = "a" "b"
base = "d"
ext = "e"
/a/b/d.e
root = "/"
path = "a" "b"
base = "d"
ext = "e"
/a/b
root = "/"
path = "a"
base = "b"
ext = "e"
*/
static void parse
(const std::string& filename,
std::string& drive,
Array<std::string>& path,
std::string& base,
std::string& ext);
/**
Returns true if \a path matches \a pattern, with standard filesystem wildcards.
*/
static bool matches(const std::string& path, const std::string& pattern, bool caseSensitive = true);
};
} // namespace G3D
#endif
@@ -7,7 +7,7 @@
@maintainer Morgan McGuire, http://graphics.cs.williams.edu
@created 2001-08-25
@edited 2010-01-30
@edited 2010-03-20
Copyright 2000-2010, Morgan McGuire.
All rights reserved.
@@ -44,6 +44,7 @@
#include "G3D/Matrix4.h"
#include "G3D/CoordinateFrame.h"
#include "G3D/PhysicsFrame.h"
#include "G3D/PhysicsFrameSpline.h"
#include "G3D/Plane.h"
#include "G3D/Line.h"
#include "G3D/Ray.h"
@@ -57,6 +58,7 @@
#include "G3D/stringutils.h"
#include "G3D/prompt.h"
#include "G3D/Table.h"
#include "G3D/FileSystem.h"
#include "G3D/Set.h"
#include "G3D/GUniqueID.h"
#include "G3D/BinaryFormat.h"
@@ -118,6 +120,7 @@ template<class T> struct HashTrait< G3D::ReferenceCountedPointer<T> > {
#include "G3D/ThreadSet.h"
#include "G3D/RegistryUtil.h"
#include "G3D/Any.h"
#include "G3D/XML.h"
#include "G3D/PointHashGrid.h"
#include "G3D/Map2D.h"
#include "G3D/Image1.h"
@@ -38,6 +38,9 @@ class Any;
All viewport arguments are the pixel bounds of the viewport-- e.g.,
RenderDevice::viewport().
See http://bittermanandy.wordpress.com/2009/04/10/a-view-to-a-thrill-part-one-camera-concepts/
for a nice introduction to camera transformations.
*/
class GCamera {
@@ -64,6 +67,8 @@ private:
/** Horizontal or Vertical */
FOVDirection m_direction;
Vector2 m_pixelOffset;
public:
/** Must be of the format produced by the Any cast, e.g.,
@@ -117,6 +122,18 @@ public:
return m_cframe;
}
/** Displacement from the upper left added in pixels in screen
space to the projection matrix. This is useful for shifting
the sampled location from the pixel center (OpenGL convention)
to other locations, such as the upper-left.*/
void setPixelOffset(const Vector2& p) {
m_pixelOffset = p;
}
const Vector2& pixelOffset() const {
return m_pixelOffset;
}
/** Sets c to the camera's coordinate frame */
void getCoordinateFrame(CoordinateFrame& c) const;
@@ -154,7 +171,7 @@ public:
This is the full angle, i.e., from the left side of the
viewport to the right side.
*/
void setFieldOfView(float angle, FOVDirection direction);
void setFieldOfView(float edgeToEdgeAngleRadians, FOVDirection direction);
/** Returns the current full field of view angle (from the left side of the
viewport to the right side) and direction */
@@ -45,7 +45,7 @@ class BinaryOutput;
Supported formats (decode and encode): Color JPEG, PNG,
(Uncompressed) TGA 24, (Uncompressed) TGA 32, BMP 1, BMP 4, BMP 8, BMP
24, PPM (P6), and PPM ASCII (P1, P2, P3), which includes PPM, PGM,
and PBM. 8-bit paletted PCX, 24-bit PCX, and ICO are supported for
and PBM. (Compressed) TGA 24, (Compressed) TGA 32, 8-bit paletted PCX, 24-bit PCX, and ICO are supported for
decoding only.
Sample usage:
@@ -78,6 +78,10 @@ class BinaryOutput;
recommended over GImage (we don't include it directly in G3D because their license
is more restrictive than the BSD one).
\cite http://tfcduke.developpez.com/tutoriel/format/tga/fichiers/tga_specs.pdf
\sa Image3, Image3uint8, Image4, Image4uint8, Image1, Image1uint8, Texture, Map2D
*/
class GImage {
private:
@@ -90,6 +90,13 @@ public:
const Color3& color, float constAtt = 1, float linAtt = 0, float quadAtt = 0,
bool specular = true, bool diffuse = true);
/** Creates a spot light that looks at a specific point (by calling spot() ) */
static GLight spotTarget(const Vector3& pos, const Vector3& target, float cutOffAngleDegrees,
const Color3& color, float constAtt = 1, float linAtt = 0, float quadAtt = 0,
bool specular = true, bool diffuse = true) {
return spot(pos, target - pos, cutOffAngleDegrees, color, constAtt, linAtt, quadAtt, specular, diffuse);
}
/** Returns the sphere within which this light has some noticable effect. May be infinite.
@param cutoff The value at which the light intensity is considered negligible. */
class Sphere effectSphere(float cutoff = 30.0f / 255) const;
@@ -52,7 +52,7 @@ template <> struct HashTrait <G3D::uint32> {
static size_t hashCode(G3D::uint32 k) { return static_cast<size_t>(k); }
};
#if 0
#ifdef G3D_OSX
template <> struct HashTrait <long unsigned int> {
static size_t hashCode(G3D::uint32 k) { return static_cast<size_t>(k); }
};
@@ -4,7 +4,7 @@
@maintainer Morgan McGuire, http://graphics.cs.williams.edu
@created 2003-05-23
@edited 2010-01-01
@edited 2010-05-01
*/
#ifndef GLG3D_ImageFormat_H
@@ -13,6 +13,7 @@
#include "G3D/platform.h"
#include "G3D/Table.h"
#include "G3D/enumclass.h"
#include "G3D/Any.h"
namespace G3D {
@@ -57,13 +58,19 @@ public:
CODE_RGB8I,
CODE_RGB8UI,
CODE_RGBA8UI,
CODE_ARGB8,
CODE_BGR8,
CODE_R8,
CODE_RG8,
CODE_RG8I,
CODE_RG8UI,
CODE_RG16F,
CODE_RGBA8,
CODE_RGBA16,
CODE_RGBA16F,
@@ -260,10 +267,14 @@ public:
static const ImageFormat* BGR8();
static const ImageFormat* R8();
static const ImageFormat* RG8();
static const ImageFormat* RG8I();
static const ImageFormat* RG8UI();
static const ImageFormat* RG16F();
static const ImageFormat* RGB5();
static const ImageFormat* RGB5A1();
@@ -298,6 +309,8 @@ public:
static const ImageFormat* RGB8UI();
static const ImageFormat* RGBA8UI();
static const ImageFormat* RGB_DXT1();
static const ImageFormat* RGBA_DXT1();
@@ -376,9 +389,18 @@ public:
NEAREST,
BILINEAR,
MHC,
HIGH_QUALITY = MHC
BEST = MHC
};
private:
static const char* toString(int i, Value& v) {
static const char* str[] = {"NEAREST", "BILINEAR", "MHC", "BEST", NULL};
static const Value val[] = {NEAREST, BILINEAR, MHC, BEST};
const char* s = str[i];
if (s) {
v = val[i];
}
return s;
}
Value value;
@@ -399,7 +421,7 @@ public:
*/
static bool convert(const Array<const void*>& srcBytes, int srcWidth, int srcHeight, const ImageFormat* srcFormat, int srcRowPadBits,
const Array<void*>& dstBytes, const ImageFormat* dstFormat, int dstRowPadBits,
bool invertY = false, BayerAlgorithm bayerAlg = BayerAlgorithm::HIGH_QUALITY);
bool invertY = false, BayerAlgorithm bayerAlg = BayerAlgorithm::MHC);
/* Checks if a conversion between two formats is available. */
static bool conversionAvailable(const ImageFormat* srcFormat, int srcRowPadBits, const ImageFormat* dstFormat, int dstRowPadBits, bool invertY = false);
@@ -1,5 +1,5 @@
#ifndef G3D_MATRIX2_H
#define G3D_MATRIX2_H
#ifndef G3D_Matrix2_h
#define G3D_Matrix2_h
#include "G3D/platform.h"
#include "G3D/Vector2.h"
@@ -14,54 +14,59 @@ private:
public:
inline Matrix2() {
Matrix2() {
data[0][0] = 1.0f; data[0][1] = 0.0f;
data[1][0] = 0.0f; data[1][1] = 1.0f;
}
inline Matrix2(float v00, float v01, float v10, float v11) {
Matrix2(float v00, float v01, float v10, float v11) {
data[0][0] = v00; data[0][1] = v01;
data[1][0] = v10; data[1][1] = v11;
}
inline Vector2 operator*(const Vector2& v) const {
static Matrix2 identity() {
return Matrix2(1.0f, 0.0f, 0.0f, 1.0f);
}
Vector2 operator*(const Vector2& v) const {
return Vector2(data[0][0] * v[0] + data[0][1] * v[1],
data[1][0] * v[0] + data[1][1] * v[1]);
}
inline Matrix2 inverse() const {
return Matrix2(data[0][0], data[1][0],
data[0][1], data[1][1]) * (1.0f / determinant());
Matrix2 inverse() const {
return Matrix2(data[1][1], -data[0][1],
-data[1][0], data[0][0]) * (1.0f / determinant());
}
inline Matrix2 transpose() const {
Matrix2 transpose() const {
return Matrix2(data[0][0], data[1][0],
data[0][1], data[1][1]);
}
inline float determinant() const {
float determinant() const {
return data[0][0] * data[1][1] - data[0][1] * data[1][0];
}
inline Matrix2 operator*(float f) const {
Matrix2 operator*(float f) const {
return Matrix2(data[0][0] * f, data[0][1] * f,
data[1][0] * f, data[1][1] * f);
}
inline Matrix2 operator/(float f) const {
Matrix2 operator/(float f) const {
return Matrix2(data[0][0] / f, data[0][1] / f,
data[1][0] / f, data[1][1] / f);
}
inline float* operator[](int i) {
float* operator[](int i) {
debugAssert(i >= 0 && i <= 2);
return data[i];
}
inline const float* operator[](int i) const {
const float* operator[](int i) const {
debugAssert(i >= 0 && i <= 1);
return data[i];
}
};
}
@@ -119,6 +119,15 @@ public:
}
Matrix4 operator*(const Matrix4& other) const;
Matrix4 operator+(const Matrix4& other) const {
Matrix4 result;
for (int r = 0; r < 4; ++r) {
for (int c = 0; c < 4; ++c) {
result.elt[r][c] = elt[r][c] + other.elt[r][c];
}
}
return result;
}
class Matrix3 upper3x3() const;
@@ -600,7 +600,7 @@ public:
outIndices.resize(N + (inSize - 2) * 3);
bool atEven = false;
for (IndexType i = 0, outIndex = N; i <= (inSize - 2); ++i, outIndex += 3) {
for (IndexType i = 0, outIndex = N; i < (inSize - 2); ++i, outIndex += 3) {
if (atEven) {
outIndices[outIndex] = inIndices[i + 1];
outIndices[outIndex + 1] = inIndices[i];
@@ -1,33 +1,9 @@
#ifndef G3D_NETADDRESS_H
#define G3D_NETADDRESS_H
#ifndef G3D_NetAddress_h
#define G3D_NetAddress_h
#include "G3D/platform.h"
#include "G3D/Table.h"
/** These control the version of Winsock used by G3D.
Version 2.0 is standard for G3D 6.09 and later.
Version 1.1 is standard for G3D 6.08 and earlier.
*/
#define G3D_WINSOCK_MAJOR_VERSION 2
#define G3D_WINSOCK_MINOR_VERSION 0
#ifdef G3D_WIN32
# if (G3D_WINSOCK_MAJOR_VERSION == 2)
# include <winsock2.h>
# elif (G3D_WINSOCK_MAJOR_VERSION == 1)
# include <winsock.h>
# endif
#else
# include <sys/types.h>
# include <sys/socket.h>
# include <netinet/in.h>
# ifndef SOCKADDR_IN
# define SOCKADDR_IN struct sockaddr_in
# endif
# ifndef SOCKET
# define SOCKET int
# endif
#endif
#include "G3D/netheaders.h"
#include "G3D/g3dmath.h"
@@ -258,8 +258,8 @@ public:
~ReliableConduit();
// The message is actually copied from the socket to an internal buffer during
// this call. Receive only deserializes.
/** The message is actually copied from the socket to an internal buffer during
this call. Receive only deserializes.*/
virtual bool messageWaiting();
/**
@@ -348,6 +348,7 @@ public:
messageWaiting();
}
/** The address of the other end of the conduit */
NetAddress address() const;
};
@@ -43,19 +43,27 @@ public:
PhysicsFrame();
/**
Purely translational force
Purely translational.
*/
PhysicsFrame(const Vector3& translation) : translation(translation) {}
PhysicsFrame(const Quat& rot, const Vector3& translation) : rotation(rot), translation(translation) {}
PhysicsFrame(const Matrix3& rot, const Vector3& translation) : rotation(rot), translation(translation) {}
PhysicsFrame(const Matrix3& rot) : rotation(rot), translation(Vector3::zero()) {}
PhysicsFrame(const CoordinateFrame& coordinateFrame);
/**
- PhysicsFrame( [quat], [vec3] )
- Vector3( ... )
- CFrame( ... )
- CFrame::from...( ... )
*/
PhysicsFrame(const class Any& any);
/** Compose: create the transformation that is <I>other</I> followed by <I>this</I>.*/
PhysicsFrame operator*(const PhysicsFrame& other) const;
virtual ~PhysicsFrame() {}
CoordinateFrame toCoordinateFrame() const;
/**
Linear interpolation (spherical linear for the rotations).
*/
@@ -67,8 +75,35 @@ public:
void serialize(class BinaryOutput& b) const;
operator CFrame() const;
/** Multiplies both pieces by \a f; note that this will result in a non-unit
quaternion that needs to be normalized */
PhysicsFrame& operator*=(float f) {
rotation *= f;
translation *= f;
return *this;
}
/** Multiplies both pieces by \a f; note that this will result in a non-unit
quaternion that needs to be normalized */
PhysicsFrame operator*(float f) const {
return PhysicsFrame(rotation * f, translation * f);
}
PhysicsFrame operator+(const PhysicsFrame& f) const {
return PhysicsFrame(rotation + f.rotation, translation + f.translation);
}
PhysicsFrame& operator+=(const PhysicsFrame& f) {
rotation += f.rotation;
translation += f.translation;
return *this;
}
};
typedef PhysicsFrame PFrame;
} // namespace
#endif
@@ -0,0 +1,37 @@
/**
@file PhysicsFrameSpline.h
@author Morgan McGuire, http://graphics.cs.williams.edu
*/
#ifndef G3D_PhysicsFrameSpline_h
#define G3D_PhysicsFrameSpline_h
#include "G3D/platform.h"
#include "G3D/PhysicsFrame.h"
#include "G3D/Spline.h"
namespace G3D {
/**
A subclass of Spline that keeps the rotation field of a
PhysicsFrame normalized and rotating the short direction.
\sa UprightFrameSpline
*/
class PhysicsFrameSpline : public Spline<PhysicsFrame> {
public:
PhysicsFrameSpline();
/** Accepts a table of properties, or any valid PhysicsFrame specification for a single control*/
PhysicsFrameSpline(const Any& any);
/** Clear and then reset all values from the any */
PhysicsFrameSpline& operator=(const Any& any);
virtual void correct(PhysicsFrame& frame) const;
virtual void ensureShortestPath(PhysicsFrame* A, int N) const;
};
}
#endif
@@ -5,7 +5,7 @@
@created 2008-07-01
@edited 2009-05-28
Copyright 2000-2009, Morgan McGuire.
Copyright 2000-2010, Morgan McGuire.
All rights reserved.
*/
#ifndef G3D_PointHashGrid_h
@@ -30,18 +30,44 @@ namespace G3D {
approximately uniform density (with respect to the radius hint),
the time cost of searching for neighbors is O(1).
<i>Value</i> must be supported by a G3D::PositionTrait,
G3D::EqualsTrait, and G3D::HashFunc. overrides are provided for
common G3D classes like G3D::Vector3.
<i>Value</i> must be supported by a G3D::PositionTrait and
G3D::EqualsTrait. Overloads are provided for
common G3D classes like G3D::Vector3. For example:
<pre>
class EqualsFunc {
public:
static bool equals(const Data& p, const Data& q) {
return p == q;
}
};
class PosFunc {
public:
static void getPosition(const Data& d, Vector3& pos) {
pos = d.location;
}
};
PointHashGrid<Data, Data::PosFunc, Data::EqualsFunc> grid;
</pre>
If the Value class defines operator==, the Equalsfunc is optional:
<pre>
PointHashGrid<Data, Data::PosFunc> grid;
</pre>
*/
template<class Value,
class PosFunc = PositionTrait<Value>,
class EqualsFunc = EqualsTrait<Value>,
class HashFunc = HashTrait<Vector3int32> >
class EqualsFunc = EqualsTrait<Value> >
class PointHashGrid {
private:
#define ThisType PointHashGrid<Value, PosFunc, EqualsFunc, HashFunc>
# define expectedCellSize (3)
# define ThisType PointHashGrid<Value, PosFunc, EqualsFunc>
/** A value annotated with precomputed position and hash code.*/
class Entry {
@@ -51,8 +77,8 @@ private:
};
/** One cell of the grid. */
typedef Array<Entry> Cell;
typedef Table<Vector3int32, Cell, HashFunc> CellTable;
typedef SmallArray<Entry, expectedCellSize> Cell;
typedef Table<Vector3int32, Cell > CellTable;
/** The cube of +/-1 along each dimension. Initialized by initOffsetArray.*/
Vector3int32 m_offsetArray[3*3*3];
@@ -182,11 +208,11 @@ public:
Array<Entry> entry(init.size());
for (int i = 0; i < entry.size(); ++i) {
const Value& value = init[i];
Vector3 pos = m_posFunc(value);
Vector3 pos;
entry[i].value = value;
entry[i].hashCode = m_hashFunc(value);
entry[i].position = pos;
PosFunc::getPosition(value, entry[i].position);
lo = lo.min(pos);
hi = hi.max(pos);
@@ -21,6 +21,8 @@
namespace G3D {
/**
Arbitrary quaternion (not necessarily unit)
Unit quaternions are used in computer graphics to represent
rotation about an axis. Any 3x3 rotation matrix can
be stored as a quaternion.
@@ -42,7 +44,7 @@ namespace G3D {
Do not subclass.
<B>BETA API -- subject to change</B>
@cite Erik B. Dam, Martin Koch, Martin Lillholm, Quaternions, Interpolation and Animation. Technical Report DIKU-TR-98/5, Department of Computer Science, University of Copenhagen, Denmark. 1998.
\cite Erik B. Dam, Martin Koch, Martin Lillholm, Quaternions, Interpolation and Animation. Technical Report DIKU-TR-98/5, Department of Computer Science, University of Copenhagen, Denmark. 1998.
*/
class Quat {
private:
@@ -63,31 +65,100 @@ public:
float x, y, z, w;
/**
Initializes to a zero degree rotation.
Initializes to a zero degree rotation, (0,0,0,1)
*/
inline Quat() : x(0), y(0), z(0), w(1) {}
Quat() : x(0), y(0), z(0), w(1) {}
Quat(
const Matrix3& rot);
/** Expects "Quat(x,y,z,w)" or a Matrix3 constructor. */
Quat(const class Any& a);
inline Quat(float _x, float _y, float _z, float _w) :
Quat(const Matrix3& rot);
Quat(float _x, float _y, float _z, float _w) :
x(_x), y(_y), z(_z), w(_w) {}
/** Defaults to a pure vector quaternion */
inline Quat(const Vector3& v, float _w = 0) : x(v.x), y(v.y), z(v.z), w(_w) {
Quat(const Vector3& v, float _w = 0) : x(v.x), y(v.y), z(v.z), w(_w) {
}
/**
The real part of the quaternion.
*/
inline const float& real() const {
const float& real() const {
return w;
}
inline float& real() {
float& real() {
return w;
}
Quat operator-() const {
return Quat(-x, -y, -z, -w);
}
Quat operator-(const Quat& other) const {
return Quat(x - other.x, y - other.y, z - other.z, w - other.w);
}
Quat& operator-=(const Quat& q) {
x -= q.x;
y -= q.y;
z -= q.z;
w -= q.w;
return *this;
}
Quat operator+(const Quat& q) const {
return Quat(x + q.x, y + q.y, z + q.z, w + q.w);
}
Quat& operator+=(const Quat& q) {
x += q.x;
y += q.y;
z += q.z;
w += q.w;
return *this;
}
/**
Negates the imaginary part.
*/
Quat conj() const {
return Quat(-x, -y, -z, w);
}
float sum() const {
return x + y + z + w;
}
float average() const {
return sum() / 4.0f;
}
Quat operator*(float s) const {
return Quat(x * s, y * s, z * s, w * s);
}
Quat& operator*=(float s) {
x *= s;
y *= s;
z *= s;
w *= s;
return *this;
}
/** @cite Based on Watt & Watt, page 360 */
friend Quat operator* (float s, const Quat& q);
inline Quat operator/(float s) const {
return Quat(x / s, y / s, z / s, w / s);
}
float dot(const Quat& other) const {
return (x * other.x) + (y * other.y) + (z * other.z) + (w * other.w);
}
/** Note: two quats can represent the Quat::sameRotation and not be equal. */
bool fuzzyEq(const Quat& q) {
return G3D::fuzzyEq(x, q.x) && G3D::fuzzyEq(y, q.y) && G3D::fuzzyEq(z, q.z) && G3D::fuzzyEq(w, q.w);
@@ -100,18 +171,14 @@ public:
return fuzzyEq(q) || fuzzyEq(-q);
}
inline Quat operator-() const {
return Quat(-x, -y, -z, -w);
}
/**
Returns the imaginary part (x, y, z)
*/
inline const Vector3& imag() const {
const Vector3& imag() const {
return *(reinterpret_cast<const Vector3*>(this));
}
inline Vector3& imag() {
Vector3& imag() {
return *(reinterpret_cast<Vector3*>(this));
}
@@ -158,43 +225,7 @@ public:
/** Normalized linear interpolation of quaternion components. */
Quat nlerp(const Quat& other, float alpha) const;
/**
Negates the imaginary part.
*/
inline Quat conj() const {
return Quat(-x, -y, -z, w);
}
inline float sum() const {
return x + y + z + w;
}
inline float average() const {
return sum() / 4.0f;
}
inline Quat operator*(float s) const {
return Quat(x * s, y * s, z * s, w * s);
}
inline Quat& operator*=(float s) {
x *= s;
y *= s;
z *= s;
w *= s;
return *this;
}
/** @cite Based on Watt & Watt, page 360 */
friend Quat operator* (float s, const Quat& q);
inline Quat operator/(float s) const {
return Quat(x / s, y / s, z / s, w / s);
}
inline float dot(const Quat& other) const {
return (x * other.x) + (y * other.y) + (z * other.z) + (w * other.w);
}
/** Note that q<SUP>-1</SUP> = q.conj() for a unit quaternion.
@cite Dam99 page 13 */
@@ -202,10 +233,6 @@ public:
return conj() / dot(*this);
}
Quat operator-(const Quat& other) const;
Quat operator+(const Quat& other) const;
/**
Quaternion multiplication (composition of rotations).
Note that this does not commute.
@@ -217,18 +244,16 @@ public:
return (*this) * other.inverse();
}
/** Is the magnitude nearly 1.0? */
inline bool isUnit(float tolerance = 1e-5) const {
bool isUnit(float tolerance = 1e-5) const {
return abs(dot(*this) - 1.0f) < tolerance;
}
inline float magnitude() const {
float magnitude() const {
return sqrtf(dot(*this));
}
inline Quat log() const {
Quat log() const {
if ((x == 0) && (y == 0) && (z == 0)) {
if (w > 0) {
return Quat(0, 0, 0, ::logf(w));
@@ -289,18 +314,16 @@ public:
return (log() * x).exp();
}
inline void unitize() {
float mag2 = dot(*this);
if (! G3D::fuzzyEq(mag2, 1.0f)) {
*this *= rsq(mag2);
}
/** Make unit length in place */
void unitize() {
*this *= rsq(dot(*this));
}
/**
Returns a unit quaterion obtained by dividing through by
the magnitude.
*/
inline Quat toUnit() const {
Quat toUnit() const {
Quat x = *this;
x.unitize();
return x;
@@ -312,7 +335,7 @@ public:
n(q) value used in Eberly's 1999 paper, which is the square of the
norm.
*/
inline float norm() const {
float norm() const {
return magnitude();
}
@@ -706,13 +729,6 @@ inline const float& Quat::operator[] (int i) const {
return ((float*)this)[i];
}
inline Quat Quat::operator-(const Quat& other) const {
return Quat(x - other.x, y - other.y, z - other.z, w - other.w);
}
inline Quat Quat::operator+(const Quat& other) const {
return Quat(x + other.x, y + other.y, z + other.z, w + other.w);
}
} // Namespace G3D
@@ -36,7 +36,7 @@ private:
// The following are for the "ray slope" optimization from
// "Fast Ray / Axis-Aligned Bounding Box Overlap Tests using Ray Slopes"
// by Martin Eisemann, Thorsten Grosch, Stefan Müller and Marcus Magnor
// by Martin Eisemann, Thorsten Grosch, Stefan Müller and Marcus Magnor
// Computer Graphics Lab, TU Braunschweig, Germany and
// University of Koblenz-Landau, Germany*/
enum Classification {MMM, MMP, MPM, MPP, PMM, PMP, PPM, PPP, POO, MOO, OPO, OMO, OOP, OOM, OMM, OMP, OPM, OPP, MOM, MOP, POM, POP, MMO, MPO, PMO, PPO}; Classification classification;
@@ -57,9 +57,12 @@ public:
/**
Inserts into the table if not already present.
Returns true if this is the first time the element was added.
*/
void insert(const T& member) {
memberTable.set(member, true);
bool insert(const T& member) {
bool isNew = false;
memberTable.getCreate(member, isNew) = true;
return isNew;
}
/**
@@ -2,9 +2,9 @@
@file SmallArray.h
@created 2009-04-26
@edited 2009-04-26
@edited 2010-02-26
Copyright 2000-2009, Morgan McGuire, http://graphics.cs.williams.edu
Copyright 2000-2010, Morgan McGuire, http://graphics.cs.williams.edu
All rights reserved.
*/
#ifndef G3D_SmallArray_h
@@ -12,6 +12,7 @@
#include "G3D/platform.h"
#include "G3D/Array.h"
#include "G3D/MemoryManager.h"
namespace G3D {
@@ -46,6 +47,11 @@ public:
resize(0, shrinkIfNecessary);
}
void clearAndSetMemoryManager(MemoryManager::Ref& m) {
clear();
m_rest.clearAndSetMemoryManager(m);
}
inline T& operator[](int i) {
debugAssert(i < m_size && i >= 0);
if (i < N) {
@@ -77,7 +83,7 @@ public:
push(v);
}
void fastRemove(int i) {
void fastRemove(int i, bool shrinkIfNecessary = false) {
debugAssert(i < m_size && i >= 0);
if (i < N) {
if (m_size <= N) {
@@ -89,7 +95,7 @@ public:
}
} else {
// Removing from the rest array
m_rest.fastRemove(i - N);
m_rest.fastRemove(i - N, shrinkIfNecessary);
}
--m_size;
}
@@ -100,7 +100,7 @@ public:
See Real Time Rendering, 2nd edition, ch 12 for a general discussion
of splines and their properties.
@sa G3D::UprightSpline, G3D::QuatSpline
\sa G3D::UprightSpline
*/
template<typename Control>
class Spline : public SplineBase {
@@ -270,7 +270,7 @@ protected:
}
/**
Mutates the array of N control points. It is useful to override this
Mutates the array of N control points that begins at \a A. It is useful to override this
method by one that wraps the values if they are angles or quaternions
for which "shortest path" interpolation is significant.
*/
@@ -333,10 +333,6 @@ public:
const Control& p2 = p[2];
const Control& p3 = p[3];
const Control& dp0 = p1 + (p0*-1.0f);
const Control& dp1 = p2 + (p1*-1.0f);
const Control& dp2 = p3 + (p2*-1.0f);
// The factor of 1/2 from averaging two time intervals is
// already factored into the basis
@@ -346,6 +342,11 @@ public:
float n0 = x / dt0;
float n1 = x / dt1;
float n2 = x / dt2;
const Control& dp0 = p1 + (p0*-1.0f);
const Control& dp1 = p2 + (p1*-1.0f);
const Control& dp2 = p3 + (p2*-1.0f);
const Control& dp1n1 = dp1 * n1;
const Control& tan1 = dp0 * n0 + dp1n1;
const Control& tan2 = dp1n1 + dp2 * n2;
@@ -846,7 +846,7 @@ public:
return true;
}
node = node->next;
} while (node != NULL);
}
return false;
}
@@ -8,9 +8,9 @@
@cite Based on a lexer written by Aaron Orenstein.
@created 2002-11-27
@edited 2009-11-24
@edited 2010-07-03
Copyright 2000-2009, Morgan McGuire.
Copyright 2000-2010, Morgan McGuire.
All rights reserved.
*/
@@ -76,6 +76,7 @@ private:
bool _bool;
int _line;
int _character;
uint64 _bytePosition;
Type _type;
ExtendedType _extendedType;
@@ -86,14 +87,15 @@ public:
_bool(false),
_line(0),
_character(0),
_bytePosition(0),
_type(END),
_extendedType(END_TYPE) {}
Token(Type t, ExtendedType e, const std::string& s, int L, int c)
: _string(s), _bool(false), _line(L), _character(c), _type(t), _extendedType(e) {}
Token(Type t, ExtendedType e, const std::string& s, int L, int c, uint64 byte)
: _string(s), _bool(false), _line(L), _character(c), _bytePosition(byte), _type(t), _extendedType(e) {}
Token(Type t, ExtendedType e, const std::string& s, bool b, int L, int c)
: _string(s), _bool(b), _line(L), _character(c), _type(t), _extendedType(e) {}
Token(Type t, ExtendedType e, const std::string& s, bool b, int L, int c, uint64 byte)
: _string(s), _bool(b), _line(L), _character(c), _bytePosition(byte), _type(t), _extendedType(e) {}
Type type() const {
return _type;
@@ -132,6 +134,12 @@ public:
return _character;
}
/** Number of bytes from the beginning of the buffer that this token was parsed from.
Begins at 0 */
uint64 bytePosition() const {
return _bytePosition;
}
/** Return the numeric value for a number type, or zero if this is
not a number type.
*/
@@ -212,6 +220,12 @@ public:
*/
class TextInput {
public:
/** Includes MSVC specials parsing */
static double parseNumber(const std::string& _string);
/** toLower(_string) == "true" */
static bool parseBoolean(const std::string& _string);
/** Tokenizer configuration options. */
class Settings {
@@ -316,12 +330,13 @@ public:
/**
Parse -1.#IND00 as the floating point number returned by
nan(), -1.#INF00 as -inf(), and 1.#INF00 as inf(). Note
that the C99 standard specifies that a variety of formats
like "NaN" and "nan" are to be used; these are easier to
parse yourself and not currently supported by readNumber.
nan(), -1.#INF00 as -G3D::inf(), and 1.#INF00 as G3D::inf().
An alternative to specifying msvcSpecials is to read numbers as:
Note that the C99 standard specifies that a variety of formats
like "nan" are to be used; these are supported by
G3D::TextInput::Settings::simpleFloatSpecials.
An alternative to specifying msvcFloatSpecials is to read numbers as:
<pre>
Token x = t.read();
Token y = t.peek();
@@ -339,10 +354,14 @@ public:
special format overrides the comment and will be parsed
instead.
If signedNumbers is false msvcSpecials will not be parsed.
If signedNumbers is false msvcFloatSpecials will not be parsed.
Default is true. */
bool msvcSpecials;
bool msvcFloatSpecials;
/** Parses "+inf', "-inf", "inf", "nan" as floats instead of symbols.
Defaults to true.*/
bool simpleFloatSpecials;
/**
Parse the following set of useful proof symbols:
@@ -362,7 +381,7 @@ public:
bool proofSymbols;
/**
When parsing booleans and msvcSpecials, is case significant?
When parsing booleans and msvcFloatSpecials, is case significant?
Default is {true}
*/
bool caseSensitive;
@@ -623,9 +642,17 @@ public:
is not a string. WrongString will be thrown if the next token in the
input stream is a string but does not match the @p s parameter. When
an exception is thrown, no tokens are consumed.
\sa readString(), readStringToken(), readUntilNewlineAsString()
*/
void readString(const std::string& s);
/** Read from the beginning of the next token until the following newline
and return the result as a string, ignoring all parsing in between. The newline
is not returned in the string, and the following token read will be a newline or
end of file token (if they are enabled for parsing).*/
std::string readUntilNewlineAsString();
/** Reads a comment token or throws WrongTokenType, and returns the token.
Use this method (rather than readComment) if you want the token's
@@ -733,13 +760,13 @@ public:
/** Read a series of two specific symbols. See readSymbol. */
inline void readSymbols(const std::string& s1, const std::string& s2) {
void readSymbols(const std::string& s1, const std::string& s2) {
readSymbol(s1);
readSymbol(s2);
}
/** Read a series of three specific symbols. See readSymbol. */
inline void readSymbols(
void readSymbols(
const std::string& s1,
const std::string& s2,
const std::string& s3) {
@@ -749,7 +776,7 @@ public:
}
/** Read a series of four specific symbols. See readSymbol. */
inline void readSymbols(
void readSymbols(
const std::string& s1,
const std::string& s2,
const std::string& s3,
@@ -209,9 +209,9 @@ public:
*/
inline Vector3 directionOrZero() const {
float mag = magnitude();
if (G3D::fuzzyEq(mag, 0.0f)) {
if (mag < 0.0000001f) {
return Vector3::zero();
} else if (G3D::fuzzyEq(mag, 1.0f)) {
} else if (mag < 1.00001f && mag > 0.99999f) {
return *this;
} else {
return *this * (1.0f / mag);
@@ -80,7 +80,7 @@ public:
inline Vector3int16& operator+=(const Vector3int16& other) {
x += other.x;
y += other.y;
z += other.y;
z += other.z;
return *this;
}

Some files were not shown because too many files have changed in this diff Show More