From 72af4052eec25ef0278a69ff973cabe64bcb184c Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 23 Dec 2015 14:36:16 +0100 Subject: [PATCH 01/16] Changed: Add getTotalVideoMemory to IDriver to query total video memory --HG-- branch : develop --- code/nel/include/nel/3d/driver.h | 7 ++ code/nel/include/nel/3d/driver_user.h | 1 + code/nel/include/nel/3d/u_driver.h | 6 ++ code/nel/src/3d/driver.cpp | 2 +- .../3d/driver/direct3d/driver_direct3d.cpp | 12 +++ .../src/3d/driver/direct3d/driver_direct3d.h | 1 + .../src/3d/driver/opengl/driver_opengl.cpp | 100 ++++++++++++++++++ code/nel/src/3d/driver/opengl/driver_opengl.h | 2 + .../driver/opengl/driver_opengl_extension.cpp | 49 --------- code/nel/src/3d/driver_user.cpp | 6 ++ 10 files changed, 136 insertions(+), 50 deletions(-) diff --git a/code/nel/include/nel/3d/driver.h b/code/nel/include/nel/3d/driver.h index 8e2eb8409..52bda8576 100644 --- a/code/nel/include/nel/3d/driver.h +++ b/code/nel/include/nel/3d/driver.h @@ -865,6 +865,12 @@ public: * get the official name of the driver */ virtual const char *getVideocardInformation () = 0; + + /** + * Get total video memory. + * get the amount of video memory of current adapter, result is in KiB, -1 if unable to determine + */ + virtual sint getTotalVideoMemory () const = 0; // @} @@ -1342,6 +1348,7 @@ public: uint32 DeviceId; uint32 SubSysId; uint32 Revision; + sint32 VideoMemory; // video memory in KiB, -1 if unable to determine }; // Get the number of hardware renderer available on the client platform. diff --git a/code/nel/include/nel/3d/driver_user.h b/code/nel/include/nel/3d/driver_user.h index 761a03114..62c6fd6db 100644 --- a/code/nel/include/nel/3d/driver_user.h +++ b/code/nel/include/nel/3d/driver_user.h @@ -412,6 +412,7 @@ public: virtual uint32 getImplementationVersion () const; virtual const char* getDriverInformation (); virtual const char* getVideocardInformation (); + virtual sint getTotalVideoMemory () const; virtual uint getNbTextureStages(); virtual void getWindowSize (uint32 &width, uint32 &height); virtual uint getWindowWidth (); diff --git a/code/nel/include/nel/3d/u_driver.h b/code/nel/include/nel/3d/u_driver.h index f880c9f47..0500192ad 100644 --- a/code/nel/include/nel/3d/u_driver.h +++ b/code/nel/include/nel/3d/u_driver.h @@ -505,6 +505,12 @@ public: */ virtual const char* getVideocardInformation () = 0; + /** + * Get total video memory. + * get the amount of video memory of current adapter, result is in KiB, -1 if unable to determine + */ + virtual sint getTotalVideoMemory () const = 0; + /// Get the number of texture stage available, for multitexturing (Normal material shaders). Valid only after setDisplay(). virtual uint getNbTextureStages() = 0; diff --git a/code/nel/src/3d/driver.cpp b/code/nel/src/3d/driver.cpp index f6fa074f0..9bd23f815 100644 --- a/code/nel/src/3d/driver.cpp +++ b/code/nel/src/3d/driver.cpp @@ -32,7 +32,7 @@ namespace NL3D { // *************************************************************************** -const uint32 IDriver::InterfaceVersion = 0x6f; // getters for anisotropic filter +const uint32 IDriver::InterfaceVersion = 0x70; // total video memory // *************************************************************************** IDriver::IDriver() : _SyncTexDrvInfos( "IDriver::_SyncTexDrvInfos" ) diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp b/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp index fb310bd7d..23ed1bedc 100644 --- a/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp +++ b/code/nel/src/3d/driver/direct3d/driver_direct3d.cpp @@ -2381,6 +2381,7 @@ bool CDriverD3D::getAdapter(uint adapter, IDriver::CAdapter &desc) const desc.Revision = identifier.Revision; desc.SubSysId = identifier.SubSysId; desc.VendorId = identifier.VendorId; + desc.VideoMemory = _Adapter == _adapter ? getTotalVideoMemory():-1; return true; } } @@ -2874,6 +2875,17 @@ const char *CDriverD3D::getVideocardInformation () // *************************************************************************** +sint CDriverD3D::getTotalVideoMemory () const +{ + H_AUTO_D3D(CDriverD3D_getTotalVideoMemory); + + // Can't use _DeviceInterface->GetAvailableTextureMem() because it's not reliable + // Returns 4 GiB instead of 2 with my GPU + return -1; +} + +// *************************************************************************** + void CDriverD3D::getBuffer (CBitmap &bitmap) { H_AUTO_D3D(CDriverD3D_getBuffer); diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d.h b/code/nel/src/3d/driver/direct3d/driver_direct3d.h index 830694a42..4dd215c9b 100644 --- a/code/nel/src/3d/driver/direct3d/driver_direct3d.h +++ b/code/nel/src/3d/driver/direct3d/driver_direct3d.h @@ -900,6 +900,7 @@ public: virtual uint32 getImplementationVersion () const; virtual const char* getDriverInformation (); virtual const char* getVideocardInformation (); + virtual sint getTotalVideoMemory () const; virtual CVertexBuffer::TVertexColorType getVertexColorFormat() const; // Textures diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.cpp b/code/nel/src/3d/driver/opengl/driver_opengl.cpp index 3539948ac..d1e1446e5 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl.cpp @@ -1199,6 +1199,105 @@ const char *CDriverGL::getVideocardInformation () return name; } +sint CDriverGL::getTotalVideoMemory() const +{ + H_AUTO_OGL(CDriverGL_getTotalVideoMemory); + + if (_Extensions.NVXGPUMemoryInfo) + { + GLint memoryInKiB = 0; + glGetIntegerv(GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX, &memoryInKiB); + + nlinfo("3D: GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX returned %d KiB", memoryInKiB); + return memoryInKiB; + } + + if (_Extensions.ATIMeminfo) + { + GLint memoryInKiB = 0; + glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI, &memoryInKiB); + + nlinfo("3D: GL_TEXTURE_FREE_MEMORY_ATI returned %d KiB", memoryInKiB); + return memoryInKiB; + } + +#if defined(NL_OS_WINDOWS) + if (_Extensions.WGLAMDGPUAssociation) + { + GLuint uNoOfGPUs = nwglGetGPUIDsAMD(0, 0); + GLuint *uGPUIDs = new GLuint[uNoOfGPUs]; + nwglGetGPUIDsAMD(uNoOfGPUs, uGPUIDs); + + GLuint memoryInMiB = 0; + nwglGetGPUInfoAMD(uGPUIDs[0], WGL_GPU_RAM_AMD, GL_UNSIGNED_INT, sizeof(GLuint), &memoryInMiB); + + delete [] uGPUIDs; + + nlinfo("3D: WGL_GPU_RAM_AMD returned %d MiB", memoryInMiB); + return memoryInMiB * 1024; + } +#elif defined(NL_OS_MAC) + GLint rendererID; + + // get current renderer ID + CGLError error = CGLGetParameter([_ctx CGLContextObj], kCGLCPCurrentRendererID, &rendererID); + + if (error == kCGLNoError) + { + GLint nrend = 0; + CGLRendererInfoObj rend; + + // get renderer info for all renderers + error = CGLQueryRendererInfo(0xffffffff, &rend, &nrend); + + if (error == kCGLNoError) + { + for (GLint i = 0; i < nrend; ++i) + { + GLint thisRendererID; + error = CGLDescribeRenderer(rend, i, kCGLRPRendererID, &thisRendererID); + + if (error == kCGLNoError) + { + // see if this is the one we want + if (thisRendererID == rendererID) + { + GLint memoryInMiB = 0; + CGLError error = CGLDescribeRenderer(rend, i, kCGLRPVideoMemoryMegabytes, &memoryInMiB); + + if (error == kCGLNoError) + { + // convert in KiB + return memoryInMiB * 1024; + } + else + { + nlerror("3D: Unable to get video memory (%s)", CGLErrorString(error)); + } + } + } + else + { + nlerror("3D: Unable to get renderer ID (%s)", CGLErrorString(error)); + } + } + + CGLDestroyRendererInfo(rend); + } + else + { + nlerror("3D: Unable to get renderers info (%s)", CGLErrorString(error)); + } + } + else + { + nlerror("3D: Unable to get current renderer ID (%s)", CGLErrorString(error)); + } +#endif + + return -1; +} + bool CDriverGL::clipRect(NLMISC::CRect &rect) { H_AUTO_OGL(CDriverGL_clipRect) @@ -2546,6 +2645,7 @@ bool CDriverGL::getAdapter(uint adapter, CAdapter &desc) const desc.Revision = 0; desc.SubSysId = 0; desc.VendorId = 0; + desc.VideoMemory = getTotalVideoMemory(); return true; } return false; diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.h b/code/nel/src/3d/driver/opengl/driver_opengl.h index 6affa6929..cb4b00b46 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.h +++ b/code/nel/src/3d/driver/opengl/driver_opengl.h @@ -520,6 +520,8 @@ public: virtual const char* getVideocardInformation (); + virtual sint getTotalVideoMemory() const; + virtual bool isActive (); virtual uint8 getBitPerPixel (); diff --git a/code/nel/src/3d/driver/opengl/driver_opengl_extension.cpp b/code/nel/src/3d/driver/opengl/driver_opengl_extension.cpp index 7342b3efc..700780077 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl_extension.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl_extension.cpp @@ -1790,44 +1790,7 @@ void registerGlExtensions(CGlExtensions &ext) #ifndef USE_OPENGLES ext.NVXGPUMemoryInfo = setupNVXGPUMemoryInfo(glext); - - if (ext.NVXGPUMemoryInfo) - { - GLint nEvictionCount = 0; -#ifdef GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX - glGetIntegerv(GL_GPU_MEMORY_INFO_EVICTION_COUNT_NVX, &nEvictionCount); -#endif - - GLint nEvictionMemory = 0; -#ifdef GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX - glGetIntegerv(GL_GPU_MEMORY_INFO_EVICTED_MEMORY_NVX, &nEvictionMemory); -#endif - - GLint nDedicatedMemoryInKB = 0; -#ifdef GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX - glGetIntegerv(GL_GPU_MEMORY_INFO_DEDICATED_VIDMEM_NVX, &nDedicatedMemoryInKB); -#endif - - GLint nTotalMemoryInKB = 0; -#ifdef GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX - glGetIntegerv(GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX, &nTotalMemoryInKB); -#endif - - GLint nCurAvailMemoryInKB = 0; -#ifdef GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX - glGetIntegerv(GL_GPU_MEMORY_INFO_CURRENT_AVAILABLE_VIDMEM_NVX, &nCurAvailMemoryInKB); -#endif - - nlinfo("Memory: total: %d available: %d dedicated: %d", nTotalMemoryInKB, nCurAvailMemoryInKB, nDedicatedMemoryInKB); - } - ext.ATIMeminfo = setupATIMeminfo(glext); - - if (ext.ATIMeminfo) - { - GLint nCurAvailMemoryInKB = 0; - glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI, &nCurAvailMemoryInKB); - } #endif } @@ -1999,18 +1962,6 @@ bool registerWGlExtensions(CGlExtensions &ext, HDC hDC) ext.WGLAMDGPUAssociation = setupWGLAMDGPUAssociation(glext); - if (ext.WGLAMDGPUAssociation) - { - GLuint uNoOfGPUs = nwglGetGPUIDsAMD(0, 0); - GLuint *uGPUIDs = new GLuint[uNoOfGPUs]; - nwglGetGPUIDsAMD(uNoOfGPUs, uGPUIDs); - - GLuint uTotalMemoryInMB = 0; - nwglGetGPUInfoAMD(uGPUIDs[0], WGL_GPU_RAM_AMD, GL_UNSIGNED_INT, sizeof(GLuint), &uTotalMemoryInMB); - - delete [] uGPUIDs; - } - ext.WGLNVGPUAffinity = setupWGLNVGPUAssociation(glext); if (ext.WGLNVGPUAffinity) diff --git a/code/nel/src/3d/driver_user.cpp b/code/nel/src/3d/driver_user.cpp index 457197d70..812bb52a9 100644 --- a/code/nel/src/3d/driver_user.cpp +++ b/code/nel/src/3d/driver_user.cpp @@ -1534,6 +1534,12 @@ const char* CDriverUser::getVideocardInformation () return _Driver->getVideocardInformation (); } +sint CDriverUser::getTotalVideoMemory () const +{ + NL3D_HAUTO_UI_DRIVER; + + return _Driver->getTotalVideoMemory (); +} uint CDriverUser::getNbTextureStages() { NL3D_HAUTO_UI_DRIVER; From 07a1285740414e255c7c36e51b3c1f3eb2c598e6 Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 23 Dec 2015 14:47:11 +0100 Subject: [PATCH 02/16] Fixed: Target at least Windows 2000 --HG-- branch : develop --- code/nel/include/nel/misc/dummy_window.h | 6 +++--- code/nel/include/nel/misc/inter_window_msg_queue.h | 6 +++--- code/nel/include/nel/misc/win_displayer.h | 6 +++--- code/nel/src/misc/stdmisc.h | 6 +++--- code/nel/src/net/stdnet.h | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/code/nel/include/nel/misc/dummy_window.h b/code/nel/include/nel/misc/dummy_window.h index 81ef078f9..0993aebaa 100644 --- a/code/nel/include/nel/misc/dummy_window.h +++ b/code/nel/include/nel/misc/dummy_window.h @@ -26,13 +26,13 @@ # define WIN32_LEAN_AND_MEAN #endif #ifndef _WIN32_WINDOWS -# define _WIN32_WINDOWS 0x0410 +# define _WIN32_WINDOWS 0x0500 #endif #ifndef _WIN32_WINNT -# define _WIN32_WINNT 0x0400 +# define _WIN32_WINNT 0x0500 #endif #ifndef WINVER -# define WINVER 0x0400 +# define WINVER 0x0500 #endif #ifndef NOMINMAX # define NOMINMAX diff --git a/code/nel/include/nel/misc/inter_window_msg_queue.h b/code/nel/include/nel/misc/inter_window_msg_queue.h index c23a52412..501105f61 100644 --- a/code/nel/include/nel/misc/inter_window_msg_queue.h +++ b/code/nel/include/nel/misc/inter_window_msg_queue.h @@ -31,13 +31,13 @@ # define WIN32_LEAN_AND_MEAN #endif #ifndef _WIN32_WINDOWS -# define _WIN32_WINDOWS 0x0410 +# define _WIN32_WINDOWS 0x0500 #endif #ifndef _WIN32_WINNT -# define _WIN32_WINNT 0x0400 +# define _WIN32_WINNT 0x0500 #endif #ifndef WINVER -# define WINVER 0x0400 +# define WINVER 0x0500 #endif #ifndef NOMINMAX # define NOMINMAX diff --git a/code/nel/include/nel/misc/win_displayer.h b/code/nel/include/nel/misc/win_displayer.h index f450055a9..7eca48351 100644 --- a/code/nel/include/nel/misc/win_displayer.h +++ b/code/nel/include/nel/misc/win_displayer.h @@ -25,13 +25,13 @@ # define WIN32_LEAN_AND_MEAN #endif #ifndef _WIN32_WINDOWS -# define _WIN32_WINDOWS 0x0410 +# define _WIN32_WINDOWS 0x0500 #endif #ifndef _WIN32_WINNT -# define _WIN32_WINNT 0x0400 +# define _WIN32_WINNT 0x0500 #endif #ifndef WINVER -# define WINVER 0x0400 +# define WINVER 0x0500 #endif #ifndef NOMINMAX # define NOMINMAX diff --git a/code/nel/src/misc/stdmisc.h b/code/nel/src/misc/stdmisc.h index b24a74616..770f2bf9f 100644 --- a/code/nel/src/misc/stdmisc.h +++ b/code/nel/src/misc/stdmisc.h @@ -46,12 +46,12 @@ #ifdef NL_OS_WINDOWS # define WIN32_LEAN_AND_MEAN -# define _WIN32_WINDOWS 0x0410 +# define _WIN32_WINDOWS 0x0500 # ifndef _WIN32_WINNT -# define _WIN32_WINNT 0x0400 +# define _WIN32_WINNT 0x0500 # endif # ifndef NL_COMP_MINGW -# define WINVER 0x0400 +# define WINVER 0x0500 # define NOMINMAX # endif # include diff --git a/code/nel/src/net/stdnet.h b/code/nel/src/net/stdnet.h index df2bc931d..b09df1c4f 100644 --- a/code/nel/src/net/stdnet.h +++ b/code/nel/src/net/stdnet.h @@ -17,9 +17,9 @@ #include "nel/misc/types_nl.h" #ifdef NL_OS_WINDOWS -# define _WIN32_WINDOWS 0x0410 +# define _WIN32_WINDOWS 0x0500 # ifndef NL_COMP_MINGW -# define WINVER 0x0400 +# define WINVER 0x0500 # define NOMINMAX # endif # include From f57b1b94218ea9d219ca644e140eaf5ed7cc5fe6 Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 23 Dec 2015 14:48:33 +0100 Subject: [PATCH 03/16] Changed: Implement CSystemUtils::getTotalVideoMemory() for Windows --HG-- branch : develop --- code/nel/include/nel/misc/system_utils.h | 1 + code/nel/src/misc/system_utils.cpp | 238 +++++++++++++++++++++++ 2 files changed, 239 insertions(+) diff --git a/code/nel/include/nel/misc/system_utils.h b/code/nel/include/nel/misc/system_utils.h index 78fd011c6..b6f121d94 100644 --- a/code/nel/include/nel/misc/system_utils.h +++ b/code/nel/include/nel/misc/system_utils.h @@ -81,6 +81,7 @@ public: /// Detect whether the current process is a windowed application. Return true if definitely yes, false if unknown static bool detectWindowedApplication(); + static sint getTotalVideoMemory(); }; } // NLMISC diff --git a/code/nel/src/misc/system_utils.cpp b/code/nel/src/misc/system_utils.cpp index bb1111b88..a350ab305 100644 --- a/code/nel/src/misc/system_utils.cpp +++ b/code/nel/src/misc/system_utils.cpp @@ -18,6 +18,14 @@ #include "nel/misc/system_utils.h" #ifdef NL_OS_WINDOWS +#define INITGUID +#include +#include +#include +#include +#include +#include +#include # include # ifdef _WIN32_WINNT_WIN7 // only supported by Windows 7 Platform SDK @@ -365,4 +373,234 @@ bool CSystemUtils::detectWindowedApplication() return false; } +#ifdef NL_OS_WINDOWS +#ifndef SAFE_RELEASE +#define SAFE_RELEASE(p) { if (p) { (p)->Release(); (p) = NULL; } } +#endif + +typedef HRESULT (WINAPI* LPDIRECTDRAWCREATE)(GUID FAR *lpGUID, LPDIRECTDRAW FAR *lplpDD, IUnknown FAR *pUnkOuter); +typedef HRESULT (WINAPI* LPCREATEDXGIFACTORY)(REFIID, void**); + +static std::string FormatError(HRESULT hr) +{ + std::string res; + + LPTSTR errorText = NULL; + + FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&errorText, 0, NULL); + + if (errorText) + { + res = NLMISC::toString("%s (0x%x)", errorText, hr); + LocalFree(errorText); + errorText = NULL; + } + + return res; +} + +struct SAdapter +{ + uint id; + std::string name; + sint memory; + GUID guid; + HMONITOR hMonitor; + bool found; + + SAdapter() + { + id = 0; + memory = -1; + guid = GUID_NULL; + hMonitor = NULL; + found = false; + } +}; + +static std::list s_dxgiAdapters; + +static void EnumerateUsingDXGI(IDXGIFactory *pDXGIFactory) +{ + nlassert(pDXGIFactory != NULL); + + for(uint index = 0; ; ++index) + { + IDXGIAdapter *pAdapter = NULL; + HRESULT hr = pDXGIFactory->EnumAdapters(index, &pAdapter); + // DXGIERR_NOT_FOUND is expected when the end of the list is hit + if (FAILED(hr)) break; + + DXGI_ADAPTER_DESC desc; + memset(&desc, 0, sizeof(DXGI_ADAPTER_DESC)); + + if (SUCCEEDED(pAdapter->GetDesc(&desc))) + { + SAdapter adapter; + adapter.id = index; + adapter.name = ucstring((ucchar*)desc.Description).toUtf8(); + adapter.memory = desc.DedicatedVideoMemory / 1024; + adapter.found = true; + + nldebug("DXGI Adapter: %u - %s - DedicatedVideoMemory: %d KiB", index, adapter.name.c_str(), adapter.memory); + + s_dxgiAdapters.push_back(adapter); + } + + SAFE_RELEASE(pAdapter); + } +} + +BOOL WINAPI DDEnumCallbackEx(GUID FAR* lpGUID, LPSTR lpDriverDescription, LPSTR lpDriverName, LPVOID lpContext, HMONITOR hm) +{ + SAdapter * pAdapter = (SAdapter*)lpContext; + + if (pAdapter->hMonitor == hm) + { + pAdapter->name = lpDriverDescription; + pAdapter->guid = *lpGUID; + pAdapter->found = true; + } + + return TRUE; +} + +#endif + +sint CSystemUtils::getTotalVideoMemory() +{ + sint res = -1; + +#ifdef NL_OS_WINDOWS + // using DXGI + HINSTANCE hDXGI = LoadLibraryA("dxgi.dll"); + + if (hDXGI) + { + + // We prefer the use of DXGI 1.1 + LPCREATEDXGIFACTORY pCreateDXGIFactory = (LPCREATEDXGIFACTORY)GetProcAddress(hDXGI, "CreateDXGIFactory1"); + + if (!pCreateDXGIFactory) + { + pCreateDXGIFactory = (LPCREATEDXGIFACTORY)GetProcAddress(hDXGI, "CreateDXGIFactory"); + } + + if (pCreateDXGIFactory) + { + IDXGIFactory *pDXGIFactory = NULL; + HRESULT hr = pCreateDXGIFactory(__uuidof(IDXGIFactory), (LPVOID*)&pDXGIFactory); + + if (SUCCEEDED(hr)) + { + EnumerateUsingDXGI(pDXGIFactory); + + SAFE_RELEASE(pDXGIFactory); + + if (!s_dxgiAdapters.empty()) + { + // TODO: determine what adapter is used by NeL + res = s_dxgiAdapters.front().memory; + } + else + { + nlwarning("Unable to find an DXGI adapter"); + } + } + else + { + nlwarning("Unable to create DXGI factory"); + } + } + else + { + nlwarning("dxgi.dll missing entry-point"); + } + + FreeLibrary(hDXGI); + } + + if (res == -1) + { + // using DirectDraw + HMODULE hInstDDraw = LoadLibraryA("ddraw.dll"); + + if (hInstDDraw) + { + SAdapter adapter; + adapter.hMonitor = MonitorFromWindow(s_window, MONITOR_DEFAULTTONULL); + + LPDIRECTDRAWENUMERATEEXA pDirectDrawEnumerateEx = (LPDIRECTDRAWENUMERATEEXA)GetProcAddress(hInstDDraw, "DirectDrawEnumerateExA"); + LPDIRECTDRAWCREATE pDDCreate = (LPDIRECTDRAWCREATE)GetProcAddress(hInstDDraw, "DirectDrawCreate"); + + if (pDirectDrawEnumerateEx && pDDCreate) + { + HRESULT hr = pDirectDrawEnumerateEx(DDEnumCallbackEx, (VOID*)&adapter, DDENUM_ATTACHEDSECONDARYDEVICES); + + if (SUCCEEDED(hr) && adapter.found) + { + LPDIRECTDRAW pDDraw = NULL; + hr = pDDCreate(&adapter.guid, &pDDraw, NULL); + + if (SUCCEEDED(hr)) + { + LPDIRECTDRAW7 pDDraw7 = NULL; + hr = pDDraw->QueryInterface(IID_IDirectDraw7, (VOID**)&pDDraw7); + + if (SUCCEEDED(hr)) + { + DDSCAPS2 ddscaps; + memset(&ddscaps, 0, sizeof(DDSCAPS2)); + ddscaps.dwCaps = DDSCAPS_VIDEOMEMORY | DDSCAPS_LOCALVIDMEM; + + DWORD pdwAvailableVidMem; + hr = pDDraw7->GetAvailableVidMem(&ddscaps, &pdwAvailableVidMem, NULL); + + if (SUCCEEDED(hr)) + { + res = (sint)pdwAvailableVidMem / 1024; + nlinfo("DirectDraw Adapter: %s - DedicatedVideoMemory: %d KiB", adapter.name.c_str(), adapter.memory); + } + else + { + nlwarning("Unable to get DirectDraw available video memory: %s", FormatError(hr).c_str()); + } + + SAFE_RELEASE(pDDraw7); + } + else + { + nlwarning("Unable to query IDirectDraw7 interface: %s", FormatError(hr).c_str()); + } + } + else + { + nlwarning("Unable to call DirectDrawCreate: %s", FormatError(hr).c_str()); + } + } + else + { + nlwarning("Unable to enumerate DirectDraw adapters (%s): %s", (adapter.found ? "found":"not found"), FormatError(hr).c_str()); + } + } + else + { + nlwarning("Unable to get pointer on DirectDraw functions (DirectDrawEnumerateExA %p, DirectDrawCreate %p)", pDirectDrawEnumerateEx, pDDCreate); + } + + FreeLibrary(hInstDDraw); + } + else + { + nlwarning("Unable to load ddraw.dll"); + } + } +#else + // TODO: implement for other systems +#endif + + return res; +} + } // NLMISC From 09e22e292d8d831a7d306a32c5c097b07ca4d423 Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 23 Dec 2015 14:56:36 +0100 Subject: [PATCH 04/16] Changed: Use toString instead of sprintf --HG-- branch : develop --- code/nel/src/misc/debug.cpp | 8 ++++---- code/nel/src/misc/mem_displayer.cpp | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/code/nel/src/misc/debug.cpp b/code/nel/src/misc/debug.cpp index bcd2d25cb..45a55188c 100644 --- a/code/nel/src/misc/debug.cpp +++ b/code/nel/src/misc/debug.cpp @@ -715,7 +715,8 @@ public: { str = ""; } - str += toString("!0x%X", addr); + + str += toString("!0x%p", (void*)addr); } // @@ -740,9 +741,8 @@ public: { str = ""; } - char tmp[32]; - sprintf (tmp, "!0x%p", addr); - str += tmp; + + str += toString("!0x%p", (void*)addr); //} str +=" DEBUG:"+toString("0x%p", addr); diff --git a/code/nel/src/misc/mem_displayer.cpp b/code/nel/src/misc/mem_displayer.cpp index 0aaac26cc..d92c4d432 100644 --- a/code/nel/src/misc/mem_displayer.cpp +++ b/code/nel/src/misc/mem_displayer.cpp @@ -138,9 +138,8 @@ static string getSourceInfo (DWORD_TYPE addr) { str = ""; } - char tmp[32]; - sprintf (tmp, "!0x%X", addr); - str += tmp; + + str += toString("!0x%p", (void*)addr); } return str; From 5d64a01f58f9112e62da13e7bd2d9ddb9d845123 Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 23 Dec 2015 15:00:49 +0100 Subject: [PATCH 05/16] Fixed: Use Xcb plugin for Qt 5 under Linux --HG-- branch : develop --- .../tools/misc/crash_report/crash_report.cpp | 20 +++++++++---------- code/nel/tools/misc/message_box_qt/main.cpp | 14 +++++++++++++ code/nel/tools/misc/words_dic_qt/main.cpp | 14 +++++++++++++ .../tools/client/client_config_qt/main.cpp | 15 +++++++------- 4 files changed, 46 insertions(+), 17 deletions(-) diff --git a/code/nel/tools/misc/crash_report/crash_report.cpp b/code/nel/tools/misc/crash_report/crash_report.cpp index 72cbc26bf..d3caddd3a 100644 --- a/code/nel/tools/misc/crash_report/crash_report.cpp +++ b/code/nel/tools/misc/crash_report/crash_report.cpp @@ -80,16 +80,17 @@ public: #include -#ifdef Q_OS_WIN32 +#if defined(Q_OS_WIN32) Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin) -#endif - -#ifdef Q_OS_MAC +#elif defined(Q_OS_MAC) Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin) -#endif +#elif defined(Q_OS_UNIX) + Q_IMPORT_PLUGIN(QXcbIntegrationPlugin) #endif -int main( int argc, char **argv ) +#endif + +int main(int argc, char **argv) { #ifndef WIN32 // Workaround to default -style=gtk+ on recent Cinnamon versions @@ -111,14 +112,13 @@ int main( int argc, char **argv ) CCmdLineParser::parse( argc, argv, params ); CCrashReportWidget w; - w.setup( params ); + w.setup(params); w.show(); int ret = app.exec(); - if( ret != EXIT_SUCCESS ) + if(ret != EXIT_SUCCESS) return ret; else return w.getReturnValue(); - -} \ No newline at end of file +} diff --git a/code/nel/tools/misc/message_box_qt/main.cpp b/code/nel/tools/misc/message_box_qt/main.cpp index cab992ef6..22b72ea5a 100644 --- a/code/nel/tools/misc/message_box_qt/main.cpp +++ b/code/nel/tools/misc/message_box_qt/main.cpp @@ -8,6 +8,20 @@ #include #include +#ifdef QT_STATICPLUGIN + +#include + +#if defined(Q_OS_WIN32) + Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin) +#elif defined(Q_OS_MAC) + Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin) +#elif defined(Q_OS_UNIX) + Q_IMPORT_PLUGIN(QXcbIntegrationPlugin) +#endif + +#endif + int main(int argc, char *argv[]) { QApplication app(argc, argv); diff --git a/code/nel/tools/misc/words_dic_qt/main.cpp b/code/nel/tools/misc/words_dic_qt/main.cpp index 31429289c..ae348c7aa 100644 --- a/code/nel/tools/misc/words_dic_qt/main.cpp +++ b/code/nel/tools/misc/words_dic_qt/main.cpp @@ -12,6 +12,20 @@ #define NL_WORDS_DIC_CFG "." #endif +#ifdef QT_STATICPLUGIN + +#include + +#if defined(Q_OS_WIN32) + Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin) +#elif defined(Q_OS_MAC) + Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin) +#elif defined(Q_OS_UNIX) + Q_IMPORT_PLUGIN(QXcbIntegrationPlugin) +#endif + +#endif + int main(int argc, char *argv[]) { diff --git a/code/ryzom/tools/client/client_config_qt/main.cpp b/code/ryzom/tools/client/client_config_qt/main.cpp index 33d379068..52d3cf7bb 100644 --- a/code/ryzom/tools/client/client_config_qt/main.cpp +++ b/code/ryzom/tools/client/client_config_qt/main.cpp @@ -25,18 +25,19 @@ #include -#ifdef Q_OS_WIN32 +#if defined(Q_OS_WIN32) Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin) -#endif - -#ifdef Q_OS_MAC +#elif defined(Q_OS_MAC) Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin) -#endif +#elif defined(Q_OS_UNIX) + Q_IMPORT_PLUGIN(QXcbIntegrationPlugin) #endif -int main( sint32 argc, char **argv ) +#endif + +int main(sint32 argc, char **argv) { - QApplication app( argc, argv ); + QApplication app(argc, argv); QApplication::setWindowIcon(QIcon(":/resources/welcome_icon.png")); QPixmap pixmap(":/resources/splash_screen.png" ); From 360a634f5b3b16fea4a6283856b7c877f8ade4e8 Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 23 Dec 2015 15:03:08 +0100 Subject: [PATCH 06/16] Changed: Don't need to use XDG_CURRENT_DESKTOP under OS X --HG-- branch : develop --- code/nel/tools/misc/crash_report/crash_report.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/nel/tools/misc/crash_report/crash_report.cpp b/code/nel/tools/misc/crash_report/crash_report.cpp index d3caddd3a..c6012a06b 100644 --- a/code/nel/tools/misc/crash_report/crash_report.cpp +++ b/code/nel/tools/misc/crash_report/crash_report.cpp @@ -92,7 +92,7 @@ public: int main(int argc, char **argv) { -#ifndef WIN32 +#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) // Workaround to default -style=gtk+ on recent Cinnamon versions char *currentDesktop = getenv("XDG_CURRENT_DESKTOP"); if (currentDesktop) From ffe0571a12d05899609fb03f4bdd510b1ab9d70d Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 23 Dec 2015 15:03:32 +0100 Subject: [PATCH 07/16] Changed: Use nlwarning instead of nlerror --HG-- branch : develop --- code/nel/src/3d/driver/opengl/driver_opengl.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.cpp b/code/nel/src/3d/driver/opengl/driver_opengl.cpp index d1e1446e5..b01f58ba3 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl.cpp @@ -1272,13 +1272,13 @@ sint CDriverGL::getTotalVideoMemory() const } else { - nlerror("3D: Unable to get video memory (%s)", CGLErrorString(error)); + nlwarning("3D: Unable to get video memory (%s)", CGLErrorString(error)); } } } else { - nlerror("3D: Unable to get renderer ID (%s)", CGLErrorString(error)); + nlwarning("3D: Unable to get renderer ID (%s)", CGLErrorString(error)); } } @@ -1286,7 +1286,7 @@ sint CDriverGL::getTotalVideoMemory() const } else { - nlerror("3D: Unable to get renderers info (%s)", CGLErrorString(error)); + nlwarning("3D: Unable to get renderers info (%s)", CGLErrorString(error)); } } else From 406182671533bfa7037bd60c8c7c754abe06ae45 Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 23 Dec 2015 15:04:22 +0100 Subject: [PATCH 08/16] Changed: Use _LP64 macro instead of sizeof(long unsigned int) == 8 --HG-- branch : develop --- code/nel/include/nel/misc/string_common.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/code/nel/include/nel/misc/string_common.h b/code/nel/include/nel/misc/string_common.h index fac53be66..a5fb43eb1 100644 --- a/code/nel/include/nel/misc/string_common.h +++ b/code/nel/include/nel/misc/string_common.h @@ -195,9 +195,11 @@ inline std::string toString(const sint64 &val) { return toString("%"NL_I64"d", v // error fix for size_t? gcc 4.1.2 requested this type instead of size_t ... inline std::string toString(const long unsigned int &val) { - if (sizeof(long unsigned int) == 8) - return toString((uint64)val); +#ifdef _LP64 + return toString((uint64)val); +#else return toString((uint32)val); +#endif } # endif @@ -210,6 +212,7 @@ inline std::string toString(const size_t &val) { return toString("%"NL_I64"u", v inline std::string toString(const size_t &val) { return toString("%u", val); } #endif #endif + inline std::string toString(const float &val) { return toString("%f", val); } inline std::string toString(const double &val) { return toString("%lf", val); } inline std::string toString(const bool &val) { return toString("%u", val?1:0); } From 55feca30d7e08ec288df1c960addf5da4dfa7365 Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 23 Dec 2015 15:08:08 +0100 Subject: [PATCH 09/16] Changed: Use nlSleep instead of usleep --HG-- branch : develop --- code/nel/include/nel/misc/mutex.h | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/code/nel/include/nel/misc/mutex.h b/code/nel/include/nel/misc/mutex.h index cb7e9a188..ec9c89ceb 100644 --- a/code/nel/include/nel/misc/mutex.h +++ b/code/nel/include/nel/misc/mutex.h @@ -293,12 +293,7 @@ public: if (!atomic_swap (&_Lock)) break; -#ifdef NL_OS_WINDOWS nlSleep (wait_time); -#else - //std::cout << "Sleeping i=" << i << std::endl; - usleep( wait_time*1000 ); -#endif } } } @@ -401,12 +396,7 @@ public: if (!CFastMutex::atomic_swap (&_Lock)) break; -#ifdef NL_OS_WINDOWS nlSleep (wait_time); -#else - //std::cout << "Sleeping i=" << i << std::endl; - usleep( wait_time*1000 ); -#endif } } } From dd69f64225c071849ab21f0cc5ee299f80e33eca Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 23 Dec 2015 15:10:06 +0100 Subject: [PATCH 10/16] Changed: Use a stack size of 1 MiB under all platforms for CCoTask (default under Windows) --HG-- branch : develop --- code/nel/include/nel/misc/co_task.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/nel/include/nel/misc/co_task.h b/code/nel/include/nel/misc/co_task.h index f47ec040e..bfd8f9ef0 100644 --- a/code/nel/include/nel/misc/co_task.h +++ b/code/nel/include/nel/misc/co_task.h @@ -28,8 +28,8 @@ namespace NLMISC # define NL_WIN_CALLBACK #endif - // Default to 8KB stack for tasks - const unsigned int NL_TASK_STACK_SIZE = 8*1024; + // Default to 1MiB stack for tasks + const uint NL_TASK_STACK_SIZE = 1024*1024; // forward def for platform specific data struct TCoTaskData; From 36358cef50a8e91cb0b9740856c53118110f9ff3 Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 23 Dec 2015 15:11:26 +0100 Subject: [PATCH 11/16] Fixed: Wrong units (1 KiB = 1024 B, 1 KB = 1000 B, etc...) --HG-- branch : develop --- code/nel/src/misc/common.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/nel/src/misc/common.cpp b/code/nel/src/misc/common.cpp index 4c0db690e..8eca1d566 100644 --- a/code/nel/src/misc/common.cpp +++ b/code/nel/src/misc/common.cpp @@ -362,7 +362,7 @@ string bytesToHumanReadable (const std::string &bytes) string bytesToHumanReadable (uint64 bytes) { - static const char *divTable[]= { "B", "KB", "MB", "GB", "TB" }; + static const char *divTable[]= { "B", "KiB", "MiB", "GiB", "TiB" }; uint div = 0; uint64 res = bytes; uint64 newres = res; From f1cc7822236f72ff7f99476593cd5e39865a69d4 Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 23 Dec 2015 15:22:06 +0100 Subject: [PATCH 12/16] Changed: Need more checks before using getTotalVideoMemory() --HG-- branch : develop --- code/ryzom/client/src/init_main_loop.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/code/ryzom/client/src/init_main_loop.cpp b/code/ryzom/client/src/init_main_loop.cpp index b7383e308..e30894479 100644 --- a/code/ryzom/client/src/init_main_loop.cpp +++ b/code/ryzom/client/src/init_main_loop.cpp @@ -886,6 +886,15 @@ void initMainLoop() { if(ClientCfg.HDEntityTexture) { + // temporary code for debug + sint videoMemory = Driver->getTotalVideoMemory(); + + if (videoMemory < 0) videoMemory = CSystemUtils::getTotalVideoMemory(); + + videoMemory /= 1024; // size in MiB + + nlinfo("Video Memory detected: %d MiB", videoMemory); + // setup "v2 texture" (or 512*512) Driver->setupAsyncTextureLod(ENTITY_TEXTURE_COARSE_LEVEL, ENTITY_TEXTURE_HIGH_LEVEL); // Allow a big cache for them (should be on 512 Mo card only) From 4fa6247672c905001155b8ebb580d37f120de7e0 Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 23 Dec 2015 15:23:50 +0100 Subject: [PATCH 13/16] Changed: windows.h already included in stdligo.h --HG-- branch : develop --- code/nel/src/ligo/zone_bank.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/code/nel/src/ligo/zone_bank.cpp b/code/nel/src/ligo/zone_bank.cpp index a099168f8..6d5de79e8 100644 --- a/code/nel/src/ligo/zone_bank.cpp +++ b/code/nel/src/ligo/zone_bank.cpp @@ -24,12 +24,6 @@ #include "nel/misc/i_xml.h" #include "nel/misc/o_xml.h" -#ifdef NL_OS_WINDOWS -#ifndef NL_COMP_MINGW -#define NOMINMAX -#endif -#include -#endif // NL_OS_WINDOWS using namespace std; using namespace NLMISC; From 4694ca2580034391ec14114cb14ec06b5971ebdb Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 23 Dec 2015 15:28:33 +0100 Subject: [PATCH 14/16] Fixed: Colors are on 3 bits (colors goes from 0 to 7) so 254 was converted to 6 (white) --HG-- branch : develop --- .../src/entities_game_service/player_manager/character.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/ryzom/server/src/entities_game_service/player_manager/character.cpp b/code/ryzom/server/src/entities_game_service/player_manager/character.cpp index 0945983c6..3107ba75c 100644 --- a/code/ryzom/server/src/entities_game_service/player_manager/character.cpp +++ b/code/ryzom/server/src/entities_game_service/player_manager/character.cpp @@ -4880,7 +4880,7 @@ void CCharacter::updateVisualInformation( uint16 InventoryEmpty, uint16 SlotEmpt } // update visual property only if srcForm is valid if(srcForm) - setVisualPropertyForEquipment( SlotEmpty, srcForm, 0 , 254 ); + setVisualPropertyForEquipment( SlotEmpty, srcForm, 0 , 6 ); } } From cfd905b4a911afd3dd1aa54687126f7e406ed82c Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 23 Dec 2015 15:30:12 +0100 Subject: [PATCH 15/16] Changed: Replace ~0u by std::numeric_limits::max() --HG-- branch : develop --- .../src/ai_service/bot_chat_interface.cpp | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/code/ryzom/server/src/ai_service/bot_chat_interface.cpp b/code/ryzom/server/src/ai_service/bot_chat_interface.cpp index 4676eac84..36dc9aa42 100644 --- a/code/ryzom/server/src/ai_service/bot_chat_interface.cpp +++ b/code/ryzom/server/src/ai_service/bot_chat_interface.cpp @@ -88,7 +88,7 @@ struct SBotChatAutomatonState uint On[5]; // value to return on player click of slot 0..4 // ctor ----------------------------------------------------------------- - SBotChatAutomatonState(SBotChatPage *page,uint on0=~0u,uint on1=~0u,uint on2=~0u,uint on3=~0u,uint on4=~0u) + SBotChatAutomatonState(SBotChatPage *page,uint on0=std::numeric_limits::max(),uint on1=std::numeric_limits::max(),uint on2=std::numeric_limits::max(),uint on3=std::numeric_limits::max(),uint on4=std::numeric_limits::max()) { Page=page; On[0]=on0; @@ -100,8 +100,8 @@ struct SBotChatAutomatonState // make sure the number of arguments supplied corresponds to the // number of options prresent on the user interfac page nlassert(page->NumOptions>=0 && page->NumOptions<=4); - nlassert(page->NumOptions==0 || On[page->NumOptions-1]!=~0u); - nlassert(page->NumOptions==4 || On[page->NumOptions]==~0u); + nlassert(page->NumOptions==0 || On[page->NumOptions-1]!=std::numeric_limits::max()); + nlassert(page->NumOptions==4 || On[page->NumOptions]==std::numeric_limits::max()); } }; @@ -344,7 +344,7 @@ struct CBotChat void setState(uint32 state) { - if (state>=Automaton->Size && state!=~0u) + if (state>=Automaton->Size && state!=std::numeric_limits::max()) { nlwarning("CBotChatEntry()::setState: Invalid state: %d",state); return; @@ -356,7 +356,7 @@ struct CBotChat // open the new page CurrentState=state; - if (state==~0u) + if (state==std::numeric_limits::max()) Done=true; else Done=!Automaton->States[CurrentState].Page->PageType->open(Player,Bot); @@ -377,7 +377,7 @@ struct CBotChat void setAutomaton(SBotChatAutomaton *automaton) { Automaton=automaton; - CurrentState=~0u; // set this to a ~0 so that setState doesn't try to clse existing page + CurrentState=std::numeric_limits::max(); // set this to a ~0 so that setState doesn't try to clse existing page setState(0); } @@ -396,7 +396,7 @@ struct CBotChat void endChat () { - setState(~0u); + setState(std::numeric_limits::max()); } CEntityId Player; @@ -672,7 +672,7 @@ struct SBotChatAutomatonState uint On[5]; // value to return on player click of slot 0..4 // ctor ----------------------------------------------------------------- - SBotChatAutomatonState(SBotChatPage *page,uint on0=~0u,uint on1=~0u,uint on2=~0u,uint on3=~0u,uint on4=~0u) + SBotChatAutomatonState(SBotChatPage *page,uint on0=std::numeric_limits::max(),uint on1=std::numeric_limits::max(),uint on2=std::numeric_limits::max(),uint on3=std::numeric_limits::max(),uint on4=std::numeric_limits::max()) { Page=page; On[0]=on0; @@ -684,8 +684,8 @@ struct SBotChatAutomatonState // make sure the number of arguments supplied corresponds to the // number of options prresent on the user interfac page nlassert(page->NumOptions>=0 && page->NumOptions<=4); - nlassert(page->NumOptions==0 || On[page->NumOptions-1]!=~0u); - nlassert(page->NumOptions==4 || On[page->NumOptions]==~0u); + nlassert(page->NumOptions==0 || On[page->NumOptions-1]!=std::numeric_limits::max()); + nlassert(page->NumOptions==4 || On[page->NumOptions]==std::numeric_limits::max()); } }; @@ -928,7 +928,7 @@ struct CBotChat void setState(uint32 state) { - if (state>=Automaton->Size && state!=~0u) + if (state>=Automaton->Size && state!=std::numeric_limits::max()) { nlwarning("CBotChatEntry()::setState: Invalid state: %d",state); return; @@ -940,7 +940,7 @@ struct CBotChat // open the new page CurrentState=state; - if (state==~0u) + if (state==std::numeric_limits::max()) Done=true; else Done=!Automaton->States[CurrentState].Page->PageType->open(Player,Bot); @@ -961,7 +961,7 @@ struct CBotChat void setAutomaton(SBotChatAutomaton *automaton) { Automaton=automaton; - CurrentState=~0u; // set this to a ~0 so that setState doesn't try to clse existing page + CurrentState=std::numeric_limits::max(); // set this to a std::numeric_limits::max() so that setState doesn't try to clse existing page setState(0); } @@ -980,7 +980,7 @@ struct CBotChat void endChat () { - setState(~0u); + setState(std::numeric_limits::max()); } CEntityId Player; From a86a013a16f9b7319c2e04204c197a48afc1114c Mon Sep 17 00:00:00 2001 From: kervala Date: Wed, 23 Dec 2015 15:30:52 +0100 Subject: [PATCH 16/16] Fixed: Warning when $json was empty (but perhaps we should fix the real reason...) --HG-- branch : develop --- code/web/private_php/ams/autoload/users.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/web/private_php/ams/autoload/users.php b/code/web/private_php/ams/autoload/users.php index 67ed9af88..5b3bfaa2d 100644 --- a/code/web/private_php/ams/autoload/users.php +++ b/code/web/private_php/ams/autoload/users.php @@ -357,7 +357,7 @@ class Users{ //error_log(print_r($rows,true)); //error_log(print_r($result,true)); //error_log(print_r($json,true)); - foreach ($json as $key => $value) { + if ($json) foreach ($json as $key => $value) { //error_log(print_r($key,true)); //error_log(print_r($value,true));