From 4265e9d801711b46ce9190fdc4a7a29aaf0e7d8b Mon Sep 17 00:00:00 2001 From: Luke Street Date: Tue, 22 Jun 2021 17:21:21 -0400 Subject: [PATCH] Use UTF-8 exclusively internally; update logvisor --- .gitignore | 4 ++ CMakeLists.txt | 66 ++++++++++++++++- include/boo/IApplication.hpp | 22 +++--- include/boo/IWindow.hpp | 5 +- include/boo/System.hpp | 16 ----- include/boo/UWPViewProvider.hpp | 14 ++-- include/boo/audiodev/IAudioVoiceEngine.hpp | 3 - include/boo/graphicsdev/D3D.hpp | 4 +- include/boo/graphicsdev/GL.hpp | 2 +- .../boo/graphicsdev/IGraphicsCommandQueue.hpp | 2 +- .../boo/graphicsdev/IGraphicsDataFactory.hpp | 4 +- include/boo/graphicsdev/Metal.hpp | 2 +- include/boo/graphicsdev/NX.hpp | 2 +- include/boo/graphicsdev/Vulkan.hpp | 2 +- lib/audiodev/WASAPI.cpp | 70 +++++++------------ lib/audiodev/WAVOut.cpp | 21 ++---- lib/graphicsdev/D3D11.cpp | 9 +-- lib/graphicsdev/GL.cpp | 10 +-- lib/graphicsdev/Vulkan.cpp | 4 +- lib/mac/ApplicationCocoa.mm | 42 +++++------ lib/mac/WindowCocoa.mm | 2 +- lib/win/ApplicationUWP.cpp | 32 ++++----- lib/win/ApplicationWin32.cpp | 44 ++++++------ lib/win/WinCommon.hpp | 16 +---- lib/win/WindowUWP.cpp | 8 +-- lib/win/WindowWin32.cpp | 30 ++++---- logvisor | 2 +- test/main.cpp | 40 ++++------- 28 files changed, 238 insertions(+), 240 deletions(-) diff --git a/.gitignore b/.gitignore index e43b0f9..9f7b734 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ .DS_Store +.idea/ +cmake-build-*/ +build/ +out/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 9198937..0fb9821 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,10 +2,72 @@ cmake_minimum_required(VERSION 3.10 FATAL_ERROR) # because of c++17 project(boo) cmake_policy(SET CMP0074 NEW) -if (NOT MSVC) +if (MSVC) + # Shaddup MSVC + add_compile_definitions(UNICODE=1 _UNICODE=1 __SSE__=1 + _CRT_SECURE_NO_WARNINGS=1 D_SCL_SECURE_NO_WARNINGS=1 + _SCL_SECURE_NO_DEPRECATE=1 _CRT_NONSTDC_NO_WARNINGS=1 + _ENABLE_EXTENDED_ALIGNED_STORAGE=1 NOMINMAX=1) + add_compile_options(/IGNORE:4221 + $<$,$>:/wd4018> + $<$,$>:/wd4800> + $<$,$>:/wd4005> + $<$,$>:/wd4311> + $<$,$>:/wd4068> + $<$,$>:/wd4267> + $<$,$>:/wd4244> + $<$,$>:/wd4200> + $<$,$>:/wd4305> + $<$,$>:/wd4067> + $<$,$>:/wd4146> + $<$,$>:/wd4309> + $<$,$>:/wd4805> + ${VS_OPTIONS}) + + string(REPLACE "/GR " "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + string(REPLACE " /EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + add_compile_options( + # Disable exceptions + $<$:/EHsc-> + + # Disable RTTI + $<$:/GR-> + + # Enforce various standards compliant behavior. + $<$:/permissive-> + + # Enable standard volatile semantics. + $<$:/volatile:iso> + + # Reports the proper value for the __cplusplus preprocessor macro. + $<$:/Zc:__cplusplus> + + # Use latest C++ standard. + $<$:/std:c++latest> + ) + + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + # Flags for MSVC (not clang-cl) + add_compile_options( + # Allow constexpr variables to have explicit external linkage. + $<$:/Zc:externConstexpr> + + # Assume that new throws exceptions, allowing better code generation. + $<$:/Zc:throwingNew> + + # Link-time Code Generation for Release builds + $<$:/GL> + ) + + # Link-time Code Generation for Release builds + set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "/LTCG") + set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO") + set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "/DEBUG /RELEASE /OPT:REF /OPT:ICF /INCREMENTAL:NO /DEBUGTYPE:cv,fixup") + endif () +else () set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) -endif() +endif () set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}") diff --git a/include/boo/IApplication.hpp b/include/boo/IApplication.hpp index 36811fb..b648768 100644 --- a/include/boo/IApplication.hpp +++ b/include/boo/IApplication.hpp @@ -14,7 +14,7 @@ class IApplication; struct IApplicationCallback { virtual int appMain(IApplication*) = 0; virtual void appQuitting(IApplication*) = 0; - virtual void appFilesOpen(IApplication*, const std::vector&) {} + virtual void appFilesOpen(IApplication*, const std::vector&) {} }; class IApplication { @@ -44,28 +44,28 @@ public: virtual EPlatformType getPlatformType() const = 0; virtual int run() = 0; - virtual SystemStringView getUniqueName() const = 0; - virtual SystemStringView getFriendlyName() const = 0; - virtual SystemStringView getProcessName() const = 0; - virtual const std::vector& getArgs() const = 0; + virtual std::string_view getUniqueName() const = 0; + virtual std::string_view getFriendlyName() const = 0; + virtual std::string_view getProcessName() const = 0; + virtual const std::vector& getArgs() const = 0; /* Constructors/initializers for sub-objects */ - virtual std::shared_ptr newWindow(SystemStringView title) = 0; + virtual std::shared_ptr newWindow(std::string_view title) = 0; }; -int ApplicationRun(IApplication::EPlatformType platform, IApplicationCallback& cb, SystemStringView uniqueName, - SystemStringView friendlyName, SystemStringView pname, const std::vector& args, +int ApplicationRun(IApplication::EPlatformType platform, IApplicationCallback& cb, std::string_view uniqueName, + std::string_view friendlyName, std::string_view pname, const std::vector& args, std::string_view gfxApi = {}, uint32_t samples = 1, uint32_t anisotropy = 1, bool deepColor = false, bool singleInstance = true); extern IApplication* APP; static inline int ApplicationRun(IApplication::EPlatformType platform, IApplicationCallback& cb, - SystemStringView uniqueName, SystemStringView friendlyName, int argc, - const SystemChar** argv, std::string_view gfxApi = {}, uint32_t samples = 1, + std::string_view uniqueName, std::string_view friendlyName, int argc, + char** argv, std::string_view gfxApi = {}, uint32_t samples = 1, uint32_t anisotropy = 1, bool deepColor = false, bool singleInstance = true) { if (APP) return 1; - std::vector args; + std::vector args; for (int i = 1; i < argc; ++i) args.push_back(argv[i]); return ApplicationRun(platform, cb, uniqueName, friendlyName, argv[0], args, gfxApi, samples, anisotropy, deepColor, diff --git a/include/boo/IWindow.hpp b/include/boo/IWindow.hpp index 0da4fe1..3f75c25 100644 --- a/include/boo/IWindow.hpp +++ b/include/boo/IWindow.hpp @@ -118,6 +118,7 @@ enum class ESpecialKey { Up = 24, Down = 25, Tab = 26, + MAX = 27, }; enum class EModifierKey { @@ -216,8 +217,8 @@ public: virtual void showWindow() = 0; virtual void hideWindow() = 0; - virtual SystemString getTitle() = 0; - virtual void setTitle(SystemStringView title) = 0; + virtual std::string getTitle() = 0; + virtual void setTitle(std::string_view title) = 0; virtual void setCursor(EMouseCursor cursor) = 0; virtual void setWaitCursor(bool wait) = 0; diff --git a/include/boo/System.hpp b/include/boo/System.hpp index 75e1be9..6d03a06 100644 --- a/include/boo/System.hpp +++ b/include/boo/System.hpp @@ -59,22 +59,6 @@ static inline ComPtr* ReferenceComPtr(ComPtr& ptr) { namespace boo { -#ifdef _WIN32 -using SystemString = std::wstring; -using SystemStringView = std::wstring_view; -using SystemChar = wchar_t; -#ifndef _SYS_STR -#define _SYS_STR(val) L##val -#endif -#else -using SystemString = std::string; -using SystemStringView = std::string_view; -using SystemChar = char; -#ifndef _SYS_STR -#define _SYS_STR(val) val -#endif -#endif - #ifndef NDEBUG #define __BooTraceArgs , const char *file, int line #define __BooTraceArgsUse , file, line diff --git a/include/boo/UWPViewProvider.hpp b/include/boo/UWPViewProvider.hpp index 6f2016c..7122624 100644 --- a/include/boo/UWPViewProvider.hpp +++ b/include/boo/UWPViewProvider.hpp @@ -8,14 +8,14 @@ namespace boo { using namespace Windows::ApplicationModel::Core; ref struct ViewProvider sealed : IFrameworkViewSource { - internal : ViewProvider(boo::IApplicationCallback& appCb, SystemStringView uniqueName, SystemStringView friendlyName, - SystemStringView pname, Platform::Array ^ params, bool singleInstance) + internal : ViewProvider(boo::IApplicationCallback& appCb, std::string_view uniqueName, std::string_view friendlyName, + std::string_view pname, Platform::Array ^ params, bool singleInstance) : m_appCb(appCb) , m_uniqueName(uniqueName) , m_friendlyName(friendlyName) , m_pname(pname) , m_singleInstance(singleInstance) { - SystemChar selfPath[1024]; + char selfPath[1024]; GetModuleFileNameW(nullptr, selfPath, 1024); m_args.reserve(params->Length + 1); m_args.emplace_back(selfPath); @@ -27,10 +27,10 @@ public: virtual IFrameworkView ^ CreateView(); internal : boo::IApplicationCallback& m_appCb; - SystemString m_uniqueName; - SystemString m_friendlyName; - SystemString m_pname; - std::vector m_args; + std::string m_uniqueName; + std::string m_friendlyName; + std::string m_pname; + std::vector m_args; bool m_singleInstance; }; #endif diff --git a/include/boo/audiodev/IAudioVoiceEngine.hpp b/include/boo/audiodev/IAudioVoiceEngine.hpp index b5ffcfe..8353f96 100644 --- a/include/boo/audiodev/IAudioVoiceEngine.hpp +++ b/include/boo/audiodev/IAudioVoiceEngine.hpp @@ -107,8 +107,5 @@ std::unique_ptr NewAudioVoiceEngine(); /** Construct WAV-rendering voice engine */ std::unique_ptr NewWAVAudioVoiceEngine(const char* path, double sampleRate, int numChans); -#if _WIN32 -std::unique_ptr NewWAVAudioVoiceEngine(const wchar_t* path, double sampleRate, int numChans); -#endif } // namespace boo diff --git a/include/boo/graphicsdev/D3D.hpp b/include/boo/graphicsdev/D3D.hpp index 95c7038..54cba71 100644 --- a/include/boo/graphicsdev/D3D.hpp +++ b/include/boo/graphicsdev/D3D.hpp @@ -20,7 +20,7 @@ public: ~D3D11DataFactory() override = default; Platform platform() const override { return Platform::D3D11; } - const SystemChar* platformName() const override { return _SYS_STR("D3D11"); } + const char* platformName() const override { return "D3D11"; } class Context final : public IGraphicsDataFactory::Context { friend class D3D11DataFactoryImpl; @@ -31,7 +31,7 @@ public: public: Platform platform() const override { return Platform::D3D11; } - const SystemChar* platformName() const override { return _SYS_STR("D3D11"); } + const char* platformName() const override { return "D3D11"; } ObjToken newStaticBuffer(BufferUse use, const void* data, size_t stride, size_t count) override; ObjToken newDynamicBuffer(BufferUse use, size_t stride, size_t count) override; diff --git a/include/boo/graphicsdev/GL.hpp b/include/boo/graphicsdev/GL.hpp index 2485627..13ef7df 100644 --- a/include/boo/graphicsdev/GL.hpp +++ b/include/boo/graphicsdev/GL.hpp @@ -27,7 +27,7 @@ public: public: Platform platform() const override { return Platform::OpenGL; } - const SystemChar* platformName() const override { return _SYS_STR("OpenGL"); } + const char* platformName() const override { return "OpenGL"; } ObjToken newStaticBuffer(BufferUse use, const void* data, size_t stride, size_t count) override; ObjToken newDynamicBuffer(BufferUse use, size_t stride, size_t count) override; diff --git a/include/boo/graphicsdev/IGraphicsCommandQueue.hpp b/include/boo/graphicsdev/IGraphicsCommandQueue.hpp index ab8d5aa..e01d6e4 100644 --- a/include/boo/graphicsdev/IGraphicsCommandQueue.hpp +++ b/include/boo/graphicsdev/IGraphicsCommandQueue.hpp @@ -15,7 +15,7 @@ struct IGraphicsCommandQueue { using Platform = IGraphicsDataFactory::Platform; virtual Platform platform() const = 0; - virtual const SystemChar* platformName() const = 0; + virtual const char* platformName() const = 0; virtual void setShaderDataBinding(const ObjToken& binding) = 0; virtual void setRenderTarget(const ObjToken& target) = 0; diff --git a/include/boo/graphicsdev/IGraphicsDataFactory.hpp b/include/boo/graphicsdev/IGraphicsDataFactory.hpp index ba49fa0..a06c1f1 100644 --- a/include/boo/graphicsdev/IGraphicsDataFactory.hpp +++ b/include/boo/graphicsdev/IGraphicsDataFactory.hpp @@ -214,11 +214,11 @@ struct IGraphicsDataFactory { enum class Platform { Null, OpenGL, D3D11, Metal, Vulkan, GX, NX }; virtual Platform platform() const = 0; - virtual const SystemChar* platformName() const = 0; + virtual const char* platformName() const = 0; struct Context { virtual Platform platform() const = 0; - virtual const SystemChar* platformName() const = 0; + virtual const char* platformName() const = 0; virtual ObjToken newStaticBuffer(BufferUse use, const void* data, size_t stride, size_t count) = 0; diff --git a/include/boo/graphicsdev/Metal.hpp b/include/boo/graphicsdev/Metal.hpp index c98d250..eff9ce9 100644 --- a/include/boo/graphicsdev/Metal.hpp +++ b/include/boo/graphicsdev/Metal.hpp @@ -22,7 +22,7 @@ public: public: Platform platform() const { return Platform::Metal; } - const SystemChar* platformName() const { return _SYS_STR("Metal"); } + const char* platformName() const { return "Metal"; } ObjToken newStaticBuffer(BufferUse use, const void* data, size_t stride, size_t count); ObjToken newDynamicBuffer(BufferUse use, size_t stride, size_t count); diff --git a/include/boo/graphicsdev/NX.hpp b/include/boo/graphicsdev/NX.hpp index a74b60f..82605fd 100644 --- a/include/boo/graphicsdev/NX.hpp +++ b/include/boo/graphicsdev/NX.hpp @@ -52,7 +52,7 @@ public: public: Platform platform() const { return Platform::NX; } - const SystemChar* platformName() const { return _SYS_STR("NX"); } + const char* platformName() const { return "NX"; } boo::ObjToken newStaticBuffer(BufferUse use, const void* data, size_t stride, size_t count); boo::ObjToken newDynamicBuffer(BufferUse use, size_t stride, size_t count); diff --git a/include/boo/graphicsdev/Vulkan.hpp b/include/boo/graphicsdev/Vulkan.hpp index 95f0455..d9fd69c 100644 --- a/include/boo/graphicsdev/Vulkan.hpp +++ b/include/boo/graphicsdev/Vulkan.hpp @@ -135,7 +135,7 @@ public: public: Platform platform() const { return Platform::Vulkan; } - const SystemChar* platformName() const { return _SYS_STR("Vulkan"); } + const char* platformName() const { return "Vulkan"; } boo::ObjToken newStaticBuffer(BufferUse use, const void* data, size_t stride, size_t count); boo::ObjToken newDynamicBuffer(BufferUse use, size_t stride, size_t count); diff --git a/lib/audiodev/WASAPI.cpp b/lib/audiodev/WASAPI.cpp index d76255b..dce6f6f 100644 --- a/lib/audiodev/WASAPI.cpp +++ b/lib/audiodev/WASAPI.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #ifdef TE_VIRTUAL_MIDI @@ -121,7 +122,7 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine { void _buildAudioRenderClient() { #if !WINDOWS_STORE if (!m_device) { - if (FAILED(m_enumerator->GetDevice(MBSTWCS(m_sinkName.c_str()).c_str(), &m_device))) { + if (FAILED(m_enumerator->GetDevice(nowide::widen(m_sinkName).c_str(), &m_device))) { Log.report(logvisor::Error, FMT_STRING("unable to obtain audio device {}"), m_sinkName); m_device.Reset(); return; @@ -129,7 +130,7 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine { } if (FAILED(m_device->Activate(IID_IAudioClient, CLSCTX_ALL, nullptr, &m_audClient))) { - Log.report(logvisor::Error, FMT_STRING(L"unable to create audio client from device")); + Log.report(logvisor::Error, FMT_STRING("unable to create audio client from device")); m_device.Reset(); return; } @@ -137,7 +138,7 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine { WAVEFORMATEXTENSIBLE* pwfx; if (FAILED(m_audClient->GetMixFormat((WAVEFORMATEX**)&pwfx))) { - Log.report(logvisor::Error, FMT_STRING(L"unable to obtain audio mix format from device")); + Log.report(logvisor::Error, FMT_STRING("unable to obtain audio mix format from device")); #if !WINDOWS_STORE m_device.Reset(); #endif @@ -215,7 +216,7 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine { /* Initialize audio client */ if (FAILED(m_audClient->Initialize(AUDCLNT_SHAREMODE_SHARED, 0, 450000, /* 45ms */ 0, (WAVEFORMATEX*)pwfx, nullptr))) { - Log.report(logvisor::Error, FMT_STRING(L"unable to initialize audio client")); + Log.report(logvisor::Error, FMT_STRING("unable to initialize audio client")); #if !WINDOWS_STORE m_device.Reset(); #endif @@ -236,7 +237,7 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine { m_mixInfo.m_sampleFormat = SOXR_INT32_I; m_mixInfo.m_bitsPerSample = 32; } else { - Log.report(logvisor::Fatal, FMT_STRING(L"unsupported bits-per-sample {}"), pwfx->Format.wBitsPerSample); + Log.report(logvisor::Fatal, FMT_STRING("unsupported bits-per-sample {}"), pwfx->Format.wBitsPerSample); #if !WINDOWS_STORE m_device.Reset(); #endif @@ -249,7 +250,7 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine { m_mixInfo.m_sampleFormat = SOXR_FLOAT32_I; m_mixInfo.m_bitsPerSample = 32; } else { - Log.report(logvisor::Error, FMT_STRING(L"unsupported floating-point bits-per-sample {}"), pwfx->Format.wBitsPerSample); + Log.report(logvisor::Error, FMT_STRING("unsupported floating-point bits-per-sample {}"), pwfx->Format.wBitsPerSample); #if !WINDOWS_STORE m_device.Reset(); #endif @@ -261,7 +262,7 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine { UINT32 bufferFrameCount; if (FAILED(m_audClient->GetBufferSize(&bufferFrameCount))) { - Log.report(logvisor::Error, FMT_STRING(L"unable to get audio buffer frame count")); + Log.report(logvisor::Error, FMT_STRING("unable to get audio buffer frame count")); #if !WINDOWS_STORE m_device.Reset(); #endif @@ -270,7 +271,7 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine { m_mixInfo.m_periodFrames = bufferFrameCount; if (FAILED(m_audClient->GetService(IID_IAudioRenderClient, &m_renderClient))) { - Log.report(logvisor::Error, FMT_STRING(L"unable to create audio render client")); + Log.report(logvisor::Error, FMT_STRING("unable to create audio render client")); #if !WINDOWS_STORE m_device.Reset(); #endif @@ -347,24 +348,24 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine { /* Enumerate default audio device */ if (FAILED( CoCreateInstance(CLSID_MMDeviceEnumerator, nullptr, CLSCTX_ALL, IID_IMMDeviceEnumerator, &m_enumerator))) { - Log.report(logvisor::Error, FMT_STRING(L"unable to create MMDeviceEnumerator instance")); + Log.report(logvisor::Error, FMT_STRING("unable to create MMDeviceEnumerator instance")); return; } if (FAILED(m_enumerator->RegisterEndpointNotificationCallback(&m_notificationClient))) { - Log.report(logvisor::Error, FMT_STRING(L"unable to register multimedia event callback")); + Log.report(logvisor::Error, FMT_STRING("unable to register multimedia event callback")); m_device.Reset(); return; } if (FAILED(m_enumerator->GetDefaultAudioEndpoint(eRender, eConsole, &m_device))) { - Log.report(logvisor::Error, FMT_STRING(L"unable to obtain default audio device")); + Log.report(logvisor::Error, FMT_STRING("unable to obtain default audio device")); m_device.Reset(); return; } LPWSTR sinkName = nullptr; m_device->GetId(&sinkName); - m_sinkName = WCSTMBS(sinkName); + m_sinkName = nowide::narrow(sinkName); CoTaskMemFree(sinkName); _buildAudioRenderClient(); @@ -386,7 +387,7 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine { m_started = false; if (m_mixInfo.m_sampleFormat != oldFmt) - Log.report(logvisor::Fatal, FMT_STRING(L"audio device sample format changed, boo doesn't support this!!")); + Log.report(logvisor::Fatal, FMT_STRING("audio device sample format changed, boo doesn't support this!!")); _resetSampleRate(); } @@ -404,7 +405,7 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine { int attempt = 0; while (true) { if (attempt >= 10) - Log.report(logvisor::Fatal, FMT_STRING(L"unable to setup AudioRenderClient")); + Log.report(logvisor::Fatal, FMT_STRING("unable to setup AudioRenderClient")); if (m_rebuild) { m_device.Reset(); @@ -473,7 +474,7 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine { bool setCurrentAudioOutput(const char* name) override { ComPtr newDevice; - if (FAILED(m_enumerator->GetDevice(MBSTWCS(name).c_str(), &newDevice))) { + if (FAILED(m_enumerator->GetDevice(nowide::widen(name).c_str(), &newDevice))) { Log.report(logvisor::Error, FMT_STRING("unable to obtain audio device {}"), name); return false; } @@ -488,7 +489,7 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine { ComPtr collection; if (FAILED(m_enumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &collection))) { - Log.report(logvisor::Error, FMT_STRING(L"unable to enumerate audio outputs")); + Log.report(logvisor::Error, FMT_STRING("unable to enumerate audio outputs")); return ret; } @@ -505,8 +506,8 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine { props->GetValue(PKEY_Device_FriendlyName, &val); std::string friendlyName; if (val.vt == VT_LPWSTR) - friendlyName = WCSTMBS(val.pwszVal); - ret.emplace_back(WCSTMBS(devName), std::move(friendlyName)); + friendlyName = nowide::narrow(val.pwszVal); + ret.emplace_back(nowide::narrow(devName), std::move(friendlyName)); } return ret; @@ -527,29 +528,12 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine { continue; #ifdef UNICODE - ret.push_back(std::make_pair(std::move(name), WCSTMBS(caps.szPname))); + ret.emplace_back(std::move(name), nowide::narrow(caps.szPname)); #else - ret.push_back(std::make_pair(std::move(name), std::string(caps.szPname))); + ret.emplace_back(std::move(name), std::string(caps.szPname)); #endif } -#if 0 - for (UINT i=0 ; igetFriendlyName()) + _SYS_STR(" MIDI-In"); + std::string name = std::string(APP->getFriendlyName()) + " MIDI-In"; auto port = virtualMIDICreatePortEx2PROC(name.c_str(), LPVM_MIDI_DATA_CB(VirtualMIDIReceiveProc), DWORD_PTR(static_cast(ret.get())), 512, TE_VM_FLAGS_PARSE_RX | TE_VM_FLAGS_INSTANTIATE_RX_ONLY); @@ -779,7 +763,7 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine { if (!ret) return {}; - SystemString name = SystemString(APP->getFriendlyName()) + _SYS_STR(" MIDI-Out"); + std::string name = std::string(APP->getFriendlyName()) + " MIDI-Out"; auto port = virtualMIDICreatePortEx2PROC(name.c_str(), nullptr, 0, 512, TE_VM_FLAGS_PARSE_TX | TE_VM_FLAGS_INSTANTIATE_TX_ONLY); if (!port) @@ -800,7 +784,7 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine { if (!ret) return {}; - SystemString name = SystemString(APP->getFriendlyName()) + _SYS_STR(" MIDI-In/Out"); + std::string name = std::string(APP->getFriendlyName()) + " MIDI-In/Out"; auto port = virtualMIDICreatePortEx2PROC(name.c_str(), LPVM_MIDI_DATA_CB(VirtualMIDIReceiveProc), DWORD_PTR(static_cast(ret.get())), 512, TE_VM_FLAGS_SUPPORTED); diff --git a/lib/audiodev/WAVOut.cpp b/lib/audiodev/WAVOut.cpp index d7b0da4..fa6816e 100644 --- a/lib/audiodev/WAVOut.cpp +++ b/lib/audiodev/WAVOut.cpp @@ -4,6 +4,7 @@ #include "boo/audiodev/IAudioVoiceEngine.hpp" #include +#include #include namespace boo { @@ -175,16 +176,17 @@ struct WAVOutVoiceEngine : BaseAudioVoiceEngine { _buildAudioRenderClient(); } +#if _WIN32 WAVOutVoiceEngine(const char* path, double sampleRate, int numChans) { - m_fp = fopen(path, "wb"); + const nowide::wstackstring wpath(path); + m_fp = _wfopen(wpath.get(), L"wb"); if (!m_fp) return; prepareWAV(sampleRate, numChans); } - -#if _WIN32 - WAVOutVoiceEngine(const wchar_t* path, double sampleRate, int numChans) { - m_fp = _wfopen(path, L"wb"); +#else + WAVOutVoiceEngine(const char* path, double sampleRate, int numChans) { + m_fp = fopen(path, "wb"); if (!m_fp) return; prepareWAV(sampleRate, numChans); @@ -243,13 +245,4 @@ std::unique_ptr NewWAVAudioVoiceEngine(const char* path, doub return ret; } -#if _WIN32 -std::unique_ptr NewWAVAudioVoiceEngine(const wchar_t* path, double sampleRate, int numChans) { - std::unique_ptr ret = std::make_unique(path, sampleRate, numChans); - if (!static_cast(*ret).m_fp) - return {}; - return ret; -} -#endif - } // namespace boo diff --git a/lib/graphicsdev/D3D11.cpp b/lib/graphicsdev/D3D11.cpp index 5e76ebe..a392e9d 100644 --- a/lib/graphicsdev/D3D11.cpp +++ b/lib/graphicsdev/D3D11.cpp @@ -16,6 +16,7 @@ #include #include +#include #undef min #undef max @@ -76,8 +77,8 @@ static inline void ThrowIfFailed(HRESULT hr) { #else _com_error err(hr, L"D3D11 fail"); #endif - LPCTSTR errMsg = err.ErrorMessage(); - Log.report(logvisor::Fatal, FMT_STRING(_SYS_STR("{}")), errMsg); + std::string errMsg = nowide::narrow(err.ErrorMessage()); + Log.report(logvisor::Fatal, FMT_STRING("{}"), errMsg); } } @@ -972,7 +973,7 @@ struct D3D11ShaderDataBinding : public GraphicsDataNode { struct D3D11CommandQueue final : IGraphicsCommandQueue { Platform platform() const override { return IGraphicsDataFactory::Platform::D3D11; } - const SystemChar* platformName() const override { return _SYS_STR("D3D11"); } + const char* platformName() const override { return "D3D11"; } D3D11Context* m_ctx; D3D11Context::Window* m_windowCtx; IGraphicsContext* m_parent; @@ -1228,7 +1229,7 @@ struct D3D11CommandQueue final : IGraphicsCommandQueue { #ifdef BOO_GRAPHICS_DEBUG_GROUPS void pushDebugGroup(const char* name, const std::array& color) override { if (m_deferredAnnot) - m_deferredAnnot->BeginEvent(MBSTWCS(name).c_str()); + m_deferredAnnot->BeginEvent(nowide::widen(name).c_str()); } void popDebugGroup() override { diff --git a/lib/graphicsdev/GL.cpp b/lib/graphicsdev/GL.cpp index 97f26a1..e53b0e1 100644 --- a/lib/graphicsdev/GL.cpp +++ b/lib/graphicsdev/GL.cpp @@ -130,7 +130,7 @@ public: GLDataFactoryImpl(IGraphicsContext* parent, GLContext* glCtx) : m_parent(parent), m_glCtx(glCtx) {} Platform platform() const override { return Platform::OpenGL; } - const SystemChar* platformName() const override { return _SYS_STR("OpenGL"); } + const char* platformName() const override { return "OpenGL"; } void commitTransaction(const FactoryCommitFunc& trans __BooTraceArgs) override; ObjToken newPoolBuffer(BufferUse use, size_t stride, size_t count __BooTraceArgs) override; @@ -1166,7 +1166,7 @@ constexpr std::array SEMANTIC_TYPE_TABLE{ struct GLCommandQueue final : IGraphicsCommandQueue { Platform platform() const override { return IGraphicsDataFactory::Platform::OpenGL; } - const SystemChar* platformName() const override { return _SYS_STR("OpenGL"); } + const char* platformName() const override { return "OpenGL"; } IGraphicsContext* m_parent = nullptr; GLContext* m_glCtx = nullptr; @@ -1357,11 +1357,7 @@ struct GLCommandQueue final : IGraphicsCommandQueue { static void RenderingWorker(GLCommandQueue* self) { BOO_MSAN_NO_INTERCEPT -#if _WIN32 - std::string thrName = WCSTMBS(APP->getFriendlyName().data()) + " Render"; -#else std::string thrName = std::string(APP->getFriendlyName()) + " Render"; -#endif logvisor::RegisterThreadName(thrName.c_str()); GLDataFactoryImpl* dataFactory = static_cast(self->m_parent->getDataFactory()); { @@ -1497,7 +1493,7 @@ struct GLCommandQueue final : IGraphicsCommandQueue { case Command::Op::DrawIndexed: if (cmd.baseVertex > 0) { Log.report(logvisor::Fatal, - FMT_STRING(_SYS_STR("Attempted to render with baseVertex > 0 (currently unsupported in GL)"))); + FMT_STRING("Attempted to render with baseVertex > 0 (currently unsupported in GL)")); } glDrawElements(currentPrim, cmd.count, GL_UNSIGNED_INT, reinterpret_cast(cmd.start * 4)); break; diff --git a/lib/graphicsdev/Vulkan.cpp b/lib/graphicsdev/Vulkan.cpp index a58d68e..9279491 100644 --- a/lib/graphicsdev/Vulkan.cpp +++ b/lib/graphicsdev/Vulkan.cpp @@ -127,7 +127,7 @@ public: ~VulkanDataFactoryImpl() { assert(m_descPoolHead == nullptr && "Dangling descriptor pools detected"); } Platform platform() const { return Platform::Vulkan; } - const SystemChar* platformName() const { return _SYS_STR("Vulkan"); } + const char* platformName() const { return "Vulkan"; } boo::ObjToken allocateDescriptorSets(VkDescriptorSet* out); @@ -2860,7 +2860,7 @@ struct VulkanShaderDataBinding : GraphicsDataNode { struct VulkanCommandQueue final : IGraphicsCommandQueue { Platform platform() const { return IGraphicsDataFactory::Platform::Vulkan; } - const SystemChar* platformName() const { return _SYS_STR("Vulkan"); } + const char* platformName() const { return "Vulkan"; } VulkanContext* m_ctx; VulkanContext::Window* m_windowCtx; IGraphicsContext* m_parent; diff --git a/lib/mac/ApplicationCocoa.mm b/lib/mac/ApplicationCocoa.mm index 477aa68..3a715fd 100644 --- a/lib/mac/ApplicationCocoa.mm +++ b/lib/mac/ApplicationCocoa.mm @@ -30,17 +30,17 @@ namespace boo { class ApplicationCocoa; } namespace boo { static logvisor::Module Log("boo::ApplicationCocoa"); -std::shared_ptr _WindowCocoaNew(SystemStringView title, MetalContext* metalCtx); +std::shared_ptr _WindowCocoaNew(std::string_view title, MetalContext* metalCtx); class ApplicationCocoa : public IApplication { public: IApplicationCallback& m_callback; AppDelegate* m_appDelegate; private: - const SystemString m_uniqueName; - const SystemString m_friendlyName; - const SystemString m_pname; - const std::vector m_args; + const std::string m_uniqueName; + const std::string m_friendlyName; + const std::string m_pname; + const std::vector m_args; NSPanel* aboutPanel; @@ -58,10 +58,10 @@ private: public: ApplicationCocoa(IApplicationCallback& callback, - SystemStringView uniqueName, - SystemStringView friendlyName, - SystemStringView pname, - const std::vector& args, + std::string_view uniqueName, + std::string_view friendlyName, + std::string_view pname, + const std::vector& args, std::string_view gfxApi, uint32_t samples, uint32_t anisotropy, @@ -164,19 +164,19 @@ public: [NSApp terminate:nil]; } - SystemStringView getUniqueName() const override { + std::string_view getUniqueName() const override { return m_uniqueName; } - SystemStringView getFriendlyName() const override { + std::string_view getFriendlyName() const override { return m_friendlyName; } - SystemStringView getProcessName() const override { + std::string_view getProcessName() const override { return m_pname; } - const std::vector& getArgs() const override { + const std::vector& getArgs() const override { return m_args; } @@ -203,10 +203,10 @@ IApplication* APP = nullptr; int ApplicationRun(IApplication::EPlatformType platform, IApplicationCallback& cb, - SystemStringView uniqueName, - SystemStringView friendlyName, - SystemStringView pname, - const std::vector& args, + std::string_view uniqueName, + std::string_view friendlyName, + std::string_view pname, + const std::vector& args, std::string_view gfxApi, uint32_t samples, uint32_t anisotropy, @@ -269,17 +269,17 @@ int ApplicationRun(IApplication::EPlatformType platform, #endif - (BOOL)application:(NSApplication*)sender openFile:(NSString*)filename { - std::vector strVec; - strVec.push_back(boo::SystemString([filename UTF8String])); + std::vector strVec; + strVec.push_back(std::string([filename UTF8String])); m_app->m_callback.appFilesOpen(boo::APP, strVec); return true; } - (void)application:(NSApplication*)sender openFiles:(NSArray*)filenames { - std::vector strVec; + std::vector strVec; strVec.reserve([filenames count]); for (NSString* str in filenames) - strVec.push_back(boo::SystemString([str UTF8String])); + strVec.push_back(std::string([str UTF8String])); m_app->m_callback.appFilesOpen(boo::APP, strVec); } diff --git a/lib/mac/WindowCocoa.mm b/lib/mac/WindowCocoa.mm index 2223d8a..da64df1 100644 --- a/lib/mac/WindowCocoa.mm +++ b/lib/mac/WindowCocoa.mm @@ -1524,7 +1524,7 @@ public: }; -std::shared_ptr _WindowCocoaNew(SystemStringView title, MetalContext* metalCtx) { +std::shared_ptr _WindowCocoaNew(std::string_view title, MetalContext* metalCtx) { auto ret = std::make_shared(); ret->setup(title, metalCtx); return ret; diff --git a/lib/win/ApplicationUWP.cpp b/lib/win/ApplicationUWP.cpp index e43950c..87d7733 100644 --- a/lib/win/ApplicationUWP.cpp +++ b/lib/win/ApplicationUWP.cpp @@ -37,15 +37,15 @@ static bool FindBestD3DCompile() { namespace boo { static logvisor::Module Log("boo::ApplicationUWP"); -std::shared_ptr _WindowUWPNew(SystemStringView title, Boo3DAppContextUWP& d3dCtx); +std::shared_ptr _WindowUWPNew(std::string_view title, Boo3DAppContextUWP& d3dCtx); class ApplicationUWP final : public IApplication { friend ref class AppView; IApplicationCallback& m_callback; - const SystemString m_uniqueName; - const SystemString m_friendlyName; - const SystemString m_pname; - const std::vector m_args; + const std::string m_uniqueName; + const std::string m_friendlyName; + const std::string m_pname; + const std::vector m_args; std::shared_ptr m_window; bool m_singleInstance; bool m_issuedWindow = false; @@ -55,8 +55,8 @@ class ApplicationUWP final : public IApplication { void _deletedWindow(IWindow* window) override {} public: - ApplicationUWP(IApplicationCallback& callback, SystemStringView uniqueName, SystemStringView friendlyName, - SystemStringView pname, const std::vector& args, bool singleInstance) + ApplicationUWP(IApplicationCallback& callback, std::string_view uniqueName, std::string_view friendlyName, + std::string_view pname, const std::vector& args, bool singleInstance) : m_callback(callback) , m_uniqueName(uniqueName) , m_friendlyName(friendlyName) @@ -67,7 +67,7 @@ public: CreateDXGIFactory1PROC MyCreateDXGIFactory1 = CreateDXGIFactory1; bool no12 = true; - for (const SystemString& arg : args) + for (const std::string& arg : args) if (!arg.compare(L"--d3d12")) no12 = false; @@ -190,7 +190,7 @@ public: /* Spawn client thread */ int clientReturn = 0; m_clientThread = std::thread([&]() { - std::string thrName = WCSTMBS(getFriendlyName().data()) + " Client Thread"; + std::string thrName = std::string(getFriendlyName()) + " Client Thread"; logvisor::RegisterThreadName(thrName.c_str()); clientReturn = m_callback.appMain(this); }); @@ -206,15 +206,15 @@ public: m_clientThread.join(); } - SystemStringView getUniqueName() const override { return m_uniqueName; } + std::string_view getUniqueName() const override { return m_uniqueName; } - SystemStringView getFriendlyName() const override { return m_friendlyName; } + std::string_view getFriendlyName() const override { return m_friendlyName; } - SystemStringView getProcessName() const override { return m_pname; } + std::string_view getProcessName() const override { return m_pname; } - const std::vector& getArgs() const override { return m_args; } + const std::vector& getArgs() const override { return m_args; } - std::shared_ptr newWindow(SystemStringView title, uint32_t sampleCount) override { + std::shared_ptr newWindow(std::string_view title, uint32_t sampleCount) override { if (!m_issuedWindow) { m_issuedWindow = true; return m_window; @@ -229,8 +229,8 @@ IApplication* APP = nullptr; ref class AppView sealed : public IFrameworkView { ApplicationUWP m_app; - internal : AppView(IApplicationCallback& callback, SystemStringView uniqueName, SystemStringView friendlyName, - SystemStringView pname, const std::vector& args, bool singleInstance) + internal : AppView(IApplicationCallback& callback, std::string_view uniqueName, std::string_view friendlyName, + std::string_view pname, const std::vector& args, bool singleInstance) : m_app(callback, uniqueName, friendlyName, pname, args, singleInstance) { APP = &m_app; } diff --git a/lib/win/ApplicationWin32.cpp b/lib/win/ApplicationWin32.cpp index d74e839..11b5a00 100644 --- a/lib/win/ApplicationWin32.cpp +++ b/lib/win/ApplicationWin32.cpp @@ -77,14 +77,14 @@ namespace boo { static logvisor::Module Log("boo::ApplicationWin32"); Win32Cursors WIN32_CURSORS; -std::shared_ptr _WindowWin32New(SystemStringView title, Boo3DAppContextWin32& d3dCtx); +std::shared_ptr _WindowWin32New(std::string_view title, Boo3DAppContextWin32& d3dCtx); class ApplicationWin32 final : public IApplication { IApplicationCallback& m_callback; - const SystemString m_uniqueName; - const SystemString m_friendlyName; - const SystemString m_pname; - const std::vector m_args; + const std::string m_uniqueName; + const std::string m_friendlyName; + const std::string m_pname; + const std::vector m_args; std::unordered_map> m_allWindows; Boo3DAppContextWin32 m_3dCtx; @@ -95,8 +95,8 @@ class ApplicationWin32 final : public IApplication { void _deletedWindow(IWindow* window) override { m_allWindows.erase(HWND(window->getPlatformHandle())); } public: - ApplicationWin32(IApplicationCallback& callback, SystemStringView uniqueName, SystemStringView friendlyName, - SystemStringView pname, const std::vector& args, std::string_view gfxApi, + ApplicationWin32(IApplicationCallback& callback, std::string_view uniqueName, std::string_view friendlyName, + std::string_view pname, const std::vector& args, std::string_view gfxApi, uint32_t samples, uint32_t anisotropy, bool deepColor, bool singleInstance) : m_callback(callback), m_uniqueName(uniqueName), m_friendlyName(friendlyName), m_pname(pname), m_args(args) { m_3dCtx.m_ctx11.m_sampleCount = samples; @@ -142,17 +142,17 @@ public: noD3d = true; #endif } - for (const SystemString& arg : args) { + for (const std::string& arg : args) { #if BOO_HAS_VULKAN - if (!arg.compare(L"--d3d11")) { + if (!arg.compare("--d3d11")) { useVulkan = false; noD3d = false; } - if (!arg.compare(L"--vulkan")) { + if (!arg.compare("--vulkan")) { noD3d = true; useVulkan = true; } - if (!arg.compare(L"--gl")) { + if (!arg.compare("--gl")) { noD3d = true; useVulkan = false; } @@ -173,7 +173,7 @@ public: /* Check device support for vulkan */ if (g_VulkanContext.m_instance == VK_NULL_HANDLE) { auto appName = getUniqueName(); - if (g_VulkanContext.initVulkan(WCSTMBS(appName.data()).c_str(), m_getVkProc)) { + if (g_VulkanContext.initVulkan(appName.data(), m_getVkProc)) { if (g_VulkanContext.enumerateDevices()) { /* Obtain DXGI Factory */ HRESULT hr = MyCreateDXGIFactory1(__uuidof(IDXGIFactory1), &m_3dCtx.m_vulkanDxFactory); @@ -375,7 +375,7 @@ public: /* Spawn client thread */ int clientReturn = 0; std::thread clientThread([&]() { - std::string thrName = WCSTMBS(getFriendlyName().data()) + " Client Thread"; + std::string thrName = std::string(getFriendlyName()) + " Client Thread"; logvisor::RegisterThreadName(thrName.c_str()); CoInitializeEx(nullptr, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE); clientReturn = m_callback.appMain(this); @@ -391,7 +391,7 @@ public: case WM_USER: { /* New-window message (coalesced onto main thread) */ std::lock_guard lk(g_nwmt); - SystemStringView* title = reinterpret_cast(msg.wParam); + std::string_view* title = reinterpret_cast(msg.wParam); m_mwret = newWindow(*title); g_nwcv.notify_one(); continue; @@ -441,16 +441,16 @@ public: w->_cleanup(); } - SystemStringView getUniqueName() const override { return m_uniqueName; } + std::string_view getUniqueName() const override { return m_uniqueName; } - SystemStringView getFriendlyName() const override { return m_friendlyName; } + std::string_view getFriendlyName() const override { return m_friendlyName; } - SystemStringView getProcessName() const override { return m_pname; } + std::string_view getProcessName() const override { return m_pname; } - const std::vector& getArgs() const override { return m_args; } + const std::vector& getArgs() const override { return m_args; } std::shared_ptr m_mwret; - std::shared_ptr newWindow(SystemStringView title) override { + std::shared_ptr newWindow(std::string_view title) override { if (GetCurrentThreadId() != g_mainThreadId) { std::unique_lock lk(g_nwmt); if (!PostThreadMessageW(g_mainThreadId, WM_USER, WPARAM(&title), 0)) @@ -469,11 +469,11 @@ public: }; IApplication* APP = nullptr; -int ApplicationRun(IApplication::EPlatformType platform, IApplicationCallback& cb, SystemStringView uniqueName, - SystemStringView friendlyName, SystemStringView pname, const std::vector& args, +int ApplicationRun(IApplication::EPlatformType platform, IApplicationCallback& cb, std::string_view uniqueName, + std::string_view friendlyName, std::string_view pname, const std::vector& args, std::string_view gfxApi, uint32_t samples, uint32_t anisotropy, bool deepColor, bool singleInstance) { - std::string thrName = WCSTMBS(friendlyName.data()) + " Main Thread"; + std::string thrName = std::string(friendlyName) + " Main Thread"; logvisor::RegisterThreadName(thrName.c_str()); if (APP) return 1; diff --git a/lib/win/WinCommon.hpp b/lib/win/WinCommon.hpp index 41c5f53..3f4a153 100644 --- a/lib/win/WinCommon.hpp +++ b/lib/win/WinCommon.hpp @@ -9,7 +9,7 @@ namespace boo { class IWindow; -} +} // namespace boo #if _WIN32_WINNT_WIN10 #include @@ -115,17 +115,3 @@ struct Boo3DAppContext { win.m_needsResize = true; } }; - -inline std::string WCSTMBS(const wchar_t* wstr) { - int sizeNeeded = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, nullptr, 0, nullptr, nullptr) - 1; - std::string strTo(sizeNeeded, 0); - WideCharToMultiByte(CP_UTF8, 0, wstr, -1, &strTo[0], sizeNeeded, nullptr, nullptr); - return strTo; -} - -inline std::wstring MBSTWCS(const char* str) { - int sizeNeeded = MultiByteToWideChar(CP_UTF8, 0, str, -1, nullptr, 0) - 1; - std::wstring strTo(sizeNeeded, 0); - MultiByteToWideChar(CP_UTF8, 0, str, -1, &strTo[0], sizeNeeded); - return strTo; -} diff --git a/lib/win/WindowUWP.cpp b/lib/win/WindowUWP.cpp index ba7fc77..ee6ad58 100644 --- a/lib/win/WindowUWP.cpp +++ b/lib/win/WindowUWP.cpp @@ -279,7 +279,7 @@ public: }; EventReceiver ^ m_eventReceiver; - WindowUWP(SystemStringView title, Boo3DAppContextUWP& b3dCtx) + WindowUWP(std::string_view title, Boo3DAppContextUWP& b3dCtx) : m_coreWindow(CoreWindow::GetForCurrentThread()), m_eventReceiver(ref new EventReceiver(*this)) { IGraphicsContext::EGraphicsAPI api = IGraphicsContext::EGraphicsAPI::D3D11; #if _WIN32_WINNT_WIN10 @@ -317,9 +317,9 @@ public: void hideWindow() override {} - SystemString getTitle() override { return SystemString(m_appView->Title->Data()); } + std::string getTitle() override { return std::string(m_appView->Title->Data()); } - void setTitle(SystemStringView title) override { m_appView->Title = ref new Platform::String(title.data()); } + void setTitle(std::string_view title) override { m_appView->Title = ref new Platform::String(title.data()); } void setCursor(EMouseCursor cursor) override {} @@ -493,7 +493,7 @@ public: IGraphicsDataFactory* getLoadContextDataFactory() override { return m_gfxCtx->getLoadContextDataFactory(); } }; -std::shared_ptr _WindowUWPNew(SystemStringView title, Boo3DAppContextUWP& d3dCtx) { +std::shared_ptr _WindowUWPNew(std::string_view title, Boo3DAppContextUWP& d3dCtx) { return std::make_shared(title, d3dCtx); } diff --git a/lib/win/WindowWin32.cpp b/lib/win/WindowWin32.cpp index df77cb6..1d3ee00 100644 --- a/lib/win/WindowWin32.cpp +++ b/lib/win/WindowWin32.cpp @@ -24,6 +24,7 @@ #endif #include +#include static const int ContextAttribs[] = {WGL_CONTEXT_MAJOR_VERSION_ARB, 3, WGL_CONTEXT_MINOR_VERSION_ARB, 3, WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, @@ -863,7 +864,7 @@ class WindowWin32 : public IWindow { } public: - WindowWin32(SystemStringView title, Boo3DAppContextWin32& b3dCtx) { + WindowWin32(std::string_view title, Boo3DAppContextWin32& b3dCtx) { const POINT ptZero = {0, 0}; HMONITOR monitor = MonitorFromPoint(ptZero, MONITOR_DEFAULTTOPRIMARY); MONITORINFO monInfo = {}; @@ -874,7 +875,8 @@ public: RECT r = {x, y, x + w, y + h}; AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW, FALSE); - m_hwnd = CreateWindowW(L"BooWindow", title.data(), WS_OVERLAPPEDWINDOW, r.left, r.top, r.right - r.left, + const nowide::wstackstring wtitle(title); + m_hwnd = CreateWindowW(L"BooWindow", wtitle.get(), WS_OVERLAPPEDWINDOW, r.left, r.top, r.right - r.left, r.bottom - r.top, nullptr, nullptr, nullptr, nullptr); m_imc = ImmGetContext(m_hwnd); @@ -890,12 +892,12 @@ public: IGraphicsContext::EGraphicsAPI api = IGraphicsContext::EGraphicsAPI::D3D11; #if BOO_HAS_GL if (b3dCtx.m_ctxOgl.m_dxFactory) { - m_gfxCtx.reset(new GraphicsContextWin32GL(IGraphicsContext::EGraphicsAPI::OpenGL3_3, this, m_hwnd, b3dCtx)); + m_gfxCtx = std::make_unique(IGraphicsContext::EGraphicsAPI::OpenGL3_3, this, m_hwnd, b3dCtx); m_openGL = true; return; } #endif - m_gfxCtx.reset(new GraphicsContextWin32D3D(api, this, m_hwnd, b3dCtx)); + m_gfxCtx = std::make_unique(api, this, m_hwnd, b3dCtx); } void _cleanup() override { m_gfxCtx.reset(); } @@ -911,13 +913,16 @@ public: void hideWindow() override { ShowWindow(m_hwnd, SW_HIDE); } - SystemString getTitle() override { + std::string getTitle() override { wchar_t title[256]; int c = GetWindowTextW(m_hwnd, title, 256); - return SystemString(title, c); + return nowide::narrow(title, c); } - void setTitle(SystemStringView title) override { SetWindowTextW(m_hwnd, title.data()); } + void setTitle(std::string_view title) override { + const nowide::wstackstring wtitle(title); + SetWindowTextW(m_hwnd, wtitle.get()); + } static void _setCursor(HCURSOR cur) { PostThreadMessageW(g_mainThreadId, WM_USER + 2, WPARAM(cur), 0); } @@ -989,13 +994,14 @@ public: float getVirtualPixelFactor() const override { #if _WIN32_WINNT_WINBLUE - if (MyGetScaleFactorForMonitor) { - DEVICE_SCALE_FACTOR Factor; + if (MyGetScaleFactorForMonitor != nullptr) { + DEVICE_SCALE_FACTOR Factor = DEVICE_SCALE_FACTOR_INVALID; HMONITOR mon = MonitorFromWindow(m_hwnd, MONITOR_DEFAULTTOPRIMARY); MyGetScaleFactorForMonitor(mon, &Factor); - if (Factor == 0) + if (Factor == 0) { return 1.f; - return Factor / 100.f; + } + return static_cast(Factor) / 100.f; } #endif return 1.f; @@ -1368,7 +1374,7 @@ public: IGraphicsDataFactory* getLoadContextDataFactory() override { return m_gfxCtx->getLoadContextDataFactory(); } }; -std::shared_ptr _WindowWin32New(SystemStringView title, Boo3DAppContextWin32& d3dCtx) { +std::shared_ptr _WindowWin32New(std::string_view title, Boo3DAppContextWin32& d3dCtx) { return std::make_shared(title, d3dCtx); } diff --git a/logvisor b/logvisor index 274ad5e..139281f 160000 --- a/logvisor +++ b/logvisor @@ -1 +1 @@ -Subproject commit 274ad5ef07e0d658ee5281f11cc19bf168f7d4c6 +Subproject commit 139281f6677bc3e08e39ebcc8b84a894cbc5fb6e diff --git a/test/main.cpp b/test/main.cpp index 23eafdc..03f8b81 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -391,7 +391,7 @@ struct TestApplicationCallback : IApplicationCallback { } int appMain(IApplication* app) override { - mainWindow = app->newWindow(_SYS_STR("YAY!")); + mainWindow = app->newWindow("YAY!"); mainWindow->setCallback(&windowCallback); mainWindow->showWindow(); windowCallback.m_lastRect = mainWindow->getWindowFrame(); @@ -457,14 +457,10 @@ struct TestApplicationCallback : IApplicationCallback { return 0; } void appQuitting(IApplication*) override { running = false; } - void appFilesOpen(IApplication*, const std::vector& paths) override { + void appFilesOpen(IApplication*, const std::vector& paths) override { fprintf(stderr, "OPENING: "); - for (const SystemString& path : paths) { -#if _WIN32 - fwprintf(stderr, L"%s ", path.c_str()); -#else + for (const std::string& path : paths) { fprintf(stderr, "%s ", path.c_str()); -#endif } fprintf(stderr, "\n"); } @@ -473,18 +469,12 @@ struct TestApplicationCallback : IApplicationCallback { } // namespace boo #if !WINDOWS_STORE -#if _WIN32 -int wmain(int argc, const boo::SystemChar** argv) -#else -int main(int argc, const boo::SystemChar** argv) -#endif -{ +int main(int argc, char** argv) { logvisor::RegisterStandardExceptions(); logvisor::RegisterConsoleLogger(); boo::TestApplicationCallback appCb; - int ret = ApplicationRun(boo::IApplication::EPlatformType::Auto, appCb, _SYS_STR("boo"), _SYS_STR("boo"), argc, argv, + int ret = ApplicationRun(boo::IApplication::EPlatformType::Auto, appCb, "boo", "boo", argc, argv, {}, 1, 1, true); - printf("IM DYING!!\n"); return ret; } @@ -496,26 +486,20 @@ using namespace Windows::ApplicationModel::Core; logvisor::RegisterConsoleLogger(); boo::TestApplicationCallback appCb; boo::ViewProvider ^ viewProvider = - ref new boo::ViewProvider(appCb, _SYS_STR("boo"), _SYS_STR("boo"), _SYS_STR("boo"), params, false); + ref new boo::ViewProvider(appCb, "boo", "boo", "boo", params, false); CoreApplication::Run(viewProvider); return 0; } #endif #if _WIN32 && !WINDOWS_STORE -int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR lpCmdLine, int) { - int argc = 0; - const boo::SystemChar** argv; - if (lpCmdLine[0]) - argv = (const wchar_t**)(CommandLineToArgvW(lpCmdLine, &argc)); - static boo::SystemChar selfPath[1024]; - GetModuleFileNameW(nullptr, selfPath, 1024); - static const boo::SystemChar* booArgv[32] = {}; - booArgv[0] = selfPath; - for (int i = 0; i < argc; ++i) - booArgv[i + 1] = argv[i]; +#include +int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpCmdLine, int) { + int argc = 0; + char** argv = nullptr; + nowide::args _(argc, argv); logvisor::CreateWin32Console(); - return wmain(argc + 1, booArgv); + return main(argc, argv); } #endif