From 0748e524e68f5555966be7191a1c40f2c455eeef Mon Sep 17 00:00:00 2001 From: Turanszki Janos Date: Sat, 14 Dec 2019 16:22:35 +0000 Subject: [PATCH] removed explicit CleanUp() from systems, automatic cleanup everywhere --- Documentation/ScriptingAPI-Documentation.md | 1 - WickedEngine/MainComponent.cpp | 8 - WickedEngine/MainComponent.h | 2 - WickedEngine/wiAudio.cpp | 279 +++++++++++--------- WickedEngine/wiAudio.h | 1 - WickedEngine/wiFont.cpp | 22 +- WickedEngine/wiFont.h | 1 - WickedEngine/wiFont_BindLua.cpp | 12 - WickedEngine/wiFont_BindLua.h | 3 - WickedEngine/wiGPUSortLib.cpp | 4 - WickedEngine/wiInitializer.cpp | 8 - WickedEngine/wiInitializer.h | 2 - WickedEngine/wiNetwork.h | 1 - WickedEngine/wiNetwork_UWP.cpp | 3 - WickedEngine/wiNetwork_Windows.cpp | 4 - WickedEngine/wiPhysicsEngine.h | 1 - WickedEngine/wiPhysicsEngine_Bullet.cpp | 39 ++- WickedEngine/wiVersion.cpp | 2 +- 18 files changed, 174 insertions(+), 219 deletions(-) diff --git a/Documentation/ScriptingAPI-Documentation.md b/Documentation/ScriptingAPI-Documentation.md index 4f9038f04..eaefacbc4 100644 --- a/Documentation/ScriptingAPI-Documentation.md +++ b/Documentation/ScriptingAPI-Documentation.md @@ -158,7 +158,6 @@ Gives you the ability to render text with a custom font. - GetAlign() : WIFALIGN halign,valign - GetColor() : Vector result - GetShadowColor() : Vector result -- Destroy() ### Sprite Render images on the screen. diff --git a/WickedEngine/MainComponent.cpp b/WickedEngine/MainComponent.cpp index 4b3b93dfe..a6827e52f 100644 --- a/WickedEngine/MainComponent.cpp +++ b/WickedEngine/MainComponent.cpp @@ -25,14 +25,6 @@ using namespace std; using namespace wiGraphics; -MainComponent::~MainComponent() -{ - // This means application is terminating. Wait for GPU to finish rendering. - wiRenderer::GetDevice()->WaitForGPU(); - - wiInitializer::CleanUp(); -} - void MainComponent::Initialize() { if (initialized) diff --git a/WickedEngine/MainComponent.h b/WickedEngine/MainComponent.h index 5b73e5d7b..182f9743f 100644 --- a/WickedEngine/MainComponent.h +++ b/WickedEngine/MainComponent.h @@ -22,8 +22,6 @@ protected: float deltaTimeAccumulator = 0; wiTimer timer; public: - virtual ~MainComponent(); - bool fullscreen = false; // Runs the main engine loop diff --git a/WickedEngine/wiAudio.cpp b/WickedEngine/wiAudio.cpp index 5189030b2..eff4bb12e 100644 --- a/WickedEngine/wiAudio.cpp +++ b/WickedEngine/wiAudio.cpp @@ -3,6 +3,7 @@ #include "wiHelper.h" #include +#include #include #include @@ -29,13 +30,132 @@ namespace wiAudio { - IXAudio2* audioEngine = nullptr; - IXAudio2MasteringVoice* masteringVoice = nullptr; - XAUDIO2_VOICE_DETAILS masteringVoiceDetails = {}; - IXAudio2SubmixVoice* submixVoices[SUBMIX_TYPE_COUNT] = {}; - X3DAUDIO_HANDLE audio3D = {}; - IUnknown* reverbEffect = nullptr; - IXAudio2SubmixVoice* reverbSubmix = nullptr; + static const XAUDIO2FX_REVERB_I3DL2_PARAMETERS reverbPresets[] = + { + XAUDIO2FX_I3DL2_PRESET_DEFAULT, + XAUDIO2FX_I3DL2_PRESET_GENERIC, + XAUDIO2FX_I3DL2_PRESET_FOREST, + XAUDIO2FX_I3DL2_PRESET_PADDEDCELL, + XAUDIO2FX_I3DL2_PRESET_ROOM, + XAUDIO2FX_I3DL2_PRESET_BATHROOM, + XAUDIO2FX_I3DL2_PRESET_LIVINGROOM, + XAUDIO2FX_I3DL2_PRESET_STONEROOM, + XAUDIO2FX_I3DL2_PRESET_AUDITORIUM, + XAUDIO2FX_I3DL2_PRESET_CONCERTHALL, + XAUDIO2FX_I3DL2_PRESET_CAVE, + XAUDIO2FX_I3DL2_PRESET_ARENA, + XAUDIO2FX_I3DL2_PRESET_HANGAR, + XAUDIO2FX_I3DL2_PRESET_CARPETEDHALLWAY, + XAUDIO2FX_I3DL2_PRESET_HALLWAY, + XAUDIO2FX_I3DL2_PRESET_STONECORRIDOR, + XAUDIO2FX_I3DL2_PRESET_ALLEY, + XAUDIO2FX_I3DL2_PRESET_CITY, + XAUDIO2FX_I3DL2_PRESET_MOUNTAINS, + XAUDIO2FX_I3DL2_PRESET_QUARRY, + XAUDIO2FX_I3DL2_PRESET_PLAIN, + XAUDIO2FX_I3DL2_PRESET_PARKINGLOT, + XAUDIO2FX_I3DL2_PRESET_SEWERPIPE, + XAUDIO2FX_I3DL2_PRESET_UNDERWATER, + XAUDIO2FX_I3DL2_PRESET_SMALLROOM, + XAUDIO2FX_I3DL2_PRESET_MEDIUMROOM, + XAUDIO2FX_I3DL2_PRESET_LARGEROOM, + XAUDIO2FX_I3DL2_PRESET_MEDIUMHALL, + XAUDIO2FX_I3DL2_PRESET_LARGEHALL, + XAUDIO2FX_I3DL2_PRESET_PLATE, + }; + + struct AudioInternal + { + bool success = false; + IXAudio2* audioEngine = nullptr; + IXAudio2MasteringVoice* masteringVoice = nullptr; + XAUDIO2_VOICE_DETAILS masteringVoiceDetails = {}; + IXAudio2SubmixVoice* submixVoices[SUBMIX_TYPE_COUNT] = {}; + X3DAUDIO_HANDLE audio3D = {}; + IUnknown* reverbEffect = nullptr; + IXAudio2SubmixVoice* reverbSubmix = nullptr; + + AudioInternal() + { + HRESULT hr; + hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); + assert(SUCCEEDED(hr)); + + hr = XAudio2Create(&audioEngine, 0, XAUDIO2_DEFAULT_PROCESSOR); + assert(SUCCEEDED(hr)); + +#ifdef _DEBUG + XAUDIO2_DEBUG_CONFIGURATION debugConfig = {}; + debugConfig.TraceMask = XAUDIO2_LOG_ERRORS | XAUDIO2_LOG_WARNINGS; + debugConfig.BreakMask = XAUDIO2_LOG_ERRORS | XAUDIO2_LOG_WARNINGS; + audioEngine->SetDebugConfiguration(&debugConfig); +#endif // _DEBUG + + hr = audioEngine->CreateMasteringVoice(&masteringVoice); + assert(SUCCEEDED(hr)); + + masteringVoice->GetVoiceDetails(&masteringVoiceDetails); + + for (int i = 0; i < SUBMIX_TYPE_COUNT; ++i) + { + hr = audioEngine->CreateSubmixVoice( + &submixVoices[i], + masteringVoiceDetails.InputChannels, + masteringVoiceDetails.InputSampleRate, + 0, 0, 0, 0); + assert(SUCCEEDED(hr)); + } + + DWORD channelMask; + masteringVoice->GetChannelMask(&channelMask); + hr = X3DAudioInitialize(channelMask, X3DAUDIO_SPEED_OF_SOUND, audio3D); + assert(SUCCEEDED(hr)); + + // Reverb setup: + { + hr = XAudio2CreateReverb(&reverbEffect); + assert(SUCCEEDED(hr)); + + XAUDIO2_EFFECT_DESCRIPTOR effects[] = { { reverbEffect, TRUE, 1 } }; + XAUDIO2_EFFECT_CHAIN effectChain = { arraysize(effects), effects }; + hr = audioEngine->CreateSubmixVoice( + &reverbSubmix, + 1, // reverb is mono + masteringVoiceDetails.InputSampleRate, + 0, 0, nullptr, &effectChain); + assert(SUCCEEDED(hr)); + + XAUDIO2FX_REVERB_PARAMETERS native; + ReverbConvertI3DL2ToNative(&reverbPresets[REVERB_PRESET_DEFAULT], &native); + HRESULT hr = reverbSubmix->SetEffectParameters(0, &native, sizeof(native)); + assert(SUCCEEDED(hr)); + } + + success = SUCCEEDED(hr); + } + ~AudioInternal() + { + SAFE_RELEASE(reverbEffect); + + if (reverbSubmix != nullptr) + reverbSubmix->DestroyVoice(); + + for (int i = 0; i < SUBMIX_TYPE_COUNT; ++i) + { + if (submixVoices[i] != nullptr) + submixVoices[i]->DestroyVoice(); + } + + if (masteringVoice != nullptr) + masteringVoice->DestroyVoice(); + + audioEngine->StopEngine(); + SAFE_RELEASE(audioEngine); + + CoUninitialize(); + } + }; + std::shared_ptr audio; Sound::~Sound() { @@ -47,11 +167,13 @@ namespace wiAudio } struct SoundInternal { + std::shared_ptr audio; WAVEFORMATEX wfx = {}; std::vector audioData; }; struct SoundInstanceInternal { + std::shared_ptr audio; IXAudio2SourceVoice* sourceVoice = nullptr; XAUDIO2_VOICE_DETAILS voiceDetails = {}; std::vector outputMatrix; @@ -62,83 +184,13 @@ namespace wiAudio void Initialize() { - HRESULT hr; - hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); - assert(SUCCEEDED(hr)); + audio = std::make_shared(); - hr = XAudio2Create(&audioEngine, 0, XAUDIO2_DEFAULT_PROCESSOR); - assert(SUCCEEDED(hr)); - -#ifdef _DEBUG - XAUDIO2_DEBUG_CONFIGURATION debugConfig = {}; - debugConfig.TraceMask = XAUDIO2_LOG_ERRORS | XAUDIO2_LOG_WARNINGS; - debugConfig.BreakMask = XAUDIO2_LOG_ERRORS | XAUDIO2_LOG_WARNINGS; - audioEngine->SetDebugConfiguration(&debugConfig); -#endif // _DEBUG - - hr = audioEngine->CreateMasteringVoice(&masteringVoice); - assert(SUCCEEDED(hr)); - - masteringVoice->GetVoiceDetails(&masteringVoiceDetails); - - for (int i = 0; i < SUBMIX_TYPE_COUNT; ++i) - { - hr = audioEngine->CreateSubmixVoice( - &submixVoices[i], - masteringVoiceDetails.InputChannels, - masteringVoiceDetails.InputSampleRate, - 0, 0, 0, 0); - assert(SUCCEEDED(hr)); - } - - DWORD channelMask; - masteringVoice->GetChannelMask(&channelMask); - hr = X3DAudioInitialize(channelMask, X3DAUDIO_SPEED_OF_SOUND, audio3D); - assert(SUCCEEDED(hr)); - - // Reverb setup: - { - hr = XAudio2CreateReverb(&reverbEffect); - assert(SUCCEEDED(hr)); - - XAUDIO2_EFFECT_DESCRIPTOR effects[] = { { reverbEffect, TRUE, 1 } }; - XAUDIO2_EFFECT_CHAIN effectChain = { arraysize(effects), effects }; - hr = audioEngine->CreateSubmixVoice( - &reverbSubmix, - 1, // reverb is mono - masteringVoiceDetails.InputSampleRate, - 0, 0, nullptr, &effectChain); - assert(SUCCEEDED(hr)); - - SetReverb(REVERB_PRESET_DEFAULT); - } - - if (SUCCEEDED(hr)) + if (audio->success) { wiBackLog::post("wiAudio Initialized"); } } - void CleanUp() - { - SAFE_RELEASE(reverbEffect); - - if (reverbSubmix != nullptr) - reverbSubmix->DestroyVoice(); - - for (int i = 0; i < SUBMIX_TYPE_COUNT; ++i) - { - if (submixVoices[i] != nullptr) - submixVoices[i]->DestroyVoice(); - } - - if (masteringVoice != nullptr) - masteringVoice->DestroyVoice(); - - audioEngine->StopEngine(); - SAFE_RELEASE(audioEngine); - - CoUninitialize(); - } HRESULT FindChunk(HANDLE hFile, DWORD fourcc, DWORD& dwChunkSize, DWORD& dwChunkDataPosition) { @@ -248,6 +300,7 @@ namespace wiAudio assert(filetype == fourccWAVE); SoundInternal* soundinternal = new SoundInternal; + soundinternal->audio = audio; hr = FindChunk(hFile, fourccFMT, dwChunkSize, dwChunkPosition); assert(SUCCEEDED(hr)); @@ -273,15 +326,16 @@ namespace wiAudio HRESULT hr; const SoundInternal* soundinternal = (const SoundInternal*)sound->handle; SoundInstanceInternal* instanceinternal = new SoundInstanceInternal; + instanceinternal->audio = audio; instanceinternal->soundinternal = soundinternal; XAUDIO2_SEND_DESCRIPTOR SFXSend[] = { - { XAUDIO2_SEND_USEFILTER, submixVoices[instance->type] }, - { XAUDIO2_SEND_USEFILTER, reverbSubmix }, + { XAUDIO2_SEND_USEFILTER, audio->submixVoices[instance->type] }, + { XAUDIO2_SEND_USEFILTER, audio->reverbSubmix }, }; XAUDIO2_VOICE_SENDS SFXSendList = { arraysize(SFXSend), SFXSend }; - hr = audioEngine->CreateSourceVoice(&instanceinternal->sourceVoice, &soundinternal->wfx, + hr = audio->audioEngine->CreateSourceVoice(&instanceinternal->sourceVoice, &soundinternal->wfx, 0, XAUDIO2_DEFAULT_FREQ_RATIO, NULL, &SFXSendList, NULL); if (FAILED(hr)) { @@ -291,7 +345,7 @@ namespace wiAudio instanceinternal->sourceVoice->GetVoiceDetails(&instanceinternal->voiceDetails); - instanceinternal->outputMatrix.resize(size_t(instanceinternal->voiceDetails.InputChannels) * size_t(masteringVoiceDetails.InputChannels)); + instanceinternal->outputMatrix.resize(size_t(instanceinternal->voiceDetails.InputChannels) * size_t(audio->masteringVoiceDetails.InputChannels)); instanceinternal->channelAzimuths.resize(instanceinternal->voiceDetails.InputChannels); for (size_t i = 0; i < instanceinternal->channelAzimuths.size(); ++i) { @@ -302,8 +356,8 @@ namespace wiAudio instanceinternal->buffer.pAudioData = soundinternal->audioData.data(); instanceinternal->buffer.Flags = XAUDIO2_END_OF_STREAM; instanceinternal->buffer.LoopCount = XAUDIO2_LOOP_INFINITE; - instanceinternal->buffer.LoopBegin = UINT32(instance->loop_begin * masteringVoiceDetails.InputSampleRate); - instanceinternal->buffer.LoopLength = UINT32(instance->loop_length * masteringVoiceDetails.InputSampleRate); + instanceinternal->buffer.LoopBegin = UINT32(instance->loop_begin * audio->masteringVoiceDetails.InputSampleRate); + instanceinternal->buffer.LoopLength = UINT32(instance->loop_length * audio->masteringVoiceDetails.InputSampleRate); hr = instanceinternal->sourceVoice->SubmitSourceBuffer(&instanceinternal->buffer); if (FAILED(hr)) @@ -371,7 +425,7 @@ namespace wiAudio { if (instance == nullptr || instance->handle == WI_NULL_HANDLE) { - HRESULT hr = masteringVoice->SetVolume(volume); + HRESULT hr = audio->masteringVoice->SetVolume(volume); assert(SUCCEEDED(hr)); } else @@ -386,7 +440,7 @@ namespace wiAudio float volume = 0; if (instance == nullptr || instance->handle == WI_NULL_HANDLE) { - masteringVoice->GetVolume(&volume); + audio->masteringVoice->GetVolume(&volume); } else { @@ -407,13 +461,13 @@ namespace wiAudio void SetSubmixVolume(SUBMIX_TYPE type, float volume) { - HRESULT hr = submixVoices[type]->SetVolume(volume); + HRESULT hr = audio->submixVoices[type]->SetVolume(volume); assert(SUCCEEDED(hr)); } float GetSubmixVolume(SUBMIX_TYPE type) { float volume; - submixVoices[type]->GetVolume(&volume); + audio->submixVoices[type]->GetVolume(&volume); return volume; } @@ -455,10 +509,10 @@ namespace wiAudio X3DAUDIO_DSP_SETTINGS settings = {}; settings.SrcChannelCount = instanceinternal->voiceDetails.InputChannels; - settings.DstChannelCount = masteringVoiceDetails.InputChannels; + settings.DstChannelCount = audio->masteringVoiceDetails.InputChannels; settings.pMatrixCoefficients = instanceinternal->outputMatrix.data(); - X3DAudioCalculate(audio3D, &listener, &emitter, flags, &settings); + X3DAudioCalculate(audio->audio3D, &listener, &emitter, flags, &settings); HRESULT hr; @@ -466,63 +520,30 @@ namespace wiAudio assert(SUCCEEDED(hr)); hr = instanceinternal->sourceVoice->SetOutputMatrix( - submixVoices[instance->type], + audio->submixVoices[instance->type], settings.SrcChannelCount, settings.DstChannelCount, settings.pMatrixCoefficients ); assert(SUCCEEDED(hr)); - hr = instanceinternal->sourceVoice->SetOutputMatrix(reverbSubmix, settings.SrcChannelCount, 1, &settings.ReverbLevel); + hr = instanceinternal->sourceVoice->SetOutputMatrix(audio->reverbSubmix, settings.SrcChannelCount, 1, &settings.ReverbLevel); assert(SUCCEEDED(hr)); XAUDIO2_FILTER_PARAMETERS FilterParametersDirect = { LowPassFilter, 2.0f * sinf(X3DAUDIO_PI / 6.0f * settings.LPFDirectCoefficient), 1.0f }; - hr = instanceinternal->sourceVoice->SetOutputFilterParameters(submixVoices[instance->type], &FilterParametersDirect); + hr = instanceinternal->sourceVoice->SetOutputFilterParameters(audio->submixVoices[instance->type], &FilterParametersDirect); assert(SUCCEEDED(hr)); XAUDIO2_FILTER_PARAMETERS FilterParametersReverb = { LowPassFilter, 2.0f * sinf(X3DAUDIO_PI / 6.0f * settings.LPFReverbCoefficient), 1.0f }; - hr = instanceinternal->sourceVoice->SetOutputFilterParameters(reverbSubmix, &FilterParametersReverb); + hr = instanceinternal->sourceVoice->SetOutputFilterParameters(audio->reverbSubmix, &FilterParametersReverb); assert(SUCCEEDED(hr)); } } - static const XAUDIO2FX_REVERB_I3DL2_PARAMETERS reverbPresets[] = - { - XAUDIO2FX_I3DL2_PRESET_DEFAULT, - XAUDIO2FX_I3DL2_PRESET_GENERIC, - XAUDIO2FX_I3DL2_PRESET_FOREST, - XAUDIO2FX_I3DL2_PRESET_PADDEDCELL, - XAUDIO2FX_I3DL2_PRESET_ROOM, - XAUDIO2FX_I3DL2_PRESET_BATHROOM, - XAUDIO2FX_I3DL2_PRESET_LIVINGROOM, - XAUDIO2FX_I3DL2_PRESET_STONEROOM, - XAUDIO2FX_I3DL2_PRESET_AUDITORIUM, - XAUDIO2FX_I3DL2_PRESET_CONCERTHALL, - XAUDIO2FX_I3DL2_PRESET_CAVE, - XAUDIO2FX_I3DL2_PRESET_ARENA, - XAUDIO2FX_I3DL2_PRESET_HANGAR, - XAUDIO2FX_I3DL2_PRESET_CARPETEDHALLWAY, - XAUDIO2FX_I3DL2_PRESET_HALLWAY, - XAUDIO2FX_I3DL2_PRESET_STONECORRIDOR, - XAUDIO2FX_I3DL2_PRESET_ALLEY, - XAUDIO2FX_I3DL2_PRESET_CITY, - XAUDIO2FX_I3DL2_PRESET_MOUNTAINS, - XAUDIO2FX_I3DL2_PRESET_QUARRY, - XAUDIO2FX_I3DL2_PRESET_PLAIN, - XAUDIO2FX_I3DL2_PRESET_PARKINGLOT, - XAUDIO2FX_I3DL2_PRESET_SEWERPIPE, - XAUDIO2FX_I3DL2_PRESET_UNDERWATER, - XAUDIO2FX_I3DL2_PRESET_SMALLROOM, - XAUDIO2FX_I3DL2_PRESET_MEDIUMROOM, - XAUDIO2FX_I3DL2_PRESET_LARGEROOM, - XAUDIO2FX_I3DL2_PRESET_MEDIUMHALL, - XAUDIO2FX_I3DL2_PRESET_LARGEHALL, - XAUDIO2FX_I3DL2_PRESET_PLATE, - }; void SetReverb(REVERB_PRESET preset) { XAUDIO2FX_REVERB_PARAMETERS native; ReverbConvertI3DL2ToNative(&reverbPresets[preset], &native); - HRESULT hr = reverbSubmix->SetEffectParameters(0, &native, sizeof(native)); + HRESULT hr = audio->reverbSubmix->SetEffectParameters(0, &native, sizeof(native)); assert(SUCCEEDED(hr)); } } diff --git a/WickedEngine/wiAudio.h b/WickedEngine/wiAudio.h index 07610ff29..6f0f0098d 100644 --- a/WickedEngine/wiAudio.h +++ b/WickedEngine/wiAudio.h @@ -6,7 +6,6 @@ namespace wiAudio { void Initialize(); - void CleanUp(); enum SUBMIX_TYPE { diff --git a/WickedEngine/wiFont.cpp b/WickedEngine/wiFont.cpp index fa9ace377..69035f442 100644 --- a/WickedEngine/wiFont.cpp +++ b/WickedEngine/wiFont.cpp @@ -76,8 +76,9 @@ namespace wiFont_Internal vector fontBuffer; stbtt_fontinfo fontInfo; int ascent, descent, lineGap; - wiFontStyle(const string& newName) : name(newName) + void Create(const string& newName) { + name = newName; wiHelper::readByteData(newName, fontBuffer); int offset = stbtt_GetFontOffsetForIndex(fontBuffer.data(), 0); @@ -92,7 +93,7 @@ namespace wiFont_Internal stbtt_GetFontVMetrics(&fontInfo, &ascent, &descent, &lineGap); } }; - std::vector fontStyles; + std::vector fontStyles; struct FontVertex { @@ -288,14 +289,6 @@ void wiFont::Initialize() wiBackLog::post("wiFont Initialized"); initialized.store(true); } -void wiFont::CleanUp() -{ - for (auto& x : fontStyles) - { - SAFE_DELETE(x); - } - fontStyles.clear(); -} void wiFont::LoadShaders() { @@ -336,7 +329,7 @@ void UpdatePendingGlyphs() const int code = codefromhash(hash); const int style = stylefromhash(hash); const int height = heightfromhash(hash); - wiFontStyle& fontStyle = *fontStyles[style]; + wiFontStyle& fontStyle = fontStyles[style]; float fontScaling = stbtt_ScaleForPixelHeight(&fontStyle.fontInfo, float(height)); @@ -389,7 +382,7 @@ void UpdatePendingGlyphs() const wchar_t code = codefromhash(hash); const int style = stylefromhash(hash); const int height = heightfromhash(hash); - wiFontStyle& fontStyle = *fontStyles[style]; + wiFontStyle& fontStyle = fontStyles[style]; rect_xywh& rect = it.second; Glyph& glyph = glyph_lookup[hash]; @@ -444,13 +437,14 @@ int wiFont::AddFontStyle(const string& fontName) { for (size_t i = 0; i < fontStyles.size(); i++) { - const wiFontStyle& fontStyle = *fontStyles[i]; + const wiFontStyle& fontStyle = fontStyles[i]; if (!fontStyle.name.compare(fontName)) { return int(i); } } - fontStyles.push_back(new wiFontStyle(fontName)); + fontStyles.emplace_back(); + fontStyles.back().Create(fontName); return int(fontStyles.size() - 1); } diff --git a/WickedEngine/wiFont.h b/WickedEngine/wiFont.h index bf599dafb..c077a5718 100644 --- a/WickedEngine/wiFont.h +++ b/WickedEngine/wiFont.h @@ -36,7 +36,6 @@ class wiFont { public: static void Initialize(); - static void CleanUp(); static void LoadShaders(); static const wiGraphics::Texture* GetAtlas(); diff --git a/WickedEngine/wiFont_BindLua.cpp b/WickedEngine/wiFont_BindLua.cpp index f5b780aea..3d3ad643c 100644 --- a/WickedEngine/wiFont_BindLua.cpp +++ b/WickedEngine/wiFont_BindLua.cpp @@ -25,7 +25,6 @@ Luna::FunctionType wiFont_BindLua::methods[] = { lunamethod(wiFont_BindLua, GetColor), lunamethod(wiFont_BindLua, GetShadowColor), - lunamethod(wiFont_BindLua, Destroy), { NULL, NULL } }; Luna::PropertyType wiFont_BindLua::properties[] = { @@ -222,17 +221,6 @@ int wiFont_BindLua::GetShadowColor(lua_State* L) return 1; } -int wiFont_BindLua::Destroy(lua_State* L) -{ - if (font != nullptr) - { - font->CleanUp(); - delete font; - font = nullptr; - } - return 0; -} - void wiFont_BindLua::Bind() { static bool initialized = false; diff --git a/WickedEngine/wiFont_BindLua.h b/WickedEngine/wiFont_BindLua.h index 802488b74..131ab4d4f 100644 --- a/WickedEngine/wiFont_BindLua.h +++ b/WickedEngine/wiFont_BindLua.h @@ -34,9 +34,6 @@ public: int GetColor(lua_State* L); int GetShadowColor(lua_State* L); - int Destroy(lua_State* L); - - static void Bind(); }; diff --git a/WickedEngine/wiGPUSortLib.cpp b/WickedEngine/wiGPUSortLib.cpp index 85c78596f..3cc4219aa 100644 --- a/WickedEngine/wiGPUSortLib.cpp +++ b/WickedEngine/wiGPUSortLib.cpp @@ -46,10 +46,6 @@ namespace wiGPUSortLib } - void CleanUp() - { - } - void Sort( uint32_t maxCount, diff --git a/WickedEngine/wiInitializer.cpp b/WickedEngine/wiInitializer.cpp index 7d5a66f40..66a15eb5b 100644 --- a/WickedEngine/wiInitializer.cpp +++ b/WickedEngine/wiInitializer.cpp @@ -44,12 +44,4 @@ namespace wiInitializer { return initializationStarted && !wiJobSystem::IsBusy(ctx); } - - void CleanUp() - { - wiFont::CleanUp(); - wiAudio::CleanUp(); - wiNetwork::CleanUp(); - wiPhysicsEngine::CleanUp(); - } } \ No newline at end of file diff --git a/WickedEngine/wiInitializer.h b/WickedEngine/wiInitializer.h index 413991665..5e4f2a4c6 100644 --- a/WickedEngine/wiInitializer.h +++ b/WickedEngine/wiInitializer.h @@ -9,8 +9,6 @@ namespace wiInitializer void InitializeComponentsAsync(); // Check if systems have been initialized or not bool IsInitializeFinished(); - - void CleanUp(); } diff --git a/WickedEngine/wiNetwork.h b/WickedEngine/wiNetwork.h index 866e83258..0a3f1ad65 100644 --- a/WickedEngine/wiNetwork.h +++ b/WickedEngine/wiNetwork.h @@ -33,7 +33,6 @@ namespace wiNetwork }; void Initialize(); - void CleanUp(); // Creates a socket that can be used to send or receive data bool CreateSocket(Socket* sock); diff --git a/WickedEngine/wiNetwork_UWP.cpp b/WickedEngine/wiNetwork_UWP.cpp index c0886fc40..8e96c44fe 100644 --- a/WickedEngine/wiNetwork_UWP.cpp +++ b/WickedEngine/wiNetwork_UWP.cpp @@ -12,9 +12,6 @@ namespace wiNetwork { wiBackLog::post("TODO wiNetwork_UWP"); } - void CleanUp() - { - } bool CreateSocket(Socket* sock) { diff --git a/WickedEngine/wiNetwork_Windows.cpp b/WickedEngine/wiNetwork_Windows.cpp index d5c81b6e4..0350149e9 100644 --- a/WickedEngine/wiNetwork_Windows.cpp +++ b/WickedEngine/wiNetwork_Windows.cpp @@ -31,10 +31,6 @@ namespace wiNetwork wiBackLog::post("wiNetwork Initialized"); } - void CleanUp() - { - WSACleanup(); - } bool CreateSocket(Socket* sock) { diff --git a/WickedEngine/wiPhysicsEngine.h b/WickedEngine/wiPhysicsEngine.h index ef54afd1d..819d2e53f 100644 --- a/WickedEngine/wiPhysicsEngine.h +++ b/WickedEngine/wiPhysicsEngine.h @@ -6,7 +6,6 @@ namespace wiPhysicsEngine { void Initialize(); - void CleanUp(); bool IsEnabled(); void SetEnabled(bool value); diff --git a/WickedEngine/wiPhysicsEngine_Bullet.cpp b/WickedEngine/wiPhysicsEngine_Bullet.cpp index 7885251ac..fe0c5d554 100644 --- a/WickedEngine/wiPhysicsEngine_Bullet.cpp +++ b/WickedEngine/wiPhysicsEngine_Bullet.cpp @@ -11,6 +11,7 @@ #include "BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h" #include +#include using namespace std; using namespace wiECS; @@ -24,30 +25,28 @@ namespace wiPhysicsEngine btVector3 gravity(0, -10, 0); int softbodyIterationCount = 5; - btCollisionConfiguration* collisionConfiguration = nullptr; - btCollisionDispatcher* dispatcher = nullptr; - btBroadphaseInterface* overlappingPairCache = nullptr; - btSequentialImpulseConstraintSolver* solver = nullptr; - btDynamicsWorld* dynamicsWorld = nullptr; + std::unique_ptr collisionConfiguration; + std::unique_ptr dispatcher; + std::unique_ptr overlappingPairCache; + std::unique_ptr solver; + std::unique_ptr dynamicsWorld; void Initialize() { // collision configuration contains default setup for memory, collision setup. Advanced users can create their own configuration. - collisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration; + collisionConfiguration = std::make_unique(); // use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded) - dispatcher = new btCollisionDispatcher(collisionConfiguration); + dispatcher = std::make_unique(collisionConfiguration.get()); // btDbvtBroadphase is a good general purpose broadphase. You can also try out btAxis3Sweep. - overlappingPairCache = new btDbvtBroadphase; + overlappingPairCache = std::make_unique(); // the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded) - solver = new btSequentialImpulseConstraintSolver; + solver = std::make_unique(); - //dynamicsWorld = new btSimpleDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration); - //dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,overlappingPairCache,solver,collisionConfiguration); - dynamicsWorld = new btSoftRigidDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration); + dynamicsWorld = std::make_unique(dispatcher.get(), overlappingPairCache.get(), solver.get(), collisionConfiguration.get()); dynamicsWorld->getSolverInfo().m_solverMode |= SOLVER_RANDMIZE_ORDER; dynamicsWorld->getDispatchInfo().m_enableSatConvex = true; @@ -55,7 +54,7 @@ namespace wiPhysicsEngine dynamicsWorld->setGravity(gravity); - btSoftRigidDynamicsWorld* softRigidWorld = (btSoftRigidDynamicsWorld*)dynamicsWorld; + btSoftRigidDynamicsWorld* softRigidWorld = (btSoftRigidDynamicsWorld*)dynamicsWorld.get(); btSoftBodyWorldInfo& softWorldInfo = softRigidWorld->getWorldInfo(); softWorldInfo.air_density = btScalar(1.2f); softWorldInfo.water_density = 0; @@ -66,14 +65,6 @@ namespace wiPhysicsEngine wiBackLog::post("wiPhysicsEngine_Bullet Initialized"); } - void CleanUp() - { - delete dynamicsWorld; - delete solver; - delete overlappingPairCache; - delete dispatcher; - delete collisionConfiguration; - } bool IsEnabled() { return ENABLED; } void SetEnabled(bool value) { ENABLED = value; } @@ -228,7 +219,7 @@ namespace wiPhysicsEngine } btSoftBody* softbody = btSoftBodyHelpers::CreateFromTriMesh( - ((btSoftRigidDynamicsWorld*)dynamicsWorld)->getWorldInfo() + ((btSoftRigidDynamicsWorld*)dynamicsWorld.get())->getWorldInfo() , btVerts , btInd , tCount @@ -287,7 +278,7 @@ namespace wiPhysicsEngine softbody->setPose(true, true); - ((btSoftRigidDynamicsWorld*)dynamicsWorld)->addSoftBody(softbody); + ((btSoftRigidDynamicsWorld*)dynamicsWorld.get())->addSoftBody(softbody); physicscomponent.physicsobject = softbody; } } @@ -458,7 +449,7 @@ namespace wiPhysicsEngine SoftBodyPhysicsComponent* physicscomponent = softbodies.GetComponent(entity); if (physicscomponent == nullptr) { - ((btSoftRigidDynamicsWorld*)dynamicsWorld)->removeSoftBody(softbody); + ((btSoftRigidDynamicsWorld*)dynamicsWorld.get())->removeSoftBody(softbody); i--; continue; } diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index 71437e831..a576d805a 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wiVersion // minor features, major updates const int minor = 36; // minor bug fixes, alterations, refactors, updates - const int revision = 5; + const int revision = 6; long GetVersion()