[deploy] Merge pull request #44 from KiwanoEngine/dev
Refactoring Event distribution mechanism
This commit is contained in:
		
						commit
						8119de2c4a
					
				|  | @ -13,7 +13,7 @@ | |||
|   <ItemGroup> | ||||
|     <ClInclude Include="..\..\src\kiwano-physics\Body.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano-physics\Contact.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano-physics\ContactListener.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano-physics\ContactEvent.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano-physics\Fixture.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano-physics\helper.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano-physics\Joint.h" /> | ||||
|  | @ -24,7 +24,7 @@ | |||
|   <ItemGroup> | ||||
|     <ClCompile Include="..\..\src\kiwano-physics\Body.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano-physics\Contact.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano-physics\ContactListener.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano-physics\ContactEvent.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano-physics\Fixture.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano-physics\Joint.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano-physics\Shape.cpp" /> | ||||
|  |  | |||
|  | @ -9,7 +9,7 @@ | |||
|     <ClInclude Include="..\..\src\kiwano-physics\helper.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano-physics\Fixture.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano-physics\Contact.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano-physics\ContactListener.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano-physics\ContactEvent.h" /> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ClCompile Include="..\..\src\kiwano-physics\Body.cpp" /> | ||||
|  | @ -18,6 +18,6 @@ | |||
|     <ClCompile Include="..\..\src\kiwano-physics\Shape.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano-physics\Fixture.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano-physics\Contact.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano-physics\ContactListener.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano-physics\ContactEvent.cpp" /> | ||||
|   </ItemGroup> | ||||
| </Project> | ||||
|  | @ -11,19 +11,21 @@ | |||
|     <ClInclude Include="..\..\src\kiwano\2d\action\Animation.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\2d\Frame.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\2d\GifSprite.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\Director.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\win32\ComPtr.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\win32\helper.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\any.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\basic_json.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\function.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\core.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\intrusive_list.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\intrusive_ptr.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\noncopyable.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\singleton.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\string.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\vector.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\Director.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\Event.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\Library.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\win32\ComPtr.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\win32\helper.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\common\any.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\common\basic_json.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\common\function.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\common\common.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\common\intrusive_list.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\common\intrusive_ptr.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\common\noncopyable.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\common\singleton.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\common\string.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\common\vector.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\kiwano.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\config.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\macros.h" /> | ||||
|  | @ -40,22 +42,19 @@ | |||
|     <ClInclude Include="..\..\src\kiwano\2d\TextStyle.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\2d\Transform.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\2d\Transition.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\AsyncTask.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\Component.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\Event.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\EventDispatcher.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\EventListener.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\Input.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\keys.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\Logger.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\ObjectBase.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\RefCounter.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\Resource.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\SmartPtr.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\Timer.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\TimerManager.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\time.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\Window.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\AsyncTask.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\Component.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\EventDispatcher.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\EventListener.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\keys.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\Logger.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\ObjectBase.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\RefCounter.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\Resource.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\SmartPtr.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\Timer.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\TimerManager.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\time.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\math\constants.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\math\ease.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\math\math.h" /> | ||||
|  | @ -65,7 +64,10 @@ | |||
|     <ClInclude Include="..\..\src\kiwano\math\scalar.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\math\Vec2.hpp" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\platform\Application.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\platform\FileSystem.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\platform\Input.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\platform\modules.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\platform\Window.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\renderer\Brush.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\renderer\Color.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\renderer\Font.h" /> | ||||
|  | @ -88,7 +90,6 @@ | |||
|     <ClInclude Include="..\..\src\kiwano\ui\Button.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\ui\Menu.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\utils\LocalStorage.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\utils\FileSystem.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\utils\ResourceCache.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\utils\UserData.h" /> | ||||
|   </ItemGroup> | ||||
|  | @ -113,21 +114,24 @@ | |||
|     <ClCompile Include="..\..\src\kiwano\2d\Text.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\2d\Transform.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\2d\Transition.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\base\AsyncTask.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\base\Component.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\base\EventDispatcher.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\base\EventListener.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\base\Input.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\base\Logger.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\base\ObjectBase.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\base\Resource.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\base\Director.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\base\Timer.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\base\TimerManager.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\base\time.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\base\Window.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\core\AsyncTask.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\core\Component.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\core\Event.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\core\EventDispatcher.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\core\EventListener.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\core\Library.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\core\Logger.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\core\ObjectBase.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\core\Resource.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\core\Director.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\core\Timer.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\core\TimerManager.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\core\time.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\platform\Application.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\platform\FileSystem.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\platform\Input.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\platform\modules.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\platform\Window.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\renderer\Brush.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\renderer\Color.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\renderer\Font.cpp" /> | ||||
|  | @ -148,7 +152,6 @@ | |||
|     <ClCompile Include="..\..\src\kiwano\ui\Button.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\ui\Menu.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\utils\LocalStorage.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\utils\FileSystem.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\utils\ResourceCache.cpp" /> | ||||
|     <ClCompile Include="..\..\src\kiwano\utils\UserData.cpp" /> | ||||
|   </ItemGroup> | ||||
|  |  | |||
|  | @ -16,7 +16,7 @@ | |||
|     <Filter Include="2d"> | ||||
|       <UniqueIdentifier>{896bdedf-6e82-449b-9b6e-0bc69f3699b1}</UniqueIdentifier> | ||||
|     </Filter> | ||||
|     <Filter Include="base"> | ||||
|     <Filter Include="core"> | ||||
|       <UniqueIdentifier>{2e18d99a-e906-499a-9e29-4e0783202644}</UniqueIdentifier> | ||||
|     </Filter> | ||||
|     <Filter Include="renderer"> | ||||
|  | @ -25,13 +25,13 @@ | |||
|     <Filter Include="2d\action"> | ||||
|       <UniqueIdentifier>{9314f30d-5742-48b6-94e5-e3b4284106f6}</UniqueIdentifier> | ||||
|     </Filter> | ||||
|     <Filter Include="core"> | ||||
|     <Filter Include="common"> | ||||
|       <UniqueIdentifier>{86e2d0f2-a9d0-4456-b6a5-d480228bbf82}</UniqueIdentifier> | ||||
|     </Filter> | ||||
|     <Filter Include="renderer\win32"> | ||||
|       <UniqueIdentifier>{30333461-e9bc-4709-84bd-ce6e0e1a3079}</UniqueIdentifier> | ||||
|     </Filter> | ||||
|     <Filter Include="base\win32"> | ||||
|     <Filter Include="core\win32"> | ||||
|       <UniqueIdentifier>{192a47a9-9df6-4f40-a7d3-888eb00c53ac}</UniqueIdentifier> | ||||
|     </Filter> | ||||
|   </ItemGroup> | ||||
|  | @ -63,29 +63,23 @@ | |||
|     <ClInclude Include="..\..\src\kiwano\2d\Transition.h"> | ||||
|       <Filter>2d</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\Component.h"> | ||||
|       <Filter>base</Filter> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\Component.h"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\Event.hpp"> | ||||
|       <Filter>base</Filter> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\EventDispatcher.h"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\EventDispatcher.h"> | ||||
|       <Filter>base</Filter> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\EventListener.h"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\EventListener.h"> | ||||
|       <Filter>base</Filter> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\RefCounter.hpp"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\keys.hpp"> | ||||
|       <Filter>base</Filter> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\Resource.h"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\RefCounter.hpp"> | ||||
|       <Filter>base</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\Resource.h"> | ||||
|       <Filter>base</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\time.h"> | ||||
|       <Filter>base</Filter> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\time.h"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\math\Matrix.hpp"> | ||||
|       <Filter>math</Filter> | ||||
|  | @ -107,27 +101,24 @@ | |||
|     <ClInclude Include="..\..\src\kiwano\math\Vec2.hpp"> | ||||
|       <Filter>math</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\Input.h"> | ||||
|       <Filter>base</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\SmartPtr.hpp"> | ||||
|       <Filter>base</Filter> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\SmartPtr.hpp"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\kiwano.h" /> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\Timer.h"> | ||||
|       <Filter>base</Filter> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\Timer.h"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\TimerManager.h"> | ||||
|       <Filter>base</Filter> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\TimerManager.h"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\AsyncTask.h"> | ||||
|       <Filter>base</Filter> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\AsyncTask.h"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\2d\GifSprite.h"> | ||||
|       <Filter>2d</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\Director.h"> | ||||
|       <Filter>base</Filter> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\Director.h"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\2d\Actor.h"> | ||||
|       <Filter>2d</Filter> | ||||
|  | @ -162,32 +153,32 @@ | |||
|     <ClInclude Include="..\..\src\kiwano\2d\FrameSequence.h"> | ||||
|       <Filter>2d</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\basic_json.hpp"> | ||||
|       <Filter>core</Filter> | ||||
|     <ClInclude Include="..\..\src\kiwano\common\basic_json.hpp"> | ||||
|       <Filter>common</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\function.hpp"> | ||||
|       <Filter>core</Filter> | ||||
|     <ClInclude Include="..\..\src\kiwano\common\function.hpp"> | ||||
|       <Filter>common</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\intrusive_list.hpp"> | ||||
|       <Filter>core</Filter> | ||||
|     <ClInclude Include="..\..\src\kiwano\common\intrusive_list.hpp"> | ||||
|       <Filter>common</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\intrusive_ptr.hpp"> | ||||
|       <Filter>core</Filter> | ||||
|     <ClInclude Include="..\..\src\kiwano\common\intrusive_ptr.hpp"> | ||||
|       <Filter>common</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\noncopyable.hpp"> | ||||
|       <Filter>core</Filter> | ||||
|     <ClInclude Include="..\..\src\kiwano\common\noncopyable.hpp"> | ||||
|       <Filter>common</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\singleton.hpp"> | ||||
|       <Filter>core</Filter> | ||||
|     <ClInclude Include="..\..\src\kiwano\common\singleton.hpp"> | ||||
|       <Filter>common</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\string.hpp"> | ||||
|       <Filter>core</Filter> | ||||
|     <ClInclude Include="..\..\src\kiwano\common\string.hpp"> | ||||
|       <Filter>common</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\vector.hpp"> | ||||
|       <Filter>core</Filter> | ||||
|     <ClInclude Include="..\..\src\kiwano\common\vector.hpp"> | ||||
|       <Filter>common</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\core.h"> | ||||
|       <Filter>core</Filter> | ||||
|     <ClInclude Include="..\..\src\kiwano\common\common.h"> | ||||
|       <Filter>common</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\2d\DebugActor.h"> | ||||
|       <Filter>2d</Filter> | ||||
|  | @ -201,17 +192,14 @@ | |||
|     <ClInclude Include="..\..\src\kiwano\2d\action\ActionWalk.h"> | ||||
|       <Filter>2d\action</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\Logger.h"> | ||||
|       <Filter>base</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\Window.h"> | ||||
|       <Filter>base</Filter> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\Logger.h"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\math\math.h"> | ||||
|       <Filter>math</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\ObjectBase.h"> | ||||
|       <Filter>base</Filter> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\ObjectBase.h"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\renderer\Color.h"> | ||||
|       <Filter>renderer</Filter> | ||||
|  | @ -282,24 +270,39 @@ | |||
|     <ClInclude Include="..\..\src\kiwano\math\scalar.h"> | ||||
|       <Filter>math</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\win32\ComPtr.hpp"> | ||||
|       <Filter>base\win32</Filter> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\win32\ComPtr.hpp"> | ||||
|       <Filter>core\win32</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\base\win32\helper.h"> | ||||
|       <Filter>base\win32</Filter> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\win32\helper.h"> | ||||
|       <Filter>core\win32</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\utils\LocalStorage.h"> | ||||
|       <Filter>utils</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\utils\FileSystem.h"> | ||||
|       <Filter>utils</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\any.hpp"> | ||||
|       <Filter>core</Filter> | ||||
|     <ClInclude Include="..\..\src\kiwano\common\any.hpp"> | ||||
|       <Filter>common</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\utils\UserData.h"> | ||||
|       <Filter>utils</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\Library.h"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\Event.h"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\platform\FileSystem.h"> | ||||
|       <Filter>platform</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\core\keys.h"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\platform\Input.h"> | ||||
|       <Filter>platform</Filter> | ||||
|     </ClInclude> | ||||
|     <ClInclude Include="..\..\src\kiwano\platform\Window.h"> | ||||
|       <Filter>platform</Filter> | ||||
|     </ClInclude> | ||||
|   </ItemGroup> | ||||
|   <ItemGroup> | ||||
|     <ClCompile Include="..\..\src\kiwano\ui\Button.cpp"> | ||||
|  | @ -323,17 +326,17 @@ | |||
|     <ClCompile Include="..\..\src\kiwano\2d\Transition.cpp"> | ||||
|       <Filter>2d</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\src\kiwano\base\EventDispatcher.cpp"> | ||||
|       <Filter>base</Filter> | ||||
|     <ClCompile Include="..\..\src\kiwano\core\EventDispatcher.cpp"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\src\kiwano\base\EventListener.cpp"> | ||||
|       <Filter>base</Filter> | ||||
|     <ClCompile Include="..\..\src\kiwano\core\EventListener.cpp"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\src\kiwano\base\Resource.cpp"> | ||||
|       <Filter>base</Filter> | ||||
|     <ClCompile Include="..\..\src\kiwano\core\Resource.cpp"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\src\kiwano\base\time.cpp"> | ||||
|       <Filter>base</Filter> | ||||
|     <ClCompile Include="..\..\src\kiwano\core\time.cpp"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\src\kiwano\platform\Application.cpp"> | ||||
|       <Filter>platform</Filter> | ||||
|  | @ -341,23 +344,20 @@ | |||
|     <ClCompile Include="..\..\src\kiwano\platform\modules.cpp"> | ||||
|       <Filter>platform</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\src\kiwano\base\Input.cpp"> | ||||
|       <Filter>base</Filter> | ||||
|     <ClCompile Include="..\..\src\kiwano\core\Timer.cpp"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\src\kiwano\base\Timer.cpp"> | ||||
|       <Filter>base</Filter> | ||||
|     <ClCompile Include="..\..\src\kiwano\core\TimerManager.cpp"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\src\kiwano\base\TimerManager.cpp"> | ||||
|       <Filter>base</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\src\kiwano\base\AsyncTask.cpp"> | ||||
|       <Filter>base</Filter> | ||||
|     <ClCompile Include="..\..\src\kiwano\core\AsyncTask.cpp"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\src\kiwano\2d\GifSprite.cpp"> | ||||
|       <Filter>2d</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\src\kiwano\base\Director.cpp"> | ||||
|       <Filter>base</Filter> | ||||
|     <ClCompile Include="..\..\src\kiwano\core\Director.cpp"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\src\kiwano\2d\Actor.cpp"> | ||||
|       <Filter>2d</Filter> | ||||
|  | @ -401,14 +401,11 @@ | |||
|     <ClCompile Include="..\..\src\kiwano\2d\action\ActionWalk.cpp"> | ||||
|       <Filter>2d\action</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\src\kiwano\base\Logger.cpp"> | ||||
|       <Filter>base</Filter> | ||||
|     <ClCompile Include="..\..\src\kiwano\core\Logger.cpp"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\src\kiwano\base\Window.cpp"> | ||||
|       <Filter>base</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\src\kiwano\base\ObjectBase.cpp"> | ||||
|       <Filter>base</Filter> | ||||
|     <ClCompile Include="..\..\src\kiwano\core\ObjectBase.cpp"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\src\kiwano\renderer\Color.cpp"> | ||||
|       <Filter>renderer</Filter> | ||||
|  | @ -464,17 +461,29 @@ | |||
|     <ClCompile Include="..\..\src\kiwano\renderer\Brush.cpp"> | ||||
|       <Filter>renderer</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\src\kiwano\base\Component.cpp"> | ||||
|       <Filter>base</Filter> | ||||
|     <ClCompile Include="..\..\src\kiwano\core\Component.cpp"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\src\kiwano\utils\LocalStorage.cpp"> | ||||
|       <Filter>utils</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\src\kiwano\utils\FileSystem.cpp"> | ||||
|       <Filter>utils</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\src\kiwano\utils\UserData.cpp"> | ||||
|       <Filter>utils</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\src\kiwano\core\Library.cpp"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\src\kiwano\core\Event.cpp"> | ||||
|       <Filter>core</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\src\kiwano\platform\FileSystem.cpp"> | ||||
|       <Filter>platform</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\src\kiwano\platform\Input.cpp"> | ||||
|       <Filter>platform</Filter> | ||||
|     </ClCompile> | ||||
|     <ClCompile Include="..\..\src\kiwano\platform\Window.cpp"> | ||||
|       <Filter>platform</Filter> | ||||
|     </ClCompile> | ||||
|   </ItemGroup> | ||||
| </Project> | ||||
|  | @ -18,7 +18,7 @@ | |||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | ||||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #include <kiwano/base/win32/helper.h> | ||||
| #include <kiwano/core/win32/helper.h> | ||||
| #include <kiwano-audio/audio-modules.h> | ||||
| #include <kiwano-audio/AudioEngine.h> | ||||
| 
 | ||||
|  |  | |||
|  | @ -19,10 +19,11 @@ | |||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #pragma once | ||||
| #include <kiwano/core/singleton.hpp> | ||||
| #include <kiwano/base/Component.h> | ||||
| #include <kiwano/base/win32/ComPtr.hpp> | ||||
| #include <kiwano/common/singleton.hpp> | ||||
| #include <kiwano/core/Component.h> | ||||
| #include <kiwano/core/win32/ComPtr.hpp> | ||||
| #include <kiwano-audio/Transcoder.h> | ||||
| #include <xaudio2.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
|  |  | |||
|  | @ -18,8 +18,8 @@ | |||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | ||||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #include <kiwano/base/Logger.h> | ||||
| #include <kiwano/utils/FileSystem.h> | ||||
| #include <kiwano/core/Logger.h> | ||||
| #include <kiwano/platform/FileSystem.h> | ||||
| #include <kiwano-audio/Sound.h> | ||||
| #include <kiwano-audio/AudioEngine.h> | ||||
| 
 | ||||
|  |  | |||
|  | @ -19,11 +19,11 @@ | |||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #pragma once | ||||
| #include <kiwano/core/intrusive_ptr.hpp> | ||||
| #include <kiwano/base/ObjectBase.h> | ||||
| #include <kiwano/base/Resource.h> | ||||
| #include <xaudio2.h> | ||||
| #include <kiwano/common/intrusive_ptr.hpp> | ||||
| #include <kiwano/core/ObjectBase.h> | ||||
| #include <kiwano/core/Resource.h> | ||||
| #include <kiwano-audio/Transcoder.h> | ||||
| #include <xaudio2.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
|  |  | |||
|  | @ -19,8 +19,8 @@ | |||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #pragma once | ||||
| #include <kiwano/core/intrusive_ptr.hpp> | ||||
| #include <kiwano/base/ObjectBase.h> | ||||
| #include <kiwano/common/intrusive_ptr.hpp> | ||||
| #include <kiwano/core/ObjectBase.h> | ||||
| #include <kiwano-audio/Sound.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
|  |  | |||
|  | @ -23,10 +23,10 @@ | |||
| #endif | ||||
| 
 | ||||
| #include <kiwano/macros.h> | ||||
| #include <kiwano/core/string.hpp> | ||||
| #include <kiwano/base/Resource.h> | ||||
| #include <kiwano/base/Logger.h> | ||||
| #include <kiwano/base/win32/ComPtr.hpp> | ||||
| #include <kiwano/common/string.hpp> | ||||
| #include <kiwano/core/Resource.h> | ||||
| #include <kiwano/core/Logger.h> | ||||
| #include <kiwano/core/win32/ComPtr.hpp> | ||||
| #include <kiwano/platform/modules.h> | ||||
| #include <kiwano-audio/audio-modules.h> | ||||
| #include <kiwano-audio/Transcoder.h> | ||||
|  |  | |||
|  | @ -19,7 +19,7 @@ | |||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #pragma once | ||||
| #include <kiwano/base/Resource.h> | ||||
| #include <kiwano/core/Resource.h> | ||||
| #include <mfapi.h> | ||||
| #include <mfidl.h> | ||||
| #include <mfreadwrite.h> | ||||
|  |  | |||
|  | @ -18,7 +18,7 @@ | |||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | ||||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #include <kiwano/base/Logger.h> | ||||
| #include <kiwano/core/Logger.h> | ||||
| #include <kiwano-audio/audio-modules.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
|  | @ -28,7 +28,7 @@ namespace kiwano | |||
| 		namespace modules | ||||
| 		{ | ||||
| 			XAudio2::XAudio2() | ||||
| 				: xaudio2(nullptr) | ||||
| 				: xaudio2() | ||||
| 				, XAudio2Create(nullptr) | ||||
| 			{ | ||||
| 				const auto xaudio2_dll_names = | ||||
|  | @ -40,16 +40,17 @@ namespace kiwano | |||
| 
 | ||||
| 				for (const auto& name : xaudio2_dll_names) | ||||
| 				{ | ||||
| 					xaudio2 = LoadLibraryW(name); | ||||
| 					if (xaudio2) | ||||
| 					if (xaudio2.Load(name)) | ||||
| 					{ | ||||
| 						XAudio2Create = (PFN_XAudio2Create) | ||||
| 							GetProcAddress(xaudio2, "XAudio2Create"); | ||||
| 						break; | ||||
| 					} | ||||
| 				} | ||||
| 
 | ||||
| 				if (!xaudio2) | ||||
| 				if (xaudio2.IsValid()) | ||||
| 				{ | ||||
| 					XAudio2Create = xaudio2.GetProcess<PFN_XAudio2Create>(L"XAudio2Create"); | ||||
| 				} | ||||
| 				else | ||||
| 				{ | ||||
| 					KGE_ERROR_LOG(L"Load xaudio2.dll failed"); | ||||
| 					throw std::runtime_error("Load xaudio2.dll failed"); | ||||
|  | @ -57,8 +58,8 @@ namespace kiwano | |||
| 			} | ||||
| 
 | ||||
| 			MediaFoundation::MediaFoundation() | ||||
| 				: mfplat(nullptr) | ||||
| 				, mfreadwrite(nullptr) | ||||
| 				: mfplat() | ||||
| 				, mfreadwrite() | ||||
| 				, MFStartup(nullptr) | ||||
| 				, MFShutdown(nullptr) | ||||
| 				, MFCreateMediaType(nullptr) | ||||
|  | @ -67,23 +68,13 @@ namespace kiwano | |||
| 				, MFCreateSourceReaderFromByteStream(nullptr) | ||||
| 				, MFCreateMFByteStreamOnStream(nullptr) | ||||
| 			{ | ||||
| 				mfplat = LoadLibraryW(L"Mfplat.dll"); | ||||
| 				if (mfplat) | ||||
| 				if (mfplat.Load(L"Mfplat.dll")) | ||||
| 				{ | ||||
| 					MFStartup = (PFN_MFStartup) | ||||
| 						GetProcAddress(mfplat, "MFStartup"); | ||||
| 
 | ||||
| 					MFShutdown = (PFN_MFShutdown) | ||||
| 						GetProcAddress(mfplat, "MFShutdown"); | ||||
| 
 | ||||
| 					MFCreateMediaType = (PFN_MFCreateMediaType) | ||||
| 						GetProcAddress(mfplat, "MFCreateMediaType"); | ||||
| 
 | ||||
| 					MFCreateWaveFormatExFromMFMediaType = (PFN_MFCreateWaveFormatExFromMFMediaType) | ||||
| 						GetProcAddress(mfplat, "MFCreateWaveFormatExFromMFMediaType"); | ||||
| 
 | ||||
| 					MFCreateMFByteStreamOnStream = (PFN_MFCreateMFByteStreamOnStream) | ||||
| 						GetProcAddress(mfplat, "MFCreateMFByteStreamOnStream"); | ||||
| 					MFStartup = mfplat.GetProcess<PFN_MFStartup>(L"MFStartup"); | ||||
| 					MFShutdown = mfplat.GetProcess<PFN_MFShutdown>(L"MFShutdown"); | ||||
| 					MFCreateMediaType = mfplat.GetProcess<PFN_MFCreateMediaType>(L"MFCreateMediaType"); | ||||
| 					MFCreateWaveFormatExFromMFMediaType = mfplat.GetProcess<PFN_MFCreateWaveFormatExFromMFMediaType>(L"MFCreateWaveFormatExFromMFMediaType"); | ||||
| 					MFCreateMFByteStreamOnStream = mfplat.GetProcess<PFN_MFCreateMFByteStreamOnStream>(L"MFCreateMFByteStreamOnStream"); | ||||
| 				} | ||||
| 				else | ||||
| 				{ | ||||
|  | @ -91,14 +82,10 @@ namespace kiwano | |||
| 					throw std::runtime_error("Load Mfplat.dll failed"); | ||||
| 				} | ||||
| 
 | ||||
| 				mfreadwrite = LoadLibraryW(L"Mfreadwrite.dll"); | ||||
| 				if (mfreadwrite) | ||||
| 				if (mfreadwrite.Load(L"Mfreadwrite.dll")) | ||||
| 				{ | ||||
| 					MFCreateSourceReaderFromURL = (PFN_MFCreateSourceReaderFromURL) | ||||
| 						GetProcAddress(mfreadwrite, "MFCreateSourceReaderFromURL"); | ||||
| 
 | ||||
| 					MFCreateSourceReaderFromByteStream = (PFN_MFCreateSourceReaderFromByteStream) | ||||
| 						GetProcAddress(mfreadwrite, "MFCreateSourceReaderFromByteStream"); | ||||
| 					MFCreateSourceReaderFromURL = mfreadwrite.GetProcess<PFN_MFCreateSourceReaderFromURL>(L"MFCreateSourceReaderFromURL"); | ||||
| 					MFCreateSourceReaderFromByteStream = mfreadwrite.GetProcess<PFN_MFCreateSourceReaderFromByteStream>(L"MFCreateSourceReaderFromByteStream"); | ||||
| 				} | ||||
| 				else | ||||
| 				{ | ||||
|  |  | |||
|  | @ -19,6 +19,7 @@ | |||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #pragma once | ||||
| #include <kiwano/core/Library.h> | ||||
| #include <xaudio2.h> | ||||
| #include <mfapi.h> | ||||
| #include <mfidl.h> | ||||
|  | @ -32,13 +33,6 @@ namespace kiwano | |||
| 		{ | ||||
| 			class KGE_API XAudio2 | ||||
| 			{ | ||||
| 				XAudio2(); | ||||
| 
 | ||||
| 				HMODULE xaudio2; | ||||
| 
 | ||||
| 				// XAudio2 functions
 | ||||
| 				typedef HRESULT(WINAPI* PFN_XAudio2Create)(IXAudio2**, UINT32, XAUDIO2_PROCESSOR); | ||||
| 
 | ||||
| 			public: | ||||
| 				static inline XAudio2& Get() | ||||
| 				{ | ||||
|  | @ -46,16 +40,29 @@ namespace kiwano | |||
| 					return instance; | ||||
| 				} | ||||
| 
 | ||||
| 				// XAudio2 functions
 | ||||
| 				typedef HRESULT(WINAPI* PFN_XAudio2Create)(IXAudio2**, UINT32, XAUDIO2_PROCESSOR); | ||||
| 
 | ||||
| 				PFN_XAudio2Create XAudio2Create; | ||||
| 
 | ||||
| 			private: | ||||
| 				XAudio2(); | ||||
| 
 | ||||
| 				XAudio2(const XAudio2&) = delete; | ||||
| 				XAudio2& operator=(const XAudio2&) = delete; | ||||
| 
 | ||||
| 				Library xaudio2; | ||||
| 			}; | ||||
| 
 | ||||
| 
 | ||||
| 			class KGE_API MediaFoundation | ||||
| 			{ | ||||
| 				MediaFoundation(); | ||||
| 
 | ||||
| 				HMODULE mfplat; | ||||
| 				HMODULE mfreadwrite; | ||||
| 			public: | ||||
| 				static inline MediaFoundation& Get() | ||||
| 				{ | ||||
| 					static MediaFoundation instance; | ||||
| 					return instance; | ||||
| 				} | ||||
| 
 | ||||
| 				// MediaFoundation functions
 | ||||
| 				typedef HRESULT(WINAPI* PFN_MFStartup)(ULONG, DWORD); | ||||
|  | @ -66,13 +73,6 @@ namespace kiwano | |||
| 				typedef HRESULT(WINAPI* PFN_MFCreateSourceReaderFromByteStream)(IMFByteStream*, IMFAttributes*, IMFSourceReader**); | ||||
| 				typedef HRESULT(WINAPI* PFN_MFCreateMFByteStreamOnStream)(IStream*, IMFByteStream**); | ||||
| 
 | ||||
| 			public: | ||||
| 				static inline MediaFoundation& Get() | ||||
| 				{ | ||||
| 					static MediaFoundation instance; | ||||
| 					return instance; | ||||
| 				} | ||||
| 
 | ||||
| 				PFN_MFStartup MFStartup; | ||||
| 				PFN_MFShutdown MFShutdown; | ||||
| 				PFN_MFCreateMediaType MFCreateMediaType; | ||||
|  | @ -80,6 +80,15 @@ namespace kiwano | |||
| 				PFN_MFCreateSourceReaderFromURL MFCreateSourceReaderFromURL; | ||||
| 				PFN_MFCreateSourceReaderFromByteStream MFCreateSourceReaderFromByteStream; | ||||
| 				PFN_MFCreateMFByteStreamOnStream MFCreateMFByteStreamOnStream; | ||||
| 
 | ||||
| 			private: | ||||
| 				MediaFoundation(); | ||||
| 
 | ||||
| 				MediaFoundation(const MediaFoundation&) = delete; | ||||
| 				MediaFoundation& operator=(const MediaFoundation&) = delete; | ||||
| 
 | ||||
| 				Library mfplat; | ||||
| 				Library mfreadwrite; | ||||
| 			}; | ||||
| 		} | ||||
| 	} | ||||
|  |  | |||
|  | @ -1,10 +1,10 @@ | |||
| // Copyright (C) 2019 Nomango
 | ||||
| 
 | ||||
| #include <kiwano/core/core.h> | ||||
| #include <kiwano/core/Function.hpp> | ||||
| #include <kiwano/core/intrusive_ptr.hpp> | ||||
| #include <kiwano/base/Window.h> | ||||
| #include <kiwano/base/Input.h> | ||||
| #include <kiwano/common/common.h> | ||||
| #include <kiwano/common/Function.hpp> | ||||
| #include <kiwano/common/intrusive_ptr.hpp> | ||||
| #include <kiwano/platform/Window.h> | ||||
| #include <kiwano/platform/Input.h> | ||||
| #include <kiwano/renderer/Renderer.h> | ||||
| #include <kiwano-imgui/ImGuiModule.h> | ||||
| #include <kiwano-imgui/imgui_impl.h> | ||||
|  |  | |||
|  | @ -19,8 +19,8 @@ | |||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #pragma once | ||||
| #include <kiwano/base/Component.h> | ||||
| #include <kiwano/core/singleton.hpp> | ||||
| #include <kiwano/core/Component.h> | ||||
| #include <kiwano/common/singleton.hpp> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| // dear imgui: Renderer for Kiwano (DirectX11)
 | ||||
| 
 | ||||
| #include <kiwano/base/win32/helper.h> | ||||
| #include <kiwano/core/win32/helper.h> | ||||
| #include <kiwano-imgui/imgui_impl_dx11.h> | ||||
| 
 | ||||
| // DirectX
 | ||||
|  |  | |||
|  | @ -25,7 +25,7 @@ | |||
| #include <kiwano-network/HttpResponse.hpp> | ||||
| #include <kiwano-network/HttpClient.h> | ||||
| 
 | ||||
| #include <kiwano/base/Logger.h> | ||||
| #include <kiwano/core/Logger.h> | ||||
| #include <kiwano/platform/Application.h> | ||||
| #include <3rd-party/curl/curl.h>  // CURL
 | ||||
| 
 | ||||
|  | @ -36,7 +36,7 @@ namespace | |||
| 
 | ||||
| 	uint32_t write_data(void* buffer, uint32_t size, uint32_t nmemb, void* userp) | ||||
| 	{ | ||||
| 		core::string* recv_buffer = (core::string*)userp; | ||||
| 		common::string* recv_buffer = (common::string*)userp; | ||||
| 		uint32_t total = size * nmemb; | ||||
| 
 | ||||
| 		// add data to the end of recv_buffer
 | ||||
|  | @ -46,10 +46,10 @@ namespace | |||
| 		return total; | ||||
| 	} | ||||
| 
 | ||||
| 	core::string convert_to_utf8(core::wstring const& str) | ||||
| 	common::string convert_to_utf8(common::wstring const& str) | ||||
| 	{ | ||||
| 		std::wstring_convert<std::codecvt_utf8<wchar_t>> utf8_conv; | ||||
| 		core::string result; | ||||
| 		common::string result; | ||||
| 
 | ||||
| 		try | ||||
| 		{ | ||||
|  | @ -63,10 +63,10 @@ namespace | |||
| 		return result; | ||||
| 	} | ||||
| 
 | ||||
| 	core::wstring convert_from_utf8(core::string const& str) | ||||
| 	common::wstring convert_from_utf8(common::string const& str) | ||||
| 	{ | ||||
| 		kiwano::string_convert<std::codecvt_utf8<wchar_t>> utf8_conv; | ||||
| 		core::wstring result; | ||||
| 		common::wstring result; | ||||
| 
 | ||||
| 		try | ||||
| 		{ | ||||
|  | @ -104,7 +104,7 @@ namespace | |||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		bool Init(HttpClient* client, Vector<core::string> const& headers, core::string const& url, core::string* response_data, core::string* response_header, char* error_buffer) | ||||
| 		bool Init(HttpClient* client, Vector<common::string> const& headers, common::string const& url, common::string* response_data, common::string* response_header, char* error_buffer) | ||||
| 		{ | ||||
| 			if (!SetOption(CURLOPT_ERRORBUFFER, error_buffer)) | ||||
| 				return false; | ||||
|  | @ -170,11 +170,11 @@ namespace | |||
| 	public: | ||||
| 		static inline bool GetRequest( | ||||
| 			HttpClient* client, | ||||
| 			Vector<core::string> const& headers, | ||||
| 			core::string const& url, | ||||
| 			Vector<common::string> const& headers, | ||||
| 			common::string const& url, | ||||
| 			long* response_code, | ||||
| 			core::string* response_data, | ||||
| 			core::string* response_header, | ||||
| 			common::string* response_data, | ||||
| 			common::string* response_header, | ||||
| 			char* error_buffer) | ||||
| 		{ | ||||
| 			Curl curl; | ||||
|  | @ -185,12 +185,12 @@ namespace | |||
| 
 | ||||
| 		static inline bool PostRequest( | ||||
| 			HttpClient* client, | ||||
| 			Vector<core::string> const& headers, | ||||
| 			core::string const& url, | ||||
| 			core::string const& request_data, | ||||
| 			Vector<common::string> const& headers, | ||||
| 			common::string const& url, | ||||
| 			common::string const& request_data, | ||||
| 			long* response_code, | ||||
| 			core::string* response_data, | ||||
| 			core::string* response_header, | ||||
| 			common::string* response_data, | ||||
| 			common::string* response_header, | ||||
| 			char* error_buffer) | ||||
| 		{ | ||||
| 			Curl curl; | ||||
|  | @ -203,12 +203,12 @@ namespace | |||
| 
 | ||||
| 		static inline bool PutRequest( | ||||
| 			HttpClient* client, | ||||
| 			Vector<core::string> const& headers, | ||||
| 			core::string const& url, | ||||
| 			core::string const& request_data, | ||||
| 			Vector<common::string> const& headers, | ||||
| 			common::string const& url, | ||||
| 			common::string const& request_data, | ||||
| 			long* response_code, | ||||
| 			core::string* response_data, | ||||
| 			core::string* response_header, | ||||
| 			common::string* response_data, | ||||
| 			common::string* response_header, | ||||
| 			char* error_buffer) | ||||
| 		{ | ||||
| 			Curl curl; | ||||
|  | @ -221,11 +221,11 @@ namespace | |||
| 
 | ||||
| 		static inline bool DeleteRequest( | ||||
| 			HttpClient* client, | ||||
| 			Vector<core::string> const& headers, | ||||
| 			core::string const& url, | ||||
| 			Vector<common::string> const& headers, | ||||
| 			common::string const& url, | ||||
| 			long* response_code, | ||||
| 			core::string* response_data, | ||||
| 			core::string* response_header, | ||||
| 			common::string* response_data, | ||||
| 			common::string* response_header, | ||||
| 			char* error_buffer) | ||||
| 		{ | ||||
| 			Curl curl; | ||||
|  | @ -307,13 +307,13 @@ namespace kiwano | |||
| 			bool ok = false; | ||||
| 			long response_code = 0; | ||||
| 			char error_message[256] = { 0 }; | ||||
| 			core::string response_header; | ||||
| 			core::string response_data; | ||||
| 			common::string response_header; | ||||
| 			common::string response_data; | ||||
| 
 | ||||
| 			core::string url = convert_to_utf8(request->GetUrl()); | ||||
| 			core::string data = convert_to_utf8(request->GetData()); | ||||
| 			common::string url = convert_to_utf8(request->GetUrl()); | ||||
| 			common::string data = convert_to_utf8(request->GetData()); | ||||
| 
 | ||||
| 			Vector<core::string> headers; | ||||
| 			Vector<common::string> headers; | ||||
| 			headers.reserve(request->GetHeaders().size()); | ||||
| 			for (const auto& pair : request->GetHeaders()) | ||||
| 			{ | ||||
|  |  | |||
|  | @ -19,9 +19,9 @@ | |||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #pragma once | ||||
| #include <kiwano/core/core.h> | ||||
| #include <kiwano/core/singleton.hpp> | ||||
| #include <kiwano/base/Component.h> | ||||
| #include <kiwano/common/common.h> | ||||
| #include <kiwano/common/singleton.hpp> | ||||
| #include <kiwano/core/Component.h> | ||||
| #include <mutex> | ||||
| #include <condition_variable> | ||||
| 
 | ||||
|  | @ -36,39 +36,19 @@ namespace kiwano | |||
| 			KGE_DECLARE_SINGLETON(HttpClient); | ||||
| 
 | ||||
| 		public: | ||||
| 			void Send( | ||||
| 				HttpRequestPtr request | ||||
| 			); | ||||
| 			void Send(HttpRequestPtr request); | ||||
| 
 | ||||
| 			inline void SetTimeoutForConnect(Duration timeout) | ||||
| 			{ | ||||
| 				timeout_for_connect_ = timeout; | ||||
| 			} | ||||
| 			void SetTimeoutForConnect(Duration timeout); | ||||
| 
 | ||||
| 			inline Duration GetTimeoutForConnect() const | ||||
| 			{ | ||||
| 				return timeout_for_connect_; | ||||
| 			} | ||||
| 			Duration GetTimeoutForConnect() const; | ||||
| 
 | ||||
| 			inline void SetTimeoutForRead(Duration timeout) | ||||
| 			{ | ||||
| 				timeout_for_read_ = timeout; | ||||
| 			} | ||||
| 			void SetTimeoutForRead(Duration timeout); | ||||
| 
 | ||||
| 			inline Duration GetTimeoutForRead() const | ||||
| 			{ | ||||
| 				return timeout_for_read_; | ||||
| 			} | ||||
| 			Duration GetTimeoutForRead() const; | ||||
| 
 | ||||
| 			inline void SetSSLVerification(String const& root_certificate_path) | ||||
| 			{ | ||||
| 				ssl_verification_ = root_certificate_path; | ||||
| 			} | ||||
| 			void SetSSLVerification(String const& root_certificate_path); | ||||
| 
 | ||||
| 			inline String const& GetSSLVerification() const | ||||
| 			{ | ||||
| 				return ssl_verification_; | ||||
| 			} | ||||
| 			String const& GetSSLVerification() const; | ||||
| 
 | ||||
| 		public: | ||||
| 			virtual void SetupComponent() override; | ||||
|  | @ -101,5 +81,37 @@ namespace kiwano | |||
| 
 | ||||
| 			std::condition_variable_any sleep_condition_; | ||||
| 		}; | ||||
| 
 | ||||
| 
 | ||||
| 		inline void HttpClient::SetTimeoutForConnect(Duration timeout) | ||||
| 		{ | ||||
| 			timeout_for_connect_ = timeout; | ||||
| 		} | ||||
| 
 | ||||
| 		inline Duration HttpClient::GetTimeoutForConnect() const | ||||
| 		{ | ||||
| 			return timeout_for_connect_; | ||||
| 		} | ||||
| 
 | ||||
| 		inline void HttpClient::SetTimeoutForRead(Duration timeout) | ||||
| 		{ | ||||
| 			timeout_for_read_ = timeout; | ||||
| 		} | ||||
| 
 | ||||
| 		inline Duration HttpClient::GetTimeoutForRead() const | ||||
| 		{ | ||||
| 			return timeout_for_read_; | ||||
| 		} | ||||
| 
 | ||||
| 		inline void HttpClient::SetSSLVerification(String const& root_certificate_path) | ||||
| 		{ | ||||
| 			ssl_verification_ = root_certificate_path; | ||||
| 		} | ||||
| 
 | ||||
| 		inline String const& HttpClient::GetSSLVerification() const | ||||
| 		{ | ||||
| 			return ssl_verification_; | ||||
| 		} | ||||
| 
 | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -30,19 +30,5 @@ namespace kiwano | |||
| 			SetHeader(L"Content-Type", L"application/json;charset=UTF-8"); | ||||
| 			data_ = json.dump(); | ||||
| 		} | ||||
| 
 | ||||
| 		void HttpRequest::SetHeader(String const& field, String const& content) | ||||
| 		{ | ||||
| 			auto iter = headers_.find(field); | ||||
| 			if (iter != headers_.end()) | ||||
| 			{ | ||||
| 				headers_[field] = content; | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				headers_.insert(std::make_pair(field, content)); | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -19,10 +19,10 @@ | |||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #pragma once | ||||
| #include <kiwano/core/function.hpp> | ||||
| #include <kiwano/core/basic_json.hpp> | ||||
| #include <kiwano/base/ObjectBase.h> | ||||
| #include <kiwano/base/SmartPtr.hpp> | ||||
| #include <kiwano/common/function.hpp> | ||||
| #include <kiwano/common/basic_json.hpp> | ||||
| #include <kiwano/core/ObjectBase.h> | ||||
| #include <kiwano/core/SmartPtr.hpp> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
|  | @ -47,35 +47,32 @@ namespace kiwano | |||
| 				Delete | ||||
| 			}; | ||||
| 
 | ||||
| 			inline HttpRequest()			: type_(Type::Unknown) {} | ||||
| 			HttpRequest(); | ||||
| 
 | ||||
| 			inline HttpRequest(Type type)	: type_(type) {} | ||||
| 			HttpRequest(Type type); | ||||
| 
 | ||||
| 			inline void						SetUrl(String const& url)								{ url_ = url; } | ||||
| 			// 请求地址
 | ||||
| 			void SetUrl(String const& url); | ||||
| 			String const& GetUrl() const; | ||||
| 
 | ||||
| 			inline String const&			GetUrl() const											{ return url_; } | ||||
| 
 | ||||
| 			inline void						SetType(Type type)										{ type_ = type; } | ||||
| 
 | ||||
| 			inline Type						GetType() const											{ return type_; } | ||||
| 
 | ||||
| 			inline void						SetData(String const& data)								{ data_ = data; } | ||||
| 			// 请求类型
 | ||||
| 			void SetType(Type type); | ||||
| 			Type GetType() const; | ||||
| 
 | ||||
| 			// 请求数据
 | ||||
| 			void SetData(String const& data); | ||||
| 			void SetJsonData(Json const& json); | ||||
| 			String const& GetData() const; | ||||
| 
 | ||||
| 			inline String const&			GetData() const											{ return data_; } | ||||
| 
 | ||||
| 			inline void						SetHeaders(Map<String, String> const& headers)			{ headers_ = headers; } | ||||
| 
 | ||||
| 			// 请求头
 | ||||
| 			void SetHeaders(Map<String, String> const& headers); | ||||
| 			void SetHeader(String const& field, String const& content); | ||||
| 			Map<String, String>& GetHeaders(); | ||||
| 			String const& GetHeader(String const& header) const; | ||||
| 
 | ||||
| 			inline Map<String, String>&		GetHeaders()											{ return headers_; } | ||||
| 
 | ||||
| 			inline String const&			GetHeader(String const& header) const					{ return headers_.at(header); } | ||||
| 
 | ||||
| 			inline void						SetResponseCallback(ResponseCallback const& callback)	{ response_cb_ = callback; } | ||||
| 
 | ||||
| 			inline ResponseCallback const&	GetResponseCallback() const								{ return response_cb_; } | ||||
| 			// 响应回调
 | ||||
| 			void SetResponseCallback(ResponseCallback const& callback); | ||||
| 			ResponseCallback const& GetResponseCallback() const; | ||||
| 
 | ||||
| 		protected: | ||||
| 			Type type_; | ||||
|  | @ -84,5 +81,33 @@ namespace kiwano | |||
| 			Map<String, String> headers_; | ||||
| 			ResponseCallback response_cb_; | ||||
| 		}; | ||||
| 
 | ||||
| 		inline HttpRequest::HttpRequest()														: type_(Type::Unknown) {} | ||||
| 
 | ||||
| 		inline HttpRequest::HttpRequest(Type type)												: type_(type) {} | ||||
| 
 | ||||
| 		inline void HttpRequest::SetUrl(String const& url)										{ url_ = url; } | ||||
| 
 | ||||
| 		inline String const& HttpRequest::GetUrl() const										{ return url_; } | ||||
| 
 | ||||
| 		inline void HttpRequest::SetType(Type type)												{ type_ = type; } | ||||
| 
 | ||||
| 		inline HttpRequest::Type HttpRequest::GetType() const									{ return type_; } | ||||
| 
 | ||||
| 		inline void HttpRequest::SetData(String const& data)									{ data_ = data; } | ||||
| 
 | ||||
| 		inline String const& HttpRequest::GetData() const										{ return data_; } | ||||
| 
 | ||||
| 		inline void HttpRequest::SetHeaders(Map<String, String> const& headers)					{ headers_ = headers; } | ||||
| 
 | ||||
| 		inline void HttpRequest::SetHeader(String const& field, String const& content)			{ headers_[field] = content; } | ||||
| 
 | ||||
| 		inline Map<String, String>& HttpRequest::GetHeaders()									{ return headers_; } | ||||
| 
 | ||||
| 		inline String const& HttpRequest::GetHeader(String const& header) const					{ return headers_.at(header); } | ||||
| 
 | ||||
| 		inline void HttpRequest::SetResponseCallback(ResponseCallback const& callback)			{ response_cb_ = callback; } | ||||
| 
 | ||||
| 		inline HttpRequest::ResponseCallback const&	HttpRequest::GetResponseCallback() const	{ return response_cb_; } | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -31,29 +31,30 @@ namespace kiwano | |||
| 			: public ObjectBase | ||||
| 		{ | ||||
| 		public: | ||||
| 			inline HttpResponse(HttpRequestPtr request)							: request_(request), succeed_(false), response_code_(0) {} | ||||
| 			HttpResponse(HttpRequestPtr request); | ||||
| 
 | ||||
| 			inline HttpRequestPtr	GetRequest() const							{ return request_; } | ||||
| 			// 获取请求
 | ||||
| 			HttpRequestPtr GetRequest() const; | ||||
| 
 | ||||
| 			inline void				SetSucceed(bool succeed)					{ succeed_ = succeed; } | ||||
| 			// 响应状态
 | ||||
| 			bool IsSucceed() const; | ||||
| 			void SetSucceed(bool succeed); | ||||
| 
 | ||||
| 			inline bool				IsSucceed() const							{ return succeed_; } | ||||
| 			// 响应状态码
 | ||||
| 			long GetResponseCode() const; | ||||
| 			void SetResponseCode(long response_code); | ||||
| 
 | ||||
| 			inline void				SetResponseCode(long response_code)			{ response_code_ = response_code; } | ||||
| 			// 响应头
 | ||||
| 			String GetHeader() const; | ||||
| 			void SetHeader(String const& response_header); | ||||
| 
 | ||||
| 			inline long				GetResponseCode() const						{ return response_code_; } | ||||
| 			// 响应数据
 | ||||
| 			String const& GetData() const; | ||||
| 			void SetData(String const& response_data); | ||||
| 
 | ||||
| 			inline void				SetHeader(String const& response_header)	{ response_header_ = response_header; } | ||||
| 
 | ||||
| 			inline String			GetHeader() const							{ return response_header_; } | ||||
| 
 | ||||
| 			inline void				SetData(String const& response_data)		{ response_data_ = response_data; } | ||||
| 
 | ||||
| 			inline String const&	GetData() const								{ return response_data_; } | ||||
| 
 | ||||
| 			inline void				SetError(String const& error_buffer)		{ error_buffer_ = error_buffer; } | ||||
| 
 | ||||
| 			inline String const&	GetError() const							{ return error_buffer_; } | ||||
| 			// 错误信息
 | ||||
| 			String const& GetError() const; | ||||
| 			void SetError(String const& error_buffer); | ||||
| 
 | ||||
| 		protected: | ||||
| 			bool succeed_; | ||||
|  | @ -64,5 +65,29 @@ namespace kiwano | |||
| 			String response_data_; | ||||
| 			String error_buffer_; | ||||
| 		}; | ||||
| 
 | ||||
| 		inline HttpResponse::HttpResponse(HttpRequestPtr request)						: request_(request), succeed_(false), response_code_(0) {} | ||||
| 
 | ||||
| 		inline HttpRequestPtr	HttpResponse::GetRequest() const						{ return request_; } | ||||
| 
 | ||||
| 		inline void				HttpResponse::SetSucceed(bool succeed)					{ succeed_ = succeed; } | ||||
| 
 | ||||
| 		inline bool				HttpResponse::IsSucceed() const							{ return succeed_; } | ||||
| 
 | ||||
| 		inline void				HttpResponse::SetResponseCode(long response_code)		{ response_code_ = response_code; } | ||||
| 
 | ||||
| 		inline long				HttpResponse::GetResponseCode() const					{ return response_code_; } | ||||
| 
 | ||||
| 		inline void				HttpResponse::SetHeader(String const& response_header)	{ response_header_ = response_header; } | ||||
| 
 | ||||
| 		inline String			HttpResponse::GetHeader() const							{ return response_header_; } | ||||
| 
 | ||||
| 		inline void				HttpResponse::SetData(String const& response_data)		{ response_data_ = response_data; } | ||||
| 
 | ||||
| 		inline String const&	HttpResponse::GetData() const							{ return response_data_; } | ||||
| 
 | ||||
| 		inline void				HttpResponse::SetError(String const& error_buffer)		{ error_buffer_ = error_buffer; } | ||||
| 
 | ||||
| 		inline String const&	HttpResponse::GetError() const							{ return error_buffer_; } | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -26,7 +26,7 @@ namespace kiwano | |||
| 	namespace physics | ||||
| 	{ | ||||
| 
 | ||||
| 		PhysicBody::PhysicBody() | ||||
| 		Body::Body() | ||||
| 			: body_(nullptr) | ||||
| 			, actor_(nullptr) | ||||
| 			, world_(nullptr) | ||||
|  | @ -36,25 +36,25 @@ namespace kiwano | |||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicBody::PhysicBody(b2Body* body, Actor* actor) | ||||
| 			: PhysicBody() | ||||
| 		Body::Body(b2Body* body, Actor* actor) | ||||
| 			: Body() | ||||
| 		{ | ||||
| 			SetB2Body(body); | ||||
| 			SetActor(actor); | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicBody::PhysicBody(PhysicWorld* world, Actor* actor) | ||||
| 			: PhysicBody() | ||||
| 		Body::Body(World* world, Actor* actor) | ||||
| 			: Body() | ||||
| 		{ | ||||
| 			Init(world, actor); | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicBody::~PhysicBody() | ||||
| 		Body::~Body() | ||||
| 		{ | ||||
| 			Destroy(); | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicBody::Init(PhysicWorld* world, Actor* actor) | ||||
| 		void Body::Init(World* world, Actor* actor) | ||||
| 		{ | ||||
| 			KGE_ASSERT(world); | ||||
| 
 | ||||
|  | @ -69,38 +69,38 @@ namespace kiwano | |||
| 			UpdateFromActor(); | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicFixture PhysicBody::AddFixture(PhysicShape* shape, const PhysicFixture::Param& param) | ||||
| 		Fixture Body::AddFixture(Shape* shape, const Fixture::Param& param) | ||||
| 		{ | ||||
| 			KGE_ASSERT(body_ && world_); | ||||
| 			return PhysicFixture(this, shape, param); | ||||
| 			return Fixture(this, shape, param); | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicFixture PhysicBody::AddCircleShape(float radius, float density) | ||||
| 		Fixture Body::AddCircleShape(float radius, float density) | ||||
| 		{ | ||||
| 			return AddFixture(&PhysicCircleShape(radius), PhysicFixture::Param(density)); | ||||
| 			return AddFixture(&CircleShape(radius), Fixture::Param(density)); | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicFixture PhysicBody::AddBoxShape(Vec2 const& size, float density) | ||||
| 		Fixture Body::AddBoxShape(Vec2 const& size, float density) | ||||
| 		{ | ||||
| 			return AddFixture(&PhysicBoxShape(size), PhysicFixture::Param(density)); | ||||
| 			return AddFixture(&BoxShape(size), Fixture::Param(density)); | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicFixture PhysicBody::AddPolygonShape(Vector<Point> const& vertexs, float density) | ||||
| 		Fixture Body::AddPolygonShape(Vector<Point> const& vertexs, float density) | ||||
| 		{ | ||||
| 			return AddFixture(&PhysicPolygonShape(vertexs), PhysicFixture::Param(density)); | ||||
| 			return AddFixture(&PolygonShape(vertexs), Fixture::Param(density)); | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicFixture PhysicBody::AddEdgeShape(Point const& p1, Point const& p2, float density) | ||||
| 		Fixture Body::AddEdgeShape(Point const& p1, Point const& p2, float density) | ||||
| 		{ | ||||
| 			return AddFixture(&PhysicEdgeShape(p1, p2), PhysicFixture::Param(density)); | ||||
| 			return AddFixture(&EdgeShape(p1, p2), Fixture::Param(density)); | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicFixture PhysicBody::AddChainShape(Vector<Point> const& vertexs, bool loop, float density) | ||||
| 		Fixture Body::AddChainShape(Vector<Point> const& vertexs, bool loop, float density) | ||||
| 		{ | ||||
| 			return AddFixture(&PhysicChainShape(vertexs, loop), PhysicFixture::Param(density)); | ||||
| 			return AddFixture(&ChainShape(vertexs, loop), Fixture::Param(density)); | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicBody::RemoveFixture(PhysicFixture const& fixture) | ||||
| 		void Body::RemoveFixture(Fixture const& fixture) | ||||
| 		{ | ||||
| 			if (fixture.GetB2Fixture()) | ||||
| 			{ | ||||
|  | @ -109,7 +109,7 @@ namespace kiwano | |||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicBody::SetCategoryBits(uint16_t category_bits) | ||||
| 		void Body::SetCategoryBits(uint16_t category_bits) | ||||
| 		{ | ||||
| 			KGE_ASSERT(body_); | ||||
| 
 | ||||
|  | @ -126,7 +126,7 @@ namespace kiwano | |||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicBody::SetMaskBits(uint16_t mask_bits) | ||||
| 		void Body::SetMaskBits(uint16_t mask_bits) | ||||
| 		{ | ||||
| 			KGE_ASSERT(body_); | ||||
| 
 | ||||
|  | @ -143,7 +143,7 @@ namespace kiwano | |||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicBody::SetGroupIndex(int16_t index) | ||||
| 		void Body::SetGroupIndex(int16_t index) | ||||
| 		{ | ||||
| 			KGE_ASSERT(body_); | ||||
| 
 | ||||
|  | @ -160,7 +160,7 @@ namespace kiwano | |||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicBody::GetMassData(float* mass, Point* center, float* inertia) const | ||||
| 		void Body::GetMassData(float* mass, Point* center, float* inertia) const | ||||
| 		{ | ||||
| 			KGE_ASSERT(body_ && world_); | ||||
| 
 | ||||
|  | @ -172,7 +172,7 @@ namespace kiwano | |||
| 			if (inertia) *inertia = data.I; | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicBody::SetMassData(float mass, Point const& center, float inertia) | ||||
| 		void Body::SetMassData(float mass, Point const& center, float inertia) | ||||
| 		{ | ||||
| 			KGE_ASSERT(body_ && world_); | ||||
| 
 | ||||
|  | @ -183,67 +183,67 @@ namespace kiwano | |||
| 			body_->SetMassData(&data); | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicBody::ResetMassData() | ||||
| 		void Body::ResetMassData() | ||||
| 		{ | ||||
| 			KGE_ASSERT(body_); | ||||
| 			body_->ResetMassData(); | ||||
| 		} | ||||
| 
 | ||||
| 		Point PhysicBody::GetBodyPosition() const | ||||
| 		Point Body::GetBodyPosition() const | ||||
| 		{ | ||||
| 			KGE_ASSERT(body_ && world_); | ||||
| 			return world_->World2Stage(body_->GetPosition()); | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicBody::SetBodyTransform(Point const& pos, float angle) | ||||
| 		void Body::SetBodyTransform(Point const& pos, float angle) | ||||
| 		{ | ||||
| 			KGE_ASSERT(body_ && world_); | ||||
| 			body_->SetTransform(world_->Stage2World(pos), math::Degree2Radian(angle)); | ||||
| 		} | ||||
| 
 | ||||
| 		Point PhysicBody::GetLocalPoint(Point const& world) const | ||||
| 		Point Body::GetLocalPoint(Point const& world) const | ||||
| 		{ | ||||
| 			KGE_ASSERT(body_ && world_); | ||||
| 			return world_->World2Stage(body_->GetLocalPoint(world_->Stage2World(world))); | ||||
| 		} | ||||
| 
 | ||||
| 		Point PhysicBody::GetWorldPoint(Point const& local) const | ||||
| 		Point Body::GetWorldPoint(Point const& local) const | ||||
| 		{ | ||||
| 			KGE_ASSERT(body_ && world_); | ||||
| 			return world_->World2Stage(body_->GetWorldPoint(world_->Stage2World(local))); | ||||
| 		} | ||||
| 
 | ||||
| 		Point PhysicBody::GetLocalCenter() const | ||||
| 		Point Body::GetLocalCenter() const | ||||
| 		{ | ||||
| 			KGE_ASSERT(body_ && world_); | ||||
| 			return world_->World2Stage(body_->GetLocalCenter()); | ||||
| 		} | ||||
| 
 | ||||
| 		Point PhysicBody::GetWorldCenter() const | ||||
| 		Point Body::GetWorldCenter() const | ||||
| 		{ | ||||
| 			KGE_ASSERT(body_ && world_); | ||||
| 			return world_->World2Stage(body_->GetWorldCenter()); | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicBody::ApplyForce(Vec2 const& force, Point const& point, bool wake) | ||||
| 		void Body::ApplyForce(Vec2 const& force, Point const& point, bool wake) | ||||
| 		{ | ||||
| 			KGE_ASSERT(body_ && world_); | ||||
| 			body_->ApplyForce(b2Vec2(force.x, force.y), world_->Stage2World(point), wake); | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicBody::ApplyForceToCenter(Vec2 const& force, bool wake) | ||||
| 		void Body::ApplyForceToCenter(Vec2 const& force, bool wake) | ||||
| 		{ | ||||
| 			KGE_ASSERT(body_ && world_); | ||||
| 			body_->ApplyForceToCenter(b2Vec2(force.x, force.y), wake); | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicBody::ApplyTorque(float torque, bool wake) | ||||
| 		void Body::ApplyTorque(float torque, bool wake) | ||||
| 		{ | ||||
| 			KGE_ASSERT(body_ && world_); | ||||
| 			body_->ApplyTorque(torque, wake); | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicBody::SetB2Body(b2Body* body) | ||||
| 		void Body::SetB2Body(b2Body* body) | ||||
| 		{ | ||||
| 			body_ = body; | ||||
| 			if (body_) | ||||
|  | @ -252,7 +252,7 @@ namespace kiwano | |||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicBody::Destroy() | ||||
| 		void Body::Destroy() | ||||
| 		{ | ||||
| 			if (world_) | ||||
| 			{ | ||||
|  | @ -264,7 +264,7 @@ namespace kiwano | |||
| 			actor_ = nullptr; | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicBody::UpdateActor() | ||||
| 		void Body::UpdateActor() | ||||
| 		{ | ||||
| 			if (actor_ && body_) | ||||
| 			{ | ||||
|  | @ -280,7 +280,7 @@ namespace kiwano | |||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicBody::UpdateFromActor() | ||||
| 		void Body::UpdateFromActor() | ||||
| 		{ | ||||
| 			if (actor_ && body_) | ||||
| 			{ | ||||
|  | @ -301,7 +301,7 @@ namespace kiwano | |||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicBody::UpdateFixtureFilter(b2Fixture* fixture) | ||||
| 		void Body::UpdateFixtureFilter(b2Fixture* fixture) | ||||
| 		{ | ||||
| 			b2Filter filter; | ||||
| 			filter.categoryBits = category_bits_; | ||||
|  |  | |||
|  | @ -28,11 +28,11 @@ namespace kiwano | |||
| { | ||||
| 	namespace physics | ||||
| 	{ | ||||
| 		class PhysicWorld; | ||||
| 		class World; | ||||
| 
 | ||||
| 		// 膠竟
 | ||||
| 		KGE_DECLARE_SMART_PTR(PhysicBody); | ||||
| 		class KGE_API PhysicBody | ||||
| 		KGE_DECLARE_SMART_PTR(Body); | ||||
| 		class KGE_API Body | ||||
| 			: public virtual RefCounter | ||||
| 		{ | ||||
| 		public: | ||||
|  | @ -43,33 +43,33 @@ namespace kiwano | |||
| 				Dynamic, | ||||
| 			}; | ||||
| 
 | ||||
| 			PhysicBody(); | ||||
| 			PhysicBody(b2Body* body, Actor* actor); | ||||
| 			PhysicBody(PhysicWorld* world, Actor* actor); | ||||
| 			PhysicBody(PhysicWorld* world, ActorPtr actor) : PhysicBody(world, actor.get()) {} | ||||
| 			virtual ~PhysicBody(); | ||||
| 			Body(); | ||||
| 			Body(b2Body* body, Actor* actor); | ||||
| 			Body(World* world, Actor* actor); | ||||
| 			Body(World* world, ActorPtr actor) : Body(world, actor.get()) {} | ||||
| 			virtual ~Body(); | ||||
| 
 | ||||
| 			// 놓迦뺏
 | ||||
| 			void Init(PhysicWorld* world, Actor* actor); | ||||
| 			void Init(World* world, Actor* actor); | ||||
| 
 | ||||
| 			// 警속셸야
 | ||||
| 			PhysicFixture AddFixture(PhysicShape* shape, const PhysicFixture::Param& param); | ||||
| 			Fixture AddFixture(Shape* shape, const Fixture::Param& param); | ||||
| 
 | ||||
| 			// 警속近榴
 | ||||
| 			PhysicFixture AddCircleShape(float radius, float density = 0.f); | ||||
| 			PhysicFixture AddBoxShape(Vec2 const& size, float density = 0.f); | ||||
| 			PhysicFixture AddPolygonShape(Vector<Point> const& vertexs, float density = 0.f); | ||||
| 			PhysicFixture AddEdgeShape(Point const& p1, Point const& p2, float density = 0.f); | ||||
| 			PhysicFixture AddChainShape(Vector<Point> const& vertexs, bool loop, float density = 0.f); | ||||
| 			Fixture AddCircleShape(float radius, float density = 0.f); | ||||
| 			Fixture AddBoxShape(Vec2 const& size, float density = 0.f); | ||||
| 			Fixture AddPolygonShape(Vector<Point> const& vertexs, float density = 0.f); | ||||
| 			Fixture AddEdgeShape(Point const& p1, Point const& p2, float density = 0.f); | ||||
| 			Fixture AddChainShape(Vector<Point> const& vertexs, bool loop, float density = 0.f); | ||||
| 
 | ||||
| 			// 삿혤셸야
 | ||||
| 			PhysicFixture GetFixtureList() const			{ KGE_ASSERT(body_); return PhysicFixture(body_->GetFixtureList()); } | ||||
| 			Fixture GetFixtureList() const			{ KGE_ASSERT(body_); return Fixture(body_->GetFixtureList()); } | ||||
| 
 | ||||
| 			// 盧뇜셸야
 | ||||
| 			void RemoveFixture(PhysicFixture const& fixture); | ||||
| 			void RemoveFixture(Fixture const& fixture); | ||||
| 
 | ||||
| 			// 삿혤쌈뇰긋
 | ||||
| 			PhysicContactEdge GetContactList() const		{ KGE_ASSERT(body_); PhysicContactEdge(body_->GetContactList()); } | ||||
| 			ContactEdge GetContactList() const		{ KGE_ASSERT(body_); ContactEdge(body_->GetContactList()); } | ||||
| 
 | ||||
| 			// 잚깎쯤
 | ||||
| 			uint16_t GetCategoryBits() const				{ return category_bits_; } | ||||
|  | @ -153,8 +153,8 @@ namespace kiwano | |||
| 			const b2Body* GetB2Body() const					{ return body_; } | ||||
| 			void SetB2Body(b2Body* body); | ||||
| 
 | ||||
| 			PhysicWorld* GetWorld()							{ return world_; } | ||||
| 			const PhysicWorld* GetWorld() const				{ return world_; } | ||||
| 			World* GetWorld()							{ return world_; } | ||||
| 			const World* GetWorld() const				{ return world_; } | ||||
| 
 | ||||
| 			void Destroy(); | ||||
| 
 | ||||
|  | @ -166,7 +166,7 @@ namespace kiwano | |||
| 
 | ||||
| 		protected: | ||||
| 			Actor* actor_; | ||||
| 			PhysicWorld* world_; | ||||
| 			World* world_; | ||||
| 			b2Body* body_; | ||||
| 
 | ||||
| 			uint16_t category_bits_; | ||||
|  |  | |||
|  | @ -27,87 +27,87 @@ namespace kiwano | |||
| 	namespace physics | ||||
| 	{ | ||||
| 
 | ||||
| 		PhysicContact::PhysicContact() | ||||
| 		Contact::Contact() | ||||
| 			: contact_(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicContact::PhysicContact(b2Contact* contact) | ||||
| 			: PhysicContact() | ||||
| 		Contact::Contact(b2Contact* contact) | ||||
| 			: Contact() | ||||
| 		{ | ||||
| 			SetB2Contact(contact); | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicContact PhysicContact::GetNext() | ||||
| 		Contact Contact::GetNext() | ||||
| 		{ | ||||
| 			KGE_ASSERT(contact_); | ||||
| 			return PhysicContact(contact_->GetNext()); | ||||
| 			return Contact(contact_->GetNext()); | ||||
| 		} | ||||
| 
 | ||||
| 		const PhysicContact PhysicContact::GetNext() const | ||||
| 		const Contact Contact::GetNext() const | ||||
| 		{ | ||||
| 			KGE_ASSERT(contact_); | ||||
| 			return PhysicContact(contact_->GetNext()); | ||||
| 			return Contact(contact_->GetNext()); | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicFixture PhysicContact::GetFixtureA() | ||||
| 		Fixture Contact::GetFixtureA() | ||||
| 		{ | ||||
| 			KGE_ASSERT(contact_); | ||||
| 			return PhysicFixture(contact_->GetFixtureA()); | ||||
| 			return Fixture(contact_->GetFixtureA()); | ||||
| 		} | ||||
| 
 | ||||
| 		const PhysicFixture PhysicContact::GetFixtureA() const | ||||
| 		const Fixture Contact::GetFixtureA() const | ||||
| 		{ | ||||
| 			KGE_ASSERT(contact_); | ||||
| 			return PhysicFixture(contact_->GetFixtureA()); | ||||
| 			return Fixture(contact_->GetFixtureA()); | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicFixture PhysicContact::GetFixtureB() | ||||
| 		Fixture Contact::GetFixtureB() | ||||
| 		{ | ||||
| 			KGE_ASSERT(contact_); | ||||
| 			return PhysicFixture(contact_->GetFixtureB()); | ||||
| 			return Fixture(contact_->GetFixtureB()); | ||||
| 		} | ||||
| 
 | ||||
| 		const PhysicFixture PhysicContact::GetFixtureB() const | ||||
| 		const Fixture Contact::GetFixtureB() const | ||||
| 		{ | ||||
| 			KGE_ASSERT(contact_); | ||||
| 			return PhysicFixture(contact_->GetFixtureB()); | ||||
| 			return Fixture(contact_->GetFixtureB()); | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicContact::SetTangentSpeed(float speed) | ||||
| 		void Contact::SetTangentSpeed(float speed) | ||||
| 		{ | ||||
| 			KGE_ASSERT(contact_); | ||||
| 
 | ||||
| 			PhysicBody* body = GetFixtureA().GetBody(); | ||||
| 			Body* body = GetFixtureA().GetBody(); | ||||
| 			KGE_ASSERT(body); | ||||
| 
 | ||||
| 			PhysicWorld* world = body->GetWorld(); | ||||
| 			World* world = body->GetWorld(); | ||||
| 			KGE_ASSERT(world); | ||||
| 
 | ||||
| 			contact_->SetTangentSpeed(world->Stage2World(speed)); | ||||
| 		} | ||||
| 
 | ||||
| 		float PhysicContact::GetTangentSpeed() const | ||||
| 		float Contact::GetTangentSpeed() const | ||||
| 		{ | ||||
| 			KGE_ASSERT(contact_); | ||||
| 
 | ||||
| 			const PhysicBody* body = GetFixtureA().GetBody(); | ||||
| 			const Body* body = GetFixtureA().GetBody(); | ||||
| 			KGE_ASSERT(body); | ||||
| 
 | ||||
| 			const PhysicWorld* world = body->GetWorld(); | ||||
| 			const World* world = body->GetWorld(); | ||||
| 			KGE_ASSERT(world); | ||||
| 
 | ||||
| 			return world->World2Stage(contact_->GetTangentSpeed()); | ||||
| 		} | ||||
| 
 | ||||
| 
 | ||||
| 		PhysicContactEdge::PhysicContactEdge() | ||||
| 		ContactEdge::ContactEdge() | ||||
| 			: edge_(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicContactEdge::PhysicContactEdge(b2ContactEdge* edge) | ||||
| 			: PhysicContactEdge() | ||||
| 		ContactEdge::ContactEdge(b2ContactEdge* edge) | ||||
| 			: ContactEdge() | ||||
| 		{ | ||||
| 			SetB2ContactEdge(edge); | ||||
| 		} | ||||
|  |  | |||
|  | @ -26,14 +26,14 @@ namespace kiwano | |||
| { | ||||
| 	namespace physics | ||||
| 	{ | ||||
| 		class PhysicBody; | ||||
| 		class Body; | ||||
| 
 | ||||
| 		// 接触
 | ||||
| 		class KGE_API PhysicContact | ||||
| 		class KGE_API Contact | ||||
| 		{ | ||||
| 		public: | ||||
| 			PhysicContact(); | ||||
| 			PhysicContact(b2Contact* contact); | ||||
| 			Contact(); | ||||
| 			Contact(b2Contact* contact); | ||||
| 			 | ||||
| 			// 是否是接触
 | ||||
| 			bool IsTouching() const						{ KGE_ASSERT(contact_); return contact_->IsTouching(); } | ||||
|  | @ -43,16 +43,16 @@ namespace kiwano | |||
| 			bool IsEnabled() const						{ KGE_ASSERT(contact_); return contact_->IsEnabled(); } | ||||
| 
 | ||||
| 			// 获取下一接触
 | ||||
| 			PhysicContact GetNext(); | ||||
| 			const PhysicContact GetNext() const; | ||||
| 			Contact GetNext(); | ||||
| 			const Contact GetNext() const; | ||||
| 
 | ||||
| 			// 夹具 A
 | ||||
| 			PhysicFixture GetFixtureA(); | ||||
| 			const PhysicFixture GetFixtureA() const; | ||||
| 			Fixture GetFixtureA(); | ||||
| 			const Fixture GetFixtureA() const; | ||||
| 
 | ||||
| 			// 夹具 B
 | ||||
| 			PhysicFixture GetFixtureB(); | ||||
| 			const PhysicFixture GetFixtureB() const; | ||||
| 			Fixture GetFixtureB(); | ||||
| 			const Fixture GetFixtureB() const; | ||||
| 
 | ||||
| 			// 摩擦
 | ||||
| 			void SetFriction(float friction)			{ KGE_ASSERT(contact_); contact_->SetFriction(friction); } | ||||
|  | @ -78,27 +78,27 @@ namespace kiwano | |||
| 
 | ||||
| 
 | ||||
| 		// 接触边
 | ||||
| 		class KGE_API PhysicContactEdge | ||||
| 		class KGE_API ContactEdge | ||||
| 		{ | ||||
| 		public: | ||||
| 			PhysicContactEdge(); | ||||
| 			PhysicContactEdge(b2ContactEdge* edge); | ||||
| 			ContactEdge(); | ||||
| 			ContactEdge(b2ContactEdge* edge); | ||||
| 
 | ||||
| 			// 获取接触物体
 | ||||
| 			PhysicBody* GetOtherBody()						{ KGE_ASSERT(edge_); return static_cast<PhysicBody*>(edge_->other->GetUserData()); } | ||||
| 			const PhysicBody* GetOtherBody() const			{ KGE_ASSERT(edge_); return static_cast<PhysicBody*>(edge_->other->GetUserData()); } | ||||
| 			Body* GetOtherBody()						{ KGE_ASSERT(edge_); return static_cast<Body*>(edge_->other->GetUserData()); } | ||||
| 			const Body* GetOtherBody() const			{ KGE_ASSERT(edge_); return static_cast<Body*>(edge_->other->GetUserData()); } | ||||
| 
 | ||||
| 			// 获取接触
 | ||||
| 			PhysicContact GetContact()						{ KGE_ASSERT(edge_); return PhysicContact(edge_->contact); } | ||||
| 			const PhysicContact GetContact() const			{ KGE_ASSERT(edge_); return PhysicContact(edge_->contact); } | ||||
| 			Contact GetContact()						{ KGE_ASSERT(edge_); return Contact(edge_->contact); } | ||||
| 			const Contact GetContact() const			{ KGE_ASSERT(edge_); return Contact(edge_->contact); } | ||||
| 
 | ||||
| 			// 获取上一接触边
 | ||||
| 			PhysicContactEdge GetPrev()						{ KGE_ASSERT(edge_); return PhysicContactEdge(edge_->prev); } | ||||
| 			const PhysicContactEdge GetPrev() const			{ KGE_ASSERT(edge_); return PhysicContactEdge(edge_->prev); } | ||||
| 			ContactEdge GetPrev()						{ KGE_ASSERT(edge_); return ContactEdge(edge_->prev); } | ||||
| 			const ContactEdge GetPrev() const			{ KGE_ASSERT(edge_); return ContactEdge(edge_->prev); } | ||||
| 
 | ||||
| 			// 获取下一接触边
 | ||||
| 			PhysicContactEdge GetNext()						{ KGE_ASSERT(edge_); return PhysicContactEdge(edge_->next); } | ||||
| 			const PhysicContactEdge GetNext() const			{ KGE_ASSERT(edge_); return PhysicContactEdge(edge_->next); } | ||||
| 			ContactEdge GetNext()						{ KGE_ASSERT(edge_); return ContactEdge(edge_->next); } | ||||
| 			const ContactEdge GetNext() const			{ KGE_ASSERT(edge_); return ContactEdge(edge_->next); } | ||||
| 
 | ||||
| 			b2ContactEdge* GetB2ContactEdge()				{ return edge_; } | ||||
| 			const b2ContactEdge* GetB2ContactEdge() const	{ return edge_; } | ||||
|  |  | |||
|  | @ -0,0 +1,65 @@ | |||
| // Copyright (c) 2018-2019 Kiwano - Nomango
 | ||||
| // 
 | ||||
| // Permission is hereby granted, free of charge, to any person obtaining a copy
 | ||||
| // of this software and associated documentation files (the "Software"), to deal
 | ||||
| // in the Software without restriction, including without limitation the rights
 | ||||
| // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | ||||
| // copies of the Software, and to permit persons to whom the Software is
 | ||||
| // furnished to do so, subject to the following conditions:
 | ||||
| // 
 | ||||
| // The above copyright notice and this permission notice shall be included in
 | ||||
| // all copies or substantial portions of the Software.
 | ||||
| // 
 | ||||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | ||||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | ||||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | ||||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | ||||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | ||||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | ||||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #include <kiwano-physics/ContactEvent.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
| 	namespace event | ||||
| 	{ | ||||
| 		EventType event::ContactBegin = EventType(L"ContactBegin"); | ||||
| 		EventType event::ContactEnd		= EventType(L"ContactEnd"); | ||||
| 	} | ||||
| 
 | ||||
| 	namespace physics | ||||
| 	{ | ||||
| 
 | ||||
| 		ContactBeginEvent::ContactBeginEvent() | ||||
| 			: Event(event::ContactBegin) | ||||
| 			, body_a(nullptr) | ||||
| 			, body_b(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		ContactBeginEvent::ContactBeginEvent(Contact const& contact) | ||||
| 			: ContactBeginEvent() | ||||
| 		{ | ||||
| 			this->contact = contact; | ||||
| 			body_a = this->contact.GetFixtureA().GetBody(); | ||||
| 			body_b = this->contact.GetFixtureB().GetBody(); | ||||
| 		} | ||||
| 
 | ||||
| 		ContactEndEvent::ContactEndEvent() | ||||
| 			: Event(event::ContactEnd) | ||||
| 			, body_a(nullptr) | ||||
| 			, body_b(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		ContactEndEvent::ContactEndEvent(Contact const& contact) | ||||
| 			: ContactEndEvent() | ||||
| 		{ | ||||
| 			this->contact = contact; | ||||
| 			body_a = this->contact.GetFixtureA().GetBody(); | ||||
| 			body_b = this->contact.GetFixtureB().GetBody(); | ||||
| 		} | ||||
| 
 | ||||
| } | ||||
| } | ||||
|  | @ -0,0 +1,62 @@ | |||
| // Copyright (c) 2018-2019 Kiwano - Nomango
 | ||||
| // 
 | ||||
| // Permission is hereby granted, free of charge, to any person obtaining a copy
 | ||||
| // of this software and associated documentation files (the "Software"), to deal
 | ||||
| // in the Software without restriction, including without limitation the rights
 | ||||
| // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | ||||
| // copies of the Software, and to permit persons to whom the Software is
 | ||||
| // furnished to do so, subject to the following conditions:
 | ||||
| // 
 | ||||
| // The above copyright notice and this permission notice shall be included in
 | ||||
| // all copies or substantial portions of the Software.
 | ||||
| // 
 | ||||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | ||||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | ||||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | ||||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | ||||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | ||||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | ||||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #pragma once | ||||
| #include <kiwano-physics/Contact.h> | ||||
| #include <kiwano-physics/Body.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
| 	namespace physics | ||||
| 	{ | ||||
| 		// 接触开始事件
 | ||||
| 		class KGE_API ContactBeginEvent | ||||
| 			: public Event | ||||
| 		{ | ||||
| 		public: | ||||
| 			Contact contact; | ||||
| 			Body* body_a; | ||||
| 			Body* body_b; | ||||
| 
 | ||||
| 			ContactBeginEvent(); | ||||
| 			ContactBeginEvent(Contact const& contact); | ||||
| 		}; | ||||
| 
 | ||||
| 		// 接触结束事件
 | ||||
| 		class KGE_API ContactEndEvent | ||||
| 			: public Event | ||||
| 		{ | ||||
| 		public: | ||||
| 			Contact contact; | ||||
| 			Body* body_a; | ||||
| 			Body* body_b; | ||||
| 
 | ||||
| 			ContactEndEvent(); | ||||
| 			ContactEndEvent(Contact const& contact); | ||||
| 		}; | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	namespace event | ||||
| 	{ | ||||
| 		extern EventType ContactBegin;	// 接触开始
 | ||||
| 		extern EventType ContactEnd;	// 接触结束
 | ||||
| 	} | ||||
| } | ||||
|  | @ -1,158 +0,0 @@ | |||
| // Copyright (c) 2018-2019 Kiwano - Nomango
 | ||||
| // 
 | ||||
| // Permission is hereby granted, free of charge, to any person obtaining a copy
 | ||||
| // of this software and associated documentation files (the "Software"), to deal
 | ||||
| // in the Software without restriction, including without limitation the rights
 | ||||
| // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | ||||
| // copies of the Software, and to permit persons to whom the Software is
 | ||||
| // furnished to do so, subject to the following conditions:
 | ||||
| // 
 | ||||
| // The above copyright notice and this permission notice shall be included in
 | ||||
| // all copies or substantial portions of the Software.
 | ||||
| // 
 | ||||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | ||||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | ||||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | ||||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | ||||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | ||||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | ||||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #include <kiwano-physics/ContactListener.h> | ||||
| #include <kiwano-physics/Body.h> | ||||
| #include <kiwano-physics/World.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
| 	namespace physics | ||||
| 	{ | ||||
| 		PhysicContactListener::PhysicContactListener() | ||||
| 			: running_(true) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicContactListener::~PhysicContactListener() | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 
 | ||||
| 		PhysicContactCallbackListener::PhysicContactCallbackListener() | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicContactCallbackListener::~PhysicContactCallbackListener() | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 
 | ||||
| 		PhysicContactListener* PhysicContactDispatcher::AddContactListener(PhysicContactListenerPtr listener) | ||||
| 		{ | ||||
| 			return AddContactListener(listener.get()); | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicContactListener* PhysicContactDispatcher::AddContactListener(PhysicContactListener* listener) | ||||
| 		{ | ||||
| 			KGE_ASSERT(listener && "AddListener failed, NULL pointer exception"); | ||||
| 
 | ||||
| 			if (listener) | ||||
| 			{ | ||||
| 				listeners_.push_back(listener); | ||||
| 			} | ||||
| 			return listener; | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicContactDispatcher::StartContactListeners(String const& listener_name) | ||||
| 		{ | ||||
| 			for (auto listener : listeners_) | ||||
| 			{ | ||||
| 				if (listener->IsName(listener_name)) | ||||
| 				{ | ||||
| 					listener->Start(); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicContactDispatcher::StopContactListeners(String const& listener_name) | ||||
| 		{ | ||||
| 			for (auto listener : listeners_) | ||||
| 			{ | ||||
| 				if (listener->IsName(listener_name)) | ||||
| 				{ | ||||
| 					listener->Stop(); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicContactDispatcher::RemoveContactListeners(String const& listener_name) | ||||
| 		{ | ||||
| 			PhysicContactListenerPtr next; | ||||
| 			for (auto listener = listeners_.first_item(); listener; listener = next) | ||||
| 			{ | ||||
| 				next = listener->next_item(); | ||||
| 
 | ||||
| 				if (listener->IsName(listener_name)) | ||||
| 				{ | ||||
| 					listeners_.remove(listener); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicContactDispatcher::StartAllContactListeners() | ||||
| 		{ | ||||
| 			for (auto listener : listeners_) | ||||
| 			{ | ||||
| 				listener->Start(); | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicContactDispatcher::StopAllContactListeners() | ||||
| 		{ | ||||
| 			for (auto listener : listeners_) | ||||
| 			{ | ||||
| 				listener->Stop(); | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicContactDispatcher::RemoveAllContactListeners() | ||||
| 		{ | ||||
| 			listeners_.clear(); | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicContactDispatcher::OnContactBegin(b2Contact* b2contact) | ||||
| 		{ | ||||
| 			if (listeners_.empty()) | ||||
| 				return; | ||||
| 
 | ||||
| 			PhysicContact contact(b2contact); | ||||
| 			PhysicContactListenerPtr next; | ||||
| 			for (auto listener = listeners_.first_item(); listener; listener = next) | ||||
| 			{ | ||||
| 				next = listener->next_item(); | ||||
| 
 | ||||
| 				if (listener->IsRunning()) | ||||
| 				{ | ||||
| 					listener->OnContactBegin(contact); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicContactDispatcher::OnContactEnd(b2Contact* b2contact) | ||||
| 		{ | ||||
| 			if (listeners_.empty()) | ||||
| 				return; | ||||
| 
 | ||||
| 			PhysicContact contact(b2contact); | ||||
| 			PhysicContactListenerPtr next; | ||||
| 			for (auto listener = listeners_.first_item(); listener; listener = next) | ||||
| 			{ | ||||
| 				next = listener->next_item(); | ||||
| 
 | ||||
| 				if (listener->IsRunning()) | ||||
| 				{ | ||||
| 					listener->OnContactEnd(contact); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 	} | ||||
| } | ||||
|  | @ -1,141 +0,0 @@ | |||
| // Copyright (c) 2018-2019 Kiwano - Nomango
 | ||||
| // 
 | ||||
| // Permission is hereby granted, free of charge, to any person obtaining a copy
 | ||||
| // of this software and associated documentation files (the "Software"), to deal
 | ||||
| // in the Software without restriction, including without limitation the rights
 | ||||
| // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | ||||
| // copies of the Software, and to permit persons to whom the Software is
 | ||||
| // furnished to do so, subject to the following conditions:
 | ||||
| // 
 | ||||
| // The above copyright notice and this permission notice shall be included in
 | ||||
| // all copies or substantial portions of the Software.
 | ||||
| // 
 | ||||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | ||||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | ||||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | ||||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | ||||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | ||||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | ||||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #pragma once | ||||
| #include <kiwano-physics/Contact.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
| 	namespace physics | ||||
| 	{ | ||||
| 		class PhysicContactDispatcher; | ||||
| 
 | ||||
| 		KGE_DECLARE_SMART_PTR(PhysicContactListener); | ||||
| 
 | ||||
| 		// 接触监听器
 | ||||
| 		class KGE_API PhysicContactListener | ||||
| 			: public ObjectBase | ||||
| 			, protected IntrusiveListItem<PhysicContactListenerPtr> | ||||
| 		{ | ||||
| 			friend IntrusiveList<PhysicContactListenerPtr>; | ||||
| 			friend class PhysicContactDispatcher; | ||||
| 
 | ||||
| 		public: | ||||
| 			PhysicContactListener(); | ||||
| 			virtual ~PhysicContactListener(); | ||||
| 
 | ||||
| 			// 接触开始
 | ||||
| 			virtual void OnContactBegin(PhysicContact contact)	{ KGE_NOT_USED(contact); } | ||||
| 
 | ||||
| 			// 接触结束
 | ||||
| 			virtual void OnContactEnd(PhysicContact contact)	{ KGE_NOT_USED(contact); } | ||||
| 
 | ||||
| 			inline void Start()									{ running_ = true; } | ||||
| 			inline void Stop()									{ running_ = true; } | ||||
| 			inline bool IsRunning() const						{ return running_; } | ||||
| 
 | ||||
| 		protected: | ||||
| 			bool running_; | ||||
| 		}; | ||||
| 
 | ||||
| 
 | ||||
| 		KGE_DECLARE_SMART_PTR(PhysicContactCallbackListener); | ||||
| 
 | ||||
| 		// 接触回调监听器
 | ||||
| 		class KGE_API PhysicContactCallbackListener | ||||
| 			: public PhysicContactListener | ||||
| 		{ | ||||
| 			friend IntrusiveList<PhysicContactListenerPtr>; | ||||
| 			friend class PhysicContactDispatcher; | ||||
| 
 | ||||
| 		public: | ||||
| 			using ContactBeginCallback	= Function<void(PhysicContact)>; | ||||
| 			using ContactEndCallback	= Function<void(PhysicContact)>; | ||||
| 
 | ||||
| 			PhysicContactCallbackListener(); | ||||
| 			virtual ~PhysicContactCallbackListener(); | ||||
| 
 | ||||
| 			// 接触开始回调
 | ||||
| 			void SetCallbackOnContactBegin(ContactBeginCallback const& cb)	{ begin_ = cb; } | ||||
| 			ContactBeginCallback GetCallbackOnContactBegin() const			{ return begin_; } | ||||
| 
 | ||||
| 			// 接触结束回调
 | ||||
| 			void SetCallbackOnContactEnd(ContactEndCallback const& cb)		{ end_ = cb; } | ||||
| 			ContactEndCallback GetCallbackOnContactEnd() const				{ return end_; } | ||||
| 
 | ||||
| 			void OnContactBegin(PhysicContact contact) override				{ if (begin_) begin_(contact); } | ||||
| 			void OnContactEnd(PhysicContact contact) override				{ if (end_) end_(contact); } | ||||
| 
 | ||||
| 		protected: | ||||
| 			ContactBeginCallback begin_; | ||||
| 			ContactEndCallback end_; | ||||
| 		}; | ||||
| 
 | ||||
| 
 | ||||
| 		// 接触分发器
 | ||||
| 		class KGE_API PhysicContactDispatcher | ||||
| 		{ | ||||
| 		public: | ||||
| 			using Listeners = IntrusiveList<PhysicContactListenerPtr>; | ||||
| 
 | ||||
| 			// 添加监听器
 | ||||
| 			PhysicContactListener* AddContactListener( | ||||
| 				PhysicContactListenerPtr listener | ||||
| 			); | ||||
| 
 | ||||
| 			// 添加监听器
 | ||||
| 			PhysicContactListener* AddContactListener( | ||||
| 				PhysicContactListener* listener | ||||
| 			); | ||||
| 
 | ||||
| 			// 启动监听器
 | ||||
| 			void StartContactListeners( | ||||
| 				String const& listener_name | ||||
| 			); | ||||
| 
 | ||||
| 			// 停止监听器
 | ||||
| 			void StopContactListeners( | ||||
| 				String const& listener_name | ||||
| 			); | ||||
| 
 | ||||
| 			// 移除监听器
 | ||||
| 			void RemoveContactListeners( | ||||
| 				String const& listener_name | ||||
| 			); | ||||
| 
 | ||||
| 			// 启动所有监听器
 | ||||
| 			void StartAllContactListeners(); | ||||
| 
 | ||||
| 			// 停止所有监听器
 | ||||
| 			void StopAllContactListeners(); | ||||
| 
 | ||||
| 			// 移除所有监听器
 | ||||
| 			void RemoveAllContactListeners(); | ||||
| 
 | ||||
| 		protected: | ||||
| 			void OnContactBegin(b2Contact* contact); | ||||
| 
 | ||||
| 			void OnContactEnd(b2Contact* contact); | ||||
| 
 | ||||
| 		private: | ||||
| 			Listeners listeners_; | ||||
| 		}; | ||||
| 	} | ||||
| } | ||||
|  | @ -27,19 +27,19 @@ namespace kiwano | |||
| 	namespace physics | ||||
| 	{ | ||||
| 
 | ||||
| 		PhysicFixture::PhysicFixture() | ||||
| 		Fixture::Fixture() | ||||
| 			: fixture_(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicFixture::PhysicFixture(b2Fixture* fixture) | ||||
| 			: PhysicFixture() | ||||
| 		Fixture::Fixture(b2Fixture* fixture) | ||||
| 			: Fixture() | ||||
| 		{ | ||||
| 			SetB2Fixture(fixture); | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicFixture::PhysicFixture(PhysicBody* body, PhysicShape* shape, const Param& param) | ||||
| 			: PhysicFixture() | ||||
| 		Fixture::Fixture(Body* body, Shape* shape, const Param& param) | ||||
| 			: Fixture() | ||||
| 		{ | ||||
| 			KGE_ASSERT(body); | ||||
| 
 | ||||
|  | @ -58,38 +58,38 @@ namespace kiwano | |||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicBody* PhysicFixture::GetBody() | ||||
| 		Body* Fixture::GetBody() | ||||
| 		{ | ||||
| 			KGE_ASSERT(fixture_); | ||||
| 			return static_cast<PhysicBody*>(fixture_->GetBody()->GetUserData()); | ||||
| 			return static_cast<Body*>(fixture_->GetBody()->GetUserData()); | ||||
| 		} | ||||
| 
 | ||||
| 		const PhysicBody* PhysicFixture::GetBody() const | ||||
| 		const Body* Fixture::GetBody() const | ||||
| 		{ | ||||
| 			KGE_ASSERT(fixture_); | ||||
| 			return static_cast<const PhysicBody*>(fixture_->GetBody()->GetUserData()); | ||||
| 			return static_cast<const Body*>(fixture_->GetBody()->GetUserData()); | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicShape PhysicFixture::GetShape() const | ||||
| 		Shape Fixture::GetShape() const | ||||
| 		{ | ||||
| 			KGE_ASSERT(fixture_); | ||||
| 			return PhysicShape(fixture_->GetShape()); | ||||
| 			return Shape(fixture_->GetShape()); | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicFixture PhysicFixture::GetNext() const | ||||
| 		Fixture Fixture::GetNext() const | ||||
| 		{ | ||||
| 			KGE_ASSERT(fixture_); | ||||
| 			return PhysicFixture(fixture_->GetNext()); | ||||
| 			return Fixture(fixture_->GetNext()); | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicFixture::GetMassData(float* mass, Point* center, float* inertia) const | ||||
| 		void Fixture::GetMassData(float* mass, Point* center, float* inertia) const | ||||
| 		{ | ||||
| 			KGE_ASSERT(fixture_); | ||||
| 
 | ||||
| 			const PhysicBody* body = GetBody(); | ||||
| 			const Body* body = GetBody(); | ||||
| 			KGE_ASSERT(body); | ||||
| 
 | ||||
| 			const PhysicWorld* world = body->GetWorld(); | ||||
| 			const World* world = body->GetWorld(); | ||||
| 			KGE_ASSERT(world); | ||||
| 
 | ||||
| 			b2MassData data; | ||||
|  | @ -100,14 +100,14 @@ namespace kiwano | |||
| 			if (inertia) *inertia = data.I; | ||||
| 		} | ||||
| 
 | ||||
| 		bool PhysicFixture::TestPoint(const Point& p) const | ||||
| 		bool Fixture::TestPoint(const Point& p) const | ||||
| 		{ | ||||
| 			KGE_ASSERT(fixture_); | ||||
| 
 | ||||
| 			const PhysicBody* body = GetBody(); | ||||
| 			const Body* body = GetBody(); | ||||
| 			KGE_ASSERT(body); | ||||
| 
 | ||||
| 			const PhysicWorld* world = body->GetWorld(); | ||||
| 			const World* world = body->GetWorld(); | ||||
| 			KGE_ASSERT(world); | ||||
| 
 | ||||
| 			return fixture_->TestPoint(world->Stage2World(p)); | ||||
|  |  | |||
|  | @ -26,10 +26,10 @@ namespace kiwano | |||
| { | ||||
| 	namespace physics | ||||
| 	{ | ||||
| 		class PhysicBody; | ||||
| 		class Body; | ||||
| 
 | ||||
| 		// 夹具
 | ||||
| 		class PhysicFixture | ||||
| 		class Fixture | ||||
| 		{ | ||||
| 		public: | ||||
| 			struct Param | ||||
|  | @ -49,19 +49,19 @@ namespace kiwano | |||
| 				{} | ||||
| 			}; | ||||
| 
 | ||||
| 			PhysicFixture(); | ||||
| 			PhysicFixture(b2Fixture* fixture); | ||||
| 			PhysicFixture(PhysicBody* body, PhysicShape* shape, const Param& param); | ||||
| 			Fixture(); | ||||
| 			Fixture(b2Fixture* fixture); | ||||
| 			Fixture(Body* body, Shape* shape, const Param& param); | ||||
| 
 | ||||
| 			// 物体
 | ||||
| 			PhysicBody* GetBody(); | ||||
| 			const PhysicBody* GetBody() const; | ||||
| 			Body* GetBody(); | ||||
| 			const Body* GetBody() const; | ||||
| 
 | ||||
| 			// 形状
 | ||||
| 			PhysicShape GetShape() const; | ||||
| 			Shape GetShape() const; | ||||
| 
 | ||||
| 			// 下一夹具 (同一物体上)
 | ||||
| 			PhysicFixture GetNext() const; | ||||
| 			Fixture GetNext() const; | ||||
| 
 | ||||
| 			// 接触传感器
 | ||||
| 			bool IsSensor() const					{ KGE_ASSERT(fixture_); return fixture_->IsSensor(); } | ||||
|  |  | |||
|  | @ -26,29 +26,29 @@ namespace kiwano | |||
| 	namespace physics | ||||
| 	{ | ||||
| 		//
 | ||||
| 		// PhysicJoint
 | ||||
| 		// Joint
 | ||||
| 		//
 | ||||
| 
 | ||||
| 		PhysicJoint::PhysicJoint() | ||||
| 		Joint::Joint() | ||||
| 			: joint_(nullptr) | ||||
| 			, world_(nullptr) | ||||
| 			, type_(Type::Unknown) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicJoint::PhysicJoint(b2Joint* joint) | ||||
| 			: PhysicJoint() | ||||
| 		Joint::Joint(b2Joint* joint) | ||||
| 			: Joint() | ||||
| 		{ | ||||
| 			SetB2Joint(joint); | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicJoint::PhysicJoint(PhysicWorld* world, b2JointDef* joint_def) | ||||
| 			: PhysicJoint() | ||||
| 		Joint::Joint(World* world, b2JointDef* joint_def) | ||||
| 			: Joint() | ||||
| 		{ | ||||
| 			Init(world, joint_def); | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicJoint::~PhysicJoint() | ||||
| 		Joint::~Joint() | ||||
| 		{ | ||||
| 			if (world_) | ||||
| 			{ | ||||
|  | @ -56,7 +56,7 @@ namespace kiwano | |||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicJoint::Init(PhysicWorld* world, b2JointDef* joint_def) | ||||
| 		void Joint::Init(World* world, b2JointDef* joint_def) | ||||
| 		{ | ||||
| 			world_ = world; | ||||
| 			if (world_) | ||||
|  | @ -68,28 +68,28 @@ namespace kiwano | |||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicBodyPtr PhysicJoint::GetBodyA() const | ||||
| 		BodyPtr Joint::GetBodyA() const | ||||
| 		{ | ||||
| 			KGE_ASSERT(joint_); | ||||
| 
 | ||||
| 			b2Body* body = joint_->GetBodyA(); | ||||
| 			return PhysicBodyPtr(static_cast<PhysicBody*>(body->GetUserData())); | ||||
| 			return BodyPtr(static_cast<Body*>(body->GetUserData())); | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicBodyPtr PhysicJoint::GetBodyB() const | ||||
| 		BodyPtr Joint::GetBodyB() const | ||||
| 		{ | ||||
| 			KGE_ASSERT(joint_); | ||||
| 
 | ||||
| 			b2Body* body = joint_->GetBodyB(); | ||||
| 			return PhysicBodyPtr(static_cast<PhysicBody*>(body->GetUserData())); | ||||
| 			return BodyPtr(static_cast<Body*>(body->GetUserData())); | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicJoint::SetB2Joint(b2Joint* joint) | ||||
| 		void Joint::SetB2Joint(b2Joint* joint) | ||||
| 		{ | ||||
| 			joint_ = joint; | ||||
| 			if (joint_) | ||||
| 			{ | ||||
| 				type_ = PhysicJoint::Type(joint_->GetType()); | ||||
| 				type_ = Joint::Type(joint_->GetType()); | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
|  | @ -98,19 +98,19 @@ namespace kiwano | |||
| 		//
 | ||||
| 
 | ||||
| 		DistanceJoint::DistanceJoint() | ||||
| 			: PhysicJoint() | ||||
| 			: Joint() | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		DistanceJoint::DistanceJoint(PhysicWorld* world, b2DistanceJointDef* def) | ||||
| 			: PhysicJoint(world, def) | ||||
| 		DistanceJoint::DistanceJoint(World* world, b2DistanceJointDef* def) | ||||
| 			: Joint(world, def) | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		DistanceJoint::DistanceJoint(PhysicWorld* world, DistanceJoint::Param const& param) | ||||
| 			: PhysicJoint() | ||||
| 		DistanceJoint::DistanceJoint(World* world, DistanceJoint::Param const& param) | ||||
| 			: Joint() | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 			KGE_ASSERT(param.body_a && param.body_b); | ||||
|  | @ -141,19 +141,19 @@ namespace kiwano | |||
| 		//
 | ||||
| 
 | ||||
| 		FrictionJoint::FrictionJoint() | ||||
| 			: PhysicJoint() | ||||
| 			: Joint() | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		FrictionJoint::FrictionJoint(PhysicWorld* world, b2FrictionJointDef* def) | ||||
| 			: PhysicJoint(world, def) | ||||
| 		FrictionJoint::FrictionJoint(World* world, b2FrictionJointDef* def) | ||||
| 			: Joint(world, def) | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		FrictionJoint::FrictionJoint(PhysicWorld* world, FrictionJoint::Param const& param) | ||||
| 			: PhysicJoint() | ||||
| 		FrictionJoint::FrictionJoint(World* world, FrictionJoint::Param const& param) | ||||
| 			: Joint() | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 			KGE_ASSERT(param.body_a && param.body_b); | ||||
|  | @ -196,19 +196,19 @@ namespace kiwano | |||
| 		//
 | ||||
| 
 | ||||
| 		GearJoint::GearJoint() | ||||
| 			: PhysicJoint() | ||||
| 			: Joint() | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		GearJoint::GearJoint(PhysicWorld* world, b2GearJointDef* def) | ||||
| 			: PhysicJoint(world, def) | ||||
| 		GearJoint::GearJoint(World* world, b2GearJointDef* def) | ||||
| 			: Joint(world, def) | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		GearJoint::GearJoint(PhysicWorld* world, GearJoint::Param const& param) | ||||
| 			: PhysicJoint() | ||||
| 		GearJoint::GearJoint(World* world, GearJoint::Param const& param) | ||||
| 			: Joint() | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 			KGE_ASSERT(param.joint_a && param.joint_b); | ||||
|  | @ -239,19 +239,19 @@ namespace kiwano | |||
| 		//
 | ||||
| 
 | ||||
| 		MotorJoint::MotorJoint() | ||||
| 			: PhysicJoint() | ||||
| 			: Joint() | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		MotorJoint::MotorJoint(PhysicWorld* world, b2MotorJointDef* def) | ||||
| 			: PhysicJoint(world, def) | ||||
| 		MotorJoint::MotorJoint(World* world, b2MotorJointDef* def) | ||||
| 			: Joint(world, def) | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		MotorJoint::MotorJoint(PhysicWorld* world, MotorJoint::Param const& param) | ||||
| 			: PhysicJoint() | ||||
| 		MotorJoint::MotorJoint(World* world, MotorJoint::Param const& param) | ||||
| 			: Joint() | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 			KGE_ASSERT(param.body_a && param.body_b); | ||||
|  | @ -294,19 +294,19 @@ namespace kiwano | |||
| 		//
 | ||||
| 
 | ||||
| 		PrismaticJoint::PrismaticJoint() | ||||
| 			: PhysicJoint() | ||||
| 			: Joint() | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		PrismaticJoint::PrismaticJoint(PhysicWorld* world, b2PrismaticJointDef* def) | ||||
| 			: PhysicJoint(world, def) | ||||
| 		PrismaticJoint::PrismaticJoint(World* world, b2PrismaticJointDef* def) | ||||
| 			: Joint(world, def) | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		PrismaticJoint::PrismaticJoint(PhysicWorld* world, PrismaticJoint::Param const& param) | ||||
| 			: PhysicJoint() | ||||
| 		PrismaticJoint::PrismaticJoint(World* world, PrismaticJoint::Param const& param) | ||||
| 			: Joint() | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 			KGE_ASSERT(param.body_a && param.body_b); | ||||
|  | @ -359,19 +359,19 @@ namespace kiwano | |||
| 		//
 | ||||
| 
 | ||||
| 		PulleyJoint::PulleyJoint() | ||||
| 			: PhysicJoint() | ||||
| 			: Joint() | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		PulleyJoint::PulleyJoint(PhysicWorld* world, b2PulleyJointDef* def) | ||||
| 			: PhysicJoint(world, def) | ||||
| 		PulleyJoint::PulleyJoint(World* world, b2PulleyJointDef* def) | ||||
| 			: Joint(world, def) | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		PulleyJoint::PulleyJoint(PhysicWorld* world, PulleyJoint::Param const& param) | ||||
| 			: PhysicJoint() | ||||
| 		PulleyJoint::PulleyJoint(World* world, PulleyJoint::Param const& param) | ||||
| 			: Joint() | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 			KGE_ASSERT(param.body_a && param.body_b); | ||||
|  | @ -431,19 +431,19 @@ namespace kiwano | |||
| 		//
 | ||||
| 
 | ||||
| 		RevoluteJoint::RevoluteJoint() | ||||
| 			: PhysicJoint() | ||||
| 			: Joint() | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		RevoluteJoint::RevoluteJoint(PhysicWorld* world, b2RevoluteJointDef* def) | ||||
| 			: PhysicJoint(world, def) | ||||
| 		RevoluteJoint::RevoluteJoint(World* world, b2RevoluteJointDef* def) | ||||
| 			: Joint(world, def) | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		RevoluteJoint::RevoluteJoint(PhysicWorld* world, RevoluteJoint::Param const& param) | ||||
| 			: PhysicJoint() | ||||
| 		RevoluteJoint::RevoluteJoint(World* world, RevoluteJoint::Param const& param) | ||||
| 			: Joint() | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 			KGE_ASSERT(param.body_a && param.body_b); | ||||
|  | @ -508,19 +508,19 @@ namespace kiwano | |||
| 		//
 | ||||
| 
 | ||||
| 		RopeJoint::RopeJoint() | ||||
| 			: PhysicJoint() | ||||
| 			: Joint() | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		RopeJoint::RopeJoint(PhysicWorld* world, b2RopeJointDef* def) | ||||
| 			: PhysicJoint(world, def) | ||||
| 		RopeJoint::RopeJoint(World* world, b2RopeJointDef* def) | ||||
| 			: Joint(world, def) | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		RopeJoint::RopeJoint(PhysicWorld* world, RopeJoint::Param const& param) | ||||
| 			: PhysicJoint() | ||||
| 		RopeJoint::RopeJoint(World* world, RopeJoint::Param const& param) | ||||
| 			: Joint() | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 			KGE_ASSERT(param.body_a && param.body_b); | ||||
|  | @ -553,19 +553,19 @@ namespace kiwano | |||
| 		//
 | ||||
| 
 | ||||
| 		WeldJoint::WeldJoint() | ||||
| 			: PhysicJoint() | ||||
| 			: Joint() | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		WeldJoint::WeldJoint(PhysicWorld* world, b2WeldJointDef* def) | ||||
| 			: PhysicJoint(world, def) | ||||
| 		WeldJoint::WeldJoint(World* world, b2WeldJointDef* def) | ||||
| 			: Joint(world, def) | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		WeldJoint::WeldJoint(PhysicWorld* world, WeldJoint::Param const& param) | ||||
| 			: PhysicJoint() | ||||
| 		WeldJoint::WeldJoint(World* world, WeldJoint::Param const& param) | ||||
| 			: Joint() | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 			KGE_ASSERT(param.body_a && param.body_b); | ||||
|  | @ -584,19 +584,19 @@ namespace kiwano | |||
| 		//
 | ||||
| 
 | ||||
| 		WheelJoint::WheelJoint() | ||||
| 			: PhysicJoint() | ||||
| 			: Joint() | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		WheelJoint::WheelJoint(PhysicWorld* world, b2WheelJointDef* def) | ||||
| 			: PhysicJoint(world, def) | ||||
| 		WheelJoint::WheelJoint(World* world, b2WheelJointDef* def) | ||||
| 			: Joint(world, def) | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		WheelJoint::WheelJoint(PhysicWorld* world, WheelJoint::Param const& param) | ||||
| 			: PhysicJoint() | ||||
| 		WheelJoint::WheelJoint(World* world, WheelJoint::Param const& param) | ||||
| 			: Joint() | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 			KGE_ASSERT(param.body_a && param.body_b); | ||||
|  | @ -642,19 +642,19 @@ namespace kiwano | |||
| 		//
 | ||||
| 
 | ||||
| 		MouseJoint::MouseJoint() | ||||
| 			: PhysicJoint() | ||||
| 			: Joint() | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		MouseJoint::MouseJoint(PhysicWorld* world, b2MouseJointDef* def) | ||||
| 			: PhysicJoint(world, def) | ||||
| 		MouseJoint::MouseJoint(World* world, b2MouseJointDef* def) | ||||
| 			: Joint(world, def) | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		MouseJoint::MouseJoint(PhysicWorld* world, MouseJoint::Param const& param) | ||||
| 			: PhysicJoint() | ||||
| 		MouseJoint::MouseJoint(World* world, MouseJoint::Param const& param) | ||||
| 			: Joint() | ||||
| 			, raw_joint_(nullptr) | ||||
| 		{ | ||||
| 			KGE_ASSERT(param.body_a && param.body_b); | ||||
|  |  | |||
|  | @ -26,7 +26,7 @@ namespace kiwano | |||
| { | ||||
| 	namespace physics | ||||
| 	{ | ||||
| 		KGE_DECLARE_SMART_PTR(PhysicJoint); | ||||
| 		KGE_DECLARE_SMART_PTR(Joint); | ||||
| 		KGE_DECLARE_SMART_PTR(DistanceJoint); | ||||
| 		KGE_DECLARE_SMART_PTR(FrictionJoint); | ||||
| 		KGE_DECLARE_SMART_PTR(GearJoint); | ||||
|  | @ -40,7 +40,7 @@ namespace kiwano | |||
| 		KGE_DECLARE_SMART_PTR(WheelJoint); | ||||
| 
 | ||||
| 		// 关节
 | ||||
| 		class KGE_API PhysicJoint | ||||
| 		class KGE_API Joint | ||||
| 			: public virtual RefCounter | ||||
| 		{ | ||||
| 		public: | ||||
|  | @ -62,43 +62,43 @@ namespace kiwano | |||
| 
 | ||||
| 			struct ParamBase | ||||
| 			{ | ||||
| 				PhysicBody* body_a; | ||||
| 				PhysicBody* body_b; | ||||
| 				Body* body_a; | ||||
| 				Body* body_b; | ||||
| 
 | ||||
| 				ParamBase(PhysicBody* body_a, PhysicBody* body_b) : body_a(body_a), body_b(body_b) {} | ||||
| 				ParamBase(PhysicBodyPtr body_a, PhysicBodyPtr body_b) : body_a(body_a.get()), body_b(body_b.get()) {} | ||||
| 				ParamBase(Body* body_a, Body* body_b) : body_a(body_a), body_b(body_b) {} | ||||
| 				ParamBase(BodyPtr body_a, BodyPtr body_b) : body_a(body_a.get()), body_b(body_b.get()) {} | ||||
| 			}; | ||||
| 
 | ||||
| 			PhysicJoint(); | ||||
| 			PhysicJoint(b2Joint* joint); | ||||
| 			PhysicJoint(PhysicWorld* world, b2JointDef* joint_def); | ||||
| 			virtual ~PhysicJoint(); | ||||
| 			Joint(); | ||||
| 			Joint(b2Joint* joint); | ||||
| 			Joint(World* world, b2JointDef* joint_def); | ||||
| 			virtual ~Joint(); | ||||
| 
 | ||||
| 			void Init(PhysicWorld* world, b2JointDef* joint_def); | ||||
| 			void Init(World* world, b2JointDef* joint_def); | ||||
| 
 | ||||
| 			PhysicBodyPtr GetBodyA() const; | ||||
| 			PhysicBodyPtr GetBodyB() const; | ||||
| 			BodyPtr GetBodyA() const; | ||||
| 			BodyPtr GetBodyB() const; | ||||
| 
 | ||||
| 			b2Joint* GetB2Joint()				{ return joint_; } | ||||
| 			const b2Joint* GetB2Joint() const	{ return joint_; } | ||||
| 			void SetB2Joint(b2Joint* joint); | ||||
| 
 | ||||
| 			PhysicWorld* GetWorld()					{ return world_; } | ||||
| 			const PhysicWorld* GetWorld() const		{ return world_; } | ||||
| 			World* GetWorld()					{ return world_; } | ||||
| 			const World* GetWorld() const		{ return world_; } | ||||
| 
 | ||||
| 		protected: | ||||
| 			b2Joint* joint_; | ||||
| 			PhysicWorld* world_; | ||||
| 			World* world_; | ||||
| 			Type type_; | ||||
| 		}; | ||||
| 
 | ||||
| 
 | ||||
| 		// 固定距离关节
 | ||||
| 		class KGE_API DistanceJoint | ||||
| 			: public PhysicJoint | ||||
| 			: public Joint | ||||
| 		{ | ||||
| 		public: | ||||
| 			struct Param : public PhysicJoint::ParamBase | ||||
| 			struct Param : public Joint::ParamBase | ||||
| 			{ | ||||
| 				Point anchor_a; | ||||
| 				Point anchor_b; | ||||
|  | @ -106,8 +106,8 @@ namespace kiwano | |||
| 				float damping_ratio; | ||||
| 
 | ||||
| 				Param( | ||||
| 					PhysicBody* body_a, | ||||
| 					PhysicBody* body_b, | ||||
| 					Body* body_a, | ||||
| 					Body* body_b, | ||||
| 					Point const& anchor_a, | ||||
| 					Point const& anchor_b, | ||||
| 					float frequency_hz = 0.f, | ||||
|  | @ -121,8 +121,8 @@ namespace kiwano | |||
| 				{} | ||||
| 
 | ||||
| 				Param( | ||||
| 					PhysicBodyPtr body_a, | ||||
| 					PhysicBodyPtr body_b, | ||||
| 					BodyPtr body_a, | ||||
| 					BodyPtr body_b, | ||||
| 					Point const& anchor_a, | ||||
| 					Point const& anchor_b, | ||||
| 					float frequency_hz = 0.f, | ||||
|  | @ -133,8 +133,8 @@ namespace kiwano | |||
| 			}; | ||||
| 
 | ||||
| 			DistanceJoint(); | ||||
| 			DistanceJoint(PhysicWorld* world, b2DistanceJointDef* def); | ||||
| 			DistanceJoint(PhysicWorld* world, Param const& param); | ||||
| 			DistanceJoint(World* world, b2DistanceJointDef* def); | ||||
| 			DistanceJoint(World* world, Param const& param); | ||||
| 
 | ||||
| 			void SetLength(float length); | ||||
| 			float GetLength() const; | ||||
|  | @ -154,18 +154,18 @@ namespace kiwano | |||
| 
 | ||||
| 		// 摩擦关节
 | ||||
| 		class KGE_API FrictionJoint | ||||
| 			: public PhysicJoint | ||||
| 			: public Joint | ||||
| 		{ | ||||
| 		public: | ||||
| 			struct Param : public PhysicJoint::ParamBase | ||||
| 			struct Param : public Joint::ParamBase | ||||
| 			{ | ||||
| 				Point anchor; | ||||
| 				float max_force; | ||||
| 				float max_torque; | ||||
| 
 | ||||
| 				Param( | ||||
| 					PhysicBody* body_a, | ||||
| 					PhysicBody* body_b, | ||||
| 					Body* body_a, | ||||
| 					Body* body_b, | ||||
| 					Point const& anchor, | ||||
| 					float max_force = 0.f, | ||||
| 					float max_torque = 0.f | ||||
|  | @ -177,8 +177,8 @@ namespace kiwano | |||
| 				{} | ||||
| 
 | ||||
| 				Param( | ||||
| 					PhysicBodyPtr body_a, | ||||
| 					PhysicBodyPtr body_b, | ||||
| 					BodyPtr body_a, | ||||
| 					BodyPtr body_b, | ||||
| 					Point const& anchor, | ||||
| 					float max_force = 0.f, | ||||
| 					float max_torque = 0.f | ||||
|  | @ -188,8 +188,8 @@ namespace kiwano | |||
| 			}; | ||||
| 
 | ||||
| 			FrictionJoint(); | ||||
| 			FrictionJoint(PhysicWorld* world, b2FrictionJointDef* def); | ||||
| 			FrictionJoint(PhysicWorld* world, Param const& param); | ||||
| 			FrictionJoint(World* world, b2FrictionJointDef* def); | ||||
| 			FrictionJoint(World* world, Param const& param); | ||||
| 
 | ||||
| 			// 设定最大摩擦力
 | ||||
| 			void SetMaxForce(float force); | ||||
|  | @ -206,18 +206,18 @@ namespace kiwano | |||
| 
 | ||||
| 		// 齿轮关节
 | ||||
| 		class KGE_API GearJoint | ||||
| 			: public PhysicJoint | ||||
| 			: public Joint | ||||
| 		{ | ||||
| 		public: | ||||
| 			struct Param : public PhysicJoint::ParamBase | ||||
| 			struct Param : public Joint::ParamBase | ||||
| 			{ | ||||
| 				PhysicJointPtr joint_a; | ||||
| 				PhysicJointPtr joint_b; | ||||
| 				JointPtr joint_a; | ||||
| 				JointPtr joint_b; | ||||
| 				float ratio; | ||||
| 
 | ||||
| 				Param( | ||||
| 					PhysicJoint* joint_a, | ||||
| 					PhysicJoint* joint_b, | ||||
| 					Joint* joint_a, | ||||
| 					Joint* joint_b, | ||||
| 					float ratio = 1.f | ||||
| 				) | ||||
| 					: ParamBase(nullptr, nullptr) | ||||
|  | @ -227,8 +227,8 @@ namespace kiwano | |||
| 				{} | ||||
| 
 | ||||
| 				Param( | ||||
| 					PhysicJointPtr joint_a, | ||||
| 					PhysicJointPtr joint_b, | ||||
| 					JointPtr joint_a, | ||||
| 					JointPtr joint_b, | ||||
| 					float ratio = 1.f | ||||
| 				) | ||||
| 					: Param(joint_a.get(), joint_b.get(), ratio) | ||||
|  | @ -236,8 +236,8 @@ namespace kiwano | |||
| 			}; | ||||
| 
 | ||||
| 			GearJoint(); | ||||
| 			GearJoint(PhysicWorld* world, b2GearJointDef* def); | ||||
| 			GearJoint(PhysicWorld* world, Param const& param); | ||||
| 			GearJoint(World* world, b2GearJointDef* def); | ||||
| 			GearJoint(World* world, Param const& param); | ||||
| 
 | ||||
| 			// 设定齿轮传动比
 | ||||
| 			void SetRatio(float ratio); | ||||
|  | @ -250,18 +250,18 @@ namespace kiwano | |||
| 
 | ||||
| 		// 马达关节
 | ||||
| 		class KGE_API MotorJoint | ||||
| 			: public PhysicJoint | ||||
| 			: public Joint | ||||
| 		{ | ||||
| 		public: | ||||
| 			struct Param : public PhysicJoint::ParamBase | ||||
| 			struct Param : public Joint::ParamBase | ||||
| 			{ | ||||
| 				float max_force; | ||||
| 				float max_torque; | ||||
| 				float correction_factor; | ||||
| 
 | ||||
| 				Param( | ||||
| 					PhysicBody* body_a, | ||||
| 					PhysicBody* body_b, | ||||
| 					Body* body_a, | ||||
| 					Body* body_b, | ||||
| 					float max_force = 1.f, | ||||
| 					float max_torque = 100.f, | ||||
| 					float correction_factor = 0.3f | ||||
|  | @ -273,8 +273,8 @@ namespace kiwano | |||
| 				{} | ||||
| 
 | ||||
| 				Param( | ||||
| 					PhysicBodyPtr body_a, | ||||
| 					PhysicBodyPtr body_b, | ||||
| 					BodyPtr body_a, | ||||
| 					BodyPtr body_b, | ||||
| 					float max_force = 0.f, | ||||
| 					float max_torque = 0.f, | ||||
| 					float correction_factor = 0.3f | ||||
|  | @ -284,8 +284,8 @@ namespace kiwano | |||
| 			}; | ||||
| 
 | ||||
| 			MotorJoint(); | ||||
| 			MotorJoint(PhysicWorld* world, b2MotorJointDef* def); | ||||
| 			MotorJoint(PhysicWorld* world, Param const& param); | ||||
| 			MotorJoint(World* world, b2MotorJointDef* def); | ||||
| 			MotorJoint(World* world, Param const& param); | ||||
| 
 | ||||
| 			// 设定最大摩擦力
 | ||||
| 			void SetMaxForce(float force); | ||||
|  | @ -302,10 +302,10 @@ namespace kiwano | |||
| 
 | ||||
| 		// 平移关节
 | ||||
| 		class KGE_API PrismaticJoint | ||||
| 			: public PhysicJoint | ||||
| 			: public Joint | ||||
| 		{ | ||||
| 		public: | ||||
| 			struct Param : public PhysicJoint::ParamBase | ||||
| 			struct Param : public Joint::ParamBase | ||||
| 			{ | ||||
| 				Point anchor; | ||||
| 				Vec2 axis; | ||||
|  | @ -317,8 +317,8 @@ namespace kiwano | |||
| 				float motor_speed; | ||||
| 
 | ||||
| 				Param( | ||||
| 					PhysicBody* body_a, | ||||
| 					PhysicBody* body_b, | ||||
| 					Body* body_a, | ||||
| 					Body* body_b, | ||||
| 					Point const& anchor, | ||||
| 					Vec2 const& axis, | ||||
| 					bool enable_limit = false, | ||||
|  | @ -340,8 +340,8 @@ namespace kiwano | |||
| 				{} | ||||
| 
 | ||||
| 				Param( | ||||
| 					PhysicBodyPtr body_a, | ||||
| 					PhysicBodyPtr body_b, | ||||
| 					BodyPtr body_a, | ||||
| 					BodyPtr body_b, | ||||
| 					Point const& anchor, | ||||
| 					Vec2 const& axis, | ||||
| 					bool enable_limit = false, | ||||
|  | @ -356,8 +356,8 @@ namespace kiwano | |||
| 			}; | ||||
| 
 | ||||
| 			PrismaticJoint(); | ||||
| 			PrismaticJoint(PhysicWorld* world, b2PrismaticJointDef* def); | ||||
| 			PrismaticJoint(PhysicWorld* world, Param const& param); | ||||
| 			PrismaticJoint(World* world, b2PrismaticJointDef* def); | ||||
| 			PrismaticJoint(World* world, Param const& param); | ||||
| 
 | ||||
| 			float GetReferenceAngle() const				{ KGE_ASSERT(raw_joint_); return math::Radian2Degree(raw_joint_->GetReferenceAngle()); } | ||||
| 			float GetJointTranslation() const; | ||||
|  | @ -388,10 +388,10 @@ namespace kiwano | |||
| 
 | ||||
| 		// 滑轮关节
 | ||||
| 		class KGE_API PulleyJoint | ||||
| 			: public PhysicJoint | ||||
| 			: public Joint | ||||
| 		{ | ||||
| 		public: | ||||
| 			struct Param : public PhysicJoint::ParamBase | ||||
| 			struct Param : public Joint::ParamBase | ||||
| 			{ | ||||
| 				Point anchor_a; | ||||
| 				Point anchor_b; | ||||
|  | @ -400,8 +400,8 @@ namespace kiwano | |||
| 				float ratio; | ||||
| 
 | ||||
| 				Param( | ||||
| 					PhysicBody* body_a, | ||||
| 					PhysicBody* body_b, | ||||
| 					Body* body_a, | ||||
| 					Body* body_b, | ||||
| 					Point const& anchor_a, | ||||
| 					Point const& anchor_b, | ||||
| 					Point const& ground_anchor_a, | ||||
|  | @ -417,8 +417,8 @@ namespace kiwano | |||
| 				{} | ||||
| 
 | ||||
| 				Param( | ||||
| 					PhysicBodyPtr body_a, | ||||
| 					PhysicBodyPtr body_b, | ||||
| 					BodyPtr body_a, | ||||
| 					BodyPtr body_b, | ||||
| 					Point const& anchor_a, | ||||
| 					Point const& anchor_b, | ||||
| 					Point const& ground_anchor_a, | ||||
|  | @ -430,8 +430,8 @@ namespace kiwano | |||
| 			}; | ||||
| 
 | ||||
| 			PulleyJoint(); | ||||
| 			PulleyJoint(PhysicWorld* world, b2PulleyJointDef* def); | ||||
| 			PulleyJoint(PhysicWorld* world, Param const& param); | ||||
| 			PulleyJoint(World* world, b2PulleyJointDef* def); | ||||
| 			PulleyJoint(World* world, Param const& param); | ||||
| 
 | ||||
| 			Point GetGroundAnchorA() const; | ||||
| 			Point GetGroundAnchorB() const; | ||||
|  | @ -451,10 +451,10 @@ namespace kiwano | |||
| 
 | ||||
| 		// 旋转关节
 | ||||
| 		class KGE_API RevoluteJoint | ||||
| 			: public PhysicJoint | ||||
| 			: public Joint | ||||
| 		{ | ||||
| 		public: | ||||
| 			struct Param : public PhysicJoint::ParamBase | ||||
| 			struct Param : public Joint::ParamBase | ||||
| 			{ | ||||
| 				Point anchor; | ||||
| 				bool enable_limit; | ||||
|  | @ -465,8 +465,8 @@ namespace kiwano | |||
| 				float motor_speed; | ||||
| 
 | ||||
| 				Param( | ||||
| 					PhysicBody* body_a, | ||||
| 					PhysicBody* body_b, | ||||
| 					Body* body_a, | ||||
| 					Body* body_b, | ||||
| 					Point const& anchor, | ||||
| 					bool enable_limit = false, | ||||
| 					float lower_angle = 0.0f, | ||||
|  | @ -486,8 +486,8 @@ namespace kiwano | |||
| 				{} | ||||
| 
 | ||||
| 				Param( | ||||
| 					PhysicBodyPtr body_a, | ||||
| 					PhysicBodyPtr body_b, | ||||
| 					BodyPtr body_a, | ||||
| 					BodyPtr body_b, | ||||
| 					Point const& anchor, | ||||
| 					bool enable_limit = false, | ||||
| 					float lower_angle = 0.0f, | ||||
|  | @ -501,8 +501,8 @@ namespace kiwano | |||
| 			}; | ||||
| 
 | ||||
| 			RevoluteJoint(); | ||||
| 			RevoluteJoint(PhysicWorld* world, b2RevoluteJointDef* def); | ||||
| 			RevoluteJoint(PhysicWorld* world, Param const& param); | ||||
| 			RevoluteJoint(World* world, b2RevoluteJointDef* def); | ||||
| 			RevoluteJoint(World* world, Param const& param); | ||||
| 
 | ||||
| 			float GetReferenceAngle() const				{ KGE_ASSERT(raw_joint_); return math::Radian2Degree(raw_joint_->GetReferenceAngle()); } | ||||
| 			float GetJointAngle() const; | ||||
|  | @ -533,18 +533,18 @@ namespace kiwano | |||
| 
 | ||||
| 		// 绳关节
 | ||||
| 		class KGE_API RopeJoint | ||||
| 			: public PhysicJoint | ||||
| 			: public Joint | ||||
| 		{ | ||||
| 		public: | ||||
| 			struct Param : public PhysicJoint::ParamBase | ||||
| 			struct Param : public Joint::ParamBase | ||||
| 			{ | ||||
| 				Point local_anchor_a; | ||||
| 				Point local_anchor_b; | ||||
| 				float max_length; | ||||
| 
 | ||||
| 				Param( | ||||
| 					PhysicBody* body_a, | ||||
| 					PhysicBody* body_b, | ||||
| 					Body* body_a, | ||||
| 					Body* body_b, | ||||
| 					Point const& local_anchor_a, | ||||
| 					Point const& local_anchor_b, | ||||
| 					float max_length = 0.f | ||||
|  | @ -556,8 +556,8 @@ namespace kiwano | |||
| 				{} | ||||
| 
 | ||||
| 				Param( | ||||
| 					PhysicBodyPtr body_a, | ||||
| 					PhysicBodyPtr body_b, | ||||
| 					BodyPtr body_a, | ||||
| 					BodyPtr body_b, | ||||
| 					Point const& local_anchor_a, | ||||
| 					Point const& local_anchor_b, | ||||
| 					float max_length = 0.f | ||||
|  | @ -567,8 +567,8 @@ namespace kiwano | |||
| 			}; | ||||
| 
 | ||||
| 			RopeJoint(); | ||||
| 			RopeJoint(PhysicWorld* world, b2RopeJointDef* def); | ||||
| 			RopeJoint(PhysicWorld* world, Param const& param); | ||||
| 			RopeJoint(World* world, b2RopeJointDef* def); | ||||
| 			RopeJoint(World* world, Param const& param); | ||||
| 
 | ||||
| 			void SetMaxLength(float length); | ||||
| 			float GetMaxLength() const; | ||||
|  | @ -580,18 +580,18 @@ namespace kiwano | |||
| 
 | ||||
| 		// 焊接关节
 | ||||
| 		class KGE_API WeldJoint | ||||
| 			: public PhysicJoint | ||||
| 			: public Joint | ||||
| 		{ | ||||
| 		public: | ||||
| 			struct Param : public PhysicJoint::ParamBase | ||||
| 			struct Param : public Joint::ParamBase | ||||
| 			{ | ||||
| 				Point anchor; | ||||
| 				float frequency_hz; | ||||
| 				float damping_ratio; | ||||
| 
 | ||||
| 				Param( | ||||
| 					PhysicBody* body_a, | ||||
| 					PhysicBody* body_b, | ||||
| 					Body* body_a, | ||||
| 					Body* body_b, | ||||
| 					Point const& anchor, | ||||
| 					float frequency_hz = 0.f, | ||||
| 					float damping_ratio = 0.f | ||||
|  | @ -603,8 +603,8 @@ namespace kiwano | |||
| 				{} | ||||
| 
 | ||||
| 				Param( | ||||
| 					PhysicBodyPtr body_a, | ||||
| 					PhysicBodyPtr body_b, | ||||
| 					BodyPtr body_a, | ||||
| 					BodyPtr body_b, | ||||
| 					Point const& anchor, | ||||
| 					float frequency_hz = 0.f, | ||||
| 					float damping_ratio = 0.f | ||||
|  | @ -614,8 +614,8 @@ namespace kiwano | |||
| 			}; | ||||
| 
 | ||||
| 			WeldJoint(); | ||||
| 			WeldJoint(PhysicWorld* world, b2WeldJointDef* def); | ||||
| 			WeldJoint(PhysicWorld* world, Param const& param); | ||||
| 			WeldJoint(World* world, b2WeldJointDef* def); | ||||
| 			WeldJoint(World* world, Param const& param); | ||||
| 
 | ||||
| 			// 设置弹簧阻尼器频率 [赫兹]
 | ||||
| 			void SetFrequency(float hz)				{ KGE_ASSERT(raw_joint_); raw_joint_->SetFrequency(hz); } | ||||
|  | @ -632,10 +632,10 @@ namespace kiwano | |||
| 
 | ||||
| 		// 轮关节
 | ||||
| 		class KGE_API WheelJoint | ||||
| 			: public PhysicJoint | ||||
| 			: public Joint | ||||
| 		{ | ||||
| 		public: | ||||
| 			struct Param : public PhysicJoint::ParamBase | ||||
| 			struct Param : public Joint::ParamBase | ||||
| 			{ | ||||
| 				Point anchor; | ||||
| 				Vec2 axis; | ||||
|  | @ -646,8 +646,8 @@ namespace kiwano | |||
| 				float damping_ratio; | ||||
| 
 | ||||
| 				Param( | ||||
| 					PhysicBody* body_a, | ||||
| 					PhysicBody* body_b, | ||||
| 					Body* body_a, | ||||
| 					Body* body_b, | ||||
| 					Point const& anchor, | ||||
| 					Vec2 const& axis, | ||||
| 					float frequency_hz = 2.0f, | ||||
|  | @ -667,8 +667,8 @@ namespace kiwano | |||
| 				{} | ||||
| 
 | ||||
| 				Param( | ||||
| 					PhysicBodyPtr body_a, | ||||
| 					PhysicBodyPtr body_b, | ||||
| 					BodyPtr body_a, | ||||
| 					BodyPtr body_b, | ||||
| 					Point const& anchor, | ||||
| 					Vec2 const& axis, | ||||
| 					float frequency_hz = 2.0f, | ||||
|  | @ -682,8 +682,8 @@ namespace kiwano | |||
| 			}; | ||||
| 
 | ||||
| 			WheelJoint(); | ||||
| 			WheelJoint(PhysicWorld* world, b2WheelJointDef* def); | ||||
| 			WheelJoint(PhysicWorld* world, Param const& param); | ||||
| 			WheelJoint(World* world, b2WheelJointDef* def); | ||||
| 			WheelJoint(World* world, Param const& param); | ||||
| 
 | ||||
| 			float GetJointTranslation() const; | ||||
| 			float GetJointLinearSpeed() const; | ||||
|  | @ -715,10 +715,10 @@ namespace kiwano | |||
| 		// 鼠标关节
 | ||||
| 		// 用于使身体的某个点追踪世界上的指定点,例如让物体追踪鼠标位置
 | ||||
| 		class KGE_API MouseJoint | ||||
| 			: public PhysicJoint | ||||
| 			: public Joint | ||||
| 		{ | ||||
| 		public: | ||||
| 			struct Param : public PhysicJoint::ParamBase | ||||
| 			struct Param : public Joint::ParamBase | ||||
| 			{ | ||||
| 				Point target; | ||||
| 				float max_force; | ||||
|  | @ -726,8 +726,8 @@ namespace kiwano | |||
| 				float damping_ratio; | ||||
| 
 | ||||
| 				Param( | ||||
| 					PhysicBody* body_a, | ||||
| 					PhysicBody* body_b, | ||||
| 					Body* body_a, | ||||
| 					Body* body_b, | ||||
| 					Point const& target, | ||||
| 					float max_force, | ||||
| 					float frequency_hz = 5.0f, | ||||
|  | @ -741,8 +741,8 @@ namespace kiwano | |||
| 				{} | ||||
| 
 | ||||
| 				Param( | ||||
| 					PhysicBodyPtr body_a, | ||||
| 					PhysicBodyPtr body_b, | ||||
| 					BodyPtr body_a, | ||||
| 					BodyPtr body_b, | ||||
| 					Point const& target, | ||||
| 					float max_force, | ||||
| 					float frequency_hz = 5.0f, | ||||
|  | @ -753,8 +753,8 @@ namespace kiwano | |||
| 			}; | ||||
| 
 | ||||
| 			MouseJoint(); | ||||
| 			MouseJoint(PhysicWorld* world, b2MouseJointDef* def); | ||||
| 			MouseJoint(PhysicWorld* world, Param const& param); | ||||
| 			MouseJoint(World* world, b2MouseJointDef* def); | ||||
| 			MouseJoint(World* world, Param const& param); | ||||
| 
 | ||||
| 			// 设定最大摩擦力 [N]
 | ||||
| 			void SetMaxForce(float force); | ||||
|  |  | |||
|  | @ -25,55 +25,55 @@ namespace kiwano | |||
| { | ||||
| 	namespace physics | ||||
| 	{ | ||||
| 		PhysicShape::PhysicShape() | ||||
| 		Shape::Shape() | ||||
| 			: shape_(nullptr) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicShape::PhysicShape(b2Shape* shape) | ||||
| 		Shape::Shape(b2Shape* shape) | ||||
| 			: shape_(shape) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		b2Shape* PhysicShape::GetB2Shape() | ||||
| 		b2Shape* Shape::GetB2Shape() | ||||
| 		{ | ||||
| 			return shape_; | ||||
| 		} | ||||
| 
 | ||||
| 		const b2Shape* PhysicShape::GetB2Shape() const | ||||
| 		const b2Shape* Shape::GetB2Shape() const | ||||
| 		{ | ||||
| 			return shape_; | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicShape::SetB2Shape(b2Shape* shape) | ||||
| 		void Shape::SetB2Shape(b2Shape* shape) | ||||
| 		{ | ||||
| 			shape_ = shape; | ||||
| 		} | ||||
| 
 | ||||
| 		//
 | ||||
| 		// PhysicCircleShape
 | ||||
| 		// CircleShape
 | ||||
| 		//
 | ||||
| 
 | ||||
| 		PhysicCircleShape::PhysicCircleShape() | ||||
| 			: PhysicShape(&circle_) | ||||
| 		CircleShape::CircleShape() | ||||
| 			: Shape(&circle_) | ||||
| 			, circle_() | ||||
| 			, radius_(0.f) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicCircleShape::PhysicCircleShape(float radius, Point const& offset) | ||||
| 			: PhysicCircleShape() | ||||
| 		CircleShape::CircleShape(float radius, Point const& offset) | ||||
| 			: CircleShape() | ||||
| 		{ | ||||
| 			Set(radius, offset); | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicCircleShape::Set(float radius, Point const& offset) | ||||
| 		void CircleShape::Set(float radius, Point const& offset) | ||||
| 		{ | ||||
| 			radius_ = radius; | ||||
| 			offset_ = offset; | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicCircleShape::FitWorld(PhysicWorld* world) | ||||
| 		void CircleShape::FitWorld(World* world) | ||||
| 		{ | ||||
| 			KGE_ASSERT(world); | ||||
| 			circle_.m_radius = world->Stage2World(radius_); | ||||
|  | @ -81,30 +81,30 @@ namespace kiwano | |||
| 		} | ||||
| 
 | ||||
| 		//
 | ||||
| 		// PhysicBoxShape
 | ||||
| 		// BoxShape
 | ||||
| 		//
 | ||||
| 
 | ||||
| 		PhysicBoxShape::PhysicBoxShape() | ||||
| 			: PhysicShape(&polygon_) | ||||
| 		BoxShape::BoxShape() | ||||
| 			: Shape(&polygon_) | ||||
| 			, polygon_() | ||||
| 			, rotation_(0.f) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicBoxShape::PhysicBoxShape(Vec2 const& size, Point const& offset, float rotation) | ||||
| 			: PhysicBoxShape() | ||||
| 		BoxShape::BoxShape(Vec2 const& size, Point const& offset, float rotation) | ||||
| 			: BoxShape() | ||||
| 		{ | ||||
| 			Set(size, offset, rotation); | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicBoxShape::Set(Vec2 const& size, Point const& offset, float rotation) | ||||
| 		void BoxShape::Set(Vec2 const& size, Point const& offset, float rotation) | ||||
| 		{ | ||||
| 			box_size_ = size; | ||||
| 			offset_ = offset; | ||||
| 			rotation_ = rotation; | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicBoxShape::FitWorld(PhysicWorld* world) | ||||
| 		void BoxShape::FitWorld(World* world) | ||||
| 		{ | ||||
| 			KGE_ASSERT(world); | ||||
| 
 | ||||
|  | @ -114,27 +114,27 @@ namespace kiwano | |||
| 		} | ||||
| 
 | ||||
| 		//
 | ||||
| 		// PhysicPolygonShape
 | ||||
| 		// PolygonShape
 | ||||
| 		//
 | ||||
| 
 | ||||
| 		PhysicPolygonShape::PhysicPolygonShape() | ||||
| 			: PhysicShape(&polygon_) | ||||
| 		PolygonShape::PolygonShape() | ||||
| 			: Shape(&polygon_) | ||||
| 			, polygon_() | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicPolygonShape::PhysicPolygonShape(Vector<Point> const& vertexs) | ||||
| 			: PhysicPolygonShape() | ||||
| 		PolygonShape::PolygonShape(Vector<Point> const& vertexs) | ||||
| 			: PolygonShape() | ||||
| 		{ | ||||
| 			Set(vertexs); | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicPolygonShape::Set(Vector<Point> const& vertexs) | ||||
| 		void PolygonShape::Set(Vector<Point> const& vertexs) | ||||
| 		{ | ||||
| 			vertexs_ = vertexs; | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicPolygonShape::FitWorld(PhysicWorld* world) | ||||
| 		void PolygonShape::FitWorld(World* world) | ||||
| 		{ | ||||
| 			KGE_ASSERT(world); | ||||
| 
 | ||||
|  | @ -149,28 +149,28 @@ namespace kiwano | |||
| 		} | ||||
| 
 | ||||
| 		//
 | ||||
| 		// PhysicEdgeShape
 | ||||
| 		// EdgeShape
 | ||||
| 		//
 | ||||
| 
 | ||||
| 		PhysicEdgeShape::PhysicEdgeShape() | ||||
| 			: PhysicShape(&edge_) | ||||
| 		EdgeShape::EdgeShape() | ||||
| 			: Shape(&edge_) | ||||
| 			, edge_() | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicEdgeShape::PhysicEdgeShape(Point const& p1, Point const& p2) | ||||
| 			: PhysicEdgeShape() | ||||
| 		EdgeShape::EdgeShape(Point const& p1, Point const& p2) | ||||
| 			: EdgeShape() | ||||
| 		{ | ||||
| 			Set(p1, p2); | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicEdgeShape::Set(Point const& p1, Point const& p2) | ||||
| 		void EdgeShape::Set(Point const& p1, Point const& p2) | ||||
| 		{ | ||||
| 			p_[0] = p1; | ||||
| 			p_[1] = p2; | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicEdgeShape::FitWorld(PhysicWorld* world) | ||||
| 		void EdgeShape::FitWorld(World* world) | ||||
| 		{ | ||||
| 			KGE_ASSERT(world); | ||||
| 
 | ||||
|  | @ -180,29 +180,29 @@ namespace kiwano | |||
| 		} | ||||
| 
 | ||||
| 		//
 | ||||
| 		// PhysicChainShape
 | ||||
| 		// ChainShape
 | ||||
| 		//
 | ||||
| 
 | ||||
| 		PhysicChainShape::PhysicChainShape() | ||||
| 			: PhysicShape(&chain_) | ||||
| 		ChainShape::ChainShape() | ||||
| 			: Shape(&chain_) | ||||
| 			, chain_() | ||||
| 			, loop_(false) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicChainShape::PhysicChainShape(Vector<Point> const& vertexs, bool loop) | ||||
| 			: PhysicChainShape() | ||||
| 		ChainShape::ChainShape(Vector<Point> const& vertexs, bool loop) | ||||
| 			: ChainShape() | ||||
| 		{ | ||||
| 			Set(vertexs, loop); | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicChainShape::Set(Vector<Point> const& vertexs, bool loop) | ||||
| 		void ChainShape::Set(Vector<Point> const& vertexs, bool loop) | ||||
| 		{ | ||||
| 			vertexs_ = vertexs; | ||||
| 			loop_ = loop; | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicChainShape::FitWorld(PhysicWorld* world) | ||||
| 		void ChainShape::FitWorld(World* world) | ||||
| 		{ | ||||
| 			KGE_ASSERT(world); | ||||
| 
 | ||||
|  |  | |||
|  | @ -25,37 +25,37 @@ namespace kiwano | |||
| { | ||||
| 	namespace physics | ||||
| 	{ | ||||
| 		class PhysicWorld; | ||||
| 		class World; | ||||
| 
 | ||||
| 		// 形状基类
 | ||||
| 		class KGE_API PhysicShape | ||||
| 		class KGE_API Shape | ||||
| 		{ | ||||
| 		public: | ||||
| 			PhysicShape(); | ||||
| 			PhysicShape(b2Shape* shape); | ||||
| 			Shape(); | ||||
| 			Shape(b2Shape* shape); | ||||
| 
 | ||||
| 			b2Shape* GetB2Shape(); | ||||
| 			const b2Shape* GetB2Shape() const; | ||||
| 			void SetB2Shape(b2Shape* shape); | ||||
| 
 | ||||
| 			virtual void FitWorld(PhysicWorld* world) {} | ||||
| 			virtual void FitWorld(World* world) {} | ||||
| 
 | ||||
| 		protected: | ||||
| 			b2Shape* shape_; | ||||
| 		}; | ||||
| 
 | ||||
| 		// 圆形形状
 | ||||
| 		class KGE_API PhysicCircleShape | ||||
| 			: public PhysicShape | ||||
| 		class KGE_API CircleShape | ||||
| 			: public Shape | ||||
| 		{ | ||||
| 		public: | ||||
| 			PhysicCircleShape(); | ||||
| 			CircleShape(); | ||||
| 
 | ||||
| 			PhysicCircleShape(float radius, Point const& offset = Point()); | ||||
| 			CircleShape(float radius, Point const& offset = Point()); | ||||
| 
 | ||||
| 			void Set(float radius, Point const& offset = Point()); | ||||
| 
 | ||||
| 			void FitWorld(PhysicWorld* world) override; | ||||
| 			void FitWorld(World* world) override; | ||||
| 
 | ||||
| 		protected: | ||||
| 			float radius_; | ||||
|  | @ -64,17 +64,17 @@ namespace kiwano | |||
| 		}; | ||||
| 
 | ||||
| 		// 盒子形状
 | ||||
| 		class KGE_API PhysicBoxShape | ||||
| 			: public PhysicShape | ||||
| 		class KGE_API BoxShape | ||||
| 			: public Shape | ||||
| 		{ | ||||
| 		public: | ||||
| 			PhysicBoxShape(); | ||||
| 			BoxShape(); | ||||
| 
 | ||||
| 			PhysicBoxShape(Vec2 const& size, Point const& offset = Point(), float rotation = 0.f); | ||||
| 			BoxShape(Vec2 const& size, Point const& offset = Point(), float rotation = 0.f); | ||||
| 
 | ||||
| 			void Set(Vec2 const& size, Point const& offset = Point(), float rotation = 0.f); | ||||
| 
 | ||||
| 			void FitWorld(PhysicWorld* world) override; | ||||
| 			void FitWorld(World* world) override; | ||||
| 
 | ||||
| 		protected: | ||||
| 			float rotation_; | ||||
|  | @ -84,17 +84,17 @@ namespace kiwano | |||
| 		}; | ||||
| 
 | ||||
| 		// 多边形形状
 | ||||
| 		class KGE_API PhysicPolygonShape | ||||
| 			: public PhysicShape | ||||
| 		class KGE_API PolygonShape | ||||
| 			: public Shape | ||||
| 		{ | ||||
| 		public: | ||||
| 			PhysicPolygonShape(); | ||||
| 			PolygonShape(); | ||||
| 
 | ||||
| 			PhysicPolygonShape(Vector<Point> const& vertexs); | ||||
| 			PolygonShape(Vector<Point> const& vertexs); | ||||
| 
 | ||||
| 			void Set(Vector<Point> const& vertexs); | ||||
| 
 | ||||
| 			void FitWorld(PhysicWorld* world) override; | ||||
| 			void FitWorld(World* world) override; | ||||
| 
 | ||||
| 		protected: | ||||
| 			Vector<Point> vertexs_; | ||||
|  | @ -102,17 +102,17 @@ namespace kiwano | |||
| 		}; | ||||
| 
 | ||||
| 		// 线段形状, 用于表示一条边
 | ||||
| 		class KGE_API PhysicEdgeShape | ||||
| 			: public PhysicShape | ||||
| 		class KGE_API EdgeShape | ||||
| 			: public Shape | ||||
| 		{ | ||||
| 		public: | ||||
| 			PhysicEdgeShape(); | ||||
| 			EdgeShape(); | ||||
| 
 | ||||
| 			PhysicEdgeShape(Point const& p1, Point const& p2); | ||||
| 			EdgeShape(Point const& p1, Point const& p2); | ||||
| 
 | ||||
| 			void Set(Point const& p1, Point const& p2); | ||||
| 
 | ||||
| 			void FitWorld(PhysicWorld* world) override; | ||||
| 			void FitWorld(World* world) override; | ||||
| 
 | ||||
| 		protected: | ||||
| 			Point p_[2]; | ||||
|  | @ -120,17 +120,17 @@ namespace kiwano | |||
| 		}; | ||||
| 
 | ||||
| 		// 链式形状
 | ||||
| 		class KGE_API PhysicChainShape | ||||
| 			: public PhysicShape | ||||
| 		class KGE_API ChainShape | ||||
| 			: public Shape | ||||
| 		{ | ||||
| 		public: | ||||
| 			PhysicChainShape(); | ||||
| 			ChainShape(); | ||||
| 
 | ||||
| 			PhysicChainShape(Vector<Point> const& vertexs, bool loop = false); | ||||
| 			ChainShape(Vector<Point> const& vertexs, bool loop = false); | ||||
| 
 | ||||
| 			void Set(Vector<Point> const& vertexs, bool loop = false); | ||||
| 
 | ||||
| 			void FitWorld(PhysicWorld* world) override; | ||||
| 			void FitWorld(World* world) override; | ||||
| 
 | ||||
| 		protected: | ||||
| 			bool loop_; | ||||
|  |  | |||
|  | @ -19,6 +19,7 @@ | |||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #include "World.h" | ||||
| #include <kiwano-physics/ContactEvent.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
|  | @ -29,12 +30,12 @@ namespace kiwano | |||
| 			const float DefaultGlobalScale = 100.f;		// 100 pixels per meters
 | ||||
| 		} | ||||
| 
 | ||||
| 		class PhysicWorld::DestructionListener : public b2DestructionListener | ||||
| 		class World::DestructionListener : public b2DestructionListener | ||||
| 		{ | ||||
| 			PhysicWorld* world_; | ||||
| 			World* world_; | ||||
| 
 | ||||
| 		public: | ||||
| 			DestructionListener(PhysicWorld* world) | ||||
| 			DestructionListener(World* world) | ||||
| 				: world_(world) | ||||
| 			{ | ||||
| 			} | ||||
|  | @ -53,24 +54,34 @@ namespace kiwano | |||
| 			} | ||||
| 		}; | ||||
| 
 | ||||
| 		class PhysicWorld::ContactListener | ||||
| 		class World::ContactListener | ||||
| 			: public b2ContactListener | ||||
| 		{ | ||||
| 			PhysicWorld* world_; | ||||
| 			World* world_; | ||||
| 
 | ||||
| 		public: | ||||
| 			ContactListener(PhysicWorld* world) | ||||
| 			ContactListener(World* world) | ||||
| 				: world_(world) | ||||
| 			{ | ||||
| 			} | ||||
| 
 | ||||
| 			void BeginContact(b2Contact* contact) override									{ world_->OnContactBegin(contact); } | ||||
| 			void EndContact(b2Contact* contact) override									{ world_->OnContactEnd(contact); } | ||||
| 			void BeginContact(b2Contact* contact) override | ||||
| 			{ | ||||
| 				ContactBeginEvent evt(contact); | ||||
| 				world_->Dispatch(&evt); | ||||
| 			} | ||||
| 
 | ||||
| 			void EndContact(b2Contact* contact) override | ||||
| 			{ | ||||
| 				ContactEndEvent evt(contact); | ||||
| 				world_->Dispatch(&evt); | ||||
| 			} | ||||
| 
 | ||||
| 			void PreSolve(b2Contact* contact, const b2Manifold* oldManifold) override		{ KGE_NOT_USED(contact); KGE_NOT_USED(oldManifold); } | ||||
| 			void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse) override	{ KGE_NOT_USED(contact); KGE_NOT_USED(impulse); } | ||||
| 		}; | ||||
| 
 | ||||
| 		PhysicWorld::PhysicWorld() | ||||
| 		World::World() | ||||
| 			: world_(b2Vec2(0, 10.0f)) | ||||
| 			, vel_iter_(6) | ||||
| 			, pos_iter_(2) | ||||
|  | @ -86,7 +97,7 @@ namespace kiwano | |||
| 			world_.SetContactListener(contact_listener_); | ||||
| 		} | ||||
| 
 | ||||
| 		PhysicWorld::~PhysicWorld() | ||||
| 		World::~World() | ||||
| 		{ | ||||
| 			world_.SetDestructionListener(nullptr); | ||||
| 			if (destruction_listener_) | ||||
|  | @ -102,15 +113,13 @@ namespace kiwano | |||
| 				contact_listener_ = nullptr; | ||||
| 			} | ||||
| 
 | ||||
| 			RemoveAllContactListeners(); | ||||
| 
 | ||||
| 			// Make sure b2World was destroyed after b2Body
 | ||||
| 			RemoveAllChildren(); | ||||
| 			RemoveAllBodies(); | ||||
| 			RemoveAllJoints(); | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicWorld::RemoveBody(PhysicBody* body) | ||||
| 		void World::RemoveBody(Body* body) | ||||
| 		{ | ||||
| 			if (body && body->GetB2Body()) | ||||
| 			{ | ||||
|  | @ -118,7 +127,7 @@ namespace kiwano | |||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicWorld::RemoveAllBodies() | ||||
| 		void World::RemoveAllBodies() | ||||
| 		{ | ||||
| 			if (world_.GetBodyCount()) | ||||
| 			{ | ||||
|  | @ -132,7 +141,7 @@ namespace kiwano | |||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicWorld::AddJoint(PhysicJoint* joint) | ||||
| 		void World::AddJoint(Joint* joint) | ||||
| 		{ | ||||
| 			if (joint) | ||||
| 			{ | ||||
|  | @ -140,7 +149,7 @@ namespace kiwano | |||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicWorld::RemoveJoint(PhysicJoint* joint) | ||||
| 		void World::RemoveJoint(Joint* joint) | ||||
| 		{ | ||||
| 			if (joint) | ||||
| 			{ | ||||
|  | @ -159,7 +168,7 @@ namespace kiwano | |||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicWorld::RemoveAllJoints() | ||||
| 		void World::RemoveAllJoints() | ||||
| 		{ | ||||
| 			if (world_.GetJointCount()) | ||||
| 			{ | ||||
|  | @ -178,14 +187,14 @@ namespace kiwano | |||
| 			joints_.clear(); | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicWorld::JointRemoved(b2Joint* joint) | ||||
| 		void World::JointRemoved(b2Joint* joint) | ||||
| 		{ | ||||
| 			if (!removing_joint_ && joint) | ||||
| 			{ | ||||
| 				auto iter = std::find_if( | ||||
| 					joints_.begin(), | ||||
| 					joints_.end(), | ||||
| 					[joint](PhysicJoint* j) -> bool { return j->GetB2Joint() == joint; } | ||||
| 					[joint](Joint* j) -> bool { return j->GetB2Joint() == joint; } | ||||
| 				); | ||||
| 
 | ||||
| 				if (iter != joints_.end()) | ||||
|  | @ -195,36 +204,36 @@ namespace kiwano | |||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		b2World* PhysicWorld::GetB2World() | ||||
| 		b2World* World::GetB2World() | ||||
| 		{ | ||||
| 			return &world_; | ||||
| 		} | ||||
| 
 | ||||
| 		const b2World* PhysicWorld::GetB2World() const | ||||
| 		const b2World* World::GetB2World() const | ||||
| 		{ | ||||
| 			return &world_; | ||||
| 		} | ||||
| 
 | ||||
| 		Vec2 PhysicWorld::GetGravity() const | ||||
| 		Vec2 World::GetGravity() const | ||||
| 		{ | ||||
| 			b2Vec2 g = world_.GetGravity(); | ||||
| 			return Vec2(g.x, g.y); | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicWorld::SetGravity(Vec2 gravity) | ||||
| 		void World::SetGravity(Vec2 gravity) | ||||
| 		{ | ||||
| 			world_.SetGravity(b2Vec2(gravity.x, gravity.y)); | ||||
| 		} | ||||
| 
 | ||||
| 		void PhysicWorld::Update(Duration dt) | ||||
| 		void World::Update(Duration dt) | ||||
| 		{ | ||||
| 			Stage::Update(dt); | ||||
| 
 | ||||
| 			b2Body* b2body = world_.GetBodyList(); | ||||
| 			while (b2body) | ||||
| 			{ | ||||
| 				PhysicBody* body = static_cast<PhysicBody*>(b2body->GetUserData()); | ||||
| 				if (body && body->GetType() != PhysicBody::Type::Static) | ||||
| 				Body* body = static_cast<Body*>(b2body->GetUserData()); | ||||
| 				if (body && body->GetType() != Body::Type::Static) | ||||
| 				{ | ||||
| 					body->UpdateFromActor(); | ||||
| 				} | ||||
|  | @ -237,8 +246,8 @@ namespace kiwano | |||
| 			b2body = world_.GetBodyList(); | ||||
| 			while (b2body) | ||||
| 			{ | ||||
| 				PhysicBody* body = static_cast<PhysicBody*>(b2body->GetUserData()); | ||||
| 				if (body && body->GetType() != PhysicBody::Type::Static) | ||||
| 				Body* body = static_cast<Body*>(b2body->GetUserData()); | ||||
| 				if (body && body->GetType() != Body::Type::Static) | ||||
| 				{ | ||||
| 					body->UpdateActor(); | ||||
| 				} | ||||
|  |  | |||
|  | @ -21,24 +21,22 @@ | |||
| #pragma once | ||||
| #include <kiwano-physics/Body.h> | ||||
| #include <kiwano-physics/Joint.h> | ||||
| #include <kiwano-physics/ContactListener.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
| 	namespace physics | ||||
| 	{ | ||||
| 		// 物理世界
 | ||||
| 		class KGE_API PhysicWorld | ||||
| 		class KGE_API World | ||||
| 			: public Stage | ||||
| 			, public PhysicContactDispatcher | ||||
| 		{ | ||||
| 			friend class PhysicBody; | ||||
| 			friend class PhysicJoint; | ||||
| 			friend class Body; | ||||
| 			friend class Joint; | ||||
| 
 | ||||
| 		public: | ||||
| 			PhysicWorld(); | ||||
| 			World(); | ||||
| 
 | ||||
| 			virtual ~PhysicWorld(); | ||||
| 			virtual ~World(); | ||||
| 
 | ||||
| 			// 获取重力
 | ||||
| 			Vec2 GetGravity() const; | ||||
|  | @ -71,16 +69,16 @@ namespace kiwano | |||
| 
 | ||||
| 		private: | ||||
| 			// 移除物体
 | ||||
| 			void RemoveBody(PhysicBody* body); | ||||
| 			void RemoveBody(Body* body); | ||||
| 
 | ||||
| 			// 移除所有物体
 | ||||
| 			void RemoveAllBodies(); | ||||
| 
 | ||||
| 			// 添加关节
 | ||||
| 			void AddJoint(PhysicJoint* joint); | ||||
| 			void AddJoint(Joint* joint); | ||||
| 
 | ||||
| 			// 移除关节
 | ||||
| 			void RemoveJoint(PhysicJoint* joint); | ||||
| 			void RemoveJoint(Joint* joint); | ||||
| 
 | ||||
| 			// 移除所有关节
 | ||||
| 			void RemoveAllJoints(); | ||||
|  | @ -105,9 +103,9 @@ namespace kiwano | |||
| 			ContactListener* contact_listener_; | ||||
| 
 | ||||
| 			bool removing_joint_; | ||||
| 			Vector<PhysicJoint*> joints_; | ||||
| 			Vector<Joint*> joints_; | ||||
| 		}; | ||||
| 
 | ||||
| 		KGE_DECLARE_SMART_PTR(PhysicWorld); | ||||
| 		KGE_DECLARE_SMART_PTR(World); | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -23,7 +23,7 @@ | |||
| #include <kiwano-physics/Shape.h> | ||||
| #include <kiwano-physics/Fixture.h> | ||||
| #include <kiwano-physics/Contact.h> | ||||
| #include <kiwano-physics/ContactListener.h> | ||||
| #include <kiwano-physics/ContactEvent.h> | ||||
| #include <kiwano-physics/Body.h> | ||||
| #include <kiwano-physics/Joint.h> | ||||
| #include <kiwano-physics/World.h> | ||||
|  |  | |||
|  | @ -20,7 +20,7 @@ | |||
| 
 | ||||
| #include <kiwano/2d/Actor.h> | ||||
| #include <kiwano/2d/Stage.h> | ||||
| #include <kiwano/base/Logger.h> | ||||
| #include <kiwano/core/Logger.h> | ||||
| #include <kiwano/renderer/Renderer.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
|  | @ -155,7 +155,7 @@ namespace kiwano | |||
| 		return visible_in_rt_; | ||||
| 	} | ||||
| 
 | ||||
| 	void Actor::Dispatch(Event& evt) | ||||
| 	void Actor::Dispatch(Event* evt) | ||||
| 	{ | ||||
| 		if (!visible_) | ||||
| 			return; | ||||
|  | @ -167,21 +167,25 @@ namespace kiwano | |||
| 			child->Dispatch(evt); | ||||
| 		} | ||||
| 
 | ||||
| 		if (responsible_ && MouseEvent::Check(evt.type)) | ||||
| 		if (responsible_) | ||||
| 		{ | ||||
| 			if (evt.type == Event::MouseMove) | ||||
| 			if (evt->type == event::MouseMove) | ||||
| 			{ | ||||
| 				if (!evt.target && ContainsPoint(Point{ evt.mouse.x, evt.mouse.y })) | ||||
| 				auto mouse_evt = evt->SafeCast<MouseMoveEvent>(); | ||||
| 				if (!mouse_evt->target && ContainsPoint(mouse_evt->pos)) | ||||
| 				{ | ||||
| 					evt.target = this; | ||||
| 					mouse_evt->target = this; | ||||
| 
 | ||||
| 					if (!hover_) | ||||
| 					{ | ||||
| 						hover_ = true; | ||||
| 
 | ||||
| 						Event hover = evt; | ||||
| 						hover.type = Event::MouseHover; | ||||
| 						EventDispatcher::Dispatch(hover); | ||||
| 						MouseHoverEvent hover; | ||||
| 						hover.pos = mouse_evt->pos; | ||||
| 						hover.left_btn_down = mouse_evt->left_btn_down; | ||||
| 						hover.right_btn_down = mouse_evt->right_btn_down; | ||||
| 						hover.target = this; | ||||
| 						EventDispatcher::Dispatch(&hover); | ||||
| 					} | ||||
| 				} | ||||
| 				else if (hover_) | ||||
|  | @ -189,27 +193,34 @@ namespace kiwano | |||
| 					hover_ = false; | ||||
| 					pressed_ = false; | ||||
| 
 | ||||
| 					Event out = evt; | ||||
| 					MouseOutEvent out; | ||||
| 					out.pos = mouse_evt->pos; | ||||
| 					out.left_btn_down = mouse_evt->left_btn_down; | ||||
| 					out.right_btn_down = mouse_evt->right_btn_down; | ||||
| 					out.target = this; | ||||
| 					out.type = Event::MouseOut; | ||||
| 					EventDispatcher::Dispatch(out); | ||||
| 					EventDispatcher::Dispatch(&out); | ||||
| 				} | ||||
| 			} | ||||
| 
 | ||||
| 			if (evt.type == Event::MouseBtnDown && hover_) | ||||
| 			if (evt->type == event::MouseDown && hover_) | ||||
| 			{ | ||||
| 				pressed_ = true; | ||||
| 				evt.target = this; | ||||
| 				evt->SafeCast<MouseDownEvent>()->target = this; | ||||
| 			} | ||||
| 
 | ||||
| 			if (evt.type == Event::MouseBtnUp && pressed_) | ||||
| 			if (evt->type == event::MouseUp && pressed_) | ||||
| 			{ | ||||
| 				pressed_ = false; | ||||
| 				evt.target = this; | ||||
| 
 | ||||
| 				Event click = evt; | ||||
| 				click.type = Event::Click; | ||||
| 				EventDispatcher::Dispatch(click); | ||||
| 				auto mouse_up_evt = evt->SafeCast<MouseUpEvent>(); | ||||
| 				mouse_up_evt->target = this; | ||||
| 
 | ||||
| 				MouseOutEvent click; | ||||
| 				click.pos = mouse_up_evt->pos; | ||||
| 				click.left_btn_down = mouse_up_evt->left_btn_down; | ||||
| 				click.right_btn_down = mouse_up_evt->right_btn_down; | ||||
| 				click.target = this; | ||||
| 				EventDispatcher::Dispatch(&click); | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
|  |  | |||
|  | @ -22,8 +22,8 @@ | |||
| #include <kiwano/2d/include-forwards.h> | ||||
| #include <kiwano/2d/Transform.h> | ||||
| #include <kiwano/2d/action/ActionManager.h> | ||||
| #include <kiwano/base/TimerManager.h> | ||||
| #include <kiwano/base/EventDispatcher.h> | ||||
| #include <kiwano/core/TimerManager.h> | ||||
| #include <kiwano/core/EventDispatcher.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
|  | @ -49,97 +49,97 @@ namespace kiwano | |||
| 		Actor(); | ||||
| 
 | ||||
| 		// 更新角色
 | ||||
| 		virtual void		OnUpdate(Duration dt)			{ KGE_NOT_USED(dt); } | ||||
| 		virtual void OnUpdate(Duration dt); | ||||
| 
 | ||||
| 		// 渲染角色
 | ||||
| 		virtual void		OnRender(RenderTarget* rt)		{ KGE_NOT_USED(rt); } | ||||
| 		virtual void OnRender(RenderTarget* rt); | ||||
| 
 | ||||
| 		// 获取显示状态
 | ||||
| 		bool				IsVisible() const				{ return visible_; } | ||||
| 		bool IsVisible() const; | ||||
| 
 | ||||
| 		// 获取响应状态
 | ||||
| 		bool				IsResponsible() const			{ return responsible_; } | ||||
| 		bool IsResponsible() const; | ||||
| 
 | ||||
| 		// 是否启用级联透明度
 | ||||
| 		bool				IsCascadeOpacityEnabled() const	{ return cascade_opacity_; } | ||||
| 		bool IsCascadeOpacityEnabled() const; | ||||
| 
 | ||||
| 		// 获取名称的 Hash 值
 | ||||
| 		size_t				GetHashName() const				{ return hash_name_; } | ||||
| 		size_t GetHashName() const; | ||||
| 
 | ||||
| 		// 获取 Z 轴顺序
 | ||||
| 		int					GetZOrder() const				{ return z_order_; } | ||||
| 		int GetZOrder() const; | ||||
| 
 | ||||
| 		// 获取坐标
 | ||||
| 		Point const&		GetPosition() const				{ return transform_.position; } | ||||
| 		Point const& GetPosition() const; | ||||
| 
 | ||||
| 		// 获取 x 坐标
 | ||||
| 		float				GetPositionX() const			{ return GetPosition().x; } | ||||
| 		float GetPositionX() const; | ||||
| 
 | ||||
| 		// 获取 y 坐标
 | ||||
| 		float				GetPositionY() const			{ return GetPosition().y; } | ||||
| 		float GetPositionY() const; | ||||
| 
 | ||||
| 		// 获取缩放比例
 | ||||
| 		Point const&		GetScale() const				{ return transform_.scale; } | ||||
| 		Point const& GetScale() const; | ||||
| 
 | ||||
| 		// 获取横向缩放比例
 | ||||
| 		float				GetScaleX() const				{ return GetScale().x; } | ||||
| 		float GetScaleX() const; | ||||
| 
 | ||||
| 		// 获取纵向缩放比例
 | ||||
| 		float				GetScaleY() const				{ return GetScale().y; } | ||||
| 		float GetScaleY() const; | ||||
| 
 | ||||
| 		// 获取错切角度
 | ||||
| 		Point const&		GetSkew() const					{ return transform_.skew; } | ||||
| 		Point const& GetSkew() const; | ||||
| 
 | ||||
| 		// 获取横向错切角度
 | ||||
| 		float				GetSkewX() const				{ return GetSkew().x; } | ||||
| 		float GetSkewX() const; | ||||
| 
 | ||||
| 		// 获取纵向错切角度
 | ||||
| 		float				GetSkewY() const				{ return GetSkew().y; } | ||||
| 		float GetSkewY() const; | ||||
| 
 | ||||
| 		// 获取旋转角度
 | ||||
| 		float				GetRotation() const				{ return transform_.rotation; } | ||||
| 		float GetRotation() const; | ||||
| 
 | ||||
| 		// 获取宽度
 | ||||
| 		float				GetWidth() const				{ return GetSize().x; } | ||||
| 		float GetWidth() const; | ||||
| 
 | ||||
| 		// 获取高度
 | ||||
| 		float				GetHeight() const				{ return GetSize().y; } | ||||
| 		float GetHeight() const; | ||||
| 
 | ||||
| 		// 获取大小
 | ||||
| 		Size const&			GetSize() const					{ return size_; } | ||||
| 		Size const& GetSize() const; | ||||
| 
 | ||||
| 		// 获取缩放后的宽度
 | ||||
| 		float				GetScaledWidth() const			{ return GetWidth() * GetScaleX(); } | ||||
| 		float GetScaledWidth() const; | ||||
| 
 | ||||
| 		// 获取缩放后的高度
 | ||||
| 		float				GetScaledHeight() const			{ return GetHeight() * GetScaleY(); } | ||||
| 		float GetScaledHeight() const; | ||||
| 
 | ||||
| 		// 获取缩放后的大小
 | ||||
| 		Size				GetScaledSize() const			{ return Size{ GetScaledWidth(), GetScaledHeight() }; } | ||||
| 		Size GetScaledSize() const; | ||||
| 
 | ||||
| 		// 获取锚点
 | ||||
| 		Point const&		GetAnchor() const				{ return anchor_; } | ||||
| 		Point const& GetAnchor() const; | ||||
| 
 | ||||
| 		// 获取 x 方向锚点
 | ||||
| 		float				GetAnchorX() const				{ return GetAnchor().x; } | ||||
| 		float GetAnchorX() const; | ||||
| 
 | ||||
| 		// 获取 y 方向锚点
 | ||||
| 		float				GetAnchorY() const				{ return GetAnchor().y; } | ||||
| 		float GetAnchorY() const; | ||||
| 
 | ||||
| 		// 获取透明度
 | ||||
| 		float				GetOpacity() const				{ return opacity_; } | ||||
| 		float GetOpacity() const; | ||||
| 
 | ||||
| 		// 获取显示透明度
 | ||||
| 		float				GetDisplayedOpacity() const		{ return displayed_opacity_; } | ||||
| 		float GetDisplayedOpacity() const; | ||||
| 
 | ||||
| 		// 获取变换
 | ||||
| 		Transform			GetTransform() const			{ return transform_; } | ||||
| 		Transform GetTransform() const; | ||||
| 
 | ||||
| 		// 获取父角色
 | ||||
| 		inline Actor*		GetParent() const				{ return parent_; } | ||||
| 		Actor* GetParent() const; | ||||
| 
 | ||||
| 		// 获取所在舞台
 | ||||
| 		inline Stage*		GetStage() const				{ return stage_; } | ||||
| 		Stage* GetStage() const; | ||||
| 
 | ||||
| 		// 获取边框
 | ||||
| 		virtual Rect GetBounds() const; | ||||
|  | @ -169,13 +169,10 @@ namespace kiwano | |||
| 		); | ||||
| 
 | ||||
| 		// 设置坐标
 | ||||
| 		inline void SetPosition( | ||||
| 		void SetPosition( | ||||
| 			float x, | ||||
| 			float y | ||||
| 		) | ||||
| 		{ | ||||
| 			SetPosition(Point{ x, y }); | ||||
| 		} | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置横坐标
 | ||||
| 		void SetPositionX( | ||||
|  | @ -193,13 +190,10 @@ namespace kiwano | |||
| 		); | ||||
| 
 | ||||
| 		// 移动坐标
 | ||||
| 		inline void Move( | ||||
| 		void Move( | ||||
| 			float vx, | ||||
| 			float vy | ||||
| 		) | ||||
| 		{ | ||||
| 			Move(Vec2{ vx, vy }); | ||||
| 		} | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置缩放比例
 | ||||
| 		// 默认为 (1.0, 1.0)
 | ||||
|  | @ -209,13 +203,10 @@ namespace kiwano | |||
| 
 | ||||
| 		// 设置缩放比例
 | ||||
| 		// 默认为 (1.0, 1.0)
 | ||||
| 		inline void SetScale( | ||||
| 		void SetScale( | ||||
| 			float scalex, | ||||
| 			float scaley | ||||
| 		) | ||||
| 		{ | ||||
| 			SetScale(Vec2{ scalex, scaley }); | ||||
| 		} | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置错切角度
 | ||||
| 		// 默认为 (0, 0)
 | ||||
|  | @ -225,13 +216,10 @@ namespace kiwano | |||
| 
 | ||||
| 		// 设置错切角度
 | ||||
| 		// 默认为 (0, 0)
 | ||||
| 		inline void SetSkew( | ||||
| 		void SetSkew( | ||||
| 			float skewx, | ||||
| 			float skewy | ||||
| 		) | ||||
| 		{ | ||||
| 			SetSkew(Vec2{ skewx, skewy }); | ||||
| 		} | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置旋转角度
 | ||||
| 		// 默认为 0
 | ||||
|  | @ -247,13 +235,10 @@ namespace kiwano | |||
| 
 | ||||
| 		// 设置锚点位置
 | ||||
| 		// 默认为 (0, 0), 范围 [0, 1]
 | ||||
| 		inline void SetAnchor( | ||||
| 		void SetAnchor( | ||||
| 			float anchorx, | ||||
| 			float anchory | ||||
| 		) | ||||
| 		{ | ||||
| 			SetAnchor(Vec2{ anchorx, anchory }); | ||||
| 		} | ||||
| 		); | ||||
| 
 | ||||
| 		// 修改宽度
 | ||||
| 		virtual void SetWidth( | ||||
|  | @ -271,13 +256,10 @@ namespace kiwano | |||
| 		); | ||||
| 
 | ||||
| 		// 修改大小
 | ||||
| 		inline void SetSize( | ||||
| 		void SetSize( | ||||
| 			float width, | ||||
| 			float height | ||||
| 		) | ||||
| 		{ | ||||
| 			SetSize(Size{ width, height }); | ||||
| 		} | ||||
| 		); | ||||
| 
 | ||||
| 		// 设置透明度
 | ||||
| 		// 默认为 1.0, 范围 [0, 1]
 | ||||
|  | @ -364,8 +346,26 @@ namespace kiwano | |||
| 		// 判断点是否在角色内
 | ||||
| 		virtual bool ContainsPoint(const Point& point) const; | ||||
| 
 | ||||
| 		// 暂停角色更新
 | ||||
| 		void PauseUpdating(); | ||||
| 
 | ||||
| 		// 继续角色更新
 | ||||
| 		void ResumeUpdating(); | ||||
| 
 | ||||
| 		// 角色更新是否暂停
 | ||||
| 		bool IsUpdatePausing() const; | ||||
| 
 | ||||
| 		// 设置更新时的回调函数
 | ||||
| 		void SetCallbackOnUpdate(UpdateCallback const& cb); | ||||
| 
 | ||||
| 		// 获取更新时的回调函数
 | ||||
| 		UpdateCallback GetCallbackOnUpdate() const; | ||||
| 
 | ||||
| 		// 渲染角色边界
 | ||||
| 		void ShowBorder(bool show); | ||||
| 
 | ||||
| 		// 事件分发
 | ||||
| 		void Dispatch(Event& evt) override; | ||||
| 		void Dispatch(Event* evt) override; | ||||
| 
 | ||||
| 		// 设置默认锚点
 | ||||
| 		static void SetDefaultAnchor( | ||||
|  | @ -373,24 +373,6 @@ namespace kiwano | |||
| 			float anchor_y | ||||
| 		); | ||||
| 
 | ||||
| 		// 暂停角色更新
 | ||||
| 		inline void				PauseUpdating()									{ update_pausing_ = true; } | ||||
| 
 | ||||
| 		// 继续角色更新
 | ||||
| 		inline void				ResumeUpdating()								{ update_pausing_ = false; } | ||||
| 
 | ||||
| 		// 角色更新是否暂停
 | ||||
| 		inline bool				IsUpdatePausing() const							{ return update_pausing_; } | ||||
| 
 | ||||
| 		// 设置更新时的回调函数
 | ||||
| 		inline void				SetCallbackOnUpdate(UpdateCallback const& cb)	{ cb_update_ = cb; } | ||||
| 
 | ||||
| 		// 获取更新时的回调函数
 | ||||
| 		inline UpdateCallback	GetCallbackOnUpdate() const						{ return cb_update_; } | ||||
| 
 | ||||
| 		// 渲染角色边界
 | ||||
| 		inline void				ShowBorder(bool show)							{ show_border_ = show; } | ||||
| 
 | ||||
| 	protected: | ||||
| 		virtual void Update(Duration dt); | ||||
| 
 | ||||
|  | @ -439,4 +421,219 @@ namespace kiwano | |||
| 		mutable Matrix3x2	transform_matrix_inverse_; | ||||
| 	}; | ||||
| 
 | ||||
| 	inline void Actor::OnUpdate(Duration dt) | ||||
| 	{ | ||||
| 		KGE_NOT_USED(dt); | ||||
| 	} | ||||
| 
 | ||||
| 	inline void Actor::OnRender(RenderTarget* rt) | ||||
| 	{ | ||||
| 		KGE_NOT_USED(rt); | ||||
| 	} | ||||
| 
 | ||||
| 	inline bool Actor::IsVisible() const | ||||
| 	{ | ||||
| 		return visible_; | ||||
| 	} | ||||
| 
 | ||||
| 	inline bool Actor::IsResponsible() const | ||||
| 	{ | ||||
| 		return responsible_; | ||||
| 	} | ||||
| 
 | ||||
| 	inline bool Actor::IsCascadeOpacityEnabled() const | ||||
| 	{ | ||||
| 		return cascade_opacity_; | ||||
| 	} | ||||
| 
 | ||||
| 	inline size_t Actor::GetHashName() const | ||||
| 	{ | ||||
| 		return hash_name_; | ||||
| 	} | ||||
| 
 | ||||
| 	inline int Actor::GetZOrder() const | ||||
| 	{ | ||||
| 		return z_order_; | ||||
| 	} | ||||
| 
 | ||||
| 	inline Point const& Actor::GetPosition() const | ||||
| 	{ | ||||
| 		return transform_.position; | ||||
| 	} | ||||
| 
 | ||||
| 	inline float Actor::GetPositionX() const | ||||
| 	{ | ||||
| 		return GetPosition().x; | ||||
| 	} | ||||
| 
 | ||||
| 	inline float Actor::GetPositionY() const | ||||
| 	{ | ||||
| 		return GetPosition().y; | ||||
| 	} | ||||
| 
 | ||||
| 	inline Point const& Actor::GetScale() const | ||||
| 	{ | ||||
| 		return transform_.scale; | ||||
| 	} | ||||
| 
 | ||||
| 	inline float Actor::GetScaleX() const | ||||
| 	{ | ||||
| 		return GetScale().x; | ||||
| 	} | ||||
| 
 | ||||
| 	inline float Actor::GetScaleY() const | ||||
| 	{ | ||||
| 		return GetScale().y; | ||||
| 	} | ||||
| 
 | ||||
| 	inline Point const& Actor::GetSkew() const | ||||
| 	{ | ||||
| 		return transform_.skew; | ||||
| 	} | ||||
| 
 | ||||
| 	inline float Actor::GetSkewX() const | ||||
| 	{ | ||||
| 		return GetSkew().x; | ||||
| 	} | ||||
| 
 | ||||
| 	inline float Actor::GetSkewY() const | ||||
| 	{ | ||||
| 		return GetSkew().y; | ||||
| 	} | ||||
| 
 | ||||
| 	inline float Actor::GetRotation() const | ||||
| 	{ | ||||
| 		return transform_.rotation; | ||||
| 	} | ||||
| 
 | ||||
| 	inline float Actor::GetWidth() const | ||||
| 	{ | ||||
| 		return GetSize().x; | ||||
| 	} | ||||
| 
 | ||||
| 	inline float Actor::GetHeight() const | ||||
| 	{ | ||||
| 		return GetSize().y; | ||||
| 	} | ||||
| 
 | ||||
| 	inline Size const& Actor::GetSize() const | ||||
| 	{ | ||||
| 		return size_; | ||||
| 	} | ||||
| 
 | ||||
| 	inline float Actor::GetScaledWidth() const | ||||
| 	{ | ||||
| 		return GetWidth() * GetScaleX(); | ||||
| 	} | ||||
| 
 | ||||
| 	inline float Actor::GetScaledHeight() const | ||||
| 	{ | ||||
| 		return GetHeight() * GetScaleY(); | ||||
| 	} | ||||
| 
 | ||||
| 	inline Size Actor::GetScaledSize() const | ||||
| 	{ | ||||
| 		return Size{ GetScaledWidth(), GetScaledHeight() }; | ||||
| 	} | ||||
| 
 | ||||
| 	inline Point const& Actor::GetAnchor() const | ||||
| 	{ | ||||
| 		return anchor_; | ||||
| 	} | ||||
| 
 | ||||
| 	inline float Actor::GetAnchorX() const | ||||
| 	{ | ||||
| 		return GetAnchor().x; | ||||
| 	} | ||||
| 
 | ||||
| 	inline float Actor::GetAnchorY() const | ||||
| 	{ | ||||
| 		return GetAnchor().y; | ||||
| 	} | ||||
| 
 | ||||
| 	inline float Actor::GetOpacity() const | ||||
| 	{ | ||||
| 		return opacity_; | ||||
| 	} | ||||
| 
 | ||||
| 	inline float Actor::GetDisplayedOpacity() const | ||||
| 	{ | ||||
| 		return displayed_opacity_; | ||||
| 	} | ||||
| 
 | ||||
| 	inline Transform Actor::GetTransform() const | ||||
| 	{ | ||||
| 		return transform_; | ||||
| 	} | ||||
| 
 | ||||
| 	inline Actor* Actor::GetParent() const | ||||
| 	{ | ||||
| 		return parent_; | ||||
| 	} | ||||
| 
 | ||||
| 	inline Stage* Actor::GetStage() const | ||||
| 	{ | ||||
| 		return stage_; | ||||
| 	} | ||||
| 
 | ||||
| 	inline void Actor::PauseUpdating() | ||||
| 	{ | ||||
| 		update_pausing_ = true; | ||||
| 	} | ||||
| 
 | ||||
| 	inline void Actor::ResumeUpdating() | ||||
| 	{ | ||||
| 		update_pausing_ = false; | ||||
| 	} | ||||
| 
 | ||||
| 	inline bool Actor::IsUpdatePausing() const | ||||
| 	{ | ||||
| 		return update_pausing_; | ||||
| 	} | ||||
| 
 | ||||
| 	inline void Actor::SetCallbackOnUpdate(UpdateCallback const& cb) | ||||
| 	{ | ||||
| 		cb_update_ = cb; | ||||
| 	} | ||||
| 
 | ||||
| 	inline Actor::UpdateCallback Actor::GetCallbackOnUpdate() const | ||||
| 	{ | ||||
| 		return cb_update_; | ||||
| 	} | ||||
| 
 | ||||
| 	inline void Actor::ShowBorder(bool show) | ||||
| 	{ | ||||
| 		show_border_ = show; | ||||
| 	} | ||||
| 
 | ||||
| 	inline void Actor::SetPosition(float x, float y) | ||||
| 	{ | ||||
| 		SetPosition(Point{ x, y }); | ||||
| 	} | ||||
| 
 | ||||
| 	inline void Actor::Move(float vx, float vy) | ||||
| 	{ | ||||
| 		Move(Vec2{ vx, vy }); | ||||
| 	} | ||||
| 
 | ||||
| 	inline void Actor::SetScale(float scalex, float scaley) | ||||
| 	{ | ||||
| 		SetScale(Vec2{ scalex, scaley }); | ||||
| 	} | ||||
| 
 | ||||
| 	inline void Actor::SetAnchor(float anchorx, float anchory) | ||||
| 	{ | ||||
| 		SetAnchor(Vec2{ anchorx, anchory }); | ||||
| 	} | ||||
| 
 | ||||
| 	inline void Actor::SetSize(float width, float height) | ||||
| 	{ | ||||
| 		SetSize(Size{ width, height }); | ||||
| 	} | ||||
| 
 | ||||
| 	inline void Actor::SetSkew(float skewx, float skewy) | ||||
| 	{ | ||||
| 		SetSkew(Vec2{ skewx, skewy }); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -19,7 +19,7 @@ | |||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #include <kiwano/2d/Canvas.h> | ||||
| #include <kiwano/base/Logger.h> | ||||
| #include <kiwano/core/Logger.h> | ||||
| #include <kiwano/renderer/Renderer.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
|  |  | |||
|  | @ -66,8 +66,8 @@ namespace kiwano | |||
| 		style.line_spacing = 20.f; | ||||
| 		debug_text_->SetStyle(style); | ||||
| 
 | ||||
| 		AddListener(Event::MouseHover, [=](const Event&) { SetOpacity(0.4f); }); | ||||
| 		AddListener(Event::MouseOut, [=](const Event&) { SetOpacity(1.f); }); | ||||
| 		AddListener(event::MouseHover, [=](Event*) { SetOpacity(0.4f); }); | ||||
| 		AddListener(event::MouseOut, [=](Event*) { SetOpacity(1.f); }); | ||||
| 	} | ||||
| 
 | ||||
| 	DebugActor::~DebugActor() | ||||
|  | @ -87,7 +87,7 @@ namespace kiwano | |||
| 		KGE_NOT_USED(dt); | ||||
| 
 | ||||
| 		frame_time_.push_back(Time::Now()); | ||||
| 		while (frame_time_.back() - frame_time_.front() >= time::Sec) | ||||
| 		while (frame_time_.back() - frame_time_.front() >= Duration::Second) | ||||
| 		{ | ||||
| 			frame_time_.erase(frame_time_.begin()); | ||||
| 		} | ||||
|  |  | |||
|  | @ -19,7 +19,7 @@ | |||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #pragma once | ||||
| #include <kiwano/base/ObjectBase.h> | ||||
| #include <kiwano/core/ObjectBase.h> | ||||
| #include <kiwano/renderer/Texture.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
|  |  | |||
|  | @ -20,7 +20,7 @@ | |||
| 
 | ||||
| #include <kiwano/2d/FrameSequence.h> | ||||
| #include <kiwano/2d/Frame.h> | ||||
| #include <kiwano/base/Logger.h> | ||||
| #include <kiwano/core/Logger.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
|  |  | |||
|  | @ -19,7 +19,7 @@ | |||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #include <kiwano/2d/GifSprite.h> | ||||
| #include <kiwano/base/win32/helper.h> | ||||
| #include <kiwano/core/win32/helper.h> | ||||
| #include <kiwano/renderer/TextureCache.h> | ||||
| #include <kiwano/renderer/Renderer.h> | ||||
| 
 | ||||
|  |  | |||
|  | @ -20,7 +20,7 @@ | |||
| 
 | ||||
| #pragma once | ||||
| #include <kiwano/2d/Actor.h> | ||||
| #include <kiwano/base/Resource.h> | ||||
| #include <kiwano/core/Resource.h> | ||||
| #include <kiwano/renderer/RenderTarget.h> | ||||
| #include <kiwano/renderer/GifImage.h> | ||||
| 
 | ||||
|  |  | |||
|  | @ -29,14 +29,14 @@ namespace kiwano | |||
| 	{ | ||||
| 		auto handler = Closure(this, &Layer::HandleMessages); | ||||
| 
 | ||||
| 		AddListener(Event::MouseBtnDown, handler); | ||||
| 		AddListener(Event::MouseBtnUp, handler); | ||||
| 		AddListener(Event::MouseMove, handler); | ||||
| 		AddListener(Event::MouseWheel, handler); | ||||
| 		AddListener(event::MouseDown, handler); | ||||
| 		AddListener(event::MouseUp, handler); | ||||
| 		AddListener(event::MouseMove, handler); | ||||
| 		AddListener(event::MouseWheel, handler); | ||||
| 
 | ||||
| 		AddListener(Event::KeyDown, handler); | ||||
| 		AddListener(Event::KeyUp, handler); | ||||
| 		AddListener(Event::Char, handler); | ||||
| 		AddListener(event::KeyDown, handler); | ||||
| 		AddListener(event::KeyUp, handler); | ||||
| 		AddListener(event::KeyChar, handler); | ||||
| 	} | ||||
| 
 | ||||
| 	Layer::~Layer() | ||||
|  | @ -64,7 +64,7 @@ namespace kiwano | |||
| 		area_.SetMaskTransform(transform); | ||||
| 	} | ||||
| 
 | ||||
| 	void Layer::Dispatch(Event& evt) | ||||
| 	void Layer::Dispatch(Event* evt) | ||||
| 	{ | ||||
| 		if (!IsVisible()) | ||||
| 			return; | ||||
|  | @ -91,31 +91,42 @@ namespace kiwano | |||
| 		rt->PopLayer(); | ||||
| 	} | ||||
| 
 | ||||
| 	void Layer::HandleMessages(Event const& evt) | ||||
| 	void Layer::HandleMessages(Event* evt) | ||||
| 	{ | ||||
| 		switch (evt.type) | ||||
| 		if (evt->type == event::MouseDown) | ||||
| 		{ | ||||
| 		case Event::MouseBtnDown: | ||||
| 			OnMouseButtonDown(evt.mouse.button, Point{ evt.mouse.x, evt.mouse.y }); | ||||
| 			break; | ||||
| 		case Event::MouseBtnUp: | ||||
| 			OnMouseButtonUp(evt.mouse.button, Point{ evt.mouse.x, evt.mouse.y }); | ||||
| 			break; | ||||
| 		case Event::MouseMove: | ||||
| 			OnMouseMoved(Point{ evt.mouse.x, evt.mouse.y }); | ||||
| 			break; | ||||
| 		case Event::MouseWheel: | ||||
| 			OnMouseWheel(evt.mouse.wheel); | ||||
| 			break; | ||||
| 		case Event::KeyDown: | ||||
| 			OnKeyDown(evt.key.code); | ||||
| 			break; | ||||
| 		case Event::KeyUp: | ||||
| 			OnKeyUp(evt.key.code); | ||||
| 			break; | ||||
| 		case Event::Char: | ||||
| 			OnChar(evt.key.c); | ||||
| 			break; | ||||
| 			auto real_evt = evt->SafeCast<MouseDownEvent>(); | ||||
| 			OnMouseButtonDown(real_evt->button, real_evt->pos); | ||||
| 		} | ||||
| 		else if (evt->type == event::MouseUp) | ||||
| 		{ | ||||
| 			auto real_evt = evt->SafeCast<MouseUpEvent>(); | ||||
| 			OnMouseButtonUp(real_evt->button, real_evt->pos); | ||||
| 		} | ||||
| 		else if (evt->type == event::MouseMove) | ||||
| 		{ | ||||
| 			auto real_evt = evt->SafeCast<MouseMoveEvent>(); | ||||
| 			OnMouseMoved(real_evt->pos); | ||||
| 		} | ||||
| 		else if (evt->type == event::MouseWheel) | ||||
| 		{ | ||||
| 			auto real_evt = evt->SafeCast<MouseWheelEvent>(); | ||||
| 			OnMouseWheel(real_evt->wheel); | ||||
| 		} | ||||
| 		else if (evt->type == event::KeyDown) | ||||
| 		{ | ||||
| 			auto real_evt = evt->SafeCast<KeyDownEvent>(); | ||||
| 			OnKeyDown(real_evt->code); | ||||
| 		} | ||||
| 		else if (evt->type == event::KeyUp) | ||||
| 		{ | ||||
| 			auto real_evt = evt->SafeCast<KeyUpEvent>(); | ||||
| 			OnKeyUp(real_evt->code); | ||||
| 		} | ||||
| 		else if (evt->type == event::KeyChar) | ||||
| 		{ | ||||
| 			auto real_evt = evt->SafeCast<KeyCharEvent>(); | ||||
| 			OnChar(real_evt->value); | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
|  |  | |||
|  | @ -34,8 +34,8 @@ namespace kiwano | |||
| 		virtual ~Layer(); | ||||
| 
 | ||||
| 		// 重载下列函数以获取图层事件
 | ||||
| 		virtual void OnMouseButtonDown(int btn, Point const& p) {} | ||||
| 		virtual void OnMouseButtonUp(int btn, Point const& p) {} | ||||
| 		virtual void OnMouseButtonDown(MouseButton::Value btn, Point const& p) {} | ||||
| 		virtual void OnMouseButtonUp(MouseButton::Value btn, Point const& p) {} | ||||
| 		virtual void OnMouseMoved(Point const& p) {} | ||||
| 		virtual void OnMouseWheel(float wheel) {} | ||||
| 		virtual void OnKeyDown(int key) {} | ||||
|  | @ -67,12 +67,12 @@ namespace kiwano | |||
| 		inline LayerArea const& GetArea() const		{ return area_; } | ||||
| 
 | ||||
| 	public: | ||||
| 		void Dispatch(Event& evt) override; | ||||
| 		void Dispatch(Event* evt) override; | ||||
| 
 | ||||
| 	protected: | ||||
| 		void Render(RenderTarget* rt) override; | ||||
| 
 | ||||
| 		void HandleMessages(Event const& evt); | ||||
| 		void HandleMessages(Event* evt); | ||||
| 
 | ||||
| 	protected: | ||||
| 		bool		swallow_; | ||||
|  |  | |||
|  | @ -19,7 +19,7 @@ | |||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #include <kiwano/2d/ShapeActor.h> | ||||
| #include <kiwano/base/Logger.h> | ||||
| #include <kiwano/core/Logger.h> | ||||
| #include <kiwano/renderer/Renderer.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
|  |  | |||
|  | @ -19,7 +19,7 @@ | |||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #include <kiwano/2d/Stage.h> | ||||
| #include <kiwano/base/Logger.h> | ||||
| #include <kiwano/core/Logger.h> | ||||
| #include <kiwano/renderer/Renderer.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
|  |  | |||
|  | @ -19,7 +19,7 @@ | |||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #include <kiwano/2d/Text.h> | ||||
| #include <kiwano/base/Logger.h> | ||||
| #include <kiwano/core/Logger.h> | ||||
| #include <kiwano/renderer/Renderer.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
|  |  | |||
|  | @ -21,8 +21,8 @@ | |||
| #include <kiwano/2d/Transition.h> | ||||
| #include <kiwano/2d/Actor.h> | ||||
| #include <kiwano/2d/Stage.h> | ||||
| #include <kiwano/base/Window.h> | ||||
| #include <kiwano/base/Logger.h> | ||||
| #include <kiwano/platform/Window.h> | ||||
| #include <kiwano/core/Logger.h> | ||||
| #include <kiwano/renderer/Renderer.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
|  |  | |||
|  | @ -36,42 +36,33 @@ namespace kiwano | |||
| 		friend IntrusiveList<ActionPtr>; | ||||
| 
 | ||||
| 	public: | ||||
| 		enum class Status | ||||
| 		{ | ||||
| 			NotStarted, | ||||
| 			Delayed, | ||||
| 			Started, | ||||
| 			Done, | ||||
| 			Removeable | ||||
| 		}; | ||||
| 
 | ||||
| 		Action(); | ||||
| 
 | ||||
| 		virtual ~Action(); | ||||
| 
 | ||||
| 		// 继续动作
 | ||||
| 		inline void Resume()										{ running_ = true; } | ||||
| 		void Resume(); | ||||
| 
 | ||||
| 		// 暂停动作
 | ||||
| 		inline void Pause()											{ running_ = false; } | ||||
| 		void Pause(); | ||||
| 
 | ||||
| 		// 停止动作
 | ||||
| 		inline void Stop()											{ status_ = Status::Removeable; } | ||||
| 		void Stop(); | ||||
| 
 | ||||
| 		// 设置动作延时
 | ||||
| 		inline void SetDelay(Duration delay)						{ delay_ = delay; } | ||||
| 		void SetDelay(Duration delay); | ||||
| 
 | ||||
| 		// 设置循环次数 (-1 为永久循环)
 | ||||
| 		inline void SetLoops(int loops)								{ loops_ = loops; } | ||||
| 		void SetLoops(int loops); | ||||
| 
 | ||||
| 		// 动作结束时移除目标角色
 | ||||
| 		inline void RemoveTargetWhenDone()							{ detach_target_ = true; } | ||||
| 		void RemoveTargetWhenDone(); | ||||
| 
 | ||||
| 		// 设置动作结束时的回调函数
 | ||||
| 		inline void SetDoneCallback(ActionCallback const& cb)		{ cb_done_ = cb; } | ||||
| 		void SetDoneCallback(ActionCallback const& cb); | ||||
| 
 | ||||
| 		// 设置动作循环结束时的回调函数
 | ||||
| 		inline void SetLoopDoneCallback(ActionCallback const& cb)	{ cb_loop_done_ = cb; } | ||||
| 		void SetLoopDoneCallback(ActionCallback const& cb); | ||||
| 
 | ||||
| 		// 获取动作的拷贝
 | ||||
| 		virtual ActionPtr Clone() const = 0; | ||||
|  | @ -79,25 +70,15 @@ namespace kiwano | |||
| 		// 获取动作的倒转
 | ||||
| 		virtual ActionPtr Reverse() const = 0; | ||||
| 
 | ||||
| 		inline void Done()											{ status_ = Status::Done; } | ||||
| 		bool IsRunning() const; | ||||
| 
 | ||||
| 		inline Status GetStatus() const								{ return status_; } | ||||
| 		int GetLoops() const; | ||||
| 
 | ||||
| 		inline bool IsRunning() const								{ return running_; } | ||||
| 		Duration GetDelay() const; | ||||
| 
 | ||||
| 		inline bool IsDone() const									{ return status_ == Status::Done || status_ == Status::Removeable; } | ||||
| 		ActionCallback GetDoneCallback() const; | ||||
| 
 | ||||
| 		inline bool IsRemoveable() const							{ return status_ == Status::Removeable; } | ||||
| 
 | ||||
| 		inline int GetLoops() const									{ return loops_; } | ||||
| 
 | ||||
| 		inline Duration GetDelay() const							{ return delay_; } | ||||
| 
 | ||||
| 		inline Duration GetElapsed() const							{ return elapsed_; } | ||||
| 
 | ||||
| 		inline ActionCallback GetDoneCallback() const				{ return cb_done_; } | ||||
| 
 | ||||
| 		inline ActionCallback GetLoopDoneCallback() const			{ return cb_loop_done_; } | ||||
| 		ActionCallback GetLoopDoneCallback() const; | ||||
| 
 | ||||
| 	protected: | ||||
| 		virtual void Init(ActorPtr target); | ||||
|  | @ -110,7 +91,28 @@ namespace kiwano | |||
| 
 | ||||
| 		void Restart(ActorPtr target); | ||||
| 
 | ||||
| 	protected: | ||||
| 		enum class Status | ||||
| 		{ | ||||
| 			NotStarted, | ||||
| 			Delayed, | ||||
| 			Started, | ||||
| 			Done, | ||||
| 			Removeable | ||||
| 		}; | ||||
| 
 | ||||
| 		Status GetStatus() const; | ||||
| 
 | ||||
| 		Duration GetElapsed() const; | ||||
| 
 | ||||
| 		int GetLoopsDone() const; | ||||
| 
 | ||||
| 		void Done(); | ||||
| 
 | ||||
| 		bool IsDone() const; | ||||
| 
 | ||||
| 		bool IsRemoveable() const; | ||||
| 
 | ||||
| 	private: | ||||
| 		Status			status_; | ||||
| 		bool			running_; | ||||
| 		bool			detach_target_; | ||||
|  | @ -121,4 +123,100 @@ namespace kiwano | |||
| 		ActionCallback	cb_done_; | ||||
| 		ActionCallback	cb_loop_done_; | ||||
| 	}; | ||||
| 
 | ||||
| 
 | ||||
| 	inline void Action::Resume() | ||||
| 	{ | ||||
| 		running_ = true; | ||||
| 	} | ||||
| 
 | ||||
| 	inline void Action::Pause() | ||||
| 	{ | ||||
| 		running_ = false; | ||||
| 	} | ||||
| 
 | ||||
| 	inline void Action::Stop() | ||||
| 	{ | ||||
| 		Done(); | ||||
| 	} | ||||
| 
 | ||||
| 	inline void Action::SetDelay(Duration delay) | ||||
| 	{ | ||||
| 		delay_ = delay; | ||||
| 	} | ||||
| 
 | ||||
| 	inline void Action::SetLoops(int loops) | ||||
| 	{ | ||||
| 		loops_ = loops; | ||||
| 	} | ||||
| 
 | ||||
| 	inline void Action::RemoveTargetWhenDone() | ||||
| 	{ | ||||
| 		detach_target_ = true; | ||||
| 	} | ||||
| 
 | ||||
| 	inline void Action::SetDoneCallback(ActionCallback const& cb) | ||||
| 	{ | ||||
| 		cb_done_ = cb; | ||||
| 	} | ||||
| 
 | ||||
| 	inline void Action::SetLoopDoneCallback(ActionCallback const& cb) | ||||
| 	{ | ||||
| 		cb_loop_done_ = cb; | ||||
| 	} | ||||
| 
 | ||||
| 	inline void Action::Done() | ||||
| 	{ | ||||
| 		status_ = Status::Done; | ||||
| 	} | ||||
| 
 | ||||
| 	inline Action::Status Action::GetStatus() const | ||||
| 	{ | ||||
| 		return status_; | ||||
| 	} | ||||
| 
 | ||||
| 	inline bool Action::IsRunning() const | ||||
| 	{ | ||||
| 		return running_; | ||||
| 	} | ||||
| 
 | ||||
| 	inline bool Action::IsDone() const | ||||
| 	{ | ||||
| 		return status_ == Status::Done || status_ == Status::Removeable; | ||||
| 	} | ||||
| 
 | ||||
| 	inline bool Action::IsRemoveable() const | ||||
| 	{ | ||||
| 		return status_ == Status::Removeable; | ||||
| 	} | ||||
| 
 | ||||
| 	inline int Action::GetLoops() const | ||||
| 	{ | ||||
| 		return loops_; | ||||
| 	} | ||||
| 
 | ||||
| 	inline Duration Action::GetDelay() const | ||||
| 	{ | ||||
| 		return delay_; | ||||
| 	} | ||||
| 
 | ||||
| 	inline Duration Action::GetElapsed() const | ||||
| 	{ | ||||
| 		return elapsed_; | ||||
| 	} | ||||
| 
 | ||||
| 	inline int Action::GetLoopsDone() const | ||||
| 	{ | ||||
| 		return loops_done_; | ||||
| 	} | ||||
| 
 | ||||
| 	inline ActionCallback Action::GetDoneCallback() const | ||||
| 	{ | ||||
| 		return cb_done_; | ||||
| 	} | ||||
| 
 | ||||
| 	inline ActionCallback Action::GetLoopDoneCallback() const | ||||
| 	{ | ||||
| 		return cb_loop_done_; | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -29,12 +29,12 @@ namespace kiwano | |||
| 
 | ||||
| 	ActionPtr ActionDelay::Clone() const | ||||
| 	{ | ||||
| 		return new ActionDelay(delay_); | ||||
| 		return new ActionDelay(GetDelay()); | ||||
| 	} | ||||
| 
 | ||||
| 	ActionPtr ActionDelay::Reverse() const | ||||
| 	{ | ||||
| 		return new ActionDelay(delay_); | ||||
| 		return new ActionDelay(GetDelay()); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -20,7 +20,7 @@ | |||
| 
 | ||||
| #include <kiwano/2d/action/ActionGroup.h> | ||||
| #include <kiwano/2d/Actor.h> | ||||
| #include <kiwano/base/Logger.h> | ||||
| #include <kiwano/core/Logger.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
|  |  | |||
|  | @ -30,71 +30,71 @@ namespace kiwano | |||
| 	struct ActionHelper | ||||
| 	{ | ||||
| 		// 设置循环次数
 | ||||
| 		inline ActionHelper& SetLoops(int loops)							{ base->SetLoops(loops); return (*this); } | ||||
| 		inline ActionHelper& SetLoops(int loops)							{ core->SetLoops(loops); return (*this); } | ||||
| 
 | ||||
| 		// 设置动作延迟
 | ||||
| 		inline ActionHelper& SetDelay(Duration delay)						{ base->SetDelay(delay); return (*this); } | ||||
| 		inline ActionHelper& SetDelay(Duration delay)						{ core->SetDelay(delay); return (*this); } | ||||
| 
 | ||||
| 		// 设置动作结束回调函数
 | ||||
| 		inline ActionHelper& SetDoneCallback(ActionCallback const& cb)		{ base->SetDoneCallback(cb); return (*this); } | ||||
| 		inline ActionHelper& SetDoneCallback(ActionCallback const& cb)		{ core->SetDoneCallback(cb); return (*this); } | ||||
| 
 | ||||
| 		// 设置动作循环结束时的回调函数
 | ||||
| 		inline ActionHelper& SetLoopDoneCallback(ActionCallback const& cb)	{ base->SetLoopDoneCallback(cb); return (*this); } | ||||
| 		inline ActionHelper& SetLoopDoneCallback(ActionCallback const& cb)	{ core->SetLoopDoneCallback(cb); return (*this); } | ||||
| 
 | ||||
| 		// 动作结束时移除目标角色
 | ||||
| 		inline ActionHelper& RemoveTargetWhenDone()							{ base->RemoveTargetWhenDone(); return (*this); } | ||||
| 		inline ActionHelper& RemoveTargetWhenDone()							{ core->RemoveTargetWhenDone(); return (*this); } | ||||
| 
 | ||||
| 		// 设置名称
 | ||||
| 		inline ActionHelper& SetName(String const& name)					{ base->SetName(name); return (*this); } | ||||
| 		inline ActionHelper& SetName(String const& name)					{ core->SetName(name); return (*this); } | ||||
| 
 | ||||
| 		// 获取指针
 | ||||
| 		inline ActionPtr Get() const										{ return base; } | ||||
| 		inline ActionPtr Get() const										{ return core; } | ||||
| 
 | ||||
| 		inline ActionHelper(ActionPtr base)									: base(base) {} | ||||
| 		inline ActionHelper(ActionPtr core)									: core(core) {} | ||||
| 
 | ||||
| 		inline operator ActionPtr() const									{ return base; } | ||||
| 		inline operator ActionPtr() const									{ return core; } | ||||
| 
 | ||||
| 	protected: | ||||
| 		ActionPtr base; | ||||
| 		ActionPtr core; | ||||
| 	}; | ||||
| 
 | ||||
| 	struct TweenHelper | ||||
| 	{ | ||||
| 		// 设置动画持续时长
 | ||||
| 		inline TweenHelper& SetDuration(Duration dur)						{ base->SetDuration(dur); return (*this); } | ||||
| 		inline TweenHelper& SetDuration(Duration dur)						{ core->SetDuration(dur); return (*this); } | ||||
| 
 | ||||
| 		// 设置循环次数
 | ||||
| 		inline TweenHelper& SetLoops(int loops)							{ base->SetLoops(loops); return (*this); } | ||||
| 		inline TweenHelper& SetLoops(int loops)							{ core->SetLoops(loops); return (*this); } | ||||
| 
 | ||||
| 		// 设置缓动函数
 | ||||
| 		inline TweenHelper& SetEaseFunc(EaseFunc ease)						{ base->SetEaseFunc(ease); return (*this); } | ||||
| 		inline TweenHelper& SetEaseFunc(EaseFunc ease)						{ core->SetEaseFunc(ease); return (*this); } | ||||
| 
 | ||||
| 		// 设置动作延迟
 | ||||
| 		inline TweenHelper& SetDelay(Duration delay)						{ base->SetDelay(delay); return (*this); } | ||||
| 		inline TweenHelper& SetDelay(Duration delay)						{ core->SetDelay(delay); return (*this); } | ||||
| 
 | ||||
| 		// 设置动作结束回调函数
 | ||||
| 		inline TweenHelper& SetDoneCallback(ActionCallback const& cb)		{ base->SetDoneCallback(cb); return (*this); } | ||||
| 		inline TweenHelper& SetDoneCallback(ActionCallback const& cb)		{ core->SetDoneCallback(cb); return (*this); } | ||||
| 
 | ||||
| 		// 设置动作循环结束时的回调函数
 | ||||
| 		inline TweenHelper& SetLoopDoneCallback(ActionCallback const& cb)	{ base->SetLoopDoneCallback(cb); return (*this); } | ||||
| 		inline TweenHelper& SetLoopDoneCallback(ActionCallback const& cb)	{ core->SetLoopDoneCallback(cb); return (*this); } | ||||
| 
 | ||||
| 		// 动作结束时移除目标角色
 | ||||
| 		inline TweenHelper& RemoveTargetWhenDone()							{ base->RemoveTargetWhenDone(); return (*this); } | ||||
| 		inline TweenHelper& RemoveTargetWhenDone()							{ core->RemoveTargetWhenDone(); return (*this); } | ||||
| 
 | ||||
| 		// 设置名称
 | ||||
| 		inline TweenHelper& SetName(String const& name)						{ base->SetName(name); return (*this); } | ||||
| 		inline TweenHelper& SetName(String const& name)						{ core->SetName(name); return (*this); } | ||||
| 
 | ||||
| 		// 获取指针
 | ||||
| 		inline ActionTweenPtr Get() const									{ return base; } | ||||
| 		inline ActionTweenPtr Get() const									{ return core; } | ||||
| 		 | ||||
| 		inline TweenHelper(ActionTweenPtr base)								: base(base) {} | ||||
| 		inline TweenHelper(ActionTweenPtr core)								: core(core) {} | ||||
| 
 | ||||
| 		inline operator ActionPtr() const									{ return base; } | ||||
| 		inline operator ActionPtr() const									{ return core; } | ||||
| 
 | ||||
| 		inline operator ActionTweenPtr() const								{ return base; } | ||||
| 		inline operator ActionTweenPtr() const								{ return core; } | ||||
| 
 | ||||
| 	protected: | ||||
| 		ActionTweenPtr base; | ||||
| 		ActionTweenPtr core; | ||||
| 	}; | ||||
| 
 | ||||
| 	// Tween actions helper
 | ||||
|  |  | |||
|  | @ -20,7 +20,7 @@ | |||
| 
 | ||||
| #include <kiwano/2d/action/ActionManager.h> | ||||
| #include <kiwano/2d/Actor.h> | ||||
| #include <kiwano/base/Logger.h> | ||||
| #include <kiwano/core/Logger.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
|  |  | |||
|  | @ -108,15 +108,15 @@ namespace kiwano | |||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			Duration elapsed = elapsed_ - delay_; | ||||
| 			Duration elapsed = GetElapsed() - GetDelay(); | ||||
| 			float loops_done = elapsed / dur_; | ||||
| 
 | ||||
| 			while (loops_done_ < static_cast<int>(loops_done)) | ||||
| 			while (GetLoopsDone() < static_cast<int>(loops_done)) | ||||
| 			{ | ||||
| 				Complete(target);	// loops_done_++
 | ||||
| 			} | ||||
| 
 | ||||
| 			percent = (status_ == Status::Done) ? 1.f : (loops_done - static_cast<float>(loops_done_)); | ||||
| 			percent = (GetStatus() == Status::Done) ? 1.f : (loops_done - static_cast<float>(GetLoopsDone())); | ||||
| 		} | ||||
| 
 | ||||
| 		if (ease_func_) | ||||
|  |  | |||
|  | @ -20,7 +20,7 @@ | |||
| 
 | ||||
| #pragma once | ||||
| #include <kiwano/2d/action/Action.h> | ||||
| #include <kiwano/base/Logger.h> | ||||
| #include <kiwano/core/Logger.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
|  |  | |||
|  | @ -19,11 +19,11 @@ | |||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #pragma once | ||||
| #include <kiwano/core/core.h> | ||||
| #include <kiwano/base/time.h> | ||||
| #include <kiwano/base/RefCounter.hpp> | ||||
| #include <kiwano/base/SmartPtr.hpp> | ||||
| #include <kiwano/base/ObjectBase.h> | ||||
| #include <kiwano/common/common.h> | ||||
| #include <kiwano/core/time.h> | ||||
| #include <kiwano/core/RefCounter.hpp> | ||||
| #include <kiwano/core/SmartPtr.hpp> | ||||
| #include <kiwano/core/ObjectBase.h> | ||||
| #include <kiwano/math/math.h> | ||||
| #include <kiwano/renderer/Color.h> | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,181 +0,0 @@ | |||
| // Copyright (c) 2016-2018 Kiwano - Nomango
 | ||||
| // 
 | ||||
| // Permission is hereby granted, free of charge, to any person obtaining a copy
 | ||||
| // of this software and associated documentation files (the "Software"), to deal
 | ||||
| // in the Software without restriction, including without limitation the rights
 | ||||
| // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | ||||
| // copies of the Software, and to permit persons to whom the Software is
 | ||||
| // furnished to do so, subject to the following conditions:
 | ||||
| // 
 | ||||
| // The above copyright notice and this permission notice shall be included in
 | ||||
| // all copies or substantial portions of the Software.
 | ||||
| // 
 | ||||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | ||||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | ||||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | ||||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | ||||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | ||||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | ||||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #pragma once | ||||
| #include <kiwano/base/keys.hpp> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
| 	// 事件类型
 | ||||
| 	typedef int EventType; | ||||
| 
 | ||||
| 	// 鼠标事件
 | ||||
| 	struct MouseEvent | ||||
| 	{ | ||||
| 		float x; | ||||
| 		float y; | ||||
| 		bool left_btn_down;		// 左键是否按下
 | ||||
| 		bool right_btn_down;	// 右键是否按下
 | ||||
| 
 | ||||
| 		union | ||||
| 		{ | ||||
| 			struct	// Events::MouseDown | Events::MouseUp | Events::MouseClick | ||||
| 			{ | ||||
| 				MouseButton::Value button; | ||||
| 			}; | ||||
| 
 | ||||
| 			struct	// Events::MouseWheel | ||||
| 			{ | ||||
| 				float wheel; | ||||
| 			}; | ||||
| 		}; | ||||
| 
 | ||||
| 		static bool Check(EventType type); | ||||
| 	}; | ||||
| 
 | ||||
| 	// 键盘事件
 | ||||
| 	struct KeyboardEvent | ||||
| 	{ | ||||
| 		int count; | ||||
| 		union | ||||
| 		{ | ||||
| 			struct	// Events::KeyDown | Events::KeyUp | ||||
| 			{ | ||||
| 				KeyCode::Value code; | ||||
| 			}; | ||||
| 
 | ||||
| 			struct	// Events::Char | ||||
| 			{ | ||||
| 				char c; | ||||
| 			}; | ||||
| 		}; | ||||
| 
 | ||||
| 		static bool Check(EventType type); | ||||
| 	}; | ||||
| 
 | ||||
| 	// 窗口事件
 | ||||
| 	struct WindowEvent | ||||
| 	{ | ||||
| 		union | ||||
| 		{ | ||||
| 			struct		// Events::WindowMoved | ||||
| 			{ | ||||
| 				int x; | ||||
| 				int y; | ||||
| 			}; | ||||
| 
 | ||||
| 			struct		// Events::WindowResized | ||||
| 			{ | ||||
| 				int width; | ||||
| 				int height; | ||||
| 			}; | ||||
| 
 | ||||
| 			struct		// Events::WindowFocusChanged | ||||
| 			{ | ||||
| 				bool focus; | ||||
| 			}; | ||||
| 
 | ||||
| 			struct		// Events::WindowTitleChanged | ||||
| 			{ | ||||
| 				const wchar_t* title; | ||||
| 			}; | ||||
| 		}; | ||||
| 
 | ||||
| 		static bool Check(EventType type); | ||||
| 	}; | ||||
| 
 | ||||
| 	// 自定义事件
 | ||||
| 	struct CustomEvent | ||||
| 	{ | ||||
| 		void* data; | ||||
| 	}; | ||||
| 
 | ||||
| 	class Actor; | ||||
| 
 | ||||
| 	// 事件
 | ||||
| 	struct KGE_API Event | ||||
| 	{ | ||||
| 		enum Type : EventType | ||||
| 		{ | ||||
| 			First, | ||||
| 
 | ||||
| 			// 鼠标事件
 | ||||
| 			MouseFirst, | ||||
| 			MouseMove,			// 移动
 | ||||
| 			MouseBtnDown,		// 鼠标按下
 | ||||
| 			MouseBtnUp,			// 鼠标抬起
 | ||||
| 			MouseWheel,			// 滚轮滚动
 | ||||
| 			MouseHover,			// 鼠标移入
 | ||||
| 			MouseOut,			// 鼠标移出
 | ||||
| 			Click,				// 鼠标点击
 | ||||
| 			MouseLast, | ||||
| 
 | ||||
| 			// 按键事件
 | ||||
| 			KeyFirst, | ||||
| 			KeyDown,			// 按键按下
 | ||||
| 			KeyUp,				// 按键抬起
 | ||||
| 			Char,				// 输出字符
 | ||||
| 			KeyLast, | ||||
| 
 | ||||
| 			// 窗口消息
 | ||||
| 			WindowFirst, | ||||
| 			WindowMoved,		// 窗口移动
 | ||||
| 			WindowResized,		// 窗口大小变化
 | ||||
| 			WindowFocusChanged,	// 获得或失去焦点
 | ||||
| 			WindowTitleChanged,	// 标题变化
 | ||||
| 			WindowClosed,		// 窗口被关闭
 | ||||
| 			WindowLast, | ||||
| 
 | ||||
| 			Last | ||||
| 		}; | ||||
| 
 | ||||
| 		int type; | ||||
| 		Actor* target; | ||||
| 
 | ||||
| 		union | ||||
| 		{ | ||||
| 			MouseEvent mouse; | ||||
| 			KeyboardEvent key; | ||||
| 			WindowEvent window; | ||||
| 			CustomEvent custom; | ||||
| 		}; | ||||
| 
 | ||||
| 		Event(EventType type = Type::First) : type(type), target(nullptr) {} | ||||
| 	}; | ||||
| 
 | ||||
| 
 | ||||
| 	// Check-functions
 | ||||
| 
 | ||||
| 	inline bool MouseEvent::Check(EventType type) | ||||
| 	{ | ||||
| 		return type > Event::MouseFirst && type < Event::MouseLast; | ||||
| 	} | ||||
| 
 | ||||
| 	inline bool KeyboardEvent::Check(EventType type) | ||||
| 	{ | ||||
| 		return type > Event::KeyFirst && type < Event::KeyLast; | ||||
| 	} | ||||
| 
 | ||||
| 	inline bool WindowEvent::Check(EventType type) | ||||
| 	{ | ||||
| 		return type > Event::WindowFirst && type < Event::WindowLast; | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  | @ -1,426 +0,0 @@ | |||
| // Copyright (c) 2016-2018 Kiwano - Nomango
 | ||||
| // 
 | ||||
| // Permission is hereby granted, free of charge, to any person obtaining a copy
 | ||||
| // of this software and associated documentation files (the "Software"), to deal
 | ||||
| // in the Software without restriction, including without limitation the rights
 | ||||
| // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | ||||
| // copies of the Software, and to permit persons to whom the Software is
 | ||||
| // furnished to do so, subject to the following conditions:
 | ||||
| // 
 | ||||
| // The above copyright notice and this permission notice shall be included in
 | ||||
| // all copies or substantial portions of the Software.
 | ||||
| // 
 | ||||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | ||||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | ||||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | ||||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | ||||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | ||||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | ||||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #include <regex> | ||||
| #include <unordered_map> | ||||
| 
 | ||||
| #include <kiwano/base/time.h> | ||||
| #include <kiwano/base/Logger.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
| 	namespace time | ||||
| 	{ | ||||
| 		//-------------------------------------------------------
 | ||||
| 		// Time
 | ||||
| 		//-------------------------------------------------------
 | ||||
| 
 | ||||
| 		Time::Time() | ||||
| 			: dur_(0) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		Time::Time(long dur) | ||||
| 			: dur_(dur) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		const Time Time::operator+(const Duration & dur) const | ||||
| 		{ | ||||
| 			return Time{ dur_ + dur.Milliseconds() }; | ||||
| 		} | ||||
| 
 | ||||
| 		const Time Time::operator-(const Duration & dur) const | ||||
| 		{ | ||||
| 			return Time{ dur_ - dur.Milliseconds() }; | ||||
| 		} | ||||
| 
 | ||||
| 		Time & Time::operator+=(const Duration & other) | ||||
| 		{ | ||||
| 			dur_ += other.Milliseconds(); | ||||
| 			return (*this); | ||||
| 		} | ||||
| 
 | ||||
| 		Time & Time::operator-=(const Duration &other) | ||||
| 		{ | ||||
| 			dur_ -= other.Milliseconds(); | ||||
| 			return (*this); | ||||
| 		} | ||||
| 
 | ||||
| 		const Duration Time::operator-(const Time & other) const | ||||
| 		{ | ||||
| 			return Duration(dur_ - other.dur_); | ||||
| 		} | ||||
| 
 | ||||
| 		Time Time::Now() noexcept | ||||
| 		{ | ||||
| 			static LARGE_INTEGER freq = {}; | ||||
| 			if (freq.QuadPart == 0LL) | ||||
| 			{ | ||||
| 				// the Function will always succceed on systems that run Windows XP or later
 | ||||
| 				QueryPerformanceFrequency(&freq); | ||||
| 			} | ||||
| 
 | ||||
| 			LARGE_INTEGER count; | ||||
| 			QueryPerformanceCounter(&count); | ||||
| 
 | ||||
| 			const long long whole = (count.QuadPart / freq.QuadPart) * 1000LL; | ||||
| 			const long long part = (count.QuadPart % freq.QuadPart) * 1000LL / freq.QuadPart; | ||||
| 			return Time{ static_cast<long>(whole + part) }; | ||||
| 		} | ||||
| 
 | ||||
| 
 | ||||
| 		//-------------------------------------------------------
 | ||||
| 		// Duration
 | ||||
| 		//-------------------------------------------------------
 | ||||
| 
 | ||||
| 		const Duration Ms	= 1L; | ||||
| 		const Duration Sec	= 1000 * Ms; | ||||
| 		const Duration Min	= 60 * Sec; | ||||
| 		const Duration Hour	= 60 * Min; | ||||
| 
 | ||||
| 		namespace | ||||
| 		{ | ||||
| 			const auto duration_regex = std::wregex(LR"(^[-+]?([0-9]*(\.[0-9]*)?(h|m|s|ms)+)+$)"); | ||||
| 
 | ||||
| 			typedef std::unordered_map<String, Duration> UnitMap; | ||||
| 			const auto unit_map = UnitMap | ||||
| 			{ | ||||
| 				{L"ms", Ms}, | ||||
| 				{L"s", Sec}, | ||||
| 				{L"m", Min}, | ||||
| 				{L"h", Hour} | ||||
| 			}; | ||||
| 		} | ||||
| 
 | ||||
| 		Duration::Duration() | ||||
| 			: milliseconds_(0) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		Duration::Duration(long milliseconds) | ||||
| 			: milliseconds_(milliseconds) | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		float Duration::Seconds() const | ||||
| 		{ | ||||
| 			long sec = milliseconds_ / Sec.milliseconds_; | ||||
| 			long ms = milliseconds_ % Sec.milliseconds_; | ||||
| 			return static_cast<float>(sec) + static_cast<float>(ms) / 1000.f; | ||||
| 		} | ||||
| 
 | ||||
| 		float Duration::Minutes() const | ||||
| 		{ | ||||
| 			long min = milliseconds_ / Min.milliseconds_; | ||||
| 			long ms = milliseconds_ % Min.milliseconds_; | ||||
| 			return static_cast<float>(min) + static_cast<float>(ms) / (60 * 1000.f); | ||||
| 		} | ||||
| 
 | ||||
| 		float Duration::Hours() const | ||||
| 		{ | ||||
| 			long hour = milliseconds_ / Hour.milliseconds_; | ||||
| 			long ms = milliseconds_ % Hour.milliseconds_; | ||||
| 			return static_cast<float>(hour) + static_cast<float>(ms) / (60 * 60 * 1000.f); | ||||
| 		} | ||||
| 
 | ||||
| 		String kiwano::time::Duration::ToString() const | ||||
| 		{ | ||||
| 			if (IsZero()) | ||||
| 			{ | ||||
| 				return String(L"0s"); | ||||
| 			} | ||||
| 
 | ||||
| 			String result; | ||||
| 			long total_ms = milliseconds_; | ||||
| 			if (total_ms < 0) | ||||
| 			{ | ||||
| 				result.append(L"-"); | ||||
| 				total_ms = -total_ms; | ||||
| 			} | ||||
| 
 | ||||
| 			long hour = total_ms / Hour.milliseconds_; | ||||
| 			long min = total_ms / Min.milliseconds_ - hour * 60; | ||||
| 			long sec = total_ms / Sec.milliseconds_ - (hour * 60 * 60 + min * 60); | ||||
| 			long ms = total_ms % Sec.milliseconds_; | ||||
| 
 | ||||
| 			if (hour) | ||||
| 			{ | ||||
| 				result.append(String::parse(hour)).append(L"h"); | ||||
| 				result.append(String::parse(min)).append(L"m"); | ||||
| 			} | ||||
| 			else if(min) | ||||
| 			{ | ||||
| 				result.append(String::parse(min)).append(L"m"); | ||||
| 			} | ||||
| 
 | ||||
| 			if (ms != 0) | ||||
| 			{ | ||||
| 				result.append(String::parse(static_cast<float>(sec) + static_cast<float>(ms) / 1000.f)) | ||||
| 					.append(L"s"); | ||||
| 			} | ||||
| 			else if (sec != 0) | ||||
| 			{ | ||||
| 				result.append(String::parse(sec)).append(L"s"); | ||||
| 			} | ||||
| 			return result; | ||||
| 		} | ||||
| 
 | ||||
| 		bool Duration::operator==(const Duration & other) const | ||||
| 		{ | ||||
| 			return milliseconds_ == other.milliseconds_; | ||||
| 		} | ||||
| 
 | ||||
| 		bool Duration::operator!=(const Duration & other) const | ||||
| 		{ | ||||
| 			return milliseconds_ != other.milliseconds_; | ||||
| 		} | ||||
| 
 | ||||
| 		bool Duration::operator>(const Duration & other) const | ||||
| 		{ | ||||
| 			return milliseconds_ > other.milliseconds_; | ||||
| 		} | ||||
| 
 | ||||
| 		bool Duration::operator>=(const Duration & other) const | ||||
| 		{ | ||||
| 			return milliseconds_ >= other.milliseconds_; | ||||
| 		} | ||||
| 
 | ||||
| 		bool Duration::operator<(const Duration & other) const | ||||
| 		{ | ||||
| 			return milliseconds_ < other.milliseconds_; | ||||
| 		} | ||||
| 
 | ||||
| 		bool Duration::operator<=(const Duration & other) const | ||||
| 		{ | ||||
| 			return milliseconds_ <= other.milliseconds_; | ||||
| 		} | ||||
| 
 | ||||
| 		float kiwano::time::Duration::operator/(const Duration & other) const | ||||
| 		{ | ||||
| 			return static_cast<float>(milliseconds_) / other.milliseconds_; | ||||
| 		} | ||||
| 
 | ||||
| 		const Duration Duration::operator+(const Duration & other) const | ||||
| 		{ | ||||
| 			return Duration(milliseconds_ + other.milliseconds_); | ||||
| 		} | ||||
| 
 | ||||
| 		const Duration Duration::operator-(const Duration & other) const | ||||
| 		{ | ||||
| 			return Duration(milliseconds_ - other.milliseconds_); | ||||
| 		} | ||||
| 
 | ||||
| 		const Duration Duration::operator-() const | ||||
| 		{ | ||||
| 			return Duration(-milliseconds_); | ||||
| 		} | ||||
| 
 | ||||
| 		const Duration Duration::operator*(int val) const | ||||
| 		{ | ||||
| 			return Duration(milliseconds_ * val); | ||||
| 		} | ||||
| 
 | ||||
| 		const Duration kiwano::time::Duration::operator*(unsigned long long val) const | ||||
| 		{ | ||||
| 			return Duration(static_cast<long>(milliseconds_ * val)); | ||||
| 		} | ||||
| 
 | ||||
| 		const Duration Duration::operator*(float val) const | ||||
| 		{ | ||||
| 			return Duration(static_cast<long>(milliseconds_ * val)); | ||||
| 		} | ||||
| 
 | ||||
| 		const Duration Duration::operator*(double val) const | ||||
| 		{ | ||||
| 			return Duration(static_cast<long>(milliseconds_ * val)); | ||||
| 		} | ||||
| 
 | ||||
| 		const Duration Duration::operator*(long double val) const | ||||
| 		{ | ||||
| 			return Duration(static_cast<long>(milliseconds_ * val)); | ||||
| 		} | ||||
| 
 | ||||
| 		const Duration Duration::operator/(int val) const | ||||
| 		{ | ||||
| 			return Duration(milliseconds_ / val); | ||||
| 		} | ||||
| 
 | ||||
| 		const Duration Duration::operator/(float val) const | ||||
| 		{ | ||||
| 			return Duration(static_cast<long>(milliseconds_ / val)); | ||||
| 		} | ||||
| 
 | ||||
| 		const Duration Duration::operator/(double val) const | ||||
| 		{ | ||||
| 			return Duration(static_cast<long>(milliseconds_ / val)); | ||||
| 		} | ||||
| 
 | ||||
| 		Duration & Duration::operator+=(const Duration &other) | ||||
| 		{ | ||||
| 			milliseconds_ += other.milliseconds_; | ||||
| 			return (*this); | ||||
| 		} | ||||
| 
 | ||||
| 		Duration & Duration::operator-=(const Duration &other) | ||||
| 		{ | ||||
| 			milliseconds_ -= other.milliseconds_; | ||||
| 			return (*this); | ||||
| 		} | ||||
| 
 | ||||
| 		Duration & Duration::operator*=(int val) | ||||
| 		{ | ||||
| 			milliseconds_ *= val; | ||||
| 			return (*this); | ||||
| 		} | ||||
| 
 | ||||
| 		Duration & Duration::operator/=(int val) | ||||
| 		{ | ||||
| 			milliseconds_ = static_cast<long>(milliseconds_ / val); | ||||
| 			return (*this); | ||||
| 		} | ||||
| 
 | ||||
| 		Duration & Duration::operator*=(float val) | ||||
| 		{ | ||||
| 			milliseconds_ = static_cast<long>(milliseconds_ * val); | ||||
| 			return (*this); | ||||
| 		} | ||||
| 
 | ||||
| 		Duration & Duration::operator/=(float val) | ||||
| 		{ | ||||
| 			milliseconds_ = static_cast<long>(milliseconds_ / val); | ||||
| 			return (*this); | ||||
| 		} | ||||
| 
 | ||||
| 		Duration & Duration::operator*=(double val) | ||||
| 		{ | ||||
| 			milliseconds_ = static_cast<long>(milliseconds_ * val); | ||||
| 			return (*this); | ||||
| 		} | ||||
| 
 | ||||
| 		Duration & Duration::operator/=(double val) | ||||
| 		{ | ||||
| 			milliseconds_ = static_cast<long>(milliseconds_ / val); | ||||
| 			return (*this); | ||||
| 		} | ||||
| 
 | ||||
| 		const Duration kiwano::time::operator*(int val, const Duration & dur) | ||||
| 		{ | ||||
| 			return dur * val; | ||||
| 		} | ||||
| 
 | ||||
| 		const Duration kiwano::time::operator/(int val, const Duration & dur) | ||||
| 		{ | ||||
| 			return dur / val; | ||||
| 		} | ||||
| 
 | ||||
| 		const Duration kiwano::time::operator*(float val, const Duration & dur) | ||||
| 		{ | ||||
| 			return dur * val; | ||||
| 		} | ||||
| 
 | ||||
| 		const Duration kiwano::time::operator/(float val, const Duration & dur) | ||||
| 		{ | ||||
| 			return dur / val; | ||||
| 		} | ||||
| 
 | ||||
| 		const Duration kiwano::time::operator*(double val, const Duration & dur) | ||||
| 		{ | ||||
| 			return dur * val; | ||||
| 		} | ||||
| 
 | ||||
| 		const Duration kiwano::time::operator/(double val, const Duration & dur) | ||||
| 		{ | ||||
| 			return dur / val; | ||||
| 		} | ||||
| 
 | ||||
| 		const Duration kiwano::time::operator*(long double val, const Duration & dur) | ||||
| 		{ | ||||
| 			return dur * val; | ||||
| 		} | ||||
| 
 | ||||
| 		Duration Duration::Parse(const String& str) | ||||
| 		{ | ||||
| 			bool		negative	= false; | ||||
| 			size_t	len			= str.length(); | ||||
| 			size_t	pos			= 0; | ||||
| 			Duration	ret; | ||||
| 
 | ||||
| 			if (!std::regex_match(str.c_str(), duration_regex)) | ||||
| 			{ | ||||
| 				KGE_ERROR_LOG(L"Duration::Parse failed, invalid duration"); | ||||
| 				return ret; | ||||
| 			} | ||||
| 
 | ||||
| 			if (str.empty() || str == L"0") { return ret; } | ||||
| 
 | ||||
| 			// ·ûºÅλ
 | ||||
| 			if (str[0] == L'-' || str[0] == L'+') | ||||
| 			{ | ||||
| 				negative = (str[0] == L'-'); | ||||
| 				pos++; | ||||
| 			} | ||||
| 
 | ||||
| 			while (pos < len) | ||||
| 			{ | ||||
| 				// ÊýÖµ
 | ||||
| 				size_t i = pos; | ||||
| 				for (; i < len; ++i) | ||||
| 				{ | ||||
| 					wchar_t ch = str[i]; | ||||
| 					if (!(ch == L'.' || L'0' <= ch && ch <= L'9')) | ||||
| 					{ | ||||
| 						break; | ||||
| 					} | ||||
| 				} | ||||
| 
 | ||||
| 				String num_str = str.substr(pos, i - pos); | ||||
| 				pos = i; | ||||
| 
 | ||||
| 				KGE_ASSERT(!(num_str.empty() || num_str == L".") && "Duration::Parse failed, invalid duration"); | ||||
| 
 | ||||
| 				// µ¥Î»
 | ||||
| 				for (; i < len; ++i) | ||||
| 				{ | ||||
| 					wchar_t ch = str[i]; | ||||
| 					if (ch == L'.' || L'0' <= ch && ch <= L'9') | ||||
| 					{ | ||||
| 						break; | ||||
| 					} | ||||
| 				} | ||||
| 
 | ||||
| 				String unit_str = str.substr(pos, i - pos); | ||||
| 				pos = i; | ||||
| 
 | ||||
| 				KGE_ASSERT(unit_map.find(unit_str) != unit_map.end() && "Duration::Parse failed, invalid duration"); | ||||
| 
 | ||||
| 				double num = std::wcstod(num_str.c_str(), nullptr); | ||||
| 				Duration unit = unit_map.at(unit_str); | ||||
| 				ret += unit * num; | ||||
| 			} | ||||
| 
 | ||||
| 			if (negative) | ||||
| 			{ | ||||
| 				ret = -ret; | ||||
| 			} | ||||
| 			return ret; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | @ -1,247 +0,0 @@ | |||
| // Copyright (c) 2016-2018 Kiwano - Nomango
 | ||||
| // 
 | ||||
| // Permission is hereby granted, free of charge, to any person obtaining a copy
 | ||||
| // of this software and associated documentation files (the "Software"), to deal
 | ||||
| // in the Software without restriction, including without limitation the rights
 | ||||
| // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | ||||
| // copies of the Software, and to permit persons to whom the Software is
 | ||||
| // furnished to do so, subject to the following conditions:
 | ||||
| // 
 | ||||
| // The above copyright notice and this permission notice shall be included in
 | ||||
| // all copies or substantial portions of the Software.
 | ||||
| // 
 | ||||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | ||||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | ||||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | ||||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | ||||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | ||||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | ||||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #pragma once | ||||
| #include <ostream> | ||||
| #include <istream> | ||||
| 
 | ||||
| #include <kiwano/macros.h> | ||||
| #include <kiwano/core/core.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
| 	namespace time | ||||
| 	{ | ||||
| 		// 时间段
 | ||||
| 		//
 | ||||
| 		// 时间段表示法:
 | ||||
| 		//     5 秒: time::Sec * 5
 | ||||
| 		//     1.5 小时: time::Hour * 1.5
 | ||||
| 		//     3 小时 45 分 15 秒: time::Hour * 3 + time::Min * 45 + time::Sec * 15
 | ||||
| 		// 在 VS2015 及更高版本可以使用 time literals:
 | ||||
| 		//     5 秒: 5_s
 | ||||
| 		//     1.5 小时: 1.5_h
 | ||||
| 		//     3 小时 45 分 15 秒: 3_h + 45_m + 15_s
 | ||||
| 		//
 | ||||
| 		struct KGE_API Duration | ||||
| 		{ | ||||
| 			Duration(); | ||||
| 
 | ||||
| 			Duration( | ||||
| 				long milliseconds | ||||
| 			); | ||||
| 
 | ||||
| 			// 转化为毫秒
 | ||||
| 			inline long Milliseconds() const		{ return milliseconds_; } | ||||
| 
 | ||||
| 			// 转化为秒
 | ||||
| 			float Seconds() const; | ||||
| 
 | ||||
| 			// 转化为分钟
 | ||||
| 			float Minutes() const; | ||||
| 
 | ||||
| 			// 转化为小时
 | ||||
| 			float Hours() const; | ||||
| 
 | ||||
| 			// 时长是否是零
 | ||||
| 			inline bool IsZero() const				{ return milliseconds_ == 0LL; } | ||||
| 
 | ||||
| 			inline void SetMilliseconds(long ms)	{ milliseconds_ = ms; } | ||||
| 
 | ||||
| 			inline void SetSeconds(float seconds)	{ milliseconds_ = static_cast<long>(seconds * 1000.f); } | ||||
| 
 | ||||
| 			inline void SetMinutes(float minutes)	{ milliseconds_ = static_cast<long>(minutes * 60 * 1000.f); } | ||||
| 
 | ||||
| 			inline void SetHours(float hours)		{ milliseconds_ = static_cast<long>(hours * 60 * 60 * 1000.f); } | ||||
| 
 | ||||
| 			// 转为字符串
 | ||||
| 			String ToString() const; | ||||
| 
 | ||||
| 			inline operator bool() const			{ return !IsZero(); } | ||||
| 
 | ||||
| 			bool operator== (const Duration &) const; | ||||
| 			bool operator!= (const Duration &) const; | ||||
| 			bool operator> (const Duration &) const; | ||||
| 			bool operator>= (const Duration &) const; | ||||
| 			bool operator< (const Duration &) const; | ||||
| 			bool operator<= (const Duration &) const; | ||||
| 
 | ||||
| 			float operator / (const Duration &) const; | ||||
| 
 | ||||
| 			const Duration operator + (const Duration &) const; | ||||
| 			const Duration operator - (const Duration &) const; | ||||
| 			const Duration operator - () const; | ||||
| 			const Duration operator * (int) const; | ||||
| 			const Duration operator * (unsigned long long) const; | ||||
| 			const Duration operator * (float) const; | ||||
| 			const Duration operator * (double) const; | ||||
| 			const Duration operator * (long double) const; | ||||
| 			const Duration operator / (int) const; | ||||
| 			const Duration operator / (float) const; | ||||
| 			const Duration operator / (double) const; | ||||
| 
 | ||||
| 			Duration& operator += (const Duration &); | ||||
| 			Duration& operator -= (const Duration &); | ||||
| 			Duration& operator *= (int); | ||||
| 			Duration& operator *= (float); | ||||
| 			Duration& operator *= (double); | ||||
| 			Duration& operator /= (int); | ||||
| 			Duration& operator /= (float); | ||||
| 			Duration& operator /= (double); | ||||
| 
 | ||||
| 			friend const Duration operator* (int, const Duration &); | ||||
| 			friend const Duration operator* (float, const Duration &); | ||||
| 			friend const Duration operator* (double, const Duration &); | ||||
| 			friend const Duration operator* (long double, const Duration &); | ||||
| 			friend const Duration operator/ (int, const Duration &); | ||||
| 			friend const Duration operator/ (float, const Duration &); | ||||
| 			friend const Duration operator/ (double, const Duration &); | ||||
| 
 | ||||
| 		public: | ||||
| 			// 时间段格式化
 | ||||
| 			//
 | ||||
| 			// 时间段字符串允许是有符号的浮点数, 并且带有时间单位后缀
 | ||||
| 			// 例如: "300ms", "-1.5h", "2h45m"
 | ||||
| 			// 允许的时间单位有 "ms", "s", "m", "h"
 | ||||
| 			static Duration Parse(const String& parse_str); | ||||
| 
 | ||||
| 			template <typename _Char> | ||||
| 			friend inline std::basic_ostream<_Char>& operator<<(std::basic_ostream<_Char>& out, const Duration& dur) | ||||
| 			{ | ||||
| 				return out << dur.ToString(); | ||||
| 			} | ||||
| 
 | ||||
| 			template <typename _Char> | ||||
| 			friend inline std::basic_istream<_Char>& operator>>(std::basic_istream<_Char>& in, Duration& dur) | ||||
| 			{ | ||||
| 				String str; | ||||
| 				if (in >> str) | ||||
| 				{ | ||||
| 					dur = Duration::Parse(str); | ||||
| 				} | ||||
| 				return in; | ||||
| 			} | ||||
| 
 | ||||
| 		private: | ||||
| 			long milliseconds_; | ||||
| 		}; | ||||
| 
 | ||||
| 		/* 预定义的时间段 */ | ||||
| 		KGE_API extern const Duration Ms;		// 毫秒
 | ||||
| 		KGE_API extern const Duration Sec;		// 秒
 | ||||
| 		KGE_API extern const Duration Min;		// 分钟
 | ||||
| 		KGE_API extern const Duration Hour;		// 小时
 | ||||
| 
 | ||||
| 
 | ||||
| 		// 时间
 | ||||
| 		//
 | ||||
| 		// 获取当前时间: Time now = Time::Now();
 | ||||
| 		// 两时间相减, 得到一个 Duration 对象, 例如:
 | ||||
| 		//     Time t1, t2;
 | ||||
| 		//     int ms = (t2 - t1).Milliseconds();  // 获取两时间相差的毫秒数
 | ||||
| 		// 
 | ||||
| 		struct KGE_API Time | ||||
| 		{ | ||||
| 			Time(); | ||||
| 
 | ||||
| 			Time(long); | ||||
| 
 | ||||
| 			// 是否是零时
 | ||||
| 			inline bool IsZero() const { return dur_ == 0; } | ||||
| 
 | ||||
| 			const Time operator + (const Duration &) const; | ||||
| 			const Time operator - (const Duration &) const; | ||||
| 
 | ||||
| 			Time& operator += (const Duration &); | ||||
| 			Time& operator -= (const Duration &); | ||||
| 
 | ||||
| 			const Duration operator - (const Time &) const; | ||||
| 
 | ||||
| 		public: | ||||
| 			// 获取当前时间
 | ||||
| 			// 由于该时间点基于系统启动时间开始计算, 所以无法格式化该时间, 
 | ||||
| 			// 也无法获得该时间的 Unix 时间戳
 | ||||
| 			static Time Now() noexcept; | ||||
| 
 | ||||
| 		private: | ||||
| 			long dur_; | ||||
| 		}; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
| 	using namespace time; | ||||
| } | ||||
| 
 | ||||
| #if KGE_VS_VER > KGE_VS_2013 | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
| 	inline namespace literals | ||||
| 	{ | ||||
| 		inline const kiwano::time::Duration operator "" _ms(long double val) | ||||
| 		{ | ||||
| 			return kiwano::time::Ms * val; | ||||
| 		} | ||||
| 
 | ||||
| 		inline const kiwano::time::Duration operator "" _s(long double val) | ||||
| 		{ | ||||
| 			return kiwano::time::Sec * val; | ||||
| 		} | ||||
| 
 | ||||
| 		inline const kiwano::time::Duration operator "" _m(long double val) | ||||
| 		{ | ||||
| 			return kiwano::time::Min * val; | ||||
| 		} | ||||
| 
 | ||||
| 		inline const kiwano::time::Duration operator "" _h(long double val) | ||||
| 		{ | ||||
| 			return kiwano::time::Hour * val; | ||||
| 		} | ||||
| 
 | ||||
| 		inline const kiwano::time::Duration operator "" _ms(unsigned long long val) | ||||
| 		{ | ||||
| 			return kiwano::time::Ms * val; | ||||
| 		} | ||||
| 
 | ||||
| 		inline const kiwano::time::Duration operator "" _s(unsigned long long val) | ||||
| 		{ | ||||
| 			return kiwano::time::Sec * val; | ||||
| 		} | ||||
| 
 | ||||
| 		inline const kiwano::time::Duration operator "" _m(unsigned long long val) | ||||
| 		{ | ||||
| 			return kiwano::time::Min * val; | ||||
| 		} | ||||
| 
 | ||||
| 		inline const kiwano::time::Duration operator "" _h(unsigned long long val) | ||||
| 		{ | ||||
| 			return kiwano::time::Hour * val; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	namespace time | ||||
| 	{ | ||||
| 		using namespace kiwano::literals; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| #endif | ||||
|  | @ -26,7 +26,7 @@ | |||
| namespace kiwano | ||||
| { | ||||
| 
 | ||||
| namespace core | ||||
| namespace common | ||||
| { | ||||
| 
 | ||||
| class bad_any_cast : public std::exception | ||||
|  | @ -519,13 +519,13 @@ _Ty any_cast(any&& a) | |||
| 	return static_cast<_Ty>(std::move(*ptr)); | ||||
| } | ||||
| 
 | ||||
| }  // namespace core
 | ||||
| }  // namespace common
 | ||||
| 
 | ||||
| }  // namespace kiwano
 | ||||
| 
 | ||||
| namespace std | ||||
| { | ||||
| 	inline void swap(kiwano::core::any& lhs, kiwano::core::any& rhs) noexcept | ||||
| 	inline void swap(kiwano::common::any& lhs, kiwano::common::any& rhs) noexcept | ||||
| 	{ | ||||
| 		lhs.swap(rhs); | ||||
| 	} | ||||
|  | @ -28,7 +28,7 @@ | |||
| namespace kiwano | ||||
| { | ||||
| 
 | ||||
| namespace core | ||||
| namespace common | ||||
| { | ||||
| 
 | ||||
| //
 | ||||
|  | @ -1602,14 +1602,14 @@ namespace __json_detail | |||
| 
 | ||||
| 			if ((std::isdigit(current) && current != '0') || (current == '-') || (current == '+')) | ||||
| 			{ | ||||
| 				float_type base = 10; | ||||
| 				float_type core = 10; | ||||
| 				if (current == '+') | ||||
| 				{ | ||||
| 					read_next(); | ||||
| 				} | ||||
| 				else if (current == '-') | ||||
| 				{ | ||||
| 					base = static_cast<float_type>(0.1); | ||||
| 					core = static_cast<float_type>(0.1); | ||||
| 					read_next(); | ||||
| 				} | ||||
| 
 | ||||
|  | @ -1620,9 +1620,9 @@ namespace __json_detail | |||
| 				} | ||||
| 
 | ||||
| 				float_type power = 1; | ||||
| 				for (; exponent; exponent >>= 1, base *= base) | ||||
| 				for (; exponent; exponent >>= 1, core *= core) | ||||
| 					if (exponent & 1) | ||||
| 						power *= base; | ||||
| 						power *= core; | ||||
| 
 | ||||
| 				number_value *= power; | ||||
| 				return token_type::value_float; | ||||
|  | @ -2728,7 +2728,7 @@ private: | |||
| 	__json_detail::json_value<basic_json> value_; | ||||
| }; | ||||
| 
 | ||||
| } // namespace core
 | ||||
| } // namespace common
 | ||||
| 
 | ||||
| } // namespace kiwano
 | ||||
| 
 | ||||
|  | @ -28,24 +28,24 @@ | |||
| #include <unordered_map> | ||||
| #include <sstream> | ||||
| 
 | ||||
| #include <kiwano/core/vector.hpp> | ||||
| #include <kiwano/core/string.hpp> | ||||
| #include <kiwano/core/any.hpp> | ||||
| #include <kiwano/core/intrusive_list.hpp> | ||||
| #include <kiwano/core/intrusive_ptr.hpp> | ||||
| #include <kiwano/core/noncopyable.hpp> | ||||
| #include <kiwano/core/singleton.hpp> | ||||
| #include <kiwano/core/function.hpp> | ||||
| #include <kiwano/core/basic_json.hpp> | ||||
| #include <kiwano/common/vector.hpp> | ||||
| #include <kiwano/common/string.hpp> | ||||
| #include <kiwano/common/any.hpp> | ||||
| #include <kiwano/common/intrusive_list.hpp> | ||||
| #include <kiwano/common/intrusive_ptr.hpp> | ||||
| #include <kiwano/common/noncopyable.hpp> | ||||
| #include <kiwano/common/singleton.hpp> | ||||
| #include <kiwano/common/function.hpp> | ||||
| #include <kiwano/common/basic_json.hpp> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
| 	using String = kiwano::core::wstring; | ||||
| 	using String = kiwano::common::wstring; | ||||
| 
 | ||||
| 	using StringStream = std::wstringstream; | ||||
| 
 | ||||
| 	template <typename _Ty, typename... _Args> | ||||
| 	using Vector = kiwano::core::vector<_Ty, _Args...>; | ||||
| 	using Vector = kiwano::common::vector<_Ty, _Args...>; | ||||
| 
 | ||||
| 	template <typename _Ty, typename... _Args> | ||||
| 	using List = std::list<_Ty, _Args...>; | ||||
|  | @ -72,21 +72,21 @@ namespace kiwano | |||
| 	using UnorderedMap = std::unordered_map<_Kty, _Ty, _Args...>; | ||||
| 
 | ||||
| 	template <typename _FuncTy> | ||||
| 	using Function = kiwano::core::function<_FuncTy>; | ||||
| 	using Function = kiwano::common::function<_FuncTy>; | ||||
| 
 | ||||
| 	using Any = kiwano::core::any; | ||||
| 	using Any = kiwano::common::any; | ||||
| 
 | ||||
| 	using Json = kiwano::core::basic_json<kiwano::Map, kiwano::Vector, kiwano::String, | ||||
| 	using Json = kiwano::common::basic_json<kiwano::Map, kiwano::Vector, kiwano::String, | ||||
| 		int, double, bool, std::allocator>; | ||||
| 
 | ||||
| 	template <typename _Ty> | ||||
| 	using Singleton = core::singleton<_Ty>; | ||||
| 	using Singleton = common::singleton<_Ty>; | ||||
| 
 | ||||
| 	template <typename _Ty> | ||||
| 	using IntrusiveList = core::intrusive_list<_Ty>; | ||||
| 	using IntrusiveList = common::intrusive_list<_Ty>; | ||||
| 
 | ||||
| 	template <typename _Ty> | ||||
| 	using IntrusiveListItem = core::intrusive_list_item<_Ty>; | ||||
| 	using IntrusiveListItem = common::intrusive_list_item<_Ty>; | ||||
| } | ||||
| 
 | ||||
| namespace std | ||||
|  | @ -25,7 +25,7 @@ | |||
| namespace kiwano | ||||
| { | ||||
| 
 | ||||
| namespace core | ||||
| namespace common | ||||
| { | ||||
| //
 | ||||
| // function is a light weight ::std::function<>-like class
 | ||||
|  | @ -321,7 +321,7 @@ private: | |||
| 	__function_detail::callable<_Ret, _Args...>* callable_; | ||||
| }; | ||||
| 
 | ||||
| }  // namespace core
 | ||||
| }  // namespace common
 | ||||
| 
 | ||||
| }  // namespace kiwano
 | ||||
| 
 | ||||
|  | @ -335,9 +335,9 @@ namespace kiwano | |||
| 		typename _Ret, | ||||
| 		typename... _Args | ||||
| 	> | ||||
| 	inline core::function<_Ret(_Args...)> Closure(_Uty* ptr, _Ret(_Ty::* func)(_Args...)) | ||||
| 	inline common::function<_Ret(_Args...)> Closure(_Uty* ptr, _Ret(_Ty::* func)(_Args...)) | ||||
| 	{ | ||||
| 		return core::function<_Ret(_Args...)>(ptr, func); | ||||
| 		return common::function<_Ret(_Args...)>(ptr, func); | ||||
| 	} | ||||
| 
 | ||||
| 	template<typename _Ty, | ||||
|  | @ -348,8 +348,8 @@ namespace kiwano | |||
| 		typename _Ret, | ||||
| 		typename... _Args | ||||
| 	> | ||||
| 	inline core::function<_Ret(_Args...)> Closure(_Uty* ptr, _Ret(_Ty::* func)(_Args...) const) | ||||
| 	inline common::function<_Ret(_Args...)> Closure(_Uty* ptr, _Ret(_Ty::* func)(_Args...) const) | ||||
| 	{ | ||||
| 		return core::function<_Ret(_Args...)>(ptr, func); | ||||
| 		return common::function<_Ret(_Args...)>(ptr, func); | ||||
| 	} | ||||
| } | ||||
|  | @ -32,7 +32,7 @@ | |||
| namespace kiwano | ||||
| { | ||||
| 
 | ||||
| namespace core | ||||
| namespace common | ||||
| { | ||||
| 
 | ||||
| template <typename _Ty> | ||||
|  | @ -261,7 +261,7 @@ private: | |||
| 		// disable warning 4996
 | ||||
| 		using _Unchecked_type = _Ty; | ||||
| 
 | ||||
| 		inline iterator_impl(value_type base = nullptr, bool is_end = false)	: base_(base), is_end_(is_end) {} | ||||
| 		inline iterator_impl(value_type core = nullptr, bool is_end = false)	: base_(core), is_end_(is_end) {} | ||||
| 
 | ||||
| 		inline _Ty				operator*() const								{ KGE_ASSERT(base_); return static_cast<_Ty>(const_cast<reference>(base_)); } | ||||
| 		inline iterator_impl&	operator++()									{ KGE_ASSERT(base_ && !is_end_); value_type next = base_->next_item(); if (next) base_ = next; else is_end_ = true; return (*this);} | ||||
|  | @ -307,7 +307,7 @@ private: | |||
| 	value_type last_; | ||||
| }; | ||||
| 
 | ||||
| }  // namespace core
 | ||||
| }  // namespace common
 | ||||
| 
 | ||||
| }  // namespace kiwano
 | ||||
| 
 | ||||
|  | @ -26,7 +26,7 @@ | |||
| namespace kiwano | ||||
| { | ||||
| 
 | ||||
| namespace core | ||||
| namespace common | ||||
| { | ||||
| 
 | ||||
| template <typename _Ty, typename _ManagerTy> | ||||
|  | @ -141,6 +141,6 @@ inline void swap(intrusive_ptr<_Ty, manager_type>& lhs, intrusive_ptr<_Ty, manag | |||
| 	lhs.swap(rhs); | ||||
| } | ||||
| 
 | ||||
| }  // namespace core
 | ||||
| }  // namespace common
 | ||||
| 
 | ||||
| }  // namespace kiwano
 | ||||
|  | @ -22,7 +22,7 @@ | |||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
| namespace core | ||||
| namespace common | ||||
| { | ||||
| 
 | ||||
| class noncopyable | ||||
|  | @ -36,5 +36,5 @@ private: | |||
| 	noncopyable& operator=(const noncopyable&) = delete; | ||||
| }; | ||||
| 
 | ||||
| }  // namespace core
 | ||||
| }  // namespace common
 | ||||
| }  // namespace kiwano
 | ||||
|  | @ -27,13 +27,13 @@ | |||
| 
 | ||||
| #ifndef KGE_DECLARE_SINGLETON | ||||
| #define KGE_DECLARE_SINGLETON( CLASS )			\ | ||||
| 	friend ::kiwano::core::singleton< CLASS >;  \ | ||||
| 	friend ::kiwano::common::singleton< CLASS >;  \ | ||||
| 	friend typename std::unique_ptr< CLASS >::deleter_type | ||||
| #endif | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
| namespace core | ||||
| namespace common | ||||
| { | ||||
| 
 | ||||
| template <typename _Ty> | ||||
|  | @ -81,5 +81,5 @@ std::once_flag singleton<_Ty>::once_; | |||
| template <typename _Ty> | ||||
| std::unique_ptr<_Ty> singleton<_Ty>::instance_; | ||||
| 
 | ||||
| }  // namespace core
 | ||||
| }  // namespace common
 | ||||
| }  // namespace kiwano
 | ||||
|  | @ -29,7 +29,7 @@ | |||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
| namespace core | ||||
| namespace common | ||||
| { | ||||
| 
 | ||||
| //
 | ||||
|  | @ -56,10 +56,10 @@ private: | |||
| 		// disable warning 4996
 | ||||
| 		using _Unchecked_type = _Ty; | ||||
| 
 | ||||
| 		inline iterator_impl(pointer base = nullptr) : base_(base) {} | ||||
| 		inline iterator_impl(pointer core = nullptr) : base_(core) {} | ||||
| 
 | ||||
| 		inline reference operator*() const									{ return *base_; } | ||||
| 		inline pointer base() const											{ return base_; } | ||||
| 		inline pointer core() const											{ return base_; } | ||||
| 
 | ||||
| 		inline iterator_impl& operator++()									{ ++base_; return (*this); } | ||||
| 		inline iterator_impl operator++(int)								{ iterator_impl old = (*this); ++(*this); return old; } | ||||
|  | @ -176,8 +176,8 @@ public: | |||
| 	inline basic_string&	assign(_Iter first, _Iter last)																{ assign_iter(first, last); return(*this); } | ||||
| 
 | ||||
| 	basic_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().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; } | ||||
| 	iterator				erase(const const_iterator where)															{ size_type off = where - cbegin(); erase(off, 1); return begin().core() + off; } | ||||
| 	iterator				erase(const const_iterator first, const const_iterator last)								{ size_type off = first - cbegin(); erase(first - cbegin(), last - first); return begin().core() + off; } | ||||
| 
 | ||||
| 	basic_string			substr(size_type pos = 0, size_type count = npos) const										{ return basic_string(*this, pos, count); } | ||||
| 
 | ||||
|  | @ -186,7 +186,7 @@ public: | |||
| 	basic_string&			insert(size_type index, const basic_string& str, size_type off, size_type count = npos); | ||||
| 	inline basic_string&	insert(size_type index, const char_type* s)													{ return insert(index, s, traits_type::length(s)); } | ||||
| 	inline basic_string&	insert(size_type index, const basic_string& str)											{ return insert(index, str, 0, str.size()); } | ||||
| 	inline iterator			insert(const_iterator pos, size_type count, char_type ch)									{ size_type off = pos - cbegin(); insert(off, count, ch); return begin().base() + off; } | ||||
| 	inline iterator			insert(const_iterator pos, size_type count, char_type ch)									{ size_type off = pos - cbegin(); insert(off, count, ch); return begin().core() + off; } | ||||
| 	inline iterator			insert(const_iterator pos, char_type ch)													{ return insert(pos, 1, ch); } | ||||
| 
 | ||||
| 	inline void				push_back(const char_type ch)																{ append(1, ch); } | ||||
|  | @ -425,8 +425,8 @@ basic_string<wchar_t> format_string(const wchar_t* const fmt, _Args&& ... args); | |||
| //
 | ||||
| // string && wstring
 | ||||
| //
 | ||||
| using string = ::kiwano::core::basic_string<char>; | ||||
| using wstring = ::kiwano::core::basic_string<wchar_t>; | ||||
| using string = ::kiwano::common::basic_string<char>; | ||||
| using wstring = ::kiwano::common::basic_string<wchar_t>; | ||||
| 
 | ||||
| 
 | ||||
| inline string to_string(int val)					{ return to_basic_string<char>(val); } | ||||
|  | @ -450,7 +450,7 @@ inline wstring to_wstring(double val)				{ return to_basic_string<wchar_t>(val); | |||
| inline wstring to_wstring(long double val)			{ return to_basic_string<wchar_t>(val); } | ||||
| 
 | ||||
| 
 | ||||
| }  // namespace core
 | ||||
| }  // namespace common
 | ||||
| }  // namespace kiwano
 | ||||
| 
 | ||||
| namespace kiwano | ||||
|  | @ -515,7 +515,7 @@ namespace __string_details | |||
| 	} | ||||
| } | ||||
| 
 | ||||
| namespace core | ||||
| namespace common | ||||
| { | ||||
| 
 | ||||
| 	template <typename _CharTy> | ||||
|  | @ -670,7 +670,7 @@ namespace core | |||
| 		} | ||||
| 		size_ = count; | ||||
| 
 | ||||
| 		traits_type::move(str_, rhs.begin().base() + pos, size_); | ||||
| 		traits_type::move(str_, rhs.begin().core() + pos, size_); | ||||
| 		traits_type::assign(str_[size_], value_type()); | ||||
| 		return (*this); | ||||
| 	} | ||||
|  | @ -693,8 +693,8 @@ namespace core | |||
| 		} | ||||
| 
 | ||||
| 		size_type new_size = size_ - count; | ||||
| 		iterator erase_at = begin().base() + offset; | ||||
| 		traits_type::move(erase_at.base(), erase_at.base() + count, new_size - offset + 1); | ||||
| 		iterator erase_at = begin().core() + offset; | ||||
| 		traits_type::move(erase_at.core(), erase_at.core() + count, new_size - offset + 1); | ||||
| 		return (*this); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -807,7 +807,7 @@ namespace core | |||
| 
 | ||||
| 			char_type* const insert_at = new_ptr + index; | ||||
| 			traits_type::move(new_ptr, old_ptr, index);							// (0) - (index)
 | ||||
| 			traits_type::move(insert_at, str.begin().base() + off, count);		// (index) - (index + count)
 | ||||
| 			traits_type::move(insert_at, str.begin().core() + off, count);		// (index) - (index + count)
 | ||||
| 			traits_type::move(insert_at + count, old_ptr + index, suffix_size);	// (index + count) - (old_size - index)
 | ||||
| 
 | ||||
| 			deallocate(str_, old_capacity + 1); | ||||
|  | @ -817,7 +817,7 @@ namespace core | |||
| 		{ | ||||
| 			char_type* const insert_at = old_ptr + index; | ||||
| 			traits_type::move(insert_at + count, old_ptr + index, suffix_size); | ||||
| 			traits_type::move(insert_at, str.begin().base() + off, count); | ||||
| 			traits_type::move(insert_at, str.begin().core() + off, count); | ||||
| 		} | ||||
| 
 | ||||
| 		return (*this); | ||||
|  | @ -880,7 +880,7 @@ namespace core | |||
| 		char_type* new_str = allocate(new_cap); | ||||
| 
 | ||||
| 		traits_type::move(new_str, str_, size_); | ||||
| 		traits_type::move(new_str + size_, other.begin().base() + pos, count); | ||||
| 		traits_type::move(new_str + size_, other.begin().core() + pos, count); | ||||
| 		traits_type::assign(new_str[new_size], value_type()); | ||||
| 
 | ||||
| 		destroy(); | ||||
|  | @ -948,7 +948,7 @@ namespace core | |||
| 		if (offset >= size_) | ||||
| 			return basic_string<_CharTy>::npos; | ||||
| 
 | ||||
| 		const_iterator citer = traits_type::find(cbegin().base() + offset, size_, ch); | ||||
| 		const_iterator citer = traits_type::find(cbegin().core() + offset, size_, ch); | ||||
| 		return citer ? (citer - cbegin()) : basic_string<_CharTy>::npos; | ||||
| 	} | ||||
| 
 | ||||
|  | @ -966,7 +966,7 @@ namespace core | |||
| 		if (offset >= size_) | ||||
| 			return basic_string<_CharTy>::npos; | ||||
| 
 | ||||
| 		const_iterator citer = std::find_first_of(cbegin().base() + offset, cend().base(), str, str + count); | ||||
| 		const_iterator citer = std::find_first_of(cbegin().core() + offset, cend().core(), str, str + count); | ||||
| 		return (citer != cend()) ? (citer - cbegin()) : basic_string<_CharTy>::npos; | ||||
| 	} | ||||
| 
 | ||||
|  | @ -977,7 +977,7 @@ namespace core | |||
| 			return npos; | ||||
| 
 | ||||
| 		const_reverse_iterator criter = std::find(crbegin(), crend(), ch); | ||||
| 		return (criter != crend()) ? (criter.base() - cbegin()) : basic_string<_CharTy>::npos; | ||||
| 		return (criter != crend()) ? (criter.core() - cbegin()) : basic_string<_CharTy>::npos; | ||||
| 	} | ||||
| 
 | ||||
| 	template <typename _CharTy> | ||||
|  | @ -1090,7 +1090,7 @@ namespace core | |||
| 		check_offset(pos); | ||||
| 
 | ||||
| 		count = clamp_suffix_size(pos, count); | ||||
| 		traits_type::move(cstr, cbegin().base() + pos, count); | ||||
| 		traits_type::move(cstr, cbegin().core() + pos, count); | ||||
| 		return count; | ||||
| 	} | ||||
| 
 | ||||
|  | @ -1159,31 +1159,31 @@ namespace core | |||
| 	//
 | ||||
| 
 | ||||
| 	template <typename _CharTy> | ||||
| 	inline basic_string<_CharTy> basic_string<_CharTy>::parse(int val)					{ return ::kiwano::core::to_basic_string<char_type>(val); } | ||||
| 	inline basic_string<_CharTy> basic_string<_CharTy>::parse(int val)					{ return ::kiwano::common::to_basic_string<char_type>(val); } | ||||
| 
 | ||||
| 	template <typename _CharTy> | ||||
| 	inline basic_string<_CharTy> basic_string<_CharTy>::parse(unsigned int val)			{ return ::kiwano::core::to_basic_string<char_type>(val); } | ||||
| 	inline basic_string<_CharTy> basic_string<_CharTy>::parse(unsigned int val)			{ return ::kiwano::common::to_basic_string<char_type>(val); } | ||||
| 
 | ||||
| 	template <typename _CharTy> | ||||
| 	inline basic_string<_CharTy> basic_string<_CharTy>::parse(long val)					{ return ::kiwano::core::to_basic_string<char_type>(val); } | ||||
| 	inline basic_string<_CharTy> basic_string<_CharTy>::parse(long val)					{ return ::kiwano::common::to_basic_string<char_type>(val); } | ||||
| 
 | ||||
| 	template <typename _CharTy> | ||||
| 	inline basic_string<_CharTy> basic_string<_CharTy>::parse(unsigned long val)		{ return ::kiwano::core::to_basic_string<char_type>(val); } | ||||
| 	inline basic_string<_CharTy> basic_string<_CharTy>::parse(unsigned long val)		{ return ::kiwano::common::to_basic_string<char_type>(val); } | ||||
| 
 | ||||
| 	template <typename _CharTy> | ||||
| 	inline basic_string<_CharTy> basic_string<_CharTy>::parse(long long val)			{ return ::kiwano::core::to_basic_string<char_type>(val); } | ||||
| 	inline basic_string<_CharTy> basic_string<_CharTy>::parse(long long val)			{ return ::kiwano::common::to_basic_string<char_type>(val); } | ||||
| 
 | ||||
| 	template <typename _CharTy> | ||||
| 	inline basic_string<_CharTy> basic_string<_CharTy>::parse(unsigned long long val)	{ return ::kiwano::core::to_basic_string<char_type>(val); } | ||||
| 	inline basic_string<_CharTy> basic_string<_CharTy>::parse(unsigned long long val)	{ return ::kiwano::common::to_basic_string<char_type>(val); } | ||||
| 
 | ||||
| 	template <typename _CharTy> | ||||
| 	inline basic_string<_CharTy> basic_string<_CharTy>::parse(float val)				{ return ::kiwano::core::to_basic_string<char_type>(val); } | ||||
| 	inline basic_string<_CharTy> basic_string<_CharTy>::parse(float val)				{ return ::kiwano::common::to_basic_string<char_type>(val); } | ||||
| 
 | ||||
| 	template <typename _CharTy> | ||||
| 	inline basic_string<_CharTy> basic_string<_CharTy>::parse(double val)				{ return ::kiwano::core::to_basic_string<char_type>(val); } | ||||
| 	inline basic_string<_CharTy> basic_string<_CharTy>::parse(double val)				{ return ::kiwano::common::to_basic_string<char_type>(val); } | ||||
| 
 | ||||
| 	template <typename _CharTy> | ||||
| 	inline basic_string<_CharTy> basic_string<_CharTy>::parse(long double val)			{ return ::kiwano::core::to_basic_string<char_type>(val); } | ||||
| 	inline basic_string<_CharTy> basic_string<_CharTy>::parse(long double val)			{ return ::kiwano::common::to_basic_string<char_type>(val); } | ||||
| 
 | ||||
| 	//
 | ||||
| 	// details of basic_string::format
 | ||||
|  | @ -1193,7 +1193,7 @@ namespace core | |||
| 	template <typename ..._Args> | ||||
| 	inline basic_string<_CharTy> basic_string<_CharTy>::format(const char_type* fmt, _Args&& ... args) | ||||
| 	{ | ||||
| 		return ::kiwano::core::format_string(fmt, std::forward<_Args>(args)...); | ||||
| 		return ::kiwano::common::format_string(fmt, std::forward<_Args>(args)...); | ||||
| 	} | ||||
| 
 | ||||
| 	//
 | ||||
|  | @ -1527,8 +1527,8 @@ class string_convert | |||
| 	enum : size_t { BUFFER_INCREASE = 8, BUFFER_MAX = 16 }; | ||||
| 
 | ||||
| public: | ||||
| 	using byte_string  = ::kiwano::core::basic_string<char>; | ||||
| 	using wide_string  = ::kiwano::core::basic_string<_Elem>; | ||||
| 	using byte_string  = ::kiwano::common::basic_string<char>; | ||||
| 	using wide_string  = ::kiwano::common::basic_string<_Elem>; | ||||
| 	using codecvt_type = _Codecvt; | ||||
| 	using state_type   = typename codecvt_type::state_type; | ||||
| 	using int_type     = typename wide_string::traits_type::int_type; | ||||
|  | @ -1702,25 +1702,25 @@ class chs_codecvt | |||
| public: | ||||
| 	chs_codecvt() : codecvt_byname("chs") {} | ||||
| 
 | ||||
| 	static inline ::kiwano::core::wstring string_to_wide(::kiwano::core::string const& str) | ||||
| 	static inline ::kiwano::common::wstring string_to_wide(::kiwano::common::string const& str) | ||||
| 	{ | ||||
| 		string_convert<chs_codecvt> conv; | ||||
| 		return conv.from_bytes(str); | ||||
| 	} | ||||
| 
 | ||||
| 	static inline ::kiwano::core::string wide_to_string(::kiwano::core::wstring const& str) | ||||
| 	static inline ::kiwano::common::string wide_to_string(::kiwano::common::wstring const& str) | ||||
| 	{ | ||||
| 		string_convert<chs_codecvt> conv; | ||||
| 		return conv.to_bytes(str); | ||||
| 	} | ||||
| }; | ||||
| 
 | ||||
| inline ::kiwano::core::wstring string_to_wide(::kiwano::core::string const& str) | ||||
| inline ::kiwano::common::wstring string_to_wide(::kiwano::common::string const& str) | ||||
| { | ||||
| 	return kiwano::chs_codecvt::string_to_wide(str); | ||||
| } | ||||
| 
 | ||||
| inline ::kiwano::core::string wide_to_string(::kiwano::core::wstring const& str) | ||||
| inline ::kiwano::common::string wide_to_string(::kiwano::common::wstring const& str) | ||||
| { | ||||
| 	return kiwano::chs_codecvt::wide_to_string(str); | ||||
| } | ||||
|  | @ -1730,18 +1730,18 @@ inline ::kiwano::core::string wide_to_string(::kiwano::core::wstring const& str) | |||
| namespace std | ||||
| { | ||||
| 	template<> | ||||
| 	struct hash<::kiwano::core::string> | ||||
| 	struct hash<::kiwano::common::string> | ||||
| 	{ | ||||
| 		inline size_t operator()(const ::kiwano::core::string& key) const | ||||
| 		inline size_t operator()(const ::kiwano::common::string& key) const | ||||
| 		{ | ||||
| 			return key.hash(); | ||||
| 		} | ||||
| 	}; | ||||
| 
 | ||||
| 	template<> | ||||
| 	struct hash<::kiwano::core::wstring> | ||||
| 	struct hash<::kiwano::common::wstring> | ||||
| 	{ | ||||
| 		inline size_t operator()(const ::kiwano::core::wstring& key) const | ||||
| 		inline size_t operator()(const ::kiwano::common::wstring& key) const | ||||
| 		{ | ||||
| 			return key.hash(); | ||||
| 		} | ||||
|  | @ -1751,13 +1751,13 @@ namespace std | |||
| namespace std | ||||
| { | ||||
| 	template<> | ||||
| 	inline void swap<::kiwano::core::string>(::kiwano::core::string& lhs, ::kiwano::core::string& rhs) noexcept | ||||
| 	inline void swap<::kiwano::common::string>(::kiwano::common::string& lhs, ::kiwano::common::string& rhs) noexcept | ||||
| 	{ | ||||
| 		lhs.swap(rhs); | ||||
| 	} | ||||
| 
 | ||||
| 	template<> | ||||
| 	inline void swap<::kiwano::core::wstring>(::kiwano::core::wstring& lhs, ::kiwano::core::wstring& rhs) noexcept | ||||
| 	inline void swap<::kiwano::common::wstring>(::kiwano::common::wstring& lhs, ::kiwano::common::wstring& rhs) noexcept | ||||
| 	{ | ||||
| 		lhs.swap(rhs); | ||||
| 	} | ||||
|  | @ -25,7 +25,7 @@ | |||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
| namespace core | ||||
| namespace common | ||||
| { | ||||
| 
 | ||||
| 
 | ||||
|  | @ -284,5 +284,5 @@ namespace __vector_details | |||
| 	}; | ||||
| } | ||||
| 
 | ||||
| }  // namespace core
 | ||||
| }  // namespace common
 | ||||
| }  // namespace kiwano
 | ||||
|  | @ -18,7 +18,7 @@ | |||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | ||||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #include <kiwano/base/AsyncTask.h> | ||||
| #include <kiwano/core/AsyncTask.h> | ||||
| #include <kiwano/platform/Application.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
|  | @ -22,7 +22,7 @@ | |||
| #include <thread> | ||||
| #include <mutex> | ||||
| 
 | ||||
| #include <kiwano/base/ObjectBase.h> | ||||
| #include <kiwano/core/ObjectBase.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
|  | @ -18,7 +18,7 @@ | |||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | ||||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #include <kiwano/base/Component.h> | ||||
| #include <kiwano/core/Component.h> | ||||
| 
 | ||||
| #define KGE_DEFINE_COMPONENT_FLAG(OFFSET) ( 0x01 << (OFFSET % 32) ) | ||||
| 
 | ||||
|  | @ -20,11 +20,13 @@ | |||
| 
 | ||||
| #pragma once | ||||
| #include <kiwano/macros.h> | ||||
| #include <kiwano/base/time.h> | ||||
| #include <kiwano/base/Event.hpp> | ||||
| #include <kiwano/core/time.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
| 	class RenderTarget; | ||||
| 	class Event; | ||||
| 
 | ||||
| 	// 基础组件
 | ||||
| 	class KGE_API ComponentBase | ||||
| 	{ | ||||
|  | @ -42,8 +44,6 @@ namespace kiwano | |||
| 	}; | ||||
| 
 | ||||
| 
 | ||||
| 	class RenderTarget; | ||||
| 
 | ||||
| 	// 渲染支持组件
 | ||||
| 	class KGE_API RenderComponent | ||||
| 		: public virtual ComponentBase | ||||
|  | @ -85,7 +85,7 @@ namespace kiwano | |||
| 		: public virtual ComponentBase | ||||
| 	{ | ||||
| 	public: | ||||
| 		virtual void HandleEvent(Event&) {} | ||||
| 		virtual void HandleEvent(Event*) {} | ||||
| 
 | ||||
| 		virtual void HandleMessage(HWND, UINT32, WPARAM, LPARAM) {} | ||||
| 
 | ||||
|  | @ -18,7 +18,7 @@ | |||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | ||||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #include <kiwano/base/Director.h> | ||||
| #include <kiwano/core/Director.h> | ||||
| #include <kiwano/2d/Actor.h> | ||||
| #include <kiwano/2d/Stage.h> | ||||
| #include <kiwano/2d/Transition.h> | ||||
|  | @ -180,7 +180,7 @@ namespace kiwano | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	void Director::HandleEvent(Event& evt) | ||||
| 	void Director::HandleEvent(Event* evt) | ||||
| 	{ | ||||
| 		if (debug_actor_) | ||||
| 			debug_actor_->Dispatch(evt); | ||||
|  | @ -20,7 +20,7 @@ | |||
| 
 | ||||
| #pragma once | ||||
| #include <kiwano/2d/include-forwards.h> | ||||
| #include <kiwano/base/Component.h> | ||||
| #include <kiwano/core/Component.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
|  | @ -72,7 +72,7 @@ namespace kiwano | |||
| 
 | ||||
| 		void OnRender(RenderTarget* rt) override; | ||||
| 
 | ||||
| 		void HandleEvent(Event& evt) override; | ||||
| 		void HandleEvent(Event* evt) override; | ||||
| 
 | ||||
| 	protected: | ||||
| 		Director(); | ||||
|  | @ -0,0 +1,134 @@ | |||
| #include <kiwano/core/Event.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
| 	EventType event::MouseMove			= EventType(L"MouseMove"); | ||||
| 	EventType event::MouseDown			= EventType(L"MouseBtnDown"); | ||||
| 	EventType event::MouseUp			= EventType(L"MouseBtnUp"); | ||||
| 	EventType event::MouseWheel			= EventType(L"MouseWheel"); | ||||
| 	EventType event::MouseHover			= EventType(L"MouseHover"); | ||||
| 	EventType event::MouseOut			= EventType(L"MouseOut"); | ||||
| 	EventType event::MouseClick			= EventType(L"MouseClick"); | ||||
| 
 | ||||
| 	EventType event::KeyDown			= EventType(L"KeyDown"); | ||||
| 	EventType event::KeyUp				= EventType(L"KeyUp"); | ||||
| 	EventType event::KeyChar			= EventType(L"KeyChar"); | ||||
| 
 | ||||
| 	EventType event::WindowMoved		= EventType(L"WindowMoved"); | ||||
| 	EventType event::WindowResized		= EventType(L"WindowResized"); | ||||
| 	EventType event::WindowFocusChanged	= EventType(L"WindowFocusChanged"); | ||||
| 	EventType event::WindowTitleChanged	= EventType(L"WindowTitleChanged"); | ||||
| 	EventType event::WindowClosed		= EventType(L"WindowClosed"); | ||||
| 
 | ||||
| 
 | ||||
| 	Event::Event(EventType const& type) | ||||
| 		: type(type) | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| 	Event::~Event() | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| 	MouseEvent::MouseEvent(EventType const& type) | ||||
| 		: Event(type) | ||||
| 		, pos() | ||||
| 		, left_btn_down(false) | ||||
| 		, right_btn_down(false) | ||||
| 		, target(nullptr) | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| 	MouseMoveEvent::MouseMoveEvent() | ||||
| 		: MouseEvent(event::MouseMove) | ||||
| 		, button(0) | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| 	MouseDownEvent::MouseDownEvent() | ||||
| 		: MouseEvent(event::MouseDown) | ||||
| 		, button(0) | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| 	MouseUpEvent::MouseUpEvent() | ||||
| 		: MouseEvent(event::MouseUp) | ||||
| 		, button(0) | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| 	MouseClickEvent::MouseClickEvent() | ||||
| 		: MouseEvent(event::MouseClick) | ||||
| 		, button(0) | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| 	MouseHoverEvent::MouseHoverEvent() | ||||
| 		: MouseEvent(event::MouseHover) | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| 	MouseOutEvent::MouseOutEvent() | ||||
| 		: MouseEvent(event::MouseOut) | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| 	MouseWheelEvent::MouseWheelEvent() | ||||
| 		: MouseEvent(event::MouseWheel) | ||||
| 		, wheel(0.f) | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| 	KeyDownEvent::KeyDownEvent() | ||||
| 		: Event(event::KeyDown) | ||||
| 		, code(0) | ||||
| 		, count(0) | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| 	KeyUpEvent::KeyUpEvent() | ||||
| 		: Event(event::KeyUp) | ||||
| 		, code(0) | ||||
| 		, count(0) | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| 	KeyCharEvent::KeyCharEvent() | ||||
| 		: Event(event::KeyChar) | ||||
| 		, value() | ||||
| 		, count(0) | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| 	WindowMovedEvent::WindowMovedEvent() | ||||
| 		: Event(event::WindowMoved) | ||||
| 		, x(0) | ||||
| 		, y(0) | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| 	WindowResizedEvent::WindowResizedEvent() | ||||
| 		: Event(event::WindowResized) | ||||
| 		, width(0) | ||||
| 		, height(0) | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| 	WindowFocusChangedEvent::WindowFocusChangedEvent() | ||||
| 		: Event(event::WindowFocusChanged) | ||||
| 		, focus(false) | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| 	WindowTitleChangedEvent::WindowTitleChangedEvent() | ||||
| 		: Event(event::WindowTitleChanged) | ||||
| 		, title() | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| 	WindowClosedEvent::WindowClosedEvent() | ||||
| 		: Event(event::WindowClosed) | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  | @ -0,0 +1,272 @@ | |||
| // Copyright (c) 2016-2018 Kiwano - Nomango
 | ||||
| // 
 | ||||
| // Permission is hereby granted, free of charge, to any person obtaining a copy
 | ||||
| // of this software and associated documentation files (the "Software"), to deal
 | ||||
| // in the Software without restriction, including without limitation the rights
 | ||||
| // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | ||||
| // copies of the Software, and to permit persons to whom the Software is
 | ||||
| // furnished to do so, subject to the following conditions:
 | ||||
| // 
 | ||||
| // The above copyright notice and this permission notice shall be included in
 | ||||
| // all copies or substantial portions of the Software.
 | ||||
| // 
 | ||||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | ||||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | ||||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | ||||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | ||||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | ||||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | ||||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #pragma once | ||||
| #include <kiwano/common/common.h> | ||||
| #include <kiwano/math/math.h> | ||||
| #include <kiwano/core/keys.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
| 	class Actor; | ||||
| 
 | ||||
| 	// 事件类型
 | ||||
| 	struct EventType | ||||
| 	{ | ||||
| 		inline EventType() : hash(0), type() | ||||
| 		{ | ||||
| 		} | ||||
| 
 | ||||
| 		inline EventType(String const& type) : hash(0), type(type) | ||||
| 		{ | ||||
| 			hash = type.hash(); | ||||
| 		} | ||||
| 
 | ||||
| 		inline bool operator==(const EventType& rhs) const | ||||
| 		{ | ||||
| 			return hash == rhs.hash && type == rhs.type; | ||||
| 		} | ||||
| 
 | ||||
| 		size_t hash; | ||||
| 		String type; | ||||
| 	}; | ||||
| 
 | ||||
| 
 | ||||
| 	namespace event | ||||
| 	{ | ||||
| 		// 鼠标事件
 | ||||
| 		extern EventType MouseMove;				// 移动
 | ||||
| 		extern EventType MouseDown;				// 鼠标按下
 | ||||
| 		extern EventType MouseUp;				// 鼠标抬起
 | ||||
| 		extern EventType MouseWheel;			// 滚轮滚动
 | ||||
| 		extern EventType MouseHover;			// 鼠标移入
 | ||||
| 		extern EventType MouseOut;				// 鼠标移出
 | ||||
| 		extern EventType MouseClick;			// 鼠标点击
 | ||||
| 
 | ||||
| 		// 按键事件
 | ||||
| 		extern EventType KeyDown;				// 按键按下
 | ||||
| 		extern EventType KeyUp;					// 按键抬起
 | ||||
| 		extern EventType KeyChar;				// 输出字符
 | ||||
| 
 | ||||
| 		// 窗口消息
 | ||||
| 		extern EventType WindowMoved;			// 窗口移动
 | ||||
| 		extern EventType WindowResized;			// 窗口大小变化
 | ||||
| 		extern EventType WindowFocusChanged;	// 获得或失去焦点
 | ||||
| 		extern EventType WindowTitleChanged;	// 标题变化
 | ||||
| 		extern EventType WindowClosed;			// 窗口被关闭
 | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	// 事件
 | ||||
| 	class KGE_API Event | ||||
| 	{ | ||||
| 	public: | ||||
| 		const EventType type; | ||||
| 
 | ||||
| 		Event(EventType const& type); | ||||
| 		virtual ~Event(); | ||||
| 
 | ||||
| 		template < | ||||
| 			typename _Ty, | ||||
| 			typename = typename std::enable_if<std::is_base_of<Event, _Ty>::value, int>::type | ||||
| 		> | ||||
| 		inline const _Ty* SafeCast() const | ||||
| 		{ | ||||
| 			const _Ty* ptr = dynamic_cast<const _Ty*>(this); | ||||
| 			if (ptr) | ||||
| 			{ | ||||
| 				return ptr; | ||||
| 			} | ||||
| 			return nullptr; | ||||
| 		} | ||||
| 
 | ||||
| 		template < | ||||
| 			typename _Ty, | ||||
| 			typename = typename std::enable_if<std::is_base_of<Event, _Ty>::value, int>::type | ||||
| 		> | ||||
| 		inline _Ty* SafeCast() | ||||
| 		{ | ||||
| 			return const_cast<_Ty*>(const_cast<const Event*>(this)->SafeCast<_Ty>()); | ||||
| 		} | ||||
| 	}; | ||||
| 
 | ||||
| 	// 鼠标事件
 | ||||
| 	class KGE_API MouseEvent | ||||
| 		: public Event | ||||
| 	{ | ||||
| 	public: | ||||
| 		Point pos; | ||||
| 		bool left_btn_down;		// 左键是否按下
 | ||||
| 		bool right_btn_down;	// 右键是否按下
 | ||||
| 		Actor* target; | ||||
| 
 | ||||
| 		MouseEvent(EventType const& type); | ||||
| 	}; | ||||
| 
 | ||||
| 	// 鼠标移动事件
 | ||||
| 	class KGE_API MouseMoveEvent | ||||
| 		: public MouseEvent | ||||
| 	{ | ||||
| 	public: | ||||
| 		MouseButton::Value button; | ||||
| 
 | ||||
| 		MouseMoveEvent(); | ||||
| 	}; | ||||
| 
 | ||||
| 	// 鼠标按键按下事件
 | ||||
| 	class KGE_API MouseDownEvent | ||||
| 		: public MouseEvent | ||||
| 	{ | ||||
| 	public: | ||||
| 		MouseButton::Value button; | ||||
| 
 | ||||
| 		MouseDownEvent(); | ||||
| 	}; | ||||
| 
 | ||||
| 	// 鼠标按键抬起事件
 | ||||
| 	class KGE_API MouseUpEvent | ||||
| 		: public MouseEvent | ||||
| 	{ | ||||
| 	public: | ||||
| 		MouseButton::Value button; | ||||
| 
 | ||||
| 		MouseUpEvent(); | ||||
| 	}; | ||||
| 
 | ||||
| 	// 鼠标点击事件
 | ||||
| 	class KGE_API MouseClickEvent | ||||
| 		: public MouseEvent | ||||
| 	{ | ||||
| 	public: | ||||
| 		MouseButton::Value button; | ||||
| 
 | ||||
| 		MouseClickEvent(); | ||||
| 	}; | ||||
| 
 | ||||
| 	// 鼠标移入事件
 | ||||
| 	class KGE_API MouseHoverEvent | ||||
| 		: public MouseEvent | ||||
| 	{ | ||||
| 	public: | ||||
| 		MouseHoverEvent(); | ||||
| 	}; | ||||
| 
 | ||||
| 	// 鼠标移出事件
 | ||||
| 	class KGE_API MouseOutEvent | ||||
| 		: public MouseEvent | ||||
| 	{ | ||||
| 	public: | ||||
| 		MouseOutEvent(); | ||||
| 	}; | ||||
| 
 | ||||
| 	// 鼠标滚轮事件
 | ||||
| 	class KGE_API MouseWheelEvent | ||||
| 		: public MouseEvent | ||||
| 	{ | ||||
| 	public: | ||||
| 		float wheel; | ||||
| 
 | ||||
| 		MouseWheelEvent(); | ||||
| 	}; | ||||
| 
 | ||||
| 	// 键盘按下事件
 | ||||
| 	class KGE_API KeyDownEvent | ||||
| 		: public Event | ||||
| 	{ | ||||
| 	public: | ||||
| 		KeyCode::Value code; | ||||
| 		int count; | ||||
| 
 | ||||
| 		KeyDownEvent(); | ||||
| 	}; | ||||
| 
 | ||||
| 	// 键盘抬起事件
 | ||||
| 	class KGE_API KeyUpEvent | ||||
| 		: public Event | ||||
| 	{ | ||||
| 	public: | ||||
| 		KeyCode::Value code; | ||||
| 		int count; | ||||
| 
 | ||||
| 		KeyUpEvent(); | ||||
| 	}; | ||||
| 
 | ||||
| 	// 键盘字符事件
 | ||||
| 	class KGE_API KeyCharEvent | ||||
| 		: public Event | ||||
| 	{ | ||||
| 	public: | ||||
| 		char value; | ||||
| 		int count; | ||||
| 
 | ||||
| 		KeyCharEvent(); | ||||
| 	}; | ||||
| 
 | ||||
| 	// 窗口移动事件
 | ||||
| 	class KGE_API WindowMovedEvent | ||||
| 		: public Event | ||||
| 	{ | ||||
| 	public: | ||||
| 		int x; | ||||
| 		int y; | ||||
| 
 | ||||
| 		WindowMovedEvent(); | ||||
| 	}; | ||||
| 
 | ||||
| 	// 窗口大小变化事件
 | ||||
| 	class KGE_API WindowResizedEvent | ||||
| 		: public Event | ||||
| 	{ | ||||
| 	public: | ||||
| 		int width; | ||||
| 		int height; | ||||
| 
 | ||||
| 		WindowResizedEvent(); | ||||
| 	}; | ||||
| 
 | ||||
| 	// 窗口焦点变化事件
 | ||||
| 	class KGE_API WindowFocusChangedEvent | ||||
| 		: public Event | ||||
| 	{ | ||||
| 	public: | ||||
| 		bool focus; | ||||
| 
 | ||||
| 		WindowFocusChangedEvent(); | ||||
| 	}; | ||||
| 
 | ||||
| 	// 窗口标题更改事件
 | ||||
| 	class KGE_API WindowTitleChangedEvent | ||||
| 		: public Event | ||||
| 	{ | ||||
| 	public: | ||||
| 		String title; | ||||
| 
 | ||||
| 		WindowTitleChangedEvent(); | ||||
| 	}; | ||||
| 
 | ||||
| 	// 窗口关闭事件
 | ||||
| 	class KGE_API WindowClosedEvent | ||||
| 		: public Event | ||||
| 	{ | ||||
| 	public: | ||||
| 		WindowClosedEvent(); | ||||
| 	}; | ||||
| 
 | ||||
| } | ||||
|  | @ -18,12 +18,12 @@ | |||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | ||||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #include <kiwano/base/EventDispatcher.h> | ||||
| #include <kiwano/base/Logger.h> | ||||
| #include <kiwano/core/EventDispatcher.h> | ||||
| #include <kiwano/core/Logger.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
| 	void EventDispatcher::Dispatch(Event& evt) | ||||
| 	void EventDispatcher::Dispatch(Event* evt) | ||||
| 	{ | ||||
| 		if (listeners_.empty()) | ||||
| 			return; | ||||
|  | @ -33,7 +33,7 @@ namespace kiwano | |||
| 		{ | ||||
| 			next = listener->next_item(); | ||||
| 
 | ||||
| 			if (listener->IsRunning() && listener->type_ == evt.type) | ||||
| 			if (listener->IsRunning() && listener->type_ == evt->type) | ||||
| 			{ | ||||
| 				listener->callback_(evt); | ||||
| 			} | ||||
|  | @ -56,9 +56,15 @@ namespace kiwano | |||
| 		return listener; | ||||
| 	} | ||||
| 
 | ||||
| 	EventListener* EventDispatcher::AddListener(EventType type, EventListener::Callback callback, String const& name) | ||||
| 	EventListener* EventDispatcher::AddListener(String const& name, EventType type, EventListener::Callback callback) | ||||
| 	{ | ||||
| 		EventListenerPtr listener = new EventListener(type, callback, name); | ||||
| 		EventListenerPtr listener = new EventListener(name, type, callback); | ||||
| 		return AddListener(listener); | ||||
| 	} | ||||
| 
 | ||||
| 	EventListener* EventDispatcher::AddListener(EventType type, EventListener::Callback callback) | ||||
| 	{ | ||||
| 		EventListenerPtr listener = new EventListener(type, callback); | ||||
| 		return AddListener(listener); | ||||
| 	} | ||||
| 
 | ||||
|  | @ -98,7 +104,7 @@ namespace kiwano | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	void EventDispatcher::StartListeners(uint32_t type) | ||||
| 	void EventDispatcher::StartListeners(const EventType& type) | ||||
| 	{ | ||||
| 		for (auto listener = listeners_.first_item(); listener; listener = listener->next_item()) | ||||
| 		{ | ||||
|  | @ -109,7 +115,7 @@ namespace kiwano | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	void EventDispatcher::StopListeners(uint32_t type) | ||||
| 	void EventDispatcher::StopListeners(const EventType& type) | ||||
| 	{ | ||||
| 		for (auto listener = listeners_.first_item(); listener; listener = listener->next_item()) | ||||
| 		{ | ||||
|  | @ -120,7 +126,7 @@ namespace kiwano | |||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	void EventDispatcher::RemoveListeners(uint32_t type) | ||||
| 	void EventDispatcher::RemoveListeners(const EventType& type) | ||||
| 	{ | ||||
| 		EventListenerPtr next; | ||||
| 		for (auto listener = listeners_.first_item(); listener; listener = next) | ||||
|  | @ -19,7 +19,7 @@ | |||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #pragma once | ||||
| #include <kiwano/base/EventListener.h> | ||||
| #include <kiwano/core/EventListener.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
|  | @ -40,9 +40,15 @@ namespace kiwano | |||
| 
 | ||||
| 		// 添加监听器
 | ||||
| 		EventListener* AddListener( | ||||
| 			String const& name, | ||||
| 			EventType type, | ||||
| 			EventListener::Callback callback, | ||||
| 			String const& name = L"" | ||||
| 			EventListener::Callback callback | ||||
| 		); | ||||
| 
 | ||||
| 		// 添加监听器
 | ||||
| 		EventListener* AddListener( | ||||
| 			EventType type, | ||||
| 			EventListener::Callback callback | ||||
| 		); | ||||
| 
 | ||||
| 		// 启动监听器
 | ||||
|  | @ -62,20 +68,20 @@ namespace kiwano | |||
| 
 | ||||
| 		// 启动监听器
 | ||||
| 		void StartListeners( | ||||
| 			uint32_t type | ||||
| 			const EventType& type | ||||
| 		); | ||||
| 
 | ||||
| 		// 停止监听器
 | ||||
| 		void StopListeners( | ||||
| 			uint32_t type | ||||
| 			const EventType& type | ||||
| 		); | ||||
| 
 | ||||
| 		// 移除监听器
 | ||||
| 		void RemoveListeners( | ||||
| 			uint32_t type | ||||
| 			const EventType& type | ||||
| 		); | ||||
| 
 | ||||
| 		virtual void Dispatch(Event& evt); | ||||
| 		virtual void Dispatch(Event* evt); | ||||
| 
 | ||||
| 	protected: | ||||
| 		Listeners listeners_; | ||||
|  | @ -19,14 +19,26 @@ | |||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #pragma once | ||||
| #include <kiwano/base/EventListener.h> | ||||
| #include <kiwano/core/EventListener.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
| 	EventListener::EventListener(EventType type, Callback const & callback, String const & name) | ||||
| 	EventListener::EventListener() | ||||
| 		: type_() | ||||
| 		, callback_() | ||||
| 		, running_(true) | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| 	EventListener::EventListener(EventType type, Callback const& callback) | ||||
| 		: type_(type) | ||||
| 		, callback_(callback) | ||||
| 		, running_(true) | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| 	EventListener::EventListener(String const& name, EventType type, Callback const& callback) | ||||
| 		: EventListener(type, callback) | ||||
| 	{ | ||||
| 		SetName(name); | ||||
| 	} | ||||
|  | @ -0,0 +1,115 @@ | |||
| // Copyright (c) 2016-2018 Kiwano - Nomango
 | ||||
| // 
 | ||||
| // Permission is hereby granted, free of charge, to any person obtaining a copy
 | ||||
| // of this software and associated documentation files (the "Software"), to deal
 | ||||
| // in the Software without restriction, including without limitation the rights
 | ||||
| // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | ||||
| // copies of the Software, and to permit persons to whom the Software is
 | ||||
| // furnished to do so, subject to the following conditions:
 | ||||
| // 
 | ||||
| // The above copyright notice and this permission notice shall be included in
 | ||||
| // all copies or substantial portions of the Software.
 | ||||
| // 
 | ||||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | ||||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | ||||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | ||||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | ||||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | ||||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | ||||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #pragma once | ||||
| #include <kiwano/common/common.h> | ||||
| #include <kiwano/core/SmartPtr.hpp> | ||||
| #include <kiwano/core/ObjectBase.h> | ||||
| #include <kiwano/core/Event.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
| 	class EventDispatcher; | ||||
| 
 | ||||
| 	KGE_DECLARE_SMART_PTR(EventListener); | ||||
| 
 | ||||
| 	// ʼþ¼àÌýÆ÷
 | ||||
| 	class KGE_API EventListener | ||||
| 		: public ObjectBase | ||||
| 		, protected IntrusiveListItem<EventListenerPtr> | ||||
| 	{ | ||||
| 		friend class EventDispatcher; | ||||
| 		friend IntrusiveList<EventListenerPtr>; | ||||
| 
 | ||||
| 	public: | ||||
| 		using Callback = Function<void(Event*)>; | ||||
| 
 | ||||
| 		EventListener(); | ||||
| 
 | ||||
| 		EventListener( | ||||
| 			EventType type, | ||||
| 			Callback const& callback | ||||
| 		); | ||||
| 
 | ||||
| 		EventListener( | ||||
| 			String const& name, | ||||
| 			EventType type, | ||||
| 			Callback const& callback | ||||
| 		); | ||||
| 
 | ||||
| 		virtual ~EventListener(); | ||||
| 
 | ||||
| 		void Start(); | ||||
| 
 | ||||
| 		void Stop(); | ||||
| 
 | ||||
| 		bool IsRunning() const; | ||||
| 
 | ||||
| 		Callback GetCallback() const; | ||||
| 
 | ||||
| 		void SetCallback(Callback const& cb); | ||||
| 
 | ||||
| 		EventType const& GetEventType() const; | ||||
| 
 | ||||
| 		void SetEventType(EventType const& type); | ||||
| 
 | ||||
| 	protected: | ||||
| 		bool		running_; | ||||
| 		EventType	type_; | ||||
| 		Callback	callback_; | ||||
| 	}; | ||||
| 
 | ||||
| 
 | ||||
| 	inline void EventListener::Start() | ||||
| 	{ | ||||
| 		running_ = true; | ||||
| 	} | ||||
| 
 | ||||
| 	inline void EventListener::Stop() | ||||
| 	{ | ||||
| 		running_ = false; | ||||
| 	} | ||||
| 
 | ||||
| 	inline bool EventListener::IsRunning() const | ||||
| 	{ | ||||
| 		return running_; | ||||
| 	} | ||||
| 
 | ||||
| 	inline EventListener::Callback EventListener::GetCallback() const | ||||
| 	{ | ||||
| 		return callback_; | ||||
| 	} | ||||
| 
 | ||||
| 	inline void EventListener::SetCallback(Callback const& cb) | ||||
| 	{ | ||||
| 		callback_ = cb; | ||||
| 	} | ||||
| 
 | ||||
| 	inline EventType const& EventListener::GetEventType() const | ||||
| 	{ | ||||
| 		return type_; | ||||
| 	} | ||||
| 
 | ||||
| 	inline void EventListener::SetEventType(EventType const& type) | ||||
| 	{ | ||||
| 		type_ = type; | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  | @ -0,0 +1,68 @@ | |||
| // Copyright (c) 2016-2018 Kiwano - Nomango
 | ||||
| // 
 | ||||
| // Permission is hereby granted, free of charge, to any person obtaining a copy
 | ||||
| // of this software and associated documentation files (the "Software"), to deal
 | ||||
| // in the Software without restriction, including without limitation the rights
 | ||||
| // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | ||||
| // copies of the Software, and to permit persons to whom the Software is
 | ||||
| // furnished to do so, subject to the following conditions:
 | ||||
| // 
 | ||||
| // The above copyright notice and this permission notice shall be included in
 | ||||
| // all copies or substantial portions of the Software.
 | ||||
| // 
 | ||||
| // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | ||||
| // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | ||||
| // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | ||||
| // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | ||||
| // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | ||||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | ||||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #include <kiwano/core/Library.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
| 
 | ||||
| 	Library::Library() | ||||
| 		: instance_(nullptr) | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| 	Library::Library(String const& lib) | ||||
| 		: instance_(nullptr) | ||||
| 	{ | ||||
| 		Load(lib); | ||||
| 	} | ||||
| 
 | ||||
| 	Library::~Library() | ||||
| 	{ | ||||
| 		Free(); | ||||
| 	} | ||||
| 
 | ||||
| 	bool Library::Load(String const& lib) | ||||
| 	{ | ||||
| 		instance_ = ::LoadLibraryW(lib.c_str()); | ||||
| 		return IsValid(); | ||||
| 	} | ||||
| 
 | ||||
| 	bool Library::IsValid() const | ||||
| 	{ | ||||
| 		return instance_ != nullptr; | ||||
| 	} | ||||
| 
 | ||||
| 	void Library::Free() | ||||
| 	{ | ||||
| 		if (instance_) | ||||
| 		{ | ||||
| 			::FreeLibrary(instance_); | ||||
| 			instance_ = nullptr; | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	FARPROC Library::GetProcess(String const& proc_name) | ||||
| 	{ | ||||
| 		KGE_ASSERT(instance_ != nullptr); | ||||
| 		return GetProcAddress(instance_, wide_to_string(proc_name).c_str()); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
|  | @ -19,45 +19,35 @@ | |||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #pragma once | ||||
| #include <kiwano/core/core.h> | ||||
| #include <kiwano/base/SmartPtr.hpp> | ||||
| #include <kiwano/base/ObjectBase.h> | ||||
| #include <kiwano/base/Event.hpp> | ||||
| #include <kiwano/macros.h> | ||||
| #include <kiwano/common/common.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
| 	class EventDispatcher; | ||||
| 
 | ||||
| 	KGE_DECLARE_SMART_PTR(EventListener); | ||||
| 
 | ||||
| 	// ʼþ¼àÌýÆ÷
 | ||||
| 	class KGE_API EventListener | ||||
| 		: public ObjectBase | ||||
| 		, protected IntrusiveListItem<EventListenerPtr> | ||||
| 	// DLL ¿â
 | ||||
| 	class KGE_API Library | ||||
| 	{ | ||||
| 		friend class EventDispatcher; | ||||
| 		friend IntrusiveList<EventListenerPtr>; | ||||
| 
 | ||||
| 	public: | ||||
| 		using Callback = Function<void(Event const&)>; | ||||
| 		Library(); | ||||
| 		Library(String const& lib); | ||||
| 		virtual ~Library(); | ||||
| 
 | ||||
| 		EventListener( | ||||
| 			EventType type, | ||||
| 			Callback const& callback, | ||||
| 			String const& name = L"" | ||||
| 		); | ||||
| 		bool Load(String const& lib); | ||||
| 
 | ||||
| 		virtual ~EventListener(); | ||||
| 		bool IsValid() const; | ||||
| 
 | ||||
| 		inline void Start()				{ running_ = true; } | ||||
| 		void Free(); | ||||
| 
 | ||||
| 		inline void Stop()				{ running_ = true; } | ||||
| 		FARPROC GetProcess(String const& proc_name); | ||||
| 
 | ||||
| 		template <typename _Proc> | ||||
| 		inline _Proc GetProcess(String const& proc_name) | ||||
| 		{ | ||||
| 			return reinterpret_cast<_Proc>(GetProcess(proc_name)); | ||||
| 		} | ||||
| 
 | ||||
| 	private: | ||||
| 		HMODULE instance_; | ||||
| 	}; | ||||
| 
 | ||||
| 		inline bool IsRunning() const	{ return running_; } | ||||
| 
 | ||||
| 	protected: | ||||
| 		bool		running_; | ||||
| 		EventType	type_; | ||||
| 		Callback	callback_; | ||||
| 	}; | ||||
| } | ||||
|  | @ -21,7 +21,7 @@ | |||
| #include <iostream> | ||||
| #include <fstream> | ||||
| 
 | ||||
| #include <kiwano/base/Logger.h> | ||||
| #include <kiwano/core/Logger.h> | ||||
| 
 | ||||
| namespace | ||||
| { | ||||
|  | @ -24,7 +24,7 @@ | |||
| #include <sstream> | ||||
| 
 | ||||
| #include <kiwano/macros.h> | ||||
| #include <kiwano/core/core.h> | ||||
| #include <kiwano/common/common.h> | ||||
| 
 | ||||
| #ifndef KGE_LOG | ||||
| #	ifdef KGE_DEBUG | ||||
|  | @ -19,8 +19,8 @@ | |||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #include <typeinfo> | ||||
| #include <kiwano/base/ObjectBase.h> | ||||
| #include <kiwano/base/Logger.h> | ||||
| #include <kiwano/core/ObjectBase.h> | ||||
| #include <kiwano/core/Logger.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
|  | @ -20,9 +20,9 @@ | |||
| 
 | ||||
| #pragma once | ||||
| #include <kiwano/macros.h> | ||||
| #include <kiwano/core/core.h> | ||||
| #include <kiwano/base/RefCounter.hpp> | ||||
| #include <kiwano/base/SmartPtr.hpp> | ||||
| #include <kiwano/common/common.h> | ||||
| #include <kiwano/core/RefCounter.hpp> | ||||
| #include <kiwano/core/SmartPtr.hpp> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
|  | @ -20,12 +20,12 @@ | |||
| 
 | ||||
| #pragma once | ||||
| #include <kiwano/macros.h> | ||||
| #include <kiwano/core/noncopyable.hpp> | ||||
| #include <kiwano/common/noncopyable.hpp> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
| 	class KGE_API RefCounter | ||||
| 		: protected core::noncopyable | ||||
| 		: protected common::noncopyable | ||||
| 	{ | ||||
| 	public: | ||||
| 		// 增加引用计数
 | ||||
|  | @ -20,8 +20,8 @@ | |||
| 
 | ||||
| #include <iostream> | ||||
| 
 | ||||
| #include <kiwano/base/Resource.h> | ||||
| #include <kiwano/base/Logger.h> | ||||
| #include <kiwano/core/Resource.h> | ||||
| #include <kiwano/core/Logger.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
|  | @ -20,7 +20,7 @@ | |||
| 
 | ||||
| #pragma once | ||||
| #include <kiwano/macros.h> | ||||
| #include <kiwano/core/core.h> | ||||
| #include <kiwano/common/common.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
|  | @ -19,8 +19,8 @@ | |||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #pragma once | ||||
| #include <kiwano/base/RefCounter.hpp> | ||||
| #include <kiwano/core/intrusive_ptr.hpp> | ||||
| #include <kiwano/core/RefCounter.hpp> | ||||
| #include <kiwano/common/intrusive_ptr.hpp> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
|  | @ -38,7 +38,7 @@ namespace kiwano | |||
| 	}; | ||||
| 
 | ||||
| 	template <typename _Ty> | ||||
| 	using SmartPtr = core::intrusive_ptr<_Ty, DefaultIntrusivePtrManager>; | ||||
| 	using SmartPtr = common::intrusive_ptr<_Ty, DefaultIntrusivePtrManager>; | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
|  | @ -18,7 +18,7 @@ | |||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | ||||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #include <kiwano/base/Timer.h> | ||||
| #include <kiwano/core/Timer.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
|  | @ -21,8 +21,8 @@ | |||
| #pragma once | ||||
| #include <functional> | ||||
| 
 | ||||
| #include <kiwano/base/ObjectBase.h> | ||||
| #include <kiwano/base/time.h> | ||||
| #include <kiwano/core/ObjectBase.h> | ||||
| #include <kiwano/core/time.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
|  | @ -18,8 +18,8 @@ | |||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | ||||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #include <kiwano/base/TimerManager.h> | ||||
| #include <kiwano/base/Logger.h> | ||||
| #include <kiwano/core/TimerManager.h> | ||||
| #include <kiwano/core/Logger.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
|  | @ -19,7 +19,7 @@ | |||
| // THE SOFTWARE.
 | ||||
| 
 | ||||
| #pragma once | ||||
| #include <kiwano/base/Timer.h> | ||||
| #include <kiwano/core/Timer.h> | ||||
| 
 | ||||
| namespace kiwano | ||||
| { | ||||
Some files were not shown because too many files have changed in this diff Show More
		Loading…
	
		Reference in New Issue