diff --git a/source/graphics/ObjectEntry.h b/source/graphics/ObjectEntry.h index 1270ec8baa..0bbbf8b853 100755 --- a/source/graphics/ObjectEntry.h +++ b/source/graphics/ObjectEntry.h @@ -6,6 +6,7 @@ class CSkeletonAnim; struct SPropPoint; #include +#include #include "CStr.h" #include "ObjectBase.h" #include "Overlay.h" diff --git a/source/gui/GUItext.cpp b/source/gui/GUItext.cpp index bd37c49809..96567c1091 100755 --- a/source/gui/GUItext.cpp +++ b/source/gui/GUItext.cpp @@ -18,8 +18,8 @@ gee@pyro.nu using namespace std; -static const TCHAR TagStart = '['; -static const TCHAR TagEnd = ']'; +static const wchar_t TagStart = '['; +static const wchar_t TagEnd = ']'; void CGUIString::SFeedback::Reset() { diff --git a/source/gui/GUIutil.cpp b/source/gui/GUIutil.cpp index bf949faab0..e7802cfd74 100755 --- a/source/gui/GUIutil.cpp +++ b/source/gui/GUIutil.cpp @@ -47,7 +47,7 @@ bool __ParseString(const CStr& Value, CRect &Output) // Use the parser to parse the values CParser& parser (CParserCache::Get("_$value_$value_$value_$value_")); - string str = (const TCHAR*)Value; + string str = Value; CParserLine line; line.ParseString(parser, str); @@ -124,7 +124,7 @@ bool __ParseString(const CStr& Value, CSize &Output) // Use the parser to parse the values CParser& parser (CParserCache::Get("_$value_$value_")); - string str = (const TCHAR*)Value; + string str = Value; CParserLine line; line.ParseString(parser, str); @@ -288,7 +288,7 @@ CRect CClientArea::GetClientArea(const CRect &parent) const bool CClientArea::SetClientArea(const CStr& Value) { // Get value in STL string format - string _Value = (const TCHAR*)Value; + string _Value = Value; // This might lack incredible speed, but since all XML files // are read at startup, reading 100 client areas will be diff --git a/source/gui/scripting/JSInterface_IGUIObject.cpp b/source/gui/scripting/JSInterface_IGUIObject.cpp index 0a69d17ae0..f9991a226f 100755 --- a/source/gui/scripting/JSInterface_IGUIObject.cpp +++ b/source/gui/scripting/JSInterface_IGUIObject.cpp @@ -572,7 +572,7 @@ JSBool JSI_IGUIObject::toString(JSContext* cx, JSObject* obj, uintN UNUSEDPARAM( IGUIObject* e = (IGUIObject*)JS_GetPrivate( cx, obj ); char buffer[256]; - snprintf(buffer, 256, "[GUIObject: %s]", (const TCHAR*)e->GetName()); + snprintf(buffer, 256, "[GUIObject: %s]", e->GetName().c_str()); buffer[255] = 0; *rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, buffer)); return JS_TRUE; diff --git a/source/lib/precompiled.h b/source/lib/precompiled.h index ab46534bb9..4b0ae1af88 100755 --- a/source/lib/precompiled.h +++ b/source/lib/precompiled.h @@ -19,6 +19,8 @@ // make string_s (secure CRT string functions) available everywhere #include "lib/string_s.h" +// make MICROLOG and the old error system available everywhere +#include "Pyrogenesis.h" // // memory headers @@ -85,6 +87,23 @@ #include #include +#ifdef __GNUC__ +# include +# include +#else +# include +# include +#endif + +// CStr is included very frequently, so a reasonable amount of time is saved +// by including it here. (~10% in a full rebuild, as of r2365) +#include "ps/CStr.h" + +// Some other external libraries that are used in several places: +#include "jsapi.h" +#include "boost/shared_ptr.hpp" +#include "boost/weak_ptr.hpp" + // (further headers to be precompiled go here) #endif // #ifdef HAVE_PCH @@ -101,7 +120,7 @@ // use VC debug heap (superceded by mmgr; it remains for completeness) #ifdef HAVE_DEBUGALLOC - // can't define _CRTDBG_MAP_ALLOC because it has a broken 'new', + // can't define _CRTDBG_MAP_ALLOC because crtdbg.h has a broken 'new', // so manually redefine the appropriate functions. # define new new(_NORMAL_BLOCK, __FILE__, __LINE__) # define malloc(s) _malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__) diff --git a/source/lib/res/ogghack.cpp b/source/lib/res/ogghack.cpp index 2528ff516a..bc8c9b9f6f 100755 --- a/source/lib/res/ogghack.cpp +++ b/source/lib/res/ogghack.cpp @@ -13,7 +13,11 @@ #include "ogghack.h" #ifdef _MSC_VER -#pragma comment(lib, "vorbisfile.lib") +# ifdef NDEBUG +# pragma comment(lib, "vorbisfile.lib") +# else +# pragma comment(lib, "vorbisfile_d.lib") +# endif #endif diff --git a/source/lib/res/snd.cpp b/source/lib/res/snd.cpp index 28c239aced..7146a0aa18 100755 --- a/source/lib/res/snd.cpp +++ b/source/lib/res/snd.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #ifdef __APPLE__ # include diff --git a/source/lib/res/vfs.cpp b/source/lib/res/vfs.cpp index 8f5d64890a..60d8a547f8 100755 --- a/source/lib/res/vfs.cpp +++ b/source/lib/res/vfs.cpp @@ -29,6 +29,8 @@ #include "vfs_tree.h" #include +#include +#include #include #include diff --git a/source/lib/res/vfs_tree.cpp b/source/lib/res/vfs_tree.cpp index 4c02a7fc4a..49b0c9a4de 100644 --- a/source/lib/res/vfs_tree.cpp +++ b/source/lib/res/vfs_tree.cpp @@ -1,9 +1,11 @@ #include "precompiled.h" #include +#include #include #include +#include #include "lib.h" #include "res.h" diff --git a/source/lib/res/zip.cpp b/source/lib/res/zip.cpp index abbf460de4..b566237c97 100755 --- a/source/lib/res/zip.cpp +++ b/source/lib/res/zip.cpp @@ -44,6 +44,7 @@ #include #include +#include // provision for removing all ZLib code (all inflate calls will fail). // used for checking DLL dependency; might also simulate corrupt Zip files. diff --git a/source/lib/sysdep/win/wtime.cpp b/source/lib/sysdep/win/wtime.cpp index 7d2269e281..e8ee4b8c1a 100755 --- a/source/lib/sysdep/win/wtime.cpp +++ b/source/lib/sysdep/win/wtime.cpp @@ -27,6 +27,7 @@ #include #include // _beginthreadex +#include #include #include diff --git a/source/lib/types.h b/source/lib/types.h index c17ef77d7c..41502a7da2 100755 --- a/source/lib/types.h +++ b/source/lib/types.h @@ -30,6 +30,5 @@ typedef unsigned int PS_uint; #if defined(SIZE_MAX) && SIZE_MAX < 32 # error "check size_t and SIZE_MAX - too small?" #endif - #endif // #ifndef __TYPES_H__ diff --git a/source/ps/CLogger.cpp b/source/ps/CLogger.cpp index 4516a0883a..3537da042e 100755 --- a/source/ps/CLogger.cpp +++ b/source/ps/CLogger.cpp @@ -4,6 +4,8 @@ #include "ConfigDB.h" #include "lib.h" +#include + #include "CConsole.h" extern CConsole* g_Console; diff --git a/source/ps/CStr.cpp b/source/ps/CStr.cpp index 5f3cf45b5c..09d2a4fe14 100755 --- a/source/ps/CStr.cpp +++ b/source/ps/CStr.cpp @@ -7,9 +7,12 @@ #include "Network/Serialization.h" #include +#include + #define UNIDOUBLER_HEADER "CStr.cpp" #include "UniDoubler.h" + // Only include these function definitions in the first instance of CStr.cpp: CStrW::CStrW(const CStr8 &asciStr) : std::wstring(asciStr.begin(), asciStr.end()) {} CStr8::CStr8(const CStrW &wideStr) : std:: string(wideStr.begin(), wideStr.end()) {} @@ -131,6 +134,24 @@ using namespace std; #include +#ifdef _UNICODE + #define tstringstream wstringstream + #define _tstod wcstod + #define _ttoi(a) wcstol(a, NULL, 0) + #define _ttol(a) wcstol(a, NULL, 0) + #define _istspace iswspace + #define _totlower towlower + #define _totupper towupper +#else + #define tstringstream stringstream + #define _tstod strtod + #define _ttoi atoi + #define _ttol atol + #define _istspace isspace + #define _totlower tolower + #define _totupper toupper +#endif + // Construction and assignment from numbers: #define NUM_TYPE(T) \ @@ -209,9 +230,9 @@ long CStr::Find(const CStr& Str) const } // Search the string for another string -long CStr::Find(const TCHAR &tchar) const +long CStr::Find(const tchar &chr) const { - size_t Pos = find(tchar, 0); + size_t Pos = find(chr, 0); if (Pos != npos) return (long)Pos; @@ -220,9 +241,9 @@ long CStr::Find(const TCHAR &tchar) const } // Search the string for another string -long CStr::Find(const int &start, const TCHAR &tchar) const +long CStr::Find(const int &start, const tchar &chr) const { - size_t Pos = find(tchar, start); + size_t Pos = find(chr, start); if (Pos != npos) return (long)Pos; @@ -230,8 +251,8 @@ long CStr::Find(const int &start, const TCHAR &tchar) const return -1; } -long CStr::FindInsensitive(const int &start, const TCHAR &tchar) const { return LCase().Find(start, _totlower(tchar)); } -long CStr::FindInsensitive(const TCHAR &tchar) const { return LCase().Find(_totlower(tchar)); } +long CStr::FindInsensitive(const int &start, const tchar &chr) const { return LCase().Find(start, _totlower(chr)); } +long CStr::FindInsensitive(const tchar &chr) const { return LCase().Find(_totlower(chr)); } long CStr::FindInsensitive(const CStr& Str) const { return LCase().Find(Str.LCase()); } @@ -251,7 +272,7 @@ CStr CStr::LowerCase() const { tstring NewString = *this; for (size_t i = 0; i < length(); i++) - NewString[i] = (TCHAR)_totlower((*this)[i]); + NewString[i] = (tchar)_totlower((*this)[i]); return NewString; } @@ -260,7 +281,7 @@ CStr CStr::UpperCase() const { tstring NewString = *this; for (size_t i = 0; i < length(); i++) - NewString[i] = (TCHAR)_totupper((*this)[i]); + NewString[i] = (tchar)_totupper((*this)[i]); return NewString; } @@ -271,7 +292,7 @@ CStr CStr::LCase() const { tstring NewString = *this; for (size_t i = 0; i < length(); i++) - NewString[i] = (TCHAR)_totlower((*this)[i]); + NewString[i] = (tchar)_totlower((*this)[i]); return NewString; } @@ -280,7 +301,7 @@ CStr CStr::UCase() const { tstring NewString = *this; for (size_t i = 0; i < length(); i++) - NewString[i] = (TCHAR)_totupper((*this)[i]); + NewString[i] = (tchar)_totupper((*this)[i]); return NewString; } @@ -380,19 +401,19 @@ CStr CStr::UnescapeBackslashes() bool escaping = false; for (size_t i = 0; i < length(); i++) { - TCHAR ch = (*this)[i]; + tchar ch = (*this)[i]; if (escaping) { switch (ch) { - case _T('n'): NewString += _T('\n'); break; + case 'n': NewString += '\n'; break; default: NewString += ch; break; } escaping = false; } else { - if (ch == _T('\\')) + if (ch == '\\') escaping = true; else NewString += ch; @@ -450,7 +471,7 @@ CStr CStr::operator+(const CStr& Str) return std::operator+(*this, std::tstring(Str)); } -CStr CStr::operator+(const TCHAR* Str) +CStr CStr::operator+(const tchar* Str) { return std::operator+(*this, std::tstring(Str)); } @@ -469,7 +490,7 @@ CStrW CStr::operator+(const CStr8& Str) #endif -CStr::operator const TCHAR*() const +CStr::operator const tchar*() const { return c_str(); } @@ -509,7 +530,7 @@ const u8 *CStrW::Deserialize(const u8 *buffer, const u8 *bufferend) std::wstring::iterator str = begin(); while (ptr < strend) - *(str++) = (TCHAR)ntohs(*(ptr++)); // convert from network order (big-endian) + *(str++) = (tchar)ntohs(*(ptr++)); // convert from network order (big-endian) return (const u8 *)(strend+1); } @@ -553,4 +574,13 @@ uint CStr::GetSerializedLength() const #endif // _UNICODE +// Clean up, to keep the second pass through unidoubler happy +#undef tstringstream +#undef _tstod +#undef _ttoi +#undef _ttol +#undef _istspace +#undef _totlower +#undef _totupper + #endif // CStr_CPP_FIRST diff --git a/source/ps/CStr.h b/source/ps/CStr.h index f375fc4361..255e276e16 100755 --- a/source/ps/CStr.h +++ b/source/ps/CStr.h @@ -28,6 +28,10 @@ Example: More Info: http://wildfiregames.com/0ad/codepit/TDD/CStr.html + +[[ This documentation is out of date; CStr is always 8 bits, and CStrW is always +sizeof(wchar_t) (16 or 32). Don't use _T; CStrW constants are just L"string". ]] + */ // history: @@ -47,74 +51,48 @@ enum PS_TRIM_MODE { PS_TRIM_LEFT, PS_TRIM_RIGHT, PS_TRIM_BOTH }; #endif -#if !defined(CSTR_H) || defined(IN_UNIDOUBLER) -#define CSTR_H +// Include this section when in unidoubler mode, and when this unicode/ascii +// version has not already been included. +#if defined(IN_UNIDOUBLER) && ( (defined(_UNICODE) && !defined(CSTR_H_U)) || (!defined(_UNICODE) && !defined(CSTR_H_A)) ) -#include "Pyrogenesis.h" -#include // Used for basic string functionality -#include +#ifdef _UNICODE +#define CSTR_H_U +#else +#define CSTR_H_A +#endif + +#include #include "ps/utf16string.h" #include "Network/Serialization.h" -#include - -#ifdef _UNICODE - - #define tstring wstring - #define tstringstream wstringstream - #define _tcout wcout - #define _tstod wcstod - #define TCHAR wchar_t - #define _ttoi(a) wcstol(a, NULL, 0) - #define _ttol(a) wcstol(a, NULL, 0) - #define _T(t) L ## t - #define _istspace iswspace - #define _tsnprintf swprintf - #define _totlower towlower - #define _totupper towupper - -#else - - #define tstringstream stringstream - #define tstring string - #define _tcout cout - #define _tstod strtod - #define _ttoi atoi - #define _ttol atol - #define TCHAR char - #define _T(t) t - #define _istspace isspace - #define _tsnprintf snprintf - #define _totlower tolower - #define _totupper toupper - -#endif - class CStr8; class CStrW; // CStr class, the mother of all strings class CStr: public std::tstring, public ISerializable { + // The two variations must be friends with each other #ifdef _UNICODE friend class CStr8; #else friend class CStrW; #endif + public: // CONSTRUCTORS CStr() {} CStr(const CStr& String) : std::tstring(String) {} - CStr(const TCHAR* String) : std::tstring(String) {} - CStr(const TCHAR* String, size_t Length) + CStr(const tchar* String) : std::tstring(String) {} + CStr(const tchar* String, size_t Length) : std::tstring(String, Length) {} - CStr(const TCHAR Char) : std::tstring(1, Char) {} // std::string's constructor is (repeats, chr) + CStr(const tchar Char) : std::tstring(1, Char) {} // std::string's constructor is (repeats, chr) CStr(std::tstring String) : std::tstring(String) {} - // CStrW construction from utf16strings + // CStr(8|W) construction from utf16strings, except on MSVC CStrW where + // CStrW === utf16string #if !(defined(_MSC_VER) && defined(_UNICODE)) CStr(utf16string String) : std::tstring(String.begin(), String.end()) {} #endif @@ -154,7 +132,7 @@ public: float ToFloat() const; double ToDouble() const; - // Returns the length of the string in characters + // Returns the length of the string in characters size_t Length() const { return length(); } // Retrieves the substring within the string @@ -163,13 +141,13 @@ public: // Search the string for another string. Returns the offset of the first // match, or -1 if no matches are found. long Find(const CStr& Str) const; - long Find(const TCHAR &tchar) const; - long Find(const int &start, const TCHAR &tchar) const; + long Find(const tchar &chr) const; + long Find(const int &start, const tchar &chr) const; // Case-insensitive versions of Find long FindInsensitive(const CStr& Str) const; - long FindInsensitive(const TCHAR &tchar) const; - long FindInsensitive(const int &start, const TCHAR &tchar) const; + long FindInsensitive(const tchar &chr) const; + long FindInsensitive(const int &start, const tchar &chr) const; // You can also do a "ReverseFind" - i.e. search starting from the end long ReverseFind(const CStr& Str) const; @@ -224,18 +202,18 @@ public: CStr& operator=(double Number); CStr operator+(const CStr& Str); - CStr operator+(const TCHAR* Str); + CStr operator+(const tchar* Str); #ifndef _UNICODE CStr8 operator+(const CStrW& Str); #else CStrW operator+(const CStr8& Str); #endif - operator const TCHAR*() const; + operator const tchar*() const; // Do some range checking in debug builds - TCHAR &operator[](size_t n) { assert(n < length()); return this->std::tstring::operator[](n); } - TCHAR &operator[](int n) { assert(n >= 0 && (size_t)n < length()); return this->std::tstring::operator[](n); } + tchar &operator[](size_t n) { assert(n < length()); return this->std::tstring::operator[](n); } + tchar &operator[](int n) { assert(n >= 0 && (size_t)n < length()); return this->std::tstring::operator[](n); } // Conversion to utf16string inline utf16string utf16() const diff --git a/source/ps/Network/NMTCreator.h b/source/ps/Network/NMTCreator.h index 30054a9062..89a3226647 100755 --- a/source/ps/Network/NMTCreator.h +++ b/source/ps/Network/NMTCreator.h @@ -268,6 +268,12 @@ const u8 *_nm::Deserialize(const u8 *pos, const u8 *end) \ /*************************************************************************/ // Pass 6, String Representation + +#define _T(s) s +// PT: I'm not sure whether this is correct - it appears that this code +// relied on CStr.h leaving _T defined in ASCII mode, so I'm not sure +// why the macro is actually used at all... + #define START_NMTS() #define END_NMTS() diff --git a/source/ps/Network/NetLog.cpp b/source/ps/Network/NetLog.cpp index 8f786e44c1..ca520915ef 100644 --- a/source/ps/Network/NetLog.cpp +++ b/source/ps/Network/NetLog.cpp @@ -4,6 +4,7 @@ #include "ThreadUtil.h" #include #include +#include #include "lib/timer.h" CNetLog g_NetLog; diff --git a/source/ps/ProfileViewer.cpp b/source/ps/ProfileViewer.cpp index 50fbd2add1..90a6d9a6f1 100644 --- a/source/ps/ProfileViewer.cpp +++ b/source/ps/ProfileViewer.cpp @@ -90,7 +90,7 @@ void RenderProfile() glPushMatrix(); glwprintf( L"%%/parent" ); glPopMatrix(); - glPopMatrix(); + glPopMatrix(); CProfileNode::const_profile_iterator it; diff --git a/source/ps/UniDoubler.h b/source/ps/UniDoubler.h index 4b43ead341..3a4a5405ee 100755 --- a/source/ps/UniDoubler.h +++ b/source/ps/UniDoubler.h @@ -5,37 +5,53 @@ #define IN_UNIDOUBLER -#define _UNICODE +// When compiling CStr.cpp with PCH, the unidoubler stuff gets rather +// confusing because of all the nested inclusions, but this makes it work: #undef CStr #undef CStr_hash_compare + +// First, set up the environment for the Unicode version +#define _UNICODE #define CStr CStrW #define CStr_hash_compare CStrW_hash_compare +#define tstring wstring +#define tchar wchar_t +#define _T(t) L ## t + +// Include the unidoubled file #include UNIDOUBLER_HEADER -// Undef all the Conversion Macros -#undef tstring -#undef tstringstream -#undef _tcout -#undef _tstod -#undef _ttoi -#undef _ttol -#undef TCHAR -#undef _T -#undef _istspace -#undef _tsnprintf -#undef _totlower -#undef _totupper - -// Now include the 8-bit version under the name CStr8 +// Clean up all the macros #undef _UNICODE #undef CStr #undef CStr_hash_compare +#undef tstring +#undef tchar +#undef _T + + +// Now include the 8-bit version under the name CStr8 #define CStr CStr8 #define CStr_hash_compare CStr8_hash_compare +#define tstring string +#define tchar char +#define _T(t) t + #include UNIDOUBLER_HEADER +// Clean up the macros again, to minimise namespace pollution +#undef CStr +#undef CStr_hash_compare +#undef tstring +#undef tchar +#undef _T + + +// To please the file that originally include CStr.h, make CStr an alias for CStr8: +#define CStr CStr8 +#define CStr_hash_compare CStr8_hash_compare + #undef IN_UNIDOUBLER #undef UNIDOUBLER_HEADER #endif - diff --git a/source/scripting/ScriptingHost.cpp b/source/scripting/ScriptingHost.cpp index 237a205cad..5b83049158 100755 --- a/source/scripting/ScriptingHost.cpp +++ b/source/scripting/ScriptingHost.cpp @@ -5,6 +5,7 @@ #include "CConsole.h" #include "Profile.h" #include +#include #include "res/res.h" diff --git a/source/simulation/EntityStateProcessing.cpp b/source/simulation/EntityStateProcessing.cpp index 01bf27193d..6cf0fe7d21 100755 --- a/source/simulation/EntityStateProcessing.cpp +++ b/source/simulation/EntityStateProcessing.cpp @@ -470,7 +470,7 @@ bool CEntity::processContactActionNoPathing( CEntityOrder* current, size_t times // Load time needs to be animation->m_ActionPos2 ms after the start of the animation. - m_fsm_anipos2 = m_fsm_anipos + ( action->m_Speed * m_fsm_animation->m_ActionPos2 * 2 ); + m_fsm_anipos2 = m_fsm_anipos + (size_t)( action->m_Speed * m_fsm_animation->m_ActionPos2 * 2 ); if( m_fsm_anipos2 < 0 ) { // Load now. diff --git a/source/tools/sced/ui/SimpleEdit.cpp b/source/tools/sced/ui/SimpleEdit.cpp index 91ee383403..a147617e4b 100755 --- a/source/tools/sced/ui/SimpleEdit.cpp +++ b/source/tools/sced/ui/SimpleEdit.cpp @@ -6,9 +6,6 @@ #include "ScEd.h" #include "SimpleEdit.h" -// Slight hack, since this gets undef'd earlier to avoid conflicts with CStr -#define _T(x) x - ///////////////////////////////////////////////////////////////////////////// // CSimpleEdit dialog diff --git a/source/tools/sced/ui/StdAfx.h b/source/tools/sced/ui/StdAfx.h index 7343bded5a..69f788bcc1 100755 --- a/source/tools/sced/ui/StdAfx.h +++ b/source/tools/sced/ui/StdAfx.h @@ -14,9 +14,11 @@ #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers +// Fix nasty conflicts between various header files. #define _SIZE_T_DEFINED #include "posix.h" -//#include "CStr.h" +#include "CStr.h" +#undef UNUSED #undef _WINDOWS_ @@ -31,12 +33,6 @@ #endif // _AFX_NO_AFXCMN_SUPPORT #undef UNUSED -#undef _T -#undef _istspace -#undef _totlower -#undef _totupper -#undef _ttoi -#undef _ttol #include "resource.h"