Merge branch 'development' into gtest-tests

This commit is contained in:
Daniel Buckmaster 2014-07-13 20:07:03 +02:00
commit 7555f1d2cc
30 changed files with 330 additions and 64 deletions

View file

@ -1168,9 +1168,7 @@ void Precipitation::destroySplash(Raindrop *drop)
PROFILE_START(PrecipDestroySplash);
if (drop == mSplashHead)
{
mSplashHead = NULL;
PROFILE_END();
return;
mSplashHead = mSplashHead->nextSplashDrop;
}
if (drop->nextSplashDrop)

View file

@ -2955,7 +2955,7 @@ void Player::updateMove(const Move* move)
// Clamp acceleration.
F32 maxAcc = (mDataBlock->swimForce / getMass()) * TickSec;
if ( false && swimSpeed > maxAcc )
if ( swimSpeed > maxAcc )
swimAcc *= maxAcc / swimSpeed;
acc += swimAcc;

View file

@ -1141,11 +1141,11 @@ void RigidShape::updatePos(F32 dt)
void RigidShape::updateForces(F32 /*dt*/)
{
if (mDisableMove) return;
Point3F gravForce(0, 0, sRigidShapeGravity * mRigid.mass * mGravityMod);
MatrixF currTransform;
mRigid.getTransform(&currTransform);
mRigid.atRest = false;
Point3F torque(0, 0, 0);
Point3F force(0, 0, 0);

View file

@ -532,3 +532,32 @@ const char* dStristr( const char* str1, const char* str2 )
{
return dStristr( const_cast< char* >( str1 ), str2 );
}
int dStrrev(char* str)
{
int l=dStrlen(str)-1; //get the string length
for(int x=0;x < l;x++,l--)
{
str[x]^=str[l]; //triple XOR Trick
str[l]^=str[x]; //for not using a temp
str[x]^=str[l];
}
return l;
}
int dItoa(int n, char s[])
{
int i, sign;
if ((sign = n) < 0) /* record sign */
n = -n; /* make n positive */
i = 0;
do { /* generate digits in reverse order */
s[i++] = n % 10 + '0'; /* get next digit */
} while ((n /= 10) > 0); /* delete it */
if (sign < 0)
s[i++] = '-';
s[i] = '\0';
dStrrev(s);
return dStrlen(s);
}

View file

@ -217,6 +217,9 @@ bool dStrEndsWith(const char* str1, const char* str2);
char* dStripPath(const char* filename);
int dStrrev(char* str);
int dItoa(int n, char s[]);
//------------------------------------------------------------------------------
// standard I/O functions [defined in platformString.cpp]

View file

@ -558,7 +558,12 @@ void GFXDrawUtil::draw2DSquare( const Point2F &screenPoint, F32 width, F32 spinA
verts[0].color = verts[1].color = verts[2].color = verts[3].color = mBitmapModulation;
if(spinAngle != 0.f)
if (spinAngle == 0.0f)
{
for( S32 i = 0; i < 4; i++ )
verts[i].point += offset;
}
else
{
MatrixF rotMatrix( EulerF( 0.0, 0.0, spinAngle ) );

View file

@ -58,7 +58,7 @@ public:
void drawRectFill( const Point2I &upperLeft, const Point2I &lowerRight, const ColorI &color );
void drawRectFill( const RectI &rect, const ColorI &color );
void draw2DSquare( const Point2F &screenPoint, F32 width, F32 spinAngle );
void draw2DSquare( const Point2F &screenPoint, F32 width, F32 spinAngle = 0.0f );
//-----------------------------------------------------------------------------
// Draw Lines

View file

@ -736,7 +736,7 @@ bool GuiGameListMenuProfile::onAdd()
// We can't call enforceConstraints() here because incRefCount initializes
// some of the things to enforce. Do a basic sanity check here instead.
if( !dStrlen(mBitmapName) )
if( !mBitmapName || !dStrlen(mBitmapName) )
{
Con::errorf( "GuiGameListMenuProfile: %s can't be created without a bitmap. Please add a 'Bitmap' property to the object definition.", getName() );
return false;

View file

@ -764,8 +764,7 @@ GuiControl* GuiInspectorTypeShapeFilename::constructEditControl()
// Change filespec
char szBuffer[512];
dSprintf( szBuffer, sizeof(szBuffer), "getLoadFilename(\"%s\", \"%d.apply\", %d.getData());",
"DTS Files (*.dts)|*.dts|COLLADA Files (*.dae)|*.dae|(All Files (*.*)|*.*|", getId(), getId() );
dSprintf( szBuffer, sizeof(szBuffer), "getLoadFormatFilename(\"%d.apply\", %d.getData());", getId(), getId() );
mBrowseButton->setField( "Command", szBuffer );
// Create "Open in ShapeEditor" button

View file

@ -32,29 +32,49 @@ extern "C"
int (*torque_winmain)( HINSTANCE hInstance, HINSTANCE h, LPSTR lpszCmdLine, int nShow) = NULL;
};
bool getDllName(std::wstring& dllName)
bool getDllName(std::wstring& dllName, const std::wstring suffix)
{
wchar_t filenameBuf[MAX_PATH];
DWORD length = GetModuleFileNameW( NULL, filenameBuf, MAX_PATH );
if(length == 0) return false;
dllName = std::wstring(filenameBuf);
size_t dotPos = dllName.find_last_of(L".");
if(dotPos == std::wstring::npos) return false;
if(dotPos == std::wstring::npos)
{
dllName.clear();
return false;
}
dllName.erase(dotPos);
dllName += L".dll";
dllName += suffix + L".dll";
return true;
}
int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCommandShow)
{
// Try to find the game DLL, which may have one of several file names.
HMODULE hGame = NULL;
std::wstring dllName = std::wstring();
if(!getDllName(dllName))
// The file name is the same as this executable's name, plus a suffix.
const std::wstring dllSuffices[] = {L"", L" DLL"};
const unsigned int numSuffices = sizeof(dllSuffices) / sizeof(std::wstring);
for (unsigned int i = 0; i < numSuffices; i++)
{
// Attempt to glue the suffix onto the current filename.
if(!getDllName(dllName, dllSuffices[i]))
continue;
// Load the DLL at that address.
hGame = LoadLibraryW(dllName.c_str());
if (hGame)
break;
}
if(!dllName.length())
{
MessageBoxW(NULL, L"Unable to find game dll", L"Error", MB_OK|MB_ICONWARNING);
return -1;
}
HMODULE hGame = LoadLibraryW(dllName.c_str());
if (!hGame)
{
wchar_t error[4096];

View file

@ -35,27 +35,27 @@ QuatF& QuatF::set( const EulerF & e )
F32 cx, sx;
F32 cy, sy;
F32 cz, sz;
mSinCos( -e.x * 0.5f, sx, cx );
mSinCos( -e.y * 0.5f, sy, cy );
mSinCos( -e.z * 0.5f, sz, cz );
mSinCos( e.x * 0.5f, sx, cx );
mSinCos( e.y * 0.5f, sy, cy );
mSinCos( e.z * 0.5f, sz, cz );
// Qyaw(z) = [ (0, 0, sin z/2), cos z/2 ]
// Qyaw(z) = [ (0, 0, sin z/2), cos z/2 ]
// Qpitch(x) = [ (sin x/2, 0, 0), cos x/2 ]
// Qroll(y) = [ (0, sin y/2, 0), cos y/2 ]
// this = Qresult = Qyaw*Qpitch*Qroll ZXY
// Qroll(y) = [ (0, sin y/2, 0), cos y/2 ]
// this = Qresult = Qyaw*Qpitch*Qroll ZXY
//
// The code that folows is a simplification of:
// roll*=pitch;
// roll*=yaw;
// *this = roll;
// roll*=pitch;
// roll*=yaw;
// *this = roll;
F32 cycz, sysz, sycz, cysz;
cycz = cy*cz;
sysz = sy*sz;
sycz = sy*cz;
cysz = cy*sz;
w = cycz*cx + sysz*sx;
w = cycz*cx - sysz*sx;
x = cycz*sx + sysz*cx;
y = sycz*cx - cysz*sx;
y = sycz*cx + cysz*sx;
z = cysz*cx - sycz*sx;
return *this;

View file

@ -0,0 +1,63 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2014 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifdef TORQUE_TESTS_ENABLED
#include "testing/unitTesting.h"
#include "math/mQuat.h"
#include "math/mAngAxis.h"
#include "math/mMatrix.h"
/// For testing things that should be close to 0, but accounting for floating-
/// point inaccuracy.
static const F32 epsilon = 1e-3f;
/// Test quaternions for equality by expecting the angle between them to be
/// close to 0.
#define EXPECT_QUAT_EQ(q1, q2) EXPECT_LT(q1.angleBetween(q2), epsilon)
TEST(QuatF, AngleBetween)
{
QuatF p(QuatF::Identity), q(QuatF::Identity);
EXPECT_LT(p.angleBetween(q), epsilon)
<< "Angle between identity quaternions should be ~0.";
p.set(EulerF(0.1, 0.15, -0.2));
q = p;
EXPECT_LT(p.angleBetween(q), epsilon)
<< "Angle between identical quaternions should be ~0.";
}
/// Test conversion from EulerF.
TEST(QuatF, Construction)
{
EulerF eId(0, 0, 0);
EXPECT_QUAT_EQ(QuatF(eId), QuatF::Identity)
<< "Quaternions constructed from identity EulerF and QuatF::Identity not equal.";
EulerF eRot(0.0f, -0.0f, 1.5707963267948966f);
MatrixF mat(eRot);
AngAxisF aaRot(mat);
EXPECT_QUAT_EQ(QuatF(eRot), QuatF(aaRot))
<< "Quaternions constructed from EulerF and AngAxisF not equal.";
}
#endif

View file

@ -50,6 +50,15 @@
#include "core/util/zip/zipVolume.h"
#include "gfx/bitmap/gBitmap.h"
MODULE_BEGIN( ColladaShapeLoader )
MODULE_INIT_AFTER( ShapeLoader )
MODULE_INIT
{
TSShapeLoader::addFormat("Collada", "dae");
TSShapeLoader::addFormat("Google Earth", "kmz");
}
MODULE_END;
//
static DAE sDAE; // Collada model database (holds the last loaded file)
static Torque::Path sLastPath; // Path of the last loaded Collada file

View file

@ -21,6 +21,7 @@
//-----------------------------------------------------------------------------
#include "platform/platform.h"
#include "console/engineAPI.h"
#include "ts/loader/tsShapeLoader.h"
#include "core/volume.h"
@ -30,6 +31,14 @@
#include "ts/tsShapeInstance.h"
#include "ts/tsMaterialList.h"
MODULE_BEGIN( ShapeLoader )
MODULE_INIT_AFTER( GFX )
MODULE_INIT
{
TSShapeLoader::addFormat("Torque DTS", "dts");
TSShapeLoader::addFormat("Torque DSQ", "dsq");
}
MODULE_END;
const F32 TSShapeLoader::DefaultTime = -1.0f;
const F64 TSShapeLoader::MinFrameRate = 15.0f;
@ -37,6 +46,8 @@ const F64 TSShapeLoader::MaxFrameRate = 60.0f;
const F64 TSShapeLoader::AppGroundFrameRate = 10.0f;
Torque::Path TSShapeLoader::shapePath;
Vector<TSShapeLoader::ShapeFormat> TSShapeLoader::smFormats;
//------------------------------------------------------------------------------
// Utility functions
@ -1270,3 +1281,53 @@ TSShapeLoader::~TSShapeLoader()
delete appSequences[iSeq];
appSequences.clear();
}
// Static functions to handle supported formats for shape loader.
void TSShapeLoader::addFormat(String name, String extension)
{
ShapeFormat newFormat;
newFormat.mName = name;
newFormat.mExtension = extension;
smFormats.push_back(newFormat);
}
String TSShapeLoader::getFormatExtensions()
{
// "*.dsq TAB *.dae TAB
StringBuilder output;
for(U32 n = 0; n < smFormats.size(); ++n)
{
output.append("*.");
output.append(smFormats[n].mExtension);
output.append("\t");
}
return output.end();
}
String TSShapeLoader::getFormatFilters()
{
// "DSQ Files|*.dsq|COLLADA Files|*.dae|"
StringBuilder output;
for(U32 n = 0; n < smFormats.size(); ++n)
{
output.append(smFormats[n].mName);
output.append("|*.");
output.append(smFormats[n].mExtension);
output.append("|");
}
return output.end();
}
DefineConsoleFunction( getFormatExtensions, const char*, ( ),,
"Returns a list of supported shape format extensions separated by tabs."
"Example output: *.dsq TAB *.dae TAB")
{
return Con::getReturnBuffer(TSShapeLoader::getFormatExtensions());
}
DefineConsoleFunction( getFormatFilters, const char*, ( ),,
"Returns a list of supported shape formats in filter form.\n"
"Example output: DSQ Files|*.dsq|COLLADA Files|*.dae|")
{
return Con::getReturnBuffer(TSShapeLoader::getFormatFilters());
}

View file

@ -45,6 +45,19 @@
class TSShapeLoader
{
// Supported Format List
protected:
struct ShapeFormat
{
String mName;
String mExtension;
};
static Vector<ShapeFormat> smFormats;
public:
static void addFormat(String name, String extension);
static String getFormatExtensions();
static String getFormatFilters();
public:
enum eLoadPhases
{