Browse Source

Use _WIN32 consistently in Urho3D engine code. Simplify some preprocessor conditionals. Closes #1036.

Lasse Öörni 10 years ago
parent
commit
973a6fa807

+ 3 - 3
Source/Urho3D/Container/Str.cpp

@@ -757,7 +757,7 @@ void String::SetUTF8FromWChar(const wchar_t* str)
     if (!str)
         return;
 
-#ifdef WIN32
+#ifdef _WIN32
     while (*str)
     {
         unsigned unicodeChar = DecodeUTF16(str);
@@ -996,7 +996,7 @@ unsigned String::DecodeUTF8(const char*& src)
     }
 }
 
-#ifdef WIN32
+#ifdef _WIN32
 void String::EncodeUTF16(wchar_t*& dest, unsigned unicodeChar)
 {
     if (unicodeChar < 0x10000)
@@ -1245,7 +1245,7 @@ WString::WString(const String& str) :
     length_(0),
     buffer_(0)
 {
-#ifdef WIN32
+#ifdef _WIN32
     unsigned neededSize = 0;
     wchar_t temp[3];
     

+ 1 - 1
Source/Urho3D/Container/Str.h

@@ -470,7 +470,7 @@ public:
     static void EncodeUTF8(char*& dest, unsigned unicodeChar);
     /// Decode Unicode character from UTF8. Pointer will be incremented.
     static unsigned DecodeUTF8(const char*& src);
-#ifdef WIN32
+#ifdef _WIN32
     /// Encode Unicode character to UTF16. Pointer will be incremented.
     static void EncodeUTF16(wchar_t*& dest, unsigned unicodeChar);
     /// Decode Unicode character from UTF16. Pointer will be incremented.

+ 2 - 2
Source/Urho3D/Core/Condition.cpp

@@ -24,7 +24,7 @@
 
 #include "../Core/Condition.h"
 
-#ifdef WIN32
+#ifdef _WIN32
 #include <windows.h>
 #else
 #include <pthread.h>
@@ -33,7 +33,7 @@
 namespace Urho3D
 {
 
-#ifdef WIN32
+#ifdef _WIN32
 
 Condition::Condition() :
     event_(0)

+ 1 - 1
Source/Urho3D/Core/Condition.h

@@ -48,7 +48,7 @@ public:
     void Wait();
 
 private:
-#ifndef WIN32
+#ifndef _WIN32
     /// Mutex for the event, necessary for pthreads-based implementation.
     void* mutex_;
 #endif

+ 2 - 2
Source/Urho3D/Core/Main.h

@@ -24,7 +24,7 @@
 
 #include "../Core/ProcessUtils.h"
 
-#if defined(WIN32) && !defined(URHO3D_WIN32_CONSOLE)
+#if defined(_WIN32) && !defined(URHO3D_WIN32_CONSOLE)
 #include "../Core/MiniDump.h"
 #include <windows.h>
 #ifdef _MSC_VER
@@ -60,7 +60,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, in
     return exitCode; \
 }
 // Other Win32 or minidumps disabled: just execute the function
-#elif defined(WIN32) && !defined(URHO3D_WIN32_CONSOLE)
+#elif defined(_WIN32) && !defined(URHO3D_WIN32_CONSOLE)
 #define URHO3D_DEFINE_MAIN(function) \
 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance, PSTR cmdLine, int showCmd) \
 { \

+ 2 - 2
Source/Urho3D/Core/Mutex.cpp

@@ -24,7 +24,7 @@
 
 #include "../Core/Mutex.h"
 
-#ifdef WIN32
+#ifdef _WIN32
 #include <windows.h>
 #else
 #include <pthread.h>
@@ -35,7 +35,7 @@
 namespace Urho3D
 {
 
-#ifdef WIN32
+#ifdef _WIN32
 
 Mutex::Mutex() :
     handle_(new CRITICAL_SECTION)

+ 6 - 6
Source/Urho3D/Core/ProcessUtils.cpp

@@ -38,7 +38,7 @@
 #include <LibCpuId/libcpuid.h>
 #endif
 
-#ifdef WIN32
+#ifdef _WIN32
 #include <windows.h>
 #include <io.h>
 #else
@@ -81,7 +81,7 @@ inline void SetFPUState(unsigned control)
 namespace Urho3D
 {
 
-#ifdef WIN32
+#ifdef _WIN32
 static bool consoleOpened = false;
 #endif
 static String currentLine;
@@ -138,7 +138,7 @@ void ErrorExit(const String& message, int exitCode)
 
 void OpenConsoleWindow()
 {
-#ifdef WIN32
+#ifdef _WIN32
     if (consoleOpened)
         return;
 
@@ -154,7 +154,7 @@ void OpenConsoleWindow()
 void PrintUnicode(const String& str, bool error)
 {
 #if !defined(ANDROID) && !defined(IOS)
-#ifdef WIN32
+#ifdef _WIN32
     // If the output stream has been redirected, use fprintf instead of WriteConsoleW,
     // though it means that proper Unicode output will not work
     FILE* out = error ? stderr : stdout;
@@ -272,7 +272,7 @@ String GetConsoleInput()
     return ret;
 #endif
 
-#ifdef WIN32
+#ifdef _WIN32
     HANDLE input = GetStdHandle(STD_INPUT_HANDLE);
     HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE);
     if (input == INVALID_HANDLE_VALUE || output == INVALID_HANDLE_VALUE)
@@ -343,7 +343,7 @@ String GetPlatform()
     return "Android";
 #elif defined(IOS)
     return "iOS";
-#elif defined(WIN32)
+#elif defined(_WIN32)
     return "Windows";
 #elif defined(__APPLE__)
     return "Mac OS X";

+ 6 - 6
Source/Urho3D/Core/Thread.cpp

@@ -24,7 +24,7 @@
 
 #include "../Core/Thread.h"
 
-#ifdef WIN32
+#ifdef _WIN32
 #include <windows.h>
 #else
 #include <pthread.h>
@@ -36,7 +36,7 @@ namespace Urho3D
 {
 
 #ifdef URHO3D_THREADING
-#ifdef WIN32
+#ifdef _WIN32
 
 DWORD WINAPI ThreadFunctionStatic(void* data)
 {
@@ -79,7 +79,7 @@ bool Thread::Run()
         return false;
 
     shouldRun_ = true;
-#ifdef WIN32
+#ifdef _WIN32
     handle_ = CreateThread(0, 0, ThreadFunctionStatic, this, 0, 0);
 #else
     handle_ = new pthread_t;
@@ -102,7 +102,7 @@ void Thread::Stop()
         return;
 
     shouldRun_ = false;
-#ifdef WIN32
+#ifdef _WIN32
     WaitForSingleObject((HANDLE)handle_, INFINITE);
     CloseHandle((HANDLE)handle_);
 #else
@@ -118,7 +118,7 @@ void Thread::Stop()
 void Thread::SetPriority(int priority)
 {
 #ifdef URHO3D_THREADING
-#ifdef WIN32
+#ifdef _WIN32
     if (handle_)
         SetThreadPriority((HANDLE)handle_, priority);
 #endif
@@ -137,7 +137,7 @@ void Thread::SetMainThread()
 
 ThreadID Thread::GetCurrentThreadID()
 {
-#ifdef WIN32
+#ifdef _WIN32
     return GetCurrentThreadId();
 #else
     return pthread_self();

+ 1 - 1
Source/Urho3D/Core/Thread.h

@@ -28,7 +28,7 @@
 #include <Urho3D/Urho3D.h>
 #endif
 
-#ifndef WIN32
+#ifndef _WIN32
 #include <pthread.h>
 typedef pthread_t ThreadID;
 #else

+ 6 - 6
Source/Urho3D/Core/Timer.cpp

@@ -27,7 +27,7 @@
 
 #include <ctime>
 
-#ifdef WIN32
+#ifdef _WIN32
 #include <windows.h>
 #include <mmsystem.h>
 #elif __EMSCRIPTEN__
@@ -51,7 +51,7 @@ Time::Time(Context* context) :
     timeStep_(0.0f),
     timerPeriod_(0)
 {
-#ifdef WIN32
+#ifdef _WIN32
     LARGE_INTEGER frequency;
     if (QueryPerformanceFrequency(&frequency))
     {
@@ -71,7 +71,7 @@ Time::~Time()
 
 static unsigned Tick()
 {
-#ifdef WIN32
+#ifdef _WIN32
     return (unsigned)timeGetTime();
 #elif __EMSCRIPTEN__
     return (unsigned)emscripten_get_now();
@@ -84,7 +84,7 @@ static unsigned Tick()
 
 static long long HiresTick()
 {
-#ifdef WIN32
+#ifdef _WIN32
     if (HiresTimer::IsSupported())
     {
         LARGE_INTEGER counter;
@@ -143,7 +143,7 @@ void Time::EndFrame()
 
 void Time::SetTimerPeriod(unsigned mSec)
 {
-#ifdef WIN32
+#ifdef _WIN32
     if (timerPeriod_ > 0)
         timeEndPeriod(timerPeriod_);
 
@@ -179,7 +179,7 @@ String Time::GetTimeStamp()
 
 void Time::Sleep(unsigned mSec)
 {
-#ifdef WIN32
+#ifdef _WIN32
     ::Sleep(mSec);
 #else
     usleep(mSec * 1000);

+ 4 - 4
Source/Urho3D/IO/File.cpp

@@ -37,7 +37,7 @@
 namespace Urho3D
 {
 
-#ifdef WIN32
+#ifdef _WIN32
 static const wchar_t* openMode[] =
 {
     L"rb",
@@ -167,7 +167,7 @@ bool File::Open(const String& fileName, FileMode mode)
         return false;
     }
 
-#ifdef WIN32
+#ifdef _WIN32
     handle_ = _wfopen(GetWideNativePath(fileName).CString(), openMode[mode]);
 #else
     handle_ = fopen(GetNativePath(fileName).CString(), openMode[mode]);
@@ -176,7 +176,7 @@ bool File::Open(const String& fileName, FileMode mode)
     // If file did not exist in readwrite mode, retry with write-update mode
     if (mode == FILE_READWRITE && !handle_)
     {
-#ifdef WIN32
+#ifdef _WIN32
         handle_ = _wfopen(GetWideNativePath(fileName).CString(), openMode[mode + 1]);
 #else
         handle_ = fopen(GetNativePath(fileName).CString(), openMode[mode + 1]);
@@ -223,7 +223,7 @@ bool File::Open(PackageFile* package, const String& fileName)
     if (!entry)
         return false;
 
-#ifdef WIN32
+#ifdef _WIN32
     handle_ = _wfopen(GetWideNativePath(package->GetName()).CString(), L"rb");
 #else
     handle_ = fopen(GetNativePath(package->GetName()).CString(), "rb");

+ 19 - 19
Source/Urho3D/IO/FileSystem.cpp

@@ -36,7 +36,7 @@
 
 #include <sys/stat.h>
 
-#ifdef WIN32
+#ifdef _WIN32
 #include <cstdio>
 #ifndef _MSC_VER
 #define _WIN32_IE 0x501
@@ -135,7 +135,7 @@ int DoSystemRun(const String& fileName, const Vector<String>& arguments)
 {
     String fixedFileName = GetNativePath(fileName);
 
-#ifdef WIN32
+#ifdef _WIN32
     // Add .exe extension if no extension defined
     if (GetExtension(fixedFileName).Empty())
         fixedFileName += ".exe";
@@ -299,7 +299,7 @@ bool FileSystem::SetCurrentDir(const String& pathName)
         URHO3D_LOGERROR("Access denied to " + pathName);
         return false;
     }
-#ifdef WIN32
+#ifdef _WIN32
     if (SetCurrentDirectoryW(GetWideNativePath(pathName).CString()) == FALSE)
     {
         URHO3D_LOGERROR("Failed to change directory to " + pathName);
@@ -332,7 +332,7 @@ bool FileSystem::CreateDir(const String& pathName)
             return false;
     }
 
-#ifdef WIN32
+#ifdef _WIN32
     bool success = (CreateDirectoryW(GetWideNativePath(RemoveTrailingSlash(pathName)).CString(), 0) == TRUE) ||
         (GetLastError() == ERROR_ALREADY_EXISTS);
 #else
@@ -433,7 +433,7 @@ bool FileSystem::SystemOpen(const String& fileName, const String& mode)
             return false;
         }
 
-#ifdef WIN32
+#ifdef _WIN32
         bool success = (size_t)ShellExecuteW(0, !mode.Empty() ? WString(mode).CString() : 0,
             GetWideNativePath(fileName).CString(), 0, 0, SW_SHOW) > 32;
 #else
@@ -499,7 +499,7 @@ bool FileSystem::Rename(const String& srcFileName, const String& destFileName)
         return false;
     }
 
-#ifdef WIN32
+#ifdef _WIN32
     return MoveFileW(GetWideNativePath(srcFileName).CString(), GetWideNativePath(destFileName).CString()) != 0;
 #else
     return rename(GetNativePath(srcFileName).CString(), GetNativePath(destFileName).CString()) == 0;
@@ -514,7 +514,7 @@ bool FileSystem::Delete(const String& fileName)
         return false;
     }
 
-#ifdef WIN32
+#ifdef _WIN32
     return DeleteFileW(GetWideNativePath(fileName).CString()) != 0;
 #else
     return remove(GetNativePath(fileName).CString()) == 0;
@@ -523,7 +523,7 @@ bool FileSystem::Delete(const String& fileName)
 
 String FileSystem::GetCurrentDir() const
 {
-#ifdef WIN32
+#ifdef _WIN32
     wchar_t path[MAX_PATH];
     path[0] = 0;
     GetCurrentDirectoryW(MAX_PATH, path);
@@ -564,7 +564,7 @@ unsigned FileSystem::GetLastModifiedTime(const String& fileName) const
     if (fileName.Empty() || !CheckAccess(fileName))
         return 0;
 
-#ifdef WIN32
+#ifdef _WIN32
     struct _stat st;
     if (!_stat(fileName.CString(), &st))
         return (unsigned)st.st_mtime;
@@ -600,7 +600,7 @@ bool FileSystem::FileExists(const String& fileName) const
 
     String fixedName = GetNativePath(RemoveTrailingSlash(fileName));
 
-#ifdef WIN32
+#ifdef _WIN32
     DWORD attributes = GetFileAttributesW(WString(fixedName).CString());
     if (attributes == INVALID_FILE_ATTRIBUTES || attributes & FILE_ATTRIBUTE_DIRECTORY)
         return false;
@@ -618,7 +618,7 @@ bool FileSystem::DirExists(const String& pathName) const
     if (!CheckAccess(pathName))
         return false;
 
-#ifndef WIN32
+#ifndef _WIN32
     // Always return true for the root directory
     if (pathName == "/")
         return true;
@@ -654,7 +654,7 @@ bool FileSystem::DirExists(const String& pathName) const
     }
 #endif
 
-#ifdef WIN32
+#ifdef _WIN32
     DWORD attributes = GetFileAttributesW(WString(fixedName).CString());
     if (attributes == INVALID_FILE_ATTRIBUTES || !(attributes & FILE_ATTRIBUTE_DIRECTORY))
         return false;
@@ -692,7 +692,7 @@ String FileSystem::GetProgramDir() const
 #elif defined(IOS)
     programDir_ = AddTrailingSlash(SDL_IOS_GetResourceDir());
     return programDir_;
-#elif defined(WIN32)
+#elif defined(_WIN32)
     wchar_t exeName[MAX_PATH];
     exeName[0] = 0;
     GetModuleFileNameW(0, exeName, MAX_PATH);
@@ -732,7 +732,7 @@ String FileSystem::GetUserDocumentsDir() const
     return AddTrailingSlash(SDL_Android_GetFilesDir());
 #elif defined(IOS)
     return AddTrailingSlash(SDL_IOS_GetDocumentsDir());
-#elif defined(WIN32)
+#elif defined(_WIN32)
     wchar_t pathName[MAX_PATH];
     pathName[0] = 0;
     SHGetSpecialFolderPathW(0, pathName, CSIDL_PERSONAL, 0);
@@ -773,7 +773,7 @@ bool FileSystem::SetLastModifiedTime(const String& fileName, unsigned newTime)
     if (fileName.Empty() || !CheckAccess(fileName))
         return false;
 
-#ifdef WIN32
+#ifdef _WIN32
     struct _stat oldTime;
     struct _utimbuf newTimes;
     if (_stat(fileName.CString(), &oldTime) != 0)
@@ -839,7 +839,7 @@ void FileSystem::ScanDirInternal(Vector<String>& result, String path, const Stri
         return;
     }
 #endif
-#ifdef WIN32
+#ifdef _WIN32
     WIN32_FIND_DATAW info;
     HANDLE handle = FindFirstFileW(WString(path + "*").CString(), &info);
     if (handle != INVALID_HANDLE_VALUE)
@@ -1034,7 +1034,7 @@ String GetInternalPath(const String& pathName)
 
 String GetNativePath(const String& pathName)
 {
-#ifdef WIN32
+#ifdef _WIN32
     return pathName.Replaced('/', '\\');
 #else
     return pathName;
@@ -1043,7 +1043,7 @@ String GetNativePath(const String& pathName)
 
 WString GetWideNativePath(const String& pathName)
 {
-#ifdef WIN32
+#ifdef _WIN32
     return WString(pathName.Replaced('/', '\\'));
 #else
     return WString(pathName);
@@ -1060,7 +1060,7 @@ bool IsAbsolutePath(const String& pathName)
     if (path[0] == '/')
         return true;
 
-#ifdef WIN32
+#ifdef _WIN32
     if (path.Length() > 1 && IsAlpha(path[0]) && path[1] == ':')
         return true;
 #endif

+ 9 - 9
Source/Urho3D/IO/FileWatcher.cpp

@@ -27,7 +27,7 @@
 #include "../IO/FileWatcher.h"
 #include "../IO/Log.h"
 
-#ifdef WIN32
+#ifdef _WIN32
 #include <windows.h>
 #elif __linux__
 #include <sys/inotify.h>
@@ -55,8 +55,8 @@ FileWatcher::FileWatcher(Context* context) :
     delay_(1.0f),
     watchSubDirs_(false)
 {
-#if defined(URHO3D_FILEWATCHER)
-#if defined(__linux__)
+#ifdef URHO3D_FILEWATCHER
+#ifdef __linux__
     watchHandle_ = inotify_init();
 #elif defined(__APPLE__) && !defined(IOS)
     supported_ = IsFileWatcherSupported();
@@ -67,8 +67,8 @@ FileWatcher::FileWatcher(Context* context) :
 FileWatcher::~FileWatcher()
 {
     StopWatching();
-#if defined(URHO3D_FILEWATCHER)
-#if defined(__linux__)
+#ifdef URHO3D_FILEWATCHER
+#ifdef __linux__
     close(watchHandle_);
 #endif
 #endif
@@ -86,7 +86,7 @@ bool FileWatcher::StartWatching(const String& pathName, bool watchSubDirs)
     StopWatching();
 
 #if defined(URHO3D_FILEWATCHER) && defined(URHO3D_THREADING)
-#if defined(WIN32)
+#ifdef _WIN32
     String nativePath = GetNativePath(RemoveTrailingSlash(pathName));
     
     dirHandle_ = (void*)CreateFileW(
@@ -203,7 +203,7 @@ void FileWatcher::StopWatching()
 
         Stop();
 
-#if defined(WIN32)
+#ifdef _WIN32
         CloseHandle((HANDLE)dirHandle_);
 #elif defined(__linux__)
         for (HashMap<int, String>::Iterator i = dirHandle_.Begin(); i != dirHandle_.End(); ++i)
@@ -225,8 +225,8 @@ void FileWatcher::SetDelay(float interval)
 
 void FileWatcher::ThreadFunction()
 {
-#if defined(URHO3D_FILEWATCHER)
-#if defined(WIN32)
+#ifdef URHO3D_FILEWATCHER
+#ifdef _WIN32
     unsigned char buffer[BUFFERSIZE];
     DWORD bytesFilled = 0;
     

+ 1 - 1
Source/Urho3D/IO/FileWatcher.h

@@ -78,7 +78,7 @@ private:
     /// Watch subdirectories flag.
     bool watchSubDirs_;
 
-#ifdef WIN32
+#ifdef _WIN32
 
     /// Directory handle for the path being watched.
     void* dirHandle_;

+ 2 - 2
Source/Urho3D/IO/PackageFile.cpp

@@ -122,7 +122,7 @@ bool PackageFile::Exists(const String& fileName) const
 {
     bool found = entries_.Find(fileName) != entries_.End();
 
-#ifdef WIN32
+#ifdef _WIN32
     // On Windows perform a fallback case-insensitive search
     if (!found)
     {
@@ -146,7 +146,7 @@ const PackageEntry* PackageFile::GetEntry(const String& fileName) const
     if (i != entries_.End())
         return &i->second_;
 
-#ifdef WIN32
+#ifdef _WIN32
     // On Windows perform a fallback case-insensitive search
     else
     {

+ 1 - 1
Source/Urho3D/Input/Input.cpp

@@ -48,7 +48,7 @@
 extern "C" int SDL_AddTouch(SDL_TouchID touchID, const char* name);
 
 // Use a "click inside window to focus" mechanism on desktop platforms when the mouse cursor is hidden
-#if defined(WIN32) || (defined(__APPLE__) && !defined(IOS)) || (defined(__linux__) && !defined(ANDROID) && !defined(RPI))
+#if defined(_WIN32) || (defined(__APPLE__) && !defined(IOS)) || (defined(__linux__) && !defined(ANDROID) && !defined(RPI))
 #define REQUIRE_CLICK_TO_FOCUS
 #endif
 

+ 1 - 1
Source/Urho3D/UI/UI.cpp

@@ -92,7 +92,7 @@ UI::UI(Context* context) :
     maxFontTextureSize_(DEFAULT_FONT_TEXTURE_MAX_SIZE),
     initialized_(false),
     usingTouchInput_(false),
-#ifdef WIN32
+#ifdef _WIN32
     nonFocusedMouseWheel_(false),    // Default MS Windows behaviour
 #else
     nonFocusedMouseWheel_(true),     // Default Mac OS X and Linux behaviour