diff --git a/project/Easy2D.sln b/Easy2D.sln similarity index 69% rename from project/Easy2D.sln rename to Easy2D.sln index 1a1b9ec4..c37868cd 100644 --- a/project/Easy2D.sln +++ b/Easy2D.sln @@ -2,17 +2,21 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.28307.271 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HelloWorld", "HelloWorld\HelloWorld.vcxproj", "{3561A359-F9FD-48AB-A977-34E7E568BC8E}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HelloWorld", "samples\HelloWorld\HelloWorld.vcxproj", "{3561A359-F9FD-48AB-A977-34E7E568BC8E}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Easy2D", "Easy2D\Easy2D.vcxproj", "{FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Easy2D", "src\easy2d\Easy2D.vcxproj", "{FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Samples", "Samples\Samples.vcxproj", "{45F5738D-CDF2-4024-974D-25B64F9043DE}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Easy2D-ImGui", "src\easy2d-imgui\Easy2D-ImGui.vcxproj", "{23AFF03B-A670-4C33-B790-18EEC82C61AE}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Box2D", "..\3rd-party\box2d\Box2D.vcxproj", "{A434E80C-1049-10BE-D9CA-B31D459E0CEF}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Easy2D-Audio", "src\easy2d-audio\Easy2D-Audio.vcxproj", "{5D45F66B-BECD-4909-BCFC-C0F3CED9D0A2}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Box2DSample", "Box2DSample\Box2DSample.vcxproj", "{324CFF47-4EB2-499A-BE5F-53A82E3BA14B}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Samples", "samples\Samples\Samples.vcxproj", "{45F5738D-CDF2-4024-974D-25B64F9043DE}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ImGuiSample", "ImGuiSample\ImGuiSample.vcxproj", "{6152D36C-EA40-4968-A696-244B6CA58395}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ImGuiSample", "samples\ImGuiSample\ImGuiSample.vcxproj", "{6152D36C-EA40-4968-A696-244B6CA58395}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Box2D", "3rd-party\box2d\Box2D.vcxproj", "{A434E80C-1049-10BE-D9CA-B31D459E0CEF}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Box2DSample", "samples\Box2DSample\Box2DSample.vcxproj", "{324CFF47-4EB2-499A-BE5F-53A82E3BA14B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -72,6 +76,22 @@ Global {6152D36C-EA40-4968-A696-244B6CA58395}.Release|Win32.Build.0 = Release|Win32 {6152D36C-EA40-4968-A696-244B6CA58395}.Release|x64.ActiveCfg = Release|x64 {6152D36C-EA40-4968-A696-244B6CA58395}.Release|x64.Build.0 = Release|x64 + {23AFF03B-A670-4C33-B790-18EEC82C61AE}.Debug|Win32.ActiveCfg = Debug|Win32 + {23AFF03B-A670-4C33-B790-18EEC82C61AE}.Debug|Win32.Build.0 = Debug|Win32 + {23AFF03B-A670-4C33-B790-18EEC82C61AE}.Debug|x64.ActiveCfg = Debug|x64 + {23AFF03B-A670-4C33-B790-18EEC82C61AE}.Debug|x64.Build.0 = Debug|x64 + {23AFF03B-A670-4C33-B790-18EEC82C61AE}.Release|Win32.ActiveCfg = Release|Win32 + {23AFF03B-A670-4C33-B790-18EEC82C61AE}.Release|Win32.Build.0 = Release|Win32 + {23AFF03B-A670-4C33-B790-18EEC82C61AE}.Release|x64.ActiveCfg = Release|x64 + {23AFF03B-A670-4C33-B790-18EEC82C61AE}.Release|x64.Build.0 = Release|x64 + {5D45F66B-BECD-4909-BCFC-C0F3CED9D0A2}.Debug|Win32.ActiveCfg = Debug|Win32 + {5D45F66B-BECD-4909-BCFC-C0F3CED9D0A2}.Debug|Win32.Build.0 = Debug|Win32 + {5D45F66B-BECD-4909-BCFC-C0F3CED9D0A2}.Debug|x64.ActiveCfg = Debug|x64 + {5D45F66B-BECD-4909-BCFC-C0F3CED9D0A2}.Debug|x64.Build.0 = Debug|x64 + {5D45F66B-BECD-4909-BCFC-C0F3CED9D0A2}.Release|Win32.ActiveCfg = Release|Win32 + {5D45F66B-BECD-4909-BCFC-C0F3CED9D0A2}.Release|Win32.Build.0 = Release|Win32 + {5D45F66B-BECD-4909-BCFC-C0F3CED9D0A2}.Release|x64.ActiveCfg = Release|x64 + {5D45F66B-BECD-4909-BCFC-C0F3CED9D0A2}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/project/Easy2D/Easy2D.vcxproj b/project/Easy2D/Easy2D.vcxproj deleted file mode 100644 index 91b69c1a..00000000 --- a/project/Easy2D/Easy2D.vcxproj +++ /dev/null @@ -1,266 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF} - Easy2D - - - - StaticLibrary - true - Unicode - - - StaticLibrary - true - Unicode - - - StaticLibrary - false - true - Unicode - - - StaticLibrary - false - true - Unicode - - - - - - - - - - - - - - - - - - - $(ProjectDir)$(Configuration)\ - $(ProjectDir)$(Configuration)\ - - - $(ProjectDir)$(Configuration)\ - $(ProjectDir)$(Configuration)\ - - - $(ProjectDir)$(Configuration)\ - $(ProjectDir)$(Configuration)\ - - - $(ProjectDir)$(Configuration)\ - $(ProjectDir)$(Configuration)\ - - - - Level3 - Disabled - true - - - Console - true - - - - - Level3 - Disabled - true - - - Console - true - - - - - Level3 - MaxSpeed - true - true - false - true - - - Console - true - true - true - - - - - Level3 - MaxSpeed - true - true - false - true - - - Console - true - true - true - - - - - - \ No newline at end of file diff --git a/project/Easy2D/Easy2D.vcxproj.filters b/project/Easy2D/Easy2D.vcxproj.filters deleted file mode 100644 index 8a075ec5..00000000 --- a/project/Easy2D/Easy2D.vcxproj.filters +++ /dev/null @@ -1,399 +0,0 @@ - - - - - {896bdedf-6e82-449b-9b6e-0bc69f3699b1} - - - {80bc6386-2b70-4bae-993c-649a55163a1b} - - - {68eac919-ee87-4030-a033-c251731928f5} - - - {07b6d541-4a1b-472a-aae0-daf9d082fe84} - - - {a9793a75-3212-4e31-a443-b23f18a1e136} - - - {836608a6-7443-48f9-8acd-18d3ba664348} - - - {86e2d0f2-a9d0-4456-b6a5-d480228bbf82} - - - - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - math - - - math - - - math - - - utils - - - utils - - - utils - - - ui - - - ui - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - math - - - core - - - core - - - math - - - core - - - core - - - core - - - core - - - core - - - core - - - math - - - utils - - - core - - - core - - - core - - - core - - - core - - - math - - - dx - - - dx - - - dx - - - dx - - - dx - - - dx - - - audio - - - audio - - - audio - - - audio - - - audio - - - core - - - audio - - - core - - - - - common - - - common - - - common - - - common - - - common - - - common - - - common - - - core - - - common - - - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - utils - - - utils - - - utils - - - ui - - - ui - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - core - - - utils - - - core - - - core - - - core - - - dx - - - dx - - - dx - - - dx - - - audio - - - audio - - - audio - - - audio - - - audio - - - audio - - - core - - - common - - - \ No newline at end of file diff --git a/project/Box2DSample/Box2DSample.filters b/samples/Box2DSample/Box2DSample.filters similarity index 100% rename from project/Box2DSample/Box2DSample.filters rename to samples/Box2DSample/Box2DSample.filters diff --git a/project/Box2DSample/Box2DSample.vcxproj b/samples/Box2DSample/Box2DSample.vcxproj similarity index 100% rename from project/Box2DSample/Box2DSample.vcxproj rename to samples/Box2DSample/Box2DSample.vcxproj diff --git a/project/Box2DSample/circle.png b/samples/Box2DSample/circle.png similarity index 100% rename from project/Box2DSample/circle.png rename to samples/Box2DSample/circle.png diff --git a/project/Box2DSample/main.cpp b/samples/Box2DSample/main.cpp similarity index 100% rename from project/Box2DSample/main.cpp rename to samples/Box2DSample/main.cpp diff --git a/project/Box2DSample/square.png b/samples/Box2DSample/square.png similarity index 100% rename from project/Box2DSample/square.png rename to samples/Box2DSample/square.png diff --git a/project/HelloWorld/HelloWorld.vcxproj b/samples/HelloWorld/HelloWorld.vcxproj similarity index 98% rename from project/HelloWorld/HelloWorld.vcxproj rename to samples/HelloWorld/HelloWorld.vcxproj index 70887eda..505f8ffc 100644 --- a/project/HelloWorld/HelloWorld.vcxproj +++ b/samples/HelloWorld/HelloWorld.vcxproj @@ -1,4 +1,4 @@ - + @@ -143,7 +143,7 @@ - + {ff7f943d-a89c-4e6c-97cf-84f7d8ff8edf} diff --git a/project/HelloWorld/HelloWorld.vcxproj.filters b/samples/HelloWorld/HelloWorld.vcxproj.filters similarity index 100% rename from project/HelloWorld/HelloWorld.vcxproj.filters rename to samples/HelloWorld/HelloWorld.vcxproj.filters diff --git a/project/HelloWorld/main.cpp b/samples/HelloWorld/main.cpp similarity index 100% rename from project/HelloWorld/main.cpp rename to samples/HelloWorld/main.cpp diff --git a/project/ImGuiSample/.gitignore b/samples/ImGuiSample/.gitignore similarity index 100% rename from project/ImGuiSample/.gitignore rename to samples/ImGuiSample/.gitignore diff --git a/project/ImGuiSample/ImGuiSample.vcxproj b/samples/ImGuiSample/ImGuiSample.vcxproj similarity index 85% rename from project/ImGuiSample/ImGuiSample.vcxproj rename to samples/ImGuiSample/ImGuiSample.vcxproj index f7945346..f57e1c3d 100644 --- a/project/ImGuiSample/ImGuiSample.vcxproj +++ b/samples/ImGuiSample/ImGuiSample.vcxproj @@ -132,29 +132,13 @@ - - - - - - - - - - - - - - - - - - - - + + {23aff03b-a670-4c33-b790-18eec82c61ae} + + {ff7f943d-a89c-4e6c-97cf-84f7d8ff8edf} diff --git a/samples/ImGuiSample/ImGuiSample.vcxproj.filters b/samples/ImGuiSample/ImGuiSample.vcxproj.filters new file mode 100644 index 00000000..4327830c --- /dev/null +++ b/samples/ImGuiSample/ImGuiSample.vcxproj.filters @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/project/ImGuiSample/main.cpp b/samples/ImGuiSample/main.cpp similarity index 100% rename from project/ImGuiSample/main.cpp rename to samples/ImGuiSample/main.cpp diff --git a/project/Samples/Demo1.h b/samples/Samples/Demo1.h similarity index 100% rename from project/Samples/Demo1.h rename to samples/Samples/Demo1.h diff --git a/project/Samples/Demo2.h b/samples/Samples/Demo2.h similarity index 100% rename from project/Samples/Demo2.h rename to samples/Samples/Demo2.h diff --git a/project/Samples/Demo3.h b/samples/Samples/Demo3.h similarity index 100% rename from project/Samples/Demo3.h rename to samples/Samples/Demo3.h diff --git a/project/Samples/Samples.vcxproj b/samples/Samples/Samples.vcxproj similarity index 95% rename from project/Samples/Samples.vcxproj rename to samples/Samples/Samples.vcxproj index 0c28845e..ea9b83c2 100644 --- a/project/Samples/Samples.vcxproj +++ b/samples/Samples/Samples.vcxproj @@ -19,7 +19,6 @@ - 15.0 {45F5738D-CDF2-4024-974D-25B64F9043DE} Samples @@ -82,7 +81,7 @@ Level3 Disabled true - ../../src/easy2d + ../../src/easy2d;../../src/easy2d-audio; true @@ -144,7 +143,10 @@ - + + {5d45f66b-becd-4909-bcfc-c0f3ced9d0a2} + + {ff7f943d-a89c-4e6c-97cf-84f7d8ff8edf} diff --git a/project/Samples/Samples.vcxproj.filters b/samples/Samples/Samples.vcxproj.filters similarity index 100% rename from project/Samples/Samples.vcxproj.filters rename to samples/Samples/Samples.vcxproj.filters diff --git a/project/Samples/common.h b/samples/Samples/common.h similarity index 85% rename from project/Samples/common.h rename to samples/Samples/common.h index b3e36e18..4fb123f2 100644 --- a/project/Samples/common.h +++ b/samples/Samples/common.h @@ -2,6 +2,7 @@ #pragma once #include "easy2d.h" +#include "easy2d-audio.h" using namespace easy2d; diff --git a/project/Samples/include-forwards.h b/samples/Samples/include-forwards.h similarity index 100% rename from project/Samples/include-forwards.h rename to samples/Samples/include-forwards.h diff --git a/project/Samples/main.cpp b/samples/Samples/main.cpp similarity index 100% rename from project/Samples/main.cpp rename to samples/Samples/main.cpp diff --git a/project/Samples/res/man.png b/samples/Samples/res/man.png similarity index 100% rename from project/Samples/res/man.png rename to samples/Samples/res/man.png diff --git a/project/Samples/res/music.wav b/samples/Samples/res/music.wav similarity index 100% rename from project/Samples/res/music.wav rename to samples/Samples/res/music.wav diff --git a/src/easy2d-audio/Easy2D-Audio.vcxproj b/src/easy2d-audio/Easy2D-Audio.vcxproj new file mode 100644 index 00000000..d4bdddb1 --- /dev/null +++ b/src/easy2d-audio/Easy2D-Audio.vcxproj @@ -0,0 +1,159 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {5D45F66B-BECD-4909-BCFC-C0F3CED9D0A2} + Win32Proj + + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + true + ../easy2d + + + Windows + true + + + + + + + Level3 + Disabled + true + + + Windows + true + + + + + + + Level3 + MaxSpeed + true + true + true + + + Windows + true + true + true + + + + + + + Level3 + MaxSpeed + true + true + true + + + Windows + true + true + true + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/easy2d-audio/Easy2D-Audio.vcxproj.filters b/src/easy2d-audio/Easy2D-Audio.vcxproj.filters new file mode 100644 index 00000000..eea586ae --- /dev/null +++ b/src/easy2d-audio/Easy2D-Audio.vcxproj.filters @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/easy2d/audio/Music.cpp b/src/easy2d-audio/Music.cpp similarity index 98% rename from src/easy2d/audio/Music.cpp rename to src/easy2d-audio/Music.cpp index d87bcbb8..a27e4697 100644 --- a/src/easy2d/audio/Music.cpp +++ b/src/easy2d-audio/Music.cpp @@ -18,11 +18,9 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#include "easy2d-audio.h" #include "Music.h" #include "Transcoder.h" -#include "audio.h" -#include "../core/logs.h" -#include "../core/modules.h" namespace easy2d { diff --git a/src/easy2d/audio/Music.h b/src/easy2d-audio/Music.h similarity index 96% rename from src/easy2d/audio/Music.h rename to src/easy2d-audio/Music.h index 59282f19..50db0a5a 100644 --- a/src/easy2d/audio/Music.h +++ b/src/easy2d-audio/Music.h @@ -19,8 +19,6 @@ // THE SOFTWARE. #pragma once -#include "../core/include-forwards.h" -#include "../core/Resource.h" #include "Voice.h" namespace easy2d diff --git a/src/easy2d/audio/Player.cpp b/src/easy2d-audio/Player.cpp similarity index 99% rename from src/easy2d/audio/Player.cpp rename to src/easy2d-audio/Player.cpp index 7f1b16d8..e49e2469 100644 --- a/src/easy2d/audio/Player.cpp +++ b/src/easy2d-audio/Player.cpp @@ -18,6 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#include "easy2d-audio.h" #include "Player.h" namespace easy2d diff --git a/src/easy2d/audio/Player.h b/src/easy2d-audio/Player.h similarity index 97% rename from src/easy2d/audio/Player.h rename to src/easy2d-audio/Player.h index 1abae46d..004310b9 100644 --- a/src/easy2d/audio/Player.h +++ b/src/easy2d-audio/Player.h @@ -19,8 +19,6 @@ // THE SOFTWARE. #pragma once -#include "../core/include-forwards.h" -#include "Music.h" namespace easy2d { diff --git a/src/easy2d/audio/Transcoder.cpp b/src/easy2d-audio/Transcoder.cpp similarity index 98% rename from src/easy2d/audio/Transcoder.cpp rename to src/easy2d-audio/Transcoder.cpp index ce9a66a2..710af127 100644 --- a/src/easy2d/audio/Transcoder.cpp +++ b/src/easy2d-audio/Transcoder.cpp @@ -22,11 +22,9 @@ # define INITGUID // MFAudioFormat_PCM, MF_MT_MAJOR_TYPE, MF_MT_SUBTYPE, MFMediaType_Audio #endif +#include "easy2d-audio.h" #include "Transcoder.h" #include "audio-modules.h" -#include "../common/ComPtr.hpp" -#include "../core/logs.h" -#include "../core/modules.h" namespace easy2d { diff --git a/src/easy2d/audio/Transcoder.h b/src/easy2d-audio/Transcoder.h similarity index 98% rename from src/easy2d/audio/Transcoder.h rename to src/easy2d-audio/Transcoder.h index bc07e3b1..dcfa53af 100644 --- a/src/easy2d/audio/Transcoder.h +++ b/src/easy2d-audio/Transcoder.h @@ -19,7 +19,6 @@ // THE SOFTWARE. #pragma once -#include "../core/Resource.h" #include #include #include diff --git a/src/easy2d/audio/Voice.cpp b/src/easy2d-audio/Voice.cpp similarity index 99% rename from src/easy2d/audio/Voice.cpp rename to src/easy2d-audio/Voice.cpp index fe46f23e..48dd3fe7 100644 --- a/src/easy2d/audio/Voice.cpp +++ b/src/easy2d-audio/Voice.cpp @@ -18,8 +18,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#include "easy2d-audio.h" #include "Voice.h" -#include "audio.h" namespace easy2d { diff --git a/src/easy2d/audio/Voice.h b/src/easy2d-audio/Voice.h similarity index 96% rename from src/easy2d/audio/Voice.h rename to src/easy2d-audio/Voice.h index 7993e8f3..ce6cd830 100644 --- a/src/easy2d/audio/Voice.h +++ b/src/easy2d-audio/Voice.h @@ -19,8 +19,6 @@ // THE SOFTWARE. #pragma once -#include "../macros.h" -#include "../common/noncopyable.hpp" #include namespace easy2d diff --git a/src/easy2d/audio/audio-modules.cpp b/src/easy2d-audio/audio-modules.cpp similarity index 99% rename from src/easy2d/audio/audio-modules.cpp rename to src/easy2d-audio/audio-modules.cpp index 748b1363..9c4e72d7 100644 --- a/src/easy2d/audio/audio-modules.cpp +++ b/src/easy2d-audio/audio-modules.cpp @@ -18,8 +18,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#include "easy2d-audio.h" #include "audio-modules.h" -#include "../core/logs.h" namespace easy2d { diff --git a/src/easy2d/audio/audio-modules.h b/src/easy2d-audio/audio-modules.h similarity index 99% rename from src/easy2d/audio/audio-modules.h rename to src/easy2d-audio/audio-modules.h index d7b3e184..872d12e5 100644 --- a/src/easy2d/audio/audio-modules.h +++ b/src/easy2d-audio/audio-modules.h @@ -19,7 +19,6 @@ // THE SOFTWARE. #pragma once -#include "../macros.h" #include #include #include diff --git a/src/easy2d/audio/audio.cpp b/src/easy2d-audio/audio.cpp similarity index 99% rename from src/easy2d/audio/audio.cpp rename to src/easy2d-audio/audio.cpp index 4619dc42..8ca1738f 100644 --- a/src/easy2d/audio/audio.cpp +++ b/src/easy2d-audio/audio.cpp @@ -18,9 +18,9 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +#include "easy2d-audio.h" #include "audio.h" #include "audio-modules.h" -#include "../core/logs.h" namespace easy2d { diff --git a/src/easy2d/audio/audio.h b/src/easy2d-audio/audio.h similarity index 94% rename from src/easy2d/audio/audio.h rename to src/easy2d-audio/audio.h index 22deb128..0c882260 100644 --- a/src/easy2d/audio/audio.h +++ b/src/easy2d-audio/audio.h @@ -19,9 +19,6 @@ // THE SOFTWARE. #pragma once -#include "../core/include-forwards.h" -#include "../core/Component.h" -#include "../common/Singleton.hpp" #include "Voice.h" namespace easy2d diff --git a/src/easy2d-audio/easy2d-audio.h b/src/easy2d-audio/easy2d-audio.h new file mode 100644 index 00000000..cf45f725 --- /dev/null +++ b/src/easy2d-audio/easy2d-audio.h @@ -0,0 +1,8 @@ +// Copyright (C) 2019 Nomango + +#pragma once +#include "easy2d.h" + +#include "audio.h" +#include "Music.h" +#include "Player.h" diff --git a/src/easy2d-imgui/Easy2D-ImGui.vcxproj b/src/easy2d-imgui/Easy2D-ImGui.vcxproj new file mode 100644 index 00000000..6d14501a --- /dev/null +++ b/src/easy2d-imgui/Easy2D-ImGui.vcxproj @@ -0,0 +1,163 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {23AFF03B-A670-4C33-B790-18EEC82C61AE} + Win32Proj + + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + true + ../easy2d;../../3rd-party/ImGui; + + + Windows + true + + + + + + + Level3 + Disabled + true + + + Windows + true + + + + + + + Level3 + MaxSpeed + true + true + true + + + Windows + true + true + true + + + + + + + Level3 + MaxSpeed + true + true + true + + + Windows + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/project/ImGuiSample/ImGuiSample.vcxproj.filters b/src/easy2d-imgui/Easy2D-ImGui.vcxproj.filters similarity index 56% rename from project/ImGuiSample/ImGuiSample.vcxproj.filters rename to src/easy2d-imgui/Easy2D-ImGui.vcxproj.filters index e993db3d..05187977 100644 --- a/project/ImGuiSample/ImGuiSample.vcxproj.filters +++ b/src/easy2d-imgui/Easy2D-ImGui.vcxproj.filters @@ -1,30 +1,10 @@  - - - imgui - - - imgui - - - imgui - - - imgui - - - easy2d-imgui - - - easy2d-imgui - - - easy2d-imgui - - - + + + + imgui @@ -43,25 +23,27 @@ imgui - - easy2d-imgui - - - easy2d-imgui - - - easy2d-imgui - - - easy2d-imgui - + + + + + + + imgui + + + imgui + + + imgui + + + imgui + - {24ae99cd-ee12-481f-bb03-d8be40d99342} - - - {37f1585a-e992-454a-8cac-e9a6142b08b6} + {d0ea3700-326c-4dc2-a674-fcb657039e87} \ No newline at end of file diff --git a/src/easy2d/Easy2D.vcxproj b/src/easy2d/Easy2D.vcxproj new file mode 100644 index 00000000..06d2c4f7 --- /dev/null +++ b/src/easy2d/Easy2D.vcxproj @@ -0,0 +1,254 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {FF7F943D-A89C-4E6C-97CF-84F7D8FF8EDF} + Easy2D + + + + StaticLibrary + true + Unicode + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + StaticLibrary + false + true + Unicode + + + + + + + + + + + + + + + + + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + + + + Level3 + Disabled + true + + + Console + true + + + + + Level3 + Disabled + true + + + Console + true + + + + + Level3 + MaxSpeed + true + true + false + true + + + Console + true + true + true + + + + + Level3 + MaxSpeed + true + true + false + true + + + Console + true + true + true + + + + + + \ No newline at end of file diff --git a/src/easy2d/Easy2D.vcxproj.filters b/src/easy2d/Easy2D.vcxproj.filters new file mode 100644 index 00000000..7587df17 --- /dev/null +++ b/src/easy2d/Easy2D.vcxproj.filters @@ -0,0 +1,360 @@ + + + + + {896bdedf-6e82-449b-9b6e-0bc69f3699b1} + + + {80bc6386-2b70-4bae-993c-649a55163a1b} + + + {68eac919-ee87-4030-a033-c251731928f5} + + + {07b6d541-4a1b-472a-aae0-daf9d082fe84} + + + {a9793a75-3212-4e31-a443-b23f18a1e136} + + + {86e2d0f2-a9d0-4456-b6a5-d480228bbf82} + + + + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + math + + + math + + + math + + + utils + + + utils + + + utils + + + ui + + + ui + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + math + + + core + + + core + + + math + + + core + + + core + + + core + + + core + + + core + + + core + + + math + + + utils + + + core + + + core + + + core + + + core + + + core + + + math + + + dx + + + dx + + + dx + + + dx + + + dx + + + dx + + + core + + + core + + + + + common + + + common + + + common + + + common + + + common + + + common + + + common + + + core + + + common + + + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + utils + + + utils + + + utils + + + ui + + + ui + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + core + + + utils + + + core + + + core + + + core + + + dx + + + dx + + + dx + + + dx + + + core + + + common + + + \ No newline at end of file diff --git a/src/easy2d/common/Array.h b/src/easy2d/common/Array.h index 92e38cb9..b9a7d0c7 100644 --- a/src/easy2d/common/Array.h +++ b/src/easy2d/common/Array.h @@ -20,6 +20,7 @@ #pragma once #include "../macros.h" +#include namespace easy2d { @@ -27,37 +28,35 @@ namespace easy2d // Array // Lightweight std::vector<>-like class // - template> - class Array + template, bool _TyIsClass = std::is_class<_Ty>::value> + class Array; + + template + class __ArrayBase { public: - using value_type = _Ty; - using allocator_type = _Alloc; - using iterator = value_type*; - using const_iterator = const value_type*; - using reference = value_type &; - using const_reference = const value_type &; - using reverse_iterator = std::reverse_iterator; - using const_reverse_iterator = std::reverse_iterator; + using value_type = _Ty; + using size_type = int; + using allocator_type = _Alloc; + using iterator = value_type*; + using const_iterator = const value_type*; + using reference = value_type &; + using const_reference = const value_type &; + using reverse_iterator = std::reverse_iterator; + using const_reverse_iterator = std::reverse_iterator; - inline Array() { size_ = capacity_ = 0; data_ = nullptr; } - inline Array(std::initializer_list<_Ty> const& list) { size_ = capacity_ = 0; data_ = nullptr; operator=(list); } - inline Array(const Array<_Ty>& src) { size_ = capacity_ = 0; data_ = nullptr; operator=(src); } - inline Array(Array<_Ty>&& src) { size_ = capacity_ = 0; data_ = nullptr; operator=(std::forward&&>(src)); } - inline ~Array() { if (data_) _destroy_all(); } - - inline Array<_Ty>& operator=(const Array<_Ty>& src) { if (&src == this) { return *this; } clear(); reserve(src.size_); std::uninitialized_copy(src.begin(), src.end(), begin()); size_ = src.size_; return *this; } - inline Array<_Ty>& operator=(Array<_Ty>&& src) { clear(); size_ = src.size_; capacity_ = src.capacity_; data_ = src.data_; src.size_ = src.capacity_ = 0; src.data_ = nullptr; return *this; } - inline Array<_Ty>& operator=(std::initializer_list<_Ty> const& list) { clear(); reserve((int)list.size()); std::uninitialized_copy(list.begin(), list.end(), begin()); size_ = (int)list.size(); return *this; } - + public: inline bool empty() const { return size_ == 0; } - inline int size() const { return size_; } - inline int size_in_bytes() const { return size_ * ((int)sizeof(_Ty)); } - inline int capacity() const { return capacity_; } - inline reference operator[](int i) { if (i < 0 || i >= size_) throw std::out_of_range("vector subscript out of range"); return data_[i]; } - inline const_reference operator[](int i) const { if (i < 0 || i >= size_) throw std::out_of_range("vector subscript out of range"); return data_[i]; } + inline size_type size() const { return size_; } + inline size_type size_in_bytes() const { return size_ * ((size_type)sizeof(_Ty)); } + inline size_type capacity() const { return capacity_; } + inline reference operator[](size_type off) { check_offset(off, "vector subscript out of range"); return data_[off]; } + inline const_reference operator[](size_type off) const { check_offset(off, "vector subscript out of range"); return data_[off]; } + + + inline bool contains(const _Ty& v) const { const _Ty* data = data_; const _Ty* data_end = data_ + size_; while (data < data_end) if (*data++ == v) return true; return false; } + inline size_type index_of(const_iterator it) const { check_offset(it - cbegin(), "invalid array position"); const ptrdiff_t off = it - data_; return (size_type)off; } - inline void clear() { if (data_) { _destroy_all(); } } inline iterator begin() { return iterator(data_); } inline const_iterator begin() const { return const_iterator(data_); } inline const_iterator cbegin() const { return begin(); } @@ -74,31 +73,111 @@ namespace easy2d inline const_reference front() const { if (empty()) throw std::out_of_range("front() called on empty array"); return data_[0]; } inline reference back() { if (empty()) throw std::out_of_range("back() called on empty array"); return data_[size_ - 1]; } inline const_reference back() const { if (empty()) throw std::out_of_range("back() called on empty array"); return data_[size_ - 1]; } - inline void swap(Array<_Ty>& rhs) { int rhs_size = rhs.size_; rhs.size_ = size_; size_ = rhs_size; int rhs_cap = rhs.capacity_; rhs.capacity_ = capacity_; capacity_ = rhs_cap; _Ty* rhs_data = rhs.data_; rhs.data_ = data_; data_ = rhs_data; } - inline void resize(int new_size) { if (new_size > capacity_) { reserve(_grow_capacity(new_size)); } _Ty tmp; std::uninitialized_fill_n(data_ + size_, new_size - size_, tmp); size_ = new_size; } - inline void resize(int new_size, const _Ty& v) { if (new_size > capacity_) reserve(_grow_capacity(new_size)); if (new_size > size_) std::uninitialized_fill_n(data_ + size_, new_size - size_, v); size_ = new_size; } - inline void reserve(int new_capacity) { if (new_capacity <= capacity_) return; _Ty* new_data = allocator_.allocate(new_capacity); if (data_) { ::memcpy(new_data, data_, (size_t)size_ * sizeof(_Ty)); allocator_.deallocate(data_, capacity_); } data_ = new_data; capacity_ = new_capacity; } + protected: + inline void check_offset(const size_type off, const char* const msg) const { if (off < 0 || off >= size_) throw std::out_of_range(msg); } - inline void push_back(const _Ty& v) { if (size_ == capacity_) reserve(_grow_capacity(size_ + 1)); allocator_.construct(data_ + size_, v); size_++; } + protected: + size_type size_; + size_type capacity_; + _Ty* data_; + _Alloc allocator_; + }; + + + // + // Array<> for common type + // + template + class Array<_Ty, _Alloc, false> + : public __ArrayBase<_Ty, _Alloc> + { + public: + inline Array() { size_ = capacity_ = 0; data_ = nullptr; } + inline Array(std::initializer_list<_Ty> const& list) { size_ = capacity_ = 0; data_ = nullptr; operator=(list); } + inline Array(const Array<_Ty>& src) { size_ = capacity_ = 0; data_ = nullptr; operator=(src); } + inline Array(Array<_Ty>&& src) { size_ = capacity_ = 0; data_ = nullptr; swap(src); } + inline ~Array() { destroy(); } + + template + inline Array(_Iter first, _Iter last) { size_ = capacity_ = 0; data_ = nullptr; assign_iter(first, last); } + + inline Array<_Ty>& operator=(const Array<_Ty>& src) { if (&src == this) { return *this; } clear(); reserve(src.size_); size_ = src.size_; ::memcpy(data_, src.data_, (size_t)size_ * sizeof(_Ty)); return *this; } + inline Array<_Ty>& operator=(Array<_Ty>&& src) { swap(src); return *this; } + inline Array<_Ty>& operator=(std::initializer_list<_Ty> const& list) { clear(); auto new_size =(size_type)list.size(); if (new_size == 0) return; reserve(new_size); size_ = new_size; assign_iter(list.begin(), list.end()); return *this; } + + inline void clear() { size_ = 0; } + inline void swap(Array<_Ty>& rhs) { size_type rhs_size = rhs.size_; rhs.size_ = size_; size_ = rhs_size; size_type rhs_cap = rhs.capacity_; rhs.capacity_ = capacity_; capacity_ = rhs_cap; _Ty* rhs_data = rhs.data_; rhs.data_ = data_; data_ = rhs_data; } + + inline void resize(size_type new_size) { if (new_size > capacity_) { reserve(grow_capacity(new_size)); } size_ = new_size; } + inline void resize(size_type new_size, const _Ty& v) { if (new_size > capacity_) reserve(grow_capacity(new_size)); if (new_size > size_) for (int n = size_; n < new_size; n++) ::memcpy(&data_[n], &v, sizeof(v)); size_ = new_size; } + inline void reserve(size_type new_capacity) { if (new_capacity <= capacity_) return; _Ty* new_data = allocator_.allocate(new_capacity); if (data_) { ::memcpy(new_data, data_, (size_t)size_ * sizeof(_Ty)); allocator_.deallocate(data_, capacity_); } data_ = new_data; capacity_ = new_capacity; } + + inline void push_back(const _Ty& v) { if (size_ == capacity_) reserve(grow_capacity(size_ + 1)); ::memcpy(&data_[size_], &v, sizeof(v)); size_++; } + inline void pop_back() { if (empty()) throw std::out_of_range("pop() called on empty vector"); size_--; } + inline void push_front(const _Ty& v) { if (size_ == 0) push_back(v); else insert(data_, v); } + + inline iterator erase(const_iterator it) { const auto off = it - data_; check_offset(off, "invalid vector position"); ::memmove(data_ + off, data_ + off + 1, ((size_t)size_ - (size_t)off - 1) * sizeof(_Ty)); size_--; return data_ + off; } + inline iterator erase(const_iterator it, const_iterator it_last) { const auto count = it_last - it; const auto off = it - data_; if (count == 0) return it; check_offset(off, "invalid vector position"); ::memmove(data_ + off, data_ + off + count, ((size_t)size_ - (size_t)off - count) * sizeof(_Ty)); size_ -= (size_type)count; return data_ + off; } + + inline iterator insert(const_iterator it, const _Ty& v) { const auto off = it - data_; check_offset(off, "invalid vector position"); if (size_ == capacity_) reserve(grow_capacity(size_ + 1)); if (off < (size_type)size_) ::memmove(data_ + off + 1, data_ + off, ((size_t)size_ - (size_t)off) * sizeof(_Ty)); ::memcpy(&data_[off], &v, sizeof(v)); size_++; return data_ + off; } + + private: + inline size_type grow_capacity(size_type sz) const { size_type new_capacity = capacity_ ? (capacity_ + capacity_ / 2) : 8; return new_capacity > sz ? new_capacity : sz; } + inline void destroy() { if (data_) allocator_.deallocate(data_, capacity_); size_ = capacity_ = 0; data_ = nullptr; } + + template + inline void assign_iter(_Iter first, _Iter last) { auto diff = std::distance(first, last); if (diff == 0) return; reserve(diff); size_ = diff; for (size_type index = 0; first != last; ++first, ++index) data_[index] = (*first); } + }; + + + // + // Array<> for class + // + template + class Array<_Ty, _Alloc, true> + : public __ArrayBase<_Ty, _Alloc> + { + public: + using value_type = _Ty; + using allocator_type = _Alloc; + using iterator = value_type*; + using const_iterator = const value_type*; + using reference = value_type &; + using const_reference = const value_type &; + using reverse_iterator = std::reverse_iterator; + using const_reverse_iterator = std::reverse_iterator; + + inline Array() { size_ = capacity_ = 0; data_ = nullptr; } + inline Array(std::initializer_list<_Ty> const& list) { size_ = capacity_ = 0; data_ = nullptr; operator=(list); } + inline Array(const Array<_Ty>& src) { size_ = capacity_ = 0; data_ = nullptr; operator=(src); } + inline Array(Array<_Ty>&& src) { size_ = capacity_ = 0; data_ = nullptr; operator=(std::forward&&>(src)); } + inline ~Array() { if (data_) destroy_all(); } + + inline Array<_Ty>& operator=(const Array<_Ty>& src) { if (&src == this) { return *this; } clear(); assign_iter(src.begin(), src.end()); return *this; } + inline Array<_Ty>& operator=(Array<_Ty>&& src) { clear(); size_ = src.size_; capacity_ = src.capacity_; data_ = src.data_; src.size_ = src.capacity_ = 0; src.data_ = nullptr; return *this; } + inline Array<_Ty>& operator=(std::initializer_list<_Ty> const& list) { clear(); assign_iter(list.begin(), list.end()); return *this; } + + inline void clear() { if (data_) { destroy_all(); } } + inline void swap(Array<_Ty>& rhs) { size_type rhs_size = rhs.size_; rhs.size_ = size_; size_ = rhs_size; size_type rhs_cap = rhs.capacity_; rhs.capacity_ = capacity_; capacity_ = rhs_cap; _Ty* rhs_data = rhs.data_; rhs.data_ = data_; data_ = rhs_data; } + + inline void resize(size_type new_size) { if (new_size > capacity_) { reserve(grow_capacity(new_size)); } _Ty tmp; std::uninitialized_fill_n(data_ + size_, new_size - size_, tmp); size_ = new_size; } + inline void resize(size_type new_size, const _Ty& v) { if (new_size > capacity_) reserve(grow_capacity(new_size)); if (new_size > size_) std::uninitialized_fill_n(data_ + size_, new_size - size_, v); size_ = new_size; } + inline void reserve(size_type new_capacity) { if (new_capacity <= capacity_) return; _Ty* new_data = allocator_.allocate(new_capacity); if (data_) { ::memcpy(new_data, data_, (size_t)size_ * sizeof(_Ty)); allocator_.deallocate(data_, capacity_); } data_ = new_data; capacity_ = new_capacity; } + + inline void push_back(const _Ty& v) { if (size_ == capacity_) reserve(grow_capacity(size_ + 1)); allocator_.construct(data_ + size_, v); size_++; } inline void pop_back() { if (empty()) throw std::out_of_range("vector empty before pop"); size_--; } inline void push_front(const _Ty& v) { if (size_ == 0) push_back(v); else insert(data_, v); } inline iterator erase(const_iterator it) { E2D_ASSERT(it >= data_ && it < data_ + size_); allocator_.destroy(it); const ptrdiff_t off = it - data_; ::memmove(data_ + off, data_ + off + 1, ((size_t)size_ - (size_t)off - 1) * sizeof(_Ty)); size_--; return data_ + off; } - inline iterator erase(const_iterator it, const_iterator it_last) { E2D_ASSERT(it >= data_ && it < data_ + size_ && it_last > it && it_last <= data_ + size_); _destroy(it, it_last); const ptrdiff_t count = it_last - it; const ptrdiff_t off = it - data_; ::memmove(data_ + off, data_ + off + count, ((size_t)size_ - (size_t)off - count) * sizeof(_Ty)); size_ -= (int)count; return data_ + off; } - inline iterator insert(const_iterator it, const _Ty& v) { E2D_ASSERT(it >= data_ && it <= data_ + size_); const ptrdiff_t off = it - data_; if (size_ == capacity_) reserve(_grow_capacity(size_ + 1)); if (off < (int)size_) ::memmove(data_ + off + 1, data_ + off, ((size_t)size_ - (size_t)off) * sizeof(_Ty)); allocator_.construct(data_ + off, v); size_++; return data_ + off; } - inline bool contains(const _Ty& v) const { const _Ty* data = data_; const _Ty* data_end = data_ + size_; while (data < data_end) if (*data++ == v) return true; return false; } - inline int index_of(const_iterator it) const { E2D_ASSERT(it >= data_ && it <= data_ + size_); const ptrdiff_t off = it - data_; return (int)off; } + inline iterator erase(const_iterator it, const_iterator it_last) { E2D_ASSERT(it >= data_ && it < data_ + size_ && it_last > it && it_last <= data_ + size_); destroy(it, it_last); const ptrdiff_t count = it_last - it; const ptrdiff_t off = it - data_; ::memmove(data_ + off, data_ + off + count, ((size_t)size_ - (size_t)off - count) * sizeof(_Ty)); size_ -= (size_type)count; return data_ + off; } + inline iterator insert(const_iterator it, const _Ty& v) { E2D_ASSERT(it >= data_ && it <= data_ + size_); const ptrdiff_t off = it - data_; if (size_ == capacity_) reserve(grow_capacity(size_ + 1)); if (off < (size_type)size_) ::memmove(data_ + off + 1, data_ + off, ((size_t)size_ - (size_t)off) * sizeof(_Ty)); allocator_.construct(data_ + off, v); size_++; return data_ + off; } private: - inline int _grow_capacity(int sz) const { int new_capacity = capacity_ ? (capacity_ + capacity_ / 2) : 8; return new_capacity > sz ? new_capacity : sz; } - inline void _destroy(iterator it, iterator it_last) { E2D_ASSERT(it >= data_ && it < data_ + size_ && it_last > it && it_last <= data_ + size_); for (; it != it_last; ++it) allocator_.destroy(it); } - inline void _destroy_all() { E2D_ASSERT((data_ && capacity_) || (!data_ && !capacity_)); if (size_) _destroy(begin(), end()); if (data_ && capacity_) allocator_.deallocate(data_, capacity_); size_ = capacity_ = 0; data_ = nullptr; } - - private: - int size_; - int capacity_; - _Ty* data_; - - typename _Alloc allocator_; + inline size_type grow_capacity(size_type sz) const { size_type new_capacity = capacity_ ? (capacity_ + capacity_ / 2) : 8; return new_capacity > sz ? new_capacity : sz; } + inline void destroy(iterator it, iterator it_last) { E2D_ASSERT(it >= data_ && it < data_ + size_ && it_last > it && it_last <= data_ + size_); for (; it != it_last; ++it) allocator_.destroy(it); } + inline void destroy_all() { E2D_ASSERT((data_ && capacity_) || (!data_ && !capacity_)); if (size_) destroy(begin(), end()); if (data_ && capacity_) allocator_.deallocate(data_, capacity_); size_ = capacity_ = 0; data_ = nullptr; } + + template + inline void assign_iter(_Iter first, _Iter last) { auto diff = std::distance(first, last); if (diff == 0) return; resize(diff); for (size_type index = 0; first != last; ++first, ++index) data_[index] = (*first); } }; } diff --git a/src/easy2d/common/ComPtr.hpp b/src/easy2d/common/ComPtr.hpp index 4f7b0beb..0e9b3503 100644 --- a/src/easy2d/common/ComPtr.hpp +++ b/src/easy2d/common/ComPtr.hpp @@ -21,21 +21,25 @@ #pragma once #include "IntrusivePtr.hpp" #include +#include namespace easy2d { + struct ComPtrManager + { + static inline void AddRef(IUnknown* ptr) + { + if (ptr) ptr->AddRef(); + } + + static inline void Release(IUnknown* ptr) + { + if (ptr) ptr->Release(); + } + }; + // ComPtr<> is a smart pointer for COM template - using ComPtr = IntrusivePtr<_Ty>; - - inline void IntrusivePtrAddRef(IUnknown* ptr) - { - if (ptr) { ptr->AddRef(); } - } - - inline void IntrusivePtrRelease(IUnknown* ptr) - { - if (ptr) { ptr->Release(); } - } + using ComPtr = IntrusivePtr<_Ty, ComPtrManager, ::std::is_base_of::value>; } diff --git a/src/easy2d/common/IntrusivePtr.hpp b/src/easy2d/common/IntrusivePtr.hpp index edc19c7d..04411cae 100644 --- a/src/easy2d/common/IntrusivePtr.hpp +++ b/src/easy2d/common/IntrusivePtr.hpp @@ -21,16 +21,27 @@ #pragma once #include "../macros.h" #include +#include namespace easy2d { - template - class IntrusivePtr + template + class IntrusivePtr; + + template + class IntrusivePtr<_Ty, _Manager, false>; + + + template + using RealIntrusivePtr = IntrusivePtr<_Ty, _Manager, true>; + + template + class IntrusivePtr<_Ty, _Manager, true> { - T* ptr_{ nullptr }; + _Ty* ptr_{ nullptr }; public: - using Type = T; + using Type = _Ty; IntrusivePtr() E2D_NOEXCEPT {} @@ -38,20 +49,20 @@ namespace easy2d IntrusivePtr(Type* p) E2D_NOEXCEPT : ptr_(p) { - IntrusivePtrAddRef(ptr_); + typename _Manager::AddRef(ptr_); } IntrusivePtr(const IntrusivePtr& other) E2D_NOEXCEPT : ptr_(other.ptr_) { - IntrusivePtrAddRef(ptr_); + typename _Manager::AddRef(ptr_); } - template - IntrusivePtr(const IntrusivePtr& other) E2D_NOEXCEPT + template + IntrusivePtr(const RealIntrusivePtr<_UTy, _Manager>& other) E2D_NOEXCEPT : ptr_(other.Get()) { - IntrusivePtrAddRef(ptr_); + typename _Manager::AddRef(ptr_); } IntrusivePtr(IntrusivePtr&& other) E2D_NOEXCEPT @@ -62,7 +73,7 @@ namespace easy2d ~IntrusivePtr() E2D_NOEXCEPT { - IntrusivePtrRelease(ptr_); + typename _Manager::Release(ptr_); } inline Type* Get() const E2D_NOEXCEPT { return ptr_; } @@ -108,7 +119,7 @@ namespace easy2d inline IntrusivePtr& operator =(IntrusivePtr&& other) E2D_NOEXCEPT { - IntrusivePtrRelease(ptr_); + typename _Manager::Release(ptr_); ptr_ = other.ptr_; other.ptr_ = nullptr; return *this; @@ -129,76 +140,76 @@ namespace easy2d } }; - template - inline bool operator==(IntrusivePtr const& lhs, IntrusivePtr const& rhs) E2D_NOEXCEPT + template + inline bool operator==(RealIntrusivePtr<_Ty, _Manager> const& lhs, RealIntrusivePtr<_UTy, _Manager> const& rhs) E2D_NOEXCEPT { return lhs.Get() == rhs.Get(); } - template - inline bool operator!=(IntrusivePtr const& lhs, IntrusivePtr const& rhs) E2D_NOEXCEPT + template + inline bool operator!=(RealIntrusivePtr<_Ty, _Manager> const& lhs, RealIntrusivePtr<_UTy, _Manager> const& rhs) E2D_NOEXCEPT { return lhs.Get() != rhs.Get(); } - template - inline bool operator<(IntrusivePtr const& lhs, IntrusivePtr const& rhs) E2D_NOEXCEPT + template + inline bool operator<(RealIntrusivePtr<_Ty, _Manager> const& lhs, RealIntrusivePtr<_UTy, _Manager> const& rhs) E2D_NOEXCEPT { return lhs.Get() < rhs.Get(); } - template - inline bool operator==(IntrusivePtr const& lhs, T* rhs) E2D_NOEXCEPT + template + inline bool operator==(RealIntrusivePtr<_Ty, _Manager> const& lhs, _Ty* rhs) E2D_NOEXCEPT { return lhs.Get() == rhs; } - template - inline bool operator!=(IntrusivePtr const& lhs, T* rhs) E2D_NOEXCEPT + template + inline bool operator!=(RealIntrusivePtr<_Ty, _Manager> const& lhs, _Ty* rhs) E2D_NOEXCEPT { return lhs.Get() != rhs; } - template - inline bool operator==(T* lhs, IntrusivePtr const& rhs) E2D_NOEXCEPT + template + inline bool operator==(_Ty* lhs, RealIntrusivePtr<_Ty, _Manager> const& rhs) E2D_NOEXCEPT { return lhs == rhs.Get(); } - template - inline bool operator!=(T* lhs, IntrusivePtr const& rhs) E2D_NOEXCEPT + template + inline bool operator!=(_Ty* lhs, RealIntrusivePtr<_Ty, _Manager> const& rhs) E2D_NOEXCEPT { return lhs != rhs.Get(); } - template - inline bool operator==(IntrusivePtr const& lhs, nullptr_t) E2D_NOEXCEPT + template + inline bool operator==(RealIntrusivePtr<_Ty, _Manager> const& lhs, nullptr_t) E2D_NOEXCEPT { return !static_cast(lhs); } - template - inline bool operator!=(IntrusivePtr const& lhs, nullptr_t) E2D_NOEXCEPT + template + inline bool operator!=(RealIntrusivePtr<_Ty, _Manager> const& lhs, nullptr_t) E2D_NOEXCEPT { return static_cast(lhs); } - template - inline bool operator==(nullptr_t, IntrusivePtr const& rhs) E2D_NOEXCEPT + template + inline bool operator==(nullptr_t, RealIntrusivePtr<_Ty, _Manager> const& rhs) E2D_NOEXCEPT { return !static_cast(rhs); } - template - inline bool operator!=(nullptr_t, IntrusivePtr const& rhs) E2D_NOEXCEPT + template + inline bool operator!=(nullptr_t, RealIntrusivePtr<_Ty, _Manager> const& rhs) E2D_NOEXCEPT { return static_cast(rhs); } // template class cannot specialize std::swap, // so implement a swap function in easy2d namespace - template - inline void swap(IntrusivePtr& lhs, IntrusivePtr& rhs) E2D_NOEXCEPT + template + inline void swap(RealIntrusivePtr<_Ty, _Manager>& lhs, RealIntrusivePtr<_Ty, _Manager>& rhs) E2D_NOEXCEPT { lhs.Swap(rhs); } diff --git a/src/easy2d/common/String.cpp b/src/easy2d/common/String.cpp index 0b03ff3a..ae1c1a34 100644 --- a/src/easy2d/common/String.cpp +++ b/src/easy2d/common/String.cpp @@ -75,7 +75,7 @@ namespace easy2d } template - constexpr size_t TraitsFindLastOf( + size_t TraitsFindLastOf( const typename _Traits::char_type* first, const size_t first_size, const size_t pos, const typename _Traits::char_type* second, const size_t count) { @@ -233,8 +233,8 @@ namespace easy2d } size_type new_size = size_ - count; - iterator erase_at = begin() + offset; - traits::move(erase_at, erase_at + count, new_size - offset + 1); + iterator erase_at = begin().base() + offset; + traits::move(erase_at.base(), erase_at.base() + count, new_size - offset + 1); return (*this); } @@ -344,7 +344,7 @@ namespace easy2d wchar_t* const insert_at = new_ptr + index; traits::move(new_ptr, old_ptr, index); // (0) - (index) - traits::move(insert_at, str.begin() + off, count); // (index) - (index + count) + traits::move(insert_at, str.begin().base() + off, count); // (index) - (index + count) traits::move(insert_at + count, old_ptr + index, suffix_size); // (index + count) - (old_size - index) deallocate(str_, old_capacity); @@ -354,7 +354,7 @@ namespace easy2d { wchar_t* const insert_at = old_ptr + index; traits::move(insert_at + count, old_ptr + index, suffix_size); - traits::move(insert_at, str.begin() + off, count); + traits::move(insert_at, str.begin().base() + off, count); } return (*this); @@ -414,7 +414,7 @@ namespace easy2d wchar_t* new_str = allocate(new_cap); traits::move(new_str, str_, size_); - traits::move(new_str + size_, other.begin() + pos, count); + traits::move(new_str + size_, other.begin().base() + pos, count); traits::assign(new_str[new_size], value_type()); destroy(); @@ -478,7 +478,7 @@ namespace easy2d if (offset >= size_) return String::npos; - const_iterator citer = traits::find(const_str_ + offset, size_, ch); + const_iterator citer = traits::find(cbegin().base() + offset, size_, ch); return citer ? (citer - cbegin()) : String::npos; } @@ -494,7 +494,7 @@ namespace easy2d if (offset >= size_) return String::npos; - const_iterator citer = std::find_first_of(cbegin() + offset, cend(), str, str + count); + const_iterator citer = std::find_first_of(cbegin().base() + offset, cend().base(), str, str + count); return (citer != cend()) ? (citer - cbegin()) : String::npos; } @@ -605,6 +605,18 @@ namespace easy2d return (*this); } + String::size_type String::copy(wchar_t * cstr, size_type count, size_type pos) const + { + if (count == 0 || cstr == const_str_) + return 0; + + check_offset(pos); + + count = clamp_suffix_size(pos, count); + traits::move(cstr, cbegin().base() + pos, count); + return count; + } + std::string String::to_string() const { return StringWideCharToMultiByte(str_); diff --git a/src/easy2d/common/String.h b/src/easy2d/common/String.h index d44735da..febde2f5 100644 --- a/src/easy2d/common/String.h +++ b/src/easy2d/common/String.h @@ -32,13 +32,62 @@ namespace easy2d // class E2D_API String { + public: + // Iterator + template + struct _Iterator + { + using iterator_category = typename std::iterator_traits<_Ty*>::iterator_category; + using value_type = typename std::iterator_traits<_Ty*>::value_type; + using difference_type = typename std::iterator_traits<_Ty*>::difference_type; + using pointer = typename std::iterator_traits<_Ty*>::pointer; + using reference = typename std::iterator_traits<_Ty*>::reference; + + // disable warning 4996 + using _Unchecked_type = _Ty; + + inline _Iterator(pointer base = nullptr) : base_(base) {} + + inline _Iterator& operator++() { ++base_; return (*this); } + inline _Iterator operator++(int) { _Iterator old = (*this); ++(*this); return old; } + + inline _Iterator& operator--() { --base_; return (*this); } + inline _Iterator operator--(int) { _Iterator old = (*this); --(*this); return old; } + + inline const _Iterator operator+(difference_type off) const { return _Iterator(base_ + off); } + inline const _Iterator operator-(difference_type off) const { return _Iterator(base_ - off); } + + inline _Iterator& operator+=(difference_type off) { base_ += off; return (*this); } + inline _Iterator& operator-=(difference_type off) { base_ -= off; return (*this); } + + inline difference_type operator-(_Iterator const& other) const { return base_ - other.base_; } + + inline bool operator==(_Iterator const& other) const { return base_ == other.base_; } + inline bool operator!=(_Iterator const& other) const { return !(*this == other); } + + inline bool operator<(_Iterator const& other) const { return base_ < other.base_; } + inline bool operator<=(_Iterator const& other) const { return base_ <= other.base_; } + inline bool operator>(_Iterator const& other) const { return base_ > other.base_; } + inline bool operator>=(_Iterator const& other) const { return base_ >= other.base_; } + + inline reference operator[](difference_type off) const { return *(base_ + off); } + + inline operator bool() const { return base_ != nullptr; } + + inline reference operator*() const { return *base_; } + inline pointer base() const { return base_; } + + private: + pointer base_{ nullptr }; + }; + public: using value_type = wchar_t; using size_type = size_t; - using iterator = value_type * ; - using const_iterator = const value_type*; - using reference = value_type & ; + using reference = value_type &; using const_reference = const value_type &; + using iterator = _Iterator; + using const_iterator = _Iterator; using reverse_iterator = std::reverse_iterator; using const_reverse_iterator = std::reverse_iterator; using traits = std::char_traits; @@ -67,7 +116,7 @@ namespace easy2d inline void clear() { discard_const_data(); if (str_) { str_[0] = value_type(); } size_ = 0; } void reserve(const size_type new_cap = 0); - inline void resize(const size_type new_size, const wchar_t ch = value_type()) { check_operability(); if (new_size < size_) str_[size_ = new_size] = value_type(); else append(new_size - size_, ch); } + inline void resize(const size_type new_size, const wchar_t ch = value_type()) { check_operability(); if (new_size < size_) str_[size_ = new_size] = value_type(); else append(new_size - size_, ch); } int compare(const wchar_t* const str) const; inline int compare(String const& str) const { return compare(str.c_str()); } @@ -105,32 +154,32 @@ namespace easy2d String& assign(size_type count, const wchar_t ch); String& assign(const wchar_t* cstr, size_type count); - inline String& assign(const wchar_t* cstr, bool const_str = true) { String(cstr, const_str).swap(*this); return *this; } - inline String& assign(std::wstring const& str) { String{ str }.swap(*this); return *this; } - inline String& assign(String const& rhs) { String{ rhs }.swap(*this); return *this; } - inline String& assign(String const& rhs, size_type pos, size_type count = npos) { String(rhs, pos, count).swap(*this); return *this; } + inline String& assign(const wchar_t* cstr, bool const_str = true) { String(cstr, const_str).swap(*this); return *this; } + inline String& assign(std::wstring const& str) { String{ str }.swap(*this); return *this; } + inline String& assign(String const& rhs) { String{ rhs }.swap(*this); return *this; } + inline String& assign(String const& rhs, size_type pos, size_type count = npos) { String(rhs, pos, count).swap(*this); return *this; } template - inline String& assign(_Iter first, _Iter last) { assign_iter(first, last); return(*this); } + inline String& assign(_Iter first, _Iter last) { assign_iter(first, last); return(*this); } String& erase(size_type offset = 0, size_type count = npos); - iterator erase(const const_iterator where) { size_type off = where - cbegin(); erase(off, 1); return begin() + off; } - iterator erase(const const_iterator first, const const_iterator last) { size_type off = first - cbegin(); erase(first - cbegin(), last - first); return begin() + off; } + iterator erase(const const_iterator where) { size_type off = where - cbegin(); erase(off, 1); return begin().base() + off; } + iterator erase(const const_iterator first, const const_iterator last) { size_type off = first - cbegin(); erase(first - cbegin(), last - first); return begin().base() + off; } - String substr(size_type pos = 0, size_type count = npos) const { return String(*this, pos, count); } + String substr(size_type pos = 0, size_type count = npos) const { return String(*this, pos, count); } String& insert(size_type index, size_type count, wchar_t ch); String& insert(size_type index, const wchar_t* s, size_type count); String& insert(size_type index, const String& str, size_type off, size_type count = npos); - inline String& insert(size_type index, const wchar_t* s) { return insert(index, s, traits::length(s)); } - inline String& insert(size_type index, const String& str) { return insert(index, str, 0, str.size()); } - inline iterator insert(const_iterator pos, size_type count, wchar_t ch) { size_type off = pos - cbegin(); insert(off, count, ch); return begin() + off; } - inline iterator insert(const_iterator pos, wchar_t ch) { return insert(pos, 1, ch); } + inline String& insert(size_type index, const wchar_t* s) { return insert(index, s, traits::length(s)); } + inline String& insert(size_type index, const String& str) { return insert(index, str, 0, str.size()); } + inline iterator insert(const_iterator pos, size_type count, wchar_t ch) { size_type off = pos - cbegin(); insert(off, count, ch); return begin().base() + off; } + inline iterator insert(const_iterator pos, wchar_t ch) { return insert(pos, 1, ch); } - inline void push_back(const wchar_t ch) { append(1, ch); } - inline wchar_t pop_back() { if (empty()) throw std::out_of_range("pop_back() called on empty string"); check_operability(); wchar_t ch = str_[--size_]; str_[size_] = value_type(); return ch; } + inline void push_back(const wchar_t ch) { append(1, ch); } + inline wchar_t pop_back() { if (empty()) throw std::out_of_range("pop_back() called on empty string"); check_operability(); wchar_t ch = str_[--size_]; str_[size_] = value_type(); return ch; } - inline size_type copy(wchar_t* cstr, size_type count, size_type pos = 0) const { check_offset(pos); if (count == 0 || cstr == const_str_) return 0; count = clamp_suffix_size(pos, count); traits::move(cstr, cbegin() + pos, count); return count; } + size_type copy(wchar_t* cstr, size_type count, size_type pos = 0) const; std::string to_string() const; std::wstring to_wstring() const; @@ -140,26 +189,26 @@ namespace easy2d size_t hash() const; public: - inline iterator begin() { check_operability(); return iterator(str_); } - inline const_iterator begin() const { return const_iterator(const_str_); } - inline const_iterator cbegin() const { return begin(); } - inline iterator end() { check_operability(); return iterator(str_ + size_); } - inline const_iterator end() const { return const_iterator(const_str_ + size_); } - inline const_iterator cend() const { return end(); } - inline reverse_iterator rbegin() { check_operability(); return reverse_iterator(end()); } - inline const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } - inline const_reverse_iterator crbegin() const { return rbegin(); } - inline reverse_iterator rend() { check_operability(); return reverse_iterator(begin()); } - inline const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } - inline const_reverse_iterator crend() const { return rend(); } - inline reference front() { if (empty()) throw std::out_of_range("front() called on empty string"); check_operability(); return str_[0]; } - inline const_reference front() const { if (empty()) throw std::out_of_range("front() called on empty string"); return const_str_[0]; } - inline reference back() { if (empty()) throw std::out_of_range("back() called on empty string"); check_operability(); return str_[size_ - 1]; } - inline const_reference back() const { if (empty()) throw std::out_of_range("back() called on empty string"); return const_str_[size_ - 1]; } + inline iterator begin() { check_operability(); return iterator(str_); } + inline const_iterator begin() const { return const_iterator(const_str_); } + inline const_iterator cbegin() const { return begin(); } + inline iterator end() { check_operability(); return iterator(str_ + size_); } + inline const_iterator end() const { return const_iterator(const_str_ + size_); } + inline const_iterator cend() const { return end(); } + inline reverse_iterator rbegin() { check_operability(); return reverse_iterator(end()); } + inline const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } + inline const_reverse_iterator crbegin() const { return rbegin(); } + inline reverse_iterator rend() { check_operability(); return reverse_iterator(begin()); } + inline const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } + inline const_reverse_iterator crend() const { return rend(); } + inline reference front() { if (empty()) throw std::out_of_range("front() called on empty string"); check_operability(); return str_[0]; } + inline const_reference front() const { if (empty()) throw std::out_of_range("front() called on empty string"); return const_str_[0]; } + inline reference back() { if (empty()) throw std::out_of_range("back() called on empty string"); check_operability(); return str_[size_ - 1]; } + inline const_reference back() const { if (empty()) throw std::out_of_range("back() called on empty string"); return const_str_[size_ - 1]; } public: - inline wchar_t operator[](size_type off) const { if(off >= size_) throw std::out_of_range("string subscript out of range"); return const_str_[off]; } - inline wchar_t& operator[](size_type off) { if (off >= size_) throw std::out_of_range("string subscript out of range"); check_operability(); return str_[off]; } + inline wchar_t operator[](size_type off) const { if(off >= size_) throw std::out_of_range("string subscript out of range"); return const_str_[off]; } + inline wchar_t& operator[](size_type off) { if (off >= size_) throw std::out_of_range("string subscript out of range"); check_operability(); return str_[off]; } public: inline const String operator+(const wchar_t ch) const { return String{ *this }.append(1, ch); } @@ -308,7 +357,7 @@ namespace easy2d { using Ctype = std::ctype; using IStream = std::basic_istream; - using SizeType = typename String::size_type; + using SizeType = String::size_type; std::ios_base::iostate state = std::ios_base::goodbit; bool changed = false; @@ -429,7 +478,7 @@ namespace easy2d template inline String FloatingToString(const wchar_t *fmt, _Ty val) { - static_assert(std::is_floating_point_v<_Ty>, "_Ty must be floating point"); + static_assert(std::is_floating_point<_Ty>::value, "_Ty must be floating point"); return format_wstring(fmt, val); } @@ -437,7 +486,7 @@ namespace easy2d template inline String IntegralToString(const _Ty val) { - static_assert(std::is_integral_v<_Ty>, "_Ty must be integral"); + static_assert(std::is_integral<_Ty>::value, "_Ty must be integral"); using _UTy = std::make_unsigned_t<_Ty>; using _Elem = String::traits::char_type; diff --git a/src/easy2d/core/ActionGroup.cpp b/src/easy2d/core/ActionGroup.cpp index 0204ae88..865344ed 100644 --- a/src/easy2d/core/ActionGroup.cpp +++ b/src/easy2d/core/ActionGroup.cpp @@ -144,41 +144,4 @@ namespace easy2d return group; } - //------------------------------------------------------- - // ActionSequence - //------------------------------------------------------- - - ActionSequence::ActionSequence() - : ActionGroup() - { - } - - ActionSequence::ActionSequence(Array const & actions) - : ActionGroup(actions, true) - { - } - - ActionSequence::~ActionSequence() - { - } - - //------------------------------------------------------- - // ActionSpawn - //------------------------------------------------------- - - ActionSpawn::ActionSpawn() - : ActionGroup() - { - sequence_ = false; - } - - ActionSpawn::ActionSpawn(Array const & actions) - : ActionGroup(actions, false) - { - } - - ActionSpawn::~ActionSpawn() - { - } - } \ No newline at end of file diff --git a/src/easy2d/core/ActionGroup.h b/src/easy2d/core/ActionGroup.h index 1f32ea43..b7b07c00 100644 --- a/src/easy2d/core/ActionGroup.h +++ b/src/easy2d/core/ActionGroup.h @@ -73,33 +73,31 @@ namespace easy2d // ˳Ðò¶¯×÷ - class E2D_DEPRECATED("ActionSequence is deprecated, use ActionGroup instead") E2D_API - ActionSequence + class E2D_API ActionSequence : public ActionGroup { public: - ActionSequence(); + E2D_DEPRECATED("ActionSequence is deprecated, use ActionGroup instead") + inline ActionSequence() : ActionGroup() {} - explicit ActionSequence( - Array const& actions - ); + E2D_DEPRECATED("ActionSequence is deprecated, use ActionGroup instead") + inline explicit ActionSequence(Array const& actions) : ActionGroup(actions, true) {} - virtual ~ActionSequence(); + virtual ~ActionSequence() {} }; // ͬ²½¶¯×÷ - class E2D_DEPRECATED("ActionSpawn is deprecated, use ActionGroup instead") E2D_API - ActionSpawn + class E2D_API ActionSpawn : public ActionGroup { public: - ActionSpawn(); + E2D_DEPRECATED("ActionSpawn is deprecated, use ActionGroup instead") + inline ActionSpawn() : ActionGroup() { sequence_ = false; } - explicit ActionSpawn( - Array const& actions - ); + E2D_DEPRECATED("ActionSpawn is deprecated, use ActionGroup instead") + inline explicit ActionSpawn(Array const& actions) : ActionGroup(actions, false) {} - virtual ~ActionSpawn(); + virtual ~ActionSpawn() {} }; } diff --git a/src/easy2d/core/RefCounter.hpp b/src/easy2d/core/RefCounter.hpp index 02482f2a..b7511b81 100644 --- a/src/easy2d/core/RefCounter.hpp +++ b/src/easy2d/core/RefCounter.hpp @@ -49,14 +49,4 @@ namespace easy2d protected: long ref_count_; }; - - inline void IntrusivePtrAddRef(RefCounter* ptr) - { - if (ptr) ptr->Retain(); - } - - inline void IntrusivePtrRelease(RefCounter* ptr) - { - if (ptr) ptr->Release(); - } } diff --git a/src/easy2d/core/helper.h b/src/easy2d/core/helper.h index f7fac7e2..60716011 100644 --- a/src/easy2d/core/helper.h +++ b/src/easy2d/core/helper.h @@ -29,18 +29,10 @@ #include #include - #ifndef E2D_DECLARE_SMART_PTR -#define E2D_DECLARE_SMART_PTR(class_name)\ - class class_name;\ - using class_name##Ptr = ::easy2d::IntrusivePtr< class_name > - -#define E2D_DECLARE_NS_SMART_PTR(ns_name, class_name)\ - namespace ns_name\ - {\ - class class_name; \ - using class_name##Ptr = ::easy2d::IntrusivePtr< class_name >;\ - } +#define E2D_DECLARE_SMART_PTR(CLASS)\ + class CLASS;\ + using CLASS##Ptr = ::easy2d::SmartPtr< CLASS > #endif namespace easy2d @@ -68,6 +60,23 @@ namespace easy2d namespace easy2d { + struct DefaultIntrusivePtrManager + { + static inline void AddRef(RefCounter* ptr) + { + if (ptr) ptr->Retain(); + } + + static inline void Release(RefCounter* ptr) + { + if (ptr) ptr->Release(); + } + }; + + template + using SmartPtr = IntrusivePtr<_Ty, DefaultIntrusivePtrManager, true>; + + E2D_DECLARE_SMART_PTR(Object); E2D_DECLARE_SMART_PTR(Image); E2D_DECLARE_SMART_PTR(Task); @@ -119,26 +128,3 @@ namespace easy2d E2D_DECLARE_SMART_PTR(Button); E2D_DECLARE_SMART_PTR(Menu); } - -namespace easy2d -{ - class __SmartPointerMaker - { - public: - static inline __SmartPointerMaker const& Instance() - { - static __SmartPointerMaker maker; - return maker; - } - - template - inline IntrusivePtr operator- (T* ptr) const - { - return IntrusivePtr(ptr); - } - }; -} - -#ifndef E_NEW -# define E_NEW (::easy2d::__SmartPointerMaker::Instance()) - new (std::nothrow) -#endif diff --git a/src/easy2d/dx/D3D11DeviceResources.cpp b/src/easy2d/dx/D3D11DeviceResources.cpp index 6cf9a816..1b9a4e08 100644 --- a/src/easy2d/dx/D3D11DeviceResources.cpp +++ b/src/easy2d/dx/D3D11DeviceResources.cpp @@ -241,7 +241,14 @@ namespace easy2d swap_chain_desc.SampleDesc.Count = 1; swap_chain_desc.SampleDesc.Quality = 0; swap_chain_desc.Windowed = TRUE; + +#if defined(_WIN32_WINNT_WIN10) swap_chain_desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; +#elif defined(_WIN32_WINNT_WINBLUE) + swap_chain_desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; +#else + swap_chain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; +#endif ComPtr dxgi_device; if (SUCCEEDED(hr)) diff --git a/src/easy2d/easy2d.h b/src/easy2d/easy2d.h index 882dcc64..cd2f2990 100644 --- a/src/easy2d/easy2d.h +++ b/src/easy2d/easy2d.h @@ -87,15 +87,6 @@ #include "math/Matrix.hpp" -// -// audio -// - -#include "audio/audio.h" -#include "audio/Music.h" -#include "audio/Player.h" - - // // utils // diff --git a/src/easy2d/utils/File.cpp b/src/easy2d/utils/File.cpp index 03e63bbf..3dd11b89 100644 --- a/src/easy2d/utils/File.cpp +++ b/src/easy2d/utils/File.cpp @@ -49,7 +49,7 @@ namespace easy2d bool File::Exists() const { - return modules::Shlwapi::Get().PathFileExistsW(file_path_.c_str()); + return !!modules::Shlwapi::Get().PathFileExistsW(file_path_.c_str()); } String const& File::GetPath() const @@ -96,7 +96,6 @@ namespace easy2d DWORD buffer_size; if (res.Load(buffer, buffer_size)) { - // дÈëÎļþ DWORD written_bytes = 0; ::WriteFile(file_handle, buffer, buffer_size, &written_bytes, NULL); ::CloseHandle(file_handle); diff --git a/src/easy2d/utils/ResLoader.cpp b/src/easy2d/utils/ResLoader.cpp index abda4b82..3a87ad99 100644 --- a/src/easy2d/utils/ResLoader.cpp +++ b/src/easy2d/utils/ResLoader.cpp @@ -22,7 +22,6 @@ #include "../core/modules.h" #include "../core/Image.h" #include "../core/Frames.h" -#include "../audio/Music.h" namespace easy2d { @@ -192,30 +191,6 @@ namespace easy2d return false; } - bool ResLoader::AddMusic(String const & id, Resource const & music) - { - MusicPtr ptr = new (std::nothrow) Music; - if (ptr) - { - if (ptr->Load(LocateRes(music, search_paths_))) - { - res_.insert(std::make_pair(id, ptr)); - return true; - } - } - return false; - } - - bool ResLoader::AddMusic(String const & id, MusicPtr const & music) - { - if (music) - { - res_.insert(std::make_pair(id, music)); - return true; - } - return false; - } - bool ResLoader::AddObj(String const& id, ObjectPtr const& obj) { if (obj) @@ -228,22 +203,17 @@ namespace easy2d ImagePtr ResLoader::GetImage(String const & id) const { - return Get(id); + return Get(id); } FramesPtr ResLoader::GetFrames(String const & id) const { - return Get(id); - } - - MusicPtr ResLoader::GetMusic(String const & id) const - { - return Get(id); + return Get(id); } ObjectPtr ResLoader::GetObj(String const & id) const { - return Get(id); + return Get(id); } void ResLoader::Delete(String const & id) diff --git a/src/easy2d/utils/ResLoader.h b/src/easy2d/utils/ResLoader.h index 7aac4361..cef9231f 100644 --- a/src/easy2d/utils/ResLoader.h +++ b/src/easy2d/utils/ResLoader.h @@ -21,7 +21,6 @@ #pragma once #include "../core/include-forwards.h" #include "../core/Resource.h" -#include "../audio/Music.h" namespace easy2d { @@ -51,12 +50,6 @@ namespace easy2d // Ìí¼ÓÖ¡¼¯ºÏ bool AddFrames(String const& id, FramesPtr const& frames); - // Ìí¼ÓÒôÀÖ - bool AddMusic(String const& id, Resource const& music); - - // Ìí¼ÓÒôÀÖ - bool AddMusic(String const& id, MusicPtr const& music); - // Ìí¼Ó¶ÔÏó bool AddObj(String const& id, ObjectPtr const& obj); @@ -64,8 +57,6 @@ namespace easy2d FramesPtr GetFrames(String const& id) const; - MusicPtr GetMusic(String const& id) const; - ObjectPtr GetObj(String const& id) const; // ɾ³ýÖ¸¶¨×ÊÔ´ @@ -79,13 +70,13 @@ namespace easy2d String const& path ); - template - auto Get(String const& id) const -> decltype(auto) + template + _Ty* Get(String const& id) const { auto iter = res_.find(id); if (iter == res_.end()) - return T{}; - return dynamic_cast((*iter).second.Get()); + return nullptr; + return dynamic_cast<_Ty*>((*iter).second.Get()); } protected: