mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-11 06:34:36 +00:00
Merge branch 'master' into console-func-refactor
Conflicts: Engine/source/app/net/net.cpp Engine/source/console/astNodes.cpp Engine/source/console/compiledEval.cpp Engine/source/console/console.h Engine/source/console/consoleInternal.h Engine/source/console/engineAPI.h
This commit is contained in:
commit
b507dc9555
6487 changed files with 315149 additions and 609761 deletions
|
|
@ -799,7 +799,7 @@ void BitRender::bitTo8Bit_3(U32 * bits, U32 * eightBits, S32 dim)
|
|||
#if defined(TORQUE_BIG_ENDIAN)
|
||||
#define MAX_SHADOW_TEXELS (256 + 4) //256 seems big enough, +4 so we can run off end of buffer.
|
||||
// slow fake gaussian
|
||||
int i, j, c;
|
||||
S32 i, j, c;
|
||||
U8 tmpLine[3][MAX_SHADOW_TEXELS];
|
||||
U8 *src0, *src1, *src2;
|
||||
U8 *s0, *s1, *s2;
|
||||
|
|
@ -809,7 +809,7 @@ void BitRender::bitTo8Bit_3(U32 * bits, U32 * eightBits, S32 dim)
|
|||
U32 currVal;
|
||||
U32 sampleVal;
|
||||
U8 c00, c01, c02, c10, c11, c12, c20, c21, c22;
|
||||
int openBuf;
|
||||
S32 openBuf;
|
||||
|
||||
src0 = tmpLine[0];
|
||||
src1 = tmpLine[1];
|
||||
|
|
@ -902,9 +902,9 @@ void BitRender::bitTo8Bit_3(U32 * bits, U32 * eightBits, S32 dim)
|
|||
sampleVal = 0; //c12; // take end.
|
||||
else // inner pixel
|
||||
{
|
||||
const int wXP = 3; // corners
|
||||
const int wPP = 4; // plus/NSEW
|
||||
const int wCP = 4; // center
|
||||
const S32 wXP = 3; // corners
|
||||
const S32 wPP = 4; // plus/NSEW
|
||||
const S32 wCP = 4; // center
|
||||
sampleVal = (c00+c02+c20+c22)*wXP + (c01+c10+c12+c21)*wPP + c11*wCP;
|
||||
sampleVal >>= 5; // div by 32 subsamples
|
||||
}
|
||||
|
|
|
|||
|
|
@ -158,6 +158,9 @@ inline BitVector::BitVector( U32 sizeInBits )
|
|||
|
||||
inline BitVector::BitVector( const BitVector &r )
|
||||
{
|
||||
mBits = NULL;
|
||||
mByteSize = 0;
|
||||
mSize = 0;
|
||||
copy(r);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,3 +38,507 @@ const ColorI ColorI::BLACK( 0, 0, 0 );
|
|||
const ColorI ColorI::RED( 255, 0, 0 );
|
||||
const ColorI ColorI::GREEN( 0, 255, 0 );
|
||||
const ColorI ColorI::BLUE( 0, 0, 255 );
|
||||
|
||||
#include "console/console.h"
|
||||
#include "console/consoleTypes.h"
|
||||
|
||||
#ifndef _STRINGUNIT_H_
|
||||
#include "core/strings/stringUnit.h"
|
||||
#endif
|
||||
|
||||
#ifndef _TDICTIONARY_H_
|
||||
#include "core/util/tDictionary.h"
|
||||
#endif
|
||||
|
||||
#include "console/consoleInternal.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
typedef HashTable<StringTableEntry, ColorF> typeNameToColorFHash;
|
||||
typedef HashTable<StringTableEntry, ColorI> typeNameToColorIHash;
|
||||
typedef HashTable<ColorF, StringTableEntry> typeColorFToNameHash;
|
||||
typedef HashTable<ColorI, StringTableEntry> typeColorIToNameHash;
|
||||
|
||||
static typeNameToColorFHash mNameToColorF;
|
||||
static typeNameToColorIHash mNameToColorI;
|
||||
static typeColorFToNameHash mColorFToName;
|
||||
static typeColorIToNameHash mColorIToName;
|
||||
|
||||
#define DEFAULT_UNKNOWN_STOCK_COLOR_NAME "White"
|
||||
|
||||
MODULE_BEGIN( StockColors )
|
||||
|
||||
MODULE_INIT_AFTER( GFX )
|
||||
|
||||
MODULE_INIT
|
||||
{
|
||||
// Create the stock colors.
|
||||
StockColor::create();
|
||||
}
|
||||
|
||||
MODULE_SHUTDOWN
|
||||
{
|
||||
// Destroy the stock colors.
|
||||
StockColor::destroy();
|
||||
}
|
||||
|
||||
MODULE_END;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
StockColorItem StockColorTable[] =
|
||||
{
|
||||
StockColorItem( "InvisibleBlack", 0, 0, 0, 0 ),
|
||||
StockColorItem( "TransparentWhite", 255, 255, 255, 0 ),
|
||||
StockColorItem( "AliceBlue", 240, 248, 255 ),
|
||||
StockColorItem( "AntiqueWhite", 250, 235, 215 ),
|
||||
StockColorItem( "Aqua", 0, 255, 255 ),
|
||||
StockColorItem( "Aquamarine", 127, 255, 212 ),
|
||||
StockColorItem( "Azure", 240, 255, 255 ),
|
||||
StockColorItem( "Beige", 245, 245, 220 ),
|
||||
StockColorItem( "Bisque", 255, 228, 196 ),
|
||||
StockColorItem( "Black", 0, 0, 0, 255 ),
|
||||
StockColorItem( "BlanchedAlmond", 255, 235, 205, 255 ),
|
||||
StockColorItem( "Blue", 0, 0, 255 ),
|
||||
StockColorItem( "BlueViolet", 138, 43, 226 ),
|
||||
StockColorItem( "Brown", 165, 42, 42, 255 ),
|
||||
StockColorItem( "BurlyWood", 222, 184, 135 ),
|
||||
StockColorItem( "CadetBlue", 95, 158, 160 ),
|
||||
StockColorItem( "Chartreuse", 127, 255, 0 ),
|
||||
StockColorItem( "Chocolate", 210, 105, 30 ),
|
||||
StockColorItem( "Coral", 255, 127, 80 ),
|
||||
StockColorItem( "CornflowerBlue", 100, 149, 237 ),
|
||||
StockColorItem( "Cornsilk", 255, 248, 220 ),
|
||||
StockColorItem( "Crimson", 220, 20, 60 ),
|
||||
StockColorItem( "Cyan", 0, 255, 255 ),
|
||||
StockColorItem( "DarkBlue", 0, 0, 139 ),
|
||||
StockColorItem( "DarkCyan", 0, 139, 139 ),
|
||||
StockColorItem( "DarkGoldenrod", 184, 134, 11 ),
|
||||
StockColorItem( "DarkGray", 169, 169, 169),
|
||||
StockColorItem( "DarkGreen", 0, 100, 0 ),
|
||||
StockColorItem( "DarkKhaki", 189, 183, 107 ),
|
||||
StockColorItem( "DarkMagenta", 139, 0, 139 ),
|
||||
StockColorItem( "DarkOliveGreen", 85, 107, 47 ),
|
||||
StockColorItem( "DarkOrange", 255, 140, 0 ),
|
||||
StockColorItem( "DarkOrchid", 153, 50, 204 ),
|
||||
StockColorItem( "DarkRed", 139, 0, 0 ),
|
||||
StockColorItem( "DarkSalmon", 233, 150, 122 ),
|
||||
StockColorItem( "DarkSeaGreen", 143, 188, 139 ),
|
||||
StockColorItem( "DarkSlateBlue", 72, 61, 139 ),
|
||||
StockColorItem( "DarkSlateGray", 47, 79, 79 ),
|
||||
StockColorItem( "DarkTurquoise", 0, 206, 209 ),
|
||||
StockColorItem( "DarkViolet", 148, 0, 211 ),
|
||||
StockColorItem( "DeepPink", 255, 20, 147 ),
|
||||
StockColorItem( "DeepSkyBlue", 0, 191, 255 ),
|
||||
StockColorItem( "DimGray", 105, 105, 105 ),
|
||||
StockColorItem( "DodgerBlue", 30, 144, 255 ),
|
||||
StockColorItem( "Firebrick", 178, 34, 34 ),
|
||||
StockColorItem( "FloralWhite", 255, 250, 240 ),
|
||||
StockColorItem( "ForestGreen", 34, 139, 34 ),
|
||||
StockColorItem( "Fuchsia", 255, 0, 255 ),
|
||||
StockColorItem( "Gainsboro", 220, 220, 220 ),
|
||||
StockColorItem( "GhostWhite", 248, 248, 255 ),
|
||||
StockColorItem( "Gold", 255, 215, 0 ),
|
||||
StockColorItem( "Goldenrod", 218, 165, 32 ),
|
||||
StockColorItem( "Gray", 128, 128, 128 ),
|
||||
StockColorItem( "Green", 0, 128, 0 ),
|
||||
StockColorItem( "GreenYellow", 173, 255, 47 ),
|
||||
StockColorItem( "Honeydew", 240, 255, 24 ),
|
||||
StockColorItem( "HotPink", 255, 105, 180 ),
|
||||
StockColorItem( "IndianRed", 205, 92, 92 ),
|
||||
StockColorItem( "Indigo", 75, 0, 130 ),
|
||||
StockColorItem( "Ivory", 255, 255, 240 ),
|
||||
StockColorItem( "Khaki", 240, 230, 140 ),
|
||||
StockColorItem( "Lavender", 230, 230, 250 ),
|
||||
StockColorItem( "LavenderBlush", 255, 240, 245 ),
|
||||
StockColorItem( "LawnGreen", 124, 252, 0 ),
|
||||
StockColorItem( "LemonChiffon", 255, 250, 205 ),
|
||||
StockColorItem( "LightBlue", 173, 216, 230 ),
|
||||
StockColorItem( "LightCoral", 240, 128, 128 ),
|
||||
StockColorItem( "LightCyan", 224, 255, 255),
|
||||
StockColorItem( "LightGoldenrodYellow", 250, 250, 210 ),
|
||||
StockColorItem( "LightGray", 211, 211, 211),
|
||||
StockColorItem( "LightGreen", 144, 238, 144 ),
|
||||
StockColorItem( "LightPink", 255, 182, 193 ),
|
||||
StockColorItem( "LightSalmon", 255, 160, 122 ),
|
||||
StockColorItem( "LightSeaGreen", 32, 178, 170 ),
|
||||
StockColorItem( "LightSkyBlue",135, 206, 250 ),
|
||||
StockColorItem( "LightSlateGray", 119, 136, 153 ),
|
||||
StockColorItem( "LightSteelBlue", 176, 196, 222 ),
|
||||
StockColorItem( "LightYellow", 255, 255, 224 ),
|
||||
StockColorItem( "Lime", 0, 255, 0 ),
|
||||
StockColorItem( "LimeGreen", 50, 205, 50 ),
|
||||
StockColorItem( "Linen", 250, 240, 230 ),
|
||||
StockColorItem( "Magenta", 255, 0, 255 ),
|
||||
StockColorItem( "Maroon", 128, 0, 0 ),
|
||||
StockColorItem( "MediumAquamarine", 102, 205, 170 ),
|
||||
StockColorItem( "MediumBlue", 0, 0, 205 ),
|
||||
StockColorItem( "MediumOrchid", 186, 85, 211 ),
|
||||
StockColorItem( "MediumPurple", 147, 112, 219 ),
|
||||
StockColorItem( "MediumSeaGreen", 60, 179, 113 ),
|
||||
StockColorItem( "MediumSlateBlue", 123, 104, 238 ),
|
||||
StockColorItem( "MediumSpringGreen", 0, 250, 154 ),
|
||||
StockColorItem( "MediumTurquoise", 72, 209, 204 ),
|
||||
StockColorItem( "MediumVioletRed", 199, 21, 133 ),
|
||||
StockColorItem( "MidnightBlue", 25, 25, 112 ),
|
||||
StockColorItem( "MintCream", 245, 255, 250 ),
|
||||
StockColorItem( "MistyRose", 255, 228, 225 ),
|
||||
StockColorItem( "Moccasin", 255, 228, 181 ),
|
||||
StockColorItem( "NavajoWhite", 255, 222, 173 ),
|
||||
StockColorItem( "Navy", 0, 0, 128 ),
|
||||
StockColorItem( "OldLace", 253, 245, 230 ),
|
||||
StockColorItem( "Olive", 128, 128, 0 ),
|
||||
StockColorItem( "OliveDrab", 107, 142, 35 ),
|
||||
StockColorItem( "Orange", 255, 165, 0 ),
|
||||
StockColorItem( "OrangeRed", 255, 69, 0 ),
|
||||
StockColorItem( "Orchid", 218, 112, 214 ),
|
||||
StockColorItem( "PaleGoldenrod", 238, 232, 170 ),
|
||||
StockColorItem( "PaleGreen", 152, 251, 152 ),
|
||||
StockColorItem( "PaleTurquoise", 175, 238, 238 ),
|
||||
StockColorItem( "PaleVioletRed", 219, 112, 147 ),
|
||||
StockColorItem( "PapayaWhip", 255, 239, 213 ),
|
||||
StockColorItem( "PeachPuff", 255, 218, 185 ),
|
||||
StockColorItem( "Peru", 205, 133, 63 ),
|
||||
StockColorItem( "Pink", 55, 192, 203 ),
|
||||
StockColorItem( "Plum", 221, 160, 221 ),
|
||||
StockColorItem( "PowderBlue", 176, 224, 230 ),
|
||||
StockColorItem( "Purple", 128, 0, 128 ),
|
||||
StockColorItem( "Red", 255, 0, 0 ),
|
||||
StockColorItem( "RosyBrown", 188, 143, 143 ),
|
||||
StockColorItem( "RoyalBlue", 65, 105, 225 ),
|
||||
StockColorItem( "SaddleBrown", 139, 69, 19 ),
|
||||
StockColorItem( "Salmon", 250, 128, 114 ),
|
||||
StockColorItem( "SandyBrown", 244, 164, 96 ),
|
||||
StockColorItem( "SeaGreen", 46, 139, 87 ),
|
||||
StockColorItem( "SeaShell", 255, 245, 238 ),
|
||||
StockColorItem( "Sienna", 160, 82, 45 ),
|
||||
StockColorItem( "Silver", 192, 192, 192 ),
|
||||
StockColorItem( "SkyBlue", 135, 206, 235 ),
|
||||
StockColorItem( "SlateBlue", 106, 90, 205 ),
|
||||
StockColorItem( "SlateGray", 112, 128, 144 ),
|
||||
StockColorItem( "Snow", 255, 250, 250 ),
|
||||
StockColorItem( "SpringGreen", 0, 255, 127 ),
|
||||
StockColorItem( "SteelBlue", 70, 130, 180 ),
|
||||
StockColorItem( "Tan", 210, 180, 140 ),
|
||||
StockColorItem( "Teal", 0, 128, 128 ),
|
||||
StockColorItem( "Thistle", 216, 191, 216 ),
|
||||
StockColorItem( "Tomato", 255, 99, 71 ),
|
||||
StockColorItem( "Turquoise", 64, 224, 208 ),
|
||||
StockColorItem( "Violet", 238, 130, 238 ),
|
||||
StockColorItem( "Wheat", 245, 222, 179 ),
|
||||
StockColorItem( "White", 255, 255, 255 ),
|
||||
StockColorItem( "WhiteSmoke", 245, 245, 245 ),
|
||||
StockColorItem( "Yellow", 255, 255, 0 ),
|
||||
StockColorItem( "YellowGreen", 154, 205, 50 )
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static bool stockColorsCreated = false;
|
||||
|
||||
void StockColor::create( void )
|
||||
{
|
||||
// Finish if already created.
|
||||
if ( stockColorsCreated )
|
||||
return;
|
||||
|
||||
// Fetch stock color count.
|
||||
const S32 stockColorCount = sizeof(StockColorTable) / sizeof(StockColorItem);
|
||||
|
||||
// Insert all stock colors.
|
||||
for( S32 index = 0; index < stockColorCount; ++index )
|
||||
{
|
||||
// Fetch stock color item.
|
||||
StockColorItem& stockColor = StockColorTable[index];
|
||||
|
||||
// Fetch stock color item.
|
||||
StringTableEntry colorName = StringTable->insert( stockColor.mColorName );
|
||||
|
||||
// Insert stock color mappings.
|
||||
mNameToColorF.insertUnique(colorName, stockColor.mColorF);
|
||||
mNameToColorI.insertUnique(colorName, stockColor.mColorI);
|
||||
mColorFToName.insertUnique(stockColor.mColorF, colorName);
|
||||
mColorIToName.insertUnique(stockColor.mColorI, colorName);
|
||||
}
|
||||
|
||||
// Flag as created.
|
||||
stockColorsCreated = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void StockColor::destroy( void )
|
||||
{
|
||||
// Finish if not created.
|
||||
if ( !stockColorsCreated )
|
||||
return;
|
||||
|
||||
// Clear stock color mappings.
|
||||
mNameToColorF.clear();
|
||||
mNameToColorI.clear();
|
||||
mColorFToName.clear();
|
||||
mColorIToName.clear();
|
||||
|
||||
// Flag as not created.
|
||||
stockColorsCreated = false;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool StockColor::isColor( const char* pStockColorName )
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal( pStockColorName != NULL, "Cannot fetch a NULL stock color name." );
|
||||
|
||||
// Fetch color name.
|
||||
StringTableEntry colorName = StringTable->insert( pStockColorName );
|
||||
|
||||
// Find if color name exists or not.
|
||||
return mNameToColorF.find( colorName ) != mNameToColorF.end();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
const ColorF& StockColor::colorF( const char* pStockColorName )
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal( pStockColorName != NULL, "Cannot fetch a NULL stock color name." );
|
||||
|
||||
// Fetch color name.
|
||||
StringTableEntry colorName = StringTable->insert( pStockColorName );
|
||||
|
||||
// Find stock color.
|
||||
typeNameToColorFHash::Iterator colorItr = mNameToColorF.find( colorName );
|
||||
|
||||
// Return color if found.
|
||||
if ( colorItr != mNameToColorF.end() )
|
||||
return colorItr->value;
|
||||
|
||||
// Warn.
|
||||
Con::warnf( "Could not find stock color name '%s'.", pStockColorName );
|
||||
|
||||
// Return default stock color.
|
||||
return mNameToColorF.find( DEFAULT_UNKNOWN_STOCK_COLOR_NAME )->value;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
const ColorI& StockColor::colorI( const char* pStockColorName )
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal( pStockColorName != NULL, "Cannot fetch a NULL stock color name." );
|
||||
|
||||
// Fetch color name.
|
||||
StringTableEntry colorName = StringTable->insert( pStockColorName );
|
||||
|
||||
// Find stock color.
|
||||
typeNameToColorIHash::Iterator colorItr = mNameToColorI.find( colorName );
|
||||
|
||||
// Return color if found.
|
||||
if ( colorItr != mNameToColorI.end() )
|
||||
return colorItr->value;
|
||||
|
||||
// Warn.
|
||||
Con::warnf( "Could not find stock color name '%s'.", colorName );
|
||||
|
||||
// Return default stock color.
|
||||
return mNameToColorI.find( DEFAULT_UNKNOWN_STOCK_COLOR_NAME )->value;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
StringTableEntry StockColor::name( const ColorF& color )
|
||||
{
|
||||
// Find stock color name.
|
||||
typeColorFToNameHash::Iterator colorNameItr = mColorFToName.find( color );
|
||||
|
||||
// Return name if found.
|
||||
if ( colorNameItr != mColorFToName.end() )
|
||||
return colorNameItr->value;
|
||||
|
||||
// Return empty string.
|
||||
return StringTable->EmptyString();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
StringTableEntry StockColor::name( const ColorI& color )
|
||||
{
|
||||
// Find stock color name.
|
||||
typeColorIToNameHash::Iterator colorNameItr = mColorIToName.find( color );
|
||||
|
||||
// Return name if found.
|
||||
if ( colorNameItr != mColorIToName.end() )
|
||||
return colorNameItr->value;
|
||||
|
||||
// Return empty string.
|
||||
return StringTable->EmptyString();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
S32 StockColor::getCount( void )
|
||||
{
|
||||
return sizeof(StockColorTable) / sizeof(StockColorItem);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
const StockColorItem* StockColor::getColorItem( const S32 index )
|
||||
{
|
||||
// Fetch stock color count.
|
||||
const S32 stockColorCount = StockColor::getCount();
|
||||
|
||||
// Is the stock color index in range?
|
||||
if ( index < 0 || index >= stockColorCount )
|
||||
{
|
||||
// No, so warn.
|
||||
Con::warnf("StockColor::getName() - Specified color index '%d' is out of range. Range is 0 to %d.", index, stockColorCount-1 );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Return color name.
|
||||
return &(StockColorTable[index]);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ColorF::ColorF( const char* pStockColorName )
|
||||
{
|
||||
// Set stock color.
|
||||
*this = StockColor::colorF( pStockColorName );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void ColorF::set( const char* pStockColorName )
|
||||
{
|
||||
// Set stock color.
|
||||
*this = StockColor::colorF( pStockColorName );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
const ColorF& ColorF::StockColor( const char* pStockColorName )
|
||||
{
|
||||
return StockColor::colorF( pStockColorName );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
StringTableEntry ColorF::StockColor( void )
|
||||
{
|
||||
// Return stock color name.
|
||||
return StockColor::name( *this );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ColorI::ColorI( const char* pStockColorName )
|
||||
{
|
||||
// Set stock color.
|
||||
*this = StockColor::colorI( pStockColorName );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void ColorI::set( const char* pStockColorName )
|
||||
{
|
||||
// Set stock color.
|
||||
*this = StockColor::colorI( pStockColorName );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
const ColorI& ColorI::StockColor( const char* pStockColorName )
|
||||
{
|
||||
return StockColor::colorI( pStockColorName );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
StringTableEntry ColorI::StockColor( void )
|
||||
{
|
||||
// Return stock color name.
|
||||
return StockColor::name( *this );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ConsoleFunction( getStockColorCount, S32, 1, 1, "() - Gets a count of available stock colors.\n"
|
||||
"@return A count of available stock colors." )
|
||||
{
|
||||
return StockColor::getCount();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ConsoleFunction( getStockColorName, const char*, 2, 2, "(stockColorIndex) - Gets the stock color name at the specified index.\n"
|
||||
"@param stockColorIndex The zero-based index of the stock color name to retrieve.\n"
|
||||
"@return The stock color name at the specified index or nothing if the string is invalid." )
|
||||
{
|
||||
// Fetch stock color index.
|
||||
const S32 stockColorIndex = dAtoi(argv[1]);
|
||||
|
||||
// Fetch the color item.
|
||||
const StockColorItem* pColorItem = StockColor::getColorItem( stockColorIndex );
|
||||
|
||||
return pColorItem == NULL ? NULL : pColorItem->getColorName();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ConsoleFunction( isStockColor, bool, 2, 2, "(stockColorName) - Gets whether the specified name is a stock color or not.\n"
|
||||
"@param stockColorName - The stock color name to test for.\n"
|
||||
"@return Whether the specified name is a stock color or not.\n" )
|
||||
{
|
||||
// Fetch stock color name.
|
||||
const char* pStockColorName = argv[1];
|
||||
|
||||
// Return whether this is a stock color name or not.
|
||||
return StockColor::isColor( pStockColorName );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ConsoleFunction( getStockColorF, const char*, 2, 2, "(stockColorName) - Gets a floating-point-based stock color by name.\n"
|
||||
"@param stockColorName - The stock color name to retrieve.\n"
|
||||
"@return The stock color that matches the specified color name. Returns nothing if the color name is not found.\n" )
|
||||
{
|
||||
// Fetch stock color name.
|
||||
const char* pStockColorName = argv[1];
|
||||
|
||||
// Return nothing if stock color name is invalid.
|
||||
if ( !StockColor::isColor( pStockColorName ) )
|
||||
return StringTable->EmptyString();
|
||||
|
||||
// Fetch stock color.
|
||||
const ColorF& color = StockColor::colorF( pStockColorName );
|
||||
|
||||
// Format stock color.
|
||||
char* returnBuffer = Con::getReturnBuffer(256);
|
||||
dSprintf(returnBuffer, 256, "%g %g %g %g", color.red, color.green, color.blue, color.alpha);
|
||||
return(returnBuffer);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ConsoleFunction( getStockColorI, const char*, 2, 2, "(stockColorName) - Gets a byte-based stock color by name.\n"
|
||||
"@param stockColorName - The stock color name to retrieve.\n"
|
||||
"@return The stock color that matches the specified color name. Returns nothing if the color name is not found.\n" )
|
||||
{
|
||||
// Fetch stock color name.
|
||||
const char* pStockColorName = argv[1];
|
||||
|
||||
// Return nothing if stock color name is invalid.
|
||||
if ( !StockColor::isColor( pStockColorName ) )
|
||||
return StringTable->EmptyString();
|
||||
|
||||
// Fetch stock color.
|
||||
const ColorI& color = StockColor::colorI( pStockColorName );
|
||||
|
||||
// Format stock color.
|
||||
char* returnBuffer = Con::getReturnBuffer(256);
|
||||
dSprintf(returnBuffer, 256, "%d %d %d %d", color.red, color.green, color.blue, color.alpha);
|
||||
return(returnBuffer);
|
||||
}
|
||||
|
|
@ -49,11 +49,18 @@ class ColorF
|
|||
const F32 in_b,
|
||||
const F32 in_a = 1.0f);
|
||||
|
||||
ColorF( const char* pStockColorName );
|
||||
|
||||
void set(const F32 in_r,
|
||||
const F32 in_g,
|
||||
const F32 in_b,
|
||||
const F32 in_a = 1.0f);
|
||||
|
||||
void set( const char* pStockColorName );
|
||||
|
||||
static const ColorF& StockColor( const char* pStockColorName );
|
||||
StringTableEntry StockColor( void );
|
||||
|
||||
ColorF& operator*=(const ColorF& in_mul); // Can be useful for lighting
|
||||
ColorF operator*(const ColorF& in_mul) const;
|
||||
ColorF& operator+=(const ColorF& in_rAdd);
|
||||
|
|
@ -123,6 +130,8 @@ class ColorI
|
|||
const U8 in_a = U8(255));
|
||||
ColorI(const ColorI& in_rCopy, const U8 in_a);
|
||||
|
||||
ColorI( const char* pStockColorName );
|
||||
|
||||
void set(const U8 in_r,
|
||||
const U8 in_g,
|
||||
const U8 in_b,
|
||||
|
|
@ -131,6 +140,11 @@ class ColorI
|
|||
void set(const ColorI& in_rCopy,
|
||||
const U8 in_a);
|
||||
|
||||
void set( const char* pStockColorName );
|
||||
|
||||
static const ColorI& StockColor( const char* pStockColorName );
|
||||
StringTableEntry StockColor( void );
|
||||
|
||||
ColorI& operator*=(const F32 in_mul);
|
||||
ColorI operator*(const F32 in_mul) const;
|
||||
|
||||
|
|
@ -175,6 +189,53 @@ class ColorI
|
|||
static const ColorI BLUE;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class StockColorItem
|
||||
{
|
||||
private:
|
||||
StockColorItem() {}
|
||||
|
||||
public:
|
||||
StockColorItem( const char* pName, const U8 red, const U8 green, const U8 blue, const U8 alpha = 255 )
|
||||
{
|
||||
// Sanity!
|
||||
AssertFatal( pName != NULL, "Stock color name cannot be NULL." );
|
||||
|
||||
// Set stock color.
|
||||
// NOTE:- We'll use the char pointer here. We can yet use the string-table unfortunately.
|
||||
mColorName = pName;
|
||||
mColorI.set( red, green, blue, alpha );
|
||||
mColorF = mColorI;
|
||||
}
|
||||
|
||||
inline const char* getColorName( void ) const { return mColorName; }
|
||||
inline const ColorF& getColorF( void ) const { return mColorF; }
|
||||
inline const ColorI& getColorI( void ) const { return mColorI; }
|
||||
|
||||
const char* mColorName;
|
||||
ColorF mColorF;
|
||||
ColorI mColorI;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class StockColor
|
||||
{
|
||||
public:
|
||||
static bool isColor( const char* pStockColorName );
|
||||
static const ColorF& colorF( const char* pStockColorName );
|
||||
static const ColorI& colorI( const char* pStockColorName );
|
||||
static StringTableEntry name( const ColorF& color );
|
||||
static StringTableEntry name( const ColorI& color );
|
||||
|
||||
static S32 getCount( void );
|
||||
static const StockColorItem* getColorItem( const S32 index );
|
||||
|
||||
static void create( void );
|
||||
static void destroy( void );
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//-------------------------------------- INLINES (ColorF)
|
||||
//
|
||||
|
|
|
|||
|
|
@ -26,9 +26,6 @@
|
|||
#ifndef _PLATFORM_H_
|
||||
#include "platform/platform.h"
|
||||
#endif
|
||||
#ifndef _EVENT_H_
|
||||
#include "platform/event.h"
|
||||
#endif
|
||||
|
||||
#include "platform/platformNet.h"
|
||||
|
||||
|
|
|
|||
|
|
@ -343,8 +343,9 @@ DefineEngineMethod( FileObject, peekLine, const char*, (),,
|
|||
|
||||
"@return String containing the line of data that was just peeked\n")
|
||||
{
|
||||
char *line = Con::getReturnBuffer( 512 );
|
||||
object->peekLine( (U8*)line, 512 );
|
||||
static const U32 bufSize = 512;
|
||||
char *line = Con::getReturnBuffer( bufSize );
|
||||
object->peekLine( (U8*)line, bufSize );
|
||||
return line;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class File
|
|||
{
|
||||
public:
|
||||
/// What is the status of our file handle?
|
||||
enum Status
|
||||
enum FileStatus
|
||||
{
|
||||
Ok = 0, ///< Ok!
|
||||
IOError, ///< Read or Write error
|
||||
|
|
@ -59,7 +59,7 @@ public:
|
|||
|
||||
private:
|
||||
void *handle; ///< Pointer to the file handle.
|
||||
Status currentStatus; ///< Current status of the file (Ok, IOError, etc.).
|
||||
FileStatus currentStatus; ///< Current status of the file (Ok, IOError, etc.).
|
||||
U32 capability; ///< Keeps track of file capabilities.
|
||||
|
||||
File(const File&); ///< This is here to disable the copy constructor.
|
||||
|
|
@ -72,7 +72,7 @@ public:
|
|||
/// Opens a file for access using the specified AccessMode
|
||||
///
|
||||
/// @returns The status of the file
|
||||
Status open(const char *filename, const AccessMode openMode);
|
||||
FileStatus open(const char *filename, const AccessMode openMode);
|
||||
|
||||
/// Gets the current position in the file
|
||||
///
|
||||
|
|
@ -99,7 +99,7 @@ public:
|
|||
/// @endcode
|
||||
///
|
||||
/// @returns The status of the file
|
||||
Status setPosition(S32 position, bool absolutePos = true);
|
||||
FileStatus setPosition(S32 position, bool absolutePos = true);
|
||||
|
||||
/// Returns the size of the file
|
||||
U32 getSize() const;
|
||||
|
|
@ -107,25 +107,25 @@ public:
|
|||
/// Make sure everything that's supposed to be written to the file gets written.
|
||||
///
|
||||
/// @returns The status of the file.
|
||||
Status flush();
|
||||
FileStatus flush();
|
||||
|
||||
/// Closes the file
|
||||
///
|
||||
/// @returns The status of the file.
|
||||
Status close();
|
||||
FileStatus close();
|
||||
|
||||
/// Gets the status of the file
|
||||
Status getStatus() const;
|
||||
FileStatus getStatus() const;
|
||||
|
||||
/// Reads "size" bytes from the file, and dumps data into "dst".
|
||||
/// The number of actual bytes read is returned in bytesRead
|
||||
/// @returns The status of the file
|
||||
Status read(U32 size, char *dst, U32 *bytesRead = NULL);
|
||||
FileStatus read(U32 size, char *dst, U32 *bytesRead = NULL);
|
||||
|
||||
/// Writes "size" bytes into the file from the pointer "src".
|
||||
/// The number of actual bytes written is returned in bytesWritten
|
||||
/// @returns The status of the file
|
||||
Status write(U32 size, const char *src, U32 *bytesWritten = NULL);
|
||||
FileStatus write(U32 size, const char *src, U32 *bytesWritten = NULL);
|
||||
|
||||
/// Returns whether or not this file is capable of the given function.
|
||||
bool hasCapability(Capability cap) const;
|
||||
|
|
@ -133,8 +133,8 @@ public:
|
|||
const void* getHandle() { return handle; }
|
||||
|
||||
protected:
|
||||
Status setStatus(); ///< Called after error encountered.
|
||||
Status setStatus(Status status); ///< Setter for the current status.
|
||||
FileStatus setStatus(); ///< Called after error encountered.
|
||||
FileStatus setStatus(FileStatus status); ///< Setter for the current status.
|
||||
};
|
||||
|
||||
#endif // _FILE_IO_H_
|
||||
|
|
|
|||
|
|
@ -234,7 +234,7 @@ public:
|
|||
mWaterMark = FrameAllocator::getWaterMark();
|
||||
mMemory = reinterpret_cast<T *>( FrameAllocator::alloc( sizeof( T ) * count ) );
|
||||
|
||||
for( int i = 0; i < mNumObjectsInMemory; i++ )
|
||||
for( S32 i = 0; i < mNumObjectsInMemory; i++ )
|
||||
constructInPlace<T>( &mMemory[i] );
|
||||
}
|
||||
|
||||
|
|
@ -242,7 +242,7 @@ public:
|
|||
~FrameTemp()
|
||||
{
|
||||
// Call destructor
|
||||
for( int i = 0; i < mNumObjectsInMemory; i++ )
|
||||
for( S32 i = 0; i < mNumObjectsInMemory; i++ )
|
||||
destructInPlace<T>( &mMemory[i] );
|
||||
|
||||
FrameAllocator::setWaterMark( mWaterMark );
|
||||
|
|
|
|||
|
|
@ -86,15 +86,34 @@ bool ITickable::advanceTime( U32 timeDelta )
|
|||
|
||||
// Advance objects
|
||||
if( tickCount )
|
||||
{
|
||||
for( ; smLastTick != targetTick; smLastTick += smTickMs )
|
||||
for( ProcessListIterator i = getProcessList().begin(); i != getProcessList().end(); i++ )
|
||||
if( (*i)->isProcessingTicks() )
|
||||
(*i)->processTick();
|
||||
{
|
||||
for( U32 i=0; i < getProcessList().size(); )
|
||||
{
|
||||
ITickable* iTick = getProcessList()[i];
|
||||
if( iTick->isProcessingTicks() )
|
||||
{
|
||||
iTick->processTick();
|
||||
|
||||
// Only advance counter if the tickable hasn't deleted itself
|
||||
if( i < getProcessList().size() && iTick == getProcessList()[i] )
|
||||
++i;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Move onto the next tickable
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
smLastDelta = ( smTickMs - ( targetTime & smTickMask ) ) & smTickMask;
|
||||
F32 dt = smLastDelta / F32( smTickMs );
|
||||
|
||||
// Now interpolate objects that want ticks
|
||||
// Now interpolate objects that want ticks. Note that an object should never delete
|
||||
// itself during an interpolateTick().
|
||||
for( ProcessListIterator i = getProcessList().begin(); i != getProcessList().end(); i++ )
|
||||
if( (*i)->isProcessingTicks() )
|
||||
(*i)->interpolateTick( dt );
|
||||
|
|
@ -102,8 +121,15 @@ bool ITickable::advanceTime( U32 timeDelta )
|
|||
|
||||
// Inform ALL objects that time was advanced
|
||||
dt = F32( timeDelta ) / 1000.f;
|
||||
for( ProcessListIterator i = getProcessList().begin(); i != getProcessList().end(); i++ )
|
||||
(*i)->advanceTime( dt );
|
||||
for( U32 i=0; i < getProcessList().size(); )
|
||||
{
|
||||
ITickable* iTick = getProcessList()[i];
|
||||
iTick->advanceTime( dt );
|
||||
|
||||
// Only advance counter if the tickable hasn't deleted itself
|
||||
if( i < getProcessList().size() && iTick == getProcessList()[i] )
|
||||
++i;
|
||||
}
|
||||
|
||||
smLastTime = targetTime;
|
||||
|
||||
|
|
|
|||
|
|
@ -324,7 +324,7 @@ namespace Torque
|
|||
return mFileData->mPath;
|
||||
}
|
||||
|
||||
FileNode::Status MemFile::getStatus() const
|
||||
FileNode::NodeStatus MemFile::getStatus() const
|
||||
{
|
||||
return mStatus;
|
||||
}
|
||||
|
|
@ -502,7 +502,7 @@ namespace Torque
|
|||
return mDirectoryData->getAttributes(attr);
|
||||
}
|
||||
|
||||
FileNode::Status MemDirectory::getStatus() const
|
||||
FileNode::NodeStatus MemDirectory::getStatus() const
|
||||
{
|
||||
return mStatus;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ namespace Torque
|
|||
virtual ~MemFile();
|
||||
|
||||
Path getName() const;
|
||||
Status getStatus() const;
|
||||
NodeStatus getStatus() const;
|
||||
bool getAttributes(Attributes*);
|
||||
|
||||
U32 getPosition();
|
||||
|
|
@ -91,7 +91,7 @@ namespace Torque
|
|||
|
||||
MemFileSystem* mFileSystem;
|
||||
MemFileData* mFileData;
|
||||
Status mStatus;
|
||||
NodeStatus mStatus;
|
||||
U32 mCurrentPos;
|
||||
|
||||
bool _updateInfo();
|
||||
|
|
@ -108,7 +108,7 @@ namespace Torque
|
|||
~MemDirectory();
|
||||
|
||||
Path getName() const;
|
||||
Status getStatus() const;
|
||||
NodeStatus getStatus() const;
|
||||
bool getAttributes(Attributes*);
|
||||
|
||||
bool open();
|
||||
|
|
@ -122,7 +122,7 @@ namespace Torque
|
|||
|
||||
U32 calculateChecksum();
|
||||
|
||||
Status mStatus;
|
||||
NodeStatus mStatus;
|
||||
U32 mSearchIndex;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ bool OggDecoder::_readNextPacket( ogg_packet* packet )
|
|||
|
||||
while( 1 )
|
||||
{
|
||||
int result = ogg_stream_packetout( &mOggStreamState, packet );
|
||||
S32 result = ogg_stream_packetout( &mOggStreamState, packet );
|
||||
if( result == 0 )
|
||||
{
|
||||
if( !mOggStream->_requestData() )
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ bool OggTheoraDecoder::_init()
|
|||
break;
|
||||
}
|
||||
|
||||
int result = th_decode_headerin( &mTheoraInfo, &mTheoraComment, &mTheoraSetup, &nextPacket );
|
||||
S32 result = th_decode_headerin( &mTheoraInfo, &mTheoraComment, &mTheoraSetup, &nextPacket );
|
||||
if( result < 0 )
|
||||
{
|
||||
haveTheoraHeader = false;
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ bool OggVorbisDecoder::_init()
|
|||
break;
|
||||
}
|
||||
|
||||
int result = vorbis_synthesis_headerin( &mVorbisInfo, &mVorbisComment, &nextPacket );
|
||||
S32 result = vorbis_synthesis_headerin( &mVorbisInfo, &mVorbisComment, &nextPacket );
|
||||
if( result != 0 )
|
||||
{
|
||||
haveVorbisHeader = false;
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@
|
|||
|
||||
#include "console/engineAPI.h"
|
||||
|
||||
using namespace Torque;
|
||||
|
||||
static AutoPtr< ResourceManager > smInstance;
|
||||
|
||||
ResourceManager::ResourceManager()
|
||||
|
|
|
|||
|
|
@ -31,8 +31,6 @@
|
|||
#include "core/util/tDictionary.h"
|
||||
#endif
|
||||
|
||||
using namespace Torque;
|
||||
|
||||
class ResourceManager
|
||||
{
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -31,6 +31,18 @@
|
|||
/// template expansion.
|
||||
namespace IOHelper
|
||||
{
|
||||
template<class A,class B,class C,class D,class E,class F,class G,class H,class I,class J,class K, class L, class M>
|
||||
inline bool reads(Stream *s,A& a,B& b,C& c,D& d,E& e,F& f,G& g,H& h,I& i,J& j,K& k,L& l,M& m)
|
||||
{ s->read(&a); s->read(&b); s->read(&c); s->read(&d); s->read(&e); s->read(&f); s->read(&g); s->read(&h); s->read(&i); s->read(&j); s->read(&k); s->read(&l); return s->read(&m); }
|
||||
|
||||
template<class A,class B,class C,class D,class E,class F,class G,class H,class I,class J,class K, class L>
|
||||
inline bool reads(Stream *s,A& a,B& b,C& c,D& d,E& e,F& f,G& g,H& h,I& i,J& j,K& k,L& l)
|
||||
{ s->read(&a); s->read(&b); s->read(&c); s->read(&d); s->read(&e); s->read(&f); s->read(&g); s->read(&h); s->read(&i); s->read(&j); s->read(&k); return s->read(&l); }
|
||||
|
||||
template<class A,class B,class C,class D,class E,class F,class G,class H,class I,class J,class K>
|
||||
inline bool reads(Stream *s,A& a,B& b,C& c,D& d,E& e,F& f,G& g,H& h,I& i,J& j,K& k)
|
||||
{ s->read(&a); s->read(&b); s->read(&c); s->read(&d); s->read(&e); s->read(&f); s->read(&g); s->read(&h); s->read(&i); s->read(&j); return s->read(&k); }
|
||||
|
||||
template<class A,class B,class C,class D,class E,class F,class G,class H,class I,class J>
|
||||
inline bool reads(Stream *s,A& a,B& b,C& c,D& d,E& e,F& f,G& g,H& h,I& i,J& j)
|
||||
{ s->read(&a); s->read(&b); s->read(&c); s->read(&d); s->read(&e); s->read(&f); s->read(&g); s->read(&h); s->read(&i); return s->read(&j); }
|
||||
|
|
@ -71,6 +83,18 @@ namespace IOHelper
|
|||
inline bool reads(Stream *s,A& a)
|
||||
{ return s->read(&a); }
|
||||
|
||||
template<class A,class B,class C,class D,class E,class F,class G,class H,class I,class J,class K,class L,class M>
|
||||
inline bool writes(Stream *s,A& a,B& b,C& c,D& d,E& e,F& f,G& g,H& h,I& i,J& j,K& k,L& l,M& m)
|
||||
{ s->write(a); s->write(b); s->write(c); s->write(d); s->write(e); s->write(f); s->write(g); s->write(h); s->write(i); s->write(j); s->write(k); s->write(l); return s->write(m); }
|
||||
|
||||
template<class A,class B,class C,class D,class E,class F,class G,class H,class I,class J,class K,class L>
|
||||
inline bool writes(Stream *s,A& a,B& b,C& c,D& d,E& e,F& f,G& g,H& h,I& i,J& j,K& k,L& l)
|
||||
{ s->write(a); s->write(b); s->write(c); s->write(d); s->write(e); s->write(f); s->write(g); s->write(h); s->write(i); s->write(j); s->write(k); return s->write(l); }
|
||||
|
||||
template<class A,class B,class C,class D,class E,class F,class G,class H,class I,class J,class K>
|
||||
inline bool writes(Stream *s,A& a,B& b,C& c,D& d,E& e,F& f,G& g,H& h,I& i,J& j,K& k)
|
||||
{ s->write(a); s->write(b); s->write(c); s->write(d); s->write(e); s->write(f); s->write(g); s->write(h); s->write(i); s->write(j); return s->write(k); }
|
||||
|
||||
template<class A,class B,class C,class D,class E,class F,class G,class H,class I,class J>
|
||||
inline bool writes(Stream *s,A& a,B& b,C& c,D& d,E& e,F& f,G& g,H& h,I& i,J& j)
|
||||
{ s->write(a); s->write(b); s->write(c); s->write(d); s->write(e); s->write(f); s->write(g); s->write(h); s->write(i); return s->write(j); }
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ Stream::Stream()
|
|||
{
|
||||
}
|
||||
|
||||
const char* Stream::getStatusString(const Status in_status)
|
||||
const char* Stream::getStatusString(const StreamStatus in_status)
|
||||
{
|
||||
switch (in_status) {
|
||||
case Ok:
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class Stream
|
|||
// Public structs and enumerations...
|
||||
public:
|
||||
/// Status constants for the stream
|
||||
enum Status {
|
||||
enum StreamStatus {
|
||||
Ok = 0, ///< Ok!
|
||||
IOError, ///< Read or Write error
|
||||
EOS, ///< End of Stream reached (mostly for reads)
|
||||
|
|
@ -74,20 +74,20 @@ public:
|
|||
|
||||
// Accessible only through inline accessors
|
||||
private:
|
||||
Status m_streamStatus;
|
||||
StreamStatus m_streamStatus;
|
||||
|
||||
// Derived accessible data modifiers...
|
||||
protected:
|
||||
void setStatus(const Status in_newStatus) { m_streamStatus = in_newStatus; }
|
||||
void setStatus(const StreamStatus in_newStatus) { m_streamStatus = in_newStatus; }
|
||||
|
||||
public:
|
||||
Stream();
|
||||
virtual ~Stream() {}
|
||||
|
||||
/// Gets the status of the stream
|
||||
Stream::Status getStatus() const { return m_streamStatus; }
|
||||
Stream::StreamStatus getStatus() const { return m_streamStatus; }
|
||||
/// Gets a printable string form of the status
|
||||
static const char* getStatusString(const Status in_status);
|
||||
static const char* getStatusString(const StreamStatus in_status);
|
||||
|
||||
// Derived classes must override these...
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -113,8 +113,9 @@ const char * StreamObject::readLine()
|
|||
if(mStream == NULL)
|
||||
return NULL;
|
||||
|
||||
char *buffer = Con::getReturnBuffer(256);
|
||||
mStream->readLine((U8 *)buffer, 256);
|
||||
static const U32 bufSize = 256;
|
||||
char *buffer = Con::getReturnBuffer(bufSize);
|
||||
mStream->readLine((U8 *)buffer, bufSize);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -438,7 +438,7 @@ void StringBufferManager::updateStats()
|
|||
request8 = 0;
|
||||
request16 = 0;
|
||||
U32 nstrings = strings.size();
|
||||
for(int i=0; i < nstrings; i++)
|
||||
for(S32 i=0; i < nstrings; i++)
|
||||
{
|
||||
request8 += strings[i]->rc->requestCount8;
|
||||
request16 += strings[i]->rc->requestCount16;
|
||||
|
|
@ -459,7 +459,7 @@ void StringBufferManager::dumpAllStrings()
|
|||
U32 nstrings = strings.size();
|
||||
Con::printf("===== String Manager: All Strings =====");
|
||||
Con::printf(" utf8 | utf16 | string");
|
||||
for(int i=0; i < nstrings; i++)
|
||||
for(S32 i=0; i < nstrings; i++)
|
||||
{
|
||||
UTF8* tmp = strings[i]->createCopy8();
|
||||
strings[i]->rc->requestCount8--;
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ U32 _StringTable::hashString(const char* str)
|
|||
char c;
|
||||
while((c = *str++) != 0) {
|
||||
ret <<= 1;
|
||||
ret ^= sgHashTable[static_cast<U32>(c)];
|
||||
ret ^= sgHashTable[static_cast<U8>(c)];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -73,7 +73,7 @@ U32 _StringTable::hashStringn(const char* str, S32 len)
|
|||
char c;
|
||||
while((c = *str++) != 0 && len--) {
|
||||
ret <<= 1;
|
||||
ret ^= sgHashTable[static_cast<U32>(c)];
|
||||
ret ^= sgHashTable[static_cast<U8>(c)];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -195,8 +195,11 @@ StringTableEntry _StringTable::lookupn(const char* val, S32 len, const bool cas
|
|||
}
|
||||
|
||||
//--------------------------------------
|
||||
void _StringTable::resize(const U32 newSize)
|
||||
void _StringTable::resize(const U32 _newSize)
|
||||
{
|
||||
/// avoid a possible 0 division
|
||||
const U32 newSize = _newSize ? _newSize : 1;
|
||||
|
||||
Node *head = NULL, *walk, *temp;
|
||||
U32 i;
|
||||
// reverse individual bucket lists
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ bool FindMatch::isMatch( const char *exp, const char *str, bool caseSensitive )
|
|||
bool FindMatch::isMatchMultipleExprs( const char *exps, const char *str, bool caseSensitive )
|
||||
{
|
||||
char *tok = 0;
|
||||
int len = dStrlen(exps);
|
||||
S32 len = dStrlen(exps);
|
||||
|
||||
char *e = new char[len+1];
|
||||
dStrcpy(e,exps);
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
#include "platform/platform.h"
|
||||
|
||||
|
||||
#if defined(TORQUE_OS_WIN32) || defined(TORQUE_OS_XBOX) || defined(TORQUE_OS_XENON)
|
||||
#if defined(TORQUE_OS_WIN) || defined(TORQUE_OS_XBOX) || defined(TORQUE_OS_XENON)
|
||||
// This standard function is not defined when compiling with VC7...
|
||||
#define vsnprintf _vsnprintf
|
||||
#endif
|
||||
|
|
@ -97,10 +97,10 @@ nat_toupper( nat_char a )
|
|||
|
||||
|
||||
|
||||
static int
|
||||
static S32
|
||||
compare_right(const nat_char* a, const nat_char* b)
|
||||
{
|
||||
int bias = 0;
|
||||
S32 bias = 0;
|
||||
|
||||
/* The longest run of digits wins. That aside, the greatest
|
||||
value wins, but we can't know that it will until we've scanned
|
||||
|
|
@ -108,7 +108,7 @@ compare_right(const nat_char* a, const nat_char* b)
|
|||
remember it in BIAS. */
|
||||
for (;; a++, b++) {
|
||||
if (!nat_isdigit(*a) && !nat_isdigit(*b))
|
||||
return bias;
|
||||
break;
|
||||
else if (!nat_isdigit(*a))
|
||||
return -1;
|
||||
else if (!nat_isdigit(*b))
|
||||
|
|
@ -123,7 +123,7 @@ compare_right(const nat_char* a, const nat_char* b)
|
|||
return bias;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return bias;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -134,7 +134,7 @@ compare_left(const nat_char* a, const nat_char* b)
|
|||
different value wins. */
|
||||
for (;; a++, b++) {
|
||||
if (!nat_isdigit(*a) && !nat_isdigit(*b))
|
||||
return 0;
|
||||
break;
|
||||
else if (!nat_isdigit(*a))
|
||||
return -1;
|
||||
else if (!nat_isdigit(*b))
|
||||
|
|
@ -149,11 +149,11 @@ compare_left(const nat_char* a, const nat_char* b)
|
|||
}
|
||||
|
||||
|
||||
static int strnatcmp0(const nat_char* a, const nat_char* b, int fold_case)
|
||||
static S32 strnatcmp0(const nat_char* a, const nat_char* b, S32 fold_case)
|
||||
{
|
||||
int ai, bi;
|
||||
S32 ai, bi;
|
||||
nat_char ca, cb;
|
||||
int fractional, result;
|
||||
S32 fractional, result;
|
||||
|
||||
ai = bi = 0;
|
||||
while (1) {
|
||||
|
|
@ -200,13 +200,13 @@ static int strnatcmp0(const nat_char* a, const nat_char* b, int fold_case)
|
|||
}
|
||||
|
||||
|
||||
int dStrnatcmp(const nat_char* a, const nat_char* b) {
|
||||
S32 dStrnatcmp(const nat_char* a, const nat_char* b) {
|
||||
return strnatcmp0(a, b, 0);
|
||||
}
|
||||
|
||||
|
||||
/* Compare, recognizing numeric string and ignoring case. */
|
||||
int dStrnatcasecmp(const nat_char* a, const nat_char* b) {
|
||||
S32 dStrnatcasecmp(const nat_char* a, const nat_char* b) {
|
||||
return strnatcmp0(a, b, 1);
|
||||
}
|
||||
|
||||
|
|
@ -328,12 +328,12 @@ char* dStrcpyl(char *dst, dsize_t dstSize, ...)
|
|||
}
|
||||
|
||||
|
||||
int dStrcmp( const UTF16 *str1, const UTF16 *str2)
|
||||
S32 dStrcmp( const UTF16 *str1, const UTF16 *str2)
|
||||
{
|
||||
#if defined(TORQUE_OS_WIN32) || defined(TORQUE_OS_XBOX) || defined(TORQUE_OS_XENON)
|
||||
#if defined(TORQUE_OS_WIN) || defined(TORQUE_OS_XBOX) || defined(TORQUE_OS_XENON)
|
||||
return wcscmp( reinterpret_cast<const wchar_t *>( str1 ), reinterpret_cast<const wchar_t *>( str2 ) );
|
||||
#else
|
||||
int ret;
|
||||
S32 ret;
|
||||
const UTF16 *a, *b;
|
||||
a = str1;
|
||||
b = str2;
|
||||
|
|
@ -347,7 +347,7 @@ int dStrcmp( const UTF16 *str1, const UTF16 *str2)
|
|||
|
||||
char* dStrupr(char *str)
|
||||
{
|
||||
#if defined(TORQUE_OS_WIN32) || defined(TORQUE_OS_XBOX) || defined(TORQUE_OS_XENON)
|
||||
#if defined(TORQUE_OS_WIN) || defined(TORQUE_OS_XBOX) || defined(TORQUE_OS_XENON)
|
||||
return _strupr(str);
|
||||
#else
|
||||
if (str == NULL)
|
||||
|
|
@ -365,7 +365,7 @@ char* dStrupr(char *str)
|
|||
|
||||
char* dStrlwr(char *str)
|
||||
{
|
||||
#if defined(TORQUE_OS_WIN32) || defined(TORQUE_OS_XBOX) || defined(TORQUE_OS_XENON)
|
||||
#if defined(TORQUE_OS_WIN) || defined(TORQUE_OS_XBOX) || defined(TORQUE_OS_XENON)
|
||||
return _strlwr(str);
|
||||
#else
|
||||
if (str == NULL)
|
||||
|
|
@ -421,7 +421,7 @@ S32 dVsprintf(char *buffer, U32 bufferSize, const char *format, void *arglist)
|
|||
|
||||
S32 dSscanf(const char *buffer, const char *format, ...)
|
||||
{
|
||||
#if defined(TORQUE_OS_WIN32) || defined(TORQUE_OS_XBOX) || defined(TORQUE_OS_XENON)
|
||||
#if defined(TORQUE_OS_WIN) || defined(TORQUE_OS_XBOX) || defined(TORQUE_OS_XENON)
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,10 +31,12 @@
|
|||
#include "platform/types.h"
|
||||
#endif
|
||||
|
||||
#if defined(TORQUE_OS_WIN32) || defined(TORQUE_OS_XBOX) || defined(TORQUE_OS_XENON)
|
||||
#if defined(TORQUE_OS_WIN) || defined(TORQUE_OS_XBOX) || defined(TORQUE_OS_XENON)
|
||||
// These standard functions are not defined on Win32 and other Microsoft platforms...
|
||||
#define strcasecmp _stricmp
|
||||
#define strncasecmp _strnicmp
|
||||
#endif
|
||||
#if (_MSC_VER < 1800) && (defined(TORQUE_OS_WIN) || defined(TORQUE_OS_XBOX) || defined(TORQUE_OS_XENON))
|
||||
#define strtof (float)strtod
|
||||
#endif
|
||||
|
||||
|
|
@ -52,22 +54,22 @@ inline char *dStrncat(char *dst, const char *src, dsize_t len)
|
|||
return strncat(dst,src,len);
|
||||
}
|
||||
|
||||
inline int dStrcmp(const char *str1, const char *str2)
|
||||
inline S32 dStrcmp(const char *str1, const char *str2)
|
||||
{
|
||||
return strcmp(str1, str2);
|
||||
}
|
||||
|
||||
inline int dStrncmp(const char *str1, const char *str2, dsize_t len)
|
||||
inline S32 dStrncmp(const char *str1, const char *str2, dsize_t len)
|
||||
{
|
||||
return strncmp(str1, str2, len);
|
||||
}
|
||||
|
||||
inline int dStricmp(const char *str1, const char *str2)
|
||||
inline S32 dStricmp(const char *str1, const char *str2)
|
||||
{
|
||||
return strcasecmp( str1, str2 );
|
||||
}
|
||||
|
||||
inline int dStrnicmp(const char *str1, const char *str2, dsize_t len)
|
||||
inline S32 dStrnicmp(const char *str1, const char *str2, dsize_t len)
|
||||
{
|
||||
return strncasecmp( str1, str2, len );
|
||||
}
|
||||
|
|
@ -87,22 +89,22 @@ inline dsize_t dStrlen(const char *str)
|
|||
return strlen(str);
|
||||
}
|
||||
|
||||
inline char *dStrchr(char *str, int c)
|
||||
inline char *dStrchr(char *str, S32 c)
|
||||
{
|
||||
return strchr(str,c);
|
||||
}
|
||||
|
||||
inline const char *dStrchr(const char *str, int c)
|
||||
inline const char *dStrchr(const char *str, S32 c)
|
||||
{
|
||||
return strchr(str,c);
|
||||
}
|
||||
|
||||
inline char *dStrrchr(char *str, int c)
|
||||
inline char *dStrrchr(char *str, S32 c)
|
||||
{
|
||||
return strrchr(str,c);
|
||||
}
|
||||
|
||||
inline const char *dStrrchr(const char *str, int c)
|
||||
inline const char *dStrrchr(const char *str, S32 c)
|
||||
{
|
||||
return strrchr(str,c);
|
||||
}
|
||||
|
|
@ -198,9 +200,9 @@ extern char *dStrlwr(char *str);
|
|||
extern char* dStrichr( char* str, char ch );
|
||||
extern const char* dStrichr( const char* str, char ch );
|
||||
|
||||
extern int dStrcmp(const UTF16 *str1, const UTF16 *str2);
|
||||
extern int dStrnatcmp( const char* str1, const char* str2 );
|
||||
extern int dStrnatcasecmp( const char* str1, const char* str2 );
|
||||
extern S32 dStrcmp(const UTF16 *str1, const UTF16 *str2);
|
||||
extern S32 dStrnatcmp( const char* str1, const char* str2 );
|
||||
extern S32 dStrnatcasecmp( const char* str1, const char* str2 );
|
||||
|
||||
inline bool dAtob(const char *str)
|
||||
{
|
||||
|
|
@ -215,13 +217,16 @@ 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]
|
||||
|
||||
extern void dPrintf(const char *format, ...);
|
||||
extern int dVprintf(const char *format, void *arglist);
|
||||
extern int dSprintf(char *buffer, U32 bufferSize, const char *format, ...);
|
||||
extern int dVsprintf(char *buffer, U32 bufferSize, const char *format, void *arglist);
|
||||
extern int dSscanf(const char *buffer, const char *format, ...);
|
||||
extern S32 dVprintf(const char *format, void *arglist);
|
||||
extern S32 dSprintf(char *buffer, U32 bufferSize, const char *format, ...);
|
||||
extern S32 dVsprintf(char *buffer, U32 bufferSize, const char *format, void *arglist);
|
||||
extern S32 dSscanf(const char *buffer, const char *format, ...);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -311,7 +311,7 @@ UTF32 oneUTF8toUTF32( const UTF8* codepoint, U32 *unitsWalked)
|
|||
U8 codeunit;
|
||||
|
||||
// check the first byte ( a.k.a. codeunit ) .
|
||||
unsigned char c = codepoint[0];
|
||||
U8 c = codepoint[0];
|
||||
c = c >> 1;
|
||||
expectedByteCount = sgFirstByteLUT[c];
|
||||
if(expectedByteCount > 0) // 0 or negative is illegal to start with
|
||||
|
|
@ -469,7 +469,7 @@ U32 oneUTF32toUTF8(const UTF32 codepoint, UTF8 *threeByteCodeunitBuf)
|
|||
U8 marker = ( ~mask << 1); // 1000 0000
|
||||
|
||||
// Process the low order bytes, shifting the codepoint down 6 each pass.
|
||||
for( int i = bytecount-1; i > 0; i--)
|
||||
for( S32 i = bytecount-1; i > 0; i--)
|
||||
{
|
||||
threeByteCodeunitBuf[i] = marker | (working & mask);
|
||||
working >>= 6;
|
||||
|
|
|
|||
|
|
@ -308,7 +308,7 @@ bool TagDictionary::match(const char* pattern, const char* str)
|
|||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
static int QSORT_CALLBACK idCompare(const void *in_p1, const void *in_p2)
|
||||
static S32 QSORT_CALLBACK idCompare(const void *in_p1, const void *in_p2)
|
||||
{
|
||||
return *((S32 *) in_p1) - *((S32 *) in_p2);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ TorqueThreadStaticListHandle _TorqueThreadStaticReg::spawnThreadStaticsInstance(
|
|||
|
||||
// Copy mThreadStaticInstances[0] (master copy) into new memory, and
|
||||
// pass it back.
|
||||
for( int i = 0; i < getThreadStaticListVector()[0].size(); i++ )
|
||||
for( S32 i = 0; i < getThreadStaticListVector()[0].size(); i++ )
|
||||
{
|
||||
getThreadStaticListVector().last().push_back( getThreadStaticListVector()[0][i]->_createInstance() );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,10 +47,12 @@ public:
|
|||
: mHitCount( 0 )
|
||||
#endif
|
||||
{ };
|
||||
virtual ~_TorqueThreadStatic() { }
|
||||
|
||||
static const U32 getListIndex(){ return mListIndex; }
|
||||
|
||||
virtual void *getMemInstPtr() = 0;
|
||||
virtual const void *getConstMemInstPtr() const = 0;
|
||||
virtual const dsize_t getMemInstSize() const = 0;
|
||||
|
||||
#ifdef TORQUE_ENABLE_THREAD_STATIC_METRICS
|
||||
|
|
@ -142,6 +144,7 @@ private:
|
|||
public:
|
||||
TorqueThreadStatic( T instanceVal ) : mInstance( instanceVal ) {}
|
||||
virtual void *getMemInstPtr() { return &mInstance; }
|
||||
virtual const void *getConstMemInstPtr() const { return &mInstance; }
|
||||
|
||||
// I am not sure these are needed, and I don't want to create confusing-to-debug code
|
||||
#if 0
|
||||
|
|
@ -180,7 +183,7 @@ public: \
|
|||
_##name##TorqueThreadStatic() : TorqueThreadStatic<type>( initalvalue ) {} \
|
||||
virtual const dsize_t getMemInstSize() const { return sizeof( type ); } \
|
||||
type &_cast() { return *reinterpret_cast<type *>( getMemInstPtr() ); } \
|
||||
const type &_const_cast() const { return *reinterpret_cast<const type *>( getMemInstPtr() ); } \
|
||||
const type &_const_cast() const { return *reinterpret_cast<const type *>( getConstMemInstPtr() ); } \
|
||||
}; \
|
||||
static _##name##TorqueThreadStatic name##TorqueThreadStatic; \
|
||||
static _TorqueThreadStaticReg _##name##TTSReg( reinterpret_cast<_TorqueThreadStatic *>( & name##TorqueThreadStatic ) )
|
||||
|
|
|
|||
|
|
@ -384,6 +384,30 @@ bool Tokenizer::advanceToken(const bool crossLine, const bool assertAvail)
|
|||
cont = false;
|
||||
}
|
||||
}
|
||||
else if (c == '/' && mpBuffer[mCurrPos+1] == '*')
|
||||
{
|
||||
// Block quote...
|
||||
if (currPosition == 0)
|
||||
{
|
||||
// continue to end of block, then let crossLine determine on the next pass
|
||||
while (mCurrPos < mBufferSize - 1 && (mpBuffer[mCurrPos] != '*' || mpBuffer[mCurrPos + 1] != '/'))
|
||||
mCurrPos++;
|
||||
|
||||
if (mCurrPos < mBufferSize - 1)
|
||||
mCurrPos += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
// This is the end of the token. Continue to EOL
|
||||
while (mCurrPos < mBufferSize - 1 && (mpBuffer[mCurrPos] != '*' || mpBuffer[mCurrPos + 1] != '/'))
|
||||
mCurrPos++;
|
||||
|
||||
if (mCurrPos < mBufferSize - 1)
|
||||
mCurrPos += 2;
|
||||
|
||||
cont = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If this is the first non-token character then store the
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ inline OutputClass horrible_cast(const InputClass input){
|
|||
// Cause a compile-time error if in, out and u are not the same size.
|
||||
// If the compile fails here, it means the compiler has peculiar
|
||||
// unions which would prevent the cast from working.
|
||||
typedef int ERROR_CantUseHorrible_cast[sizeof(InputClass)==sizeof(u)
|
||||
typedef S32 ERROR_CantUseHorrible_cast[sizeof(InputClass)==sizeof(u)
|
||||
&& sizeof(InputClass)==sizeof(OutputClass) ? 1 : -1];
|
||||
u.in = input;
|
||||
return u.out;
|
||||
|
|
@ -270,7 +270,7 @@ struct VoidToDefaultVoid<void> { typedef DefaultVoid type; };
|
|||
#endif
|
||||
|
||||
// The size of a single inheritance member function pointer.
|
||||
const int SINGLE_MEMFUNCPTR_SIZE = sizeof(void (GenericClass::*)());
|
||||
const S32 SINGLE_MEMFUNCPTR_SIZE = sizeof(void (GenericClass::*)());
|
||||
|
||||
// SimplifyMemFunc< >::Convert()
|
||||
//
|
||||
|
|
@ -284,7 +284,7 @@ const int SINGLE_MEMFUNCPTR_SIZE = sizeof(void (GenericClass::*)());
|
|||
// template specialisation, I use full specialisation of a wrapper struct.
|
||||
|
||||
// general case -- don't know how to convert it. Force a compile failure
|
||||
template <int N>
|
||||
template <S32 N>
|
||||
struct SimplifyMemFunc {
|
||||
template <class X, class XFuncType, class GenericMemFuncType>
|
||||
inline static GenericClass *Convert(X *pthis, XFuncType function_to_bind,
|
||||
|
|
@ -344,11 +344,11 @@ struct SimplifyMemFunc< SINGLE_MEMFUNCPTR_SIZE + sizeof(int) > {
|
|||
XFuncType func;
|
||||
struct {
|
||||
GenericMemFuncType funcaddress; // points to the actual member function
|
||||
int delta; // #BYTES to be added to the 'this' pointer
|
||||
S32 delta; // #BYTES to be added to the 'this' pointer
|
||||
}s;
|
||||
} u;
|
||||
// Check that the horrible_cast will work
|
||||
typedef int ERROR_CantUsehorrible_cast[sizeof(function_to_bind)==sizeof(u.s)? 1 : -1];
|
||||
typedef S32 ERROR_CantUsehorrible_cast[sizeof(function_to_bind)==sizeof(u.s)? 1 : -1];
|
||||
u.func = function_to_bind;
|
||||
bound_func = u.s.funcaddress;
|
||||
return reinterpret_cast<GenericClass *>(reinterpret_cast<char *>(pthis) + u.s.delta);
|
||||
|
|
@ -367,8 +367,8 @@ struct SimplifyMemFunc< SINGLE_MEMFUNCPTR_SIZE + sizeof(int) > {
|
|||
// is internally defined as:
|
||||
struct MicrosoftVirtualMFP {
|
||||
void (GenericClass::*codeptr)(); // points to the actual member function
|
||||
int delta; // #bytes to be added to the 'this' pointer
|
||||
int vtable_index; // or 0 if no virtual inheritance
|
||||
S32 delta; // #bytes to be added to the 'this' pointer
|
||||
S32 vtable_index; // or 0 if no virtual inheritance
|
||||
};
|
||||
// The CRUCIAL feature of Microsoft/Intel MFPs which we exploit is that the
|
||||
// m_codeptr member is *always* called, regardless of the values of the other
|
||||
|
|
@ -405,7 +405,7 @@ struct SimplifyMemFunc<SINGLE_MEMFUNCPTR_SIZE + 2*sizeof(int) >
|
|||
MicrosoftVirtualMFP s;
|
||||
} u2;
|
||||
// Check that the horrible_cast<>s will work
|
||||
typedef int ERROR_CantUsehorrible_cast[sizeof(function_to_bind)==sizeof(u.s)
|
||||
typedef S32 ERROR_CantUsehorrible_cast[sizeof(function_to_bind)==sizeof(u.s)
|
||||
&& sizeof(function_to_bind)==sizeof(u.ProbeFunc)
|
||||
&& sizeof(u2.virtfunc)==sizeof(u2.s) ? 1 : -1];
|
||||
// Unfortunately, taking the address of a MF prevents it from being inlined, so
|
||||
|
|
@ -477,24 +477,24 @@ struct SimplifyMemFunc<SINGLE_MEMFUNCPTR_SIZE + 3*sizeof(int) >
|
|||
// is internally defined as:
|
||||
struct {
|
||||
GenericMemFuncType m_funcaddress; // points to the actual member function
|
||||
int delta; // #bytes to be added to the 'this' pointer
|
||||
int vtordisp; // #bytes to add to 'this' to find the vtable
|
||||
int vtable_index; // or 0 if no virtual inheritance
|
||||
S32 delta; // #bytes to be added to the 'this' pointer
|
||||
S32 vtordisp; // #bytes to add to 'this' to find the vtable
|
||||
S32 vtable_index; // or 0 if no virtual inheritance
|
||||
} s;
|
||||
} u;
|
||||
// Check that the horrible_cast will work
|
||||
typedef int ERROR_CantUsehorrible_cast[sizeof(XFuncType)==sizeof(u.s)? 1 : -1];
|
||||
typedef S32 ERROR_CantUsehorrible_cast[sizeof(XFuncType)==sizeof(u.s)? 1 : -1];
|
||||
u.func = function_to_bind;
|
||||
bound_func = u.s.funcaddress;
|
||||
int virtual_delta = 0;
|
||||
S32 virtual_delta = 0;
|
||||
if (u.s.vtable_index) { // Virtual inheritance is used
|
||||
// First, get to the vtable.
|
||||
// It is 'vtordisp' bytes from the start of the class.
|
||||
const int * vtable = *reinterpret_cast<const int *const*>(
|
||||
const S32 * vtable = *reinterpret_cast<const S32 *const*>(
|
||||
reinterpret_cast<const char *>(pthis) + u.s.vtordisp );
|
||||
|
||||
// 'vtable_index' tells us where in the table we should be looking.
|
||||
virtual_delta = u.s.vtordisp + *reinterpret_cast<const int *>(
|
||||
virtual_delta = u.s.vtordisp + *reinterpret_cast<const S32 *>(
|
||||
reinterpret_cast<const char *>(vtable) + u.s.vtable_index);
|
||||
}
|
||||
// The int at 'virtual_delta' gives us the amount to add to 'this'.
|
||||
|
|
@ -777,7 +777,7 @@ public:
|
|||
// Ensure that there's a compilation failure if function pointers
|
||||
// and data pointers have different sizes.
|
||||
// If you get this error, you need to #undef FASTDELEGATE_USESTATICFUNCTIONHACK.
|
||||
typedef int ERROR_CantUseEvilMethod[sizeof(GenericClass *)==sizeof(function_to_bind) ? 1 : -1];
|
||||
typedef S32 ERROR_CantUseEvilMethod[sizeof(GenericClass *)==sizeof(function_to_bind) ? 1 : -1];
|
||||
m_pthis = horrible_cast<GenericClass *>(function_to_bind);
|
||||
// MSVC, SunC++ and DMC accept the following (non-standard) code:
|
||||
// m_pthis = static_cast<GenericClass *>(static_cast<void *>(function_to_bind));
|
||||
|
|
@ -792,7 +792,7 @@ public:
|
|||
// Ensure that there's a compilation failure if function pointers
|
||||
// and data pointers have different sizes.
|
||||
// If you get this error, you need to #undef FASTDELEGATE_USESTATICFUNCTIONHACK.
|
||||
typedef int ERROR_CantUseEvilMethod[sizeof(UnvoidStaticFuncPtr)==sizeof(this) ? 1 : -1];
|
||||
typedef S32 ERROR_CantUseEvilMethod[sizeof(UnvoidStaticFuncPtr)==sizeof(this) ? 1 : -1];
|
||||
return horrible_cast<UnvoidStaticFuncPtr>(this);
|
||||
}
|
||||
#endif // !defined(FASTDELEGATE_USESTATICFUNCTIONHACK)
|
||||
|
|
@ -906,7 +906,7 @@ public:
|
|||
// Implicit conversion to "bool" using the safe_bool idiom
|
||||
private:
|
||||
typedef struct SafeBoolStruct {
|
||||
int a_data_pointer_to_this_is_0_on_buggy_compilers;
|
||||
S32 a_data_pointer_to_this_is_0_on_buggy_compilers;
|
||||
StaticFunctionPtr m_nonzero;
|
||||
} UselessTypedef;
|
||||
typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type;
|
||||
|
|
@ -991,7 +991,7 @@ public:
|
|||
// Implicit conversion to "bool" using the safe_bool idiom
|
||||
private:
|
||||
typedef struct SafeBoolStruct {
|
||||
int a_data_pointer_to_this_is_0_on_buggy_compilers;
|
||||
S32 a_data_pointer_to_this_is_0_on_buggy_compilers;
|
||||
StaticFunctionPtr m_nonzero;
|
||||
} UselessTypedef;
|
||||
typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type;
|
||||
|
|
@ -1076,7 +1076,7 @@ public:
|
|||
// Implicit conversion to "bool" using the safe_bool idiom
|
||||
private:
|
||||
typedef struct SafeBoolStruct {
|
||||
int a_data_pointer_to_this_is_0_on_buggy_compilers;
|
||||
S32 a_data_pointer_to_this_is_0_on_buggy_compilers;
|
||||
StaticFunctionPtr m_nonzero;
|
||||
} UselessTypedef;
|
||||
typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type;
|
||||
|
|
@ -1161,7 +1161,7 @@ public:
|
|||
// Implicit conversion to "bool" using the safe_bool idiom
|
||||
private:
|
||||
typedef struct SafeBoolStruct {
|
||||
int a_data_pointer_to_this_is_0_on_buggy_compilers;
|
||||
S32 a_data_pointer_to_this_is_0_on_buggy_compilers;
|
||||
StaticFunctionPtr m_nonzero;
|
||||
} UselessTypedef;
|
||||
typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type;
|
||||
|
|
@ -1246,7 +1246,7 @@ public:
|
|||
// Implicit conversion to "bool" using the safe_bool idiom
|
||||
private:
|
||||
typedef struct SafeBoolStruct {
|
||||
int a_data_pointer_to_this_is_0_on_buggy_compilers;
|
||||
S32 a_data_pointer_to_this_is_0_on_buggy_compilers;
|
||||
StaticFunctionPtr m_nonzero;
|
||||
} UselessTypedef;
|
||||
typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type;
|
||||
|
|
@ -1331,7 +1331,7 @@ public:
|
|||
// Implicit conversion to "bool" using the safe_bool idiom
|
||||
private:
|
||||
typedef struct SafeBoolStruct {
|
||||
int a_data_pointer_to_this_is_0_on_buggy_compilers;
|
||||
S32 a_data_pointer_to_this_is_0_on_buggy_compilers;
|
||||
StaticFunctionPtr m_nonzero;
|
||||
} UselessTypedef;
|
||||
typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type;
|
||||
|
|
@ -1416,7 +1416,7 @@ public:
|
|||
// Implicit conversion to "bool" using the safe_bool idiom
|
||||
private:
|
||||
typedef struct SafeBoolStruct {
|
||||
int a_data_pointer_to_this_is_0_on_buggy_compilers;
|
||||
S32 a_data_pointer_to_this_is_0_on_buggy_compilers;
|
||||
StaticFunctionPtr m_nonzero;
|
||||
} UselessTypedef;
|
||||
typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type;
|
||||
|
|
@ -1501,7 +1501,7 @@ public:
|
|||
// Implicit conversion to "bool" using the safe_bool idiom
|
||||
private:
|
||||
typedef struct SafeBoolStruct {
|
||||
int a_data_pointer_to_this_is_0_on_buggy_compilers;
|
||||
S32 a_data_pointer_to_this_is_0_on_buggy_compilers;
|
||||
StaticFunctionPtr m_nonzero;
|
||||
} UselessTypedef;
|
||||
typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type;
|
||||
|
|
@ -1586,7 +1586,7 @@ public:
|
|||
// Implicit conversion to "bool" using the safe_bool idiom
|
||||
private:
|
||||
typedef struct SafeBoolStruct {
|
||||
int a_data_pointer_to_this_is_0_on_buggy_compilers;
|
||||
S32 a_data_pointer_to_this_is_0_on_buggy_compilers;
|
||||
StaticFunctionPtr m_nonzero;
|
||||
} UselessTypedef;
|
||||
typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type;
|
||||
|
|
@ -1613,6 +1613,261 @@ private: // Invoker for static functions
|
|||
return (*(m_Closure.GetStaticFunction()))(p1, p2, p3, p4, p5, p6, p7, p8); }
|
||||
};
|
||||
|
||||
//N=11
|
||||
template<class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class RetType=detail::DefaultVoid>
|
||||
class FastDelegate11 {
|
||||
private:
|
||||
typedef typename detail::DefaultVoidToVoid<RetType>::type DesiredRetType;
|
||||
typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11);
|
||||
typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11);
|
||||
typedef RetType (detail::GenericClass::*GenericMemFn)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11);
|
||||
typedef detail::ClosurePtr<GenericMemFn, StaticFunctionPtr, UnvoidStaticFunctionPtr> ClosureType;
|
||||
ClosureType m_Closure;
|
||||
public:
|
||||
// Typedefs to aid generic programming
|
||||
typedef FastDelegate11 type;
|
||||
|
||||
// Construction and comparison functions
|
||||
FastDelegate11() { clear(); }
|
||||
FastDelegate11(const FastDelegate11 &x) {
|
||||
m_Closure.CopyFrom(this, x.m_Closure); }
|
||||
void operator = (const FastDelegate11 &x) {
|
||||
m_Closure.CopyFrom(this, x.m_Closure); }
|
||||
bool operator ==(const FastDelegate11 &x) const {
|
||||
return m_Closure.IsEqual(x.m_Closure); }
|
||||
bool operator !=(const FastDelegate11 &x) const {
|
||||
return !m_Closure.IsEqual(x.m_Closure); }
|
||||
bool operator <(const FastDelegate11 &x) const {
|
||||
return m_Closure.IsLess(x.m_Closure); }
|
||||
bool operator >(const FastDelegate11 &x) const {
|
||||
return x.m_Closure.IsLess(m_Closure); }
|
||||
// Binding to non-const member functions
|
||||
template < class X, class Y >
|
||||
FastDelegate11(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11) ) {
|
||||
m_Closure.bindmemfunc(detail::implicit_cast<X*>(pthis), function_to_bind); }
|
||||
template < class X, class Y >
|
||||
inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11)) {
|
||||
m_Closure.bindmemfunc(detail::implicit_cast<X*>(pthis), function_to_bind); }
|
||||
// Binding to const member functions.
|
||||
template < class X, class Y >
|
||||
FastDelegate11(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11) const) {
|
||||
m_Closure.bindconstmemfunc(detail::implicit_cast<const X*>(pthis), function_to_bind); }
|
||||
template < class X, class Y >
|
||||
inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11) const) {
|
||||
m_Closure.bindconstmemfunc(detail::implicit_cast<const X *>(pthis), function_to_bind); }
|
||||
// Static functions. We convert them into a member function call.
|
||||
// This constructor also provides implicit conversion
|
||||
FastDelegate11(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11) ) {
|
||||
bind(function_to_bind); }
|
||||
// for efficiency, prevent creation of a temporary
|
||||
void operator = (DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11) ) {
|
||||
bind(function_to_bind); }
|
||||
inline void bind(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8), Param9 p9, Param10 p10, Param11 p11) {
|
||||
m_Closure.bindstaticfunc(this, &FastDelegate11::InvokeStaticFunction,
|
||||
function_to_bind); }
|
||||
// Invoke the delegate
|
||||
RetType operator() (Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11) const {
|
||||
return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11); }
|
||||
// Implicit conversion to "bool" using the safe_bool idiom
|
||||
private:
|
||||
typedef struct SafeBoolStruct {
|
||||
S32 a_data_pointer_to_this_is_0_on_buggy_compilers;
|
||||
StaticFunctionPtr m_nonzero;
|
||||
} UselessTypedef;
|
||||
typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type;
|
||||
public:
|
||||
operator unspecified_bool_type() const {
|
||||
return empty()? 0: &SafeBoolStruct::m_nonzero;
|
||||
}
|
||||
// necessary to allow ==0 to work despite the safe_bool idiom
|
||||
inline bool operator==(StaticFunctionPtr funcptr) {
|
||||
return m_Closure.IsEqualToStaticFuncPtr(funcptr); }
|
||||
inline bool operator!=(StaticFunctionPtr funcptr) {
|
||||
return !m_Closure.IsEqualToStaticFuncPtr(funcptr); }
|
||||
inline bool operator ! () const { // Is it bound to anything?
|
||||
return !m_Closure; }
|
||||
inline bool empty() const {
|
||||
return !m_Closure; }
|
||||
void clear() { m_Closure.clear();}
|
||||
// Conversion to and from the DelegateMemento storage class
|
||||
const DelegateMemento & GetMemento() { return m_Closure; }
|
||||
void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); }
|
||||
|
||||
private: // Invoker for static functions
|
||||
RetType InvokeStaticFunction(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11) const {
|
||||
return (*(m_Closure.GetStaticFunction()))(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11); }
|
||||
};
|
||||
|
||||
//N=12
|
||||
template<class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class RetType=detail::DefaultVoid>
|
||||
class FastDelegate12 {
|
||||
private:
|
||||
typedef typename detail::DefaultVoidToVoid<RetType>::type DesiredRetType;
|
||||
typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12);
|
||||
typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12);
|
||||
typedef RetType (detail::GenericClass::*GenericMemFn)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12);
|
||||
typedef detail::ClosurePtr<GenericMemFn, StaticFunctionPtr, UnvoidStaticFunctionPtr> ClosureType;
|
||||
ClosureType m_Closure;
|
||||
public:
|
||||
// Typedefs to aid generic programming
|
||||
typedef FastDelegate12 type;
|
||||
|
||||
// Construction and comparison functions
|
||||
FastDelegate12() { clear(); }
|
||||
FastDelegate12(const FastDelegate12 &x) {
|
||||
m_Closure.CopyFrom(this, x.m_Closure); }
|
||||
void operator = (const FastDelegate12 &x) {
|
||||
m_Closure.CopyFrom(this, x.m_Closure); }
|
||||
bool operator ==(const FastDelegate12 &x) const {
|
||||
return m_Closure.IsEqual(x.m_Closure); }
|
||||
bool operator !=(const FastDelegate12 &x) const {
|
||||
return !m_Closure.IsEqual(x.m_Closure); }
|
||||
bool operator <(const FastDelegate12 &x) const {
|
||||
return m_Closure.IsLess(x.m_Closure); }
|
||||
bool operator >(const FastDelegate12 &x) const {
|
||||
return x.m_Closure.IsLess(m_Closure); }
|
||||
// Binding to non-const member functions
|
||||
template < class X, class Y >
|
||||
FastDelegate12(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12) ) {
|
||||
m_Closure.bindmemfunc(detail::implicit_cast<X*>(pthis), function_to_bind); }
|
||||
template < class X, class Y >
|
||||
inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12)) {
|
||||
m_Closure.bindmemfunc(detail::implicit_cast<X*>(pthis), function_to_bind); }
|
||||
// Binding to const member functions.
|
||||
template < class X, class Y >
|
||||
FastDelegate12(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12) const) {
|
||||
m_Closure.bindconstmemfunc(detail::implicit_cast<const X*>(pthis), function_to_bind); }
|
||||
template < class X, class Y >
|
||||
inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12) const) {
|
||||
m_Closure.bindconstmemfunc(detail::implicit_cast<const X *>(pthis), function_to_bind); }
|
||||
// Static functions. We convert them into a member function call.
|
||||
// This constructor also provides implicit conversion
|
||||
FastDelegate12(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12) ) {
|
||||
bind(function_to_bind); }
|
||||
// for efficiency, prevent creation of a temporary
|
||||
void operator = (DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12) ) {
|
||||
bind(function_to_bind); }
|
||||
inline void bind(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8), Param9 p9, Param10 p10, Param11 p11, Param12 p12) {
|
||||
m_Closure.bindstaticfunc(this, &FastDelegate12::InvokeStaticFunction,
|
||||
function_to_bind); }
|
||||
// Invoke the delegate
|
||||
RetType operator() (Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12) const {
|
||||
return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11,p12); }
|
||||
// Implicit conversion to "bool" using the safe_bool idiom
|
||||
private:
|
||||
typedef struct SafeBoolStruct {
|
||||
S32 a_data_pointer_to_this_is_0_on_buggy_compilers;
|
||||
StaticFunctionPtr m_nonzero;
|
||||
} UselessTypedef;
|
||||
typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type;
|
||||
public:
|
||||
operator unspecified_bool_type() const {
|
||||
return empty()? 0: &SafeBoolStruct::m_nonzero;
|
||||
}
|
||||
// necessary to allow ==0 to work despite the safe_bool idiom
|
||||
inline bool operator==(StaticFunctionPtr funcptr) {
|
||||
return m_Closure.IsEqualToStaticFuncPtr(funcptr); }
|
||||
inline bool operator!=(StaticFunctionPtr funcptr) {
|
||||
return !m_Closure.IsEqualToStaticFuncPtr(funcptr); }
|
||||
inline bool operator ! () const { // Is it bound to anything?
|
||||
return !m_Closure; }
|
||||
inline bool empty() const {
|
||||
return !m_Closure; }
|
||||
void clear() { m_Closure.clear();}
|
||||
// Conversion to and from the DelegateMemento storage class
|
||||
const DelegateMemento & GetMemento() { return m_Closure; }
|
||||
void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); }
|
||||
|
||||
private: // Invoker for static functions
|
||||
RetType InvokeStaticFunction(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12) const {
|
||||
return (*(m_Closure.GetStaticFunction()))(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12); }
|
||||
};
|
||||
|
||||
//N=13
|
||||
template<class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class RetType=detail::DefaultVoid>
|
||||
class FastDelegate13 {
|
||||
private:
|
||||
typedef typename detail::DefaultVoidToVoid<RetType>::type DesiredRetType;
|
||||
typedef DesiredRetType (*StaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12, Param13 p13);
|
||||
typedef RetType (*UnvoidStaticFunctionPtr)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12, Param13 p13);
|
||||
typedef RetType (detail::GenericClass::*GenericMemFn)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12, Param13 p13);
|
||||
typedef detail::ClosurePtr<GenericMemFn, StaticFunctionPtr, UnvoidStaticFunctionPtr> ClosureType;
|
||||
ClosureType m_Closure;
|
||||
public:
|
||||
// Typedefs to aid generic programming
|
||||
typedef FastDelegate13 type;
|
||||
|
||||
// Construction and comparison functions
|
||||
FastDelegate13() { clear(); }
|
||||
FastDelegate13(const FastDelegate13 &x) {
|
||||
m_Closure.CopyFrom(this, x.m_Closure); }
|
||||
void operator = (const FastDelegate13 &x) {
|
||||
m_Closure.CopyFrom(this, x.m_Closure); }
|
||||
bool operator ==(const FastDelegate13 &x) const {
|
||||
return m_Closure.IsEqual(x.m_Closure); }
|
||||
bool operator !=(const FastDelegate13 &x) const {
|
||||
return !m_Closure.IsEqual(x.m_Closure); }
|
||||
bool operator <(const FastDelegate13 &x) const {
|
||||
return m_Closure.IsLess(x.m_Closure); }
|
||||
bool operator >(const FastDelegate13 &x) const {
|
||||
return x.m_Closure.IsLess(m_Closure); }
|
||||
// Binding to non-const member functions
|
||||
template < class X, class Y >
|
||||
FastDelegate13(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12, Param13 p13) ) {
|
||||
m_Closure.bindmemfunc(detail::implicit_cast<X*>(pthis), function_to_bind); }
|
||||
template < class X, class Y >
|
||||
inline void bind(Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12, Param13 p13)) {
|
||||
m_Closure.bindmemfunc(detail::implicit_cast<X*>(pthis), function_to_bind); }
|
||||
// Binding to const member functions.
|
||||
template < class X, class Y >
|
||||
FastDelegate13(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12, Param13 p13) const) {
|
||||
m_Closure.bindconstmemfunc(detail::implicit_cast<const X*>(pthis), function_to_bind); }
|
||||
template < class X, class Y >
|
||||
inline void bind(const Y *pthis, DesiredRetType (X::* function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12, Param13 p13) const) {
|
||||
m_Closure.bindconstmemfunc(detail::implicit_cast<const X *>(pthis), function_to_bind); }
|
||||
// Static functions. We convert them into a member function call.
|
||||
// This constructor also provides implicit conversion
|
||||
FastDelegate13(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12, Param13 p13) ) {
|
||||
bind(function_to_bind); }
|
||||
// for efficiency, prevent creation of a temporary
|
||||
void operator = (DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12, Param13 p13) ) {
|
||||
bind(function_to_bind); }
|
||||
inline void bind(DesiredRetType (*function_to_bind)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8), Param9 p9, Param10 p10, Param11 p11, Param12 p12, Param13 p13) {
|
||||
m_Closure.bindstaticfunc(this, &FastDelegate13::InvokeStaticFunction,
|
||||
function_to_bind); }
|
||||
// Invoke the delegate
|
||||
RetType operator() (Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12, Param13 p13) const {
|
||||
return (m_Closure.GetClosureThis()->*(m_Closure.GetClosureMemPtr()))(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11,p12,p13); }
|
||||
// Implicit conversion to "bool" using the safe_bool idiom
|
||||
private:
|
||||
typedef struct SafeBoolStruct {
|
||||
S32 a_data_pointer_to_this_is_0_on_buggy_compilers;
|
||||
StaticFunctionPtr m_nonzero;
|
||||
} UselessTypedef;
|
||||
typedef StaticFunctionPtr SafeBoolStruct::*unspecified_bool_type;
|
||||
public:
|
||||
operator unspecified_bool_type() const {
|
||||
return empty()? 0: &SafeBoolStruct::m_nonzero;
|
||||
}
|
||||
// necessary to allow ==0 to work despite the safe_bool idiom
|
||||
inline bool operator==(StaticFunctionPtr funcptr) {
|
||||
return m_Closure.IsEqualToStaticFuncPtr(funcptr); }
|
||||
inline bool operator!=(StaticFunctionPtr funcptr) {
|
||||
return !m_Closure.IsEqualToStaticFuncPtr(funcptr); }
|
||||
inline bool operator ! () const { // Is it bound to anything?
|
||||
return !m_Closure; }
|
||||
inline bool empty() const {
|
||||
return !m_Closure; }
|
||||
void clear() { m_Closure.clear();}
|
||||
// Conversion to and from the DelegateMemento storage class
|
||||
const DelegateMemento & GetMemento() { return m_Closure; }
|
||||
void SetMemento(const DelegateMemento &any) { m_Closure.CopyFrom(this, any); }
|
||||
|
||||
private: // Invoker for static functions
|
||||
RetType InvokeStaticFunction(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12, Param13 p13) const {
|
||||
return (*(m_Closure.GetStaticFunction()))(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13); }
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Fast Delegates, part 4:
|
||||
|
|
@ -1965,6 +2220,117 @@ public:
|
|||
*static_cast<BaseType*>(this) = x; }
|
||||
};
|
||||
|
||||
//N=11
|
||||
// Specialization to allow use of
|
||||
// FastDelegate< R ( Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11 ) >
|
||||
// instead of
|
||||
// FastDelegate11 < Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, R >
|
||||
template<typename R, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11>
|
||||
class FastDelegate< R ( Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11 ) >
|
||||
// Inherit from FastDelegate11 so that it can be treated just like a FastDelegate11
|
||||
: public FastDelegate11 < Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, R >
|
||||
{
|
||||
public:
|
||||
// Make using the base type a bit easier via typedef.
|
||||
typedef FastDelegate11 < Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, R > BaseType;
|
||||
|
||||
// Allow users access to the specific type of this delegate.
|
||||
typedef FastDelegate SelfType;
|
||||
|
||||
// Mimic the base class constructors.
|
||||
FastDelegate() : BaseType() { }
|
||||
|
||||
template < class X, class Y >
|
||||
FastDelegate(Y * pthis,
|
||||
R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11 ))
|
||||
: BaseType(pthis, function_to_bind) { }
|
||||
|
||||
template < class X, class Y >
|
||||
FastDelegate(const Y *pthis,
|
||||
R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11 ) const)
|
||||
: BaseType(pthis, function_to_bind)
|
||||
{ }
|
||||
|
||||
FastDelegate(R (*function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11 ))
|
||||
: BaseType(function_to_bind) { }
|
||||
void operator = (const BaseType &x) {
|
||||
*static_cast<BaseType*>(this) = x; }
|
||||
};
|
||||
|
||||
//N=12
|
||||
// Specialization to allow use of
|
||||
// FastDelegate< R ( Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12 ) >
|
||||
// instead of
|
||||
// FastDelegate12 < Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, R >
|
||||
template<typename R, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12>
|
||||
class FastDelegate< R ( Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12 ) >
|
||||
// Inherit from FastDelegate12 so that it can be treated just like a FastDelegate12
|
||||
: public FastDelegate12 < Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, R >
|
||||
{
|
||||
public:
|
||||
// Make using the base type a bit easier via typedef.
|
||||
typedef FastDelegate12 < Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, R > BaseType;
|
||||
|
||||
// Allow users access to the specific type of this delegate.
|
||||
typedef FastDelegate SelfType;
|
||||
|
||||
// Mimic the base class constructors.
|
||||
FastDelegate() : BaseType() { }
|
||||
|
||||
template < class X, class Y >
|
||||
FastDelegate(Y * pthis,
|
||||
R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12 ))
|
||||
: BaseType(pthis, function_to_bind) { }
|
||||
|
||||
template < class X, class Y >
|
||||
FastDelegate(const Y *pthis,
|
||||
R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12 ) const)
|
||||
: BaseType(pthis, function_to_bind)
|
||||
{ }
|
||||
|
||||
FastDelegate(R (*function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12 ))
|
||||
: BaseType(function_to_bind) { }
|
||||
void operator = (const BaseType &x) {
|
||||
*static_cast<BaseType*>(this) = x; }
|
||||
};
|
||||
|
||||
//N=13
|
||||
// Specialization to allow use of
|
||||
// FastDelegate< R ( Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13 ) >
|
||||
// instead of
|
||||
// FastDelegate13 < Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, R >
|
||||
template<typename R, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13>
|
||||
class FastDelegate< R ( Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13 ) >
|
||||
// Inherit from FastDelegate13 so that it can be treated just like a FastDelegate13
|
||||
: public FastDelegate13 < Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, R >
|
||||
{
|
||||
public:
|
||||
// Make using the base type a bit easier via typedef.
|
||||
typedef FastDelegate13 < Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, R > BaseType;
|
||||
|
||||
// Allow users access to the specific type of this delegate.
|
||||
typedef FastDelegate SelfType;
|
||||
|
||||
// Mimic the base class constructors.
|
||||
FastDelegate() : BaseType() { }
|
||||
|
||||
template < class X, class Y >
|
||||
FastDelegate(Y * pthis,
|
||||
R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12, Param13 p13 ))
|
||||
: BaseType(pthis, function_to_bind) { }
|
||||
|
||||
template < class X, class Y >
|
||||
FastDelegate(const Y *pthis,
|
||||
R (X::* function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12, Param13 p13 ) const)
|
||||
: BaseType(pthis, function_to_bind)
|
||||
{ }
|
||||
|
||||
FastDelegate(R (*function_to_bind)( Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12, Param13 p13 ))
|
||||
: BaseType(function_to_bind) { }
|
||||
void operator = (const BaseType &x) {
|
||||
*static_cast<BaseType*>(this) = x; }
|
||||
};
|
||||
|
||||
|
||||
#endif //FASTDELEGATE_ALLOW_FUNCTION_TYPE_SYNTAX
|
||||
|
||||
|
|
@ -2097,6 +2463,39 @@ FastDelegate8<Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, FA
|
|||
return FastDelegate8<Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, FASTDLGT_RETTYPE>(x, func);
|
||||
}
|
||||
|
||||
//N=11
|
||||
template <class X, class Y, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class RetType>
|
||||
FastDelegate11<Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, FASTDLGT_RETTYPE> MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11)) {
|
||||
return FastDelegate11<Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, FASTDLGT_RETTYPE>(x, func);
|
||||
}
|
||||
|
||||
template <class X, class Y, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class RetType>
|
||||
FastDelegate11<Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, FASTDLGT_RETTYPE> MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11) const) {
|
||||
return FastDelegate11<Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, FASTDLGT_RETTYPE>(x, func);
|
||||
}
|
||||
|
||||
//N=12
|
||||
template <class X, class Y, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class RetType>
|
||||
FastDelegate12<Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, FASTDLGT_RETTYPE> MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12)) {
|
||||
return FastDelegate12<Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, FASTDLGT_RETTYPE>(x, func);
|
||||
}
|
||||
|
||||
template <class X, class Y, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class RetType>
|
||||
FastDelegate12<Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, FASTDLGT_RETTYPE> MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12) const) {
|
||||
return FastDelegate12<Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, FASTDLGT_RETTYPE>(x, func);
|
||||
}
|
||||
|
||||
//N=13
|
||||
template <class X, class Y, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class RetType>
|
||||
FastDelegate13<Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, FASTDLGT_RETTYPE> MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12, Param13 p13)) {
|
||||
return FastDelegate13<Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, FASTDLGT_RETTYPE>(x, func);
|
||||
}
|
||||
|
||||
template <class X, class Y, class Param1, class Param2, class Param3, class Param4, class Param5, class Param6, class Param7, class Param8, class Param9, class Param10, class Param11, class Param12, class Param13, class RetType>
|
||||
FastDelegate13<Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, FASTDLGT_RETTYPE> MakeDelegate(Y* x, RetType (X::*func)(Param1 p1, Param2 p2, Param3 p3, Param4 p4, Param5 p5, Param6 p6, Param7 p7, Param8 p8, Param9 p9, Param10 p10, Param11 p11, Param12 p12, Param13 p13) const) {
|
||||
return FastDelegate13<Param1, Param2, Param3, Param4, Param5, Param6, Param7, Param8, Param9, Param10, Param11, Param12, Param13, FASTDLGT_RETTYPE>(x, func);
|
||||
}
|
||||
|
||||
|
||||
// clean up after ourselves...
|
||||
#undef FASTDLGT_RETTYPE
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
int mOffset;
|
||||
S32 mOffset;
|
||||
};
|
||||
|
||||
#endif // _UTIL_DELEGATE_H_
|
||||
|
|
@ -37,7 +37,7 @@ public:
|
|||
|
||||
volatile U8 *u8Mem = reinterpret_cast<U8 *>( memory );
|
||||
|
||||
for( int i = 0; i < size >> 2; i++ )
|
||||
for( S32 i = 0; i < size >> 2; i++ )
|
||||
{
|
||||
// g = garbage byte
|
||||
// Input: [X|Y|Z|g] (rgba)
|
||||
|
|
@ -57,7 +57,7 @@ public:
|
|||
volatile const U8 *srcU8 = reinterpret_cast<const U8 *>( source );
|
||||
volatile U8 *dstU8 = reinterpret_cast<U8 *>( destination );
|
||||
|
||||
for( int i = 0; i < size >> 2; i++ )
|
||||
for( S32 i = 0; i < size >> 2; i++ )
|
||||
{
|
||||
// g = garbage byte
|
||||
// Input: [X|Y|Z|g] (rgba)
|
||||
|
|
@ -85,13 +85,13 @@ public:
|
|||
virtual void ToBuffer( void *destination, const void *source, const dsize_t size ) const
|
||||
{
|
||||
AssertFatal( size % 3 == 0, "Bad buffer size for DXT5nm Swizzle" );
|
||||
const int pixels = size / 3;
|
||||
const S32 pixels = size / 3;
|
||||
|
||||
volatile const U8 *srcU8 = reinterpret_cast<const U8 *>( source );
|
||||
volatile U8 *dstU8 = reinterpret_cast<U8 *>( destination );
|
||||
|
||||
// destination better damn well be the right size
|
||||
for( int i = 0; i < pixels; i++ )
|
||||
for( S32 i = 0; i < pixels; i++ )
|
||||
{
|
||||
// g = garbage byte
|
||||
// Input: [X|Y|Z|g] (rgba)
|
||||
|
|
|
|||
|
|
@ -73,6 +73,33 @@ class Journal
|
|||
void dispatch() { (*ptr)(); }
|
||||
};
|
||||
|
||||
template <class A,class B,class C,class D,class E,class F,class G,class H,class I,class J,class K,class L,class M>
|
||||
struct FunctorDecl< void(*)(A,B,C,D,E,F,G,H,I,J,K,L,M) >: public Functor {
|
||||
typedef void(*FuncPtr)(A,B,C,D,E,F,G,H,I,J,K,L,M);
|
||||
FuncPtr ptr; A a; B b; C c; D d; E e; F f; G g; H h; I i; J j; K k; L l; M m;
|
||||
FunctorDecl(FuncPtr p): ptr(p) {}
|
||||
void read(Stream *file) { IOHelper::reads(file,a,b,c,d,e,f,g,h,i,j,k,l,m); }
|
||||
void dispatch() { (*ptr)(a,b,c,d,e,f,g,h,i,j,k,l,m); }
|
||||
};
|
||||
|
||||
template <class A,class B,class C,class D,class E,class F,class G,class H,class I,class J,class K,class L>
|
||||
struct FunctorDecl< void(*)(A,B,C,D,E,F,G,H,I,J,K,L) >: public Functor {
|
||||
typedef void(*FuncPtr)(A,B,C,D,E,F,G,H,I,J,K,L);
|
||||
FuncPtr ptr; A a; B b; C c; D d; E e; F f; G g; H h; I i; J j; K k; L l;
|
||||
FunctorDecl(FuncPtr p): ptr(p) {}
|
||||
void read(Stream *file) { IOHelper::reads(file,a,b,c,d,e,f,g,h,i,j,k,l); }
|
||||
void dispatch() { (*ptr)(a,b,c,d,e,f,g,h,i,j,k,l); }
|
||||
};
|
||||
|
||||
template <class A,class B,class C,class D,class E,class F,class G,class H,class I,class J,class K>
|
||||
struct FunctorDecl< void(*)(A,B,C,D,E,F,G,H,I,J,K) >: public Functor {
|
||||
typedef void(*FuncPtr)(A,B,C,D,E,F,G,H,I,J,K);
|
||||
FuncPtr ptr; A a; B b; C c; D d; E e; F f; G g; H h; I i; J j; K k;
|
||||
FunctorDecl(FuncPtr p): ptr(p) {}
|
||||
void read(Stream *file) { IOHelper::reads(file,a,b,c,d,e,f,g,h,i,j,k); }
|
||||
void dispatch() { (*ptr)(a,b,c,d,e,f,g,h,i,j,k); }
|
||||
};
|
||||
|
||||
template <class A,class B,class C,class D,class E,class F,class G,class H,class I,class J>
|
||||
struct FunctorDecl< void(*)(A,B,C,D,E,F,G,H,I,J) >: public Functor {
|
||||
typedef void(*FuncPtr)(A,B,C,D,E,F,G,H,I,J);
|
||||
|
|
@ -174,6 +201,36 @@ class Journal
|
|||
void dispatch() { (obj->*method)(); }
|
||||
};
|
||||
|
||||
template <class T,class A,class B,class C,class D,class E,class F,class G,class H,class I,class J,class K,class L,class M>
|
||||
struct MethodDecl<T*, void(T::*)(A,B,C,D,E,F,G,H,I,J,K,L,M) >: public Functor {
|
||||
typedef T* ObjPtr;
|
||||
typedef void(T::*MethodPtr)(A,B,C,D,E,F,G,H,I,J,K,L,M);
|
||||
ObjPtr obj; MethodPtr method; A a; B b; C c; D d; E e; F f; G g; H h; I i; J j; K k; L l; M m;
|
||||
MethodDecl(ObjPtr o,MethodPtr p): obj(o), method(p) {}
|
||||
void read(Stream *file) { IOHelper::reads(file,a,b,c,d,e,f,g,h,i,j,k,l,m); }
|
||||
void dispatch() { (obj->*method)(a,b,c,d,e,f,g,h,i,j,k,l,m); }
|
||||
};
|
||||
|
||||
template <class T,class A,class B,class C,class D,class E,class F,class G,class H,class I,class J,class K,class L>
|
||||
struct MethodDecl<T*, void(T::*)(A,B,C,D,E,F,G,H,I,J,K,L) >: public Functor {
|
||||
typedef T* ObjPtr;
|
||||
typedef void(T::*MethodPtr)(A,B,C,D,E,F,G,H,I,J,K,L);
|
||||
ObjPtr obj; MethodPtr method; A a; B b; C c; D d; E e; F f; G g; H h; I i; J j; K k; L l;
|
||||
MethodDecl(ObjPtr o,MethodPtr p): obj(o), method(p) {}
|
||||
void read(Stream *file) { IOHelper::reads(file,a,b,c,d,e,f,g,h,i,j,k,l); }
|
||||
void dispatch() { (obj->*method)(a,b,c,d,e,f,g,h,i,j,k,l); }
|
||||
};
|
||||
|
||||
template <class T,class A,class B,class C,class D,class E,class F,class G,class H,class I,class J,class K>
|
||||
struct MethodDecl<T*, void(T::*)(A,B,C,D,E,F,G,H,I,J,K) >: public Functor {
|
||||
typedef T* ObjPtr;
|
||||
typedef void(T::*MethodPtr)(A,B,C,D,E,F,G,H,I,J,K);
|
||||
ObjPtr obj; MethodPtr method; A a; B b; C c; D d; E e; F f; G g; H h; I i; J j; K k;
|
||||
MethodDecl(ObjPtr o,MethodPtr p): obj(o), method(p) {}
|
||||
void read(Stream *file) { IOHelper::reads(file,a,b,c,d,e,f,g,h,i,j,k); }
|
||||
void dispatch() { (obj->*method)(a,b,c,d,e,f,g,h,i,j,k); }
|
||||
};
|
||||
|
||||
template <class T,class A,class B,class C,class D,class E,class F,class G,class H,class I,class J>
|
||||
struct MethodDecl<T*, void(T::*)(A,B,C,D,E,F,G,H,I,J) >: public Functor {
|
||||
typedef T* ObjPtr;
|
||||
|
|
@ -445,6 +502,12 @@ public:
|
|||
return value; \
|
||||
}
|
||||
|
||||
template<class Func,class A,class B,class C,class D,class E,class F, class G, class H, class I, class J, class K, class L, class M>
|
||||
Method(Func,(Func func,A a,B b,C c,D d,E e,F f, G g, H h, I i, J j, K k, L l, M m),(a,b,c,d,e,f,g,h,i,j,k,l,m))
|
||||
template<class Func,class A,class B,class C,class D,class E,class F, class G, class H, class I, class J, class K, class L>
|
||||
Method(Func,(Func func,A a,B b,C c,D d,E e,F f, G g, H h, I i, J j, K k, L l),(a,b,c,d,e,f,g,h,i,j,k,l))
|
||||
template<class Func,class A,class B,class C,class D,class E,class F, class G, class H, class I, class J, class K>
|
||||
Method(Func,(Func func,A a,B b,C c,D d,E e,F f, G g, H h, I i, J j, K k),(a,b,c,d,e,f,g,h,i,j,k))
|
||||
template<class Func,class A,class B,class C,class D,class E,class F, class G, class H, class I, class J>
|
||||
Method(Func,(Func func,A a,B b,C c,D d,E e,F f, G g, H h, I i, J j),(a,b,c,d,e,f,g,h,i,j))
|
||||
template<class Func,class A,class B,class C,class D,class E,class F, class G, class H, class I>
|
||||
|
|
@ -493,6 +556,12 @@ public:
|
|||
return; \
|
||||
}
|
||||
|
||||
template<class Func,class A,class B,class C,class D,class E, class F, class G, class H, class I, class J, class K, class L, class M>
|
||||
Method((Func func,A a,B b,C c,D d,E e,F f,G g,H h,I i,J j,K k,L l,M m),(mFile,id,a,b,c,d,e,f,g,h,i,j,k,l,m),(a,b,c,d,e,f,g,h,i,j,k,l,m))
|
||||
template<class Func,class A,class B,class C,class D,class E, class F, class G, class H, class I, class J, class K, class L>
|
||||
Method((Func func,A a,B b,C c,D d,E e,F f,G g,H h,I i,J j,K k,L l),(mFile,id,a,b,c,d,e,f,g,h,i,j,k,l),(a,b,c,d,e,f,g,h,i,j,k,l))
|
||||
template<class Func,class A,class B,class C,class D,class E, class F, class G, class H, class I, class J, class K>
|
||||
Method((Func func,A a,B b,C c,D d,E e,F f,G g,H h,I i,J j,K k),(mFile,id,a,b,c,d,e,f,g,h,i,j,k),(a,b,c,d,e,f,g,h,i,j,k))
|
||||
template<class Func,class A,class B,class C,class D,class E, class F, class G, class H, class I, class J>
|
||||
Method((Func func,A a,B b,C c,D d,E e,F f,G g,H h,I i,J j),(mFile,id,a,b,c,d,e,f,g,h,i,j),(a,b,c,d,e,f,g,h,i,j))
|
||||
template<class Func,class A,class B,class C,class D,class E, class F, class G, class H, class I>
|
||||
|
|
@ -537,6 +606,12 @@ public:
|
|||
}
|
||||
|
||||
|
||||
template<class Obj,class A,class B,class C,class D,class E,class F,class G,class H,class I,class J,class K,class L,class M>
|
||||
Method((Obj* obj,void (Obj::*method)(A,B,C,D,E,F,G,H,I,J,K,L,M),A a,B b,C c,D d,E e,F f,G g,H h,I i,J j,K k,L l,M m),(mFile,id,a,b,c,d,e,f,g,h,i,j,k,l,m),(a,b,c,d,e,f,g,h,i,j,k,l,m))
|
||||
template<class Obj,class A,class B,class C,class D,class E,class F,class G,class H,class I,class J,class K,class L>
|
||||
Method((Obj* obj,void (Obj::*method)(A,B,C,D,E,F,G,H,I,J,K,L),A a,B b,C c,D d,E e,F f,G g,H h,I i,J j,K k,L l),(mFile,id,a,b,c,d,e,f,g,h,i,j,k,l),(a,b,c,d,e,f,g,h,i,j,k,l))
|
||||
template<class Obj,class A,class B,class C,class D,class E,class F,class G,class H,class I,class J,class K>
|
||||
Method((Obj* obj,void (Obj::*method)(A,B,C,D,E,F,G,H,I,J,K),A a,B b,C c,D d,E e,F f,G g,H h,I i,J j,K k),(mFile,id,a,b,c,d,e,f,g,h,i,j,k),(a,b,c,d,e,f,g,h,i,j,k))
|
||||
template<class Obj,class A,class B,class C,class D,class E,class F,class G,class H,class I,class J>
|
||||
Method((Obj* obj,void (Obj::*method)(A,B,C,D,E,F,G,H,I,J),A a,B b,C c,D d,E e,F f,G g,H h,I i,J j),(mFile,id,a,b,c,d,e,f,g,h,i,j),(a,b,c,d,e,f,g,h,i,j))
|
||||
template<class Obj,class A,class B,class C,class D,class E,class F,class G,class H,class I>
|
||||
|
|
@ -574,6 +649,12 @@ public:
|
|||
return false; \
|
||||
}
|
||||
|
||||
template<class A,class B,class C,class D,class E, class F, class G, class H,class I,class J,class K,class L,class M>
|
||||
Method((A& a,B& b,C& c,D& d,E& e, F& f, G& g, H& h, I& i,J& j,K& k,L& l,M& m),(mFile,a,b,c,d,e,f,g,h,i,j,k,l,m));
|
||||
template<class A,class B,class C,class D,class E, class F, class G, class H,class I,class J,class K,class L>
|
||||
Method((A& a,B& b,C& c,D& d,E& e, F& f, G& g, H& h, I& i,J& j,K& k,L& l),(mFile,a,b,c,d,e,f,g,h,i,j,k,l));
|
||||
template<class A,class B,class C,class D,class E, class F, class G, class H,class I,class J,class K>
|
||||
Method((A& a,B& b,C& c,D& d,E& e, F& f, G& g, H& h, I& i,J& j,K& k),(mFile,a,b,c,d,e,f,g,h,i,j,k));
|
||||
template<class A,class B,class C,class D,class E, class F, class G, class H,class I,class J>
|
||||
Method((A& a,B& b,C& c,D& d,E& e, F& f, G& g, H& h, I& i,J& j),(mFile,a,b,c,d,e,f,g,h,i,j));
|
||||
template<class A,class B,class C,class D,class E, class F, class G, class H,class I>
|
||||
|
|
@ -608,6 +689,12 @@ public:
|
|||
return false; \
|
||||
}
|
||||
|
||||
template<class A,class B,class C,class D,class E, class F, class G, class H, class I, class J, class K,class L,class M>
|
||||
Method((A& a,B& b,C& c,D& d,E& e,F& f,G& g, H& h, I& i, J& j, K& k, L& l, M& m),(mFile,a,b,c,d,e,f,g,h,i,j,k,l,m));
|
||||
template<class A,class B,class C,class D,class E, class F, class G, class H, class I, class J, class K,class L>
|
||||
Method((A& a,B& b,C& c,D& d,E& e,F& f,G& g, H& h, I& i, J& j, K& k, L& l),(mFile,a,b,c,d,e,f,g,h,i,j,k,l));
|
||||
template<class A,class B,class C,class D,class E, class F, class G, class H, class I, class J, class K>
|
||||
Method((A& a,B& b,C& c,D& d,E& e,F& f,G& g, H& h, I& i, J& j, K& k),(mFile,a,b,c,d,e,f,g,h,i,j,k));
|
||||
template<class A,class B,class C,class D,class E, class F, class G, class H, class I, class J>
|
||||
Method((A& a,B& b,C& c,D& d,E& e,F& f,G& g, H& h, I& i, J& j),(mFile,a,b,c,d,e,f,g,h,i,j));
|
||||
template<class A,class B,class C,class D,class E, class F, class G, class H, class I>
|
||||
|
|
|
|||
|
|
@ -243,6 +243,75 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
/// @copydoc JournaledSignal<void()>
|
||||
template<class A, class B, class C, class D, class E, class F, class G, class H, class I, class J, class K>
|
||||
class JournaledSignal<void(A,B,C,D,E,F,G,H,I,J,K)> : public Signal<void(A,B,C,D,E,F,G,H,I,J,K)>
|
||||
{
|
||||
typedef Signal<void(A,B,C,D,E,F,G,H,I,J,K)> Parent;
|
||||
|
||||
public:
|
||||
JournaledSignal()
|
||||
{
|
||||
Journal::DeclareFunction((Parent*)this, &Parent::trigger);
|
||||
}
|
||||
|
||||
~JournaledSignal()
|
||||
{
|
||||
Journal::RemoveFunction((Parent*)this, &Parent::trigger);
|
||||
}
|
||||
|
||||
void trigger(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k)
|
||||
{
|
||||
Journal::Call((Parent*)this, &Parent::trigger, a, b, c, d, e, f, g, h, i, j, k);
|
||||
}
|
||||
};
|
||||
|
||||
/// @copydoc JournaledSignal<void()>
|
||||
template<class A, class B, class C, class D, class E, class F, class G, class H, class I, class J, class K, class L>
|
||||
class JournaledSignal<void(A,B,C,D,E,F,G,H,I,J,K,L)> : public Signal<void(A,B,C,D,E,F,G,H,I,J,K,L)>
|
||||
{
|
||||
typedef Signal<void(A,B,C,D,E,F,G,H,I,J,K,L)> Parent;
|
||||
|
||||
public:
|
||||
JournaledSignal()
|
||||
{
|
||||
Journal::DeclareFunction((Parent*)this, &Parent::trigger);
|
||||
}
|
||||
|
||||
~JournaledSignal()
|
||||
{
|
||||
Journal::RemoveFunction((Parent*)this, &Parent::trigger);
|
||||
}
|
||||
|
||||
void trigger(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l)
|
||||
{
|
||||
Journal::Call((Parent*)this, &Parent::trigger, a, b, c, d, e, f, g, h, i, j, k, l);
|
||||
}
|
||||
};
|
||||
|
||||
/// @copydoc JournaledSignal<void()>
|
||||
template<class A, class B, class C, class D, class E, class F, class G, class H, class I, class J, class K, class L, class M>
|
||||
class JournaledSignal<void(A,B,C,D,E,F,G,H,I,J,K,L,M)> : public Signal<void(A,B,C,D,E,F,G,H,I,J,K,L,M)>
|
||||
{
|
||||
typedef Signal<void(A,B,C,D,E,F,G,H,I,J,K,L,M)> Parent;
|
||||
|
||||
public:
|
||||
JournaledSignal()
|
||||
{
|
||||
Journal::DeclareFunction((Parent*)this, &Parent::trigger);
|
||||
}
|
||||
|
||||
~JournaledSignal()
|
||||
{
|
||||
Journal::RemoveFunction((Parent*)this, &Parent::trigger);
|
||||
}
|
||||
|
||||
void trigger(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m)
|
||||
{
|
||||
Journal::Call((Parent*)this, &Parent::trigger, a, b, c, d, e, f, g, h, i, j, k, l, m);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Common event callbacks definitions
|
||||
|
|
@ -325,8 +394,8 @@ typedef JournaledSignal<void(WindowId, S32, S32)> ResizeEvent;
|
|||
/// void event(S32 timeDelta)
|
||||
typedef JournaledSignal<void(S32)> TimeManagerEvent;
|
||||
|
||||
// void event(U32 deviceInst,F32 fValue, U16 deviceType, U16 objType, U16 ascii, U16 objInst, U8 action, U8 modifier)
|
||||
typedef JournaledSignal<void(U32,F32,U16,U16,U16,U16,U8,U8)> InputEvent;
|
||||
// void event(U32 deviceInst, F32 fValue, F32 fValue2, F32 fValue3, F32 fValue4, S32 iValue, U16 deviceType, U16 objType, U16 ascii, U16 objInst, U8 action, U8 modifier)
|
||||
typedef JournaledSignal<void(U32,F32,F32,F32,F32,S32,U16,U16,U16,U16,U8,U8)> InputEvent;
|
||||
|
||||
/// void event(U32 popupGUID, U32 commandID, bool& returnValue)
|
||||
typedef JournaledSignal<void(U32, U32)> PopupMenuEvent;
|
||||
|
|
|
|||
|
|
@ -96,6 +96,11 @@ public:
|
|||
get()._signalProcess.notify(del,order);
|
||||
}
|
||||
|
||||
static void notify(SignalSlot<void()> &slot, F32 order = PROCESS_DEFAULT_ORDER)
|
||||
{
|
||||
get()._signalProcess.notify(slot,order);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static void notify(T func, F32 order = PROCESS_DEFAULT_ORDER)
|
||||
{
|
||||
|
|
|
|||
189
Engine/source/core/util/journal/test/journalTest.cpp
Normal file
189
Engine/source/core/util/journal/test/journalTest.cpp
Normal file
|
|
@ -0,0 +1,189 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 "core/util/journal/journaledSignal.h"
|
||||
#include "core/util/safeDelete.h"
|
||||
|
||||
FIXTURE(Journal)
|
||||
{
|
||||
public:
|
||||
// Used for basic API test.
|
||||
struct receiver
|
||||
{
|
||||
U16 lastTriggerValue;
|
||||
void trigger(U16 msg)
|
||||
{
|
||||
lastTriggerValue = msg;
|
||||
}
|
||||
};
|
||||
|
||||
// Used for non-basic test.
|
||||
typedef JournaledSignal<void(U32, U16)> EventA;
|
||||
typedef JournaledSignal<void(U8, S8)> EventB;
|
||||
typedef JournaledSignal<void(U32, S32)> EventC;
|
||||
|
||||
// Root, non-dynamic signal receiver.
|
||||
struct multiReceiver {
|
||||
U32 recvA, recvB, recvC;
|
||||
|
||||
EventA *dynamicA;
|
||||
EventB *dynamicB;
|
||||
EventC *dynamicC;
|
||||
|
||||
void receiverRoot(U8 msg)
|
||||
{
|
||||
if(msg==1)
|
||||
{
|
||||
dynamicA = new EventA();
|
||||
dynamicA->notify(this, &multiReceiver::receiverA);
|
||||
}
|
||||
|
||||
if(msg==2)
|
||||
{
|
||||
dynamicB = new EventB();
|
||||
dynamicB->notify(this, &multiReceiver::receiverB);
|
||||
}
|
||||
|
||||
if(msg==3)
|
||||
{
|
||||
dynamicC = new EventC();
|
||||
dynamicC->notify(this, &multiReceiver::receiverC);
|
||||
}
|
||||
}
|
||||
|
||||
void receiverA(U32, U16 d)
|
||||
{
|
||||
recvA += d;
|
||||
}
|
||||
|
||||
void receiverB(U8, S8 d)
|
||||
{
|
||||
recvB += d;
|
||||
}
|
||||
|
||||
void receiverC(U32, S32 d)
|
||||
{
|
||||
recvC += d;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
TEST_FIX(Journal, BasicAPI)
|
||||
{
|
||||
receiver rec;
|
||||
rec.lastTriggerValue = 0;
|
||||
|
||||
// Set up a journaled signal to test with.
|
||||
JournaledSignal<void(U16)> testEvent;
|
||||
testEvent.notify(&rec, &receiver::trigger);
|
||||
|
||||
// Initialize journal recording and fire off some events...
|
||||
Journal::Record("test.jrn");
|
||||
ASSERT_TRUE(Journal::IsRecording());
|
||||
|
||||
testEvent.trigger(16);
|
||||
testEvent.trigger(17);
|
||||
testEvent.trigger(18);
|
||||
|
||||
EXPECT_EQ(rec.lastTriggerValue, 18)
|
||||
<< "Should encounter last triggered value (18).";
|
||||
|
||||
Journal::Stop();
|
||||
ASSERT_FALSE(Journal::IsRecording());
|
||||
|
||||
// Clear it...
|
||||
rec.lastTriggerValue = 0;
|
||||
|
||||
// and play back - should get same thing.
|
||||
Journal::Play("test.jrn");
|
||||
|
||||
// Since we fired 3 events, it should take three loops.
|
||||
EXPECT_TRUE(Journal::PlayNext()) << "Should be two more events.";
|
||||
EXPECT_TRUE(Journal::PlayNext()) << "Should be one more event.";
|
||||
EXPECT_FALSE(Journal::PlayNext()) << "Should be no more events.";
|
||||
|
||||
EXPECT_EQ(rec.lastTriggerValue, 18)
|
||||
<< "Should encounter last journaled value (18).";
|
||||
}
|
||||
|
||||
TEST_FIX(Journal, DynamicSignals)
|
||||
{
|
||||
multiReceiver rec;
|
||||
|
||||
// Reset our state values.
|
||||
rec.recvA = rec.recvB = rec.recvC = 0;
|
||||
|
||||
// Set up a signal to start with.
|
||||
JournaledSignal<void(U8)> testEvent;
|
||||
testEvent.notify(&rec, &multiReceiver::receiverRoot);
|
||||
|
||||
// Initialize journal recording and fire off some events...
|
||||
Journal::Record("test.jrn");
|
||||
ASSERT_TRUE(Journal::IsRecording());
|
||||
|
||||
testEvent.trigger(1);
|
||||
rec.dynamicA->trigger(8, 100);
|
||||
testEvent.trigger(2);
|
||||
rec.dynamicA->trigger(8, 8);
|
||||
rec.dynamicB->trigger(9, 'a');
|
||||
testEvent.trigger(3);
|
||||
SAFE_DELETE(rec.dynamicB); // Test a deletion.
|
||||
rec.dynamicC->trigger(8, 1);
|
||||
rec.dynamicC->trigger(8, 1);
|
||||
|
||||
// Did we end up with expected values? Check before clearing.
|
||||
EXPECT_EQ(rec.recvA, 108) << "recvA wasn't 108 - something broken in signals?";
|
||||
EXPECT_EQ(rec.recvB, 'a') << "recvB wasn't 'a' - something broken in signals?";
|
||||
EXPECT_EQ(rec.recvC, 2) << "recvC wasn't 2 - something broken in signals?";
|
||||
|
||||
// Reset our state values.
|
||||
rec.recvA = rec.recvB = rec.recvC = 0;
|
||||
|
||||
// And kill the journal...
|
||||
Journal::Stop();
|
||||
|
||||
// Also kill our remaining dynamic signals.
|
||||
SAFE_DELETE(rec.dynamicA);
|
||||
SAFE_DELETE(rec.dynamicB);
|
||||
SAFE_DELETE(rec.dynamicC);
|
||||
|
||||
// Play back - should get same thing.
|
||||
Journal::Play("test.jrn");
|
||||
|
||||
// Since we fired 8 events, it should take 7+1=8 loops.
|
||||
for(S32 i = 0; i < 7; i++)
|
||||
{
|
||||
EXPECT_TRUE(Journal::PlayNext())
|
||||
<< "Should be more events.";
|
||||
}
|
||||
|
||||
EXPECT_FALSE(Journal::PlayNext())
|
||||
<< "Should be no more events.";
|
||||
|
||||
EXPECT_EQ(rec.recvA, 108) << "recvA wasn't 108 - something broken in journal?";
|
||||
EXPECT_EQ(rec.recvB, 'a') << "recvB wasn't 'a' - something broken in journal?";
|
||||
EXPECT_EQ(rec.recvC, 2) << "recvC wasn't 2 - something broken in journal?";
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
// 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
|
||||
|
|
@ -20,37 +20,41 @@
|
|||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "unit/test.h"
|
||||
#ifdef TORQUE_TESTS_ENABLED
|
||||
#include "testing/unitTesting.h"
|
||||
#include "core/util/journal/process.h"
|
||||
#include "core/util/safeDelete.h"
|
||||
|
||||
using namespace UnitTesting;
|
||||
|
||||
CreateUnitTest(TestingProcess, "Journal/Process")
|
||||
FIXTURE(Process)
|
||||
{
|
||||
// How many ticks remaining?
|
||||
U32 _remainingTicks;
|
||||
|
||||
// Callback for process list.
|
||||
void process()
|
||||
public:
|
||||
U32 remainingTicks;
|
||||
void notification()
|
||||
{
|
||||
if(_remainingTicks==0)
|
||||
if(remainingTicks == 0)
|
||||
Process::requestShutdown();
|
||||
|
||||
_remainingTicks--;
|
||||
remainingTicks--;
|
||||
}
|
||||
};
|
||||
|
||||
void run()
|
||||
TEST_FIX(Process, BasicAPI)
|
||||
{
|
||||
// We'll run 30 ticks, then quit.
|
||||
remainingTicks = 30;
|
||||
|
||||
// Register with the process list.
|
||||
Process::notify(this, &ProcessFixture::notification);
|
||||
|
||||
// And do 30 notifies, making sure we end on the 30th.
|
||||
for(S32 i = 0; i < 30; i++)
|
||||
{
|
||||
// We'll run 30 ticks, then quit.
|
||||
_remainingTicks = 30;
|
||||
|
||||
// Register with the process list.
|
||||
Process::notify(this, &TestingProcess::process);
|
||||
|
||||
// And do 30 notifies, making sure we end on the 30th.
|
||||
for(S32 i=0; i<30; i++)
|
||||
test(Process::processEvents(), "Should quit after 30 ProcessEvents() calls - not before!");
|
||||
test(!Process::processEvents(), "Should quit after the 30th ProcessEvent() call!");
|
||||
EXPECT_TRUE(Process::processEvents())
|
||||
<< "Should quit after 30 ProcessEvents() calls - not before!";
|
||||
}
|
||||
};
|
||||
|
||||
EXPECT_FALSE(Process::processEvents())
|
||||
<< "Should quit after the 30th ProcessEvent() call!";
|
||||
|
||||
Process::remove(this, &ProcessFixture::notification);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,173 +0,0 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 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.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "unit/test.h"
|
||||
#include "core/util/journal/journaledSignal.h"
|
||||
#include "core/util/safeDelete.h"
|
||||
|
||||
using namespace UnitTesting;
|
||||
|
||||
CreateUnitTest(TestsJournalRecordAndPlayback, "Journal/Basic")
|
||||
{
|
||||
U32 _lastTriggerValue;
|
||||
|
||||
void triggerReceiver(U16 msg)
|
||||
{
|
||||
_lastTriggerValue = msg;
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
// Reset the last trigger value just in case...
|
||||
_lastTriggerValue = 0;
|
||||
|
||||
// Set up a journaled signal to test with.
|
||||
JournaledSignal<void(U16)> testEvent;
|
||||
|
||||
testEvent.notify(this, &TestsJournalRecordAndPlayback::triggerReceiver);
|
||||
|
||||
// Initialize journal recording and fire off some events...
|
||||
Journal::Record("test.jrn");
|
||||
|
||||
testEvent.trigger(16);
|
||||
testEvent.trigger(17);
|
||||
testEvent.trigger(18);
|
||||
|
||||
test(_lastTriggerValue == 18, "Should encounter last triggered value (18).");
|
||||
|
||||
Journal::Stop();
|
||||
|
||||
// Clear it...
|
||||
_lastTriggerValue = 0;
|
||||
|
||||
// and play back - should get same thing.
|
||||
Journal::Play("test.jrn");
|
||||
|
||||
// Since we fired 3 events, it should take three loops.
|
||||
test(Journal::PlayNext(), "Should be two more events.");
|
||||
test(Journal::PlayNext(), "Should be one more event.");
|
||||
test(!Journal::PlayNext(), "Should be no more events.");
|
||||
|
||||
test(_lastTriggerValue == 18, "Should encounter last journaled value (18).");
|
||||
}
|
||||
};
|
||||
|
||||
CreateUnitTest(TestsJournalDynamicSignals, "Journal/DynamicSignals")
|
||||
{
|
||||
typedef JournaledSignal<void(U32, U16)> EventA;
|
||||
typedef JournaledSignal<void(U8, S8)> EventB;
|
||||
typedef JournaledSignal<void(U32, S32)> EventC;
|
||||
|
||||
EventA *dynamicA;
|
||||
EventB *dynamicB;
|
||||
EventC *dynamicC;
|
||||
|
||||
// Root, non-dynamic signal receiver.
|
||||
void receiverRoot(U8 msg)
|
||||
{
|
||||
if(msg==1)
|
||||
{
|
||||
dynamicA = new EventA();
|
||||
dynamicA->notify(this, &TestsJournalDynamicSignals::receiverA);
|
||||
}
|
||||
|
||||
if(msg==2)
|
||||
{
|
||||
dynamicB = new EventB();
|
||||
dynamicB->notify(this, &TestsJournalDynamicSignals::receiverB);
|
||||
}
|
||||
|
||||
if(msg==3)
|
||||
{
|
||||
dynamicC = new EventC();
|
||||
dynamicC->notify(this, &TestsJournalDynamicSignals::receiverC);
|
||||
}
|
||||
}
|
||||
|
||||
U32 recvA, recvB, recvC;
|
||||
|
||||
void receiverA(U32, U16 d)
|
||||
{
|
||||
recvA += d;
|
||||
}
|
||||
|
||||
void receiverB(U8, S8 d)
|
||||
{
|
||||
recvB += d;
|
||||
}
|
||||
|
||||
void receiverC(U32, S32 d)
|
||||
{
|
||||
recvC += d;
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
// Reset our state values.
|
||||
recvA = recvB = recvC = 0;
|
||||
|
||||
// Set up a signal to start with.
|
||||
JournaledSignal<void(U8)> testEvent;
|
||||
testEvent.notify(this, &TestsJournalDynamicSignals::receiverRoot);
|
||||
|
||||
// Initialize journal recording and fire off some events...
|
||||
Journal::Record("test.jrn");
|
||||
|
||||
testEvent.trigger(1);
|
||||
dynamicA->trigger(8, 100);
|
||||
testEvent.trigger(2);
|
||||
dynamicA->trigger(8, 8);
|
||||
dynamicB->trigger(9, 'a');
|
||||
testEvent.trigger(3);
|
||||
SAFE_DELETE(dynamicB); // Test a deletion.
|
||||
dynamicC->trigger(8, 1);
|
||||
dynamicC->trigger(8, 1);
|
||||
|
||||
// Did we end up with expected values? Check before clearing.
|
||||
test(recvA == 108, "recvA wasn't 108 - something broken in signals?");
|
||||
test(recvB == 'a', "recvB wasn't 'a' - something broken in signals?");
|
||||
test(recvC == 2, "recvC wasn't 2 - something broken in signals?");
|
||||
|
||||
// Reset our state values.
|
||||
recvA = recvB = recvC = 0;
|
||||
|
||||
// And kill the journal...
|
||||
Journal::Stop();
|
||||
|
||||
// Also kill our remaining dynamic signals.
|
||||
SAFE_DELETE(dynamicA);
|
||||
SAFE_DELETE(dynamicB);
|
||||
SAFE_DELETE(dynamicC);
|
||||
|
||||
// Play back - should get same thing.
|
||||
Journal::Play("test.jrn");
|
||||
|
||||
// Since we fired 8 events, it should take 7+1=8 loops.
|
||||
for(S32 i=0; i<7; i++)
|
||||
test(Journal::PlayNext(), "Should be more events.");
|
||||
test(!Journal::PlayNext(), "Should be no more events.");
|
||||
|
||||
test(recvA == 108, "recvA wasn't 108 - something broken in journal?");
|
||||
test(recvB == 'a', "recvB wasn't 'a' - something broken in journal?");
|
||||
test(recvC == 2, "recvC wasn't 2 - something broken in journal?");
|
||||
}
|
||||
};
|
||||
|
|
@ -154,7 +154,7 @@ void MD5Final( unsigned char digest[16], MD5Context* ctx)
|
|||
MD5Transform(ctx->buf, (int *) ctx->in);
|
||||
byteReverse((unsigned char *) ctx->buf, 4);
|
||||
memcpy(digest, ctx->buf, 16);
|
||||
memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
|
||||
memset(ctx, 0, sizeof(MD5Context)); /* In case it's sensitive */
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ void Path::_split(String name)
|
|||
idx = name.find('/', 0, String::Right);
|
||||
if (idx >= pos)
|
||||
{
|
||||
int len = idx - pos;
|
||||
S32 len = idx - pos;
|
||||
mPath = name.substr(pos,len? len: 1);
|
||||
mPath = Path::CleanSeparators(mPath);
|
||||
pos = idx + 1;
|
||||
|
|
@ -408,7 +408,7 @@ String Path::getDirectory(U32 count) const
|
|||
|
||||
U32 end = offset;
|
||||
|
||||
while (mPath[end] != '/' && end < mPath.length())
|
||||
while (end < mPath.length() && mPath[end] != '/')
|
||||
end++;
|
||||
|
||||
return mPath.substr(offset,end - offset);
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class Path
|
|||
public:
|
||||
enum Separator
|
||||
{
|
||||
#if defined(TORQUE_OS_WIN32) || defined(TORQUE_OS_XENON)
|
||||
#if defined(TORQUE_OS_WIN) || defined(TORQUE_OS_XENON)
|
||||
OsSeparator = '\\'
|
||||
#else
|
||||
OsSeparator = '/'
|
||||
|
|
|
|||
|
|
@ -760,7 +760,7 @@ String& String::operator=(const String &src)
|
|||
|
||||
String& String::operator+=(const StringChar *src)
|
||||
{
|
||||
if( src == NULL && !*src )
|
||||
if( src == NULL || !*src )
|
||||
return *this;
|
||||
|
||||
// Append the given string into a new string
|
||||
|
|
@ -1419,7 +1419,7 @@ void String::copy(StringChar* dst, const StringChar *src, U32 len)
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#if defined(TORQUE_OS_WIN32) || defined(TORQUE_OS_XBOX) || defined(TORQUE_OS_XENON)
|
||||
#if defined(TORQUE_OS_WIN) || defined(TORQUE_OS_XBOX) || defined(TORQUE_OS_XENON)
|
||||
// This standard function is not defined when compiling with VC7...
|
||||
#define vsnprintf _vsnprintf
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -126,11 +126,11 @@ inline void Swizzle<T, mapLength>::ToBuffer( void *destination, const void *sour
|
|||
T *dest = reinterpret_cast<T *>( destination );
|
||||
const T *src = reinterpret_cast<const T *>( source );
|
||||
|
||||
for( int i = 0; i < size / ( mapLength * sizeof( T ) ); i++ )
|
||||
for( S32 i = 0; i < size / ( mapLength * sizeof( T ) ); i++ )
|
||||
{
|
||||
dMemcpy( dest, src, mapLength * sizeof( T ) );
|
||||
|
||||
for( int j = 0; j < mapLength; j++ )
|
||||
for( S32 j = 0; j < mapLength; j++ )
|
||||
*dest++ = src[mMap[j]];
|
||||
|
||||
src += mapLength;
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ inline void Swizzle<U8, 4>::InPlace( void *memory, const dsize_t size ) const
|
|||
U8 *src = reinterpret_cast<U8 *>( memory );
|
||||
|
||||
// Fast divide by 4 since we are assured a proper size
|
||||
for( int i = 0; i < size >> 2; i++ )
|
||||
for( S32 i = 0; i < size >> 2; i++ )
|
||||
{
|
||||
BYTESWAP( *dest++, src[mMap[0]] );
|
||||
BYTESWAP( *dest++, src[mMap[1]] );
|
||||
|
|
@ -57,7 +57,7 @@ inline void Swizzle<U8, 4>::ToBuffer( void *destination, const void *source, con
|
|||
const U8 *src = reinterpret_cast<const U8 *>( source );
|
||||
|
||||
// Fast divide by 4 since we are assured a proper size
|
||||
for( int i = 0; i < size >> 2; i++ )
|
||||
for( S32 i = 0; i < size >> 2; i++ )
|
||||
{
|
||||
*dest++ = src[mMap[0]];
|
||||
*dest++ = src[mMap[1]];
|
||||
|
|
@ -80,7 +80,7 @@ inline void Swizzle<U8, 3>::InPlace( void *memory, const dsize_t size ) const
|
|||
U8 *dest = reinterpret_cast<U8 *>( memory );
|
||||
U8 *src = reinterpret_cast<U8 *>( memory );
|
||||
|
||||
for( int i = 0; i < size /3; i++ )
|
||||
for( S32 i = 0; i < size /3; i++ )
|
||||
{
|
||||
BYTESWAP( *dest++, src[mMap[0]] );
|
||||
BYTESWAP( *dest++, src[mMap[1]] );
|
||||
|
|
@ -98,7 +98,7 @@ inline void Swizzle<U8, 3>::ToBuffer( void *destination, const void *source, con
|
|||
U8 *dest = reinterpret_cast<U8 *>( destination );
|
||||
const U8 *src = reinterpret_cast<const U8 *>( source );
|
||||
|
||||
for( int i = 0; i < size / 3; i++ )
|
||||
for( S32 i = 0; i < size / 3; i++ )
|
||||
{
|
||||
*dest++ = src[mMap[0]];
|
||||
*dest++ = src[mMap[1]];
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
|
||||
/// A vector with a compile-time constant size.
|
||||
template< typename T, int SIZE >
|
||||
template< typename T, S32 SIZE >
|
||||
class FixedSizeVector
|
||||
{
|
||||
protected:
|
||||
|
|
@ -46,19 +46,19 @@ class FixedSizeVector
|
|||
FixedSizeVector( const T& a, const T& b, const T& c, const T& d, const T& e, const T& f )
|
||||
{ mArray[ 0 ] = a; mArray[ 1 ] = b; mArray[ 2 ] = c; mArray[ 3 ] = d; mArray[ 4 ] = e; mArray[ 5 ] = f; }
|
||||
FixedSizeVector( const T& a, const T& b, const T& c, const T& d, const T& e, const T& f, const T& g )
|
||||
{ mArray[ 0 ] = a; mArray[ 1 ] = b; mArray[ 2 ] = c; mArray[ 3 ] = d; mArray[ 4 ] = e; mArray[ 5 ] = f; mArray[ 6 ]; }
|
||||
{ mArray[ 0 ] = a; mArray[ 1 ] = b; mArray[ 2 ] = c; mArray[ 3 ] = d; mArray[ 4 ] = e; mArray[ 5 ] = f; mArray[ 6 ] = g; }
|
||||
FixedSizeVector( const T& a, const T& b, const T& c, const T& d, const T& e, const T& f, const T& g, const T& h )
|
||||
{ mArray[ 0 ] = a; mArray[ 1 ] = b; mArray[ 2 ] = c; mArray[ 3 ] = d; mArray[ 4 ] = e; mArray[ 5 ] = f; mArray[ 6 ]; mArray[ 7 ] = h; }
|
||||
{ mArray[ 0 ] = a; mArray[ 1 ] = b; mArray[ 2 ] = c; mArray[ 3 ] = d; mArray[ 4 ] = e; mArray[ 5 ] = f; mArray[ 6 ] = g; mArray[ 7 ] = h; }
|
||||
FixedSizeVector( const T& a, const T& b, const T& c, const T& d, const T& e, const T& f, const T& g, const T& h, const T& i )
|
||||
{ mArray[ 0 ] = a; mArray[ 1 ] = b; mArray[ 2 ] = c; mArray[ 3 ] = d; mArray[ 4 ] = e; mArray[ 5 ] = f; mArray[ 6 ]; mArray[ 7 ] = h; mArray[ 8 ] = i; }
|
||||
{ mArray[ 0 ] = a; mArray[ 1 ] = b; mArray[ 2 ] = c; mArray[ 3 ] = d; mArray[ 4 ] = e; mArray[ 5 ] = f; mArray[ 6 ] = g; mArray[ 7 ] = h; mArray[ 8 ] = i; }
|
||||
FixedSizeVector( const T& a, const T& b, const T& c, const T& d, const T& e, const T& f, const T& g, const T& h, const T& i, const T& j )
|
||||
{ mArray[ 0 ] = a; mArray[ 1 ] = b; mArray[ 2 ] = c; mArray[ 3 ] = d; mArray[ 4 ] = e; mArray[ 5 ] = f; mArray[ 6 ]; mArray[ 7 ] = h; mArray[ 8 ] = i; mArray[ 9 ] = j; }
|
||||
{ mArray[ 0 ] = a; mArray[ 1 ] = b; mArray[ 2 ] = c; mArray[ 3 ] = d; mArray[ 4 ] = e; mArray[ 5 ] = f; mArray[ 6 ] = g; mArray[ 7 ] = h; mArray[ 8 ] = i; mArray[ 9 ] = j; }
|
||||
FixedSizeVector( const T& a, const T& b, const T& c, const T& d, const T& e, const T& f, const T& g, const T& h, const T& i, const T& j, const T& k )
|
||||
{ mArray[ 0 ] = a; mArray[ 1 ] = b; mArray[ 2 ] = c; mArray[ 3 ] = d; mArray[ 4 ] = e; mArray[ 5 ] = f; mArray[ 6 ]; mArray[ 7 ] = h; mArray[ 8 ] = i; mArray[ 9 ] = j; mArray[ 10 ] = k; }
|
||||
{ mArray[ 0 ] = a; mArray[ 1 ] = b; mArray[ 2 ] = c; mArray[ 3 ] = d; mArray[ 4 ] = e; mArray[ 5 ] = f; mArray[ 6 ] = g; mArray[ 7 ] = h; mArray[ 8 ] = i; mArray[ 9 ] = j; mArray[ 10 ] = k; }
|
||||
FixedSizeVector( const T& a, const T& b, const T& c, const T& d, const T& e, const T& f, const T& g, const T& h, const T& i, const T& j, const T& k, const T& l )
|
||||
{ mArray[ 0 ] = a; mArray[ 1 ] = b; mArray[ 2 ] = c; mArray[ 3 ] = d; mArray[ 4 ] = e; mArray[ 5 ] = f; mArray[ 6 ]; mArray[ 7 ] = h; mArray[ 8 ] = i; mArray[ 9 ] = j; mArray[ 10 ] = k; mArray[ 11 ] = l; }
|
||||
{ mArray[ 0 ] = a; mArray[ 1 ] = b; mArray[ 2 ] = c; mArray[ 3 ] = d; mArray[ 4 ] = e; mArray[ 5 ] = f; mArray[ 6 ] = g; mArray[ 7 ] = h; mArray[ 8 ] = i; mArray[ 9 ] = j; mArray[ 10 ] = k; mArray[ 11 ] = l; }
|
||||
FixedSizeVector( const T& a, const T& b, const T& c, const T& d, const T& e, const T& f, const T& g, const T& h, const T& i, const T& j, const T& k, const T& l, const T& m )
|
||||
{ mArray[ 0 ] = a; mArray[ 1 ] = b; mArray[ 2 ] = c; mArray[ 3 ] = d; mArray[ 4 ] = e; mArray[ 5 ] = f; mArray[ 6 ]; mArray[ 7 ] = h; mArray[ 8 ] = i; mArray[ 9 ] = j; mArray[ 10 ] = k; mArray[ 11 ] = l; mArray[ 12 ] =m; }
|
||||
{ mArray[ 0 ] = a; mArray[ 1 ] = b; mArray[ 2 ] = c; mArray[ 3 ] = d; mArray[ 4 ] = e; mArray[ 5 ] = f; mArray[ 6 ] = g; mArray[ 7 ] = h; mArray[ 8 ] = i; mArray[ 9 ] = j; mArray[ 10 ] = k; mArray[ 11 ] = l; mArray[ 12 ] =m; }
|
||||
|
||||
U32 size() const { return SIZE; }
|
||||
bool empty() const { return ( SIZE == 0 ); }
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
#include "core/util/tSignal.h"
|
||||
|
||||
|
||||
void SignalBase::DelegateLink::insert(DelegateLink* node, float order)
|
||||
void SignalBase::DelegateLink::insert(DelegateLink* node, F32 order)
|
||||
{
|
||||
// Note: can only legitimately be called on list head
|
||||
DelegateLink * walk = next;
|
||||
|
|
|
|||
|
|
@ -54,7 +54,6 @@ public:
|
|||
{
|
||||
mList.next = mList.prev = &mList;
|
||||
mList.order = 0.5f;
|
||||
mTriggerNext = NULL;
|
||||
}
|
||||
|
||||
~SignalBase();
|
||||
|
|
@ -77,6 +76,8 @@ protected:
|
|||
|
||||
void insert(DelegateLink* node, F32 order);
|
||||
void unlink();
|
||||
|
||||
virtual ~DelegateLink() {}
|
||||
};
|
||||
|
||||
DelegateLink mList;
|
||||
|
|
@ -92,6 +93,78 @@ protected:
|
|||
Vector<DelegateLink*> mTriggerNext;
|
||||
};
|
||||
|
||||
template<typename Signature> class SignalBaseT;
|
||||
|
||||
/// Class for handle automatic diconnect form Signal when destroyed
|
||||
template< typename Signature >
|
||||
class SignalSlot
|
||||
{
|
||||
public:
|
||||
typedef Delegate< Signature > DelegateSig;
|
||||
typedef SignalBaseT< Signature > SignalSig;
|
||||
|
||||
SignalSlot() : mSignal(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
~SignalSlot()
|
||||
{
|
||||
disconnect();
|
||||
}
|
||||
|
||||
const DelegateSig& getDelegate() { return mDlg; }
|
||||
|
||||
/// setDelegate disconect form Signal old delegate and connect new delegate
|
||||
template<typename X>
|
||||
void setDelegate( const X &fn ) { setDelegate( DelegateSig( fn ) ); }
|
||||
|
||||
template<typename X, typename Y>
|
||||
void setDelegate( const X &ptr, const Y &fn ) { setDelegate( DelegateSig( ptr, fn ) ); }
|
||||
|
||||
void setDelegate( const DelegateSig &dlg)
|
||||
{
|
||||
SignalSig* signal = mSignal;
|
||||
if( isConnected() )
|
||||
disconnect();
|
||||
|
||||
mDlg = dlg;
|
||||
if( signal && mDlg )
|
||||
signal->notify( mDlg );
|
||||
}
|
||||
|
||||
/// is connected to Signal
|
||||
bool isConnected() const { return mSignal; }
|
||||
|
||||
/// disconnect from Signal
|
||||
void disconnect()
|
||||
{
|
||||
if( mSignal )
|
||||
{
|
||||
SignalSig *oldSignal = mSignal;
|
||||
mSignal = NULL;
|
||||
oldSignal->remove( mDlg );
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
friend class SignalBaseT< Signature >;
|
||||
|
||||
void _setSignal(SignalSig *sig)
|
||||
{
|
||||
mSignal = sig;
|
||||
}
|
||||
|
||||
SignalSig* _getSignal() const { return mSignal; }
|
||||
|
||||
DelegateSig mDlg;
|
||||
SignalSig *mSignal;
|
||||
|
||||
private:
|
||||
SignalSlot( const SignalSlot&) {}
|
||||
SignalSlot& operator=( const SignalSlot&) {}
|
||||
};
|
||||
|
||||
template<typename Signature> class SignalBaseT : public SignalBase
|
||||
{
|
||||
public:
|
||||
|
|
@ -135,7 +208,7 @@ public:
|
|||
{
|
||||
if( del->mDelegate == dlg )
|
||||
{
|
||||
for ( int i = 0; i < mTriggerNext.size(); i++ )
|
||||
for ( S32 i = 0; i < mTriggerNext.size(); i++ )
|
||||
{
|
||||
if( mTriggerNext[i] == ptr )
|
||||
mTriggerNext[i] = ptr->next;
|
||||
|
|
@ -163,6 +236,18 @@ public:
|
|||
notify(dlg, order);
|
||||
}
|
||||
|
||||
void notify( SignalSlot<Signature> &slot, F32 order = 0.5f)
|
||||
{
|
||||
if( !slot.getDelegate() )
|
||||
return;
|
||||
|
||||
if( slot.isConnected() )
|
||||
slot.disconnect();
|
||||
|
||||
slot._setSignal( this );
|
||||
mList.insert( new SlotLinkImpl(slot), order );
|
||||
}
|
||||
|
||||
template <class T,class U>
|
||||
void remove(T obj,U func)
|
||||
{
|
||||
|
|
@ -198,6 +283,23 @@ protected:
|
|||
DelegateLinkImpl(DelegateSig dlg) : mDelegate(dlg) {}
|
||||
};
|
||||
|
||||
struct SlotLinkImpl : public DelegateLinkImpl
|
||||
{
|
||||
SlotLinkImpl(SignalSlot<Signature>& slot) : mSlot( &slot ), DelegateLinkImpl( slot.getDelegate() )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
~SlotLinkImpl()
|
||||
{
|
||||
if( mSlot )
|
||||
mSlot->_setSignal( NULL );
|
||||
}
|
||||
|
||||
protected:
|
||||
SignalSlot<Signature> *mSlot;
|
||||
};
|
||||
|
||||
DelegateSig & getDelegate(SignalBase::DelegateLink * link)
|
||||
{
|
||||
return ((DelegateLinkImpl*)link)->mDelegate;
|
||||
|
|
@ -463,6 +565,75 @@ class Signal<bool(A,B,C,D,E,F,G,H,I,J)> : public SignalBaseT<bool(A,B,C,D,E,F,G,
|
|||
}
|
||||
};
|
||||
|
||||
template<class A, class B, class C, class D, class E, class F, class G, class H, class I, class J, class K>
|
||||
class Signal<bool(A,B,C,D,E,F,G,H,I,J,K)> : public SignalBaseT<bool(A,B,C,D,E,F,G,H,I,J,K)>
|
||||
{
|
||||
public:
|
||||
|
||||
bool trigger( A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k )
|
||||
{
|
||||
this->mTriggerNext.push_back(NULL);
|
||||
for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
|
||||
{
|
||||
this->mTriggerNext.last() = ptr->next;
|
||||
if( !this->getDelegate( ptr )( a, b, c, d, e, f, g, h, i, j, k ) )
|
||||
{
|
||||
this->mTriggerNext.pop_back();
|
||||
return false;
|
||||
}
|
||||
ptr = this->mTriggerNext.last();
|
||||
}
|
||||
this->mTriggerNext.pop_back();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template<class A, class B, class C, class D, class E, class F, class G, class H, class I, class J, class K, class L>
|
||||
class Signal<bool(A,B,C,D,E,F,G,H,I,J,K,L)> : public SignalBaseT<bool(A,B,C,D,E,F,G,H,I,J,K,L)>
|
||||
{
|
||||
public:
|
||||
|
||||
bool trigger( A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l )
|
||||
{
|
||||
this->mTriggerNext.push_back(NULL);
|
||||
for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
|
||||
{
|
||||
this->mTriggerNext.last() = ptr->next;
|
||||
if( !this->getDelegate( ptr )( a, b, c, d, e, f, g, h, i, j, k, l ) )
|
||||
{
|
||||
this->mTriggerNext.pop_back();
|
||||
return false;
|
||||
}
|
||||
ptr = this->mTriggerNext.last();
|
||||
}
|
||||
this->mTriggerNext.pop_back();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template<class A, class B, class C, class D, class E, class F, class G, class H, class I, class J, class K, class L, class M>
|
||||
class Signal<bool(A,B,C,D,E,F,G,H,I,J,K,L,M)> : public SignalBaseT<bool(A,B,C,D,E,F,G,H,I,J,K,L,M)>
|
||||
{
|
||||
public:
|
||||
|
||||
bool trigger( A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m )
|
||||
{
|
||||
this->mTriggerNext.push_back(NULL);
|
||||
for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
|
||||
{
|
||||
this->mTriggerNext.last() = ptr->next;
|
||||
if( !this->getDelegate( ptr )( a, b, c, d, e, f, g, h, i, j, k, l, m ) )
|
||||
{
|
||||
this->mTriggerNext.pop_back();
|
||||
return false;
|
||||
}
|
||||
ptr = this->mTriggerNext.last();
|
||||
}
|
||||
this->mTriggerNext.pop_back();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// Non short-circuit signal implementations
|
||||
|
||||
template<>
|
||||
|
|
@ -663,4 +834,58 @@ class Signal<void(A,B,C,D,E,F,G,H,I,J)> : public SignalBaseT<void(A,B,C,D,E,F,G,
|
|||
}
|
||||
};
|
||||
|
||||
template<class A, class B, class C, class D, class E, class F, class G, class H, class I, class J, class K>
|
||||
class Signal<void(A,B,C,D,E,F,G,H,I,J,K)> : public SignalBaseT<void(A,B,C,D,E,F,G,H,I,J,K)>
|
||||
{
|
||||
public:
|
||||
|
||||
void trigger( A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k )
|
||||
{
|
||||
this->mTriggerNext.push_back(NULL);
|
||||
for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
|
||||
{
|
||||
this->mTriggerNext.last() = ptr->next;
|
||||
this->getDelegate( ptr )( a, b, c, d, e, f, g, h, i, j, k );
|
||||
ptr = this->mTriggerNext.last();
|
||||
}
|
||||
this->mTriggerNext.pop_back();
|
||||
}
|
||||
};
|
||||
|
||||
template<class A, class B, class C, class D, class E, class F, class G, class H, class I, class J, class K, class L>
|
||||
class Signal<void(A,B,C,D,E,F,G,H,I,J,K,L)> : public SignalBaseT<void(A,B,C,D,E,F,G,H,I,J,K,L)>
|
||||
{
|
||||
public:
|
||||
|
||||
void trigger( A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l )
|
||||
{
|
||||
this->mTriggerNext.push_back(NULL);
|
||||
for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
|
||||
{
|
||||
this->mTriggerNext.last() = ptr->next;
|
||||
this->getDelegate( ptr )( a, b, c, d, e, f, g, h, i, j, k, l );
|
||||
ptr = this->mTriggerNext.last();
|
||||
}
|
||||
this->mTriggerNext.pop_back();
|
||||
}
|
||||
};
|
||||
|
||||
template<class A, class B, class C, class D, class E, class F, class G, class H, class I, class J, class K, class L, class M>
|
||||
class Signal<void(A,B,C,D,E,F,G,H,I,J,K,L,M)> : public SignalBaseT<void(A,B,C,D,E,F,G,H,I,J,K,L,M)>
|
||||
{
|
||||
public:
|
||||
|
||||
void trigger( A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m )
|
||||
{
|
||||
this->mTriggerNext.push_back(NULL);
|
||||
for( SignalBase::DelegateLink* ptr = this->mList.next; ptr != &this->mList; )
|
||||
{
|
||||
this->mTriggerNext.last() = ptr->next;
|
||||
this->getDelegate( ptr )( a, b, c, d, e, f, g, h, i, j, k, l, m );
|
||||
ptr = this->mTriggerNext.last();
|
||||
}
|
||||
this->mTriggerNext.pop_back();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // _TSIGNAL_H_
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@
|
|||
#ifndef _PLATFORM_H_
|
||||
#include "platform/platform.h"
|
||||
#endif
|
||||
#include <algorithm>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Helper definitions for the vector class.
|
||||
|
|
@ -181,6 +182,9 @@ class Vector
|
|||
///
|
||||
void merge( const T *addr, U32 count );
|
||||
|
||||
// Reverses the order of elements.
|
||||
void reverse();
|
||||
|
||||
/// @}
|
||||
};
|
||||
|
||||
|
|
@ -504,7 +508,7 @@ template<class T> inline void Vector<T>::compact()
|
|||
resize(mElementCount);
|
||||
}
|
||||
|
||||
typedef int (QSORT_CALLBACK *qsort_compare_func)(const void *, const void *);
|
||||
typedef S32 (QSORT_CALLBACK *qsort_compare_func)(const void *, const void *);
|
||||
|
||||
template<class T> inline void Vector<T>::sort(compare_func f)
|
||||
{
|
||||
|
|
@ -760,6 +764,12 @@ template<class T> inline void Vector<T>::merge( const T *addr, U32 count )
|
|||
mElementCount = newSize;
|
||||
}
|
||||
|
||||
template<class T> inline void Vector<T>::reverse()
|
||||
{
|
||||
for (U32 i = 0, j = size(); (i != j) && (i != --j); ++i)
|
||||
std::swap( mArray[ i ], mArray[ j ] );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
/// Template for vectors of pointers.
|
||||
template <class T>
|
||||
|
|
@ -790,7 +800,7 @@ class VectorPtr : public Vector<void *>
|
|||
const_iterator end() const;
|
||||
|
||||
void insert(iterator,const T&);
|
||||
void insert(int idx) { Parent::insert(idx); }
|
||||
void insert(S32 idx) { Parent::insert(idx); }
|
||||
void erase(iterator);
|
||||
|
||||
T& front();
|
||||
|
|
|
|||
40
Engine/source/core/util/test/pathTest.cpp
Normal file
40
Engine/source/core/util/test/pathTest.cpp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 "core/util/path.h"
|
||||
|
||||
TEST(MakeRelativePath, MakeRelativePath)
|
||||
{
|
||||
EXPECT_EQ(Torque::Path::MakeRelativePath("art/interiors/burg/file.png", "art/interiors/"), "burg/file.png");
|
||||
EXPECT_EQ(Torque::Path::MakeRelativePath("art/interiors/file.png", "art/interiors/burg/"), "../file.png");
|
||||
EXPECT_EQ(Torque::Path::MakeRelativePath("art/file.png", "art/interiors/burg/"), "../../file.png");
|
||||
EXPECT_EQ(Torque::Path::MakeRelativePath("file.png", "art/interiors/burg/"), "../../../file.png");
|
||||
EXPECT_EQ(Torque::Path::MakeRelativePath("art/interiors/burg/file.png", "art/interiors/burg/"), "file.png");
|
||||
EXPECT_EQ(Torque::Path::MakeRelativePath("art/interiors/camp/file.png", "art/interiors/burg/"), "../camp/file.png");
|
||||
EXPECT_EQ(Torque::Path::MakeRelativePath("art/interiors/burg/file.png", "art/shapes/"), "../interiors/burg/file.png");
|
||||
EXPECT_EQ(Torque::Path::MakeRelativePath("levels/den/file.png", "art/interiors/burg/"), "../../../levels/den/file.png");
|
||||
EXPECT_EQ(Torque::Path::MakeRelativePath("art/interiors/burg/file.png", "art/dts/burg/"), "../../interiors/burg/file.png");
|
||||
};
|
||||
|
||||
#endif
|
||||
332
Engine/source/core/util/test/strTest.cpp
Normal file
332
Engine/source/core/util/test/strTest.cpp
Normal file
|
|
@ -0,0 +1,332 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 "core/util/str.h"
|
||||
#include "core/util/tVector.h"
|
||||
#include "core/strings/stringFunctions.h"
|
||||
#include "core/strings/unicode.h"
|
||||
|
||||
/// This is called Str, not String, because googletest doesn't let you use both
|
||||
/// TEST(x) and TEST_FIX(x). So this fixture is called Str, to match the StrTest
|
||||
/// struct, and the remaining fixture-les tests are named String.
|
||||
FIXTURE(Str)
|
||||
{
|
||||
protected:
|
||||
struct StrTest
|
||||
{
|
||||
const UTF8* mData;
|
||||
const UTF16* mUTF16;
|
||||
U32 mLength;
|
||||
|
||||
StrTest() : mData( 0 ), mUTF16( 0 ) {}
|
||||
StrTest( const char* str )
|
||||
: mData( str ), mLength( str ? dStrlen( str ) : 0 ), mUTF16( NULL )
|
||||
{
|
||||
if( str )
|
||||
mUTF16 = convertUTF8toUTF16( mData );
|
||||
}
|
||||
~StrTest()
|
||||
{
|
||||
if( mUTF16 )
|
||||
delete [] mUTF16;
|
||||
}
|
||||
};
|
||||
|
||||
Vector< StrTest* > mStrings;
|
||||
|
||||
virtual void SetUp()
|
||||
{
|
||||
mStrings.push_back( new StrTest( NULL ) );
|
||||
mStrings.push_back( new StrTest( "" ) );
|
||||
mStrings.push_back( new StrTest( "Torque" ) );
|
||||
mStrings.push_back( new StrTest( "TGEA" ) );
|
||||
mStrings.push_back( new StrTest( "GarageGames" ) );
|
||||
mStrings.push_back( new StrTest( "TGB" ) );
|
||||
mStrings.push_back( new StrTest( "games" ) );
|
||||
mStrings.push_back( new StrTest( "engine" ) );
|
||||
mStrings.push_back( new StrTest( "rocks" ) );
|
||||
mStrings.push_back( new StrTest( "technology" ) );
|
||||
mStrings.push_back( new StrTest( "Torque 3D" ) );
|
||||
mStrings.push_back( new StrTest( "Torque 2D" ) );
|
||||
}
|
||||
|
||||
virtual void TearDown()
|
||||
{
|
||||
for( U32 i = 0; i < mStrings.size(); ++ i )
|
||||
delete mStrings[ i ];
|
||||
mStrings.clear();
|
||||
}
|
||||
};
|
||||
|
||||
#define EACH_STRING(i) \
|
||||
for( U32 i = 0; i < mStrings.size(); ++ i )
|
||||
#define EACH_PAIR(i, j) \
|
||||
for( U32 i = 0; i < mStrings.size(); ++ i ) \
|
||||
for( U32 j = 0; j < mStrings.size(); ++ j )
|
||||
|
||||
TEST_FIX(Str, Test1)
|
||||
{
|
||||
EACH_STRING(i)
|
||||
{
|
||||
StrTest& data = *mStrings[i];
|
||||
String str( data.mData );
|
||||
String str16( data.mUTF16 );
|
||||
|
||||
EXPECT_TRUE( str.length() == data.mLength );
|
||||
EXPECT_TRUE( str.size() == data.mLength + 1 );
|
||||
EXPECT_TRUE( str.isEmpty() || str.length() > 0 );
|
||||
EXPECT_TRUE( str.length() == str16.length() );
|
||||
EXPECT_TRUE( str.size() == str16.size() );
|
||||
|
||||
EXPECT_TRUE( dMemcmp( str.utf16(), str16.utf16(), str.length() * sizeof( UTF16 ) ) == 0 );
|
||||
EXPECT_TRUE( !data.mData || dMemcmp( str.utf16(), data.mUTF16, str.length() * sizeof( UTF16 ) ) == 0 );
|
||||
EXPECT_TRUE( !data.mData || dMemcmp( str16.utf8(), data.mData, str.length() ) == 0 );
|
||||
|
||||
EXPECT_TRUE( !data.mData || dStrcmp( str.utf8(), data.mData ) == 0 );
|
||||
EXPECT_TRUE( !data.mData || dStrcmp( str.utf16(), data.mUTF16 ) == 0 );
|
||||
}
|
||||
}
|
||||
|
||||
TEST_FIX(Str, Test2)
|
||||
{
|
||||
EACH_STRING(i)
|
||||
{
|
||||
StrTest& data = *mStrings[i];
|
||||
String str( data.mData );
|
||||
|
||||
EXPECT_TRUE( str == str );
|
||||
EXPECT_FALSE( str != str );
|
||||
EXPECT_FALSE( str < str );
|
||||
EXPECT_FALSE( str > str );
|
||||
EXPECT_TRUE( str.equal( str ) );
|
||||
EXPECT_TRUE( str.equal( str, String::NoCase ) );
|
||||
}
|
||||
}
|
||||
|
||||
TEST_FIX(Str, Test3)
|
||||
{
|
||||
EACH_PAIR(i, j)
|
||||
{
|
||||
StrTest& d1 = *mStrings[i];
|
||||
StrTest& d2 = *mStrings[j];
|
||||
|
||||
if( &d1 != &d2 )
|
||||
EXPECT_TRUE( String( d1.mData ) != String( d2.mData )
|
||||
|| ( String( d1.mData ).isEmpty() && String( d2.mData ).isEmpty() ) );
|
||||
else
|
||||
EXPECT_TRUE( String( d1.mData ) == String( d2.mData ) );
|
||||
}
|
||||
}
|
||||
|
||||
TEST(String, Empty)
|
||||
{
|
||||
EXPECT_TRUE( String().length() == 0 );
|
||||
EXPECT_TRUE( String( "" ).length() == 0 );
|
||||
EXPECT_TRUE( String().size() == 1 );
|
||||
EXPECT_TRUE( String( "" ).size() == 1 );
|
||||
EXPECT_TRUE( String().isEmpty() );
|
||||
EXPECT_TRUE( String( "" ).isEmpty() );
|
||||
}
|
||||
|
||||
TEST(String, Trim)
|
||||
{
|
||||
EXPECT_TRUE( String( " Foobar Barfoo \n\t " ).trim() == String( "Foobar Barfoo" ) );
|
||||
EXPECT_TRUE( String( "Foobar" ).trim() == String( "Foobar" ) );
|
||||
EXPECT_TRUE( String( " " ).trim().isEmpty() );
|
||||
}
|
||||
|
||||
TEST(String, Compare)
|
||||
{
|
||||
String str( "Foobar" );
|
||||
|
||||
EXPECT_TRUE( str.compare( "Foo", 3 ) == 0 );
|
||||
EXPECT_TRUE( str.compare( "bar", 3, String::NoCase | String::Right ) == 0 );
|
||||
EXPECT_TRUE( str.compare( "foo", 3, String::NoCase ) == 0 );
|
||||
EXPECT_TRUE( str.compare( "BAR", 3, String::NoCase | String::Right ) == 0 );
|
||||
EXPECT_TRUE( str.compare( "Foobar" ) == 0 );
|
||||
EXPECT_TRUE( str.compare( "Foo" ) != 0 );
|
||||
EXPECT_TRUE( str.compare( "foobar", 0, String::NoCase ) == 0 );
|
||||
EXPECT_TRUE( str.compare( "FOOBAR", 0, String::NoCase ) == 0 );
|
||||
EXPECT_TRUE( str.compare( "Foobar", 0, String::Right ) == 0 );
|
||||
EXPECT_TRUE( str.compare( "foobar", 0, String::NoCase | String::Right ) == 0 );
|
||||
}
|
||||
|
||||
TEST(String, Order)
|
||||
{
|
||||
Vector< String > strs;
|
||||
|
||||
strs.push_back( "a" );
|
||||
strs.push_back( "a0" );
|
||||
strs.push_back( "a1" );
|
||||
strs.push_back( "a1a" );
|
||||
strs.push_back( "a1b" );
|
||||
strs.push_back( "a2" );
|
||||
strs.push_back( "a10" );
|
||||
strs.push_back( "a20" );
|
||||
|
||||
for( U32 i = 0; i < strs.size(); ++ i )
|
||||
{
|
||||
for( U32 j = 0; j < i; ++ j )
|
||||
{
|
||||
EXPECT_TRUE( strs[ j ] < strs[ i ] );
|
||||
EXPECT_TRUE( strs[ i ] > strs[ j ] );
|
||||
|
||||
EXPECT_TRUE( !( strs[ j ] > strs[ i ] ) );
|
||||
EXPECT_TRUE( !( strs[ i ] < strs[ i ] ) );
|
||||
|
||||
EXPECT_TRUE( strs[ j ] <= strs[ i ] );
|
||||
EXPECT_TRUE( strs[ i ] >= strs[ j ] );
|
||||
}
|
||||
|
||||
EXPECT_TRUE( !( strs[ i ] < strs[ i ] ) );
|
||||
EXPECT_TRUE( !( strs[ i ] > strs[ i ] ) );
|
||||
EXPECT_TRUE( strs[ i ] <= strs[ i ] );
|
||||
EXPECT_TRUE( strs[ i ] >= strs[ i ] );
|
||||
|
||||
for( U32 j = i + 1; j < strs.size(); ++ j )
|
||||
{
|
||||
EXPECT_TRUE( strs[ j ] > strs[ i ] );
|
||||
EXPECT_TRUE( strs[ i ] < strs[ j ] );
|
||||
|
||||
EXPECT_TRUE( !( strs[ j ] < strs[ i ] ) );
|
||||
EXPECT_TRUE( !( strs[ i ] > strs[ j ] ) );
|
||||
|
||||
EXPECT_TRUE( strs[ j ] >= strs[ i ] );
|
||||
EXPECT_TRUE( strs[ i ] <= strs[ j ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// TODO
|
||||
TEST(String, Find)
|
||||
{
|
||||
}
|
||||
|
||||
TEST(String, Insert)
|
||||
{
|
||||
// String.insert( Pos, Char )
|
||||
EXPECT_TRUE( String( "aa" ).insert( 1, 'c' ) == String( "aca" ) );
|
||||
|
||||
// String.insert( Pos, String )
|
||||
EXPECT_TRUE( String( "aa" ).insert( 1, "cc" ) == String( "acca" ) );
|
||||
EXPECT_TRUE( String( "aa" ).insert( 1, String( "cc" ) ) == String( "acca" ) );
|
||||
|
||||
// String.insert( Pos, String, Len )
|
||||
EXPECT_TRUE( String( "aa" ).insert( 1, "ccdddd", 2 ) == String( "acca" ) );
|
||||
}
|
||||
|
||||
TEST(String, Erase)
|
||||
{
|
||||
EXPECT_TRUE( String( "abba" ).erase( 1, 2 ) == String( "aa" ) );
|
||||
EXPECT_TRUE( String( "abba" ).erase( 0, 4 ).isEmpty() );
|
||||
}
|
||||
|
||||
TEST(String, Replace)
|
||||
{
|
||||
// String.replace( Pos, Len, String )
|
||||
EXPECT_TRUE( String( "abba" ).replace( 1, 2, "ccc" ) == String( "accca" ) );
|
||||
EXPECT_TRUE( String( "abba" ).replace( 1, 2, String( "ccc" ) ) == String( "accca" ) );
|
||||
EXPECT_TRUE( String( "abba" ).replace( 0, 4, "" ).isEmpty() );
|
||||
EXPECT_TRUE( String( "abba" ).replace( 2, 2, "c" ) == String( "abc" ) );
|
||||
|
||||
// String.replace( Char, Char )
|
||||
EXPECT_TRUE( String().replace( 'a', 'b' ).isEmpty() );
|
||||
EXPECT_TRUE( String( "ababc" ).replace( 'a', 'b' ) == String( "bbbbc" ) );
|
||||
EXPECT_TRUE( String( "ababc" ).replace( 'd', 'e' ) == String( "ababc" ) );
|
||||
|
||||
// String.replace( String, String )
|
||||
EXPECT_TRUE( String().replace( "foo", "bar" ).isEmpty() );
|
||||
EXPECT_TRUE( String( "foobarfoo" ).replace( "foo", "bar" ) == String( "barbarbar" ) );
|
||||
EXPECT_TRUE( String( "foobar" ).replace( "xx", "yy" ) == String( "foobar" ) );
|
||||
EXPECT_TRUE( String( "foofoofoo" ).replace( "foo", "" ).isEmpty() );
|
||||
}
|
||||
|
||||
TEST(String, SubStr)
|
||||
{
|
||||
EXPECT_TRUE( String( "foobar" ).substr( 0, 3 ) == String( "foo" ) );
|
||||
EXPECT_TRUE( String( "foobar" ).substr( 3 ) == String( "bar" ) );
|
||||
EXPECT_TRUE( String( "foobar" ).substr( 2, 2 ) == String( "ob" ) );
|
||||
EXPECT_TRUE( String( "foobar" ).substr( 2, 0 ).isEmpty() );
|
||||
EXPECT_TRUE( String( "foobar" ).substr( 0, 6 ) == String( "foobar" ) );
|
||||
}
|
||||
|
||||
TEST(String, ToString)
|
||||
{
|
||||
EXPECT_TRUE( String::ToString( U32( 1 ) ) == String( "1" ) );
|
||||
EXPECT_TRUE( String::ToString( S32( -1 ) ) == String( "-1" ) );
|
||||
EXPECT_TRUE( String::ToString( F32( 1.01 ) ) == String( "1.01" ) );
|
||||
EXPECT_TRUE( String::ToString( "%s%i", "foo", 1 ) == String( "foo1" ) );
|
||||
}
|
||||
|
||||
TEST(String, CaseConversion)
|
||||
{
|
||||
EXPECT_TRUE( String::ToLower( "foobar123." ) == String( "foobar123." ) );
|
||||
EXPECT_TRUE( String::ToLower( "FOOBAR123." ) == String( "foobar123." ) );
|
||||
EXPECT_TRUE( String::ToUpper( "barfoo123." ) == String( "BARFOO123." ) );
|
||||
EXPECT_TRUE( String::ToUpper( "BARFOO123." ) == String( "BARFOO123." ) );
|
||||
}
|
||||
|
||||
TEST(String, Concat)
|
||||
{
|
||||
EXPECT_TRUE( String( "foo" ) + String( "bar" ) == String( "foobar" ) );
|
||||
EXPECT_TRUE( String() + String( "bar" ) == String( "bar" ) );
|
||||
EXPECT_TRUE( String( "foo" ) + String() == String( "foo" ) );
|
||||
EXPECT_TRUE( String() + String() == String() );
|
||||
EXPECT_TRUE( String( "fo" ) + 'o' == String( "foo" ) );
|
||||
EXPECT_TRUE( 'f' + String( "oo" ) == String( "foo" ) );
|
||||
EXPECT_TRUE( String( "foo" ) + "bar" == String( "foobar" ) );
|
||||
EXPECT_TRUE( "foo" + String( "bar" ) == String( "foobar" ) );
|
||||
}
|
||||
|
||||
TEST(String, Hash)
|
||||
{
|
||||
EXPECT_TRUE( String( "foo" ).getHashCaseSensitive() == String( "foo" ).getHashCaseSensitive() );
|
||||
EXPECT_TRUE( String( "foo" ).getHashCaseSensitive() != String( "bar" ).getHashCaseSensitive() );
|
||||
EXPECT_TRUE( String( "foo" ).getHashCaseInsensitive() == String( "FOO" ).getHashCaseInsensitive() );
|
||||
}
|
||||
|
||||
TEST(String, Intern)
|
||||
{
|
||||
EXPECT_TRUE( String( "foo" ).intern().isSame( String( "foo" ).intern() ) );
|
||||
EXPECT_TRUE( !String( "foo" ).intern().isSame( String( "bar" ).intern() ) );
|
||||
EXPECT_TRUE( !String( "foo" ).intern().isSame( String( "Foo" ).intern() ) );
|
||||
EXPECT_TRUE( String( "foo" ).intern() == String( "foo" ).intern() );
|
||||
EXPECT_TRUE( String( "foo" ).intern() != String( "bar" ).intern() );
|
||||
EXPECT_TRUE( String( "foo" ).intern().isInterned() );
|
||||
}
|
||||
|
||||
TEST(StringBuilder, StringBuilder)
|
||||
{
|
||||
StringBuilder str;
|
||||
|
||||
str.append( 'f' );
|
||||
str.append( "oo" );
|
||||
str.append( String( "ba" ) );
|
||||
str.append( "rfajskfdj", 1 );
|
||||
str.format( "%s", "barfoo" );
|
||||
|
||||
EXPECT_TRUE( str.end() == String( "foobarbarfoo" ) );
|
||||
}
|
||||
|
||||
#endif
|
||||
129
Engine/source/core/util/test/swizzleTest.cpp
Normal file
129
Engine/source/core/util/test/swizzleTest.cpp
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 "platform/platform.h"
|
||||
#include "testing/unitTesting.h"
|
||||
#include "core/util/swizzle.h"
|
||||
#include "math/mRandom.h"
|
||||
|
||||
class TestStruct
|
||||
{
|
||||
private:
|
||||
static U32 smIdx;
|
||||
U32 mIdx;
|
||||
U32 mData;
|
||||
|
||||
public:
|
||||
TestStruct( const S32 data = -1 ) : mData( data ), mIdx( smIdx++ ) {};
|
||||
|
||||
dsize_t Idx() const { return mIdx; }
|
||||
|
||||
U32 Data() const { return mData; }
|
||||
void Data(U32 val) { mData = val; }
|
||||
};
|
||||
|
||||
U32 TestStruct::smIdx = 0;
|
||||
|
||||
TEST(Swizzle, Swizzle)
|
||||
{
|
||||
//------------------------------------------------------------------------
|
||||
// Debugger-Observable Functionality Tests
|
||||
//------------------------------------------------------------------------
|
||||
U8 simpleBuffer[] = { 0, 1, 2, 3 };
|
||||
U8 simpleTest[] = { 0, 1, 2, 3 };
|
||||
|
||||
#define RESET_SIMPLE() dMemcpy( simpleTest, simpleBuffer, sizeof( simpleBuffer ) )
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// No-switch test
|
||||
dsize_t noSwzl4[] = { 0, 1, 2, 3 };
|
||||
Swizzle<U8,4> noSwizzle4( noSwzl4 );
|
||||
|
||||
noSwizzle4.InPlace( simpleTest, sizeof( simpleTest ) );
|
||||
EXPECT_EQ( dMemcmp( simpleTest, simpleBuffer, sizeof( simpleBuffer ) ), 0 )
|
||||
<< "No-switch test failed!";
|
||||
RESET_SIMPLE();
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// No-brainer RGBA->BGRA test
|
||||
dsize_t bgraSwzl[] = { 2, 1, 0, 3 };
|
||||
Swizzle<U8,4> bgraSwizzle( bgraSwzl );
|
||||
|
||||
U8 bgraTest[] = { 2, 1, 0, 3 };
|
||||
bgraSwizzle.InPlace( simpleTest, sizeof( simpleTest ) );
|
||||
EXPECT_EQ( dMemcmp( simpleTest, bgraTest, sizeof( bgraTest ) ), 0 )
|
||||
<< "U8 RGBA->BGRA test failed";
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Reverse test
|
||||
bgraSwizzle.InPlace( simpleTest, sizeof( simpleTest ) );
|
||||
EXPECT_EQ( dMemcmp( simpleTest, simpleBuffer, sizeof( simpleBuffer ) ), 0 )
|
||||
<< "U8 RGBA->BGRA reverse test failed";
|
||||
|
||||
RESET_SIMPLE();
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Object support test
|
||||
Swizzle<TestStruct,4> bgraObjSwizzle( bgraSwzl );
|
||||
{
|
||||
U32 objIdx[] = { 0, 1, 2, 3 };
|
||||
|
||||
FrameTemp<TestStruct> objTest( sizeof( objIdx ) / sizeof( U32 ) );
|
||||
FrameTemp<U32> randData( sizeof( objIdx ) / sizeof( U32 ) );
|
||||
|
||||
bool same = true;
|
||||
|
||||
for( U32 i = 0; i < sizeof( objIdx ) / sizeof( U32 ); i++ )
|
||||
{
|
||||
// Make random data and assign it
|
||||
randData[i] = gRandGen.randI();
|
||||
objTest[i].Data( randData[i] );
|
||||
|
||||
// Continue object sanity check
|
||||
same &= ( objTest[i].Idx() == objIdx[i] );
|
||||
}
|
||||
|
||||
EXPECT_TRUE( same )
|
||||
<< "Test object failed to be competent";
|
||||
|
||||
bgraObjSwizzle.InPlace( ~objTest, sizeof( TestStruct ) * ( sizeof( objIdx ) / sizeof( U32 ) ) );
|
||||
same = true;
|
||||
|
||||
for( U32 i = 0; i < sizeof( objIdx ) / sizeof( U32 ); i++ )
|
||||
same &= ( objTest[i].Idx() == bgraTest[i] ) && ( objTest[i].Data() == randData[ (U32)bgraTest[ i ] ] );
|
||||
|
||||
EXPECT_TRUE( same )
|
||||
<< "Object RGBA->BGRA test failed.";
|
||||
|
||||
bgraObjSwizzle.InPlace( ~objTest, sizeof( TestStruct ) * ( sizeof( objIdx ) / sizeof( U32 ) ) );
|
||||
same = true;
|
||||
|
||||
for( U32 i = 0; i < sizeof( objIdx ) / sizeof( U32 ); i++ )
|
||||
same &= ( objTest[i].Idx() == objIdx[i] ) && ( objTest[i].Data() == randData[i] );
|
||||
|
||||
EXPECT_TRUE( same )
|
||||
<< "Object RGBA->BGRA reverse test failed.";
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 GarageGames, LLC
|
||||
// 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
|
||||
|
|
@ -20,35 +20,30 @@
|
|||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "unit/test.h"
|
||||
#ifdef TORQUE_TESTS_ENABLED
|
||||
#include "testing/unitTesting.h"
|
||||
#include "core/util/tFixedSizeDeque.h"
|
||||
|
||||
|
||||
using namespace UnitTesting;
|
||||
|
||||
#define TEST( x ) test( ( x ), "FAIL: " #x )
|
||||
|
||||
CreateUnitTest( TestFixedSizeDeque, "Util/FixedSizeDeque" )
|
||||
TEST(FixedSizeDeque, FixedSizeDeque)
|
||||
{
|
||||
void run()
|
||||
{
|
||||
enum { DEQUE_SIZE = 3 };
|
||||
FixedSizeDeque< U32 > deque( DEQUE_SIZE );
|
||||
enum { DEQUE_SIZE = 3 };
|
||||
FixedSizeDeque< U32 > deque( DEQUE_SIZE );
|
||||
|
||||
TEST( deque.capacity() == DEQUE_SIZE );
|
||||
TEST( deque.size() == 0 );
|
||||
EXPECT_EQ( deque.capacity(), DEQUE_SIZE );
|
||||
EXPECT_EQ( deque.size(), 0 );
|
||||
|
||||
deque.pushFront( 1 );
|
||||
TEST( deque.capacity() == ( DEQUE_SIZE - 1 ) );
|
||||
TEST( deque.size() == 1 );
|
||||
TEST( !deque.isEmpty() );
|
||||
deque.pushFront( 1 );
|
||||
EXPECT_EQ( deque.capacity(), ( DEQUE_SIZE - 1 ) );
|
||||
EXPECT_EQ( deque.size(), 1 );
|
||||
EXPECT_FALSE( deque.isEmpty() );
|
||||
|
||||
deque.pushBack( 2 );
|
||||
TEST( deque.capacity() == ( DEQUE_SIZE - 2 ) );
|
||||
TEST( deque.size() == 2 );
|
||||
deque.pushBack( 2 );
|
||||
EXPECT_EQ( deque.capacity(), ( DEQUE_SIZE - 2 ) );
|
||||
EXPECT_EQ( deque.size(), 2 );
|
||||
|
||||
TEST( deque.popFront() == 1 );
|
||||
TEST( deque.popFront() == 2 );
|
||||
TEST( deque.isEmpty() );
|
||||
}
|
||||
EXPECT_EQ( deque.popFront(), 1 );
|
||||
EXPECT_EQ( deque.popFront(), 2 );
|
||||
EXPECT_TRUE( deque.isEmpty() );
|
||||
};
|
||||
|
||||
#endif
|
||||
125
Engine/source/core/util/test/tVectorTest.cpp
Normal file
125
Engine/source/core/util/test/tVectorTest.cpp
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 "core/util/tVector.h"
|
||||
|
||||
// Define some test data used below.
|
||||
FIXTURE(Vector)
|
||||
{
|
||||
public:
|
||||
struct Dtor
|
||||
{
|
||||
bool* ptr;
|
||||
Dtor() {} // Needed for vector increment.
|
||||
Dtor(bool* ptr): ptr(ptr) {}
|
||||
~Dtor()
|
||||
{
|
||||
*ptr = true;
|
||||
}
|
||||
};
|
||||
|
||||
static const S32 ints[];
|
||||
static const U32 length;
|
||||
static S32 QSORT_CALLBACK sortInts(const S32* a, const S32* b)
|
||||
{
|
||||
S32 av = *a;
|
||||
S32 bv = *b;
|
||||
|
||||
if (av < bv)
|
||||
return -1;
|
||||
else if (av > bv)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
const S32 VectorFixture::ints[] = {0, 10, 2, 3, 14, 4, 12, 6, 16, 7, 8, 1, 11, 5, 13, 9, 15};
|
||||
const U32 VectorFixture::length = sizeof(VectorFixture::ints) / sizeof(S32);
|
||||
|
||||
TEST_FIX(Vector, Allocation)
|
||||
{
|
||||
Vector<S32> *vector = new Vector<S32>;
|
||||
for (S32 i = 0; i < 1000; i++)
|
||||
vector->push_back(10000 + i);
|
||||
|
||||
// Erase the first element, 500 times.
|
||||
for (S32 i = 0; i < 500; i++)
|
||||
vector->erase(U32(0));
|
||||
|
||||
vector->compact();
|
||||
|
||||
EXPECT_EQ(vector->size(), 500) << "Vector was unexpectedly short!";
|
||||
|
||||
delete vector;
|
||||
}
|
||||
|
||||
TEST_FIX(Vector, Deallocation)
|
||||
{
|
||||
bool dtorVals[10];
|
||||
Vector<Dtor> v;
|
||||
|
||||
// Only add the first 9 entries; the last is populated below.
|
||||
for (U32 i = 0; i < 9; i++)
|
||||
v.push_back(Dtor(&dtorVals[i]));
|
||||
|
||||
// Fill the values array with false so we can test for destruction.
|
||||
for (U32 i = 0; i < 10; i++)
|
||||
dtorVals[i] = false;
|
||||
|
||||
v.decrement();
|
||||
EXPECT_TRUE(dtorVals[8]) << "Vector::decrement failed to call destructor";
|
||||
|
||||
v.decrement(2);
|
||||
EXPECT_TRUE(dtorVals[7]) << "Vector::decrement failed to call destructor";
|
||||
EXPECT_TRUE(dtorVals[6]) << "Vector::decrement failed to call destructor";
|
||||
|
||||
v.pop_back();
|
||||
EXPECT_TRUE(dtorVals[5]) << "Vector::pop_back failed to call destructor";
|
||||
|
||||
v.increment();
|
||||
v.last() = Dtor(&dtorVals[9]);
|
||||
v.clear();
|
||||
|
||||
// All elements should have been destructed.
|
||||
for (U32 i = 0; i < 10; i++)
|
||||
EXPECT_TRUE(dtorVals[i])
|
||||
<< "Element " << i << "'s destructor was not called";
|
||||
}
|
||||
|
||||
TEST_FIX(Vector, Sorting)
|
||||
{
|
||||
Vector<S32> v;
|
||||
|
||||
for(U32 i = 0; i < length; i++)
|
||||
v.push_back(ints[i]);
|
||||
|
||||
v.sort(sortInts);
|
||||
|
||||
for(U32 i = 0; i < length - 1; i++)
|
||||
EXPECT_TRUE(v[i] <= v[i + 1])
|
||||
<< "Element " << i << " was not in sorted order";
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 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.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "unit/test.h"
|
||||
#include "core/util/path.h"
|
||||
|
||||
using namespace UnitTesting;
|
||||
|
||||
#define TEST( x ) test( ( x ), "FAIL: " #x )
|
||||
|
||||
CreateUnitTest(TestPathMakeRelativePath, "Core/Util/Path/MakeRelativePath")
|
||||
{
|
||||
void run()
|
||||
{
|
||||
TEST(Torque::Path::MakeRelativePath("art/interiors/burg/file.png", "art/interiors/") == "burg/file.png");
|
||||
TEST(Torque::Path::MakeRelativePath("art/interiors/file.png", "art/interiors/burg/") == "../file.png");
|
||||
TEST(Torque::Path::MakeRelativePath("art/file.png", "art/interiors/burg/") == "../../file.png");
|
||||
TEST(Torque::Path::MakeRelativePath("file.png", "art/interiors/burg/") == "../../../file.png");
|
||||
TEST(Torque::Path::MakeRelativePath("art/interiors/burg/file.png", "art/interiors/burg/") == "file.png");
|
||||
TEST(Torque::Path::MakeRelativePath("art/interiors/camp/file.png", "art/interiors/burg/") == "../camp/file.png");
|
||||
TEST(Torque::Path::MakeRelativePath("art/interiors/burg/file.png", "art/shapes/") == "../interiors/burg/file.png");
|
||||
TEST(Torque::Path::MakeRelativePath("levels/den/file.png", "art/interiors/burg/") == "../../../levels/den/file.png");
|
||||
TEST(Torque::Path::MakeRelativePath("art/interiors/burg/file.png", "art/dts/burg/") == "../../interiors/burg/file.png");
|
||||
}
|
||||
};
|
||||
|
|
@ -1,358 +0,0 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 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.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "unit/test.h"
|
||||
#include "core/util/str.h"
|
||||
#include "core/util/tVector.h"
|
||||
#include "core/strings/stringFunctions.h"
|
||||
#include "core/strings/unicode.h"
|
||||
|
||||
|
||||
#ifndef TORQUE_SHIPPING
|
||||
|
||||
using namespace UnitTesting;
|
||||
|
||||
#define TEST( x ) test( ( x ), "FAIL: " #x )
|
||||
#define XTEST( t, x ) t->test( ( x ), "FAIL: " #x )
|
||||
|
||||
CreateUnitTest( TestString, "Util/String" )
|
||||
{
|
||||
struct StrTest
|
||||
{
|
||||
const UTF8* mData;
|
||||
const UTF16* mUTF16;
|
||||
U32 mLength;
|
||||
|
||||
StrTest() : mData( 0 ), mUTF16( 0 ) {}
|
||||
StrTest( const char* str )
|
||||
: mData( str ), mLength( str ? dStrlen( str ) : 0 ), mUTF16( NULL )
|
||||
{
|
||||
if( str )
|
||||
mUTF16 = convertUTF8toUTF16( mData );
|
||||
}
|
||||
~StrTest()
|
||||
{
|
||||
if( mUTF16 )
|
||||
delete [] mUTF16;
|
||||
}
|
||||
};
|
||||
|
||||
Vector< StrTest* > mStrings;
|
||||
|
||||
template< class T >
|
||||
void runTestOnStrings()
|
||||
{
|
||||
for( U32 i = 0; i < mStrings.size(); ++ i )
|
||||
T::run( this, *mStrings[ i ] );
|
||||
}
|
||||
template< class T >
|
||||
void runPairwiseTestOnStrings()
|
||||
{
|
||||
for( U32 i = 0; i < mStrings.size(); ++ i )
|
||||
for( U32 j = 0; j < mStrings.size(); ++ j )
|
||||
T::run( this, *mStrings[ i ], *mStrings[ j ] );
|
||||
}
|
||||
|
||||
struct Test1
|
||||
{
|
||||
static void run( TestString* test, StrTest& data )
|
||||
{
|
||||
String str( data.mData );
|
||||
String str16( data.mUTF16 );
|
||||
|
||||
XTEST( test, str.length() == data.mLength );
|
||||
XTEST( test, str.size() == data.mLength + 1 );
|
||||
XTEST( test, str.isEmpty() || str.length() > 0 );
|
||||
XTEST( test, str.length() == str16.length() );
|
||||
XTEST( test, str.size() == str16.size() );
|
||||
|
||||
XTEST( test, dMemcmp( str.utf16(), str16.utf16(), str.length() * sizeof( UTF16 ) ) == 0 );
|
||||
XTEST( test, !data.mData || dMemcmp( str.utf16(), data.mUTF16, str.length() * sizeof( UTF16 ) ) == 0 );
|
||||
XTEST( test, !data.mData || dMemcmp( str16.utf8(), data.mData, str.length() ) == 0 );
|
||||
|
||||
XTEST( test, !data.mData || dStrcmp( str.utf8(), data.mData ) == 0 );
|
||||
XTEST( test, !data.mData || dStrcmp( str.utf16(), data.mUTF16 ) == 0 );
|
||||
}
|
||||
};
|
||||
|
||||
struct Test2
|
||||
{
|
||||
static void run( TestString* test, StrTest& data )
|
||||
{
|
||||
String str( data.mData );
|
||||
|
||||
XTEST( test, str == str );
|
||||
XTEST( test, !( str != str ) );
|
||||
XTEST( test, !( str < str ) );
|
||||
XTEST( test, !( str > str ) );
|
||||
XTEST( test, str.equal( str ) );
|
||||
XTEST( test, str.equal( str, String::NoCase ) );
|
||||
}
|
||||
};
|
||||
|
||||
struct Test3
|
||||
{
|
||||
static void run( TestString* test, StrTest& d1, StrTest& d2 )
|
||||
{
|
||||
if( &d1 != &d2 )
|
||||
XTEST( test, String( d1.mData ) != String( d2.mData )
|
||||
|| ( String( d1.mData ).isEmpty() && String( d2.mData ).isEmpty() ) );
|
||||
else
|
||||
XTEST( test, String( d1.mData ) == String( d2.mData ) );
|
||||
}
|
||||
};
|
||||
|
||||
void testEmpty()
|
||||
{
|
||||
TEST( String().length() == 0 );
|
||||
TEST( String( "" ).length() == 0 );
|
||||
TEST( String().size() == 1 );
|
||||
TEST( String( "" ).size() == 1 );
|
||||
TEST( String().isEmpty() );
|
||||
TEST( String( "" ).isEmpty() );
|
||||
}
|
||||
|
||||
void testTrim()
|
||||
{
|
||||
TEST( String( " Foobar Barfoo \n\t " ).trim() == String( "Foobar Barfoo" ) );
|
||||
TEST( String( "Foobar" ).trim() == String( "Foobar" ) );
|
||||
TEST( String( " " ).trim().isEmpty() );
|
||||
}
|
||||
|
||||
void testCompare()
|
||||
{
|
||||
String str( "Foobar" );
|
||||
|
||||
TEST( str.compare( "Foo", 3 ) == 0 );
|
||||
TEST( str.compare( "bar", 3, String::NoCase | String::Right ) == 0 );
|
||||
TEST( str.compare( "foo", 3, String::NoCase ) == 0 );
|
||||
TEST( str.compare( "BAR", 3, String::NoCase | String::Right ) == 0 );
|
||||
TEST( str.compare( "Foobar" ) == 0 );
|
||||
TEST( str.compare( "Foo" ) != 0 );
|
||||
TEST( str.compare( "foobar", 0, String::NoCase ) == 0 );
|
||||
TEST( str.compare( "FOOBAR", 0, String::NoCase ) == 0 );
|
||||
TEST( str.compare( "Foobar", 0, String::Right ) == 0 );
|
||||
TEST( str.compare( "foobar", 0, String::NoCase | String::Right ) == 0 );
|
||||
}
|
||||
|
||||
void testOrder()
|
||||
{
|
||||
Vector< String > strs;
|
||||
|
||||
strs.push_back( "a" );
|
||||
strs.push_back( "a0" );
|
||||
strs.push_back( "a1" );
|
||||
strs.push_back( "a1a" );
|
||||
strs.push_back( "a1b" );
|
||||
strs.push_back( "a2" );
|
||||
strs.push_back( "a10" );
|
||||
strs.push_back( "a20" );
|
||||
|
||||
for( U32 i = 0; i < strs.size(); ++ i )
|
||||
{
|
||||
for( U32 j = 0; j < i; ++ j )
|
||||
{
|
||||
TEST( strs[ j ] < strs[ i ] );
|
||||
TEST( strs[ i ] > strs[ j ] );
|
||||
|
||||
TEST( !( strs[ j ] > strs[ i ] ) );
|
||||
TEST( !( strs[ i ] < strs[ i ] ) );
|
||||
|
||||
TEST( strs[ j ] <= strs[ i ] );
|
||||
TEST( strs[ i ] >= strs[ j ] );
|
||||
}
|
||||
|
||||
TEST( !( strs[ i ] < strs[ i ] ) );
|
||||
TEST( !( strs[ i ] > strs[ i ] ) );
|
||||
TEST( strs[ i ] <= strs[ i ] );
|
||||
TEST( strs[ i ] >= strs[ i ] );
|
||||
|
||||
for( U32 j = i + 1; j < strs.size(); ++ j )
|
||||
{
|
||||
TEST( strs[ j ] > strs[ i ] );
|
||||
TEST( strs[ i ] < strs[ j ] );
|
||||
|
||||
TEST( !( strs[ j ] < strs[ i ] ) );
|
||||
TEST( !( strs[ i ] > strs[ j ] ) );
|
||||
|
||||
TEST( strs[ j ] >= strs[ i ] );
|
||||
TEST( strs[ i ] <= strs[ j ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void testFind()
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
|
||||
void testInsert()
|
||||
{
|
||||
// String.insert( Pos, Char )
|
||||
TEST( String( "aa" ).insert( 1, 'c' ) == String( "aca" ) );
|
||||
|
||||
// String.insert( Pos, String )
|
||||
TEST( String( "aa" ).insert( 1, "cc" ) == String( "acca" ) );
|
||||
TEST( String( "aa" ).insert( 1, String( "cc" ) ) == String( "acca" ) );
|
||||
|
||||
// String.insert( Pos, String, Len )
|
||||
TEST( String( "aa" ).insert( 1, "ccdddd", 2 ) == String( "acca" ) );
|
||||
}
|
||||
|
||||
void testErase()
|
||||
{
|
||||
TEST( String( "abba" ).erase( 1, 2 ) == String( "aa" ) );
|
||||
TEST( String( "abba" ).erase( 0, 4 ).isEmpty() );
|
||||
}
|
||||
|
||||
void testReplace()
|
||||
{
|
||||
// String.replace( Pos, Len, String )
|
||||
TEST( String( "abba" ).replace( 1, 2, "ccc" ) == String( "accca" ) );
|
||||
TEST( String( "abba" ).replace( 1, 2, String( "ccc" ) ) == String( "accca" ) );
|
||||
TEST( String( "abba" ).replace( 0, 4, "" ).isEmpty() );
|
||||
TEST( String( "abba" ).replace( 2, 2, "c" ) == String( "abc" ) );
|
||||
|
||||
// String.replace( Char, Char )
|
||||
TEST( String().replace( 'a', 'b' ).isEmpty() );
|
||||
TEST( String( "ababc" ).replace( 'a', 'b' ) == String( "bbbbc" ) );
|
||||
TEST( String( "ababc" ).replace( 'd', 'e' ) == String( "ababc" ) );
|
||||
|
||||
// String.replace( String, String )
|
||||
TEST( String().replace( "foo", "bar" ).isEmpty() );
|
||||
TEST( String( "foobarfoo" ).replace( "foo", "bar" ) == String( "barbarbar" ) );
|
||||
TEST( String( "foobar" ).replace( "xx", "yy" ) == String( "foobar" ) );
|
||||
TEST( String( "foofoofoo" ).replace( "foo", "" ).isEmpty() );
|
||||
}
|
||||
|
||||
void testSubstr()
|
||||
{
|
||||
TEST( String( "foobar" ).substr( 0, 3 ) == String( "foo" ) );
|
||||
TEST( String( "foobar" ).substr( 3 ) == String( "bar" ) );
|
||||
TEST( String( "foobar" ).substr( 2, 2 ) == String( "ob" ) );
|
||||
TEST( String( "foobar" ).substr( 2, 0 ).isEmpty() );
|
||||
TEST( String( "foobar" ).substr( 0, 6 ) == String( "foobar" ) );
|
||||
}
|
||||
|
||||
void testToString()
|
||||
{
|
||||
TEST( String::ToString( U32( 1 ) ) == String( "1" ) );
|
||||
TEST( String::ToString( S32( -1 ) ) == String( "-1" ) );
|
||||
TEST( String::ToString( F32( 1.01 ) ) == String( "1.01" ) );
|
||||
TEST( String::ToString( "%s%i", "foo", 1 ) == String( "foo1" ) );
|
||||
}
|
||||
|
||||
void testCaseConversion()
|
||||
{
|
||||
TEST( String::ToLower( "foobar123." ) == String( "foobar123." ) );
|
||||
TEST( String::ToLower( "FOOBAR123." ) == String( "foobar123." ) );
|
||||
TEST( String::ToUpper( "barfoo123." ) == String( "BARFOO123." ) );
|
||||
TEST( String::ToUpper( "BARFOO123." ) == String( "BARFOO123." ) );
|
||||
}
|
||||
|
||||
void testConcat()
|
||||
{
|
||||
TEST( String( "foo" ) + String( "bar" ) == String( "foobar" ) );
|
||||
TEST( String() + String( "bar" ) == String( "bar" ) );
|
||||
TEST( String( "foo" ) + String() == String( "foo" ) );
|
||||
TEST( String() + String() == String() );
|
||||
TEST( String( "fo" ) + 'o' == String( "foo" ) );
|
||||
TEST( 'f' + String( "oo" ) == String( "foo" ) );
|
||||
TEST( String( "foo" ) + "bar" == String( "foobar" ) );
|
||||
TEST( "foo" + String( "bar" ) == String( "foobar" ) );
|
||||
}
|
||||
|
||||
void testHash()
|
||||
{
|
||||
TEST( String( "foo" ).getHashCaseSensitive() == String( "foo" ).getHashCaseSensitive() );
|
||||
TEST( String( "foo" ).getHashCaseSensitive() != String( "bar" ).getHashCaseSensitive() );
|
||||
TEST( String( "foo" ).getHashCaseInsensitive() == String( "FOO" ).getHashCaseInsensitive() );
|
||||
}
|
||||
|
||||
void testIntern()
|
||||
{
|
||||
TEST( String( "foo" ).intern().isSame( String( "foo" ).intern() ) );
|
||||
TEST( !String( "foo" ).intern().isSame( String( "bar" ).intern() ) );
|
||||
TEST( !String( "foo" ).intern().isSame( String( "Foo" ).intern() ) );
|
||||
TEST( String( "foo" ).intern() == String( "foo" ).intern() );
|
||||
TEST( String( "foo" ).intern() != String( "bar" ).intern() );
|
||||
TEST( String( "foo" ).intern().isInterned() );
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
mStrings.push_back( new StrTest( NULL ) );
|
||||
mStrings.push_back( new StrTest( "" ) );
|
||||
mStrings.push_back( new StrTest( "Torque" ) );
|
||||
mStrings.push_back( new StrTest( "TGEA" ) );
|
||||
mStrings.push_back( new StrTest( "GarageGames" ) );
|
||||
mStrings.push_back( new StrTest( "TGB" ) );
|
||||
mStrings.push_back( new StrTest( "games" ) );
|
||||
mStrings.push_back( new StrTest( "engine" ) );
|
||||
mStrings.push_back( new StrTest( "rocks" ) );
|
||||
mStrings.push_back( new StrTest( "technology" ) );
|
||||
mStrings.push_back( new StrTest( "Torque 3D" ) );
|
||||
mStrings.push_back( new StrTest( "Torque 2D" ) );
|
||||
|
||||
runTestOnStrings< Test1 >();
|
||||
runTestOnStrings< Test2 >();
|
||||
|
||||
runPairwiseTestOnStrings< Test3 >();
|
||||
|
||||
testEmpty();
|
||||
testTrim();
|
||||
testCompare();
|
||||
testOrder();
|
||||
testFind();
|
||||
testInsert();
|
||||
testReplace();
|
||||
testErase();
|
||||
testSubstr();
|
||||
testToString();
|
||||
testCaseConversion();
|
||||
testConcat();
|
||||
testHash();
|
||||
testIntern();
|
||||
|
||||
for( U32 i = 0; i < mStrings.size(); ++ i )
|
||||
delete mStrings[ i ];
|
||||
mStrings.clear();
|
||||
}
|
||||
};
|
||||
|
||||
CreateUnitTest( TestStringBuilder, "Util/StringBuilder" )
|
||||
{
|
||||
void run()
|
||||
{
|
||||
StringBuilder str;
|
||||
|
||||
str.append( 'f' );
|
||||
str.append( "oo" );
|
||||
str.append( String( "ba" ) );
|
||||
str.append( "rfajskfdj", 1 );
|
||||
str.format( "%s", "barfoo" );
|
||||
|
||||
TEST( str.end() == String( "foobarbarfoo" ) );
|
||||
}
|
||||
};
|
||||
|
||||
#endif // !TORQUE_SHIPPING
|
||||
|
|
@ -1,138 +0,0 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (c) 2012 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.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "unit/test.h"
|
||||
#include "console/console.h"
|
||||
#include "core/util/tVector.h"
|
||||
|
||||
|
||||
#ifndef TORQUE_SHIPPING
|
||||
|
||||
using namespace UnitTesting;
|
||||
|
||||
#define TEST( x ) test( ( x ), "FAIL: " #x )
|
||||
#define XTEST( t, x ) t->test( ( x ), "FAIL: " #x )
|
||||
|
||||
CreateUnitTest( TestVector, "Util/Vector" )
|
||||
{
|
||||
bool dtorVals[ 10 ];
|
||||
struct Dtor
|
||||
{
|
||||
bool* ptr;
|
||||
Dtor() {}
|
||||
Dtor( bool* ptr )
|
||||
: ptr( ptr ) { *ptr = false; }
|
||||
~Dtor()
|
||||
{
|
||||
*ptr = true;
|
||||
}
|
||||
};
|
||||
void testDestruction()
|
||||
{
|
||||
Vector< Dtor > v;
|
||||
|
||||
for( U32 i = 0; i < 9; ++ i )
|
||||
v.push_back( Dtor( &dtorVals[ i ] ) );
|
||||
|
||||
v.decrement();
|
||||
v.decrement( 2 );
|
||||
v.pop_back();
|
||||
v.increment();
|
||||
v.last() = Dtor( &dtorVals[ 9 ] );
|
||||
v.clear();
|
||||
|
||||
TEST( dtorVals[ 0 ] );
|
||||
TEST( dtorVals[ 1 ] );
|
||||
TEST( dtorVals[ 2 ] );
|
||||
TEST( dtorVals[ 3 ] );
|
||||
TEST( dtorVals[ 4 ] );
|
||||
TEST( dtorVals[ 5 ] );
|
||||
TEST( dtorVals[ 6 ] );
|
||||
TEST( dtorVals[ 7 ] );
|
||||
TEST( dtorVals[ 8 ] );
|
||||
TEST( dtorVals[ 9 ] );
|
||||
}
|
||||
|
||||
static S32 QSORT_CALLBACK sortInts( const int* a, const int* b )
|
||||
{
|
||||
int av = *a;
|
||||
int bv = *b;
|
||||
|
||||
if( av < bv )
|
||||
return -1;
|
||||
else if( av > bv )
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void testSort()
|
||||
{
|
||||
Vector< int > v;
|
||||
|
||||
v.push_back( 0 );
|
||||
v.push_back( 10 );
|
||||
v.push_back( 2 );
|
||||
v.push_back( 3 );
|
||||
v.push_back( 14 );
|
||||
v.push_back( 4 );
|
||||
v.push_back( 12 );
|
||||
v.push_back( 6 );
|
||||
v.push_back( 16 );
|
||||
v.push_back( 7 );
|
||||
v.push_back( 8 );
|
||||
v.push_back( 1 );
|
||||
v.push_back( 11 );
|
||||
v.push_back( 5 );
|
||||
v.push_back( 13 );
|
||||
v.push_back( 9 );
|
||||
v.push_back( 15 );
|
||||
|
||||
v.sort( sortInts );
|
||||
|
||||
TEST( v[ 0 ] == 0 );
|
||||
TEST( v[ 1 ] == 1 );
|
||||
TEST( v[ 2 ] == 2 );
|
||||
TEST( v[ 3 ] == 3 );
|
||||
TEST( v[ 4 ] == 4 );
|
||||
TEST( v[ 5 ] == 5 );
|
||||
TEST( v[ 6 ] == 6 );
|
||||
TEST( v[ 7 ] == 7 );
|
||||
TEST( v[ 8 ] == 8 );
|
||||
TEST( v[ 9 ] == 9 );
|
||||
TEST( v[ 10 ] == 10 );
|
||||
TEST( v[ 11 ] == 11 );
|
||||
TEST( v[ 12 ] == 12 );
|
||||
TEST( v[ 13 ] == 13 );
|
||||
TEST( v[ 14 ] == 14 );
|
||||
TEST( v[ 15 ] == 15 );
|
||||
TEST( v[ 16 ] == 16 );
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
testSort();
|
||||
testDestruction();
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
#include "core/crc.h"
|
||||
#include "core/strings/stringFunctions.h"
|
||||
#include "core/util/zip/zipArchive.h"
|
||||
|
|
@ -194,3 +194,4 @@ private:
|
|||
return ret;
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
#include "platform/platform.h"
|
||||
|
||||
#include "unit/test.h"
|
||||
|
|
@ -250,3 +250,4 @@ private:
|
|||
return ret;
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
#include "core/strings/stringFunctions.h"
|
||||
#include "core/util/zip/zipArchive.h"
|
||||
#include "core/util/zip/unitTests/zipTest.h"
|
||||
|
|
@ -242,3 +242,4 @@ bail:
|
|||
return ret;
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
|
@ -216,7 +216,7 @@ String ZipObject::getFileEntry(S32 idx)
|
|||
|
||||
const Zip::CentralDir &dir = (*mZipArchive)[idx];
|
||||
char buffer[1024];
|
||||
int chars = dSprintf(buffer, sizeof(buffer), "%s\t%d\t%d\t%d\t%08x",
|
||||
S32 chars = dSprintf(buffer, sizeof(buffer), "%s\t%d\t%d\t%d\t%08x",
|
||||
dir.mFilename.c_str(), dir.mUncompressedSize, dir.mCompressedSize,
|
||||
dir.mCompressMethod, dir.mCRC32);
|
||||
if (chars < sizeof(buffer))
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ public:
|
|||
}
|
||||
|
||||
virtual Path getName() const { return mZipFilename; }
|
||||
virtual Status getStatus() const
|
||||
virtual NodeStatus getStatus() const
|
||||
{
|
||||
if (mZipStream)
|
||||
{
|
||||
|
|
@ -182,7 +182,7 @@ public:
|
|||
Torque::Path getName() const { return mPath; }
|
||||
|
||||
// getStatus() doesn't appear to be used for directories
|
||||
Status getStatus() const
|
||||
NodeStatus getStatus() const
|
||||
{
|
||||
return FileNode::Open;
|
||||
}
|
||||
|
|
@ -274,7 +274,7 @@ public:
|
|||
Torque::Path getName() const { return mPath; }
|
||||
|
||||
// getStatus() doesn't appear to be used for directories
|
||||
Status getStatus() const
|
||||
NodeStatus getStatus() const
|
||||
{
|
||||
return FileNode::Open;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -651,7 +651,7 @@ bool MountSystem::unmount(FileSystemRef fs)
|
|||
// also check that fs is not null each time since its a strong ref
|
||||
// so it could be nulled during removal.
|
||||
bool unmounted = false;
|
||||
for (int i = mMountList.size() - 1; !fs.isNull() && i >= 0; --i)
|
||||
for (S32 i = mMountList.size() - 1; !fs.isNull() && i >= 0; --i)
|
||||
{
|
||||
if (mMountList[i].fileSystem.getPointer() == fs.getPointer())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ public:
|
|||
class FileNode : public FileBase
|
||||
{
|
||||
public:
|
||||
enum Status
|
||||
enum NodeStatus
|
||||
{
|
||||
Open, ///< In an open state
|
||||
Closed, ///< In a closed state
|
||||
|
|
@ -122,7 +122,7 @@ public:
|
|||
|
||||
// Properties
|
||||
virtual Path getName() const = 0;
|
||||
virtual Status getStatus() const = 0;
|
||||
virtual NodeStatus getStatus() const = 0;
|
||||
|
||||
virtual bool getAttributes(Attributes*) = 0;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue