From: <axl...@us...> - 2010-06-30 01:43:32
|
Revision: 753 http://hgengine.svn.sourceforge.net/hgengine/?rev=753&view=rev Author: axlecrusher Date: 2010-06-30 01:43:25 +0000 (Wed, 30 Jun 2010) Log Message: ----------- Reorganize headers and math data structures to allow for much easier inclusion into tools. Tools no longer need to pull in a huge mess of HG2 source files when compiling. Modified Paths: -------------- Mercury2/src/AlignedBuffer.h Mercury2/src/Camera.cpp Mercury2/src/MQuaternion.cpp Mercury2/src/MQuaternion.h Mercury2/src/MercuryAsset.h Mercury2/src/MercuryCrash.c Mercury2/src/MercuryCrash.h Mercury2/src/MercuryFile.cpp Mercury2/src/MercuryFile.h Mercury2/src/MercuryHash.h Mercury2/src/MercuryLog.h Mercury2/src/MercuryMatrix.cpp Mercury2/src/MercuryMatrix.h Mercury2/src/MercuryMessageManager.h Mercury2/src/MercuryNamedResource.cpp Mercury2/src/MercuryPrefs.cpp Mercury2/src/MercuryPrefs.h Mercury2/src/MercurySound.h Mercury2/src/MercuryTheme.cpp Mercury2/src/MercuryTheme.h Mercury2/src/MercuryUtil.cpp Mercury2/src/MercuryUtil.h Mercury2/src/MercuryValue.cpp Mercury2/src/MercuryVector.h Mercury2/src/MercuryVertex.cpp Mercury2/src/MercuryVertex.h Mercury2/src/MercuryWindow.h Mercury2/src/ModuleManager.h Mercury2/src/RawImageData.h Mercury2/src/XMLParser.cpp Added Paths: ----------- Mercury2/src/InstanceCounter.h Mercury2/src/MercuryStringUtil.cpp Mercury2/src/MercuryStringUtil.h Modified: Mercury2/src/AlignedBuffer.h =================================================================== --- Mercury2/src/AlignedBuffer.h 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/AlignedBuffer.h 2010-06-30 01:43:25 UTC (rev 753) @@ -1,6 +1,7 @@ #ifndef ALIGNEDBUFFER_H #define ALIGNEDBUFFER_H +#include <MercuryUtil.h> #include <Mint.h> template <typename T> Modified: Mercury2/src/Camera.cpp =================================================================== --- Mercury2/src/Camera.cpp 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/Camera.cpp 2010-06-30 01:43:25 UTC (rev 753) @@ -51,7 +51,7 @@ //compute the world space look vector (broken if camera is in transform node) m_lookAt = MercuryVector(0,0,-1); //by default camera looks down world Z - m_lookAt = m_lookAt.Rotate( r ); + m_lookAt = RotateVector(m_lookAt,r); m_lookAt.NormalizeSelf(); LOOKAT = m_lookAt; @@ -102,7 +102,8 @@ MQuaternion qLeftRight = MQuaternion::CreateFromAxisAngle(MercuryVector(0,1,0), m_x); MercuryVector LocalX = MercuryVector( 1, 0, 0 ); - LocalX = LocalX.Rotate( qLeftRight ); + LocalX = RotateVector( LocalX,qLeftRight ); + MQuaternion qUpDown = MQuaternion::CreateFromAxisAngle(LocalX, m_y); Added: Mercury2/src/InstanceCounter.h =================================================================== --- Mercury2/src/InstanceCounter.h (rev 0) +++ Mercury2/src/InstanceCounter.h 2010-06-30 01:43:25 UTC (rev 753) @@ -0,0 +1,39 @@ +#ifndef INSTANCECOUNTER_H +#define INSTANCECOUNTER_H + +//This counter is used with singletons to +//ensure proper destruction order of the +//singleton +template<typename T> +class InstanceCounter +{ + public: + InstanceCounter(const MString & name) + :m_name(name) + { + if (m_count == 0) + { + printf("Creating instance %s\n", m_name.c_str()); + m_instance = &T::GetInstance(); + } + ++m_count; + } + ~InstanceCounter() + { + --m_count; + if (m_count == 0) + { + printf("Destroying instance %s\n", m_name.c_str()); + SAFE_DELETE(m_instance); + } + } + private: + static unsigned long m_count; + MString m_name; + T* m_instance; +}; + +template<typename T> + unsigned long InstanceCounter<T>::m_count = 0; + +#endif Modified: Mercury2/src/MQuaternion.cpp =================================================================== --- Mercury2/src/MQuaternion.cpp 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/MQuaternion.cpp 2010-06-30 01:43:25 UTC (rev 753) @@ -359,6 +359,10 @@ matrix[3][3] = 1; } +MercuryVertex RotateVector(const MercuryVertex& v, const MQuaternion& q) +{ + return (q * MQuaternion(0, v) * q.reciprocal()).ToVector(); +} /**************************************************************************** * Copyright (C) 2009 by Joshua Allen, Charles Lohr, Adam Lowman * Modified: Mercury2/src/MQuaternion.h =================================================================== --- Mercury2/src/MQuaternion.h 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/MQuaternion.h 2010-06-30 01:43:25 UTC (rev 753) @@ -91,6 +91,8 @@ ///Spherically interpolate between two quaternions t = 0..1 MQuaternion SLERP( const MQuaternion &a, const MQuaternion &b,float t); +MercuryVertex RotateVector(const MercuryVertex& v, const MQuaternion& q); + #endif /**************************************************************************** Modified: Mercury2/src/MercuryAsset.h =================================================================== --- Mercury2/src/MercuryAsset.h 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/MercuryAsset.h 2010-06-30 01:43:25 UTC (rev 753) @@ -9,7 +9,7 @@ #include <XMLParser.h> #include <Callback.h> #include <MercuryLog.h> - +#include <MercuryStringUtil.h> #include <MercuryHash.h> #include <list> Modified: Mercury2/src/MercuryCrash.c =================================================================== --- Mercury2/src/MercuryCrash.c 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/MercuryCrash.c 2010-06-30 01:43:25 UTC (rev 753) @@ -187,6 +187,15 @@ return exceptions[i].name; } +void fail_m( const char * message, const char * file, int line ) +{ + char backtracebuffer[2048]; + //Probably should message box here somewhere in the event we're running on Windows. + fprintf( stderr, "Fatal Error: \"%s\" in %s:%d\n", message, file, line ); + cnget_backtrace( 1, backtracebuffer, 2047 ); + puts( backtracebuffer ); + exit(-1); +} /* * (c) 2003-2008 Glenn Maynard, Steve Checkoway, Avery Lee, Charles Lohr Modified: Mercury2/src/MercuryCrash.h =================================================================== --- Mercury2/src/MercuryCrash.h 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/MercuryCrash.h 2010-06-30 01:43:25 UTC (rev 753) @@ -11,10 +11,14 @@ int cnset_execute_on_crash( FNType fn ); const char * cn_get_crash_description( int code ); +void fail_m( const char * message, const char * file, int line ); + #ifdef __cplusplus }; #endif +#define FAIL( message ) fail_m( message, __FILE__, __LINE__ ); + #endif Modified: Mercury2/src/MercuryFile.cpp =================================================================== --- Mercury2/src/MercuryFile.cpp 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/MercuryFile.cpp 2010-06-30 01:43:25 UTC (rev 753) @@ -6,8 +6,8 @@ #include "MercuryFileDriverZipped.h" #include "MercuryFileDriverPacked.h" #include "MercuryTheme.h" +#include <MercuryStringUtil.h> - /********************FILE MANAGER**************************/ MercuryFileManager::MercuryFileManager() @@ -134,7 +134,47 @@ return true; } +long FileToString( const MString & sFileName, char * & data ) +{ + data = 0; + MercuryFile * f = FILEMAN.Open( sFileName ); + if( !f ) return -1; + + int length = f->Length(); + + data = (char*)malloc( length + 1 ); + + if( !data ) + { + data = 0; + delete f; + return -1; + } + + int r = f->Read( data, length ); + + delete f; + + if( r != length ) + { + free( data ); + data = 0; + return -1; + } + + return length; +} + +bool StringToFile( const MString & sFileName, const MString & data ) +{ + MercuryFile * f = FILEMAN.Open( sFileName, MFP_WRITE_ONLY ); + if( !f ) return false; + f->Write( data.c_str(), data.length() ); + delete f; + return true; +} + MercuryFileManager& MercuryFileManager::GetInstance() { static MercuryFileManager* instance = NULL; Modified: Mercury2/src/MercuryFile.h =================================================================== --- Mercury2/src/MercuryFile.h 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/MercuryFile.h 2010-06-30 01:43:25 UTC (rev 753) @@ -3,6 +3,7 @@ #include <MAutoPtr.h> #include <MercuryUtil.h> +#include <InstanceCounter.h> //Forward decleration, as there's no real need to have this included unless we _need_ it. template< typename t > @@ -93,7 +94,13 @@ MVector< MAutoPtr< MercuryFileDriver> > * m_Drivers; }; +///Open up filename: sFileName and dump it into a new buffer; you must delete the return value when done. +///The return value is -1 if there was an issue, otherwise it is valid. +long FileToString( const MString & sFileName, char * & data ); +///Take a string and write it to the hard drive as a file. True indicates everything is okay. +bool StringToFile( const MString & sFileName, const MString & data ); + static InstanceCounter<MercuryFileManager> MFMcounter("MercuryFileManager"); #define FILEMAN MercuryFileManager::GetInstance() Modified: Mercury2/src/MercuryHash.h =================================================================== --- Mercury2/src/MercuryHash.h 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/MercuryHash.h 2010-06-30 01:43:25 UTC (rev 753) @@ -4,6 +4,7 @@ #include "global.h" #include <MercuryVector.h> #include <assert.h> +#include <MercuryString.h> ///Mercury Hash Table for Strings template<typename T> Modified: Mercury2/src/MercuryLog.h =================================================================== --- Mercury2/src/MercuryLog.h 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/MercuryLog.h 2010-06-30 01:43:25 UTC (rev 753) @@ -4,8 +4,8 @@ #include <list> #include <MercuryString.h> #include <MercuryThreads.h> - #include <MercuryUtil.h> +#include <InstanceCounter.h> class MercuryLog { Modified: Mercury2/src/MercuryMatrix.cpp =================================================================== --- Mercury2/src/MercuryMatrix.cpp 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/MercuryMatrix.cpp 2010-06-30 01:43:25 UTC (rev 753) @@ -1,5 +1,5 @@ #include "MercuryMatrix.h" -#include <MercuryLog.h> +//#include <MercuryLog.h> MercuryMatrixMemory::MercuryMatrixMemory() { @@ -271,7 +271,7 @@ MatrixMultiply4f ( m_matrix, m.m_matrix, r.m_matrix); return r; } - +/* void MercuryMatrix::Print() const { for (int i = 0; i < 4; ++i) @@ -280,7 +280,7 @@ } LOG.Write("\n"); } - +*/ MercuryVector MercuryMatrix::operator*(const MercuryVector& v) const { MercuryVector r; Modified: Mercury2/src/MercuryMatrix.h =================================================================== --- Mercury2/src/MercuryMatrix.h 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/MercuryMatrix.h 2010-06-30 01:43:25 UTC (rev 753) @@ -6,7 +6,7 @@ #include "MercuryUtil.h" #include <MercuryVertex.h> #include <MQuaternion.h> - +#include <InstanceCounter.h> #include <list> #include <MSemaphore.h> Modified: Mercury2/src/MercuryMessageManager.h =================================================================== --- Mercury2/src/MercuryMessageManager.h 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/MercuryMessageManager.h 2010-06-30 01:43:25 UTC (rev 753) @@ -13,6 +13,7 @@ #include <MAutoPtr.h> #include <MSemaphore.h> #include <MercuryValue.h> +#include <InstanceCounter.h> class MessageHolder : public RefBase { Modified: Mercury2/src/MercuryNamedResource.cpp =================================================================== --- Mercury2/src/MercuryNamedResource.cpp 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/MercuryNamedResource.cpp 2010-06-30 01:43:25 UTC (rev 753) @@ -1,5 +1,5 @@ #include <MercuryNamedResource.h> -#include <MercuryUtil.h> +#include <MercuryStringUtil.h> #include <stdio.h> MString MercuryNamedResource::GetValueS( const MString & sDataPointer ) Modified: Mercury2/src/MercuryPrefs.cpp =================================================================== --- Mercury2/src/MercuryPrefs.cpp 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/MercuryPrefs.cpp 2010-06-30 01:43:25 UTC (rev 753) @@ -1,5 +1,6 @@ #include <MercuryPrefs.h> #include <XMLParser.h> +#include <MercuryCrash.h> MercuryPreferences & MercuryPreferences::GetInstance() { Modified: Mercury2/src/MercuryPrefs.h =================================================================== --- Mercury2/src/MercuryPrefs.h 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/MercuryPrefs.h 2010-06-30 01:43:25 UTC (rev 753) @@ -3,6 +3,7 @@ #include <MercuryNamedResource.h> #include <MercuryUtil.h> +#include <InstanceCounter.h> class XMLNode; class XMLDocument; Modified: Mercury2/src/MercurySound.h =================================================================== --- Mercury2/src/MercurySound.h 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/MercurySound.h 2010-06-30 01:43:25 UTC (rev 753) @@ -6,6 +6,7 @@ #include <MAutoPtr.h> #include <MercuryHash.h> #include <MercuryVector.h> +#include <InstanceCounter.h> class MercurySoundSource : public RefBase { Added: Mercury2/src/MercuryStringUtil.cpp =================================================================== --- Mercury2/src/MercuryStringUtil.cpp (rev 0) +++ Mercury2/src/MercuryStringUtil.cpp 2010-06-30 01:43:25 UTC (rev 753) @@ -0,0 +1,207 @@ +#include <MercuryStringUtil.h> + +MString ConvertToCFormat( const MString & ncf ) +{ + MString ret; + const char* nccf = ncf.c_str(); + + for ( int i = 0; (unsigned)i < ncf.length(); i++ ) + { + switch ( nccf[i] ) + { + case '\t': ret += "\\t"; break; + case '\n': ret += "\\n"; break; + case '\r': ret += "\\r"; break; + case '\f': ret += "\\f"; break; + case '\b': ret += "\\b"; break; + case '\\': ret += "\\\\"; break; + case '\'': ret += "\\\'"; break; + case '\"': ret += "\\\""; break; + default: + if( nccf[i] < 32 ) + { + ret += "\\"; + ret += ((unsigned char)nccf[i]/64)%8 + '0'; + ret += ((unsigned char)nccf[i]/8)%8 + '0'; + ret += (unsigned char)nccf[i]%8 + '0'; + } else + ret += nccf[i]; + } + } + return ret; +} + +MString ConvertToUnformatted( const MString & cf ) +{ + MString ret; + const char* ccf = cf.c_str(); + + for ( int i = 0; (unsigned)i < cf.length(); i++ ) + { + switch ( ccf[i] ) + { + case '\\': + i++; + if ( (unsigned)i >= cf.length() ) + return ret; + switch ( ccf[i] ) + { + case 't': ret += '\t'; break; + case 'n': ret += '\n'; break; + case 'r': ret += '\r'; break; + case 'f': ret += '\f'; break; + case 'b': ret += '\b'; break; + case '\\': ret += '\\'; break; + case '\'': ret += '\''; break; + case '\"': ret += '\"'; break; + default: + if( ccf[i] >= '0' && ccf[i] <= '7' ) + { + char c = ccf[i] - '0'; + if( ccf[i+1] >= '0' && ccf[i+1] <= '8' ) + { + i++; + c = c * 8 + ccf[i] - '0'; + } + if( ccf[i+1] >= '0' && ccf[i+1] <= '8' ) + { + i++; + c = c * 8 + ccf[i] - '0'; + } + ret += c; + } + } + break; + default: + ret += ccf[i]; + } + } + return ret; +} + +MString ToUpper(const MString& s) +{ + MString t = s; + char * ti = (char*)t.c_str(); + for (unsigned long i = 0; i < s.length(); ++i) + { + if( ti[i] >= 'a' && ti[i] <= 'z' ) + ti[i] -= ( 'a' - 'A' ); + } + return t; +} + +MString ToLower(const MString & s) +{ + MString t = s; + char * ti = (char*)t.c_str(); + for (unsigned long i = 0; i < s.length(); ++i) + { + if( ti[i] >= 'A' && ti[i] <= 'Z' ) + ti[i] += ( 'a' - 'A' ); + } + return t; +} + +MString ToProper(const MString & s) +{ + if( s.length() == 0 ) + return ""; + + MString t = s; + char * ti = (char*)t.c_str(); + + if( ti[0] >= 'a' && ti[0] <= 'z' ) + ti[0] -= ( 'a' - 'A' ); + + for (unsigned long i = 1; i < s.length(); ++i) + { + if( ti[i] >= 'A' && ti[i] <= 'Z' ) + ti[i] += ( 'a' - 'A' ); + } + return t; + +} + + + +float StrToFloat(const MString & s, float d) +{ + float x = d; +#if defined( WIN32 ) && !defined( LEAN_HG ) + if ( s.length() > 0) sscanf_s(s.c_str(), "%f", &x); +#else + if ( s.length() > 0) sscanf(s.c_str(), "%f", &x); +#endif + return x; +} + +int32_t StrToInt(const MString & s, int32_t d) +{ + int32_t x = d; +#if defined( WIN32 ) && !defined( LEAN_HG ) + if ( s.length() > 0) sscanf_s(s.c_str(), "%d", &x); +#else + if ( s.length() > 0) sscanf(s.c_str(), "%d", &x); +#endif + return x; +} + +bool StrToBool( const MString & s, bool d ) +{ + MString tmpret = s; + + tmpret = ToUpper( tmpret ); + if( tmpret.compare( "TRUE" ) == 0 ) return 1; + if( tmpret.compare( "FALSE" ) == 0 ) return 0; + if( tmpret.compare( "ON" ) == 0 ) return 1; + if( tmpret.compare( "OFF" ) == 0 ) return 0; + if( tmpret.compare( "YES" ) == 0 ) return 1; + if( tmpret.compare( "NO" ) == 0 ) return 0; + + return StrToInt( tmpret, d ) != 0; +} + +void SplitStrings( const MString & in, MVector < MString > & out, + const char * termin, const char * whitespace, + long termlen, long wslen ) +{ + const char * inStr = in.c_str(); + long curPos = 0; + long inLen = in.length(); + while ( curPos < inLen ) + { + curPos += BytesNUntil( inStr, whitespace, curPos, inLen, wslen ); + long NextPos = BytesUntil( inStr, termin, curPos, inLen, termlen ); + out.push_back( in.substr( curPos, NextPos ) ); + curPos += NextPos + 1; + } +} + + +/* Copyright (c) 2010, Joshua Allen and Charles Lohr + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the distribution. + * - Neither the name of the Mercury Engine nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ Added: Mercury2/src/MercuryStringUtil.h =================================================================== --- Mercury2/src/MercuryStringUtil.h (rev 0) +++ Mercury2/src/MercuryStringUtil.h 2010-06-30 01:43:25 UTC (rev 753) @@ -0,0 +1,58 @@ +#ifndef MERCURYSTRINGUTIL_H +#define MERCURYSTRINGUTIL_H + +#include <MercuryString.h> +#include <Mint.h> +#include <MercuryVector.h> + +///Make a string all upper case +MString ToUpper(const MString & s); + +///Make a string all lower case +MString ToLower(const MString & s); + +///Make a string proper case (HELLO -> Hello, hello -> Hello) +MString ToProper(const MString & s); + +float StrToFloat(const MString & s, float d = 0); +int32_t StrToInt(const MString & s, int32_t d = 0); +bool StrToBool( const MString & s, bool d = false ); + +///Split given string into other strings using delimiters from termin +void SplitStrings( const MString & in, MVector < MString > & out, const char * termin, const char * whitespace, long termlen, long wslen ); + +///Convert string containing binary characters to C-style formatted string. +MString ConvertToCFormat( const MString & ncf ); + +///Convert a C-style formatted string into it's binary string equivalent. +MString ConvertToUnformatted( const MString & cf ); + +#endif + + +/* Copyright (c) 2010, Joshua Allen and Charles Lohr + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the distribution. + * - Neither the name of the Mercury Engine nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ Modified: Mercury2/src/MercuryTheme.cpp =================================================================== --- Mercury2/src/MercuryTheme.cpp 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/MercuryTheme.cpp 2010-06-30 01:43:25 UTC (rev 753) @@ -1,6 +1,8 @@ #include <MercuryTheme.h> #include <MercuryPrefs.h> #include <XMLParser.h> +#include <MercuryCrash.h> +#include <MercuryStringUtil.h> #define MAX_THEMES 100 Modified: Mercury2/src/MercuryTheme.h =================================================================== --- Mercury2/src/MercuryTheme.h 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/MercuryTheme.h 2010-06-30 01:43:25 UTC (rev 753) @@ -2,9 +2,9 @@ #define _MERCURY_THEME_H #include <MercuryNamedResource.h> -#include <MercuryUtil.h> //huh? #include <MercuryHash.h> #include <MercuryVector.h> +#include <InstanceCounter.h> class XMLNode; class XMLDocument; Modified: Mercury2/src/MercuryUtil.cpp =================================================================== --- Mercury2/src/MercuryUtil.cpp 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/MercuryUtil.cpp 2010-06-30 01:43:25 UTC (rev 753) @@ -1,8 +1,5 @@ #include <MercuryUtil.h> -#include <MercuryFile.h> #include <Mint.h> -#include <MercuryVector.h> -#include <MercuryBacktrace.h> #include <math.h> #ifdef WIN32 @@ -11,179 +8,6 @@ #include <unistd.h> #endif -MString ConvertToCFormat( const MString & ncf ) -{ - MString ret; - const char* nccf = ncf.c_str(); - - for ( int i = 0; (unsigned)i < ncf.length(); i++ ) - { - switch ( nccf[i] ) - { - case '\t': ret += "\\t"; break; - case '\n': ret += "\\n"; break; - case '\r': ret += "\\r"; break; - case '\f': ret += "\\f"; break; - case '\b': ret += "\\b"; break; - case '\\': ret += "\\\\"; break; - case '\'': ret += "\\\'"; break; - case '\"': ret += "\\\""; break; - default: - if( nccf[i] < 32 ) - { - ret += "\\"; - ret += ((unsigned char)nccf[i]/64)%8 + '0'; - ret += ((unsigned char)nccf[i]/8)%8 + '0'; - ret += (unsigned char)nccf[i]%8 + '0'; - } else - ret += nccf[i]; - } - } - return ret; -} - -MString ConvertToUnformatted( const MString & cf ) -{ - MString ret; - const char* ccf = cf.c_str(); - - for ( int i = 0; (unsigned)i < cf.length(); i++ ) - { - switch ( ccf[i] ) - { - case '\\': - i++; - if ( (unsigned)i >= cf.length() ) - return ret; - switch ( ccf[i] ) - { - case 't': ret += '\t'; break; - case 'n': ret += '\n'; break; - case 'r': ret += '\r'; break; - case 'f': ret += '\f'; break; - case 'b': ret += '\b'; break; - case '\\': ret += '\\'; break; - case '\'': ret += '\''; break; - case '\"': ret += '\"'; break; - default: - if( ccf[i] >= '0' && ccf[i] <= '7' ) - { - char c = ccf[i] - '0'; - if( ccf[i+1] >= '0' && ccf[i+1] <= '8' ) - { - i++; - c = c * 8 + ccf[i] - '0'; - } - if( ccf[i+1] >= '0' && ccf[i+1] <= '8' ) - { - i++; - c = c * 8 + ccf[i] - '0'; - } - ret += c; - } - } - break; - default: - ret += ccf[i]; - } - } - return ret; -} - -MString ToUpper(const MString& s) -{ - MString t = s; - char * ti = (char*)t.c_str(); - for (unsigned long i = 0; i < s.length(); ++i) - { - if( ti[i] >= 'a' && ti[i] <= 'z' ) - ti[i] -= ( 'a' - 'A' ); - } - return t; -} - -MString ToLower(const MString & s) -{ - MString t = s; - char * ti = (char*)t.c_str(); - for (unsigned long i = 0; i < s.length(); ++i) - { - if( ti[i] >= 'A' && ti[i] <= 'Z' ) - ti[i] += ( 'a' - 'A' ); - } - return t; -} - -MString ToProper(const MString & s) -{ - if( s.length() == 0 ) - return ""; - - MString t = s; - char * ti = (char*)t.c_str(); - - if( ti[0] >= 'a' && ti[0] <= 'z' ) - ti[0] -= ( 'a' - 'A' ); - - for (unsigned long i = 1; i < s.length(); ++i) - { - if( ti[i] >= 'A' && ti[i] <= 'Z' ) - ti[i] += ( 'a' - 'A' ); - } - return t; - -} - - - -float StrToFloat(const MString & s, float d) -{ - float x = d; -#if defined( WIN32 ) && !defined( LEAN_HG ) - if ( s.length() > 0) sscanf_s(s.c_str(), "%f", &x); -#else - if ( s.length() > 0) sscanf(s.c_str(), "%f", &x); -#endif - return x; -} - -int32_t StrToInt(const MString & s, int32_t d) -{ - int32_t x = d; -#if defined( WIN32 ) && !defined( LEAN_HG ) - if ( s.length() > 0) sscanf_s(s.c_str(), "%d", &x); -#else - if ( s.length() > 0) sscanf(s.c_str(), "%d", &x); -#endif - return x; -} - -bool StrToBool( const MString & s, bool d ) -{ - MString tmpret = s; - - tmpret = ToUpper( tmpret ); - if( tmpret.compare( "TRUE" ) == 0 ) return 1; - if( tmpret.compare( "FALSE" ) == 0 ) return 0; - if( tmpret.compare( "ON" ) == 0 ) return 1; - if( tmpret.compare( "OFF" ) == 0 ) return 0; - if( tmpret.compare( "YES" ) == 0 ) return 1; - if( tmpret.compare( "NO" ) == 0 ) return 0; - - return StrToInt( tmpret, d ) != 0; -} - - -void fail_m( const char * message, const char * file, int line ) -{ - char backtracebuffer[2048]; - //Probably should message box here somewhere in the event we're running on Windows. - fprintf( stderr, "Fatal Error: \"%s\" in %s:%d\n", message, file, line ); - cnget_backtrace( 1, backtracebuffer, 2047 ); - puts( backtracebuffer ); - exit(-1); -} - void* mmemalign(size_t align, size_t size, void*& mem) { uintptr_t mask = ~(uintptr_t)(align - 1); @@ -197,48 +21,6 @@ return (uintptr_t(mem) % align) == 0; } -long FileToString( const MString & sFileName, char * & data ) -{ - data = 0; - - MercuryFile * f = FILEMAN.Open( sFileName ); - if( !f ) return -1; - - int length = f->Length(); - - data = (char*)malloc( length + 1 ); - - if( !data ) - { - data = 0; - delete f; - return -1; - } - - int r = f->Read( data, length ); - - delete f; - - if( r != length ) - { - free( data ); - data = 0; - return -1; - } - - return length; -} - -bool StringToFile( const MString & sFileName, const MString & data ) -{ - MercuryFile * f = FILEMAN.Open( sFileName, MFP_WRITE_ONLY ); - if( !f ) return false; - f->Write( data.c_str(), data.length() ); - delete f; - return true; -} - - int GeneralUsePrimes[] = { 3, 13, 37, 73, 131, 229, 337, 821, 2477, 4594, 8941, 14797, 24953, 39041, 60811, 104729 }; int GetAPrime( int ith ) @@ -274,22 +56,6 @@ return i - start; } -void SplitStrings( const MString & in, MVector < MString > & out, - const char * termin, const char * whitespace, - long termlen, long wslen ) -{ - const char * inStr = in.c_str(); - long curPos = 0; - long inLen = in.length(); - while ( curPos < inLen ) - { - curPos += BytesNUntil( inStr, whitespace, curPos, inLen, wslen ); - long NextPos = BytesUntil( inStr, termin, curPos, inLen, termlen ); - out.push_back( in.substr( curPos, NextPos ) ); - curPos += NextPos + 1; - } -} - void msleep(uint32_t msec) { #ifdef WIN32 Modified: Mercury2/src/MercuryUtil.h =================================================================== --- Mercury2/src/MercuryUtil.h 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/MercuryUtil.h 2010-06-30 01:43:25 UTC (rev 753) @@ -2,7 +2,6 @@ #define MERCURYUTIL_H #include <stdlib.h> -#include <MercuryString.h> #include <global.h> #include <stdio.h> @@ -12,26 +11,10 @@ #define TO_ENDIAN( x ) -void fail_m( const char * message, const char * file, int line ); -#define FAIL( message ) fail_m( message, __FILE__, __LINE__ ); - //returns an aligned pointer, mem is the actual (unaligned) pointer for freeing void* mmemalign(size_t align, size_t size, void*& mem); bool isAligned(size_t align, const void* mem); -///Make a string all upper case -MString ToUpper(const MString & s); - -///Make a string all lower case -MString ToLower(const MString & s); - -///Make a string proper case (HELLO -> Hello, hello -> Hello) -MString ToProper(const MString & s); - -float StrToFloat(const MString & s, float d = 0); -int32_t StrToInt(const MString & s, int32_t d = 0); -bool StrToBool( const MString & s, bool d = false ); - template<typename T> const T& MAX(const T& t1, const T& t2) { @@ -52,48 +35,6 @@ return value; } -//This counter is used with singletons to -//ensure proper destruction order of the -//singleton -template<typename T> -class InstanceCounter -{ - public: - InstanceCounter(const MString & name) - :m_name(name) - { - if (m_count == 0) - { - printf("Creating instance %s\n", m_name.c_str()); - m_instance = &T::GetInstance(); - } - ++m_count; - } - ~InstanceCounter() - { - --m_count; - if (m_count == 0) - { - printf("Destroying instance %s\n", m_name.c_str()); - SAFE_DELETE(m_instance); - } - } - private: - static unsigned long m_count; - MString m_name; - T* m_instance; -}; - -template<typename T> - unsigned long InstanceCounter<T>::m_count = 0; - -///Open up filename: sFileName and dump it into a new buffer; you must delete the return value when done. -///The return value is -1 if there was an issue, otherwise it is valid. -long FileToString( const MString & sFileName, char * & data ); - -///Take a string and write it to the hard drive as a file. True indicates everything is okay. -bool StringToFile( const MString & sFileName, const MString & data ); - /* These two functions are very different */ /// nextPow2 will go to the NEXT power of 2 even if x is already a power of 2. inline int nextPow2(int x) { int num = 1; while(num <= x) num <<= 1; return num; } @@ -119,15 +60,6 @@ ///Bytes until something other than a terminal long BytesNUntil( const char* strin, const char * termin, long start, long slen, long termlen ); -///Split given string into other strings using delimiters from termin -void SplitStrings( const MString & in, MVector < MString > & out, const char * termin, const char * whitespace, long termlen, long wslen ); - -///Convert string containing binary characters to C-style formatted string. -MString ConvertToCFormat( const MString & ncf ); - -///Convert a C-style formatted string into it's binary string equivalent. -MString ConvertToUnformatted( const MString & cf ); - ///millisecond sleep void msleep(uint32_t msec); Modified: Mercury2/src/MercuryValue.cpp =================================================================== --- Mercury2/src/MercuryValue.cpp 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/MercuryValue.cpp 2010-06-30 01:43:25 UTC (rev 753) @@ -1,8 +1,8 @@ #include <MercuryMessageManager.h> #include <MercuryValue.h> #include <MessageHandler.h> +#include <MercuryStringUtil.h> - DelegateNotifierList::DelegateNotifierList( DeletionNotifier nf, MessageHandler * no ) : NotifyFunction( nf ), NotifyObject( no ), Next( NULL ) { Modified: Mercury2/src/MercuryVector.h =================================================================== --- Mercury2/src/MercuryVector.h 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/MercuryVector.h 2010-06-30 01:43:25 UTC (rev 753) @@ -2,6 +2,7 @@ #define _MERCURY_VECTOR_H #include <string.h> +#include <stdlib.h> ///Stripped down and fast vector class template<typename T> Modified: Mercury2/src/MercuryVertex.cpp =================================================================== --- Mercury2/src/MercuryVertex.cpp 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/MercuryVertex.cpp 2010-06-30 01:43:25 UTC (rev 753) @@ -1,10 +1,7 @@ #include <MercuryVertex.h> #include <MercuryUtil.h> #include <MercuryMath.h> -#include <MQuaternion.h> -#include <MercuryMatrix.h> - MercuryVertex::MercuryVertex() { m_xyzw[0] = m_xyzw[1] = m_xyzw[2] = m_xyzw[3] = 0; @@ -127,22 +124,6 @@ return dp; } -MercuryVertex MercuryVertex::operator*(const MercuryMatrix& m) const -{ - MercuryVertex r; - MercuryVertex v1(m[0][0], m[1][0], m[2][0], m[3][0]); - MercuryVertex v2(m[0][1], m[1][1], m[2][1], m[3][1]); - MercuryVertex v3(m[0][2], m[1][2], m[2][2], m[3][2]); - MercuryVertex v4(m[0][3], m[1][3], m[2][3], m[3][3]); - - r[0] = ((*this)*v1).AddComponents(); - r[1] = ((*this)*v2).AddComponents(); - r[2] = ((*this)*v3).AddComponents(); - r[3] = ((*this)*v4).AddComponents(); - - return r; -} - float MercuryVertex::AddComponents() const { return GetX() + GetY() + GetZ() + GetW(); @@ -153,11 +134,6 @@ return ssprintf("%s: %f %f %f %f", s.c_str(), m_xyzw[0], m_xyzw[1], m_xyzw[2], m_xyzw[3]); } -MercuryVertex MercuryVertex::Rotate(const MQuaternion& q) const -{ - return (q * MQuaternion(0, *this) * q.reciprocal()).ToVector(); -} - MercuryVertex MercuryVertex::CreateFromString(const MString& s) { float x,y,z; Modified: Mercury2/src/MercuryVertex.h =================================================================== --- Mercury2/src/MercuryVertex.h 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/MercuryVertex.h 2010-06-30 01:43:25 UTC (rev 753) @@ -10,8 +10,6 @@ #define __inline__ inline #endif -class MQuaternion; -class MercuryMatrix; class MercuryVertex { @@ -62,9 +60,6 @@ const MercuryVertex& operator /= (const MercuryVertex& p); inline MercuryVertex operator * (const MercuryVertex& p) const { MercuryVertex r(*this); r*=p; return r; } inline MercuryVertex operator / (const MercuryVertex& p) const { MercuryVertex r(*this); r/=p; return r; } - - MercuryVertex operator*(const MercuryMatrix& m) const; - inline MercuryVertex& operator += ( const MercuryVertex& other ) { m_xyzw[0]+=other[0]; m_xyzw[1]+=other[1]; m_xyzw[2]+=other[2]; return *this; } inline MercuryVertex& operator -= ( const MercuryVertex& other ) { m_xyzw[0]-=other[0]; m_xyzw[1]-=other[1]; m_xyzw[2]-=other[2]; return *this; } @@ -89,9 +84,7 @@ MercuryVertex DotProduct3(const MercuryVertex& rhs1, const MercuryVertex& rhs2, const MercuryVertex& rhs3) const; MString Stringify(const MString& s = "Vertex") const; - - MercuryVertex Rotate(const MQuaternion& q) const; - + float AddComponents() const; static MercuryVertex CreateFromString(const MString& s); Modified: Mercury2/src/MercuryWindow.h =================================================================== --- Mercury2/src/MercuryWindow.h 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/MercuryWindow.h 2010-06-30 01:43:25 UTC (rev 753) @@ -3,6 +3,7 @@ #include <global.h> #include <MercuryUtil.h> +#include <MercuryStringUtil.h> #include <list> #include <Callback.h> Modified: Mercury2/src/ModuleManager.h =================================================================== --- Mercury2/src/ModuleManager.h 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/ModuleManager.h 2010-06-30 01:43:25 UTC (rev 753) @@ -4,6 +4,7 @@ #include <MercuryUtil.h> #include <MercuryHash.h> #include <MercuryThreads.h> +#include <InstanceCounter.h> #ifdef INSTANCE_WATCH #include <set> Modified: Mercury2/src/RawImageData.h =================================================================== --- Mercury2/src/RawImageData.h 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/RawImageData.h 2010-06-30 01:43:25 UTC (rev 753) @@ -2,6 +2,7 @@ #define RAWIMAGEDATA_H #include <MercuryUtil.h> +#include <MercuryStringUtil.h> enum ColorByteType { Modified: Mercury2/src/XMLParser.cpp =================================================================== --- Mercury2/src/XMLParser.cpp 2010-06-29 03:47:54 UTC (rev 752) +++ Mercury2/src/XMLParser.cpp 2010-06-30 01:43:25 UTC (rev 753) @@ -1,6 +1,7 @@ #include <XMLParser.h> #include <MercuryFile.h> #include <MercuryVector.h> +#include <MercuryStringUtil.h> #include <libxml/parser.h> #include <libxml/tree.h> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |