From 0fa5ddafbfb196be70d2df8ae8299bfc8fbf398d Mon Sep 17 00:00:00 2001 From: Drewol Date: Sat, 27 Jun 2020 19:24:09 +0200 Subject: [PATCH 01/11] Replace Ref with std::shared_ptr and fix some warnings --- Audio/include/Audio/DSP.hpp | 1 + Audio/src/AudioStream.cpp | 2 +- Audio/src/AudioStreamMa.cpp | 3 +- Audio/src/AudioStreamMa.hpp | 4 +- Audio/src/AudioStreamMp3.hpp | 5 +- Audio/src/AudioStreamOgg.hpp | 5 +- Audio/src/AudioStreamWav.hpp | 5 +- Audio/src/DSP.cpp | 14 + Beatmap/include/Beatmap/AudioEffects.hpp | 12 +- Beatmap/include/Beatmap/BeatmapObjects.hpp | 4 +- Beatmap/src/BeatmapFromKSH.cpp | 2 + GUI/include/GUI/nanovg_lua.h | 25 +- Graphics/include/Graphics/Font.hpp | 2 +- Graphics/include/Graphics/Image.hpp | 4 +- Graphics/include/Graphics/Keys.hpp | 6 +- Graphics/include/Graphics/Material.hpp | 2 +- Graphics/include/Graphics/Mesh.hpp | 2 +- Graphics/include/Graphics/OpenGL.hpp | 2 +- Graphics/include/Graphics/ParticleEmitter.hpp | 6 +- .../include/Graphics/ParticleParameter.hpp | 12 +- Graphics/include/Graphics/ParticleSystem.hpp | 2 +- Graphics/include/Graphics/Shader.hpp | 2 +- Graphics/include/Graphics/Texture.hpp | 2 +- Graphics/src/Font.cpp | 2 +- Graphics/src/Material.cpp | 2 +- Graphics/src/ParticleSystem.cpp | 4 +- Graphics/src/Window.cpp | 6 +- Main/CMakeLists.txt | 2 + Main/include/Audio/AudioPlayback.hpp | 2 +- Main/include/Camera.hpp | 6 +- Main/include/ChatOverlay.hpp | 4 +- Main/include/Game.hpp | 2 +- Main/include/GameConfig.hpp | 8 +- Main/include/Input.hpp | 4 +- Main/include/SongFilter.hpp | 6 +- Main/include/SongSelect.hpp | 6 +- Main/include/SongSort.hpp | 2 +- Main/src/Application.cpp | 13 +- Main/src/AsyncAssetLoader.cpp | 6 +- Main/src/Audio/AudioPlayback.cpp | 29 +- Main/src/Audio/GameAudioEffects.cpp | 6 + Main/src/Background.cpp | 3 +- Main/src/Camera.cpp | 13 +- Main/src/ChatOverlay.cpp | 35 +-- Main/src/DownloadScreen.cpp | 3 +- Main/src/Game.cpp | 25 +- Main/src/GameplaySettingsDialog.cpp | 67 ++-- Main/src/Input.cpp | 6 +- Main/src/LaserTrackBuilder.cpp | 4 +- Main/src/MultiplayerScreen.cpp | 18 +- Main/src/ScoreScreen.cpp | 16 +- Main/src/Scoring.cpp | 17 +- Main/src/SettingsScreen.cpp | 39 ++- Main/src/SkinConfig.cpp | 8 +- Main/src/SongSelect.cpp | 91 +++--- Main/src/SongSort.cpp | 2 +- Main/src/TCPSocket.cpp | 4 +- Main/src/Track.cpp | 4 +- Main/src/TransitionScreen.cpp | 2 +- Shared/include/Shared/Enum.hpp | 18 +- Shared/include/Shared/Jobs.hpp | 2 +- Shared/include/Shared/Log.hpp | 2 +- Shared/include/Shared/Ref.hpp | 288 ++---------------- Shared/include/Shared/ResourceManager.hpp | 7 +- Shared/include/Shared/String.hpp | 4 +- Shared/include/Shared/Vector.hpp | 2 +- Shared/include/Shared/VectorMath.hpp | 10 +- Shared/src/Jobs.cpp | 18 +- Tests.Game/src/TestAudio.cpp | 2 +- Tests.Game/src/TestMusicPlayer.cpp | 2 +- 70 files changed, 385 insertions(+), 561 deletions(-) diff --git a/Audio/include/Audio/DSP.hpp b/Audio/include/Audio/DSP.hpp index afed78c50..8a84ff016 100644 --- a/Audio/include/Audio/DSP.hpp +++ b/Audio/include/Audio/DSP.hpp @@ -20,6 +20,7 @@ class PanDSP : public DSP class BQFDSP : public DSP { public: + BQFDSP(); float b0 = 1.0f; float b1 = 0.0f; float b2 = 0.0f; diff --git a/Audio/src/AudioStream.cpp b/Audio/src/AudioStream.cpp index 2416a70eb..a1ca4421d 100644 --- a/Audio/src/AudioStream.cpp +++ b/Audio/src/AudioStream.cpp @@ -42,6 +42,6 @@ Ref AudioStream::Create(Audio* audio, const String& path, bool prel { Ref impl = FindImplementation(audio, path, preload); if(impl) - audio->GetImpl()->Register(impl.GetData()); + audio->GetImpl()->Register(impl.get()); return impl; } \ No newline at end of file diff --git a/Audio/src/AudioStreamMa.cpp b/Audio/src/AudioStreamMa.cpp index 42053db21..3162c0dff 100644 --- a/Audio/src/AudioStreamMa.cpp +++ b/Audio/src/AudioStreamMa.cpp @@ -141,7 +141,6 @@ Ref AudioStreamMa::Create(class Audio* audio, const String& path, b { delete impl; impl = nullptr; - return Ref(); } - return Ref(impl); + return Utility::CastRef(Utility::MakeRef(impl)); } diff --git a/Audio/src/AudioStreamMa.hpp b/Audio/src/AudioStreamMa.hpp index fa351d6da..b45e2dfa9 100644 --- a/Audio/src/AudioStreamMa.hpp +++ b/Audio/src/AudioStreamMa.hpp @@ -13,8 +13,6 @@ class AudioStreamMa : public AudioStreamBase ma_decoder m_decoder; int m_byteRate; protected: - AudioStreamMa() = default; - ~AudioStreamMa(); bool Init(Audio* audio, const String& path, bool preload) override; int32 GetStreamPosition_Internal() override; int32 GetStreamRate_Internal() override; @@ -23,5 +21,7 @@ class AudioStreamMa : public AudioStreamBase float* GetPCM_Internal() override; uint32 GetSampleRate_Internal() const override; public: + AudioStreamMa() = default; + ~AudioStreamMa(); static Ref Create(class Audio* audio, const String& path, bool preload); }; diff --git a/Audio/src/AudioStreamMp3.hpp b/Audio/src/AudioStreamMp3.hpp index 755cd2bf7..9efa127ce 100644 --- a/Audio/src/AudioStreamMp3.hpp +++ b/Audio/src/AudioStreamMp3.hpp @@ -23,8 +23,7 @@ class AudioStreamMp3 : public AudioStreamBase int m_unsynchsafe(int in); int m_toLittleEndian(int num); protected: - AudioStreamMp3() = default; - ~AudioStreamMp3(); + bool Init(Audio* audio, const String& path, bool preload) override; void SetPosition_Internal(int32 pos) override; int32 GetStreamPosition_Internal() override; @@ -33,5 +32,7 @@ class AudioStreamMp3 : public AudioStreamBase float* GetPCM_Internal() override; int32 DecodeData_Internal() override; public: + AudioStreamMp3() = default; + ~AudioStreamMp3(); static Ref Create(Audio* audio, const String& path, bool preload); }; diff --git a/Audio/src/AudioStreamOgg.hpp b/Audio/src/AudioStreamOgg.hpp index 36a56a5e5..ca5572084 100644 --- a/Audio/src/AudioStreamOgg.hpp +++ b/Audio/src/AudioStreamOgg.hpp @@ -11,8 +11,7 @@ class AudioStreamOgg : public AudioStreamBase Vector m_pcm; int64 m_playPos; - AudioStreamOgg() = default; - ~AudioStreamOgg(); + bool Init(Audio* audio, const String& path, bool preload) override; void SetPosition_Internal(int32 pos) override; int32 GetStreamPosition_Internal() override; @@ -25,5 +24,7 @@ class AudioStreamOgg : public AudioStreamBase static int m_Seek(AudioStreamOgg* self, int64 offset, int whence); static long m_Tell(AudioStreamOgg* self); public: + AudioStreamOgg() = default; + ~AudioStreamOgg(); static Ref Create(class Audio* audio, const String& path, bool preload); }; diff --git a/Audio/src/AudioStreamWav.hpp b/Audio/src/AudioStreamWav.hpp index 70aec1091..8f0e5647f 100644 --- a/Audio/src/AudioStreamWav.hpp +++ b/Audio/src/AudioStreamWav.hpp @@ -37,8 +37,7 @@ class AudioStreamWav : public AudioStreamBase uint32 m_decode_ms_adpcm(const Buffer& encoded, Buffer* decoded, uint64 pos); protected: - AudioStreamWav() = default; - ~AudioStreamWav(); + bool Init(Audio* audio, const String& path, bool preload) override; int32 GetStreamPosition_Internal() override; int32 GetStreamRate_Internal() override; @@ -47,5 +46,7 @@ class AudioStreamWav : public AudioStreamBase float* GetPCM_Internal() override; uint32 GetSampleRate_Internal() const override; public: + AudioStreamWav() = default; + ~AudioStreamWav(); static Ref Create(class Audio* audio, const String& path, bool preload); }; diff --git a/Audio/src/DSP.cpp b/Audio/src/DSP.cpp index 946b8f666..d6cda8f45 100644 --- a/Audio/src/DSP.cpp +++ b/Audio/src/DSP.cpp @@ -15,6 +15,20 @@ void PanDSP::Process(float* out, uint32 numSamples) } } +BQFDSP::BQFDSP() +{ + for (size_t i = 0; i < 2; i++) + { + for (size_t j = 0; j < order; j++) + { + za[i][j] = 0.f; + zb[i][j] = 0.f; + } + + } + +} + void BQFDSP::Process(float* out, uint32 numSamples) { for(uint32 c = 0; c < 2; c++) diff --git a/Beatmap/include/Beatmap/AudioEffects.hpp b/Beatmap/include/Beatmap/AudioEffects.hpp index 14eea2630..e8683455c 100644 --- a/Beatmap/include/Beatmap/AudioEffects.hpp +++ b/Beatmap/include/Beatmap/AudioEffects.hpp @@ -33,7 +33,7 @@ DefineEnum(EffectType, UserDefined7, UserDefined8, UserDefined9 // etc... - ); + ) /* Effect parameter that is used to define a certain time range/period/speed @@ -86,7 +86,9 @@ class EffectParam EffectParam(T value) { values[0] = value; + values[1] = value; isRange = false; + timeFunction = Interpolation::Linear; } EffectParam(T valueA, T valueB, Interpolation::TimeFunction timeFunction = Interpolation::Linear) { @@ -198,10 +200,6 @@ struct AudioEffect } pitchshift; struct { - // Peak Q factor (>=0) - EffectParam peakQ; - // Peak amplification (>=0) - EffectParam gain; // Q factor for filter (>0) EffectParam q; // Cuttoff frequency (Hz) @@ -209,10 +207,6 @@ struct AudioEffect } lpf; struct { - // Peak Q factor (>=0) - EffectParam peakQ; - // Peak amplification (>=0) - EffectParam gain; // Q factor for filter (>0) EffectParam q; // Cuttoff frequency (Hz) diff --git a/Beatmap/include/Beatmap/BeatmapObjects.hpp b/Beatmap/include/Beatmap/BeatmapObjects.hpp index 639d0ae84..f141847da 100644 --- a/Beatmap/include/Beatmap/BeatmapObjects.hpp +++ b/Beatmap/include/Beatmap/BeatmapObjects.hpp @@ -279,7 +279,7 @@ struct TimingPoint double GetBPM() const { return 60000.0 / beatDuration; } // Position in ms when this timing point appears - MapTime time; + MapTime time = 0; // Beat duration of a 4th note in milliseconds // this is a double so the least precision is lost // can be cast back to integer format once is has been multiplied by the amount of beats you want the length of. @@ -287,7 +287,7 @@ struct TimingPoint double beatDuration; // Upper part of the time signature // how many beats per bar - uint8 numerator; + uint8 numerator = 4; // Lower part of the time signature // the note value (4th, 3th, 8th notes, etc.) for a beat uint8 denominator = 4; diff --git a/Beatmap/src/BeatmapFromKSH.cpp b/Beatmap/src/BeatmapFromKSH.cpp index 19db1eeea..6ab935aa8 100644 --- a/Beatmap/src/BeatmapFromKSH.cpp +++ b/Beatmap/src/BeatmapFromKSH.cpp @@ -712,6 +712,7 @@ bool Beatmap::m_ProcessKShootMap(BinaryStream &input, bool metadataOnly) { // Inser filter type change event EventObjectState *evt = new EventObjectState(); + evt->interTickIndex = tickSettingIndex; evt->time = mapTime; evt->key = EventKey::LaserEffectType; evt->data.effectVal = ParseFilterType(p.second); @@ -722,6 +723,7 @@ bool Beatmap::m_ProcessKShootMap(BinaryStream &input, bool metadataOnly) // Inser filter type change event float gain = (float)atol(*p.second) / 100.0f; EventObjectState *evt = new EventObjectState(); + evt->interTickIndex = tickSettingIndex; evt->time = mapTime; evt->key = EventKey::LaserEffectMix; evt->data.floatVal = gain; diff --git a/GUI/include/GUI/nanovg_lua.h b/GUI/include/GUI/nanovg_lua.h index 3111881ef..3f6f5970f 100644 --- a/GUI/include/GUI/nanovg_lua.h +++ b/GUI/include/GUI/nanovg_lua.h @@ -69,6 +69,7 @@ struct GUIState Map animations; int scissorOffset; Vector transformStack; + Vector nvgFonts; }; @@ -88,7 +89,7 @@ static int LoadFont(const char* name, const char* filename, lua_State* L) { String path = filename; Graphics::Font newFont = FontRes::Create(g_gl, path); - if (!newFont.IsValid()) + if (!newFont) { lua_Debug ar; lua_getstack(L, 1, &ar); @@ -112,8 +113,8 @@ static int LoadFont(const char* name, const char* filename, lua_State* L) nvgFontFace(g_guiState.vg, name); return 0; } - - nvgFontFaceId(g_guiState.vg, nvgCreateFont(g_guiState.vg, name, filename)); + int fontId = nvgCreateFont(g_guiState.vg, name, filename); + nvgFontFaceId(g_guiState.vg, fontId); nvgAddFallbackFont(g_guiState.vg, name, "fallback"); } return 0; @@ -140,7 +141,7 @@ static void AnimationLoader(Vector files, ImageAnimation* ia) if (ia->Compressed.load()) { - for (size_t i = 0; i < ia->FrameCount; i++) + for (int i = 0; i < ia->FrameCount; i++) { if (ia->Cancelled.load()) break; @@ -155,7 +156,7 @@ static void AnimationLoader(Vector files, ImageAnimation* ia) ia->NextImage = ImageRes::Create(ia->FrameData[0]); } else { - for (size_t i = 0; i < ia->FrameCount; i++) + for (int i = 0; i < ia->FrameCount; i++) { if (ia->Cancelled.load()) break; @@ -335,11 +336,6 @@ static int lText(lua_State* L /*const char* s, float x, float y*/) //} return 0; } -static int guiText(const char* s, float x, float y) -{ - nvgText(g_guiState.vg, x, y, s, 0); - return 0; -} static int lFontFace(lua_State* L /*const char* s*/) { @@ -429,8 +425,13 @@ static int lSetImageTint(lua_State* L /*int r, int g, int b*/) static int lImageRect(lua_State* L /*float x, float y, float w, float h, int image, float alpha, float angle*/) { - float x, y, w, h, alpha, angle; - int image; + float x = 0.f; + float y = 0.f; + float w = 0.f; + float h = 0.f; + float alpha = 1.f; + float angle = 0.f; + int image = -1; x = luaL_checknumber(L, 1); y = luaL_checknumber(L, 2); w = luaL_checknumber(L, 3); diff --git a/Graphics/include/Graphics/Font.hpp b/Graphics/include/Graphics/Font.hpp index d15b8747b..b81a9dc8b 100644 --- a/Graphics/include/Graphics/Font.hpp +++ b/Graphics/include/Graphics/Font.hpp @@ -51,5 +51,5 @@ namespace Graphics typedef Ref Font; typedef Ref Text; - DEFINE_RESOURCE_TYPE(Font, FontRes); + DEFINE_RESOURCE_TYPE(Font, FontRes) } diff --git a/Graphics/include/Graphics/Image.hpp b/Graphics/include/Graphics/Image.hpp index 221155c84..d0e8c0ec9 100644 --- a/Graphics/include/Graphics/Image.hpp +++ b/Graphics/include/Graphics/Image.hpp @@ -48,6 +48,6 @@ namespace Graphics typedef Ref Image; typedef Ref SpriteMap; - DEFINE_RESOURCE_TYPE(Image, ImageRes); - DEFINE_RESOURCE_TYPE(SpriteMap, SpriteMapRes); + DEFINE_RESOURCE_TYPE(Image, ImageRes) + DEFINE_RESOURCE_TYPE(SpriteMap, SpriteMapRes) } \ No newline at end of file diff --git a/Graphics/include/Graphics/Keys.hpp b/Graphics/include/Graphics/Keys.hpp index f3ed67055..e19c950bb 100644 --- a/Graphics/include/Graphics/Keys.hpp +++ b/Graphics/include/Graphics/Keys.hpp @@ -11,13 +11,13 @@ namespace Graphics DefineEnum(MouseButton, Left = 0, Middle, - Right); + Right) DefineBitflagEnum(ModifierKeys, None = 0, Alt = 1, Ctrl = 2, - Shift = 4); + Shift = 4) DefineEnum(Key, None = 0, @@ -90,5 +90,5 @@ namespace Graphics Return, PageUp, PageDown, - Tab); + Tab) } \ No newline at end of file diff --git a/Graphics/include/Graphics/Material.hpp b/Graphics/include/Graphics/Material.hpp index 0fdfa9de0..9b05ba01b 100644 --- a/Graphics/include/Graphics/Material.hpp +++ b/Graphics/include/Graphics/Material.hpp @@ -96,5 +96,5 @@ namespace Graphics typedef Ref Material; - DEFINE_RESOURCE_TYPE(Material, MaterialRes); + DEFINE_RESOURCE_TYPE(Material, MaterialRes) } \ No newline at end of file diff --git a/Graphics/include/Graphics/Mesh.hpp b/Graphics/include/Graphics/Mesh.hpp index 43f64cbbe..0c1246d52 100644 --- a/Graphics/include/Graphics/Mesh.hpp +++ b/Graphics/include/Graphics/Mesh.hpp @@ -48,5 +48,5 @@ namespace Graphics typedef Ref Mesh; - DEFINE_RESOURCE_TYPE(Mesh, MeshRes); + DEFINE_RESOURCE_TYPE(Mesh, MeshRes) } \ No newline at end of file diff --git a/Graphics/include/Graphics/OpenGL.hpp b/Graphics/include/Graphics/OpenGL.hpp index 6d26fba87..2a4a2da6c 100644 --- a/Graphics/include/Graphics/OpenGL.hpp +++ b/Graphics/include/Graphics/OpenGL.hpp @@ -29,7 +29,7 @@ namespace Graphics public: OpenGL(); - ~OpenGL(); + virtual ~OpenGL(); void InitResourceManagers(); bool Init(Window& window, uint32 antialiasing); diff --git a/Graphics/include/Graphics/ParticleEmitter.hpp b/Graphics/include/Graphics/ParticleEmitter.hpp index 9067fbeda..9ff435b2b 100644 --- a/Graphics/include/Graphics/ParticleEmitter.hpp +++ b/Graphics/include/Graphics/ParticleEmitter.hpp @@ -12,6 +12,7 @@ namespace Graphics class ParticleEmitter { public: + ParticleEmitter() = default; ~ParticleEmitter(); // Material used for the particle @@ -36,8 +37,9 @@ namespace Graphics #define PARTICLE_PARAMETER(__name, __type)\ void Set##__name(const IParticleParameter<__type>& param)\ {\ - if(m_param_##__name)\ - delete m_param_##__name;\ + IParticleParameter<__type>* p = static_cast*>(m_param_##__name);\ + if(p)\ + delete p;\ m_param_##__name = param.Duplicate();\ } #include diff --git a/Graphics/include/Graphics/ParticleParameter.hpp b/Graphics/include/Graphics/ParticleParameter.hpp index 393db3ffe..cc79b403e 100644 --- a/Graphics/include/Graphics/ParticleParameter.hpp +++ b/Graphics/include/Graphics/ParticleParameter.hpp @@ -14,6 +14,7 @@ namespace Graphics class IParticleParameter { public: + virtual ~IParticleParameter() = default; // Used to initialize a starting attribute virtual T Init(float systemTime) { return Sample(systemTime); } // Used to process over lifetime events @@ -171,9 +172,13 @@ namespace Graphics */ class PPCone : public IParticleParameter { + private: + float lengthMin, lengthMax; + float angle; + Transform mat; public: PPCone(Vector3 dir, float angle, float lengthMin, float lengthMax) - : angle(angle * Math::degToRad), lengthMin(lengthMin), lengthMax(lengthMax) + : lengthMin(lengthMin), lengthMax(lengthMax), angle(angle * Math::degToRad) { Vector3 normal = dir.Normalized(); Vector3 tangent = Vector3(normal.y, -normal.x, normal.z); @@ -210,10 +215,7 @@ namespace Graphics return Vector3(0, 0, lengthMax); } IMPLEMENT_DUPLICATE(Vector3, PPCone); - private: - float lengthMin, lengthMax; - float angle; - Transform mat; + }; #undef IMPLEMENT_DUPLICATE diff --git a/Graphics/include/Graphics/ParticleSystem.hpp b/Graphics/include/Graphics/ParticleSystem.hpp index c6bfe9f69..cbc4ce555 100644 --- a/Graphics/include/Graphics/ParticleSystem.hpp +++ b/Graphics/include/Graphics/ParticleSystem.hpp @@ -23,5 +23,5 @@ namespace Graphics typedef Ref ParticleSystem; - DEFINE_RESOURCE_TYPE(ParticleSystem, ParticleSystemRes); + DEFINE_RESOURCE_TYPE(ParticleSystem, ParticleSystemRes) } \ No newline at end of file diff --git a/Graphics/include/Graphics/Shader.hpp b/Graphics/include/Graphics/Shader.hpp index 926714756..f00138748 100644 --- a/Graphics/include/Graphics/Shader.hpp +++ b/Graphics/include/Graphics/Shader.hpp @@ -41,5 +41,5 @@ namespace Graphics typedef Ref Shader; - DEFINE_RESOURCE_TYPE(Shader, ShaderRes); + DEFINE_RESOURCE_TYPE(Shader, ShaderRes) } \ No newline at end of file diff --git a/Graphics/include/Graphics/Texture.hpp b/Graphics/include/Graphics/Texture.hpp index 79f155081..992316616 100644 --- a/Graphics/include/Graphics/Texture.hpp +++ b/Graphics/include/Graphics/Texture.hpp @@ -50,5 +50,5 @@ namespace Graphics typedef Ref Texture; - DEFINE_RESOURCE_TYPE(Texture, TextureRes); + DEFINE_RESOURCE_TYPE(Texture, TextureRes) } \ No newline at end of file diff --git a/Graphics/src/Font.cpp b/Graphics/src/Font.cpp index d8182e327..956fa7385 100644 --- a/Graphics/src/Font.cpp +++ b/Graphics/src/Font.cpp @@ -331,7 +331,7 @@ namespace Graphics ret->mesh->SetData(vertices); ret->mesh->SetPrimitiveType(PrimitiveType::TriangleList); - Text textObj = Ref(ret); + Text textObj = Utility::MakeRef(ret); // Insert into cache size->cache.AddText(str, textObj); return textObj; diff --git a/Graphics/src/Material.cpp b/Graphics/src/Material.cpp index e11fbf1a0..80e9fde4b 100644 --- a/Graphics/src/Material.cpp +++ b/Graphics/src/Material.cpp @@ -101,7 +101,7 @@ namespace Graphics { m_shaders[(size_t)t] = shader; - if (!shader.IsValid()) + if (shader.get() == nullptr) return; uint32 handle = shader->Handle(); diff --git a/Graphics/src/ParticleSystem.cpp b/Graphics/src/ParticleSystem.cpp index 0977dc19a..b6aa39409 100644 --- a/Graphics/src/ParticleSystem.cpp +++ b/Graphics/src/ParticleSystem.cpp @@ -37,7 +37,7 @@ namespace Graphics { (*it)->Render(rs, deltaTime); - if(it->GetRefCount() == 1) + if(it->use_count() == 1) { if((*it)->HasFinished()) { @@ -65,7 +65,7 @@ namespace Graphics { for(auto em : m_emitters) { - em.Destroy(); + em.reset(); } m_emitters.clear(); } diff --git a/Graphics/src/Window.cpp b/Graphics/src/Window.cpp index 94ef055a2..7a8a33a13 100644 --- a/Graphics/src/Window.cpp +++ b/Graphics/src/Window.cpp @@ -91,7 +91,7 @@ namespace Graphics // Release gamepads for(auto it : m_gamepads) { - it.second.Destroy(); + it.second.reset(); } SDL_DestroyWindow(m_window); @@ -610,7 +610,7 @@ namespace Graphics { Ref* openGamepad = m_impl->m_gamepads.Find(deviceIndex); if(openGamepad) - return openGamepad->As(); + return Utility::CastRef(*openGamepad); Ref newGamepad; Gamepad_Impl* gamepadImpl = new Gamepad_Impl(); @@ -631,7 +631,7 @@ namespace Graphics m_impl->m_gamepads.Add(deviceIndex, newGamepad); m_impl->m_joystickMap.Add(SDL_JoystickInstanceID(gamepadImpl->m_joystick), gamepadImpl); } - return newGamepad.As(); + return Utility::CastRef(newGamepad); } void Window::SetMousePos(const Vector2i& pos) diff --git a/Main/CMakeLists.txt b/Main/CMakeLists.txt index 9652cedef..8cc818f73 100644 --- a/Main/CMakeLists.txt +++ b/Main/CMakeLists.txt @@ -62,6 +62,8 @@ set_output_postfixes(usc-game) if(MSVC) set_target_properties(usc-game PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS") set_target_properties(usc-game PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/bin") +else() + target_compile_options(usc-game PUBLIC -Wall -Wextra -Werror -Wno-unused-variable -Wno-unused-parameter -Wno-unused-function) endif(MSVC) # Dependencies diff --git a/Main/include/Audio/AudioPlayback.hpp b/Main/include/Audio/AudioPlayback.hpp index 3bb0e6320..54133032b 100644 --- a/Main/include/Audio/AudioPlayback.hpp +++ b/Main/include/Audio/AudioPlayback.hpp @@ -73,7 +73,7 @@ class AudioPlayback : Unique void SetFXTrackEnabled(bool enabled); // Switch audio track - void SetSwitchableTrackEnabled(int index, bool enabled); + void SetSwitchableTrackEnabled(size_t index, bool enabled); void ResetSwitchableTracks(); BeatmapPlayback& GetBeatmapPlayback(); diff --git a/Main/include/Camera.hpp b/Main/include/Camera.hpp index e06825d0b..d3a8563be 100755 --- a/Main/include/Camera.hpp +++ b/Main/include/Camera.hpp @@ -5,12 +5,12 @@ */ struct CameraShake { + float duration; + float amplitude; + float time = 0.0f; CameraShake() = default; CameraShake(float duration); CameraShake(float duration, float amplitude); - float amplitude; - float duration; - float time = 0.0f; }; static const float KSM_PITCH_UNIT_PRE_168 = 7.0f; diff --git a/Main/include/ChatOverlay.hpp b/Main/include/ChatOverlay.hpp index 804289693..0c7c2ae43 100644 --- a/Main/include/ChatOverlay.hpp +++ b/Main/include/ChatOverlay.hpp @@ -72,13 +72,13 @@ class ChatOverlay: public IApplicationTickable bool m_nuklearRunning = false; + MultiplayerScreen* m_multi = NULL; struct nk_context* m_nctx = NULL; std::queue m_eventQueue; - MultiplayerScreen* m_multi = NULL; char m_chatDraft[512] = {0}; bool m_isOpen = false; - struct nk_scroll m_chatScroll = {0}; + struct nk_scroll m_chatScroll = {0, 0}; int m_newMessages = 0; bool m_inEdit = false; bool m_forceToBottom = false; diff --git a/Main/include/Game.hpp b/Main/include/Game.hpp index b467fb8ce..4189f3a13 100644 --- a/Main/include/Game.hpp +++ b/Main/include/Game.hpp @@ -27,7 +27,7 @@ struct ScoreReplay { int32 currentScore = 0; int32 maxScore = 0; - int32 nextHitStat = 0; + size_t nextHitStat = 0; Vector replay; }; GameFlags operator|(const GameFlags& a, const GameFlags& b); diff --git a/Main/include/GameConfig.hpp b/Main/include/GameConfig.hpp index cd346ef54..dec6e313f 100644 --- a/Main/include/GameConfig.hpp +++ b/Main/include/GameConfig.hpp @@ -146,16 +146,16 @@ DefineEnum(GameConfigKeys, // Gameplay options GaugeType, MirrorChart, - RandomizeChart); + RandomizeChart) DefineEnum(GaugeTypes, Normal, - Hard); + Hard) DefineEnum(SpeedMods, XMod, MMod, - CMod); + CMod) DefineEnum(AbortMethod, None, @@ -168,7 +168,7 @@ DefineEnum(AbortMethod, DefineEnum(AutoScoreScreenshotSettings, Off, Highscore, - Always); + Always) DefineEnum(ButtonComboModeSettings, Disabled, diff --git a/Main/include/Input.hpp b/Main/include/Input.hpp index 73120d570..b785e9f13 100644 --- a/Main/include/Input.hpp +++ b/Main/include/Input.hpp @@ -4,7 +4,7 @@ DefineEnum(InputDevice, Keyboard, Mouse, - Controller); + Controller) typedef Ref MouseLockHandle; @@ -27,7 +27,7 @@ class Input : Unique LS_1Neg, // Right laser- (<----|) LS_1Pos, // Right laser+ Back, - Length); + Length) ~Input(); void Init(Graphics::Window& wnd); diff --git a/Main/include/SongFilter.hpp b/Main/include/SongFilter.hpp index f4b54f9ad..120795867 100644 --- a/Main/include/SongFilter.hpp +++ b/Main/include/SongFilter.hpp @@ -15,7 +15,7 @@ class SongFilter { public: SongFilter() = default; - ~SongFilter() = default; + virtual ~SongFilter() = default; virtual Map GetFiltered(const Map& source) { return source; } virtual String GetName() const { return m_name; } @@ -30,6 +30,7 @@ class SongFilter class LevelFilter : public SongFilter { public: + ~LevelFilter() = default; LevelFilter(uint16 level) : m_level(level) {} virtual Map GetFiltered(const Map& source) override; virtual String GetName() const override; @@ -45,6 +46,7 @@ class FolderFilter : public SongFilter { public: FolderFilter(String folder, MapDatabase* database) : m_folder(folder), m_mapDatabase(database) {} + ~FolderFilter() = default; virtual Map GetFiltered(const Map& source); virtual String GetName() const override; virtual bool IsAll() const override; @@ -61,6 +63,8 @@ class CollectionFilter : public SongFilter { public: CollectionFilter(String collection, MapDatabase* database) : m_collection(collection), m_mapDatabase(database) {} + ~CollectionFilter() = default; + virtual Map GetFiltered(const Map& source); virtual String GetName() const override; virtual bool IsAll() const override; diff --git a/Main/include/SongSelect.hpp b/Main/include/SongSelect.hpp index e21690bf0..460809e7d 100644 --- a/Main/include/SongSelect.hpp +++ b/Main/include/SongSelect.hpp @@ -6,6 +6,9 @@ struct SongSelectIndex { +private: + FolderIndex* m_folder; + Vector m_charts; public: SongSelectIndex() = default; SongSelectIndex(FolderIndex* folder) @@ -44,9 +47,6 @@ struct SongSelectIndex FolderIndex* GetFolder() const { return m_folder; } Vector GetCharts() const { return m_charts; } -private: - FolderIndex* m_folder; - Vector m_charts; }; diff --git a/Main/include/SongSort.hpp b/Main/include/SongSort.hpp index 9ec3c5885..8ec288ee6 100644 --- a/Main/include/SongSort.hpp +++ b/Main/include/SongSort.hpp @@ -22,7 +22,7 @@ class SongSort { public: SongSort(String name, bool dir) : m_name(name),m_dir(dir) {}; - ~SongSort() = default; + virtual ~SongSort() = default; virtual void SortInplace(Vector& vec, const Map& collection) = 0; virtual SortType GetType() const = 0; diff --git a/Main/src/Application.cpp b/Main/src/Application.cpp index c2ef4e088..a1b27bb22 100644 --- a/Main/src/Application.cpp +++ b/Main/src/Application.cpp @@ -1095,6 +1095,11 @@ void Application::m_Cleanup() Discord_Shutdown(); + for(auto& id : g_guiState.nvgFonts) + { + + } + #ifdef EMBEDDED nvgDeleteGLES2(g_guiState.vg); #else @@ -2305,26 +2310,26 @@ bool JacketLoadingJob::Run() b.resize(response.text.length()); memcpy(b.data(), response.text.c_str(), b.size()); loadedImage = ImageRes::Create(b); - if (loadedImage.IsValid()) + if (loadedImage) { if (loadedImage->GetSize().x > w || loadedImage->GetSize().y > h) { loadedImage->ReSize({w, h}); } } - return loadedImage.IsValid(); + return loadedImage.get() != nullptr; } else { loadedImage = ImageRes::Create(imagePath); - if (loadedImage.IsValid()) + if (loadedImage) { if (loadedImage->GetSize().x > w || loadedImage->GetSize().y > h) { loadedImage->ReSize({w, h}); } } - return loadedImage.IsValid(); + return loadedImage.get() != nullptr; } } void JacketLoadingJob::Finalize() diff --git a/Main/src/AsyncAssetLoader.cpp b/Main/src/AsyncAssetLoader.cpp index 9269ebed6..d3b59638d 100644 --- a/Main/src/AsyncAssetLoader.cpp +++ b/Main/src/AsyncAssetLoader.cpp @@ -17,12 +17,12 @@ struct AsyncTextureLoadOperation : public AsyncLoadOperation bool AsyncLoad() { image = g_application->LoadImage(name); - return image.IsValid(); + return image.get() != nullptr; } bool AsyncFinalize() { target = TextureRes::Create(g_gl, image); - return target.IsValid(); + return target.get() != nullptr; } }; struct AsyncMeshLoadOperation : public AsyncLoadOperation @@ -55,7 +55,7 @@ struct AsyncMaterialLoadOperation : public AsyncLoadOperation } bool AsyncFinalize() { - return (target = g_application->LoadMaterial(name)).IsValid(); + return (target = g_application->LoadMaterial(name)).get() != nullptr; } }; struct AsyncWrapperOperation : public AsyncLoadOperation diff --git a/Main/src/Audio/AudioPlayback.cpp b/Main/src/Audio/AudioPlayback.cpp index 0b8a9bffd..4fc3a0cc6 100644 --- a/Main/src/Audio/AudioPlayback.cpp +++ b/Main/src/Audio/AudioPlayback.cpp @@ -69,7 +69,7 @@ bool AudioPlayback::Init(class BeatmapPlayback& playback, const String& mapRootP } } - if (m_fxtrack.IsValid()) { + if (m_fxtrack) { // Prevent loading switchables if fx track is in use. return true; } @@ -162,10 +162,10 @@ bool AudioPlayback::HasEnded() const void AudioPlayback::SetEffect(uint32 index, HoldObjectState* object, class BeatmapPlayback& playback) { // Don't use effects when using an FX track - if(m_fxtrack.IsValid()) + if(m_fxtrack) return; - assert(index >= 0 && index <= 1); + assert(index <= 1); m_CleanupDSP(m_buttonDSPs[index]); m_currentHoldEffects[index] = object; @@ -182,7 +182,7 @@ void AudioPlayback::SetEffect(uint32 index, HoldObjectState* object, class Beatm if (m_buttonEffects[index].type == EffectType::SwitchAudio) return; - dsp = m_buttonEffects[index].CreateDSP(m_GetDSPTrack().GetData(), *this); + dsp = m_buttonEffects[index].CreateDSP(m_GetDSPTrack().get(), *this); Logf("Set effect: %s", Logger::Severity::Debug, dsp->GetName()); if(dsp) @@ -197,7 +197,7 @@ void AudioPlayback::SetEffect(uint32 index, HoldObjectState* object, class Beatm } void AudioPlayback::SetEffectEnabled(uint32 index, bool enabled) { - assert(index >= 0 && index <= 1); + assert(index <= 1); m_effectMix[index] = enabled ? 1.0f : 0.0f; if (m_buttonEffects[index].type == EffectType::SwitchAudio) { @@ -212,7 +212,7 @@ void AudioPlayback::SetEffectEnabled(uint32 index, bool enabled) } void AudioPlayback::ClearEffect(uint32 index, HoldObjectState* object) { - assert(index >= 0 && index <= 1); + assert(index <= 1); if(m_currentHoldEffects[index] == object) { m_CleanupDSP(m_buttonDSPs[index]); @@ -249,10 +249,10 @@ void AudioPlayback::SetLaserFilterInput(float input, bool active) if(!m_laserDSP) { // Don't use Bitcrush effects over FX track - if(m_fxtrack.IsValid() && m_laserEffectType == EffectType::Bitcrush) + if(m_fxtrack && m_laserEffectType == EffectType::Bitcrush) return; - m_laserDSP = m_laserEffect.CreateDSP(m_GetDSPTrack().GetData(), *this); + m_laserDSP = m_laserEffect.CreateDSP(m_GetDSPTrack().get(), *this); if(!m_laserDSP) { Logf("Failed to create laser DSP with type %d", Logger::Severity::Warning, m_laserEffect.type); @@ -287,8 +287,7 @@ float AudioPlayback::GetLaserEffectMix() const } Ref AudioPlayback::m_GetDSPTrack() { - if(m_fxtrack) - return m_fxtrack; + if(m_fxtrack) return m_fxtrack; return m_music; } void AudioPlayback::SetFXTrackEnabled(bool enabled) @@ -310,12 +309,12 @@ void AudioPlayback::SetFXTrackEnabled(bool enabled) } m_fxtrackEnabled = enabled; } -void AudioPlayback::SetSwitchableTrackEnabled(int index, bool enabled) +void AudioPlayback::SetSwitchableTrackEnabled(size_t index, bool enabled) { - if (m_fxtrack.IsValid()) + if (m_fxtrack) return; - assert(index >= 0 && index < m_switchables.size()); + assert(index < m_switchables.size()); int32 disableTrack = -1; int32 enableTrack = -1; @@ -346,7 +345,7 @@ void AudioPlayback::SetSwitchableTrackEnabled(int index, bool enabled) } void AudioPlayback::ResetSwitchableTracks() { - for (int i = 0; i < m_switchables.size(); ++i) + for (size_t i = 0; i < m_switchables.size(); ++i) { if (m_switchables[i].m_audio) m_switchables[i].m_audio->SetVolume(0.0f); @@ -472,6 +471,8 @@ void AudioPlayback::m_SetLaserEffectParameter(float input) rt->SetLength(actualLength); break; } + default: + break; } } diff --git a/Main/src/Audio/GameAudioEffects.cpp b/Main/src/Audio/GameAudioEffects.cpp index 2085b70c2..0f1296d7b 100644 --- a/Main/src/Audio/GameAudioEffects.cpp +++ b/Main/src/Audio/GameAudioEffects.cpp @@ -39,6 +39,8 @@ DSP* GameAudioEffect::CreateDSP(class AudioBase* audioTrack, AudioPlayback& play { // Don't set anthing for biquad Filters BQFDSP* bqfDSP = new BQFDSP(); + + audioTrack->AddDSP(bqfDSP); ret = bqfDSP; break; @@ -121,6 +123,8 @@ DSP* GameAudioEffect::CreateDSP(class AudioBase* audioTrack, AudioPlayback& play ret = ps; break; } + default: + break; } if(!ret) @@ -196,5 +200,7 @@ void GameAudioEffect::SetParams(DSP* dsp, AudioPlayback& playback, HoldObjectSta ps->amount = (float)object->effectParams[0]; break; } + default: + break; } } diff --git a/Main/src/Background.cpp b/Main/src/Background.cpp index 483be47f8..1143c9018 100644 --- a/Main/src/Background.cpp +++ b/Main/src/Background.cpp @@ -97,7 +97,7 @@ class TestBackground : public FullscreenBackground String skin = g_gameConfig.GetString(GameConfigKeys::Skin); lua = luaL_newstate(); - auto openLib = [this](char* name, lua_CFunction lib) + auto openLib = [this](const char* name, lua_CFunction lib) { luaL_requiref(lua, name, lib, 1); lua_pop(lua, 1); @@ -191,7 +191,6 @@ class TestBackground : public FullscreenBackground clearTransition = Math::Clamp(clearTransition, 0.0f, 1.0f); - Vector3 trackEndWorld = Vector3(0.0f, 25.0f, 0.0f); Vector2i screenCenter = game->GetCamera().GetScreenCenter(); tilt = { game->GetCamera().GetActualRoll(), game->GetCamera().GetBackgroundSpin() }; diff --git a/Main/src/Camera.cpp b/Main/src/Camera.cpp index fdde6f94d..bbbfc65f7 100755 --- a/Main/src/Camera.cpp +++ b/Main/src/Camera.cpp @@ -279,7 +279,7 @@ void Camera::SetSlowTilt(bool tilt) void Camera::SetSlamAmount(uint32 index, float amount) { - assert(index >= 0 && index <= 1); + assert(index <= 1); if (m_slamDuration != 0) { m_slamRoll[index] = amount; @@ -289,19 +289,19 @@ void Camera::SetSlamAmount(uint32 index, float amount) void Camera::SetRollIgnore(uint32 index, bool slam) { - assert(index >= 0 && index <= 1); + assert(index <= 1); m_rollIgnoreTimer[index] = m_rollIgnoreDuration + (slam ? m_slamDuration : 0); } float Camera::GetRollIgnoreTimer(uint32 index) { - assert(index >= 0 && index <= 1); + assert(index <= 1); return m_rollIgnoreTimer[index]; } float Camera::GetSlamAmount(uint32 index) { - assert(index >= 0 && index <= 1); + assert(index <= 1); return m_slamRoll[index]; } @@ -338,11 +338,6 @@ Vector2 Camera::Project(const Vector3& pos) return screenSpace.xy(); } -static float Lerp(float a, float b, float alpha) -{ - return a + (b - a) * alpha; -} - RenderState Camera::CreateRenderState(bool clipped) { int portrait = g_aspectRatio > 1 ? 0 : 1; diff --git a/Main/src/ChatOverlay.cpp b/Main/src/ChatOverlay.cpp index 8e321413c..cd4b10ab0 100644 --- a/Main/src/ChatOverlay.cpp +++ b/Main/src/ChatOverlay.cpp @@ -43,8 +43,9 @@ bool ChatOverlay::Init() void ChatOverlay::InitNuklearIfNeeded() { - if (m_nuklearRunning) + if (m_nuklearRunning) { return; + } m_nctx = nk_sdl_init((SDL_Window*)g_gameWindow->Handle()); g_gameWindow->OnAnyEvent.Add(this, &ChatOverlay::UpdateNuklearInput); @@ -53,22 +54,22 @@ void ChatOverlay::InitNuklearIfNeeded() nk_sdl_font_stash_begin(&atlas); struct nk_font *fallback = nk_font_atlas_add_from_file(atlas, Path::Normalize( Path::Absolute("fonts/settings/NotoSans-Regular.ttf")).c_str(), 24, 0); - struct nk_font_config cfg_kr = nk_font_config(24); - cfg_kr.merge_mode = nk_true; - cfg_kr.range = nk_font_korean_glyph_ranges(); - - NK_STORAGE const nk_rune jp_ranges[] = { - 0x0020, 0x00FF, - 0x3000, 0x303f, - 0x3040, 0x309f, - 0x30a0, 0x30ff, - 0x4e00, 0x9faf, - 0xff00, 0xffef, - 0 - }; - struct nk_font_config cfg_jp = nk_font_config(24); - cfg_jp.merge_mode = nk_true; - cfg_jp.range = jp_ranges; + // struct nk_font_config cfg_kr = nk_font_config(24); + // cfg_kr.merge_mode = nk_true; + // cfg_kr.range = nk_font_korean_glyph_ranges(); + + // NK_STORAGE const nk_rune jp_ranges[] = { + // 0x0020, 0x00FF, + // 0x3000, 0x303f, + // 0x3040, 0x309f, + // 0x30a0, 0x30ff, + // 0x4e00, 0x9faf, + // 0xff00, 0xffef, + // 0 + // }; + // struct nk_font_config cfg_jp = nk_font_config(24); + // cfg_jp.merge_mode = nk_true; + // cfg_jp.range = jp_ranges; NK_STORAGE const nk_rune cjk_ranges[] = { 0x0020, 0x00FF, diff --git a/Main/src/DownloadScreen.cpp b/Main/src/DownloadScreen.cpp index 349bc05e7..cf410be79 100644 --- a/Main/src/DownloadScreen.cpp +++ b/Main/src/DownloadScreen.cpp @@ -392,6 +392,7 @@ bool DownloadScreen::m_extractFile(archive * a, String path) f.Write(buff, size); } f.Close(); + return true; } //https://stackoverflow.com/a/6142700 @@ -466,7 +467,7 @@ int DownloadScreen::m_PlayPreview(lua_State* L) // Try to play the preview Ref previewAudio = g_audio->CreateStream(preview_path); - if (previewAudio && previewAudio.GetData()) + if (previewAudio && previewAudio.get()) { m_previewPlayer.FadeTo(previewAudio, 0); } diff --git a/Main/src/Game.cpp b/Main/src/Game.cpp index dd364d515..0378f94ac 100755 --- a/Main/src/Game.cpp +++ b/Main/src/Game.cpp @@ -454,7 +454,7 @@ class Game_Impl : public Game std::shuffle(swaps.begin(), swaps.end(), std::default_random_engine((int)(1000 * g_application->GetAppTime()))); bool unchanged = true; - for (size_t i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) { if (swaps[i] != i) { @@ -555,14 +555,14 @@ class Game_Impl : public Game { if(m_laserFollowEmitters[i]) { - m_laserFollowEmitters[i].Release(); + m_laserFollowEmitters[i].reset(); } } for(uint32 i = 0; i < 6; i++) { if(m_holdEmitters[i]) { - m_holdEmitters[i].Release(); + m_holdEmitters[i].reset(); } } @@ -595,7 +595,7 @@ class Game_Impl : public Game else { if(m_lockMouse) - m_lockMouse.Release(); + m_lockMouse.reset(); g_gameWindow->SetCursorVisible(true); } } @@ -803,8 +803,7 @@ class Game_Impl : public Game glFlush(); // Set laser follow particle visiblity - if ((particleMaterial.IsValid() && basicParticleTexture.IsValid()) && - (particleMaterial.GetData() && basicParticleTexture.GetData())) + if (particleMaterial && particleMaterial) { for (uint32 i = 0; i < 2; i++) { @@ -824,7 +823,7 @@ class Game_Impl : public Game { if (m_laserFollowEmitters[i]) { - m_laserFollowEmitters[i].Release(); + m_laserFollowEmitters[i].reset(); } } } @@ -846,7 +845,7 @@ class Game_Impl : public Game { if (m_holdEmitters[i]) { - m_holdEmitters[i].Release(); + m_holdEmitters[i].reset(); } } @@ -884,8 +883,7 @@ class Game_Impl : public Game NVG_FLUSH(); // Render particle effects last - if ((particleMaterial.IsValid() && basicParticleTexture.IsValid()) && - (particleMaterial.GetData() && basicParticleTexture.GetData())) + if (particleMaterial && basicParticleTexture) { RenderParticles(rs, deltaTime); glFlush(); @@ -1015,7 +1013,7 @@ class Game_Impl : public Game auto samples = m_beatmap->GetSamplePaths(); m_fxSamples = new Sample[samples.size()]; - for (int i = 0; i < samples.size(); i++) + for (size_t i = 0; i < samples.size(); i++) { if (default_sfx.Contains(samples[i])) { @@ -1407,8 +1405,6 @@ class Game_Impl : public Game if(m_scoring.autoplay) textPos.y += RenderText("Autoplay enabled", textPos, Color::Blue).y; - // List recent hits and their delay - Vector2 tableStart = textPos; uint32 hitsShown = 0; // Show all hit debug info on screen (up to a maximum) for(auto it = m_scoring.hitStats.rbegin(); it != m_scoring.hitStats.rend(); it++) @@ -1554,8 +1550,7 @@ class Game_Impl : public Game // Create hit effect particle Color hitColor = (buttonIdx < 4) ? Color::White : Color::FromHSV(20, 0.7f, 1.0f); float hitWidth = (buttonIdx < 4) ? m_track->buttonWidth : m_track->fxbuttonWidth; - if ((particleMaterial.IsValid() && basicParticleTexture.IsValid()) && - (particleMaterial.GetData() && basicParticleTexture.GetData())) + if (particleMaterial && basicParticleTexture) { Ref emitter = CreateHitEmitter(hitColor, hitWidth); emitter->position.x = m_track->GetButtonPlacement(buttonIdx); diff --git a/Main/src/GameplaySettingsDialog.cpp b/Main/src/GameplaySettingsDialog.cpp index 717850b90..f64d3b02a 100644 --- a/Main/src/GameplaySettingsDialog.cpp +++ b/Main/src/GameplaySettingsDialog.cpp @@ -25,10 +25,10 @@ GameplaySettingsDialog::~GameplaySettingsDialog() template GameplaySettingsDialog::Setting GameplaySettingsDialog::m_CreateEnumSetting(GameConfigKeys key, String name) { - Setting s = std::make_unique(SettingData({ - name, - SettingType::Enum, - })); + Setting s = std::make_unique(); + + s->name = name; + s->type = SettingType::Enum; EnumStringMap nameMap = EnumClass::GetMap(); for (auto it = nameMap.begin(); it != nameMap.end(); it++) @@ -54,10 +54,9 @@ GameplaySettingsDialog::Setting GameplaySettingsDialog::m_CreateEnumSetting(Game GameplaySettingsDialog::Setting GameplaySettingsDialog::m_CreateFloatSetting(GameConfigKeys key, String name, Vector2 range, float mult) { - Setting s = std::make_unique(SettingData({ - name, - SettingType::Floating, - })); + Setting s = std::make_unique(); + s->name = name; + s->type = SettingType::Floating; auto getter = [key](float& value) { value = g_gameConfig.GetFloat(key); @@ -78,10 +77,9 @@ GameplaySettingsDialog::Setting GameplaySettingsDialog::m_CreateFloatSetting(Gam GameplaySettingsDialog::Setting GameplaySettingsDialog::m_CreateIntSetting(GameConfigKeys key, String name, Vector2i range) { - Setting s = std::make_unique(SettingData({ - name, - SettingType::Integer, - })); + Setting s = std::make_unique(); + s->name = name; + s->type = SettingType::Integer; auto getter = [key](int& value) { value = g_gameConfig.GetInt(key); @@ -101,11 +99,10 @@ GameplaySettingsDialog::Setting GameplaySettingsDialog::m_CreateIntSetting(GameC GameplaySettingsDialog::Setting GameplaySettingsDialog::m_CreateToggleSetting(GameConfigKeys key, String name) { - Setting s = std::make_unique(SettingData({ - name, - SettingType::Toggle, - })); + Setting s = std::make_unique(); + s->name = name; + s->type = SettingType::Toggle; auto getter = [key](bool& value) { value = g_gameConfig.GetBool(key); @@ -450,22 +447,26 @@ void GameplaySettingsDialog::m_ChangeStepSetting(int steps) switch (currentSetting->type) { - case SettingType::Integer: - currentSetting->intSetting.val = Math::Clamp(currentSetting->intSetting.val + steps, - currentSetting->intSetting.min, - currentSetting->intSetting.max); - currentSetting->intSetting.setter.Call(currentSetting->intSetting.val); - break; - case SettingType::Toggle: - currentSetting->boolSetting.val = !currentSetting->boolSetting.val; - currentSetting->boolSetting.setter.Call(currentSetting->boolSetting.val); - break; - case SettingType::Enum: - int size = currentSetting->enumSetting.options.size(); - AdvanceLooping(currentSetting->enumSetting.val, steps, size); - String &newVal = currentSetting->enumSetting.options.at(currentSetting->enumSetting.val); - currentSetting->enumSetting.setter.Call(newVal); - break; + case SettingType::Integer: + currentSetting->intSetting.val = Math::Clamp(currentSetting->intSetting.val + steps, + currentSetting->intSetting.min, + currentSetting->intSetting.max); + currentSetting->intSetting.setter.Call(currentSetting->intSetting.val); + break; + case SettingType::Toggle: + currentSetting->boolSetting.val = !currentSetting->boolSetting.val; + currentSetting->boolSetting.setter.Call(currentSetting->boolSetting.val); + break; + case SettingType::Enum: + { + int size = currentSetting->enumSetting.options.size(); + AdvanceLooping(currentSetting->enumSetting.val, steps, size); + String &newVal = currentSetting->enumSetting.options.at(currentSetting->enumSetting.val); + currentSetting->enumSetting.setter.Call(newVal); + } + break; + case SettingType::Floating: + break; } } @@ -491,5 +492,7 @@ void GameplaySettingsDialog::m_OnKeyPressed(SDL_Scancode code) case SDL_SCANCODE_DOWN: m_AdvanceSelection(1); break; + default: + break; } } \ No newline at end of file diff --git a/Main/src/Input.cpp b/Main/src/Input.cpp index d85dd1dd8..f6d4ae0fd 100644 --- a/Main/src/Input.cpp +++ b/Main/src/Input.cpp @@ -68,7 +68,7 @@ void Input::Cleanup() { m_gamepad->OnButtonPressed.RemoveAll(this); m_gamepad->OnButtonReleased.RemoveAll(this); - m_gamepad.Release(); + m_gamepad.reset(); } if(m_window) { @@ -83,7 +83,7 @@ void Input::Update(float deltaTime) { for(auto it = m_mouseLocks.begin(); it != m_mouseLocks.end();) { - if(it->GetRefCount() == 1) + if(it->use_count() == 1) { it = m_mouseLocks.erase(it); continue; @@ -105,7 +105,7 @@ void Input::Update(float deltaTime) { for(uint32 i = 0; i < 2; i++) { - if(m_mouseAxisMapping[i] < 0 || m_mouseAxisMapping[i] > 1) + if(m_mouseAxisMapping[i] > 1) { // INVALID MAPPING m_laserStates[i] = 0.0f; diff --git a/Main/src/LaserTrackBuilder.cpp b/Main/src/LaserTrackBuilder.cpp index e15d74ad0..8f3e8fd9a 100644 --- a/Main/src/LaserTrackBuilder.cpp +++ b/Main/src/LaserTrackBuilder.cpp @@ -93,7 +93,7 @@ Mesh LaserTrackBuilder::GenerateTrackMesh(class BeatmapPlayback& playback, Laser leftSide.size.x = realBorderSize; leftSide.pos.x = leftCap.Left(); - Rect sideUv = Rect(0.0f, textureBorder, textureBorder, invTextureBorder); + //Rect sideUv = Rect(0.0f, textureBorder, textureBorder, invTextureBorder); Rect capUv = Rect(0.0f, 0.0f, invTextureBorder, textureBorder); // Cap at the top Vector leftVerts; if(swapped) @@ -134,7 +134,7 @@ Mesh LaserTrackBuilder::GenerateTrackMesh(class BeatmapPlayback& playback, Laser rightSide.size.x = realBorderSize; rightSide.pos.x = rightCenter.Right(); - Rect sideUv = Rect(invTextureBorder, textureBorder, 1.0f, invTextureBorder); + //Rect sideUv = Rect(invTextureBorder, textureBorder, 1.0f, invTextureBorder); Rect capUv = Rect(textureBorder, invTextureBorder, 1.0f, 1.0f); // Cap at the bottom Vector rightVerts; if(swapped) diff --git a/Main/src/MultiplayerScreen.cpp b/Main/src/MultiplayerScreen.cpp index 3d444b0c3..05814cd81 100644 --- a/Main/src/MultiplayerScreen.cpp +++ b/Main/src/MultiplayerScreen.cpp @@ -428,7 +428,7 @@ ChartIndex* MultiplayerScreen::m_getChartByHash(const String& hash, const String { ChartIndex* newChart = NULL; - for (int ind = 0; ind < folder.second->charts.size(); ind++) + for (size_t ind = 0; ind < folder.second->charts.size(); ind++) { ChartIndex* chart = folder.second->charts[ind]; if (chart->level == level) @@ -468,7 +468,7 @@ ChartIndex* MultiplayerScreen::m_getChartByShortPath(const String& path, uint32* { ChartIndex* newChart = NULL; - for (int ind = 0; ind < folder.second->charts.size(); ind++) + for (size_t ind = 0; ind < folder.second->charts.size(); ind++) { ChartIndex* chart = folder.second->charts[ind]; @@ -564,7 +564,7 @@ void MultiplayerScreen::m_changeDifficulty(int offset) FolderIndex* folder = m_mapDatabase->GetFolder(this->m_selectedMapId); int oldDiff = this->m_selectedDiffIndex; int newInd = this->m_selectedDiffIndex + offset; - if (newInd < 0 || newInd >= folder->charts.size()) + if (newInd < 0 || newInd >= (int)folder->charts.size()) { return; } @@ -595,7 +595,7 @@ void MultiplayerScreen::GetMapBPMForSpeed(String path, struct MultiplayerBPMInf { Logf("Couldn't find map at %s", Logger::Severity::Error, path); - info = { 0 }; + info = { 0, 0, 0, 0 }; return; } @@ -606,14 +606,14 @@ void MultiplayerScreen::GetMapBPMForSpeed(String path, struct MultiplayerBPMInf { Logf("Could not read path for beatmap: %s", Logger::Severity::Error, path); delete newMap; - info = { 0 }; + info = { 0, 0, 0, 0 }; return; } FileReader reader(mapFile); if (!newMap->Load(reader)) { delete newMap; - info = { 0 }; + info = { 0, 0, 0, 0 }; return; } @@ -864,7 +864,7 @@ void MultiplayerScreen::Tick(float deltaTime) else { if (m_lockMouse) - m_lockMouse.Release(); + m_lockMouse.reset(); g_gameWindow->SetCursorVisible(true); } @@ -1351,7 +1351,7 @@ void MultiplayerScreen::OnSuspend() m_mapDatabase->StopSearching(); if (m_lockMouse) - m_lockMouse.Release(); + m_lockMouse.reset(); } bool MultiplayerScreen::IsSyncing() @@ -1487,7 +1487,7 @@ void MultiplayerScreen::m_updatePreview(ChartIndex* diff, bool mapChanged) if (newPreview) { Ref previewAudio = g_audio->CreateStream(audioPath); - if (previewAudio && previewAudio.GetData()) + if (previewAudio) { previewAudio->SetPosition(diff->preview_offset); diff --git a/Main/src/ScoreScreen.cpp b/Main/src/ScoreScreen.cpp index a11ecbfdc..f86d58d2e 100644 --- a/Main/src/ScoreScreen.cpp +++ b/Main/src/ScoreScreen.cpp @@ -112,11 +112,11 @@ class ScoreScreen_Impl : public ScoreScreen m_displayIndex += (button == Input::Button::FX_0) ? -1 : 1; - if (m_displayIndex >= m_stats->size()) + if (m_displayIndex >= (int)m_stats->size()) m_displayIndex = 0; if (m_displayIndex < 0) - m_displayIndex = m_stats->size() - 1; + m_displayIndex = (int)m_stats->size() - 1; loadScoresFromMultiplayer(); updateLuaData(); @@ -169,7 +169,7 @@ class ScoreScreen_Impl : public ScoreScreen } void loadScoresFromMultiplayer() { - if (m_displayIndex >= m_stats->size()) + if (m_displayIndex >= (int)m_stats->size()) return; const nlohmann::json& data= (*m_stats)[m_displayIndex]; @@ -243,7 +243,7 @@ class ScoreScreen_Impl : public ScoreScreen m_playerId = uid; // Show the player's score first - for (int i=0; isize(); i++) + for (size_t i=0; isize(); i++) { if (m_playerId == (*m_stats)[i].value("uid", "")) { @@ -572,7 +572,7 @@ class ScoreScreen_Impl : public ScoreScreen AutoScoreScreenshotSettings screensetting = g_gameConfig.GetEnum(GameConfigKeys::AutoScoreScreenshot); if (screensetting == AutoScoreScreenshotSettings::Always || (screensetting == AutoScoreScreenshotSettings::Highscore && m_highScores.empty()) || - (screensetting == AutoScoreScreenshotSettings::Highscore && m_score > m_highScores.front()->score)) + (screensetting == AutoScoreScreenshotSettings::Highscore && m_score > (uint32)m_highScores.front()->score)) { Capture(); } @@ -585,10 +585,10 @@ class ScoreScreen_Impl : public ScoreScreen m_showStats = g_input.GetButton(Input::Button::FX_0); // Check for new scores - if (m_multiplayer && m_numPlayersSeen != m_stats->size()) + if (m_multiplayer && m_numPlayersSeen != (int)m_stats->size()) { // Reselect the player we were looking at before - for (int i = 0; i < m_stats->size(); i++) + for (size_t i = 0; i < m_stats->size(); i++) { if (m_displayId == static_cast((*m_stats)[i].value("uid", ""))) { @@ -667,7 +667,7 @@ class ScoreScreen_Impl : public ScoreScreen Image screenshot = ImageRes::Screenshot(g_gl, size, { x,y }); String screenshotPath = "screenshots/" + Shared::Time::Now().ToString() + ".png"; screenshot->SavePNG(screenshotPath); - screenshot.Release(); + screenshot.reset(); lua_getglobal(m_lua, "screenshot_captured"); if (lua_isfunction(m_lua, -1)) diff --git a/Main/src/Scoring.cpp b/Main/src/Scoring.cpp index 43f817fdc..57e7f6915 100755 --- a/Main/src/Scoring.cpp +++ b/Main/src/Scoring.cpp @@ -241,7 +241,7 @@ float Scoring::GetLaserPosition(uint32 index, float pos) float Scoring::GetLaserRollOutput(uint32 index) { - assert(index >= 0 && index <= 1); + assert(index <= 1); // Ignore slams that are the last segment since Camera handles slam behaviour if (m_currentLaserSegments[index] && !(m_currentLaserSegments[index]->flags & LaserObjectState::flag_Instant && !m_currentLaserSegments[index]->next)) @@ -786,7 +786,7 @@ ObjectState* Scoring::m_ConsumeTick(uint32 buttonCode) { HoldObjectState* hos = (HoldObjectState*)hitObject; hos = hos->GetRoot(); - if (hos->time - Scoring::goodHitTime <= currentTime + m_inputOffset) + if (hos->time - Scoring::goodHitTime <= currentTime + (MapTime)m_inputOffset) m_SetHoldObject(hitObject, buttonCode); return nullptr; } @@ -1031,7 +1031,7 @@ void Scoring::m_UpdateLasers(float deltaTime) if ((currentSegment->time + currentSegment->duration) < mapTime) { auto currentTicks = m_ticks[6 + i]; - if (currentSegment->flags & LaserObjectState::flag_Instant == 0 + if ((currentSegment->flags & LaserObjectState::flag_Instant) == 0 || currentTicks.empty() || (LaserObjectState*)currentTicks.front()->object != currentSegment) // Don't null slam that hasn't been judged yet { @@ -1069,7 +1069,6 @@ void Scoring::m_UpdateLasers(float deltaTime) m_laserInput[i] = autoplay ? 0.0f : m_input->GetInputLaserDir(i); - bool notAffectingGameplay = true; if (currentSegment) { // Update laser gameplay @@ -1101,7 +1100,7 @@ void Scoring::m_UpdateLasers(float deltaTime) { laserPositions[i] = Math::Min(laserPositions[i] + input, laserTargetPositions[i]); } - else if (laserDir < 0 && positionDelta > 0 || laserDir > 0 && positionDelta < 0) + else if ((laserDir < 0 && positionDelta > 0) || (laserDir > 0 && positionDelta < 0)) { laserPositions[i] = laserPositions[i] + input; } @@ -1114,7 +1113,6 @@ void Scoring::m_UpdateLasers(float deltaTime) } - notAffectingGameplay = false; float punishMult = 1.0f; //if next segment is the opposite direction then allow for some extra wrong turning @@ -1190,11 +1188,10 @@ void Scoring::m_OnButtonPressed(Input::Button buttonCode) } else if (buttonCode > Input::Button::BT_S) { - ObjectState* obj = nullptr; if (buttonCode < Input::Button::LS_1Neg) - obj = m_ConsumeTick(6); // Laser L + m_ConsumeTick(6); // Laser L else - obj = m_ConsumeTick(7); // Laser R + m_ConsumeTick(7); // Laser R } } void Scoring::m_OnButtonReleased(Input::Button buttonCode) @@ -1216,7 +1213,7 @@ void Scoring::m_OnButtonReleased(Input::Button buttonCode) MapTotals Scoring::CalculateMapTotals() const { - MapTotals ret = { 0 }; + MapTotals ret = { 0, 0, 0 }; const Beatmap& map = m_playback->GetBeatmap(); Set processedLasers; diff --git a/Main/src/SettingsScreen.cpp b/Main/src/SettingsScreen.cpp index cd82956cd..ed3f116d7 100644 --- a/Main/src/SettingsScreen.cpp +++ b/Main/src/SettingsScreen.cpp @@ -64,8 +64,7 @@ static void nk_sdl_text(nk_flags event) static int nk_get_property_state(struct nk_context *ctx, const char *name) { - if (!ctx || !ctx->current || !ctx->current->layout) - return NK_PROPERTY_DEFAULT; + if (!ctx || !ctx->current || !ctx->current->layout) return NK_PROPERTY_DEFAULT; struct nk_window* win = ctx->current; nk_hash hash = 0; if (name[0] == '#') { @@ -443,22 +442,22 @@ class SettingsScreen_Impl : public SettingsScreen nk_sdl_font_stash_begin(&atlas); struct nk_font *fallback = nk_font_atlas_add_from_file(atlas, Path::Normalize( Path::Absolute("fonts/settings/NotoSans-Regular.ttf")).c_str(), 24, 0); - struct nk_font_config cfg_kr = nk_font_config(24); - cfg_kr.merge_mode = nk_true; - cfg_kr.range = nk_font_korean_glyph_ranges(); - - NK_STORAGE const nk_rune jp_ranges[] = { - 0x0020, 0x00FF, - 0x3000, 0x303f, - 0x3040, 0x309f, - 0x30a0, 0x30ff, - 0x4e00, 0x9faf, - 0xff00, 0xffef, - 0 - }; - struct nk_font_config cfg_jp = nk_font_config(24); - cfg_jp.merge_mode = nk_true; - cfg_jp.range = jp_ranges; + // struct nk_font_config cfg_kr = nk_font_config(24); + // cfg_kr.merge_mode = nk_true; + // cfg_kr.range = nk_font_korean_glyph_ranges(); + + // NK_STORAGE const nk_rune jp_ranges[] = { + // 0x0020, 0x00FF, + // 0x3000, 0x303f, + // 0x3040, 0x309f, + // 0x30a0, 0x30ff, + // 0x4e00, 0x9faf, + // 0xff00, 0xffef, + // 0 + // }; + // struct nk_font_config cfg_jp = nk_font_config(24); + // cfg_jp.merge_mode = nk_true; + // cfg_jp.range = jp_ranges; NK_STORAGE const nk_rune cjk_ranges[] = { 0x0020, 0x00FF, @@ -960,7 +959,7 @@ class ButtonBindingScreen_Impl : public ButtonBindingScreen if (m_completed && m_gamepad) { m_gamepad->OnButtonPressed.RemoveAll(this); - m_gamepad.Release(); + m_gamepad.reset(); g_application->RemoveTickable(this); } @@ -1190,7 +1189,7 @@ bool SkinSettingsScreen::StringSelectionSetting(String key, String label, SkinSe selection = 0; auto prevSelection = selection; Vector displayData; - for (size_t i = 0; i < setting.selectionSetting.numOptions; i++) + for (int i = 0; i < setting.selectionSetting.numOptions; i++) { displayData.Add(*setting.selectionSetting.options[i]); } diff --git a/Main/src/SkinConfig.cpp b/Main/src/SkinConfig.cpp index a33af210d..9bf717780 100644 --- a/Main/src/SkinConfig.cpp +++ b/Main/src/SkinConfig.cpp @@ -109,7 +109,7 @@ SkinConfig::SkinConfig(String skin) newsetting.selectionSetting.def = strdup(*def); newsetting.selectionSetting.numOptions = values.at("values").size(); newsetting.selectionSetting.options = new String[newsetting.selectionSetting.numOptions]; - for (size_t i = 0; i < newsetting.selectionSetting.numOptions; i++) + for (int i = 0; i < newsetting.selectionSetting.numOptions; i++) { values.at("values").at(i).get_to(newsetting.selectionSetting.options[i]); } @@ -142,6 +142,7 @@ SkinConfig::SkinConfig(String skin) break; case SkinSetting::Type::Color: + { values.at("default").get_to(def); ColorConfigEntry ce; ce.FromString(def); @@ -154,6 +155,9 @@ SkinConfig::SkinConfig(String skin) { newsetting.colorSetting.hsv = false; } + } + break; + default: break; } m_settings.Add(newsetting); @@ -243,6 +247,8 @@ void SkinConfig::InitDefaults() case SkinSetting::Type::Color: Set(setting.key, *setting.colorSetting.def); break; + default: + break; } } diff --git a/Main/src/SongSelect.cpp b/Main/src/SongSelect.cpp index 11bfea367..76c0da249 100644 --- a/Main/src/SongSelect.cpp +++ b/Main/src/SongSelect.cpp @@ -125,7 +125,7 @@ void PreviewPlayer::FadeTo(Ref stream, int32 restartPos /* = -1 */) m_fadeDelayTimer = 0.0f; m_nextStream = stream; m_nextRestartPos = restartPos; - stream.Release(); + stream.reset(); } void PreviewPlayer::Update(float deltaTime) { @@ -155,7 +155,7 @@ void PreviewPlayer::Update(float deltaTime) if (m_fadeOutTimer >= m_fadeDuration) if (m_currentStream) - m_currentStream.Release(); + m_currentStream.reset(); } if (m_fadeDelayTimer >= m_fadeDelayDuration && m_fadeInTimer < m_fadeDuration) @@ -166,7 +166,7 @@ void PreviewPlayer::Update(float deltaTime) m_currentStream = m_nextStream; if (m_currentStream) m_currentStream->SetVolume(1.0f); - m_nextStream.Release(); + m_nextStream.reset(); m_currentRestartPos = m_nextRestartPos; } else @@ -402,7 +402,7 @@ class SelectionWheel { for (const auto &it : m_SourceCollection()) { - if (it.second.GetFolder()->id == id) + if (it.second.GetFolder()->id == (int32)id) { SelectMapByMapIndex(it.first); break; @@ -472,7 +472,7 @@ class SelectionWheel return foundSortIndex; } - void AdvanceSelection(uint32 offset) + void AdvanceSelection(int32 offset) { uint32 vecLen = m_sortVec.size(); if (vecLen == 0) @@ -483,7 +483,7 @@ class SelectionWheel { newIndex += vecLen; } - if (newIndex >= vecLen) // Rolled over + if ((uint32)newIndex >= vecLen) // Rolled over { newIndex -= vecLen; } @@ -1181,26 +1181,45 @@ class SortSolection g_gameConfig.Set(GameConfigKeys::LastSort, m_selection); for (SongSort *s : m_sorts) { - TitleSort *t = (TitleSort *)s; - ScoreSort *sc = (ScoreSort *)s; - DateSort *d = (DateSort *)s; - switch (s->GetType()) - { - case TITLE_ASC: - case TITLE_DESC: - delete t; - break; - case SCORE_DESC: - case SCORE_ASC: - delete sc; - break; - case DATE_DESC: - case DATE_ASC: - delete d; - break; - } + delete s; + // TitleSort *t = (TitleSort *)s; + // ScoreSort *sc = (ScoreSort *)s; + // DateSort *d = (DateSort *)s; + // EffectorSort *e = (EffectorSort *)s; + // ArtistSort* a = (ArtistSort*)s; + // switch (s->GetType()) + // { + // case TITLE_ASC: + // case TITLE_DESC: + // delete t; + // break; + // case SCORE_DESC: + // case SCORE_ASC: + // delete sc; + // break; + // case DATE_DESC: + // case DATE_ASC: + // delete d; + // break; + // case EFFECTOR_DESC: + // case EFFECTOR_ASC: + // delete e; + // break; + // case ARTIST_ASC: + // case ARTIST_DESC: + // delete a; + // break; + // default: + // break; + // } } m_sorts.clear(); + + if (m_lua) + { + g_application->DisposeLua(m_lua); + m_lua = nullptr; + } } bool Init() @@ -1397,7 +1416,7 @@ class SongSelect_Impl : public SongSelect String m_getCurrentChartName() { - + return String(); } void m_SetCurrentChartOffset(int newValue) @@ -1432,12 +1451,12 @@ class SongSelect_Impl : public SongSelect m_filterSelection->SetMapDB(m_mapDatabase); - m_mapDatabase->OnFoldersAdded.Add(m_selectionWheel.GetData(), &SelectionWheel::OnFoldersAdded); - m_mapDatabase->OnFoldersUpdated.Add(m_selectionWheel.GetData(), &SelectionWheel::OnFoldersUpdated); - m_mapDatabase->OnFoldersCleared.Add(m_selectionWheel.GetData(), &SelectionWheel::OnFoldersCleared); - m_mapDatabase->OnFoldersRemoved.Add(m_selectionWheel.GetData(), &SelectionWheel::OnFoldersRemoved); - m_mapDatabase->OnSearchStatusUpdated.Add(m_selectionWheel.GetData(), &SelectionWheel::OnSearchStatusUpdated); - m_selectionWheel->OnSongsChanged.Add(m_filterSelection.GetData(), &FilterSelection::OnSongsChanged); + m_mapDatabase->OnFoldersAdded.Add(m_selectionWheel.get(), &SelectionWheel::OnFoldersAdded); + m_mapDatabase->OnFoldersUpdated.Add(m_selectionWheel.get(), &SelectionWheel::OnFoldersUpdated); + m_mapDatabase->OnFoldersCleared.Add(m_selectionWheel.get(), &SelectionWheel::OnFoldersCleared); + m_mapDatabase->OnFoldersRemoved.Add(m_selectionWheel.get(), &SelectionWheel::OnFoldersRemoved); + m_mapDatabase->OnSearchStatusUpdated.Add(m_selectionWheel.get(), &SelectionWheel::OnSearchStatusUpdated); + m_selectionWheel->OnSongsChanged.Add(m_filterSelection.get(), &FilterSelection::OnSongsChanged); m_mapDatabase->StartSearching(); m_filterSelection->SetFiltersByIndex(g_gameConfig.GetInt(GameConfigKeys::LevelFilter), g_gameConfig.GetInt(GameConfigKeys::FolderFilter)); @@ -1560,7 +1579,7 @@ class SongSelect_Impl : public SongSelect if (newPreview) { Ref previewAudio = g_audio->CreateStream(audioPath); - if (previewAudio && previewAudio.GetData()) + if (previewAudio) { previewAudio->SetPosition(diff->preview_offset); @@ -1584,7 +1603,7 @@ class SongSelect_Impl : public SongSelect // When a map is selected in the song wheel void OnFolderSelected(FolderIndex *folder) { - if (!folder->charts.empty() && folder->charts.size() > m_selectionWheel->GetSelectedDifficultyIndex()) + if (!folder->charts.empty() && (int)folder->charts.size() > m_selectionWheel->GetSelectedDifficultyIndex()) m_updatePreview(folder->charts[m_selectionWheel->GetSelectedDifficultyIndex()], true); } // When a difficulty is selected in the song wheel @@ -1743,6 +1762,8 @@ class SongSelect_Impl : public SongSelect m_sortSelection->Active = !m_sortSelection->Active; } break; + default: + break; } } void m_OnMouseScroll(int32 steps) @@ -1949,7 +1970,7 @@ class SongSelect_Impl : public SongSelect else { if (m_lockMouse) - m_lockMouse.Release(); + m_lockMouse.reset(); g_gameWindow->SetCursorVisible(true); } @@ -2010,7 +2031,7 @@ class SongSelect_Impl : public SongSelect m_previewPlayer.Pause(); m_mapDatabase->PauseSearching(); if (m_lockMouse) - m_lockMouse.Release(); + m_lockMouse.reset(); } virtual void OnRestore() { diff --git a/Main/src/SongSort.cpp b/Main/src/SongSort.cpp index e4988db13..1294282aa 100644 --- a/Main/src/SongSort.cpp +++ b/Main/src/SongSort.cpp @@ -53,7 +53,7 @@ void ScoreSort::SortInplace(Vector& vec, const Mapscores) { - if (score->score < maxScore) + if (score->score < (int32)maxScore) continue; maxScore = score->score; } diff --git a/Main/src/TCPSocket.cpp b/Main/src/TCPSocket.cpp index 7f28e88d5..5ba85ebaf 100644 --- a/Main/src/TCPSocket.cpp +++ b/Main/src/TCPSocket.cpp @@ -260,7 +260,7 @@ void TCPSocket::m_pushJsonValue(lua_State* L, const nlohmann::json& val) else if (val.is_array()) { lua_newtable(L); - for (int index = 0; index < val.size(); index++) + for (size_t index = 0; index < val.size(); index++) { lua_pushinteger(L, index + 1); m_pushJsonValue(L, val[index]); @@ -389,7 +389,7 @@ void TCPSocket::ProcessSocket() if (m_readingMode == TCPPacketMode::JSON_LINE) { // Scan the new bytes for line break - int tokenIndex; + uint32 tokenIndex; for (tokenIndex = newDataStart; tokenIndex < m_amountRead && m_dataBuff[tokenIndex] != '\n'; tokenIndex++); diff --git a/Main/src/Track.cpp b/Main/src/Track.cpp index ca47f184b..944f72abe 100644 --- a/Main/src/Track.cpp +++ b/Main/src/Track.cpp @@ -112,7 +112,7 @@ bool Track::AsyncFinalize() // Load track cover material & texture here for skin back-compat trackCoverMaterial = g_application->LoadMaterial("trackCover"); trackCoverTexture = g_application->LoadTexture("trackCover.png"); - if (trackCoverMaterial.IsValid()) + if (trackCoverMaterial) { trackCoverMaterial->opaque = false; } @@ -645,7 +645,7 @@ void Track::DrawCombo(RenderQueue& rq, uint32 score, Color color, float scale) void Track::DrawTrackCover(RenderQueue& rq) { #ifndef EMBEDDED - if (trackCoverMaterial.IsValid() && trackCoverTexture.IsValid()) + if (trackCoverMaterial && trackCoverTexture) { Transform t = trackOrigin; MaterialParameterSet p; diff --git a/Main/src/TransitionScreen.cpp b/Main/src/TransitionScreen.cpp index 973c8cfe8..922a61890 100644 --- a/Main/src/TransitionScreen.cpp +++ b/Main/src/TransitionScreen.cpp @@ -347,7 +347,7 @@ class TransitionScreen_Impl : public TransitionScreen } } - void OnFinished(Job job) + void OnFinished(Job& job) { // Finalize? IAsyncLoadable *loadable = dynamic_cast(m_tickableToLoad); diff --git a/Shared/include/Shared/Enum.hpp b/Shared/include/Shared/Enum.hpp index ac04101b8..4e356e257 100644 --- a/Shared/include/Shared/Enum.hpp +++ b/Shared/include/Shared/Enum.hpp @@ -18,18 +18,19 @@ class EnumStringMap String src = enumInit; size_t split = 0; size_t idLast = 0; + size_t badVal = -1; EnumType e; - for(uint32_t i = 0; split != -1 && !src.empty(); i++) + for(uint32_t i = 0; split != badVal && !src.empty(); i++) { split = src.find(','); - String seg = (split == -1) ? src : src.substr(0, split); + String seg = (split == badVal) ? src : src.substr(0, split); size_t assignment = seg.find("="); - if(assignment != -1) + if(assignment != badVal) { String valueStr = seg.substr(assignment + 1); seg = seg.substr(0, assignment); size_t charValue = valueStr.find('\''); - if(charValue != -1) // Probably a char value + if(charValue != badVal) // Probably a char value idLast = (size_t)valueStr[charValue + 1]; else // Hex or decimal value idLast = strtol(*valueStr, NULL, 0); @@ -38,7 +39,7 @@ class EnumStringMap seg.Trim(); names.Add(e, seg); rev.Add(seg, e); - src = (split == -1) ? src : src.substr(split + 1); + src = (split == badVal) ? src : src.substr(split + 1); } } auto begin() @@ -89,11 +90,12 @@ class BitflagEnumConversion { uint32 result = 0; size_t next = 0; - while(next != -1) + size_t badVal = -1; + while(next != badVal) { next = str.find('|'); String current = str; - if(next != -1) + if(next != badVal) { current = str.substr(0, next); str = str.substr(next + 1); @@ -170,7 +172,7 @@ struct Enum_##_n\ and allows string<=>value conversions for multiple flags at the same time */ #define DefineBitflagEnum(_n, ...) enum class _n : uint32 { __VA_ARGS__, _Length };\ -DeclareBitwiseEnumOps(_n);\ +DeclareBitwiseEnumOps(_n)\ struct Enum_##_n\ {\ typedef _n EnumType;\ diff --git a/Shared/include/Shared/Jobs.hpp b/Shared/include/Shared/Jobs.hpp index f982e493b..18a910aa1 100644 --- a/Shared/include/Shared/Jobs.hpp +++ b/Shared/include/Shared/Jobs.hpp @@ -46,7 +46,7 @@ class JobBase : public Unique // Called when finished // called from main thread when JobSheduler::Update is called - Delegate> OnFinished; + Delegate&> OnFinished; // Create job from lambda function template diff --git a/Shared/include/Shared/Log.hpp b/Shared/include/Shared/Log.hpp index 40117c3ee..cd4df86fe 100644 --- a/Shared/include/Shared/Log.hpp +++ b/Shared/include/Shared/Log.hpp @@ -35,7 +35,7 @@ class Logger : Unique Normal = 2, Warning = 3, Error = 4 - ); + ) diff --git a/Shared/include/Shared/Ref.hpp b/Shared/include/Shared/Ref.hpp index 6c23fdff1..111068075 100644 --- a/Shared/include/Shared/Ref.hpp +++ b/Shared/include/Shared/Ref.hpp @@ -1,274 +1,44 @@ #pragma once -#include -#include +#include -template class RefCounted; -/* - Basic shared pointer class - the object should be constructed once explicitly with a pointer to the object to manage - When there are no more references to this object, the underlying object gets deleted -*/ template -class Ref -{ -protected: - T* m_data; - int32_t* m_refCount; - void m_Dec() - { - if(m_refCount) - { - assert(m_refCount[0] != 0); - if(m_refCount[0] >= 0) - { - m_refCount[0]--; - if(m_refCount[0] == 0) - { - delete m_data; - delete m_refCount; - m_refCount = nullptr; -#if _DEBUG - m_data = nullptr; -#endif - } - } - else - { - m_refCount[0]++; - if(m_refCount[0] == 0) - { - delete m_refCount; - m_refCount = nullptr; -#if _DEBUG - m_data = nullptr; -#endif - } - } - } - } - void m_Inc() - { - if(m_refCount) - { - if(m_refCount[0] >= 0) - { - m_refCount[0]++; - } - else - { - m_refCount[0]--; - } - } - } - void m_AssignCounter(); - int32* m_CreateNewCounter(); +using Ref = std::shared_ptr; +// class Ref : public std::shared_ptr { +// public: +// using std::shared_ptr::get; +// using std::shared_ptr::reset; +// using std::shared_ptr::use_count; -public: - explicit Ref(T* data, int32_t* refCount) - : m_data(data), m_refCount(refCount) - { - m_Inc(); - } - - inline Ref() { m_data = nullptr; m_refCount = nullptr; } - explicit inline Ref(T* obj) - { - m_data = obj; - m_refCount = m_CreateNewCounter(); - m_refCount[0]++; - m_AssignCounter(); - } - inline ~Ref() - { - m_Dec(); - } - inline Ref(const Ref& other) - { - m_data = other.m_data; - m_refCount = other.m_refCount; - m_Inc(); - } - inline Ref(Ref&& other) - { - m_data = other.m_data; - m_refCount = other.m_refCount; - other.m_refCount = nullptr; - } - inline Ref& operator=(const Ref& other) - { - m_Dec(); - m_data = other.m_data; - m_refCount = other.m_refCount; - m_Inc(); - return *this; - } - inline Ref& operator=(Ref&& other) - { - m_Dec(); - m_data = other.m_data; - m_refCount = other.m_refCount; - other.m_refCount = nullptr; - return *this; - } - inline T& operator*() { assert(IsValid()); return *m_data; } - inline const T& operator*() const { assert(IsValid()); return *m_data; } - inline T* operator->() { assert(IsValid()); return m_data; } - inline const T* operator->() const { assert(IsValid()); return m_data; } - - template - inline Target* Cast() - { - if(!m_refCount) - return nullptr; - return dynamic_cast(m_data); - } - template - inline const Target* Cast() const - { - if(!m_refCount) - return nullptr; - return dynamic_cast(m_data); - } - // Casts the reference to a different type while not breaking the reference counting - template - inline Ref As() - { - Target* castData = dynamic_cast(m_data); - if(!m_refCount || !castData) - return Ref(); - return Ref(castData, m_refCount); - } - - inline bool operator<(const Ref& other) const - { - return m_refCount < other.m_refCount; - } - inline bool operator==(const Ref& other) const - { - return m_refCount == other.m_refCount; - } - inline bool operator!=(const Ref& other) const - { - return m_refCount != other.m_refCount; - } - inline bool operator==(const T* other) const - { - return m_refCount && m_data == other; - } - inline bool operator!=(const T* other) const - { - return m_refCount && m_data != other; - } +// inline bool IsValid() const {return get() != nullptr;} - inline void Destroy() - { - assert(IsValid()); - assert(m_refCount[0] > 0); - m_refCount[0] = -m_refCount[0] + 1; - m_refCount = nullptr; - delete m_data; - } - inline void Release() - { - m_Dec(); - m_refCount = nullptr; - } +// inline void Destroy() +// { +// assert(IsValid()); +// reset(); +// } - inline bool IsValid() const { return m_refCount != nullptr && m_refCount[0] > 0; } - inline operator bool() const { return IsValid(); } +// inline void Release() +// { +// if(use_count() < 2) +// Destroy(); +// } - inline int32_t GetRefCount() const { if(m_refCount && m_refCount[0] > 0) return m_refCount[0]; else return 0; } +// inline int GetRefCount() {return use_count();} - inline T* GetData() { assert(IsValid()); return m_data; } - inline const T* GetData() const { assert(IsValid()); return m_data; } -}; +// }; namespace Utility { - template + template Ref MakeRef(T* obj) { - return Ref(obj); - } -} - -/* - Base class for objects that allows them to create a shared pointer from themselves - WARNING: Only use on objects allocated with "new" - Repeatedly calling MakeShared will return the same shared pointer -*/ -class IRefCounted -{ -protected: - int32* m_refCount = (int32*)0; -public: -#if _DEBUG - ~IRefCounted() - { - // Should never happen, object will always - assert(!m_refCount || m_refCount[0] <= 0); + Ref ret = std::make_shared(); + ret.reset(obj); + return ret; } -#endif - int32 GetRefCount() const - { - return (m_refCount) ? m_refCount[0] : 0; - } - // Internal use, assigns the reference counter when constructing a Ref object without calling RefCounted::MakeShared - void _AssignRefCounter(int32* counter) - { - assert(m_refCount == nullptr || m_refCount == counter); - m_refCount = counter; - } - int32* _GetRefCounter() - { - if(!m_refCount) - m_refCount = new int32(0); - return m_refCount; - } -}; -// Same as above but typed version -template -class RefCounted : public IRefCounted -{ -public: - // Can be used for objects allocated with new to get a reference counted handle to this object - Ref MakeShared() - { - return Ref((T*)this, _GetRefCounter()); - } -}; - - -// Possibly assign reference counter in RefCounted object -template struct RefCounterHelper -{ - static void Assign(T* obj, int32* counter) - { - } - static int32* CreateCounter(T* obj) - { - return new int32(0); - } -}; -template struct RefCounterHelper -{ - static void Assign(T* obj, int32* counter) - { - obj->_AssignRefCounter(counter); - } - static int32* CreateCounter(T* obj) - { - return obj->_GetRefCounter(); - } -}; -template void Ref::m_AssignCounter() -{ - assert(m_data); - RefCounterHelper::value>::Assign((T*)m_data, m_refCount); -} -template int32* Ref::m_CreateNewCounter() -{ - assert(m_data); - return RefCounterHelper::value>::CreateCounter((T*)m_data); -} \ No newline at end of file + template + Ref CastRef(const Ref& a) { + return std::dynamic_pointer_cast(a); + } +} // namespace Utility \ No newline at end of file diff --git a/Shared/include/Shared/ResourceManager.hpp b/Shared/include/Shared/ResourceManager.hpp index 7283a0dd0..71ffe39a2 100644 --- a/Shared/include/Shared/ResourceManager.hpp +++ b/Shared/include/Shared/ResourceManager.hpp @@ -38,7 +38,8 @@ class ResourceManager : public IResourceManager, Unique // when the object is no longer referenced the resource manager will collect it when the next garbage collection triggers const Ref Register(T* pObject) { - Ref ret = Utility::MakeRef(pObject); + Ref ret = Ref(); + ret.reset(pObject); m_lock.lock(); m_objects.push_back(ret); m_lock.unlock(); @@ -50,7 +51,7 @@ class ResourceManager : public IResourceManager, Unique m_lock.lock(); for(auto it = m_objects.begin(); it != m_objects.end();) { - if(it->GetRefCount() <= 1) + if(it->use_count() <= 1) { numCleanedUp++; it = m_objects.erase(it); @@ -71,7 +72,7 @@ class ResourceManager : public IResourceManager, Unique for(auto it = m_objects.begin(); it != m_objects.end(); it++) { if(*it) - it->Destroy(); + it->reset(); } m_objects.clear(); m_lock.unlock(); diff --git a/Shared/include/Shared/String.hpp b/Shared/include/Shared/String.hpp index fa4098ac8..bae522191 100644 --- a/Shared/include/Shared/String.hpp +++ b/Shared/include/Shared/String.hpp @@ -147,7 +147,7 @@ template bool StringBase::Split(const StringBase& delim, StringBase* l, StringBase* r) const { size_t f = find(delim); - if(f == -1) + if(f == (size_t)-1) return false; StringBase selfCopy = *this; if(r) @@ -200,7 +200,6 @@ Vector> StringBase::Explode(const StringBase& delim) const template void StringBase::TrimFront(T c) { - StringBase& s = (*this); while(length() > 0) { if(front() != c) @@ -211,7 +210,6 @@ void StringBase::TrimFront(T c) template void StringBase::TrimBack(T c) { - StringBase& s = (*this); while(length() > 0) { if(back() != c) diff --git a/Shared/include/Shared/Vector.hpp b/Shared/include/Shared/Vector.hpp index 0e7f7b086..446cd3758 100644 --- a/Shared/include/Shared/Vector.hpp +++ b/Shared/include/Shared/Vector.hpp @@ -18,7 +18,7 @@ class Vector : public std::vector using std::vector::push_back; // Adds a new element and returns it - I& Add(const I& obj = I()) { push_back(obj); return back(); }; + I& Add(const I& obj = I()) { push_back(std::move(obj)); return back(); }; I& AddZeroed() { push_back(I()); memset(&back(), 0, sizeof(I)); return back(); }; void AddUnique(const I& obj) { diff --git a/Shared/include/Shared/VectorMath.hpp b/Shared/include/Shared/VectorMath.hpp index 485d8718a..754b181c6 100644 --- a/Shared/include/Shared/VectorMath.hpp +++ b/Shared/include/Shared/VectorMath.hpp @@ -291,7 +291,7 @@ namespace VectorMath static T Dot(const VectorBase& lhs, const VectorBase& rhs) { static_assert(sizeof(T) == 0, "Invalid vector types for dot product"); - }; + } template static T Dot(const VectorBase& lhs, const VectorBase& rhs) { @@ -362,22 +362,22 @@ namespace VectorMath static VectorBase Normalize(const VectorBase& lhs) { static_assert(sizeof(T) == 0, "Invalid vector type for normalize"); - }; + } template static VectorBase Normalize(const VectorBase& lhs) { return lhs / lhs.Length(); - }; + } template static VectorBase Normalize(const VectorBase& lhs) { return lhs / lhs.Length(); - }; + } template static VectorBase Normalize(const VectorBase& lhs) { return lhs / lhs.Length(); - }; + } // Member normalized function template VectorBase VectorBase::Normalized() const diff --git a/Shared/src/Jobs.cpp b/Shared/src/Jobs.cpp index 1a9d491c4..cd2779de4 100644 --- a/Shared/src/Jobs.cpp +++ b/Shared/src/Jobs.cpp @@ -37,7 +37,7 @@ struct JobThread if(thread.joinable()) thread.join(); } - bool IsActive() const { return activeJob.IsValid(); } + bool IsActive() const { return activeJob.get() != nullptr; } }; class JobSheduler_Impl @@ -70,11 +70,11 @@ class JobSheduler_Impl } m_lock.lock(); // Unregister jobs - for(auto job : m_jobQueue) + for(auto& job : m_jobQueue) { job->m_sheduler = nullptr; } - for(auto job : m_finishedJobs) + for(auto& job : m_finishedJobs) { job->m_sheduler = nullptr; } @@ -144,7 +144,7 @@ class JobSheduler_Impl myThread->idleDuration.Restart(); // Process a job - Job peekJob = m_jobQueue.front(); + Job& peekJob = m_jobQueue.front(); if((peekJob->jobFlags & JobFlags::IO) != JobFlags::IO || (myThread->index != 0)) // Only perform IO on first thread { myThread->activeJob = m_jobQueue.PopFront(); @@ -160,7 +160,7 @@ class JobSheduler_Impl m_lock.unlock(); // Clear the active job - myThread->activeJob.Release(); + myThread->activeJob.reset(); } else { @@ -236,7 +236,7 @@ void JobBase::Terminate() m_sheduler->m_lock.lock(); for(auto it = sheduler->m_jobQueue.begin(); it != sheduler->m_jobQueue.end(); it++) { - if(*it == this) + if(it->get() == this) { sheduler->m_jobQueue.erase(it); m_sheduler->m_lock.unlock(); @@ -249,10 +249,10 @@ void JobBase::Terminate() // Wait for running job for(JobThread* t : m_sheduler->m_threadPool) { - if(t->activeJob == this) + if(t->activeJob.get() == this) { // Wait for job to complete - while(t->activeJob == this) + while(t->activeJob.get() == this) { std::this_thread::yield(); } @@ -264,7 +264,7 @@ void JobBase::Terminate() m_sheduler->m_lock.lock(); for(auto it = m_sheduler->m_finishedJobs.rbegin(); it != m_sheduler->m_finishedJobs.rend(); it++) { - if(*it == this) + if(it->get() == this) { m_sheduler->m_finishedJobs.erase(--(it.base())); m_sheduler->m_lock.unlock(); diff --git a/Tests.Game/src/TestAudio.cpp b/Tests.Game/src/TestAudio.cpp index 1884dd144..cb629949b 100644 --- a/Tests.Game/src/TestAudio.cpp +++ b/Tests.Game/src/TestAudio.cpp @@ -21,7 +21,7 @@ Test("Audio.Playback") TestEnsure(audio->Init(false)); Sample testSample = audio->CreateSample(testSamplePath); - TestEnsure(testSample.IsValid()); + TestEnsure(testSample); testSample->SetVolume(1.0f); diff --git a/Tests.Game/src/TestMusicPlayer.cpp b/Tests.Game/src/TestMusicPlayer.cpp index 4910cac5f..fb40f4a8c 100644 --- a/Tests.Game/src/TestMusicPlayer.cpp +++ b/Tests.Game/src/TestMusicPlayer.cpp @@ -16,7 +16,7 @@ void TestMusicPlayer::Init(const String& songPath, uint32 startOffset) TestEnsure(audio->Init(false)); song = audio->CreateStream(songPath); - TestEnsure(song.IsValid()); + TestEnsure(song); song->Play(); song->SetPosition(startOffset); From 0ab1294d37c0f2348346fdb54c198a809da78974 Mon Sep 17 00:00:00 2001 From: Drewol Date: Sat, 27 Jun 2020 19:50:24 +0200 Subject: [PATCH 02/11] Fix segfault on exit --- GUI/include/GUI/nanovg_lua.h | 18 +++++++++--------- Graphics/src/Font.cpp | 5 ++++- Main/src/Application.cpp | 12 +++++++----- Shared/include/Shared/ResourceManager.hpp | 3 +-- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/GUI/include/GUI/nanovg_lua.h b/GUI/include/GUI/nanovg_lua.h index 3f6f5970f..457effa3a 100644 --- a/GUI/include/GUI/nanovg_lua.h +++ b/GUI/include/GUI/nanovg_lua.h @@ -17,7 +17,7 @@ struct Label int size; float scale; FontRes::TextOptions opt; - Graphics::Font* font; + Graphics::Font font; String content; }; @@ -55,7 +55,7 @@ struct GUIState Map nextPaintId; Map fontCahce; Map> vgImages; - Graphics::Font* currentFont; + Graphics::Font currentFont; Vector4 fillColor; int textAlign; int fontSize; @@ -83,7 +83,7 @@ static int LoadFont(const char* name, const char* filename, lua_State* L) Graphics::Font* cached = g_guiState.fontCahce.Find(name); if (cached) { - g_guiState.currentFont = cached; + g_guiState.currentFont = *cached; } else { @@ -103,7 +103,7 @@ static int LoadFont(const char* name, const char* filename, lua_State* L) return 0; } g_guiState.fontCahce.Add(name, newFont); - g_guiState.currentFont = g_guiState.fontCahce.Find(name); + g_guiState.currentFont = *g_guiState.fontCahce.Find(name); } } @@ -504,7 +504,7 @@ static int lCreateLabel(lua_State* L /*const char* text, int size, bool monospac int monospace = luaL_checkinteger(L, 3); Label newLabel; - newLabel.text = (*g_guiState.currentFont)->CreateText(Utility::ConvertToWString(text), + newLabel.text = g_guiState.currentFont->CreateText(Utility::ConvertToWString(text), size * g_guiState.t.GetScale().y, (FontRes::TextOptions)monospace); newLabel.scale = g_guiState.t.GetScale().y; @@ -524,7 +524,7 @@ static int lUpdateLabel(lua_State* L /*int labelId, const char* text, int size*/ const char* text = luaL_checkstring(L, 2); int size = luaL_checkinteger(L, 3); Label updated; - updated.text = (*g_guiState.currentFont)->CreateText(Utility::ConvertToWString(text), size * g_guiState.t.GetScale().y); + updated.text = g_guiState.currentFont->CreateText(Utility::ConvertToWString(text), size * g_guiState.t.GetScale().y); updated.size = size; updated.scale = g_guiState.t.GetScale().y; updated.content = text; @@ -553,7 +553,7 @@ static int lDrawLabel(lua_State* L /*int labelId, float x, float y, float maxWid if (fabsf(te.scale - g_guiState.t.GetScale().y) > 0.001) { te.scale = g_guiState.t.GetScale().y; - te.text = (*te.font)->CreateText(Utility::ConvertToWString(te.content), Math::Round((float)te.size * te.scale)); + te.text = te.font->CreateText(Utility::ConvertToWString(te.content), Math::Round((float)te.size * te.scale)); g_guiState.textCache[L][labelId] = te; } float mwScale = 1.0f; @@ -720,7 +720,7 @@ static int lFastText(lua_State* L /* String utf8string, float x, float y */) y = luaL_checknumber(L, 3); WString text = Utility::ConvertToWString(s); - Text te = (*g_guiState.currentFont)->CreateText(text, g_guiState.fontSize); + Text te = g_guiState.currentFont->CreateText(text, g_guiState.fontSize); Transform textTransform = g_guiState.t; textTransform *= Transform::Translation(Vector2(x, y)); @@ -1016,7 +1016,7 @@ static int lFastTextSize(lua_State* L /* char* text */) s = luaL_checkstring(L, 1); WString text = Utility::ConvertToWString(s); - Text l = (*g_guiState.currentFont)->CreateText(text, g_guiState.fontSize); + Text l = g_guiState.currentFont->CreateText(text, g_guiState.fontSize); lua_pushnumber(L, l->size.x); lua_pushnumber(L, l->size.y); return 2; diff --git a/Graphics/src/Font.cpp b/Graphics/src/Font.cpp index 956fa7385..7f750aa63 100644 --- a/Graphics/src/Font.cpp +++ b/Graphics/src/Font.cpp @@ -198,8 +198,11 @@ namespace Graphics delete s.second; } m_sizes.clear(); - if (m_face) + if (m_face && FT_Done_Face) + { FT_Done_Face(m_face); + m_face = nullptr; + } } bool Init(const String& assetPath) { diff --git a/Main/src/Application.cpp b/Main/src/Application.cpp index a1b27bb22..e9b3ad86f 100644 --- a/Main/src/Application.cpp +++ b/Main/src/Application.cpp @@ -1091,15 +1091,17 @@ void Application::m_Cleanup() delete img.second; } + //clear fonts before freeing library + for (auto& f : g_guiState.fontCahce) + { + f.second.reset(); + } + g_guiState.currentFont.reset(); + Graphics::FontRes::FreeLibrary(); Discord_Shutdown(); - for(auto& id : g_guiState.nvgFonts) - { - - } - #ifdef EMBEDDED nvgDeleteGLES2(g_guiState.vg); #else diff --git a/Shared/include/Shared/ResourceManager.hpp b/Shared/include/Shared/ResourceManager.hpp index 71ffe39a2..2d1b78ae2 100644 --- a/Shared/include/Shared/ResourceManager.hpp +++ b/Shared/include/Shared/ResourceManager.hpp @@ -38,8 +38,7 @@ class ResourceManager : public IResourceManager, Unique // when the object is no longer referenced the resource manager will collect it when the next garbage collection triggers const Ref Register(T* pObject) { - Ref ret = Ref(); - ret.reset(pObject); + Ref ret(pObject); m_lock.lock(); m_objects.push_back(ret); m_lock.unlock(); From da65ceba30a06f8515d7659baf61d7f56b30a6f4 Mon Sep 17 00:00:00 2001 From: Drewol Date: Sat, 27 Jun 2020 21:45:08 +0200 Subject: [PATCH 03/11] Memory cleanup --- Beatmap/src/BeatmapFromKSH.cpp | 1 + GUI/include/GUI/nanovg_lua.h | 20 ++++++++++---------- Graphics/CMakeLists.txt | 1 + Graphics/src/Font.cpp | 4 ++-- Graphics/src/Image.cpp | 2 +- Graphics/src/ImageLoader.cpp | 2 +- Graphics/src/Material.cpp | 2 +- Graphics/src/Mesh.cpp | 2 +- Graphics/src/OpenGL.cpp | 2 +- Graphics/src/ParticleSystem.cpp | 6 +++++- Graphics/src/SpriteMap.cpp | 3 --- Graphics/src/Texture.cpp | 8 -------- Main/include/Track.hpp | 2 +- Main/src/Application.cpp | 2 +- Tests.Game/src/TestBeatmap.cpp | 2 +- Tests/include/Tests/TestManager.hpp | 2 +- 16 files changed, 28 insertions(+), 33 deletions(-) diff --git a/Beatmap/src/BeatmapFromKSH.cpp b/Beatmap/src/BeatmapFromKSH.cpp index 6ab935aa8..cad5ece0f 100644 --- a/Beatmap/src/BeatmapFromKSH.cpp +++ b/Beatmap/src/BeatmapFromKSH.cpp @@ -733,6 +733,7 @@ bool Beatmap::m_ProcessKShootMap(BinaryStream &input, bool metadataOnly) { float vol = (float)atol(*p.second) / 100.0f; EventObjectState *evt = new EventObjectState(); + evt->interTickIndex = tickSettingIndex; evt->time = mapTime; evt->key = EventKey::LaserEffectMix; evt->data.floatVal = vol; diff --git a/GUI/include/GUI/nanovg_lua.h b/GUI/include/GUI/nanovg_lua.h index 457effa3a..b61f0824d 100644 --- a/GUI/include/GUI/nanovg_lua.h +++ b/GUI/include/GUI/nanovg_lua.h @@ -66,7 +66,7 @@ struct GUIState NVGcolor imageTint; Rect scissor; Vector2i resolution; - Map animations; + Map> animations; int scissorOffset; Vector transformStack; Vector nvgFonts; @@ -128,7 +128,7 @@ static int lBeginPath(lua_State* L) } -static void AnimationLoader(Vector files, ImageAnimation* ia) +static void AnimationLoader(Vector files, Ref ia) { ia->FrameCount = files.size(); files.Sort([](FileInfo& a, FileInfo& b) { @@ -199,7 +199,7 @@ static int lTickAnimation(lua_State* L) if (!g_guiState.animations.Contains(key)) return 0; - ImageAnimation* ia = g_guiState.animations.at(key); + Ref ia = g_guiState.animations.at(key); if (!ia->LoadComplete.load()) return 0; @@ -243,7 +243,7 @@ static int LoadAnimation(lua_State* L, const char* path, float frametime, int lo return -1; int key = nvgCreateImage(g_guiState.vg, *files[0].fullPath, 0); - ImageAnimation* ia = new ImageAnimation(); + Ref ia = std::make_shared(); ia->Compressed = compressed; ia->TimesToLoop = loopcount; ia->LoopCounter = 0; @@ -252,7 +252,7 @@ static int LoadAnimation(lua_State* L, const char* path, float frametime, int lo ia->Cancelled.store(false); ia->State = L; ia->JobThread = new Thread(AnimationLoader, files, ia); - g_guiState.animations[key] = ia; + g_guiState.animations.insert(std::make_pair(key, ia)); return key; } @@ -261,7 +261,7 @@ static int lResetAnimation(lua_State* L) { int key; key = luaL_checkinteger(L, 1); - ImageAnimation* ia = g_guiState.animations[key]; + Ref ia = g_guiState.animations.at(key); ia->CurrentFrame = 0; ia->Timer = 0; ia->LoopCounter = 0; @@ -440,10 +440,10 @@ static int lImageRect(lua_State* L /*float x, float y, float w, float h, int ima alpha = luaL_checknumber(L, 6); angle = luaL_checknumber(L, 7); - int imgH, imgW; + int imgH = -1, imgW = -1; nvgImageSize(g_guiState.vg, image, &imgW, &imgH); - float scaleX, scaleY; - float tr[6]; + float scaleX = 1.f, scaleY = 1.f; + float tr[6] = {0.f, 0.f, 0.f, 0.f, 0.f, 0.f}; nvgCurrentTransform(g_guiState.vg, tr); scaleX = w / imgW; scaleY = h / imgH; @@ -1056,11 +1056,11 @@ static int DisposeGUI(lua_State* state) anim.second->JobThread->join(); anim.second->Frames.clear(); anim.second->FrameData.clear(); + delete anim.second->JobThread; nvgDeleteImage(g_guiState.vg, anim.first); } for (int k : keysToDelete) { - delete g_guiState.animations[k]; g_guiState.animations.erase(k); } diff --git a/Graphics/CMakeLists.txt b/Graphics/CMakeLists.txt index e5eefe3ef..094ad8f21 100644 --- a/Graphics/CMakeLists.txt +++ b/Graphics/CMakeLists.txt @@ -44,6 +44,7 @@ target_link_libraries(Graphics ${JPEG_LIBRARIES}) target_link_libraries(Graphics ${PNG_LIBRARIES}) target_link_libraries(Graphics GLEW) if(UNIX) + target_compile_options(Graphics PUBLIC -Wall -Wextra -Werror -Wno-unused-variable -Wno-unused-parameter -Wno-unused-function) target_link_libraries(Graphics pthread) target_link_libraries(Graphics dl) if(APPLE) diff --git a/Graphics/src/Font.cpp b/Graphics/src/Font.cpp index 7f750aa63..e3ee5c33c 100644 --- a/Graphics/src/Font.cpp +++ b/Graphics/src/Font.cpp @@ -177,13 +177,13 @@ namespace Graphics class Font_Impl : public FontRes { + OpenGL* m_gl; FT_Face m_face; Buffer m_data; Map m_sizes; uint32 m_currentSize = 0; - OpenGL* m_gl; friend class TextRes; public: @@ -198,7 +198,7 @@ namespace Graphics delete s.second; } m_sizes.clear(); - if (m_face && FT_Done_Face) + if (m_face) { FT_Done_Face(m_face); m_face = nullptr; diff --git a/Graphics/src/Image.cpp b/Graphics/src/Image.cpp index a1e41ff22..a2635f1eb 100644 --- a/Graphics/src/Image.cpp +++ b/Graphics/src/Image.cpp @@ -139,7 +139,7 @@ namespace Graphics PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); png_bytep* row_pointers = (png_bytep*)malloc(sizeof(png_bytep) * m_size.y); - for (size_t i = 0; i < m_size.y; ++i) { + for (int i = 0; i < m_size.y; ++i) { row_pointers[m_size.y - i - 1] = (png_bytep)(m_pData + i * m_size.x); } diff --git a/Graphics/src/ImageLoader.cpp b/Graphics/src/ImageLoader.cpp index d47c691a6..b24c5cf00 100644 --- a/Graphics/src/ImageLoader.cpp +++ b/Graphics/src/ImageLoader.cpp @@ -9,7 +9,7 @@ #endif // HAVE_STDDEF_H redefinition -#pragma warning(disable:4005) +//#pragma warning(disable:4005) #include "jpeglib.h" namespace Graphics diff --git a/Graphics/src/Material.cpp b/Graphics/src/Material.cpp index 80e9fde4b..79640d020 100644 --- a/Graphics/src/Material.cpp +++ b/Graphics/src/Material.cpp @@ -50,8 +50,8 @@ namespace Graphics } ShaderType shaderType; - uint32 location; uint32 paramType; + uint32 location; }; struct BoundParameterList : public Vector { diff --git a/Graphics/src/Mesh.cpp b/Graphics/src/Mesh.cpp index 1fada235f..9a1121b07 100644 --- a/Graphics/src/Mesh.cpp +++ b/Graphics/src/Mesh.cpp @@ -73,7 +73,7 @@ namespace Graphics type = GL_DOUBLE; #endif } - assert(type != -1); + assert(type != (uint32)-1); glVertexAttribPointer((int)index, (int)e.components, type, GL_TRUE, (int)totalVertexSize, (void*)offset); glEnableVertexAttribArray((int)index); offset += e.componentSize * e.components; diff --git a/Graphics/src/OpenGL.cpp b/Graphics/src/OpenGL.cpp index 73d87b443..ef3e1493a 100644 --- a/Graphics/src/OpenGL.cpp +++ b/Graphics/src/OpenGL.cpp @@ -208,6 +208,6 @@ namespace Graphics break; } String msgString = String(message, message + length); - Logf("GLDebug: %s", Logger::Severity::Info, msgString); + Logf("GLDebug: %s", mySeverity, msgString); } } diff --git a/Graphics/src/ParticleSystem.cpp b/Graphics/src/ParticleSystem.cpp index b6aa39409..9da671e9a 100644 --- a/Graphics/src/ParticleSystem.cpp +++ b/Graphics/src/ParticleSystem.cpp @@ -170,7 +170,11 @@ namespace Graphics if(newCapacity > 0) { m_particles = new Particle[m_poolSize]; - memset(m_particles, 0, m_poolSize * sizeof(Particle)); + for (size_t i = 0; i < m_poolSize; i++) + { + m_particles[i] = Particle(); + } + } else { diff --git a/Graphics/src/SpriteMap.cpp b/Graphics/src/SpriteMap.cpp index 7e88663ac..c5d66c3f4 100644 --- a/Graphics/src/SpriteMap.cpp +++ b/Graphics/src/SpriteMap.cpp @@ -74,7 +74,6 @@ namespace Graphics // Returns the category that has space for the requested size Category& AssignCategory(Vector2i requestedSize) { - int32 mostSpace = 0; Category* dstCat = nullptr; while(true) @@ -88,7 +87,6 @@ namespace Graphics if(remainingY > requestedSize.y) { // This category is OK - mostSpace = remainingY; dstCat = &cat; break; } @@ -160,7 +158,6 @@ namespace Graphics void CopySubImage(Image dst, Image src, Vector2i dstPos) { - Vector2i dstSize = dst->GetSize(); Vector2i srcSize = src->GetSize(); Colori* pSrc = src->GetBits(); diff --git a/Graphics/src/Texture.cpp b/Graphics/src/Texture.cpp index 2f4ee9b57..768775eec 100644 --- a/Graphics/src/Texture.cpp +++ b/Graphics/src/Texture.cpp @@ -80,14 +80,6 @@ namespace Graphics glReadBuffer(GL_BACK); glBindTexture(GL_TEXTURE_2D, m_texture); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, pos.x, pos.y, m_size.x, m_size.y); - GLenum err; - bool errored = false; - while ((err = glGetError()) != GL_NO_ERROR) - { - Logf("OpenGL Error: 0x%p", Logger::Severity::Error, err); - errored = true; - } - //assert(!errored); glBindTexture(GL_TEXTURE_2D, 0); } diff --git a/Main/include/Track.hpp b/Main/include/Track.hpp index 66b49d48a..74be81e54 100644 --- a/Main/include/Track.hpp +++ b/Main/include/Track.hpp @@ -149,7 +149,7 @@ class Track : Unique, public IAsyncLoadable // Laser track generators class LaserTrackBuilder* m_laserTrackBuilder[2] = { 0 }; - const TimingPoint* m_lastTimingPoint; + const TimingPoint* m_lastTimingPoint = nullptr; // Bar tick locations Vector m_barTicks; diff --git a/Main/src/Application.cpp b/Main/src/Application.cpp index e9b3ad86f..f6152c9e9 100644 --- a/Main/src/Application.cpp +++ b/Main/src/Application.cpp @@ -1098,7 +1098,6 @@ void Application::m_Cleanup() } g_guiState.currentFont.reset(); - Graphics::FontRes::FreeLibrary(); Discord_Shutdown(); @@ -1108,6 +1107,7 @@ void Application::m_Cleanup() nvgDeleteGL3(g_guiState.vg); #endif + Graphics::FontRes::FreeLibrary(); if (m_updateThread.joinable()) m_updateThread.join(); diff --git a/Tests.Game/src/TestBeatmap.cpp b/Tests.Game/src/TestBeatmap.cpp index 652d7d542..40a8658fa 100644 --- a/Tests.Game/src/TestBeatmap.cpp +++ b/Tests.Game/src/TestBeatmap.cpp @@ -17,7 +17,7 @@ Beatmap LoadTestBeatmap(const String& mapPath = testBeatmapPath) TestEnsure(file.OpenRead(mapPath)); FileReader reader(file); TestEnsure(beatmap.Load(reader)); - return std::move(beatmap); + return beatmap; } Test("Beatmap.v160") diff --git a/Tests/include/Tests/TestManager.hpp b/Tests/include/Tests/TestManager.hpp index ae06fe05c..962982ca6 100644 --- a/Tests/include/Tests/TestManager.hpp +++ b/Tests/include/Tests/TestManager.hpp @@ -69,6 +69,6 @@ class TestContext String GetName() const { return m_name; } private: - TestManager* m_testManager; String m_name; + TestManager* m_testManager; }; \ No newline at end of file From 4bd11e8d31cc47da59c5f18d31c8bd34ba572ea8 Mon Sep 17 00:00:00 2001 From: Drewol Date: Sat, 27 Jun 2020 22:28:52 +0200 Subject: [PATCH 04/11] Fix some warnings in Audio and disable werror for mac --- Audio/CMakeLists.txt | 4 ++++ Audio/src/AudioStreamBase.cpp | 2 +- Audio/src/AudioStreamMa.cpp | 11 +++++---- Audio/src/AudioStreamMp3.cpp | 4 ++-- Audio/src/AudioStreamOgg.cpp | 6 ++--- Audio/src/AudioStreamOgg.hpp | 2 +- Audio/src/AudioStreamWav.cpp | 12 +++++----- Audio/src/AudioStreamWav.hpp | 2 +- Audio/src/DSP.cpp | 36 +++++++++++++++--------------- Audio/src/Sample.cpp | 3 ++- Audio/src/Unix/AudioOutput_SDL.cpp | 6 +++-- Graphics/CMakeLists.txt | 2 +- Main/CMakeLists.txt | 2 +- 13 files changed, 49 insertions(+), 43 deletions(-) diff --git a/Audio/CMakeLists.txt b/Audio/CMakeLists.txt index 36c9c079e..774bff82e 100644 --- a/Audio/CMakeLists.txt +++ b/Audio/CMakeLists.txt @@ -37,6 +37,10 @@ target_include_directories(Audio PRIVATE ${PCHROOT} ) +if(UNIX AND NOT APPLE) + target_compile_options(Audio PUBLIC -Wall -Wextra -Werror -Wno-unused-variable -Wno-unused-parameter -Wno-unused-function -Wno-unused-value) +endif(UNIX AND NOT APPLE) + # Dependencies ## Local Dependencies target_link_libraries(Audio Shared) diff --git a/Audio/src/AudioStreamBase.cpp b/Audio/src/AudioStreamBase.cpp index 667a4b094..f9f487d6a 100644 --- a/Audio/src/AudioStreamBase.cpp +++ b/Audio/src/AudioStreamBase.cpp @@ -190,7 +190,7 @@ void AudioStreamBase::Process(float* out, uint32 numSamples) if(m_samplePos > 0) { - if(m_samplePos >= m_samplesTotal) + if((uint64)m_samplePos >= m_samplesTotal) { if(!m_ended) { diff --git a/Audio/src/AudioStreamMa.cpp b/Audio/src/AudioStreamMa.cpp index 3162c0dff..e5aecad90 100644 --- a/Audio/src/AudioStreamMa.cpp +++ b/Audio/src/AudioStreamMa.cpp @@ -93,7 +93,7 @@ int32 AudioStreamMa::DecodeData_Internal() int actualRead = 0; for (size_t i = 0; i < samplesPerRead; i++) { - if (m_playbackPointer >= m_samplesTotal) + if (m_playbackPointer >= (int64)m_samplesTotal) { m_currentBufferSize = samplesPerRead; m_remainingBufferData = samplesPerRead; @@ -114,7 +114,7 @@ int32 AudioStreamMa::DecodeData_Internal() float decodeBuffer[256]; int totalRead = ma_decoder_read_pcm_frames(&m_decoder, decodeBuffer, samplesPerRead); - for (size_t i = 0; i < totalRead; i++) + for (int i = 0; i < totalRead; i++) { m_readBuffer[0][i] = decodeBuffer[i * 2]; m_readBuffer[1][i] = decodeBuffer[i * 2 + 1]; @@ -136,11 +136,10 @@ uint32 AudioStreamMa::GetSampleRate_Internal() const Ref AudioStreamMa::Create(class Audio* audio, const String& path, bool preload) { - AudioStreamMa* impl = new AudioStreamMa(); + Ref impl; if (!impl->Init(audio, path, preload)) { - delete impl; - impl = nullptr; + impl.reset(); } - return Utility::CastRef(Utility::MakeRef(impl)); + return Utility::CastRef(impl); } diff --git a/Audio/src/AudioStreamMp3.cpp b/Audio/src/AudioStreamMp3.cpp index 2aadb125a..ddd8f2c92 100644 --- a/Audio/src/AudioStreamMp3.cpp +++ b/Audio/src/AudioStreamMp3.cpp @@ -139,7 +139,7 @@ bool AudioStreamMp3::Init(Audio* audio, const String& path, bool preload) int totalSamples = 0; while (r > 0) { - for (size_t i = 0; i < r; i++) + for (int32 i = 0; i < r; i++) { m_pcm.Add(m_readBuffer[0][i]); m_pcm.Add(m_readBuffer[1][i]); @@ -218,7 +218,7 @@ int32 AudioStreamMp3::DecodeData_Internal() m_playPos++; continue; } - else if (m_playPos >= m_samplesTotal) + else if ((uint64)m_playPos >= m_samplesTotal) { m_currentBufferSize = samplesPerRead; m_remainingBufferData = samplesPerRead; diff --git a/Audio/src/AudioStreamOgg.cpp b/Audio/src/AudioStreamOgg.cpp index 570ec5071..a79520212 100644 --- a/Audio/src/AudioStreamOgg.cpp +++ b/Audio/src/AudioStreamOgg.cpp @@ -59,7 +59,7 @@ bool AudioStreamOgg::Init(Audio* audio, const String& path, bool preload) { if (m_info.channels == 2) { - for (size_t i = 0; i < r; i++) + for (int i = 0; i < r; i++) { m_pcm.Add(readBuffer[0][i]); m_pcm.Add(readBuffer[1][i]); @@ -67,7 +67,7 @@ bool AudioStreamOgg::Init(Audio* audio, const String& path, bool preload) } else if (m_info.channels == 1) { - for (size_t i = 0; i < r; i++) + for (int i = 0; i < r; i++) { m_pcm.Add(readBuffer[0][i]); m_pcm.Add(readBuffer[0][i]); @@ -139,7 +139,7 @@ int32 AudioStreamOgg::DecodeData_Internal() m_playPos++; continue; } - else if (m_playPos >= m_samplesTotal) + else if ((uint64)m_playPos >= m_samplesTotal) { m_currentBufferSize = m_bufferSize; m_remainingBufferData = m_bufferSize; diff --git a/Audio/src/AudioStreamOgg.hpp b/Audio/src/AudioStreamOgg.hpp index ca5572084..2ebac4ca7 100644 --- a/Audio/src/AudioStreamOgg.hpp +++ b/Audio/src/AudioStreamOgg.hpp @@ -6,7 +6,7 @@ class AudioStreamOgg : public AudioStreamBase { protected: - OggVorbis_File m_ovf = { 0 }; + OggVorbis_File m_ovf; vorbis_info m_info; Vector m_pcm; int64 m_playPos; diff --git a/Audio/src/AudioStreamWav.cpp b/Audio/src/AudioStreamWav.cpp index d88c60047..90b46ae6e 100644 --- a/Audio/src/AudioStreamWav.cpp +++ b/Audio/src/AudioStreamWav.cpp @@ -159,7 +159,7 @@ bool AudioStreamWav::Init(Audio* audio, const String& path, bool preload) //Decode to float - int pos = 0; + uint64 pos = 0; m_pcm.resize(2 * m_samplesTotal * sizeof(float)); if (m_format.nFormat == 1) { @@ -191,10 +191,10 @@ bool AudioStreamWav::Init(Audio* audio, const String& path, bool preload) while (pos < m_samplesTotal) { - int newDecoded = m_decode_ms_adpcm(m_Internaldata, &decodedBuffer, pos); + uint32 newDecoded = m_decode_ms_adpcm(m_Internaldata, &decodedBuffer, pos); pos += m_format.nBlockAlign; int16* src = ((int16*)decodedBuffer.data()); - for (size_t i = 0; i < newDecoded; i++) + for (uint32 i = 0; i < newDecoded; i++) { m_pcm[(2 * decoded) + (i * 2)] = (float)src[i * 2] / (float)0x7FFF; m_pcm[(2 * decoded) + (i * 2) + 1] = (float)src[i * 2 + 1] / (float)0x7FFF; @@ -335,7 +335,7 @@ int32 AudioStreamWav::DecodeData_Internal() { for (uint32 i = 0; i < samplesPerRead; i++) { - if (m_playbackPointer >= m_samplesTotal) + if (m_playbackPointer >= (int64)m_samplesTotal) { m_currentBufferSize = samplesPerRead; m_remainingBufferData = samplesPerRead; @@ -352,7 +352,7 @@ int32 AudioStreamWav::DecodeData_Internal() // Mix mono sample for (uint32 i = 0; i < samplesPerRead; i++) { - if (m_playbackPointer >= m_samplesTotal) + if (m_playbackPointer >= (int64)m_samplesTotal) { m_currentBufferSize = samplesPerRead; m_remainingBufferData = samplesPerRead; @@ -409,7 +409,7 @@ int32 AudioStreamWav::DecodeData_Internal() m_playbackPointer++; continue; } - else if (m_playbackPointer >= m_samplesTotal) + else if (m_playbackPointer >= (int64)m_samplesTotal) { m_currentBufferSize = samplesPerRead; m_remainingBufferData = samplesPerRead; diff --git a/Audio/src/AudioStreamWav.hpp b/Audio/src/AudioStreamWav.hpp index 8f0e5647f..b2068700d 100644 --- a/Audio/src/AudioStreamWav.hpp +++ b/Audio/src/AudioStreamWav.hpp @@ -30,7 +30,7 @@ class AudioStreamWav : public AudioStreamBase uint16 nBitsPerSample; }; Buffer m_Internaldata; - WavFormat m_format = { 0 }; + WavFormat m_format; Vector m_pcm; int64 m_playbackPointer = 0; uint64 m_dataPosition = 0; diff --git a/Audio/src/DSP.cpp b/Audio/src/DSP.cpp index d6cda8f45..608cdf7ed 100644 --- a/Audio/src/DSP.cpp +++ b/Audio/src/DSP.cpp @@ -197,8 +197,8 @@ void GateDSP::Process(float* out, uint32 numSamples) if(m_length < 2) return; - int32 startSample = startTime * audio->GetSampleRate() / 1000.0; - int32 currentSample = audioBase->GetPosition() * audio->GetSampleRate() / 1000.0; + uint32 startSample = startTime * audio->GetSampleRate() / 1000.0; + uint32 currentSample = audioBase->GetPosition() * audio->GetSampleRate() / 1000.0; for(uint32 i = 0; i < numSamples; i++) { @@ -244,8 +244,8 @@ void TapeStopDSP::SetLength(double length) } void TapeStopDSP::Process(float* out, uint32 numSamples) { - int32 startSample = startTime * audio->GetSampleRate() / 1000.0; - int32 currentSample = audioBase->GetPosition() * audio->GetSampleRate() / 1000.0; + uint32 startSample = startTime * audio->GetSampleRate() / 1000.0; + uint32 currentSample = audioBase->GetPosition() * audio->GetSampleRate() / 1000.0; for(uint32 i = 0; i < numSamples; i++) { @@ -312,12 +312,12 @@ void RetriggerDSP::Process(float* out, uint32 numSamples) return; ///TODO: Clean up casting - int32 startSample = (double)startTime * ((double)audio->GetSampleRate() / 1000.0); - int32 nowSample = (double)audioBase->GetPosition() * ((double)audio->GetSampleRate() / 1000.0); + uint32 startSample = (double)startTime * ((double)audio->GetSampleRate() / 1000.0); + uint32 nowSample = (double)audioBase->GetPosition() * ((double)audio->GetSampleRate() / 1000.0); float* pcmSource = audioBase->GetPCM(); double rateMult = (double)audioBase->GetSampleRate() / audio->GetSampleRate(); - int32 pcmStartSample = (double)lastTimingPoint * ((double)audioBase->GetSampleRate() / 1000.0); - int32 baseStartRepeat = (double)lastTimingPoint * ((double)audio->GetSampleRate() / 1000.0); + uint32 pcmStartSample = (double)lastTimingPoint * ((double)audioBase->GetSampleRate() / 1000.0); + uint32 baseStartRepeat = (double)lastTimingPoint * ((double)audio->GetSampleRate() / 1000.0); for(uint32 i = 0; i < numSamples; i++) { @@ -362,8 +362,8 @@ void WobbleDSP::Process(float* out, uint32 numSamples) return; static Interpolation::CubicBezier easing(Interpolation::EaseInExpo); - int32 startSample = startTime * audio->GetSampleRate() / 1000.0; - int32 currentSample = audioBase->GetPosition() * audio->GetSampleRate() / 1000.0; + uint32 startSample = startTime * audio->GetSampleRate() / 1000.0; + uint32 currentSample = audioBase->GetPosition() * audio->GetSampleRate() / 1000.0; for(uint32 i = 0; i < numSamples; i++) { @@ -400,8 +400,8 @@ void PhaserDSP::Process(float* out, uint32 numSamples) if (m_length == 0) return; - int32 startSample = startTime * audio->GetSampleRate() / 1000.0; - int32 currentSample = audioBase->GetPosition() * audio->GetSampleRate() / 1000.0; + uint32 startSample = startTime * audio->GetSampleRate() / 1000.0; + uint32 currentSample = audioBase->GetPosition() * audio->GetSampleRate() / 1000.0; for(uint32 i = 0; i < numSamples; i++) { @@ -473,8 +473,8 @@ void FlangerDSP::Process(float* out, uint32 numSamples) if(m_bufferLength <= 0) return; - int32 startSample = startTime * audio->GetSampleRate() / 1000.0; - int32 currentSample = audioBase->GetPosition() * audio->GetSampleRate() / 1000.0; + uint32 startSample = startTime * audio->GetSampleRate() / 1000.0; + uint32 currentSample = audioBase->GetPosition() * audio->GetSampleRate() / 1000.0; for(uint32 i = 0; i < numSamples; i++) { @@ -523,8 +523,8 @@ void EchoDSP::Process(float* out, uint32 numSamples) float* data = m_sampleBuffer.data(); if (!data) return; - int32 startSample = startTime * audio->GetSampleRate() / 1000.0; - int32 currentSample = audioBase->GetPosition() * audio->GetSampleRate() / 1000.0; + uint32 startSample = startTime * audio->GetSampleRate() / 1000.0; + uint32 currentSample = audioBase->GetPosition() * audio->GetSampleRate() / 1000.0; for(uint32 i = 0; i < numSamples; i++) { @@ -567,8 +567,8 @@ void SidechainDSP::Process(float* out, uint32 numSamples) if(m_length == 0) return; - int32 startSample = startTime * audio->GetSampleRate() / 1000.0; - int32 currentSample = audioBase->GetPosition() * audio->GetSampleRate() / 1000.0; + uint32 startSample = startTime * audio->GetSampleRate() / 1000.0; + uint32 currentSample = audioBase->GetPosition() * audio->GetSampleRate() / 1000.0; for(uint32 i = 0; i < numSamples; i++) { diff --git a/Audio/src/Sample.cpp b/Audio/src/Sample.cpp index ac2a67bae..dbcc570ed 100644 --- a/Audio/src/Sample.cpp +++ b/Audio/src/Sample.cpp @@ -15,6 +15,7 @@ class Sample_Impl : public SampleRes { public: + Buffer m_data; Audio* m_audio; float* m_pcm = nullptr; @@ -92,7 +93,7 @@ class Sample_Impl : public SampleRes } const Buffer& GetData() const { - return Buffer(); + return m_data; } uint32 GetBitsPerSample() const { diff --git a/Audio/src/Unix/AudioOutput_SDL.cpp b/Audio/src/Unix/AudioOutput_SDL.cpp index 87025856f..79a0f5147 100644 --- a/Audio/src/Unix/AudioOutput_SDL.cpp +++ b/Audio/src/Unix/AudioOutput_SDL.cpp @@ -32,7 +32,7 @@ class SDLAudio class AudioOutput_Impl { public: - SDL_AudioSpec m_audioSpec = { 0 }; + SDL_AudioSpec m_audioSpec; SDL_AudioDeviceID m_deviceId = 0; IMixer* m_mixer = nullptr; volatile bool m_running = false; @@ -63,7 +63,9 @@ class AudioOutput_Impl { CloseDevice(); - SDL_AudioSpec desiredSpec = { 0 }; + SDL_AudioSpec desiredSpec; + memset(&desiredSpec, 0, sizeof(SDL_AudioSpec)); + memset(&m_audioSpec, 0, sizeof(SDL_AudioSpec)); desiredSpec.freq = 44100; desiredSpec.format = AUDIO_F32; desiredSpec.channels = 2; /* 1 = mono, 2 = stereo */ diff --git a/Graphics/CMakeLists.txt b/Graphics/CMakeLists.txt index 094ad8f21..714814f0a 100644 --- a/Graphics/CMakeLists.txt +++ b/Graphics/CMakeLists.txt @@ -44,13 +44,13 @@ target_link_libraries(Graphics ${JPEG_LIBRARIES}) target_link_libraries(Graphics ${PNG_LIBRARIES}) target_link_libraries(Graphics GLEW) if(UNIX) - target_compile_options(Graphics PUBLIC -Wall -Wextra -Werror -Wno-unused-variable -Wno-unused-parameter -Wno-unused-function) target_link_libraries(Graphics pthread) target_link_libraries(Graphics dl) if(APPLE) find_library(OPEN_GL OpenGL) target_link_libraries(Graphics ${OPEN_GL}) else(APPLE) + target_compile_options(Graphics PUBLIC -Wall -Wextra -Werror -Wno-unused-variable -Wno-unused-parameter -Wno-unused-function) target_link_libraries(Graphics GL) find_package(X11 REQUIRED) include_directories(${X11_INCLUDE_DIR}) diff --git a/Main/CMakeLists.txt b/Main/CMakeLists.txt index 8cc818f73..42207fde0 100644 --- a/Main/CMakeLists.txt +++ b/Main/CMakeLists.txt @@ -62,7 +62,7 @@ set_output_postfixes(usc-game) if(MSVC) set_target_properties(usc-game PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS") set_target_properties(usc-game PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/bin") -else() +elseif(NOT APPLE) target_compile_options(usc-game PUBLIC -Wall -Wextra -Werror -Wno-unused-variable -Wno-unused-parameter -Wno-unused-function) endif(MSVC) From ca08b2c57c25cda99c04ccf573fd02c0ec2887da Mon Sep 17 00:00:00 2001 From: Drewol Date: Sat, 27 Jun 2020 22:52:17 +0200 Subject: [PATCH 05/11] Fix some stuff --- Audio/CMakeLists.txt | 3 +++ Audio/src/AudioStreamMa.cpp | 5 +++++ Audio/src/AudioStreamMa.hpp | 2 +- Audio/src/AudioStreamMp3.hpp | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Audio/CMakeLists.txt b/Audio/CMakeLists.txt index 774bff82e..bf71fdec4 100644 --- a/Audio/CMakeLists.txt +++ b/Audio/CMakeLists.txt @@ -39,6 +39,9 @@ target_include_directories(Audio PRIVATE if(UNIX AND NOT APPLE) target_compile_options(Audio PUBLIC -Wall -Wextra -Werror -Wno-unused-variable -Wno-unused-parameter -Wno-unused-function -Wno-unused-value) + if(CMAKE_BUILD_TYPE STREQUAL "Release") + target_compile_options(Audio PUBLIC -Wno-maybe-uninitialized) + endif(CMAKE_BUILD_TYPE STREQUAL "Release") endif(UNIX AND NOT APPLE) # Dependencies diff --git a/Audio/src/AudioStreamMa.cpp b/Audio/src/AudioStreamMa.cpp index e5aecad90..866fe7cfb 100644 --- a/Audio/src/AudioStreamMa.cpp +++ b/Audio/src/AudioStreamMa.cpp @@ -11,6 +11,11 @@ #define MINIAUDIO_IMPLEMENTATION #include "miniaudio.h" +AudioStreamMa::AudioStreamMa() +{ + memset(&m_decoder, 0, sizeof(ma_decoder)); +} + AudioStreamMa::~AudioStreamMa() { Deregister(); diff --git a/Audio/src/AudioStreamMa.hpp b/Audio/src/AudioStreamMa.hpp index b45e2dfa9..8007749ee 100644 --- a/Audio/src/AudioStreamMa.hpp +++ b/Audio/src/AudioStreamMa.hpp @@ -21,7 +21,7 @@ class AudioStreamMa : public AudioStreamBase float* GetPCM_Internal() override; uint32 GetSampleRate_Internal() const override; public: - AudioStreamMa() = default; + AudioStreamMa(); ~AudioStreamMa(); static Ref Create(class Audio* audio, const String& path, bool preload); }; diff --git a/Audio/src/AudioStreamMp3.hpp b/Audio/src/AudioStreamMp3.hpp index 9efa127ce..3b6a634c4 100644 --- a/Audio/src/AudioStreamMp3.hpp +++ b/Audio/src/AudioStreamMp3.hpp @@ -7,7 +7,7 @@ extern "C" class AudioStreamMp3 : public AudioStreamBase { - mp3_decoder_t* m_decoder; + mp3_decoder_t* m_decoder = nullptr; size_t m_mp3dataOffset = 0; size_t m_mp3dataLength = 0; int32 m_mp3samplePosition = 0; From b4ca2c6f2a10673460e129d9c71463bea254fe35 Mon Sep 17 00:00:00 2001 From: Drewol Date: Sun, 28 Jun 2020 00:48:23 +0200 Subject: [PATCH 06/11] Fix transition to song select issues and fix crash with miniaudio --- Audio/CMakeLists.txt | 2 +- Audio/src/AudioStreamMa.cpp | 11 ++++------- Audio/src/AudioStreamMa.hpp | 4 ++-- Main/include/AsyncLoadable.hpp | 4 +++- Main/src/Application.cpp | 22 ++++++++++++++++++++++ Main/src/SongSelect.cpp | 8 ++++---- Main/src/TransitionScreen.cpp | 3 +++ 7 files changed, 39 insertions(+), 15 deletions(-) diff --git a/Audio/CMakeLists.txt b/Audio/CMakeLists.txt index bf71fdec4..640332f16 100644 --- a/Audio/CMakeLists.txt +++ b/Audio/CMakeLists.txt @@ -29,7 +29,7 @@ source_group("" FILES ${PCH_FILES}) enable_precompiled_headers("${AUDIO_SRC}" "${PCH_SRC}") add_library(Audio ${AUDIO_SRC} ${PCH_FILES}) -target_compile_features(Audio PUBLIC cxx_std_14) +target_compile_features(Audio PUBLIC cxx_std_17) target_include_directories(Audio PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) target_include_directories(Audio PRIVATE ${SRCROOT} diff --git a/Audio/src/AudioStreamMa.cpp b/Audio/src/AudioStreamMa.cpp index 866fe7cfb..a49381ff2 100644 --- a/Audio/src/AudioStreamMa.cpp +++ b/Audio/src/AudioStreamMa.cpp @@ -11,10 +11,6 @@ #define MINIAUDIO_IMPLEMENTATION #include "miniaudio.h" -AudioStreamMa::AudioStreamMa() -{ - memset(&m_decoder, 0, sizeof(ma_decoder)); -} AudioStreamMa::~AudioStreamMa() { @@ -141,10 +137,11 @@ uint32 AudioStreamMa::GetSampleRate_Internal() const Ref AudioStreamMa::Create(class Audio* audio, const String& path, bool preload) { - Ref impl; + AudioStreamMa* impl = new AudioStreamMa(); if (!impl->Init(audio, path, preload)) { - impl.reset(); + delete impl; + impl = nullptr; } - return Utility::CastRef(impl); + return Utility::CastRef(Ref(impl)); } diff --git a/Audio/src/AudioStreamMa.hpp b/Audio/src/AudioStreamMa.hpp index 8007749ee..0969cb7ed 100644 --- a/Audio/src/AudioStreamMa.hpp +++ b/Audio/src/AudioStreamMa.hpp @@ -10,7 +10,7 @@ class AudioStreamMa : public AudioStreamBase int64 m_playbackPointer = 0; uint64 m_dataPosition = 0; const int sample_rate = 48000; - ma_decoder m_decoder; + ma_decoder m_decoder = { }; int m_byteRate; protected: bool Init(Audio* audio, const String& path, bool preload) override; @@ -21,7 +21,7 @@ class AudioStreamMa : public AudioStreamBase float* GetPCM_Internal() override; uint32 GetSampleRate_Internal() const override; public: - AudioStreamMa(); + AudioStreamMa() = default; ~AudioStreamMa(); static Ref Create(class Audio* audio, const String& path, bool preload); }; diff --git a/Main/include/AsyncLoadable.hpp b/Main/include/AsyncLoadable.hpp index bd676b0e5..d4f57bd03 100644 --- a/Main/include/AsyncLoadable.hpp +++ b/Main/include/AsyncLoadable.hpp @@ -10,7 +10,9 @@ class IAsyncLoadable { public: - virtual ~IAsyncLoadable() = default; + virtual ~IAsyncLoadable() { + Log("Tickable destroyed", Logger::Severity::Debug); + }; // Loads this object // returns success virtual bool AsyncLoad() = 0; diff --git a/Main/src/Application.cpp b/Main/src/Application.cpp index f6152c9e9..9dda4db02 100644 --- a/Main/src/Application.cpp +++ b/Main/src/Application.cpp @@ -23,6 +23,8 @@ #include "SkinConfig.hpp" #include "SkinHttp.hpp" #include "ShadedMesh.hpp" +#include + #ifdef EMBEDDED #define NANOVG_GLES2_IMPLEMENTATION #else @@ -1126,8 +1128,26 @@ void Application::Shutdown() g_gameWindow->Close(); } + +void PrintStack() +{ + int j, nptrs; + void *buffer[100]; + char **strings; + + nptrs = backtrace(buffer, 100); + strings = backtrace_symbols(buffer, nptrs); + for (j = 0; j < nptrs; j++) + Logf("\t%s", Logger::Severity::Debug, strings[j]); + + free(strings); +} + void Application::AddTickable(class IApplicationTickable *tickable, class IApplicationTickable *insertBefore) { + Log("Adding tickable", Logger::Severity::Debug); + + TickableChange &change = g_tickableChanges.Add(); change.mode = TickableChange::Added; change.tickable = tickable; @@ -1135,6 +1155,8 @@ void Application::AddTickable(class IApplicationTickable *tickable, class IAppli } void Application::RemoveTickable(IApplicationTickable *tickable, bool noDelete) { + Logf("Removing tickable: %s", Logger::Severity::Debug, noDelete ? "NoDelete" : "Delete"); + TickableChange &change = g_tickableChanges.Add(); if (noDelete) { diff --git a/Main/src/SongSelect.cpp b/Main/src/SongSelect.cpp index 76c0da249..f17e3cdf9 100644 --- a/Main/src/SongSelect.cpp +++ b/Main/src/SongSelect.cpp @@ -1356,7 +1356,8 @@ class SongSelect_Impl : public SongSelect float m_advanceDiff = 0.0f; float m_sensMult = 1.0f; MouseLockHandle m_lockMouse; - bool m_suspended = false; + bool m_suspended = true; + bool m_hasRestored = false; bool m_previewLoaded = true; bool m_showScores = false; uint64_t m_previewDelayTicks = 0; @@ -1933,9 +1934,7 @@ class SongSelect_Impl : public SongSelect virtual void Render(float deltaTime) { - if (m_suspended) - return; - + if (m_suspended && m_hasRestored) return; lua_getglobal(m_lua, "render"); lua_pushnumber(m_lua, deltaTime); if (lua_pcall(m_lua, 1, 0, 0) != 0) @@ -2037,6 +2036,7 @@ class SongSelect_Impl : public SongSelect { g_application->DiscordPresenceMenu("Song Select"); m_suspended = false; + m_hasRestored = true; m_previewPlayer.Restore(); m_selectionWheel->ResetLuaTables(); m_mapDatabase->ResumeSearching(); diff --git a/Main/src/TransitionScreen.cpp b/Main/src/TransitionScreen.cpp index 922a61890..66d661373 100644 --- a/Main/src/TransitionScreen.cpp +++ b/Main/src/TransitionScreen.cpp @@ -87,6 +87,7 @@ class TransitionScreen_Impl : public TransitionScreen virtual void Tick(float deltaTime) { + if(m_tickableToLoad == nullptr) return; m_transitionTimer += deltaTime; if (m_transition == Wait && m_lastComplete) @@ -104,6 +105,7 @@ class TransitionScreen_Impl : public TransitionScreen { Log("[Transition] Finished loading tickable", Logger::Severity::Info); g_application->AddTickable(m_tickableToLoad, this); + m_tickableToLoad = nullptr; } } m_lastComplete = m_loadComplete; @@ -112,6 +114,7 @@ class TransitionScreen_Impl : public TransitionScreen { if (m_tickableToLoad && m_transition == End) { + Log("transition tickable nulled", Logger::Severity::Debug); m_tickableToLoad = nullptr; } } From 74658ca673e134615ae041e532f3dc7acc1ce4a6 Mon Sep 17 00:00:00 2001 From: Drewol Date: Sun, 28 Jun 2020 00:56:40 +0200 Subject: [PATCH 07/11] Remove debug stuff --- Main/src/Application.cpp | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/Main/src/Application.cpp b/Main/src/Application.cpp index 9dda4db02..d07a8602b 100644 --- a/Main/src/Application.cpp +++ b/Main/src/Application.cpp @@ -23,7 +23,6 @@ #include "SkinConfig.hpp" #include "SkinHttp.hpp" #include "ShadedMesh.hpp" -#include #ifdef EMBEDDED #define NANOVG_GLES2_IMPLEMENTATION @@ -1128,21 +1127,6 @@ void Application::Shutdown() g_gameWindow->Close(); } - -void PrintStack() -{ - int j, nptrs; - void *buffer[100]; - char **strings; - - nptrs = backtrace(buffer, 100); - strings = backtrace_symbols(buffer, nptrs); - for (j = 0; j < nptrs; j++) - Logf("\t%s", Logger::Severity::Debug, strings[j]); - - free(strings); -} - void Application::AddTickable(class IApplicationTickable *tickable, class IApplicationTickable *insertBefore) { Log("Adding tickable", Logger::Severity::Debug); From 7a067f4c057bfa290b744f411f11f2814dfbd845 Mon Sep 17 00:00:00 2001 From: Drewol Date: Fri, 10 Jul 2020 16:32:53 +0200 Subject: [PATCH 08/11] Fix transition screen flashing --- Main/include/TransitionScreen.hpp | 4 ++-- Main/src/SongSelect.cpp | 2 -- Main/src/TransitionScreen.cpp | 13 ++++++------- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Main/include/TransitionScreen.hpp b/Main/include/TransitionScreen.hpp index ff95237c5..e9d1e2ae9 100644 --- a/Main/include/TransitionScreen.hpp +++ b/Main/include/TransitionScreen.hpp @@ -10,8 +10,8 @@ class TransitionScreen : public IApplicationTickable public: virtual ~TransitionScreen() = default; static TransitionScreen* Create(); - virtual void TransitionTo(class Game* next) = 0; - virtual void TransitionTo(IAsyncLoadableApplicationTickable* next, bool noCancel = true) = 0; + virtual void TransitionTo(class Game* next, IApplicationTickable* before = nullptr) = 0; + virtual void TransitionTo(IAsyncLoadableApplicationTickable* next, bool noCancel = true, IApplicationTickable* before = nullptr) = 0; virtual void RemoveOnComplete(DelegateHandle handle) = 0; virtual void RemoveAllOnComplete(void* handle) = 0; diff --git a/Main/src/SongSelect.cpp b/Main/src/SongSelect.cpp index f17e3cdf9..5b77a4dac 100644 --- a/Main/src/SongSelect.cpp +++ b/Main/src/SongSelect.cpp @@ -1648,7 +1648,6 @@ class SongSelect_Impl : public SongSelect // When we are in multiplayer, just report the song and exit instead m_multiplayer->SetSelectedMap(folder, m_selectionWheel->GetSelectedChart()); - m_suspended = true; g_application->RemoveTickable(this); return; } @@ -1662,7 +1661,6 @@ class SongSelect_Impl : public SongSelect return; } game->GetScoring().autoplay = autoplay; - m_suspended = true; // Transition to game g_transition->TransitionTo(game); diff --git a/Main/src/TransitionScreen.cpp b/Main/src/TransitionScreen.cpp index 66d661373..56e40334e 100644 --- a/Main/src/TransitionScreen.cpp +++ b/Main/src/TransitionScreen.cpp @@ -56,7 +56,7 @@ class TransitionScreen_Impl : public TransitionScreen m_loadComplete = false; m_transitionTimer = 0.0f; m_lastComplete = false; - m_transition = In; + m_transition = Transition::In; } public: @@ -104,8 +104,7 @@ class TransitionScreen_Impl : public TransitionScreen if (m_tickableToLoad) { Log("[Transition] Finished loading tickable", Logger::Severity::Info); - g_application->AddTickable(m_tickableToLoad, this); - m_tickableToLoad = nullptr; + g_application->AddTickable(m_tickableToLoad); } } m_lastComplete = m_loadComplete; @@ -157,7 +156,7 @@ class TransitionScreen_Impl : public TransitionScreen return true; } - virtual void TransitionTo(IAsyncLoadableApplicationTickable *next, bool noCancel) + virtual void TransitionTo(IAsyncLoadableApplicationTickable *next, bool noCancel, IApplicationTickable* before) { m_isGame = false; m_InitTransition(next); @@ -182,10 +181,10 @@ class TransitionScreen_Impl : public TransitionScreen g_jobSheduler->Queue(m_loadingJob); } - g_application->AddTickable(this); + g_application->AddTickable(this, before); } - virtual void TransitionTo(Game *next) + virtual void TransitionTo(Game* next, IApplicationTickable* before) { m_isGame = true; m_canCancel = true; @@ -262,7 +261,7 @@ class TransitionScreen_Impl : public TransitionScreen { g_jobSheduler->Queue(m_loadingJob); } - g_application->AddTickable(this); + g_application->AddTickable(this, before); } void Render(float deltaTime) From 5a69b3fed26f9b5000f9bea203797342dcff7342 Mon Sep 17 00:00:00 2001 From: Drewol Date: Sat, 11 Jul 2020 14:06:49 +0200 Subject: [PATCH 09/11] Fix custom flangers --- Audio/src/DSP.cpp | 32 +++++++------ Beatmap/include/Beatmap/AudioEffects.hpp | 3 ++ Beatmap/src/AudioEffects.cpp | 20 ++++++++ Beatmap/src/BeatmapFromKSH.cpp | 59 +++++++++++++++++++----- Main/src/Audio/GameAudioEffects.cpp | 3 +- 5 files changed, 88 insertions(+), 29 deletions(-) diff --git a/Audio/src/DSP.cpp b/Audio/src/DSP.cpp index 608cdf7ed..ce7b02e3a 100644 --- a/Audio/src/DSP.cpp +++ b/Audio/src/DSP.cpp @@ -451,15 +451,18 @@ float PhaserDSP::APF::Update(float in) return y; } -void FlangerDSP::SetLength(double length) -{ +void FlangerDSP::SetLength(double length) { double flength = length / 1000.0 * audio->GetSampleRate(); m_length = (uint32)flength; } -void FlangerDSP::SetDelayRange(uint32 min, uint32 max) + +void FlangerDSP::SetDelayRange(uint32 offset, uint32 depth) { - assert(max > min); // Assuming 44100hz is the base sample rate + uint32 max = offset + depth; + uint32 min = offset; + + float mult = (float)audio->GetSampleRate() / 44100.f; m_min = min * mult; m_max = max * mult; @@ -468,22 +471,21 @@ void FlangerDSP::SetDelayRange(uint32 min, uint32 max) } void FlangerDSP::Process(float* out, uint32 numSamples) { - float* data = m_sampleBuffer.data(); - - if(m_bufferLength <= 0) + if (m_bufferLength <= 0) return; uint32 startSample = startTime * audio->GetSampleRate() / 1000.0; uint32 currentSample = audioBase->GetPosition() * audio->GetSampleRate() / 1000.0; + float* data = m_sampleBuffer.data(); for(uint32 i = 0; i < numSamples; i++) { - if(currentSample + i < startSample) + if (currentSample + i < startSample) { continue; } // Determine where we want to sample past samples - float f = fmodf(((float)m_time / (float)m_length), 1.f); + float f = fmodf(((float)m_time / (float)m_length), 1.f); f = fabsf(f * 2 - 1); uint32 d = (uint32)(m_min + ((m_max - 1) - m_min) * (f)); @@ -493,17 +495,17 @@ void FlangerDSP::Process(float* out, uint32 numSamples) samplePos = m_bufferLength + samplePos; // Inject new sample - data[m_bufferOffset + 0] = out[i*2]; - data[m_bufferOffset + 1] = out[i*2+1]; + data[m_bufferOffset + 0] = out[i * 2]; + data[m_bufferOffset + 1] = out[i * 2 + 1]; // Apply delay - out[i * 2] = (data[samplePos] + out[i*2]) * 0.5f * mix + + out[i * 2] = (data[samplePos] + out[i * 2]) * 0.5f * mix + out[i * 2] * (1 - mix); - out[i * 2 + 1] = (data[samplePos+1] + out[i*2+1]) * 0.5f * mix + - out[i * 2+1] * (1 - mix); + out[i * 2 + 1] = (data[samplePos + 1] + out[i * 2 + 1]) * 0.5f * mix + + out[i * 2 + 1] * (1 - mix); m_bufferOffset += 2; - if(m_bufferOffset >= m_bufferLength) + if (m_bufferOffset >= m_bufferLength) m_bufferOffset = 0; m_time++; } diff --git a/Beatmap/include/Beatmap/AudioEffects.hpp b/Beatmap/include/Beatmap/AudioEffects.hpp index e8683455c..49cc328f1 100644 --- a/Beatmap/include/Beatmap/AudioEffects.hpp +++ b/Beatmap/include/Beatmap/AudioEffects.hpp @@ -119,6 +119,9 @@ struct AudioEffect // Use this to get default effect settings static const AudioEffect& GetDefault(EffectType type); + + void SetDefaultEffectParams(int16* params); + // The effect type EffectType type = EffectType::None; diff --git a/Beatmap/src/AudioEffects.cpp b/Beatmap/src/AudioEffects.cpp index 78ac3ac58..77a021ef6 100644 --- a/Beatmap/src/AudioEffects.cpp +++ b/Beatmap/src/AudioEffects.cpp @@ -103,6 +103,7 @@ static AudioEffect CreateDefault(EffectType type) ret.wobble.q = FloatRange(2.0f); break; case EffectType::Flanger: + ret.duration = TimeRange(2000); ret.flanger.offset = IntRange(10); ret.flanger.depth = IntRange(40); break; @@ -134,3 +135,22 @@ const AudioEffect& AudioEffect::GetDefault(EffectType type) assert((size_t)type < defaults.effects.size()); return defaults.effects[(size_t)type]; } + +void AudioEffect::SetDefaultEffectParams(int16* params) +{ + // Set defaults based on effect type + switch (type) + { + case EffectType::Bitcrush: + params[0] = bitcrusher.reduction.Sample(1); + break; + case EffectType::Wobble: + break; + case EffectType::Flanger: + params[0] = flanger.depth.Sample(1); + params[1] = flanger.offset.Sample(1); + break; + default: + break; + } +} diff --git a/Beatmap/src/BeatmapFromKSH.cpp b/Beatmap/src/BeatmapFromKSH.cpp index cad5ece0f..fb487f8b2 100644 --- a/Beatmap/src/BeatmapFromKSH.cpp +++ b/Beatmap/src/BeatmapFromKSH.cpp @@ -164,16 +164,30 @@ struct MultiParamRange r.isRange = isRange; return r; } - EffectParam ToDurationParam() + EffectParam ToDurationParam(bool isAbsolute) { - auto r = params[0].type == MultiParam::Float ? EffectParam(params[0].fval, params[1].fval) : EffectParam(params[0].ival, params[1].ival); + EffectParam r; + if (isAbsolute) + { + if (params[0].type == MultiParam::Float) + { + r = EffectParam((int)(1000.f * params[0].fval), (int)(1000.f * params[1].fval)); + } + else + { + r = EffectParam(params[0].ival, params[1].ival); + } + } + else { + r = params[0].type == MultiParam::Float ? EffectParam(params[0].fval, params[1].fval) : EffectParam(params[0].ival, params[1].ival); + } r.isRange = isRange; return r; } EffectParam ToSamplesParam() { EffectParam r; - if (params[0].type == MultiParam::Int) + if (params[0].type == MultiParam::Int || params[0].type == MultiParam::Samples) r = EffectParam(params[0].ival, params[1].ival); r.isRange = isRange; return r; @@ -305,11 +319,11 @@ AudioEffect ParseCustomEffect(const KShootEffectDefinition &def, Vector target = param->ToFloatParam(); } }; - auto AssignDurationIfSet = [&](EffectParam &target, const String &name) { + auto AssignDurationIfSet = [&](EffectParam &target, const String &name, bool absolute) { auto *param = params.Find(name); if (param) { - target = param->ToDurationParam(); + target = param->ToDurationParam(absolute); } }; auto AssignSamplesIfSet = [&](EffectParam &target, const String &name) { @@ -340,29 +354,31 @@ AudioEffect ParseCustomEffect(const KShootEffectDefinition &def, Vector AssignSamplesIfSet(effect.bitcrusher.reduction, "amount"); break; case EffectType::Echo: - AssignDurationIfSet(effect.duration, "waveLength"); + AssignDurationIfSet(effect.duration, "waveLength", false); AssignFloatIfSet(effect.echo.feedback, "feedbackLevel"); break; case EffectType::Flanger: - AssignDurationIfSet(effect.duration, "period"); + AssignDurationIfSet(effect.duration, "period", true); + AssignIntIfSet(effect.flanger.depth, "depth"); + AssignIntIfSet(effect.flanger.offset, "delay"); break; case EffectType::Gate: - AssignDurationIfSet(effect.duration, "waveLength"); + AssignDurationIfSet(effect.duration, "waveLength", false); AssignFloatIfSet(effect.gate.gate, "rate"); break; case EffectType::Retrigger: - AssignDurationIfSet(effect.duration, "waveLength"); + AssignDurationIfSet(effect.duration, "waveLength", false); AssignFloatIfSet(effect.retrigger.gate, "rate"); - AssignDurationIfSet(effect.retrigger.reset, "updatePeriod"); + AssignDurationIfSet(effect.retrigger.reset, "updatePeriod", false); break; case EffectType::Wobble: - AssignDurationIfSet(effect.duration, "waveLength"); + AssignDurationIfSet(effect.duration, "waveLength", false); AssignFloatIfSet(effect.wobble.min, "loFreq"); AssignFloatIfSet(effect.wobble.max, "hiFreq"); AssignFloatIfSet(effect.wobble.q, "Q"); break; case EffectType::TapeStop: - AssignDurationIfSet(effect.duration, "speed"); + AssignDurationIfSet(effect.duration, "speed", false); break; case EffectType::SwitchAudio: AssignIntIfSet(effect.switchaudio.index, "index"); @@ -656,6 +672,25 @@ bool Beatmap::m_ProcessKShootMap(BinaryStream &input, bool metadataOnly) else paramsOut[0] = atoi(*effectParams); } + else //set default params + { + if (*type < EffectType::UserDefined0) { + switch (*type) + { + case EffectType::Flanger: + paramsOut[0] = 45; + paramsOut[1] = 15; + break; + + default: + break; + } + } + else { + m_customEffects.at(*type).SetDefaultEffectParams(paramsOut); + } + } + return *type; }; diff --git a/Main/src/Audio/GameAudioEffects.cpp b/Main/src/Audio/GameAudioEffects.cpp index 0f1296d7b..bf2b237a5 100644 --- a/Main/src/Audio/GameAudioEffects.cpp +++ b/Main/src/Audio/GameAudioEffects.cpp @@ -190,8 +190,7 @@ void GameAudioEffect::SetParams(DSP* dsp, AudioPlayback& playback, HoldObjectSta { FlangerDSP* fl = (FlangerDSP*)dsp; double delay = (noteDuration) / 1000.0; - fl->SetLength(object->effectParams[0]); - fl->SetDelayRange(10, 40); + fl->SetDelayRange(object->effectParams[1], object->effectParams[0]); break; } case EffectType::PitchShift: From 2c14cfc6b470f7849f425a8c4140500c42ee8801 Mon Sep 17 00:00:00 2001 From: Drewol Date: Sat, 11 Jul 2020 18:18:11 +0200 Subject: [PATCH 10/11] Add null check for flanger buffer --- Audio/src/DSP.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Audio/src/DSP.cpp b/Audio/src/DSP.cpp index ce7b02e3a..b6ad03831 100644 --- a/Audio/src/DSP.cpp +++ b/Audio/src/DSP.cpp @@ -473,10 +473,12 @@ void FlangerDSP::Process(float* out, uint32 numSamples) { if (m_bufferLength <= 0) return; + float* data = m_sampleBuffer.data(); + if (data == nullptr) + return; uint32 startSample = startTime * audio->GetSampleRate() / 1000.0; uint32 currentSample = audioBase->GetPosition() * audio->GetSampleRate() / 1000.0; - float* data = m_sampleBuffer.data(); for(uint32 i = 0; i < numSamples; i++) { From 39b45e4747577655be29557939737a6d86c2c5b6 Mon Sep 17 00:00:00 2001 From: Drewol Date: Sat, 18 Jul 2020 11:29:36 +0200 Subject: [PATCH 11/11] Fix background errorOnLib not using const char* --- Main/src/Background.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Main/src/Background.cpp b/Main/src/Background.cpp index 6a7a6bff9..36a12741e 100644 --- a/Main/src/Background.cpp +++ b/Main/src/Background.cpp @@ -104,7 +104,7 @@ class TestBackground : public FullscreenBackground }; - auto errorOnLib = [this](char* name) + auto errorOnLib = [this](const char* name) { luaL_dostring(lua, (String(name) + " = {}; setmetatable(" + String(name) + ", {__index = function() error(\"Song background cannot access the '" + name + "' library\") end})").c_str()); };